NetBSD porting - blinkkin/blinkkin.github.com GitHub Wiki

Common tasks involved in porting tools from NetBSD to Linux and probably other Unix-like system.


RCS and SCCS information’s

Can be compiled with -Dlint flag passed to compiler. Good solution is also removing them completely.


emalloc and other wrapers

Can be safely changed to counterpart without “e” prefix e.g. emalloc → malloc. Few other wrapers like raise_default_signal are also used, need some further investigation.


System macros

Macros like __dead are pretty common. Use information from cdefs.h to define them or change them.


System limits and other setting

MAXBSIZE or REG_BASIC (few other also) are undefined, defining them resolve problem e.g:

#define MAXBSIZE (64 * 1024)
#define REG_BASIC 0000

Functions getprogname and setprogname

Can be safely removed.


Function fgetln

Simple wrapper from MirBSD to use GNU getline() is available, but some systems libc implementation are missing both fgetln() and getline() functions probably.


Function asprintf

stdio.h from uClibc provides it when USE_GNU is defined e.g.:

#define __USE_GNU

Some system doesn’t have it AFAIK.


Simplified common changes:

static void usage(void) __dead;
static void usage(void) __attribute__((__noreturn__));
#define MAXBSIZE (64 * 1024)
#define REG_BASIC 0000
#define __USE_GNU
#include <stdio.h>
for asprintf
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
for stat/fstat and so on

Useful macros: http://cvsweb.netbsd.org/bsdweb.cgi/src/sys/sys/cdefs.h?rev=1.84.2.1

Wrapper for fgetln http://www.mirbsd.org/cvs.cgi/contrib/code/mirmake/dist/contrib/fgetln.c?rev=1.6:

char *
fgetln(FILE *stream, size_t *len)
{
	static char *lb = NULL;
	static size_t lbsz = 0;

	if ((*len = getline(&lb, &lbsz, stream)) != (size_t)-1)
		/* getdelim ensures *len is not 0 here */
		return (lb);

	/* not required by manpage, but reference implementation does this */
	*len = 0;

	/* not required to zero lb or lbsz: getdelim manages it */
	return (NULL);
}

p.
⚠️ **GitHub.com Fallback** ⚠️