diff options
Diffstat (limited to 'usr/src/lib/libbc/libc')
458 files changed, 55405 insertions, 0 deletions
diff --git a/usr/src/lib/libbc/libc/compat/4.1/ftime.c b/usr/src/lib/libbc/libc/compat/4.1/ftime.c new file mode 100644 index 0000000000..efb4c7f794 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/ftime.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1998 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/05/01 */ + +#include <sys/types.h> +#include <sys/time.h> + +/* + * Backwards compatible ftime. + */ +/* these two ints are from libc */ +extern int _timezone; +extern int _daylight; + + +/* from old timeb.h */ +struct timeb { + time_t time; + u_short millitm; + short timezone; + short dstflag; +}; + +ftime(tp) + register struct timeb *tp; +{ + struct timeval t; + + if (_gettimeofday(&t) < 0) + return (-1); + + _ltzset(t.tv_sec); + + tp->time = t.tv_sec; + tp->millitm = t.tv_usec / 1000; + tp->timezone = _timezone / 60; + tp->dstflag = _daylight; +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/getpw.c b/usr/src/lib/libbc/libc/compat/4.1/getpw.c new file mode 100644 index 0000000000..cd6324b633 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/getpw.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1984 by Sun Microsystems, Inc. + */ + +#include <pwd.h> + +getpw(uid, buf) + int uid; + char buf[]; +{ + struct passwd *pw; + char numbuf[20]; + + pw = getpwuid(uid); + if(pw == 0) + return 1; + strcpy(buf, pw->pw_name); + strcat(buf, ":"); + strcat(buf, pw->pw_passwd); + strcat(buf, ":"); + sprintf(numbuf, "%d", pw->pw_uid); + strcat(buf, numbuf); + strcat(buf, ":"); + sprintf(numbuf, "%d", pw->pw_gid); + strcat(buf, numbuf); + strcat(buf, ":"); +#if 0 + sprintf(numbuf, "%d", pw->pw_quota); + strcat(buf, numbuf); + strcat(buf, ":"); + strcat(buf, pw->pw_comment); + strcat(buf, ":"); +#endif + strcat(buf, pw->pw_gecos); + strcat(buf, ":"); + strcat(buf, pw->pw_dir); + strcat(buf, ":"); + strcat(buf, pw->pw_shell); + return 0; +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/nice.c b/usr/src/lib/libbc/libc/compat/4.1/nice.c new file mode 100644 index 0000000000..e78077b956 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/nice.c @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/05/30 */ + +#include <sys/time.h> +#include <sys/resource.h> + +/* + * Backwards compatible nice. + */ +int +nice(incr) + int incr; +{ + int prio; + extern int errno; + int serrno; + + serrno = errno; + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (prio == -1 && errno) + return (-1); + if (setpriority(PRIO_PROCESS, 0, prio + incr) == -1) + return (-1); + errno = serrno; + return (0); +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/rand.c b/usr/src/lib/libbc/libc/compat/4.1/rand.c new file mode 100644 index 0000000000..b801c9473e --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/rand.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +static long randx = 1; + +srand(x) +unsigned x; +{ + randx = x; +} + +rand() +{ + return((randx = randx * 1103515245 + 12345) & 0x7fffffff); +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/times.c b/usr/src/lib/libbc/libc/compat/4.1/times.c new file mode 100644 index 0000000000..8d25509ef6 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/times.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/times.h> +#include <unistd.h> + +clock_t +times(tmsp) + register struct tms *tmsp; +{ + int ret; + + ret = _times(tmsp); + + if (ret == -1) + return(ret * _sysconf(_SC_CLK_TCK) / 60); + else + return(0); +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/vlimit.c b/usr/src/lib/libbc/libc/compat/4.1/vlimit.c new file mode 100644 index 0000000000..d7aa1ee1a1 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/vlimit.c @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/06/20 */ + +/* + * (Almost) backwards compatible vlimit. + */ +#include <sys/time.h> +#include <sys/resource.h> +#include <errno.h> + +/* LIM_NORAISE is not emulated */ +#define LIM_NORAISE 0 /* if <> 0, can't raise limits */ +#define LIM_CPU 1 /* max secs cpu time */ +#define LIM_FSIZE 2 /* max size of file created */ +#define LIM_DATA 3 /* max growth of data space */ +#define LIM_STACK 4 /* max growth of stack */ +#define LIM_CORE 5 /* max size of ``core'' file */ +#define LIM_MAXRSS 6 /* max desired data+stack core usage */ + +#define NLIMITS 6 + +vlimit(limit, value) + int limit, value; +{ + struct rlimit rlim; + + if (limit <= 0 || limit > NLIMITS) + return (EINVAL); + if (value == -1) { + if (getrlimit(limit - 1, &rlim) < 0) + return (-1); + return (rlim.rlim_cur); + } + rlim.rlim_cur = value; + rlim.rlim_max = RLIM_INFINITY; + return (setrlimit(limit - 1, &rlim)); +} diff --git a/usr/src/lib/libbc/libc/compat/4.1/vtimes.c b/usr/src/lib/libbc/libc/compat/4.1/vtimes.c new file mode 100644 index 0000000000..cb417f7ba8 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/4.1/vtimes.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/05/31 */ + +#include <sys/time.h> +#include <sys/resource.h> + +/* + * Backwards compatible vtimes. + */ +struct vtimes { + int vm_utime; /* user time (60'ths) */ + int vm_stime; /* system time (60'ths) */ + /* divide next two by utime+stime to get averages */ + unsigned vm_idsrss; /* integral of d+s rss */ + unsigned vm_ixrss; /* integral of text rss */ + int vm_maxrss; /* maximum rss */ + int vm_majflt; /* major page faults */ + int vm_minflt; /* minor page faults */ + int vm_nswap; /* number of swaps */ + int vm_inblk; /* block reads */ + int vm_oublk; /* block writes */ +}; + +vtimes(par, chi) + register struct vtimes *par, *chi; +{ + struct rusage ru; + + if (par) { + if (getrusage(RUSAGE_SELF, &ru) < 0) + return (-1); + getvtimes(&ru, par); + } + if (chi) { + if (getrusage(RUSAGE_CHILDREN, &ru) < 0) + return (-1); + getvtimes(&ru, chi); + } + return (0); +} + +static +getvtimes(aru, avt) + register struct rusage *aru; + register struct vtimes *avt; +{ + + avt->vm_utime = scale60(&aru->ru_utime); + avt->vm_stime = scale60(&aru->ru_stime); + avt->vm_idsrss = ((aru->ru_idrss+aru->ru_isrss) / 100) * 60; + avt->vm_ixrss = aru->ru_ixrss / 100 * 60; + avt->vm_maxrss = aru->ru_maxrss; + avt->vm_majflt = aru->ru_majflt; + avt->vm_minflt = aru->ru_minflt; + avt->vm_nswap = aru->ru_nswap; + avt->vm_inblk = aru->ru_inblock; + avt->vm_oublk = aru->ru_oublock; +} + +static +scale60(tvp) + register struct timeval *tvp; +{ + + return (tvp->tv_sec * 60 + tvp->tv_usec / 16667); +} diff --git a/usr/src/lib/libbc/libc/compat/common/gtty.c b/usr/src/lib/libbc/libc/compat/common/gtty.c new file mode 100644 index 0000000000..cb3513d612 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/gtty.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/07/04 */ + +/* + * Writearound to old gtty system call. + */ + +#include <sgtty.h> + +gtty(fd, ap) + struct sgttyb *ap; +{ + + return(ioctl(fd, TIOCGETP, ap)); +} diff --git a/usr/src/lib/libbc/libc/compat/common/lockf.c b/usr/src/lib/libbc/libc/compat/common/lockf.c new file mode 100644 index 0000000000..0007b3bb19 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/lockf.c @@ -0,0 +1,106 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <fcntl.h> +#include <unistd.h> +#include <errno.h> +#include <sys/syscall.h> + +/* + * convert lockf() into fcntl() for SystemV compatibility + */ + +/* New SVR4 values */ +#define SV_GETLK 5 +#define SV_SETLK 6 +#define SV_SETLKW 7 + +lockf(fildes, function, size) + int fildes; + int function; + long size; +{ + struct flock ld; + register int cmd; + + cmd = SV_SETLK; /* assume non-blocking operation */ + ld.l_type = F_WRLCK; /* lockf() only deals with exclusive locks */ + ld.l_whence = 1; /* lock always starts at current position */ + if (size < 0) { + ld.l_start = size; + ld.l_len = -size; + } else { + ld.l_start = 0L; + ld.l_len = size; + } + + switch (function) { + case F_TEST: + if (_syscall(SYS_fcntl, fildes, SV_GETLK, &ld) != -1) { + if (ld.l_type == F_UNLCK) { + ld.l_pid = ld.l_xxx; + /* l_pid is the last field in the + SVr3 flock structure */ + return (0); + } else + errno = EACCES; /* EAGAIN ?? */ + } + return (-1); + + default: + errno = EINVAL; + return (-1); + + /* the rest fall thru to the fcntl() at the end */ + case F_ULOCK: + ld.l_type = F_UNLCK; + break; + + case F_LOCK: + cmd = SV_SETLKW; /* block, if not available */ + break; + + case F_TLOCK: + break; + } + if (_syscall(SYS_fcntl, fildes, cmd, &ld) == -1) { + switch (errno) { + /* this hack is purported to be for /usr/group compatibility */ + case ENOLCK: + errno = EDEADLK; + } + return(-1); + } else { + ld.l_pid = ld.l_xxx; /* l_pid is the last field in the + SVr3 flock structure */ + return(0); + } +} diff --git a/usr/src/lib/libbc/libc/compat/common/pause.c b/usr/src/lib/libbc/libc/compat/common/pause.c new file mode 100644 index 0000000000..ac4e42c5ce --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/pause.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/06/09 */ + +/* + * Backwards compatible pause. + */ +pause() +{ + + sigpause(sigblock(0)); + return (-1); +} diff --git a/usr/src/lib/libbc/libc/compat/common/stty.c b/usr/src/lib/libbc/libc/compat/common/stty.c new file mode 100644 index 0000000000..c4fdbbebe7 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/stty.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/07/04 */ + +/* + * Writearound to old stty system call. + */ + +#include <sgtty.h> + +stty(fd, ap) + struct sgttyb *ap; +{ + + return(ioctl(fd, TIOCSETP, ap)); +} diff --git a/usr/src/lib/libbc/libc/compat/common/tell.c b/usr/src/lib/libbc/libc/compat/common/tell.c new file mode 100644 index 0000000000..dbdf3f36e5 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/tell.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * return offset in file. + */ + +long lseek(); + +long tell(f) +{ + return(lseek(f, 0L, 1)); +} diff --git a/usr/src/lib/libbc/libc/compat/common/ulimit.c b/usr/src/lib/libbc/libc/compat/common/ulimit.c new file mode 100644 index 0000000000..dc85a971f2 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/ulimit.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/time.h> +#include <sys/resource.h> +#include <errno.h> + +extern errno; + +ulimit(cmd, newlimit) + int cmd; + long newlimit; +{ + struct rlimit rlimit; + + switch (cmd) { + + case 1: + if (getrlimit(RLIMIT_FSIZE, &rlimit) < 0) + return(-1); + return (rlimit.rlim_cur / 512); + + case 2: + rlimit.rlim_cur = rlimit.rlim_max = newlimit * 512; + return (setrlimit(RLIMIT_FSIZE, &rlimit)); + + case 3: + if (getrlimit(RLIMIT_DATA, &rlimit) < 0) + return(-1); + return (rlimit.rlim_cur); + + case 4: + return (getdtablesize()); + + default: + errno = EINVAL; + return (-1); + } +} diff --git a/usr/src/lib/libbc/libc/compat/common/utime.c b/usr/src/lib/libbc/libc/compat/common/utime.c new file mode 100644 index 0000000000..b4f3849e81 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/common/utime.c @@ -0,0 +1,65 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/05/31 */ + +#include <sys/types.h> +#include <sys/time.h> + +extern long time(); + +/* + * Backwards compatible utime. + * + * The System V system call allows any user with write permission + * on a file to set the accessed and modified times to the current + * time; they specify this by passing a null pointer to "utime". + * This is done to simulate reading one byte from a file and + * overwriting that byte with itself, which is the technique used + * by older versions of the "touch" command. The advantage of this + * hack in the system call is that it works correctly even if the file + * is zero-length. + * + * The BSD system call never allowed a null pointer so there should + * be no compatibility problem there. + */ +utime(name, otv) + char *name; + time_t otv[2]; +{ + struct timeval tv[2]; + + if (otv == 0) { + return (utimes(name, (struct timeval *)0)); + } else { + tv[0].tv_sec = (long)otv[0]; + tv[0].tv_usec = 0; + tv[1].tv_sec = (long)otv[1]; + tv[1].tv_usec = 0; + } + return (utimes(name, tv)); +} diff --git a/usr/src/lib/libbc/libc/compat/sys5/getpw.c b/usr/src/lib/libbc/libc/compat/sys5/getpw.c new file mode 100644 index 0000000000..f40dbd7bc8 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/sys5/getpw.c @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1984 by Sun Microsystems, Inc. + */ + +#include <pwd.h> + +struct passwd *getpwuid(); + +getpw(uid, buf) + int uid; + char buf[]; +{ + struct passwd *pw; + char numbuf[20]; + + pw = getpwuid(uid); + if(pw == 0) + return 1; + strcpy(buf, pw->pw_name); + strcat(buf, ":"); + strcat(buf, pw->pw_passwd); + if (*pw->pw_age != '\0') { + strcat(buf, ","); + strcat(buf, pw->pw_age); + } + strcat(buf, ":"); + sprintf(numbuf, "%d", pw->pw_uid); + strcat(buf, numbuf); + strcat(buf, ":"); + sprintf(numbuf, "%d", pw->pw_gid); + strcat(buf, numbuf); + strcat(buf, ":"); + strcat(buf, pw->pw_gecos); + strcat(buf, ":"); + strcat(buf, pw->pw_dir); + strcat(buf, ":"); + strcat(buf, pw->pw_shell); + return 0; +} diff --git a/usr/src/lib/libbc/libc/compat/sys5/mkepoch.c b/usr/src/lib/libbc/libc/compat/sys5/mkepoch.c new file mode 100644 index 0000000000..1eacd8bbd9 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/sys5/mkepoch.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 Sun Microsystems Inc. + */ + +/* + * Put out a C declaration which initializes "epoch" to the time ("tv_sec" + * portion) when this program was run. + */ + +#include <stdio.h> +#include <sys/time.h> + +int gettimeofday(); +void perror(); +void exit(); + +/*ARGSUSED*/ +int +main(argc, argv) + int argc; + char **argv; +{ + struct timeval now; + + if (gettimeofday(&now, (struct timezone *)NULL) < 0) { + perror("mkepoch: gettimeofday failed"); + exit(1); + } + + if (printf("static long epoch = %ld;\n", now.tv_sec) == EOF) { + perror("mkepoch: can't write output"); + exit(1); + } + + return (0); +} diff --git a/usr/src/lib/libbc/libc/compat/sys5/nice.c b/usr/src/lib/libbc/libc/compat/sys5/nice.c new file mode 100644 index 0000000000..926e79eb10 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/sys5/nice.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/05/30 */ + +#include <sys/time.h> +#include <sys/resource.h> +#include <errno.h> + +/* + * Backwards compatible nice. + */ +int +nice(incr) + int incr; +{ + register int prio; + int serrno; + + /* put in brain-damaged upper range checking */ + if ((incr > 40) && (geteuid() != 0)) { + errno = EPERM; + return (-1); + } + + serrno = errno; + errno = 0; + prio = getpriority(PRIO_PROCESS, 0); + if (prio == -1 && errno) + return (-1); + prio += incr; + if (prio < -20) + prio = -20; + else if (prio > 19) + prio = 19; + if (setpriority(PRIO_PROCESS, 0, prio) == -1) { + /* + * 4.3BSD stupidly returns EACCES on an attempt by a + * non-super-user process to lower a priority; map + * it to EPERM. + */ + if (errno == EACCES) + errno = EPERM; + return (-1); + } + errno = serrno; + return (prio); +} diff --git a/usr/src/lib/libbc/libc/compat/sys5/rand.c b/usr/src/lib/libbc/libc/compat/sys5/rand.c new file mode 100644 index 0000000000..1d9390ce71 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/sys5/rand.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ + +static long randx=1; + +void +srand(x) +unsigned x; +{ + randx = x; +} + +int +rand() +{ + return(((randx = randx * 1103515245L + 12345)>>16) & 0x7fff); +} diff --git a/usr/src/lib/libbc/libc/compat/sys5/times.c b/usr/src/lib/libbc/libc/compat/sys5/times.c new file mode 100644 index 0000000000..94a8ee0aa3 --- /dev/null +++ b/usr/src/lib/libbc/libc/compat/sys5/times.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/times.h> + +clock_t +times(tmsp) + register struct tms *tmsp; +{ + int ret; + + ret = _times(tmsp); + + if (ret == -1) + return(ret * _sysconf(_SC_CLK_TCK) / 60); + else + return(0); +} diff --git a/usr/src/lib/libbc/libc/crt/sparc/_ftou.c b/usr/src/lib/libbc/libc/crt/sparc/_ftou.c new file mode 100644 index 0000000000..44c5d7f7eb --- /dev/null +++ b/usr/src/lib/libbc/libc/crt/sparc/_ftou.c @@ -0,0 +1,70 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +unsigned +_dtou(d) + double d; +{ + /* Convert double to unsigned. */ + + int id; + + /* + * id = d is correct if 0 <= d < 2**31, and good enough if d is NaN + * or d < 0 or d >= 2**32. Otherwise, since the result (int) d of + * converting 2**31 <= d < 2**32 is unknown, adjust d before the + * conversion. + */ + + if (d >= 2147483648.0) + id = 0x80000000 | (int) (d - 2147483648.0); + else + id = (int) d; + return (unsigned) id; +} + +unsigned +_ftou(dd) + int dd; /* really float */ +{ + /* Convert float to unsigned. */ + + int id; + double d = (double) *((float *)(&dd)); + /* + * id = d is correct if 0 <= d < 2**31, and good enough if d is NaN + * or d < 0 or d >= 2**32. Otherwise, since the result (int) d of + * converting 2**31 <= d < 2**32 is unknown, adjust d before the + * conversion. + */ + + if (d >= 2147483648.0) + id = 0x80000000 | (int) (d - 2147483648.0); + else + id = (int) d; + return (unsigned) id; +} diff --git a/usr/src/lib/libbc/libc/crt/sparc/misalign.s b/usr/src/lib/libbc/libc/crt/sparc/misalign.s new file mode 100644 index 0000000000..d497c953db --- /dev/null +++ b/usr/src/lib/libbc/libc/crt/sparc/misalign.s @@ -0,0 +1,363 @@ +! .text +! .asciz ident "%Z%%M% %I% %E% SMI" +! .align 4 +! .seg "text" + +! Copyright 2005 Sun Microsystems, Inc. All rights reserved. +! Use is subject to license terms. +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! + +! +! C library routines for compiler support of misaligned memory +! references. These are called when an in-line test reveals a +! misaligned address. +! + + .file "misalign.s" + +#include <SYS.h> + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! int ld_int(p) +! char *p; +! { +! /* +! * load 32-bit int from misaligned address +! * cost(16-bit aligned case): 9 cycles +! * cost(8-bit aligned case): 18 cycles +! */ +! } +! + RTENTRY(.ld_int) + andcc %o0,1,%g0 ! test 16-bit alignment + be,a 1f ! fast case: two loads; + lduh [%o0+2],%o1 ! do first one in delay slot +! + ldub [%o0+3],%o3 ! slow case: load 4 bytes in <o0,o1,o2,o3> + ldub [%o0+2],%o2 + ldub [%o0+1],%o1 + ldub [%o0],%o0 ! note this has to be done last. + sll %o2,8,%o2 + sll %o1,16,%o1 + sll %o0,24,%o0 + or %o1,%o0,%o0 ! put the pieces together. + or %o2,%o0,%o0 + retl + or %o3,%o0,%o0 +1: + lduh [%o0],%o0 ! 2nd half of fast case + sll %o0,16,%o0 ! shift, concat, done. + retl + or %o0,%o1,%o0 + SET_SIZE(.ld_int) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! float ld_float(p) +! char *p; +! { +! /* load 32-bit float (not double!) from misaligned address */ +! } +! + RTENTRY(.ld_float) + save %sp,-SA(MINFRAME+8),%sp + andcc %i0,1,%g0 ! test for short alignment + be,a 1f + lduh [%i0],%o0 ! short aligned case: 2 loads, 2 stores +! + ldub [%i0],%o0 ! byte aligned case: 4 loads, 4 stores + ldub [%i0+1],%o1 + ldub [%i0+2],%o2 + ldub [%i0+3],%o3 + stb %o0,[%fp-4] + stb %o1,[%fp-3] + stb %o2,[%fp-2] + b 2f + stb %o3,[%fp-1] +1: + lduh [%i0+2],%o1 ! rest of short aligned case + sth %o0,[%fp-4] + sth %o1,[%fp-2] +2: + ld [%fp-4],%f0 ! load FPU reg, done + ret + restore + SET_SIZE(.ld_float) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! double ld_double(p) +! char *p; +! { +! /* load 64-bit float from misaligned address */ +! } +! + RTENTRY(.ld_double) + save %sp,-SA(MINFRAME+8),%sp + andcc %i0,3,%g0 ! test for long alignment + be,a 1f ! long aligned case: 2 loads, no stores + ld [%i0],%f0 +! + andcc %i0,1,%g0 ! test for short alignment + be,a 2f ! short aligned case: 4 loads, 4 stores + lduh [%i0],%o0 +! + ldub [%i0],%o0 ! worst case: byte alignment + ldub [%i0+1],%o1 ! 8 loads, 8 stores + ldub [%i0+2],%o2 + ldub [%i0+3],%o3 + stb %o0,[%fp-8] + stb %o1,[%fp-7] + stb %o2,[%fp-6] + stb %o3,[%fp-5] + ldub [%i0+4],%o0 + ldub [%i0+5],%o1 + ldub [%i0+6],%o2 + ldub [%i0+7],%o3 + stb %o0,[%fp-4] + stb %o1,[%fp-3] + stb %o2,[%fp-2] + stb %o3,[%fp-1] + ldd [%fp-8],%f0 ! load f0-f1, done + ret + restore +2: + lduh [%i0+2],%o1 ! rest of short aligned case + lduh [%i0+4],%o2 + lduh [%i0+6],%o3 + sth %o0,[%fp-8] + sth %o1,[%fp-6] + sth %o2,[%fp-4] + sth %o3,[%fp-2] + ldd [%fp-8],%f0 ! load f0-f1, done + ret + restore +1: + ld [%i0+4],%f1 ! rest of long aligned case + ret + restore + SET_SIZE(.ld_double) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! int st_int(x,p) +! int x; +! char *p; +! { +! /* store 32-bit int from misaligned address; +! return stored value */ +! } +! + RTENTRY(.st_int) + andcc %o1,1,%g0 ! test for short alignment + be,a 1f + srl %o0,16,%o4 +! + srl %o0,24,%o5 ! byte aligned case + stb %o5,[%o1] + srl %o0,16,%o2 + stb %o2,[%o1+1] + srl %o0,8,%o3 + stb %o3,[%o1+2] + retl + stb %o0,[%o1+3] +1: + sth %o4,[%o1] ! rest of short aligned case + retl + sth %o0,[%o1+2] + SET_SIZE(.st_int) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! float st_float(x,p) +! float x; +! char *p; +! { +! /* store 32-bit float from misaligned address; +! return stored value */ +! } +! + RTENTRY(.st_float) + save %sp,-SA(MINFRAME+8),%sp + andcc %i1,1,%g0 ! test for short alignment + be,a 1f ! short aligned case + srl %i0,16,%o0 +! + srl %i0,24,%o0 ! byte aligned case + srl %i0,16,%o1 + srl %i0,8,%o2 + stb %o0,[%i1] + stb %o1,[%i1+1] + stb %o2,[%i1+2] + stb %i0,[%i1+3] + st %i0,[%fp-4] ! store temp, load f0, done + ld [%fp-4],%f0 + ret + restore +1: + sth %o0,[%i1] ! rest of short aligned case + sth %i0,[%i1+2] + st %i0,[%fp-4] + ld [%fp-4],%f0 + ret + restore + SET_SIZE(.st_float) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! double st_double(x,p) +! double x; +! char *p; +! { +! /* store 64-bit float from misaligned address; +! return stored value */ +! } +! + RTENTRY(.st_double) + save %sp,-SA(MINFRAME+8),%sp + andcc %i2,3,%g0 ! test for long alignment + be,a 1f ! long aligned case: 2 stores, 2 loads + st %i0,[%i2] +! + andcc %i2,1,%g0 ! test for short alignment + be,a 2f ! short aligned case: 4 stores, 4 loads + srl %i0,16,%o0 +! ! byte aligned case: the pits + srl %i0,24,%o0 + srl %i0,16,%o1 + srl %i0,8,%o2 + stb %o0,[%i2] ! store first word, a byte at a time + stb %o1,[%i2+1] + stb %o2,[%i2+2] + stb %i0,[%i2+3] + srl %i1,24,%o0 + srl %i1,16,%o1 + srl %i1,8,%o2 + stb %o0,[%i2+4] ! store second word, a byte at a time + stb %o1,[%i2+5] + stb %o2,[%i2+6] + stb %i1,[%i2+7] + std %i0,[%fp-8] ! since dest is misaligned, must use temp + ldd [%fp-8],%f0 ! load f0,f1 from double-aligned temp, done + ret + restore +2: ! rest of short aligned case + srl %i1,16,%o1 + sth %o0,[%i2] ! store two words, a half word at a time + sth %i0,[%i2+2] + sth %o1,[%i2+4] + sth %i1,[%i2+6] + std %i0,[%fp-8] ! since dest is misaligned, must use temp + ldd [%fp-8],%f0 ! load f0,f1 from double-aligned temp, done + ret + restore +1: ! rest of long aligned case + st %i1,[%i2+4] + ld [%i2],%f0 ! load f0,f1 from long-aligned memory, done + ld [%i2+4],%f1 + ret + restore + SET_SIZE(.st_double) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! void st_float_foreff(x,p) +! float x; +! char *p; +! { +! /* store 32-bit float from misaligned address */ +! } +! + RTENTRY(.st_float_foreff) + andcc %o1,1,%g0 ! test for short alignment + be,a 1f + srl %o0,16,%o2 +! + srl %o0,24,%o2 ! byte aligned case + srl %o0,16,%o3 + srl %o0,8,%o4 + stb %o2,[%o1] + stb %o3,[%o1+1] + stb %o4,[%o1+2] + retl + stb %o0,[%o1+3] +1: ! rest of short aligned case + sth %o2,[%o1] + retl + sth %o0,[%o1+2] + SET_SIZE(.st_float_foreff) + +!- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + +! +! void st_double_foreff(x,p) +! double x; +! char *p; +! { +! /* store 64-bit float from misaligned address; +! return stored value */ +! } +! + RTENTRY(.st_double_foreff) + andcc %o2,3,%g0 ! test for long alignment + be,a 1f ! long aligned case: 2 stores + st %o0,[%o2] +! + andcc %o2,1,%g0 ! test for short alignment + be,a 2f ! short aligned case: 4 stores + srl %o0,16,%o3 +! + srl %o0,24,%o3 ! byte aligned case: 8 stores + srl %o0,16,%o4 + srl %o0,8,%o5 + stb %o3,[%o2] + stb %o4,[%o2+1] + stb %o5,[%o2+2] + stb %o0,[%o2+3] + srl %o1,24,%o3 + srl %o1,16,%o4 + srl %o1,8,%o5 + stb %o3,[%o2+4] + stb %o4,[%o2+5] + stb %o5,[%o2+6] + retl + stb %o1,[%o2+7] +2: ! rest of short aligned case + srl %o1,16,%o4 + sth %o3,[%o2] + sth %o0,[%o2+2] + sth %o4,[%o2+4] + retl + sth %o1,[%o2+6] +1: ! rest of long aligned case + retl + st %o1,[%o2+4] + SET_SIZE(.st_double_foreff) diff --git a/usr/src/lib/libbc/libc/crt/sparc/muldiv.s b/usr/src/lib/libbc/libc/crt/sparc/muldiv.s new file mode 100644 index 0000000000..65a752a4dd --- /dev/null +++ b/usr/src/lib/libbc/libc/crt/sparc/muldiv.s @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + + .ident "%Z%%M% %I% %E% SMI" + + .file "muldiv.s" + +#include <SYS.h> + + ENTRY(.udiv) + wr %g0, %g0, %y + nop + nop + mov %o0, %o3 ! o3 gets remainder + udiv %o0, %o1, %o0 ! o0 contains quotient a/b + umul %o0, %o1, %o4 ! o4 contains q*b + retl + sub %o3, %o4, %o3 ! o3 gets a-q*b + SET_SIZE(.udiv) + + ENTRY(.div) + sra %o0,31,%o4 ! extend sign + wr %o4,%g0,%y + cmp %o1,0xffffffff ! is divisor -1? + be,a 1f ! if yes + subcc %g0,%o0,%o0 ! simply negate dividend + mov %o0,%o3 ! o3 gets remainder + sdiv %o0,%o1,%o0 ! o0 contains quotient a/b + smul %o0,%o1,%o4 ! o4 contains q*b + retl + sub %o3,%o4,%o3 ! o3 gets a-q*b +1: + retl + mov %g0,%o3 ! remainder is 0 + SET_SIZE(.div) diff --git a/usr/src/lib/libbc/libc/crt/sparc/ptr_call.s b/usr/src/lib/libbc/libc/crt/sparc/ptr_call.s new file mode 100644 index 0000000000..559b0ec563 --- /dev/null +++ b/usr/src/lib/libbc/libc/crt/sparc/ptr_call.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +! .seg "data" +! .asciz "Copyr 1992 Sun Micro" + .seg ".text" + + +/* + * Indirect procedure call. + * just jump to whatever's in %g1 + */ + .global .ptr_call +.ptr_call: + jmp %g1 + nop diff --git a/usr/src/lib/libbc/libc/crt/sparc/start_float.s b/usr/src/lib/libbc/libc/crt/sparc/start_float.s new file mode 100644 index 0000000000..5a816604b9 --- /dev/null +++ b/usr/src/lib/libbc/libc/crt/sparc/start_float.s @@ -0,0 +1,36 @@ +! .data +! .asciz ident "%Z%%M% %I% %E% SMI" + +! Copyright 2005 Sun Microsystems, Inc. All rights reserved. +! Use is subject to license terms. +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! + + .file "start_float.s" + +#include <SYS.h> + + ENTRY(.start_float) + retl + nop ! [internal] + + SET_SIZE(.start_float) diff --git a/usr/src/lib/libbc/libc/gen/4.2/nlist.c b/usr/src/lib/libbc/libc/gen/4.2/nlist.c new file mode 100644 index 0000000000..12bef92183 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/4.2/nlist.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 Sun Microsystems, Inc. + */ + +#include <sys/file.h> +#include <a.out.h> + +/* + * nlist - retreive attributes from name list (string table version) + * [The actual work is done in ../common/_nlist.c] + */ +nlist(name, list) + char *name; + struct nlist *list; +{ + register int fd; + register int e; + + fd = open(name, O_RDONLY, 0); + e = _nlist(fd, list); + close(fd); + return (e); +} diff --git a/usr/src/lib/libbc/libc/gen/4.2/sleep.c b/usr/src/lib/libbc/libc/gen/4.2/sleep.c new file mode 100644 index 0000000000..5fd8ce1708 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/4.2/sleep.c @@ -0,0 +1,66 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/05/30 */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/time.h> +#include <signal.h> + +#define setvec(vec, a) \ + vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 + +static int ringring; + +sleep(n) + unsigned n; +{ + void sleepx(); + int omask; + struct itimerval itv, oitv; + register struct itimerval *itp = &itv; + struct sigvec vec, ovec; + + if (n == 0) + return; + timerclear(&itp->it_interval); + timerclear(&itp->it_value); + if (setitimer(ITIMER_REAL, itp, &oitv) < 0) + return; + itp->it_value.tv_sec = n; + if (timerisset(&oitv.it_value)) { + if (timercmp(&oitv.it_value, &itp->it_value, >)) + oitv.it_value.tv_sec -= itp->it_value.tv_sec; + else { + itp->it_value = oitv.it_value; + /* + * This is a hack, but we must have time to + * return from the setitimer after the alarm + * or else it'll be restarted. And, anyway, + * sleep never did anything more than this before. + */ + oitv.it_value.tv_sec = 1; + oitv.it_value.tv_usec = 0; + } + } + setvec(vec, sleepx); + (void) sigvec(SIGALRM, &vec, &ovec); + omask = sigblock(sigmask(SIGALRM)); + ringring = 0; + (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0); + while (!ringring) + sigpause(omask &~ sigmask(SIGALRM)); + (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0); + (void) sigsetmask(omask); + (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); +} + +static void +sleepx() +{ + + ringring = 1; +} diff --git a/usr/src/lib/libbc/libc/gen/4.2/system.c b/usr/src/lib/libbc/libc/gen/4.2/system.c new file mode 100644 index 0000000000..295413f620 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/4.2/system.c @@ -0,0 +1,99 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <signal.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <string.h> +#include <sys/file.h> + +extern int execl(); + +int +system(s) +char *s; +{ + int status; + pid_t pid, w; + register void (*istat)(), (*qstat)(); + char path[256]; + char *c; + + while (*s == ' ' || *s == '\t') + s++; + + if (strncmp(s, "/usr/ucb", strlen("/usr/ucb")) == 0) { + /* check if command is under /usr/ucb, if not + * replace /usr/ucb with /usr/bin. + */ + strcpy(path, s); + if ((c = strchr(path, ' ')) != NULL) + *c ='\0'; + if (access(path, F_OK) == -1) { + strncpy(path, "/usr/bin", strlen("/usr/bin")); + if (c != NULL) *c = ' '; + s = path; + } + } + else if (strncmp(s, "/bin", strlen("/bin")) == 0 || + strncmp(s, "/usr/bin", strlen("/usr/bin")) == 0) { + /* if /usr/bin is specified, first check if a command + * with the same name exists under /usr/ucb */ + strcpy(path, "/usr/ucb"); + if (strncmp(s, "/bin", strlen("/bin")) == 0) + strcat(path, strchr(s+1, '/')); + else { + c = strchr(s+1, '/'); + strcat(path, strchr(c+1, '/')); + } + if ((c = strchr(path, ' ')) != NULL) + *c ='\0'; + if (access(path, F_OK) == 0) { + if (c != NULL) *c = ' '; + s = path; + } + } + + if ((pid = vfork()) == 0) { + (void) execl("/bin/sh", "sh", "-c", s, (char *)0); + _exit(127); + } + if (pid == -1) { + return (-1); + } + istat = signal(SIGINT, SIG_IGN); + qstat = signal(SIGQUIT, SIG_IGN); + w = waitpid(pid, &status, 0); + (void) signal(SIGINT, istat); + (void) signal(SIGQUIT, qstat); + return ((w == -1) ? -1: status); +} diff --git a/usr/src/lib/libbc/libc/gen/4.2/timezone.c b/usr/src/lib/libbc/libc/gen/4.2/timezone.c new file mode 100644 index 0000000000..d1795123a1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/4.2/timezone.c @@ -0,0 +1,99 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.4 83/09/25 */ + +/* + * The arguments are the number of minutes of time + * you are westward from Greenwich and whether DST is in effect. + * It returns a string + * giving the name of the local timezone. + * + * Sorry, I don't know all the names. + */ + +static struct zone { + int offset; + char *stdzone; + char *dlzone; +} zonetab[] = { + -12*60, "NZST", "NZDT", /* New Zealand */ + -10*60, "EST", "EST", /* Aust: Eastern */ + -10*60+30, "CST", "CST", /* Aust: Central */ + -8*60, "WST", 0, /* Aust: Western */ + -9*60, "JST", 0, /* Japanese */ + 0*60, "GMT", "BST", /* Great Britain and Eire */ + -1*60, "MET", "MET DST", /* Middle European */ + -2*60, "EET", "EET DST", /* Eastern European */ + 3*60+30, "NST", "NDT", /* Newfoundland */ + 4*60, "AST", "ADT", /* Atlantic */ + 5*60, "EST", "EDT", /* Eastern */ + 6*60, "CST", "CDT", /* Central */ + 7*60, "MST", "MDT", /* Mountain */ + 8*60, "PST", "PDT", /* Pacific */ + 9*60, "YST", "YDT", /* Yukon */ + 10*60, "HST", "HDT", /* Hawaiian */ + -1 +}; + +char *timezone(zone, dst) +{ + register struct zone *zp; + static char czone[10]; + char *sign; + register char *p, *q; + char *getenv(), *index(); + + if (p = getenv("TZNAME")) { + if (q = index(p, ',')) { + if (dst) + return(++q); + else { + *q = '\0'; + strncpy(czone, p, sizeof(czone)-1); + czone[sizeof(czone)-1] = '\0'; + *q = ','; + return (czone); + } + } + return(p); + } + for (zp=zonetab; zp->offset!=-1; zp++) + if (zp->offset==zone) { + if (dst && zp->dlzone) + return(zp->dlzone); + if (!dst && zp->stdzone) + return(zp->stdzone); + } + if (zone<0) { + zone = -zone; + sign = "+"; + } else + sign = "-"; + sprintf(czone, "GMT%s%d:%02d", sign, zone/60, zone%60); + return(czone); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_add.c b/usr/src/lib/libbc/libc/gen/common/_Q_add.c new file mode 100644 index 0000000000..a91091596a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_add.c @@ -0,0 +1,80 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +static double zero = 0.0, tiny = 1.0e-300, huge = 1.0e300; +static dummy(); +extern _Q_get_rp_rd(), _Q_set_exception(); + +QUAD +_Q_add(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + QUAD z; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); /* get fp_precision, fp_direction */ + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + _fp_add(&px,&py,&pz); + _fp_pack(&pz,&z,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return z; +} + +/* don't use ieee_flags(), use machine dependent routine +_Q_get_rp_rd() +{ + char *out; + fp_precision = ieee_flags("get","precision","",&out); + fp_direction = ieee_flags("get","direction","",&out); + return 0; +} +*/ + +_Q_set_exception(ex) + unsigned ex; +{ + /* simulate exceptions using double arithmetic */ + double t; + if((ex&(1<<fp_invalid))!=0) t = (zero/zero); + if((ex&(1<<fp_overflow))!=0) t = (huge*huge); + if((ex&(1<<fp_underflow))!=0) t = (tiny*tiny); + if((ex&(1<<fp_division))!=0) t = (tiny/zero); + if((ex&(1<<fp_inexact))!=0) t = (huge+tiny); + dummy(t); /* prevent optimizer eliminating previous expression */ + return 0; +} + +static +dummy(x) + double x; +{ + return 0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_cmp.c b/usr/src/lib/libbc/libc/gen/common/_Q_cmp.c new file mode 100644 index 0000000000..027401381f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_cmp.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +enum fcc_type +_Q_cmp(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + enum fcc_type fcc; + _fp_current_exceptions = 0; + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + fcc = _fp_compare(&px,&py,0); /* quiet NaN unexceptional */ + _Q_set_exception(_fp_current_exceptions); + return fcc; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_cmpe.c b/usr/src/lib/libbc/libc/gen/common/_Q_cmpe.c new file mode 100644 index 0000000000..70340e08b7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_cmpe.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +enum fcc_type +_Q_cmpe(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + enum fcc_type fcc; + _fp_current_exceptions = 0; + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + fcc = _fp_compare(&px,&py,1); /* quiet NaN exceptional */ + _Q_set_exception(_fp_current_exceptions); + return fcc; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_div.c b/usr/src/lib/libbc/libc/gen/common/_Q_div.c new file mode 100644 index 0000000000..b5a28184fe --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_div.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC div + +QUAD +_Q_div(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + QUAD z; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + _fp_div(&px,&py,&pz); + _fp_pack(&pz,&z,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return z; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_dtoq.c b/usr/src/lib/libbc/libc/gen/common/_Q_dtoq.c new file mode 100644 index 0000000000..0c4b6996a2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_dtoq.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC dtoq + +QUAD +_Q_dtoq(x) + double x; +{ + unpacked px; + QUAD q; + _fp_current_exceptions = 0; + _fp_unpack(&px,&x,fp_op_double); + _fp_pack(&px,&q,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return q; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_fcc.c b/usr/src/lib/libbc/libc/gen/common/_Q_fcc.c new file mode 100644 index 0000000000..ac9a6eb31d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_fcc.c @@ -0,0 +1,78 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1989 by Sun Microsystems, Inc. + */ + +/* integer function _Q_feq, _Q_fne, _Q_fgt, _Q_fge, _Q_flt, _Q_fle */ + +#include "_Qquad.h" + +int _Q_feq(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmp(x,y); + return (fcc_equal==fcc); +} + +int _Q_fne(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmp(x,y); + return (fcc_equal!=fcc); +} + +int _Q_fgt(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmpe(x,y); + return (fcc_greater==fcc); +} + +int _Q_fge(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmpe(x,y); + return (fcc_greater==fcc||fcc_equal==fcc); +} + +int _Q_flt(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmpe(x,y); + return (fcc_less==fcc); +} + +int _Q_fle(x,y) + QUAD x,y; +{ + enum fcc_type fcc; + fcc = _Q_cmpe(x,y); + return (fcc_less==fcc||fcc_equal==fcc); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_get_rp_rd.S b/usr/src/lib/libbc/libc/gen/common/_Q_get_rp_rd.S new file mode 100644 index 0000000000..b8409bed81 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_get_rp_rd.S @@ -0,0 +1,55 @@ +! +! #ident "%Z%%M% %I% %E% SMI" +! +! Copyright 2005 Sun Microsystems, Inc. All rights reserved. +! Use is subject to license terms. +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! + +#include "SYS.h" + + ENTRY(_Q_get_rp_rd) + .global fp_precision, fp_direction +__Q_get_rp_rd: +#ifdef PIC + PIC_SETUP(o5) + ld [%o5+fp_direction],%o3 +#else + set fp_direction,%o3 +#endif + set 0xc0000000,%o4 ! mask of rounding direction bits + st %fsr,[%sp+0x44] + ld [%sp+0x44],%o0 ! o0 = fsr + and %o0,%o4,%o1 + srl %o1,30,%o1 + st %o1,[%o3] +#ifdef PIC + ld [%o5+fp_precision],%o3 +#else + set fp_precision,%o3 +#endif + set 0x30000000,%o4 + and %o0,%o4,%o1 + srl %o1,28,%o1 + retl + st %o1,[%o3] + SET_SIZE(_Q_get_rp_rd) diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_itoq.c b/usr/src/lib/libbc/libc/gen/common/_Q_itoq.c new file mode 100644 index 0000000000..ac51aeafcd --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_itoq.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +#define FUNC itoq + +QUAD +_Q_itoq(x) + int x; +{ + unpacked px; + QUAD q; + _fp_unpack(&px,&x,fp_op_integer); + _fp_pack(&px,&q,fp_op_extended); + return q; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_mul.c b/usr/src/lib/libbc/libc/gen/common/_Q_mul.c new file mode 100644 index 0000000000..5089330d34 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_mul.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC mul + +QUAD +_Q_mul(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + QUAD z; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + _fp_mul(&px,&py,&pz); + _fp_pack(&pz,&z,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return z; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_neg.c b/usr/src/lib/libbc/libc/gen/common/_Q_neg.c new file mode 100644 index 0000000000..9b2fca39a5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_neg.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" + +QUAD +_Q_neg(x) + QUAD x; +{ + QUAD z; + int *pz = (int*) &z; + double dummy = 1.0; + z = x; + if((*(int*)&dummy)!=0) { + pz[0] ^= 0x80000000; + } else { + pz[3] ^= 0x80000000; + } + return z; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_qtod.c b/usr/src/lib/libbc/libc/gen/common/_Q_qtod.c new file mode 100644 index 0000000000..fe13d05b98 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_qtod.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC qtod + +double +_Q_qtod(x) + QUAD x; +{ + unpacked px; + double d; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_pack(&px,&d,fp_op_double); + _Q_set_exception(_fp_current_exceptions); + return d; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_qtoi.c b/usr/src/lib/libbc/libc/gen/common/_Q_qtoi.c new file mode 100644 index 0000000000..317f0d90fa --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_qtoi.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_set_exception(); + +int +_Q_qtoi(x) + QUAD x; +{ + unpacked px; + int i; + enum fp_direction_type saved_fp_direction = fp_direction; + + _fp_current_exceptions = 0; + fp_direction = fp_tozero; + _fp_unpack(&px,&x,fp_op_extended); + _fp_pack(&px,&i,fp_op_integer); + _Q_set_exception(_fp_current_exceptions); + fp_direction = saved_fp_direction; + return i; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_qtos.c b/usr/src/lib/libbc/libc/gen/common/_Q_qtos.c new file mode 100644 index 0000000000..3df31ae0e1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_qtos.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC qtos + +SINGLERESULT +_Q_qtos(x) + QUAD x; +{ + unpacked px; + float s; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_pack(&px,&s,fp_op_single); + _Q_set_exception(_fp_current_exceptions); + RETURNSINGLE(s); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_qtou.c b/usr/src/lib/libbc/libc/gen/common/_Q_qtou.c new file mode 100644 index 0000000000..9f09b3f732 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_qtou.c @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_set_exception(); + +unsigned +_Q_qtou(x) + QUAD x; +{ + unpacked px; + QUAD c; + unsigned u,*pc = (unsigned*)&c,r; + enum fp_direction_type saved_fp_direction = fp_direction; + + pc[0] = 0x401e0000; pc[1]=pc[2]=pc[3]=0; /* c = 2^31 */ + r = 0; + u = *(int*)&x; /* high part of x */ + if(u>=0x401e0000&&u<0x401f0000) { + r = 0x80000000; + x = _Q_sub(x,c); + } + + _fp_current_exceptions = 0; + fp_direction = fp_tozero; + _fp_unpack(&px,&x,fp_op_extended); + _fp_pack(&px,&u,fp_op_integer); + _Q_set_exception(_fp_current_exceptions); + fp_direction = saved_fp_direction; + return (u|r); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_sqrt.c b/usr/src/lib/libbc/libc/gen/common/_Q_sqrt.c new file mode 100644 index 0000000000..ac175cc51a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_sqrt.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC sqrt + +QUAD +_Q_sqrt(x) + QUAD x; +{ + unpacked px,pz; + QUAD z; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_sqrt(&px,&pz); + _fp_pack(&pz,&z,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return z; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_stoq.c b/usr/src/lib/libbc/libc/gen/common/_Q_stoq.c new file mode 100644 index 0000000000..293ee0208e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_stoq.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC stoq + +QUAD +_Q_stoq(x) + SINGLE x; +{ + unpacked px; + QUAD q; + _fp_current_exceptions = 0; + _fp_unpack(&px,&x,fp_op_single); + _fp_pack(&px,&q,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return q; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_sub.c b/usr/src/lib/libbc/libc/gen/common/_Q_sub.c new file mode 100644 index 0000000000..306f5bf260 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_sub.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +extern _Q_get_rp_rd(), _Q_set_exception(); + +#define FUNC sub + +QUAD +_Q_sub(x,y) + QUAD x,y; +{ + unpacked px,py,pz; + QUAD z; + _fp_current_exceptions = 0; + _Q_get_rp_rd(); + _fp_unpack(&px,&x,fp_op_extended); + _fp_unpack(&py,&y,fp_op_extended); + _fp_sub(&px,&py,&pz); + _fp_pack(&pz,&z,fp_op_extended); + _Q_set_exception(_fp_current_exceptions); + return z; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Q_utoq.c b/usr/src/lib/libbc/libc/gen/common/_Q_utoq.c new file mode 100644 index 0000000000..4ebdf44a3f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Q_utoq.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +#define FUNC utoq + +QUAD +_Q_utoq(x) + unsigned x; +{ + unpacked px; + QUAD q,c; + int *pc =(int*)&c; + pc[0] = 0x401e0000; pc[1]=pc[2]=pc[3]=0; /* pc = 2^31 */ + if((x&0x80000000)!=0) { + x ^= 0x80000000; + _fp_unpack(&px,&x,fp_op_integer); + _fp_pack(&px,&q,fp_op_extended); + q = _Q_add(q,c); + } else { + _fp_unpack(&px,&x,fp_op_integer); + _fp_pack(&px,&q,fp_op_extended); + } + return q; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfaddsub.c b/usr/src/lib/libbc/libc/gen/common/_Qfaddsub.c new file mode 100644 index 0000000000..c9bc64f49e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfaddsub.c @@ -0,0 +1,216 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +PRIVATE void +true_add(px, py, pz) + unpacked *px, *py, *pz; + +{ + unsigned c; + unpacked *pt; + + if ((int) px->fpclass < (int) py->fpclass) { /* Reverse. */ + pt = py; + py = px; + px = pt; + } + /* Now class(x) >= class(y). */ + switch (px->fpclass) { + case fp_quiet: /* NaN + x -> NaN */ + case fp_signaling: /* NaN + x -> NaN */ + case fp_infinity: /* Inf + x -> Inf */ + case fp_zero: /* 0 + 0 -> 0 */ + *pz = *px; + return; + default: + if (py->fpclass == fp_zero) { + *pz = *px; + return; + } + } + /* Now z is normal or subnormal. */ + /* Now y is normal or subnormal. */ + if (px->exponent < py->exponent) { /* Reverse. */ + pt = py; + py = px; + px = pt; + } + /* Now class(x) >= class(y). */ + pz->fpclass = px->fpclass; + pz->sign = px->sign; + pz->exponent = px->exponent; + pz->rounded = pz->sticky = 0; + + if (px->exponent != py->exponent) { /* pre-alignment required */ + fpu_rightshift(py, pz->exponent - py->exponent); + pz->rounded = py->rounded; + pz->sticky = py->sticky; + } + c = 0; + c = fpu_add3wc(&(pz->significand[3]),px->significand[3], + py->significand[3],c); + c = fpu_add3wc(&(pz->significand[2]),px->significand[2], + py->significand[2],c); + c = fpu_add3wc(&(pz->significand[1]),px->significand[1], + py->significand[1],c); + c = fpu_add3wc(&(pz->significand[0]),px->significand[0], + py->significand[0],c); + + /* Handle carry out of msb. */ + if(pz->significand[0]>=0x20000) { + fpu_rightshift(pz, 1); /* Carried out bit. */ + pz->exponent ++; /* Renormalize. */ + } + return; +} + +PRIVATE void +true_sub(px, py, pz) + unpacked *px, *py, *pz; + +{ + unsigned *z,g,s,r,c; + int n; + unpacked *pt; + + if ((int) px->fpclass < (int) py->fpclass) { /* Reverse. */ + pt = py; + py = px; + px = pt; + } + /* Now class(x) >= class(y). */ + *pz = *px; /* Tentative difference: x. */ + switch (pz->fpclass) { + case fp_quiet: /* NaN - x -> NaN */ + case fp_signaling: /* NaN - x -> NaN */ + return; + case fp_infinity: /* Inf - x -> Inf */ + if (py->fpclass == fp_infinity) { + fpu_error_nan(pz); /* Inf - Inf -> NaN */ + pz->fpclass = fp_quiet; + } + return; + case fp_zero: /* 0 - 0 -> 0 */ + pz->sign = (fp_direction == fp_negative); + return; + default: + if (py->fpclass == fp_zero) + return; + } + + /* x and y are both normal or subnormal. */ + + if (px->exponent < py->exponent) { /* Reverse. */ + pt = py; + py = px; + px = pt; + } + /* Now exp(x) >= exp(y). */ + pz->fpclass = px->fpclass; + pz->sign = px->sign; + pz->exponent = px->exponent; + pz->rounded = 0; + pz->sticky = 0; + z = pz->significand; + + if (px->exponent == py->exponent) { /* no pre-alignment required */ + c = 0; + c = fpu_sub3wc(&z[3],px->significand[3],py->significand[3],c); + c = fpu_sub3wc(&z[2],px->significand[2],py->significand[2],c); + c = fpu_sub3wc(&z[1],px->significand[1],py->significand[1],c); + c = fpu_sub3wc(&z[0],px->significand[0],py->significand[0],c); + if((z[0]|z[1]|z[2]|z[3])==0) { /* exact zero result */ + pz->sign = (fp_direction == fp_negative); + pz->fpclass = fp_zero; + return; + } + if(z[0]>=0x20000) { /* sign reversal occurred */ + pz->sign = py->sign; + c = 0; + c = fpu_neg2wc(&z[3],z[3],c); + c = fpu_neg2wc(&z[2],z[2],c); + c = fpu_neg2wc(&z[1],z[1],c); + c = fpu_neg2wc(&z[0],z[0],c); + } + fpu_normalize(pz); + return; + } else { /* pre-alignment required */ + fpu_rightshift(py, pz->exponent - py->exponent - 1); + r = py->rounded; /* rounded bit */ + s = py->sticky; /* sticky bit */ + fpu_rightshift(py, 1); + g = py->rounded; /* guard bit */ + if(s!=0) r = (r==0); + if((r|s)!=0) g = (g==0);/* guard and rounded bits of z */ + c = ((g|r|s)!=0); + c = fpu_sub3wc(&z[3],px->significand[3],py->significand[3],c); + c = fpu_sub3wc(&z[2],px->significand[2],py->significand[2],c); + c = fpu_sub3wc(&z[1],px->significand[1],py->significand[1],c); + c = fpu_sub3wc(&z[0],px->significand[0],py->significand[0],c); + + if(z[0]>=0x10000) { /* don't need post-shifted */ + pz->sticky = s|r; + pz->rounded = g; + } else { /* post-shifted left 1 bit */ + pz->sticky = s; + pz->rounded = r; + pz->significand[0] = (z[0]<<1)|((z[1]&0x80000000)>>31); + pz->significand[1] = (z[1]<<1)|((z[2]&0x80000000)>>31); + pz->significand[2] = (z[2]<<1)|((z[3]&0x80000000)>>31); + pz->significand[3] = (z[3]<<1)|g; + pz->exponent -= 1; + if(z[0]<0x10000) fpu_normalize(pz); + } + return; + } +} + +void +_fp_add(px, py, pz) + unpacked *px, *py, *pz; + +{ + if (px->sign == py->sign) + true_add(px, py, pz); + else + true_sub(px, py, pz); +} + +void +_fp_sub(px, py, pz) + unpacked *px, *py, *pz; + +{ + py->sign = 1 - py->sign; + if (px->sign == py->sign) + true_add(px, py, pz); + else + true_sub(px, py, pz); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfcompare.c b/usr/src/lib/libbc/libc/gen/common/_Qfcompare.c new file mode 100644 index 0000000000..7b1a3136eb --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfcompare.c @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +enum fcc_type +_fp_compare(px, py, strict) + unpacked *px, *py; + int strict; /* 0 if quiet NaN unexceptional, 1 if + * exceptional */ + +{ + enum fcc_type cc; + int k,n; + + if ((px->fpclass == fp_quiet) || (py->fpclass == fp_quiet) || + (px->fpclass == fp_signaling) || (py->fpclass == fp_signaling)) { + if (strict) /* NaN */ + fpu_set_exception(fp_invalid); + cc = fcc_unordered; + } else if ((px->fpclass == fp_zero) && (py->fpclass == fp_zero)) + cc = fcc_equal; + /* both zeros */ + else if (px->sign < py->sign) + cc = fcc_greater; + else if (px->sign > py->sign) + cc = fcc_less; + else { /* signs the same, compute magnitude cc */ + if ((int) px->fpclass > (int) py->fpclass) + cc = fcc_greater; + else if ((int) px->fpclass < (int) py->fpclass) + cc = fcc_less; + else + /* same classes */ if (px->fpclass == fp_infinity) + cc = fcc_equal; /* same infinity */ + else if (px->exponent > py->exponent) + cc = fcc_greater; + else if (px->exponent < py->exponent) + cc = fcc_less; + else { /* equal exponents */ + n = fpu_cmpli(px->significand,py->significand,4); + if(n>0) cc = fcc_greater; + else if(n<0) cc = fcc_less; + else cc = fcc_equal; + } + if (px->sign) + switch (cc) { /* negative numbers */ + case fcc_less: + cc = fcc_greater; + break; + case fcc_greater: + cc = fcc_less; + break; + } + } + return (cc); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfdiv.c b/usr/src/lib/libbc/libc/gen/common/_Qfdiv.c new file mode 100644 index 0000000000..90b408686b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfdiv.c @@ -0,0 +1,295 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +void +_fp_div(px, py, pz) + unpacked *px, *py, *pz; + +{ + unsigned r[4],*y,q,c; + int n; + + *pz = *px; + pz->sign = px->sign ^ py->sign; + + if ((py->fpclass == fp_quiet) || (py->fpclass == fp_signaling)) { + *pz = *py; + return; + } + switch (px->fpclass) { + case fp_quiet: + case fp_signaling: + return; + case fp_zero: + case fp_infinity: + if (px->fpclass == py->fpclass) { /* 0/0 or inf/inf */ + fpu_error_nan(pz); + pz->fpclass = fp_quiet; + } + return; + case fp_normal: + switch (py->fpclass) { + case fp_zero: /* number/0 */ + fpu_set_exception(fp_division); + pz->fpclass = fp_infinity; + return; + case fp_infinity: /* number/inf */ + pz->fpclass = fp_zero; + return; + } + } + + /* Now x and y are both normal or subnormal. */ + + r[0] = px->significand[0]; + r[1] = px->significand[1]; + r[2] = px->significand[2]; + r[3] = px->significand[3]; + y = py->significand; + + if(fpu_cmpli(r,y,4)>=0) + pz->exponent = px->exponent - py->exponent; + else + pz->exponent = px->exponent - py->exponent - 1; + + q=0; + while(q<0x10000) { /* generate quo[0] */ + q<<=1; + if(fpu_cmpli(r,y,4)>=0) { + q += 1; /* if r>y do r-=y and q+=1 */ + c = 0; + c = fpu_sub3wc(&r[3],r[3],y[3],c); + c = fpu_sub3wc(&r[2],r[2],y[2],c); + c = fpu_sub3wc(&r[1],r[1],y[1],c); + c = fpu_sub3wc(&r[0],r[0],y[0],c); + } + r[0] = (r[0]<<1)|((r[1]&0x80000000)>>31); /* r << 1 */ + r[1] = (r[1]<<1)|((r[2]&0x80000000)>>31); + r[2] = (r[2]<<1)|((r[3]&0x80000000)>>31); + r[3] = (r[3]<<1); + } + pz->significand[0]=q; + q=0; /* generate quo[1] */ + n = 32; + while(n--) { + q<<=1; + if(fpu_cmpli(r,y,4)>=0) { + q += 1; /* if r>y do r-=y and q+=1 */ + c = 0; + c = fpu_sub3wc(&r[3],r[3],y[3],c); + c = fpu_sub3wc(&r[2],r[2],y[2],c); + c = fpu_sub3wc(&r[1],r[1],y[1],c); + c = fpu_sub3wc(&r[0],r[0],y[0],c); + } + r[0] = (r[0]<<1)|((r[1]&0x80000000)>>31); /* r << 1 */ + r[1] = (r[1]<<1)|((r[2]&0x80000000)>>31); + r[2] = (r[2]<<1)|((r[3]&0x80000000)>>31); + r[3] = (r[3]<<1); + } + pz->significand[1] = q; + q=0; /* generate quo[2] */ + n = 32; + while(n--) { + q<<=1; + if(fpu_cmpli(r,y,4)>=0) { + q += 1; /* if r>y do r-=y and q+=1 */ + c = 0; + c = fpu_sub3wc(&r[3],r[3],y[3],c); + c = fpu_sub3wc(&r[2],r[2],y[2],c); + c = fpu_sub3wc(&r[1],r[1],y[1],c); + c = fpu_sub3wc(&r[0],r[0],y[0],c); + } + r[0] = (r[0]<<1)|((r[1]&0x80000000)>>31); /* r << 1 */ + r[1] = (r[1]<<1)|((r[2]&0x80000000)>>31); + r[2] = (r[2]<<1)|((r[3]&0x80000000)>>31); + r[3] = (r[3]<<1); + } + pz->significand[2] = q; + q=0; /* generate quo[3] */ + n = 32; + while(n--) { + q<<=1; + if(fpu_cmpli(r,y,4)>=0) { + q += 1; /* if r>y do r-=y and q+=1 */ + c = 0; + c = fpu_sub3wc(&r[3],r[3],y[3],c); + c = fpu_sub3wc(&r[2],r[2],y[2],c); + c = fpu_sub3wc(&r[1],r[1],y[1],c); + c = fpu_sub3wc(&r[0],r[0],y[0],c); + } + r[0] = (r[0]<<1)|((r[1]&0x80000000)>>31); /* r << 1 */ + r[1] = (r[1]<<1)|((r[2]&0x80000000)>>31); + r[2] = (r[2]<<1)|((r[3]&0x80000000)>>31); + r[3] = (r[3]<<1); + } + pz->significand[3] = q; + if((r[0]|r[1]|r[2]|r[3])==0) pz->sticky = pz->rounded = 0; + else { + pz->sticky = 1; /* half way case won't occur */ + if(fpu_cmpli(r,y,4)>=0) pz->rounded = 1; + } +} + +void +_fp_sqrt(px, pz) + unpacked *px, *pz; + +{ /* *pz gets sqrt(*px) */ + + unsigned *x,r,c,q,t[4],s[4]; + *pz = *px; + switch (px->fpclass) { + case fp_quiet: + case fp_signaling: + case fp_zero: + return; + case fp_infinity: + if (px->sign == 1) { /* sqrt(-inf) */ + fpu_error_nan(pz); + pz->fpclass = fp_quiet; + } + return; + case fp_normal: + if (px->sign == 1) { /* sqrt(-norm) */ + fpu_error_nan(pz); + pz->fpclass = fp_quiet; + return; + } + } + + /* Now x is normal. */ + x = px->significand; + if (px->exponent & 1) { /* sqrt(1.f * 2**odd) = sqrt (2.+2f) * + * 2**(odd-1)/2 */ + pz->exponent = (px->exponent - 1) / 2; + x[0] = (x[0]<<1)|((x[1]&0x80000000)>>31); /* x<<1 */ + x[1] = (x[1]<<1)|((x[2]&0x80000000)>>31); + x[2] = (x[2]<<1)|((x[3]&0x80000000)>>31); + x[3] = (x[3]<<1); + } else { /* sqrt(1.f * 2**even) = sqrt (1.f) * + * 2**(even)/2 */ + pz->exponent = px->exponent / 2; + } + s[0]=s[1]=s[2]=s[3]=t[0]=t[1]=t[2]=t[3]=0; + q = 0; + r = 0x00010000; + while(r!=0) { /* compute sqrt[0] */ + t[0] = s[0]+r; + if(t[0]<=x[0]) { + s[0] = t[0]+r; + x[0] -= t[0]; + q += r; + } + x[0] = (x[0]<<1)|((x[1]&0x80000000)>>31); /* x<<1 */ + x[1] = (x[1]<<1)|((x[2]&0x80000000)>>31); + x[2] = (x[2]<<1)|((x[3]&0x80000000)>>31); + x[3] = (x[3]<<1); + r>>=1; + } + pz->significand[0] = q; + q = 0; + r = 0x80000000; + while(r!=0) { /* compute sqrt[1] */ + t[1] = s[1]+r; /* no carry */ + t[0] = s[0]; + if(fpu_cmpli(t,x,2)<=0) { + c = 0; + c = fpu_add3wc(&s[1],t[1],r,c); + c = fpu_add3wc(&s[0],t[0],0,c); + c = 0; + c = fpu_sub3wc(&x[1],x[1],t[1],c); + c = fpu_sub3wc(&x[0],x[0],t[0],c); + q += r; + } + x[0] = (x[0]<<1)|((x[1]&0x80000000)>>31); /* x<<1 */ + x[1] = (x[1]<<1)|((x[2]&0x80000000)>>31); + x[2] = (x[2]<<1)|((x[3]&0x80000000)>>31); + x[3] = (x[3]<<1); + r>>=1; + } + pz->significand[1] = q; + q = 0; + r = 0x80000000; + while(r!=0) { /* compute sqrt[2] */ + t[2] = s[2]+r; /* no carry */ + t[1] = s[1]; + t[0] = s[0]; + if(fpu_cmpli(t,x,3)<=0) { + c = 0; + c = fpu_add3wc(&s[2],t[2],r,c); + c = fpu_add3wc(&s[1],t[1],0,c); + c = fpu_add3wc(&s[0],t[0],0,c); + c = 0; + c = fpu_sub3wc(&x[2],x[2],t[2],c); + c = fpu_sub3wc(&x[1],x[1],t[1],c); + c = fpu_sub3wc(&x[0],x[0],t[0],c); + q += r; + } + x[0] = (x[0]<<1)|((x[1]&0x80000000)>>31); /* x<<1 */ + x[1] = (x[1]<<1)|((x[2]&0x80000000)>>31); + x[2] = (x[2]<<1)|((x[3]&0x80000000)>>31); + x[3] = (x[3]<<1); + r>>=1; + } + pz->significand[2] = q; + q = 0; + r = 0x80000000; + while(r!=0) { /* compute sqrt[3] */ + t[3] = s[3]+r; /* no carry */ + t[2] = s[2]; + t[1] = s[1]; + t[0] = s[0]; + if(fpu_cmpli(t,x,4)<=0) { + c = 0; + c = fpu_add3wc(&s[3],t[3],r,c); + c = fpu_add3wc(&s[2],t[2],0,c); + c = fpu_add3wc(&s[1],t[1],0,c); + c = fpu_add3wc(&s[0],t[0],0,c); + c = 0; + c = fpu_sub3wc(&x[3],x[3],t[3],c); + c = fpu_sub3wc(&x[2],x[2],t[2],c); + c = fpu_sub3wc(&x[1],x[1],t[1],c); + c = fpu_sub3wc(&x[0],x[0],t[0],c); + q += r; + } + x[0] = (x[0]<<1)|((x[1]&0x80000000)>>31); /* x<<1 */ + x[1] = (x[1]<<1)|((x[2]&0x80000000)>>31); + x[2] = (x[2]<<1)|((x[3]&0x80000000)>>31); + x[3] = (x[3]<<1); + r>>=1; + } + pz->significand[3] = q; + if((x[0]|x[1]|x[2]|x[3])==0) { + pz->sticky = pz->rounded = 0; + } else { + pz->sticky = 1; + if(fpu_cmpli(s,x,4)<0) pz->rounded=1; else pz->rounded = 0; + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfmul.c b/usr/src/lib/libbc/libc/gen/common/_Qfmul.c new file mode 100644 index 0000000000..bd55bedd7c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfmul.c @@ -0,0 +1,183 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "_Qquad.h" +#include "_Qglobals.h" + + +void +_fp_mul(px, py, pz) + unpacked *px, *py, *pz; + +{ + unpacked *pt; + unsigned acc[4]; /* Product accumulator. */ + unsigned i,j,y,*x,s,r,c; + + if ((int) px->fpclass < (int) py->fpclass) { + pt = px; + px = py; + py = pt; + } + /* Now class(x) >= class(y). */ + + *pz = *px; + pz->sign = px->sign ^ py->sign; + + switch (px->fpclass) { + case fp_quiet: + case fp_signaling: + case fp_zero: + return; + case fp_infinity: + if (py->fpclass == fp_zero) { + fpu_error_nan(pz); + pz->fpclass = fp_quiet; + } + return; + case fp_normal: + if (py->fpclass == fp_zero) { + pz->fpclass = fp_zero; + return; + } + } + + /* Now x and y are both normal or subnormal. */ + + x = px->significand; /* save typing */ + + s=r=acc[0]=acc[1]=acc[2]=acc[3]=0; /* intialize acc to zero */ + + y = py->significand[3]; /* py->significand[3] * x */ + if(y!=0) { + j=1; + do { + s |= r; /* shift acc right one bit */ + r = acc[3]&1; + acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1); + acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1); + acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1); + acc[0] = (acc[0]>>1); + if(j&y) { /* bit i of y != 0, add x to acc */ + c = 0; + c = fpu_add3wc(&acc[3],acc[3],x[3],c); + c = fpu_add3wc(&acc[2],acc[2],x[2],c); + c = fpu_add3wc(&acc[1],acc[1],x[1],c); + c = fpu_add3wc(&acc[0],acc[0],x[0],c); + } + j += j; + } while (j!=0); + } + + y = py->significand[2]; /* py->significand[2] * x */ + if(y!=0) { + j=1; + do { + s |= r; /* shift acc right one bit */ + r = acc[3]&1; + acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1); + acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1); + acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1); + acc[0] = (acc[0]>>1); + if(j&y) { /* bit i of y != 0, add x to acc */ + c = 0; + c = fpu_add3wc(&acc[3],acc[3],x[3],c); + c = fpu_add3wc(&acc[2],acc[2],x[2],c); + c = fpu_add3wc(&acc[1],acc[1],x[1],c); + c = fpu_add3wc(&acc[0],acc[0],x[0],c); + } + j += j; + } while (j!=0); + } else { + s |= r|(acc[3]&0x7fffffff); + r = (acc[3]&0x80000000)>>31; + acc[3]=acc[2];acc[2]=acc[1];acc[1]=acc[0];acc[0]=0; + } + + y = py->significand[1]; /* py->significand[1] * x */ + if(y!=0) { + j=1; + do { + s |= r; /* shift acc right one bit */ + r = acc[3]&1; + acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1); + acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1); + acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1); + acc[0] = (acc[0]>>1); + if(j&y) { /* bit i of y != 0, add x to acc */ + c = 0; + c = fpu_add3wc(&acc[3],acc[3],x[3],c); + c = fpu_add3wc(&acc[2],acc[2],x[2],c); + c = fpu_add3wc(&acc[1],acc[1],x[1],c); + c = fpu_add3wc(&acc[0],acc[0],x[0],c); + } + j += j; + } while (j!=0); + } else { + s |= r|(acc[3]&0x7fffffff); + r = (acc[3]&0x80000000)>>31; + acc[3]=acc[2];acc[2]=acc[1];acc[1]=acc[0];acc[0]=0; + } + + /* py->significand[0] * x */ + y = py->significand[0]; /* y is of form 0x0001???? */ + j=1; + do { + s |= r; /* shift acc right one bit */ + r = acc[3]&1; + acc[3] = ((acc[2]&1)<<31)|(acc[3]>>1); + acc[2] = ((acc[1]&1)<<31)|(acc[2]>>1); + acc[1] = ((acc[0]&1)<<31)|(acc[1]>>1); + acc[0] = (acc[0]>>1); + if(j&y) { /* bit i of y != 0, add x to acc */ + c = 0; + c = fpu_add3wc(&acc[3],acc[3],x[3],c); + c = fpu_add3wc(&acc[2],acc[2],x[2],c); + c = fpu_add3wc(&acc[1],acc[1],x[1],c); + c = fpu_add3wc(&acc[0],acc[0],x[0],c); + } + j += j; + } while (j<=y); + + if(acc[0]>=0x20000) { /* right shift one bit to normalize */ + pz->exponent = px->exponent + py->exponent + 1; + pz->sticky = s|r; + pz->rounded = acc[3]&1; + pz->significand[3]=((acc[2]&1)<<31)|(acc[3]>>1); + pz->significand[2]=((acc[1]&1)<<31)|(acc[2]>>1); + pz->significand[1]=((acc[0]&1)<<31)|(acc[1]>>1); + pz->significand[0]=(acc[0]>>1); + } else { + pz->exponent = px->exponent + py->exponent; + pz->sticky = s; + pz->rounded = r; + pz->significand[3]=acc[3]; + pz->significand[2]=acc[2]; + pz->significand[1]=acc[1]; + pz->significand[0]=acc[0]; + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfpack.c b/usr/src/lib/libbc/libc/gen/common/_Qfpack.c new file mode 100644 index 0000000000..f7462d9fc2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfpack.c @@ -0,0 +1,428 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* Pack procedures for Sparc FPU simulator. */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +PRIVATE int +overflow_to_infinity(sign) + int sign; + +/* Returns 1 if overflow should go to infinity, 0 if to max finite. */ + +{ + int inf; + + switch (fp_direction) { + case fp_nearest: + inf = 1; + break; + case fp_tozero: + inf = 0; + break; + case fp_positive: + inf = !sign; + break; + case fp_negative: + inf = sign; + break; + } + return (inf); +} + +PRIVATE void +round(pu) + unpacked *pu; + +/* Round according to current rounding mode. */ + +{ + int increment; /* boolean to indicate round up */ + int sr; + sr = pu->sticky|pu->rounded; + + if (sr == 0) + return; + fpu_set_exception(fp_inexact); + switch (fp_direction) { + case fp_nearest: + increment = pu->rounded; + break; + case fp_tozero: + increment = 0; + break; + case fp_positive: + increment = (pu->sign == 0) & (sr != 0); + break; + case fp_negative: + increment = (pu->sign != 0) & (sr != 0); + break; + } + if (increment) { + pu->significand[3]++; + if (pu->significand[3] == 0) { + pu->significand[2]++; + if (pu->significand[2] == 0) { + pu->significand[1]++; + if (pu->significand[1] == 0) { + pu->significand[0]++; /* rounding carried out */ + if( pu->significand[0] == 0x20000) { + pu->exponent++; + pu->significand[0] = 0x10000; + } + } + } + } + } + if ((fp_direction == fp_nearest) && + (pu->sticky == 0) && increment!=0) { /* ambiguous case */ + pu->significand[3] &= 0xfffffffe; /* force round to even */ + } +} + +PRIVATE void +packinteger(pu, px) + unpacked *pu; /* unpacked result */ + int *px; /* packed integer */ +{ + switch (pu->fpclass) { + case fp_zero: + *px = 0; + break; + case fp_normal: + if (pu->exponent >= 32) + goto overflow; + fpu_rightshift(pu, 112 - pu->exponent); + round(pu); + if (pu->significand[3] >= 0x80000000) + if ((pu->sign == 0)||(pu->significand[3] > 0x80000000)) + goto overflow; + *px = pu->significand[3]; + if (pu->sign) + *px = -*px; + break; + case fp_infinity: + case fp_quiet: + case fp_signaling: +overflow: + if (pu->sign) + *px = 0x80000000; + else + *px = 0x7fffffff; + _fp_current_exceptions &= ~(1 << (int) fp_inexact); + fpu_set_exception(fp_invalid); + break; + } +} + +PRIVATE void +packsingle(pu, px) + unpacked *pu; /* unpacked result */ + single_type *px; /* packed single */ +{ + px->sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + px->exponent = 0; + px->significand = 0; + break; + case fp_infinity: +infinity: + px->exponent = 0xff; + px->significand = 0; + break; + case fp_quiet: + case fp_signaling: + fpu_rightshift(pu, 113-24); + px->exponent = 0xff; + px->significand = 0x400000|(0x3fffff&pu->significand[3]); + break; + case fp_normal: + fpu_rightshift(pu, 113-24); + pu->exponent += SINGLE_BIAS; + if (pu->exponent <= 0) { + px->exponent = 0; + fpu_rightshift(pu, 1 - pu->exponent); + round(pu); + if (pu->significand[3] == 0x800000) { /* rounded + * back up to + * normal */ + px->exponent = 1; + px->significand = 0; + return; + } + if (_fp_current_exceptions & (1 << fp_inexact)) + fpu_set_exception(fp_underflow); + px->significand = 0x7fffff & pu->significand[3]; + return; + } + round(pu); + if (pu->significand[3] == 0x1000000) { /* rounding overflow */ + pu->significand[3] = 0x800000; + pu->exponent += 1; + } + if (pu->exponent >= 0xff) { + fpu_set_exception(fp_overflow); + fpu_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + px->exponent = 0xfe; + px->significand = 0x7fffff; + return; + } + px->exponent = pu->exponent; + px->significand = 0x7fffff & pu->significand[3]; + } +} + +PRIVATE void +packdouble(pu, px, py) + unpacked *pu; /* unpacked result */ + double_type *px; /* packed double */ + unsigned *py; +{ + px->sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + px->exponent = 0; + px->significand = 0; + *py = 0; + break; + case fp_infinity: +infinity: + px->exponent = 0x7ff; + px->significand = 0; + *py = 0; + break; + case fp_quiet: + case fp_signaling: + fpu_rightshift(pu, 113-53); + px->exponent = 0x7ff; + px->significand = 0x80000 | (0x7ffff & pu->significand[2]); + *py = pu->significand[3]; + break; + case fp_normal: + fpu_rightshift(pu, 113-53); + pu->exponent += DOUBLE_BIAS; + if (pu->exponent <= 0) { /* underflow */ + px->exponent = 0; + fpu_rightshift(pu, 1 - pu->exponent); + round(pu); + if (pu->significand[2] == 0x100000) { /* rounded + * back up to + * normal */ + px->exponent = 1; + px->significand = 0; + *py = 0; + return; + } + if (_fp_current_exceptions & (1 << fp_inexact)) + fpu_set_exception(fp_underflow); + px->exponent = 0; + px->significand = 0xfffff & pu->significand[2]; + *py = pu->significand[3]; + return; + } + round(pu); + if (pu->significand[2] == 0x200000) { /* rounding overflow */ + pu->significand[2] = 0x100000; + pu->exponent += 1; + } + if (pu->exponent >= 0x7ff) { /* overflow */ + fpu_set_exception(fp_overflow); + fpu_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + px->exponent = 0x7fe; + px->significand = 0xfffff; + *py = 0xffffffff; + return; + } + px->exponent = pu->exponent; + px->significand = 0xfffff & pu->significand[2]; + *py = pu->significand[3]; + break; + } +} + +PRIVATE void +packextended(pu, px, py, pz, pw) + unpacked *pu; /* unpacked result */ + extended_type *px; /* packed extended */ + unsigned *py, *pz, *pw; +{ + px->sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + px->exponent = 0; + px->significand = 0; + *pz = 0; + *py = 0; + *pw = 0; + break; + case fp_infinity: +infinity: + px->exponent = 0x7fff; + px->significand = 0; + *pz = 0; + *py = 0; + *pw = 0; + break; + case fp_quiet: + case fp_signaling: + px->exponent = 0x7fff; + px->significand = 0x8000 | pu->significand[0]; /* Insure quiet + * nan. */ + *py = pu->significand[1]; + *pz = pu->significand[2]; + *pw = pu->significand[3]; + break; + case fp_normal: + pu->exponent += EXTENDED_BIAS; + if (pu->exponent <= 0) { /* underflow */ + fpu_rightshift(pu, 1-pu->exponent); + round(pu); + if (pu->significand[0] < 0x00010000) { /* not rounded + * back up + * to normal */ + if (_fp_current_exceptions & (1 << fp_inexact)) + fpu_set_exception(fp_underflow); + px->exponent = 0; + } else + px->exponent = 1; + px->significand = pu->significand[0]; + *py = pu->significand[1]; + *pz = pu->significand[2]; + *pw = pu->significand[3]; + return; + } + round(pu); /* rounding overflow handled in round() */ + if (pu->exponent >= 0x7fff) { /* overflow */ + fpu_set_exception(fp_overflow); + fpu_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + px->exponent = 0x7ffe; /* overflow to max norm */ + px->significand = 0xffff; + *py = 0xffffffff; + *pz = 0xffffffff; + *pw = 0xffffffff; + return; + } + px->exponent = pu->exponent; + px->significand = pu->significand[0]; + *py = pu->significand[1]; + *pz = pu->significand[2]; + *pw = pu->significand[3]; + break; + } +} + +void +_fp_pack(pu, n, type) + unpacked *pu; /* unpacked operand */ + int *n; /* output result's address */ + enum fp_op_type type; /* type of datum */ + +{ + switch (type) { + case fp_op_integer: + { + packinteger(pu, n); + break; + } + case fp_op_single: + { + single_type x; + packsingle(pu, &x); + n[0] = *(int*)&x; + break; + } + case fp_op_double: + { + double_type x; + double t=1.0; + int i0,i1; + if((*(int*)&t)!=0) {i0=0;i1=1;} else {i0=1;i1=0;} + packdouble(pu, &x,&n[i1]); + n[i0] = *(int*)&x; + break; + } + case fp_op_extended: + { + extended_type x; + unsigned y, z, w; + unpacked u; + int k; + switch (fp_precision) { /* Implement extended + * rounding precision mode. */ + case fp_single: + { + single_type tx; + packsingle(pu, &tx); + pu = &u; + unpacksingle(pu, tx); + break; + } + case fp_double: + { + double_type tx; + unsigned ty; + packdouble(pu, &tx, &ty); + pu = &u; + unpackdouble(pu, tx, ty); + break; + } + case fp_precision_3: /* rounded to 64 bits */ + { + k = pu->exponent+ EXTENDED_BIAS; + if(k>=0) k = 113-64; + else k = 113-64-k; + fpu_rightshift(pu,113-64); + round(pu); + pu->sticky=pu->rounded=0; + pu->exponent += k; + fpu_normalize(pu); + break; + } + } + { + int i0,i1,i2,i3; + double t = 1.0; + if((*(int*)&t)!=0) {i0=0;i1=1;i2=2;i3=3;} + else {i0=3;i1=2;i2=1;i3=0;} + packextended(pu, &x, &n[i1], &n[i2], &n[i3]); + n[i0] = *(int*)&x; + } + + break; + } + } +} + diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfunpack.c b/usr/src/lib/libbc/libc/gen/common/_Qfunpack.c new file mode 100644 index 0000000000..1e744d94ef --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfunpack.c @@ -0,0 +1,231 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* Unpack procedures for Sparc FPU simulator. */ + +#include "_Qquad.h" +#include "_Qglobals.h" + +PRIVATE void +unpackinteger(pu, x) + unpacked *pu; /* unpacked result */ + int x; /* packed integer */ +{ + unsigned ux; + pu->sticky = pu->rounded = 0; + if (x == 0) { + pu->sign = 0; + pu->fpclass = fp_zero; + } else { + (*pu).sign = x < 0; + (*pu).fpclass = fp_normal; + (*pu).exponent = INTEGER_BIAS; + if(x<0) ux = -x; else ux = x; + (*pu).significand[0] = ux>>15; + (*pu).significand[1] = (ux&0x7fff)<<17; + (*pu).significand[2] = 0; + (*pu).significand[3] = 0; + fpu_normalize(pu); + } +} + +void +unpacksingle(pu, x) + unpacked *pu; /* unpacked result */ + single_type x; /* packed single */ +{ + unsigned u; + pu->sticky = pu->rounded = 0; + u = x.significand; + (*pu).sign = x.sign; + pu->significand[1] = 0; + pu->significand[2] = 0; + pu->significand[3] = 0; + if (x.exponent == 0) { /* zero or sub */ + if (x.significand == 0) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* subnormal */ + pu->fpclass = fp_normal; + pu->exponent = -SINGLE_BIAS-6; + pu->significand[0]=u; + fpu_normalize(pu); + return; + } + } else if (x.exponent == 0xff) { /* inf or nan */ + if (x.significand == 0) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((u & 0x400000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_signaling; + fpu_set_exception(fp_invalid); + } + pu->significand[0] = 0x18000 | (u >> 7); + (*pu).significand[1]=((u&0x7f)<<25); + return; + } + } + (*pu).exponent = x.exponent - SINGLE_BIAS; + (*pu).fpclass = fp_normal; + (*pu).significand[0]=0x10000|(u>>7); + (*pu).significand[1]=((u&0x7f)<<25); +} + +void +unpackdouble(pu, x, y) + unpacked *pu; /* unpacked result */ + double_type x; /* packed double */ + unsigned y; +{ + unsigned u; + pu->sticky = pu->rounded = 0; + u = x.significand; + (*pu).sign = x.sign; + pu->significand[1] = y; + pu->significand[2] = 0; + pu->significand[3] = 0; + if (x.exponent == 0) { /* zero or sub */ + if ((x.significand == 0) && (y == 0)) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* subnormal */ + pu->fpclass = fp_normal; + pu->exponent = -DOUBLE_BIAS-3; + pu->significand[0] = u; + fpu_normalize(pu); + return; + } + } else if (x.exponent == 0x7ff) { /* inf or nan */ + if ((u|y) == 0) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((u & 0x80000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_signaling; + fpu_set_exception(fp_invalid); + } + pu->significand[0] = 0x18000 | (u >> 4); + (*pu).significand[1]=((u&0xf)<<28)|(y>>4); + (*pu).significand[2]=((y&0xf)<<28); + return; + } + } + (*pu).exponent = x.exponent - DOUBLE_BIAS; + (*pu).fpclass = fp_normal; + (*pu).significand[0]=0x10000|(u>>4); + (*pu).significand[1]=((u&0xf)<<28)|(y>>4); + (*pu).significand[2]=((y&0xf)<<28); +} + +PRIVATE void +unpackextended(pu, x, y, z, w) + unpacked *pu; /* unpacked result */ + extended_type x; /* packed extended */ + unsigned y, z, w; +{ + unsigned u; + pu->sticky = pu->rounded = 0; + u = x.significand; + (*pu).sign = x.sign; + (*pu).fpclass = fp_normal; + (*pu).exponent = x.exponent - EXTENDED_BIAS; + (*pu).significand[0] = (x.exponent==0)? u:0x10000|u; + (*pu).significand[1] = y; + (*pu).significand[2] = z; + (*pu).significand[3] = w; + if (x.exponent < 0x7fff) { /* zero, normal, or subnormal */ + if ((z|y|w|pu->significand[0]) == 0) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* normal or subnormal */ + if(x.exponent==0) { + fpu_normalize(pu); + pu->exponent += 1; + } + return; + } + } else { /* inf or nan */ + if ((u|z|y|w) == 0) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((u & 0x00008000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_signaling; + fpu_set_exception(fp_invalid); + } + pu->significand[0] |= 0x8000; /* make quiet */ + return; + } +} +} + +void +_fp_unpack(pu, n, dtype) + unpacked *pu; /* unpacked result */ + int *n; /* input array */ + enum fp_op_type dtype; /* type of datum */ + +{ + switch ((int) dtype) { + case fp_op_integer: + unpackinteger(pu, n[0]); + break; + case fp_op_single: + { + single_type x; + *(int*)&x = n[0]; + unpacksingle(pu, x); + break; + } + case fp_op_double: + { + double_type x; + double t=1.0; int i0,i1; + if((*(int*)&t)!=0) {i0=0;i1=1;} else {i0=1;i1=0;} + *(int*)&x = n[i0]; + unpackdouble(pu, x, n[i1]); + break; + } + case fp_op_extended: + { + extended_type x; + double t=1.0; int i0,i1,i2,i3; + if((*(int*)&t)!=0) {i0=0;i1=1;i2=2;i3=3;} + else {i0=3;i1=2;i2=1;i3=0;} + *(int*)&x = n[i0]; + unpackextended(pu, x, n[i1], n[i2], n[i3]); + break; + } + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/_Qfutility.c b/usr/src/lib/libbc/libc/gen/common/_Qfutility.c new file mode 100644 index 0000000000..ea8503bdf2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qfutility.c @@ -0,0 +1,278 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* Utility functions for Sparc FPU simulator. */ + +#include "_Qquad.h" +#include "_Qglobals.h" + + +void +fpu_normalize(pu) + unpacked *pu; + +/* Normalize a number. Does not affect zeros, infs, or NaNs. */ +/* The number will be normalized to 113 bit extended: + * 0x0001####,0x########,0x########,0x########. + */ + +{ + unsigned u,u0,u1,u2,u3,m,n,k; + u0 = pu->significand[0]; + u1 = pu->significand[1]; + u2 = pu->significand[2]; + u3 = pu->significand[3]; + if ((*pu).fpclass == fp_normal) { + if ((u0|u1|u2|u3)==0) { + (*pu).fpclass = fp_zero; + return; + } + while (u0 == 0) { + u0 = u1; u1=u2; u2=u3; u3=0; + (*pu).exponent = (*pu).exponent - 32; + } + if (u0>=0x20000) { /* u3 should be zero */ + n=1; u = u0>>1; + while(u>=0x20000) {u >>= 1; n += 1;} + m = (1<<n)-1; + k = 32-n; + (*pu).exponent += n; + u3 = ((u2&m)<<k)|(u3>>n); + u2 = ((u1&m)<<k)|(u2>>n); + u1 = ((u0&m)<<k)|(u1>>n); + u0 = u; + } else if(u0<0x10000) { + n=1; u = u0<<1; + while(u<0x10000) {u <<= 1; n += 1;} + k = 32-n; + m = -(1<<k); + (*pu).exponent -= n; + u0 = (u0<<n)|((u1&m)>>k); + u1 = (u1<<n)|((u2&m)>>k); + u2 = (u2<<n)|((u3&m)>>k); + u3 = (u3<<n); + } + pu->significand[0] = u0; + pu->significand[1] = u1; + pu->significand[2] = u2; + pu->significand[3] = u3; + } +} + +void +fpu_rightshift(pu, n) + unpacked *pu; + int n; + +/* Right shift significand sticky by n bits. */ + +{ + unsigned m,k,j,u0,u1,u2,u3; + if (n > 113) { /* drastic */ + if (((*pu).significand[0] | (*pu).significand[1] + | (*pu).significand[2] | (*pu).significand[3]) == 0){ + /* really zero */ + pu->fpclass = fp_zero; + return; + } else { + pu->rounded = 0; + pu->sticky = 1; + pu->significand[3] = 0; + pu->significand[2] = 0; + pu->significand[1] = 0; + pu->significand[0] = 0; + return; + } + } + while (n >= 32) { /* big shift */ + pu->sticky |= pu->rounded | (pu->significand[3]&0x7fffffff); + pu->rounded = (*pu).significand[3]>>31; + (*pu).significand[3] = (*pu).significand[2]; + (*pu).significand[2] = (*pu).significand[1]; + (*pu).significand[1] = (*pu).significand[0]; + (*pu).significand[0] = 0; + n -= 32; + } + if (n > 0) { /* small shift */ + u0 = pu->significand[0]; + u1 = pu->significand[1]; + u2 = pu->significand[2]; + u3 = pu->significand[3]; + m = (1<<n)-1; + k = 32 - n; + j = (1<<(n-1))-1; + pu->sticky |= pu->rounded | (u3&j); + pu->rounded = (u3&m)>>(n-1); + pu->significand[3] = ((u2&m)<<k)|(u3>>n); + pu->significand[2] = ((u1&m)<<k)|(u2>>n); + pu->significand[1] = ((u0&m)<<k)|(u1>>n); + pu->significand[0] = u0>>n; + } +} + +void +fpu_set_exception(ex) + enum fp_exception_type ex; + +/* Set the exception bit in the current exception register. */ + +{ + _fp_current_exceptions |= 1 << (int) ex; +} + +void +fpu_error_nan(pu) + unpacked *pu; + +{ /* Set invalid exception and error nan in *pu */ + + fpu_set_exception(fp_invalid); + pu->significand[0] = 0x7fffffff|((pu->sign)<<31); + pu->significand[1] = 0xffffffff; + pu->significand[2] = 0xffffffff; + pu->significand[3] = 0xffffffff; +} + +/* the following fpu_add3wc should be inlined as + * .inline _fpu_add3wc,3 + * ld [%o1],%o4 ! sum = x + * addcc -1,%o3,%g0 ! restore last carry in cc reg + * addxcc %o4,%o2,%o4 ! sum = sum + y + last carry + * st %o4,[%o0] ! *z = sum + * addx %g0,%g0,%o0 ! return new carry + * .end + */ + +unsigned +fpu_add3wc(z,x,y,carry) + unsigned *z,x,y,carry; +{ /* *z = x + y + carry, set carry; */ + if(carry==0) { + *z = x+y; + return (*z<y); + } else { + *z = x+y+1; + return (*z<=y); + } +} + +/* the following fpu_sub3wc should be inlined as + * .inline _fpu_sub3wc,3 + * ld [%o1],%o4 ! sum = *x + * addcc -1,%o3,%g0 ! restore last carry in cc reg + * subxcc %o4,%o2,%o4 ! sum = sum - y - last carry + * st %o4,[%o0] ! *x = sum + * addx %g0,%g0,%o0 ! return new carry + * .end + */ + +unsigned +fpu_sub3wc(z,x,y,carry) + unsigned *z,x,y,carry; +{ /* *z = x - y - carry, set carry; */ + if(carry==0) { + *z = x-y; + return (*z>x); + } else { + *z = x-y-1; + return (*z>=x); + } +} + +/* the following fpu_neg2wc should be inlined as + * .inline _fpu_neg2wc,2 + * ld [%o1],%o3 ! tmp = *x + * addcc -1,%o2,%g0 ! restore last carry in cc reg + * subxcc %g0,%o3,%o3 ! sum = 0 - tmp - last carry + * st %o3,[%o0] ! *x = sum + * addx %g0,%g0,%o0 ! return new carry + * .end + */ + +unsigned +fpu_neg2wc(z,x,carry) + unsigned *z,x,carry; +{ /* *x = 0 - *x - carry, set carry; */ + if(carry==0) { + *z = -x; + return ((*z)!=0); + } else { + *z = -x-1; + return 1; + } +} + +int +fpu_cmpli(x,y,n) + unsigned x[],y[]; int n; +{ /* compare two unsigned array */ + int i; + i=0; + while(i<n) { + if(x[i]>y[i]) return 1; + else if(x[i]<y[i]) return -1; + i++; + } + return 0; +} + +#ifdef DEBUG +void +display_unpacked(pu) + unpacked *pu; + +/* Print out unpacked record. */ + +{ + (void) printf(" unpacked "); + if (pu->sign) + (void) printf("-"); + else + (void) printf("+"); + + switch (pu->fpclass) { + case fp_zero: + (void) printf("0 "); + break; + case fp_normal: + (void) printf("normal"); + break; + case fp_infinity: + (void) printf("Inf "); + break; + case fp_quiet: + case fp_signaling: + (void) printf("nan "); + break; + } + (void) printf(" %X %X %X %X (%X,%X) exponent %X \n", + pu->significand[0], pu->significand[1],pu->significand[2], + pu->significand[3], (pu->rounded!=0), + (pu->sticky!=0),pu->exponent); +} +#endif + diff --git a/usr/src/lib/libbc/libc/gen/common/_Qglobals.h b/usr/src/lib/libbc/libc/gen/common/_Qglobals.h new file mode 100644 index 0000000000..bd97672569 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qglobals.h @@ -0,0 +1,186 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + + /* Sparc floating-point simulator PRIVATE include file. */ + +#ifdef KERNEL +#include <sys/types.h> +#include <vm/seg.h> +#endif + + /* PRIVATE CONSTANTS */ + +#define INTEGER_BIAS 31 +#define SINGLE_BIAS 127 +#define DOUBLE_BIAS 1023 +#define EXTENDED_BIAS 16383 + + /* PRIVATE TYPES */ + +#ifdef DEBUG +#define PRIVATE +#else +#define PRIVATE static +#endif + +#ifdef KERNEL +#define DOUBLE_E(n) (n & 0xfffe) /* More significant word of double. */ +#define DOUBLE_F(n) (1+DOUBLE_E(n)) /* Less significant word of double. */ +#define EXTENDED_E(n) (n & 0xfffc) /* Sign/exponent/significand of extended. */ +#define EXTENDED_F(n) (1+EXTENDED_E(n)) /* 2nd word of extended significand. */ +#define EXTENDED_G(n) (2+EXTENDED_E(n)) /* 3rd word of extended significand. */ +#define EXTENDED_H(n) (3+EXTENDED_E(n)) /* 4th word of extended significand. */ +#endif + +typedef + struct + { + int sign ; + enum fp_class_type fpclass ; + int exponent ; /* Unbiased exponent. */ + unsigned significand[4] ; /* Four significand word . */ + int rounded; /* rounded bit */ + int sticky; /* stick bit */ + } + unpacked ; + + /* PRIVATE GLOBAL VARIABLES */ + +enum fp_direction_type fp_direction ; /* Current rounding direction. */ +enum fp_precision_type fp_precision ; /* Current extended rounding precision. */ + +unsigned _fp_current_exceptions ; /* Current floating-point exceptions. */ + +#ifdef KERNEL +struct fpu * _fp_current_pfregs ; /* Current pointer to stored f registers. */ + +void (* _fp_current_read_freg) () ; /* Routine to use to read f registers. */ +void (* _fp_current_write_freg) () ; /* Routine to use to write f registers. */ + +int fptrapcode ; /* Last code for fp trap. */ +char *fptrapaddr ; /* Last addr for fp trap. */ +enum seg_rw fptraprw ; /* Last fp fault read/write flag */ + + /* PRIVATE FUNCTIONS */ + + /* pfreg routines use "physical" FPU registers. */ + +extern void _fp_read_pfreg ( /* pf, n */ ) ; + +/* FPU_REGS_TYPE *pf /* Where to put current %fn. */ +/* unsigned n ; /* Want to read register n. */ + +extern void _fp_write_pfreg ( /* pf, n */ ) ; + +/* FPU_REGS_TYPE *pf /* Where to get new %fn. */ +/* unsigned n ; /* Want to read register n. */ + + /* vfreg routines use "virtual" FPU registers at *_fp_current_pfregs. */ + +extern void _fp_read_vfreg ( /* pf, n */ ) ; + +/* FPU_REGS_TYPE *pf /* Where to put current %fn. */ +/* unsigned n ; /* Want to read register n. */ + +extern void _fp_write_vfreg ( /* pf, n */ ) ; + +/* FPU_REGS_TYPE *pf /* Where to get new %fn. */ +/* unsigned n ; /* Want to read register n. */ + +extern enum ftt_type +_fp_iu_simulator( /* pinst, pregs, pwindow, pfpu */ ) ; +/* fp_inst_type pinst; /* FPU instruction to simulate. */ +/* struct regs *pregs; /* Pointer to PCB image of registers. */ +/* struct window *pwindow;/* Pointer to locals and ins. */ +/* struct fpu *pfpu; /* Pointer to FPU register block. */ +#endif + +extern void _fp_unpack ( /* pu, n, type */ ) ; +/* unpacked *pu ; /* unpacked result */ +/* unsigned n ; /* register where data starts */ +/* fp_op_type type ; /* type of datum */ + +extern void _fp_pack ( /* pu, n, type */) ; +/* unpacked *pu ; /* unpacked result */ +/* unsigned n ; /* register where data starts */ +/* fp_op_type type ; /* type of datum */ + +extern void _fp_unpack_word ( /* pu, n, type */ ) ; +/* unsigned *pu ; /* unpacked result */ +/* unsigned n ; /* register where data starts */ + +extern void _fp_pack_word ( /* pu, n, type */) ; +/* unsigned *pu ; /* unpacked result */ +/* unsigned n ; /* register where data starts */ + +extern void fpu_normalize (/* pu */) ; +/* unpacked *pu ; /* unpacked operand and result */ + +extern void fpu_rightshift (/* pu, n */) ; +/* unpacked *pu ; unsigned n ; */ +/* Right shift significand sticky by n bits. */ + +extern unsigned fpu_add3wc (/* z,x,y,c */) ; +/* unsigned *z,x,y,c; /* *z = x+y+carry; return new carry */ + +extern unsigned fpu_sub3wc (/* z,x,y,c */) ; +/* unsigned *z,x,y,c; /* *z = x-y-carry; return new carry */ + +extern unsigned fpu_neg2wc (/* x,c */) ; +/* unsigned *z,x,c; /* *z = 0-x-carry; return new carry */ + +extern int fpu_cmpli (/* x,y,n */) ; +/* unsigned x[],y[],n; /* n-word compare */ + +extern void fpu_set_exception(/* ex */) ; +/* enum fp_exception_type ex ; /* exception to be set in curexcep */ + +extern void fpu_error_nan(/* pu */) ; +/* unpacked *pu ; /* Set invalid exception and error nan in *pu */ + +extern void unpacksingle (/* pu, x */) ; +/* unpacked *pu; /* packed result */ +/* single_type x; /* packed single */ + +extern void unpackdouble (/* pu, x, y */) ; +/* unpacked *pu; /* unpacked result */ +/* double_type x; /* packed double */ +/* unsigned y; */ + +extern enum fcc_type _fp_compare (/* px, py */) ; + +extern void _fp_add(/* px, py, pz */) ; +extern void _fp_sub(/* px, py, pz */) ; +extern void _fp_mul(/* px, py, pz */) ; +extern void _fp_div(/* px, py, pz */) ; +extern void _fp_sqrt(/* px, pz */) ; + +#ifdef KERNEL +extern enum ftt_type _fp_write_word ( /* caddr_t, value */ ) ; +extern enum ftt_type _fp_read_word ( /* caddr_t, pvalue */ ) ; +extern enum ftt_type read_iureg ( /* n, pregs, pwindow, pvalue */ ); +#endif diff --git a/usr/src/lib/libbc/libc/gen/common/_Qquad.h b/usr/src/lib/libbc/libc/gen/common/_Qquad.h new file mode 100644 index 0000000000..81f212e8da --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_Qquad.h @@ -0,0 +1,207 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1989 by Sun Microsystems, Inc. + */ + +/* + * Header file for long double == quadruple-precision run-time support. C + * "long double" and Fortran "real*16" are implemented identically on all + * architectures. + * + * Thus the quad run-time support is intentionally coded as C-callable routines + * for portability. + * + * Mixed-case identifiers with leading _ are intentionally chosen to minimize + * conflicts with user-defined C and Fortran identifiers. + */ + +#include <math.h> /* to get float macros */ + +#ifndef _QUAD_INCLUDED_ +#define _QUAD_INCLUDED_ /* Render harmless multiple inclusions. */ + + +#ifdef __STDC__ /* are we there yet */ + +#define QUAD long double +#define SINGLE float +#define SINGLERESULT float +#define RETURNSINGLE(x) return x +#define ASSIGNSINGLERESULT(x,y) x = y + +#else + +struct quadstruct { + unsigned parts[4] +}; + +#define QUAD struct quadstruct + +#define SINGLE FLOATPARAMETER +#define SINGLERESULT FLOATFUNCTIONTYPE +#define RETURNSINGLE(x) RETURNFLOAT(x) +#define ASSIGNSINGLERESULT(x,y) {SINGLERESULT _kug = y; *(int *)&x = *(int*)&_kug;} + +#endif + +/****** Phase I Quad support: C run-time in libc/crt *****/ + +extern QUAD _Q_neg( /* QUAD x */ ); /* returns -x */ +extern QUAD _Q_add( /* QUAD x, y */ ); /* returns x + y */ +extern QUAD _Q_sub( /* QUAD x, y */ ); /* returns x - y */ +extern QUAD _Q_mul( /* QUAD x, y */ ); /* returns x * y */ +extern QUAD _Q_div( /* QUAD x, y */ ); /* returns x / y */ +extern QUAD _Q_sqrt( /* QUAD x */ ); /* return sqrt(x) */ +extern enum fcc_type + _Q_cmp( /* QUAD x, y */ ); /* x compare y , exception + * only on signaling NaN */ +extern enum fcc_type + _Q_cmpe( /* QUAD x, y */ ); /* x compare y , exception + * on quiet NaN */ +extern int _Q_feq( /* QUAD x, y */ ); /* return TRUE if x == y */ +extern int _Q_fne( /* QUAD x, y */ ); /* return TRUE if x != y */ +extern int _Q_fgt( /* QUAD x, y */ ); /* return TRUE if x > y */ +extern int _Q_fge( /* QUAD x, y */ ); /* return TRUE if x >= y */ +extern int _Q_flt( /* QUAD x, y */ ); /* return TRUE if x < y */ +extern int _Q_fle( /* QUAD x, y */ ); /* return TRUE if x <= y */ + +/* Conversion routines are pretty straightforward. */ + +extern QUAD _Q_stoq( /* SINGLE s */ ); +extern QUAD _Q_dtoq( /* double d */ ); +extern QUAD _Q_itoq( /* int i */ ); +extern QUAD _Q_utoq( /* unsigned u */ ); +extern SINGLERESULT _Q_qtos( /* QUAD x */ ); +extern double _Q_qtod( /* QUAD x */ ); +extern int _Q_qtoi( /* QUAD x */ ); +extern unsigned _Q_qtou( /* QUAD x */ ); + +/****** + Phase I Quad support: scanf/printf support in libc/gen/common +*****/ + +extern void +decimal_to_longdouble( /* QUAD *px ; decimal_mode *pm; + * decimal_record *pd; + fp_exception_field_type *ps; */ ); + +extern void +longdouble_to_decimal( /* QUAD *px ; decimal_mode *pm; + * decimal_record *pd; + fp_exception_field_type *ps; */ ); + +#ifdef sparc +enum fcc_type /* relationships for loading into cc */ + { + fcc_equal = 0, + fcc_less = 1, + fcc_greater = 2, + fcc_unordered = 3 + } ; +#endif +#ifdef i386 +enum fcc_type /* relationships for loading into cc */ + { + fcc_equal = 64, + fcc_less = 1, + fcc_greater = 0, + fcc_unordered = 69 + } ; +#endif +#ifdef mc68000 +enum fcc_type /* relationships for loading into cc */ + { + fcc_equal = 4, + fcc_less = 25, + fcc_greater = 0, + fcc_unordered = 2 + } ; +#endif + +#ifdef i386 +typedef /* FPU register viewed as single components. */ + struct + { + unsigned significand : 23 ; + unsigned exponent : 8 ; + unsigned sign : 1 ; + } + single_type ; + +typedef /* FPU register viewed as double components. */ + struct + { + unsigned significand : 20 ; + unsigned exponent : 11 ; + unsigned sign : 1 ; + } + double_type ; +typedef /* FPU register viewed as extended components. */ + struct + { + unsigned significand : 16 ; + unsigned exponent : 15 ; + unsigned sign : 1 ; + } + extended_type ; +#else +typedef /* FPU register viewed as single components. */ + struct + { + unsigned sign : 1 ; + unsigned exponent : 8 ; + unsigned significand : 23 ; + } + single_type ; + +typedef /* FPU register viewed as double components. */ + struct + { + unsigned sign : 1 ; + unsigned exponent : 11 ; + unsigned significand : 20 ; + } + double_type ; +typedef /* FPU register viewed as extended components. */ + struct + { + unsigned sign : 1 ; + unsigned exponent : 15 ; + unsigned significand : 16 ; + } + extended_type ; +#endif + + +enum fp_op_type /* Type specifiers in FPU instructions. */ + { + fp_op_integer = 0, /* Not in hardware, but convenient to define. */ + fp_op_single = 1, + fp_op_double = 2, + fp_op_extended = 3 + } ; + + +#endif /* QUAD_INCLUDED */ diff --git a/usr/src/lib/libbc/libc/gen/common/_base_S.c b/usr/src/lib/libbc/libc/gen/common/_base_S.c new file mode 100644 index 0000000000..429a078539 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_base_S.c @@ -0,0 +1,126 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +/* Fundamental utilities for base conversion that should be recoded as assembly language subprograms or as inline expansion templates. */ + +void +_fourdigitsquick(t, d) + short unsigned t; + char *d; + +/* Converts t < 10000 into four ascii digits at *pc. */ + +{ + register short i; + + i = 3; + do { + d[i] = '0' + t % 10; + t = t / 10; + } + while (--i != -1); +} + +void +_multiply_base_two_vector(n, px, py, product) + short unsigned n, *py; + _BIG_FLOAT_DIGIT *px, product[3]; + +{ + /* + * Given xi and yi, base 2**16 vectors of length n, computes dot + * product + * + * sum (i=0,n-1) of x[i]*y[n-1-i] + * + * Product may fill as many as three short-unsigned buckets. Product[0] + * is least significant, product[2] most. + */ + + unsigned long acc, p; + short unsigned carry; + int i; + + acc = 0; + carry = 0; + for (i = 0; i < n; i++) { + p=_umac(px[i],py[n - 1 - i],acc); + if (p < acc) + carry++; + acc = p; + } + product[0] = (_BIG_FLOAT_DIGIT) (acc & 0xffff); + product[1] = (_BIG_FLOAT_DIGIT) (acc >> 16); + product[2] = (_BIG_FLOAT_DIGIT) (carry); +} + +void +_multiply_base_ten_vector(n, px, py, product) + short unsigned n, *py; + _BIG_FLOAT_DIGIT *px, product[3]; + +{ + /* + * Given xi and yi, base 10**4 vectors of length n, computes dot + * product + * + * sum (i=0,n-1) of x[i]*y[n-1-i] + * + * Product may fill as many as three short-unsigned buckets. Product[0] + * is least significant, product[2] most. + */ + +#define ABASE 3000000000 /* Base of accumulator. */ + + unsigned long acc; + short unsigned carry; + int i; + + acc = 0; + carry = 0; + for (i = 0; i < n; i++) { + acc=_umac(px[i],py[n - 1 - i],acc); + if (acc >= (unsigned long) ABASE) { + carry++; + acc -= ABASE; + } + } + /* + NOTE: because + acc * <= ABASE-1, + acc/10000 <= 299999 + which would overflow a short unsigned + */ + product[0] = (_BIG_FLOAT_DIGIT) (acc % 10000); + acc /= 10000; + product[1] = (_BIG_FLOAT_DIGIT) (acc % 10000); + acc /= 10000; + product[2] = (_BIG_FLOAT_DIGIT) (acc + (ABASE / 100000000) * carry); +} + diff --git a/usr/src/lib/libbc/libc/gen/common/_base_il.c b/usr/src/lib/libbc/libc/gen/common/_base_il.c new file mode 100644 index 0000000000..13b1a51d89 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_base_il.c @@ -0,0 +1,104 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +/* The following should be coded as inline expansion templates. */ + +/* + * Fundamental utilities that multiply two shorts into a unsigned long, add + * carry, compute quotient and remainder in underlying base, and return + * quo<<16 | rem as a unsigned long. + */ + +/* + * C compilers tend to generate bad code - forcing full unsigned long by + * unsigned long multiplies when what is really wanted is the unsigned long + * product of half-long operands. Similarly the quotient and remainder are + * all half-long. So these functions should really be implemented by inline + * expansion templates. + */ + +unsigned long +_umac(x, y, c) /* p = x * y + c ; return p */ + _BIG_FLOAT_DIGIT x, y; + unsigned long c; +{ + return x * (unsigned long) y + c; +} + +unsigned long +_carry_in_b10000(x, c) /* p = x + c ; return (p/10000 << 16 | + * p%10000) */ + _BIG_FLOAT_DIGIT x; + long unsigned c; +{ + unsigned long p = x + c ; + + return ((p / 10000) << 16) | (p % 10000); +} + +void +_carry_propagate_two(carry, psignificand) + unsigned long carry; + _BIG_FLOAT_DIGIT *psignificand; +{ + /* + * Propagate carries in a base-2**16 significand. + */ + + long unsigned p; + int j; + + j = 0; + while (carry != 0) { + p = _carry_in_b65536(psignificand[j],carry); + psignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } +} + +void +_carry_propagate_ten(carry, psignificand) + unsigned long carry; + _BIG_FLOAT_DIGIT *psignificand; +{ + /* + * Propagate carries in a base-10**4 significand. + */ + + int j; + unsigned long p; + + j = 0; + while (carry != 0) { + p = _carry_in_b10000(psignificand[j],carry); + psignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } +} + diff --git a/usr/src/lib/libbc/libc/gen/common/_base_sup.c b/usr/src/lib/libbc/libc/gen/common/_base_sup.c new file mode 100644 index 0000000000..3ca8e5f3ac --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_base_sup.c @@ -0,0 +1,321 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +#ifdef DEBUG + +void +_display_big_float(pbf, base) + _big_float *pbf; + unsigned base; + +{ + int i; + + for (i = 0; i < pbf->blength; i++) { + switch (base) { + case 2: + printf(" + %d * 2** %d", pbf->bsignificand[i], (16 * i + pbf->bexponent)); + break; + case 10: + printf(" + %d * 10** %d", pbf->bsignificand[i], (4 * i + pbf->bexponent)); + break; + } + if ((i % 4) == 3) + printf("\n"); + } + printf("\n"); +} + +#endif + +void +_integerstring_to_big_decimal(ds, ndigs, nzin, pnzout, pd) + char ds[]; +unsigned ndigs, nzin, *pnzout; +_big_float *pd; + +{ + /* + * Convert ndigs decimal digits from ds, and up to 3 trailing zeros, + * into a decimal big_float in *pd. nzin tells how many implicit + * trailing zeros may be used, while *pnzout tells how many were + * actually absorbed. Up to 3 are used if available so that + * (ndigs+*pnzout) % 4 = 0. + */ + + int extras, taken, id, ids; + +#ifdef DEBUG + printf(" _integerstring_to_big_decimal: ndigs %d nzin %d ds %s \n", ndigs, nzin, ds); +#endif + + /* Compute how many trailing zeros we're going to put in *pd. */ + + extras = ndigs % 4; + if ((extras > 0) && (nzin != 0)) { + taken = 4 - extras; + if (taken > nzin) + taken = nzin; + } else + taken = 0; + + *pnzout = nzin - taken; + +#define IDIGIT(i) ((i < 0) ? 0 : ((i < ndigs) ? (ds[i] - '0') : 0)) + + pd->bexponent = 0; + pd->blength = (ndigs + taken + 3) / 4; + + ids = (ndigs + taken) - 4 * pd->blength; + id = pd->blength - 1; + +#ifdef DEBUG + printf(" _integerstring_to_big_decimal exponent %d ids %d id %d \n", pd->bexponent, ids, id); +#endif + + pd->bsignificand[id] = 1000 * IDIGIT(ids) + 100 * IDIGIT(ids + 1) + 10 * IDIGIT(ids + 2) + IDIGIT(ids + 3); + ids += 4; + + for (; ids < (int) (ndigs + taken - 4); ids += 4) { /* Additional digits to + * be found. Main loop. */ + id--; + pd->bsignificand[id] = 1000 * ds[ids] + 100 * ds[ids + 1] + 10 * ds[ids + 2] + ds[ids + 3] - 1111 * '0'; + } + +#ifdef DEBUG + assert((id == 1) || (id == 0)); +#endif + if (id != 0) + pd->bsignificand[0] = 1000 * IDIGIT(ids) + 100 * IDIGIT(ids + 1) + 10 * IDIGIT(ids + 2) + IDIGIT(ids + 3); + +#ifdef DEBUG + printf(" _integerstring_to_big_decimal: "); + _display_big_float(pd, 10); +#endif +} + +void +_fractionstring_to_big_decimal(ds, ndigs, nzin, pbf) + char ds[]; +unsigned ndigs, nzin; +_big_float *pbf; + +{ + /* + * Converts a decimal string containing an implicit point, nzin + * leading implicit zeros, and ndigs explicit digits, into a big + * float. + */ + + int ids, ibf; + +#ifdef DEBUG + printf(" _fractionstring_to_big_decimal ndigs %d nzin %d s %s \n", ndigs, nzin, ds); +#endif + + pbf->bexponent = -(int) (nzin + ndigs); + pbf->blength = (ndigs + 3) / 4; + + ids = nzin + ndigs - 4 * pbf->blength; + ibf = pbf->blength - 1; + +#ifdef DEBUG + printf(" _fractionstring_to_big_decimal exponent %d ids %d ibf %d \n", pbf->bexponent, ids, ibf); +#endif + +#define FDIGIT(i) ((i < nzin) ? 0 : ((i < (nzin+ndigs)) ? (ds[i-nzin] - '0') : 0)) + + pbf->bsignificand[ibf] = 1000 * FDIGIT(ids) + 100 * FDIGIT(ids + 1) + 10 * FDIGIT(ids + 2) + FDIGIT(ids + 3); + ids += 4; + + for (; ids < (int) (nzin + ndigs - 4); ids += 4) { /* Additional digits to + * be found. Main loop. */ + ibf--; + pbf->bsignificand[ibf] = 1000 * ds[ids - nzin] + 100 * ds[ids + 1 - nzin] + 10 * ds[ids + 2 - nzin] + ds[ids + 3 - nzin] - 1111 * '0'; + } + + if (ibf > 0) { +#ifdef DEBUG + assert(ibf == 1); +#endif + pbf->bsignificand[0] = 1000 * FDIGIT(ids) + 100 * FDIGIT(ids + 1) + 10 * FDIGIT(ids + 2) + FDIGIT(ids + 3); + } else { +#ifdef DEBUG + assert(ibf == 0); +#endif + } + +#ifdef DEBUG + printf(" _fractionstring_to_big_decimal: "); + _display_big_float(pbf, 10); +#endif +} + +void +_mul_10000short(pbf, carry) + _big_float *pbf; + long unsigned carry; +{ + int j; + long unsigned p; + + for (j = 0; j < pbf->blength; j++) { + p = _prod_10000_b65536(pbf->bsignificand[j], carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + while (carry != 0) { + p = _carry_out_b10000(carry); + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + pbf->blength = j; +} + +void +_big_decimal_to_big_binary(pd, pb) + _big_float *pb, *pd; + +{ + /* Convert _big_float from decimal form to binary form. */ + + int id, idbound; + _BIG_FLOAT_DIGIT sticky, carry; + _BIG_FLOAT_DIGIT multiplier; + +#ifdef DEBUG + assert(pd->bexponent >= -3); + assert(pd->bexponent <= 3); +#endif + pb->bexponent = 0; + pb->blength = 1; + id = pd->blength - 1; + if ((id == 0) && (pd->bexponent < 0)) { + pb->bsignificand[0] = 0; + } else { + pb->bsignificand[0] = pd->bsignificand[id--]; + idbound = (pd->bexponent < 0) ? 1 : 0; /* How far to carry next + * for loop depends on + * whether last digit + * requires special + * treatment. */ + for (; id >= idbound; id--) { + _mul_10000short(pb, (long unsigned) pd->bsignificand[id]); + } + } + if (pd->bexponent < 0) {/* Have to save some integer bits, discard + * and stick some fraction bits at the end. */ +#ifdef DEBUG + assert(id == 0); +#endif + sticky = 0; + carry = pd->bsignificand[0]; + multiplier = 10000; + switch (pd->bexponent) { + case -1: + sticky = carry % 10; + carry /= 10; + multiplier = 1000; + break; + case -2: + sticky = carry % 100; + carry /= 100; + multiplier = 100; + break; + case -3: + sticky = carry % 1000; + carry /= 1000; + multiplier = 10; + break; + } + _multiply_base_two(pb, multiplier, (long unsigned) carry); + if (sticky != 0) + pb->bsignificand[0] |= 1; /* Save lost bits. */ + } else if (pd->bexponent > 0) { /* Have to append some zeros. */ + switch (pd->bexponent) { + case 1: + multiplier = 10; + break; + case 2: + multiplier = 100; + break; + case 3: + multiplier = 1000; + break; + } + carry = 0; + _multiply_base_two(pb, multiplier, (long unsigned) carry); + } +#ifdef DEBUG + printf(" _big_decimal_to_big_binary "); + _display_big_float(pb, 2); +#endif +} + +_big_binary_to_unpacked(pb, pu) + _big_float *pb; + unpacked *pu; + +{ + /* Convert a binary big_float to a binary_unpacked. */ + + int ib, iu; + +#ifdef DEBUG + assert(pb->bsignificand[pb->blength - 1] != 0); /* Assert pb is + * normalized. */ +#endif + + iu = 0; + for (ib = pb->blength - 1; ((ib - 1) >= 0) && (iu < UNPACKED_SIZE); ib -= 2) { + pu->significand[iu++] = pb->bsignificand[ib] << 16 | pb->bsignificand[ib - 1]; + } + if (iu < UNPACKED_SIZE) { /* The big float fits in the unpacked + * with no rounding. */ + if (ib == 0) + pu->significand[iu++] = pb->bsignificand[ib] << 16; + for (; iu < UNPACKED_SIZE; iu++) + pu->significand[iu] = 0; + } else { /* The big float is too big; chop, stick, and + * normalize. */ + while (pb->bsignificand[ib] == 0) + ib--; + if (ib >= 0) + pu->significand[UNPACKED_SIZE - 1] |= 1; /* Stick lsb if nonzero + * found. */ + } + + pu->exponent = 16 * pb->blength + pb->bexponent - 1; + _fp_normalize(pu); + +#ifdef DEBUG + printf(" _big_binary_to_unpacked \n"); + _display_unpacked(pu); +#endif +} diff --git a/usr/src/lib/libbc/libc/gen/common/_big_power.c b/usr/src/lib/libbc/libc/gen/common/_big_power.c new file mode 100644 index 0000000000..994bcdc092 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_big_power.c @@ -0,0 +1,1772 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +unsigned short _max_big_powers_ten = 1260; +unsigned short _big_powers_ten[] = {1, /* begin powers of 10000 in + * base 65536 */ + /* 10000**90 = 65536**22 * */ 24832, 26544, 2586, 53761, 57792, 53253, 29499, 56082, + 11839, 41887, 40418, 25010, 56546, 10851, 1212, 37926, + 54683, 24944, 9622, 49891, 30137, 5131, 11297, 7965, + 27232, 47123, 15266, 35282, 32115, 24817, 55263, 50890, + 57131, 1641, 34615, 9400, 1773, 26259, 28395, 6473, + 56175, 37773, 33397, 24180, 39478, 50542, 46897, 13968, + 17093, 51240, 31118, 9390, 3806, /* * 65536**74 */ + /* 10000**180 = 65536**45 * */ 33985, 7059, 50023, 49495, 50123, 42743, 46480, 57582, + 11318, 19673, 45663, 3344, 38612, 23984, 46968, 53347, + 1637, 11314, 39569, 11385, 46514, 18737, 254, 8488, + 51985, 44900, 30372, 57670, 35, 2423, 21277, 52736, + 17783, 36546, 57005, 52994, 11764, 34186, 38967, 29573, + 31609, 52884, 35484, 5862, 37331, 46285, 3552, 17166, + 23884, 16123, 63828, 64220, 40233, 60185, 35113, 44957, + 62568, 31869, 62842, 20359, 37122, 26110, 39645, 20711, + 5066, 62485, 7570, 43880, 25252, 32872, 25424, 17843, + 18779, 28712, 52721, 12061, 37011, 17182, 18688, 41694, + 9744, 49728, 27156, 3092, 40688, 48751, 18433, 52160, + 33601, 24318, 57448, 65020, 26274, 17344, 47654, 41401, + 62950, 31535, 27325, 4701, 11581, 64161, 47399, 3270, + 221, /* * 65536**149 */ + /* 10000**270 = 65536**67 * */ 8448, 53501, 26337, 31473, 40957, 40631, 48909, 53457, + 20735, 15028, 5789, 54161, 14411, 54948, 58612, 16703, + 60933, 37416, 13759, 21647, 15992, 8158, 21322, 49916, + 50899, 10500, 61546, 64808, 24885, 47894, 22543, 7780, + 30293, 45924, 12217, 38801, 56975, 28948, 9918, 42159, + 64774, 9810, 51572, 22988, 21827, 9461, 13137, 48930, + 33891, 51044, 37035, 25332, 1280, 56459, 12584, 48754, + 40019, 43829, 8962, 15530, 62271, 18344, 6657, 19593, + 44745, 58787, 40668, 52192, 32657, 12973, 31749, 56817, + 44085, 36894, 57738, 47056, 63832, 3276, 5478, 58665, + 57346, 40249, 28227, 21581, 12301, 31946, 358, 8638, + 19457, 56089, 7233, 5275, 49953, 53412, 34142, 32827, + 37650, 65359, 31247, 34120, 46664, 57489, 20280, 30130, + 28614, 21249, 30833, 40373, 44196, 8194, 36189, 58466, + 2574, 44938, 8814, 109, 18128, 7521, 47937, 57918, + 37532, 54663, 2577, 9044, 22665, 25537, 10764, 19087, + 7004, 2179, 41422, 5651, 26207, 17993, 50256, 38597, + 3449, 61115, 20807, 44005, 28834, 13215, 7913, 53059, + 4484, 48600, 17162, 35297, 4759, 49174, 43511, 60182, + 5836, 31015, 22479, 40680, 54915, 12, /* * 65536**224 */ + /* 10000**360 = 65536**90 * */ 39297, 28797, 19536, 11545, 64015, 52591, 13876, 58921, + 23682, 1986, 56989, 18252, 21209, 33745, 52547, 51178, + 2782, 19350, 6109, 37173, 53626, 3048, 1461, 55725, + 51369, 18035, 53937, 17798, 33511, 50816, 46721, 45035, + 58118, 27037, 24312, 45764, 42900, 63148, 16576, 11767, + 46031, 6789, 47345, 858, 43692, 25905, 7147, 29400, + 28424, 54349, 52149, 60542, 63221, 7749, 51852, 6952, + 25762, 29494, 20486, 45960, 32833, 26932, 18753, 55669, + 15583, 21202, 32441, 16038, 60580, 44361, 9748, 61294, + 59477, 43384, 56673, 48473, 14732, 25204, 62875, 17232, + 55644, 40058, 18129, 397, 49816, 27626, 60216, 25306, + 38110, 10732, 35472, 39607, 16165, 62410, 7086, 27496, + 50158, 41865, 47027, 43707, 3983, 64460, 53739, 28189, + 875, 42538, 58391, 18282, 8861, 45795, 10907, 36476, + 20935, 50159, 63428, 22377, 35199, 22005, 58273, 27559, + 40171, 2536, 15354, 53038, 32599, 8294, 43881, 6890, + 4104, 39477, 3416, 14231, 63716, 58698, 8871, 28387, + 43094, 28276, 49866, 44118, 58895, 28174, 4918, 14393, + 4723, 25333, 55124, 30906, 58587, 29493, 21770, 496, + 22682, 20698, 63098, 29331, 42083, 17816, 23787, 43214, + 2135, 41163, 59940, 47651, 37571, 35042, 16945, 53313, + 47751, 5968, 61004, 51568, 25849, 56505, 61289, 33232, + 55259, 50253, 35550, 46938, 19022, 14950, 37908, 18484, + 19143, 12648, 11973, 7740, 15947, 57462, 5693, 21228, + 11590, 15884, 57998, 31222, 14304, 59938, 39970, 1254, + 5177, 25824, 46245, 44888, 46972, 27017, 60069, 4030, + 48863, /* * 65536**298 */ + /* 10000**450 = 65536**112 * */ 57600, 1753, 64214, 10939, 52713, 57114, 47498, 12718, + 65226, 52478, 17581, 45728, 40296, 17124, 22976, 7882, + 59829, 9678, 48006, 42769, 33867, 59105, 40007, 33681, + 62758, 12880, 7653, 19018, 42114, 60278, 48185, 24533, + 7865, 16338, 28648, 55791, 6926, 17250, 39828, 40360, + 3146, 9794, 29068, 10091, 31954, 10861, 174, 9952, + 30118, 38130, 10042, 27126, 56412, 40935, 47114, 38430, + 26489, 15830, 50460, 58142, 53729, 28445, 34585, 11908, + 54573, 17947, 9765, 11260, 4075, 58984, 37064, 3346, + 57974, 57633, 26781, 41340, 61062, 3241, 44773, 47277, + 24897, 34071, 18673, 27883, 6091, 16551, 28150, 8364, + 61856, 64804, 11090, 50777, 18722, 53215, 55972, 60192, + 45393, 21503, 15047, 51201, 21232, 3696, 22906, 29678, + 36725, 62961, 55329, 45203, 36089, 61516, 18075, 29511, + 26330, 20863, 5232, 942, 52303, 1329, 7169, 16407, + 23511, 28002, 27861, 39195, 36757, 29288, 52738, 31621, + 59210, 51984, 42640, 5659, 47418, 7854, 11002, 58823, + 59570, 36949, 22019, 59119, 41882, 20539, 877, 50827, + 37562, 38614, 43945, 48560, 55615, 11703, 51736, 56400, + 53305, 18317, 58518, 38512, 29906, 60122, 44314, 46596, + 19166, 62123, 52578, 15091, 61001, 5047, 22701, 14755, + 18755, 47468, 31041, 14196, 42158, 21968, 3373, 44915, + 57195, 47466, 25892, 61074, 29817, 54, 64515, 27653, + 57344, 1463, 29300, 40052, 16841, 42643, 59474, 15330, + 16570, 6014, 44041, 19131, 29244, 50031, 55233, 44818, + 47712, 45727, 952, 34593, 60454, 19073, 4703, 4072, + 20111, 54979, 12176, 32868, 27943, 49668, 5088, 3807, + 49956, 5296, 3481, 21434, 32644, 61933, 14474, 15724, + 10598, 63757, 8203, 57593, 35835, 35825, 54421, 10282, + 58911, 46419, 7408, 59548, 56341, 21421, 19169, 40562, + 34398, 32643, 48732, 2508, 2467, 37998, 64620, 58696, + 45958, 12921, 53097, 62410, 8256, 16357, 3350, 63594, + 35148, 3705, 63330, 36057, 54181, 2837, /* * 65536**373 */ + /* 10000**540 = 65536**135 * */ 15937, 20970, 57308, 46022, 51974, 28228, 49601, 21388, + 40296, 55589, 44307, 42834, 398, 65459, 29106, 36117, + 58627, 55677, 12574, 29537, 16367, 36210, 27724, 17412, + 18304, 13827, 20066, 27247, 827, 4058, 41496, 20247, + 51620, 1082, 40533, 21160, 34685, 20554, 43988, 59273, + 34265, 55478, 129, 12039, 16053, 54781, 10914, 47279, + 59144, 13059, 239, 57141, 24079, 42596, 19598, 19025, + 42888, 9118, 45324, 12662, 14300, 23767, 3983, 64928, + 23773, 48090, 61417, 45026, 31449, 8952, 13451, 50205, + 9133, 1606, 29283, 16751, 52783, 25986, 27202, 64448, + 7976, 36045, 65419, 18289, 6687, 58459, 2696, 64771, + 59103, 11898, 15922, 1849, 13696, 18721, 51962, 60276, + 33088, 13618, 33835, 955, 54730, 30753, 42953, 7375, + 61463, 55489, 54327, 58832, 30130, 14445, 27383, 2532, + 60622, 8764, 27263, 20809, 29172, 10746, 27493, 19018, + 21323, 2715, 51634, 13711, 18305, 64990, 61883, 29593, + 30164, 37070, 50170, 17727, 64571, 25429, 8567, 42658, + 41690, 25244, 38225, 58617, 37108, 46866, 41447, 12452, + 41201, 46696, 36226, 58260, 6808, 60813, 3511, 42132, + 2464, 20759, 17487, 10188, 15270, 14266, 25609, 58137, + 57931, 2205, 6443, 37431, 12405, 58845, 33285, 16573, + 14071, 5820, 16529, 58780, 31569, 52734, 18992, 50695, + 46732, 20912, 5076, 48345, 22472, 23041, 64294, 52141, + 22442, 392, 26740, 43057, 11860, 14356, 63434, 15374, + 14772, 28670, 41433, 1974, 54122, 17046, 50870, 58582, + 5398, 17662, 56622, 53433, 51651, 8826, 50675, 27415, + 59006, 31726, 3039, 15225, 1797, 30657, 62118, 31964, + 11409, 19519, 46289, 51026, 63766, 51506, 6721, 28612, + 43824, 40432, 28241, 27448, 45638, 22197, 9841, 39482, + 9863, 39609, 40744, 38597, 41001, 28616, 32806, 21219, + 8559, 63020, 56887, 1918, 19985, 9540, 10554, 43907, + 50615, 38633, 61885, 47235, 60236, 61683, 13384, 60276, + 39709, 37164, 11604, 48681, 49626, 35185, 43726, 49403, + 29356, 30785, 4575, 1193, 43617, 38640, 17416, 6671, + 7232, 27443, 26406, 41752, 6566, 25930, 62643, 18778, + 54032, 30217, 3010, 58389, 63320, 30362, 35000, 19530, + 13024, 51771, 54380, 9543, 4082, 11961, 11867, 45471, + 30275, 39318, 40920, 8938, 25475, 57521, 52508, 58089, + 24296, 24154, 27196, 31838, 56076, 47056, 45743, 14112, + 53271, 164, /* * 65536**448 */ + /* 10000**630 = 65536**157 * */ 41216, 46406, 59322, 61369, 51512, 20872, 33344, 41848, + 43840, 47477, 17497, 55908, 2232, 55500, 37020, 51781, + 22444, 37436, 7404, 2929, 57789, 15841, 61447, 35446, + 61753, 33940, 20974, 40070, 32303, 24165, 35623, 37205, + 10896, 16123, 6081, 4131, 29524, 1872, 8494, 27926, + 37845, 23806, 62637, 1365, 6521, 39715, 46011, 60077, + 9346, 51026, 41457, 9861, 44621, 22494, 64632, 15645, + 7424, 61517, 4626, 23178, 34013, 8518, 49315, 57860, + 32895, 17307, 57060, 28216, 27297, 61081, 36199, 59774, + 44595, 28382, 55034, 12516, 60988, 3506, 50799, 38145, + 54391, 63230, 20695, 45368, 10226, 3270, 24994, 56899, + 31459, 18314, 32368, 51902, 33323, 63009, 59011, 29737, + 29075, 49025, 4282, 31052, 15197, 60533, 9381, 32019, + 50249, 61190, 24684, 34675, 46264, 42435, 53411, 31868, + 38459, 40070, 61396, 19036, 30012, 23474, 3616, 19739, + 9343, 27372, 23783, 53650, 37433, 59240, 38132, 41049, + 45152, 8725, 51544, 34525, 36550, 16360, 27941, 7440, + 35100, 54826, 64859, 13997, 4890, 53899, 54048, 35700, + 10798, 26647, 1271, 49433, 25744, 53858, 31178, 14919, + 937, 30111, 55552, 58717, 17286, 37081, 34938, 9745, + 24865, 45841, 34340, 43224, 22583, 5991, 64792, 16894, + 50876, 18240, 63281, 5032, 50942, 44113, 38789, 36691, + 51395, 8802, 13454, 56366, 32520, 61447, 35750, 63344, + 37142, 50639, 5722, 37943, 60442, 51591, 43337, 64200, + 64641, 57845, 46520, 36321, 44691, 5976, 53935, 32798, + 18551, 30652, 17368, 30219, 17859, 32537, 43934, 44612, + 43162, 55927, 7118, 44489, 276, 17010, 19651, 59717, + 37728, 13644, 63771, 16530, 51265, 23961, 51401, 39975, + 37696, 39126, 60849, 22425, 21035, 9611, 64833, 55092, + 17850, 19413, 53650, 61853, 22584, 14070, 18779, 41400, + 29164, 23227, 47530, 25123, 4816, 10016, 33069, 3061, + 50950, 15317, 22406, 5087, 51471, 51986, 21623, 53924, + 56665, 20549, 54909, 13520, 40440, 5926, 58434, 18, + 50925, 8063, 35498, 15845, 51871, 7543, 20521, 27848, + 48972, 24508, 61119, 46506, 34938, 10016, 61223, 2437, + 18604, 57378, 59677, 26266, 31802, 20692, 53429, 64574, + 20518, 2425, 41617, 57694, 62360, 47901, 142, 34172, + 5481, 48289, 53305, 12663, 37332, 46869, 144, 52762, + 35315, 13067, 41549, 63950, 10274, 26507, 13044, 60707, + 31640, 20218, 11020, 6092, 31125, 46895, 40706, 13301, + 33249, 14254, 13694, 14182, 44179, 19002, 10953, 42206, + 2912, 61112, 21006, 46700, 45041, 13788, 37984, 61123, + 2920, 53910, 22103, 46791, 35691, 26534, 59183, 6629, + 38284, 40141, 33801, 45081, 40582, 63304, 9780, 38978, + 37040, 33628, 42029, 7586, 6756, 27120, 50939, 17873, + 34198, 43080, 58421, 36335, 22204, 37477, 9, /* * 65536**523 */ + /* 10000**720 = 65536**180 * */ 29441, 9221, 44176, 26692, 60846, 31847, 29090, 25339, + 35930, 20844, 8043, 17725, 25927, 13288, 32521, 8126, + 50775, 44966, 15361, 9307, 64745, 7612, 24764, 29669, + 13555, 50864, 44391, 48083, 58573, 42556, 61204, 64477, + 11986, 42790, 52174, 42952, 53031, 54270, 20286, 8768, + 22341, 61349, 63774, 14080, 60374, 62747, 7402, 25223, + 28052, 46846, 46980, 8609, 9078, 33609, 53505, 34930, + 32968, 30589, 32788, 43651, 14971, 17775, 57203, 12298, + 62205, 17626, 9672, 31691, 63216, 49734, 40541, 6402, + 22005, 30587, 13054, 10329, 31904, 3172, 13622, 45858, + 46301, 10464, 15293, 17945, 17536, 61782, 57231, 38296, + 45404, 38204, 18123, 28934, 2342, 37881, 10854, 32095, + 4987, 56042, 25984, 9019, 45858, 6236, 46121, 45379, + 18810, 26175, 50282, 21223, 50027, 12893, 65320, 5925, + 50383, 43903, 42003, 15205, 5093, 41037, 60929, 42849, + 11522, 14113, 15252, 27792, 31752, 2747, 32751, 24967, + 11946, 51822, 33949, 61093, 54336, 61377, 44704, 51071, + 52508, 36736, 35998, 31965, 32400, 38483, 30039, 39655, + 12271, 53350, 3018, 27056, 52286, 4241, 2469, 12591, + 57208, 5539, 59538, 57279, 51412, 4367, 51194, 63224, + 42879, 57531, 5593, 36875, 3222, 36878, 8834, 58841, + 50736, 22072, 2883, 64310, 30818, 10755, 8048, 27469, + 32380, 287, 25978, 8932, 22638, 42123, 54687, 38020, + 54046, 34026, 2495, 20815, 13295, 60567, 18045, 38166, + 27324, 23540, 61061, 18019, 41556, 19312, 21205, 18355, + 4165, 36131, 36155, 63114, 1178, 4578, 57389, 10680, + 64688, 3879, 48569, 34056, 47861, 11495, 20055, 59999, + 8785, 16819, 48092, 5275, 39435, 62427, 11880, 55745, + 40370, 22261, 23222, 37349, 25595, 44199, 47928, 8827, + 33878, 10592, 29893, 58929, 55559, 62526, 3540, 28795, + 45772, 44601, 30551, 23900, 47810, 48207, 38046, 45993, + 54951, 42424, 37459, 26441, 64051, 39949, 15873, 48249, + 18153, 33377, 31324, 46745, 57720, 38661, 25484, 2856, + 27871, 57992, 32210, 39775, 27415, 49689, 12774, 39695, + 54026, 8851, 64076, 45346, 30440, 4954, 43827, 59588, + 26458, 35245, 6276, 9866, 19606, 17051, 10101, 42987, + 13096, 65041, 11754, 60180, 40909, 8317, 52670, 33992, + 60144, 23815, 64633, 10803, 13953, 41749, 52611, 55862, + 19561, 29527, 2011, 60830, 46093, 11917, 17017, 8948, + 6256, 43842, 30373, 60280, 24957, 58414, 59183, 55358, + 58102, 26713, 8531, 36657, 63486, 13580, 4866, 34860, + 64464, 17306, 43397, 37920, 15862, 59273, 3367, 51941, + 23330, 41718, 46765, 17746, 54707, 19066, 17076, 30414, + 2252, 63321, 11865, 11828, 30996, 63021, 12032, 19445, + 18188, 27359, 23050, 15348, 3491, 46691, 51491, 36848, + 33160, 12581, 63320, 56725, 1821, 43960, 39997, 18740, + 48805, 41842, 24120, 15890, 54968, 55258, 61757, 32921, + 9505, 55385, 18647, 48173, 26532, 22866, 2391, 60301, + 4042, 25640, 2549, 20478, 51618, 41943, 15933, 49899, + 41880, 50809, 7605, 15053, 44692, 26691, 4504, 56850, + 53475, 704, 51873, 61228, 29198, 50857, 6149, 26788, + 1987, 17697, 41116, 7369, 23359, 53572, 17078, 54242, + 56763, 36431, /* * 65536**597 */ + /* 10000**810 = 65536**202 * */ 24832, 34883, 19140, 51974, 19534, 493, 52319, 13085, + 44094, 53939, 13943, 21197, 17741, 12809, 17083, 47879, + 44152, 35922, 40786, 5096, 8680, 9278, 44616, 38504, + 36424, 51297, 47600, 4593, 4526, 149, 59298, 44171, + 44964, 25078, 37864, 13646, 63055, 58238, 37926, 35586, + 10600, 3464, 53122, 28369, 17593, 3852, 29481, 59844, + 27408, 27200, 56105, 64110, 48332, 50180, 19869, 47629, + 55510, 63058, 63565, 15060, 30626, 63856, 56518, 46308, + 39745, 24691, 36420, 55961, 36063, 63197, 60888, 53216, + 16582, 21061, 31362, 31969, 40126, 63351, 10808, 40164, + 30133, 43848, 10633, 38149, 14270, 53620, 35996, 7377, + 31064, 14168, 27656, 8304, 9433, 48523, 18453, 35684, + 59897, 45916, 24972, 15325, 2090, 26144, 25610, 31629, + 32660, 38294, 23250, 17832, 48733, 50586, 41084, 47429, + 31712, 34017, 19793, 62777, 45378, 44102, 8716, 29657, + 11066, 8490, 21653, 65497, 54560, 34995, 45742, 29639, + 47537, 31847, 50867, 52761, 21881, 37741, 50563, 52577, + 19856, 51512, 7692, 58548, 21610, 63516, 13279, 10470, + 25956, 22794, 15559, 37617, 47777, 14198, 59911, 38144, + 48165, 43003, 1866, 15531, 29396, 63328, 5477, 46307, + 7420, 63290, 9773, 16965, 24790, 59750, 55367, 43061, + 40717, 39703, 31857, 13914, 10833, 9318, 46436, 41858, + 33725, 2693, 48237, 15973, 39351, 1385, 60479, 8159, + 36758, 43662, 65499, 30448, 36485, 14023, 16129, 56629, + 11037, 14727, 56695, 61224, 10018, 61924, 17039, 58813, + 51177, 7002, 14025, 34593, 12170, 14808, 16590, 42794, + 54486, 23047, 40628, 57635, 49464, 47344, 56582, 36349, + 43317, 39710, 36166, 49702, 43150, 50620, 52026, 12306, + 14900, 24719, 32561, 23469, 56363, 58169, 29717, 62860, + 5914, 30326, 36935, 6904, 10575, 39528, 43903, 45125, + 45571, 20883, 10642, 49940, 49906, 46725, 33540, 15427, + 54802, 23586, 6422, 34110, 28513, 24672, 55236, 59300, + 18103, 8071, 343, 46748, 44955, 44719, 46329, 45518, + 64515, 53685, 49458, 57239, 26923, 63817, 49998, 82, + 48162, 49280, 36045, 52738, 55278, 52109, 36659, 28664, + 54266, 36879, 7837, 33525, 38888, 43635, 3373, 31635, + 39148, 20248, 61282, 48866, 43029, 19598, 35185, 15499, + 29972, 51650, 46352, 17452, 27329, 41299, 61120, 41483, + 63249, 41810, 38435, 63667, 39939, 54741, 6587, 14314, + 2969, 13087, 5872, 55217, 56115, 62553, 44160, 49781, + 42336, 33771, 30218, 31267, 4033, 42958, 21612, 41303, + 34647, 1810, 28901, 41550, 40209, 11769, 4586, 22182, + 26502, 5719, 30640, 11452, 12437, 21544, 2884, 63001, + 2124, 35767, 51047, 27970, 13456, 60413, 51818, 58535, + 47850, 36522, 31614, 53268, 52691, 2465, 9577, 57821, + 34723, 14832, 5857, 29536, 54171, 49780, 47615, 47261, + 30128, 62107, 57931, 31222, 38520, 25994, 3823, 15723, + 16547, 17305, 49713, 43099, 51610, 41171, 23658, 34248, + 13535, 21991, 43596, 26442, 58160, 23695, 3544, 34778, + 18047, 45877, 18286, 24355, 51158, 26871, 58388, 26582, + 47810, 41235, 7058, 10487, 40836, 51818, 20367, 52775, + 5736, 33296, 60350, 61028, 33129, 22124, 2553, 40846, + 49426, 30198, 41206, 31906, 2268, 23375, 26363, 25951, + 25327, 21358, 4872, 53366, 58360, 57573, 39684, 22204, + 14446, 39744, 2602, 5841, 58903, 33209, 16767, 10211, + 61495, 8426, 33859, 133, 24228, 7746, 3317, 39266, + 40762, 27964, 33156, 57057, 37827, 18835, 48966, 45870, + 59270, 1291, 59568, 53631, 7193, 56246, 21395, 738, + 4375, 22741, 15183, 23729, 51074, 56262, 2115, /* * 65536**672 */ + /* 10000**900 = 65536**225 * */ 14273, 7163, 46567, 51827, 50089, 10023, 55949, 245, + 1159, 17037, 51278, 44226, 51648, 35729, 25509, 4403, + 15277, 58952, 2800, 32557, 39271, 9423, 24984, 39140, + 57089, 23151, 3062, 50830, 59291, 867, 53101, 7095, + 19611, 35795, 41060, 9674, 47969, 12545, 38874, 29165, + 11512, 41264, 63581, 29168, 53103, 21505, 38999, 33701, + 54139, 9676, 37916, 53588, 50017, 6515, 42130, 2532, + 36284, 38864, 44500, 4466, 55531, 50755, 15508, 146, + 28502, 38791, 21688, 26877, 52133, 54811, 29308, 24528, + 20734, 17408, 49222, 26459, 17409, 64821, 4200, 39238, + 64979, 29921, 33627, 35459, 36916, 51567, 33008, 1628, + 6279, 54380, 30133, 5936, 17139, 52719, 46819, 42853, + 41752, 31544, 1462, 57857, 44269, 5290, 12763, 55500, + 39832, 27225, 48368, 61922, 40176, 40270, 5222, 2985, + 26859, 21907, 20962, 63398, 54831, 61348, 11462, 26890, + 43826, 50193, 60034, 50174, 47495, 52289, 11971, 42857, + 8385, 26684, 23657, 10379, 54996, 40463, 25724, 21824, + 57970, 19757, 19307, 26592, 34085, 58605, 6778, 23721, + 51260, 28842, 5296, 13158, 47821, 847, 16832, 60766, + 40427, 3841, 28863, 20200, 1138, 3729, 22912, 46234, + 33780, 41281, 39777, 35382, 6550, 55549, 44803, 54984, + 41452, 20025, 49044, 15289, 39110, 28891, 12771, 9774, + 12295, 20992, 36634, 40705, 61898, 9178, 25519, 22203, + 50236, 10613, 5567, 27529, 13389, 798, 40083, 55933, + 29668, 42166, 48813, 57826, 5693, 61199, 24917, 35398, + 55081, 28044, 10934, 490, 44922, 45359, 60589, 21808, + 6223, 60886, 55947, 15636, 18202, 12652, 47001, 33715, + 1784, 10522, 3250, 23010, 53423, 13029, 14613, 14582, + 65496, 51185, 8470, 26681, 63330, 65425, 32413, 51168, + 32060, 54007, 60139, 17653, 53407, 8189, 34606, 61688, + 13850, 35471, 27651, 37005, 61499, 55526, 56224, 41600, + 60040, 857, 42303, 38156, 38085, 44751, 16609, 54544, + 38471, 14234, 8060, 31105, 63558, 7269, 31069, 36939, + 42433, 13862, 40368, 37119, 25856, 65017, 20549, 36357, + 64397, 17712, 38575, 49805, 59582, 22005, 40440, 19428, + 51467, 17010, 36430, 58855, 2452, 2695, 44580, 46065, + 30873, 60279, 54935, 34216, 22695, 58545, 48440, 15018, + 27887, 23637, 63051, 4534, 13378, 51603, 40257, 52604, + 691, 51699, 15786, 21724, 13278, 55833, 44434, 30861, + 51287, 5897, 10147, 58856, 38101, 14294, 17815, 47872, + 28393, 15890, 20928, 62986, 42962, 56890, 979, 15681, + 47673, 38922, 36092, 57686, 64599, 33633, 28338, 34918, + 57465, 49865, 18528, 54552, 57036, 7276, 11198, 57630, + 22789, 16017, 10059, 23237, 21681, 41524, 46643, 24961, + 44147, 48940, 62394, 7143, 9385, 11046, 65044, 57878, + 57160, 47316, 45445, 2750, 58598, 9603, 42454, 30694, + 52059, 29206, 18204, 40173, 25648, 6014, 61497, 56963, + 26048, 57723, 8838, 62072, 11570, 12733, 36026, 31434, + 3840, 46987, 33053, 832, 52289, 60589, 40187, 10691, + 45021, 57479, 35352, 44144, 11407, 18748, 20537, 37568, + 37950, 36743, 62914, 48316, 55419, 772, 17111, 43564, + 6290, 40888, 38291, 40921, 20680, 48207, 42217, 38503, + 730, 2822, 22255, 43137, 41848, 58326, 23670, 15109, + 5304, 37155, 44928, 50110, 44814, 1337, 31179, 31519, + 53369, 16421, 43531, 23933, 45501, 33542, 14548, 41770, + 5329, 24587, 36163, 13284, 26154, 26979, 58480, 55123, + 27153, 35641, 19702, 30180, 24988, 59627, 49160, 35901, + 53053, 26775, 49062, 44985, 39819, 25504, 32870, 50542, + 63631, 62927, 32094, 334, 21162, 62179, 40136, 13124, + 27741, 9876, 3165, 29681, 27682, 30484, 38671, 4766, + 48626, 12961, 26759, 53270, 6514, 16672, 17944, 11173, + 54309, 18987, 19908, 62166, 55133, 64931, 34429, 19375, + 40200, 22618, 12904, 18863, 56035, 50621, 8647, 4914, + 56531, 52460, 17908, 38068, 9533, 24082, 12137, 56181, + 52161, 1403, 43630, 37617, 47129, 31272, 12184, 10307, + 41534, 57868, 122, /* * 65536**747 */ + /* 10000**990 = 65536**247 * */ 8448, 11216, 5465, 5252, 13691, 62777, 24660, 63602, + 11742, 63994, 26533, 6198, 64453, 64762, 15022, 11560, + 57999, 1346, 43073, 12670, 29299, 41692, 40405, 12003, + 9686, 58196, 51539, 5057, 17555, 47938, 13325, 47771, + 18543, 44041, 7371, 42873, 64950, 38189, 47026, 40574, + 537, 46950, 53263, 23417, 20499, 12622, 63037, 21674, + 48336, 5244, 44671, 30812, 22163, 9040, 9255, 65488, + 41576, 18286, 31279, 38058, 36504, 1777, 41531, 32231, + 45969, 61787, 5163, 19977, 41699, 14970, 29550, 50366, + 57333, 24146, 56484, 10557, 6318, 5085, 19553, 12503, + 43553, 41906, 1510, 18184, 26688, 55056, 6458, 8707, + 11358, 14113, 9658, 9531, 38165, 19586, 46404, 23885, + 31549, 25819, 31379, 53700, 15570, 44506, 9573, 8610, + 37474, 23712, 41571, 42241, 62359, 3173, 48388, 35115, + 13886, 29265, 13202, 39660, 17261, 57603, 53509, 30252, + 3049, 31534, 42061, 10178, 10072, 42133, 19531, 5512, + 22011, 20317, 60832, 45754, 23861, 8803, 8024, 9300, + 8189, 56661, 19449, 40072, 10395, 51816, 45325, 21642, + 40617, 4397, 40831, 53612, 3720, 26816, 21980, 49486, + 19775, 28607, 30907, 20380, 59273, 64398, 56231, 48013, + 32960, 6029, 14723, 17302, 7319, 55312, 16409, 27905, + 10307, 20664, 26193, 33375, 29613, 47129, 6833, 57131, + 38357, 56322, 30287, 21069, 29634, 17545, 54322, 46630, + 59448, 27103, 63182, 30298, 48945, 39899, 34349, 14202, + 9978, 9256, 11625, 18019, 44700, 31588, 9709, 17067, + 2480, 10551, 52262, 59626, 5719, 22611, 2829, 47524, + 4751, 61315, 1190, 28590, 40756, 50116, 968, 39757, + 59488, 152, 10598, 9539, 42089, 34440, 21330, 35753, + 57353, 65382, 61232, 47818, 19428, 4893, 4284, 12072, + 10649, 29127, 34573, 16717, 42170, 60771, 8829, 1181, + 54700, 28796, 64820, 9014, 65265, 31595, 45949, 58747, + 15945, 20377, 21475, 59780, 50806, 49411, 51255, 36905, + 12430, 20303, 34553, 47326, 21884, 63330, 16073, 51001, + 5581, 9735, 30854, 43394, 26578, 29424, 49994, 36100, + 23634, 20809, 64072, 61243, 52060, 29913, 33631, 16296, + 32437, 6349, 52749, 15700, 39620, 46399, 24489, 6483, + 17702, 4372, 49283, 33988, 57337, 23019, 50643, 4364, + 1804, 2490, 53301, 55512, 15361, 57965, 43339, 53049, + 20703, 30461, 65186, 1853, 40917, 13989, 32509, 65014, + 57041, 36741, 42577, 10428, 33201, 2351, 43760, 450, + 18475, 4148, 40810, 1574, 45201, 54811, 9696, 18240, + 4281, 814, 28703, 27646, 50507, 42975, 30223, 13460, + 10852, 61914, 38691, 12727, 45042, 53605, 54025, 59128, + 14779, 11283, 46064, 12505, 43685, 23386, 14520, 29358, + 4627, 44117, 55001, 34108, 6241, 49319, 18776, 49487, + 42437, 35867, 3921, 48818, 61712, 3800, 7816, 56515, + 1495, 29296, 8713, 35840, 43635, 26808, 13132, 16233, + 2497, 3233, 44848, 48144, 53724, 1894, 2759, 63597, + 29964, 63225, 43350, 56438, 29890, 64077, 2120, 45261, + 4371, 14786, 41470, 17466, 55157, 32471, 62494, 38002, + 23407, 2940, 57644, 42903, 4020, 53587, 3318, 47999, + 5161, 32029, 30737, 54071, 2557, 50689, 53234, 36175, + 40961, 32172, 3909, 19016, 61625, 34111, 14144, 24936, + 16896, 62818, 12372, 59457, 1887, 645, 63537, 17392, + 1114, 50039, 2686, 34251, 9674, 21696, 13228, 40036, + 54714, 47286, 2182, 22144, 44868, 31758, 23861, 11525, + 21730, 3665, 26632, 58312, 32064, 33523, 30267, 40799, + 36724, 54784, 38117, 5204, 9016, 64205, 17027, 48311, + 33725, 42192, 59162, 43755, 36462, 12221, 8743, 63827, + 16782, 28240, 33067, 53442, 64633, 16828, 53744, 17998, + 37175, 47644, 57936, 1832, 6528, 14825, 46409, 1977, + 17054, 36191, 14793, 17786, 41401, 29332, 13834, 6240, + 59939, 25580, 16725, 50035, 43728, 33886, 35213, 22229, + 24861, 38719, 3055, 3061, 58000, 6125, 41860, 31265, + 49348, 46603, 9764, 35877, 30160, 49410, 7100, 47807, + 10718, 5537, 45289, 36196, 32331, 64349, 61700, 5981, + 6649, 6342, 2822, 52677, 22254, 39294, 58122, 35925, + 22310, 1603, 14936, 42974, 12624, 31289, 1266, 10913, + 8274, 37729, 49689, 38262, 24455, 55587, 6913, 50313, + 30337, 55817, 64980, 41358, 51940, 10242, 19280, 13531, + 23954, 15839, 46833, 1614, 46746, 42892, 58742, 44714, + 44748, 23250, 2673, 2661, 56547, 21341, 8958, 7, + /* * 65536**822 */ + /* 10000**1080 = 65536**270 * */ 35969, 65527, 20338, 12242, 57030, 27483, 20925, 34866, + 37995, 62473, 1330, 16007, 26899, 34993, 53763, 13986, + 26884, 65400, 55901, 12138, 53839, 8515, 45230, 37130, + 30737, 40433, 16575, 47085, 45034, 5302, 28335, 57005, + 22440, 10619, 59258, 6861, 41500, 62167, 57844, 4133, + 35839, 22712, 27192, 42174, 46754, 26624, 61306, 60061, + 12433, 10121, 6313, 37820, 6007, 61184, 13391, 25383, + 49031, 38668, 43505, 15089, 64994, 4879, 11070, 22631, + 6207, 65503, 28118, 36679, 35922, 20644, 38606, 32825, + 9233, 56150, 1583, 51096, 45352, 60012, 2115, 41832, + 60619, 29484, 25747, 59731, 50215, 33401, 9777, 33356, + 4545, 41181, 60374, 15690, 35095, 63846, 4140, 8324, + 13904, 48649, 35456, 8116, 42157, 50206, 40063, 45872, + 7599, 18962, 48417, 39625, 19385, 7183, 39285, 25477, + 31918, 34075, 2973, 20304, 3869, 40907, 6283, 53285, + 21565, 54800, 3099, 63351, 19428, 2283, 59341, 9996, + 48252, 48814, 54345, 22150, 21613, 40202, 43876, 38944, + 64604, 6563, 30994, 2553, 44916, 42593, 29298, 37038, + 45249, 11025, 48205, 9383, 16918, 37853, 32410, 31440, + 29243, 60387, 34792, 54085, 7280, 64745, 6242, 42678, + 55653, 7950, 56873, 4902, 52836, 43897, 639, 9280, + 60008, 46619, 32011, 25081, 52076, 28983, 47306, 61838, + 19535, 24464, 41653, 25843, 43561, 48725, 41247, 44966, + 53302, 43814, 7367, 9458, 13869, 31476, 12767, 55594, + 30824, 63935, 9696, 6667, 31999, 50893, 55234, 42913, + 19496, 12880, 54616, 37680, 47181, 15774, 42091, 48571, + 41189, 56906, 44069, 19494, 61417, 47627, 49626, 52385, + 19434, 65511, 16820, 2643, 49943, 35149, 43140, 3439, + 65423, 7246, 36543, 9896, 3582, 10149, 23496, 35541, + 2582, 11269, 42535, 44767, 50152, 61980, 39561, 56609, + 37061, 8334, 45130, 14096, 40278, 15114, 49471, 56808, + 15632, 54413, 64099, 46435, 36467, 53419, 10772, 11521, + 43612, 64772, 20299, 52506, 17748, 39569, 60365, 21251, + 34284, 10636, 44072, 26904, 45857, 43639, 24318, 61907, + 7878, 33513, 15616, 62983, 46136, 7313, 21547, 37227, + 46503, 24860, 48549, 21798, 22342, 14131, 22033, 52279, + 61857, 16311, 50989, 36484, 56525, 24361, 51738, 39047, + 44213, 30533, 50080, 52323, 16437, 46793, 4846, 62968, + 35862, 43889, 2791, 18111, 16134, 36985, 43534, 1666, + 2970, 12365, 38432, 6777, 44929, 12920, 34750, 5142, + 239, 43658, 42039, 14776, 35110, 9559, 45088, 53364, + 38362, 42460, 43246, 8437, 16032, 36097, 55193, 24167, + 59792, 8093, 36288, 38140, 6056, 32401, 1144, 16797, + 24474, 23434, 37962, 30049, 52725, 56110, 58340, 36802, + 24828, 48521, 19413, 25682, 45914, 55, 12190, 42713, + 60387, 16852, 63593, 27607, 55260, 27802, 54479, 29187, + 8748, 34352, 5241, 45524, 60050, 405, 46704, 41046, + 26477, 45891, 60022, 51904, 33611, 44204, 30580, 60004, + 18775, 32340, 28622, 45538, 49045, 63367, 23219, 51168, + 42982, 41136, 63410, 31213, 43173, 37726, 19222, 29370, + 44402, 19495, 23168, 12370, 17208, 15786, 47477, 27836, + 19826, 28477, 5719, 24067, 5087, 35305, 16911, 20735, + 54257, 4741, 23273, 14332, 37147, 18175, 45630, 40503, + 24950, 18113, 9135, 9501, 21821, 12582, 11139, 62854, + 464, 12572, 57428, 13531, 28477, 18522, 10541, 26505, + 47692, 53471, 25747, 53782, 13544, 8182, 45875, 48127, + 54948, 29352, 17720, 43079, 19041, 62187, 64838, 33792, + 47137, 49136, 38397, 48247, 2603, 30425, 51397, 24949, + 30697, 22370, 53700, 21914, 65294, 30144, 34466, 24897, + 9592, 158, 24612, 13665, 38859, 58457, 23999, 40845, + 19152, 14012, 21212, 22737, 36399, 8307, 28748, 2060, + 7589, 17249, 362, 41692, 8612, 51819, 58869, 4455, + 53139, 21737, 37335, 5624, 59010, 36579, 36223, 36932, + 17544, 4121, 41032, 28204, 45035, 63366, 26317, 7171, + 33739, 4399, 61606, 57877, 21760, 61384, 19819, 2133, + 21109, 34777, 25708, 22613, 46696, 44052, 51710, 23536, + 17871, 32203, 8966, 41282, 22625, 20237, 16347, 22565, + 3942, 25598, 47178, 3759, 63556, 22918, 62263, 51106, + 11270, 3902, 54133, 5238, 58847, 3357, 60086, 28063, + 40717, 9011, 38024, 1066, 18471, 2339, 9331, 40412, + 1959, 22572, 45730, 53351, 36637, 31458, 11444, 30555, + 52969, 30098, 1350, 49651, 16400, 55522, 61620, 8113, + 3029, 39240, 39252, 23947, 60404, 24211, 16221, 11621, + 54989, 62562, 8457, 57734, 61481, 33303, 53947, 23929, + 10226, 29099, 38390, 60716, 10264, 58142, 33253, 35683, + 32668, 52365, 37839, 21035, 30530, 65294, 20410, 33214, + 33927, 59639, 51510, 55225, 60899, 32713, 55680, 22427, + 18934, 50901, 55499, 18342, 34273, 48413, 15059, 1856, + 23957, 18148, 27163, /* * 65536**896 */ + /* 10000**1170 = 65536**292 * */ 57600, 19436, 30159, 40265, 63827, 34677, 48744, 35442, + 44746, 27137, 10696, 50059, 49688, 55567, 48021, 27347, + 12423, 52843, 52579, 6439, 46139, 58036, 63895, 50521, + 2639, 35617, 15101, 35359, 52213, 33998, 64533, 60211, + 25245, 54062, 27178, 8474, 26829, 10437, 19695, 1050, + 25311, 10258, 7964, 35543, 40907, 25898, 18812, 4362, + 32146, 61326, 31532, 50972, 12327, 46814, 65349, 13080, + 49055, 60452, 4498, 43691, 45804, 4764, 48417, 10341, + 49321, 56403, 59480, 9205, 62814, 39328, 32280, 35768, + 7313, 28486, 27160, 31200, 26934, 46241, 57455, 24222, + 15734, 51453, 37567, 57333, 38064, 48913, 61530, 26786, + 43961, 12101, 40131, 46639, 11918, 42601, 32832, 61279, + 40551, 44553, 26324, 59251, 53986, 50472, 36564, 36026, + 57448, 33095, 56484, 52713, 37122, 10150, 7602, 12809, + 1704, 30364, 65439, 11312, 44484, 9736, 64030, 3053, + 58942, 31227, 6957, 3662, 46800, 22475, 19542, 51939, + 50569, 63911, 48766, 59192, 23248, 58323, 8099, 33672, + 20857, 60081, 54343, 36309, 14110, 31124, 35564, 44710, + 59463, 54102, 32666, 52080, 35270, 27597, 2521, 7800, + 15502, 15199, 31684, 15860, 43249, 35670, 23980, 26978, + 1778, 59009, 47962, 37281, 9450, 60769, 8063, 64424, + 36596, 53977, 5301, 15655, 13812, 53130, 42429, 16208, + 12103, 19916, 37755, 53157, 63374, 6767, 46635, 50715, + 33492, 18514, 53655, 37278, 6138, 29099, 17136, 6795, + 51046, 43083, 31957, 8875, 46491, 32531, 18588, 6232, + 53334, 14070, 5211, 29319, 34016, 52582, 9454, 15404, + 39941, 14707, 54612, 25892, 17481, 984, 48580, 31799, + 30800, 16827, 8558, 16278, 65451, 40259, 46308, 50697, + 39993, 52045, 56233, 47481, 31161, 388, 53391, 37511, + 60369, 8391, 34809, 36357, 458, 53784, 44568, 33556, + 13954, 49150, 5041, 54584, 60304, 21022, 41788, 36261, + 41549, 65179, 40541, 51127, 9883, 21359, 32861, 22699, + 14405, 39846, 25772, 63294, 16861, 39665, 16819, 32781, + 16146, 20361, 49368, 48805, 11794, 18538, 59056, 48282, + 34943, 15871, 28426, 53226, 11855, 45462, 30124, 60860, + 28055, 9267, 43021, 46094, 42638, 38870, 1321, 55408, + 37034, 45963, 41870, 38539, 60271, 41848, 30287, 44532, + 15544, 26752, 39819, 41330, 28662, 32340, 35342, 45264, + 53173, 39672, 13627, 16487, 47378, 56815, 64338, 38261, + 55537, 33663, 9483, 51506, 57269, 63848, 63177, 4795, + 39218, 41025, 28259, 47624, 23486, 30665, 7272, 2830, + 39617, 10425, 47029, 61323, 62933, 44477, 30007, 43020, + 52077, 30725, 38435, 57638, 16462, 27056, 64988, 16566, + 50537, 20493, 9906, 21492, 43895, 374, 44515, 56769, + 8223, 48380, 40760, 14257, 39656, 34630, 41285, 15246, + 62411, 47824, 48336, 36913, 6976, 16512, 57714, 42313, + 13979, 48088, 60, 24912, 62211, 28151, 35752, 36701, + 50052, 24618, 59132, 20255, 12497, 59698, 29577, 51569, + 12798, 42198, 53790, 23570, 19875, 61970, 10800, 48176, + 24589, 6893, 31612, 57636, 10610, 30282, 22215, 44024, + 31263, 34518, 45043, 32436, 12262, 46765, 52624, 16321, + 4114, 59087, 54751, 49164, 37820, 64012, 27438, 25871, + 11204, 15290, 26961, 38400, 20759, 64316, 9621, 64020, + 46909, 20691, 52647, 33348, 11576, 17066, 14015, 49566, + 40538, 63664, 14944, 20687, 39074, 25856, 38268, 47873, + 30505, 1498, 37095, 13677, 9292, 30643, 49306, 2970, + 34675, 26586, 4470, 13882, 62018, 42647, 14650, 32179, + 31724, 63540, 6422, 45588, 48883, 16175, 17479, 7982, + 51335, 3705, 24447, 24326, 21497, 52371, 25062, 24894, + 15989, 3109, 50876, 27200, 8648, 32174, 20005, 8719, + 61318, 38490, 117, 58091, 45689, 24069, 39959, 30543, + 2616, 64752, 62632, 16639, 3681, 44725, 9996, 35120, + 41225, 47680, 31561, 303, 57460, 13392, 15823, 14403, + 48491, 10280, 30164, 63874, 53006, 38217, 29855, 29272, + 24594, 7725, 18809, 57474, 55413, 58819, 52259, 8574, + 28330, 5615, 47921, 11575, 1337, 37725, 18350, 20197, + 59722, 7403, 55547, 56424, 54478, 9683, 30498, 4876, + 11569, 8650, 7196, 1998, 22300, 6472, 53770, 18940, + 8345, 3191, 3892, 35925, 31490, 15746, 63659, 19136, + 40591, 38919, 7939, 18832, 4632, 51547, 58229, 27339, + 25497, 1691, 51106, 275, 61634, 48153, 48098, 6661, + 63928, 58037, 26688, 5855, 11436, 61191, 44893, 42901, + 60804, 42379, 26937, 11543, 23770, 16000, 49890, 22438, + 57970, 3854, 64957, 3519, 40127, 20002, 45185, 39487, + 35298, 55263, 46570, 8685, 55848, 35560, 19389, 27707, + 13058, 28900, 15944, 7688, 37021, 39815, 30190, 44862, + 23598, 35229, 62820, 2996, 20461, 46976, 9001, 27879, + 48268, 46227, 49321, 49454, 63850, 61735, 54794, 42907, + 23571, 26334, 53654, 65360, 25489, 6468, 53678, 42675, + 52954, 59402, 4235, 63352, 24939, 48637, 61250, 26806, + 49629, 9768, 42381, 54045, 9937, 12168, 37664, 4615, + 55658, 1123, 65351, 60196, 45320, 56318, 30654, 20203, + 33201, 41697, 44590, 23892, 65277, 21327, 25805, 61616, + 58532, 8858, 28723, 13551, 44996, 22985, 48164, 17401, + 48762, 63463, 10663, 40820, 44187, 7691, 37052, 1577, + /* * 65536**971 */ +0}; /* end powers of 10000 in base 65536 */ + +unsigned short _start_big_powers_ten[] = { + 0, 1, 54, 159, 317, 526, 788, 1102, + 1469, 1887, 2358, 2881, 3457, 4084, 4764, +0}; /* end _start_big_powers_ten */ + +unsigned short _leading_zeros_big_powers_ten[] = { + 0, 22, 45, 67, 90, 112, 135, 157, + 180, 202, 225, 247, 270, 292, +0}; /* end _leading_zeros_big_powers_ten */ + +unsigned short _max_big_powers_two = 1050; +unsigned short _big_powers_two[] = {1, /* begin powers of 65536 in + * base 10000 */ + /* 65536**70 = */ 4576, 5330, 2659, 2634, 2700, 241, 736, 6118, + 2918, 4420, 4263, 834, 7879, 7750, 4507, 3089, + 9485, 9709, 7384, 3707, 3230, 3352, 7721, 5033, + 2406, 9107, 3228, 6941, 8819, 1325, 5084, 9353, + 9449, 2435, 6704, 9445, 4261, 3162, 5528, 9548, + 4853, 5551, 7153, 8634, 6800, 2062, 51, 2591, + 4400, 2943, 1099, 5223, 667, 7222, 3974, 9347, + 6550, 4000, 3007, 556, 1451, 904, 8812, 7639, + 1900, 4787, 3415, 4511, 6120, 1037, 2997, 97, + 403, 7164, 4093, 5216, 3246, 5134, 8480, 6291, + 8881, 3964, 9238, 2427, 14, /* * 10000**84 */ + /* 65536**140 = */ 9776, 2253, 8946, 6582, 4366, 1230, 5988, 5994, + 4986, 2332, 3133, 9676, 4549, 5629, 4568, 9179, + 3036, 9197, 7169, 3119, 9828, 5638, 3796, 4617, + 6421, 5990, 9499, 523, 5203, 2152, 7290, 6879, + 9813, 4441, 5925, 798, 7236, 4019, 6307, 8398, + 157, 2516, 6143, 8646, 7492, 9583, 9938, 5152, + 6847, 8006, 683, 244, 8006, 1196, 3758, 9532, + 452, 401, 5992, 7450, 1493, 753, 9827, 1126, + 2835, 5738, 7741, 3443, 881, 2236, 1741, 4233, + 5279, 3671, 2940, 5294, 7898, 9852, 7504, 8508, + 3953, 2527, 3546, 2712, 2847, 3048, 7420, 3799, + 6771, 8202, 4354, 7186, 8190, 4570, 6440, 5511, + 8549, 5153, 5490, 7918, 620, 5243, 5543, 3873, + 6356, 9078, 5386, 1591, 7111, 4159, 2320, 8196, + 6569, 6064, 290, 9978, 187, 8976, 8722, 4655, + 482, 8111, 4070, 76, 2883, 9619, 7217, 7027, + 5806, 3289, 7545, 7242, 8353, 2644, 8452, 1680, + 1123, 8161, 4848, 8635, 987, 5726, 9071, 3094, + 2436, 6472, 1303, 2224, 7305, 1464, 2855, 9906, + 1460, 1230, 6481, 9106, 631, 3182, 966, 9732, + 3988, 7802, 5403, 4445, 2222, 2728, 3489, 8571, + 202, /* * 10000**168 */ + /* 65536**210 = */ 4976, 281, 6012, 17, 8847, 4796, 3320, 9840, + 359, 4031, 4266, 8224, 5040, 9010, 6606, 8362, + 3870, 2803, 1299, 2790, 5573, 8496, 7425, 3329, + 7000, 497, 2926, 2886, 5811, 7267, 4596, 9031, + 6264, 3836, 4739, 2863, 3432, 4432, 9069, 2431, + 2863, 4311, 2750, 4609, 1868, 9838, 8459, 363, + 1809, 2581, 5504, 2024, 6298, 5674, 9180, 4725, + 8486, 7668, 2709, 289, 3360, 275, 2585, 2205, + 4105, 2770, 7940, 4706, 8653, 4347, 7154, 3676, + 6577, 340, 6463, 2121, 2672, 6305, 8022, 7840, + 5602, 9571, 4312, 3466, 8020, 1916, 4070, 2988, + 3457, 6416, 9812, 2174, 8930, 9173, 6076, 8312, + 857, 1096, 1180, 620, 4859, 152, 1092, 7491, + 4745, 3889, 3900, 2599, 4401, 3692, 4364, 2736, + 4341, 1761, 6723, 5419, 7347, 3190, 5989, 9396, + 3021, 918, 8083, 7208, 5461, 1098, 6917, 8071, + 5616, 7722, 7108, 9396, 2863, 1362, 9097, 9696, + 5896, 164, 8909, 555, 434, 8445, 4953, 6921, + 2368, 285, 1641, 6713, 6744, 9989, 6930, 9850, + 2475, 71, 4925, 5299, 4396, 8984, 4026, 8373, + 1527, 940, 5824, 5337, 6969, 4236, 2973, 2267, + 2558, 6780, 186, 2173, 5244, 6671, 3833, 9623, + 4375, 6327, 6339, 7965, 6106, 2682, 9003, 9739, + 1314, 50, 4056, 4385, 7946, 1430, 6097, 9714, + 449, 6659, 5844, 1707, 5755, 2108, 2981, 3824, + 2297, 8807, 4920, 5469, 831, 2922, 9193, 2194, + 8297, 6119, 2088, 3045, 6641, 4977, 2769, 7282, + 4848, 6251, 1477, 1725, 9884, 3400, 123, 4489, + 8747, 9422, 2934, 2294, 9954, 3692, 8377, 1570, + 4011, 7220, 3419, 4810, 5449, 2242, 1, 507, + 7969, 5364, 7835, 8911, 8206, 8810, 1515, 9401, + 4940, 3087, 5588, 2520, 2889, /* * 10000**252 */ + /* 65536**280 = */ 176, 213, 2607, 9939, 341, 6807, 5102, 2207, + 8576, 9910, 5541, 1756, 3100, 5881, 2766, 1754, + 7165, 678, 8260, 2609, 5249, 4119, 911, 2853, + 5944, 1955, 7766, 4398, 7425, 6034, 2902, 1670, + 5261, 6752, 8696, 8901, 723, 2061, 1185, 4361, + 1220, 6295, 9342, 3745, 2770, 2245, 9517, 8616, + 519, 326, 4902, 2510, 240, 2817, 6116, 7267, + 5696, 5673, 4758, 400, 7924, 2433, 2768, 7115, + 9889, 8056, 4872, 3379, 6347, 188, 2900, 3628, + 718, 2601, 569, 4493, 9471, 7751, 6734, 4229, + 7350, 4570, 3539, 9964, 7318, 2925, 7285, 5044, + 910, 1170, 6902, 9479, 5846, 4587, 2066, 9718, + 2024, 9598, 9786, 6834, 9788, 878, 8515, 479, + 3827, 7717, 2467, 4862, 6342, 6429, 1755, 8575, + 9653, 7658, 6064, 8500, 3739, 6705, 9709, 8727, + 7188, 3920, 643, 3538, 9196, 2044, 2512, 4030, + 4742, 8858, 2798, 5421, 9449, 4493, 7923, 7811, + 8000, 9466, 893, 2451, 2464, 595, 648, 4712, + 9685, 1069, 6432, 5712, 9366, 2291, 8285, 9673, + 963, 797, 3759, 8730, 9787, 3118, 6175, 6888, + 7340, 5804, 1787, 4499, 9274, 5600, 8623, 2000, + 3012, 7525, 3772, 5832, 8776, 8233, 8819, 4186, + 8839, 1243, 3757, 6603, 38, 8988, 1689, 9475, + 2656, 4308, 2757, 1617, 8483, 7419, 4432, 422, + 3379, 9379, 7941, 4832, 6397, 4864, 132, 4744, + 5018, 2249, 3186, 7947, 8711, 5661, 7136, 1949, + 9827, 4135, 7566, 106, 1785, 6344, 6462, 5900, + 9559, 1743, 8759, 9815, 2766, 2726, 8889, 1178, + 6042, 1337, 2344, 758, 2262, 9853, 9870, 320, + 3981, 2791, 3735, 1192, 7971, 6202, 2032, 4478, + 7712, 7807, 4055, 1262, 7318, 4267, 551, 2405, + 7480, 3657, 1175, 4133, 614, 4983, 3622, 729, + 1553, 3186, 1015, 1134, 6445, 3169, 9873, 4821, + 19, 2947, 3314, 1074, 2191, 3683, 9534, 9977, + 1274, 6156, 5112, 1886, 5073, 7996, 4769, 5584, + 4236, 2031, 7148, 3026, 7816, 3827, 5170, 7265, + 7348, 9775, 6826, 6117, 8322, 5389, 723, 3879, + 7766, 2144, 1642, 5480, 4291, 6302, 1317, 4356, + 5214, 6696, 1438, 768, 8736, 6532, 2848, 9268, + 1403, 1103, 9555, 2274, 4988, 1270, 6107, 5515, + 8883, 2507, 275, 8187, 4670, 975, 165, 6868, + 1973, 902, 9995, 1421, 78, 6534, 7688, 171, + 1151, 4, /* * 10000**337 */ + /* 65536**350 = */ 5376, 2848, 3097, 7478, 9581, 4767, 564, 7416, + 2894, 9542, 726, 2535, 6568, 6434, 5775, 8334, + 6660, 8109, 768, 4381, 7948, 832, 9727, 6736, + 4371, 7686, 8518, 332, 173, 8241, 8498, 4, + 6562, 3493, 3112, 4998, 660, 1524, 6823, 6242, + 6475, 8178, 7929, 8298, 9439, 9161, 2065, 5021, + 3388, 6887, 6511, 6683, 4151, 1208, 8005, 4130, + 3692, 6948, 2189, 805, 1154, 133, 4169, 6639, + 1811, 990, 5508, 8629, 300, 2310, 3518, 5017, + 5358, 5850, 8671, 6573, 49, 5520, 5528, 8064, + 3441, 5935, 5356, 5963, 5632, 5922, 9287, 2478, + 1595, 8827, 1212, 9835, 4848, 2573, 8854, 6317, + 8300, 7144, 3193, 6224, 2297, 6291, 2094, 9274, + 3829, 9250, 3608, 9224, 6286, 3559, 7081, 5126, + 7724, 2849, 7390, 9500, 2307, 2908, 641, 5630, + 1271, 2165, 7588, 4861, 9441, 7062, 2062, 3854, + 259, 5391, 1477, 3176, 5832, 3351, 3779, 3495, + 6085, 9743, 1068, 4149, 3738, 9737, 2761, 6395, + 1575, 6136, 9570, 419, 8912, 4743, 139, 5106, + 9429, 6354, 6639, 2016, 32, 6503, 2688, 253, + 3072, 8438, 1809, 3605, 7429, 6407, 3523, 3194, + 3301, 3415, 8083, 7442, 13, 6376, 3587, 9852, + 3230, 915, 6344, 8098, 9192, 4127, 1359, 3713, + 5754, 6880, 2667, 3981, 1681, 155, 2793, 6465, + 6334, 7863, 2526, 4075, 2560, 5031, 1170, 77, + 6463, 1877, 5427, 7978, 2699, 301, 4894, 2316, + 6716, 9859, 235, 6316, 9834, 5965, 4481, 9083, + 6291, 8558, 9362, 8075, 9932, 6405, 6902, 3829, + 6056, 2529, 691, 6770, 1761, 3187, 8874, 7283, + 6080, 7420, 5693, 4501, 1471, 9833, 6366, 4679, + 4737, 3318, 5819, 5229, 5279, 6659, 9858, 424, + 4410, 35, 645, 8191, 9263, 5668, 2513, 5232, + 5091, 8185, 1986, 8716, 5718, 7585, 3116, 2732, + 2118, 7247, 3777, 6391, 5165, 5421, 8223, 4033, + 3829, 5689, 9637, 4867, 4761, 5856, 4362, 9352, + 5900, 8005, 2560, 3264, 8131, 5834, 2535, 8375, + 3975, 593, 6644, 5831, 1577, 4428, 8434, 1205, + 8880, 3712, 4093, 5790, 74, 5755, 5356, 421, + 1541, 652, 668, 5683, 1879, 3825, 122, 8887, + 6501, 9684, 829, 1335, 1784, 3655, 6775, 3013, + 7584, 8971, 8943, 4562, 3406, 4808, 2970, 4085, + 7148, 5625, 5979, 2961, 1398, 3067, 2645, 2510, + 1070, 2790, 850, 8698, 3506, 1221, 7240, 683, + 2748, 3836, 5782, 3889, 4328, 8462, 5594, 6692, + 2708, 6983, 5135, 6812, 3321, 5822, 1915, 2109, + 500, 5493, 5883, 7103, 3947, 841, 8799, 7661, + 617, 2921, 2247, 125, 6758, 8415, 1893, 2050, + 9160, 7931, 7846, 8933, 827, 3462, 7938, 8842, + 5671, 8291, 2242, 395, 8090, 1762, 8081, 8357, + 6877, 1775, 3990, 2665, 4244, 3538, 9877, 5469, + 4185, 7179, 1956, 8820, 4442, 1034, 950, 5064, + 5290, 45, 4563, 1743, 7448, 4025, 9091, 9971, + 5877, 7819, 3936, 3940, 6105, 58, /* * 10000**421 */ + /* 65536**420 = */ 576, 8988, 664, 3919, 9397, 8633, 7900, 5633, + 778, 481, 1888, 1204, 5101, 7862, 7589, 9191, + 9710, 2689, 4485, 1804, 6343, 4331, 3074, 8357, + 5813, 3262, 9731, 3649, 2080, 2864, 5674, 77, + 9082, 6281, 981, 3039, 4540, 5146, 1654, 4127, + 3199, 1398, 5247, 1783, 9163, 5185, 706, 2750, + 8430, 9896, 2547, 2815, 2509, 3404, 2669, 3713, + 2722, 1799, 138, 926, 9118, 8525, 4454, 8668, + 6336, 9770, 8685, 9548, 997, 5846, 7559, 9483, + 8362, 1665, 2765, 9093, 8253, 1725, 9810, 213, + 7885, 2853, 1411, 2276, 6384, 8329, 4969, 5285, + 2251, 6643, 9833, 2982, 9239, 927, 6645, 1456, + 7982, 8688, 6067, 7858, 2076, 6104, 5217, 644, + 3517, 5939, 7126, 7571, 4858, 4602, 2878, 9362, + 6694, 1240, 50, 8423, 6113, 5386, 9069, 6622, + 2139, 1576, 1299, 3779, 4071, 6783, 4160, 4975, + 1015, 3216, 5541, 4822, 2752, 7525, 532, 1015, + 3436, 6112, 6964, 1057, 5338, 1449, 5575, 127, + 7502, 6613, 7556, 5345, 1136, 4662, 1741, 2461, + 5108, 8880, 4068, 7622, 9910, 1884, 6898, 3514, + 5504, 3849, 4888, 1780, 9861, 1304, 3382, 2005, + 7315, 1614, 7822, 5275, 9537, 1118, 3830, 1889, + 3342, 8466, 6400, 254, 2618, 9653, 6474, 4960, + 397, 2576, 7484, 9275, 8232, 199, 8566, 161, + 6360, 6573, 5545, 1958, 3067, 5263, 559, 4958, + 315, 1554, 8857, 7186, 8622, 3782, 7740, 3278, + 1794, 7268, 2632, 5501, 9618, 8738, 3643, 6277, + 6012, 3610, 288, 4206, 5796, 3475, 7174, 4912, + 8758, 6323, 3905, 9152, 7953, 4361, 4463, 3095, + 3554, 1683, 6030, 1929, 7375, 6258, 2152, 6562, + 5846, 3295, 3906, 621, 3967, 5512, 6962, 5184, + 8037, 2555, 6225, 7071, 7488, 1212, 4898, 2473, + 7328, 3716, 5825, 9672, 9639, 7120, 443, 7612, + 8465, 6114, 8131, 5825, 3200, 7748, 9274, 4311, + 9358, 4668, 7300, 8736, 3949, 584, 9431, 5922, + 6761, 5835, 1402, 9894, 7088, 2458, 2112, 5215, + 1778, 6588, 9991, 9956, 9148, 6733, 5266, 3544, + 6437, 9631, 1618, 5442, 3963, 2241, 6525, 5097, + 6792, 8765, 5631, 4038, 1736, 3256, 8351, 5314, + 9979, 6884, 6015, 1122, 5239, 8501, 5776, 6649, + 5114, 6880, 460, 475, 1329, 2777, 8032, 6562, + 7846, 7018, 9893, 9391, 3793, 9834, 4199, 3843, + 627, 9689, 2149, 160, 1327, 9674, 8560, 9299, + 8965, 7349, 8187, 6017, 7068, 8093, 5757, 7606, + 2423, 135, 372, 6302, 4605, 2027, 9171, 1324, + 5511, 9099, 8850, 8994, 8232, 4470, 7980, 8005, + 7216, 4482, 6124, 297, 1049, 6980, 9621, 311, + 8951, 8883, 5978, 4077, 9581, 2508, 4711, 4428, + 3341, 3531, 523, 9142, 7401, 8003, 950, 3295, + 419, 7685, 2793, 4628, 1466, 9344, 1694, 9744, + 592, 3901, 7624, 5300, 607, 2830, 7331, 3324, + 7412, 9343, 1002, 9334, 400, 485, 9954, 1257, + 52, 7039, 3202, 2626, 5007, 3291, 4237, 9444, + 6860, 5339, 7508, 1175, 9228, 4913, 9145, 1340, + 306, 2129, 9924, 8112, 991, 7118, 5675, 6906, + 6348, 2476, 1269, 8053, 650, 3578, 7757, 1877, + 7566, 604, 1036, 8177, 8169, 1777, 7586, 4055, + 1745, 2700, 8005, 1, 372, 843, 3229, 5851, + 5704, 3752, 2409, 8356, 4838, 930, 4075, 8149, + 2620, 6567, 3302, 6988, 8270, 757, 3275, 3899, + 7832, 488, 7302, 9455, 2508, 8718, 7517, 8654, + 6925, 3559, 8617, 5973, 8089, 9073, 5897, 6014, + 3039, 4038, 3131, 8979, 8916, 7739, 2464, 4424, + 7777, 834, /* * 10000**505 */ + /* 65536**490 = */ 5776, 9431, 507, 3988, 8799, 5719, 9020, 3099, + 7523, 4041, 2773, 7913, 8546, 6090, 6505, 6324, + 678, 5416, 5566, 9267, 5891, 2562, 106, 1954, + 5018, 2963, 9753, 1086, 574, 9248, 8457, 7833, + 5151, 9537, 3506, 9829, 7272, 920, 8588, 5032, + 9739, 9592, 8917, 8333, 8413, 7860, 3589, 8574, + 3040, 7813, 4386, 28, 1593, 4394, 1358, 4985, + 8871, 9096, 7462, 836, 3458, 9265, 9262, 3279, + 912, 290, 1497, 4428, 5919, 4146, 4003, 5874, + 8647, 167, 8364, 2483, 6932, 5005, 6519, 2592, + 536, 2731, 193, 7398, 2945, 7802, 785, 4094, + 4184, 1213, 8852, 1686, 4541, 6405, 3357, 6423, + 1506, 6089, 1213, 1133, 5118, 3415, 1077, 1958, + 6675, 7423, 6153, 7034, 5831, 1338, 1066, 1935, + 583, 96, 8781, 3076, 4800, 7302, 1310, 6858, + 6070, 9182, 3912, 3432, 5149, 677, 7501, 1001, + 3691, 1492, 2816, 7033, 4083, 5163, 3022, 2024, + 5952, 3985, 8572, 2595, 5985, 5333, 212, 4524, + 2671, 5416, 7327, 8839, 2754, 6826, 8335, 6676, + 5653, 9426, 1185, 1908, 1677, 7014, 9493, 6814, + 2015, 4170, 7520, 9097, 2581, 7181, 8159, 8204, + 1452, 6864, 9467, 5347, 9830, 4403, 5856, 3087, + 6043, 7312, 4115, 990, 889, 8356, 7923, 7708, + 3107, 8295, 8873, 4976, 5777, 3831, 4188, 835, + 8231, 3690, 3524, 9390, 7023, 1876, 7236, 4427, + 514, 6350, 5016, 519, 151, 1119, 1920, 7165, + 137, 5736, 9277, 2526, 8000, 4638, 7675, 3197, + 8010, 7236, 9027, 3052, 429, 4251, 621, 4687, + 580, 9670, 8660, 7852, 6291, 8441, 4969, 2407, + 460, 7339, 6761, 6500, 9983, 805, 915, 8696, + 4445, 56, 9303, 6908, 3917, 8292, 6104, 9779, + 3567, 692, 1259, 292, 833, 3190, 9406, 3740, + 275, 1099, 1482, 6853, 1080, 8559, 8139, 1396, + 4902, 2874, 9613, 5810, 236, 8443, 5416, 8393, + 8751, 3616, 102, 6320, 4005, 809, 2349, 7262, + 1060, 927, 6212, 1845, 2309, 6601, 234, 7023, + 1037, 8076, 4278, 8787, 1111, 2785, 5347, 9174, + 4866, 8543, 1979, 9701, 8951, 2955, 1607, 317, + 508, 4607, 9658, 4672, 6840, 1896, 1259, 9832, + 7398, 176, 317, 3185, 5585, 2848, 1431, 545, + 8514, 9260, 9054, 4691, 4722, 2396, 4080, 1438, + 7161, 38, 2373, 2081, 359, 5634, 8412, 7366, + 1617, 1042, 9842, 492, 426, 5456, 9432, 5831, + 6293, 3455, 895, 9218, 307, 3951, 18, 7350, + 1858, 1805, 352, 8085, 3566, 9921, 3839, 8974, + 7501, 3634, 8467, 8370, 4209, 3242, 617, 38, + 5947, 3376, 6638, 1543, 4303, 6258, 2008, 8965, + 5607, 4777, 5725, 4908, 4312, 5484, 6276, 4939, + 2969, 1989, 8160, 2323, 3613, 5872, 6195, 1051, + 2368, 5130, 5114, 4157, 8861, 3505, 8475, 5251, + 1312, 9694, 9803, 6432, 350, 7092, 8507, 6429, + 4896, 4256, 953, 5869, 4820, 6006, 5260, 8523, + 905, 2152, 7727, 2873, 4262, 9943, 2468, 6602, + 299, 1975, 3745, 9332, 4535, 4221, 4273, 7144, + 297, 4009, 8535, 451, 3773, 2948, 5922, 5956, + 4079, 5527, 687, 9259, 9230, 6868, 4982, 8161, + 1559, 5930, 8859, 3745, 9346, 3511, 3694, 1580, + 6169, 323, 5558, 3735, 8840, 8377, 6888, 1528, + 3427, 9648, 7158, 7572, 8821, 3085, 1542, 5127, + 4430, 6826, 7402, 9291, 562, 1246, 8624, 2794, + 6256, 7655, 1083, 8826, 4414, 1460, 2278, 7861, + 8341, 3677, 2984, 4691, 451, 3560, 1580, 7583, + 6509, 4045, 7972, 321, 4512, 1662, 9186, 371, + 7919, 1240, 8982, 997, 1836, 9492, 5360, 5448, + 6025, 4174, 4995, 3474, 7970, 2139, 1951, 7419, + 8942, 6697, 4438, 3559, 2076, 8885, 2256, 6627, + 543, 164, 5853, 4856, 7906, 2129, 1724, 3786, + 8533, 3135, 3539, 2300, 6945, 7244, 4342, 4067, + 890, 7697, 9580, 7680, 61, 6007, 8870, 7700, + 8996, 6715, 3370, 1992, 889, 3860, 6590, 5603, + 2020, 9641, 1761, 2911, 576, 4742, 4317, 2007, + 5876, 2778, 8887, 2860, 2104, 1998, 8765, 3094, + 540, 3195, 9389, 5556, 3538, 4926, 3190, 7472, + 609, 5522, 9966, 9799, 5660, 1889, 1, /* * 10000**590 */ + /* 65536**560 = */ 976, 4979, 3040, 9206, 955, 4391, 2817, 938, + 1112, 5523, 5387, 1306, 5954, 1973, 9036, 8492, + 5961, 9057, 4333, 4301, 583, 4235, 3509, 9051, + 920, 2693, 5406, 961, 5945, 2876, 5973, 8416, + 1345, 265, 9047, 1241, 3361, 9657, 5675, 7186, + 6284, 4664, 9707, 5178, 8714, 3055, 9424, 8160, + 3540, 2285, 3000, 83, 4995, 4114, 2049, 3255, + 8318, 6178, 1394, 1626, 8128, 5450, 1000, 7325, + 954, 3111, 9095, 6175, 1638, 7210, 4996, 5422, + 2210, 9768, 129, 952, 7035, 3095, 2545, 68, + 2121, 5895, 5840, 8038, 6233, 8454, 4819, 41, + 9659, 756, 5166, 4451, 6171, 828, 6973, 381, + 5405, 8524, 5788, 8040, 5624, 9949, 4079, 8021, + 9909, 5434, 9374, 9549, 4519, 3315, 9843, 3053, + 936, 2227, 1563, 8987, 4406, 3206, 3672, 5667, + 4927, 3654, 3143, 8371, 3840, 3751, 6085, 6065, + 7371, 2891, 5391, 340, 2817, 4181, 8243, 2568, + 4276, 5037, 5579, 4087, 9881, 3156, 7618, 738, + 4561, 1917, 5475, 356, 8296, 541, 939, 4009, + 4945, 7654, 9014, 5190, 1958, 8762, 8536, 2515, + 6041, 1430, 8447, 7896, 4976, 5974, 1848, 2061, + 848, 2128, 9096, 8336, 5768, 1268, 2744, 2445, + 1997, 547, 5266, 2066, 2785, 6457, 7035, 5368, + 7618, 1389, 1304, 4119, 899, 4551, 3877, 3140, + 3879, 3564, 3844, 3066, 2279, 7763, 4159, 3714, + 7863, 6139, 516, 4075, 3813, 411, 6837, 7570, + 863, 6397, 2306, 9709, 5957, 1883, 2460, 1164, + 7907, 8462, 6278, 2391, 1205, 9618, 8604, 7140, + 5742, 5884, 9887, 3539, 9756, 6773, 1783, 3234, + 7128, 2285, 7327, 5364, 9023, 4212, 1005, 1827, + 4830, 6992, 6679, 2761, 8465, 8923, 6697, 2139, + 8041, 1978, 8857, 3050, 3862, 4736, 7727, 9356, + 7020, 8064, 840, 7255, 2415, 925, 5770, 8623, + 8843, 1722, 7152, 5061, 1193, 5878, 4483, 8654, + 5757, 9025, 998, 8067, 6265, 832, 4047, 3221, + 6466, 2287, 9674, 5520, 1293, 7456, 3458, 5767, + 755, 3752, 6416, 7411, 6410, 1693, 3423, 9206, + 7864, 5888, 8614, 4425, 4627, 5663, 5784, 6655, + 643, 3172, 1929, 8595, 420, 6586, 6985, 3036, + 6496, 6346, 5234, 1163, 9945, 300, 800, 7684, + 8060, 6753, 6778, 4600, 6518, 2929, 5468, 4077, + 5824, 431, 7782, 841, 2968, 1032, 7716, 9390, + 9987, 2069, 2135, 4678, 113, 7300, 3384, 8798, + 4109, 1841, 6669, 6689, 5687, 795, 4836, 8859, + 9130, 1137, 557, 3551, 4205, 4030, 2660, 5896, + 2006, 6595, 1224, 6297, 2619, 5306, 4522, 550, + 2776, 5836, 9778, 1076, 3355, 6338, 8670, 7630, + 3713, 7476, 1252, 6054, 9540, 5558, 2803, 8396, + 3948, 5582, 105, 3026, 9555, 138, 1654, 7788, + 9819, 9821, 3618, 582, 6614, 1325, 7741, 530, + 2492, 3387, 950, 3424, 4823, 7442, 9865, 9714, + 1796, 5099, 2964, 4613, 3652, 4807, 6659, 7494, + 4223, 8782, 8155, 1636, 2192, 1810, 2642, 3661, + 9096, 8284, 7796, 9482, 9920, 6951, 6355, 8988, + 350, 3480, 1984, 768, 5747, 4435, 2898, 8288, + 967, 1866, 4451, 8747, 7626, 3684, 6476, 4752, + 6604, 558, 2385, 9001, 2462, 5150, 5259, 6616, + 2390, 4184, 9526, 5941, 3138, 3861, 3482, 19, + 6341, 7036, 6369, 227, 5578, 9777, 4200, 538, + 6718, 2752, 1338, 4237, 2048, 5785, 5899, 4648, + 2755, 2819, 9492, 9450, 9570, 1581, 954, 3311, + 3691, 9510, 4695, 9790, 4907, 2502, 6597, 8365, + 4396, 3170, 92, 3169, 9407, 870, 9168, 7108, + 90, 5103, 4276, 5344, 4920, 7045, 1679, 1520, + 7051, 8893, 6973, 6818, 2512, 574, 6179, 5618, + 225, 1644, 2951, 1314, 9901, 1499, 2582, 3814, + 2485, 8706, 3433, 9669, 3891, 469, 6359, 8382, + 5455, 5542, 6754, 4380, 271, 4014, 867, 8095, + 6721, 914, 2408, 2133, 7283, 9336, 5715, 9709, + 2233, 3472, 3873, 9891, 5910, 5471, 6346, 222, + 8177, 9547, 1543, 7347, 1126, 4978, 2536, 6994, + 5877, 8981, 9413, 1542, 9992, 7496, 7307, 6635, + 831, 6332, 3769, 394, 1877, 37, 4545, 2982, + 5374, 7892, 9053, 6562, 2197, 6380, 8510, 2259, + 1952, 2956, 8378, 1486, 6599, 3860, 1054, 381, + 653, 3946, 8672, 8801, 9960, 5721, 3028, 6761, + 5872, 1570, 2165, 2319, 6451, 7788, 265, 5408, + 5369, 67, 8748, 2202, 6405, 5114, 2663, 4433, + 6258, 3883, 9615, 4072, 7588, 4059, 2415, 4238, + 8235, 2561, 9582, 4274, 4141, 5656, 1887, 8922, + 8452, 1792, 498, 6663, 2697, 5907, 6270, 9502, + 7239, 988, 5148, 5593, 9033, 6819, 2688, 7212, + 8656, 4307, 2183, 8071, 4878, 895, 5360, 6555, + 225, 6796, 7011, 1301, 1281, 7342, 1056, 6924, + 6214, 9340, 16, /* * 10000**674 */ + /* 65536**630 = */ 6176, 6430, 7092, 4105, 8720, 5723, 5981, 9910, + 5297, 4110, 3651, 4988, 5821, 4616, 4727, 5734, + 8042, 9496, 1397, 4266, 7433, 391, 738, 3945, + 4598, 4271, 7578, 529, 472, 6685, 9791, 6802, + 3226, 7385, 7662, 6806, 1919, 9525, 6729, 7962, + 5888, 9669, 2636, 7607, 7516, 8780, 6202, 3965, + 112, 1209, 5491, 2643, 2462, 5963, 2515, 1230, + 4121, 4054, 2940, 582, 5240, 8210, 1080, 9217, + 1033, 602, 7441, 2065, 6998, 3379, 489, 658, + 7501, 6167, 3242, 2737, 9556, 1554, 242, 2323, + 3353, 779, 5274, 3089, 6341, 24, 1328, 8441, + 1217, 2901, 9907, 9097, 3783, 3841, 3212, 1283, + 5332, 7926, 4527, 4103, 1597, 7221, 5369, 9156, + 4301, 8902, 3951, 9950, 6527, 2132, 6719, 2566, + 5427, 2526, 4888, 1869, 1785, 3119, 5644, 9918, + 1783, 5055, 2971, 6210, 2536, 6963, 3318, 1938, + 1884, 5924, 8977, 2428, 8311, 3225, 1210, 2846, + 4884, 7409, 5288, 5889, 3103, 3776, 3574, 7832, + 1546, 680, 9682, 9901, 1161, 4236, 893, 9012, + 9788, 3335, 620, 6581, 941, 8694, 462, 3523, + 6654, 1481, 9845, 7439, 7476, 5821, 3819, 9038, + 1144, 6471, 9971, 5535, 9048, 3965, 9361, 1496, + 3009, 6969, 2693, 5755, 2330, 6810, 2352, 1512, + 2523, 9719, 7464, 7771, 8431, 3033, 751, 7904, + 7402, 4660, 2761, 5357, 2617, 5937, 2788, 5153, + 4719, 8910, 4078, 2261, 8892, 8638, 523, 6944, + 2764, 4273, 8230, 3796, 8416, 6433, 7600, 6223, + 3477, 9222, 8330, 8551, 61, 9175, 7442, 4076, + 8823, 9894, 4097, 8187, 9873, 9573, 3391, 4457, + 2092, 2354, 9874, 6178, 6230, 8587, 583, 4119, + 2196, 8390, 9503, 8332, 9211, 1596, 3306, 7433, + 9397, 231, 7884, 9555, 83, 4747, 4305, 5408, + 3811, 4850, 1772, 2406, 1877, 3578, 6173, 7833, + 14, 8328, 2596, 5975, 5184, 5562, 387, 5768, + 3222, 1877, 2477, 8064, 5842, 6208, 4771, 6956, + 5542, 7513, 9381, 7844, 3531, 2747, 5733, 713, + 2053, 2655, 7472, 5000, 4903, 8819, 4211, 9930, + 4030, 1341, 2835, 1622, 12, 8582, 5178, 8384, + 6232, 4624, 9277, 1178, 7232, 4849, 887, 1037, + 4858, 8575, 6772, 5980, 7295, 7449, 9758, 9866, + 709, 3994, 799, 1400, 2397, 7707, 7902, 1208, + 3204, 8039, 8612, 7645, 1835, 8956, 5657, 2088, + 189, 2316, 6271, 218, 6153, 5436, 1, 194, + 2726, 9535, 4441, 3603, 3399, 9412, 4862, 8591, + 9976, 1486, 2073, 3543, 2316, 841, 5016, 4073, + 6014, 6689, 3912, 7333, 9067, 9942, 8796, 7745, + 9452, 8145, 2207, 5872, 3731, 9353, 9948, 9187, + 6536, 8425, 8829, 6688, 6100, 4022, 9374, 4893, + 5752, 13, 5691, 2233, 4334, 5630, 6246, 434, + 1221, 7461, 2426, 5642, 4710, 2812, 1033, 4356, + 3089, 1587, 1993, 6607, 4931, 7635, 1098, 4997, + 23, 2333, 5751, 7215, 2503, 5703, 293, 1194, + 1899, 427, 5631, 1081, 3676, 556, 9765, 5256, + 7616, 7431, 8935, 5493, 652, 6013, 9659, 3691, + 6652, 1760, 4298, 2524, 758, 6723, 9665, 3205, + 9325, 9890, 7705, 8841, 3106, 4116, 3348, 2963, + 7234, 63, 3671, 4198, 1691, 5227, 9985, 6405, + 8748, 830, 6348, 5353, 3024, 5032, 7552, 7653, + 1768, 2704, 6335, 4599, 243, 8332, 3602, 9120, + 9092, 4163, 1618, 9591, 9048, 5124, 6084, 9117, + 6114, 4589, 462, 745, 7286, 6528, 7139, 6347, + 1825, 932, 1067, 293, 443, 6679, 65, 3780, + 4351, 751, 9603, 8711, 5504, 8908, 7748, 8541, + 4250, 7889, 9317, 7250, 2112, 3173, 4267, 5986, + 4804, 1066, 4792, 7231, 1488, 661, 9538, 4177, + 9074, 656, 2338, 5296, 1871, 4347, 8386, 8313, + 2884, 5370, 5220, 7582, 2797, 8578, 8049, 5674, + 3977, 9693, 2366, 545, 869, 6824, 8706, 3830, + 2164, 5089, 2472, 2628, 1004, 2701, 1638, 7113, + 8101, 4748, 929, 8775, 9272, 1560, 8789, 5664, + 8258, 9613, 5486, 4613, 9863, 9005, 5112, 1799, + 4345, 8645, 570, 9967, 6500, 832, 8592, 838, + 9031, 7856, 5907, 381, 2763, 8153, 8398, 995, + 5801, 6346, 1214, 5007, 5316, 6928, 416, 4825, + 5944, 1297, 7549, 1499, 839, 1928, 5878, 5745, + 3272, 2572, 5248, 1460, 3905, 4288, 6818, 2388, + 7859, 9256, 1185, 2181, 3363, 8050, 8380, 9891, + 439, 5568, 8003, 5852, 1229, 9602, 7847, 5969, + 9057, 5525, 970, 1188, 372, 4928, 2344, 9662, + 9190, 1151, 8943, 5226, 1228, 2502, 8609, 9922, + 8201, 8724, 7651, 4046, 9691, 9904, 1535, 8250, + 4015, 5963, 9786, 6581, 8264, 4230, 7914, 2186, + 9235, 6295, 4350, 2794, 3271, 3552, 7515, 6223, + 2140, 4314, 2250, 1975, 627, 4462, 5690, 3413, + 3619, 4409, 8546, 2810, 6451, 8042, 6981, 5847, + 6670, 8620, 6057, 2985, 520, 3854, 5227, 9175, + 7632, 2479, 2790, 9594, 8713, 9800, 6204, 804, + 8244, 513, 650, 8472, 3103, 8833, 3041, 1162, + 1267, 7884, 8114, 5632, 7241, 3921, 9695, 2345, + 756, 9724, 9477, 2820, 7004, 2987, 1515, 6371, + 7318, 7495, 8174, 1492, 1502, 2107, 9841, 9638, + 7642, 9871, 8621, 6991, 2350, 4862, 9372, 1741, + 9751, 3844, 4708, 9941, 942, 865, 2781, 5447, + 15, 528, 3632, 5878, 351, 0, 1393, 8028, + 4688, 8018, 7552, 5798, 3137, 1883, 241, /* * 10000**758 */ + /* 65536**700 = */ 1376, 4586, 3110, 8109, 813, 2413, 7374, 4459, + 7631, 8946, 4454, 2451, 688, 5867, 8242, 3361, + 8832, 4437, 5519, 3061, 364, 4012, 8341, 4231, + 8360, 5724, 6055, 1955, 7486, 8472, 2328, 9617, + 1395, 8211, 2562, 3881, 804, 5684, 1580, 5622, + 253, 2116, 7361, 6279, 8846, 9490, 3076, 6714, + 859, 4921, 470, 1568, 3914, 3534, 5861, 68, + 2260, 9838, 1745, 6725, 9675, 3197, 369, 9299, + 6927, 6882, 1999, 4319, 1994, 6604, 8141, 2440, + 2345, 7443, 449, 202, 4032, 490, 5338, 8768, + 7265, 5012, 8672, 5900, 5541, 4891, 6096, 4383, + 6323, 5870, 1524, 7638, 3400, 6366, 6213, 428, + 1872, 5107, 6186, 2421, 5576, 1881, 8804, 9572, + 7734, 3881, 9595, 2628, 7760, 5058, 7924, 5553, + 5156, 4098, 9186, 269, 8189, 3581, 8233, 6224, + 2891, 7680, 3446, 8138, 7568, 9843, 8204, 1986, + 6126, 3468, 9198, 8388, 1316, 8387, 9313, 3728, + 6889, 9813, 4372, 1967, 8561, 6099, 8106, 4100, + 5281, 3861, 9375, 9097, 9704, 7224, 1961, 2569, + 3683, 6468, 2169, 2345, 5718, 8692, 5385, 7056, + 3147, 1978, 9445, 4762, 5390, 6541, 6663, 8522, + 8775, 8245, 1022, 4, 7451, 1623, 4426, 5431, + 2700, 3478, 216, 8713, 9146, 9152, 9543, 2348, + 201, 5303, 5894, 5551, 3564, 1811, 148, 5018, + 5783, 3415, 2654, 4387, 5930, 7241, 822, 304, + 5280, 4874, 8619, 3871, 6573, 1810, 8121, 6109, + 1252, 8884, 9457, 3422, 7107, 4752, 5692, 3659, + 2111, 406, 6917, 6654, 9902, 5175, 1115, 7073, + 5448, 9436, 637, 3031, 4610, 2213, 8584, 6608, + 8221, 6999, 5789, 9499, 119, 4379, 8719, 2495, + 9433, 5245, 6219, 6585, 1470, 7864, 17, 8133, + 1623, 4331, 9120, 7601, 2788, 4753, 1113, 3304, + 9695, 2285, 9289, 9894, 6930, 3596, 3553, 8327, + 3702, 8520, 952, 6437, 1794, 9348, 2373, 8042, + 9623, 4687, 852, 7710, 2830, 712, 6949, 4962, + 7564, 845, 325, 8598, 5915, 7846, 134, 4092, + 8320, 2594, 3361, 3486, 2148, 3874, 1167, 7721, + 2997, 4766, 7956, 2990, 3706, 6230, 7158, 2270, + 7383, 7156, 220, 461, 4389, 6761, 3391, 7669, + 3533, 4179, 4452, 1983, 96, 4861, 4969, 1955, + 1730, 5804, 2690, 480, 5521, 8307, 9407, 5267, + 5224, 5589, 354, 8171, 1931, 9270, 5338, 6469, + 3134, 2294, 7509, 6092, 7856, 4817, 9694, 9938, + 1734, 183, 3086, 8839, 1378, 1696, 6749, 5189, + 6701, 1425, 6429, 2989, 6291, 4557, 2441, 8383, + 3238, 4712, 9405, 2934, 2351, 5480, 7183, 2544, + 7983, 7358, 4167, 1710, 3735, 3718, 8737, 7750, + 2985, 1040, 7766, 2755, 6766, 6331, 9095, 6047, + 5580, 5501, 6305, 1682, 9474, 461, 3990, 4426, + 8734, 2562, 3942, 9748, 6939, 150, 6359, 7682, + 3379, 1328, 8128, 5972, 6892, 4860, 2107, 3330, + 3704, 1205, 115, 5648, 8256, 3308, 374, 9011, + 8758, 5046, 5154, 5092, 5698, 6810, 7156, 9533, + 3113, 3809, 4000, 4964, 7395, 6816, 1282, 9606, + 9471, 9830, 9937, 3567, 8703, 2376, 6893, 5218, + 7293, 3215, 3398, 8549, 2494, 1587, 3804, 2858, + 9019, 5968, 7835, 5821, 7483, 7121, 544, 9024, + 8399, 7510, 4571, 2094, 3538, 1577, 7130, 5822, + 1996, 1483, 1700, 5527, 570, 791, 2578, 3080, + 4903, 4771, 7320, 1545, 9454, 7539, 4331, 3864, + 9802, 6872, 8528, 3996, 7125, 5732, 9571, 790, + 7470, 9665, 219, 7307, 2199, 2311, 8669, 5264, + 8130, 5497, 6322, 7105, 571, 2920, 8273, 7186, + 9789, 3904, 5074, 2746, 1540, 9054, 395, 3472, + 3313, 2272, 5600, 1972, 5374, 5315, 7487, 3887, + 8919, 1379, 4867, 9911, 159, 1775, 2502, 5278, + 8189, 1751, 649, 4827, 5636, 5922, 8085, 7978, + 3876, 953, 91, 5265, 586, 8369, 1331, 3073, + 5441, 2656, 756, 3750, 5065, 3432, 5601, 2925, + 4324, 3109, 1584, 4244, 9847, 6788, 5544, 6780, + 875, 2974, 1407, 5026, 2485, 3708, 2179, 5846, + 6041, 6243, 9491, 4441, 8586, 1275, 6189, 8674, + 40, 4704, 5642, 9795, 88, 3425, 6010, 8541, + 5143, 7969, 9303, 6803, 2653, 5277, 1220, 2598, + 1511, 617, 5980, 8438, 428, 2439, 9102, 4813, + 534, 1182, 9186, 8299, 9546, 6675, 1047, 6804, + 1680, 2682, 3261, 8008, 6770, 7586, 2977, 4414, + 9460, 434, 7519, 615, 9068, 5178, 7915, 2666, + 3944, 4924, 7855, 2223, 8572, 5298, 1552, 8389, + 4271, 7406, 6363, 7646, 8398, 8160, 2069, 539, + 5033, 7604, 1436, 5275, 482, 4351, 9141, 7999, + 6490, 1856, 3788, 4972, 5139, 4359, 6807, 1250, + 8357, 3359, 3649, 6754, 7053, 8789, 3562, 3793, + 4146, 60, 5998, 7979, 8575, 592, 4584, 4106, + 3404, 7617, 6881, 2697, 3152, 8488, 6329, 3043, + 6970, 9232, 1885, 3130, 4859, 6188, 3885, 1044, + 822, 8498, 6408, 1921, 6737, 8743, 431, 6405, + 7340, 7105, 1238, 6695, 9100, 4467, 5128, 4391, + 4528, 5406, 1064, 8420, 754, 3135, 359, 634, + 5146, 7439, 1807, 1138, 5941, 52, 1554, 8214, + 8509, 3041, 4027, 4222, 1102, 2485, 3258, 3872, + 7554, 6844, 3183, 3660, 6015, 2150, 1179, 4086, + 3006, 5648, 1070, 7839, 9394, 417, 4476, 5914, + 3153, 8151, 8754, 4566, 7354, 2266, 2595, 9675, + 9849, 2561, 3843, 3783, 4417, 1091, 6860, 7239, + 776, 8822, 6599, 1796, 4964, 6626, 1710, 4832, + 1737, 4985, 9724, 500, 8824, 4870, 4557, 3357, + 2631, 1898, 8659, 6055, 6063, 1360, 3880, 6129, + 6219, 2248, 3427, 3819, 9834, 529, 8694, 5071, + 4713, 9682, 7120, 1400, 1385, 3033, 9416, 7959, + 232, 7154, 1288, 5060, 4686, 6550, 9634, 4993, + 3244, 3205, 2668, 4768, 7732, 5099, 1453, 8980, + 281, 144, 5597, 4066, 5746, 2220, 2838, 9818, + 910, 3708, 5565, 8463, 8273, 2742, 3946, 304, + 6406, 1028, 9203, 2140, 3691, 2406, 1882, 426, + 2922, 1953, 3435, /* * 10000**842 */ + /* 65536**770 = */ 6576, 245, 6356, 5875, 2422, 9666, 6333, 951, + 150, 2145, 7477, 5966, 1410, 2763, 307, 9452, + 5802, 5729, 1339, 3258, 2063, 9970, 6176, 1754, + 4757, 3297, 966, 8543, 8894, 117, 6213, 2274, + 4313, 8739, 3420, 691, 5977, 4505, 2536, 2997, + 3881, 3568, 1510, 5728, 6781, 9126, 7767, 1593, + 9017, 7864, 1976, 3746, 7862, 5273, 5257, 3301, + 8551, 2783, 2395, 7645, 315, 6447, 7429, 2440, + 943, 3567, 1927, 4649, 8911, 9014, 7172, 1994, + 6157, 4143, 8757, 2551, 3648, 9689, 5687, 6387, + 9358, 3878, 3632, 3984, 7237, 2547, 9700, 993, + 2278, 5799, 2100, 1748, 7385, 9669, 7791, 8150, + 6319, 2225, 9870, 9690, 884, 2677, 3804, 2903, + 2175, 5452, 7358, 8961, 7445, 515, 9507, 2931, + 7139, 9066, 276, 3657, 4963, 1907, 2044, 603, + 5124, 7175, 7031, 7712, 4449, 9865, 5262, 5849, + 9041, 3705, 6218, 4092, 1255, 2007, 9678, 3624, + 5180, 3538, 8771, 8142, 5087, 8757, 6817, 3082, + 3769, 7244, 4883, 4619, 4167, 1699, 9115, 9182, + 1348, 2906, 6991, 5382, 3461, 8628, 7028, 9325, + 3587, 7188, 4383, 9966, 7798, 105, 2955, 7538, + 2950, 3988, 9142, 6793, 5340, 3555, 1117, 5218, + 6349, 7006, 3785, 9480, 9839, 4795, 7464, 9682, + 7006, 4058, 4110, 4069, 1190, 4288, 2430, 8454, + 3076, 1395, 6594, 9163, 7479, 8065, 4755, 4874, + 647, 6200, 3270, 4761, 1485, 8860, 4861, 2395, + 1448, 8327, 776, 9899, 8277, 9220, 3382, 2782, + 3123, 5194, 3714, 4997, 1538, 2611, 9158, 9311, + 8857, 2483, 4214, 3062, 4880, 7846, 8772, 8092, + 3695, 7541, 9097, 667, 7806, 5727, 2261, 5090, + 5471, 9091, 3406, 422, 3994, 6902, 5228, 1216, + 1965, 375, 2757, 996, 4155, 1371, 5076, 7668, + 940, 2295, 8732, 9059, 8808, 6358, 2737, 8179, + 5344, 4418, 7027, 3631, 7129, 1789, 96, 7192, + 1246, 891, 8740, 2336, 4936, 2213, 1414, 7793, + 3041, 8231, 6528, 7078, 299, 7293, 1683, 8208, + 8097, 1670, 6643, 7366, 5146, 9629, 9972, 2977, + 9684, 1445, 2334, 7490, 1104, 6613, 6778, 2262, + 517, 4530, 4411, 8052, 2891, 5782, 3582, 7797, + 2650, 7112, 9324, 6077, 1036, 217, 980, 5753, + 9082, 1275, 6766, 2989, 6223, 2611, 2289, 9995, + 0, 7007, 3794, 3507, 9401, 7170, 8065, 7505, + 5429, 8108, 57, 4816, 6308, 795, 5172, 9799, + 514, 8369, 6605, 2125, 8482, 4855, 5695, 7116, + 2726, 6596, 5449, 1018, 7187, 8663, 6383, 5434, + 5472, 111, 1133, 7483, 572, 2642, 7374, 3672, + 6578, 1601, 5038, 1935, 8108, 8112, 219, 5137, + 9883, 1208, 4391, 872, 4997, 9658, 6156, 4152, + 247, 7022, 1720, 3435, 3669, 892, 3328, 3906, + 9750, 9679, 3130, 1096, 2598, 8077, 5644, 9251, + 4790, 7079, 4824, 248, 6992, 13, 4271, 385, + 2690, 2875, 7987, 6637, 9248, 6579, 9888, 4147, + 5376, 4578, 8170, 9261, 7266, 9739, 5526, 3243, + 1271, 6280, 134, 2294, 1169, 6079, 629, 2541, + 571, 1074, 4067, 6219, 6141, 4059, 7791, 6269, + 4370, 504, 2106, 4204, 12, 396, 8296, 6851, + 5299, 1980, 2205, 6099, 7526, 8617, 1275, 7304, + 4306, 3079, 7189, 7371, 5846, 1884, 1101, 8229, + 73, 4440, 531, 5649, 4927, 9063, 6529, 6352, + 1199, 4855, 1212, 9365, 1939, 4630, 8322, 1252, + 9242, 2296, 6277, 3508, 6969, 8655, 5338, 8780, + 7263, 603, 9464, 7296, 5563, 9966, 3937, 7009, + 529, 8557, 2752, 5988, 9040, 1872, 541, 8295, + 4144, 2418, 3603, 269, 8858, 9362, 2376, 1882, + 225, 7448, 2381, 1931, 426, 2059, 3337, 7981, + 6221, 8665, 5603, 2085, 651, 6853, 1798, 5910, + 8799, 3888, 1917, 5075, 7299, 2087, 4433, 5613, + 437, 8893, 3374, 5536, 8180, 2413, 3805, 4782, + 5355, 7634, 833, 828, 4318, 6069, 1943, 6953, + 3331, 9719, 1055, 7989, 8882, 7868, 3167, 1941, + 5715, 9354, 8646, 6553, 8643, 2581, 3241, 6665, + 3936, 5677, 776, 8961, 2596, 1404, 8448, 3466, + 8374, 6407, 9540, 3608, 8614, 6021, 573, 949, + 8416, 7147, 8621, 2691, 6429, 8691, 7634, 772, + 89, 2786, 7169, 6823, 9486, 7807, 1554, 1429, + 8278, 3688, 5352, 4658, 8852, 9013, 9163, 5624, + 2363, 8992, 7480, 9099, 5429, 8079, 1235, 1177, + 8441, 9443, 8841, 1526, 899, 4690, 7947, 9598, + 210, 8061, 5363, 8632, 8660, 3791, 7135, 5744, + 3939, 5190, 4819, 8291, 1515, 7886, 3114, 6952, + 2498, 5758, 245, 1104, 6047, 2056, 3379, 7991, + 6993, 7720, 1746, 4440, 7800, 3194, 2512, 4296, + 3072, 8662, 1929, 7680, 4080, 4999, 7253, 6706, + 65, 8144, 5567, 3131, 3500, 8032, 3210, 8721, + 9733, 246, 3335, 8139, 2564, 2307, 5130, 7685, + 6143, 2690, 4963, 9028, 3967, 8385, 6454, 3020, + 3844, 1893, 2889, 5541, 8504, 374, 7689, 2068, + 4199, 6632, 6003, 4161, 7427, 5366, 3837, 7481, + 4184, 4059, 6669, 2982, 6572, 7942, 6892, 3090, + 9143, 4052, 988, 8996, 7508, 2430, 3054, 6349, + 4014, 4949, 6171, 2648, 9933, 1038, 3046, 8955, + 3754, 4123, 3175, 3938, 2682, 3831, 9513, 1213, + 394, 783, 5094, 8043, 4966, 3131, 6018, 9166, + 7031, 7139, 5518, 4981, 5179, 8622, 2757, 9262, + 3635, 2899, 5093, 9238, 8975, 2374, 4244, 8814, + 31, 6851, 2453, 7638, 528, 6045, 3521, 4686, + 5415, 6689, 4342, 4629, 1928, 2182, 968, 3344, + 7654, 6088, 5259, 9531, 2122, 8346, 4173, 735, + 9159, 4533, 7493, 6745, 2635, 6334, 7907, 7916, + 2572, 478, 8063, 2679, 4777, 1168, 5397, 5514, + 1663, 2579, 6615, 1964, 8593, 5498, 6036, 7463, + 8815, 1208, 5069, 5234, 609, 8966, 4552, 1157, + 2099, 44, 1001, 9393, 8254, 196, 1517, 113, + 3557, 5894, 6684, 6020, 2640, 3565, 672, 5834, + 8844, 3245, 3912, 4242, 480, 3940, 3700, 9274, + 4416, 2558, 4846, 4828, 5599, 9101, 6419, 1439, + 5164, 5219, 3056, 2619, 5510, 7513, 2339, 2952, + 7539, 2728, 6880, 2140, 406, 3032, 5314, 2592, + 6889, 4490, 2748, 8871, 3996, 3202, 6519, 2460, + 7927, 8324, 2242, 7373, 9534, 7626, 7641, 4965, + 3972, 5369, 3904, 2053, 8744, 8630, 124, 1431, + 1643, 5368, 7730, 1757, 2613, 7414, 225, 9158, + 7726, 197, 2648, 9531, 7062, 2318, 8972, 433, + 458, 7883, 8832, 2662, 3314, 8091, 6748, 5703, + 5124, 7447, 8008, 9237, 6696, 7880, 28, 8663, + 525, 2906, 7521, 2442, 7245, 7738, 8926, 4, + /* * 10000**927 */ + /* 65536**840 = */ 1776, 4209, 107, 8907, 5829, 8291, 3792, 7140, + 8690, 5729, 1980, 8333, 6343, 4729, 4891, 6613, + 1876, 7120, 2857, 4433, 4445, 5275, 7171, 48, + 9321, 7844, 7123, 2851, 7177, 8795, 9744, 9639, + 2481, 2561, 4398, 8938, 6005, 3603, 9539, 4851, + 6380, 6376, 5478, 9062, 2258, 8093, 4242, 3610, + 6371, 1120, 9049, 432, 8580, 9844, 443, 4598, + 4973, 845, 5958, 5061, 7948, 9512, 9145, 8386, + 7212, 126, 1672, 1176, 9349, 4654, 4602, 814, + 7191, 2008, 4459, 5745, 7526, 646, 5999, 9963, + 8550, 9791, 7786, 277, 6598, 7600, 901, 3352, + 8074, 3157, 3661, 6470, 905, 3657, 4173, 4804, + 6683, 9857, 4353, 1123, 8293, 669, 6879, 594, + 353, 1428, 3387, 5667, 8085, 1175, 4243, 393, + 6238, 449, 5931, 3907, 1424, 3236, 205, 3023, + 6171, 188, 7723, 9095, 1359, 1890, 1791, 8386, + 444, 162, 2509, 3757, 3354, 2757, 231, 6664, + 6929, 6426, 9025, 937, 1175, 7815, 5138, 5412, + 9050, 8921, 9895, 949, 2682, 909, 9622, 5279, + 1797, 7274, 4291, 3764, 3575, 9282, 6469, 2980, + 3245, 4850, 6847, 3690, 5293, 5479, 8362, 264, + 8983, 2738, 1503, 6814, 1557, 2719, 9253, 5235, + 9351, 1013, 8631, 7562, 7326, 2565, 5343, 3416, + 3876, 2749, 5448, 9776, 3548, 2345, 8095, 5557, + 5994, 1001, 201, 6028, 4903, 5273, 4875, 3387, + 9854, 5952, 8239, 532, 4892, 4540, 9787, 1357, + 2935, 7540, 7254, 295, 3020, 4145, 9693, 3272, + 4423, 6528, 7824, 9108, 8383, 6625, 3156, 5428, + 8091, 1867, 6682, 7034, 7554, 883, 4275, 763, + 4093, 692, 7649, 4523, 2587, 8443, 2065, 5289, + 9385, 6198, 7308, 5388, 4113, 3746, 2214, 4397, + 4402, 6210, 4346, 199, 1021, 9899, 5375, 5990, + 9027, 7089, 3338, 5270, 1537, 9622, 1888, 1494, + 9477, 8020, 3438, 4614, 5382, 9984, 8216, 4446, + 3556, 3442, 1354, 3210, 5823, 5800, 6798, 3366, + 2968, 1726, 7017, 5620, 5685, 7769, 1878, 7500, + 6906, 3901, 6414, 5479, 2752, 711, 1004, 8708, + 4338, 9854, 8760, 1031, 3150, 743, 967, 684, + 7982, 5422, 6089, 7801, 1017, 3190, 1700, 5919, + 5483, 6599, 7922, 2498, 3262, 4877, 2088, 1374, + 4022, 8151, 1697, 2456, 6997, 7997, 7193, 4662, + 7068, 6463, 3470, 8660, 3199, 7435, 5453, 1076, + 419, 2619, 1406, 6533, 9911, 5996, 9877, 4978, + 7672, 1304, 822, 4811, 7474, 9591, 1426, 9125, + 9955, 1525, 5834, 5706, 5982, 3518, 5423, 6252, + 1064, 2787, 605, 1021, 4464, 1705, 4838, 9614, + 319, 2323, 8396, 3547, 53, 6057, 9843, 4142, + 9535, 8053, 2223, 5879, 8446, 8236, 5036, 8137, + 9073, 2448, 8498, 6342, 6345, 9231, 4639, 9982, + 1217, 5858, 1892, 9155, 8981, 1331, 5526, 8429, + 7349, 9100, 8885, 3800, 9082, 5906, 8711, 8499, + 5398, 2333, 2499, 1358, 5396, 4550, 5870, 8484, + 5564, 9294, 9792, 6786, 1836, 6702, 1679, 9666, + 135, 7422, 5626, 6295, 7828, 7080, 3345, 185, + 3703, 6082, 2495, 8876, 5184, 3822, 7532, 8564, + 2685, 1624, 5515, 9775, 308, 9383, 8733, 3077, + 7284, 7302, 35, 9581, 4927, 7462, 4845, 3331, + 5693, 4714, 8522, 2192, 964, 8033, 2145, 732, + 5792, 9066, 856, 2601, 577, 8527, 5526, 5967, + 8391, 3060, 4344, 853, 3311, 6918, 8370, 5791, + 6755, 9258, 1964, 3862, 7326, 2755, 1576, 1675, + 119, 386, 2571, 8189, 3370, 701, 3281, 710, + 8885, 6139, 9961, 8922, 8174, 8375, 6138, 9847, + 4854, 5777, 8551, 7930, 7401, 3457, 3143, 1508, + 5753, 3694, 5993, 5228, 5480, 2515, 6763, 8335, + 9088, 4979, 7987, 5760, 3039, 5766, 5868, 1932, + 3435, 8274, 1667, 8305, 9678, 5741, 5193, 9322, + 9946, 2433, 928, 3582, 8437, 5169, 7521, 9860, + 9741, 840, 26, 7364, 2620, 7373, 1114, 7601, + 7048, 5289, 8616, 2816, 9703, 3595, 2060, 5086, + 2673, 3530, 1359, 1861, 4220, 3700, 899, 1352, + 5551, 1020, 5759, 8483, 992, 8250, 9411, 3180, + 6634, 856, 6254, 6194, 3917, 9296, 9035, 2348, + 9174, 7872, 3374, 8845, 3908, 3210, 8206, 3901, + 1083, 2442, 6626, 7538, 1519, 2002, 5375, 1211, + 4597, 1027, 8913, 2970, 5316, 2039, 3828, 9530, + 8672, 1290, 6243, 8398, 7670, 584, 8554, 9782, + 4689, 2322, 3891, 5570, 2441, 3620, 2995, 7453, + 7493, 7524, 9193, 1840, 8562, 7087, 8880, 1692, + 9390, 2120, 6310, 1186, 3800, 4528, 2717, 3715, + 4188, 848, 3877, 973, 8688, 171, 3610, 1814, + 4226, 8168, 4374, 640, 1652, 9149, 1983, 7776, + 5724, 8085, 7642, 4732, 4416, 6266, 5192, 6489, + 4151, 5721, 1778, 2708, 6310, 8698, 8896, 1888, + 8171, 3950, 4756, 4292, 2005, 4487, 6940, 3027, + 8680, 4280, 8169, 7400, 8615, 848, 4686, 4370, + 1307, 1776, 7336, 6208, 5860, 6436, 695, 2444, + 2655, 2326, 4144, 5741, 3920, 5873, 4979, 7768, + 5503, 7203, 2283, 7788, 2037, 9131, 2916, 8724, + 4754, 8308, 2395, 6739, 485, 8073, 7861, 1191, + 981, 1998, 4277, 2306, 5509, 2861, 676, 5039, + 4515, 6900, 2085, 7407, 2948, 4810, 7243, 8107, + 6124, 3955, 3517, 1027, 1467, 8102, 4121, 3754, + 9510, 2956, 3027, 944, 8889, 8388, 2269, 8781, + 8941, 503, 1588, 7452, 9731, 7045, 9086, 8895, + 90, 3144, 5569, 1415, 3996, 8866, 4640, 3533, + 3634, 4686, 8961, 5342, 8259, 8604, 9081, 9368, + 7927, 6117, 7509, 8903, 3256, 7008, 3099, 3508, + 3273, 9709, 9373, 1374, 8944, 3639, 8505, 4042, + 12, 530, 9273, 4801, 761, 4913, 6606, 6739, + 5605, 5637, 719, 6984, 1130, 1078, 8796, 4411, + 7204, 8668, 5225, 1596, 8800, 8083, 5620, 910, + 8022, 8753, 5414, 3163, 9797, 2492, 2109, 9440, + 9737, 3659, 2952, 913, 4297, 3855, 6891, 6867, + 5392, 9757, 9361, 4312, 5415, 3533, 5994, 513, + 3224, 3486, 346, 4150, 2752, 5895, 3247, 2275, + 5137, 5424, 6854, 9918, 2273, 7434, 6655, 2269, + 9720, 3915, 9785, 8604, 3799, 6065, 4070, 2204, + 2145, 4721, 6743, 8533, 4504, 4512, 8547, 8199, + 8506, 3184, 2829, 8578, 5963, 9629, 3319, 1411, + 784, 9160, 3925, 2117, 8216, 8156, 5230, 1021, + 8468, 9979, 199, 6132, 4556, 3388, 4447, 1503, + 9203, 4028, 4633, 4537, 9846, 7104, 966, 9786, + 2402, 6280, 8393, 3514, 3675, 5066, 45, 5484, + 8185, 6376, 6151, 3773, 8101, 8363, 7257, 2164, + 3548, 1215, 4667, 559, 511, 5707, 5787, 7552, + 6589, 8935, 2179, 1088, 2297, 2033, 1133, 574, + 8896, 3265, 2681, 3424, 2090, 7972, 4505, 1357, + 7108, 8543, 9500, 3580, 1116, 5400, 236, 7512, + 4229, 8918, 1198, 544, 6951, 1621, 3290, 8406, + 6135, 1400, 78, 9094, 1289, 9849, 4254, 3557, + 696, 483, 5400, 2399, 2703, 409, 1518, 1043, + 8505, 1877, 6060, 3483, 9219, 914, 4416, 2185, + 6440, 7397, 2019, 4889, 9143, 6834, 3063, 8356, + 3821, 7035, 1972, 8312, 1494, 4774, 9537, 8837, + 5645, 2248, 9105, 2307, 8597, 8588, 1190, 7930, + 8253, 8822, 6853, 69, /* * 10000**1011 */ + /* 65536**910 = */ 6976, 7276, 8858, 1221, 9753, 5084, 4453, 1746, + 2564, 5306, 1580, 9569, 1433, 6440, 9350, 1312, + 163, 2607, 7092, 9083, 4624, 8203, 8919, 7749, + 3440, 6823, 6182, 2031, 7548, 5547, 4636, 5050, + 5758, 7923, 4655, 1010, 9987, 772, 7430, 7397, + 8813, 2398, 8251, 2488, 2603, 118, 1294, 227, + 9376, 9951, 3868, 1075, 5311, 7911, 4461, 8224, + 274, 2903, 9270, 3359, 2746, 3671, 2503, 7591, + 6718, 4357, 8995, 4873, 2301, 2009, 7763, 4513, + 4937, 3992, 1217, 3614, 7118, 5669, 5378, 1265, + 1379, 7102, 7925, 1319, 1768, 3234, 8757, 2335, + 3113, 1722, 6896, 563, 7461, 4313, 9102, 1117, + 9118, 9666, 6719, 1369, 4573, 3534, 3090, 3498, + 7834, 2943, 8466, 9411, 6501, 9251, 2604, 892, + 466, 4658, 6553, 3949, 377, 2602, 284, 99, + 2675, 9445, 2191, 5520, 5423, 3134, 7131, 8653, + 4866, 284, 5986, 9313, 3557, 1286, 1602, 1116, + 2596, 5249, 6799, 8663, 1549, 7218, 8045, 5368, + 8620, 85, 8305, 8144, 6653, 4913, 796, 5668, + 471, 8853, 7640, 5428, 3341, 4658, 7712, 5801, + 3405, 3699, 207, 6821, 3089, 3959, 5917, 1322, + 7214, 438, 7617, 1547, 4391, 183, 4965, 5172, + 8933, 4752, 479, 9733, 950, 7810, 5681, 3581, + 4162, 4049, 3572, 3884, 1211, 7627, 6099, 4410, + 7572, 7868, 229, 3452, 1679, 6516, 782, 9064, + 5097, 4056, 5308, 424, 847, 8447, 1214, 4563, + 763, 7166, 8506, 1912, 4796, 2775, 3847, 35, + 5471, 2069, 3525, 3321, 4709, 8304, 3015, 3633, + 1027, 9475, 4081, 15, 9395, 7495, 5293, 1385, + 707, 4543, 4533, 15, 2282, 6080, 6456, 7843, + 8776, 2104, 5874, 3666, 3846, 6178, 7517, 9013, + 1282, 5177, 3730, 5068, 2562, 1258, 266, 4640, + 9320, 2217, 1078, 8299, 3147, 5444, 2258, 6110, + 5603, 4852, 4268, 8378, 1360, 7766, 3834, 2833, + 2966, 498, 1814, 5324, 8535, 3968, 4782, 6038, + 5348, 5378, 8407, 7004, 3934, 5886, 6509, 4476, + 2518, 942, 387, 7880, 310, 2194, 789, 9524, + 3994, 6498, 4676, 2194, 7029, 1471, 7694, 9214, + 4989, 807, 9958, 2955, 1408, 9697, 9369, 4043, + 690, 8441, 3288, 8437, 1376, 4984, 1291, 8808, + 8585, 9792, 8599, 7985, 2883, 8551, 9600, 8612, + 8145, 8093, 5364, 7581, 6825, 892, 9161, 7353, + 5283, 6962, 4767, 4665, 8637, 8511, 8351, 9611, + 3276, 9081, 4325, 3128, 7232, 9014, 9828, 7083, + 2200, 3406, 4976, 3646, 4736, 5100, 1263, 7919, + 1368, 83, 7397, 8019, 626, 1181, 8554, 9738, + 9409, 5766, 9788, 6858, 6925, 6625, 9783, 5868, + 6651, 3983, 8582, 2528, 9149, 186, 7976, 295, + 4158, 4110, 3783, 1155, 1983, 4097, 2663, 3665, + 5049, 8310, 2361, 5778, 8997, 1458, 2437, 3930, + 1459, 3258, 8915, 5745, 9011, 1080, 8782, 2896, + 4877, 3522, 7368, 8059, 9387, 4871, 3417, 9118, + 6149, 5578, 2863, 325, 4461, 7766, 3619, 6858, + 6849, 1017, 9989, 7450, 1635, 5741, 6046, 8153, + 1705, 7337, 1343, 4508, 2940, 2177, 8291, 3668, + 3988, 7230, 9741, 9276, 1492, 9060, 5831, 1915, + 4323, 3327, 5156, 7634, 5667, 93, 1615, 7146, + 384, 1403, 7450, 648, 397, 3380, 8248, 1488, + 8379, 2229, 9203, 481, 9153, 8241, 705, 9533, + 7505, 3015, 9070, 125, 4603, 8425, 5131, 8879, + 2839, 4140, 6128, 5688, 1555, 2700, 6136, 9704, + 8254, 4678, 981, 264, 9401, 7255, 3538, 8116, + 2324, 280, 7020, 4111, 5298, 9315, 3155, 4012, + 8476, 2668, 2959, 543, 8033, 1389, 3592, 5881, + 3970, 1845, 1091, 1032, 5505, 9360, 7060, 667, + 6498, 9986, 6028, 6059, 2489, 6376, 6771, 8583, + 4217, 3978, 6537, 2508, 9228, 9830, 2933, 2459, + 8427, 1706, 8995, 5630, 4841, 5215, 6392, 6342, + 5770, 4998, 9239, 6236, 9028, 5774, 6114, 3192, + 5621, 2678, 2250, 3881, 2567, 9124, 9573, 1676, + 2312, 1368, 6964, 3234, 4195, 9740, 5063, 9313, + 8299, 611, 4657, 6404, 1343, 7887, 8822, 8197, + 5746, 7804, 5463, 2033, 3102, 6063, 2280, 6637, + 1051, 2474, 4788, 2287, 7937, 9814, 3499, 7309, + 1637, 7193, 6908, 5451, 3257, 2935, 3737, 3206, + 8537, 9857, 2923, 667, 1218, 3142, 9336, 5960, + 8995, 7527, 2049, 7522, 8223, 5862, 1222, 9496, + 2180, 3866, 8448, 6658, 9447, 819, 9613, 5574, + 9317, 1802, 3131, 3030, 8763, 4072, 4076, 7598, + 8667, 3937, 1660, 5038, 187, 5592, 840, 8447, + 9967, 4635, 9237, 7598, 9848, 2653, 3049, 3750, + 5699, 501, 3604, 2456, 8654, 9459, 3750, 2733, + 7222, 5883, 5306, 5175, 8727, 2434, 4666, 8910, + 7732, 2483, 1128, 8416, 8276, 4920, 5230, 732, + 264, 4622, 4744, 4607, 1765, 7218, 6301, 5284, + 5847, 9294, 9827, 7152, 5212, 7979, 7615, 346, + 9431, 9390, 6846, 4592, 3987, 9010, 6105, 7017, + 2309, 1668, 8732, 7920, 4915, 189, 4196, 2592, + 6493, 6397, 7470, 8439, 500, 7208, 5090, 7817, + 3410, 1055, 3293, 8207, 7000, 3912, 627, 465, + 5905, 6474, 2596, 2542, 778, 300, 5879, 416, + 4448, 209, 6162, 8063, 3755, 7192, 5775, 3507, + 2520, 9838, 7927, 343, 7467, 8024, 3848, 1883, + 5174, 5680, 8899, 7719, 4619, 5499, 6810, 6724, + 7123, 6290, 1740, 8554, 5207, 1737, 757, 8732, + 1574, 1745, 1252, 107, 5059, 759, 6479, 2507, + 9607, 6267, 6763, 9485, 1818, 1684, 8360, 6300, + 4553, 7822, 2597, 1854, 1975, 4238, 7314, 8224, + 6705, 8199, 4727, 7715, 2855, 6660, 1739, 3406, + 6535, 43, 1242, 296, 7753, 2009, 5291, 821, + 18, 1348, 6704, 5226, 437, 3221, 1962, 4528, + 1858, 284, 7106, 560, 2332, 416, 6562, 6435, + 2683, 5055, 1485, 3514, 9627, 1215, 6205, 1477, + 6555, 4687, 3258, 3747, 9818, 9762, 1986, 7259, + 28, 2493, 9870, 9052, 1720, 8645, 1800, 5327, + 7511, 658, 2621, 7002, 8181, 8866, 1088, 5519, + 209, 1740, 7793, 3014, 1175, 5203, 4023, 6554, + 2270, 5199, 858, 1103, 1175, 9769, 833, 2917, + 7007, 2643, 2767, 8226, 4073, 6218, 6074, 1207, + 6949, 4017, 6636, 5655, 8096, 9055, 2536, 9186, + 8843, 1363, 5220, 3307, 2440, 6009, 9620, 6050, + 1115, 4676, 3791, 977, 9909, 7363, 8927, 6256, + 62, 559, 5329, 6245, 5692, 5519, 2414, 5324, + 8526, 6190, 9466, 3871, 6430, 5570, 8518, 3076, + 4532, 8548, 1161, 3916, 9511, 356, 1491, 1877, + 5183, 6069, 4894, 9405, 3707, 6403, 8855, 6093, + 6422, 9704, 8695, 3494, 2905, 1988, 3599, 945, + 635, 4691, 3183, 3024, 9662, 835, 6925, 3011, + 3908, 2017, 5279, 8224, 4096, 9738, 901, 1320, + 2166, 1263, 9773, 1622, 5610, 5924, 4911, 7663, + 5610, 524, 6658, 5441, 179, 749, 4203, 4005, + 5667, 9337, 33, 8313, 262, 2359, 9623, 8540, + 7893, 8663, 7047, 8786, 4550, 3678, 3447, 1408, + 7314, 8285, 3199, 1835, 5737, 7556, 7294, 8703, + 8128, 9057, 8403, 4123, 6700, 6751, 1483, 9449, + 473, 4244, 8907, 6359, 5562, 1974, 3050, 8446, + 8917, 251, 6614, 7901, 1243, 9635, 3181, 8615, + 5248, 5140, 9350, 5142, 76, 6633, 8022, 4730, + 1918, 6607, 7956, 7681, 8077, 1116, 271, 5575, + 3878, 500, 2472, 7001, 5866, 7249, 1797, 9779, + 6083, 6938, 6244, 6041, 5725, 4592, 9808, 346, + 7514, 8583, 4325, 4357, 2303, 7553, 2057, 7873, + 731, 3634, 4935, 6612, 993, 341, 4071, 9185, + 9884, 4686, 1924, 487, 2122, 3551, 8157, 4261, + 5804, 9007, 3999, 7058, 2929, 3813, 6266, 9248, + 3732, 7720, 2932, 4846, 9009, 5513, 386, 5866, + 6709, 1187, 3069, 5947, 1009, 1673, 5145, 992, + /* * 10000**1095 */ + /* 65536**980 = */ 2176, 248, 1520, 1891, 317, 4171, 757, 8470, + 652, 7083, 8338, 6493, 4307, 8339, 1485, 8274, + 9486, 5402, 7939, 165, 7113, 9646, 2927, 6165, + 5955, 9620, 9187, 4373, 6839, 1506, 6488, 8229, + 4865, 6749, 5419, 1020, 7004, 8972, 3246, 7404, + 935, 2842, 1856, 9433, 2067, 6350, 9296, 492, + 9336, 8036, 7456, 4970, 3370, 6744, 9291, 1339, + 3023, 9520, 6938, 491, 7452, 8359, 9349, 6900, + 9125, 4234, 4245, 4886, 8311, 2065, 9189, 8952, + 303, 5958, 7274, 6088, 2313, 4527, 7803, 2173, + 3259, 8336, 7826, 2669, 367, 1056, 4270, 5660, + 9691, 4897, 3869, 7976, 41, 1111, 2781, 7089, + 4609, 8652, 164, 7944, 9031, 1555, 5491, 3585, + 2999, 3852, 8420, 7772, 969, 8120, 5102, 4406, + 1136, 1437, 3008, 2149, 599, 7074, 9892, 5579, + 9743, 5835, 8891, 5006, 5570, 2243, 384, 6609, + 1133, 7279, 8904, 2863, 3066, 2014, 8748, 4461, + 2650, 1866, 288, 6998, 5516, 3897, 1166, 9797, + 8531, 8250, 7831, 3696, 870, 7023, 389, 7558, + 1999, 8258, 2046, 7513, 2811, 8238, 1173, 5128, + 122, 4675, 7237, 8182, 9434, 3240, 8220, 7546, + 8358, 9730, 9714, 8782, 2992, 8324, 9009, 9726, + 7008, 9997, 5661, 2033, 1192, 761, 4021, 7857, + 8964, 6300, 3078, 4631, 3885, 8829, 5412, 8533, + 4943, 9925, 503, 4646, 296, 8615, 1814, 2856, + 7475, 6102, 8949, 418, 9540, 2480, 2129, 7414, + 9899, 4415, 2420, 2374, 8697, 8448, 8389, 7107, + 1253, 1244, 5943, 7751, 5903, 2021, 1474, 7634, + 7301, 718, 3185, 8741, 2753, 2589, 7111, 6699, + 2626, 2326, 3628, 9551, 9923, 2100, 4313, 7508, + 9937, 857, 1179, 1855, 629, 1816, 5015, 4599, + 2703, 2364, 5149, 2416, 7588, 8446, 9864, 9747, + 852, 1958, 6390, 9211, 613, 3992, 2800, 79, + 6870, 5815, 7821, 8733, 9913, 4655, 3430, 5757, + 986, 8621, 7406, 8629, 7657, 9176, 9632, 1725, + 1371, 2317, 8136, 3049, 6937, 4684, 9733, 1710, + 5797, 5178, 3269, 189, 2095, 3335, 4981, 5396, + 4385, 4817, 1469, 2289, 4091, 2694, 7790, 8184, + 3667, 4975, 6886, 9264, 718, 8665, 388, 712, + 2259, 1874, 3031, 5644, 9660, 8683, 8488, 5076, + 9643, 9501, 1888, 5081, 1651, 4604, 4374, 8112, + 2414, 6612, 9929, 6241, 5596, 1128, 2103, 4114, + 6934, 3602, 1823, 2207, 5530, 2980, 2658, 5633, + 6674, 7776, 5101, 8530, 1935, 7744, 1424, 8220, + 8128, 4931, 1355, 7845, 6170, 9867, 6584, 6935, + 6795, 5163, 7645, 7867, 4345, 344, 1026, 2615, + 2625, 8149, 5050, 6811, 7299, 8987, 7386, 8553, + 7549, 2918, 4748, 950, 8418, 2389, 7522, 2261, + 255, 8942, 7767, 6011, 820, 8949, 5517, 490, + 5373, 781, 9901, 6177, 3439, 4703, 1761, 5121, + 7534, 7327, 4637, 4787, 4313, 3097, 3202, 1610, + 2764, 3750, 4394, 8205, 1931, 1077, 5151, 1179, + 4549, 5279, 8522, 4711, 3315, 4642, 5964, 6940, + 6983, 6916, 5068, 9367, 1156, 9702, 6608, 670, + 195, 1247, 328, 7188, 4002, 5834, 5307, 684, + 8962, 2762, 7862, 5007, 9687, 9931, 7972, 6337, + 4225, 5619, 4964, 8533, 6248, 7185, 4312, 6265, + 5874, 6340, 5018, 6652, 8458, 5872, 770, 554, + 1302, 4058, 8248, 4358, 4652, 6024, 890, 4875, + 2705, 5584, 7538, 976, 5571, 360, 1820, 3412, + 6038, 6315, 9315, 6561, 4197, 4690, 9422, 9752, + 3733, 7172, 9556, 3042, 4647, 5338, 6505, 5121, + 2219, 6640, 8273, 1078, 8827, 2091, 623, 6853, + 6117, 9542, 8504, 5937, 2070, 8902, 4059, 8539, + 8624, 8109, 4590, 1628, 6268, 9461, 7165, 9491, + 4033, 4220, 8426, 396, 2679, 1851, 8628, 3905, + 1106, 4994, 2277, 6769, 4436, 3506, 5218, 8859, + 7428, 7126, 4193, 6588, 1522, 6658, 2167, 4533, + 2632, 8226, 468, 5175, 8409, 9024, 9564, 1863, + 4504, 9182, 2197, 8657, 8529, 1546, 4264, 9014, + 6824, 106, 5357, 8213, 8963, 3340, 638, 1656, + 9952, 4541, 1058, 8801, 9759, 2222, 2920, 1735, + 5882, 321, 1602, 2695, 8764, 2383, 9357, 6416, + 6598, 2886, 4225, 3840, 2473, 2140, 3062, 7970, + 8073, 9445, 2112, 8917, 2596, 171, 5587, 524, + 8222, 6139, 3895, 9767, 2438, 2422, 2005, 5505, + 4947, 4718, 5294, 2535, 7980, 951, 8984, 1407, + 1440, 3542, 2134, 3317, 4770, 128, 8450, 1947, + 1460, 3424, 5633, 2582, 649, 519, 8207, 6121, + 6139, 9894, 9980, 1710, 9769, 5225, 284, 7703, + 2624, 8299, 8939, 3596, 6656, 2936, 4770, 147, + 2739, 1940, 8867, 4694, 9518, 867, 3069, 9403, + 9348, 2490, 1169, 8508, 853, 8050, 131, 3801, + 3028, 6506, 5448, 2260, 8910, 5919, 670, 1208, + 1218, 228, 6106, 2550, 9642, 6253, 1298, 6945, + 9839, 7653, 3981, 9028, 4597, 4675, 4894, 9260, + 6700, 9025, 5944, 4541, 5170, 3888, 2026, 1647, + 8420, 4215, 2651, 1370, 5805, 7668, 9641, 8292, + 4721, 5231, 8320, 3, 8444, 2102, 1581, 3061, + 1034, 5466, 910, 9717, 9852, 6767, 317, 2826, + 4926, 9635, 1398, 9416, 1139, 6713, 1096, 9345, + 6737, 548, 7124, 4403, 2439, 8806, 9365, 5021, + 9528, 9613, 6181, 4633, 9610, 2617, 9828, 3195, + 3306, 9236, 1650, 1103, 5701, 2131, 2941, 5509, + 5556, 1853, 1247, 2983, 5129, 8837, 2623, 9853, + 8119, 5778, 9731, 5106, 6842, 7995, 301, 6820, + 2110, 7373, 8539, 3599, 6848, 5821, 5314, 3069, + 9753, 5159, 8600, 7729, 5936, 924, 3160, 4973, + 3849, 5006, 3502, 9551, 5341, 1601, 1092, 433, + 1572, 5946, 6038, 3545, 5322, 2411, 9889, 7641, + 8900, 6192, 9858, 1043, 4811, 3308, 7779, 2545, + 7963, 6558, 74, 8987, 5722, 5026, 2881, 4719, + 5084, 9274, 5489, 1330, 1686, 9460, 4437, 8446, + 2075, 4792, 6219, 9685, 612, 5747, 4490, 3931, + 5705, 3583, 4775, 5449, 1695, 6443, 8344, 8509, + 9209, 6503, 2965, 6959, 2726, 1628, 296, 2447, + 1438, 1914, 5386, 8362, 4148, 4979, 9400, 8414, + 9300, 8354, 7531, 9950, 5125, 8849, 2939, 1847, + 7962, 1124, 851, 2943, 9872, 5655, 797, 4552, + 7777, 7723, 8476, 5346, 977, 3644, 9120, 7364, + 4835, 8669, 9157, 9672, 7818, 8654, 9068, 7482, + 1642, 6578, 7998, 1898, 9438, 1015, 8315, 7132, + 1764, 8202, 5622, 1460, 8768, 3457, 111, 8793, + 6904, 8641, 1212, 6691, 5575, 2788, 7815, 646, + 3034, 3167, 1541, 3614, 162, 7023, 3217, 8610, + 4669, 346, 9747, 4128, 7411, 53, 1844, 2454, + 5512, 4377, 5549, 9197, 2988, 5800, 7230, 6270, + 9887, 4439, 1073, 2705, 9696, 4646, 7107, 9250, + 4806, 9598, 6577, 1310, 9339, 8418, 8519, 5917, + 2358, 1093, 9989, 8004, 3372, 6136, 4321, 4657, + 6000, 5693, 2462, 3856, 4089, 2522, 6144, 8267, + 3376, 9923, 9328, 5582, 2740, 8429, 3047, 511, + 9284, 6246, 5686, 7135, 4976, 1175, 4120, 9157, + 8525, 7158, 4119, 8361, 1810, 4566, 666, 6241, + 3896, 4733, 3696, 9610, 5365, 9852, 8767, 1301, + 5871, 8539, 682, 4994, 1086, 7813, 851, 5979, + 2648, 3138, 9995, 4591, 263, 5236, 8753, 7364, + 3999, 461, 2585, 7108, 306, 5152, 2741, 1754, + 4543, 9288, 1672, 2058, 6221, 4785, 1733, 909, + 6084, 7208, 7617, 673, 3060, 8661, 4417, 2233, + 8342, 9571, 6460, 6889, 2706, 3929, 5167, 967, + 6966, 9916, 6571, 6214, 6145, 9200, 1010, 2198, + 9079, 2821, 7049, 6905, 8235, 6461, 4953, 8649, + 905, 407, 9711, 2323, 2666, 2091, 1025, 5391, + 1241, 6737, 9248, 9298, 8450, 9319, 1462, 9150, + 1607, 4170, 6541, 7781, 1467, 8420, 5376, 194, + 6651, 7415, 513, 3578, 2889, 6835, 4776, 4085, + 538, 8155, 3194, 9467, 2105, 8505, 7369, 4793, + 4217, 9718, 8891, 3626, 1771, 8721, 116, 5540, + 7326, 3918, 6894, 8012, 4180, 7138, 5236, 5303, + 2602, 3564, 9007, 5662, 4729, 6969, 4493, 4929, + 1502, 5857, 8687, 97, 3912, 4519, 8216, 5498, + 4214, 8063, 1746, 8592, 9702, 9017, 1531, 1223, + 4247, 820, 4218, 1186, 3587, 9973, 1734, 1297, + 8275, 2024, 9920, 6071, 5908, 4298, 895, 3902, + 2619, 2039, 8559, 2462, 332, 8129, 2696, 7156, + 5009, 5726, 4366, 8780, 2654, 2723, 4871, 244, + 1015, 9987, 1781, 4136, 1, /* * 10000**1180 */ +0}; /* end powers of 65536 in base 10000 */ + +unsigned short _start_big_powers_two[] = { + 0, 1, 86, 255, 508, 846, 1268, 1774, + 2365, 3040, 3799, 4642, 5570, 6582, 7678, 8859, + +0}; /* end _start_big_powers_two */ diff --git a/usr/src/lib/libbc/libc/gen/common/_crypt.c b/usr/src/lib/libbc/libc/gen/common/_crypt.c new file mode 100644 index 0000000000..e18d528966 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_crypt.c @@ -0,0 +1,472 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984,1988 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* + * This program implements the + * Proposed Federal Information Processing + * Data Encryption Standard. + * See Federal Register, March 17, 1975 (40FR12134) + */ + +/* + * Initial permutation, + */ +static char IP[] = { + 58,50,42,34,26,18,10, 2, + 60,52,44,36,28,20,12, 4, + 62,54,46,38,30,22,14, 6, + 64,56,48,40,32,24,16, 8, + 57,49,41,33,25,17, 9, 1, + 59,51,43,35,27,19,11, 3, + 61,53,45,37,29,21,13, 5, + 63,55,47,39,31,23,15, 7, +}; + +/* + * Final permutation, FP = IP^(-1) + */ +static char FP[] = { + 40, 8,48,16,56,24,64,32, + 39, 7,47,15,55,23,63,31, + 38, 6,46,14,54,22,62,30, + 37, 5,45,13,53,21,61,29, + 36, 4,44,12,52,20,60,28, + 35, 3,43,11,51,19,59,27, + 34, 2,42,10,50,18,58,26, + 33, 1,41, 9,49,17,57,25, +}; + +/* + * Permuted-choice 1 from the key bits + * to yield C and D. + * Note that bits 8,16... are left out: + * They are intended for a parity check. + */ +static char PC1_C[] = { + 57,49,41,33,25,17, 9, + 1,58,50,42,34,26,18, + 10, 2,59,51,43,35,27, + 19,11, 3,60,52,44,36, +}; + +static char PC1_D[] = { + 63,55,47,39,31,23,15, + 7,62,54,46,38,30,22, + 14, 6,61,53,45,37,29, + 21,13, 5,28,20,12, 4, +}; + +/* + * Sequence of shifts used for the key schedule. + */ +static char shifts[] = { + 1,1,2,2,2,2,2,2,1,2,2,2,2,2,2,1, +}; + +/* + * Permuted-choice 2, to pick out the bits from + * the CD array that generate the key schedule. + */ +static char PC2_C[] = { + 14,17,11,24, 1, 5, + 3,28,15, 6,21,10, + 23,19,12, 4,26, 8, + 16, 7,27,20,13, 2, +}; + +static char PC2_D[] = { + 41,52,31,37,47,55, + 30,40,51,45,33,48, + 44,49,39,56,34,53, + 46,42,50,36,29,32, +}; + +static struct _crypt { + /* + * The C and D arrays used to calculate the key schedule. + */ + char _C[28]; + char _D[28]; + /* + * The key schedule. + * Generated from the key. + */ + char _KS[16][48]; + /* + * The E bit-selection table. + */ + char _E[48]; + /* + * The current block, divided into 2 halves. + */ + char _L[32], _R[32]; + char _tempL[32]; + char _f[32]; + /* + * The combination of the key and the input, before selection. + */ + char _preS[48]; + /* + * Temps for crypt + */ + char _ablock[66], _iobuf[16]; +} *__crypt; +#define C (_c->_C) +#define D (_c->_D) +#define KS (_c->_KS) +#define E (_c->_E) +#define L (_c->_L) +#define R (_c->_R) +#define tempL (_c->_tempL) +#define f (_c->_f) +#define preS (_c->_preS) +#define ablock (_c->_ablock) +#define iobuf (_c->_iobuf) + +/* + * Set up the key schedule from the key. + */ + +#ifndef CRYPT +static +#endif +void +setkey(key) +char *key; +{ + register i, j, k; + int t; + register struct _crypt *_c = __crypt; + + if (!_c) { + _cryptinit(); + _c = __crypt; + } + /* + * First, generate C and D by permuting + * the key. The low order bit of each + * 8-bit char is not used, so C and D are only 28 + * bits apiece. + */ + for (i=0; i<28; i++) { + C[i] = key[PC1_C[i]-1]; + D[i] = key[PC1_D[i]-1]; + } + /* + * To generate Ki, rotate C and D according + * to schedule and pick up a permutation + * using PC2. + */ + for (i=0; i<16; i++) { + /* + * rotate. + */ + for (k=0; k<shifts[i]; k++) { + t = C[0]; + for (j=0; j<28-1; j++) + C[j] = C[j+1]; + C[27] = t; + t = D[0]; + for (j=0; j<28-1; j++) + D[j] = D[j+1]; + D[27] = t; + } + /* + * get Ki. Note C and D are concatenated. + */ + for (j=0; j<24; j++) { + KS[i][j] = C[PC2_C[j]-1]; + KS[i][j+24] = D[PC2_D[j]-28-1]; + } + } +} + +/* + * The E bit-selection table. + */ +static char e[] = { + 32, 1, 2, 3, 4, 5, + 4, 5, 6, 7, 8, 9, + 8, 9,10,11,12,13, + 12,13,14,15,16,17, + 16,17,18,19,20,21, + 20,21,22,23,24,25, + 24,25,26,27,28,29, + 28,29,30,31,32, 1, +}; + +/* + * The 8 selection functions. + * For some reason, they give a 0-origin + * index, unlike everything else. + */ +static char S[8][64] = { + 14, 4,13, 1, 2,15,11, 8, 3,10, 6,12, 5, 9, 0, 7, + 0,15, 7, 4,14, 2,13, 1,10, 6,12,11, 9, 5, 3, 8, + 4, 1,14, 8,13, 6, 2,11,15,12, 9, 7, 3,10, 5, 0, + 15,12, 8, 2, 4, 9, 1, 7, 5,11, 3,14,10, 0, 6,13, + + 15, 1, 8,14, 6,11, 3, 4, 9, 7, 2,13,12, 0, 5,10, + 3,13, 4, 7,15, 2, 8,14,12, 0, 1,10, 6, 9,11, 5, + 0,14, 7,11,10, 4,13, 1, 5, 8,12, 6, 9, 3, 2,15, + 13, 8,10, 1, 3,15, 4, 2,11, 6, 7,12, 0, 5,14, 9, + + 10, 0, 9,14, 6, 3,15, 5, 1,13,12, 7,11, 4, 2, 8, + 13, 7, 0, 9, 3, 4, 6,10, 2, 8, 5,14,12,11,15, 1, + 13, 6, 4, 9, 8,15, 3, 0,11, 1, 2,12, 5,10,14, 7, + 1,10,13, 0, 6, 9, 8, 7, 4,15,14, 3,11, 5, 2,12, + + 7,13,14, 3, 0, 6, 9,10, 1, 2, 8, 5,11,12, 4,15, + 13, 8,11, 5, 6,15, 0, 3, 4, 7, 2,12, 1,10,14, 9, + 10, 6, 9, 0,12,11, 7,13,15, 1, 3,14, 5, 2, 8, 4, + 3,15, 0, 6,10, 1,13, 8, 9, 4, 5,11,12, 7, 2,14, + + 2,12, 4, 1, 7,10,11, 6, 8, 5, 3,15,13, 0,14, 9, + 14,11, 2,12, 4, 7,13, 1, 5, 0,15,10, 3, 9, 8, 6, + 4, 2, 1,11,10,13, 7, 8,15, 9,12, 5, 6, 3, 0,14, + 11, 8,12, 7, 1,14, 2,13, 6,15, 0, 9,10, 4, 5, 3, + + 12, 1,10,15, 9, 2, 6, 8, 0,13, 3, 4,14, 7, 5,11, + 10,15, 4, 2, 7,12, 9, 5, 6, 1,13,14, 0,11, 3, 8, + 9,14,15, 5, 2, 8,12, 3, 7, 0, 4,10, 1,13,11, 6, + 4, 3, 2,12, 9, 5,15,10,11,14, 1, 7, 6, 0, 8,13, + + 4,11, 2,14,15, 0, 8,13, 3,12, 9, 7, 5,10, 6, 1, + 13, 0,11, 7, 4, 9, 1,10,14, 3, 5,12, 2,15, 8, 6, + 1, 4,11,13,12, 3, 7,14,10,15, 6, 8, 0, 5, 9, 2, + 6,11,13, 8, 1, 4,10, 7, 9, 5, 0,15,14, 2, 3,12, + + 13, 2, 8, 4, 6,15,11, 1,10, 9, 3,14, 5, 0,12, 7, + 1,15,13, 8,10, 3, 7, 4,12, 5, 6,11, 0,14, 9, 2, + 7,11, 4, 1, 9,12,14, 2, 0, 6,10,13,15, 3, 5, 8, + 2, 1,14, 7, 4,10, 8,13,15,12, 9, 0, 3, 5, 6,11, +}; + +/* + * P is a permutation on the selected combination + * of the current L and key. + */ +static char P[] = { + 16, 7,20,21, + 29,12,28,17, + 1,15,23,26, + 5,18,31,10, + 2, 8,24,14, + 32,27, 3, 9, + 19,13,30, 6, + 22,11, 4,25, +}; + + +/* + * The payoff: encrypt a block. + */ + +void +encrypt(block, edflag) +char *block; +int edflag; +{ + int i, ii; + register int t, j, k; + register struct _crypt *_c = __crypt; + + if (!_c) { + _cryptinit(); + _c = __crypt; + } + /* + * First, permute the bits in the input + */ + for (j=0; j<64; j++) + L[j] = block[IP[j]-1]; + /* + * Perform an encryption operation 16 times. + */ + for (ii=0; ii<16; ii++) { + /* + * Set direction + */ +#ifdef CRYPT + if (edflag) + i = 15-ii; + else +#endif + i = ii; + /* + * Save the R array, + * which will be the new L. + */ + for (j=0; j<32; j++) + tempL[j] = R[j]; + /* + * Expand R to 48 bits using the E selector; + * exclusive-or with the current key bits. + */ + for (j=0; j<48; j++) + preS[j] = R[E[j]-1] ^ KS[i][j]; + /* + * The pre-select bits are now considered + * in 8 groups of 6 bits each. + * The 8 selection functions map these + * 6-bit quantities into 4-bit quantities + * and the results permuted + * to make an f(R, K). + * The indexing into the selection functions + * is peculiar; it could be simplified by + * rewriting the tables. + */ + for (j=0; j<8; j++) { + t = 6*j; + k = S[j][(preS[t+0]<<5)+ + (preS[t+1]<<3)+ + (preS[t+2]<<2)+ + (preS[t+3]<<1)+ + (preS[t+4]<<0)+ + (preS[t+5]<<4)]; + t = 4*j; + f[t+0] = (k>>3)&01; + f[t+1] = (k>>2)&01; + f[t+2] = (k>>1)&01; + f[t+3] = (k>>0)&01; + } + /* + * The new R is L ^ f(R, K). + * The f here has to be permuted first, though. + */ + for (j=0; j<32; j++) + R[j] = L[j] ^ f[P[j]-1]; + /* + * Finally, the new L (the original R) + * is copied back. + */ + for (j=0; j<32; j++) + L[j] = tempL[j]; + } + /* + * The output L and R are reversed. + */ + for (j=0; j<32; j++) { + t = L[j]; + L[j] = R[j]; + R[j] = t; + } + /* + * The final output + * gets the inverse permutation of the very original. + */ + for (j=0; j<64; j++) + block[j] = L[FP[j]-1]; +} + +char * +_crypt(pw, salt) +char *pw, *salt; +{ + register int i, j, c; + int temp; + register struct _crypt *_c = __crypt; + + if (!_c) { + _cryptinit(); + _c = __crypt; + } + for(i=0; i<66; i++) + ablock[i] = 0; + for(i=0; (c= *pw) && i<64; pw++){ + for(j=0; j<7; j++, i++) + ablock[i] = (c>>(6-j)) & 01; + i++; + } + + setkey(ablock); + + for(i=0; i<66; i++) + ablock[i] = 0; + + for(i=0;i<48;i++) + E[i] = e[i]; + + for(i=0;i<2;i++){ + c = *salt++; + iobuf[i] = c; + if(c > 'Z') + c -= 6; + if(c > '9') + c -= 7; + c -= '.'; + for(j=0;j<6;j++){ + if((c>>j) & 01){ + temp = E[6*i+j]; + E[6*i+j] = E[6*i+j+24]; + E[6*i+j+24] = temp; + } + } + } + + for(i=0; i<25; i++) + encrypt(ablock,0); + + for(i=0; i < 11; i++) { + c = 0; + for(j=0; j<6; j++){ + c <<= 1; + c |= ablock[6*i+j]; + } + c += '.'; + if(c > '9') + c += 7; + if(c > 'Z') + c += 6; + iobuf[i+2] = c; + } + iobuf[i+2] = 0; + if(iobuf[1]==0) + iobuf[1] = iobuf[0]; + return(iobuf); +} + +static +_cryptinit() +{ + register struct _crypt *_c = __crypt; + register int i; + + if (_c) + return; + _c = __crypt = (struct _crypt *)calloc(1, sizeof (struct _crypt)); + if (_c == 0) + abort(); + + for(i=0;i<48;i++) + E[i] = e[i]; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_nlist.c b/usr/src/lib/libbc/libc/gen/common/_nlist.c new file mode 100644 index 0000000000..906f243a33 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_nlist.c @@ -0,0 +1,108 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/05/30 */ + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/types.h> +#include <sys/param.h> +#include <a.out.h> + +#define BSIZ 8*1024 /* size of local buffers */ + +/* + * _nlist - retreive attributes from name list (string table version) + * + * Note: This is a modified form of the original nlist() function. + * It takes a file descriptor instead of a filename argument + * and is intended to be called by nlist(3) and kvmnlist(3K). + * The algorithm has been modified from the original to use local + * (rather than stdio) buffering and issues considerably fewer lseeks. + */ +_nlist(fd, list) + int fd; + struct nlist *list; +{ + register struct nlist *p, *q; + register char *s1, *s2; + register int soff; + register int stroff = 0; + register n, m; + int maxlen, nreq; + long sa; /* symbol address */ + long ss; /* start of strings */ + struct exec buf; + struct nlist space[BSIZ/sizeof (struct nlist)]; + char strs[BSIZ]; + + maxlen = 0; + for (q = list, nreq = 0; q->n_un.n_name && q->n_un.n_name[0]; + q++, nreq++) { + q->n_type = 0; + q->n_value = 0; + q->n_desc = 0; + q->n_other = 0; + n = strlen(q->n_un.n_name); + if (n > maxlen) + maxlen = n; + } + if ((fd == -1) || (lseek(fd, 0L, 0) == -1) || + (read(fd, (char*)&buf, sizeof buf) != sizeof buf) || N_BADMAG(buf)) + return (-1); + sa = N_SYMOFF(buf); + ss = sa + buf.a_syms; + n = buf.a_syms; + while (n) { + m = MIN(n, sizeof (space)); + lseek(fd, sa, 0); + if (read(fd, (char *)space, m) != m) + break; + sa += m; + n -= m; + for (q = space; (m -= sizeof (struct nlist)) >= 0; q++) { + soff = q->n_un.n_strx; + if (soff == 0 || q->n_type & N_STAB) + continue; + if ((soff + maxlen + 1) >= stroff) { + /* + * Read strings into local cache. + * Assumes (maxlen < sizeof (strs)). + */ + lseek(fd, ss+soff, 0); + read(fd, strs, sizeof strs); + stroff = soff + sizeof (strs); + } + for (p = list; + p->n_un.n_name && p->n_un.n_name[0]; + p++) { + if (p->n_type != 0) + continue; + s1 = p->n_un.n_name; + s2 = &strs[soff-(stroff-sizeof (strs))]; + while (*s1) { + if (*s1++ != *s2++) + goto cont; + } + if (*s2) + goto cont; + p->n_value = q->n_value; + p->n_type = q->n_type; + p->n_desc = q->n_desc; + p->n_other = q->n_other; + if (--nreq == 0) + goto alldone; + break; +cont: ; + } + } + } +alldone: + return (nreq); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_perror.c b/usr/src/lib/libbc/libc/gen/common/_perror.c new file mode 100644 index 0000000000..ea9cac5cb5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_perror.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/06/30 */ +/* + * Print the error indicated + * in the cerror cell. + */ +#include <sys/types.h> +#include <sys/uio.h> + +extern int errno; +extern int sys_nerr; +extern char *sys_errlist[]; +extern int strlen(); +extern int writev(); + +void +_perror(s) + char *s; +{ + struct iovec iov[4]; + register struct iovec *v = iov; + + if (s && *s) { + v->iov_base = s; + v->iov_len = strlen(s); + v++; + v->iov_base = ": "; + v->iov_len = 2; + v++; + } + v->iov_base = + (unsigned)errno < sys_nerr ? sys_errlist[errno] : "Unknown error"; + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = "\n"; + v->iov_len = 1; + writev(2, iov, (v - iov) + 1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_psignal.c b/usr/src/lib/libbc/libc/gen/common/_psignal.c new file mode 100644 index 0000000000..d28a9be0ea --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_psignal.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/02/10 */ + +/* + * Print the name of the signal indicated + * along with the supplied message. + */ +#include <sys/types.h> +#include <sys/uio.h> +#include <signal.h> + +extern char *sys_siglist[]; +extern int strlen(); +extern int writev(); + +void +_psignal(sig, s) + unsigned sig; + char *s; +{ + struct iovec iov[4]; + register struct iovec *v = iov; + + if (s && *s) { + v->iov_base = s; + v->iov_len = strlen(s); + v++; + v->iov_base = ": "; + v->iov_len = 2; + v++; + } + v->iov_base = + (unsigned)sig < NSIG ? sys_siglist[sig] : "Unknown signal"; + v->iov_len = strlen(v->iov_base); + v++; + v->iov_base = "\n"; + v->iov_len = 1; + writev(2, iov, (v - iov) + 1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/_small_power.c b/usr/src/lib/libbc/libc/gen/common/_small_power.c new file mode 100644 index 0000000000..1cb4f32a61 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_small_power.c @@ -0,0 +1,878 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +unsigned short _max_tiny_powers_ten = 4; +unsigned short _tiny_powers_ten[] = {1, /* begin powers of 10 in + * base 65536 */ + /* 10**1 = */ 10, /* * 65536**0 */ + /* 10**2 = */ 100, /* * 65536**1 */ + /* 10**3 = */ 1000, /* * 65536**1 */ +0 } ; + +unsigned short _start_tiny_powers_ten[] = { + 0, 1, 2, 3, 4, +0}; /* end _start_tiny_powers_ten */ + +unsigned short _leading_zeros_tiny_powers_ten[] = { + 0, 0, 0, 0, +0}; /* end _leading_zeros_tiny_powers_ten */ + +unsigned short _max_tiny_powers_two = 16; +unsigned short _tiny_powers_two[] = {1, /* begin powers of 2 in + * base 10000 */ + /* 2**1 = */ 2, /* * 10000**0 */ + /* 2**2 = */ 4, /* * 10000**0 */ + /* 2**3 = */ 8, /* * 10000**0 */ + /* 2**4 = */ 16, /* * 10000**0 */ + /* 2**5 = */ 32, /* * 10000**0 */ + /* 2**6 = */ 64, /* * 10000**0 */ + /* 2**7 = */ 128, /* * 10000**0 */ + /* 2**8 = */ 256, /* * 10000**0 */ + /* 2**9 = */ 512, /* * 10000**0 */ + /* 2**10 = */ 1024, /* * 10000**0 */ + /* 2**11 = */ 2048, /* * 10000**0 */ + /* 2**12 = */ 4096, /* * 10000**0 */ + /* 2**13 = */ 8192, /* * 10000**0 */ + /* 2**14 = */ 6384, 1, /* * 10000**1 */ + /* 2**15 = */ 2768, 3, /* * 10000**1 */ +0}; + +unsigned short _start_tiny_powers_two[] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 18, +0}; /* end _start_tiny_powers_two */ + +unsigned short _max_small_powers_ten = 90; +unsigned short _small_powers_ten[] = {1, /* begin powers of 10000 in + * base 65536 */ + /* 10000**1 = */ 10000, /* * 65536**0 */ + /* 10000**2 = */ 57600, 1525, /* * 65536**1 */ + /* 10000**3 = */ 4096, 54437, 232, /* * 65536**2 */ + /* 10000**4 = 65536**1 * */ 28609, 34546, 35, /* * 65536**3 */ + /* 10000**5 = 65536**1 * */ 25360, 24109, 27591, 5, /* * 65536**4 */ + /* 10000**6 = 65536**1 * */ 41216, 52461, 7118, 54210, /* * 65536**4 */ + /* 10000**7 = 65536**1 * */ 4096, 609, 15909, 52830, 8271, /* * 65536**5 */ + /* 10000**8 = 65536**2 * */ 61313, 34220, 16731, 11629, 1262, /* * 65536**6 */ + /* 10000**9 = 65536**2 * */ 40720, 45899, 1813, 31689, 38862, 192, /* * 65536**7 */ + /* 10000**10 = 65536**2 * */ 24832, 47605, 49067, 23716, 61891, 25385, 29, /* * 65536**8 */ + /* 10000**11 = 65536**2 * */ 4096, 285, 9232, 58239, 57170, 38515, 31729, 4, + /* * 65536**9 */ + /* 10000**12 = 65536**3 * */ 32577, 45355, 38512, 38358, 3651, 36101, 44841, /* * 65536**9 */ + /* 10000**13 = 65536**3 * */ 56080, 45850, 37384, 3668, 12301, 38269, 18196, 6842, + /* * 65536**10 */ + /* 10000**14 = 65536**3 * */ 8448, 18701, 29652, 51080, 65023, 27172, 37903, 3192, + 1044, /* * 65536**11 */ + /* 10000**15 = 65536**3 * */ 4096, 37081, 37989, 16940, 55138, 17665, 39458, 9751, + 20263, 159, /* * 65536**12 */ + /* 10000**16 = 65536**4 * */ 7937, 49002, 60772, 28216, 38893, 55975, 63988, 59711, + 20227, 24, /* * 65536**13 */ + /* 10000**17 = 65536**4 * */ 5904, 8539, 12149, 36793, 43681, 12958, 60573, 21267, + 35015, 46478, 3, /* * 65536**14 */ + /* 10000**18 = 65536**4 * */ 57600, 63028, 53094, 12749, 18174, 21993, 48265, 14922, + 59933, 4030, 37092, /* * 65536**14 */ + /* 10000**19 = 65536**4 * */ 4096, 29077, 42481, 30581, 10617, 59493, 46251, 1892, + 5557, 4505, 52391, 5659,/* * 65536**15 */ + /* 10000**20 = 65536**5 * */ 52929, 10084, 25506, 6346, 61348, 31525, 52689, 61296, + 27615, 15903, 40426, 863, /* * 65536**16 */ + /* 10000**21 = 65536**5 * */ 21264, 53708, 60962, 25043, 64008, 31200, 50906, 9831, + 56185, 43877, 36378, 50952, 131, /* * 65536**17 */ + /* 10000**22 = 65536**5 * */ 41216, 15724, 12323, 26246, 59245, 58406, 46648, 13767, + 11372, 15053, 61895, 48686, 7054, 20, /* * 65536**18 */ + /* 10000**23 = 65536**5 * */ 4096, 25425, 24719, 55736, 8564, 12208, 3664, 51518, + 17140, 61079, 30312, 2500, 30693, 4468, 3, /* * 65536**19 */ + /* 10000**24 = 65536**6 * */ 36481, 57623, 45627, 58488, 53274, 7238, 2063, 31221, + 62631, 25319, 35409, 25293, 54667, 30681, /* * 65536**19 */ + /* 10000**25 = 65536**6 * */ 36624, 43054, 17160, 43698, 6780, 36385, 52800, 62346, + 52747, 33988, 2855, 31979, 38083, 44325, 4681, /* * 65536**20 */ + /* 10000**26 = 65536**6 * */ 24832, 39604, 33321, 54106, 42443, 60698, 47535, 24088, + 45785, 18352, 47026, 40291, 5183, 35843, 24059, 714, + /* * 65536**21 */ + /* 10000**27 = 65536**6 * */ 4096, 9741, 31019, 65404, 27119, 57580, 26653, 42453, + 19179, 26186, 42000, 1847, 62708, 14406, 12813, 247, + 109, /* * 65536**22 */ + /* 10000**28 = 65536**7 * */ 24129, 9598, 60989, 12011, 4842, 3874, 57395, 38141, + 46606, 49307, 60792, 31833, 21440, 9318, 47123, 41461, + 16, /* * 65536**23 */ + /* 10000**29 = 65536**7 * */ 51984, 38977, 13448, 57354, 56264, 8962, 51839, 64773, + 39323, 49783, 15587, 30924, 36601, 56615, 27581, 36454, + 35254, 2, /* * 65536**24 */ + /* 10000**30 = 65536**7 * */ 8448, 35340, 6075, 36516, 22191, 40873, 1607, 45622, + 23883, 24544, 32988, 43530, 61694, 55616, 43150, 32976, + 27418, 25379, /* * 65536**24 */ + /* 10000**31 = 65536**7 * */ 4096, 31177, 3520, 59871, 10675, 50890, 19916, 24149, + 23777, 11324, 41057, 14921, 56274, 30917, 19462, 54968, + 47943, 38791, 3872, /* * 65536**25 */ + /* 10000**32 = 65536**8 * */ 15873, 11925, 39177, 991, 14589, 3861, 58415, 9076, + 62956, 54223, 56328, 50180, 45274, 48333, 32537, 42547, + 9731, 59679, 590, /* * 65536**26 */ + /* 10000**33 = 65536**8 * */ 1808, 42438, 63147, 20041, 7015, 11522, 28221, 1553, + 22569, 60278, 6353, 64979, 24968, 8908, 56671, 15252, + 61068, 20668, 10866, 90,/* * 65536**27 */ + /* 10000**34 = 65536**8 * */ 57600, 34675, 37115, 10547, 29538, 8782, 13742, 2274, + 49789, 48851, 34813, 1529, 63291, 20385, 21567, 26375, + 17879, 54310, 4465, 49690, 13, /* * 65536**28 */ + /* 10000**35 = 65536**8 * */ 4096, 7813, 24923, 28239, 10857, 6267, 57884, 1104, + 13355, 12253, 10222, 25424, 29081, 42697, 59670, 36426, + 11816, 5896, 28271, 6729, 6510, 2, /* * 65536**29 */ + /* 10000**36 = 65536**9 * */ 11713, 63320, 64714, 46692, 19240, 27004, 38784, 53336, + 45253, 51245, 27415, 30647, 7397, 1235, 20017, 4150, + 44939, 54131, 54377, 23778, 20993, /* * 65536**29 */ + /* 10000**37 = 65536**9 * */ 17168, 58491, 47197, 51410, 58964, 34615, 2072, 33950, + 12058, 30921, 20731, 27847, 50068, 30360, 23244, 18766, + 10281, 55033, 26067, 23689, 21820, 3203, /* * 65536**30 */ + /* 10000**38 = 65536**9 * */ 41216, 3819, 54189, 42817, 20452, 63381, 15905, 23836, + 64476, 12991, 24350, 10699, 54745, 44887, 53976, 33978, + 52415, 25776, 41725, 46873, 34270, 51761, 488, /* * 65536**31 */ + /* 10000**39 = 65536**9 * */ 4096, 54337, 38934, 31580, 54213, 14464, 3799, 7995, + 20469, 27486, 35742, 38963, 29424, 22289, 12353, 49612, + 63792, 14909, 51757, 22894, 19408, 11901, 38234, 74, + /* * 65536**32 */ + /* 10000**40 = 65536**10 * */ 11649, 64451, 53492, 21026, 10320, 46863, 62195, 22291, + 5139, 56386, 23933, 54841, 6553, 63577, 14364, 146, + 5334, 34483, 30649, 31397, 65121, 4791, 24938, 11, + /* * 65536**33 */ + /* 10000**41 = 65536**10 * */ 32528, 30753, 25002, 28674, 49544, 49174, 20510, 31554, + 13177, 54576, 1131, 8404, 2368, 6264, 60325, 20399, + 59254, 45917, 48925, 57236, 49094, 13120, 16251, 48269, + 1, /* * 65536**34 */ + /* 10000**42 = 65536**10 * */ 24832, 40051, 4852, 23815, 57751, 30951, 45359, 52825, + 47454, 43738, 46135, 23020, 22786, 53481, 57611, 51172, + 32136, 33825, 30766, 41577, 18557, 4419, 48258, 19839, + 17365, /* * 65536**34 */ + /* 10000**43 = 65536**10 * */ 4096, 23293, 29471, 58452, 10401, 57820, 20066, 36761, + 1884, 65513, 48769, 44607, 60376, 39716, 56720, 23702, + 44800, 23607, 39177, 14310, 43928, 21567, 39106, 19891, + 48163, 2649, /* * 65536**35 */ + /* 10000**44 = 65536**11 * */ 15681, 63698, 8912, 13287, 42995, 63126, 21637, 36777, + 32431, 46620, 39425, 49174, 21052, 57516, 50478, 65056, + 16163, 64930, 40889, 59911, 63262, 9978, 14207, 8971, + 20805, 404, /* * 65536**36 */ + /* 10000**45 = 65536**11 * */ 47888, 38008, 759, 29888, 35867, 23808, 45296, 50805, + 43483, 47380, 58073, 29407, 25871, 19276, 30504, 57366, + 28150, 37314, 20803, 51663, 10133, 43861, 55010, 58919, + 40104, 45478, 61, /* * 65536**37 */ + /* 10000**46 = 65536**11 * */ 8448, 44043, 59159, 35955, 61568, 58720, 44336, 21839, + 6392, 46891, 22733, 18829, 43895, 22571, 38397, 28046, + 31633, 47847, 24429, 12886, 19227, 44634, 63044, 29753, + 34206, 31815, 27115, 9, /* * 65536**38 */ + /* 10000**47 = 65536**11 * */ 4096, 29369, 3248, 28531, 40302, 6834, 17920, 30813, + 25732, 895, 58307, 8540, 58281, 10713, 63556, 37314, + 57543, 62026, 44628, 19951, 54878, 42773, 56026, 6179, + 32156, 43475, 32422, 28601, 1, /* * 65536**39 */ + /* 10000**48 = 65536**12 * */ 23809, 44161, 32287, 43489, 57637, 25618, 47998, 30365, + 41030, 61880, 15488, 65191, 53068, 59042, 53249, 29613, + 36076, 54840, 25225, 50116, 50437, 64798, 63636, 41326, + 54618, 20041, 15843, 14364, /* * 65536**39 */ + /* 10000**49 = 65536**12 * */ 63248, 32064, 46402, 63566, 53051, 8570, 63781, 29035, + 49273, 15348, 27874, 25771, 44955, 14273, 19009, 46477, + 54374, 256, 10304, 10057, 12591, 33264, 15327, 65230, + 9281, 9246, 32546, 53041, 2191, /* * 65536**40 */ + /* 10000**50 = 65536**12 * */ 57600, 47538, 30012, 33416, 5779, 52543, 14955, 35252, + 34782, 2206, 17734, 26701, 42508, 64987, 37777, 57124, + 60435, 12392, 17447, 39348, 16878, 46721, 51907, 22530, + 20977, 55656, 9634, 32118, 29069, 334, /* * 65536**41 */ + /* 10000**51 = 65536**12 * */ 4096, 56181, 37909, 62051, 57882, 28769, 4865, 4138, + 25827, 45211, 65456, 19041, 17578, 21510, 30412, 33988, + 51260, 645, 15059, 4518, 30804, 6431, 32009, 60688, + 58237, 31488, 10572, 55070, 42740, 2099, 51, /* * 65536**42 */ + /* 10000**52 = 65536**13 * */ 36033, 38348, 20936, 15516, 61328, 26677, 27526, 58791, + 46612, 58866, 37907, 15353, 13530, 36242, 14944, 48130, + 35293, 53906, 27993, 21489, 23884, 13157, 21524, 26364, + 53942, 15236, 2605, 48147, 25001, 51568, 7, /* * 65536**43 */ + /* 10000**53 = 65536**13 * */ 13072, 34362, 43867, 39482, 62015, 47837, 12870, 56280, + 36938, 22760, 18758, 50472, 36038, 7984, 23450, 5896, + 25984, 31785, 33969, 1727, 30095, 42892, 21783, 57492, + 62742, 62566, 34532, 42941, 63042, 46566, 12332, 1, + /* * 65536**44 */ + /* 10000**54 = 65536**13 * */ 41216, 16746, 42795, 37829, 54392, 32198, 60131, 44331, + 27691, 64644, 19440, 30126, 5237, 22651, 13410, 46714, + 56195, 4364, 21762, 39215, 8951, 57008, 60416, 41531, + 52644, 62917, 20362, 23397, 35768, 36339, 53889, 11881, + /* * 65536**44 */ + /* 10000**55 = 65536**13 * */ 4096, 21809, 2475, 22738, 42508, 9931, 22113, 33671, + 27164, 62657, 30087, 59510, 11332, 18383, 16800, 1438, + 51464, 1598, 41146, 51432, 59343, 49237, 57850, 17586, + 61185, 32432, 9248, 9587, 53618, 63873, 58552, 1454, + 1813, /* * 65536**45 */ + /* 10000**56 = 65536**14 * */ 52353, 46255, 35993, 16973, 29446, 13051, 54942, 63953, + 49984, 3784, 37711, 17336, 3249, 34037, 30179, 51547, + 62604, 25235, 65286, 9367, 7087, 21241, 35739, 8587, + 57208, 13652, 57779, 31446, 24325, 31122, 65478, 42285, + 276, /* * 65536**46 */ + /* 10000**57 = 65536**14 * */ 28432, 4900, 13346, 62788, 9341, 32317, 33703, 38095, + 6686, 33355, 16433, 23034, 52325, 42047, 1913, 33965, + 47993, 45952, 59754, 29017, 27013, 8905, 25433, 23293, + 17566, 17241, 26707, 27088, 50702, 58783, 14572, 21719, + 13940, 42, /* * 65536**47 */ + /* 10000**58 = 65536**14 * */ 24832, 48946, 29451, 47156, 30780, 13409, 48819, 59910, + 19092, 38316, 36337, 49003, 14090, 64544, 65439, 42739, + 15054, 54427, 55299, 51245, 60571, 56233, 51678, 18936, + 27074, 53000, 13430, 23787, 37637, 45352, 42441, 5919, + 8242, 28911, 6, /* * 65536**48 */ + /* 10000**59 = 65536**14 * */ 4096, 40941, 64220, 32973, 50139, 8040, 14382, 42873, + 22773, 39457, 44262, 22872, 5077, 43622, 22888, 39729, + 10329, 61353, 5536, 32454, 34107, 40362, 37220, 34381, + 13673, 14499, 24823, 41905, 381, 16623, 5784, 17468, + 42151, 31961, 64411, /* * 65536**48 */ + /* 10000**60 = 65536**15 * */ 7233, 18983, 28183, 44631, 60514, 35242, 61218, 64477, + 46754, 61412, 6113, 48626, 13158, 34944, 14260, 11326, + 49080, 56977, 6572, 25608, 54516, 27214, 13823, 27150, + 26454, 47380, 16603, 15306, 30762, 39784, 27442, 50649, + 62895, 27068, 9828, /* * 65536**49 */ + /* 10000**61 = 65536**15 * */ 43792, 38847, 28096, 14140, 52922, 42161, 13601, 36173, + 16014, 54814, 59818, 49348, 56667, 4055, 64532, 15967, + 2624, 7505, 61622, 31850, 35459, 42846, 18728, 51997, + 40846, 44292, 34541, 35973, 61887, 41173, 26838, 31979, + 8736, 25917, 45666, 1499, /* * 65536**50 */ + /* 10000**62 = 65536**15 * */ 8448, 44810, 13095, 43135, 18957, 24987, 29233, 38891, + 41071, 64875, 41291, 3047, 53274, 57398, 53162, 34150, + 28036, 11680, 51673, 4442, 45100, 56578, 50185, 10233, + 47582, 33944, 42038, 8166, 19041, 42291, 16362, 43951, + 5391, 41989, 9106, 54760, 228, /* * 65536**51 */ + /* 10000**63 = 65536**15 * */ 4096, 31657, 15909, 59582, 46469, 49660, 43252, 23836, + 1822, 15403, 43099, 2060, 63857, 23840, 726, 16, + 2203, 19126, 45958, 60012, 47461, 14593, 49481, 35961, + 30201, 36316, 37275, 8558, 29166, 9097, 48597, 28080, + 46114, 1670, 36903, 48109, 60131, 34, /* * 65536**52 */ + /* 10000**64 = 65536**16 * */ 31745, 38958, 34651, 48851, 40818, 55513, 12167, 4629, + 20678, 27614, 28272, 53066, 55311, 54677, 29038, 9906, + 26288, 44486, 13860, 7445, 54106, 15426, 21518, 25599, + 29632, 52309, 61207, 26105, 10482, 21948, 51191, 32988, + 60892, 62574, 61390, 24540, 21495, 5, /* * 65536**53 */ + /* 10000**65 = 65536**16 * */ 59152, 38859, 27112, 9943, 29246, 46308, 43654, 23440, + 14626, 39987, 1909, 19322, 59793, 11591, 63863, 39534, + 16615, 5643, 63684, 3218, 61456, 62047, 27665, 9667, + 35650, 51705, 37277, 29451, 31919, 1535, 11653, 45123, + 30057, 11563, 33836, 42583, 61200, 53279, /* * 65536**53 */ + /* 10000**66 = 65536**16 * */ 57600, 36081, 3497, 16025, 39885, 7086, 11770, 49925, + 52760, 37095, 25125, 20163, 48020, 51475, 48984, 36592, + 22272, 6039, 27549, 11541, 29419, 50065, 32011, 8621, + 51171, 41935, 9121, 62440, 34173, 19446, 7226, 16418, + 28789, 29082, 64932, 47770, 31329, 57194, 8129, /* * 65536**54 */ + /* 10000**67 = 65536**16 * */ 4096, 43109, 44817, 15013, 349, 21670, 63961, 64083, + 42817, 24290, 56172, 45097, 20804, 37583, 31790, 39986, + 34255, 34742, 43113, 5307, 657, 24985, 39815, 35044, + 6227, 58480, 55822, 39919, 34823, 19902, 42295, 13422, + 58393, 41160, 59285, 18003, 35209, 12108, 34087, 1240, + /* * 65536**55 */ + /* 10000**68 = 65536**17 * */ 60353, 41409, 59398, 18882, 38037, 47482, 28751, 33090, + 30117, 14650, 25355, 35617, 49750, 56134, 29714, 64965, + 18890, 39493, 57954, 17209, 26868, 22612, 25083, 16147, + 23222, 58811, 18741, 43323, 58017, 49228, 8725, 6288, + 42830, 17624, 11654, 33355, 40380, 19111, 18897, 189, + /* * 65536**56 */ + /* 10000**69 = 65536**17 * */ 8976, 42761, 33550, 19847, 1937, 17484, 10813, 13123, + 37129, 31635, 58987, 51244, 21658, 31751, 8341, 61702, + 35160, 12946, 11178, 1307, 50562, 24899, 27178, 58659, + 28415, 59015, 51549, 39899, 51938, 47956, 29095, 32307, + 23199, 20231, 19681, 39074, 37793, 13185, 32628, 57875, + 28, /* * 65536**57 */ + /* 10000**70 = 65536**17 * */ 41216, 54505, 27740, 32111, 39908, 55783, 63803, 28577, + 30562, 13393, 50827, 23016, 56875, 56920, 53052, 65368, + 8774, 31765, 43095, 30041, 9959, 26451, 6007, 46947, + 60390, 2655, 58365, 14697, 13288, 41013, 43013, 47495, + 63025, 3907, 8479, 17371, 55386, 62870, 43803, 6562, + 26687, 4, /* * 65536**58 */ + /* 10000**71 = 65536**17 * */ 4096, 58913, 59964, 53368, 36195, 59193, 45551, 42775, + 29992, 44615, 40363, 5323, 32104, 28518, 14765, 32031, + 62806, 63882, 55646, 65087, 45399, 8223, 43060, 36548, + 58459, 17134, 52325, 47193, 40770, 7739, 23490, 17171, + 63071, 20160, 52548, 40893, 17914, 21603, 62505, 25147, + 8409, 44072, /* * 65536**58 */ + /* 10000**72 = 65536**18 * */ 27521, 60125, 29501, 2815, 14371, 43832, 3478, 33791, + 51024, 583, 20927, 45484, 37762, 1743, 37821, 33399, + 50191, 3571, 40475, 32059, 54783, 29734, 57834, 14456, + 37816, 13190, 13248, 7745, 63741, 20156, 9264, 59692, + 20887, 15428, 58914, 36351, 26077, 36464, 17905, 11149, + 57219, 6724, /* * 65536**59 */ + /* 10000**73 = 65536**18 * */ 24336, 26935, 41638, 39557, 55517, 17424, 52608, 6914, + 47396, 5081, 13641, 23353, 8508, 3186, 2010, 24315, + 40408, 538, 209, 59600, 19467, 11527, 54873, 61944, + 19485, 47338, 33756, 54005, 8045, 46526, 40707, 19525, + 15876, 11443, 39250, 56333, 7802, 1675, 11212, 15996, + 62421, 8794, 1026, /* * 65536**60 */ + /* 10000**74 = 65536**18 * */ 24832, 753, 33902, 1057, 20580, 53783, 25186, 7547, + 4703, 26832, 30359, 27313, 17835, 10802, 46470, 11746, + 54270, 12213, 58466, 15647, 37174, 60682, 64366, 2100, + 20924, 16445, 56823, 38510, 45568, 21163, 33003, 24467, + 34787, 6566, 6642, 54069, 40755, 39510, 53695, 53870, + 47576, 212, 37726, 156, /* * 65536**61 */ + /* 10000**75 = 65536**18 * */ 4096, 62685, 2386, 23877, 17121, 44724, 13358, 41907, + 41839, 16333, 31342, 46120, 30711, 19393, 51408, 26578, + 63712, 44712, 15207, 44489, 22195, 27848, 40203, 38301, + 49408, 23368, 35389, 19134, 14068, 21209, 59469, 29147, + 8645, 63772, 33033, 19013, 55402, 55210, 19580, 2273, + 42396, 30107, 34816, 58428, 23, /* * 65536**62 */ + /* 10000**76 = 65536**19 * */ 64321, 14460, 22716, 33611, 24948, 24456, 34854, 14570, + 20672, 29340, 27950, 15341, 13662, 18575, 39364, 48599, + 43129, 33302, 33952, 51892, 20922, 36425, 23750, 9940, + 51699, 64701, 45815, 42663, 17650, 19572, 40482, 12463, + 56039, 38290, 15104, 47093, 33189, 52392, 57531, 7962, + 4085, 37362, 31872, 42307, 3, /* * 65536**63 */ + /* 10000**77 = 65536**19 * */ 39696, 37398, 14430, 44858, 55112, 48990, 23283, 18790, + 21679, 64018, 58972, 60024, 45316, 23060, 33618, 46566, + 4999, 38165, 48601, 11132, 37006, 4104, 3094, 51048, + 43548, 46496, 63232, 63166, 18061, 32197, 7114, 52241, + 59101, 47238, 50898, 56144, 22881, 30280, 42986, 2538, + 22287, 65423, 24132, 39983, 36455, /* * 65536**63 */ + /* 10000**78 = 65536**19 * */ 8448, 37641, 60970, 53817, 34620, 26809, 53603, 11840, + 65315, 27659, 36840, 4774, 53255, 51266, 49374, 31849, + 58673, 34634, 847, 47288, 45442, 20110, 7634, 20568, + 1069, 54261, 35766, 33680, 2422, 59924, 38352, 23629, + 14323, 5530, 34632, 854, 32391, 27171, 13996, 24127, + 47987, 53048, 26430, 64082, 44868, 5562, /* * 65536**64 */ + /* 10000**79 = 65536**19 * */ 4096, 38041, 24335, 63207, 47059, 53042, 15146, 50163, + 20030, 38046, 26364, 35413, 5192, 45534, 65134, 58109, + 56587, 56728, 21140, 37889, 591, 42486, 59164, 29196, + 10770, 37619, 38327, 15953, 42355, 44721, 12471, 38572, + 37445, 55337, 28619, 25604, 31218, 2686, 44786, 34119, + 19089, 38938, 1406, 13025, 30322, 52318, 848, /* * 65536**65 */ + /* 10000**80 = 65536**20 * */ 39681, 20636, 44529, 51164, 44332, 14397, 19767, 29638, + 26576, 60013, 43014, 20891, 62200, 50179, 57762, 41042, + 9018, 55056, 29609, 17541, 55738, 53010, 6147, 28807, + 15003, 21212, 21224, 58802, 64334, 1815, 42543, 48717, + 55265, 2731, 60751, 35938, 60539, 52921, 16417, 54374, + 33536, 41237, 30182, 52451, 10738, 33839, 129, /* * 65536**66 */ + /* 10000**81 = 65536**20 * */ 55056, 58726, 41564, 7242, 42303, 59708, 15620, 29224, + 16042, 20903, 36389, 53331, 1011, 55875, 58888, 42381, + 8726, 58976, 6752, 40182, 64532, 53336, 5320, 40218, + 22491, 47793, 37668, 34246, 47596, 6344, 36101, 47403, + 57881, 55456, 57232, 55381, 39451, 16037, 10395, 55849, + 20584, 22605, 33012, 29997, 40035, 29270, 49979, 19, + /* * 65536**67 */ + /* 10000**82 = 65536**20 * */ 57600, 304, 19649, 9062, 61761, 53494, 36822, 17359, + 57867, 38143, 37317, 49120, 25593, 55754, 47565, 63209, + 38050, 2867, 26919, 19814, 58675, 37878, 58442, 51915, + 62120, 44919, 51900, 40147, 42793, 8414, 38680, 13620, + 3281, 3200, 2574, 39533, 57266, 9427, 12351, 59330, + 65481, 19476, 18617, 16765, 60689, 22332, 16930, 1018, + 3, /* * 65536**68 */ + /* 10000**83 = 65536**20 * */ 4096, 34133, 13118, 52246, 118, 44592, 46914, 56290, + 55304, 19309, 13836, 13374, 19415, 29153, 63755, 2537, + 7629, 36574, 34085, 28779, 9215, 56409, 41267, 48261, + 57713, 15734, 27270, 4383, 51582, 63841, 7811, 22094, + 44078, 18932, 50376, 17240, 12464, 37970, 41614, 4476, + 48877, 62535, 50731, 11752, 29198, 48108, 23919, 24503, + 30155, /* * 65536**68 */ + /* 10000**84 = 65536**21 * */ 19137, 47672, 9009, 8324, 13074, 40116, 18454, 55821, + 29382, 16450, 48671, 34408, 28834, 20240, 17296, 6483, + 50284, 2844, 26625, 10775, 23054, 63951, 9192, 27348, + 62406, 7104, 56113, 52348, 31694, 829, 19336, 53771, + 58757, 53192, 48006, 58694, 51853, 57729, 5261, 3195, + 12946, 5366, 21693, 18913, 50215, 56476, 60081, 22602, + 4601, /* * 65536**69 */ + /* 10000**85 = 65536**21 * */ 4880, 14056, 50810, 10654, 62486, 16138, 62281, 42703, + 30629, 9123, 42174, 23426, 52386, 29231, 13584, 17535, + 48797, 5048, 43202, 12878, 51532, 13229, 48286, 65210, + 30380, 8498, 11852, 52530, 15891, 37300, 28926, 55606, + 47964, 38789, 16916, 6909, 18124, 56824, 58936, 34770, + 26887, 53527, 6658, 61950, 16053, 43950, 50105, 61039, + 7176, 702, /* * 65536**70 */ + /* 10000**86 = 65536**21 * */ 41216, 51560, 1536, 51753, 41401, 39902, 23854, 6927, + 46788, 8561, 17232, 40771, 34326, 27433, 53868, 43272, + 57155, 24725, 7458, 8352, 12397, 46215, 58306, 24167, + 50590, 49979, 32208, 30768, 58751, 37048, 55323, 56989, + 56036, 55270, 17502, 17637, 34014, 45645, 3422, 40513, + 46633, 41590, 3591, 54744, 41788, 18033, 33986, 60877, + 7393, 8743, 107, /* * 65536**71 */ + /* 10000**87 = 65536**21 * */ 4096, 34577, 32443, 57978, 26984, 43149, 60584, 2087, + 19553, 27123, 27162, 13173, 54189, 1541, 43802, 59547, + 17146, 56929, 3804, 28274, 42698, 57555, 58795, 47664, + 31303, 20183, 43722, 58930, 49990, 13956, 46277, 62921, + 35895, 43462, 47313, 15294, 10851, 62486, 17172, 52506, + 47541, 15659, 2618, 18340, 30817, 46840, 58591, 11281, + 14681, 6104, 22758, 16, /* * 65536**72 */ + /* 10000**88 = 65536**22 * */ 2689, 32076, 53494, 37134, 5093, 31800, 38796, 36430, + 45015, 42954, 6784, 40362, 17308, 43147, 16587, 26910, + 46920, 37806, 18276, 17274, 19363, 35326, 5643, 37337, + 49432, 32423, 6959, 384, 41484, 22433, 5925, 18929, + 56261, 32247, 51731, 50253, 41431, 25214, 53724, 19867, + 31750, 33525, 30671, 22526, 18910, 25307, 31484, 11081, + 28224, 39939, 32400, 2, /* * 65536**73 */ + /* 10000**89 = 65536**22 * */ 20240, 27226, 40062, 21186, 14194, 20105, 57268, 56831, + 54310, 23924, 16794, 50347, 5582, 49153, 4967, 11715, + 31882, 55511, 51400, 55428, 39291, 23914, 8894, 12269, + 53185, 30950, 61251, 39973, 62714, 6601, 8879, 22936, + 51864, 41464, 39272, 7845, 64612, 29329, 45255, 38581, + 46647, 38204, 6635, 17448, 32077, 38389, 8917, 58964, + 43674, 17922, 61646, 24943, /* * 65536**73 */ +0}; /* end powers of 10000 in base 65536 */ + +unsigned short _start_small_powers_ten[] = { + 0, 1, 2, 4, 7, 10, 14, 18, + 23, 28, 34, 41, 49, 56, 64, 73, + 83, 93, 104, 115, 127, 139, 152, 166, + 181, 195, 210, 226, 243, 260, 278, 296, + 315, 334, 354, 375, 397, 418, 440, 463, + 487, 511, 536, 561, 587, 613, 640, 668, + 697, 725, 754, 784, 815, 846, 878, 910, + 943, 976, 1010, 1045, 1080, 1115, 1151, 1188, + 1226, 1264, 1302, 1341, 1381, 1421, 1462, 1504, + 1546, 1588, 1631, 1675, 1720, 1765, 1810, 1856, + 1903, 1950, 1998, 2047, 2096, 2145, 2195, 2246, + 2298, 2350, 2402, +0}; /* end _start_small_powers_ten */ + +unsigned short _leading_zeros_small_powers_ten[] = { + 0, 0, 0, 0, 1, 1, 1, 1, + 2, 2, 2, 2, 3, 3, 3, 3, + 4, 4, 4, 4, 5, 5, 5, 5, + 6, 6, 6, 6, 7, 7, 7, 7, + 8, 8, 8, 8, 9, 9, 9, 9, + 10, 10, 10, 10, 11, 11, 11, 11, + 12, 12, 12, 12, 13, 13, 13, 13, + 14, 14, 14, 14, 15, 15, 15, 15, + 16, 16, 16, 16, 17, 17, 17, 17, + 18, 18, 18, 18, 19, 19, 19, 19, + 20, 20, 20, 20, 21, 21, 21, 21, + 22, 22, +0}; /* end _leading_zeros_small_powers_ten */ + +unsigned short _max_small_powers_two = 70; +unsigned short _small_powers_two[] = {1, /* begin powers of 65536 in + * base 10000 */ + /* 65536**1 = */ 5536, 6, /* * 10000**1 */ + /* 65536**2 = */ 7296, 9496, 42, /* * 10000**2 */ + /* 65536**3 = */ 656, 7671, 4749, 281, /* * 10000**3 */ + /* 65536**4 = */ 1616, 955, 737, 6744, 1844, /* * 10000**4 */ + /* 65536**5 = */ 6176, 7470, 6291, 9614, 2581, 2089, 1, /* * 10000**6 */ + /* 65536**6 = */ 336, 4395, 5935, 4337, 1426, 1625, 9228, 7, + /* * 10000**7 */ + /* 65536**7 = */ 96, 2922, 4963, 8530, 2762, 5348, 6858, 9229, + 51, /* * 10000**8 */ + /* 65536**8 = */ 1456, 6821, 4317, 4607, 6337, 4634, 938, 6692, + 2823, 340, /* * 10000**9 */ + /* 65536**9 = */ 416, 598, 3615, 2648, 1827, 5357, 3141, 3062, + 1985, 745, 2230, /* * 10000**10 */ + /* 65536**10 = */ 2976, 3254, 6559, 3019, 1628, 8327, 3684, 1820, + 9029, 7330, 163, 4615, 1, /* * 10000**12 */ + /* 65536**11 = */ 5136, 3647, 1951, 6171, 2397, 8943, 9196, 9668, + 6473, 8053, 411, 9713, 5780, 9, /* * 10000**13 */ + /* 65536**12 = */ 2896, 3451, 4640, 5444, 235, 4161, 7666, 2320, + 7894, 3835, 8076, 3866, 1735, 7710, 62, /* * 10000**14 */ + /* 65536**13 = */ 2256, 3715, 9658, 8394, 6640, 6839, 6245, 3762, + 6393, 2295, 3874, 5105, 301, 3933, 3761, 411, + /* * 10000**15 */ + /* 65536**14 = */ 9216, 1024, 1036, 2481, 4057, 4225, 7144, 7363, + 6306, 7019, 1508, 6670, 9794, 5063, 6671, 9946, + 2695, /* * 10000**16 */ + /* 65536**15 = */ 9776, 9261, 2012, 1606, 5812, 6189, 6875, 8389, + 8274, 8515, 4291, 5007, 3297, 2958, 3843, 4778, + 4706, 7668, 1, /* * 10000**18 */ + /* 65536**16 = */ 9936, 2963, 9131, 4007, 5758, 394, 564, 6564, + 9846, 3269, 785, 6879, 5008, 7098, 4235, 6195, + 3731, 892, 5792, 11, /* * 10000**19 */ + /* 65536**17 = */ 5696, 8284, 8640, 2594, 2554, 8922, 4889, 2000, + 474, 1715, 7190, 7290, 9370, 7352, 1480, 3279, + 5418, 2567, 360, 8855, 75, /* * 10000**20 */ + /* 65536**18 = */ 3056, 7553, 5333, 7012, 5949, 8931, 3976, 4046, + 7174, 7347, 5079, 4561, 100, 2084, 1468, 2248, + 5538, 6421, 9786, 3640, 3232, 497, /* * 10000**21 */ + /* 65536**19 = */ 8016, 3435, 2989, 3387, 9621, 1007, 9670, 4718, + 1782, 10, 5498, 2986, 3494, 7682, 505, 4550, + 3101, 2951, 7380, 5177, 6213, 2575, 3259, /* * 10000**22 */ + /* 65536**20 = */ 6576, 8693, 9620, 22, 4055, 7806, 9725, 2221, + 6078, 7041, 6994, 6527, 2356, 452, 6027, 2114, + 6955, 7061, 5021, 8239, 9100, 5920, 8703, 1359, + 2, /* * 10000**24 */ + /* 65536**21 = */ 4736, 7544, 3294, 4843, 8630, 590, 8760, 9194, + 2369, 8810, 4931, 9312, 5595, 7716, 8435, 2602, + 6738, 5277, 2535, 4014, 1598, 2763, 8611, 463, + 9984, 13, /* * 10000**25 */ + /* 65536**22 = */ 8496, 4621, 5027, 2440, 7421, 2800, 9232, 5393, + 5043, 7691, 5754, 3553, 4950, 2449, 6731, 9956, + 8625, 7631, 8347, 8120, 2835, 6443, 8604, 9602, + 4463, 7399, 91, /* * 10000**26 */ + /* 65536**23 = */ 3856, 7535, 9761, 787, 8650, 9435, 6706, 6152, + 3397, 429, 4551, 7122, 6488, 106, 8869, 529, + 3252, 1747, 9008, 7027, 7780, 7032, 3970, 3063, + 101, 119, 2269, 601, /* * 10000**27 */ + /* 65536**24 = */ 6816, 9030, 6279, 806, 1564, 8849, 6254, 1426, + 6114, 7210, 7149, 7217, 4245, 9340, 9482, 6667, + 6544, 2704, 9739, 507, 6138, 143, 4010, 2790, + 9212, 9447, 1963, 2006, 3940, /* * 10000**28 */ + /* 65536**25 = */ 3376, 4749, 9727, 3171, 3590, 8314, 137, 5328, + 6453, 4629, 4119, 168, 7622, 4064, 3565, 659, + 1283, 2235, 2829, 579, 3297, 1874, 301, 1720, + 5919, 8965, 9085, 8086, 4987, 5822, 2, /* * 10000**30 */ + /* 65536**26 = */ 9536, 2588, 9797, 8405, 5027, 9833, 2920, 6711, + 8725, 8437, 3124, 7045, 6495, 8255, 2478, 1590, + 7009, 1368, 5992, 3885, 5988, 6071, 8619, 3893, + 8856, 9031, 3316, 3641, 1030, 3280, 9230, 16, + /* * 10000**31 */ + /* 65536**27 = */ 1296, 9663, 3158, 4287, 4561, 8438, 9564, 1238, + 5583, 4416, 9762, 1598, 2492, 2250, 2312, 8485, + 2245, 9183, 681, 6630, 5032, 8301, 4574, 8137, + 2334, 3657, 6567, 8313, 5943, 4832, 8776, 9067, + 110, /* * 10000**32 */ + /* 65536**28 = */ 4656, 2861, 6016, 3534, 7793, 2661, 1606, 6252, + 5607, 3565, 1376, 507, 6191, 2332, 3979, 8113, + 3928, 1806, 199, 8149, 602, 7318, 6068, 6413, + 4353, 453, 8880, 3807, 4932, 8905, 5606, 2429, + 8387, 726, /* * 10000**33 */ + /* 65536**29 = */ 5616, 9009, 3328, 3652, 5212, 2370, 8260, 1598, + 1326, 2590, 903, 5772, 6699, 525, 3031, 9646, + 8579, 3763, 3502, 4169, 6077, 6398, 407, 2140, + 240, 6340, 2651, 3748, 8507, 404, 3179, 3689, + 6354, 4102, 4763, /* * 10000**34 */ + /* 65536**30 = */ 176, 629, 2853, 9288, 7567, 4479, 2895, 662, + 1214, 6931, 5982, 9711, 3491, 306, 3061, 120, + 6562, 8197, 1738, 2537, 9596, 9156, 5085, 9711, + 2664, 9814, 7485, 6305, 9316, 2297, 1597, 3138, + 9922, 315, 4855, 1217, 3, /* * 10000**36 */ + /* 65536**31 = */ 4336, 3297, 8330, 7065, 1783, 5341, 6078, 3807, + 5044, 7972, 1775, 9304, 9821, 6900, 7703, 4380, + 8020, 1596, 5292, 6227, 83, 506, 571, 3427, + 1549, 7769, 1278, 3540, 4701, 7249, 6051, 2435, + 8758, 8866, 9350, 9129, 4586, 20, /* * 10000**37 */ + /* 65536**32 = */ 4096, 608, 6490, 6433, 6994, 9465, 2811, 5388, + 8537, 6050, 8648, 8581, 31, 2769, 9034, 8166, + 7429, 8018, 6976, 7354, 300, 1764, 4372, 5614, + 7723, 9337, 5923, 5820, 7936, 1274, 5846, 9820, + 249, 9574, 9709, 9425, 7929, 780, 134, /* * 10000**38 */ + /* 65536**33 = */ 5456, 2731, 2627, 5621, 947, 4080, 3730, 6396, + 6144, 8751, 4982, 1095, 7858, 9392, 370, 6183, + 466, 6340, 1687, 7467, 8999, 7474, 4952, 7757, + 1322, 249, 924, 8343, 1841, 4877, 1810, 1833, + 2824, 3302, 1768, 435, 6718, 49, 6941, 878, + /* * 10000**39 */ + /* 65536**34 = */ 4416, 4572, 973, 5074, 9431, 3089, 6019, 2703, + 5103, 5805, 7706, 4575, 9067, 5610, 9876, 1518, + 297, 1298, 782, 8372, 7400, 5044, 3259, 5210, + 9431, 7132, 6896, 2903, 6453, 1142, 2123, 9353, + 5677, 8380, 9289, 9748, 3699, 5291, 5701, 6096, + 5758, /* * 10000**40 */ + /* 65536**35 = */ 6976, 9532, 6493, 6043, 3269, 2514, 1434, 3256, + 7926, 9924, 8462, 7705, 4899, 6384, 307, 8375, + 4146, 7675, 7658, 2517, 1267, 2086, 4885, 3921, + 4162, 4562, 3002, 6206, 2837, 4404, 416, 2122, + 9169, 8890, 8826, 5809, 1554, 5224, 5413, 4821, + 6242, 7739, 3, /* * 10000**42 */ + /* 65536**36 = */ 9136, 4869, 7721, 6606, 6791, 8931, 5101, 4615, + 9675, 1209, 675, 343, 1365, 3935, 1393, 6016, + 7142, 5976, 4989, 4304, 612, 6401, 7031, 8671, + 6531, 2510, 8972, 6092, 6305, 9140, 1839, 121, + 3491, 5131, 9003, 6471, 1019, 252, 605, 4534, + 7310, 4014, 7330, 24, /* * 10000**43 */ + /* 65536**37 = */ 6896, 4657, 5371, 1419, 8274, 6525, 7670, 2075, + 1048, 6433, 4729, 3272, 8888, 3105, 7437, 3707, + 7539, 9945, 8272, 9643, 6241, 9949, 5565, 8738, + 2446, 8167, 5445, 4112, 4410, 364, 608, 1914, + 6970, 8094, 4236, 2461, 3598, 1754, 932, 4189, + 7874, 9413, 5190, 904, 162, /* * 10000**44 */ + /* 65536**38 = */ 6256, 6345, 4380, 786, 4167, 6625, 3887, 7470, + 5331, 9957, 1903, 4788, 5414, 7530, 1586, 693, + 203, 4930, 8972, 7865, 3377, 8571, 3045, 45, + 8325, 8547, 7044, 9721, 711, 4008, 8276, 9888, + 8463, 4063, 3545, 1862, 4659, 3725, 1049, 6413, + 7917, 1973, 3534, 8563, 2759, 1062, /* * 10000**45 */ + /* 65536**39 = */ 3216, 6919, 9266, 4, 3666, 3309, 1852, 9398, + 1373, 6894, 265, 8846, 3283, 1564, 9448, 6846, + 8350, 3810, 1301, 9442, 6621, 1192, 3293, 9081, + 7496, 750, 1603, 1625, 9808, 2953, 2203, 4208, + 5975, 8237, 1752, 1267, 4429, 2134, 1679, 9245, + 540, 4417, 7159, 7929, 9944, 7318, 6961, /* * 10000**46 */ + /* 65536**40 = */ 3776, 4660, 1922, 2874, 5008, 2649, 4360, 9467, + 2519, 4188, 2221, 3197, 2661, 9825, 4379, 1375, + 472, 6887, 7310, 9440, 5735, 2309, 7864, 3997, + 7371, 1131, 9128, 6505, 7738, 2086, 5167, 9927, + 5178, 9192, 3057, 5599, 7248, 2850, 8932, 1324, + 29, 6057, 1171, 1864, 1952, 7622, 4061, 5624, + 4, /* * 10000**48 */ + /* 65536**41 = */ 3936, 2506, 734, 3063, 3124, 7686, 4323, 7887, + 7229, 1282, 2904, 3150, 2249, 8641, 6534, 704, + 2006, 9526, 3294, 7751, 830, 215, 240, 8931, + 2055, 9525, 24, 1502, 205, 8812, 8187, 9735, + 468, 853, 3796, 6104, 1623, 5104, 6234, 8202, + 9226, 1742, 2351, 6782, 8488, 8185, 1648, 1083, + 9004, 29, /* * 10000**49 */ + /* 65536**42 = */ 9696, 9010, 9849, 1579, 4538, 171, 2501, 768, + 1435, 4533, 4950, 7432, 1109, 1317, 8855, 170, + 9834, 9082, 8014, 1129, 5679, 5684, 49, 3589, + 5010, 3873, 5288, 5235, 4723, 4576, 982, 6620, + 4652, 5281, 246, 6622, 4933, 6384, 4874, 7130, + 8892, 4180, 6558, 560, 4016, 7791, 6974, 6293, + 3242, 9553, 195, /* * 10000**50 */ + /* 65536**43 = */ 7056, 2903, 3118, 5896, 2722, 6397, 6659, 8038, + 9194, 4092, 2908, 5995, 8133, 8184, 9911, 9152, + 2143, 2400, 5030, 2670, 6348, 3842, 8518, 9028, + 8880, 3763, 9753, 5617, 839, 3692, 6344, 4758, + 6857, 6107, 6468, 1007, 2486, 4157, 4305, 3626, + 2842, 8759, 2487, 3141, 6250, 7295, 9125, 3757, + 8958, 6658, 2128, 1284, /* * 10000**51 */ + /* 65536**44 = */ 2016, 7250, 277, 692, 7634, 1634, 6149, 2012, + 666, 3571, 5511, 7380, 3578, 9928, 935, 430, + 3633, 450, 1810, 4086, 29, 916, 831, 4834, + 8851, 169, 7275, 9631, 1521, 4414, 4580, 1866, + 1538, 3293, 6875, 7144, 9099, 9444, 9724, 1751, + 7078, 8451, 5436, 4880, 586, 6082, 3812, 8558, + 6115, 7397, 4247, 2174, 8416, /* * 10000**52 */ + /* 65536**45 = */ 576, 9212, 986, 2732, 6359, 5854, 1577, 8731, + 165, 3422, 2299, 1799, 6177, 4861, 1226, 6614, + 5106, 5009, 3111, 1958, 7323, 1168, 6419, 6470, + 816, 3593, 5513, 4893, 3378, 5878, 3808, 194, + 6600, 128, 1582, 4242, 8887, 1619, 3962, 7269, + 5289, 1123, 9085, 1310, 6081, 3795, 3091, 2074, + 8728, 9872, 9872, 3101, 5226, 5156, 5, /* * 10000**54 */ + /* 65536**46 = */ 8736, 1406, 8868, 819, 1329, 9420, 8640, 5154, + 660, 5279, 9690, 4332, 7663, 978, 8997, 3141, + 162, 3291, 5326, 9879, 2961, 4041, 3243, 9988, + 9781, 6199, 3515, 3780, 2678, 2749, 9612, 8943, + 8873, 1861, 8795, 4079, 6233, 1028, 4248, 7150, + 7544, 1594, 1923, 1700, 3007, 8973, 6650, 1923, + 1802, 8593, 6094, 1839, 1465, 7867, 1473, 36, + /* * 10000**55 */ + /* 65536**47 = */ 2496, 868, 2468, 2102, 2717, 7830, 2775, 9173, + 7542, 8872, 8436, 5459, 764, 4431, 3806, 7539, + 7422, 39, 6304, 5050, 6842, 387, 9733, 4823, + 3075, 1771, 9672, 9119, 182, 6017, 49, 1443, + 9543, 651, 1322, 8984, 2625, 1859, 3669, 240, + 445, 3829, 6179, 3803, 7894, 4235, 3207, 9315, + 8478, 2658, 2700, 647, 2296, 1314, 6086, 8954, + 236, /* * 10000**56 */ + /* 65536**48 = */ 7856, 1605, 8538, 2846, 5089, 4687, 3716, 9919, + 2629, 4825, 9844, 6315, 5285, 5026, 9055, 849, + 7602, 4549, 9204, 8113, 411, 7275, 4428, 3914, + 4814, 4411, 5800, 6171, 7320, 1310, 697, 8773, + 9504, 6477, 2864, 4088, 878, 8633, 3768, 2686, + 5095, 260, 2038, 3905, 6111, 6696, 1711, 8860, + 5256, 255, 4625, 9488, 4897, 9351, 708, 9230, + 5180, 1552, /* * 10000**57 */ + /* 65536**49 = */ 816, 6765, 6891, 1411, 1361, 585, 2496, 5940, + 9151, 8435, 8006, 4356, 9152, 8575, 1421, 9410, + 241, 3085, 3161, 3890, 8471, 7098, 1085, 6928, + 5957, 847, 7711, 669, 3966, 136, 7182, 1896, + 1639, 8963, 7557, 9941, 7400, 8044, 6225, 4395, + 3525, 2752, 4075, 1436, 6089, 9107, 5982, 177, + 5282, 6131, 5674, 5878, 1975, 9235, 773, 1926, + 6970, 5825, 174, 1, /* * 10000**59 */ + /* 65536**50 = */ 7376, 6387, 2911, 6461, 3747, 7480, 1690, 198, + 8866, 6135, 6501, 7289, 4024, 1181, 2859, 3078, + 5846, 145, 9514, 5757, 951, 46, 3083, 523, + 3356, 8036, 3650, 4119, 165, 8888, 445, 3324, + 5934, 9910, 4292, 2907, 1554, 87, 4322, 1521, + 3207, 8176, 7237, 6403, 8117, 6257, 6039, 9081, + 2315, 5832, 1447, 7797, 2125, 7907, 9851, 7407, + 8542, 2879, 1443, 6680, 6, /* * 10000**60 */ + /* 65536**51 = */ 3536, 6771, 7158, 7177, 5736, 3840, 4863, 7208, + 3474, 1464, 9748, 4512, 4637, 4392, 5166, 8545, + 3629, 1034, 458, 3103, 2471, 892, 7790, 5532, + 2245, 9290, 9066, 6709, 436, 5052, 1768, 4586, + 2408, 651, 5462, 1286, 1998, 1818, 7163, 8580, + 3922, 3354, 7616, 4441, 7679, 1951, 2915, 1997, + 5357, 1129, 8814, 3678, 5099, 7083, 6956, 9716, + 7060, 4129, 7321, 9938, 6994, 43, /* * 10000**61 */ + /* 65536**52 = */ 5296, 7429, 1064, 8787, 1535, 5836, 6737, 5360, + 9305, 7475, 4524, 2317, 8, 4504, 7762, 8978, + 6147, 8012, 2266, 1210, 9792, 4307, 1287, 6205, + 4579, 4156, 260, 445, 7670, 733, 757, 9686, + 743, 9720, 1899, 5092, 9359, 7542, 6283, 5824, + 8426, 3452, 4159, 5290, 53, 1064, 231, 4497, + 9441, 5252, 1706, 9172, 2173, 4907, 4838, 3367, + 7839, 4418, 6120, 4749, 3918, 3890, 286, /* * 10000**62 */ + /* 65536**53 = */ 8656, 1651, 8994, 1809, 5347, 8161, 4279, 7115, + 7611, 2584, 3858, 6565, 9475, 4197, 9949, 3079, + 8635, 4722, 7087, 3415, 6443, 7725, 3064, 9317, + 9, 7629, 6599, 5226, 4036, 8154, 5560, 6657, + 6726, 4795, 6565, 1763, 4796, 3850, 2121, 2845, + 4508, 5496, 6852, 2698, 8079, 654, 5789, 6906, + 4847, 6947, 8841, 7375, 9838, 9398, 5327, 1421, + 8773, 9423, 9278, 574, 1175, 720, 8792, 1876, + /* * 10000**63 */ + /* 65536**54 = */ 9616, 6663, 1609, 3568, 2853, 4339, 2031, 6688, + 1127, 4908, 4827, 9125, 6626, 6691, 5175, 548, + 3545, 7584, 4583, 1888, 833, 7827, 2934, 8997, + 885, 4209, 2061, 4388, 7549, 6997, 3600, 9595, + 8766, 9203, 5268, 2995, 2214, 5032, 7090, 3822, + 4934, 5401, 8693, 1036, 3030, 3492, 2195, 9555, + 8254, 361, 9307, 5944, 1506, 1807, 1869, 1573, + 6644, 3223, 4768, 8474, 8567, 3620, 7231, 3155, + 2300, 1, /* * 10000**65 */ + /* 65536**55 = */ 4176, 9387, 1096, 2997, 7592, 9403, 2053, 8081, + 2903, 8078, 4437, 7637, 1340, 4806, 2654, 7647, + 8714, 8256, 1192, 2008, 3864, 5732, 3919, 6625, + 8324, 6829, 7280, 5477, 22, 4868, 5460, 1517, + 1460, 5263, 3966, 4850, 6335, 1663, 3219, 5060, + 9676, 2273, 9847, 2269, 875, 1570, 4407, 867, + 6765, 2595, 5923, 6978, 6176, 3425, 8627, 377, + 1494, 6071, 6774, 3313, 2450, 6470, 4545, 3471, + 3481, 611, 8, /* * 10000**66 */ + /* 65536**56 = */ 8336, 3799, 8977, 8580, 8953, 4764, 7036, 9876, + 3968, 8838, 6173, 7515, 8292, 4802, 4041, 1188, + 821, 2329, 3024, 4105, 4264, 7676, 3151, 1687, + 5084, 9900, 6839, 8386, 7690, 9395, 8462, 3897, + 2505, 5537, 268, 5595, 2347, 7888, 1286, 3257, + 9499, 6743, 7894, 5718, 8876, 7255, 7441, 8594, + 6724, 255, 6739, 9026, 6070, 1279, 1522, 3612, + 3260, 8847, 651, 5166, 4916, 3978, 3523, 5246, + 3566, 5311, 8294, 52, /* * 10000**67 */ + /* 65536**57 = */ 8096, 5894, 1574, 7714, 43, 2184, 2523, 9650, + 1575, 3179, 1651, 3501, 3766, 8219, 2451, 3254, + 2844, 8725, 6127, 5099, 2408, 2283, 4244, 9887, + 6081, 9719, 5587, 9722, 6802, 1122, 7208, 9254, + 3224, 9251, 9936, 5679, 9659, 3352, 992, 9185, + 7809, 1502, 5381, 6586, 5014, 1853, 928, 5154, + 390, 5752, 8779, 2100, 2677, 330, 4178, 6007, + 1032, 8359, 1917, 3248, 8832, 4428, 9401, 4946, + 5758, 5069, 392, 2231, 346, /* * 10000**68 */ + /* 65536**58 = */ 9456, 2241, 2296, 5023, 8603, 910, 1641, 8936, + 2443, 9272, 770, 2358, 1521, 5067, 2602, 212, + 5711, 240, 6254, 8223, 4108, 4472, 9747, 2246, + 9214, 4242, 3330, 7613, 9589, 5975, 845, 7383, + 8715, 4670, 6325, 4066, 9448, 9976, 3685, 4663, + 819, 6255, 9064, 5361, 669, 1072, 9555, 8626, + 2817, 5631, 8240, 3137, 3640, 4425, 1572, 2133, + 2522, 2191, 7294, 3496, 5239, 1291, 2961, 2669, + 8708, 9722, 3335, 3388, 77, 2269, /* * 10000**69 */ + /* 65536**59 = */ 8416, 8146, 5348, 2376, 9128, 4143, 545, 451, + 3012, 5808, 3486, 8940, 5709, 881, 7880, 687, + 7487, 6067, 3720, 3514, 5782, 3919, 8702, 7736, + 3429, 4098, 2686, 7394, 4598, 447, 7084, 7829, + 4625, 239, 5811, 830, 779, 9057, 5544, 8524, + 4545, 3050, 9297, 7901, 8723, 8979, 3505, 6156, + 1449, 1683, 3545, 437, 1604, 657, 1594, 8593, + 5771, 5905, 3944, 1659, 6020, 1312, 560, 4990, + 4981, 8062, 6279, 7830, 8477, 1690, 4870, 1, + /* * 10000**71 */ + /* 65536**60 = */ 976, 1411, 9919, 8589, 8182, 5470, 4277, 310, + 7388, 2827, 6561, 4689, 3615, 4636, 9457, 4874, + 2539, 5979, 3685, 7887, 2183, 3479, 9959, 3527, + 3648, 9005, 6554, 789, 2987, 4730, 9956, 7769, + 5312, 3419, 1265, 2963, 7987, 4657, 940, 5203, + 6986, 4591, 8183, 866, 2314, 4916, 2530, 2592, + 2010, 6588, 6150, 2465, 2610, 7664, 8690, 1294, + 4572, 7906, 2686, 75, 7595, 2685, 8762, 8310, + 7518, 3878, 3382, 8035, 9990, 1399, 1401, 7453, + 9, /* * 10000**72 */ + /* 65536**61 = */ 3136, 7692, 831, 3710, 1847, 5547, 3325, 4193, + 2002, 8690, 227, 1304, 3374, 8590, 4336, 4444, + 7852, 6386, 9345, 6585, 6778, 4055, 5825, 741, + 8449, 5589, 1961, 862, 1207, 4856, 7416, 4434, + 8153, 2401, 5450, 1460, 5451, 3497, 4365, 9971, + 8594, 1562, 1180, 7807, 5984, 141, 8299, 5895, + 4348, 4342, 9576, 6548, 5118, 5010, 8068, 539, + 9078, 7579, 1511, 2808, 6413, 3934, 4033, 1584, + 4114, 7883, 8171, 3926, 7300, 339, 5111, 8990, + 8668, 63, /* * 10000**73 */ + /* 65536**62 = */ 896, 3464, 828, 4011, 9306, 298, 3554, 4242, + 553, 963, 3624, 437, 7010, 6352, 393, 406, + 7799, 4357, 5776, 5807, 6169, 2904, 3779, 353, + 8524, 6075, 2729, 4887, 7602, 726, 6801, 5228, + 4071, 5370, 6940, 8278, 6307, 5116, 7561, 8064, + 1732, 3560, 2722, 7286, 8588, 9797, 4191, 9108, + 9166, 5810, 1194, 2488, 6167, 8905, 7284, 6781, + 9345, 6837, 4571, 4995, 771, 654, 2474, 5457, + 5487, 7250, 6320, 7890, 8534, 4547, 6722, 2135, + 4968, 5580, 418, /* * 10000**74 */ + /* 65536**63 = */ 256, 2576, 6510, 324, 4303, 718, 6903, 7003, + 9210, 4794, 8775, 2982, 226, 613, 7281, 195, + 7925, 1463, 4495, 5408, 9644, 6976, 9579, 8975, + 1179, 7063, 7562, 2320, 6701, 8959, 5098, 6779, + 1322, 5003, 5035, 2493, 9807, 3514, 1228, 1859, + 1205, 9516, 2323, 3137, 919, 2479, 5587, 9360, + 2668, 4236, 8066, 1396, 6818, 8497, 2587, 7358, + 8364, 879, 9869, 2280, 994, 5600, 350, 6166, + 1796, 1963, 5037, 463, 5936, 8125, 2796, 3416, + 6844, 3439, 620, 2743, /* * 10000**75 */ + /* 65536**64 = */ 7216, 2413, 6242, 6329, 3535, 3048, 9716, 3847, + 2459, 9947, 9823, 5862, 684, 5051, 1633, 7237, + 4082, 1105, 3913, 8147, 4628, 2342, 5068, 8381, + 5768, 8500, 9520, 3082, 1945, 941, 1246, 1960, + 3022, 5276, 6548, 4248, 7893, 7776, 1243, 9474, + 3063, 8474, 2492, 1662, 8144, 9768, 5878, 3576, + 1393, 7987, 1138, 1120, 3602, 4075, 7322, 847, + 1327, 963, 550, 6758, 7732, 8115, 4300, 7273, + 3065, 8942, 7697, 6179, 4733, 8902, 1907, 9305, + 772, 3159, 4862, 9313, 7976, 1, /* * 10000**77 */ + /* 65536**65 = */ 7776, 5658, 1530, 8253, 1241, 6899, 7753, 668, + 8242, 2709, 5318, 6414, 5047, 6822, 3390, 4737, + 5381, 4036, 9612, 7436, 4002, 5647, 1799, 431, + 6577, 3806, 8429, 4347, 7724, 2124, 4024, 8726, + 2637, 7742, 4306, 9844, 3491, 9666, 2213, 6215, + 8857, 2143, 1249, 7169, 6077, 9021, 4628, 5264, + 5087, 5163, 2312, 7783, 8012, 2806, 1300, 6980, + 1827, 9865, 1111, 5893, 8641, 5316, 7987, 1513, + 5507, 3003, 9196, 7392, 2387, 2494, 5495, 4983, + 4774, 3289, 6735, 8633, 6172, 7813, 11, /* * 10000**78 */ + /* 65536**66 = */ 7936, 3648, 7165, 8638, 4263, 1002, 5822, 8862, + 2094, 1039, 8207, 2757, 2230, 9672, 1751, 6253, + 262, 8564, 8485, 8691, 3810, 8024, 6274, 7809, + 3097, 3119, 7891, 234, 8558, 9086, 788, 3509, + 5621, 6999, 8755, 4608, 692, 3861, 4517, 749, + 3084, 1697, 8514, 5770, 9255, 86, 9732, 1839, + 6133, 5709, 3071, 1843, 5440, 6528, 5194, 9801, + 16, 4618, 5148, 935, 5197, 6009, 876, 8315, + 6672, 699, 8740, 2380, 2882, 2432, 6666, 1901, + 1524, 9194, 6517, 6428, 4773, 3222, 2103, 77, + /* * 10000**79 */ + /* 65536**67 = */ 3696, 7337, 9352, 6926, 6582, 5015, 7161, 8187, + 465, 5633, 762, 6538, 3353, 8808, 6923, 8089, + 1412, 2025, 9085, 8988, 9122, 5838, 5452, 1746, + 6173, 7085, 5018, 7140, 8626, 6181, 1919, 994, + 853, 3304, 3552, 7269, 1116, 9034, 1415, 6069, + 7935, 4803, 4627, 8518, 3499, 6753, 6921, 4483, + 4346, 5218, 8474, 2977, 7920, 4660, 6769, 2379, + 2811, 5359, 9592, 9900, 6722, 9883, 8919, 7584, + 685, 3395, 9225, 2958, 355, 2441, 8916, 7623, + 9326, 7972, 8366, 8123, 5458, 8276, 3326, 56, + 506, /* * 10000**80 */ + /* 65536**68 = */ 1056, 1854, 758, 3630, 3348, 6180, 6166, 165, + 7899, 7340, 5348, 9365, 5055, 3066, 3454, 6080, + 9848, 9658, 7831, 7108, 8301, 8955, 537, 1590, + 5174, 3016, 6084, 9930, 331, 4552, 4097, 5364, + 8723, 6534, 5525, 4464, 5816, 9542, 2645, 7263, + 7934, 1414, 6554, 5974, 6290, 7544, 8914, 3249, + 8840, 5332, 6263, 6210, 4635, 9666, 3728, 4508, + 7291, 5847, 6434, 9265, 7878, 6347, 357, 3482, + 1868, 9214, 1849, 5947, 4671, 5704, 4973, 9361, + 8699, 4115, 6427, 3760, 8728, 1710, 6977, 1818, + 1585, 3316, /* * 10000**81 */ + /* 65536**69 = */ 6016, 664, 8439, 648, 8318, 4423, 5479, 3853, + 9949, 6006, 4636, 9693, 5857, 6510, 1440, 1518, + 8376, 1231, 5717, 1215, 924, 9286, 1524, 5765, + 3684, 485, 793, 2354, 7497, 2047, 824, 1957, + 5684, 9394, 9226, 8916, 6634, 2630, 5258, 5308, + 224, 9905, 2215, 5017, 595, 4810, 7348, 4887, + 9538, 5887, 6917, 9608, 61, 1356, 1558, 726, + 2522, 6777, 6947, 3209, 3331, 8627, 7952, 8695, + 4067, 948, 6450, 4715, 7631, 7959, 7912, 5090, + 9015, 7655, 6845, 7482, 2853, 3762, 5884, 173, + 6479, 7764, 1732, 2, /* * 10000**83 */ +0}; /* end powers of 65536 in base 10000 */ + +unsigned short _start_small_powers_two[] = { + 0, 1, 3, 6, 10, 15, 22, 30, + 39, 49, 60, 73, 87, 102, 118, 135, + 154, 174, 195, 217, 240, 265, 291, 318, + 346, 375, 406, 438, 471, 505, 540, 577, + 615, 654, 694, 735, 778, 822, 867, 913, + 960, 1009, 1059, 1110, 1162, 1215, 1270, 1326, + 1383, 1441, 1501, 1562, 1624, 1687, 1751, 1817, + 1884, 1952, 2021, 2091, 2163, 2236, 2310, 2385, + 2461, 2539, 2618, 2698, 2779, 2861, 2945, +0}; /* end _start_small_powers_two */ diff --git a/usr/src/lib/libbc/libc/gen/common/_sprintf_sup.c b/usr/src/lib/libbc/libc/gen/common/_sprintf_sup.c new file mode 100644 index 0000000000..573e4c269a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_sprintf_sup.c @@ -0,0 +1,354 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +/* + * Fundamental utilities of base conversion required for sprintf - but too + * complex or too seldom used to be worth assembly language coding. + */ + +unsigned long +_prodc_b10000(x, y, c) /* p = x * y + c ; return (p/10000 << 16 | + * p%10000) */ + _BIG_FLOAT_DIGIT x, y; + unsigned long c; +{ + unsigned long p = x * (unsigned long) y + c; + + return ((p / 10000) << 16) | (p % 10000); +} + +unsigned long +_prod_b65536(x, y) /* p = x * y ; return p */ + _BIG_FLOAT_DIGIT x, y; +{ + return x * (unsigned long) y; +} + +unsigned long +_prod_b10000(x, y) /* p = x * y ; return (p/10000 << 16 | + * p%10000) */ + _BIG_FLOAT_DIGIT x, y; +{ + unsigned long p = x * (unsigned long) y; + + return ((p / 10000) << 16) | (p % 10000); +} + +unsigned long +_lshift_b10000(x, n, c) /* p = x << n + c ; return (p/10000 << 16 | + * p%10000) */ + _BIG_FLOAT_DIGIT x; + short unsigned n; + long unsigned c; +{ + unsigned long p = (((unsigned long) x) << n) + c; + + return ((p / 10000) << 16) | (p % 10000); +} + +unsigned long +_prod_10000_b65536(x, c) /* p = x * 10000 + c ; return p */ + _BIG_FLOAT_DIGIT x; + long unsigned c; +{ + return x * (unsigned long) 10000 + c; +} + +unsigned long +_prod_65536_b10000(x, c) /* p = x << 16 + c ; return (p/10000 << 16 | + * p%10000) */ + _BIG_FLOAT_DIGIT x; + long unsigned c; +{ + unsigned long p = (((unsigned long) x) << 16) + c; + + return ((p / 10000) << 16) | (p % 10000); +} + +unsigned long +_carry_out_b10000(c) /* p = c ; return (p/10000 << 16 | p%10000) */ + unsigned long c; +{ + return ((c / 10000) << 16) | (c % 10000); +} + +void +_left_shift_base_ten(pbf, multiplier) + _big_float *pbf; + short unsigned multiplier; + +{ + /* + * Multiply a base-10**4 significand by 2<<multiplier. Extend length + * as necessary to accommodate carries. + */ + + short unsigned length = pbf->blength; + int j; + unsigned long carry; + long p; + + carry = 0; + for (j = 0; j < length; j++) { + p = _lshift_b10000((_BIG_FLOAT_DIGIT) pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + while (carry != 0) { + p = _carry_out_b10000(carry); + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + pbf->blength = j; +} + +void +_left_shift_base_two(pbf, multiplier) + _big_float *pbf; + short unsigned multiplier; +{ + /* + * Multiply a base-2**16 significand by 2<<multiplier. Extend length + * as necessary to accommodate carries. + */ + + short unsigned length = pbf->blength; + long unsigned p; + int j; + unsigned long carry; + + carry = 0; + for (j = 0; j < length; j++) { + p = _lshift_b65536(pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + if (carry != 0) { + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (_carry_out_b65536(carry) & 0xffff); + } + pbf->blength = j; +} + +void +_right_shift_base_two(pbf, multiplier, sticky) + _big_float *pbf; + short unsigned multiplier; + _BIG_FLOAT_DIGIT *sticky; + +{ + /* *pb = *pb / 2**multiplier to normalize. 15 <= multiplier <= 1 */ + /* Any bits shifted out got to *sticky. */ + + long unsigned p; + int j; + unsigned long carry; + + carry = 0; + for (j = pbf->blength - 1; j >= 0; j--) { + p = _rshift_b65536(pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p >> 16); + carry = p & 0xffff; + } + *sticky = (_BIG_FLOAT_DIGIT) carry; +} + +void +_multiply_base_ten(pbf, multiplier) + _BIG_FLOAT_DIGIT multiplier; + _big_float *pbf; +{ + /* + * Multiply a base-10**4 significand by multiplier. Extend length as + * necessary to accommodate carries. + */ + + int j; + unsigned long carry; + long p; + + carry = 0; + for (j = 0; j < pbf->blength; j++) { + p = _prodc_b10000((_BIG_FLOAT_DIGIT) pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + while (carry != 0) { + p = _carry_out_b10000(carry); + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + pbf->blength = j; +} + +void +_multiply_base_two(pbf, multiplier, carry) + _big_float *pbf; + _BIG_FLOAT_DIGIT multiplier; + long unsigned carry; +{ + /* + * Multiply a base-2**16 significand by multiplier. Extend length as + * necessary to accommodate carries. + */ + + short unsigned length = pbf->blength; + long unsigned p; + int j; + + for (j = 0; j < length; j++) { + p = _prodc_b65536(pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + if (carry != 0) { + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (_carry_out_b65536(carry) & 0xffff); + } + pbf->blength = j; +} + +void +_multiply_base_ten_by_two(pbf, multiplier) + short unsigned multiplier; + _big_float *pbf; +{ + /* + * Multiply a base-10**4 significand by 2**multiplier. Extend length + * as necessary to accommodate carries. + */ + + short unsigned length = pbf->blength; + int j; + long unsigned carry, p; + + carry = 0; + for (j = 0; j < length; j++) { + p = _lshift_b10000(pbf->bsignificand[j], multiplier, carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + while (carry != 0) { + p = _carry_out_b10000(carry); + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + pbf->blength = j; +} + +void +_unpacked_to_big_float(pu, pb, pe) + unpacked *pu; + _big_float *pb; + int *pe; + +{ + /* + * Converts pu into a bigfloat *pb of minimal length; exponent *pe + * such that pu = *pb * 2 ** *pe + */ + + int iz, it; + + for (iz = (UNPACKED_SIZE - 2); pu->significand[iz] == 0; iz--); /* Find lsw. */ + + for (it = 0; it <= iz; it++) { + pb->bsignificand[2 * (iz - it)] = pu->significand[it] & 0xffff; + pb->bsignificand[2 * (iz - it) + 1] = pu->significand[it] >> 16; + } + + pb->blength = 2 * iz + 2; + if (pb->bsignificand[0] == 0) { + for (it = 1; it < pb->blength; it++) + pb->bsignificand[it - 1] = pb->bsignificand[it]; + pb->blength--; + } + *pe = pu->exponent + 1 - 16 * pb->blength; + pb->bexponent = 0; + +#ifdef DEBUG + printf(" unpacked to big float 2**%d * ", *pe); + _display_big_float(pb, 2); +#endif +} + +void +_mul_65536short(pbf, carry) + _big_float *pbf; + unsigned long carry; +{ + /* *pbf *= 65536 ; += carry ; */ + + long unsigned p; + int j; + + for (j = 0; j < pbf->blength; j++) { + p = _prod_65536_b10000(pbf->bsignificand[j], carry); + pbf->bsignificand[j] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + while (carry != 0) { + p = _carry_out_b10000(carry); + pbf->bsignificand[j++] = (_BIG_FLOAT_DIGIT) (p & 0xffff); + carry = p >> 16; + } + pbf->blength = j; +} + +void +_big_binary_to_big_decimal(pb, pd) + _big_float *pb, *pd; + +{ + /* Convert _big_float from binary form to decimal form. */ + + int i; + + pd->bsignificand[0] = pb->bsignificand[pb->blength - 1] % 10000; + if (pd->bsignificand[0] == pb->bsignificand[pb->blength - 1]) { + pd->blength = 1; + } else { + pd->blength = 2; + pd->bsignificand[1] = pb->bsignificand[pb->blength - 1] / 10000; + } + for (i = pb->blength - 2; i >= 0; i--) { /* Multiply by 2**16 and + * add next significand. */ + _mul_65536short(pd, (unsigned long) pb->bsignificand[i]); + } + for (i = 0; i <= (pb->bexponent - 16); i += 16) { /* Multiply by 2**16 for + * each trailing zero. */ + _mul_65536short(pd, (unsigned long) 0); + } + if (pb->bexponent > i) + _left_shift_base_ten(pd, (short unsigned) (pb->bexponent - i)); + pd->bexponent = 0; + +#ifdef DEBUG + printf(" _big_binary_to_big_decimal "); + _display_big_float(pd, 10); +#endif +} diff --git a/usr/src/lib/libbc/libc/gen/common/_times_power.c b/usr/src/lib/libbc/libc/gen/common/_times_power.c new file mode 100644 index 0000000000..10f73781cc --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_times_power.c @@ -0,0 +1,472 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "base_conversion.h" +#include <malloc.h> + +void +_copy_big_float_digits(p1, p2, n) + _BIG_FLOAT_DIGIT *p1, *p2; + short unsigned n; + +{ /* Copies p1[n] = p2[n] */ + short unsigned i; + + for (i = 0; i < n; i++) + *p1++ = *p2++; +} + +void +_free_big_float(p) + _big_float *p; + +{ + /* Central routine to call free for base conversion. */ + + char *freearg = (char *) p; + + (void) free(freearg); +#ifdef DEBUG + printf(" free called with %X \n", freearg); +#endif +} + +void +_base_conversion_abort(ern, bcastring) + int ern; + char *bcastring; + +{ + char pstring[160]; + + errno = ern; + (void) sprintf(pstring, " libc base conversion file %s line %d: %s", __FILE__, __LINE__, bcastring); + perror(pstring); + abort(); +} + +void +_big_float_times_power( +#ifdef notdef +/* function to multiply a big_float times a positive power of two or ten. */ + _big_float * pbf; /* Operand x, to be replaced + * by the product x * mult ** + * n. */ + int mult; /* if mult is two, x is base 10**4; if mult + * is ten, x is base 2**16 */ + int n; + int precision; /* Number of bits of precision + * ultimately required (mult=10) or + * number of digits of precision + * ultimately required (mult=2). + * Extra bits are allowed internally + * to permit correct rounding. */ +/* + * if precision is < 0, then -pfb->bexponent/{4 or 16} digits are discarded + * on the last product. + */ + _big_float **pnewbf; /* Return result *pnewbf is set to: pbf if + * uneventful BIG_FLOAT_TIMES_TOOBIG if n is + * bigger than the tables permit ; + * BIG_FLOAT_TIMES_NOMEM if pbf->blength + * was insufficient to hold the product, and + * malloc failed to produce a new block ; + * &newbf if pbf->blength + * was insufficient to hold the product, and + * a new _big_float was allocated by malloc. + * newbf holds the product. It's the + * caller's responsibility to free this space + * when no longer needed. */ +#else + pbf, mult, n, precision, pnewbf +#endif +) + _big_float *pbf; + int mult, n, precision; + _big_float **pnewbf; + +{ + short unsigned base, sumlz = 0; + unsigned short productsize, trailing_zeros_to_delete, needed_precision, *pp, *table[3], max[3], *start[3], *lz[3], tablepower[3]; + int i, j, itlast; + _big_float *pbfold = pbf; + int discard; + + if (precision >= 0) + discard = -1; + else { + precision = -precision; + discard = 0; + } + switch (mult) { + case 2: /* *pbf is in base 10**4 so multiply by a + * power of two */ + base = 10; + max[0] = _max_tiny_powers_two; + max[1] = _max_small_powers_two; + max[2] = _max_big_powers_two; + table[0] = _tiny_powers_two; + table[1] = _small_powers_two; + table[2] = _big_powers_two; + lz[0] = 0; + lz[1] = 0; + lz[2] = 0; + start[0] = _start_tiny_powers_two; + start[1] = _start_small_powers_two; + start[2] = _start_big_powers_two; + needed_precision = 2 + (precision + 1) / 4; /* Precision is in base + * ten; counts round and + * sticky. */ + break; + case 10: /* *pbf is in base 2**16 so multiply by a + * power of ten */ + base = 2; + max[0] = _max_tiny_powers_ten; + max[1] = _max_small_powers_ten; + max[2] = _max_big_powers_ten; + table[0] = _tiny_powers_ten; + table[1] = _small_powers_ten; + table[2] = _big_powers_ten; + start[0] = _start_tiny_powers_ten; + start[1] = _start_small_powers_ten; + start[2] = _start_big_powers_ten; + lz[0] = _leading_zeros_tiny_powers_ten; + lz[1] = _leading_zeros_small_powers_ten; + lz[2] = _leading_zeros_big_powers_ten; + needed_precision = 2 + (precision + 1) / 16; /* Precision is in base + * two; counts round and + * sticky. */ + break; + } + for (i = 0; i < 3; i++) { + tablepower[i] = n % max[i]; + n = n / max[i]; + } + for (itlast = 2; (itlast >= 0) && (tablepower[itlast] == 0); itlast--); + /* Determine last i; could be 0, 1, or 2. */ + if (n > 0) { /* The tables aren't big enough to accomodate + * mult**n, but it doesn't matter since the + * result would undoubtedly overflow even + * binary quadruple precision format. Return + * an error code. */ + (void) printf("\n _times_power failed due to exponent %d %d %d leftover: %d \n", tablepower[0], tablepower[1], tablepower[2], n); + *pnewbf = BIG_FLOAT_TIMES_TOOBIG; + goto ret; + } + productsize = pbf->blength; + for (i = 0; i < 3; i++) + productsize += (start[i])[tablepower[i] + 1] - (start[i])[tablepower[i]]; + + if (productsize < needed_precision) + needed_precision = productsize; + + if (productsize <= pbf->bsize) { + *pnewbf = pbf; /* Work with *pnewbf from now on. */ + } else { /* Need more significance than *pbf can hold. */ + char *mallocresult; + int mallocarg; + + mallocarg = sizeof(_big_float) + sizeof(_BIG_FLOAT_DIGIT) * (productsize - _BIG_FLOAT_SIZE); + mallocresult = malloc(mallocarg); +#ifdef DEBUG + printf(" malloc arg %X result %X \n", mallocarg, (int) mallocresult); +#endif + if (mallocresult == (char *) 0) { /* Not enough memory + * left, bail out. */ + *pnewbf = BIG_FLOAT_TIMES_NOMEM; + goto ret; + } + *pnewbf = (_big_float *) mallocresult; + _copy_big_float_digits((*pnewbf)->bsignificand, pbf->bsignificand, pbf->blength); + (*pnewbf)->blength = pbf->blength; + (*pnewbf)->bexponent = pbf->bexponent; + pbf = *pnewbf; + pbf->bsize = productsize; + } + + /* pbf now points to the input and the output big_floats. */ + + for (i = 0; i <= itlast; i++) + if (tablepower[i] != 0) { /* Step through each of the + * tables. */ + unsigned lengthx, lengthp; + + /* Powers of 10**4 have leading zeros in base 2**16. */ + lengthp = (start[i])[tablepower[i] + 1] - (start[i])[tablepower[i]]; + lengthx = pbf->blength; + + if (discard >= 0) + switch (base) { + case 2: + discard = (-pbf->bexponent) / 16; + break; + case 10: + discard = (-pbf->bexponent) / 4; + break; + } + +#ifdef DEBUG + { + long basexp; + int id; + + printf(" step %d x operand length %d \n", i, lengthx); + _display_big_float(pbf, base); + printf(" step %d p operand length %d power %d \n", i, lengthp, tablepower[i]); + basexp = (base == 2) ? (lz[i])[tablepower[i]] : 0; + for (id = 0; id < lengthp; id++) { + printf("+ %d * ", (table[i])[id + (start[i])[tablepower[i]]]); + if (base == 2) + printf("2**%d", 16 * (basexp + id)); + if (base == 10) + printf("10**%d", 4 * (basexp + id)); + if ((id % 4) == 3) + printf("\n"); + } + printf("\n"); + } + if ((i == itlast) && (discard >= 0)) + printf(" alternative discard %d digits \n", discard); +#endif + + if (base == 2) { + sumlz += (lz[i])[tablepower[i]]; + pbf->bexponent += 16 * (lz[i])[tablepower[i]]; + } + if (lengthp == 1) { /* Special case - multiply by + * <= 10**4 or 2**13 */ + switch (base) { + case 10: + _multiply_base_ten_by_two(pbf, tablepower[i]); + break; + case 2: + _multiply_base_two(pbf, (_BIG_FLOAT_DIGIT) ((table[i])[tablepower[i]]), (unsigned long) 0); + break; + } +#ifdef DEBUG + assert(pbf->blength <= pbf->bsize); +#endif + } else if (lengthx == 1) { /* Special case of short + * multiplicand. */ + _BIG_FLOAT_DIGIT multiplier = pbf->bsignificand[0]; + + _copy_big_float_digits(pbf->bsignificand, (unsigned short *) &((table[i])[(start[i])[tablepower[i]]]), lengthp); + pbf->blength = lengthp; + switch (base) { + case 10: + _multiply_base_ten(pbf, multiplier); + break; + case 2: + _multiply_base_two(pbf, multiplier, (unsigned long) 0); + break; + } +#ifdef DEBUG + assert(pbf->blength <= pbf->bsize); +#endif + } else {/* General case. */ + short unsigned canquit; + short unsigned excess; + + /* + * The result will be accumulated in *pbf + * from most significant to least + * significant. + */ + + /* Generate criterion for early termination. */ + switch (base) { + case 2: + canquit = 65536; + break; + case 10: + canquit = 10000; + break; + } + canquit -= 3 + ((lengthx < lengthp) ? lengthx : lengthp); + + pbf->bsignificand[lengthx + lengthp - 1] = 0; /* Only gets filled by + * carries. */ + for (j = lengthx + lengthp - 2; j >= 0; j--) { + int istart = j - lengthp + 1, istop = lengthx - 1; + short unsigned lengthprod; + _BIG_FLOAT_DIGIT product[3]; + + pp = (unsigned short *) &((table[i])[(start[i])[tablepower[i]]]); + if (j < istop) + istop = j; + if (0 > istart) + istart = 0; + + switch (base) { + case 2: + _multiply_base_two_vector((short unsigned) (istop - istart + 1), &(pbf->bsignificand[istart]), &(pp[j - istop]), product); + if (product[2] != 0) + _carry_propagate_two((unsigned long) product[2], &(pbf->bsignificand[j + 2])); + if (product[1] != 0) + _carry_propagate_two((unsigned long) product[1], &(pbf->bsignificand[j + 1])); + break; + case 10: + _multiply_base_ten_vector((short unsigned) (istop - istart + 1), &(pbf->bsignificand[istart]), &(pp[j - istop]), product); + if (product[2] != 0) + _carry_propagate_ten((unsigned long) product[2], &(pbf->bsignificand[j + 2])); + if (product[1] != 0) + _carry_propagate_ten((unsigned long) product[1], &(pbf->bsignificand[j + 1])); + break; + } + pbf->bsignificand[j] = product[0]; + lengthprod = lengthx + lengthp; + if (pbf->bsignificand[lengthprod - 1] == 0) + lengthprod--; + if (lengthprod > needed_precision) + excess = lengthprod - needed_precision; + else + excess = 0; + if ((i == itlast) && ((j + 2) <= excess) && (pbf->bsignificand[j + 1] <= canquit) + && ((pbf->bsignificand[j + 1] | pbf->bsignificand[j]) != 0)) { + /* + * On the last + * multiplication, it's not + * necessary to develop the + * entire product, if further + * digits can't possibly + * affect significant digits, + * unless there's a chance + * the product might be + * exact! + */ + /* + * Note that the product + * might be exact if the j + * and j+1 terms are zero; if + * they are non-zero, then it + * won't be after they're + * discarded. + */ + + excess = j + 2; /* Can discard j+1, j, + * ... 0 */ +#ifdef DEBUG + printf(" decided to quit early at j %d since s[j+1] is %d <= %d \n", j, pbf->bsignificand[j + 1], canquit); + printf(" s[j+2..j] are %d %d %d \n", pbf->bsignificand[j + 2], pbf->bsignificand[j + 1], pbf->bsignificand[j]); + printf(" requested precision %d needed_precision %d big digits out of %d \n", precision, needed_precision, lengthprod); +#endif + if ((discard >= 0) && ((j + 2) > (discard - (int) sumlz))) { +#ifdef DEBUG + printf(" early quit rejected because j+2 = %d > %d = discard \n", j + 2, discard); +#endif + goto pastdiscard; + } + pbf->bsignificand[excess] |= 1; /* Sticky bit on. */ +#ifdef DEBUG + printf(" discard %d digits - last gets %d \n", excess, pbf->bsignificand[excess]); +#endif + trailing_zeros_to_delete = excess; + goto donegeneral; + } + pastdiscard: ; +#ifdef DEBUG + /* + * else { printf(" early termination + * rejected at j %d since s[j+1] = + * %d, canquit = %d \n", j, + * pbf->bsignificand[j + 1], + * canquit); printf(" s[j+2..j] are + * %d %d %d \n", pbf->bsignificand[j + * + 2], pbf->bsignificand[j + 1], + * pbf->bsignificand[j]); printf(" + * requested precision %d + * needed_precision %d big digits out + * of %d \n", precision, + * needed_precision, lengthprod); } + */ +#endif + } + trailing_zeros_to_delete = 0; + donegeneral: + pbf->blength = lengthx + lengthp; + if (pbf->bsignificand[pbf->blength - 1] == 0) + pbf->blength--; + for (; pbf->bsignificand[trailing_zeros_to_delete] == 0; trailing_zeros_to_delete++); + /* + * Look for additional trailing zeros to + * delete. + */ + + /* + * fix for bug 1070565; if too many trailing + * zeroes are deleted, we'll violate the + * assertion that bexponent is in [-3,+4] + */ + if (base == 10) { + int deletelimit=(1-((pbf->bexponent+3)/4)); + + if ((int)trailing_zeros_to_delete > deletelimit) { +#ifdef DEBUG + printf("\n __x_power trailing zeros delete count lowered from %d to + %d \n", trailing_zeros_to_delete,deletelimit); +#endif + + trailing_zeros_to_delete = deletelimit; + } + } + + + if (trailing_zeros_to_delete != 0) { +#ifdef DEBUG + printf(" %d trailing zeros deleted \n", trailing_zeros_to_delete); +#endif + _copy_big_float_digits(pbf->bsignificand, &(pbf->bsignificand[trailing_zeros_to_delete]), pbf->blength - trailing_zeros_to_delete); + pbf->blength -= trailing_zeros_to_delete; + switch (base) { + case 2: + pbf->bexponent += 16 * trailing_zeros_to_delete; + break; + case 10: + pbf->bexponent += 4 * trailing_zeros_to_delete; + break; + } + } + } + } + if ((pbfold != pbf) && (pbf->blength <= pbfold->bsize)) { /* Don't need that huge + * buffer after all! */ +#ifdef DEBUG + printf(" free called from times_power because final length %d <= %d original size \n", pbf->blength, pbfold->bsize); +#endif + + /* Copy product to original buffer. */ + pbfold->blength = pbf->blength; + pbfold->bexponent = pbf->bexponent; + _copy_big_float_digits(pbfold->bsignificand, pbf->bsignificand, pbf->blength); + _free_big_float(*pnewbf); /* Free new buffer. */ + *pnewbf = pbfold; /* New buffer pointer now agrees with + * original. */ + } +ret: + return; +} diff --git a/usr/src/lib/libbc/libc/gen/common/_unpack_dble.c b/usr/src/lib/libbc/libc/gen/common/_unpack_dble.c new file mode 100644 index 0000000000..0ba46e5a53 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/_unpack_dble.c @@ -0,0 +1,267 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char sccsid[] = "%Z%%M% %I% %E% SMI"; +#endif + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +void +_fp_normalize(pu) + unpacked *pu; + +/* Normalize a number. Does not affect zeros, infs, or NaNs. */ + +{ + int i; + short unsigned nlzwords, nlzbits; + long unsigned t; + + if ((*pu).fpclass == fp_normal) { + for (nlzwords = 0; (pu->significand[nlzwords] == 0) && (nlzwords < UNPACKED_SIZE); nlzwords++); + if (nlzwords >= UNPACKED_SIZE) { + (*pu).fpclass = fp_zero; + return; + } + if (nlzwords > 0) { + for (i = 0; i < UNPACKED_SIZE - nlzwords; i++) + pu->significand[i] = pu->significand[i + nlzwords]; + for (; i < UNPACKED_SIZE; i++) + pu->significand[i] = 0; + pu->exponent -= 32 * nlzwords; + } + for (; pu->significand[UNPACKED_SIZE - 1 - nlzwords] == 0; nlzwords++); + /* nlzwords is now the count of trailing zero words. */ + + nlzbits = 0; + t = pu->significand[0]; + /* TESTS to determine normalize count. */ + +#define SHIFTMACRO(n) if (t <= (((unsigned long) 0xffffffff) >> n)) { t = t<<n ; nlzbits += n ; } + SHIFTMACRO(16); + SHIFTMACRO(8); + SHIFTMACRO(4); + SHIFTMACRO(2); + SHIFTMACRO(1); + pu->exponent -= nlzbits; + if (nlzbits >= 1) { /* small shift */ + unsigned long high, low, shiftout = 0; + for (i = UNPACKED_SIZE - 1 - nlzwords; i >= 0; i--) { + high = pu->significand[i] << nlzbits; + low = pu->significand[i] >> (32 - nlzbits); + pu->significand[i] = shiftout | high; + shiftout = low; + } + } + } +} + +void +_fp_set_exception(ex) + enum fp_exception_type ex; + +/* Set the exception bit in the current exception register. */ + +{ + _fp_current_exceptions |= 1 << (int) ex; +} + +enum fp_class_type +_class_double(x) + double *x; +{ + double_equivalence kluge; + + kluge.x = *x; + if (kluge.f.msw.exponent == 0) { /* 0 or sub */ + if ((kluge.f.msw.significand == 0) && (kluge.f.significand2 == 0)) + return fp_zero; + else + return fp_subnormal; + } else if (kluge.f.msw.exponent == 0x7ff) { /* inf or nan */ + if ((kluge.f.msw.significand == 0) && (kluge.f.significand2 == 0)) + return fp_infinity; + else if (kluge.f.msw.significand >= 0x40000) + return fp_quiet; + else + return fp_signaling; + } else + return fp_normal; +} + +void +_fp_leftshift(pu, n) + unpacked *pu; + unsigned n; + +/* Left shift significand by 11 <= n <= 16 bits. Affect all classes. */ + +{ + int i; + + unsigned long high, low, shiftout = 0; + for (i = UNPACKED_SIZE - 1; i >= 0; i--) { + high = pu->significand[i] << n; + low = pu->significand[i] >> (32 - n); + pu->significand[i] = shiftout | high; + shiftout = low; + } +} + +void +_unpack_double(pu, px) + unpacked *pu; /* unpacked result */ + double *px; /* packed double */ +{ + double_equivalence x; + int i; + + x.x = *px; + (*pu).sign = x.f.msw.sign; + pu->significand[1] = x.f.significand2; + for (i = 2; i < UNPACKED_SIZE; i++) + pu->significand[i] = 0; + if (x.f.msw.exponent == 0) { /* zero or sub */ + if ((x.f.msw.significand == 0) && (x.f.significand2 == 0)) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* subnormal */ + pu->fpclass = fp_normal; + pu->exponent = 12 - DOUBLE_BIAS; + pu->significand[0] = x.f.msw.significand; + _fp_normalize(pu); + return; + } + } else if (x.f.msw.exponent == 0x7ff) { /* inf or nan */ + if ((x.f.msw.significand == 0) && (x.f.significand2 == 0)) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((x.f.msw.significand & 0x80000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_quiet; + _fp_set_exception(fp_invalid); + } + pu->significand[0] = 0x80000 | x.f.msw.significand; + _fp_leftshift(pu, 11); + return; + } + } + (*pu).exponent = x.f.msw.exponent - DOUBLE_BIAS; + (*pu).fpclass = fp_normal; + (*pu).significand[0] = 0x100000 | x.f.msw.significand; + _fp_leftshift(pu, 11); +} + +enum fp_class_type +_class_quadruple(x) + quadruple *x; +{ + quadruple_equivalence kluge; + int i; + + for (i = 0; i < 4; i++) +#ifdef __STDC__ + kluge.x = *x; +#else + kluge.x.u[i] = x->u[i]; +#endif + if (kluge.f.msw.exponent == 0) { /* 0 or sub */ + if ((kluge.f.msw.significand == 0) && (kluge.f.significand2 == 0) && (kluge.f.significand3 == 0) && (kluge.f.significand4 == 0)) + return fp_zero; + else + return fp_subnormal; + } else if (kluge.f.msw.exponent == 0x7fff) { /* inf or nan */ + if ((kluge.f.msw.significand == 0) && (kluge.f.significand2 == 0) && (kluge.f.significand3 == 0) && (kluge.f.significand4 == 0)) + return fp_infinity; + else if ((kluge.f.msw.significand & 0xffff) >= 0x8000) + return fp_quiet; + else + return fp_signaling; + } else + return fp_normal; +} + +void +_unpack_quadruple(pu, px) + unpacked *pu; /* unpacked result */ + quadruple *px; /* packed quadruple */ +{ + quadruple_equivalence x; + int i; + + for (i = 0; i < 4; i++) +#ifdef __STDC__ + x.x = *px; +#else + x.x.u[i] = px->u[i]; +#endif + (*pu).sign = x.f.msw.sign; + pu->significand[1] = x.f.significand2; + pu->significand[2] = x.f.significand3; + pu->significand[3] = x.f.significand4; + for (i = 4; i < UNPACKED_SIZE; i++) + pu->significand[i] = 0; + if (x.f.msw.exponent == 0) { /* zero or sub */ + if ((x.f.msw.significand | x.f.significand2 | x.f.significand3 | x.f.significand4) == 0) { /* zero */ + pu->fpclass = fp_zero; + goto ret; + } else { /* subnormal */ + pu->fpclass = fp_normal; + pu->exponent = 16 - QUAD_BIAS; + pu->significand[0] = x.f.msw.significand; + _fp_normalize(pu); + goto ret; + } + } else if (x.f.msw.exponent == 0x7fff) { /* inf or nan */ + if ((x.f.msw.significand | x.f.significand2 | x.f.significand3 | x.f.significand4) == 0) { /* inf */ + pu->fpclass = fp_infinity; + goto ret; + } else { /* nan */ + if ((x.f.msw.significand & 0x8000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_quiet; + _fp_set_exception(fp_invalid); + } + pu->significand[0] = 0x8000 | x.f.msw.significand; + _fp_leftshift(pu, 16); + goto ret; + } + } + (*pu).exponent = x.f.msw.exponent - QUAD_BIAS; + (*pu).fpclass = fp_normal; + (*pu).significand[0] = 0x10000 | x.f.msw.significand; + _fp_leftshift(pu, 15); +ret: + /* + * printf("/n _unpack_quadruple ") ; _display_unpacked(pu); + */ + return; +} diff --git a/usr/src/lib/libbc/libc/gen/common/a64l.c b/usr/src/lib/libbc/libc/gen/common/a64l.c new file mode 100644 index 0000000000..86c694169f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/a64l.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +/* + * convert base 64 ascii to long int + * char set is [./0-9A-Za-z] + * + */ + +#define BITSPERCHAR 6 /* to hold entire character set */ + +long +a64l(s) +register char *s; +{ + register int i, c; + long lg = 0; + + for (i = 0; (c = *s++) != '\0'; i += BITSPERCHAR) { + if (c > 'Z') + c -= 'a' - 'Z' - 1; + if (c > '9') + c -= 'A' - '9' - 1; + lg |= (long)(c - ('0' - 2)) << i; + } + return (lg); +} diff --git a/usr/src/lib/libbc/libc/gen/common/abs.c b/usr/src/lib/libbc/libc/gen/common/abs.c new file mode 100644 index 0000000000..dde5f1b6cb --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/abs.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ + +int +abs(arg) +register int arg; +{ + return (arg >= 0 ? arg : -arg); +} diff --git a/usr/src/lib/libbc/libc/gen/common/alarm.c b/usr/src/lib/libbc/libc/gen/common/alarm.c new file mode 100644 index 0000000000..d804f9673c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/alarm.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/06/10 */ + +/* + * Backwards compatible alarm. + */ +#include <sys/time.h> + +alarm(secs) + int secs; +{ + struct itimerval it, oitv; + register struct itimerval *itp = ⁢ + + timerclear(&itp->it_interval); + itp->it_value.tv_sec = secs; + itp->it_value.tv_usec = 0; + if (setitimer(ITIMER_REAL, itp, &oitv) < 0) + return (-1); + if (oitv.it_value.tv_usec) + oitv.it_value.tv_sec++; + return (oitv.it_value.tv_sec); +} diff --git a/usr/src/lib/libbc/libc/gen/common/asctime.c b/usr/src/lib/libbc/libc/gen/common/asctime.c new file mode 100644 index 0000000000..1762a3d12b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/asctime.c @@ -0,0 +1,64 @@ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ + +#include <time.h> +#include <tzfile.h> + +static char cbuf[26]; + +char *ct_numb(); + +char * +asctime(t) +struct tm *t; +{ + register char *cp, *ncp; + register int *tp; + + cp = cbuf; + for (ncp = "Day Mon 00 00:00:00 1900\n"; *cp++ = *ncp++;); + ncp = &"SunMonTueWedThuFriSat"[3*t->tm_wday]; + cp = cbuf; + *cp++ = *ncp++; + *cp++ = *ncp++; + *cp++ = *ncp++; + cp++; + tp = &t->tm_mon; + ncp = &"JanFebMarAprMayJunJulAugSepOctNovDec"[(*tp)*3]; + *cp++ = *ncp++; + *cp++ = *ncp++; + *cp++ = *ncp++; + cp = ct_numb(cp, *--tp); + cp = ct_numb(cp, *--tp+100); + cp = ct_numb(cp, *--tp+100); + cp = ct_numb(cp, *--tp+100); + cp = ct_numb(cp, (t->tm_year + TM_YEAR_BASE)/100); + cp--; + cp = ct_numb(cp, t->tm_year+100); + return(cbuf); +} + +static char * +ct_numb(cp, n) +register char *cp; +{ + cp++; + if (n>=10) + *cp++ = (n/10)%10 + '0'; + else + *cp++ = ' '; + *cp++ = n%10 + '0'; + return(cp); +} diff --git a/usr/src/lib/libbc/libc/gen/common/atof.c b/usr/src/lib/libbc/libc/gen/common/atof.c new file mode 100644 index 0000000000..bfad17cd09 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/atof.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +#include <stdio.h> + +extern double +strtod(); + +double +atof(cp) + char *cp; +{ + return strtod(cp, (char **) NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/atoi.c b/usr/src/lib/libbc/libc/gen/common/atoi.c new file mode 100644 index 0000000000..0ace01d68b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/atoi.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <ctype.h> + +#define ATOI + +#ifdef ATOI +typedef int TYPE; +#define NAME atoi +#else +typedef long TYPE; +#define NAME atol +#endif + +TYPE +NAME(p) +register char *p; +{ + register TYPE n; + register int c, neg = 0; + + if (!isdigit(c = *p)) { + while (isspace(c)) + c = *++p; + switch (c) { + case '-': + neg++; + case '+': /* fall-through */ + c = *++p; + } + if (!isdigit(c)) + return (0); + } + for (n = '0' - c; isdigit(c = *++p); ) { + n *= 10; /* two steps to avoid unnecessary overflow */ + n += '0' - c; /* accum neg to avoid surprises at MAX */ + } + return (neg ? n : -n); +} diff --git a/usr/src/lib/libbc/libc/gen/common/atol.c b/usr/src/lib/libbc/libc/gen/common/atol.c new file mode 100644 index 0000000000..5a2f88fab5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/atol.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <ctype.h> + +#define ATOL + +#ifdef ATOI +typedef int TYPE; +#define NAME atoi +#else +typedef long TYPE; +#define NAME atol +#endif + +TYPE +NAME(p) +register char *p; +{ + register TYPE n; + register int c, neg = 0; + + if (!isdigit(c = *p)) { + while (isspace(c)) + c = *++p; + switch (c) { + case '-': + neg++; + case '+': /* fall-through */ + c = *++p; + } + if (!isdigit(c)) + return (0); + } + for (n = '0' - c; isdigit(c = *++p); ) { + n *= 10; /* two steps to avoid unnecessary overflow */ + n += '0' - c; /* accum neg to avoid surprises at MAX */ + } + return (neg ? n : -n); +} diff --git a/usr/src/lib/libbc/libc/gen/common/base_conversion.h b/usr/src/lib/libbc/libc/gen/common/base_conversion.h new file mode 100644 index 0000000000..dd342ef7ec --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/base_conversion.h @@ -0,0 +1,464 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> + +#include <floatingpoint.h> + +#ifdef DEBUG +#include <stdio.h> +#include <assert.h> +#endif + +/* Sun floating-point PRIVATE include file. */ + +/* PRIVATE MACROS */ + +#ifdef DEBUG +#define PRIVATE +#else +#define PRIVATE static +#endif + +/* PRIVATE CONSTANTS */ + +#define SINGLE_BIAS 127 +#define DOUBLE_BIAS 1023 +#define EXTENDED_BIAS 16383 +#define QUAD_BIAS 16383 + +#define SINGLE_MAXE 97 /* Maximum decimal exponent we need to + * consider. */ +#define DOUBLE_MAXE 771 /* Maximum decimal exponent we need to + * consider. */ +#define EXTENDED_MAXE 12330 /* Maximum decimal exponent we need to + * consider. */ +#define QUAD_MAXE 12330 /* Maximum decimal exponent we need to + * consider. */ + +#define UNPACKED_SIZE 5 /* Size of unpacked significand. */ + +/* PRIVATE TYPES */ + +typedef struct { /* Unpack floating-point internal format. *//* V + * alue is 0.s0s1..sn * 2**(1+exponent) */ + int sign; + enum fp_class_type fpclass; + int exponent; /* Unbiased exponent. */ + unsigned significand[UNPACKED_SIZE]; /* Last word is round + * and sticky. */ +} + unpacked; + +#ifdef i386 +typedef struct { /* Most significant word formats. */ + unsigned significand:23; + unsigned exponent:8; + unsigned sign:1; +} + single_msw; + +typedef struct { + unsigned significand:20; + unsigned exponent:11; + unsigned sign:1; +} + double_msw; + +typedef struct { + unsigned exponent:15; + unsigned sign:1; + unsigned unused:16; +} + extended_msw; + +typedef struct { + unsigned significand:16; + unsigned exponent:15; + unsigned sign:1; +} + quadruple_msw; + +typedef struct { /* Floating-point formats in detail. */ + single_msw msw; +} + single_formatted; + +typedef struct { + unsigned significand2; + double_msw msw; +} + double_formatted; + +typedef struct { + unsigned significand2; + unsigned significand; + extended_msw msw; +} + extended_formatted; + +typedef struct { + unsigned significand4; + unsigned significand3; + unsigned significand2; + quadruple_msw msw; +} + quadruple_formatted; +#else +typedef struct { /* Most significant word formats. */ + unsigned sign:1; + unsigned exponent:8; + unsigned significand:23; +} + single_msw; + +typedef struct { + unsigned sign:1; + unsigned exponent:11; + unsigned significand:20; +} + double_msw; + +typedef struct { + unsigned sign:1; + unsigned exponent:15; + unsigned unused:16; +} + extended_msw; + +typedef struct { + unsigned sign:1; + unsigned exponent:15; + unsigned significand:16; +} + quadruple_msw; + +typedef struct { /* Floating-point formats in detail. */ + single_msw msw; +} + single_formatted; + +typedef struct { + double_msw msw; + unsigned significand2; +} + double_formatted; + +typedef struct { + extended_msw msw; + unsigned significand; + unsigned significand2; +} + extended_formatted; + +typedef struct { + quadruple_msw msw; + unsigned significand2; + unsigned significand3; + unsigned significand4; +} + quadruple_formatted; +#endif + +typedef union { /* Floating-point formats equivalenced. */ + single_formatted f; + single x; +} + single_equivalence; + +typedef union { + double_formatted f; + double x; +} + double_equivalence; + +typedef union { + extended_formatted f; + extended x; +} + extended_equivalence; + +typedef union { + quadruple_formatted f; + quadruple x; +} + quadruple_equivalence; + +/* PRIVATE GLOBAL VARIABLES */ + +fp_exception_field_type _fp_current_exceptions; /* Current floating-point + * exceptions. */ + +enum fp_direction_type + _fp_current_direction; /* Current rounding direction. */ + +enum fp_precision_type + _fp_current_precision; /* Current rounding precision. */ + +/* PRIVATE FUNCTIONS */ + +extern void +_fp_normalize( /* pu */ ); +/* unpacked *pu ; /* unpacked operand and result */ + +extern void +_fp_leftshift( /* pu, n */ ); +/* + * unpacked *pu; unsigned n; + */ + +extern void +_fp_set_exception( /* ex */ ); +/* enum fp_exception_type ex ; /* exception to be set in curexcep */ + +/* + * Default size for _big_float - suitable for single and double precision. + */ + +#define _BIG_FLOAT_SIZE (DECIMAL_STRING_LENGTH/2) +#define _BIG_FLOAT_DIGIT short unsigned /* big_float significand type */ + +#define _INTEGER_SIZE 4932 /* Maximum number of integer digits in a + * representable extended or quad. */ + +typedef struct { /* Variable-precision floating-point type + * used for intermediate results. */ + unsigned short bsize; /* Maximum allowable logical length of + * significand. */ + unsigned short blength;/* Logical length of significand. */ + short int bexponent; /* Exponent to be attached to least + * significant word of significand. + * exponent >= 0 implies all integer, + * with decimal point to right of + * least significant word of + * significand, and is equivalent to + * number of omitted trailing zeros + * of significand. -length < exponent + * < 0 implies decimal point within + * significand. exponent = -length + * implies decimal point to left of + * most significand word. exponent < + * -length implies decimal point to + * left of most significant word with + * -length-exponent leading zeros. */ + /* + * NOTE: bexponent represents a power of 2 or 10, even though big + * digits are powers of 2**16 or 10**4. + */ + _BIG_FLOAT_DIGIT bsignificand[_BIG_FLOAT_SIZE]; + /* + * Significand of digits in base 10**4 or 2**16. significand[0] is + * least significant, significand[length-1] is most significant. + */ +} _big_float; + +#define BIG_FLOAT_TIMES_NOMEM (_big_float *)0 +#define BIG_FLOAT_TIMES_TOOBIG (_big_float *)1 + +/* Internal functions defined in base conversion support routines. */ + +extern void _multiply_base_ten(); +extern void _multiply_base_two_carry(); +extern void _multiply_base_ten_by_two(); +extern void _multiply_base_two(); +extern void _multiply_base_two_by_two(); +extern void _carry_propagate_two(); +extern void _carry_propagate_ten(); +extern void _multiply_base_two_vector(); +extern void _multiply_base_ten_vector(); +extern void _fourdigitsquick(); +extern void _unpacked_to_big_float(); +extern void _big_binary_to_big_decimal(); +extern void _left_shift_base_ten(); +extern void _left_shift_base_two(); +extern void _right_shift_base_two(); +extern void _free_big_float(); +extern void _base_conversion_abort(); +extern void _display_big_float(); +extern void _integerstring_to_big_decimal(); +extern void _fractionstring_to_big_decimal(); +extern void _big_decimal_to_big_binary(); +extern void _fp_rightshift(); +extern void _fp_leftshift(); +extern void _fp_normalize(); +extern void _pack_single(); +extern void _pack_double(); +extern void _pack_extended(); +extern void _pack_quadruple(); +extern void _unpack_single(); +extern void _unpack_double(); +extern void _unpack_extended(); +extern void _unpack_quadruple(); +extern void _unpacked_to_decimal(); +extern enum fp_class_type _class_single(); +extern enum fp_class_type _class_double(); +extern enum fp_class_type _class_extended(); +extern enum fp_class_type _class_quadruple(); + +/* + Fundamental utilities that multiply or add two shorts into a unsigned long, + sometimes add an unsigned long carry, + compute quotient and remainder in underlying base, and return + quo<<16 | rem as a unsigned long. + */ + +extern unsigned long _umac(); /* p = x * y + c ; return p */ +/* +extern unsigned long _prodc_b65536(); /* p = x * y + c ; return p */ +#define _prodc_b65536(x,y,c) (_umac((x),(y),(c))) +extern unsigned long _prodc_b10000(); /* p = x * y + c ; return (p/10000 << +extern unsigned long _prod_b65536(); /* p = x * y ; return p */ +extern unsigned long _prod_b10000(); /* p = x * y ; return (p/10000 << 16 | p%10000) */ +extern unsigned long _prod_10000_b65536(); /* p = x * 10000 + c ; return + * p */ +extern unsigned long _prod_65536_b10000(); /* p = x * 65536 + c ; return + * (p/10000 << 16 | p%10000) */ +/* +extern unsigned long _rshift_b65536(); /* p = x << n + c<<16 ; return p */ +#define _rshift_b65536(x,n,c) ((((unsigned long) (x)) << (16-(n))) + ((c)<<16)) +/* +extern unsigned long _lshift_b65536(); /* p = x << n + c ; return p */ +#define _lshift_b65536(x,n,c) ((((unsigned long) (x)) << (n)) + (c)) +extern unsigned long _lshift_b10000(); /* p = x << n + c ; return (p/10000 + * << 16 | p%10000) */ +/* +extern unsigned long _carry_in_b65536(); /* p = x + c ; return p */ +#define _carry_in_b65536(x,c) ((x) + (c)) +extern unsigned long _carry_in_b10000(); /* p = x + c ; return + * (p/10000 << 16 | p%10000) */ +/* +extern unsigned long _carry_out_b65536(); /* p = c ; return p */ +#define _carry_out_b65536(c) (c) +extern unsigned long _carry_out_b10000(); /* p = c ; return (p/10000 << + * 16 | p%10000) */ + +/* + * Header file for revised "fast" base conversion based upon table look-up + * methods. + */ + +extern void +_big_float_times_power( +#ifdef notdef +/* function to multiply a big_float times a positive power of two or ten. */ + _big_float * pbf; /* Operand x, to be replaced + * by the product x * mult ** + * n. */ + int mult; /* if mult is two, x is base 10**4; if mult + * is ten, x is base 2**16 */ + int n; + int precision; /* Number of bits of precision + * ultimately required (mult=10) or + * number of digits of precision + * ultimately required (mult=2). + * Extra bits are allowed internally + * to permit correct rounding. */ + _big_float **pnewbf; /* Return result *pnewbf is set to: pbf f + * uneventful: *pbf holds the product ; + * BIG_FLOAT_TIMES_TOOBIG if n is + * bigger than the tables permit ; + * BIG_FLOAT_TIMES_NOMEM if + * pbf->blength was insufficient to hold the + * product, and malloc failed to produce a + * new block ; &newbf if + * pbf->blength was insufficient to hold the + * product, and a new _big_float was + * allocated by malloc. newbf holds the + * product. It's the caller's responsibility + * to free this space when no longer needed. */ +#endif +); + +/* Variables defined in _small_powers.c and _big_powers.c */ +/* Used in base conversion. */ + +/* + * The run-time structure consists of two large tables of powers - either + * powers of 10**4 in base 2**16 or vice versa. + * + * Suppose it's powers of T in base B. Then + * + * _tiny_powers_T contains TTINY entries, T**0, T**1, ... T**TTINY-1 where + * T is 2 or 10, TTINY is 16 or 4 _small_powers_T contains TSMALL + * entries, T**0, T**1, ... T**TSMALL-1 where T is 2**TTINY or 10**TTINY + * _big_powers_T contains TBIG entries, T**0, T**1, ... T**TBIG-1 + * where T is (2**TTINY)**TSMALL or (10**TTINY)**TSMALL + * + * so that any power of T from 0 to T**(TTINY*TSMALL*TBIG-1) can be represented + * as a product of just two table entries. Since the powers vary greatly in + * size, the tables are condensed to exclude leading and trailing zeros. The + * following tables + * + * _max_tiny_powers_T contains one entry, TTINY + * _start_tiny_powers_T contains TTINY entries + * _leading_zeros_tiny_powers_T contains TTINY entries + * _max_small_powers_T contains one entry, TSMALL + * _start_small_powers_T contains TSMALL entries + * _leading_zeros_small_powers_T contains TSMALL entries + * _max_big_powers_T contains one entry, TBIG + * _start_big_powers_T contains TBIG entries + * _leading_zeros_big_powers_T contains TBIG entries + * + * The powers are maintained with x[start] less significant than x[start+1], so + * + * The powers are maintained with x[start] less significant than x[start+1], so + * that the interpretation of a _small_powers_T entry is that + * +T**i = (B**leading_zeros[i]) * (x[start[i]] + x[start[i]+1] * B + ... + * x[start[i+1]-1] * B**(start[i+1]-start[i]) ) + * + * where B = (2 or 10)**TTINY + * + * The powers are listed consecutively in the tables, with start index and + * leading zero information retained and printed out at the end. + * + */ + +extern unsigned short _max_tiny_powers_ten; +extern unsigned short _tiny_powers_ten[]; +extern unsigned short _start_tiny_powers_ten[]; +extern unsigned short _leading_zeros_tiny_powers_ten[]; +extern unsigned short _max_tiny_powers_two; +extern unsigned short _tiny_powers_two[]; +extern unsigned short _start_tiny_powers_two[]; + +extern unsigned short _max_small_powers_ten; +extern unsigned short _small_powers_ten[]; +extern unsigned short _start_small_powers_ten[]; +extern unsigned short _leading_zeros_small_powers_ten[]; +extern unsigned short _max_small_powers_two; +extern unsigned short _small_powers_two[]; +extern unsigned short _start_small_powers_two[]; + +extern unsigned short _max_big_powers_ten; +extern unsigned short _big_powers_ten[]; +extern unsigned short _start_big_powers_ten[]; +extern unsigned short _leading_zeros_big_powers_ten[]; +extern unsigned short _max_big_powers_two; +extern unsigned short _big_powers_two[]; +extern unsigned short _start_big_powers_two[]; diff --git a/usr/src/lib/libbc/libc/gen/common/bcmp.c b/usr/src/lib/libbc/libc/gen/common/bcmp.c new file mode 100644 index 0000000000..ea0f30a4f5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/bcmp.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB X.X XX/XX/XX */ + +bcmp(s1, s2, len) + register char *s1, *s2; + register int len; +{ + + while (len--) + if (*s1++ != *s2++) + return (1); + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/bsearch.c b/usr/src/lib/libbc/libc/gen/common/bsearch.c new file mode 100644 index 0000000000..d5ee461163 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/bsearch.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +/* + * Binary search algorithm, generalized from Knuth (6.2.1) Algorithm B. + * + */ + +typedef char *POINTER; + +POINTER +bsearch(key, base, nel, width, compar) +POINTER key; /* Key to be located */ +POINTER base; /* Beginning of table */ +unsigned nel; /* Number of elements in the table */ +unsigned width; /* Width of an element (bytes) */ +int (*compar)(); /* Comparison function */ +{ + int two_width = width + width; + POINTER last = base + width * (nel - 1); /* Last element in table */ + + while (last >= base) { + + register POINTER p = base + width * ((last - base)/two_width); + register int res = (*compar)(key, p); + + if (res == 0) + return (p); /* Key found */ + if (res < 0) + last = p - width; + else + base = p + width; + } + return ((POINTER) 0); /* Key not found */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/calloc.c b/usr/src/lib/libbc/libc/gen/common/calloc.c new file mode 100644 index 0000000000..66b2788825 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/calloc.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * calloc - allocate and clear memory block + */ +#define CHARPERINT (sizeof(int)/sizeof(char)) +#define NULL 0 +#ifdef S5EMUL +#define ptr_t void* +#else +#define ptr_t char* +#endif + +ptr_t +calloc(num, size) + unsigned num, size; +{ + register ptr_t mp; + ptr_t malloc(); + + num *= size; + mp = malloc(num); + if (mp == NULL) + return(NULL); + bzero(mp, num); + return ((ptr_t)(mp)); +} + +cfree(p, num, size) + ptr_t p; + unsigned num, size; +{ + free(p); +} diff --git a/usr/src/lib/libbc/libc/gen/common/char_to_decimal.h b/usr/src/lib/libbc/libc/gen/common/char_to_decimal.h new file mode 100644 index 0000000000..e08f177d39 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/char_to_decimal.h @@ -0,0 +1,532 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This file contains the common part of string_to_decimal, func_to_decimal, + * and file_to_decimal. NEXT must be defined to cause CURRENT to contain the + * next input character. ATEOF must be defined to be == EOF if an input + * file is at EOF, != EOF otherwise. + */ + +{ + int sigfound; + int ids = 0; + int i; + int nzbp = 0, nzap = 0; /* Length of zero substring + * before point, after point. */ + char decpt; + int nfast, nfastlimit; + char *pfast; + + *pform = invalid_form; /* Invalid until we find something. */ + *pechar = NULL; /* No exponent field assumed. */ + pd->fpclass = fp_normal;/* Defaults. */ + pd->sign = 0; /* Positive. */ + pd->exponent = 0; + pd->more = 0; /* Assume no overflow of digits on NaN + * string. */ + if (fortran_conventions != 0) + decpt = '.'; + else +#ifdef PRE41 + decpt = '.'; +#else + decpt = *(localeconv()->decimal_point); +#endif + while (isspace(CURRENT)) { + NEXT; + } /* Skip white space. */ + if (fortran_conventions >= 2) { + /* + * All white space - valid zero for Fortran formatted input. + */ + *pform = whitespace_form; + if (isspace(*cp)) + good = cp; + else + good = cp - 1; + if ((nread >= nmax) && (CURRENT == NULL)) { /* Used up field width. */ + pd->fpclass = fp_zero; + goto done; + } + } + if (CURRENT == '+') { + NEXT; + } else if (CURRENT == '-') { /* Negative. */ + pd->sign = 1; + NEXT; + } + sigfound = -1; /* -1 = no digits found yet. */ + + if (('1' <= CURRENT) && (CURRENT <= '9')) { + good = cp; + *pform = fixed_int_form; + sigfound = 1; /* 1 = significant digits found. */ + pd->ds[ids++] = CURRENT; + NEXT; + goto number; + } else + switch (CURRENT) { + case ' ': + if (fortran_conventions < 2) + goto firstdefault; + case '0': + *pform = fixed_int_form; + while ((CURRENT == '0') || ((fortran_conventions >= 2) && (CURRENT == ' '))) { + NEXT; + } /* Ignore leading zeros. */ + if ((*cp == '0') || ((fortran_conventions >= 2) && (*cp == ' '))) + good = cp; + else + good = cp - 1; + sigfound = 0; /* 0 = only zeros found yet. */ + goto number; + case 'i': + case 'I': + { /* Try infinity. */ + static char *infstring = "INFINITY"; + int is, iagree; + +#define UCASE(c) ( (('a' <= c) && (c <= 'z')) ? c - 32 : c ) + + NEXT; + is = 1; + while (is <= 7 && + UCASE(CURRENT) == infstring[is]) { + NEXT; + is++; + } + iagree = is; + if (CURRENT != NULL) { + is++; /* To account for infstring + * indexing starting at 0. + */ + } + if (iagree >= 3) { /* Found syntactically + * valid infinity. */ + if (iagree < 8) { /* INFxxxx */ + if (iagree > 3) { + nmax++; /* 1083219 */ + CURRENT = EOF; /* 1083219 */ + } + good = cp - (is - 3); + *pform = inf_form; + } else { /* INFINITYxxx */ + good = cp - (is - 8); + *pform = infinity_form; + } + pd->fpclass = fp_infinity; + sigfound = iagree; + } + else { + nmax++; /* 1083219 */ + CURRENT = EOF; /* 1083219 */ + } + goto done; + } + case 'n': + case 'N': + { /* Try NaN. */ + static char *nanstring = "NAN("; + int is; + + NEXT; + is = 1; + while (is <= 3 && + UCASE(CURRENT) == nanstring[is]) { + NEXT; + is++; + } + if ((is == 3)) { /* Found syntactically + * valid NaN. */ + *pform = nan_form; + good = CURRENT == NULL ? cp : cp - 1; + pd->fpclass = fp_quiet; + sigfound = 1; + } + else if (is == 4) { /* Found NaN followed by + * parenthesis. */ + good = CURRENT == NULL ? cp - 1 : cp - 2; + *pform = nan_form; + pd->fpclass = fp_quiet; + sigfound = 1; + while ((CURRENT != 0) && (CURRENT != ')') && (ids < (DECIMAL_STRING_LENGTH - 1))) { + pd->ds[ids++] = CURRENT; + NEXT; + } + while ((CURRENT != 0) && (CURRENT != ')') && (ATEOF != EOF)) { /* Pick up rest of + * string. */ + pd->more = 1; + NEXT; + } + if (CURRENT == ')') { + good = cp; + NEXT; + *pform = nanstring_form; + } + else { + nmax++; /* 1083219 */ + CURRENT = EOF; /* 1083219 */ + } + } + else { + nmax++; /* 1083219 */ + CURRENT = EOF; /* 1083219 */ + } + goto done; + } + default: + if (CURRENT == decpt) { + NEXT; /* Try number. */ + goto afterpoint; + } + firstdefault: + goto done; + } + +number: + +nextnumber: + if (('1' <= CURRENT) && (CURRENT <= '9')) { + if ((ids + nzbp + 2) >= DECIMAL_STRING_LENGTH) { /* Not enough room to + * store it all: fake + * end of string. */ + pd->exponent += nzbp + 1; + pd->more = 1; + pd->ds[ids] = 0; /* Actual string termination. */ + ids = DECIMAL_STRING_LENGTH - 1; /* To allow end of + * program to terminate + * again. */ + } else { + for (i = 0; (i < nzbp); i++) + pd->ds[ids++] = '0'; + pd->ds[ids++] = CURRENT; + } + *pform = fixed_int_form; + sigfound = 1; + nzbp = 0; + NEXT; + nfastlimit = DECIMAL_STRING_LENGTH - 3 - ids; + if ((0 < nfastlimit) && ('1' <= CURRENT) && (CURRENT <= '9')) { /* Special handling for + * common case. */ + nfast = 0; + pfast = &(pd->ds[ids]); + do { + pfast[nfast++] = CURRENT; + NEXT; + } + while (('1' <= CURRENT) && (CURRENT <= '9') && (nfast < nfastlimit)); + ids += nfast; + } + if (CURRENT == '0') + goto nextnumberzero; /* common case */ + good = cp; + if (('1' > *good) || (*good > '9')) + good--; /* look out if we fell off end */ + goto nextnumber; + } else + switch (CURRENT) { + case ' ': + if (fortran_conventions < 2) + goto numberdefault; + if (fortran_conventions == 2) { + NEXT; + goto nextnumber; + } + case '0': + *pform = fixed_int_form; + nextnumberzero: + while ((CURRENT == '0') || (CURRENT == ' ')) { /* Accumulate zero + * substring. */ + if (CURRENT == ' ') { + if (fortran_conventions < 2) { + good = cp - 1; + goto numberdefault; + } + if (fortran_conventions == 2) { + nzbp--; /* Undo effect of + * following nzbp++ */ + } + } + good = cp; + nzbp++; + NEXT; + } + goto nextnumber; + + case 'E': + case 'e': + efound: + *pechar = cp; + if (sigfound == -1) /* exp following no digits? + * bad format */ + goto done; + if (sigfound > 0) + pd->exponent += nzbp; + goto exponent; + case '+': + case '-': + case 'D': + case 'd': + case 'Q': + case 'q': + if (fortran_conventions != 0) + goto efound; + default: + if (CURRENT == decpt) { + NEXT; + goto afterpoint; + } + numberdefault: + if (sigfound > 0) + pd->exponent += nzbp; + goto done; + } + +afterpoint: + if (sigfound >= 0) { /* Better accept the point as good, but don't + * accept the next character after. */ + good = cp - 1; /* Assume cp points past. */ + if (*good != decpt) /* If not, bump good. */ + good++; + } + switch (*pform) { /* Revise *pform now that point has been + * found. */ + case invalid_form: + case whitespace_form: + *pform = fixed_dotfrac_form; + break; + case fixed_int_form: + *pform = fixed_intdot_form; + break; + } +switchafterpoint: + if (('1' <= CURRENT) && (CURRENT <= '9')) { + if (*pform == fixed_intdot_form) + *pform = fixed_intdotfrac_form; + good = cp; + if (sigfound < 1) { /* No significant digits found so + * far. */ + sigfound = 1; + pd->ds[ids++] = CURRENT; + pd->exponent = -(nzap + 1); + } else { /* Significant digits have begun. */ + if ((ids + nzbp + nzap + 2) >= DECIMAL_STRING_LENGTH) { /* Not enough room to + * store it all: fake + * end of string. */ + pd->exponent += nzbp; + pd->more = 1; + pd->ds[ids] = 0; /* Actual string + * termination. */ + ids = DECIMAL_STRING_LENGTH - 1; /* To allow end of + * program to terminate + * again. */ + } else { + for (i = 0; (i < (nzbp + nzap)); i++) + pd->ds[ids++] = '0'; + pd->ds[ids++] = CURRENT; + pd->exponent -= nzap + 1; + } + } + nzbp = 0; + nzap = 0; + NEXT; + nfastlimit = DECIMAL_STRING_LENGTH - 3 - ids; + if ((0 < nfastlimit) && ('1' <= CURRENT) && (CURRENT <= '9')) { /* Special handling for + * common case. */ + nfast = 0; + pfast = &(pd->ds[ids]); + do { + pfast[nfast++] = CURRENT; + NEXT; + } + while (('1' <= CURRENT) && (CURRENT <= '9') && (nfast < nfastlimit)); + good = cp; + if (('1' > *good) || (*good > '9')) + good--; /* look out if we fell off end */ + ids += nfast; + pd->exponent -= nfast; + } + if (CURRENT == '0') + goto zeroafterpoint; + goto switchafterpoint; + } else + switch (CURRENT) { + case ' ': + if (fortran_conventions < 2) + goto afterpointdefault; + if (fortran_conventions == 2) { + /* + * To pass FCVS, all blanks after point must + * count as if zero seen. + */ + if (sigfound == -1) + sigfound = 0; + NEXT; + goto switchafterpoint; + } + case '0': + if (*pform == fixed_intdot_form) + *pform = fixed_intdotfrac_form; + if (sigfound == -1) + sigfound = 0; + zeroafterpoint: + good = cp; + nzap++; + NEXT; + while ((CURRENT == '0') || (CURRENT == ' ')) { + if (CURRENT == ' ') { /* Handle blanks and + * Fortran. */ + if (fortran_conventions < 2) { + good = cp - 1; + goto afterpointdefault; + } + if (fortran_conventions == 2) { + nzap--; /* Undo following nzap++ */ + } + } + nzap++; + NEXT; + } + good = cp; + if (*good != '0') + good--; + goto switchafterpoint; + + case 'E': + case 'e': + efound2: + *pechar = cp; + if (sigfound == -1) /* exp following no digits? + * bad! */ + goto done; + if (sigfound > 0) + pd->exponent += nzbp; + goto exponent; + case '+': + case '-': + case 'D': + case 'd': + case 'Q': + case 'q': + if (fortran_conventions != 0) + goto efound2; + + default: + afterpointdefault: + if (sigfound > 0) + pd->exponent += nzbp; + goto done; + } +exponent: + { + unsigned explicitsign = 0, explicitexponent = 0; + + if ((CURRENT != '+') && (CURRENT != '-')) { /* Skip EeDd and + * following blanks. */ + NEXT; /* Pass the EeDd. */ + if (fortran_conventions >= 2) + while (CURRENT == ' ') { + NEXT; + } + } + if (CURRENT == '+') { + NEXT; + } else if (CURRENT == '-') { /* Negative explicit + * exponent. */ + NEXT; + explicitsign = 1; + } + while ((('0' <= CURRENT) && (CURRENT <= '9')) || (CURRENT == ' ')) { /* Accumulate explicit + * exponent. */ + if (CURRENT == ' ') { /* Handle blanks and Fortran. */ + if (fortran_conventions < 2) + goto doneexp; + if (fortran_conventions == 2) { + NEXT; + goto exploop; + } + CURRENT = '0'; + } + good = cp; + if (explicitexponent <= 400000000) { + explicitexponent = 10 * explicitexponent + CURRENT - '0'; + } + NEXT; + switch (*pform) { + case whitespace_form: + case fixed_int_form: + *pform = floating_int_form; + break; + case fixed_intdot_form: + *pform = floating_intdot_form; + break; + case fixed_dotfrac_form: + *pform = floating_dotfrac_form; + break; + case fixed_intdotfrac_form: + *pform = floating_intdotfrac_form; + break; + } + exploop: ; + } +doneexp: + if (explicitsign == 1) + pd->exponent -= explicitexponent; + else + pd->exponent += explicitexponent; + } + +done: + if (fortran_conventions >= 2) { /* Fill up field width with extra + * blanks found. */ + if (good == (cp - 1)) + good = NULL; /* Flag that whole field was good up + * to now. */ + while (CURRENT == ' ') { + NEXT; + } + if (good == NULL) { + good = CURRENT == NULL ? cp : cp - 1; + } + } + if (sigfound < 1) + pd->fpclass = fp_zero; /* True zero found. */ + + pd->ds[ids] = 0; /* Terminate decimal string. */ + pd->ndigits = ids; /* Save string length in ndigits. */ + if (good >= cp0) { /* Valid token found. */ + *ppc = good + 1;/* token found - point one past. */ + } else { /* No valid token found. */ + *pform = invalid_form; + *ppc = cp0; /* No token found - revert to original value. */ + pd->sign = 0; + pd->fpclass = fp_signaling; /* If anyone looks, x will be + * nan. */ + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/clock.c b/usr/src/lib/libbc/libc/gen/common/clock.c new file mode 100644 index 0000000000..9045962263 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/clock.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ + +#include <sys/types.h> +#include <sys/times.h> +#include <sys/param.h> /* for HZ (clock frequency in Hz) */ +#define TIMES(B) (B.tms_utime+B.tms_stime+B.tms_cutime+B.tms_cstime) + +extern long times(); +static long first; + +long +clock() +{ + struct tms buffer; + + if (times(&buffer) == -1L) + return (0L); + if (first == 0L) + first = TIMES(buffer); + return ((TIMES(buffer) - first) * (1000000L/HZ)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/closedir.c b/usr/src/lib/libbc/libc/gen/common/closedir.c new file mode 100644 index 0000000000..5aa8c21e0c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/closedir.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/param.h> +#include <dirent.h> + +/* + * close a directory. + */ +int +closedir(dirp) + register DIR *dirp; +{ + int fd; + extern void free(); + extern int close(); + + fd = dirp->dd_fd; + dirp->dd_fd = -1; + dirp->dd_loc = 0; + free(dirp->dd_buf); + free((char *)dirp); + return (close(fd)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/codeset.h b/usr/src/lib/libbc/libc/gen/common/codeset.h new file mode 100644 index 0000000000..9199780307 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/codeset.h @@ -0,0 +1,73 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * codeset information + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifndef lint +/* static char *sccsid = "%Z%%M% %I% %E% SMI"; */ +#endif + +#include <stdio.h> +#define NAME_SIZE 14 /* Length of the code set name */ + +struct _code_header { + char code_name[NAME_SIZE+1]; /* code set name */ + int code_id; /* code set id */ + int code_info_size; /* size of code set info */ +}; + +struct _code_set_info { + char code_name[NAME_SIZE+1]; /* code set name */ + int code_id; /* code ID */ + char *code_info; /* code information */ + int open_flag; /* Am I open library ? */ +}; + +#define EUC_SET "euc" +#define XCCS_SET "xccs" +#define ISO2022_SET "iso2022" + +#define CODESET_NONE 0 +#define CODESET_EUC 2 +#define CODESET_XCCS 3 +#define CODESET_ISO2022 4 +#define CODESET_USER 100 + +#define ERROR -1 +#define ERROR_NO_LIB -2 /* dlopen failed */ +#define ERROR_NO_SYM -3 /* dlsym failed */ + +#ifdef DEBUG +#define LIBRARY_PATH "/tmp/" +#else +#define LIBRARY_PATH "/usr/lib/" +#endif + +void *_ml_open_library(); diff --git a/usr/src/lib/libbc/libc/gen/common/crypt.c b/usr/src/lib/libbc/libc/gen/common/crypt.c new file mode 100644 index 0000000000..037b9527b4 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/crypt.c @@ -0,0 +1,75 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* The real crypt is now _crypt. This version performs automatic + * authentication via pwauth for special password entries, or simply + * calls _crypt for the usual case. + */ + +char * +crypt(pw, salt) +char *pw, *salt; +{ + static char *iobuf; + extern char *_crypt(); + extern char *malloc(); + + if (iobuf == 0) { + iobuf = malloc((unsigned)16); + if (iobuf == 0) + return (0); + } + /* handle the case where the password is really in passwd.adjunct. + * In this case, the salt will start with "##". We should call + * passauth to determine if pw is valid. If so, we should return + * the salt, and otherwise return NULL. If salt does not start with + * "##", crypt will act in the normal fashion. + */ + if (salt[0] == '#' && salt[1] == '#') { + if (pwdauth(salt+2, pw) == 0) + strcpy(iobuf, salt); + else + iobuf[0] = '\0'; + return(iobuf); + } + /* handle the case where the password is really in group.adjunct. + * In this case, the salt will start with "#$". We should call + * grpauth to determine if pw is valid. If so, we should return + * the salt, and otherwise return NULL. If salt does not start with + * "#$", crypt will act in the normal fashion. + */ + if (salt[0] == '#' && salt[1] == '$') { + if (grpauth(salt+2, pw) == 0) + strcpy(iobuf, salt); + else + iobuf[0] = '\0'; + return(iobuf); + } + return (_crypt(pw, salt)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ctime.c b/usr/src/lib/libbc/libc/gen/common/ctime.c new file mode 100644 index 0000000000..4ff04654ae --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ctime.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Arthur Olson. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from Arthur Olson's 3.1 */ + +/*LINTLIBRARY*/ + +#include <sys/types.h> +#include <time.h> + +char * +ctime(timep) +time_t * timep; +{ + return asctime(localtime(timep)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ctype_.c b/usr/src/lib/libbc/libc/gen/common/ctype_.c new file mode 100644 index 0000000000..a46c969f72 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ctype_.c @@ -0,0 +1,172 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/07/08 */ + +#include <ctype.h> +#include <stdlib.h> + + +char _ctype_[] = { 0, + +/* 0 1 2 3 4 5 6 7 */ + +/* 0*/ _C, _C, _C, _C, _C, _C, _C, _C, +/* 10*/ _C, _S|_C, _S|_C, _S|_C, _S|_C, _S|_C, _C, _C, +/* 20*/ _C, _C, _C, _C, _C, _C, _C, _C, +/* 30*/ _C, _C, _C, _C, _C, _C, _C, _C, +/* 40*/ (char)(_S|_B), _P, _P, _P, _P, _P, _P, _P, +/* 50*/ _P, _P, _P, _P, _P, _P, _P, _P, +/* 60*/ _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, _N|_X, +/* 70*/ _N|_X, _N|_X, _P, _P, _P, _P, _P, _P, +/*100*/ _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, +/*110*/ _U, _U, _U, _U, _U, _U, _U, _U, +/*120*/ _U, _U, _U, _U, _U, _U, _U, _U, +/*130*/ _U, _U, _U, _P, _P, _P, _P, _P, +/*140*/ _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, +/*150*/ _L, _L, _L, _L, _L, _L, _L, _L, +/*160*/ _L, _L, _L, _L, _L, _L, _L, _L, +/*170*/ _L, _L, _L, _P, _P, _P, _P, _C, +/*200*/ 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0 +}; + +unsigned int _mb_cur_max; + +/* Now we also supply the functions in libc as well as the macros in + * ctype.h + */ + +#undef isalpha +#undef isupper +#undef islower +#undef isdigit +#undef isxdigit +#undef isspace +#undef ispunct +#undef isalnum +#undef isprint +#undef isgraph +#undef iscntrl +#undef isascii +#undef toascii + +extern int mbtowc(); + +int isalpha(c) +register int c; +{ + return((_ctype_+1)[c]&(_U|_L)); +} + +int isupper(c) +register int c; +{ + return((_ctype_+1)[c]&_U); +} + +int islower(c) +register int c; +{ + return((_ctype_+1)[c]&_L); +} + +int isdigit(c) +register int c; +{ + return((_ctype_+1)[c]&_N); +} + +int isxdigit(c) +register int c; +{ + return((_ctype_+1)[c]&_X); +} + + +int isspace(c) +register int c; +{ + return((_ctype_+1)[c]&_S); +} + + +int ispunct(c) +register int c; +{ + return((_ctype_+1)[c]&_P); +} + + +int isalnum(c) +register int c; +{ + return((_ctype_+1)[c]&(_U|_L|_N)); +} + + +int isprint(c) +register int c; +{ + return((_ctype_+1)[c]&(_P|_U|_L|_N|_B)); +} + + +int isgraph(c) +register int c; +{ + return((_ctype_+1)[c]&(_P|_U|_L|_N)); +} + + +int iscntrl(c) +register int c; +{ + return((_ctype_+1)[c]&_C); +} + +int isascii(c) +register int c; +{ + return((unsigned)(c)<=0177); +} + +int toascii(c) +register int c; +{ + return((c)&0177); +} + diff --git a/usr/src/lib/libbc/libc/gen/common/decimal_bin.c b/usr/src/lib/libbc/libc/gen/common/decimal_bin.c new file mode 100644 index 0000000000..c398f592b7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/decimal_bin.c @@ -0,0 +1,694 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* Conversion between binary and decimal floating point. */ + +#include "base_conversion.h" + +void +decimal_to_binary_integer(ds, ndigs, nzeros, nsig, pb) + char ds[]; /* Input decimal integer string. */ +unsigned ndigs; /* Input number of explicit digits in ds. */ +unsigned nzeros; /* Input number of implicit trailing zeros. */ +unsigned nsig; /* Input number of significant bits required. */ +_big_float *pb; /* Pointer to big_float to receive result. */ + +/* + * Converts a decimal integer string ds with ndigs explicit leading digits + * and nzeros implicit trailing zeros to a _big_float **pb, which only + * requires nsig significand bits. + */ +/* Inexactness is indicated by pb->bsignificand[0] |= 1. */ +/* + * If the input is too big for a big_float, pb->bexponent is set to 0x7fff. + */ + +{ + unsigned nzout; + _big_float d, *pbout; + + d.bsize = _BIG_FLOAT_SIZE; + _integerstring_to_big_decimal(ds, ndigs, nzeros, &nzout, &d); + _big_decimal_to_big_binary(&d, pb); + if (nzout != 0) { + _big_float_times_power(pb, 10, (int) nzout, (int) nsig, &pbout); + switch ((unsigned int)pbout) { + case ((unsigned int)BIG_FLOAT_TIMES_TOOBIG): +#ifdef DEBUG + (void) printf(" decimal_to_binary_integer: decimal exponent %d too large for tables ", nzout); +#endif + pb->bexponent = 0x7fff; + break; + case ((unsigned int)BIG_FLOAT_TIMES_NOMEM): + { + char bcastring[80]; + + (void) sprintf(bcastring, " decimal exponent %d ", nzout); + _base_conversion_abort(ENOMEM, bcastring); + break; + } + default: +#ifdef DEBUG + if (pbout != pb) + (void) printf(" decimal_to_binary_integer: large decimal exponent %d needs heap buffer \n", nzout); + printf(" decimal_to_binary_integer: product "); + _display_big_float(pb, 2); +#endif + if (pbout != pb) { /* We don't really need such + * a large product; the + * target can't be more than + * a quad! */ + int i, allweneed; + + allweneed = 2 + (nsig + 2) / 16; + for (i = 0; i < allweneed; i++) + pb->bsignificand[i] = pbout->bsignificand[i + pbout->blength - allweneed]; + for (i = 0; (pbout->bsignificand[i] == 0); i++); + if (i < (pbout->blength - allweneed)) + pb->bsignificand[0] |= 1; /* Stick discarded bits. */ + + pb->blength = allweneed; + pb->bexponent = pbout->bexponent + 16 * (pbout->blength - allweneed); +#ifdef DEBUG + printf(" decimal_to_binary_integer: removed %d excess digits from product \n", pbout->blength - allweneed); + _display_big_float(pb, 2); +#endif + _free_big_float(pbout); + } + break; + } + } +} + +void +decimal_to_binary_fraction(ds, ndigs, nzeros, nsig, pb) + char ds[]; /* Decimal integer string input. */ +unsigned ndigs; /* Number of explicit digits to read. */ +unsigned nzeros; /* Number of implicit leading zeros before + * digits. */ +unsigned nsig; /* Number of significant bits needed. */ +_big_float *pb; /* Pointer to intended big_float result. */ + +/* + * Converts an explicit decimal string *ds[0]..*ds[ndigs-1] preceded by + * nzeros implicit leading zeros after the point into a big_float at *pb. If + * the input does not fit exactly in a big_float, the least significant bit + * of pbout->significand is stuck on. If the input is too big for the base + * conversion tables, pb->bexponent is set to 0x7fff. + */ + +{ + unsigned twopower, twosig; + int i, excess; + _big_float d, *pdout; + + d.bsize = _BIG_FLOAT_SIZE; + _fractionstring_to_big_decimal(ds, ndigs, nzeros, &d); + + twopower = nsig + 3 + (((nzeros + 1) * (unsigned long) 217706) >> 16); + twosig = 1 + (((nsig + 2) * (unsigned long) 19729) >> 16); + +#ifdef DEBUG + printf(" decimal_to_binary_fraction sigbits %d twopower %d twosig %d \n", + nsig, twopower, twosig); +#endif + _big_float_times_power(&d, 2, (int) twopower, (int) twosig, &pdout); + switch ((unsigned int)pdout) { + case ((unsigned int)BIG_FLOAT_TIMES_TOOBIG): +#ifdef DEBUG + (void) printf(" decimal_to_binary_fraction binary exponent %d too large for tables ", twopower); +#endif + pb->bexponent = 0x7fff; + goto ret; + case ((unsigned int)BIG_FLOAT_TIMES_NOMEM): + { + char bcastring[80]; + + (void) sprintf(bcastring, " binary exponent %d ", twopower); + _base_conversion_abort(ENOMEM, bcastring); + break; + } + default: +#ifdef DEBUG + if (&d != pdout) + printf(" decimal_to_binary_fraction large binary exponent %d needs heap buffer \n", twopower); + printf(" product "); + _display_big_float(pdout, 10); +#endif + break; + } + + + if (pdout->bexponent <= -4) { + /* Have computed appropriate decimal part; now toss fraction. */ + excess = (-pdout->bexponent) / 4; +#ifdef DEBUG + printf(" discard %d excess fraction digits \n", 4 * excess); +#endif + for (i = 0; (i < excess) && ((pdout)->bsignificand[i] == 0); i++); + if (i < excess) + (pdout)->bsignificand[excess] |= 1; /* Sticky bit for + * discarded fraction. */ + for (i = excess; i < (pdout)->blength; i++) + (pdout)->bsignificand[i - excess] = (pdout)->bsignificand[i]; + + (pdout)->blength -= excess; + (pdout)->bexponent += 4 * excess; + } + _big_decimal_to_big_binary(pdout, pb); + if (pdout != &d) + _free_big_float(pdout); + pb->bexponent = -twopower; + +ret: + return; +} + +void +decimal_to_unpacked(px, pd, significant_bits) + unpacked *px; + decimal_record *pd; + unsigned significant_bits; + +/* + * Converts *pd to *px so that *px can be correctly rounded. significant_bits + * tells how many bits will be significant in the final result to avoid + * superfluous computation. Inexactness is communicated by sticking on the + * lsb of px->significand[UNPACKED_SIZE-1]. Integer buffer overflow is + * indicated with a huge positive exponent. + */ + +{ + int frac_bits, sigint; + unsigned length, ndigs, ntz, nlz, ifrac, nfrac; + _big_float bi, bf, *ptounpacked = &bi; + + px->sign = pd->sign; + px->fpclass = pd->fpclass; + if ((px->fpclass != fp_normal) && (px->fpclass != fp_subnormal)) + goto ret; + for (length = 0; pd->ds[length] != 0; length++); + if (length == 0) { /* A zero significand slipped by. */ + px->fpclass = fp_zero; + goto ret; + } + /* Length contains the number of explicit digits in string. */ + if (pd->exponent >= 0) {/* All integer digits. */ + ndigs = length; + ntz = pd->exponent; /* Trailing zeros. */ + ifrac = 0; + nfrac = 0; /* No fraction digits. */ + nlz = 0; + } else if (length <= -pd->exponent) { /* No integer digits. */ + ndigs = 0; + ntz = 0; + ifrac = 0; + nfrac = length; + nlz = -pd->exponent - length; /* Leading zeros. */ + } else { /* Some integer digits, some fraction digits. */ + ndigs = length + pd->exponent; + ntz = 0; + ifrac = ndigs; + nfrac = -pd->exponent; + nlz = 0; + while ((pd->ds[ifrac] == '0') && (nfrac != 0)) { + ifrac++; + nfrac--; + nlz++; + } /* Remove leading zeros. */ + } + if (ndigs != 0) { /* Convert integer digits. */ + + bi.bsize = _BIG_FLOAT_SIZE; + decimal_to_binary_integer(pd->ds, ndigs, ntz, significant_bits, &bi); + if (bi.bexponent == 0x7fff) { /* Too big for buffer. */ + px->exponent = 0x000fffff; + px->significand[0] = 0x80000000; + goto ret; + } + sigint = 16 * (bi.blength + bi.bexponent - 1); + if (sigint < 0) + sigint = 0; + } else { /* No integer digits. */ + bi.blength = 0; + bi.bsignificand[0] = 0; + bi.bexponent = 0; + sigint = 0; + } + frac_bits = significant_bits - sigint + 2; + bf.blength = 0; + if ((nfrac != 0) && (frac_bits > 0)) { /* Convert fraction digits, + * even if we only need a + * round or sticky. */ + + bf.bsize = _BIG_FLOAT_SIZE; + decimal_to_binary_fraction(&(pd->ds[ifrac]), nfrac, nlz, (unsigned) frac_bits, &bf); + } else { /* Only need fraction bits for sticky. */ + if (nfrac != 0) + bi.bsignificand[0] |= 1; /* Stick for fraction. */ + } + if (bi.blength == 0) { /* No integer digits; all fraction. */ + if (bf.bexponent == 0x7fff) { /* Buffer overflowed. */ + px->exponent = -0x000fffff; + px->significand[0] = 0x80000000; + goto ret; + } + ptounpacked = &bf; /* Exceptional case - all fraction. */ + goto punpack; + } + if (bf.blength != 0) { /* Combine integer and fraction bits. */ + int expdiff = bi.bexponent - (bf.bexponent + 16 * (bf.blength - 1)); /* Exponent difference. */ + int uneeded = 2 + (significant_bits + 2) / 16; /* Number of big float + * digits needed. */ + int nmove, leftshift, i, if0; + +#ifdef DEBUG + printf(" bi+bf exponent diff is %d \n", expdiff); + printf(" need %d big float digits \n", uneeded); + assert(bi.blength != 0); + assert(bf.blength != 0); + assert(bi.bsignificand[bi.blength - 1] != 0); /* Normalized bi. */ + assert(bf.bsignificand[bf.blength - 1] != 0); /* Normalized bf. */ + assert(bi.bexponent >= 0); /* bi is all integer */ + assert(((-bf.bexponent - 16 * (bf.blength - 1)) >= 16) || + ((bf.bsignificand[bf.blength - 1] >> (-bf.bexponent - 16 * (bf.blength - 1))) == 0)); + /* assert either bf << 1 or bf < 1 */ + /* + * Assert that integer and fraction parts don't overlap by + * more than one big digit. + */ + assert(expdiff > 0); + assert(uneeded <= (2 * UNPACKED_SIZE)); +#endif + + + if (bi.blength >= uneeded) { /* bi will overflow unpacked, + * so bf is just a sticky. */ + bi.bsignificand[0] |= 1; + goto punpack; + } + leftshift = 16 - (expdiff % 16); + if (leftshift > 0) { /* shift bf to align with bi. */ + expdiff += 16 * bf.blength; + _left_shift_base_two(&bf, (short unsigned) leftshift); + expdiff -= 16 * bf.blength; /* If bf.blength is + * longer, adjust + * expdiff. */ + } + expdiff += leftshift; + expdiff /= 16; /* Remaining expdiff in _BIG_FLOAT_DIGITS. */ + expdiff--; +#ifdef DEBUG + assert(expdiff >= 0); /* expdiff is now equal to the size + * of the hole between bi and bf. */ +#endif + nmove = uneeded - bi.blength; + /* nmove is the number of words to add to bi. */ + if (nmove < 0) + nmove = 0; + if (nmove > (expdiff + bf.blength)) + nmove = (expdiff + bf.blength); +#ifdef DEBUG + printf(" increase bi by %d words to merge \n", nmove); +#endif + if (nmove == 0) + i = -1; + else + for (i = (bi.blength - 1 + nmove); i >= nmove; i--) + bi.bsignificand[i] = bi.bsignificand[i - nmove]; + for (; (i >= 0) && (expdiff > 0); i--) { /* Fill hole with zeros. */ + expdiff--; + bi.bsignificand[i] = 0; + } + if0 = i; + for (; i >= 0; i--) + bi.bsignificand[i] = bf.bsignificand[i + bf.blength - 1 - if0]; + for (i = (bf.blength - 2 - if0); bf.bsignificand[i] == 0; i--); + /* Find first non-zero. */ + if (i >= 0) + bi.bsignificand[0] |= 1; /* If non-zero found, + * stick it. */ + bi.blength += nmove; + bi.bexponent -= 16 * nmove; + goto punpack; + } +punpack: + ptounpacked->bsignificand[0] |= pd->more; /* Stick in any lost + * digits. */ + +#ifdef DEBUG + printf(" merged bi and bf: "); + _display_big_float(ptounpacked, 2); +#endif + + _big_binary_to_unpacked(ptounpacked, px); + +ret: + return; +} + +/* PUBLIC FUNCTIONS */ + +/* + * decimal_to_floating routines convert the decimal record at *pd to the + * floating type item at *px, observing the modes specified in *pm and + * setting exceptions in *ps. + * + * pd->sign and pd->fpclass are always taken into account. + * + * pd->exponent, pd->ds and pd->ndigits are used when pd->fpclass is + * fp_normal or fp_subnormal. In these cases pd->ds is expected to + * contain one or more ascii digits followed by a null and pd->ndigits + * is assumed to be the length of the string pd->ds. Notice that for + * efficiency reasons, the assumption that pd->ndigits == strlen(pd->ds) + * is NEVER verified. + * + * px is set to a correctly rounded approximation to + * (sign)*(ds)*10**(exponent) If pd->more != 0 then additional nonzero digits + * are assumed to follow those in ds; fp_inexact is set accordingly. + * + * Thus if pd->exponent == -2 and pd->ds = "1234", *px will get 12.34 rounded to + * storage precision. + * + * px is correctly rounded according to the IEEE rounding modes in pm->rd. *ps + * is set to contain fp_inexact, fp_underflow, or fp_overflow if any of these + * arise. + * + * pm->df and pm->ndigits are never used. + * + */ + +void +decimal_to_single(px, pm, pd, ps) + single *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + single_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize to no floating-point + * exceptions. */ + kluge.f.msw.sign = pd->sign ? 1 : 0; + switch (pd->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + break; + case fp_infinity: + kluge.f.msw.exponent = 0xff; + kluge.f.msw.significand = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0xff; + kluge.f.msw.significand = 0x7fffff; + break; + case fp_signaling: + kluge.f.msw.exponent = 0xff; + kluge.f.msw.significand = 0x3fffff; + break; + default: + if (pd->exponent > SINGLE_MAXE) { /* Guaranteed overflow. */ + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = 0x000fffff; + u.significand[0] = 0x80000000; + } else if (pd->exponent >= -SINGLE_MAXE) { /* Guaranteed in range. */ + goto inrange; + } else if (pd->exponent <= (-SINGLE_MAXE - DECIMAL_STRING_LENGTH)) { /* Guaranteed deep + * underflow. */ + goto underflow; + } else { /* Deep underflow possible, depending on + * string length. */ + int i; + + for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - SINGLE_MAXE)); i++); + if (i < (-pd->exponent - SINGLE_MAXE)) { /* Deep underflow */ + underflow: + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = -0x000fffff; + u.significand[0] = 0x80000000; + } else {/* In range. */ + inrange: + decimal_to_unpacked(&u, pd, 24); + } + } + _fp_current_exceptions = 0; + _fp_current_direction = pm->rd; + _pack_single(&u, &kluge.x); + *ps = _fp_current_exceptions; + } + *px = kluge.x; +} + +void +decimal_to_double(px, pm, pd, ps) + double *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + double_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize to no floating-point + * exceptions. */ + kluge.f.msw.sign = pd->sign ? 1 : 0; + switch (pd->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_infinity: + kluge.f.msw.exponent = 0x7ff; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7ff; + kluge.f.msw.significand = 0xfffff; + kluge.f.significand2 = 0xffffffff; + break; + case fp_signaling: + kluge.f.msw.exponent = 0x7ff; + kluge.f.msw.significand = 0x7ffff; + kluge.f.significand2 = 0xffffffff; + break; + default: + if (pd->exponent > DOUBLE_MAXE) { /* Guaranteed overflow. */ + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = 0x000fffff; + u.significand[0] = 0x80000000; + } else if (pd->exponent >= -DOUBLE_MAXE) { /* Guaranteed in range. */ + goto inrange; + } else if (pd->exponent <= (-DOUBLE_MAXE - DECIMAL_STRING_LENGTH)) { /* Guaranteed deep + * underflow. */ + goto underflow; + } else { /* Deep underflow possible, depending on + * string length. */ + int i; + + for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - DOUBLE_MAXE)); i++); + if (i < (-pd->exponent - DOUBLE_MAXE)) { /* Deep underflow */ + underflow: + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = -0x000fffff; + u.significand[0] = 0x80000000; + } else {/* In range. */ + inrange: + decimal_to_unpacked(&u, pd, 53); + } + } + _fp_current_exceptions = 0; + _fp_current_direction = pm->rd; + _pack_double(&u, &kluge.x); + *ps = _fp_current_exceptions; + } + *px = kluge.x; +} + +void +decimal_to_extended(px, pm, pd, ps) + extended *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + extended_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize to no floating-point + * exceptions. */ + kluge.f.msw.sign = pd->sign ? 1 : 0; + switch (pd->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_infinity: + kluge.f.msw.exponent = 0x7fff; + kluge.f.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7fff; + kluge.f.significand = 0xffffffff; + kluge.f.significand2 = 0xffffffff; + break; + case fp_signaling: + kluge.f.msw.exponent = 0x7fff; + kluge.f.significand = 0x3fffffff; + kluge.f.significand2 = 0xffffffff; + break; + default: + if (pd->exponent > EXTENDED_MAXE) { /* Guaranteed overflow. */ + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = 0x000fffff; + u.significand[0] = 0x80000000; + } else if (pd->exponent >= -EXTENDED_MAXE) { /* Guaranteed in range. */ + goto inrange; + } else if (pd->exponent <= (-EXTENDED_MAXE - DECIMAL_STRING_LENGTH)) { /* Guaranteed deep + * underflow. */ + goto underflow; + } else { /* Deep underflow possible, depending on + * string length. */ + int i; + + for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - EXTENDED_MAXE)); i++); + if (i < (-pd->exponent - EXTENDED_MAXE)) { /* Deep underflow */ + underflow: + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = -0x000fffff; + u.significand[0] = 0x80000000; + } else {/* In range. */ + inrange: + decimal_to_unpacked(&u, pd, 64); + } + } + _fp_current_exceptions = 0; + _fp_current_direction = pm->rd; + _fp_current_precision = fp_extended; + _pack_extended(&u, px); + *ps = _fp_current_exceptions; + return; + } + (*px)[0] = kluge.x[0]; + (*px)[1] = kluge.x[1]; + (*px)[2] = kluge.x[2]; +} + +void +decimal_to_quadruple(px, pm, pd, ps) + quadruple *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + quadruple_equivalence kluge; + unpacked u; + int i; + + *ps = 0; /* Initialize to no floating-point + * exceptions. */ + kluge.f.msw.sign = pd->sign ? 1 : 0; + switch (pd->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + kluge.f.significand3 = 0; + kluge.f.significand4 = 0; + break; + case fp_infinity: + kluge.f.msw.exponent = 0x7fff; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + kluge.f.significand3 = 0; + kluge.f.significand4 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7fff; + kluge.f.msw.significand = 0xffff; + kluge.f.significand2 = 0xffffffff; + kluge.f.significand3 = 0xffffffff; + kluge.f.significand4 = 0xffffffff; + break; + case fp_signaling: + kluge.f.msw.exponent = 0x7fff; + kluge.f.msw.significand = 0x7fff; + kluge.f.significand2 = 0xffffffff; + kluge.f.significand3 = 0xffffffff; + kluge.f.significand4 = 0xffffffff; + break; + default: + if (pd->exponent > QUAD_MAXE) { /* Guaranteed overflow. */ + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = 0x000fffff; + u.significand[0] = 0x80000000; + } else if (pd->exponent >= -QUAD_MAXE) { /* Guaranteed in range. */ + goto inrange; + } else if (pd->exponent <= (-QUAD_MAXE - DECIMAL_STRING_LENGTH)) { /* Guaranteed deep + * underflow. */ + goto underflow; + } else { /* Deep underflow possible, depending on + * string length. */ + + for (i = 0; (pd->ds[i] != 0) && (i < (-pd->exponent - QUAD_MAXE)); i++); + if (i < (-pd->exponent - QUAD_MAXE)) { /* Deep underflow */ + underflow: + u.sign = pd->sign == 0 ? 0 : 1; + u.fpclass = fp_normal; + u.exponent = -0x000fffff; + u.significand[0] = 0x80000000; + } else {/* In range. */ + inrange: + decimal_to_unpacked(&u, pd, 113); + } + } + _fp_current_exceptions = 0; + _fp_current_direction = pm->rd; + _pack_quadruple(&u, px); + *ps = _fp_current_exceptions; + return; + } +#ifdef __STDC__ + *px = kluge.x; +#else + for (i = 0; i < 4; i++) + px->u[i] = kluge.x.u[i]; +#endif +} diff --git a/usr/src/lib/libbc/libc/gen/common/double_decim.c b/usr/src/lib/libbc/libc/gen/common/double_decim.c new file mode 100644 index 0000000000..4a48da9cce --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/double_decim.c @@ -0,0 +1,709 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* Conversion between binary and decimal floating point. */ + +#include "base_conversion.h" + +/* PRIVATE FUNCTIONS */ + +void +decimal_round(pm, pd, ps, round, sticky) + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; + char round; + unsigned sticky; + +/* + * Rounds decimal record *pd according to modes in *pm, recording exceptions + * for inexact or overflow in *ps. round is the round digit and sticky is 0 + * or non-zero to indicate exact or inexact. pd->ndigits is expected to be + * correctly set. + */ + +{ + int lsd, i; + + if ((round == '0') && (sticky == 0)) { /* Exact. */ + goto done; + } + *ps |= 1 << fp_inexact; + + switch (pm->rd) { + case fp_nearest: + if (round < '5') + goto done; + if (round > '5') + goto roundup; + if (sticky != 0) + goto roundup; + /* Now in ambiguous case; round up if lsd is odd. */ + if (pd->ndigits <= 0) + goto done; /* Presumed 0. */ + lsd = pd->ds[pd->ndigits - 1] - '0'; + if ((lsd % 2) == 0) + goto done; + goto roundup; + case fp_positive: + if (pd->sign != 0) + goto done; + goto roundup; + case fp_negative: + if (pd->sign == 0) + goto done; + goto roundup; + case fp_tozero: + goto done; + } +roundup: + for (i = (pd->ndigits - 1); (pd->ds[i] == '9') && (i >= 0); i--) + pd->ds[i] = '0'; + if (i >= 0) + (pd->ds[i])++; + else { /* Rounding carry out has occurred. */ + pd->ds[0] = '1'; + if (pm->df == floating_form) { /* For E format, simply + * adjust exponent. */ + pd->exponent++; + } else { /* For F format, increase length of string. */ + if (pd->ndigits > 0) + pd->ds[pd->ndigits] = '0'; + pd->ndigits++; + } + } + goto ret; +done: + if (pd->ndigits <= 0) { /* Create zero string. */ + pd->ds[0] = '0'; + pd->ndigits = 1; + } +ret: + pd->ds[pd->ndigits] = 0;/* Terminate string. */ + return; +} + +void +binary_to_decimal_integer(pu, nsig, ds, nzeros, ndigs) + unpacked *pu; /* Input unpacked integer value input. */ + unsigned nsig; /* Input number of significant digits + * required. */ + char ds[]; /* Output decimal integer string output - + * must be large enough. */ +unsigned *nzeros; /* Output number of implicit trailing zeros + * produced. */ +unsigned *ndigs; /* Output number of explicit digits produced + * in ds. */ + +/* + * Converts an unpacked integer value *pu into a decimal string in *ds, of + * length returned in *ndigs. /* Inexactness is indicated by setting + * ds[ndigs-1] odd. + */ + +{ + + _big_float *pd, b, d; + int e, i, is; + _BIG_FLOAT_DIGIT stickyshift; + char s[4]; + + b.bsize = _BIG_FLOAT_SIZE; /* Initialize sizes of big floats. */ + d.bsize = _BIG_FLOAT_SIZE; + _unpacked_to_big_float(pu, &b, &e); + if (e < 0) { + _right_shift_base_two(&b, (short unsigned) -e, &stickyshift); +#ifdef DEBUG + assert(stickyshift == 0); +#endif + } + _big_binary_to_big_decimal(&b, &d); + if (e <= 0) + pd = &d; + else { + _big_float_times_power(&d, 2, e, (int) nsig, &pd); + switch ((unsigned int)pd) { + case ((unsigned int)BIG_FLOAT_TIMES_TOOBIG): + { + char bcastring[80]; + + (void) sprintf(bcastring, " binary exponent %d ", e); + _base_conversion_abort(ERANGE, bcastring); + break; + } + case ((unsigned int)BIG_FLOAT_TIMES_NOMEM): + { + char bcastring[80]; + + (void) sprintf(bcastring, " binary exponent %d ", e); + _base_conversion_abort(ENOMEM, bcastring); + break; + } + default: +#ifdef DEBUG + if (pd != &d) + (void) printf(" large binary exponent %d needs heap buffer \n", e); + printf(" product "); + _display_big_float(pd, 10); +#endif + break; + } + } + _fourdigitsquick((short unsigned) pd->bsignificand[pd->blength - 1], s); + for (i = 0; s[i] == '0'; i++); /* Find first non-zero digit. */ + for (is = 0; i <= 3;) + ds[is++] = s[i++]; /* Copy subsequent digits. */ + + for (i = (pd->blength - 2); i >= 0; i--) { /* Convert powers of + * 10**4 to decimal + * digits. */ + _fourdigitsquick((short unsigned) pd->bsignificand[i], &(ds[is])); + is += 4; + } + + ds[is] = 0; + *ndigs = is; + *nzeros = pd->bexponent; + if (pd != &d) + _free_big_float(pd); + +#ifdef DEBUG + printf(" binary to decimal integer result %s * 10**%d \n", ds, *nzeros); +#endif +} + +void +binary_to_decimal_fraction(pu, nsig, nfrac, ds, nzeros, ndigs) + unpacked *pu; /* Input unpacked fraction value output < 1 + * in magnitude. */ + unsigned nsig; /* Input number of significant digits + * required. */ + unsigned nfrac; /* Input number of digits after point + * required. */ + char ds[]; /* Output decimal integer string output - + * must be large enough. */ +int *nzeros; /* Output number of implicit leading zeros + * produced. */ +int *ndigs; /* Output number of explicit digits produced + * in ds. */ + +/* + * Converts an unpacked fraction value *pu into a decimal string consisting + * of a) an implicit '.' b) *nzeros implicit leading zeros c) *ndigs explicit + * digits in ds ds contains at least nsig significant digits. nzeros + * + * *ndigs is at least nfrac digits after the point. Inexactness is indicated + * by sticking to the lsb. + */ + +{ + _big_float *pb, b, d; + int e, i, j, is, excess; + char s[4]; + int tensig, tenpower; + _BIG_FLOAT_DIGIT stickyshift; + + *nzeros = 0; + if (pu->fpclass == fp_zero) { /* Exact zero. */ + for (i = 0; i <= nfrac; i++) + ds[i] = '0'; + for (; i <= nsig; i++) + ds[i] = '0'; + *ndigs = i; + return; + } + b.bsize = _BIG_FLOAT_SIZE; /* Initialize sizes of big floats. */ + d.bsize = _BIG_FLOAT_SIZE; + _unpacked_to_big_float(pu, &b, &e); + /* + * e < 0 always + */ + b.bexponent = e; + tenpower = nsig + (int) (((17 - e - 16 * b.blength) * (unsigned long) 19729) >> 16); + if (tenpower < nfrac) + tenpower = nfrac; + tensig = nfrac; + if (nsig > tensig) + tensig = nsig; + tensig = 1 + (((tensig + 2) * 217706) >> 16); + tensig = -tensig; + +#ifdef DEBUG + printf(" binary to decimal fraction exponent 2**%d \n", e); + printf(" binary to decimal fraction nsig %d nfrac %d tenpower %d tensig %d \n", nsig, nfrac, tenpower, tensig); +#endif + _big_float_times_power(&b, 10, tenpower, tensig, &pb); + switch ((unsigned int)pb) { + case ((unsigned int)BIG_FLOAT_TIMES_TOOBIG): + { + char bcastring[80]; + + (void) sprintf(bcastring, " decimal exponent %d ", tenpower); + _base_conversion_abort(ERANGE, bcastring); + break; + } + case ((unsigned int)BIG_FLOAT_TIMES_NOMEM): + { + char bcastring[80]; + + (void) sprintf(bcastring, " decimal exponent %d ", tenpower); + _base_conversion_abort(ENOMEM, bcastring); + break; + } + default: +#ifdef DEBUG + if (pb != &b) + printf(" large decimal exponent %d needs heap buffer \n", tenpower); + printf(" product "); + _display_big_float(pb, 2); +#endif + break; + } + + if (pb->bexponent <= -16) { + /* Have computed appropriate decimal part; now toss fraction. */ + excess = (-pb->bexponent) / 16; +#ifdef DEBUG + printf(" discard %d excess fraction bits \n", 16 * excess); +#endif + for (i = 0; (i < excess) && (pb->bsignificand[i] == 0); i++); + if (i < excess) + pb->bsignificand[excess] |= 1; /* Sticky bit for + * discarded fraction. */ + for (i = excess; i < pb->blength; i++) + pb->bsignificand[i - excess] = pb->bsignificand[i]; + + pb->blength -= excess; + pb->bexponent += 16 * excess; + } + if (pb->bexponent < 0) { + _right_shift_base_two(pb, (short unsigned) -pb->bexponent, &stickyshift); + if (stickyshift != 0) + pb->bsignificand[0] |= 1; /* Stick to lsb. */ + } + _big_binary_to_big_decimal(pb, &d); + + i = d.blength - 1; + while (d.bsignificand[i] == 0) + i--; + _fourdigitsquick((short unsigned) d.bsignificand[i], s); + for (j = 0; s[j] == '0'; j++); /* Find first non-zero digit. */ + for (is = 0; j <= 3;) + ds[is++] = s[j++]; /* Copy subsequent digits. */ + + for (i--; i >= 0; i--) {/* Convert powers of 10**4 to decimal digits. */ + _fourdigitsquick((short unsigned) d.bsignificand[i], &(ds[is])); + is += 4; + } + + ds[is] = 0; + *ndigs = is; +#ifdef DEBUG + assert(tenpower >= is); +#endif + *nzeros = tenpower - is;/* There were supposed to be tenpower leading + * digits, and is were found. */ + + if (pb != &b) + _free_big_float(pb); + +#ifdef DEBUG + printf(" binary to decimal fraction result .%s * 10**%d \n", ds, -(*nzeros)); +#endif + +} + +void +_unpacked_to_decimal(px, pm, pd, ps) + unpacked *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + unpacked fx, ix; + unsigned fmask, imask; + int i, intdigs, fracdigs, fraczeros, fracsigs, ids, idsbound, lzbound; + unsigned nsig, nfrac, intzeros, intsigs; + char is[_INTEGER_SIZE], fs[DECIMAL_STRING_LENGTH]; + char round = '0'; + unsigned sticky = 0; + + pd->sign = px->sign; + pd->fpclass = px->fpclass; + if ((px->fpclass != fp_normal) && (px->fpclass != fp_subnormal)) + return; + if ((pm->ndigits >= DECIMAL_STRING_LENGTH) || + ((pm->df == floating_form) && (pm->ndigits < 1))) { /* Gross overflow or bad + * spec. */ +overflow: + *ps |= 1 << fp_overflow; + return; + } + /* Divide x up into integer part ix and fraction part fx. */ + + ix = *px; + fx = ix; + if (ix.exponent <= -1) {/* All fraction. */ + ix.fpclass = fp_zero; + } else if (ix.exponent >= 159) { /* All integer. */ + fx.fpclass = fp_zero; + } else if ((ix.exponent % 32) == 31) { /* Integer/fraction boundary + * is conveniently on a word + * boundary. */ + imask = (ix.exponent + 1) / 32; /* Words 0..imask-1 are + * integer; imask..SIZE are + * fraction. */ + for (i = 0; i < imask; i++) + fx.significand[i] = 0; + for (; i < UNPACKED_SIZE; i++) + ix.significand[i] = 0; + _fp_normalize(&fx); + } else { /* Integer/fraction boundary falls in the + * middle of a word. */ + imask = (ix.exponent + 1) / 32; /* Words 0..imask-1 are + * integer; imask is integer + * and fraction ; + * imask+1..SIZE are + * fraction. */ + for (i = 0; i < imask; i++) + fx.significand[i] = 0; + fmask = (1 << (31 - (ix.exponent % 32))) - 1; + fx.significand[imask] &= fmask; + ix.significand[imask] &= ~fmask; + for (i = (imask + 1); i < UNPACKED_SIZE; i++) + ix.significand[i] = 0; + _fp_normalize(&fx); + } + if (ix.fpclass != fp_zero) { /* Compute integer part of result. */ + if (pm->df == floating_form) + nsig = pm->ndigits + 1; /* Significant digits wanted + * for E format, plus one for + * rounding. */ + else + nsig = _INTEGER_SIZE; /* Significant digits wanted + * for F format == all. */ + + binary_to_decimal_integer(&ix, nsig, is, &intzeros, &intsigs); + } else { + intsigs = 0; + intzeros = 0; + } + intdigs = intsigs + intzeros; + fracdigs = 0; + if (((pm->df == fixed_form) && (pm->ndigits >= 0)) || + ((pm->df == floating_form) && ((pm->ndigits + 1) > intdigs))) { /* Need to compute + * fraction part. */ + if (pm->df == floating_form) { /* Need more significant + * digits. */ + nsig = pm->ndigits + 2 - intdigs; /* Add two for rounding, + * sticky. */ + if (nsig > DECIMAL_STRING_LENGTH) + nsig = DECIMAL_STRING_LENGTH; + nfrac = 1; + } else { /* Need fraction digits. */ + nsig = 0; + nfrac = pm->ndigits + 2; /* Add two for rounding, + * sticky. */ + if (nfrac > DECIMAL_STRING_LENGTH) + nfrac = DECIMAL_STRING_LENGTH; + } + binary_to_decimal_fraction(&fx, nsig, nfrac, fs, &fraczeros, &fracsigs); + fracdigs = fraczeros + fracsigs; + } + if (pm->df == floating_form) { /* Combine integer and fraction for E + * format. */ + idsbound = intsigs; + if (idsbound > pm->ndigits) + idsbound = pm->ndigits; + for (ids = 0; ids < idsbound; ids++) + pd->ds[ids] = is[ids]; + /* Put integer into output string. */ + idsbound = intsigs + intzeros; + if (idsbound > pm->ndigits) + idsbound = pm->ndigits; + for (; ids < idsbound; ids++) + pd->ds[ids] = '0'; + if (ids == pm->ndigits) { /* Integer part had enough + * significant digits. */ + pd->ndigits = ids; + pd->exponent = intdigs - ids; + if (ids < intdigs) { /* Gather rounding info. */ + if (ids < intsigs) + round = is[ids++]; + else + round = '0'; + for (; (is[ids] == '0') && (ids < intsigs); ids++); + if (ids < intsigs) + sticky = 1; + if (fx.fpclass != fp_zero) + sticky = 1; + } else {/* Integer part is exact - round from + * fraction. */ + if (fx.fpclass != fp_zero) { + int stickystart; + /* Fraction non-zero. */ + if (fraczeros > 0) { /* Round digit is zero. */ + round = '0'; + stickystart = 0; /* Stickies start with + * fs[0]. */ + } else { /* Round digit is fs[0]. */ + round = fs[0]; + stickystart = 1; /* Stickies start with + * fs[1]. */ + } + if (sticky == 0) { /* Search for sticky + * bits. */ + for (ids = stickystart; (fs[ids] == '0') && (ids < fracdigs); ids++); + if (ids < fracdigs) + sticky = 1; + } + } + } + } else { /* Need more significant digits from fraction + * part. */ + idsbound = pm->ndigits - ids; + if (ids == 0) { /* No integer part - find first + * significant digit. */ + for (i = 0; fs[i] == '0'; i++); + idsbound = i + idsbound + fraczeros; + i += fraczeros; /* Point i at first + * significant digit. */ + } else + i = 0; + if (idsbound > fracdigs) + idsbound = fracdigs; + pd->exponent = -idsbound; + + if (fraczeros < idsbound) /* Compute number of + * leading zeros + * required. */ + lzbound = fraczeros; + else + lzbound = idsbound; + for (; (i < lzbound); i++) + pd->ds[ids++] = '0'; + for (; (i < idsbound); i++) + pd->ds[ids++] = fs[i - fraczeros]; + i -= fraczeros; /* Don't worry about leading zeros + * from now on, we're just rounding */ + if (i < fracsigs) { /* Gather rounding info. */ + if (i < 0) + round = '0'; + else + round = fs[i]; + i++; + if (sticky == 0) { /* Find out if remainder + * is exact. */ + if (i < 0) + i = 0; + for (; (fs[i] == '0') && (i < fracsigs); i++); + if (i < fracsigs) + sticky = 1; + } + } else {/* Fraction part is exact - add zero digits + * if required. */ + for (; ids < pm->ndigits; ids++) + pd->ds[ids] = '0'; + } + pd->ndigits = ids; + } + decimal_round(pm, pd, ps, round, sticky); + } else { /* Combine integer and fraction for F format. */ + if (pm->ndigits >= 0) { /* Normal F format. */ + if ((intdigs + pm->ndigits) >= DECIMAL_STRING_LENGTH) + goto overflow; + for (ids = 0; ids < intsigs; ids++) + pd->ds[ids] = is[ids]; + for (; ids < intdigs; ids++) + pd->ds[ids] = '0'; + /* Copy integer digits. */ + idsbound = fracdigs; + if (idsbound > pm->ndigits) + idsbound = pm->ndigits; + if (fraczeros < idsbound) /* Compute number of + * leading zeros + * required. */ + lzbound = fraczeros; + else + lzbound = idsbound; + for (i = 0; (i < lzbound); i++) + pd->ds[ids++] = '0'; + for (; (i < idsbound); i++) + pd->ds[ids++] = fs[i - fraczeros]; /* Copy fraction digits. */ + for (; i < pm->ndigits; i++) + pd->ds[ids++] = '0'; + /* Copy trailing zeros if necessary. */ + pd->ndigits = ids; + pd->exponent = intdigs - ids; + i -= fraczeros; /* Don't worry about leading zeros + * from now on, we're just rounding */ + if (i < fracsigs) { /* Gather rounding info. */ + if (i < 0) + round = '0'; + else + round = fs[i]; + i++; + if (sticky == 0) { /* Find out if remainder + * is exact. */ + if (i < 0) + i = 0; + for (; (fs[i] == '0') && (i < fracsigs); i++); + if (i < fracsigs) + sticky = 1; + } + } + decimal_round(pm, pd, ps, round, sticky); + } else { /* Bizarre F format - round to left of point. */ + int roundpos = -pm->ndigits; + + if (intdigs >= DECIMAL_STRING_LENGTH) + goto overflow; + if (roundpos >= DECIMAL_STRING_LENGTH) + goto overflow; + if (intdigs <= roundpos) { /* Not enough integer + * digits. */ + if (intdigs == roundpos) { + round = is[0]; + i = 1; + } else { + round = '0'; + i = 0; + } + for (; (is[i] == '0') && (i < intsigs); i++); + /* Search for sticky bits. */ + if (i < intsigs) + sticky = 1; + pd->ndigits = 0; + } else {/* Some integer digits do not get rounded + * away. */ +#ifdef _NO_GOOD + for (ids = 0; ids < (intsigs - roundpos); ids++) + pd->ds[ids] = is[ids]; + for (ids = 0; ids < (intdigs - roundpos); ids++) + pd->ds[ids] = '0'; +#else + { + int ncopy = intsigs - roundpos; + if (ncopy > 0) { + /* Copy integer digits. */ + (void) memcpy(&(pd->ds[0]), &(is[0]), ncopy); + ids = ncopy; + } + } + { + int ncopy = intdigs - roundpos - ids ; + if (ncopy > 0) { + (void) memset(&(pd->ds[ids]), '0', ncopy); + ids += ncopy; + } + } +#endif /* _NO_GOOD */ + /* Copy integer digits. */ + pd->ndigits = ids; + if (ids < intsigs) { /* Inexact. */ + round = is[ids++]; + for (; (is[ids] == '0') && (ids < intsigs); ids++); + /* Search for non-zero digits. */ + if (ids < intsigs) + sticky = 1; + } + } + if (fx.fpclass != fp_zero) + sticky = 1; + decimal_round(pm, pd, ps, round, sticky); + for (i = pd->ndigits; i < (pd->ndigits + roundpos); i++) + pd->ds[i] = '0'; /* Blank out rounded + * away digits. */ + pd->exponent = 0; + pd->ndigits = i; + pd->ds[i] = 0; /* Terminate string. */ + } + } +} + +void +double_to_decimal(px, pm, pd, ps) + double *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + double_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize *ps. */ + kluge.x = *px; + pd->sign = kluge.f.msw.sign; + pd->fpclass = _class_double(px); + switch (pd->fpclass) { + case fp_zero: + break; + case fp_infinity: + break; + case fp_quiet: + break; + case fp_signaling: + break; + default: + _unpack_double(&u, &kluge.x); + _unpacked_to_decimal(&u, pm, pd, ps); + } +} + +void +quadruple_to_decimal(px, pm, pd, ps) + quadruple *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + quadruple_equivalence kluge; + unpacked u; + int i; + + *ps = 0; /* Initialize *ps - no exceptions. */ + for (i = 0; i < 4; i++) +#ifdef __STDC__ + kluge.x = *px; +#else + kluge.x.u[i] = px->u[i]; +#endif + pd->sign = kluge.f.msw.sign; + pd->fpclass = _class_quadruple(px); + switch (pd->fpclass) { + case fp_zero: + break; + case fp_infinity: + break; + case fp_quiet: + break; + case fp_signaling: + break; + default: + _unpack_quadruple(&u, px); + _unpacked_to_decimal(&u, pm, pd, ps); + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/drand48.c b/usr/src/lib/libbc/libc/gen/common/drand48.c new file mode 100644 index 0000000000..13d0895991 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/drand48.c @@ -0,0 +1,177 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1996 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +/* + * drand48, etc. pseudo-random number generator + * This implementation assumes unsigned short integers of at least + * 16 bits, long integers of at least 32 bits, and ignores + * overflows on adding or multiplying two unsigned integers. + * Two's-complement representation is assumed in a few places. + * Some extra masking is done if unsigneds are exactly 16 bits + * or longs are exactly 32 bits, but so what? + * An assembly-language implementation would run significantly faster. + */ +#define N 16 +#define MASK ((unsigned)(1 << (N - 1)) + (1 << (N - 1)) - 1) +#define LOW(x) ((unsigned)(x) & MASK) +#define HIGH(x) LOW((x) >> N) +#define MUL(x, y, z) { long l = (long)(x) * (long)(y); \ + (z)[0] = LOW(l); (z)[1] = HIGH(l); } +#define CARRY(x, y) ((long)(x) + (long)(y) > MASK) +#define ADDEQU(x, y, z) (z = CARRY(x, (y)), x = LOW(x + (y))) +#define X0 0x330E +#define X1 0xABCD +#define X2 0x1234 +#define A0 0xE66D +#define A1 0xDEEC +#define A2 0x5 +#define C 0xB +#define SET3(x, x0, x1, x2) ((x)[0] = (x0), (x)[1] = (x1), (x)[2] = (x2)) +#define SETLOW(x, y, n) SET3(x, LOW((y)[n]), LOW((y)[(n)+1]), LOW((y)[(n)+2])) +#define SEED(x0, x1, x2) (SET3(x, x0, x1, x2), SET3(a, A0, A1, A2), c = C) +#define REST(v) \ + for (i = 0; i < 3; i++) { \ + xsubi[i] = x[i]; \ + x[i] = temp[i]; \ + } \ + return (v) + +#define NEST(TYPE, f, F) \ + TYPE f(xsubi) \ + register unsigned short *xsubi; \ + { \ + register int i; \ + register TYPE v; \ + unsigned temp[3]; \ + \ + for (i = 0; i < 3; i++) { \ + temp[i] = x[i]; \ + x[i] = LOW(xsubi[i]); \ + } \ + v = F(); \ + REST(v); \ + } + +static unsigned x[3] = { X0, X1, X2 }, a[3] = { A0, A1, A2 }, c = C; +static unsigned short lastx[3]; +static void next(); + +double +drand48() +{ + static double two16m = 1.0 / (1L << N); + + next(); + return (two16m * (two16m * (two16m * x[0] + x[1]) + x[2])); +} + +NEST(double, erand48, drand48) + +long +lrand48() +{ + next(); + return (((long)x[2] << (N - 1)) + (x[1] >> 1)); +} + +long +mrand48() +{ + next(); + return (((long)x[2] << N) + x[1]); +} + +static void +next() +{ + unsigned p[2], q[2], r[2], carry0, carry1; + + MUL(a[0], x[0], p); + ADDEQU(p[0], c, carry0); + ADDEQU(p[1], carry0, carry1); + MUL(a[0], x[1], q); + ADDEQU(p[1], q[0], carry0); + MUL(a[1], x[0], r); + x[2] = LOW(carry0 + carry1 + CARRY(p[1], r[0]) + q[1] + r[1] + + a[0] * x[2] + a[1] * x[1] + a[2] * x[0]); + x[1] = LOW(p[1] + r[0]); + x[0] = LOW(p[0]); +} + +void +srand48(seedval) +long seedval; +{ + SEED(X0, LOW(seedval), HIGH(seedval)); +} + +unsigned short * +seed48(seed16v) +unsigned short seed16v[3]; +{ + SETLOW(lastx, x, 0); + SEED(LOW(seed16v[0]), LOW(seed16v[1]), LOW(seed16v[2])); + return (lastx); +} + +void +lcong48(param) +unsigned short param[7]; +{ + SETLOW(x, param, 0); + SETLOW(a, param, 3); + c = LOW(param[6]); +} + +NEST(long, nrand48, lrand48) + +NEST(long, jrand48, mrand48) + +#ifdef DRIVER +/* + * This should print the sequences of integers in Tables 2 + * and 1 of the TM: + * 1623, 3442, 1447, 1829, 1305, ... + * 657EB7255101, D72A0C966378, 5A743C062A23, ... + */ +#include <stdio.h> + +main() +{ + int i; + + for (i = 0; i < 80; i++) { + printf("%4d ", (int)(4096 * drand48())); + printf("%.4X%.4X%.4X\n", x[2], x[1], x[0]); + } +} +#endif diff --git a/usr/src/lib/libbc/libc/gen/common/dysize.c b/usr/src/lib/libbc/libc/gen/common/dysize.c new file mode 100644 index 0000000000..0b7d74458f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/dysize.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from Arthur Olson's 3.1 */ + +/*LINTLIBRARY*/ + +#include <tzfile.h> + +dysize(y) +{ + /* + ** The 4.[0123]BSD version of dysize behaves as if the return statement + ** below read + ** return ((y % 4) == 0) ? DAYS_PER_LYEAR : DAYS_PER_NYEAR; + ** but since we'd rather be right than (strictly) compatible. . . + */ + return isleap(y) ? DAYS_PER_LYEAR : DAYS_PER_NYEAR; +} diff --git a/usr/src/lib/libbc/libc/gen/common/econvert.c b/usr/src/lib/libbc/libc/gen/common/econvert.c new file mode 100644 index 0000000000..a82ad20f61 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/econvert.c @@ -0,0 +1,143 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +static char *nanstring = "NaN"; +static char *infstring = "Infinity"; + +char * +econvert(arg, ndigits, decpt, sign, buf) + double arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + char *pc; + int nc; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = floating_form; /* E format. */ + dm.ndigits = ndigits; /* Number of significant digits. */ + double_to_decimal(&arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + *decpt = dr.exponent + ndigits; + for (i = 0; i < ndigits; i++) + buf[i] = dr.ds[i]; + buf[ndigits] = 0; + break; + case fp_zero: + *decpt = 1; + for (i = 0; i < ndigits; i++) + buf[i] = '0'; + buf[ndigits] = 0; + break; + case fp_infinity: + *decpt = 0; + pc = infstring; + if (ndigits < 8) + nc = 3; + else + nc = 8; + goto movestring; + case fp_quiet: + case fp_signaling: + *decpt = 0; + pc = nanstring; + nc = 3; +movestring: + for (i = 0; i < nc; i++) + buf[i] = pc[i]; + buf[nc] = 0; + break; + } + return buf; /* For compatibility with ecvt. */ +} + +char * +fconvert(arg, ndigits, decpt, sign, buf) + double arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + char *pc; + int nc; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = fixed_form; /* F format. */ + dm.ndigits = ndigits; /* Number of digits after point. */ + double_to_decimal(&arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + if (ndigits >= 0) + *decpt = dr.ndigits - ndigits; + else + *decpt = dr.ndigits; + for (i = 0; i < dr.ndigits; i++) + buf[i] = dr.ds[i]; + buf[dr.ndigits] = 0; + break; + case fp_zero: + *decpt = 0; + buf[0] = '0'; + for (i = 1; i < ndigits; i++) + buf[i] = '0'; + buf[i] = 0; + break; + case fp_infinity: + *decpt = 0; + pc = infstring; + if (ndigits < 8) + nc = 3; + else + nc = 8; + goto movestring; + case fp_quiet: + case fp_signaling: + *decpt = 0; + pc = nanstring; + nc = 3; +movestring: + for (i = 0; i < nc; i++) + buf[i] = pc[i]; + buf[nc] = 0; + break; + } + return buf; /* For compatibility with fcvt. */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/ecvt.c b/usr/src/lib/libbc/libc/gen/common/ecvt.c new file mode 100644 index 0000000000..6215866bb1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ecvt.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +#include <stdio.h> +extern char * +econvert(), *fconvert(); + +static char *efcvtbuffer; + +char * +ecvt(arg, ndigits, decpt, sign) + double arg; + int ndigits, *decpt, *sign; +{ + if (efcvtbuffer == NULL) + efcvtbuffer = (char *)calloc(1,1024); + return econvert(arg, ndigits, decpt, sign, efcvtbuffer); +} + +char * +fcvt(arg, ndigits, decpt, sign) + double arg; + int ndigits, *decpt, *sign; +{ + if (efcvtbuffer == NULL) + efcvtbuffer = (char *)calloc(1,1024); + return fconvert(arg, ndigits, decpt, sign, efcvtbuffer); +} diff --git a/usr/src/lib/libbc/libc/gen/common/errlst.c b/usr/src/lib/libbc/libc/gen/common/errlst.c new file mode 100644 index 0000000000..e660fc56c7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/errlst.c @@ -0,0 +1,114 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/05/30 */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +char *sys_errlist[] = { + "Error 0", + "Not owner", /* 1 - EPERM */ + "No such file or directory", /* 2 - ENOENT */ + "No such process", /* 3 - ESRCH */ + "Interrupted system call", /* 4 - EINTR */ + "I/O error", /* 5 - EIO */ + "No such device or address", /* 6 - ENXIO */ + "Arg list too long", /* 7 - E2BIG */ + "Exec format error", /* 8 - ENOEXEC */ + "Bad file number", /* 9 - EBADF */ + "No children", /* 10 - ECHILD */ + "No more processes", /* 11 - EAGAIN */ + "Not enough memory", /* 12 - ENOMEM */ + "Permission denied", /* 13 - EACCES */ + "Bad address", /* 14 - EFAULT */ + "Block device required", /* 15 - ENOTBLK */ + "Device busy", /* 16 - EBUSY */ + "File exists", /* 17 - EEXIST */ + "Cross-device link", /* 18 - EXDEV */ + "No such device", /* 19 - ENODEV */ + "Not a directory", /* 20 - ENOTDIR */ + "Is a directory", /* 21 - EISDIR */ + "Invalid argument", /* 22 - EINVAL */ + "File table overflow", /* 23 - ENFILE */ + "Too many open files", /* 24 - EMFILE */ + "Inappropriate ioctl for device", /* 25 - ENOTTY */ + "Text file busy", /* 26 - ETXTBSY */ + "File too large", /* 27 - EFBIG */ + "No space left on device", /* 28 - ENOSPC */ + "Illegal seek", /* 29 - ESPIPE */ + "Read-only file system", /* 30 - EROFS */ + "Too many links", /* 31 - EMLINK */ + "Broken pipe", /* 32 - EPIPE */ + +/* math software */ + "Argument too large", /* 33 - EDOM */ + "Result too large", /* 34 - ERANGE */ + +/* non-blocking and interrupt i/o */ + "Operation would block", /* 35 - EWOULDBLOCK */ + "Operation now in progress", /* 36 - EINPROGRESS */ + "Operation already in progress", /* 37 - EALREADY */ + +/* ipc/network software */ + + /* argument errors */ + "Socket operation on non-socket", /* 38 - ENOTSOCK */ + "Destination address required", /* 39 - EDESTADDRREQ */ + "Message too long", /* 40 - EMSGSIZE */ + "Protocol wrong type for socket", /* 41 - EPROTOTYPE */ + "Option not supported by protocol", /* 42 - ENOPROTOOPT */ + "Protocol not supported", /* 43 - EPROTONOSUPPORT */ + "Socket type not supported", /* 44 - ESOCKTNOSUPPORT */ + "Operation not supported on socket", /* 45 - EOPNOTSUPP */ + "Protocol family not supported", /* 46 - EPFNOSUPPORT */ + "Address family not supported by protocol family", + /* 47 - EAFNOSUPPORT */ + "Address already in use", /* 48 - EADDRINUSE */ + "Can't assign requested address", /* 49 - EADDRNOTAVAIL */ + + /* operational errors */ + "Network is down", /* 50 - ENETDOWN */ + "Network is unreachable", /* 51 - ENETUNREACH */ + "Network dropped connection on reset", /* 52 - ENETRESET */ + "Software caused connection abort", /* 53 - ECONNABORTED */ + "Connection reset by peer", /* 54 - ECONNRESET */ + "No buffer space available", /* 55 - ENOBUFS */ + "Socket is already connected", /* 56 - EISCONN */ + "Socket is not connected", /* 57 - ENOTCONN */ + "Can't send after socket shutdown", /* 58 - ESHUTDOWN */ + "Too many references: can't splice", /* 59 - ETOOMANYREFS */ + "Connection timed out", /* 60 - ETIMEDOUT */ + "Connection refused", /* 61 - EREFUSED */ + "Too many levels of symbolic links", /* 62 - ELOOP */ + "File name too long", /* 63 - ENAMETOOLONG */ + "Host is down", /* 64 - EHOSTDOWN */ + "Host is unreachable", /* 65 - EHOSTUNREACH */ + "Directory not empty", /* 66 - ENOTEMPTY */ + "Too many processes", /* 67 - EPROCLIM */ + "Too many users", /* 68 - EUSERS */ + "Disc quota exceeded", /* 69 - EDQUOT */ + "Stale NFS file handle", /* 70 - ESTALE */ + "Too many levels of remote in path", /* 71 - EREMOTE */ + "Not a stream device", /* 72 - ENOSTR */ + "Timer expired", /* 73 - ETIME */ + "Out of stream resources", /* 74 - ENOSR */ + "No message of desired type", /* 75 - ENOMSG */ + "Not a data message", /* 76 - EBADMSG */ + "Identifier removed", /* 77 - EIDRM */ + "Deadlock situation detected/avoided", /* 78 - EDEADLK */ + "No record locks available", /* 79 - ENOLCK */ + "Machine is not on the network", /* 80 - ENONET */ + "Object is remote", /* 81 - ERREMOTE */ + "Link has been severed", /* 82 - ENOLINK */ + "Advertise error ", /* 83 - EADV */ + "Srmount error ", /* 84 - ESRMNT */ + "Communication error on send", /* 85 - ECOMM */ + "Protocol error", /* 86 - EPROTO */ + "Multihop attempted", /* 87 - EMULTIHOP */ + "EDOTDOT!!!!", /* 88 - EDOTDOT -can't happen */ + "Remote address changed", /* 89 - EREMCHG */ + "Function not implemented", /* 90 - ENOSYS */ +}; +int sys_nerr = { sizeof sys_errlist/sizeof sys_errlist[0] }; diff --git a/usr/src/lib/libbc/libc/gen/common/euc.h b/usr/src/lib/libbc/libc/gen/common/euc.h new file mode 100644 index 0000000000..201fb17fbf --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/euc.h @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +/* This module is created for NLS on Jan.07.87 */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* static char *sccsid = "%Z%%M% %I% %E% SMI"; */ + +#define SS2 0x008e +#define SS3 0x008f + +typedef struct { + short int _eucw1, _eucw2, _eucw3; /* EUC width */ +} eucwidth_t; + +#define csetno(c) (((c)&0x80)?((c)==SS2)?2:(((c)==SS3)?3:1):0) + /* Returns code set number for the first byte of an EUC char. */ diff --git a/usr/src/lib/libbc/libc/gen/common/euc.multibyte.c b/usr/src/lib/libbc/libc/gen/common/euc.multibyte.c new file mode 100644 index 0000000000..a97bc90e15 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/euc.multibyte.c @@ -0,0 +1,206 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" +#include "euc.h" +#include <limits.h> + +#define EUCMASK 0x8080 /* All id bits */ +#define MASK0 0x0000 /* Code Set 0 */ +#define MASK1 0x8080 /* Code Set 1 */ +#define MASK2 0x0080 /* Code Set 2 */ +#define MASK3 0x8000 /* Code Set 3 */ + +#define EUCWID1 eucinfo->_eucw1 +#define EUCWID2 eucinfo->_eucw2 +#define EUCWID3 eucinfo->_eucw3 + +int _mbtowc_euc(wchar, s, n) +wchar_t *wchar; +char *s; +size_t n; +{ + register int length; + register wchar_t intcode; + register c; + char *olds = (char *)s; + wchar_t mask; + eucwidth_t * eucinfo = (eucwidth_t *)_code_set_info.code_info; + + if(n <= 0) + return(-1); + if(s == (char *)0) + return 0; + c = (unsigned char)*s++; + if(c < 0200) { + if(wchar) + *wchar = c; + return(c ? 1 : 0); + } + intcode = 0; + if (c == SS2) { + if(!(length = EUCWID2)) { + if(wchar) + *wchar = c; + return(1); + } + mask = MASK2; + } else if(c == SS3) { + if(!(length = EUCWID3)) { + if(wchar) + *wchar = c; + return(1); + } + mask = MASK3; + } else { + if(iscntrl(c)) { + if(wchar) + *wchar = c; + return(1); + } + length = EUCWID1 - 1; + mask = MASK1; + intcode = c & 0177; + } + if(length + 1 > n) + return(-1); + while(length--) { + if((c = (unsigned char)*s++) < 0200 || iscntrl(c)) + return(-1); + intcode = (intcode << 8) | (c & 0177); + } + if(wchar) + *wchar = intcode | mask; + return((char *)s - olds); +} + + +size_t +_mbstowcs_euc(pwcs, s, n) + wchar_t *pwcs; + char *s; + size_t n; +{ + register int i, j; + + j=0; + while(*s) { + if(j>=n) + break; + i=_mbtowc_euc(pwcs+j, s, MB_LEN_MAX); + if(i==-1) + return -1; + s+=i; + ++j; + } + if(j<n) + pwcs[j]=0; + return j; +} + + +size_t +_wcstombs_euc(s, pwcs, n) + char *s; + wchar_t *pwcs; + size_t n; +{ + register wchar_t wc; + register int i; + register int r=n; /* Rest of bytes. */ + register char *t; + char mbbuf[MB_LEN_MAX+1]; + + while(wc=(*pwcs++)) { + i=_wctomb_euc(mbbuf, wc); + + if (i>r) + break; + if (i==-1) return -1; + + r-=i; + for (t=mbbuf;i>0;--i){ + /* Copy each byte. */ + *(s++)=*(t++); + } + } + if (r>0) + /* Has enough room for NUL. */ + *s=0; + return n-r; +} + +int _wctomb_euc(s, wchar) +char *s; +wchar_t wchar; +{ + eucwidth_t * eucinfo = (eucwidth_t *)_code_set_info.code_info; + char *olds = s; + register int size, index; + unsigned char d; + if(!s) + return(0); + if( wchar <= 0177 || wchar <= 0377 && iscntrl(wchar)) { + *s++ = wchar; + return(wchar ? 1 : 0); + } + switch(wchar & EUCMASK) { + + case MASK1: + size = EUCWID1; + break; + + case MASK2: + *s++ = SS2; + size = EUCWID2; + break; + + case MASK3: + *s++ = SS3; + size = EUCWID3; + break; + + default: + return(-1); + } + index = size; + while(index--) { + d = wchar | 0200; + wchar >>= 8; + if(iscntrl(d)) + return(-1); + s[index] = d; + } +return(s + size - olds); +} diff --git a/usr/src/lib/libbc/libc/gen/common/execvp.c b/usr/src/lib/libbc/libc/gen/common/execvp.c new file mode 100644 index 0000000000..67579cef07 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/execvp.c @@ -0,0 +1,129 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * execlp(name, arg,...,0) (like execl, but does path search) + * execvp(name, argv) (like execv, but does path search) + */ +#include <sys/errno.h> +#include <sys/param.h> +#include <varargs.h> +#define NULL 0 + +static char *execat(); +static char *shell = "/bin/sh"; +extern char *getenv(), *strchr(); +extern unsigned sleep(); +extern int errno, execv(); + +/*VARARGS1*/ +int +execlp(name, va_alist) + char *name; + va_dcl +{ + va_list args; + + va_start(args); + return(execvp(name, (char **)args)); +} + +int +execvp(name, argv) +char *name, **argv; +{ + char *pathstr; + char fname[MAXPATHLEN]; + char *newargs[256]; + int i; + register char *cp; + register unsigned etxtbsy=1; + register int eacces=0; + + if((pathstr = getenv("PATH")) == NULL) + pathstr = ":/usr/ucb:/bin:/usr/bin"; + cp = strchr(name, '/')? "": pathstr; + + do { + cp = execat(cp, name, fname); + retry: + (void) execv(fname, argv); + switch(errno) { + case ENOEXEC: + newargs[0] = "sh"; + newargs[1] = fname; + for(i=1; newargs[i+1]=argv[i]; ++i) { + if(i >= 254) { + errno = E2BIG; + return(-1); + } + } + (void) execv(shell, newargs); + return(-1); + case ETXTBSY: + if(++etxtbsy > 5) + return(-1); + (void) sleep(etxtbsy); + goto retry; + case EACCES: + ++eacces; + break; + case ENOMEM: + case E2BIG: + case EFAULT: + return(-1); + } + } while(cp); + if(eacces) + errno = EACCES; + return(-1); +} + +static char * +execat(s1, s2, si) +register char *s1, *s2; +char *si; +{ + register char *s; + char *end; + + s = si; + end = s + MAXPATHLEN; + while(*s1 && *s1 != ':' && s < end) + *s++ = *s1++; + if(si != s && s < end) + *s++ = '/'; + while(*s2 && s < end) + *s++ = *s2++; + *s = '\0'; + return(*s1? ++s1: 0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/exit.c b/usr/src/lib/libbc/libc/gen/common/exit.c new file mode 100644 index 0000000000..44aae2fe47 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/exit.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +struct handlers { + void (*handler)(); + caddr_t arg; + struct handlers *next; +}; + +extern void _cleanup(); + +/* the list of handlers and their arguments */ +struct handlers *_exit_handlers; + +/* + * exit -- do termination processing, then evaporate process + */ +void +exit(code) + int code; +{ + register struct handlers *h; + + while (h = _exit_handlers) { + _exit_handlers = h->next; + (*h->handler)(code, h->arg); + } + _cleanup(); + _exit(code); +} diff --git a/usr/src/lib/libbc/libc/gen/common/exportent.c b/usr/src/lib/libbc/libc/gen/common/exportent.c new file mode 100644 index 0000000000..c96efff0c8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/exportent.c @@ -0,0 +1,268 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1986-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Exported file system table manager. Reads/writes "/etc/xtab". + */ + +#include <stdio.h> +#include <exportent.h> +#include <sys/file.h> +#include <ctype.h> + +extern char *strtok(); +extern char *strcpy(); + +#define LINESIZE 4096 + +static char *TMPFILE = "/tmp/xtabXXXXXX"; + +static char *skipwhite(); +static char *skipnonwhite(); + +FILE * +setexportent() +{ + FILE *f; + int fd; + + /* + * Create the tab file if it does not exist already + */ + if (access(TABFILE, F_OK) < 0) { + fd = open(TABFILE, O_CREAT, 0644); + close(fd); + } + if (access(TABFILE, W_OK) == 0) { + f = fopen(TABFILE, "r+"); + } else { + f = fopen(TABFILE, "r"); + } + if (f == NULL) { + return (NULL); + } + if (flock(fileno(f), LOCK_EX) < 0) { + (void)fclose(f); + return (NULL); + } + return (f); +} + + +void +endexportent(f) + FILE *f; +{ + (void)fclose(f); +} + + +struct exportent * +getexportent(f) + FILE *f; +{ + static char *line = NULL; + static struct exportent xent; + int len; + char *p; + + if (line == NULL) { + line = (char *)malloc(LINESIZE + 1); + } + if (fgets(line, LINESIZE, f) == NULL) { + return (NULL); + } + len = strlen(line); + if (line[len-1] == '\n') { + line[len-1] = 0; + } + xent.xent_dirname = line; + xent.xent_options = NULL; + p = skipnonwhite(line); + if (*p == 0) { + return (&xent); + } + *p++ = 0; + p = skipwhite(p); + if (*p == 0) { + return (&xent); + } + if (*p == '-') { + p++; + } + xent.xent_options = p; + return (&xent); +} + +remexportent(f, dirname) + FILE *f; + char *dirname; +{ + char buf[LINESIZE]; + FILE *f2; + int len; + char *fname; + int fd; + long pos; + long rempos; + int remlen; + int res; + + fname = (char *) malloc(strlen(TMPFILE) + 1); + pos = ftell(f); + rempos = 0; + remlen = 0; + (void)strcpy(fname, TMPFILE); + fd = mkstemp(fname); + if (fd < 0) { + return (-1); + } + if (unlink(fname) < 0) { + (void)close(fd); + return (-1); + } + f2 = fdopen(fd, "r+"); + if (f2 == NULL) { + (void)close(fd); + return (-1); + } + len = strlen(dirname); + rewind(f); + while (fgets(buf, sizeof(buf), f)) { + if (strncmp(buf, dirname, + len) != 0 || ! isspace((unsigned char)buf[len])) { + if (fputs(buf, f2) <= 0) { + (void)fclose(f2); + return (-1); + } + } else { + remlen = strlen(buf); + rempos = ftell(f) - remlen; + } + } + rewind(f); + if (ftruncate(fileno(f), 0L) < 0) { + (void)fclose(f2); + return (-1); + } + rewind(f2); + while (fgets(buf, sizeof(buf), f2)) { + if (fputs(buf, f) <= 0) { + (void)fclose(f2); + return (-1); + } + } + (void)fclose(f2); + if (remlen == 0) { + /* nothing removed */ + (void) fseek(f, pos, L_SET); + res = -1; + } else if (pos <= rempos) { + res = fseek(f, pos, L_SET); + } else if (pos > rempos + remlen) { + res = fseek(f, pos - remlen, L_SET); + } else { + res = fseek(f, rempos, L_SET); + } + return (res < 0 ? -1 : 0); +} + + +addexportent(f, dirname, options) + FILE *f; + char *dirname; + char *options; +{ + long pos; + + pos = ftell(f); + if (fseek(f, 0L, L_XTND) >= 0 && + fprintf(f, "%s", dirname) > 0 && + (options == NULL || fprintf(f, " -%s", options) > 0) && + fprintf(f, "\n") > 0 && + fseek(f, pos, L_SET) >= 0) { + return (0); + } + return (-1); +} + + +char * +getexportopt(xent, opt) + struct exportent *xent; + char *opt; +{ + static char *tokenbuf = NULL; + char *lp; + char *tok; + int len; + + if (tokenbuf == NULL) { + tokenbuf = (char *)malloc(LINESIZE); + } + if (xent->xent_options == NULL) { + return (NULL); + } + (void)strcpy(tokenbuf, xent->xent_options); + lp = tokenbuf; + len = strlen(opt); + while ((tok = strtok(lp, ",")) != NULL) { + lp = NULL; + if (strncmp(opt, tok, len) == 0) { + if (tok[len] == '=') { + return (&tok[len + 1]); + } else if (tok[len] == 0) { + return (""); + } + } + } + return (NULL); +} + + +#define iswhite(c) ((c) == ' ' || c == '\t') + +static char * +skipwhite(str) + char *str; +{ + while (*str && iswhite(*str)) { + str++; + } + return (str); +} + +static char * +skipnonwhite(str) + char *str; +{ + while (*str && ! iswhite(*str)) { + str++; + } + return (str); +} diff --git a/usr/src/lib/libbc/libc/gen/common/fabs.c b/usr/src/lib/libbc/libc/gen/common/fabs.c new file mode 100644 index 0000000000..d570aa4017 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/fabs.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +double +fabs(x) + double x; +{ + long *px = (long *) &x; +#ifdef i386 + px[1] &= 0x7fffffff; +#else + px[0] &= 0x7fffffff; +#endif + return x; +} diff --git a/usr/src/lib/libbc/libc/gen/common/file_decim.c b/usr/src/lib/libbc/libc/gen/common/file_decim.c new file mode 100644 index 0000000000..a12b272fb6 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/file_decim.c @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <ctype.h> +#include <stdio.h> +#ifndef PRE41 +#include <locale.h> +#endif +#include "base_conversion.h" + +void +file_to_decimal(ppc, nmax, fortran_conventions, pd, pform, pechar, pf, pnread) + char **ppc; + int nmax; + int fortran_conventions; + decimal_record *pd; + enum decimal_string_form *pform; + char **pechar; + FILE *pf; + int *pnread; + +{ + register char *cp = *ppc; + register int current; + register int nread = 1; /* Number of characters read so far. */ + char *good = cp - 1; /* End of known good token. */ + char *cp0 = cp; + + current = getc(pf); /* Initialize buffer. */ + *cp = current; + +#define ATEOF current +#define CURRENT current +#define NEXT \ + if (nread < nmax) \ + { cp++ ; current = getc(pf) ; *cp = current ; nread++ ;} \ + else \ + { current = NULL ; } ; + +#include "char_to_decimal.h" +#undef CURRENT +#undef NEXT + + if (nread < nmax) { + while (cp >= *ppc) { /* Push back as many excess + * characters as possible. */ + if (*cp != EOF) { /* Can't push back EOF. */ + if (ungetc(*cp, pf) == EOF) + break; + } cp--; + nread--; + } + } + cp++; + *cp = 0; /* Terminating null. */ + *pnread = nread; + +} diff --git a/usr/src/lib/libbc/libc/gen/common/float_decim.c b/usr/src/lib/libbc/libc/gen/common/float_decim.c new file mode 100644 index 0000000000..f532e8b2c5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/float_decim.c @@ -0,0 +1,94 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* + * Conversion between single, and extended binary and decimal + * floating point - separated from double_to_decimal to minimize impact on + * main(){printf("Hello");} + */ + +#include "base_conversion.h" + +void +single_to_decimal(px, pm, pd, ps) + single *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + single_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize *ps - no exceptions. */ + kluge.x = *px; + pd->sign = kluge.f.msw.sign; + pd->fpclass = _class_single(px); + switch (pd->fpclass) { + case fp_zero: + break; + case fp_infinity: + break; + case fp_quiet: + break; + case fp_signaling: + break; + default: + _unpack_single(&u, &kluge.x); + _unpacked_to_decimal(&u, pm, pd, ps); + } +} + +void +extended_to_decimal(px, pm, pd, ps) + extended *px; + decimal_mode *pm; + decimal_record *pd; + fp_exception_field_type *ps; +{ + extended_equivalence kluge; + unpacked u; + + *ps = 0; /* Initialize *ps - no exceptions. */ + kluge.x[0] = (*px)[0]; + kluge.x[1] = (*px)[1]; + kluge.x[2] = (*px)[2]; + pd->sign = kluge.f.msw.sign; + pd->fpclass = _class_extended(px); + switch (pd->fpclass) { + case fp_zero: + break; + case fp_infinity: + break; + case fp_quiet: + break; + case fp_signaling: + break; + default: + _unpack_extended(&u, px); + _unpacked_to_decimal(&u, pm, pd, ps); + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/fmod.c b/usr/src/lib/libbc/libc/gen/common/fmod.c new file mode 100644 index 0000000000..2c071a4ccb --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/fmod.c @@ -0,0 +1,163 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* Special version adapted from libm for use in libc. */ + +#ifdef i386 +static n0 = 1, n1 = 0; +#else +static n0 = 0, n1 = 1; +#endif + +static double two52 = 4.503599627370496000E+15; +static double twom52 = 2.220446049250313081E-16; + +static double +setexception(n, x) + int n; + double x; +{ +} + +double +copysign(x, y) + double x, y; +{ + long *px = (long *) &x; + long *py = (long *) &y; + px[n0] = (px[n0] & 0x7fffffff) | (py[n0] & 0x80000000); + return x; +} + +static double +fabs(x) + double x; +{ + long *px = (long *) &x; +#ifdef i386 + px[1] &= 0x7fffffff; +#else + px[0] &= 0x7fffffff; +#endif + return x; +} + +static int +finite(x) + double x; +{ + long *px = (long *) &x; + return ((px[n0] & 0x7ff00000) != 0x7ff00000); +} + +static int +ilogb(x) + double x; +{ + long *px = (long *) &x, k; + k = px[n0] & 0x7ff00000; + if (k == 0) { + if ((px[n1] | (px[n0] & 0x7fffffff)) == 0) + return 0x80000001; + else { + x *= two52; + return ((px[n0] & 0x7ff00000) >> 20) - 1075; + } + } else if (k != 0x7ff00000) + return (k >> 20) - 1023; + else + return 0x7fffffff; +} + +static double +scalbn(x, n) + double x; + int n; +{ + long *px = (long *) &x, k; + double twom54 = twom52 * 0.25; + k = (px[n0] & 0x7ff00000) >> 20; + if (k == 0x7ff) + return x + x; + if ((px[n1] | (px[n0] & 0x7fffffff)) == 0) + return x; + if (k == 0) { + x *= two52; + k = ((px[n0] & 0x7ff00000) >> 20) - 52; + } + k = k + n; + if (n > 5000) + return setexception(2, x); + if (n < -5000) + return setexception(1, x); + if (k > 0x7fe) + return setexception(2, x); + if (k <= -54) + return setexception(1, x); + if (k > 0) { + px[n0] = (px[n0] & 0x800fffff) | (k << 20); + return x; + } + k += 54; + px[n0] = (px[n0] & 0x800fffff) | (k << 20); + return x * twom54; +} + +double +fmod(x, y) + double x, y; +{ + int ny, nr; + double r, z, w; +int finite(), ilogb(); +double fabs(), scalbn(), copysign(); + + /* purge off exception values */ + if (!finite(x) || y != y || y == 0.0) { + return (x * y) / (x * y); + } + /* scale and subtract to get the remainder */ + r = fabs(x); + y = fabs(y); + ny = ilogb(y); + while (r >= y) { + nr = ilogb(r); + if (nr == ny) + w = y; + else { + z = scalbn(y, nr - ny - 1); + w = z + z; + } + if (r >= w) + r -= w; + else + r -= z; + } + + /* restore sign */ + return copysign(r, x); +} diff --git a/usr/src/lib/libbc/libc/gen/common/frexp.c b/usr/src/lib/libbc/libc/gen/common/frexp.c new file mode 100644 index 0000000000..ffc75618b1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/frexp.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" /* from UCB 5.2 3/9/86 */ + +/* + * the call + * x = frexp(arg,&exp); + * must return a double fp quantity x which is <1.0 + * and the corresponding binary exponent "exp". + * such that + * arg = x*2^exp + */ +double +frexp(x, i) + double x; + int *i; +{ + int neg, j; + + j = 0; + neg = 0; + if (x<0) { + x = -x; + neg = 1; + } + if (x>=1.0) + while (x>=1.0) { + j = j+1; + x = x/2; + } + else if (x < 0.5 && x != 0.0) + while(x<0.5) { + j = j-1; + x = 2*x; + } + *i = j; + if(neg) + x = -x; + return (x); +} diff --git a/usr/src/lib/libbc/libc/gen/common/fstab.c b/usr/src/lib/libbc/libc/gen/common/fstab.c new file mode 100644 index 0000000000..6802ce6397 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/fstab.c @@ -0,0 +1,146 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.4 83/06/19 */ + +#include <fstab.h> +#include <stdio.h> +#include <ctype.h> +#include <mntent.h> + +static struct fstab *pfs; +static FILE *fs_file; + +static +fstabscan(fs) + struct fstab *fs; +{ + struct mntent *mnt; + + /* skip over all filesystem types except '4.2', 'swap' & 'ignore' */ + while (((mnt = getmntent(fs_file)) != NULL) && + !((strcmp(mnt->mnt_type, MNTTYPE_42) == 0) || + (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) || + (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0))) + continue; + if (mnt == NULL) + return (EOF); + fs->fs_spec = mnt->mnt_fsname; + fs->fs_file = mnt->mnt_dir; + if (strcmp(mnt->mnt_type, MNTTYPE_IGNORE) == 0) { + strcpy(mnt->mnt_opts, FSTAB_XX); + } else if (strcmp(mnt->mnt_type, MNTTYPE_SWAP) == 0) { + strcpy(mnt->mnt_opts, FSTAB_SW); + } else if (hasmntopt(mnt, MNTOPT_RO)) { + strcpy(mnt->mnt_opts, FSTAB_RO); + } else if (hasmntopt(mnt, MNTOPT_QUOTA)) { + strcpy(mnt->mnt_opts, FSTAB_RQ); + } else { + strcpy(mnt->mnt_opts, FSTAB_RW); + } + fs->fs_type = mnt->mnt_opts; + fs->fs_freq = mnt->mnt_freq; + fs->fs_passno = mnt->mnt_passno; + return (5); +} + +setfsent() +{ + + if (fs_file) + endfsent(); + if ((fs_file = setmntent(FSTAB, "r")) == NULL) { + fs_file = 0; + return (0); + } + return (1); +} + +endfsent() +{ + + if (fs_file) { + endmntent(fs_file); + fs_file = 0; + } + return (1); +} + +struct fstab * +getfsent() +{ + int nfields; + + if ((fs_file == 0) && (setfsent() == 0)) + return ((struct fstab *)0); + if (pfs == 0) { + pfs = (struct fstab *)malloc(sizeof (struct fstab)); + if (pfs == 0) + return (0); + } + nfields = fstabscan(pfs); + if (nfields == EOF || nfields != 5) + return ((struct fstab *)0); + return (pfs); +} + +struct fstab * +getfsspec(name) + char *name; +{ + register struct fstab *fsp; + + if (setfsent() == 0) /* start from the beginning */ + return ((struct fstab *)0); + while((fsp = getfsent()) != 0) + if (strcmp(fsp->fs_spec, name) == 0) + return (fsp); + return ((struct fstab *)0); +} + +struct fstab * +getfsfile(name) + char *name; +{ + register struct fstab *fsp; + + if (setfsent() == 0) /* start from the beginning */ + return ((struct fstab *)0); + while ((fsp = getfsent()) != 0) + if (strcmp(fsp->fs_file, name) == 0) + return (fsp); + return ((struct fstab *)0); +} + +struct fstab * +getfstype(type) + char *type; +{ + register struct fstab *fs; + + if (setfsent() == 0) + return ((struct fstab *)0); + while ((fs = getfsent()) != 0) + if (strcmp(fs->fs_type, type) == 0) + return (fs); + return ((struct fstab *)0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ftok.c b/usr/src/lib/libbc/libc/gen/common/ftok.c new file mode 100644 index 0000000000..ae0724c487 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ftok.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/sysmacros.h> + +key_t +ftok(path, id) +char *path; +char id; +{ + struct stat st; + + return(stat(path, &st) < 0 ? (key_t)-1 : + (key_t)((key_t)id << 24 | ((long)(unsigned)minor(st.st_dev)) << 16 | + (unsigned)st.st_ino)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ftw.c b/usr/src/lib/libbc/libc/gen/common/ftw.c new file mode 100644 index 0000000000..6ac2cade21 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ftw.c @@ -0,0 +1,239 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/*************************************************************** + * ftw - file tree walk + * + * int ftw (path, fn, depth) char *path; int (*fn)(); int depth; + * + * Given a path name, ftw starts from the file given by that path + * name and visits each file and directory in the tree beneath + * that file. If a single file has multiple links within the + * structure, it will be visited once for each such link. + * For each object visited, fn is called with three arguments. + * The first contains the path name of the object, the second + * contains a pointer to a stat buffer which will usually hold + * appropriate information for the object and the third will + * contain an integer value giving additional information about + * + * FTW_F The object is a file for which stat was + * successful. It does not guarantee that the + * file can actually be read. + * + * FTW_D The object is a directory for which stat and + * open for read were both successful. + * + * FTW_DNR The object is a directory for which stat + * succeeded, but which cannot be read. Because + * the directory cannot be read, fn will not be + * called for any descendants of this directory. + * + * FTW_NS Stat failed on the object because of lack of + * appropriate permission, or because the object is a + * symbolic link that points to a non-existent file. + * This indication will be given, for example, for each + * file in a directory with read but no execute + * permission. Because stat failed, it is not + * possible to determine whether this object is a file + * or a directory. The stat buffer passed to fn will + * contain garbage. Stat failure for any reason + * other than lack of permission will be + * considered an error and will cause ftw to stop + * and return -1 to its caller. + * + * If fn returns nonzero, ftw stops and returns the same value + * to its caller. If ftw gets into other trouble along the way, + * it returns -1 and leaves an indication of the cause in errno. + * + * The third argument to ftw does not limit the depth to which + * ftw will go. Rather, it limits the depth to which ftw will + * go before it starts recycling file descriptors. In general, + * it is necessary to use a file descriptor for each level of the + * tree, but they can be recycled for deep trees by saving the + * position, closing, re-opening, and seeking. It is possible + * to start recycling file descriptors by sensing when we have + * run out, but in general this will not be terribly useful if + * fn expects to be able to open files. We could also figure out + * how many file descriptors are available and guarantee a certain + * number to fn, but we would not know how many to guarantee, + * and we do not want to impose the extra overhead on a caller who + * knows how many are available without having to figure it out. + * + * It is possible for ftw to die with a memory fault in the event + * of a file system so deeply nested that the stack overflows. + **************************************************************/ + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/dir.h> +#include <errno.h> +#include <ftw.h> + +#define NULL 0 + +extern char *malloc(), *strcpy(); +extern void free(); +extern int errno; + +int +ftw(path, fn, depth) +char *path; +int (*fn)(); +int depth; +{ + int rc, n; + DIR *dirp; + char *subpath, *component; + struct stat sb; + struct direct *dp; + + /* Try to get file status. + If unsuccessful, errno will say why. */ + if(stat(path, &sb) < 0) { + if (errno == EACCES) { + return((*fn)(path, &sb, FTW_NS)); + } else if (errno == ENOENT) { + /* Check if symbolic link points to non-existent file */ + if (lstat(path, &sb) < 0) { + return(-1); + } + else if ((sb.st_mode & S_IFMT) == S_IFLNK) { + errno = ENOENT; + return((*fn)(path, &sb, FTW_NS)); + } + else { + return(-1); + } + } else { + return(-1); + } + } + + /* + * The stat succeeded, so we know the object exists. + * If not a directory, call the user function and return. + */ + if((sb.st_mode & S_IFMT) != S_IFDIR) + return((*fn)(path, &sb, FTW_F)); + + /* + * The object was a directory. + * + * Open a file to read the directory + */ + dirp = opendir(path); + + /* + * Call the user function, telling it whether + * the directory can be read. If it can't be read + * call the user function or indicate an error, + * depending on the reason it couldn't be read. + */ + if(dirp == NULL) + return(errno == EACCES? (*fn)(path, &sb, FTW_DNR): -1); + + /* We could read the directory. Call user function. */ + rc = (*fn)(path, &sb, FTW_D); + if(rc != 0) + return(rc); + + /* Allocate a buffer to hold generated pathnames. */ + n = strlen(path); + subpath = malloc((unsigned)(n+MAXNAMLEN+2)); + if(subpath == NULL) { + closedir(dirp); + errno = ENOMEM; + return(-1); + } + + /* Create a prefix to which we will append component names */ + (void)strcpy(subpath, path); + if(subpath[0] != '\0' && subpath[n-1] != '/') + subpath[n++] = '/'; + component = &subpath[n]; + + /* + * Read the directory one component at a time. + * We must ignore "." and "..", but other than that, + * just create a path name and call self to check it out. + */ + while((dp = readdir(dirp)) != NULL) { + if(strcmp(dp->d_name, ".") != 0 && + strcmp(dp->d_name, "..") != 0) { + long here; + + /* Append component name to the working path */ + (void)strcpy(component, dp->d_name); + + /* + * If we are about to exceed our depth, + * remember where we are and close a file. + */ + if(depth <= 1) { + here = telldir(dirp); + closedir(dirp); + } + + /* + * Do a recursive call to process the file. + * (watch this, sports fans) + */ + rc = ftw(subpath, fn, depth-1); + if(rc != 0) { + free(subpath); + if(depth > 1) + closedir(dirp); + return(rc); + } + + /* + * If we closed the file, try to reopen it. + */ + if(depth <= 1) { + dirp = opendir(path); + if(dirp == NULL) { + free(subpath); + return(-1); + } + seekdir(dirp, here); + } + } + } + + /* + * We got out of the subdirectory loop. The return from + * the final readdir is in dp. Clean up. + */ + free(subpath); + closedir(dirp); + return(0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/func_decim.c b/usr/src/lib/libbc/libc/gen/common/func_decim.c new file mode 100644 index 0000000000..a42a3c80ca --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/func_decim.c @@ -0,0 +1,83 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <ctype.h> +#include <stdio.h> +#ifndef PRE41 +#include <locale.h> +#endif +#include "base_conversion.h" + +void +func_to_decimal(ppc, nmax, fortran_conventions, pd, pform, pechar, pget, pnread, punget) + char **ppc; + int nmax; + int fortran_conventions; + decimal_record *pd; + enum decimal_string_form *pform; + char **pechar; + int (*pget) (); +int *pnread; +int (*punget) (); + +{ + register char *cp = *ppc; + register int current; + register int nread = 1; /* Number of characters read so far. */ + char *good = cp - 1; /* End of known good token. */ + char *cp0 = cp; + + current = (*pget) (); /* Initialize buffer. */ + *cp = current; + +#define ATEOF current +#define CURRENT current +#define NEXT \ + if (nread < nmax) \ + { cp++ ; current = (*pget)() ; *cp = current ; nread++ ;} \ + else \ + { current = NULL ; } ; + +#include "char_to_decimal.h" +#undef CURRENT +#undef NEXT + + if ((nread < nmax) && (punget != NULL)) { + while (cp >= *ppc) { /* Push back as many excess + * characters as possible. */ + if (*cp != EOF) { /* Can't push back EOF. */ + if ((*punget) (*cp) == EOF) + break; + } + cp--; + nread--; + } + } + cp++; + *cp = 0; /* Terminating null. */ + *pnread = nread; +} diff --git a/usr/src/lib/libbc/libc/gen/common/gconvert.c b/usr/src/lib/libbc/libc/gen/common/gconvert.c new file mode 100644 index 0000000000..885889855d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/gconvert.c @@ -0,0 +1,164 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* + * gcvt - Floating output conversion to minimal length string + */ + +#include "base_conversion.h" +#ifndef PRE41 +#include <locale.h> +#endif + +void +_gcvt(ndigit, pd, trailing, buf) + int ndigit; + decimal_record *pd; + char *buf; +{ + char *p, *pstring; + int i; + static char *inf8 = "Infinity"; + static char *inf3 = "Inf"; + static char *nan = "NaN"; +#ifdef PRE41 + char decpt = '.'; +#else + char decpt = *(localeconv()->decimal_point); +#endif + + p = buf; + if (pd->sign) + *(p++) = '-'; + switch (pd->fpclass) { + case fp_zero: + *(p++) = '0'; + if (trailing != 0) { + *(p++) = decpt; + for (i = 0; i < ndigit - 1; i++) + *(p++) = '0'; + } + break; + case fp_infinity: + if (ndigit < 8) + pstring = inf3; + else + pstring = inf8; + goto copystring; + case fp_quiet: + case fp_signaling: + pstring = nan; +copystring: + for (i = 0; *pstring != 0;) + *(p++) = *(pstring++); + break; + default: + if ((pd->exponent > 0) || (pd->exponent < -(ndigit + 3))) { /* E format. */ + char estring[4]; + int n; + + i = 0; + *(p++) = pd->ds[0]; + *(p++) = decpt; + for (i = 1; pd->ds[i] != 0;) + *(p++) = pd->ds[i++]; + if (trailing == 0) { /* Remove trailing zeros and . */ + p--; + while (*p == '0') + p--; + if (*p != decpt) + p++; + } + *(p++) = 'e'; + n = pd->exponent + i - 1; + if (n >= 0) + *(p++) = '+'; + else { + *(p++) = '-'; + n = -n; + } + _fourdigitsquick((short unsigned) n, estring); + for (i = 0; estring[i] == '0'; i++); /* Find end of zeros. */ + if (i > 2) + i = 2; /* Guarantee two zeros. */ + for (; i <= 3;) + *(p++) = estring[i++]; /* Copy exp digits. */ + } else { /* F format. */ + if (pd->exponent >= (1 - ndigit)) { /* x.xxx */ + for (i = 0; i < (ndigit + pd->exponent);) + *(p++) = pd->ds[i++]; + *(p++) = decpt; + if (pd->ds[i] != 0) { /* More follows point. */ + for (; i < ndigit;) + *(p++) = pd->ds[i++]; + } + } else {/* 0.00xxxx */ + *(p++) = '0'; + *(p++) = decpt; + for (i = 0; i < -(pd->exponent + ndigit); i++) + *(p++) = '0'; + for (i = 0; pd->ds[i] != 0;) + *(p++) = pd->ds[i++]; + } + if (trailing == 0) { /* Remove trailing zeros and point. */ + p--; + while (*p == '0') + p--; + if (*p != decpt) + p++; + } + } + } + *(p++) = 0; +} + +char * +gconvert(number, ndigit, trailing, buf) + double number; + int ndigit, trailing; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type fef; + + dm.rd = fp_direction; + dm.df = floating_form; + dm.ndigits = ndigit; + double_to_decimal(&number, &dm, &dr, &fef); + _gcvt(ndigit, &dr, trailing, buf); + return (buf); +} + +char * +gcvt(number, ndigit, buf) + double number; + int ndigit; + char *buf; +{ + return (gconvert(number, ndigit, 0, buf)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getacinfo.c b/usr/src/lib/libbc/libc/gen/common/getacinfo.c new file mode 100644 index 0000000000..d73f62eff7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getacinfo.c @@ -0,0 +1,313 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ +/* getacinfo.c - get audit control info */ + +#include <stdio.h> +#include <string.h> + +#define DIROP 0 +#define OTHEROP 1 + +#define LEN 360 /* maximum audit control entry length */ + +#define SUCCESS 0 +#define EOF_WARN 1 +#define REW_WARN 2 +#define EOF_ERR -1 +#define ERROR -2 +#define FORMAT_ERR -3 + + +static char *AUDIT_CTRL = "/etc/security/audit/audit_control"; +static char *MINLABEL = "minfree:"; +static char *DIRLABEL = "dir:"; +static char *FLGLABEL = "flags:"; +static int LASTOP; +static int DIRINIT; +static FILE *acf; /* pointer into /etc/security/audit/audit_control */ + +/* getacinfo.c - get audit control info + * + * getacdir() - get audit control directories, one at a time + * getacflg() - get audit control flags + * getacmin() - get audit control directory min. fill value + * setac() - rewind the audit control file + * endac() - close the audit control file + */ + + +/* getacdir() - get audit control directories, one at a time + * + * input: len - size of dir buffer + * + * output: dir - directory string + * + * returns: 0 - entry read ok + * -1 - end of file + * -2 - error - can't open audit control file for read + * -3 - error - directory entry format error + * 1 - directory search started from beginning again + * + * notes: It is the responsibility of the calling function to + * check the status of the directory entry. + */ + +int +getacdir(dir, len) +char *dir; +int len; +{ + int retstat = SUCCESS, gotone = 0, dirlen, dirst; + char entry[LEN]; + void setac(); + + /* + * open file if it is not already opened + */ + if (acf == NULL && (acf = fopen(AUDIT_CTRL, "r")) == NULL) + retstat = ERROR; + else if (LASTOP != DIROP && DIRINIT == 1) { + retstat = REW_WARN; + setac(); + } else { + DIRINIT = 1; + LASTOP == DIROP; + } + if (retstat >= SUCCESS) { + do { + if (fgets(entry, LEN, acf) != NULL) { + switch(*entry) { + case '#': + break; + case 'd': + /* + * return directory entry + */ + if (!strncmp(entry,DIRLABEL,strlen(DIRLABEL))) { + if ((strlen(entry)+1) > len) + retstat = FORMAT_ERR; + else { + /* + * allow zero or one blank + * between colon and directory + */ + if (entry[strlen(DIRLABEL)] == ' ') { + dirst = strlen(DIRLABEL)+1; + dirlen = + strlen(entry) - + (strlen(DIRLABEL)+2); + } else { + dirst = strlen(DIRLABEL); + dirlen = + strlen(entry) - + (strlen(DIRLABEL)+1); + } + strcpy(dir, entry+dirst); + strcpy(dir+dirlen, "\0"); + gotone = 1; + } + } else + retstat = FORMAT_ERR; + break; + case 'm': + break; + case 'f': + break; + default: + break; + } + } else if ((feof(acf)) == 0) + retstat = ERROR; + else + retstat = EOF_ERR; + + } while (gotone == 0 && retstat >= SUCCESS); + } + return (retstat); +} + +/* + * getacmin() - get audit control directory min. fill value + * + * output: min_val - percentage of directory fill allowed + * + * returns: 0 - entry read ok + * 1 - end of file + * -2 - error; errno contains error number + * -3 - error - directory entry format error + */ + +int +getacmin(min_val) +int *min_val; +{ + int retstat = SUCCESS, gotone = 0; + char entry[LEN]; + void endac(); + + /* + * open file if it is not already opened + */ + if (acf == NULL && (acf = fopen(AUDIT_CTRL, "r")) == NULL) + retstat = ERROR; + else + rewind(acf); + + if (retstat == SUCCESS) { + do { + if (fgets(entry, LEN, acf) != NULL) { + switch(*entry) { + case '#': + break; + case 'd': + break; + case 'm': + if (!strncmp(entry, MINLABEL, strlen(MINLABEL))) { + sscanf(entry+strlen(MINLABEL), "%d", min_val); + gotone = 1; + } else + retstat = FORMAT_ERR; + break; + case 'f': + break; + default: + break; + } + } else if ((feof(acf)) == 0) + retstat = ERROR; + else + retstat = EOF_WARN; + + } while (gotone == 0 && retstat == SUCCESS); + } + + if (LASTOP == DIROP) + LASTOP = OTHEROP; + else + endac(); + + return (retstat); +} + +/* getacflg() - get audit control flags + * + * output: auditstring - character representation of system audit flags + * + * returns: 0 - entry read ok + * 1 - end of file + * -2 - error - errno contains error number + * -3 - error - directory entry format error + */ + +getacflg(auditstring, len) +char *auditstring; +int len; +{ + int retstat = SUCCESS, gotone = 0, minst, minlen; + char entry[LEN]; + void endac(); + + /* + * open file if it is not already opened + */ + if (acf == NULL && (acf = fopen(AUDIT_CTRL, "r")) == NULL) + retstat = ERROR; + else + rewind(acf); + + if (retstat == SUCCESS) { + do { + if (fgets(entry, LEN, acf) != NULL) { + switch(*entry) { + case '#': + break; + case 'd': + break; + case 'm': + break; + case 'f': + if ((strncmp(entry, FLGLABEL, strlen(FLGLABEL))) == 0) { + if (entry[strlen(FLGLABEL)] == ' ') { + minst = strlen(FLGLABEL)+1; + minlen = strlen(entry)-(strlen(FLGLABEL)+2); + } else { + minst = strlen(FLGLABEL); + minlen = strlen(entry)-(strlen(FLGLABEL)+1); + } + if (minlen > len) + retstat = FORMAT_ERR; + else { + strcpy(auditstring, entry+minst); + strcpy(auditstring+minlen, "\0"); + gotone = 1; + } + } else + retstat = FORMAT_ERR; + break; + default: + break; + } + } else if ((feof(acf)) == 0) + retstat = ERROR; + else + retstat = EOF_WARN; + + } while (gotone == 0 && retstat == SUCCESS); + } + if (LASTOP == DIROP) + LASTOP = OTHEROP; + else + endac(); + + return (retstat); +} + +/* rewind the audit control file */ +void +setac() +{ + if (acf == NULL) + acf = fopen(AUDIT_CTRL, "r"); + else + rewind(acf); + LASTOP = DIROP; + DIRINIT = 0; +} + + +/* close the audit control file */ +void +endac() +{ + if (acf != NULL) { + fclose(acf); + acf = NULL; + } + LASTOP = DIROP; + DIRINIT = 0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/getauditflags.c b/usr/src/lib/libbc/libc/gen/common/getauditflags.c new file mode 100644 index 0000000000..c58be9f408 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getauditflags.c @@ -0,0 +1,497 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#include <sys/label.h> +#include <sys/audit.h> +#include <auevents.h> + +#define ON 1 +#define OK 0 +#define OFF -1 +#define COMMA ',' +#define COMMASTR "," + +#define COMMON 0 +#define SUCCESS 1 +#define FAILURE 2 + +#define MAXFLDLEN 25 +#define MAXSTRLEN 360 +#define MAXEVENT 11 + +/* GLOBALS */ + +static int length; +static int pos = 0; + +struct list { + short count; + short on[MAXEVENT+1]; + short off; +}; +typedef struct list list_t; + +struct exception { + short type; + short exception; +}; +typedef struct exception except_t; + +/* + * getauditflagschar() - convert bit flag to character string + * + * input: masks->as_success - audit on success + * masks->as_failure - audit on failure + * verbose - string format. 0 if short name; 1 if long name; + * + * output: auditstring - resultant audit string + * + * returns: 0 - entry read ok + * -1 - error + */ + +getauditflagschar(auditstring, masks, verbose) + char *auditstring; + audit_state_t *masks; + int verbose; +{ + int i, j, k, mask_num; + int list = -1, retstat = 0; + int except_list[3]; + char *prefix = " "; + except_t except[2]; + list_t lists[3]; + + /* + * initialize input buffer + */ + strcpy(auditstring, ""); + /* + * initialize lists struct + */ + for (mask_num = COMMON; mask_num <= FAILURE; mask_num++) { + lists[mask_num].count = 0; + lists[mask_num].off = -1; + for (i=0;i<MAXEVENT+1;i++) + lists[mask_num].on[i] = -1; + } + /* + * initialize exception lists + */ + for (i = 0; i < 2; i++) { + except[i].type = -1; + except[i].exception = -1; + } + + for (i = 0; i < 3; i++) + except_list[i] = 0; + + /* + * set length global + */ + length = verbose; + pos = 0; + + /* + * find turned-on events - if on, store index of event + * in one of the three event lists, common, success, failure. + */ + for ( i = 0; i < MAXEVENT; i++) { + if (((event_class[i].event_mask & masks->as_success) > 0) || + ((event_class[i].event_mask & masks->as_failure) > 0)) { + + /* + * check for events in common + */ + if (((event_class[i].event_mask & masks->as_success) > + 0) && + ((event_class[i].event_mask & masks->as_failure) > 0)) + lists[COMMON].on[lists[COMMON].count++] = i; + + /* + * check for success events + */ + if ((event_class[i].event_mask & masks->as_success) > 0) + lists[SUCCESS].on[lists[SUCCESS].count++] = i; + else { + except_list[SUCCESS]++; + if (lists[SUCCESS].off == -1) + lists[SUCCESS].off = i; + } + /* + * check for failure events + */ + if ((event_class[i].event_mask & masks->as_failure) > 0) + lists[FAILURE].on[lists[FAILURE].count++] = i; + else { + except_list[FAILURE]++; + if (lists[FAILURE].off == -1) + lists[FAILURE].off = i; + } + } else { + except_list[COMMON]++; + if (lists[COMMON].off == -1) + lists[COMMON].off = i; + } + } + /* + * check for all set or all-1 set - output all and common exceptions. + * the all or common state is exclusive; only one of the + * three, (+-)all, allowed + */ + /* + * no exceptions + */ + if (lists[COMMON].count >= MAXEVENT-2) { + if (lists[COMMON].count == MAXEVENT) + list = COMMON; + + /* + * one exception + */ + else if (lists[COMMON].count == MAXEVENT-1) { + for (i=COMMON;i<=FAILURE && (list == -1);i++) { + if (except_list[i] == 1) { + list = COMMON; + except[0].type = i; + except[0].exception = lists[i].off; + } + } + } + /* + * two exceptions + */ + else if (lists[COMMON].count == MAXEVENT-2) { + if (except_list[COMMON] == 1) { + list = COMMON; + except[0].type = COMMON; + except[0].exception = lists[COMMON].off; + for (i=SUCCESS;i<=FAILURE;i++) { + if (except_list[i] == 1) { + except[1].type = i; + except[1].exception = lists[i].off; + } + } + + } else if (except_list[COMMON] == 0) { + for (i=SUCCESS,j=0;i<=FAILURE;i++) { + if (except_list[i] == 1) { + list = COMMON; + except[j].type = i; + except[j++].exception = lists[i].off; + } + } + } + } + } else { + /* + * check for +all or -all + */ + for (i=SUCCESS,j=0;i<=FAILURE;i++) { + if (lists[i].count >= MAXEVENT-1) { + list = i; + except[j].type = i; + if (lists[i].count != MAXEVENT) { + if (lists[i].off != -1) + except[j++].exception = + lists[i].off; + else + except[j++].exception = + lists[COMMON].off; + } + } + } + } + /* + * output all and exceptions + */ + if (list != -1) { + if(list==SUCCESS) { + if ((stringcopy(auditstring, "+", 0)) == -1) + retstat = -1; + } + if(list==FAILURE) { + if ((stringcopy(auditstring, "-", 0)) == -1) + retstat = -1; + } + + if (retstat == 0) { + if (length) { + if + ((stringcopy(auditstring,event_class[11].event_lname,1)) == -1) + retstat = -1; + } else + if ((stringcopy(auditstring, event_class[11].event_sname,1)) == -1) + retstat = -1; + } + + if (retstat == 0) { + /* + * output exceptions + */ + for (i=0;i<2 && except[i].exception != -1; i++) { + if ((stringcopy(auditstring, "^", 0)) == -1) + retstat = -1; + if(except[i].type==SUCCESS) { + if ((stringcopy(auditstring, "+", 0)) == -1) + retstat = -1; + } + if (except[i].type==FAILURE) { + if ((stringcopy(auditstring, "-", 0)) == -1) + retstat = -1; + } + if (length == 1 && retstat == 0) { + if ((stringcopy(auditstring, + event_class[except[i].exception].event_lname, 1))==-1) + retstat = -1; + } else if (retstat == 0) { + if ((stringcopy(auditstring, + event_class[except[i].exception].event_sname, 1))==-1) + retstat = -1; + } + } + } + } /* end of " all " processing */ + + /* + * process common events if no "all" was output + */ + if (list == -1 && (lists[COMMON].count > 0) && retstat == 0) { + /* + * output common events first + */ + for (j=0;j<lists[COMMON].count;j++) { + if (length == 1) { + if ((stringcopy(auditstring, + event_class[lists[COMMON].on[j]].event_lname, 1)) == -1) + retstat = -1; + } else if ((stringcopy(auditstring, + event_class[lists[COMMON].on[j]].event_sname, 1)) == -1) + retstat = -1; + } + /* + * remove common events from individual lists + */ + if (retstat == 0) { + for (i=SUCCESS;i<=FAILURE;i++) { + for(j=0;j<lists[COMMON].count;j++) { + for(k=0;k < lists[i].count;k++) { + if (lists[COMMON].on[j] == + lists[i].on[k]) + lists[i].on[k] = -1; + } + } + } + } + } + + /* + * start processing individual event flags in success + * and failure lists + */ + if (list != COMMON && retstat == 0) { + for (i=SUCCESS;i<=FAILURE;i++) { + if(list != i) { + if (i==SUCCESS) strcpy(prefix, "+"); + if (i==FAILURE) strcpy(prefix, "-"); + for (j=0;j<MAXEVENT && j<lists[i].count;j++) { + if (lists[i].on[j] != -1) { + if ((stringcopy(auditstring, prefix, 0)) == -1) + retstat = -1; + if (length == 1 && + retstat == 0) { + if ((stringcopy(auditstring, + event_class[lists[i].on[j]].event_lname, 1))==-1) + retstat = -1; + } else if (retstat == 0) { + if ((stringcopy(auditstring, + event_class[lists[i].on[j]].event_sname, 1))==-1) + retstat = -1; + } + } + } + } + } + } + if ((stringcopy(auditstring, "\0", 2)) == -1) + retstat = -1; + + return (retstat); +} + +static stringcopy(auditstring, event, flag) + char *auditstring; + char *event; + int flag; /* if set, output comma after event */ +{ + int retstat = 0; + + /* + * check size + */ + if (pos >= MAXSTRLEN) { + fprintf(stderr,"getauditflagschar: Inputted buffer too small.\n"); + retstat = -1; + } else if (flag != 2) { + strcpy(auditstring+pos, event); + pos += strlen(event); + if(flag) { + strcpy(auditstring+pos, COMMASTR); + pos += strlen(COMMASTR); + } + } else { + /* + * add null terminator only + */ + if (pos) + strcpy(auditstring+(pos-1), event); + + } + return (retstat); +} + +/* + * getauditflagsbin() - converts character string to success and + * failure bit masks + * + * input: auditstring - audit string + * cnt - number of elements in the masks array + * + * output: masks->as_success - audit on success + * masks->as_failure - audit on failure + * + * returns: 0 - ok + * -1 - error - string contains characters which do + * not match event flag names + */ + +getauditflagsbin(auditstring, masks) + char *auditstring; + audit_state_t *masks; +{ + int i, gotone, done = 0, invert = 0, tryagain; + int retstat = 0, succ_event, fail_event; + char *ptr, tmp_buff[MAXFLDLEN]; + + /* + * process character string + */ + do { + gotone = 0; + /* + * read through string storing chars. until a comma + */ + for (ptr=tmp_buff; !gotone;) { + if(*auditstring!=COMMA && *auditstring!='\0' && + *auditstring!='\n' && *auditstring!=' ') + *ptr++ = *auditstring++; + else if (*auditstring == ' ') + *auditstring++; + else { + if (*auditstring == '\0' || + *auditstring == '\n') { + done = 1; + if (ptr == tmp_buff) + done = 2; + } + gotone = 1; + } + } + /* + * process audit state + */ + if(gotone && done != 2) { + if(!done) auditstring++; + *ptr++ = '\0'; + ptr = tmp_buff; + gotone = 0; + succ_event = ON; + fail_event = ON; + tryagain = 1; + invert = 0; + + /* + * get flags + */ + do { + switch (*ptr++) { + case '^': + invert = 1; + succ_event = OFF; + fail_event = OFF; + break; + case '+': + if (invert) + fail_event = OK; + else { + succ_event = ON; + fail_event = OK; + } + break; + case '-': + if (invert) + succ_event = OK; + else { + fail_event = ON; + succ_event = OK; + } + break; + default: + tryagain = 0; + ptr--; + break; + } + } while(tryagain); + + /* add audit state to mask */ + for (i=0;i<MAXEVENT+1 && !gotone;i++) { + if ((!(strcmp(ptr, event_class[i].event_sname))) || + (!(strcmp(ptr, event_class[i].event_lname)))) { + if (succ_event == ON) + masks->as_success |= event_class[i].event_mask; + else if (succ_event == OFF) + masks->as_success &= ~(event_class[i].event_mask); + if (fail_event == ON) + masks->as_failure |= event_class[i].event_mask; + else if (fail_event == OFF) + masks->as_failure &= ~(event_class[i].event_mask); + gotone = 1; + } + } + if(!gotone) { + retstat = -1; + done = 1; + } + } + } while (!done); + + return (retstat); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getauid.c b/usr/src/lib/libbc/libc/gen/common/getauid.c new file mode 100644 index 0000000000..8dc4df8cc2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getauid.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +getauid(void) +{ + return (0); +} + +int +setauid(int auid) +{ + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getcwd.c b/usr/src/lib/libbc/libc/gen/common/getcwd.c new file mode 100644 index 0000000000..3f3f46b067 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getcwd.c @@ -0,0 +1,80 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Library routine to GET the Current Working Directory. + * arg1 is a pointer to a character buffer into which the + * path name of the current directory is placed by the + * subroutine. arg1 may be zero, in which case the + * subroutine will call malloc to get the required space. + * arg2 is the length of the buffer space for the path-name. + * If the actual path-name is longer than (arg2-2), or if + * the value of arg2 is not at least 3, the subroutine will + * return a value of zero, with errno set as appropriate. + */ + +#include <stdio.h> +#include <sys/errno.h> + +extern FILE *popen(); +extern char *malloc(), *fgets(), *strchr(); +extern int errno, pclose(); + +char * +getcwd(arg1, arg2) +char *arg1; +int arg2; +{ + FILE *pipe; + char *trm; + + if(arg2 <= 0) { + errno = EINVAL; + return(0); + } + if(arg1 == 0) + if((arg1 = malloc((unsigned)arg2)) == 0) { + errno = ENOMEM; + return(0); + } + errno = 0; + if((pipe = popen("pwd", "r")) == 0) + return(0); + (void) fgets(arg1, arg2, pipe); + (void) pclose(pipe); + trm = strchr(arg1, '\0'); + if(*(trm-1) != '\n') { + errno = ERANGE; + return(0); + } + *(trm-1) = '\0'; + return(arg1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getenv.c b/usr/src/lib/libbc/libc/gen/common/getenv.c new file mode 100644 index 0000000000..e6c4fb2062 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getenv.c @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * getenv(name) + * returns ptr to value associated with name, if any, else NULL + */ +#define NULL 0 +extern char **environ; +static char *nvmatch(); + +char * +getenv(name) +register char *name; +{ + register char *v, **p=environ; + + if(p == NULL) + return(NULL); + while(*p != NULL) + if((v = nvmatch(name, *p++)) != NULL) + return(v); + return(NULL); +} + +/* + * s1 is either name, or name=value + * s2 is name=value + * if names match, return value of s2, else NULL + * used for environment searching: see getenv + */ + +static char * +nvmatch(s1, s2) +register char *s1, *s2; +{ + while(*s1 == *s2++) + if(*s1++ == '=') + return(s2); + if(*s1 == '\0' && *(s2-1) == '=') + return(s2); + return(NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getfaudflgs.c b/usr/src/lib/libbc/libc/gen/common/getfaudflgs.c new file mode 100644 index 0000000000..aecf952377 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getfaudflgs.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* c2 secure */ + +#include <sys/types.h> +#include <sys/label.h> +#include <sys/audit.h> + +#define MAXSTRLEN 360 + +/* getfaudflgs.c */ + +/* + * getfauditflags() - combines system event flag mask with user event + * flag masks. + * + * input: usremasks->as_success - always audit on success + * usremasks->as_failure - always audit on failure + * usrdmasks->as_success - never audit on success + * usrdmasks->as_failure - never audit on failure + * + * output: lastmasks->as_success - audit on success + * lastmasks->as_failure - audit on failure + * + * returns: 0 - ok + * -1 - error + */ + +getfauditflags(usremasks, usrdmasks, lastmasks) +audit_state_t *usremasks; +audit_state_t *usrdmasks; +audit_state_t *lastmasks; +{ + int len = MAXSTRLEN, retstat = 0; + char s_auditstring[MAXSTRLEN]; + audit_state_t masks; + + masks.as_success = 0; + masks.as_failure = 0; + /* + * get system audit mask and convert to bit mask + */ + if ((getacflg(s_auditstring, len)) >= 0) { + if ((getauditflagsbin(s_auditstring, &masks)) != 0) + retstat = -1; + } else + retstat = -1; + + /* + * combine system and user event masks + */ + if (retstat == 0) { + lastmasks->as_success = masks.as_success; + lastmasks->as_failure = masks.as_failure; + + lastmasks->as_success |= usremasks->as_success; + lastmasks->as_failure |= usremasks->as_failure; + + lastmasks->as_success &= ~(usrdmasks->as_success); + lastmasks->as_failure &= ~(usrdmasks->as_failure); + } + return (retstat); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getgraent.c b/usr/src/lib/libbc/libc/gen/common/getgraent.c new file mode 100644 index 0000000000..f8c3637c51 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getgraent.c @@ -0,0 +1,483 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <stdio.h> +#include <grp.h> +#include <grpadj.h> +#include <rpcsvc/ypclnt.h> + +extern void rewind(); +extern long strtol(); +extern int strlen(); +extern int strcmp(); +extern int fclose(); +extern char *strcpy(); +extern char *calloc(); +extern char *malloc(); + +void setgraent(), endgraent(); + +static struct gradata { + char *domain; + FILE *grfa; + char *yp; + int yplen; + char *oldyp; + int oldyplen; + struct list { + char *name; + struct list *nxt; + } *minuslist; /* list of - items */ + struct group_adjunct interpgra; + char interpline[BUFSIZ+1]; + struct group_adjunct *sv; +} *gradata, *_gradata(); + +static char *GROUPADJ = "/etc/security/group.adjunct"; +static struct group_adjunct *interpret(); +static struct group_adjunct *interpretwithsave(); +static struct group_adjunct *save(); +static struct group_adjunct *getnamefromyellow(); +static struct group_adjunct *getgidfromyellow(); + +static struct gradata * +_gradata() +{ + register struct gradata *g = gradata; + + if (g == 0) { + g = (struct gradata *)calloc(1, sizeof (struct gradata)); + gradata = g; + } + return (g); +} + +#ifdef NOT_DEFINED +struct group_adjunct * +getgragid(gid) +register gid; +{ + struct group *getgrgid(); + struct group *gr; + + if ((gr = getgrgid(gid)) == NULL) + return NULL; + return (getgranam(gr->gr_name)); +} +#endif NOT_DEFINED + +struct group_adjunct * +getgranam(name) +register char *name; +{ + register struct gradata *g = _gradata(); + struct group_adjunct *gra; + char line[BUFSIZ+1]; + + setgraent(); + if (g == 0) + return (0); + if (!g->grfa) + return NULL; + while (fgets(line, BUFSIZ, g->grfa) != NULL) { + if ((gra = interpret(line, strlen(line))) == NULL) + continue; + if (matchname(line, &gra, name)) { + endgraent(); + return (gra); + } + } + endgraent(); + return (NULL); +} + +void +setgraent() +{ + register struct gradata *g = _gradata(); + + if (g == NULL) + return; + if (g->domain == NULL) + (void) yp_get_default_domain(&g->domain); + if (!g->grfa) + g->grfa = fopen(GROUPADJ, "r"); + else + rewind(g->grfa); + if (g->yp) + free(g->yp); + g->yp = NULL; + freeminuslist(); +} + +void +endgraent() +{ + register struct gradata *g = _gradata(); + + if (g == 0) + return; + if (g->grfa) { + (void) fclose(g->grfa); + g->grfa = NULL; + } + if (g->yp) + free(g->yp); + g->yp = NULL; + freeminuslist(); +} + +struct group_adjunct * +fgetgraent(f) + FILE *f; +{ + char line1[BUFSIZ+1]; + + if(fgets(line1, BUFSIZ, f) == NULL) + return(NULL); + return (interpret(line1, strlen(line1))); +} + +static char * +grskip(p,c) + register char *p; + register c; +{ + while(*p && *p != c && *p != '\n') ++p; + if (*p == '\n') + *p = '\0'; + else if (*p != '\0') + *p++ = '\0'; + return(p); +} + +struct group_adjunct * +getgraent() +{ + register struct gradata *g = _gradata(); + char line1[BUFSIZ+1]; + static struct group_adjunct *savegra; + struct group_adjunct *gra; + + if (g == 0) + return (0); + if (g->domain == NULL) { + (void) yp_get_default_domain(&g->domain); + } + if(!g->grfa && !(g->grfa = fopen(GROUPADJ, "r"))) + return(NULL); + again: + if (g->yp) { + gra = interpretwithsave(g->yp, g->yplen, savegra); + free(g->yp); + if (gra == NULL) + return(NULL); + getnextfromyellow(); + if (onminuslist(gra)) + goto again; + else + return (gra); + } + else if (fgets(line1, BUFSIZ, g->grfa) == NULL) + return(NULL); + if ((gra = interpret(line1, strlen(line1))) == NULL) + return(NULL); + switch(line1[0]) { + case '+': + if (strcmp(gra->gra_name, "+") == 0) { + getfirstfromyellow(); + savegra = save(gra); + goto again; + } + /* + * else look up this entry in NIS + */ + savegra = save(gra); + gra = getnamefromyellow(gra->gra_name+1, savegra); + if (gra == NULL) + goto again; + else if (onminuslist(gra)) + goto again; + else + return (gra); + break; + case '-': + addtominuslist(gra->gra_name+1); + goto again; + break; + default: + if (onminuslist(gra)) + goto again; + return (gra); + break; + } + /*NOTREACHED*/ +} + +static struct group_adjunct * +interpret(val, len) + char *val; +{ + register struct gradata *g = _gradata(); + register char *p; + + if (g == 0) + return (0); + strncpy(g->interpline, val, len); + p = g->interpline; + g->interpline[len] = '\n'; + g->interpline[len+1] = 0; + g->interpgra.gra_name = p; + p = grskip(p,':'); + if (strcmp(g->interpgra.gra_name, "+") == 0) { + /* we are going to the NIS - fix the + * rest of the struct as much as is needed + */ + g->interpgra.gra_passwd = ""; + return (&g->interpgra); + } + g->interpgra.gra_passwd = p; + while(*p && *p != '\n') p++; + *p = '\0'; + return (&g->interpgra); +} + +static +freeminuslist() { + register struct gradata *g = _gradata(); + struct list *ls; + + if (g == 0) + return; + for (ls = g->minuslist; ls != NULL; ls = ls->nxt) { + free(ls->name); + free(ls); + } + g->minuslist = NULL; +} + +static struct group_adjunct * +interpretwithsave(val, len, savegra) + char *val; + struct group_adjunct *savegra; +{ + register struct gradata *g = _gradata(); + struct group_adjunct *gra; + + if (g == 0) + return (0); + if ((gra = interpret(val, len)) == NULL) + return (NULL); + if (savegra->gra_passwd && *savegra->gra_passwd) + gra->gra_passwd = savegra->gra_passwd; + return (gra); +} + +static +onminuslist(gra) + struct group_adjunct *gra; +{ + register struct gradata *g = _gradata(); + struct list *ls; + register char *nm; + + if (g == 0) + return 0; + nm = gra->gra_name; + for (ls = g->minuslist; ls != NULL; ls = ls->nxt) + if (strcmp(ls->name, nm) == 0) + return 1; + return 0; +} + +static +getnextfromyellow() +{ + register struct gradata *g = _gradata(); + int reason; + char *key = NULL; + int keylen; + + if (g == 0) + return; + if (reason = yp_next(g->domain, "group.adjunct.byname", + g->oldyp, g->oldyplen, &key, &keylen, + &g->yp, &g->yplen)) { +#ifdef DEBUG +fprintf(stderr, "reason yp_next failed is %d\n", reason); +#endif + g->yp = NULL; + } + if (g->oldyp) + free(g->oldyp); + g->oldyp = key; + g->oldyplen = keylen; +} + +static +getfirstfromyellow() +{ + register struct gradata *g = _gradata(); + int reason; + char *key = NULL; + int keylen; + + if (g == 0) + return; + if (reason = yp_first(g->domain, "group.adjunct.byname", + &key, &keylen, &g->yp, &g->yplen)) { +#ifdef DEBUG +fprintf(stderr, "reason yp_first failed is %d\n", reason); +#endif + g->yp = NULL; + } + if (g->oldyp) + free(g->oldyp); + g->oldyp = key; + g->oldyplen = keylen; +} + +static struct group_adjunct * +getnamefromyellow(name, savegra) + char *name; + struct group_adjunct *savegra; +{ + register struct gradata *g = _gradata(); + struct group_adjunct *gra; + int reason; + char *val; + int vallen; + + if (g == 0) + return (NULL); + if (reason = yp_match(g->domain, "group.adjunct.byname", + name, strlen(name), &val, &vallen)) { +#ifdef DEBUG +fprintf(stderr, "reason yp_next failed is %d\n", reason); +#endif + return NULL; + } + else { + gra = interpret(val, vallen); + free(val); + if (gra == NULL) + return NULL; + if (savegra->gra_passwd && *savegra->gra_passwd) + gra->gra_passwd = savegra->gra_passwd; + return gra; + } +} + +static +addtominuslist(name) + char *name; +{ + register struct gradata *g = _gradata(); + struct list *ls; + char *buf; + + if (g == 0) + return; + ls = (struct list *)malloc(sizeof(struct list)); + buf = (char *)malloc(strlen(name) + 1); + (void) strcpy(buf, name); + ls->name = buf; + ls->nxt = g->minuslist; + g->minuslist = ls; +} + +/* + * save away psswd field, which is the only + * one which can be specified in a local + entry to override the + * value in the NIS + */ +static struct group_adjunct * +save(gra) + struct group_adjunct *gra; +{ + register struct gradata *g = _gradata(); + + if (g == 0) + return 0; + /* + * free up stuff from last time around + */ + if (g->sv) { + free(g->sv->gra_passwd); + free(g->sv); + } + g->sv = (struct group_adjunct *)calloc(1, sizeof(struct group_adjunct)); + g->sv->gra_passwd = (char *)malloc(strlen(gra->gra_passwd) + 1); + (void) strcpy(g->sv->gra_passwd, gra->gra_passwd); + return g->sv; +} + +static +matchname(line1, grap, name) + char line1[]; + struct group_adjunct **grap; + char *name; +{ + struct group_adjunct *savegra; + struct group_adjunct *gra = *grap; + + switch(line1[0]) { + case '+': + if (strcmp(gra->gra_name, "+") == 0) { + savegra = save(gra); + gra = getnamefromyellow(name, savegra); + if (gra) { + *grap = gra; + return 1; + } + else + return 0; + } + if (strcmp(gra->gra_name+1, name) == 0) { + savegra = save(gra); + gra = getnamefromyellow(gra->gra_name+1, savegra); + if (gra) { + *grap = gra; + return 1; + } + else + return 0; + } + break; + case '-': + if (strcmp(gra->gra_name+1, name) == 0) { + *grap = NULL; + return 1; + } + break; + default: + if (strcmp(gra->gra_name, name) == 0) + return 1; + } + return 0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/getlogin.c b/usr/src/lib/libbc/libc/gen/common/getlogin.c new file mode 100644 index 0000000000..d5c0dd2baf --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getlogin.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1992 by Sun Microsystems, Inc. + */ + +#include <pwd.h> +#include <stdio.h> + +char * +getlogin() +{ + char *lgn; + + if ((lgn = (char *)_getlogin()) == NULL) { + struct passwd *pwd; + if ((pwd = (struct passwd *)_getpwuid(_getuid())) != NULL) + return (pwd->pw_name); + } + return (lgn); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getopt.c b/usr/src/lib/libbc/libc/gen/common/getopt.c new file mode 100644 index 0000000000..e15aee926b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getopt.c @@ -0,0 +1,106 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from 4.3BSD-tahoe 4.9 6/23/89 */ + +/* + * Copyright (c) 1989 Sun Microsystems, Inc. + */ +/* + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +/* LINTLIBRARY */ + +#include <stdio.h> +#include <string.h> + +/* + * get option letter from argument vector + */ +/* See lib/libc/gen/common/optind.c for next 3 definitions. */ +extern char *optarg; /* argument associated with option */ +extern int opterr; /* if error message should be printed */ +extern int optind; /* index into parent argv vector */ +int optopt; /* character checked for validity */ + + +#define BADCH (int)'?' +#define EMSG "" + +getopt(nargc, nargv, ostr) + int nargc; + char **nargv, *ostr; +{ + static char *place = EMSG; /* option letter processing */ + register char *oli; /* option letter list index */ + char *p; + + if (!*place) { /* update scanning pointer */ + if (optind >= nargc || *(place = nargv[optind]) != '-') { + place = EMSG; + return (EOF); + } + if (place[1] && *++place == '-') { /* found "--" */ + ++optind; + place = EMSG; + return (EOF); + } + } /* option letter okay? */ + if ((optopt = (int)*place++) == (int)':' || + !(oli = strchr(ostr, optopt))) { + + /* + * For backwards compatibility: don't treat '-' as an + * option letter unless caller explicitly asked for it. + */ + if (optopt == (int)'-') + return (EOF); + if (!*place) + ++optind; + if (opterr) { + if (!(p = strrchr(*nargv, '/'))) + p = *nargv; + else + ++p; + (void)fprintf(stderr, "%s: illegal option -- %c\n", + p, optopt); + } + return (BADCH); + } + if (*++oli != ':') { /* don't need argument */ + optarg = NULL; + if (!*place) + ++optind; + } else { /* need an argument */ + if (*place) /* no white space */ + optarg = place; + else if (nargc <= ++optind) { /* no arg */ + place = EMSG; + if (!(p = strrchr(*nargv, '/'))) + p = *nargv; + else + ++p; + if (opterr) + (void)fprintf(stderr, + "%s: option requires an argument -- %c\n", + p, optopt); + return (BADCH); + } else /* white space */ + optarg = nargv[optind]; + place = EMSG; + ++optind; + } + return (optopt); /* dump back option letter */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/getpass.c b/usr/src/lib/libbc/libc/gen/common/getpass.c new file mode 100644 index 0000000000..c651662f31 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getpass.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R3 1.10 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <signal.h> +#include <termios.h> + +extern void setbuf(); +extern FILE *fopen(); +extern int fclose(), fprintf(), findiop(); +extern int kill(), ioctl(), getpid(); +static int intrupt; + +#define MAXPASSWD 8 /* max significant characters in password */ + +char * +getpass(prompt) +char *prompt; +{ + struct termios ttyb; + unsigned long flags; + register char *p; + register int c; + FILE *fi; + static char pbuf[ MAXPASSWD + 1 ]; + struct sigvec osv, sv; + void catch(); + + if((fi = fopen("/dev/tty", "r")) == NULL) +#ifdef S5EMUL + return((char*)NULL); +#else + fi = stdin; +#endif + else + setbuf(fi, (char*)NULL); + sv.sv_handler = catch; + sv.sv_mask = 0; + sv.sv_flags = SV_INTERRUPT; + (void) sigvec(SIGINT, &sv, &osv); + intrupt = 0; + (void) ioctl(fileno(fi), TCGETS, &ttyb); + flags = ttyb.c_lflag; + ttyb.c_lflag &= ~(ECHO | ECHOE | ECHOK | ECHONL); + (void) ioctl(fileno(fi), TCSETSF, &ttyb); + (void) fputs(prompt, stderr); + p = pbuf; + while( !intrupt && + (c = getc(fi)) != '\n' && c != '\r' && c != EOF ) { + if(p < &pbuf[ MAXPASSWD ]) + *p++ = c; + } + *p = '\0'; + ttyb.c_lflag = flags; + (void) ioctl(fileno(fi), TCSETSW, &ttyb); + (void) putc('\n', stderr); + (void) sigvec(SIGINT, &osv, (struct sigvec *)NULL); + if(fi != stdin) + (void) fclose(fi); +#ifdef S5EMUL /* XXX - BOTH versions should probably do this! */ + if(intrupt) + (void) kill(getpid(), SIGINT); +#endif + return(pbuf); +} + +static void +catch() +{ + ++intrupt; +} diff --git a/usr/src/lib/libbc/libc/gen/common/getpwaent.c b/usr/src/lib/libbc/libc/gen/common/getpwaent.c new file mode 100644 index 0000000000..050adc74a3 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getpwaent.c @@ -0,0 +1,586 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + + +#include <stdio.h> +#include <sys/types.h> +#include <sys/label.h> +#include <sys/audit.h> +#include <pwdadj.h> +#include <pwd.h> +#include <rpcsvc/ypclnt.h> + +extern void rewind(); +extern long strtol(); +extern int strcmp(); +extern int strlen(); +extern int fclose(); +extern char *strcpy(); +extern char *strncpy(); +extern char *calloc(); +extern char *malloc(); + +void setpwaent(), endpwaent(); + +static struct _pwajunk { + struct passwd _NULLPW; + FILE *_pwfadj; + char *_yp; + int _yplen; + char *_oldyp; + int _oldyplen; + struct list { + char *name; + struct list *nxt; + } *_minuslist; + struct passwd _interppasswd; + struct passwd_adjunct _apwadj; + char _interpline[BUFSIZ+1]; + char *_domain; +} *__pwajunk, *_pwajunk(); + +#define NULLPW (_pwa->_NULLPW) +#define pwfadj (_pwa->_pwfadj) +#define yp (_pwa->_yp) +#define yplen (_pwa->_yplen) +#define oldyp (_pwa->_oldyp) +#define oldyplen (_pwa->_oldyplen) +#define minuslist (_pwa->_minuslist) +#define interppasswd (_pwa->_interppasswd) +#define apwadj (_pwa->_apwadj) +#define interpline (_pwa->_interpline) +#define domain (_pwa->_domain) + +static char *PASSWDADJ = "/etc/security/passwd.adjunct"; + +static struct passwd_adjunct *interpret(); +static struct passwd_adjunct *interpretwithsave(); +static struct passwd_adjunct *save(); +static struct passwd_adjunct *getnamefromyellow(); + +static struct _pwajunk * +_pwajunk() +{ + + if (__pwajunk == 0) + __pwajunk = (struct _pwajunk *)calloc(1, sizeof (*__pwajunk)); + return (__pwajunk); +} + +struct passwd_adjunct * +getpwanam(name) + register char *name; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct passwd_adjunct *pwadj; + char line[BUFSIZ+1]; + + if (_pwa == 0) + return (0); + setpwaent(); + if (!pwfadj) + return NULL; + while (fgets(line, BUFSIZ, pwfadj) != NULL) { + if ((pwadj = interpret(line, strlen(line))) == NULL) + continue; + if (matchname(line, &pwadj, name)) { + endpwaent(); + return pwadj; + } + } + endpwaent(); + return NULL; +} + +#ifdef NOT_INCLUDED +struct passwd_adjunct * +getpwauid(uid) + register uid; +{ + register struct _pwajunk *_pwa = _pwajunk(); + /* + * provided for consistency even though there is no uid in + * the adjunct file. + */ + struct passwd *getpwuid(); + struct passwd *pw; + + if (_pwa == 0) + return (0); + if ((pw = getpwuid(uid)) == NULL) + return NULL; + return (getpwanam(pw->pw_name)); +} +#endif NOT_INCLUDED + + + + +void +setpwaent() +{ + register struct _pwajunk *_pwa = _pwajunk(); + + if (_pwa == 0) + return; + if (domain == NULL) { + (void) yp_get_default_domain(&domain ); + } + if (pwfadj == NULL) + pwfadj = fopen(PASSWDADJ, "r"); + else + rewind(pwfadj); + if (yp) + free(yp); + yp = NULL; + freeminuslist(); +} + + + +void +endpwaent() +{ + register struct _pwajunk *_pwa = _pwajunk(); + + if (_pwa == 0) + return; + if (pwfadj != NULL) { + (void) fclose(pwfadj); + pwfadj = NULL; + } + if (yp) + free(yp); + yp = NULL; + freeminuslist(); + endnetgrent(); +} + + + +struct passwd_adjunct * +getpwaent() +{ + register struct _pwajunk *_pwa = _pwajunk(); + char line[BUFSIZ+1]; + static struct passwd_adjunct *savepwadj; + struct passwd_adjunct *pwadj; + char *user; + char *mach; + char *dom; + + if (_pwa == 0) + return (0); + if (domain == NULL) { + (void) yp_get_default_domain(&domain ); + } + if (pwfadj == NULL && (pwfadj = fopen(PASSWDADJ, "r")) == NULL) { + return (NULL); + } + + for (;;) { + if (yp) { + pwadj = interpretwithsave(yp, yplen, savepwadj); + free(yp); + if (pwadj == NULL) + return(NULL); + getnextfromyellow(); + if (!onminuslist(pwadj)) { + return(pwadj); + } + } else if (getnetgrent(&mach,&user,&dom)) { + if (user) { + pwadj = getnamefromyellow(user, savepwadj); + if (pwadj != NULL && !onminuslist(pwadj)) { + return(pwadj); + } + } + } else { + endnetgrent(); + if (fgets(line, BUFSIZ, pwfadj) == NULL) { + return(NULL); + } + if ((pwadj = interpret(line, strlen(line))) == NULL) + return(NULL); + switch(line[0]) { + case '+': + if (strcmp(pwadj->pwa_name, "+") == 0) { + getfirstfromyellow(); + savepwadj = save(pwadj); + } else if (line[1] == '@') { + savepwadj = save(pwadj); + if (innetgr(pwadj->pwa_name+2,(char *) NULL,"*",domain)) { + /* include the whole NIS database */ + getfirstfromyellow(); + } else { + setnetgrent(pwadj->pwa_name+2); + } + } else { + /* + * else look up this entry in NIS + */ + savepwadj = save(pwadj); + pwadj = getnamefromyellow(pwadj->pwa_name+1, savepwadj); + if (pwadj != NULL && !onminuslist(pwadj)) { + return(pwadj); + } + } + break; + case '-': + if (line[1] == '@') { + if (innetgr(pwadj->pwa_name+2,(char *) NULL,"*",domain)) { + /* everybody was subtracted */ + return(NULL); + } + setnetgrent(pwadj->pwa_name+2); + while (getnetgrent(&mach,&user,&dom)) { + if (user) { + addtominuslist(user); + } + } + endnetgrent(); + } else { + addtominuslist(pwadj->pwa_name+1); + } + break; + default: + if (!onminuslist(pwadj)) { + return(pwadj); + } + break; + } + } + } +} + +static +matchname(line1, pwadjp, name) + char line1[]; + struct passwd_adjunct **pwadjp; + char *name; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct passwd_adjunct *savepwadj; + struct passwd_adjunct *pwadj = *pwadjp; + + if (_pwa == 0) + return (0); + switch(line1[0]) { + case '+': + if (strcmp(pwadj->pwa_name, "+") == 0) { + savepwadj = save(pwadj); + pwadj = getnamefromyellow(name, savepwadj); + if (pwadj) { + *pwadjp = pwadj; + return 1; + } + else + return 0; + } + if (line1[1] == '@') { + if (innetgr(pwadj->pwa_name+2,(char *) NULL,name,domain)) { + savepwadj = save(pwadj); + pwadj = getnamefromyellow(name,savepwadj); + if (pwadj) { + *pwadjp = pwadj; + return 1; + } + } + return 0; + } + if (strcmp(pwadj->pwa_name+1, name) == 0) { + savepwadj = save(pwadj); + pwadj = getnamefromyellow(pwadj->pwa_name+1, savepwadj); + if (pwadj) { + *pwadjp = pwadj; + return 1; + } + else + return 0; + } + break; + case '-': + if (line1[1] == '@') { + if (innetgr(pwadj->pwa_name+2,(char *) NULL,name,domain)) { + *pwadjp = NULL; + return 1; + } + } + else if (strcmp(pwadj->pwa_name+1, name) == 0) { + *pwadjp = NULL; + return 1; + } + break; + default: + if (strcmp(pwadj->pwa_name, name) == 0) + return 1; + } + return 0; +} + +static +getnextfromyellow() +{ + register struct _pwajunk *_pwa = _pwajunk(); + int reason; + char *key; + int keylen; + + if (_pwa == 0) + return; + reason = yp_next(domain, "passwd_adjunct",oldyp, oldyplen, &key + ,&keylen,&yp,&yplen); + if (reason) { +#ifdef DEBUG +fprintf(stderr, "reason yp_next failed is %d\n", reason); +#endif + yp = NULL; + } + if (oldyp) + free(oldyp); + oldyp = key; + oldyplen = keylen; +} + +static +getfirstfromyellow() +{ + register struct _pwajunk *_pwa = _pwajunk(); + int reason; + char *key; + int keylen; + + if (_pwa == 0) + return; + reason = yp_first(domain, "passwd_adjunct", &key, &keylen, &yp, &yplen); + if (reason) { +#ifdef DEBUG +fprintf(stderr, "reason yp_first failed is %d\n", reason); +#endif + yp = NULL; + } + if (oldyp) + free(oldyp); + oldyp = key; + oldyplen = keylen; +} + +static struct passwd_adjunct * +getnamefromyellow(name, savepwadj) + char *name; + struct passwd_adjunct *savepwadj; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct passwd_adjunct *pwadj; + int reason; + char *val; + int vallen; + + if (_pwa == 0) + return (0); + reason = yp_match(domain, "passwd.adjunct.byname", name, strlen(name) + , &val, &vallen); + if (reason) { +#ifdef DEBUG +fprintf(stderr, "reason yp_match failed is %d\n", reason); +#endif + return NULL; + } else { + pwadj = interpret(val, vallen); + free(val); + if (pwadj == NULL) + return NULL; + if (savepwadj->pwa_passwd && *savepwadj->pwa_passwd) + pwadj->pwa_passwd = savepwadj->pwa_passwd; + return pwadj; + } +} + +static struct passwd_adjunct * +interpretwithsave(val, len, savepwadj) + char *val; + struct passwd_adjunct *savepwadj; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct passwd_adjunct *pwadj; + + if (_pwa == 0) + return (0); + if ((pwadj = interpret(val, len)) == NULL) + return NULL; + if (savepwadj->pwa_passwd && *savepwadj->pwa_passwd) + pwadj->pwa_passwd = savepwadj->pwa_passwd; + return pwadj; +} + +static char * +pwskip(p) + register char *p; +{ + while(*p && *p != ':' && *p != '\n') + ++p; + if (*p == '\n') + *p = '\0'; + else if (*p != '\0') + *p++ = '\0'; + return(p); +} + +static struct passwd_adjunct * +interpret(val, len) + char *val; +{ + register struct _pwajunk *_pwa = _pwajunk(); + register char *p; + char *field; + + if (_pwa == 0) + return (0); + (void) strncpy(interpline, val, len); + p = interpline; + interpline[len] = '\n'; + interpline[len+1] = 0; + + apwadj.pwa_name = p; + p = pwskip(p); + if (strcmp(apwadj.pwa_name, "+") == 0) { + /* we are going to the NIS - fix the + * rest of the struct as much as is needed + */ + apwadj.pwa_passwd = ""; + return (&apwadj); + } + apwadj.pwa_passwd = p; + p = pwskip(p); + field = p; + p = pwskip(p); + labelfromstring(0, field, &apwadj.pwa_minimum); + field = p; + p = pwskip(p); + labelfromstring(0, field, &apwadj.pwa_maximum); + field = p; + p = pwskip(p); + labelfromstring(0, field, &apwadj.pwa_def); + field = p; + p = pwskip(p); + apwadj.pwa_au_always.as_success = 0; + apwadj.pwa_au_always.as_failure = 0; + if (getauditflagsbin(field, &apwadj.pwa_au_always) != 0) + return NULL; + field = p; + (void) pwskip(p); + p = apwadj.pwa_passwd; + while (*p && *p != ',') + p++; + if (*p) + *p = '\0'; + apwadj.pwa_age = p; + apwadj.pwa_au_never.as_success = 0; + apwadj.pwa_au_never.as_failure = 0; + if (getauditflagsbin(field, &apwadj.pwa_au_never) != 0) + return NULL; + return(&apwadj); +} + +static +freeminuslist() { + register struct _pwajunk *_pwa = _pwajunk(); + struct list *ls; + + if (_pwa == 0) + return; + for (ls = minuslist; ls != NULL; ls = ls->nxt) { + free(ls->name); + free((char *) ls); + } + minuslist = NULL; +} + +static +addtominuslist(name) + char *name; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct list *ls; + char *buf; + + if (_pwa == 0) + return; + ls = (struct list *) malloc(sizeof(struct list)); + buf = malloc((unsigned) strlen(name) + 1); + (void) strcpy(buf, name); + ls->name = buf; + ls->nxt = minuslist; + minuslist = ls; +} + +/* + * save away the psswd field, which is the only one which can be + * specified in a local + entry to override the value in the NIS + * for passwd.adjunct + */ +static struct passwd_adjunct * +save(pwadj) + struct passwd_adjunct *pwadj; +{ + register struct _pwajunk *_pwa = _pwajunk(); + static struct passwd_adjunct *sv; + + if (_pwa == 0) + return (0); + /* free up stuff from last call */ + if (sv) { + free(sv->pwa_passwd); + free((char *) sv); + } + sv = (struct passwd_adjunct *) malloc(sizeof(struct passwd_adjunct)); + + sv->pwa_passwd = malloc((unsigned) strlen(pwadj->pwa_passwd) + 1); + (void) strcpy(sv->pwa_passwd, pwadj->pwa_passwd); + + return sv; +} + +static +onminuslist(pwadj) + struct passwd_adjunct *pwadj; +{ + register struct _pwajunk *_pwa = _pwajunk(); + struct list *ls; + register char *nm; + + if (_pwa == 0) + return 0; + nm = pwadj->pwa_name; + for (ls = minuslist; ls != NULL; ls = ls->nxt) { + if (strcmp(ls->name,nm) == 0) { + return(1); + } + } + return(0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getsubopt.c b/usr/src/lib/libbc/libc/gen/common/getsubopt.c new file mode 100644 index 0000000000..c41bcca34b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getsubopt.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* created from scratch */ + +/* + * getsubopt - parse suboptions from a flag argument. + */ +#include <string.h> +#include <stdio.h> + +int +getsubopt(optionsp, tokens, valuep) + char **optionsp; + char *tokens[]; + char **valuep; +{ + register char *s = *optionsp, *p; + register int i, optlen; + + *valuep = NULL; + if (*s == '\0') + return (-1); + p = strchr(s, ','); /* find next option */ + if (p == NULL) { + p = s + strlen(s); + } else { + *p++ = '\0'; /* mark end and point to next */ + } + *optionsp = p; /* point to next option */ + p = strchr(s, '='); /* find value */ + if (p == NULL) { + optlen = strlen(s); + *valuep = NULL; + } else { + optlen = p - s; + *valuep = ++p; + } + for (i = 0; tokens[i] != NULL; i++) { + if ((optlen == strlen(tokens[i])) && + (strncmp(s, tokens[i], optlen) == 0)) + return (i); + } + /* no match, point value at option and return error */ + *valuep = s; + return (-1); +} + diff --git a/usr/src/lib/libbc/libc/gen/common/getttyent.c b/usr/src/lib/libbc/libc/gen/common/getttyent.c new file mode 100644 index 0000000000..b289a77399 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getttyent.c @@ -0,0 +1,162 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.4 5/19/86 */ +/* + * Copyright (c) 1985 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <stdio.h> +#include <strings.h> +#include <ttyent.h> + +static char *TTYFILE = "/etc/ttytab"; +#define LINE 256 +static struct _ttyentjunk { + char zapchar; + FILE *tf; + char line[LINE]; + struct ttyent tty; +} *__ttyentjunk, *_ttyentjunk(); + +static struct _ttyentjunk * +_ttyentjunk() +{ + + if (__ttyentjunk == 0) + __ttyentjunk = (struct _ttyentjunk *)calloc(1, sizeof (struct _ttyentjunk)); + return (__ttyentjunk); +} + +setttyent() +{ + register struct _ttyentjunk *t = _ttyentjunk(); + + if (t == 0) + return; + if (t->tf == NULL) + t->tf = fopen(TTYFILE, "r"); + else + rewind(t->tf); +} + +endttyent() +{ + register struct _ttyentjunk *t = _ttyentjunk(); + + if (t == 0) + return; + if (t->tf != NULL) { + (void) fclose(t->tf); + t->tf = NULL; + } +} + +#define QUOTED 1 + +/* + * Skip over the current field, removing quotes, + * and return a pointer to the next field. + */ +static char * +skip(p) + register char *p; +{ + register struct _ttyentjunk *t = _ttyentjunk(); + register char *cp = p; + register int c; + register int q = 0; + + if (t == 0) + return (0); + for (; (c = *p) != '\0'; p++) { + if (c == '"') { + q ^= QUOTED; /* obscure, but nice */ + continue; + } + if (q == QUOTED && *p == '\\' && *(p+1) == '"') + p++; + *cp++ = *p; + if (q == QUOTED) + continue; + if (c == '#') { + t->zapchar = c; + *p = 0; + break; + } + if (c == '\t' || c == ' ' || c == '\n') { + t->zapchar = c; + *p++ = 0; + while ((c = *p) == '\t' || c == ' ' || c == '\n') + p++; + break; + } + } + *--cp = '\0'; + return (p); +} + +static char * +value(p) + register char *p; +{ + if ((p = index(p,'=')) == 0) + return(NULL); + p++; /* get past the = sign */ + return(p); +} + +struct ttyent * +getttyent() +{ + register struct _ttyentjunk *t = _ttyentjunk(); + register char *p; + register int c; + + if (t == 0) + return (NULL); + if (t->tf == NULL) { + if ((t->tf = fopen(TTYFILE, "r")) == NULL) + return (NULL); + } + do { + p = fgets(t->line, LINE, t->tf); + if (p == NULL) + return (NULL); + while ((c = *p) == '\t' || c == ' ' || c == '\n') + p++; + } while (c == '\0' || c == '#'); + t->zapchar = 0; + t->tty.ty_name = p; + p = skip(p); + t->tty.ty_getty = p; + p = skip(p); + t->tty.ty_type = p; + p = skip(p); + t->tty.ty_status = 0; + t->tty.ty_window = NULL; + for (; *p; p = skip(p)) { +#define space(x) ((c = p[x]) == ' ' || c == '\t' || c == '\n') + if (strncmp(p, "on", 2) == 0 && space(2)) + t->tty.ty_status |= TTY_ON; + else if (strncmp(p, "off", 3) == 0 && space(3)) + t->tty.ty_status &= ~TTY_ON; + else if (strncmp(p, "secure", 6) == 0 && space(6)) + t->tty.ty_status |= TTY_SECURE; + else if (strncmp(p, "local", 5) == 0 && space(5)) + t->tty.ty_status |= TTY_LOCAL; + else if (strncmp(p, "window=", 7) == 0) + t->tty.ty_window = value(p); + else + break; + } + if (t->zapchar == '#' || *p == '#') + while ((c = *++p) == ' ' || c == '\t') + ; + t->tty.ty_comment = p; + if (*p == 0) + t->tty.ty_comment = 0; + if (p = index(p, '\n')) + *p = '\0'; + return(&t->tty); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getttynam.c b/usr/src/lib/libbc/libc/gen/common/getttynam.c new file mode 100644 index 0000000000..b61ba7b1cc --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getttynam.c @@ -0,0 +1,24 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.2 3/9/86 */ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <ttyent.h> + +struct ttyent * +getttynam(tty) + char *tty; +{ + register struct ttyent *t; + + setttyent(); + while (t = getttyent()) { + if (strcmp(tty, t->ty_name) == 0) + break; + } + endttyent(); + return (t); +} diff --git a/usr/src/lib/libbc/libc/gen/common/getusershell.c b/usr/src/lib/libbc/libc/gen/common/getusershell.c new file mode 100644 index 0000000000..f03c328a8d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/getusershell.c @@ -0,0 +1,107 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.4 7/25/86 */ +/* + * Copyright (c) 1985 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/param.h> +#include <sys/file.h> +#include <sys/stat.h> +#include <ctype.h> +#include <stdio.h> + +#define SHELLS "/etc/shells" + +/* + * Do not add local shells here. They should be added in /etc/shells + */ +static char *okshells[] = + { "/bin/sh", "/bin/csh", "/usr/bin/sh", "/usr/bin/csh", 0 }; + +static char **shells, *strings; +static char **curshell; +extern char **initshells(); + +/* + * Get a list of shells from SHELLS, if it exists. + */ +char * +getusershell() +{ + char *ret; + + if (curshell == NULL) + curshell = initshells(); + ret = *curshell; + if (ret != NULL) + curshell++; + return (ret); +} + +endusershell() +{ + + if (shells != NULL) + free((char *)shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + curshell = NULL; +} + +setusershell() +{ + + curshell = initshells(); +} + +static char ** +initshells() +{ + register char **sp, *cp; + register FILE *fp; + struct stat statb; + extern char *malloc(), *calloc(); + + if (shells != NULL) + free((char *)shells); + shells = NULL; + if (strings != NULL) + free(strings); + strings = NULL; + if ((fp = fopen(SHELLS, "r")) == (FILE *)0) + return(okshells); + if (fstat(fileno(fp), &statb) == -1) { + (void)fclose(fp); + return(okshells); + } + if ((strings = malloc((unsigned)statb.st_size + 1)) == NULL) { + (void)fclose(fp); + return(okshells); + } + shells = (char **)calloc((unsigned)statb.st_size / 3, sizeof (char *)); + if (shells == NULL) { + (void)fclose(fp); + free(strings); + strings = NULL; + return(okshells); + } + sp = shells; + cp = strings; + while (fgets(cp, MAXPATHLEN + 1, fp) != NULL) { + while (*cp != '#' && *cp != '/' && *cp != '\0') + cp++; + if (*cp == '#' || *cp == '\0') + continue; + *sp++ = cp; + while (!isspace(*cp) && *cp != '#' && *cp != '\0') + cp++; + *cp++ = '\0'; + } + *sp = (char *)0; + (void)fclose(fp); + return (shells); +} diff --git a/usr/src/lib/libbc/libc/gen/common/grpauth.c b/usr/src/lib/libbc/libc/gen/common/grpauth.c new file mode 100644 index 0000000000..7c75419c44 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/grpauth.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <stdio.h> +#include <signal.h> +#include <grp.h> +#include <sys/time.h> +#include <errno.h> + +/* + * Version to go in the BCP compatibility library in SVr4 version of + * SunOS. This does not bother talking to rpc.pwdauthd or looking for the + * password.adjunct file on the system since they do not exist anymore. + * They have been effectively replaced by a more robust aging security provided + * by the combination of /etc/shadow file, shadow support in the NIS+ + * passwd table and the use of secure RPC in NIS+. + */ + +grpauth(name, password) + char *name; + char *password; +{ + + /* + * this routine authenticates a password for the named user. + * Assumes the adjunct file does not exist. + * and therefore checks the group "source" using the standard + * getgrnam(3C) routine that uses /etc/nsswitch.conf(4). + */ + struct group gr; + struct group *grp; + + if ((grp = getgrnam(name)) == NULL) + /* group is not in main password system */ + return (-1); + gr = *grp; + if (gr.gr_passwd[0] == '#' && gr.gr_passwd[1] == '$') { + /* this means that /etc/group has problems */ + fprintf(stderr, "grpauth: bad group entry for %s\n", + gr.gr_name); + return (-1); + } + if (strcmp(crypt(password, gr.gr_passwd), gr.gr_passwd) == 0) + return (0); + else + return (-1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/hsearch.c b/usr/src/lib/libbc/libc/gen/common/hsearch.c new file mode 100644 index 0000000000..8d96f34554 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/hsearch.c @@ -0,0 +1,523 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1996 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +/* Compile time switches: + + MULT - use a multiplicative hashing function. + DIV - use the remainder mod table size as a hashing function. + CHAINED - use a linked list to resolve collisions. + OPEN - use open addressing to resolve collisions. + BRENT - use Brent's modification to improve the OPEN algorithm. + SORTUP - CHAINED list is sorted in increasing order. + SORTDOWN - CHAINED list is sorted in decreasing order. + START - CHAINED list with entries appended at front. + DRIVER - compile in a main program to drive the tests. + DEBUG - compile some debugging printout statements. + USCR - user supplied comparison routine. +*/ + +#include <stdio.h> +#include <limits.h> + +#define SUCCEED 0 +#define FAIL 1 +#define TRUE 1 +#define FALSE 0 +#define repeat for(;;) +#define until(A) if(A) break; + +#ifdef OPEN +# undef CHAINED +#else +#ifndef CHAINED +# define OPEN +#endif +#endif + +#ifdef MULT +# undef DIV +#else +#ifndef DIV +# define MULT +#endif +#endif + +#ifdef START +# undef SORTUP +# undef SORTDOWN +#else +#ifdef SORTUP +# undef SORTDOWN +#endif +#endif + +#ifdef USCR +# define COMPARE(A, B) (* hcompar)((A), (B)) + extern int (* hcompar)(); +#else +# define COMPARE(A, B) strcmp((A), (B)) +#endif + +#ifdef MULT +# define SHIFT ((bitsper * sizeof(int)) - m) /* Shift factor */ +# define FACTOR 035761254233 /* Magic multiplication factor */ +# define HASH hashm /* Multiplicative hash function */ +# define HASH2 hash2m /* Secondary hash function */ +static unsigned int bitsper; /* Bits per byte */ +static unsigned int hashm(); +static unsigned int hash2m(); +#else +#ifdef DIV +# define HASH hashd /* Division hashing routine */ +# define HASH2(A) 1 /* Secondary hash function */ +static unsigned int hashd(); +#endif +#endif + +typedef enum { + FIND, /* Find, if present */ + ENTER /* Find; enter if not present */ +} ACTION; +typedef char *POINTER; +typedef struct entry { /* Hash table entry */ + POINTER key; + POINTER data; +} ENTRY; + +#ifdef CHAINED +typedef struct node { /* Part of the linked list of entries */ + ENTRY item; + struct node *next; +} NODE; +typedef NODE *TABELEM; +static NODE **table; /* The address of the hash table */ +static ENTRY *build(); +#else +#ifdef OPEN +typedef ENTRY TABELEM; /* What the table contains (TABle ELEMents) */ +static TABELEM *table; /* The address of the hash table */ +static unsigned int count = 0; /* Number of entries in hash table */ +#endif +#endif + +static unsigned int length; /* Size of the hash table */ +static unsigned int m; /* Log base 2 of length */ +static unsigned int prcnt; /* Number of probes this item */ + +extern void free(); +extern int printf(), fprintf(); +extern char *malloc(), *calloc(), *strcpy(); + +int hcreate(); +void hdestroy(); +ENTRY *hsearch(); +static unsigned int crunch(); + +#ifdef DRIVER +static void hdump(); + +main() +{ + char line[80]; /* Room for the input line */ + int i = 0; /* Data generator */ + ENTRY *res; /* Result of hsearch */ + ENTRY *new; /* Test entry */ + + if(hcreate(5)) + printf("Length = %u, m = %u\n", length, m); + else { + fprintf(stderr, "Out of core\n"); + exit(FAIL); + } + + repeat { + hdump(); + printf("Enter a probe: "); + until (EOF == scanf("%s", line)); +#ifdef DEBUG + printf("%s, ", line); + printf("division: %d, ", hashd(line)); + printf("multiplication: %d\n", hashm(line)); +#endif + new = (ENTRY *) malloc(sizeof(ENTRY)); + if(new == NULL) { + fprintf(stderr, "Out of core \n"); + exit(FAIL); + } + else { + new->key = malloc((unsigned) strlen(line) + 1); + if(new->key == NULL) { + fprintf(stderr, "Out of core \n"); + exit(FAIL); + } + strcpy(new->key, line); + new->data = malloc(sizeof(int)); + if(new->data == NULL) { + fprintf(stderr, "Out of core \n"); + exit(FAIL); + } + *new->data = i++; + } + res = hsearch(*new, ENTER); + printf("The number of probes required was %d\n", prcnt); + if(res == (ENTRY *) 0) + printf("Table is full\n"); + else { + printf("Success: "); + printf("Key = %s, Value = %d\n", res->key, *res->data); + } + } + exit(SUCCEED); +} +#endif + +int +hcreate(size) /* Create a hash table no smaller than size */ +int size; /* Minimum size for hash table */ +{ + unsigned int unsize; /* Holds the shifted size */ + + if(size <= 0) + return(FALSE); + + unsize = size; /* +1 for empty table slot; -1 for ceiling */ + length = 1; /* Maximum entries in tabbe */ + m = 0; /* Log2 length */ + while(unsize) { + unsize >>= 1; + length <<= 1; + m++; + } + + table = (TABELEM *) calloc(length, sizeof(TABELEM)); + return(table != NULL); +} + +void +hdestroy() /* Reset the module to its initial state */ +{ + free((POINTER) table); +#ifdef OPEN + count = 0; +#endif +} + +#ifdef OPEN +/* Hash search of a fixed-capacity table. Open addressing used to + resolve collisions. Algorithm modified from Knuth, Volume 3, + section 6.4, algorithm D. Labels flag corresponding actions. +*/ + +ENTRY +*hsearch(item, action) /* Find or insert the item into the table */ +ENTRY item; /* Item to be inserted or found */ +ACTION action; /* FIND or ENTER */ +{ + unsigned int i; /* Insertion index */ + unsigned int c; /* Secondary probe displacement */ + + prcnt = 1; + +/* D1: */ + i = HASH(item.key); /* Primary hash on key */ +#ifdef DEBUG + if(action == ENTER) + printf("hash = %o\n", i); +#endif + +/* D2: */ + if(table[i].key == NULL) /* Empty slot? */ + goto D6; + else if(COMPARE(table[i].key, item.key) == 0) /* Match? */ + return(&table[i]); + +/* D3: */ + c = HASH2(item.key); /* No match => compute secondary hash */ +#ifdef DEBUG + if(action == ENTER) + printf("hash2 = %o\n", c); +#endif + +D4: + i = (i + c) % length; /* Advance to next slot */ + prcnt++; + +/* D5: */ + if(table[i].key == NULL) /* Empty slot? */ + goto D6; + else if(COMPARE(table[i].key, item.key) == 0) /* Match? */ + return(&table[i]); + else + goto D4; + +D6: if(action == FIND) /* Insert if requested */ + return((ENTRY *) NULL); + if(count == (length - 1)) /* Table full? */ + return((ENTRY *) 0); + +#ifdef BRENT +/* Brent's variation of the open addressing algorithm. Do extra + work during insertion to speed retrieval. May require switching + of previously placed items. Adapted from Knuth, Volume 3, section + 4.6 and Brent's article in CACM, volume 10, #2, February 1973. +*/ + + { unsigned int p0 = HASH(item.key); /* First probe index */ + unsigned int c0 = HASH2(item.key); /* Main branch increment */ + unsigned int r = prcnt - 1; /* Current minimum distance */ + unsigned int j; /* Counts along main branch */ + unsigned int k; /* Counts along secondary branch */ + unsigned int curj; /* Current best main branch site */ + unsigned int curpos; /* Current best table index */ + unsigned int pj; /* Main branch indices */ + unsigned int cj; /* Secondary branch increment distance*/ + unsigned int pjk; /* Secondary branch probe indices */ + + if(prcnt >= 3) { + for(j = 0; j < prcnt; j++) { /* Count along main branch */ + pj = (p0 + j * c0) % length; /* New main branch index */ + cj = HASH2(table[pj].key); /* Secondary branch incr. */ + for(k=1; j+k <= r; k++) { /* Count on secondary branch*/ + pjk = (pj + k * cj) % length; /* Secondary probe */ + if(table[pjk].key == NULL) { /* Improvement found */ + r = j + k; /* Decrement upper bound */ + curj = pj; /* Save main probe index */ + curpos = pjk; /* Save secondeary index */ + } + } + } + if(r != prcnt - 1) { /* If an improvement occurred */ + table[curpos] = table[curj]; /* Old key to new site */ +#ifdef DEBUG + printf("Switch curpos = %o, curj = %o, oldi = %o\n", + curj, curpos, i); +#endif + i = curj; + } + } + } +#endif + count++; /* Increment table occupancy count */ + table[i] = item; /* Save item */ + return(&table[i]); /* Address of item is returned */ +} +#endif + +#ifdef USCR +# ifdef DRIVER +static int +compare(a, b) +POINTER a; +POINTER b; +{ + return(strcmp(a, b)); +} + +int (* hcompar)() = compare; +# endif +#endif + +#ifdef CHAINED +# ifdef SORTUP +# define STRCMP(A, B) (COMPARE((A), (B)) > 0) +# else +# ifdef SORTDOWN +# define STRCMP(A, B) (COMPARE((A), (B)) < 0) +# else +# define STRCMP(A, B) (COMPARE((A), (B)) != 0) +# endif +# endif + +ENTRY +*hsearch(item, action) /* Chained search with sorted lists */ +ENTRY item; /* Item to be inserted or found */ +ACTION action; /* FIND or ENTER */ +{ + NODE *p; /* Searches through the linked list */ + NODE **q; /* Where to store the pointer to a new NODE */ + unsigned int i; /* Result of hash */ + int res; /* Result of string comparison */ + + prcnt = 1; + + i = HASH(item.key); /* Table[i] contains list head */ + + if(table[i] == (NODE*)NULL) { /* List has not yet been begun */ + if(action == FIND) + return((ENTRY *) NULL); + else + return(build(&table[i], (NODE *) NULL, item)); + } + else { /* List is not empty */ + q = &table[i]; + p = table[i]; + while(p != NULL && (res = STRCMP(item.key, p->item.key))) { + prcnt++; + q = &(p->next); + p = p->next; + } + + if(p != NULL && res == 0) /* Item has been found */ + return(&(p->item)); + else { /* Item is not yet on list */ + if(action == FIND) + return((ENTRY *) NULL); + else +#ifdef START + return(build(&table[i], table[i], item)); +#else + return(build(q, p, item)); +#endif + } + } +} + +static ENTRY +*build(last, next, item) +NODE **last; /* Where to store in last list item */ +NODE *next; /* Link to next list item */ +ENTRY item; /* Item to be kept in node */ +{ + NODE *p = (NODE *) malloc(sizeof(NODE)); + + if(p != NULL) { + p->item = item; + *last = p; + p->next = next; + return(&(p->item)); + } + else + return(NULL); +} +#endif + +#ifdef DIV +static unsigned int +hashd(key) /* Division hashing scheme */ +POINTER key; /* Key to be hashed */ +{ + return(crunch(key) % length); +} +#else +#ifdef MULT +/* + NOTE: The following algorithm only works on machines where + the results of multiplying two integers is the least + significant part of the double word integer required to hold + the result. It is adapted from Knuth, Volume 3, section 6.4. +*/ + +static unsigned int +hashm(key) /* Multiplication hashing scheme */ +POINTER key; /* Key to be hashed */ +{ + static int first = TRUE; /* TRUE on the first call only */ + + if(first) { /* Compute the number of bits in a byte */ + unsigned char c = UCHAR_MAX; /* A byte full of 1's */ + bitsper = 0; + while(c) { /* Shift until no more 1's */ + c >>= 1; + bitsper++; /* Count number of shifts */ + } + first = FALSE; + } + return((int) (((unsigned) (crunch(key) * FACTOR)) >> SHIFT)); +} + +/* + * Secondary hashing, for use with multiplicitive hashing scheme. + * Adapted from Knuth, Volume 3, section 6.4. + */ + +static unsigned int +hash2m(key) /* Secondary hashing routine */ +POINTER key; /* String to be hashed */ +{ + return((int) (((unsigned) ((crunch(key) * FACTOR) << m) >> SHIFT) | 1)); +} +#endif +#endif + +static unsigned int +crunch(key) /* Convert multicharacter key to unsigned int */ +POINTER key; +{ + unsigned int sum = 0; /* Results */ + int s; /* Length of the key */ + + for(s = 0; *key; s++) /* Simply add up the bytes */ + sum += *key++; + + return(sum + s); +} + +#ifdef DRIVER +static void +hdump() /* Dumps loc, data, probe count, key */ +{ + unsigned int i; /* Counts table slots */ +#ifdef OPEN + unsigned int sum = 0; /* Counts probes */ +#else +#ifdef CHAINED + NODE *a; /* Current Node on list */ +#endif +#endif + + for(i = 0; i < length; i++) +#ifdef OPEN + if(table[i].key == NULL) + printf("%o.\t-,\t-,\t(NULL)\n", i); + else { + unsigned int oldpr = prcnt; /* Save current probe count */ + hsearch(table[i], FIND); + sum += prcnt; + printf("%o.\t%d,\t%d,\t%s\n", i, + *table[i].data, prcnt, table[i].key); + prcnt = oldpr; + } + printf("Total probes = %d\n", sum); +#else +#ifdef CHAINED + if(table[i] == NULL) + printf("%o.\t-,\t-,\t(NULL)\n", i); + else { + printf("%o.", i); + for(a = table[i]; a != NULL; a = a->next) + printf("\t%d,\t%#0.4x,\t%s\n", + *a->item.data, a, a->item.key); + } +#endif +#endif +} +#endif diff --git a/usr/src/lib/libbc/libc/gen/common/ieee_globals.c b/usr/src/lib/libbc/libc/gen/common/ieee_globals.c new file mode 100644 index 0000000000..101eeffa5c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ieee_globals.c @@ -0,0 +1,57 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +/* + * contains definitions for variables for IEEE floating-point arithmetic + * modes; IEEE floating-point arithmetic exception handling; + */ + +#include <floatingpoint.h> + +enum fp_direction_type fp_direction; +/* + * Current rounding direction. Updated by ieee_flags. + */ + +enum fp_precision_type fp_precision; +/* + * Current rounding precision. Updated by ieee_flags. + */ + +sigfpe_handler_type ieee_handlers[N_IEEE_EXCEPTION]; +/* + * Array of pointers to functions to handle SIGFPE's corresponding to IEEE + * fp_exceptions. sigfpe_default means do not generate SIGFPE. An invalid + * address such as sigfpe_abort will cause abort on that SIGFPE. Updated by + * ieee_handler. + */ +fp_exception_field_type fp_accrued_exceptions; +/* + * Sticky accumulated exceptions, updated by ieee_flags. In hardware + * implementations this variable is not automatically updated as the hardware + * changes and should therefore not be relied on directly. + */ diff --git a/usr/src/lib/libbc/libc/gen/common/index.c b/usr/src/lib/libbc/libc/gen/common/index.c new file mode 100644 index 0000000000..9b5e0a5766 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/index.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * Return the ptr in sp at which the character c appears; + * NULL if not found + */ + +#define NULL 0 + +char * +index(sp, c) + register char *sp, c; +{ + + do { + if (*sp == c) + return (sp); + } while (*sp++); + return (NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/isatty.c b/usr/src/lib/libbc/libc/gen/common/isatty.c new file mode 100644 index 0000000000..689f9e5e2a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/isatty.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R3 1.7 */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +/*LINTLIBRARY*/ +/* + * Returns 1 iff file is a tty + */ +#include <sys/termio.h> + +extern int ioctl(); +extern int errno; + +int +isatty(f) +int f; +{ + struct termio tty; + int err ; + + err = errno; + if(ioctl(f, TCGETA, &tty) < 0) + { + errno = err; + return(0); + } + return(1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/iso.multibyte.c b/usr/src/lib/libbc/libc/gen/common/iso.multibyte.c new file mode 100644 index 0000000000..e5ff8c421c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/iso.multibyte.c @@ -0,0 +1,937 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" +#include "iso2022.h" + +#define TO_MULTI 2 +#define TO_SINGLE 1 + +#define BIT7ENV 7 /* 7bit enviornment */ +#define BIT8ENV 8 /* 8bit environment */ +#define NUM_OF_STATES 4 /* G0, G1, G2, G3 */ +#define BIT8(_ch) (_ch & 0x80) +#define MAXSIZE 100 /* ESC LOCK upper lower */ + +#define USE_STATE 0 /* use the actual _state info */ +#define USE_CONTROL 1 /* use C0 or C1 */ +#define USE_SS2 2 /* use Single shift 2 */ +#define USE_SS3 3 /* use Single shift 3 */ + +#define G0MASK 0x0000 +#define G1MASK 0x0080 +#define G2MASK 0x8000 +#define G3MASK 0x8080 +#define FINAL 0x33 /* Temporary final character */ + +#define MMB_CUR_MAX 128 + +/* + * Keep state informations + */ +struct state { + char width; /* 1 or 2 */ + char final; /* final character */ +}; + +static char _my_env = BIT7ENV; /* default 7bits environment */ +static struct state Invoked_G0, Invoked_G1; +static char _currentG0 = G0; +static char _currentG1 = G1; +static struct state _des_states[NUM_OF_STATES] = { + {-1, 0}, {-1, 0}, {-1, 0}, {01, 0} +}; + +int _savestates(); /* save states */ +int _restorestates(); /* restore states */ +int _initializestates();/* Initialize states */ + +/* + * Variables for wc*tomb*() + */ +static char _currentOUT = G0; /* G0, G1, G2 or G3 */ +static prevcsize = 1; + +/* + * mbtowc - subroutine for most iso codeset sequences + */ +int +_mbtowc_iso(pwc, s, n) + wchar_t *pwc; + char *s; + size_t n; +{ + unsigned char ch; + unsigned char tch; /* temporary use */ + unsigned char *us = (unsigned char *)s; + int gen_wide_state = USE_STATE; /* used in gen_wide: */ + int length = 0; + int len = 0; + wchar_t wide; + int mask; + int i; + + isowidth_t * isoinfo = (isowidth_t *) _code_set_info.code_info; + + /* + * initialize _g0_stuff + */ + if (_des_states[G0].width == -1) { + _des_states[G0].width = isoinfo->g0_len; + _des_states[G1].width = isoinfo->g1_len; + _des_states[G2].width = isoinfo->g2_len; + _des_states[G3].width = isoinfo->g3_len; + _my_env = isoinfo->bit_env; + + Invoked_G0 = _des_states[G0]; + Invoked_G1 = _des_states[G1]; + } + + /* + * get character and proceed + */ +loop: + ch = *us++; + if (++length > n) return (-1); /* too long */ + switch (ch) { /* get a character */ + /* escape sequence or locking shifts */ + case ESC: /* escape sequence */ + gen_wide_state = USE_STATE; /* used in gen_wide: */ + ch = *us++; + if (++length > n) return (-1); /* too long */ + switch (ch) { + /* DESIGNATE */ + case 0x24: /* designate */ + ch = *us++; + if (++length > n) return (-1); /* too long */ + switch (ch) { + case 0x28: case 0x29: + case 0x2A: case 0x2B: + case 0x2D: case 0x2E: + case 0x2F: + tch = ch; /* save this to decide _des_state */ + /* Skip intermidiates */ + do { + ch = *us++; + if (++length > n) return (-1); /* too long */ + } while (ch >= 0x20 && ch <= 0x2F); + if (ch < 0x30) /* ch should be a final character */ + return (-1); /* error */ + if (tch == 0x28) + i = G0; + else if (tch == 0x29 || tch == 0x2D) + i = G1; + else if (tch == 0x2A || tch == 0x2E) + i = G2; + else /* (tch == 0x2B || tch == 0x2F) */ + i = G3; + /* updates state info */ + _des_states[i].width = TO_MULTI; + _des_states[i].final = ch; + + goto loop; + break; + default: + /* This is an illegal sequence */ + return (-1); + break; + } + break; + case 0x28: /* designate */ + case 0x29: case 0x2A: case 0x2B: + case 0x2D: case 0x2E: case 0x2F: + tch = ch; /* save this to decide _des_state */ + /* Skip intermidiates */ + do { + ch = *us++; + if (++length > n) return (-1); /* too long */ + } while (ch >= 0x20 && ch <= 0x2F); + if (ch < 0x30) /* ch should be a final character */ + return (-1); /* error */ + if (tch == 0x28) + i = G0; + else if (tch == 0x29 || tch == 0x2D) + i = G1; + else if (tch == 0x2A || tch == 0x2E) + i = G2; + else /* (tch == 0x2B || tch == 0x2F) */ + i = G3; + /* updates state info */ + _des_states[i].width = TO_SINGLE; + _des_states[i].final = ch; + + goto loop; + break; + + /* LOCKING SHIFTS */ + case LS1R: /* locking shift LS1R */; + Invoked_G1 = _des_states[G1]; + _currentG1 = G1; + goto loop; + break; + case LS2: /* locking shift LS2 */ + Invoked_G0 = _des_states[G2]; + _currentG0 = G2; + goto loop; + break; + case LS2R: /* locking shift LS2R */ + Invoked_G1 = _des_states[G2]; + _currentG1 = G2; + goto loop; + break; + case LS3: /* locking shift LS3 */ + Invoked_G0 = _des_states[G3]; + _currentG0 = G3; + goto loop; + break; + case LS3R: /* locking shift LS3R */ + Invoked_G1 = _des_states[G3]; + _currentG1 = G3; + goto loop; + break; + + /* CONTROL FUNCTIONS */ + case 0x21: /* C0 sets */ + case 0x22: /* C1 sets */ + do { + ch = *us++; + if (++length > n) return (-1); /* too long */ + } while (ch >= 0x20 && ch <= 0x2F); + if (ch < 0x30) /* ch should be a final character */ + return (-1); /* error */ + goto loop; + break; + + /* SINGLE SHIFT for 7bit environment */ + case SS2_7B: /* Single shift SS2 for 7bits */ + case SS3_7B: /* Single shoft SS3 for 7bits */ + if (ch == SS2_7B) + gen_wide_state = USE_SS2; + else + gen_wide_state = USE_SS3; + goto loop; + break; + + default: /* should be an error */ + return (-1); + break; + } + /* locking shifts */ + case LS0: + gen_wide_state = USE_STATE; /* used in gen_wide: */ + Invoked_G0 = _des_states[G0]; + _currentG0 = G0; + goto loop; + break; + + case LS1: + gen_wide_state = USE_STATE; /* used in gen_wide: */ + Invoked_G0 = _des_states[G1]; + _currentG0 = G1; + goto loop; + break; + + /* Single shift SS3 and SS2 for 8bits */ + case SS2_8B: + case SS3_8B: + if (ch == SS2_8B) + gen_wide_state = USE_SS2; + else + gen_wide_state = USE_SS3; + goto loop; + break; + + /* This character is not any special character/ + * It does not change any state. + * Goto where it generates wide character. + */ + default: + /* + * Use this ch to generate pwc. + */ + if (ch == 0) { /* end of string or 0 */ + wide = 0; + mask = 0; + goto gen_wide; + } + break; + } + + + /* + * Generate pwc here. + * The information here is + * current state and length. If the length is two, you need to + * read one more character. + */ + switch (gen_wide_state) { + case USE_STATE: + if (BIT8(ch)) { /* 8bit environment ? */ + /* current mode is G1 mode */ + if (Invoked_G1.width == 2) { + tch = *us++; + if (++length > n) return (-1); + wide = ch; + wide = (wide << 8 | tch); + } + else { + wide = ch; + } + if (_currentG1 == G0) mask = G0MASK; + else if (_currentG1 == G1) mask = G1MASK; + else if (_currentG1 == G2) mask = G2MASK; + else mask = G3MASK; + } + else { + /* current mode is G0 mode */ + if (Invoked_G0.width == 2) { + tch = *us++; + if (++length > n) return (-1); + wide = ch; + wide = (wide << 8 | tch); + } + else { + wide = ch; + } + if (_currentG0 == G0) mask = G0MASK; + else if (_currentG0 == G1) mask = G1MASK; + else if (_currentG0 == G2) mask = G2MASK; + else mask = G3MASK; + } + break; + case USE_SS2: + if (_des_states[G2].width == 2) { + tch = *us++; + if (++length > n) return (-1); + wide = ch; + wide = (wide << 8 | tch); + } + else { + wide = ch; + } + mask = G2MASK; + break; + case USE_SS3: + if (_des_states[G3].width == 2) { + tch = *us++; + if (++length > n) return (-1); + wide = ch; + wide = (wide << 8 | tch); + } + else { + wide = ch; + } + mask = G3MASK; + break; + default: + /* shoult be internal error */ + return (-1); + break; + } +gen_wide: + wide &= 0x7F7F; /* strip off the top bit */ + wide = wide | mask; + if (pwc != NULL) + *pwc = wide; + return (length); +} + + +#define MAXMBSIZE 128 +/* + * mbstowcs() + */ +size_t +_mbstowcs_iso(pwcs, s, n) + wchar_t *pwcs; + unsigned char *s; + size_t n; +{ + int ret1; + int accsum = 0; + wchar_t pwc; + + /* + * If pwcs == 0, do nothing. + */ + if (pwcs == 0) + return (0); + /* + * States things + */ + _savestates(); _initializestates(); + while (accsum < n) { + ret1 = _mbtowc_iso (&pwc, s, MAXMBSIZE); + if (ret1 < 0) + return (-1); /* error */ + if (ret1 == 0 || pwc == 0) { + if (pwcs == 0) + *pwcs = 0; + /* + * Restore states + */ + _restorestates(); + return (accsum); + } + s = s + ret1; /* increment the pointer */ + *pwcs++ = pwc; + ++accsum; + } + /* + * Restore states + */ + _restorestates(); + return (accsum); +} + +/* + * wctomb - + */ +int +_wctomb_iso(s, pwc) + unsigned char *s; + wchar_t pwc; +{ + unsigned char ch; + unsigned char tch; /* temporary use */ + unsigned char *us = (unsigned char *)s; + int gen_wide_state = USE_STATE; /* used in gen_wide: */ + int length = 0; + int len = 0; + wchar_t wide; + unsigned short mode; + unsigned char buf[MAXSIZE]; + unsigned char *bp; + int csize, i; + int n = MMB_CUR_MAX; + + isowidth_t * isoinfo = (isowidth_t *) _code_set_info.code_info; + + /* + * If pwc is 0, do this first. + */ + if (pwc == 0) { + if (s != 0) { + *s = 0; + return (1); + } + else { + return (0); + } + } + + mode = pwc & G3MASK; /* The mode of this character */ + if (((pwc >> 8) & 0x007f) == 0) + csize = 1; + else + csize = 2; + bp = buf; + length = 0; +#ifdef DDDebug + if (_my_env == BIT7ENV) + printf ("7b "); + else + printf ("8b "); + printf ("csize = %d, prevcsize = %d, (%x,%x) ",csize, prevcsize, (pwc>>8)&0x00ff, pwc&0x00ff); + switch (mode) { + case G0MASK: + printf ("G0"); break; + case G1MASK: + printf ("G1"); break; + case G2MASK: + printf ("G2"); break; + case G3MASK: + printf ("G3"); break; + default: + printf ("XXXX"); break; + } +#endif + + switch (_my_env) { + case BIT7ENV: /* 7 bit environment */ + switch (mode) { + case G0MASK: + if (_currentOUT != G0 || prevcsize != csize) { + _currentOUT = G0; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x28; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x28; + *bp++ = FINAL; + length += 3; + } + *bp++ = SI; + ++length; + } + if (csize == 1) { + *bp++ = pwc & 0x007f; + ++length; + } + else { + *bp++ = (pwc & 0x7f00) >> 8; + ++length; + *bp++ = pwc & 0x007f; + ++length; + } + break; + case G1MASK: + if (_currentOUT != G1 || prevcsize != csize) { + _currentOUT = G1; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x29; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x29; + *bp++ = FINAL; + length += 3; + } + *bp++ = SO; + ++length; + } + if (csize == 1) { + *bp++ = pwc & 0x007f; + ++length; + } + else { + *bp++ = (pwc & 0x7f00) >> 8; + ++length; + *bp++ = pwc & 0x007f; + ++length; + } + break; + case G2MASK: + if (_currentOUT != G2 || prevcsize != csize) { + _currentOUT = G2; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x2A; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x2A; + *bp++ = FINAL; + length += 3; + } + *bp++ = ESC; *bp++ = LS2; + length += 2; + } + if (csize == 1) { + *bp++ = pwc & 0x007f; + ++length; + } + else { + *bp++ = (pwc & 0x7f00) >> 8; + ++length; + *bp++ = pwc & 0x007f; + ++length; + } + break; + case G3MASK: + if (_currentOUT != G3 || prevcsize != csize) { + _currentOUT = G3; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x2B; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x2B; + *bp++ = FINAL; + length += 3; + } + *bp++ = ESC; *bp++ = LS3; + length += 2; + } + if (csize == 1) { + *bp++ = pwc & 0x007f; + ++length; + } + else { + *bp++ = (pwc & 0x7f00) >> 8; + ++length; + *bp++ = pwc & 0x007f; + ++length; + } + break; + } + break; + case BIT8ENV: /* 8 bit environment */ + switch (mode) { + case G0MASK: + if (_currentOUT != G0 || prevcsize != csize) { + _currentOUT = G0; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x28; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x28; + *bp++ = FINAL; + length += 3; + } + *bp++ = LS0; + ++length; + } + if (csize == 1) { + *bp++ = pwc & 0x007f; + ++length; + } + else { + *bp++ = (pwc & 0x7f00) >> 8; + ++length; + *bp++ = pwc & 0x007f; + ++length; + } + break; + case G1MASK: + if (_currentOUT != G1 || prevcsize != csize) { + _currentOUT = G1; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x29; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x29; + *bp++ = FINAL; + length += 3; + } + *bp++ = ESC; *bp++ = LS1R; + length += 2; + } + + /* + * If state is G1 or G2, or G3, assume that + * this is 8bit characters. To do this more + * accurately, wide character needs to be + * larger than 16 bits to keep more information. + */ + pwc |= 0x8080; + if (csize == 1) { + *bp++ = pwc & 0x00ff; + ++length; + } + else { + *bp++ = (pwc & 0xff00) >> 8; + ++length; + *bp++ = pwc & 0x00ff; + ++length; + } + break; + case G2MASK: + if (_currentOUT != G2 || prevcsize != csize) { + _currentOUT = G2; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x2A; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x2A; + *bp++ = FINAL; + length += 3; + } + *bp++ = ESC; *bp++ = LS2R; + length += 2; + } + /* + * If state is G1 or G2, or G3, assume that + * this is 8bit characters. To do this more + * accurately, wide character needs to be + * larger than 16 bits to keep more information. + */ + pwc |= 0x8080; + if (csize == 1) { + *bp++ = pwc & 0x00ff; + ++length; + } + else { + *bp++ = (pwc & 0xff00) >> 8; + ++length; + *bp++ = pwc & 0x00ff; + ++length; + } + break; + case G3MASK: + if (_currentOUT != G3 || prevcsize != csize) { + _currentOUT = G3; + if (csize == 2) { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x24; + *bp++ = 0x2B; + *bp++ = FINAL; + length += 4; + } + else { + /* + * Emit escape sequences + */ + *bp++ = ESC; + *bp++ = 0x2B; + *bp++ = FINAL; + length += 3; + } + *bp++ = ESC; *bp++ = LS3R; + length += 2; + } + /* + * If state is G1 or G2, or G3, assume that + * this is 8bit characters. To do this more + * accurately, wide character needs to be + * larger than 16 bits to keep more information. + */ + pwc |= 0x8080; + if (csize == 1) { + *bp++ = pwc & 0x00ff; + ++length; + } + else { + *bp++ = (pwc & 0xff00) >> 8; + ++length; + *bp++ = pwc & 0x00ff; + ++length; + } + break; + } + break; + default: /* Should never happens */ + return (-1); + break; + } + + prevcsize = csize; + + if (length > n) { + return (-1); /* buffer too small */ + } + for (i = 0; i < length; i++) { + *s++ = buf[i]; + } +#ifdef DDDebug + printf ("\t("); + for (i = 0; i < length; i++) { + printf ("%x,", buf[i]); + } + printf (")\n"); +#endif + return (length); +} + +/* + * wcstombs + */ +size_t +_wcstombs_iso(s, pwcs, n) + char *s; + wchar_t *pwcs; + int n; +{ + int acclen = 0; + char buf[MMB_CUR_MAX]; + int ret1; + int i; + + if (n < 0) + return (-1); + /* + * Initialize State + */ + _savestates(); _initializestates(); + while (acclen < n) { + ret1 = _wctomb_iso (buf, *pwcs); + /* + * end of string ? + */ + if (ret1 == 1 && buf[0] == 0) { + *s = 0; + /* + * restore states + */ + _restorestates(); + return (acclen); + } + /* + * Error ? + */ + if (ret1 < 0) + return (-1); + acclen += ret1; + for (i = 0; i < ret1; i++) + *s++ = buf[i]; + ++pwcs; + } + + /* + * restore states + */ + _restorestates(); + + /* + * return the length + */ + return (acclen); +} + + +/* + * Supplementary routines + */ + +int +_initializestates() +{ + _currentG0 = G0; + _currentG1 = G1; + + _des_states[G0].width = -1; /* This makes it Initialize */ + + _currentOUT = G0; + prevcsize = 1; +} + +static char SAVED_currentG0; +static char SAVED_currentG1; +static struct state SAVED_des_states[NUM_OF_STATES]; +static struct state SAVED_Invoked_G0, SAVED_Invoked_G1; +static char SAVED_currentOUT = G0; /* G0, G1, G2 or G3 */ +static SAVED_prevcsize = 1; + +int +_savestates() +{ + + SAVED_currentG0 = _currentG0; + SAVED_currentG1 = _currentG1; + + SAVED_des_states[G0] = _des_states[G0]; + SAVED_des_states[G1] = _des_states[G1]; + SAVED_des_states[G2] = _des_states[G2]; + SAVED_des_states[G3] = _des_states[G3]; + + SAVED_Invoked_G0 = Invoked_G0; + SAVED_Invoked_G1 = Invoked_G1; + + SAVED_currentOUT = _currentOUT; + SAVED_prevcsize = prevcsize; +} + +int +_restorestates() +{ + _currentG0 = SAVED_currentG0; + _currentG1 = SAVED_currentG1; + + _des_states[G0] = SAVED_des_states[G0]; + _des_states[G1] = SAVED_des_states[G1]; + _des_states[G2] = SAVED_des_states[G2]; + _des_states[G3] = SAVED_des_states[G3]; + + Invoked_G0 = SAVED_Invoked_G0; + Invoked_G1 = SAVED_Invoked_G1; + + _currentOUT = SAVED_currentOUT; + prevcsize = SAVED_prevcsize; +} diff --git a/usr/src/lib/libbc/libc/gen/common/iso2022.h b/usr/src/lib/libbc/libc/gen/common/iso2022.h new file mode 100644 index 0000000000..5e7e63abe7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/iso2022.h @@ -0,0 +1,76 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * ISO2022 generic escape sequence handler for graphical characters + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* static char *sccsid = "%Z%%M% %I% %E% SMI"; */ + +/* + * single control characters + */ +#define SI 0x0F +#define SO 0x0E + +#define ESC 0x1B + +#define LS0 0x0F +#define LS1 0x0E +#define LS1R 0x7E /* need ESC */ +#define LS2 0x6E /* need ESC */ +#define LS2R 0x7D /* need ESC */ +#define LS3 0x6F /* need ESC */ +#define LS3R 0x7C /* need ESC */ +#define SS2_7B 0x4E /* need ESC */ +#define SS2_8B 0x8E +#define SS3_7B 0x4F /* need ESC */ +#define SS3_8B 0x8F + +#define C_C0 0 +#define C_C1 1 + +#define G0 0 +#define G1 1 +#define G2 2 +#define G3 3 + +#define CONT 0 +#define SING 1 +#define MULT 2 +/* + * code info + */ +typedef struct { + char g0_len; /* 1 or 2 */ + char g1_len; /* 1 or 2 */ + char g2_len; /* 1 or 2 */ + char g3_len; /* 1 or 2 */ + char bit_env;/* 7 or 8 */ + +} isowidth_t; diff --git a/usr/src/lib/libbc/libc/gen/common/issecure.c b/usr/src/lib/libbc/libc/gen/common/issecure.c new file mode 100644 index 0000000000..5567d9a07f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/issecure.c @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <sys/file.h> + +#define PWDADJ "/etc/security/passwd.adjunct" + +/* + * Is this a secure system ? + */ +issecure() +{ + static int securestate = -1; + + if (securestate == -1) + securestate = (access(PWDADJ, F_OK) == 0); + return(securestate); +} diff --git a/usr/src/lib/libbc/libc/gen/common/jcsetpgrp.c b/usr/src/lib/libbc/libc/gen/common/jcsetpgrp.c new file mode 100644 index 0000000000..50c6eb8175 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/jcsetpgrp.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +/* + * POSIX call to set job control process group of current process. + * Use 4BSD "setpgrp" call, but don't call "setpgrp" since that may refer + * to SVID "setpgrp" call in System V environment. + */ +int +jcsetpgrp(pgrp) + int pgrp; +{ + return (setpgid(0,pgrp)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/l64a.c b/usr/src/lib/libbc/libc/gen/common/l64a.c new file mode 100644 index 0000000000..5115b998ba --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/l64a.c @@ -0,0 +1,68 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +/* + * convert long int to base 64 ascii + * char set is [./0-9A-Za-z] + * two's complement negatives are assumed, + * but no assumptions are made about sign propagation on right shift + * + */ + +#include <values.h> +#define BITSPERCHAR 6 /* to hold entire character set */ +#define BITSPERLONG (BITSPERBYTE * sizeof(long)) +#define NMAX ((BITSPERLONG + BITSPERCHAR - 1)/BITSPERCHAR) +#define SIGN (-(1L << (BITSPERLONG - BITSPERCHAR - 1))) +#define CHARMASK ((1 << BITSPERCHAR) - 1) +#define WORDMASK ((1L << ((NMAX - 1) * BITSPERCHAR)) - 1) + +static char buf[NMAX + 1]; + +char * +l64a(lg) +register long lg; +{ + register char *s = buf; + + while (lg != 0) { + + register int c = ((int)lg & CHARMASK) + ('0' - 2); + + if (c > '9') + c += 'A' - '9' - 1; + if (c > 'Z') + c += 'a' - 'Z' - 1; + *s++ = c; + /* fill high-order CHAR if negative */ + /* but suppress sign propagation */ + lg = ((lg < 0) ? (lg >> BITSPERCHAR) | SIGN : + lg >> BITSPERCHAR) & WORDMASK; + } + *s = '\0'; + return (buf); +} diff --git a/usr/src/lib/libbc/libc/gen/common/labeltostring.c b/usr/src/lib/libbc/libc/gen/common/labeltostring.c new file mode 100644 index 0000000000..b4e667b366 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/labeltostring.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <sys/label.h> + +char * +labeltostring(part, value, verbose) +int part; +blabel_t *value; +int verbose; +{ + char *string; + + string = (char *)malloc(sizeof(char)); + strcpy(string, ""); + return (string); +} + +labelfromstring(part, label_string, value) +int part; +char *label_string; +blabel_t *value; +{ + bzero(value, sizeof(value)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ldexp.c b/usr/src/lib/libbc/libc/gen/common/ldexp.c new file mode 100644 index 0000000000..d7d83183b1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ldexp.c @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.7 */ + +/*LINTLIBRARY*/ +/* + * double ldexp (value, exp) + * double value; + * int exp; + * + * Ldexp returns value * 2**exp, if that result is in range. + * If underflow occurs, it returns zero. If overflow occurs, + * it returns a value of appropriate sign and largest single- + * precision magnitude. In case of underflow or overflow, + * the external int "errno" is set to ERANGE. Note that errno is + * not modified if no error occurs, so if you intend to test it + * after you use ldexp, you had better set it to something + * other than ERANGE first (zero is a reasonable value to use). + */ + +#include <values.h> +#include <errno.h> +/* Largest signed long int power of 2 */ +#define MAXSHIFT (BITSPERBYTE * sizeof(long) - 2) + +extern double frexp(); + +double +ldexp(value, exp) +register double value; +register int exp; +{ + int old_exp; + + if (exp == 0 || value == 0.0) /* nothing to do for zero */ + return (value); +#if !(pdp11 || u3b5) /* pdp11 "cc" can't handle cast of + double to void on pdp11 or 3b5 */ + (void) +#endif + frexp(value, &old_exp); + if (exp > 0) { + if (exp + old_exp > MAXBEXP) { /* overflow */ + errno = ERANGE; + return ((double)(value < 0 ? MINDOUBLE : MAXDOUBLE)); +/* + return ((double)(value < 0 ? -1.0e999 : 1.0e999)); +*/ + } + for ( ; exp > MAXSHIFT; exp -= MAXSHIFT) + value *= (1L << MAXSHIFT); + return (value * (1L << exp)); + } + if (exp + old_exp < MINBEXP) { /* underflow */ + errno = ERANGE; + return (0.0); + } + for ( ; exp < -MAXSHIFT; exp += MAXSHIFT) + value *= 1.0/(1L << MAXSHIFT); /* mult faster than div */ + return (value / (1L << -exp)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/lfind.c b/usr/src/lib/libbc/libc/gen/common/lfind.c new file mode 100644 index 0000000000..63aa525cf7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/lfind.c @@ -0,0 +1,57 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +/* + * Linear search algorithm, generalized from Knuth (6.1) Algorithm Q. + * + * This version no longer has anything to do with Knuth's Algorithm Q, + * which first copies the new element into the table, then looks for it. + * The assumption there was that the cost of checking for the end of the + * table before each comparison outweighed the cost of the comparison, which + * isn't true when an arbitrary comparison function must be called and when the + * copy itself takes a significant number of cycles. + * Actually, it has now reverted to Algorithm S, which is "simpler." + */ + +typedef char *POINTER; +extern POINTER memcpy(); + +POINTER +lfind(key, base, nelp, width, compar) +register POINTER key; /* Key to be located */ +register POINTER base; /* Beginning of table */ +unsigned *nelp; /* Pointer to current table size */ +register unsigned width; /* Width of an element (bytes) */ +int (*compar)(); /* Comparison function */ +{ + register POINTER next = base + *nelp * width; /* End of table */ + + for ( ; base < next; base += width) + if ((*compar)(key, base) == 0) + return (base); /* Key found */ + return (POINTER)0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/localtime.c b/usr/src/lib/libbc/libc/gen/common/localtime.c new file mode 100644 index 0000000000..ba4278f37e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/localtime.c @@ -0,0 +1,1421 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1995-2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from Arthur Olson's 6.1 */ + +/*LINTLIBRARY*/ + +#include <tzfile.h> +#include <time.h> +#include <string.h> +#include <ctype.h> +#include <stdio.h> /* for NULL */ +#include <fcntl.h> + +#include <sys/param.h> /* for MAXPATHLEN */ + +#undef FILENAME_MAX +#define FILENAME_MAX MAXPATHLEN + +#ifdef __STDC__ + +#define P(s) s + +#else /* !defined __STDC__ */ + +/* +** Memory management functions +*/ + +extern char * calloc(); +extern char * malloc(); + +/* +** Communication with the environment +*/ + +extern char * getenv(); + +#define ASTERISK * +#define P(s) (/ASTERISK s ASTERISK/) + +#define const + +#endif /* !defined __STDC__ */ + +#ifndef TRUE +#define TRUE 1 +#define FALSE 0 +#endif /* !defined TRUE */ + +#define ACCESS_MODE O_RDONLY + +#define OPEN_MODE O_RDONLY + +/* +** Someone might make incorrect use of a time zone abbreviation: +** 1. They might reference tzname[0] before calling tzset (explicitly +** or implicitly). +** 2. They might reference tzname[1] before calling tzset (explicitly +** or implicitly). +** 3. They might reference tzname[1] after setting to a time zone +** in which Daylight Saving Time is never observed. +** 4. They might reference tzname[0] after setting to a time zone +** in which Standard Time is never observed. +** 5. They might reference tm.TM_ZONE after calling offtime. +** What's best to do in the above cases is open to debate; +** for now, we just set things up so that in any of the five cases +** WILDABBR is used. Another possibility: initialize tzname[0] to the +** string "tzname[0] used before set", and similarly for the other cases. +** And another: initialize tzname[0] to "ERA", with an explanation in the +** manual page of what this "time zone abbreviation" means (doing this so +** that tzname[0] has the "normal" length of three characters). +*/ +static const char *WILDABBR = " "; + +static const char *GMT = "GMT"; + +struct ttinfo { /* time type information */ + long tt_gmtoff; /* GMT offset in seconds */ + int tt_isdst; /* used to set tm_isdst */ + int tt_abbrind; /* abbreviation list index */ + int tt_ttisstd; /* TRUE if transition is std time */ +}; + +struct state { + int timecnt; + int typecnt; + int charcnt; + time_t *ats; + unsigned char *types; + struct ttinfo *ttis; + char *chars; + char *last_tzload; /* name of file tzload() last opened */ +}; + +struct rule { + int r_type; /* type of rule--see below */ + int r_day; /* day number of rule */ + int r_week; /* week number of rule */ + int r_mon; /* month number of rule */ + long r_time; /* transition time of rule */ +}; + +#define JULIAN_DAY 0 /* Jn - Julian day */ +#define DAY_OF_YEAR 1 /* n - day of year */ +#define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */ + +/* +** Prototypes for static functions. +*/ + +static int allocall P((register struct state * sp)); +static long detzcode P((const char * codep)); +static void freeall P((register struct state * sp)); +static const char * getzname P((const char * strp, const int i)); +static const char * getnum P((const char * strp, int * nump, int min, + int max)); +static const char * getsecs P((const char * strp, long * secsp)); +static const char * getoffset P((const char * strp, long * offsetp)); +static const char * getrule P((const char * strp, struct rule * rulep)); +static void gmtload P((struct state * sp)); +static void gmtsub P((const time_t * timep, long offset, + struct tm * tmp)); +static void localsub P((const time_t * timep, long offset, + struct tm * tmp)); +static void normalize P((int * tensptr, int * unitsptr, int base)); +static void settzname P((void)); +static time_t time1 P((struct tm * tmp, void (* funcp)(), + long offset)); +static time_t time2 P((struct tm *tmp, void (* funcp)(), + long offset, int * okayp)); +static void timesub P((const time_t * timep, long offset, + struct tm * tmp)); +static int tmcomp P((const struct tm * atmp, + const struct tm * btmp)); +static time_t transtime P((time_t janfirst, int year, + const struct rule * rulep, long offset)); +static int tzload P((const char * name, struct state * sp)); +static int tzparse P((const char * name, struct state * sp, + int lastditch)); + +static struct state * lclptr; +static struct state * gmtptr; + +static int lcl_is_set; +static int gmt_is_set; + +#ifdef S5EMUL +char * tzname[2] = { + "GMT", + " ", +}; + +time_t timezone = 0; +time_t altzone = 0; +int daylight = 0; +#endif /* defined S5EMUL */ + +static long +detzcode(codep) +const char * const codep; +{ + register long result; + register int i; + + result = 0; + for (i = 0; i < 4; ++i) + result = (result << 8) | (codep[i] & 0xff); + return result; +} + +/* +** Free up existing items pointed to by the specified "state" structure, +** and allocate new ones of sizes specified by that "state" structure. +** Return 0 on success; return -1 and free all previously-allocated items +** on failure. +*/ +static int +allocall(sp) +register struct state * const sp; +{ + freeall(sp); + + if (sp->timecnt != 0) { + sp->ats = (time_t *)calloc((unsigned)sp->timecnt, + (unsigned)sizeof (time_t)); + if (sp->ats == NULL) + return -1; + sp->types = + (unsigned char *)calloc((unsigned)sp->timecnt, + (unsigned)sizeof (unsigned char)); + if (sp->types == NULL) { + freeall(sp); + return -1; + } + } + sp->ttis = + (struct ttinfo *)calloc((unsigned)sp->typecnt, + (unsigned)sizeof (struct ttinfo)); + if (sp->ttis == NULL) { + freeall(sp); + return -1; + } + sp->chars = (char *)calloc((unsigned)sp->charcnt + 1, + (unsigned)sizeof (char)); + if (sp->chars == NULL) { + freeall(sp); + return -1; + } + return 0; +} + +/* +** Free all the items pointed to by the specified "state" structure (except for +** "chars", which might have other references to it), and zero out all the +** pointers to those items. +*/ +static void +freeall(sp) +register struct state * const sp; +{ + if (sp->ttis) { + free((char *)sp->ttis); + sp->ttis = 0; + } + if (sp->types) { + free((char *)sp->types); + sp->types = 0; + } + if (sp->ats) { + free((char *)sp->ats); + sp->ats = 0; + } +} + +#ifdef S5EMUL +static void +settzname() +{ + register const struct state * const sp = lclptr; + register int i; + + tzname[0] = (char *)GMT; + tzname[1] = (char *)WILDABBR; + daylight = 0; + timezone = 0; + altzone = 0; + if (sp == NULL) + return; + for (i = 0; i < sp->typecnt; ++i) { + register const struct ttinfo * const ttisp = &sp->ttis[i]; + + tzname[ttisp->tt_isdst] = + (char *) &sp->chars[ttisp->tt_abbrind]; + if (ttisp->tt_isdst) + daylight = 1; + if (i == 0 || !ttisp->tt_isdst) + timezone = -(ttisp->tt_gmtoff); + if (i == 0 || ttisp->tt_isdst) + altzone = -(ttisp->tt_gmtoff); + } + /* + ** And to get the latest zone names into tzname. . . + */ + for (i = 0; i < sp->timecnt; ++i) { + register const struct ttinfo * const ttisp = + &sp->ttis[sp->types[i]]; + + tzname[ttisp->tt_isdst] = + (char *) &sp->chars[ttisp->tt_abbrind]; + } +} +#endif + +/* +** Maximum size of a time zone file. +*/ +#define MAX_TZFILESZ (sizeof (struct tzhead) + \ + TZ_MAX_TIMES * (4 + sizeof (char)) + \ + TZ_MAX_TYPES * (4 + 2 * sizeof (char)) + \ + TZ_MAX_CHARS * sizeof (char) + \ + TZ_MAX_LEAPS * 2 * 4 + \ + TZ_MAX_TYPES * sizeof (char)) + +static int +tzload(name, sp) +register const char * name; +register struct state * const sp; +{ + register const char * p; + register int i; + register int fid; + + if (name == NULL && (name = (const char *)TZDEFAULT) == NULL) + return -1; + { + register int doaccess; + char fullname[FILENAME_MAX + 1]; + + if (name[0] == ':') + ++name; + doaccess = name[0] == '/'; + if (!doaccess) { + if ((p = TZDIR) == NULL) + return -1; + if ((strlen(p) + strlen(name) + 1) >= sizeof fullname) + return -1; + (void) strcpy(fullname, p); + (void) strcat(fullname, "/"); + (void) strcat(fullname, name); + /* + ** Set doaccess if '.' (as in "../") shows up in name. + */ + if (strchr(name, '.') != NULL) + doaccess = TRUE; + name = fullname; + } + if (sp->last_tzload && strcmp(sp->last_tzload, name) == 0) + return (0); + if (doaccess && access(name, ACCESS_MODE) != 0) + return -1; + if ((fid = open(name, OPEN_MODE)) == -1) + return -1; + } + { + register const struct tzhead * tzhp; + char buf[MAX_TZFILESZ]; + int leapcnt; + int ttisstdcnt; + + i = read(fid, buf, sizeof buf); + if (close(fid) != 0 || i < sizeof *tzhp) + return -1; + tzhp = (struct tzhead *) buf; + ttisstdcnt = (int) detzcode(tzhp->tzh_ttisstdcnt); + leapcnt = (int) detzcode(tzhp->tzh_leapcnt); + sp->timecnt = (int) detzcode(tzhp->tzh_timecnt); + sp->typecnt = (int) detzcode(tzhp->tzh_typecnt); + sp->charcnt = (int) detzcode(tzhp->tzh_charcnt); + if (leapcnt < 0 || leapcnt > TZ_MAX_LEAPS || + sp->typecnt <= 0 || sp->typecnt > TZ_MAX_TYPES || + sp->timecnt < 0 || sp->timecnt > TZ_MAX_TIMES || + sp->charcnt < 0 || sp->charcnt > TZ_MAX_CHARS || + (ttisstdcnt != sp->typecnt && ttisstdcnt != 0)) + return -1; + if (i < sizeof *tzhp + + sp->timecnt * (4 + sizeof (char)) + + sp->typecnt * (4 + 2 * sizeof (char)) + + sp->charcnt * sizeof (char) + + leapcnt * 2 * 4 + + ttisstdcnt * sizeof (char)) + return -1; + if (allocall(sp) < 0) + return -1; + p = buf + sizeof *tzhp; + for (i = 0; i < sp->timecnt; ++i) { + sp->ats[i] = detzcode(p); + p += 4; + } + for (i = 0; i < sp->timecnt; ++i) { + sp->types[i] = (unsigned char) *p++; + if (sp->types[i] >= sp->typecnt) + return -1; + } + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + ttisp->tt_gmtoff = detzcode(p); + p += 4; + ttisp->tt_isdst = (unsigned char) *p++; + if (ttisp->tt_isdst != 0 && ttisp->tt_isdst != 1) + return -1; + ttisp->tt_abbrind = (unsigned char) *p++; + if (ttisp->tt_abbrind < 0 || + ttisp->tt_abbrind > sp->charcnt) + return -1; + } + for (i = 0; i < sp->charcnt-1; ++i) + sp->chars[i] = *p++; + sp->chars[i] = '\0'; /* ensure '\0' at end */ + p += (4 + 4) * leapcnt; /* skip leap seconds list */ + for (i = 0; i < sp->typecnt; ++i) { + register struct ttinfo * ttisp; + + ttisp = &sp->ttis[i]; + if (ttisstdcnt == 0) + ttisp->tt_ttisstd = FALSE; + else { + ttisp->tt_ttisstd = *p++; + if (ttisp->tt_ttisstd != TRUE && + ttisp->tt_ttisstd != FALSE) + return -1; + } + } + } + if (sp->last_tzload) + free(sp->last_tzload); + sp->last_tzload = strdup(name); + return 0; +} + +static const int mon_lengths[2][MONSPERYEAR] = { + 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31, + 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 +}; + +static const int year_lengths[2] = { + DAYSPERNYEAR, DAYSPERLYEAR +}; + +/* +** Given a pointer into a time zone string, scan until a character that is not +** a valid character in a zone name is found. Return a pointer to that +** character. +** Support both quoted and unquoted timezones. +*/ + +static const char * +getzname(strp, quoted) +const char * strp; +int quoted; +{ + unsigned char c; + + if (quoted) { + while ((c = (unsigned char)*strp) != '\0' && + (isalnum(c) || (c == '+') || (c == '-'))) + ++strp; + } else { + while ((c = (unsigned char)*strp) != '\0' && !isdigit(c) + && (c != ',') && (c != '-') && (c != '+')) + ++strp; + } + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number from that string. +** Check that the number is within a specified range; if it is not, return +** NULL. +** Otherwise, return a pointer to the first character not part of the number. +*/ + +static const char * +getnum(strp, nump, min, max) +register const char * strp; +int * const nump; +const int min; +const int max; +{ + register char c; + register int num; + + if (strp == NULL || !isdigit(*strp)) + return NULL; + num = 0; + while ((c = *strp) != '\0' && isdigit(c)) { + num = num * 10 + (c - '0'); + if (num > max) + return NULL; /* illegal value */ + ++strp; + } + if (num < min) + return NULL; /* illegal value */ + *nump = num; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a number of seconds, +** in hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the number +** of seconds. +*/ + +static const char * +getsecs(strp, secsp) +register const char * strp; +long * const secsp; +{ + int num; + + strp = getnum(strp, &num, 0, HOURSPERDAY); + if (strp == NULL) + return NULL; + *secsp = num * SECSPERHOUR; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, MINSPERHOUR - 1); + if (strp == NULL) + return NULL; + *secsp += num * SECSPERMIN; + if (*strp == ':') { + ++strp; + strp = getnum(strp, &num, 0, SECSPERMIN - 1); + if (strp == NULL) + return NULL; + *secsp += num; + } + } + return strp; +} + +/* +** Given a pointer into a time zone string, extract an offset, in +** [+-]hh[:mm[:ss]] form, from the string. +** If any error occurs, return NULL. +** Otherwise, return a pointer to the first character not part of the time. +*/ + +static const char * +getoffset(strp, offsetp) +register const char * strp; +long * const offsetp; +{ + register int neg; + + if (*strp == '-') { + neg = 1; + ++strp; + } else if (isdigit(*strp) || *strp++ == '+') + neg = 0; + else return NULL; /* illegal offset */ + strp = getsecs(strp, offsetp); + if (strp == NULL) + return NULL; /* illegal time */ + if (neg) + *offsetp = -*offsetp; + return strp; +} + +/* +** Given a pointer into a time zone string, extract a rule in the form +** date[/time]. See POSIX section 8 for the format of "date" and "time". +** If a valid rule is not found, return NULL. +** Otherwise, return a pointer to the first character not part of the rule. +*/ + +static const char * +getrule(strp, rulep) +const char * strp; +register struct rule * const rulep; +{ + if (*strp == 'J') { + /* + ** Julian day. + */ + rulep->r_type = JULIAN_DAY; + ++strp; + strp = getnum(strp, &rulep->r_day, 1, DAYSPERNYEAR); + } else if (*strp == 'M') { + /* + ** Month, week, day. + */ + rulep->r_type = MONTH_NTH_DAY_OF_WEEK; + ++strp; + strp = getnum(strp, &rulep->r_mon, 1, MONSPERYEAR); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_week, 1, 5); + if (strp == NULL) + return NULL; + if (*strp++ != '.') + return NULL; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERWEEK - 1); + } else if (isdigit(*strp)) { + /* + ** Day of year. + */ + rulep->r_type = DAY_OF_YEAR; + strp = getnum(strp, &rulep->r_day, 0, DAYSPERLYEAR - 1); + } else return NULL; /* invalid format */ + if (strp == NULL) + return NULL; + if (*strp == '/') { + /* + ** Time specified. + */ + ++strp; + strp = getsecs(strp, &rulep->r_time); + } else rulep->r_time = 2 * SECSPERHOUR; /* default = 2:00:00 */ + return strp; +} + +/* +** Given the Epoch-relative time of January 1, 00:00:00 GMT, in a year, the +** year, a rule, and the offset from GMT at the time that rule takes effect, +** calculate the Epoch-relative time that rule takes effect. +*/ + +static time_t +transtime(janfirst, year, rulep, offset) +const time_t janfirst; +const int year; +register const struct rule * const rulep; +const long offset; +{ + register int leapyear; + register time_t value; + register int i; + int d, m1, yy0, yy1, yy2, dow; + + leapyear = isleap(year); + switch (rulep->r_type) { + + case JULIAN_DAY: + /* + ** Jn - Julian day, 1 == January 1, 60 == March 1 even in leap + ** years. + ** In non-leap years, or if the day number is 59 or less, just + ** add SECSPERDAY times the day number-1 to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + (rulep->r_day - 1) * SECSPERDAY; + if (leapyear && rulep->r_day >= 60) + value += SECSPERDAY; + break; + + case DAY_OF_YEAR: + /* + ** n - day of year. + ** Just add SECSPERDAY times the day number to the time of + ** January 1, midnight, to get the day. + */ + value = janfirst + rulep->r_day * SECSPERDAY; + break; + + case MONTH_NTH_DAY_OF_WEEK: + /* + ** Mm.n.d - nth "dth day" of month m. + */ + value = janfirst; + for (i = 0; i < rulep->r_mon - 1; ++i) + value += mon_lengths[leapyear][i] * SECSPERDAY; + + /* + ** Use Zeller's Congruence to get day-of-week of first day of + ** month. + */ + m1 = (rulep->r_mon + 9) % 12 + 1; + yy0 = (rulep->r_mon <= 2) ? (year - 1) : year; + yy1 = yy0 / 100; + yy2 = yy0 % 100; + dow = ((26 * m1 - 2) / 10 + + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1) % 7; + if (dow < 0) + dow += DAYSPERWEEK; + + /* + ** "dow" is the day-of-week of the first day of the month. Get + ** the day-of-month (zero-origin) of the first "dow" day of the + ** month. + */ + d = rulep->r_day - dow; + if (d < 0) + d += DAYSPERWEEK; + for (i = 1; i < rulep->r_week; ++i) { + if (d + DAYSPERWEEK >= + mon_lengths[leapyear][rulep->r_mon - 1]) + break; + d += DAYSPERWEEK; + } + + /* + ** "d" is the day-of-month (zero-origin) of the day we want. + */ + value += d * SECSPERDAY; + break; + } + + /* + ** "value" is the Epoch-relative time of 00:00:00 GMT on the day in + ** question. To get the Epoch-relative time of the specified local + ** time on that day, add the transition time and the current offset + ** from GMT. + */ + return value + rulep->r_time + offset; +} + +/* +** Given a POSIX section 8-style TZ string, fill in the rule tables as +** appropriate. +*/ + +static int +tzparse(name, sp, lastditch) +const char * name; +struct state * const sp; +const int lastditch; +{ + const char * stdname; + const char * dstname; + int stdlen; + int dstlen; + long stdoffset; + long dstoffset; + time_t * atp; + unsigned char * typep; + char * cp; + + freeall(sp); /* */ + stdname = name; + if (lastditch) { + stdlen = strlen(name); /* length of standard zone name */ + name += stdlen; + if (stdlen >= sizeof sp->chars) + stdlen = (sizeof sp->chars) - 1; + } else { + if (*name == '<') { + name++; + stdname++; + name = getzname(name, 1); + if (*name != '>') { + return (-1); + } + stdlen = name - stdname; + name++; + } else { + name = getzname(name, 0); + stdlen = name - stdname; + } + if (stdlen < 3) + return -1; + } + if (*name == '\0') + stdoffset = 0; + else { + name = getoffset(name, &stdoffset); + if (name == NULL) + return -1; + } + if (*name != '\0') { + dstname = name; + if (*name == '<') { + name++; + dstname++; + name = getzname(name, 1); + if (*name != '>') { + return (-1); + } + dstlen = name - dstname; + name++; + } else { + name = getzname(name, 0); + dstlen = name - dstname; + } + if (dstlen < 3) + return -1; + if (*name != '\0' && *name != ',' && *name != ';') { + name = getoffset(name, &dstoffset); + if (name == NULL) + return -1; + } else dstoffset = stdoffset - SECSPERHOUR; + if (*name == ',' || *name == ';') { + struct rule start; + struct rule end; + register int year; + register time_t janfirst; + time_t starttime; + time_t endtime; + + ++name; + if ((name = getrule(name, &start)) == NULL) + return -1; + if (*name++ != ',') + return -1; + if ((name = getrule(name, &end)) == NULL) + return -1; + if (*name != '\0') + return -1; + sp->typecnt = 2; /* standard time and DST */ + /* + ** Two transitions per year, from EPOCH_YEAR to 2037. + */ + sp->timecnt = 2 * (2037 - EPOCH_YEAR + 1); + if (sp->timecnt > TZ_MAX_TIMES) + return -1; + sp->charcnt = stdlen + 1 + dstlen + 1; + if (allocall(sp) < 0) + return -1; + sp->ttis[0].tt_gmtoff = -dstoffset; + sp->ttis[0].tt_isdst = 1; + sp->ttis[0].tt_abbrind = stdlen + 1; + sp->ttis[1].tt_gmtoff = -stdoffset; + sp->ttis[1].tt_isdst = 0; + sp->ttis[1].tt_abbrind = 0; + atp = sp->ats; + typep = sp->types; + janfirst = 0; + for (year = EPOCH_YEAR; year <= 2037; ++year) { + starttime = transtime(janfirst, year, &start, + stdoffset); + endtime = transtime(janfirst, year, &end, + dstoffset); + if (starttime > endtime) { + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + } else { + *atp++ = starttime; + *typep++ = 0; /* DST begins */ + *atp++ = endtime; + *typep++ = 1; /* DST ends */ + } + janfirst += + year_lengths[isleap(year)] * SECSPERDAY; + } + } else { + int sawstd; + int sawdst; + long stdfix; + long dstfix; + long oldfix; + int isdst; + register int i; + + if (*name != '\0') + return -1; + if (tzload(TZDEFRULES, sp) != 0) { + freeall(sp); + return -1; + } + /* + ** Discard zone abbreviations from file, and allocate + ** space for the ones from TZ. + */ + free(sp->chars); + sp->charcnt = stdlen + 1 + dstlen + 1; + sp->chars = (char *)calloc((unsigned)sp->charcnt, + (unsigned)sizeof (char)); + /* + ** Compute the difference between the real and + ** prototype standard and summer time offsets + ** from GMT, and put the real standard and summer + ** time offsets into the rules in place of the + ** prototype offsets. + */ + sawstd = FALSE; + sawdst = FALSE; + stdfix = 0; + dstfix = 0; + for (i = 0; i < sp->typecnt; ++i) { + if (sp->ttis[i].tt_isdst) { + oldfix = dstfix; + dstfix = + sp->ttis[i].tt_gmtoff + dstoffset; + if (sawdst && (oldfix != dstfix)) + return -1; + sp->ttis[i].tt_gmtoff = -dstoffset; + sp->ttis[i].tt_abbrind = stdlen + 1; + sawdst = TRUE; + } else { + oldfix = stdfix; + stdfix = + sp->ttis[i].tt_gmtoff + stdoffset; + if (sawstd && (oldfix != stdfix)) + return -1; + sp->ttis[i].tt_gmtoff = -stdoffset; + sp->ttis[i].tt_abbrind = 0; + sawstd = TRUE; + } + } + /* + ** Make sure we have both standard and summer time. + */ + if (!sawdst || !sawstd) + return -1; + /* + ** Now correct the transition times by shifting + ** them by the difference between the real and + ** prototype offsets. Note that this difference + ** can be different in standard and summer time; + ** the prototype probably has a 1-hour difference + ** between standard and summer time, but a different + ** difference can be specified in TZ. + */ + isdst = FALSE; /* we start in standard time */ + for (i = 0; i < sp->timecnt; ++i) { + register const struct ttinfo * ttisp; + + /* + ** If summer time is in effect, and the + ** transition time was not specified as + ** standard time, add the summer time + ** offset to the transition time; + ** otherwise, add the standard time offset + ** to the transition time. + */ + ttisp = &sp->ttis[sp->types[i]]; + sp->ats[i] += + (isdst && !ttisp->tt_ttisstd) ? + dstfix : stdfix; + isdst = ttisp->tt_isdst; + } + } + } else { + dstlen = 0; + sp->typecnt = 1; /* only standard time */ + sp->timecnt = 0; + sp->charcnt = stdlen + 1; + if (allocall(sp) < 0) + return -1; + sp->ttis[0].tt_gmtoff = -stdoffset; + sp->ttis[0].tt_isdst = 0; + sp->ttis[0].tt_abbrind = 0; + } + cp = sp->chars; + (void) strncpy(cp, stdname, stdlen); + cp += stdlen; + *cp++ = '\0'; + if (dstlen != 0) { + (void) strncpy(cp, dstname, dstlen); + *(cp + dstlen) = '\0'; + } + return 0; +} + +static void +gmtload(sp) +struct state * const sp; +{ + if (tzload(GMT, sp) != 0) + (void) tzparse(GMT, sp, TRUE); +} + +void +tzsetwall() +{ + lcl_is_set = TRUE; + if (lclptr == NULL) { + lclptr = (struct state *) calloc(1, (unsigned)sizeof *lclptr); + if (lclptr == NULL) { +#ifdef S5EMUL + settzname(); /* all we can do */ +#endif + return; + } + } + if (tzload((char *) NULL, lclptr) != 0) + gmtload(lclptr); +#ifdef S5EMUL + settzname(); +#endif +} + +void +tzset() +{ + register const char * name; + + name = (const char *)getenv("TZ"); + if (name == NULL) { + tzsetwall(); + return; + } + lcl_is_set = TRUE; + if (lclptr == NULL) { + lclptr = (struct state *) calloc(1, (unsigned)sizeof *lclptr); + if (lclptr == NULL) { +#ifdef S5EMUL + settzname(); /* all we can do */ +#endif + return; + } + } + if (*name == '\0') { + /* + ** User wants it fast rather than right. + */ + lclptr->timecnt = 0; + lclptr->typecnt = 1; + lclptr->charcnt = sizeof GMT; + if (allocall(lclptr) < 0) + return; + lclptr->ttis[0].tt_gmtoff = 0; + lclptr->ttis[0].tt_abbrind = 0; + (void) strcpy(lclptr->chars, GMT); + } else if (tzload(name, lclptr) != 0) + if (name[0] == ':' || tzparse(name, lclptr, FALSE) != 0) + (void) tzparse(name, lclptr, TRUE); +#ifdef S5EMUL + settzname(); +#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 +** freely called. (And no, the PANS doesn't require the above behavior-- +** but it *is* desirable.) +** +** The unused offset argument is for the benefit of mktime variants. +*/ + +static struct tm tm; + +/*ARGSUSED*/ +static void +localsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + register const struct state * sp; + register const struct ttinfo * ttisp; + register int i; + const time_t t = *timep; + + if (!lcl_is_set) + tzset(); + sp = lclptr; + if (sp == NULL) { + gmtsub(timep, offset, tmp); + return; + } + if (sp->timecnt == 0 || t < sp->ats[0]) { + i = 0; + while (sp->ttis[i].tt_isdst) + if (++i >= sp->typecnt) { + i = 0; + break; + } + } else { + for (i = 1; i < sp->timecnt; ++i) + if (t < sp->ats[i]) + break; + i = sp->types[i - 1]; + } + ttisp = &sp->ttis[i]; + timesub(&t, ttisp->tt_gmtoff, tmp); + tmp->tm_isdst = ttisp->tt_isdst; +#ifdef S5EMUL + tzname[tmp->tm_isdst] = (char *) &sp->chars[ttisp->tt_abbrind]; +#endif /* S5EMUL */ + tmp->tm_zone = &sp->chars[ttisp->tt_abbrind]; +} + +struct tm * +localtime(timep) +const time_t * const timep; +{ + time_t temp_time = *(const time_t*)timep; + + _ltzset(&temp_time); /* + * base localtime calls this to initialize + * some things, so we'll do it here, too. + */ + localsub(timep, 0L, &tm); + return &tm; +} + +/* +** gmtsub is to gmtime as localsub is to localtime. +*/ + +static void +gmtsub(timep, offset, tmp) +const time_t * const timep; +const long offset; +struct tm * const tmp; +{ + if (!gmt_is_set) { + gmt_is_set = TRUE; + gmtptr = (struct state *) calloc(1, (unsigned)sizeof *gmtptr); + if (gmtptr != NULL) + gmtload(gmtptr); + } + timesub(timep, offset, tmp); + /* + ** Could get fancy here and deliver something such as + ** "GMT+xxxx" or "GMT-xxxx" if offset is non-zero, + ** but this is no time for a treasure hunt. + */ + if (offset != 0) + tmp->tm_zone = (char *)WILDABBR; + else { + if (gmtptr == NULL) + tmp->tm_zone = (char *)GMT; + else tmp->tm_zone = gmtptr->chars; + } +} + +struct tm * +gmtime(timep) +const time_t * const timep; +{ + gmtsub(timep, 0L, &tm); + return &tm; +} + +struct tm * +offtime(timep, offset) +const time_t * const timep; +const long offset; +{ + gmtsub(timep, offset, &tm); + return &tm; +} + +static void +timesub(timep, offset, tmp) +const time_t * const timep; +const long offset; +register struct tm * const tmp; +{ + register long days; + register long rem; + register int y; + register int yleap; + register const int * ip; + + days = *timep / SECSPERDAY; + rem = *timep % SECSPERDAY; + rem += offset; + while (rem < 0) { + rem += SECSPERDAY; + --days; + } + while (rem >= SECSPERDAY) { + rem -= SECSPERDAY; + ++days; + } + tmp->tm_hour = (int) (rem / SECSPERHOUR); + rem = rem % SECSPERHOUR; + tmp->tm_min = (int) (rem / SECSPERMIN); + tmp->tm_sec = (int) (rem % SECSPERMIN); + tmp->tm_wday = (int) ((EPOCH_WDAY + days) % DAYSPERWEEK); + if (tmp->tm_wday < 0) + tmp->tm_wday += DAYSPERWEEK; + y = EPOCH_YEAR; + if (days >= 0) + for ( ; ; ) { + yleap = isleap(y); + if (days < (long) year_lengths[yleap]) + break; + ++y; + days = days - (long) year_lengths[yleap]; + } + else do { + --y; + yleap = isleap(y); + days = days + (long) year_lengths[yleap]; + } while (days < 0); + tmp->tm_year = y - TM_YEAR_BASE; + tmp->tm_yday = (int) days; + ip = mon_lengths[yleap]; + for (tmp->tm_mon = 0; days >= (long) ip[tmp->tm_mon]; ++(tmp->tm_mon)) + days = days - (long) ip[tmp->tm_mon]; + tmp->tm_mday = (int) (days + 1); + tmp->tm_isdst = 0; + tmp->tm_gmtoff = offset; +} + +/* +** Adapted from code provided by Robert Elz, who writes: +** The "best" way to do mktime I think is based on an idea of Bob +** Kridle's (so its said...) from a long time ago. (mtxinu!kridle now). +** It does a binary search of the time_t space. Since time_t's are +** just 32 bits, its a max of 32 iterations (even at 64 bits it +** would still be very reasonable). +*/ + +#ifndef WRONG +#define WRONG (-1) +#endif /* !defined WRONG */ + +static void +normalize(tensptr, unitsptr, base) +int * const tensptr; +int * const unitsptr; +const int base; +{ + int tmp; + + if (*unitsptr >= base) { + *tensptr += *unitsptr / base; + *unitsptr %= base; + } else if (*unitsptr < 0) { + /* tmp has the range 0 to abs(*unitptr) -1 */ + tmp = -1 - (*unitsptr); + *tensptr -= (tmp/base + 1); + *unitsptr = (base - 1) - (tmp % base); + } +} + +static int +tmcomp(atmp, btmp) +register const struct tm * const atmp; +register const struct tm * const btmp; +{ + register int result; + + if ((result = (atmp->tm_year - btmp->tm_year)) == 0 && + (result = (atmp->tm_mon - btmp->tm_mon)) == 0 && + (result = (atmp->tm_mday - btmp->tm_mday)) == 0 && + (result = (atmp->tm_hour - btmp->tm_hour)) == 0 && + (result = (atmp->tm_min - btmp->tm_min)) == 0) + result = atmp->tm_sec - btmp->tm_sec; + return result; +} + +static time_t +time2(tmp, funcp, offset, okayp) +struct tm * const tmp; +void (* const funcp)(); +const long offset; +int * const okayp; +{ + register const struct state * sp; + register int dir; + register int bits; + register int i, j ; + register int saved_seconds; + time_t newt; + time_t t; + struct tm yourtm, mytm; + + *okayp = FALSE; + yourtm = *tmp; + if (yourtm.tm_sec >= SECSPERMIN + 2 || yourtm.tm_sec < 0) + normalize(&yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN); + normalize(&yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR); + normalize(&yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY); + normalize(&yourtm.tm_year, &yourtm.tm_mon, MONSPERYEAR); + while (yourtm.tm_mday <= 0) { + if (yourtm.tm_mon == 0) { + yourtm.tm_mon = 12; + --yourtm.tm_year; + } + yourtm.tm_mday += + mon_lengths[isleap(yourtm.tm_year + + TM_YEAR_BASE)][--yourtm.tm_mon]; + if (yourtm.tm_mon >= MONSPERYEAR) { + yourtm.tm_mon = 0; + --yourtm.tm_year; + } + } + for ( ; ; ) { + i = mon_lengths[isleap(yourtm.tm_year + + TM_YEAR_BASE)][yourtm.tm_mon]; + if (yourtm.tm_mday <= i) + break; + yourtm.tm_mday -= i; + if (++yourtm.tm_mon >= MONSPERYEAR) { + yourtm.tm_mon = 0; + ++yourtm.tm_year; + } + } + saved_seconds = yourtm.tm_sec; + yourtm.tm_sec = 0; + /* + ** Calculate the number of magnitude bits in a time_t + ** (this works regardless of whether time_t is + ** signed or unsigned, though lint complains if unsigned). + */ + for (bits = 0, t = 1; t > 0; ++bits, t <<= 1) + ; + /* + ** If time_t is signed, then 0 is the median value, + ** if time_t is unsigned, then 1 << bits is median. + */ + t = (t < 0) ? 0 : ((time_t) 1 << bits); + for ( ; ; ) { + (*funcp)(&t, offset, &mytm); + dir = tmcomp(&mytm, &yourtm); + if (dir != 0) { + if (bits-- < 0) + return WRONG; + if (bits < 0) + --t; + else if (dir > 0) + t -= (time_t) 1 << bits; + else t += (time_t) 1 << bits; + continue; + } + if (yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst) + break; + /* + ** Right time, wrong type. + ** Hunt for right time, right type. + ** It's okay to guess wrong since the guess + ** gets checked. + */ + sp = (const struct state *) + ((funcp == localsub) ? lclptr : gmtptr); + if (sp == NULL) + return WRONG; + for (i = 0; i < sp->typecnt; ++i) { + if (sp->ttis[i].tt_isdst != yourtm.tm_isdst) + continue; + for (j = 0; j < sp->typecnt; ++j) { + if (sp->ttis[j].tt_isdst == yourtm.tm_isdst) + continue; + newt = t + sp->ttis[j].tt_gmtoff - + sp->ttis[i].tt_gmtoff; + (*funcp)(&newt, offset, &mytm); + if (tmcomp(&mytm, &yourtm) != 0) + continue; + if (mytm.tm_isdst != yourtm.tm_isdst) + continue; + /* + ** We have a match. + */ + t = newt; + goto label; + } + } + return WRONG; + } +label: + t += saved_seconds; + (*funcp)(&t, offset, tmp); + *okayp = TRUE; + return t; +} + +static time_t +time1(tmp, funcp, offset) +struct tm * const tmp; +void (* const funcp)(); +const long offset; +{ + register time_t t; + register const struct state * sp; + register int samei, otheri; + int okay; + + + if (tmp->tm_isdst > 1) + tmp->tm_isdst = 1; + t = time2(tmp, funcp, offset, &okay); + if (okay || tmp->tm_isdst < 0) + return t; + /* + ** We're supposed to assume that somebody took a time of one type + ** and did some math on it that yielded a "struct tm" that's bad. + ** We try to divine the type they started from and adjust to the + ** type they need. + */ + sp = (const struct state *) ((funcp == localsub) ? lclptr : gmtptr); + if (sp == NULL) + return WRONG; + for (samei = 0; samei < sp->typecnt; ++samei) { + if (sp->ttis[samei].tt_isdst != tmp->tm_isdst) + continue; + for (otheri = 0; otheri < sp->typecnt; ++otheri) { + if (sp->ttis[otheri].tt_isdst == tmp->tm_isdst) + continue; + tmp->tm_sec += sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + t = time2(tmp, funcp, offset, &okay); + if (okay) + return t; + tmp->tm_sec -= sp->ttis[otheri].tt_gmtoff - + sp->ttis[samei].tt_gmtoff; + tmp->tm_isdst = !tmp->tm_isdst; + } + } + return WRONG; +} + +time_t +mktime(tmp) +struct tm * const tmp; +{ + return time1(tmp, localsub, 0L); +} + +time_t +timelocal(tmp) +struct tm * const tmp; +{ + tmp->tm_isdst = -1; + return mktime(tmp); +} + +time_t +timegm(tmp) +struct tm * const tmp; +{ + return time1(tmp, gmtsub, 0L); +} + +time_t +timeoff(tmp, offset) +struct tm * const tmp; +const long offset; +{ + + return time1(tmp, gmtsub, offset); +} diff --git a/usr/src/lib/libbc/libc/gen/common/lsearch.c b/usr/src/lib/libbc/libc/gen/common/lsearch.c new file mode 100644 index 0000000000..adcb72b0d7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/lsearch.c @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.8 */ + +/*LINTLIBRARY*/ +/* + * Linear search algorithm, generalized from Knuth (6.1) Algorithm Q. + * + * This version no longer has anything to do with Knuth's Algorithm Q, + * which first copies the new element into the table, then looks for it. + * The assumption there was that the cost of checking for the end of the + * table before each comparison outweighed the cost of the comparison, which + * isn't true when an arbitrary comparison function must be called and when the + * copy itself takes a significant number of cycles. + * Actually, it has now reverted to Algorithm S, which is "simpler." + */ + +typedef char *POINTER; +extern POINTER memcpy(); + +POINTER +lsearch(key, base, nelp, width, compar) +register POINTER key; /* Key to be located */ +register POINTER base; /* Beginning of table */ +unsigned *nelp; /* Pointer to current table size */ +register unsigned width; /* Width of an element (bytes) */ +int (*compar)(); /* Comparison function */ +{ + register POINTER next = base + *nelp * width; /* End of table */ + + for ( ; base < next; base += width) + if ((*compar)(key, base) == 0) + return (base); /* Key found */ + ++*nelp; /* Not found, add to table */ + return (memcpy(base, key, (int)width)); /* base now == next */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/madvise.c b/usr/src/lib/libbc/libc/gen/common/madvise.c new file mode 100644 index 0000000000..b81422817f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/madvise.c @@ -0,0 +1,57 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <errno.h> + +/* + * Function to provide advise to vm system to optimize it's + * characteristics for a particular application + */ + +/*LINTLIBRARY*/ +madvise(addr, len, advice) + caddr_t addr; + u_int len; + int advice; +{ + if (len == 0) { + errno = EINVAL; + return (-1); + } + return (mctl(addr, len, MC_ADVISE, advice)); +} + +/* + * This is only here so programs that use vadvise will not fail + * because it is not in the bcp libc. + */ +int +vadvise(int param) { + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mallint.h b/usr/src/lib/libbc/libc/gen/common/mallint.h new file mode 100644 index 0000000000..d516393191 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mallint.h @@ -0,0 +1,120 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +/* + * file: mallint.h + * description: + * + * Definitions for malloc.c and friends (realloc.c, memalign.c) + * + * The node header structure. Header info never overlaps with user + * data space, in order to accommodate the following atrocity: + * free(p); + * realloc(p, newsize); + * ... which was historically used to obtain storage compaction as + * a side effect of the realloc() call, when the block referenced + * by p was coalesced with another free block by the call to free(). + * + * To reduce storage consumption, a header block is associated with + * free blocks only, not allocated blocks. + * When a free block is allocated, its header block is put on + * a free header block list. + * + * This creates a header space and a free block space. + * The left pointer of a header blocks is used to chain free header + * blocks together. New header blocks are allocated in chunks of + * NFREE_HDRS. + */ +#include <malloc.h> + +typedef enum {false,true} bool; +typedef struct freehdr *Freehdr; +typedef struct dblk *Dblk; +typedef unsigned int uint; + +/* + * Description of a header for a free block + * Only free blocks have such headers. + */ +struct freehdr { + Freehdr left; /* Left tree pointer */ + Freehdr right; /* Right tree pointer */ + Dblk block; /* Ptr to the data block */ + uint size; +}; + +#define NIL ((Freehdr) 0) +#define NFREE_HDRS 512 /* Get this many headers at a time */ +#define SMALLEST_BLK sizeof(struct dblk) /* Size of smallest block */ +#define NULL 0 + +/* + * Description of a data block. + * A data block consists of a length word, possibly followed by + * a filler word for alignment, followed by the user's data. + * To back up from the user's data to the length word, use + * (address of data) - ALIGNSIZ; + */ + +#ifdef sparc +#define ALIGNSIZ sizeof(double) +struct dblk { + uint size; /* Size of the block */ + uint filler; /* filler, for double alignment */ + char data[ALIGNSIZ]; /* Addr returned to the caller */ +}; +#endif + +#ifdef mc68000 +#define ALIGNSIZ sizeof(uint) +struct dblk { + uint size; /* Size of the block */ + char data[ALIGNSIZ]; /* Addr returned to the caller */ +}; +#endif + + +/* + * weight(x) is the size of a block, in bytes; or 0 if and only if x + * is a null pointer. Note that malloc() and free() should be + * prepared to deal with things like zero-length blocks, which + * can be introduced by errant programs. + */ + +#define weight(x) ((x) == NIL? 0: (x->size)) +#define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) +#define nextblk(p, size) ((Dblk) ((char *) (p) + (size))) +#define max(a, b) ((a) < (b)? (b): (a)) +#define min(a, b) ((a) < (b)? (a): (b)) +#define heapsize() (_ubound - _lbound) +#define misaligned(p) ((unsigned)(p)&3) + +extern Freehdr _root; +extern char *_lbound, *_ubound; +extern int malloc_debug(); + +extern struct mallinfo __mallinfo; diff --git a/usr/src/lib/libbc/libc/gen/common/malloc.c b/usr/src/lib/libbc/libc/gen/common/malloc.c new file mode 100644 index 0000000000..ba57931487 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/malloc.c @@ -0,0 +1,1523 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +/* + * file: malloc.c + * description: + * Yet another memory allocator, this one based on a method + * described in C.J. Stephenson, "Fast Fits" + * + * The basic data structure is a "Cartesian" binary tree, in which + * nodes are ordered by ascending addresses (thus minimizing free + * list insertion time) and block sizes decrease with depth in the + * tree (thus minimizing search time for a block of a given size). + * + * In other words: for any node s, let D(s) denote the set of + * descendents of s; for all x in D(left(s)) and all y in + * D(right(s)), we have: + * + * a. addr(x) < addr(s) < addr(y) + * b. len(x) <= len(s) >= len(y) + */ + +#include "mallint.h" +#include <errno.h> + +/* system interface */ + +extern char *sbrk(); +extern int getpagesize(); +extern abort(); +extern int errno; + +static int nbpg = 0; /* set by calling getpagesize() */ +static bool morecore(); /* get more memory into free space */ + +#ifdef S5EMUL +#define ptr_t void * /* ANSI C says these are voids */ +#define free_t void /* ANSI says void free(ptr_t ptr) */ +#define free_return(x) return +#else +#define ptr_t char * /* BSD still (4.3) wants char*'s */ +#define free_t int /* BSD says int free(ptr_t ptr) */ +#define free_return(x) return(x) +#endif + +/* SystemV-compatible information structure */ +#define INIT_MXFAST 0 +#define INIT_NLBLKS 100 +#define INIT_GRAIN ALIGNSIZ + +struct mallinfo __mallinfo = { + 0,0,0,0,0,0,0,0,0,0, /* basic info */ + INIT_MXFAST, INIT_NLBLKS, INIT_GRAIN, /* mallopt options */ + 0,0,0 +}; + +/* heap data structures */ + +Freehdr _root = NIL; /* root of free space list */ +char *_lbound = NULL; /* lower bound of heap */ +char *_ubound = NULL; /* upper bound of heap */ + +/* free header list management */ + +static Freehdr getfreehdr(); +static putfreehdr(); +static Freehdr freehdrptr = NIL; /* ptr to block of available headers */ +static int nfreehdrs = 0; /* # of headers in current block */ +static Freehdr freehdrlist = NIL; /* List of available headers */ + +/* error checking */ +static error(); /* sets errno; prints msg and aborts if DEBUG is on */ + +#ifdef DEBUG /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ + +int malloc_debug(/*level*/); +int malloc_verify(); +static int debug_level = 1; + +/* + * A block with a negative size, a size that is not a multiple + * of ALIGNSIZ, a size greater than the current extent of the + * heap, or a size which extends beyond the end of the heap is + * considered bad. + */ + +#define badblksize(p,size)\ +( (size) < SMALLEST_BLK \ + || (size) & (ALIGNSIZ-1) \ + || (size) > heapsize() \ + || ((char*)(p))+(size) > _ubound ) + +#else !DEBUG ================================================= + +#define malloc_debug(level) 0 +#define malloc_verify() 1 +#define debug_level 0 +#define badblksize(p,size) 0 + +#endif !DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +/* + * insert (newblk, len) + * Inserts a new node in the free space tree, placing it + * in the correct position with respect to the existing nodes. + * + * algorithm: + * Starting from the root, a binary search is made for the new + * node. If this search were allowed to continue, it would + * eventually fail (since there cannot already be a node at the + * given address); but in fact it stops when it reaches a node in + * the tree which has a length less than that of the new node (or + * when it reaches a null tree pointer). + * + * The new node is then inserted at the root of the subtree for + * which the shorter node forms the old root (or in place of the + * null pointer). + */ + +static +insert(newblk, len) + register Dblk newblk; /* Ptr to the block to insert */ + register uint len; /* Length of new node */ +{ + register Freehdr *fpp; /* Address of ptr to subtree */ + register Freehdr x; + register Freehdr *left_hook; /* Temp for insertion */ + register Freehdr *right_hook; /* Temp for insertion */ + register Freehdr newhdr; + + /* + * check for bad block size. + */ + if ( badblksize(newblk,len) ) { + error("insert: bad block size (%d) at %#x\n", len, newblk); + return; + } + + /* + * Search for the first node which has a weight less + * than that of the new node; this will be the + * point at which we insert the new node. + */ + fpp = &_root; + x = *fpp; + while (weight(x) >= len) { + if (newblk < x->block) + fpp = &x->left; + else + fpp = &x->right; + x = *fpp; + } + + /* + * Perform root insertion. The variable x traces a path through + * the fpp, and with the help of left_hook and right_hook, + * rewrites all links that cross the territory occupied + * by newblk. + */ + + if ((newhdr = getfreehdr()) == NIL) { + /* Error message returned by getfreehdr() */ + return; + } + *fpp = newhdr; + + newhdr->left = NIL; + newhdr->right = NIL; + newhdr->block = newblk; + newhdr->size = len; + + /* + * set length word in the block for consistency with the header. + */ + + newblk->size = len; + + left_hook = &newhdr->left; + right_hook = &newhdr->right; + + while (x != NIL) { + /* + * Remark: + * The name 'left_hook' is somewhat confusing, since + * it is always set to the address of a .right link + * field. However, its value is always an address + * below (i.e., to the left of) newblk. Similarly + * for right_hook. The values of left_hook and + * right_hook converge toward the value of newblk, + * as in a classical binary search. + */ + if (x->block < newblk) { + /* + * rewrite link crossing from the left + */ + *left_hook = x; + left_hook = &x->right; + x = x->right; + } else { + /* + * rewrite link crossing from the right + */ + *right_hook = x; + right_hook = &x->left; + x = x->left; + } /*else*/ + } /*while*/ + + *left_hook = *right_hook = NIL; /* clear remaining hooks */ + +} /*insert*/ + + +/* + * delete(p) + * deletes a node from a cartesian tree. p is the address of + * a pointer to the node which is to be deleted. + * + * algorithm: + * The left and right branches of the node to be deleted define two + * subtrees which are to be merged and attached in place of the + * deleted node. Each node on the inside edges of these two + * subtrees is examined and longer nodes are placed above the + * shorter ones. + * + * On entry: + * *p is assumed to be non-null. + */ +static +delete(p) + register Freehdr *p; +{ + register Freehdr x; + register Freehdr left_branch; /* left subtree of deleted node */ + register Freehdr right_branch; /* right subtree of deleted node */ + register uint left_weight; + register uint right_weight; + + x = *p; + left_branch = x->left; + left_weight = weight(left_branch); + right_branch = x->right; + right_weight = weight(right_branch); + + while (left_branch != right_branch) { + /* + * iterate until left branch and right branch are + * both NIL. + */ + if ( left_weight >= right_weight ) { + /* + * promote the left branch + */ + if (left_branch != NIL) { + if (left_weight == 0) { + /* zero-length block */ + error("blocksize=0 at %#x\n", + (int)left_branch->block->data); + break; + } + *p = left_branch; + p = &left_branch->right; + left_branch = *p; + left_weight = weight(left_branch); + } + } else { + /* + * promote the right branch + */ + if (right_branch != NIL) { + if (right_weight == 0) { + /* zero-length block */ + error("blocksize=0 at %#x\n", + (int)right_branch->block->data); + break; + } + *p = right_branch; + p = &right_branch->left; + right_branch = *p; + right_weight = weight(right_branch); + } + }/*else*/ + }/*while*/ + *p = NIL; + putfreehdr(x); +} /*delete*/ + + +/* + * demote(p) + * Demotes a node in a cartesian tree, if necessary, to establish + * the required vertical ordering. + * + * algorithm: + * The left and right subtrees of the node to be demoted are to + * be partially merged and attached in place of the demoted node. + * The nodes on the inside edges of these two subtrees are + * examined and the longer nodes are placed above the shorter + * ones, until a node is reached which has a length no greater + * than that of the node being demoted (or until a null pointer + * is reached). The node is then attached at this point, and + * the remaining subtrees (if any) become its descendants. + * + * on entry: + * a. All the nodes in the tree, including the one to be demoted, + * must be correctly ordered horizontally; + * b. All the nodes except the one to be demoted must also be + * correctly positioned vertically. The node to be demoted + * may be already correctly positioned vertically, or it may + * have a length which is less than that of one or both of + * its progeny. + * c. *p is non-null + */ + +static +demote(p) + register Freehdr *p; +{ + register Freehdr x; /* addr of node to be demoted */ + register Freehdr left_branch; + register Freehdr right_branch; + register uint left_weight; + register uint right_weight; + register uint x_weight; + + x = *p; + x_weight = weight(x); + left_branch = x->left; + right_branch = x->right; + left_weight = weight(left_branch); + right_weight = weight(right_branch); + + while (left_weight > x_weight || right_weight > x_weight) { + /* + * select a descendant branch for promotion + */ + if (left_weight >= right_weight) { + /* + * promote the left branch + */ + *p = left_branch; + p = &left_branch->right; + left_branch = *p; + left_weight = weight(left_branch); + } else { + /* + * promote the right branch + */ + *p = right_branch; + p = &right_branch->left; + right_branch = *p; + right_weight = weight(right_branch); + } /*else*/ + } /*while*/ + + *p = x; /* attach demoted node here */ + x->left = left_branch; + x->right = right_branch; + +} /*demote*/ + + +/* + * char* + * malloc(nbytes) + * Allocates a block of length specified in bytes. If nbytes is + * zero, a valid pointer (that should not be dereferenced) is returned. + * + * algorithm: + * The freelist is searched by descending the tree from the root + * so that at each decision point the "better fitting" branch node + * is chosen (i.e., the shorter one, if it is long enough, or + * the longer one, otherwise). The descent stops when both + * branch nodes are too short. + * + * function result: + * Malloc returns a pointer to the allocated block. A null + * pointer indicates an error. + * + * diagnostics: + * + * ENOMEM: storage could not be allocated. + * + * EINVAL: either the argument was invalid, or the heap was found + * to be in an inconsistent state. More detailed information may + * be obtained by enabling range checks (cf., malloc_debug()). + * + * Note: In this implementation, each allocated block includes a + * length word, which occurs before the address seen by the caller. + * Allocation requests are rounded up to a multiple of wordsize. + */ + +ptr_t +malloc(nbytes) + register uint nbytes; +{ + register Freehdr allocp; /* ptr to node to be allocated */ + register Freehdr *fpp; /* for tree modifications */ + register Freehdr left_branch; + register Freehdr right_branch; + register uint left_weight; + register uint right_weight; + Dblk retblk; /* block returned to the user */ + + /* + * if rigorous checking was requested, do it. + */ + if (debug_level >= 2) { + malloc_verify(); + } + + /* + * add the size of a length word to the request, and + * guarantee at least one word of usable data. + */ + nbytes += ALIGNSIZ; + if (nbytes < SMALLEST_BLK) { + nbytes = SMALLEST_BLK; + } else { + nbytes = roundup(nbytes, ALIGNSIZ); + } + + /* + * ensure that at least one block is big enough to satisfy + * the request. + */ + + if (weight(_root) < nbytes) { + /* + * the largest block is not enough. + */ + if(!morecore(nbytes)) + return 0; + } + + /* + * search down through the tree until a suitable block is + * found. At each decision point, select the better + * fitting node. + */ + + fpp = &_root; + allocp = *fpp; + left_branch = allocp->left; + right_branch = allocp->right; + left_weight = weight(left_branch); + right_weight = weight(right_branch); + + while (left_weight >= nbytes || right_weight >= nbytes) { + if (left_weight <= right_weight) { + if (left_weight >= nbytes) { + fpp = &allocp->left; + allocp = left_branch; + } else { + fpp = &allocp->right; + allocp = right_branch; + } + } else { + if (right_weight >= nbytes) { + fpp = &allocp->right; + allocp = right_branch; + } else { + fpp = &allocp->left; + allocp = left_branch; + } + } + left_branch = allocp->left; + right_branch = allocp->right; + left_weight = weight(left_branch); + right_weight = weight(right_branch); + } /*while*/ + + /* + * allocate storage from the selected node. + */ + + if (allocp->size - nbytes <= SMALLEST_BLK) { + /* + * not big enough to split; must leave at least + * a dblk's worth of space. + */ + retblk = allocp->block; + delete(fpp); + } else { + + /* + * Split the selected block n bytes from the top. The + * n bytes at the top are returned to the caller; the + * remainder of the block goes back to free space. + */ + register Dblk nblk; + + retblk = allocp->block; + nblk = nextblk(retblk, nbytes); /* ^next block */ + nblk->size = allocp->size = retblk->size - nbytes; + __mallinfo.ordblks++; /* count fragments */ + + /* + * Change the selected node to point at the newly split + * block, and move the node to its proper place in + * the free space list. + */ + allocp->block = nblk; + demote(fpp); + + /* + * set the length field of the allocated block; we need + * this because free() does not specify a length. + */ + retblk->size = nbytes; + } + /* maintain statistics */ + __mallinfo.uordbytes += retblk->size; /* bytes allocated */ + __mallinfo.allocated++; /* frags allocated */ + if (nbytes < __mallinfo.mxfast) + __mallinfo.smblks++; /* kludge to pass the SVVS */ + + return((ptr_t)retblk->data); + +} /*malloc*/ + +/* + * free(p) + * return a block to the free space tree. + * + * algorithm: + * Starting at the root, search for and coalesce free blocks + * adjacent to one given. When the appropriate place in the + * tree is found, insert the given block. + * + * Some sanity checks to avoid total confusion in the tree. + * If the block has already been freed, return. + * If the ptr is not from the sbrk'ed space, return. + * If the block size is invalid, return. + */ +free_t +free(ptr) + ptr_t ptr; +{ + register uint nbytes; /* Size of node to be released */ + register Freehdr *fpp; /* For deletion from free list */ + register Freehdr neighbor; /* Node to be coalesced */ + register Dblk neighbor_blk; /* Ptr to potential neighbor */ + register uint neighbor_size; /* Size of potential neighbor */ + register Dblk oldblk; /* Ptr to block to be freed */ + + /* + * if rigorous checking was requested, do it. + */ + if (debug_level >= 2) { + malloc_verify(); + } + + /* + * Check the address of the old block. + */ + if ( misaligned(ptr) ) { + error("free: illegal address (%#x)\n", ptr); + free_return(0); + } + + /* + * Freeing something that wasn't allocated isn't + * exactly kosher, but fclose() does it routinely. + */ + if( ptr < (ptr_t)_lbound || ptr > (ptr_t)_ubound ) { + errno = EINVAL; + free_return(0); + } + + /* + * Get node length by backing up by the size of a header. + * Check for a valid length. It must be a positive + * multiple of ALIGNSIZ, at least as large as SMALLEST_BLK, + * no larger than the extent of the heap, and must not + * extend beyond the end of the heap. + */ + oldblk = (Dblk)((char*)ptr - ALIGNSIZ); + nbytes = oldblk->size; + if (badblksize(oldblk,nbytes)) { + error("free: bad block size (%d) at %#x\n", + (int)nbytes, (int)oldblk ); + free_return(0); + } + + /* maintain statistics */ + __mallinfo.uordbytes -= nbytes; /* bytes allocated */ + __mallinfo.allocated--; /* frags allocated */ + + /* + * Search the tree for the correct insertion point for this + * node, coalescing adjacent free blocks along the way. + */ + fpp = &_root; + neighbor = *fpp; + while (neighbor != NIL) { + neighbor_blk = neighbor->block; + neighbor_size = neighbor->size; + if (oldblk < neighbor_blk) { + Dblk nblk = nextblk(oldblk,nbytes); + if (nblk == neighbor_blk) { + /* + * Absorb and delete right neighbor + */ + nbytes += neighbor_size; + __mallinfo.ordblks--; + delete(fpp); + } else if (nblk > neighbor_blk) { + /* + * The block being freed overlaps + * another block in the tree. This + * is bad news. Return to avoid + * further fouling up the the tree. + */ + error("free: blocks %#x, %#x overlap\n", + (int)oldblk, (int)neighbor_blk); + free_return(0); + } else { + /* + * Search to the left + */ + fpp = &neighbor->left; + } + } else if (oldblk > neighbor_blk) { + Dblk nblk = nextblk(neighbor_blk, neighbor_size); + if (nblk == oldblk) { + /* + * Absorb and delete left neighbor + */ + oldblk = neighbor_blk; + nbytes += neighbor_size; + __mallinfo.ordblks--; + delete(fpp); + } else if (nblk > oldblk) { + /* + * This block has already been freed + */ + error("free: block %#x was already free\n", + (int)ptr); + free_return(0); + } else { + /* + * search to the right + */ + fpp = &neighbor->right; + } + } else { + /* + * This block has already been freed + * as "oldblk == neighbor_blk" + */ + error("free: block %#x was already free\n", (int)ptr); + free_return(0); + } /*else*/ + + /* + * Note that this depends on a side effect of + * delete(fpp) in order to terminate the loop! + */ + neighbor = *fpp; + + } /*while*/ + + /* + * Insert the new node into the free space tree + */ + insert( oldblk, nbytes ); + free_return(1); + +} /*free*/ + + +/* + * char* + * shrink(oldblk, oldsize, newsize) + * Decreases the size of an old block to a new size. + * Returns the remainder to free space. Returns the + * truncated block to the caller. + */ + +static char * +shrink(oldblk, oldsize, newsize) + register Dblk oldblk; + register uint oldsize, newsize; +{ + register Dblk remainder; + if (oldsize - newsize >= SMALLEST_BLK) { + /* + * Block is to be contracted. Split the old block + * and return the remainder to free space. + */ + remainder = nextblk(oldblk, newsize); + remainder->size = oldsize - newsize; + oldblk->size = newsize; + + /* maintain statistics */ + __mallinfo.ordblks++; /* count fragments */ + __mallinfo.allocated++; /* negate effect of free() */ + + free(remainder->data); + } + return(oldblk->data); +} + + +/* + * char* + * realloc(ptr, nbytes) + * + * Reallocate an old block with a new size, returning the old block + * if possible. The block returned is guaranteed to preserve the + * contents of the old block up to min(size(old block), newsize). + * + * For backwards compatibility, ptr is allowed to reference + * a block freed since the LAST call of malloc(). Thus the old + * block may be busy, free, or may even be nested within a free + * block. + * + * Some old programs have been known to do things like the following, + * which is guaranteed not to work: + * + * free(ptr); + * free(dummy); + * dummy = malloc(1); + * ptr = realloc(ptr,nbytes); + * + * This atrocity was found in the source for diff(1). + */ +ptr_t +realloc(ptr, nbytes) + ptr_t ptr; + uint nbytes; +{ + register Freehdr *fpp; + register Freehdr fp; + register Dblk oldblk; + register Dblk freeblk; + register Dblk oldneighbor; + register uint oldsize; + register uint newsize; + register uint oldneighborsize; + + /* + * Add SVR4 semantics for OS 5.x so /usr/lib librarys + * work correctly when running in BCP mode + */ + if (ptr == NULL) { + return (malloc(nbytes)); + } + + /* + * if rigorous checking was requested, do it. + */ + if (debug_level >= 2) { + malloc_verify(); + } + + /* + * Check the address of the old block. + */ + if ( misaligned(ptr) || + ptr < (ptr_t)_lbound || + ptr > (ptr_t)_ubound ) { + error("realloc: illegal address (%#x)\n", ptr); + return(NULL); + } + + /* + * check location and size of the old block and its + * neighboring block to the right. If the old block is + * at end of memory, the neighboring block is undefined. + */ + oldblk = (Dblk)((char*)ptr - ALIGNSIZ); + oldsize = oldblk->size; + if (badblksize(oldblk,oldsize)) { + error("realloc: bad block size (%d) at %#x\n", + oldsize, oldblk); + return(NULL); + } + oldneighbor = nextblk(oldblk,oldsize); + + /* *** tree search code pulled into separate subroutine *** */ + if (reclaim(oldblk, oldsize, 1) == -1) { + return(NULL); /* internal error */ + } + + /* + * At this point, we can guarantee that oldblk is out of free + * space. What we do next depends on a comparison of the size + * of the old block and the requested new block size. To do + * this, first round up the new size request. + */ + newsize = nbytes + ALIGNSIZ; /* add size of a length word */ + if (newsize < SMALLEST_BLK) { + newsize = SMALLEST_BLK; + } else { + newsize = roundup(newsize, ALIGNSIZ); + } + + /* + * Next, examine the size of the old block, and compare it + * with the requested new size. + */ + + if (oldsize >= newsize) { + /* + * Block is to be made smaller. + */ + return(shrink(oldblk, oldsize, newsize)); + } + + /* + * Block is to be expanded. Look for adjacent free memory. + */ + if ( oldneighbor < (Dblk)_ubound ) { + /* + * Search for the adjacent block in the free + * space tree. Note that the tree may have been + * modified in the earlier loop. + */ + fpp = &_root; + fp = *fpp; + oldneighborsize = oldneighbor->size; + if ( badblksize(oldneighbor, oldneighborsize) ) { + error("realloc: bad blocksize(%d) at %#x\n", + oldneighborsize, oldneighbor); + return(NULL); + } + while ( weight(fp) >= oldneighborsize ) { + freeblk = fp->block; + if (oldneighbor < freeblk) { + /* + * search to the left + */ + fpp = &(fp->left); + fp = *fpp; + } + else if (oldneighbor > freeblk) { + /* + * search to the right + */ + fpp = &(fp->right); + fp = *fpp; + } + else { /* oldneighbor == freeblk */ + /* + * neighboring block is free; is it big enough? + */ + if (oldsize + oldneighborsize >= newsize) { + /* + * Big enough. Delete freeblk, join + * oldblk to neighbor, return newsize + * bytes to the caller, and return the + * remainder to free storage. + */ + delete(fpp); + + /* maintain statistics */ + __mallinfo.ordblks--; + __mallinfo.uordbytes += oldneighborsize; + + oldsize += oldneighborsize; + oldblk->size = oldsize; + return(shrink(oldblk, oldsize, newsize)); + } else { + /* + * Not big enough. Stop looking for a + * free lunch. + */ + break; + } /*else*/ + } /*else*/ + }/*while*/ + } /*if*/ + + /* + * At this point, we know there is no free space in which to + * expand. Malloc a new block, copy the old block to the new, + * and free the old block, IN THAT ORDER. + */ + ptr = malloc(nbytes); + if (ptr != NULL) { + bcopy(oldblk->data, ptr, oldsize-ALIGNSIZ); + free(oldblk->data); + } + return(ptr); + +} /* realloc */ + + +/* + * *** The following code was pulled out of realloc() *** + * + * int + * reclaim(oldblk, oldsize, flag) + * If a block containing 'oldsize' bytes from 'oldblk' + * is in the free list, remove it from the free list. + * 'oldblk' and 'oldsize' are assumed to include the free block header. + * + * Returns 1 if block was successfully removed. + * Returns 0 if block was not in free list. + * Returns -1 if block spans a free/allocated boundary (error() called + * if 'flag' == 1). + */ +static int +reclaim(oldblk, oldsize, flag) + register Dblk oldblk; + uint oldsize; + int flag; +{ + register Dblk oldneighbor; + register Freehdr *fpp; + register Freehdr fp; + register Dblk freeblk; + register uint size; + + /* + * Search the free space list for a node describing oldblk, + * or a node describing a block containing oldblk. Assuming + * the size of blocks decreases monotonically with depth in + * the tree, the loop may terminate as soon as a block smaller + * than oldblk is encountered. + */ + + oldneighbor = nextblk(oldblk, oldsize); + + fpp = &_root; + fp = *fpp; + while ( (size = weight(fp)) >= oldsize ) { + freeblk = fp->block; + if (badblksize(freeblk,size)) { + error("realloc: bad block size (%d) at %#x\n", + size, freeblk); + return(-1); + } + if ( oldblk == freeblk ) { + /* + * |<-- freeblk ... + * _________________________________ + * |<-- oldblk ... + * --------------------------------- + * Found oldblk in the free space tree; delete it. + */ + delete(fpp); + + /* maintain statistics */ + __mallinfo.uordbytes += oldsize; + __mallinfo.allocated++; + return(1); + } + else if (oldblk < freeblk) { + /* + * |<-- freeblk ... + * _________________________________ + * |<--oldblk ... + * --------------------------------- + * Search to the left for oldblk + */ + fpp = &fp->left; + fp = *fpp; + } + else { + /* + * |<-- freeblk ... + * _________________________________ + * | |<--oldblk--->|<--oldneighbor + * --------------------------------- + * oldblk is somewhere to the right of freeblk. + * Check to see if it lies within freeblk. + */ + register Dblk freeneighbor; + freeneighbor = nextblk(freeblk, freeblk->size); + if (oldblk >= freeneighbor) { + /* + * |<-- freeblk--->|<--- freeneighbor ... + * _________________________________ + * | |<--oldblk--->| + * --------------------------------- + * no such luck; search to the right. + */ + fpp = &fp->right; + fp = *fpp; + } + else { + /* + * freeblk < oldblk < freeneighbor; + * i.e., oldblk begins within freeblk. + */ + if (oldneighbor > freeneighbor) { + /* + * |<-- freeblk--->|<--- freeneighbor + * _________________________________ + * | |<--oldblk--->|<--oldneighbor + * --------------------------------- + * oldblk straddles a block boundary! + */ + if (flag) { + error("realloc: block %#x straddles free block boundary\n", oldblk); + } + return(-1); + } + else if ( oldneighbor == freeneighbor ) { + /* + * |<-------- freeblk------------->| + * _________________________________ + * | |<--oldblk--->| + * --------------------------------- + * Oldblk is on the right end of + * freeblk. Delete freeblk, split + * into two fragments, and return + * the one on the left to free space. + */ + delete(fpp); + + /* maintain statistics */ + __mallinfo.ordblks++; + __mallinfo.uordbytes += oldsize; + __mallinfo.allocated += 2; + + freeblk->size -= oldsize; + free(freeblk->data); + return(1); + } + else { + /* + * |<-------- freeblk------------->| + * _________________________________ + * | |oldblk | oldneighbor | + * --------------------------------- + * Oldblk is in the middle of freeblk. + * Delete freeblk, split into three + * fragments, and return the ones on + * the ends to free space. + */ + delete(fpp); + + /* maintain statistics */ + __mallinfo.ordblks += 2; + __mallinfo.uordbytes += freeblk->size; + __mallinfo.allocated += 3; + + /* + * split the left fragment by + * subtracting the size of oldblk + * and oldblk's neighbor + */ + freeblk->size -= + ( (char*)freeneighbor + - (char*)oldblk ); + /* + * split the right fragment by + * setting oldblk's neighbor's size + */ + oldneighbor->size = + (char*)freeneighbor + - (char*)oldneighbor; + /* + * return the fragments to free space + */ + free(freeblk->data); + free(oldneighbor->data); + return(1); + } /*else*/ + } /*else*/ + } /* else */ + } /*while*/ + + return(0); /* free block not found */ +} + +/* + * bool + * morecore(nbytes) + * Add a block of at least nbytes from end-of-memory to the + * free space tree. + * + * return value: + * true if at least n bytes can be allocated + * false otherwise + * + * remarks: + * + * -- free space (delimited by the extern variable _ubound) is + * extended by an amount determined by rounding nbytes up to + * a multiple of the system page size. + * + * -- The lower bound of the heap is determined the first time + * this routine is entered. It does NOT necessarily begin at + * the end of static data space, since startup code (e.g., for + * profiling) may have invoked sbrk() before we got here. + */ + +static bool +morecore(nbytes) + uint nbytes; +{ + Dblk p; + Freehdr newhdr; + + if (nbpg == 0) { + nbpg = getpagesize(); + /* hack to avoid fragmenting the heap with the first + freehdr page */ + if ((newhdr = getfreehdr()) == NIL) { + /* Error message returned by getfreehdr() */ + return(false); + } + (void)putfreehdr(newhdr); + } + nbytes = roundup(nbytes, nbpg); + p = (Dblk) sbrk((int)nbytes); + if (p == (Dblk) -1) { + if (errno == EAGAIN) errno = ENOMEM; + return(false); /* errno = ENOMEM */ + } + if (_lbound == NULL) /* set _lbound the first time through */ + _lbound = (char*) p; + _ubound = (char *) p + nbytes; + p->size = nbytes; + + /* maintain statistics */ + __mallinfo.arena = _ubound - _lbound; + __mallinfo.uordbytes += nbytes; + __mallinfo.ordblks++; + __mallinfo.allocated++; + + free(p->data); + return(true); + +} /*morecore*/ + + +/* + * Get a free block header from the free header list. + * When the list is empty, allocate an array of headers. + * When the array is empty, allocate another one. + * When we can't allocate another array, we're in deep weeds. + */ +static Freehdr +getfreehdr() +{ + Freehdr r; + register Dblk blk; + register uint size; + + if (freehdrlist != NIL) { + r = freehdrlist; + freehdrlist = freehdrlist->left; + return(r); + } + if (nfreehdrs <= 0) { + size = NFREE_HDRS*sizeof(struct freehdr) + ALIGNSIZ; + blk = (Dblk) sbrk(size); + if ((int)blk == -1) { + malloc_debug(1); + error("getfreehdr: out of memory"); + if (errno == EAGAIN) errno = ENOMEM; + return(NIL); + } + if (_lbound == NULL) /* set _lbound on first allocation */ + _lbound = (char*)blk; + blk->size = size; + freehdrptr = (Freehdr)blk->data; + nfreehdrs = NFREE_HDRS; + _ubound = (char*) nextblk(blk,size); + + /* maintain statistics */ + __mallinfo.arena = _ubound - _lbound; + __mallinfo.treeoverhead += size; + } + nfreehdrs--; + return(freehdrptr++); +} + +/* + * Free a free block header + * Add it to the list of available headers. + */ +static +putfreehdr(p) + Freehdr p; +{ + p->left = freehdrlist; + freehdrlist = p; +} + + +#ifndef DEBUG /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ + +/* + * stubs for error handling and diagnosis routines. These are what + * you get in the standard C library; for non-placebo diagnostics + * load /usr/lib/malloc.debug.o with your program. + */ +/*ARGSUSED*/ +static +error(fmt, arg1, arg2, arg3) + char *fmt; + int arg1, arg2, arg3; +{ + errno = EINVAL; +} + +#endif !DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + + +#ifdef DEBUG /* >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> */ + +/* + * malloc_debug(level) + * + * description: + * + * Controls the level of error diagnosis and consistency checking + * done by malloc() and free(). level is interpreted as follows: + * + * 0: malloc() and free() return 0 if error detected in arguments + * (errno is set to EINVAL) + * 1: malloc() and free() abort if errors detected in arguments + * 2: same as 1, but scan entire heap for errors on every call + * to malloc() or free() + * + * function result: + * returns the previous level of error reporting. + */ +int +malloc_debug(level) + int level; +{ + int old_level; + old_level = debug_level; + debug_level = level; + return old_level; +} + +/* + * check a free space tree pointer. Should be in + * the static free pool or somewhere in the heap. + */ + +#define chkblk(p)\ + if ( misaligned(p)\ + || ((Dblk)(p) < (Dblk)_lbound || (Dblk)(p) > (Dblk)_ubound)){\ + blkerror(p);\ + return 0;\ + } + +#define chkhdr(p) chkblk(p) + +static blkerror(p) + Freehdr p; +{ + error("Illegal block address (%#x)\n", (p)); +} + +/* + * cartesian(p) + * returns 1 if free space tree p satisfies internal consistency + * checks. + */ + +static int +cartesian(p) + register Freehdr p; +{ + register Freehdr probe; + register Dblk db,pdb; + + if (p == NIL) /* no tree to test */ + return 1; + /* + * check that root has a data block + */ + chkhdr(p); + pdb = p->block; + chkblk(pdb); + + /* + * check that the child blocks are no larger than the parent block. + */ + probe = p->left; + if (probe != NIL) { + chkhdr(probe); + db = probe->block; + chkblk(db); + if (probe->size > p->size) /* child larger than parent */ + return 0; + } + probe = p->right; + if (probe != NIL) { + chkhdr(probe); + db = probe->block; + chkblk(db); + if (probe->size > p->size) /* child larger than parent */ + return 0; + } + /* + * test data addresses in the left subtree, + * starting at the left subroot and probing to + * the right. All data addresses must be < p->block. + */ + probe = p->left; + while (probe != NIL) { + chkhdr(probe); + db = probe->block; + chkblk(db); + if ( nextblk(db, probe->size) >= pdb ) /* overlap */ + return 0; + probe = probe->right; + } + /* + * test data addresses in the right subtree, + * starting at the right subroot and probing to + * the left. All addresses must be > nextblk(p->block). + */ + pdb = nextblk(pdb, p->size); + probe = p->right; + while (probe != NIL) { + chkhdr(probe); + db = probe->block; + chkblk(db); + if (db == NULL || db <= pdb) /* overlap */ + return 0; + probe = probe->left; + } + return (cartesian(p->left) && cartesian(p->right)); +} + +/* + * malloc_verify() + * + * This is a verification routine. It walks through all blocks + * in the heap (both free and busy) and checks for bad blocks. + * malloc_verify returns 1 if the heap contains no detectably bad + * blocks; otherwise it returns 0. + */ + +int +malloc_verify() +{ + register int maxsize; + register int hdrsize; + register int size; + register Dblk p; + uint lb,ub; + + extern char end[]; + + if (_lbound == NULL) /* no allocation yet */ + return 1; + + /* + * first check heap bounds pointers + */ + lb = (uint)end; + ub = (uint)sbrk(0); + + if ((uint)_lbound < lb || (uint)_lbound > ub) { + error("malloc_verify: illegal heap lower bound (%#x)\n", + _lbound); + return 0; + } + if ((uint)_ubound < lb || (uint)_ubound > ub) { + error("malloc_verify: illegal heap upper bound (%#x)\n", + _ubound); + return 0; + } + maxsize = heapsize(); + p = (Dblk)_lbound; + while (p < (Dblk) _ubound) { + size = p->size; + if ( (size) < SMALLEST_BLK + || (size) & (ALIGNSIZ-1) + || (size) > heapsize() + || ((char*)(p))+(size) > _ubound ) { + error("malloc_verify: bad block size (%d) at %#x\n", + size, p); + return(0); /* Badness */ + } + p = nextblk(p, size); + } + if (p > (Dblk) _ubound) { + error("malloc_verify: heap corrupted\n"); + return(0); + } + if (!cartesian(_root)){ + error("malloc_verify: free space tree corrupted\n"); + return(0); + } + return(1); +} + +/* + * The following is a kludge to avoid dependency on stdio, which + * uses malloc() and free(), one of which probably got us here in + * the first place. + */ + +#define putchar(c) (*buf++ = (c)) +extern int fileno(); /*bletch*/ +#define stderr 2 /*bletch*/ +#define LBUFSIZ 256 + +static char stderrbuf[LBUFSIZ]; + +/*VARARGS2*/ +static +sprintf( string, fmt, x1, x2, x3 ) + char *string; + register char *fmt; + uint x1,x2,x3; +{ + register char *buf = string; + uint *argp = &x1; + register char c; + + while ( c = *fmt++ ) { + if (c != '%') { + putchar(c); + } else { + /* + * print formatted argument + */ + register uint x; + unsigned short radix; + char prbuf[12]; + register char *cp; + + x = *argp++; + + switch( c = *fmt++ ) { + case 'd': + radix = 10; + if ((int)x < 0) { + putchar('-'); + x = (unsigned)(-(int)x); + } + break; + case '#': + c = *fmt++; + if (c == 'x') { + putchar('0'); + putchar(c); + } + /*FALL THROUGH*/ + case 'x': + radix = 16; + break; + default: + putchar(c); + continue; + } /*switch*/ + + cp = prbuf; + do { + *cp++ = "0123456789abcdef"[x%radix]; + x /= radix; + } while(x); + do { + putchar(*--cp); + } while(cp > prbuf); + }/*if*/ + } /*while*/ + + putchar('\0'); + return(buf - string); + +} /*sprintf*/ + +/* + * Error routine. + * If debug_level == 0, does nothing except set errno = EINVAL. + * Otherwise, prints an error message to stderr and generates a + * core image. + */ + +/*VARARGS1*/ +static +error(fmt, arg1, arg2, arg3) + char *fmt; + int arg1, arg2, arg3; +{ + static n = 0; /* prevents infinite recursion when using stdio */ + register int nbytes; + + errno = EINVAL; + if (debug_level == 0) + return; + if (!n++) { + nbytes = sprintf(stderrbuf, fmt, arg1, arg2, arg3); + stderrbuf[nbytes++] = '\n'; + stderrbuf[nbytes] = '\0'; + write(fileno(stderr), stderrbuf, nbytes); + } + abort(); +} + +#endif DEBUG <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< diff --git a/usr/src/lib/libbc/libc/gen/common/mallopt.c b/usr/src/lib/libbc/libc/gen/common/mallopt.c new file mode 100644 index 0000000000..e85c847db5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mallopt.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +#include "mallint.h" +#include <errno.h> + +/* + * mallopt -- System V-compatible malloc "optimizer" + */ +mallopt(cmd, value) +int cmd, value; +{ + if (__mallinfo.smblks != 0) + return(-1); /* small block has been allocated */ + + switch (cmd) { + case M_MXFAST: /* small block size */ + if (value < 0) + return(-1); + __mallinfo.mxfast = value; + break; + + case M_NLBLKS: /* # small blocks per holding block */ + if (value <= 0) + return(-1); + __mallinfo.nlblks = value; + break; + + case M_GRAIN: /* small block rounding factor */ + if (value <= 0) + return(-1); + /* round up to multiple of minimum alignment */ + __mallinfo.grain = roundup(value, ALIGNSIZ); + break; + + case M_KEEP: /* Sun algorithm always preserves data */ + break; + + default: + return(-1); + } + + /* make sure that everything is consistent */ + __mallinfo.mxfast = roundup(__mallinfo.mxfast, __mallinfo.grain); + + return(0); +} + + +/* + * mallinfo -- System V-compatible malloc information reporter + */ +struct mallinfo +mallinfo() +{ + struct mallinfo mi; + + mi = __mallinfo; + mi.uordblks = mi.uordbytes - (mi.allocated * sizeof(uint)); + mi.fordblks = mi.arena - (mi.treeoverhead + mi.uordblks + + (mi.ordblks * sizeof(uint))); + return(mi); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mbextern.h b/usr/src/lib/libbc/libc/gen/common/mbextern.h new file mode 100644 index 0000000000..b858e7e321 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mbextern.h @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifndef lint +/* static char *sccsid = "%Z%%M% %I% %E% SMI"; */ +#endif + +/* + * external declaration for mb* routines + */ + +extern struct _code_set_info _code_set_info; diff --git a/usr/src/lib/libbc/libc/gen/common/mblib.c b/usr/src/lib/libbc/libc/gen/common/mblib.c new file mode 100644 index 0000000000..855dc0e6d8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mblib.c @@ -0,0 +1,89 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * misc routines + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <stdio.h> +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" +#include <dlfcn.h> + +static void *handle = (void *)NULL; /* initialize it with -1 */ + +/* + * Close current library library + */ +_ml_close_library() +{ + if (handle == (void *)NULL) { + _code_set_info.open_flag = NULL; + return; + } + + dlclose(handle); + _code_set_info.open_flag = NULL; + handle = (void *)NULL; + return(0); +} + +/* + * Open the given library + */ +void * +_ml_open_library() +{ + char buf[BUFSIZ]; + + if (handle != (void *)NULL) /* This library is already opened */ + return(handle); + + /* + * Open the given library + */ + strcpy(buf, LIBRARY_PATH); + strcat(buf, _code_set_info.code_name); + strcat(buf, ".so"); +#ifdef DEBUG + printf ("ml_open_library: buf = '%s'\n", buf); +#endif + handle = dlopen(buf, 1); + if (handle != (void *)NULL) + _code_set_info.open_flag = 1; +#ifdef DEBUG + else + printf ("_ml_open_library: dlopen failed\n"); +#endif + return(handle); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mbstowcs.c b/usr/src/lib/libbc/libc/gen/common/mbstowcs.c new file mode 100644 index 0000000000..1216ccbd45 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mbstowcs.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * mbstowcs + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" + +int +mbstowcs(pwcs, s, n) + wchar_t * pwcs; + char *s; + size_t n; +{ + char *handle; /* handle */ + int (*p)(); + int num = 0; + int ret; + + switch (_code_set_info.code_id) { + case CODESET_NONE: + /* + * default code set, + */ + while (*s && num < n) { + *pwcs++ = (wchar_t)*s++; + num++; + } + if (num < n) + *pwcs = 0; + return (num); + break; + case CODESET_EUC: + /* + * EUC code set + */ + return(_mbstowcs_euc(pwcs, s, n)); + break; + + case CODESET_XCCS: + /* + * XCCS code set + */ + return(_mbstowcs_xccs(pwcs, s, n)); + break; + + case CODESET_ISO2022: + /* + * ISO family + */ + return(_mbstowcs_iso(pwcs, s, n)); + break; + + default: + /* + * User defined code set + */ + handle = _ml_open_library(); + if (handle == (void *)NULL) + return(ERROR_NO_LIB); /* No user library */ + p = (int (*)()) dlsym(handle, "_mbstowcs"); + if (p == (int (*)()) NULL) + return(ERROR_NO_SYM); + ret = (*p)(pwcs, s, n); + return (ret); + break; + } + /* NOTREACHED */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/mbtowc.c b/usr/src/lib/libbc/libc/gen/common/mbtowc.c new file mode 100644 index 0000000000..9fbedb48c9 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mbtowc.c @@ -0,0 +1,132 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1997 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * mbtowc + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <stdlib.h> +#include "codeset.h" +#include "mbextern.h" + +#undef mblen + +int +mbtowc(pwc, s, n) + wchar_t * pwc; + char *s; + size_t n; +{ + char *handle; /* handle */ + int (*p)(); + int ret; + + switch (_code_set_info.code_id) { + case CODESET_NONE: +#ifdef DEBUG + printf ("DEFAULT: mbtowc invoked\n"); +#endif + /* + * This is a default code set + */ + if (s == NULL) + return (1); + else { + if (pwc != NULL) + *pwc = (unsigned char)*s; + return (1); + } + break; + case CODESET_EUC: +#ifdef DEBUG + printf ("EUC: mbtowc invoked\n"); +#endif + /* + * EUC code set + */ + return(_mbtowc_euc(pwc, s, n)); + break; + + case CODESET_XCCS: +#ifdef DEBUG + printf ("XCCS: mbtowc invoked\n"); +#endif + /* + * XCCS code set + */ + return(_mbtowc_xccs(pwc, s, n)); + break; + + case CODESET_ISO2022: +#ifdef DEBUG + printf ("ISO2022: mbtowc invoked\n"); +#endif + /* + * ISO family + */ + return(_mbtowc_iso(pwc, s, n)); + break; + + default: + /* + * User defined code set + */ + handle = _ml_open_library(); + if (handle == (char *)NULL) + return(ERROR_NO_LIB); /* No user library */ + p = (int (*)()) dlsym(handle, "_mbtowc"); + if (p == (int (*)()) NULL) + return(ERROR_NO_SYM); + ret = (*p)(pwc, s, n); + return (ret); + break; + } + /* NOTREACHED */ +} + +int mblen(s, n) +register char *s; int n; +{ + int val; + + if (_code_set_info.code_id != CODESET_ISO2022) + return (mbtowc((wchar_t *)0, s, n)); + else { + /* + * ISO's mbtowc() changes 'states'. + */ + _savestates(); + val = mbtowc((wchar_t *)0, s, n); + _restorestates(); + return (val); + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/memalign.c b/usr/src/lib/libbc/libc/gen/common/memalign.c new file mode 100644 index 0000000000..a71c2a06f8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/memalign.c @@ -0,0 +1,142 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "mallint.h" +#include <errno.h> + +extern int errno; + +/* + * memalign(align,nbytes) + * + * Description: + * Returns a block of specified size on a specified alignment boundary. + * + * Algorithm: + * Malloc enough to ensure that a block can be aligned correctly. + * Find the alignment point and return the fragments + * before and after the block. + * + * Errors: + * Returns NULL and sets errno as follows: + * [EINVAL] + * if nbytes = 0, + * or if alignment is misaligned, + * or if the heap has been detectably corrupted. + * [ENOMEM] + * if the requested memory could not be allocated. + */ + +char * +memalign(align, nbytes) + uint align; + uint nbytes; +{ + uint reqsize; /* Num of bytes to get from malloc() */ + register char *p; /* Ptr returned from malloc() */ + register Dblk blk; /* For addressing fragment blocks */ + register uint blksize; /* Current (shrinking) block size */ + register char *alignedp; /* Ptr to properly aligned boundary */ + register Dblk aligned_blk; /* The block to be returned */ + register uint frag_size; /* size of fragments fore and aft */ + uint x; /* ccom can't do (char*)(uint/uint) */ + + /* + * check for valid size and alignment parameters + */ + if (nbytes == 0 || misaligned(align)) { + errno = EINVAL; + return NULL; + } + + /* + * Malloc enough memory to guarantee that the result can be + * aligned correctly. The worst case is when malloc returns + * a block so close to the next alignment boundary that a + * fragment of minimum size cannot be created. + */ + nbytes = roundup(nbytes, ALIGNSIZ); + reqsize = nbytes + align + SMALLEST_BLK; + p = malloc(reqsize); + if (p == NULL) { + return NULL; + } + + /* + * get size of the entire block (overhead and all) + */ + blk = (Dblk)(p - ALIGNSIZ); /* back up to get length word */ + blksize = blk->size; + + /* + * locate the proper alignment boundary within the block. + */ + x = roundup((uint)p, align); /* ccom work-around */ + alignedp = (char *)x; + aligned_blk = (Dblk)(alignedp - ALIGNSIZ); + + /* + * Check out the space to the left of the alignment + * boundary, and split off a fragment if necessary. + */ + frag_size = (uint)aligned_blk - (uint)blk; + if (frag_size != 0) { + /* + * Create a fragment to the left of the aligned block. + */ + if ( frag_size < SMALLEST_BLK ) { + /* + * Not enough space. So make the split + * at the other end of the alignment unit. + */ + frag_size += align; + aligned_blk = nextblk(aligned_blk,align); + } + blk->size = frag_size; + blksize -= frag_size; + aligned_blk->size = blksize; + free(blk->data); + } + + /* + * Is there a (sufficiently large) fragment to the + * right of the aligned block? + */ + nbytes += ALIGNSIZ; + frag_size = blksize - nbytes; + if (frag_size > SMALLEST_BLK) { + /* + * split and free a fragment on the right + */ + blk = nextblk(aligned_blk, nbytes); + blk->size = frag_size; + aligned_blk->size -= frag_size; + free(blk->data); + } + return(aligned_blk->data); +} diff --git a/usr/src/lib/libbc/libc/gen/common/memccpy.c b/usr/src/lib/libbc/libc/gen/common/memccpy.c new file mode 100644 index 0000000000..cbdc8b0db2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/memccpy.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +/* + * Copy s2 to s1, stopping if character c is copied. Copy no more than n bytes. + * Return a pointer to the byte after character c in the copy, + * or NULL if c is not found in the first n bytes. + */ +char * +memccpy(s1, s2, c, n) +register char *s1, *s2; +register int c, n; +{ + while (--n >= 0) + if ((*s1++ = *s2++) == c) + return (s1); + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/memchr.c b/usr/src/lib/libbc/libc/gen/common/memchr.c new file mode 100644 index 0000000000..89754259dd --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/memchr.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +/* + * Return the ptr in sp at which the character c appears; + * NULL if not found in n chars; don't stop at \0. + */ +char * +memchr(sp, c, n) +register char *sp, c; +register int n; +{ + while (--n >= 0) + if (*sp++ == c) + return (--sp); + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/memcmp.c b/usr/src/lib/libbc/libc/gen/common/memcmp.c new file mode 100644 index 0000000000..f4439d8005 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/memcmp.c @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +/* + * Compare n bytes: s1>s2: >0 s1==s2: 0 s1<s2: <0 + */ +int +memcmp(s1, s2, n) +register char *s1, *s2; +register int n; +{ + int diff; + + if (s1 != s2) + while (--n >= 0) + if (diff = *s1++ - *s2++) + return (diff); + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mkstemp.c b/usr/src/lib/libbc/libc/gen/common/mkstemp.c new file mode 100644 index 0000000000..b76c90788e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mkstemp.c @@ -0,0 +1,34 @@ +#pragma ident "%Z%%M% %I% %E% SMI" /* from UCB 5.2 3/9/86 */ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/file.h> + +mkstemp(as) + char *as; +{ + register char *s; + register unsigned int pid; + register int fd, i; + + pid = getpid(); + s = as; + while (*s++) + /* void */; + s--; + while (*--s == 'X') { + *s = (pid % 10) + '0'; + pid /= 10; + } + s++; + i = 'a'; + while ((fd = open(as, O_CREAT|O_EXCL|O_RDWR, 0600)) == -1) { + if (i == 'z') + return(-1); + *s = i++; + } + return(fd); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mktemp.c b/usr/src/lib/libbc/libc/gen/common/mktemp.c new file mode 100644 index 0000000000..8373996607 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mktemp.c @@ -0,0 +1,76 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R3 1.11 */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +/*LINTLIBRARY*/ +/**************************************************************** + * Routine expects a string of length at least 6, with + * six trailing 'X's. These will be overlaid with a + * letter and the last (5) digigts of the proccess ID. + * If every letter (a thru z) thus inserted leads to + * an existing file name, your string is shortened to + * length zero upon return (first character set to '\0'). + ***************************************************************/ +#include <sys/types.h> +#include <sys/stat.h> + +#define XCNT 6 + +extern int strlen(), access(), getpid(); + +char * +mktemp(as) +char *as; +{ + register char *s=as; + register unsigned pid; + register unsigned xcnt=0; /* keeps track of number of X's seen */ + struct stat buf; + + pid = getpid(); + s += strlen(as); /* point at the terminal null */ + while(*--s == 'X' && ++xcnt <= XCNT) { + *s = (pid%10) + '0'; + pid /= 10; + } + if(*++s) { /* maybe there were no 'X's */ + *s = 'a'; + while (stat(as, &buf) == 0) { + if(++*s > 'z') { + *as = '\0'; + break; + } + } + } else + if (stat(as, &buf) == 0) + *as = '\0'; + return(as); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mlock.c b/usr/src/lib/libbc/libc/gen/common/mlock.c new file mode 100644 index 0000000000..d31c9c6e08 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mlock.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <errno.h> + +/* + * Function to lock address range in memory. + */ + +/*LINTLIBRARY*/ +mlock(addr, len) + caddr_t addr; + u_int len; +{ + if((int)len <= 0) { + errno = EINVAL; + return(-1); + } + return (mctl(addr, len, MC_LOCK, 0)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mlockall.c b/usr/src/lib/libbc/libc/gen/common/mlockall.c new file mode 100644 index 0000000000..03b60a1411 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mlockall.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> + +/* + * Function to lock address space in memory. + */ + +/*LINTLIBRARY*/ +mlockall(flags) + int flags; +{ + + return (mctl(0, 0, MC_LOCKAS, flags)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/mntent.c b/usr/src/lib/libbc/libc/gen/common/mntent.c new file mode 100644 index 0000000000..853eb4ab58 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/mntent.c @@ -0,0 +1,245 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <ctype.h> +#include <mntent.h> +#include <sys/file.h> + +static struct mntent *mntp; +char *calloc(); + +struct mntent * +_mnt() +{ + + if (mntp == 0) + mntp = (struct mntent *)calloc(1, sizeof (struct mntent)); + return (mntp); +} + +static char * +mntstr(p) + register char **p; +{ + unsigned char *cp = (unsigned char *) *p; + unsigned char *retstr; + + while (*cp && isspace(*cp)) + cp++; + retstr = cp; + while (*cp && !isspace(*cp)) + cp++; + if (*cp) { + *cp = '\0'; + cp++; + } + *p = (char *) cp; + return ((char *)retstr); +} + +static int +mntdigit(p) + register char **p; +{ + register int value = 0; + unsigned char *cp = (unsigned char *) *p; + + while (*cp && isspace(*cp)) + cp++; + for (; *cp && isdigit(*cp); cp++) { + value *= 10; + value += *cp - '0'; + } + while (*cp && !isspace(*cp)) + cp++; + if (*cp) { + *cp = '\0'; + cp++; + } + *p = (char *) cp; + return (value); +} + +static +mnttabscan(mnttabp, mnt) + FILE *mnttabp; + struct mntent *mnt; +{ + static char *line = NULL; + char *cp; + + if (line == NULL) + line = (char *)malloc(BUFSIZ+1); + do { + cp = fgets(line, BUFSIZ, mnttabp); + if (cp == NULL) { + return (EOF); + } + } while (*cp == '#'); + mnt->mnt_fsname = mntstr(&cp); + if (*cp == '\0') + return (1); + mnt->mnt_dir = mntstr(&cp); + if (*cp == '\0') + return (2); + mnt->mnt_type = mntstr(&cp); + if (*cp == '\0') + return (3); + mnt->mnt_opts = mntstr(&cp); + if (*cp == '\0') + return (4); + mnt->mnt_freq = mntdigit(&cp); + if (*cp == '\0') + return (5); + mnt->mnt_passno = mntdigit(&cp); + return (6); +} + +FILE * +setmntent(fname, flag) + char *fname; + char *flag; +{ + FILE *mnttabp; + + if ((mnttabp = fopen(fname, flag)) == NULL) { + return (NULL); + } + for (; *flag ; flag++) { + if (*flag == 'w' || *flag == 'a' || *flag == '+') { + if (flock(fileno(mnttabp), LOCK_EX) < 0) { + fclose(mnttabp); + return (NULL); + } + break; + } + } + return (mnttabp); +} + +int +endmntent(mnttabp) + FILE *mnttabp; +{ + + if (mnttabp) { + fclose(mnttabp); + } + return (1); +} + +struct mntent * +getmntent(mnttabp) + FILE *mnttabp; +{ + int nfields; + + if (mnttabp == 0) + return ((struct mntent *)0); + if (_mnt() == 0) + return ((struct mntent *)0); + nfields = mnttabscan(mnttabp, mntp); + if (nfields == EOF || nfields != 6) + return ((struct mntent *)0); + return (mntp); +} + +addmntent(mnttabp, mnt) + FILE *mnttabp; + register struct mntent *mnt; +{ + if (fseek(mnttabp, 0L, 2) < 0) + return (1); + if (mnt == (struct mntent *)0) + return (1); + if (mnt->mnt_fsname == NULL || mnt->mnt_dir == NULL || + mnt->mnt_type == NULL || mnt->mnt_opts == NULL) + return (1); + + mntprtent(mnttabp, mnt); + return (0); +} + +static char * +mntopt(p) + char **p; +{ + unsigned char *cp = (unsigned char *) *p; + unsigned char *retstr; + + while (*cp && isspace(*cp)) + cp++; + retstr = cp; + while (*cp && *cp != ',') + cp++; + if (*cp) { + *cp = '\0'; + cp++; + } + *p = (char *) cp; + return ((char *)retstr); +} + +char * +hasmntopt(mnt, opt) + register struct mntent *mnt; + register char *opt; +{ + char *f, *opts; + static char *tmpopts; + + if (tmpopts == 0) { + tmpopts = (char *)calloc(256, sizeof (char)); + if (tmpopts == 0) + return (0); + } + strcpy(tmpopts, mnt->mnt_opts); + opts = tmpopts; + f = mntopt(&opts); + for (; *f; f = mntopt(&opts)) { + if (strncmp(opt, f, strlen(opt)) == 0) + return (f - tmpopts + mnt->mnt_opts); + } + return (NULL); +} + +static +mntprtent(mnttabp, mnt) + FILE *mnttabp; + register struct mntent *mnt; +{ + fprintf(mnttabp, "%s %s %s %s %d %d\n", + mnt->mnt_fsname, + mnt->mnt_dir, + mnt->mnt_type, + mnt->mnt_opts, + mnt->mnt_freq, + mnt->mnt_passno); + return(0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/modf.c b/usr/src/lib/libbc/libc/gen/common/modf.c new file mode 100644 index 0000000000..3ce1bb8256 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/modf.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" /* from ATT S5R3 */ + +/* The following is extracted from... */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +/* + * modf(value, iptr) returns the signed fractional part of value + * and stores the integer part indirectly through iptr. + * + */ + +#define MAXPOWTWO 4.503599627370496000E+15 + /* doubles >= MAXPOWTWO are already integers */ +double +modf(value, iptr) +double value; +register double *iptr; +{ + register double absvalue; + + if ((absvalue = (value >= 0.0) ? value : -value) >= MAXPOWTWO) + *iptr = value; /* it must be an integer */ + else { + *iptr = absvalue + MAXPOWTWO; /* shift fraction off right */ + *iptr -= MAXPOWTWO; /* shift back without fraction */ + while (*iptr > absvalue) /* above arithmetic might round */ + *iptr -= 1.0; /* test again just to be sure */ + if (value < 0.0) + *iptr = -*iptr; + } + return (value - *iptr); /* signed fractional part */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/msync.c b/usr/src/lib/libbc/libc/gen/common/msync.c new file mode 100644 index 0000000000..b97fc42509 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/msync.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <errno.h> + +/* + * Function to synchronize address range with backing store. + */ + +/*LINTLIBRARY*/ +msync(addr, len, flags) + caddr_t addr; + u_int len; + int flags; +{ + if ((int)len <= 0) { + errno = EINVAL; + return (-1); + } + return (mctl(addr, len, MC_SYNC, flags)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/munlock.c b/usr/src/lib/libbc/libc/gen/common/munlock.c new file mode 100644 index 0000000000..9720c5a5de --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/munlock.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> + +/* + * Function to unlock address range from memory. + */ + +/*LINTLIBRARY*/ +munlock(addr, len) + caddr_t addr; + u_int len; +{ + + return (mctl(addr, len, MC_UNLOCK, 0)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/munlockall.c b/usr/src/lib/libbc/libc/gen/common/munlockall.c new file mode 100644 index 0000000000..382f71b3f9 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/munlockall.c @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <sys/types.h> +#include <sys/mman.h> + +/* + * Function to unlock address space from memory. + */ + +/*LINTLIBRARY*/ +munlockall() +{ + + return (mctl(0, 0, MC_UNLOCKAS, 0)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ndbm.c b/usr/src/lib/libbc/libc/gen/common/ndbm.c new file mode 100644 index 0000000000..8559b4a777 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ndbm.c @@ -0,0 +1,931 @@ +/* + * Copyright 2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/file.h> +#include <stdio.h> +#include <errno.h> +#include <ndbm.h> +datum dbm_do_nextkey(/*db, key*/); + + +/*add support for batched writing for NIS*/ + +#define _DBM_DEFWRITE 0x4 +#define _DBM_DIRTY 0x8 +#define _DBM_DIRDIRTY 0x10 +#define dbm_dirty(db) ((db)->dbm_flags & _DBM_DIRTY) +#define dbm_dirdirty(db) ((db)->dbm_flags & _DBM_DIRDIRTY) +#define dbm_defwrite(db) ((db)->dbm_flags & _DBM_DEFWRITE) +#define dbm_setdirty(db) (db)->dbm_flags |= _DBM_DIRTY +#define dbm_clrdirty(db) (db)->dbm_flags &= ~_DBM_DIRTY +#define dbm_setdirdirty(db) (db)->dbm_flags |= _DBM_DIRDIRTY +#define dbm_clrdirdirty(db) (db)->dbm_flags &= ~_DBM_DIRDIRTY + +/*used to make a dbm file all at once instead of incrementally*/ +dbm_setdefwrite(db) + DBM *db; +{ + db->dbm_flags |= _DBM_DEFWRITE; +} + +dbm_flush(db) + DBM *db; +{ + int ok=0; + if (dbm_flushpag(db)<0) ok= -1; + if (dbm_flushdir(db)<0) ok= -1; + return(ok); +} + +dbm_flushpag(db) + DBM *db; +{ + int ok=0; + if (dbm_dirty(db)){ /*must page out the page*/ + (void) lseek(db->dbm_pagf, (long)(db->dbm_pagbno*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + ok= -1; + } + dbm_clrdirty(db); + } + return(ok); +} + +dbm_flushdir(db) + DBM *db; +{ + int ok=0; + if (dbm_dirdirty(db)){ /*must page out the dir*/ + (void) lseek(db->dbm_dirf, (long)(db->dbm_dirbno*DBLKSIZ), L_SET); + if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) { + ok= -1; + } + dbm_clrdirdirty(db); + } + return(ok); +} +#define BYTESIZ 8 +#undef setbit + +static datum makdatum(); +static long dcalchash(); +extern int errno; +extern char *malloc(); +extern char *strcpy(); +extern char *strcat(); + +DBM * +dbm_open(file, flags, mode) + char *file; + int flags, mode; +{ + struct stat statb; + register DBM *db; + int serrno; + + if ((db = (DBM *)malloc(sizeof *db)) == 0) { + errno = ENOMEM; + return ((DBM *)0); + } + db->dbm_flags = (flags & 03) == O_RDONLY ? _DBM_RDONLY : 0; + if ((flags & 03) == O_WRONLY) + flags = (flags & ~03) | O_RDWR; + if (strlcpy(db->dbm_pagbuf, file, sizeof (db->dbm_pagbuf)) >= + sizeof (db->dbm_pagbuf) || + strlcat(db->dbm_pagbuf, ".pag", sizeof (db->dbm_pagbuf)) >= + sizeof (db->dbm_pagbuf)) { + /* + * file.pag does not fit into dbm_pagbuf. + * fails with ENAMETOOLONG. + */ + serrno = ENAMETOOLONG; + goto bad; + } + db->dbm_pagf = open(db->dbm_pagbuf, flags, mode); + if (db->dbm_pagf < 0) { + serrno = errno; + goto bad; + } + /* + * We know this won't overflow so it is safe to ignore the + * return value; we use strl* to prevent false hits in + * code sweeps. + */ + (void) strlcpy(db->dbm_pagbuf, file, sizeof (db->dbm_pagbuf)); + (void) strlcat(db->dbm_pagbuf, ".dir", sizeof (db->dbm_pagbuf)); + db->dbm_dirf = open(db->dbm_pagbuf, flags, mode); + if (db->dbm_dirf < 0) { + serrno = errno; + goto bad1; + } + (void) fstat(db->dbm_dirf, &statb); + db->dbm_maxbno = statb.st_size*BYTESIZ-1; + db->dbm_pagbno = db->dbm_dirbno = -1; + return (db); +bad1: + (void) close(db->dbm_pagf); +bad: + free((char *)db); + errno = serrno; + return ((DBM *)0); +} + +void +dbm_close(db) + DBM *db; +{ +(void) dbm_close_status(db); +} + +/*close with return code*/ +int +dbm_close_status(db) + DBM *db; +{ + int ok; + ok=0; + + if (dbm_flush(db) <0) ok = -1; + if (close(db->dbm_dirf)<0) ok= -1; + if ( close(db->dbm_pagf)<0) ok= -1; + free((char *)db); + return(ok); +} +long +dbm_forder(db, key) + register DBM *db; + datum key; +{ + long hash; + + hash = dcalchash(key); + for (db->dbm_hmask=0;; db->dbm_hmask=(db->dbm_hmask<<1)+1) { + db->dbm_blkno = hash & db->dbm_hmask; + db->dbm_bitno = db->dbm_blkno + db->dbm_hmask; + if (getbit(db) == 0) + break; + } + return (db->dbm_blkno); +} + +datum +dbm_fetch(db, key) + register DBM *db; + datum key; +{ + register i; + datum item; + + if (dbm_error(db)) + goto err; + dbm_access(db, dcalchash(key)); + if ((i = finddatum(db->dbm_pagbuf, key)) >= 0) { + item = makdatum(db->dbm_pagbuf, i+1); + if (item.dptr != NULL) + return (item); + } +err: + item.dptr = NULL; + item.dsize = 0; + return (item); +} + +dbm_delete(db, key) + register DBM *db; + datum key; +{ + register i; + + if (dbm_error(db)) + return (-1); + if (dbm_rdonly(db)) { + errno = EPERM; + return (-1); + } + dbm_access(db, dcalchash(key)); + if ((i = finddatum(db->dbm_pagbuf, key)) < 0) + return (-1); + if (!delitem(db->dbm_pagbuf, i)) + goto err; + db->dbm_pagbno = db->dbm_blkno; + if (dbm_defwrite(db)) { + dbm_setdirty(db); + } + else { + (void) lseek(db->dbm_pagf, (long)(db->dbm_blkno*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) { + err: + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + } + return (0); +} + +dbm_store(db, key, dat, replace) + register DBM *db; + datum key, dat; + int replace; +{ + register i; + datum item, item1; + char ovfbuf[PBLKSIZ]; + + if (dbm_error(db)) + return (-1); + if (dbm_rdonly(db)) { + errno = EPERM; + return (-1); + } +loop: + dbm_access(db, dcalchash(key)); + if ((i = finddatum(db->dbm_pagbuf, key)) >= 0) { + if (!replace) + return (1); + if (!delitem(db->dbm_pagbuf, i)) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + } + if (!additem(db->dbm_pagbuf, key, dat)) + goto split; + db->dbm_pagbno = db->dbm_blkno; + if (dbm_defwrite(db)) { + dbm_setdirty(db); + } + else { + + (void) lseek(db->dbm_pagf, (long)(db->dbm_blkno*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + } + return (0); + +split: + if (key.dsize+dat.dsize+3*sizeof(short) >= PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + errno = ENOSPC; + return (-1); + } + bzero(ovfbuf, PBLKSIZ); + for (i=0;;) { + item = makdatum(db->dbm_pagbuf, i); + if (item.dptr == NULL) + break; + if (dcalchash(item) & (db->dbm_hmask+1)) { + item1 = makdatum(db->dbm_pagbuf, i+1); + if (item1.dptr == NULL) { + /*(void) fprintf(stderr, "ndbm: split not paired\n");*/ + db->dbm_flags |= _DBM_IOERR; + break; + } + if (!additem(ovfbuf, item, item1) || + !delitem(db->dbm_pagbuf, i)) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + continue; + } + i += 2; + } + db->dbm_pagbno = db->dbm_blkno; + (void) lseek(db->dbm_pagf, (long)(db->dbm_blkno*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + dbm_clrdirty(db); /*clear dirty*/ + (void) lseek(db->dbm_pagf, + (long)((db->dbm_blkno+db->dbm_hmask+1)*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, ovfbuf, PBLKSIZ) != PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + if (setbit(db) < 0) { + db->dbm_flags |= _DBM_IOERR; + return (-1); + } + goto loop; +} +static long +dbm_hashinc(db,hash) + DBM *db; + long hash; +{ + + long bit; + + hash &= db->dbm_hmask; + bit = db->dbm_hmask+1; + for(;;) { + bit >>= 1; + if(bit == 0) + return(0L); + if((hash&bit) == 0) + return(hash|bit); + hash &= ~bit; + } +} + + + +static datum nullkey= {NULL, 0}; + +datum +dbm_firsthash(db,hash) +register DBM *db; +long hash; +{ + register i,j; + datum item, bitem; + +loop: + dbm_access(db, hash); + j=0; + bitem = makdatum(db->dbm_pagbuf, 0); + for(i=2;; i+=2) { + item = makdatum(db->dbm_pagbuf, i); + if(item.dptr == NULL) + break; + if(cmpdatum(bitem, item) < 0) { + j=i; + bitem = item; + } + } + if(bitem.dptr != NULL) { + db->dbm_keyptr = j + 2; + db->dbm_blkptr = db->dbm_blkno; + return(bitem); + } + hash = dbm_hashinc(db,hash); + if(hash == 0) + return(item); /*null item*/ + goto loop; + +} + +datum +dbm_firstkey(db) + DBM *db; +{ + + db->dbm_blkptr = 0L; + db->dbm_keyptr = 0; + return (dbm_firsthash(db, 0L)); +} +datum +dbm_nextkey(db) + DBM *db; +{ + + return (dbm_do_nextkey(db, nullkey)); +} + +/*this is used if keyptr-2,blocknum doesn't point to the previous +specific key allowing the fast hash order search -- +its use indicates user tampering with our state variables, +which some evil users might do to search from some specific place. +It finds the first key at or after blkptr,keyptr in block seq order +this requires looking at all sorts of emtpy blocks in many cases*/ + +static +datum +dbm_slow_nextkey(db) + register DBM *db; + +{ + + struct stat statb; + datum item; + + if (dbm_error(db) || fstat(db->dbm_pagf, &statb) < 0) + goto err; + statb.st_size /= PBLKSIZ; + + for (;;) { + if (db->dbm_blkptr != db->dbm_pagbno) { + + if (dbm_dirty(db)) dbm_flushpag(db); + + db->dbm_pagbno = db->dbm_blkptr; + (void) lseek(db->dbm_pagf, (long)(db->dbm_blkptr*PBLKSIZ), L_SET); + if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) + bzero(db->dbm_pagbuf, PBLKSIZ); +#ifdef DEBUG + else if (chkblk(db->dbm_pagbuf) < 0) + db->dbm_flags |= _DBM_IOERR; +#endif + } + /*Am I an empty block?*/ + if (((short *)db->dbm_pagbuf)[0] != 0) { + item = makdatum(db->dbm_pagbuf, db->dbm_keyptr); + if (item.dptr != NULL) { + db->dbm_keyptr += 2; + return (item); + } + db->dbm_keyptr = 0; + } + /*go to next sequential block*/ + if (++db->dbm_blkptr >= statb.st_size) + break; + } +err: + item.dptr = NULL; + item.dsize = 0; + return (item); +} + + + +datum +dbm_do_nextkey(db, inkey) + register DBM *db; + datum inkey; +{ + datum item,bitem; + long hash; + datum key; + int f; + register i; + register j; + register short *sp; + register n; + register char *p1, *p2; + + if ( dbm_error(db) ) { + item.dptr = NULL; + item.dsize = 0; + return (item); + } + + /*user has supplied lastkey*/ + + if(inkey.dptr != NULL) { + dbm_access(db, (hash=dcalchash(inkey))); + if ((i = finddatum(db->dbm_pagbuf, inkey)) >= 0) { + db->dbm_keyptr = i + 2; + db->dbm_blkptr = db->dbm_blkno; + } + key=inkey; + } + else { + /*is this a manual firstkey request? */ + + if (db->dbm_blkptr == 0L && + db->dbm_keyptr == 0) + return(dbm_firsthash(db, 0L)); + + /*no -- get lastkey this is like dbm_access by blkptr*/ + + if (db->dbm_blkptr != db->dbm_pagbno) { + + if (dbm_dirty(db)) dbm_flushpag(db); + db->dbm_pagbno = db->dbm_blkptr; + (void) lseek(db->dbm_pagf, (long)(db->dbm_blkptr*PBLKSIZ), L_SET); + if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) + bzero(db->dbm_pagbuf, PBLKSIZ); +#ifdef DEBUG + else if (chkblk(db->dbm_pagbuf) < 0) + db->dbm_flags |= _DBM_IOERR; +#endif + } + /*now just make up last key datum*/ + if (db->dbm_keyptr >=2) key= makdatum(db->dbm_pagbuf,(db->dbm_keyptr-2)); + else key=nullkey; + + /* the keyptr pagbuf have failed us, the user must + be an extra clever moron who depends on + these variables and their former meaning. + If we set the variables this would have got + us the key for sure! So give him the old algorithm.*/ + if (key.dptr == NULL) return(dbm_slow_nextkey(db)); + } + + /*at this point the last key is paged in and + we can proceed as in old dbm -- like Ken did his. */ + + f = 1; + j=0; + sp = (short *)db->dbm_pagbuf; + + for(i=0;; i+=2) { + + /*begin put makdatum inline*/ + + if ((unsigned)i >= sp[0]) { + item.dptr = NULL; + item.dsize = 0; + break; /*from below*/ + } + else { + if (i > 0) item.dsize = sp[i] - sp[i+1]; + else item.dsize = PBLKSIZ - sp[i+1]; + item.dptr = db->dbm_pagbuf+sp[i+1]; + } + + /* item = makdatum(db->dbm_pagbuf, i);*/ + /*end put makdatum inline*/ + + if(item.dptr == NULL) + break; +/*inline cmpdatum*/ + + + n = key.dsize; + if(n != item.dsize) + if( (n - item.dsize) <= 0 ) continue; + else { } + else { + if(n == 0) continue; + p1 = key.dptr; + p2 = item.dptr; + do + if(*p1++ != *p2++) + if((*--p1 - *--p2) > 0) goto keep_going; + else continue; + while(--n); + continue; + } + +keep_going: + +/*end inline cmpdatum*/ + /*if(cmpdatum(key, item) <= 0) + continue;*/ + if (f) { + bitem = item; + j=i; + f = 0; + } + else { + +/* if(cmpdatum(bitem, item) < 0)*/ + + n = bitem.dsize; + if(n != item.dsize) + { + if((n - item.dsize) <0) { + bitem = item; + j=i; + } + } + else if (n != 0) { + p1 = bitem.dptr; + p2 = item.dptr; + do + if(*p1++ != *p2++) { + if((*--p1 - *--p2) <0) { + bitem = item; + j=i; + } + break; + } + while(--n); + } + } + } + + if(f == 0) { + db->dbm_keyptr = j + 2; + db->dbm_blkptr = db->dbm_blkno; + return(bitem); + } + + /*really need hash at this point*/ + /*if he gave us a key we have already calculated the hash*/ + /*if not get it*/ + if (inkey.dptr == NULL) hash=dcalchash(key); + hash = dbm_hashinc(db,hash); + + if(hash == 0) + return(item); /*null*/ + /*get first item on next page in hash table order*/ + return(dbm_firsthash(db, hash)); + + +} + +static +dbm_access(db, hash) + register DBM *db; + long hash; +{ + register b, i, n; + register long bn; + register long my_bitno; + register long my_hmask; + register long my_blkno; + + for (my_hmask=0;; my_hmask=(my_hmask<<1)+1) { + my_blkno = hash & my_hmask; + my_bitno = my_blkno + my_hmask; + /*getbit inline*/ + if (my_bitno > db->dbm_maxbno) break; + n = my_bitno % BYTESIZ; + bn = my_bitno / BYTESIZ; + i = bn % DBLKSIZ; + b = bn / DBLKSIZ; + if (b != db->dbm_dirbno) { + if (dbm_dirdirty(db)) dbm_flushdir(db); /*must flush*/ + db->dbm_dirbno = b; + (void) lseek(db->dbm_dirf, (long)(b*DBLKSIZ), L_SET); + if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) + bzero(db->dbm_dirbuf, DBLKSIZ); + } + if ( (db->dbm_dirbuf[i] & (1<<n)) == 0 ) break; + + /* + if (getbit(db) == 0) + break; + */ + } + /*copy*/ + db->dbm_blkno=my_blkno; + db->dbm_bitno=my_bitno; + db->dbm_hmask=my_hmask; + + if (my_blkno != db->dbm_pagbno) { + if (dbm_dirty(db)){ /*must page out the page*/ + (void) lseek(db->dbm_pagf, (long)(db->dbm_pagbno*PBLKSIZ), L_SET); + if (write(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) { + db->dbm_flags |= _DBM_IOERR; + } + dbm_clrdirty(db); + } + + db->dbm_pagbno = my_blkno; + (void) lseek(db->dbm_pagf, (long)(my_blkno*PBLKSIZ), L_SET); + if (read(db->dbm_pagf, db->dbm_pagbuf, PBLKSIZ) != PBLKSIZ) + bzero(db->dbm_pagbuf, PBLKSIZ); +#ifdef DEBUG + else if (chkblk(db->dbm_pagbuf) < 0) + db->dbm_flags |= _DBM_IOERR; +#endif + } +} + +static +getbit(db) + register DBM *db; +{ + long bn; + register b, i, n; + + + if (db->dbm_bitno > db->dbm_maxbno) + return (0); + n = db->dbm_bitno % BYTESIZ; + bn = db->dbm_bitno / BYTESIZ; + i = bn % DBLKSIZ; + b = bn / DBLKSIZ; + if (b != db->dbm_dirbno) { + if (dbm_dirdirty(db)) dbm_flushdir(db); /*must flush*/ + db->dbm_dirbno = b; + (void) lseek(db->dbm_dirf, (long)(b*DBLKSIZ), L_SET); + if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) + bzero(db->dbm_dirbuf, DBLKSIZ); + } + return (db->dbm_dirbuf[i] & (1<<n)); +} + +static +setbit(db) + register DBM *db; +{ + long bn; + register i, n, b; + + if (db->dbm_bitno > db->dbm_maxbno) + db->dbm_maxbno = db->dbm_bitno; + n = db->dbm_bitno % BYTESIZ; + bn = db->dbm_bitno / BYTESIZ; + i = bn % DBLKSIZ; + b = bn / DBLKSIZ; + if (b != db->dbm_dirbno) { + if (dbm_dirdirty(db)) dbm_flushdir(db); + db->dbm_dirbno = b; + (void) lseek(db->dbm_dirf, (long)(b*DBLKSIZ), L_SET); + if (read(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) + bzero(db->dbm_dirbuf, DBLKSIZ); + } + db->dbm_dirbuf[i] |= 1<<n; + db->dbm_dirbno = b; + if (dbm_defwrite(db)) { + dbm_setdirdirty(db); + } else{ + (void) lseek(db->dbm_dirf, (long)(b*DBLKSIZ), L_SET); + if (write(db->dbm_dirf, db->dbm_dirbuf, DBLKSIZ) != DBLKSIZ) { + return (-1); + } + } + return (0); +} + +static datum +makdatum(buf, n) + char buf[PBLKSIZ]; +{ + register short *sp; + register t; + datum item; + + sp = (short *)buf; + if ((unsigned)n >= sp[0]) { + item.dptr = NULL; + item.dsize = 0; + return (item); + } + t = PBLKSIZ; + if (n > 0) + t = sp[n]; + item.dptr = buf+sp[n+1]; + item.dsize = t - sp[n+1]; + return (item); +} + +static cmpdatum(d1, d2) + datum d1, d2; +{ + register n; + register char *p1, *p2; + + n = d1.dsize; + if(n != d2.dsize) + return(n - d2.dsize); + if(n == 0) + return(0); + p1 = d1.dptr; + p2 = d2.dptr; + do + if(*p1++ != *p2++) + return(*--p1 - *--p2); + while(--n); + return(0); +} + +static +finddatum(buf, item) + char buf[PBLKSIZ]; + datum item; +{ + register short *sp; + register int i, n, j; + + sp = (short *)buf; + n = PBLKSIZ; + for (i=0, j=sp[0]; i<j; i+=2, n = sp[i]) { + n -= sp[i+1]; + if (n != item.dsize) + continue; + if (n == 0 || bcmp(&buf[sp[i+1]], item.dptr, n) == 0) + return (i); + } + return (-1); +} + +static int hitab[16] +/* ken's +{ + 055,043,036,054,063,014,004,005, + 010,064,077,000,035,027,025,071, +}; +*/ + = { 61, 57, 53, 49, 45, 41, 37, 33, + 29, 25, 21, 17, 13, 9, 5, 1, +}; +static long hltab[64] + = { + 06100151277L,06106161736L,06452611562L,05001724107L, + 02614772546L,04120731531L,04665262210L,07347467531L, + 06735253126L,06042345173L,03072226605L,01464164730L, + 03247435524L,07652510057L,01546775256L,05714532133L, + 06173260402L,07517101630L,02431460343L,01743245566L, + 00261675137L,02433103631L,03421772437L,04447707466L, + 04435620103L,03757017115L,03641531772L,06767633246L, + 02673230344L,00260612216L,04133454451L,00615531516L, + 06137717526L,02574116560L,02304023373L,07061702261L, + 05153031405L,05322056705L,07401116734L,06552375715L, + 06165233473L,05311063631L,01212221723L,01052267235L, + 06000615237L,01075222665L,06330216006L,04402355630L, + 01451177262L,02000133436L,06025467062L,07121076461L, + 03123433522L,01010635225L,01716177066L,05161746527L, + 01736635071L,06243505026L,03637211610L,01756474365L, + 04723077174L,03642763134L,05750130273L,03655541561L, +}; + +static long +dcalchash(item) + datum item; +{ + register int s, c, j; + register char *cp; + register long hashl; + register int hashi; + + hashl = 0; + hashi = 0; + for (cp = item.dptr, s=item.dsize; --s >= 0; ) { + c = *cp++; + for (j=0; j<BYTESIZ; j+=4) { + hashi += hitab[c&017]; + hashl += hltab[hashi&63]; + c >>= 4; + } + } + return (hashl); +} + +/* + * Delete pairs of items (n & n+1). + */ +static +delitem(buf, n) + char buf[PBLKSIZ]; +{ + register short *sp, *sp1; + register i1, i2; + + sp = (short *)buf; + i2 = sp[0]; + if ((unsigned)n >= i2 || (n & 1)) + return (0); + if (n == i2-2) { + sp[0] -= 2; + return (1); + } + i1 = PBLKSIZ; + if (n > 0) + i1 = sp[n]; + i1 -= sp[n+2]; + if (i1 > 0) { + i2 = sp[i2]; + bcopy(&buf[i2], &buf[i2 + i1], sp[n+2] - i2); + } + sp[0] -= 2; + for (sp1 = sp + sp[0], sp += n+1; sp <= sp1; sp++) + sp[0] = sp[2] + i1; + return (1); +} + +/* + * Add pairs of items (item & item1). + */ +static +additem(buf, item, item1) + char buf[PBLKSIZ]; + datum item, item1; +{ + register short *sp; + register i1, i2; + + sp = (short *)buf; + i1 = PBLKSIZ; + i2 = sp[0]; + if (i2 > 0) + i1 = sp[i2]; + i1 -= item.dsize + item1.dsize; + if (i1 <= (i2+3) * sizeof(short)) + return (0); + sp[0] += 2; + sp[++i2] = i1 + item1.dsize; + bcopy(item.dptr, &buf[i1 + item1.dsize], item.dsize); + sp[++i2] = i1; + bcopy(item1.dptr, &buf[i1], item1.dsize); + return (1); +} + +#ifdef DEBUG +static +chkblk(buf) + char buf[PBLKSIZ]; +{ + register short *sp; + register t, i; + + sp = (short *)buf; + t = PBLKSIZ; + for (i=0; i<sp[0]; i++) { + if (sp[i+1] > t) + return (-1); + t = sp[i+1]; + } + if (t < (sp[0]+1)*sizeof(short)) + return (-1); + return (0); +} +#endif diff --git a/usr/src/lib/libbc/libc/gen/common/nl_cxtime.c b/usr/src/lib/libbc/libc/gen/common/nl_cxtime.c new file mode 100644 index 0000000000..53c73ee0d9 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/nl_cxtime.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <stdio.h> +#include <time.h> + +#define TBUFSIZE 128 +char _tbuf[TBUFSIZE]; + +char * +nl_cxtime(clk, fmt) + struct tm *clk; + char *fmt; +{ + char *nl_ascxtime(); + return (nl_ascxtime(localtime(clk), fmt)); +} + +char * +nl_ascxtime(tmptr, fmt) + struct tm *tmptr; + char *fmt; +{ + return (strftime (_tbuf, TBUFSIZE, fmt ? fmt : "%H:%M:%S", tmptr) ? + _tbuf : asctime(tmptr)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/nl_strncmp.c b/usr/src/lib/libbc/libc/gen/common/nl_strncmp.c new file mode 100644 index 0000000000..cbf844c983 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/nl_strncmp.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> + +#define MAXSTR 256 /* use same value as used in strcoll */ + +int +nl_strncmp(s1, s2, n) + char *s1; + char *s2; + int n; +{ + char ns1[MAXSTR+1]; + char ns2[MAXSTR+1]; + register int i; + register char *p1, *p2; + + p1 = ns1; + p2 = ns2; + + for (i = 0; i < n && i < MAXSTR; i++) { + *p1++ = *s1++; + *p2++ = *s2++; + } + *p1 = *p2 = '\0'; + + return (strcoll(ns1, ns2)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/on_exit.c b/usr/src/lib/libbc/libc/gen/common/on_exit.c new file mode 100644 index 0000000000..354c9a6409 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/on_exit.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +char *malloc(); + +struct handlers { + void (*handler)(); + caddr_t arg; + struct handlers *next; +}; + +extern struct handlers *_exit_handlers; + +int +on_exit(handler, arg) + void (*handler)(); + caddr_t arg; +{ + register struct handlers *h = + (struct handlers *)malloc(sizeof (*h)); + + if (h == 0) + return (-1); + h->handler = handler; + h->arg = arg; + h->next = _exit_handlers; + _exit_handlers = h; + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/opendir.c b/usr/src/lib/libbc/libc/gen/common/opendir.c new file mode 100644 index 0000000000..cf41897df2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/opendir.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/param.h> +#include <sys/stat.h> +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> + +/* + * open a directory. + */ +DIR * +opendir(name) + char *name; +{ + register DIR *dirp; + register int fd; + struct stat sb; + extern int errno; + extern char *malloc(); + extern int open(), close(), fstat(); + + if ((fd = open(name, O_RDONLY | O_NDELAY)) == -1) + return (NULL); + if (fstat(fd, &sb) == -1) { + (void) close(fd); + return (NULL); + } + if ((sb.st_mode & S_IFMT) != S_IFDIR) { + errno = ENOTDIR; + (void) close(fd); + return (NULL); + } + if (((dirp = (DIR *)malloc(sizeof(DIR))) == NULL) || + ((dirp->dd_buf = malloc(sb.st_blksize)) == NULL)) { + if (dirp) + free(dirp); + (void) close(fd); + return (NULL); + } + dirp->dd_fd = fd; + dirp->dd_loc = 0; + dirp->dd_size = 0; + dirp->dd_bsize = sb.st_blksize; + dirp->dd_off = 0; + (void) fcntl(fd, F_SETFD, FD_CLOEXEC); + return (dirp); +} diff --git a/usr/src/lib/libbc/libc/gen/common/optind.c b/usr/src/lib/libbc/libc/gen/common/optind.c new file mode 100644 index 0000000000..5bfeb416cb --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/optind.c @@ -0,0 +1,31 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 Sun Microsystems, Inc. + */ + +/*LINTLIBRARY*/ +int optind = 1; +int opterr = 1; +char *optarg; diff --git a/usr/src/lib/libbc/libc/gen/common/pack_float.c b/usr/src/lib/libbc/libc/gen/common/pack_float.c new file mode 100644 index 0000000000..4a75254292 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/pack_float.c @@ -0,0 +1,455 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "base_conversion.h" + +void +_fp_rightshift(pu, n) + unpacked *pu; + int n; + +/* Right shift significand sticky by n bits. */ + +{ + int i; + + if (n >= (32 * UNPACKED_SIZE)) { /* drastic */ + for (i = 0; (pu->significand[i] == 0) && (i < UNPACKED_SIZE); i++); + if (i >= UNPACKED_SIZE) { + pu->fpclass = fp_zero; + return; + } else { + for (i = 0; i < (UNPACKED_SIZE - 1); i++) + pu->significand[i] = 0; + pu->significand[UNPACKED_SIZE - 1] = 1; + return; + } + } + while (n >= 32) { /* big shift */ + if (pu->significand[UNPACKED_SIZE - 1] != 0) + pu->significand[UNPACKED_SIZE - 2] |= 1; + for (i = UNPACKED_SIZE - 2; i >= 0; i--) + pu->significand[i + 1] = pu->significand[i]; + pu->significand[0] = 0; + n -= 32; + } + if (n >= 1) { /* small shift */ + unsigned long high, low, shiftout = 0; + for (i = 0; i < UNPACKED_SIZE; i++) { + high = pu->significand[i] >> n; + low = pu->significand[i] << (32 - n); + pu->significand[i] = shiftout | high; + shiftout = low; + } + if (shiftout != 0) + pu->significand[UNPACKED_SIZE - 1] |= 1; + } +} + +PRIVATE int +overflow_to_infinity(sign) + int sign; + +/* Returns 1 if overflow should go to infinity, 0 if to max finite. */ + +{ + int inf; + + switch (_fp_current_direction) { + case fp_nearest: + inf = 1; + break; + case fp_tozero: + inf = 0; + break; + case fp_positive: + inf = !sign; + break; + case fp_negative: + inf = sign; + break; + } + return (inf); +} + +PRIVATE void +round(pu, roundword) + unpacked *pu; + +/* + * Round according to current rounding mode. pu must be shifted to so that + * the roundbit is pu->significand[roundword] & 0x80000000 + */ + +{ + int increment; /* boolean to indicate round up */ + int is; + unsigned msw; /* msw before increment */ + + for (is = (roundword + 1); is < UNPACKED_SIZE; is++) + if (pu->significand[is] != 0) { /* Condense extra bits into + * sticky bottom of + * roundword. */ + pu->significand[roundword] |= 1; + break; + } + if (pu->significand[roundword] == 0) + return; + _fp_set_exception(fp_inexact); + switch (_fp_current_direction) { + case fp_nearest: + increment = pu->significand[roundword] >= 0x80000000; + break; + case fp_tozero: + increment = 0; + break; + case fp_positive: + increment = (pu->sign == 0) & (pu->significand[roundword] != 0); + break; + case fp_negative: + increment = (pu->sign != 0) & (pu->significand[roundword] != 0); + break; + } + if (increment) { + msw=pu->significand[0]; /* save msw before round */ + is = roundword; + do { + is--; + pu->significand[is]++; + } + while ((pu->significand[is] == 0) && (is > 0)); + if (pu->significand[0] < msw) { /* rounding carried out */ + pu->exponent++; + pu->significand[0] = 0x80000000; + } + } + if ((_fp_current_direction == fp_nearest) && (pu->significand[roundword] == 0x80000000)) { /* ambiguous case */ + pu->significand[roundword - 1] &= ~1; /* force round to even */ + } +} + +void +_pack_single(pu, px) + unpacked *pu; /* unpacked result */ + single *px; /* packed single */ +{ + single_equivalence kluge; + + kluge.f.msw.sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + break; + case fp_infinity: +infinity: + kluge.f.msw.exponent = 0xff; + kluge.f.msw.significand = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0xff; + kluge.f.msw.significand = 0x400000 | (0x3fffff & (pu->significand[0] >> 8)); + break; + case fp_normal: + _fp_rightshift(pu, 8); + pu->exponent += SINGLE_BIAS; + if (pu->exponent <= 0) { + kluge.f.msw.exponent = 0; + _fp_rightshift(pu, 1 - pu->exponent); + round(pu, 1); + if (pu->significand[0] == 0x800000) { /* rounded back up to + * normal */ + kluge.f.msw.exponent = 1; + kluge.f.msw.significand = 0; + _fp_set_exception(fp_underflow); + goto ret; + } + if (_fp_current_exceptions & (1 << fp_inexact)) + _fp_set_exception(fp_underflow); + kluge.f.msw.significand = 0x7fffff & pu->significand[0]; + goto ret; + } + round(pu, 1); + if (pu->significand[0] == 0x1000000) { /* rounding overflow */ + pu->significand[0] = 0x800000; + pu->exponent += 1; + } + if (pu->exponent >= 0xff) { + _fp_set_exception(fp_overflow); + _fp_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + kluge.f.msw.exponent = 0xfe; + kluge.f.msw.significand = 0x7fffff; + goto ret; + } + kluge.f.msw.exponent = pu->exponent; + kluge.f.msw.significand = 0x7fffff & pu->significand[0]; + } +ret: + *px = kluge.x; +} + +void +_pack_double(pu, px) + unpacked *pu; /* unpacked result */ + double *px; /* packed double */ +{ + double_equivalence kluge; + + kluge.f.msw.sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_infinity: +infinity: + kluge.f.msw.exponent = 0x7ff; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7ff; + _fp_rightshift(pu, 11); + kluge.f.msw.significand = 0x80000 | (0x7ffff & pu->significand[0]); + kluge.f.significand2 = pu->significand[1]; + break; + case fp_normal: + _fp_rightshift(pu, 11); + pu->exponent += DOUBLE_BIAS; + if (pu->exponent <= 0) { /* underflow */ + kluge.f.msw.exponent = 0; + _fp_rightshift(pu, 1 - pu->exponent); + round(pu, 2); + if (pu->significand[0] == 0x100000) { /* rounded back up to + * normal */ + kluge.f.msw.exponent = 1; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + _fp_set_exception(fp_underflow); + goto ret; + } + if (_fp_current_exceptions & (1 << fp_inexact)) + _fp_set_exception(fp_underflow); + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0xfffff & pu->significand[0]; + kluge.f.significand2 = pu->significand[1]; + goto ret; + } + round(pu, 2); + if (pu->significand[0] == 0x200000) { /* rounding overflow */ + pu->significand[0] = 0x100000; + pu->exponent += 1; + } + if (pu->exponent >= 0x7ff) { /* overflow */ + _fp_set_exception(fp_overflow); + _fp_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + kluge.f.msw.exponent = 0x7fe; + kluge.f.msw.significand = 0xfffff; + kluge.f.significand2 = 0xffffffff; + goto ret; + } + kluge.f.msw.exponent = pu->exponent; + kluge.f.msw.significand = 0xfffff & pu->significand[0]; + kluge.f.significand2 = pu->significand[1]; + break; + } +ret: + *px = kluge.x; +} + +void +_pack_extended(pu, px) + unpacked *pu; /* unpacked result */ + extended *px; /* packed extended */ +{ + extended_equivalence kluge; + + kluge.f.msw.sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_infinity: +infinity: + kluge.f.msw.exponent = 0x7fff; + kluge.f.significand = 0; + kluge.f.significand2 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7fff; + kluge.f.significand = 0x40000000 | (0x7fffffff & pu->significand[0]); + kluge.f.significand2 = pu->significand[1]; + break; + case fp_normal: + switch (_fp_current_precision) { + case fp_single: + { + single s; + _pack_single(pu, &s); + _unpack_single(pu, &s); + break; + } + case fp_double: + { + double s; + _pack_double(pu, &s); + _unpack_double(pu, &s); + break; + } + } + pu->exponent += EXTENDED_BIAS; + if (pu->exponent <= 0) { /* underflow */ + kluge.f.msw.exponent = 0; + _fp_rightshift(pu, -pu->exponent); + round(pu, 2); + if (_fp_current_exceptions & (1 << fp_inexact)) + _fp_set_exception(fp_underflow); + kluge.f.msw.exponent = 0; + kluge.f.significand = pu->significand[0]; + kluge.f.significand2 = pu->significand[1]; + goto ret; + } + round(pu, 2); + if (pu->exponent >= 0x7fff) { /* overflow */ + _fp_set_exception(fp_overflow); + _fp_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + kluge.f.msw.exponent = 0x7ffe; + kluge.f.significand = 0xffffffff; + kluge.f.significand2 = 0xffffffff; + goto ret; + } + kluge.f.msw.exponent = pu->exponent; + kluge.f.significand = pu->significand[0]; + kluge.f.significand2 = pu->significand[1]; + break; + } +ret: + (*px)[0] = kluge.x[0]; + (*px)[1] = kluge.x[1]; + (*px)[2] = kluge.x[2]; +} + +void +_pack_quadruple(pu, px) + unpacked *pu; /* unpacked result */ + quadruple *px; /* packed quadruple */ +{ + quadruple_equivalence kluge; + int i; + + kluge.f.msw.sign = pu->sign; + switch (pu->fpclass) { + case fp_zero: + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + kluge.f.significand3 = 0; + kluge.f.significand4 = 0; + break; + case fp_infinity: +infinity: + kluge.f.msw.exponent = 0x7fff; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + kluge.f.significand3 = 0; + kluge.f.significand4 = 0; + break; + case fp_quiet: + kluge.f.msw.exponent = 0x7fff; + _fp_rightshift(pu, 15); + kluge.f.msw.significand = 0x8000 | (0xffff & pu->significand[0]); + kluge.f.significand2 = pu->significand[1]; + kluge.f.significand3 = pu->significand[2]; + kluge.f.significand4 = pu->significand[3]; + break; + case fp_normal: + _fp_rightshift(pu, 15); + pu->exponent += QUAD_BIAS; + if (pu->exponent <= 0) { /* underflow */ + kluge.f.msw.exponent = 0; + _fp_rightshift(pu, 1 - pu->exponent); + round(pu, 4); + if (pu->significand[0] == 0x10000) { /* rounded back up to + * normal */ + kluge.f.msw.exponent = 1; + kluge.f.msw.significand = 0; + kluge.f.significand2 = 0; + kluge.f.significand3 = 0; + kluge.f.significand4 = 0; + _fp_set_exception(fp_underflow); + goto ret; + } + if (_fp_current_exceptions & (1 << fp_inexact)) + _fp_set_exception(fp_underflow); + kluge.f.msw.exponent = 0; + kluge.f.msw.significand = 0xffff & pu->significand[0]; + kluge.f.significand2 = pu->significand[1]; + kluge.f.significand3 = pu->significand[2]; + kluge.f.significand4 = pu->significand[3]; + goto ret; + } + round(pu, 4); + if (pu->significand[0] == 0x20000) { /* rounding overflow */ + pu->significand[0] = 0x10000; + pu->exponent += 1; + } + if (pu->exponent >= 0x7fff) { /* overflow */ + _fp_set_exception(fp_overflow); + _fp_set_exception(fp_inexact); + if (overflow_to_infinity(pu->sign)) + goto infinity; + kluge.f.msw.exponent = 0x7ffe; + kluge.f.msw.significand = 0xffff; + kluge.f.significand2 = 0xffffffff; + kluge.f.significand3 = 0xffffffff; + kluge.f.significand4 = 0xffffffff; + goto ret; + } + kluge.f.msw.exponent = pu->exponent; + kluge.f.msw.significand = pu->significand[0] & 0xffff; + kluge.f.significand2 = pu->significand[1]; + kluge.f.significand3 = pu->significand[2]; + kluge.f.significand4 = pu->significand[3]; + break; + } +ret: +#ifdef __STDC__ + *px = kluge.x; +#else + for (i = 0; i < 4; i++) + px->u[i] = kluge.x.u[i]; +#endif +} diff --git a/usr/src/lib/libbc/libc/gen/common/perror.c b/usr/src/lib/libbc/libc/gen/common/perror.c new file mode 100644 index 0000000000..484af3f4cf --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/perror.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1983 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Print the error indicated + * in the cerror cell. + */ +#include <stdio.h> + +extern int fflush(); +extern void _perror(); + +void +perror(s) + char *s; +{ + + (void)fflush(stderr); + _perror(s); +} diff --git a/usr/src/lib/libbc/libc/gen/common/plock.c b/usr/src/lib/libbc/libc/gen/common/plock.c new file mode 100644 index 0000000000..f818e5ebee --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/plock.c @@ -0,0 +1,314 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* @(#)plock.c 1.3 90/03/30 */ + +/* + * Copyright (c) 1989 by Sun Microsystems, Inc. + */ + +/* + * plock - lock "segments" in physical memory. + * + * Supports SVID-compatible plock, taking into account dynamically linked + * objects (such as shared libraries). + */ + +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/lock.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <machine/param.h> +#include <machine/vmparam.h> +#include <a.out.h> +#include <link.h> +#include <errno.h> + +/* + * Globals we reference. + */ +extern struct link_dynamic _DYNAMIC; +extern int mlock(); +extern int munlock(); + +/* + * Module-scope variables. + */ +static int page_size = 0; /* cached result of getpagesize() */ +static int lock_state = 0; /* lock state */ +static int state_pid = -1; /* pid to which state belongs */ + +/* + * Local worker routine to lock text and data segments. Handles + * dynamically loaded objects. This routine is highly dependent + * on executable format and layout. + */ +static int +apply_lock(op, f) + int op; /* desired operation */ + int (*f)(); /* function to perform */ +{ + int e = 0; /* return value */ + caddr_t a; /* address of operation */ + u_int l; /* length of operation */ + struct link_map *lmp; /* link map walker */ + struct exec *eh; /* exec header */ + extern caddr_t sbrk(); /* find end of data segment */ + extern caddr_t etext; /* end of text segment */ + + /* + * Operate on application segment first. + */ + switch (op) { + case TXTLOCK: + a = (caddr_t)USRTEXT; /* note: old Sun-2 not handled */ + l = (u_int)&etext - USRTEXT; + break; + case DATLOCK: + a = (caddr_t)(((int)&etext + (SEGSIZ - 1)) & ~(SEGSIZ - 1)); + l = (u_int)(sbrk(0) - a); + break; + } + l = (l + (page_size - 1)) & (u_int)~(page_size - 1); + + /* + * Perform the operation -- if failure, return immediately. + */ + if (e = (*f)(a, l)) + return (e); + + /* + * If we're not a dynamically linked program, we are finished. + */ + if (&_DYNAMIC == 0) + return (0); + + /* + * Find the list of dynamically linked objects. If we get + * dynamic linking formats we don't recognize, then punt. + */ + switch (_DYNAMIC.ld_version) { + case 2: +#ifdef sparc + case 3: +#endif sparc + lmp = _DYNAMIC.ld_un.ld_2->ld_loaded; + break; + default: + return (0); + } + + /* + * Loop over all objects. Extract the addresses and lengths as + * required, and perform the appropriate operation. + */ + + while (lmp) { + eh = (struct exec *)lmp->lm_addr; + switch (op) { + case TXTLOCK: + a = (caddr_t)eh; + l = (u_int)eh->a_text; + break; + case DATLOCK: + a = (caddr_t)((u_int)eh + N_DATADDR(*eh) - + N_TXTADDR(*eh)); + l = (u_int)eh->a_data + (u_int)eh->a_bss; + break; + } + l = (l + (page_size - 1)) & ~(page_size - 1); + if (e = (*f)(a, l)) + return (e); + lmp = lmp->lm_next; + } + return (0); +} + +/* + * plock + */ +int +plock(op) + int op; /* desired operation */ +{ + int e = 0; /* return value */ + int pid; /* current pid */ + caddr_t a1, a2; /* loop variables */ + struct rlimit rl; /* resource limit */ + + /* + * Initialize static caches. + */ + if (page_size == 0) + page_size = getpagesize(); + + /* + * Validate state of lock's. If parent has forked, then + * the lock state needs to be reset (children do not inherit + * memory locks, and thus do not inherit their state). + */ + if ((pid = getpid()) != state_pid) { + lock_state = 0; + state_pid = pid; + } + + /* + * Dispatch on operation. Note: plock and its relatives depend + * upon "op" being bit encoded. + */ + switch (op) { + + /* + * UNLOCK: remove all memory locks. Requires that some be set! + */ + case UNLOCK: + if (lock_state == 0) { + errno = EINVAL; + return (-1); + } + if (e = munlockall()) + return (-1); + else { + lock_state = 0; + return (0); + } + /*NOTREACHED*/ + + /* + * TXTLOCK: locks text segments. + */ + case TXTLOCK: + + /* + * If a text or process lock is already set, then fail. + */ + if ((lock_state & TXTLOCK) || (lock_state & PROCLOCK)) { + errno = EINVAL; + return (-1); + } + + /* + * Try to apply the lock(s). If a failure occurs, + * back them out. On success, remember that a text + * lock was set. + */ + if (e = apply_lock(op, mlock)) + (void) apply_lock(op, munlock); + else + lock_state |= TXTLOCK; + return (e); + /*NOTREACHED*/ + + /* + * DATLOCK: locks data segment(s), including the stack and all + * future growth in the address space. + */ + case DATLOCK: + + /* + * If a data or process lock is already set, then fail. + */ + if ((lock_state & DATLOCK) || (lock_state & PROCLOCK)) { + errno = EINVAL; + return (-1); + } + + /* + * Try to lock the data segments. On failure, back out + * the locks and return. + */ + if (e = apply_lock(op, mlock)) { + (void) apply_lock(op, munlock); + return (-1); + } + + /* + * Try to lock the stack segment. Find out the extent + * and start of the stack (there should be a function for + * this!) and then iterate over the pages of the stack + * locking them. The stack *could* be sparely populated. + * Ignore lock failures resulting from the absence of a + * mapping. + */ + (void) getrlimit(RLIMIT_STACK, &rl); + for (a1 = (caddr_t)USRSTACK - page_size; + a1 != (caddr_t)USRSTACK - rl.rlim_cur; a1 -= page_size) + if (e = mlock(a1, page_size)) { + if (errno == ENOMEM) + e = 0; + break; + } + + /* + * If we were successful in locking the stack, then + * try to set a lock for all future mappings. + */ + if (!e) + e = mlockall(MCL_FUTURE); + + /* + * If failures have occurred, back out the locks + * and return failure. + */ + if (e) { + e = errno; + (void) apply_lock(op, munlock); + for (a2 = (caddr_t)USRSTACK - page_size; a2 != a1; + a2 -= page_size) + (void) munlock(a2, page_size); + errno = e; + return (-1); + } + + /* + * Data, stack, and growth have been locked. Set state + * and return success. + */ + lock_state |= DATLOCK; + return (0); + /*NOTREACHED*/ + + /* + * PROCLOCK: lock everything, and all future things as well. + * There should be nothing locked when this is called. + */ + case PROCLOCK: + if (lock_state) { + errno = EINVAL; + return (-1); + } + if (mlockall(MCL_CURRENT | MCL_FUTURE) == 0) { + lock_state |= PROCLOCK; + return (0); + } else + return (-1); + /*NOTREACHED*/ + + /* + * Invalid operation. + */ + default: + errno = EINVAL; + return (-1); + /*NOTREACHED*/ + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/popen.c b/usr/src/lib/libbc/libc/gen/common/popen.c new file mode 100644 index 0000000000..bb295e717a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/popen.c @@ -0,0 +1,98 @@ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.2 85/06/05 */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <stdio.h> +#include <signal.h> +#include <vfork.h> + +#define tst(a,b) (*mode == 'r'? (b) : (a)) +#define RDR 0 +#define WTR 1 + +extern char *malloc(); +extern int execl(), vfork(), pipe(), close(), fcntl(); + +static int *popen_pid; +static int nfiles; + +FILE * +popen(cmd,mode) + char *cmd; + char *mode; +{ + int p[2]; + register int *poptr; + register int myside, hisside, pid; + + if (nfiles <= 0) + nfiles = getdtablesize(); + if (popen_pid == NULL) { + popen_pid = (int *)malloc(nfiles * sizeof *popen_pid); + if (popen_pid == NULL) + return (NULL); + for (pid = 0; pid < nfiles; pid++) + popen_pid[pid] = -1; + } + if (pipe(p) < 0) + return (NULL); + myside = tst(p[WTR], p[RDR]); + hisside = tst(p[RDR], p[WTR]); + if ((pid = vfork()) == 0) { + /* myside and hisside reverse roles in child */ + int stdio; + + /* close all pipes from other popen's */ + for (poptr = popen_pid; poptr < popen_pid+nfiles; poptr++) { + if(*poptr >= 0) + close(poptr - popen_pid); + } + stdio = tst(0, 1); + (void) close(myside); + if (hisside != stdio) { + (void) dup2(hisside, stdio); + (void) close(hisside); + } + (void) execl("/bin/sh", "sh", "-c", cmd, (char *)NULL); + _exit(127); + } + if (pid == -1) { + close(myside); + close(hisside); + return (NULL); + } + popen_pid[myside] = pid; + close(hisside); + return (fdopen(myside, mode)); +} + +int +pclose(ptr) + FILE *ptr; +{ + int child = -1; + int pid, status, omask; + + if (popen_pid != NULL) { + child = popen_pid[fileno(ptr)]; + popen_pid[fileno(ptr)] = -1; + } + fclose(ptr); + if (child == -1) + return (-1); + omask = sigblock(sigmask(SIGINT)|sigmask(SIGQUIT)|sigmask(SIGHUP)); + while ((pid = waitpid(child, &status, 0)) != child && pid != -1) + ; + (void) sigsetmask(omask); + return (pid == -1 ? -1 : status); +} diff --git a/usr/src/lib/libbc/libc/gen/common/posix_sig.c b/usr/src/lib/libbc/libc/gen/common/posix_sig.c new file mode 100644 index 0000000000..b0d5975966 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/posix_sig.c @@ -0,0 +1,95 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1994 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * posix signal package + */ +#include <stdio.h> +#include <signal.h> +#include <errno.h> +#define cantmask (sigmask(SIGKILL)|sigmask(SIGSTOP)) + +extern errno; + +/* + * sigemptyset - all known signals + */ +sigemptyset(sigp) + sigset_t *sigp; +{ + if (!sigp) + return errno = EINVAL, -1; + *sigp = 0; + return 0; +} + +/* + * sigfillset - all known signals + */ +sigfillset(sigp) + sigset_t *sigp; +{ + if (!sigp) + return errno = EINVAL, -1; + *sigp = sigmask(NSIG - 1) | (sigmask(NSIG - 1) - 1); + return 0; +} + +/* + * add the signal to the set + */ +sigaddset(sigp,signo) + sigset_t* sigp; +{ + if (!sigp || signo <= 0 || signo >= NSIG) + return errno = EINVAL, -1; + *sigp |= sigmask(signo); + return 0; +} + +/* + * remove the signal from the set + */ +sigdelset(sigp,signo) + sigset_t* sigp; +{ + if (!sigp || signo <= 0 || signo >= NSIG) + return errno = EINVAL, -1; + *sigp &= ~sigmask(signo); + return 0; +} + +/* + * return true if the signal is in the set (return is 0 or 1) + */ +sigismember(sigp,signo) + sigset_t* sigp; +{ + if (!sigp || signo <= 0 || signo >= NSIG) + return errno = EINVAL, -1; + return (*sigp & sigmask(signo)) != 0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/posix_tty.c b/usr/src/lib/libbc/libc/gen/common/posix_tty.c new file mode 100644 index 0000000000..4e95ace01f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/posix_tty.c @@ -0,0 +1,240 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * wrappers for posix tty manipulation functions + */ + +#include <errno.h> +#include <termios.h> +#include <termio.h> +#include <sys/types.h> + +extern errno; + +speed_t cfgetospeed(/*struct termios* p*/); +int cfsetospeed(/*struct termios* p, speed_t speed*/); +speed_t cfgetispeed(/*struct termios* p*/); +int cfsetispeed(/*struct termios* p, speed_t speed*/); +int tcgetattr(/*int fd, struct termios* p*/); +int tcsetattr(/*int fd, opts, struct termios* p*/); +int tcsendbreak(/*int fd, howlong*/); +int tcdrain(/*int fd*/); +int tcflush(/*int fd, which*/); +int tcflow(/*int fd, what*/); +pid_t tcgetpgrp(/*int fd*/); +int tcsetpgrp(/*int fd, pid_t pgrp*/); + +/* + * return the output speed from the struct + */ +speed_t +cfgetospeed(termios_p) + struct termios *termios_p; +{ + return (termios_p->c_cflag & CBAUDEXT ? + (termios_p->c_cflag & CBAUD) + CBAUD + 1 : + termios_p->c_cflag & CBAUD); +} + +/* + * set the speed in the struct + */ +cfsetospeed(termios_p, speed) + struct termios *termios_p; + speed_t speed; +{ + if (speed > (2*CBAUD + 1)) { + errno = EINVAL; + return (-1); + } + if (speed > CBAUD) { + termios_p->c_cflag |= CBAUDEXT; + speed -= (CBAUD + 1); + } else + termios_p->c_cflag &= ~CBAUDEXT; + + termios_p->c_cflag = + (termios_p->c_cflag & ~CBAUD) | (speed & CBAUD); + return (0); +} + +/* + * return the input speed from the struct + */ +speed_t +cfgetispeed(termios_p) + struct termios *termios_p; +{ + return (termios_p->c_cflag & CIBAUDEXT ? + ((termios_p->c_cflag & CIBAUD) >> IBSHIFT) + + (CIBAUD >> IBSHIFT) + 1 : + (termios_p->c_cflag & CIBAUD) >> IBSHIFT); +} + +/* + * set the input speed in the struct + */ +cfsetispeed(termios_p, speed) + struct termios *termios_p; + speed_t speed; +{ + if (speed > (2*CBAUD + 1)) { + errno = EINVAL; + return (-1); + } + if ((speed << IBSHIFT) > CIBAUD) { + termios_p->c_cflag |= CIBAUDEXT; + speed -= ((CIBAUD >> IBSHIFT) + 1); + } else + termios_p->c_cflag &= ~CIBAUDEXT; + termios_p->c_cflag = + (termios_p->c_cflag & ~CIBAUD) | ((speed << IBSHIFT) & CIBAUD); + return (0); +} + +/* + * grab the modes + */ +tcgetattr(fd, termios_p) + struct termios *termios_p; +{ + return (ioctl(fd, TCGETS, termios_p)); +} + +/* + * set the modes + */ +tcsetattr(fd, option, termios_p) + struct termios *termios_p; +{ + struct termios work_area; + + /* If input speed is zero, set it to the output speed. */ + if ((((termios_p->c_cflag >> IBSHIFT) & CIBAUD) == 0) && + ((termios_p->c_cflag & CIBAUDEXT) == 0)) { + work_area = *termios_p; + work_area.c_cflag |= (work_area.c_cflag & CBAUD) << IBSHIFT; + if (termios_p->c_cflag & CBAUDEXT) + work_area.c_cflag |= CIBAUDEXT; + termios_p = &work_area; + } + switch (option) { + case TCSADRAIN: + return (ioctl(fd, TCSETSW, termios_p)); + case TCSAFLUSH: + return (ioctl(fd, TCSETSF, termios_p)); + case TCSANOW: + return (ioctl(fd, TCSETS, termios_p)); + default: + errno = EINVAL; + return (-1); + } + /*NOTREACHED*/ +} + +/* + * send a break + * This is kludged for duration != 0; it should do something like crank the + * baud rate down and then send the break if the duration != 0. + */ +tcsendbreak(fd, duration) +{ + register unsigned d = (unsigned)duration; + + do + if (ioctl(fd, TCSBRK, 0) == -1) + return (-1); + while (d--); + return (0); +} + +/* + * wait for all output to drain from fd + */ +tcdrain(fd) +{ + return (ioctl(fd, TCSBRK, !0)); +} + +/* + * flow control + */ +tcflow(fd, action) +{ + switch (action) { + default: + errno = EINVAL; + return (-1); + case TCOOFF: + case TCOON: + case TCIOFF: + case TCION: + return (ioctl(fd, TCXONC, action)); + } + /*NOTREACHED*/ +} + +/* + * flush read/write/both + */ +tcflush(fd, queue) +{ + switch (queue) { + default: + errno = EINVAL; + return (-1); + case TCIFLUSH: + case TCOFLUSH: + case TCIOFLUSH: + return (ioctl(fd, TCFLSH, queue)); + } + /*NOTREACHED*/ +} + +/* + * get the foreground process group id + */ +pid_t +tcgetpgrp(fd) +{ + int grp_id; + + if (ioctl(fd, TIOCGETPGRP, &grp_id) == -1) + return ((pid_t)-1); + else + return ((pid_t)grp_id); +} + +/* + * set the foreground process group id + */ +tcsetpgrp(fd, grp_id) +{ + return (ioctl(fd, TIOCSETPGRP, &grp_id)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/psignal.c b/usr/src/lib/libbc/libc/gen/common/psignal.c new file mode 100644 index 0000000000..1be7704b44 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/psignal.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1983 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Print the name of the signal indicated + * along with the supplied message. + */ +#include <stdio.h> + +extern int fflush(); +extern void _psignal(); + +void +psignal(sig, s) + unsigned sig; + char *s; +{ + + (void)fflush(stderr); + _psignal(sig, s); +} diff --git a/usr/src/lib/libbc/libc/gen/common/putenv.c b/usr/src/lib/libbc/libc/gen/common/putenv.c new file mode 100644 index 0000000000..41e2a49b7c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/putenv.c @@ -0,0 +1,121 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/* LINTLIBRARY */ +/* putenv - change environment variables + + input - char *change = a pointer to a string of the form + "name=value" + + output - 0, if successful + 1, otherwise +*/ +#define NULL 0 +extern char **environ; /* pointer to enviroment */ +static reall; /* flag to reallocate space, if putenv is called + more than once */ + +int +putenv(change) +char *change; +{ + char **newenv; /* points to new environment */ + register int which; /* index of variable to replace */ + char *realloc(), *malloc(); /* memory alloc routines */ + + if ((which = find(change)) < 0) { + /* if a new variable */ + /* which is negative of table size, so invert and + count new element */ + which = (-which) + 1; + if (reall) { + /* we have expanded environ before */ + newenv = (char **)realloc(environ, + which*sizeof(char *)); + if (newenv == NULL) return -1; + /* now that we have space, change environ */ + environ = newenv; + } else { + /* environ points to the original space */ + reall++; + newenv = (char **)malloc(which*sizeof(char *)); + if (newenv == NULL) return -1; + (void)memcpy((char *)newenv, (char *)environ, + (int)(which*sizeof(char *))); + environ = newenv; + } + environ[which-2] = change; + environ[which-1] = NULL; + } else { + /* we are replacing an old variable */ + environ[which] = change; + } + return 0; +} + +/* find - find where s2 is in environ + * + * input - str = string of form name=value + * + * output - index of name in environ that matches "name" + * -size of table, if none exists +*/ +static +find(str) +register char *str; +{ + register int ct = 0; /* index into environ */ + + while(environ[ct] != NULL) { + if (match(environ[ct], str) != 0) + return ct; + ct++; + } + return -(++ct); +} +/* + * s1 is either name, or name=value + * s2 is name=value + * if names match, return value of 1, + * else return 0 + */ + +static +match(s1, s2) +register char *s1, *s2; +{ + while(*s1 == *s2++) { + if (*s1 == '=') + return 1; + s1++; + } + return 0; +} diff --git a/usr/src/lib/libbc/libc/gen/common/pwdauth.c b/usr/src/lib/libbc/libc/gen/common/pwdauth.c new file mode 100644 index 0000000000..b001267e69 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/pwdauth.c @@ -0,0 +1,75 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <stdio.h> +#include <pwd.h> +#include <shadow.h> +#include <errno.h> + +/* + * Version to go in the BCP compatibility library in SVr4 version of + * SunOS. This does not bother talking to rpc.pwdauthd or looking for the + * password.adjunct file on the system since they do not exist anymore. + * They have been effectively replaced by a more robust aging security provided + * by the combination of /etc/shadow file, shadow support in the NIS+ + * passwd table and the use of secure RPC in NIS+. + */ + +pwdauth(name, password) + char *name; + char *password; +{ + /* + * this routine authenticates a password for the named user. + * Assumes the adjunct file does not exist. + * and therefore checks the passwd "source" using the standard + * getpwnam(3C) routine that uses /etc/nsswitch.conf(4). + */ + + struct passwd *pwp = NULL; + struct spwd *spwp = NULL; + char *enpwp; + + if (spwp = getspnam(name)) + enpwp = spwp->sp_pwdp; + else if (pwp = getpwnam(name)) + enpwp = pwp->pw_passwd; + else + /* user is not in main password system */ + return (-1); + if (enpwp[0] == '#' && enpwp[1] == '#') { + /* this means that /etc/passwd has problems */ + fprintf(stderr, "pwdauth: bad passwd entry for %s\n", + name); + return (-1); + } + if (strcmp(crypt(password, enpwp), enpwp) == 0) + return (0); + else + return (-1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/pwdnm.c b/usr/src/lib/libbc/libc/gen/common/pwdnm.c new file mode 100644 index 0000000000..dda9de2a15 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/pwdnm.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* c2 secure */ + +#include <rpc/rpc.h> +#include <rpcsvc/pwdnm.h> + + +bool_t +xdr_pwdnm(xdrs,objp) + XDR *xdrs; + pwdnm *objp; +{ + if (! xdr_wrapstring(xdrs, &objp->name)) { + return(FALSE); + } + if (! xdr_wrapstring(xdrs, &objp->password)) { + return(FALSE); + } + return(TRUE); +} + + diff --git a/usr/src/lib/libbc/libc/gen/common/qeconvert.c b/usr/src/lib/libbc/libc/gen/common/qeconvert.c new file mode 100644 index 0000000000..38c324ddc2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/qeconvert.c @@ -0,0 +1,154 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +char * +qeconvert(arg, ndigits, decpt, sign, buf) + quadruple *arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + static char *nanstring = "NaN"; + static char *infstring = "Infinity"; + char *pc; + int nc; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = floating_form; /* E format. */ + dm.ndigits = ndigits; /* Number of significant digits. */ + quadruple_to_decimal(arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + *decpt = dr.exponent + ndigits; + for (i = 0; i < ndigits; i++) + buf[i] = dr.ds[i]; + buf[ndigits] = 0; + break; + case fp_zero: + *decpt = 1; + for (i = 0; i < ndigits; i++) + buf[i] = '0'; + buf[ndigits] = 0; + break; + case fp_infinity: + *decpt = 0; + pc = infstring; + if (ndigits < 8) + nc = 3; + else + nc = 8; + goto movestring; + case fp_quiet: + case fp_signaling: + *decpt = 0; + pc = nanstring; + nc = 3; +movestring: + for (i = 0; i < nc; i++) + buf[i] = pc[i]; + buf[nc] = 0; + break; + } + return buf; /* For compatibility with ecvt. */ +} + +char * +qfconvert(arg, ndigits, decpt, sign, buf) + quadruple *arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = fixed_form; /* F format. */ + dm.ndigits = ndigits; /* Number of digits after point. */ + quadruple_to_decimal(arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + if (ndigits >= 0) + *decpt = dr.ndigits - ndigits; + else + *decpt = dr.ndigits; + for (i = 0; i < dr.ndigits; i++) + buf[i] = dr.ds[i]; + buf[dr.ndigits] = 0; + break; + case fp_zero: + *decpt = 0; + buf[0] = '0'; + for (i = 1; i < ndigits; i++) + buf[i] = '0'; + buf[i] = 0; + break; + case fp_infinity: + *decpt = 0; + if (ndigits < 8) + buf = "Inf"; + else + buf = "Infinity"; + break; + case fp_quiet: + case fp_signaling: + *decpt = 0; + buf = "NaN"; + break; + } + return buf; /* For compatibility with fcvt. */ +} + +extern void _gcvt(); + +char * +qgconvert(number, ndigit, trailing, buf) + quadruple *number; + int ndigit, trailing; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type fef; + + dm.rd = fp_direction; + dm.df = floating_form; + dm.ndigits = ndigit; + quadruple_to_decimal(number, &dm, &dr, &fef); + _gcvt(ndigit, &dr, trailing, buf); + return (buf); +} diff --git a/usr/src/lib/libbc/libc/gen/common/qsort.c b/usr/src/lib/libbc/libc/gen/common/qsort.c new file mode 100644 index 0000000000..f8c86b7713 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/qsort.c @@ -0,0 +1,221 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/03/089 */ + +/* + * qsort.c: + * Our own version of the system qsort routine which is faster by an average + * of 25%, with lows and highs of 10% and 50%. + * The THRESHold below is the insertion sort threshold, and has been adjusted + * for records of size 48 bytes. + * The MTHREShold is where we stop finding a better median. + */ + +#define THRESH 4 /* threshold for insertion */ +#define MTHRESH 6 /* threshold for median */ + +static int (*qcmp)(); /* the comparison routine */ +static int qsz; /* size of each record */ +static int thresh; /* THRESHold in chars */ +static int mthresh; /* MTHRESHold in chars */ + +/* + * qsort: + * First, set up some global parameters for qst to share. Then, quicksort + * with qst(), and then a cleanup insertion sort ourselves. Sound simple? + * It's not... + */ + +qsort(base, n, size, compar) + char *base; + int n; + int size; + int (*compar)(); +{ + register char c, *i, *j, *lo, *hi; + char *min, *max; + + if (n <= 1) + return; + qsz = size; + qcmp = compar; + thresh = qsz * THRESH; + mthresh = qsz * MTHRESH; + max = base + n * qsz; + if (n >= THRESH) { + qst(base, max); + hi = base + thresh; + } else { + hi = max; + } + /* + * First put smallest element, which must be in the first THRESH, in + * the first position as a sentinel. This is done just by searching + * the first THRESH elements (or the first n if n < THRESH), finding + * the min, and swapping it into the first position. + */ + for (j = lo = base; (lo += qsz) < hi; ) + if (qcmp(j, lo) > 0) + j = lo; + if (j != base) { + /* swap j into place */ + for (i = base, hi = base + qsz; i < hi; ) { + c = *j; + *j++ = *i; + *i++ = c; + } + } + /* + * With our sentinel in place, we now run the following hyper-fast + * insertion sort. For each remaining element, min, from [1] to [n-1], + * set hi to the index of the element AFTER which this one goes. + * Then, do the standard insertion sort shift on a character at a time + * basis for each element in the frob. + */ + for (min = base; (hi = min += qsz) < max; ) { + while (qcmp(hi -= qsz, min) > 0) + /* void */; + if ((hi += qsz) != min) { + for (lo = min + qsz; --lo >= min; ) { + c = *lo; + for (i = j = lo; (j -= qsz) >= hi; i = j) + *i = *j; + *i = c; + } + } + } +} + +/* + * qst: + * Do a quicksort + * First, find the median element, and put that one in the first place as the + * discriminator. (This "median" is just the median of the first, last and + * middle elements). (Using this median instead of the first element is a big + * win). Then, the usual partitioning/swapping, followed by moving the + * discriminator into the right place. Then, figure out the sizes of the two + * partions, do the smaller one recursively and the larger one via a repeat of + * this code. Stopping when there are less than THRESH elements in a partition + * and cleaning up with an insertion sort (in our caller) is a huge win. + * All data swaps are done in-line, which is space-losing but time-saving. + * (And there are only three places where this is done). + */ + +static +qst(base, max) + char *base, *max; +{ + register char c, *i, *j, *jj; + register int ii; + char *mid, *tmp; + int lo, hi; + + /* + * At the top here, lo is the number of characters of elements in the + * current partition. (Which should be max - base). + * Find the median of the first, last, and middle element and make + * that the middle element. Set j to largest of first and middle. + * If max is larger than that guy, then it's that guy, else compare + * max with loser of first and take larger. Things are set up to + * prefer the middle, then the first in case of ties. + */ + lo = max - base; /* number of elements as chars */ + do { + mid = i = base + qsz * ((lo / qsz) >> 1); + if (lo >= mthresh) { + j = (qcmp((jj = base), i) > 0 ? jj : i); + if (qcmp(j, (tmp = max - qsz)) > 0) { + /* switch to first loser */ + j = (j == jj ? i : jj); + if (qcmp(j, tmp) < 0) + j = tmp; + } + if (j != i) { + ii = qsz; + do { + c = *i; + *i++ = *j; + *j++ = c; + } while (--ii); + } + } + /* + * Semi-standard quicksort partitioning/swapping + */ + for (i = base, j = max - qsz; ; ) { + while (i < mid && qcmp(i, mid) <= 0) + i += qsz; + while (j > mid) { + if (qcmp(mid, j) <= 0) { + j -= qsz; + continue; + } + tmp = i + qsz; /* value of i after swap */ + if (i == mid) { + /* j <-> mid, new mid is j */ + mid = jj = j; + } else { + /* i <-> j */ + jj = j; + j -= qsz; + } + goto swap; + } + if (i == mid) { + break; + } else { + /* i <-> mid, new mid is i */ + jj = mid; + tmp = mid = i; /* value of i after swap */ + j -= qsz; + } + swap: + ii = qsz; + do { + c = *i; + *i++ = *jj; + *jj++ = c; + } while (--ii); + i = tmp; + } + /* + * Look at sizes of the two partitions, do the smaller + * one first by recursion, then do the larger one by + * making sure lo is its size, base and max are update + * correctly, and branching back. But only repeat + * (recursively or by branching) if the partition is + * of at least size THRESH. + */ + i = (j = mid) + qsz; + if ((lo = j - base) <= (hi = max - i)) { + if (lo >= thresh) + qst(base, j); + base = i; + lo = hi; + } else { + if (hi >= thresh) + qst(i, max); + max = j; + } + } while (lo >= thresh); +} diff --git a/usr/src/lib/libbc/libc/gen/common/random.c b/usr/src/lib/libbc/libc/gen/common/random.c new file mode 100644 index 0000000000..8213e11b0d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/random.c @@ -0,0 +1,384 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/01/02 */ + +#include <stdio.h> + +/* + * random.c: + * An improved random number generation package. In addition to the standard + * rand()/srand() like interface, this package also has a special state info + * interface. The initstate() routine is called with a seed, an array of + * bytes, and a count of how many bytes are being passed in; this array is then + * initialized to contain information for random number generation with that + * much state information. Good sizes for the amount of state information are + * 32, 64, 128, and 256 bytes. The state can be switched by calling the + * setstate() routine with the same array as was initiallized with initstate(). + * By default, the package runs with 128 bytes of state information and + * generates far better random numbers than a linear congruential generator. + * If the amount of state information is less than 32 bytes, a simple linear + * congruential R.N.G. is used. + * Internally, the state information is treated as an array of longs; the + * zeroeth element of the array is the type of R.N.G. being used (small + * integer); the remainder of the array is the state information for the + * R.N.G. Thus, 32 bytes of state information will give 7 longs worth of + * state information, which will allow a degree seven polynomial. (Note: the + * zeroeth word of state information also has some other information stored + * in it -- see setstate() for details). + * The random number generation technique is a linear feedback shift register + * approach, employing trinomials (since there are fewer terms to sum up that + * way). In this approach, the least significant bit of all the numbers in + * the state table will act as a linear feedback shift register, and will have + * period 2^deg - 1 (where deg is the degree of the polynomial being used, + * assuming that the polynomial is irreducible and primitive). The higher + * order bits will have longer periods, since their values are also influenced + * by pseudo-random carries out of the lower bits. The total period of the + * generator is approximately deg*(2**deg - 1); thus doubling the amount of + * state information has a vast influence on the period of the generator. + * Note: the deg*(2**deg - 1) is an approximation only good for large deg, + * when the period of the shift register is the dominant factor. With deg + * equal to seven, the period is actually much longer than the 7*(2**7 - 1) + * predicted by this formula. + */ + + + +/* + * For each of the currently supported random number generators, we have a + * break value on the amount of state information (you need at least this + * many bytes of state info to support this random number generator), a degree + * for the polynomial (actually a trinomial) that the R.N.G. is based on, and + * the separation between the two lower order coefficients of the trinomial. + */ + +#define TYPE_0 0 /* linear congruential */ +#define BREAK_0 8 +#define DEG_0 0 +#define SEP_0 0 + +#define TYPE_1 1 /* x**7 + x**3 + 1 */ +#define BREAK_1 32 +#define DEG_1 7 +#define SEP_1 3 + +#define TYPE_2 2 /* x**15 + x + 1 */ +#define BREAK_2 64 +#define DEG_2 15 +#define SEP_2 1 + +#define TYPE_3 3 /* x**31 + x**3 + 1 */ +#define BREAK_3 128 +#define DEG_3 31 +#define SEP_3 3 + +#define TYPE_4 4 /* x**63 + x + 1 */ +#define BREAK_4 256 +#define DEG_4 63 +#define SEP_4 1 + + +/* + * Array versions of the above information to make code run faster -- relies + * on fact that TYPE_i == i. + */ + +#define MAX_TYPES 5 /* max number of types above */ + +static struct _randomjunk { + int degrees[MAX_TYPES]; + int seps[MAX_TYPES]; + long randtbl[ DEG_3 + 1 ]; +/* + * fptr and rptr are two pointers into the state info, a front and a rear + * pointer. These two pointers are always rand_sep places aparts, as they cycle + * cyclically through the state information. (Yes, this does mean we could get + * away with just one pointer, but the code for random() is more efficient this + * way). The pointers are left positioned as they would be from the call + * initstate(1, randtbl, 128) + * (The position of the rear pointer, rptr, is really 0 (as explained above + * in the initialization of randtbl) because the state table pointer is set + * to point to randtbl[1] (as explained below). + */ + long *fptr, *rptr; +/* + * The following things are the pointer to the state information table, + * the type of the current generator, the degree of the current polynomial + * being used, and the separation between the two pointers. + * Note that for efficiency of random(), we remember the first location of + * the state information, not the zeroeth. Hence it is valid to access + * state[-1], which is used to store the type of the R.N.G. + * Also, we remember the last location, since this is more efficient than + * indexing every time to find the address of the last element to see if + * the front and rear pointers have wrapped. + */ + long *state; + int rand_type, rand_deg, rand_sep; + long *end_ptr; +} *__randomjunk, *_randomjunk(), _randominit = { + /* + * Initially, everything is set up as if from : + * initstate(1, &randtbl, 128); + * Note that this initialization takes advantage of the fact + * that srandom() advances the front and rear pointers 10*rand_deg + * times, and hence the rear pointer which starts at 0 will also + * end up at zero; thus the zeroeth element of the state + * information, which contains info about the current + * position of the rear pointer is just + * MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3. + */ + { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 }, + { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 }, + { TYPE_3, + (long)0x9a319039, (long)0x32d9c024, (long)0x9b663182, (long)0x5da1f342, + (long)0xde3b81e0, (long)0xdf0a6fb5, (long)0xf103bc02, (long)0x48f340fb, + (long)0x7449e56b, (long)0xbeb1dbb0, (long)0xab5c5918, (long)0x946554fd, + (long)0x8c2e680f, (long)0xeb3d799f, (long)0xb11ee0b7, (long)0x2d436b86, + (long)0xda672e2a, (long)0x1588ca88, (long)0xe369735d, (long)0x904f35f7, + (long)0xd7158fd6, (long)0x6fa6f051, (long)0x616e6b96, (long)0xac94efdc, + (long)0x36413f93, (long)0xc622c298, (long)0xf5a42ab8, (long)0x8a88d77b, + (long)0xf5ad9d0e, (long)0x8999220b, (long)0x27fb47b9 }, + &_randominit.randtbl[ SEP_3 + 1 ], + &_randominit.randtbl[1], + &_randominit.randtbl[1], + TYPE_3, DEG_3, SEP_3, + &_randominit.randtbl[ DEG_3 + 1] +}; + +long random(); +extern char *malloc(); + +static struct _randomjunk * +_randomjunk() +{ + register struct _randomjunk *rp = __randomjunk; + + if (rp == 0) { + rp = (struct _randomjunk *)malloc(sizeof (*rp)); + if (rp == 0) + return (0); + *rp = _randominit; + __randomjunk = rp; + } + return (rp); +} + +/* + * srandom: + * Initialize the random number generator based on the given seed. If the + * type is the trivial no-state-information type, just remember the seed. + * Otherwise, initializes state[] based on the given "seed" via a linear + * congruential generator. Then, the pointers are set to known locations + * that are exactly rand_sep places apart. Lastly, it cycles the state + * information a given number of times to get rid of any initial dependencies + * introduced by the L.C.R.N.G. + * Note that the initialization of randtbl[] for default usage relies on + * values produced by this routine. + */ + +srandom(x) + unsigned x; +{ + register struct _randomjunk *rp = _randomjunk(); + register int i; + + if (rp == 0) + return; + if (rp->rand_type == TYPE_0) { + rp->state[0] = x; + } else { + rp->state[0] = x; + for (i = 1; i < rp->rand_deg; i++) { + rp->state[i] = 1103515245*rp->state[i - 1] + 12345; + } + rp->fptr = &rp->state[rp->rand_sep]; + rp->rptr = &rp->state[0]; + for (i = 0; i < 10 * rp->rand_deg; i++) + random(); + } +} + + + +/* + * initstate: + * Initialize the state information in the given array of n bytes for + * future random number generation. Based on the number of bytes we + * are given, and the break values for the different R.N.G.'s, we choose + * the best (largest) one we can and set things up for it. srandom() is + * then called to initialize the state information. + * Note that on return from srandom(), we set state[-1] to be the type + * multiplexed with the current value of the rear pointer; this is so + * successive calls to initstate() won't lose this information and will + * be able to restart with setstate(). + * Note: the first thing we do is save the current state, if any, just like + * setstate() so that it doesn't matter when initstate is called. + * Returns a pointer to the old state. + */ + +char * +initstate(seed, arg_state, n) + unsigned seed; /* seed for R. N. G. */ + char *arg_state; /* pointer to state array */ + int n; /* # bytes of state info */ +{ + register struct _randomjunk *rp = _randomjunk(); + register char *ostate; + + if (rp == 0) + return (0); + ostate = (char *)(&rp->state[-1]); + + if (rp->rand_type == TYPE_0) rp->state[-1] = rp->rand_type; + else rp->state[-1] = + MAX_TYPES*(rp->rptr - rp->state) + rp->rand_type; + if (n < BREAK_0) { + fprintf(stderr, + "initstate: state array too small, ignored; minimum size is %d bytes\n", + BREAK_0); + return (0); + } else if (n < BREAK_1) { + rp->rand_type = TYPE_0; + rp->rand_deg = DEG_0; + rp->rand_sep = SEP_0; + } else if (n < BREAK_2) { + rp->rand_type = TYPE_1; + rp->rand_deg = DEG_1; + rp->rand_sep = SEP_1; + } else if (n < BREAK_3) { + rp->rand_type = TYPE_2; + rp->rand_deg = DEG_2; + rp->rand_sep = SEP_2; + } else if (n < BREAK_4) { + rp->rand_type = TYPE_3; + rp->rand_deg = DEG_3; + rp->rand_sep = SEP_3; + } else { + rp->rand_type = TYPE_4; + rp->rand_deg = DEG_4; + rp->rand_sep = SEP_4; + } + rp->state = &((long *)arg_state)[1]; /* first location */ + rp->end_ptr = &rp->state[rp->rand_deg]; /* set end_ptr before srandom */ + srandom(seed); + rp->state[-1] = (rp->rand_type == TYPE_0) ? rp->rand_type + : MAX_TYPES * (rp->rptr - rp->state) + rp->rand_type; + return (ostate); +} + + +/* + * setstate: + * Restore the state from the given state array. + * Note: it is important that we also remember the locations of the pointers + * in the current state information, and restore the locations of the pointers + * from the old state information. This is done by multiplexing the pointer + * location into the zeroeth word of the state information. + * Note that due to the order in which things are done, it is OK to call + * setstate() with the same state as the current state. + * Returns a pointer to the old state information. + */ + +char * +setstate(arg_state) + char *arg_state; +{ + register struct _randomjunk *rp = _randomjunk(); + register long *new_state; + register int type; + register int rear; + char *ostate; + + if (rp == 0) + return (0); + new_state = (long *)arg_state; + type = new_state[0] % MAX_TYPES; + rear = new_state[0] / MAX_TYPES; + ostate = (char *)(&rp->state[-1]); + + rp->state[-1] = (rp->rand_type == TYPE_0) ? rp->rand_type + : MAX_TYPES*(rp->rptr - rp->state) + rp->rand_type; + switch (type) { + case TYPE_0: + case TYPE_1: + case TYPE_2: + case TYPE_3: + case TYPE_4: + rp->rand_type = type; + rp->rand_deg = rp->degrees[type]; + rp->rand_sep = rp->seps[type]; + break; + + default: + fprintf(stderr, "setstate: invalid state info; not changed.\n"); + } + rp->state = &new_state[1]; + if (rp->rand_type != TYPE_0) { + rp->rptr = &rp->state[rear]; + rp->fptr = &rp->state[(rear + rp->rand_sep) % rp->rand_deg]; + } + rp->end_ptr = &rp->state[rp->rand_deg]; /* set end_ptr too */ + return (ostate); +} + + +/* + * random: + * If we are using the trivial TYPE_0 R.N.G., just do the old linear + * congruential bit. Otherwise, we do our fancy trinomial stuff, which is the + * same in all ther other cases due to all the global variables that have been + * set up. The basic operation is to add the number at the rear pointer into + * the one at the front pointer. Then both pointers are advanced to the next + * location cyclically in the table. The value returned is the sum generated, + * reduced to 31 bits by throwing away the "least random" low bit. + * Note: the code takes advantage of the fact that both the front and + * rear pointers can't wrap on the same call by not testing the rear + * pointer if the front one has wrapped. + * Returns a 31-bit random number. + */ + +long +random() +{ + register struct _randomjunk *rp = _randomjunk(); + long i; + + if (rp == 0) + return (0); + if (rp->rand_type == TYPE_0) { + i = rp->state[0] = (rp->state[0]*1103515245 + 12345)&0x7fffffff; + } else { + *rp->fptr += *rp->rptr; + i = (*rp->fptr >> 1)&0x7fffffff; /* chucking least random bit */ + if (++rp->fptr >= rp->end_ptr) { + rp->fptr = rp->state; + ++rp->rptr; + } else if (++rp->rptr >= rp->end_ptr) + rp->rptr = rp->state; + } + return (i); +} diff --git a/usr/src/lib/libbc/libc/gen/common/readdir.c b/usr/src/lib/libbc/libc/gen/common/readdir.c new file mode 100644 index 0000000000..c4f2c65652 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/readdir.c @@ -0,0 +1,67 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/param.h> +#include <dirent.h> + +/* + * get next entry in a directory. + */ +struct dirent * +readdir(dirp) + register DIR *dirp; +{ + register struct dirent *dp; + int saveloc = 0; + +next: + if (dirp->dd_size != 0) { + dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc]; + saveloc = dirp->dd_loc; /* save for possible EOF */ + dirp->dd_loc += dp->d_reclen; + } + if (dirp->dd_loc >= dirp->dd_size) + dirp->dd_loc = dirp->dd_size = 0; + + if (dirp->dd_size == 0 /* refill buffer */ + && (dirp->dd_size = getdents(dirp->dd_fd, dirp->dd_buf, dirp->dd_bsize) + ) <= 0 + ) { + if (dirp->dd_size == 0) /* This means EOF */ + dirp->dd_loc = saveloc; /* EOF so save for telldir */ + return (NULL); /* error or EOF */ + } + + dp = (struct dirent *)&dirp->dd_buf[dirp->dd_loc]; + if (dp->d_reclen <= 0) + return (NULL); + if (dp->d_fileno == 0) + goto next; + dirp->dd_off = dp->d_off; + return(dp); +} diff --git a/usr/src/lib/libbc/libc/gen/common/realpath.c b/usr/src/lib/libbc/libc/gen/common/realpath.c new file mode 100644 index 0000000000..2fa7c5333a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/realpath.c @@ -0,0 +1,241 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +#include <strings.h> +#include <sys/param.h> +#include <errno.h> + +extern char *getwd(); + +/* LINTLIBRARY */ + +/* + * Input name in raw, canonicalized pathname output to canon. If dosymlinks + * is nonzero, resolves all symbolic links encountered during canonicalization + * into an equivalent symlink-free form. Returns 0 on success, -1 on failure. + * The routine fails if the current working directory can't be obtained or if + * either of the arguments is NULL. + * + * Sets errno on failure. + */ +int +pathcanon(raw, canon, dosymlinks) + char *raw, + *canon; + int dosymlinks; +{ + register char *s, + *d; + register char *limit = canon + MAXPATHLEN; + char *modcanon; + int nlink = 0; + + /* + * Do a bit of sanity checking. + */ + if (raw == NULL || canon == NULL) { + errno = EINVAL; + return (-1); + } + + /* + * If the path in raw is not already absolute, convert it to that form. + * In any case, initialize canon with the absolute form of raw. Make + * sure that none of the operations overflow the corresponding buffers. + * The code below does the copy operations by hand so that it can easily + * keep track of whether overflow is about to occur. + */ + s = raw; + d = canon; + if (*s != '/') { + /* Relative; prepend the working directory. */ + if (getwd(d) == NULL) { + /* Use whatever errno value getwd may have left around. */ + return (-1); + } + d += strlen(d); + /* Add slash to separate working directory from relative part. */ + if (d < limit) + *d++ = '/'; + modcanon = d; + } else + modcanon = canon; + while (d < limit && *s) + *d++ = *s++; + + /* Add a trailing slash to simplify the code below. */ + s = "/"; + while (d < limit && (*d++ = *s++)) + continue; + + + /* + * Canonicalize the path. The strategy is to update in place, with + * d pointing to the end of the canonicalized portion and s to the + * current spot from which we're copying. This works because + * canonicalization doesn't increase path length, except as discussed + * below. Note also that the path has had a slash added at its end. + * This greatly simplifies the treatment of boundary conditions. + */ + d = s = modcanon; + while (d < limit && *s) { + if ((*d++ = *s++) == '/' && d > canon + 1) { + register char *t = d - 2; + + switch (*t) { + case '/': + /* Found // in the name. */ + d--; + continue; + case '.': + switch (*--t) { + case '/': + /* Found /./ in the name. */ + d -= 2; + continue; + case '.': + if (*--t == '/') { + /* Found /../ in the name. */ + while (t > canon && *--t != '/') + continue; + d = t + 1; + } + continue; + default: + break; + } + break; + default: + break; + } + /* + * We're at the end of a component. If dosymlinks is set + * see whether the component is a symbolic link. If so, + * replace it by its contents. + */ + if (dosymlinks) { + char link[MAXPATHLEN + 1]; + register int llen; + + /* + * See whether it's a symlink by trying to read it. + * + * Start by isolating it. + */ + *(d - 1) = '\0'; + if ((llen = readlink(canon, link, sizeof link)) >= 0) { + /* Make sure that there are no circular links. */ + nlink++; + if (nlink > MAXSYMLINKS) { + errno = ELOOP; + return (-1); + } + /* + * The component is a symlink. Since its value can be + * of arbitrary size, we can't continue copying in place. + * Instead, form the new path suffix in the link buffer + * and then copy it back to its proper spot in canon. + */ + t = link + llen; + *t++ = '/'; + /* + * Copy the remaining unresolved portion to the end + * of the symlink. If the sum of the unresolved part and + * the readlink exceeds MAXPATHLEN, the extra bytes + * will be dropped off. Too bad! + */ + (void) strncpy(t, s, sizeof link - llen - 1); + link[sizeof link - 1] = '\0'; + /* + * If the link's contents are absolute, copy it back + * to the start of canon, otherwise to the beginning of + * the link's position in the path. + */ + if (link[0] == '/') { + /* Absolute. */ + (void) strcpy(canon, link); + d = s = canon; + } + else { + /* + * Relative: find beginning of component and copy. + */ + --d; + while (d > canon && *--d != '/') + continue; + s = ++d; + /* + * If the sum of the resolved part, the readlink + * and the remaining unresolved part exceeds + * MAXPATHLEN, the extra bytes will be dropped off. + */ + if (strlen(link) >= (limit - s)) { + (void) strncpy(s, link, limit - s); + *(limit - 1) = '\0'; + } else { + (void) strcpy(s, link); + } + } + continue; + } else { + /* + * readlink call failed. It can be because it was + * not a link (i.e. a file, dir etc.) or because the + * the call actually failed. + */ + if (errno != EINVAL) + return (-1); + *(d - 1) = '/'; /* Restore it */ + } + } /* if (dosymlinks) */ + } + } /* while */ + + /* Remove the trailing slash that was added above. */ + if (*(d - 1) == '/' && d > canon + 1) + d--; + *d = '\0'; + return (0); +} + +/* + * Canonicalize the path given in raw, resolving away all symbolic link + * components. Store the result into the buffer named by canon, which + * must be long enough (MAXPATHLEN bytes will suffice). Returns NULL + * on failure and canon on success. + * + * The routine indirectly invokes the readlink() system call and getwd() + * so it inherits the possibility of hanging due to inaccessible file + * system resources. + */ +char * +realpath(raw, canon) + char *raw; + char *canon; +{ + return (pathcanon(raw, canon, 1) < 0 ? NULL : canon); +} diff --git a/usr/src/lib/libbc/libc/gen/common/regex.c b/usr/src/lib/libbc/libc/gen/common/regex.c new file mode 100644 index 0000000000..9352d6ca7e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/regex.c @@ -0,0 +1,441 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * routines to do regular expression matching + * + * Entry points: + * + * re_comp(s) + * char *s; + * ... returns 0 if the string s was compiled successfully, + * a pointer to an error message otherwise. + * If passed 0 or a null string returns without changing + * the currently compiled re (see note 11 below). + * + * re_exec(s) + * char *s; + * ... returns 1 if the string s matches the last compiled regular + * expression, + * 0 if the string s failed to match the last compiled + * regular expression, and + * -1 if the compiled regular expression was invalid + * (indicating an internal error). + * + * The strings passed to both re_comp and re_exec may have trailing or + * embedded newline characters; they are terminated by nulls. + * + * The identity of the author of these routines is lost in antiquity; + * this is essentially the same as the re code in the original V6 ed. + * + * The regular expressions recognized are described below. This description + * is essentially the same as that for ed. + * + * A regular expression specifies a set of strings of characters. + * A member of this set of strings is said to be matched by + * the regular expression. In the following specification for + * regular expressions the word `character' means any character but NUL. + * + * 1. Any character except a special character matches itself. + * Special characters are the regular expression delimiter plus + * \ [ . and sometimes ^ * $. + * 2. A . matches any character. + * 3. A \ followed by any character except a digit or ( ) + * matches that character. + * 4. A nonempty string s bracketed [s] (or [^s]) matches any + * character in (or not in) s. In s, \ has no special meaning, + * and ] may only appear as the first letter. A substring + * a-b, with a and b in ascending ASCII order, stands for + * the inclusive range of ASCII characters. + * 5. A regular expression of form 1-4 followed by * matches a + * sequence of 0 or more matches of the regular expression. + * 6. A regular expression, x, of form 1-8, bracketed \(x\) + * matches what x matches. + * 7. A \ followed by a digit n matches a copy of the string that the + * bracketed regular expression beginning with the nth \( matched. + * 8. A regular expression of form 1-8, x, followed by a regular + * expression of form 1-7, y matches a match for x followed by + * a match for y, with the x match being as long as possible + * while still permitting a y match. + * 9. A regular expression of form 1-8 preceded by ^ (or followed + * by $), is constrained to matches that begin at the left + * (or end at the right) end of a line. + * 10. A regular expression of form 1-9 picks out the longest among + * the leftmost matches in a line. + * 11. An empty regular expression stands for a copy of the last + * regular expression encountered. + */ + +/* + * constants for re's + */ +#define CBRA 1 +#define CCHR 2 +#define CDOT 4 +#define CCL 6 +#define NCCL 8 +#define CDOL 10 +#define CEOF 11 +#define CKET 12 +#define CBACK 18 + +#define CSTAR 01 + +#define ESIZE 512 +#define NBRA 9 + +static struct re_globals { + char _expbuf[ESIZE]; + char *_braslist[NBRA], *_braelist[NBRA]; + char _circf; +} *re_globals; +#define expbuf (_re->_expbuf) +#define braslist (_re->_braslist) +#define braelist (_re->_braelist) +#define circf (_re->_circf) + +/* + * compile the regular expression argument into a dfa + */ +char * +re_comp(sp) + register char *sp; +{ + register int c; + register struct re_globals *_re = re_globals; + register char *ep; + int cclcnt, numbra = 0; + char *lastep = 0; + char bracket[NBRA]; + char *bracketp = &bracket[0]; + char *retoolong = "Regular expression too long"; + + if (_re == 0) { + _re = (struct re_globals *)calloc(1, sizeof (*_re)); + if (_re == 0) + return ("Out of memory"); + re_globals = _re; + } + ep = expbuf; + +#define comerr(msg) {expbuf[0] = 0; numbra = 0; return(msg); } + + if (sp == 0 || *sp == '\0') { + if (*ep == 0) + return("No previous regular expression"); + return(0); + } + if (*sp == '^') { + circf = 1; + sp++; + } + else + circf = 0; + for (;;) { + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + if ((c = *sp++) == '\0') { + if (bracketp != bracket) + comerr("unmatched \\("); + *ep++ = CEOF; + *ep++ = 0; + return(0); + } + if (c != '*') + lastep = ep; + switch (c) { + + case '.': + *ep++ = CDOT; + continue; + + case '*': + if (lastep == 0 || *lastep == CBRA || *lastep == CKET) + goto defchar; + *lastep |= CSTAR; + continue; + + case '$': + if (*sp != '\0') + goto defchar; + *ep++ = CDOL; + continue; + + case '[': + *ep++ = CCL; + *ep++ = 0; + cclcnt = 1; + if ((c = *sp++) == '^') { + c = *sp++; + ep[-2] = NCCL; + } + do { + if (c == '\0') + comerr("missing ]"); + if (c == '-' && ep [-1] != 0) { + if ((c = *sp++) == ']') { + *ep++ = '-'; + cclcnt++; + break; + } + while (ep[-1] < c) { + *ep = ep[-1] + 1; + ep++; + cclcnt++; + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + } + } + *ep++ = c; + cclcnt++; + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + } while ((c = *sp++) != ']'); + lastep[1] = cclcnt; + continue; + + case '\\': + if ((c = *sp++) == '(') { + if (numbra >= NBRA) + comerr("too many \\(\\) pairs"); + *bracketp++ = numbra; + *ep++ = CBRA; + *ep++ = numbra++; + continue; + } + if (c == ')') { + if (bracketp <= bracket) + comerr("unmatched \\)"); + *ep++ = CKET; + *ep++ = *--bracketp; + continue; + } + if (c >= '1' && c < ('1' + NBRA)) { + *ep++ = CBACK; + *ep++ = c - '1'; + continue; + } + *ep++ = CCHR; + *ep++ = c; + continue; + + defchar: + default: + *ep++ = CCHR; + *ep++ = c; + } + } +} + +/* + * match the argument string against the compiled re + */ +int +re_exec(p1) + register char *p1; +{ + register struct re_globals *_re = re_globals; + register char *p2; + register int c; + int rv; + + if (_re == 0) + return (0); + p2 = expbuf; + for (c = 0; c < NBRA; c++) { + braslist[c] = 0; + braelist[c] = 0; + } + if (circf) + return((advance(p1, p2))); + /* + * fast check for first character + */ + if (*p2 == CCHR) { + c = p2[1]; + do { + if (*p1 != c) + continue; + if (rv = advance(p1, p2)) + return(rv); + } while (*p1++); + return(0); + } + /* + * regular algorithm + */ + do + if (rv = advance(p1, p2)) + return(rv); + while (*p1++); + return(0); +} + +/* + * try to match the next thing in the dfa + */ +static int +advance(lp, ep) + register char *lp, *ep; +{ + register char *curlp; + int ct, i; + int rv; + register struct re_globals *_re = re_globals; + + for (;;) + switch (*ep++) { + + case CCHR: + if (*ep++ == *lp++) + continue; + return(0); + + case CDOT: + if (*lp++) + continue; + return(0); + + case CDOL: + if (*lp == '\0') + continue; + return(0); + + case CEOF: + return(1); + + case CCL: + if (cclass(ep, *lp++, 1)) { + ep += *ep; + continue; + } + return(0); + + case NCCL: + if (cclass(ep, *lp++, 0)) { + ep += *ep; + continue; + } + return(0); + + case CBRA: + braslist[*ep++] = lp; + continue; + + case CKET: + braelist[*ep++] = lp; + continue; + + case CBACK: + if (braelist[i = *ep++] == 0) + return(-1); + if (backref(i, lp)) { + lp += braelist[i] - braslist[i]; + continue; + } + return(0); + + case CBACK|CSTAR: + if (braelist[i = *ep++] == 0) + return(-1); + curlp = lp; + ct = braelist[i] - braslist[i]; + while (backref(i, lp)) + lp += ct; + while (lp >= curlp) { + if (rv = advance(lp, ep)) + return(rv); + lp -= ct; + } + continue; + + case CDOT|CSTAR: + curlp = lp; + while (*lp++) + ; + goto star; + + case CCHR|CSTAR: + curlp = lp; + while (*lp++ == *ep) + ; + ep++; + goto star; + + case CCL|CSTAR: + case NCCL|CSTAR: + curlp = lp; + while (cclass(ep, *lp++, ep[-1] == (CCL|CSTAR))) + ; + ep += *ep; + goto star; + + star: + do { + lp--; + if (rv = advance(lp, ep)) + return(rv); + } while (lp > curlp); + return(0); + + default: + return(-1); + } +} + +static +backref(i, lp) + register int i; + register char *lp; +{ + register char *bp; + register struct re_globals *_re = re_globals; + + bp = braslist[i]; + while (*bp++ == *lp++) + if (bp >= braelist[i]) + return(1); + return(0); +} + +static int +cclass(set, c, af) + register char *set, c; + int af; +{ + register int n; + + if (c == 0) + return(0); + n = *set++; + while (--n) + if (*set++ == c) + return(af); + return(! af); +} diff --git a/usr/src/lib/libbc/libc/gen/common/rindex.c b/usr/src/lib/libbc/libc/gen/common/rindex.c new file mode 100644 index 0000000000..fd442e4b13 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/rindex.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * Return the ptr in sp at which the character c last + * appears; NULL if not found + */ + +#define NULL 0 + +char * +rindex(sp, c) + register char *sp, c; +{ + register char *r; + + r = NULL; + do { + if (*sp == c) + r = sp; + } while (*sp++); + return (r); +} diff --git a/usr/src/lib/libbc/libc/gen/common/scandir.c b/usr/src/lib/libbc/libc/gen/common/scandir.c new file mode 100644 index 0000000000..ca66e6ebd5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/scandir.c @@ -0,0 +1,107 @@ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms are permitted + * provided that the above copyright notice and this paragraph are + * duplicated in all such forms and that any documentation, + * advertising materials, and other materials related to such + * distribution and use acknowledge that the software was developed + * by the University of California, Berkeley. The name of the + * University may not be used to endorse or promote products derived + * from this software without specific prior written permission. + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED + * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/05/30 */ + +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +/* + * Scan the directory dirname calling select to make a list of selected + * directory entries then sort using qsort and compare routine dcomp. + * Returns the number of entries and a pointer to a list of pointers to + * struct direct (through namelist). Returns -1 if there were any errors. + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/dir.h> + +scandir(dirname, namelist, select, dcomp) + char *dirname; + struct direct *(*namelist[]); + int (*select)(), (*dcomp)(); +{ + register struct direct *d, *p, **names; + register int nitems; + register char *cp1, *cp2; + struct stat stb; + long arraysz; + DIR *dirp; + + if ((dirp = opendir(dirname)) == NULL) + return(-1); + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); + + /* + * estimate the array size by taking the size of the directory file + * and dividing it by a multiple of the minimum size entry. + */ + arraysz = (stb.st_size / 24); + names = (struct direct **)malloc(arraysz * sizeof(struct direct *)); + if (names == NULL) + return(-1); + + nitems = 0; + while ((d = readdir(dirp)) != NULL) { + if (select != NULL && !(*select)(d)) + continue; /* just selected names */ + /* + * Make a minimum size copy of the data + */ + p = (struct direct *)malloc(DIRSIZ(d)); + if (p == NULL) + return(-1); + p->d_ino = d->d_ino; + p->d_reclen = d->d_reclen; + p->d_namlen = d->d_namlen; + for (cp1 = p->d_name, cp2 = d->d_name; *cp1++ = *cp2++; ); + /* + * Check to make sure the array has space left and + * realloc the maximum size. + */ + if (++nitems >= arraysz) { + if (fstat(dirp->dd_fd, &stb) < 0) + return(-1); /* just might have grown */ + arraysz = stb.st_size / 12; + names = (struct direct **)realloc((char *)names, + arraysz * sizeof(struct direct *)); + if (names == NULL) + return(-1); + } + names[nitems-1] = p; + } + closedir(dirp); + if (nitems && dcomp != NULL) + qsort(names, nitems, sizeof(struct direct *), dcomp); + *namelist = names; + return(nitems); +} + +/* + * Alphabetic order comparison routine for those who want it. + */ +alphasort(d1, d2) + struct direct **d1, **d2; +{ + return(strcmp((*d1)->d_name, (*d2)->d_name)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/seconvert.c b/usr/src/lib/libbc/libc/gen/common/seconvert.c new file mode 100644 index 0000000000..99e86a8656 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/seconvert.c @@ -0,0 +1,154 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include "base_conversion.h" + +char * +seconvert(arg, ndigits, decpt, sign, buf) + single *arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + static char *nanstring = "NaN"; + static char *infstring = "Infinity"; + char *pc; + int nc; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = floating_form; /* E format. */ + dm.ndigits = ndigits; /* Number of significant digits. */ + single_to_decimal(arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + *decpt = dr.exponent + ndigits; + for (i = 0; i < ndigits; i++) + buf[i] = dr.ds[i]; + buf[ndigits] = 0; + break; + case fp_zero: + *decpt = 1; + for (i = 0; i < ndigits; i++) + buf[i] = '0'; + buf[ndigits] = 0; + break; + case fp_infinity: + *decpt = 0; + pc = infstring; + if (ndigits < 8) + nc = 3; + else + nc = 8; + goto movestring; + case fp_quiet: + case fp_signaling: + *decpt = 0; + pc = nanstring; + nc = 3; +movestring: + for (i = 0; i < nc; i++) + buf[i] = pc[i]; + buf[nc] = 0; + break; + } + return buf; /* For compatibility with ecvt. */ +} + +char * +sfconvert(arg, ndigits, decpt, sign, buf) + single *arg; + int ndigits, *decpt, *sign; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type ef; + int i; + + dm.rd = fp_direction; /* Rounding direction. */ + dm.df = fixed_form; /* F format. */ + dm.ndigits = ndigits; /* Number of digits after point. */ + single_to_decimal(arg, &dm, &dr, &ef); + *sign = dr.sign; + switch (dr.fpclass) { + case fp_normal: + case fp_subnormal: + if (ndigits >= 0) + *decpt = dr.ndigits - ndigits; + else + *decpt = dr.ndigits; + for (i = 0; i < dr.ndigits; i++) + buf[i] = dr.ds[i]; + buf[dr.ndigits] = 0; + break; + case fp_zero: + *decpt = 0; + buf[0] = '0'; + for (i = 1; i < ndigits; i++) + buf[i] = '0'; + buf[i] = 0; + break; + case fp_infinity: + *decpt = 0; + if (ndigits < 8) + buf = "Inf"; + else + buf = "Infinity"; + break; + case fp_quiet: + case fp_signaling: + *decpt = 0; + buf = "NaN"; + break; + } + return buf; /* For compatibility with fcvt. */ +} + +extern void _gcvt(); + +char * +sgconvert(number, ndigit, trailing, buf) + single *number; + int ndigit, trailing; + char *buf; +{ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type fef; + + dm.rd = fp_direction; + dm.df = floating_form; + dm.ndigits = ndigit; + single_to_decimal(number, &dm, &dr, &fef); + _gcvt(ndigit, &dr, trailing, buf); + return (buf); +} diff --git a/usr/src/lib/libbc/libc/gen/common/seekdir.c b/usr/src/lib/libbc/libc/gen/common/seekdir.c new file mode 100644 index 0000000000..55facc6aa2 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/seekdir.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/param.h> +#include <dirent.h> + +/* + * seek to an entry in a directory. + * Only values returned by "telldir" should be passed to seekdir. + */ +void +seekdir(dirp, tell) + register DIR *dirp; + register long tell; +{ + extern long lseek(); + long curloc; + + curloc = telldir(dirp); + if (curloc == tell) + return; + dirp->dd_loc = 0; + (void) lseek(dirp->dd_fd, tell, 0); + dirp->dd_size = 0; + dirp->dd_off = tell; +} + +#undef rewinddir + +void +rewinddir(dirp) + DIR *dirp; +{ + seekdir(dirp, 0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/setlocale.c b/usr/src/lib/libbc/libc/gen/common/setlocale.c new file mode 100644 index 0000000000..9d4691198f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/setlocale.c @@ -0,0 +1,861 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <fcntl.h> +extern int open(); +#include <locale.h> +#include <stdlib.h> +#include "codeset.h" +#include <ctype.h> +#include <string.h> +#include <memory.h> +#include <malloc.h> +#include <sys/param.h> /* for MAXPATHLEN */ +#include <sys/stat.h> +#include <errno.h> +#include <limits.h> + +#define TRAILER ".ci" + +extern int stat(); +extern char *getenv(); + +struct _code_set_info _code_set_info = { + NULL, + CODESET_NONE, /* no codeset */ + NULL, /* not defined */ + 0, +}; + +/* tolower() and toupper() conversion table + * is hidden here to avoid being placed in the + * extern .sa file in the dynamic version of libc + */ + +char _ctype_ul[] = { 0, + +/* 0 1 2 3 4 5 6 7 */ + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', + ' ', '!', '"', '#', '$', '%', '&', '\'', + '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ':', ';', '<', '=', '>', '?', + '@', 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', '[', '\\', ']', '^', '_', + '`', 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', '{', '|', '}', '~', '\177', + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, +}; + +/* following layout is: + * LC_NUMERIC LC_TIME LC_MONETARY LANGINFO LC_COLLATE LC_MESSAGES + */ +char _locales[MAXLOCALE - 1][MAXLOCALENAME + 1] ; + +char _my_time[MAXLOCALENAME + 1]; + +/* The array Default holds the systems notion of default locale. It is normally + * found in {LOCALE}/.default and moved to here. Note there is only one + * default locale spanning all categories + */ + +static char Default[MAXLOCALENAME+1]; + +struct langinfo _langinfo; +struct dtconv *_dtconv = NULL; + +static char *realmonths = NULL; +static char *realdays = NULL; +static char *realfmts = NULL; +static short lang_succ = ON; /* setlocale success */ + + +/* Set the values here to guarantee stdio use of the + decimal point + */ +static struct lconv lconv_arr = { + ".", "", "", "", "", + "", "", "", "", "", + CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX, + CHAR_MAX, CHAR_MAX, CHAR_MAX, CHAR_MAX +}; + +/* lconv is externally defined by ANSI C */ +struct lconv *lconv = &lconv_arr; + +static char *lconv_numeric_str = NULL; +static char *lconv_monetary_str = NULL; + +int getlocale_ctype(/*char *locale, char *ctypep, char *newlocale*/); +char *getlocale_numeric(/*char *locale, struct lconv *lconvp*/); +static char *getlocale_monetary(); +void init_statics(); + +static char *getstr(/*char *p, char **strp*/); +static char *getgrouping(/*char *p, char **groupingp*/); +static char *getnum(/*char *p, int *nump*/); +static char *getbool(/*char *p, int *boolp*/); +int openlocale(/*char *category, int cat_id, char *locale, char *newlocale */); +static int set_codeinfo(/*char */); +static int set_default(); + +char * +setlocale(category, locale) + int category; + char *locale; +{ + static char buf[MAXLOCALE*(MAXLOCALENAME + 1) + 1]; + /* buffer for current LC_ALL value */ + int nonuniform; + short ret; + char my_ctype[CTYPE_SIZE]; /* local copy */ + struct lconv my_lconv; /* local copy */ + char *my_lconv_numeric_str; + char *my_lconv_monetary_str; + register int i; + register char *p; + + + /* initialize my_lconv to lconv */ + memcpy(&my_lconv, lconv, sizeof(my_lconv)); + + /* + * Following code is to avoid static initialisation of + * strings which would otherwise blow up "xstr". + */ + if (_locales[0][0] == '\0') + init_statics(); + + if (locale == NULL) { + if (category == LC_ALL) { + /* + * Assume all locales are set to the same value. Then + * scan through the locales to see if any are + * different. If they are the same, return the common + * value; otherwise, construct a "composite" value. + */ + nonuniform = 0; /* assume all locales set the same */ + for (i = 0; i < MAXLOCALE - 2; i++) { + if (strcmp(_locales[i], _locales[i + 1]) != 0) { + nonuniform = 1; + break; + } + } + if (nonuniform) { + /* + * They're not all the same. Construct a list + * of all the locale values, in order, + * separated by slashes. Return that value. + */ + (void) strcpy(buf, _locales[0]); + for (i = 1; i < MAXLOCALE - 1; i++) { + (void) strcat(buf, "/"); + (void) strcat(buf, _locales[i]); + } + return (buf); + } else { + /* + * They're all the same; any one you return is + * OK. + */ + return (_locales[0]); + } + } else + return (_locales[category - 1]); + } + + switch (category) { + + case LC_ALL: + if (strchr(locale, '/') != NULL) { + /* + * Composite value; extract each category. + */ + if (strlen(locale) > sizeof buf - 1) + return (NULL); /* too long */ + (void) strcpy(buf, locale); + p = buf; + + /* + * LC_CTYPE and LC_NUMERIC are set here. + * Others locales won't be set here, + * they will be just marked. + */ + for (i = 0; i < MAXLOCALE - 1; i++) { + p = strtok(p, "/"); + if (p == NULL) + return (NULL); /* missing item */ + switch (i) { + + case LC_CTYPE - 1: + if (setlocale(LC_CTYPE,p) == NULL) + return NULL; + break; + case LC_NUMERIC - 1: + if (setlocale(LC_NUMERIC,p) == NULL) + return NULL; + break; + case LC_TIME - 1: + if (setlocale(LC_TIME,p) == NULL) + return NULL; + break; + case LC_MONETARY - 1: + if (setlocale(LC_MONETARY,p) == NULL) + return NULL; + break; + case LANGINFO - 1: + if (setlocale(LANGINFO,p) == NULL) + return NULL; + break; + case LC_COLLATE - 1: + if (setlocale(LC_COLLATE,p) == NULL) + return NULL; + break; + case LC_MESSAGES - 1: + if (setlocale(LC_MESSAGES,p) == NULL) + return NULL; + break; + } + p = NULL; + } + if (strtok((char *)NULL, "/") != NULL) + return (NULL); /* extra stuff at end */ + } + + /* If category = LC_ALL, Drop through to test each individual + * category, one at a time. Note default rules where env vars + * are not set + */ + + case LC_CTYPE: + if ((ret = getlocale_ctype(locale , my_ctype, + _locales[LC_CTYPE - 1])) < 0) + return (NULL); + if (ret) { + (void) memcpy(_ctype_, my_ctype, CTYPE_SIZE/2); + (void) memcpy(_ctype_ul, my_ctype+(CTYPE_SIZE/2), CTYPE_SIZE/2); + } + if (category != LC_ALL) + break; + + case LC_NUMERIC: + if ((my_lconv_numeric_str = + getlocale_numeric(locale, &my_lconv, + _locales[LC_NUMERIC - 1])) == NULL) + return (NULL); + if (*my_lconv_numeric_str) { + if (lconv_numeric_str != NULL) + free((malloc_t)lconv_numeric_str); + lconv_numeric_str = my_lconv_numeric_str; + memcpy(lconv, my_lconv, sizeof(my_lconv)); + } + if (category != LC_ALL) + break; + + case LC_TIME: + if ((ret = openlocale("LC_TIME", LC_TIME, locale, + _locales[LC_TIME -1])) < 0) + return (NULL); + if (ret) + (void) close(ret); + if (category != LC_ALL) + break; + + case LC_MONETARY: + if ((my_lconv_monetary_str = + getlocale_monetary(locale, &my_lconv, + _locales[LC_MONETARY - 1])) == NULL) + return (NULL); + if (*my_lconv_monetary_str) { + if (lconv_monetary_str != NULL) + free((malloc_t)lconv_monetary_str); + lconv_monetary_str = my_lconv_monetary_str; + memcpy(lconv, &my_lconv, sizeof(my_lconv)); + } + if (category != LC_ALL) + break; + + case LANGINFO: + if ((ret = openlocale("LANGINFO", LANGINFO, locale, + _locales[LANGINFO - 1])) < 0) { + lang_succ = OFF; + return (NULL); + } + if (ret) { + lang_succ = OFF; + (void) close(ret); + } + if (category != LC_ALL) + break; + + case LC_COLLATE: + if ((ret = openlocale("LC_COLLATE", LC_COLLATE, locale, + _locales[LC_COLLATE - 1])) < 0) + return (NULL); + if (ret) { + (void) close(ret); + } + if (category != LC_ALL) + break; + + case LC_MESSAGES: + if ((ret = openlocale("LC_MESSAGES", LC_MESSAGES, locale, + _locales[LC_MESSAGES - 1])) < 0) + return (NULL); + if (ret) { + (void) close(ret); + } + } + return (setlocale(category, (char *)NULL)); +} + +int +getlocale_ctype(locale, ctypep, newlocale) + char *locale; + char *ctypep; + char *newlocale; +{ + register int fd; + + if ((fd = openlocale("LC_CTYPE", LC_CTYPE, locale, newlocale)) > 0) { + if (read(fd, (char *)ctypep, CTYPE_SIZE) != CTYPE_SIZE) { + (void) close(fd); + fd = -1; + } + (void) close(fd); + } + return (fd); +} + +/* open and load the numeric information */ + +char * +getlocale_numeric(locale, lconvp, newlocale) + char *locale; + register struct lconv *lconvp; + char *newlocale; +{ + register int fd; + struct stat buf; + char *str; + register char *p; + + if ((fd = openlocale("LC_NUMERIC", LC_NUMERIC, locale, newlocale)) < 0) + return (NULL); + if (fd == 0) + return ""; + if ((fstat(fd, &buf)) != 0) + return (NULL); + if ((str = (char*)malloc((unsigned)buf.st_size + 2)) == NULL) + return (NULL); + + if ((read(fd, str, (int)buf.st_size)) != buf.st_size) { + free((malloc_t)str); + return (NULL); + } + + /* Set last character of str to '\0' */ + p = &str[buf.st_size]; + *p++ = '\n'; + *p = '\0'; + + /* p will "walk thru" str */ + p = str; + + p = getstr(p, &lconvp->decimal_point); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->thousands_sep); + if (p == NULL) + goto fail; + p = getgrouping(p, &lconvp->grouping); + if (p == NULL) + goto fail; + (void) close(fd); + + return (str); + +fail: + (void) close(fd); + free((malloc_t)str); + return (NULL); +} + + +static char * +getlocale_monetary(locale, lconvp, newlocale) + char *locale; + register struct lconv *lconvp; + char *newlocale; +{ + register int fd; + struct stat buf; + char *str; + register char *p; + + if ((fd = openlocale("LC_MONETARY", LC_MONETARY, locale, newlocale)) < 0) + return (NULL); + if (fd == 0) + return ""; + if ((fstat(fd, &buf)) != 0) + return (NULL); + if ((str = (char*)malloc((unsigned)buf.st_size + 2)) == NULL) + return (NULL); + + if ((read(fd, str, (int)buf.st_size)) != buf.st_size) { + free((malloc_t)str); + return (NULL); + } + + /* Set last character of str to '\0' */ + p = &str[buf.st_size]; + *p++ = '\n'; + *p = '\0'; + + /* p will "walk thru" str */ + p = str; + + p = getstr(p, &lconvp->int_curr_symbol); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->currency_symbol); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->mon_decimal_point); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->mon_thousands_sep); + if (p == NULL) + goto fail; + p = getgrouping(p, &lconvp->mon_grouping); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->positive_sign); + if (p == NULL) + goto fail; + p = getstr(p, &lconvp->negative_sign); + if (p == NULL) + goto fail; + p = getnum(p, &lconvp->frac_digits); + if (p == NULL) + goto fail; + p = getbool(p, &lconvp->p_cs_precedes); + if (p == NULL) + goto fail; + p = getbool(p, &lconvp->p_sep_by_space); + if (p == NULL) + goto fail; + p = getbool(p, &lconvp->n_cs_precedes); + if (p == NULL) + goto fail; + p = getbool(p, &lconvp->n_sep_by_space); + if (p == NULL) + goto fail; + p = getnum(p, &lconvp->p_sign_posn); + if (p == NULL) + goto fail; + p = getnum(p, &lconvp->n_sign_posn); + if (p == NULL) + goto fail; + (void) close(fd); + + return (str); + +fail: + (void) close(fd); + free((malloc_t)str); + return NULL; +} + +static char * +getstr(p, strp) + register char *p; + char **strp; +{ + *strp = p; + p = strchr(p, '\n'); + if (p == NULL) + return (NULL); /* no end-of-line */ + *p++ = '\0'; + return (p); +} + +static char * +getgrouping(p, groupingp) + register char *p; + char **groupingp; +{ + register int c; + + if (*p == '\0') + return (NULL); /* no grouping */ + *groupingp = p; + while ((c = *p) != '\n') { + if (c == '\0') + return (NULL); /* no end-of-line */ + if (c >= '0' && c <= '9') + *p++ = c - '0'; + else + *p++ = '\177'; + } + *p++ = '\0'; + return (p); +} + +static char * +getnum(p, nump) + register char *p; + char *nump; +{ + register int num; + register int c; + + if (*p == '\0') + return (NULL); /* no number */ + if (*p == '\n') + *nump = '\177'; /* blank line - no value */ + else { + num = 0; + while ((c = *p) != '\n') { + if (c < '0' || c > '9') + return (NULL); /* bad number */ + num = num*10 + c - '0'; + p++; + } + *nump = num; + } + *p++ = '\0'; + return (p); +} + +static char * +getbool(p, boolp) + register char *p; + char *boolp; +{ + + if (*p == '\0') + return (NULL); /* no number */ + if (*p == '\n') + *boolp = '\177'; /* blank line - no value */ + else { + switch (*p++) { + + case 'y': + case 'Y': + case 't': + case 'T': + *boolp = 1; /* true */ + break; + + case 'n': + case 'N': + case 'f': + case 'F': + *boolp = 0; /* false */ + break; + + default: + return (NULL); /* bad boolean */ + } + if (*p != '\n') + return (NULL); /* noise at end of line */ + } + *p++ = '\0'; + return (p); +} + +/* + * Open a locale file. First, check the value of "locale"; if it's a null + * string, first check the environment variable with the same name as the + * category, and then check the environment variable "LANG". If neither of + * them are set to non-null strings, use the LC_default env.var and if this + * has no meaning then assume we are running in the C locale. It is expected + * That LC_default is set across the whole system. If the resulting locale is + * longer than MAXLOCALENAME characters, reject it. Then, try looking in the + * per-machine locale directory for the file in question; if it's not found + * there, try looking in the shared locale directory. + * If there is no work to do, that is, the last setting of locales is equal + * to the current request, then we don't do anything, and exit with value 0. + * Copy the name of the locale used into "newlocale". + * Exit with positive value if we opened a file + * Exit with -1 if an error occured (invalid locale). + * Exit with 0 if there is no need to look at the disk file. + * (Assumption - there is always at least one fd open before setlocale + * is called) + */ +int +openlocale(category, cat_id, locale, newlocale) + char *category; + register int cat_id; + register char *locale; + char *newlocale; +{ + char pathname[MAXPATHLEN], *defp; + int fd, fd2; + struct _code_header code_header; + char *my_info; + + if (*locale == '\0') { + locale = getenv(category); + if (locale == NULL || *locale == '\0') { + locale = getenv("LANG"); + if (locale == NULL || *locale == '\0') { + if (*Default == '\0') { + defp = getenv("LC_default"); + if (defp == NULL || *defp == '\0') + strcpy(Default,"C"); + else + strcpy(Default, defp); + } + locale = Default; + } + } + } + if (strcmp(locale,_locales[cat_id-1]) == 0) { + (void) strcpy(newlocale, locale); + return 0; + } + if (strlen(locale) > MAXLOCALENAME) + return -1; + + (void) strcpy(pathname, PRIVATE_LOCALE_DIR); + (void) strcat(pathname, category); + (void) strcat(pathname, "/"); + (void) strcat(pathname, locale); + if ((fd = open(pathname, O_RDONLY)) < 0 && errno == ENOENT) { + (void) strcpy(pathname, LOCALE_DIR); + (void) strcat(pathname, category); + (void) strcat(pathname, "/"); + (void) strcat(pathname, locale); + fd = open(pathname, O_RDONLY); + } + if (fd >= 0) + (void) strcpy(newlocale, locale); + /* + * bug id 1072740; if by some chance the actual fd we're going to + * return is 0, change it to be some non-zero descriptor, because + * returning 0 means something different. If '0' is the only + * descriptor left, return an error. + */ + if (fd == 0) { + int dupfd; + + if ((dupfd = dup(fd)) < 1) { + (void) close(fd); + fd = -1; + } else { + (void) close(fd); + fd = dupfd; + } + } + + if (cat_id == LC_CTYPE) { + + /* Go and get the trailer file */ + + (void) strcat(pathname, TRAILER); + fd2 = open(pathname, O_RDONLY); + if ( fd2 == 0 ) { + fd2 = dup(fd2); + close(0); + } + + if (fd2 == -1) { + set_default(); + return fd; + } + + /* + * ctype trailer file exists - read it + */ + + if (read (fd2, (char *)&code_header, sizeof (code_header)) != + sizeof (code_header)) { + /* + * File format not correct + */ + set_default(); + close(fd2); + return -1; + } + /* + * set up trailer file + */ + strcpy(_code_set_info.code_name, code_header.code_name); + _code_set_info.code_id = code_header.code_id; + if (_code_set_info.code_info != NULL) + free (_code_set_info.code_info); + if (code_header.code_info_size > 0) { + my_info = malloc(code_header.code_info_size); + if (read (fd2, (char *)my_info, + code_header.code_info_size) != + code_header.code_info_size) { + close(fd2); + set_default(); + return -1; + } + _code_set_info.code_info = my_info; + } + else { + /* + * We have a corrupted file too + */ + _code_set_info.code_info = NULL; + close(fd2); + set_default(); + return -1; + } + close (fd2); + } + return fd; +} + +struct lconv * +localeconv() +{ + return (lconv); +} + +struct dtconv * +localdtconv() +{ + register char *p; + register short i; + + char *rawmonths = "Jan\nFeb\nMar\nApr\nMay\nJun\nJul\nAug\nSep\nOct\nNov\nDec\nJanuary\nFebruary\nMarch\nApril\nMay\nJune\nJuly\nAugust\nSeptember\nOctober\nNovember\nDecember"; + + char *rawdays = "Sun\nMon\nTue\nWed\nThu\nFri\nSat\nSunday\nMonday\nTuesday\nWednesday\nThursday\nFriday\nSaturday"; + +char *rawfmts = "%H:%M:%S\n%m/%d/%y\n%a %b %e %T %Z %Y\nAM\nPM\n%A, %B %e, %Y\n"; + + /* fix for bugid 1067574 ... robinson */ + (void)getlocale_time(); + + if (_dtconv == NULL) { + + /* We malloc both the space for the dtconv struct and the + * copy of the strings above because this program is later run + * through xstr and the resultant strings are put in read-only + * text segment. Therefore we cannot write to the original + * raw strings but we can to their copies. + */ + + _dtconv = (struct dtconv*)malloc(sizeof (struct dtconv)); + if (_dtconv == NULL) + return (NULL); + if ((realmonths = malloc(strlen(rawmonths)+1)) == NULL) + return (NULL); + strcpy(realmonths, rawmonths); + if ((realdays = malloc(strlen(rawdays)+1)) == NULL) + return (NULL); + strcpy(realdays, rawdays); + if ((realfmts = malloc(strlen(rawfmts)+1)) == NULL) + return (NULL); + strcpy(realfmts, rawfmts); + + /* p will "walk thru" str */ + + p = realmonths; + + for (i = 0; i < 12; i++) + p = getstr(p, &(_dtconv->abbrev_month_names[i])); + + for (i = 0; i < 12; i++) + p = getstr(p, &(_dtconv->month_names[i])); + p = realdays; + for (i= 0; i < 7; i++) + p = getstr(p, &(_dtconv->abbrev_weekday_names[i])); + for (i = 0; i < 7; i++) + p = getstr(p, &(_dtconv->weekday_names[i])); + p = realfmts; + p = getstr(p, &_dtconv->time_format); + p = getstr(p, &_dtconv->sdate_format); + p = getstr(p, &_dtconv->dtime_format); + p = getstr(p, &_dtconv->am_string); + p = getstr(p, &_dtconv->pm_string); + p = getstr(p, &_dtconv->ldate_format); + } + + return (_dtconv); +} + + +static int +set_default() +{ + + strcpy(_code_set_info.code_name, Default); + _code_set_info.code_id = CODESET_NONE; + if (_code_set_info.code_info != NULL) + free (_code_set_info.code_info); + _code_set_info.code_info = NULL; + _code_set_info.open_flag = 0; +} + +void init_statics() { + + short i; + + for (i=0; i<MAXLOCALE-1;i++) + strcpy(_locales[i],"C"); + strcpy(_code_set_info.code_name, "default"); + strcpy(_my_time,"C"); + _langinfo.yesstr = "yes"; + _langinfo.nostr = "no"; +} diff --git a/usr/src/lib/libbc/libc/gen/common/setrgid.c b/usr/src/lib/libbc/libc/gen/common/setrgid.c new file mode 100644 index 0000000000..b28ae628a8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/setrgid.c @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/06/30 */ + +setrgid(rgid) + int rgid; +{ + + return (setregid(rgid, -1)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/setruid.c b/usr/src/lib/libbc/libc/gen/common/setruid.c new file mode 100644 index 0000000000..19ccd20f76 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/setruid.c @@ -0,0 +1,30 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/06/30 */ + +setruid(ruid) + int ruid; +{ + + return (setreuid(ruid, -1)); +} diff --git a/usr/src/lib/libbc/libc/gen/common/sigfpe.c b/usr/src/lib/libbc/libc/gen/common/sigfpe.c new file mode 100644 index 0000000000..24b24eb95f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sigfpe.c @@ -0,0 +1,203 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +/* Swap handler for SIGFPE codes. */ + +#include <errno.h> +#include <signal.h> +#include <floatingpoint.h> + +#ifndef FPE_INTDIV_TRAP +#define FPE_INTDIV_TRAP 0x14 /* integer divide by zero */ +#endif +#ifndef FPE_CHKINST_TRAP +#define FPE_CHKINST_TRAP 0x18 /* CHK [CHK2] instruction */ +#endif +#ifndef FPE_TRAPV_TRAP +#define FPE_TRAPV_TRAP 0x1c /* TRAPV [cpTRAPcc TRAPcc] instr */ +#endif +#ifndef FPE_FLTBSUN_TRAP +#define FPE_FLTBSUN_TRAP 0xc0 /* [branch or set on unordered cond] */ +#endif +#ifndef FPE_FLTINEX_TRAP +#define FPE_FLTINEX_TRAP 0xc4 /* [floating inexact result] */ +#endif +#ifndef FPE_FLTDIV_TRAP +#define FPE_FLTDIV_TRAP 0xc8 /* [floating divide by zero] */ +#endif +#ifndef FPE_FLTUND_TRAP +#define FPE_FLTUND_TRAP 0xcc /* [floating underflow] */ +#endif +#ifndef FPE_FLTOPERR_TRAP +#define FPE_FLTOPERR_TRAP 0xd0 /* [floating operand error] */ +#endif +#ifndef FPE_FLTOVF_TRAP +#define FPE_FLTOVF_TRAP 0xd4 /* [floating overflow] */ +#endif +#ifndef FPE_FLTNAN_TRAP +#define FPE_FLTNAN_TRAP 0xd8 /* [floating Not-A-Number] */ +#endif +#ifndef FPE_FPA_ENABLE +#define FPE_FPA_ENABLE 0x400 /* [FPA not enabled] */ +#endif +#ifndef FPE_FPA_ERROR +#define FPE_FPA_ERROR 0x404 /* [FPA arithmetic exception] */ +#endif + +#define N_SIGFPE_CODE 13 + +/* Array of SIGFPE codes. */ + +static sigfpe_code_type sigfpe_codes[N_SIGFPE_CODE] = { + FPE_INTDIV_TRAP, + FPE_CHKINST_TRAP, + FPE_TRAPV_TRAP, + FPE_FLTBSUN_TRAP, + FPE_FLTINEX_TRAP, + FPE_FLTDIV_TRAP, + FPE_FLTUND_TRAP, + FPE_FLTOPERR_TRAP, + FPE_FLTOVF_TRAP, + FPE_FLTNAN_TRAP, + FPE_FPA_ENABLE, + FPE_FPA_ERROR, + 0}; + +/* Array of handlers. */ + +static sigfpe_handler_type sigfpe_handlers[N_SIGFPE_CODE]; + +static int _sigfpe_master_enabled; +/* Originally zero, set to 1 by _enable_sigfpe_master. */ + +void +_sigfpe_master(sig, code, scp, addr) + int sig; + sigfpe_code_type code; + struct sigcontext *scp; + char *addr; +{ + int i; + enum fp_exception_type exception; + + for (i = 0; (i < N_SIGFPE_CODE) && (code != sigfpe_codes[i]); i++); + /* Find index of handler. */ + if (i >= N_SIGFPE_CODE) + i = N_SIGFPE_CODE - 1; + switch ((unsigned int)sigfpe_handlers[i]) { + case (unsigned int)SIGFPE_DEFAULT: + switch (code) { + case FPE_FLTBSUN_TRAP: + case FPE_FLTOPERR_TRAP: + case FPE_FLTNAN_TRAP: + exception = fp_invalid; + goto ieee; + case FPE_FLTINEX_TRAP: + exception = fp_inexact; + goto ieee; + case FPE_FLTDIV_TRAP: + exception = fp_division; + goto ieee; + case FPE_FLTUND_TRAP: + exception = fp_underflow; + goto ieee; + case FPE_FLTOVF_TRAP: + exception = fp_overflow; + goto ieee; + default: /* The common default treatment is to abort. */ + break; + } + case (unsigned int)SIGFPE_ABORT: + abort(); + case (unsigned int)SIGFPE_IGNORE: + return; + default: /* User-defined not SIGFPE_DEFAULT or + * SIGFPE_ABORT. */ + (sigfpe_handlers[i]) (sig, code, scp, addr); + return; + } +ieee: + switch ((unsigned int)ieee_handlers[(int) exception]) { + case (unsigned int)SIGFPE_DEFAULT: + /* Error condition but ignore it. */ + case (unsigned int)SIGFPE_IGNORE: + /* Error condition but ignore it. */ + return; + case (unsigned int)SIGFPE_ABORT: + abort(); + default: + (ieee_handlers[(int) exception]) (sig, code, scp, addr); + return; + } +} + +int +_enable_sigfpe_master() +{ + /* Enable the sigfpe master handler always. */ + struct sigvec newsigvec, oldsigvec; + + newsigvec.sv_handler = _sigfpe_master; + newsigvec.sv_mask = 0; + newsigvec.sv_onstack = 0; + _sigfpe_master_enabled = 1; + return sigvec(SIGFPE, &newsigvec, &oldsigvec); +} + +int +_test_sigfpe_master() +{ + /* + * Enable the sigfpe master handler if it's never been enabled + * before. + */ + + if (_sigfpe_master_enabled == 0) + return _enable_sigfpe_master(); + else + return _sigfpe_master_enabled; +} + +sigfpe_handler_type +sigfpe(code, hdl) + sigfpe_code_type code; + sigfpe_handler_type hdl; +{ + sigfpe_handler_type oldhdl; + int i; + + _test_sigfpe_master(); + for (i = 0; (i < N_SIGFPE_CODE) && (code != sigfpe_codes[i]); i++); + /* Find index of handler. */ + if (i >= N_SIGFPE_CODE) { + errno = EINVAL; + return (sigfpe_handler_type) BADSIG;/* Not 0 or SIGFPE code */ + } + oldhdl = sigfpe_handlers[i]; + sigfpe_handlers[i] = hdl; + return oldhdl; +} diff --git a/usr/src/lib/libbc/libc/gen/common/siglist.c b/usr/src/lib/libbc/libc/gen/common/siglist.c new file mode 100644 index 0000000000..3467ab140e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/siglist.c @@ -0,0 +1,48 @@ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/30/05 */ + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ +#include <signal.h> + +char *sys_siglist[NSIG] = { + "Signal 0", + "Hangup", /* SIGHUP */ + "Interrupt", /* SIGINT */ + "Quit", /* SIGQUIT */ + "Illegal instruction", /* SIGILL */ + "Trace/BPT trap", /* SIGTRAP */ + "Abort", /* SIGABRT */ + "Emulator trap", /* SIGEMT */ + "Arithmetic exception", /* SIGFPE */ + "Killed", /* SIGKILL */ + "Bus error", /* SIGBUS */ + "Segmentation fault", /* SIGSEGV */ + "Bad system call", /* SIGSYS */ + "Broken pipe", /* SIGPIPE */ + "Alarm clock", /* SIGALRM */ + "Terminated", /* SIGTERM */ + "Urgent I/O condition", /* SIGURG */ + "Stopped (signal)", /* SIGSTOP */ + "Stopped", /* SIGTSTP */ + "Continued", /* SIGCONT */ + "Child exited", /* SIGCHLD */ + "Stopped (tty input)", /* SIGTTIN */ + "Stopped (tty output)", /* SIGTTOU */ + "I/O possible", /* SIGIO */ + "Cputime limit exceeded", /* SIGXCPU */ + "Filesize limit exceeded", /* SIGXFSZ */ + "Virtual timer expired", /* SIGVTALRM */ + "Profiling timer expired", /* SIGPROF */ + "Window changed", /* SIGWINCH */ + "Resource lost", /* SIGLOST */ + "User defined signal 1", /* SIGUSR1 */ + "User defined signal 2" /* SIGUSR2 */ +}; diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/alloca.s b/usr/src/lib/libbc/libc/gen/common/sparc/alloca.s new file mode 100644 index 0000000000..bec6bc5ba0 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/alloca.s @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * .seg "data" + * .asciz ident "%Z%%M% %I% %E% SMI" + */ +! .seg "text" + + .file "alloca.s" + +#include <sun4/asm_linkage.h> + + ! + ! o0: # bytes of space to allocate, already rounded to 0 mod 8 + ! o1: %sp-relative offset of tmp area + ! o2: %sp-relative offset of end of tmp area + ! + ! we want to bump %sp by the requested size + ! then copy the tmp area to its new home + ! this is necessasy as we could theoretically + ! be in the middle of a compilicated expression. + ! + ENTRY(__builtin_alloca) + mov %sp, %o3 ! save current sp + sub %sp, %o0, %sp ! bump to new value + ! copy loop: should do nothing gracefully + b 2f + subcc %o2, %o1, %o5 ! number of bytes to move +1: + ld [%o3 + %o1], %o4 ! load from old temp area + st %o4, [%sp + %o1] ! store to new temp area + add %o1, 4, %o1 +2: bg 1b + subcc %o5, 4, %o5 + ! now return new %sp + end-of-temp + retl + add %sp, %o2, %o0 + SET_SIZE(__builtin_alloca) diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/base_conv.c b/usr/src/lib/libbc/libc/gen/common/sparc/base_conv.c new file mode 100644 index 0000000000..405b0ab99a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/base_conv.c @@ -0,0 +1,129 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +/* + * Machine-independent versions of base conversion primitives. + * Routines to multiply buffers by 2**16 or 10**4. Base 10**4 buffers have + * b[i] < 10000, carry in and out < 65536. Base 2**16 buffers have b[i] < + * 65536, carry in and out < 10000. If n is positive, b[0]..b[n-1] are + * processed; if n is negative, b[0]..b[n+1] are processed. + */ + +void +_fourdigits(t, d) + unsigned t; + char d[4]; + +/* Converts t < 10000 into four ascii digits at *pc. */ + +{ + register short i; + + i = 3; + do { + d[i] = '0' + t % 10; + t = t / 10; + } + while (--i != -1); +} + +unsigned +_quorem10000(u, pr) + unsigned u; + unsigned *pr; +{ + *pr = u % 10000; + return (u / 10000); +} + +void +_mul_10000(b, n, c) + unsigned *b; + int n; + unsigned *c; +{ + /* Multiply base-2**16 buffer by 10000. */ + + register unsigned carry, t; + register short int i; + register unsigned *pb; + + carry = *c; + pb = b; + if ((i = n) > 0) { + i--; + do { + *pb = (t = (*pb * 10000) + carry) & 0xffff; + pb++; + carry = t >> 16; + } + while (--i != -1); + } else { + i = -i - 1; + do { + *pb = (t = (*pb * 10000) + carry) & 0xffff; + pb--; + carry = t >> 16; + } + while (--i != -1); + } + *c = carry; +} + +void +_mul_65536(b, n, c) + unsigned *b; + int n; + unsigned *c; +{ + /* Multiply base-10**4 buffer by 65536. */ + + register unsigned carry, t; + register short int i; + register unsigned *pb; + + carry = *c; + pb = b; + if ((i = n) > 0) { + i--; + do { + *pb = (t = (*pb << 16) | carry) % 10000; + pb++; + carry = t / 10000; + } + while (--i != -1); + } else { + i = -i - 1; + do { + *pb = (t = (*pb << 16) | carry) % 10000; + pb--; + carry = t / 10000; + } + while (--i != -1); + } + *c = carry; +} diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/ffs.s b/usr/src/lib/libbc/libc/gen/common/sparc/ffs.s new file mode 100644 index 0000000000..5534fcc7ca --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/ffs.s @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +! .seg "data" +! .asciz ident "%Z%%M% %I% %E% SMI" + .seg ".text" + + .file "ffs.s" + +#include <sun4/asm_linkage.h> + + ENTRY(ffs) + tst %o0 ! if zero, done + bz 2f + clr %o1 ! delay slot, return zero if no bit set +1: + inc %o1 ! bit that will get checked + btst 1, %o0 + be 1b ! if bit is zero, keep checking + srl %o0, 1, %o0 ! shift input right until we hit a 1 bit +2: + retl + mov %o1, %o0 ! return value is in o1 + SET_SIZE(ffs) diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/insque.s b/usr/src/lib/libbc/libc/gen/common/sparc/insque.s new file mode 100644 index 0000000000..eef886a1c7 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/insque.s @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +! .seg "data" +! .asciz ident "%Z%%M% %I% %E% SMI" + .seg ".text" + + .file "insque.s" + +#include <sun4/asm_linkage.h> + +/* + * insque(entryp, predp) + * + * Insert entryp after predp in a doubly linked list. + */ + ENTRY(insque) + ld [%o1], %g1 ! predp->forw + st %o1, [%o0 + 4] ! entryp->back = predp + st %g1, [%o0] ! entryp->forw = predp->forw + st %o0, [%o1] ! predp->forw = entryp + retl + st %o0, [%g1 + 4] ! predp->forw->back = entryp + SET_SIZE(insque) diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/isinf.c b/usr/src/lib/libbc/libc/gen/common/sparc/isinf.c new file mode 100644 index 0000000000..2bd47b88e5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/isinf.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Recognize an infinity or a NaN when one is presented. + * This is for keeping various IO routines out of trouble + */ + + +int +isinf( d0, d1 ) + unsigned d0,d1; + /* a lie -- actually its a ``double'' */ +{ + if (d1 != 0 ) return 0; /* nope -- low-order must be all zeros */ + if (d0 != 0x7ff00000 && d0 != 0xfff00000) return 0; /* nope */ + return 1; +} + +int +isnan( d0,d1 ) + unsigned d0,d1; + /* a lie -- actually its a ``double'' */ +{ +#define EXPONENT 0x7ff00000 +#define SIGN 0x80000000 + if ((d0 & EXPONENT) != EXPONENT ) return 0; /* exponent wrong */ + if ((d0 & ~(EXPONENT|SIGN)) == 0 && d1 == 0 ) return 0; /* must have bits */ + return 1; +} diff --git a/usr/src/lib/libbc/libc/gen/common/sparc/remque.s b/usr/src/lib/libbc/libc/gen/common/sparc/remque.s new file mode 100644 index 0000000000..358b2eb08c --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/sparc/remque.s @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +! .seg "data" +! .asciz ident "%Z%%M% %I% %E% SMI" +! .seg "text" + + .file "remque.s" + +#include <sun4/asm_linkage.h> + +/* + * remque(entryp) + * + * Remove entryp from a doubly linked list + */ + ENTRY(remque) + ld [%o0], %g1 ! entryp->forw + ld [%o0 + 4], %g2 ! entryp->back + st %g1, [%g2] ! entryp->back = entryp->forw + retl + st %g2, [%g1 + 4] ! entryp->forw = entryp->back + SET_SIZE(remque) diff --git a/usr/src/lib/libbc/libc/gen/common/ssignal.c b/usr/src/lib/libbc/libc/gen/common/ssignal.c new file mode 100644 index 0000000000..8becd84fd5 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ssignal.c @@ -0,0 +1,93 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * ssignal, gsignal: software signals + */ +#include <signal.h> + +/* Highest allowable user signal number */ +#define MAXSIG NSIG + +/* Lowest allowable signal number (lowest user number is always 1) */ +#define MINSIG (-4) + +/* Table of signal values */ +typedef int (*sigfunc)(); +sigfunc *ssigp; + + +sigfunc * +_ssig() +{ + if (ssigp == 0) + ssigp = (sigfunc *)calloc(MAXSIG-MINSIG+1, sizeof (sigfunc)); + return (ssigp); +} + +int +(*ssignal(sig, fn))() +register int sig, (*fn)(); +{ + register int (*savefn)(); + register sigfunc *sp = _ssig(); + + if (sp == 0) + return ((int (*)())SIG_DFL); + if (sig >= MINSIG && sig <= MAXSIG) { + savefn = sp[sig-MINSIG]; + sp[sig-MINSIG] = fn; + } else + savefn = (int (*)())SIG_DFL; + + return (savefn); +} + +int +gsignal(sig) +register int sig; +{ + register int (*sigfn)(); + register sigfunc *sp = _ssig(); + + if (sp == 0) + return (0); + if (sig < MINSIG || sig > MAXSIG || + (sigfn = sp[sig-MINSIG]) == (int (*)())SIG_DFL) + return (0); + else if (sigfn == (int (*)())SIG_IGN) + return (1); + else { + sp[sig-MINSIG] = (int (*)())SIG_DFL; + return ((*sigfn)(sig)); + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/strchr.c b/usr/src/lib/libbc/libc/gen/common/strchr.c new file mode 100644 index 0000000000..e978579ae1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strchr.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Return the ptr in sp at which the character c appears; + * NULL if not found + */ + +#define NULL 0 + +char * +strchr(sp, c) +register char *sp, c; +{ + do { + if(*sp == c) + return(sp); + } while(*sp++); + return(NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strftime.c b/usr/src/lib/libbc/libc/gen/common/strftime.c new file mode 100644 index 0000000000..5267bc447a --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strftime.c @@ -0,0 +1,531 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1996 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; /* from S5R3.1 cftime.c 1.9 */ +#endif + +/*LINTLIBRARY*/ + +#include <locale.h> +#include <time.h> +#include <string.h> +#include <sys/param.h> +#include <sys/stat.h> + +static char *getstr(/*char *p, char **strp*/); +static char *itoa(); +extern int stat(); +extern char *getenv(); +extern char *malloc(); +extern int openlocale(/*char *category, int cat_id, char *locale, char *newlocale */); +extern void init_statics(); + +extern struct dtconv *_dtconv; +extern char _locales[MAXLOCALE + 1][MAXLOCALENAME + 1]; +extern char _my_time[]; + +char *dtconv_str = NULL; +char *getlocale_time(); + +int +strftime(buf, maxsize, format, tm) +char *buf, *format; +struct tm *tm; +{ + register char *cp, *p, c; + int size; + int i, temp; + register struct dtconv *dtcp; + + (void) getlocale_time(); + dtcp = localdtconv(); /* get locale's strings */ + + /* Build date string by parsing format string */ + cp = buf; + size = 0; + while ((c = *format++) != '\0') { + if (c == '%') { + switch (*format++) { + + case '%': /* Percent sign */ + if (++size >= maxsize) + return (0); + *cp++ = '%'; + break; + + case 'a': /* Abbreviated weekday name */ + for (p = dtcp->abbrev_weekday_names[tm->tm_wday]; + *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + case 'A': /* Weekday name */ + for (p = dtcp->weekday_names[tm->tm_wday]; + *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + case 'h': + case 'b': /* Abbreviated month name */ + for (p = dtcp->abbrev_month_names[tm->tm_mon]; + *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + case 'B': /* Month name */ + for (p = dtcp->month_names[tm->tm_mon]; + *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + case 'c': /* date and time representation */ + i = strftime(cp, maxsize - size, "%x %X", tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'C': /* long date and time representation */ + i = strftime(cp, maxsize - size, + dtcp->ldate_format, tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'd': /* Day of month, with leading zero */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_mday, cp, 2); + break; + + case 'D': /* Shorthand for %m/%d/%y */ + i = strftime(cp, maxsize - size, "%m/%d/%y", + tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'e': /* Day of month without leading zero */ + if ((size += 2) >= maxsize) + return (0); + if (tm->tm_mday < 10) { + *cp++ = ' '; + cp = itoa(tm->tm_mday, cp, 1); + } else + cp = itoa(tm->tm_mday, cp, 2); + break; + + case 'H': /* Hour (24 hour version) */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_hour, cp, 2); + break; + + case 'I': /* Hour (12 hour version) */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_hour > 12 ? + tm->tm_hour - 12 : + (tm->tm_hour == 0 ? 12 : tm->tm_hour), + cp, 2); + break; + + case 'j': /* Julian date */ + if ((size += 3) >= maxsize) + return (0); + cp = itoa(tm->tm_yday + 1, cp, 3); + break; + + case 'k': /* Hour (24 hour version) */ + if ((size += 2) >= maxsize) + return (0); + if (tm->tm_hour < 10) { + *cp++ = ' '; + cp = itoa(tm->tm_hour, cp, 1); + } else + cp = itoa(tm->tm_hour, cp, 2); + break; + + case 'l': /* Hour (12 hour version) */ + if ((size += 2) >= maxsize) + return (0); + temp = tm->tm_hour > 12 ? + tm->tm_hour - 12 : + (tm->tm_hour == 0 ? 12 : tm->tm_hour); + if (temp < 10) { + *cp++ = ' '; + cp = itoa(temp, cp, 1); + } else + cp = itoa(temp, cp, 2); + break; + + case 'm': /* Month number */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_mon + 1, cp, 2); + break; + + case 'M': /* Minute */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_min, cp, 2); + break; + + case 'n': /* Newline */ + if (++size >= maxsize) + return (0); + *cp++ = '\n'; + break; + + case 'p': /* AM or PM */ + if (tm->tm_hour >= 12) + p = dtcp->pm_string; + else + p = dtcp->am_string; + for (; *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + case 'r': /* Shorthand for %I:%M:%S AM or PM */ + i = strftime(cp, maxsize - size, "%I:%M:%S %p", + tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'R': /* Time as %H:%M */ + i = strftime(cp, maxsize - size, "%H:%M", tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'S': /* Seconds */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa(tm->tm_sec, cp, 2); + break; + + case 't': /* Tab */ + if (++size >= maxsize) + return (0); + *cp++ = '\t'; + break; + + case 'T': /* Shorthand for %H:%M:%S */ + i = strftime(cp, maxsize - size, "%H:%M:%S", + tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'U': /* Weekday number, taking Sunday as + * the first day of the week */ + if ((size += 2) >= maxsize) + return (0); + temp = tm->tm_yday - tm->tm_wday; + if (temp >= -3 ) { + i = (temp + 1) / 7 + 1; /* +1 for - tm->tm_wday */ + if (temp % 7 >= 4) + i++; + } else + i = 52; + cp = itoa(i, cp, 2); + break; + + case 'w': /* Weekday number */ + if (++size >= maxsize) + return (0); + cp = itoa(tm->tm_wday, cp, 1); + break; + + case 'W': /* Week number of year, taking Monday as + * first day of week */ + if ((size += 2) >= maxsize) + return (0); + if (tm->tm_wday == 0) + temp = tm->tm_yday - 6; + else + temp = tm->tm_yday - tm->tm_wday + 1; + if (temp >= -3) { + i = (temp + 1) / 7 + 1; /* 1 for + -tm->tm_wday */ + if (temp % 7 >= 4) + i++; + } else + i = 52; /* less than 4 days in the first + week causes it to belong to + the tail of prev year */ + cp = itoa(i, cp, 2); + break; + + case 'x': /* Localized date format */ + i = strftime(cp, maxsize - size, + dtcp->sdate_format, tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'X': /* Localized time format */ + i = strftime(cp, maxsize - size, + dtcp->time_format, tm); + if (i == 0) + return (0); + cp += i; + size += i; + break; + + case 'y': /* Year in the form yy */ + if ((size += 2) >= maxsize) + return (0); + cp = itoa((tm->tm_year% 100), cp, 2); + break; + + case 'Y': /* Year in the form ccyy */ + if ((size += 4) >= maxsize) + return (0); + cp = itoa(1900 + tm->tm_year, cp, 4); + break; + + case 'Z': /* Timezone */ + for(p = tm->tm_zone; *p != '\0'; p++) { + if (++size >= maxsize) + return (0); + *cp++ = *p; + } + break; + + default: + if ((size += 2) >= maxsize) + return (0); + *cp++ = c; + *cp++ = *(format - 1); + break; + } + } else { + if (++size >= maxsize) + return (0); + *cp++ = c; + } + } + *cp = '\0'; + return(size); +} + +static char * +itoa(i, ptr, dig) +register int i; +register char *ptr; +register int dig; +{ + switch(dig) { + case 4: + *ptr++ = i / 1000 + '0'; + i = i - i / 1000 * 1000; + case 3: + *ptr++ = i / 100 + '0'; + i = i - i / 100 * 100; + case 2: + *ptr++ = i / 10 + '0'; + case 1: + *ptr++ = i % 10 + '0'; + } + + return(ptr); +} + +char * +getlocale_time() +{ + register int fd; + struct stat buf; + char *str; + register char *p; + register int i; + struct dtconv dtconvp; + char temp[MAXLOCALENAME + 1]; + + if (_locales[0][0] == '\0') + init_statics(); + + /* Here we use the string newlocales to set time constants + * which should have been saved + * from a previous call to setlocale. We deferred the read until now + */ + + if (strcmp(_my_time, _locales[LC_TIME -1]) == 0) { + if (dtconv_str == NULL) { + /* + * Below is executed if getlocale_time() + * is called when LC_TIME locale is initial + * C locale. + */ + strcpy(temp, "C"); + /* + * Just to make openlocale() to read LC_TIME file. + */ + strcat(_locales[LC_TIME-1], temp); + goto initial; + } + return dtconv_str; + } + strcpy(temp, _locales[LC_TIME - 1]); + strcpy(_locales[LC_TIME - 1], _my_time); +initial: + if ((fd = openlocale("LC_TIME", LC_TIME, temp, _locales[LC_TIME - 1])) < 0) + return (NULL); + strcpy(_my_time, _locales[LC_TIME - 1]); + if (fd == 0) + return dtconv_str; + if ((fstat(fd, &buf)) != 0) + return (NULL); + if ((str = malloc((unsigned)buf.st_size + 2)) == NULL) { + close(fd); + return (NULL); + } + + if ((read(fd, str, (int)buf.st_size)) != buf.st_size) { + close(fd); + free(str); + return (NULL); + } + + /* Set last character of str to '\0' */ + p = &str[buf.st_size]; + *p++ = '\n'; + *p = '\0'; + + /* p will "walk thru" str */ + p = str; + + for (i = 0; i < 12; i++) { + p = getstr(p, &dtconvp.abbrev_month_names[i]); + if (p == NULL) + goto fail; + } + for (i = 0; i < 12; i++) { + p = getstr(p, &dtconvp.month_names[i]); + if (p == NULL) + goto fail; + } + for (i = 0; i < 7; i++) { + p = getstr(p, &dtconvp.abbrev_weekday_names[i]); + if (p == NULL) + goto fail; + } + for (i = 0; i < 7; i++) { + p = getstr(p, &dtconvp.weekday_names[i]); + if (p == NULL) + goto fail; + } + p = getstr(p, &dtconvp.time_format); + if (p == NULL) + goto fail; + p = getstr(p, &dtconvp.sdate_format); + if (p == NULL) + goto fail; + p = getstr(p, &dtconvp.dtime_format); + if (p == NULL) + goto fail; + p = getstr(p, &dtconvp.am_string); + if (p == NULL) + goto fail; + p = getstr(p, &dtconvp.pm_string); + if (p == NULL) + goto fail; + p = getstr(p, &dtconvp.ldate_format); + if (p == NULL) + goto fail; + (void) close(fd); + + /* + * set info. + */ + if (dtconv_str != NULL) + free(dtconv_str); + + dtconv_str = str; + + /* The following is to get space malloc'd for _dtconv */ + + if (_dtconv == 0) + (void) localdtconv(); + memcpy(_dtconv, &dtconvp, sizeof(struct dtconv)); + return (dtconv_str); + +fail: + (void) close(fd); + free(str); + return (NULL); +} + + +static char * +getstr(p, strp) + register char *p; + char **strp; +{ + *strp = p; + p = strchr(p, '\n'); + if (p == NULL) + return (NULL); /* no end-of-line */ + *p++ = '\0'; + return (p); +} diff --git a/usr/src/lib/libbc/libc/gen/common/stricmp.c b/usr/src/lib/libbc/libc/gen/common/stricmp.c new file mode 100644 index 0000000000..0f9fedfa8b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/stricmp.c @@ -0,0 +1,92 @@ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from UCB 1.3 8/3/87 */ + +/* + * Copyright (c) 1987 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +/* + * This array is designed for mapping upper and lower case letter + * together for a case independent comparison. The mappings are + * based upon ascii character sequences. + */ +static char charmap[] = { + '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007', + '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017', + '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027', + '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037', + '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047', + '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057', + '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067', + '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077', + '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137', + '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147', + '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157', + '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167', + '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177', + '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207', + '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217', + '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227', + '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237', + '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247', + '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257', + '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267', + '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277', + '\300', '\341', '\342', '\343', '\344', '\345', '\346', '\347', + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', + '\370', '\371', '\372', '\333', '\334', '\335', '\336', '\337', + '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347', + '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357', + '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367', + '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377', +}; + +strcasecmp(s1, s2) + register char *s1, *s2; +{ + register char *cm = charmap; + + while (cm[*s1] == cm[*s2++]) + if (*s1++ == '\0') + return(0); + return(cm[*s1] - cm[*--s2]); +} + +strncasecmp(s1, s2, n) + register char *s1, *s2; + register int n; +{ + register char *cm = charmap; + + while (--n >= 0 && cm[*s1] == cm[*s2++]) + if (*s1++ == '\0') + return(0); + return(n < 0 ? 0 : cm[*s1] - cm[*--s2]); +} + +/* + * For 4.0 compatibility + */ +stricmp(s1, s2) + register char *s1, *s2; +{ + return(strcasecmp(s1, s2)); +} + +strnicmp(s1, s2, n) + register char *s1, *s2; + register int n; +{ + return(strncasecmp(s1, s2, n)); +} + diff --git a/usr/src/lib/libbc/libc/gen/common/string_decim.c b/usr/src/lib/libbc/libc/gen/common/string_decim.c new file mode 100644 index 0000000000..2dd47e6ab1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/string_decim.c @@ -0,0 +1,64 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +#include <ctype.h> +#include <stdio.h> +#ifndef PRE41 +#include <locale.h> +#endif +#include "base_conversion.h" + +void +string_to_decimal(ppc, nmax, fortran_conventions, pd, pform, pechar) + char **ppc; + int nmax; + int fortran_conventions; + decimal_record *pd; + enum decimal_string_form *pform; + char **pechar; + +{ + register char *cp = *ppc; + register int current; + register int nread = 1; /* Number of characters read so far. */ + char *cp0 = cp; + char *good = cp - 1; /* End of known good token. */ + + current = *cp; + +#define ATEOF 0 /* A string is never at EOF. */ +#define CURRENT current +#define NEXT \ + if (nread < nmax) \ + {cp++ ; current = *cp ; nread++ ;} \ + else \ + {current = NULL ; } ; /* Increment input character and cp. */ + +#include "char_to_decimal.h" +#undef CURRENT +#undef NEXT +} diff --git a/usr/src/lib/libbc/libc/gen/common/strncat.c b/usr/src/lib/libbc/libc/gen/common/strncat.c new file mode 100644 index 0000000000..4166460683 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strncat.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 80/12/21 */ + +/* + * Concatenate s2 on the end of s1. S1's space must be large enough. + * At most n characters are moved. + * Return s1. + */ + +char * +strncat(s1, s2, n) + register char *s1, *s2; + register n; +{ + register char *os1; + + os1 = s1; + while (*s1++) + ; + --s1; + while (*s1++ = *s2++) + if (--n < 0) { + *--s1 = '\0'; + break; + } + return (os1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strpbrk.c b/usr/src/lib/libbc/libc/gen/common/strpbrk.c new file mode 100644 index 0000000000..c876665bd9 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strpbrk.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Return ptr to first occurance of any character from `brkset' + * in the character string `string'; NULL if none exists. + */ + +#define NULL (char *) 0 + +char * +strpbrk(string, brkset) +register char *string, *brkset; +{ + register char *p; + + do { + for(p=brkset; *p != '\0' && *p != *string; ++p) + ; + if(*p != '\0') + return(string); + } + while(*string++); + return(NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strptime.c b/usr/src/lib/libbc/libc/gen/common/strptime.c new file mode 100644 index 0000000000..bfd7aef821 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strptime.c @@ -0,0 +1,483 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1997 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <ctype.h> +#include <locale.h> +#include <time.h> + +static char *strmatch(/*char *cp, char *string*/); +static char *yearmatch(/*char *cp, char *format, struct tm *tm, + int *hadyearp*/); +static char *cvtnum(/*char *cp, int *nump*/); +static char *skipnws(/*char *format*/); + +extern char *getlocale_time(); +#define NULL 0 + +char * +strptime(buf, format, tm) + char *buf; + char *format; + struct tm *tm; +{ + register char *cp, *p; + register int c, ch; + register int i; + register struct dtconv *dtcp; + int hadyear; + + (void) getlocale_time(); + dtcp = localdtconv(); /* get locale's strings */ + + cp = buf; + while ((c = *format++) != '\0') { + if (c == '%') { + switch (*format++) { + + case '%': /* Percent sign */ + if (*cp++ != '%') + return (NULL); + break; + + case 'a': /* Abbreviated weekday name */ + case 'A': /* Weekday name */ + for (i = 0; i < 7; i++) { + if ((p = strmatch(cp, + dtcp->weekday_names[i], + *format)) != NULL + || (p = strmatch(cp, + dtcp->abbrev_weekday_names[i], + *format)) != NULL) + goto match_wday; + } + return (NULL); /* no match */ + + match_wday: + tm->tm_wday = i; + cp = p; + break; + + case 'h': + case 'b': /* Abbreviated month name */ + case 'B': /* Month name */ + for (i = 0; i < 12; i++) { + if ((p = strmatch(cp, + dtcp->month_names[i], + *format)) != NULL + || (p = strmatch(cp, + dtcp->abbrev_month_names[i], + *format)) != NULL) + goto match_month; + } + return (NULL); /* no match */ + + match_month: + tm->tm_mon = i; + cp = p; + break; + + case 'c': /* date and time representation */ + cp = strptime(cp, "%x %X", tm); + if (cp == NULL) + return (NULL); + break; + + case 'C': /* long date and time representation */ + cp = strptime(cp, dtcp->ldate_format, tm); + if (cp == NULL) + return (NULL); + break; + + case 'd': /* Day of month, with leading zero */ + case 'e': /* Day of month without leading zero */ + cp = cvtnum(cp, &tm->tm_mday); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_mday > 31) + return (NULL); + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'D': /* Shorthand for %m/%d/%y */ + cp = strptime(cp, "%m/%d/%y", tm); + if (cp == NULL) + return (NULL); + break; + + case 'H': /* Hour (24 hour version) */ + case 'k': /* Hour (24 hour version) */ + cp = cvtnum(cp, &tm->tm_hour); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_hour > 23) + return (NULL); + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'I': /* Hour (12 hour version) */ + case 'l': /* Hour (12 hour version) */ + cp = cvtnum(cp, &tm->tm_hour); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_hour == 12) + tm->tm_hour = 0; + else if (tm->tm_hour > 11) + return (NULL); + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'j': /* Julian date */ + cp = cvtnum(cp, &tm->tm_yday); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_yday > 365) + return (NULL); + break; + + case 'm': /* Month number */ + cp = cvtnum(cp, &tm->tm_mon); + if (cp == NULL) + return (NULL); /* no digits */ + tm->tm_mon--; + if (tm->tm_mon < 0 || tm->tm_mon > 11) + return (NULL); + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'M': /* Minute */ + /* + * This is optional; if we're at the end of the + * string, or the next character is white + * space, don't try to match it. + */ + if ((c = *cp) != '\0' + && !isspace((unsigned char)c)) { + cp = cvtnum(cp, &tm->tm_min); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_min > 59) + return (NULL); + } + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'p': /* AM or PM */ + if ((p = strmatch(cp, dtcp->am_string, + *format)) != NULL) { + /* + * AM. + */ + if (tm->tm_hour == 12) + tm->tm_hour = 0; + cp = p; + } else if ((p = strmatch(cp, dtcp->pm_string, + *format)) != NULL) { + /* + * PM. + */ + if (tm->tm_hour > 12) + return (NULL); /* error */ + else if (tm->tm_hour != 12) + tm->tm_hour += 12; + cp = p; + } + break; + + case 'r': /* Shorthand for %I:%M:%S AM or PM */ + cp = strptime(cp, "%I:%M:%S %p", tm); + if (cp == NULL) + return (NULL); + break; + + case 'R': /* Time as %H:%M */ + cp = strptime(cp, "%H:%M", tm); + if (cp == NULL) + return (NULL); + break; + + case 'S': /* Seconds */ + /* + * This is optional; if we're at the end of the + * string, or the next character is white + * space, don't try to match it. + */ + if ((c = *cp) != '\0' + && !isspace((unsigned char)c)) { + cp = cvtnum(cp, &tm->tm_sec); + if (cp == NULL) + return (NULL); /* no digits */ + if (tm->tm_sec > 59) + return (NULL); + } + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + break; + + case 'T': /* Shorthand for %H:%M:%S */ + cp = strptime(cp, "%H:%M:%S", tm); + if (cp == NULL) + return (NULL); + break; + + case 'x': /* Localized date format */ + cp = strptime(cp, dtcp->sdate_format, tm); + if (cp == NULL) + return (NULL); + break; + + case 'X': /* Localized time format */ + cp = strptime(cp, dtcp->time_format, tm); + if (cp == NULL) + return (NULL); + break; + + case 'y': /* Year in the form yy */ + cp = yearmatch(cp, format, tm, &hadyear); + if (cp == NULL) + return (NULL); + if (hadyear) { + if (tm->tm_year < 69) + tm->tm_year += 100; + } + return (cp); /* match is complete */ + + case 'Y': /* Year in the form ccyy */ + cp = yearmatch(cp, format, tm, &hadyear); + if (cp == NULL) + return (NULL); + if (hadyear) { + tm->tm_year -= 1900; + if (tm->tm_year < 0) + return (NULL); + } + return (cp); /* match is complete */ + + default: + return (NULL); /* unknown conversion */ + } + } else { + if (isspace((unsigned char)c)) { + while ((ch = *cp++) != '\0' + && isspace((unsigned char)ch)) + ; + cp--; + } else { + if (*cp++ != c) + return (NULL); + } + } + } + return (cp); +} + +/* + * Try to match the beginning of the string pointed to by "cp" with the string + * pointed to by "string". The match is independent of the case of either + * string. + * + * "termc" is the next character in the format string following the one for + * which this match is being done. If the match succeeds, make sure the next + * character after the match is either '\0', or that it would match "termc". + * + * If both matches succeed, return a pointer to the next character after the + * first match. Otherwise, return NULL. + */ +static char * +strmatch(cp, string, termc) + register char *cp; + register char *string; + char termc; +{ + register unsigned char c, strc; + + /* + * Match the beginning portion of "cp" with "string". + */ + while ((strc = *string++) != '\0') { + c = *cp++; + if (isupper(c)) + c = tolower(c); + if (isupper(strc)) + strc = tolower(strc); + if (c != strc) + return (NULL); + } + + if ((c = *cp) != '\0') { + if (isspace((unsigned char)termc)) { + if (!isspace(c)) + return (NULL); + } else { + if (c != (unsigned char)termc) + return (NULL); + } + } + return (cp); +} + +/* + * Try to match a %y or %Y specification. + * If it matches, try matching the rest of the format. If it succeeds, just + * return. Otherwise, try backing the scan up, ignoring the %y/%Y and any + * following non-white-space string. If that succeeds, just return. (This + * permits a missing year to be detected if it's at the beginning of a date, as + * well as if it's at the end of a date, so that formats such as "%Y/%m/%d" can + * match "3/14" and default the year.) + * + * Set "*hadyearp" to indicate whether a year was specified or not. + */ +static char * +yearmatch(cp, format, tm, hadyearp) + register char *cp; + char *format; + struct tm *tm; + int *hadyearp; +{ + register int c; + char *savecp; + int saveyear; + + /* + * This is optional; if we're at the end of the + * string, or the next character is white + * space, don't try to match it. + */ + if ((c = *cp) != '\0' && !isspace((unsigned char)c)) { + savecp = cp; + saveyear = tm->tm_year; + cp = cvtnum(cp, &tm->tm_year); + if (cp == NULL) + return (NULL); /* no digits */ + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + + /* + * Year can also be optional if it's at + * the *beginning* of a date. We check + * this by trying to parse the rest of + * the date here. If we succeed, OK; + * otherwise, we skip over the %y and + * try again. + */ + cp = strptime(cp, format, tm); + if (cp != NULL) + *hadyearp = 1; + else { + *hadyearp = 0; + cp = savecp; + format = skipnws(format); + tm->tm_year = saveyear; + cp = strptime(cp, format, tm); + } + } else { + *hadyearp = 0; + if ((c = *cp) == '\0' + || isspace((unsigned char)c)) + format = skipnws(format); + cp = strptime(cp, format, tm); + } + + return (cp); +} + +/* + * Try to match a (decimal) number in the string pointed to by "cp". + * If the match succeeds, store the result in the "int" pointed to by "nump" + * and return a pointer to the character following the number in the string. + * If it fails, return NULL. + */ +static char * +cvtnum(cp, nump) + register char *cp; + int *nump; +{ + register int c; + register int i; + + c = (unsigned char)*cp++; + if (!isdigit(c)) + return (NULL); /* no digits */ + i = 0; + do { + i = i*10 + c - '0'; + c = (unsigned char)*cp++; + } while (isdigit(c)); + *nump = i; + return (cp - 1); +} + +/* + * If a format item (such as %H, hours) is followed by a non-white-space + * character other than "%", and the part of the string that matched the format + * item is followed by white space, the string of non-white-space, + * non-format-item characters following that format item may be omitted. + */ +static char * +skipnws(format) + register char *format; +{ + register char c; + + /* + * Skip over non-white-space, non-digit characters. "%" is special. + */ + while ((c = *format) != '\0' && !isspace((unsigned char)c)) { + if (c == '%') { + /* + * This is a format item. If it's %%, skip it as + * that's a non-white space, non-digit character. + */ + if (*(format + 1) == '%') + format++; /* skip % */ + else + break; + } + format++; + } + + return (format); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strrchr.c b/usr/src/lib/libbc/libc/gen/common/strrchr.c new file mode 100644 index 0000000000..28c338b895 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strrchr.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Return the ptr in sp at which the character c last + * appears; NULL if not found +*/ + +#define NULL 0 + +char * +strrchr(sp, c) +register char *sp, c; +{ + register char *r; + + r = NULL; + do { + if(*sp == c) + r = sp; + } while(*sp++); + return(r); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strspn.c b/usr/src/lib/libbc/libc/gen/common/strspn.c new file mode 100644 index 0000000000..d68f5ce6af --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strspn.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Return the number of characters in the maximum leading segment + * of string which consists solely of characters from charset. + */ +int +strspn(string, charset) +char *string; +register char *charset; +{ + register char *p, *q; + + for(q=string; *q != '\0'; ++q) { + for(p=charset; *p != '\0' && *p != *q; ++p) + ; + if(*p == '\0') + break; + } + return(q-string); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strstr.c b/usr/src/lib/libbc/libc/gen/common/strstr.c new file mode 100644 index 0000000000..79bc3151fd --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strstr.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Get matching substring + */ +#include <string.h> + +#pragma weak strstr = _strstr + +char * +_strstr(s1, s2) + register char *s1, *s2; +{ + int s2len = strlen(s2); /* length of the second string */ + /* + * If the length of the second string is 0, + * return the first argument. + */ + if (s2len == 0) + return (s1); + + while (strlen(s1) >= s2len) { + if (strncmp(s1, s2, s2len) == 0) + return (s1); + s1++; + } + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strtod.c b/usr/src/lib/libbc/libc/gen/common/strtod.c new file mode 100644 index 0000000000..fa551c76f1 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strtod.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 by Sun Microsystems, Inc. + */ + +#include <errno.h> +#include <stdio.h> +#include <values.h> +#include <floatingpoint.h> + +double +strtod(cp, ptr) + char *cp; + char **ptr; +{ + double x; + decimal_mode mr; + decimal_record dr; + fp_exception_field_type fs; + enum decimal_string_form form; + char *pechar; + + string_to_decimal(&cp, MAXINT, 0, &dr, &form, &pechar); + if (ptr != (char **) NULL) + *ptr = cp; + if (form == invalid_form) + return 0.0; /* Shameful kluge for SVID's sake. */ + mr.rd = fp_direction; + decimal_to_double(&x, &mr, &dr, &fs); + if (fs & (1 << fp_overflow)) { /* Overflow. */ + errno = ERANGE; + } + if (fs & (1 << fp_underflow)) { /* underflow */ + errno = ERANGE; + } + return x; +} diff --git a/usr/src/lib/libbc/libc/gen/common/strtok.c b/usr/src/lib/libbc/libc/gen/common/strtok.c new file mode 100644 index 0000000000..07fdbc7e94 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strtok.c @@ -0,0 +1,65 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * uses strpbrk and strspn to break string into tokens on + * sequentially subsequent calls. returns NULL when no + * non-separator characters remain. + * `subsequent' calls are calls with first argument NULL. + */ + +#define NULL (char*)0 + +extern int strspn(); +extern char *strpbrk(); + +char * +strtok(string, sepset) +char *string, *sepset; +{ + register char *p, *q, *r; + static char *savept; + + /*first or subsequent call*/ + p = (string == NULL)? savept: string; + + if(p == 0) /* return if no tokens remaining */ + return(NULL); + + q = p + strspn(p, sepset); /* skip leading separators */ + + if(*q == '\0') /* return if no tokens remaining */ + return(NULL); + + if((r = strpbrk(q, sepset)) == NULL) /* move past token */ + savept = 0; /* indicate this is last token */ + else { + *r = '\0'; + savept = ++r; + } + return(q); +} diff --git a/usr/src/lib/libbc/libc/gen/common/strtol.c b/usr/src/lib/libbc/libc/gen/common/strtol.c new file mode 100644 index 0000000000..5871be330f --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/strtol.c @@ -0,0 +1,79 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <ctype.h> +#define DIGIT(x) (isdigit(x) ? (x) - '0' : \ + islower(x) ? (x) + 10 - 'a' : (x) + 10 - 'A') +#define MBASE ('z' - 'a' + 1 + 10) + +long +strtol(str, ptr, base) +register char *str; +char **ptr; +register int base; +{ + register long val; + register int c; + int xx, neg = 0; + + if (ptr != (char **)0) + *ptr = str; /* in case no number is formed */ + if (base < 0 || base > MBASE) + return (0); /* base is invalid -- should be a fatal error */ + if (!isalnum(c = *str)) { + while (isspace(c)) + c = *++str; + switch (c) { + case '-': + neg++; + case '+': /* fall-through */ + c = *++str; + } + } + if (base == 0) + if (c != '0') + base = 10; + else if (str[1] == 'x' || str[1] == 'X') + base = 16; + else + base = 8; + /* + * for any base > 10, the digits incrementally following + * 9 are assumed to be "abc...z" or "ABC...Z" + */ + if (!isalnum(c) || (xx = DIGIT(c)) >= base) + return (0); /* no number formed */ + if (base == 16 && c == '0' && isxdigit(str[2]) && + (str[1] == 'x' || str[1] == 'X')) + c = *(str += 2); /* skip over leading "0x" or "0X" */ + for (val = -DIGIT(c); isalnum(c = *++str) && (xx = DIGIT(c)) < base; ) + /* accumulate neg avoids surprises near MAXLONG */ + val = base * val - xx; + if (ptr != (char **)0) + *ptr = str; + return (neg ? val : -val); +} diff --git a/usr/src/lib/libbc/libc/gen/common/swab.c b/usr/src/lib/libbc/libc/gen/common/swab.c new file mode 100644 index 0000000000..19c50d1e99 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/swab.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/06/27 */ + +/* + * Swab bytes + * Jeffrey Mogul, Stanford + */ + +void +swab(from, to, n) + register char *from, *to; + register int n; +{ + register unsigned long temp; + + if (n <= 1) + return; + n >>= 1; n++; +#define STEP temp = *from++,*to++ = *from++,*to++ = temp + /* round to multiple of 8 */ + while ((--n) & 07) + STEP; + n >>= 3; + while (--n >= 0) { + STEP; STEP; STEP; STEP; + STEP; STEP; STEP; STEP; + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/syslog.c b/usr/src/lib/libbc/libc/gen/common/syslog.c new file mode 100644 index 0000000000..ffe71acfb6 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/syslog.c @@ -0,0 +1,341 @@ +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * SYSLOG -- print message on log file + * + * This routine looks a lot like printf, except that it + * outputs to the log file instead of the standard output. + * Also: + * adds a timestamp, + * prints the module name in front of the message, + * has some other formatting types (or will sometime), + * adds a newline on the end of the message. + * + * The output of this routine is intended to be read by /etc/syslogd. + * + * Author: Eric Allman + * Modified to use UNIX domain IPC by Ralph Campbell + */ + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/signal.h> +#include <sys/syslog.h> +#include <sys/time.h> +#include <netdb.h> +#include <strings.h> +#include <varargs.h> +#include <vfork.h> +#include <stdio.h> + +#define MAXLINE 1024 /* max message size */ +#define NULL 0 /* manifest */ + +#define PRIMASK(p) (1 << ((p) & LOG_PRIMASK)) +#define PRIFAC(p) (((p) & LOG_FACMASK) >> 3) +#define IMPORTANT LOG_ERR + +static char *logname = "/dev/log"; +static char *ctty = "/dev/console"; +static char *sysmsg = "/dev/sysmsg"; + +static struct _syslog { + int _LogFile; + int _LogStat; + char *_LogTag; + int _LogMask; + struct sockaddr _SyslogAddr; + char *_SyslogHost; + int _LogFacility; +} *_syslog; +#define LogFile (_syslog->_LogFile) +#define LogStat (_syslog->_LogStat) +#define LogTag (_syslog->_LogTag) +#define LogMask (_syslog->_LogMask) +#define SyslogAddr (_syslog->_SyslogAddr) +#define SyslogHost (_syslog->_SyslogHost) +#define LogFacility (_syslog->_LogFacility) + +extern int errno; + +extern char *calloc(); +extern char *strerror(int); +extern time_t time(); +extern unsigned int alarm(); + +static int +allocstatic() +{ + _syslog = (struct _syslog *)calloc(1, sizeof (struct _syslog)); + if (_syslog == 0) + return (0); /* can't do it */ + LogFile = -1; /* fd for log */ + LogStat = 0; /* status bits, set by openlog() */ + LogTag = "syslog"; /* string to tag the entry with */ + LogMask = 0xff; /* mask of priorities to be logged */ + LogFacility = LOG_USER; /* default facility code */ + return (1); +} + +/*VARARGS2*/ +syslog(pri, fmt, va_alist) + int pri; + char *fmt; + va_dcl +{ + va_list ap; + + va_start(ap); + vsyslog(pri, fmt, ap); + va_end(ap); +} + +vsyslog(pri, fmt, ap) + int pri; + char *fmt; + va_list ap; +{ + char buf[MAXLINE + 1], outline[MAXLINE + 1]; + register char *b, *f, *o; + register int c; + long now; + int pid, olderrno = errno; + int retsiz, outsiz = MAXLINE + 1; + int taglen; +/* + * Maximum tag length is 256 (the pad in outline) minus the size of the + * other things that can go in the pad. + */ +#define MAX_TAG 230 + + + if (_syslog == 0 && !allocstatic()) + return; + + /* see if we should just throw out this message */ + if (pri <= 0 || PRIFAC(pri) >= LOG_NFACILITIES || + (PRIMASK(pri) & LogMask) == 0) + return; + if (LogFile < 0) + openlog(LogTag, LogStat | LOG_NDELAY, 0); + + /* set default facility if none specified */ + if ((pri & LOG_FACMASK) == 0) + pri |= LogFacility; + + /* build the message */ + o = outline; + (void) time(&now); + (void) sprintf(o, "<%d>%.15s ", pri, ctime(&now) + 4); + o += strlen(o); + + if (LogTag) { + taglen = strlen(LogTag) < MAX_TAG ? strlen(LogTag) : MAX_TAG; + strncpy(o, LogTag, taglen); + o[taglen] = '\0'; + o += strlen(o); + } + if (LogStat & LOG_PID) { + (void) sprintf(o, "[%d]", getpid()); + o += strlen(o); + } + if (LogTag) { + (void) strcpy(o, ": "); + o += 2; + } + + b = buf; + f = fmt; + while ((c = *f++) != '\0' && c != '\n' && b < &buf[MAXLINE]) { + char *errstr; + + if (c != '%') { + *b++ = c; + continue; + } + if ((c = *f++) != 'm') { + *b++ = '%'; + *b++ = c; + continue; + } + if ((errstr = strerror(olderrno)) == NULL) + (void) snprintf(b, &buf[MAXLINE] - b, "error %d", + olderrno); + else { + while (*errstr != '\0' && b < &buf[MAXLINE]) { + if (*errstr == '%') { + strcpy(b, "%%"); + b += 2; + } + else + *b++ = *errstr; + errstr++; + } + *b = '\0'; + } + b += strlen(b); + } + if (b > buf && *(b-1) != '\n') /* ensure at least one newline */ + *b++ = '\n'; + *b = '\0'; + (void) vsnprintf(o, &outline[sizeof (outline)] - o, buf, ap); + c = strlen(outline) + 1; /* add one for NULL byte */ + if (c > MAXLINE) { + c = MAXLINE; + outline[MAXLINE-1] = '\0'; + } + + /* output the message to the local logger */ + if (sendto(LogFile, outline, c, 0, &SyslogAddr, + sizeof (SyslogAddr)) >= 0) + return; + if (!(LogStat & LOG_CONS)) + return; + + /* output the message to the console */ + pid = vfork(); + if (pid == -1) + return; + if (pid == 0) { + int fd; + + (void) signal(SIGALRM, SIG_DFL); + (void) sigsetmask(sigblock(0) & ~sigmask(SIGALRM)); + (void) alarm(5); + if (((fd = open(sysmsg, O_WRONLY)) >= 0) || + (fd = open(ctty, O_WRONLY)) >= 0) { + (void) alarm(0); + if (outsiz > 2) { /* Just in case */ + (void) strcat(o, "\r\n"); + c += 2; + } + o = index(outline, '>') + 1; + (void) write(fd, o, c - (o - outline)); + (void) close(fd); + } else + (void) alarm(0); + _exit(0); + } + if (!(LogStat & LOG_NOWAIT)) + while ((c = wait((int *)0)) > 0 && c != pid) + ; +} + +/* + * OPENLOG -- open system log + */ + +openlog(ident, logstat, logfac) + char *ident; + int logstat, logfac; +{ + if (_syslog == 0 && !allocstatic()) + return; + if (ident != NULL) + LogTag = ident; + LogStat = logstat; + if (logfac != 0) + LogFacility = logfac & LOG_FACMASK; + if (LogFile >= 0) + return; + SyslogAddr.sa_family = AF_UNIX; + (void) strncpy(SyslogAddr.sa_data, logname, + sizeof (SyslogAddr.sa_data)); + if (LogStat & LOG_NDELAY) { + LogFile = socket(AF_UNIX, SOCK_DGRAM, 0); + (void) fcntl(LogFile, F_SETFD, 1); + } +} + +/* + * CLOSELOG -- close the system log + */ + +closelog() +{ + + if (_syslog == 0) + return; + (void) close(LogFile); + LogFile = -1; +} + +/* + * SETLOGMASK -- set the log mask level + */ +setlogmask(pmask) + int pmask; +{ + int omask; + + if (_syslog == 0 && !allocstatic()) + return (-1); + omask = LogMask; + if (pmask != 0) + LogMask = pmask; + return (omask); +} + +/* + * snprintf/vsnprintf -- These routines are here + * temporarily to solve bugid 1220257. Perhaps + * they could become a public interface at some + * point but not for now. + */ + +extern int _doprnt(); + +/*VARARGS3*/ +static int +snprintf(string, n, format, va_alist) +char *string, *format; +size_t n; +va_dcl +{ + register int count; + FILE siop; + va_list ap; + + if (n == 0) + return (0); + siop._cnt = n - 1; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + va_start(ap); + count = _doprnt(format, ap, &siop); + va_end(ap); + *siop._ptr = '\0'; /* plant terminating null character */ + return (count); +} + +/*VARARGS3*/ +static int +vsnprintf(string, n, format, ap) +char *string, *format; +size_t n; +va_list ap; +{ + register int count; + FILE siop; + + if (n == 0) + return (0); + siop._cnt = n - 1; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + count = _doprnt(format, ap, &siop); + *siop._ptr = '\0'; /* plant terminating null character */ + return (count); +} diff --git a/usr/src/lib/libbc/libc/gen/common/telldir.c b/usr/src/lib/libbc/libc/gen/common/telldir.c new file mode 100644 index 0000000000..84364cb547 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/telldir.c @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/param.h> +#include <dirent.h> + +/* + * return a pointer into a directory + */ +long +telldir(dirp) + register DIR *dirp; +{ + return(dirp->dd_off); +} diff --git a/usr/src/lib/libbc/libc/gen/common/tfind.c b/usr/src/lib/libbc/libc/gen/common/tfind.c new file mode 100644 index 0000000000..b58036f1bd --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/tfind.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Tree search algorithm, generalized from Knuth (6.2.2) Algorithm T. + * + * The NODE * arguments are declared in the lint files as char *, + * because the definition of NODE isn't available to the user. + */ + +#include <search.h> +typedef char *POINTER; +typedef struct node { POINTER key; struct node *llink, *rlink; } NODE; + +#define NULL 0 + + +/* tfind - find a node, or return 0 */ +NODE * +tfind(key, rootp, compar) +POINTER key; /* Key to be located */ +register NODE **rootp; /* Address of the root of the tree */ +int (*compar)(); /* Comparison function */ +{ + if (rootp == NULL) + return (NULL); + while (*rootp != NULL) { /* T1: */ + int r = (*compar)(key, (*rootp)->key); /* T2: */ + if (r == 0) + return (*rootp); /* Key found */ + rootp = (r < 0) ? + &(*rootp)->llink : /* T3: Take left branch */ + &(*rootp)->rlink; /* T4: Take right branch */ + } + return (NODE *)(NULL); +} diff --git a/usr/src/lib/libbc/libc/gen/common/time.c b/usr/src/lib/libbc/libc/gen/common/time.c new file mode 100644 index 0000000000..7b73f79bd8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/time.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/02/27 */ + +/* + * Backwards compatible time call. + */ +#include <sys/types.h> +#include <sys/time.h> + +time_t +time(t) + time_t *t; +{ + struct timeval tt; + + if (gettimeofday(&tt, (struct timezone *)0) < 0) + return (-1); + if (t) + *t = tt.tv_sec; + return (tt.tv_sec); +} diff --git a/usr/src/lib/libbc/libc/gen/common/tsearch.c b/usr/src/lib/libbc/libc/gen/common/tsearch.c new file mode 100644 index 0000000000..87070147ce --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/tsearch.c @@ -0,0 +1,140 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.3 */ + +/*LINTLIBRARY*/ +/* + * Tree search algorithm, generalized from Knuth (6.2.2) Algorithm T. + * + * + * The NODE * arguments are declared in the lint files as char *, + * because the definition of NODE isn't available to the user. + */ + +#include <search.h> +typedef char *POINTER; +typedef struct node { POINTER key; struct node *llink, *rlink; } NODE; + +#define NULL 0 + +extern char *malloc(); + +NODE * +tsearch(key, rootp, compar) /* Find or insert key into search tree*/ +POINTER key; /* Key to be located */ +register NODE **rootp; /* Address of the root of the tree */ +int (*compar)(); /* Comparison function */ +{ + register NODE *q; /* New node if key not found */ + + if (rootp == NULL) + return (NULL); + while (*rootp != NULL) { /* T1: */ + int r = (*compar)(key, (*rootp)->key); /* T2: */ + if (r == 0) + return (*rootp); /* Key found */ + rootp = (r < 0) ? + &(*rootp)->llink : /* T3: Take left branch */ + &(*rootp)->rlink; /* T4: Take right branch */ + } + q = (NODE *) malloc(sizeof(NODE)); /* T5: Not found */ + if (q != NULL) { /* Allocate new node */ + *rootp = q; /* Link new node to old */ + q->key = key; /* Initialize new node */ + q->llink = q->rlink = NULL; + } + return (q); +} + +NODE * +tdelete(key, rootp, compar) /* Delete node with key key */ +POINTER key; /* Key to be deleted */ +register NODE **rootp; /* Address of the root of tree */ +int (*compar)(); /* Comparison function */ +{ + NODE *p; /* Parent of node to be deleted */ + register NODE *q; /* Successor node */ + register NODE *r; /* Right son node */ + int ans; /* Result of comparison */ + + if (rootp == NULL || (p = *rootp) == NULL) + return (NULL); + while ((ans = (*compar)(key, (*rootp)->key)) != 0) { + p = *rootp; + rootp = (ans < 0) ? + &(*rootp)->llink : /* Take left branch */ + &(*rootp)->rlink; /* Take right branch */ + if (*rootp == NULL) + return (NULL); /* Key not found */ + } + r = (*rootp)->rlink; /* D1: */ + if ((q = (*rootp)->llink) == NULL) /* Llink NULL? */ + q = r; + else if (r != NULL) { /* Rlink NULL? */ + if (r->llink == NULL) { /* D2: Find successor */ + r->llink = q; + q = r; + } else { /* D3: Find NULL link */ + for (q = r->llink; q->llink != NULL; q = r->llink) + r = q; + r->llink = q->rlink; + q->llink = (*rootp)->llink; + q->rlink = (*rootp)->rlink; + } + } + free((POINTER) *rootp); /* D4: Free node */ + *rootp = q; /* Link parent to replacement */ + return (p); +} + +void +twalk(root, action) /* Walk the nodes of a tree */ +NODE *root; /* Root of the tree to be walked */ +void (*action)(); /* Function to be called at each node */ +{ + void _twalk(); + + if (root != NULL && action != NULL) + _twalk(root, action, 0); +} + +static void +_twalk(root, action, level) /* Walk the nodes of a tree */ +register NODE *root; /* Root of the tree to be walked */ +register void (*action)(); /* Function to be called at each node */ +register int level; +{ + if (root->llink == NULL && root->rlink == NULL) + (*action)(root, leaf, level); + else { + (*action)(root, preorder, level); + if (root->llink != NULL) + _twalk(root->llink, action, level + 1); + (*action)(root, postorder, level); + if (root->rlink != NULL) + _twalk(root->rlink, action, level + 1); + (*action)(root, endorder, level); + } +} diff --git a/usr/src/lib/libbc/libc/gen/common/ttyslot.c b/usr/src/lib/libbc/libc/gen/common/ttyslot.c new file mode 100644 index 0000000000..a6c6506412 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ttyslot.c @@ -0,0 +1,65 @@ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from UCB 5.2 3/9/86 */ + +/* + * Copyright (c) 1984 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +/* + * Return the number of the slot in the utmp file + * corresponding to the current user: try for file 0, 1, 2. + * To mimic the behavior of getttyent, we loop through utmp + * and try to find an entry with a matching line number. + * If we don't find one we return the index of the end of + * the file, so that the record can be added to the end of + * the file. + */ +#include "../../sys/common/compat.h" +#include <sys/syscall.h> +#include <sys/fcntl.h> +#include <stdio.h> + +char *ttyname(); +char *rindex(); + +#define NULL 0 + +ttyslot() +{ + register char *tp, *p; + register s; + int fd; + struct utmpx utx; + + + if ((tp = ttyname(0)) == NULL && + (tp = ttyname(1)) == NULL && + (tp = ttyname(2)) == NULL) + return(0); + if ((p = rindex(tp, '/')) == NULL) + p = tp; + else + p++; + + if ((fd = _syscall(SYS_open, "/etc/utmpx", O_RDONLY)) == -1) { + perror("ttyslot: open of /etc/utmpx failed:"); + return(0); + } + + s = 0; + while (_read(fd, &utx, sizeof(struct utmpx)) > 0) { + s++; + if (strncmp(utx.ut_line, p, sizeof(utx.ut_line)) == 0) { + _syscall(SYS_close, fd); + return(s); + } + } + _syscall(SYS_close, fd); + return (s); +} diff --git a/usr/src/lib/libbc/libc/gen/common/ualarm.c b/usr/src/lib/libbc/libc/gen/common/ualarm.c new file mode 100644 index 0000000000..9972b0b279 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/ualarm.c @@ -0,0 +1,36 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/06/05 */ + +/* + * Copyright (c) 1985 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <sys/time.h> + +#define USPS 1000000 /* # of microseconds in a second */ + +/* + * Generate a SIGALRM signal in ``usecs'' microseconds. + * If ``reload'' is non-zero, keep generating SIGALRM + * every ``reload'' microseconds after the first signal. + */ +unsigned +ualarm(usecs, reload) + register unsigned usecs; + register unsigned reload; +{ + struct itimerval new, old; + + new.it_interval.tv_usec = reload % USPS; + new.it_interval.tv_sec = reload / USPS; + + new.it_value.tv_usec = usecs % USPS; + new.it_value.tv_sec = usecs / USPS; + + if (setitimer(ITIMER_REAL, &new, &old) == 0) + return (old.it_value.tv_sec * USPS + old.it_value.tv_usec); + /* else */ + return (-1); +} diff --git a/usr/src/lib/libbc/libc/gen/common/unpack_float.c b/usr/src/lib/libbc/libc/gen/common/unpack_float.c new file mode 100644 index 0000000000..7f3afe273e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/unpack_float.c @@ -0,0 +1,200 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1988 by Sun Microsystems, Inc. + */ + +/* IEEE function implementations. */ + +#include "base_conversion.h" + +enum fp_class_type +_class_single(x) + single *x; +{ + single_equivalence kluge; + + kluge.x = *x; + if (kluge.f.msw.exponent == 0) { /* 0 or sub */ + if (kluge.f.msw.significand == 0) + return fp_zero; + else + return fp_subnormal; + } else if (kluge.f.msw.exponent == 0xff) { /* inf or nan */ + if (kluge.f.msw.significand == 0) + return fp_infinity; + else if (kluge.f.msw.significand >= 0x400000) + return fp_quiet; + else + return fp_signaling; + } else + return fp_normal; +} + +enum fp_class_type +_class_extended(x) + extended *x; +{ + extended_equivalence kluge; + + kluge.x[0] = (*x)[0]; + kluge.x[1] = (*x)[1]; + kluge.x[2] = (*x)[2]; + if (kluge.f.msw.exponent == 0) { /* 0 or sub */ + if ((kluge.f.significand == 0) && (kluge.f.significand2 == 0)) + return fp_zero; + else + return fp_subnormal; + } else if (kluge.f.msw.exponent == 0x7fff) { /* inf or nan */ + if (((kluge.f.significand & 0x7fffffff) == 0) && (kluge.f.significand2 == 0)) + return fp_infinity; + else if ((kluge.f.significand & 0x7fffffff) >= 0x40000000) + return fp_quiet; + else + return fp_signaling; + } else + return fp_normal; +} + +void +_unpack_single(pu, px) + unpacked *pu; /* unpacked result */ + single *px; /* packed single */ +{ + single_equivalence x; + int i; + + x.x = *px; + (*pu).sign = x.f.msw.sign; + for (i = 1; i < UNPACKED_SIZE; i++) + pu->significand[i] = 0; + if (x.f.msw.exponent == 0) { /* zero or sub */ + if (x.f.msw.significand == 0) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* subnormal */ + pu->fpclass = fp_normal; + pu->exponent = -SINGLE_BIAS; + pu->significand[0] = x.f.msw.significand << 9; + _fp_normalize(pu); + return; + } + } else if (x.f.msw.exponent == 0xff) { /* inf or nan */ + if (x.f.msw.significand == 0) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((x.f.msw.significand & 0x400000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_quiet; + _fp_set_exception(fp_invalid); + } + pu->significand[0] = 0x40000000 | (x.f.msw.significand << 8); + return; + } + } + (*pu).exponent = x.f.msw.exponent - SINGLE_BIAS; + (*pu).fpclass = fp_normal; + (*pu).significand[0] = 0x80000000 | (x.f.msw.significand << 8); +} + +void +_unpack_extended(pu, px) + unpacked *pu; /* unpacked result */ + extended *px; /* packed extended */ +{ + extended_equivalence x; + int i; + + x.x[0] = (*px)[0]; + x.x[1] = (*px)[1]; + x.x[2] = (*px)[2]; + pu->sign = x.f.msw.sign; + pu->fpclass = fp_normal; + pu->exponent = x.f.msw.exponent - EXTENDED_BIAS; + pu->significand[0] = x.f.significand; + pu->significand[1] = x.f.significand2; + for (i = 2; i < UNPACKED_SIZE; i++) + pu->significand[i] = 0; + if (x.f.msw.exponent == 0x7fff) { /* inf or nan */ + if (((x.f.significand & 0x7fffffff) == 0) && (x.f.significand2 == 0)) { /* inf */ + pu->fpclass = fp_infinity; + return; + } else { /* nan */ + if ((x.f.significand & 0x40000000) != 0) { /* quiet */ + pu->fpclass = fp_quiet; + } else {/* signaling */ + pu->fpclass = fp_quiet; + _fp_set_exception(fp_invalid); + } + return; + } + } + if (x.f.significand < 0x80000000) { /* zero or unnormal */ + if ((x.f.significand == 0) && (x.f.significand2 == 0)) { /* zero */ + pu->fpclass = fp_zero; + return; + } else { /* unnormal */ + pu->fpclass = fp_normal; + _fp_normalize(pu); + return; + } + } +} + + +_display_unpacked(pu) + unpacked *pu; +{ + int i, e; + + (void) printf(" unpacked "); + if (pu->sign == 1) + (void) printf("-"); + else + (void) printf("+"); + switch (pu->fpclass) { + case fp_zero: + (void) printf("0"); + break; + case fp_infinity: + (void) printf("Infinity"); + break; + case fp_quiet: + (void) printf("NaN(quiet)"); + break; + case fp_signaling: + (void) printf("NaN(signaling)"); + break; + case fp_subnormal: + case fp_normal: + e = 1 + pu->exponent; + for (i = 0; i < UNPACKED_SIZE; i++) { + e -= 32; + (void) printf(" %8X *2**%d + ", pu->significand[i], e); + } + } + (void) printf("\n"); +} diff --git a/usr/src/lib/libbc/libc/gen/common/usleep.c b/usr/src/lib/libbc/libc/gen/common/usleep.c new file mode 100644 index 0000000000..88099cf89d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/usleep.c @@ -0,0 +1,75 @@ +/* + * Copyright 1996 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 5.1 85/06/05 */ + +/* + * Copyright (c) 1985 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#include <unistd.h> +#include <sys/time.h> +#include <signal.h> + +#define USPS 1000000 /* number of microseconds in a second */ +#define TICK (USPS / _sysconf(_SC_CLK_TCK)) + +#define setvec(vec, a) \ + vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 + +static int ringring; + +usleep(n) + unsigned n; +{ + static void sleepx(); + int omask; + struct itimerval itv, oitv; + register struct itimerval *itp = &itv; + struct sigvec vec, ovec; + + if (n == 0) + return; + timerclear(&itp->it_interval); + timerclear(&itp->it_value); + if (setitimer(ITIMER_REAL, itp, &oitv) < 0) + return; + itp->it_value.tv_sec = n / USPS; + itp->it_value.tv_usec = n % USPS; + if (timerisset(&oitv.it_value)) { + if (timercmp(&oitv.it_value, &itp->it_value, >)) { + oitv.it_value.tv_sec -= itp->it_value.tv_sec; + oitv.it_value.tv_usec -= itp->it_value.tv_usec; + if (oitv.it_value.tv_usec < 0) { + oitv.it_value.tv_usec += USPS; + oitv.it_value.tv_sec--; + } + } else { + itp->it_value = oitv.it_value; + oitv.it_value.tv_sec = 0; + oitv.it_value.tv_usec = 2 * TICK; + } + } + setvec(vec, sleepx); + (void) sigvec(SIGALRM, &vec, &ovec); + omask = sigblock(sigmask(SIGALRM)); + ringring = 0; + (void) setitimer(ITIMER_REAL, itp, (struct itimerval *)0); + while (!ringring) + sigpause(omask &~ sigmask(SIGALRM)); + (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0); + (void) sigsetmask(omask); + (void) setitimer(ITIMER_REAL, &oitv, (struct itimerval *)0); +} + +static void +sleepx() +{ + + ringring = 1; +} diff --git a/usr/src/lib/libbc/libc/gen/common/valloc.c b/usr/src/lib/libbc/libc/gen/common/valloc.c new file mode 100644 index 0000000000..68fd6a9efc --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/valloc.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.3 83/07/01 */ + +extern unsigned getpagesize(); +extern char *memalign(); + +char * +valloc(size) + unsigned size; +{ + static unsigned pagesize; + if (!pagesize) + pagesize = getpagesize(); + return memalign(pagesize, size); +} diff --git a/usr/src/lib/libbc/libc/gen/common/wcstombs.c b/usr/src/lib/libbc/libc/gen/common/wcstombs.c new file mode 100644 index 0000000000..9520238429 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/wcstombs.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * wcstombs + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" + +size_t +wcstombs(s, pwcs, n) + char *s; + wchar_t * pwcs; + size_t n; +{ + char *handle; /* handle */ + int (*p)(); + int num = 0; + int ret; + + switch (_code_set_info.code_id) { + case CODESET_NONE: + /* + * default code set + */ + while (*pwcs && (num < n)) { + *s++ = *pwcs++ & 0x00ff; + num++; + } + if (num < n) + *s = 0; + return (num); + break; + case CODESET_EUC: + /* + * EUC code set + */ + return(_wcstombs_euc(s, pwcs, n)); + break; + + case CODESET_XCCS: + /* + * XCCS code set + */ + return(_wcstombs_xccs(s, pwcs, n)); + break; + + case CODESET_ISO2022: + /* + * ISO family + */ + return(_wcstombs_iso(s, pwcs, n)); + break; + + default: + /* + * User defined code set + */ + handle = _ml_open_library(); + if (handle == (char *)NULL) + return(ERROR_NO_LIB); /* No user library */ + p = (int (*)()) dlsym(handle, "_wcstombs"); + if (p == (int (*)()) NULL) + return(ERROR_NO_SYM); + ret = (*p)(s, pwcs, n); + return (ret); + break; + } + /* NOTREACHED */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/wctomb.c b/usr/src/lib/libbc/libc/gen/common/wctomb.c new file mode 100644 index 0000000000..dba8d0999d --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/wctomb.c @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * wctomb + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <sys/types.h> +#include "codeset.h" +#include "mbextern.h" + +int +wctomb(s, pwc) + char *s; + wchar_t pwc; +{ + char *handle; /* handle */ + int (*p)(); + int ret; + + switch (_code_set_info.code_id) { + case CODESET_NONE: + /* + * Default code set, + */ + if (s == NULL) + return (0); /* No state dependency */ + else { + *s = (char) (pwc & 0x00ff); + return (1); + } + case CODESET_EUC: + /* + * EUC code set + */ + if (s == NULL) + return (0); /* No state dependecy */ + return(_wctomb_euc(s, pwc)); + break; + + case CODESET_XCCS: + /* + * XCCS code set + */ + if (s == 0) + return (0); /* No state dependecy */ + return(_wctomb_xccs(s, pwc)); + break; + + case CODESET_ISO2022: + /* + * ISO family + */ + if (s == 0) + return (1); /* State dependant */ + return(_wctomb_iso(s, pwc)); + break; + + default: + /* + * User defined code set + */ + handle = _ml_open_library(); + if (handle == (char *)NULL) + return(ERROR_NO_LIB); /* No user library */ + p = (int (*)()) dlsym(handle, "_wctomb"); + if (p == (int (*)()) NULL) + return(ERROR_NO_SYM); + ret = (*p)(s, pwc); + return (ret); + break; + } + /* NOTREACHED */ +} diff --git a/usr/src/lib/libbc/libc/gen/common/xccs.multibyte.c b/usr/src/lib/libbc/libc/gen/common/xccs.multibyte.c new file mode 100644 index 0000000000..6685f4d707 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/common/xccs.multibyte.c @@ -0,0 +1,342 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#if !defined(lint) && defined(SCCSIDS) +static char *sccsid = "%Z%%M% %I% %E% SMI"; +#endif + +#include <stdio.h> +#include <sys/types.h> + +#define CS377 0377 +#define MASK 0x0000ffff +#define TOP1 0x80000000 +#define TOP2 0x08000000 + + +/* + * mbtowc routines for the Xerox XCCS codeset standard + */ +int +_mbtowc_xccs(pwc, s, n) + wchar_t *pwc; + char *s; + int n; +{ + static unsigned int CSselect = 0; + static int CSlength = 1; + wchar_t twchar = 0; + + /* + * If length is negative, return error + */ + if (n <= 0) + return (-1); + + /* + * End of string ? + */ + if (*s == 0 && CSlength == 1) + return (0); + if (*s == 0 && *(s + 1) == 0 && CSlength == 2) + return (0); + + /* + * Get a character + */ + if ((unsigned char)*s == CS377) { + /* + * Switching code set + */ + ++s; + /* + * Change characteristics + */ + if ((unsigned char)*s == CS377) { + ++s; + /* + * two byte sequence + */ + if (*s++ != 0) + return (-1); + CSselect = 0; + CSlength = 2; + + } + else { + /* + * Change CSselect + */ + CSselect = (unsigned int)*s++; + CSlength = 1; + } + } + + /* + * Get a character and return + */ + if (CSlength == 1) { + twchar = CSselect; + } + else { + twchar = *s++; + } + twchar = twchar << 8; + twchar = twchar | *s; + if (pwc) + *pwc = twchar & MASK; + /* + * Encode additional information + */ + if (CSlength == 2) + if (pwc) + *pwc |= TOP1; + return (CSlength); +} + +/* + * wctomb routines + */ +int +_wctomb_xccs(s, pwc) + char *s; + wchar_t pwc; +{ + unsigned char upper, lower; + char *old = s; +#ifdef DEBUG + printf ("XCCS- xctomb\n"); +#endif + + if (!s) + return (0); + + /* + * Get lower and upper anyway + */ + lower = pwc & 0x00ff; + upper = (pwc >> 8) & 0x00ff; + if (lower == CS377 || upper == CS377) + return (-1); + if (pwc & TOP1) { /* length == 2 */ + /* + * This was the marker. + * Emitt 3 additional characters. + */ + *s++ = CS377; + *s++ = CS377; + *s++ = 0; + *s++ = upper; + *s++ = lower; + } + else { + /* + * This was the marker. + * Emitt 2 additional characters. + */ + *s++ = CS377; + *s++ = upper; + *s++ = lower; + } + return (s - old); +} + + +/* + * mbstowcs routines + */ +size_t +_mbstowcs_xccs(pwc, s, n) + wchar_t *pwc; + char *s; + int n; +{ + static unsigned int CSselect = 0; + static int CSlength = 1; + wchar_t twchar = 0; + int cnt = 0; + + /* + * If length is negative, return error + */ + if (n <= 0) + return (-1); + + /* + * End of string ? + */ + if (*s == 0 && CSlength == 1) + return (0); + if (*s == 0 && *(s + 1) == 0 && CSlength == 2) + return (0); + + do { + /* + * Check for an end of the string + */ + if (((*s == 0 && CSlength == 1)) || + ((*s == 0 && *(s + 1) == 0 && CSlength == 2))) { + *pwc = 0; + ++cnt; + --n; + break; + } + /* + * Get a character + */ + if ((unsigned char)*s == CS377) { + ++s; + /* + * Change characterristics + */ + if ((unsigned char)*s == CS377) { + ++s; + /* + * two byte sequence + */ + if (*s++ != 0) + return (-1); + CSselect = 0; + CSlength = 2; + + } + else { + /* + * Change CSselect + */ + CSselect = (unsigned int)*s++; + CSlength = 1; + } + } + + /* + * Get a character and return + */ + if (CSlength == 1) { + twchar = CSselect; + } + else { + twchar = *s++; + } + twchar = twchar << 8; + twchar = twchar | *s++; + *pwc = twchar & MASK; + if (CSlength == 2) + *pwc |= TOP1; + ++pwc; + ++cnt; + --n; + } while (n >= 0); + return (cnt); +} + + +/* + * wcstombs routines + */ +size_t +_wcstombs_xccs(s, pwc, n) + char *s; + wchar_t *pwc; + int n; +{ + int cnt = 0; + unsigned char lower, upper; + int in_2byte = 0; + int in_1byte = 0; + int current = 0; + + if (n <= 0) + return (-1); + + if (*pwc == 0) + return (0); + + do { + lower = *pwc & 0x00ff; + upper = (*pwc >> 8) & 0x00ff; + /* + * End of string ? + */ + if (lower == 0) { + *s++ = 0; + ++cnt; + --n; + if (n == 0) + break; + *s++ = 0; + ++cnt; + break; + } + if (lower == CS377 || upper == CS377) + return (-1); + if (*pwc & TOP1) { /* length == 2 */ + if (in_2byte == 0) { + /* + * This was the marker. + * Emitt 3 additional characters. + */ + *s++ = CS377; ++cnt; --n; + *s++ = CS377; ++cnt; --n; + *s++ = 0; ++cnt; --n; + in_2byte = 1; + in_1byte = 0; + } + *s++ = upper; ++cnt; --n; + if (n == 0) + break; + *s++ = lower; ++cnt; --n; + if (n == 0) + break; + } + else { + if ((in_1byte == 0 && in_2byte == 1) || + (in_1byte == 1 && upper != current) || + (in_1byte == 0 && in_2byte == 0 && upper != 0)) { + /* + * This was the marker. + * Emitt 2 additional characters. + */ + *s++ = CS377; ++cnt; --n; + if (n == 0) + break; + *s++ = upper; ++cnt; --n; + if (n == 0) + break; + in_2byte = 0; + in_1byte = 1; + current = upper; + } + *s++ = lower; ++cnt; --n; + if (n == 0) + break; + } + ++pwc; + } while (n >= 0); + return (cnt); +} diff --git a/usr/src/lib/libbc/libc/gen/sys5/assert.c b/usr/src/lib/libbc/libc/gen/sys5/assert.c new file mode 100644 index 0000000000..13ec8a88ee --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/assert.c @@ -0,0 +1,68 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * called from "assert" macro; prints without printf or stdio. + */ + +#define WRITE(s, n) (void) write(2, (s), (n)) +#define WRITESTR(s1, n, s2) WRITE((s1), n), \ + WRITE((s2), (unsigned) strlen(s2)) + +#define LINESTR ", line NNNNN\n" +char *malloc(); + +_assert(assertion, filename, line_num) +char *assertion; +char *filename; +int line_num; +{ + static char *linestr; + register char *p; + register int div, digit; + + if (!linestr) { + linestr = malloc(strlen(LINESTR)+1); + strcpy(linestr, LINESTR); + } + p = &linestr[7]; + + WRITESTR("Assertion failed: ", 18, assertion); + WRITESTR(", file ", 7, filename); + for (div = 10000; div != 0; line_num %= div, div /= 10) + if ((digit = line_num/div) != 0 || p != &linestr[7] || div == 1) + *p++ = digit + '0'; + *p++ = '\n'; + *p = '\0'; + WRITE(linestr, (unsigned) strlen(linestr)); + (void) abort(); +} diff --git a/usr/src/lib/libbc/libc/gen/sys5/nlist.c b/usr/src/lib/libbc/libc/gen/sys5/nlist.c new file mode 100644 index 0000000000..1621793297 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/nlist.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 Sun Microsystems, Inc. + */ + +#include <sys/file.h> +#include <a.out.h> + +/* + * nlist - retreive attributes from name list (string table version) + * [The actual work is done in ../common/_nlist.c] + */ +nlist(name, list) + char *name; + struct nlist *list; +{ + register int fd; + + fd = open(name, O_RDONLY, 0); + (void) _nlist(fd, list); + close(fd); + return (0); +} diff --git a/usr/src/lib/libbc/libc/gen/sys5/sgetl.c b/usr/src/lib/libbc/libc/gen/sys5/sgetl.c new file mode 100644 index 0000000000..8904cc103e --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/sgetl.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Provide machine independent transfer of longs. + */ + +/* + * The intent here is to provide a means to make the value of + * bytes in an io-buffer correspond to the value of a long + * in the memory while doing the io a `long' at a time. + * Files written and read in this way are machine-independent. + * + */ +#include <values.h> + +long sgetl(buffer) +register char *buffer; +{ + register long l = 0; + register int i = BITSPERBYTE * sizeof(long); + + while ((i -= BITSPERBYTE) >= 0) + l |= (short) ((unsigned char) *buffer++) << i; + return l; + } + diff --git a/usr/src/lib/libbc/libc/gen/sys5/sighold.c b/usr/src/lib/libbc/libc/gen/sys5/sighold.c new file mode 100644 index 0000000000..d0b304dd72 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/sighold.c @@ -0,0 +1,118 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1987 Sun Microsystems, Inc. + */ + +#include <errno.h> +#include <sys/signal.h> + +int +sighold(sig) + int sig; +{ + + if (sig == SIGKILL) { + errno = EINVAL; + return (-1); /* sigblock quietly disallows SIGKILL */ + } + (void) sigblock(sigmask(sig)); + return (0); /* SVID specifies 0 return on success */ +} + +int +sigrelse(sig) + int sig; +{ + + if (sig == SIGKILL) { + errno = EINVAL; + return (-1); /* sigsetmask quietly disallows SIGKILL */ + } + (void) sigsetmask(sigblock(0) & ~sigmask(sig)); + return (0); /* SVID specifies 0 return on success */ +} + +int +sigignore(sig) + int sig; +{ + struct sigvec vec; + + if (sig == SIGKILL) { + errno = EINVAL; + return (-1); /* sigsetmask quietly disallows SIGKILL */ + } + if (sigvec(sig, (struct sigvec *)0, &vec) < 0) + return (-1); + vec.sv_handler = SIG_IGN; + if (sigvec(sig, &vec, (struct sigvec *)0) < 0) + return (-1); + (void) sigsetmask(sigblock(0) & ~sigmask(sig)); + return (0); /* SVID specifies 0 return on success */ +} + +void (* +sigset(sig, func))() + int sig; + void (*func)(); +{ + struct sigvec newvec; + int newmask; + struct sigvec oldvec; + int oldmask; + + if (sigvec(sig, (struct sigvec *)0, &oldvec) < 0) + return (SIG_ERR); + oldmask = sigblock(0); + newvec = oldvec; + newvec.sv_flags |= SV_INTERRUPT; + newvec.sv_flags &= ~SV_RESETHAND; + newvec.sv_mask = 0; + newmask = oldmask; + if (func == SIG_HOLD) { + /* + * Signal will be held. Set the bit for that + * signal in the signal mask. Leave the action + * alone. + */ + newmask |= sigmask(sig); + } else { + /* + * Signal will not be held. Clear the bit + * for it in the signal mask. Set the action + * for it. + */ + newmask &= ~sigmask(sig); + newvec.sv_handler = func; + } + if (sigvec(sig, &newvec, (struct sigvec *)0) < 0) + return (SIG_ERR); + if (sigsetmask(newmask) < 0) + return (SIG_ERR); + if (oldmask & sigmask(sig)) + return (SIG_HOLD); /* signal was held */ + else + return (oldvec.sv_handler); +} diff --git a/usr/src/lib/libbc/libc/gen/sys5/sleep.c b/usr/src/lib/libbc/libc/gen/sys5/sleep.c new file mode 100644 index 0000000000..eb5e3c392b --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/sleep.c @@ -0,0 +1,112 @@ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1980 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +/* + * Copyright (c) 1986 by Sun Microsystems, Inc. + */ + +#include <sys/time.h> +#include <signal.h> + +#define setvec(vec, a) \ + vec.sv_handler = a; vec.sv_mask = vec.sv_onstack = 0 + +/* + * sleep(n) + * + * return 0 if n seconds passed + * return n - t if t seconds passed + * + * this code is gross and works just barely. + * it would be nice if someone rewrote it. + */ +unsigned +sleep(n) + unsigned n; +{ + void sleepx(); + int omask; + struct itimerval new, old, zero; + register struct itimerval *newp = &new; + struct timeval left_over; + int alrm_flg; + struct sigvec vec, ovec; + + if (n == 0) + return(0); + timerclear(&newp->it_interval); + timerclear(&newp->it_value); + if (setitimer(ITIMER_REAL, newp, &old) < 0) + return(n); + newp->it_value.tv_sec = n; + alrm_flg = 0; + timerclear(&left_over); + if (timerisset(&old.it_value)) { + if (timercmp(&old.it_value, &newp->it_value, >)) { + old.it_value.tv_sec -= newp->it_value.tv_sec; + ++alrm_flg; + } else { + left_over.tv_sec = newp->it_value.tv_sec + - old.it_value.tv_sec; + if (old.it_value.tv_usec != 0) { + left_over.tv_sec--; + left_over.tv_usec = 1000000 + - old.it_value.tv_usec; + } + newp->it_value = old.it_value; + timerclear(&old.it_value); + --alrm_flg; + } + } + if (alrm_flg >= 0) { + setvec(vec, sleepx); + (void) sigvec(SIGALRM, &vec, &ovec); + } + omask = sigblock(sigmask(SIGALRM)); + (void) setitimer(ITIMER_REAL, newp, (struct itimerval *)0); + sigpause(omask &~ sigmask(SIGALRM)); + timerclear(&zero.it_value); + timerclear(&zero.it_interval); + (void) setitimer(ITIMER_REAL, &zero, newp); + if (alrm_flg >= 0) + (void) sigvec(SIGALRM, &ovec, (struct sigvec *)0); + (void) sigsetmask(omask); + if (alrm_flg > 0 || (alrm_flg < 0 && timerisset(&newp->it_value))) { + struct itimerval reset; + + /* + * I use reset instead of what new points to because the + * code that calculates the return value depends on the + * old value of *newp. + */ + reset = *newp; + newp = &reset; + newp->it_value.tv_usec += old.it_value.tv_usec; + newp->it_value.tv_sec += old.it_value.tv_sec; + if (newp->it_value.tv_usec >= 1000000) { + newp->it_value.tv_usec -= 1000000; + newp->it_value.tv_sec++; + } + (void) setitimer(ITIMER_REAL, newp, (struct itimerval *)0); + newp = &new; + } + left_over.tv_sec += newp->it_value.tv_sec; + left_over.tv_usec += newp->it_value.tv_usec; + if (left_over.tv_usec >= 1000000) { + left_over.tv_sec++; + left_over.tv_usec -= 1000000; + } + if (left_over.tv_usec >= 500000) + left_over.tv_sec++; + return(left_over.tv_sec); +} + +static void +sleepx() +{ +} diff --git a/usr/src/lib/libbc/libc/gen/sys5/sputl.c b/usr/src/lib/libbc/libc/gen/sys5/sputl.c new file mode 100644 index 0000000000..9867b878d8 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/sputl.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" +/* + * Provide machine independent transfer of longs. + */ + +/* + * The intent here is to provide a means to make the value of + * bytes in an io-stream correspond to the value of the long + * in the memory while doing the io a `long' at a time. + * Files written and read in this way are machine-independent. + * + */ +#include <values.h> + +void sputl(l, buffer) +register long l; +register char *buffer; +{ + register int i = BITSPERBYTE * sizeof(long); + + while ((i -= BITSPERBYTE) >= 0) + *buffer++ = (char) (l >> i); +} + diff --git a/usr/src/lib/libbc/libc/gen/sys5/system.c b/usr/src/lib/libbc/libc/gen/sys5/system.c new file mode 100644 index 0000000000..9919b3bbc3 --- /dev/null +++ b/usr/src/lib/libbc/libc/gen/sys5/system.c @@ -0,0 +1,97 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <signal.h> +#include <sys/types.h> +#include <sys/wait.h> +#include <string.h> +#include <sys/file.h> + +extern int execl(); + +int +system(s) +char *s; +{ + int status; + pid_t pid, w; + register void (*istat)(), (*qstat)(); + char path[256]; + char *c; + + while (*s == ' ' || *s == '\t') + s++; + + if (strncmp(s, "/usr/ucb", strlen("/usr/ucb")) == 0) { + /* check if command is under /usr/ucb, if not + * replace /usr/ucb with /usr/bin. + */ + strcpy(path, s); + if ((c = strchr(path, ' ')) != NULL) + *c ='\0'; + if (access(path, F_OK) == -1) { + strncpy(path, "/usr/bin", strlen("/usr/bin")); + if (c != NULL) *c = ' '; + s = path; + } + } + else if (strncmp(s, "/bin", strlen("/bin")) == 0 || + strncmp(s, "/usr/bin", strlen("/usr/bin")) == 0) { + /* if /usr/bin is specified, first check if the command + * exists under /usr/bin, otherwise try /usr/ucb */ + if (access(path, F_OK) == -1) { + strcpy(path, "/usr/ucb"); + if (strncmp(s, "/bin", strlen("/bin")) == 0) + strcat(path, strchr(s+1, '/')); + else { + c = strchr(s+1, '/'); + strcat(path, strchr(c+1, '/')); + } + if (c != NULL) *c = ' '; + s = path; + } + } + + if ((pid = vfork()) == 0) { + (void) execl("/bin/sh", "sh", "-c", s, (char *)0); + _exit(127); + } + if (pid == -1) { + return (-1); + } + istat = signal(SIGINT, SIG_IGN); + qstat = signal(SIGQUIT, SIG_IGN); + w = waitpid(pid, &status, 0); + (void) signal(SIGINT, istat); + (void) signal(SIGQUIT, qstat); + return ((w == -1) ? -1: status); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_addr.c b/usr/src/lib/libbc/libc/inet/inet_addr.c new file mode 100644 index 0000000000..ac347b1965 --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_addr.c @@ -0,0 +1,125 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.5 82/11/14 */ + +#include <sys/types.h> +#include <ctype.h> +#include <netinet/in.h> + +/* + * Internet address interpretation routine. + * All the network library routines call this + * routine to interpret entries in the data bases + * which are expected to be an address. + * The value returned is in network order. + */ +u_long +inet_addr(cp) + register char *cp; +{ + register u_long val, base, n; + register char c; + u_long parts[4], *pp = parts; + +again: + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, other=decimal. + */ + val = 0; base = 10; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; + else + base = 8; + } + while (c = *cp) { + if (isdigit(c)) { + if ((c - '0') >= base) + break; + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16-bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 4) + return (-1); + *pp++ = val, cp++; + goto again; + } + /* + * Check for trailing characters. + */ + if (*cp && !isspace(*cp)) + return (-1); + *pp++ = val; + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts; + switch (n) { + + case 1: /* a -- 32 bits */ + val = parts[0]; + break; + + case 2: /* a.b -- 8.24 bits */ + val = (parts[0] << 24) | (parts[1] & 0xffffff); + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) | + (parts[2] & 0xffff); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + val = (parts[0] << 24) | ((parts[1] & 0xff) << 16) | + ((parts[2] & 0xff) << 8) | (parts[3] & 0xff); + break; + + default: + return (-1); + } + val = htonl(val); + return (val); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_lnaof.c b/usr/src/lib/libbc/libc/inet/inet_lnaof.c new file mode 100644 index 0000000000..463d930e67 --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_lnaof.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.3 82/11/14 */ + +#include <sys/types.h> +#include <netinet/in.h> + +/* + * Return the local network address portion of an + * internet address; handles class a/b/c network + * number formats. + */ +inet_lnaof(in) + struct in_addr in; +{ + register u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return ((i)&IN_CLASSA_HOST); + else if (IN_CLASSB(i)) + return ((i)&IN_CLASSB_HOST); + else + return ((i)&IN_CLASSC_HOST); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_makeaddr.c b/usr/src/lib/libbc/libc/inet/inet_makeaddr.c new file mode 100644 index 0000000000..ffa52390a9 --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_makeaddr.c @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2001 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * University Copyright- Copyright (c) 1982, 1986, 1988 + * The Regents of the University of California + * All Rights Reserved + * + * University Acknowledgment- Portions of this document are derived from + * software developed by the University of California, Berkeley, and its + * contributors. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.4 85/06/02 */ + +#include <sys/types.h> +#include <netinet/in.h> + +/* + * Formulate an Internet address from network + host. Used in + * building addresses stored in the ifnet structure. + */ +struct in_addr +inet_makeaddr(net, host) + int net, host; +{ + ulong_t addr; + struct in_addr inaddr; + + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + else + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + inaddr.s_addr = htonl(addr); + return (inaddr); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_netof.c b/usr/src/lib/libbc/libc/inet/inet_netof.c new file mode 100644 index 0000000000..7e7359f79d --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_netof.c @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.3 82/11/14 */ + +#include <sys/types.h> +#include <netinet/in.h> + +/* + * Return the network number from an internet + * address; handles class a/b/c network #'s. + */ +inet_netof(in) + struct in_addr in; +{ + register u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); + else if (IN_CLASSB(i)) + return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); + else + return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_network.c b/usr/src/lib/libbc/libc/inet/inet_network.c new file mode 100644 index 0000000000..ef4949c6b3 --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_network.c @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 82/10/07 */ + +#include <sys/types.h> +#include <ctype.h> + +/* + * Internet network address interpretation routine. + * The library routines call this routine to interpret + * network numbers. + */ +u_long +inet_network(cp) + register char *cp; +{ + register u_long val, base, n; + register char c; + u_long parts[4], *pp = parts; + register int i; + +again: + val = 0; base = 10; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; + else + base = 8; + } + while (c = *cp) { + if (isdigit(c)) { + if ((c - '0') >= base) + break; + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + if (pp >= parts + 4) + return (-1); + *pp++ = val, cp++; + goto again; + } + if (*cp && !isspace(*cp)) + return (-1); + *pp++ = val; + n = pp - parts; + if (n > 4) + return (-1); + for (val = 0, i = 0; i < n; i++) { + val <<= 8; + val |= parts[i] & 0xff; + } + return (val); +} diff --git a/usr/src/lib/libbc/libc/inet/inet_ntoa.c b/usr/src/lib/libbc/libc/inet/inet_ntoa.c new file mode 100644 index 0000000000..d8fdd91ca3 --- /dev/null +++ b/usr/src/lib/libbc/libc/inet/inet_ntoa.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.1 83/06/12 */ + +/* + * Convert network-format internet address + * to base 256 d.d.d.d representation. + */ +#include <sys/types.h> +#include <netinet/in.h> + +char * +inet_ntoa(in) + struct in_addr in; +{ + static char b[18]; + register char *p; + + p = (char *)∈ +#define UC(b) (((int)b)&0xff) + sprintf(b, "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); + return (b); +} diff --git a/usr/src/lib/libbc/libc/net/authunix.c b/usr/src/lib/libbc/libc/net/authunix.c new file mode 100644 index 0000000000..2f7671ee75 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/authunix.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1992 by Sun Microsystems, Inc. + */ + + +#include <rpc/types.h> +#include <rpc/auth.h> + +#undef authunix_create +#undef authunix_create_default + +AUTH * +authunix_create(machname, uid, gid, len, aup_gids) + char *machname; + uid_t uid; + gid_t gid; + register int len; + gid_t *aup_gids; +{ + return(authsys_create(machname, uid, gid, len, aup_gids)); +} + + + +AUTH * +authunix_create_default() +{ + return(authsys_create_default()); +} diff --git a/usr/src/lib/libbc/libc/net/bindresvport.c b/usr/src/lib/libbc/libc/net/bindresvport.c new file mode 100644 index 0000000000..69e367ce2d --- /dev/null +++ b/usr/src/lib/libbc/libc/net/bindresvport.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#include <sys/types.h> +#include <sys/errno.h> +#include <sys/socket.h> +#include <netinet/in.h> + +/* + * Bind a socket to a privileged IP port + */ +bindresvport(sd, sin) + int sd; + struct sockaddr_in *sin; +{ + int res; + static short port; + struct sockaddr_in myaddr; + extern int errno; + int i; + +#define STARTPORT 600 +#define ENDPORT (IPPORT_RESERVED - 1) +#define NPORTS (ENDPORT - STARTPORT + 1) + + if (sin == (struct sockaddr_in *)0) { + sin = &myaddr; + bzero(sin, sizeof (*sin)); + sin->sin_family = AF_INET; + } else if (sin->sin_family != AF_INET) { + errno = EPFNOSUPPORT; + return (-1); + } + if (port == 0) { + port = (getpid() % NPORTS) + STARTPORT; + } + res = -1; + errno = EADDRINUSE; + for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) { + sin->sin_port = htons(port++); + if (port > ENDPORT) { + port = STARTPORT; + } + res = bind(sd, sin, sizeof(struct sockaddr_in)); + } + return (res); +} diff --git a/usr/src/lib/libbc/libc/net/ether_addr.c b/usr/src/lib/libbc/libc/net/ether_addr.c new file mode 100644 index 0000000000..d8950e7546 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/ether_addr.c @@ -0,0 +1,115 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1990 by Sun Microsystems, Inc. + * + * All routines necessary to deal with the file /etc/ethers. The file + * contains mappings from 48 bit ethernet addresses to their corresponding + * hosts name. The addresses have an ascii representation of the form + * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff; the + * bytes are always in network order. + */ + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <net/if.h> +#include <netinet/in.h> +#include <net/if_arp.h> +#include <netinet/if_ether.h> + +static char *domain; /* NIS domain name */ +static int usingyellow; +static char *ethers = "/etc/ethers"; + +/* + * Parses a line from /etc/ethers into its components. The line has the form + * 8:0:20:1:17:c8 krypton + * where the first part is a 48 bit ethernet addrerss and the second is + * the corresponding hosts name. + * Returns zero if successful, non-zero otherwise. + */ +ether_line(s, e, hostname) + char *s; /* the string to be parsed */ + struct ether_addr *e; /* ethernet address struct to be filled in */ + char *hostname; /* hosts name to be set */ +{ + register int i; + unsigned int t[6]; + + i = sscanf(s, " %x:%x:%x:%x:%x:%x %s", + &t[0], &t[1], &t[2], &t[3], &t[4], &t[5], hostname); + if (i != 7) { + return (7 - i); + } + for (i = 0; i < 6; i++) + e->ether_addr_octet[i] = t[i]; + return (0); +} + +/* + * Converts a 48 bit ethernet number to its string representation. + */ +#define EI(i) (unsigned int)(e->ether_addr_octet[(i)]) +char * +ether_ntoa(e) + struct ether_addr *e; +{ + static char *s; + + if (s == 0) { + s = (char *)malloc(18); + if (s == 0) + return (0); + } + s[0] = 0; + sprintf(s, "%x:%x:%x:%x:%x:%x", + EI(0), EI(1), EI(2), EI(3), EI(4), EI(5)); + return (s); +} + +/* + * Converts a ethernet address representation back into its 48 bits. + */ +struct ether_addr * +ether_aton(s) + char *s; +{ + static struct ether_addr *ep; + register int i; + unsigned int t[6]; + + if (ep == 0) { + ep = (struct ether_addr *)calloc(1, sizeof (struct ether_addr)); + if (ep == 0) + return (0); + } + i = sscanf(s, " %x:%x:%x:%x:%x:%x", + &t[0], &t[1], &t[2], &t[3], &t[4], &t[5]); + if (i != 6) + return ((struct ether_addr *)NULL); + for (i = 0; i < 6; i++) + ep->ether_addr_octet[i] = t[i]; + return (ep); +} diff --git a/usr/src/lib/libbc/libc/net/getrpcport.c b/usr/src/lib/libbc/libc/net/getrpcport.c new file mode 100644 index 0000000000..688cd10985 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/getrpcport.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1985 by Sun Microsystems, Inc. + */ + +#include <stdio.h> +#include <rpc/rpc.h> +#include <netdb.h> +#include <sys/socket.h> + +getrpcport(host, prognum, versnum, proto) + char *host; +{ + struct sockaddr_in addr; + struct hostent *hp; + + if ((hp = gethostbyname(host)) == NULL) + return (0); + bcopy(hp->h_addr, (char *) &addr.sin_addr, hp->h_length); + addr.sin_family = AF_INET; + addr.sin_port = 0; + return (pmap_getport(&addr, prognum, versnum, proto)); +} diff --git a/usr/src/lib/libbc/libc/net/rcmd.c b/usr/src/lib/libbc/libc/net/rcmd.c new file mode 100644 index 0000000000..9e989ff69e --- /dev/null +++ b/usr/src/lib/libbc/libc/net/rcmd.c @@ -0,0 +1,398 @@ +/* + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright (c) 1983 Regents of the University of California. + * All rights reserved. The Berkeley software License Agreement + * specifies the terms and conditions for redistribution. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <ctype.h> +#include <pwd.h> +#include <sys/param.h> +#include <sys/file.h> +#include <sys/signal.h> +#include <sys/socket.h> +#include <sys/stat.h> + +#include <netinet/in.h> + +#include <netdb.h> +#include <errno.h> + +extern errno; +char *index(), *strcpy(); +#ifndef S5EMUL +char *sprintf(); +#endif +static char *domain; + +int +rcmd( + char **ahost, + unsigned short rport, + const char *locuser, + const char *remuser, + const char *cmd, + int *fd2p) +{ + int s, timo = 1, pid, oldmask, retval; + struct sockaddr_in sin, from; + char c; + int lport = IPPORT_RESERVED - 1; + struct hostent *hp; + + pid = getpid(); + hp = gethostbyname(*ahost); + if (hp == 0) { + fprintf(stderr, "%s: unknown host\n", *ahost); + return (-1); + } + *ahost = hp->h_name; + oldmask = sigblock(sigmask(SIGURG)); + for (;;) { + s = rresvport(&lport); + if (s < 0) { + if (errno == EAGAIN) + fprintf(stderr, "socket: All ports in use\n"); + else + perror("rcmd: socket"); + sigsetmask(oldmask); + return (-1); + } + fcntl(s, F_SETOWN, pid); + sin.sin_family = hp->h_addrtype; + bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, hp->h_length); + sin.sin_port = rport; + if (connect(s, &sin, sizeof (sin)) >= 0) + break; + (void) close(s); + if (errno == EADDRINUSE) { + lport--; + continue; + } + if (errno == ECONNREFUSED && timo <= 16) { + sleep(timo); + timo *= 2; + continue; + } + if (hp->h_addr_list[1] != NULL) { + int oerrno = errno; + + fprintf(stderr, + "connect to address %s: ", inet_ntoa(sin.sin_addr)); + errno = oerrno; + perror(0); + hp->h_addr_list++; + bcopy(hp->h_addr_list[0], (caddr_t)&sin.sin_addr, + hp->h_length); + fprintf(stderr, "Trying %s...\n", + inet_ntoa(sin.sin_addr)); + continue; + } + perror(hp->h_name); + sigsetmask(oldmask); + return (-1); + } + lport--; + if (fd2p == 0) { + write(s, "", 1); + lport = 0; + } else { + char num[8]; + int s2 = rresvport(&lport), s3; + int len = sizeof (from); + + if (s2 < 0) + goto bad; + listen(s2, 1); + (void) sprintf(num, "%d", lport); + if (write(s, num, strlen(num)+1) != strlen(num)+1) { + perror("write: setting up stderr"); + (void) close(s2); + goto bad; + } + s3 = accept(s2, &from, &len); + (void) close(s2); + if (s3 < 0) { + perror("accept"); + lport = 0; + goto bad; + } + *fd2p = s3; + from.sin_port = ntohs((u_short)from.sin_port); + if (from.sin_family != AF_INET || + from.sin_port >= IPPORT_RESERVED) { + fprintf(stderr, + "socket: protocol failure in circuit setup.\n"); + goto bad2; + } + } + (void) write(s, locuser, strlen(locuser)+1); + (void) write(s, remuser, strlen(remuser)+1); + (void) write(s, cmd, strlen(cmd)+1); + retval = read(s, &c, 1); + if (retval != 1) { + if (retval == 0) { + fprintf(stderr, + "Protocol error, %s closed connection\n", *ahost); + } else if (retval < 0) { + perror(*ahost); + } else { + fprintf(stderr, + "Protocol error, %s sent %d bytes\n", *ahost, retval); + } + goto bad2; + } + if (c != 0) { + while (read(s, &c, 1) == 1) { + (void) write(2, &c, 1); + if (c == '\n') + break; + } + goto bad2; + } + sigsetmask(oldmask); + return (s); +bad2: + if (lport) + (void) close(*fd2p); +bad: + (void) close(s); + sigsetmask(oldmask); + return (-1); +} + +int +rresvport(alport) + int *alport; +{ + struct sockaddr_in sin; + int s; + + sin.sin_family = AF_INET; + sin.sin_addr.s_addr = INADDR_ANY; + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) + return (-1); + for (;;) { + sin.sin_port = htons((u_short)*alport); + if (bind(s, (caddr_t)&sin, sizeof (sin)) >= 0) + return (s); + if (errno != EADDRINUSE) { + (void) close(s); + return (-1); + } + (*alport)--; + if (*alport == IPPORT_RESERVED/2) { + (void) close(s); + errno = EAGAIN; /* close */ + return (-1); + } + } +} + +int +ruserok( + const char *rhost, + int superuser, + const char *ruser, + const char *luser) +{ + FILE *hostf; + char fhost[MAXHOSTNAMELEN]; + register const char *sp; + register char *p; + int baselen = -1; + + struct stat sbuf; + struct passwd *pwd; + char pbuf[MAXPATHLEN]; + int euid = -1; + + sp = rhost; + p = fhost; + while (*sp) { + if (*sp == '.') { + if (baselen == -1) + baselen = sp - rhost; + *p++ = *sp++; + } else { + *p++ = isupper(*sp) ? tolower(*sp++) : *sp++; + } + } + *p = '\0'; + + /* check /etc/hosts.equiv */ + if (!superuser) { + if ((hostf = fopen("/etc/hosts.equiv", "r")) != NULL) { + if (!_validuser(hostf, fhost, luser, ruser, baselen)) { + (void) fclose(hostf); + return(0); + } + (void) fclose(hostf); + } + } + + /* check ~/.rhosts */ + + if ((pwd = getpwnam(luser)) == NULL) + return(-1); + (void)strcpy(pbuf, pwd->pw_dir); + (void)strcat(pbuf, "/.rhosts"); + + /* + * Read .rhosts as the local user to avoid NFS mapping the root uid + * to something that can't read .rhosts. + */ + euid = geteuid(); + (void) seteuid (pwd->pw_uid); + if ((hostf = fopen(pbuf, "r")) == NULL) { + if (euid != -1) + (void) seteuid (euid); + return(-1); + } + (void)fstat(fileno(hostf), &sbuf); + if (sbuf.st_uid && sbuf.st_uid != pwd->pw_uid) { + fclose(hostf); + if (euid != -1) + (void) seteuid (euid); + return(-1); + } + + if (!_validuser(hostf, fhost, luser, ruser, baselen)) { + (void) fclose(hostf); + if (euid != -1) + (void) seteuid (euid); + return(0); + } + + (void) fclose(hostf); + if (euid != -1) + (void) seteuid (euid); + return (-1); +} + +_validuser(hostf, rhost, luser, ruser, baselen) +char *rhost, *luser, *ruser; +FILE *hostf; +int baselen; +{ + char *user; + char ahost[MAXHOSTNAMELEN]; + int hostmatch, usermatch; + register char *p; + + if (domain == NULL) { + (void) yp_get_default_domain(&domain); + } + while (fgets(ahost, sizeof (ahost), hostf)) { + hostmatch = usermatch = 0; /* bugid fix 1033104 */ + p = ahost; + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') { + *p = isupper(*p) ? tolower(*p) : *p; + p++; + } + if (*p == ' ' || *p == '\t') { + *p++ = '\0'; + while (*p == ' ' || *p == '\t') + p++; + user = p; + while (*p != '\n' && *p != ' ' && *p != '\t' && *p != '\0') + p++; + } else + user = p; + *p = '\0'; + if (ahost[0] == '+' && ahost[1] == 0) + hostmatch = 1; + else if (ahost[0] == '+' && ahost[1] == '@') + hostmatch = innetgr(ahost + 2, rhost, + NULL, domain); + else if (ahost[0] == '-' && ahost[1] == '@') { + if (innetgr(ahost + 2, rhost, NULL, domain)) + break; + } + else if (ahost[0] == '-') { + if (_checkhost(rhost, ahost+1, baselen)) + break; + } + else + hostmatch = _checkhost(rhost, ahost, baselen); + if (user[0]) { + if (user[0] == '+' && user[1] == 0) + usermatch = 1; + else if (user[0] == '+' && user[1] == '@') + usermatch = innetgr(user+2, NULL, + ruser, domain); + else if (user[0] == '-' && user[1] == '@') { + if (hostmatch && innetgr(user+2, NULL, + ruser, domain)) + break; + } + else if (user[0] == '-') { + if (hostmatch && !strcmp(user+1, ruser)) + break; + } + else + usermatch = !strcmp(user, ruser); + } + else + usermatch = !strcmp(ruser, luser); + if (hostmatch && usermatch) + return (0); + } + return (-1); +} + +_checkhost(rhost, lhost, len) +char *rhost, *lhost; +int len; +{ + static char *ldomain; + static char *domainp; + static int nodomain; + register char *cp; + + if (ldomain == NULL) { + ldomain = (char *)malloc(MAXHOSTNAMELEN+1); + if (ldomain == 0) + return (0); + } + + if (len == -1) + return(!strcmp(rhost, lhost)); + if (strncmp(rhost, lhost, len)) + return(0); + if (!strcmp(rhost, lhost)) + return(1); + if (*(lhost + len) != '\0') + return(0); + if (nodomain) + return(0); + if (!domainp) { + /* + * "domainp" points after the first dot in the host name + */ + if (gethostname(ldomain, MAXHOSTNAMELEN) == -1) { + nodomain = 1; + return(0); + } + ldomain[MAXHOSTNAMELEN] = NULL; + if ((domainp = index(ldomain, '.')) == (char *)NULL) { + nodomain = 1; + return(0); + } + domainp++; + cp = domainp; + while (*cp) { + *cp = isupper(*cp) ? tolower(*cp) : *cp; + cp++; + } + } + return(!strcmp(domainp, rhost + len +1)); +} diff --git a/usr/src/lib/libbc/libc/net/rexec.c b/usr/src/lib/libbc/libc/net/rexec.c new file mode 100644 index 0000000000..8d8c141aca --- /dev/null +++ b/usr/src/lib/libbc/libc/net/rexec.c @@ -0,0 +1,144 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.8 83/08/18 */ + +#include <sys/types.h> +#include <sys/socket.h> + +#include <netinet/in.h> + +#include <stdio.h> +#include <netdb.h> +#include <errno.h> + +extern errno; +char *index(); +char *getpass(), *getlogin(); +#ifndef S5EMUL +char *sprintf(); +#endif + +int +rexec( + char **ahost, + unsigned short rport, + const char *name, + const char *pass, + const char *cmd, + int *fd2p) +{ + int s, timo = 1, s3; + struct sockaddr_in sin, sin2, from; + char c; + u_short port; + struct hostent *hp; + + hp = gethostbyname(*ahost); + if (hp == 0) { + fprintf(stderr, "%s: unknown host\n", *ahost); + return (-1); + } + *ahost = hp->h_name; + _ruserpass(hp->h_name, &name, &pass); +retry: + s = socket(AF_INET, SOCK_STREAM, 0); + if (s < 0) { + perror("rexec: socket"); + return (-1); + } + sin.sin_family = hp->h_addrtype; + sin.sin_port = rport; + bcopy(hp->h_addr, (caddr_t)&sin.sin_addr, hp->h_length); + if (connect(s, &sin, sizeof(sin)) < 0) { + if (errno == ECONNREFUSED && timo <= 16) { + (void) close(s); + sleep(timo); + timo *= 2; + goto retry; + } + perror(hp->h_name); + (void) close(s); + return (-1); + } + if (fd2p == 0) { + (void) write(s, "", 1); + port = 0; + } else { + char num[8]; + int s2, sin2len; + + s2 = socket(AF_INET, SOCK_STREAM, 0); + if (s2 < 0) { + (void) close(s); + return (-1); + } + listen(s2, 1); + sin2len = sizeof (sin2); + if (getsockname(s2, (char *)&sin2, &sin2len) < 0 || + sin2len != sizeof (sin2)) { + perror("getsockname"); + (void) close(s2); + goto bad; + } + port = ntohs((u_short)sin2.sin_port); + (void) sprintf(num, "%u", port); + (void) write(s, num, strlen(num)+1); + { int len = sizeof (from); + s3 = accept(s2, &from, &len); + close(s2); + if (s3 < 0) { + perror("accept"); + port = 0; + goto bad; + } + } + *fd2p = s3; + } + (void) write(s, name, strlen(name) + 1); + /* should public key encypt the password here */ + (void) write(s, pass, strlen(pass) + 1); + (void) write(s, cmd, strlen(cmd) + 1); + if (read(s, &c, 1) != 1) { + perror(*ahost); + goto bad; + } + if (c != 0) { + while (read(s, &c, 1) == 1) { + (void) write(2, &c, 1); + if (c == '\n') + break; + } + goto bad; + } + return (s); +bad: + if (port) + (void) close(*fd2p); + (void) close(s); + return (-1); +} diff --git a/usr/src/lib/libbc/libc/net/ruserpass.c b/usr/src/lib/libbc/libc/net/ruserpass.c new file mode 100644 index 0000000000..a88d986259 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/ruserpass.c @@ -0,0 +1,236 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 82/10/10 */ + +#include <stdio.h> +#include <ctype.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +char *malloc(), *index(), *getenv(), *getpass(), *getlogin(); + +#define DEFAULT 1 +#define LOGIN 2 +#define PASSWD 3 +#define NOTIFY 4 +#define WRITE 5 +#define YES 6 +#define NO 7 +#define COMMAND 8 +#define FORCE 9 +#define ID 10 +#define MACHINE 11 + +#define MAXTOKEN 11 +#define NTOKENS (MAXTOKEN - 1 + 2 + 1) /* two duplicates and null, minus id */ + +static struct ruserdata { + char tokval[100]; + struct toktab { + char *tokstr; + int tval; + } toktab[NTOKENS]; + FILE *cfile; +} *ruserdata, *_ruserdata(); + + +static struct ruserdata * +_ruserdata() +{ + register struct ruserdata *d = ruserdata; + struct toktab *t; + + if (d == 0) { + if ((d = (struct ruserdata *) + calloc(1, sizeof(struct ruserdata))) == NULL) { + return(NULL); + } + ruserdata = d; + t = d->toktab; + t->tokstr = "default"; t++->tval = DEFAULT; + t->tokstr = "login"; t++->tval = LOGIN; + t->tokstr = "password"; t++->tval = PASSWD; + t->tokstr = "notify"; t++->tval = NOTIFY; + t->tokstr = "write"; t++->tval = WRITE; + t->tokstr = "yes"; t++->tval = YES; + t->tokstr = "y"; t++->tval = YES; + t->tokstr = "no"; t++->tval = NO; + t->tokstr = "n"; t++->tval = NO; + t->tokstr = "command"; t++->tval = COMMAND; + t->tokstr = "force"; t++->tval = FORCE; + t->tokstr = "machine"; t++->tval = MACHINE; + t->tokstr = 0; t->tval = 0; + } + return(d); +} + + +_ruserpass(host, aname, apass) + char *host, **aname, **apass; +{ + + if (*aname == 0 || *apass == 0) + rnetrc(host, aname, apass); + if (*aname == 0) { + char *myname = getlogin(); + *aname = malloc(16); + printf("Name (%s:%s): ", host, myname); + fflush(stdout); + if (read(2, *aname, 16) <= 0) + exit(1); + if ((*aname)[0] == '\n') + *aname = myname; + else + if (index(*aname, '\n')) + *index(*aname, '\n') = 0; + } + if (*aname && *apass == 0) { + printf("Password (%s:%s): ", host, *aname); + fflush(stdout); + *apass = getpass(""); + } +} + + +static +rnetrc(host, aname, apass) + char *host, **aname, **apass; +{ + register struct ruserdata *d = _ruserdata(); + char *hdir, buf[BUFSIZ]; + int t; + struct stat stb; + extern int errno; + + if (d == 0) + return; + + hdir = getenv("HOME"); + if (hdir == NULL) + hdir = "."; + sprintf(buf, "%s/.netrc", hdir); + d->cfile = fopen(buf, "r"); + if (d->cfile == NULL) { + if (errno != ENOENT) + perror(buf); + return; + } +next: + while ((t = token())) switch(t) { + + case DEFAULT: + (void) token(); + continue; + + case MACHINE: + if (token() != ID || strcmp(host, d->tokval)) + continue; + while ((t = token()) && t != MACHINE) switch(t) { + + case LOGIN: + if (token()) + if (*aname == 0) { + *aname = malloc(strlen(d->tokval) + 1); + strcpy(*aname, d->tokval); + } else { + if (strcmp(*aname, d->tokval)) + goto next; + } + break; + case PASSWD: + if (fstat(fileno(d->cfile), &stb) >= 0 + && (stb.st_mode & 077) != 0) { + fprintf(stderr, "Error - .netrc file not correct mode.\n"); + fprintf(stderr, "Remove password or correct mode.\n"); + exit(1); + } + if (token() && *apass == 0) { + *apass = malloc(strlen(d->tokval) + 1); + strcpy(*apass, d->tokval); + } + break; + case COMMAND: + case NOTIFY: + case WRITE: + case FORCE: + (void) token(); + break; + default: + fprintf(stderr, "Unknown .netrc option %s\n", d->tokval); + break; + } + goto done; + } +done: + fclose(d->cfile); +} + +static +token() +{ + register struct ruserdata *d = _ruserdata(); + char *cp; + int c; + struct toktab *t; + + if (d == 0) + return(0); + + if (feof(d->cfile)) + return (0); + while ((c = getc(d->cfile)) != EOF && + (c == '\n' || c == '\t' || c == ' ' || c == ',')) + continue; + if (c == EOF) + return (0); + cp = d->tokval; + if (c == '"') { + while ((c = getc(d->cfile)) != EOF && c != '"') { + if (c == '\\') + c = getc(d->cfile); + *cp++ = c; + } + } else { + *cp++ = c; + while ((c = getc(d->cfile)) != EOF + && c != '\n' && c != '\t' && c != ' ' && c != ',') { + if (c == '\\') + c = getc(d->cfile); + *cp++ = c; + } + } + *cp = 0; + if (d->tokval[0] == 0) + return (0); + for (t = d->toktab; t->tokstr; t++) + if (!strcmp(t->tokstr, d->tokval)) + return (t->tval); + return (ID); +} + diff --git a/usr/src/lib/libbc/libc/net/sparc/htonl.c b/usr/src/lib/libbc/libc/net/sparc/htonl.c new file mode 100644 index 0000000000..0d1cea836d --- /dev/null +++ b/usr/src/lib/libbc/libc/net/sparc/htonl.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB X.X XX/XX/XX */ + +htonl(a) + long a; +{ + + return (a); +} diff --git a/usr/src/lib/libbc/libc/net/sparc/htons.c b/usr/src/lib/libbc/libc/net/sparc/htons.c new file mode 100644 index 0000000000..404774ea41 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/sparc/htons.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB X.X XX/XX/XX */ + +#include <sys/types.h> + +htons(a) + u_short a; +{ + + return (a); +} diff --git a/usr/src/lib/libbc/libc/net/sparc/ntohl.c b/usr/src/lib/libbc/libc/net/sparc/ntohl.c new file mode 100644 index 0000000000..33e908f04e --- /dev/null +++ b/usr/src/lib/libbc/libc/net/sparc/ntohl.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB X.X XX/XX/XX */ + +ntohl(a) + long a; +{ + + return (a); +} diff --git a/usr/src/lib/libbc/libc/net/sparc/ntohs.c b/usr/src/lib/libbc/libc/net/sparc/ntohs.c new file mode 100644 index 0000000000..7c9bed4bc3 --- /dev/null +++ b/usr/src/lib/libbc/libc/net/sparc/ntohs.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB X.X XX/XX/XX */ + +#include <sys/types.h> + +ntohs(a) + u_short a; +{ + + return (a); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/filbuf.c b/usr/src/lib/libbc/libc/stdio/4.2/filbuf.c new file mode 100644 index 0000000000..3cf2197cd9 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/filbuf.c @@ -0,0 +1,85 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern _findbuf(); +extern int read(); +extern int fflush(); + +int +__filbuf(iop) +register FILE *iop; +{ + return (_filbuf(iop)); +} + +int +_filbuf(iop) +register FILE *iop; +{ + + if ( !(iop->_flag & _IOREAD) ) + if (iop->_flag & _IORW) + iop->_flag |= _IOREAD; + else + return(EOF); + + if (iop->_flag&(_IOSTRG|_IOEOF)) + return(EOF); + + if (iop->_base == NULL) /* get buffer if we don't have one */ + _findbuf(iop); + + if (iop == stdin) { + if (stdout->_flag&_IOLBF) + (void) fflush(stdout); + if (stderr->_flag&_IOLBF) + (void) fflush(stderr); + } + + iop->_ptr = iop->_base; + iop->_cnt = read(fileno(iop), (char *)iop->_base, + (unsigned)((iop->_flag & _IONBF) ? 1 : iop->_bufsiz )); + if (--iop->_cnt >= 0) /* success */ + return (*iop->_ptr++); + if (iop->_cnt != -1) /* error */ + iop->_flag |= _IOERR; + else { /* end-of-file */ + iop->_flag |= _IOEOF; + if (iop->_flag & _IORW) + iop->_flag &= ~_IOREAD; + } + iop->_cnt = 0; + return (EOF); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/flsbuf.c b/usr/src/lib/libbc/libc/stdio/4.2/flsbuf.c new file mode 100644 index 0000000000..94da8125f5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/flsbuf.c @@ -0,0 +1,291 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.8 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include "../common/stdiom.h" +#include <sys/errno.h> +#include <sys/types.h> +#include <sys/stat.h> + +extern void free(); +extern int errno, write(), close(), isatty(); +extern char *malloc(); +extern unsigned char (*_smbuf)[_SBFSIZ]; + +void _getsmbuf(); + +/* + * Flush buffers on exit + */ + +void +_cleanup() +{ + extern int fclose(); + + _fwalk(fclose); +} +/* + fclose() will flush (output) buffers for a buffered open + FILE and then issue a system close on the _fileno. The + _base field will be reset to NULL for any but stdin and + stdout, the _ptr field will be set the same as the _base + field. The _flags and the _cnt field will be zeroed. + If buffers had been obtained via malloc(), the space will + be free()'d. In case the FILE was not open, or fflush() + or close() failed, an EOF will be returned, otherwise the + return value is 0. + */ + +int +fclose(iop) +register FILE *iop; +{ + register int rtn=EOF; + + if(iop == NULL) + return(rtn); + if(iop->_flag & (_IOREAD | _IOWRT | _IORW) + && (iop->_flag & _IOSTRG) == 0) { + rtn = (iop->_flag & _IONBF)? 0: fflush(iop); + if(close(fileno(iop)) < 0) + rtn = EOF; + } + if(iop->_flag & _IOMYBUF) { + free((char*)iop->_base); + iop->_base = NULL; + } + iop->_flag = 0; + iop->_cnt = 0; + iop->_ptr = iop->_base; + iop->_bufsiz = 0; + return(rtn); +} + +/* + The fflush() routine must take care because of the + possibility for recursion. The calling program might + do IO in an interupt catching routine that is likely + to interupt the write() call within fflush() + */ + +int +fflush(iop) +register FILE *iop; +{ + if (!(iop->_flag & _IOWRT)) { + return(0); + } + while(!(iop->_flag & _IONBF) && (iop->_flag & _IOWRT) && + (iop->_base != NULL) && (iop->_ptr > iop->_base) ) + (void) _xflsbuf(iop); + return(ferror(iop) ? EOF : 0); +} + +/* The routine _flsbuf may or may not actually flush the output buffer. If + * the file is line-buffered, the fact that iop->_cnt has run below zero + * is meaningless: it is always kept below zero so that invocations of putc + * will consistently give control to _flsbuf, even if the buffer is far from + * full. _flsbuf, on seeing the "line-buffered" flag, determines whether the + * buffer is actually full by comparing iop->_ptr to the end of the buffer + * iop->_base + iop->_bufsiz. If it is full, or if an output line is + * completed (with a newline), the buffer is flushed. (Note: the character + * argument to _flsbuf is not flushed with the current buffer if the buffer + * is actually full -- it goes into the buffer after flushing.) + */ + +int +_flsbuf(c, iop) +unsigned char c; +register FILE *iop; +{ + unsigned char c1; + + do { + /* check for linebuffered with write perm, but no EOF */ + if ( (iop->_flag & (_IOLBF | _IOWRT | _IOEOF)) == (_IOLBF | _IOWRT) ) { + if ( iop->_ptr >= iop->_base + iop->_bufsiz ) /* if buffer full, */ + break; /* exit do-while, and flush buf. */ + if ( (*iop->_ptr++ = c) != '\n' ) + return(c); + return(_xflsbuf(iop) == EOF ? EOF : c); + } + /* write out an unbuffered file, if have write perm, but no EOF */ + if ( (iop->_flag & (_IONBF | _IOWRT | _IOEOF)) == (_IONBF | _IOWRT) ) { + c1 = c; + iop->_cnt = 0; + if (write(fileno(iop), (char *) &c1, 1) == 1) + return(c); + iop->_flag |= _IOERR; + return(EOF); + } + /* The _wrtchk call is here rather than at the top of _flsbuf to re- */ + /* duce overhead for line-buffered I/O under normal circumstances. */ + + if (_WRTCHK(iop)) /* is writing legitimate? */ + return(EOF); + } while ( (iop->_flag & (_IONBF | _IOLBF)) ); + + + (void) _xflsbuf(iop); /* full buffer: flush buffer */ + (void) putc((char) c, iop); /* then put "c" in newly emptied buf */ + /* (which, because of signals, may NOT be empty) */ + return( ferror(iop) ? EOF : c); +} + +/* The function _xflsbuf writes out the current contents of the output + * buffer delimited by iop->_base and iop->_ptr. + * iop->_cnt is reset appropriately, but its value on entry to _xflsbuf + * is ignored. + * + * The following code is not strictly correct. If a signal is raised, + * invoking a signal-handler which generates output into the same buffer + * being flushed, a peculiar output sequence may result (for example, + * the output generated by the signal-handler may appear twice). At + * present no means has been found to guarantee correct behavior without + * resorting to the disabling of signals, a means considered too expensive. + * For now the code has been written with the intent of reducing the + * probability of strange effects and, when they do occur, of confining + * the damage. Except under extremely pathological circumstances, this + * code should be expected to respect buffer boundaries even in the face + * of interrupts and other signals. + */ + +int +_xflsbuf(iop) +register FILE *iop; +{ + register unsigned char *base; + register int n; + + n = iop->_ptr - (base = iop->_base); + iop->_ptr = base; + iop->_cnt = (iop->_flag &(_IONBF | _IOLBF)) ? 0 : iop->_bufsiz; + _BUFSYNC(iop); + if (n > 0 && n != write(fileno(iop),(char*)base,(unsigned)n) ) { + iop->_flag |= _IOERR; + return(EOF); + } + return(0); +} + +/* The function _wrtchk checks to see whether it is legitimate to write + * to the specified device. If it is, _wrtchk sets flags in iop->_flag for + * writing, assures presence of a buffer, and returns 0. If writing is not + * legitimate, EOF is returned. + */ + +int +_wrtchk(iop) +register FILE *iop; +{ + if ( (iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT ) { + if (!(iop->_flag & (_IOWRT | _IORW))) + return(EOF); /* bogus call--read-only file */ + iop->_flag = iop->_flag & ~_IOEOF | _IOWRT; /* fix flags */ + } + if (iop->_flag & _IOSTRG) + return(0); /* not our business to monkey with buffers or counts */ + if (iop->_base == NULL) /* this is first I/O to file--get buffer */ + _findbuf(iop); + if (iop->_ptr == iop->_base && !(iop->_flag & (_IONBF | _IOLBF)) ) { + iop->_cnt = iop->_bufsiz; /* first write since seek--set cnt */ + _BUFSYNC(iop); + } + return(0); +} + +/* + * _findbuf, called only when iop->_base == NULL, locates a predefined buffer + * or allocates a buffer using malloc. If a buffer is obtained from malloc, + * the _IOMYBUF flag is set in iop->_flag. + */ + +_findbuf(iop) +register FILE *iop; +{ + register int fno = fileno(iop); /* file number */ + struct stat statb; + register int size; + + /* allocate a small block for unbuffered, large for buffered */ + if (iop->_flag & _IONBF) { + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } else { + + if ( isatty(fno) ) { + iop->_flag |= _IOLBF; + size = 128; + } else { + if (fstat(fno, &statb) < 0) + size = BUFSIZ; + else { + if ((size = statb.st_blksize) <= 0) + size = BUFSIZ; + } + } + if ((iop->_base = (unsigned char *) malloc(size+8)) != NULL) { + /* if we got a buffer */ + iop->_flag |= _IOMYBUF; + iop->_bufsiz = size; + } else { + /* if no room for buffer, use small buffer */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + iop->_flag &= ~_IOLBF; + iop->_flag |= _IONBF; + } + } + iop->_ptr = iop->_base; +} + +/* The function _bufsync is called because interrupts and other signals + * which occur in between the decrementing of iop->_cnt and the incrementing + * of iop->_ptr, or in other contexts as well, may upset the synchronization + * of iop->_cnt and iop->ptr. If this happens, calling _bufsync should + * resynchronize the two quantities (this is not always possible). Resyn- + * chronization guarantees that putc invocations will not write beyond + * the end of the buffer. Note that signals during _bufsync can cause + * _bufsync to do the wrong thing, but usually with benign effects. + */ + +_bufsync(iop) +register FILE *iop; +{ + register int spaceleft; + register unsigned char *bufend = iop->_base + iop->_bufsiz; + + if ((spaceleft = bufend - iop->_ptr) < 0) + iop->_ptr = bufend; + else if (spaceleft < iop->_cnt) + iop->_cnt = spaceleft; +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/fopen.c b/usr/src/lib/libbc/libc/stdio/4.2/fopen.c new file mode 100644 index 0000000000..6e7a69d4be --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/fopen.c @@ -0,0 +1,92 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.8 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <fcntl.h> + +extern int open(), fclose(); +extern FILE *_findiop(), *_endopen(); + +FILE * +fopen(file, mode) +char *file, *mode; +{ + return (_endopen(file, mode, _findiop())); +} + +FILE * +freopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + (void) fclose(iop); /* doesn't matter if this fails */ + return (_endopen(file, mode, iop)); +} + +static FILE * +_endopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + register int plus, oflag, fd; + + if (iop == NULL || file == NULL || file[0] == '\0') + return (NULL); + plus = (mode[1] == '+'); + switch (mode[0]) { + case 'w': + oflag = (plus ? O_RDWR : O_WRONLY) | O_TRUNC | O_CREAT; + break; + case 'a': + oflag = (plus ? O_RDWR : O_WRONLY) | O_CREAT; + break; + case 'r': + oflag = plus ? O_RDWR : O_RDONLY; + break; + default: + return (NULL); + } + if ((fd = open(file, oflag, 0666)) < 0) + return (NULL); + iop->_cnt = 0; + iop->_file = fd; + iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; + if (mode[0] == 'a') { + if ((lseek(fd,0L,2)) < 0) { + (void) close(fd); + return NULL; + } + } + iop->_base = iop->_ptr = NULL; + iop->_bufsiz = 0; + return (iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/fprintf.c b/usr/src/lib/libbc/libc/stdio/4.2/fprintf.c new file mode 100644 index 0000000000..ef0e3a073e --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/fprintf.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +fprintf(iop, format, va_alist) +FILE *iop; +char *format; +va_dcl +{ + unsigned char localbuf[BUFSIZ]; + register int count; + va_list ap; + + va_start(ap); + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + va_end(ap); + return(count); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/printf.c b/usr/src/lib/libbc/libc/stdio/4.2/printf.c new file mode 100644 index 0000000000..e3c31230bb --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/printf.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +printf(format, va_alist) +char *format; +va_dcl +{ + register int count; + va_list ap; + + va_start(ap); + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + count = _doprnt(format, ap, stdout); + va_end(ap); + return(count); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/setbuf.c b/usr/src/lib/libbc/libc/stdio/4.2/setbuf.c new file mode 100644 index 0000000000..21e285bac2 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/setbuf.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern void free(); +extern int isatty(); +extern unsigned char (*_smbuf)[_SBFSIZ]; +extern void _getsmbuf(); + +void +setbuf(iop, buf) +register FILE *iop; +char *buf; +{ + register int fno = fileno(iop); /* file number */ + + if(iop->_base != NULL && iop->_flag & _IOMYBUF) + free((char*)iop->_base); + iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); + if((iop->_base = (unsigned char*)buf) == NULL) { + iop->_flag |= _IONBF; /* file unbuffered except in fastio */ + /* use small buffers reserved for this */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } + else /* regular buffered I/O, standard buffer size */ + iop->_bufsiz = BUFSIZ; + iop->_ptr = iop->_base; + iop->_cnt = 0; +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/sprintf.c b/usr/src/lib/libbc/libc/stdio/4.2/sprintf.c new file mode 100644 index 0000000000..37503be956 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/sprintf.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +char * +sprintf(string, format, va_alist) +char *string, *format; +va_dcl +{ + FILE siop; + va_list ap; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + va_start(ap); + (void) _doprnt(format, ap, &siop); + va_end(ap); + *siop._ptr = '\0'; /* plant terminating null character */ + return(string); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/vfprintf.c b/usr/src/lib/libbc/libc/stdio/4.2/vfprintf.c new file mode 100644 index 0000000000..e569706662 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/vfprintf.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +vfprintf(iop, format, ap) +FILE *iop; +char *format; +va_list ap; +{ + unsigned char localbuf[BUFSIZ]; + register int count; + + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + return(count); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/vprintf.c b/usr/src/lib/libbc/libc/stdio/4.2/vprintf.c new file mode 100644 index 0000000000..7fe56dba42 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/vprintf.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +vprintf(format, ap) +char *format; +va_list ap; +{ + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + return(_doprnt(format, ap, stdout)); +} diff --git a/usr/src/lib/libbc/libc/stdio/4.2/vsprintf.c b/usr/src/lib/libbc/libc/stdio/4.2/vsprintf.c new file mode 100644 index 0000000000..01cc261c02 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/4.2/vsprintf.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +char * +vsprintf(string, format, ap) +char *string, *format; +va_list ap; +{ + FILE siop; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + (void) _doprnt(format, ap, &siop); + *siop._ptr = '\0'; /* plant terminating null character */ + return(string); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/clrerr.c b/usr/src/lib/libbc/libc/stdio/common/clrerr.c new file mode 100644 index 0000000000..fcb8f0478e --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/clrerr.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#undef clearerr + +void +clearerr(iop) +register FILE *iop; +{ + iop->_flag &= ~(_IOERR | _IOEOF); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/ctermid.c b/usr/src/lib/libbc/libc/stdio/common/ctermid.c new file mode 100644 index 0000000000..23365e3a6a --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/ctermid.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern char *strcpy(); +static char res[L_ctermid]; + +char * +ctermid(s) +register char *s; +{ + return (strcpy(s != NULL ? s : res, "/dev/tty")); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/cuserid.c b/usr/src/lib/libbc/libc/stdio/common/cuserid.c new file mode 100644 index 0000000000..b33140d0b8 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/cuserid.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <pwd.h> + +extern char *strcpy(), *getlogin(); +extern int getuid(); +extern struct passwd *getpwuid(); +static char res[L_cuserid]; + +char * +cuserid(s) +char *s; +{ + register struct passwd *pw; + register char *p; + + if (s == NULL) + s = res; + p = getlogin(); + if (p != NULL) + return (strcpy(s, p)); + pw = getpwuid(getuid()); + endpwent(); + if (pw != NULL) + return (strcpy(s, pw->pw_name)); + *s = '\0'; + return (NULL); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/doprnt.c b/usr/src/lib/libbc/libc/stdio/common/doprnt.c new file mode 100644 index 0000000000..cc7324534c --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/doprnt.c @@ -0,0 +1,1279 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved + */ + +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * _doprnt: common code for printf, fprintf, sprintf + * Floating-point code is included or not, depending + * on whether the preprocessor variable FLOAT is 1 or 0. + */ +#define MAXARGS 50 +#ifndef FLOAT +#define FLOAT 1 /* YES! we want floating */ +#endif + +#include <stdio.h> +#include <ctype.h> +#include <varargs.h> +#include <values.h> +#include <locale.h> +#include "doprnt.h" +#include "stdiom.h" +#include <string.h> /* strchr, strlen, strspn */ + +#define max(a,b) ((a) > (b) ? (a) : (b)) +#define min(a,b) ((a) < (b) ? (a) : (b)) + +/* If this symbol is nonzero, allow '0' as a flag */ +/* If this symbol is nonzero, allow '0' as a flag */ +#define FZERO 1 + +#if FLOAT +/* + * libc/gen/common functions for floating-point conversion + */ +#include <floatingpoint.h> +extern void _fourdigitsquick(); +#endif + +void _mkarglst(); +void _getarg(); +static char *_check_dol(); + + +#define emitchar(c) { if (--filecnt < 0) { \ + register FILE *iop = file; \ + if (((iop->_flag & (_IOLBF|_IONBF)) == 0 \ + || -filecnt >= iop->_bufsiz)) { \ + iop->_ptr = fileptr; \ + if (iop->_flag & _IOSTRG) \ + return iop->_ptr - iop->_base; \ + else \ + (void) _xflsbuf(iop); \ + fileptr = iop->_ptr; \ + filecnt = iop->_cnt; \ + filecnt--; \ + } \ + } \ + *fileptr++ = (unsigned)(c); \ + count++; \ + } + +static char *nullstr = "(null)"; +static char *lowerhex = "0123456789abcdef"; +static char *upperhex = "0123456789ABCDEF"; + +/* stva_list is used to subvert C's restriction that a variable with an + * array type can not appear on the left hand side of an assignment operator. + * By putting the array inside a structure, the functionality of assigning to + * the whole array through a simple assignment is achieved.. +*/ +typedef struct stva_list { + va_list ap; +} stva_list; + +_doprnt(format, in_args, file) + char *format; + va_list in_args; + FILE *file; +{ + char convertbuffer[1024] ; + + /* Current position in format */ + register char *cp; + + /* Starting and ending points for value to be printed */ + register char *bp; + char *p; + + /* Pointer and count for I/O buffer */ + register unsigned char *fileptr; + register int filecnt; + + /* Field width and precision */ + int width; + register int prec; + + /* Format code */ + char fcode; + + /* Number of padding zeroes required on the left */ + int lzero; + + /* Flags - nonzero if corresponding character appears in format */ + bool fplus; /* + */ + bool fminus; /* - */ + bool fblank; /* blank */ + bool fsharp; /* # */ +#if FZERO + bool ansi_fzero; /* 0 for ansi-dictated formats */ + bool compat_fzero; /* 0 for backward compatibility */ +#endif + bool Lsize; /* Capital L for size = long double = quadruple */ + + /* Pointer to sign, "0x", "0X", or empty */ + char *prefix; + + /* Scratch */ + int nblank; + +#if FLOAT + /* Exponent or empty */ + char *suffix; + + /* Buffer to create exponent */ + char expbuf[7]; /* "e+xxxx\0" */ + + /* Number of padding zeroes required on the right */ + int rzero; + + /* Length of exponent suffix. */ + int suffixlength; + + /* The value being converted, if real or quadruple */ + double dval; + quadruple qval; + + /* Output values from fconvert and econvert */ + int decpt, sign; + + /* Values are developed in this buffer */ + char buf[1034]; /* Size of convertbuffer, plus some for exponent and sign. */ + + /* Current locale's decimal point */ + char decpt_char = *(localeconv()->decimal_point); + +#else + /* Values are developed in this buffer */ + char buf[MAXDIGS]; +#endif + + + /* The value being converted, if integer */ + register unsigned long val; + + /* Work variables */ + register int n; + register char c; + char radix; + int svswitch = 0; + /* count of output characters */ + register int count; + + /* variables for positional parameters */ + char *sformat = format; /* save the beginning of the format */ + int fpos = 1; /* 1 if first positional parameter */ + stva_list args, /* used to step through the argument list */ + args_width, /* for width */ + args_prec, /* for prec */ + sargs; /* used to save the start of the argument list */ + stva_list arglst[MAXARGS];/* array giving the approriate values + * for va_arg() to retrieve the + * corresponding argument: + * arglst[0] is the first argument + * arglst[1] is the second argument, etc. + */ + int index = 0; /* argument placeolder */ + /* Initialize args and sargs to the start of the argument list. + * Note that ANSI guarantees that the address of the first member of + * a structure will be the same as the address of the structure. */ + args_width = args_prec = args = sargs = *(struct stva_list *)&in_args; + + +/* initialize p an bp (starting and ending points) bugid 1141781 */ + + p = bp = NULL; + + cp = format; + if ((c = *cp++) != '\0') { + /* + * We know we're going to write something; make sure + * we can write and set up buffers, etc.. + */ + if (_WRTCHK(file)) + return(EOF); + } else + return(0); /* no fault, no error */ + + count = 0; + fileptr = file->_ptr; + filecnt = file->_cnt; + + /* + * The main loop -- this loop goes through one iteration + * for each ordinary character or format specification. + */ + do { + if (c != '%') { + /* Ordinary (non-%) character */ + emitchar(c); + } else { + /* + * % has been spotted! + * + * First, try the 99% cases. + * then parse the format specification. + * + * Note that this code assumes the Sun + * Workstation environment (all params + * passed as int == long, no interrupts + * for fixed point overflow from negating + * the most negative number). + */ + skipit: + switch(c = *cp++) { + + case 'l': + case 'h': + /* Quickly ignore long & short specifiers */ + goto skipit; + + case 's': + bp = va_arg(args.ap, char *); + if (bp == NULL) + bp = nullstr; + while (c = *bp++) + emitchar(c); + p = bp; + continue; + + case 'c': + c = va_arg(args.ap, int); + emitc: + emitchar(c); + continue; + + case 'i': + case 'd': + case 'D': + val = va_arg(args.ap, int); + if ((long) val < 0) { + emitchar('-'); + val = -val; + } + goto udcommon; + + case 'U': + case 'u': + val = va_arg(args.ap, unsigned); + udcommon: + { + register char *stringp = lowerhex; + bp = buf+MAXDIGS; + stringp = lowerhex; + do { + *--bp = stringp[val%10]; + val /= 10; + } while (val); + } + goto intout; + + case 'X': + { + register char *stringp = upperhex; + val = va_arg(args.ap, unsigned); + bp = buf + MAXDIGS; + if (val == 0) + goto zero; + while (val) { + *--bp = stringp[val%16]; + val /= 16; + } + } + goto intout; + + case 'x': + case 'p': + { + register char *stringp = lowerhex; + val = va_arg(args.ap, unsigned); + bp = buf + MAXDIGS; + if (val == 0) + goto zero; + while (val) { + *--bp = stringp[val%16]; + val /= 16; + } + } + goto intout; + + case 'O': + case 'o': + { + register char *stringp = lowerhex; + val = va_arg(args.ap, unsigned); + bp = buf + MAXDIGS; + if (val == 0) + goto zero; + while (val) { + *--bp = stringp[val%8]; + val /= 8; + } + } + /* Common code to output integers */ + intout: + p = buf + MAXDIGS; + while (bp < p) { + c = *bp++; + emitchar(c); + } + continue; + + zero: + c = '0'; + goto emitc; + + default: + /* + * let AT&T deal with it + */ + cp-= 2; + } + + Lsize = 0; /* Not long double unless we say so. */ + /* Scan the <flags> */ + fplus = 0; + fminus = 0; + fblank = 0; + fsharp = 0; +#if FZERO + ansi_fzero = 0; + compat_fzero = 0; +#endif + scan: switch (*++cp) { + case '+': + fplus = 1; + goto scan; + case '-': + fminus = 1; + goto scan; + case ' ': + fblank = 1; + goto scan; + case '#': + fsharp = 1; + goto scan; +#if FZERO + case '0': + ansi_fzero = 1; + compat_fzero = 1; + goto scan; +#endif + } + + /* Scan the field width */ + if (*cp == '*') { + char *p; + int val; + + p = _check_dol(cp+1, &val); + if (p != (char *)NULL) { + /* + * argument re-order + */ + if (fpos) { + _mkarglst(sformat, sargs, arglst); + fpos = 0; + } + if (val <= MAXARGS) { + args_width = arglst[val - 1]; + } else { + args_width = arglst[MAXARGS - 1]; + _getarg(sformat, &args_width, val); + } + width = va_arg(args_width.ap, int); + if (width < 0) { + width = -width; + fminus = 1; + } + cp = p; + } + else { + width = va_arg(args.ap, int); + if (width < 0) { + width = -width; + fminus = 1; + } + cp++; + } + } else { + index = width = 0; + while (isdigit(*cp)) { + n = tonumber(*cp++); + index = width = width * 10 + n; + } + } + + /* Scan the precision */ + if (*cp == '.') { + + /* '*' instead of digits? */ + if (*++cp == '*') { + char *p; + int val; + + p = _check_dol(cp+1, &val); + if (p != (char *)NULL) { + /* + * argument re-order + */ + if (fpos) { + _mkarglst(sformat, sargs, arglst); + fpos = 0; + } + if (val <= MAXARGS) { + args_prec = arglst[val - 1]; + } else { + args_prec = arglst[MAXARGS - 1]; + _getarg(sformat, &args_prec, val); + } + prec = va_arg(args_prec.ap, int); + cp = p; + } + else { + prec = va_arg(args.ap, int); + cp++; + } + } else { + prec = 0; + while (isdigit(*cp)) { + n = tonumber(*cp++); + prec = prec * 10 + n; + } + } + } else + prec = -1; + + if (*cp == '$') { + if (fpos) { + _mkarglst(sformat, sargs, arglst); + fpos = 0; + } + if (index <= MAXARGS) { + args = arglst[index - 1]; + } else { + args = arglst[MAXARGS - 1]; + _getarg(sformat, &args, index); + } + goto scan; + } + /* + * The character addressed by cp must be the + * format letter -- there is nothing left for + * it to be. + * + * The status of the +, -, #, blank, and 0 + * flags are reflected in the variables + * "fplus", "fminus", "fsharp", "fblank", + * and "ansi_fzero"/"compat_fzero", respectively. + * "width" and "prec" contain numbers + * corresponding to the digit strings + * before and after the decimal point, + * respectively. If there was no decimal + * point, "prec" is -1. + * + * The following switch sets things up + * for printing. What ultimately gets + * printed will be padding blanks, a prefix, + * left padding zeroes, a value, right padding + * zeroes, a suffix, and more padding + * blanks. Padding blanks will not appear + * simultaneously on both the left and the + * right. Each case in this switch will + * compute the value, and leave in several + * variables the information necessary to + * construct what is to be printed. + * + * The prefix is a sign, a blank, "0x", "0X", + * or null, and is addressed by "prefix". + * + * The suffix is either null or an exponent, + * and is addressed by "suffix". + * + * The value to be printed starts at "bp" + * and continues up to and not including "p". + * + * "lzero" and "rzero" will contain the number + * of padding zeroes required on the left + * and right, respectively. If either of + * these variables is negative, it will be + * treated as if it were zero. + * + * The number of padding blanks, and whether + * they go on the left or the right, will be + * computed on exit from the switch. + */ + + lzero = 0; + prefix = ""; +#if FLOAT + rzero = 0; + suffix = prefix; +#endif + +#if FZERO + /* if both zero-padding and left-justify flags + * are used, ignore zero-padding, per ansi c + */ + if (ansi_fzero & fminus) { + ansi_fzero = 0; + compat_fzero = 0; + } + + /* if zero-padding and precision are specified, + * ignore zero-padding for ansi-dictated formats, + * per ansi c + */ + if (ansi_fzero & (prec != -1)) ansi_fzero = 0; +#endif + + next: + switch (fcode = *cp++) { + + /* toss the length modifier, if any */ + case 'l': + case 'h': + goto next; + + case 'L': + Lsize = 1; /* Remember long double size. */ + goto next; + + /* + * fixed point representations + * + * "radix" is the radix for the conversion. + * Conversion is unsigned unless fcode is 'd'. + * We assume a 2's complement machine and + * that fixed point overflow (from negating + * the largest negative int) is ignored. + */ + + case 'i': + case 'D': + case 'U': + case 'd': + case 'u': + radix = 10; + goto fixed; + + case 'O': + case 'o': + radix = 8; + goto fixed; + + case 'X': + case 'x': + radix = 16; + + fixed: + /* Establish default precision */ + if (prec < 0) + prec = 1; + + /* Fetch the argument to be printed */ + val = va_arg(args.ap, unsigned); + + /* If signed conversion, establish sign */ + if (fcode == 'd' || fcode == 'D' || fcode == 'i') { + if ((long) val < 0) { + prefix = "-"; + val = -val; + } else if (fplus) + prefix = "+"; + else if (fblank) + prefix = " "; + } + /* Set translate table for digits */ + { + register char *stringp; + if (fcode == 'X') + stringp = upperhex; + else + stringp = lowerhex; + + /* Develop the digits of the value */ + bp = buf + MAXDIGS; + switch(radix) { + case 8: /*octal*/ + while (val) { + *--bp = stringp[val%8]; + val /= 8; + } + break; + case 16:/*hex*/ + while (val) { + *--bp = stringp[val%16]; + val /= 16; + } + break; + default: + while (val) { + *--bp = stringp[val%10]; + val /= 10; + } + break; + } /* switch */ + } + + /* Calculate padding zero requirement */ + p = buf + MAXDIGS; + + /* Handle the # flag */ + if (fsharp && bp != p) { + switch (fcode) { + case 'x': + prefix = "0x"; + break; + case 'X': + prefix = "0X"; + break; + } + } +#if FZERO + if (ansi_fzero) { + n = width - strlen(prefix); + if (n > prec) + prec = n; + } +#endif + lzero = bp - p + prec; + + /* Handle the # flag for 'o' */ + if (fsharp && bp != p && fcode == 'o' && + lzero < 1) { + lzero = 1; + } + break; +#if FLOAT + +#ifdef sparc +#define GETQVAL /* Sun-4 macro to get a quad q from the argument list, passed as a pointer. */ \ + { qval = *(va_arg(args.ap, quadruple*)) ; } +#else +#define GETQVAL /* Sun-3 macro to get a quad q from the argument list, passed as a value. */ \ + { int iq ; unsigned long * pl = (unsigned long *) (&qval) ; for(iq=0;iq<4;iq++) pl[iq] = (unsigned long) va_arg(args.ap, unsigned long) ; } +#endif + + case 'E': + case 'e': + /* + * E-format. The general strategy + * here is fairly easy: we take + * what econvert gives us and re-format it. + */ + + /* Establish default precision */ + if (prec < 0) + prec = 6; + + /* Fetch the value */ + if (Lsize == 0) { /* Double */ + dval = va_arg(args.ap, double); + bp = econvert(dval, prec + 1, &decpt, &sign, convertbuffer); + } else { /* Long Double = quadruple */ + GETQVAL; + bp = qeconvert(&qval, prec + 1, &decpt, &sign, convertbuffer); + } + + /* Determine the prefix */ + if (sign) + prefix = "-"; + else if (fplus) + prefix = "+"; + else if (fblank) + prefix = " "; + if (convertbuffer[0] > '9') + { /* handle infinity, nan */ + bp = &convertbuffer[0]; + for (p = bp+1 ; *p != 0 ; p++) ; + goto ebreak ; + } + { + register char *stringp; + /* Place the first digit in the buffer */ + stringp = &buf[0]; + *stringp++ = *bp != '\0'? *bp++: '0'; + + /* Put in a decimal point if needed */ + if (prec != 0 || fsharp) + *stringp++ = decpt_char; + + /* Create the rest of the mantissa */ + rzero = prec; + while (rzero > 0 && *bp!= '\0') { + --rzero; + *stringp++ = *bp++; + } + p = stringp; + } + + bp = &buf[0]; + + /* Create the exponent */ + if (convertbuffer[0] != '0') + n = decpt - 1; + else + n = 0 ; + if (n < 0) + n = -n; + _fourdigitsquick( (short unsigned) n, &(expbuf[2]) ) ; + expbuf[6] = 0 ; + if (n < 100) + /* + * Normally two digit exponent field, + * three or four if required. + */ + { suffix = &(expbuf[4]) ; suffixlength = 4 ; } + else if (n < 1000) + { suffix = &(expbuf[3]) ; suffixlength = 5 ; } + else + { suffix = &(expbuf[2]) ; suffixlength = 6 ; } + /* Put in the exponent sign */ + *--suffix = (decpt > 0 || convertbuffer[0] == '0' )? '+': '-'; + + /* Put in the e; note kludge in 'g' format */ + *--suffix = fcode; +ebreak: +#if FZERO + if (compat_fzero &! fminus) + /* Calculate padding zero requirement */ + lzero = width - (strlen(prefix) + + (p - buf) + rzero + suffixlength); +#endif + break; + + case 'f': + /* + * F-format floating point. This is + * a good deal less simple than E-format. + * The overall strategy will be to call + * fconvert, reformat its result into buf, + * and calculate how many trailing + * zeroes will be required. There will + * never be any leading zeroes needed. + */ + + /* Establish default precision */ + if (prec < 0) + prec = 6; + + if (Lsize == 0) { + dval = va_arg(args.ap, double); + bp = fconvert(dval, prec, &decpt, &sign, convertbuffer); + } else { + GETQVAL ; + bp = qfconvert(&qval, prec, &decpt, &sign, convertbuffer); + } + + /* Determine the prefix */ + if (sign) + prefix = "-"; + else if (fplus) + prefix = "+"; + else if (fblank) + prefix = " "; + if (convertbuffer[0] > '9') + { /* handle infinity, nan */ + bp = &convertbuffer[0]; + for (p = bp+1 ; *p != 0 ; p++) ; + goto fbreak ; + } + { + register char *stringp; + /* Initialize buffer pointer */ + stringp = &buf[0]; + + /* Emit the digits before the decimal point */ + n = decpt; + if (n <= 0) + *stringp++ = '0'; + else + do + if (*bp == '\0' ) + *stringp++ = '0'; + else { + *stringp++ = *bp++; + } + while (--n != 0); + + /* Decide whether we need a decimal point */ + if (fsharp || prec > 0) + *stringp++ = decpt_char; + + /* Digits(if any) after the decimal point */ + n = prec; + rzero = prec - n; + while (--n >= 0) { + if (++decpt <= 0 || *bp == '\0') + *stringp++ = '0'; + else { + *stringp++ = *bp++; + } + } +#if FZERO + if (compat_fzero &! fminus) + /* Calculate padding zero requirement */ + lzero = width - (strlen(prefix) + + (stringp - buf) + rzero); +#endif + p = stringp; + } + + bp = &buf[0]; +fbreak: + break; + + case 'G': + case 'g': + /* + * g-format. We play around a bit + * and then jump into e or f, as needed. + */ + + /* Establish default precision */ + if (prec < 0) + prec = 6; + else if (prec == 0) + prec = 1; + + if (Lsize == 0) { + dval = va_arg(args.ap, double); + bp = gconvert(dval, prec, fsharp, convertbuffer); + } else { + GETQVAL; + bp = qgconvert(&qval, prec, fsharp, convertbuffer); + } + bp = convertbuffer ; + if (convertbuffer[0] == '-') { + prefix = "-" ; + bp++; + } + else if (fplus) + prefix = "+"; + else if (fblank) + prefix = " "; + if (isupper(fcode)) + { /* Put in a big E for small minds. */ + for (p = bp ; (*p != NULL) && (*p != 'e') ; p++) ; + if (*p == 'e') *p = 'E' ; + for (; (*p != NULL) ; p++) ; + /* Find end of string. */ + } + else + for (p = bp ; *p != NULL ; p++) ; + /* Find end of string. */ + rzero = 0; +#if FZERO + if (compat_fzero & !fminus) + /* Calculate padding zero requirement */ + lzero = width - (strlen(prefix) + + (p - bp) + rzero); +#endif + break ; + +#endif + case 'c': + buf[0] = va_arg(args.ap, int); + bp = &buf[0]; + p = bp + 1; + break; + + case 's': + bp = va_arg(args.ap, char *); + if (prec < 0) + prec = MAXINT; + /* avoid *(0) */ + if (bp == NULL) + bp = nullstr; + for (n=0; *bp++ != '\0' && n < prec; n++) + ; +#if FZERO + if (compat_fzero &! fminus) + lzero = width - n; +#endif + p = --bp; + bp -= n; + break; + + case '\0': + /* well, what's the punch line? */ + goto out; + + case 'n': + svswitch = 1; + break; + default: + p = bp = &fcode; + p++; + break; + + } + /* Calculate number of padding blanks */ + nblank = width +#if FLOAT + - (rzero < 0? 0: rzero) + - strlen(suffix) +#endif + - (p - bp) + - (lzero < 0? 0: lzero) + - strlen(prefix); + + /* Blanks on left if required */ + if (!fminus) + while (--nblank >= 0) + emitchar(' '); + + /* Prefix, if any */ + while (*prefix != '\0') { + emitchar(*prefix); + prefix++; + } + + /* Zeroes on the left */ + while (--lzero >= 0) + emitchar('0'); + + /* The value itself */ + while (bp < p) { + emitchar(*bp); + bp++; + } +#if FLOAT + /* Zeroes on the right */ + while (--rzero >= 0) + emitchar('0'); + + /* The suffix */ + while (*suffix != '\0') { + emitchar(*suffix); + suffix++; + } +#endif + /* Blanks on the right if required */ + if (fminus) + while (--nblank >= 0) + emitchar(' '); + /* If %n is seen, save count in argument */ + if (svswitch == 1) { + long *svcount; + svcount = va_arg (args.ap, long *); + *svcount = count; + svswitch = 0; + } + } /* else */ + } while ((c = *cp++) != '\0'); /* do */ +out: + file->_ptr = fileptr; + file->_cnt = filecnt; + if (file->_flag & (_IONBF | _IOLBF) && + (file->_flag & _IONBF || + memchr((char *)file->_base, '\n', fileptr - file->_base) != NULL)) + (void) _xflsbuf(file); + return (ferror(file)? EOF: count); +} + +#ifdef sparc +/* + * We use "double *" instead of "quadruple *" to skip over the pointer to + * long double on the argument list since a pointer is a pointer after all. + */ +#define SKIPQVAL { \ + (void) va_arg(args.ap, double *); \ +} +#else /* Sun-3 */ +#define SKIPQVAL { \ + int iq; \ + for (iq = 0; iq < 4; iq++) \ + (void) va_arg(args.ap, unsigned long); \ +} +#endif +/* This function initializes arglst, to contain the appropriate va_list values + * for the first MAXARGS arguments. */ +void +_mkarglst(fmt, args, arglst) +char *fmt; +stva_list args; +stva_list arglst[]; +{ + static char *digits = "01234567890", *skips = "# +-.0123456789h$"; + + enum types {INT = 1, LONG, CHAR_PTR, DOUBLE, LONG_DOUBLE, VOID_PTR, + LONG_PTR, INT_PTR}; + enum types typelst[MAXARGS], curtype; + int maxnum, n, curargno, flags; + + /* + * Algorithm 1. set all argument types to zero. + * 2. walk through fmt putting arg types in typelst[]. + * 3. walk through args using va_arg(args.ap, typelst[n]) + * and set arglst[] to the appropriate values. + * Assumptions: Cannot use %*$... to specify variable position. + */ + + (void)memset((void *)typelst, 0, sizeof(typelst)); + maxnum = -1; + curargno = 0; + while ((fmt = strchr(fmt, '%')) != 0) + { + fmt++; /* skip % */ + if (fmt[n = strspn(fmt, digits)] == '$') + { + curargno = atoi(fmt) - 1; /* convert to zero base */ + fmt += n + 1; + } + flags = 0; + again:; + fmt += strspn(fmt, skips); + switch (*fmt++) + { + case '%': /*there is no argument! */ + continue; + case 'l': + flags |= 0x1; + goto again; + case 'L': + flags |= 0x8; + goto again; + case '*': /* int argument used for value */ + flags |= 0x2; + curtype = INT; + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (flags & 0x8) + curtype = LONG_DOUBLE; + else + curtype = DOUBLE; + break; + case 's': + curtype = CHAR_PTR; + break; + case 'p': + curtype = VOID_PTR; + break; + case 'n': + if (flags & 0x1) + curtype = LONG_PTR; + else + curtype = INT_PTR; + break; + default: + if (flags & 0x1) + curtype = LONG; + else + curtype = INT; + break; + } + if (curargno >= 0 && curargno < MAXARGS) + { + typelst[curargno] = curtype; + if (maxnum < curargno) + maxnum = curargno; + } + curargno++; /* default to next in list */ + if (flags & 0x2) /* took care of *, keep going */ + { + flags ^= 0x2; + goto again; + } + } + for (n = 0 ; n <= maxnum; n++) + { + arglst[n] = args; + if (typelst[n] == 0) + typelst[n] = INT; + + switch (typelst[n]) + { + case INT: + va_arg(args.ap, int); + break; + case LONG: + va_arg(args.ap, long); + break; + case CHAR_PTR: + va_arg(args.ap, char *); + break; + case DOUBLE: + va_arg(args.ap, double); + break; + case LONG_DOUBLE: + SKIPQVAL + break; + case VOID_PTR: + va_arg(args.ap, void *); + break; + case LONG_PTR: + va_arg(args.ap, long *); + break; + case INT_PTR: + va_arg(args.ap, int *); + break; + } + } +} + +/* + * This function is used to find the va_list value for arguments whose + * position is greater than MAXARGS. This function is slow, so hopefully + * MAXARGS will be big enough so that this function need only be called in + * unusual circumstances. + * pargs is assumed to contain the value of arglst[MAXARGS - 1]. + */ +void +_getarg(fmt, pargs, argno) +char *fmt; +stva_list *pargs; +int argno; +{ + static char *digits = "01234567890", *skips = "# +-.0123456789h$"; + int i, n, curargno, flags; + char *sfmt = fmt; + int found = 1; + + curargno = i = MAXARGS; + while (found) + { + fmt = sfmt; + found = 0; + while ((i != argno) && (fmt = strchr(fmt, '%')) != 0) + { + fmt++; /* skip % */ + if (fmt[n = strspn(fmt, digits)] == '$') + { + curargno = atoi(fmt); + fmt += n + 1; + } + + /* find conversion specifier for next argument */ + if (i != curargno) + { + curargno++; + continue; + } else + found = 1; + flags = 0; + again:; + fmt += strspn(fmt, skips); + switch (*fmt++) + { + case '%': /*there is no argument! */ + continue; + case 'l': + flags |= 0x1; + goto again; + case 'L': + flags |= 0x8; + goto again; + case '*': /* int argument used for value */ + flags |= 0x2; + (void)va_arg((*pargs).ap, int); + break; + case 'e': + case 'E': + case 'f': + case 'g': + case 'G': + if (flags & 0x8) { +#define args (*pargs) + SKIPQVAL +#undef args + } + else + (void)va_arg((*pargs).ap, double); + break; + case 's': + (void)va_arg((*pargs).ap, char *); + break; + case 'p': + (void)va_arg((*pargs).ap, void *); + break; + case 'n': + if (flags & 0x1) + (void)va_arg((*pargs).ap, long *); + else + (void)va_arg((*pargs).ap, int *); + break; + default: + if (flags & 0x1) + (void)va_arg((*pargs).ap, long int); + else + (void)va_arg((*pargs).ap, int); + break; + } + i++; + curargno++; /* default to next in list */ + if (flags & 0x2) /* took care of *, keep going */ + { + flags ^= 0x2; + goto again; + } + } + + /* missing specifier for parameter, assume parameter is an int */ + if (!found && i != argno) { + (void)va_arg((*pargs).ap, int); + i++; + curargno++; + found = 1; + } + } +} + + +/* + * parse a string, mini parse + */ +static char * +_check_dol(s, val) + char *s; + int *val; +{ + char *os; /* save old string */ + int tmp_val = 0; + int flag = 0; + + while (isdigit (*s)) { + ++flag; + tmp_val = tmp_val*10 + *s - '0'; + s++; + } + if (flag == 0) + return ((char *)NULL); + if (*s == '$') { + *val = tmp_val; + return(++s); + } + return ((char *)NULL); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/doprnt.h b/usr/src/lib/libbc/libc/stdio/common/doprnt.h new file mode 100644 index 0000000000..68c4e5d06e --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/doprnt.h @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* Maximum number of digits in any integer (long) representation */ +#define MAXDIGS 11 + +/* Convert a digit character to the corresponding number */ +#define tonumber(x) ((x)-'0') + +/* Convert a number between 0 and 9 to the corresponding digit */ +#define todigit(x) ((x)+'0') + +/* Data type for flags */ +typedef char bool; diff --git a/usr/src/lib/libbc/libc/stdio/common/doscan.c b/usr/src/lib/libbc/libc/stdio/common/doscan.c new file mode 100644 index 0000000000..45ba3cb308 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/doscan.c @@ -0,0 +1,513 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1988-1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <ctype.h> +#include <varargs.h> +#include <values.h> +#include <floatingpoint.h> +#include <errno.h> + +#define NCHARS (1 << BITSPERBYTE) +#define locgetc() (chcount+=1,getc(iop)) +#define locungetc(x) (chcount-=1,ungetc(x,iop)) + +extern char *memset(); +static int chcount,flag_eof; + +#ifdef S5EMUL +#define isws(c) isspace(c) +#else +/* + * _sptab[c+1] is 1 iff 'c' is a white space character according to the + * 4.2BSD "scanf" definition - namely, SP, TAB, and NL are the only + * whitespace characters. + */ +static char _sptab[1+256] = { + 0, /* EOF - not a whitespace char */ + 0,0,0,0,0,0,0,0, + 0,1,1,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 1,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, +}; + +#define isws(c) ((_sptab + 1)[c] != 0) +#endif + +int +_doscan(iop, fmt, va_alist) +register FILE *iop; +register unsigned char *fmt; +va_list va_alist; +{ + extern unsigned char *setup(); + char tab[NCHARS]; + register int ch; + int nmatch = 0, len, inchar, stow, size; + chcount=0; flag_eof=0; + + /******************************************************* + * Main loop: reads format to determine a pattern, + * and then goes to read input stream + * in attempt to match the pattern. + *******************************************************/ + for ( ; ; ) + { + if ( (ch = *fmt++) == '\0') + return(nmatch); /* end of format */ + if (isws(ch)) + { + if (!flag_eof) + { + while (isws(inchar = locgetc())) + ; + if (inchar == EOF) { + chcount--; + flag_eof = 1; + } + else if (locungetc(inchar) == EOF) + flag_eof = 1; + } + continue; + } + if (ch != '%' || (ch = *fmt++) == '%') + { + if ( (inchar = locgetc()) == ch ) + continue; + if (inchar != EOF) { + if (locungetc(inchar) != EOF) + return(nmatch); /* failed to match input */ + } else { + chcount--; + } + break; + } + if (ch == '*') + { + stow = 0; + ch = *fmt++; + } + else + stow = 1; + + for (len = 0; isdigit(ch); ch = *fmt++) + len = len * 10 + ch - '0'; + if (len == 0) + len = MAXINT; + if ( (size = ch) == 'l' || (size == 'h') || (size == 'L') ) + ch = *fmt++; + if (ch == '\0' || + ch == '[' && (fmt = setup(fmt, tab)) == NULL) + return(EOF); /* unexpected end of format */ + if (isupper(ch)) /* no longer documented */ + { + /* + * The rationale behind excluding the size + * of 'L' is that the 'L' size specifier was + * introduced in ANSI/ISO-C. If the user + * specifies a format of %LG, it can mean + * nothing other than "long double", be the + * code ANSI or not. Mapping it to "double" + * makes no sense. + */ + if (size != 'L') + size = 'l'; +#ifdef S5EMUL + ch = _tolower(ch); +#else + ch = tolower(ch); +#endif + } + switch(ch) + { + case 'c': + case 's': + case '[': + if ((size = string(stow,ch,len,tab,iop,&va_alist)) < 0) + goto out; /* EOF seen, nothing converted */ + break; + case 'n': + if (stow == 0) + continue; + if (size == 'h') + *va_arg(va_alist, short *) = (short) chcount; + else if (size == 'l') + *va_arg(va_alist, long *) = (long) chcount; + else + *va_arg(va_alist, int *) = (int) chcount; + continue; + default: + if ((size = number(stow, ch, len, size, iop, &va_alist)) < 0) + goto out; /* EOF seen, nothing converted */ + break; + } + if (size) + nmatch += stow; + else + return((flag_eof && !nmatch) ? EOF : nmatch); + continue; + } +out: + return (nmatch != 0 ? nmatch : EOF); /* end of input */ +} + +/*************************************************************** + * Functions to read the input stream in an attempt to match incoming + * data to the current pattern from the main loop of _doscan(). + ***************************************************************/ +static int +number(stow, type, len, size, iop, listp) +int stow, type, len, size; +register FILE *iop; +va_list *listp; +{ + char numbuf[64], inchar, lookahead; + register char *np = numbuf; + register int c, base; + int digitseen = 0, floater = 0, negflg = 0; + long lcval = 0; + switch(type) + { + case 'e': + case 'f': + case 'g': + floater++; + case 'd': + case 'u': + case 'i': + base = 10; + break; + case 'o': + base = 8; + break; + case 'x': + base = 16; + break; + default: + return(0); /* unrecognized conversion character */ + } + if (!flag_eof) + { + while (isws(c = locgetc())) + ; + } + else + c = locgetc(); + if (c == EOF) { + chcount--; + return(-1); /* EOF before match */ + } + if (floater != 0) { /* Handle floating point with + * file_to_decimal. */ + decimal_mode dm; + decimal_record dr; + fp_exception_field_type efs; + enum decimal_string_form form; + char *echar; + int nread, ic; + char buffer[1024]; + char *nb = buffer; + + locungetc(c); + if (len > 1024) + len = 1024; + file_to_decimal(&nb, len, 0, &dr, &form, &echar, iop, &nread); + if (stow && (form != invalid_form)) { + dm.rd = fp_direction; + if (size == 'l') { /* double */ + decimal_to_double((double *) va_arg(*listp, double *), &dm, &dr, &efs); + } else if (size == 'L') { /* quad */ + decimal_to_quadruple((quadruple *)va_arg(*listp, double *), &dm, &dr, &efs); + } else {/* single */ + decimal_to_single((float *) va_arg(*listp, float *), &dm, &dr, &efs); + } + if ((efs & (1 << fp_overflow)) != 0) { + errno = ERANGE; + } + if ((efs & (1 << fp_underflow)) != 0) { + errno = ERANGE; + } + } + chcount += nread; /* Count characters read. */ + c = *nb; /* Get first unused character. */ + ic = c; + if (c == NULL) { + ic = locgetc(); + c = ic; + /* + * If null, first unused may have been put back + * already. + */ + } + if (ic == EOF) { + chcount--; + flag_eof = 1; + } else if (locungetc(c) == EOF) + flag_eof = 1; + return ((form == invalid_form) ? 0 : 1); /* successful match if + * non-zero */ + } + switch(c) { + case '-': + negflg++; + if (type == 'u') + break; + case '+': /* fall-through */ + if (--len <= 0) + break; + if ( (c = locgetc()) != '0') + break; + case '0': + if ( (type != 'i') || (len <= 1) ) + break; + if ( ((inchar = locgetc()) == 'x') || (inchar == 'X') ) + { + /* If not using sscanf and * + * at the buffer's end * + * then LOOK ahead */ + + if ( (iop->_flag & _IOSTRG) || (iop->_cnt != 0) ) + lookahead = locgetc(); + else + { + if ( read(fileno(iop),np,1) == 1) + lookahead = *np; + else + lookahead = EOF; + chcount += 1; + } + if ( isxdigit(lookahead) ) + { + base =16; + + if ( len <= 2) + { + locungetc(lookahead); + len -= 1; /* Take into account the 'x'*/ + } + else + { + c = lookahead; + len -= 2; /* Take into account '0x'*/ + } + } + else + { + locungetc(lookahead); + locungetc(inchar); + } + } + else + { + locungetc(inchar); + base = 8; + } + } + if (!negflg || type != 'u') + for (; --len >= 0 ; *np++ = c, c = locgetc()) + { + if (np > numbuf + 62) + { + errno = ERANGE; + return(0); + } + if (isdigit(c)) + { + register int digit; + digit = c - '0'; + if (base == 8) + { + if (digit >= 8) + break; + if (stow) + lcval = (lcval<<3) + digit; + } + else + { + if (stow) + { + if (base == 10) + lcval = (((lcval<<2) + lcval)<<1) + digit; + else /* base == 16 */ + lcval = (lcval<<4) + digit; + } + } + digitseen++; + + + continue; + } + else if (base == 16 && isxdigit(c)) + { + register int digit; + digit = c - (isupper(c) ? 'A' - 10 : 'a' - 10); + if (stow) + lcval = (lcval<<4) + digit; + digitseen++; + continue; + } + break; + } + + + if (stow && digitseen) + { + /* suppress possible overflow on 2's-comp negation */ + if (negflg && lcval != HIBITL) + lcval = -lcval; + if (size == 'l') + *va_arg(*listp, long *) = lcval; + else if (size == 'h') + *va_arg(*listp, short *) = (short)lcval; + else + *va_arg(*listp, int *) = (int)lcval; + } + if (c == EOF) { + chcount--; + flag_eof=1; + } else if (locungetc(c) == EOF) + flag_eof=1; + return (digitseen); /* successful match if non-zero */ +} + +static int +string(stow, type, len, tab, iop, listp) +register int stow, type, len; +register char *tab; +register FILE *iop; +va_list *listp; +{ + register int ch; + register char *ptr; + char *start; + + start = ptr = stow ? va_arg(*listp, char *) : NULL; + if (type == 's') + { + if (!flag_eof) + { + while (isws(ch = locgetc())) + ; + } + else + ch = locgetc(); + if (ch == EOF) + return(-1); /* EOF before match */ + while (ch != EOF && !isws(ch)) + { + if (stow) + *ptr = ch; + ptr++; + if (--len <= 0) + break; + ch = locgetc(); + } + } else if (type == 'c') { + if (len == MAXINT) + len = 1; + while ( (ch = locgetc()) != EOF) + { + if (stow) + *ptr = ch; + ptr++; + if (--len <= 0) + break; + } + } else { /* type == '[' */ + while ( (ch = locgetc()) != EOF && !tab[ch]) + { + if (stow) + *ptr = ch; + ptr++; + if (--len <= 0) + break; + } + } + if (ch == EOF ) + { + chcount-=1; + flag_eof = 1; + } + else if (len > 0 && locungetc(ch) == EOF) + flag_eof = 1; + if (ptr == start) + return(0); /* no match */ + if (stow && type != 'c') + *ptr = '\0'; + return (1); /* successful match */ +} + +static unsigned char * +setup(fmt, tab) +register unsigned char *fmt; +register char *tab; +{ + register int b, c, d, t = 0; + + if (*fmt == '^') + { + t++; + fmt++; + } + (void) memset(tab, !t, NCHARS); + if ( (c = *fmt) == ']' || c == '-') /* first char is special */ + { + tab[c] = t; + fmt++; + } + while ( (c = *fmt++) != ']') + { + if (c == '\0') + return(NULL); /* unexpected end of format */ + if (c == '-' && (d = *fmt) != ']' && (b = fmt[-2]) < d) + { + (void) memset(&tab[b], t, d - b + 1); + fmt++; + } + else + tab[c] = t; + } + return (fmt); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fdopen.c b/usr/src/lib/libbc/libc/stdio/common/fdopen.c new file mode 100644 index 0000000000..a225c02b45 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fdopen.c @@ -0,0 +1,89 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.4 */ + +/*LINTLIBRARY*/ +/* + * Unix routine to do an "fopen" on file descriptor + * The mode has to be repeated because you can't query its + * status + */ + +#include <stdio.h> +#include <sys/errno.h> + +extern int errno; +extern long lseek(); +extern FILE *_findiop(); + +FILE * +fdopen(fd, mode) +int fd; +register char *mode; +{ + static int nofile = -1; + register FILE *iop; + + if(nofile < 0) + nofile = getdtablesize(); + + if(fd < 0 || fd >= nofile) { + errno = EINVAL; + return(NULL); + } + + if((iop = _findiop()) == NULL) + return(NULL); + + iop->_cnt = 0; + iop->_file = fd; + iop->_base = iop->_ptr = NULL; + iop->_bufsiz = 0; + switch(*mode) { + + case 'r': + iop->_flag = _IOREAD; + break; + case 'a': + (void) lseek(fd, 0L, 2); + /* No break */ + case 'w': + iop->_flag = _IOWRT; + break; + default: + errno = EINVAL; + return(NULL); + } + + if(mode[1] == '+') + iop->_flag = _IORW; + + return(iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/feof.c b/usr/src/lib/libbc/libc/stdio/common/feof.c new file mode 100644 index 0000000000..9bbaeded9b --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/feof.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + + +/*LINTLIBRARY*/ +#include <stdio.h> + +#undef feof +#define __feof__(p) (((p)->_flag&_IOEOF)!=0) + +int +feof(fp) +register FILE *fp; +{ + return (__feof__(fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/ferror.c b/usr/src/lib/libbc/libc/stdio/common/ferror.c new file mode 100644 index 0000000000..4c0b69e3b9 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/ferror.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> + +#undef ferror +#define __ferror__(p) (((p)->_flag&_IOERR)!=0) + +int +ferror(fp) +register FILE *fp; +{ + return (__ferror__(fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fgetc.c b/usr/src/lib/libbc/libc/stdio/common/fgetc.c new file mode 100644 index 0000000000..8ed7c98f0b --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fgetc.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +int +fgetc(fp) +register FILE *fp; +{ + return(getc(fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fgets.c b/usr/src/lib/libbc/libc/stdio/common/fgets.c new file mode 100644 index 0000000000..d6cfb55466 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fgets.c @@ -0,0 +1,82 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 3.3 */ + +/*LINTLIBRARY*/ +/* + * This version reads directly from the buffer rather than looping on getc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + */ +#include <stdio.h> +#include "stdiom.h" + +#define MIN(x, y) (x < y ? x : y) + +extern int _filbuf(); +extern char *memccpy(); + +char * +fgets(ptr, size, iop) +char *ptr; +register int size; +register FILE *iop; +{ + char *p, *ptr0 = ptr; + register int n; + + if ( !(iop->_flag & (_IOREAD|_IORW)) ) { + iop->_flag |= _IOERR; + return (NULL); + } + + for (size--; size > 0; size -= n) { + if (iop->_cnt <= 0) { /* empty buffer */ + if (_filbuf(iop) == EOF) { + if (ptr0 == ptr) + return (NULL); + break; /* no more data */ + } + iop->_ptr--; + iop->_cnt++; + } + n = MIN(size, iop->_cnt); + if ((p = memccpy(ptr, (char *) iop->_ptr, '\n', n)) != NULL) + n = p - ptr; + ptr += n; + iop->_cnt -= n; + iop->_ptr += n; + _BUFSYNC(iop); + if (p != NULL) + break; /* found '\n' in buffer */ + } + *ptr = '\0'; + return (ptr0); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fileno.c b/usr/src/lib/libbc/libc/stdio/common/fileno.c new file mode 100644 index 0000000000..5d91655a26 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fileno.c @@ -0,0 +1,32 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> + +int +fileno(fp) +register FILE *fp; +{ + return (fp->_file); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/findiop.c b/usr/src/lib/libbc/libc/stdio/common/findiop.c new file mode 100644 index 0000000000..a8175927f0 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/findiop.c @@ -0,0 +1,144 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <errno.h> +#include "iob.h" + +#define active(iop) ((iop)->_flag & (_IOREAD|_IOWRT|_IORW)) + +extern char *calloc(); + +static unsigned char sbuf[NSTATIC][_SBFSIZ]; +unsigned char (*_smbuf)[_SBFSIZ] = sbuf; +static FILE **iobglue; +static FILE **endglue; + +/* + * Find a free FILE for fopen et al. + * We have a fixed static array of entries, and in addition + * may allocate additional entries dynamically, up to the kernel + * limit on the number of open files. + * At first just check for a free slot in the fixed static array. + * If none are available, then we allocate a structure to glue together + * the old and new FILE entries, which are then no longer contiguous. + */ +FILE * +_findiop() +{ + register FILE **iov, *iop; + register FILE *fp; + + if(iobglue == NULL) { + for(iop = _iob; iop < _iob + NSTATIC; iop++) + if(!active(iop)) + return(iop); + + if(_f_morefiles() == 0) { + errno = ENOMEM; + return(NULL); + } + } + + iov = iobglue; + while(*iov != NULL && active(*iov)) + if (++iov >= endglue) { + errno = EMFILE; + return(NULL); + } + + if(*iov == NULL) + *iov = (FILE *)calloc(1, sizeof **iov); + + return(*iov); +} + +_f_morefiles() +{ + register FILE **iov; + register FILE *fp; + register unsigned char *cp; + int nfiles; + + nfiles = getdtablesize(); + + iobglue = (FILE **)calloc(nfiles, sizeof *iobglue); + if(iobglue == NULL) + return(0); + + if((_smbuf = (unsigned char (*)[_SBFSIZ])malloc(nfiles * sizeof *_smbuf)) == NULL) { + free((char *)iobglue); + iobglue = NULL; + return(0); + } + + endglue = iobglue + nfiles; + + for(fp = _iob, iov = iobglue; fp < &_iob[NSTATIC]; /* void */) + *iov++ = fp++; + + return(1); +} + +f_prealloc() +{ + register FILE **iov; + register FILE *fp; + + if(iobglue == NULL && _f_morefiles() == 0) + return; + + for(iov = iobglue; iov < endglue; iov++) + if(*iov == NULL) + *iov = (FILE *)calloc(1, sizeof **iov); +} + +void +_fwalk(function) +register int (*function)(); +{ + register FILE **iov; + register FILE *fp; + + if(function == NULL) + return; + + if(iobglue == NULL) { + for(fp = _iob; fp < &_iob[NSTATIC]; fp++) + if(active(fp)) + (*function)(fp); + } else { + for(iov = iobglue; iov < endglue; iov++) + if(*iov && active(*iov)) + (*function)(*iov); + } +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fputc.c b/usr/src/lib/libbc/libc/stdio/common/fputc.c new file mode 100644 index 0000000000..54ceb3220b --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fputc.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +int +fputc(c, fp) +int c; +register FILE *fp; +{ + return(putc(c, fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fputs.c b/usr/src/lib/libbc/libc/stdio/common/fputs.c new file mode 100644 index 0000000000..a18ba04b12 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fputs.c @@ -0,0 +1,146 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +/*LINTLIBRARY*/ +/* + * This version writes directly to the buffer rather than looping on putc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + */ +#include <stdio.h> +#include "stdiom.h" +#include <errno.h> + +extern char *memccpy(); +static char *memnulccpy(); + +int +fputs(ptr, iop) +char *ptr; +register FILE *iop; +{ + register int ndone = 0, n; + register unsigned char *cptr, *bufend; + register char *p; + register char c; + + if (_WRTCHK(iop)) { + iop->_flag |= _IOERR; +#ifdef POSIX + errno = EBADF; +#endif POSIX + return (EOF); + } + bufend = iop->_base + iop->_bufsiz; + + if ((iop->_flag & _IONBF) == 0) { + if (iop->_flag & _IOLBF) { + for ( ; ; ptr += n) { + while ((n = bufend - (cptr = iop->_ptr)) <= 0) + /* full buf */ + if (_xflsbuf(iop) == EOF) + return(EOF); + if ((p = memnulccpy((char *) cptr, ptr, '\n', n)) != NULL) { + /* + * Copy terminated either because we + * saw a newline or we saw a NUL (end + * of string). + */ + c = *(p - 1); /* last character moved */ + if (c == '\0') + p--; /* didn't write '\0' */ + n = p - (char *) cptr; + } + iop->_cnt -= n; + iop->_ptr += n; + _BUFSYNC(iop); + ndone += n; + if (p != NULL) { + /* + * We found either a newline or a NUL. + * If we found a newline, flush the + * buffer. + * If we found a NUL, we're done. + */ + if (c == '\n') { + if (_xflsbuf(iop) == EOF) + return(EOF); + } else { + /* done */ + return(ndone); + } + } + } + } else { + for ( ; ; ptr += n) { + while ((n = bufend - (cptr = iop->_ptr)) <= 0) + /* full buf */ + if (_xflsbuf(iop) == EOF) + return(EOF); + if ((p = memccpy((char *) cptr, ptr, '\0', n)) != NULL) + n = (p - (char *) cptr) - 1; + iop->_cnt -= n; + iop->_ptr += n; + _BUFSYNC(iop); + ndone += n; + if (p != NULL) { + /* done */ + return(ndone); + } + } + } + } else { + /* write out to an unbuffered file */ + return (write(iop->_file, ptr, strlen(ptr))); + } +} + +/* + * Copy s2 to s1, stopping if character c or a NUL is copied. + * Copy no more than n bytes. + * Return a pointer to the byte after character c or NUL in the copy, + * or NULL if c or NUL is not found in the first n bytes. + */ +static char * +memnulccpy(s1, s2, c, n) +register char *s1, *s2; +register int c, n; +{ + register int cmoved; + + while (--n >= 0) { + cmoved = *s2++; + if ((*s1++ = cmoved) == '\0' || cmoved == c) + return (s1); + } + return (0); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fread.c b/usr/src/lib/libbc/libc/stdio/common/fread.c new file mode 100644 index 0000000000..c195690c5f --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fread.c @@ -0,0 +1,77 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 3.11 */ + +/*LINTLIBRARY*/ +/* + * This version reads directly from the buffer rather than looping on getc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + */ +#include <stdio.h> +#include "stdiom.h" + +#define MIN(x, y) (x < y ? x : y) + +extern int _filbuf(); +extern _bufsync(); +extern char *memcpy(); + +int +fread(ptr, size, count, iop) +char *ptr; +int size, count; +register FILE *iop; +{ + register unsigned int nleft; + register int n; + + if (size <= 0 || count <= 0) return 0; + nleft = count * size; + + /* Put characters in the buffer */ + /* note that the meaning of n when just starting this loop is + irrelevant. It is defined in the loop */ + for ( ; ; ) { + if (iop->_cnt <= 0) { /* empty buffer */ + if (_filbuf(iop) == EOF) + return (count - (nleft + size - 1)/size); + iop->_ptr--; + iop->_cnt++; + } + n = MIN(nleft, iop->_cnt); + ptr = memcpy(ptr, (char *) iop->_ptr, n) + n; + iop->_cnt -= n; + iop->_ptr += n; + _BUFSYNC(iop); + if ((nleft -= n) == 0) + return (count); + } +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fseek.c b/usr/src/lib/libbc/libc/stdio/common/fseek.c new file mode 100644 index 0000000000..348f11302d --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fseek.c @@ -0,0 +1,94 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* + * Seek for standard library. Coordinates with buffering. + */ +#include <stdio.h> + +extern long lseek(); +extern int fflush(); + +int +fseek(iop, offset, ptrname) +register FILE *iop; +long offset; +int ptrname; +{ + register int resync, c; + long p = -1; /* can't happen? */ + + iop->_flag &= ~_IOEOF; + if(iop->_flag & _IOREAD) { + if(ptrname < 2 && iop->_base && !(iop->_flag&_IONBF)) { + c = iop->_cnt; + p = offset; + if(ptrname == 0) { + long curpos = lseek(fileno(iop), 0L, 1); + if (curpos == -1) + return (-1); + p += c - curpos; + resync = offset&01; + } else { + offset -= (long)c; + resync = 0; + } + if(!(iop->_flag&_IORW) && c > 0 && p <= c && + p >= iop->_base - iop->_ptr) { + iop->_ptr += (int)p; + iop->_cnt -= (int)p; + return(0); + } + } else + resync = 0; + if(iop->_flag & _IORW) { + iop->_ptr = iop->_base; + iop->_flag &= ~_IOREAD; + resync = 0; + } + p = lseek(fileno(iop), offset-resync, ptrname); + iop->_cnt = 0; + if (resync && p != -1) + if (getc(iop) == EOF) + p = -1; + } else if(iop->_flag & (_IOWRT | _IORW)) { + p = fflush(iop); + iop->_cnt = 0; + if(iop->_flag & _IORW) { + iop->_flag &= ~_IOWRT; + iop->_ptr = iop->_base; + } + return(lseek(fileno(iop), offset, ptrname) == -1 || p == EOF ? + -1 : 0); + } + return((p == -1)? -1: 0); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/ftell.c b/usr/src/lib/libbc/libc/stdio/common/ftell.c new file mode 100644 index 0000000000..85659bb764 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/ftell.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * Return file offset. + * Coordinates with buffering. + */ +#include <stdio.h> + +extern long lseek(); + +long +ftell(iop) +register FILE *iop; +{ + register long tres; + register int adjust; + + if(iop->_cnt < 0) + iop->_cnt = 0; + if(iop->_flag & _IOREAD) + adjust = - iop->_cnt; + else if(iop->_flag & (_IOWRT | _IORW)) { + adjust = 0; + if(iop->_flag & _IOWRT && iop->_base && + (iop->_flag & _IONBF) == 0) + adjust = iop->_ptr - iop->_base; + } else + return(-1); + tres = lseek(fileno(iop), 0L, 1); + if(tres >= 0) + tres += (long)adjust; + return(tres); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/fwrite.c b/usr/src/lib/libbc/libc/stdio/common/fwrite.c new file mode 100644 index 0000000000..c68412ed52 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/fwrite.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 3.6 */ + +/*LINTLIBRARY*/ +/* + * This version writes directly to the buffer rather than looping on putc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + * + * This version does buffered writes larger than BUFSIZ directly, when + * the buffer is empty. + */ +#include <stdio.h> +#include "stdiom.h" + +#define MIN(x, y) (x < y ? x : y) + +extern char *memcpy(); + +int +fwrite(ptr, size, count, iop) +char *ptr; +int size, count; +register FILE *iop; +{ + register unsigned nleft; + register int n; + register unsigned char *cptr, *bufend; + register unsigned char *prev_ptr; + + if (size <= 0 || count <= 0 || _WRTCHK(iop)) + return (0); + + bufend = iop->_base + iop->_bufsiz; + nleft = count*size; + + /* if the file is unbuffered, or if the iop->ptr = iop->base, and there + is > BUFSZ chars to write, we can do a direct write */ + prev_ptr = iop->_ptr; + if (iop->_base >= iop->_ptr) { /*this covers the unbuffered case, too*/ + if (((iop->_flag & _IONBF) != 0) || (nleft >= BUFSIZ)) { + if ((n=write(fileno(iop),ptr,nleft)) != nleft) + { + iop->_flag |= _IOERR; + n = (n >= 0) ? n : 0; + } + return n/size; + } + } + /* Put characters in the buffer */ + /* note that the meaning of n when just starting this loop is + irrelevant. It is defined in the loop */ + for (; ; ptr += n) { + while ((n = bufend - (cptr = iop->_ptr)) <= 0) /* full buf */ + if (_xflsbuf(iop) == EOF) + return (count - (nleft + size - 1)/size); + n = MIN(nleft, n); + (void) memcpy((char *) cptr, ptr, n); + iop->_cnt -= n; + iop->_ptr += n; + _BUFSYNC(iop); + /* done; flush if linebuffered with a newline */ + if ((nleft -= n) == 0) { + if (iop->_flag & (_IOLBF | _IONBF)) { + if ((iop->_flag & _IONBF) || (memchr(prev_ptr, + '\n',iop->_ptr - prev_ptr) != NULL)) { + (void) _xflsbuf(iop); + } + } + return (count); + } + } +} diff --git a/usr/src/lib/libbc/libc/stdio/common/getc.c b/usr/src/lib/libbc/libc/stdio/common/getc.c new file mode 100644 index 0000000000..617c18be80 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/getc.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> + +#undef getc +#define __getc__(p) (--(p)->_cnt>=0? ((int)*(p)->_ptr++):_filbuf(p)) + +int +getc(fp) +register FILE *fp; +{ + return (__getc__(fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/getchar.c b/usr/src/lib/libbc/libc/stdio/common/getchar.c new file mode 100644 index 0000000000..db8a18821b --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/getchar.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * A subroutine version of the macro getchar. + */ +#include <stdio.h> +#undef getchar + +int +getchar() +{ + return(getc(stdin)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/gets.c b/usr/src/lib/libbc/libc/stdio/common/gets.c new file mode 100644 index 0000000000..3cf3a49af6 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/gets.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 3.3 */ + +/*LINTLIBRARY*/ +/* + * This version reads directly from the buffer rather than looping on getc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + */ +#include <stdio.h> +#include "stdiom.h" + +extern int _filbuf(); +extern _bufsync(); +extern char *memccpy(); + +char * +gets(ptr) +char *ptr; +{ + char *p, *ptr0 = ptr; + register int n; + + for ( ; ; ) { + if (stdin->_cnt <= 0) { /* empty buffer */ + if (_filbuf(stdin) == EOF) { + if (ptr0 == ptr) + return (NULL); + break; /* no more data */ + } + stdin->_ptr--; + stdin->_cnt++; + } + n = stdin->_cnt; + if ((p = memccpy(ptr, (char *) stdin->_ptr, '\n', n)) != NULL) + n = p - ptr; + ptr += n; + stdin->_cnt -= n; + stdin->_ptr += n; + _BUFSYNC(stdin); + if (p != NULL) { /* found '\n' in buffer */ + ptr--; /* step back over '\n' */ + break; + } + } + *ptr = '\0'; + return (ptr0); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/getw.c b/usr/src/lib/libbc/libc/stdio/common/getw.c new file mode 100644 index 0000000000..97df767bce --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/getw.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* + * The intent here is to provide a means to make the order of + * bytes in an io-stream correspond to the order of the bytes + * in the memory while doing the io a `word' at a time. + */ +#include <stdio.h> + +int +getw(stream) +register FILE *stream; +{ + int w; + register char *s = (char *)&w; + register int i = sizeof(int); + + while (--i >= 0) + *s++ = getc(stream); + return (feof(stream) || ferror(stream) ? EOF : w); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/iob.c b/usr/src/lib/libbc/libc/stdio/common/iob.c new file mode 100644 index 0000000000..df2e0846d3 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/iob.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from Sun */ + +#include <stdio.h> +#include "iob.h" + +FILE _iob[NSTATIC] = { +#if pdp11 + { NULL, 0, NULL, 0, _IOREAD, 0 }, /* stdin */ + { NULL, 0, NULL, 0, _IOWRT, 1 }, /* stdout */ + { NULL, 0, NULL, 0, _IOWRT|_IONBF, 2 }, /* stderr */ +#else +#if u370 + { NULL, 0, NULL, 0, _IOREAD, 0 }, /* stdin */ + { NULL, 0, NULL, 0, _IOWRT, 1 }, /* stdout */ + { NULL, 0, NULL, 0, _IOWRT|_IONBF, 2 }, /* stderr */ +#else /* just about every other UNIX system in existence */ + { 0, NULL, NULL, 0, _IOREAD, 0 }, /* stdin */ + { 0, NULL, NULL, 0, _IOWRT, 1 }, /* stdout */ + { 0, NULL, NULL, 0, _IOWRT|_IONBF, 2 }, /* stderr */ +#endif +#endif +}; diff --git a/usr/src/lib/libbc/libc/stdio/common/iob.h b/usr/src/lib/libbc/libc/stdio/common/iob.h new file mode 100644 index 0000000000..644dfecf46 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/iob.h @@ -0,0 +1,29 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#define NSTATIC 32 diff --git a/usr/src/lib/libbc/libc/stdio/common/putc.c b/usr/src/lib/libbc/libc/stdio/common/putc.c new file mode 100644 index 0000000000..9cf2d6dae6 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/putc.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> + +#undef putc +#define __putc__(x, p) (--(p)->_cnt >= 0 ?\ + (int)(*(p)->_ptr++ = (unsigned char)(x)) :\ + (((p)->_flag & _IOLBF) && -(p)->_cnt < (p)->_bufsiz ?\ + ((*(p)->_ptr = (unsigned char)(x)) != '\n' ?\ + (int)(*(p)->_ptr++) :\ + _flsbuf(*(unsigned char *)(p)->_ptr, p)) :\ + _flsbuf((unsigned char)(x), p))) + +int +putc(c, fp) +register char c; +register FILE *fp; +{ + return (__putc__(c, fp)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/putchar.c b/usr/src/lib/libbc/libc/stdio/common/putchar.c new file mode 100644 index 0000000000..7a8fb3b9b5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/putchar.c @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +/* + * A subroutine version of the macro putchar + */ +#include <stdio.h> +#undef putchar + +int +putchar(c) +register char c; +{ + return(putc(c, stdout)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/puts.c b/usr/src/lib/libbc/libc/stdio/common/puts.c new file mode 100644 index 0000000000..ed6297474c --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/puts.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 3.3 */ + +/*LINTLIBRARY*/ +/* + * This version writes directly to the buffer rather than looping on putc. + * Ptr args aren't checked for NULL because the program would be a + * catastrophic mess anyway. Better to abort than just to return NULL. + */ +#include <stdio.h> +#include "stdiom.h" + +extern char *memccpy(); + +int +puts(ptr) +char *ptr; +{ + char *p; + register int ndone = 0, n; + register unsigned char *cptr, *bufend; + + if (_WRTCHK(stdout)) + return (EOF); + + bufend = stdout->_base + stdout->_bufsiz; + + for ( ; ; ptr += n) { + while ((n = bufend - (cptr = stdout->_ptr)) <= 0) /* full buf */ + if (_xflsbuf(stdout) == EOF) + return(EOF); + if ((p = memccpy((char *) cptr, ptr, '\0', n)) != NULL) + n = p - (char *) cptr; + stdout->_cnt -= n; + stdout->_ptr += n; + _BUFSYNC(stdout); + ndone += n; + if (p != NULL) { + stdout->_ptr[-1] = '\n'; /* overwrite '\0' with '\n' */ + if (stdout->_flag & (_IONBF | _IOLBF)) /* flush line */ + if (_xflsbuf(stdout) == EOF) + return(EOF); + return(ndone); + } + } +} diff --git a/usr/src/lib/libbc/libc/stdio/common/putw.c b/usr/src/lib/libbc/libc/stdio/common/putw.c new file mode 100644 index 0000000000..db34b3aed4 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/putw.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* + * The intent here is to provide a means to make the order of + * bytes in an io-stream correspond to the order of the bytes + * in the memory while doing the io a `word' at a time. + */ +#include <stdio.h> + +int +putw(w, stream) +int w; +register FILE *stream; +{ + register char *s = (char *)&w; + register int i = sizeof(int); + + while (--i >= 0) + (void) putc(*s++, stream); + return (ferror(stream)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/remove.c b/usr/src/lib/libbc/libc/stdio/common/remove.c new file mode 100644 index 0000000000..d886a73306 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/remove.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> + +#undef remove + +int +remove(fname) +register char *fname; +{ + return (unlink(fname)); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/rew.c b/usr/src/lib/libbc/libc/stdio/common/rew.c new file mode 100644 index 0000000000..d56416aed2 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/rew.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern int fflush(); +extern long lseek(); + +void +rewind(iop) +register FILE *iop; +{ + (void) fflush(iop); + (void) lseek(fileno(iop), 0L, 0); + iop->_cnt = 0; + iop->_ptr = iop->_base; + iop->_flag &= ~(_IOERR | _IOEOF); + if(iop->_flag & _IORW) + iop->_flag &= ~(_IOREAD | _IOWRT); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/scanf.c b/usr/src/lib/libbc/libc/stdio/common/scanf.c new file mode 100644 index 0000000000..0a54f708d4 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/scanf.c @@ -0,0 +1,256 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <ctype.h> +#include <varargs.h> +#include <errno.h> + +#define ON 1 +#define OFF 0 + +#define ARGMAX 64 +static unsigned char newap[ARGMAX * sizeof(double)]; +static unsigned char newform[256]; +extern char *strcpy(); +extern char *malloc(); + +extern int _doscan(); +static int format_arg(); + +/*VARARGS1*/ +int +scanf(fmt, va_alist) +char *fmt; +va_dcl +{ + va_list ap; + char *nf; + int ret_val; + + va_start(ap); + if (strlen(fmt) >= sizeof(newform)) { + nf = malloc(strlen(fmt)+1); + if (format_arg(strcpy(nf, fmt), ap, newap) == ON) { + ret_val = _doscan(stdin, nf, newap); + free(nf); + return(ret_val); + } + free(nf); + } else if (format_arg(strcpy(newform, fmt), ap, newap) == ON) { + return(_doscan(stdin, newform, newap)); + } + return(_doscan(stdin, fmt, ap)); +} + +/*VARARGS2*/ +int +fscanf(iop, fmt, va_alist) +FILE *iop; +char *fmt; +va_dcl +{ + va_list ap; + char *nf; + int ret_val; + + va_start(ap); +#ifdef POSIX + if ( !(iop->_flag & (_IOREAD|_IORW)) ) { + iop->_flag |= _IOERR; + errno = EBADF; + return (EOF); + } +#endif POSIX + if (strlen(fmt) >= sizeof(newform)) { + nf = malloc(strlen(fmt)+1); + if (format_arg(strcpy(nf, fmt), ap, newap) == ON) { + ret_val = _doscan(stdin, nf, newap); + free(nf); + return(ret_val); + } + free(nf); + } else if (format_arg(strcpy(newform, fmt), ap, newap) == ON) { + return(_doscan(iop, newform, newap)); + } + return(_doscan(iop, fmt, ap)); +} + +/*VARARGS2*/ +int +sscanf(str, fmt, va_alist) +register char *str; +char *fmt; +va_dcl +{ + va_list ap; + FILE strbuf; + char *nf; + int ret_val; + + va_start(ap); + strbuf._flag = _IOREAD|_IOSTRG; + strbuf._ptr = strbuf._base = (unsigned char*)str; + strbuf._cnt = strlen(str); + strbuf._bufsiz = strbuf._cnt; + if (strlen(fmt) >= sizeof(newform)) { + nf = malloc(strlen(fmt)+1); + if (format_arg(strcpy(nf, fmt), ap, newap) == ON) { + ret_val = _doscan(stdin, nf, newap); + free(nf); + return(ret_val); + } + free(nf); + } else if (format_arg(strcpy(newform, fmt), ap, newap) == ON) { + return(_doscan(&strbuf, newform, newap)); + } + return(_doscan(&strbuf, fmt, ap)); +} + +/* + * This function reorganises the format string and argument list. + */ + + +#ifndef NL_ARGMAX +#define NL_ARGMAX 9 +#endif + +struct al { + int a_num; /* arg # specified at this position */ + unsigned char *a_start; /* ptr to 'n' part of '%n$' in format str */ + unsigned char *a_end; /* ptr to '$'+1 part of '%n$' in format str */ + int *a_val; /* pointers to arguments */ +}; + +static int +format_arg(format, list, newlist) +unsigned char *format, *list, *newlist; +{ + unsigned char *aptr, *bptr, *cptr; + register i, fcode, nl_fmt, num, length, j; + unsigned char *fmtsav; + struct al args[ARGMAX + 1]; + +#ifdef VTEST + { + int fd; + fd = creat("/tmp/SCANF", 0666); + } +#endif + for (i = 0; i <= ARGMAX; args[i++].a_num = 0); + nl_fmt = 0; + i = j = 1; + while (*format) { + while ((fcode = *format++) != '\0' && fcode != '%') ; + if (!fcode || i > ARGMAX) + break; + charswitch: + switch (fcode = *format++) { + case 'l': + case 'h': + goto charswitch; + case '0': case '1': case '2': + case '3': case '4': case '5': + case '6': case '7': case '8': + case '9': + num = fcode - '0'; + fmtsav = format; + while (isdigit(fcode = *format)) { + num = num * 10 + fcode - '0'; + format++; + } + if (*format == '$') { + nl_fmt++; + args[i].a_start = fmtsav - 1; + args[i].a_end = ++format; + if (num > NL_ARGMAX) + num = num; + args[i].a_num = num; + } + goto charswitch; + /* now have arg type only to parse */ + case 'd': case 'u': case 'o': + case 'x': case 'e': case 'f': + case 'g': case 'c': case '[': + case 's': + if (nl_fmt == 0) + return(OFF); + if (!args[i].a_num) { + args[i].a_start = args[i].a_end = format - 1; + args[i].a_num = j++; + } + i++; + break; + case '*': + case '%': + break; + default: + format--; + break; + } + } + length = i; + if (nl_fmt == 0) + return (OFF); + for (i = 1; i < length && args[i].a_num == 0; i++); + + /* + * Reformat the format string + */ + cptr = aptr = args[i].a_start; + do { + bptr = args[i++].a_end; + for (; i < length && args[i].a_num == 0; i++); + if (i == length) + while (*cptr++); + else + cptr = args[i].a_start; + for (; bptr != cptr; *aptr++ = *bptr++); + } while (i < length); + + /* + * Create arglist + * assuming that pointer to all variable type have + * same size. + */ + for (i = 1; i < length; i++) + args[i].a_val = ((int **)(list += sizeof(int *)))[-1]; + + for (i = 1; i < length; i++) { + int **ptr; + ptr = (int **)newlist; + *ptr = args[args[i].a_num].a_val; + newlist += sizeof(int *); + } + return(ON); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/setbuffer.c b/usr/src/lib/libbc/libc/stdio/common/setbuffer.c new file mode 100644 index 0000000000..5b8ffb2aca --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/setbuffer.c @@ -0,0 +1,89 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * University Copyright- Copyright (c) 1982, 1986, 1988 + * The Regents of the University of California + * All Rights Reserved + * + * University Acknowledgment- Portions of this document are derived from + * software developed by the University of California, Berkeley, and its + * contributors. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from UCB 4.2 83/02/27 */ + +#include <stdio.h> + +extern void free(); +extern int isatty(); +extern unsigned char (*_smbuf)[_SBFSIZ]; +extern void _getsmbuf(); + +void +setbuffer(iop, buf, size) + register FILE *iop; + char *buf; + int size; +{ + register int fno = fileno(iop); /* file number */ + + if (iop->_base != NULL && iop->_flag&_IOMYBUF) + free((char *)iop->_base); + iop->_flag &= ~(_IOMYBUF|_IONBF|_IOLBF); + if ((iop->_base = (unsigned char *)buf) == NULL) { + iop->_flag |= _IONBF; /* file unbuffered except in fastio */ + /* use small buffers reserved for this */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } else { + /* regular buffered I/O, specified buffer size */ + if (size <= 0) + return; + iop->_bufsiz = size; + } + iop->_ptr = iop->_base; + iop->_cnt = 0; +} + +/* + * set line buffering + */ +setlinebuf(iop) + register FILE *iop; +{ + register unsigned char *buf; + extern char *malloc(); + + fflush(iop); + setbuffer(iop, (unsigned char *)NULL, 0); + buf = (unsigned char *)malloc(128); + if (buf != NULL) { + setbuffer(iop, buf, 128); + iop->_flag |= _IOLBF|_IOMYBUF; + } +} diff --git a/usr/src/lib/libbc/libc/stdio/common/setvbuf.c b/usr/src/lib/libbc/libc/stdio/common/setvbuf.c new file mode 100644 index 0000000000..3721c52147 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/setvbuf.c @@ -0,0 +1,88 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern void free(); +extern unsigned char (*_smbuf)[_SBFSIZ]; +extern char *malloc(); +extern void _getsmbuf(); + +int +setvbuf(iop, buf, type, size) +register FILE *iop; +register char *buf; +register int type; +register int size; +{ + register int fno = fileno(iop); /* file number */ + + if(iop->_base != NULL && iop->_flag & _IOMYBUF) + free((char*)iop->_base); + iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); + switch (type) { + /*note that the flags are the same as the possible values for type*/ + case _IONBF: + /* file is unbuffered except in fastio */ + iop->_flag |= _IONBF; + /* use small buffers reserved for this */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + break; + case _IOLBF: + case _IOFBF: + if (size < 0) + return -1; + iop->_flag |= type; + size = (size == 0) ? BUFSIZ : size; + /* + * need eight characters beyond bufend for stdio slop + */ + if (size <= 8) { + size = BUFSIZ; + buf = NULL; + } + if (buf == NULL) { + size += 8; + buf = malloc((unsigned)size); + iop->_flag |= _IOMYBUF; + } + iop->_base = (unsigned char *)buf; + iop->_bufsiz = size - 8; + break; + default: + return -1; + } + iop->_ptr = iop->_base; + iop->_cnt = 0; + return 0; +} diff --git a/usr/src/lib/libbc/libc/stdio/common/stdiom.h b/usr/src/lib/libbc/libc/stdio/common/stdiom.h new file mode 100644 index 0000000000..cac8d3c0b5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/stdiom.h @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* The following macros improve performance of the stdio by reducing the + number of calls to _bufsync and _wrtchk. _BUFSYNC has the same + effect as _bufsync, and _WRTCHK has the same effect as _wrtchk, + but often these functions have no effect, and in those cases the + macros avoid the expense of calling the functions. */ + +#define _BUFSYNC(iop) if ((iop->_base + iop->_bufsiz) - iop->_ptr < \ + ( iop->_cnt < 0 ? 0 : iop->_cnt ) ) \ + _bufsync(iop) +#define _WRTCHK(iop) ((((iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT) \ + || (iop->_base == NULL) \ + || (iop->_ptr == iop->_base && iop->_cnt == 0 \ + && !(iop->_flag & (_IONBF | _IOLBF)))) \ + ? _wrtchk(iop) : 0 ) diff --git a/usr/src/lib/libbc/libc/stdio/common/tempnam.c b/usr/src/lib/libbc/libc/stdio/common/tempnam.c new file mode 100644 index 0000000000..53631b1c7a --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/tempnam.c @@ -0,0 +1,101 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <string.h> + +#define max(A,B) (((A)<(B))?(B):(A)) + +extern char *malloc(), *getenv(), *mktemp(); +extern int access(); + +static char *pcopy(); +static char seed[4]; + +char * +tempnam(dir, pfx) +char *dir; /* use this directory please (if non-NULL) */ +char *pfx; /* use this (if non-NULL) as filename prefix */ +{ + register char *p, *q, *tdir; + int x=0, y=0, z; + + if (seed[0] == 0) + seed[0] = seed[1] = seed[2] = 'A'; + z=strlen(P_tmpdir); + if((tdir = getenv("TMPDIR")) != NULL) { + x = strlen(tdir); + } + if(dir != NULL) { + y=strlen(dir); + } + if((p=malloc((unsigned)(max(max(x,y),z)+16))) == NULL) + return(NULL); + if(x > 0 && access(pcopy(p, tdir), 3) == 0) + goto OK; + if(y > 0 && access(pcopy(p, dir), 3) == 0) + goto OK; + if(access(pcopy(p, P_tmpdir), 3) == 0) + goto OK; + if(access(pcopy(p, "/tmp"), 3) != 0) + return(NULL); +OK: + (void)strcat(p, "/"); + if(pfx) { + *(p+strlen(p)+5) = '\0'; + (void)strncat(p, pfx, 5); + } + (void)strcat(p, seed); + (void)strcat(p, "XXXXXX"); + q = seed; + while(*q == 'Z') + *q++ = 'A'; + ++*q; + if(*mktemp(p) == '\0') + return(NULL); + return(p); +} + +static char* +pcopy(space, arg) +char *space, *arg; +{ + char *p; + + if(arg) { + (void)strcpy(space, arg); + p = space-1+strlen(space); + if(*p == '/') + *p = '\0'; + } + return(space); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/tmpfile.c b/usr/src/lib/libbc/libc/stdio/common/tmpfile.c new file mode 100644 index 0000000000..5981194b75 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/tmpfile.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +/*LINTLIBRARY*/ +/* + * tmpfile - return a pointer to an update file that can be + * used for scratch. The file will automatically + * go away if the program using it terminates. + */ +#include <stdio.h> + +extern FILE *fopen(); +extern int unlink(); +extern char *tmpnam(); +extern void perror(); + +FILE * +tmpfile() +{ + char tfname[L_tmpnam]; + register FILE *p; + + (void) tmpnam(tfname); + if((p = fopen(tfname, "w+")) == NULL) + return NULL; + else + (void) unlink(tfname); + return(p); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/tmpnam.c b/usr/src/lib/libbc/libc/stdio/common/tmpnam.c new file mode 100644 index 0000000000..ed20714514 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/tmpnam.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern char *mktemp(), *strcpy(), *strcat(); +static char str[L_tmpnam], seed[] = { 'a', 'a', 'a', '\0' }; + +char * +tmpnam(s) +char *s; +{ + register char *p, *q; + register int cnt = 0; + + p = (s == NULL)? str: s; + (void) strcpy(p, P_tmpdir); + (void) strcat(p, seed); + (void) strcat(p, "XXXXXX"); + + q = seed; + while(*q == 'z') { + *q++ = 'a'; + cnt++; + } + if (cnt < 3) + ++*q; + + (void) mktemp(p); + return(p); +} diff --git a/usr/src/lib/libbc/libc/stdio/common/ungetc.c b/usr/src/lib/libbc/libc/stdio/common/ungetc.c new file mode 100644 index 0000000000..f6c5f8b8f4 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/common/ungetc.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +int +ungetc(c, iop) +int c; +register FILE *iop; +{ + if(c == EOF) + return(EOF); + if((iop->_flag & (_IOREAD|_IORW)) == 0) + return(EOF); + + if (iop->_base == NULL) /* get buffer if we don't have one */ + _findbuf(iop); + + if((iop->_flag & _IOREAD) == 0 || iop->_ptr <= iop->_base) + if(iop->_ptr == iop->_base && iop->_cnt == 0) + ++iop->_ptr; + else + return(EOF); + if (*--iop->_ptr != c) *iop->_ptr = c; /* was *--iop->_ptr = c; */ + ++iop->_cnt; + return(c); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c new file mode 100644 index 0000000000..aa247dab34 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/filbuf.c @@ -0,0 +1,92 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1998 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern _findbuf(); +extern int read(); +extern int fflush(); + +int +__filbuf(iop) +register FILE *iop; +{ + return (_filbuf(iop)); +} + +int +_filbuf(iop) +register FILE *iop; +{ + static void lbfflush(); + + if ( !(iop->_flag & _IOREAD) ) + if (iop->_flag & _IORW) + iop->_flag |= _IOREAD; + else + return(EOF); + + if (iop->_flag&_IOSTRG) + return(EOF); + + if (iop->_base == NULL) /* get buffer if we don't have one */ + _findbuf(iop); + + /* if this device is a terminal (line-buffered) or unbuffered, then */ + /* flush buffers of all line-buffered devices currently writing */ + + if (iop->_flag & (_IOLBF | _IONBF)) + _fwalk(lbfflush); + + iop->_ptr = iop->_base; + iop->_cnt = read(fileno(iop), (char *)iop->_base, + (unsigned)((iop->_flag & _IONBF) ? 1 : iop->_bufsiz )); + if (--iop->_cnt >= 0) /* success */ + return (*iop->_ptr++); + if (iop->_cnt != -1) /* error */ + iop->_flag |= _IOERR; + else { /* end-of-file */ + iop->_flag |= _IOEOF; + if (iop->_flag & _IORW) + iop->_flag &= ~_IOREAD; + } + iop->_cnt = 0; + return (EOF); +} + +static void +lbfflush(iop) +FILE *iop; +{ + if (iop->_flag & _IOLBF) + (void) fflush(iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c new file mode 100644 index 0000000000..635b1ff2ba --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/flsbuf.c @@ -0,0 +1,295 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + /* from ../4.2/flsbuf.c */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <sys/errno.h> +#include "../common/stdiom.h" +#include <sys/types.h> +#include <sys/stat.h> +#include <unistd.h> + +extern void free(); +extern int errno, write(), close(), isatty(); +extern char *malloc(); +extern unsigned char (*_smbuf)[_SBFSIZ]; + +void _getsmbuf(); + +/* + * Flush buffers on exit + */ + +void +_cleanup() +{ + extern int fclose(); + + _fwalk(fclose); +} +/* + fclose() will flush (output) buffers for a buffered open + FILE and then issue a system close on the _fileno. The + _base field will be reset to NULL for any but stdin and + stdout, the _ptr field will be set the same as the _base + field. The _flags and the _cnt field will be zeroed. + If buffers had been obtained via malloc(), the space will + be free()'d. In case the FILE was not open, or fflush() + or close() failed, an EOF will be returned, otherwise the + return value is 0. + */ + +int +fclose(iop) +register FILE *iop; +{ + register int rtn=EOF; + + if(iop == NULL) + return(rtn); + if(iop->_flag & (_IOREAD | _IOWRT | _IORW) + && (iop->_flag & _IOSTRG) == 0) { + rtn = (iop->_flag & _IONBF)? 0: fflush(iop); + if(close(fileno(iop)) < 0) + rtn = EOF; + } + if(iop->_flag & _IOMYBUF) { + free((char*)iop->_base); + iop->_base = NULL; + } + iop->_flag = 0; + iop->_cnt = 0; + iop->_ptr = iop->_base; + iop->_bufsiz = 0; + return(rtn); +} + +/* + The fflush() routine must take care because of the + possibility for recursion. The calling program might + do IO in an interupt catching routine that is likely + to interupt the write() call within fflush() + */ + +int +fflush(iop) +register FILE *iop; +{ + if (!(iop->_flag & _IOWRT)) { + if ((iop->_base != NULL) && iop->_cnt) { + lseek(iop->_file, -(iop->_cnt), SEEK_CUR); + iop->_cnt = 0; + } + return(0); + } + while(!(iop->_flag & _IONBF) && (iop->_flag & _IOWRT) && + (iop->_base != NULL) && (iop->_ptr > iop->_base) ) + (void) _xflsbuf(iop); + return(ferror(iop) ? EOF : 0); +} + +/* The routine _flsbuf may or may not actually flush the output buffer. If + * the file is line-buffered, the fact that iop->_cnt has run below zero + * is meaningless: it is always kept below zero so that invocations of putc + * will consistently give control to _flsbuf, even if the buffer is far from + * full. _flsbuf, on seeing the "line-buffered" flag, determines whether the + * buffer is actually full by comparing iop->_ptr to the end of the buffer + * iop->_base + iop->_bufsiz. If it is full, or if an output line is + * completed (with a newline), the buffer is flushed. (Note: the character + * argument to _flsbuf is not flushed with the current buffer if the buffer + * is actually full -- it goes into the buffer after flushing.) + */ + +int +_flsbuf(c, iop) +unsigned char c; +register FILE *iop; +{ + unsigned char c1; + + do { + /* check for linebuffered with write perm, but no EOF */ + if ( (iop->_flag & (_IOLBF | _IOWRT | _IOEOF)) == (_IOLBF | _IOWRT) ) { + if ( iop->_ptr >= iop->_base + iop->_bufsiz ) /* if buffer full, */ + break; /* exit do-while, and flush buf. */ + if ( (*iop->_ptr++ = c) != '\n' ) + return(c); + return(_xflsbuf(iop) == EOF ? EOF : c); + } + /* write out an unbuffered file, if have write perm, but no EOF */ + if ( (iop->_flag & (_IONBF | _IOWRT | _IOEOF)) == (_IONBF | _IOWRT) ) { + c1 = c; + iop->_cnt = 0; + if (write(fileno(iop), (char *) &c1, 1) == 1) + return(c); + iop->_flag |= _IOERR; + return(EOF); + } + /* The _wrtchk call is here rather than at the top of _flsbuf to re- */ + /* duce overhead for line-buffered I/O under normal circumstances. */ + + if (_WRTCHK(iop)) /* is writing legitimate? */ + return(EOF); + } while ( (iop->_flag & (_IONBF | _IOLBF)) ); + + + (void) _xflsbuf(iop); /* full buffer: flush buffer */ + (void) putc((char) c, iop); /* then put "c" in newly emptied buf */ + /* (which, because of signals, may NOT be empty) */ + return( ferror(iop) ? EOF : c); +} + +/* The function _xflsbuf writes out the current contents of the output + * buffer delimited by iop->_base and iop->_ptr. + * iop->_cnt is reset appropriately, but its value on entry to _xflsbuf + * is ignored. + * + * The following code is not strictly correct. If a signal is raised, + * invoking a signal-handler which generates output into the same buffer + * being flushed, a peculiar output sequence may result (for example, + * the output generated by the signal-handler may appear twice). At + * present no means has been found to guarantee correct behavior without + * resorting to the disabling of signals, a means considered too expensive. + * For now the code has been written with the intent of reducing the + * probability of strange effects and, when they do occur, of confining + * the damage. Except under extremely pathological circumstances, this + * code should be expected to respect buffer boundaries even in the face + * of interrupts and other signals. + */ + +int +_xflsbuf(iop) +register FILE *iop; +{ + register unsigned char *base; + register int n; + + n = iop->_ptr - (base = iop->_base); + iop->_ptr = base; + iop->_cnt = (iop->_flag &(_IONBF | _IOLBF)) ? 0 : iop->_bufsiz; + _BUFSYNC(iop); + if (n > 0 && n != write(fileno(iop),(char*)base,(unsigned)n) ) { + iop->_flag |= _IOERR; + return(EOF); + } + return(0); +} + +/* The function _wrtchk checks to see whether it is legitimate to write + * to the specified device. If it is, _wrtchk sets flags in iop->_flag for + * writing, assures presence of a buffer, and returns 0. If writing is not + * legitimate, EOF is returned. + */ + +int +_wrtchk(iop) +register FILE *iop; +{ + if ( (iop->_flag & (_IOWRT | _IOEOF)) != _IOWRT ) { + if (!(iop->_flag & (_IOWRT | _IORW))) + return(EOF); /* bogus call--read-only file */ + iop->_flag = iop->_flag & ~_IOEOF | _IOWRT; /* fix flags */ + } + if (iop->_flag & _IOSTRG) + return(0); /* not our business to monkey with buffers or counts */ + if (iop->_base == NULL) /* this is first I/O to file--get buffer */ + _findbuf(iop); + if (iop->_ptr == iop->_base && !(iop->_flag & (_IONBF | _IOLBF)) ) { + iop->_cnt = iop->_bufsiz; /* first write since seek--set cnt */ + _BUFSYNC(iop); + } + return(0); +} + +/* + * _findbuf, called only when iop->_base == NULL, locates a predefined buffer + * or allocates a buffer using malloc. If a buffer is obtained from malloc, + * the _IOMYBUF flag is set in iop->_flag. + */ + +_findbuf(iop) +register FILE *iop; +{ + register int fno = fileno(iop); /* file number */ + struct stat statb; + register int size; + + /* allocate a small block for unbuffered, large for buffered */ + if (iop->_flag & _IONBF) { + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } else { + + if ( isatty(fno) ) { + iop->_flag |= _IOLBF; + size = 128; + } else { + if (fstat(fno, &statb) < 0) + size = BUFSIZ; + else { + if ((size = statb.st_blksize) <= 0) + size = BUFSIZ; + } + } + if ((iop->_base = (unsigned char *) malloc(size+8)) != NULL) { + /* if we got a buffer */ + iop->_flag |= _IOMYBUF; + iop->_bufsiz = size; + } else { + /* if no room for buffer, use small buffer */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + iop->_flag &= ~_IOLBF; + iop->_flag |= _IONBF; + } + } + iop->_ptr = iop->_base; +} + +/* The function _bufsync is called because interrupts and other signals + * which occur in between the decrementing of iop->_cnt and the incrementing + * of iop->_ptr, or in other contexts as well, may upset the synchronization + * of iop->_cnt and iop->ptr. If this happens, calling _bufsync should + * resynchronize the two quantities (this is not always possible). Resyn- + * chronization guarantees that putc invocations will not write beyond + * the end of the buffer. Note that signals during _bufsync can cause + * _bufsync to do the wrong thing, but usually with benign effects. + */ + +_bufsync(iop) +register FILE *iop; +{ + register int spaceleft; + register unsigned char *bufend = iop->_base + iop->_bufsiz; + + if ((spaceleft = bufend - iop->_ptr) < 0) + iop->_ptr = bufend; + else if (spaceleft < iop->_cnt) + iop->_cnt = spaceleft; +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/fopen.c b/usr/src/lib/libbc/libc/stdio/sys5/fopen.c new file mode 100644 index 0000000000..d7cb1ee876 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/fopen.c @@ -0,0 +1,91 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.8 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <fcntl.h> + +extern int open(), fclose(); +extern FILE *_findiop(), *_endopen(); + +FILE * +fopen(file, mode) +char *file, *mode; +{ + return (_endopen(file, mode, _findiop())); +} + +FILE * +freopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + (void) fclose(iop); /* doesn't matter if this fails */ + return (_endopen(file, mode, iop)); +} + +static FILE * +_endopen(file, mode, iop) +char *file, *mode; +register FILE *iop; +{ + register int plus, oflag, fd; + + if (iop == NULL || file == NULL || file[0] == '\0') + return (NULL); + plus = (mode[1] == '+'); + switch (mode[0]) { + case 'w': + oflag = (plus ? O_RDWR : O_WRONLY) | O_TRUNC | O_CREAT; + break; + case 'a': + oflag = (plus ? O_RDWR : O_WRONLY) | O_APPEND | O_CREAT; + break; + case 'r': + oflag = plus ? O_RDWR : O_RDONLY; + break; + default: + return (NULL); + } + if ((fd = open(file, oflag, 0666)) < 0) + return (NULL); + iop->_cnt = 0; + iop->_file = fd; + iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; + if (mode[0] == 'a') { + if (!plus) { + /* if update only mode, move file pointer to the end + of the file */ + if ((lseek(fd,0L,2)) < 0) { + (void) close(fd); + return NULL; + } + } + } + iop->_base = iop->_ptr = NULL; + iop->_bufsiz = 0; + return (iop); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c new file mode 100644 index 0000000000..8daed9d391 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/fprintf.c @@ -0,0 +1,74 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +fprintf(iop, format, va_alist) +FILE *iop; +char *format; +va_dcl +{ + unsigned char localbuf[BUFSIZ]; + register int count; + va_list ap; + + va_start(ap); + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + va_end(ap); + return(ferror(iop)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/printf.c b/usr/src/lib/libbc/libc/stdio/sys5/printf.c new file mode 100644 index 0000000000..0a320e4d86 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/printf.c @@ -0,0 +1,61 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +printf(format, va_alist) +char *format; +va_dcl +{ + register int count; + va_list ap; + + va_start(ap); + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + count = _doprnt(format, ap, stdout); + va_end(ap); + return(ferror(stdout)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c b/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c new file mode 100644 index 0000000000..3ad6092e4d --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/setbuf.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1986 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 2.2 */ + +/*LINTLIBRARY*/ +#include <stdio.h> + +extern void free(); +extern int isatty(); +extern unsigned char (*_smbuf)[_SBFSIZ]; +extern void _getsmbuf(); + +void +setbuf(iop, buf) +register FILE *iop; +char *buf; +{ + register int fno = fileno(iop); /* file number */ + + if(iop->_base != NULL && iop->_flag & _IOMYBUF) + free((char*)iop->_base); + iop->_flag &= ~(_IOMYBUF | _IONBF | _IOLBF); + if((iop->_base = (unsigned char*)buf) == NULL) { + iop->_flag |= _IONBF; /* file unbuffered except in fastio */ + /* use small buffers reserved for this */ + iop->_base = _smbuf[fno]; + iop->_bufsiz = _SBFSIZ; + } + else { /* regular buffered I/O, standard buffer size */ + if (isatty(fno)) + iop->_flag |= _IOLBF; + iop->_bufsiz = BUFSIZ; + } + iop->_ptr = iop->_base; + iop->_cnt = 0; +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c new file mode 100644 index 0000000000..a86dbc8be5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/sprintf.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.5 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +sprintf(string, format, va_alist) +char *string, *format; +va_dcl +{ + register int count; + FILE siop; + va_list ap; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + va_start(ap); + count = _doprnt(format, ap, &siop); + va_end(ap); + *siop._ptr = '\0'; /* plant terminating null character */ + return(count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c new file mode 100644 index 0000000000..502add53e5 --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vfprintf.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1988 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.1 */ + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +vfprintf(iop, format, ap) +FILE *iop; +char *format; +va_list ap; +{ + unsigned char localbuf[BUFSIZ]; + register int count; + + if (!(iop->_flag & _IOWRT)) { + /* if no write flag */ + if (iop->_flag & _IORW) { + /* if ok, cause read-write */ + iop->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + if (iop->_flag & _IONBF) { + iop->_flag &= ~_IONBF; + iop->_ptr = iop->_base = localbuf; + iop->_bufsiz = BUFSIZ; + count = _doprnt(format, ap, iop); + fflush(iop); + iop->_flag |= _IONBF; + iop->_base = NULL; + iop->_bufsiz = 0; + iop->_cnt = 0; + } else + count = _doprnt(format, ap, iop); + return(ferror(iop)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c new file mode 100644 index 0000000000..442c95cb5f --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vprintf.c @@ -0,0 +1,63 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> + +extern int _doprnt(); + +/*VARARGS1*/ +int +vprintf(format, ap) +char *format; +va_list ap; +{ + register int count; + + if (!(stdout->_flag & _IOWRT)) { + /* if no write flag */ + if (stdout->_flag & _IORW) { + /* if ok, cause read-write */ + stdout->_flag |= _IOWRT; + } else { + /* else error */ + return EOF; + } + } + count = _doprnt(format, ap, stdout); + return(ferror(stdout)? EOF: count); +} diff --git a/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c b/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c new file mode 100644 index 0000000000..c86412d4fb --- /dev/null +++ b/usr/src/lib/libbc/libc/stdio/sys5/vsprintf.c @@ -0,0 +1,59 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/*LINTLIBRARY*/ +#include <stdio.h> +#include <varargs.h> +#include <values.h> + +extern int _doprnt(); + +/*VARARGS2*/ +int +vsprintf(string, format, ap) +char *string, *format; +va_list ap; +{ + register int count; + FILE siop; + + siop._cnt = MAXINT; + siop._base = siop._ptr = (unsigned char *)string; + siop._flag = _IOWRT+_IOSTRG; + count = _doprnt(format, ap, &siop); + *siop._ptr = '\0'; /* plant terminating null character */ + return(count); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/access.c b/usr/src/lib/libbc/libc/sys/4.2/access.c new file mode 100644 index 0000000000..d3a709483b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/access.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <syscall.h> +#include <unistd.h> +#include <sys/param.h> + +int access(path, mode) +char *path; +int mode; +{ + CHKNULL(path); + + return(access_com(path, mode)); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/chdir.c b/usr/src/lib/libbc/libc/sys/4.2/chdir.c new file mode 100644 index 0000000000..bc946ab3f2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/chdir.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" + +chdir(s) + char *s; +{ + CHKNULL(s); + return _syscall(SYS_chdir, s); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/chkpath.h b/usr/src/lib/libbc/libc/sys/4.2/chkpath.h new file mode 100644 index 0000000000..388e0cc772 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/chkpath.h @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/syscall.h> +#include <sys/errno.h> + +#define CHKNULL(p) \ + if ((p) == (char *)0 || (p) == (char *) -1) { \ + errno = EFAULT; \ + return (-1); \ + } else if (*(p) == 0) { \ + p = "."; \ + } + +extern int syscall(); +extern errno; diff --git a/usr/src/lib/libbc/libc/sys/4.2/chmod.c b/usr/src/lib/libbc/libc/sys/4.2/chmod.c new file mode 100644 index 0000000000..4fe5c31cf0 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/chmod.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +chmod(s, m) + char *s; +{ + CHKNULL(s); + return _syscall(SYS_chmod, s, m); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/chown.c b/usr/src/lib/libbc/libc/sys/4.2/chown.c new file mode 100644 index 0000000000..3db6290c9a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/chown.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +chown(s, u, g) + char *s; +{ + CHKNULL(s); + return _syscall(SYS_lchown, s, u, g); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/chroot.c b/usr/src/lib/libbc/libc/sys/4.2/chroot.c new file mode 100644 index 0000000000..bde83e267b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/chroot.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +chroot(d) + char *d; +{ + CHKNULL(d); + return _syscall(SYS_chroot, d); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/creat.c b/usr/src/lib/libbc/libc/sys/4.2/creat.c new file mode 100644 index 0000000000..3fd67c345e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/creat.c @@ -0,0 +1,46 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <syscall.h> +#include <unistd.h> +#include <errno.h> +#include <sys/param.h> + +extern int errno; + +int creat(path, mode) +char *path; +int mode; +{ + CHKNULL(path); + + return(creat_com(path, mode)); +} + + diff --git a/usr/src/lib/libbc/libc/sys/4.2/execve.c b/usr/src/lib/libbc/libc/sys/4.2/execve.c new file mode 100644 index 0000000000..b78b7d31b3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/execve.c @@ -0,0 +1,71 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <string.h> +#include <sys/file.h> +#include <sys/syscall.h> + +execve(file, argv, arge) +char *file; +char **argv, **arge; +{ + char *c; + char path[256]; + + + CHKNULL(file); + if (strncmp(file, "/usr/ucb", strlen("/usr/ucb")) == 0) { + if (_syscall(SYS_access, file, F_OK) == -1) { + strcpy(path, "/usr/bin"); + strcat(path, strrchr(file, '/')); + file = path; + } + } + else if (strncmp(file, "/bin", strlen("/bin")) == 0 || + strncmp(file, "/usr/bin", strlen("/usr/bin")) == 0) { + strcpy(path, "/usr/ucb"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + } + else if (strncmp(file, "/usr/5bin", strlen("/usr/5bin")) == 0) { + strcpy(path, "/usr/bin"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + else { + strcpy(path, "/usr/ucb"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + } + } + + return(_syscall(SYS_execve, file, argv, arge)); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/fcntl.c b/usr/src/lib/libbc/libc/sys/4.2/fcntl.c new file mode 100644 index 0000000000..8e19913010 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/fcntl.c @@ -0,0 +1,187 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1996 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <unistd.h> +#include <sys/errno.h> +#include <sys/fcntl.h> +#include <sys/filio.h> +#include <sys/ioccom.h> +#include <sys/syscall.h> + + +/* The following is an array of fcntl commands. The numbers listed + * below are from SVR4. Array is indexed with SunOS 4.1 numbers to + * obtain the SVR4 numbers. + */ +int cmd_op[14] = {0, 1, 2, 3, 4, 23, 24, 14, 6, 7, 21, 20, -1, 22}; + +/* SVR4/SunOS 5.0 equivalent modes */ +#define N_O_NDELAY 0x04 +#define N_O_SYNC 0x10 +#define N_O_NONBLOCK 0x80 +#define N_O_CREAT 0x100 +#define N_O_TRUNC 0x200 +#define N_O_EXCL 0x400 + +#define S5_FASYNC 0x1000 + +/* from SVR4 stropts.h */ +#define S5_S_RDNORM 0x0040 +#define S5_S_WRNORM 0x0004 +#define S5_S_RDBAND 0x0080 +#define S5_S_BANDURG 0x0200 +#define S5_I_SETSIG (('S'<<8)|011) +#define S5_I_GETSIG (('S'<<8)|012) + +/* Mask corresponding to the bits above in SunOS 4.x */ +#define FLAGS_MASK (O_SYNC|O_NONBLOCK|O_CREAT|O_TRUNC|O_EXCL \ + |O_NDELAY|FNBIO|FASYNC) +#define N_FLAGS_MASK (N_O_NDELAY|N_O_SYNC|N_O_NONBLOCK|N_O_CREAT \ + |N_O_TRUNC|N_O_EXCL|S5_FASYNC) + +struct n_flock { + short l_type; + short l_whence; + long l_start; + long l_len; /* len == 0 means until end of file */ + long l_sysid; + long l_pid; + long pad[4]; /* reserve area */ +} ; + + +int fcntl(fd, cmd, arg) +int fd, cmd, arg; +{ + return(bc_fcntl(fd, cmd, arg)); +} + + +int bc_fcntl(fd, cmd, arg) +int fd, cmd, arg; +{ + int fds, ret; + struct flock *savarg; + struct n_flock nfl; + extern int errno; + int i, narg; + + if ((cmd == F_SETOWN) || (cmd == F_GETOWN)) { + ret = _s_fcntl(fd, cmd_op[cmd], arg); + if ((ret != -1) || (errno != EINVAL)) + return (ret); + else { + if (cmd == F_GETOWN) { + if (_ioctl(fd, S5_I_GETSIG, &i) < 0) { + if (errno == EINVAL) + i = 0; + else + return (-1); + } + if (i & (S5_S_RDBAND|S5_S_BANDURG| + S5_S_RDNORM|S5_S_WRNORM)) + return (getpid()); + return (0); + } else { /* cmd == F_SETOWN */ + i = S5_S_RDNORM|S5_S_WRNORM|S5_S_RDBAND|S5_S_BANDURG; + return (ioctl(fd, S5_I_SETSIG, i)); + } + } + } + if (cmd == F_SETFL) { + if (arg & FLAGS_MASK) { + narg = arg & ~FLAGS_MASK; + if (arg & FASYNC) + narg |= S5_FASYNC; + if (arg & O_SYNC) + narg |= N_O_SYNC; + if (arg & O_CREAT) + narg |= N_O_CREAT; + if (arg & O_TRUNC) + narg |= N_O_TRUNC; + if (arg & O_EXCL) + narg |= N_O_EXCL; + if (arg & (O_NDELAY)) + narg |= N_O_NDELAY; + if (arg & O_NONBLOCK) + narg |= N_O_NONBLOCK; + if (arg & FNBIO) + narg |= N_O_NDELAY; + arg = narg; + } + } else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) { + if (arg == 0 || arg == -1) { + errno = EFAULT; + return(-1); + } + savarg = (struct flock *)arg; + arg = (int) &nfl; + nfl.l_type = savarg->l_type; + nfl.l_whence = savarg->l_whence; + nfl.l_start = savarg->l_start; + nfl.l_len = savarg->l_len; + nfl.l_pid = savarg->l_pid; + } + + ret = _s_fcntl(fd, cmd_op[cmd], arg); + + if (ret != -1) { + if (cmd == F_DUPFD) { + if ((fds = fd_get(fd)) != -1) + fd_add(ret, fds); + } else if (cmd == F_GETFL) { + if (ret & N_FLAGS_MASK) { + narg = ret & ~N_FLAGS_MASK; + if (ret & S5_FASYNC) + narg |= FASYNC; + if (ret & N_O_SYNC) + narg |= O_SYNC; + if (ret & N_O_NONBLOCK) + narg |= O_NONBLOCK; + if (ret & N_O_CREAT) + narg |= O_CREAT; + if (ret & N_O_TRUNC) + narg |= O_TRUNC; + if (ret & N_O_EXCL) + narg |= O_EXCL; + if (ret & (N_O_NDELAY)) + narg |= O_NDELAY; + ret = narg; + } + } else if (cmd == F_SETLK || cmd == F_SETLKW || + cmd == F_GETLK) { + savarg->l_type = nfl.l_type; + savarg->l_whence = nfl.l_whence; + savarg->l_start = nfl.l_start; + savarg->l_len = nfl.l_len; + savarg->l_pid = nfl.l_pid; + arg = (int) savarg; + } + } + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/getpgrp.c b/usr/src/lib/libbc/libc/sys/4.2/getpgrp.c new file mode 100644 index 0000000000..f048fc9a0e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/getpgrp.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int getpgrp(pid) +int pid; +{ + return(getpgid(pid)); +} + diff --git a/usr/src/lib/libbc/libc/sys/4.2/link.c b/usr/src/lib/libbc/libc/sys/4.2/link.c new file mode 100644 index 0000000000..9126147c1a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/link.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +link(a, b) + char *a; + char *b; +{ + CHKNULL(a); + CHKNULL(b); + return _syscall(SYS_link, a, b); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/mkdir.c b/usr/src/lib/libbc/libc/sys/4.2/mkdir.c new file mode 100644 index 0000000000..2755d6b9d7 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/mkdir.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +mkdir(p, m) + char *p; +{ + CHKNULL(p); + return _syscall(SYS_mkdir, p, m); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/mkfifo.c b/usr/src/lib/libbc/libc/sys/4.2/mkfifo.c new file mode 100644 index 0000000000..d0fec9511b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/mkfifo.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/stat.h> +#include "chkpath.h" + +mkfifo(path, mode) + char *path; + mode_t mode; +{ + CHKNULL(path); + return mknod(path, S_IFIFO | (mode & (S_IRWXU|S_IRWXG|S_IRWXO))); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/mknod.c b/usr/src/lib/libbc/libc/sys/4.2/mknod.c new file mode 100644 index 0000000000..27e4dedbb2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/mknod.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +mknod(p, m, d) + char *p; + int m, d; +{ + CHKNULL(p); + return _syscall(SYS_mknod, p, m, d); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/mount.c b/usr/src/lib/libbc/libc/sys/4.2/mount.c new file mode 100644 index 0000000000..7b8289e4e9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/mount.c @@ -0,0 +1,166 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1997 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> +#include <sys/types.h> +#include <rpc/types.h> +#include <sys/time.h> +#include <sys/mount.h> +#include <sys/syscall.h> +#include <netinet/in.h> + + +#define GETFSIND 1 /* translate fs id to ftype index */ +#define CLIENT 1 /* #defined in <pn.h> */ +#define MS_RFFLAGS (MS_CACHE) + +/* + * Flags bits passed to mount(2), from the SVR4 sys/mount.h header file. + */ +#define MS_RDONLY 0x01 /* read only bit */ +#define MS_DATA 0x04 /* 6-argument mount */ +#define MS_NOSUID 0x10 /* Setuid programs disallowed */ +#define MS_REMOUNT 0x20 /* Remount */ +#define MS_NOTRUNC 0x40 /* Return ENAMETOOLONG for long filenames */ + +/* + * structs netbuf, knetconfig, and nfsarg from SVR4 + */ + + +struct netbuf { + unsigned int maxlen; + unsigned int len; + char *buf; +}; + +struct knetconfig { + unsigned long knc_semantics; /* token name */ + char *knc_protofmly; /* protocol family */ + char *knc_proto; /* protocol */ + dev_t knc_rdev; /* device id */ + unsigned long knc_unused[8]; +}; + +struct nfsarg { + struct netbuf *addr; /* file server address */ + /* secure NFS time sync address */ + struct netbuf *syncaddr; + /* transport knetconfig struct */ + struct knetconfig *knconf; + char *hostname; /* server's hostname */ + char *netname; /* server's netname */ + caddr_t fh; /* File handle to be mounted */ + int flags; /* flags */ + int wsize; /* write size in bytes */ + int rsize; /* read size in bytes */ + int timeo; /* initial timeout in .1 secs */ + int retrans; /* times to retry send */ + int acregmin; /* attr cache file min secs */ + int acregmax; /* attr cache file max secs */ + int acdirmin; /* attr cache dir min secs */ + int acdirmax; /* attr cache dir max secs */ +}; + +int +mount(type, dir, flags, data) +char *type, *dir; +int flags; +caddr_t data; +{ + int idx, nflags = 0; + int returnValue; + char fstr[32]; + struct nfsarg narg; + struct nfsarg *na = &narg; + struct nfs_args *nfsa; + + if (strcmp(type, "4.2") == 0) + strcpy(fstr, "ufs"); + else if (strcmp(type, "lo") == 0) + strcpy(fstr, "lo"); + else if (strcmp(type, "nfs") == 0) + strcpy(fstr, "nfs"); + + if ((idx = sysfs(GETFSIND, fstr)) == -1) + return (-1); + + nflags = MS_NOTRUNC; + switch (flags) { + case M_RDONLY: nflags |= MS_RDONLY; + case M_NOSUID: nflags |= MS_NOSUID; + case M_REMOUNT: nflags |= MS_REMOUNT; + } + + if (strcmp(type, "4.2") == 0) + return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0)); + else if (strcmp(type, "lo") == 0) + return (_syscall(SYS_mount, data, dir, nflags, idx, 0, 0)); + else if (strcmp(type, "nfs") == 0) { + nflags |= MS_DATA; + nfsa = (struct nfs_args *)data; + if ((na->addr = + (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) + return (-1); + if ((na->syncaddr = + (struct netbuf *)malloc(sizeof (struct netbuf))) == NULL) { + free(na->addr); + return (-1); + } + if ((na->knconf = +(struct knetconfig *)malloc(sizeof (struct knetconfig))) == NULL) { + free(na->addr); + free(na->syncaddr); + return (-1); + } + na->addr->maxlen = sizeof (struct sockaddr_in); + na->addr->len = na->addr->maxlen; + na->addr->buf = (char *)nfsa->addr; + na->syncaddr->maxlen = na->addr->maxlen; + na->syncaddr->len = na->syncaddr->maxlen; + na->syncaddr->buf = (char *)nfsa->addr; + strcpy(na->hostname, nfsa->hostname); + strcpy(na->netname, nfsa->netname); + na->fh = nfsa->fh; + na->flags = nfsa->flags; + na->wsize = nfsa->wsize; + na->rsize = nfsa->rsize; + na->timeo = nfsa->timeo; + na->retrans = nfsa->retrans; + na->acregmin = nfsa->acregmin; + na->acregmax = nfsa->acregmax; + na->acdirmin = nfsa->acdirmin; + na->acdirmax = nfsa->acdirmax; + returnValue = (_syscall(SYS_mount, data, dir, nflags, idx, na, + sizeof (struct nfsarg))); + free(na->addr); + free(na->syncaddr); + free(na->knconf); + return (returnValue); + } +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/open.c b/usr/src/lib/libbc/libc/sys/4.2/open.c new file mode 100644 index 0000000000..1ea83dd49e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/open.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <unistd.h> +#include <sys/fcntl.h> +#include <sys/errno.h> + +#include "chkpath.h" + +int +open(char *path, int flags, int mode) +{ + return (bc_open(path, flags, mode)); +} + +int +bc_open(char *path, int flags, int mode) +{ + CHKNULL(path); + if (flags & FNDELAY) { + flags &= ~FNDELAY; + flags |= O_NONBLOCK; + } + return (open_com(path, flags, mode)); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/pathconf.c b/usr/src/lib/libbc/libc/sys/4.2/pathconf.c new file mode 100644 index 0000000000..59de4a791b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/pathconf.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" + +pathconf(p, what) + char* p; +{ + CHKNULL(p); + return _syscall(SYS_pathconf, p, what); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/read.c b/usr/src/lib/libbc/libc/sys/4.2/read.c new file mode 100644 index 0000000000..1eaa42d661 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/read.c @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <errno.h> +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <syscall.h> + +/* + * If reading from the utmp file, map the data to the SunOS 4.1 + * format on the fly. + */ +extern int errno; + +extern void to_utmp(char *, char *, int); + +int +read(int fd, char *buf, int size) +{ + return (bc_read(fd, buf, size)); +} + +int +bc_read(int fd, char *buf, int size) +{ + int fds, ret, off; + char *nbuf; + + if (fd_get(fd) != -1) { /* we're reading utmp (utmpx, really) */ + size = getmodsize(size, sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(size)) == NULL) { + (void) fprintf(stderr, "read: malloc failed\n"); + exit(-1); + } + + if ((ret = _read(fd, nbuf, size)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + free(nbuf); + return (-1); + } + to_utmp(buf, nbuf, ret); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + free(nbuf); + return (ret); + } + + if ((ret = _read(fd, buf, size)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + } + return (ret); +} + +void +to_utmp(char *buf, char *nbuf, int len) +{ + struct compat_utmp *ut; + struct utmpx *utx; + + utx = (struct utmpx *) nbuf; + ut = (struct compat_utmp *) buf; + + while ((char *)utx < (nbuf + len)) { + (void) strncpy(ut->ut_line, utx->ut_line, sizeof (ut->ut_line)); + (void) strncpy(ut->ut_name, utx->ut_user, sizeof (ut->ut_name)); + (void) strncpy(ut->ut_host, utx->ut_host, sizeof (ut->ut_host)); + ut->ut_time = utx->ut_tv.tv_sec; + utx++; + ut++; + } +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/readlink.c b/usr/src/lib/libbc/libc/sys/4.2/readlink.c new file mode 100644 index 0000000000..2eb745c0a9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/readlink.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +readlink(p, b, s) + char *p, *b; +{ + CHKNULL(p); + return _syscall(SYS_readlink, p, b, s); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/readv.c b/usr/src/lib/libbc/libc/sys/4.2/readv.c new file mode 100644 index 0000000000..75985299e9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/readv.c @@ -0,0 +1,94 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/errno.h> +#include <sys/types.h> +#include <unistd.h> +#include <syscall.h> +#include <sys/uio.h> + +extern int errno; + +/* + * If reading from the utmp file, map the data to the SunOS 4.1 + * format on the fly. + */ +extern void to_utmp(char *, char *, int); + +int +readv(int fd, struct iovec *iov, int iovcnt) +{ + return (bc_readv(fd, iov, iovcnt)); +} + +int +bc_readv(int fd, struct iovec *iov, int iovcnt) +{ + int fds, ret, off; + int i, size, total = 0; + char *nbuf; + + if (fd_get(fd) != -1) { /* we're reading utmp (utmpx really) */ + for (i = 0; i < iovcnt; i++) { + size = getmodsize(iov[i].iov_len, + sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(size)) == NULL) { + fprintf(stderr, "readv: malloc failed\n"); + exit(-1); + } + + if ((ret = _read(fd, nbuf, size)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + free(nbuf); + return (-1); + } + + total += ret; + + to_utmp(iov[i].iov_base, nbuf, ret); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + free(nbuf); + } + + return (total); + } + + if ((ret = _readv(fd, iov, iovcnt)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + } + return (ret); + +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/rename.c b/usr/src/lib/libbc/libc/sys/4.2/rename.c new file mode 100644 index 0000000000..6b762dc450 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/rename.c @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <syscall.h> + +int rename(path1, path2) +char *path1, *path2; +{ + int ret; + char buf1[256]; + char buf2[256]; + + CHKNULL(path1); + CHKNULL(path2); + + /* + * with the removal of utmp and wtmp, we now need + * to map the utmp or wtmp rename operation into + * a rename of utmpx or wtmpx + */ + if (strcmp(path1, "/var/adm/utmp") == 0 || + strcmp(path1, "/var/adm/wtmp") == 0 || + strcmp(path1, "/etc/utmp") == 0) { + if (strcmp(path1, "/etc/utmp") == 0 || + strcmp(path1,"/var/adm/utmp") == 0) + strcpy(buf1, "/var/adm/utmpx"); + else + strcpy(buf1, "/var/adm/wtmpx"); + strcpy(buf2, path2); + strcat(buf2, "x"); + ret = _syscall(SYS_rename, buf1, buf2); + } else + ret = _syscall(SYS_rename, path1, path2); + + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/rmdir.c b/usr/src/lib/libbc/libc/sys/4.2/rmdir.c new file mode 100644 index 0000000000..1e92356c67 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/rmdir.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +rmdir(d) + char *d; +{ + int ret; + extern errno; + + CHKNULL(d); + ret = _syscall(SYS_rmdir, d); + if (errno == EEXIST) + errno = ENOTEMPTY; + return ret; +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/setgid.c b/usr/src/lib/libbc/libc/sys/4.2/setgid.c new file mode 100644 index 0000000000..5cfd0f6768 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/setgid.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +setgid(int gid) +{ + return (setregid(gid, gid)); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/setjmp.c b/usr/src/lib/libbc/libc/sys/4.2/setjmp.c new file mode 100644 index 0000000000..1373198c83 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/setjmp.c @@ -0,0 +1,93 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <sys/setjmp.h> +#include "../common/ucontext.h" + +int _getsp(); + +int +setjmp(env) + jmp_buf env; +{ + register o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + register int sp = _getsp(); + ucontext_t uc; + + /* + * Get the current machine context. + */ + uc.uc_flags = UC_STACK | UC_SIGMASK; + __getcontext(&uc); + + /* + * Note that the pc and former sp (fp) from the stack are valid + * because the call to __getcontext must flush the user windows + * to the stack. + */ + bp->sjs_flags = 0; + bp->sjs_sp = *((int *)sp+14); + bp->sjs_pc = *((int *)sp+15) + 0x8; + bp->sjs_stack = uc.uc_stack; + + /* save the mask */ + bp->sjs_flags |= JB_SAVEMASK; + memcpy(bp->sjs_sigmask, &(uc.uc_sigmask), 3 * sizeof (int)); + + return (0); +} + + + +void +longjmp(env, val) + jmp_buf env; + int val; +{ + o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + setjmp_struct_t sjmp, *sp; + + sp = &sjmp; + sp->sjs_flags = bp->sjs_flags; + sp->sjs_sp = bp->sjs_sp; + sp->sjs_pc = bp->sjs_pc; + sp->sjs_fp = 0; + sp->sjs_i7 = 0; + sp->sjs_uclink = 0; + sp->sjs_sigmask[0] = bp->sjs_sigmask[0]; + sp->sjs_sigmask[1] = bp->sjs_sigmask[1]; + sp->sjs_sigmask[2] = bp->sjs_sigmask[2]; + sp->sjs_sigmask[3] = 0; + sp->sjs_stack = bp->sjs_stack; + _siglongjmp(sjmp, val); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/setpgrp.c b/usr/src/lib/libbc/libc/sys/4.2/setpgrp.c new file mode 100644 index 0000000000..a22315b026 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/setpgrp.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int setpgrp(pid, pgrp) +int pid, pgrp; +{ + if ((pgrp == 0) && (pid == getpid())) { + return(bc_setsid()); + } else + return(setpgid(pid, pgrp)); +} + + diff --git a/usr/src/lib/libbc/libc/sys/4.2/setuid.c b/usr/src/lib/libbc/libc/sys/4.2/setuid.c new file mode 100644 index 0000000000..5b290dc922 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/setuid.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +setuid(int uid) +{ + return (setreuid(uid, uid)); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/stat.c b/usr/src/lib/libbc/libc/sys/4.2/stat.c new file mode 100644 index 0000000000..dc930d2c16 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/stat.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <sys/stat.h> + +extern int errno; + +int stat(path, buf) +char *path; +struct stat *buf; +{ + return(bc_stat(path, buf)); +} + + +int bc_stat(path, buf) +char *path; +struct stat *buf; +{ + if ((path == (char*)-1) || (path == (char*)0)) { + errno = EFAULT; + return (-1); + } + if ((buf == (struct stat*)0) || (buf == (struct stat*)-1)) { + errno = EFAULT; + return (-1); + } + return(stat_com(SYS_stat, path, buf)); +} + + +int lstat(path, buf) +char *path; +struct stat *buf; +{ + return(bc_lstat(path, buf)); +} + +int bc_lstat(path, buf) +char *path; +struct stat *buf; +{ + CHKNULL(path); + return(stat_com(SYS_lstat, path, buf)); +} + diff --git a/usr/src/lib/libbc/libc/sys/4.2/statfs.c b/usr/src/lib/libbc/libc/sys/4.2/statfs.c new file mode 100644 index 0000000000..7518c48cf9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/statfs.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <sys/types.h> +#include <sys/vfs.h> + +statfs(s, b) + char *s; + struct statfs *b; +{ + CHKNULL(s); + + return(statfs_com(s, b)); +} + diff --git a/usr/src/lib/libbc/libc/sys/4.2/symlink.c b/usr/src/lib/libbc/libc/sys/4.2/symlink.c new file mode 100644 index 0000000000..eafd8febb1 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/symlink.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +# include "chkpath.h" + +symlink(t, f) + char *t, *f; +{ + CHKNULL(t); + CHKNULL(f); + return _syscall(SYS_symlink, t, f); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/truncate.c b/usr/src/lib/libbc/libc/sys/4.2/truncate.c new file mode 100644 index 0000000000..4e5981abbd --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/truncate.c @@ -0,0 +1,60 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "chkpath.h" +#include <syscall.h> +#include <unistd.h> +#include <errno.h> +#include <sys/fcntl.h> +#include <sys/param.h> + +extern int errno; + +int truncate(path, length) +char *path; +off_t length; +{ + int fd, ret=0; + + CHKNULL(path); + + if (strcmp(path, "/etc/mtab") == 0 || strcmp(path, "/etc/fstab") == 0) { + errno = ENOENT; + return(-1); + } + if ((fd = open(path, O_WRONLY)) == -1) { + return(-1); + } + + if (ftruncate(fd, length) == -1) { + close(fd); + return(-1); + } + close(fd); + return(0); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/unlink.c b/usr/src/lib/libbc/libc/sys/4.2/unlink.c new file mode 100644 index 0000000000..a11e96e301 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/unlink.c @@ -0,0 +1,58 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <sys/errno.h> + +int unlink(char *path) +{ + int ret; + char buf[256]; + extern int errno; + char dot[2] = {'.','\n'}; + + if (path == (char *) 0) { + errno = EFAULT; + return(-1); + } else if (strcmp(path, "") == 0) + path = dot; + + else if (strcmp(path, "/var/adm/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0 || + strcmp(path, "/etc/utmp") == 0) { + if (strcmp(path, "/etc/utmp") == 0 || + strcmp(path, "/var/adm/utmp") == 0) + strcpy(buf, "/var/adm/utmpx"); + else + strcpy(buf, "/var/adm/wtmpx"); + ret = _syscall(SYS_unlink, buf); + } else + ret = _syscall(SYS_unlink, path); + + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/write.c b/usr/src/lib/libbc/libc/sys/4.2/write.c new file mode 100644 index 0000000000..4180aacbe7 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/write.c @@ -0,0 +1,127 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/errno.h> +#include <sys/types.h> +#include <unistd.h> + +/* + * If writing to a utmp-like file, map the utmp structure to + * new format on the fly. + */ +extern int errno; + +extern int conv2utmp(char *, char *, int); +extern int conv2utmpx(char *, char *, int); + +int +write(int fd, char *buf, int size) +{ + return (bc_write(fd, buf, size)); +} + +int +bc_write(int fd, char *buf, int size) +{ + int ret, off; + int nsize; + char *nbuf; + + if (fd_get(fd) != -1) { /* writing utmp (utmpx actually) */ + nsize = getmodsize(size, sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(nsize)) == NULL) { + (void) fprintf(stderr, "write: malloc failed\n"); + exit(-1); + } + + (void) memset(nbuf, 0, nsize); + + ret = conv2utmpx(nbuf, buf, size); + + if ((ret = _write(fd, nbuf, ret)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + free(nbuf); + return (-1); + } + + free(nbuf); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + + return (ret); + } + + if ((ret = _write(fd, buf, size)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + } + return (ret); + +} + +/* From SunOS/SVR4 utmp.h */ +#define USER_PROCESS 7 +#define DEAD_PROCESS 8 + +extern int +conv2utmpx(char *nbuf, char *buf, int len) +{ + struct compat_utmp *ut; + struct utmpx *utx; + + utx = (struct utmpx *) nbuf; + ut = (struct compat_utmp *) buf; + + while ((char *)ut < (buf + len)) { + (void) strcpy(utx->ut_user, ut->ut_name); + (void) memset(utx->ut_id, 0, sizeof (utx->ut_id)); + (void) strcpy(utx->ut_line, ut->ut_line); + utx->ut_pid = 0; + if ((strcmp(utx->ut_user, "") == 0) && + (strcmp(utx->ut_host, "") == 0)) + utx->ut_type = DEAD_PROCESS; + else + utx->ut_type = USER_PROCESS; + utx->ut_exit.e_termination = 0; + utx->ut_exit.e_exit = 0; + utx->ut_tv.tv_sec = ut->ut_time; + utx->ut_tv.tv_usec = 0; + utx->ut_session = 0; + utx->ut_syslen = sizeof (ut->ut_name) + 1; + (void) strcpy(utx->ut_host, ut->ut_host); + ut++; + utx++; + } + return ((char *) utx - nbuf); +} diff --git a/usr/src/lib/libbc/libc/sys/4.2/writev.c b/usr/src/lib/libbc/libc/sys/4.2/writev.c new file mode 100644 index 0000000000..4bfbbe0d33 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/4.2/writev.c @@ -0,0 +1,99 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/errno.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/uio.h> + +/* + * If writing to a utmp-like file, map the utmp structure to + * new format on the fly. + */ +extern int errno; + +extern int conv2utmpx(char *, char *, int); + +int +writev(int fd, struct iovec *iov, int iovcnt) +{ + return (bc_writev(fd, iov, iovcnt)); +} + +int +bc_writev(int fd, struct iovec *iov, int iovcnt) +{ + int ret, off; + int nsize, total = 0; + char *nbuf; + int i; + + if (fd_get(fd) != -1) { /* writing utmp (utmpx, actually) */ + for (i = 0; i < iovcnt; i++) { + nsize = getmodsize(iov[i].iov_len, + sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(nsize)) == NULL) { + fprintf(stderr, "writev: malloc failed\n"); + exit(-1); + } + + (void) memset(nbuf, 0, nsize); + + ret = conv2utmpx(nbuf, iov[i].iov_base, iov[i].iov_len); + + if ((ret = _write(fd, nbuf, ret)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + free(nbuf); + return (-1); + } + + total += ret; + + free(nbuf); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + + } + total = getmodsize(total, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + return (total); + } + + if ((ret = _writev(fd, iov, iovcnt)) == -1) { + if (errno == EAGAIN) + errno = EWOULDBLOCK; + } + + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/_access.c b/usr/src/lib/libbc/libc/sys/common/_access.c new file mode 100644 index 0000000000..4ce2a1ca56 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/_access.c @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <unistd.h> +#include <sys/param.h> + +int access_com(char *path, int mode) +{ + int ret=0; + char buf[MAXPATHLEN+100]; + + if (strcmp(path, "/etc/mtab") == 0 || + strcmp(path, "/etc/fstab") == 0) { + if (mode == W_OK || mode == X_OK) + return(-1); + else return(0); + } else if (strcmp(path, "/var/adm/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0) { + strcpy(buf, path); + strcat(buf, "x"); + return(_syscall(SYS_access, buf, mode)); + } else if (strcmp(path, "/etc/utmp") == 0) { + strcpy(buf, "/var/adm/utmpx"); + return(_syscall(SYS_access, buf, mode)); + } else + return(_syscall(SYS_access, path, mode)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/_creat.c b/usr/src/lib/libbc/libc/sys/common/_creat.c new file mode 100644 index 0000000000..1f2181cc81 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/_creat.c @@ -0,0 +1,66 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <unistd.h> +#include <errno.h> +#include <sys/param.h> +#include "compat.h" /* for UTMPX_MAGIC_FLAG */ + +extern int errno; + +int creat_com(char *path, int mode) +{ + int ret=0; + int fd, fd2; + char buf[MAXPATHLEN+100]; + + if (strcmp(path, "/etc/mtab") == 0 || + strcmp(path, "/etc/fstab") == 0) { + errno = ENOENT; + return(-1); + } + if (strcmp(path, "/var/adm/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0) { + strcpy(buf, path); + strcat(buf, "x"); + if ((fd = _syscall(SYS_creat, buf, mode)) >= 0) { + fd2 = UTMPX_MAGIC_FLAG; + fd_add(fd, fd2); + } + return(fd); + } else if (strcmp(path, "/etc/utmp") == 0) { + strcpy(buf, "/var/adm/utmpx"); + if ((fd = _syscall(SYS_creat, buf, mode)) >= 0) { + fd2 = UTMPX_MAGIC_FLAG; + fd_add(fd, fd2); + } + return(fd); + } else + return(_syscall(SYS_creat, path, mode)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/_open.c b/usr/src/lib/libbc/libc/sys/common/_open.c new file mode 100644 index 0000000000..a144c8c307 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/_open.c @@ -0,0 +1,417 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1999-2002 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <fcntl.h> +#include <strings.h> +#include <mntent.h> +#include <syscall.h> +#include <sys/param.h> +#include <sys/sysmacros.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <dirent.h> +#include "s5sysmacros.h" +#include "compat.h" + +#define PRINTER_DIR "/etc/lp/printers/" +#define PRINTER_CONFIG_FILE "/configuration" +#define MNT_LINE_MAX 1024 + +#define GETTOK(xx, ll) \ + if ((xx = strtok(ll, sepstr)) == NULL) \ + return (-1); \ + if (strcmp(xx, dash) == 0) \ + xx = NULL + +char *mktemp(); +char *strtok(); +static void getPrinterInfo(char *, FILE *); +static char sepstr[] = " \t\n"; +static char dash[] = "-"; + +/* SVR4/SunOS 5.0 equivalent modes */ +#define N_O_NDELAY 0x04 +#define N_O_SYNC 0x10 +#define N_O_NONBLOCK 0x80 +#define N_O_CREAT 0x100 +#define N_O_TRUNC 0x200 +#define N_O_EXCL 0x400 + +/* Mask corresponding to the bits above in SunOS 4.x */ +#define FLAGS_MASK (O_SYNC|O_NONBLOCK|O_CREAT|O_TRUNC|O_EXCL \ + |_FNDELAY|_FNBIO) + +int +open_com(char *path, int flags, int mode) +{ + int fd, fd2, pathl, inspt, ret = 0; + int nflags = flags; + char loc[] = "/lib/locale"; + char *loct = NULL; + + if (flags & FLAGS_MASK) { + nflags = flags & ~FLAGS_MASK; + if (flags & O_SYNC) + nflags |= N_O_SYNC; + if (flags & (_FNDELAY|O_NONBLOCK)) { + nflags |= N_O_NONBLOCK; + } + if (flags & O_CREAT) + nflags |= N_O_CREAT; + if (flags & O_TRUNC) + nflags |= N_O_TRUNC; + if (flags & O_EXCL) + nflags |= N_O_EXCL; + if (flags & _FNBIO) + nflags |= N_O_NDELAY; + } + +/* change path from ..../lib/locale/.... to ..../lib/oldlocale/.... XXX */ + + if ((loct = (char *)_strstr(path, loc)) != NULL) { /* /lib/locale ? */ + char locbuf[MAXPATHLEN+100]; /* to hold new locale path */ + + pathl = strlen(path); + inspt = pathl - strlen(loct) + 5; /* pos to add "old" */ + (void) strncpy(locbuf, path, inspt); /* copy path upto lib */ + locbuf[inspt] = '\0'; /* make it a string */ + strcat(locbuf, "old"); /* add "old" */ + strcat(locbuf, loct+5); /* add remainer of path */ + return (_syscall(SYS_open, locbuf, nflags, mode)); + } + + if (strcmp(path, "/etc/mtab") == 0) { + return (open_mnt("/etc/mnttab", "mtab", nflags, mode)); + } else if (strcmp(path, "/etc/fstab") == 0) { + return (open_mnt("/etc/vfstab", "fstab", nflags, mode)); + } else if (strcmp(path, "/etc/printcap") == 0) { + if ((fd = _syscall(SYS_open, path, + nflags, mode)) != -1) + return (fd); + return (open_printcap()); + } else if (strcmp(path, "/etc/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0) { + char buf[MAXPATHLEN+100]; + if (strcmp(path, "/etc/utmp") == 0) + strcpy(buf, "/var/adm/utmpx"); + else + strcpy(buf, "/var/adm/wtmpx"); + if ((fd = _syscall(SYS_open, buf, + nflags, mode)) == -1) + return (-1); + fd2 = UTMPX_MAGIC_FLAG; + fd_add(fd, fd2); + return (fd); + } else + return (_syscall(SYS_open, path, nflags, mode)); +} + +int +open_mnt(char *fname, char *tname, int flags, int mode) +{ + FILE *fd_in, *fd_out; + FILE *_fopen(); + char tmp_name[64]; + char line[MNT_LINE_MAX]; + int fd; + + if ((fd_in = _fopen(fname, "r")) == NULL) + return (-1); + + sprintf(tmp_name, "%s%s%s", "/tmp/", tname, "XXXXXX"); + mktemp(tmp_name); + + if ((fd_out = _fopen(tmp_name, "a+")) == NULL) { + fclose(fd_in); + return (-1); + } + + while (getmntline(line, fd_in) != -1) { + if (strcmp(fname, "/etc/mnttab") == 0) { + if (putmline(line, fd_out) == -1) { + fclose(fd_in); + fclose(fd_out); + return (-1); + } + } else /* processing vfstab */ + if (putfline(line, fd_out) == -1) { + fclose(fd_in); + fclose(fd_out); + return (-1); + } + } + + if (feof(fd_in)) { + fclose(fd_in); + fclose(fd_out); + + fd = _syscall(SYS_open, tmp_name, O_RDONLY); + + if (fd == -1 || unlink(tmp_name) == -1) + return (-1); + + return (fd); + } else { + fclose(fd_in); + fclose(fd_out); + return (-1); + } +} + + +int +getmntline(char *lp, FILE *fp) +{ + int ret; + char *cp; + + while ((lp = fgets(lp, MNT_LINE_MAX, fp)) != NULL) { + if (strlen(lp) == MNT_LINE_MAX-1 && lp[MNT_LINE_MAX-2] != '\n') + return (-1); + for (cp = lp; *cp == ' ' || *cp == '\t'; cp++) + ; + if (*cp != '#' && *cp != '\n') + return (0); + } + return (-1); +} + +int +putmline(char *line, FILE *fp) +{ + struct mntent mnt; + char *buf; + char *devnumstr = 0; /* the device number, in (hex) ascii */ + char *remainder; /* remainder of mnt_opts string, after devnum */ + unsigned long devnum; + + GETTOK(mnt.mnt_fsname, line); + GETTOK(mnt.mnt_dir, NULL); + GETTOK(mnt.mnt_type, NULL); + GETTOK(mnt.mnt_opts, NULL); + GETTOK(buf, NULL); + mnt.mnt_freq = 0; + mnt.mnt_passno = 0; + + if (strtok(NULL, sepstr) != NULL) + return (-1); + if (strcmp(mnt.mnt_type, "ufs") == 0) { + mnt.mnt_type = "4.2"; + } + + /* + * the device number, if present, follows the '=' + * in the mnt_opts string. + */ + + if (mnt.mnt_opts != NULL) + devnumstr = (char *)strchr(mnt.mnt_opts, '='); + + if (!devnumstr) { + /* no device number on this line */ + fprintf(fp, "%s %s %s %s %d %d\n", + mnt.mnt_fsname, mnt.mnt_dir, mnt.mnt_type, + mnt.mnt_opts, mnt.mnt_freq, mnt.mnt_passno); + } else { + /* found the device number, convert it to 4.x format */ + devnum = strtol(&devnumstr[1], (char **)NULL, 16); + remainder = (char *)strchr(&devnumstr[1], ' '); + devnumstr[1] = 0; /* null terminate mnt_opts after '=' */ + devnum = cmpdev(devnum); + + fprintf(fp, "%s %s %s %s%4x%s %d %d\n", + mnt.mnt_fsname, mnt.mnt_dir, mnt.mnt_type, + mnt.mnt_opts, devnum, remainder ? remainder : "", + mnt.mnt_freq, mnt.mnt_passno); + } + + return (0); +} + +int +putfline(char *line, FILE *fp) +{ + struct mntent mnt; + char *buf; + + GETTOK(mnt.mnt_fsname, line); + GETTOK(buf, NULL); + GETTOK(mnt.mnt_dir, NULL); + if (mnt.mnt_dir == NULL && strcmp(mnt.mnt_fsname, "/dev/root") == 0) + mnt.mnt_dir = "/"; + GETTOK(mnt.mnt_type, NULL); + GETTOK(buf, NULL); + GETTOK(buf, NULL); + GETTOK(mnt.mnt_opts, NULL); + if (mnt.mnt_opts == NULL) + mnt.mnt_opts = "rw"; + mnt.mnt_freq = 0; + mnt.mnt_passno = 0; + + if (strtok(NULL, sepstr) != NULL) + return (-1); + if (strcmp(mnt.mnt_type, "ufs") == 0) { + mnt.mnt_type = "4.2"; + } + + fprintf(fp, "%s %s %s %s %d %d\n", + mnt.mnt_fsname, mnt.mnt_dir, mnt.mnt_type, + mnt.mnt_opts, mnt.mnt_freq, mnt.mnt_passno); + + return (0); +} + + +FILE * +_fopen(char *file, char *mode) +{ + extern FILE *_findiop(); + FILE *iop; + + register int plus, oflag, fd; + + iop = _findiop(); + + if (iop == NULL || file == NULL || file[0] == '\0') + return (NULL); + plus = (mode[1] == '+'); + switch (mode[0]) { + case 'w': + oflag = (plus ? O_RDWR : O_WRONLY) | N_O_TRUNC | N_O_CREAT; + break; + case 'a': + oflag = (plus ? O_RDWR : O_WRONLY) | N_O_CREAT; + break; + case 'r': + oflag = plus ? O_RDWR : O_RDONLY; + break; + default: + return (NULL); + } + if ((fd = _syscall(SYS_open, file, oflag, 0666)) < 0) + return (NULL); + iop->_cnt = 0; + iop->_file = fd; + iop->_flag = plus ? _IORW : (mode[0] == 'r') ? _IOREAD : _IOWRT; + if (mode[0] == 'a') { + if ((lseek(fd, 0L, 2)) < 0) { + (void) close(fd); + return (NULL); + } + } + iop->_base = iop->_ptr = NULL; + iop->_bufsiz = 0; + return (iop); +} + +static int +open_printcap() +{ + FILE *fd; + FILE *_fopen(); + char tmp_name[] = "/tmp/printcap.XXXXXX"; + int tmp_file; + DIR *printerDir; + struct dirent *entry; + + mktemp(tmp_name); + if ((fd = _fopen(tmp_name, "a+")) == NULL) + return (-1); + fprintf(fd, "# Derived from lp(1) configuration information for BCP\n"); + + if ((printerDir = opendir(PRINTER_DIR)) != NULL) { + while ((entry = readdir(printerDir)) != NULL) + if (entry->d_name[0] != '.') + getPrinterInfo(entry->d_name, fd); + closedir(printerDir); + } + fclose(fd); + + tmp_file = _syscall(SYS_open, tmp_name, O_RDONLY); + if (tmp_file == -1 || unlink(tmp_name) == -1) + return (-1); + + return (tmp_file); +} + + +static void +getPrinterInfo(char *printerName, FILE *fd) +{ + char *fullPath; + char *str; + char *p; + char *c; + struct stat buf; + int config_fd; + + fullPath = (char *)malloc(strlen(PRINTER_DIR) + strlen(printerName) + + strlen(PRINTER_CONFIG_FILE) + 1); + strcpy(fullPath, PRINTER_DIR); + strcat(fullPath, printerName); + strcat(fullPath, PRINTER_CONFIG_FILE); + + if ((config_fd = _syscall(SYS_open, fullPath, O_RDONLY)) == -1) { + free(fullPath); + return; + } + if ((fstat(config_fd, &buf)) != 0 || + (str = (char *)malloc(buf.st_size + 2)) == NULL) { + free(fullPath); + close(config_fd); + return; + } + if ((read(config_fd, str, buf.st_size)) != buf.st_size) { + free(fullPath); + free(str); + close(config_fd); + return; + } + p = &str[buf.st_size]; + p[0] = '\n'; + p[1] = '\0'; + + fprintf(fd, "%s:", printerName); + if ((p = (char *)_strstr(str, "Remote")) != NULL) { + /* remote printer */ + p = (char *)strchr(p, ' ') + 1; + c = (char *)strchr(p, '\n'); + *c = '\0'; + fprintf(fd, "lp=:rm=%s:rp=%s:\n", p, printerName); + } else if ((p = (char *)_strstr(str, "Device")) != NULL) { + /* local printer */ + p = (char *)strchr(p, ' ') + 1; + c = (char *)strchr(p, '\n'); + *c = '\0'; + fprintf(fd, "lp=%s:\n", p); + } + free(fullPath); + free(str); + close(config_fd); +} diff --git a/usr/src/lib/libbc/libc/sys/common/_stat.c b/usr/src/lib/libbc/libc/sys/common/_stat.c new file mode 100644 index 0000000000..cdbab6d0ed --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/_stat.c @@ -0,0 +1,184 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/errno.h> +#include <sys/syscall.h> +#include <sys/fcntl.h> +#include <sys/stat.h> +#include <sys/param.h> +#include "compat.h" +#include "s5sysmacros.h" + +#define ST_FSTYPSZ 16 /* array size for file system type name */ + +struct ts { + long tv_sec; /* seconds */ + long tv_nsec; /* nanoseconds */ +}; + +struct n_stat { + unsigned long st_dev; + long st_pad1[3]; /* reserved for network id */ + unsigned long st_ino; + unsigned long st_mode; + unsigned long st_nlink; + long st_uid; + long st_gid; + unsigned long st_rdev; + long st_pad2[2]; + long st_size; + long st_pad3; /* future off_t expansion */ + struct ts st_atim; + struct ts st_mtim; + struct ts st_ctim; + long st_blksize; + long st_blocks; + char st_fstype[ST_FSTYPSZ]; + long st_pad4[8]; /* expansion area */ + +}; + +static void cpstatbuf(struct stat *, struct n_stat *); + +int +fstat(int fd, struct stat *buf) +{ + return (bc_fstat(fd, buf)); +} + +int +bc_fstat(int fd, struct stat *buf) +{ + int ret; + struct n_stat nb; + extern int errno; + + if (buf == 0) { + errno = EFAULT; + return (-1); + } + + if ((ret = _syscall(SYS_fstat, fd, &nb)) == -1) + return (ret); + + cpstatbuf(buf, &nb); + if (fd_get(fd) != -1) { + buf->st_size = getmodsize(buf->st_size, + sizeof (struct utmpx), sizeof(struct compat_utmp)); + } + + return (ret); +} + +int +stat_com(int sysnum, char *path, struct stat *buf) +{ + int fd, ret; + struct n_stat nb; + + if (strcmp(path, "/etc/mtab") == 0) { +/* + * stat the real mnttab, or the "parsed" mtab + * created by open? + * + * for now, stat the real mnttab. + */ + +/* + * fd = open_mnt("/etc/mnttab", "mtab", O_RDONLY); + * ret = fstat(fd, buf); + * close(fd); + * return(ret); + */ + ret = stat_com(sysnum, "/etc/mnttab", buf); + return(ret); + } else if (strcmp(path, "/etc/fstab") == 0) { + fd = open_mnt("/etc/vfstab", "fstab", O_RDONLY); + ret = fstat(fd, buf); + close(fd); + return(ret); + } else if (strcmp(path, "/var/adm/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0 || + strcmp(path, "/etc/utmp") == 0) { + char pathx[MAXPATHLEN+100]; + if (strcmp(path, "/etc/utmp") == 0) + strcpy(pathx, "/var/adm/utmpx"); + else { + strcpy(pathx, path); + strcat(pathx, "x"); + } + if ((ret = _syscall(sysnum, pathx, &nb)) == -1) + return(-1); + else { + buf->st_size = getmodsize(buf->st_size, + sizeof(struct compat_utmp), sizeof(struct utmpx)); + cpstatbuf(buf, &nb); + return(ret); + } + } else if (_strstr(path, "/lib/locale/") != 0) { + fd = open(path, O_RDONLY); + ret = fstat(fd, buf); + close(fd); + return(ret); + } else { + if ((ret = _syscall(sysnum, path, &nb)) != -1) + cpstatbuf(buf, &nb); + return(ret); + } +} + + +/* + * Common code to copy xstat buf to BSD style buf + */ +static void +cpstatbuf(struct stat *bsdbuf, struct n_stat *nbuf) +{ + bsdbuf->st_dev = (dev_t) cmpdev(nbuf->st_dev); + bsdbuf->st_ino = nbuf->st_ino; + bsdbuf->st_mode = (unsigned short) nbuf->st_mode; + bsdbuf->st_nlink = (short) nbuf->st_nlink; + + if ((unsigned long)nbuf->st_uid > 0xffff) + bsdbuf->st_uid = 60001; /* UID_NOBODY */ + else + bsdbuf->st_uid = (uid_t) nbuf->st_uid; + + if ((unsigned long)nbuf->st_gid > 0xffff) + bsdbuf->st_gid = 60001; /* GID_NOBODY */ + else + bsdbuf->st_gid = (gid_t) nbuf->st_gid; + + bsdbuf->st_rdev = (dev_t) cmpdev(nbuf->st_rdev); + bsdbuf->st_size = nbuf->st_size; + bsdbuf->st_atime = nbuf->st_atim.tv_sec; + bsdbuf->st_mtime = nbuf->st_mtim.tv_sec; + bsdbuf->st_ctime = nbuf->st_ctim.tv_sec; + bsdbuf->st_blksize = nbuf->st_blksize; + bsdbuf->st_blocks = nbuf->st_blocks; +} diff --git a/usr/src/lib/libbc/libc/sys/common/_statfs.c b/usr/src/lib/libbc/libc/sys/common/_statfs.c new file mode 100644 index 0000000000..bda893e7a8 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/_statfs.c @@ -0,0 +1,96 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/vfs.h> +#include <sys/syscall.h> + +#define FSTYPSZ 16 /* array size for file system type name */ + +struct statvfs { + u_long f_bsize; /* fundamental file system block size */ + u_long f_frsize; /* fragment size */ + u_long f_blocks; /* total # of blocks of f_frsize on fs */ + u_long f_bfree; /* total # of free blocks of f_frsize */ + u_long f_bavail; /* # of free blocks avail to non-superuser */ + u_long f_files; /* total # of file nodes (inodes) */ + u_long f_ffree; /* total # of free file nodes */ + u_long f_favail; /* # of free nodes avail to non-superuser */ + u_long f_fsid; /* file system id (dev for now) */ + char f_basetype[FSTYPSZ]; /* target fs type name, null-terminated */ + u_long f_flag; /* bit-mask of flags */ + u_long f_namemax; /* maximum file name length */ + char f_fstr[32]; /* filesystem-specific string */ + u_long f_filler[16]; /* reserved for future expansion */ +}; + + +statfs_com(s, b) + char *s; + struct statfs *b; +{ + int ret; + struct statvfs vfsb; + + if ((ret = _syscall(SYS_statvfs, s, &vfsb)) == 0) { + cpstatvfs(b, &vfsb); + } + return(ret); +} + +fstatfs(fd, b) + int fd; + struct statfs *b; +{ + int ret; + struct statvfs vfsb; + + if ((ret = _syscall(SYS_fstatvfs,fd, &vfsb)) == 0) { + cpstatvfs(b, &vfsb); + } + return(ret); +} + +/* + * Common code to copy vfs buf to BSD style buf + */ +cpstatvfs(bsdbuf, vbuf) + struct statfs *bsdbuf; + struct statvfs *vbuf; +{ + bsdbuf->f_type = (long) 0; /* type of info, zero for now */ + bsdbuf->f_bsize = (vbuf->f_frsize != 0) ? + (long) vbuf->f_frsize: (long) vbuf->f_bsize; + bsdbuf->f_blocks = (long) vbuf->f_blocks; + bsdbuf->f_bfree = (long) vbuf->f_bfree; + bsdbuf->f_bavail = (long) vbuf->f_bavail; + bsdbuf->f_files = (long) vbuf->f_files; + bsdbuf->f_ffree = (long) vbuf->f_ffree; + bsdbuf->f_fsid.val[0] = vbuf->f_fsid; + bsdbuf->f_fsid.val[1] = 0; +} diff --git a/usr/src/lib/libbc/libc/sys/common/accept.c b/usr/src/lib/libbc/libc/sys/common/accept.c new file mode 100644 index 0000000000..d33199d6b5 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/accept.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/errno.h> + +#define N_AGAIN 11 + +extern int errno; + +accept(s, addr, addrlen) +int s; +struct sockaddr *addr; +int *addrlen; +{ + int a; + if ((a = _accept(s, addr, addrlen)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(errno); + } + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/bind.c b/usr/src/lib/libbc/libc/sys/common/bind.c new file mode 100644 index 0000000000..65803a2d9a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/bind.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1996, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#include <sys/errno.h> +#include <sys/types.h> +#include <sys/socket.h> + +#pragma ident "%Z%%M% %I% %E% SMI" /* optional comment */ + +extern int errno; + +#define SOV_SOCKBSD 3 + +bind(s, name, namelen) +int s; +struct sockaddr *name; +int namelen; +{ + int a; + if ((a = _so_bind(s, name, namelen, SOV_SOCKBSD)) != 0) { + maperror(errno); + } + return (a); +} diff --git a/usr/src/lib/libbc/libc/sys/common/cdioctl.h b/usr/src/lib/libbc/libc/sys/common/cdioctl.h new file mode 100644 index 0000000000..25d0656709 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/cdioctl.h @@ -0,0 +1,149 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1989 Sun Microsystems, Inc. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * + * Defines for SCSI direct access devices modified for CDROM, based on sddef.h + * + */ + +/* + * CDROM io controls type definitions + */ +struct cdrom_msf { + unsigned char cdmsf_min0; /* starting minute */ + unsigned char cdmsf_sec0; /* starting second */ + unsigned char cdmsf_frame0; /* starting frame */ + unsigned char cdmsf_min1; /* ending minute */ + unsigned char cdmsf_sec1; /* ending second */ + unsigned char cdmsf_frame1; /* ending frame */ +}; + +struct cdrom_ti { + unsigned char cdti_trk0; /* starting track */ + unsigned char cdti_ind0; /* starting index */ + unsigned char cdti_trk1; /* ending track */ + unsigned char cdti_ind1; /* ending index */ +}; + +struct cdrom_tochdr { + unsigned char cdth_trk0; /* starting track */ + unsigned char cdth_trk1; /* ending track */ +}; + +struct cdrom_tocentry { + unsigned char cdte_track; + unsigned char cdte_adr :4; + unsigned char cdte_ctrl :4; + unsigned char cdte_format; + union { + struct { + unsigned char minute; + unsigned char second; + unsigned char frame; + } msf; + int lba; + } cdte_addr; + unsigned char cdte_datamode; +}; + +struct cdrom_subchnl { + unsigned char cdsc_format; + unsigned char cdsc_audiostatus; + unsigned char cdsc_adr: 4; + unsigned char cdsc_ctrl: 4; + unsigned char cdsc_trk; + unsigned char cdsc_ind; + union { + struct { + unsigned char minute; + unsigned char second; + unsigned char frame; + } msf; + int lba; + } cdsc_absaddr; + union { + struct { + unsigned char minute; + unsigned char second; + unsigned char frame; + } msf; + int lba; + } cdsc_reladdr; +}; + +/* + * definition of audio volume control structure + */ +struct cdrom_volctrl { + unsigned char channel0; + unsigned char channel1; + unsigned char channel2; + unsigned char channel3; +}; + +struct cdrom_read { + int cdread_lba; + caddr_t cdread_bufaddr; + int cdread_buflen; +}; + +/* + * CDROM io control commands + */ +#define CDROMPAUSE _IO(c, 10) /* Pause Audio Operation */ + +#define CDROMRESUME _IO(c, 11) /* Resume paused Audio Operation */ + +#define CDROMPLAYMSF _IOW(c, 12, struct cdrom_msf) /* Play Audio MSF */ +#define CDROMPLAYTRKIND _IOW(c, 13, struct cdrom_ti) /* + * Play Audio +` * Track/index + */ +#define CDROMREADTOCHDR \ + _IOR(c, 103, struct cdrom_tochdr) /* Read TOC header */ +#define CDROMREADTOCENTRY \ + _IOWR(c, 104, struct cdrom_tocentry) /* Read a TOC entry */ + +#define CDROMSTOP _IO(c, 105) /* Stop the cdrom drive */ + +#define CDROMSTART _IO(c, 106) /* Start the cdrom drive */ + +#define CDROMEJECT _IO(c, 107) /* Ejects the cdrom caddy */ + +#define CDROMVOLCTRL \ + _IOW(c, 14, struct cdrom_volctrl) /* control output volume */ + +#define CDROMSUBCHNL \ + _IOWR(c, 108, struct cdrom_subchnl) /* read the subchannel data */ + +#define CDROMREADMODE2 \ + _IOW(c, 110, struct cdrom_read) /* read CDROM mode 2 data */ + +#define CDROMREADMODE1 \ + _IOW(c, 111, struct cdrom_read) /* read CDROM mode 1 data */ + diff --git a/usr/src/lib/libbc/libc/sys/common/close.c b/usr/src/lib/libbc/libc/sys/common/close.c new file mode 100644 index 0000000000..2cdc0b74ba --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/close.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> + +int +close(int fd) +{ + return(bc_close(fd)); +} + +int +bc_close(int fd) +{ + fd_rem(fd); + return(_syscall(SYS_close, fd)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/compat.h b/usr/src/lib/libbc/libc/sys/common/compat.h new file mode 100644 index 0000000000..df1ac6c4d2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/compat.h @@ -0,0 +1,83 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <utmp.h> +#include <sys/types.h> +#include <sys/time.h> + +/* + * the following value will be stuffed into "fd2", which was previously + * used to hold the fd of the utmpx or wtmpx file when the application + * attempted to open utmp or wtmp. Since we now only support utmpx + * and wtmpx, that is always the only file we open (now as "fd"). + * The magic value in the second descriptor simply tells us that + * the fd is "special", in that we have to do utmp to utmpx + * record conversions on data read or written. The magic value + * is specifically chosen to be higher than any possible fd value + * could be in a 4.x application. + */ + +#define UTMPX_MAGIC_FLAG 512 + +/* + * 4.x utmp record format + */ +struct compat_utmp + { + char ut_line[8]; /* tty name */ + char ut_name[8]; /* user id */ + char ut_host[16]; /* host name, if remote */ + time_t ut_time; /* time on */ + } ; + + +struct exit_status +{ + short e_termination; /* termination status */ + short e_exit; /* exit status */ +} ; + +struct utmpx + { + char ut_user[32]; /* user login name */ + char ut_id[4]; /* inittab id */ + char ut_line[32]; /* device name (console, lnxx) */ + long ut_pid; /* process id */ + short ut_type; /* type of entry */ + struct exit_status ut_exit; /* process termination/exit status */ + struct timeval ut_tv; /* time entry was made */ + long ut_session; /* session ID, used for windowing */ + long pad[5]; /* reserved for future use */ + short ut_syslen; /* significant length of ut_host */ + /* including terminating null */ + char ut_host[257]; /* remote host name */ + } ; + + +#define getmodsize(size, ftype, ttype) \ + (((size / ftype) * ttype) + (size % ftype)) diff --git a/usr/src/lib/libbc/libc/sys/common/connect.c b/usr/src/lib/libbc/libc/sys/common/connect.c new file mode 100644 index 0000000000..3867cb3bc6 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/connect.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1996 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> +#include <sys/types.h> +#include <sys/socket.h> + +/* SVR4 stream operation macros */ +#define STR ('S'<<8) +#define I_SWROPT (STR|023) +#define SNDPIPE 0x002 + +extern int errno; + +connect(s, name, namelen) +int s; +struct sockaddr *name; +int namelen; +{ + int a; + + if ((a = _connect(s, name, namelen)) == -1) + maperror(); + return (a); +} diff --git a/usr/src/lib/libbc/libc/sys/common/dup.c b/usr/src/lib/libbc/libc/sys/common/dup.c new file mode 100644 index 0000000000..57403687af --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/dup.c @@ -0,0 +1,44 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> + + +int dup(fd) +int fd; +{ + int ret, fds; + + if ((ret = _syscall(SYS_dup, fd)) == -1) + return(-1); + + if ((fds = fd_get(fd)) != -1) + fd_add(ret, fds); + + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/dup2.c b/usr/src/lib/libbc/libc/sys/common/dup2.c new file mode 100644 index 0000000000..1c78240bc6 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/dup2.c @@ -0,0 +1,79 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <fcntl.h> +#include <unistd.h> +#include <syscall.h> +#include <sys/errno.h> + +#define OPEN_MAX 20 /* Taken from SVR4 limits.h */ + +int dup2(fildes, fildes2) +int fildes, /* file descriptor to be duplicated */ + fildes2; /* desired file descriptor */ +{ + int tmperrno; /* local work area */ + register int open_max; /* max open files */ + extern int errno; /* system error indicator */ + int ret; /* return value */ + int fds; /* duplicate files descriptor */ + + if ((open_max = ulimit(4, 0)) < 0) + open_max = OPEN_MAX; /* take a guess */ + + /* Be sure fildes is valid and open */ + if (fcntl(fildes, F_GETFL, 0) == -1) { + errno = EBADF; + return (-1); + } + + /* Be sure fildes2 is in valid range */ + if (fildes2 < 0 || fildes2 >= open_max) { + errno = EBADF; + return (-1); + } + + /* Check if file descriptors are equal */ + if (fildes == fildes2) { + /* open and equal so no dup necessary */ + return (fildes2); + } + /* Close in case it was open for another file */ + /* Must save and restore errno in case file was not open */ + tmperrno = errno; + close(fildes2); + errno = tmperrno; + + /* Do the dup */ + if ((ret = fcntl(fildes, F_DUPFD, fildes2)) != -1) { + if ((fds = fd_get(fildes)) != -1) + fd_add(fildes2, fds); + } + return(ret); + +} diff --git a/usr/src/lib/libbc/libc/sys/common/execl.c b/usr/src/lib/libbc/libc/sys/common/execl.c new file mode 100644 index 0000000000..a8c5d487d6 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/execl.c @@ -0,0 +1,48 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <varargs.h> + +/* + * execl(name, arg0, arg1, ..., argn, (char *)0) + * environment automatically passed. + */ +/*VARARGS1*/ +execl(name, va_alist) + register char *name; + va_dcl +{ + extern char **environ; + va_list args; + + va_start(args); + return (execve(name, (char **)args, environ)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/execle.c b/usr/src/lib/libbc/libc/sys/common/execle.c new file mode 100644 index 0000000000..2fe9de5f09 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/execle.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1987 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" +#include <varargs.h> + +/* + * execle(name, arg0, arg1, ..., argn, (char *)0, envp) + */ +/*VARARGS1*/ +execle(name, va_alist) + register char *name; + va_dcl +{ + register char **first; + va_list args; + + va_start(args); + first = (char **)args; + while (va_arg(args, char *)) /* traverse argument list to 0 */ + ; + /* environment is next arg */ + return(execve(name, first, *(char **)args)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/execv.c b/usr/src/lib/libbc/libc/sys/common/execv.c new file mode 100644 index 0000000000..24cc3947e7 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/execv.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" +/* + * execv(file, argv) + * + * where argv is a vector argv[0] ... argv[x], NULL + * last vector element must be NULL + * environment passed automatically + */ + +execv(file, argv) + char *file; + char **argv; +{ + extern char **environ; + + return(execve(file, argv, environ)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/fdlist.c b/usr/src/lib/libbc/libc/sys/common/fdlist.c new file mode 100644 index 0000000000..03b71b5a29 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/fdlist.c @@ -0,0 +1,137 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> + +#define NUM_FD 16 + +struct fd_lst{ + int fd[NUM_FD]; /* list of 16 descriptors */ + int fds[NUM_FD]; + struct fd_lst *next; +}; + + +static struct fd_lst *fdlist = NULL; +static struct fd_lst *fdtail = NULL; + + +fd_init(lst) + struct fd_lst *lst; +{ + int i; + + for (i=0; i<NUM_FD; i++) { + lst->fd[i] = -1; + lst->fds[i] = -1; + } + lst->next = NULL; +} + + + +int fd_add(fd, fds) +int fd, fds; +{ + int i; + struct fd_lst *fdc, *fdnew; + + fdc = fdlist; + + while (fdc != NULL) { + for (i=0; i<NUM_FD; i++) { + if (fdc->fd[i] == -1) { + fdc->fd[i] = fd; + fdc->fds[i] = fds; + return(0); + } + } + fdc = fdc->next; + } + + if ((fdnew = (struct fd_lst *)malloc(sizeof(struct fd_lst))) == NULL) { + fprintf(stderr,"fd_add: malloc failed\n"); + exit(1); + } + + fd_init(fdnew); + + if (fdlist == NULL) + fdlist = fdnew; + else + fdtail->next = fdnew; + + fdtail = fdnew; + fdtail->fd[0] = fd; + fdtail->fds[0] = fds; + return(0); +} + + +int fd_rem(fd) +{ + int i; + struct fd_lst *fdc = fdlist; + + while (fdc != NULL) { + for (i=0; i<NUM_FD; i++) { + if (fdc->fd[i] == fd) { + fdc->fd[i] = -1; + fdc->fds[i] = -1; + return(0); + } + } + fdc = fdc->next; + } +} + + +int fd_get(fd) +{ + int i; + struct fd_lst *fdc = fdlist; + + while (fdc != NULL) { + for (i=0; i<NUM_FD; i++) { + if (fdc->fd[i] == fd) { + return(fdc->fds[i]); + } + } + fdc = fdc->next; + } + return(-1); +} + + + + + + + + + diff --git a/usr/src/lib/libbc/libc/sys/common/flock.c b/usr/src/lib/libbc/libc/sys/common/flock.c new file mode 100644 index 0000000000..1c34632344 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/flock.c @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/file.h> +#include <sys/fcntl.h> + +int flock(fd, operation) +int fd, operation; +{ + struct flock fl; + int cmd = F_SETLKW; + + fl.l_whence = 0; + fl.l_start = 0; + fl.l_len = 0; + fl.l_type = 0; + if (operation & LOCK_UN) + fl.l_type |= F_UNLCK; + if (operation & LOCK_SH) + fl.l_type |= F_RDLCK; + if (operation & LOCK_EX) + fl.l_type |= F_WRLCK; + if (operation & LOCK_NB) + cmd = F_SETLK; + return(bc_fcntl(fd, cmd, &fl)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/fsync.c b/usr/src/lib/libbc/libc/sys/common/fsync.c new file mode 100644 index 0000000000..97a0bcaa1a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/fsync.c @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> + + +int +fsync(int fd) +{ + int ret; + + if ((ret = _syscall(SYS_fsync, fd)) == -1) + return (-1); + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/ftruncate.c b/usr/src/lib/libbc/libc/sys/common/ftruncate.c new file mode 100644 index 0000000000..ab66775508 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/ftruncate.c @@ -0,0 +1,62 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <sys/types.h> + +/* The following are from SVR4 sys/fcntl.h */ + +#define F_FREESP 11 /* Free file space */ +#define F_WRLCK 02 /* Write Lock */ + +/* lock structure from SVR4. */ +struct fl { + short l_type; + short l_whence; + off_t l_start; + off_t l_len; + long l_sysid; + pid_t l_pid; + long pad[4]; +}; + +int ftruncate(int fd, off_t length) +{ + + struct fl lck; + + lck.l_whence = 0; /* offset l_start from beginning of file */ + lck.l_start = length; + lck.l_type = F_WRLCK; /* setting a write lock */ + lck.l_len = 0L; + + if (_syscall(SYS_fcntl, fd, F_FREESP, (int)&lck) == -1) + return (-1); + else + return (0); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getdents.c b/usr/src/lib/libbc/libc/sys/common/getdents.c new file mode 100644 index 0000000000..dce588a3a3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getdents.c @@ -0,0 +1,116 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1994 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <unistd.h> +#include <sys/types.h> +#include <sys/dirent.h> +#include <sys/syscall.h> +#include <sys/param.h> +#include <sys/errno.h> + +#define ALIGN 4 + +extern int errno; + +struct n_dirent{ + unsigned long d_ino; + long d_off; + unsigned short d_reclen; + char d_name[1]; +}; + + +int getdents(fd, buf, bytes) +int fd; +char *buf; +int bytes; +{ + return(bc_getdents(fd, buf, bytes)); +} + + +int bc_getdents(fd, buf, bytes) +int fd; +char *buf; +int bytes; +{ + int ret, nbytes; + char *nbuf; + struct dirent *dir; + struct n_dirent *ndir; + int count=0; + off_t last_off; + + if (buf == (char *)0 || buf == (char *)-1) { + errno = EFAULT; + return(-1); + } + + nbytes = bytes; /* buffer can only be as large as user expects */ + + if ((nbuf = (char *)malloc(nbytes)) == NULL) { + return(-1); + } + + if ((ret = _syscall(SYS_getdents, fd, nbuf, nbytes)) == -1) { + free(nbuf); + return(ret); + } + + + dir = (struct dirent *)buf; + ndir = (struct n_dirent *)nbuf; /* source directory format */ + + while ((((int)(((char *)dir) + sizeof(struct n_dirent) + + strlen(ndir->d_name) + ALIGN) & ~(ALIGN - 1)) < + (int)(buf + bytes)) && + ((char *)ndir + sizeof(struct n_dirent) <= (nbuf + ret))) { + dir->d_off = ndir->d_off; + dir->d_fileno = ndir->d_ino; /* NOT VALID */ + dir->d_namlen = strlen(ndir->d_name); + dir->d_reclen = (short)((sizeof(struct dirent) - MAXNAMLEN + + dir->d_namlen + ALIGN) & -ALIGN); + strncpy(dir->d_name, ndir->d_name, dir->d_namlen); + dir->d_name[dir->d_namlen] = '\0'; + count += dir->d_reclen; + last_off = ndir->d_off; + dir = (struct dirent *)((char *)dir + + ((int)( dir->d_reclen))); + ndir = (struct n_dirent *)((char *)ndir + + ((int)(ndir->d_reclen))); + } + + /* + * Seek to the next entry in the directory. If all entries + * in ndir were not copied to dir, the next getdents syscall + * will start reading from there. + */ + (void)lseek(fd, last_off, SEEK_SET); + free(nbuf); + return(count); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getdtablesize.c b/usr/src/lib/libbc/libc/sys/common/getdtablesize.c new file mode 100644 index 0000000000..aeb6f4e075 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getdtablesize.c @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/time.h> +#include <sys/resource.h> + +/* + * getdtablesize is implemented on top of getrlimit's + * RLIMIT_NOFILE feature. The current (Soft) limit is + * returned. + */ + +getdtablesize() +{ + int nds; + int error; + struct rlimit rip; + + error = getrlimit(RLIMIT_NOFILE, &rip); + if ( error < 0 ) + return (-1); + else + return (rip.rlim_cur); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getegid.c b/usr/src/lib/libbc/libc/sys/common/getegid.c new file mode 100644 index 0000000000..9e3e71cf22 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getegid.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +getegid(void) +{ + int egid; + + if ((egid = _getegid()) > 0xffff) + egid = 60001; /* nobody */ + return (egid); +} diff --git a/usr/src/lib/libbc/libc/sys/common/geteuid.c b/usr/src/lib/libbc/libc/sys/common/geteuid.c new file mode 100644 index 0000000000..0c6fd1c19c --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/geteuid.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +geteuid(void) +{ + int euid; + + if ((euid = _geteuid()) > 0xffff) + euid = 60001; /* nobody */ + return (euid); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getgid.c b/usr/src/lib/libbc/libc/sys/common/getgid.c new file mode 100644 index 0000000000..3bc425e75f --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getgid.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +getgid(void) +{ + int gid; + + if ((gid = _getgid()) > 0xffff) + gid = 60001; /* nobody */ + return (gid); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getpeername.c b/usr/src/lib/libbc/libc/sys/common/getpeername.c new file mode 100644 index 0000000000..df84142c8a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getpeername.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> + +extern int errno; + +getpeername(s, name, namelen) +int s; +struct sockaddr *name; +int *namelen; +{ + int a; + if ((a = _getpeername(s, name, namelen)) == -1) + maperror(errno); + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/getsockname.c b/usr/src/lib/libbc/libc/sys/common/getsockname.c new file mode 100644 index 0000000000..35f5a2d8ae --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getsockname.c @@ -0,0 +1,45 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> + +extern int errno; + +getsockname(s, name, namelen) +int s; +struct sockaddr *name; +int *namelen; +{ + int a; + if ((a = _getsockname(s, name, namelen)) == -1) + maperror(errno); + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/getsockopt.c b/usr/src/lib/libbc/libc/sys/common/getsockopt.c new file mode 100644 index 0000000000..f62742d32b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getsockopt.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> + +extern int errno; + +getsockopt(s, level, optname, optval, optlen) +register int s; +register int level; +register int optname; +register char *optval; +register int *optlen; +{ + int a; + if ((a = _getsockopt(s, level, optname, optval, optlen)) == -1) + maperror(errno); + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/gettimeofday.c b/usr/src/lib/libbc/libc/sys/common/gettimeofday.c new file mode 100644 index 0000000000..d027ceee36 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/gettimeofday.c @@ -0,0 +1,122 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995 Sun Microsystems, Inc. All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <time.h> +#include <tzfile.h> +#include <sys/time.h> + +static int get_tzp_info(void); +extern long _timezone, _altzone; /* from the base libc */ + + +/* + * The second parameter to gettimeofday() did not work correctly on + * 4.x, and it was documented that localtime() should be used instead. + * This is an attempt to provide correctly what 4.x meant to do. There + * are shortcomings, however. See notes for DST_RUM and DST_AUSTALT. + */ + +int +gettimeofday(tp, tzp) +struct timeval *tp; +struct timezone *tzp; +{ + int ret = 0; + + if (tp != NULL) + if ((ret = _gettimeofday(tp)) == -1) + maperror(); + + /* + * We should call localtime() with the current time and + * set tz_minuteswest to _altzone/SECSPERMIN if tm_isdst + * is set. But we want to be bug-for-bug compatible with + * 4.x, which would never adjust for DST. Futher comments + * are in get_tzp_info(). + */ + if (tzp != NULL) { + _tzset(); + tzp->tz_dsttime = get_tzp_info(); + tzp->tz_minuteswest = _timezone/SECSPERMIN; + } + + return(ret); +} + +static int +get_tzp_info() +{ + char *zonename = getenv("TZ"); + + if ((zonename == NULL) || (*zonename == '\0')) + return (DST_NONE); + + if ((strncmp(zonename, "US/", 3) == 0) || + (strcmp(zonename, "PST8PDT") == 0) || + (strcmp(zonename, "MST7MDT") == 0) || + (strcmp(zonename, "CST6CDT") == 0) || + (strcmp(zonename, "EST5EDT") == 0) || + (strncmp(zonename, "America/", 8) == 0)) + return (DST_USA); + + if (strncmp(zonename, "Australia/", 10) == 0) + return (DST_AUST); + + if (strcmp(zonename, "WET") == 0) + return (DST_WET); + + if (strcmp(zonename, "MET") == 0) + return (DST_MET); + + if (strcmp(zonename, "EET") == 0) + return (DST_EET); + + if (strncmp(zonename, "Canada/", 7) == 0) + return (DST_CAN); + + if ((strcmp(zonename, "GB") == 0) || + (strcmp(zonename, "GB-Eire") == 0)) + return (DST_GB); + + /* + * what's the corresponding DST_RUM: Rumanian DST? + * There was not Rumanian timezone on 4.x. + */ + + if (strcmp(zonename, "Turkey") == 0) + return (DST_TUR); + + /* + * How do we differentiate between DST_AUST and DST_AUSTALT? + * It seems that all of our current Australia timezones do + * not have the 1986 shift, so we never will return DST_AUSTALT. + */ + + return (DST_NONE); +} diff --git a/usr/src/lib/libbc/libc/sys/common/getuid.c b/usr/src/lib/libbc/libc/sys/common/getuid.c new file mode 100644 index 0000000000..175c9dd683 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/getuid.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +getuid(void) +{ + int uid; + + if ((uid = _getuid()) > 0xffff) + uid = 60001; /* nobody */ + return (uid); +} diff --git a/usr/src/lib/libbc/libc/sys/common/ioctl.c b/usr/src/lib/libbc/libc/sys/common/ioctl.c new file mode 100644 index 0000000000..bfe677a3c1 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/ioctl.c @@ -0,0 +1,645 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Do not include sys/conf.h- it isn't in the compatibility include dirs. + */ +#ifdef THIS_IS_AVAIL +#include <sys/conf.h> +#endif +#include <stdio.h> +#include <signal.h> +#include <sys/types.h> +#include <sys/ioccom.h> +#include <sys/stropts.h> +#include <sys/des.h> +#include <sys/fcntl.h> +#include <sys/filio.h> +#include <sys/termios.h> +#include <sys/termio.h> +#include <sys/ttold.h> +#include <sys/ttycom.h> +#include <sys/msio.h> +#include <sys/errno.h> +#include <nettli/tihdr.h> +#include <nettli/timod.h> +#include <nettli/tiuser.h> +#include <sun/dkio.h> +#include <scsi/impl/uscsi.h> +#include "cdioctl.h" +#include "s5dkio.h" +#include "s5fdio.h" + +/* + * parameter for windows ioctls + */ +struct winclip { + int wc_blockbytes; /* size of wc_block */ + int wc_clipid; /* Current clip id of clipping */ + short wc_screenrect[4]; /* Screen relatived (used when paint) */ + char *wc_block; /* Block where RectList is copied. */ +}; + +/* + * Ioctl control packet + */ +struct s5termios { + tcflag_t c_iflag; /* input modes */ + tcflag_t c_oflag; /* output modes */ + tcflag_t c_cflag; /* control modes */ + tcflag_t c_lflag; /* line discipline modes */ + cc_t c_cc[19]; /* control chars */ +}; + +#define N_ENOMSG 35 +#define N_I_FIND ('S'<<8)|013 +#define N_I_PUSH ('S'<<8)|02 +#define WINGETEXPOSEDRL _IOWR(g,31,struct winclip) +#define WINGETDAMAGEDRL _IOWR(g,32,struct winclip) + +struct n_sgttyb { + char sg_ispeed; /* input speed */ + char sg_ospeed; /* output speed */ + char sg_erase; /* erase character */ + char sg_kill; /* kill character */ + int sg_flags; /* mode flags */ +}; + +static int handle_dkio_partitions(int, int, int); +static int tcget(int, int, int); +static int tcset(int, int, int); +static int _bc_ioctl(int, int, int); + +int +ioctl(int des, int request, int arg) +{ + int ret; + + if ((ret = _bc_ioctl(des, request, arg)) == -1) + maperror(); + return (ret); +} + +int +bc_ioctl(int des, int request, int arg) +{ + int ret; + + if ((ret = _bc_ioctl(des, request, arg)) == -1) + maperror(); + return (ret); +} + +static int +_bc_ioctl(int des, int request, int arg) +{ + int ret; + int nreq = (request >> 8) & 0xFF; + struct n_sgttyb nsg; + struct s5_dk_cinfo newArgs; + struct dk_info *infoArgs; + struct dk_conf *confArgs; + extern int errno; + + /* not all mappings for 'm' have been performed */ + switch (nreq) { + case ((int) 't'): + if (_ioctl(des, N_I_FIND, "ttcompat") == 0) + if (_ioctl(des, N_I_PUSH, "ttcompat") == -1) + perror("ioctl/I_PUSH"); + switch(request) { + case TIOCSETD: + /* added for sunview */ + return(0); + case TIOCREMOTE: request = ('t'<<8)|30; + break; + case TIOCNOTTY: + bc_setsid(); + return(0); + case TIOCGPGRP: request = ('t'<<8)|20; + break; + case TIOCSPGRP: + { + pid_t pgid; + sigset_t set, oset; + + request = ('t'<<8)|21; + ret = _ioctl(des, request, arg); + + /* + * SunOS4.x allows this to succeed + * even if the process group does + * not exist yet. We emulate the 4.x + * bug by creating the process group + * and reissuing the ioctl(). + * See bugid 1175044. + */ + if (ret != 0 && errno == EPERM && + (pgid = *((pid_t *)arg)) != 0 && + pgid == getpid() && + setpgid(0, pgid) == 0) { + sigemptyset(&set); + sigaddset(&set, SIGTSTP); + sigaddset(&set, SIGTTIN); + sigaddset(&set, SIGTTOU); + sigprocmask(SIG_BLOCK, + &set, &oset); + ret = _ioctl(des, + request, arg); + sigprocmask(SIG_SETMASK, + &oset, NULL); + } + return(ret); + } + case TIOCSTI: request = ('t'<<8)|23; + break; + case TIOCSIGNAL: request = ('t'<<8)|31; + break; + case TIOCCONS: request = ('t'<<8)|36; + break; + case TIOCSWINSZ: request = ('T'<<8)|103; + break; + case TIOCGWINSZ: request = ('T'<<8)|104; + break; + case TIOCSETP: + case TIOCSETN: + { + struct sgttyb *sg = (struct sgttyb *)arg; + nsg.sg_ispeed = sg->sg_ispeed; + nsg.sg_ospeed = sg->sg_ospeed; + nsg.sg_erase = sg->sg_erase; + nsg.sg_kill = sg->sg_kill; + nsg.sg_flags = (int)sg->sg_flags; + arg = (int)&nsg; + request = request & 0x0FFFF; + break; + } + + case TIOCGETP: + { + struct sgttyb *sg = (struct sgttyb *)arg; + + ret = _ioctl(des, request&0xFFFF, &nsg); + if (ret != -1) { + sg->sg_ispeed = nsg.sg_ispeed; + sg->sg_ospeed = nsg.sg_ospeed; + sg->sg_erase = nsg.sg_erase; + sg->sg_kill = nsg.sg_kill; + sg->sg_flags = (short)nsg.sg_flags & 0x0FFFF; + } + return(ret); + } + case TIOCPKT: + case TIOCUCNTL: + case TIOCTCNTL: + case TIOCSSOFTCAR: + case TIOCGSOFTCAR: + case TIOCISPACE: + case TIOCISIZE: + case TIOCSSIZE: + case TIOCGSIZE: + break; + default: request = request & 0x0FFFF; + break; + } + break; + case ((int) 'T'): + switch(request) { + case TCGETS: + request = ('T'<<8)|13; + return(tcget(des, request, arg)); + break; + case TCSETS: + request = ('T'<<8)|14; + return(tcset(des, request, arg)); + break; + case TCSETSW: + request = ('T'<<8)|15; + return(tcset(des, request, arg)); + break; + case TCSETSF: + request = ('T'<<8)|16; + return(tcset(des, request, arg)); + break; + case TCGETA: + case TCSETA: + case TCSETAW: + case TCSETAF: + default: + request = request & 0x0FFFF; + break; + } + break; + case ((int) 'S'): + switch (request) { + case I_PLINK: request = ('S'<<8)|026; + break; + case I_PUNLINK: request = ('S'<<8)|027; + break; + case I_STR: { + struct strioctl *iarg = + (struct strioctl *)arg; + int cmd = iarg->ic_cmd; + + switch (cmd) { + case TI_GETINFO: { + /* + * The T_info_ack structure + * has one additional word + * added to it in 5.x. + * To prevent the module from + * overwritting user memory we + * use an internal buffer for + * the transfer and copy out + * the results to the caller. + */ + struct { + struct T_info_ack info; + long pad[16]; + } args; + char *dp = iarg->ic_dp; + + memcpy(&args.info, iarg->ic_dp, + sizeof(struct T_info_ack)); + iarg->ic_dp = + (char *) &args.info; + iarg->ic_cmd = (TIMOD | 140); + ret = _ioctl(des, + request & 0xffff, arg); + iarg->ic_cmd = cmd; + iarg->ic_dp = dp; + iarg->ic_len = + sizeof(struct T_info_ack); + memcpy(iarg->ic_dp, &args.info, + iarg->ic_len); + return (ret); + break; + } + case TI_OPTMGMT: + iarg->ic_cmd = (TIMOD | 141); + break; + case TI_BIND: + iarg->ic_cmd = (TIMOD | 142); + break; + case TI_UNBIND: + iarg->ic_cmd = (TIMOD | 143); + break; + } + ret = _ioctl(des, + request & 0xffff, arg); + iarg->ic_cmd = cmd; + return ret; + } + default: request = request & 0x0FFFF; + break; + } + break; + case ((int) 'm'): + switch (request) { + case MSIOGETPARMS: request = ('m'<<8)|1; + break; + case MSIOSETPARMS: request = ('m'<<8)|2; + break; + default: request = request & 0x0FFFF; + break; + } + break; + case ((int) 'd'): + switch (request) { + case DKIOCGGEOM: + request = S5DKIOCGGEOM; + break; + case DKIOCSGEOM: + request = S5DKIOCSGEOM; + break; + case DKIOCSAPART: + request = S5DKIOCSAPART; + break; + case DKIOCGAPART: + request = S5DKIOCGAPART; + break; + case DKIOCSTYPE: + request = S5HDKIOCSTYPE; + break; + case DKIOCGTYPE: + request = S5HDKIOCGTYPE; + break; + case DKIOCSBAD: + request = S5HDKIOCSBAD; + break; + case DKIOCGBAD: + request = S5HDKIOCGBAD; + break; + case DKIOCSCMD: + request = S5HDKIOCSCMD; + break; + case DKIOCGDIAG: + request = S5HDKIOCGDIAG; + break; + case FDKIOGCHAR: + request = S5FDIOGCHAR; + break; + case FDKIOSCHAR: + request = S5FDIOSCHAR; + break; + case FDKEJECT: + request = S5FDEJECT; + break; + case FDKGETCHANGE: + request = S5FDGETCHANGE; + break; + case FDKGETDRIVECHAR: + request = S5FDGETDRIVECHAR; + break; + case FDKSETDRIVECHAR: + request = S5FDSETDRIVECHAR; + break; + case FDKGETSEARCH: + request = S5FDGETSEARCH; + break; + case FDKSETSEARCH: + request = S5FDSETSEARCH; + break; + case FDKIOCSCMD: + request = S5FDIOCMD; + break; + case F_RAW: + request = S5FDRAW; + break; + case DKIOCINFO: + ret = _ioctl(des, S5DKIOCINFO, &newArgs); + if (ret != -1) { + infoArgs = (struct dk_info *)arg; + infoArgs->dki_ctlr = + newArgs.dki_addr; + infoArgs->dki_unit = + newArgs.dki_unit; + infoArgs->dki_ctype = + newArgs.dki_ctype; + infoArgs->dki_flags = + newArgs.dki_flags; + } + return ret; + break; + case DKIOCGCONF: + ret = _ioctl(des, S5DKIOCINFO, &newArgs); + if (ret != -1) { + confArgs = (struct dk_conf *)arg; + strncpy(confArgs->dkc_cname, + newArgs.dki_cname, + DK_DEVLEN); + strncpy(confArgs->dkc_dname, + newArgs.dki_dname, + DK_DEVLEN); + confArgs->dkc_ctype = + (u_short)newArgs.dki_ctype; + confArgs->dkc_flags = + (u_short)newArgs.dki_flags; + confArgs->dkc_cnum = + newArgs.dki_cnum; + confArgs->dkc_addr = + newArgs.dki_addr; + confArgs->dkc_space = + (u_int)newArgs.dki_space; + confArgs->dkc_prio = + newArgs.dki_prio; + confArgs->dkc_vec = + newArgs.dki_vec; + confArgs->dkc_unit = + newArgs.dki_unit; + confArgs->dkc_slave = + newArgs.dki_slave; + } + return ret; + break; + case DKIOCWCHK: + /* + * This is unsupported in SVR4. It + * turns on verify-after-write for + * the floppy. I don't think the + * system call should fail, however. + */ + return 0; + break; + case DKIOCGPART: + case DKIOCSPART: + return (handle_dkio_partitions(des, + request, arg)); + case DKIOCGLOG: + /* unsupported */ + errno = EINVAL; + return -1; + break; + case DESIOCBLOCK: + case DESIOCQUICK: + break; /* no change for these two */ + default: + request = request & 0x0FFFF; /* try */ + break; + } + break; + case ((int) 'c'): + switch (request) { + case CDROMPAUSE: + request = S5CDROMPAUSE; + break; + case CDROMRESUME: + request = S5CDROMRESUME; + break; + case CDROMPLAYMSF: + request = S5CDROMPLAYMSF; + break; + case CDROMPLAYTRKIND: + request = S5CDROMPLAYTRKIND; + break; + case CDROMREADTOCHDR: + request = S5CDROMREADTOCHDR; + break; + case CDROMREADTOCENTRY: + request = S5CDROMREADTOCENTRY; + break; + case CDROMSTOP: + request = S5CDROMSTOP; + break; + case CDROMSTART: + request = S5CDROMSTART; + break; + case CDROMEJECT: + request = S5CDROMEJECT; + break; + case CDROMVOLCTRL: + request = S5CDROMVOLCTRL; + break; + case CDROMSUBCHNL: + request = S5CDROMSUBCHNL; + break; + case CDROMREADMODE1: + request = S5CDROMREADMODE1; + break; + case CDROMREADMODE2: + request = S5CDROMREADMODE2; + break; + } + break; + case ((int) 'u'): + switch (request) { + case USCSICMD: + { + struct s5_uscsi_cmd s5_cmd; + struct uscsi_cmd *cmd = + (struct uscsi_cmd *) arg; + request = S5USCSICMD; + s5_cmd.uscsi_cdb = cmd->uscsi_cdb; + s5_cmd.uscsi_cdblen = + cmd->uscsi_cdblen; + s5_cmd.uscsi_bufaddr = + cmd->uscsi_bufaddr; + s5_cmd.uscsi_buflen = + cmd->uscsi_buflen; + s5_cmd.uscsi_flags = + cmd->uscsi_flags; + ret = _ioctl(des, request, &s5_cmd); + cmd->uscsi_status = s5_cmd.uscsi_status; + return(ret); + } + } + break; + case ((int) 'k'): + case ((int) 'v'): + case ((int) 'F'): + case ((int) 'G'): + case ((int) 'X'): + case ((int) 'L'): + request = request & 0x0FFFF; + break; + case ((int) 'f'): + if ((request == FIOCLEX) || (request == FIONCLEX)) + return(fcntl(des, F_SETFD, + ((request == FIOCLEX) ? 1 : 0))); + break; + case ((int) 'g'): + /* Treat the following 2 ioctls specially for + * sunview. */ + if (request == WINGETEXPOSEDRL || + request == WINGETDAMAGEDRL) { + ret = _ioctl(des, request, arg); + if (errno == N_ENOMSG) + errno = EFBIG; + return(ret); + } + break; + } + return (_ioctl(des, request, arg)); +} + + +static int +handle_dkio_partitions(int des, int request, int arg) +{ + struct s5_dk_cinfo cinfo; + struct dk_allmap map; + struct dk_map *part; + int ret; + extern int errno; + + part = (struct dk_map *) arg; + + ret = _ioctl(des, S5DKIOCINFO, &cinfo); + + if ((cinfo.dki_partition < 0) || (cinfo.dki_partition >= NDKMAP)) { + errno = EINVAL; + return (-1); + } + + if (ret != -1) { + ret = _ioctl(des, S5DKIOCGAPART, &map); + if (ret != -1) { + if (request == DKIOCGPART) { + part->dkl_cylno = + map.dka_map[cinfo.dki_partition].dkl_cylno; + part->dkl_nblk = + map.dka_map[cinfo.dki_partition].dkl_nblk; + } else { + map.dka_map[cinfo.dki_partition].dkl_cylno = + part->dkl_cylno; + map.dka_map[cinfo.dki_partition].dkl_nblk = + part->dkl_nblk; + ret = _ioctl(des, S5DKIOCSAPART, &map); + } + } + } + return (ret); +} + +static int +tcset(des, request, arg) + register int des; + register int request; + int arg; +{ + struct s5termios s5termios; + struct termios *termios; + + termios = (struct termios *)arg; + + if (termios != NULL) { + s5termios.c_iflag = termios->c_iflag; + s5termios.c_oflag = termios->c_oflag; + s5termios.c_cflag = termios->c_cflag; + s5termios.c_lflag = termios->c_lflag; + memcpy(s5termios.c_cc, termios->c_cc, NCCS); + return (_ioctl(des, request, &s5termios)); + } else + return (_ioctl(des, request, NULL)); + +} + +static int +tcget(des, request, arg) + register int des; + register int request; + int arg; +{ + struct s5termios s5termios; + struct termios *termios; + int ret; + + termios = (struct termios *)arg; + + ret = _ioctl(des, request, &s5termios); + + if (termios != NULL) { + termios->c_iflag = s5termios.c_iflag; + termios->c_oflag = s5termios.c_oflag; + termios->c_cflag = s5termios.c_cflag; + termios->c_lflag = s5termios.c_lflag; + memcpy(termios->c_cc, s5termios.c_cc, NCCS); + } + + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/kill.c b/usr/src/lib/libbc/libc/sys/common/kill.c new file mode 100644 index 0000000000..8f6b4094b6 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/kill.c @@ -0,0 +1,47 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> +#include <stdio.h> + +extern int errno; + +kill(pid, sig) +int pid, sig; +{ + return(bc_kill(pid, sig)); +} + + +bc_kill(pid, sig) +int pid, sig; +{ + return(_kill(pid, maptonewsig(sig))); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/listen.c b/usr/src/lib/libbc/libc/sys/common/listen.c new file mode 100644 index 0000000000..0b0dc91c7f --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/listen.c @@ -0,0 +1,40 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +extern int errno; + +listen(s, backlog) +int s, backlog; +{ + int a; + if ((a = _listen(s, backlog)) == -1) + maperror(errno); + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/lseek.c b/usr/src/lib/libbc/libc/sys/common/lseek.c new file mode 100644 index 0000000000..9476093725 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/lseek.c @@ -0,0 +1,57 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "compat.h" +#include <errno.h> +#include <syscall.h> +#include <sys/types.h> +#include <unistd.h> + +extern int errno; + +off_t lseek(int fd, off_t offset, int whence) +{ + int off, ret; + + if (whence < 0 || whence > 2) { + errno = EINVAL; + return (-1); + } + if (fd_get(fd) != -1) { + off = getmodsize(offset, sizeof(struct utmpx), + sizeof(struct compat_utmp)); + if ((ret = _syscall(SYS_lseek, fd, off, whence)) == -1) + return(-1); + + ret = getmodsize(ret, sizeof(struct compat_utmp), + sizeof(struct utmpx)); + return (ret); + } + else + return (_syscall(SYS_lseek, fd, offset, whence)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/maperror.c b/usr/src/lib/libbc/libc/sys/common/maperror.c new file mode 100644 index 0000000000..c60db84912 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/maperror.c @@ -0,0 +1,295 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * Include the SVR4/5.0 errno.h + */ + +#include "s5errno.h" + +/* from UCB 4.1 82/12/28 */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * XError codes from 4.1 + */ + +#define XEPERM 1 /* Not owner */ +#define XENOENT 2 /* No such file or directory */ +#define XESRCH 3 /* No such process */ +#define XEINTR 4 /* Interrupted system call */ +#define XEIO 5 /* I/O error */ +#define XENXIO 6 /* No such device or address */ +#define XE2BIG 7 /* Arg list too long */ +#define XENOEXEC 8 /* Exec format error */ +#define XEBADF 9 /* Bad file number */ +#define XECHILD 10 /* No children */ +#define XEAGAIN 11 /* No more processes */ +#define XENOMEM 12 /* Not enough core */ +#define XEACCES 13 /* Permission denied */ +#define XEFAULT 14 /* Bad address */ +#define XENOTBLK 15 /* Block device required */ +#define XEBUSY 16 /* Mount device busy */ +#define XEEXIST 17 /* File exists */ +#define XEXDEV 18 /* Cross-device link */ +#define XENODEV 19 /* No such device */ +#define XENOTDIR 20 /* Not a directory*/ +#define XEISDIR 21 /* Is a directory */ +#define XEINVAL 22 /* Invalid argument */ +#define XENFILE 23 /* File table overflow */ +#define XEMFILE 24 /* Too many open files */ +#define XENOTTY 25 /* Not a typewriter */ +#define XETXTBSY 26 /* Text file busy */ +#define XEFBIG 27 /* File too large */ +#define XENOSPC 28 /* No space left on device */ +#define XESPIPE 29 /* Illegal seek */ +#define XEROFS 30 /* Read-only file system */ +#define XEMLINK 31 /* Too many links */ +#define XEPIPE 32 /* Broken pipe */ + +/* math software */ +#define XEDOM 33 /* Argument too large */ +#define XERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define XEWOULDBLOCK 35 /* Operation would block */ +#define XEINPROGRESS 36 /* Operation now in progress */ +#define XEALREADY 37 /* Operation already in progress */ +/* ipc/network software */ + + /* argument errors */ +#define XENOTSOCK 38 /* Socket operation on non-socket */ +#define XEDESTADDRREQ 39 /* Destination address required */ +#define XEMSGSIZE 40 /* Message too long */ +#define XEPROTOTYPE 41 /* Protocol wrong type for socket */ +#define XENOPROTOOPT 42 /* Protocol not available */ +#define XEPROTONOSUPPORT 43 /* Protocol not supported */ +#define XESOCKTNOSUPPORT 44 /* Socket type not supported */ +#define XEOPNOTSUPP 45 /* Operation not supported on socket */ +#define XEPFNOSUPPORT 46 /* Protocol family not supported */ +#define XEAFNOSUPPORT 47 /* Address family not supported by protocol family */ +#define XEADDRINUSE 48 /* Address already in use */ +#define XEADDRNOTAVAIL 49 /* Can't assign requested address */ + + /* operational errors */ +#define XENETDOWN 50 /* Network is down */ +#define XENETUNREACH 51 /* Network is unreachable */ +#define XENETRESET 52 /* Network dropped connection on reset */ +#define XECONNABORTED 53 /* Software caused connection abort */ +#define XECONNRESET 54 /* Connection reset by peer */ +#define XENOBUFS 55 /* No buffer space available */ +#define XEISCONN 56 /* Socket is already connected */ +#define XENOTCONN 57 /* Socket is not connected */ +#define XESHUTDOWN 58 /* Can't send after socket shutdown */ +#define XETOOMANYREFS 59 /* Too many references: can't splice */ +#define XETIMEDOUT 60 /* Connection timed out */ +#define XECONNREFUSED 61 /* Connection refused */ + + /* */ +#define XELOOP 62 /* Too many levels of symbolic links */ +#define XENAMETOOLONG 63 /* File name too long */ + +/* should be rearranged */ +#define XEHOSTDOWN 64 /* Host is down */ +#define XEHOSTUNREACH 65 /* No route to host */ +#define XENOTEMPTY 66 /* Directory not empty */ + +/* quotas & mush */ +#define XEPROCLIM 67 /* Too many processes */ +#define XEUSERS 68 /* Too many users */ +#define XEDQUOT 69 /* Disc quota exceeded */ + +/* Network File System */ +#define XESTALE 70 /* Stale NFS file handle */ +#define XEREMOTE 71 /* Too many levels of remote in path */ + +/* streams */ +#define XENOSTR 72 /* Device is not a stream */ +#define XETIME 73 /* Timer expired */ +#define XENOSR 74 /* Out of streams resources */ +#define XENOMSG 75 /* No message of desired type */ +#define XEBADMSG 76 /* Trying to read unreadable message */ + +/* SystemV IPC */ +#define XEIDRM 77 /* Identifier removed */ + +/* SystemV Record Locking */ +#define XEDEADLK 78 /* Deadlock condition. */ +#define XENOLCK 79 /* No record locks available. */ + +/* POSIX */ +#define XENOSYS 90 /* function not implemented */ + + +void maperror() +{ + extern int errno; + + if (errno == 0) + return; + + switch (errno) { + case ENOMSG: + errno = XENOMSG; /* No message of desired type */ + break; + case EIDRM: + errno = XEIDRM; /* Identifier removed */ + break; + case EDEADLK: + errno = XEDEADLK; /* Deadlock condition. */ + break; + case ENOLCK: + errno = XENOLCK; /* No record locks available. */ + break; + case ENOSTR: + errno = XENOSTR; /* Device not a stream */ + break; + case ETIME: + errno = XETIME; /* timer expired */ + break; + case ENOSR: + errno = XENOSR; /* out of streams resources */ + break; + case EBADMSG: + errno = XEBADMSG; /* trying to read unreadable message */ + break; + case ENOSYS: + errno = XENOSYS; /* Unsupported file system operation */ + break; + case ELOOP: + errno = XELOOP; /* Symbolic link loop */ + break; + case ERESTART: + errno = XEINTR; /* Convert ERESTART to EINTR for + interrupted system calls */ + break; + case ENAMETOOLONG: + errno = XENAMETOOLONG; /* File name too long */ + break; + case ENOTEMPTY: + errno = XENOTEMPTY; /* directory not empty */ + break; + case EUSERS: + errno = XEUSERS; /* Too many users (for UFS) */ + break; + case ENOTSOCK: + errno = XENOTSOCK; /* Socket operation on non-socket */ + break; + case EDESTADDRREQ: + errno = XEDESTADDRREQ; /* Destination address required */ + break; + case EMSGSIZE: + errno = XEMSGSIZE; /* Message too long */ + break; + case EPROTOTYPE: + errno = XEPROTOTYPE; /* Protocol wrong type for socket */ + break; + case ENOPROTOOPT: + errno = XENOPROTOOPT; /* Protocol not available */ + break; + case EPROTONOSUPPORT: + errno = XEPROTONOSUPPORT; /* Protocol not supported */ + break; + case ESOCKTNOSUPPORT: + errno = XESOCKTNOSUPPORT; /* Socket type not supported */ + break; + case EOPNOTSUPP: + errno = XEOPNOTSUPP; /* Operation not supported on socket */ + break; + case EPFNOSUPPORT: + errno = XEPFNOSUPPORT; /* Protocol family not supported */ + break; + case EAFNOSUPPORT: + errno = XEAFNOSUPPORT; /* Address family not supported by */ + break; + case EADDRINUSE: + errno = XEADDRINUSE; /* Address already in use */ + break; + case EADDRNOTAVAIL: + errno = XEADDRNOTAVAIL; /* Can't assign requested address */ + break; + case ENETDOWN: + errno = XENETDOWN; /* Network is down */ + break; + case ENETUNREACH: + errno = XENETUNREACH; /* Network is unreachable */ + break; + case ENETRESET: + errno = XENETRESET; /* Dropped connection due to reset */ + break; + case ECONNABORTED: + errno = XECONNABORTED; /* Software caused connection abort */ + break; + case ECONNRESET: + errno = XECONNRESET; /* Connection reset by peer */ + break; + case ENOBUFS: + errno = XENOBUFS; /* No buffer space available */ + break; + case EISCONN: + errno = XEISCONN; /* Socket is already connected */ + break; + case ENOTCONN: + errno = XENOTCONN; /* Socket is not connected */ + break; + case ESHUTDOWN: + errno = XESHUTDOWN; /* Can't send after socket shutdown */ + break; + case ETOOMANYREFS: + errno = XETOOMANYREFS; /* Too many references: can't splice */ + break; + case ETIMEDOUT: + errno = XETIMEDOUT; /* Connection timed out */ + break; + case ECONNREFUSED: + errno = XECONNREFUSED; /* Connection refused */ + break; + case EHOSTDOWN: + errno = XEHOSTDOWN; /* Host is down */ + break; + case EHOSTUNREACH: + errno = XEHOSTUNREACH; /* No route to host */ + break; + case EALREADY: + errno = XEALREADY; + break; + case EINPROGRESS: + errno = XEINPROGRESS; + break; + case ESTALE: + errno = XESTALE; /* Stale NFS file handle */ + break; + case EDQUOT: + errno = XEDQUOT; /* Disc quota exceeded */ + break; + default: + break; + } + + return; + +} diff --git a/usr/src/lib/libbc/libc/sys/common/mincore.c b/usr/src/lib/libbc/libc/sys/common/mincore.c new file mode 100644 index 0000000000..e35bbd71d3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/mincore.c @@ -0,0 +1,56 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* mincore.c SMI 12/14/90 */ +#include <errno.h> +#include <syscall.h> +#include <sys/types.h> +#include <unistd.h> + +#define INCORE 1; /* return only the incore status bit */ + +extern int errno; + +int mincore(addr, len, vec) +caddr_t addr; +int len; +char *vec; +{ + int i; + + if (len <0) { + errno = EINVAL; + return(-1); + } + + if(_syscall(SYS_mincore, addr, len, vec) == 0) { + for (i=0; i< len/getpagesize(); i++) { + vec[i] &= INCORE; + } + } +} diff --git a/usr/src/lib/libbc/libc/sys/common/msgsys.c b/usr/src/lib/libbc/libc/sys/common/msgsys.c new file mode 100644 index 0000000000..90dd6f02f2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/msgsys.c @@ -0,0 +1,119 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <varargs.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/msg.h> + + +/* msgsys dispatch argument */ +#define MSGGET 0 +#define MSGCTL 1 +#define MSGRCV 2 +#define MSGSND 3 + + +msgget(key, msgflg) +key_t key; +int msgflg; +{ + return(_syscall(SYS_msgsys, MSGGET, key, msgflg)); +} + +msgctl(msqid, cmd, buf) +int msqid, cmd; +struct msqid_ds *buf; +{ + return(_syscall(SYS_msgsys, MSGCTL, msqid, cmd, buf)); +} + +msgrcv(msqid, msgp, msgsz, msgtyp, msgflg) +int msqid; +struct msgbuf *msgp; +int msgsz; +long msgtyp; +int msgflg; +{ + return(_syscall(SYS_msgsys, MSGRCV, msqid, msgp, msgsz, msgtyp, msgflg)); +} + +msgsnd(msqid, msgp, msgsz, msgflg) +int msqid; +struct msgbuf *msgp; +int msgsz, msgflg; +{ + return(_syscall(SYS_msgsys, MSGSND, msqid, msgp, msgsz, msgflg)); +} + + +msgsys(sysnum, va_alist) +int sysnum; +va_dcl +{ + va_list ap; + key_t key; + int msgflg; + int msgflag; + int msqid, cmd; + struct msqid_ds *buf; + struct msgbuf *msgp; + int msgsz; + long msgtyp; + + + va_start(ap); + switch (sysnum) { + case MSGGET: + key=va_arg(ap, key_t); + msgflag=va_arg(ap, int); + return(msgget(key, msgflag)); + case MSGCTL: + msqid=va_arg(ap, int); + cmd=va_arg(ap, int); + buf=va_arg(ap, struct msqid_ds *); + return(msgctl(msqid, cmd, buf)); + case MSGRCV: + msqid=va_arg(ap, int); + msgp=va_arg(ap, struct msgbuf *); + msgsz=va_arg(ap, int); + msgtyp=va_arg(ap, long); + msgflg=va_arg(ap, int); + return(msgrcv(msqid, msgp, msgsz, msgtyp, msgflg)); + case MSGSND: + msqid=va_arg(ap, int); + msgp=va_arg(ap, struct msgbuf *); + msgsz=va_arg(ap, int); + msgflg=va_arg(ap, int); + return(msgsnd(msqid, msgp, msgsz, msgflg)); + } +} diff --git a/usr/src/lib/libbc/libc/sys/common/recv.c b/usr/src/lib/libbc/libc/sys/common/recv.c new file mode 100644 index 0000000000..3c8d9c35ee --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/recv.c @@ -0,0 +1,87 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/errno.h> + +extern int errno; + +#define N_AGAIN 11 + +int recv(s, buf, len, flags) +int s; +char *buf; +int len, flags; +{ + int a; + if ((a = _recv(s, buf, len, flags)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(errno); + } + return(a); +} + + +int recvfrom(s, buf, len, flags, from, fromlen) +int s; +char *buf; +int len, flags; +struct sockaddr *from; +int *fromlen; +{ + int a; + if ((a = _recvfrom(s, buf, len, flags, from, fromlen)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(errno); + } + return(a); +} + + +int recvmsg(s, msg, flags) +int s; +struct msghdr *msg; +int flags; +{ + int a; + if ((a = _recvmsg(s, msg, flags)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(errno); + } + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/rlimit.c b/usr/src/lib/libbc/libc/sys/common/rlimit.c new file mode 100644 index 0000000000..4cf918416b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/rlimit.c @@ -0,0 +1,68 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/time.h> +#include <sys/resource.h> +#include <sys/syscall.h> + + +/* + * The following are the resource values for SVR4. + * The resource values are mapped to SVR4 values + * before invoking the system calls. + */ +int rlim_res[RLIM_NLIMITS] = {0, 1, 2, 3, 4, -1, 5}; + +int getrlimit(resource, rlp) +int resource; +struct rlimit *rlp; +{ + return(bc_getrlimit(resource, rlp)); +} + +int bc_getrlimit(resource, rlp) +int resource; +struct rlimit *rlp; +{ + return(_syscall(SYS_getrlimit, rlim_res[resource], rlp)); +} + +int setrlimit(resource, rlp) +int resource; +struct rlimit *rlp; +{ + return(bc_setrlimit(resource, rlp)); +} + +int bc_setrlimit(resource, rlp) +int resource; +struct rlimit *rlp; +{ + return(_syscall(SYS_setrlimit, rlim_res[resource], rlp)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/s5dkio.h b/usr/src/lib/libbc/libc/sys/common/s5dkio.h new file mode 100644 index 0000000000..31e70052a3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/s5dkio.h @@ -0,0 +1,135 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990 by Sun Microsystems, Inc. + */ + +#ifndef _SYS5_DKIO_H +#define _SYS5_DKIO_H + +#pragma ident "%Z%%M% %I% %E% SMI" /* SunOS-4.0 5.19 */ + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Structures and definitions for disk io control commands + */ + +/* + * Structures used as data by ioctl calls. + */ + +/* + * Used for controller info + */ +struct s5_dk_cinfo { + char dki_cname[DK_DEVLEN]; /* controller name (no unit #) */ + short dki_ctype; /* controller type */ + short dki_flags; /* flags */ + short dki_cnum; /* controller number */ + int dki_addr; /* controller address */ + int dki_space; /* controller bus type */ + int dki_prio; /* interrupt priority */ + int dki_vec; /* interrupt vector */ + char dki_dname[DK_DEVLEN]; /* drive name (no unit #) */ + int dki_unit; /* unit number */ + int dki_slave; /* slave number */ + short dki_partition; /* partition number */ + short dki_maxtransfer; /* max. transfer size in DEV_BSIZE */ +}; + + +/* + * Disk io control commands + * Warning: some other ioctls with the DIOC prefix exist elsewhere. + */ +#define S5DKIOC (0x04 << 8) +#define S5DKIOCGGEOM (S5DKIOC|1) /* Get geometry */ +#define S5DKIOCSGEOM (S5DKIOC|2) /* Set geometry */ +#define S5DKIOCINFO (S5DKIOC|3) /* Get info */ +#define S5DKIOCSAPART (S5DKIOC|4) /* Set all partitions */ +#define S5DKIOCGAPART (S5DKIOC|5) /* Get all partitions */ + +/* + * These from hdio.h + */ +#define S5HDKIOC (0x04 << 8) +#define S5HDKIOCSTYPE (S5HDKIOC|101) /* Set drive info */ +#define S5HDKIOCGTYPE (S5HDKIOC|102) /* Get drive info */ +#define S5HDKIOCSBAD (S5HDKIOC|103) /* Set bad sector map */ +#define S5HDKIOCGBAD (S5HDKIOC|104) /* Get bad sector map */ +#define S5HDKIOCSCMD (S5HDKIOC|105) /* Set generic cmd */ +#define S5HDKIOCGDIAG (S5HDKIOC|106) /* Get diagnostics */ + +/* + * These are from cdio.h + * CDROM io control commands + */ +#define S5CDIOC (0x04 << 8) +#define S5CDROMPAUSE (S5CDIOC|151) /* Pause Audio Operation */ +#define S5CDROMRESUME (S5CDIOC|152) /* Resume paused Audio Operation */ +#define S5CDROMPLAYMSF (S5CDIOC|153) /* Play Audio MSF */ +#define S5CDROMPLAYTRKIND (S5CDIOC|154) /* Play Audio Track/index */ +#define S5CDROMREADTOCHDR (S5CDIOC|155) /* Read TOC header */ +#define S5CDROMREADTOCENTRY (S5CDIOC|156) /* Read a TOC entry */ +#define S5CDROMSTOP (S5CDIOC|157) /* Stop the CDrom drive */ +#define S5CDROMSTART (S5CDIOC|158) /* Start the CDrom drive */ +#define S5CDROMEJECT (S5CDIOC|159) /* Ejects the CDrom caddy */ +#define S5CDROMVOLCTRL (S5CDIOC|160) /* control output volume */ +#define S5CDROMSUBCHNL (S5CDIOC|161) /* read the subchannel data */ +#define S5CDROMREADMODE2 (S5CDIOC|162) /* read CDROM mode 2 data */ +#define S5CDROMREADMODE1 (S5CDIOC|163) /* read CDROM mode 1 data */ + +/* + * From sys/scsi/impl/uscsi.h +/* + * definition for user-scsi command structure + */ +struct s5_uscsi_cmd { + int uscsi_flags; /* read, write, etc. see below */ + short uscsi_status; /* resulting status */ + short uscsi_timeout; /* Command Timeout */ + caddr_t uscsi_cdb; /* cdb to send to target */ + caddr_t uscsi_bufaddr; /* i/o source/destination */ + u_int uscsi_buflen; /* size of i/o to take place */ + u_int uscsi_resid; /* resid from i/o operation */ + u_char uscsi_cdblen; /* # of valid cdb bytes */ + u_char uscsi_reserved_1; /* Reserved for Future Use */ + u_char uscsi_reserved_2; /* Reserved for Future Use */ + u_char uscsi_reserved_3; /* Reserved for Future Use */ + caddr_t uscsi_reserved_4; /* Reserved for Future Use */ + void *uscsi_reserved_5; /* Reserved for Future Use */ +}; + +/* + * User SCSI io control command + */ +#define S5USCSIIOC (0x04 << 8) +#define S5USCSICMD (S5USCSIIOC|201) /* user scsi command */ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS5_DKIO_H */ diff --git a/usr/src/lib/libbc/libc/sys/common/s5errno.h b/usr/src/lib/libbc/libc/sys/common/s5errno.h new file mode 100644 index 0000000000..0f657eb413 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/s5errno.h @@ -0,0 +1,192 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#ifndef _SYS_ERRNO_H +#define _SYS_ERRNO_H + +#ident "%Z%%M% %I% %E% SMI" + +/* + * Error codes + */ + +#define EPERM 1 /* Not super-user */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* interrupted system call */ +#define EIO 5 /* I/O error */ +#define ENXIO 6 /* No such device or address */ +#define E2BIG 7 /* Arg list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file number */ +#define ECHILD 10 /* No children */ +#define EAGAIN 11 /* No more processes */ +#define ENOMEM 12 /* Not enough core */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Mount device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* No such device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* File table overflow */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Not a typewriter */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ +#define EDOM 33 /* Math arg out of domain of func */ +#define ERANGE 34 /* Math result not representable */ +#define ENOMSG 35 /* No message of desired type */ +#define EIDRM 36 /* Identifier removed */ +#define ECHRNG 37 /* Channel number out of range */ +#define EL2NSYNC 38 /* Level 2 not synchronized */ +#define EL3HLT 39 /* Level 3 halted */ +#define EL3RST 40 /* Level 3 reset */ +#define ELNRNG 41 /* Link number out of range */ +#define EUNATCH 42 /* Protocol driver not attached */ +#define ENOCSI 43 /* No CSI structure available */ +#define EL2HLT 44 /* Level 2 halted */ +#define EDEADLK 45 /* Deadlock condition. */ +#define ENOLCK 46 /* No record locks available. */ + +/* Filesystem Quotas */ +#define EDQUOT 49 /* Disc quota exceeded */ + +/* Convergent Error Returns */ +#define EBADE 50 /* invalid exchange */ +#define EBADR 51 /* invalid request descriptor */ +#define EXFULL 52 /* exchange full */ +#define ENOANO 53 /* no anode */ +#define EBADRQC 54 /* invalid request code */ +#define EBADSLT 55 /* invalid slot */ +#define EDEADLOCK 56 /* file locking deadlock error */ + +#define EBFONT 57 /* bad font file fmt */ + +/* stream problems */ +#define ENOSTR 60 /* Device not a stream */ +#define ENODATA 61 /* no data (for no delay io) */ +#define ETIME 62 /* timer expired */ +#define ENOSR 63 /* out of streams resources */ + +#define ENONET 64 /* Machine is not on the network */ +#define ENOPKG 65 /* Package not installed */ +#define EREMOTE 66 /* The object is remote */ +#define ENOLINK 67 /* the link has been severed */ +#define EADV 68 /* advertise error */ +#define ESRMNT 69 /* srmount error */ + +#define ECOMM 70 /* Communication error on send */ +#define EPROTO 71 /* Protocol error */ +#define EMULTIHOP 74 /* multihop attempted */ +#define EBADMSG 77 /* trying to read unreadable message */ +#define ENAMETOOLONG 78 /* path name is too long */ +#define EOVERFLOW 79 /* value too large to be stored in data type */ +#define ENOTUNIQ 80 /* given log. name not unique */ +#define EBADFD 81 /* f.d. invalid for this operation */ +#define EREMCHG 82 /* Remote address changed */ + +/* shared library problems */ +#define ELIBACC 83 /* Can't access a needed shared lib. */ +#define ELIBBAD 84 /* Accessing a corrupted shared lib. */ +#define ELIBSCN 85 /* .lib section in a.out corrupted. */ +#define ELIBMAX 86 /* Attempting to link in too many libs. */ +#define ELIBEXEC 87 /* Attempting to exec a shared library. */ +#define EILSEQ 88 /* Illegal byte sequence. */ +#define ENOSYS 89 /* Unsupported file system operation */ +#define ELOOP 90 /* Symbolic link loop */ +#define ERESTART 91 /* Restartable system call */ +#define ESTRPIPE 92 /* if pipe/FIFO, don't sleep in stream head */ +#define ENOTEMPTY 93 /* directory not empty */ +#define EUSERS 94 /* Too many users (for UFS) */ + +/* BSD Networking Software */ + /* argument errors */ +#define ENOTSOCK 95 /* Socket operation on non-socket */ +#define EDESTADDRREQ 96 /* Destination address required */ +#define EMSGSIZE 97 /* Message too long */ +#define EPROTOTYPE 98 /* Protocol wrong type for socket */ +#define ENOPROTOOPT 99 /* Protocol not available */ +#define EPROTONOSUPPORT 120 /* Protocol not supported */ +#define ESOCKTNOSUPPORT 121 /* Socket type not supported */ +#define EOPNOTSUPP 122 /* Operation not supported on socket */ +#define EPFNOSUPPORT 123 /* Protocol family not supported */ +#define EAFNOSUPPORT 124 /* Address family not supported by + protocol family */ +#define EADDRINUSE 125 /* Address already in use */ +#define EADDRNOTAVAIL 126 /* Can't assign requested address */ + /* operational errors */ +#define ENETDOWN 127 /* Network is down */ +#define ENETUNREACH 128 /* Network is unreachable */ +#define ENETRESET 129 /* Network dropped connection because + of reset */ +#define ECONNABORTED 130 /* Software caused connection abort */ +#define ECONNRESET 131 /* Connection reset by peer */ +#define ENOBUFS 132 /* No buffer space available */ +#define EISCONN 133 /* Socket is already connected */ +#define ENOTCONN 134 /* Socket is not connected */ +/* XENIX has 135 - 142 */ +#define ESHUTDOWN 143 /* Can't send after socket shutdown */ +#define ETOOMANYREFS 144 /* Too many references: can't splice */ +#define ETIMEDOUT 145 /* Connection timed out */ +#define ECONNREFUSED 146 /* Connection refused */ +#define EHOSTDOWN 147 /* Host is down */ +#define EHOSTUNREACH 148 /* No route to host */ +#define EWOULDBLOCK EAGAIN +#define EALREADY 149 /* operation already in progress */ +#define EINPROGRESS 150 /* operation now in progress */ + +/* SUN Network File System */ +#define ESTALE 151 /* Stale NFS file handle */ + +#ifdef XENIX_MERGE +/* XENIX error numbers */ +#define EUCLEAN 135 /* Structure needs cleaning */ +#define ENOTNAM 137 /* Not a XENIX named type file */ +#define ENAVAIL 138 /* No XENIX semaphores available */ +#define EISNAM 139 /* Is a named type file */ +#define EREMOTEIO 140 /* Remote I/O error */ +#define EINIT 141 /* Reserved for future */ +#define EREMDEV 142 /* Error 142 */ +#endif /* XENIX_MERGE */ + +#endif /* _SYS_ERRNO_H */ diff --git a/usr/src/lib/libbc/libc/sys/common/s5fdio.h b/usr/src/lib/libbc/libc/sys/common/s5fdio.h new file mode 100644 index 0000000000..e20e1f84e2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/s5fdio.h @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1991 by Sun Microsystems, Inc. + */ + +#ifndef _SYS5_FDIO_H +#define _SYS5_FDIO_H + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Disk io control commands + */ +#define S5FDIOC (0x04 << 8) +#define S5FDIOGCHAR (S5FDIOC|51) /* GetCharacteristics */ +#define S5FDIOSCHAR (S5FDIOC|52) /* SetCharacteristics */ +#define S5FDEJECT (S5FDIOC|53) /* Eject floppy disk */ +#define S5FDGETCHANGE (S5FDIOC|54) /* Get diskchng stat */ +#define S5FDGETDRIVECHAR (S5FDIOC|55) /* Get drivechar */ +#define S5FDSETDRIVECHAR (S5FDIOC|56) /* Set drivechar */ +#define S5FDGETSEARCH (S5FDIOC|57) /* Get search tbl */ +#define S5FDSETSEARCH (S5FDIOC|58) /* Set search tbl */ +#define S5FDIOCMD (S5FDIOC|59) /* Floppy command */ +#define S5FDRAW (S5FDIOC|70) /* ECDstyle genericcmd*/ + +#ifdef __cplusplus +} +#endif + +#endif /* _SYS5_FDIO_H */ diff --git a/usr/src/lib/libbc/libc/sys/common/s5sysmacros.h b/usr/src/lib/libbc/libc/sys/common/s5sysmacros.h new file mode 100644 index 0000000000..3e59830f32 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/s5sysmacros.h @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#define L_BITSMAJOR 14 /* # of SVR4 major device bits */ +#define L_BITSMINOR 18 /* # of SVR4 minor device bits */ +#define L_MAXMIN 0x3ffff /* MAX minor for 3b2 software drivers. + ** For 3b2 hardware devices the minor is + ** restricted to 256 (0-255) + */ +#define O_BITSMINOR 8 /* # of SunOS 4.x minor device bits */ +#define O_MAXMAJ 0xff /* SunOS 4.x max major value */ +#define O_MAXMIN 0xff /* SunOS 4.x max minor value */ + +/* convert to old dev format */ + +#define cmpdev(x) (unsigned long)((((x)>>L_BITSMINOR) > O_MAXMAJ || \ + ((x)&L_MAXMIN) > O_MAXMIN) ? NODEV : \ + ((((x)>>L_BITSMINOR)<<O_BITSMINOR)|((x)&O_MAXMIN))) diff --git a/usr/src/lib/libbc/libc/sys/common/semsys.c b/usr/src/lib/libbc/libc/sys/common/semsys.c new file mode 100644 index 0000000000..be523f6a3a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/semsys.c @@ -0,0 +1,118 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2005 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <varargs.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/sem.h> + +/* semsys dispatch argument */ +#define SEMCTL 0 +#define SEMGET 1 +#define SEMOP 2 + +/*VARARGS3*/ +semctl(semid, semnum, cmd, arg) +int semid, cmd; +int semnum; +union semun arg; +{ + switch (cmd) { + + case IPC_STAT: + case IPC_SET: + cmd += 10; + /* fall-through */ + case SETVAL: + case GETALL: + case SETALL: + return(_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,arg.val)); + + case IPC_RMID: + cmd += 10; + /* fall-through */ + default: + return(_syscall(SYS_semsys,SEMCTL,semid,semnum,cmd,0)); + } +} + +semget(key, nsems, semflg) +key_t key; +int nsems, semflg; +{ + return(_syscall(SYS_semsys, SEMGET, key, nsems, semflg)); +} + +semop(semid, sops, nsops) +int semid; +struct sembuf *sops; +int nsops; +{ + return(_syscall(SYS_semsys, SEMOP, semid, sops, nsops)); +} + +semsys(sysnum, va_alist) +int sysnum; +va_dcl +{ + va_list ap; + int semid, cmd; + int semnum, val; + union semun arg; + key_t key; + int nsems, semflg; + struct sembuf *sops; + int nsops; + + va_start(ap); + switch (sysnum) { + case SEMCTL: + semid=va_arg(ap, int); + semnum=va_arg(ap, int); + cmd=va_arg(ap, int); + val=va_arg(ap, int); + if ((cmd == IPC_STAT) || (cmd == IPC_SET) || (cmd == IPC_RMID)) + cmd += 10; + return(_syscall(SYS_semsys, SEMCTL, semid, semnum, cmd, val)); + case SEMGET: + key=va_arg(ap, key_t); + nsems=va_arg(ap, int); + semflg=va_arg(ap, int); + return(semget(key, nsems, semflg)); + case SEMOP: + semid=va_arg(ap, int); + sops=va_arg(ap, struct sembuf *); + nsops=va_arg(ap, int); + return(semop(semid, sops, nsops)); + } +} + diff --git a/usr/src/lib/libbc/libc/sys/common/send.c b/usr/src/lib/libbc/libc/sys/common/send.c new file mode 100644 index 0000000000..371935f87a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/send.c @@ -0,0 +1,166 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1997 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/errno.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <sys/syslog.h> +#include <sys/strlog.h> +#include <sys/stropts.h> +#include <stdio.h> + +extern int errno; + +#define N_AGAIN 11 + +int +send(s, msg, len, flags) + int s; + char *msg; + int len, flags; +{ + int a; + if ((a = _send(s, msg, len, flags)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(); + } + return (a); +} + + +/* Added to convert socket "/dev/log" to stream "/dev/conslog" */ +#define logname "/dev/conslog" +#define MAXLINE 1024 +#define SVR4_ENOTSOCK 95 /* Socket operation on non-socket */ + + +int +sendto(s, msg, len, flags, to, tolen) + int s; + char *msg; + int len, flags; + struct sockaddr *to; + int tolen; +{ + int a; + static int LogDev = -1; + /* check for logfile */ + + if ((a = _sendto(s, msg, len, flags, to, tolen)) == -1) { + if (errno == SVR4_ENOTSOCK && + strcmp(to->sa_data, "/dev/log") == 0) { + char *msg_p; + struct log_ctl hdr; + struct strbuf dat; + struct strbuf ctl; + struct stat sbuf; + if (LogDev == -1) { + int tfd; + /* close socket /dev/log */ + close(s); + /* open stream /dev/conslog */ + tfd = open(logname, O_WRONLY); + if (tfd == -1) + return (-1); + /* insure stream has same fd as closed socket */ + if (tfd != s) { + if (dup2(tfd, s) < 0) { + close(tfd); + return (-1); + } + close(tfd); + } + if (fcntl(s, F_SETFD, FD_CLOEXEC) == -1) + return (-1); + if (fstat(s, &sbuf) != -1) + LogDev = sbuf.st_rdev; + + } else if (fstat(s, &sbuf) == -1 || + LogDev != sbuf.st_rdev) + return (-1); + + /* build the header */ + + /* parse <pri> from msg */ + + hdr.mid = 1; /* 0 for kernal */ + /* sid, ltime, ttime, seq_no not used */ + + hdr.pri = strtol(msg + 1, &msg_p, 10); + if (msg + 1 == msg_p) { + hdr.pri = (LOG_USER|LOG_INFO); + } else { + len -= msg_p - msg; + msg = msg_p + 1; + } + hdr.flags = SL_CONSOLE; + hdr.level = 0; + + ctl.maxlen = sizeof (struct log_ctl); + ctl.len = sizeof (struct log_ctl); + ctl.buf = (caddr_t)&hdr; + dat.maxlen = MAXLINE; + dat.len = len; + if (dat.len > MAXLINE) { + dat.len = MAXLINE; + msg[MAXLINE - 1] = '\0'; + } + dat.buf = msg; + + /* output the message to the local logger */ + if (_putmsg(s, &ctl, &dat, 0) == 0) + return (0); + } + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(); + } + return (a); +} + + +int +sendmsg(s, msg, flags) + int s; + struct msghdr *msg; + int flags; +{ + int a; + if ((a = _sendmsg(s, msg, flags)) == -1) { + if (errno == N_AGAIN) + errno = EWOULDBLOCK; + else + maperror(); + } + return (a); +} diff --git a/usr/src/lib/libbc/libc/sys/common/setegid.c b/usr/src/lib/libbc/libc/sys/common/setegid.c new file mode 100644 index 0000000000..9b570a34f7 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/setegid.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +setegid(int egid) +{ + return (setregid(-1, egid)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/seteuid.c b/usr/src/lib/libbc/libc/sys/common/seteuid.c new file mode 100644 index 0000000000..802f054e2f --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/seteuid.c @@ -0,0 +1,33 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +seteuid(int euid) +{ + return (setreuid(-1, euid)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/setregid.c b/usr/src/lib/libbc/libc/sys/common/setregid.c new file mode 100644 index 0000000000..f1d8f04340 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/setregid.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> + +int +setregid(int gid, int egid) +{ + if (gid > 0xffff || egid > 0xffff) { + errno = EINVAL; + return (-1); + } + return (_setregid(gid, egid)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/setreuid.c b/usr/src/lib/libbc/libc/sys/common/setreuid.c new file mode 100644 index 0000000000..1e2c448d26 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/setreuid.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> + +int +setreuid(int uid, int euid) +{ + if (uid > 0xffff || euid > 0xffff) { + errno = EINVAL; + return (-1); + } + return (_setreuid(uid, euid)); +} diff --git a/usr/src/lib/libbc/libc/sys/common/setsid.c b/usr/src/lib/libbc/libc/sys/common/setsid.c new file mode 100644 index 0000000000..138917bc4d --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/setsid.c @@ -0,0 +1,68 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1993 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/errno.h> + + +static int setsid_called = 0; +static int real_setsid_called=0; +static int setsid_val, setsid_errno; + +extern int errno; + +/* setpgrp system call number, setsid command code */ +#define SYS_pgrpsys 39 +#define SYS_setsid 3 + +setsid() +{ + if (setsid_called != getpid()) { + setsid_called = getpid(); + return(bc_setsid()); + } else { + errno = EPERM; + return(-1); + } +} + + + +int +bc_setsid() +{ + if (real_setsid_called != getpid()) { + real_setsid_called = getpid(); + setsid_val = _syscall(SYS_pgrpsys, SYS_setsid); + setsid_errno = errno; + } + errno = setsid_errno; + return(setsid_val); +} + + + diff --git a/usr/src/lib/libbc/libc/sys/common/setsockopt.c b/usr/src/lib/libbc/libc/sys/common/setsockopt.c new file mode 100644 index 0000000000..3b2c418e7b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/setsockopt.c @@ -0,0 +1,115 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1989 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> +#include <netinet/in.h> + +/* multicast setsockopts */ +#define SUNOS4X_IP_MULTICAST_IF 2 +#define SUNOS4X_IP_MULTICAST_TTL 3 +#define SUNOS4X_IP_MULTICAST_LOOP 4 +#define SUNOS4X_IP_ADD_MEMBERSHIP 5 +#define SUNOS4X_IP_DROP_MEMBERSHIP 6 +#define SUNOS5X_IP_MULTICAST_IF 0x10 +#define SUNOS5X_IP_MULTICAST_TTL 0x11 +#define SUNOS5X_IP_MULTICAST_LOOP 0x12 +#define SUNOS5X_IP_ADD_MEMBERSHIP 0x13 +#define SUNOS5X_IP_DROP_MEMBERSHIP 0x14 + +extern int errno; + +setsockopt(s, level, optname, optval, optlen) +register int s; +register int level; +register int optname; +register char *optval; +register int optlen; +{ + int a; + + if (level == SOL_SOCKET) + switch (optname) { + case SO_DONTLINGER: { + struct linger ling; + ling.l_onoff = 0; + if ((a = _setsockopt(s, level, SO_LINGER, &ling, + sizeof (struct linger))) == -1) + maperror(errno); + return (a); + } + + case SO_LINGER: + if (optlen == sizeof (int)) { + struct linger ling; + ling.l_onoff = 1; + ling.l_linger = (int)*optval; + if ((a = _setsockopt(s, level, SO_LINGER, &ling, + sizeof (struct linger))) == -1) + maperror(errno); + return (a); + } + case SO_DEBUG: + case SO_KEEPALIVE: + case SO_DONTROUTE: + case SO_USELOOPBACK: + case SO_REUSEADDR: + if (!optval) { + int val = 1; + if ((a = _setsockopt(s, level, optname, &val, + sizeof (int))) == -1) + maperror(errno); + return (a); + } + } + if (level == IPPROTO_IP) + switch (optname) { + case SUNOS4X_IP_MULTICAST_IF: + optname = SUNOS5X_IP_MULTICAST_IF; + break; + + case SUNOS4X_IP_MULTICAST_TTL: + optname = SUNOS5X_IP_MULTICAST_TTL; + break; + + case SUNOS4X_IP_MULTICAST_LOOP: + optname = SUNOS5X_IP_MULTICAST_LOOP; + break; + + case SUNOS4X_IP_ADD_MEMBERSHIP: + optname = SUNOS5X_IP_ADD_MEMBERSHIP; + break; + + case SUNOS4X_IP_DROP_MEMBERSHIP: + optname = SUNOS5X_IP_DROP_MEMBERSHIP; + break; + } + + if ((a = _setsockopt(s, level, optname, optval, optlen)) == -1) + maperror(errno); + return(a); +} diff --git a/usr/src/lib/libbc/libc/sys/common/shmsys.c b/usr/src/lib/libbc/libc/sys/common/shmsys.c new file mode 100644 index 0000000000..14e8cb2596 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/shmsys.c @@ -0,0 +1,160 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1984 AT&T */ +/* All Rights Reserved */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* from S5R2 1.3 */ + +#include <syscall.h> +#include <varargs.h> +#include <sys/types.h> +#include <sys/ipc.h> +#include <sys/shm.h> +#include <sys/errno.h> + + +/* shmsys dispatch argument */ +#define SHMAT 0 +#define SHMCTL 1 +#define SHMDT 2 +#define SHMGET 3 + +struct shmid_sv { + struct ipc_perm shm_perm; + int shm_segsz; + struct anon_map *shm_amp; + unsigned short shm_lkcnt; + char pad[2]; + short shm_lpid; + short shm_cpid; + unsigned short shm_nattch; + unsigned short shm_cnattch; + time_t shm_atime; + time_t shm_dtime; + time_t shm_ctime; +}; + + +char * +shmat(shmid, shmaddr, shmflg) + int shmid; + char *shmaddr; + int shmflg; +{ + return ((char *)_syscall(SYS_shmsys, SHMAT, shmid, shmaddr, shmflg)); +} + +shmctl(shmid, cmd, buf) + int shmid, cmd; + struct shmid_ds *buf; +{ + struct shmid_sv n_buf; + int ret; + extern int errno; + + if (buf == (struct shmid_ds *)-1) { + errno = EFAULT; + return(-1); + } + + if (buf == 0) { + ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, 0); + } else { + n_buf.shm_perm = buf->shm_perm; + n_buf.shm_segsz = buf->shm_segsz; + n_buf.shm_amp = buf->shm_amp; + n_buf.shm_lpid = buf->shm_lpid; + n_buf.shm_cpid = buf->shm_cpid; + n_buf.shm_nattch = buf->shm_nattch; + n_buf.shm_atime = buf->shm_atime; + n_buf.shm_dtime = buf->shm_dtime; + n_buf.shm_ctime = buf->shm_ctime; + n_buf.shm_lkcnt = 0; + n_buf.shm_cnattch = 0; + + ret = _syscall(SYS_shmsys, SHMCTL, shmid, cmd, &n_buf); + + buf->shm_perm = n_buf.shm_perm; + buf->shm_segsz = n_buf.shm_segsz; + buf->shm_amp = n_buf.shm_amp; + buf->shm_lpid = n_buf.shm_lpid; + buf->shm_cpid = n_buf.shm_cpid; + buf->shm_nattch = n_buf.shm_nattch; + buf->shm_atime = n_buf.shm_atime; + buf->shm_dtime = n_buf.shm_dtime; + buf->shm_ctime = n_buf.shm_ctime; + } + + return(ret); +} + +shmdt(shmaddr) + char *shmaddr; +{ + + return (_syscall(SYS_shmsys, SHMDT, shmaddr)); +} + +shmget(key, size, shmflg) + key_t key; + int size, shmflg; +{ + return (_syscall(SYS_shmsys, SHMGET, key, size, shmflg)); +} + +shmsys(sysnum, va_alist) +int sysnum; +va_dcl +{ + va_list ap; + int shmid, shmflg, cmd, size; + char *shmaddr; + struct shmid_ds *buf; + key_t key; + + va_start(ap); + switch (sysnum) { + case SHMAT: + shmid=va_arg(ap, int); + shmaddr=va_arg(ap, char *); + shmflg=va_arg(ap, int); + return((int)shmat(shmid, shmaddr, shmflg)); + case SHMCTL: + shmid=va_arg(ap, int); + cmd=va_arg(ap, int); + buf=va_arg(ap, struct shmid_ds *); + return(shmctl(shmid, cmd, buf)); + case SHMDT: + shmaddr=va_arg(ap, char *); + return(shmdt(shmaddr)); + case SHMGET: + key=va_arg(ap, key_t); + size=va_arg(ap, int); + shmflg=va_arg(ap, int); + return(shmget(key, size, shmflg)); + } +} diff --git a/usr/src/lib/libbc/libc/sys/common/shutdown.c b/usr/src/lib/libbc/libc/sys/common/shutdown.c new file mode 100644 index 0000000000..0ce818076c --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/shutdown.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/errno.h> +#include <sys/types.h> +#include <sys/socket.h> + +extern int errno; +#define N_ENOTCONN 134 + +int +shutdown(s, how) +register int s; +int how; +{ + int a; + if ((a = _shutdown(s, how)) == -1) { + if (errno == N_ENOTCONN) { + errno = 0; + a = 0; + } else + maperror(errno); + } + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/sigaction.c b/usr/src/lib/libbc/libc/sys/common/sigaction.c new file mode 100644 index 0000000000..1b1ccccf10 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sigaction.c @@ -0,0 +1,177 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <errno.h> +#include <signal.h> +#include "signalmap.h" + +static void signal_init(void); +#pragma init(signal_init) + +extern void (*handlers[])(); +extern void maphandler(int, int, struct sigcontext *, char *); +extern void (*_siguhandler[])(); /* libucb */ +extern void _sigvechandler(int, void*, void*); /* libucb */ + +extern int maptonewsig(); +extern int _sigaction(); +extern int maptonewmask(); +extern int maptooldmask(); +extern int _signal(); +extern int _sigprocmask(); +extern char *memset(); +extern int _sigpending(); + +typedef struct { + unsigned long __sigbits[4]; +} S5_sigset_t; + +typedef struct { + int sa_flags; + void (*sa_handler)(); + S5_sigset_t sa_mask; + int sa_resv[2]; +} S5_sigaction; + +#define S5_SA_ONSTACK 0x00000001 +#define S5_SA_RESETHAND 0x00000002 +#define S5_SA_RESTART 0x00000004 +#define S5_SA_NOCLDSTOP 0x00020000 + +int +sigaction(sig, act, oact) +int sig; +struct sigaction *act, *oact; +{ + S5_sigaction S5_act; + S5_sigaction S5_oact; + int ret; + int newsig; + void (*oldhand)(); + void (*oldsiguhand)(); + + newsig = maptonewsig(sig); + oldhand = handlers[newsig]; + oldsiguhand = _siguhandler[newsig]; + if (act == NULL) { + ret = _sigaction(newsig, (S5_sigaction *)NULL, &S5_oact); + } else { + S5_act.sa_flags = 0; + if (act->sa_flags & SA_ONSTACK) + S5_act.sa_flags |= S5_SA_ONSTACK; + if (act->sa_flags & SA_RESETHAND) + S5_act.sa_flags |= S5_SA_RESETHAND; + if (act->sa_flags & SA_NOCLDSTOP) + S5_act.sa_flags |= S5_SA_NOCLDSTOP; + if (!(act->sa_flags & SA_INTERRUPT)) + S5_act.sa_flags |= S5_SA_RESTART; + /* + * _sigvechandler() receives control from the OS. + * It calls through _siguhandler[] to maphandler(), + * which maps the signal number new-to-old, and + * calls the user's handler through handlers[]. + */ + handlers[newsig] = act->sa_handler; + _siguhandler[newsig] = maphandler; + if ((act->sa_handler == SIG_DFL) || + (act->sa_handler == SIG_IGN)) + S5_act.sa_handler = act->sa_handler; + else + S5_act.sa_handler = _sigvechandler; + S5_act.sa_mask.__sigbits[0] = maptonewmask(act->sa_mask); + S5_act.sa_mask.__sigbits[1] = 0; + S5_act.sa_mask.__sigbits[2] = 0; + S5_act.sa_mask.__sigbits[3] = 0; + + ret = _sigaction(newsig, &S5_act, &S5_oact); + } + + if ((oact != NULL) && (ret != -1)) { + oact->sa_flags = 0; + if (S5_oact.sa_flags & S5_SA_ONSTACK) + oact->sa_flags |= SA_ONSTACK; + if (S5_oact.sa_flags & S5_SA_RESETHAND) + oact->sa_flags |= SA_RESETHAND; + if (S5_oact.sa_flags & S5_SA_NOCLDSTOP) + oact->sa_flags |= SA_NOCLDSTOP; + if (!(S5_oact.sa_flags & S5_SA_RESTART)) + oact->sa_flags |= SA_INTERRUPT; + if ((S5_oact.sa_handler == SIG_DFL) || + (S5_oact.sa_handler == SIG_IGN)) + oact->sa_handler = S5_oact.sa_handler; + else + oact->sa_handler = oldhand; + oact->sa_mask = maptooldmask(S5_oact.sa_mask.__sigbits[0]); + } + if (ret == -1) { + handlers[newsig] = oldhand; + _siguhandler[newsig] = oldsiguhand; + } + return (ret); +} + +static void +signal_init() { +#define S5_SIGPOLL 22 + _signal(S5_SIGPOLL, SIG_IGN); +#undef S5_SIGPOLL +} + +int +sigprocmask(how, set, oset) +int how; +sigset_t *set, *oset; +{ + int how_map[] = {0, 1, 2, 0, 3}; + int ret; + S5_sigset_t s5_set, s5_oset; + + if (set == NULL) /* query */ + ret = _sigprocmask(how_map[how], NULL, &s5_oset); + else { + memset(&s5_set, 0, sizeof (S5_sigset_t)); + s5_set.__sigbits[0] = maptonewmask(*set); + ret = _sigprocmask(how_map[how], &s5_set, &s5_oset); + } + if ((oset != NULL) && (ret == 0)) + *oset = maptooldmask(s5_oset.__sigbits[0]); + return (ret); +} + +int +sigpending(set) +sigset_t *set; +{ + S5_sigset_t s5_set; + int ret; + + ret = _sigpending(&s5_set); + *set = maptooldmask(s5_set.__sigbits[0]); + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/signalmap.c b/usr/src/lib/libbc/libc/sys/common/signalmap.c new file mode 100644 index 0000000000..38df7e237a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/signalmap.c @@ -0,0 +1,319 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1996 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.2 */ + +#include "signalmap.h" +#include <sys/signal.h> +#include <sys/errno.h> + +extern int errno; +void (*handlers[32])(); /* XXX - 32??? NSIG, maybe? */ + +void maphandler(sig, code, scp, addr) +int sig, code; +struct sigcontext *scp; +char *addr; +{ + switch (sig) { + case SIGBUS: + case SIGSEGV: + switch (FC_CODE(code)) { + case 3: /* 5.x value for FC_OBJERR */ + code = FC_MAKE_ERR(FC_ERRNO(code)); + break; + case 5: /* 5.x value for FC_NOMAP */ + code = FC_NOMAP; + break; + } + break; + } + __sendsig(maptooldsig(sig), code, scp, addr, handlers[sig]); +} + +void (*signal(sig, a))() +int sig; +void (*a)(); +{ + int newsig; + + struct sigvec osv, sv; + + sv.sv_handler = a; + sv.sv_mask = 0; +#ifdef S5EMUL + sv.sv_flags = SV_INTERRUPT|SV_RESETHAND; +#else + sv.sv_flags = 0; +#endif + if (sigvec(sig, &sv, &osv) < 0) + return (BADSIG); + return (osv.sv_handler); +} + + +sigvec(sig, nvec, ovec) +int sig; +struct sigvec *nvec, *ovec; +{ + int newsig; + struct sigvec tvec, *tvecp; + void (*oldhand)(); + + if ((int)nvec == -1 || (int)ovec == -1) { + errno = EFAULT; + return (-1); + } + + newsig = maptonewsig(sig); + oldhand = handlers[newsig]; + + if ((tvecp = nvec) != 0) { + tvec = *nvec; + tvecp = &tvec; + /* + * To be compatible with the behavior of SunOS 4.x: + * If the new signal handler is SIG_IGN or SIG_DFL, + * do not change the signal's entry in the handler array. + * This allows a child of vfork(2) to set signal handlers + * to SIG_IGN or SIG_DFL without affecting the parent. + */ + if (tvecp->sv_handler != SIG_DFL && + tvecp->sv_handler != SIG_IGN) { + handlers[newsig] = tvecp->sv_handler; + tvecp->sv_handler = maphandler; + } + } + + if (ucbsigvec(newsig, tvecp, ovec) == -1) { + handlers[newsig] = oldhand; + return (-1); + } + + if (ovec && ovec->sv_handler != SIG_DFL && ovec->sv_handler != SIG_IGN) + ovec->sv_handler = oldhand; + + return (0); +} + +sigsetmask(mask) +int mask; +{ + int ret; + ret = ucbsigsetmask(maptonewmask(mask)); + return(maptooldmask(ret)); +} + +sigblock(mask) +int mask; +{ + int ret; + ret = ucbsigblock(maptonewmask(mask)); + return(maptooldmask(ret)); +} + + +int sigpause(mask) +int mask; +{ + int ret; + return(ucbsigpause(maptonewmask(mask))); +} + +siginterrupt(sig, flag) +int sig, flag; +{ + return(ucbsiginterrupt(maptonewsig(sig), flag)); +} + + +maptonewsig(sig) +int sig; +{ + switch (sig) { + case SIGURG: /* urgent condition on IO channel */ + return(XSIGURG); + case SIGSTOP: /* sendable stop signal not from tty */ + return(XSIGSTOP); + case SIGTSTP: /* stop signal from tty */ + return(XSIGTSTP); + case SIGCONT: /* continue a stopped process */ + return(XSIGCONT); + case SIGCLD: /* System V name for SIGCHLD */ + return(XSIGCLD); + case SIGTTIN: /* to readers pgrp upon background tty read */ + return(XSIGTTIN); + case SIGTTOU: /* like TTIN for output */ + return(XSIGTTOU); + case SIGIO: /* input/output possible signal */ + return(XSIGIO); + case SIGXCPU: /* exceeded CPU time limit */ + return(XSIGXCPU); + case SIGXFSZ: /* exceeded file size limit */ + return(XSIGXFSZ); + case SIGVTALRM: /* virtual time alarm */ + return(XSIGVTALRM); + case SIGPROF: /* profiling time alarm */ + return(XSIGPROF); + case SIGWINCH: /* window changed */ + return(XSIGWINCH); + case SIGLOST: /* resource lost, not supported */ + return(-1); + case SIGUSR1: + return(XSIGUSR1); + case SIGUSR2: /* user defined signal 2 */ + return(XSIGUSR2); + default: + return(sig); + } +} + + +maptooldsig(sig) +int sig; +{ + switch (sig) { + case XSIGURG: /* urgent condition on IO channel */ + return(SIGURG); + case XSIGSTOP: /* sendable stop signal not from tty */ + return(SIGSTOP); + case XSIGTSTP: /* stop signal from tty */ + return(SIGTSTP); + case XSIGCONT: /* continue a stopped process */ + return(SIGCONT); + case XSIGCLD: /* System V name for SIGCHLD */ + return(SIGCLD); + case XSIGTTIN: /* to readers pgrp upon background tty read */ + return(SIGTTIN); + case XSIGTTOU: /* like TTIN for output */ + return(SIGTTOU); + case XSIGIO: /* input/output possible signal */ + return(SIGIO); + case XSIGXCPU: /* exceeded CPU time limit */ + return(SIGXCPU); + case XSIGXFSZ: /* exceeded file size limit */ + return(SIGXFSZ); + case XSIGVTALRM: /* virtual time alarm */ + return(SIGVTALRM); + case XSIGPROF: /* profiling time alarm */ + return(SIGPROF); + case XSIGWINCH: /* window changed */ + return(SIGWINCH); + case XSIGUSR1: + return(SIGUSR1); + case XSIGUSR2: /* user defined signal 2 */ + return(SIGUSR2); + case XSIGPWR: /* user defined signal 2 */ + return(-1); + default: + return(sig); + } +} + +int maptooldmask(mask) + int mask; +{ + int omask; + + omask = mask & 0x7FFF; /* these signo are same */ + + if (mask & sigmask(XSIGURG)) + omask |= sigmask(SIGURG); + if (mask & sigmask(XSIGSTOP)) + omask |= sigmask(SIGSTOP); + if (mask & sigmask(XSIGTSTP)) + omask |= sigmask(SIGTSTP); + if (mask & sigmask(XSIGCONT)) + omask |= sigmask(SIGCONT); + if (mask & sigmask(XSIGCLD)) + omask |= sigmask(SIGCLD); + if (mask & sigmask(XSIGTTIN)) + omask |= sigmask(SIGTTIN); + if (mask & sigmask(XSIGTTOU)) + omask |= sigmask(SIGTTOU); + if (mask & sigmask(XSIGIO)) + omask |= sigmask(SIGIO); + if (mask & sigmask(XSIGXCPU)) + omask |= sigmask(SIGXCPU); + if (mask & sigmask(XSIGXFSZ)) + omask |= sigmask(SIGXFSZ); + if (mask & sigmask(XSIGVTALRM)) + omask |= sigmask(SIGVTALRM); + if (mask & sigmask(XSIGPROF)) + omask |= sigmask(SIGPROF); + if (mask & sigmask(XSIGWINCH)) + omask |= sigmask(SIGWINCH); + if (mask & sigmask(XSIGUSR1)) + omask |= sigmask(SIGUSR1); + if (mask & sigmask(XSIGUSR2)) + omask |= sigmask(SIGUSR2); + return(omask); +} + + +int maptonewmask(omask) + int omask; +{ + int mask; + + if (omask == -1) { + return(-1); + } + + mask = omask & 0x7FFF; /* these signo are the same */ + + if (omask & sigmask(SIGURG)) + mask |= sigmask(XSIGURG); + if (omask & sigmask(SIGSTOP)) + mask |= sigmask(XSIGSTOP); + if (omask & sigmask(SIGTSTP)) + mask |= sigmask(XSIGTSTP); + if (omask & sigmask(SIGCONT)) + mask |= sigmask(XSIGCONT); + if (omask & sigmask(SIGCLD)) + mask |= sigmask(XSIGCLD); + if (omask & sigmask(SIGTTIN)) + mask |= sigmask(XSIGTTIN); + if (omask & sigmask(SIGTTOU)) + mask |= sigmask(XSIGTTOU); + if (omask & sigmask(SIGIO)) + mask |= sigmask(XSIGIO); + if (omask & sigmask(SIGXCPU)) + mask |= sigmask(XSIGXCPU); + if (omask & sigmask(SIGXFSZ)) + mask |= sigmask(XSIGXFSZ); + if (omask & sigmask(SIGVTALRM)) + mask |= sigmask(XSIGVTALRM); + if (omask & sigmask(SIGPROF)) + mask |= sigmask(XSIGPROF); + if (omask & sigmask(SIGWINCH)) + mask |= sigmask(XSIGWINCH); + if (omask & sigmask(SIGUSR1)) + mask |= sigmask(XSIGUSR1); + if (omask & sigmask(SIGUSR2)) + mask |= sigmask(XSIGUSR2); + return(mask); +} diff --git a/usr/src/lib/libbc/libc/sys/common/signalmap.h b/usr/src/lib/libbc/libc/sys/common/signalmap.h new file mode 100644 index 0000000000..6e99dad5b8 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/signalmap.h @@ -0,0 +1,91 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#define XSIGUSR1 16 /* user defined signal 1 */ +#define XSIGUSR2 17 /* user defined signal 2 */ +#define XSIGCLD 18 /* System V name for SIGCHLD */ +#define XSIGPWR 19 /* power-fail restart */ +#define XSIGWINCH 20 /* window changed */ +#define XSIGURG 21 /* urgent condition on IO channel */ +#define XSIGIO 22 /* input/output possible signal */ +#define XSIGSTOP 23 /* sendable stop signal not from tty */ +#define XSIGTSTP 24 /* stop signal from tty */ +#define XSIGCONT 25 /* continue a stopped process */ +#define XSIGTTIN 26 /* to readers pgrp upon background tty read */ +#define XSIGTTOU 27 /* like TTIN for output */ +#define XSIGVTALRM 28 /* virtual time alarm */ +#define XSIGPROF 29 /* profiling time alarm */ +#define XSIGXCPU 30 /* exceeded CPU time limit */ +#define XSIGXFSZ 31 /* exceeded file size limit */ + + +/* SVR4 siginfo_t structure */ +#define SI_PAD ((128/sizeof(int)) -3) + +typedef struct siginfo { + + int si_signo; /* signal from signal.h */ + int si_code; /* code from above */ + int si_errno; /* error from errno.h */ + + union { + + int _pad[SI_PAD]; /* for future growth */ + + struct { /* kill(), SIGCLD */ + long _pid; /* process ID */ + union { + struct { + long _uid; + } _kill; + struct { + long _utime; + int _status; + long _stime; + } _cld; + } _pdata; + } _proc; + + struct { /* SIGSEGV, SIGBUS, SIGILL and SIGFPE */ + char * _addr; /* faulting address */ + } _fault; + + struct { /* SIGPOLL, SIGXFSZ */ + /* fd not currently available for SIGPOLL */ + int _fd; /* file descriptor */ + long _band; + } _file; + + } _data; + +} siginfo_t; + +#define si_pid _data._proc._pid +#define si_status _data._proc._pdata._cld._status +#define si_addr _data._fault._addr diff --git a/usr/src/lib/libbc/libc/sys/common/sigsetjmp.c b/usr/src/lib/libbc/libc/sys/common/sigsetjmp.c new file mode 100644 index 0000000000..fab2911048 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sigsetjmp.c @@ -0,0 +1,153 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <sys/setjmp.h> +#include "ucontext.h" + +int _getsp(); + +int +sigsetjmp(env, savemask) + sigjmp_buf env; + int savemask; +{ + register o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + register int sp = _getsp(); + ucontext_t uc; + + /* + * Get the current machine context. + */ + uc.uc_flags = UC_STACK | UC_SIGMASK; + __getcontext(&uc); + + /* + * Note that the pc and former sp (fp) from the stack are valid + * because the call to __getcontext must flush the user windows + * to the stack. + */ + bp->sjs_flags = 0; + bp->sjs_sp = *((int *)sp+14); + bp->sjs_pc = *((int *)sp+15) + 0x8; + bp->sjs_stack = uc.uc_stack; + + if (savemask) { + /* save the mask */ + bp->sjs_flags |= JB_SAVEMASK; + memcpy(bp->sjs_sigmask, &(uc.uc_sigmask), 3 * sizeof (int)); + } else { + memset(bp->sjs_sigmask, 0, 3 * sizeof (int)); + } + + return (0); +} + + +void +siglongjmp(env, val) + sigjmp_buf env; + int val; +{ + o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + setjmp_struct_t sjmp, *sp; + + sp = &sjmp; + sp->sjs_flags = bp->sjs_flags; + sp->sjs_sp = bp->sjs_sp; + sp->sjs_pc = bp->sjs_pc; + sp->sjs_fp = 0; + sp->sjs_i7 = 0; + sp->sjs_uclink = 0; + sp->sjs_sigmask[0] = bp->sjs_sigmask[0]; + sp->sjs_sigmask[1] = bp->sjs_sigmask[1]; + sp->sjs_sigmask[2] = bp->sjs_sigmask[2]; + sp->sjs_sigmask[3] = 0; + sp->sjs_stack = bp->sjs_stack; + + _siglongjmp(sjmp, val); +} + +int +_setjmp(env) + jmp_buf env; +{ + register o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + register int sp = _getsp(); + ucontext_t uc; + + /* + * Get the current machine context. + */ + uc.uc_flags = UC_STACK; + __getcontext(&uc); + + /* + * Note that the pc and former sp (fp) from the stack are valid + * because the call to __getcontext must flush the user windows + * to the stack. + */ + bp->sjs_flags = 0; + bp->sjs_sp = *((int *)sp+14); + bp->sjs_pc = *((int *)sp+15) + 0x8; + bp->sjs_sigmask[0] = 0; + bp->sjs_sigmask[1] = 0; + bp->sjs_sigmask[2] = 0; + bp->sjs_stack = uc.uc_stack; + + return (0); +} + + +void +_longjmp(env, val) + jmp_buf env; + int val; +{ + o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + setjmp_struct_t sjmp, *sp; + + sp = &sjmp; + sp->sjs_flags = bp->sjs_flags; + sp->sjs_sp = bp->sjs_sp; + sp->sjs_pc = bp->sjs_pc; + sp->sjs_fp = 0; + sp->sjs_i7 = 0; + sp->sjs_uclink = 0; + sp->sjs_sigmask[0] = bp->sjs_sigmask[0]; + sp->sjs_sigmask[1] = bp->sjs_sigmask[1]; + sp->sjs_sigmask[2] = bp->sjs_sigmask[2]; + sp->sjs_sigmask[3] = 0; + sp->sjs_stack = bp->sjs_stack; + + _siglongjmp(sjmp, val); +} diff --git a/usr/src/lib/libbc/libc/sys/common/socket.c b/usr/src/lib/libbc/libc/sys/common/socket.c new file mode 100644 index 0000000000..a804463505 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/socket.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1996 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/errno.h> + +extern int errno; + +int +socket(family, type, protocol) +register int family; +register int type; +register int protocol; +{ + int a; + static int map[]={0,2,1,4,5,6}; + if ((a = _socket_bsd(family, map[type], protocol)) == -1) { + maperror(errno); + switch (errno) { + case EAFNOSUPPORT: + case EPROTOTYPE: + errno = EPROTONOSUPPORT; + break; + } + } + return(a); +} + + diff --git a/usr/src/lib/libbc/libc/sys/common/socketpair.c b/usr/src/lib/libbc/libc/sys/common/socketpair.c new file mode 100644 index 0000000000..8a70bf5ea1 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/socketpair.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1996 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/socket.h> +#include <sys/errno.h> + +extern int errno; + +int +socketpair(family, type, protocol, sv) +register int family; +register int type; +register int protocol; +register int sv[2]; +{ + int ret; + static int map[] = {0, 2, 1, 4, 5, 6}; + if ((ret = _socketpair_bsd(family, map[type], protocol, + sv)) == -1) { + maperror(errno); + switch (errno) { + case EAFNOSUPPORT: + case EPROTOTYPE: + errno = EPROTONOSUPPORT; + break; + } + } + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_exit.s b/usr/src/lib/libbc/libc/sys/common/sparc/_exit.s new file mode 100644 index 0000000000..4608b4faac --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_exit.s @@ -0,0 +1,29 @@ +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! +! "%Z%%M% %I% %E% SMI" +! Copyright (c) 1986 by Sun Microsystems, Inc. +! + .seg ".text" + +#include "SYS.h" + + PSEUDO(_exit,exit) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_read.s b/usr/src/lib/libbc/libc/sys/common/sparc/_read.s new file mode 100644 index 0000000000..c74875cdd0 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_read.s @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */ + +/* C library -- read */ +/* int read (int fildes, void *buf, unsigned nbyte); */ + + .file "_read.s" + +#include "SYS.h" + + SYSREENTRY(_read) + mov SYS_read, %g1 + t 8 + SYSRESTART(.restart__read) + RET + + SET_SIZE(_read) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_readv.s b/usr/src/lib/libbc/libc/sys/common/sparc/_readv.s new file mode 100644 index 0000000000..17476b896a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_readv.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */ + +/* C library -- readv */ + + .file "_readv.s" + +#include "SYS.h" + + SYSREENTRY(_readv) + mov SYS_readv, %g1 + t 8 + SYSRESTART(.restart__readv) + RET + + SET_SIZE(_readv) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_syscall.s b/usr/src/lib/libbc/libc/sys/common/sparc/_syscall.s new file mode 100644 index 0000000000..678f8b9a28 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_syscall.s @@ -0,0 +1,36 @@ +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! +! "%Z%%M% %I% %E% SMI" +! Copyright (c) 1986 by Sun Microsystems, Inc. +! +! .seg "text" + + .file "_syscall.s" + +#include "SYS.h" + +#define SYS_syscall 0 /* SYS_indir */ + + BSDSYSCALL(syscall) + RET + + SET_SIZE(_syscall) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_write.s b/usr/src/lib/libbc/libc/sys/common/sparc/_write.s new file mode 100644 index 0000000000..effdb03eb9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_write.s @@ -0,0 +1,43 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */ + +/* C library -- write */ +/* int write (int fildes, void *buf, unsigned nbyte); */ + + .file "_write.s" + +#include "SYS.h" + + SYSREENTRY(_write) + mov SYS_write, %g1 + t 8 + SYSRESTART(.restart__write) + RET + + SET_SIZE(_write) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/_writev.s b/usr/src/lib/libbc/libc/sys/common/sparc/_writev.s new file mode 100644 index 0000000000..282c206156 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/_writev.s @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.9 */ + +/* C library -- writev */ + + .file "_writev.s" + +#include "SYS.h" + + SYSREENTRY(_writev) + mov SYS_writev, %g1 + t 8 + SYSRESTART(.restart__writev) + RET + + SET_SIZE(_writev) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/brk.s b/usr/src/lib/libbc/libc/sys/common/sparc/brk.s new file mode 100644 index 0000000000..da5a832b97 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/brk.s @@ -0,0 +1,52 @@ +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! +! "%Z%%M% %I% %E% SMI" +! Copyright (c) 1986 by Sun Microsystems, Inc. +! + .seg ".text" + +#include "SYS.h" +#define ALIGNSIZE 8 + +#define SYS_brk 17 + + .global .curbrk + .type .curbrk,#object + .size .curbrk,4 + + ENTRY(brk) + add %o0, (ALIGNSIZE-1), %o0 ! round up new break to a + andn %o0, (ALIGNSIZE-1), %o0 ! multiple of alignsize + mov %o0, %o2 ! save new break + mov SYS_brk, %g1 + t 8 + CERROR(o5) +#ifdef PIC + PIC_SETUP(o5) + ld [%o5 + .curbrk], %g1 + st %o2, [%g1] +#else + sethi %hi(.curbrk), %g1 ! save new break + st %o2, [%g1 + %lo(.curbrk)] +#endif + RET + SET_SIZE(brk) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/cerror.s b/usr/src/lib/libbc/libc/sys/common/sparc/cerror.s new file mode 100644 index 0000000000..cc18490166 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/cerror.s @@ -0,0 +1,52 @@ +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! +! "%Z%%M% %I% %E% SMI" +! Copyright (c) 1986 by Sun Microsystems, Inc. +! +! Note this routine used to be called cerror, the +! file name will not change for now. We might go +! back to the old name. + +! .seg "text" + +#include "SYS.h" + +! .seg "text" + .global .cerror + .global errno + + ENTRY(.cerror) +#ifdef PIC + PIC_SETUP(o5) + ld [%o5 + errno], %g1 + st %o0, [%g1] +#else + sethi %hi(errno), %g1 + st %o0, [%g1 + %lo(errno)] +#endif + save %sp, -SA(MINFRAME), %sp + call maperror,0 + nop + ret + restore %g0, -1, %o0 + + SET_SIZE(.cerror) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/errno.s b/usr/src/lib/libbc/libc/sys/common/sparc/errno.s new file mode 100644 index 0000000000..8b778008d2 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/errno.s @@ -0,0 +1,32 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* #ident "%Z%%M% %I% %E% SMI" */ + .globl _errno + .seg ".data" + .align 4 +_errno: .word 0 + diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/getmsg.s b/usr/src/lib/libbc/libc/sys/common/sparc/getmsg.s new file mode 100644 index 0000000000..847a2a9e21 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/getmsg.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ + +/* C library -- getmsg */ +/* int getmsg (int fd, struct strbuf *ctlptr, */ +/* struct strbuf *dataptr, int *flags) */ + +#include "SYS.h" + + .file "getmsg.s" + + SYSCALL_RESTART(getmsg) + RET + + SET_SIZE(getmsg) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/getppid.s b/usr/src/lib/libbc/libc/sys/common/sparc/getppid.s new file mode 100644 index 0000000000..6072ab0986 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/getppid.s @@ -0,0 +1,35 @@ +! +! "%Z%%M% %I% %E%" +! ident "%Z%%M% %I% %E% SMI" +! Copyright 2005 Sun Microsystems, Inc. All rights reserved. +! Use is subject to license terms. +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! + .seg ".text" + +#include "SYS.h" + + PSEUDO(getppid,getpid) + retl /* ppid = getppid(); */ + mov %o1, %o0 + + SET_SIZE(getppid) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/mmap.s b/usr/src/lib/libbc/libc/sys/common/sparc/mmap.s new file mode 100644 index 0000000000..8d50eb00f3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/mmap.s @@ -0,0 +1,49 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * ident "%Z%%M% %I% %E% SMI" + */ + +/* + * Interface to mmap introduced in 4.0. Incorporates flag telling + * system to use 4.0 interface to mmap. + */ + +#include "SYS.h" +#include <sys/mman.h> + +#define FLAGS %o3 + +ENTRY(mmap) + sethi %hi(_MAP_NEW), %g1 + or %g1, FLAGS, FLAGS + mov SYS_mmap, %g1 + t 8 + CERROR(o5) + RET + +SET_SIZE(mmap) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/pipe.s b/usr/src/lib/libbc/libc/sys/common/sparc/pipe.s new file mode 100644 index 0000000000..5f12b48f55 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/pipe.s @@ -0,0 +1,41 @@ +! +! ident "%Z%%M% %I% %E% SMI" +! Copyright 2005 Sun Microsystems, Inc. All rights reserved. +! Use is subject to license terms. +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! + .seg ".text" + +#include "SYS.h" + + + ENTRY(pipe) + mov %o0, %o2 ! save ptr to array + mov SYS_pipe, %g1 + t 8 + CERROR(o5); + st %o0, [%o2] + st %o1, [%o2 + 4] + retl + clr %o0 + + SET_SIZE(pipe) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/putmsg.s b/usr/src/lib/libbc/libc/sys/common/sparc/putmsg.s new file mode 100644 index 0000000000..63714b4555 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/putmsg.s @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* Copyright (c) 1989 by Sun Microsystems, Inc. */ + +.ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.5 */ + +/* C library -- putmsg */ +/* int putmsg (int fd, struct const strbuf *ctlptr, + struct const strbuf *dataptr, int *flags) */ + +#include "SYS.h" + + .file "putmsg.s" + + SYSCALL_RESTART(putmsg) + RET + + SET_SIZE(putmsg) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/sbrk.s b/usr/src/lib/libbc/libc/sys/common/sparc/sbrk.s new file mode 100644 index 0000000000..144c217961 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/sbrk.s @@ -0,0 +1,71 @@ +! +! CDDL HEADER START +! +! The contents of this file are subject to the terms of the +! Common Development and Distribution License, Version 1.0 only +! (the "License"). You may not use this file except in compliance +! with the License. +! +! You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE +! or http://www.opensolaris.org/os/licensing. +! See the License for the specific language governing permissions +! and limitations under the License. +! +! When distributing Covered Code, include this CDDL HEADER in each +! file and include the License file at usr/src/OPENSOLARIS.LICENSE. +! If applicable, add the following below this CDDL HEADER, with the +! fields enclosed by brackets "[]" replaced with your own identifying +! information: Portions Copyright [yyyy] [name of copyright owner] +! +! CDDL HEADER END +! +! "%Z%%M% %I% %E% SMI" +! Copyright (c) 1986 by Sun Microsystems, Inc. +! +! .seg "text" + + .file "sbrk.s" + +#include "SYS.h" +#include <sys/syscall.h> + +#define ALIGNSIZE 8 + + .global .curbrk + .type .curbrk,#object + .size .curbrk,4 + + .global end + .section ".data" + .align 4 +.curbrk: + .word end + + ENTRY(sbrk) + add %o0, (ALIGNSIZE-1), %o0 ! round up request to align size + andn %o0, (ALIGNSIZE-1), %o0 +#ifdef PIC + PIC_SETUP(o5) + ld [%o5 + .curbrk], %g1 + ld [%g1], %o3 +#else + sethi %hi(.curbrk), %o2 + ld [%o2 + %lo(.curbrk)], %o3 +#endif + add %o3, (ALIGNSIZE-1), %o3 ! round up .curbrk to align size + andn %o3, (ALIGNSIZE-1), %o3 + add %o3, %o0, %o0 ! new break setting = request + .curbrk + mov %o0, %o4 ! save it + mov SYS_brk, %g1 + t 8 + CERROR(o5) +#ifdef PIC + PIC_SETUP(o5) + ld [%o5 + .curbrk], %g1 + st %o4, [%g1] +#else + st %o4, [%o2 + %lo(.curbrk)] ! store new break in .curbrk +#endif + retl + mov %o3, %o0 ! return old break + SET_SIZE(sbrk) diff --git a/usr/src/lib/libbc/libc/sys/common/sparc/sendsig.s b/usr/src/lib/libbc/libc/sys/common/sparc/sendsig.s new file mode 100644 index 0000000000..1f95b5f05b --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/sparc/sendsig.s @@ -0,0 +1,51 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ + .ident "%Z%%M% %I% %E% SMI" + +/* + * Copyright (c) 1993 by Sun Microsystems, Inc. + */ + +#include <sys/asm_linkage.h> + +! +! __sendsig(sig, code, scp, addr, sigfunc) +! +! Call a signal handler in a way that's compatible with statically +! linked 4.x binaries. +! +! We have to save our first four arguments to the stack because +! that's what the 4.x kernel did and that's where the signal handler +! (__sigtramp, normally) expects to find them. +! +ENTRY_NP(__sendsig) + save %sp, -SA(MINFRAME), %sp + ! save i0-i3 to stack, %sp+64 (WINDOWSIZE) + std %i0, [%sp + WINDOWSIZE] + std %i2, [%sp + WINDOWSIZE + 8] + mov %i0, %o0 ! pass parameters in %o regs as well, in case + mov %i1, %o1 ! we're calling directly into C code (as will + mov %i2, %o2 ! happen if the a.out is dynamically linked) + jmpl %i4, %o7 ! call the signal handler + mov %i3, %o3 + ret + restore diff --git a/usr/src/lib/libbc/libc/sys/common/syscall.c b/usr/src/lib/libbc/libc/sys/common/syscall.c new file mode 100644 index 0000000000..93eb70df09 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/syscall.c @@ -0,0 +1,556 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> +#include <stdio.h> +#include <varargs.h> +#include <sys/syscall.h> +#include "xsyscall.h" + +/* + * Array of SVR4 system call numbers. The 4.1 numbers are mapped + * to their SVR4/5.0 equivalents before trapping into the kernel. + */ + +int syscallnum[190] = { SYS_syscall, SYS_exit, SYS_fork, + SYS_read, SYS_write, SYS_open, SYS_close, + -1, SYS_creat, SYS_link, SYS_unlink, + -1, SYS_chdir, 0, SYS_mknod, + SYS_chmod, SYS_lchown, 0, 0, + SYS_lseek, SYS_getpid, 0, 0, + 0, SYS_getuid, 0, SYS_ptrace, + 0, 0, 0, 0, + 0, 0, SYS_access, 0, + 0, SYS_sync, SYS_kill, SYS_stat, + 0, SYS_lstat, SYS_dup, SYS_pipe, + 0, SYS_profil, 0, 0, + SYS_getgid, 0, 0, 0, + SYS_acct, 0, -1, SYS_ioctl, + -1 /*reboot*/, 0, SYS_symlink, SYS_readlink, + SYS_execve, SYS_umask, SYS_chroot, SYS_fstat, + 0, -1/*getpagesize*/,-1, 0, + 0, 0, -1, -1, + SYS_mmap, -1, SYS_munmap, SYS_mprotect, + -1 /*advise*/, SYS_vhangup, 0, SYS_mincore, + SYS_getgroups, SYS_setgroups, -1 /*getpgrp*/, -1 /*setpgrp*/, + SYS_setitimer, 0, -1 /*swapon*/, SYS_getitimer, + -1/*gethostname*/,-1/*sethostname*/,-1/*getdtablesize*/,-1/*dup2*/, + -1/*getdopt*/, SYS_fcntl, -1 /*select*/, -1 /*setdopt*/, + SYS_fsync, -1 /*setprio*/, -1 /*socket*/, -1 /*connect*/, + -1 /*accept*/, -1 /*getprio*/, -1 /*send*/, -1 /*recv*/, + 0, -1 /*bind*/, -1 /*setsockopt*/,-1 /*listen*/, + 0, -1 /*sigvec*/, -1 /*sigblock*/, -1 /*sigsetmask*/, + -1 /*sigpause*/, -1 /*sigstack*/, -1 /*recvmsg*/, -1 /*sendmsg*/, + -1 /*vtrace*/, SYS_gettimeofday, -1 /*getrusage*/, -1 /*getsockopt*/, + 0, SYS_readv, SYS_writev, -1 /*settimeofday*/, + SYS_fchown, SYS_fchmod, -1 /*recvfrom*/, -1 /*setreuid*/, + -1 /*getregid*/, SYS_rename, -1 /*truncate*/, -1 /*ftruncate*/, + -1 /*flock*/, 0, -1 /*sendto*/, -1 /*shutdown*/, + -1 /*socketpair*/,SYS_mkdir, SYS_rmdir, SYS_utimes, + 0, SYS_adjtime, -1 /*getpeername*/,-1 /*gethostid*/, + 0, SYS_getrlimit, SYS_setrlimit, -1 /*killpg*/, + 0, 0, 0, -1/*getsockname*/, + SYS_getmsg, SYS_putmsg, SYS_poll, 0, + -1/*nfssvc*/, -1 /*getdirentries*/, SYS_statfs, SYS_fstatfs, + SYS_umount, -1 /*async_daemmon*/ -1 /*getfh*/, -1/*getdomain*/, + -1/*setdomain*/, 0, -1 /*quotactl*/, -1 /*exportfs*/, + SYS_mount, -1/*ustat*/, SYS_semsys, SYS_msgsys, + SYS_shmsys, -1 /*auditsys*/, -1 /*rfsys*/, SYS_getdents, + -1 /*setsid*/, SYS_fchdir, SYS_fchroot, -1 /*vpixsys*/, + -1 /*aioread*/, -1 /*aiowrite*/, -1 /*aiocancel*/, SYS_sigpending, + 0, -1 /*setpgid*/, SYS_pathconf, SYS_uname, +}; + + +syscall(sysnum, va_alist) +int sysnum; +va_dcl +{ + va_list ap; + int i1, i2, i3, i4; + char *c1, *c2, *c3, *c4; + + va_start(ap); + switch(sysnum) { + case XSYS_read: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(bc_read(i1, c1, i2)); + case XSYS_write: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(bc_write(i1, c1, i2)); + case XSYS_readv: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(bc_readv(i1, c1, i2)); + case XSYS_writev: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(bc_writev(i1, c1, i2)); + case XSYS_open: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + if (i2) + return(bc_open(c1, i1, i2)); + else + return(bc_open(c1, i1)); + case XSYS_close: + i1 = va_arg(ap, int); + return(bc_close(i1)); + case XSYS_fcntl: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(bc_fcntl(i1, i2, i3)); + case XSYS_select: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + c3 = va_arg(ap, char *); + c4 = va_arg(ap, char *); + return(_select(i1, c1, c2, c3, c4)); + case XSYS_ioctl : + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(bc_ioctl(i1, i2, c1)); + case XSYS_stat: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(bc_stat(c1, c2)); + case XSYS_lstat: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(bc_lstat(c1, c2)); + case XSYS_fstat: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(bc_fstat(i1, c1)); + case XSYS_getdents: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(bc_getdents(i1, c1, i2)); + case XSYS_kill: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(bc_kill(i1, i2)); + case XSYS_mount: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + i1 = va_arg(ap, int); + c3 = va_arg(ap, char *); + return(mount(c1, c2, i1, c3)); + case XSYS_getrlimit: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(bc_getrlimit(i1, c1)); + case XSYS_setrlimit: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(bc_setrlimit(i1, c1)); + case XSYS_uname: + c1 = va_arg(ap, char *); + return(bc_uname(c1)); + case XSYS_creat: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(creat(c1, i1)); + case XSYS_unmount: + c1 = va_arg(ap, char *); + return(umount(c1)); + case XSYS_link: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(link(c1, c2)); + case XSYS_unlink: + c1 = va_arg(ap, char *); + return(unlink(c1)); + case XSYS_chdir: + c1 = va_arg(ap, char *); + return(chdir(c1)); + case XSYS_mknod: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(mknod(c1, i1, i2)); + case XSYS_chmod: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(chmod(c1, i1)); + case XSYS_chown: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(chown(c1, i1, i2)); + case XSYS_lseek: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(lseek(i1, i2, i3)); + case XSYS_access: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(access(c1, i1)); + case XSYS_dup: + i1 = va_arg(ap, int); + return(dup(i1)); + case XSYS_dup2: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(dup(i1, i2)); + case XSYS_pipe: + c1 = (char *)va_arg(ap, int *); + return(pipe(c1)); + case XSYS_symlink: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(symlink(c1, c2)); + case XSYS_readlink: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(readlink(c1, c2, i1)); + case XSYS_execve: + c1 = va_arg(ap, char *); + c2 = (char *)va_arg(ap, char **); + c3 = (char *)va_arg(ap, char **); + return(execve(c1, c2, c3)); + case XSYS_chroot: + c1 = va_arg(ap, char *); + return(chroot(c1)); + case XSYS_getgroups: + i1 = va_arg(ap, int); + c1 = (char *)va_arg(ap, int *); + return(getgroups(i1, c1)); + case XSYS_setgroups: + i1 = va_arg(ap, int); + c1 = (char *)va_arg(ap, int *); + return(setgroups(i1, c1)); + case XSYS_fsync: + i1 = va_arg(ap, int); + return(fsync(i1)); + case XSYS_gettimeofday: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(gettimeofday(c1, c2)); + case XSYS_settimeofday: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(settimeofday(c1, c2)); + case XSYS_rename: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(rename(c1, c2)); + case XSYS_mkdir: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(mkdir(c1, i1)); + case XSYS_rmdir: + c1 = va_arg(ap, char *); + return(rmdir(c1)); + case XSYS_statfs: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(statfs(c1, c2)); + case XSYS_fstatfs: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(fstatfs(i1, c1)); + case XSYS_getpagesize: + return(getpagesize()); + case XSYS_gethostid: + return(gethostid()); + case XSYS_getdtablesize: + return(getdtablesize()); + case XSYS_pathconf: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(pathconf(c1, i1)); + case XSYS_gethostname: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(gethostname(c1, i1)); + case XSYS_sethostname: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(sethostname(c1, i1)); + case XSYS_setreuid: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(setreuid(i1, i2)); + case XSYS_setregid: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(setregid(i1, i2)); + case XSYS_getpriority: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(getpriority(i1, i2)); + case XSYS_setpriority: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(setpriority(i1, i2, i3)); + case XSYS_sigvec: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(sigvec(i1, c1, c2)); + case XSYS_sigblock: + i1 = va_arg(ap, int); + return(sigblock(i1)); + case XSYS_sigpending: + c1 = va_arg(ap, char *); + return(sigpending(c1)); + case XSYS_sigsetmask: + i1 = va_arg(ap, int); + return(sigsetmask(i1)); + case XSYS_sigpause: + c1 = va_arg(ap, char *); + return(sigpause(c1)); + case XSYS_sigstack: + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(sigstack(c1, c2)); + case XSYS_truncate: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(truncate(c1, i1)); + case XSYS_ftruncate: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(ftruncate(i1, i2)); + case XSYS_killpg: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(killpg(i1, i2)); + case XSYS_setpgid: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(setpgid(i1, i2)); + case XSYS_ptrace: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i4 = va_arg(ap, int); + c2 = va_arg(ap, char *); + return(ptrace(i1, i2, i3, c1, i4, c2)); +#ifdef S5EMUL + case XSYS_getpgrp: + return(getpgrp()); + case XSYS_setpgrp: + return(setpgrp()); +#else + case XSYS_getpgrp: + i1 = va_arg(ap, int); + return(getpgrp(i1)); + case XSYS_setpgrp: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(setpgrp(i1, i2)); +#endif + case XSYS_getrusage: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(getrusage(i1, c1)); + case XSYS_setsid: + return(setsid()); + + case XSYS_flock: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(flock(i1, i2)); + + /* the following system calls are now implemented in + * libsocket */ + case XSYS_accept: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = (char *)va_arg(ap, int *); + return(_accept(i1, c1, c2)); + case XSYS_bind: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(_bind(i1, c1, i2)); + case XSYS_connect: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(_connect(i1, c1, i2)); + case XSYS_getsockopt: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(_getsockopt(i1, i2, i3, c1, c2)); + case XSYS_getpeername: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(_getpeername(i1, c1, c2)); + case XSYS_getsockname: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + c2 = va_arg(ap, char *); + return(_getsockname(i1, c1, c2)); + case XSYS_getdomainname: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(getdomainname(c1, i1)); + case XSYS_listen: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(_listen(i1, i2)); + case XSYS_recv: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(_recv(i1, c1, i2, i3)); + case XSYS_recvfrom: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c2 = va_arg(ap, char *); + c3 = va_arg(ap, char *); + return(_recvfrom(i1, c1, i2, i3, c2, c3)); + case XSYS_recvmsg: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(_recvmsg(i1, c1, i2)); + case XSYS_send: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(_send(i1, c1, i2, i3)); + case XSYS_sendto: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c2 = va_arg(ap, char *); + i4 = va_arg(ap, int); + return(_sendto(i1, c1, i2, i3, c2, i4)); + case XSYS_sendmsg: + i1 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i2 = va_arg(ap, int); + return(_sendmsg(i1, c1, i2)); + case XSYS_setdomainname: + c1 = va_arg(ap, char *); + i1 = va_arg(ap, int); + return(setdomainname(c1 ,i1)); + case XSYS_setsockopt: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c1 = va_arg(ap, char *); + i4 = va_arg(ap, int); + return(_setsockopt(i1, i2, i3, c1, i4)); + case XSYS_shutdown: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + return(_shutdown(i1, i2)); + case XSYS_socket: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + return(_socket(i1, i2, i3)); + case XSYS_socketpair: + i1 = va_arg(ap, int); + i2 = va_arg(ap, int); + i3 = va_arg(ap, int); + c1 = va_arg(ap, char *); + return(_socketpair(i1, i2, i3, c1)); + + + /* The following can directly go through syscall */ + case XSYS_acct: + case XSYS_adjtime: + case XSYS_exit: + case XSYS_fchdir: + case XSYS_fchmod: + case XSYS_fchown: + case XSYS_fchroot: + case XSYS_fork: + case XSYS_getgid: + case XSYS_getitimer: + case XSYS_getmsg: + case XSYS_getpid: + case XSYS_getuid: + case XSYS_mincore: + case XSYS_mprotect: + case XSYS_munmap: + case XSYS_putmsg: + case XSYS_poll: + case XSYS_profil: + case XSYS_setitimer: + case XSYS_sync: + case XSYS_umask: + case XSYS_utimes: + case XSYS_semsys: + case XSYS_msgsys: + case XSYS_shmsys: + case XSYS_mmap: + case XSYS_vhangup: + return(_syscall(syscallnum[sysnum], va_alist)); + + case XSYS_aioread: + case XSYS_aiowrite: + case XSYS_aiocancel: + case XSYS_swapon: + case XSYS_async_daemon: + case XSYS_getfh: + case XSYS_nfssvc: + case XSYS_exportfs: + case XSYS_auditsys: + case XSYS_vpixsys: + case XSYS_quotactl: + case XSYS_getdopt: + case XSYS_setdopt: + case XSYS_ustat: + case XSYS_vtrace: + case XSYS_reboot: + case XSYS_madvise: + case XSYS_vadvise: + case XSYS_getdirentries: + fprintf(stderr,"system call not supported\n"); + return(-1); + } +} diff --git a/usr/src/lib/libbc/libc/sys/common/ucontext.h b/usr/src/lib/libbc/libc/sys/common/ucontext.h new file mode 100644 index 0000000000..8f2243d85e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/ucontext.h @@ -0,0 +1,141 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This file contains all the type definitions necessary to + * define the equivalent of SVR4 struct ucontext. + */ + +/* Definition for alternate stack */ +typedef struct sigaltstack { + char *ss_sp; + int ss_size; + int ss_flags; +} stack_t; + +/* Register window */ +struct rwindow { + int rw_local[8]; /* locals */ + int rw_in[8]; /* ins */ +}; + +#define SPARC_MAXREGWINDOW 31 /* max windows in SPARC arch. */ + +struct gwindows { + int wbcnt; + int *spbuf[SPARC_MAXREGWINDOW]; + struct rwindow wbuf[SPARC_MAXREGWINDOW]; +}; + +typedef struct gwindows gwindows_t; + +/* Floating point registers */ +struct fpq { + unsigned long *fpq_addr; /* address */ + unsigned long fpq_instr; /* instruction */ +}; + +struct fq { + union { /* FPU inst/addr queue */ + double whole; + struct fpq fpq; + } FQu; +}; + +struct fpu { + union { /* FPU floating point regs */ + unsigned fpu_regs[32]; /* 32 singles */ + double fpu_dregs[16]; /* 16 doubles */ + } fpu_fr; + struct fq *fpu_q; /* ptr to array of FQ entries */ + unsigned fpu_fsr; /* FPU status register */ + unsigned char fpu_qcnt; /* # of entries in saved FQ */ + unsigned char fpu_q_entrysize; /* # of bytes per FQ entry */ + unsigned char fpu_en; /* flag signifying fpu in use */ +}; + +typedef struct fpu fpregset_t; + +/* Register set */ +#define NGREG 19 + +typedef int gregset_t[NGREG]; + +typedef struct mcontext{ + gregset_t gregs; /* general register set */ + gwindows_t *gwins; /* POSSIBLE pointer to register windows */ + fpregset_t fpregs; /* floating point register set */ + long filler[21]; +} mcontext_t; + + +typedef struct ucontext{ + unsigned long uc_flags; + struct ucontext *uc_link; + unsigned long uc_sigmask[4]; + stack_t uc_stack; + mcontext_t uc_mcontext; + long uc_filler[23]; +} ucontext_t; + + + +/* The following is needed by the setjmp/longjmp routines */ + +#define _ABI_JBLEN 12 /* _JBLEN from base */ + +/* + * The following structure MUST match the ABI size specifier _SIGJBLEN. + * This is 19 (words). The ABI value for _JBLEN is 12 (words). + * A sigset_t is 16 bytes and a stack_t is 12 bytes. The layout must + * match sigjmp_struct_t, defined in usr/src/lib/libc/inc/sigjmp_struct.h + */ +typedef struct setjmp_struct_t { + int sjs_flags; /* JBUF[ 0] */ + int sjs_sp; /* JBUF[ 1] */ + int sjs_pc; /* JBUF[ 2] */ + int sjs_fp; /* JBUF[ 3] */ + int sjs_i7; /* JBUF[ 4] */ + void *sjs_uclink; + unsigned long sjs_pad[_ABI_JBLEN - 6]; + unsigned long sjs_sigmask[4]; + stack_t sjs_stack; +} setjmp_struct_t; + +typedef struct o_setjmp_struct_t { + int sjs_flags; /* JBUF[ 0] */ + int sjs_sp; /* JBUF[ 1] */ + int sjs_pc; /* JBUF[ 2] */ + unsigned long sjs_sigmask[3]; + stack_t sjs_stack; +} o_setjmp_struct_t; + +#define JB_SAVEMASK 0x1 +#define UC_SIGMASK 001 +#define UC_STACK 002 + diff --git a/usr/src/lib/libbc/libc/sys/common/uname.c b/usr/src/lib/libbc/libc/sys/common/uname.c new file mode 100644 index 0000000000..ef09e18f63 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/uname.c @@ -0,0 +1,85 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> +#include <string.h> +#include <sys/utsname.h> +#include <sys/syscall.h> + +/* + * utsname structure has a different format in SVr4/SunOS 5.0. + * The data needs to be mapped before returning to the user. + */ + +/* + * The following values and structure are from the SVR4 utsname.h. + */ +#define NEW_SYS_NMLN 257 +#define SYS_NMLN 9 +#define SYS_NDLN 65 + +struct n_utsname { + char sysname[NEW_SYS_NMLN]; + char nodename[NEW_SYS_NMLN]; + char release[NEW_SYS_NMLN]; + char version[NEW_SYS_NMLN]; + char machine[NEW_SYS_NMLN]; +}; + +int uname( uts ) +register struct utsname *uts; /* where to put results */ +{ + return(bc_uname(uts)); +} + +int bc_uname( uts ) +struct utsname *uts; +{ + struct n_utsname n_uts; + int ret; + + if ((ret = _syscall(SYS_uname, &n_uts)) != -1) { + memcpy(uts->sysname, n_uts.sysname, SYS_NMLN); + if (strlen(n_uts.sysname) > SYS_NMLN) + uts->sysname[SYS_NMLN-1] = '\0'; + memcpy(uts->nodename, n_uts.nodename, SYS_NDLN); + if (strlen(n_uts.nodename) > SYS_NDLN) + uts->nodename[SYS_NDLN-1] = '\0'; + memcpy(uts->release, n_uts.release, SYS_NMLN); + if (strlen(n_uts.release) > SYS_NMLN) + uts->release[SYS_NMLN-1] = '\0'; + memcpy(uts->version, n_uts.version, SYS_NMLN); + if (strlen(n_uts.version) > SYS_NMLN) + uts->version[SYS_NMLN-1] = '\0'; + memcpy(uts->machine, n_uts.machine, SYS_NMLN); + if (strlen(n_uts.machine) > SYS_NMLN) + uts->machine[SYS_NMLN-1] = '\0'; + } + + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/common/unmount.c b/usr/src/lib/libbc/libc/sys/common/unmount.c new file mode 100644 index 0000000000..fad0ee3717 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/unmount.c @@ -0,0 +1,34 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +unmount(s) + char *s; +{ + return umount(s); +} diff --git a/usr/src/lib/libbc/libc/sys/common/wait.c b/usr/src/lib/libbc/libc/sys/common/wait.c new file mode 100644 index 0000000000..df865cbc46 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/wait.c @@ -0,0 +1,291 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1995 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */ +/* All Rights Reserved */ + +/* + * Portions of this source code were derived from Berkeley 4.3 BSD + * under license from the Regents of the University of California. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * Compatibility lib for BSD's wait3() and wait4(). + */ + +#include <errno.h> +#include <sys/types.h> +#include <sys/time.h> +#include <sys/times.h> +#include <sys/wait.h> +#include <sys/param.h> +#include <sys/resource.h> +#include "signalmap.h" + +/* + * Since sysV does not support rusage as in BSD, an approximate approach + * is: + * ... + * call times + * call waitid + * if ( a child is found ) + * call times again + * rusage ~= diff in the 2 times call + * ... + * + */ + +extern int errno; + +/* + * arguments to wait functions from SVR4 + */ + +#define N_WEXITED 0001 /* wait for processes that have exite */ +#define N_WTRAPPED 0002 /* wait for processes stopped while tracing */ +#define N_WSTOPPED 0004 /* wait for processes stopped by signals */ +#define N_WCONTINUED 0010 /* wait for processes continued */ + +#define N_WUNTRACED N_WSTOPPED /* for POSIX */ + +#define N_WNOHANG 0100 /* non blocking form of wait */ +#define N_WNOWAIT 0200 /* non destructive form of wait */ + +#define WCOREFLG 0200 + +/* + * SIGCLD signal codes from SVr4 + */ + +#define CLD_EXITED 1 /* child has exited */ +#define CLD_KILLED 2 /* child was killed */ +#define CLD_DUMPED 3 /* child has coredumped */ +#define CLD_TRAPPED 4 /* traced child has stopped */ +#define CLD_STOPPED 5 /* child has stopped on signal */ +#define CLD_CONTINUED 6 /* stopped child has continued */ +#define NSIGCLD 6 + +/* + * id type from SVR4 procset.h + */ +typedef enum idtype { + P_PID, /* A process identifier. */ + P_PPID, /* A parent process identifier. */ + P_PGID, /* A process group (job control group) */ + /* identifier. */ + P_SID, /* A session identifier. */ + P_CID, /* A scheduling class identifier. */ + P_UID, /* A user identifier. */ + P_GID, /* A group identifier. */ + P_ALL /* All processes. */ +} idtype_t; + +static void mapstatus(int *, int); + +int +wait(int *status) +{ + int ret, nstatus; + + if ((int)status == -1) { + errno = EFAULT; + return (-1); + } + + ret = _wait(&nstatus); + if (status) + mapstatus(status, nstatus); + return (ret); +} + +int +waitpid(int pid, int *status, int options) +{ + int noptions, ret; + int nstatus; + + if ((int)status == -1) { + errno = EFAULT; + return (-1); + } + + /* + * BSD's wait* routines only support WNOHANG & WUNTRACED + */ + if (options & ~(WNOHANG|WUNTRACED)) + return (EINVAL); + noptions = (N_WEXITED|N_WTRAPPED); + if (options & WNOHANG) + noptions |= N_WNOHANG; + if (options & WUNTRACED) + noptions |= N_WUNTRACED; /* == N_WSTOPPED */ + + ret = _waitpid(pid, &nstatus, noptions); + + if (status) + mapstatus(status, nstatus); + + return (ret); +} + +/* + * It would be -so- nice just to call _wait3 and mapstatus here. + */ +int +wait3(int *status, int options, struct rusage *rp) +{ + return (wait4(0, status, options, rp)); +} + +static int wstat(int, int); + +/* + * It would be -so- nice just to call _wait4 and mapstatus here. + */ +int +wait4(int pid, int *status, int options, struct rusage *rp) +{ + struct tms before_tms; + struct tms after_tms; + siginfo_t info; + int error; + int noptions; + idtype_t idtype; + + if ((int)status == -1 || (int)rp == -1) { + errno = EFAULT; + return(-1); + } + + if (rp) + memset(rp, 0, sizeof(struct rusage)); + memset(&info, 0, sizeof (siginfo_t)); + if (times(&before_tms) < 0) + return (-1); /* errno is set by times() */ + + /* + * BSD's wait* routines only support WNOHANG & WUNTRACED + */ + if (options & ~(WNOHANG|WUNTRACED)) + return (EINVAL); + noptions = N_WEXITED | N_WTRAPPED; + if (options & WNOHANG) + noptions |= N_WNOHANG; + if (options & WUNTRACED) + noptions |= N_WUNTRACED; /* == N_WSTOPPED */ + + /* + * Emulate undocumented 4.x semantics for 1186845 + */ + if (pid < 0) { + pid = -pid; + idtype = P_PGID; + } else if (pid == 0) + idtype = P_ALL; + else + idtype = P_PID; + + error = _waitid(idtype, pid, &info, noptions); + if (error == 0) { + long diffu; /* difference in usertime (ticks) */ + long diffs; /* difference in systemtime (ticks) */ + + if ((options & WNOHANG) && (info.si_pid == 0)) + return (0); /* no child found */ + + if (rp) { + if (times(&after_tms) < 0) + return (-1); /* errno already set by times() */ + /* + * The system/user time is an approximation only !!! + */ + diffu = after_tms.tms_cutime - before_tms.tms_cutime; + diffs = after_tms.tms_cstime - before_tms.tms_cstime; + rp->ru_utime.tv_sec = diffu / HZ; + rp->ru_utime.tv_usec = (diffu % HZ) * (1000000 / HZ); + rp->ru_stime.tv_sec = diffs / HZ; + rp->ru_stime.tv_usec = (diffs % HZ) * (1000000 / HZ); + } + if (status) + *status = wstat(info.si_code, info.si_status); + return (info.si_pid); + } else { + return (-1); /* error number is set by waitid() */ + } +} + + +/* + * Convert the status code to old style wait status + */ +static int +wstat(int code, int status) +{ + register stat = (status & 0377); + + switch (code) { + case CLD_EXITED: + stat <<= 8; + break; + case CLD_KILLED: + stat = maptooldsig(stat); + if (code == CLD_DUMPED) + stat |= WCOREFLG; + break; + case CLD_DUMPED: + stat |= WCOREFLG; + break; + case CLD_TRAPPED: + case CLD_STOPPED: + stat = maptooldsig(stat); + stat <<= 8; + stat |= _WSTOPPED; + break; + } + return (stat); +} + +static void +mapstatus(int *new, int old) +{ + int stat = old & 0xFF; + + switch(stat) { + case _WSTOPPED: + *new = maptooldsig(stat >> 8); + *new = (stat << 8) | _WSTOPPED; + break; + case 0: + *new = old; + break; + default: + *new = maptooldsig(old & 0x7F); + if (old & 0x80) + *new |= 0x80; /* set WCOREFLG */ + } +} diff --git a/usr/src/lib/libbc/libc/sys/common/xsyscall.h b/usr/src/lib/libbc/libc/sys/common/xsyscall.h new file mode 100644 index 0000000000..780e4eb316 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/common/xsyscall.h @@ -0,0 +1,230 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + * + * Copyright 2000 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* from UCB 4.11 06/09/83 */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#ifndef __sys_syscall_h +#define __sys_syscall_h + +/* List of SunOS 4.1 system call numbers. All SYS_* have been + * renamed to XSYS_* to avoid confusion with the new SunOS/SVR4 + * numbers used in other routines in libbc. */ + +#define XSYS_exit 1 +#define XSYS_fork 2 +#define XSYS_read 3 +#define XSYS_write 4 +#define XSYS_open 5 +#define XSYS_close 6 +#define XSYS_wait4 7 +#define XSYS_creat 8 +#define XSYS_link 9 +#define XSYS_unlink 10 +#define XSYS_execv 11 +#define XSYS_chdir 12 + /* 13 is old: time */ +#define XSYS_mknod 14 +#define XSYS_chmod 15 +#define XSYS_chown 16 + /* 17 is old: sbreak */ + /* 18 is old: stat */ +#define XSYS_lseek 19 +#define XSYS_getpid 20 + /* 21 is old: mount */ + /* 22 is old: umount */ + /* 23 is old: setuid */ +#define XSYS_getuid 24 + /* 25 is old: stime */ +#define XSYS_ptrace 26 + /* 27 is old: alarm */ + /* 28 is old: fstat */ + /* 29 is old: pause */ + /* 30 is old: utime */ + /* 31 is old: stty */ + /* 32 is old: gtty */ +#define XSYS_access 33 + /* 34 is old: nice */ + /* 35 is old: ftime */ +#define XSYS_sync 36 +#define XSYS_kill 37 +#define XSYS_stat 38 + /* 39 is old: setpgrp */ +#define XSYS_lstat 40 +#define XSYS_dup 41 +#define XSYS_pipe 42 + /* 43 is old: times */ +#define XSYS_profil 44 + /* 45 is unused */ + /* 46 is old: setgid */ +#define XSYS_getgid 47 + /* 48 is old: sigsys */ + /* 49 is unused */ + /* 50 is unused */ +#define XSYS_acct 51 + /* 52 is old: phys */ +#define XSYS_mctl 53 +#define XSYS_ioctl 54 +#define XSYS_reboot 55 + /* 56 is old: mpxchan */ +#define XSYS_symlink 57 +#define XSYS_readlink 58 +#define XSYS_execve 59 +#define XSYS_umask 60 +#define XSYS_chroot 61 +#define XSYS_fstat 62 + /* 63 is unused */ +#define XSYS_getpagesize 64 +#define XSYS_msync 65 + /* 66 is old: vfork */ + /* 67 is old: vread */ + /* 68 is old: vwrite */ +#define XSYS_sbrk 69 +#define XSYS_sstk 70 +#define XSYS_mmap 71 +#define XSYS_vadvise 72 +#define XSYS_munmap 73 +#define XSYS_mprotect 74 +#define XSYS_madvise 75 +#define XSYS_vhangup 76 + /* 77 is old: vlimit */ +#define XSYS_mincore 78 +#define XSYS_getgroups 79 +#define XSYS_setgroups 80 +#define XSYS_getpgrp 81 +#define XSYS_setpgrp 82 +#define XSYS_setitimer 83 + /* 84 is old: wait & wait3 */ +#define XSYS_swapon 85 +#define XSYS_getitimer 86 +#define XSYS_gethostname 87 +#define XSYS_sethostname 88 +#define XSYS_getdtablesize 89 +#define XSYS_dup2 90 +#define XSYS_getdopt 91 +#define XSYS_fcntl 92 +#define XSYS_select 93 +#define XSYS_setdopt 94 +#define XSYS_fsync 95 +#define XSYS_setpriority 96 +#define XSYS_socket 97 +#define XSYS_connect 98 +#define XSYS_accept 99 +#define XSYS_getpriority 100 +#define XSYS_send 101 +#define XSYS_recv 102 + /* 103 was socketaddr */ +#define XSYS_bind 104 +#define XSYS_setsockopt 105 +#define XSYS_listen 106 + /* 107 was vtimes */ +#define XSYS_sigvec 108 +#define XSYS_sigblock 109 +#define XSYS_sigsetmask 110 +#define XSYS_sigpause 111 +#define XSYS_sigstack 112 +#define XSYS_recvmsg 113 +#define XSYS_sendmsg 114 +#define XSYS_vtrace 115 +#define XSYS_gettimeofday 116 +#define XSYS_getrusage 117 +#define XSYS_getsockopt 118 + /* 119 is old resuba */ +#define XSYS_readv 120 +#define XSYS_writev 121 +#define XSYS_settimeofday 122 +#define XSYS_fchown 123 +#define XSYS_fchmod 124 +#define XSYS_recvfrom 125 +#define XSYS_setreuid 126 +#define XSYS_setregid 127 +#define XSYS_rename 128 +#define XSYS_truncate 129 +#define XSYS_ftruncate 130 +#define XSYS_flock 131 + /* 132 is unused */ +#define XSYS_sendto 133 +#define XSYS_shutdown 134 +#define XSYS_socketpair 135 +#define XSYS_mkdir 136 +#define XSYS_rmdir 137 +#define XSYS_utimes 138 + /* 139 is unused */ +#define XSYS_adjtime 140 +#define XSYS_getpeername 141 +#define XSYS_gethostid 142 + /* 143 is old: sethostid */ +#define XSYS_getrlimit 144 +#define XSYS_setrlimit 145 +#define XSYS_killpg 146 + /* 147 is unused */ + /* 148 is old: setquota */ + /* 149 is old: quota */ +#define XSYS_getsockname 150 +#define XSYS_getmsg 151 +#define XSYS_putmsg 152 +#define XSYS_poll 153 + /* 154 is old: nfs_mount */ +#define XSYS_nfssvc 155 +#define XSYS_getdirentries 156 +#define XSYS_statfs 157 +#define XSYS_fstatfs 158 +#define XSYS_unmount 159 +#define XSYS_async_daemon 160 +#define XSYS_getfh 161 +#define XSYS_getdomainname 162 +#define XSYS_setdomainname 163 + /* 164 is old: pcfs_mount */ +#define XSYS_quotactl 165 +#define XSYS_exportfs 166 +#define XSYS_mount 167 +#define XSYS_ustat 168 +#define XSYS_semsys 169 +#define XSYS_msgsys 170 +#define XSYS_shmsys 171 +#define XSYS_auditsys 172 + /* 173 is old: rfsys */ +#define XSYS_getdents 174 +#define XSYS_setsid 175 +#define XSYS_fchdir 176 +#define XSYS_fchroot 177 +#define XSYS_vpixsys 178 + +#define XSYS_aioread 179 +#define XSYS_aiowrite 180 +#define XSYS_aiowait 181 +#define XSYS_aiocancel 182 + +#define XSYS_sigpending 183 + /* 184 is available */ +#define XSYS_setpgid 185 +#define XSYS_pathconf 186 +#define XSYS_fpathconf 187 +#define XSYS_sysconf 188 + +#define XSYS_uname 189 + +#endif /* !__sys_syscall_h */ diff --git a/usr/src/lib/libbc/libc/sys/sys5/access.c b/usr/src/lib/libbc/libc/sys/sys5/access.c new file mode 100644 index 0000000000..54fcbf170c --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/access.c @@ -0,0 +1,39 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <unistd.h> +#include <sys/param.h> + +int access(path, mode) +char *path; +int mode; +{ + return(access_com(path, mode)); +} + diff --git a/usr/src/lib/libbc/libc/sys/sys5/chdir.c b/usr/src/lib/libbc/libc/sys/sys5/chdir.c new file mode 100644 index 0000000000..8de4004424 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/chdir.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +chdir(s) + char *s; +{ + return _syscall(SYS_chdir, s); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/chmod.c b/usr/src/lib/libbc/libc/sys/sys5/chmod.c new file mode 100644 index 0000000000..06d184581a --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/chmod.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +chmod(s, m) + char *s; +{ + return _syscall(SYS_chmod, s, m); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/chown.c b/usr/src/lib/libbc/libc/sys/sys5/chown.c new file mode 100644 index 0000000000..696112e3ff --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/chown.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +chown(s, u, g) + char *s; +{ + return _syscall(SYS_lchown, s, u, g); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/chroot.c b/usr/src/lib/libbc/libc/sys/sys5/chroot.c new file mode 100644 index 0000000000..419393b170 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/chroot.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +chroot(d) + char *d; +{ + return _syscall(SYS_chroot, d); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/creat.c b/usr/src/lib/libbc/libc/sys/sys5/creat.c new file mode 100644 index 0000000000..06e3de38ac --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/creat.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int creat(path, mode) +char *path; +int mode; +{ + + return(creat_com(path, mode)); +} + diff --git a/usr/src/lib/libbc/libc/sys/sys5/execve.c b/usr/src/lib/libbc/libc/sys/sys5/execve.c new file mode 100644 index 0000000000..bf86229015 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/execve.c @@ -0,0 +1,68 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <string.h> +#include <sys/file.h> +#include <sys/syscall.h> + +execve(file, argv, arge) +char *file; +char **argv, **arge; +{ + char *c; + char path[256]; + + if (strncmp(file, "/usr/bin", strlen("/usr/bin")) == 0 || + strncmp(file, "/bin", strlen("/bin")) == 0) { + if (_syscall(SYS_access, file, F_OK) == -1) { + strcpy(path, "/usr/ucb"); + strcat(path, strrchr(file, '/')); + file = path; + } + } + else if (strncmp(file, "/usr/ucb", strlen("/usr/ucb")) == 0) { + strcpy(path, "/usr/bin"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + } + else if (strncmp(file, "/usr/5bin", strlen("/usr/5bin")) == 0) { + strcpy(path, "/usr/bin"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + else { + strcpy(path, "/usr/ucb"); + strcat(path, strrchr(file, '/')); + if (_syscall(SYS_access, path, F_OK) == 0) + file = path; + } + } + + return(_syscall(SYS_execve, file, argv, arge)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/fcntl.c b/usr/src/lib/libbc/libc/sys/sys5/fcntl.c new file mode 100644 index 0000000000..3d8342ba4c --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/fcntl.c @@ -0,0 +1,181 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1990-1996 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> +#include <sys/fcntl.h> +#include <sys/errno.h> +#include <sys/filio.h> +#include <sys/ioccom.h> +#include <unistd.h> + +/* The following is an array of fcntl commands. The numbers listed + * below are from SVR4. Array is indexed with SunOS 4.1 numbers to + * obtain the SVR4 numbers. + */ +int cmd_op[14] = {0, 1, 2, 3, 4, 23, 24, 14, 6, 7, 21, 20, -1, 22}; + +/* SVR4/SunOS 5.0 equivalent modes */ +#define N_O_NDELAY 0x04 +#define N_O_SYNC 0x10 +#define N_O_NONBLOCK 0x80 +#define N_O_CREAT 0x100 +#define N_O_TRUNC 0x200 +#define N_O_EXCL 0x400 + +#define S5_FASYNC 0x1000 + +/* from SVR4 stropts.h */ +#define S5_S_RDNORM 0x0040 +#define S5_S_WRNORM 0x0004 +#define S5_S_RDBAND 0x0080 +#define S5_S_BANDURG 0x0200 +#define S5_I_SETSIG (('S'<<8)|011) +#define S5_I_GETSIG (('S'<<8)|012) + +/* Mask corresponding to the bits above in SunOS 4.x */ +#define FLAGS_MASK (O_SYNC|O_NONBLOCK|O_CREAT|O_TRUNC|O_EXCL \ + |O_NDELAY|FASYNC) +#define N_FLAGS_MASK (N_O_NDELAY|N_O_SYNC|N_O_NONBLOCK|N_O_CREAT \ + |N_O_TRUNC|N_O_EXCL|S5_FASYNC) + +struct n_flock { + short l_type; + short l_whence; + long l_start; + long l_len; /* len == 0 means until end of file */ + long l_sysid; + long l_pid; + long pad[4]; /* reserve area */ +} ; + +int fcntl(fd, cmd, arg) +int fd, cmd, arg; +{ + return(bc_fcntl(fd, cmd, arg)); +} + +int bc_fcntl(fd, cmd, arg) +int fd, cmd, arg; +{ + int fds, ret; + struct flock *savarg; + struct n_flock nfl; + extern int errno; + int narg, i; + + if ((cmd == F_SETOWN) || (cmd == F_GETOWN)) { + ret = _s_fcntl(fd, cmd_op[cmd], arg); + if ((ret != -1) || (errno != EINVAL)) + return (ret); + else { + if (cmd == F_GETOWN) { + if (_ioctl(fd, S5_I_GETSIG, &i) < 0) { + if (errno == EINVAL) + i = 0; + else + return (-1); + } + if (i & (S5_S_RDBAND|S5_S_BANDURG| + S5_S_RDNORM|S5_S_WRNORM)) + return (getpid()); + return (0); + } else { /* cmd == F_SETOWN */ + i = S5_S_RDNORM|S5_S_WRNORM|S5_S_RDBAND|S5_S_BANDURG; + return (ioctl(fd, S5_I_SETSIG, i)); + } + } + } + if (cmd == F_SETFL) { + if (arg & FLAGS_MASK) { + narg = arg & ~FLAGS_MASK; + if (arg & FASYNC) + narg |= S5_FASYNC; + if (arg & O_SYNC) + narg |= N_O_SYNC; + if (arg & O_CREAT) + narg |= N_O_CREAT; + if (arg & O_TRUNC) + narg |= N_O_TRUNC; + if (arg & O_EXCL) + narg |= N_O_EXCL; + if (arg & (O_NDELAY)) + narg |= N_O_NDELAY; + if (arg & O_NONBLOCK) + narg |= N_O_NONBLOCK; + arg = narg; + } + } else if (cmd == F_SETLK || cmd == F_SETLKW || cmd == F_GETLK) { + if (arg == 0 || arg == -1) { + errno = EFAULT; + return(-1); + } + savarg = (struct flock *)arg; + arg = (int) &nfl; + nfl.l_type = savarg->l_type; + nfl.l_whence = savarg->l_whence; + nfl.l_start = savarg->l_start; + nfl.l_len = savarg->l_len; + nfl.l_pid = savarg->l_pid; + } + + ret = _s_fcntl(fd, cmd_op[cmd], arg); + + if (ret != -1) { + if (cmd == F_DUPFD) { + if ((fds = fd_get(fd)) != -1) + fd_add(ret, fds); + } else if (cmd == F_GETFL) { + if (ret & N_FLAGS_MASK) { + narg = ret & ~N_FLAGS_MASK; + if (ret & S5_FASYNC) + narg |= FASYNC; + if (ret & N_O_SYNC) + narg |= O_SYNC; + if (ret & N_O_NONBLOCK) + narg |= O_NONBLOCK; + if (ret & N_O_CREAT) + narg |= O_CREAT; + if (ret & N_O_TRUNC) + narg |= O_TRUNC; + if (ret & N_O_EXCL) + narg |= O_EXCL; + if (ret & (N_O_NDELAY)) + narg |= O_NDELAY; + ret = narg; + } + } else if (cmd == F_SETLK || cmd == F_SETLKW || + cmd == F_GETLK) { + savarg->l_type = nfl.l_type; + savarg->l_whence = nfl.l_whence; + savarg->l_start = nfl.l_start; + savarg->l_len = nfl.l_len; + savarg->l_pid = nfl.l_pid; + } + } + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/getgroups.c b/usr/src/lib/libbc/libc/sys/sys5/getgroups.c new file mode 100644 index 0000000000..d4c64d4b2c --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/getgroups.c @@ -0,0 +1,52 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * POSIX.1 compatible getgroups() routine + * This is needed while gid_t is not the same size as int (or whatever the + * syscall is using at the time). + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/param.h> +#include <sys/syscall.h> + +getgroups(gidsetsize, grouplist) +int gidsetsize; +gid_t grouplist[]; +{ + int glist[NGROUPS]; /* getgroups() syscall returns ints */ + register int i; /* loop control */ + register int rc; /* return code hold area */ + + rc = _syscall(SYS_getgroups, gidsetsize, glist); + if (rc > 0 && gidsetsize != 0) + for (i = 0; i < rc; i++) + grouplist[i] = (gid_t)glist[i]; + return (rc); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/getpgrp.c b/usr/src/lib/libbc/libc/sys/sys5/getpgrp.c new file mode 100644 index 0000000000..b1d6508297 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/getpgrp.c @@ -0,0 +1,41 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + getpgrp -- system call emulation for 4.2BSD + + last edit: 01-Jul-1983 D A Gwyn +*/ + +extern int _getpgrp(); + +int +getpgrp() + { + return _getpgrp( 0 ); /* 0 means this process */ + } diff --git a/usr/src/lib/libbc/libc/sys/sys5/link.c b/usr/src/lib/libbc/libc/sys/sys5/link.c new file mode 100644 index 0000000000..11cad8f463 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/link.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +link(a, b) + char *a; + char *b; +{ + return _syscall(SYS_link, a, b); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/mkdir.c b/usr/src/lib/libbc/libc/sys/sys5/mkdir.c new file mode 100644 index 0000000000..71c6275fba --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/mkdir.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +mkdir(p, m) + char *p; +{ + return _syscall(SYS_mkdir, p, m); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/mkfifo.c b/usr/src/lib/libbc/libc/sys/sys5/mkfifo.c new file mode 100644 index 0000000000..7745f0ba91 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/mkfifo.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/stat.h> + +mkfifo(path, mode) + char *path; + mode_t mode; +{ + return mknod(path, S_IFIFO | (mode & (S_IRWXU|S_IRWXG|S_IRWXO))); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/mknod.c b/usr/src/lib/libbc/libc/sys/sys5/mknod.c new file mode 100644 index 0000000000..1fef5217eb --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/mknod.c @@ -0,0 +1,55 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * If we're asked to make a directory, do a "mkdir" instead, so we meet + * the letter of the SVID (yuk!). + */ + +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> + +extern int _mknod(); +extern int mkdir(); + +int +mknod(path, mode, dev) + char *path; + int mode; + int dev; +{ + if ((mode & S_IFMT) == S_IFDIR) + if (geteuid()) { + errno = EPERM; + return(-1); + } else + return (mkdir(path, mode & 07777)); + else + return (_mknod(path, mode, dev)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/mount.c b/usr/src/lib/libbc/libc/sys/sys5/mount.c new file mode 100644 index 0000000000..4a4fd64645 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/mount.c @@ -0,0 +1,42 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995 Sun Microsystems, Inc. All rights reserved. + */ + +#ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> + +int +mount(spec, dir, rdonly) +char *spec; +char *dir; +int rdonly; +{ + int ret; + + if ((ret = _mount(spec, dir, rdonly)) != 0) { + maperror(errno); + } + return (ret); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/open.c b/usr/src/lib/libbc/libc/sys/sys5/open.c new file mode 100644 index 0000000000..e6a0a529a9 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/open.c @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" +#include <sys/errno.h> + +extern int errno; + +open(path, flags, mode) + char *path; + int flags; + int mode; +{ + return (bc_open(path, flags, mode)); +} + + + +bc_open(path, flags, mode) + char *path; + int flags; + int mode; +{ + if ((path == (char*)0) || (path == (char*) -1)) { + errno = EFAULT; + return (-1); + } + return (open_com(path, flags, mode)); +} + diff --git a/usr/src/lib/libbc/libc/sys/sys5/pathconf.c b/usr/src/lib/libbc/libc/sys/sys5/pathconf.c new file mode 100644 index 0000000000..94477894f3 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/pathconf.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +pathconf(p, what) + char* p; +{ + return _syscall(SYS_pathconf, p, what); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/read.c b/usr/src/lib/libbc/libc/sys/sys5/read.c new file mode 100644 index 0000000000..35262a4f34 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/read.c @@ -0,0 +1,96 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <syscall.h> + +/* + * If reading from the utmp file, map the data to the SunOS 4.1 + * format on the fly. + */ + +extern void to_utmp(char *, char *, int); + +int +read(int fd, char *buf, int size) +{ + return (bc_read(fd, buf, size)); +} + +int +bc_read(int fd, char *buf, int size) +{ + int ret, off; + char *nbuf; + + if (fd_get(fd) != -1) { /* we're reading utmp (utmpx, really) */ + size = getmodsize(size, sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(size)) == NULL) { + (void) fprintf(stderr, "read: malloc failed\n"); + exit(-1); + } + + if ((ret = _read(fd, nbuf, size)) == -1) { + free(nbuf); + return (-1); + } + + to_utmp(buf, nbuf, ret); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + free(nbuf); + return (ret); + } + + return (_read(fd, buf, size)); +} + +void +to_utmp(char *buf, char *nbuf, int len) +{ + struct compat_utmp *ut; + struct utmpx *utx; + + utx = (struct utmpx *) nbuf; + ut = (struct compat_utmp *) buf; + + while ((char *)utx < (nbuf + len)) { + (void) strncpy(ut->ut_line, utx->ut_line, sizeof (ut->ut_line)); + (void) strncpy(ut->ut_name, utx->ut_user, sizeof (ut->ut_name)); + (void) strncpy(ut->ut_host, utx->ut_host, sizeof (ut->ut_host)); + ut->ut_time = utx->ut_tv.tv_sec; + utx++; + ut++; + } +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/readlink.c b/usr/src/lib/libbc/libc/sys/sys5/readlink.c new file mode 100644 index 0000000000..3182902f03 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/readlink.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +readlink(p, b, s) + char *p, *b; +{ + return _syscall(SYS_readlink, p, b, s); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/readv.c b/usr/src/lib/libbc/libc/sys/sys5/readv.c new file mode 100644 index 0000000000..eb203eb067 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/readv.c @@ -0,0 +1,84 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <syscall.h> +#include <sys/uio.h> + +/* + * If reading from the utmp file, map the data to the SunOS 4.1 + * format on the fly. + */ +extern void to_utmp(char *, char *, int); + +int +readv(int fd, struct iovec *iov, int iovcnt) +{ + return (bc_readv(fd, iov, iovcnt)); +} + +int +bc_readv(int fd, struct iovec *iov, int iovcnt) +{ + int ret, off; + int i, size, total = 0; + char *nbuf; + + if (fd_get(fd) != -1) { + for (i = 0; i < iovcnt; i++) { + size = getmodsize(iov[i].iov_len, + sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(size)) == NULL) { + fprintf(stderr, "readv: malloc failed\n"); + exit(-1); + } + + if ((ret = _read(fd, nbuf, size)) == -1) { + free(nbuf); + return (-1); + } + + total += ret; + + to_utmp(iov[i].iov_base, nbuf, ret); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + + free(nbuf); + } + return (total); + } + + return (_readv(fd, iov, iovcnt)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/rename.c b/usr/src/lib/libbc/libc/sys/sys5/rename.c new file mode 100644 index 0000000000..b1d99b5fbb --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/rename.c @@ -0,0 +1,53 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> + +int rename(path1, path2) +char *path1, *path2; +{ + int ret; + char buf1[256]; + char buf2[256]; + + if (strcmp(path1, "/var/adm/utmp") == 0 || + strcmp(path1, "/var/adm/wtmp") == 0 || + strcmp(path1, "/etc/utmp") == 0) { + if (strcmp(path1, "/etc/utmp") == 0 || + strcmp(path1, "/var/adm/utmp") == 0) + strcpy(path1, "/var/adm/utmpx"); + else + strcpy(path1, "/var/adm/wtmpx"); + strcpy(buf2, path2); + strcat(buf2, "x"); + ret = _syscall(SYS_rename, buf1, buf2); + } else + ret = _syscall(SYS_rename, path1, path2); + + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/rmdir.c b/usr/src/lib/libbc/libc/sys/sys5/rmdir.c new file mode 100644 index 0000000000..2f859bcfd1 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/rmdir.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +rmdir(d) + char *d; +{ + int ret; + extern errno; + + return(_syscall(SYS_rmdir, d)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/setgid.c b/usr/src/lib/libbc/libc/sys/sys5/setgid.c new file mode 100644 index 0000000000..fc3cf277ed --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/setgid.c @@ -0,0 +1,38 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> + +int +setgid(int gid) +{ + if (geteuid() == 0) + return (setregid(gid, gid)); + else + return (setregid(-1, gid)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/setgroups.c b/usr/src/lib/libbc/libc/sys/sys5/setgroups.c new file mode 100644 index 0000000000..a9f3cb210e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/setgroups.c @@ -0,0 +1,54 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +/* + * POSIX.1 compatible setgroups() routine + * This is needed while gid_t is not the same size as int (or whatever the + * syscall is using at the time). + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <errno.h> +#include <sys/types.h> +#include <sys/param.h> +#include <sys/syscall.h> + +setgroups(ngroups, grouplist) +int ngroups; +gid_t grouplist[]; +{ + int glist[NGROUPS]; /* setgroups() syscall expects ints */ + register int i; /* loop control */ + + if (ngroups > NGROUPS) { + errno = EINVAL; + return (-1); + } + for (i = 0; i < ngroups; i++) + glist[i] = (int)grouplist[i]; + return (_syscall(SYS_setgroups, ngroups, glist)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/setjmp.c b/usr/src/lib/libbc/libc/sys/sys5/setjmp.c new file mode 100644 index 0000000000..3227218946 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/setjmp.c @@ -0,0 +1,91 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* Copyright (c) 1988 AT&T */ +/* All Rights Reserved */ + + +/* + * Copyright 2004 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + + +#include <sys/setjmp.h> +#include "../common/ucontext.h" + +int _getsp(); + +int +setjmp(env) + jmp_buf env; +{ + register o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + register int sp = _getsp(); + ucontext_t uc; + + /* + * Get the current machine context. + */ + uc.uc_flags = UC_STACK; + __getcontext(&uc); + + /* + * Note that the pc and former sp (fp) from the stack are valid + * because the call to __getcontext must flush the user windows + * to the stack. + */ + bp->sjs_flags = 0; + bp->sjs_sp = *((int *)sp+14); + bp->sjs_pc = *((int *)sp+15) + 0x8; + bp->sjs_sigmask[0] = 0; + bp->sjs_sigmask[1] = 0; + bp->sjs_sigmask[2] = 0; + bp->sjs_stack = uc.uc_stack; + + return (0); +} + + +void +longjmp(env, val) + jmp_buf env; + int val; +{ + o_setjmp_struct_t *bp = (o_setjmp_struct_t *)env; + setjmp_struct_t sjmp, *sp; + + sp = &sjmp; + sp->sjs_flags = bp->sjs_flags; + sp->sjs_sp = bp->sjs_sp; + sp->sjs_pc = bp->sjs_pc; + sp->sjs_fp = 0; + sp->sjs_i7 = 0; + sp->sjs_uclink = 0; + sp->sjs_sigmask[0] = bp->sjs_sigmask[0]; + sp->sjs_sigmask[1] = bp->sjs_sigmask[1]; + sp->sjs_sigmask[2] = bp->sjs_sigmask[2]; + sp->sjs_sigmask[3] = 0; + sp->sjs_stack = bp->sjs_stack; + _siglongjmp(sjmp, val); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/setpgrp.c b/usr/src/lib/libbc/libc/sys/sys5/setpgrp.c new file mode 100644 index 0000000000..d1f75e5097 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/setpgrp.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +extern int setsid(); + +int +setpgrp() +{ + + return (setsid()); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/setuid.c b/usr/src/lib/libbc/libc/sys/sys5/setuid.c new file mode 100644 index 0000000000..c5cfacff9e --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/setuid.c @@ -0,0 +1,36 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1995, by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +int +setuid(int uid) +{ + if (geteuid() == 0) + return (setreuid(uid, uid)); + else + return (setreuid(-1, uid)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/stat.c b/usr/src/lib/libbc/libc/sys/sys5/stat.c new file mode 100644 index 0000000000..ebd07f1cd6 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/stat.c @@ -0,0 +1,72 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <sys/errno.h> + +extern int errno; + +int stat(path, buf) +char *path; +struct stat *buf; +{ + return(bc_stat(path, buf)); +} + +int bc_stat(path, buf) +char *path; +struct stat *buf; +{ + if (path == (char*)0) { + errno = EFAULT; + return (-1); + } + if ((buf == (struct stat*)0) || (buf == (struct stat*)-1)) { + errno = EFAULT; + return (-1); + } + return(stat_com(SYS_stat, path, buf)); +} + + +int lstat(path, buf) +char *path; +struct stat *buf; +{ + return(bc_lstat(path, buf)); +} + +int bc_lstat(path, buf) +char *path; +struct stat *buf; +{ + return(stat_com(SYS_lstat, path, buf)); +} + diff --git a/usr/src/lib/libbc/libc/sys/sys5/statfs.c b/usr/src/lib/libbc/libc/sys/sys5/statfs.c new file mode 100644 index 0000000000..7b597f49c4 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/statfs.c @@ -0,0 +1,37 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/types.h> +#include <sys/vfs.h> + +statfs(s, b) + char *s; + struct statfs *b; +{ + return(statfs_com(s, b)); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/symlink.c b/usr/src/lib/libbc/libc/sys/sys5/symlink.c new file mode 100644 index 0000000000..0d1768f546 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/symlink.c @@ -0,0 +1,35 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <sys/syscall.h> + +symlink(t, f) + char *t, *f; +{ + return _syscall(SYS_symlink, t, f); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/truncate.c b/usr/src/lib/libbc/libc/sys/sys5/truncate.c new file mode 100644 index 0000000000..20d4e123e0 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/truncate.c @@ -0,0 +1,57 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> +#include <unistd.h> +#include <errno.h> +#include <sys/fcntl.h> +#include <sys/param.h> + +extern int errno; + +int truncate(path, length) +char *path; +off_t length; +{ + int fd, ret=0; + + if (strcmp(path, "/etc/mtab") == 0 || strcmp(path, "/etc/fstab") == 0) { + errno = ENOENT; + return(-1); + } + if ((fd = open(path, O_WRONLY)) == -1) { + return(-1); + } + + if (ftruncate(fd, length) == -1) { + close(fd); + return(-1); + } + close(fd); + return(0); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/unlink.c b/usr/src/lib/libbc/libc/sys/sys5/unlink.c new file mode 100644 index 0000000000..db378d4ccc --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/unlink.c @@ -0,0 +1,50 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <syscall.h> + +int unlink(path) +char *path; +{ + int ret; + char buf[256]; + + if (strcmp(path, "/var/adm/utmp") == 0 || + strcmp(path, "/var/adm/wtmp") == 0 || + strcmp(path, "/etc/utmp") == 0) { + if (strcmp(path, "/etc/utmp") == 0 || + strcmp(path, "/var/adm/utmp") == 0) + strcpy(buf, "/var/adm/utmpx"); + else + strcpy(buf, "/var/adm/wtmpx"); + ret = _syscall(SYS_unlink, buf); + } else + ret = _syscall(SYS_unlink, path); + + return(ret); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/write.c b/usr/src/lib/libbc/libc/sys/sys5/write.c new file mode 100644 index 0000000000..d385a23077 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/write.c @@ -0,0 +1,115 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> + +/* + * If writing to a utmp-like file, map the utmp structure to + * new format on the fly. + */ +extern int conv2utmpx(char *, char *, int); + +int +write(int fd, char *buf, int size) +{ + return (bc_write(fd, buf, size)); +} + +int +bc_write(int fd, char *buf, int size) +{ + int ret, off; + int nsize; + char *nbuf; + + if (fd_get(fd) != -1) { + nsize = getmodsize(size, sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(nsize)) == NULL) { + (void) fprintf(stderr, "write: malloc failed\n"); + exit(-1); + } + + (void) memset(nbuf, 0, nsize); + + ret = conv2utmpx(nbuf, buf, size); + + if ((ret = _write(fd, nbuf, ret)) == -1) { + free(nbuf); + return (-1); + } + + free(nbuf); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + return (ret); + } + + return (_write(fd, buf, size)); +} + +/* From SunOS/SVR4 utmp.h */ +#define USER_PROCESS 7 +#define DEAD_PROCESS 8 + +extern int +conv2utmpx(char *nbuf, char *buf, int len) +{ + struct compat_utmp *ut; + struct utmpx *utx; + + utx = (struct utmpx *) nbuf; + ut = (struct compat_utmp *) buf; + + while ((char *)ut < (buf + len)) { + (void) strcpy(utx->ut_user, ut->ut_name); + (void) memset(utx->ut_id, 0, sizeof (utx->ut_id)); + (void) strcpy(utx->ut_line, ut->ut_line); + utx->ut_pid = 0; + if ((strcmp(utx->ut_user, "") == 0) && + (strcmp(utx->ut_host, "") == 0)) + utx->ut_type = DEAD_PROCESS; + else + utx->ut_type = USER_PROCESS; + utx->ut_exit.e_termination = 0; + utx->ut_exit.e_exit = 0; + utx->ut_tv.tv_sec = ut->ut_time; + utx->ut_tv.tv_usec = 0; + utx->ut_session = 0; + utx->ut_syslen = sizeof (ut->ut_name) + 1; + (void) strcpy(utx->ut_host, ut->ut_host); + ut++; + utx++; + } + return ((char *) utx - nbuf); +} diff --git a/usr/src/lib/libbc/libc/sys/sys5/writev.c b/usr/src/lib/libbc/libc/sys/sys5/writev.c new file mode 100644 index 0000000000..fe9371ce58 --- /dev/null +++ b/usr/src/lib/libbc/libc/sys/sys5/writev.c @@ -0,0 +1,89 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 1999 by Sun Microsystems, Inc. + * All rights reserved. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include "../common/compat.h" +#include <stdio.h> +#include <sys/types.h> +#include <unistd.h> +#include <sys/uio.h> + +/* + * If writing to a utmp-like file, map the utmp structure to + * new format on the fly. + */ +extern int conv2utmpx(char *, char *, int); + +int +writev(int fd, struct iovec *iov, int iovcnt) +{ + return (bc_writev(fd, iov, iovcnt)); +} + +int +bc_writev(int fd, struct iovec *iov, int iovcnt) +{ + int ret, off; + int nsize, total = 0; + char *nbuf; + int i; + + if (fd_get(fd) != -1) { + for (i = 0; i < iovcnt; i++) { + nsize = getmodsize(iov[i].iov_len, + sizeof (struct compat_utmp), + sizeof (struct utmpx)); + + if ((nbuf = (void *)malloc(nsize)) == NULL) { + fprintf(stderr, "writev: malloc failed\n"); + exit(-1); + } + + (void) memset(nbuf, 0, nsize); + + ret = conv2utmpx(nbuf, iov[i].iov_base, iov[i].iov_len); + + if ((ret = _write(fd, nbuf, ret)) == -1) { + free(nbuf); + return (-1); + } + + total += ret; + + free(nbuf); + + ret = getmodsize(ret, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + } + total = getmodsize(total, sizeof (struct utmpx), + sizeof (struct compat_utmp)); + return (total); + + } + + return (_writev(fd, iov, iovcnt)); +} diff --git a/usr/src/lib/libbc/libc/yp/yp_bind.c b/usr/src/lib/libbc/libc/yp/yp_bind.c new file mode 100644 index 0000000000..904b153ab4 --- /dev/null +++ b/usr/src/lib/libbc/libc/yp/yp_bind.c @@ -0,0 +1,249 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1992 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <errno.h> +#include <sys/time.h> +#include <rpc/rpc.h> +#include <rpc/pmap_prot.h> +#include <sys/socket.h> +#include <sys/file.h> +#include <sys/syslog.h> + +#include "yp_prot.h" +#include "ypv1_prot.h" +#include "ypclnt.h" + +/* + * This is the same as struct dom_binding used by the base __yp_dobind(). + * Named differently here to avoid name conflict with the compat + * struct dom_binding. + */ + +/* Copied from base <sys/netconfig.h> */ + +struct netconfig { + char *nc_netid; /* network identifier */ + unsigned long nc_semantics; /* defined below */ + unsigned long nc_flag; /* defined below */ + char *nc_protofmly; /* protocol family name */ + char *nc_proto; /* protocol name */ + char *nc_device; /* device name for network id */ + unsigned long nc_nlookups; /* # of entries in nc_lookups */ + char **nc_lookups; /* list of lookup directories */ + unsigned long nc_unused[8]; +}; + +/* Copied from base <sys/tiuser.h> */ + +struct netbuf { + unsigned int maxlen; + unsigned int len; + char *buf; +}; + +struct s5_dom_binding { + struct s5_dom_binding *dom_next; + char *dom_domain; + struct s5_ypbind_binding *dom_binding; + CLIENT *dom_client; +}; + +struct s5_ypbind_binding { + struct netconfig *ypbind_conf; + struct netbuf *ypbind_svcaddr; + char *ypbind_servername; + long ypbind_hi_vers; + long ypbind_lo_vers; +}; + +static void _yp_unbind(); +static struct dom_binding *load_dom_binding_cache(); + +static struct dom_binding *bound_domains; /* List of bound domains */ + +/* + * This is a "wrapper" function that is implemented by the yp_bind() + * function in base libnsl/yp. + */ +#ifdef NOTDEFINED +int +yp_bind(domain) + char *domain; +{ + /* XXX */ + _yp_bind(domain); +} +#endif + +/* + * Attempts to find a dom_binding in the list at bound_domains having the + * domain name field equal to the passed domain name, and removes it if found. + * The domain-server binding will not exist after the call to this function. + * All resources associated with the binding will be freed. + */ +#ifdef NOTDEFINED +void +yp_unbind (domain) + char *domain; +{ + _yp_unbind(domain); /* clean our local cache */ + /* XXX */ + _yp_unbind(domain); +} +#endif + +/* + * This is a wrapper around the yp_get_default_domain() + * function in base libnsl/yp. + */ +#ifdef NOTDEFINED +int +yp_get_default_domain(domain) + char **domain; +{ + /* XXX */ + _yp_get_default_domain(domain); +} +#endif + +/* + * Attempts to locate a NIS server that serves a passed domain. + * This is a wrapper around the __yp_dobind() function in base + * libnsl/yp; it converts the libnsl [netbuf based] dom_binding structure into + * the [sockaddr based] one that is expected by binary compat apps. Note that, + * the wrapper must allocate memory resources in order to hold + * the + */ +int +_yp_dobind(domain, binding) + char *domain; + struct dom_binding **binding; /* if result == 0, ptr to dom_binding */ +{ + int retval; + struct s5_dom_binding *dom_binding; /* Ptr to dom_binding from libnsl __yp_dobind() */ + int status; + + /* XXX */ + retval = __yp_dobind(domain, &dom_binding); + if (retval != 0) + return(retval); + + if ((*binding = load_dom_binding_cache(domain, dom_binding)) == NULL) + return (YPERR_RESRC); /* make sure it is in our cache */ + return (0); /* This is the go path */ +} + + +/* + * This allocates some memory for a domain binding, initialize it, and + * returns a pointer to it. Based on the program version we ended up + * talking to ypbind with, fill out an opvector of appropriate protocol + * modules. + */ +static struct dom_binding * +load_dom_binding_cache(domain, dom_binding) + char *domain; + struct s5_dom_binding *dom_binding; +{ + struct dom_binding *pdomb = NULL; + struct sockaddr_in *sa; /* To get a port bound to socket */ + struct sockaddr_in local_name; + int local_name_len = sizeof(struct sockaddr_in); + + + for (pdomb = bound_domains; pdomb != NULL; pdomb = pdomb->dom_pnext) { + if (strcmp(domain, pdomb->dom_domain) == 0) + return (pdomb); + } + + if ((pdomb = (struct dom_binding *) malloc(sizeof(struct dom_binding))) + == NULL) { + (void) syslog(LOG_ERR, "load_dom_binding_cache: malloc failure."); + return (struct dom_binding *) (NULL); + } + + sa = (struct sockaddr_in *)dom_binding->dom_binding->ypbind_svcaddr->buf; + pdomb->dom_server_addr.sin_family = sa->sin_family; + pdomb->dom_server_addr.sin_port = sa->sin_port; + pdomb->dom_server_addr.sin_addr.s_addr = sa->sin_addr.s_addr; + bzero(pdomb->dom_server_addr.sin_zero, 8); + pdomb->dom_server_port = sa->sin_port; + pdomb->dom_socket = RPC_ANYSOCK; + pdomb->dom_vers = dom_binding->dom_binding->ypbind_hi_vers; + /* the claim is 5.0 CLIENT * can be used by a 4.x RPC user */ + pdomb->dom_client = dom_binding->dom_client; + + (void) strcpy(pdomb->dom_domain, domain);/* Remember the domain name */ + pdomb->dom_pnext = bound_domains; /* Link this to the list as */ + bound_domains = pdomb; /* ... the head entry */ + + return (pdomb); +} + +static void +_yp_unbind (domain) + char *domain; +{ + struct dom_binding *pdomb; + struct dom_binding *ptrail = 0; + + + if ( (domain == NULL) ||(strlen(domain) == 0) ) { + return; + } + + for (pdomb = bound_domains; pdomb != NULL; + ptrail = pdomb, pdomb = pdomb->dom_pnext) { + + if (strcmp(domain, pdomb->dom_domain) == 0) { + if (pdomb == bound_domains) + bound_domains = pdomb->dom_pnext; + else + ptrail->dom_pnext = pdomb->dom_pnext; + free((char *) pdomb); + break; + } + } +} + +int +yp_ismapthere(stat) + int stat; +{ + + switch (stat) { + + case 0: /* it actually succeeded! */ + case YPERR_KEY: /* no such key in map */ + case YPERR_NOMORE: + case YPERR_BUSY: + return (TRUE); + } + return (FALSE); +} diff --git a/usr/src/lib/libbc/libc/yp/yp_prot.h b/usr/src/lib/libbc/libc/yp/yp_prot.h new file mode 100644 index 0000000000..54f78c52d3 --- /dev/null +++ b/usr/src/lib/libbc/libc/yp/yp_prot.h @@ -0,0 +1,347 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1997 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This file contains symbols and structures defining the rpc protocol + * between the NIS clients and the NIS servers. The servers + * are the NIS database servers, and the NIS binders. + */ + +/* + * The following procedures are supported by the protocol: + * + * YPPROC_NULL() returns () takes nothing, returns nothing. This indicates + * that the NIS server is alive. + * + * YPPROC_DOMAIN (char *) returns (bool_t) TRUE. Indicates that the + * responding NIS server does serve the named domain; FALSE indicates no + * support. + * + * YPPROC_DOMAIN_NONACK (char *) returns (TRUE) if the NIS server does serve + * the named domain, otherwise does not return. Used in the broadcast case. + * + * YPPROC_MATCH (struct ypreq_key) returns (struct ypresp_val). Returns the + * right-hand value for a passed left-hand key, within a named map and + * domain. + * + * YPPROC_FIRST (struct ypreq_nokey) returns (struct ypresp_key_val). + * Returns the first key-value pair from a named domain and map. + * + * YPPROC_NEXT (struct ypreq_key) returns (struct ypresp_key_val). Returns + * the key-value pair following a passed key-value pair within a named + * domain and map. + * + * YPPROC_XFR (struct ypreq_xfr) returns nothing. Indicates to a server that + * a map should be updated. + * + * YPPROC_CLEAR takes nothing, returns nothing. Instructs a NIS server to + * close the current map, so that old versions of the disk file don't get + * held open. + * + * YPPROC_ALL (struct ypreq_nokey), returns + * union switch (bool more) { + * TRUE: (struct ypresp_key_val); + * FALSE: (struct) {}; + * } + * + * YPPROC_MASTER (struct ypreq_nokey), returns (ypresp_master) + * + * YPPROC_ORDER (struct ypreq_nokey), returns (ypresp_order) + * + * YPPROC_MAPLIST (char *), returns (struct ypmaplist *) + */ +#ifndef BOOL_DEFINED +typedef unsigned int bool; +#define BOOL_DEFINED +#endif + +extern bool xdr_datum(); +extern bool xdr_ypdomain_wrap_string(); +extern bool xdr_ypmap_wrap_string(); +extern bool xdr_ypreq_key(); +extern bool xdr_ypreq_nokey(); +extern bool xdr_ypreq_xfr(); +extern bool xdr_ypresp_val(); +extern bool xdr_ypresp_key_val(); +extern bool xdr_ypbind_resp(); +extern bool xdr_ypbind_setdom(); +extern bool xdr_yp_inaddr(); +extern bool xdr_ypmap_parms(); +extern bool xdr_ypowner_wrap_string(); +extern bool xdr_yppushresp_xfr(); +extern bool xdr_ypresp_order(); +extern bool xdr_ypresp_master(); +extern bool xdr_ypall(); +extern bool xdr_ypresp_maplist(); + +/* Program and version symbols, magic numbers */ + +#define YPPROG ((u_long)100004) +#define YPVERS ((u_long)2) +#define YPVERS_ORIG ((u_long)1) +#define YPMAXRECORD ((u_long)1024) +#define YPMAXDOMAIN ((u_long)256) +#define YPMAXMAP ((u_long)64) +#define YPMAXPEER ((u_long)256) + +/* byte size of a large NIS packet */ +#define YPMSGSZ 1600 + +#ifndef DATUM +typedef struct { + char *dptr; + int dsize; +} datum; +#define DATUM +#endif + +struct ypmap_parms { + char *domain; /* Null string means not available */ + char *map; /* Null string means not available */ + unsigned long int ordernum; /* 0 means not available */ + char *owner; /* Null string means not available */ +}; + +/* + * Request parameter structures + */ + +struct ypreq_key { + char *domain; + char *map; + datum keydat; +}; + +struct ypreq_nokey { + char *domain; + char *map; +}; + +struct ypreq_xfr { + struct ypmap_parms map_parms; + unsigned long transid; + unsigned long proto; + unsigned short port; +}; +#define ypxfr_domain map_parms.domain +#define ypxfr_map map_parms.map +#define ypxfr_ordernum map_parms.ordernum +#define ypxfr_owner map_parms.owner + +/* + * Response parameter structures + */ + +struct ypresp_val { + long unsigned status; + datum valdat; +}; + +struct ypresp_key_val { + long unsigned status; + datum keydat; + datum valdat; +}; + +struct ypresp_master { + long unsigned status; + char *master; +}; + +struct ypresp_order { + long unsigned status; + unsigned long int ordernum; +}; + +struct ypmaplist { + char ypml_name[YPMAXMAP + 1]; + struct ypmaplist *ypml_next; +}; + +struct ypresp_maplist { + long unsigned status; + struct ypmaplist *list; +}; + +/* + * Procedure symbols. YPPROC_NULL, YPPROC_DOMAIN, and YPPROC_DOMAIN_NONACK + * must keep the same values (0, 1, and 2) that they had in the first version + * of the protocol. + */ + +#define YPPROC_NULL ((u_long)0) +#define YPPROC_DOMAIN ((u_long)1) +#define YPPROC_DOMAIN_NONACK ((u_long)2) +#define YPPROC_MATCH ((u_long)3) +#define YPPROC_FIRST ((u_long)4) +#define YPPROC_NEXT ((u_long)5) +#define YPPROC_XFR ((u_long)6) +#define YPPROC_CLEAR ((u_long)7) +#define YPPROC_ALL ((u_long)8) +#define YPPROC_MASTER ((u_long)9) +#define YPPROC_ORDER ((u_long)10) +#define YPPROC_MAPLIST ((u_long)11) + +/* Return status values */ + +#define YP_TRUE ((long)1) /* General purpose success code */ +#define YP_NOMORE ((long)2) /* No more entries in map */ +#define YP_FALSE ((long)0) /* General purpose failure code */ +#define YP_NOMAP ((long)-1) /* No such map in domain */ +#define YP_NODOM ((long)-2) /* Domain not supported */ +#define YP_NOKEY ((long)-3) /* No such key in map */ +#define YP_BADOP ((long)-4) /* Invalid operation */ +#define YP_BADDB ((long)-5) /* Server data base is bad */ +#define YP_YPERR ((long)-6) /* NIS server error */ +#define YP_BADARGS ((long)-7) /* Request arguments bad */ +#define YP_VERS ((long)-8) /* NIS server version mismatch - server + * can't supply requested service. */ + +/* + * Domain binding data structure, used by ypclnt package and ypserv modules. + * Users of the ypclnt package (or of this protocol) don't HAVE to know about + * it, but it must be available to users because _yp_dobind is a public + * interface. + */ + +struct dom_binding { + struct dom_binding *dom_pnext; + char dom_domain[YPMAXDOMAIN + 1]; + struct sockaddr_in dom_server_addr; + unsigned short int dom_server_port; + int dom_socket; + CLIENT *dom_client; + unsigned short int dom_local_port; + long int dom_vers; +}; + + +/* + * Protocol between clients and NIS binder servers + */ + +/* + * The following procedures are supported by the protocol: + * + * YPBINDPROC_NULL() returns () + * takes nothing, returns nothing + * + * YPBINDPROC_DOMAIN takes (char *) returns (struct ypbind_resp) + * + * YPBINDPROC_SETDOM takes (struct ypbind_setdom) returns nothing + */ + +/* Program and version symbols, magic numbers */ + +#define YPBINDPROG ((u_long)100007) +#define YPBINDVERS ((u_long)2) +#define YPBINDVERS_ORIG ((u_long)1) + +/* Procedure symbols */ + +#define YPBINDPROC_NULL ((u_long)0) +#define YPBINDPROC_DOMAIN ((u_long)1) +#define YPBINDPROC_SETDOM ((u_long)2) +/* + * Response structure and overall result status codes. Success and failure + * represent two separate response message types. + */ + +enum ypbind_resptype {YPBIND_SUCC_VAL = 1, YPBIND_FAIL_VAL = 2}; + +struct ypbind_binding { + struct in_addr ypbind_binding_addr; /* In network order */ + unsigned short int ypbind_binding_port; /* In network order */ +}; +struct ypbind_resp { + enum ypbind_resptype ypbind_status; + union { + unsigned long ypbind_error; + struct ypbind_binding ypbind_bindinfo; + } ypbind_respbody; +}; + + +/* Detailed failure reason codes for response field ypbind_error*/ + +#define YPBIND_ERR_ERR 1 /* Internal error */ +#define YPBIND_ERR_NOSERV 2 /* No bound server for passed domain */ +#define YPBIND_ERR_RESC 3 /* System resource allocation failure */ + +/* + * Request data structure for ypbind "Set domain" procedure. + */ +struct ypbind_setdom { + char ypsetdom_domain[YPMAXDOMAIN + 1]; + struct ypbind_binding ypsetdom_binding; + unsigned short ypsetdom_vers; +}; +#define ypsetdom_addr ypsetdom_binding.ypbind_binding_addr +#define ypsetdom_port ypsetdom_binding.ypbind_binding_port + +/* + * Protocol between clients (ypxfr, only) and yppush + * yppush speaks a protocol in the transient range, which + * is supplied to ypxfr as a command-line parameter when it + * is activated by ypserv. + */ +#define YPPUSHVERS ((u_long) 1) +#define YPPUSHVERS_ORIG ((u_long)1) + +/* Procedure symbols */ + +#define YPPUSHPROC_NULL ((u_long)0) +#define YPPUSHPROC_XFRRESP ((u_long)1) + +struct yppushresp_xfr { + unsigned long transid; + unsigned long status; +}; + +/* Status values for yppushresp_xfr.status */ + +#define YPPUSH_SUCC ((long)1) /* Success */ +#define YPPUSH_AGE ((long)2) /* Master's version not newer */ +#define YPPUSH_NOMAP ((long)-1) /* Can't find server for map */ +#define YPPUSH_NODOM ((long)-2) /* Domain not supported */ +#define YPPUSH_RSRC ((long)-3) /* Local resouce alloc failure */ +#define YPPUSH_RPC ((long)-4) /* RPC failure talking to server */ +#define YPPUSH_MADDR ((long)-5) /* Can't get master address */ +#define YPPUSH_YPERR ((long)-6) /* NIS server/map db error */ +#define YPPUSH_BADARGS ((long)-7) /* Request arguments bad */ +#define YPPUSH_DBM ((long)-8) /* Local dbm operation failed */ +#define YPPUSH_FILE ((long)-9) /* Local file I/O operation failed */ +#define YPPUSH_SKEW ((long)-10) /* Map version skew during transfer */ +#define YPPUSH_CLEAR ((long)-11) /* Can't send "Clear" req to local + * ypserv */ +#define YPPUSH_FORCE ((long)-12) /* No local order number in map - + * use -f flag. */ +#define YPPUSH_XFRERR ((long)-13) /* ypxfr error */ +#define YPPUSH_REFUSED ((long)-14) /* Transfer request refused by ypserv */ + + diff --git a/usr/src/lib/libbc/libc/yp/ypclnt.h b/usr/src/lib/libbc/libc/yp/ypclnt.h new file mode 100644 index 0000000000..e2404c5c06 --- /dev/null +++ b/usr/src/lib/libbc/libc/yp/ypclnt.h @@ -0,0 +1,103 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1991 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * ypclnt.h + * This defines the symbols used in the c language + * interface to the NIS client functions. A description of this interface + * can be read in ypclnt(3N). + */ + +/* + * Failure reason codes. The success condition is indicated by a functional + * value of "0". + */ +#define YPERR_BADARGS 1 /* Args to function are bad */ +#define YPERR_RPC 2 /* RPC failure */ +#define YPERR_DOMAIN 3 /* Can't bind to a server which serves + * this domain. */ +#define YPERR_MAP 4 /* No such map in server's domain */ +#define YPERR_KEY 5 /* No such key in map */ +#define YPERR_YPERR 6 /* Internal NIS server or client + * interface error */ +#define YPERR_RESRC 7 /* Local resource allocation failure */ +#define YPERR_NOMORE 8 /* No more records in map database */ +#define YPERR_PMAP 9 /* Can't communicate with portmapper */ +#define YPERR_YPBIND 10 /* Can't communicate with ypbind */ +#define YPERR_YPSERV 11 /* Can't communicate with ypserv */ +#define YPERR_NODOM 12 /* Local domain name not set */ +#define YPERR_BADDB 13 /* NIS data base is bad */ +#define YPERR_VERS 14 /* NIS version mismatch */ +#define YPERR_ACCESS 15 /* Access violation */ +#define YPERR_BUSY 16 /* Database is busy */ + +/* + * Types of update operations + */ +#define YPOP_CHANGE 1 /* change, do not add */ +#define YPOP_INSERT 2 /* add, do not change */ +#define YPOP_DELETE 3 /* delete this entry */ +#define YPOP_STORE 4 /* add, or change */ + + + +/* + * Data definitions + */ + +/* + * struct ypall_callback * is the arg which must be passed to yp_all + */ + +struct ypall_callback { + int (*foreach)(); /* Return non-0 to stop getting + * called */ + char *data; /* Opaque pointer for use of callback + * function */ +}; + +/* + * External NIS client function references. + */ +extern int yp_bind(); +extern int _yp_dobind(); +extern void yp_unbind(); +extern int yp_get_default_domain (); +extern int yp_match (); +extern int yp_first (); +extern int yp_next(); +extern int yp_master(); +extern int yp_order(); +extern int yp_all(); +extern int yp_match(); +extern char *yperr_string(); +extern int ypprot_err(); + +/* + * Global NIS data structures + */ diff --git a/usr/src/lib/libbc/libc/yp/ypv1_prot.h b/usr/src/lib/libbc/libc/yp/ypv1_prot.h new file mode 100644 index 0000000000..54d2c461b5 --- /dev/null +++ b/usr/src/lib/libbc/libc/yp/ypv1_prot.h @@ -0,0 +1,147 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1990 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +/* + * This contains symbol and structure definitions used in supporting the old + * "v1" protocol. They were previously defined in yp_prot.h. + * + * This file exists so that the NIS system can provide backward compatibility. + * Normal NIS client processes should not use this interface: the old + * protocol will not be supported in the next release. + */ +#define YPOLDVERS (YPVERS - 1) +#define YPOLDPROC_NULL ((u_long)0) +#define YPOLDPROC_DOMAIN ((u_long)1) +#define YPOLDPROC_DOMAIN_NONACK ((u_long)2) +#define YPOLDPROC_MATCH ((u_long)3) +#define YPOLDPROC_FIRST ((u_long)4) +#define YPOLDPROC_NEXT ((u_long)5) +#define YPOLDPROC_POLL ((u_long)6) +#define YPOLDPROC_PUSH ((u_long)7) +#define YPOLDPROC_PULL ((u_long)8) +#define YPOLDPROC_GET ((u_long)9) + +enum ypreqtype {YPREQ_KEY = 1, YPREQ_NOKEY = 2, YPREQ_MAP_PARMS = 3}; +struct yprequest { + enum ypreqtype yp_reqtype; + union { + struct ypreq_key yp_req_keytype; + struct ypreq_nokey yp_req_nokeytype; + struct ypmap_parms yp_req_map_parmstype; + }yp_reqbody; +}; + +#define YPMATCH_REQTYPE YPREQ_KEY +#define ypmatch_req_domain yp_reqbody.yp_req_keytype.domain +#define ypmatch_req_map yp_reqbody.yp_req_keytype.map +#define ypmatch_req_keydat yp_reqbody.yp_req_keytype.keydat +#define ypmatch_req_keyptr yp_reqbody.yp_req_keytype.keydat.dptr +#define ypmatch_req_keysize yp_reqbody.yp_req_keytype.keydat.dsize + +#define YPFIRST_REQTYPE YPREQ_NOKEY +#define ypfirst_req_domain yp_reqbody.yp_req_nokeytype.domain +#define ypfirst_req_map yp_reqbody.yp_req_nokeytype.map + +#define YPNEXT_REQTYPE YPREQ_KEY +#define ypnext_req_domain yp_reqbody.yp_req_keytype.domain +#define ypnext_req_map yp_reqbody.yp_req_keytype.map +#define ypnext_req_keydat yp_reqbody.yp_req_keytype.keydat +#define ypnext_req_keyptr yp_reqbody.yp_req_keytype.keydat.dptr +#define ypnext_req_keysize yp_reqbody.yp_req_keytype.keydat.dsize + +#define YPPUSH_REQTYPE YPREQ_NOKEY +#define yppush_req_domain yp_reqbody.yp_req_nokeytype.domain +#define yppush_req_map yp_reqbody.yp_req_nokeytype.map + +#define YPPULL_REQTYPE YPREQ_NOKEY +#define yppull_req_domain yp_reqbody.yp_req_nokeytype.domain +#define yppull_req_map yp_reqbody.yp_req_nokeytype.map + +#define YPPOLL_REQTYPE YPREQ_NOKEY +#define yppoll_req_domain yp_reqbody.yp_req_nokeytype.domain +#define yppoll_req_map yp_reqbody.yp_req_nokeytype.map + +#define YPGET_REQTYPE YPREQ_MAP_PARMS +#define ypget_req_domain yp_reqbody.yp_req_map_parmstype.domain +#define ypget_req_map yp_reqbody.yp_req_map_parmstype.map +#define ypget_req_ordernum yp_reqbody.yp_req_map_parmstype.ordernum +#define ypget_req_owner yp_reqbody.yp_req_map_parmstype.owner + +enum ypresptype {YPRESP_VAL = 1, YPRESP_KEY_VAL = 2, YPRESP_MAP_PARMS = 3}; +struct ypresponse { + enum ypresptype yp_resptype; + union { + struct ypresp_val yp_resp_valtype; + struct ypresp_key_val yp_resp_key_valtype; + struct ypmap_parms yp_resp_map_parmstype; + } yp_respbody; +}; + +#define YPMATCH_RESPTYPE YPRESP_VAL +#define ypmatch_resp_status yp_respbody.yp_resp_valtype.status +#define ypmatch_resp_valdat yp_respbody.yp_resp_valtype.valdat +#define ypmatch_resp_valptr yp_respbody.yp_resp_valtype.valdat.dptr +#define ypmatch_resp_valsize yp_respbody.yp_resp_valtype.valdat.dsize + +#define YPFIRST_RESPTYPE YPRESP_KEY_VAL +#define ypfirst_resp_status yp_respbody.yp_resp_key_valtype.status +#define ypfirst_resp_keydat yp_respbody.yp_resp_key_valtype.keydat +#define ypfirst_resp_keyptr yp_respbody.yp_resp_key_valtype.keydat.dptr +#define ypfirst_resp_keysize yp_respbody.yp_resp_key_valtype.keydat.dsize +#define ypfirst_resp_valdat yp_respbody.yp_resp_key_valtype.valdat +#define ypfirst_resp_valptr yp_respbody.yp_resp_key_valtype.valdat.dptr +#define ypfirst_resp_valsize yp_respbody.yp_resp_key_valtype.valdat.dsize + +#define YPNEXT_RESPTYPE YPRESP_KEY_VAL +#define ypnext_resp_status yp_respbody.yp_resp_key_valtype.status +#define ypnext_resp_keydat yp_respbody.yp_resp_key_valtype.keydat +#define ypnext_resp_keyptr yp_respbody.yp_resp_key_valtype.keydat.dptr +#define ypnext_resp_keysize yp_respbody.yp_resp_key_valtype.keydat.dsize +#define ypnext_resp_valdat yp_respbody.yp_resp_key_valtype.valdat +#define ypnext_resp_valptr yp_respbody.yp_resp_key_valtype.valdat.dptr +#define ypnext_resp_valsize yp_respbody.yp_resp_key_valtype.valdat.dsize + +#define YPPOLL_RESPTYPE YPRESP_MAP_PARMS +#define yppoll_resp_domain yp_respbody.yp_resp_map_parmstype.domain +#define yppoll_resp_map yp_respbody.yp_resp_map_parmstype.map +#define yppoll_resp_ordernum yp_respbody.yp_resp_map_parmstype.ordernum +#define yppoll_resp_owner yp_respbody.yp_resp_map_parmstype.owner + + +extern bool _xdr_yprequest(); +extern bool _xdr_ypresponse(); + +#define YPBINDOLDVERS (YPBINDVERS - 1) +struct ypbind_oldsetdom { + char ypoldsetdom_domain[YPMAXDOMAIN + 1]; + struct ypbind_binding ypoldsetdom_binding; +}; +#define ypoldsetdom_addr ypoldsetdom_binding.ypbind_binding_addr +#define ypoldsetdom_port ypoldsetdom_binding.ypbind_binding_port + +extern bool _xdr_ypbind_oldsetdom(); |