diff options
Diffstat (limited to 'lib/libc')
296 files changed, 2803 insertions, 5581 deletions
diff --git a/lib/libc/Makefile b/lib/libc/Makefile index 4fdc2f2d27f6..d02e1eed812c 100644 --- a/lib/libc/Makefile +++ b/lib/libc/Makefile @@ -6,8 +6,8 @@ # from CFLAGS below. To remove these strings from just the system call # stubs, remove just -DSYSLIBC_RCS from CFLAGS. LIB=c -SHLIB_MAJOR= 3 -SHLIB_MINOR= 0 +SHLIB_MAJOR= 2 +SHLIB_MINOR= 2 CFLAGS+=-DLIBC_RCS -DSYSLIBC_RCS AINC= -I${.CURDIR}/${MACHINE} CLEANFILES+=tags @@ -53,7 +53,7 @@ libkern.${MACHINE}:: ${KMSRCS} .endif #beforeinstall: tags -# ${INSTALL} ${COPY} -o bin -g bin -m 444 tags /var/db/libc.tags +# install -c -o bin -g bin -m 444 tags /var/db/libc.tags tags: ${SRCS} ctags ${.ALLSRC:M*.c} diff --git a/lib/libc/compat-43/gethostid.3 b/lib/libc/compat-43/gethostid.3 index 72222cc57287..8f56a282f2dd 100644 --- a/lib/libc/compat-43/gethostid.3 +++ b/lib/libc/compat-43/gethostid.3 @@ -57,10 +57,10 @@ returns the 32-bit identifier for the current processor. .Pp This function has been deprecated. The hostid should be set or retrieved by use of -.Xr sysctl 3 . +.Xr sysctl 2 . .Sh SEE ALSO +.Xr sysctl 2 , .Xr gethostname 3 , -.Xr sysctl 3 , .Xr sysctl 8 . .Sh BUGS 32 bits for the identifier is too small. diff --git a/lib/libc/compat-43/sigvec.2 b/lib/libc/compat-43/sigvec.2 index a37c988d5baa..1b5244f25fe3 100644 --- a/lib/libc/compat-43/sigvec.2 +++ b/lib/libc/compat-43/sigvec.2 @@ -102,9 +102,9 @@ must arrange to restore the previous context itself. When a signal is delivered to a process a new signal mask is installed for the duration of the process' signal handler (or until a -.Xr sigblock 2 +.Xr sigblock or -.Xr sigsetmask 2 +.Xr sigsetmask call is made). This mask is formed by taking the current signal mask, adding the signal to be delivered, and @@ -140,7 +140,7 @@ with names as in the include file .It Dv SIGQUIT No " create core image" " quit program" .It Dv SIGILL No " create core image" " illegal instruction" .It Dv SIGTRAP No " create core image" " trace trap" -.It Dv SIGABRT No " create core image" Xr abort 3 +.It Dv SIGABRT No " create core image" Xr abort 2 call (formerly .Dv SIGIOT ) .It Dv SIGEMT No " create core image" " emulate instruction executed" @@ -148,7 +148,7 @@ call (formerly .It Dv SIGKILL No " terminate process" " kill program" .It Dv SIGBUS No " create core image" " bus error" .It Dv SIGSEGV No " create core image" " segmentation violation" -.It Dv SIGSYS No " create core image" " non-existent system call invoked" +.It Dv SIGSYS No " create core image" " system call given invalid argument" .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" .It Dv SIGALRM No " terminate process" " real-time timer expired" .It Dv SIGTERM No " terminate process" " software termination signal" diff --git a/lib/libc/db/btree/Makefile.inc b/lib/libc/db/btree/Makefile.inc index 8ed76494aabf..71f8dfcf9e4d 100644 --- a/lib/libc/db/btree/Makefile.inc +++ b/lib/libc/db/btree/Makefile.inc @@ -1,7 +1,7 @@ -# @(#)Makefile.inc 8.2 (Berkeley) 7/14/94 +# @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 .PATH: ${.CURDIR}/db/btree SRCS+= bt_close.c bt_conv.c bt_debug.c bt_delete.c bt_get.c bt_open.c \ bt_overflow.c bt_page.c bt_put.c bt_search.c bt_seq.c bt_split.c \ - bt_utils.c + bt_stack.c bt_utils.c diff --git a/lib/libc/db/btree/bt_close.c b/lib/libc/db/btree/bt_close.c index 27f9ab660f98..6269bd5c8ac0 100644 --- a/lib/libc/db/btree/bt_close.c +++ b/lib/libc/db/btree/bt_close.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_close.c 8.7 (Berkeley) 8/17/94"; +static char sccsid[] = "@(#)bt_close.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -75,30 +75,25 @@ __bt_close(dbp) t->bt_pinned = NULL; } - /* Sync the tree. */ + /* + * Delete any already deleted record that we've been saving + * because the cursor pointed to it. + */ + if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) + return (RET_ERROR); + if (__bt_sync(dbp, 0) == RET_ERROR) return (RET_ERROR); - /* Close the memory pool. */ if (mpool_close(t->bt_mp) == RET_ERROR) return (RET_ERROR); - /* Free random memory. */ - if (t->bt_cursor.key.data != NULL) { - free(t->bt_cursor.key.data); - t->bt_cursor.key.size = 0; - t->bt_cursor.key.data = NULL; - } - if (t->bt_rkey.data) { - free(t->bt_rkey.data); - t->bt_rkey.size = 0; - t->bt_rkey.data = NULL; - } - if (t->bt_rdata.data) { - free(t->bt_rdata.data); - t->bt_rdata.size = 0; - t->bt_rdata.data = NULL; - } + if (t->bt_stack) + free(t->bt_stack); + if (t->bt_kbuf) + free(t->bt_kbuf); + if (t->bt_dbuf) + free(t->bt_dbuf); fd = t->bt_fd; free(t); @@ -122,6 +117,8 @@ __bt_sync(dbp, flags) { BTREE *t; int status; + PAGE *h; + void *p; t = dbp->internal; @@ -137,15 +134,40 @@ __bt_sync(dbp, flags) return (RET_ERROR); } - if (F_ISSET(t, B_INMEM | B_RDONLY) || !F_ISSET(t, B_MODIFIED)) + if (ISSET(t, B_INMEM | B_RDONLY) || !ISSET(t, B_MODIFIED)) return (RET_SUCCESS); - if (F_ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) + if (ISSET(t, B_METADIRTY) && bt_meta(t) == RET_ERROR) return (RET_ERROR); - if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) - F_CLR(t, B_MODIFIED); + /* + * Nastiness. If the cursor has been marked for deletion, but not + * actually deleted, we have to make a copy of the page, delete the + * key/data item, sync the file, and then restore the original page + * contents. + */ + if (ISSET(t, B_DELCRSR)) { + if ((p = (void *)malloc(t->bt_psize)) == NULL) + return (RET_ERROR); + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + return (RET_ERROR); + memmove(p, h, t->bt_psize); + if ((status = + __bt_dleaf(t, h, t->bt_bcursor.index)) == RET_ERROR) + goto ecrsr; + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } + if ((status = mpool_sync(t->bt_mp)) == RET_SUCCESS) + CLR(t, B_MODIFIED); + +ecrsr: if (ISSET(t, B_DELCRSR)) { + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) + return (RET_ERROR); + memmove(h, p, t->bt_psize); + free(p); + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + } return (status); } @@ -169,12 +191,12 @@ bt_meta(t) return (RET_ERROR); /* Fill in metadata. */ - m.magic = BTREEMAGIC; - m.version = BTREEVERSION; - m.psize = t->bt_psize; - m.free = t->bt_free; - m.nrecs = t->bt_nrecs; - m.flags = F_ISSET(t, SAVEMETA); + m.m_magic = BTREEMAGIC; + m.m_version = BTREEVERSION; + m.m_psize = t->bt_psize; + m.m_free = t->bt_free; + m.m_nrecs = t->bt_nrecs; + m.m_flags = t->bt_flags & SAVEMETA; memmove(p, &m, sizeof(BTMETA)); mpool_put(t->bt_mp, p, MPOOL_DIRTY); diff --git a/lib/libc/db/btree/bt_conv.c b/lib/libc/db/btree/bt_conv.c index 1cb208b14d94..eb4934090b58 100644 --- a/lib/libc/db/btree/bt_conv.c +++ b/lib/libc/db/btree/bt_conv.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_conv.c 8.5 (Berkeley) 8/17/94"; +static char sccsid[] = "@(#)bt_conv.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -68,7 +68,7 @@ __bt_pgin(t, pg, pp) u_char flags; char *p; - if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) + if (!ISSET(((BTREE *)t), B_NEEDSWAP)) return; if (pg == P_META) { mswap(pp); @@ -89,7 +89,7 @@ __bt_pgin(t, pg, pp) M_16_SWAP(h->linp[i]); p = (char *)GETBINTERNAL(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); p += sizeof(pgno_t); if (*(u_char *)p & P_BIGKEY) { @@ -104,9 +104,9 @@ __bt_pgin(t, pg, pp) M_16_SWAP(h->linp[i]); p = (char *)GETBLEAF(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); flags = *(u_char *)p; if (flags & (P_BIGKEY | P_BIGDATA)) { p += sizeof(u_char); @@ -116,7 +116,7 @@ __bt_pgin(t, pg, pp) P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -136,7 +136,7 @@ __bt_pgout(t, pg, pp) u_char flags; char *p; - if (!F_ISSET(((BTREE *)t), B_NEEDSWAP)) + if (!ISSET(((BTREE *)t), B_NEEDSWAP)) return; if (pg == P_META) { mswap(pp); @@ -149,7 +149,7 @@ __bt_pgout(t, pg, pp) for (i = 0; i < top; i++) { p = (char *)GETBINTERNAL(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); p += sizeof(pgno_t); if (*(u_char *)p & P_BIGKEY) { @@ -164,9 +164,9 @@ __bt_pgout(t, pg, pp) for (i = 0; i < top; i++) { p = (char *)GETBLEAF(h, i); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); - p += sizeof(u_int32_t); + p += sizeof(size_t); flags = *(u_char *)p; if (flags & (P_BIGKEY | P_BIGDATA)) { p += sizeof(u_char); @@ -176,7 +176,7 @@ __bt_pgout(t, pg, pp) P_32_SWAP(p); } if (flags & P_BIGDATA) { - p += sizeof(u_int32_t); + p += sizeof(size_t); P_32_SWAP(p); p += sizeof(pgno_t); P_32_SWAP(p); @@ -206,16 +206,16 @@ mswap(pg) char *p; p = (char *)pg; - P_32_SWAP(p); /* magic */ + P_32_SWAP(p); /* m_magic */ p += sizeof(u_int32_t); - P_32_SWAP(p); /* version */ + P_32_SWAP(p); /* m_version */ p += sizeof(u_int32_t); - P_32_SWAP(p); /* psize */ + P_32_SWAP(p); /* m_psize */ p += sizeof(u_int32_t); - P_32_SWAP(p); /* free */ + P_32_SWAP(p); /* m_free */ p += sizeof(u_int32_t); - P_32_SWAP(p); /* nrecs */ + P_32_SWAP(p); /* m_nrecs */ p += sizeof(u_int32_t); - P_32_SWAP(p); /* flags */ + P_32_SWAP(p); /* m_flags */ p += sizeof(u_int32_t); } diff --git a/lib/libc/db/btree/bt_debug.c b/lib/libc/db/btree/bt_debug.c index 3aefbe762244..5f9ac1ded8b3 100644 --- a/lib/libc/db/btree/bt_debug.c +++ b/lib/libc/db/btree/bt_debug.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_debug.c 8.5 (Berkeley) 8/17/94"; +static char sccsid[] = "@(#)bt_debug.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -65,22 +65,24 @@ __bt_dump(dbp) t = dbp->internal; (void)fprintf(stderr, "%s: pgsz %d", - F_ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); - if (F_ISSET(t, R_RECNO)) + ISSET(t, B_INMEM) ? "memory" : "disk", t->bt_psize); + if (ISSET(t, R_RECNO)) (void)fprintf(stderr, " keys %lu", t->bt_nrecs); #undef X #define X(flag, name) \ - if (F_ISSET(t, flag)) { \ + if (ISSET(t, flag)) { \ (void)fprintf(stderr, "%s%s", sep, name); \ sep = ", "; \ } - if (t->flags != 0) { + if (t->bt_flags) { sep = " flags ("; + X(B_DELCRSR, "DELCRSR"); X(R_FIXLEN, "FIXLEN"); X(B_INMEM, "INMEM"); X(B_NODUPS, "NODUPS"); X(B_RDONLY, "RDONLY"); X(R_RECNO, "RECNO"); + X(B_SEQINIT, "SEQINIT"); X(B_METADIRTY,"METADIRTY"); (void)fprintf(stderr, ")\n"); } @@ -106,19 +108,19 @@ __bt_dmpage(h) char *sep; m = (BTMETA *)h; - (void)fprintf(stderr, "magic %lx\n", m->magic); - (void)fprintf(stderr, "version %lu\n", m->version); - (void)fprintf(stderr, "psize %lu\n", m->psize); - (void)fprintf(stderr, "free %lu\n", m->free); - (void)fprintf(stderr, "nrecs %lu\n", m->nrecs); - (void)fprintf(stderr, "flags %lu", m->flags); + (void)fprintf(stderr, "magic %lx\n", m->m_magic); + (void)fprintf(stderr, "version %lu\n", m->m_version); + (void)fprintf(stderr, "psize %lu\n", m->m_psize); + (void)fprintf(stderr, "free %lu\n", m->m_free); + (void)fprintf(stderr, "nrecs %lu\n", m->m_nrecs); + (void)fprintf(stderr, "flags %lu", m->m_flags); #undef X #define X(flag, name) \ - if (m->flags & flag) { \ + if (m->m_flags & flag) { \ (void)fprintf(stderr, "%s%s", sep, name); \ sep = ", "; \ } - if (m->flags) { + if (m->m_flags) { sep = " ("; X(B_NODUPS, "NODUPS"); X(R_RECNO, "RECNO"); @@ -190,7 +192,7 @@ __bt_dpage(h) h->lower, h->upper, top); for (cur = 0; cur < top; cur++) { (void)fprintf(stderr, "\t[%03d] %4d ", cur, h->linp[cur]); - switch (h->flags & P_TYPE) { + switch(h->flags & P_TYPE) { case P_BINTERNAL: bi = GETBINTERNAL(h, cur); (void)fprintf(stderr, @@ -212,14 +214,14 @@ __bt_dpage(h) (void)fprintf(stderr, "big key page %lu size %u/", *(pgno_t *)bl->bytes, - *(u_int32_t *)(bl->bytes + sizeof(pgno_t))); + *(size_t *)(bl->bytes + sizeof(pgno_t))); else if (bl->ksize) (void)fprintf(stderr, "%s/", bl->bytes); if (bl->flags & P_BIGDATA) (void)fprintf(stderr, "big data page %lu size %u", *(pgno_t *)(bl->bytes + bl->ksize), - *(u_int32_t *)(bl->bytes + bl->ksize + + *(size_t *)(bl->bytes + bl->ksize + sizeof(pgno_t))); else if (bl->dsize) (void)fprintf(stderr, "%.*s", @@ -231,7 +233,7 @@ __bt_dpage(h) (void)fprintf(stderr, "big data page %lu size %u", *(pgno_t *)rl->bytes, - *(u_int32_t *)(rl->bytes + sizeof(pgno_t))); + *(size_t *)(rl->bytes + sizeof(pgno_t))); else if (rl->dsize) (void)fprintf(stderr, "%.*s", (int)rl->dsize, rl->bytes); @@ -265,7 +267,7 @@ __bt_stat(dbp) pcont = pinternal = pleaf = 0; nkeys = ifree = lfree = 0; for (i = P_ROOT; (h = mpool_get(t->bt_mp, i, 0)) != NULL; ++i) { - switch (h->flags & P_TYPE) { + switch(h->flags & P_TYPE) { case P_BINTERNAL: case P_RINTERNAL: ++pinternal; @@ -293,7 +295,7 @@ __bt_stat(dbp) (void)mpool_put(t->bt_mp, h, 0); break; } - i = F_ISSET(t, R_RECNO) ? + i = ISSET(t, R_RECNO) ? GETRINTERNAL(h, 0)->pgno : GETBINTERNAL(h, 0)->pgno; (void)mpool_put(t->bt_mp, h, 0); @@ -301,7 +303,7 @@ __bt_stat(dbp) (void)fprintf(stderr, "%d level%s with %ld keys", levels, levels == 1 ? "" : "s", nkeys); - if (F_ISSET(t, R_RECNO)) + if (ISSET(t, R_RECNO)) (void)fprintf(stderr, " (%ld header count)", t->bt_nrecs); (void)fprintf(stderr, "\n%lu pages (leaf %ld, internal %ld, overflow %ld)\n", diff --git a/lib/libc/db/btree/bt_delete.c b/lib/libc/db/btree/bt_delete.c index ece1ab656e62..5dba534850c9 100644 --- a/lib/libc/db/btree/bt_delete.c +++ b/lib/libc/db/btree/bt_delete.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_delete.c 8.13 (Berkeley) 7/28/94"; +static char sccsid[] = "@(#)bt_delete.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -47,17 +47,18 @@ static char sccsid[] = "@(#)bt_delete.c 8.13 (Berkeley) 7/28/94"; #include <db.h> #include "btree.h" -static int __bt_bdelete __P((BTREE *, const DBT *)); -static int __bt_curdel __P((BTREE *, const DBT *, PAGE *, u_int)); -static int __bt_pdelete __P((BTREE *, PAGE *)); -static int __bt_relink __P((BTREE *, PAGE *)); -static int __bt_stkacq __P((BTREE *, PAGE **, CURSOR *)); +static int bt_bdelete __P((BTREE *, const DBT *)); /* - * __bt_delete - * Delete the item(s) referenced by a key. + * __BT_DELETE -- Delete the item(s) referenced by a key. * - * Return RET_SPECIAL if the key is not found. + * Parameters: + * dbp: pointer to access method + * key: key to delete + * flags: R_CURSOR if deleting what the cursor references + * + * Returns: + * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. */ int __bt_delete(dbp, key, flags) @@ -66,8 +67,6 @@ __bt_delete(dbp, key, flags) u_int flags; { BTREE *t; - CURSOR *c; - PAGE *h; int status; t = dbp->internal; @@ -78,433 +77,242 @@ __bt_delete(dbp, key, flags) t->bt_pinned = NULL; } - /* Check for change to a read-only tree. */ - if (F_ISSET(t, B_RDONLY)) { + if (ISSET(t, B_RDONLY)) { errno = EPERM; return (RET_ERROR); } - switch (flags) { + switch(flags) { case 0: - status = __bt_bdelete(t, key); + status = bt_bdelete(t, key); break; case R_CURSOR: /* - * If flags is R_CURSOR, delete the cursor. Must already - * have started a scan and not have already deleted it. + * If flags is R_CURSOR, delete the cursor; must already have + * started a scan and not have already deleted the record. For + * the delete cursor bit to have been set requires that the + * scan be initialized, so no reason to check. */ - c = &t->bt_cursor; - if (F_ISSET(c, CURS_INIT)) { - if (F_ISSET(c, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL) - return (RET_ERROR); - - /* - * If the page is about to be emptied, we'll need to - * delete it, which means we have to acquire a stack. - */ - if (NEXTINDEX(h) == 1) - if (__bt_stkacq(t, &h, &t->bt_cursor)) - return (RET_ERROR); - - status = __bt_dleaf(t, NULL, h, c->pg.index); - - if (NEXTINDEX(h) == 0 && status == RET_SUCCESS) { - if (__bt_pdelete(t, h)) - return (RET_ERROR); - } else - mpool_put(t->bt_mp, - h, status == RET_SUCCESS ? MPOOL_DIRTY : 0); - break; - } - /* FALLTHROUGH */ + if (!ISSET(t, B_SEQINIT)) + goto einval; + status = ISSET(t, B_DELCRSR) ? + RET_SPECIAL : __bt_crsrdel(t, &t->bt_bcursor); + break; default: - errno = EINVAL; +einval: errno = EINVAL; return (RET_ERROR); } if (status == RET_SUCCESS) - F_SET(t, B_MODIFIED); + SET(t, B_MODIFIED); return (status); } /* - * __bt_stkacq -- - * Acquire a stack so we can delete a cursor entry. + * BT_BDELETE -- Delete all key/data pairs matching the specified key. * * Parameters: - * t: tree - * hp: pointer to current, pinned PAGE pointer - * c: pointer to the cursor - * - * Returns: - * 0 on success, 1 on failure - */ -static int -__bt_stkacq(t, hp, c) - BTREE *t; - PAGE **hp; - CURSOR *c; -{ - BINTERNAL *bi; - EPG *e; - EPGNO *parent; - PAGE *h; - indx_t index; - pgno_t pgno; - recno_t nextpg, prevpg; - int exact, level; - - /* - * Find the first occurrence of the key in the tree. Toss the - * currently locked page so we don't hit an already-locked page. - */ - h = *hp; - mpool_put(t->bt_mp, h, 0); - if ((e = __bt_search(t, &c->key, &exact)) == NULL) - return (1); - h = e->page; - - /* See if we got it in one shot. */ - if (h->pgno == c->pg.pgno) - goto ret; - - /* - * Move right, looking for the page. At each move we have to move - * up the stack until we don't have to move to the next page. If - * we have to change pages at an internal level, we have to fix the - * stack back up. - */ - while (h->pgno != c->pg.pgno) { - if ((nextpg = h->nextpg) == P_INVALID) - break; - mpool_put(t->bt_mp, h, 0); - - /* Move up the stack. */ - for (level = 0; (parent = BT_POP(t)) != NULL; ++level) { - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (1); - - /* Move to the next index. */ - if (parent->index != NEXTINDEX(h) - 1) { - index = parent->index + 1; - BT_PUSH(t, h->pgno, index); - break; - } - mpool_put(t->bt_mp, h, 0); - } - - /* Restore the stack. */ - while (level--) { - /* Push the next level down onto the stack. */ - bi = GETBINTERNAL(h, index); - pgno = bi->pgno; - BT_PUSH(t, pgno, 0); - - /* Lose the currently pinned page. */ - mpool_put(t->bt_mp, h, 0); - - /* Get the next level down. */ - if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL) - return (1); - index = 0; - } - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, nextpg, 0)) == NULL) - return (1); - } - - if (h->pgno == c->pg.pgno) - goto ret; - - /* Reacquire the original stack. */ - mpool_put(t->bt_mp, h, 0); - if ((e = __bt_search(t, &c->key, &exact)) == NULL) - return (1); - h = e->page; - - /* - * Move left, looking for the page. At each move we have to move - * up the stack until we don't have to change pages to move to the - * next page. If we have to change pages at an internal level, we - * have to fix the stack back up. - */ - while (h->pgno != c->pg.pgno) { - if ((prevpg = h->prevpg) == P_INVALID) - break; - mpool_put(t->bt_mp, h, 0); - - /* Move up the stack. */ - for (level = 0; (parent = BT_POP(t)) != NULL; ++level) { - /* Get the parent page. */ - if ((h = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (1); - - /* Move to the next index. */ - if (parent->index != 0) { - index = parent->index - 1; - BT_PUSH(t, h->pgno, index); - break; - } - mpool_put(t->bt_mp, h, 0); - } - - /* Restore the stack. */ - while (level--) { - /* Push the next level down onto the stack. */ - bi = GETBINTERNAL(h, index); - pgno = bi->pgno; - - /* Lose the currently pinned page. */ - mpool_put(t->bt_mp, h, 0); - - /* Get the next level down. */ - if ((h = mpool_get(t->bt_mp, pgno, 0)) == NULL) - return (1); - - index = NEXTINDEX(h) - 1; - BT_PUSH(t, pgno, index); - } - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, prevpg, 0)) == NULL) - return (1); - } - - -ret: mpool_put(t->bt_mp, h, 0); - return ((*hp = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL); -} - -/* - * __bt_bdelete -- - * Delete all key/data pairs matching the specified key. - * - * Parameters: - * t: tree + * tree: tree * key: key to delete * * Returns: * RET_ERROR, RET_SUCCESS and RET_SPECIAL if the key not found. */ static int -__bt_bdelete(t, key) +bt_bdelete(t, key) BTREE *t; const DBT *key; { - EPG *e; + EPG *e, save; PAGE *h; - int deleted, exact, redo; - - deleted = 0; + pgno_t cpgno, pg; + indx_t cindex; + int deleted, dirty1, dirty2, exact; /* Find any matching record; __bt_search pins the page. */ -loop: if ((e = __bt_search(t, key, &exact)) == NULL) - return (deleted ? RET_SUCCESS : RET_ERROR); + if ((e = __bt_search(t, key, &exact)) == NULL) + return (RET_ERROR); if (!exact) { mpool_put(t->bt_mp, e->page, 0); - return (deleted ? RET_SUCCESS : RET_SPECIAL); + return (RET_SPECIAL); } /* - * Delete forward, then delete backward, from the found key. If - * there are duplicates and we reach either side of the page, do - * the key search again, so that we get them all. + * Delete forward, then delete backward, from the found key. The + * ordering is so that the deletions don't mess up the page refs. + * The first loop deletes the key from the original page, the second + * unpins the original page. In the first loop, dirty1 is set if + * the original page is modified, and dirty2 is set if any subsequent + * pages are modified. In the second loop, dirty1 starts off set if + * the original page has been modified, and is set if any subsequent + * pages are modified. + * + * If find the key referenced by the cursor, don't delete it, just + * flag it for future deletion. The cursor page number is P_INVALID + * unless the sequential scan is initialized, so no reason to check. + * A special case is when the already deleted cursor record was the + * only record found. If so, then the delete opertion fails as no + * records were deleted. + * + * Cycle in place in the current page until the current record doesn't + * match the key or the page is empty. If the latter, walk forward, + * skipping empty pages and repeating until a record doesn't match + * the key or the end of the tree is reached. */ - redo = 0; - h = e->page; - do { - if (__bt_dleaf(t, key, h, e->index)) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); - } - if (F_ISSET(t, B_NODUPS)) { - if (NEXTINDEX(h) == 0) { - if (__bt_pdelete(t, h)) + cpgno = t->bt_bcursor.pgno; + cindex = t->bt_bcursor.index; + save = *e; + dirty1 = 0; + for (h = e->page, deleted = 0;;) { + dirty2 = 0; + do { + if (h->pgno == cpgno && e->index == cindex) { + if (!ISSET(t, B_DELCRSR)) { + SET(t, B_DELCRSR); + deleted = 1; + } + ++e->index; + } else { + if (__bt_dleaf(t, h, e->index)) { + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); + mpool_put(t->bt_mp, save.page, dirty1); return (RET_ERROR); - } else - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); - } - deleted = 1; - } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0); - - /* Check for right-hand edge of the page. */ - if (e->index == NEXTINDEX(h)) - redo = 1; + } + if (h->pgno == save.page->pgno) + dirty1 = MPOOL_DIRTY; + else + dirty2 = MPOOL_DIRTY; + deleted = 1; + } + } while (e->index < NEXTINDEX(h) && __bt_cmp(t, key, e) == 0); - /* Delete from the key to the beginning of the page. */ - while (e->index-- > 0) { - if (__bt_cmp(t, key, e) != 0) + /* + * Quit if didn't find a match, no next page, or first key on + * the next page doesn't match. Don't unpin the original page + * unless an error occurs. + */ + if (e->index < NEXTINDEX(h)) break; - if (__bt_dleaf(t, key, h, e->index) == RET_ERROR) { - mpool_put(t->bt_mp, h, 0); - return (RET_ERROR); + for (;;) { + if ((pg = h->nextpg) == P_INVALID) + goto done1; + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, save.page, dirty1); + return (RET_ERROR); + } + if (NEXTINDEX(h) != 0) { + e->page = h; + e->index = 0; + break; + } } - if (e->index == 0) - redo = 1; - } - /* Check for an empty page. */ - if (NEXTINDEX(h) == 0) { - if (__bt_pdelete(t, h)) - return (RET_ERROR); - goto loop; + if (__bt_cmp(t, key, e) != 0) + break; } - /* Put the page. */ - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - - if (redo) - goto loop; - return (RET_SUCCESS); -} - -/* - * __bt_pdelete -- - * Delete a single page from the tree. - * - * Parameters: - * t: tree - * h: leaf page - * - * Returns: - * RET_SUCCESS, RET_ERROR. - * - * Side-effects: - * mpool_put's the page - */ -static int -__bt_pdelete(t, h) - BTREE *t; - PAGE *h; -{ - BINTERNAL *bi; - PAGE *pg; - EPGNO *parent; - indx_t cnt, index, *ip, offset; - u_int32_t nksize; - char *from; - /* - * Walk the parent page stack -- a LIFO stack of the pages that were - * traversed when we searched for the page where the delete occurred. - * Each stack entry is a page number and a page index offset. The - * offset is for the page traversed on the search. We've just deleted - * a page, so we have to delete the key from the parent page. - * - * If the delete from the parent page makes it empty, this process may - * continue all the way up the tree. We stop if we reach the root page - * (which is never deleted, it's just not worth the effort) or if the - * delete does not empty the page. + * Reach here with the original page and the last page referenced + * pinned (they may be the same). Release it if not the original. */ - while ((parent = BT_POP(t)) != NULL) { - /* Get the parent page. */ - if ((pg = mpool_get(t->bt_mp, parent->pgno, 0)) == NULL) - return (RET_ERROR); - - index = parent->index; - bi = GETBINTERNAL(pg, index); - - /* Free any overflow pages. */ - if (bi->flags & P_BIGKEY && - __ovfl_delete(t, bi->bytes) == RET_ERROR) { - mpool_put(t->bt_mp, pg, 0); - return (RET_ERROR); - } +done1: if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, dirty2); - /* - * Free the parent if it has only the one key and it's not the - * root page. If it's the rootpage, turn it back into an empty - * leaf page. - */ - if (NEXTINDEX(pg) == 1) - if (pg->pgno == P_ROOT) { - pg->lower = BTDATAOFF; - pg->upper = t->bt_psize; - pg->flags = P_BLEAF; + /* + * Walk backwards from the record previous to the record returned by + * __bt_search, skipping empty pages, until a record doesn't match + * the key or reach the beginning of the tree. + */ + *e = save; + for (;;) { + if (e->index) + --e->index; + for (h = e->page; e->index; --e->index) { + if (__bt_cmp(t, key, e) != 0) + goto done2; + if (h->pgno == cpgno && e->index == cindex) { + if (!ISSET(t, B_DELCRSR)) { + SET(t, B_DELCRSR); + deleted = 1; + } } else { - if (__bt_relink(t, pg) || __bt_free(t, pg)) + if (__bt_dleaf(t, h, e->index) == RET_ERROR) { + mpool_put(t->bt_mp, h, dirty1); return (RET_ERROR); - continue; + } + if (h->pgno == save.page->pgno) + dirty1 = MPOOL_DIRTY; + deleted = 1; } - else { - /* Pack remaining key items at the end of the page. */ - nksize = NBINTERNAL(bi->ksize); - from = (char *)pg + pg->upper; - memmove(from + nksize, from, (char *)bi - from); - pg->upper += nksize; - - /* Adjust indices' offsets, shift the indices down. */ - offset = pg->linp[index]; - for (cnt = index, ip = &pg->linp[0]; cnt--; ++ip) - if (ip[0] < offset) - ip[0] += nksize; - for (cnt = NEXTINDEX(pg) - index; --cnt; ++ip) - ip[0] = ip[1] < offset ? ip[1] + nksize : ip[1]; - pg->lower -= sizeof(indx_t); } - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - break; + if ((pg = h->prevpg) == P_INVALID) + goto done2; + mpool_put(t->bt_mp, h, dirty1); + dirty1 = 0; + if ((e->page = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + e->index = NEXTINDEX(e->page); } - /* Free the leaf page, as long as it wasn't the root. */ - if (h->pgno == P_ROOT) { - mpool_put(t->bt_mp, h, MPOOL_DIRTY); - return (RET_SUCCESS); - } - return (__bt_relink(t, h) || __bt_free(t, h)); + /* + * Reach here with the last page that was looked at pinned. Release + * it. + */ +done2: mpool_put(t->bt_mp, h, dirty1); + return (deleted ? RET_SUCCESS : RET_SPECIAL); } /* - * __bt_dleaf -- - * Delete a single record from a leaf page. + * __BT_DLEAF -- Delete a single record from a leaf page. * * Parameters: * t: tree - * key: referenced key - * h: page - * index: index on page to delete + * index: index on current page to delete * * Returns: * RET_SUCCESS, RET_ERROR. */ int -__bt_dleaf(t, key, h, index) +__bt_dleaf(t, h, index) BTREE *t; - const DBT *key; PAGE *h; - u_int index; + indx_t index; { - BLEAF *bl; - indx_t cnt, *ip, offset; - u_int32_t nbytes; - void *to; + register BLEAF *bl; + register indx_t cnt, *ip, offset; + register size_t nbytes; char *from; + void *to; - /* If this record is referenced by the cursor, delete the cursor. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index == index && - __bt_curdel(t, key, h, index)) - return (RET_ERROR); - - /* If the entry uses overflow pages, make them available for reuse. */ + /* + * Delete a record from a btree leaf page. Internal records are never + * deleted from internal pages, regardless of the records that caused + * them to be added being deleted. Pages made empty by deletion are + * not reclaimed. They are, however, made available for reuse. + * + * Pack the remaining entries at the end of the page, shift the indices + * down, overwriting the deleted record and its index. If the record + * uses overflow pages, make them available for reuse. + */ to = bl = GETBLEAF(h, index); if (bl->flags & P_BIGKEY && __ovfl_delete(t, bl->bytes) == RET_ERROR) return (RET_ERROR); if (bl->flags & P_BIGDATA && __ovfl_delete(t, bl->bytes + bl->ksize) == RET_ERROR) return (RET_ERROR); - - /* Pack the remaining key/data items at the end of the page. */ nbytes = NBLEAF(bl); + + /* + * Compress the key/data pairs. Compress and adjust the [BR]LEAF + * offsets. Reset the headers. + */ from = (char *)h + h->upper; memmove(from + nbytes, from, (char *)to - from); h->upper += nbytes; - /* Adjust the indices' offsets, shift the indices down. */ offset = h->linp[index]; for (cnt = index, ip = &h->linp[0]; cnt--; ++ip) if (ip[0] < offset) @@ -512,146 +320,5 @@ __bt_dleaf(t, key, h, index) for (cnt = NEXTINDEX(h) - index; --cnt; ++ip) ip[0] = ip[1] < offset ? ip[1] + nbytes : ip[1]; h->lower -= sizeof(indx_t); - - /* If the cursor is on this page, adjust it as necessary. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index > index) - --t->bt_cursor.pg.index; - return (RET_SUCCESS); } - -/* - * __bt_curdel -- - * Delete the cursor. - * - * Parameters: - * t: tree - * key: referenced key (or NULL) - * h: page - * index: index on page to delete - * - * Returns: - * RET_SUCCESS, RET_ERROR. - */ -static int -__bt_curdel(t, key, h, index) - BTREE *t; - const DBT *key; - PAGE *h; - u_int index; -{ - CURSOR *c; - EPG e; - PAGE *pg; - int curcopy, status; - - /* - * If there are duplicates, move forward or backward to one. - * Otherwise, copy the key into the cursor area. - */ - c = &t->bt_cursor; - F_CLR(c, CURS_AFTER | CURS_BEFORE | CURS_ACQUIRE); - - curcopy = 0; - if (!F_ISSET(t, B_NODUPS)) { - /* - * We're going to have to do comparisons. If we weren't - * provided a copy of the key, i.e. the user is deleting - * the current cursor position, get one. - */ - if (key == NULL) { - e.page = h; - e.index = index; - if ((status = __bt_ret(t, &e, - &c->key, &c->key, NULL, NULL, 1)) != RET_SUCCESS) - return (status); - curcopy = 1; - key = &c->key; - } - /* Check previous key, if not at the beginning of the page. */ - if (index > 0) { - e.page = h; - e.index = index - 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_BEFORE); - goto dup2; - } - } - /* Check next key, if not at the end of the page. */ - if (index < NEXTINDEX(h) - 1) { - e.page = h; - e.index = index + 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_AFTER); - goto dup2; - } - } - /* Check previous key if at the beginning of the page. */ - if (index == 0 && h->prevpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (RET_ERROR); - e.page = pg; - e.index = NEXTINDEX(pg) - 1; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_BEFORE); - goto dup1; - } - mpool_put(t->bt_mp, pg, 0); - } - /* Check next key if at the end of the page. */ - if (index == NEXTINDEX(h) - 1 && h->nextpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (RET_ERROR); - e.page = pg; - e.index = 0; - if (__bt_cmp(t, key, &e) == 0) { - F_SET(c, CURS_AFTER); -dup1: mpool_put(t->bt_mp, pg, 0); -dup2: c->pg.pgno = e.page->pgno; - c->pg.index = e.index; - return (RET_SUCCESS); - } - mpool_put(t->bt_mp, pg, 0); - } - } - e.page = h; - e.index = index; - if (curcopy || (status = - __bt_ret(t, &e, &c->key, &c->key, NULL, NULL, 1)) == RET_SUCCESS) { - F_SET(c, CURS_ACQUIRE); - return (RET_SUCCESS); - } - return (status); -} - -/* - * __bt_relink -- - * Link around a deleted page. - * - * Parameters: - * t: tree - * h: page to be deleted - */ -static int -__bt_relink(t, h) - BTREE *t; - PAGE *h; -{ - PAGE *pg; - - if (h->nextpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (RET_ERROR); - pg->prevpg = h->prevpg; - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - } - if (h->prevpg != P_INVALID) { - if ((pg = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (RET_ERROR); - pg->nextpg = h->nextpg; - mpool_put(t->bt_mp, pg, MPOOL_DIRTY); - } - return (0); -} diff --git a/lib/libc/db/btree/bt_get.c b/lib/libc/db/btree/bt_get.c index 74824c73f4b2..28b2d603dfe5 100644 --- a/lib/libc/db/btree/bt_get.c +++ b/lib/libc/db/btree/bt_get.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_get.c 8.6 (Berkeley) 7/20/94"; +static char sccsid[] = "@(#)bt_get.c 8.2 (Berkeley) 9/7/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -91,15 +91,148 @@ __bt_get(dbp, key, data, flags) return (RET_SPECIAL); } - status = __bt_ret(t, e, NULL, NULL, data, &t->bt_rdata, 0); + /* + * A special case is if we found the record but it's flagged for + * deletion. In this case, we want to find another record with the + * same key, if it exists. Rather than look around the tree we call + * __bt_first and have it redo the search, as __bt_first will not + * return keys marked for deletion. Slow, but should never happen. + */ + if (ISSET(t, B_DELCRSR) && e->page->pgno == t->bt_bcursor.pgno && + e->index == t->bt_bcursor.index) { + mpool_put(t->bt_mp, e->page, 0); + if ((e = __bt_first(t, key, &exact)) == NULL) + return (RET_ERROR); + if (!exact) + return (RET_SPECIAL); + } + status = __bt_ret(t, e, NULL, data); /* * If the user is doing concurrent access, we copied the * key/data, toss the page. */ - if (F_ISSET(t, B_DB_LOCK)) + if (ISSET(t, B_DB_LOCK)) mpool_put(t->bt_mp, e->page, 0); else t->bt_pinned = e->page; return (status); } + +/* + * __BT_FIRST -- Find the first entry. + * + * Parameters: + * t: the tree + * key: the key + * + * Returns: + * The first entry in the tree greater than or equal to key. + */ +EPG * +__bt_first(t, key, exactp) + BTREE *t; + const DBT *key; + int *exactp; +{ + register PAGE *h; + register EPG *e; + EPG save; + pgno_t cpgno, pg; + indx_t cindex; + int found; + + /* + * Find any matching record; __bt_search pins the page. Only exact + * matches are tricky, otherwise just return the location of the key + * if it were to be inserted into the tree. + */ + if ((e = __bt_search(t, key, exactp)) == NULL) + return (NULL); + if (!*exactp) + return (e); + + if (ISSET(t, B_DELCRSR)) { + cpgno = t->bt_bcursor.pgno; + cindex = t->bt_bcursor.index; + } else { + cpgno = P_INVALID; + cindex = 0; /* GCC thinks it's uninitialized. */ + } + + /* + * Walk backwards, skipping empty pages, as long as the entry matches + * and there are keys left in the tree. Save a copy of each match in + * case we go too far. A special case is that we don't return a match + * on records that the cursor references that have already been flagged + * for deletion. + */ + save = *e; + h = e->page; + found = 0; + do { + if (cpgno != h->pgno || cindex != e->index) { + if (save.page->pgno != e->page->pgno) { + mpool_put(t->bt_mp, save.page, 0); + save = *e; + } else + save.index = e->index; + found = 1; + } + /* + * Make a special effort not to unpin the page the last (or + * original) match was on, but also make sure it's unpinned + * if an error occurs. + */ + while (e->index == 0) { + if (h->prevpg == P_INVALID) + goto done1; + if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) { + if (h->pgno == save.page->pgno) + mpool_put(t->bt_mp, save.page, 0); + return (NULL); + } + e->page = h; + e->index = NEXTINDEX(h); + } + --e->index; + } while (__bt_cmp(t, key, e) == 0); + + /* + * Reach here with the last page that was looked at pinned, which may + * or may not be the same as the last (or original) match page. If + * it's not useful, release it. + */ +done1: if (h->pgno != save.page->pgno) + mpool_put(t->bt_mp, h, 0); + + /* + * If still haven't found a record, the only possibility left is the + * next one. Move forward one slot, skipping empty pages and check. + */ + if (!found) { + h = save.page; + if (++save.index == NEXTINDEX(h)) { + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) { + *exactp = 0; + return (e); + } + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (NULL); + } while ((save.index = NEXTINDEX(h)) == 0); + save.page = h; + } + if (__bt_cmp(t, key, &save) != 0) { + *exactp = 0; + return (e); + } + } + *e = save; + *exactp = 1; + return (e); +} diff --git a/lib/libc/db/btree/bt_open.c b/lib/libc/db/btree/bt_open.c index f052249777d6..f156745f9700 100644 --- a/lib/libc/db/btree/bt_open.c +++ b/lib/libc/db/btree/bt_open.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94"; +static char sccsid[] = "@(#)bt_open.c 8.5 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -61,11 +61,6 @@ static char sccsid[] = "@(#)bt_open.c 8.10 (Berkeley) 8/17/94"; #include <db.h> #include "btree.h" -#ifdef DEBUG -#undef MINPSIZE -#define MINPSIZE 128 -#endif - static int byteorder __P((void)); static int nroot __P((BTREE *)); static int tmp __P((void)); @@ -162,6 +157,7 @@ __bt_open(fname, flags, mode, openinfo, dflags) if ((t = (BTREE *)malloc(sizeof(BTREE))) == NULL) goto err; memset(t, 0, sizeof(BTREE)); + t->bt_bcursor.pgno = P_INVALID; t->bt_fd = -1; /* Don't close unopened fd on error. */ t->bt_lorder = b.lorder; t->bt_order = NOT; @@ -171,9 +167,9 @@ __bt_open(fname, flags, mode, openinfo, dflags) if ((t->bt_dbp = dbp = (DB *)malloc(sizeof(DB))) == NULL) goto err; - memset(t->bt_dbp, 0, sizeof(DB)); + t->bt_flags = 0; if (t->bt_lorder != machine_lorder) - F_SET(t, B_NEEDSWAP); + SET(t, B_NEEDSWAP); dbp->type = DB_BTREE; dbp->internal = t; @@ -190,9 +186,9 @@ __bt_open(fname, flags, mode, openinfo, dflags) * open a backing temporary file. Otherwise, it's a disk-based tree. */ if (fname) { - switch (flags & O_ACCMODE) { + switch(flags & O_ACCMODE) { case O_RDONLY: - F_SET(t, B_RDONLY); + SET(t, B_RDONLY); break; case O_RDWR: break; @@ -200,7 +196,7 @@ __bt_open(fname, flags, mode, openinfo, dflags) default: goto einval; } - + if ((t->bt_fd = open(fname, flags, mode)) < 0) goto err; @@ -209,7 +205,7 @@ __bt_open(fname, flags, mode, openinfo, dflags) goto einval; if ((t->bt_fd = tmp()) == -1) goto err; - F_SET(t, B_INMEM); + SET(t, B_INMEM); } if (fcntl(t->bt_fd, F_SETFD, 1) == -1) @@ -218,7 +214,8 @@ __bt_open(fname, flags, mode, openinfo, dflags) if (fstat(t->bt_fd, &sb)) goto err; if (sb.st_size) { - if ((nr = read(t->bt_fd, &m, sizeof(BTMETA))) < 0) + nr = read(t->bt_fd, &m, sizeof(BTMETA)); + if (nr < 0) goto err; if (nr != sizeof(BTMETA)) goto eftype; @@ -231,28 +228,28 @@ __bt_open(fname, flags, mode, openinfo, dflags) * don't bother to return an error, we just clear the NEEDSWAP * bit. */ - if (m.magic == BTREEMAGIC) - F_CLR(t, B_NEEDSWAP); + if (m.m_magic == BTREEMAGIC) + CLR(t, B_NEEDSWAP); else { - F_SET(t, B_NEEDSWAP); - M_32_SWAP(m.magic); - M_32_SWAP(m.version); - M_32_SWAP(m.psize); - M_32_SWAP(m.free); - M_32_SWAP(m.nrecs); - M_32_SWAP(m.flags); + SET(t, B_NEEDSWAP); + M_32_SWAP(m.m_magic); + M_32_SWAP(m.m_version); + M_32_SWAP(m.m_psize); + M_32_SWAP(m.m_free); + M_32_SWAP(m.m_nrecs); + M_32_SWAP(m.m_flags); } - if (m.magic != BTREEMAGIC || m.version != BTREEVERSION) + if (m.m_magic != BTREEMAGIC || m.m_version != BTREEVERSION) goto eftype; - if (m.psize < MINPSIZE || m.psize > MAX_PAGE_OFFSET + 1 || - m.psize & sizeof(indx_t) - 1) + if (m.m_psize < MINPSIZE || m.m_psize > MAX_PAGE_OFFSET + 1 || + m.m_psize & sizeof(indx_t) - 1) goto eftype; - if (m.flags & ~SAVEMETA) + if (m.m_flags & ~SAVEMETA) goto eftype; - b.psize = m.psize; - F_SET(t, m.flags); - t->bt_free = m.free; - t->bt_nrecs = m.nrecs; + b.psize = m.m_psize; + t->bt_flags |= m.m_flags; + t->bt_free = m.m_free; + t->bt_nrecs = m.m_nrecs; } else { /* * Set the page size to the best value for I/O to this file. @@ -268,11 +265,11 @@ __bt_open(fname, flags, mode, openinfo, dflags) /* Set flag if duplicates permitted. */ if (!(b.flags & R_DUP)) - F_SET(t, B_NODUPS); + SET(t, B_NODUPS); t->bt_free = P_INVALID; t->bt_nrecs = 0; - F_SET(t, B_METADIRTY); + SET(t, B_METADIRTY); } t->bt_psize = b.psize; @@ -307,7 +304,7 @@ __bt_open(fname, flags, mode, openinfo, dflags) if ((t->bt_mp = mpool_open(NULL, t->bt_fd, t->bt_psize, ncache)) == NULL) goto err; - if (!F_ISSET(t, B_INMEM)) + if (!ISSET(t, B_INMEM)) mpool_filter(t->bt_mp, __bt_pgin, __bt_pgout, t); /* Create a root page if new tree. */ @@ -316,11 +313,11 @@ __bt_open(fname, flags, mode, openinfo, dflags) /* Global flags. */ if (dflags & DB_LOCK) - F_SET(t, B_DB_LOCK); + SET(t, B_DB_LOCK); if (dflags & DB_SHMEM) - F_SET(t, B_DB_SHMEM); + SET(t, B_DB_SHMEM); if (dflags & DB_TXN) - F_SET(t, B_DB_TXN); + SET(t, B_DB_TXN); return (dbp); @@ -360,9 +357,8 @@ nroot(t) mpool_put(t->bt_mp, meta, 0); return (RET_SUCCESS); } - if (errno != EINVAL) /* It's OK to not exist. */ + if (errno != EINVAL) return (RET_ERROR); - errno = 0; if ((meta = mpool_new(t->bt_mp, &npg)) == NULL) return (RET_ERROR); @@ -436,7 +432,7 @@ __bt_fd(dbp) } /* In-memory database can't have a file descriptor. */ - if (F_ISSET(t, B_INMEM)) { + if (ISSET(t, B_INMEM)) { errno = ENOENT; return (-1); } diff --git a/lib/libc/db/btree/bt_overflow.c b/lib/libc/db/btree/bt_overflow.c index b28b8e04711a..0057a03cd73e 100644 --- a/lib/libc/db/btree/bt_overflow.c +++ b/lib/libc/db/btree/bt_overflow.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_overflow.c 8.5 (Berkeley) 7/16/94"; +static char sccsid[] = "@(#)bt_overflow.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -69,7 +69,7 @@ static char sccsid[] = "@(#)bt_overflow.c 8.5 (Berkeley) 7/16/94"; * * Parameters: * t: tree - * p: pointer to { pgno_t, u_int32_t } + * p: pointer to { pgno_t, size_t } * buf: storage address * bufsz: storage size * @@ -81,16 +81,15 @@ __ovfl_get(t, p, ssz, buf, bufsz) BTREE *t; void *p; size_t *ssz; - void **buf; + char **buf; size_t *bufsz; { PAGE *h; pgno_t pg; - size_t nb, plen; - u_int32_t sz; + size_t nb, plen, sz; memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); *ssz = sz; #ifdef DEBUG @@ -99,8 +98,7 @@ __ovfl_get(t, p, ssz, buf, bufsz) #endif /* Make the buffer bigger as necessary. */ if (*bufsz < sz) { - *buf = (char *)(*buf == NULL ? malloc(sz) : realloc(*buf, sz)); - if (*buf == NULL) + if ((*buf = (char *)realloc(*buf, sz)) == NULL) return (RET_ERROR); *bufsz = sz; } @@ -144,8 +142,7 @@ __ovfl_put(t, dbt, pg) PAGE *h, *last; void *p; pgno_t npg; - size_t nb, plen; - u_int32_t sz; + size_t nb, plen, sz; /* * Allocate pages and copy the key/data record into them. Store the @@ -184,7 +181,7 @@ __ovfl_put(t, dbt, pg) * * Parameters: * t: tree - * p: pointer to { pgno_t, u_int32_t } + * p: pointer to { pgno_t, size_t } * * Returns: * RET_ERROR, RET_SUCCESS @@ -196,11 +193,10 @@ __ovfl_delete(t, p) { PAGE *h; pgno_t pg; - size_t plen; - u_int32_t sz; + size_t plen, sz; memmove(&pg, p, sizeof(pgno_t)); - memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(u_int32_t)); + memmove(&sz, (char *)p + sizeof(pgno_t), sizeof(size_t)); #ifdef DEBUG if (pg == P_INVALID || sz == 0) diff --git a/lib/libc/db/btree/bt_page.c b/lib/libc/db/btree/bt_page.c index 0d9d138d5cee..f71a40d84716 100644 --- a/lib/libc/db/btree/bt_page.c +++ b/lib/libc/db/btree/bt_page.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_page.c 8.3 (Berkeley) 7/14/94"; +static char sccsid[] = "@(#)bt_page.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -43,8 +43,7 @@ static char sccsid[] = "@(#)bt_page.c 8.3 (Berkeley) 7/14/94"; #include "btree.h" /* - * __bt_free -- - * Put a page on the freelist. + * __BT_FREE -- Put a page on the freelist. * * Parameters: * t: tree @@ -52,16 +51,13 @@ static char sccsid[] = "@(#)bt_page.c 8.3 (Berkeley) 7/14/94"; * * Returns: * RET_ERROR, RET_SUCCESS - * - * Side-effect: - * mpool_put's the page. */ int __bt_free(t, h) BTREE *t; PAGE *h; { - /* Insert the page at the head of the free list. */ + /* Insert the page at the start of the free list. */ h->prevpg = P_INVALID; h->nextpg = t->bt_free; t->bt_free = h->pgno; @@ -71,8 +67,7 @@ __bt_free(t, h) } /* - * __bt_new -- - * Get a new page, preferably from the freelist. + * __BT_NEW -- Get a new page, preferably from the freelist. * * Parameters: * t: tree @@ -90,9 +85,9 @@ __bt_new(t, npg) if (t->bt_free != P_INVALID && (h = mpool_get(t->bt_mp, t->bt_free, 0)) != NULL) { - *npg = t->bt_free; - t->bt_free = h->nextpg; - return (h); + *npg = t->bt_free; + t->bt_free = h->nextpg; + return (h); } return (mpool_new(t->bt_mp, npg)); } diff --git a/lib/libc/db/btree/bt_put.c b/lib/libc/db/btree/bt_put.c index 952be09e551f..11a211b15a63 100644 --- a/lib/libc/db/btree/bt_put.c +++ b/lib/libc/db/btree/bt_put.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_put.c 8.8 (Berkeley) 7/26/94"; +static char sccsid[] = "@(#)bt_put.c 8.3 (Berkeley) 9/16/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -76,7 +76,7 @@ __bt_put(dbp, key, data, flags) PAGE *h; indx_t index, nxtindex; pgno_t pg; - u_int32_t nbytes; + size_t nbytes; int dflags, exact, status; char *dest, db[NOVFLSIZE], kb[NOVFLSIZE]; @@ -88,38 +88,33 @@ __bt_put(dbp, key, data, flags) t->bt_pinned = NULL; } - /* Check for change to a read-only tree. */ - if (F_ISSET(t, B_RDONLY)) { - errno = EPERM; - return (RET_ERROR); - } - switch (flags) { + case R_CURSOR: + if (!ISSET(t, B_SEQINIT)) + goto einval; + if (ISSET(t, B_DELCRSR)) + goto einval; + break; case 0: case R_NOOVERWRITE: break; - case R_CURSOR: - /* - * If flags is R_CURSOR, put the cursor. Must already - * have started a scan and not have already deleted it. - */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, - CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE)) - break; - /* FALLTHROUGH */ default: - errno = EINVAL; +einval: errno = EINVAL; + return (RET_ERROR); + } + + if (ISSET(t, B_RDONLY)) { + errno = EPERM; return (RET_ERROR); } /* - * If the key/data pair won't fit on a page, store it on overflow - * pages. Only put the key on the overflow page if the pair are - * still too big after moving the data to an overflow page. + * If the key/data won't fit on a page, store it on indirect pages. + * Only store the key on the overflow page if it's too big after the + * data is on an overflow page. * * XXX - * If the insert fails later on, the overflow pages aren't recovered. + * If the insert fails later on, these pages aren't recovered. */ dflags = 0; if (key->size + data->size > t->bt_ovflsize) { @@ -130,7 +125,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) tkey.size = NOVFLSIZE; memmove(kb, &pg, sizeof(pgno_t)); memmove(kb + sizeof(pgno_t), - &key->size, sizeof(u_int32_t)); + &key->size, sizeof(size_t)); dflags |= P_BIGKEY; key = &tkey; } @@ -141,7 +136,7 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) tdata.size = NOVFLSIZE; memmove(db, &pg, sizeof(pgno_t)); memmove(db + sizeof(pgno_t), - &data->size, sizeof(u_int32_t)); + &data->size, sizeof(size_t)); dflags |= P_BIGDATA; data = &tdata; } @@ -151,15 +146,15 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) /* Replace the cursor. */ if (flags == R_CURSOR) { - if ((h = mpool_get(t->bt_mp, t->bt_cursor.pg.pgno, 0)) == NULL) + if ((h = mpool_get(t->bt_mp, t->bt_bcursor.pgno, 0)) == NULL) return (RET_ERROR); - index = t->bt_cursor.pg.index; + index = t->bt_bcursor.index; goto delete; } /* - * Find the key to delete, or, the location at which to insert. - * Bt_fast and __bt_search both pin the returned page. + * Find the key to delete, or, the location at which to insert. Bt_fast + * and __bt_search pin the returned page. */ if (t->bt_order == NOT || (e = bt_fast(t, key, data, &exact)) == NULL) if ((e = __bt_search(t, key, &exact)) == NULL) @@ -168,26 +163,34 @@ storekey: if (__ovfl_put(t, key, &pg) == RET_ERROR) index = e->index; /* - * Add the key/data pair to the tree. If an identical key is already - * in the tree, and R_NOOVERWRITE is set, an error is returned. If - * R_NOOVERWRITE is not set, the key is either added (if duplicates are - * permitted) or an error is returned. + * Add the specified key/data pair to the tree. If an identical key + * is already in the tree, and R_NOOVERWRITE is set, an error is + * returned. If R_NOOVERWRITE is not set, the key is either added (if + * duplicates are permitted) or an error is returned. + * + * Pages are split as required. */ switch (flags) { case R_NOOVERWRITE: if (!exact) break; + /* + * One special case is if the cursor references the record and + * it's been flagged for deletion. Then, we delete the record, + * leaving the cursor there -- this means that the inserted + * record will not be seen in a cursor scan. + */ + if (ISSET(t, B_DELCRSR) && t->bt_bcursor.pgno == h->pgno && + t->bt_bcursor.index == index) { + CLR(t, B_DELCRSR); + goto delete; + } mpool_put(t->bt_mp, h, 0); return (RET_SPECIAL); default: - if (!exact || !F_ISSET(t, B_NODUPS)) + if (!exact || !ISSET(t, B_NODUPS)) break; - /* - * !!! - * Note, the delete may empty the page, so we need to put a - * new entry into the page immediately. - */ -delete: if (__bt_dleaf(t, key, h, index) == RET_ERROR) { +delete: if (__bt_dleaf(t, h, index) == RET_ERROR) { mpool_put(t->bt_mp, h, 0); return (RET_ERROR); } @@ -217,12 +220,6 @@ delete: if (__bt_dleaf(t, key, h, index) == RET_ERROR) { dest = (char *)h + h->upper; WR_BLEAF(dest, key, data, dflags); - /* If the cursor is on this page, adjust it as necessary. */ - if (F_ISSET(&t->bt_cursor, CURS_INIT) && - !F_ISSET(&t->bt_cursor, CURS_ACQUIRE) && - t->bt_cursor.pg.pgno == h->pgno && t->bt_cursor.pg.index >= index) - ++t->bt_cursor.pg.index; - if (t->bt_order == NOT) if (h->nextpg == P_INVALID) { if (index == NEXTINDEX(h) - 1) { @@ -241,10 +238,11 @@ delete: if (__bt_dleaf(t, key, h, index) == RET_ERROR) { mpool_put(t->bt_mp, h, MPOOL_DIRTY); success: - if (flags == R_SETCURSOR) - __bt_setcur(t, e->page->pgno, e->index); - - F_SET(t, B_MODIFIED); + if (flags == R_SETCURSOR) { + t->bt_bcursor.pgno = e->page->pgno; + t->bt_bcursor.index = e->index; + } + SET(t, B_MODIFIED); return (RET_SUCCESS); } @@ -269,7 +267,7 @@ bt_fast(t, key, data, exactp) int *exactp; { PAGE *h; - u_int32_t nbytes; + size_t nbytes; int cmp; if ((h = mpool_get(t->bt_mp, t->bt_last.pgno, 0)) == NULL) { @@ -280,8 +278,8 @@ bt_fast(t, key, data, exactp) t->bt_cur.index = t->bt_last.index; /* - * If won't fit in this page or have too many keys in this page, - * have to search to get split stack. + * If won't fit in this page or have too many keys in this page, have + * to search to get split stack. */ nbytes = NBLEAFDBT(key->size, data->size); if (h->upper - h->lower < nbytes + sizeof(indx_t)) diff --git a/lib/libc/db/btree/bt_search.c b/lib/libc/db/btree/bt_search.c index 485afcbbf025..ff334216d019 100644 --- a/lib/libc/db/btree/bt_search.c +++ b/lib/libc/db/btree/bt_search.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_search.c 8.8 (Berkeley) 7/31/94"; +static char sccsid[] = "@(#)bt_search.c 8.6 (Berkeley) 3/15/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -45,12 +45,11 @@ static char sccsid[] = "@(#)bt_search.c 8.8 (Berkeley) 7/31/94"; #include <db.h> #include "btree.h" -static int __bt_snext __P((BTREE *, PAGE *, const DBT *, int *)); -static int __bt_sprev __P((BTREE *, PAGE *, const DBT *, int *)); +static int bt_snext __P((BTREE *, PAGE *, const DBT *, int *)); +static int bt_sprev __P((BTREE *, PAGE *, const DBT *, int *)); /* - * __bt_search -- - * Search a btree for a key. + * __BT_SEARCH -- Search a btree for a key. * * Parameters: * t: tree to search @@ -96,26 +95,24 @@ __bt_search(t, key, exactp) } /* - * If it's a leaf page, we're almost done. If no duplicates - * are allowed, or we have an exact match, we're done. Else, - * it's possible that there were matching keys on this page, - * which later deleted, and we're on a page with no matches - * while there are matches on other pages. If at the start or - * end of a page, check the adjacent page. + * If it's a leaf page, and duplicates aren't allowed, we're + * done. If duplicates are allowed, it's possible that there + * were duplicate keys on duplicate pages, and they were later + * deleted, so we could be on a page with no matches while + * there are matches on other pages. If we're at the start or + * end of a page, check on both sides. */ if (h->flags & P_BLEAF) { - if (!F_ISSET(t, B_NODUPS)) { + t->bt_cur.index = base; + *exactp = 0; + if (!ISSET(t, B_NODUPS)) { if (base == 0 && - h->prevpg != P_INVALID && - __bt_sprev(t, h, key, exactp)) + bt_sprev(t, h, key, exactp)) return (&t->bt_cur); if (base == NEXTINDEX(h) && - h->nextpg != P_INVALID && - __bt_snext(t, h, key, exactp)) + bt_snext(t, h, key, exactp)) return (&t->bt_cur); } - *exactp = 0; - t->bt_cur.index = base; return (&t->bt_cur); } @@ -128,86 +125,111 @@ __bt_search(t, key, exactp) */ index = base ? base - 1 : base; -next: BT_PUSH(t, h->pgno, index); +next: if (__bt_push(t, h->pgno, index) == RET_ERROR) + return (NULL); pg = GETBINTERNAL(h, index)->pgno; mpool_put(t->bt_mp, h, 0); } } /* - * __bt_snext -- - * Check for an exact match after the key. + * BT_SNEXT -- Check for an exact match after the key. * * Parameters: - * t: tree - * h: current page - * key: key + * t: tree to search + * h: current page. + * key: key to find * exactp: pointer to exact match flag * * Returns: * If an exact match found. */ static int -__bt_snext(t, h, key, exactp) +bt_snext(t, h, key, exactp) BTREE *t; PAGE *h; const DBT *key; int *exactp; { EPG e; + PAGE *tp; + pgno_t pg; + /* Skip until reach the end of the tree or a key. */ + for (pg = h->nextpg; pg != P_INVALID;) { + if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, h, 0); + return (NULL); + } + if (NEXTINDEX(tp) != 0) + break; + pg = tp->prevpg; + mpool_put(t->bt_mp, tp, 0); + } /* - * Get the next page. The key is either an exact - * match, or not as good as the one we already have. + * The key is either an exact match, or not as good as + * the one we already have. */ - if ((e.page = mpool_get(t->bt_mp, h->nextpg, 0)) == NULL) - return (0); - e.index = 0; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); + if (pg != P_INVALID) { + e.page = tp; + e.index = NEXTINDEX(tp) - 1; + if (__bt_cmp(t, key, &e) == 0) { + mpool_put(t->bt_mp, h, 0); + t->bt_cur = e; + *exactp = 1; + return (1); + } } - mpool_put(t->bt_mp, e.page, 0); return (0); } /* - * __bt_sprev -- - * Check for an exact match before the key. + * BT_SPREV -- Check for an exact match before the key. * * Parameters: - * t: tree - * h: current page - * key: key + * t: tree to search + * h: current page. + * key: key to find * exactp: pointer to exact match flag * * Returns: * If an exact match found. */ static int -__bt_sprev(t, h, key, exactp) +bt_sprev(t, h, key, exactp) BTREE *t; PAGE *h; const DBT *key; int *exactp; { EPG e; + PAGE *tp; + pgno_t pg; + /* Skip until reach the beginning of the tree or a key. */ + for (pg = h->prevpg; pg != P_INVALID;) { + if ((tp = mpool_get(t->bt_mp, pg, 0)) == NULL) { + mpool_put(t->bt_mp, h, 0); + return (NULL); + } + if (NEXTINDEX(tp) != 0) + break; + pg = tp->prevpg; + mpool_put(t->bt_mp, tp, 0); + } /* - * Get the previous page. The key is either an exact - * match, or not as good as the one we already have. + * The key is either an exact match, or not as good as + * the one we already have. */ - if ((e.page = mpool_get(t->bt_mp, h->prevpg, 0)) == NULL) - return (0); - e.index = NEXTINDEX(e.page) - 1; - if (__bt_cmp(t, key, &e) == 0) { - mpool_put(t->bt_mp, h, 0); - t->bt_cur = e; - *exactp = 1; - return (1); + if (pg != P_INVALID) { + e.page = tp; + e.index = NEXTINDEX(tp) - 1; + if (__bt_cmp(t, key, &e) == 0) { + mpool_put(t->bt_mp, h, 0); + t->bt_cur = e; + *exactp = 1; + return (1); + } } - mpool_put(t->bt_mp, e.page, 0); return (0); } diff --git a/lib/libc/db/btree/bt_seq.c b/lib/libc/db/btree/bt_seq.c index 303b4819031f..182ef7080d5e 100644 --- a/lib/libc/db/btree/bt_seq.c +++ b/lib/libc/db/btree/bt_seq.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_seq.c 8.7 (Berkeley) 7/20/94"; +static char sccsid[] = "@(#)bt_seq.c 8.2 (Berkeley) 9/7/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -48,21 +48,24 @@ static char sccsid[] = "@(#)bt_seq.c 8.7 (Berkeley) 7/20/94"; #include <db.h> #include "btree.h" -static int __bt_first __P((BTREE *, const DBT *, EPG *, int *)); -static int __bt_seqadv __P((BTREE *, EPG *, int)); -static int __bt_seqset __P((BTREE *, EPG *, DBT *, int)); +static int bt_seqadv __P((BTREE *, EPG *, int)); +static int bt_seqset __P((BTREE *, EPG *, DBT *, int)); /* * Sequential scan support. * - * The tree can be scanned sequentially, starting from either end of the - * tree or from any specific key. A scan request before any scanning is - * done is initialized as starting from the least node. + * The tree can be scanned sequentially, starting from either end of the tree + * or from any specific key. A scan request before any scanning is done is + * initialized as starting from the least node. + * + * Each tree has an EPGNO which has the current position of the cursor. The + * cursor has to survive deletions/insertions in the tree without losing its + * position. This is done by noting deletions without doing them, and then + * doing them when the cursor moves (or the tree is closed). */ /* - * __bt_seq -- - * Btree sequential scan interface. + * __BT_SEQ -- Btree sequential scan interface. * * Parameters: * dbp: pointer to access method @@ -93,21 +96,21 @@ __bt_seq(dbp, key, data, flags) /* * If scan unitialized as yet, or starting at a specific record, set - * the scan to a specific key. Both __bt_seqset and __bt_seqadv pin - * the page the cursor references if they're successful. + * the scan to a specific key. Both bt_seqset and bt_seqadv pin the + * page the cursor references if they're successful. */ - switch (flags) { + switch(flags) { case R_NEXT: case R_PREV: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - status = __bt_seqadv(t, &e, flags); + if (ISSET(t, B_SEQINIT)) { + status = bt_seqadv(t, &e, flags); break; } /* FALLTHROUGH */ + case R_CURSOR: case R_FIRST: case R_LAST: - case R_CURSOR: - status = __bt_seqset(t, &e, key, flags); + status = bt_seqset(t, &e, key, flags); break; default: errno = EINVAL; @@ -115,26 +118,27 @@ __bt_seq(dbp, key, data, flags) } if (status == RET_SUCCESS) { - __bt_setcur(t, e.page->pgno, e.index); + status = __bt_ret(t, &e, key, data); - status = - __bt_ret(t, &e, key, &t->bt_rkey, data, &t->bt_rdata, 0); + /* Update the actual cursor. */ + t->bt_bcursor.pgno = e.page->pgno; + t->bt_bcursor.index = e.index; /* * If the user is doing concurrent access, we copied the * key/data, toss the page. */ - if (F_ISSET(t, B_DB_LOCK)) + if (ISSET(t, B_DB_LOCK)) mpool_put(t->bt_mp, e.page, 0); else t->bt_pinned = e.page; + SET(t, B_SEQINIT); } return (status); } /* - * __bt_seqset -- - * Set the sequential scan to a specific key. + * BT_SEQSET -- Set the sequential scan to a specific key. * * Parameters: * t: tree @@ -149,50 +153,87 @@ __bt_seq(dbp, key, data, flags) * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. */ static int -__bt_seqset(t, ep, key, flags) +bt_seqset(t, ep, key, flags) BTREE *t; EPG *ep; DBT *key; int flags; { + EPG *e; PAGE *h; pgno_t pg; int exact; /* - * Find the first, last or specific key in the tree and point the - * cursor at it. The cursor may not be moved until a new key has - * been found. + * Delete any already deleted record that we've been saving because + * the cursor pointed to it. Since going to a specific key, should + * delete any logically deleted records so they aren't found. + */ + if (ISSET(t, B_DELCRSR) && __bt_crsrdel(t, &t->bt_bcursor)) + return (RET_ERROR); + + /* + * Find the first, last or specific key in the tree and point the cursor + * at it. The cursor may not be moved until a new key has been found. */ - switch (flags) { + switch(flags) { case R_CURSOR: /* Keyed scan. */ /* - * Find the first instance of the key or the smallest key - * which is greater than or equal to the specified key. + * Find the first instance of the key or the smallest key which + * is greater than or equal to the specified key. If run out + * of keys, return RET_SPECIAL. */ if (key->data == NULL || key->size == 0) { errno = EINVAL; return (RET_ERROR); } - return (__bt_first(t, key, ep, &exact)); + e = __bt_first(t, key, &exact); /* Returns pinned page. */ + if (e == NULL) + return (RET_ERROR); + /* + * If at the end of a page, skip any empty pages and find the + * next entry. + */ + if (e->index == NEXTINDEX(e->page)) { + h = e->page; + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); + e->index = 0; + e->page = h; + } + *ep = *e; + break; case R_FIRST: /* First record. */ case R_NEXT: /* Walk down the left-hand side of the tree. */ for (pg = P_ROOT;;) { if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) return (RET_ERROR); - - /* Check for an empty tree. */ - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - if (h->flags & (P_BLEAF | P_RLEAF)) break; pg = GETBINTERNAL(h, 0)->pgno; mpool_put(t->bt_mp, h, 0); } + + /* Skip any empty pages. */ + while (NEXTINDEX(h) == 0 && h->nextpg != P_INVALID) { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } + + if (NEXTINDEX(h) == 0) { + mpool_put(t->bt_mp, h, 0); + return (RET_SPECIAL); + } + ep->page = h; ep->index = 0; break; @@ -202,19 +243,25 @@ __bt_seqset(t, ep, key, flags) for (pg = P_ROOT;;) { if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) return (RET_ERROR); - - /* Check for an empty tree. */ - if (NEXTINDEX(h) == 0) { - mpool_put(t->bt_mp, h, 0); - return (RET_SPECIAL); - } - if (h->flags & (P_BLEAF | P_RLEAF)) break; pg = GETBINTERNAL(h, NEXTINDEX(h) - 1)->pgno; mpool_put(t->bt_mp, h, 0); } + /* Skip any empty pages. */ + while (NEXTINDEX(h) == 0 && h->prevpg != P_INVALID) { + pg = h->prevpg; + mpool_put(t->bt_mp, h, 0); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } + + if (NEXTINDEX(h) == 0) { + mpool_put(t->bt_mp, h, 0); + return (RET_SPECIAL); + } + ep->page = h; ep->index = NEXTINDEX(h) - 1; break; @@ -223,8 +270,7 @@ __bt_seqset(t, ep, key, flags) } /* - * __bt_seqadvance -- - * Advance the sequential scan. + * BT_SEQADVANCE -- Advance the sequential scan. * * Parameters: * t: tree @@ -237,224 +283,98 @@ __bt_seqset(t, ep, key, flags) * RET_ERROR, RET_SUCCESS or RET_SPECIAL if there's no next key. */ static int -__bt_seqadv(t, ep, flags) +bt_seqadv(t, e, flags) BTREE *t; - EPG *ep; + EPG *e; int flags; { - CURSOR *c; + EPGNO *c, delc; PAGE *h; indx_t index; pgno_t pg; - int exact; - /* - * There are a couple of states that we can be in. The cursor has - * been initialized by the time we get here, but that's all we know. - */ - c = &t->bt_cursor; + /* Save the current cursor if going to delete it. */ + c = &t->bt_bcursor; + if (ISSET(t, B_DELCRSR)) + delc = *c; - /* - * The cursor was deleted where there weren't any duplicate records, - * so the key was saved. Find out where that key would go in the - * current tree. It doesn't matter if the returned key is an exact - * match or not -- if it's an exact match, the record was added after - * the delete so we can just return it. If not, as long as there's - * a record there, return it. - */ - if (F_ISSET(c, CURS_ACQUIRE)) - return (__bt_first(t, &c->key, ep, &exact)); - - /* Get the page referenced by the cursor. */ - if ((h = mpool_get(t->bt_mp, c->pg.pgno, 0)) == NULL) + if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) return (RET_ERROR); /* - * Find the next/previous record in the tree and point the cursor at - * it. The cursor may not be moved until a new key has been found. + * Find the next/previous record in the tree and point the cursor at it. + * The cursor may not be moved until a new key has been found. */ - switch (flags) { + index = c->index; + switch(flags) { case R_NEXT: /* Next record. */ - /* - * The cursor was deleted in duplicate records, and moved - * forward to a record that has yet to be returned. Clear - * that flag, and return the record. - */ - if (F_ISSET(c, CURS_AFTER)) - goto usecurrent; - index = c->pg.index; if (++index == NEXTINDEX(h)) { - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); + do { + pg = h->nextpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); index = 0; } break; case R_PREV: /* Previous record. */ - /* - * The cursor was deleted in duplicate records, and moved - * backward to a record that has yet to be returned. Clear - * that flag, and return the record. - */ - if (F_ISSET(c, CURS_BEFORE)) { -usecurrent: F_CLR(c, CURS_AFTER | CURS_BEFORE); - ep->page = h; - ep->index = c->pg.index; - return (RET_SUCCESS); - } - index = c->pg.index; - if (index == 0) { - pg = h->prevpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) - return (RET_ERROR); + if (index-- == 0) { + do { + pg = h->prevpg; + mpool_put(t->bt_mp, h, 0); + if (pg == P_INVALID) + return (RET_SPECIAL); + if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + return (RET_ERROR); + } while (NEXTINDEX(h) == 0); index = NEXTINDEX(h) - 1; - } else - --index; + } break; } - ep->page = h; - ep->index = index; - return (RET_SUCCESS); -} - -/* - * __bt_first -- - * Find the first entry. - * - * Parameters: - * t: the tree - * key: the key - * erval: return EPG - * exactp: pointer to exact match flag - * - * Returns: - * The first entry in the tree greater than or equal to key, - * or RET_SPECIAL if no such key exists. - */ -static int -__bt_first(t, key, erval, exactp) - BTREE *t; - const DBT *key; - EPG *erval; - int *exactp; -{ - PAGE *h; - EPG *ep, save; - pgno_t pg; + e->page = h; + e->index = index; /* - * Find any matching record; __bt_search pins the page. - * - * If it's an exact match and duplicates are possible, walk backwards - * in the tree until we find the first one. Otherwise, make sure it's - * a valid key (__bt_search may return an index just past the end of a - * page) and return it. + * Delete any already deleted record that we've been saving because the + * cursor pointed to it. This could cause the new index to be shifted + * down by one if the record we're deleting is on the same page and has + * a larger index. */ - if ((ep = __bt_search(t, key, exactp)) == NULL) - return (NULL); - if (*exactp) { - if (F_ISSET(t, B_NODUPS)) { - *erval = *ep; - return (RET_SUCCESS); - } - - /* - * Walk backwards, as long as the entry matches and there are - * keys left in the tree. Save a copy of each match in case - * we go too far. - */ - save = *ep; - h = ep->page; - do { - if (save.page->pgno != ep->page->pgno) { - mpool_put(t->bt_mp, save.page, 0); - save = *ep; - } else - save.index = ep->index; - - /* - * Don't unpin the page the last (or original) match - * was on, but make sure it's unpinned if an error - * occurs. - */ - if (ep->index == 0) { - if (h->prevpg == P_INVALID) - break; - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - if ((h = mpool_get(t->bt_mp, - h->prevpg, 0)) == NULL) { - if (h->pgno == save.page->pgno) - mpool_put(t->bt_mp, - save.page, 0); - return (RET_ERROR); - } - ep->page = h; - ep->index = NEXTINDEX(h); - } - --ep->index; - } while (__bt_cmp(t, key, ep) == 0); - - /* - * Reach here with the last page that was looked at pinned, - * which may or may not be the same as the last (or original) - * match page. If it's not useful, release it. - */ - if (h->pgno != save.page->pgno) - mpool_put(t->bt_mp, h, 0); - - *erval = save; - return (RET_SUCCESS); - } - - /* If at the end of a page, find the next entry. */ - if (ep->index == NEXTINDEX(ep->page)) { - h = ep->page; - pg = h->nextpg; - mpool_put(t->bt_mp, h, 0); - if (pg == P_INVALID) - return (RET_SPECIAL); - if ((h = mpool_get(t->bt_mp, pg, 0)) == NULL) + if (ISSET(t, B_DELCRSR)) { + CLR(t, B_DELCRSR); /* Don't try twice. */ + if (c->pgno == delc.pgno && c->index > delc.index) + --c->index; + if (__bt_crsrdel(t, &delc)) return (RET_ERROR); - ep->index = 0; - ep->page = h; } - *erval = *ep; return (RET_SUCCESS); } /* - * __bt_setcur -- - * Set the cursor to an entry in the tree. + * __BT_CRSRDEL -- Delete the record referenced by the cursor. * * Parameters: - * t: the tree - * pgno: page number - * index: page index + * t: tree + * + * Returns: + * RET_ERROR, RET_SUCCESS */ -void -__bt_setcur(t, pgno, index) +int +__bt_crsrdel(t, c) BTREE *t; - pgno_t pgno; - u_int index; + EPGNO *c; { - /* Lose any already deleted key. */ - if (t->bt_cursor.key.data != NULL) { - free(t->bt_cursor.key.data); - t->bt_cursor.key.size = 0; - t->bt_cursor.key.data = NULL; - } - F_CLR(&t->bt_cursor, CURS_ACQUIRE | CURS_AFTER | CURS_BEFORE); + PAGE *h; + int status; - /* Update the cursor. */ - t->bt_cursor.pg.pgno = pgno; - t->bt_cursor.pg.index = index; - F_SET(&t->bt_cursor, CURS_INIT); + CLR(t, B_DELCRSR); /* Don't try twice. */ + if ((h = mpool_get(t->bt_mp, c->pgno, 0)) == NULL) + return (RET_ERROR); + status = __bt_dleaf(t, h, c->index); + mpool_put(t->bt_mp, h, MPOOL_DIRTY); + return (status); } diff --git a/lib/libc/db/btree/bt_split.c b/lib/libc/db/btree/bt_split.c index 1646d8215950..4a572c04c682 100644 --- a/lib/libc/db/btree/bt_split.c +++ b/lib/libc/db/btree/bt_split.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_split.c 8.9 (Berkeley) 7/26/94"; +static char sccsid[] = "@(#)bt_split.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -79,13 +79,13 @@ u_long bt_rootsplit, bt_split, bt_sortsplit, bt_pfxsaved; * RET_ERROR, RET_SUCCESS */ int -__bt_split(t, sp, key, data, flags, ilen, argskip) +__bt_split(t, sp, key, data, flags, ilen, skip) BTREE *t; PAGE *sp; const DBT *key, *data; int flags; size_t ilen; - u_int32_t argskip; + indx_t skip; { BINTERNAL *bi; BLEAF *bl, *tbl; @@ -93,8 +93,7 @@ __bt_split(t, sp, key, data, flags, ilen, argskip) EPGNO *parent; PAGE *h, *l, *r, *lchild, *rchild; indx_t nxtindex; - u_int16_t skip; - u_int32_t n, nbytes, nksize; + size_t n, nbytes, nksize; int parentsplit; char *dest; @@ -104,7 +103,6 @@ __bt_split(t, sp, key, data, flags, ilen, argskip) * skip set to the offset which should be used. Additionally, l and r * are pinned. */ - skip = argskip; h = sp->pgno == P_ROOT ? bt_root(t, sp, &l, &r, &skip, ilen) : bt_page(t, sp, &l, &r, &skip, ilen); @@ -117,14 +115,14 @@ __bt_split(t, sp, key, data, flags, ilen, argskip) */ h->linp[skip] = h->upper -= ilen; dest = (char *)h + h->upper; - if (F_ISSET(t, R_RECNO)) + if (ISSET(t, R_RECNO)) WR_RLEAF(dest, data, flags) else WR_BLEAF(dest, key, data, flags) /* If the root page was split, make it look right. */ if (sp->pgno == P_ROOT && - (F_ISSET(t, R_RECNO) ? + (ISSET(t, R_RECNO) ? bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) goto err2; @@ -232,7 +230,7 @@ __bt_split(t, sp, key, data, flags, ilen, argskip) } /* Insert the key into the parent page. */ - switch (rchild->flags & P_TYPE) { + switch(rchild->flags & P_TYPE) { case P_BINTERNAL: h->linp[skip] = h->upper -= nbytes; dest = (char *)h + h->linp[skip]; @@ -297,7 +295,7 @@ __bt_split(t, sp, key, data, flags, ilen, argskip) /* If the root page was split, make it look right. */ if (sp->pgno == P_ROOT && - (F_ISSET(t, R_RECNO) ? + (ISSET(t, R_RECNO) ? bt_rroot(t, sp, l, r) : bt_broot(t, sp, l, r)) == RET_ERROR) goto err1; @@ -390,9 +388,6 @@ bt_page(t, h, lp, rp, skip, ilen) mpool_put(t->bt_mp, r, 0); return (NULL); } -#ifdef PURIFY - memset(l, 0xff, t->bt_psize); -#endif l->pgno = h->pgno; l->nextpg = r->pgno; l->prevpg = h->prevpg; @@ -408,7 +403,7 @@ bt_page(t, h, lp, rp, skip, ilen) return (NULL); } tp->prevpg = r->pgno; - mpool_put(t->bt_mp, tp, MPOOL_DIRTY); + mpool_put(t->bt_mp, tp, 0); } /* @@ -539,7 +534,7 @@ bt_broot(t, h, l, r) { BINTERNAL *bi; BLEAF *bl; - u_int32_t nbytes; + size_t nbytes; char *dest; /* @@ -555,7 +550,7 @@ bt_broot(t, h, l, r) dest = (char *)h + h->upper; WR_BINTERNAL(dest, 0, l->pgno, 0); - switch (h->flags & P_TYPE) { + switch(h->flags & P_TYPE) { case P_BLEAF: bl = GETBLEAF(r, 0); nbytes = NBINTERNAL(bl->ksize); @@ -618,12 +613,12 @@ bt_psplit(t, h, l, r, pskip, ilen) { BINTERNAL *bi; BLEAF *bl; - CURSOR *c; RLEAF *rl; + EPGNO *c; PAGE *rval; void *src; indx_t full, half, nxt, off, skip, top, used; - u_int32_t nbytes; + size_t nbytes; int bigkeycnt, isbigkey; /* @@ -707,16 +702,19 @@ bt_psplit(t, h, l, r, pskip, ilen) * cursor is at or past the skipped slot, the cursor is incremented by * one. If the cursor is on the right page, it is decremented by the * number of records split to the left page. + * + * Don't bother checking for the B_SEQINIT flag, the page number will + * be P_INVALID. */ - c = &t->bt_cursor; - if (F_ISSET(c, CURS_INIT) && c->pg.pgno == h->pgno) { - if (c->pg.index >= skip) - ++c->pg.index; - if (c->pg.index < nxt) /* Left page. */ - c->pg.pgno = l->pgno; + c = &t->bt_bcursor; + if (c->pgno == h->pgno) { + if (c->index >= skip) + ++c->index; + if (c->index < nxt) /* Left page. */ + c->pgno = l->pgno; else { /* Right page. */ - c->pg.pgno = r->pgno; - c->pg.index -= nxt; + c->pgno = r->pgno; + c->index -= nxt; } } diff --git a/lib/libc/db/btree/bt_utils.c b/lib/libc/db/btree/bt_utils.c index 9c1438eb8425..d2d1f739e94d 100644 --- a/lib/libc/db/btree/bt_utils.c +++ b/lib/libc/db/btree/bt_utils.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)bt_utils.c 8.8 (Berkeley) 7/20/94"; +static char sccsid[] = "@(#)bt_utils.c 8.4 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -48,91 +48,78 @@ static char sccsid[] = "@(#)bt_utils.c 8.8 (Berkeley) 7/20/94"; #include "btree.h" /* - * __bt_ret -- - * Build return key/data pair. + * __BT_RET -- Build return key/data pair as a result of search or scan. * * Parameters: * t: tree - * e: key/data pair to be returned + * d: LEAF to be returned to the user. * key: user's key structure (NULL if not to be filled in) - * rkey: memory area to hold key - * data: user's data structure (NULL if not to be filled in) - * rdata: memory area to hold data - * copy: always copy the key/data item + * data: user's data structure * * Returns: * RET_SUCCESS, RET_ERROR. */ int -__bt_ret(t, e, key, rkey, data, rdata, copy) +__bt_ret(t, e, key, data) BTREE *t; EPG *e; - DBT *key, *rkey, *data, *rdata; - int copy; + DBT *key, *data; { - BLEAF *bl; - void *p; + register BLEAF *bl; + register void *p; bl = GETBLEAF(e->page, e->index); /* - * We must copy big keys/data to make them contigous. Otherwise, - * leave the page pinned and don't copy unless the user specified + * We always copy big keys/data to make them contigous. Otherwise, + * we leave the page pinned and don't copy unless the user specified * concurrent access. */ - if (key == NULL) - goto dataonly; - - if (bl->flags & P_BIGKEY) { - if (__ovfl_get(t, bl->bytes, - &key->size, &rkey->data, &rkey->size)) + if (bl->flags & P_BIGDATA) { + if (__ovfl_get(t, bl->bytes + bl->ksize, + &data->size, &t->bt_dbuf, &t->bt_dbufsz)) return (RET_ERROR); - key->data = rkey->data; - } else if (copy || F_ISSET(t, B_DB_LOCK)) { - if (bl->ksize > rkey->size) { - p = (void *)(rkey->data == NULL ? - malloc(bl->ksize) : realloc(rkey->data, bl->ksize)); - if (p == NULL) + data->data = t->bt_dbuf; + } else if (ISSET(t, B_DB_LOCK)) { + /* Use +1 in case the first record retrieved is 0 length. */ + if (bl->dsize + 1 > t->bt_dbufsz) { + if ((p = + (void *)realloc(t->bt_dbuf, bl->dsize + 1)) == NULL) return (RET_ERROR); - rkey->data = p; - rkey->size = bl->ksize; + t->bt_dbuf = p; + t->bt_dbufsz = bl->dsize + 1; } - memmove(rkey->data, bl->bytes, bl->ksize); - key->size = bl->ksize; - key->data = rkey->data; + memmove(t->bt_dbuf, bl->bytes + bl->ksize, bl->dsize); + data->size = bl->dsize; + data->data = t->bt_dbuf; } else { - key->size = bl->ksize; - key->data = bl->bytes; + data->size = bl->dsize; + data->data = bl->bytes + bl->ksize; } -dataonly: - if (data == NULL) + if (key == NULL) return (RET_SUCCESS); - if (bl->flags & P_BIGDATA) { - if (__ovfl_get(t, bl->bytes + bl->ksize, - &data->size, &rdata->data, &rdata->size)) + if (bl->flags & P_BIGKEY) { + if (__ovfl_get(t, bl->bytes, + &key->size, &t->bt_kbuf, &t->bt_kbufsz)) return (RET_ERROR); - data->data = rdata->data; - } else if (copy || F_ISSET(t, B_DB_LOCK)) { - /* Use +1 in case the first record retrieved is 0 length. */ - if (bl->dsize + 1 > rdata->size) { - p = (void *)(rdata->data == NULL ? - malloc(bl->dsize + 1) : - realloc(rdata->data, bl->dsize + 1)); - if (p == NULL) + key->data = t->bt_kbuf; + } else if (ISSET(t, B_DB_LOCK)) { + if (bl->ksize > t->bt_kbufsz) { + if ((p = + (void *)realloc(t->bt_kbuf, bl->ksize)) == NULL) return (RET_ERROR); - rdata->data = p; - rdata->size = bl->dsize + 1; + t->bt_kbuf = p; + t->bt_kbufsz = bl->ksize; } - memmove(rdata->data, bl->bytes + bl->ksize, bl->dsize); - data->size = bl->dsize; - data->data = rdata->data; + memmove(t->bt_kbuf, bl->bytes, bl->ksize); + key->size = bl->ksize; + key->data = t->bt_kbuf; } else { - data->size = bl->dsize; - data->data = bl->bytes + bl->ksize; + key->size = bl->ksize; + key->data = bl->bytes; } - return (RET_SUCCESS); } @@ -193,9 +180,9 @@ __bt_cmp(t, k1, e) if (bigkey) { if (__ovfl_get(t, bigkey, - &k2.size, &t->bt_rdata.data, &t->bt_rdata.size)) + &k2.size, &t->bt_dbuf, &t->bt_dbufsz)) return (RET_ERROR); - k2.data = t->bt_rdata.data; + k2.data = t->bt_dbuf; } return ((*t->bt_cmp)(k1, &k2)); } diff --git a/lib/libc/db/btree/btree.h b/lib/libc/db/btree/btree.h index 36d35c998bfd..dd798ecc3919 100644 --- a/lib/libc/db/btree/btree.h +++ b/lib/libc/db/btree/btree.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -33,14 +33,9 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)btree.h 8.11 (Berkeley) 8/17/94 + * @(#)btree.h 8.5 (Berkeley) 2/21/94 */ -/* Macros to set/clear/test flags. */ -#define F_SET(p, f) (p)->flags |= (f) -#define F_CLR(p, f) (p)->flags &= ~(f) -#define F_ISSET(p, f) ((p)->flags & (f)) - #include <mpool.h> #define DEFMINKEYPAGE (2) /* Minimum keys per page */ @@ -84,9 +79,8 @@ typedef struct _page { } PAGE; /* First and next index. */ -#define BTDATAOFF \ - (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \ - sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t)) +#define BTDATAOFF (sizeof(pgno_t) + sizeof(pgno_t) + sizeof(pgno_t) + \ + sizeof(u_int32_t) + sizeof(indx_t) + sizeof(indx_t)) #define NEXTINDEX(p) (((p)->lower - BTDATAOFF) / sizeof(indx_t)) /* @@ -105,8 +99,9 @@ typedef struct _page { * be manipulated without copying. (This presumes that 32 bit items can be * manipulated on this system.) */ -#define LALIGN(n) (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1)) -#define NOVFLSIZE (sizeof(pgno_t) + sizeof(u_int32_t)) +#define LALIGN(n) \ + (((n) + sizeof(pgno_t) - 1) & ~(sizeof(pgno_t) - 1)) +#define NOVFLSIZE (sizeof(pgno_t) + sizeof(size_t)) /* * For the btree internal pages, the item is a key. BINTERNALs are {key, pgno} @@ -118,7 +113,7 @@ typedef struct _page { * some minor modifications of the above rule. */ typedef struct _binternal { - u_int32_t ksize; /* key size */ + size_t ksize; /* key size */ pgno_t pgno; /* page number stored on */ #define P_BIGDATA 0x01 /* overflow data */ #define P_BIGKEY 0x02 /* overflow key */ @@ -127,21 +122,21 @@ typedef struct _binternal { } BINTERNAL; /* Get the page's BINTERNAL structure at index indx. */ -#define GETBINTERNAL(pg, indx) \ +#define GETBINTERNAL(pg, indx) \ ((BINTERNAL *)((char *)(pg) + (pg)->linp[indx])) /* Get the number of bytes in the entry. */ -#define NBINTERNAL(len) \ - LALIGN(sizeof(u_int32_t) + sizeof(pgno_t) + sizeof(u_char) + (len)) +#define NBINTERNAL(len) \ + LALIGN(sizeof(size_t) + sizeof(pgno_t) + sizeof(u_char) + (len)) /* Copy a BINTERNAL entry to the page. */ -#define WR_BINTERNAL(p, size, pgno, flags) { \ - *(u_int32_t *)p = size; \ - p += sizeof(u_int32_t); \ - *(pgno_t *)p = pgno; \ - p += sizeof(pgno_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ +#define WR_BINTERNAL(p, size, pgno, flags) { \ + *(size_t *)p = size; \ + p += sizeof(size_t); \ + *(pgno_t *)p = pgno; \ + p += sizeof(pgno_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ } /* @@ -154,78 +149,78 @@ typedef struct _rinternal { } RINTERNAL; /* Get the page's RINTERNAL structure at index indx. */ -#define GETRINTERNAL(pg, indx) \ +#define GETRINTERNAL(pg, indx) \ ((RINTERNAL *)((char *)(pg) + (pg)->linp[indx])) /* Get the number of bytes in the entry. */ -#define NRINTERNAL \ +#define NRINTERNAL \ LALIGN(sizeof(recno_t) + sizeof(pgno_t)) /* Copy a RINTERAL entry to the page. */ -#define WR_RINTERNAL(p, nrecs, pgno) { \ - *(recno_t *)p = nrecs; \ - p += sizeof(recno_t); \ - *(pgno_t *)p = pgno; \ +#define WR_RINTERNAL(p, nrecs, pgno) { \ + *(recno_t *)p = nrecs; \ + p += sizeof(recno_t); \ + *(pgno_t *)p = pgno; \ } /* For the btree leaf pages, the item is a key and data pair. */ typedef struct _bleaf { - u_int32_t ksize; /* size of key */ - u_int32_t dsize; /* size of data */ + size_t ksize; /* size of key */ + size_t dsize; /* size of data */ u_char flags; /* P_BIGDATA, P_BIGKEY */ char bytes[1]; /* data */ } BLEAF; /* Get the page's BLEAF structure at index indx. */ -#define GETBLEAF(pg, indx) \ +#define GETBLEAF(pg, indx) \ ((BLEAF *)((char *)(pg) + (pg)->linp[indx])) /* Get the number of bytes in the entry. */ #define NBLEAF(p) NBLEAFDBT((p)->ksize, (p)->dsize) /* Get the number of bytes in the user's key/data pair. */ -#define NBLEAFDBT(ksize, dsize) \ - LALIGN(sizeof(u_int32_t) + sizeof(u_int32_t) + sizeof(u_char) + \ +#define NBLEAFDBT(ksize, dsize) \ + LALIGN(sizeof(size_t) + sizeof(size_t) + sizeof(u_char) + \ (ksize) + (dsize)) /* Copy a BLEAF entry to the page. */ -#define WR_BLEAF(p, key, data, flags) { \ - *(u_int32_t *)p = key->size; \ - p += sizeof(u_int32_t); \ - *(u_int32_t *)p = data->size; \ - p += sizeof(u_int32_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ - memmove(p, key->data, key->size); \ - p += key->size; \ - memmove(p, data->data, data->size); \ +#define WR_BLEAF(p, key, data, flags) { \ + *(size_t *)p = key->size; \ + p += sizeof(size_t); \ + *(size_t *)p = data->size; \ + p += sizeof(size_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ + memmove(p, key->data, key->size); \ + p += key->size; \ + memmove(p, data->data, data->size); \ } /* For the recno leaf pages, the item is a data entry. */ typedef struct _rleaf { - u_int32_t dsize; /* size of data */ + size_t dsize; /* size of data */ u_char flags; /* P_BIGDATA */ char bytes[1]; } RLEAF; /* Get the page's RLEAF structure at index indx. */ -#define GETRLEAF(pg, indx) \ +#define GETRLEAF(pg, indx) \ ((RLEAF *)((char *)(pg) + (pg)->linp[indx])) /* Get the number of bytes in the entry. */ #define NRLEAF(p) NRLEAFDBT((p)->dsize) /* Get the number of bytes from the user's data. */ -#define NRLEAFDBT(dsize) \ - LALIGN(sizeof(u_int32_t) + sizeof(u_char) + (dsize)) +#define NRLEAFDBT(dsize) \ + LALIGN(sizeof(size_t) + sizeof(u_char) + (dsize)) /* Copy a RLEAF entry to the page. */ -#define WR_RLEAF(p, data, flags) { \ - *(u_int32_t *)p = data->size; \ - p += sizeof(u_int32_t); \ - *(u_char *)p = flags; \ - p += sizeof(u_char); \ - memmove(p, data->data, data->size); \ +#define WR_RLEAF(p, data, flags) { \ + *(size_t *)p = data->size; \ + p += sizeof(size_t); \ + *(u_char *)p = flags; \ + p += sizeof(u_char); \ + memmove(p, data->data, data->size); \ } /* @@ -237,6 +232,12 @@ typedef struct _rleaf { * record less than key in the tree so that descents work. Leaf page searches * must find the smallest record greater than key so that the returned index * is the record's correct position for insertion. + * + * One comment about cursors. The cursor key is never removed from the tree, + * even if deleted. This is because it is quite difficult to decide where the + * cursor should be when other keys have been inserted/deleted in the tree; + * duplicate keys make it impossible. This scheme does require extra work + * though, to make sure that we don't perform an operation on a deleted key. */ typedef struct _epgno { pgno_t pgno; /* the page number */ @@ -249,90 +250,53 @@ typedef struct _epg { } EPG; /* - * About cursors. The cursor (and the page that contained the key/data pair - * that it referenced) can be deleted, which makes things a bit tricky. If - * there are no duplicates of the cursor key in the tree (i.e. B_NODUPS is set - * or there simply aren't any duplicates of the key) we copy the key that it - * referenced when it's deleted, and reacquire a new cursor key if the cursor - * is used again. If there are duplicates keys, we move to the next/previous - * key, and set a flag so that we know what happened. NOTE: if duplicate (to - * the cursor) keys are added to the tree during this process, it is undefined - * if they will be returned or not in a cursor scan. - * - * The flags determine the possible states of the cursor: - * - * CURS_INIT The cursor references *something*. - * CURS_ACQUIRE The cursor was deleted, and a key has been saved so that - * we can reacquire the right position in the tree. - * CURS_AFTER, CURS_BEFORE - * The cursor was deleted, and now references a key/data pair - * that has not yet been returned, either before or after the - * deleted key/data pair. - * XXX - * This structure is broken out so that we can eventually offer multiple - * cursors as part of the DB interface. - */ -typedef struct _cursor { - EPGNO pg; /* B: Saved tree reference. */ - DBT key; /* B: Saved key, or key.data == NULL. */ - recno_t rcursor; /* R: recno cursor (1-based) */ - -#define CURS_ACQUIRE 0x01 /* B: Cursor needs to be reacquired. */ -#define CURS_AFTER 0x02 /* B: Unreturned cursor after key. */ -#define CURS_BEFORE 0x04 /* B: Unreturned cursor before key. */ -#define CURS_INIT 0x08 /* RB: Cursor initialized. */ - u_int8_t flags; -} CURSOR; - -/* - * The metadata of the tree. The nrecs field is used only by the RECNO code. + * The metadata of the tree. The m_nrecs field is used only by the RECNO code. * This is because the btree doesn't really need it and it requires that every * put or delete call modify the metadata. */ typedef struct _btmeta { - u_int32_t magic; /* magic number */ - u_int32_t version; /* version */ - u_int32_t psize; /* page size */ - u_int32_t free; /* page number of first free page */ - u_int32_t nrecs; /* R: number of records */ - + u_int32_t m_magic; /* magic number */ + u_int32_t m_version; /* version */ + u_int32_t m_psize; /* page size */ + u_int32_t m_free; /* page number of first free page */ + u_int32_t m_nrecs; /* R: number of records */ #define SAVEMETA (B_NODUPS | R_RECNO) - u_int32_t flags; /* bt_flags & SAVEMETA */ + u_int32_t m_flags; /* bt_flags & SAVEMETA */ + u_int32_t m_unused; /* unused */ } BTMETA; /* The in-memory btree/recno data structure. */ typedef struct _btree { - MPOOL *bt_mp; /* memory pool cookie */ + MPOOL *bt_mp; /* memory pool cookie */ - DB *bt_dbp; /* pointer to enclosing DB */ + DB *bt_dbp; /* pointer to enclosing DB */ - EPG bt_cur; /* current (pinned) page */ - PAGE *bt_pinned; /* page pinned across calls */ + EPG bt_cur; /* current (pinned) page */ + PAGE *bt_pinned; /* page pinned across calls */ - CURSOR bt_cursor; /* cursor */ + EPGNO bt_bcursor; /* B: btree cursor */ + recno_t bt_rcursor; /* R: recno cursor (1-based) */ -#define BT_PUSH(t, p, i) { \ - t->bt_sp->pgno = p; \ - t->bt_sp->index = i; \ - ++t->bt_sp; \ -} -#define BT_POP(t) (t->bt_sp == t->bt_stack ? NULL : --t->bt_sp) -#define BT_CLR(t) (t->bt_sp = t->bt_stack) - EPGNO bt_stack[50]; /* stack of parent pages */ - EPGNO *bt_sp; /* current stack pointer */ +#define BT_POP(t) (t->bt_sp ? t->bt_stack + --t->bt_sp : NULL) +#define BT_CLR(t) (t->bt_sp = 0) + EPGNO *bt_stack; /* stack of parent pages */ + u_int bt_sp; /* current stack pointer */ + u_int bt_maxstack; /* largest stack */ - DBT bt_rkey; /* returned key */ - DBT bt_rdata; /* returned data */ + char *bt_kbuf; /* key buffer */ + size_t bt_kbufsz; /* key buffer size */ + char *bt_dbuf; /* data buffer */ + size_t bt_dbufsz; /* data buffer size */ - int bt_fd; /* tree file descriptor */ + int bt_fd; /* tree file descriptor */ - pgno_t bt_free; /* next free page */ + pgno_t bt_free; /* next free page */ u_int32_t bt_psize; /* page size */ - indx_t bt_ovflsize; /* cut-off for key/data overflow */ - int bt_lorder; /* byte order */ + indx_t bt_ovflsize; /* cut-off for key/data overflow */ + int bt_lorder; /* byte order */ /* sorted order */ enum { NOT, BACK, FORWARD } bt_order; - EPGNO bt_last; /* last insert */ + EPGNO bt_last; /* last insert */ /* B: key comparison function */ int (*bt_cmp) __P((const DBT *, const DBT *)); @@ -341,43 +305,49 @@ typedef struct _btree { /* R: recno input function */ int (*bt_irec) __P((struct _btree *, recno_t)); - FILE *bt_rfp; /* R: record FILE pointer */ - int bt_rfd; /* R: record file descriptor */ + FILE *bt_rfp; /* R: record FILE pointer */ + int bt_rfd; /* R: record file descriptor */ - caddr_t bt_cmap; /* R: current point in mapped space */ - caddr_t bt_smap; /* R: start of mapped space */ - caddr_t bt_emap; /* R: end of mapped space */ - size_t bt_msize; /* R: size of mapped region. */ + caddr_t bt_cmap; /* R: current point in mapped space */ + caddr_t bt_smap; /* R: start of mapped space */ + caddr_t bt_emap; /* R: end of mapped space */ + size_t bt_msize; /* R: size of mapped region. */ - recno_t bt_nrecs; /* R: number of records */ - size_t bt_reclen; /* R: fixed record length */ - u_char bt_bval; /* R: delimiting byte/pad character */ + recno_t bt_nrecs; /* R: number of records */ + size_t bt_reclen; /* R: fixed record length */ + u_char bt_bval; /* R: delimiting byte/pad character */ /* * NB: * B_NODUPS and R_RECNO are stored on disk, and may not be changed. */ -#define B_INMEM 0x00001 /* in-memory tree */ -#define B_METADIRTY 0x00002 /* need to write metadata */ -#define B_MODIFIED 0x00004 /* tree modified */ -#define B_NEEDSWAP 0x00008 /* if byte order requires swapping */ -#define B_RDONLY 0x00010 /* read-only tree */ - +#define B_DELCRSR 0x00001 /* cursor has been deleted */ +#define B_INMEM 0x00002 /* in-memory tree */ +#define B_METADIRTY 0x00004 /* need to write metadata */ +#define B_MODIFIED 0x00008 /* tree modified */ +#define B_NEEDSWAP 0x00010 /* if byte order requires swapping */ #define B_NODUPS 0x00020 /* no duplicate keys permitted */ +#define B_RDONLY 0x00040 /* read-only tree */ #define R_RECNO 0x00080 /* record oriented tree */ +#define B_SEQINIT 0x00100 /* sequential scan initialized */ -#define R_CLOSEFP 0x00040 /* opened a file pointer */ -#define R_EOF 0x00100 /* end of input file reached. */ -#define R_FIXLEN 0x00200 /* fixed length records */ -#define R_MEMMAPPED 0x00400 /* memory mapped file. */ -#define R_INMEM 0x00800 /* in-memory file */ -#define R_MODIFIED 0x01000 /* modified file */ -#define R_RDONLY 0x02000 /* read-only file */ - -#define B_DB_LOCK 0x04000 /* DB_LOCK specified. */ -#define B_DB_SHMEM 0x08000 /* DB_SHMEM specified. */ -#define B_DB_TXN 0x10000 /* DB_TXN specified. */ - u_int32_t flags; +#define R_CLOSEFP 0x00200 /* opened a file pointer */ +#define R_EOF 0x00400 /* end of input file reached. */ +#define R_FIXLEN 0x00800 /* fixed length records */ +#define R_MEMMAPPED 0x01000 /* memory mapped file. */ +#define R_INMEM 0x02000 /* in-memory file */ +#define R_MODIFIED 0x04000 /* modified file */ +#define R_RDONLY 0x08000 /* read-only file */ + +#define B_DB_LOCK 0x10000 /* DB_LOCK specified. */ +#define B_DB_SHMEM 0x20000 /* DB_SHMEM specified. */ +#define B_DB_TXN 0x40000 /* DB_TXN specified. */ + + u_int32_t bt_flags; /* btree state */ } BTREE; +#define SET(t, f) ((t)->bt_flags |= (f)) +#define CLR(t, f) ((t)->bt_flags &= ~(f)) +#define ISSET(t, f) ((t)->bt_flags & (f)) + #include "extern.h" diff --git a/lib/libc/db/btree/extern.h b/lib/libc/db/btree/extern.h index ebd9c5492308..4007bc708500 100644 --- a/lib/libc/db/btree/extern.h +++ b/lib/libc/db/btree/extern.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.10 (Berkeley) 7/20/94 + * @(#)extern.h 8.3 (Berkeley) 2/21/94 */ int __bt_close __P((DB *)); @@ -39,8 +39,9 @@ int __bt_crsrdel __P((BTREE *, EPGNO *)); int __bt_defcmp __P((const DBT *, const DBT *)); size_t __bt_defpfx __P((const DBT *, const DBT *)); int __bt_delete __P((const DB *, const DBT *, u_int)); -int __bt_dleaf __P((BTREE *, const DBT *, PAGE *, u_int)); +int __bt_dleaf __P((BTREE *, PAGE *, int)); int __bt_fd __P((const DB *)); +EPG *__bt_first __P((BTREE *, const DBT *, int *)); int __bt_free __P((BTREE *, PAGE *)); int __bt_get __P((const DB *, const DBT *, DBT *, u_int)); PAGE *__bt_new __P((BTREE *, pgno_t *)); @@ -48,16 +49,15 @@ void __bt_pgin __P((void *, pgno_t, void *)); void __bt_pgout __P((void *, pgno_t, void *)); int __bt_push __P((BTREE *, pgno_t, int)); int __bt_put __P((const DB *dbp, DBT *, const DBT *, u_int)); -int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *, DBT *, DBT *, int)); +int __bt_ret __P((BTREE *, EPG *, DBT *, DBT *)); EPG *__bt_search __P((BTREE *, const DBT *, int *)); int __bt_seq __P((const DB *, DBT *, DBT *, u_int)); -void __bt_setcur __P((BTREE *, pgno_t, u_int)); int __bt_split __P((BTREE *, PAGE *, - const DBT *, const DBT *, int, size_t, u_int32_t)); + const DBT *, const DBT *, int, size_t, indx_t)); int __bt_sync __P((const DB *, u_int)); int __ovfl_delete __P((BTREE *, void *)); -int __ovfl_get __P((BTREE *, void *, size_t *, void **, size_t *)); +int __ovfl_get __P((BTREE *, void *, size_t *, char **, size_t *)); int __ovfl_put __P((BTREE *, const DBT *, pgno_t *)); #ifdef DEBUG diff --git a/lib/libc/db/doc/hash.usenix.ps b/lib/libc/db/doc/hash.usenix.ps index c884778830d2..03a01cbf0e90 100644 --- a/lib/libc/db/doc/hash.usenix.ps +++ b/lib/libc/db/doc/hash.usenix.ps @@ -7,7 +7,7 @@ % lib/psdit.pro -- prolog for psdit (ditroff) files % Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved. % last edit: shore Sat Nov 23 20:28:03 1985 -% RCSID: $Header: psdit.pro,v 2.1 85/11/24 12:19:43 shore Rel $ +% RCSID: $Header: /pub/FreeBSD/FreeBSD-CVS/src/lib/libc/db/doc/Attic/hash.usenix.ps,v 1.2 1994/08/05 01:17:43 wollman Exp $ % Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics, % 17 Feb, 87. diff --git a/lib/libc/db/doc/libtp.usenix.ps b/lib/libc/db/doc/libtp.usenix.ps index ea821a9145e2..ebe73cdfc102 100644 --- a/lib/libc/db/doc/libtp.usenix.ps +++ b/lib/libc/db/doc/libtp.usenix.ps @@ -7,7 +7,7 @@ % lib/psdit.pro -- prolog for psdit (ditroff) files % Copyright (c) 1984, 1985 Adobe Systems Incorporated. All Rights Reserved. % last edit: shore Sat Nov 23 20:28:03 1985 -% RCSID: $Header: psdit.pro,v 2.1 85/11/24 12:19:43 shore Rel $ +% RCSID: $Header: /pub/FreeBSD/FreeBSD-CVS/src/lib/libc/db/doc/Attic/libtp.usenix.ps,v 1.2 1994/08/05 01:17:46 wollman Exp $ % Changed by Edward Wang (edward@ucbarpa.berkeley.edu) to handle graphics, % 17 Feb, 87. diff --git a/lib/libc/db/hash/extern.h b/lib/libc/db/hash/extern.h index 3167e6d0f754..b7ef37ada29a 100644 --- a/lib/libc/db/hash/extern.h +++ b/lib/libc/db/hash/extern.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -30,7 +30,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.4 (Berkeley) 6/16/94 + * @(#)extern.h 8.2 (Berkeley) 2/21/94 */ BUFHEAD *__add_ovflpage __P((HTAB *, BUFHEAD *)); @@ -40,26 +40,26 @@ int __big_insert __P((HTAB *, BUFHEAD *, const DBT *, const DBT *)); int __big_keydata __P((HTAB *, BUFHEAD *, DBT *, DBT *, int)); int __big_return __P((HTAB *, BUFHEAD *, int, DBT *, int)); int __big_split __P((HTAB *, BUFHEAD *, BUFHEAD *, BUFHEAD *, - int, u_int32_t, SPLIT_RETURN *)); + int, u_int, SPLIT_RETURN *)); int __buf_free __P((HTAB *, int, int)); void __buf_init __P((HTAB *, int)); -u_int32_t __call_hash __P((HTAB *, char *, int)); +u_int __call_hash __P((HTAB *, char *, int)); int __delpair __P((HTAB *, BUFHEAD *, int)); int __expand_table __P((HTAB *)); int __find_bigpair __P((HTAB *, BUFHEAD *, int, char *, int)); -u_int16_t __find_last_page __P((HTAB *, BUFHEAD **)); +u_short __find_last_page __P((HTAB *, BUFHEAD **)); void __free_ovflpage __P((HTAB *, BUFHEAD *)); -BUFHEAD *__get_buf __P((HTAB *, u_int32_t, BUFHEAD *, int)); -int __get_page __P((HTAB *, char *, u_int32_t, int, int, int)); -int __ibitmap __P((HTAB *, int, int, int)); -u_int32_t __log2 __P((u_int32_t)); -int __put_page __P((HTAB *, char *, u_int32_t, int, int)); +BUFHEAD *__get_buf __P((HTAB *, u_int, BUFHEAD *, int)); +int __get_page __P((HTAB *, char *, u_int, int, int, int)); +int __init_bitmap __P((HTAB *, int, int, int)); +u_int __log2 __P((u_int)); +int __put_page __P((HTAB *, char *, u_int, int, int)); void __reclaim_buf __P((HTAB *, BUFHEAD *)); -int __split_page __P((HTAB *, u_int32_t, u_int32_t)); +int __split_page __P((HTAB *, u_int, u_int)); /* Default hash routine. */ extern u_int32_t (*__default_hash) __P((const void *, size_t)); #ifdef HASH_STATISTICS -extern int hash_accesses, hash_collisions, hash_expansions, hash_overflows; +extern long hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c index 68176e404ff4..6a23f3d801cb 100644 --- a/lib/libc/db/hash/hash.c +++ b/lib/libc/db/hash/hash.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash.c 8.9 (Berkeley) 6/16/94"; +static char sccsid[] = "@(#)hash.c 8.7 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -60,13 +60,13 @@ static int alloc_segs __P((HTAB *, int)); static int flush_meta __P((HTAB *)); static int hash_access __P((HTAB *, ACTION, DBT *, DBT *)); static int hash_close __P((DB *)); -static int hash_delete __P((const DB *, const DBT *, u_int32_t)); +static int hash_delete __P((const DB *, const DBT *, u_int)); static int hash_fd __P((const DB *)); -static int hash_get __P((const DB *, const DBT *, DBT *, u_int32_t)); -static int hash_put __P((const DB *, DBT *, const DBT *, u_int32_t)); +static int hash_get __P((const DB *, const DBT *, DBT *, u_int)); +static int hash_put __P((const DB *, DBT *, const DBT *, u_int)); static void *hash_realloc __P((SEGMENT **, int, int)); -static int hash_seq __P((const DB *, DBT *, DBT *, u_int32_t)); -static int hash_sync __P((const DB *, u_int32_t)); +static int hash_seq __P((const DB *, DBT *, DBT *, u_int)); +static int hash_sync __P((const DB *, u_int)); static int hdestroy __P((HTAB *)); static HTAB *init_hash __P((HTAB *, const char *, HASHINFO *)); static int init_htab __P((HTAB *, int)); @@ -86,7 +86,7 @@ static void swap_header_copy __P((HASHHDR *, HASHHDR *)); #define ABNORMAL (1) #ifdef HASH_STATISTICS -int hash_accesses, hash_collisions, hash_expansions, hash_overflows; +long hash_accesses, hash_collisions, hash_expansions, hash_overflows; #endif /************************** INTERFACE ROUTINES ***************************/ @@ -130,13 +130,6 @@ __hash_open(file, flags, mode, info, dflags) if (file) { if ((hashp->fp = open(file, flags, mode)) == -1) RETURN_ERROR(errno, error0); - - /* if the .db file is empty, and we had permission to create - a new .db file, then reinitialize the database */ - if ((flags & O_CREAT) && - fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0) - new_table = 1; - (void)fcntl(hashp->fp, F_SETFD, 1); } if (new_table) { @@ -186,7 +179,7 @@ __hash_open(file, flags, mode, info, dflags) (hashp->BSHIFT + BYTE_SHIFT); hashp->nmaps = bpages; - (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_int32_t *)); + (void)memset(&hashp->mapp[0], 0, bpages * sizeof(u_long *)); } /* Initialize Buffer Manager */ @@ -373,7 +366,7 @@ init_htab(hashp, nelem) hashp->LAST_FREED = 2; /* First bitmap page is at: splitpoint l2 page offset 1 */ - if (__ibitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) + if (__init_bitmap(hashp, OADDR_OF(l2, 1), l2 + 1, 0)) return (-1); hashp->MAX_BUCKET = hashp->LOW_MASK = nbuckets - 1; @@ -458,7 +451,7 @@ hdestroy(hashp) static int hash_sync(dbp, flags) const DB *dbp; - u_int32_t flags; + u_int flags; { HTAB *hashp; @@ -512,7 +505,7 @@ flush_meta(hashp) else if (wsize != sizeof(HASHHDR)) { errno = EFTYPE; - hashp->error = errno; + hashp->errno = errno; return (-1); } for (i = 0; i < NCACHED; i++) @@ -537,13 +530,13 @@ hash_get(dbp, key, data, flag) const DB *dbp; const DBT *key; DBT *data; - u_int32_t flag; + u_int flag; { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag) { - hashp->error = errno = EINVAL; + hashp->errno = errno = EINVAL; return (ERROR); } return (hash_access(hashp, HASH_GET, (DBT *)key, data)); @@ -554,17 +547,17 @@ hash_put(dbp, key, data, flag) const DB *dbp; DBT *key; const DBT *data; - u_int32_t flag; + u_int flag; { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag && flag != R_NOOVERWRITE) { - hashp->error = errno = EINVAL; + hashp->errno = errno = EINVAL; return (ERROR); } if ((hashp->flags & O_ACCMODE) == O_RDONLY) { - hashp->error = errno = EPERM; + hashp->errno = errno = EPERM; return (ERROR); } return (hash_access(hashp, flag == R_NOOVERWRITE ? @@ -575,17 +568,17 @@ static int hash_delete(dbp, key, flag) const DB *dbp; const DBT *key; - u_int32_t flag; /* Ignored */ + u_int flag; /* Ignored */ { HTAB *hashp; hashp = (HTAB *)dbp->internal; if (flag && flag != R_CURSOR) { - hashp->error = errno = EINVAL; + hashp->errno = errno = EINVAL; return (ERROR); } if ((hashp->flags & O_ACCMODE) == O_RDONLY) { - hashp->error = errno = EPERM; + hashp->errno = errno = EPERM; return (ERROR); } return (hash_access(hashp, HASH_DELETE, (DBT *)key, NULL)); @@ -602,10 +595,10 @@ hash_access(hashp, action, key, val) { register BUFHEAD *rbufp; BUFHEAD *bufp, *save_bufp; - register u_int16_t *bp; + register u_short *bp; register int n, ndx, off, size; register char *kp; - u_int16_t pageno; + u_short pageno; #ifdef HASH_STATISTICS hash_accesses++; @@ -621,7 +614,7 @@ hash_access(hashp, action, key, val) /* Pin the bucket chain */ rbufp->flags |= BUF_PIN; - for (bp = (u_int16_t *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) + for (bp = (u_short *)rbufp->page, n = *bp++, ndx = 1; ndx < n;) if (bp[1] >= REAL_KEY) { /* Real key/data pair */ if (size == off - *bp && @@ -640,7 +633,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_int16_t *)rbufp->page; + bp = (u_short *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -662,7 +655,7 @@ hash_access(hashp, action, key, val) return (ERROR); } /* FOR LOOP INIT */ - bp = (u_int16_t *)rbufp->page; + bp = (u_short *)rbufp->page; n = *bp++; ndx = 1; off = hashp->BSIZE; @@ -696,7 +689,7 @@ found: save_bufp->flags &= ~BUF_PIN; return (ABNORMAL); case HASH_GET: - bp = (u_int16_t *)rbufp->page; + bp = (u_short *)rbufp->page; if (bp[ndx + 1] < REAL_KEY) { if (__big_return(hashp, rbufp, ndx, val, 0)) return (ERROR); @@ -727,16 +720,16 @@ static int hash_seq(dbp, key, data, flag) const DB *dbp; DBT *key, *data; - u_int32_t flag; + u_int flag; { - register u_int32_t bucket; + register u_int bucket; register BUFHEAD *bufp; HTAB *hashp; - u_int16_t *bp, ndx; + u_short *bp, ndx; hashp = (HTAB *)dbp->internal; if (flag && flag != R_FIRST && flag != R_NEXT) { - hashp->error = errno = EINVAL; + hashp->errno = errno = EINVAL; return (ERROR); } #ifdef HASH_STATISTICS @@ -757,7 +750,7 @@ hash_seq(dbp, key, data, flag) if (!bufp) return (ERROR); hashp->cpage = bufp; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; if (bp[0]) break; } @@ -767,7 +760,7 @@ hash_seq(dbp, key, data, flag) return (ABNORMAL); } } else - bp = (u_int16_t *)hashp->cpage->page; + bp = (u_short *)hashp->cpage->page; #ifdef DEBUG assert(bp); @@ -778,7 +771,7 @@ hash_seq(dbp, key, data, flag) __get_buf(hashp, bp[hashp->cndx], bufp, 0); if (!bufp) return (ERROR); - bp = (u_int16_t *)(bufp->page); + bp = (u_short *)(bufp->page); hashp->cndx = 1; } if (!bp[0]) { @@ -817,7 +810,7 @@ extern int __expand_table(hashp) HTAB *hashp; { - u_int32_t old_bucket, new_bucket; + u_int old_bucket, new_bucket; int dirsize, new_segnum, spare_ndx; #ifdef HASH_STATISTICS @@ -884,7 +877,7 @@ hash_realloc(p_ptr, oldsize, newsize) return (p); } -extern u_int32_t +extern u_int __call_hash(hashp, k, len) HTAB *hashp; char *k; diff --git a/lib/libc/db/hash/hash.h b/lib/libc/db/hash/hash.h index 504a9b603e52..1c80f83c69d5 100644 --- a/lib/libc/db/hash/hash.h +++ b/lib/libc/db/hash/hash.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)hash.h 8.3 (Berkeley) 5/31/94 + * @(#)hash.h 8.2 (Berkeley) 2/21/94 */ /* Operations */ @@ -45,12 +45,12 @@ typedef enum { typedef struct _bufhead BUFHEAD; struct _bufhead { - BUFHEAD *prev; /* LRU links */ - BUFHEAD *next; /* LRU links */ - BUFHEAD *ovfl; /* Overflow page buffer header */ - u_int32_t addr; /* Address of this page */ - char *page; /* Actual page data */ - char flags; + BUFHEAD *prev; /* LRU links */ + BUFHEAD *next; /* LRU links */ + BUFHEAD *ovfl; /* Overflow page buffer header */ + u_int addr; /* Address of this page */ + char *page; /* Actual page data */ + char flags; #define BUF_MOD 0x0001 #define BUF_DISK 0x0002 #define BUF_BUCKET 0x0004 @@ -62,60 +62,51 @@ struct _bufhead { typedef BUFHEAD **SEGMENT; /* Hash Table Information */ -typedef struct hashhdr { /* Disk resident portion */ - int magic; /* Magic NO for hash tables */ - int version; /* Version ID */ - u_int32_t lorder; /* Byte Order */ - int bsize; /* Bucket/Page Size */ - int bshift; /* Bucket shift */ - int dsize; /* Directory Size */ - int ssize; /* Segment Size */ - int sshift; /* Segment shift */ - int ovfl_point; /* Where overflow pages are being - * allocated */ - int last_freed; /* Last overflow page freed */ - int max_bucket; /* ID of Maximum bucket in use */ - int high_mask; /* Mask to modulo into entire table */ - int low_mask; /* Mask to modulo into lower half of - * table */ - int ffactor; /* Fill factor */ - int nkeys; /* Number of keys in hash table */ - int hdrpages; /* Size of table header */ - int h_charkey; /* value of hash(CHARKEY) */ -#define NCACHED 32 /* number of bit maps and spare - * points */ - int spares[NCACHED];/* spare pages for overflow */ - u_int16_t bitmaps[NCACHED]; /* address of overflow page - * bitmaps */ +typedef struct hashhdr { /* Disk resident portion */ + int magic; /* Magic NO for hash tables */ + int version; /* Version ID */ + long lorder; /* Byte Order */ + int bsize; /* Bucket/Page Size */ + int bshift; /* Bucket shift */ + int dsize; /* Directory Size */ + int ssize; /* Segment Size */ + int sshift; /* Segment shift */ + int ovfl_point; /* Where overflow pages are being allocated */ + int last_freed; /* Last overflow page freed */ + int max_bucket; /* ID of Maximum bucket in use */ + int high_mask; /* Mask to modulo into entire table */ + int low_mask; /* Mask to modulo into lower half of table */ + int ffactor; /* Fill factor */ + int nkeys; /* Number of keys in hash table */ + int hdrpages; /* Size of table header */ + int h_charkey; /* value of hash(CHARKEY) */ +#define NCACHED 32 /* number of bit maps and spare points */ + int spares[NCACHED];/* spare pages for overflow */ + u_short bitmaps[NCACHED]; /* address of overflow page bitmaps */ } HASHHDR; -typedef struct htab { /* Memory resident data structure */ - HASHHDR hdr; /* Header */ - int nsegs; /* Number of allocated segments */ - int exsegs; /* Number of extra allocated - * segments */ - u_int32_t /* Hash function */ +typedef struct htab { /* Memory resident data structure */ + HASHHDR hdr; /* Header */ + int nsegs; /* Number of allocated segments */ + int exsegs; /* Number of extra allocated segments */ + u_int32_t /* Hash function */ (*hash)__P((const void *, size_t)); - int flags; /* Flag values */ - int fp; /* File pointer */ - char *tmp_buf; /* Temporary Buffer for BIG data */ - char *tmp_key; /* Temporary Buffer for BIG keys */ - BUFHEAD *cpage; /* Current page */ - int cbucket; /* Current bucket */ - int cndx; /* Index of next item on cpage */ - int error; /* Error Number -- for DBM - * compatability */ - int new_file; /* Indicates if fd is backing store - * or no */ - int save_file; /* Indicates whether we need to flush - * file at - * exit */ - u_int32_t *mapp[NCACHED]; /* Pointers to page maps */ - int nmaps; /* Initial number of bitmaps */ - int nbufs; /* Number of buffers left to - * allocate */ - BUFHEAD bufhead; /* Header of buffer lru list */ - SEGMENT *dir; /* Hash Bucket directory */ + int flags; /* Flag values */ + int fp; /* File pointer */ + char *tmp_buf; /* Temporary Buffer for BIG data */ + char *tmp_key; /* Temporary Buffer for BIG keys */ + BUFHEAD *cpage; /* Current page */ + int cbucket; /* Current bucket */ + int cndx; /* Index of next item on cpage */ + int errno; /* Error Number -- for DBM compatability */ + int new_file; /* Indicates if fd is backing store or no */ + int save_file; /* Indicates whether we need to flush file at + * exit */ + u_long *mapp[NCACHED]; /* Pointers to page maps */ + int nmaps; /* Initial number of bitmaps */ + int nbufs; /* Number of buffers left to allocate */ + BUFHEAD bufhead; /* Header of buffer lru list */ + SEGMENT *dir; /* Hash Bucket directory */ } HTAB; /* @@ -138,14 +129,14 @@ typedef struct htab { /* Memory resident data structure */ #define BYTE_SHIFT 3 #define INT_TO_BYTE 2 #define INT_BYTE_SHIFT 5 -#define ALL_SET ((u_int32_t)0xFFFFFFFF) +#define ALL_SET ((u_int)0xFFFFFFFF) #define ALL_CLEAR 0 -#define PTROF(X) ((BUFHEAD *)((ptrdiff_t)(X)&~0x3)) -#define ISMOD(X) ((u_int32_t)(ptrdiff_t)(X)&0x1) -#define DOMOD(X) ((X) = (char *)((ptrdiff_t)(X)|0x1)) -#define ISDISK(X) ((u_int32_t)(ptrdiff_t)(X)&0x2) -#define DODISK(X) ((X) = (char *)((ptrdiff_t)(X)|0x2)) +#define PTROF(X) ((BUFHEAD *)((u_int)(X)&~0x3)) +#define ISMOD(X) ((u_int)(X)&0x1) +#define DOMOD(X) ((X) = (char *)((u_int)(X)|0x1)) +#define ISDISK(X) ((u_int)(X)&0x2) +#define DODISK(X) ((X) = (char *)((u_int)(X)|0x2)) #define BITS_PER_MAP 32 @@ -165,9 +156,9 @@ typedef struct htab { /* Memory resident data structure */ #define SPLITSHIFT 11 #define SPLITMASK 0x7FF -#define SPLITNUM(N) (((u_int32_t)(N)) >> SPLITSHIFT) +#define SPLITNUM(N) (((u_int)(N)) >> SPLITSHIFT) #define OPAGENUM(N) ((N) & SPLITMASK) -#define OADDR_OF(S,O) ((u_int32_t)((u_int32_t)(S) << SPLITSHIFT) + (O)) +#define OADDR_OF(S,O) ((u_int)((u_int)(S) << SPLITSHIFT) + (O)) #define BUCKET_TO_PAGE(B) \ (B) + hashp->HDRPAGES + ((B) ? hashp->SPARES[__log2((B)+1)-1] : 0) diff --git a/lib/libc/db/hash/hash_bigkey.c b/lib/libc/db/hash/hash_bigkey.c index 578314a6455e..b747fbce69f1 100644 --- a/lib/libc/db/hash/hash_bigkey.c +++ b/lib/libc/db/hash/hash_bigkey.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_bigkey.c 8.3 (Berkeley) 5/31/94"; +static char sccsid[] = "@(#)hash_bigkey.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -90,13 +90,13 @@ __big_insert(hashp, bufp, key, val) BUFHEAD *bufp; const DBT *key, *val; { - register u_int16_t *p; + register u_short *p; int key_size, n, val_size; - u_int16_t space, move_bytes, off; + u_short space, move_bytes, off; char *cp, *key_data, *val_data; cp = bufp->page; /* Character pointer of p. */ - p = (u_int16_t *)cp; + p = (u_short *)cp; key_data = (char *)key->data; key_size = key->size; @@ -134,7 +134,7 @@ __big_insert(hashp, bufp, key, val) OFFSET(p) = off; } else p[n - 2] = FULL_KEY; - p = (u_int16_t *)bufp->page; + p = (u_short *)bufp->page; cp = bufp->page; bufp->flags |= BUF_MOD; } @@ -164,7 +164,7 @@ __big_insert(hashp, bufp, key, val) if (!bufp) return (-1); cp = bufp->page; - p = (u_int16_t *)cp; + p = (u_short *)cp; } else p[n] = FULL_KEY_DATA; bufp->flags |= BUF_MOD; @@ -189,12 +189,12 @@ __big_delete(hashp, bufp) BUFHEAD *bufp; { register BUFHEAD *last_bfp, *rbufp; - u_int16_t *bp, pageno; + u_short *bp, pageno; int key_done, n; rbufp = bufp; last_bfp = NULL; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; pageno = 0; key_done = 0; @@ -217,7 +217,7 @@ __big_delete(hashp, bufp) last_bfp = rbufp; if (!rbufp) return (-1); /* Error. */ - bp = (u_int16_t *)rbufp->page; + bp = (u_short *)rbufp->page; } /* @@ -232,7 +232,7 @@ __big_delete(hashp, bufp) pageno = bp[n - 1]; /* Now, bp is the first page of the pair. */ - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; if (n > 2) { /* There is an overflow page. */ bp[1] = pageno; @@ -270,13 +270,13 @@ __find_bigpair(hashp, bufp, ndx, key, size) char *key; int size; { - register u_int16_t *bp; + register u_short *bp; register char *p; int ksize; - u_int16_t bytes; + u_short bytes; char *kkey; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; p = bufp->page; ksize = size; kkey = key; @@ -292,7 +292,7 @@ __find_bigpair(hashp, bufp, ndx, key, size) if (!bufp) return (-3); p = bufp->page; - bp = (u_int16_t *)p; + bp = (u_short *)p; ndx = 1; } @@ -314,17 +314,17 @@ __find_bigpair(hashp, bufp, ndx, key, size) * of the pair; 0 if there isn't any (i.e. big pair is the last key in the * bucket) */ -extern u_int16_t +extern u_short __find_last_page(hashp, bpp) HTAB *hashp; BUFHEAD **bpp; { BUFHEAD *bufp; - u_int16_t *bp, pageno; + u_short *bp, pageno; int n; bufp = *bpp; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; for (;;) { n = bp[0]; @@ -341,7 +341,7 @@ __find_last_page(hashp, bpp) bufp = __get_buf(hashp, pageno, bufp, 0); if (!bufp) return (0); /* Need to indicate an error! */ - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; } *bpp = bufp; @@ -364,15 +364,15 @@ __big_return(hashp, bufp, ndx, val, set_current) int set_current; { BUFHEAD *save_p; - u_int16_t *bp, len, off, save_addr; + u_short *bp, len, off, save_addr; char *tp; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; while (bp[ndx + 1] == PARTIAL_KEY) { bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; ndx = 1; } @@ -380,7 +380,7 @@ __big_return(hashp, bufp, ndx, val, set_current) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; save_p = bufp; save_addr = save_p->addr; off = bp[1]; @@ -401,7 +401,7 @@ __big_return(hashp, bufp, ndx, val, set_current) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; } else { /* The data is all on one page. */ tp = (char *)bp; @@ -420,7 +420,7 @@ __big_return(hashp, bufp, ndx, val, set_current) if (!hashp->cpage) return (-1); hashp->cndx = 1; - if (!((u_int16_t *) + if (!((u_short *) hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; @@ -452,14 +452,14 @@ collect_data(hashp, bufp, len, set) BUFHEAD *bufp; int len, set; { - register u_int16_t *bp; + register u_short *bp; register char *p; BUFHEAD *xbp; - u_int16_t save_addr; + u_short save_addr; int mylen, totlen; p = bufp->page; - bp = (u_int16_t *)p; + bp = (u_short *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; @@ -479,7 +479,7 @@ collect_data(hashp, bufp, len, set) __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!hashp->cpage) return (-1); - else if (!((u_int16_t *)hashp->cpage->page)[0]) { + else if (!((u_short *)hashp->cpage->page)[0]) { hashp->cbucket++; hashp->cpage = NULL; } @@ -531,10 +531,10 @@ collect_key(hashp, bufp, len, val, set) BUFHEAD *xbp; char *p; int mylen, totlen; - u_int16_t *bp, save_addr; + u_short *bp, save_addr; p = bufp->page; - bp = (u_int16_t *)p; + bp = (u_short *)p; mylen = hashp->BSIZE - bp[1]; save_addr = bufp->addr; @@ -573,15 +573,15 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret) /* Pointer to first page containing the big key/data */ BUFHEAD *big_keyp; int addr; /* Address of big_keyp */ - u_int32_t obucket;/* Old Bucket */ + u_int obucket;/* Old Bucket */ SPLIT_RETURN *ret; { register BUFHEAD *tmpp; - register u_int16_t *tp; + register u_short *tp; BUFHEAD *bp; DBT key, val; - u_int32_t change; - u_int16_t free_space, n, off; + u_int change; + u_short free_space, n, off; bp = big_keyp; @@ -613,14 +613,14 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret) (tmpp->ovfl ? tmpp->ovfl->addr : 0), (bp ? bp->addr : 0)); #endif tmpp->ovfl = bp; /* one of op/np point to big_keyp */ - tp = (u_int16_t *)tmpp->page; + tp = (u_short *)tmpp->page; #ifdef DEBUG assert(FREESPACE(tp) >= OVFLSIZE); #endif n = tp[0]; off = OFFSET(tp); free_space = FREESPACE(tp); - tp[++n] = (u_int16_t)addr; + tp[++n] = (u_short)addr; tp[++n] = OVFLPAGE; tp[0] = n; OFFSET(tp) = off; @@ -636,7 +636,7 @@ __big_split(hashp, op, np, big_keyp, addr, obucket, ret) ret->newp = np; ret->oldp = op; - tp = (u_int16_t *)big_keyp->page; + tp = (u_short *)big_keyp->page; big_keyp->flags |= BUF_MOD; if (tp[0] > 2) { /* diff --git a/lib/libc/db/hash/hash_buf.c b/lib/libc/db/hash/hash_buf.c index 92e1f933adb2..1362c83e1a3d 100644 --- a/lib/libc/db/hash/hash_buf.c +++ b/lib/libc/db/hash/hash_buf.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; +static char sccsid[] = "@(#)hash_buf.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -57,10 +57,8 @@ static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #include <sys/param.h> #include <errno.h> -#include <stddef.h> #include <stdio.h> #include <stdlib.h> - #ifdef DEBUG #include <assert.h> #endif @@ -70,7 +68,7 @@ static char sccsid[] = "@(#)hash_buf.c 8.5 (Berkeley) 7/15/94"; #include "page.h" #include "extern.h" -static BUFHEAD *newbuf __P((HTAB *, u_int32_t, BUFHEAD *)); +static BUFHEAD *newbuf __P((HTAB *, u_int, BUFHEAD *)); /* Unlink B from its place in the lru */ #define BUF_REMOVE(B) { \ @@ -104,12 +102,12 @@ static BUFHEAD *newbuf __P((HTAB *, u_int32_t, BUFHEAD *)); extern BUFHEAD * __get_buf(hashp, addr, prev_bp, newpage) HTAB *hashp; - u_int32_t addr; + u_int addr; BUFHEAD *prev_bp; int newpage; /* If prev_bp set, indicates a new overflow page. */ { register BUFHEAD *bp; - register u_int32_t is_disk_mask; + register u_int is_disk_mask; register int is_disk, segment_ndx; SEGMENT segp; @@ -142,7 +140,7 @@ __get_buf(hashp, addr, prev_bp, newpage) return (NULL); if (!prev_bp) segp[segment_ndx] = - (BUFHEAD *)((ptrdiff_t)bp | is_disk_mask); + (BUFHEAD *)((u_int)bp | is_disk_mask); } else { BUF_REMOVE(bp); MRU_INSERT(bp); @@ -159,7 +157,7 @@ __get_buf(hashp, addr, prev_bp, newpage) static BUFHEAD * newbuf(hashp, addr, prev_bp) HTAB *hashp; - u_int32_t addr; + u_int addr; BUFHEAD *prev_bp; { register BUFHEAD *bp; /* The buffer we're going to use */ @@ -167,7 +165,7 @@ newbuf(hashp, addr, prev_bp) register BUFHEAD *next_xbp; SEGMENT segp; int segment_ndx; - u_int16_t oaddr, *shortp; + u_short oaddr, *shortp; oaddr = 0; bp = LRU; @@ -179,16 +177,10 @@ newbuf(hashp, addr, prev_bp) /* Allocate a new one */ if ((bp = (BUFHEAD *)malloc(sizeof(BUFHEAD))) == NULL) return (NULL); -#ifdef PURIFY - memset(bp, 0xff, sizeof(BUFHEAD)); -#endif if ((bp->page = (char *)malloc(hashp->BSIZE)) == NULL) { free(bp); return (NULL); } -#ifdef PURIFY - memset(bp->page, 0xff, hashp->BSIZE); -#endif if (hashp->nbufs) hashp->nbufs--; } else { @@ -203,7 +195,7 @@ newbuf(hashp, addr, prev_bp) * Set oaddr before __put_page so that you get it * before bytes are swapped. */ - shortp = (u_int16_t *)bp->page; + shortp = (u_short *)bp->page; if (shortp[0]) oaddr = shortp[shortp[0] - 1]; if ((bp->flags & BUF_MOD) && __put_page(hashp, bp->page, @@ -246,7 +238,7 @@ newbuf(hashp, addr, prev_bp) (oaddr != xbp->addr)) break; - shortp = (u_int16_t *)xbp->page; + shortp = (u_short *)xbp->page; if (shortp[0]) /* set before __put_page */ oaddr = shortp[shortp[0] - 1]; diff --git a/lib/libc/db/hash/hash_log2.c b/lib/libc/db/hash/hash_log2.c index c8c56bff2dcc..b773707ebae2 100644 --- a/lib/libc/db/hash/hash_log2.c +++ b/lib/libc/db/hash/hash_log2.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,18 +35,16 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_log2.c 8.2 (Berkeley) 5/31/94"; +static char sccsid[] = "@(#)hash_log2.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> -#include <db.h> - -u_int32_t +u_int __log2(num) - u_int32_t num; + u_int num; { - register u_int32_t i, limit; + register u_int i, limit; limit = 1; for (i = 0; limit < num; limit = limit << 1, i++); diff --git a/lib/libc/db/hash/hash_page.c b/lib/libc/db/hash/hash_page.c index 2c050909f212..7b018cbea45c 100644 --- a/lib/libc/db/hash/hash_page.c +++ b/lib/libc/db/hash/hash_page.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; +static char sccsid[] = "@(#)hash_page.c 8.4 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ /* @@ -72,19 +72,19 @@ static char sccsid[] = "@(#)hash_page.c 8.7 (Berkeley) 8/16/94"; #include "page.h" #include "extern.h" -static u_int32_t *fetch_bitmap __P((HTAB *, int)); -static u_int32_t first_free __P((u_int32_t)); +static u_long *fetch_bitmap __P((HTAB *, int)); +static u_long first_free __P((u_long)); static int open_temp __P((HTAB *)); -static u_int16_t overflow_page __P((HTAB *)); +static u_short overflow_page __P((HTAB *)); static void putpair __P((char *, const DBT *, const DBT *)); -static void squeeze_key __P((u_int16_t *, const DBT *, const DBT *)); +static void squeeze_key __P((u_short *, const DBT *, const DBT *)); static int ugly_split - __P((HTAB *, u_int32_t, BUFHEAD *, BUFHEAD *, int, int)); + __P((HTAB *, u_int, BUFHEAD *, BUFHEAD *, int, int)); #define PAGE_INIT(P) { \ - ((u_int16_t *)(P))[0] = 0; \ - ((u_int16_t *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_int16_t); \ - ((u_int16_t *)(P))[2] = hashp->BSIZE; \ + ((u_short *)(P))[0] = 0; \ + ((u_short *)(P))[1] = hashp->BSIZE - 3 * sizeof(u_short); \ + ((u_short *)(P))[2] = hashp->BSIZE; \ } /* @@ -97,9 +97,9 @@ putpair(p, key, val) char *p; const DBT *key, *val; { - register u_int16_t *bp, n, off; + register u_short *bp, n, off; - bp = (u_int16_t *)p; + bp = (u_short *)p; /* Enter the key first. */ n = bp[0]; @@ -115,7 +115,7 @@ putpair(p, key, val) /* Adjust page info. */ bp[0] = n; - bp[n + 1] = off - ((n + 3) * sizeof(u_int16_t)); + bp[n + 1] = off - ((n + 3) * sizeof(u_short)); bp[n + 2] = off; } @@ -130,11 +130,11 @@ __delpair(hashp, bufp, ndx) BUFHEAD *bufp; register int ndx; { - register u_int16_t *bp, newoff; + register u_short *bp, newoff; register int n; - u_int16_t pairlen; + u_short pairlen; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; n = bp[0]; if (bp[ndx + 1] < REAL_KEY) @@ -165,7 +165,7 @@ __delpair(hashp, bufp, ndx) } /* Finally adjust the page data */ bp[n] = OFFSET(bp) + pairlen; - bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_int16_t); + bp[n - 1] = bp[n + 1] + pairlen + 2 * sizeof(u_short); bp[0] = n - 2; hashp->NKEYS--; @@ -180,18 +180,18 @@ __delpair(hashp, bufp, ndx) extern int __split_page(hashp, obucket, nbucket) HTAB *hashp; - u_int32_t obucket, nbucket; + u_int obucket, nbucket; { register BUFHEAD *new_bufp, *old_bufp; - register u_int16_t *ino; + register u_short *ino; register char *np; DBT key, val; int n, ndx, retval; - u_int16_t copyto, diff, off, moved; + u_short copyto, diff, off, moved; char *op; - copyto = (u_int16_t)hashp->BSIZE; - off = (u_int16_t)hashp->BSIZE; + copyto = (u_short)hashp->BSIZE; + off = (u_short)hashp->BSIZE; old_bufp = __get_buf(hashp, obucket, NULL, 0); if (old_bufp == NULL) return (-1); @@ -202,7 +202,7 @@ __split_page(hashp, obucket, nbucket) old_bufp->flags |= (BUF_MOD | BUF_PIN); new_bufp->flags |= (BUF_MOD | BUF_PIN); - ino = (u_int16_t *)(op = old_bufp->page); + ino = (u_short *)(op = old_bufp->page); np = new_bufp->page; moved = 0; @@ -244,13 +244,13 @@ __split_page(hashp, obucket, nbucket) /* Now clean up the page */ ino[0] -= moved; - FREESPACE(ino) = copyto - sizeof(u_int16_t) * (ino[0] + 3); + FREESPACE(ino) = copyto - sizeof(u_short) * (ino[0] + 3); OFFSET(ino) = copyto; #ifdef DEBUG3 (void)fprintf(stderr, "split %d/%d\n", - ((u_int16_t *)np)[0] / 2, - ((u_int16_t *)op)[0] / 2); + ((u_short *)np)[0] / 2, + ((u_short *)op)[0] / 2); #endif /* unpin both pages */ old_bufp->flags &= ~BUF_PIN; @@ -276,28 +276,28 @@ __split_page(hashp, obucket, nbucket) static int ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) HTAB *hashp; - u_int32_t obucket; /* Same as __split_page. */ + u_int obucket; /* Same as __split_page. */ BUFHEAD *old_bufp, *new_bufp; int copyto; /* First byte on page which contains key/data values. */ int moved; /* Number of pairs moved to new page. */ { register BUFHEAD *bufp; /* Buffer header for ino */ - register u_int16_t *ino; /* Page keys come off of */ - register u_int16_t *np; /* New page */ - register u_int16_t *op; /* Page keys go on to if they aren't moving */ + register u_short *ino; /* Page keys come off of */ + register u_short *np; /* New page */ + register u_short *op; /* Page keys go on to if they aren't moving */ BUFHEAD *last_bfp; /* Last buf header OVFL needing to be freed */ DBT key, val; SPLIT_RETURN ret; - u_int16_t n, off, ov_addr, scopyto; + u_short n, off, ov_addr, scopyto; char *cino; /* Character value of ino */ bufp = old_bufp; - ino = (u_int16_t *)old_bufp->page; - np = (u_int16_t *)new_bufp->page; - op = (u_int16_t *)old_bufp->page; + ino = (u_short *)old_bufp->page; + np = (u_short *)new_bufp->page; + op = (u_short *)old_bufp->page; last_bfp = NULL; - scopyto = (u_int16_t)copyto; /* ANSI */ + scopyto = (u_short)copyto; /* ANSI */ n = ino[0] - 1; while (n < ino[0]) { @@ -308,16 +308,16 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) old_bufp = ret.oldp; if (!old_bufp) return (-1); - op = (u_int16_t *)old_bufp->page; + op = (u_short *)old_bufp->page; new_bufp = ret.newp; if (!new_bufp) return (-1); - np = (u_int16_t *)new_bufp->page; + np = (u_short *)new_bufp->page; bufp = ret.nextp; if (!bufp) return (0); cino = (char *)bufp->page; - ino = (u_int16_t *)cino; + ino = (u_short *)cino; last_bfp = ret.nextp; } else if (ino[n + 1] == OVFLPAGE) { ov_addr = ino[n]; @@ -327,14 +327,14 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) */ ino[0] -= (moved + 2); FREESPACE(ino) = - scopyto - sizeof(u_int16_t) * (ino[0] + 3); + scopyto - sizeof(u_short) * (ino[0] + 3); OFFSET(ino) = scopyto; bufp = __get_buf(hashp, ov_addr, bufp, 0); if (!bufp) return (-1); - ino = (u_int16_t *)bufp->page; + ino = (u_short *)bufp->page; n = 1; scopyto = hashp->BSIZE; moved = 0; @@ -362,7 +362,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, old_bufp); if (!old_bufp) return (-1); - op = (u_int16_t *)old_bufp->page; + op = (u_short *)old_bufp->page; putpair((char *)op, &key, &val); } old_bufp->flags |= BUF_MOD; @@ -375,7 +375,7 @@ ugly_split(hashp, obucket, old_bufp, new_bufp, copyto, moved) __add_ovflpage(hashp, new_bufp); if (!new_bufp) return (-1); - np = (u_int16_t *)new_bufp->page; + np = (u_short *)new_bufp->page; putpair((char *)np, &key, &val); } new_bufp->flags |= BUF_MOD; @@ -400,10 +400,10 @@ __addel(hashp, bufp, key, val) BUFHEAD *bufp; const DBT *key, *val; { - register u_int16_t *bp, *sop; + register u_short *bp, *sop; int do_expand; - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; do_expand = 0; while (bp[0] && (bp[2] < REAL_KEY || bp[bp[0]] < REAL_KEY)) /* Exception case */ @@ -415,7 +415,7 @@ __addel(hashp, bufp, key, val) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; } else /* Try to squeeze key on this page */ if (FREESPACE(bp) > PAIRSIZE(key, val)) { @@ -425,7 +425,7 @@ __addel(hashp, bufp, key, val) bufp = __get_buf(hashp, bp[bp[0] - 1], bufp, 0); if (!bufp) return (-1); - bp = (u_int16_t *)bufp->page; + bp = (u_short *)bufp->page; } if (PAIRFITS(bp, key, val)) @@ -435,7 +435,7 @@ __addel(hashp, bufp, key, val) bufp = __add_ovflpage(hashp, bufp); if (!bufp) return (-1); - sop = (u_int16_t *)bufp->page; + sop = (u_short *)bufp->page; if (PAIRFITS(sop, key, val)) putpair((char *)sop, key, val); @@ -466,12 +466,12 @@ __add_ovflpage(hashp, bufp) HTAB *hashp; BUFHEAD *bufp; { - register u_int16_t *sp; - u_int16_t ndx, ovfl_num; + register u_short *sp; + u_short ndx, ovfl_num; #ifdef DEBUG1 int tmp1, tmp2; #endif - sp = (u_int16_t *)bufp->page; + sp = (u_short *)bufp->page; /* Check if we are dynamically determining the fill factor */ if (hashp->FFACTOR == DEF_FFACTOR) { @@ -518,12 +518,12 @@ extern int __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) HTAB *hashp; char *p; - u_int32_t bucket; + u_int bucket; int is_bucket, is_disk, is_bitmap; { register int fd, page, size; int rsize; - u_int16_t *bp; + u_short *bp; fd = hashp->fp; size = hashp->BSIZE; @@ -539,7 +539,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if ((lseek(fd, (off_t)page << hashp->BSHIFT, SEEK_SET) == -1) || ((rsize = read(fd, p, size)) == -1)) return (-1); - bp = (u_int16_t *)p; + bp = (u_short *)p; if (!rsize) bp[0] = 0; /* We hit the EOF, so initialize a new page */ else @@ -556,7 +556,7 @@ __get_page(hashp, p, bucket, is_bucket, is_disk, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((int *)p)[i]); + M_32_SWAP(((long *)p)[i]); } else { M_16_SWAP(bp[0]); max = bp[0] + 2; @@ -578,7 +578,7 @@ extern int __put_page(hashp, p, bucket, is_bucket, is_bitmap) HTAB *hashp; char *p; - u_int32_t bucket; + u_int bucket; int is_bucket, is_bitmap; { register int fd, page, size; @@ -596,11 +596,11 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) if (is_bitmap) { max = hashp->BSIZE >> 2; /* divide by 4 */ for (i = 0; i < max; i++) - M_32_SWAP(((int *)p)[i]); + M_32_SWAP(((long *)p)[i]); } else { - max = ((u_int16_t *)p)[0] + 2; + max = ((u_short *)p)[0] + 2; for (i = 0; i <= max; i++) - M_16_SWAP(((u_int16_t *)p)[i]); + M_16_SWAP(((u_short *)p)[i]); } } if (is_bucket) @@ -624,14 +624,14 @@ __put_page(hashp, p, bucket, is_bucket, is_bitmap) * once they are read in. */ extern int -__ibitmap(hashp, pnum, nbits, ndx) +__init_bitmap(hashp, pnum, nbits, ndx) HTAB *hashp; int pnum, nbits, ndx; { - u_int32_t *ip; + u_long *ip; int clearbytes, clearints; - if ((ip = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) + if ((ip = (u_long *)malloc(hashp->BSIZE)) == NULL) return (1); hashp->nmaps++; clearints = ((nbits - 1) >> INT_BYTE_SHIFT) + 1; @@ -641,16 +641,16 @@ __ibitmap(hashp, pnum, nbits, ndx) hashp->BSIZE - clearbytes); ip[clearints - 1] = ALL_SET << (nbits & BYTE_MASK); SETBIT(ip, 0); - hashp->BITMAPS[ndx] = (u_int16_t)pnum; + hashp->BITMAPS[ndx] = (u_short)pnum; hashp->mapp[ndx] = ip; return (0); } -static u_int32_t +static u_long first_free(map) - u_int32_t map; + u_long map; { - register u_int32_t i, mask; + register u_long i, mask; mask = 0x1; for (i = 0; i < BITS_PER_MAP; i++) { @@ -661,13 +661,13 @@ first_free(map) return (i); } -static u_int16_t +static u_short overflow_page(hashp) HTAB *hashp; { - register u_int32_t *freep; + register u_long *freep; register int max_free, offset, splitnum; - u_int16_t addr; + u_short addr; int bit, first_page, free_bit, free_page, i, in_use_bits, j; #ifdef DEBUG2 int tmp1, tmp2; @@ -681,9 +681,9 @@ overflow_page(hashp) /* Look through all the free maps to find the first free block */ first_page = hashp->LAST_FREED >>(hashp->BSHIFT + BYTE_SHIFT); for ( i = first_page; i <= free_page; i++ ) { - if (!(freep = (u_int32_t *)hashp->mapp[i]) && + if (!(freep = (u_long *)hashp->mapp[i]) && !(freep = fetch_bitmap(hashp, i))) - return (0); + return (NULL); if (i == free_page) in_use_bits = free_bit; else @@ -713,7 +713,7 @@ overflow_page(hashp) if (offset > SPLITMASK) { if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (0); + return (NULL); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -726,7 +726,7 @@ overflow_page(hashp) free_page++; if (free_page >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (0); + return (NULL); } /* * This is tricky. The 1 indicates that you want the new page @@ -739,9 +739,9 @@ overflow_page(hashp) * don't have to if we tell init_bitmap not to leave it clear * in the first place. */ - if (__ibitmap(hashp, - (int)OADDR_OF(splitnum, offset), 1, free_page)) - return (0); + if (__init_bitmap(hashp, (int)OADDR_OF(splitnum, offset), + 1, free_page)) + return (NULL); hashp->SPARES[splitnum]++; #ifdef DEBUG2 free_bit = 2; @@ -751,7 +751,7 @@ overflow_page(hashp) if (++splitnum >= NCACHED) { (void)write(STDERR_FILENO, OVMSG, sizeof(OVMSG) - 1); - return (0); + return (NULL); } hashp->OVFL_POINT = splitnum; hashp->SPARES[splitnum] = hashp->SPARES[splitnum-1]; @@ -795,7 +795,7 @@ found: for (i = 0; (i < splitnum) && (bit > hashp->SPARES[i]); i++); offset = (i ? bit - hashp->SPARES[i - 1] : bit); if (offset >= SPLITMASK) - return (0); /* Out of overflow pages */ + return (NULL); /* Out of overflow pages */ addr = OADDR_OF(i, offset); #ifdef DEBUG2 (void)fprintf(stderr, "OVERFLOW_PAGE: ADDR: %d BIT: %d PAGE %d\n", @@ -814,16 +814,16 @@ __free_ovflpage(hashp, obufp) HTAB *hashp; BUFHEAD *obufp; { - register u_int16_t addr; - u_int32_t *freep; + register u_short addr; + u_long *freep; int bit_address, free_page, free_bit; - u_int16_t ndx; + u_short ndx; addr = obufp->addr; #ifdef DEBUG1 (void)fprintf(stderr, "Freeing %d\n", addr); #endif - ndx = (((u_int16_t)addr) >> SPLITSHIFT); + ndx = (((u_short)addr) >> SPLITSHIFT); bit_address = (ndx ? hashp->SPARES[ndx - 1] : 0) + (addr & SPLITMASK) - 1; if (bit_address < hashp->LAST_FREED) @@ -879,11 +879,11 @@ open_temp(hashp) */ static void squeeze_key(sp, key, val) - u_int16_t *sp; + u_short *sp; const DBT *key, *val; { register char *p; - u_int16_t free_space, n, off, pageno; + u_short free_space, n, off, pageno; p = (char *)sp; n = sp[0]; @@ -904,14 +904,14 @@ squeeze_key(sp, key, val) OFFSET(sp) = off; } -static u_int32_t * +static u_long * fetch_bitmap(hashp, ndx) HTAB *hashp; int ndx; { if (ndx >= hashp->nmaps) return (NULL); - if ((hashp->mapp[ndx] = (u_int32_t *)malloc(hashp->BSIZE)) == NULL) + if ((hashp->mapp[ndx] = (u_long *)malloc(hashp->BSIZE)) == NULL) return (NULL); if (__get_page(hashp, (char *)hashp->mapp[ndx], hashp->BITMAPS[ndx], 0, 1, 1)) { diff --git a/lib/libc/db/hash/hsearch.c b/lib/libc/db/hash/hsearch.c index cc8f7a4aad1f..e4914b1bb077 100644 --- a/lib/libc/db/hash/hsearch.c +++ b/lib/libc/db/hash/hsearch.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)hsearch.c 8.4 (Berkeley) 7/21/94"; +static char sccsid[] = "@(#)hsearch.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -58,7 +58,7 @@ hcreate(nel) info.nelem = nel; info.bsize = 256; info.ffactor = 8; - info.cachesize = 0; + info.cachesize = NULL; info.hash = NULL; info.lorder = 0; dbp = (DB *)__hash_open(NULL, O_CREAT | O_RDWR, 0600, &info, 0); diff --git a/lib/libc/db/hash/ndbm.c b/lib/libc/db/hash/ndbm.c index 28adce4f9435..89b9916566b2 100644 --- a/lib/libc/db/hash/ndbm.c +++ b/lib/libc/db/hash/ndbm.c @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94"; +static char sccsid[] = "@(#)ndbm.c 8.2 (Berkeley) 9/11/93"; #endif /* LIBC_SCCS and not lint */ /* @@ -45,10 +45,10 @@ static char sccsid[] = "@(#)ndbm.c 8.4 (Berkeley) 7/21/94"; #include <sys/param.h> +#include <ndbm.h> #include <stdio.h> #include <string.h> -#include <ndbm.h> #include "hash.h" /* @@ -67,7 +67,7 @@ dbm_open(file, flags, mode) info.bsize = 4096; info.ffactor = 40; info.nelem = 1; - info.cachesize = 0; + info.cachesize = NULL; info.hash = NULL; info.lorder = 0; (void)strcpy(path, file); @@ -180,7 +180,7 @@ dbm_error(db) HTAB *hp; hp = (HTAB *)db->internal; - return (hp->error); + return (hp->errno); } extern int @@ -190,7 +190,7 @@ dbm_clearerr(db) HTAB *hp; hp = (HTAB *)db->internal; - hp->error = 0; + hp->errno = 0; return (0); } diff --git a/lib/libc/db/hash/page.h b/lib/libc/db/hash/page.h index 0fc0d5a3e96d..dae82aebdd74 100644 --- a/lib/libc/db/hash/page.h +++ b/lib/libc/db/hash/page.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -33,7 +33,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)page.h 8.2 (Berkeley) 5/31/94 + * @(#)page.h 8.1 (Berkeley) 6/6/93 */ /* @@ -73,20 +73,20 @@ * You might as well do this up front. */ -#define PAIRSIZE(K,D) (2*sizeof(u_int16_t) + (K)->size + (D)->size) -#define BIGOVERHEAD (4*sizeof(u_int16_t)) -#define KEYSIZE(K) (4*sizeof(u_int16_t) + (K)->size); -#define OVFLSIZE (2*sizeof(u_int16_t)) +#define PAIRSIZE(K,D) (2*sizeof(u_short) + (K)->size + (D)->size) +#define BIGOVERHEAD (4*sizeof(u_short)) +#define KEYSIZE(K) (4*sizeof(u_short) + (K)->size); +#define OVFLSIZE (2*sizeof(u_short)) #define FREESPACE(P) ((P)[(P)[0]+1]) #define OFFSET(P) ((P)[(P)[0]+2]) #define PAIRFITS(P,K,D) \ (((P)[2] >= REAL_KEY) && \ (PAIRSIZE((K),(D)) + OVFLSIZE) <= FREESPACE((P))) -#define PAGE_META(N) (((N)+3) * sizeof(u_int16_t)) +#define PAGE_META(N) (((N)+3) * sizeof(u_short)) typedef struct { BUFHEAD *newp; BUFHEAD *oldp; BUFHEAD *nextp; - u_int16_t next_addr; + u_short next_addr; } SPLIT_RETURN; diff --git a/lib/libc/db/man/btree.3 b/lib/libc/db/man/btree.3 index 8284b21aaeec..a51e1e562c3d 100644 --- a/lib/libc/db/man/btree.3 +++ b/lib/libc/db/man/btree.3 @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)btree.3 8.4 (Berkeley) 8/18/94 +.\" @(#)btree.3 8.3 (Berkeley) 2/21/94 .\" -.TH BTREE 3 "August 18, 1994" +.TH BTREE 3 "February 21, 1994" .\".UC 7 .SH NAME btree \- btree database access method @@ -207,13 +207,6 @@ O lg base N where base is the average fill factor. Often, inserting ordered data into btrees results in a low fill factor. This implementation has been modified to make ordered insertion the best case, resulting in a much better than normal page fill factor. -.SH ERRORS -The -.I btree -access method routines may fail and set -.I errno -for any of the errors specified for the library routine -.IR dbopen (3). .SH "SEE ALSO" .IR dbopen (3), .IR hash (3), diff --git a/lib/libc/db/man/hash.3 b/lib/libc/db/man/hash.3 index d408b5dcbca3..3ae00a20d80d 100644 --- a/lib/libc/db/man/hash.3 +++ b/lib/libc/db/man/hash.3 @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)hash.3 8.6 (Berkeley) 8/18/94 +.\" @(#)hash.3 8.5 (Berkeley) 2/21/94 .\" -.TH HASH 3 "August 18, 1994" +.TH HASH 3 "February 21, 1994" .UC 7 .SH NAME hash \- hash database access method @@ -131,19 +131,12 @@ If a hash function is specified, will attempt to determine if the hash function specified is the same as the one with which the database was created, and will fail if it is not. .PP -Backward compatible interfaces to the older -.I dbm +Backward compatible interfaces to the routines described in +.IR dbm (3), and -.I ndbm -routines are provided, however these interfaces are not compatible with +.IR ndbm (3) +are provided, however these interfaces are not compatible with previous file formats. -.SH ERRORS -The -.I hash -access method routines may fail and set -.I errno -for any of the errors specified for the library routine -.IR dbopen (3). .SH "SEE ALSO" .IR btree (3), .IR dbopen (3), diff --git a/lib/libc/db/man/recno.3 b/lib/libc/db/man/recno.3 index 516bef0a9007..a40e6c941a54 100644 --- a/lib/libc/db/man/recno.3 +++ b/lib/libc/db/man/recno.3 @@ -29,9 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)recno.3 8.5 (Berkeley) 8/18/94 +.\" @(#)recno.3 8.3 (Berkeley) 2/21/94 .\" -.TH RECNO 3 "August 18, 1994" +.TH RECNO 3 "February 21, 1994" .UC 7 .SH NAME recno \- record number database access method @@ -97,9 +97,6 @@ The structure element specifies the length of the record, and the structure element .I bval is used as the pad character. -Any records, inserted into the database, that are less than -.I reclen -bytes long are automatically padded. .TP R_NOKEY In the interface specified by @@ -179,11 +176,6 @@ The .I size field of the key should be the size of that type. .PP -Because there can be no meta-data associated with the underlying -recno access method files, any changes made to the default values -(e.g. fixed record length or byte separator value) must be explicitly -specified each time the file is opened. -.PP In the interface specified by .IR dbopen , using the @@ -191,23 +183,11 @@ using the interface to create a new record will cause the creation of multiple, empty records if the record number is more than one greater than the largest record currently in the database. -.SH ERRORS -The -.I recno -access method routines may fail and set -.I errno -for any of the errors specified for the library routine -.IR dbopen (3) -or the following: -.TP -[EINVAL] -An attempt was made to add a record to a fixed-length database that -was too large to fit. .SH "SEE ALSO" -.IR btree (3) .IR dbopen (3), .IR hash (3), .IR mpool (3), +.IR recno (3) .sp .IR "Document Processing in a Relational Database System" , Michael Stonebraker, Heidi Stettner, Joseph Kalash, Antonin Guttman, diff --git a/lib/libc/db/mpool/mpool.c b/lib/libc/db/mpool/mpool.c index a61041e09160..562c7f5e98fc 100644 --- a/lib/libc/db/mpool/mpool.c +++ b/lib/libc/db/mpool/mpool.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,11 +32,10 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94"; +static char sccsid[] = "@(#)mpool.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> -#include <sys/queue.h> #include <sys/stat.h> #include <errno.h> @@ -46,21 +45,31 @@ static char sccsid[] = "@(#)mpool.c 8.5 (Berkeley) 7/26/94"; #include <unistd.h> #include <db.h> - #define __MPOOLINTERFACE_PRIVATE -#include <mpool.h> +#include "mpool.h" static BKT *mpool_bkt __P((MPOOL *)); static BKT *mpool_look __P((MPOOL *, pgno_t)); static int mpool_write __P((MPOOL *, BKT *)); +#ifdef DEBUG +static void __mpoolerr __P((const char *fmt, ...)); +#endif /* - * mpool_open -- - * Initialize a memory pool. + * MPOOL_OPEN -- initialize a memory pool. + * + * Parameters: + * key: Shared buffer key. + * fd: File descriptor. + * pagesize: File page size. + * maxcache: Max number of cached pages. + * + * Returns: + * MPOOL pointer, NULL on error. */ MPOOL * mpool_open(key, fd, pagesize, maxcache) - void *key; + DBT *key; int fd; pgno_t pagesize, maxcache; { @@ -68,35 +77,49 @@ mpool_open(key, fd, pagesize, maxcache) MPOOL *mp; int entry; - /* - * Get information about the file. - * - * XXX - * We don't currently handle pipes, although we should. - */ if (fstat(fd, &sb)) return (NULL); + /* XXX + * We should only set st_size to 0 for pipes -- 4.4BSD has the fix so + * that stat(2) returns true for ISSOCK on pipes. Until then, this is + * fairly close. + */ if (!S_ISREG(sb.st_mode)) { errno = ESPIPE; return (NULL); } - /* Allocate and initialize the MPOOL cookie. */ - if ((mp = (MPOOL *)calloc(1, sizeof(MPOOL))) == NULL) + if ((mp = (MPOOL *)malloc(sizeof(MPOOL))) == NULL) return (NULL); - CIRCLEQ_INIT(&mp->lqh); + mp->free.cnext = mp->free.cprev = (BKT *)&mp->free; + mp->lru.cnext = mp->lru.cprev = (BKT *)&mp->lru; for (entry = 0; entry < HASHSIZE; ++entry) - CIRCLEQ_INIT(&mp->hqh[entry]); + mp->hashtable[entry].hnext = mp->hashtable[entry].hprev = + mp->hashtable[entry].cnext = mp->hashtable[entry].cprev = + (BKT *)&mp->hashtable[entry]; + mp->curcache = 0; mp->maxcache = maxcache; - mp->npages = sb.st_size / pagesize; mp->pagesize = pagesize; + mp->npages = sb.st_size / pagesize; mp->fd = fd; + mp->pgcookie = NULL; + mp->pgin = mp->pgout = NULL; + +#ifdef STATISTICS + mp->cachehit = mp->cachemiss = mp->pagealloc = mp->pageflush = + mp->pageget = mp->pagenew = mp->pageput = mp->pageread = + mp->pagewrite = 0; +#endif return (mp); } /* - * mpool_filter -- - * Initialize input/output filters. + * MPOOL_FILTER -- initialize input/output filters. + * + * Parameters: + * pgin: Page in conversion routine. + * pgout: Page out conversion routine. + * pgcookie: Cookie for page in/out routines. */ void mpool_filter(mp, pgin, pgout, pgcookie) @@ -109,130 +132,126 @@ mpool_filter(mp, pgin, pgout, pgcookie) mp->pgout = pgout; mp->pgcookie = pgcookie; } - + /* - * mpool_new -- - * Get a new page of memory. + * MPOOL_NEW -- get a new page + * + * Parameters: + * mp: mpool cookie + * pgnoadddr: place to store new page number + * Returns: + * RET_ERROR, RET_SUCCESS */ void * mpool_new(mp, pgnoaddr) MPOOL *mp; pgno_t *pgnoaddr; { - struct _hqh *head; - BKT *bp; + BKT *b; + BKTHDR *hp; - if (mp->npages == MAX_PAGE_NUMBER) { - (void)fprintf(stderr, "mpool_new: page allocation overflow.\n"); - abort(); - } #ifdef STATISTICS ++mp->pagenew; #endif /* - * Get a BKT from the cache. Assign a new page number, attach - * it to the head of the hash chain, the tail of the lru chain, - * and return. + * Get a BKT from the cache. Assign a new page number, attach it to + * the hash and lru chains and return. */ - if ((bp = mpool_bkt(mp)) == NULL) + if ((b = mpool_bkt(mp)) == NULL) return (NULL); - *pgnoaddr = bp->pgno = mp->npages++; - bp->flags = MPOOL_PINNED; - - head = &mp->hqh[HASHKEY(bp->pgno)]; - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q); - return (bp->page); + *pgnoaddr = b->pgno = mp->npages++; + b->flags = MPOOL_PINNED; + inshash(b, b->pgno); + inschain(b, &mp->lru); + return (b->page); } /* - * mpool_get - * Get a page. + * MPOOL_GET -- get a page from the pool + * + * Parameters: + * mp: mpool cookie + * pgno: page number + * flags: not used + * + * Returns: + * RET_ERROR, RET_SUCCESS */ void * mpool_get(mp, pgno, flags) MPOOL *mp; pgno_t pgno; - u_int flags; /* XXX not used? */ + u_int flags; /* XXX not used? */ { - struct _hqh *head; - BKT *bp; + BKT *b; + BKTHDR *hp; off_t off; int nr; - /* Check for attempt to retrieve a non-existent page. */ - if (pgno >= mp->npages) { - errno = EINVAL; - return (NULL); - } - + /* + * If asking for a specific page that is already in the cache, find + * it and return it. + */ + if (b = mpool_look(mp, pgno)) { #ifdef STATISTICS - ++mp->pageget; + ++mp->pageget; #endif - - /* Check for a page that is cached. */ - if ((bp = mpool_look(mp, pgno)) != NULL) { #ifdef DEBUG - if (bp->flags & MPOOL_PINNED) { - (void)fprintf(stderr, - "mpool_get: page %d already pinned\n", bp->pgno); - abort(); - } + if (b->flags & MPOOL_PINNED) + __mpoolerr("mpool_get: page %d already pinned", + b->pgno); #endif - /* - * Move the page to the head of the hash chain and the tail - * of the lru chain. - */ - head = &mp->hqh[HASHKEY(bp->pgno)]; - CIRCLEQ_REMOVE(head, bp, hq); - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_REMOVE(&mp->lqh, bp, q); - CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q); - - /* Return a pinned page. */ - bp->flags |= MPOOL_PINNED; - return (bp->page); + rmchain(b); + inschain(b, &mp->lru); + b->flags |= MPOOL_PINNED; + return (b->page); + } + + /* Not allowed to retrieve a non-existent page. */ + if (pgno >= mp->npages) { + errno = EINVAL; + return (NULL); } /* Get a page from the cache. */ - if ((bp = mpool_bkt(mp)) == NULL) + if ((b = mpool_bkt(mp)) == NULL) return (NULL); + b->pgno = pgno; + b->flags = MPOOL_PINNED; - /* Read in the contents. */ #ifdef STATISTICS ++mp->pageread; #endif + /* Read in the contents. */ off = mp->pagesize * pgno; if (lseek(mp->fd, off, SEEK_SET) != off) return (NULL); - if ((nr = read(mp->fd, bp->page, mp->pagesize)) != mp->pagesize) { + if ((nr = read(mp->fd, b->page, mp->pagesize)) != mp->pagesize) { if (nr >= 0) errno = EFTYPE; return (NULL); } + if (mp->pgin) + (mp->pgin)(mp->pgcookie, b->pgno, b->page); - /* Set the page number, pin the page. */ - bp->pgno = pgno; - bp->flags = MPOOL_PINNED; - - /* - * Add the page to the head of the hash chain and the tail - * of the lru chain. - */ - head = &mp->hqh[HASHKEY(bp->pgno)]; - CIRCLEQ_INSERT_HEAD(head, bp, hq); - CIRCLEQ_INSERT_TAIL(&mp->lqh, bp, q); - - /* Run through the user's filter. */ - if (mp->pgin != NULL) - (mp->pgin)(mp->pgcookie, bp->pgno, bp->page); - - return (bp->page); + inshash(b, b->pgno); + inschain(b, &mp->lru); +#ifdef STATISTICS + ++mp->pageget; +#endif + return (b->page); } /* - * mpool_put - * Return a page. + * MPOOL_PUT -- return a page to the pool + * + * Parameters: + * mp: mpool cookie + * page: page pointer + * pgno: page number + * + * Returns: + * RET_ERROR, RET_SUCCESS */ int mpool_put(mp, page, flags) @@ -240,172 +259,193 @@ mpool_put(mp, page, flags) void *page; u_int flags; { - BKT *bp; + BKT *baddr; +#ifdef DEBUG + BKT *b; +#endif #ifdef STATISTICS ++mp->pageput; #endif - bp = (BKT *)((char *)page - sizeof(BKT)); + baddr = (BKT *)((char *)page - sizeof(BKT)); #ifdef DEBUG - if (!(bp->flags & MPOOL_PINNED)) { - (void)fprintf(stderr, - "mpool_put: page %d not pinned\n", bp->pgno); - abort(); + if (!(baddr->flags & MPOOL_PINNED)) + __mpoolerr("mpool_put: page %d not pinned", b->pgno); + for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { + if (b == (BKT *)&mp->lru) + __mpoolerr("mpool_put: %0x: bad address", baddr); + if (b == baddr) + break; } #endif - bp->flags &= ~MPOOL_PINNED; - bp->flags |= flags & MPOOL_DIRTY; + baddr->flags &= ~MPOOL_PINNED; + baddr->flags |= flags & MPOOL_DIRTY; return (RET_SUCCESS); } /* - * mpool_close - * Close the buffer pool. + * MPOOL_CLOSE -- close the buffer pool + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS */ int mpool_close(mp) MPOOL *mp; { - BKT *bp; + BKT *b, *next; /* Free up any space allocated to the lru pages. */ - while ((bp = mp->lqh.cqh_first) != (void *)&mp->lqh) { - CIRCLEQ_REMOVE(&mp->lqh, mp->lqh.cqh_first, q); - free(bp); + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = next) { + next = b->cprev; + free(b); } - - /* Free the MPOOL cookie. */ free(mp); return (RET_SUCCESS); } /* - * mpool_sync - * Sync the pool to disk. + * MPOOL_SYNC -- sync the file to disk. + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS */ int mpool_sync(mp) MPOOL *mp; { - BKT *bp; + BKT *b; - /* Walk the lru chain, flushing any dirty pages to disk. */ - for (bp = mp->lqh.cqh_first; - bp != (void *)&mp->lqh; bp = bp->q.cqe_next) - if (bp->flags & MPOOL_DIRTY && - mpool_write(mp, bp) == RET_ERROR) + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) + if (b->flags & MPOOL_DIRTY && mpool_write(mp, b) == RET_ERROR) return (RET_ERROR); - - /* Sync the file descriptor. */ return (fsync(mp->fd) ? RET_ERROR : RET_SUCCESS); } /* - * mpool_bkt - * Get a page from the cache (or create one). + * MPOOL_BKT -- get/create a BKT from the cache + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * NULL on failure and a pointer to the BKT on success */ static BKT * mpool_bkt(mp) MPOOL *mp; { - struct _hqh *head; - BKT *bp; + BKT *b; - /* If under the max cached, always create a new page. */ if (mp->curcache < mp->maxcache) goto new; /* - * If the cache is max'd out, walk the lru list for a buffer we - * can flush. If we find one, write it (if necessary) and take it - * off any lists. If we don't find anything we grow the cache anyway. + * If the cache is maxxed out, search the lru list for a buffer we + * can flush. If we find one, write it if necessary and take it off + * any lists. If we don't find anything we grow the cache anyway. * The cache never shrinks. */ - for (bp = mp->lqh.cqh_first; - bp != (void *)&mp->lqh; bp = bp->q.cqe_next) - if (!(bp->flags & MPOOL_PINNED)) { - /* Flush if dirty. */ - if (bp->flags & MPOOL_DIRTY && - mpool_write(mp, bp) == RET_ERROR) + for (b = mp->lru.cprev; b != (BKT *)&mp->lru; b = b->cprev) + if (!(b->flags & MPOOL_PINNED)) { + if (b->flags & MPOOL_DIRTY && + mpool_write(mp, b) == RET_ERROR) return (NULL); + rmhash(b); + rmchain(b); #ifdef STATISTICS ++mp->pageflush; #endif - /* Remove from the hash and lru queues. */ - head = &mp->hqh[HASHKEY(bp->pgno)]; - CIRCLEQ_REMOVE(head, bp, hq); - CIRCLEQ_REMOVE(&mp->lqh, bp, q); #ifdef DEBUG - { void *spage; - spage = bp->page; - memset(bp, 0xff, sizeof(BKT) + mp->pagesize); - bp->page = spage; + { + void *spage; + spage = b->page; + memset(b, 0xff, sizeof(BKT) + mp->pagesize); + b->page = spage; } #endif - return (bp); + return (b); } -new: if ((bp = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) +new: if ((b = (BKT *)malloc(sizeof(BKT) + mp->pagesize)) == NULL) return (NULL); #ifdef STATISTICS ++mp->pagealloc; #endif -#if defined(DEBUG) || defined(PURIFY) - memset(bp, 0xff, sizeof(BKT) + mp->pagesize); +#ifdef DEBUG + memset(b, 0xff, sizeof(BKT) + mp->pagesize); #endif - bp->page = (char *)bp + sizeof(BKT); + b->page = (char *)b + sizeof(BKT); ++mp->curcache; - return (bp); + return (b); } /* - * mpool_write - * Write a page to disk. + * MPOOL_WRITE -- sync a page to disk + * + * Parameters: + * mp: mpool cookie + * + * Returns: + * RET_ERROR, RET_SUCCESS */ static int -mpool_write(mp, bp) +mpool_write(mp, b) MPOOL *mp; - BKT *bp; + BKT *b; { off_t off; + if (mp->pgout) + (mp->pgout)(mp->pgcookie, b->pgno, b->page); + #ifdef STATISTICS ++mp->pagewrite; #endif - - /* Run through the user's filter. */ - if (mp->pgout) - (mp->pgout)(mp->pgcookie, bp->pgno, bp->page); - - off = mp->pagesize * bp->pgno; + off = mp->pagesize * b->pgno; if (lseek(mp->fd, off, SEEK_SET) != off) return (RET_ERROR); - if (write(mp->fd, bp->page, mp->pagesize) != mp->pagesize) + if (write(mp->fd, b->page, mp->pagesize) != mp->pagesize) return (RET_ERROR); - - bp->flags &= ~MPOOL_DIRTY; + b->flags &= ~MPOOL_DIRTY; return (RET_SUCCESS); } /* - * mpool_look - * Lookup a page in the cache. + * MPOOL_LOOK -- lookup a page + * + * Parameters: + * mp: mpool cookie + * pgno: page number + * + * Returns: + * NULL on failure and a pointer to the BKT on success */ static BKT * mpool_look(mp, pgno) MPOOL *mp; pgno_t pgno; { - struct _hqh *head; - BKT *bp; + register BKT *b; + register BKTHDR *tb; - head = &mp->hqh[HASHKEY(pgno)]; - for (bp = head->cqh_first; bp != (void *)head; bp = bp->hq.cqe_next) - if (bp->pgno == pgno) { + /* XXX + * If find the buffer, put it first on the hash chain so can + * find it again quickly. + */ + tb = &mp->hashtable[HASHKEY(pgno)]; + for (b = tb->hnext; b != (BKT *)tb; b = b->hnext) + if (b->pgno == pgno) { #ifdef STATISTICS ++mp->cachehit; #endif - return (bp); + return (b); } #ifdef STATISTICS ++mp->cachemiss; @@ -415,14 +455,16 @@ mpool_look(mp, pgno) #ifdef STATISTICS /* - * mpool_stat - * Print out cache statistics. + * MPOOL_STAT -- cache statistics + * + * Parameters: + * mp: mpool cookie */ void mpool_stat(mp) MPOOL *mp; { - BKT *bp; + BKT *b; int cnt; char *sep; @@ -436,7 +478,7 @@ mpool_stat(mp) mp->pagealloc, mp->pageflush); if (mp->cachehit + mp->cachemiss) (void)fprintf(stderr, - "%.0f%% cache hit rate (%lu hits, %lu misses)\n", + "%.0f%% cache hit rate (%lu hits, %lu misses)\n", ((double)mp->cachehit / (mp->cachehit + mp->cachemiss)) * 100, mp->cachehit, mp->cachemiss); (void)fprintf(stderr, "%lu page reads, %lu page writes\n", @@ -444,20 +486,49 @@ mpool_stat(mp) sep = ""; cnt = 0; - for (bp = mp->lqh.cqh_first; - bp != (void *)&mp->lqh; bp = bp->q.cqe_next) { - (void)fprintf(stderr, "%s%d", sep, bp->pgno); - if (bp->flags & MPOOL_DIRTY) + for (b = mp->lru.cnext; b != (BKT *)&mp->lru; b = b->cnext) { + (void)fprintf(stderr, "%s%d", sep, b->pgno); + if (b->flags & MPOOL_DIRTY) (void)fprintf(stderr, "d"); - if (bp->flags & MPOOL_PINNED) + if (b->flags & MPOOL_PINNED) (void)fprintf(stderr, "P"); if (++cnt == 10) { sep = "\n"; cnt = 0; } else sep = ", "; - + } (void)fprintf(stderr, "\n"); } #endif + +#ifdef DEBUG +#if __STDC__ +#include <stdarg.h> +#else +#include <varargs.h> +#endif + +static void +#if __STDC__ +__mpoolerr(const char *fmt, ...) +#else +__mpoolerr(fmt, va_alist) + char *fmt; + va_dcl +#endif +{ + va_list ap; +#if __STDC__ + va_start(ap, fmt); +#else + va_start(ap); +#endif + (void)vfprintf(stderr, fmt, ap); + va_end(ap); + (void)fprintf(stderr, "\n"); + abort(); + /* NOTREACHED */ +} +#endif diff --git a/lib/libc/db/recno/extern.h b/lib/libc/db/recno/extern.h index feed43445332..218813169f93 100644 --- a/lib/libc/db/recno/extern.h +++ b/lib/libc/db/recno/extern.h @@ -30,14 +30,14 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)extern.h 8.3 (Berkeley) 6/4/94 + * @(#)extern.h 8.2 (Berkeley) 2/21/94 */ #include "../btree/extern.h" int __rec_close __P((DB *)); int __rec_delete __P((const DB *, const DBT *, u_int)); -int __rec_dleaf __P((BTREE *, PAGE *, u_int32_t)); +int __rec_dleaf __P((BTREE *, PAGE *, indx_t)); int __rec_fd __P((const DB *)); int __rec_fmap __P((BTREE *, recno_t)); int __rec_fout __P((BTREE *)); diff --git a/lib/libc/db/recno/rec_close.c b/lib/libc/db/recno/rec_close.c index 16fb0b4ecab0..a96d4f1a1edf 100644 --- a/lib/libc/db/recno/rec_close.c +++ b/lib/libc/db/recno/rec_close.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_close.c 8.6 (Berkeley) 8/18/94"; +static char sccsid[] = "@(#)rec_close.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -76,11 +76,11 @@ __rec_close(dbp) /* Committed to closing. */ status = RET_SUCCESS; - if (F_ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize)) + if (ISSET(t, R_MEMMAPPED) && munmap(t->bt_smap, t->bt_msize)) status = RET_ERROR; - if (!F_ISSET(t, R_INMEM)) - if (F_ISSET(t, R_CLOSEFP)) { + if (!ISSET(t, R_INMEM)) + if (ISSET(t, R_CLOSEFP)) { if (fclose(t->bt_rfp)) status = RET_ERROR; } else @@ -125,58 +125,39 @@ __rec_sync(dbp, flags) if (flags == R_RECNOSYNC) return (__bt_sync(dbp, 0)); - if (F_ISSET(t, R_RDONLY | R_INMEM) || !F_ISSET(t, R_MODIFIED)) + if (ISSET(t, R_RDONLY | R_INMEM) || !ISSET(t, R_MODIFIED)) return (RET_SUCCESS); /* Read any remaining records into the tree. */ - if (!F_ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) + if (!ISSET(t, R_EOF) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) return (RET_ERROR); /* Rewind the file descriptor. */ if (lseek(t->bt_rfd, (off_t)0, SEEK_SET) != 0) return (RET_ERROR); - /* Save the cursor. */ - scursor = t->bt_cursor.rcursor; + iov[1].iov_base = "\n"; + iov[1].iov_len = 1; + scursor = t->bt_rcursor; key.size = sizeof(recno_t); key.data = &trec; - if (F_ISSET(t, R_FIXLEN)) { - /* - * We assume that fixed length records are all fixed length. - * Any that aren't are either EINVAL'd or corrected by the - * record put code. - */ - status = (dbp->seq)(dbp, &key, &data, R_FIRST); - while (status == RET_SUCCESS) { - if (write(t->bt_rfd, data.data, data.size) != data.size) - return (RET_ERROR); - status = (dbp->seq)(dbp, &key, &data, R_NEXT); - } - } else { - iov[1].iov_base = &t->bt_bval; - iov[1].iov_len = 1; - - status = (dbp->seq)(dbp, &key, &data, R_FIRST); - while (status == RET_SUCCESS) { - iov[0].iov_base = data.data; - iov[0].iov_len = data.size; - if (writev(t->bt_rfd, iov, 2) != data.size + 1) - return (RET_ERROR); - status = (dbp->seq)(dbp, &key, &data, R_NEXT); - } - } - - /* Restore the cursor. */ - t->bt_cursor.rcursor = scursor; - + status = (dbp->seq)(dbp, &key, &data, R_FIRST); + while (status == RET_SUCCESS) { + iov[0].iov_base = data.data; + iov[0].iov_len = data.size; + if (writev(t->bt_rfd, iov, 2) != data.size + 1) + return (RET_ERROR); + status = (dbp->seq)(dbp, &key, &data, R_NEXT); + } + t->bt_rcursor = scursor; if (status == RET_ERROR) return (RET_ERROR); if ((off = lseek(t->bt_rfd, (off_t)0, SEEK_CUR)) == -1) return (RET_ERROR); if (ftruncate(t->bt_rfd, off)) return (RET_ERROR); - F_CLR(t, R_MODIFIED); + CLR(t, R_MODIFIED); return (RET_SUCCESS); } diff --git a/lib/libc/db/recno/rec_delete.c b/lib/libc/db/recno/rec_delete.c index a16593d4e6a1..35f56b999460 100644 --- a/lib/libc/db/recno/rec_delete.c +++ b/lib/libc/db/recno/rec_delete.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_delete.c 8.7 (Berkeley) 7/14/94"; +static char sccsid[] = "@(#)rec_delete.c 8.4 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -88,13 +88,13 @@ __rec_delete(dbp, key, flags) status = rec_rdelete(t, nrec); break; case R_CURSOR: - if (!F_ISSET(&t->bt_cursor, CURS_INIT)) + if (!ISSET(t, B_SEQINIT)) goto einval; if (t->bt_nrecs == 0) return (RET_SPECIAL); - status = rec_rdelete(t, t->bt_cursor.rcursor - 1); + status = rec_rdelete(t, t->bt_rcursor - 1); if (status == RET_SUCCESS) - --t->bt_cursor.rcursor; + --t->bt_rcursor; break; default: einval: errno = EINVAL; @@ -102,7 +102,7 @@ einval: errno = EINVAL; } if (status == RET_SUCCESS) - F_SET(t, B_MODIFIED | R_MODIFIED); + SET(t, B_MODIFIED | R_MODIFIED); return (status); } @@ -154,11 +154,11 @@ int __rec_dleaf(t, h, index) BTREE *t; PAGE *h; - u_int32_t index; + indx_t index; { - RLEAF *rl; - indx_t *ip, cnt, offset; - u_int32_t nbytes; + register RLEAF *rl; + register indx_t *ip, cnt, offset; + register size_t nbytes; char *from; void *to; diff --git a/lib/libc/db/recno/rec_get.c b/lib/libc/db/recno/rec_get.c index 47dd773fb97f..35555755c7ad 100644 --- a/lib/libc/db/recno/rec_get.c +++ b/lib/libc/db/recno/rec_get.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_get.c 8.9 (Berkeley) 8/18/94"; +static char sccsid[] = "@(#)rec_get.c 8.4 (Berkeley) 3/1/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -90,7 +90,7 @@ __rec_get(dbp, key, data, flags) * original file. */ if (nrec > t->bt_nrecs) { - if (F_ISSET(t, R_EOF | R_INMEM)) + if (ISSET(t, R_EOF | R_INMEM)) return (RET_SPECIAL); if ((status = t->bt_irec(t, nrec)) != RET_SUCCESS) return (status); @@ -101,7 +101,7 @@ __rec_get(dbp, key, data, flags) return (RET_ERROR); status = __rec_ret(t, e, 0, NULL, data); - if (F_ISSET(t, B_DB_LOCK)) + if (ISSET(t, B_DB_LOCK)) mpool_put(t->bt_mp, e->page, 0); else t->bt_pinned = e->page; @@ -127,38 +127,31 @@ __rec_fpipe(t, top) recno_t nrec; size_t len; int ch; - u_char *p; + char *p; - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - realloc(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) + if (t->bt_dbufsz < t->bt_reclen) { + if ((t->bt_dbuf = + (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; + t->bt_dbufsz = t->bt_reclen; } - data.data = t->bt_rdata.data; + data.data = t->bt_dbuf; data.size = t->bt_reclen; - for (nrec = t->bt_nrecs; nrec < top;) { + for (nrec = t->bt_nrecs; nrec < top; ++nrec) { len = t->bt_reclen; - for (p = t->bt_rdata.data;; *p++ = ch) - if ((ch = getc(t->bt_rfp)) == EOF || !--len) { - if (ch != EOF) - *p = ch; - if (len != 0) - memset(p, t->bt_bval, len); - if (__rec_iput(t, - nrec, &data, 0) != RET_SUCCESS) + for (p = t->bt_dbuf;; *p++ = ch) + if ((ch = getc(t->bt_rfp)) == EOF || !len--) { + if (__rec_iput(t, nrec, &data, 0) + != RET_SUCCESS) return (RET_ERROR); - ++nrec; break; } if (ch == EOF) break; } if (nrec < top) { - F_SET(t, R_EOF); + SET(t, R_EOF); return (RET_SPECIAL); } return (RET_SUCCESS); @@ -184,15 +177,14 @@ __rec_vpipe(t, top) indx_t len; size_t sz; int bval, ch; - u_char *p; + char *p; bval = t->bt_bval; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { - for (p = t->bt_rdata.data, - sz = t->bt_rdata.size;; *p++ = ch, --sz) { + for (p = t->bt_dbuf, sz = t->bt_dbufsz;; *p++ = ch, --sz) { if ((ch = getc(t->bt_rfp)) == EOF || ch == bval) { - data.data = t->bt_rdata.data; - data.size = p - (u_char *)t->bt_rdata.data; + data.data = t->bt_dbuf; + data.size = p - t->bt_dbuf; if (ch == EOF && data.size == 0) break; if (__rec_iput(t, nrec, &data, 0) @@ -201,21 +193,19 @@ __rec_vpipe(t, top) break; } if (sz == 0) { - len = p - (u_char *)t->bt_rdata.data; - t->bt_rdata.size += (sz = 256); - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_rdata.size) : - realloc(t->bt_rdata.data, t->bt_rdata.size); - if (t->bt_rdata.data == NULL) + len = p - t->bt_dbuf; + t->bt_dbufsz += (sz = 256); + if ((t->bt_dbuf = (char *)realloc(t->bt_dbuf, + t->bt_dbufsz)) == NULL) return (RET_ERROR); - p = (u_char *)t->bt_rdata.data + len; + p = t->bt_dbuf + len; } } if (ch == EOF) break; } if (nrec < top) { - F_SET(t, R_EOF); + SET(t, R_EOF); return (RET_SPECIAL); } return (RET_SUCCESS); @@ -238,36 +228,33 @@ __rec_fmap(t, top) { DBT data; recno_t nrec; - u_char *sp, *ep, *p; + caddr_t sp, ep; size_t len; + char *p; - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - realloc(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) + if (t->bt_dbufsz < t->bt_reclen) { + if ((t->bt_dbuf = + (char *)realloc(t->bt_dbuf, t->bt_reclen)) == NULL) return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; + t->bt_dbufsz = t->bt_reclen; } - data.data = t->bt_rdata.data; + data.data = t->bt_dbuf; data.size = t->bt_reclen; - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; + sp = t->bt_cmap; + ep = t->bt_emap; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { if (sp >= ep) { - F_SET(t, R_EOF); + SET(t, R_EOF); return (RET_SPECIAL); } len = t->bt_reclen; - for (p = t->bt_rdata.data; - sp < ep && len > 0; *p++ = *sp++, --len); - if (len != 0) - memset(p, t->bt_bval, len); + for (p = t->bt_dbuf; sp < ep && len--; *p++ = *sp++); + memset(p, t->bt_bval, len); if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) return (RET_ERROR); } - t->bt_cmap = (caddr_t)sp; + t->bt_cmap = sp; return (RET_SUCCESS); } @@ -287,25 +274,25 @@ __rec_vmap(t, top) recno_t top; { DBT data; - u_char *sp, *ep; + caddr_t sp, ep; recno_t nrec; int bval; - sp = (u_char *)t->bt_cmap; - ep = (u_char *)t->bt_emap; + sp = t->bt_cmap; + ep = t->bt_emap; bval = t->bt_bval; for (nrec = t->bt_nrecs; nrec < top; ++nrec) { if (sp >= ep) { - F_SET(t, R_EOF); + SET(t, R_EOF); return (RET_SPECIAL); } for (data.data = sp; sp < ep && *sp != bval; ++sp); - data.size = sp - (u_char *)data.data; + data.size = sp - (caddr_t)data.data; if (__rec_iput(t, nrec, &data, 0) != RET_SUCCESS) return (RET_ERROR); ++sp; } - t->bt_cmap = (caddr_t)sp; + t->bt_cmap = sp; return (RET_SUCCESS); } diff --git a/lib/libc/db/recno/rec_open.c b/lib/libc/db/recno/rec_open.c index 51d8a3c260fd..2a0f354227a6 100644 --- a/lib/libc/db/recno/rec_open.c +++ b/lib/libc/db/recno/rec_open.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * This code is derived from software contributed to Berkeley by @@ -35,7 +35,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_open.c 8.10 (Berkeley) 9/1/94"; +static char sccsid[] = "@(#)rec_open.c 8.6 (Berkeley) 2/22/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -98,7 +98,7 @@ __rec_open(fname, flags, mode, openinfo, dflags) t = dbp->internal; if (openinfo) { if (openinfo->flags & R_FIXEDLEN) { - F_SET(t, R_FIXLEN); + SET(t, R_FIXLEN); t->bt_reclen = openinfo->reclen; if (t->bt_reclen == 0) goto einval; @@ -107,11 +107,12 @@ __rec_open(fname, flags, mode, openinfo, dflags) } else t->bt_bval = '\n'; - F_SET(t, R_RECNO); + SET(t, R_RECNO); if (fname == NULL) - F_SET(t, R_EOF | R_INMEM); + SET(t, R_EOF | R_INMEM); else t->bt_rfd = rfd; + t->bt_rcursor = 0; if (fname != NULL) { /* @@ -123,20 +124,20 @@ __rec_open(fname, flags, mode, openinfo, dflags) if (lseek(rfd, (off_t)0, SEEK_CUR) == -1 && errno == ESPIPE) { switch (flags & O_ACCMODE) { case O_RDONLY: - F_SET(t, R_RDONLY); + SET(t, R_RDONLY); break; default: goto einval; } slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) goto err; - F_SET(t, R_CLOSEFP); + SET(t, R_CLOSEFP); t->bt_irec = - F_ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; + ISSET(t, R_FIXLEN) ? __rec_fpipe : __rec_vpipe; } else { switch (flags & O_ACCMODE) { case O_RDONLY: - F_SET(t, R_RDONLY); + SET(t, R_RDONLY); break; case O_RDWR: break; @@ -156,16 +157,8 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) * fails if the file is too large. */ if (sb.st_size == 0) - F_SET(t, R_EOF); + SET(t, R_EOF); else { -#ifdef MMAP_NOT_AVAILABLE - /* - * XXX - * Mmap doesn't work correctly on many current - * systems. In particular, it can fail subtly, - * with cache coherency problems. Don't use it - * for now. - */ t->bt_msize = sb.st_size; if ((t->bt_smap = mmap(NULL, t->bt_msize, PROT_READ, MAP_PRIVATE, rfd, @@ -173,12 +166,9 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) goto slow; t->bt_cmap = t->bt_smap; t->bt_emap = t->bt_smap + sb.st_size; - t->bt_irec = F_ISSET(t, R_FIXLEN) ? + t->bt_irec = ISSET(t, R_FIXLEN) ? __rec_fmap : __rec_vmap; - F_SET(t, R_MEMMAPPED); -#else - goto slow; -#endif + SET(t, R_MEMMAPPED); } } } @@ -196,14 +186,13 @@ slow: if ((t->bt_rfp = fdopen(rfd, "r")) == NULL) if ((h = mpool_get(t->bt_mp, P_ROOT, 0)) == NULL) goto err; if ((h->flags & P_TYPE) == P_BLEAF) { - F_CLR(h, P_TYPE); - F_SET(h, P_RLEAF); + h->flags = h->flags & ~P_TYPE | P_RLEAF; mpool_put(t->bt_mp, h, MPOOL_DIRTY); } else mpool_put(t->bt_mp, h, 0); if (openinfo && openinfo->flags & R_SNAPSHOT && - !F_ISSET(t, R_EOF | R_INMEM) && + !ISSET(t, R_EOF | R_INMEM) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) goto err; return (dbp); @@ -233,7 +222,7 @@ __rec_fd(dbp) } /* In-memory database can't have a file descriptor. */ - if (F_ISSET(t, R_INMEM)) { + if (ISSET(t, R_INMEM)) { errno = ENOENT; return (-1); } diff --git a/lib/libc/db/recno/rec_put.c b/lib/libc/db/recno/rec_put.c index 1afae0d5a675..590d45b4f919 100644 --- a/lib/libc/db/recno/rec_put.c +++ b/lib/libc/db/recno/rec_put.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_put.c 8.7 (Berkeley) 8/18/94"; +static char sccsid[] = "@(#)rec_put.c 8.3 (Berkeley) 3/1/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -66,7 +66,7 @@ __rec_put(dbp, key, data, flags) u_int flags; { BTREE *t; - DBT fdata, tdata; + DBT tdata; recno_t nrec; int status; @@ -78,38 +78,11 @@ __rec_put(dbp, key, data, flags) t->bt_pinned = NULL; } - /* - * If using fixed-length records, and the record is long, return - * EINVAL. If it's short, pad it out. Use the record data return - * memory, it's only short-term. - */ - if (F_ISSET(t, R_FIXLEN) && data->size != t->bt_reclen) { - if (data->size > t->bt_reclen) - goto einval; - - if (t->bt_rdata.size < t->bt_reclen) { - t->bt_rdata.data = t->bt_rdata.data == NULL ? - malloc(t->bt_reclen) : - realloc(t->bt_rdata.data, t->bt_reclen); - if (t->bt_rdata.data == NULL) - return (RET_ERROR); - t->bt_rdata.size = t->bt_reclen; - } - memmove(t->bt_rdata.data, data->data, data->size); - memset((char *)t->bt_rdata.data + data->size, - t->bt_bval, t->bt_reclen - data->size); - fdata.data = t->bt_rdata.data; - fdata.size = t->bt_reclen; - } else { - fdata.data = data->data; - fdata.size = data->size; - } - switch (flags) { case R_CURSOR: - if (!F_ISSET(&t->bt_cursor, CURS_INIT)) + if (!ISSET(t, B_SEQINIT)) goto einval; - nrec = t->bt_cursor.rcursor; + nrec = t->bt_rcursor; break; case R_SETCURSOR: if ((nrec = *(recno_t *)key->data) == 0) @@ -142,11 +115,11 @@ einval: errno = EINVAL; * already in the database. If skipping records, create empty ones. */ if (nrec > t->bt_nrecs) { - if (!F_ISSET(t, R_EOF | R_INMEM) && + if (!ISSET(t, R_EOF | R_INMEM) && t->bt_irec(t, nrec) == RET_ERROR) return (RET_ERROR); if (nrec > t->bt_nrecs + 1) { - if (F_ISSET(t, R_FIXLEN)) { + if (ISSET(t, R_FIXLEN)) { if ((tdata.data = (void *)malloc(t->bt_reclen)) == NULL) return (RET_ERROR); @@ -160,18 +133,18 @@ einval: errno = EINVAL; if (__rec_iput(t, t->bt_nrecs, &tdata, 0) != RET_SUCCESS) return (RET_ERROR); - if (F_ISSET(t, R_FIXLEN)) + if (ISSET(t, R_FIXLEN)) free(tdata.data); } } - if ((status = __rec_iput(t, nrec - 1, &fdata, flags)) != RET_SUCCESS) + if ((status = __rec_iput(t, nrec - 1, data, flags)) != RET_SUCCESS) return (status); if (flags == R_SETCURSOR) - t->bt_cursor.rcursor = nrec; - - F_SET(t, R_MODIFIED); + t->bt_rcursor = nrec; + + SET(t, R_MODIFIED); return (__rec_ret(t, NULL, nrec, key, NULL)); } @@ -198,7 +171,7 @@ __rec_iput(t, nrec, data, flags) PAGE *h; indx_t index, nxtindex; pgno_t pg; - u_int32_t nbytes; + size_t nbytes; int dflags, status; char *dest, db[NOVFLSIZE]; @@ -214,7 +187,7 @@ __rec_iput(t, nrec, data, flags) tdata.data = db; tdata.size = NOVFLSIZE; *(pgno_t *)db = pg; - *(u_int32_t *)(db + sizeof(pgno_t)) = data->size; + *(size_t *)(db + sizeof(pgno_t)) = data->size; dflags = P_BIGDATA; data = &tdata; } else @@ -273,7 +246,7 @@ __rec_iput(t, nrec, data, flags) WR_RLEAF(dest, data, dflags); ++t->bt_nrecs; - F_SET(t, B_MODIFIED); + SET(t, B_MODIFIED); mpool_put(t->bt_mp, h, MPOOL_DIRTY); return (RET_SUCCESS); diff --git a/lib/libc/db/recno/rec_search.c b/lib/libc/db/recno/rec_search.c index acc109e9925b..a1feff8a4173 100644 --- a/lib/libc/db/recno/rec_search.c +++ b/lib/libc/db/recno/rec_search.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_search.c 8.4 (Berkeley) 7/14/94"; +static char sccsid[] = "@(#)rec_search.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -91,8 +91,9 @@ __rec_search(t, recno, op) total += r->nrecs; } - BT_PUSH(t, pg, index - 1); - + if (__bt_push(t, pg, index - 1) == RET_ERROR) + return (NULL); + pg = r->pgno; switch (op) { case SDELETE: diff --git a/lib/libc/db/recno/rec_seq.c b/lib/libc/db/recno/rec_seq.c index f80992c5982d..56f78e764c51 100644 --- a/lib/libc/db/recno/rec_seq.c +++ b/lib/libc/db/recno/rec_seq.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1991, 1993, 1994 + * Copyright (c) 1991, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #ifndef lint -static char sccsid[] = "@(#)rec_seq.c 8.3 (Berkeley) 7/14/94"; +static char sccsid[] = "@(#)rec_seq.c 8.2 (Berkeley) 9/7/93"; #endif /* not lint */ #include <sys/types.h> @@ -82,8 +82,8 @@ __rec_seq(dbp, key, data, flags) goto einval; break; case R_NEXT: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - nrec = t->bt_cursor.rcursor + 1; + if (ISSET(t, B_SEQINIT)) { + nrec = t->bt_rcursor + 1; break; } /* FALLTHROUGH */ @@ -91,14 +91,14 @@ __rec_seq(dbp, key, data, flags) nrec = 1; break; case R_PREV: - if (F_ISSET(&t->bt_cursor, CURS_INIT)) { - if ((nrec = t->bt_cursor.rcursor - 1) == 0) + if (ISSET(t, B_SEQINIT)) { + if ((nrec = t->bt_rcursor - 1) == 0) return (RET_SPECIAL); break; } /* FALLTHROUGH */ case R_LAST: - if (!F_ISSET(t, R_EOF | R_INMEM) && + if (!ISSET(t, R_EOF | R_INMEM) && t->bt_irec(t, MAX_REC_NUMBER) == RET_ERROR) return (RET_ERROR); nrec = t->bt_nrecs; @@ -107,9 +107,9 @@ __rec_seq(dbp, key, data, flags) einval: errno = EINVAL; return (RET_ERROR); } - + if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) { - if (!F_ISSET(t, R_EOF | R_INMEM) && + if (!ISSET(t, R_EOF | R_INMEM) && (status = t->bt_irec(t, nrec)) != RET_SUCCESS) return (status); if (t->bt_nrecs == 0 || nrec > t->bt_nrecs) @@ -119,11 +119,11 @@ einval: errno = EINVAL; if ((e = __rec_search(t, nrec - 1, SEARCH)) == NULL) return (RET_ERROR); - F_SET(&t->bt_cursor, CURS_INIT); - t->bt_cursor.rcursor = nrec; + SET(t, B_SEQINIT); + t->bt_rcursor = nrec; status = __rec_ret(t, e, nrec, key, data); - if (F_ISSET(t, B_DB_LOCK)) + if (ISSET(t, B_DB_LOCK)) mpool_put(t->bt_mp, e->page, 0); else t->bt_pinned = e->page; diff --git a/lib/libc/db/recno/rec_utils.c b/lib/libc/db/recno/rec_utils.c index baea3fad5066..f7fb145024a1 100644 --- a/lib/libc/db/recno/rec_utils.c +++ b/lib/libc/db/recno/rec_utils.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1990, 1993, 1994 + * Copyright (c) 1990, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char sccsid[] = "@(#)rec_utils.c 8.6 (Berkeley) 7/16/94"; +static char sccsid[] = "@(#)rec_utils.c 8.3 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -45,14 +45,11 @@ static char sccsid[] = "@(#)rec_utils.c 8.6 (Berkeley) 7/16/94"; #include "recno.h" /* - * __rec_ret -- - * Build return data. + * __REC_RET -- Build return data as a result of search or scan. * * Parameters: * t: tree - * e: key/data pair to be returned - * nrec: record number - * key: user's key structure + * d: LEAF to be returned to the user. * data: user's data structure * * Returns: @@ -65,58 +62,53 @@ __rec_ret(t, e, nrec, key, data) recno_t nrec; DBT *key, *data; { - RLEAF *rl; - void *p; + register RLEAF *rl; + register void *p; - if (key == NULL) - goto dataonly; - - /* We have to copy the key, it's not on the page. */ - if (sizeof(recno_t) > t->bt_rkey.size) { - p = (void *)(t->bt_rkey.data == NULL ? - malloc(sizeof(recno_t)) : - realloc(t->bt_rkey.data, sizeof(recno_t))); - if (p == NULL) - return (RET_ERROR); - t->bt_rkey.data = p; - t->bt_rkey.size = sizeof(recno_t); - } - memmove(t->bt_rkey.data, &nrec, sizeof(recno_t)); - key->size = sizeof(recno_t); - key->data = t->bt_rkey.data; - -dataonly: if (data == NULL) - return (RET_SUCCESS); + goto retkey; + + rl = GETRLEAF(e->page, e->index); /* - * We must copy big keys/data to make them contigous. Otherwise, + * We always copy big data to make it contigous. Otherwise, we * leave the page pinned and don't copy unless the user specified * concurrent access. */ - rl = GETRLEAF(e->page, e->index); if (rl->flags & P_BIGDATA) { if (__ovfl_get(t, rl->bytes, - &data->size, &t->bt_rdata.data, &t->bt_rdata.size)) + &data->size, &t->bt_dbuf, &t->bt_dbufsz)) return (RET_ERROR); - data->data = t->bt_rdata.data; - } else if (F_ISSET(t, B_DB_LOCK)) { + data->data = t->bt_dbuf; + } else if (ISSET(t, B_DB_LOCK)) { /* Use +1 in case the first record retrieved is 0 length. */ - if (rl->dsize + 1 > t->bt_rdata.size) { - p = (void *)(t->bt_rdata.data == NULL ? - malloc(rl->dsize + 1) : - realloc(t->bt_rdata.data, rl->dsize + 1)); - if (p == NULL) + if (rl->dsize + 1 > t->bt_dbufsz) { + if ((p = + (void *)realloc(t->bt_dbuf, rl->dsize + 1)) == NULL) return (RET_ERROR); - t->bt_rdata.data = p; - t->bt_rdata.size = rl->dsize + 1; + t->bt_dbuf = p; + t->bt_dbufsz = rl->dsize + 1; } - memmove(t->bt_rdata.data, rl->bytes, rl->dsize); + memmove(t->bt_dbuf, rl->bytes, rl->dsize); data->size = rl->dsize; - data->data = t->bt_rdata.data; + data->data = t->bt_dbuf; } else { data->size = rl->dsize; data->data = rl->bytes; } + +retkey: if (key == NULL) + return (RET_SUCCESS); + + /* We have to copy the key, it's not on the page. */ + if (sizeof(recno_t) > t->bt_kbufsz) { + if ((p = (void *)realloc(t->bt_kbuf, sizeof(recno_t))) == NULL) + return (RET_ERROR); + t->bt_kbuf = p; + t->bt_kbufsz = sizeof(recno_t); + } + memmove(t->bt_kbuf, &nrec, sizeof(recno_t)); + key->size = sizeof(recno_t); + key->data = t->bt_kbuf; return (RET_SUCCESS); } diff --git a/lib/libc/db/test/Makefile b/lib/libc/db/test/Makefile index a5dd08ae58b8..c816432551d4 100644 --- a/lib/libc/db/test/Makefile +++ b/lib/libc/db/test/Makefile @@ -1,23 +1,17 @@ -# @(#)Makefile 8.15 (Berkeley) 7/28/94 +# @(#)Makefile 8.9 (Berkeley) 2/21/94 PROG= dbtest OBJS= dbtest.o strerror.o -# Uncomment the STAT line get hash and btree statistical use info. This -# also forces ld to load the btree debug functions for use by gdb, which -# is useful. The db library has to be compiled with -DSTATISTICS as well. -INC= -I${PORTDIR}/include -I${PORTDIR} -OORG= -g -#STAT= -DSTATISTICS -CFLAGS= -D__DBINTERFACE_PRIVATE -DDEBUG ${STAT} ${OORG} ${INC} +# Add -DSTATISTICS to CFLAGS to get btree statistical use info. +# Note, the db library has to be compiled for statistics as well. +CFLAGS= -D__DBINTERFACE_PRIVATE -DDEBUG -O ${INC} -dbtest: ${OBJS} ${PORTDIR}/libdb.a - ${CC} -o $@ ${OBJS} ${PORTDIR}/libdb.a +dbtest: ${OBJS} ${LIB} + ${CC} -o $@ ${OBJS} ${LIB} -strerror.o: ${PORTDIR}/clib/strerror.c - ${CC} -c ${PORTDIR}/clib/strerror.c +strerror.o: ../PORT/clib/strerror.c + ${CC} -c ../PORT/clib/strerror.c clean: - rm -f dbtest.core gmon.out ${OBJS} ${PROG} t1 t2 t3 - -${OBJS}: Makefile + rm -f gmon.out ${OBJS} ${PROG} t1 t2 t3 diff --git a/lib/libc/db/test/README b/lib/libc/db/test/README index 0c0cd13d8fa0..8631c77cfd85 100644 --- a/lib/libc/db/test/README +++ b/lib/libc/db/test/README @@ -1,25 +1,17 @@ -# @(#)README 8.8 (Berkeley) 7/31/94 +# @(#)README 8.2 (Berkeley) 2/21/94 To build this portably, try something like: - make PORTDIR="../PORT/MACH" + make INC="-I../PORT/MACH/ -I../PORT/MACH/include" LIB=../PORT/MACH/libdb.a where MACH is the machine, i.e. "sunos.4.1.1". To run the tests, enter "sh run.test". If your system dictionary isn't in /usr/share/dict/words, edit run.test to reflect the correct place. -Fairly large files (the command files) are built in this directory during -the test runs, and even larger files (the database files) are created in -"/var/tmp". If the latter directory doesn't exist, set the environmental -variable TMPDIR to a directory where the files can be built. - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= -The script file consists of lines with an initial character which is -the command for that line, or an initial character indicating a key -or data entry for a previous command. - -Legal command characters are as follows: +The script file consists of lines with a initial character which is +the "command" for that line. Legal characters are as follows: c: compare a record + must be followed by [kK][dD]; the data value in the database @@ -28,24 +20,17 @@ c: compare a record e: echo a string + writes out the rest of the line into the output file; if the last character is not a carriage-return, a newline is appended. -f: set the flags for the next command - + no value zero's the flags g: do a get command + must be followed by [kK] + writes out the retrieved data DBT. -o [r]: dump [reverse] - + dump the database out, if 'r' is set, in reverse order. p: do a put command + must be followed by [kK][dD] r: do a del command - + must be followed by [kK] unless R_CURSOR flag set. -S: sync the database + + must be followed by [kK] s: do a seq command - + must be followed by [kK] if R_CURSOR flag set. + writes out the retrieved data DBT. - -Legal key/data characters are as follows: - +f: set the flags for the next command + + no value zero's the flags D [file]: data file + set the current data value to the contents of the file d [data]: @@ -54,21 +39,17 @@ K [file]: key file + set the current key value to the contents of the file k [data]: + set the current key value to the contents of the line. - -Blank lines, lines with leading white space, and lines with leading -hash marks (#) are ignored. +o [r]: dump [reverse] + + dump the database out, if 'r' is set, in reverse order. Options to dbtest are as follows: - -d: Set the DB_LOCK flag. -f: Use the file argument as the database file. -i: Use the rest of the argument to set elements in the info structure. If the type is btree, then "-i cachesize=10240" will set BTREEINFO.cachesize to 10240. -o: The rest of the argument is the output file instead of using stdout. - -s: Don't delete the database file before opening it, i.e. - use the database file from a previous run. -Dbtest requires two arguments, the type of access "hash", "recno" -or "btree", and the script name or "-" to indicate stdin. +Dbtest requires two arguments, the type of access "hash", "recno" or +"btree", and the script name. diff --git a/lib/libc/db/test/dbtest.c b/lib/libc/db/test/dbtest.c index 4341b4c4709c..c526415a7a09 100644 --- a/lib/libc/db/test/dbtest.c +++ b/lib/libc/db/test/dbtest.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1992, 1993, 1994 + * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -33,12 +33,12 @@ #ifndef lint static char copyright[] = -"@(#) Copyright (c) 1992, 1993, 1994\n\ +"@(#) Copyright (c) 1992, 1993\n\ The Regents of the University of California. All rights reserved.\n"; #endif /* not lint */ #ifndef lint -static char sccsid[] = "@(#)dbtest.c 8.17 (Berkeley) 9/1/94"; +static char sccsid[] = "@(#)dbtest.c 8.8 (Berkeley) 2/21/94"; #endif /* not lint */ #include <sys/param.h> @@ -65,8 +65,6 @@ void get __P((DB *, DBT *)); void getdata __P((DB *, DBT *, DBT *)); void put __P((DB *, DBT *, DBT *)); void rem __P((DB *, DBT *)); -char *sflags __P((int)); -void synk __P((DB *)); void *rfile __P((char *, size_t *)); void seq __P((DB *, DBT *)); u_int setflags __P((char *)); @@ -74,14 +72,13 @@ void *setinfo __P((DBTYPE, char *)); void usage __P((void)); void *xmalloc __P((char *, size_t)); -DBTYPE type; /* Database type. */ -void *infop; /* Iflags. */ -u_long lineno; /* Current line in test script. */ -u_int flags; /* Current DB flags. */ -int ofd = STDOUT_FILENO; /* Standard output fd. */ +DBTYPE type; +void *infop; +u_long lineno; +u_int flags; +int ofd = STDOUT_FILENO; DB *XXdbp; /* Global for gdb. */ -int XXlineno; /* Fast breakpoint for gdb. */ int main(argc, argv) @@ -94,15 +91,14 @@ main(argc, argv) DB *dbp; DBT data, key, keydata; size_t len; - int ch, oflags, sflag; - char *fname, *infoarg, *p, *t, buf[8 * 1024]; + int ch, oflags; + char *fname, *infoarg, *p, buf[8 * 1024]; infoarg = NULL; fname = NULL; oflags = O_CREAT | O_RDWR; - sflag = 0; - while ((ch = getopt(argc, argv, "f:i:lo:s")) != EOF) - switch (ch) { + while ((ch = getopt(argc, argv, "f:i:lo:")) != EOF) + switch(ch) { case 'f': fname = optarg; break; @@ -117,9 +113,6 @@ main(argc, argv) O_WRONLY|O_CREAT|O_TRUNC, 0666)) < 0) err("%s: %s", optarg, strerror(errno)); break; - case 's': - sflag = 1; - break; case '?': default: usage(); @@ -134,8 +127,8 @@ main(argc, argv) type = dbtype(*argv++); /* Open the descriptor file. */ - if (strcmp(*argv, "-") && freopen(*argv, "r", stdin) == NULL) - err("%s: %s", *argv, strerror(errno)); + if (freopen(*argv, "r", stdin) == NULL) + err("%s: %s", *argv, strerror(errno)); /* Set up the db structure as necessary. */ if (infoarg == NULL) @@ -146,10 +139,7 @@ main(argc, argv) if (*p != '\0') infop = setinfo(type, p); - /* - * Open the DB. Delete any preexisting copy, you almost never - * want it around, and it often screws up tests. - */ + /* Open the DB. */ if (fname == NULL) { p = getenv("TMPDIR"); if (p == NULL) @@ -157,9 +147,7 @@ main(argc, argv) (void)sprintf(buf, "%s/__dbtest", p); fname = buf; (void)unlink(buf); - } else if (!sflag) - (void)unlink(fname); - + } if ((dbp = dbopen(fname, oflags, S_IRUSR | S_IWUSR, type, infop)) == NULL) err("dbopen: %s", strerror(errno)); @@ -168,16 +156,8 @@ main(argc, argv) state = COMMAND; for (lineno = 1; (p = fgets(buf, sizeof(buf), stdin)) != NULL; ++lineno) { - /* Delete the newline, displaying the key/data is easier. */ - if (ofd == STDOUT_FILENO && (t = strchr(p, '\n')) != NULL) - *t = '\0'; - if ((len = strlen(buf)) == 0 || isspace(*p) || *p == '#') - continue; - - /* Convenient gdb break point. */ - if (XXlineno == lineno) - XXlineno = 1; - switch (*p) { + len = strlen(buf); + switch(*p) { case 'c': /* compare */ if (state != COMMAND) err("line %lu: not expecting command", lineno); @@ -190,8 +170,7 @@ main(argc, argv) /* Don't display the newline, if CR at EOL. */ if (p[len - 2] == '\r') --len; - if (write(ofd, p + 1, len - 1) != len - 1 || - write(ofd, "\n", 1) != 1) + if (write(ofd, p + 1, len - 1) != len - 1) err("write: %s", strerror(errno)); break; case 'g': /* get */ @@ -209,19 +188,8 @@ main(argc, argv) case 'r': /* remove */ if (state != COMMAND) err("line %lu: not expecting command", lineno); - if (flags == R_CURSOR) { - rem(dbp, &key); - state = COMMAND; - } else { - state = KEY; - command = REMOVE; - } - break; - case 'S': /* sync */ - if (state != COMMAND) - err("line %lu: not expecting command", lineno); - synk(dbp); - state = COMMAND; + state = KEY; + command = REMOVE; break; case 's': /* seq */ if (state != COMMAND) @@ -245,7 +213,7 @@ main(argc, argv) err("line %lu: not expecting data", lineno); data.data = xmalloc(p + 1, len - 1); data.size = len - 1; -ldata: switch (command) { +ldata: switch(command) { case COMPARE: compare(&keydata, &data); break; @@ -281,7 +249,7 @@ ldata: switch (command) { key.data = xmalloc(p + 1, len - 1); key.size = len - 1; } -lkey: switch (command) { +lkey: switch(command) { case COMPARE: getdata(dbp, &key, &keydata); state = DATA; @@ -297,13 +265,13 @@ lkey: switch (command) { break; case REMOVE: rem(dbp, &key); - if ((type != DB_RECNO) && (flags != R_CURSOR)) + if (type != DB_RECNO) free(key.data); state = COMMAND; break; case SEQ: seq(dbp, &key); - if ((type != DB_RECNO) && (flags != R_CURSOR)) + if (type != DB_RECNO) free(key.data); state = COMMAND; break; @@ -317,15 +285,11 @@ lkey: switch (command) { break; default: err("line %lu: %s: unknown command character", - lineno, p); + p, lineno); } } #ifdef STATISTICS - /* - * -l must be used (DB_LOCK must be set) for this to be - * used, otherwise a page will be locked and it will fail. - */ - if (type == DB_BTREE && oflags & DB_LOCK) + if (type == DB_BTREE) __bt_stat(dbp); #endif if (dbp->close(dbp)) @@ -335,6 +299,7 @@ lkey: switch (command) { } #define NOOVERWRITE "put failed, would overwrite key\n" +#define NOSUCHKEY "get failed, no such key\n" void compare(db1, db2) @@ -363,23 +328,17 @@ get(dbp, kp) { DBT data; - switch (dbp->get(dbp, kp, &data, flags)) { + switch(dbp->get(dbp, kp, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); - if (ofd == STDOUT_FILENO) - (void)write(ofd, "\n", 1); break; case -1: err("line %lu: get: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: -#define NOSUCHKEY "get failed, no such key\n" - if (ofd != STDOUT_FILENO) - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); - else - (void)fprintf(stderr, "%d: %.*s: %s", - lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); -#undef NOSUCHKEY + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); + (void)fprintf(stderr, "%d: %.*s: %s\n", + lineno, kp->size, kp->data, NOSUCHKEY); break; } } @@ -389,14 +348,14 @@ getdata(dbp, kp, dp) DB *dbp; DBT *kp, *dp; { - switch (dbp->get(dbp, kp, dp, flags)) { + switch(dbp->get(dbp, kp, dp, flags)) { case 0: return; case -1: err("line %lu: getdata: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: - err("line %lu: getdata failed, no such key", lineno); + err("line %lu: get failed, no such key", lineno); /* NOTREACHED */ } } @@ -406,7 +365,7 @@ put(dbp, kp, dp) DB *dbp; DBT *kp, *dp; { - switch (dbp->put(dbp, kp, dp, flags)) { + switch(dbp->put(dbp, kp, dp, flags)) { case 0: break; case -1: @@ -423,67 +382,34 @@ rem(dbp, kp) DB *dbp; DBT *kp; { - switch (dbp->del(dbp, kp, flags)) { + switch(dbp->del(dbp, kp, flags)) { case 0: break; case -1: - err("line %lu: rem: %s", lineno, strerror(errno)); + err("line %lu: get: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: -#define NOSUCHKEY "rem failed, no such key\n" - if (ofd != STDOUT_FILENO) - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); - else if (flags != R_CURSOR) - (void)fprintf(stderr, "%d: %.*s: %s", - lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); - else - (void)fprintf(stderr, - "%d: rem of cursor failed\n", lineno); -#undef NOSUCHKEY + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); break; } } void -synk(dbp) - DB *dbp; -{ - switch (dbp->sync(dbp, flags)) { - case 0: - break; - case -1: - err("line %lu: synk: %s", lineno, strerror(errno)); - /* NOTREACHED */ - } -} - -void seq(dbp, kp) DB *dbp; DBT *kp; { DBT data; - switch (dbp->seq(dbp, kp, &data, flags)) { + switch(dbp->seq(dbp, kp, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); - if (ofd == STDOUT_FILENO) - (void)write(ofd, "\n", 1); break; case -1: err("line %lu: seq: %s", lineno, strerror(errno)); /* NOTREACHED */ case 1: -#define NOSUCHKEY "seq failed, no such key\n" - if (ofd != STDOUT_FILENO) - (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); - else if (flags == R_CURSOR) - (void)fprintf(stderr, "%d: %.*s: %s", - lineno, MIN(kp->size, 20), kp->data, NOSUCHKEY); - else - (void)fprintf(stderr, - "%d: seq (%s) failed\n", lineno, sflags(flags)); -#undef NOSUCHKEY + (void)write(ofd, NOSUCHKEY, sizeof(NOSUCHKEY) - 1); break; } } @@ -504,11 +430,9 @@ dump(dbp, rev) nflags = R_NEXT; } for (;; flags = nflags) - switch (dbp->seq(dbp, &key, &data, flags)) { + switch(dbp->seq(dbp, &key, &data, flags)) { case 0: (void)write(ofd, data.data, data.size); - if (ofd == STDOUT_FILENO) - (void)write(ofd, "\n", 1); break; case 1: goto done; @@ -519,7 +443,7 @@ dump(dbp, rev) } done: return; } - + u_int setflags(s) char *s; @@ -527,43 +451,32 @@ setflags(s) char *p, *index(); for (; isspace(*s); ++s); - if (*s == '\n' || *s == '\0') + if (*s == '\n') return (0); if ((p = index(s, '\n')) != NULL) *p = '\0'; - if (!strcmp(s, "R_CURSOR")) return (R_CURSOR); - if (!strcmp(s, "R_FIRST")) return (R_FIRST); - if (!strcmp(s, "R_IAFTER")) return (R_IAFTER); - if (!strcmp(s, "R_IBEFORE")) return (R_IBEFORE); - if (!strcmp(s, "R_LAST")) return (R_LAST); - if (!strcmp(s, "R_NEXT")) return (R_NEXT); - if (!strcmp(s, "R_NOOVERWRITE")) return (R_NOOVERWRITE); - if (!strcmp(s, "R_PREV")) return (R_PREV); - if (!strcmp(s, "R_SETCURSOR")) return (R_SETCURSOR); - + if (!strcmp(s, "R_CURSOR")) + return (R_CURSOR); + if (!strcmp(s, "R_FIRST")) + return (R_FIRST); + if (!strcmp(s, "R_IAFTER")) + return (R_IAFTER); + if (!strcmp(s, "R_IBEFORE")) + return (R_IBEFORE); + if (!strcmp(s, "R_LAST")) + return (R_LAST); + if (!strcmp(s, "R_NEXT")) + return (R_NEXT); + if (!strcmp(s, "R_NOOVERWRITE")) + return (R_NOOVERWRITE); + if (!strcmp(s, "R_PREV")) + return (R_PREV); + if (!strcmp(s, "R_SETCURSOR")) + return (R_SETCURSOR); err("line %lu: %s: unknown flag", lineno, s); /* NOTREACHED */ } -char * -sflags(flags) - int flags; -{ - switch (flags) { - case R_CURSOR: return ("R_CURSOR"); - case R_FIRST: return ("R_FIRST"); - case R_IAFTER: return ("R_IAFTER"); - case R_IBEFORE: return ("R_IBEFORE"); - case R_LAST: return ("R_LAST"); - case R_NEXT: return ("R_NEXT"); - case R_NOOVERWRITE: return ("R_NOOVERWRITE"); - case R_PREV: return ("R_PREV"); - case R_SETCURSOR: return ("R_SETCURSOR"); - } - - return ("UNKNOWN!"); -} - DBTYPE dbtype(s) char *s; @@ -593,8 +506,8 @@ setinfo(type, s) *eq++ = '\0'; if (!isdigit(*eq)) err("%s: structure set statement must be a number", s); - - switch (type) { + + switch(type) { case DB_BTREE: if (!strcmp("flags", s)) { ib.flags = atoi(eq); diff --git a/lib/libc/db/test/run.test b/lib/libc/db/test/run.test index 52b74c316199..5eeaf743dd68 100644 --- a/lib/libc/db/test/run.test +++ b/lib/libc/db/test/run.test @@ -1,26 +1,19 @@ #!/bin/sh - # -# @(#)run.test 8.10 (Berkeley) 7/26/94 +# @(#)run.test 8.7 (Berkeley) 9/16/93 # # db regression tests main() { - PROG=./dbtest - TMP1=t1 - TMP2=t2 - TMP3=t3 +DICT=/usr/share/dict/words +#DICT=/usr/dict/words +PROG=./dbtest +TMP1=t1 +TMP2=t2 +TMP3=t3 - if [ -f /usr/share/dict/words ]; then - DICT=/usr/share/dict/words - elif [ -f /usr/dict/words ]; then - DICT=/usr/dict/words - else - echo 'run.test: no dictionary' - exit 1 - fi - if [ $# -eq 0 ]; then for t in 1 2 3 4 5 6 7 8 9 10 11 12 13 20; do test$t @@ -352,7 +345,7 @@ test7() for (i = 1; i <= 120; ++i) printf("%05d: input key %d: %s\n", i, i, $0); printf("%05d: input key %d: %s\n", 120, 120, $0); - printf("seq failed, no such key\n"); + printf("get failed, no such key\n"); printf("%05d: input key %d: %s\n", 1, 1, $0); printf("%05d: input key %d: %s\n", 2, 2, $0); exit; @@ -371,10 +364,10 @@ test7() for (i = 1; i <= 120; ++i) printf("s\n"); printf("fR_CURSOR\ns\nk120\n"); - printf("r\n"); + printf("r\nk120\n"); printf("fR_NEXT\ns\n"); printf("fR_CURSOR\ns\nk1\n"); - printf("r\n"); + printf("r\nk1\n"); printf("fR_FIRST\ns\n"); }' > $TMP2 $PROG -o $TMP3 recno $TMP2 @@ -399,11 +392,13 @@ test8() if (i % 8 == 0) { printf("c\nkkey2\nD/bin/csh\n"); printf("c\nkkey1\nD/bin/sh\n"); - printf("e\t%d of 10 (comparison)\n", i); + printf("e\t%d of 10 (comparison)\r\n", i); } else - printf("e\t%d of 10 \n", i); + printf("e\t%d of 10 \r\n", i); printf("r\nkkey1\nr\nkkey2\n"); } + printf("e\n"); + printf("eend of test8 run\n"); }' > $TMP1 $PROG btree $TMP1 # $PROG hash $TMP1 @@ -464,7 +459,7 @@ test10() printf("p\nk%d\nd%s\n", ++i, $0); } END { - printf("fR_CURSOR\nr\n"); + printf("fR_CURSOR\nr\nk1\n"); printf("eR_CURSOR SHOULD HAVE FAILED\n"); }' > $TMP2 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1 @@ -578,8 +573,7 @@ test13() echo g echo k$i done > $TMP2 - $PROG -s \ - -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 + $PROG -ilorder=$order -f byte.file -o $TMP3 $type $TMP2 if (cmp -s $TMP1 $TMP3) ; then : else echo "test13: $type/$order get failed" diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc index c4fa5140f7e8..f91be48502df 100644 --- a/lib/libc/gen/Makefile.inc +++ b/lib/libc/gen/Makefile.inc @@ -19,7 +19,7 @@ SRCS+= alarm.c assert.c clock.c closedir.c config.c confstr.c crypt.c \ sigsetops.c sleep.c sysconf.c sysctl.c syslog.c \ telldir.c termios.c time.c times.c timezone.c ttyname.c ttyslot.c \ ualarm.c uname.c unvis.c usleep.c utime.c valloc.c vis.c wait.c \ - wait3.c waitpid.c _thread_init.c + wait3.c waitpid.c # *rand48 family, from 1.1.5 SRCS+= _rand48.c drand48.c erand48.c jrand48.c lcong48.c lrand48.c \ @@ -46,9 +46,7 @@ MAN3+= gen/alarm.3 gen/clock.3 gen/confstr.3 gen/config_open.3 \ gen/getmntinfo.3 gen/getnetgrent.3 gen/getpagesize.3 gen/getpass.3 \ gen/getpwent.3 gen/getttyent.3 gen/getvfsent.3 gen/getusershell.3 \ gen/glob.3 \ - gen/initgroups.3 gen/isinf.3 gen/ldexp.3 \ - gen/msgctl.3 gen/msgget.3 gen/msgrcv.3 gen/msgsnd.3 \ - gen/modf.3 gen/nice.3 \ + gen/initgroups.3 gen/isinf.3 gen/ldexp.3 gen/modf.3 gen/nice.3 \ gen/nlist.3 gen/pause.3 gen/popen.3 gen/psignal.3 gen/pwcache.3 \ gen/raise.3 gen/rand48.3 gen/scandir.3 gen/setjmp.3 gen/setmode.3 \ gen/siginterrupt.3 gen/signal.3 gen/sigsetops.3 gen/sleep.3 \ @@ -59,16 +57,14 @@ MAN3+= gen/alarm.3 gen/clock.3 gen/confstr.3 gen/config_open.3 \ MLINKS+=config_open.3 config_next.3 config_open.3 config_close.3 \ config_open.3 config_skip.3 -MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 crypt.3 des_setkey.3 \ - crypt.3 des_cipher.3 +MLINKS+=crypt.3 encrypt.3 crypt.3 setkey.3 MLINKS+=directory.3 closedir.3 directory.3 dirfd.3 directory.3 opendir.3 \ directory.3 readdir.3 directory.3 rewinddir.3 directory.3 seekdir.3 \ directory.3 telldir.3 MLINKS+=exec.3 execl.3 exec.3 execle.3 exec.3 execlp.3 exec.3 execv.3 \ - exec.3 execvp.3 exec.3 exect.3 + exec.3 execvp.3 MLINKS+=err.3 verr.3 err.3 errx.3 err.3 verrx.3 err.3 warn.3 err.3 vwarn.3 \ - err.3 warnx.3 err.3 vwarnx.3 err.3 err_set_file.3 \ - err.3 err_set_exit.3 + err.3 warnx.3 err.3 vwarnx.3 MLINKS+=isinf.3 isnan.3 MLINKS+=getcap.3 cgetcap.3 getcap.3 cgetclose.3 getcap.3 cgetent.3 \ getcap.3 cgetfirst.3 getcap.3 cgetmatch.3 getcap.3 cgetnext.3 \ @@ -92,7 +88,7 @@ MLINKS+=getvfsent.3 getvfsbyname.3 getvfsent.3 getvfsbytype.3 \ MLINKS+=getusershell.3 endusershell.3 getusershell.3 setusershell.3 MLINKS+=glob.3 globfree.3 MLINKS+=popen.3 pclose.3 -MLINKS+=psignal.3 sys_siglist.3 psignal.3 sys_signame.3 +MLINKS+=psignal.3 sys_siglist.3 MLINKS+=pwcache.3 user_from_uid.3 pwcache.3 group_from_gid.3 MLINKS+=rand48.3 _rand48.3 rand48.3 drand48.3 rand48.3 erand48.3 \ rand48.3 jrand48.3 rand48.3 lcong48.3 rand48.3 lrand48.3 \ @@ -116,6 +112,3 @@ MLINKS+=tcsetattr.3 tcgetattr.3 tcsetattr.3 cfsetospeed.3 \ MLINKS+=ttyname.3 isatty.3 ttyname.3 ttyslot.3 MLINKS+=tzset.3 tzsetwall.3 MLINKS+=vis.3 strvis.3 vis.3 strvisx.3 -MLINKS+=unvis.3 strunvis.3 -MLINKS+=fts.3 fts_open.3 fts.3 fts_read.3 fts.3 fts_children.3 \ - fts.3 fts_close.3 diff --git a/lib/libc/gen/assert.c b/lib/libc/gen/assert.c index eb2748ce6d44..4914acac157f 100644 --- a/lib/libc/gen/assert.c +++ b/lib/libc/gen/assert.c @@ -35,6 +35,7 @@ static char sccsid[] = "@(#)assert.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> #include <assert.h> #include <stdio.h> #include <stdlib.h> diff --git a/lib/libc/gen/confstr.c b/lib/libc/gen/confstr.c index 0a7078e7f347..cc4df538c40b 100644 --- a/lib/libc/gen/confstr.c +++ b/lib/libc/gen/confstr.c @@ -42,7 +42,6 @@ static char sccsid[] = "@(#)confstr.c 8.1 (Berkeley) 6/4/93"; #include <paths.h> #include <stdlib.h> #include <unistd.h> -#include <string.h> size_t confstr(name, buf, len) diff --git a/lib/libc/gen/crypt.c b/lib/libc/gen/crypt.c index c1417b8e4a61..59cb92008dbe 100644 --- a/lib/libc/gen/crypt.c +++ b/lib/libc/gen/crypt.c @@ -36,12 +36,11 @@ #if defined(LIBC_SCCS) && !defined(lint) /* from static char sccsid[] = "@(#)crypt.c 5.11 (Berkeley) 6/25/91"; */ -static char rcsid[] = "$Header: /home/ncvs/src/lib/libc/gen/crypt.c,v 1.3 1995/05/30 05:40:10 rgrimes Exp $"; +static char rcsid[] = "$Header: /pub/FreeBSD/FreeBSD-CVS/src/lib/libc/gen/crypt.c,v 1.3 1995/05/30 05:40:10 rgrimes Exp $"; #endif /* LIBC_SCCS and not lint */ #include <unistd.h> #include <stdio.h> -#include <string.h> /* * UNIX password, and DES, encryption. @@ -50,10 +49,6 @@ static char rcsid[] = "$Header: /home/ncvs/src/lib/libc/gen/crypt.c,v 1.3 1995/0 * encryption, make sure you've got libcrypt.a around. */ -__warn_references(des_setkey, - "WARNING! des_setkey(3) not present in the system!"); - -int des_setkey(key) register const char *key; { @@ -61,10 +56,6 @@ des_setkey(key) return (0); } -__warn_references(des_cipher, - "WARNING! des_cipher(3) not present in the system!"); - -int des_cipher(in, out, salt, num_iter) const char *in; char *out; @@ -76,10 +67,6 @@ des_cipher(in, out, salt, num_iter) return (0); } -__warn_references(setkey, - "WARNING! setkey(3) not present in the system!"); - -int setkey(key) register const char *key; { @@ -87,10 +74,6 @@ setkey(key) return (0); } -__warn_references(encrypt, - "WARNING! encrypt(3) not present in the system!"); - -int encrypt(block, flag) register char *block; int flag; diff --git a/lib/libc/gen/daemon.3 b/lib/libc/gen/daemon.3 index 97646d7855f2..1905923a66f7 100644 --- a/lib/libc/gen/daemon.3 +++ b/lib/libc/gen/daemon.3 @@ -37,7 +37,6 @@ .Nm daemon .Nd run in the background .Sh SYNOPSIS -.Fd #include <stdlib.h> .Fn daemon "int nochdir" "int noclose" .Sh DESCRIPTION .Pp diff --git a/lib/libc/gen/disklabel.c b/lib/libc/gen/disklabel.c index ac2894e3bd07..cc4c3dff45a6 100644 --- a/lib/libc/gen/disklabel.c +++ b/lib/libc/gen/disklabel.c @@ -32,11 +32,7 @@ */ #ifndef lint -#if 0 -static char sccsid[] = "@(#)disklabel.c 8.2 (Berkeley) 5/3/95"; -#endif -static const char rcsid[] = - "$Id$"; +static char sccsid[] = "@(#)disklabel.c 8.1 (Berkeley) 6/4/93"; #endif /* not lint */ #include <sys/param.h> @@ -50,8 +46,8 @@ static const char rcsid[] = #include <stdlib.h> #include <string.h> #include <unistd.h> -#include <ctype.h> +static int error __P((int)); static int gettype __P((char *, char **)); struct disklabel * @@ -66,7 +62,7 @@ getdiskbyname(name) char *cp, *cq; /* can't be register */ char p, max, psize[3], pbsize[3], pfsize[3], poffset[3], ptype[3]; - u_int32_t *dx; + u_long *dx; if (cgetent(&buf, db_array, (char *) name) < 0) return NULL; @@ -171,3 +167,17 @@ gettype(t, names) return (atoi(t)); return (0); } + +static int +error(err) + int err; +{ + char *p; + + (void)write(STDERR_FILENO, "disktab: ", 9); + (void)write(STDERR_FILENO, _PATH_DISKTAB, sizeof(_PATH_DISKTAB) - 1); + (void)write(STDERR_FILENO, ": ", 2); + p = strerror(err); + (void)write(STDERR_FILENO, p, strlen(p)); + (void)write(STDERR_FILENO, "\n", 1); +} diff --git a/lib/libc/gen/exec.3 b/lib/libc/gen/exec.3 index 367d71ae86d6..bda6e9e6169f 100644 --- a/lib/libc/gen/exec.3 +++ b/lib/libc/gen/exec.3 @@ -185,7 +185,7 @@ The return value is \-1, and the global variable .Va errno will be set to indicate the error. .Sh FILES -.Bl -tag -width /bin/sh -compact +.Bl -tag -width /bin/sh - compact .It Pa /bin/sh The shell. .El diff --git a/lib/libc/gen/fstab.c b/lib/libc/gen/fstab.c index a5260687149a..47ad477afbd5 100644 --- a/lib/libc/gen/fstab.c +++ b/lib/libc/gen/fstab.c @@ -46,10 +46,10 @@ static FILE *_fs_fp; static struct fstab _fs_fstab; static int LineNo = 0; -static void error __P((int)); -static int fstabscan __P((void)); +static error __P((int)); +static fstabscan __P((void)); -static int +static fstabscan() { char *cp, *p; @@ -77,9 +77,9 @@ fstabscan() _fs_fstab.fs_vfstype = strcmp(_fs_fstab.fs_type, FSTAB_SW) ? "ufs" : "swap"; - if ((cp = strsep(&p, ":\n")) != NULL) { + if (cp = strsep(&p, ":\n")) { _fs_fstab.fs_freq = atoi(cp); - if ((cp = strsep(&p, ":\n")) != NULL) { + if (cp = strsep(&p, ":\n")) { _fs_fstab.fs_passno = atoi(cp); return(1); } @@ -157,7 +157,7 @@ bad: /* no way to distinguish between EOF and syntax error */ struct fstab * getfsent() { - if ((!_fs_fp && !setfsent()) || !fstabscan()) + if (!_fs_fp && !setfsent() || !fstabscan()) return((struct fstab *)NULL); return(&_fs_fstab); } @@ -184,7 +184,6 @@ getfsfile(name) return((struct fstab *)NULL); } -int setfsent() { if (_fs_fp) { @@ -192,7 +191,7 @@ setfsent() LineNo = 0; return(1); } - if ((_fs_fp = fopen(_PATH_FSTAB, "r")) != NULL) { + if (_fs_fp = fopen(_PATH_FSTAB, "r")) { LineNo = 0; return(1); } @@ -209,7 +208,7 @@ endfsent() } } -static void +static error(err) int err; { diff --git a/lib/libc/gen/getbsize.3 b/lib/libc/gen/getbsize.3 index b4390390eab2..045557304eae 100644 --- a/lib/libc/gen/getbsize.3 +++ b/lib/libc/gen/getbsize.3 @@ -75,5 +75,5 @@ a block size of 512 bytes. .Sh HISTORY The .Nm getbsize -function first appeared in +function call appeared in .Bx 4.4 . diff --git a/lib/libc/gen/getcap.3 b/lib/libc/gen/getcap.3 index e29437fb0488..c423a98f54bc 100644 --- a/lib/libc/gen/getcap.3 +++ b/lib/libc/gen/getcap.3 @@ -73,7 +73,7 @@ .Fn cgetclose "void" .Sh DESCRIPTION .Fn Cgetent -extracts the capability +extracts the capability rec .Fa name from the database specified by the .Dv NULL diff --git a/lib/libc/gen/getcap.c b/lib/libc/gen/getcap.c index 93d195267fc5..6bb44506ecbb 100644 --- a/lib/libc/gen/getcap.c +++ b/lib/libc/gen/getcap.c @@ -192,6 +192,7 @@ getent(cap, len, db_array, fd, name, depth, nfield) int fd, depth; { DB *capdbp; + DBT key, data; register char *r_end, *rp, **db_p; int myfd, eof, foundit, retval, clen; char *record, *cbuf; @@ -541,6 +542,8 @@ cdbget(capdbp, bp, name) char **bp, *name; { DBT key, data; + char *buf; + int st; key.data = name; key.size = strlen(name); diff --git a/lib/libc/gen/getcwd.3 b/lib/libc/gen/getcwd.3 index 8b385be52957..8740a75986a0 100644 --- a/lib/libc/gen/getcwd.3 +++ b/lib/libc/gen/getcwd.3 @@ -35,8 +35,7 @@ .Dt GETCWD 3 .Os BSD 4.2 .Sh NAME -.Nm getcwd , -.Nm getwd +.Nm getcwd .Nd get working directory pathname .Sh SYNOPSIS .Fd #include <unistd.h> diff --git a/lib/libc/gen/getfsent.3 b/lib/libc/gen/getfsent.3 index 1cc90bf99376..105183798062 100644 --- a/lib/libc/gen/getfsent.3 +++ b/lib/libc/gen/getfsent.3 @@ -43,7 +43,7 @@ .Nd get file system descriptor file entry .Sh SYNOPSIS .Fd #include <fstab.h> -.Ft struct fstab * +.Ft fstab * .Fn getfsent void .Ft struct fstab * .Fn getfsspec "const char *spec" diff --git a/lib/libc/gen/getgrent.3 b/lib/libc/gen/getgrent.3 index 4b02c85becc4..e9bd284312ad 100644 --- a/lib/libc/gen/getgrent.3 +++ b/lib/libc/gen/getgrent.3 @@ -53,7 +53,7 @@ .Fn getgrnam "const char *name" .Ft struct group * .Fn getgrgid "gid_t gid" -.Ft int +.Ft struct group * .Fn setgroupent "int stayopen" .\" .Ft void .\" .Fn setgrfile "const char *name" diff --git a/lib/libc/gen/getgrent.c b/lib/libc/gen/getgrent.c index 6451dc997f22..9ba9a717e54a 100644 --- a/lib/libc/gen/getgrent.c +++ b/lib/libc/gen/getgrent.c @@ -163,7 +163,7 @@ start_gr() char *line; size_t linelen; _gr_yp_enabled = 0; - while((line = fgetln(_gr_fp, &linelen)) != NULL) { + while(line = fgetln(_gr_fp, &linelen)) { if(line[0] == '+') { if(line[1] && !_gr_yp_enabled) { _gr_yp_enabled = 1; @@ -301,7 +301,6 @@ grscan(search, gid, name) return(1); } /* NOTREACHED */ - return (0); } #ifdef YP @@ -426,8 +425,7 @@ unpack: strcpy(resultbuf, result); free(result); - if((result = strchr(resultbuf, '\n')) != NULL) - *result = '\0'; + if(result = strchr(resultbuf, '\n')) *result = '\0'; if (_gr_breakout_yp(gr, resultbuf)) return(1); else diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c index c65e1fa6eb9a..10c4df76f3e8 100644 --- a/lib/libc/gen/getgrouplist.c +++ b/lib/libc/gen/getgrouplist.c @@ -50,6 +50,7 @@ getgrouplist(uname, agroup, groups, grpcnt) int *grpcnt; { register struct group *grp; + register struct passwd *pw; register int i, ngroups; int ret, maxgroups; diff --git a/lib/libc/gen/getpagesize.c b/lib/libc/gen/getpagesize.c index 556ff9e032da..d586cf68d534 100644 --- a/lib/libc/gen/getpagesize.c +++ b/lib/libc/gen/getpagesize.c @@ -38,24 +38,16 @@ static char sccsid[] = "@(#)getpagesize.c 8.1 (Berkeley) 6/4/93"; #include <sys/param.h> #include <sys/sysctl.h> -/* - * This is unlikely to change over the running time of any - * program, so we cache the result to save some syscalls. - */ - int getpagesize() { - int mib[2]; - static int value; + int mib[2], value; size_t size; - if (!value) { - mib[0] = CTL_HW; - mib[1] = HW_PAGESIZE; - size = sizeof value; - if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) - return (-1); - } + mib[0] = CTL_HW; + mib[1] = HW_PAGESIZE; + size = sizeof value; + if (sysctl(mib, 2, &value, &size, NULL, 0) == -1) + return (-1); return (value); } diff --git a/lib/libc/gen/getpass.3 b/lib/libc/gen/getpass.3 index 6582ddd10186..f312d42b8f5a 100644 --- a/lib/libc/gen/getpass.3 +++ b/lib/libc/gen/getpass.3 @@ -64,7 +64,7 @@ turns off character echoing while reading the password. .Nm Getpass returns a pointer to the null terminated password. .Sh FILES -.Bl -tag -width /dev/tty -compact +.Bl -tag -width /dev/tty - compact .It Pa /dev/tty .El .Sh SEE ALSO diff --git a/lib/libc/gen/getpass.c b/lib/libc/gen/getpass.c index 658f5b6d6ab3..f6391a190433 100644 --- a/lib/libc/gen/getpass.c +++ b/lib/libc/gen/getpass.c @@ -36,54 +36,23 @@ static char sccsid[] = "@(#)getpass.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/termios.h> -#include <signal.h> +#include <sys/signal.h> #include <paths.h> #include <pwd.h> #include <stdio.h> #include <unistd.h> -static struct termios oterm, term; -static sig_t ointhandler, oquithandler, otstphandler, oconthandler; -static FILE *fp; - -static void -sighandler(int signo) -{ - /* restore tty state */ - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm); - - /* restore old sig handlers */ - (void)signal(SIGINT, ointhandler); - (void)signal(SIGQUIT, oquithandler); - (void)signal(SIGTSTP, otstphandler); - - /* resend us this signal */ - (void)kill(getpid(), signo); -} - -/* ARGSUSED */ -static void -sigconthandler(int signo) -{ - /* re-install our signal handlers */ - ointhandler = signal(SIGINT, sighandler); - oquithandler = signal(SIGQUIT, sighandler); - otstphandler = signal(SIGTSTP, sighandler); - - /* turn off echo again */ - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); -} - - char * getpass(prompt) const char *prompt; { + struct termios term; register int ch; register char *p; - FILE *outfp; + FILE *fp, *outfp; long omask; + int echo; static char buf[_PASSWORD_LEN + 1]; /* @@ -94,16 +63,16 @@ getpass(prompt) outfp = stderr; fp = stdin; } - - ointhandler = signal(SIGINT, sighandler); - oquithandler = signal(SIGQUIT, sighandler); - otstphandler = signal(SIGTSTP, sighandler); - oconthandler = signal(SIGCONT, sigconthandler); - - (void)tcgetattr(fileno(fp), &oterm); - term = oterm; - term.c_lflag &= ~ECHO; - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + /* + * note - blocking signals isn't necessarily the + * right thing, but we leave it for now. + */ + omask = sigblock(sigmask(SIGINT)|sigmask(SIGTSTP)); + (void)tcgetattr(fileno(fp), &term); + if (echo = (term.c_lflag & ECHO)) { + term.c_lflag &= ~ECHO; + (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + } (void)fputs(prompt, outfp); rewind(outfp); /* implied flush */ for (p = buf; (ch = getc(fp)) != EOF && ch != '\n';) @@ -111,14 +80,11 @@ getpass(prompt) *p++ = ch; *p = '\0'; (void)write(fileno(outfp), "\n", 1); - (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &oterm); - - /* restore old sig handlers */ - (void)signal(SIGINT, ointhandler); - (void)signal(SIGQUIT, oquithandler); - (void)signal(SIGTSTP, otstphandler); - (void)signal(SIGCONT, oconthandler); - + if (echo) { + term.c_lflag |= ECHO; + (void)tcsetattr(fileno(fp), TCSAFLUSH|TCSASOFT, &term); + } + (void)sigsetmask(omask); if (fp != stdin) (void)fclose(fp); return(buf); diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c index da64187d1c2d..d4275394f641 100644 --- a/lib/libc/gen/initgroups.c +++ b/lib/libc/gen/initgroups.c @@ -38,7 +38,6 @@ static char sccsid[] = "@(#)initgroups.c 8.1 (Berkeley) 6/4/93"; #include <sys/param.h> #include <stdio.h> -#include <err.h> int initgroups(uname, agroup) diff --git a/lib/libc/gen/isatty.c b/lib/libc/gen/isatty.c index c8356c710342..f6bb04b86316 100644 --- a/lib/libc/gen/isatty.c +++ b/lib/libc/gen/isatty.c @@ -37,27 +37,12 @@ static char sccsid[] = "@(#)isatty.c 8.1 (Berkeley) 6/4/93"; #include <termios.h> #include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif int isatty(fd) int fd; { - int retval; struct termios t; -#ifdef _THREAD_SAFE - if (_thread_fd_lock(fd, FD_READ, NULL,__FILE__,__LINE__) == 0) { -#endif - retval = (tcgetattr(fd, &t) != -1); -#ifdef _THREAD_SAFE - _thread_fd_unlock(fd, FD_READ); - } else { - retval = 0; - } -#endif - return(retval); + return(tcgetattr(fd, &t) != -1); } diff --git a/lib/libc/gen/ldexp.3 b/lib/libc/gen/ldexp.3 index a19b329c7e64..bffcacf48902 100644 --- a/lib/libc/gen/ldexp.3 +++ b/lib/libc/gen/ldexp.3 @@ -73,5 +73,5 @@ is returned. .Sh STANDARDS The .Fn ldexp -function conforms to +function conforms .St -ansiC . diff --git a/lib/libc/gen/nlist.c b/lib/libc/gen/nlist.c index cbece1889383..9993dcabc053 100644 --- a/lib/libc/gen/nlist.c +++ b/lib/libc/gen/nlist.c @@ -73,6 +73,8 @@ __fdnlist(fd, list) register off_t stroff, symoff; register u_long symsize; register int nent; + size_t strsize; + struct nlist nbuf[1024]; struct exec * exec; struct stat st; diff --git a/lib/libc/gen/opendir.c b/lib/libc/gen/opendir.c index a3db45b18d77..b3c0e096d67e 100644 --- a/lib/libc/gen/opendir.c +++ b/lib/libc/gen/opendir.c @@ -56,16 +56,6 @@ opendir(name) int saved_errno; struct stat sb; - /* - * stat() before open() because opening of special files may be - * harmful. fstat() after open because the file may have changed. - */ - if (stat(name, &sb) != 0) - return NULL; - if (!S_ISDIR(sb.st_mode)) { - errno = ENOTDIR; - return NULL; - } if ((fd = open(name, O_RDONLY | O_NONBLOCK)) == -1) return NULL; dirp = NULL; @@ -79,13 +69,18 @@ opendir(name) (dirp = malloc(sizeof(DIR))) == NULL) goto fail; /* - * Use the system page size if that is a multiple of DIRBLKSIZ - * this could speed things up in some cases we hope + * If CLBYTES is an exact multiple of DIRBLKSIZ, use a CLBYTES + * buffer that it cluster boundary aligned. + * Hopefully this can be a big win someday by allowing page trades + * to user space to be done by getdirentries() */ - dirp->dd_len = getpagesize(); - if ((dirp->dd_len % DIRBLKSIZ) != 0) + if ((CLBYTES % DIRBLKSIZ) == 0) { + dirp->dd_buf = malloc(CLBYTES); + dirp->dd_len = CLBYTES; + } else { + dirp->dd_buf = malloc(DIRBLKSIZ); dirp->dd_len = DIRBLKSIZ; - dirp->dd_buf = malloc(dirp->dd_len); + } if (dirp->dd_buf == NULL) goto fail; dirp->dd_fd = fd; diff --git a/lib/libc/gen/psignal.3 b/lib/libc/gen/psignal.3 index 0f66f521fa7e..2be78336390f 100644 --- a/lib/libc/gen/psignal.3 +++ b/lib/libc/gen/psignal.3 @@ -36,7 +36,7 @@ .Os BSD 4.2 .Sh NAME .Nm psignal , -.Nm sys_siglist , +.Nm sys_siglist .Nm sys_signame .Nd system signal messages .Sh SYNOPSIS diff --git a/lib/libc/gen/psignal.c b/lib/libc/gen/psignal.c index b7e7ab66761a..51491b430842 100644 --- a/lib/libc/gen/psignal.c +++ b/lib/libc/gen/psignal.c @@ -39,7 +39,7 @@ static char sccsid[] = "@(#)psignal.c 8.1 (Berkeley) 6/4/93"; * Print the name of the signal indicated * along with the supplied message. */ -#include <signal.h> +#include <sys/signal.h> #include <string.h> #include <unistd.h> diff --git a/lib/libc/gen/pwcache.3 b/lib/libc/gen/pwcache.3 index 2e69a04261c4..74afa746ed96 100644 --- a/lib/libc/gen/pwcache.3 +++ b/lib/libc/gen/pwcache.3 @@ -84,7 +84,7 @@ pointer is returned. .Xr getpwuid 3 .Sh HISTORY The -.Fn user_from_uid +.Fn user_from_id and -.Fn group_from_gid +.Fn group_from_id functions first appeared in 4.4BSD. diff --git a/lib/libc/gen/pwcache.c b/lib/libc/gen/pwcache.c index 05773bd7e105..1dcbf5d0f200 100644 --- a/lib/libc/gen/pwcache.c +++ b/lib/libc/gen/pwcache.c @@ -38,7 +38,6 @@ static char sccsid[] = "@(#)pwcache.c 8.1 (Berkeley) 6/4/93"; #include <sys/types.h> #include <grp.h> -#include <string.h> #include <pwd.h> #include <stdio.h> #include <utmp.h> @@ -53,10 +52,10 @@ user_from_uid(uid, nouser) { static struct ncache { uid_t uid; - int found; char name[UT_NAMESIZE + 1]; } c_uid[NCACHE]; static int pwopen; + static char nbuf[15]; /* 32 bits == 10 digits */ register struct passwd *pw; register struct ncache *cp; @@ -66,18 +65,15 @@ user_from_uid(uid, nouser) setpassent(1); pwopen = 1; } - pw = getpwuid(uid); - cp->uid = uid; - if (pw != NULL) { - cp->found = 1; - (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; - } else { - cp->found = 0; - (void)snprintf(cp->name, UT_NAMESIZE, "%u", uid); + if ((pw = getpwuid(uid)) == NULL) { if (nouser) return (NULL); + (void)snprintf(nbuf, sizeof(nbuf), "%u", uid); + return (nbuf); } + cp->uid = uid; + (void)strncpy(cp->name, pw->pw_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } @@ -89,10 +85,10 @@ group_from_gid(gid, nogroup) { static struct ncache { gid_t gid; - int found; char name[UT_NAMESIZE + 1]; } c_gid[NCACHE]; static int gropen; + static char nbuf[15]; /* 32 bits == 10 digits */ struct group *gr; struct ncache *cp; @@ -102,18 +98,15 @@ group_from_gid(gid, nogroup) setgroupent(1); gropen = 1; } - gr = getgrgid(gid); - cp->gid = gid; - if (gr != NULL) { - cp->found = 1; - (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); - cp->name[UT_NAMESIZE] = '\0'; - } else { - cp->found = 0; - (void)snprintf(cp->name, UT_NAMESIZE, "%u", gid); + if ((gr = getgrgid(gid)) == NULL) { if (nogroup) return (NULL); + (void)snprintf(nbuf, sizeof(nbuf), "%u", gid); + return (nbuf); } + cp->gid = gid; + (void)strncpy(cp->name, gr->gr_name, UT_NAMESIZE); + cp->name[UT_NAMESIZE] = '\0'; } return (cp->name); } diff --git a/lib/libc/gen/setmode.c b/lib/libc/gen/setmode.c index c69d77568cdd..2190b4e07d3c 100644 --- a/lib/libc/gen/setmode.c +++ b/lib/libc/gen/setmode.c @@ -67,7 +67,7 @@ typedef struct bitcmd { #define CMD2_UBITS 0x10 static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int)); -static void compress_mode __P((BITCMD *)); +static int compress_mode __P((BITCMD *)); #ifdef SETMODE_DEBUG static void dumpmode __P((BITCMD *)); #endif @@ -172,7 +172,7 @@ setmode(p) BITCMD *set, *saveset, *endset; sigset_t sigset, sigoset; mode_t mask; - int equalopdone=0, permXbits, setlen; + int equalopdone, permXbits, setlen; if (!*p) return (NULL); @@ -402,7 +402,7 @@ dumpmode(set) * 'g' and 'o' commands continue to be separate. They could probably be * compacted, but it's not worth the effort. */ -static void +static int compress_mode(set) register BITCMD *set; { diff --git a/lib/libc/gen/sleep.c b/lib/libc/gen/sleep.c index b06475d392a5..3c0b8fa31efa 100644 --- a/lib/libc/gen/sleep.c +++ b/lib/libc/gen/sleep.c @@ -36,35 +36,18 @@ static char sccsid[] = "@(#)sleep.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/time.h> -#include <signal.h> +#include <sys/signal.h> #include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#else #define setvec(vec, a) \ vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 static int ringring; -#endif unsigned int sleep(seconds) unsigned int seconds; { -#ifdef _THREAD_SAFE - struct timespec time_to_sleep; - struct timespec time_remaining; - - if (seconds) { - time_to_sleep.ts_sec = seconds; - time_to_sleep.ts_nsec = 0; - nanosleep(&time_to_sleep,&time_remaining); - seconds = time_remaining.ts_sec; - } - return(seconds); -#else register struct itimerval *itp; struct itimerval itv, oitv; struct sigvec vec, ovec; @@ -105,13 +88,10 @@ sleep(seconds) (void) sigsetmask(omask); (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); return 0; -#endif } -#ifndef _THREAD_SAFE static void sleephandler() { ringring = 1; } -#endif diff --git a/lib/libc/gen/sysconf.c b/lib/libc/gen/sysconf.c index 16a3efa0026d..2994505e942c 100644 --- a/lib/libc/gen/sysconf.c +++ b/lib/libc/gen/sysconf.c @@ -39,7 +39,6 @@ static char sccsid[] = "@(#)sysconf.c 8.2 (Berkeley) 3/20/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> -#include <sys/time.h> #include <sys/sysctl.h> #include <sys/resource.h> @@ -63,6 +62,7 @@ long sysconf(name) int name; { + struct clockinfo clk; struct rlimit rl; size_t len; int mib[2], value; diff --git a/lib/libc/gen/sysctl.3 b/lib/libc/gen/sysctl.3 index 35835c847ec4..a7cffcfc73bf 100644 --- a/lib/libc/gen/sysctl.3 +++ b/lib/libc/gen/sysctl.3 @@ -51,7 +51,7 @@ The information available from consists of integers, strings, and tables. Information may be retrieved and set from the command interface using the -.Xr sysctl 8 +.Xr sysctl 1 utility. .Pp Unless explicitly noted below, @@ -117,7 +117,7 @@ listed here, and described in separate sections below. .Bl -column CTLXMACHDEPXXX "Next level namesXXXXXX" -offset indent .It Sy Pa Name Next level names Description .It CTL\_DEBUG sys/sysctl.h Debugging -.It CTL\_VFS sys/sysctl.h File system +.It CTL\_FS sys/sysctl.h File system .It CTL\_HW sys/sysctl.h Generic CPU, I/O .It CTL\_KERN sys/sysctl.h High kernel limits .It CTL\_MACHDEP sys/sysctl.h Machine dependent @@ -176,7 +176,7 @@ as a debugging variable, the following declaration would be used: int dospecialcheck = 1; struct ctldebug debug5 = { "dospecialcheck", &dospecialcheck }; .Ed -.Sh CTL_VFS +.Sh CTL_FS There are currently no second level names for the file system. .Sh CTL_HW The string and integer information available for the CTL_HW level @@ -260,7 +260,7 @@ information. .Bl -tag -width "123456" .It Li KERN_ARGMAX The maximum bytes of argument to -.Xr execve 2 . +.Xr exec 2 . .It Li KERN_BOOTTIME A .Va struct timeval diff --git a/lib/libc/gen/sysctl.c b/lib/libc/gen/sysctl.c index cb7448af3243..f67a5338d636 100644 --- a/lib/libc/gen/sysctl.c +++ b/lib/libc/gen/sysctl.c @@ -43,7 +43,6 @@ static char sccsid[] = "@(#)sysctl.c 8.2 (Berkeley) 1/4/94"; #include <paths.h> #include <stdio.h> #include <unistd.h> -#include <string.h> int sysctl(name, namelen, oldp, oldlenp, newp, newlen) diff --git a/lib/libc/gen/syslog.3 b/lib/libc/gen/syslog.3 index ab1bd9d8e59e..832fd9ce52e5 100644 --- a/lib/libc/gen/syslog.3 +++ b/lib/libc/gen/syslog.3 @@ -173,15 +173,11 @@ The same as but logged to a file readable only by selected individuals. .It Dv LOG_CRON -The cron daemon: -.Xr cron 8 . +The clock daemon. .It Dv LOG_DAEMON System daemons, such as .Xr routed 8 , that are not provided for explicitly by other facilities. -.It Dv LOG_FTP -The file transfer protocol daemon: -.Xr ftpd 8 . .It Dv LOG_KERN Messages generated by the kernel. These cannot be generated by any user processes. @@ -252,10 +248,8 @@ always returns the previous log mask level. .Bd -literal -offset indent -compact syslog(LOG_ALERT, "who: internal error 23"); -openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP); - +openlog("ftpd", LOG_PID, LOG_DAEMON); setlogmask(LOG_UPTO(LOG_ERR)); - syslog(LOG_INFO, "Connection from host %d", CallingHost); syslog(LOG_INFO|LOG_LOCAL2, "foobar error: %m"); diff --git a/lib/libc/gen/syslog.c b/lib/libc/gen/syslog.c index 3873a696fd57..dd5a8cca004f 100644 --- a/lib/libc/gen/syslog.c +++ b/lib/libc/gen/syslog.c @@ -32,11 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -/* -static char sccsid[] = "From: @(#)syslog.c 8.4 (Berkeley) 3/18/94"; -*/ -static const char rcsid[] = - "$Id$"; +static char sccsid[] = "@(#)syslog.c 8.4 (Berkeley) 3/18/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -61,16 +57,12 @@ static const char rcsid[] = static int LogFile = -1; /* fd for log */ static int connected; /* have done connect */ -static int opened; /* have done openlog() */ static int LogStat = 0; /* status bits, set by openlog() */ static const char *LogTag = NULL; /* string to tag the entry with */ static int LogFacility = LOG_USER; /* default facility code */ static int LogMask = 0xff; /* mask of priorities to be logged */ extern char *__progname; /* Program name, from crt0. */ -static void disconnectlog __P((void)); /* disconnect from syslogd */ -static void connectlog __P((void)); /* (re)connect to syslogd */ - /* * Format of the magic cookie passed through the stdio hook */ @@ -84,8 +76,7 @@ struct bufcookie { * XXX: Maybe one day, dynamically allocate it so that the line length * is `unlimited'. */ -static -int writehook(cookie, buf, len) +static writehook(cookie, buf, len) void *cookie; /* really [struct bufcookie *] */ char *buf; /* characters to copy */ int len; /* length to copy */ @@ -137,7 +128,7 @@ vsyslog(pri, fmt, ap) va_list ap; { register int cnt; - register char ch, *p; + register char ch, *p, *t; time_t now; int fd, saved_errno; char *stdp, tbuf[2048], fmt_cpy[1024]; @@ -238,18 +229,8 @@ vsyslog(pri, fmt, ap) } /* Get connected, output the message to the local logger. */ - if (!opened) + if (!connected) openlog(LogTag, LogStat | LOG_NDELAY, 0); - connectlog(); - if (send(LogFile, tbuf, cnt, 0) >= 0) - return; - - /* - * If the send() failed, the odds are syslogd was restarted. - * Make one (only) attempt to reconnect to /dev/log. - */ - disconnectlog(); - connectlog(); if (send(LogFile, tbuf, cnt, 0) >= 0) return; @@ -276,56 +257,33 @@ vsyslog(pri, fmt, ap) static struct sockaddr SyslogAddr; /* AF_UNIX address of local logger */ -static void -disconnectlog() +void +openlog(ident, logstat, logfac) + const char *ident; + int logstat, logfac; { - /* - * If the user closed the FD and opened another in the same slot, - * that's their problem. They should close it before calling on - * system services. - */ - if (LogFile != -1) { - close(LogFile); - LogFile = -1; - } - connected = 0; /* retry connect */ -} + if (ident != NULL) + LogTag = ident; + LogStat = logstat; + if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) + LogFacility = logfac; -static void -connectlog() -{ if (LogFile == -1) { SyslogAddr.sa_family = AF_UNIX; (void)strncpy(SyslogAddr.sa_data, _PATH_LOG, sizeof(SyslogAddr.sa_data)); - if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) - return; - (void)fcntl(LogFile, F_SETFD, 1); + if (LogStat & LOG_NDELAY) { + if ((LogFile = socket(AF_UNIX, SOCK_DGRAM, 0)) == -1) + return; + (void)fcntl(LogFile, F_SETFD, 1); + } } - if (LogFile != -1 && !connected) { + if (LogFile != -1 && !connected) if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr)) == -1) { (void)close(LogFile); LogFile = -1; } else connected = 1; - } -} - -void -openlog(ident, logstat, logfac) - const char *ident; - int logstat, logfac; -{ - if (ident != NULL) - LogTag = ident; - LogStat = logstat; - if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0) - LogFacility = logfac; - - if (LogStat & LOG_NDELAY) /* open immediately */ - connectlog(); - - opened = 1; /* ident and facility has been set */ } void diff --git a/lib/libc/gen/termios.c b/lib/libc/gen/termios.c index 5264a2dfceb9..3041987ee7df 100644 --- a/lib/libc/gen/termios.c +++ b/lib/libc/gen/termios.c @@ -36,11 +36,15 @@ static char sccsid[] = "@(#)termios.c 8.2 (Berkeley) 2/21/94"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> -#include <sys/fcntl.h> #include <sys/ioctl.h> +#include <sys/tty.h> #include <sys/time.h> +#define KERNEL /* XXX - FREAD and FWRITE ifdef'd KERNEL*/ +#include <sys/fcntl.h> +#undef KERNEL #include <errno.h> +#include <stdio.h> #include <termios.h> #include <unistd.h> @@ -95,7 +99,6 @@ tcsetpgrp(fd, pgrp) pid_t tcgetpgrp(fd) - int fd; { int s; @@ -165,12 +168,11 @@ cfmakeraw(t) t->c_oflag &= ~OPOST; t->c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL|ICANON|ISIG|IEXTEN|NOFLSH|TOSTOP|PENDIN); t->c_cflag &= ~(CSIZE|PARENB); - t->c_cflag |= CS8|CREAD; + t->c_cflag |= CS8; t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 0; } -int tcsendbreak(fd, len) int fd, len; { @@ -186,7 +188,6 @@ tcsendbreak(fd, len) return (0); } -int tcdrain(fd) int fd; { @@ -194,7 +195,6 @@ tcdrain(fd) return (ioctl(fd, TIOCDRAIN, 0)); } -int tcflush(fd, which) int fd, which; { @@ -217,7 +217,6 @@ tcflush(fd, which) return (ioctl(fd, TIOCFLUSH, &com)); } -int tcflow(fd, action) int fd, action; { diff --git a/lib/libc/gen/ttyname.c b/lib/libc/gen/ttyname.c index 39c640ee5eae..f024f52e20ca 100644 --- a/lib/libc/gen/ttyname.c +++ b/lib/libc/gen/ttyname.c @@ -39,121 +39,11 @@ static char sccsid[] = "@(#)ttyname.c 8.2 (Berkeley) 1/27/94"; #include <sys/stat.h> #include <fcntl.h> #include <dirent.h> -#include <stdlib.h> #include <termios.h> -#include <unistd.h> #include <db.h> #include <string.h> #include <paths.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -static pthread_mutex_t ttyname_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_key_t ttyname_key; -static int ttyname_init = 0; - -char * -ttyname(int fd) -{ - char *ret; - - if (_thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__) == 0) { - ret = __ttyname_basic(fd); - _thread_fd_unlock(fd, FD_READ); - } else { - ret = NULL; - } - - return (ret); -} - -char * -__ttyname_r_basic(int fd, char *buf, size_t len) -{ - register struct dirent *dirp; - register DIR *dp; - struct stat dsb; - struct stat sb; - char *rval; - int minlen; - - rval = NULL; - - /* Must be a terminal. */ - if (!isatty(fd)) - return (rval); - /* Must be a character device. */ - if (_thread_sys_fstat(fd, &sb) || !S_ISCHR(sb.st_mode)) - return (rval); - /* Must have enough room */ - if (len <= sizeof(_PATH_DEV)) - return (rval); - - if ((dp = opendir(_PATH_DEV)) != NULL) { - memcpy(buf, _PATH_DEV, sizeof(_PATH_DEV)); - for (rval = NULL; (dirp = readdir(dp)) != NULL;) { - if (dirp->d_fileno != sb.st_ino) - continue; - minlen = (len - (sizeof(_PATH_DEV) - 1)) < (dirp->d_namlen + 1) ? - (len - (sizeof(_PATH_DEV) - 1)) : (dirp->d_namlen + 1); - memcpy(buf + sizeof(_PATH_DEV) - 1, dirp->d_name, minlen); - if (stat(buf, &dsb) || sb.st_dev != dsb.st_dev || - sb.st_ino != dsb.st_ino) - continue; - rval = buf; - break; - } - (void) closedir(dp); - } - return (rval); -} - -char * -__ttyname_basic(int fd) -{ - char *buf; - - pthread_mutex_lock(&ttyname_lock); - if (ttyname_init == 0) { - if (pthread_keycreate(&ttyname_key, free)) { - pthread_mutex_unlock(&ttyname_lock); - return (NULL); - } - ttyname_init = 1; - } - pthread_mutex_unlock(&ttyname_lock); - - /* Must have thread specific data field to put data */ - if (pthread_getspecific(ttyname_key, (void **) &buf) != 0) { - return (NULL); - } else if (buf == NULL) { - if ((buf = malloc(sizeof(_PATH_DEV) + MAXNAMLEN)) != NULL) { - if (pthread_setspecific(ttyname_key, buf) != 0) { - free(buf); - return (NULL); - } - } else { - return (NULL); - } - } - return (__ttyname_r_basic(fd, buf, sizeof(_PATH_DEV) + MAXNAMLEN)); -} - -char * -ttyname_r(int fd, char *buf, size_t len) -{ - char *ret; - - if (_thread_fd_lock(fd, FD_READ, NULL, __FILE__, __LINE__) == 0) { - ret = __ttyname_r_basic(fd, buf, len); - _thread_fd_unlock(fd, FD_READ); - } else { - ret = NULL; - } - return (ret); -} -#else static char buf[sizeof(_PATH_DEV) + MAXNAMLEN] = _PATH_DEV; static char *oldttyname __P((int, struct stat *)); @@ -220,4 +110,3 @@ oldttyname(fd, sb) (void)closedir(dp); return (NULL); } -#endif diff --git a/lib/libc/gen/unvis.c b/lib/libc/gen/unvis.c index ebeb771b235a..547048336c4d 100644 --- a/lib/libc/gen/unvis.c +++ b/lib/libc/gen/unvis.c @@ -36,6 +36,7 @@ static char sccsid[] = "@(#)unvis.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> +#include <ctype.h> #include <vis.h> /* diff --git a/lib/libc/gen/usleep.c b/lib/libc/gen/usleep.c index 9e29f314d959..9127bfc4f42e 100644 --- a/lib/libc/gen/usleep.c +++ b/lib/libc/gen/usleep.c @@ -36,12 +36,9 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <sys/time.h> -#include <signal.h> +#include <sys/signal.h> #include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#else + #define TICK 10000 /* system clock resolution in microseconds */ #define USPS 1000000 /* number of microseconds in a second */ @@ -49,22 +46,11 @@ static char sccsid[] = "@(#)usleep.c 8.1 (Berkeley) 6/4/93"; vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 static int ringring; -#endif - void usleep(useconds) unsigned int useconds; { -#ifdef _THREAD_SAFE - struct timespec time_to_sleep; - - if (useconds) { - time_to_sleep.ts_nsec = (useconds % 1000000) * 1000; - time_to_sleep.ts_sec = useconds / 1000000; - nanosleep(&time_to_sleep,NULL); - } -#else register struct itimerval *itp; struct itimerval itv, oitv; struct sigvec vec, ovec; @@ -104,13 +90,10 @@ usleep(useconds) (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0); (void) sigsetmask(omask); (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); -#endif } -#ifndef _THREAD_SAFE static void sleephandler() { ringring = 1; } -#endif diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c index 66954e7cd57e..e12226a593f6 100644 --- a/lib/libc/gen/vis.c +++ b/lib/libc/gen/vis.c @@ -51,8 +51,7 @@ vis(dst, c, flag, nextc) int c, nextc; register int flag; { - c = (unsigned char)c; - if (isgraph(c) || + if ((u_int)c <= UCHAR_MAX && isgraph(c) || ((flag & VIS_SP) == 0 && c == ' ') || ((flag & VIS_TAB) == 0 && c == '\t') || ((flag & VIS_NL) == 0 && c == '\n') || diff --git a/lib/libc/gmon/Makefile.inc b/lib/libc/gmon/Makefile.inc index 57dc29364566..65a865917db6 100644 --- a/lib/libc/gmon/Makefile.inc +++ b/lib/libc/gmon/Makefile.inc @@ -5,7 +5,6 @@ SRCS+= gmon.c mcount.c MAN3+= gmon/moncontrol.3 -MLINKS+= moncontrol.3 monstartup.3 # mcount cannot be compiled with profiling mcount.po: mcount.o diff --git a/lib/libc/i386/DEFS.h b/lib/libc/i386/DEFS.h index 2ec3019f91cd..27240d7df76c 100644 --- a/lib/libc/i386/DEFS.h +++ b/lib/libc/i386/DEFS.h @@ -38,24 +38,6 @@ * $Id: DEFS.h,v 1.2 1994/08/05 01:17:56 wollman Exp $ */ -#include <sys/cdefs.h> - -/* - * CNAME and HIDENAME manage the relationship between symbol names in C - * and the equivalent assembly language names. CNAME is given a name as - * it would be used in a C program. It expands to the equivalent assembly - * language name. HIDENAME is given an assembly-language name, and expands - * to a possibly-modified form that will be invisible to C programs. - */ -#if defined(__ELF__) /* { */ -#define CNAME(csym) csym -#define HIDENAME(asmsym) __CONCAT(.,asmsym) -#else /* } { */ -#define CNAME(csym) __CONCAT(_,csym) -#define HIDENAME(asmsym) asmsym -#endif /* } */ - - /* XXX should use align 4,0x90 for -m486. */ #define _START_ENTRY .align 2,0x90; #if 0 @@ -69,30 +51,30 @@ #ifdef PROF #define ALTENTRY(x) _START_ENTRY \ - .globl CNAME(x); .type CNAME(x),@function; CNAME(x):; \ + .globl _/**/x; .type _/**/x,@function; _/**/x:; \ _MID_ENTRY \ - call HIDENAME(mcount); jmp 9f + call mcount; jmp 9f -#define ENTRY(x) _START_ENTRY \ - .globl CNAME(x); .type CNAME(x),@function; CNAME(x):; \ +#define ENTRY(x) _START_ENTRY \ + .globl _/**/x; .type _/**/x,@function; _/**/x:; \ _MID_ENTRY \ - call HIDENAME(mcount); 9: + call mcount; 9: #define ALTASENTRY(x) _START_ENTRY \ .globl x; .type x,@function; x:; \ _MID_ENTRY \ - call HIDENAME(mcount); jmp 9f + call mcount; jmp 9f #define ASENTRY(x) _START_ENTRY \ .globl x; .type x,@function; x:; \ _MID_ENTRY \ - call HIDENAME(mcount); 9: + call mcount; 9: #else /* !PROF */ -#define ENTRY(x) _START_ENTRY .globl CNAME(x); .type CNAME(x),@function; \ - CNAME(x): +#define ENTRY(x) _START_ENTRY .globl _/**/x; .type _/**/x,@function; \ + _/**/x: #define ALTENTRY(x) ENTRY(x) #define ASENTRY(x) _START_ENTRY .globl x; .type x,@function; x: diff --git a/lib/libc/i386/SYS.h b/lib/libc/i386/SYS.h index 9a63bf0fcff2..bbd2a1d95eb6 100644 --- a/lib/libc/i386/SYS.h +++ b/lib/libc/i386/SYS.h @@ -61,27 +61,13 @@ #define PIC_GOTOFF(x) x #endif -#define SYSCALL(x) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); ENTRY(x); lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b +#define SYSCALL(x) 2: jmp cerror; ENTRY(x); lea SYS_/**/x,%eax; LCALL(7,0); jb 2b #define RSYSCALL(x) SYSCALL(x); ret - -/* - * For the thread_safe versions, we prepend _thread_sys_ to the function - * name so that the 'C' wrapper can go around the real name. - */ -#ifdef _THREAD_SAFE /* in case */ -#define PSYSCALL(x,y) 2: PIC_PROLOGUE; jmp PIC_PLT(HIDENAME(cerror)); ENTRY(y); lea __CONCAT(SYS_,x),%eax; KERNCALL; jb 2b -#define PRSYSCALL(x,y) PSYSCALL(x,y); ret -#endif - -#define PSEUDO(x,y) ENTRY(x); lea __CONCAT(SYS_,y), %eax; KERNCALL; ret -#define CALL(x,y) call CNAME(y); addl $4*x,%esp +#define PSEUDO(x,y) ENTRY(x); lea SYS_/**/y, %eax; ; LCALL(7,0); ret +#define CALL(x,y) call _/**/y; addl $4*x,%esp /* gas fucks up offset -- although we don't currently need it, do for BCS */ #define LCALL(x,y) .byte 0x9a ; .long y; .word x -#ifdef __ELF__ -#define KERNCALL int $0x80 /* Faster */ -#else -#define KERNCALL LCALL(7,0) /* The old way */ -#endif - #define ASMSTR .asciz + + .globl cerror diff --git a/lib/libc/i386/gen/Makefile.inc b/lib/libc/i386/gen/Makefile.inc index 387aebffef0f..87873af521c9 100644 --- a/lib/libc/i386/gen/Makefile.inc +++ b/lib/libc/i386/gen/Makefile.inc @@ -3,3 +3,4 @@ SRCS+= isinf.c infinity.c SRCS+= _setjmp.S alloca.S fabs.S ldexp.c modf.S setjmp.S sigsetjmp.S +SRCS+= divsi3.S fixdfsi.S fixunsdfsi.S udivsi3.S diff --git a/lib/libc/i386/gen/_setjmp.S b/lib/libc/i386/gen/_setjmp.S index 23a2cdea0a03..876f3c0aadf8 100644 --- a/lib/libc/i386/gen/_setjmp.S +++ b/lib/libc/i386/gen/_setjmp.S @@ -53,11 +53,7 @@ #include "DEFS.h" -#ifdef _THREAD_SAFE -ENTRY(__thread_sys_setjmp) -#else ENTRY(_setjmp) -#endif movl 4(%esp),%eax movl 0(%esp),%edx movl %edx, 0(%eax) /* rta */ @@ -70,11 +66,7 @@ ENTRY(_setjmp) xorl %eax,%eax ret -#ifdef _THREAD_SAFE -ENTRY(__thread_sys_longjmp) -#else ENTRY(_longjmp) -#endif movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx diff --git a/lib/libc/i386/gen/modf.S b/lib/libc/i386/gen/modf.S index 34a89ed4dbce..bce5a3519ed1 100644 --- a/lib/libc/i386/gen/modf.S +++ b/lib/libc/i386/gen/modf.S @@ -50,10 +50,10 @@ */ /* With CHOP mode on, frndint behaves as TRUNC does. Useful. */ - -#include "DEFS.h" - -ENTRY(modf) +.text +.globl _modf +.type _modf,@function +_modf: pushl %ebp movl %esp,%ebp subl $16,%esp diff --git a/lib/libc/i386/gen/setjmp.S b/lib/libc/i386/gen/setjmp.S index be457fc55b3e..449ea3747fde 100644 --- a/lib/libc/i386/gen/setjmp.S +++ b/lib/libc/i386/gen/setjmp.S @@ -54,20 +54,10 @@ #include "DEFS.h" #include "SYS.h" -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_setjmp) -#else ENTRY(setjmp) -#endif - PIC_PROLOGUE pushl $0 -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigblock)) -#else - call PIC_PLT(CNAME(sigblock)) -#endif + call PIC_PLT(_sigblock) popl %edx - PIC_EPILOGUE movl 4(%esp),%ecx movl 0(%esp),%edx movl %edx, 0(%ecx) @@ -81,21 +71,11 @@ ENTRY(setjmp) xorl %eax,%eax ret -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_longjmp) -#else ENTRY(longjmp) -#endif movl 4(%esp),%edx - PIC_PROLOGUE pushl 24(%edx) -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigsetmask)) -#else - call PIC_PLT(CNAME(sigsetmask)) /* XXX this is not reentrant */ -#endif + call PIC_PLT(_sigsetmask) /* XXX this is not reentrant */ popl %eax - PIC_EPILOGUE movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx diff --git a/lib/libc/i386/gen/sigsetjmp.S b/lib/libc/i386/gen/sigsetjmp.S index 3610a2b5eac0..4ec4538f3453 100644 --- a/lib/libc/i386/gen/sigsetjmp.S +++ b/lib/libc/i386/gen/sigsetjmp.S @@ -59,28 +59,18 @@ * use sigreturn() if sigreturn() works. */ -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_sigsetjmp) -#else ENTRY(sigsetjmp) -#endif movl 8(%esp),%eax movl 4(%esp),%ecx movl %eax,32(%ecx) testl %eax,%eax - jz 2f - PIC_PROLOGUE + jz 1f pushl $0 -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigblock)) -#else - call PIC_PLT(CNAME(sigblock)) -#endif + call PIC_PLT(_sigblock) addl $4,%esp - PIC_EPILOGUE movl 4(%esp),%ecx movl %eax,24(%ecx) -2: movl 0(%esp),%edx +1: movl 0(%esp),%edx movl %edx, 0(%ecx) movl %ebx, 4(%ecx) movl %esp, 8(%ecx) @@ -91,24 +81,14 @@ ENTRY(sigsetjmp) xorl %eax,%eax ret -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_siglongjmp) -#else ENTRY(siglongjmp) -#endif movl 4(%esp),%edx cmpl $0,32(%edx) - jz 2f - PIC_PROLOGUE + jz 1f pushl 24(%edx) -#ifdef _THREAD_SAFE - call PIC_PLT(CNAME(_thread_sys_sigsetmask)) -#else - call PIC_PLT(CNAME(sigsetmask)) -#endif + call PIC_PLT(_sigsetmask) addl $4,%esp - PIC_EPILOGUE -2: movl 4(%esp),%edx +1: movl 4(%esp),%edx movl 8(%esp),%eax movl 0(%edx),%ecx movl 4(%edx),%ebx @@ -119,7 +99,7 @@ ENTRY(siglongjmp) fninit fldcw 28(%edx) testl %eax,%eax - jnz 1f + jnz 2f incl %eax -1: movl %ecx,0(%esp) +2: movl %ecx,0(%esp) ret diff --git a/lib/libc/i386/string/bcopy.S b/lib/libc/i386/string/bcopy.S index 6d9993825a04..facfc3a96231 100644 --- a/lib/libc/i386/string/bcopy.S +++ b/lib/libc/i386/string/bcopy.S @@ -53,10 +53,8 @@ ENTRY(bcopy) movl 12(%esp),%esi movl 16(%esp),%edi movl 20(%esp),%ecx - movl %edi,%eax - subl %esi,%eax - cmpl %ecx,%eax /* overlapping? */ - jb 1f + cmpl %esi,%edi /* potentially overlapping? */ + jnb 1f cld /* nope, copy forwards. */ shrl $2,%ecx /* copy by words */ rep @@ -71,10 +69,10 @@ ENTRY(bcopy) 1: addl %ecx,%edi /* copy backwards. */ addl %ecx,%esi + std + andl $3,%ecx /* any fractional bytes? */ decl %edi decl %esi - andl $3,%ecx /* any fractional bytes? */ - std rep movsb movl 20(%esp),%ecx /* copy remainder by words */ diff --git a/lib/libc/i386/string/memmove.S b/lib/libc/i386/string/memmove.S index 497af4fceacc..27d6d3178bf0 100644 --- a/lib/libc/i386/string/memmove.S +++ b/lib/libc/i386/string/memmove.S @@ -54,10 +54,8 @@ ENTRY(memmove) movl 12(%esp),%edi movl 16(%esp),%esi movl 20(%esp),%ecx - movl %edi,%eax - subl %esi,%eax - cmpl %ecx,%eax - jb 1f + cmpl %esi,%edi /* potentially overlapping? */ + jnb 1f cld /* nope, copy forwards. */ shrl $2,%ecx /* copy by words */ rep @@ -73,10 +71,10 @@ ENTRY(memmove) 1: addl %ecx,%edi /* copy backwards. */ addl %ecx,%esi + std + andl $3,%ecx /* any fractional bytes? */ decl %edi decl %esi - andl $3,%ecx /* any fractional bytes? */ - std rep movsb movl 20(%esp),%ecx /* copy remainder by words */ diff --git a/lib/libc/i386/sys/Ovfork.S b/lib/libc/i386/sys/Ovfork.S index 0161f4a87a19..a941be2d7182 100644 --- a/lib/libc/i386/sys/Ovfork.S +++ b/lib/libc/i386/sys/Ovfork.S @@ -41,7 +41,6 @@ .asciz "$Id: Ovfork.S,v 1.2 1995/01/23 01:29:37 davidg Exp $" #endif /* SYSLIBC_RCS and not lint */ -#include "DEFS.h" #include "SYS.h" /* @@ -51,49 +50,30 @@ * %eax == pid of child in parent, %eax == pid of parent in child. * */ + .set vfork,66 +.globl _vfork +.type _vfork,@function -ENTRY(vfork) +_vfork: popl %ecx /* my rta into ecx */ - lea SYS_vfork,%eax - KERNCALL + movl $vfork, %eax + LCALL(7,0) jb verror vforkok: cmpl $0,%edx /* child process? */ jne child /* yes */ jmp parent -#ifdef _THREAD_SAFE - /* - * Threaded version using __error(). - */ - .globl CNAME(__error) - .type CNAME(__error),@function -verror: - pushl %eax -#ifdef PIC - call PIC_PLT(CNAME(__error)) -#else - call CNAME(__error) -#endif - popl %ecx - movl %ecx,(%eax) - movl $-1,%eax - movl $-1,%edx -#else /* !_THREAD_SAFE */ - /* - * Non-threaded version using global errno. - */ - .globl CNAME(errno) +.globl _errno verror: #ifdef PIC PIC_PROLOGUE - movl PIC_GOT(CNAME(errno)), %edx + movl PIC_GOT(_errno), %edx movl %eax,(%edx) PIC_EPILOGUE #else - movl %eax,CNAME(errno) + movl %eax,_errno #endif movl $-1,%eax -#endif /* !_THREAD_SAFE */ jmp %ecx child: movl $0,%eax diff --git a/lib/libc/i386/sys/brk.S b/lib/libc/i386/sys/brk.S index 1636858c0d3e..c66add4905fc 100644 --- a/lib/libc/i386/sys/brk.S +++ b/lib/libc/i386/sys/brk.S @@ -43,8 +43,10 @@ #include "SYS.h" - .globl HIDENAME(curbrk) - .globl HIDENAME(minbrk) +#define SYS_brk 17 + + .globl curbrk + .globl minbrk ENTRY(_brk) jmp ok @@ -52,40 +54,39 @@ ENTRY(brk) #ifdef PIC movl 4(%esp),%eax PIC_PROLOGUE - movl PIC_GOT(HIDENAME(curbrk)),%edx # set up GOT addressing - movl PIC_GOT(HIDENAME(minbrk)),%ecx # + movl PIC_GOT(curbrk),%edx # set up GOT addressing + movl PIC_GOT(minbrk),%ecx # cmpl %eax,(%ecx) PIC_EPILOGUE jl ok movl (%ecx),%eax movl %eax,4(%esp) ok: - lea SYS_break,%eax - KERNCALL + lea SYS_brk,%eax + LCALL(7,0) jb err movl 4(%esp),%eax movl %eax,(%edx) movl $0,%eax ret err: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp PIC_PLT(cerror) #else movl 4(%esp),%eax - cmpl %eax,HIDENAME(minbrk) + cmpl %eax,minbrk jl ok - movl HIDENAME(minbrk),%eax + movl minbrk,%eax movl %eax,4(%esp) ok: - lea SYS_break,%eax - KERNCALL + lea SYS_brk,%eax + LCALL(7,0) jb err movl 4(%esp),%eax - movl %eax,HIDENAME(curbrk) + movl %eax,curbrk movl $0,%eax ret err: - jmp HIDENAME(cerror) + jmp cerror #endif diff --git a/lib/libc/i386/sys/cerror.S b/lib/libc/i386/sys/cerror.S index a54b55eb2d1f..8c49bd4aeab4 100644 --- a/lib/libc/i386/sys/cerror.S +++ b/lib/libc/i386/sys/cerror.S @@ -43,45 +43,16 @@ #include "SYS.h" - .globl HIDENAME(cerror) - -#ifdef _THREAD_SAFE - /* - * Threaded version using __error(). - */ - .globl CNAME(__error) - .type CNAME(__error),@function -HIDENAME(cerror): - pushl %eax -#ifdef PIC - /* The caller must execute the PIC prologue before jumping to cerror. */ - call PIC_PLT(CNAME(__error)) - popl %ecx - PIC_EPILOGUE -#else - call CNAME(__error) - popl %ecx -#endif - movl %ecx,(%eax) - movl $-1,%eax - movl $-1,%edx - ret - -#else /* _THREAD_SAFE */ - /* - * Non-threaded version using global errno. - */ - .globl CNAME(errno) -HIDENAME(cerror): + .globl _errno +cerror: #ifdef PIC - /* The caller must execute the PIC prologue before jumping to cerror. */ - movl PIC_GOT(CNAME(errno)),%ecx + PIC_PROLOGUE + movl PIC_GOT(_errno),%ecx movl %eax,(%ecx) PIC_EPILOGUE #else - movl %eax,CNAME(errno) + movl %eax,_errno #endif movl $-1,%eax movl $-1,%edx ret -#endif /* _THREAD_SAFE */ diff --git a/lib/libc/i386/sys/exect.S b/lib/libc/i386/sys/exect.S index 59ce389f2978..9fe53d21bc57 100644 --- a/lib/libc/i386/sys/exect.S +++ b/lib/libc/i386/sys/exect.S @@ -51,6 +51,5 @@ ENTRY(exect) orl $ PSL_T,%edx pushl %edx popf - KERNCALL - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) /* exect(file, argv, env); */ + LCALL(7,0) + jmp cerror /* exect(file, argv, env); */ diff --git a/lib/libc/i386/sys/fork.S b/lib/libc/i386/sys/fork.S index 27b49d326eed..8b8507711339 100644 --- a/lib/libc/i386/sys/fork.S +++ b/lib/libc/i386/sys/fork.S @@ -43,11 +43,7 @@ #include "SYS.h" -#ifdef _THREAD_SAFE -PSYSCALL(fork,_thread_sys_fork) -#else SYSCALL(fork) -#endif cmpl $0,%edx /* parent, since %edx == 0 in parent, 1 in child */ je 1f movl $0,%eax diff --git a/lib/libc/i386/sys/pipe.S b/lib/libc/i386/sys/pipe.S index b415ec0e7fca..1741cd24e7d1 100644 --- a/lib/libc/i386/sys/pipe.S +++ b/lib/libc/i386/sys/pipe.S @@ -43,11 +43,7 @@ #include "SYS.h" -#ifdef _THREAD_SAFE -PSYSCALL(pipe,_thread_sys_pipe) -#else SYSCALL(pipe) -#endif movl 4(%esp),%ecx movl %eax,(%ecx) movl %edx,4(%ecx) diff --git a/lib/libc/i386/sys/ptrace.S b/lib/libc/i386/sys/ptrace.S index 993c9be55056..d18dd0a193a4 100644 --- a/lib/libc/i386/sys/ptrace.S +++ b/lib/libc/i386/sys/ptrace.S @@ -47,16 +47,15 @@ ENTRY(ptrace) xorl %eax,%eax #ifdef PIC PIC_PROLOGUE - movl PIC_GOT(CNAME(errno)),%edx + movl PIC_GOT(_errno),%edx movl %eax,(%edx) PIC_EPILOGUE #else - movl %eax,CNAME(errno) + movl %eax,_errno #endif lea SYS_ptrace,%eax - KERNCALL + LCALL(7,0) jb err ret err: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp cerror diff --git a/lib/libc/i386/sys/sbrk.S b/lib/libc/i386/sys/sbrk.S index 4213114aa4d2..90729f651ca6 100644 --- a/lib/libc/i386/sys/sbrk.S +++ b/lib/libc/i386/sys/sbrk.S @@ -43,53 +43,48 @@ #include "SYS.h" - .globl CNAME(end) - .globl HIDENAME(minbrk) - .globl HIDENAME(curbrk) +#define SYS_brk 17 + + .globl _end + .globl minbrk + .globl curbrk .data -HIDENAME(minbrk): .long CNAME(end) -HIDENAME(curbrk): .long CNAME(end) +minbrk: .long _end +curbrk: .long _end .text ENTRY(sbrk) #ifdef PIC movl 4(%esp),%ecx PIC_PROLOGUE - movl PIC_GOT(HIDENAME(curbrk)),%edx + movl PIC_GOT(curbrk),%edx movl (%edx),%eax PIC_EPILOGUE - testl %ecx,%ecx - jz back addl %eax,4(%esp) - lea SYS_break,%eax - KERNCALL + lea SYS_brk,%eax + LCALL(7,0) jb err PIC_PROLOGUE - movl PIC_GOT(HIDENAME(curbrk)),%edx + movl PIC_GOT(curbrk),%edx movl (%edx),%eax addl %ecx,(%edx) PIC_EPILOGUE -back: ret err: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp PIC_PLT(cerror) -#else /* !PIC */ +#else movl 4(%esp),%ecx - movl HIDENAME(curbrk),%eax - testl %ecx,%ecx - jz back + movl curbrk,%eax addl %eax,4(%esp) - lea SYS_break,%eax - KERNCALL + lea SYS_brk,%eax + LCALL(7,0) jb err - movl HIDENAME(curbrk),%eax - addl %ecx,HIDENAME(curbrk) -back: + movl curbrk,%eax + addl %ecx,curbrk ret err: - jmp HIDENAME(cerror) -#endif /* PIC */ + jmp cerror +#endif diff --git a/lib/libc/i386/sys/setlogin.S b/lib/libc/i386/sys/setlogin.S index 1ec31b9ef760..27e23a74ca3b 100644 --- a/lib/libc/i386/sys/setlogin.S +++ b/lib/libc/i386/sys/setlogin.S @@ -43,17 +43,17 @@ #include "SYS.h" -.globl CNAME(_logname_valid) /* in getlogin() */ +.globl __logname_valid /* in getlogin() */ SYSCALL(setlogin) #ifdef PIC PIC_PROLOGUE pushl %eax - movl PIC_GOT(CNAME(_logname_valid)),%eax + movl PIC_GOT(__logname_valid),%eax movl $0,(%eax) popl %eax PIC_EPILOGUE #else - movl $0,CNAME(_logname_valid) + movl $0,__logname_valid #endif ret /* setlogin(name) */ diff --git a/lib/libc/i386/sys/sigpending.S b/lib/libc/i386/sys/sigpending.S index cbace9d2f05b..d42a765dbf32 100644 --- a/lib/libc/i386/sys/sigpending.S +++ b/lib/libc/i386/sys/sigpending.S @@ -43,11 +43,7 @@ #include "SYS.h" -#ifdef _THREAD_SAFE -PSYSCALL(sigpending,_thread_sys_sigpending) -#else SYSCALL(sigpending) -#endif movl 4(%esp),%ecx # fetch pointer to... movl %eax,(%ecx) # store old mask xorl %eax,%eax diff --git a/lib/libc/i386/sys/sigprocmask.S b/lib/libc/i386/sys/sigprocmask.S index 33112aa0ad17..a433522a1aa5 100644 --- a/lib/libc/i386/sys/sigprocmask.S +++ b/lib/libc/i386/sys/sigprocmask.S @@ -44,14 +44,9 @@ #include "SYS.h" err: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp cerror -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_sigprocmask) -#else ENTRY(sigprocmask) -#endif movl 8(%esp),%ecx # fetch new sigset pointer cmpl $0,%ecx # check new sigset pointer jne 1f # if not null, indirect @@ -60,8 +55,8 @@ ENTRY(sigprocmask) jmp 2f 1: movl (%ecx),%ecx # fetch indirect ... movl %ecx,8(%esp) # to new mask arg -2: lea SYS_sigprocmask,%eax - KERNCALL +2: movl $ SYS_sigprocmask , %eax + LCALL(0x7,0) jb err movl 12(%esp),%ecx # fetch old mask requested cmpl $0,%ecx # test if old mask requested diff --git a/lib/libc/i386/sys/sigreturn.S b/lib/libc/i386/sys/sigreturn.S index f09c1fea9c06..884fb1ebc58e 100644 --- a/lib/libc/i386/sys/sigreturn.S +++ b/lib/libc/i386/sys/sigreturn.S @@ -44,13 +44,14 @@ #include "SYS.h" /* - * NOTE: If the profiling ENTRY() code ever changes any registers, they - * must be saved. On FreeBSD, this is not the case. + * We must preserve the state of the registers as the user has set them up. */ +#ifdef PROF +#undef ENTRY +#define ENTRY(x) \ + .globl _/**/x; .align 2; _/**/x: pusha ; \ + .data; 1:; .long 0; .text; movl $1b,%eax; call mcount; popa ; nop +#endif /* PROF */ -#ifdef _THREAD_SAFE -PSYSCALL(sigreturn,_thread_sys_sigreturn) -#else SYSCALL(sigreturn) -#endif ret diff --git a/lib/libc/i386/sys/sigsuspend.S b/lib/libc/i386/sys/sigsuspend.S index 825b068a885c..823204187886 100644 --- a/lib/libc/i386/sys/sigsuspend.S +++ b/lib/libc/i386/sys/sigsuspend.S @@ -44,19 +44,14 @@ #include "SYS.h" err: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp cerror -#ifdef _THREAD_SAFE -ENTRY(_thread_sys_sigsuspend) -#else ENTRY(sigsuspend) -#endif movl 4(%esp),%eax # fetch mask arg movl (%eax),%eax # indirect to mask arg movl %eax,4(%esp) - lea SYS_sigsuspend,%eax - KERNCALL + movl $ SYS_sigsuspend ,%eax + LCALL(0x7,0) jb err xorl %eax,%eax # shouldn t happen ret diff --git a/lib/libc/i386/sys/syscall.S b/lib/libc/i386/sys/syscall.S index ccc1b93e6901..89e91e9c6d50 100644 --- a/lib/libc/i386/sys/syscall.S +++ b/lib/libc/i386/sys/syscall.S @@ -47,11 +47,10 @@ ENTRY(syscall) pop %ecx /* rta */ pop %eax /* syscall number */ push %ecx - KERNCALL + LCALL(7,0) push %ecx /* need to push a word to keep stack frame intact upon return; the word must be the return address. */ jb 1f ret 1: - PIC_PROLOGUE - jmp PIC_PLT(HIDENAME(cerror)) + jmp cerror diff --git a/lib/libc/locale/Makefile.inc b/lib/libc/locale/Makefile.inc index 5fd09d27a922..795d1f81bf89 100644 --- a/lib/libc/locale/Makefile.inc +++ b/lib/libc/locale/Makefile.inc @@ -4,8 +4,9 @@ .PATH: ${.CURDIR}/${MACHINE}/locale ${.CURDIR}/locale SRCS+= ansi.c ctype.c euc.c frune.c isctype.c lconv.c localeconv.c \ - mbrune.c none.c rune.c setlocale.c table.c utf2.c setrunelocale.c \ - runetype.c tolower.c toupper.c nomacros.c collate.c setinvalidrune.c + mbrune.c none.c rune.c common_setlocale.c \ + startup_setlocale.c read_runemagi.c setlocale.c table.c utf2.c \ + runetype.c tolower.c toupper.c nomacros.c collate.c MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \ locale/isblank.3 locale/iscntrl.3 locale/isdigit.3 locale/isgraph.3 \ @@ -14,8 +15,3 @@ MAN3+= locale/ctype.3 locale/isalnum.3 locale/isalpha.3 locale/isascii.3 \ locale/rune.3 locale/setlocale.3 locale/toascii.3 locale/tolower.3 \ locale/toupper.3 MAN4+= locale/euc.4 locale/utf2.4 -MLINKS+= rune.3 setrunelocale.3 rune.3 setinvalidrune.3 rune.3 sgetrune.3 \ - rune.3 sputrune.3 rune.3 fgetrune.3 rune.3 fungetrune.3 \ - rune.3 fputrune.3 mbrune.3 mbrrune.3 mbrune.3 mbmb.3 \ - multibyte.3 mblen.3 multibyte.3 mbstowcs.3 multibyte.3 mbtowc.3 \ - multibyte.3 wcstombs.3 multibyte.3 wctomb.3 setlocale.3 localeconv.3 diff --git a/lib/libc/locale/ansi.c b/lib/libc/locale/ansi.c index a5a3362d8adf..e5c8e8ff96de 100644 --- a/lib/libc/locale/ansi.c +++ b/lib/libc/locale/ansi.c @@ -53,7 +53,7 @@ mblen(s, n) if (s == 0 || *s == 0) return (0); /* No support for state dependent encodings. */ - if (sgetrune(s, n, &e) == _INVALID_RUNE) + if (sgetrune(s, (int)n, &e) == _INVALID_RUNE) return (s - e); return (e - s); } @@ -70,7 +70,7 @@ mbtowc(pwc, s, n) if (s == 0 || *s == 0) return (0); /* No support for state dependent encodings. */ - if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) + if ((r = sgetrune(s, (int)n, &e)) == _INVALID_RUNE) return (s - e); if (pwc) *pwc = r; @@ -137,12 +137,11 @@ wcstombs(s, pwcs, n) *s = 0; break; } - if (!sputrune(*pwcs++, s, n, &e)) + if (!sputrune(*pwcs++, s, (int)n, &e)) return (-1); /* encoding error */ if (!e) /* too long */ return (cnt); cnt += e - s; - n -= e - s; s = e; } return (cnt); diff --git a/lib/libc/locale/collate.c b/lib/libc/locale/collate.c index ef73cefebb74..d06bd5c3ad3d 100644 --- a/lib/libc/locale/collate.c +++ b/lib/libc/locale/collate.c @@ -36,7 +36,6 @@ #include <sysexits.h> #include "collate.h" -char *_PathLocale; int __collate_load_error = 1; u_char __collate_charmap_table[UCHAR_MAX + 1][STR_LEN]; u_char __collate_substitute_table[UCHAR_MAX + 1][STR_LEN]; @@ -59,27 +58,20 @@ __collate_load_tables(encoding) char *encoding; { char buf[PATH_MAX]; + static char *path_locale; FILE *fp; - int save_load_error; - save_load_error = __collate_load_error; __collate_load_error = 1; - if (!encoding) { - __collate_load_error = save_load_error; + if (!encoding) return -1; - } - if (!*encoding || !strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) - return 0; - if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))) - _PathLocale = _PATH_LOCALE; - strcpy(buf, _PathLocale); + if (!path_locale && !(path_locale = getenv("PATH_LOCALE"))) + path_locale = _PATH_LOCALE; + strcpy(buf, path_locale); strcat(buf, "/"); strcat(buf, encoding); strcat(buf, "/LC_COLLATE"); - if ((fp = fopen(buf, "r")) == NULL) { - __collate_load_error = save_load_error; + if ((fp = fopen(buf, "r")) == NULL) return -1; - } FREAD(__collate_charmap_table, sizeof(__collate_charmap_table), 1, fp); FREAD(__collate_substitute_table, sizeof(__collate_substitute_table), 1, fp); diff --git a/lib/libc/locale/euc.4 b/lib/libc/locale/euc.4 index 9524a4dea503..966b896b657f 100644 --- a/lib/libc/locale/euc.4 +++ b/lib/libc/locale/euc.4 @@ -38,7 +38,7 @@ .Dt EUC 4 .Os .Sh NAME -.Nm euc +.Nm EUC .Nd EUC encoding of runes .Sh SYNOPSIS \fBENCODING "EUC"\fP diff --git a/lib/libc/locale/euc.c b/lib/libc/locale/euc.c index bc33ff64ef77..e58c8556087a 100644 --- a/lib/libc/locale/euc.c +++ b/lib/libc/locale/euc.c @@ -34,7 +34,6 @@ * SUCH DAMAGE. */ -#ifdef XPG4 #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)euc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -219,4 +218,3 @@ CodeSet1: } return (len); } -#endif /* XPG4 */ diff --git a/lib/libc/locale/isupper.3 b/lib/libc/locale/isupper.3 index f8fb41305914..6035f0915f32 100644 --- a/lib/libc/locale/isupper.3 +++ b/lib/libc/locale/isupper.3 @@ -69,6 +69,6 @@ returns non-zero if the character tests true. .Xr ascii 7 .Sh STANDARDS The -.Fn isupper +.Xr isupper function conforms to .St -ansiC . diff --git a/lib/libc/locale/none.c b/lib/libc/locale/none.c index 41f70aef7a10..b5d8e44299cd 100644 --- a/lib/libc/locale/none.c +++ b/lib/libc/locale/none.c @@ -64,6 +64,8 @@ _none_sgetrune(string, n, result) size_t n; char const **result; { + int c; + if (n < 1) { if (result) *result = string; diff --git a/lib/libc/locale/rune.c b/lib/libc/locale/rune.c index bc4d07cf2c24..8075825bd7fa 100644 --- a/lib/libc/locale/rune.c +++ b/lib/libc/locale/rune.c @@ -38,136 +38,70 @@ static char sccsid[] = "@(#)rune.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include <ctype.h> +#include <errno.h> +#include <limits.h> #include <rune.h> #include <stdio.h> -#include <string.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/stat.h> +#include "common_rune.h" -_RuneLocale * -_Read_RuneMagi(fp) - FILE *fp; -{ - char *data; - void *lastp; - _RuneLocale *rl; - _RuneEntry *rr; - struct stat sb; - int x; - - if (fstat(fileno(fp), &sb) < 0) - return(0); - - if (sb.st_size < sizeof(_RuneLocale)) - return(0); - - if ((data = malloc(sb.st_size)) == NULL) - return(0); - - rewind(fp); /* Someone might have read the magic number once already */ - - if (fread(data, sb.st_size, 1, fp) != 1) { - free(data); - return(0); - } - - rl = (_RuneLocale *)data; - lastp = data + sb.st_size; +char *_PathLocale; - rl->variable = rl + 1; - - if (memcmp(rl->magic, _RUNE_MAGIC_1, sizeof(rl->magic))) { - free(data); - return(0); - } +extern int _none_init __P((_RuneLocale *)); +extern int _UTF2_init __P((_RuneLocale *)); +extern int _EUC_init __P((_RuneLocale *)); - rl->invalid_rune = ntohl(rl->invalid_rune); - rl->variable_len = ntohl(rl->variable_len); - rl->runetype_ext.nranges = ntohl(rl->runetype_ext.nranges); - rl->maplower_ext.nranges = ntohl(rl->maplower_ext.nranges); - rl->mapupper_ext.nranges = ntohl(rl->mapupper_ext.nranges); - - for (x = 0; x < _CACHED_RUNES; ++x) { - rl->runetype[x] = ntohl(rl->runetype[x]); - rl->maplower[x] = ntohl(rl->maplower[x]); - rl->mapupper[x] = ntohl(rl->mapupper[x]); - } - - rl->runetype_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->runetype_ext.ranges + rl->runetype_ext.nranges; - if (rl->variable > lastp) { - free(data); - return(0); - } +int +setrunelocale(encoding) + char *encoding; +{ + FILE *fp; + char name[PATH_MAX]; + _RuneLocale *rl; - rl->maplower_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->maplower_ext.ranges + rl->maplower_ext.nranges; - if (rl->variable > lastp) { - free(data); - return(0); - } + if (!encoding) + return(EFAULT); - rl->mapupper_ext.ranges = (_RuneEntry *)rl->variable; - rl->variable = rl->mapupper_ext.ranges + rl->mapupper_ext.nranges; - if (rl->variable > lastp) { - free(data); + /* + * The "C" and "POSIX" locale are always here. + */ + if (!strcmp(encoding, "C") || !strcmp(encoding, "POSIX")) { + _CurrentRuneLocale = &_DefaultRuneLocale; return(0); } - for (x = 0; x < rl->runetype_ext.nranges; ++x) { - rr = rl->runetype_ext.ranges; - - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - if ((rr[x].map = ntohl(rr[x].map)) == 0) { - int len = rr[x].max - rr[x].min + 1; - rr[x].types = rl->variable; - rl->variable = rr[x].types + len; - if (rl->variable > lastp) { - free(data); - return(0); - } - while (len-- > 0) - rr[x].types[len] = ntohl(rr[x].types[len]); - } else - rr[x].types = 0; - } + if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE"))) + PathLocale = _PATH_LOCALE; - for (x = 0; x < rl->maplower_ext.nranges; ++x) { - rr = rl->maplower_ext.ranges; - - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - rr[x].map = ntohl(rr[x].map); - } + (void) strcpy(name, PathLocale); + (void) strcat(name, "/"); + (void) strcat(name, encoding); + (void) strcat(name, "/LC_CTYPE"); - for (x = 0; x < rl->mapupper_ext.nranges; ++x) { - rr = rl->mapupper_ext.ranges; + if ((fp = fopen(name, "r")) == NULL) + return(ENOENT); - rr[x].min = ntohl(rr[x].min); - rr[x].max = ntohl(rr[x].max); - rr[x].map = ntohl(rr[x].map); + if ((rl = _Read_RuneMagi(fp)) == 0) { + fclose(fp); + return(EFTYPE); } - if (((char *)rl->variable) + rl->variable_len > (char *)lastp) { - free(data); - return(0); - } - - /* - * Go out and zero pointers that should be zero. - */ - if (!rl->variable_len) - rl->variable = 0; - - if (!rl->runetype_ext.nranges) - rl->runetype_ext.ranges = 0; - - if (!rl->maplower_ext.nranges) - rl->maplower_ext.ranges = 0; - - if (!rl->mapupper_ext.nranges) - rl->mapupper_ext.ranges = 0; + fclose(fp); + + if (!rl->encoding[0] || !strcmp(rl->encoding, "UTF2")) { + return(_UTF2_init(rl)); + } else if (!strcmp(rl->encoding, "NONE")) { + return(_none_init(rl)); + } else if (!strcmp(rl->encoding, "EUC")) { + return(_EUC_init(rl)); + } else + return(EINVAL); +} - return(rl); +void +setinvalidrune(ir) + rune_t ir; +{ + _INVALID_RUNE = ir; } + diff --git a/lib/libc/locale/runetype.c b/lib/libc/locale/runetype.c index 282f806c2466..b2c0e391f4e2 100644 --- a/lib/libc/locale/runetype.c +++ b/lib/libc/locale/runetype.c @@ -1,54 +1,16 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 <rune.h> unsigned long ___runetype(c) - _BSD_CT_RUNE_T_ c; + _BSD_RUNE_T_ c; { -#ifdef XPG4 int x; _RuneRange *rr = &_CurrentRuneLocale->runetype_ext; _RuneEntry *re = rr->ranges; - if (c < 0 || c == EOF) - return(0L); - + if (c == EOF) + return(0); for (x = 0; x < rr->nranges; ++x, ++re) { if (c < re->min) return(0L); @@ -59,6 +21,6 @@ ___runetype(c) return(re->map); } } -#endif return(0L); } + diff --git a/lib/libc/locale/setlocale.c b/lib/libc/locale/setlocale.c index 11f21398e76f..dc8157af0c64 100644 --- a/lib/libc/locale/setlocale.c +++ b/lib/libc/locale/setlocale.c @@ -43,49 +43,13 @@ static char sccsid[] = "@(#)setlocale.c 8.1 (Berkeley) 7/4/93"; #include <rune.h> #include <stdlib.h> #include <string.h> -#include "collate.h" +#include "common_setlocale.h" +#include "common_rune.h" -/* - * Category names for getenv() - */ -static char *categories[_LC_LAST] = { - "LC_ALL", - "LC_COLLATE", - "LC_CTYPE", - "LC_MONETARY", - "LC_NUMERIC", - "LC_TIME", -}; - -/* - * Current locales for each category - */ -static char current_categories[_LC_LAST][32] = { - "C", - "C", - "C", - "C", - "C", - "C", -}; - -/* - * The locales we are going to try and load - */ -static char new_categories[_LC_LAST][32]; - -static char current_locale_string[_LC_LAST * 33]; char *_PathLocale; -static char *currentlocale __P((void)); static char *loadlocale __P((int)); -extern int __time_load_locale __P((const char *)); /* strftime.c */ - -#ifdef XPG4 -extern int _xpg4_setrunelocale __P((char *)); -#endif - char * setlocale(category, locale) int category; @@ -94,8 +58,8 @@ setlocale(category, locale) int found, i, len; char *env, *r; - if (!_PathLocale && !(_PathLocale = getenv("PATH_LOCALE"))) - _PathLocale = _PATH_LOCALE; + if (!PathLocale && !(PathLocale = getenv("PATH_LOCALE"))) + PathLocale = _PATH_LOCALE; if (category < 0 || category >= _LC_LAST) return (NULL); @@ -175,47 +139,6 @@ setlocale(category, locale) return (NULL); } -/* To be compatible with crt0 hack */ -void -_startup_setlocale(category, locale) - int category; - const char *locale; -{ -#ifndef XPG4 - (void) setlocale(category, locale); -#endif -} - -static char * -currentlocale() -{ - int i, len; - - (void)strcpy(current_locale_string, current_categories[1]); - - for (i = 2; i < _LC_LAST; ++i) - if (strcmp(current_categories[1], current_categories[i])) { - len = strlen(current_categories[1]) + 1 + - strlen(current_categories[2]) + 1 + - strlen(current_categories[3]) + 1 + - strlen(current_categories[4]) + 1 + - strlen(current_categories[5]) + 1; - if (len > sizeof(current_locale_string)) - return NULL; - (void) strcpy(current_locale_string, current_categories[1]); - (void) strcat(current_locale_string, "/"); - (void) strcat(current_locale_string, current_categories[2]); - (void) strcat(current_locale_string, "/"); - (void) strcat(current_locale_string, current_categories[3]); - (void) strcat(current_locale_string, "/"); - (void) strcat(current_locale_string, current_categories[4]); - (void) strcat(current_locale_string, "/"); - (void) strcat(current_locale_string, current_categories[5]); - break; - } - return (current_locale_string); -} - static char * loadlocale(category) int category; @@ -228,11 +151,7 @@ loadlocale(category) return (current_categories[category]); if (category == LC_CTYPE) { -#ifdef XPG4 - if (_xpg4_setrunelocale(new_categories[LC_CTYPE])) -#else if (setrunelocale(new_categories[LC_CTYPE])) -#endif return (NULL); (void)strcpy(current_categories[LC_CTYPE], new_categories[LC_CTYPE]); @@ -272,13 +191,11 @@ loadlocale(category) * Some day we will actually look at this file. */ (void)snprintf(name, sizeof(name), "%s/%s/%s", - _PathLocale, new_categories[category], categories[category]); + PathLocale, new_categories[category], categories[category]); #endif switch (category) { case LC_MONETARY: case LC_NUMERIC: return (NULL); } - /* Just in case...*/ - return (NULL); } diff --git a/lib/libc/locale/table.c b/lib/libc/locale/table.c index 9424a5812a1b..fb7344eafad5 100644 --- a/lib/libc/locale/table.c +++ b/lib/libc/locale/table.c @@ -38,6 +38,8 @@ static char sccsid[] = "@(#)table.c 8.1 (Berkeley) 6/27/93"; #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> + #include <ctype.h> #include <rune.h> @@ -84,38 +86,6 @@ _RuneLocale _DefaultRuneLocale = { _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, /*78*/ _L|_R|_G|_A, _L|_R|_G|_A, _L|_R|_G|_A, _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, _C, - /*80*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*88*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*90*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*98*/ _C, _C, _C, _C, - _C, _C, _C, _C, - /*A0*/ _R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*A8*/ _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*B0*/ _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*B8*/ _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - _P|_R|_G, _P|_R|_G, _P|_R|_G, _P|_R|_G, - /*C0*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, - /*C8*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, - /*D0*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _P|_R|_G, - /*D8*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, - /*E0*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, - /*E8*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, - /*F0*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _P|_R|_G, - /*F8*/ _R|_G, _R|_G, _R|_G, _R|_G, - _R|_G, _R|_G, _R|_G, _R|_G, }, { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, diff --git a/lib/libc/locale/tolower.c b/lib/libc/locale/tolower.c index 65d5175a7b3c..995cdceab0f1 100644 --- a/lib/libc/locale/tolower.c +++ b/lib/libc/locale/tolower.c @@ -1,60 +1,23 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 <rune.h> -_BSD_CT_RUNE_T_ +_BSD_RUNE_T_ ___tolower(c) - _BSD_CT_RUNE_T_ c; + _BSD_RUNE_T_ c; { -#ifdef XPG4 int x; _RuneRange *rr = &_CurrentRuneLocale->maplower_ext; _RuneEntry *re = rr->ranges; - if (c < 0 || c == EOF) - return(c); - + if (c == EOF) + return(EOF); for (x = 0; x < rr->nranges; ++x, ++re) { if (c < re->min) return(c); if (c <= re->max) return(re->map + c - re->min); } -#endif return(c); } + + diff --git a/lib/libc/locale/toupper.c b/lib/libc/locale/toupper.c index d2e4480d8fad..1f6c722a6bd8 100644 --- a/lib/libc/locale/toupper.c +++ b/lib/libc/locale/toupper.c @@ -1,60 +1,22 @@ -/*- - * Copyright (c) 1993 - * The Regents of the University of California. All rights reserved. - * - * This code is derived from software contributed to Berkeley by - * Paul Borman at Krystal Technologies. - * - * 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. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. 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 <rune.h> -_BSD_CT_RUNE_T_ +_BSD_RUNE_T_ ___toupper(c) - _BSD_CT_RUNE_T_ c; + _BSD_RUNE_T_ c; { -#ifdef XPG4 int x; _RuneRange *rr = &_CurrentRuneLocale->mapupper_ext; _RuneEntry *re = rr->ranges; - if (c < 0 || c == EOF) - return(c); - + if (c == EOF) + return(EOF); for (x = 0; x < rr->nranges; ++x, ++re) { if (c < re->min) return(c); if (c <= re->max) return(re->map + c - re->min); } -#endif return(c); } + diff --git a/lib/libc/locale/utf2.4 b/lib/libc/locale/utf2.4 index e2cf8cc905e3..20a95877d884 100644 --- a/lib/libc/locale/utf2.4 +++ b/lib/libc/locale/utf2.4 @@ -38,7 +38,7 @@ .Dt UTF2 4 .Os .Sh NAME -.Nm utf2 +.Nm UTF2 .Nd "Universal character set Transformation Format encoding of runes .Sh SYNOPSIS \fBENCODING "UTF2"\fP diff --git a/lib/libc/locale/utf2.c b/lib/libc/locale/utf2.c index c46dd93b6125..846fad90ed6f 100644 --- a/lib/libc/locale/utf2.c +++ b/lib/libc/locale/utf2.c @@ -34,7 +34,6 @@ * SUCH DAMAGE. */ -#ifdef XPG4 #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)utf2.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -147,4 +146,3 @@ _UTF2_sputrune(c, string, n, result) return (1); } } -#endif /* XPG4 */ diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 4c9bd23c584a..4bcd68265e64 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -8,20 +8,16 @@ SRCS+= gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ getproto.c getprotoent.c getprotoname.c getservbyname.c \ getservbyport.c getservent.c herror.c inet_addr.c inet_lnaof.c \ inet_makeaddr.c inet_netof.c inet_network.c inet_ntoa.c \ - linkaddr.c rcmd.c recv.c res_comp.c res_data.c res_debug.c \ - res_init.c res_mkquery.c res_query.c res_send.c send.c ether_addr.c - -# iso_addr.c -# ns_addr.c ns_ntoa.c + iso_addr.c linkaddr.c ns_addr.c ns_ntoa.c rcmd.c recv.c res_comp.c \ + res_debug.c res_init.c res_mkquery.c res_query.c res_send.c \ + send.c ether_addr.c # machine-dependent net sources .include "${.CURDIR}/${MACHINE}/net/Makefile.inc" MAN3+= net/byteorder.3 net/ethers.3 net/gethostbyname.3 net/getnetent.3 \ net/getprotoent.3 net/getservent.3 net/inet.3 net/linkaddr.3 \ - net/rcmd.3 net/resolver.3 - -# not installed: net/ns.3 net/iso_addr.3 + net/ns.3 net/rcmd.3 net/resolver.3 MLINKS+=byteorder.3 htonl.3 byteorder.3 htons.3 byteorder.3 ntohl.3 \ byteorder.3 ntohs.3 @@ -39,8 +35,8 @@ MLINKS+=getservent.3 endservent.3 getservent.3 getservbyname.3 \ MLINKS+=inet.3 addr.3 inet.3 inet_addr.3 inet.3 inet_lnaof.3 \ inet.3 inet_makeaddr.3 inet.3 inet_netof.3 inet.3 inet_network.3 \ inet.3 inet_ntoa.3 inet.3 network.3 inet.3 ntoa.3 inet.3 inet_aton.3 -MLINKS+=linkaddr.3 link_addr.3 linkaddr.3 link_ntoa.3 -#MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 +MLINKS+=linkaddr.3 linkntoa.3 +MLINKS+=ns.3 ns_addr.3 ns.3 ns_ntoa.3 MLINKS+=rcmd.3 rresvport.3 rcmd.3 iruserok.3 rcmd.3 ruserok.3 MLINKS+=resolver.3 dn_comp.3 resolver.3 dn_expand.3 resolver.3 res_init.3 \ resolver.3 res_mkquery.3 resolver.3 res_send.3 resolver.3 res_query.3 \ diff --git a/lib/libc/net/ether_addr.c b/lib/libc/net/ether_addr.c index ded2ce349d14..b287f2e361e4 100644 --- a/lib/libc/net/ether_addr.c +++ b/lib/libc/net/ether_addr.c @@ -147,6 +147,7 @@ int ether_ntohost(hostname, e) ether_a = ether_ntoa(e); if (yp_match(yp_domain, "ethers.byaddr", ether_a, strlen(ether_a), &result, &resultlen)) { + free(result); continue; } strncpy((char *)&buf, result, resultlen); @@ -196,6 +197,7 @@ int ether_hostton(hostname, e) continue; if (yp_match(yp_domain, "ethers.byname", hostname, strlen(hostname), &result, &resultlen)) { + free(result); continue; } strncpy((char *)&buf, result, resultlen); diff --git a/lib/libc/net/ethers.3 b/lib/libc/net/ethers.3 index a24f177abdf7..0ee4b6c912d1 100644 --- a/lib/libc/net/ethers.3 +++ b/lib/libc/net/ethers.3 @@ -169,8 +169,8 @@ maps in addition to the data in the .Pa /etc/ethers file. .Sh SEE ALSO -.Xr yp 4 , -.Xr ethers 5 +.Xr ethers 5 , +.Xr yp 8 .Sh BUGS .Pp The diff --git a/lib/libc/net/gethostbydns.c b/lib/libc/net/gethostbydns.c index 05ea8002ac78..4f8bb090f8c8 100644 --- a/lib/libc/net/gethostbydns.c +++ b/lib/libc/net/gethostbydns.c @@ -63,7 +63,6 @@ static char rcsid[] = "$Id: gethostbydns.c,v 1.4.4.1 1995/08/30 04:06:40 davidg #include <arpa/nameser.h> #include <stdio.h> -#include <unistd.h> #include <string.h> #include <netdb.h> #include <resolv.h> @@ -76,8 +75,10 @@ static char rcsid[] = "$Id: gethostbydns.c,v 1.4.4.1 1995/08/30 04:06:40 davidg #define MAXALIASES 35 #define MAXADDRS 35 +#define MULTI_PTRS_ARE_ALIASES 1 /* XXX - experimental */ + static const char AskedForGot[] = - "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; + "gethostby*.gethostanswer: asked for \"%s\", got \"%s\""; static char *h_addr_ptrs[MAXADDRS + 1]; @@ -88,10 +89,6 @@ static struct in_addr host_addr; static FILE *hostf = NULL; static int stayopen = 0; -#ifdef RESOLVSORT -static void addrsort __P((char **, int)); -#endif - #if PACKETSZ > 1024 #define MAXPACKET PACKETSZ #else @@ -128,6 +125,51 @@ dprintf(msg, num) #endif +#ifdef RESOLVSORT +static void +addrsort(ap, num) + char **ap; + int num; +{ + int i, j; + char **p; + short aval[MAXADDRS]; + int needsort = 0; + + p = ap; + for (i = 0; i < num; i++, p++) { + for (j = 0 ; (unsigned)j < _res.nsort; j++) + if (_res.sort_list[j].addr.s_addr == + (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) + break; + aval[i] = j; + if (needsort == 0 && i > 0 && j < aval[i-1]) + needsort = i; + } + if (!needsort) + return; + + while (needsort < num) { + for (j = needsort - 1; j >= 0; j--) { + if (aval[j] > aval[j+1]) { + char *hp; + + i = aval[j]; + aval[j] = aval[j+1]; + aval[j+1] = i; + + hp = ap[j]; + ap[j] = ap[j+1]; + ap[j+1] = hp; + + } else + break; + } + needsort++; + } +} +#endif + static struct hostent * gethostanswer(answer, anslen, qname, qclass, qtype) const querybuf *answer; @@ -144,9 +186,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype) int haveanswer, had_error; int toobig = 0; char tbuf[MAXDNAME+1]; - const char *tname; - tname = qname; host.h_name = NULL; eom = answer->buf + anslen; /* @@ -184,9 +224,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype) host.h_aliases = host_aliases; hap = h_addr_ptrs; *hap = NULL; -#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ host.h_addr_list = h_addr_ptrs; -#endif haveanswer = 0; had_error = 0; while (ancount-- > 0 && cp < eom && !had_error) { @@ -218,7 +256,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype) cp += n; if (host.h_name && strcasecmp(host.h_name, bp) != 0) { syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.gethostanswer: asked for \"%s\", got CNAME for \"%s\"", + "gethostby*.gethostanswer: asked for \"%s\", got CNAME for \"%s\"", host.h_name, bp); continue; /* XXX - had_error++ ? */ } @@ -239,36 +277,19 @@ gethostanswer(answer, anslen, qname, qclass, qtype) buflen -= n; continue; } - if (qtype == T_PTR && type == T_CNAME) { - n = dn_expand(answer->buf, eom, cp, tbuf, sizeof tbuf); - if (n < 0) { - had_error++; - continue; - } - cp += n; - /* Get canonical name. */ - n = strlen(tbuf) + 1; /* for the \0 */ - if (n > buflen) { - had_error++; - continue; - } - strcpy(bp, tbuf); - tname = bp; - bp += n; - buflen -= n; - continue; - } if (type != qtype) { + /* CNAME->PTR should not cause a log message. */ + if (!(qtype == T_PTR && type == T_CNAME)) syslog(LOG_NOTICE|LOG_AUTH, - "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"", - qname, p_class(qclass), p_type(qtype), - p_type(type)); + "gethostby*.gethostanswer: asked for \"%s %s %s\", got type \"%s\"", + qname, p_class(qclass), p_type(qtype), + p_type(type)); cp += n; continue; /* XXX - had_error++ ? */ } switch (type) { case T_PTR: - if (strcasecmp(tname, bp) != 0) { + if (strcasecmp(qname, bp) != 0) { syslog(LOG_NOTICE|LOG_AUTH, AskedForGot, qname, bp); cp += n; @@ -279,7 +300,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype) had_error++; break; } -#ifdef MULTI_PTRS_ARE_ALIASES +#if MULTI_PTRS_ARE_ALIASES cp += n; if (!haveanswer) host.h_name = bp; @@ -333,7 +354,7 @@ gethostanswer(answer, anslen, qname, qclass, qtype) if (hap >= &h_addr_ptrs[MAXADDRS-1]) { if (!toobig++) dprintf("Too many addresses (%d)\n", - MAXADDRS); + MAXADDRS); cp += n; continue; } @@ -362,11 +383,6 @@ gethostanswer(answer, anslen, qname, qclass, qtype) qclass == C_IN && qtype == T_A) addrsort(h_addr_ptrs, haveanswer); # endif /*RESOLVSORT*/ -#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ - /* nothing */ -#else - host.h_addr = h_addr_ptrs[0]; -#endif /*BSD*/ if (!host.h_name) { n = strlen(qname) + 1; /* for the \0 */ strcpy(bp, qname); @@ -428,15 +444,10 @@ _gethostbydnsname(name) host.h_length = INT32SZ; h_addr_ptrs[0] = (char *)&host_addr; h_addr_ptrs[1] = NULL; -#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ host.h_addr_list = h_addr_ptrs; -#else - host.h_addr = h_addr_ptrs[0]; -#endif - h_errno = NETDB_SUCCESS; return (&host); } - if (!isdigit(*cp) && *cp != '.') + if (!isdigit(*cp) && *cp != '.') break; } @@ -462,7 +473,7 @@ _gethostbydnsaddr(addr, len, type) u_long old_options; char hname2[MAXDNAME+1]; #endif /*SUNSECURITY*/ - + if ((_res.options & RES_INIT) == 0 && res_init() == -1) { h_errno = NETDB_INTERNAL; return (NULL); @@ -523,56 +534,10 @@ _gethostbydnsaddr(addr, len, type) return (hp); } -#ifdef RESOLVSORT -static void -addrsort(ap, num) - char **ap; - int num; -{ - int i, j; - char **p; - short aval[MAXADDRS]; - int needsort = 0; - - p = ap; - for (i = 0; i < num; i++, p++) { - for (j = 0 ; (unsigned)j < _res.nsort; j++) - if (_res.sort_list[j].addr.s_addr == - (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask)) - break; - aval[i] = j; - if (needsort == 0 && i > 0 && j < aval[i-1]) - needsort = i; - } - if (!needsort) - return; - - while (needsort < num) { - for (j = needsort - 1; j >= 0; j--) { - if (aval[j] > aval[j+1]) { - char *hp; - - i = aval[j]; - aval[j] = aval[j+1]; - aval[j+1] = i; - - hp = ap[j]; - ap[j] = ap[j+1]; - ap[j+1] = hp; - - } else - break; - } - needsort++; - } -} -#endif void _sethostdnsent(stayopen) int stayopen; { - if ((_res.options & RES_INIT) == 0 && res_init() == -1) - return; if (stayopen) _res.options |= RES_STAYOPEN | RES_USEVC; } diff --git a/lib/libc/net/gethostbyht.c b/lib/libc/net/gethostbyht.c index 9f1fa4c7acc2..97f8d1f484f1 100644 --- a/lib/libc/net/gethostbyht.c +++ b/lib/libc/net/gethostbyht.c @@ -67,20 +67,21 @@ static char rcsid[] = "$Id: gethostbyht.c,v 1.2 1995/05/30 05:40:44 rgrimes Exp #include <string.h> #define MAXALIASES 35 +#define MAXADDRS 35 static struct hostent host; static char *host_aliases[MAXALIASES]; static char hostbuf[BUFSIZ+1]; static FILE *hostf = NULL; -static struct in_addr host_addr; -static char *h_addr_ptrs[2]; +static char hostaddr[MAXADDRS]; +static char *host_addrs[2]; static int stayopen = 0; void _sethosthtent(f) int f; { - if (!hostf) + if (hostf == NULL) hostf = fopen(_PATH_HOSTS, "r" ); else rewind(hostf); @@ -102,40 +103,33 @@ gethostent() char *p; register char *cp, **q; - if (!hostf && !(hostf = fopen(_PATH_HOSTS, "r" ))) { - h_errno = NETDB_INTERNAL; + if (hostf == NULL && (hostf = fopen(_PATH_HOSTS, "r" )) == NULL) return (NULL); - } again: - if (!(p = fgets(hostbuf, sizeof hostbuf, hostf))) { - h_errno = HOST_NOT_FOUND; + if ((p = fgets(hostbuf, BUFSIZ, hostf)) == NULL) return (NULL); - } if (*p == '#') goto again; - if (!(cp = strpbrk(p, "#\n"))) + cp = strpbrk(p, "#\n"); + if (cp == NULL) goto again; *cp = '\0'; - if (!(cp = strpbrk(p, " \t"))) + cp = strpbrk(p, " \t"); + if (cp == NULL) goto again; *cp++ = '\0'; /* THIS STUFF IS INTERNET SPECIFIC */ - if (!inet_aton(p, &host_addr)) - goto again; - h_addr_ptrs[0] = (char *)&host_addr; - h_addr_ptrs[1] = NULL; -#if BSD >= 43 || defined(h_addr) /* new-style hostent structure */ - host.h_addr_list = h_addr_ptrs; -#else - host.h_addr = h_addr_ptrs[0]; -#endif - host.h_length = sizeof(u_int32_t); + host.h_addr_list = host_addrs; + host.h_addr = hostaddr; + *((u_int32_t *)host.h_addr) = inet_addr(p); + host.h_length = sizeof (u_int32_t); host.h_addrtype = AF_INET; while (*cp == ' ' || *cp == '\t') cp++; host.h_name = cp; q = host.h_aliases = host_aliases; - if (cp = strpbrk(cp, " \t")) + cp = strpbrk(cp, " \t"); + if (cp != NULL) *cp++ = '\0'; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { @@ -144,11 +138,11 @@ again: } if (q < &host_aliases[MAXALIASES - 1]) *q++ = cp; - if (cp = strpbrk(cp, " \t")) + cp = strpbrk(cp, " \t"); + if (cp != NULL) *cp++ = '\0'; } *q = NULL; - h_errno = NETDB_SUCCESS; return (&host); } @@ -158,9 +152,9 @@ _gethostbyhtname(name) { register struct hostent *p; register char **cp; - + sethostent(0); - while (p = gethostent()) { + while ((p = gethostent())) { if (strcasecmp(p->h_name, name) == 0) break; for (cp = p->h_aliases; *cp != 0; cp++) @@ -180,10 +174,9 @@ _gethostbyhtaddr(addr, len, type) register struct hostent *p; sethostent(0); - while (p = gethostent()) + while ((p = gethostent())) if (p->h_addrtype == type && !bcmp(p->h_addr, addr, len)) break; endhostent(); return (p); } - diff --git a/lib/libc/net/gethostbynis.c b/lib/libc/net/gethostbynis.c index f01f1052f36e..397e2fa4308c 100644 --- a/lib/libc/net/gethostbynis.c +++ b/lib/libc/net/gethostbynis.c @@ -37,11 +37,6 @@ static char rcsid[] = "$Id: gethostbynis.c,v 1.1 1994/09/25 02:12:14 pst Exp $"; #include <ctype.h> #include <errno.h> #include <string.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif #define MAXALIASES 35 #define MAXADDRS 35 @@ -62,7 +57,6 @@ _gethostbynis(name, map) int resultlen; static struct hostent h; static char *domain = (char *)NULL; - static char ypbuf[YPMAXRECORD]; if (domain == (char *)NULL) if (yp_get_default_domain (&domain)) @@ -71,11 +65,6 @@ _gethostbynis(name, map) if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) return ((struct hostent *)NULL); - /* avoid potential memory leak */ - bcopy((char *)result, (char *)&ypbuf, resultlen); - free(result); - result = (char *)&ypbuf; - if ((cp = index(result, '\n'))) *cp = '\0'; @@ -119,10 +108,8 @@ _gethostbynisname(name) } struct hostent * -_gethostbynisaddr(addr, len, type) - char *addr; - int len; - int type; +_gethostbynisaddr(name) + char *name; { - return _gethostbynis(inet_ntoa(*(struct in_addr *)addr),"hosts.byaddr"); + return _gethostbynis(name, "hosts.byaddr"); } diff --git a/lib/libc/net/getnetbydns.c b/lib/libc/net/getnetbydns.c index 92d1d4aa5204..6b3eb44a3011 100644 --- a/lib/libc/net/getnetbydns.c +++ b/lib/libc/net/getnetbydns.c @@ -50,13 +50,6 @@ * - * --Copyright-- */ -/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)gethostnamadr.c 8.1 (Berkeley) 6/4/93"; @@ -68,23 +61,19 @@ static char rcsid[] = "$Id: getnetbydns.c,v 1.3 1995/05/30 05:40:46 rgrimes Exp #include <netinet/in.h> #include <arpa/inet.h> #include <arpa/nameser.h> - -#include <stdio.h> #include <netdb.h> #include <resolv.h> +#include <stdio.h> #include <ctype.h> #include <errno.h> #include <string.h> -#include <unistd.h> #include <syslog.h> -#include "res_config.h" +#define BYNAME 0 +#define BYADDR 1 -extern int h_errno; - -#define BYADDR 0 -#define BYNAME 1 #define MAXALIASES 35 +#define MAXADDRS 35 #if PACKETSZ > 1024 #define MAXPACKET PACKETSZ @@ -93,15 +82,17 @@ extern int h_errno; #endif typedef union { - HEADER hdr; - u_char buf[MAXPACKET]; + HEADER hdr; + u_char buf[MAXPACKET]; } querybuf; typedef union { - long al; - char ac; + int32_t al; + char ac; } align; +extern int h_errno; + static struct netent * getnetanswer(answer, anslen, net_i) querybuf *answer; @@ -109,15 +100,20 @@ getnetanswer(answer, anslen, net_i) int net_i; { - register HEADER *hp; - register u_char *cp; - register int n; - u_char *eom; - int type, class, buflen, ancount, qdcount, haveanswer, i, nchar; - char aux1[30], aux2[30], ans[30], *in, *st, *pauxt, *bp, **ap, - *paux1 = &aux1[0], *paux2 = &aux2[0], flag = 0; -static struct netent net_entry; -static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; + register HEADER *hp; + register u_char *cp; + register int n; + u_char *eom; + int type, class, buflen, ancount, qdcount, + haveanswer, i, nchar; + char aux1[30], aux2[30], ans[30], + *in, *st, *pauxt, *bp, **ap, + *paux1 = &aux1[0], + *paux2 = &aux2[0], + flag = 0; +static struct netent net_entry; +static char *net_aliases[MAXALIASES], + netbuf[BUFSIZ+1]; /* * find first satisfactory answer @@ -145,10 +141,12 @@ static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; h_errno = HOST_NOT_FOUND; else h_errno = TRY_AGAIN; - return (NULL); + + return ((struct netent *) NULL); } - while (qdcount-- > 0) + while (qdcount-- > 0){ cp += __dn_skipname(cp, eom) + QFIXEDSZ; + } ap = net_aliases; *ap = NULL; net_entry.n_aliases = net_aliases; @@ -170,26 +168,27 @@ static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; cp += n; return (NULL); } - cp += n; + cp += n; *ap++ = bp; - bp += strlen(bp) + 1; - net_entry.n_addrtype = - (class == C_IN) ? AF_INET : AF_UNSPEC; + bp += (strlen(bp) + 1); + net_entry.n_addrtype = (class == C_IN) + ? AF_INET + : AF_UNSPEC; haveanswer++; } } if (haveanswer) { *ap = NULL; switch (net_i) { - case BYADDR: + case BYADDR : net_entry.n_name = *net_entry.n_aliases; net_entry.n_net = 0L; break; - case BYNAME: + case BYNAME : in = *net_entry.n_aliases; net_entry.n_name = &ans[0]; aux2[0] = '\0'; - for (i = 0; i < 4; i++) { + for (i = 0; i < 4; i++) { for (st = in, nchar = 0; *st != '.'; st++, nchar++) @@ -197,23 +196,23 @@ static char *net_aliases[MAXALIASES], netbuf[BUFSIZ+1]; if (nchar != 1 || *in != '0' || flag) { flag = 1; (void)strncpy(paux1, - (i==0) ? in : in-1, - (i==0) ?nchar : nchar+1); - paux1[(i==0) ? nchar : nchar+1] = '\0'; + (i==0) ?in :in-1, + (i==0) ?nchar :nchar+1); + paux1[(i==0) ?nchar :nchar+1] = '\0'; pauxt = paux2; paux2 = strcat(paux1, paux2); paux1 = pauxt; } in = ++st; - } + } net_entry.n_net = inet_network(paux2); - break; } net_entry.n_aliases++; return (&net_entry); + } else { + h_errno = TRY_AGAIN; + return ((struct netent *) NULL); } - h_errno = TRY_AGAIN; - return (NULL); } struct netent * @@ -221,40 +220,41 @@ _getnetbydnsaddr(net, net_type) register long net; register int net_type; { - unsigned int netbr[4]; - int nn, anslen; - querybuf buf; - char qbuf[MAXDNAME]; - unsigned long net2; - struct netent *net_entry; + unsigned int netbr[4]; + int nn, anslen; + querybuf buf; + char qbuf[MAXDNAME]; + unsigned long net2; + struct netent *net_entry; if (net_type != AF_INET) return (NULL); - for (nn = 4, net2 = net; net2; net2 >>= 8) + for (nn = 4, net2 = net; net2; net2 >>= 8) { netbr[--nn] = net2 & 0xff; + } switch (nn) { - case 3: /* Class A */ - sprintf(qbuf, "0.0.0.%u.in-addr.arpa", netbr[3]); - break; - case 2: /* Class B */ - sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", netbr[3], netbr[2]); - break; - case 1: /* Class C */ - sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], - netbr[1]); - break; - case 0: /* Class D - E */ - sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", netbr[3], netbr[2], - netbr[1], netbr[0]); - break; + case 3: /* Class A */ + (void)sprintf(qbuf, "0.0.0.%u.in-addr.arpa", + netbr[3]); + break; + case 2: /* Class B */ + (void)sprintf(qbuf, "0.0.%u.%u.in-addr.arpa", + netbr[3], netbr[2]); + break; + case 1: /* Class C */ + (void)sprintf(qbuf, "0.%u.%u.%u.in-addr.arpa", + netbr[3], netbr[2], netbr[1]); + break; + case 0: /* Class D - E */ + (void)sprintf(qbuf, "%u.%u.%u.%u.in-addr.arpa", + netbr[3], netbr[2], netbr[1], netbr[0]); + break; } - anslen = res_query(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + anslen = res_query(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf); if (anslen < 0) { -#ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_query failed\n"); -#endif return (NULL); } net_entry = getnetanswer(&buf, anslen, BYADDR); @@ -262,34 +262,28 @@ _getnetbydnsaddr(net, net_type) unsigned u_net = net; /* maybe net should be unsigned ? */ /* Strip trailing zeros */ - while ((u_net & 0xff) == 0 && u_net != 0) + while ((u_net & 0xff) == 0 && u_net != 0) { u_net >>= 8; + } net_entry->n_net = u_net; - return (net_entry); } - return (NULL); + return (net_entry); } struct netent * _getnetbydnsname(net) register const char *net; { - int anslen; - querybuf buf; - char qbuf[MAXDNAME]; + int anslen; + querybuf buf; + char qbuf[MAXDNAME]; - if ((_res.options & RES_INIT) == 0 && res_init() == -1) { - h_errno = NETDB_INTERNAL; - return (NULL); - } - strcpy(&qbuf[0], net); - anslen = res_search(qbuf, C_IN, T_PTR, (u_char *)&buf, sizeof(buf)); + (void)strcpy(&qbuf[0],net); + anslen = res_search(qbuf, C_IN, T_PTR, buf.buf, sizeof buf.buf); if (anslen < 0) { -#ifdef DEBUG if (_res.options & RES_DEBUG) printf("res_query failed\n"); -#endif - return (NULL); + return NULL; } return getnetanswer(&buf, anslen, BYNAME); } diff --git a/lib/libc/net/getnetbyht.c b/lib/libc/net/getnetbyht.c index 24ca2ed11805..4f6439cc77df 100644 --- a/lib/libc/net/getnetbyht.c +++ b/lib/libc/net/getnetbyht.c @@ -31,16 +31,6 @@ * SUCH DAMAGE. */ -/* Portions Copyright (c) 1993 Carlos Leandro and Rui Salgueiro - * Dep. Matematica Universidade de Coimbra, Portugal, Europe - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * from getnetent.c 1.1 (Coimbra) 93/06/02 - */ - #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ @@ -49,7 +39,6 @@ static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> -#include <arpa/nameser.h> #include <netdb.h> #include <stdio.h> #include <string.h> @@ -66,7 +55,6 @@ void _setnethtent(f) int f; { - if (netf == NULL) netf = fopen(_PATH_NETWORKS, "r" ); else @@ -77,7 +65,6 @@ _setnethtent(f) void _endnethtent() { - if (netf) { fclose(netf); netf = NULL; @@ -116,7 +103,7 @@ again: net.n_net = inet_network(cp); net.n_addrtype = AF_INET; q = net.n_aliases = net_aliases; - if (p != NULL) + if (p != NULL) cp = p; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { @@ -141,7 +128,7 @@ _getnetbyhtname(name) register char **cp; setnetent(_net_stayopen); - while (p = getnetent()) { + while ((p = getnetent())) { if (strcasecmp(p->n_name, name) == 0) break; for (cp = p->n_aliases; *cp != 0; cp++) @@ -154,6 +141,7 @@ found: return (p); } + struct netent * _getnetbyhtaddr(net, type) register long net; @@ -162,7 +150,7 @@ _getnetbyhtaddr(net, type) register struct netent *p; setnetent(_net_stayopen); - while (p = getnetent()) + while ((p = getnetent())) if (p->n_addrtype == type && p->n_net == net) break; if (!_net_stayopen) diff --git a/lib/libc/net/getnetbynis.c b/lib/libc/net/getnetbynis.c index 51e026b1ce7d..85c719eb1b15 100644 --- a/lib/libc/net/getnetbynis.c +++ b/lib/libc/net/getnetbynis.c @@ -34,16 +34,9 @@ static char rcsid[] = "$Id: getnetbynis.c,v 1.3 1995/05/30 05:40:47 rgrimes Exp #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> -#include <stdlib.h> #include <ctype.h> #include <errno.h> #include <string.h> -#include <arpa/nameser.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -#endif #define MAXALIASES 35 #define MAXADDRS 35 @@ -62,19 +55,19 @@ _getnetbynis(name, map) int resultlen; static struct netent h; static char *domain = (char *)NULL; - static char ypbuf[YPMAXRECORD]; if (domain == (char *)NULL) if (yp_get_default_domain (&domain)) return (NULL); + if (result) { + free(result); + result = 0; + } + if (yp_match(domain, map, name, strlen(name), &result, &resultlen)) return (NULL); - bcopy((char *)result, (char *)&ypbuf, resultlen); - free(result); - result = (char *)&ypbuf; - if ((cp = index(result, '\n'))) *cp = '\0'; @@ -122,41 +115,19 @@ _getnetbynisaddr(addr, type) long addr; int type; { + struct in_addr in; char *str, *cp; - unsigned long net2; - int nn; - unsigned int netbr[4]; - char buf[MAXDNAME]; + struct netent *np; if (type != AF_INET) return (NULL); - for (nn = 4, net2 = addr; net2; net2 >>= 8) { - netbr[--nn] = net2 & 0xff; - } - - switch (nn) { - case 3: /* Class A */ - sprintf(buf, "%u", netbr[3]); - break; - case 2: /* Class B */ - sprintf(buf, "%u.%u", netbr[2], netbr[3]); - break; - case 1: /* Class C */ - sprintf(buf, "%u.%u.%u", netbr[1], netbr[2], netbr[3]); - break; - case 0: /* Class D - E */ - sprintf(buf, "%u.%u.%u.%u", netbr[0], netbr[1], - netbr[2], netbr[3]); - break; - } - - str = (char *)&buf; - cp = str + (strlen(str) - 2); - + in.s_addr = addr; + str = inet_ntoa(in); + cp = str + strlen(str) - 2; while(!strcmp(cp, ".0")) { *cp = '\0'; - cp = str + (strlen(str) - 2); + cp = str + strlen(str) - 2; } return _getnetbynis(str, "networks.byaddr"); diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c index 35e535a39467..6bee5d3a8beb 100644 --- a/lib/libc/net/getservent.c +++ b/lib/libc/net/getservent.c @@ -41,12 +41,6 @@ static char sccsid[] = "@(#)getservent.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <string.h> #include <stdlib.h> -#ifdef YP -#include <rpc/rpc.h> -#include <rpcsvc/yp_prot.h> -#include <rpcsvc/ypclnt.h> -static int serv_stepping_yp = 0; -#endif #define MAXALIASES 35 @@ -56,53 +50,6 @@ static struct servent serv; static char *serv_aliases[MAXALIASES]; int _serv_stayopen; -#ifdef YP -static int -_getypservent(line) - char *line; -{ - static char *key = NULL; - static int keylen; - static char *yp_domain = NULL; - char *lastkey, *result; - int resultlen; - int rv; - - if(!yp_domain) { - if(yp_get_default_domain(&yp_domain)) - return (0); - } - - if (!serv_stepping_yp) { - if (key) - free(key); - if ((rv = yp_first(yp_domain, "services.byname", &key, &keylen, - &result, &resultlen))) { - serv_stepping_yp = 0; - return(0); - } - serv_stepping_yp = 1; - } else { - lastkey = key; - rv = yp_next(yp_domain, "services.byname", key, keylen, &key, - &keylen, &result, &resultlen); - free(lastkey); - if (rv) { - serv_stepping_yp = 0; - return (0); - } - } - - strncpy(line, result, BUFSIZ - 1); - /* getservent() expects lines terminated with \n -- make it happy */ - strcat(line, "\n"); - - free(result); - - return(1); -} -#endif - void setservent(f) int f; @@ -130,25 +77,11 @@ getservent() char *p; register char *cp, **q; -#ifdef YP - if (serv_stepping_yp && _getypservent(line)) { - p = (char *)&line; - goto unpack; - } -tryagain: -#endif if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) return (NULL); again: if ((p = fgets(line, BUFSIZ, servf)) == NULL) return (NULL); -#ifdef YP - if (*p == '+') { - if (!_getypservent(&line)) - goto tryagain; - } -unpack: -#endif if (*p == '#') goto again; cp = strpbrk(p, "#\n"); diff --git a/lib/libc/net/herror.c b/lib/libc/net/herror.c index bf57c5546590..207445358c61 100644 --- a/lib/libc/net/herror.c +++ b/lib/libc/net/herror.c @@ -69,7 +69,7 @@ const char *h_errlist[] = { "Unknown server error", /* 3 NO_RECOVERY */ "No address associated with name", /* 4 NO_ADDRESS */ }; -int h_nerr = { sizeof h_errlist / sizeof h_errlist[0] }; +int h_nerr = { sizeof(h_errlist)/sizeof(h_errlist[0]) }; extern int h_errno; diff --git a/lib/libc/net/inet_addr.c b/lib/libc/net/inet_addr.c index a1ac89951970..f69d0fcd8c0f 100644 --- a/lib/libc/net/inet_addr.c +++ b/lib/libc/net/inet_addr.c @@ -1,9 +1,7 @@ /* - * ++Copyright++ 1983, 1990, 1993 - * - * Copyright (c) 1983, 1990, 1993 - * The Regents of the University of California. All rights reserved. - * + * The Regents of the University of California. All rights reserved. + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -14,12 +12,12 @@ * documentation and/or other materials provided with the distribution. * 3. All advertising materials mentioning features or use of this software * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. + * This product includes software developed by the University of + * California, Berkeley and its contributors. * 4. 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 @@ -31,31 +29,10 @@ * 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. - * - - * Portions Copyright (c) 1993 by Digital Equipment Corporation. - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies, and that - * the name of Digital Equipment Corporation not be used in advertising or - * publicity pertaining to distribution of the document or software without - * specific, written prior permission. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT - * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS - * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS - * SOFTWARE. - * - - * --Copyright-- */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)inet_addr.c 8.1 (Berkeley) 6/17/93"; -static char rcsid[] = "$Id$"; #endif /* LIBC_SCCS and not lint */ #include <sys/param.h> @@ -78,7 +55,7 @@ inet_addr(cp) return (INADDR_NONE); } -/* +/* * Check whether "cp" is a valid ascii representation * of an Internet address and convert to a binary address. * Returns 1 if the address is valid, 0 if not. @@ -96,52 +73,50 @@ inet_aton(cp, addr) u_int parts[4]; register u_int *pp = parts; - c = *cp; for (;;) { /* * Collect number up to ``.''. * Values are specified as for C: - * 0x=hex, 0=octal, isdigit=decimal. + * 0x=hex, 0=octal, other=decimal. */ - if (!isdigit(c)) - return (0); val = 0; base = 10; - if (c == '0') { - c = *++cp; - if (c == 'x' || c == 'X') - base = 16, c = *++cp; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; else base = 8; } - for (;;) { + while ((c = *cp) != '\0') { if (isascii(c) && isdigit(c)) { val = (val * base) + (c - '0'); - c = *++cp; - } else if (base == 16 && isascii(c) && isxdigit(c)) { - val = (val << 4) | + cp++; + continue; + } + if (base == 16 && isascii(c) && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); - c = *++cp; - } else - break; + cp++; + continue; + } + break; } - if (c == '.') { + if (*cp == '.') { /* * Internet format: * a.b.c.d - * a.b.c (with c treated as 16 bits) + * a.b.c (with c treated as 16-bits) * a.b (with b treated as 24 bits) */ - if (pp >= parts + 3) + if (pp >= parts + 3 || val > 0xff) return (0); - *pp++ = val; - c = *++cp; + *pp++ = val, cp++; } else break; } /* * Check for trailing characters. */ - if (c != '\0' && (!isascii(c) || !isspace(c))) + if (*cp && (!isascii(*cp) || !isspace(*cp))) return (0); /* * Concoct the address according to @@ -150,9 +125,6 @@ inet_aton(cp, addr) n = pp - parts + 1; switch (n) { - case 0: - return (0); /* initial nondigit */ - case 1: /* a -- 32 bits */ break; diff --git a/lib/libc/net/inet_network.c b/lib/libc/net/inet_network.c index c3a96a64e54e..fda53b6ecc61 100644 --- a/lib/libc/net/inet_network.c +++ b/lib/libc/net/inet_network.c @@ -74,7 +74,7 @@ again: break; } if (*cp == '.') { - if (pp >= parts + 3) + if (pp >= parts + 4) return (INADDR_NONE); *pp++ = val, cp++; goto again; @@ -83,6 +83,8 @@ again: return (INADDR_NONE); *pp++ = val; n = pp - parts; + if (n > 4) + return (INADDR_NONE); for (val = 0, i = 0; i < n; i++) { val <<= 8; val |= parts[i] & 0xff; diff --git a/lib/libc/net/linkaddr.3 b/lib/libc/net/linkaddr.3 index ae0410443903..54e320602954 100644 --- a/lib/libc/net/linkaddr.3 +++ b/lib/libc/net/linkaddr.3 @@ -75,7 +75,7 @@ may contain an optional network interface identifier of the form .Dq "name unit-number" , suitable for the first argument to -.Xr ifconfig 8 , +.Xr ifconfig 4 , followed in all cases by a colon and an interface address in the form of groups of hexadecimal digits @@ -100,8 +100,8 @@ always returns a null terminated string. has no return value. (See .Sx BUGS . ) -.\" .Sh SEE ALSO -.\" .Xr iso 4 +.Sh SEE ALSO +.Xr iso 4 , .Sh HISTORY The .Fn link_addr diff --git a/lib/libc/net/rcmd.3 b/lib/libc/net/rcmd.3 index 6849dac0a4ca..ba0f9cc58206 100644 --- a/lib/libc/net/rcmd.3 +++ b/lib/libc/net/rcmd.3 @@ -163,7 +163,7 @@ and .Fn ruserok return \-1. If the local domain (as obtained from -.Xr gethostname 3 ) +.Xr gethostname 2 ) is the same as the remote domain, only the machine name need be specified. .Pp The diff --git a/lib/libc/net/res_comp.c b/lib/libc/net/res_comp.c index fbe5e95b28a6..58b26deada88 100644 --- a/lib/libc/net/res_comp.c +++ b/lib/libc/net/res_comp.c @@ -95,7 +95,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) /* * fetch next label in domain name */ - while (n = *cp++) { + while ((n = *cp++)) { /* * Check for indirection */ @@ -110,14 +110,14 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) return (-1); checked += n + 1; while (--n >= 0) { - if (((c = *cp++) == '.') || (c == '\\')) { + if ((c = *cp++) == '.') { if (dn + n + 2 >= eom) return (-1); *dn++ = '\\'; } *dn++ = c; if (cp >= eomorig) /* out of range */ - return (-1); + return(-1); } break; @@ -126,7 +126,7 @@ dn_expand(msg, eomorig, comp_dn, exp_dn, length) len = cp - comp_dn + 1; cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); if (cp < msg || cp >= eomorig) /* out of range */ - return (-1); + return(-1); checked += 2; /* * Check for loops in the compressed name; @@ -262,12 +262,12 @@ __dn_skipname(comp_dn, eom) cp++; break; default: /* illegal type */ - return (-1); + return -1; } break; } if (cp > eom) - return (-1); + return -1; return (cp - comp_dn); } @@ -298,7 +298,7 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) for (cpp = dnptrs; cpp < lastdnptr; cpp++) { dn = exp_dn; sp = cp = *cpp; - while (n = *cp++) { + while ((n = *cp++)) { /* * check for indirection */ @@ -318,12 +318,11 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) continue; goto next; - case INDIR_MASK: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - default: /* illegal type */ return (-1); + + case INDIR_MASK: /* indirection */ + cp = msg + (((n & 0x3f) << 8) | *cp); } } if (*dn == '\0') @@ -334,7 +333,11 @@ dn_find(exp_dn, msg, dnptrs, lastdnptr) } /* - * Routines to insert/extract short/long's. + * Routines to insert/extract short/long's. Must account for byte + * order and non-alignment problems. This code at least has the + * advantage of being portable. + * + * used by sendmail. */ u_int16_t diff --git a/lib/libc/net/res_config.h b/lib/libc/net/res_config.h index 7d5566427320..a1339d9652a1 100644 --- a/lib/libc/net/res_config.h +++ b/lib/libc/net/res_config.h @@ -1,8 +1,7 @@ #define DEBUG 1 /* enable debugging code (needed for dig) */ #undef ALLOW_T_UNSPEC /* enable the "unspec" RR type for old athena */ #define RESOLVSORT /* allow sorting of addresses in gethostbyname */ -#define RFC1535 /* comply with RFC1535 (STRONGLY reccomended by vixie)*/ +#undef RFC1535 /* comply with RFC1535 */ #undef ALLOW_UPDATES /* destroy your system security */ #undef USELOOPBACK /* res_init() bind to localhost */ #undef SUNSECURITY /* verify gethostbyaddr() calls - WE DONT NEED IT */ -#define MULTI_PTRS_ARE_ALIASES /* fold multiple PTR records into aliases */ diff --git a/lib/libc/net/res_debug.c b/lib/libc/net/res_debug.c index 9f4d6569e6d2..74aef85b538f 100644 --- a/lib/libc/net/res_debug.c +++ b/lib/libc/net/res_debug.c @@ -58,22 +58,54 @@ static char rcsid[] = "$Id: res_debug.c,v 1.3.4.1 1995/08/30 04:06:48 davidg Exp #include <sys/param.h> #include <netinet/in.h> -#ifdef ISO #include <netiso/iso.h> -#endif - #include <arpa/inet.h> #include <arpa/nameser.h> #include <stdio.h> -#include <netdb.h> #include <resolv.h> #include <string.h> +#include <netdb.h> #include "res_config.h" -extern const char *_res_opcodes[]; -extern const char *_res_resultcodes[]; +const char *_res_opcodes[] = { + "QUERY", + "IQUERY", + "CQUERYM", + "CQUERYU", /* experimental */ + "NOTIFY", /* experimental */ + "5", + "6", + "7", + "8", + "UPDATEA", + "UPDATED", + "UPDATEDA", + "UPDATEM", + "UPDATEMA", + "ZONEINIT", + "ZONEREF", +}; + +const char *_res_resultcodes[] = { + "NOERROR", + "FORMERR", + "SERVFAIL", + "NXDOMAIN", + "NOTIMP", + "REFUSED", + "6", + "7", + "8", + "9", + "10", + "11", + "12", + "13", + "14", + "NOCHANGE", +}; /* XXX: we should use getservbyport() instead. */ static const char * @@ -171,13 +203,13 @@ do_rrset(msg, len, cp, cnt, pflag, file, hs) * Print answer records. */ sflag = (_res.pfcode & pflag); - if (n = ntohs(cnt)) { + if ((n = ntohs(cnt))) { if ((!_res.pfcode) || ((sflag) && (_res.pfcode & RES_PRF_HEAD1))) fprintf(file, hs); while (--n >= 0) { if ((!_res.pfcode) || sflag) { - cp = p_rr(cp, msg, file); + cp = p_rr(cp, msg, file); } else { unsigned int dlen; cp += __dn_skipname(cp, cp + MAXCDNAME); @@ -258,10 +290,9 @@ __fp_nquery(msg, len, file) ntohs(hp->id)); putc('\n', file); } - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEADX)) - putc(';', file); + putc(';', file); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_HEAD2)) { - fprintf(file, "; flags:"); + fprintf(file,"; flags:"); if (hp->qr) fprintf(file, " qr"); if (hp->aa) @@ -279,7 +310,7 @@ __fp_nquery(msg, len, file) fprintf(file, ", Auth: %d", ntohs(hp->nscount)); fprintf(file, ", Addit: %d", ntohs(hp->arcount)); } - if ((!_res.pfcode) || (_res.pfcode & + if ((!_res.pfcode) || (_res.pfcode & (RES_PRF_HEADX | RES_PRF_HEAD2 | RES_PRF_HEAD1))) { putc('\n',file); } @@ -288,23 +319,11 @@ __fp_nquery(msg, len, file) */ if (n = ntohs(hp->qdcount)) { if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ";; QUESTIONS:\n"); + fprintf(file,";; QUESTIONS:\n"); while (--n >= 0) { - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - fprintf(file, ";;\t"); + fprintf(file,";;\t"); TruncTest(cp); - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - cp = p_cdnname(cp, msg, len, file); - else { - int n; - char name[MAXDNAME]; - - if ((n = dn_expand(msg, msg+len, cp, name, - sizeof name)) < 0) - cp = NULL; - else - cp += n; - } + cp = p_cdnname(cp, msg, len, file); ErrorTest(cp); TruncTest(cp); if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) @@ -316,8 +335,7 @@ __fp_nquery(msg, len, file) fprintf(file, ", class = %s\n", __p_class(_getshort((u_char*)cp))); cp += INT16SZ; - if ((!_res.pfcode) || (_res.pfcode & RES_PRF_QUES)) - putc('\n', file); + putc('\n', file); } } /* @@ -418,9 +436,7 @@ __p_rr(cp, msg, file) { int type, class, dlen, n, c; struct in_addr inaddr; -#ifdef ISO struct iso_addr isoa; -#endif const u_char *cp1, *cp2; u_int32_t tmpttl, t; int lcnt; @@ -455,7 +471,7 @@ __p_rr(cp, msg, file) case C_HS: bcopy(cp, (char *)&inaddr, INADDRSZ); if (dlen == 4) { - fprintf(file, "\t%s", inet_ntoa(inaddr)); + fprintf(file,"\t%s", inet_ntoa(inaddr)); cp += dlen; } else if (dlen == 7) { char *address; @@ -491,11 +507,11 @@ __p_rr(cp, msg, file) case T_ISDN: cp2 = cp + dlen; if (n = *cp++) { - fprintf(file, "\t%.*s", n, cp); + fprintf(file,"\t%.*s", n, cp); cp += n; } if ((cp < cp2) && (n = *cp++)) { - fprintf(file, "\t%.*s", n, cp); + fprintf(file,"\t%.*s", n, cp); cp += n; } else if (type == T_HINFO) fprintf(file, "\n;; *** Warning *** OS-type missing"); @@ -528,7 +544,7 @@ __p_rr(cp, msg, file) case T_MX: case T_AFSDB: case T_RT: - fprintf(file, "\t%d ", _getshort((u_char*)cp)); + fprintf(file,"\t%d ", _getshort((u_char*)cp)); cp += INT16SZ; if ((cp = p_fqname(cp, msg, file)) == NULL) return (NULL); @@ -544,7 +560,7 @@ __p_rr(cp, msg, file) return (NULL); break; - case T_TXT: + case T_TXT: case T_X25: (void) fputs("\t\"", file); cp2 = cp1 + dlen; @@ -559,9 +575,8 @@ __p_rr(cp, msg, file) } } putc('"', file); - break; + break; -#ifdef ISO case T_NSAP: isoa.isoa_len = dlen; if (isoa.isoa_len > sizeof(isoa.isoa_genaddr)) @@ -570,7 +585,6 @@ __p_rr(cp, msg, file) (void) fprintf(file, "\t%s", iso_ntoa(&isoa)); cp += dlen; break; -#endif case T_MINFO: case T_RP: @@ -591,7 +605,7 @@ __p_rr(cp, msg, file) case T_UID: case T_GID: if (dlen == 4) { - fprintf(file, "\t%u", _getlong((u_char*)cp)); + fprintf(file,"\t%u", _getlong((u_char*)cp)); cp += INT32SZ; } break; @@ -610,7 +624,7 @@ __p_rr(cp, msg, file) while (cp < cp1 + dlen) { c = *cp++; do { - if (c & 0200) { + if (c & 0200) { if (lcnt == 0) { fputs("\n\t\t\t", file); lcnt = 5; @@ -619,7 +633,7 @@ __p_rr(cp, msg, file) putc(' ', file); lcnt--; } - c <<= 1; + c <<= 1; } while (++n & 07); } putc(')', file); @@ -643,7 +657,7 @@ __p_rr(cp, msg, file) #endif /* ALLOW_T_UNSPEC */ default: - fprintf(file, "\t?%d?", type); + fprintf(file,"\t?%d?", type); cp += dlen; } #if 0 @@ -652,7 +666,7 @@ __p_rr(cp, msg, file) putc('\n', file); #endif if (cp - cp1 != dlen) { - fprintf(file, ";; packet size error (found %d, dlen was %d)\n", + fprintf(file,";; packet size error (found %d, dlen was %d)\n", cp - cp1, dlen); cp = NULL; } diff --git a/lib/libc/net/res_init.c b/lib/libc/net/res_init.c index 583572195bb2..2e5e396aab74 100644 --- a/lib/libc/net/res_init.c +++ b/lib/libc/net/res_init.c @@ -96,7 +96,7 @@ struct __res_state _res; * since it was noted that INADDR_ANY actually meant ``the first interface * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface, * it had to be "up" in order for you to reach your own name server. It - * was later decided that since the recommended practice is to always + * was later decided that since the recommended practice is to always * install local static routes through 127.0.0.1 for all your network * interfaces, that we could solve this problem without a code change. * @@ -223,7 +223,8 @@ res_init() cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + (void)strncpy(_res.defdname, cp, + sizeof(_res.defdname) - 1); if ((cp = strpbrk(_res.defdname, " \t\n")) != NULL) *cp = '\0'; havesearch = 0; @@ -238,7 +239,8 @@ res_init() cp++; if ((*cp == '\0') || (*cp == '\n')) continue; - strncpy(_res.defdname, cp, sizeof(_res.defdname) - 1); + (void)strncpy(_res.defdname, cp, + sizeof(_res.defdname) - 1); if ((cp = strchr(_res.defdname, '\n')) != NULL) *cp = '\0'; /* @@ -267,7 +269,7 @@ res_init() } /* read nameservers to query */ if (MATCH(buf, "nameserver") && nserv < MAXNS) { - struct in_addr a; + struct in_addr a; cp = buf + sizeof("nameserver") - 1; while (*cp == ' ' || *cp == '\t') @@ -293,7 +295,7 @@ res_init() break; net = cp; while (*cp && !ISSORTMASK(*cp) && *cp != ';' && - isascii(*cp) && !isspace(*cp)) + isascii(*cp) && !isspace(*cp)) cp++; n = *cp; *cp = 0; @@ -310,11 +312,11 @@ res_init() if (inet_aton(net, &a)) { _res.sort_list[nsort].mask = a.s_addr; } else { - _res.sort_list[nsort].mask = + _res.sort_list[nsort].mask = net_mask(_res.sort_list[nsort].addr); } } else { - _res.sort_list[nsort].mask = + _res.sort_list[nsort].mask = net_mask(_res.sort_list[nsort].addr); } nsort++; @@ -329,7 +331,7 @@ res_init() continue; } } - if (nserv > 1) + if (nserv > 1) _res.nscount = nserv; #ifdef RESOLVSORT _res.nsort = nsort; @@ -349,7 +351,7 @@ res_init() #ifndef RFC1535 dots = 0; - for (cp = _res.defdname; *cp; cp++) + for (cp = _res.defdname; *cp; cp++) dots += (*cp == '.'); cp = _res.defdname; @@ -369,7 +371,7 @@ res_init() printf(";;\t..END..\n"); } #endif /* DEBUG */ -#endif /* !RFC1535 */ +#endif /*!RFC1535*/ } if ((cp = getenv("RES_OPTIONS")) != NULL) @@ -395,7 +397,7 @@ res_setoptions(options, source) while (*cp == ' ' || *cp == '\t') cp++; /* search for and process individual options */ - if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { + if (!strncmp(cp, "ndots:", sizeof("ndots:")-1)) { i = atoi(cp + sizeof("ndots:") - 1); if (i <= RES_MAXNDOTS) _res.ndots = i; @@ -405,7 +407,7 @@ res_setoptions(options, source) if (_res.options & RES_DEBUG) printf(";;\tndots=%d\n", _res.ndots); #endif - } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { + } else if (!strncmp(cp, "debug", sizeof("debug")-1)) { #ifdef DEBUG if (!(_res.options & RES_DEBUG)) { printf(";; res_setoptions(\"%s\", \"%s\")..\n", @@ -429,12 +431,12 @@ static u_int32_t net_mask(in) /* XXX - should really use system's version of this */ struct in_addr in; { - register u_int32_t i = ntohl(in.s_addr); + register u_int32_t i = ntohl(in.s_addr); - if (IN_CLASSA(i)) - return (htonl(IN_CLASSA_NET)); - else if (IN_CLASSB(i)) - return (htonl(IN_CLASSB_NET)); + if (IN_CLASSA(i)) + return (htonl(IN_CLASSA_NET)); + else if (IN_CLASSB(i)) + return (htonl(IN_CLASSB_NET)); return (htonl(IN_CLASSC_NET)); } #endif diff --git a/lib/libc/net/res_mkquery.c b/lib/libc/net/res_mkquery.c index dd46311814e0..c942a2e3a62e 100644 --- a/lib/libc/net/res_mkquery.c +++ b/lib/libc/net/res_mkquery.c @@ -61,9 +61,9 @@ static char rcsid[] = "$Id: res_mkquery.c,v 1.4.4.1 1995/08/30 04:06:54 davidg E #include <arpa/nameser.h> #include <stdio.h> -#include <netdb.h> #include <resolv.h> #include <string.h> +#include <netdb.h> #include "res_config.h" @@ -103,7 +103,7 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) * Initialize header fields. */ if ((buf == NULL) || (buflen < HFIXEDSZ)) - return (-1); + return(-1); bzero(buf, HFIXEDSZ); hp = (HEADER *) buf; hp->id = htons(++_res.id); @@ -123,7 +123,7 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) case QUERY: /*FALLTHROUGH*/ case NS_NOTIFY_OP: if ((buflen -= QFIXEDSZ) < 0) - return (-1); + return(-1); if ((n = dn_comp(dname, cp, buflen, dnptrs, lastdnptr)) < 0) return (-1); cp += n; @@ -197,13 +197,13 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) return (-1); cp += n; __putshort(type, cp); - cp += INT16SZ; - __putshort(class, cp); - cp += INT16SZ; + cp += INT16SZ; + __putshort(class, cp); + cp += INT16SZ; __putlong(0, cp); cp += INT32SZ; __putshort(datalen, cp); - cp += INT16SZ; + cp += INT16SZ; if (datalen) { bcopy(data, cp, datalen); cp += datalen; @@ -220,13 +220,13 @@ res_mkquery(op, dname, class, type, data, datalen, newrr_in, buf, buflen) return (-1); cp += n; __putshort(newrr->r_type, cp); - cp += INT16SZ; - __putshort(newrr->r_class, cp); - cp += INT16SZ; + cp += INT16SZ; + __putshort(newrr->r_class, cp); + cp += INT16SZ; __putlong(0, cp); cp += INT32SZ; __putshort(newrr->r_size, cp); - cp += INT16SZ; + cp += INT16SZ; if (newrr->r_size) { bcopy(newrr->r_data, cp, newrr->r_size); cp += newrr->r_size; diff --git a/lib/libc/net/res_query.c b/lib/libc/net/res_query.c index 18d49a30f07c..2a1ce53a1329 100644 --- a/lib/libc/net/res_query.c +++ b/lib/libc/net/res_query.c @@ -139,21 +139,21 @@ res_query(name, class, type, answer, anslen) ntohs(hp->ancount)); #endif switch (hp->rcode) { - case NXDOMAIN: - h_errno = HOST_NOT_FOUND; - break; - case SERVFAIL: - h_errno = TRY_AGAIN; - break; - case NOERROR: - h_errno = NO_DATA; - break; - case FORMERR: - case NOTIMP: - case REFUSED: - default: - h_errno = NO_RECOVERY; - break; + case NXDOMAIN: + h_errno = HOST_NOT_FOUND; + break; + case SERVFAIL: + h_errno = TRY_AGAIN; + break; + case NOERROR: + h_errno = NO_DATA; + break; + case FORMERR: + case NOTIMP: + case REFUSED: + default: + h_errno = NO_RECOVERY; + break; } return (-1); } @@ -186,7 +186,7 @@ res_search(name, class, type, answer, anslen) errno = 0; h_errno = HOST_NOT_FOUND; /* default, if we never query */ dots = 0; - for (cp = name; *cp; cp++) + for (cp = name; *cp; cp++) dots += (*cp == '.'); trailing_dot = 0; if (cp > name && *--cp == '.') diff --git a/lib/libc/net/res_send.c b/lib/libc/net/res_send.c index 55465d0e7d9d..b3ea98c4b390 100644 --- a/lib/libc/net/res_send.c +++ b/lib/libc/net/res_send.c @@ -102,38 +102,38 @@ static int vc = 0; /* is the socket a virtual ciruit? */ fprintf args;\ __fp_nquery(query, size, stdout);\ } else {} - static void - Aerror(file, string, error, address) - FILE *file; - char *string; - int error; - struct sockaddr_in address; - { - int save = errno; - - if (_res.options & RES_DEBUG) { +static void +Aerror(file, string, error, address) + FILE *file; + char *string; + int error; + struct sockaddr_in address; +{ + int save = errno; + + if (_res.options & RES_DEBUG) { fprintf(file, "res_send: %s ([%s].%u): %s\n", - string, - inet_ntoa(address.sin_addr), + string, + inet_ntoa(address.sin_addr), ntohs(address.sin_port), - strerror(error)); - } - errno = save; + strerror(error)); } - static void - Perror(file, string, error) - FILE *file; - char *string; - int error; - { - int save = errno; - - if (_res.options & RES_DEBUG) { - fprintf(file, "res_send: %s: %s\n", - string, strerror(error)); - } - errno = save; + errno = save; +} +static void +Perror(file, string, error) + FILE *file; + char *string; + int error; +{ + int save = errno; + + if (_res.options & RES_DEBUG) { + fprintf(file, "res_send: %s: %s\n", + string, strerror(error)); } + errno = save; +} #endif static res_send_qhook Qhook = NULL; @@ -214,7 +214,7 @@ res_nameinquery(name, type, class, buf, eom) if (n < 0) return (-1); cp += n; - ttype = _getshort(cp); cp += INT16SZ; + ttype = _getshort(cp); cp += INT16SZ; tclass = _getshort(cp); cp += INT16SZ; if (ttype == type && tclass == class && @@ -263,20 +263,20 @@ res_queriesmatch(buf1, eom1, buf2, eom2) int res_send(buf, buflen, ans, anssiz) - const u_char *buf; - int buflen; - u_char *ans; - int anssiz; + const u_char *buf; + int buflen; + u_char *ans; + int anssiz; { - HEADER *hp = (HEADER *) buf; - HEADER *anhp = (HEADER *) ans; + HEADER *hp = (HEADER *) buf; + HEADER *anhp = (HEADER *) ans; int gotsomewhere, connreset, terrno, try, v_circuit, resplen, ns; - register int n; - u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ + register int n; + u_int badns; /* XXX NSMAX can't exceed #/bits in this var */ if ((_res.options & RES_INIT) == 0 && res_init() == -1) { /* errno should have been set by res_init() in this case. */ - return (-1); + return (-1); } DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_QUERY), (stdout, ";; res_send()\n"), buf, buflen); @@ -293,7 +293,7 @@ res_send(buf, buflen, ans, anssiz) for (ns = 0; ns < _res.nscount; ns++) { struct sockaddr_in *nsap = &_res.nsaddr_list[ns]; same_ns: - if (badns & (1 << ns)) { + if (badns & (1<<ns)) { _res_close(); goto next_ns; } @@ -330,13 +330,13 @@ res_send(buf, buflen, ans, anssiz) Dprint(_res.options & RES_DEBUG, (stdout, ";; Querying server (# %d) address = %s\n", - ns + 1, inet_ntoa(nsap->sin_addr))); + ns+1, inet_ntoa(nsap->sin_addr))); if (v_circuit) { - int truncated; - struct iovec iov[2]; - u_short len; - u_char *cp; + int truncated; + struct iovec iov[2]; + u_short len; + u_char *cp; /* * Use virtual circuit; @@ -360,7 +360,7 @@ res_send(buf, buflen, ans, anssiz) terrno = errno; Aerror(stderr, "connect/vc", errno, *nsap); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); goto next_ns; } @@ -377,7 +377,7 @@ res_send(buf, buflen, ans, anssiz) if (writev(s, iov, 2) != (INT16SZ + buflen)) { terrno = errno; Perror(stderr, "write failed", errno); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); goto next_ns; } @@ -456,10 +456,10 @@ res_send(buf, buflen, ans, anssiz) /* * Use datagrams. */ - struct timeval timeout; - fd_set dsmask; + struct timeval timeout; + fd_set dsmask; struct sockaddr_in from; - int fromlen; + int fromlen; if ((s < 0) || vc) { if (vc) @@ -499,7 +499,7 @@ res_send(buf, buflen, ans, anssiz) Aerror(stderr, "connect(dg)", errno, *nsap); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); goto next_ns; } @@ -507,7 +507,7 @@ res_send(buf, buflen, ans, anssiz) } if (send(s, (char*)buf, buflen, 0) != buflen) { Perror(stderr, "send", errno); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); goto next_ns; } @@ -534,7 +534,7 @@ res_send(buf, buflen, ans, anssiz) sizeof(struct sockaddr)) != buflen) { Aerror(stderr, "sendto", errno, *nsap); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); goto next_ns; } @@ -608,7 +608,7 @@ res_send(buf, buflen, ans, anssiz) #endif if (!(_res.options & RES_INSECURE2) && !res_queriesmatch(buf, buf + buflen, - ans, ans + anssiz)) { + ans, ans + anssiz)) { /* * response contains wrong query? ignore it. * XXX - potential security hazard could @@ -626,11 +626,11 @@ res_send(buf, buflen, ans, anssiz) DprintQ(_res.options & RES_DEBUG, (stdout, "server rejected query:\n"), ans, resplen); - badns |= (1 << ns); + badns |= (1<<ns); _res_close(); /* don't retry if called from dig */ if (!_res.pfcode) - goto next_ns; + goto next_ns; } if (!(_res.options & RES_IGNTC) && anhp->tc) { /* @@ -644,13 +644,9 @@ res_send(buf, buflen, ans, anssiz) goto same_ns; } } /*if vc/dg*/ - Dprint((_res.options & RES_DEBUG) || - ((_res.pfcode & RES_PRF_REPLY) && - (_res.pfcode & RES_PRF_HEAD1)), - (stdout, ";; got answer:\n")); DprintQ((_res.options & RES_DEBUG) || (_res.pfcode & RES_PRF_REPLY), - (stdout, ""), + (stdout, ";; got answer:\n"), ans, resplen); /* * If using virtual circuits, we assume that the first server diff --git a/lib/libc/nls/catgets.3 b/lib/libc/nls/catgets.3 index 186ea00599ff..f644130f343a 100644 --- a/lib/libc/nls/catgets.3 +++ b/lib/libc/nls/catgets.3 @@ -63,4 +63,5 @@ otherwise it returns .Sh STANDARDS The .Fn catgets -function conforms to \fBxpg3\fR. +function conforms to +.St -xpg3 . diff --git a/lib/libc/nls/msgcat.c b/lib/libc/nls/msgcat.c index 681ff28f651b..5bf3947ddd5f 100644 --- a/lib/libc/nls/msgcat.c +++ b/lib/libc/nls/msgcat.c @@ -260,7 +260,8 @@ nl_catd catd; { MCCatT *cat = (MCCatT *) catd; MCSetT *set; - int i; + MCMsgT *msg; + int i, j; if (!cat) return -1; @@ -294,7 +295,8 @@ int type; MCHeaderT header; MCCatT *cat; MCSetT *set; - long i; + MCMsgT *msg; + long i, j; off_t nextSet; cat = (MCCatT *) malloc(sizeof(MCCatT)); diff --git a/lib/libc/quad/Makefile.inc b/lib/libc/quad/Makefile.inc index 617aae3bff27..627357428d17 100644 --- a/lib/libc/quad/Makefile.inc +++ b/lib/libc/quad/Makefile.inc @@ -1,19 +1,10 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# Quad support, if needed - -.if ${MACHINE} == "i386" - -SRCS+= cmpdi2.c divdi3.c moddi3.c qdivrem.c ucmpdi2.c udivdi3.c umoddi3.c - -.else - +# Quad support SRCS+= adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c fixdfdi.c \ fixsfdi.c fixunsdfdi.c fixunssfdi.c floatdidf.c floatdisf.c \ floatunsdidf.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 - .PATH: ${.CURDIR}/${MACHINE}/quad ${.CURDIR}/quad diff --git a/lib/libc/quad/quad.h b/lib/libc/quad/quad.h index 873a1f6bde0a..bc6a2f836327 100644 --- a/lib/libc/quad/quad.h +++ b/lib/libc/quad/quad.h @@ -35,7 +35,6 @@ * SUCH DAMAGE. * * @(#)quad.h 8.1 (Berkeley) 6/4/93 - * $Id$ */ /* @@ -96,11 +95,7 @@ union uu { #define LHALF(x) ((x) & ((1 << HALF_BITS) - 1)) #define LHUP(x) ((x) << HALF_BITS) -quad_t __divdi3 __P((quad_t a, quad_t b)); -quad_t __moddi3 __P((quad_t a, quad_t b)); -u_quad_t __qdivrem __P((u_quad_t u, u_quad_t v, u_quad_t *rem)); -u_quad_t __udivdi3 __P((u_quad_t a, u_quad_t b)); -u_quad_t __umoddi3 __P((u_quad_t a, u_quad_t b)); +extern u_quad_t __qdivrem __P((u_quad_t u, u_quad_t v, u_quad_t *rem)); /* * XXX diff --git a/lib/libc/regex/engine.c b/lib/libc/regex/engine.c index 8b54837c7316..6d982f889c51 100644 --- a/lib/libc/regex/engine.c +++ b/lib/libc/regex/engine.c @@ -686,7 +686,6 @@ sopno lev; /* PLUS nesting level */ /* "can't happen" */ assert(nope); /* NOTREACHED */ - return "shut up gcc"; } /* diff --git a/lib/libc/regex/regcomp.c b/lib/libc/regex/regcomp.c index 10412aada61d..feb24ecced33 100644 --- a/lib/libc/regex/regcomp.c +++ b/lib/libc/regex/regcomp.c @@ -673,6 +673,7 @@ static void p_bracket(p) register struct parse *p; { + register char c; register cset *cs = allocset(p); register int invert = 0; @@ -820,7 +821,7 @@ register cset *cs; register char *u; register char c; - while (MORE() && isalpha((unsigned char)PEEK())) + while (MORE() && isalpha(PEEK())) NEXT(); len = p->next - sp; for (cp = cclasses; cp->name != NULL; cp++) @@ -888,6 +889,7 @@ int endc; /* name ended by endc,']' */ register char *sp = p->next; register struct cname *cp; register int len; + register char c; while (MORE() && !SEETWO(endc, ']')) NEXT(); @@ -913,7 +915,6 @@ static char /* if no counterpart, return ch */ othercase(ch) int ch; { - ch = (unsigned char)ch; assert(isalpha(ch)); if (isupper(ch)) return(tolower(ch)); @@ -938,7 +939,6 @@ int ch; register char *oldend = p->end; char bracket[3]; - ch = (unsigned char)ch; assert(othercase(ch) != ch); /* p_bracket() would recurse */ p->next = bracket; p->end = bracket+2; @@ -962,7 +962,7 @@ register int ch; { register cat_t *cap = p->g->categories; - if ((p->g->cflags®_ICASE) && isalpha((unsigned char)ch) && othercase(ch) != ch) + if ((p->g->cflags®_ICASE) && isalpha(ch) && othercase(ch) != ch) bothcases(p, ch); else { EMIT(OCHAR, (unsigned char)ch); @@ -1213,7 +1213,7 @@ register cset *cs; for (i = 0; i < css; i++) if (CHIN(cs, i)) - return((unsigned char)i); + return((char)i); assert(never); return(0); /* arbitrary */ } diff --git a/lib/libc/regex/regerror.c b/lib/libc/regex/regerror.c index 212f709cf73f..2d2160ac1126 100644 --- a/lib/libc/regex/regerror.c +++ b/lib/libc/regex/regerror.c @@ -166,6 +166,8 @@ const regex_t *preg; char *localbuf; { register struct rerr *r; + register size_t siz; + register char *p; for (r = rerrs; r->code != 0; r++) if (strcmp(r->name, preg->re_endp) == 0) diff --git a/lib/libc/rpc/Makefile.inc b/lib/libc/rpc/Makefile.inc index 00d86b9acab7..43f0f3939532 100644 --- a/lib/libc/rpc/Makefile.inc +++ b/lib/libc/rpc/Makefile.inc @@ -21,4 +21,3 @@ MAN3+= rpc/bindresvport.3 rpc/getrpcent.3 rpc/getrpcport.3 rpc/rpc.3 MAN5+= rpc/rpc.5 MAN8+= rpc/rstat_svc.8 -MLINKS+=getrpcent.3 getrpcbyname.3 getrpcent.3 getrpcbynumber.3 diff --git a/lib/libc/rpc/auth_none.c b/lib/libc/rpc/auth_none.c index b04d5e66707a..9993392bdff6 100644 --- a/lib/libc/rpc/auth_none.c +++ b/lib/libc/rpc/auth_none.c @@ -41,7 +41,6 @@ static char *rcsid = "$Id: auth_none.c,v 1.2 1995/05/30 05:41:11 rgrimes Exp $"; * Copyright (C) 1984, Sun Microsystems, Inc. */ -#include <stdlib.h> #include <rpc/types.h> #include <rpc/xdr.h> #include <rpc/auth.h> diff --git a/lib/libc/rpc/auth_unix.c b/lib/libc/rpc/auth_unix.c index b63b95954c52..777f42182371 100644 --- a/lib/libc/rpc/auth_unix.c +++ b/lib/libc/rpc/auth_unix.c @@ -47,8 +47,6 @@ static char *rcsid = "$Id: auth_unix.c,v 1.4 1995/05/30 05:41:12 rgrimes Exp $"; #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <sys/param.h> #include <rpc/types.h> @@ -85,7 +83,7 @@ struct audata { }; #define AUTH_PRIVATE(auth) ((struct audata *)auth->ah_private) -static void marshal_new_auth(); +static bool_t marshal_new_auth(); /* * This goop is here because some servers refuse to accept a @@ -94,7 +92,7 @@ static void marshal_new_auth(); */ static int authunix_maxgrouplist = 0; -void +int set_rpc_maxgrouplist(int num) { authunix_maxgrouplist = num; @@ -330,7 +328,7 @@ authunix_destroy(auth) * Marshals (pre-serializes) an auth struct. * sets private data, au_marshed and au_mpos */ -static void +static bool_t marshal_new_auth(auth) register AUTH *auth; { diff --git a/lib/libc/rpc/bindresvport.3 b/lib/libc/rpc/bindresvport.3 index 5d1648751c08..1fb1f9a30600 100644 --- a/lib/libc/rpc/bindresvport.3 +++ b/lib/libc/rpc/bindresvport.3 @@ -1,5 +1,5 @@ .\" @(#)bindresvport.3n 2.2 88/08/02 4.0 RPCSRC; from 1.7 88/03/14 SMI -.TH BINDRESVPORT 3 "22 november 1987" +.TH BINDRESVPORT 3N "22 november 1987" .SH NAME bindresvport \- bind a socket to a privileged IP port .SH SYNOPSIS diff --git a/lib/libc/rpc/bindresvport.c b/lib/libc/rpc/bindresvport.c index c7f93b205270..e7cfe8bc91b9 100644 --- a/lib/libc/rpc/bindresvport.c +++ b/lib/libc/rpc/bindresvport.c @@ -41,8 +41,6 @@ static char *rcsid = "$Id: bindresvport.c,v 1.2 1995/05/30 05:41:13 rgrimes Exp #include <sys/errno.h> #include <sys/socket.h> #include <netinet/in.h> -#include <unistd.h> -#include <string.h> /* * Bind a socket to a privileged IP port diff --git a/lib/libc/rpc/clnt_generic.c b/lib/libc/rpc/clnt_generic.c index a529336dc447..96f4c3de726a 100644 --- a/lib/libc/rpc/clnt_generic.c +++ b/lib/libc/rpc/clnt_generic.c @@ -40,7 +40,6 @@ static char *rcsid = "$Id: clnt_generic.c,v 1.2 1995/05/30 05:41:14 rgrimes Exp #include <sys/socket.h> #include <sys/errno.h> #include <netdb.h> -#include <string.h> /* * Generic client creation: takes (hostname, program-number, protocol) and diff --git a/lib/libc/rpc/clnt_perror.c b/lib/libc/rpc/clnt_perror.c index 3c73c448d7ec..f7ef47fbde09 100644 --- a/lib/libc/rpc/clnt_perror.c +++ b/lib/libc/rpc/clnt_perror.c @@ -40,7 +40,6 @@ static char *rcsid = "$Id: clnt_perror.c,v 1.2 1995/05/30 05:41:15 rgrimes Exp $ * */ #include <stdio.h> -#include <stdlib.h> #include <string.h> #include <rpc/rpc.h> #include <rpc/types.h> @@ -151,7 +150,7 @@ clnt_perror(rpch, s) CLIENT *rpch; char *s; { - (void) fprintf(stderr,"%s\n",clnt_sperror(rpch,s)); + (void) fprintf(stderr,"%s",clnt_sperror(rpch,s)); } @@ -221,7 +220,7 @@ void clnt_perrno(num) enum clnt_stat num; { - (void) fprintf(stderr,"%s\n",clnt_sperrno(num)); + (void) fprintf(stderr,"%s",clnt_sperrno(num)); } @@ -262,7 +261,7 @@ void clnt_pcreateerror(s) char *s; { - (void) fprintf(stderr,"%s\n",clnt_spcreateerror(s)); + (void) fprintf(stderr,"%s",clnt_spcreateerror(s)); } struct auth_errtab { diff --git a/lib/libc/rpc/clnt_raw.c b/lib/libc/rpc/clnt_raw.c index 56c15ef0cf02..8f8a3d8d5f9a 100644 --- a/lib/libc/rpc/clnt_raw.c +++ b/lib/libc/rpc/clnt_raw.c @@ -45,7 +45,6 @@ static char *rcsid = "$Id: clnt_raw.c,v 1.2 1995/05/30 05:41:16 rgrimes Exp $"; */ #include <rpc/rpc.h> -#include <stdlib.h> #define MCALL_MSG_SIZE 24 @@ -98,7 +97,7 @@ clntraw_create(prog, vers) clntraw_private = clp; } /* - * pre-serialize the static part of the call msg and stash it away + * pre-serialize the staic part of the call msg and stash it away */ call_msg.rm_direction = CALL; call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION; diff --git a/lib/libc/rpc/clnt_simple.c b/lib/libc/rpc/clnt_simple.c index 2678287f9fca..df7fbf8df241 100644 --- a/lib/libc/rpc/clnt_simple.c +++ b/lib/libc/rpc/clnt_simple.c @@ -42,7 +42,6 @@ static char *rcsid = "$Id: clnt_simple.c,v 1.2 1995/05/30 05:41:17 rgrimes Exp $ #include <stdio.h> #include <stdlib.h> -#include <unistd.h> #include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> diff --git a/lib/libc/rpc/clnt_tcp.c b/lib/libc/rpc/clnt_tcp.c index 261ca44a9057..b7c649777a22 100644 --- a/lib/libc/rpc/clnt_tcp.c +++ b/lib/libc/rpc/clnt_tcp.c @@ -53,9 +53,6 @@ static char *rcsid = "$Id: clnt_tcp.c,v 1.2 1995/05/30 05:41:18 rgrimes Exp $"; */ #include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> #include <netdb.h> @@ -191,7 +188,7 @@ clnttcp_create(raddr, prog, vers, sockp, sendsz, recvsz) call_msg.rm_call.cb_vers = vers; /* - * pre-serialize the static part of the call msg and stash it away + * pre-serialize the staic part of the call msg and stash it away */ xdrmem_create(&(ct->ct_xdrs), ct->ct_mcall, MCALL_MSG_SIZE, XDR_ENCODE); @@ -420,8 +417,8 @@ readtcp(ct, buf, len) #endif /* def FD_SETSIZE */ while (TRUE) { readfds = mask; - switch (select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, - (fd_set *)NULL, &(ct->ct_wait))) { + switch (select(_rpc_dtablesize(), &readfds, (int*)NULL, (int*)NULL, + &(ct->ct_wait))) { case 0: ct->ct_error.re_status = RPC_TIMEDOUT; return (-1); diff --git a/lib/libc/rpc/clnt_udp.c b/lib/libc/rpc/clnt_udp.c index cb8140179ea3..1e2b450e2ec6 100644 --- a/lib/libc/rpc/clnt_udp.c +++ b/lib/libc/rpc/clnt_udp.c @@ -40,9 +40,6 @@ static char *rcsid = "$Id: clnt_udp.c,v 1.3.4.1 1995/08/04 19:37:31 davidg Exp $ */ #include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> #include <sys/ioctl.h> @@ -291,8 +288,8 @@ send_again: #endif /* def FD_SETSIZE */ for (;;) { readfds = mask; - switch (select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, - (fd_set *)NULL, &(cu->cu_wait))) { + switch (select(_rpc_dtablesize(), &readfds, (int *)NULL, + (int *)NULL, &(cu->cu_wait))) { case 0: time_waited.tv_sec += cu->cu_wait.tv_sec; diff --git a/lib/libc/rpc/get_myaddress.c b/lib/libc/rpc/get_myaddress.c index 1565531f22bd..04399c4c57d3 100644 --- a/lib/libc/rpc/get_myaddress.c +++ b/lib/libc/rpc/get_myaddress.c @@ -45,7 +45,6 @@ static char *rcsid = "$Id: get_myaddress.c,v 1.2 1995/05/30 05:41:20 rgrimes Exp #include <rpc/pmap_prot.h> #include <sys/socket.h> #include <stdio.h> -#include <unistd.h> #include <net/if.h> #include <sys/ioctl.h> #include <netinet/in.h> diff --git a/lib/libc/rpc/getrpcent.3 b/lib/libc/rpc/getrpcent.3 index 2bac189b451c..edf64e4f6b72 100644 --- a/lib/libc/rpc/getrpcent.3 +++ b/lib/libc/rpc/getrpcent.3 @@ -1,5 +1,5 @@ .\" @(#)getrpcent.3n 2.2 88/08/02 4.0 RPCSRC; from 1.11 88/03/14 SMI -.TH GETRPCENT 3 "14 December 1987" +.TH GETRPCENT 3N "14 December 1987" .SH NAME getrpcent, getrpcbyname, getrpcbynumber \- get RPC entry .SH SYNOPSIS diff --git a/lib/libc/rpc/getrpcent.c b/lib/libc/rpc/getrpcent.c index e9b919c89222..824a81eb39e0 100644 --- a/lib/libc/rpc/getrpcent.c +++ b/lib/libc/rpc/getrpcent.c @@ -38,7 +38,6 @@ static char *rcsid = "$Id: getrpcent.c,v 1.2 1995/05/30 05:41:21 rgrimes Exp $"; */ #include <stdio.h> -#include <stdlib.h> #include <sys/types.h> #include <string.h> #include <rpc/rpc.h> @@ -206,8 +205,8 @@ getrpcent() int reason; register struct rpcdata *d = _rpcdata(); #ifdef YP - char *val = NULL; - int vallen; + char *key = NULL, *val = NULL; + int keylen, vallen; #endif if (d == 0) diff --git a/lib/libc/rpc/getrpcport.c b/lib/libc/rpc/getrpcport.c index b28049332769..a081dd8771b8 100644 --- a/lib/libc/rpc/getrpcport.c +++ b/lib/libc/rpc/getrpcport.c @@ -38,7 +38,6 @@ static char *rcsid = "$Id: getrpcport.c,v 1.2 1995/05/30 05:41:22 rgrimes Exp $" */ #include <stdio.h> -#include <string.h> #include <rpc/rpc.h> #include <netdb.h> #include <sys/socket.h> diff --git a/lib/libc/rpc/pmap_clnt.c b/lib/libc/rpc/pmap_clnt.c index c91682fb1b78..8048e9bcd663 100644 --- a/lib/libc/rpc/pmap_clnt.c +++ b/lib/libc/rpc/pmap_clnt.c @@ -40,7 +40,6 @@ static char *rcsid = "$Id: pmap_clnt.c,v 1.2 1995/05/30 05:41:22 rgrimes Exp $"; * Copyright (C) 1984, Sun Microsystems, Inc. */ -#include <unistd.h> #include <rpc/rpc.h> #include <rpc/pmap_prot.h> #include <rpc/pmap_clnt.h> diff --git a/lib/libc/rpc/pmap_getmaps.c b/lib/libc/rpc/pmap_getmaps.c index cbb1a4318b5f..a5379c521182 100644 --- a/lib/libc/rpc/pmap_getmaps.c +++ b/lib/libc/rpc/pmap_getmaps.c @@ -47,7 +47,6 @@ static char *rcsid = "$Id: pmap_getmaps.c,v 1.2 1995/05/30 05:41:23 rgrimes Exp #include <sys/socket.h> #include <netdb.h> #include <stdio.h> -#include <unistd.h> #include <errno.h> #include <net/if.h> #include <sys/ioctl.h> diff --git a/lib/libc/rpc/pmap_getport.c b/lib/libc/rpc/pmap_getport.c index dd63a3757f40..c1cc9c6f24e9 100644 --- a/lib/libc/rpc/pmap_getport.c +++ b/lib/libc/rpc/pmap_getport.c @@ -45,7 +45,6 @@ static char *rcsid = "$Id: pmap_getport.c,v 1.2 1995/05/30 05:41:24 rgrimes Exp #include <rpc/pmap_clnt.h> #include <sys/socket.h> #include <net/if.h> -#include <unistd.h> static struct timeval timeout = { 5, 0 }; static struct timeval tottimeout = { 60, 0 }; diff --git a/lib/libc/rpc/pmap_rmt.c b/lib/libc/rpc/pmap_rmt.c index 4b9cba89b2ab..2a467bd56dae 100644 --- a/lib/libc/rpc/pmap_rmt.c +++ b/lib/libc/rpc/pmap_rmt.c @@ -47,9 +47,7 @@ static char *rcsid = "$Id: pmap_rmt.c,v 1.2 1995/05/30 05:41:27 rgrimes Exp $"; #include <rpc/pmap_rmt.h> #include <sys/socket.h> #include <stdio.h> -#include <unistd.h> #include <errno.h> -#include <string.h> #include <net/if.h> #include <sys/ioctl.h> #include <arpa/inet.h> @@ -171,7 +169,6 @@ getbroadcastnets(addrs, sock, buf) struct ifconf ifc; struct ifreq ifreq, *ifr; struct sockaddr_in *sin; - struct in_addr addr; char *cp, *cplim; int n, i = 0; @@ -199,24 +196,17 @@ getbroadcastnets(addrs, sock, buf) sin = (struct sockaddr_in *)&ifr->ifr_addr; #ifdef SIOCGIFBRDADDR /* 4.3BSD */ if (ioctl(sock, SIOCGIFBRDADDR, (char *)&ifreq) < 0) { - addr = + addrs[i++] = inet_makeaddr(inet_netof(sin->sin_addr), INADDR_ANY); } else { - addr = ((struct sockaddr_in*) + addrs[i++] = ((struct sockaddr_in*) &ifreq.ifr_addr)->sin_addr; } #else /* 4.2 BSD */ - addr = inet_makeaddr(inet_netof(sin->sin_addr), + addrs[i++] = inet_makeaddr(inet_netof(sin->sin_addr), INADDR_ANY); #endif - for (n=i-1; n>=0; n--) { - if (addr.s_addr == addrs[n].s_addr) - break; - } - if (n<0) { - addrs[i++] = addr; - } } } return (i); @@ -338,8 +328,8 @@ clnt_broadcast(prog, vers, proc, xargs, argsp, xresults, resultsp, eachresult) msg.acpted_rply.ar_results.where = (caddr_t)&r; msg.acpted_rply.ar_results.proc = xdr_rmtcallres; readfds = mask; - switch (select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, - (fd_set *)NULL, &t)) { + switch (select(_rpc_dtablesize(), &readfds, (int *)NULL, + (int *)NULL, &t)) { case 0: /* timed out */ stat = RPC_TIMEDOUT; diff --git a/lib/libc/rpc/rpc.3 b/lib/libc/rpc/rpc.3 index 3d9d6b218a23..ff00dc333029 100644 --- a/lib/libc/rpc/rpc.3 +++ b/lib/libc/rpc/rpc.3 @@ -13,7 +13,7 @@ reply. Finally, the procedure call returns to the client. .LP Routines that are used for Secure RPC (DES authentication) are described in -.BR rpc_secure (3). +.BR rpc_secure (3N). Secure RPC can be used only if DES encryption is available. .LP .ft B @@ -646,7 +646,7 @@ client for the remote program .IR prognum , version .IR versnum ; -the client uses +the client uses use .SM UDP/IP as a transport. The remote program is located at Internet address @@ -700,7 +700,7 @@ client for the remote program .IR prognum , on .IR versnum ; -the client uses +the client uses use .SM UDP/IP as a transport. The remote program is located at Internet address @@ -725,7 +725,7 @@ out. The total time for the call to time out is specified by .BR clnt_call(\|) . .IP -This allows the user to specify the maximum packet size for sending and receiving +This allows the user to specify the maximun packet size for sending and receiving .SM UDP\s0-based .SM RPC messages. @@ -1709,7 +1709,7 @@ This routine modifies the global variable .BR svc_fds(\|) . Service implementors usually do not need this routine. .SH SEE ALSO -.BR rpc_secure (3), +.BR rpc_secure (3N), .BR xdr (3) .br The following manuals: diff --git a/lib/libc/rpc/rpc.5 b/lib/libc/rpc/rpc.5 index 794197b65387..324ecb153a83 100644 --- a/lib/libc/rpc/rpc.5 +++ b/lib/libc/rpc/rpc.5 @@ -68,4 +68,4 @@ nsemntd 100039 .SH FILES /etc/rpc .SH "SEE ALSO" -getrpcent(3) +getrpcent(3N) diff --git a/lib/libc/rpc/rpc_callmsg.c b/lib/libc/rpc/rpc_callmsg.c index 54f103b5b753..7077ea40fd0b 100644 --- a/lib/libc/rpc/rpc_callmsg.c +++ b/lib/libc/rpc/rpc_callmsg.c @@ -41,8 +41,7 @@ static char *rcsid = "$Id: rpc_callmsg.c,v 1.2 1995/05/30 05:41:28 rgrimes Exp $ */ #include <sys/param.h> -#include <stdlib.h> -#include <string.h> + #include <rpc/rpc.h> /* diff --git a/lib/libc/rpc/rstat.1 b/lib/libc/rpc/rstat.1 index 03c3a063b301..52eaa31c924e 100644 --- a/lib/libc/rpc/rstat.1 +++ b/lib/libc/rpc/rstat.1 @@ -17,7 +17,7 @@ The load average numbers give the number of jobs in the run queue averaged over 1, 5 and 15 minutes. .PP The -.B rstat_svc(8) +.B rstat_svc(8c) daemon must be running on the remote host for this command to work. .B rstat @@ -50,8 +50,8 @@ daemon has terminated on the remote host. rstat: RPC: Port mapper failure - RPC: Timed out .IP The remote host is not running the portmapper (see -.BR portmap(8) ), +.BR portmap(8c) ), and cannot accommodate any RPC-based services. The host may be down. .SH "SEE ALSO" -.BR portmap (8), -.BR rstat_svc (8) +.BR portmap (8c), +.BR rstat_svc (8c) diff --git a/lib/libc/rpc/rstat_svc.8 b/lib/libc/rpc/rstat_svc.8 index b7b438681ba9..a10b71dbacad 100644 --- a/lib/libc/rpc/rstat_svc.8 +++ b/lib/libc/rpc/rstat_svc.8 @@ -1,5 +1,5 @@ .\" @(#)rstat_svc.8c 2.2 88/08/03 4.0 RPCSRC; from 1.10 87/09/09 SMI -.TH RSTAT_SVC 8 "24 November 1987" +.TH RSTAT_SVC 8C "24 November 1987" .SH NAME rstat_svc \- kernel statistics server .SH SYNOPSIS @@ -17,5 +17,5 @@ daemon is normally invoked at boot time through /etc/rc.local. .PP .B rstat_svc uses an RPC protocol defined in /usr/include/rpcsvc/rstat.x. -.\" .SH "SEE ALSO" -.\" .BR rstat (1), +.SH "SEE ALSO" +.BR rstat (1), diff --git a/lib/libc/rpc/svc.c b/lib/libc/rpc/svc.c index 809cbfb596e7..8c8354b19c0e 100644 --- a/lib/libc/rpc/svc.c +++ b/lib/libc/rpc/svc.c @@ -43,8 +43,6 @@ static char *rcsid = "$Id: svc.c,v 1.2 1995/05/30 05:41:31 rgrimes Exp $"; * Copyright (C) 1984, Sun Microsystems, Inc. */ -#include <string.h> -#include <stdlib.h> #include <sys/errno.h> #include <rpc/rpc.h> #include <rpc/pmap_clnt.h> diff --git a/lib/libc/rpc/svc_auth_unix.c b/lib/libc/rpc/svc_auth_unix.c index 27ced54634e1..7a5d24be0d4f 100644 --- a/lib/libc/rpc/svc_auth_unix.c +++ b/lib/libc/rpc/svc_auth_unix.c @@ -45,7 +45,6 @@ static char *rcsid = "$Id: svc_auth_unix.c,v 1.2 1995/05/30 05:41:33 rgrimes Exp */ #include <stdio.h> -#include <string.h> #include <rpc/rpc.h> /* diff --git a/lib/libc/rpc/svc_raw.c b/lib/libc/rpc/svc_raw.c index f72a5f4cb1ef..80aa9a126f93 100644 --- a/lib/libc/rpc/svc_raw.c +++ b/lib/libc/rpc/svc_raw.c @@ -43,7 +43,7 @@ static char *rcsid = "$Id: svc_raw.c,v 1.2 1995/05/30 05:41:34 rgrimes Exp $"; */ #include <rpc/rpc.h> -#include <stdlib.h> + /* * This is the "network" that we will be moving data over diff --git a/lib/libc/rpc/svc_simple.c b/lib/libc/rpc/svc_simple.c index 8bcc3061e8c5..4b93a331dc82 100644 --- a/lib/libc/rpc/svc_simple.c +++ b/lib/libc/rpc/svc_simple.c @@ -41,8 +41,6 @@ static char *rcsid = "$Id: svc_simple.c,v 1.2 1995/05/30 05:41:37 rgrimes Exp $" */ #include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> #include <netdb.h> diff --git a/lib/libc/rpc/svc_tcp.c b/lib/libc/rpc/svc_tcp.c index b71fc6b8ed0d..94b5ea1dcb38 100644 --- a/lib/libc/rpc/svc_tcp.c +++ b/lib/libc/rpc/svc_tcp.c @@ -44,12 +44,11 @@ static char *rcsid = "$Id: svc_tcp.c,v 1.2 1995/05/30 05:41:38 rgrimes Exp $"; */ #include <stdio.h> -#include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> #include <errno.h> +extern bool_t abort(); +extern errno; /* * Ops vector for TCP/IP based rpc service handle @@ -307,8 +306,8 @@ readtcp(xprt, buf, len) #endif /* def FD_SETSIZE */ do { readfds = mask; - if (select(_rpc_dtablesize(), &readfds, (fd_set *)NULL, - (fd_set *)NULL, &wait_per_try) <= 0) { + if (select(_rpc_dtablesize(), &readfds, (int*)NULL, (int*)NULL, + &wait_per_try) <= 0) { if (errno == EINTR) { continue; } diff --git a/lib/libc/rpc/svc_udp.c b/lib/libc/rpc/svc_udp.c index b071355feff4..1491a582aa4f 100644 --- a/lib/libc/rpc/svc_udp.c +++ b/lib/libc/rpc/svc_udp.c @@ -43,8 +43,6 @@ static char *rcsid = "$Id: svc_udp.c,v 1.3 1995/05/30 05:41:39 rgrimes Exp $"; #include <stdio.h> #include <stdlib.h> -#include <unistd.h> -#include <string.h> #include <rpc/rpc.h> #include <sys/socket.h> #include <errno.h> diff --git a/lib/libc/stdio/Makefile.inc b/lib/libc/stdio/Makefile.inc index a549be2c1050..5ca501621a49 100644 --- a/lib/libc/stdio/Makefile.inc +++ b/lib/libc/stdio/Makefile.inc @@ -1,19 +1,18 @@ # @(#)Makefile.inc 8.3 (Berkeley) 4/17/94 -# $Id$ # stdio sources .PATH: ${.CURDIR}/stdio -SRCS+= asprintf.c clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c \ - fgetc.c fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \ +SRCS+= clrerr.c fclose.c fdopen.c feof.c ferror.c fflush.c fgetc.c \ + fgetln.c fgetpos.c fgets.c fileno.c findfp.c flags.c fopen.c \ fprintf.c fpurge.c fputc.c fputs.c fread.c freopen.c fscanf.c \ fseek.c fsetpos.c ftell.c funopen.c fvwrite.c fwalk.c fwrite.c \ getc.c getchar.c gets.c getw.c makebuf.c mktemp.c perror.c \ printf.c putc.c putchar.c puts.c putw.c refill.c remove.c rewind.c \ rget.c scanf.c setbuf.c setbuffer.c setvbuf.c snprintf.c sprintf.c \ - sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vasprintf.c \ - vfprintf.c vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c \ - vsscanf.c wbuf.c wsetup.c + sscanf.c stdio.c tempnam.c tmpfile.c tmpnam.c ungetc.c vfprintf.c \ + vfscanf.c vprintf.c vscanf.c vsnprintf.c vsprintf.c vsscanf.c \ + wbuf.c wsetup.c MAN3+= stdio/fclose.3 stdio/ferror.3 stdio/fflush.3 stdio/fgetln.3 \ stdio/fgets.3 stdio/fopen.3 stdio/fputs.3 stdio/fread.3 stdio/fseek.3 \ @@ -33,7 +32,7 @@ MLINKS+=getc.3 fgetc.3 getc.3 getchar.3 getc.3 getw.3 MLINKS+=mktemp.3 mkstemp.3 MLINKS+=printf.3 fprintf.3 printf.3 snprintf.3 printf.3 sprintf.3 \ printf.3 vfprintf.3 printf.3 vprintf.3 printf.3 vsnprintf.3 \ - printf.3 vsprintf.3 printf.3 asprintf.3 printf.3 vasprintf.3 + printf.3 vsprintf.3 MLINKS+=putc.3 fputc.3 putc.3 putchar.3 putc.3 putw.3 MLINKS+=scanf.3 fscanf.3 scanf.3 sscanf.3 scanf.3 vfscanf.3 scanf.3 vscanf.3 \ scanf.3 vsscanf.3 diff --git a/lib/libc/stdio/clrerr.c b/lib/libc/stdio/clrerr.c index a597b7b0baf3..de4526e0a7dc 100644 --- a/lib/libc/stdio/clrerr.c +++ b/lib/libc/stdio/clrerr.c @@ -40,20 +40,10 @@ static char sccsid[] = "@(#)clrerr.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #undef clearerr -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif void clearerr(fp) FILE *fp; { -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif __sclearerr(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif } diff --git a/lib/libc/stdio/fclose.c b/lib/libc/stdio/fclose.c index be9210801b50..8315c3cf41ea 100644 --- a/lib/libc/stdio/fclose.c +++ b/lib/libc/stdio/fclose.c @@ -42,12 +42,7 @@ static char sccsid[] = "@(#)fclose.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int fclose(fp) register FILE *fp; { @@ -57,9 +52,6 @@ fclose(fp) errno = EBADF; return (EOF); } -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif r = fp->_flags & __SWR ? __sflush(fp) : 0; if (fp->_close != NULL && (*fp->_close)(fp->_cookie) < 0) r = EOF; @@ -69,11 +61,7 @@ fclose(fp) FREEUB(fp); if (HASLB(fp)) FREELB(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif fp->_flags = 0; /* Release this FILE for reuse. */ - fp->_file = -1; fp->_r = fp->_w = 0; /* Mess up if reaccessed. */ return (r); } diff --git a/lib/libc/stdio/fflush.c b/lib/libc/stdio/fflush.c index fce893292e60..4a5cf0f43084 100644 --- a/lib/libc/stdio/fflush.c +++ b/lib/libc/stdio/fflush.c @@ -41,36 +41,21 @@ static char sccsid[] = "@(#)fflush.c 8.1 (Berkeley) 6/4/93"; #include <errno.h> #include <stdio.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* Flush a single file, or (if fp is NULL) all files. */ -int fflush(fp) register FILE *fp; { - int retval; if (fp == NULL) return (_fwalk(__sflush)); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif if ((fp->_flags & (__SWR | __SRW)) == 0) { errno = EBADF; - retval = EOF; - } else { - retval = __sflush(fp); + return (EOF); } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sflush(fp)); } -int __sflush(fp) register FILE *fp; { diff --git a/lib/libc/stdio/fgetc.c b/lib/libc/stdio/fgetc.c index 7e2738f6c48f..800846cda974 100644 --- a/lib/libc/stdio/fgetc.c +++ b/lib/libc/stdio/fgetc.c @@ -39,22 +39,9 @@ static char sccsid[] = "@(#)fgetc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int fgetc(fp) FILE *fp; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sgetc(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sgetc(fp)); } diff --git a/lib/libc/stdio/fgetpos.c b/lib/libc/stdio/fgetpos.c index 4ac0be4ed3e2..1f4ec1de23d6 100644 --- a/lib/libc/stdio/fgetpos.c +++ b/lib/libc/stdio/fgetpos.c @@ -39,23 +39,10 @@ static char sccsid[] = "@(#)fgetpos.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int fgetpos(fp, pos) FILE *fp; fpos_t *pos; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = (*pos = ftell(fp)) == (fpos_t)-1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return(retval); + return((*pos = ftell(fp)) == (fpos_t)-1); } diff --git a/lib/libc/stdio/fgets.c b/lib/libc/stdio/fgets.c index 186a1a1136ad..09f68772818d 100644 --- a/lib/libc/stdio/fgets.c +++ b/lib/libc/stdio/fgets.c @@ -40,11 +40,6 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; #include <stdio.h> #include <string.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Read at most n-1 characters from the given file. @@ -54,19 +49,16 @@ static char sccsid[] = "@(#)fgets.c 8.2 (Berkeley) 12/22/93"; char * fgets(buf, n, fp) char *buf; - register int n; + register size_t n; register FILE *fp; { register size_t len; register char *s; register unsigned char *p, *t; - if (n <= 0) /* sanity check */ + if (n == 0) /* sanity check */ return (NULL); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif s = buf; n--; /* leave space for NUL */ while (n != 0) { @@ -76,12 +68,8 @@ fgets(buf, n, fp) if ((len = fp->_r) <= 0) { if (__srefill(fp)) { /* EOF/error: stop with partial or no line */ - if (s == buf) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (s == buf) return (NULL); - } break; } len = fp->_r; @@ -103,9 +91,6 @@ fgets(buf, n, fp) fp->_p = t; (void)memcpy((void *)s, (void *)p, len); s[len] = 0; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (buf); } fp->_r -= len; @@ -115,8 +100,5 @@ fgets(buf, n, fp) n -= len; } *s = 0; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (buf); } diff --git a/lib/libc/stdio/findfp.c b/lib/libc/stdio/findfp.c index 2986a2ccbbd8..64548db20b3f 100644 --- a/lib/libc/stdio/findfp.c +++ b/lib/libc/stdio/findfp.c @@ -127,10 +127,6 @@ found: * XXX. Force immediate allocation of internal memory. Not used by stdio, * but documented historically for certain applications. Bad applications. */ -__warn_references(f_prealloc, - "warning: this program uses f_prealloc(), which is stupid."); - -void f_prealloc() { register struct glue *g; diff --git a/lib/libc/stdio/fpurge.c b/lib/libc/stdio/fpurge.c index 7cf54ffb2e38..3bee5132aa57 100644 --- a/lib/libc/stdio/fpurge.c +++ b/lib/libc/stdio/fpurge.c @@ -42,10 +42,6 @@ static char sccsid[] = "@(#)fpurge.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * fpurge: like fflush, but without writing anything: leave the @@ -55,23 +51,15 @@ int fpurge(fp) register FILE *fp; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif if (!fp->_flags) { errno = EBADF; - retval = EOF; - } else { - if (HASUB(fp)) - FREEUB(fp); - fp->_p = fp->_bf._base; - fp->_r = 0; - fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; - retval = 0; + return(EOF); } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + + if (HASUB(fp)) + FREEUB(fp); + fp->_p = fp->_bf._base; + fp->_r = 0; + fp->_w = fp->_flags & (__SLBF|__SNBF) ? 0 : fp->_bf._size; + return (0); } diff --git a/lib/libc/stdio/fputc.c b/lib/libc/stdio/fputc.c index 09b55d59a58e..c86f71161fc4 100644 --- a/lib/libc/stdio/fputc.c +++ b/lib/libc/stdio/fputc.c @@ -39,23 +39,10 @@ static char sccsid[] = "@(#)fputc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int fputc(c, fp) int c; register FILE *fp; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = putc(c, fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (putc(c, fp)); } diff --git a/lib/libc/stdio/fputs.c b/lib/libc/stdio/fputs.c index 92fcc303a690..9f9be2e2feee 100644 --- a/lib/libc/stdio/fputs.c +++ b/lib/libc/stdio/fputs.c @@ -41,20 +41,14 @@ static char sccsid[] = "@(#)fputs.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <string.h> #include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Write the given string to the given file. */ -int fputs(s, fp) const char *s; FILE *fp; { - int retval; struct __suio uio; struct __siov iov; @@ -62,12 +56,5 @@ fputs(s, fp) iov.iov_len = uio.uio_resid = strlen(s); uio.uio_iov = &iov; uio.uio_iovcnt = 1; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sfvwrite(fp, &uio); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sfvwrite(fp, &uio)); } diff --git a/lib/libc/stdio/fread.3 b/lib/libc/stdio/fread.3 index c3e591af9ddd..03a91412bc88 100644 --- a/lib/libc/stdio/fread.3 +++ b/lib/libc/stdio/fread.3 @@ -44,9 +44,9 @@ .Nd binary stream input/output .Sh SYNOPSIS .Fd #include <stdio.h> -.Ft size_t +.Ft int .Fn fread "void *ptr" "size_t size" "size_t nmemb" "FILE *stream" -.Ft size_t +.Ft int .Fn fwrite "const void *ptr" "size_t size" "size_t nmemb" "FILE *stream" .Sh DESCRIPTION The function diff --git a/lib/libc/stdio/fread.c b/lib/libc/stdio/fread.c index 7132e8544c01..22436ec8dcc1 100644 --- a/lib/libc/stdio/fread.c +++ b/lib/libc/stdio/fread.c @@ -40,11 +40,6 @@ static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; #include <stdio.h> #include <string.h> -#include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif size_t fread(buf, size, count, fp) @@ -64,9 +59,6 @@ fread(buf, size, count, fp) */ if ((resid = count * size) == 0) return (0); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif if (fp->_r < 0) fp->_r = 0; total = resid; @@ -85,8 +77,5 @@ fread(buf, size, count, fp) (void)memcpy((void *)p, (void *)fp->_p, resid); fp->_r -= resid; fp->_p += resid; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (count); } diff --git a/lib/libc/stdio/fscanf.c b/lib/libc/stdio/fscanf.c index bbb3155f94ad..f0e726af8490 100644 --- a/lib/libc/stdio/fscanf.c +++ b/lib/libc/stdio/fscanf.c @@ -44,20 +44,14 @@ static char sccsid[] = "@(#)fscanf.c 8.1 (Berkeley) 6/4/93"; #else #include <varargs.h> #endif -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif #if __STDC__ -int fscanf(FILE *fp, char const *fmt, ...) { int ret; va_list ap; va_start(ap, fmt); #else -int fscanf(fp, fmt, va_alist) FILE *fp; char *fmt; @@ -68,13 +62,7 @@ fscanf(fp, fmt, va_alist) va_start(ap); #endif -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif ret = __svfscanf(fp, fmt, ap); va_end(ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (ret); } diff --git a/lib/libc/stdio/fseek.c b/lib/libc/stdio/fseek.c index 1e99de9db2cc..9cb04ad03787 100644 --- a/lib/libc/stdio/fseek.c +++ b/lib/libc/stdio/fseek.c @@ -45,10 +45,6 @@ static char sccsid[] = "@(#)fseek.c 8.3 (Berkeley) 1/2/94"; #include <stdlib.h> #include <errno.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif #define POS_ERR (-(fpos_t)1) @@ -72,9 +68,6 @@ fseek(fp, offset, whence) if (!__sdidinit) __sinit(); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif /* * Have to be able to seek. */ @@ -99,12 +92,8 @@ fseek(fp, offset, whence) curoff = fp->_offset; else { curoff = (*seekfn)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (curoff == -1L) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (curoff == -1L) return (EOF); - } } if (fp->_flags & __SRD) { curoff -= fp->_r; @@ -126,9 +115,6 @@ fseek(fp, offset, whence) default: errno = EINVAL; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (EOF); } @@ -212,9 +198,6 @@ fseek(fp, offset, whence) if (HASUB(fp)) FREEUB(fp); fp->_flags &= ~__SEOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (0); } @@ -241,9 +224,6 @@ fseek(fp, offset, whence) fp->_p += n; fp->_r -= n; } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (0); /* @@ -253,9 +233,6 @@ fseek(fp, offset, whence) dumb: if (__sflush(fp) || (*seekfn)(fp->_cookie, (fpos_t)offset, whence) == POS_ERR) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (EOF); } /* success: clear EOF indicator and discard ungetc() data */ @@ -265,8 +242,5 @@ dumb: fp->_r = 0; /* fp->_w = 0; */ /* unnecessary (I think...) */ fp->_flags &= ~__SEOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (0); } diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c index abffc3e8daa1..724e5437812b 100644 --- a/lib/libc/stdio/ftell.c +++ b/lib/libc/stdio/ftell.c @@ -41,17 +41,13 @@ static char sccsid[] = "@(#)ftell.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <errno.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * ftell: return current offset. */ long ftell(fp) - register FILE *fp; + register const FILE *fp; { register fpos_t pos; @@ -60,9 +56,6 @@ ftell(fp) return (-1L); } -#ifdef _THREAD_SAFE - _thread_flockfile(fp, __FILE__, __LINE__); -#endif /* * Find offset of underlying I/O object, then * adjust for buffered bytes. @@ -71,12 +64,8 @@ ftell(fp) pos = fp->_offset; else { pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR); - if (pos == -1) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (pos == -1L) return (pos); - } } if (fp->_flags & __SRD) { /* @@ -95,8 +84,5 @@ ftell(fp) */ pos += fp->_p - fp->_bf._base; } -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (pos); } diff --git a/lib/libc/stdio/fwrite.c b/lib/libc/stdio/fwrite.c index 7efb0ac4e277..dbc2e978d7d0 100644 --- a/lib/libc/stdio/fwrite.c +++ b/lib/libc/stdio/fwrite.c @@ -41,10 +41,6 @@ static char sccsid[] = "@(#)fwrite.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include "local.h" #include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Write `count' objects (each size `size') from memory to the given file. @@ -65,18 +61,12 @@ fwrite(buf, size, count, fp) uio.uio_iov = &iov; uio.uio_iovcnt = 1; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif /* * The usual case is success (__sfvwrite returns 0); * skip the divide if this happens, since divides are * generally slow and since this occurs whenever size==0. */ - if (__sfvwrite(fp, &uio) != 0) - count = (n - uio.uio_resid) / size; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (count); + if (__sfvwrite(fp, &uio) == 0) + return (count); + return ((n - uio.uio_resid) / size); } diff --git a/lib/libc/stdio/getc.c b/lib/libc/stdio/getc.c index c0726ee2db64..1e900cd6e64a 100644 --- a/lib/libc/stdio/getc.c +++ b/lib/libc/stdio/getc.c @@ -39,27 +39,14 @@ static char sccsid[] = "@(#)getc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * A subroutine version of the macro getc. */ #undef getc -int getc(fp) register FILE *fp; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sgetc(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sgetc(fp)); } diff --git a/lib/libc/stdio/getchar.c b/lib/libc/stdio/getchar.c index 7aeef8af645f..20e52b79193e 100644 --- a/lib/libc/stdio/getchar.c +++ b/lib/libc/stdio/getchar.c @@ -42,23 +42,10 @@ static char sccsid[] = "@(#)getchar.c 8.1 (Berkeley) 6/4/93"; * A subroutine version of the macro getchar. */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif #undef getchar -int getchar() { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif - retval = getc(stdin); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif - return (retval); + return (getc(stdin)); } diff --git a/lib/libc/stdio/gets.c b/lib/libc/stdio/gets.c index d31aeeef9148..0517930bbcb1 100644 --- a/lib/libc/stdio/gets.c +++ b/lib/libc/stdio/gets.c @@ -40,9 +40,6 @@ static char sccsid[] = "@(#)gets.c 8.1 (Berkeley) 6/4/93"; #include <unistd.h> #include <stdio.h> -#include <sys/cdefs.h> - -__warn_references(gets, "warning: this program uses gets(), which is unsafe."); char * gets(buf) @@ -52,7 +49,7 @@ gets(buf) register char *s; static int warned; static char w[] = - "warning: this program uses gets(), which is unsafe.\n"; + "warning: this program uses gets(), which is unsafe.\r\n"; if (!warned) { (void) write(STDERR_FILENO, w, sizeof(w) - 1); diff --git a/lib/libc/stdio/mktemp.c b/lib/libc/stdio/mktemp.c index 3f5966e1f424..6cedd6a6be43 100644 --- a/lib/libc/stdio/mktemp.c +++ b/lib/libc/stdio/mktemp.c @@ -40,7 +40,6 @@ static char sccsid[] = "@(#)mktemp.c 8.1 (Berkeley) 6/4/93"; #include <fcntl.h> #include <errno.h> #include <stdio.h> -#include <unistd.h> #include <ctype.h> static int _gettemp(); diff --git a/lib/libc/stdio/printf.3 b/lib/libc/stdio/printf.3 index e675b3eda99b..4238a90a889e 100644 --- a/lib/libc/stdio/printf.3 +++ b/lib/libc/stdio/printf.3 @@ -43,12 +43,10 @@ .Nm fprintf , .Nm sprintf , .Nm snprintf , -.Nm asprintf , .Nm vprintf , .Nm vfprintf, .Nm vsprintf , -.Nm vsnprintf , -.Nm vasprintf +.Nm vsnprintf .Nd formatted output conversion .Sh SYNOPSIS .Fd #include <stdio.h> @@ -60,8 +58,8 @@ .Fn sprintf "char *str" "const char *format" ... .Ft int .Fn snprintf "char *str" "size_t size" "const char *format" ... -.Ft int -.Fn asprintf "char **ret" "const char *format" ... +.\" .Ft int +.\" .Fn smprintf "const char *format" ... .Fd #include <stdarg.h> .Ft int .Fn vprintf "const char *format" "va_list ap" @@ -71,8 +69,8 @@ .Fn vsprintf "char *str" "char *format" "va_list ap" .Ft int .Fn vsnprintf "char *str" "size_t size" "const char *format" "va_list ap" -.Ft int -.Fn vasprintf "char **ret" "const char *format" "va_list ap" +.\" .Ft int +.\" .Fn vsmprintf "const char *format" "va_list ap" .Sh DESCRIPTION The .Fn printf @@ -96,47 +94,45 @@ write output to the given output and .Fn vsnprintf write to the character string -.Fa str ; -and -.Fn asprintf -and -.Fn vasprintf -dynamically allocate a new string with -.Xr malloc 3 -/ -.Xr realloc 3 . -.Pp +.Fa str . +.\" .IR str ; +.\" and +.\" .I smprintf +.\" and +.\" .I vsmprintf +.\" dynamically allocate a new string with +.\" .IR malloc . These functions write the output under the control of a .Fa format string that specifies how subsequent arguments (or arguments accessed via the variable-length argument facilities of .Xr stdarg 3 ) are converted for output. -.Pp +.\" Except for +.\" .I smprintf +.\" and +.\" .IR vsmprintf , +.\" all of these functions return These functions return the number of characters printed (not including the trailing .Ql \e0 used to end output to strings). -.Pp -.Fn Asprintf -and -.Fn vasprintf -return a pointer to a buffer sufficiently large to hold the -string in the -.Fa ret -argument; -This pointer should be passed to -.Xr free 3 -to release the allocated storage when it is no longer needed. -If sufficient space cannot be allocated, -.Fn asprintf -and -.Fn vasprintf -will return -1 and set -.Fa ret -to be a NULL pointer. -.Pp +.\" .I Smprintf +.\" and +.\" .I vsmprintf +.\" return a pointer to a string of an appropriate length; +.\" this pointer should be passed to +.\" .I free +.\" to release the associated storage +.\" when it is no longer needed. +.\" If sufficient space is not avaliable, +.\" .I smprintf +.\" and +.\" .I vsmprintf +.\" will return +.\" .SM +.\" .BR .Fn Snprintf and .Fn vsnprintf @@ -151,7 +147,6 @@ if the return value is greater than or equal to the .Fa size argument, the string was too short and some of the printed characters were discarded. -.Pp .Fn Sprintf and .Fn vsprintf @@ -605,15 +600,6 @@ The functions and .Fn vsnprintf are new to this release. -.Pp -The functions -.Fn asprintf -and -.Fn vasprintf -first appeared in the GNU C library. This implementation is thought -to be compatable but is not derived from the GNU code. This implementation -was written by Peter Wemm <peter@FreeBSD.org> and first appeared in -FreeBSD-2.2. .Sh BUGS The conversion formats .Cm \&%D , diff --git a/lib/libc/stdio/putc.c b/lib/libc/stdio/putc.c index f1d42b11454b..c18353b7044a 100644 --- a/lib/libc/stdio/putc.c +++ b/lib/libc/stdio/putc.c @@ -39,28 +39,15 @@ static char sccsid[] = "@(#)putc.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * A subroutine version of the macro putc. */ #undef putc -int putc(c, fp) int c; register FILE *fp; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sputc(c, fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sputc(c, fp)); } diff --git a/lib/libc/stdio/putchar.c b/lib/libc/stdio/putchar.c index 5e04a6c72f2c..036b8970772c 100644 --- a/lib/libc/stdio/putchar.c +++ b/lib/libc/stdio/putchar.c @@ -39,29 +39,16 @@ static char sccsid[] = "@(#)putchar.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif #undef putchar /* * A subroutine version of the macro putchar */ -int putchar(c) int c; { - int retval; register FILE *so = stdout; -#ifdef _THREAD_SAFE - _thread_flockfile(so,__FILE__,__LINE__); -#endif - retval = __sputc(c, so); -#ifdef _THREAD_SAFE - _thread_funlockfile(so); -#endif - return (retval); + return (__sputc(c, so)); } diff --git a/lib/libc/stdio/puts.c b/lib/libc/stdio/puts.c index e8a35c533a51..96a81842b86f 100644 --- a/lib/libc/stdio/puts.c +++ b/lib/libc/stdio/puts.c @@ -41,19 +41,13 @@ static char sccsid[] = "@(#)puts.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <string.h> #include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Write the given string to stdout, appending a newline. */ -int puts(s) char const *s; { - int retval; size_t c = strlen(s); struct __suio uio; struct __siov iov[2]; @@ -65,12 +59,5 @@ puts(s) uio.uio_resid = c + 1; uio.uio_iov = &iov[0]; uio.uio_iovcnt = 2; -#ifdef _THREAD_SAFE - _thread_flockfile(stdout,__FILE__,__LINE__); -#endif - retval = __sfvwrite(stdout, &uio) ? EOF : '\n'; -#ifdef _THREAD_SAFE - _thread_funlockfile(stdout); -#endif - return (retval); + return (__sfvwrite(stdout, &uio) ? EOF : '\n'); } diff --git a/lib/libc/stdio/putw.c b/lib/libc/stdio/putw.c index 604bed0b7925..4ba898207f1e 100644 --- a/lib/libc/stdio/putw.c +++ b/lib/libc/stdio/putw.c @@ -40,17 +40,11 @@ static char sccsid[] = "@(#)putw.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int putw(w, fp) int w; FILE *fp; { - int retval; struct __suio uio; struct __siov iov; @@ -58,12 +52,5 @@ putw(w, fp) iov.iov_len = uio.uio_resid = sizeof(w); uio.uio_iov = &iov; uio.uio_iovcnt = 1; -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif - retval = __sfvwrite(fp, &uio); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (retval); + return (__sfvwrite(fp, &uio)); } diff --git a/lib/libc/stdio/rewind.c b/lib/libc/stdio/rewind.c index f20f6197f977..4f8391b5030f 100644 --- a/lib/libc/stdio/rewind.c +++ b/lib/libc/stdio/rewind.c @@ -40,22 +40,12 @@ static char sccsid[] = "@(#)rewind.c 8.1 (Berkeley) 6/4/93"; #include <errno.h> #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif void rewind(fp) register FILE *fp; { -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif (void) fseek(fp, 0L, SEEK_SET); clearerr(fp); -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif errno = 0; /* not required, but seems reasonable */ } diff --git a/lib/libc/stdio/scanf.c b/lib/libc/stdio/scanf.c index 5faf018711d3..d36b13a9ed55 100644 --- a/lib/libc/stdio/scanf.c +++ b/lib/libc/stdio/scanf.c @@ -44,16 +44,10 @@ static char sccsid[] = "@(#)scanf.c 8.1 (Berkeley) 6/4/93"; #else #include <varargs.h> #endif -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif #if __STDC__ -int scanf(char const *fmt, ...) #else -int scanf(fmt, va_alist) char *fmt; va_dcl @@ -67,13 +61,7 @@ scanf(fmt, va_alist) #else va_start(ap); #endif -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif ret = __svfscanf(stdin, fmt, ap); va_end(ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif return (ret); } diff --git a/lib/libc/stdio/setvbuf.c b/lib/libc/stdio/setvbuf.c index c6c037d7e293..867f9b4951f6 100644 --- a/lib/libc/stdio/setvbuf.c +++ b/lib/libc/stdio/setvbuf.c @@ -41,16 +41,11 @@ static char sccsid[] = "@(#)setvbuf.c 8.2 (Berkeley) 11/16/93"; #include <stdio.h> #include <stdlib.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Set one of the three kinds of buffering, optionally including * a buffer. */ -int setvbuf(fp, buf, mode, size) register FILE *fp; char *buf; @@ -70,9 +65,6 @@ setvbuf(fp, buf, mode, size) if ((mode != _IOFBF && mode != _IOLBF) || (int)size < 0) return (EOF); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif /* * Write current buffer, if any. Discard unread input (including * ungetc data), cancel line buffering, and free old buffer if @@ -124,9 +116,6 @@ nbf: fp->_w = 0; fp->_bf._base = fp->_p = fp->_nbuf; fp->_bf._size = 1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (ret); } flags |= __SMBF; @@ -167,8 +156,5 @@ nbf: } __cleanup = _cleanup; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (ret); } diff --git a/lib/libc/stdio/snprintf.c b/lib/libc/stdio/snprintf.c index 82fad1a75904..3c3cf7d8169b 100644 --- a/lib/libc/stdio/snprintf.c +++ b/lib/libc/stdio/snprintf.c @@ -46,10 +46,8 @@ static char sccsid[] = "@(#)snprintf.c 8.1 (Berkeley) 6/4/93"; #endif #if __STDC__ -int snprintf(char *str, size_t n, char const *fmt, ...) #else -int snprintf(str, n, fmt, va_alist) char *str; size_t n; @@ -68,7 +66,6 @@ snprintf(str, n, fmt, va_alist) #else va_start(ap); #endif - f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n - 1; diff --git a/lib/libc/stdio/sprintf.c b/lib/libc/stdio/sprintf.c index e71f7d091bc2..254064fabd54 100644 --- a/lib/libc/stdio/sprintf.c +++ b/lib/libc/stdio/sprintf.c @@ -48,10 +48,8 @@ static char sccsid[] = "@(#)sprintf.c 8.1 (Berkeley) 6/4/93"; #include "local.h" #if __STDC__ -int sprintf(char *str, char const *fmt, ...) #else -int sprintf(str, fmt, va_alist) char *str; char *fmt; @@ -62,7 +60,6 @@ sprintf(str, fmt, va_alist) va_list ap; FILE f; - f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = INT_MAX; diff --git a/lib/libc/stdio/sscanf.c b/lib/libc/stdio/sscanf.c index dc96312a5635..bb7274437802 100644 --- a/lib/libc/stdio/sscanf.c +++ b/lib/libc/stdio/sscanf.c @@ -59,10 +59,8 @@ eofread(cookie, buf, len) } #if __STDC__ -int sscanf(const char *str, char const *fmt, ...) #else -int sscanf(str, fmt, va_alist) char *str; char *fmt; @@ -73,7 +71,6 @@ sscanf(str, fmt, va_alist) va_list ap; FILE f; - f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._r = strlen(str); diff --git a/lib/libc/stdio/stdio.3 b/lib/libc/stdio/stdio.3 index 3bde13c391a7..7ebc782d06e3 100644 --- a/lib/libc/stdio/stdio.3 +++ b/lib/libc/stdio/stdio.3 @@ -63,7 +63,7 @@ If a file can support positioning requests (such as a disk file, as opposed to a terminal) then a .Em file position indicator associated with the stream is positioned at the start of the file (byte -zero), unless the file is opened with append mode. If append mode +zero), unless the file is opened with appended mode. If append mode is used, the position indicator will be placed the end-of-file. The position indicator is maintained by subsequent reads, writes and positioning requests. All input occurs as if the characters @@ -111,7 +111,7 @@ opened explicitly: (for reading conventional input), .It .Em standard output -(for writing conventional output), and +(for writing conventional input), and .It .Em standard error (for writing diagnostic output). @@ -229,7 +229,7 @@ feof check and reset stream status ferror check and reset stream status fflush flush a stream fgetc get next character or word from input stream -fgetln get a line from a stream +fgetline get a line from a stream fgetpos reposition a stream fgets get a line from a stream fileno check and reset stream status diff --git a/lib/libc/stdio/ungetc.c b/lib/libc/stdio/ungetc.c index 25f59d7420fb..deaed759992f 100644 --- a/lib/libc/stdio/ungetc.c +++ b/lib/libc/stdio/ungetc.c @@ -42,10 +42,6 @@ static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; #include <stdlib.h> #include <string.h> #include "local.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * Expand the ungetc buffer `in place'. That is, adjust fp->_p when @@ -53,7 +49,7 @@ static char sccsid[] = "@(#)ungetc.c 8.2 (Berkeley) 11/3/93"; * and move the bytes in the buffer around as necessary so that they * are all at the end (stack-style). */ -static int +static __submore(fp) register FILE *fp; { @@ -86,7 +82,6 @@ __submore(fp) return (0); } -int ungetc(c, fp) int c; register FILE *fp; @@ -95,27 +90,16 @@ ungetc(c, fp) return (EOF); if (!__sdidinit) __sinit(); -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif if ((fp->_flags & __SRD) == 0) { /* * Not already reading: no good unless reading-and-writing. * Otherwise, flush any current write stuff. */ - if ((fp->_flags & __SRW) == 0) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if ((fp->_flags & __SRW) == 0) return (EOF); - } if (fp->_flags & __SWR) { - if (__sflush(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (__sflush(fp)) return (EOF); - } fp->_flags &= ~__SWR; fp->_w = 0; fp->_lbfsize = 0; @@ -129,17 +113,10 @@ ungetc(c, fp) * This may require expanding the current ungetc buffer. */ if (HASUB(fp)) { - if (fp->_r >= fp->_ub._size && __submore(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (fp->_r >= fp->_ub._size && __submore(fp)) return (EOF); - } *--fp->_p = c; fp->_r++; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (c); } fp->_flags &= ~__SEOF; @@ -153,9 +130,6 @@ ungetc(c, fp) fp->_p[-1] == c) { fp->_p--; fp->_r++; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (c); } @@ -170,8 +144,5 @@ ungetc(c, fp) fp->_ubuf[sizeof(fp->_ubuf) - 1] = c; fp->_p = &fp->_ubuf[sizeof(fp->_ubuf) - 1]; fp->_r = 1; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif return (c); } diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 0f241deebe10..f53db612ff60 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -59,10 +59,6 @@ static char sccsid[] = "@(#)vfprintf.c 8.1 (Berkeley) 6/4/93"; #include "local.h" #include "fvwrite.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* Define FLOATING_POINT to get floating point. */ #define FLOATING_POINT @@ -306,7 +302,8 @@ vfprintf(fp, fmt0, ap) u_quad_t uqval; /* %q integers */ int base; /* base for [diouxX] conversion */ int dprec; /* a copy of prec if [diouxX], 0 otherwise */ - int realsz; /* field size expanded by dprec, sign, etc */ + int fieldsz; /* field size expanded by sign, etc */ + int realsz; /* field size expanded by dprec */ int size; /* size of converted field or string */ char *xdigs; /* digits for [xX] conversion */ #define NIOV 8 @@ -369,25 +366,14 @@ vfprintf(fp, fmt0, ap) flags&SHORTINT ? (u_long)(u_short)va_arg(ap, int) : \ (u_long)va_arg(ap, u_int)) -#ifdef _THREAD_SAFE - _thread_flockfile(fp,__FILE__,__LINE__); -#endif /* sorry, fprintf(read_only_file, "") returns EOF, not 0 */ - if (cantwrite(fp)) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + if (cantwrite(fp)) return (EOF); - } /* optimise fprintf(stderr) (and other unbuffered Unix files) */ if ((fp->_flags & (__SNBF|__SWR|__SRW)) == (__SNBF|__SWR) && - fp->_file >= 0) { -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif + fp->_file >= 0) return (__sbprintf(fp, fmt0, ap)); - } fmt = (char *)fmt0; uio.uio_iov = iovp = iov; @@ -707,13 +693,14 @@ number: if ((dprec = prec) >= 0) * floating precision; finally, if LADJUST, pad with blanks. * * Compute actual size, so we know how much to pad. - * size excludes decimal prec; realsz includes it. + * fieldsz excludes decimal prec; realsz includes it. */ - realsz = dprec > size ? dprec : size; + fieldsz = size; if (sign) - realsz++; + fieldsz++; else if (flags & HEXPREFIX) - realsz += 2; + fieldsz += 2; + realsz = dprec > fieldsz ? dprec : fieldsz; /* right-adjusting blank padding */ if ((flags & (LADJUST|ZEROPAD)) == 0) @@ -733,7 +720,7 @@ number: if ((dprec = prec) >= 0) PAD(width - realsz, zeroes); /* leading zeroes from decimal precision */ - PAD(dprec - size, zeroes); + PAD(dprec - fieldsz, zeroes); /* the string or number proper */ #ifdef FLOATING_POINT @@ -795,12 +782,7 @@ number: if ((dprec = prec) >= 0) done: FLUSH(); error: - if (__sferror(fp)) - ret = EOF; -#ifdef _THREAD_SAFE - _thread_funlockfile(fp); -#endif - return (ret); + return (__sferror(fp) ? EOF : ret); /* NOTREACHED */ } diff --git a/lib/libc/stdio/vscanf.c b/lib/libc/stdio/vscanf.c index 677039ecc8e4..5d128650b54b 100644 --- a/lib/libc/stdio/vscanf.c +++ b/lib/libc/stdio/vscanf.c @@ -39,24 +39,11 @@ static char sccsid[] = "@(#)vscanf.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ #include <stdio.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif -int vscanf(fmt, ap) const char *fmt; _BSD_VA_LIST_ ap; { - int retval; -#ifdef _THREAD_SAFE - _thread_flockfile(stdin,__FILE__,__LINE__); -#endif - retval = __svfscanf(stdin, fmt, ap); -#ifdef _THREAD_SAFE - _thread_funlockfile(stdin); -#endif - return (retval); + return (__svfscanf(stdin, fmt, ap)); } diff --git a/lib/libc/stdio/vsnprintf.c b/lib/libc/stdio/vsnprintf.c index 1bff18bb8d3d..ccc8af63f355 100644 --- a/lib/libc/stdio/vsnprintf.c +++ b/lib/libc/stdio/vsnprintf.c @@ -40,7 +40,6 @@ static char sccsid[] = "@(#)vsnprintf.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> -int vsnprintf(str, n, fmt, ap) char *str; size_t n; @@ -52,7 +51,6 @@ vsnprintf(str, n, fmt, ap) if ((int)n < 1) return (EOF); - f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = n - 1; diff --git a/lib/libc/stdio/vsprintf.c b/lib/libc/stdio/vsprintf.c index cdfb9ebb91f5..c6e192ae07c6 100644 --- a/lib/libc/stdio/vsprintf.c +++ b/lib/libc/stdio/vsprintf.c @@ -41,7 +41,6 @@ static char sccsid[] = "@(#)vsprintf.c 8.1 (Berkeley) 6/4/93"; #include <stdio.h> #include <limits.h> -int vsprintf(str, fmt, ap) char *str; const char *fmt; @@ -50,7 +49,6 @@ vsprintf(str, fmt, ap) int ret; FILE f; - f._file = -1; f._flags = __SWR | __SSTR; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._w = INT_MAX; diff --git a/lib/libc/stdio/vsscanf.c b/lib/libc/stdio/vsscanf.c index 0d4d05a10a4f..540f2906b89b 100644 --- a/lib/libc/stdio/vsscanf.c +++ b/lib/libc/stdio/vsscanf.c @@ -52,15 +52,14 @@ eofread(cookie, buf, len) return (0); } -int vsscanf(str, fmt, ap) const char *str; const char *fmt; _BSD_VA_LIST_ ap; { + int ret; FILE f; - f._file = -1; f._flags = __SRD; f._bf._base = f._p = (unsigned char *)str; f._bf._size = f._r = strlen(str); diff --git a/lib/libc/stdlib/Makefile.inc b/lib/libc/stdlib/Makefile.inc index 81e8ed030903..de3d864b36ea 100644 --- a/lib/libc/stdlib/Makefile.inc +++ b/lib/libc/stdlib/Makefile.inc @@ -14,10 +14,10 @@ SRCS+= abort.c atexit.c atof.c atoi.c atol.c bsearch.c calloc.c div.c \ MAN3+= stdlib/abort.3 stdlib/abs.3 stdlib/alloca.3 stdlib/atexit.3 \ stdlib/atof.3 stdlib/atoi.3 stdlib/atol.3 stdlib/bsearch.3 \ - stdlib/calloc.3 stdlib/div.3 stdlib/exit.3 \ + stdlib/calloc.3 stdlib/div.3 stdlib/exit.3 stdlib/free.3 \ stdlib/getenv.3 stdlib/getopt.3 stdlib/getsubopt.3 stdlib/labs.3 \ stdlib/ldiv.3 stdlib/malloc.3 stdlib/memory.3 stdlib/qsort.3 \ - stdlib/radixsort.3 stdlib/rand.3 stdlib/random.3 \ + stdlib/radixsort.3 stdlib/rand.3 stdlib/random.3 stdlib/realloc.3 \ stdlib/realpath.3 stdlib/strtod.3 stdlib/strtol.3 stdlib/strtoul.3 \ stdlib/system.3 @@ -27,4 +27,3 @@ MLINKS+=rand.3 srand.3 MLINKS+=random.3 initstate.3 random.3 setstate.3 random.3 srandom.3 MLINKS+=strtol.3 strtoq.3 MLINKS+=strtoul.3 strtouq.3 -MLINKS+=malloc.3 free.3 malloc.3 realloc.3 diff --git a/lib/libc/stdlib/abort.c b/lib/libc/stdlib/abort.c index f41500739fec..e56e7e97d6b1 100644 --- a/lib/libc/stdlib/abort.c +++ b/lib/libc/stdlib/abort.c @@ -35,14 +35,10 @@ static char sccsid[] = "@(#)abort.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ -#include <signal.h> +#include <sys/signal.h> #include <stdlib.h> #include <stddef.h> #include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif void abort() @@ -55,24 +51,15 @@ abort() * any errors -- X311J doesn't allow abort to return anyway. */ sigdelset(&mask, SIGABRT); -#ifdef _THREAD_SAFE - (void) _thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif (void)kill(getpid(), SIGABRT); /* * if SIGABRT ignored, or caught and the handler returns, do * it again, only harder. */ -#ifdef _THREAD_SAFE - (void) _thread_sys_signal(SIGABRT, SIG_DFL); - (void) _thread_sys_sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#else (void)signal(SIGABRT, SIG_DFL); (void)sigprocmask(SIG_SETMASK, &mask, (sigset_t *)NULL); -#endif (void)kill(getpid(), SIGABRT); exit(1); } diff --git a/lib/libc/stdlib/getenv.c b/lib/libc/stdlib/getenv.c index a6bbd355d93f..7407e0b81749 100644 --- a/lib/libc/stdlib/getenv.c +++ b/lib/libc/stdlib/getenv.c @@ -39,7 +39,20 @@ static char sccsid[] = "@(#)getenv.c 8.1 (Berkeley) 6/4/93"; #include <stddef.h> #include <string.h> -inline char *__findenv __P((const char *, int *)); +char *__findenv __P((const char *, int *)); + +/* + * getenv -- + * Returns ptr to value associated with name, if any, else NULL. + */ +char * +getenv(name) + const char *name; +{ + int offset; + + return (__findenv(name, &offset)); +} /* * __findenv -- @@ -50,42 +63,25 @@ inline char *__findenv __P((const char *, int *)); * * This routine *should* be a static; don't use it. */ -inline char * +char * __findenv(name, offset) register const char *name; int *offset; { extern char **environ; - register int len, i; + register int len; register const char *np; - register char **p, *cp; + register char **p, *c; if (name == NULL || environ == NULL) return (NULL); for (np = name; *np && *np != '='; ++np) continue; len = np - name; - for (p = environ; (cp = *p) != NULL; ++p) { - for (np = name, i = len; i && *cp; i--) - if (*cp++ != *np++) - break; - if (i == 0 && *cp++ == '=') { + for (p = environ; (c = *p) != NULL; ++p) + if (strncmp(c, name, len) == 0 && c[len] == '=') { *offset = p - environ; - return (cp); + return (c + len + 1); } - } return (NULL); } - -/* - * getenv -- - * Returns ptr to value associated with name, if any, else NULL. - */ -char * -getenv(name) - const char *name; -{ - int offset; - - return (__findenv(name, &offset)); -} diff --git a/lib/libc/stdlib/heapsort.c b/lib/libc/stdlib/heapsort.c index 964955381ea2..d800064f648a 100644 --- a/lib/libc/stdlib/heapsort.c +++ b/lib/libc/stdlib/heapsort.c @@ -38,9 +38,10 @@ static char sccsid[] = "@(#)heapsort.c 8.1 (Berkeley) 6/4/93"; #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> #include <errno.h> -#include <stddef.h> #include <stdlib.h> +#include <stddef.h> /* * Swap two areas of size number of bytes. Although qsort(3) permits random diff --git a/lib/libc/stdlib/ldiv.3 b/lib/libc/stdlib/ldiv.3 index 2b61499e4ecd..a68952f94b26 100644 --- a/lib/libc/stdlib/ldiv.3 +++ b/lib/libc/stdlib/ldiv.3 @@ -44,7 +44,7 @@ .Sh SYNOPSIS .Fd #include <stdlib.h> .Ft ldiv_t -.Fn ldiv "long num" "long denom" +.Fn ldiv "int num" "int denom" .Sh DESCRIPTION The .Fn ldiv diff --git a/lib/libc/stdlib/qsort.c b/lib/libc/stdlib/qsort.c index 7c3d2133a064..49f53495a10a 100644 --- a/lib/libc/stdlib/qsort.c +++ b/lib/libc/stdlib/qsort.c @@ -32,17 +32,13 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -#if 0 static char sccsid[] = "@(#)qsort.c 8.1 (Berkeley) 6/4/93"; -#endif -static const char rcsid[] = - "$Id$"; #endif /* LIBC_SCCS and not lint */ +#include <sys/types.h> #include <stdlib.h> -typedef int cmp_t __P((const void *, const void *)); -static inline char *med3 __P((char *, char *, char *, cmp_t *)); +static inline char *med3 __P((char *, char *, char *, int (*)())); static inline void swapfunc __P((char *, char *, int, int)); #define min(a, b) (a) < (b) ? a : b @@ -88,7 +84,7 @@ swapfunc(a, b, n, swaptype) static inline char * med3(a, b, c, cmp) char *a, *b, *c; - cmp_t *cmp; + int (*cmp)(); { return cmp(a, b) < 0 ? (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) @@ -99,7 +95,7 @@ void qsort(a, n, es, cmp) void *a; size_t n, es; - cmp_t *cmp; + int (*cmp)(); { char *pa, *pb, *pc, *pd, *pl, *pm, *pn; int d, r, swaptype, swap_cnt; diff --git a/lib/libc/stdlib/strhash.c b/lib/libc/stdlib/strhash.c index 1ccda325d447..860d52a5212e 100644 --- a/lib/libc/stdlib/strhash.c +++ b/lib/libc/stdlib/strhash.c @@ -1,5 +1,5 @@ #ifndef lint -static char *rcsid = "$Header: /home/ncvs/src/lib/libc/stdlib/strhash.c,v 1.4.4.1 1996/02/11 09:05:56 jkh Exp $"; +static char *rcsid = "$Header: /pub/FreeBSD/FreeBSD-CVS/src/lib/libc/stdlib/strhash.c,v 1.4.4.1 1996/02/11 09:05:56 jkh Exp $"; #endif /* diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc index c67bf9735a93..4d93c365ada8 100644 --- a/lib/libc/stdtime/Makefile.inc +++ b/lib/libc/stdtime/Makefile.inc @@ -8,4 +8,3 @@ MAN3+= stdtime/ctime.3 stdtime/strftime.3 stdtime/time2posix.3 MLINKS+=ctime.3 asctime.3 ctime.3 difftime.3 ctime.3 gmtime.3 \ ctime.3 localtime.3 ctime.3 mktime.3 -MLINKS+=time2posix.3 posix2time.3 diff --git a/lib/libc/stdtime/asctime.c b/lib/libc/stdtime/asctime.c index 1655f6a26576..107b44c4b5cd 100644 --- a/lib/libc/stdtime/asctime.c +++ b/lib/libc/stdtime/asctime.c @@ -1,4 +1,5 @@ + #ifndef lint #ifndef NOID static char elsieid[] = "@(#)asctime.c 7.5"; diff --git a/lib/libc/stdtime/localtime.c b/lib/libc/stdtime/localtime.c index c4cfc8899be9..c6fae73d9a10 100644 --- a/lib/libc/stdtime/localtime.c +++ b/lib/libc/stdtime/localtime.c @@ -17,10 +17,6 @@ static char elsieid[] = "@(#)localtime.c 7.44"; #include "private.h" #include "tzfile.h" #include "fcntl.h" -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* ** SunOS 4.1.1 headers lack O_BINARY. @@ -164,10 +160,6 @@ static struct state gmtmem; static char lcl_TZname[TZ_STRLEN_MAX + 1]; static int lcl_is_set; static int gmt_is_set; -#ifdef _THREAD_SAFE -static pthread_mutex_t lcl_mutex = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t gmt_mutex = PTHREAD_MUTEX_INITIALIZER; -#endif char * tzname[2] = { wildabbr, @@ -916,13 +908,8 @@ struct state * const sp; */ static #endif /* !defined STD_INSPIRED */ -#ifdef _THREAD_SAFE -void -tzsetwall_basic P((void)) -#else void tzsetwall P((void)) -#endif { if (lcl_is_set < 0) return; @@ -942,23 +929,8 @@ tzsetwall P((void)) settzname(); } -#ifdef _THREAD_SAFE -void -tzsetwall P((void)) -{ - pthread_mutex_lock(&lcl_mutex); - tzsetwall_basic(); - pthread_mutex_unlock(&lcl_mutex); -} -#endif - -#ifdef _THREAD_SAFE -static void -tzset_basic P((void)) -#else void tzset P((void)) -#endif { register const char * name; @@ -998,16 +970,6 @@ tzset P((void)) settzname(); } -#ifdef _THREAD_SAFE -void -tzset P((void)) -{ - pthread_mutex_lock(&lcl_mutex); - tzset_basic(); - pthread_mutex_unlock(&lcl_mutex); -} -#endif - /* ** The easy way to behave "as if no library function calls" localtime ** is to not call it--so we drop its guts into "localsub", which can be @@ -1064,55 +1026,13 @@ struct tm * const tmp; #endif /* defined TM_ZONE */ } -#ifdef _THREAD_SAFE -int -localtime_r(timep, p_tm) -const time_t * const timep; -struct tm *p_tm; -{ - pthread_mutex_lock(&lcl_mutex); - tzset(); - localsub(timep, 0L, p_tm); - pthread_mutex_unlock(&lcl_mutex); - return(0); -} -#endif - struct tm * localtime(timep) const time_t * const timep; { -#ifdef _THREAD_SAFE - static pthread_mutex_t localtime_mutex = PTHREAD_MUTEX_INITIALIZER; - static pthread_key_t localtime_key = -1; - struct tm *p_tm; - - pthread_mutex_lock(&localtime_mutex); - if (localtime_key < 0) { - if (pthread_keycreate(&localtime_key, free) < 0) { - pthread_mutex_unlock(&localtime_mutex); - return(NULL); - } - } - pthread_mutex_unlock(&localtime_mutex); - if (pthread_getspecific(localtime_key,(void **) &p_tm) != 0) { - return(NULL); - } else if (p_tm == NULL) { - if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { - return(NULL); - } - pthread_setspecific(localtime_key, p_tm); - } - pthread_mutex_lock(&lcl_mutex); - tzset(); - localsub(timep, 0L, p_tm); - pthread_mutex_unlock(&lcl_mutex); - return p_tm; -#else tzset(); localsub(timep, 0L, &tm); return &tm; -#endif } /* @@ -1125,9 +1045,6 @@ const time_t * const timep; const long offset; struct tm * const tmp; { -#ifdef _THREAD_SAFE - pthread_mutex_lock(&gmt_mutex); -#endif if (!gmt_is_set) { gmt_is_set = TRUE; #ifdef ALL_STATE @@ -1136,9 +1053,6 @@ struct tm * const tmp; #endif /* defined ALL_STATE */ gmtload(gmtptr); } -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&gmt_mutex); -#endif timesub(timep, offset, gmtptr, tmp); #ifdef TM_ZONE /* @@ -1165,43 +1079,9 @@ struct tm * gmtime(timep) const time_t * const timep; { -#ifdef _THREAD_SAFE - static pthread_mutex_t gmtime_mutex = PTHREAD_MUTEX_INITIALIZER; - static pthread_key_t gmtime_key = -1; - struct tm *p_tm; - - pthread_mutex_lock(&gmtime_mutex); - if (gmtime_key < 0) { - if (pthread_keycreate(&gmtime_key, free) < 0) { - pthread_mutex_unlock(&gmtime_mutex); - return(NULL); - } - } - pthread_mutex_unlock(&gmtime_mutex); - if (pthread_getspecific(gmtime_key,(void **) &p_tm) != 0) { - return(NULL); - } else if (p_tm == NULL) { - if ((p_tm = (struct tm *)malloc(sizeof(struct tm))) == NULL) { - return(NULL); - } - pthread_setspecific(gmtime_key, p_tm); - } - gmtsub(timep, 0L, p_tm); - return(p_tm); -#else gmtsub(timep, 0L, &tm); return &tm; -#endif -} - -#ifdef _THREAD_SAFE -int -gmtime_r(const time_t * timep, struct tm * tm) -{ - gmtsub(timep, 0L, tm); - return(0); } -#endif #ifdef STD_INSPIRED @@ -1604,16 +1484,8 @@ time_t mktime(tmp) struct tm * const tmp; { - time_t mktime_return_value; -#ifdef _THREAD_SAFE - pthread_mutex_lock(&lcl_mutex); -#endif tzset(); - mktime_return_value = time1(tmp, localsub, 0L); -#ifdef _THREAD_SAFE - pthread_mutex_unlock(&lcl_mutex); -#endif - return(mktime_return_value); + return time1(tmp, localsub, 0L); } #ifdef STD_INSPIRED diff --git a/lib/libc/stdtime/strftime.c b/lib/libc/stdtime/strftime.c index 653d6ba74c58..b0e82a7d639e 100644 --- a/lib/libc/stdtime/strftime.c +++ b/lib/libc/stdtime/strftime.c @@ -483,17 +483,15 @@ __time_load_locale(const char *name) struct stat st; size_t namesize; size_t bufsize; - int save_using_locale; - save_using_locale = using_locale; using_locale = 0; - if (name == NULL) - goto no_locale; - - if (!*name || !strcmp(name, "C") || !strcmp(name, "POSIX")) + if (!strcmp(name, "C") || !strcmp(name, "POSIX")) return 0; + if (name == NULL || *name == '\0') { + goto no_locale; + } /* ** If the locale name is the same as our cache, use the cache. */ @@ -516,8 +514,9 @@ __time_load_locale(const char *name) "%s/%s/%s", _PathLocale, name, lc_time); fd = open(filename, O_RDONLY); - if (fd < 0) + if (fd < 0) { goto no_locale; + } if (fstat(fd, &st) != 0) goto bad_locale; if (st.st_size <= 0) @@ -544,7 +543,7 @@ __time_load_locale(const char *name) ap < (const char **) (&localebuf + 1); ++ap) { if (p == plim) - goto reset_locale; + goto bad_lbuf; *ap = p; while (*p != '\n') ++p; @@ -558,19 +557,16 @@ __time_load_locale(const char *name) using_locale = 1; return 0; -reset_locale: +bad_lbuf: + free(lbuf); +bad_locale: + (void) close(fd); +no_locale: /* * XXX - This may not be the correct thing to do in this case. * setlocale() assumes that we left the old locale alone. */ locale_buf = locale_buf_C; localebuf = C_time_locale; - save_using_locale = 0; -bad_lbuf: - free(lbuf); -bad_locale: - (void) close(fd); -no_locale: - using_locale = save_using_locale; return -1; } diff --git a/lib/libc/stdtime/tzfile.5 b/lib/libc/stdtime/tzfile.5 index f894390cc1cd..4bff7de04d12 100644 --- a/lib/libc/stdtime/tzfile.5 +++ b/lib/libc/stdtime/tzfile.5 @@ -3,7 +3,7 @@ .Os FreeBSD 2.0 .Sh NAME .Nm tzfile -.Nd timezone information +.Nd time zone information .Sh SYNOPSIS .Fd #include <tzfile.h> .Sh DESCRIPTION @@ -40,7 +40,7 @@ four-byte values of type sorted in ascending order. These values are written in ``standard'' byte order. Each is used as a transition time (as returned by -.Xr time 3 ) +.Xr time 2 ) at which the rules for computing local time change. Next come .Li tzh_timecnt @@ -89,7 +89,7 @@ Then there are pairs of four-byte values, written in standard byte order; the first value of each pair gives the time (as returned by -.Xr time 3 ) +.Xr time 2 ) at which a leap second occurs; the second gives the .Em total diff --git a/lib/libc/string/Makefile.inc b/lib/libc/string/Makefile.inc index c88832cf5be2..336476aa7938 100644 --- a/lib/libc/string/Makefile.inc +++ b/lib/libc/string/Makefile.inc @@ -1,5 +1,4 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/4/93 -# $Id$ .PATH: ${.CURDIR}/${MACHINE}/string ${.CURDIR}/string @@ -17,12 +16,12 @@ OBJS+= bzero.o bzero.o: memset.c ${CC} -DBZERO ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} @${LD} -x -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} bzero.po: memset.c ${CC} -DBZERO ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} @${LD} -X -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} .endif # If no machine specific memmove(3), build one out of bcopy(3). @@ -31,12 +30,12 @@ OBJS+= memmove.o memmove.o: bcopy.c ${CC} -DMEMMOVE ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} @${LD} -x -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} memmove.po: bcopy.c ${CC} -DMEMMOVE ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} @${LD} -X -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} .endif # If no machine specific memcpy(3), build one out of bcopy(3). @@ -45,12 +44,12 @@ OBJS+= memcpy.o memcpy.o: bcopy.c ${CC} -DMEMCOPY ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} @${LD} -x -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} memcpy.po: bcopy.c ${CC} -DMEMCOPY ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} @${LD} -X -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} .endif # If no machine specific strchr(3), build one out of index(3). @@ -59,12 +58,12 @@ OBJS+= strchr.o strchr.o: index.c ${CC} -DSTRCHR ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} @${LD} -x -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} strchr.po: index.c ${CC} -DSTRCHR ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} @${LD} -X -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} .endif # If no machine specific strrchr(3), build one out of rindex(3). @@ -73,12 +72,12 @@ OBJS+= strrchr.o strrchr.o: rindex.c ${CC} -DSTRRCHR ${CFLAGS} -c ${.ALLSRC} -o ${.TARGET} @${LD} -x -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} strrchr.po: rindex.c ${CC} -DSTRRCHR ${CFLAGS} -c -p ${.ALLSRC} -o ${.TARGET} @${LD} -X -r ${.TARGET} - @mv -f a.out ${.TARGET} + @mv a.out ${.TARGET} .endif # MAN3+= string/bcmp.3 string/bcopy.3 string/bstring.3 string/bzero.3 \ @@ -95,4 +94,4 @@ MLINKS+=strcasecmp.3 strncasecmp.3 MLINKS+=strcat.3 strncat.3 MLINKS+=strcmp.3 strncmp.3 MLINKS+=strcpy.3 strncpy.3 -MLINKS+=strerror.3 perror.3 strerror.3 sys_errlist.3 strerror.3 sys_nerr.3 +MLINKS+=strerror.3 perror.3 diff --git a/lib/libc/sys/Makefile.inc b/lib/libc/sys/Makefile.inc index 431aa04ce782..dc65844af2ca 100644 --- a/lib/libc/sys/Makefile.inc +++ b/lib/libc/sys/Makefile.inc @@ -1,5 +1,4 @@ # @(#)Makefile.inc 8.1 (Berkeley) 6/17/93 -# $Id$ # sys sources .PATH: ${.CURDIR}/${MACHINE}/sys ${.CURDIR}/sys @@ -22,13 +21,11 @@ ASM= accept.o access.o acct.o adjtime.o bind.o chdir.o chflags.o chmod.o \ getrlimit.o getrusage.o getsockname.o getsockopt.o gettimeofday.o \ getuid.o ioctl.o kill.o ktrace.o lfs_bmapv.o lfs_markv.o \ lfs_segclean.o lfs_segwait.o link.o listen.o lstat.o \ - madvise.o mincore.o minherit.o mkdir.o mkfifo.o mknod.o mlock.o \ - mount.o \ + madvise.o mincore.o mkdir.o mkfifo.o mknod.o mlock.o mount.o \ mprotect.o msgsys.o msync.o munlock.o munmap.o nfssvc.o \ ntp_adjtime.o open.o pathconf.o profil.o quotactl.o read.o \ readlink.o readv.o recvfrom.o recvmsg.o rename.o revoke.o rmdir.o \ - rtprio.o select.o semsys.o sendmsg.o sendto.o setegid.o seteuid.o \ - setgid.o \ + rtprio.o select.o semsys.o sendmsg.o sendto.o setegid.o seteuid.o setgid.o \ setgroups.o setitimer.o setpgid.o setpriority.o \ setregid.o setreuid.o setrlimit.o \ setsid.o setsockopt.o settimeofday.o setuid.o shmsys.o shutdown.o \ @@ -92,13 +89,11 @@ MAN2+= sys/accept.2 sys/access.2 sys/acct.2 sys/adjtime.2 sys/bind.2 \ sys/getrlimit.2 sys/getrusage.2 sys/getsockname.2 sys/getsockopt.2 \ sys/gettimeofday.2 sys/getuid.2 sys/intro.2 sys/ioctl.2 sys/kill.2 \ sys/ktrace.2 sys/link.2 sys/listen.2 sys/lseek.2 sys/mkdir.2 \ - sys/mkfifo.2 sys/mknod.2 sys/madvise.2 sys/mincore.2 sys/minherit.2 \ - sys/mlock.2 \ + sys/mkfifo.2 sys/mknod.2 sys/madvise.2 sys/mincore.2 sys/mlock.2 \ sys/mmap.2 sys/mount.2 sys/mprotect.2 sys/msync.2 sys/munmap.2 \ - sys/ptrace.2 sys/nfssvc.2 sys/open.2 sys/pathconf.2 sys/pipe.2 \ - sys/profil.2 sys/quotactl.2 sys/read.2 sys/readlink.2 sys/reboot.2 \ - sys/recv.2 sys/rename.2 sys/revoke.2 sys/rmdir.2 \ - sys/rtprio.2 sys/select.2 \ + sys/nfssvc.2 sys/open.2 sys/pathconf.2 sys/pipe.2 sys/profil.2 \ + sys/quotactl.2 sys/read.2 sys/readlink.2 sys/reboot.2 sys/recv.2 \ + sys/rename.2 sys/revoke.2 sys/rmdir.2 sys/rtprio.2 sys/select.2 \ sys/semctl.2 sys/semget.2 sys/semop.2 \ sys/send.2 sys/setgroups.2 \ sys/setpgid.2 sys/setregid.2 sys/setreuid.2 \ @@ -110,6 +105,8 @@ MAN2+= sys/accept.2 sys/access.2 sys/acct.2 sys/adjtime.2 sys/bind.2 \ sys/sync.2 sys/syscall.2 sys/truncate.2 sys/umask.2 sys/unlink.2 \ sys/utimes.2 sys/vfork.2 sys/wait.2 sys/write.2 +# missing: ptrace.2 + MLINKS+=brk.2 sbrk.2 MLINKS+=dup.2 dup2.2 MLINKS+=chdir.2 fchdir.2 diff --git a/lib/libc/sys/_exit.2 b/lib/libc/sys/_exit.2 index 12a5f7e0967d..73e60627453a 100644 --- a/lib/libc/sys/_exit.2 +++ b/lib/libc/sys/_exit.2 @@ -53,7 +53,7 @@ This may entail delays, for example, waiting for output to drain; a process in this state may not be killed, as it is already dying. .It If the parent process of the calling process has an outstanding -.Xr wait 2 +.Xr wait call or catches the .Dv SIGCHLD diff --git a/lib/libc/sys/accept.2 b/lib/libc/sys/accept.2 index 126000a2ecb6..d475e3685b43 100644 --- a/lib/libc/sys/accept.2 +++ b/lib/libc/sys/accept.2 @@ -129,31 +129,6 @@ by issuing a call with providing only the control information, or by calling .Xr setsockopt 2 . -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn accept -is implemented as the -.Va accept -syscall. -.Pp -In the threaded library, the -.Va accept -syscall is assembled to -.Fn _thread_sys_accept -and -.Fn accept -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_accept . -If the call to -.Fn _thread_sys_accept -would block, a context switch is performed. Before returning, -.Fn accept -unlocks -.Va s . -.Pp .Sh RETURN VALUES The call returns \-1 on error. If it succeeds, it returns a non-negative integer that is a descriptor for the accepted socket. diff --git a/lib/libc/sys/bind.2 b/lib/libc/sys/bind.2 index f98631d7939b..18512e29e5c9 100644 --- a/lib/libc/sys/bind.2 +++ b/lib/libc/sys/bind.2 @@ -62,28 +62,6 @@ needed (using .Pp The rules used in name binding vary between communication domains. Consult the manual entries in section 4 for detailed information. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn bind -is implemented as the -.Va bind -syscall. -.Pp -In the threaded library, the -.Va bind -syscall is assembled to -.Fn _thread_sys_bind -and -.Fn bind -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_bind . -Before returning, -.Fn bind -unlocks -.Va s . .Sh RETURN VALUES If the bind is successful, a 0 value is returned. A return value of -1 indicates an error, which is diff --git a/lib/libc/sys/brk.2 b/lib/libc/sys/brk.2 index 0e34e4f7daa9..7580f3855dbf 100644 --- a/lib/libc/sys/brk.2 +++ b/lib/libc/sys/brk.2 @@ -94,7 +94,7 @@ it will not be possible to set the break beyond the .Em rlim_max value returned from a call to -.Xr getrlimit 2 , +.Xr getrlimit , e.g. .Dq qetext + rlp\(->rlim_max. (see @@ -109,12 +109,12 @@ otherwise -1 with set to indicate why the allocation failed. The .Nm sbrk -function returns a pointer to the base of the new storage if successful; +returns a pointer to the base of the new storage if successful; otherwise -1 with .Va errno set to indicate why the allocation failed. .Sh ERRORS -.Fn Sbrk +.Xr Sbrk will fail and no additional memory will be allocated if one of the following are true: .Bl -tag -width [ENOMEM] @@ -139,7 +139,7 @@ Setting the break may fail due to a temporary lack of swap space. It is not possible to distinguish this from a failure caused by exceeding the maximum size of the data segment without consulting -.Xr getrlimit 2 . +.Xr getrlimit . .Sh HISTORY A .Nm diff --git a/lib/libc/sys/chown.2 b/lib/libc/sys/chown.2 index 89656f3b2dca..11c3956898e8 100644 --- a/lib/libc/sys/chown.2 +++ b/lib/libc/sys/chown.2 @@ -66,8 +66,7 @@ capability is restricted to the super-user. clears the set-user-id and set-group-id bits on the file to prevent accidental or mischievous creation of -set-user-id and set-group-id programs if not executed -by the super-user. +set-user-id and set-group-id programs. .Pp .Fn Fchown is particularly useful when used in conjunction diff --git a/lib/libc/sys/close.2 b/lib/libc/sys/close.2 index 3a64dac01887..885ac807b693 100644 --- a/lib/libc/sys/close.2 +++ b/lib/libc/sys/close.2 @@ -78,7 +78,7 @@ of the descriptors can be rearranged with or deleted with .Fn close before the -.Xr execve 2 +.Xr execve is attempted, but if some of these descriptors will still be needed if the execve fails, it is necessary to arrange for them to be closed if the execve succeeds. @@ -90,28 +90,6 @@ execve; the call .Dq Li fcntl(d, F_SETFD, 0) restores the default, which is to not close the descriptor. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn close -is implemented as the -.Va close -syscall. -.Pp -In the threaded library, the -.Va close -syscall is assembled to -.Fn _thread_sys_close -and -.Fn close -is implemented as a function which locks -.Va d -for read and write, then calls -.Fn _thread_sys_close . -Before returning, -.Fn close -unlocks -.Va d . .Sh RETURN VALUES Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and the global integer variable diff --git a/lib/libc/sys/connect.2 b/lib/libc/sys/connect.2 index a6d7c7133165..eb38ab320b4b 100644 --- a/lib/libc/sys/connect.2 +++ b/lib/libc/sys/connect.2 @@ -68,30 +68,6 @@ only once; datagram sockets may use multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn connect -is implemented as the -.Va connect -syscall. -.Pp -In the threaded library, the -.Va connect -syscall is assembled to -.Fn _thread_sys_connect -and -.Fn connect -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_connect . -If the call to -.Fn _thread_sys_connect -would block, a context switch is performed. Before returning, -.Fn connect -unlocks -.Va s . .Sh RETURN VALUES If the connection or binding succeeds, 0 is returned. Otherwise a -1 is returned, and a more specific error @@ -103,10 +79,10 @@ The call fails if: .Bl -tag -width EADDRNOTAVAILABB .It Bq Er EBADF -.Fa s +.Fa S is not a valid descriptor. .It Bq Er ENOTSOCK -.Fa s +.Fa S is a descriptor for a file, not a socket. .It Bq Er EADDRNOTAVAIL The specified address is not available on this machine. diff --git a/lib/libc/sys/dup.2 b/lib/libc/sys/dup.2 index 29d1ada27b77..898963923e8c 100644 --- a/lib/libc/sys/dup.2 +++ b/lib/libc/sys/dup.2 @@ -95,53 +95,6 @@ is specified. If this descriptor is already in use, the descriptor is first deallocated as if a .Xr close 2 call had been done first. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn dup -is implemented as the -.Va dup -syscall. -.Pp -In the threaded library, the -.Va dup -syscall is assembled to -.Fn _thread_sys_dup -and -.Fn dup -is implemented as a function which locks -.Va oldd -for read and write, then calls -.Fn _thread_sys_dup . -Before returning, -.Fn dup -unlocks -.Va oldd . -.Pp -In the non-threaded library -.Fn dup2 -is implemented as the -.Va dup2 -syscall. -.Pp -In the threaded library, the -.Va dup2 -syscall is assembled to -.Fn _thread_sys_dup2 -and -.Fn dup2 -is implemented as a function which locks both -.Va oldd -and -.Va newd -for read and write, then calls -.Fn _thread_sys_dup2 . -Before returning, -.Fn dup2 -unlocks -.Va oldd . -and -.Va newd . .Sh RETURN VALUES The value -1 is returned if an error occurs in either call. The external variable diff --git a/lib/libc/sys/execve.2 b/lib/libc/sys/execve.2 index 4db261896152..ba47e6d1833c 100644 --- a/lib/libc/sys/execve.2 +++ b/lib/libc/sys/execve.2 @@ -178,23 +178,6 @@ and .Fa argv points to the array of character pointers to the arguments themselves. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn execve -is implemented as the -.Va execve -syscall. -.Pp -In the threaded library, the -.Va execve -syscall is assembled to -.Fn _thread_sys_execve -and -.Fn execve -is implemented as a function which performs user-thread -library re-initialization and then calls -.Fn _thread_sys_execve . .Sh RETURN VALUES As the .Fn execve @@ -244,7 +227,7 @@ is larger than the system-imposed limit. The limit in the system as released is 20480 bytes .Pf ( Dv NCARGS in -.Ao Pa sys/param.h Ac ) . +.Ao Pa sys/param.h Ac . .It Bq Er EFAULT The new process file is not as long as indicated by the size values in its header. @@ -267,10 +250,9 @@ the real is ``root'', then the program has some of the powers of a super-user as well. .Sh SEE ALSO -.Xr _exit 2 , +.Xr exit 2 , .Xr fork 2 , .Xr execl 3 , -.Xr exit 3 , .Xr environ 7 .Sh HISTORY The diff --git a/lib/libc/sys/flock.2 b/lib/libc/sys/flock.2 index 5ec080c5f5d1..bb6abb75fc5b 100644 --- a/lib/libc/sys/flock.2 +++ b/lib/libc/sys/flock.2 @@ -109,28 +109,6 @@ forks and the child explicitly unlocks the file, the parent will lose its lock. .Pp Processes blocked awaiting a lock may be awakened by signals. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn flock -is implemented as the -.Va flock -syscall. -.Pp -In the threaded library, the -.Va flock -syscall is assembled to -.Fn _thread_sys_flock -and -.Fn flock -is implemented as a function which locks -.Va fd -for read and write, then calls -.Fn _thread_sys_flock . -Before returning, -.Fn flock -unlocks -.Va fd . .Sh RETURN VALUES Zero is returned if the operation was successful; on an error a -1 is returned and an error code is left in diff --git a/lib/libc/sys/fork.2 b/lib/libc/sys/fork.2 index b8d465a0892d..0c290f69bd1c 100644 --- a/lib/libc/sys/fork.2 +++ b/lib/libc/sys/fork.2 @@ -59,9 +59,9 @@ for instance, file pointers in file objects are shared between the child and the parent, so that an .Xr lseek 2 on a descriptor in the child process can affect a subsequent -.Xr read 2 +.Xr read or -.Xr write 2 +.Xr write by the parent. This descriptor copying is also used by the shell to establish standard input and output for newly created processes diff --git a/lib/libc/sys/fsync.2 b/lib/libc/sys/fsync.2 index 313b4c7a7116..234ea6e996ed 100644 --- a/lib/libc/sys/fsync.2 +++ b/lib/libc/sys/fsync.2 @@ -53,28 +53,6 @@ of buffers for the associated file to be written to a disk. should be used by programs that require a file to be in a known state, for example, in building a simple transaction facility. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn fsync -is implemented as the -.Va fsync -syscall. -.Pp -In the threaded library, the -.Va fsync -syscall is assembled to -.Fn _thread_sys_fsync -and -.Fn fsync -is implemented as a function which locks -.Va fd -for read and write, then calls -.Fn _thread_sys_fsync . -Before returning, -.Fn fsync -unlocks -.Va fd . .Sh RETURN VALUES A 0 value is returned on success. A -1 value indicates an error. @@ -94,8 +72,8 @@ An I/O error occurred while reading from or writing to the file system. .El .Sh SEE ALSO .Xr sync 2 , -.Xr update 4 , -.Xr sync 8 +.Xr sync 8 , +.Xr update 8 .Sh HISTORY The .Nm diff --git a/lib/libc/sys/ftruncate.c b/lib/libc/sys/ftruncate.c index 72a6a9158153..2f3ae6d5a024 100644 --- a/lib/libc/sys/ftruncate.c +++ b/lib/libc/sys/ftruncate.c @@ -37,11 +37,6 @@ static char sccsid[] = "@(#)ftruncate.c 8.1 (Berkeley) 6/17/93"; #include <sys/types.h> #include <sys/syscall.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -53,16 +48,5 @@ ftruncate(fd, length) off_t length; { -#ifdef _THREAD_SAFE - int retval; - if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) { - retval = -1; - } else { - retval = __syscall((quad_t)SYS_ftruncate, fd, 0, length); - _thread_fd_unlock(fd, FD_RDWR); - } - return(retval); -#else return(__syscall((quad_t)SYS_ftruncate, fd, 0, length)); -#endif } diff --git a/lib/libc/sys/getdirentries.2 b/lib/libc/sys/getdirentries.2 index b0ecd92287c7..6df944420db6 100644 --- a/lib/libc/sys/getdirentries.2 +++ b/lib/libc/sys/getdirentries.2 @@ -120,28 +120,6 @@ The current position pointer should only be set to a value returned by a value returned in the location pointed to by .Fa basep , or zero. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn getdirentries -is implemented as the -.Va getdirentries -syscall. -.Pp -In the threaded library, the -.Va getdirentries -syscall is assembled to -.Fn _thread_sys_getdirentries -and -.Fn getdirentries -is implemented as a function which locks -.Va fd -for read and write, then calls -.Fn _thread_sys_getdirentries . -Before returning, -.Fn getdirentries -unlocks -.Va fd . .Sh RETURN VALUES If successful, the number of bytes actually transferred is returned. Otherwise, -1 is returned and the global variable @@ -151,16 +129,16 @@ is set to indicate the error. .Fn Getdirentries will fail if: .Bl -tag -width [EFAULT] -.It Bq Er EBADF +.It EBADF .Fa fd is not a valid file descriptor open for reading. -.It Bq Er EFAULT +.It EFAULT Either .Fa buf or .Fa basep point outside the allocated address space. -.It Bq Er EIO +.It EIO An .Tn I/O error occurred while reading from or writing to the file system. diff --git a/lib/libc/sys/getfh.2 b/lib/libc/sys/getfh.2 index e881066096b4..ab73d5a4b558 100644 --- a/lib/libc/sys/getfh.2 +++ b/lib/libc/sys/getfh.2 @@ -38,7 +38,7 @@ .Nm getfh .Nd get file handle .Sh SYNOPSIS -.Fd #include <sys/param.h> +.Fd #include <sys/types.h> .Fd #include <sys/mount.h> .Ft int .Fn getfh "char *path" "fhandle_t *fhp" diff --git a/lib/libc/sys/getgid.2 b/lib/libc/sys/getgid.2 index 574c15a11eb2..52519d767c68 100644 --- a/lib/libc/sys/getgid.2 +++ b/lib/libc/sys/getgid.2 @@ -70,7 +70,7 @@ indicate an error. .Sh SEE ALSO .Xr getuid 2 , .Xr setregid 2 , -.Xr setgid 2 +.Xr setgid 3 .Sh STANDARDS .Fn Getgid and diff --git a/lib/libc/sys/getlogin.2 b/lib/libc/sys/getlogin.2 index b0c6f1bb1483..5b351ca0fed2 100644 --- a/lib/libc/sys/getlogin.2 +++ b/lib/libc/sys/getlogin.2 @@ -66,50 +66,6 @@ This call is restricted to the super-user, and is normally used only when a new session is being created on behalf of the named user (for example, at login time, or when a remote shell is invoked). -.Pp -.Em NOTE: -There is only one `login name' per `session . -.Pp -It is -.Em CRITICALLY -important to ensure that -.Fn setlogin -is only ever called after the process has taken adequate steps to ensure -that it is detached from it's parent's session. -Making a -.Fn setsid -system call is the -.Em ONLY -way to do this. The -.Fn daemon -library call calls -.Fn setsid -which is an ideal way of detaching from a controlling terminal and -forking into the background. -.Pp -In particular, doing a -.Fn "ioctl" "ttyfd" "TIOCNOTTY" "..." -or -.Fn "setpgrp" "..." -is -.Em NOT -sufficient. -.Pp -Once a parent process does a -.Fn setsid -call, it is acceptable for some child of that process to then do a -.Fn setlogin -even though it is not the session leader, but beware that ALL processes -in the session will change their login name at the same time, even the -parent. -.Pp -This is not the same as the traditional UNIX behavior of inheriting privilege. -.Pp -Since the -.Fn setlogin -system call is restricted to the super-user, it is assumed that (like -all other privileged programs) the programmer has taken adequate -precautions to prevent security violations. .Sh RETURN VALUES If a call to .Fn getlogin @@ -145,8 +101,7 @@ characters, currently 12. The caller tried to set the login name and was not the super-user. .El .Sh SEE ALSO -.Xr setsid 2 , -.Xr daemon 3 +.Xr setsid 2 .Sh BUGS Login names are limited in length by .Fn setlogin . diff --git a/lib/libc/sys/getpeername.2 b/lib/libc/sys/getpeername.2 index 5ca0a443c326..d89488c3aaf9 100644 --- a/lib/libc/sys/getpeername.2 +++ b/lib/libc/sys/getpeername.2 @@ -53,28 +53,6 @@ the amount of space pointed to by On return it contains the actual size of the name returned (in bytes). The name is truncated if the buffer provided is too small. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn getpeername -is implemented as the -.Va getpeername -syscall. -.Pp -In the threaded library, the -.Va getpeername -syscall is assembled to -.Fn _thread_sys_getpeername -and -.Fn getpeername -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_getpeername . -Before returning, -.Fn getpeername -unlocks -.Va s . .Sh DIAGNOSTICS A 0 is returned if the call succeeds, -1 if it fails. .Sh ERRORS diff --git a/lib/libc/sys/getpid.2 b/lib/libc/sys/getpid.2 index 22f9257b5198..5f77706f30f9 100644 --- a/lib/libc/sys/getpid.2 +++ b/lib/libc/sys/getpid.2 @@ -63,7 +63,7 @@ and functions are always successful, and no return value is reserved to indicate an error. .Sh SEE ALSO -.Xr gethostid 3 +.Xr gethostid 2 .Sh STANDARDS .Fn Getpid and diff --git a/lib/libc/sys/getrlimit.2 b/lib/libc/sys/getrlimit.2 index 42b9028dada9..9aa3c8edac37 100644 --- a/lib/libc/sys/getrlimit.2 +++ b/lib/libc/sys/getrlimit.2 @@ -60,7 +60,7 @@ parameter is one of the following: .Bl -tag -width RLIMIT_FSIZEAA .It Li RLIMIT_CORE The largest size (in bytes) -.Xr core 5 +.Xr core file that may be created. .It Li RLIMIT_CPU The maximum amount of cpu time (in seconds) to be used by @@ -171,11 +171,19 @@ raised the maximum limit value, and the caller is not the super-user. .El .Sh SEE ALSO .Xr csh 1 , -.Xr quota 1 , -.Xr quotactl 2 , +.Xr quota 2 , .Xr sigaltstack 2 , .Xr sigvec 2 , .Xr sysctl 3 +.Sh BUGS +There should be +.Ic limit +and +.Ic unlimit +commands in +.Xr sh 1 +as well as in +.Xr csh . .Sh HISTORY The .Nm diff --git a/lib/libc/sys/getsockname.2 b/lib/libc/sys/getsockname.2 index e053b4768e7b..d56e40486646 100644 --- a/lib/libc/sys/getsockname.2 +++ b/lib/libc/sys/getsockname.2 @@ -51,28 +51,6 @@ the amount of space pointed to by .Fa name . On return it contains the actual size of the name returned (in bytes). -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn getsockname -is implemented as the -.Va getsockname -syscall. -.Pp -In the threaded library, the -.Va getsockname -syscall is assembled to -.Fn _thread_sys_getsockname -and -.Fn getsockname -is implemented as a function which locks -.Va fd -for read and write, then calls -.Fn _thread_sys_getsockname . -Before returning, -.Fn getsockname -unlocks -.Va fd . .Sh DIAGNOSTICS A 0 is returned if the call succeeds, -1 if it fails. .Sh ERRORS diff --git a/lib/libc/sys/getsockopt.2 b/lib/libc/sys/getsockopt.2 index 5adfdec61c33..46d3d8a53fc9 100644 --- a/lib/libc/sys/getsockopt.2 +++ b/lib/libc/sys/getsockopt.2 @@ -29,10 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94 -.\" $Id$ +.\" @(#)getsockopt.2 8.3 (Berkeley) 4/19/94 .\" -.Dd November 3, 1995 +.Dd April 19, 1994 .Dt GETSOCKOPT 2 .Os BSD 4.3r .Sh NAME @@ -190,7 +189,7 @@ is performed. If the socket promises reliable delivery of data and .Dv SO_LINGER is set, the system will block the process on the -.Xr close 2 +.Xr close attempt until it is able to transmit the data or until it decides it is unable to deliver the information (a timeout period, termed the linger interval, is specified in the @@ -201,7 +200,7 @@ is requested). If .Dv SO_LINGER is disabled and a -.Xr close 2 +.Xr close is issued, the system will process the close in a manner that allows the process to continue as quickly as possible. .Pp @@ -215,9 +214,9 @@ With protocols that support out-of-band data, the option requests that out-of-band data be placed in the normal data input queue as received; it will then be accessible with -.Xr recv 2 +.Xr recv or -.Xr read 2 +.Xr read calls without the .Dv MSG_OOB flag. @@ -229,11 +228,7 @@ are options to adjust the normal buffer sizes allocated for output and input buffers, respectively. The buffer size may be increased for high-volume connections, or may be decreased to limit the possible backlog of incoming data. -The system places an absolute maximum on these values, which is accessible -through the -.Xr sysctl 3 -MIB variable -.Dq Li kern.maxsockbuf . +The system places an absolute limit on these values. .Pp .Dv SO_SNDLOWAT is an option to set the minimum count for output operations. @@ -266,7 +261,7 @@ wait until they have received the smaller of the low water mark value or the requested amount. Receive calls may still return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue -is different from that which was returned. +is different than that returned. .Pp .Dv SO_SNDTIMEO is an option to set a timeout value for output operations. @@ -313,49 +308,6 @@ returns any pending error on the socket and clears the error status. It may be used to check for asynchronous errors on connected datagram sockets or for other asynchronous errors. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn getsockopt -is implemented as the -.Va getsockopt -syscall. -.Pp -In the threaded library, the -.Va getsockopt -syscall is assembled to -.Fn _thread_sys_getsockopt -and -.Fn getsockopt -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_getsockopt . -Before returning, -.Fn getsockopt -unlocks -.Va s . -.Pp -In the non-threaded library -.Fn setsockopt -is implemented as the -.Va setsockopt -syscall. -.Pp -In the threaded library, the -.Va setsockopt -syscall is assembled to -.Fn _thread_sys_setsockopt -and -.Fn setsockopt -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_setsockopt . -Before returning, -.Fn setsockopt -unlocks -.Va s . .Sh RETURN VALUES A 0 is returned if the call succeeds, -1 if it fails. .Sh ERRORS @@ -384,10 +336,8 @@ is not in a valid part of the process address space. .Sh SEE ALSO .Xr ioctl 2 , .Xr socket 2 , -.Xr getprotoent 3 , -.Xr sysctl 3 , -.Xr protocols 5 , -.Xr sysctl 8 +.Xr getprotoent 3 +.Xr protocols 5 .Sh BUGS Several of the socket options should be handled at lower levels of the system. .Sh HISTORY diff --git a/lib/libc/sys/intro.2 b/lib/libc/sys/intro.2 index 79aad8a8a6b6..bf4380917e39 100644 --- a/lib/libc/sys/intro.2 +++ b/lib/libc/sys/intro.2 @@ -47,49 +47,13 @@ their error returns, and other common definitions and concepts. .\".Pp .\"<more later...> .Sh DIAGNOSTICS -Nearly all of the system calls provide an error number referenced via -the external identifier errno. This identifier is defined in -.Aq Pa sys/errno.h -for non-threaded programs as: +Nearly all of the system calls provide an error number in the external +variable +.Va errno , +which is defined as: .Pp .Dl extern int errno .Pp -and for threaded programs as: -.Pp -.Dl extern int * __error(); -.Dl #define errno (* __error()) -.Pp -A threaded program must be compiled with -.Va _THREAD_SAFE -defined so that the preprocessor will output the appropriate errno -definition to the compiler. Failure to do so will mean that error -variables will not be thread specific. -.Pp -The threaded library implementation of -.Va __error() -returns a pointer to a field in the thread specific structure for -threads other than the initial thread. For the initial thread, -.Va __error() -returns a pointer to a global -.Va errno -variable that is compatible with that used by non-threaded programs. -This allows the initial thread to call functions in libraries which have -not been compiled with -.Va _THREAD_SAFE . -Programmers should ensure that threads other than the initial thread only -call functions in libraries that have been compiled with -.Va _THREAD_SAFE . -.Pp -Programmers should include -.Aq Pa sys/errno.h to obtain the definition of -.Va errno -rather than coding the definition as an external reference directly. It is -planned that the -.Va extern int errno -definition will eventually be replaced by the threaded definition so that -all libraries will have a thread-aware treatment of -.Va errno . -.Pp When a system call detects an error, it returns an integer value indicating failure (usually -1) @@ -159,9 +123,9 @@ or a read (write) request was made to a file that was only open for writing (reading). .It Er 10 ECHILD Em "\&No child processes" . A -.Xr wait 2 +.Xr wait or -.Xr waitpid 2 +.Xr waitpid function was executed by a process that had no existing or unwaited-for child processes. .It Er 11 EDEADLK Em "Resource deadlock avoided" . @@ -187,7 +151,7 @@ in a manner which would have conflicted with the request. .It Er 17 EEXIST Em "File exists" . An existing file was mentioned in an inappropriate context, for instance, as the new link name in a -.Xr link 2 +.Xr link function. .It Er 18 EXDEV Em "Improper link" . A hard link to a file on another file system @@ -205,9 +169,9 @@ An attempt was made to open a directory with write mode specified. .It Er 22 EINVAL Em "Invalid argument" . Some invalid argument was supplied. (For example, specifying an undefined signal to a -.Xr signal 3 +.Xr signal or -.Xr kill 2 +.Xr kill function). .It Er 23 ENFILE Em "Too many open files in system" . Maximum number of file descriptors allowable on the system @@ -227,7 +191,7 @@ special device for which the operation was inappropriate. The new process was a pure procedure (shared text) file which was open for writing by another process, or while the pure procedure file was being executed an -.Xr open 2 +.Xr open call requested write access. .It Er 27 EFBIG Em "File too large" . The size of a file exceeded the maximum (about @@ -236,7 +200,7 @@ The size of a file exceeded the maximum (about bytes). .It Er 28 ENOSPC Em "Device out of space" . A -.Xr write 2 +.Xr write to an ordinary file, the creation of a directory or symbolic link, or the creation of a directory entry failed because no more disk blocks were available @@ -245,7 +209,7 @@ created file failed because no more inodes were available on the file system. .It Er 29 ESPIPE Em "Illegal seek" . An -.Xr lseek 2 +.Xr lseek function was issued on a socket, pipe or .Tn FIFO . .It Er 30 EROFS Em "Read-only file system" . @@ -344,12 +308,12 @@ An operation on a socket or pipe was not performed because the system lacked sufficient buffer space or because a queue was full. .It Er 56 EISCONN Em "Socket is already connected" . A -.Xr connect 2 +.Xr connect request was made on an already connected socket; or, a -.Xr sendto 2 +.Xr sendto or -.Xr sendmsg 2 +.Xr sendmsg request on a connected socket specified a destination when already connected. .It Er 57 ENOTCONN Em "Socket is not connected" . @@ -363,9 +327,9 @@ had already been shut down with a previous call. .It Er 60 ETIMEDOUT Em "Operation timed out" . A -.Xr connect 2 +.Xr connect or -.Xr send 2 +.Xr send request failed because the connected party did not properly respond after a period of time. (The timeout period is dependent on the communication protocol.) @@ -397,7 +361,7 @@ was supplied to a remove directory or rename call. The quota system ran out of table entries. .It Er 69 EDQUOT Em "Disc quota exceeded" . A -.Xr write 2 +.Xr write to an ordinary file, the creation of a directory or symbolic link, or the creation of a directory entry failed because the user's quota of disk blocks was @@ -450,7 +414,7 @@ A new process is created by a currently active process; (see The parent process ID of a process is initially the process ID of its creator. If the creating process exits, the parent process ID of each child is set to the ID of a system process, -.Xr init 8 . +.Xr init . .It Process Group Each active process is a member of a process group that is identified by a non-negative integer called the process group ID. This is the process @@ -497,7 +461,7 @@ as the group, but is in a different process group. Note that when a process exits, the parent process for its children is changed to be -.Nm init , +.Xr init , which is in a separate session. Not all members of an orphaned process group are necessarily orphaned processes (those whose creating process has exited). @@ -701,5 +665,4 @@ of a certain format. An Address Family is the set of addresses for a specific group of protocols. Each socket has an address chosen from the address family in which the socket was created. .Sh SEE ALSO -.Xr intro 3 , -.Xr perror 3 +intro(3), perror(3) diff --git a/lib/libc/sys/ioctl.2 b/lib/libc/sys/ioctl.2 index 38c58b9dcf59..36ce6ff47f65 100644 --- a/lib/libc/sys/ioctl.2 +++ b/lib/libc/sys/ioctl.2 @@ -68,28 +68,6 @@ Macros and defines used in specifying an ioctl .Fa request are located in the file .Ao Pa sys/ioctl.h Ac . -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn ioctl -is implemented as the -.Va ioctl -syscall. -.Pp -In the threaded library, the -.Va ioctl -syscall is assembled to -.Fn _thread_sys_ioctl -and -.Fn ioctl -is implemented as a function which locks -.Va d -for read and write, then calls -.Fn _thread_sys_ioctl . -Before returning, -.Fn ioctl -unlocks -.Va d . .Sh RETURN VALUES If an error has occurred, a value of -1 is returned and .Va errno diff --git a/lib/libc/sys/ktrace.2 b/lib/libc/sys/ktrace.2 index fd4515fc6082..9fe61f89570f 100644 --- a/lib/libc/sys/ktrace.2 +++ b/lib/libc/sys/ktrace.2 @@ -38,9 +38,7 @@ .Nm ktrace .Nd process tracing .Sh SYNOPSIS -.Fd #include <sys/param.h> -.Fd #include <sys/time.h> -.Fd #include <sys/uio.h> +.Fd #include <sys/types.h> .Fd #include <sys/ktrace.h> .Ft int .Fn ktrace "const char *tracefile" "int ops" "int trpoints" "int pid" diff --git a/lib/libc/sys/link.2 b/lib/libc/sys/link.2 index 4c27ab9765ac..d1607862d2c5 100644 --- a/lib/libc/sys/link.2 +++ b/lib/libc/sys/link.2 @@ -74,6 +74,7 @@ both and .Fa name2 must be in the same file system. +Unless the caller is the super-user, .Fa name1 may not be a directory. .Sh RETURN VALUES @@ -112,7 +113,8 @@ does exist. .It Bq Er EPERM The file named by .Fa name1 -is a directory. +is a directory and the effective +user ID is not super-user. .It Bq Er EXDEV The link named by .Fa name2 @@ -147,10 +149,3 @@ is outside the process's allocated address space. is expected to conform to IEEE Std 1003.1-1988 .Pq Dq Tn POSIX . -.Sh HISTORY -.Pp -The -.Nm -system call traditionally allows the super-user to link directories which -corrupts the filesystem coherency. This implementation no longer permits -it. diff --git a/lib/libc/sys/listen.2 b/lib/libc/sys/listen.2 index b3271dd2d62c..0ab28bc2bd59 100644 --- a/lib/libc/sys/listen.2 +++ b/lib/libc/sys/listen.2 @@ -29,10 +29,9 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.\" From: @(#)listen.2 8.2 (Berkeley) 12/11/93 -.\" $Id$ +.\" @(#)listen.2 8.2 (Berkeley) 12/11/93 .\" -.Dd November 3, 1995 +.Dd December 11, 1993 .Dt LISTEN 2 .Os BSD 4.2 .Sh NAME @@ -69,41 +68,6 @@ receive an error with an indication of .Er ECONNREFUSED , or, if the underlying protocol supports retransmission, the request may be ignored so that retries may succeed. -.Pp -The -.Xr sysctl 3 -MIB variable -.Dq Li kern.somaxconn -specifies a hard limit on -.Fa backlog ; -if a value greater than -.Li kern.somaxconn -or less than zero is specified, -.Fa backlog -is silently forced to -.Li kern.somaxconn . -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn listen -is implemented as the -.Va listen -syscall. -.Pp -In the threaded library, the -.Va listen -syscall is assembled to -.Fn _thread_sys_listen -and -.Fn listen -is implemented as a function which locks -.Va s -for read and write, then calls -.Fn _thread_sys_listen . -Before returning, -.Fn listen -unlocks -.Va s . .Sh RETURN VALUES A 0 return value indicates success; -1 indicates an error. .Sh ERRORS @@ -125,17 +89,13 @@ The socket is not of a type that supports the operation .Sh SEE ALSO .Xr accept 2 , .Xr connect 2 , -.Xr socket 2 , -.Xr sysctl 3 , -.Xr sysctl 8 +.Xr socket 2 +.Sh BUGS +The +.Fa backlog +is currently limited (silently) to 32. .Sh HISTORY The .Nm function call appeared in .Bx 4.2 . -The ability to configure the maximum -.Fa backlog -at run-time, and to use a negative -.Fa backlog -to request the maximum allowable value, was introduced in -.Fx 2.2 . diff --git a/lib/libc/sys/lseek.c b/lib/libc/sys/lseek.c index 8896ad8d3567..52208d137a93 100644 --- a/lib/libc/sys/lseek.c +++ b/lib/libc/sys/lseek.c @@ -37,11 +37,6 @@ static char sccsid[] = "@(#)lseek.c 8.1 (Berkeley) 6/17/93"; #include <sys/types.h> #include <sys/syscall.h> -#include <unistd.h> -#ifdef _THREAD_SAFE -#include <pthread.h> -#include "pthread_private.h" -#endif /* * This function provides 64-bit offset padding that @@ -53,17 +48,7 @@ lseek(fd, offset, whence) off_t offset; int whence; { -#ifdef _THREAD_SAFE - off_t offs; - if (_thread_fd_lock(fd, FD_RDWR, NULL,__FILE__,__LINE__) != 0) { - offs = -1; - } else { - offs = __syscall((quad_t) SYS_lseek,fd, 0, offset, whence); - _thread_fd_unlock(fd, FD_RDWR); - } - return(offs); + extern off_t __syscall(); -#else return(__syscall((quad_t)SYS_lseek, fd, 0, offset, whence)); -#endif } diff --git a/lib/libc/sys/madvise.2 b/lib/libc/sys/madvise.2 index 4326389b1eb1..d0676ab18fce 100644 --- a/lib/libc/sys/madvise.2 +++ b/lib/libc/sys/madvise.2 @@ -38,9 +38,7 @@ .Nm madvise .Nd give advise about use of memory .Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/mman.h> -.Fn madvise "caddr_t addr" "size_t len" "int behav" +.Fn madvise "caddr_t addr" "int len" "int behav" .Sh DESCRIPTION The .Fn madvise @@ -61,12 +59,7 @@ The known behaviors are given in .Xr msync 2 , .Xr munmap 2 , .Xr mprotect 2 , -.Xr mincore 2 . - -.Sh BUGS -.Nm madvise -is not yet implemented. - +.Xr mincore 2 .Sh HISTORY The .Nm madvise diff --git a/lib/libc/sys/mincore.2 b/lib/libc/sys/mincore.2 index a51fcc9fc464..4e73c2ab90f8 100644 --- a/lib/libc/sys/mincore.2 +++ b/lib/libc/sys/mincore.2 @@ -38,9 +38,7 @@ .Nm mincore .Nd get advise about use of memory .Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/mman.h> -.Fn mincore "caddr_t addr" "size_t len" "char *vec" +.Fn mincore "caddr_t addr" "int len" "char *vec" .Sh DESCRIPTION The .Fn mincore diff --git a/lib/libc/sys/mmap.2 b/lib/libc/sys/mmap.2 index 2b87189dc723..1c0d84a85d0c 100644 --- a/lib/libc/sys/mmap.2 +++ b/lib/libc/sys/mmap.2 @@ -124,7 +124,7 @@ Notify the kernel that the region may contain semaphores and that special handling may be necessary. .It Dv MAP_INHERIT Permit regions to be inherited across -.Xr execve 2 +.Xr exec 2 system calls. .It Dv MAP_PRIVATE Modifications are private. @@ -202,27 +202,9 @@ parameter wasn't available. .Dv MAP_ANON was specified and insufficient memory was available. .Sh "SEE ALSO" +.Xr getpagesize 2 , .Xr msync 2 , .Xr munmap 2 , .Xr mprotect 2 , .Xr madvise 2 , -.Xr mincore 2 , -.Xr mlock 2 , -.Xr munlock 2 , -.Xr getpagesize 3 - -.Sh BUGS -.Ar len -is limit to 2GB. Mmapping slightly more than 2GB doesn't work, but -mapping a window of size (filesize % 2GB) for file sizes of slightly -less than 2G, 4GB, 6GB and 8GB. - -The limit is imposed for a variety of reasons. Most of them have to do -with FreeBSD not wanting to use 64 bit offsets in the VM system due to -the extreme performance penalty. So FreeBSD use 32bit page indexes and -this gives FreeBSD a maximum of 8TB filesizes. It's actually bugs in -the filesystem code that causes the limit to be further restricted to -1TB (loss of precision when doing blockno calculations). - -Another reason for the 2GB limit is that filesystem metadata can -reside at negative offsets. +.Xr mincore 2 diff --git a/lib/libc/sys/mprotect.2 b/lib/libc/sys/mprotect.2 index 4ddd65d5e8ac..bb2b9ad21e44 100644 --- a/lib/libc/sys/mprotect.2 +++ b/lib/libc/sys/mprotect.2 @@ -38,9 +38,7 @@ .Nm mprotect .Nd control the protection of pages .Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/mman.h> -.Fn mprotect "caddr_t addr" "size_t len" "int prot" +.Fn mprotect "caddr_t addr" "int len" "int prot" .Sh DESCRIPTION The .Fn mprotect diff --git a/lib/libc/sys/msync.2 b/lib/libc/sys/msync.2 index 409dd08b35a2..d976e304599e 100644 --- a/lib/libc/sys/msync.2 +++ b/lib/libc/sys/msync.2 @@ -38,9 +38,7 @@ .Nm msync .Nd synchronize a mapped region .Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/mman.h> -.Fn msync "caddr_t addr" "size_t len" "int flags" +.Fn msync "caddr_t addr" "int len" "int flags" .Sh DESCRIPTION The .Fn msync diff --git a/lib/libc/sys/munmap.2 b/lib/libc/sys/munmap.2 index 5d14016e887d..b9e8a1b0841c 100644 --- a/lib/libc/sys/munmap.2 +++ b/lib/libc/sys/munmap.2 @@ -38,8 +38,6 @@ .Nm munmap .Nd remove a mapping .Sh SYNOPSIS -.Fd #include <sys/types.h> -.Fd #include <sys/mman.h> .Fn munmap "caddr_t addr" "size_t len" .Sh DESCRIPTION The @@ -68,12 +66,12 @@ parameter was negative, or some part of the region being unmapped is not part of the currently valid address space. .Sh "SEE ALSO" +.Xr getpagesize 2 , .Xr msync 2 , .Xr munmap 2 , .Xr mprotect 2 , .Xr madvise 2 , -.Xr mincore 2 , -.Xr getpagesize 3 +.Xr mincore 2 .Sh HISTORY The .Fn munmap diff --git a/lib/libc/sys/open.2 b/lib/libc/sys/open.2 index bb7526250cb4..dea59fcce346 100644 --- a/lib/libc/sys/open.2 +++ b/lib/libc/sys/open.2 @@ -136,7 +136,7 @@ When a new file is created it is given the group of the directory which contains it. .Pp The new descriptor is set to remain open across -.Xr execve 2 +.Xr execve system calls; see .Xr close 2 and @@ -146,26 +146,6 @@ The system imposes a limit on the number of file descriptors open simultaneously by one process. .Xr Getdtablesize 2 returns the current system limit. -.Pp -.Sh IMPLEMENTATION NOTES -In the non-threaded library -.Fn open -is implemented as the -.Va open -syscall. -.Pp -In the threaded library, the -.Va open -syscall is assembled to -.Fn _thread_sys_open -and -.Fn open -is implemented as a function which disables thread rescheduling -and calls -.Fn _thread_sys_open . -Before returning, -.Fn open -enables thread rescheduling. .Sh ERRORS The named file is opened unless: .Bl -tag -width Er diff --git a/lib/libc/sys/pipe.2 b/lib/libc/sys/pipe.2 index 763cc2fc7dfa..51b7364bf86c 100644 --- a/lib/libc/sys/pipe.2 +++ b/lib/libc/sys/pipe.2 @@ -48,13 +48,12 @@ function creates a .Em pipe , which is an object allowing -bidirectional data flow, +unidirectional data flow, and allocates a pair of file descriptors. -.Pp -By convention, the first descriptor is normally used as the +The first descriptor connects to the .Em read end of the pipe, -and the second is normally the +and the second connects to the .Em write end , so that data written to .Fa fildes[1] @@ -70,7 +69,7 @@ the read end of the pipe. The pipe itself persists until all its associated descriptors are closed. .Pp -A pipe that has had an end closed is considered +A pipe whose read or write end has been closed is considered .Em widowed . Writing on such a pipe causes the writing process to receive a @@ -80,10 +79,9 @@ Widowing a pipe is the only way to deliver end-of-file to a reader: after the reader consumes any buffered data, reading a widowed pipe returns a zero count. .Pp -The bidirectional nature of this implementation of pipes is not -portable to older systems, so it is recommended to use the convention -for using the endpoints in the traditional manner when using a -pipe in one direction. +Pipes are really a special case of the +.Xr socketpair 2 +call and, in fact, are implemented as such in the system. .Sh RETURN VALUES On successful creation of the pipe, zero is returned. Otherwise, a value of -1 is returned and the variable @@ -115,5 +113,3 @@ space. A .Nm function call appeared in Version 6 AT&T UNIX. -.Pp -Bidirectional pipes were first used on Unix System V release 4. diff --git a/lib/libc/sys/ptrace.2 b/lib/libc/sys/ptrace.2 index dc66d1d77d44..f9cf5d106206 100644 --- a/lib/libc/sys/ptrace.2 +++ b/lib/libc/sys/ptrace.2 @@ -75,7 +75,7 @@ and data, which is why there are two requests: conceptually, .Dv PT_READ_I reads from the instruction space and .Dv PT_READ_D -reads from the data space. In the current FreeBSD implementation, these +reads from the data space. In the current NetBSD implementation, these two requests are completely identical. The .Fa addr argument specifies the address (in the traced process' virtual address @@ -145,61 +145,6 @@ The traced process terminates, as if had been used with .Dv SIGKILL given as the signal to be delivered. -.It Dv PT_ATTACH -This request allows a process to gain control of an otherwise unrelated -process and begin tracing it. It does not need any cooperation from -the to-be-traced process. In this case, -.Fa pid -specifies the process ID of the to-be-traced process, and the other two -arguments are ignored. This request requires that the target process -must have the same real UID as the tracing process, and that it must -not be executing a setuid or setgid executable. (If the tracing -process is running as root, these restrictions do not apply.) The -tracing process will see the newly-traced process stop and may then -control it as if it had been traced all along. -.It Dv PT_DETACH -This request is like PT_CONTINUE, except that it does not allow -specifying an alternate place to continue execution, and after it -succeeds, the traced process is no longer traced and continues -execution normally. -.El -.Pp -Additionally, machine-specific requests can exist. On the i386, these -are: -.Bl -tag -width 12n -.It Dv PT_GETREGS -This request reads the traced process' machine registers into the -.Dq Li "struct reg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_SETREGS -This request is the converse of -.Dv PT_GETREGS ; -it loads the traced process' machine registers from the -.Dq Li "struct reg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_GETFPREGS -This request reads the traced process' floating-point registers into -the -.Dq Li "struct fpreg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . -.It Dv PT_SETFPREGS -This request is the converse of -.Dv PT_GETFPREGS ; -it loads the traced process' floating-point registers from the -.Dq Li "struct fpreg" -(defined in -.Aq Pa machine/reg.h ) -pointed to by -.Fa addr . .El .Sh ERRORS Some requests can cause @@ -219,10 +164,6 @@ No process having the specified process ID exists. .It Bq Er EINVAL .Bl -bullet -compact .It -A process attempted to use -.Dv PT_ATTACH -on itself. -.It The .Fa request was not one of the legal requests. @@ -241,40 +182,12 @@ The signal number (in to .Dv PT_CONTINUE was neither 0 nor a legal signal number. -.It -.Dv PT_GETREGS , -.Dv PT_SETREGS , -.Dv PT_GETFPREGS , -or -.Dv PT_SETFPREGS -was attempted on a process with no valid register set. (This is -normally true only of system processes.) -.El -.It Bq Er EBUSY -.Bl -bullet -compact -.It -.Dv PT_ATTACH -was attempted on a process that was already being traced. -.It -A request attempted to manipulate a process that was being traced by -some process other than the one making the request. -.It -A request (other than -.Dv PT_ATTACH ) -specified a process that wasn't stopped. .El .It Bq Er EPERM .Bl -bullet -compact .It -A request (other than -.Dv PT_ATTACH ) +A request attempted to manipulate a process that wasn't being traced at all. -.It -An attempt was made to use -.Dv PT_ATTACH -on a process in violation of the requirements listed under -.Dv PT_ATTACH -above. .El .Sh SEE ALSO .Xr sigaction 2 diff --git a/lib/libc/sys/quotactl.2 b/lib/libc/sys/quotactl.2 index f40a0dee2d0b..047d070d2be3 100644 --- a/lib/libc/sys/quotactl.2 +++ b/lib/libc/sys/quotactl.2 @@ -41,7 +41,7 @@ .Nm quotactl .Nd manipulate filesystem quotas .Sh SYNOPSIS -.Fd #include <ufs/ufs/quota.h> /* for ufs quotas */ +.Ft #include <ufs/ufs/quota.h> /* for ufs quotas */ .Ft int .Fn quotactl "const char *path" "int cmd" "int id" "char *addr" .Sh DESCRIPTION diff --git a/lib/libc/sys/read.2 b/lib/libc/sys/read.2 index ea428fd47a12..b94341a043c0 100644 --- a/lib/libc/sys/read.2 +++ b/lib/libc/sys/read.2 @@ -107,53 +107,6 @@ The system guarantees to read the number of bytes requested if the descriptor references a normal file that has that many bytes left before the end-of-file, but in no other case. .Pp -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn read -is implemented as the -.Va read -syscall. -.Pp -In the threaded library, the -.Va read -syscall is assembled to -.Fn _thread_sys_read -and -.Fn read -is implemented as a function which locks -.Va d -for read, then calls -.Fn _thread_sys_read . -If the call to -.Fn _thread_sys_read -would block, a context switch is performed. Before returning, -.Fn read -unlocks -.Va d . -.Pp -In the non-threaded library -.Fn readv -is implemented as the -.Va readv -syscall. -.Pp -In the threaded library, the -.Va readv -syscall is assembled to -.Fn _thread_sys_readv -and -.Fn readv -is implemented as a function which locks -.Va d -for read, then calls -.Fn _thread_sys_readv . -If the call to -.Fn _thread_sys_readv -would block, a context switch is performed. Before returning, -.Fn readv -unlocks -.Va d . .Sh RETURN VALUES If successful, the number of bytes actually read is returned. Upon reading end-of-file, diff --git a/lib/libc/sys/reboot.2 b/lib/libc/sys/reboot.2 index ad66ee5646db..0db9ea2349cb 100644 --- a/lib/libc/sys/reboot.2 +++ b/lib/libc/sys/reboot.2 @@ -140,6 +140,7 @@ variable The caller is not the super-user. .El .Sh SEE ALSO +.Xr kadb 4 , .Xr crash 8 , .Xr halt 8 , .Xr init 8 , diff --git a/lib/libc/sys/rtprio.2 b/lib/libc/sys/rtprio.2 index 1fd18ee5f05d..8b74272999e1 100644 --- a/lib/libc/sys/rtprio.2 +++ b/lib/libc/sys/rtprio.2 @@ -35,10 +35,10 @@ .Nm rtprio .Nd examine or modify a process realtime or idle priority .Sh SYNOPSIS -.Fd #include <sys/types.h> +.Fd #include <sys/resource.h> .Fd #include <sys/rtprio.h> .Ft int -.Fn rtprio "int function" "pid_t pid" "struct rtprio *rtp" +.Fn rtprio "function" "pid_t pid" "struct rtprio *rtp" .Sh DESCRIPTION .Fn rtprio is used to lookup or change the realtime or idle priority of a process. @@ -101,6 +101,6 @@ implementation in FreeBSD was substantially rewritten by David Greenman. .Xr rtprio 1 , .Xr nice 1 , .Xr ps 1 , -.Xr setpriority 2 , -.Xr nice 3 , +.Xr nice 2 , .Xr renice 8 + diff --git a/lib/libc/sys/setsid.2 b/lib/libc/sys/setsid.2 index 404b1b81a008..48ac6a071785 100644 --- a/lib/libc/sys/setsid.2 +++ b/lib/libc/sys/setsid.2 @@ -68,7 +68,7 @@ group ID of a process other than the calling process matches the process ID of the calling process. .El .Sh SEE ALSO -.Xr setpgid 2 , +.Xr setpgid 3 , .Xr tcgetpgrp 3 , .Xr tcsetpgrp 3 .Sh STANDARDS diff --git a/lib/libc/sys/sigaction.2 b/lib/libc/sys/sigaction.2 index b9fe5caca506..3f41266a9c81 100644 --- a/lib/libc/sys/sigaction.2 +++ b/lib/libc/sys/sigaction.2 @@ -50,7 +50,7 @@ struct sigaction { .Sh DESCRIPTION The system defines a set of signals that may be delivered to a process. Signal delivery resembles the occurrence of a hardware interrupt: -the signal is normally blocked from further occurrence, the current process +the signal is blocked from further occurrence, the current process context is saved, and a new one is built. A process may specify a .Em handler to which a signal is delivered, or specify that a signal is to be @@ -68,7 +68,7 @@ of the process. This may be changed, on a per-handler basis, so that signals are taken on a special .Em "signal stack" . .Pp -Signal routines normally execute with the signal that caused their +Signal routines execute with the signal that caused their invocation .Em blocked , but other signals may yet occur. @@ -131,7 +131,7 @@ If is non-zero, the previous handling information for the signal is returned to the user. .Pp -Once a signal handler is installed, it normally remains installed +Once a signal handler is installed, it remains installed until another .Fn sigaction call is made, or an @@ -178,16 +178,7 @@ bit is set in the system will deliver the signal to the process on a .Em "signal stack" , specified with -.Xr sigaltstack 2 . -If the -.Dv SA_NODEFER -bit is set, further occurrences of the delivered signal are not -masked during the execution of the handler. -If the -.Dv SA_RESETHAND -bit is set, the handler is reset back to -.Dv SIG_DFL -at the moment the signal is delivered. +.Xr sigstack 2 . .Pp If a signal is caught during the system calls listed below, the call may be forced to terminate @@ -243,7 +234,7 @@ with names as in the include file .It Dv SIGQUIT No " create core image" " quit program" .It Dv SIGILL No " create core image" " illegal instruction" .It Dv SIGTRAP No " create core image" " trace trap" -.It Dv SIGABRT No " create core image" Xr abort 3 +.It Dv SIGABRT No " create core image" Xr abort 2 call (formerly .Dv SIGIOT ) .It Dv SIGEMT No " create core image" " emulate instruction executed" @@ -251,7 +242,7 @@ call (formerly .It Dv SIGKILL No " terminate process" " kill program" .It Dv SIGBUS No " create core image" " bus error" .It Dv SIGSEGV No " create core image" " segmentation violation" -.It Dv SIGSYS No " create core image" " non-existent system call invoked" +.It Dv SIGSYS No " create core image" " system call given invalid argument" .It Dv SIGPIPE No " terminate process" " write on a pipe with no reader" .It Dv SIGALRM No " terminate process" " real-time timer expired" .It Dv SIGTERM No " terminate process" " software termination signal" @@ -361,11 +352,6 @@ and Those signals are available on most .Tn BSD Ns \-derived systems. -The -.Dv SA_NODEFER -and -.Dv SA_RESETHAND -are intended for backwards compatability with other operating systems. .Sh SEE ALSO .Xr kill 1 , .Xr ptrace 2 , @@ -376,7 +362,7 @@ are intended for backwards compatability with other operating systems. .Xr sigblock 2 , .Xr sigsetmask 2 , .Xr sigpause 2 , -.Xr sigaltstack 2 , +.Xr sigstack 2 , .Xr sigvec 2 , .Xr setjmp 3 , .Xr siginterrupt 3 , diff --git a/lib/libc/sys/sigaltstack.2 b/lib/libc/sys/sigaltstack.2 index 4892a923fcbd..f1ed718eb966 100644 --- a/lib/libc/sys/sigaltstack.2 +++ b/lib/libc/sys/sigaltstack.2 @@ -71,7 +71,7 @@ the system arranges a switch to the signal stack for the duration of the signal handler's execution. .Pp If -.Dv SS_DISABLE +.Dv SA_DISABLE is set in .Fa ss_flags , .Fa ss_sp @@ -95,9 +95,9 @@ is non-zero, the current signal stack state is returned. The .Fa ss_flags field will contain the value -.Dv SS_ONSTACK +.Dv SA_ONSTACK if the process is currently on a signal stack and -.Dv SS_DISABLE +.Dv SA_DISABLE if the signal stack is currently disabled. .Sh NOTES The value diff --git a/lib/libc/sys/stat.2 b/lib/libc/sys/stat.2 index 51a5b2e5ff4b..27bc183ddeb0 100644 --- a/lib/libc/sys/stat.2 +++ b/lib/libc/sys/stat.2 @@ -256,7 +256,7 @@ depend on the time stamps being contiguous (in calls to .Xr symlink 7 .Sh BUGS Applying -.Fn fstat +.Xr fstat to a socket (and thus to a pipe) returns a zeroed buffer, except for the blocksize field, diff --git a/lib/libc/sys/sync.2 b/lib/libc/sys/sync.2 index 6309c18c7261..5e79feff2d28 100644 --- a/lib/libc/sys/sync.2 +++ b/lib/libc/sys/sync.2 @@ -53,7 +53,7 @@ As information in the cache is lost after a system crash a call is issued frequently by the user process -.Xr update 4 +.Xr update 8 (about every 30 seconds). .Pp The function @@ -62,8 +62,8 @@ may be used to synchronize individual file descriptor attributes. .Sh SEE ALSO .Xr fsync 2 , -.Xr update 4 , -.Xr sync 8 +.Xr sync 8 , +.Xr update 8 .Sh BUGS .Fn Sync may return before the buffers are completely flushed. diff --git a/lib/libc/sys/unlink.2 b/lib/libc/sys/unlink.2 index 1f469453d5ad..78221bc505fc 100644 --- a/lib/libc/sys/unlink.2 +++ b/lib/libc/sys/unlink.2 @@ -56,8 +56,6 @@ all resources associated with the file are reclaimed. If one or more process have the file open when the last link is removed, the link is removed, but the removal of the file is delayed until all references to it have been closed. -.Fa path -may not be a directory. .Sh RETURN VALUES Upon successful completion, a value of 0 is returned. Otherwise, a value of -1 is returned and @@ -85,7 +83,8 @@ to be removed. .It Bq Er ELOOP Too many symbolic links were encountered in translating the pathname. .It Bq Er EPERM -The named file is a directory. +The named file is a directory and the effective user ID +of the process is not the super-user. .It Bq Er EPERM The directory containing the file is marked sticky, and neither the containing directory nor the file to be removed @@ -111,9 +110,3 @@ points outside the process's allocated address space. An .Nm function call appeared in Version 6 AT&T UNIX. -.Pp -The -.Nm -system call traditionally allows the super-user to unlink directories which -can damage the filesystem integrity. This implementation no longer permits -it. diff --git a/lib/libc/sys/utimes.2 b/lib/libc/sys/utimes.2 index 125b6193c637..1ebeb37eecd9 100644 --- a/lib/libc/sys/utimes.2 +++ b/lib/libc/sys/utimes.2 @@ -82,7 +82,7 @@ and the effective user ID of the process does not match the owner of the file, and is not the super-user, and write access is denied. .It Bq Er EFAULT -.Fa File +.Xr File or .Fa times points outside the process's allocated address space. diff --git a/lib/libc/sys/vfork.2 b/lib/libc/sys/vfork.2 index 0d0dbf02d3be..8b6e077a90ee 100644 --- a/lib/libc/sys/vfork.2 +++ b/lib/libc/sys/vfork.2 @@ -48,16 +48,16 @@ space of the old process, which is horrendously inefficient in a paged environment. It is useful when the purpose of .Xr fork 2 would have been to create a new system context for an -.Xr execve 2 . +.Xr execve . .Fn Vfork differs from -.Xr fork 2 +.Xr fork in that the child borrows the parent's memory and thread of control until a call to .Xr execve 2 or an exit (either by a call to -.Xr exit 3 -or abnormally). +.Xr exit 2 +or abnormally.) The parent process is suspended while the child is using its resources. .Pp .Fn Vfork @@ -66,7 +66,7 @@ the parent's context. .Pp .Fn Vfork can normally be used just like -.Xr fork 2 . +.Xr fork . It does not work, however, to return while running in the childs context from the procedure that called .Fn vfork @@ -74,19 +74,19 @@ since the eventual return from .Fn vfork would then return to a no longer existent stack frame. Be careful, also, to call -.Xr _exit 2 +.Xr _exit rather than -.Xr exit 3 +.Xr exit if you can't -.Xr execve 2 , +.Xr execve , since -.Xr exit 3 +.Xr exit will flush and close standard I/O channels, and thereby mess up the parent processes standard I/O data structures. (Even with -.Xr fork 2 +.Xr fork it is wrong to call -.Xr exit 3 +.Xr exit since buffered data would then be flushed twice.) .Sh SEE ALSO .Xr fork 2 , @@ -95,15 +95,15 @@ since buffered data would then be flushed twice.) .Xr wait 2 , .Sh DIAGNOSTICS Same as for -.Xr fork 2 . +.Xr fork . .Sh BUGS This system call will be eliminated when proper system sharing mechanisms are implemented. Users should not depend on the memory sharing semantics of -.Xr vfork 2 +.Xr vfork as it will, in that case, be made synonymous to -.Xr fork 2 . +.Xr fork . .Pp To avoid a possible deadlock situation, processes that are children in the middle diff --git a/lib/libc/sys/wait.2 b/lib/libc/sys/wait.2 index cd9ab62750e7..c0077b150ce8 100644 --- a/lib/libc/sys/wait.2 +++ b/lib/libc/sys/wait.2 @@ -156,7 +156,7 @@ One of the first three macros will evaluate to a non-zero (true) value: True if the process terminated normally by a call to .Xr _exit 2 or -.Xr exit 3 . +.Xr exit 2 . .It Fn WIFSIGNALED status True if the process terminated due to receipt of a signal. .It Fn WIFSTOPPED status @@ -178,7 +178,7 @@ is true, evaluates to the low-order 8 bits of the argument passed to .Xr _exit 2 or -.Xr exit 3 +.Xr exit 2 by the child. .It Fn WTERMSIG status If @@ -287,9 +287,8 @@ and the ability to restart a pending .Fn wait call are extensions to the POSIX interface. .Sh SEE ALSO -.Xr _exit 2 , -.Xr sigaction 2 , -.Xr exit 3 +.Xr exit 2 , +.Xr sigaction 2 .Sh HISTORY A .Nm diff --git a/lib/libc/sys/write.2 b/lib/libc/sys/write.2 index a1e4a517cbe2..de2d3aef59ab 100644 --- a/lib/libc/sys/write.2 +++ b/lib/libc/sys/write.2 @@ -115,53 +115,6 @@ and may write fewer bytes than requested; the return value must be noted, and the remainder of the operation should be retried when possible. -.Sh IMPLEMENTATION NOTES -.Pp -In the non-threaded library -.Fn write -is implemented as the -.Va write -syscall. -.Pp -In the threaded library, the -.Va write -syscall is assembled to -.Fn _thread_sys_write -and -.Fn write -is implemented as a function which locks -.Va d -for read and write, then calls -.Fn _thread_sys_write . -If the call to -.Fn _thread_sys_write -would block, a context switch is performed. Before returning, -.Fn write -unlocks -.Va d . -.Pp -In the non-threaded library -.Fn writev -is implemented as the -.Va writev -syscall. -.Pp -In the threaded library, the -.Va writev -syscall is assembled to -.Fn _thread_sys_writev -and -.Fn writev -is implemented as a function which locks -.Va d -for read and write, then calls -.Fn _thread_sys_writev . -If the call to -.Fn _thread_sys_writev -would block, a context switch is performed. Before returning, -.Fn writev -unlocks -.Va d . .Sh RETURN VALUES Upon successful completion the number of bytes which were written is returned. Otherwise a -1 is returned and the global variable diff --git a/lib/libc/xdr/xdr.3 b/lib/libc/xdr/xdr.3 index ae1ea860518c..b656ea804da8 100644 --- a/lib/libc/xdr/xdr.3 +++ b/lib/libc/xdr/xdr.3 @@ -1,5 +1,5 @@ .\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI -.TH XDR 3 "16 February 1988" +.TH XDR 3N "16 February 1988" .SH NAME xdr \- library routines for external data representation .SH SYNOPSIS AND DESCRIPTION @@ -808,7 +808,7 @@ routines as parameters, and one of the most frequently used primitives, requires three. Returns one if it succeeds, zero otherwise. .SH SEE ALSO -.BR rpc (3) +.BR rpc (3N) .LP The following manuals: .RS diff --git a/lib/libc/xdr/xdr.c b/lib/libc/xdr/xdr.c index 87b4f7aaacf4..f4530869a709 100644 --- a/lib/libc/xdr/xdr.c +++ b/lib/libc/xdr/xdr.c @@ -44,7 +44,6 @@ static char *rcsid = "$Id: xdr.c,v 1.2 1995/05/30 05:42:03 rgrimes Exp $"; */ #include <stdio.h> -#include <stdlib.h> #include <rpc/types.h> #include <rpc/xdr.h> diff --git a/lib/libc/xdr/xdr_array.c b/lib/libc/xdr/xdr_array.c index 35bbb2bd99e8..57b5189ba820 100644 --- a/lib/libc/xdr/xdr_array.c +++ b/lib/libc/xdr/xdr_array.c @@ -44,7 +44,6 @@ static char *rcsid = "$Id: xdr_array.c,v 1.2 1995/05/30 05:42:04 rgrimes Exp $"; #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <rpc/types.h> #include <rpc/xdr.h> diff --git a/lib/libc/xdr/xdr_mem.c b/lib/libc/xdr/xdr_mem.c index 6f82f670f17a..05e01224e957 100644 --- a/lib/libc/xdr/xdr_mem.c +++ b/lib/libc/xdr/xdr_mem.c @@ -44,7 +44,7 @@ static char *rcsid = "$Id: xdr_mem.c,v 1.2 1995/05/30 05:42:06 rgrimes Exp $"; * */ -#include <string.h> + #include <rpc/types.h> #include <rpc/xdr.h> #include <netinet/in.h> diff --git a/lib/libc/xdr/xdr_rec.c b/lib/libc/xdr/xdr_rec.c index 3b69f257132b..dbd7d0380360 100644 --- a/lib/libc/xdr/xdr_rec.c +++ b/lib/libc/xdr/xdr_rec.c @@ -51,7 +51,6 @@ static char *rcsid = "$Id: xdr_rec.c,v 1.3 1995/05/30 05:42:09 rgrimes Exp $"; #include <stdio.h> #include <stdlib.h> -#include <string.h> #include <rpc/types.h> #include <rpc/xdr.h> #include <netinet/in.h> diff --git a/lib/libc/xdr/xdr_reference.c b/lib/libc/xdr/xdr_reference.c index 91ccff2d79cf..b65c8497068b 100644 --- a/lib/libc/xdr/xdr_reference.c +++ b/lib/libc/xdr/xdr_reference.c @@ -43,8 +43,6 @@ static char *rcsid = "$Id: xdr_reference.c,v 1.2 1995/05/30 05:42:12 rgrimes Exp */ #include <stdio.h> -#include <stdlib.h> -#include <string.h> #include <rpc/types.h> #include <rpc/xdr.h> |