Build NetBSD libc library in world in ELF mode.

3 sets of libraries are built now:
  . ack: all libraries that ack can compile (/usr/lib/i386/)
  . clang+elf: all libraries with minix headers (/usr/lib/)
  . clang+elf: all libraries with netbsd headers (/usr/netbsd/)

Once everything can be compiled with netbsd libraries and headers, the
/usr/netbsd hierarchy will be obsolete and its libraries compiled with
netbsd headers will be installed in /usr/lib, and its headers
in /usr/include. (i.e. minix libc and current minix headers set
will be gone.)

To use the NetBSD libc system (libraries + headers) before
it is the default libc, see:
   http://wiki.minix3.org/en/DevelopersGuide/UsingNetBSDCode
This wiki page also documents the maintenance of the patch
files of minix-specific changes to imported NetBSD code.

Changes in this commit:
  . libsys: Add NBSD compilation and create a safe NBSD-based libc.
  . Port rest of libraries (except libddekit) to new header system.
  . Enable compilation of libddekit with new headers.
  . Enable kernel compilation with new headers.
  . Enable drivers compilation with new headers.
  . Port legacy commands to new headers and libc.
  . Port servers to new headers.
  . Add <sys/sigcontext.h> in compat library.
  . Remove dependency file in tree.
  . Enable compilation of common/lib/libc/atomic in libsys
  . Do not generate RCSID strings in libc.
  . Temporarily disable zoneinfo as they are incompatible with NetBSD format
  . obj-nbsd for .gitignore
  . Procfs: use only integer arithmetic. (Antoine Leca)
  . Increase ramdisk size to create NBSD-based images.
  . Remove INCSYMLINKS handling hack.
  . Add nbsd_include/sys/exec_elf.h
  . Enable ELF compilation with NBSD libc.
  . Add 'make nbsdsrc' in tools to download reference NetBSD sources.
  . Automate minix-port.patch creation.
  . Avoid using fstavfs() as it is *extremely* slow and unneeded.
  . Set err() as PRIVATE to avoid name clash with libc.
  . [NBSD] servers/vm: remove compilation warnings.
  . u32 is not a long in NBSD headers.
  . UPDATING info on netbsd hierarchy
  . commands fixes for netbsd libc
This commit is contained in:
Gianluca Guida 2011-04-27 13:00:52 +00:00 committed by Ben Gras
parent e3f68488ee
commit cc17b27a2b
136 changed files with 3567 additions and 470 deletions

2
.gitignore vendored
View file

@ -13,9 +13,11 @@ cscope.*
*.a
*.d
.depend
nbsdsrc/*
obj-ack
obj-gnu
obj-elf-base
obj-gnu-nbsd
tools/revision
TAGS
tags

View file

@ -55,8 +55,10 @@ mkfiles:
make -C share/mk install
includes:
$(MAKE) -C nbsd_include includes
$(MAKE) -C include includes
$(MAKE) -C lib includes
$(MAKE) -C lib includes NBSD_LIBC=yes
$(MAKE) -C lib includes NBSD_LIBC=no
libraries: includes
$(MAKE) -C lib build_ack
@ -70,7 +72,7 @@ gnu-includes: includes
SHELL=/bin/sh; if [ -f $(MKHEADERS443_PKGSRC) ] ; then sh -e $(MKHEADERS443_PKGSRC) ; fi
.ifndef MINIX_GENERATE_ELF
gnu-libraries: #gnu-includes
gnu-libraries: includes #gnu-includes
$(MAKE) -C lib build_gnu
clang-libraries: includes
@ -89,7 +91,7 @@ commands: includes libraries
$(MAKE) -C commands all
depend:
$(MAKE) -C boot depend
$(MAKE) CC=cc -C boot depend
$(MAKE) -C commands depend
$(MAKE) -C kernel depend
$(MAKE) -C servers depend
@ -102,12 +104,12 @@ etcforce:
$(MAKE) -C etc installforce
all:
$(MAKE) -C boot all
$(MAKE) CC=cc -C boot all
$(MAKE) -C commands all
$(MAKE) -C tools all
install:
$(MAKE) -C boot install
$(MAKE) CC=cc -C boot install
$(MAKE) -C man install makedb
$(MAKE) -C commands install
$(MAKE) -C share install

View file

@ -1,2 +1,8 @@
.if (${NBSD_LIBC} != "no")
CPPFLAGS+= -D_MINIX -D_NETBSD_SOURCE -D_MINIX_COMPAT
LDADD+= -lminlib -lcompat_minix -lasyn
.else
CPPFLAGS+= -D_MINIX -D_POSIX_SOURCE
.endif
BINDIR?=/usr/bin

View file

@ -42,6 +42,9 @@ static char RcsId[] = "$Header$";
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#ifdef __NBSD_LIBC
#include <sys/time.h>
#endif
#ifndef S_IREAD
#define S_IREAD S_IRUSR
#endif

View file

@ -181,26 +181,49 @@ int main(int argc, char *argv[])
if (!(high_byte & 0x80)) /* class A or 0 */
{
if (destination)
#ifdef __NBSD_LIBC
defaultmask= htonl(0xff000000);
#else
defaultmask= HTONL(0xff000000);
#endif
}
else if (!(high_byte & 0x40)) /* class B */
{
#ifdef __NBSD_LIBC
defaultmask= htonl(0xffff0000);
#else
defaultmask= HTONL(0xffff0000);
#endif
}
else if (!(high_byte & 0x20)) /* class C */
{
#ifdef __NBSD_LIBC
defaultmask= htonl(0xffffff00);
#else
defaultmask= HTONL(0xffffff00);
#endif
}
else /* class D is multicast ... */
{
fprintf(stderr, "%s: Warning: Martian address '%s'\n",
prog_name, inet_ntoa(destination));
#ifdef __NBSD_LIBC
defaultmask= htonl(0xffffffff);
#else
defaultmask= HTONL(0xffffffff);
#endif
}
if (destination & ~defaultmask)
{
/* host route */
#ifdef __NBSD_LIBC
defaultmask= htonl(0xffffffff);
#else
defaultmask= HTONL(0xffffffff);
#endif
}
if (!cidr)
netmask= defaultmask;

View file

@ -225,7 +225,7 @@ retry:
{
(void) memcpy(parsenextc, rl_cp+rl_off, nr);
parsenextc[nr++]= '\n';
free(rl_cp);
free((void *)rl_cp);
rl_cp= NULL;
rl_off= 0;
}
@ -385,7 +385,7 @@ pushstring(char *s, int len, void *ap)
struct strpush *sp;
INTOFF;
/*dprintf("*** calling pushstring: %s, %d\n", s, len);*/
/*dbgprintf("*** calling pushstring: %s, %d\n", s, len);*/
if (parsefile->strpush) {
sp = ckmalloc(sizeof (struct strpush));
sp->prev = parsefile->strpush;
@ -412,7 +412,7 @@ popstring(void)
parsenextc = sp->prevstring;
parsenleft = sp->prevnleft;
parselleft = sp->prevlleft;
/*dprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/
/*dbgprintf("*** calling popstring: restoring to '%s'\n", parsenextc);*/
if (sp->ap)
sp->ap->flag &= ~ALIASINUSE;
parsefile->strpush = sp->prev;

View file

@ -265,7 +265,7 @@ out1fmt(const char *fmt, ...)
}
void
dprintf(const char *fmt, ...)
dbgprintf(const char *fmt, ...)
{
va_list ap;
@ -325,7 +325,7 @@ out1fmt(va_alist)
}
void
dprintf(va_alist)
dbgprintf(va_alist)
va_dcl
{
va_list ap;

View file

@ -69,7 +69,7 @@ void flushout(struct output *);
void freestdout(void);
void outfmt(struct output *, const char *, ...) __printflike(2, 3);
void out1fmt(const char *, ...) __printflike(1, 2);
void dprintf(const char *, ...) __printflike(1, 2);
void dbgprintf(const char *, ...) __printflike(1, 2);
void fmtstr(char *, int, const char *, ...) __printflike(3, 4);
void doformat(struct output *, const char *, va_list) __printflike(2, 0);
int xwrite(int, char *, int);

View file

@ -81,7 +81,7 @@ extern char nullstr[1]; /* null string */
#define TRACE(param)
#endif
#ifdef __minix
#if defined(__minix) && !defined(__NBSD_LIBC)
typedef long quad_t; /* XXX */
typedef unsigned long u_quad_t; /* XXX */
#endif

View file

@ -62,11 +62,10 @@ __FBSDID("$FreeBSD: src/bin/sh/trap.c,v 1.29 2004/04/06 20:06:51 markm Exp $");
#endif
#include "builtins.h"
#ifdef __minix
#if defined(__minix) && !defined(__NBSD_LIBC)
#define NO_SIGINTERRUPT
#define NO_SYS_SIGNAME
#define NO_SYS_SIGLIST
#endif
typedef void (*sig_T)(int);
@ -560,7 +559,7 @@ int sig;
static char *strsigname(sig)
int sig;
{
return sys_signame[sig];
return (char *)sys_signame[sig];
}
#endif
@ -577,7 +576,7 @@ int sig;
char *strsiglist(sig)
int sig;
{
return sys_siglist[sig];
return (char *)sys_siglist[sig];
}
#endif

View file

@ -2,6 +2,8 @@
PROG= awk
SRCS= awkgram.y b.c lex.c lib.c main.c parse.c proctab.c run.c tran.c
LDADD= -lm
DEPEND+= ${LIBM}
YHEADER= yes
QUIET_YACC= yes

View file

@ -5,7 +5,11 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <time.h>
#ifdef __NBSD_LIBC
#include <compat/regexp.h>
#else
#include <regexp.h>
#endif
#include <limits.h>
#include <stdlib.h>
#include <string.h>

View file

@ -94,6 +94,12 @@
#define K 1024 /* STD_BLK */
#define K_MASK (~(K-1)) /* Round to K boundary */
#define K_SHIFT 10 /* Ie. 1<<10 = K */
#ifdef __NBSD_LIBC
/* Name pollution with more famous macros describing machine's
* page size. These defs should be renamed. */
#undef PAGE_MASK
#undef PAGE_SHIFT
#endif /* __NBSD_LIBC */
#define PAGE_MASK 0x1f /* Word mode: 32 bytes */
#define PAGE_SHIFT 5 /* Ie. 1<<5 = 32 */
#define MAP_BITS_PER_BLOCK (8 * K) /* 1k block, 8192 bits */

View file

@ -39,7 +39,11 @@ static char *cachefile= PATH_DHCPCACHE;
static int qflag; /* True if printing cached DHCP data. */
static int aflag, rflag; /* True if adding or deleting pool addresses. */
#ifdef __NBSD_LIBC
#define BCAST_IP htonl(0xFFFFFFFFUL)
#else
#define BCAST_IP HTONL(0xFFFFFFFFUL)
#endif
/* We try to play with up to this many networks. */
#define N_NETS 32
@ -104,13 +108,24 @@ network_t *if2net(int n)
static ipaddr_t defaultmask(ipaddr_t ip)
{
/* Compute netmask by the oldfashioned Class rules. */
#ifdef __NBSD_LIBC
if (B(&ip)[0] < 0x80) return htonl(0xFF000000UL); /* Class A. */
if (B(&ip)[0] < 0xC0) return htonl(0xFFFF0000UL); /* Class B. */
if (B(&ip)[0] < 0xE0) return htonl(0xFFFFFF00UL); /* Class C. */
return htonl(0xFFFFFFFFUL); /* Multicast? Shouldn't happen... */
#else
if (B(&ip)[0] < 0x80) return HTONL(0xFF000000UL); /* Class A. */
if (B(&ip)[0] < 0xC0) return HTONL(0xFFFF0000UL); /* Class B. */
if (B(&ip)[0] < 0xE0) return HTONL(0xFFFFFF00UL); /* Class C. */
return HTONL(0xFFFFFFFFUL); /* Multicast? Shouldn't happen... */
#endif
}
#ifdef __NBSD_LIBC
#define POOL_MAGIC htonl(0x81F85D00UL)
#else
#define POOL_MAGIC HTONL(0x81F85D00UL)
#endif
typedef struct pool { /* Dynamic pool entry. */
u32_t magic; /* Pool file magic number. */

View file

@ -21,8 +21,13 @@
#include "dhcpd.h"
static ether_addr_t BCAST_ETH = {{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }};
#ifdef __NBSD_LIBC
#define BCAST_IP htonl(0xFFFFFFFFUL)
#define LOCALHOST htonl(0x7F000001UL)
#else
#define BCAST_IP HTONL(0xFFFFFFFFUL)
#define LOCALHOST HTONL(0x7F000001UL)
#endif
static u16_t udp_cksum(ipaddr_t src, ipaddr_t dst, udp_hdr_t *udp)
{
@ -64,13 +69,21 @@ void udp2ether(buf_t *bp, network_t *np)
/* Fill in the Ethernet, IP and UDP headers. */
bp->eth->eh_dst= BCAST_ETH;
bp->eth->eh_src= np->eth;
#ifdef __NBSD_LIBC
bp->eth->eh_proto= htons(ETH_IP_PROTO);
#else
bp->eth->eh_proto= HTONS(ETH_IP_PROTO);
#endif
bp->ip->ih_vers_ihl= 0x45;
bp->ip->ih_tos= 0;
bp->ip->ih_length= htons(sizeof(ip_hdr_t)
+ sizeof(udp_hdr_t) + udpio.uih_data_len);
bp->ip->ih_id= 0;
#ifdef __NBSD_LIBC
bp->ip->ih_flags_fragoff= ntohs(0x4000);
#else
bp->ip->ih_flags_fragoff= NTOHS(0x4000);
#endif
bp->ip->ih_ttl= IP_MAX_TTL;
bp->ip->ih_proto= IPPROTO_UDP;
bp->ip->ih_hdr_chk= 0;
@ -91,7 +104,11 @@ int ether2udp(buf_t *bp)
*/
udp_io_hdr_t udpio;
#ifdef __NBSD_LIBC
if (bp->eth->eh_proto != htons(ETH_IP_PROTO)
#else
if (bp->eth->eh_proto != HTONS(ETH_IP_PROTO)
#endif
|| bp->ip->ih_vers_ihl != 0x45
|| bp->ip->ih_proto != IPPROTO_UDP
|| oneC_sum(0, bp->ip, 20) != (u16_t) ~0
@ -118,12 +135,20 @@ void make_arp(buf_t *bp, network_t *np)
memset(arp, 0, sizeof(*arp));
arp->dstaddr= BCAST_ETH;
arp->srcaddr= np->eth;
#ifdef __NBSD_LIBC
arp->ethtype= htons(ETH_ARP_PROTO);
arp->hdr= htons(ARP_ETHERNET);
arp->pro= htons(ETH_IP_PROTO);
arp->op= htons(ARP_REQUEST);
#else
arp->ethtype= HTONS(ETH_ARP_PROTO);
arp->hdr= HTONS(ARP_ETHERNET);
arp->pro= HTONS(ETH_IP_PROTO);
arp->op= HTONS(ARP_REQUEST);
#endif
arp->hln= 6;
arp->pln= 4;
arp->op= HTONS(ARP_REQUEST);
arp->sha= np->eth;
memcpy(arp->spa, &np->ip, sizeof(np->ip));
memcpy(arp->tpa, &np->ip, sizeof(np->ip));
@ -136,10 +161,18 @@ int is_arp_me(buf_t *bp, network_t *np)
*/
arp46_t *arp= (arp46_t *) bp->eth;
if (arp->ethtype == HTONS(ETH_ARP_PROTO)
if (
#ifdef __NBSD_LIBC
arp->ethtype == htons(ETH_ARP_PROTO)
&& arp->hdr == htons(ARP_ETHERNET)
&& arp->pro == htons(ETH_IP_PROTO)
&& arp->op == htons(ARP_REPLY)
#else
arp->ethtype == HTONS(ETH_ARP_PROTO)
&& arp->hdr == HTONS(ARP_ETHERNET)
&& arp->pro == HTONS(ETH_IP_PROTO)
&& arp->op == HTONS(ARP_REPLY)
#endif
&& memcmp(&arp->spa, &np->ip, sizeof(np->ip)) == 0
&& memcmp(&arp->sha, &np->eth, sizeof(np->eth)) != 0
) {
@ -178,7 +211,11 @@ void icmp_advert(buf_t *bp, network_t *np)
icmp->ih_hun.ihh_ram.iram_aes= 2;
icmp->ih_hun.ihh_ram.iram_lt= htons(DELTA_ADV);
((u32_t *) icmp->ih_dun.uhd_data)[0] = np->gateway;
#ifdef __NBSD_LIBC
((u32_t *) icmp->ih_dun.uhd_data)[1] = htonl((u32_t) -9999);
#else
((u32_t *) icmp->ih_dun.uhd_data)[1] = HTONL((u32_t) -9999);
#endif
icmp->ih_chksum= 0;
icmp->ih_chksum= ~oneC_sum(0, icmp, 16);
}

View file

@ -31,6 +31,9 @@
* @(#)diff.h 8.1 (Berkeley) 6/6/93
*/
#ifdef __NBSD_LIBC
#include <minix/config.h>
#endif
#include <sys/types.h>
#include <regex.h>

View file

@ -114,8 +114,10 @@ void info P((void));
void reboot P((void));
void reset_kbd_state P(());
#ifndef __NBSD_LIBC
/* getline.c */
char *getline P((char *startline, unsigned maxlength, unsigned offset));
#endif
/* ihexload.c */
void ihexload P((void));

View file

@ -50,7 +50,11 @@ char *sbm_brk();
#endif /*DBG_SIZE*/
/* Forward routine declarations */
#ifdef __NBSD_LIBC
void *sbrk();
#else
char *sbrk();
#endif
struct smblk *sbm_nmak(), *sbm_nget(), *sbm_mget(), *sbm_split();
struct smblk *sbm_lmak(), *sbm_err();
@ -759,6 +763,11 @@ free(ptr)
char *ptr;
{ register struct smblk *sm, **smp;
#ifdef __NBSD_LIBC
/* In NetBSD, free is a nop if ptr == NULL; */
if(ptr == NULL)
return(1);
#endif
smp = &((struct smblk **)ptr)[-1]; /* Point to addr-1 */
sm = *smp; /* Pluck SM ptr therefrom */
if(((sm->smflags&0377) != SM_NID) || sm->smaddr != (SBMA)smp)

View file

@ -123,6 +123,10 @@ char *cktagdir(tag, dir)
/* This function reads a single textline from a binary file. It returns
* the number of bytes read, or 0 at EOF.
*/
#ifdef __NBSD_LIBC
/* Avoid name pollution with stdio's getline. */
#define getline ref_getline
#endif
int getline(buf, limit, fp)
char *buf; /* buffer to read into */
int limit; /* maximum characters to read */

View file

@ -53,7 +53,9 @@ enum ntype {
N_PRUNE, N_REGEX, N_SIZE, N_TYPE, N_USER, N_XDEV, N_DELETE
};
#ifndef __NBSD_LIBC
typedef unsigned int u_int32_t;
#endif
/* node definition */
typedef struct _plandata {

View file

@ -127,6 +127,12 @@ char *ctime();
char *prog_name;
#ifdef __NBSD_LIBC
/* Already defined in stdio.h */
#undef fwopen
#define fwopen finger_fwopen
#endif
int main (int argc, char *argv[]);
static void doall(void);
static void donames(char **args);

View file

@ -38,6 +38,10 @@
char *prog = 0, *processing = 0;
#ifdef __NBSD_LIBC
/* getline() already declared in stdio.h */
#define getline fix_getline
#endif
_PROTOTYPE(char *getline, (FILE *fp, char *b));
_PROTOTYPE(char *range, (char *s, int *p1, int *p2));
_PROTOTYPE(int getcommand, (FILE *fp, int *o1, int *o2, char *pcmd, int *n1, int *n2));

View file

@ -45,6 +45,11 @@ char *cmdargv[NUMARGS];
int printreply = 1;
char reply[1024];
#ifdef __NBSD_LIBC
/* Already declared in stdio.h */
#define getline ftp_getline
#endif
_PROTOTYPE(static void makeargs, (char *buff));
_PROTOTYPE(int DOver, (void));
_PROTOTYPE(int DOhelp, (void));

View file

@ -104,7 +104,11 @@ struct servent *servent;
/* This HACK allows the server to establish data connections correctly */
/* when using the loopback device to talk to ourselves */
#ifdef __NBSD_LIBC
if((hostip & ntohl(0xFF000000)) == inet_addr("127.0.0.0"))
#else
if((hostip & NTOHL(0xFF000000)) == inet_addr("127.0.0.0"))
#endif
hostip = myip;
if((tcp_device = getenv("TCP_DEVICE")) == NULL)
@ -206,7 +210,11 @@ static int ftpdata_fd = -1;
char *buff;
ipaddr_t ripaddr;
tcpport_t rport;
#ifdef __NBSD_LIBC
static tcpport_t lport = htons(0xF000);
#else
static tcpport_t lport = HTONS(0xF000);
#endif
int s;
int i;
int wpid;
@ -221,7 +229,11 @@ int wasopen;
#endif
ripaddr = hostip;
#ifdef __NBSD_LIBC
rport = htons(2);
#else
rport = HTONS(20);
#endif
/* here we set up a connection to listen on if not passive mode */
/* otherwise we use this to connect for passive mode */

View file

@ -39,6 +39,11 @@ char *FtpdVersion = "2.00";
#include "file.h"
#include "net.h"
#ifdef __NBSD_LIBC
/* Already declared in stdio.h */
#define getline ftpd_getline
#endif
_PROTOTYPE(static void init, (void));
_PROTOTYPE(static int doHELP, (char *buff));
_PROTOTYPE(static int doNOOP, (char *buff));

View file

@ -9,7 +9,9 @@
#include <unistd.h>
#include <sys/types.h>
#include <stdlib.h>
#ifndef __NBSD_LIBC
#include <alloca.h>
#endif
#include <string.h>
#include <assert.h>
#include <minix/gcov.h>

View file

@ -19,7 +19,7 @@ LDADD= -lz
DPADD= ${LIBZ}
.if ${COMPILER_TYPE} == "gnu"
CPPFLAGS+= -isystem ../../../include
CFLAGS+= -Wall
.endif
.if ${OPSYS} == "Minix"

View file

@ -16,7 +16,7 @@
* that copyright notice.
*/
#if _MINIX
#if _MINIX && !defined(__NBSD_LIBC)
#include <sys/types.h>
#include <sys/ioctl.h>
#include <assert.h>
@ -50,6 +50,16 @@
#include <sys/param.h>
#include <strings.h>
#include <ctype.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/ioc_net.h>
#include <net/netlib.h>
#include <net/gen/in.h>
#include <net/gen/tcp.h>
#include <net/gen/tcp_io.h>
#endif
extern int h_errno;
@ -73,11 +83,18 @@ extern int h_errno;
#ifndef C_HS
#define C_HS 4
#endif
#ifndef NOCHANGE
#define NOCHANGE 0xf
#endif
FILE *filePtr;
#ifdef __NBSD_LIBC
static struct __res_state orig;
#else
struct state orig;
extern struct state _res;
#endif
static u8_t *cname = NULL;
int getclass = C_IN;
int gettype, getdeftype = T_A;
@ -91,7 +108,7 @@ int main _ARGS(( int c, char *v[] ));
static int parsetype _ARGS(( char *s ));
static int parseclass _ARGS(( char *s ));
static void hperror _ARGS(( int errno ));
static void hperror _ARGS(( int err_no ));
static void printanswer _ARGS(( struct hostent *hp ));
static int ListHosts _ARGS(( char *namePtr, int queryType ));
static int gethostinfo _ARGS(( char *name ));
@ -111,7 +128,11 @@ main(c, v)
char **v;
{
char *domain;
#ifdef __NBSD_LIBC
struct in_addr addr;
#else
ipaddr_t addr;
#endif
register struct hostent *hp;
register char *s, *p;
register inverse = 0;
@ -195,11 +216,23 @@ main(c, v)
hperror(h_errno);
exit(1);
}
#ifdef __NBSD_LIBC
memcpy(&_res.nsaddr.sin_addr, hp->h_addr, NS_INADDRSZ);
#else
_res.nsaddr= *(ipaddr_t *)hp->h_addr;
#endif
printf("Using domain server:\n");
printanswer(hp);
}
else {
#ifdef __NBSD_LIBC
_res.nsaddr.sin_family = AF_INET;
_res.nsaddr.sin_addr = addr;
_res.nsaddr.sin_port = htons(NAMESERVER_PORT);
printf("Using domain server %s:\n",
inet_ntoa(_res.nsaddr.sin_addr));
#else
_res.nsaddr_list[0]= addr;
_res.nsport_list[0]= htons(NAMESERVER_PORT);
printf("Using domain server %s",
@ -209,6 +242,7 @@ main(c, v)
_res.nsport_list[0]= htons(atoi(p));
}
printf(":\n");
#endif
}
}
domain = v[1];
@ -340,12 +374,21 @@ printanswer(hp)
register struct hostent *hp;
{
register char **cp;
#ifdef __NBSD_LIBC
struct in_addr **hptr;
#else
register ipaddr_t **hptr;
#endif
printf("Name: %s\n", hp->h_name);
printf("Address:");
#ifdef __NBSD_LIBC
for (hptr = (struct in_addr **)hp->h_addr_list; *hptr; hptr++)
printf(" %s", inet_ntoa(**hptr));
#else
for (hptr = (ipaddr_t **)hp->h_addr_list; *hptr; hptr++)
printf(" %s", inet_ntoa(*(ipaddr_t *)*hptr));
#endif
printf("\nAliases:");
for (cp = hp->h_aliases; cp && *cp && **cp; cp++)
printf(" %s", *cp);
@ -353,10 +396,10 @@ printanswer(hp)
}
static void
hperror(errno)
int errno;
hperror(err_no)
int err_no;
{
switch(errno) {
switch(err_no) {
case HOST_NOT_FOUND:
fprintf(stderr,"Host not found.\n");
break;
@ -372,9 +415,8 @@ switch(errno) {
}
}
typedef union querybuf {
dns_hdr_t qb1;
HEADER qb1;
u8_t qb2[PACKETSZ];
} querybuf_t;
@ -450,7 +492,7 @@ getinfo(name, domain, type)
char *name, *domain;
{
dns_hdr_t *hp;
HEADER *hp;
u8_t *eom, *bp, *cp;
querybuf_t buf, answer;
int n, n1, i, j, nmx, ancount, nscount, arcount, qdcount, buflen;
@ -488,7 +530,7 @@ printinfo(answer, eom, filter, isls)
int filter;
int isls;
{
dns_hdr_t *hp;
HEADER *hp;
u8_t *bp, *cp;
int n, n1, i, j, nmx, ancount, nscount, arcount, qdcount, buflen;
u_short pref, class;
@ -496,21 +538,44 @@ printinfo(answer, eom, filter, isls)
/*
* find first satisfactory answer
*/
hp = (dns_hdr_t *) answer;
hp = (HEADER *) answer;
ancount = ntohs(hp->dh_ancount);
qdcount = ntohs(hp->dh_qdcount);
nscount = ntohs(hp->dh_nscount);
arcount = ntohs(hp->dh_arcount);
if (_res.options & RES_DEBUG || (verbose && isls == 0))
printf("rcode = %d (%s), ancount=%d\n",
#ifdef __NBSD_LIBC
hp->rcode,
DecodeError(hp->rcode),
#else
hp->dh_flag2 & DHF_RCODE,
DecodeError(hp->dh_flag2 & DHF_RCODE), ancount);
if (hp->dh_flag2 & DHF_RCODE != NOERROR ||
DecodeError(hp->dh_flag2 & DHF_RCODE),
#endif
ancount);
if (
#ifdef __NBSD_LIBC
hp->rcode != NOERROR ||
#else
hp->dh_flag2 & DHF_RCODE != NOERROR ||
#endif
(ancount+nscount+arcount) == 0) {
switch (hp->dh_flag2 & DHF_RCODE) {
switch (
#ifdef __NBSD_LIBC
hp->rcode
#else
hp->dh_flag2 & DHF_RCODE
#endif
) {
case NXDOMAIN:
/* Check if it's an authoritive answer */
if (hp->dh_flag1 & DHF_AA) {
if (
#ifdef __NBSD_LIBC
hp->aa
#else
hp->dh_flag1 & DHF_AA
#endif
) {
h_errno = HOST_NOT_FOUND;
return(0);
} else {
@ -546,14 +611,20 @@ printinfo(answer, eom, filter, isls)
bp = hostbuf;
nmx = 0;
buflen = sizeof(hostbuf);
cp = (u8_t *)answer + sizeof(dns_hdr_t);
cp = (u8_t *)answer + sizeof(HEADER);
if (qdcount) {
cp += dn_skipname((u8_t *)cp,(u8_t *)eom) + QFIXEDSZ;
while (--qdcount > 0)
cp += dn_skipname((u8_t *)cp,(u8_t *)eom) + QFIXEDSZ;
}
if (ancount) {
if (!(hp->dh_flag1 & DHF_AA))
if (!
#ifdef __NBSD_LIBC
hp->aa
#else
(hp->dh_flag1 & DHF_AA)
#endif
)
if (verbose && isls == 0)
printf("The following answer is not authoritative:\n");
while (--ancount >= 0 && cp && cp < eom) {
@ -597,7 +668,11 @@ pr_rr(cp, msg, file, filter)
int filter;
{
int type, class, dlen, n, c, proto, ttl;
#ifdef __NBSD_LIBC
struct in_addr inaddr;
#else
ipaddr_t inaddr;
#endif
u8_t *cp1;
struct protoent *protop;
struct servent *servp;
@ -751,7 +826,7 @@ pr_rr(cp, msg, file, filter)
}
break;
/* Roy end */
#ifndef __NBSD_LIBC
case T_UINFO:
if (doprint)
fprintf(file,"%c%s", punc, cp);
@ -766,7 +841,7 @@ pr_rr(cp, msg, file, filter)
cp += sizeof(int);
}
break;
#endif
case T_WKS:
if (dlen < sizeof(u_long) + 1)
break;
@ -868,12 +943,14 @@ pr_type(type)
return("MAILA");
case T_ANY: /* matches any type */
return("ANY");
#ifndef __NBSD_LIBC
case T_UINFO:
return("UINFO");
case T_UID:
return("UID");
case T_GID:
return("GID");
#endif
default:
return (sprintf(nbuf, "%d", type) == EOF ? NULL : nbuf);
}
@ -963,7 +1040,7 @@ ListHosts(namePtr, queryType)
int queryType; /* e.g. T_A */
{
querybuf_t buf, answer;
dns_hdr_t *headerPtr;
HEADER *headerPtr;
int msglen;
int amtToRead;
@ -1039,22 +1116,55 @@ ListHosts(namePtr, queryType)
}
if (_res.options & RES_DEBUG || verbose)
printf("rcode = %d (%s), ancount=%d\n",
#ifdef __NBSD_LIBC
answer.qb1.rcode,
DecodeError(answer.qb1.rcode),
ntohs(answer.qb1.ancount)
#else
answer.qb1.dh_flag2 & DHF_RCODE,
DecodeError(answer.qb1.dh_flag2 & DHF_RCODE),
ntohs(answer.qb1.dh_ancount));
ntohs(answer.qb1.dh_ancount)
#endif
);
/*
* Analyze response to our NS lookup
*/
#ifdef __NBSD_LIBC
nscount = ntohs(answer.qb1.ancount) +
ntohs(answer.qb1.nscount) +
ntohs(answer.qb1.arcount);
#else
nscount = ntohs(answer.qb1.dh_ancount) + ntohs(answer.qb1.dh_nscount) +
ntohs(answer.qb1.dh_arcount);
#endif
if (answer.qb1.dh_flag2 & DHF_RCODE != NOERROR || nscount == 0) {
switch (answer.qb1.dh_flag2 & DHF_RCODE) {
if (
#ifdef __NBSD_LIBC
answer.qb1.rcode != NOERROR || nscount == 0
#else
answer.qb1.dh_flag2 & DHF_RCODE != NOERROR || nscount == 0
#endif
) {
switch (
#ifdef __NBSD_LIBC
answer.qb1.rcode
#else
answer.qb1.dh_flag2 & DHF_RCODE
#endif
) {
case NXDOMAIN:
/* Check if it's an authoritive answer */
if (answer.qb1.dh_flag1 & DHF_AA) {
if (
#ifdef __NBSD_LIBC
answer.qb1.aa
#else
answer.qb1.dh_flag1 & DHF_AA
#endif
) {
printf("No such domain\n");
} else {
printf("Unable to get information about domain -- try again later.\n");
@ -1075,7 +1185,7 @@ ListHosts(namePtr, queryType)
return (0);
}
cp = answer.qb2 + sizeof(dns_hdr_t);
cp = answer.qb2 + sizeof(HEADER);
if (ntohs(answer.qb1.dh_qdcount) > 0)
cp += dn_skipname(cp, answer.qb2 + msglen) + QFIXEDSZ;
@ -1198,7 +1308,11 @@ again:
tcpconf.nwtc_flags= NWTC_EXCL | NWTC_LP_SEL | NWTC_SET_RA |
NWTC_SET_RP;
tcpconf.nwtc_remaddr= *(ipaddr_t *)nsipaddr[thisns];
#ifdef __NBSD_LIBC
tcpconf.nwtc_remport= _res.nsaddr.sin_port;
#else
tcpconf.nwtc_remport= _res.nsport_list[0];
#endif
result= ioctl(tcp_fd, NWIOSTCPCONF, &tcpconf);
if (result == -1)
{
@ -1295,7 +1409,11 @@ again:
break;
}
#ifdef __NBSD_LIBC
i = buf.qb1.rcode;
#else
i = buf.qb1.dh_flag2 & DHF_RCODE;
#endif
if (i != NOERROR || ntohs(buf.qb1.dh_ancount) == 0) {
if ((thisns+1) < numnsaddr &&
(i == SERVFAIL || i == NOTIMP || i == REFUSED)) {
@ -1319,7 +1437,7 @@ again:
break;
}
numAnswers++;
cp = buf.qb2 + sizeof(dns_hdr_t);
cp = buf.qb2 + sizeof(HEADER);
if (ntohs(buf.qb1.dh_qdcount) > 0)
cp += dn_skipname(cp, buf.qb2 + len) + QFIXEDSZ;
@ -1351,11 +1469,15 @@ again:
return(result);
case ERR_READING_MSG:
headerPtr = (dns_hdr_t *) &buf;
headerPtr = (HEADER *) &buf;
fprintf(stderr,"ListHosts: error receiving zone transfer:\n");
fprintf(stderr,
" result: %s, answers = %d, authority = %d, additional = %d\n",
#ifdef __NBSD_LIBC
resultcodes[headerPtr->rcode],
#else
resultcodes[headerPtr->dh_flag2 & DHF_RCODE],
#endif
ntohs(headerPtr->dh_ancount),
ntohs(headerPtr->dh_nscount),
ntohs(headerPtr->dh_arcount));

View file

@ -16,6 +16,10 @@ Created: Jan 27, 1992 by Philip Homburg
#include <string.h>
#include <unistd.h>
#ifdef __NBSD_LIBC
#include <netinet/in.h>
#endif
#include <net/netlib.h>
#include <net/hton.h>
#include <net/gen/ether.h>

View file

@ -35,6 +35,7 @@
/* remove _() stuff */
#define _(a) a
#ifndef __NBSD_LIBC
typedef unsigned long ulong;
void err(int eval, const char *fmt, ...)
{
@ -44,6 +45,7 @@ void err(int eval, const char *fmt, ...)
va_end(ap);
exit(eval);
}
#endif
/*-------------------------------------------------------------------*/
/* SHM_DEST and SHM_LOCKED are defined in kernel headers,

View file

@ -229,8 +229,11 @@ void time_functions(void)
icmp_hdr= (icmp_hdr_t *) (ip_hdr + 1);
ip_hdr->ih_vers_ihl= 0x45;
#ifdef __NBSD_LIBC
ip_hdr->ih_dst= htonl(0xFFFFFFFFL);
#else
ip_hdr->ih_dst= HTONL(0xFFFFFFFFL);
#endif
icmp_hdr->ih_type= ICMP_TYPE_ROUTE_SOL;
icmp_hdr->ih_code= 0;
icmp_hdr->ih_chksum= 0;
@ -253,7 +256,11 @@ void time_functions(void)
* broadcast them (to keep bad hosts up.)
*/
#ifdef __NBSD_LIBC
advertize(bcast ? htonl(0xFFFFFFFFL) : htonl(0x7F000001L));
#else
advertize(bcast ? HTONL(0xFFFFFFFFL) : HTONL(0x7F000001L));
#endif
next_advert= now + MaxAdvertisementInterval;
#if !__minix_vmd
/* Make sure we are listening to RIP now. */
@ -570,7 +577,11 @@ int main(int argc, char **argv)
ipopt.nwio_ttl= 1;
ipopt.nwio_df= 0;
ipopt.nwio_hdropt.iho_opt_siz= 0;
#ifdef __NBSD_LIBC
ipopt.nwio_rem= htonl(0xFFFFFFFFL);
#else
ipopt.nwio_rem= HTONL(0xFFFFFFFFL);
#endif
ipopt.nwio_proto= IPPROTO_ICMP;
if (ioctl(irdp_fd, NWIOSIPOPT, &ipopt) < 0)

View file

@ -100,14 +100,22 @@ int pencode(char *s)
for (save = s; *s && *s != '.'; ++s);
if (*s) {
*s = '\0';
#ifdef __NBSD_LIBC
fac = decode(save, facilitynames);
#else
fac = decode(save, FacNames);
#endif
if (fac < 0) bailout("unknown facility name:", save);
*s++ = '.';
} else {
fac = 0;
s = save;
}
#ifdef __NBSD_LIBC
lev = decode(s, prioritynames);
#else
lev = decode(s, PriNames);
#endif
if (lev < 0) bailout("unknown priority name:", save);
return((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
}

View file

@ -135,7 +135,11 @@ int uid; /* user id */
if (fd >= 0) close(fd);
/* Enter new fields. */
#ifdef __NBSD_LIBC
strncpy(entry.ut_name, user, sizeof(entry.ut_name));
#else
strncpy(entry.ut_user, user, sizeof(entry.ut_user));
#endif
if (hostname) strncpy(entry.ut_host, hostname, sizeof(entry.ut_host));
if (entry.ut_pid == 0) entry.ut_pid = getpid();

View file

@ -447,6 +447,10 @@ char *cxsize(struct file *f)
static int (*CMP)(struct file *f1, struct file *f2);
static int (*rCMP)(struct file *f1, struct file *f2);
#ifdef __NBSD_LIBC
#define mergesort _ls_mergesort
#endif
static void mergesort(struct file **al)
/* This is either a stable mergesort, or thermal noise, I'm no longer sure.
* It must be called like this: if (L != nil && L->next != nil) mergesort(&L);

View file

@ -13,7 +13,11 @@
#include <unistd.h>
#include <string.h>
#include <fcntl.h>
#ifdef __NBSD_LIBC
#include <compat/a.out.h>
#else
#include <minix/a.out.h>
#endif
#include "proto.h"
#define NN_UNDF 0

View file

@ -74,6 +74,7 @@ PUBLIC int Printf(const char *format, ...)
{
va_list ap;
int retval;
#ifndef __NBSD_LIBC
FILE tmp_stream;
va_start(ap, format);
@ -86,7 +87,11 @@ PUBLIC int Printf(const char *format, ...)
retval = _doprnt(format, ap, &tmp_stream);
putc('\0',&tmp_stream);
#else
va_start(ap, format);
retval = vsnprintf(outbuf, OUTBUFSIZE, format, ap);
#endif
va_end(ap);
outstr(outbuf);

View file

@ -88,6 +88,10 @@ unsigned int block_size;
FILE *proto;
#ifdef __NBSD_LIBC
#define getline _mkfs_getline
#endif
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(block_t sizeup, (char *device));
_PROTOTYPE(void super, (zone_t zones, Ino_t inodes));

View file

@ -6,6 +6,9 @@
#include <minix/minlib.h>
#include <errno.h>
#include <stdio.h>
#ifdef __NBSD_LIBC
#include <sys/stat.h>
#endif
_PROTOTYPE(int main, (int argc, char *argv []));
_PROTOTYPE(void badcomm, (void));

View file

@ -26,6 +26,10 @@ static const char version[] = "2.7";
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <sys/asynchio.h>
#ifdef __NBSD_LIBC
#include <netinet/in.h>
#include <arpa/nameser.h>
#endif
#include <net/hton.h>
#include <net/netlib.h>
#include <net/gen/in.h>
@ -43,6 +47,13 @@ static const char version[] = "2.7";
#include <paths.h>
#ifdef __NBSD_LIBC
#undef HTONL
#undef HTONS
#define HTONL htonl
#define HTONS htons
#endif
#define HTTL 3600L /* Default time to live for /etc/hosts data. */
#define SHORT_TIMEOUT 2 /* If you expect an answer soon. */
#define MEDIUM_TIMEOUT 4 /* Soon, but not that soon. */
@ -133,8 +144,8 @@ static char *nowgmt(void)
#define namencmp(n1, n2, len) strncasecmp(PC(n1), PC(n2), len)
typedef struct dns { /* A DNS packet. */
dns_hdr_t hdr; /* DNS header. */
u8_t data[PACKETSZ - sizeof(dns_hdr_t)]; /* DNS data. */
HEADER hdr; /* DNS header. */
u8_t data[PACKETSZ - sizeof(HEADER)]; /* DNS data. */
} dns_t;
/* Addres of DNS packet to octet address, or vv. */
@ -344,12 +355,25 @@ static void dns_tell(int indent, dns_t *dp, size_t size)
"NOERROR", "FORMERR", "SERVFAIL", "NXDOMAIN", "NOTIMP", "REFUSED"
};
if (size < sizeof(dns_hdr_t)) return;
if (size < sizeof(HEADER)) return;
printf("%*s", indent, "");
#ifdef __NBSD_LIBC
printf("DNS %s:", (dp->hdr.qr) ? "reply" : "query");
r = dp->hdr.rcode;
#else
printf("DNS %s:", (dp->hdr.dh_flag1 & DHF_QR) ? "reply" : "query");
r= dp->hdr.dh_flag2 & DHF_RCODE;
#endif
printf(" %s", r < arraysize(rcodes) ? rcodes[r] : itoa("ERR_%lu", r));
#ifdef __NBSD_LIBC
if (dp->hdr.aa) printf(" AA");
if (dp->hdr.tc) printf(" TC");
if (dp->hdr.rd) printf(" RD");
if (dp->hdr.ra) printf(" RA");
if (dp->hdr.ad) printf(" AD");
if (dp->hdr.cd) printf(" CD");
#else
if (dp->hdr.dh_flag1 & DHF_AA) printf(" AA");
if (dp->hdr.dh_flag1 & DHF_TC) printf(" TC");
if (dp->hdr.dh_flag1 & DHF_RD) printf(" RD");
@ -357,6 +381,7 @@ static void dns_tell(int indent, dns_t *dp, size_t size)
#ifdef DHF_AD
if (dp->hdr.dh_flag2 & DHF_AD) printf(" AD");
if (dp->hdr.dh_flag2 & DHF_CD) printf(" CD");
#endif
#endif
fputc('\n', stdout);
@ -394,9 +419,13 @@ static u32_t dns_ttl(dns_t *dp, size_t size, u32_t delta)
hasttl= hassoa= 0;
minttl= 365*24*3600L;
dlim= dns2oct(dp) + size;
if (size < sizeof(dns_hdr_t)) return 0;
if (size < sizeof(HEADER)) return 0;
#ifdef __NBSD_LIBC
rcode= dp->hdr.rcode;
#else
rcode= dp->hdr.dh_flag2 & DHF_RCODE;
#endif
count[0]= ntohs(dp->hdr.dh_qdcount);
count[1]= ntohs(dp->hdr.dh_ancount);
count[2]= ntohs(dp->hdr.dh_nscount);
@ -898,8 +927,21 @@ static int query_hosts(u8_t *qname, unsigned type, dns_t *dp, size_t *pdlen)
if (single) return 0;
/* Assume we can answer. */
#ifdef __NBSD_LIBC
dns.hdr.qr = 1;
dns.hdr.opcode = 0;
dns.hdr.aa = 1;
dns.hdr.tc = 0;
dns.hdr.rd = 0;
dns.hdr.ra = 1;
dns.hdr.unused = 0;
dns.hdr.ad = 0;
dns.hdr.cd = 0;
dns.hdr.rcode = 0;
#else
dns.hdr.dh_flag1= DHF_QR | DHF_AA;
dns.hdr.dh_flag2= DHF_RA;
#endif
dns.hdr.dh_qdcount= HTONS(1);
ancount= 0;
dns.hdr.dh_nscount= HTONS(0);
@ -1035,8 +1077,21 @@ static int query_chaos(u8_t *qname, unsigned type, dns_t *dp, size_t *pdlen)
if (type != HTONS(T_TXT) || namecmp(qname, "version.bind") != 0) return 0;
#ifdef __NBSD_LIBC
dns.hdr.qr = 1;
dns.hdr.opcode = 0;
dns.hdr.aa = 1;
dns.hdr.tc = 0;
dns.hdr.rd = 0;
dns.hdr.ra = 1;
dns.hdr.unused = 0;
dns.hdr.ad = 0;
dns.hdr.cd = 0;
dns.hdr.rcode = 0;
#else
dns.hdr.dh_flag1= DHF_QR | DHF_AA;
dns.hdr.dh_flag2= DHF_RA;
#endif
dns.hdr.dh_qdcount= HTONS(1);
dns.hdr.dh_ancount= HTONS(1);
dns.hdr.dh_nscount= HTONS(0);
@ -1104,7 +1159,11 @@ static void cache_reply(dns_t *dp, size_t dlen)
u8_t name[MAXDNAME];
u32_t minttl;
#if __NBSD_LIBC
if ((dp->hdr.rd && !dp->hdr.tc)) return;
#else
if ((dp->hdr.dh_flag1 & (DHF_RD | DHF_TC)) != DHF_RD) return;
#endif
if (dp->hdr.dh_qdcount != HTONS(1)) return;
cp= dp->data;
r= dn_expand(dns2oct(dp), dns2oct(dp) + dlen, cp, name, MAXDNAME);
@ -1188,14 +1247,27 @@ static int compose_reply(dns_t *dp, size_t *pdlen)
/* Remember ID and RD. */
id= dp->hdr.dh_id;
#ifdef __NBSD_LIBC
rd= dp->hdr.rd;
#else
rd= dp->hdr.dh_flag1 & DHF_RD;
#endif
if (r == -1) {
/* Malformed query, reply "FORMERR". */
#ifdef __NBSD_LIBC
dp->hdr.tc = 0;
dp->hdr.qr = 1;
dp->hdr.aa = 1;
dp->hdr.unused = 0;
dp->hdr.ra = 1;
dp->hdr.rcode = FORMERR;
#else
dp->hdr.dh_flag1 &= ~(DHF_TC);
dp->hdr.dh_flag1 |= DHF_QR | DHF_AA;
dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
dp->hdr.dh_flag2 |= DHF_RA | FORMERR;
#endif
} else
if (class == HTONS(C_IN) && query_hosts(name, type, dp, pdlen)) {
/* Answer to this query is in the hosts file. */
@ -1204,7 +1276,11 @@ static int compose_reply(dns_t *dp, size_t *pdlen)
if (class == HTONS(C_IN) && (qp= get_query(name, type)) != nil) {
/* Answer to this query is present in the cache. */
memcpy(dp, &qp->dns, dlen= qp->size);
#ifdef __NBSD_LIBC
dp->hdr.aa = 1;
#else
dp->hdr.dh_flag1 &= ~DHF_AA;
#endif
(void) dns_ttl(dp, dlen, now - qp->age);
if (rd) {
if (qp->stale <= now) {
@ -1223,17 +1299,34 @@ static int compose_reply(dns_t *dp, size_t *pdlen)
/* No real name daemon present, or this name has a repeated top level
* domain sequence. Reply "no such domain".
*/
#ifdef __NBSD_LIBC
dp->hdr.tc = 0;
dp->hdr.qr = 1;
dp->hdr.aa = 1;
dp->hdr.unused = 0;
dp->hdr.ra = 1;
dp->hdr.rcode = NXDOMAIN;
#else
dp->hdr.dh_flag1 &= ~(DHF_TC);
dp->hdr.dh_flag1 |= DHF_QR | DHF_AA;
dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
dp->hdr.dh_flag2 |= DHF_RA | NXDOMAIN;
#endif
} else
if (!rd) {
/* "Recursion Desired" is off, so don't bother to relay. */
#ifdef __NBSD_LIBC
dp->hdr.tc = 0;
dp->hdr.qr = 1;
dp->hdr.unused = 0;
dp->hdr.ra = 1;
dp->hdr.rcode = NOERROR;
#else
dp->hdr.dh_flag1 &= ~(DHF_TC);
dp->hdr.dh_flag1 |= DHF_QR;
dp->hdr.dh_flag2 &= ~(DHF_UNUSED | DHF_RCODE);
dp->hdr.dh_flag2 |= DHF_RA | NOERROR;
#endif
} else {
/* Caller needs to consult with a real name daemon. */
return 0;
@ -1241,8 +1334,12 @@ static int compose_reply(dns_t *dp, size_t *pdlen)
/* Copy ID and RD back to answer. */
dp->hdr.dh_id= id;
#ifdef __NBSD_LIBC
dp->hdr.rd = rd;
#else
dp->hdr.dh_flag1 &= ~DHF_RD;
dp->hdr.dh_flag1 |= rd;
#endif
*pdlen= dlen;
return 1;
}
@ -1295,8 +1392,22 @@ static void refresh_cache(void)
dlen= cp - dns2oct(&udp.dns);
udp.dns.hdr.dh_id= new_id(ID_REFRESH, my_port, ID_IPSELF);
#ifdef __NBSD_LIBC
udp.dns.hdr.qr = 0;
udp.dns.hdr.opcode = 0;
udp.dns.hdr.aa = 0;
udp.dns.hdr.tc = 0;
udp.dns.hdr.rd = 1;
udp.dns.hdr.ra = 0;
udp.dns.hdr.unused = 0;
udp.dns.hdr.ad = 0;
udp.dns.hdr.cd = 0;
udp.dns.hdr.rcode = 0;
#else
udp.dns.hdr.dh_flag1= DHF_RD;
udp.dns.hdr.dh_flag2= 0;
#endif
udp.dns.hdr.dh_qdcount= HTONS(1);
udp.dns.hdr.dh_ancount= HTONS(0);
udp.dns.hdr.dh_nscount= HTONS(0);
@ -1348,7 +1459,7 @@ static int job_read_udp(void *data, int expired)
/* Restart this job no matter what. */
newjob(job_read_udp, NEVER, nil);
if (ulen < (ssize_t) (sizeof(udp_io_hdr_t) + sizeof(dns_hdr_t))) return 1;
if (ulen < (ssize_t) (sizeof(udp_io_hdr_t) + sizeof(HEADER))) return 1;
if (debug >= 1) {
printf("%s:%u UDP ", inet_ntoa(udp.hdr.uih_src_addr),
@ -1359,7 +1470,13 @@ static int job_read_udp(void *data, int expired)
/* Check, and if necessary reinitialize my configuration. */
init_config(udp.hdr.uih_dst_addr);
if (udp.dns.hdr.dh_flag1 & DHF_QR) {
if (
#ifdef __NBSD_LIBC
udp.dns.hdr.qr
#else
udp.dns.hdr.dh_flag1 & DHF_QR
#endif
) {
/* This is a remote named reply, not a query. */
/* Response to a query previously relayed? */
@ -1918,8 +2035,21 @@ static void named_probe(ipaddr_t ip)
* "What are the name servers for the root domain?"
*/
udp.dns.hdr.dh_id= new_id(ID_PROBE, my_port, ID_IPSELF);
#ifdef __NBSD_LIBC
udp.dns.hdr.qr = 0;
udp.dns.hdr.opcode = 0;
udp.dns.hdr.aa = 0;
udp.dns.hdr.tc = 0;
udp.dns.hdr.rd = 0;
udp.dns.hdr.ra = 0;
udp.dns.hdr.unused = 0;
udp.dns.hdr.ad = 0;
udp.dns.hdr.cd = 0;
udp.dns.hdr.rcode = 0;
#else
udp.dns.hdr.dh_flag1= 0;
udp.dns.hdr.dh_flag2= 0;
#endif
udp.dns.hdr.dh_qdcount= HTONS(1);
udp.dns.hdr.dh_ancount= HTONS(0);
udp.dns.hdr.dh_nscount= HTONS(0);

View file

@ -7,7 +7,11 @@
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#ifdef __NBSD_LIBC
#include <a.out.h>
#else
#include <minix/a.out.h>
#endif
#include <minix/config.h>
#include <minix/const.h>
#include <stdio.h>

View file

@ -68,6 +68,10 @@ static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
* Routines which handle command line options
*/
#ifdef __NBSD_LIBC
#define getline pax_getline
#endif
static char flgch[] = FLGCH; /* list of all possible flags */
static OPLIST *ophead = NULL; /* head for format specific options -x */
static OPLIST *optail = NULL; /* option tail */

View file

@ -24,6 +24,11 @@
#include <string.h>
#include <unistd.h>
#ifdef __NBSD_LIBC
#define setkey pwdauth_setkey
#define encrypt pwdauth_encrypt
#endif
#define LEN 1024
char SHADOW[] = "/etc/shadow";

View file

@ -40,6 +40,11 @@ Changed: Dec 11, 2000 by Kees J. Bot
#define MAX_RARP_RETRIES 5
#define RARP_TIMEOUT 5
#ifdef __NBSD_LIBC
#undef HTONS
#define HTONS htons
#endif
typedef struct rarp46
{
ether_addr_t a46_dstaddr;

View file

@ -55,9 +55,17 @@ void write_log()
fd = open(WTMP,O_APPEND|O_WRONLY,1);
if (fd) {
if (strcmp(prog,"reboot"))
#ifdef __NBSD_LIBC
strcpy (wtmp.ut_name, prog);
#else
strcpy (wtmp.ut_user, prog);
#endif
else
#ifdef __NBSD_LIBC
strcpy (wtmp.ut_name, "shutdown"); /* last ... */
#else
strcpy (wtmp.ut_user, "shutdown"); /* last ... */
#endif
strcpy (wtmp.ut_id, "~~");
strcpy (wtmp.ut_line, "~");
wtmp.ut_pid = 0;

View file

@ -396,8 +396,14 @@ int crash_check()
crashed = (lseek(fd, - (off_t) sizeof(last), SEEK_END) == -1
|| read(fd, (void *) &last, sizeof(last)) != sizeof(last)
|| last.ut_line[0] != '~'
#ifdef __NBSD_LIBC
|| (strncmp(last.ut_name, "shutdown", sizeof(last.ut_name))
&& strncmp(last.ut_name, "halt", sizeof(last.ut_name)))
#else
|| (strncmp(last.ut_user, "shutdown", sizeof(last.ut_user))
&& strncmp(last.ut_user, "halt", sizeof(last.ut_user))));
&& strncmp(last.ut_user, "halt", sizeof(last.ut_user)))
#endif
);
close(fd);
return crashed;
}

View file

@ -69,7 +69,6 @@ unsigned int sign = 0;
unsigned int bits = 8;
unsigned int stereo = 0;
unsigned int rate = 22050;
unsigned int time = 10;
int old_stdin;
struct termios old_tty, new_tty;

View file

@ -19,6 +19,9 @@
#include <sys/types.h>
#include <sys/ioctl.h>
#endif
#ifdef __NBSD_LIBC
#include <unistd.h>
#endif
/* Default settings, the Minix ones are defined in <termios.h> */

View file

@ -502,7 +502,11 @@ void cfline(char *line, struct filed * fLog)
while (strchr(", ;", *q)) q++;
/* Decode priority name */
#ifdef __NBSD_LIBC
pri = decode(buf, prioritynames);
#else
pri = decode(buf, PriNames);
#endif
if (pri < 0) {
sprintf(xbuf, "unknown priority name \"%s\"", buf);
logerror(xbuf);
@ -520,7 +524,11 @@ void cfline(char *line, struct filed * fLog)
fLog->f_pmask[ix] = pri;
}
} else {
#ifdef __NBSD_LIBC
ix = decode(buf, facilitynames);
#else
ix = decode(buf, FacNames);
#endif
if (ix < 0) {
sprintf(xbuf, "unknown facility name \"%s\"", buf);
logerror(xbuf);

View file

@ -67,8 +67,13 @@ FILE *fp;
return(-1);
}
fclose(fp);
#ifdef __NBSD_LIBC
strncpy(luser, utmp.ut_name, USER_SIZE < sizeof(utmp.ut_name) ?
USER_SIZE : sizeof(utmp.ut_name));
#else
strncpy(luser, utmp.ut_user, USER_SIZE < sizeof(utmp.ut_user) ?
USER_SIZE : sizeof(utmp.ut_user));
#endif
luser[USER_SIZE] = '\0';
/* get local tty */

View file

@ -31,7 +31,11 @@ struct utmp utmp;
while(read(fd, &utmp, sizeof(struct utmp)) == sizeof(struct utmp)) {
if(utmp.ut_type != USER_PROCESS) continue;
#ifdef __NBSD_LIBC
if(strncmp(utmp.ut_name, name, sizeof(utmp.ut_name))) continue;
#else
if(strncmp(utmp.ut_user, name, sizeof(utmp.ut_user))) continue;
#endif
if(*tty && strncmp(utmp.ut_line, tty, sizeof(utmp.ut_line))) continue;
strcpy(tty, utmp.ut_line);
ret = SUCCESS;

View file

@ -728,7 +728,9 @@
/* #undef gid_t */
/* Define to `unsigned long' if <sys/types.h> does not define. */
#ifndef __NBSD_LIBC
#define id_t unsigned long
#endif
/* Define to the type of a signed integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */

View file

@ -24,6 +24,10 @@ int cflag = 0;
int fields = 0;
int chars = 0;
#ifdef __NBSD_LIBC
#define getline unix_getline
#endif
_PROTOTYPE(int main, (int argc, char **argv));
_PROTOTYPE(FILE *xfopen, (char *fn, char *mode));
_PROTOTYPE(char *skip, (char *s));

View file

@ -21,9 +21,11 @@
extern char *optarg;
extern int optind;
#ifndef __NBSD_LIBC
typedef unsigned char u_int8_t;
typedef unsigned short int u_int16_t;
typedef unsigned long int u_int32_t;
#endif
#ifndef min
#define min(a,b) ((a) < (b) ? (a) : (b))

View file

@ -1,7 +1,7 @@
# $NetBSD: Makefile.inc,v 1.7 2009/01/04 17:54:29 pooka Exp $
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
|| ${LIB} == "rump")
|| ${LIB} == "rump" || (defined(__MINIX) && ${LIB} == "sys"))
SRCS+= atomic_add_64_cas.c atomic_add_64_nv_cas.c atomic_and_64_cas.c \
atomic_and_64_nv_cas.c atomic_dec_64_cas.c atomic_dec_64_nv_cas.c \

View file

@ -1,6 +1,6 @@
diff -ru /home/netbsd/src/common/lib/libc/Makefile.inc ./Makefile.inc
--- /home/netbsd/src/common/lib/libc/Makefile.inc 2008-10-27 03:01:48.000000000 +0000
+++ ./Makefile.inc 2011-02-15 13:10:57.000000000 +0000
diff -ru nbsdsrc/src/common/lib/libc/Makefile.inc common/lib/libc/Makefile.inc
--- nbsdsrc/src/common/lib/libc/Makefile.inc
+++ common/lib/libc/Makefile.inc
@@ -1,7 +1,11 @@
# $NetBSD: Makefile.inc,v 1.10 2008/10/26 07:22:50 mrg Exp $
@ -13,9 +13,21 @@ diff -ru /home/netbsd/src/common/lib/libc/Makefile.inc ./Makefile.inc
COMMON_CODEDIRS+=hash/sha1 hash/sha2 hash/rmd160
.if defined(COMMON_MACHINE_ARCH) && !empty(COMMON_MACHINE_ARCH) && \
diff -ru /home/netbsd/src/common/lib/libc/arch/i386/string/strchr.S ./arch/i386/string/strchr.S
--- /home/netbsd/src/common/lib/libc/arch/i386/string/strchr.S 2009-07-18 03:01:04.000000000 +0000
+++ ./arch/i386/string/strchr.S 2011-02-15 13:26:06.000000000 +0000
diff -ru nbsdsrc/src/common/lib/libc/arch/i386/atomic/Makefile.inc common/lib/libc/arch/i386/atomic/Makefile.inc
--- nbsdsrc/src/common/lib/libc/arch/i386/atomic/Makefile.inc
+++ common/lib/libc/arch/i386/atomic/Makefile.inc
@@ -1,7 +1,7 @@
# $NetBSD: Makefile.inc,v 1.7 2009/01/04 17:54:29 pooka Exp $
.if defined(LIB) && (${LIB} == "kern" || ${LIB} == "c" || ${LIB} == "pthread" \
- || ${LIB} == "rump")
+ || ${LIB} == "rump" || (defined(__MINIX) && ${LIB} == "sys"))
SRCS+= atomic_add_64_cas.c atomic_add_64_nv_cas.c atomic_and_64_cas.c \
atomic_and_64_nv_cas.c atomic_dec_64_cas.c atomic_dec_64_nv_cas.c \
diff -ru nbsdsrc/src/common/lib/libc/arch/i386/string/strchr.S common/lib/libc/arch/i386/string/strchr.S
--- nbsdsrc/src/common/lib/libc/arch/i386/string/strchr.S
+++ common/lib/libc/arch/i386/string/strchr.S
@@ -100,4 +100,8 @@
popl %esi
ret
@ -25,9 +37,9 @@ diff -ru /home/netbsd/src/common/lib/libc/arch/i386/string/strchr.S ./arch/i386/
+#else
STRONG_ALIAS(index,strchr)
+#endif
diff -ru /home/netbsd/src/common/lib/libc/arch/i386/string/strrchr.S ./arch/i386/string/strrchr.S
--- /home/netbsd/src/common/lib/libc/arch/i386/string/strrchr.S 2009-07-18 03:01:04.000000000 +0000
+++ ./arch/i386/string/strrchr.S 2011-02-15 13:27:15.000000000 +0000
diff -ru nbsdsrc/src/common/lib/libc/arch/i386/string/strrchr.S common/lib/libc/arch/i386/string/strrchr.S
--- nbsdsrc/src/common/lib/libc/arch/i386/string/strrchr.S
+++ common/lib/libc/arch/i386/string/strrchr.S
@@ -93,4 +93,8 @@
popl %esi
ret

View file

@ -1,4 +1,10 @@
Populate it with new includes; you need the new install:
# cd /usr/src/commands/install
# make clean install
# cd /usr/src
# make includes
20110228:
(Next release bumped to MINIX 3.2.0.)
ELF support in the base system. /usr/lib libraries

View file

@ -1,2 +1,8 @@
.if (${NBSD_LIBC} != "no")
CPPFLAGS+= -D_MINIX -D_NETBSD_SOURCE
LDADD+= -lminlib -lcompat_minix
DEPEND+= ${LIBMINLIB} ${LIBCOMPAT_MINIX}
.else
CPPFLAGS+= -D_MINIX -D_POSIX_SOURCE
.endif
BINDIR?=/usr/sbin

View file

@ -107,7 +107,7 @@ newroot: ../../commands/newroot/newroot.sh
sysenv: ../../commands/sysenv/sysenv
install ${STRIPFLAG} ../../commands/$@/$@ $@
../../commands/sysenv:
../../commands/sysenv/sysenv:
$(MAKE) -C ../../commands/sysenv
sh: ../../commands/ash/sh
@ -119,7 +119,7 @@ sh: ../../commands/ash/sh
service: ../../commands/service/service
install ${STRIPFLAG} ../../commands/service/$@ $@
../../commands/service:
../../commands/service/service:
$(MAKE) -C ../../commands/service
mfs: ../../servers/mfs/mfs

View file

@ -1,5 +1,5 @@
boot
420 440
640 440
d--755 0 0
bin d--755 0 0
cdprobe ---755 0 0 cdprobe

View file

@ -12,7 +12,11 @@ that data into a seed for a psuedo random number generator.
#include "assert.h"
#include "random.h"
#ifdef __NBSD_LIBC
#include <sys/sha2.h>
#else
#include <minix/sha2.h>
#endif
#include "aes/rijndael.h"
#define N_DERIV 16

View file

@ -29,9 +29,15 @@ LDFLAGS+= -T ${.CURDIR}/arch/${ARCH}/kernel.lds
.endif
LDFLAGS+= -nostdlib -L${LIBDIR}
CFLAGS+=-march=i386
.if (${NBSD_LIBC} != "no")
LDADD+= -lminlib
DPADD+= ${LIBMINLIB}
CPPFLAGS+= -D_NETBSD_SOURCE
.else
DPADD+= ${LIBC}
LDADD+= -lgcc -lc -lgcc
.endif
.endif
CPPFLAGS+= -I${.CURDIR} -I${.CURDIR}/arch/${ARCH}/include -I${MINIXSRCDIR}
AFLAGS+= -I${.CURDIR} -I${.CURDIR}/arch/${ARCH}/include -I${MINIXSRCDIR}

View file

@ -195,7 +195,7 @@ _PROTOTYPE( __dead void arch_monitor, (void) );
_PROTOTYPE( void arch_get_aout_headers, (int i, struct exec *h) );
#endif
_PROTOTYPE( void restore_user_context, (struct proc * p) );
_PROTOTYPE( void read_tsc, (unsigned long *high, unsigned long *low) );
_PROTOTYPE( void read_tsc, (u32_t *high, u32_t *low) );
_PROTOTYPE( int arch_init_profile_clock, (u32_t freq) );
_PROTOTYPE( void arch_stop_profile_clock, (void) );
_PROTOTYPE( void arch_ack_profile_clock, (void) );

View file

@ -1,8 +1,23 @@
.include <bsd.own.mk>
SUBDIR= csu libc libcurses libdriver libnetdriver libedit libm libsys \
libtimers libutil libbz2 libl libhgfs libz libfetch libarchive \
libvtreefs libaudiodriver libmthread libexec libdevman libusb \
.if defined(NBSD_LIBC) && (${NBSD_LIBC} != "no")
LIBC_DIR= nbsd_libc
LIBM_DIR= nbsd_libm
LIBCOMPAT_DIR= nbsd_libcompat_minix
LIBMINLIB_DIR= nbsd_libminlib
LIBASYN_DIR= nbsd_libasyn
.endif
LIBC_DIR?= libc
LIBM_DIR?= libm
LIBCOMPAT_DIR?=
LIBMINLIB_DIR?=
LIBASYN_DIR?=
SUBDIR= csu ${LIBCOMPAT_DIR} ${LIBC_DIR} libcurses libdriver libnetdriver \
libedit ${LIBM_DIR} libsys libtimers libutil libbz2 libl libhgfs \
libz libfetch libarchive libvtreefs libaudiodriver libmthread \
libexec libdevman libusb ${LIBMINLIB_DIR} ${LIBASYN_DIR} \
libddekit
.if ${COMPILER_TYPE} == "ack"
@ -32,3 +47,4 @@ clean_all:
sh gnu_build.sh clean
sh elf_build_base.sh clean
sh elf_build.sh clean

View file

@ -1,2 +1,7 @@
.if defined(NBSD_LIBC) && (${NBSD_LIBC} == "yes")
CPPFLAGS+= -D_MINIX -D_NETBSD_SOURCE
AFLAGS+= -D_MINIX
.else
CPPFLAGS+= -D_MINIX -D_POSIX_SOURCE
AFLAGS+= -D_MINIX -D_POSIX_SOURCE
.endif

View file

@ -4,5 +4,6 @@ export CC=clang
export COMPILER_TYPE=gnu
export PATH=$PATH:/usr/pkg/bin:/usr/gnu_cross/bin
export MAKEOBJDIR=obj-elf-clang
export NBSD_LIBC=${NBSD_LIBC}
make $@

View file

@ -6,6 +6,7 @@ export CC=i386-pc-minix3-gcc
export COMPILER_TYPE=gnu
export MAKEOBJDIR=obj-elf
export PATH=$PATH:/usr/gnu_cross/bin
export NBSD_LIBC=${NBSD_LIBC}
if [ "$@" != clean ]
then echo "$0: Unexpected arguments $@"

View file

@ -4,7 +4,9 @@ set -e
export CC=clang
export COMPILER_TYPE=gnu
export MAKEOBJDIR=obj-elf-base
export PATH=$PATH:/usr/pkg/bin
make $@
export MAKEOBJDIR=obj-elfbase-nbsd
make $@ NBSD_LIBC=yes
export MAKEOBJDIR=obj-elfbase
make $@ NBSD_LIBC=no

View file

@ -1,7 +1,9 @@
#!/bin/sh
export CC=gcc
export MAKEOBJDIR=obj-gnu
export PATH=$PATH:/usr/pkg/bin
make $@
export MAKEOBJDIR=obj-gnu-nbsd
make $@ NBSD_LIBC=yes
export MAKEOBJDIR=obj-gnu
make $@ NBSD_LIBC=no

View file

@ -65,7 +65,11 @@ SRCS+= minix_utils.c
.endif
CPPFLAGS+= -DHAVE_CONFIG_H
.if (${NBSD_LIBC} != "no")
INCSDIR= /usr/netbsd/include
.else
INCSDIR= /usr/include
.endif
INCS= archive.h \
archive_entry.h

View file

@ -710,7 +710,9 @@
#define _POSIX_1_SOURCE 2
/* Define to 1 if you need to in order for `stat' and other things to work. */
#ifndef __NBSD_LIBC
#define _POSIX_SOURCE 1
#endif
/* Define for Solaris 2.5.1 so the uint64_t typedef from <sys/synch.h>,
<pthread.h>, or <semaphore.h> is not used. If the typedef were allowed, the
@ -728,7 +730,9 @@
/* #undef gid_t */
/* Define to `unsigned long' if <sys/types.h> does not define. */
#ifndef __NBSD_LIBC
#define id_t unsigned long
#endif
/* Define to the type of a signed integer type of width exactly 64 bits if
such a type exists and the standard includes do not define it. */

View file

@ -8,6 +8,10 @@ SRCS= bzlib.c blocksort.c compress.c crctable.c decompress.c \
huffman.c randtable.c
CPPFLAGS+= -I ${BZ2DIR}
INCS= bzlib.h
.if (${NBSD_LIBC} != "no")
INCSDIR= /usr/netbsd/include
.else
INCSDIR= /usr/include
.endif
.include <bsd.lib.mk>

View file

@ -10,6 +10,10 @@ SRCS = pci.c printf.c mem.c pgtab.c dde.c initcall.c thread.c condvar.c lock.c s
CFLAGS += -Wall
.if ${NBSD_LIBC} != "no"
CFLAGS += -D_NETBSD_SOURCE
.endif
.endif
.include <bsd.lib.mk>

View file

@ -474,7 +474,7 @@ PUBLIC void _ddekit_print_backtrace(ddekit_thread_t *th)
bp =th->jb[0].__bp;
#else /* !__ACK__ */
#include <sys/jmp_buf.h>
#if defined(JB_PC) && defined(JB_SP)
#if defined(JB_BP)
/* um, yikes. */
bp = (unsigned long) *((void **)(&((char *)th->jb)[JB_BP]));
#else

View file

@ -56,7 +56,13 @@ int read_header_elf(
}
phdr = (const Elf_Phdr *)(exec_hdr + hdr->e_phoff);
if (!_minix_aligned(phdr, Elf_Addr)) {
if (
#ifdef __NBSD_LIBC
rounddown((uintptr_t)phdr, sizeof(Elf_Addr)) != (uintptr_t)phdr
#else
!_minix_aligned(phdr, Elf_Addr)
#endif
) {
return ENOEXEC;
}

View file

@ -1,6 +1,8 @@
/* Part of libhgfs - (c) 2009, D.C. van Moolenbroek */
#ifndef __NBSD_LIBC
#define _POSIX_SOURCE 1 /* need PATH_MAX */
#endif
#define _SYSTEM 1 /* need negative error codes */
#include <minix/config.h>

View file

@ -1,4 +1,5 @@
# Makefile for libsys
.include <bsd.own.mk>
LIB= sys
@ -128,4 +129,8 @@ SRCS= \
CPPFLAGS.sched_start.c+= -I${MINIXSRCDIR}
.if (${NBSD_LIBC} != "no")
.include "Makefile.libc.inc"
.endif
.include <bsd.lib.mk>

View file

@ -0,0 +1,136 @@
#
# Minimal libc for servers and drivers.
#
LIBCSRCDIR=${MINIXSRCDIR}/lib/nbsd_libc
.if (${NBSD_LIBC} != "no")
MACHINE_ARCH=${MACHINE}
#
# Shared libc with userspace (/common/lib/libc)
#
.include "${MINIXSRCDIR}/common/lib/libc/Makefile.inc"
.include "${.CURDIR}/arch/${MACHINE}/Makefile.libc.inc"
.if empty(SRCS:Mbyte_swap_8.*)
SRCS+= bswap64.c
.endif
.if (${MACHINE_ARCH} != "alpha") && \
(${MACHINE_ARCH} != "mips64eb") && \
(${MACHINE_ARCH} != "mips64el") && \
(${MACHINE_ARCH} != "powerpc64") && \
(${MACHINE_ARCH} != "sparc64") && \
(${MACHINE_ARCH} != "x86_64")
# Quad support
SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c \
iordi3.c lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c \
notdi2.c qdivrem.c subdi3.c ucmpdi2.c udivdi3.c umoddi3.c \
xordi3.c
.endif
.for i in \
random.c strtoll.c strtoul.c strtoull.c strtoumax.c \
memchr.c memcmp.c memcpy.c memmove.c popcount32.c popcount64.c \
strcasecmp.c strcat.c strchr.c strcmp.c strcpy.c strlcat.c \
strlcpy.c strlen.c strncasecmp.c strncmp.c strncpy.c strrchr.c \
strsep.c strstr.c ptree.c rb.c sha1.c sha2.c
SRCS+= ${i}
CPPFLAGS.${i}+= -D_LIBC -I${LIBCSRCDIR}/include
.endfor
.if empty(SRCS:Mmemset2.*)
SRCS+= memset.c
.endif
#
# Customized versions of libc functions.
#
SRCS+= calloc.c malloc.c
SRCS+= fputs.c _stdfile.c
CPPFLAGS.fputs.c+= -I${LIBCSRCDIR}/include
#
# Functions imported directly from the libc.
#
# Import from stdio
.for i in sprintf.c fprintf.c perror.c vsnprintf.c snprintf.c
.PATH.c: ${LIBCSRCDIR}/stdio
CPPFLAGS.${i}= -I${LIBCSRCDIR}/stdio -I${LIBCSRCDIR}/include
SRCS+= ${i}
.endfor
# Import from stdlib
.for i in abort.c atexit.c atoi.c exit.c getenv.c \
getopt.c ldiv.c setenv.c
.PATH.c: ${LIBCSRCDIR}/stdlib
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/stdlib -I${LIBCSRCDIR}/include
.endfor
# Import from gen
errlist.c: ${LIBCSRCDIR}/gen/errlist-minix.awk \
${MINIXSRCDIR}/nbsd_include/sys/errno.h
${TOOL_AWK} -f ${.ALLSRC} > ${.TARGET}
.for i in assert.c _errno.c errno.c _env.c errlist.c \
execle.c getprogname.c sleep.c time.c \
ctype_.c isctype.c tolower_.c toupper_.c \
infinityf_ieee754.c infinity_ieee754.c \
fpclassifyf_ieee754.c fpclassifyd_ieee754.c \
isinff_ieee754.c isinfd_ieee754.c \
isnanf_ieee754.c isnand_ieee754.c \
isfinitef_ieee754.c isfinited_ieee754.c \
signbitf_ieee754.c signbitd_ieee754.c \
nanf.c infinityl.c
.PATH.c: ${LIBCSRCDIR}/arch/${MACHINE}/gen ${LIBCSRCDIR}/gen/minix \
${LIBCSRCDIR}/gen ${LIBCSRCDIR}
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include
.endfor
CPPFLAGS.ctype_.c+= -I${LIBCSRCDIR}/locale
CPPFLAGS.isctype.c+= -I${LIBCSRCDIR}/locale
CPPFLAGS.tolower_.c+= -I${LIBCSRCDIR}/locale
CPPFLAGS.toupper_.c+= -I${LIBCSRCDIR}/locale
# Import from regex
.for i in regcomp.c regerror.c regexec.c regfree.c
.PATH.c: ${LIBCSRCDIR}/regex
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include
.endfor
# Import from string
.for i in strcspn.c strerror.c strerror_r.c strtol.c \
bcmp.S bcopy.S bzero.S
.PATH.S: ${LIBCSRCDIR}/arch/${MACHINE}/string
.PATH.c: ${LIBCSRCDIR}/string
SRCS+= ${i}
CPPFLAGS.${i}+= -D_LIBC -I${LIBCSRCDIR}/include
.endfor
CPPFLAGS.strtol.c+= -I${LIBCSRCDIR}/../../common/lib/libc/stdlib
# Import from time
.for i in asctime.c localtime.c strftime.c
.PATH.c: ${LIBCSRCDIR}/time
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include
.endfor
# Import from locale
.for i in _def_time.c
.PATH.c: ${LIBCSRCDIR}/locale
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include -I${LIBCSRCDIR}/locale
.endfor
# Import from sys-minix
.for i in access.c brk.c close.c environ.c execve.c fork.c \
getgid.c getpid.c getuid.c gettimeofday.c loadname.c \
link.c mknod.c mmap.c nanosleep.c open.c read.c sbrk.c \
select.c setuid.c stat.c stime.c syscall.c umask.c \
unlink.c waitpid.c \
brksize.S _ipc.S _senda.S
.PATH.c: ${LIBCSRCDIR}/sys-minix
.PATH.S: ${LIBCSRCDIR}/arch/${MACHINE}/sys-minix
SRCS+= ${i}
CPPFLAGS.${i}+= -I${LIBCSRCDIR}/include
.endfor
CPPFLAGS+= -D_LIBSYS
.endif

50
lib/libsys/_stdfile.c Normal file
View file

@ -0,0 +1,50 @@
/* $NetBSD: findfp.c,v 1.25 2010/09/06 14:52:55 christos Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Chris Torek.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <stdio.h>
#include <unistd.h>
#define std(flags, file) \
/* p r w flags file bf lfbsize cookie close */ \
{ NULL, 0, 0, flags, file, { NULL, 0 }, 0, __sF + file, NULL, \
/* read seek write ext up */ \
NULL, NULL, NULL, { NULL, 0 }, NULL, \
/* ur ubuf, nbuf lb blksize offset */ \
0, { '\0', '\0', '\0' }, { '\0' }, { NULL, 0 }, 0, (fpos_t)0 }
FILE __sF[3] = {
std(__SRD, STDIN_FILENO), /* stdin */
std(__SWR, STDOUT_FILENO), /* stdout */
std(__SWR|__SNBF, STDERR_FILENO) /* stderr */
};

7
lib/libsys/abort.c Normal file
View file

@ -0,0 +1,7 @@
#include <stdlib.h>
#include <minix/sysutil.h>
void abort()
{
panic("Abort.");
}

View file

@ -0,0 +1,4 @@
SRCS+= byte_swap_2.S byte_swap_4.S ffs.S
SRCS+= memchr.S memcmp.S memcpy.S memmove.S memset.S \
strcat.S strchr.S strcmp.S strcpy.S strlen.S \
strncmp.S strrchr.S

View file

@ -4,6 +4,8 @@
#include <assert.h>
#include <stdio.h>
#ifndef __NBSD_LIBC
#include <minix/config.h>
#include <minix/const.h>
#include <minix/sysutil.h>
@ -11,3 +13,36 @@
void __bad_assertion(const char *mess) {
panic("%s", mess);
}
#else /* NBSD_LIBC */
#include <sys/types.h>
#include <stdlib.h>
void
__assert13(file, line, function, failedexpr)
const char *file, *function, *failedexpr;
int line;
{
(void)fprintf(stderr,
"assertion \"%s\" failed: file \"%s\", line %d%s%s%s\n",
failedexpr, file, line,
function ? ", function \"" : "",
function ? function : "",
function ? "\"" : "");
abort();
/* NOTREACHED */
}
void
__assert(file, line, failedexpr)
const char *file, *failedexpr;
int line;
{
__assert13(file, line, NULL, failedexpr);
/* NOTREACHED */
}
#endif /* NBSD_LIBC */

28
lib/libsys/calloc.c Normal file
View file

@ -0,0 +1,28 @@
/* $Header$ */
#include <stdlib.h>
/* replace undef by define */
#define ALIGN_EIGHT_BYTES /* Use 8-byte alignment. */
#ifdef ALIGN_EIGHT_BYTES
#define ALIGN_SIZE 8
#else
#define ALIGN_SIZE sizeof(size_t)
#endif
#define ALIGN(x) (((x) + (ALIGN_SIZE - 1)) & ~(ALIGN_SIZE - 1))
void *
calloc(size_t nelem, size_t elsize)
{
register char *p;
register size_t *q;
size_t size = ALIGN(nelem * elsize);
p = malloc(size);
if (p == NULL) return NULL;
q = (size_t *) (p + size);
while ((char *) q > p) *--q = 0;
return p;
}

125
lib/libsys/errlist.c Normal file
View file

@ -0,0 +1,125 @@
/* Automatically generated file; do not edit */
#include <sys/cdefs.h>
__RCSID("$NetBSD: errlist.awk,v 1.4 2010/12/16 22:52:32 joerg Exp $");
#include <errno.h>
static const char *const errlist[] = {
[0] = "Undefined error: 0", /* 0 - ENOERROR */
[99] = "generic error", /* 99 - EGENERIC */
[1] = "operation not permitted", /* 1 - EPERM */
[2] = "no such file or directory", /* 2 - ENOENT */
[3] = "no such process", /* 3 - ESRCH */
[4] = "interrupted function call", /* 4 - EINTR */
[5] = "input/output error", /* 5 - EIO */
[6] = "no such device or address", /* 6 - ENXIO */
[7] = "arg list too long", /* 7 - E2BIG */
[8] = "exec format error", /* 8 - ENOEXEC */
[9] = "bad file descriptor", /* 9 - EBADF */
[10] = "no child process", /* 10 - ECHILD */
[11] = "resource temporarily unavailable", /* 11 - EAGAIN */
[12] = "not enough space", /* 12 - ENOMEM */
[13] = "permission denied", /* 13 - EACCES */
[14] = "bad address", /* 14 - EFAULT */
[15] = "Extension: not a block special file", /* 15 - ENOTBLK */
[16] = "resource busy", /* 16 - EBUSY */
[17] = "file exists", /* 17 - EEXIST */
[18] = "improper link", /* 18 - EXDEV */
[19] = "no such device", /* 19 - ENODEV */
[20] = "not a directory", /* 20 - ENOTDIR */
[21] = "is a directory", /* 21 - EISDIR */
[22] = "invalid argument", /* 22 - EINVAL */
[23] = "too many open files in system", /* 23 - ENFILE */
[24] = "too many open files", /* 24 - EMFILE */
[25] = "inappropriate I/O control operation", /* 25 - ENOTTY */
[26] = "no longer used", /* 26 - ETXTBSY */
[27] = "file too large", /* 27 - EFBIG */
[28] = "no space left on device", /* 28 - ENOSPC */
[29] = "invalid seek", /* 29 - ESPIPE */
[30] = "read-only file system", /* 30 - EROFS */
[31] = "too many links", /* 31 - EMLINK */
[32] = "broken pipe", /* 32 - EPIPE */
[33] = "domain error (from ANSI C std )", /* 33 - EDOM */
[34] = "result too large (from ANSI C std )", /* 34 - ERANGE */
[35] = "resource deadlock avoided", /* 35 - EDEADLK */
[36] = "file name too long", /* 36 - ENAMETOOLONG */
[37] = "no locks available", /* 37 - ENOLCK */
[38] = "function not implemented", /* 38 - ENOSYS */
[39] = "directory not empty", /* 39 - ENOTEMPTY */
[40] = "too many levels of symlinks detected", /* 40 - ELOOP */
[41] = "service restarted", /* 41 - ERESTART */
[43] = "Identifier removed", /* 43 - EIDRM */
[44] = "illegal byte sequence", /* 44 - EILSEQ */
[45] = "No message of desired type", /* 45 - ENOMSG */
[46] = "Value too large to be stored in data type",/* 46 - EOVERFLOW */
[50] = "invalid packet size for some protocol",/* 50 - EPACKSIZE */
[51] = "not enough buffers left", /* 51 - ENOBUFS */
[52] = "illegal ioctl for device", /* 52 - EBADIOCTL */
[53] = "badmode in ioctl", /* 53 - EBADMODE */
[54] = "call would block on nonblocking socket",/* 54 - EWOULDBLOCK */
[55] = "network unreachable", /* 55 - ENETUNREACH */
[56] = "host unreachable", /* 56 - EHOSTUNREACH */
[57] = "already connected", /* 57 - EISCONN */
[58] = "address in use", /* 58 - EADDRINUSE */
[59] = "connection refused", /* 59 - ECONNREFUSED */
[60] = "connection reset", /* 60 - ECONNRESET */
[61] = "connection timed out", /* 61 - ETIMEDOUT */
[62] = "urgent data present", /* 62 - EURG */
[63] = "no urgent data present", /* 63 - ENOURG */
[64] = "no connection (yet or anymore )", /* 64 - ENOTCONN */
[65] = "a write call to a shutdown connection",/* 65 - ESHUTDOWN */
[66] = "no such connection", /* 66 - ENOCONN */
[67] = "address family not supported", /* 67 - EAFNOSUPPORT */
[68] = "protocol not supported by AF", /* 68 - EPROTONOSUPPORT */
[69] = "Protocol wrong type for socket", /* 69 - EPROTOTYPE */
[70] = "Operation now in progress", /* 70 - EINPROGRESS */
[71] = "Can't assign requested address", /* 71 - EADDRNOTAVAIL */
[72] = "Connection already in progress", /* 72 - EALREADY */
[73] = "Message too long", /* 73 - EMSGSIZE */
[74] = "Socket operation on non-socket", /* 74 - ENOTSOCK */
[75] = "Protocol not available", /* 75 - ENOPROTOOPT */
[76] = "Operation not supported", /* 76 - EOPNOTSUPP */
[77] = "network is down", /* 77 - ENETDOWN */
[78] = "Protocol family not supported", /* 78 - EPFNOSUPPORT */
[79] = "Destination address required", /* 79 - EDESTADDRREQ */
[80] = "Host is down", /* 80 - EHOSTDOWN */
[81] = "Network dropped connection on reset", /* 81 - ENETRESET */
[82] = "Socket type not supported", /* 82 - ESOCKTNOSUPPORT */
[83] = "Software caused connection abort", /* 83 - ECONNABORTED */
[84] = "Too many references: can't splice", /* 84 - ETOOMANYREFS */
[101] = "can't send message due to deadlock", /* 101 - ELOCKED */
[102] = "illegal system call number", /* 102 - EBADCALL */
[103] = "bad source or destination process", /* 103 - EBADSRCDST */
[104] = "no permission for system call", /* 104 - ECALLDENIED */
[105] = "source or destination is not alive", /* 105 - EDEADSRCDST */
[106] = "source or destination is not ready", /* 106 - ENOTREADY */
[107] = "destination cannot handle request", /* 107 - EBADREQUEST */
[110] = "IPC trap not allowed", /* 110 - ETRAPDENIED */
[201] = "pseudo-code: don't send a reply", /* 201 - EDONTREPLY */
[150] = "Inappropriate file type or format", /* 150 - EFTYPE */
[151] = "Authentication error", /* 151 - EAUTH */
[152] = "Need authenticator", /* 152 - ENEEDAUTH */
[153] = "Operation canceled", /* 153 - ECANCELED */
[160] = "Stale NFS file handle", /* 160 - ESTALE */
[161] = "Too many levels of remote in path", /* 161 - EREMOTE */
[162] = "RPC struct is bad", /* 162 - EBADRPC */
[163] = "RPC version wrong", /* 163 - ERPCMISMATCH */
[164] = "RPC prog. not avail", /* 164 - EPROGUNAVAIL */
[165] = "Program version wrong", /* 165 - EPROGMISMATCH */
[166] = "Bad procedure for program", /* 166 - EPROCUNAVAIL */
[170] = "Bad or Corrupt message", /* 170 - EBADMSG */
[175] = "Too many processes", /* 175 - EPROCLIM */
[176] = "Too many users", /* 176 - EUSERS */
[177] = "Disc quota exceeded", /* 177 - EDQUOT */
[180] = "Multihop attempted ", /* 180 - EMULTIHOP */
[181] = "Link has been severed", /* 181 - ENOLINK */
[182] = "Protocol error", /* 182 - EPROTO */
[185] = "Attribute not found", /* 185 - ENOATTR */
[190] = "No message available", /* 190 - ENODATA */
[191] = "No STREAM resources", /* 191 - ENOSR */
[192] = "Not a STREAM", /* 192 - ENOSTR */
[193] = "STREAM ioctl timeout", /* 193 - ETIME */
[301] = "specified endpoint is bad", /* 301 - EBADEPT */
[302] = "specified endpoint is not alive", /* 302 - EDEADEPT */
};
const int sys_nerr = sizeof(errlist) / sizeof(errlist[0]);
const char * const *sys_errlist = errlist;

15
lib/libsys/fputs.c Normal file
View file

@ -0,0 +1,15 @@
#include <sys/cdefs.h>
#include "namespace.h"
#include <assert.h>
#include <stdio.h>
#ifdef __weak_alias
__weak_alias(fputs, _fputs)
#endif
int fputs(const char *s, FILE *fp)
{
assert(fp == stdout || fp == stderr);
puts(s);
}

252
lib/libsys/malloc.c Normal file
View file

@ -0,0 +1,252 @@
/* $Header$ */
/* replace undef by define */
#define ALIGN_EIGHT_BYTES /* Use 8-byte alignment. */
#define DEBUG /* check assertions */
#undef SLOWDEBUG /* some extra test loops (requires DEBUG) */
#ifndef DEBUG
#define NDEBUG
#endif
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h>
static int no_debug = -1;
#define CHECK_DBG(statement)
#if _EM_WSIZE == _EM_PSIZE
#define ptrint int
#else
#define ptrint long
#endif
#if _EM_PSIZE == 2
#define BRKSIZE 1024
#else
#define BRKSIZE 4096
#endif
#ifdef ALIGN_EIGHT_BYTES
#define PTRSIZE 8
#else
#define PTRSIZE ((int) sizeof(void *))
#endif
#define Align(x,a) (((x) + (a - 1)) & ~(a - 1))
#define NextSlot(p) (* (void **) ((p) - PTRSIZE))
#define NextFree(p) (* (void **) (p))
/*
* A short explanation of the data structure and algorithms.
* An area returned by malloc() is called a slot. Each slot
* contains the number of bytes requested, but preceeded by
* an extra pointer to the next the slot in memory.
* '_bottom' and '_top' point to the first/last slot.
* More memory is asked for using brk() and appended to top.
* The list of free slots is maintained to keep malloc() fast.
* '_empty' points the the first free slot. Free slots are
* linked together by a pointer at the start of the
* user visable part, so just after the next-slot pointer.
* Free slots are merged together by free().
*
* Since modern processors prefer 8-byte alignment, we now pretend
* our pointers are 8 bytes wide.
*/
extern void *_sbrk(int);
extern int _brk(void *);
static void *_bottom, *_top, *_empty;
static int grow(size_t len)
{
register char *p;
assert(NextSlot((char *)_top) == 0);
if ((char *) _top + len < (char *) _top
|| (p = (char *)Align((ptrint)_top + len, BRKSIZE)) < (char *) _top ) {
errno = ENOMEM;
return(0);
}
if (_brk(p) != 0)
return(0);
NextSlot((char *)_top) = p;
NextSlot(p) = 0;
free(_top);
_top = p;
return 1;
}
void *
malloc(const size_t size)
{
register char *prev, *p, *next, *new;
unsigned ntries;
if (size == 0)
return NULL;
CHECK_DBG(return _dbg_malloc(size));
for (ntries = 0; ntries < 2; ntries++) {
unsigned len = Align(size, PTRSIZE) + PTRSIZE;
if (len < 2 * PTRSIZE) {
errno = ENOMEM;
return NULL;
}
if (_bottom == 0) {
if ((p = _sbrk(2 * PTRSIZE)) == (char *) -1)
return NULL;
p = (char *) Align((ptrint)p, PTRSIZE);
p += PTRSIZE;
_top = _bottom = p;
NextSlot(p) = 0;
}
#ifdef SLOWDEBUG
for (p = _bottom; (next = NextSlot(p)) != 0; p = next)
assert(next > p);
assert(p == _top);
#endif
for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
next = NextSlot(p);
new = p + len; /* easily overflows!! */
if (new > next || new <= p)
continue; /* too small */
if (new + PTRSIZE < next) { /* too big, so split */
/* + PTRSIZE avoids tiny slots on free list */
NextSlot(new) = next;
NextSlot(p) = new;
NextFree(new) = NextFree(p);
NextFree(p) = new;
}
if (prev)
NextFree(prev) = NextFree(p);
else
_empty = NextFree(p);
return p;
}
if (grow(len) == 0)
break;
}
assert(ntries != 2);
return NULL;
}
void *
realloc(void *oldp, size_t size)
{
register char *prev, *p, *next, *new;
char *old = oldp;
register size_t len, n;
if (old == 0)
return malloc(size);
if (size == 0) {
free(old);
return NULL;
}
CHECK_DBG(return _dbg_realloc(oldp, size));
len = Align(size, PTRSIZE) + PTRSIZE;
next = NextSlot(old);
n = (int)(next - old); /* old length */
/*
* extend old if there is any free space just behind it
*/
for (prev = 0, p = _empty; p != 0; prev = p, p = NextFree(p)) {
if (p > next)
break;
if (p == next) { /* 'next' is a free slot: merge */
NextSlot(old) = NextSlot(p);
if (prev)
NextFree(prev) = NextFree(p);
else
_empty = NextFree(p);
next = NextSlot(old);
break;
}
}
new = old + len;
/*
* Can we use the old, possibly extended slot?
*/
if (new <= next && new >= old) { /* it does fit */
if (new + PTRSIZE < next) { /* too big, so split */
/* + PTRSIZE avoids tiny slots on free list */
NextSlot(new) = next;
NextSlot(old) = new;
free(new);
}
return old;
}
if ((new = malloc(size)) == NULL) /* it didn't fit */
return NULL;
memcpy(new, old, n); /* n < size */
free(old);
return new;
}
void
free(void *ptr)
{
register char *prev, *next;
char *p = ptr;
if (p == 0)
return;
CHECK_DBG(_dbg_free(ptr); return);
#ifdef SLOWDEBUG
{
int found;
char *curr;
/* block must be in block list */
assert(_bottom);
found = 0;
for (curr = _bottom; (next = NextSlot(curr)) != 0; curr = next) {
assert(next > curr);
if (curr == p) found = 1;
}
if (curr == p) found = 1;
assert(found);
/* block must not be in free list */
if (_empty) {
found = 0;
for (curr = _empty; (next = NextFree(curr)) != 0; curr = next) {
assert(next > curr);
if (curr == p) found = 1;
}
if (curr == p) found = 1;
assert(!found);
}
}
#endif
assert((char *) NextSlot(p) > p);
for (prev = 0, next = _empty; next != 0; prev = next, next = NextFree(next))
if (p < next)
break;
NextFree(p) = next;
if (prev)
NextFree(prev) = p;
else
_empty = p;
if (next) {
assert((char *) NextSlot(p) <= next);
if (NextSlot(p) == next) { /* merge p and next */
NextSlot(p) = NextSlot(next);
NextFree(p) = NextFree(next);
}
}
if (prev) {
assert((char *) NextSlot(prev) <= p);
if (NextSlot(prev) == p) { /* merge prev and p */
NextSlot(prev) = NextSlot(p);
NextFree(prev) = NextFree(p);
}
}
}

View file

@ -41,8 +41,10 @@ PUBLIC void panic(const char *fmt, ...)
/* Try exit */
_exit(1);
#ifndef __NBSD_LIBC
/* Try to signal ourself */
abort();
#endif
/* If exiting nicely through PM fails for some reason, try to
* commit suicide. E.g., message to PM might fail due to deadlock.

View file

@ -7,9 +7,15 @@
/* vprintf() uses kputc() to print characters. */
void kputc(int c);
#ifdef __NBSD_LIBC
#define count_kputc(c) do { charcount++; putf((c), farg); } while(0)
int __fvprintf(void (*putf)(int, void *), const char *fmt, va_list argp, void *farg)
#else /* !NBSD_LIBC */
#define count_kputc(c) do { charcount++; kputc(c); } while(0)
int vprintf(const char *fmt, va_list argp)
#endif /* NBSD_LIBC */
{
int c, charcount = 0;
enum { LEFT, RIGHT } adjust;
@ -167,10 +173,52 @@ int vprintf(const char *fmt, va_list argp)
}
/* Mark the end with a null (should be something else, like -1). */
#ifdef __NBDS_LIBC
putf(0, farg);
#else
kputc(0);
#endif
return charcount;
}
#ifdef __NBSD_LIBC
#include <sys/cdefs.h>
#include <assert.h>
#include <unistd.h>
#include <stdio.h>
__weak_alias(vprintf, _vprintf)
__weak_alias(vfprintf, _vfprintf)
__strong_alias(__vfprintf_unlocked, _vfprintf)
static void
__xfputc(int c, void *arg)
{
FILE *fp = (FILE *)arg;
if (fp->_flags & __SSTR) {
/* Write to a string. */
if (fp->_w == 0)
return;
memset(fp->_p++, c, 1);
fp->_w -= 1;
return;
}
/* Not a string. Print it. */
kputc(c);
}
int _vprintf(const char *fmt, va_list argp)
{
__fvprintf(__xfputc, fmt, argp, stdout);
}
int _vfprintf(FILE *fp, const char *fmt, va_list argp)
{
__fvprintf(__xfputc, fmt, argp, fp);
}
#endif
/*
* $PchId: kprintf.c,v 1.5 1996/04/11 06:59:05 philip Exp $
*/

View file

@ -2,7 +2,11 @@
LIB= util
.if (${NBSD_LIBC} != "no")
# SHA and MD5 functions already in libc
SRCS= openpty.c efun.c
.else
SRCS= openpty.c sha2.c efun.c \
sha1.c sha1hl.c sha2.c sha2hl.c md5c.c md5hl.c
.endif
.include <bsd.lib.mk>

View file

@ -1,5 +1,6 @@
#ifndef __NBSD_LIBC
#define _POSIX_SOURCE 1 /* tell headers to include POSIX stuff */
#endif
#define _MINIX 1 /* tell headers to include MINIX stuff */
#define _SYSTEM 1 /* tell headers that this is the kernel */

View file

@ -5,7 +5,12 @@ LIB= z
SRCS= adler32.c compress.c crc32.c deflate.c gzclose.c gzlib.c gzread.c \
gzwrite.c infback.c inffast.c inflate.c inftrees.c trees.c uncompr.c zutil.c
.if (${NBSD_LIBC} != "no")
INCSDIR= /usr/netbsd/include
.else
INCSDIR= /usr/include
.endif
INCS= zconf.h zlib.h
CPPFLAGS += -DNO_VIZ=1

View file

@ -68,9 +68,7 @@ BUILDCOLD= no
.include "${.CURDIR}/citrus/Makefile.inc"
.endif
.include "${.CURDIR}/compat-43/Makefile.inc"
.ifndef(__MINIX)
.include "${.CURDIR}/dlfcn/Makefile.inc"
.endif
.include "${.CURDIR}/gdtoa/Makefile.inc"
.include "${.CURDIR}/gen/Makefile.inc"
.if defined(__MINIX)

View file

@ -31,7 +31,7 @@ CITRUS?= yes
WARNS=4
.if defined(__MINIX)
CPPFLAGS+= -D_LIBC -DLIBC_SCSS -DSYSLIBC_SCSS
CPPFLAGS+= -D_LIBC
.else
CPPFLAGS+= -D_LIBC -DLIBC_SCCS -DSYSLIBC_SCCS -D_REENTRANT
.endif

View file

@ -3,8 +3,8 @@
# sources
.PATH: ${ARCHDIR}/citrus ${.CURDIR}/citrus
MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major
CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR}
#MODULE_SHLIB_MAJOR!= . ${NETBSDSRCDIR}/lib/i18n_module/shlib_version ; echo $$major
#CPPFLAGS.citrus_module.c+=-DI18NMODULE_MAJOR=${MODULE_SHLIB_MAJOR}
SRCS+= citrus_bcs.c citrus_bcs_strtol.c citrus_bcs_strtoul.c \
citrus_csmapper.c citrus_ctype.c citrus_ctype_fallback.c \
citrus_db.c citrus_db_hash.c citrus_esdb.c citrus_hash.c \

View file

@ -48,7 +48,12 @@ __RCSID("$NetBSD: dlfcn_elf.c,v 1.7 2010/10/16 10:27:07 skrll Exp $");
#define dl_iterate_phdr ___dl_iterate_phdr
#define ELFSIZE ARCH_ELFSIZE
#ifdef __minix
#include <sys/null.h>
#include <dlfcn.h>
#else
#include "rtld.h"
#endif
#ifdef __weak_alias
__weak_alias(dlopen,___dlopen)
@ -128,6 +133,7 @@ dlinfo(void *handle, int req, void *v)
return -1;
}
#ifndef __minix
/*ARGSUSED*/
int
dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
@ -136,3 +142,4 @@ dl_iterate_phdr(int (*callback)(struct dl_phdr_info *, size_t, void *),
return 0;
}
#endif

View file

@ -7,7 +7,6 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <net/gen/netdb.h>
#ifdef __weak_alias
__weak_alias(gethostname, _gethostname)

View file

@ -103,7 +103,9 @@ __opendir_common(int fd, const char *name, int flags)
DIR *dirp = NULL;
int serrno;
struct stat sb;
#ifndef __minix
struct statvfs sfb;
#endif
int error;
if (fcntl(fd, F_SETFD, FD_CLOEXEC) == -1)
@ -129,8 +131,6 @@ __opendir_common(int fd, const char *name, int flags)
*/
#ifdef __minix
if (fstatvfs(fd, &sfb) < 0)
goto error;
/* MOUNT_UNION and MOUNT_NFS not supported */
flags &= ~DTF_NODUP;
#else

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,7 @@
LIB= compat_minix
CPPFLAGS+= -D_MINIX_COMPAT
MACHINE_ARCH= ${ARCH}
.PATH: ${.CURDIR}

View file

@ -6,3 +6,5 @@ INCS+= configfile.h termcap.h
INCS+= compat/a.out.h compat/regexp.h compat/syslog.h \
compat/pwd.h
INCS+= net/gen/netdb.h net/gen/resolv.h net/gen/nameser.h
INCS+= sys/jmp_buf.h ${MACHINE_ARCH}/compat_jmp_buf.h
INCS+= sys/sigcontext.h

View file

@ -0,0 +1,16 @@
#ifndef _COMPAT_MACHINE_JMP_BUF_H
#define _COMPAT_MACHINE_JMP_BUF_H
/* This file is strictly dependant on the libc's
* setjmp/longjmp code! Keep it in sync! */
/* This is used only by libddekit's src/thread.c.
* Being incredibly fragile (not to mention hardly
* portable, it would be a good idea to replace
* that code. */
#define JB_PC 0
#define JB_SP 8
#define JB_BP 12
#endif /* _COMPAT_MACHINE_JMP_BUF_H */

Some files were not shown because too many files have changed in this diff Show more