From 18e5fa7e42323fc7f4bcc3506a34afcfc04cb420 Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Mon, 12 Feb 1979 05:47:05 -0800 Subject: [PATCH] BSD 3 development Work on file usr/src/lib/libdbm/dbm.c Work on file usr/src/lib/libm/hypot.c Work on file usr/src/lib/libm/erf.c Work on file usr/src/lib/libdbm/dbm.h Work on file usr/src/lib/libm/atan.c Work on file usr/src/lib/libm/exp.c Work on file usr/src/lib/libm/fabs.c Work on file usr/src/lib/libm/floor.c Work on file usr/src/lib/libdbm/Makefile Work on file usr/src/lib/libm/j1.c Work on file usr/src/lib/libm/tanh.c Work on file usr/src/lib/libmp/madd.c Work on file usr/src/lib/libm/j0.c Work on file usr/src/lib/libm/log.c Work on file usr/src/lib/libm/sinh.c Work on file usr/src/lib/libm/tan.c Work on file usr/src/lib/libm/sin.c Work on file usr/src/lib/libmp/mdiv.c Work on file usr/src/lib/libmp/gcd.c Work on file usr/src/lib/libmp/mout.c Work on file usr/src/lib/libm/jn.c Work on file usr/src/lib/libm/sqrt.c Work on file usr/src/lib/libm/pow.c Work on file usr/src/lib/libmp/mult.c Work on file usr/src/lib/libmp/msqrt.c Work on file usr/src/lib/libmp/pow.c Work on file usr/src/lib/libmp/util.c Work on file usr/src/libc/crt/mcount.s Work on file usr/src/libc/gen/calloc.c Work on file usr/src/libc/gen/atofo.s Work on file usr/src/libc/crt/cerror.s Work on file usr/src/libc/gen/atof.c Work on file usr/src/libc/csu/crt0.s Work on file usr/src/libc/csu/mcrt0.s Work on file usr/src/libc/gen/chrtab.c Work on file usr/src/libc/gen/atol.c Work on file usr/src/libc/gen/ctime.c Work on file usr/src/libc/gen/mktemp.c Work on file usr/src/libc/gen/ecvt.c Work on file usr/src/libc/gen/errlst.c Work on file usr/src/libc/gen/index.c Work on file usr/src/libc/gen/execvp.c Work on file usr/src/libc/gen/getlogin.c Work on file usr/src/libc/gen/ltol3.c Work on file usr/src/libc/gen/malloc.c Work on file usr/src/libc/gen/frexp.c Work on file usr/src/libc/gen/l3tol.c Work on file usr/src/libc/gen/isatty.c Work on file usr/src/libc/gen/getenv.c Work on file usr/src/libc/gen/crypt.c Work on file usr/src/libc/gen/ldexp.c Work on file usr/src/libc/gen/modf.c Work on file usr/src/libc/gen/rin.c Work on file usr/src/libc/gen/rindex.c Work on file usr/src/libc/gen/strcpyn.c Work on file usr/src/libc/gen/rand.c Work on file usr/src/libc/gen/strlen.c Work on file usr/src/libc/gen/strcpy.c Work on file usr/src/libc/gen/strncat.c Work on file usr/src/libc/gen/perror.c Work on file usr/src/libc/gen/strcmp.c Work on file usr/src/libc/gen/strncmp.c Work on file usr/src/libc/gen/qsort.c Work on file usr/src/libc/gen/strcat.c Work on file usr/src/libc/gen/strcmpn.c Work on file usr/src/libc/gen/strcatn.c Work on file usr/src/libc/gen/stty.c Work on file usr/src/libc/stdio/data.c Work on file usr/src/libc/stdio/clrerr.c Work on file usr/src/libc/gen/ttyname.c Work on file usr/src/libc/stdio/doscan.c Work on file usr/src/libc/gen/strncpy.c Work on file usr/src/libc/stdio/fdopen.c Work on file usr/src/libc/gen/tell.c Work on file usr/src/libc/gen/swab.c Work on file usr/src/libc/gen/timezone.c Work on file usr/src/libc/stdio/error.c Work on file usr/src/libc/gen/ttyslot.c Work on file usr/src/libc/stdio/fgets.c Work on file usr/src/libc/stdio/freopen.c Work on file usr/src/libc/stdio/getgrent.c Work on file usr/src/libc/stdio/fputc.c Work on file usr/src/libc/stdio/getgrnam.c Work on file usr/src/libc/stdio/filbuf.c Work on file usr/src/libc/stdio/fgetc.c Work on file usr/src/libc/stdio/fputs.c Work on file usr/src/libc/stdio/fprintf.c Work on file usr/src/libc/stdio/getchar.c Work on file usr/src/libc/stdio/getpass.c Work on file usr/src/libc/stdio/gcvt.c Work on file usr/src/libc/stdio/ftell.c Work on file usr/src/libc/stdio/flsbuf.c Work on file usr/src/libc/stdio/getgrgid.c Work on file usr/src/libc/stdio/fseek.c Work on file usr/src/libc/stdio/ios.r Work on file usr/src/libc/stdio/getpwent.c Work on file usr/src/libc/stdio/getpw.c Work on file usr/src/libc/stdio/getpwuid.c Work on file usr/src/libc/stdio/gets.c Work on file usr/src/libc/stdio/getw.c Work on file usr/src/libc/stdio/getpwnam.c Work on file usr/src/libc/stdio/intss.c Work on file usr/src/libc/stdio/printf.c Work on file usr/src/libc/stdio/scanf.c Work on file usr/src/libc/stdio/stuff.c Work on file usr/src/libc/stdio/ungetc.c Work on file usr/src/libc/stdio/tmpnam.c Work on file usr/src/libc/stdio/portli.cc Work on file usr/src/libc/sys/_exit.s Work on file usr/src/libc/stdio/sprintf.c Work on file usr/src/libc/stdio/puts.c Work on file usr/src/libc/stdio/strout.c Work on file usr/src/libc/stdio/rew.c Work on file usr/src/libc/stdio/putw.c Work on file usr/src/libc/stdio/putchar.c Work on file usr/src/libc/stdio/rdwr.c Work on file usr/src/libc/stdio/setbuf.c Work on file usr/src/libc/sys/chdir.s Work on file usr/src/libc/sys/creat.s Work on file usr/src/libc/sys/acct.s Work on file usr/src/libc/sys/crt0.s Work on file usr/src/libc/sys/cleanup.s Work on file usr/src/libc/sys/execle.s Work on file usr/src/libc/sys/chown.s Work on file usr/src/libc/sys/chmod.s Work on file usr/src/libc/sys/alloca.s Work on file usr/src/libc/sys/close.s Work on file usr/src/libc/sys/execl.s Work on file usr/src/libc/sys/abort.s Work on file usr/src/libc/sys/access.s Work on file usr/src/libc/sys/cerror.s Work on file usr/src/libc/sys/abs.s Work on file usr/src/libc/sys/dup.s Work on file usr/src/libc/sys/chroot.s Work on file usr/src/libc/sys/alarm.s Work on file usr/src/libc/sys/execv.s Work on file usr/src/libc/sys/ioctl.s Work on file usr/src/libc/sys/execve.s Work on file usr/src/libc/sys/getcsw.s Work on file usr/src/libc/sys/makdir.s Work on file usr/src/libc/sys/kill.s Work on file usr/src/libc/sys/link.s Work on file usr/src/libc/sys/locv.s Work on file usr/src/libc/sys/ltoi.s Work on file usr/src/libc/sys/exit.s Work on file usr/src/libc/sys/getpid.s Work on file usr/src/libc/sys/getuid.s Work on file usr/src/libc/sys/ltod.s Work on file usr/src/libc/sys/fstat.s Work on file usr/src/libc/sys/getgid.s Work on file usr/src/libc/sys/itol.s Work on file usr/src/libc/sys/nargs.s Work on file usr/src/libc/sys/mcount.s Work on file usr/src/libc/sys/setgid.s Work on file usr/src/libc/sys/pipe.s Work on file usr/src/libc/sys/ptrace.s Work on file usr/src/libc/sys/reset.s Work on file usr/src/libc/sys/mdate.s Work on file usr/src/libc/sys/open.s Work on file usr/src/libc/sys/nexect.s Work on file usr/src/libc/sys/sbrk.s Work on file usr/src/libc/sys/prof.s Work on file usr/src/libc/sys/nice.s Work on file usr/src/libc/sys/mknod.s Work on file usr/src/libc/sys/mount.s Work on file usr/src/libc/sys/read.s Work on file usr/src/libc/sys/mcrt0.s Work on file usr/src/libc/sys/time.s Work on file usr/src/libc/sys/utime.s Work on file usr/src/libc/sys/syscall.s Work on file usr/src/libc/sys/wait.s Work on file usr/src/libc/sys/times.s Work on file usr/src/libc/sys/umask.s Work on file usr/src/libc/sys/sync.s Work on file usr/src/libc/sys/unlink.s Work on file usr/src/libc/sys/stat.s Work on file usr/src/libc/sys/setuid.s Work on file usr/src/libc/sys/stime.s Work on file usr/src/libc/sys/umount.s Work on file usr/src/libc/sys/write.s Work on file usr/src/libc/sys/signal.s Synthesized-from: 3bsd --- usr/src/lib/libdbm/Makefile | 13 + usr/src/lib/libdbm/dbm.c | 471 +++++++++++++++++++++++ usr/src/lib/libdbm/dbm.h | 30 ++ usr/src/lib/libm/atan.c | 111 ++++++ usr/src/lib/libm/erf.c | 116 ++++++ usr/src/lib/libm/exp.c | 45 +++ usr/src/lib/libm/fabs.c | 9 + usr/src/lib/libm/floor.c | 30 ++ usr/src/lib/libm/hypot.c | 41 ++ usr/src/lib/libm/j0.c | 187 ++++++++++ usr/src/lib/libm/j1.c | 193 ++++++++++ usr/src/lib/libm/jn.c | 107 ++++++ usr/src/lib/libm/log.c | 62 +++ usr/src/lib/libm/pow.c | 36 ++ usr/src/lib/libm/sin.c | 74 ++++ usr/src/lib/libm/sinh.c | 67 ++++ usr/src/lib/libm/sqrt.c | 56 +++ usr/src/lib/libm/tan.c | 73 ++++ usr/src/lib/libm/tanh.c | 27 ++ usr/src/lib/libmp/gcd.c | 46 +++ usr/src/lib/libmp/madd.c | 146 ++++++++ usr/src/lib/libmp/mdiv.c | 106 ++++++ usr/src/lib/libmp/mout.c | 141 +++++++ usr/src/lib/libmp/msqrt.c | 37 ++ usr/src/lib/libmp/mult.c | 87 +++++ usr/src/lib/libmp/pow.c | 40 ++ usr/src/lib/libmp/util.c | 88 +++++ usr/src/libc/crt/cerror.s | 10 + usr/src/libc/crt/mcount.s | 19 + usr/src/libc/csu/crt0.s | 33 ++ usr/src/libc/csu/mcrt0.s | 83 ++++ usr/src/libc/gen/atof.c | 49 +++ usr/src/libc/gen/atofo.s | 148 ++++++++ usr/src/libc/gen/atol.c | 25 ++ usr/src/libc/gen/calloc.c | 31 ++ usr/src/libc/gen/chrtab.c | 98 +++++ usr/src/libc/gen/crypt.c | 380 +++++++++++++++++++ usr/src/libc/gen/ctime.c | 245 ++++++++++++ usr/src/libc/gen/ecvt.c | 104 ++++++ usr/src/libc/gen/errlst.c | 38 ++ usr/src/libc/gen/execvp.c | 83 ++++ usr/src/libc/gen/frexp.c | 36 ++ usr/src/libc/gen/getenv.c | 40 ++ usr/src/libc/gen/getlogin.c | 25 ++ usr/src/libc/gen/index.c | 17 + usr/src/libc/gen/isatty.c | 14 + usr/src/libc/gen/l3tol.c | 24 ++ usr/src/libc/gen/ldexp.c | 40 ++ usr/src/libc/gen/ltol3.c | 24 ++ usr/src/libc/gen/malloc.c | 189 ++++++++++ usr/src/libc/gen/mktemp.c | 26 ++ usr/src/libc/gen/modf.c | 46 +++ usr/src/libc/gen/perror.c | 25 ++ usr/src/libc/gen/qsort.c | 120 ++++++ usr/src/libc/gen/rand.c | 12 + usr/src/libc/gen/rin.c | 35 ++ usr/src/libc/gen/rindex.c | 20 + usr/src/libc/gen/strcat.c | 19 + usr/src/libc/gen/strcatn.c | 24 ++ usr/src/libc/gen/strcmp.c | 13 + usr/src/libc/gen/strcmpn.c | 14 + usr/src/libc/gen/strcpy.c | 16 + usr/src/libc/gen/strcpyn.c | 21 ++ usr/src/libc/gen/strlen.c | 15 + usr/src/libc/gen/strncat.c | 24 ++ usr/src/libc/gen/strncmp.c | 14 + usr/src/libc/gen/strncpy.c | 21 ++ usr/src/libc/gen/stty.c | 17 + usr/src/libc/gen/swab.c | 16 + usr/src/libc/gen/tell.c | 10 + usr/src/libc/gen/timezone.c | 44 +++ usr/src/libc/gen/ttyname.c | 49 +++ usr/src/libc/gen/ttyslot.c | 58 +++ usr/src/libc/stdio/clrerr.c | 7 + usr/src/libc/stdio/data.c | 13 + usr/src/libc/stdio/doscan.c | 275 ++++++++++++++ usr/src/libc/stdio/error.c | 12 + usr/src/libc/stdio/fdopen.c | 30 ++ usr/src/libc/stdio/fgetc.c | 7 + usr/src/libc/stdio/fgets.c | 21 ++ usr/src/libc/stdio/filbuf.c | 36 ++ usr/src/libc/stdio/flsbuf.c | 102 +++++ usr/src/libc/stdio/fprintf.c | 9 + usr/src/libc/stdio/fputc.c | 7 + usr/src/libc/stdio/fputs.c | 13 + usr/src/libc/stdio/freopen.c | 28 ++ usr/src/libc/stdio/fseek.c | 44 +++ usr/src/libc/stdio/ftell.c | 31 ++ usr/src/libc/stdio/gcvt.c | 62 +++ usr/src/libc/stdio/getchar.c | 11 + usr/src/libc/stdio/getgrent.c | 63 ++++ usr/src/libc/stdio/getgrgid.c | 14 + usr/src/libc/stdio/getgrnam.c | 14 + usr/src/libc/stdio/getpass.c | 40 ++ usr/src/libc/stdio/getpw.c | 39 ++ usr/src/libc/stdio/getpwent.c | 66 ++++ usr/src/libc/stdio/getpwnam.c | 14 + usr/src/libc/stdio/getpwuid.c | 14 + usr/src/libc/stdio/gets.c | 17 + usr/src/libc/stdio/getw.c | 16 + usr/src/libc/stdio/intss.c | 4 + usr/src/libc/stdio/ios.r | 685 ++++++++++++++++++++++++++++++++++ usr/src/libc/stdio/portli.cc | 136 +++++++ usr/src/libc/stdio/printf.c | 8 + usr/src/libc/stdio/putchar.c | 12 + usr/src/libc/stdio/puts.c | 11 + usr/src/libc/stdio/putw.c | 13 + usr/src/libc/stdio/rdwr.c | 44 +++ usr/src/libc/stdio/rew.c | 11 + usr/src/libc/stdio/scanf.c | 28 ++ usr/src/libc/stdio/setbuf.c | 15 + usr/src/libc/stdio/sprintf.c | 14 + usr/src/libc/stdio/strout.c | 23 ++ usr/src/libc/stdio/stuff.c | 6 + usr/src/libc/stdio/tmpnam.c | 8 + usr/src/libc/stdio/ungetc.c | 16 + usr/src/libc/sys/_exit.s | 14 + usr/src/libc/sys/abort.s | 10 + usr/src/libc/sys/abs.s | 22 ++ usr/src/libc/sys/access.s | 16 + usr/src/libc/sys/acct.s | 13 + usr/src/libc/sys/alarm.s | 18 + usr/src/libc/sys/alloca.s | 13 + usr/src/libc/sys/cerror.s | 10 + usr/src/libc/sys/chdir.s | 15 + usr/src/libc/sys/chmod.s | 15 + usr/src/libc/sys/chown.s | 15 + usr/src/libc/sys/chroot.s | 15 + usr/src/libc/sys/cleanup.s | 8 + usr/src/libc/sys/close.s | 15 + usr/src/libc/sys/creat.s | 16 + usr/src/libc/sys/crt0.s | 33 ++ usr/src/libc/sys/dup.s | 22 ++ usr/src/libc/sys/execl.s | 13 + usr/src/libc/sys/execle.s | 15 + usr/src/libc/sys/execv.s | 17 + usr/src/libc/sys/execve.s | 14 + usr/src/libc/sys/exit.s | 15 + usr/src/libc/sys/fstat.s | 17 + usr/src/libc/sys/getcsw.s | 11 + usr/src/libc/sys/getgid.s | 25 ++ usr/src/libc/sys/getpid.s | 17 + usr/src/libc/sys/getuid.s | 27 ++ usr/src/libc/sys/ioctl.s | 18 + usr/src/libc/sys/itol.s | 12 + usr/src/libc/sys/kill.s | 14 + usr/src/libc/sys/link.s | 17 + usr/src/libc/sys/locv.s | 15 + usr/src/libc/sys/ltod.s | 18 + usr/src/libc/sys/ltoi.s | 8 + usr/src/libc/sys/makdir.s | 16 + usr/src/libc/sys/mcount.s | 19 + usr/src/libc/sys/mcrt0.s | 83 ++++ usr/src/libc/sys/mdate.s | 14 + usr/src/libc/sys/mknod.s | 16 + usr/src/libc/sys/mount.s | 16 + usr/src/libc/sys/nargs.s | 9 + usr/src/libc/sys/nexect.s | 20 + usr/src/libc/sys/nice.s | 16 + usr/src/libc/sys/open.s | 17 + usr/src/libc/sys/pipe.s | 20 + usr/src/libc/sys/prof.s | 8 + usr/src/libc/sys/ptrace.s | 17 + usr/src/libc/sys/read.s | 17 + usr/src/libc/sys/reset.s | 45 +++ usr/src/libc/sys/sbrk.s | 42 +++ usr/src/libc/sys/setgid.s | 16 + usr/src/libc/sys/setuid.s | 16 + usr/src/libc/sys/signal.s | 19 + usr/src/libc/sys/stat.s | 18 + usr/src/libc/sys/stime.s | 13 + usr/src/libc/sys/sync.s | 7 + usr/src/libc/sys/syscall.s | 11 + usr/src/libc/sys/time.s | 26 ++ usr/src/libc/sys/times.s | 9 + usr/src/libc/sys/umask.s | 15 + usr/src/libc/sys/umount.s | 15 + usr/src/libc/sys/unlink.s | 17 + usr/src/libc/sys/utime.s | 15 + usr/src/libc/sys/wait.s | 25 ++ usr/src/libc/sys/write.s | 17 + 181 files changed, 8049 insertions(+) create mode 100644 usr/src/lib/libdbm/Makefile create mode 100644 usr/src/lib/libdbm/dbm.c create mode 100644 usr/src/lib/libdbm/dbm.h create mode 100644 usr/src/lib/libm/atan.c create mode 100644 usr/src/lib/libm/erf.c create mode 100644 usr/src/lib/libm/exp.c create mode 100644 usr/src/lib/libm/fabs.c create mode 100644 usr/src/lib/libm/floor.c create mode 100644 usr/src/lib/libm/hypot.c create mode 100644 usr/src/lib/libm/j0.c create mode 100644 usr/src/lib/libm/j1.c create mode 100644 usr/src/lib/libm/jn.c create mode 100644 usr/src/lib/libm/log.c create mode 100644 usr/src/lib/libm/pow.c create mode 100644 usr/src/lib/libm/sin.c create mode 100644 usr/src/lib/libm/sinh.c create mode 100644 usr/src/lib/libm/sqrt.c create mode 100644 usr/src/lib/libm/tan.c create mode 100644 usr/src/lib/libm/tanh.c create mode 100644 usr/src/lib/libmp/gcd.c create mode 100644 usr/src/lib/libmp/madd.c create mode 100644 usr/src/lib/libmp/mdiv.c create mode 100644 usr/src/lib/libmp/mout.c create mode 100644 usr/src/lib/libmp/msqrt.c create mode 100644 usr/src/lib/libmp/mult.c create mode 100644 usr/src/lib/libmp/pow.c create mode 100644 usr/src/lib/libmp/util.c create mode 100644 usr/src/libc/crt/cerror.s create mode 100644 usr/src/libc/crt/mcount.s create mode 100644 usr/src/libc/csu/crt0.s create mode 100644 usr/src/libc/csu/mcrt0.s create mode 100644 usr/src/libc/gen/atof.c create mode 100644 usr/src/libc/gen/atofo.s create mode 100644 usr/src/libc/gen/atol.c create mode 100644 usr/src/libc/gen/calloc.c create mode 100644 usr/src/libc/gen/chrtab.c create mode 100644 usr/src/libc/gen/crypt.c create mode 100644 usr/src/libc/gen/ctime.c create mode 100644 usr/src/libc/gen/ecvt.c create mode 100644 usr/src/libc/gen/errlst.c create mode 100644 usr/src/libc/gen/execvp.c create mode 100644 usr/src/libc/gen/frexp.c create mode 100644 usr/src/libc/gen/getenv.c create mode 100644 usr/src/libc/gen/getlogin.c create mode 100644 usr/src/libc/gen/index.c create mode 100644 usr/src/libc/gen/isatty.c create mode 100644 usr/src/libc/gen/l3tol.c create mode 100644 usr/src/libc/gen/ldexp.c create mode 100644 usr/src/libc/gen/ltol3.c create mode 100644 usr/src/libc/gen/malloc.c create mode 100644 usr/src/libc/gen/mktemp.c create mode 100644 usr/src/libc/gen/modf.c create mode 100644 usr/src/libc/gen/perror.c create mode 100644 usr/src/libc/gen/qsort.c create mode 100644 usr/src/libc/gen/rand.c create mode 100644 usr/src/libc/gen/rin.c create mode 100644 usr/src/libc/gen/rindex.c create mode 100644 usr/src/libc/gen/strcat.c create mode 100644 usr/src/libc/gen/strcatn.c create mode 100644 usr/src/libc/gen/strcmp.c create mode 100644 usr/src/libc/gen/strcmpn.c create mode 100644 usr/src/libc/gen/strcpy.c create mode 100644 usr/src/libc/gen/strcpyn.c create mode 100644 usr/src/libc/gen/strlen.c create mode 100644 usr/src/libc/gen/strncat.c create mode 100644 usr/src/libc/gen/strncmp.c create mode 100644 usr/src/libc/gen/strncpy.c create mode 100644 usr/src/libc/gen/stty.c create mode 100644 usr/src/libc/gen/swab.c create mode 100644 usr/src/libc/gen/tell.c create mode 100644 usr/src/libc/gen/timezone.c create mode 100644 usr/src/libc/gen/ttyname.c create mode 100644 usr/src/libc/gen/ttyslot.c create mode 100644 usr/src/libc/stdio/clrerr.c create mode 100644 usr/src/libc/stdio/data.c create mode 100644 usr/src/libc/stdio/doscan.c create mode 100644 usr/src/libc/stdio/error.c create mode 100644 usr/src/libc/stdio/fdopen.c create mode 100644 usr/src/libc/stdio/fgetc.c create mode 100644 usr/src/libc/stdio/fgets.c create mode 100644 usr/src/libc/stdio/filbuf.c create mode 100644 usr/src/libc/stdio/flsbuf.c create mode 100644 usr/src/libc/stdio/fprintf.c create mode 100644 usr/src/libc/stdio/fputc.c create mode 100644 usr/src/libc/stdio/fputs.c create mode 100644 usr/src/libc/stdio/freopen.c create mode 100644 usr/src/libc/stdio/fseek.c create mode 100644 usr/src/libc/stdio/ftell.c create mode 100644 usr/src/libc/stdio/gcvt.c create mode 100644 usr/src/libc/stdio/getchar.c create mode 100644 usr/src/libc/stdio/getgrent.c create mode 100644 usr/src/libc/stdio/getgrgid.c create mode 100644 usr/src/libc/stdio/getgrnam.c create mode 100644 usr/src/libc/stdio/getpass.c create mode 100644 usr/src/libc/stdio/getpw.c create mode 100644 usr/src/libc/stdio/getpwent.c create mode 100644 usr/src/libc/stdio/getpwnam.c create mode 100644 usr/src/libc/stdio/getpwuid.c create mode 100644 usr/src/libc/stdio/gets.c create mode 100644 usr/src/libc/stdio/getw.c create mode 100644 usr/src/libc/stdio/intss.c create mode 100644 usr/src/libc/stdio/ios.r create mode 100644 usr/src/libc/stdio/portli.cc create mode 100644 usr/src/libc/stdio/printf.c create mode 100644 usr/src/libc/stdio/putchar.c create mode 100644 usr/src/libc/stdio/puts.c create mode 100644 usr/src/libc/stdio/putw.c create mode 100644 usr/src/libc/stdio/rdwr.c create mode 100644 usr/src/libc/stdio/rew.c create mode 100644 usr/src/libc/stdio/scanf.c create mode 100644 usr/src/libc/stdio/setbuf.c create mode 100644 usr/src/libc/stdio/sprintf.c create mode 100644 usr/src/libc/stdio/strout.c create mode 100644 usr/src/libc/stdio/stuff.c create mode 100644 usr/src/libc/stdio/tmpnam.c create mode 100644 usr/src/libc/stdio/ungetc.c create mode 100644 usr/src/libc/sys/_exit.s create mode 100644 usr/src/libc/sys/abort.s create mode 100644 usr/src/libc/sys/abs.s create mode 100644 usr/src/libc/sys/access.s create mode 100644 usr/src/libc/sys/acct.s create mode 100644 usr/src/libc/sys/alarm.s create mode 100644 usr/src/libc/sys/alloca.s create mode 100644 usr/src/libc/sys/cerror.s create mode 100644 usr/src/libc/sys/chdir.s create mode 100644 usr/src/libc/sys/chmod.s create mode 100644 usr/src/libc/sys/chown.s create mode 100644 usr/src/libc/sys/chroot.s create mode 100644 usr/src/libc/sys/cleanup.s create mode 100644 usr/src/libc/sys/close.s create mode 100644 usr/src/libc/sys/creat.s create mode 100644 usr/src/libc/sys/crt0.s create mode 100644 usr/src/libc/sys/dup.s create mode 100644 usr/src/libc/sys/execl.s create mode 100644 usr/src/libc/sys/execle.s create mode 100644 usr/src/libc/sys/execv.s create mode 100644 usr/src/libc/sys/execve.s create mode 100644 usr/src/libc/sys/exit.s create mode 100644 usr/src/libc/sys/fstat.s create mode 100644 usr/src/libc/sys/getcsw.s create mode 100644 usr/src/libc/sys/getgid.s create mode 100644 usr/src/libc/sys/getpid.s create mode 100644 usr/src/libc/sys/getuid.s create mode 100644 usr/src/libc/sys/ioctl.s create mode 100644 usr/src/libc/sys/itol.s create mode 100644 usr/src/libc/sys/kill.s create mode 100644 usr/src/libc/sys/link.s create mode 100644 usr/src/libc/sys/locv.s create mode 100644 usr/src/libc/sys/ltod.s create mode 100644 usr/src/libc/sys/ltoi.s create mode 100644 usr/src/libc/sys/makdir.s create mode 100644 usr/src/libc/sys/mcount.s create mode 100644 usr/src/libc/sys/mcrt0.s create mode 100644 usr/src/libc/sys/mdate.s create mode 100644 usr/src/libc/sys/mknod.s create mode 100644 usr/src/libc/sys/mount.s create mode 100644 usr/src/libc/sys/nargs.s create mode 100644 usr/src/libc/sys/nexect.s create mode 100644 usr/src/libc/sys/nice.s create mode 100644 usr/src/libc/sys/open.s create mode 100644 usr/src/libc/sys/pipe.s create mode 100644 usr/src/libc/sys/prof.s create mode 100644 usr/src/libc/sys/ptrace.s create mode 100644 usr/src/libc/sys/read.s create mode 100644 usr/src/libc/sys/reset.s create mode 100644 usr/src/libc/sys/sbrk.s create mode 100644 usr/src/libc/sys/setgid.s create mode 100644 usr/src/libc/sys/setuid.s create mode 100644 usr/src/libc/sys/signal.s create mode 100644 usr/src/libc/sys/stat.s create mode 100644 usr/src/libc/sys/stime.s create mode 100644 usr/src/libc/sys/sync.s create mode 100644 usr/src/libc/sys/syscall.s create mode 100644 usr/src/libc/sys/time.s create mode 100644 usr/src/libc/sys/times.s create mode 100644 usr/src/libc/sys/umask.s create mode 100644 usr/src/libc/sys/umount.s create mode 100644 usr/src/libc/sys/unlink.s create mode 100644 usr/src/libc/sys/utime.s create mode 100644 usr/src/libc/sys/wait.s create mode 100644 usr/src/libc/sys/write.s diff --git a/usr/src/lib/libdbm/Makefile b/usr/src/lib/libdbm/Makefile new file mode 100644 index 0000000000..7b86eceeaf --- /dev/null +++ b/usr/src/lib/libdbm/Makefile @@ -0,0 +1,13 @@ +CFLAGS=-O + +libdbm.a: dbm.o + mv dbm.o libdbm.a + +dbm.o : dbm.h + +install: + install -c libdbm.a $(DESTDIR)/usr/lib + install -c dbm.h $(DESTDIR)/usr/include + +clean: + rm libdbm.a diff --git a/usr/src/lib/libdbm/dbm.c b/usr/src/lib/libdbm/dbm.c new file mode 100644 index 0000000000..b594193e31 --- /dev/null +++ b/usr/src/lib/libdbm/dbm.c @@ -0,0 +1,471 @@ +#include "dbm.h" +#include +#include + +dbminit(file) +char *file; +{ + struct stat statb; + + strcpy(pagbuf, file); + strcat(pagbuf, ".pag"); + pagf = open(pagbuf, 2); + + strcpy(pagbuf, file); + strcat(pagbuf, ".dir"); + dirf = open(pagbuf, 2); + if(pagf < 0 || dirf < 0) { + printf("cannot open database %s\n", file); + return(-1); + } + fstat(dirf, &statb); + maxbno = statb.st_size*BYTESIZ-1; + return(0); +} + +long +forder(key) +datum key; +{ + long hash; + + hash = calchash(key); + for(hmask=0;; hmask=(hmask<<1)+1) { + blkno = hash & hmask; + bitno = blkno + hmask; + if(getbit() == 0) + break; + } + return(blkno); +} + +datum +fetch(key) +datum key; +{ + register i; + datum item; + + dbm_access(calchash(key)); + for(i=0;; i+=2) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + return(item); + if(cmpdatum(key, item) == 0) { + item = makdatum(pagbuf, i+1); + if(item.dptr == NULL) + printf("items not in pairs\n"); + return(item); + } + } +} + +delete(key) +datum key; +{ + register i; + datum item; + + dbm_access(calchash(key)); + for(i=0;; i+=2) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + return(-1); + if(cmpdatum(key, item) == 0) { + delitem(pagbuf, i); + delitem(pagbuf, i); + break; + } + } + lseek(pagf, blkno*PBLKSIZ, 0); + write(pagf, pagbuf, PBLKSIZ); + return(0); +} + +store(key, dat) +datum key, dat; +{ + register i; + datum item; + char ovfbuf[PBLKSIZ]; + +loop: + dbm_access(calchash(key)); + for(i=0;; i+=2) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + break; + if(cmpdatum(key, item) == 0) { + delitem(pagbuf, i); + delitem(pagbuf, i); + break; + } + } + i = additem(pagbuf, key); + if(i < 0) + goto split; + if(additem(pagbuf, dat) < 0) { + delitem(pagbuf, i); + goto split; + } + lseek(pagf, blkno*PBLKSIZ, 0); + write(pagf, pagbuf, PBLKSIZ); + return; + +split: + if(key.dsize+dat.dsize+2*sizeof(short) >= PBLKSIZ) { + printf("entry too big\n"); + return; + } + clrbuf(ovfbuf, PBLKSIZ); + for(i=0;;) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + break; + if(calchash(item) & (hmask+1)) { + additem(ovfbuf, item); + delitem(pagbuf, i); + item = makdatum(pagbuf, i); + if(item.dptr == NULL) { + printf("split not paired\n"); + break; + } + additem(ovfbuf, item); + delitem(pagbuf, i); + continue; + } + i += 2; + } + lseek(pagf, blkno*PBLKSIZ, 0); + write(pagf, pagbuf, PBLKSIZ); + lseek(pagf, (blkno+hmask+1)*PBLKSIZ, 0); + write(pagf, ovfbuf, PBLKSIZ); + setbit(); + goto loop; +} + +datum +firstkey() +{ + return(firsthash(0L)); +} + +datum +nextkey(key) +datum key; +{ + register i; + datum item, bitem; + long hash; + int f; + + hash = calchash(key); + dbm_access(hash); + f = 1; + for(i=0;; i+=2) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + break; + if(cmpdatum(key, item) <= 0) + continue; + if(f || cmpdatum(bitem, item) < 0) { + bitem = item; + f = 0; + } + } + if(f == 0) + return(bitem); + hash = hashinc(hash); + if(hash == 0) + return(item); + return(firsthash(hash)); +} + +datum +firsthash(hash) +long hash; +{ + register i; + datum item, bitem; + +loop: + dbm_access(hash); + bitem = makdatum(pagbuf, 0); + for(i=2;; i+=2) { + item = makdatum(pagbuf, i); + if(item.dptr == NULL) + break; + if(cmpdatum(bitem, item) < 0) + bitem = item; + } + if(bitem.dptr != NULL) + return(bitem); + hash = hashinc(hash); + if(hash == 0) + return(item); + goto loop; +} + +dbm_access(hash) +long hash; +{ + static long oldb = -1; + + for(hmask=0;; hmask=(hmask<<1)+1) { + blkno = hash & hmask; + bitno = blkno + hmask; + if(getbit() == 0) + break; + } + if(blkno != oldb) { + clrbuf(pagbuf, PBLKSIZ); + lseek(pagf, blkno*PBLKSIZ, 0); + read(pagf, pagbuf, PBLKSIZ); + chkblk(pagbuf); + oldb = blkno; + } +} + +getbit() +{ + long bn; + register b, i, n; + static oldb = -1; + + if(bitno > maxbno) + return(0); + n = bitno % BYTESIZ; + bn = bitno / BYTESIZ; + i = bn % DBLKSIZ; + b = bn / DBLKSIZ; + if(b != oldb) { + clrbuf(dirbuf, DBLKSIZ); + lseek(dirf, (long)b*DBLKSIZ, 0); + read(dirf, dirbuf, DBLKSIZ); + oldb = b; + } + if(dirbuf[i] & (1< maxbno) { + maxbno = bitno; + getbit(); + } + n = bitno % BYTESIZ; + bn = bitno / BYTESIZ; + i = bn % DBLKSIZ; + b = bn / DBLKSIZ; + dirbuf[i] |= 1<= sp[0]) + goto null; + t = PBLKSIZ; + if(n > 0) + t = sp[n+1-1]; + item.dptr = buf+sp[n+1]; + item.dsize = t - sp[n+1]; + return(item); + +null: + item.dptr = NULL; + item.dsize = 0; + return(item); +} + +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); +} + +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, +}; +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, +}; + +long +hashinc(hash) +long hash; +{ + long bit; + + hash &= hmask; + bit = hmask+1; + for(;;) { + bit >>= 1; + if(bit == 0) + return(0L); + if((hash&bit) == 0) + return(hash|bit); + hash &= ~bit; + } +} + +long +calchash(item) +datum item; +{ + register i, j, f; + long hashl; + int hashi; + + hashl = 0; + hashi = 0; + for(i=0; i>= 4; + } + } + return(hashl); +} + +delitem(buf, n) +char buf[PBLKSIZ]; +{ + register short *sp; + register i1, i2, i3; + + sp = (short *)buf; + if(n < 0 || n >= sp[0]) + goto bad; + i1 = sp[n+1]; + i2 = PBLKSIZ; + if(n > 0) + i2 = sp[n+1-1]; + i3 = sp[sp[0]+1-1]; + if(i2 > i1) + while(i1 > i3) { + i1--; + i2--; + buf[i2] = buf[i1]; + buf[i1] = 0; + } + i2 -= i1; + for(i1=n+1; i1 0) + i1 = sp[sp[0]+1-1]; + i1 -= item.dsize; + i2 = (sp[0]+2) * sizeof(short); + if(i1 <= i2) + return(-1); + sp[sp[0]+1] = i1; + for(i2=0; i2 t) + goto bad; + t = sp[i+1]; + } + if(t < (sp[0]+1)*sizeof(short)) + goto bad; + return; + +bad: + printf("bad block\n"); + abort(); + clrbuf(buf, PBLKSIZ); +} diff --git a/usr/src/lib/libdbm/dbm.h b/usr/src/lib/libdbm/dbm.h new file mode 100644 index 0000000000..2fb0a6c0bc --- /dev/null +++ b/usr/src/lib/libdbm/dbm.h @@ -0,0 +1,30 @@ +#define PBLKSIZ 512 +#define DBLKSIZ 4096 +#define BYTESIZ 8 +#define NULL ((char *) 0) + +long bitno; +long maxbno; +long blkno; +long hmask; + +char pagbuf[PBLKSIZ]; +char dirbuf[DBLKSIZ]; + +int dirf; +int pagf; + +typedef struct +{ + char *dptr; + int dsize; +} datum; + +datum fetch(); +datum makdatum(); +datum firstkey(); +datum nextkey(); +datum firsthash(); +long calchash(); +long hashinc(); + diff --git a/usr/src/lib/libm/atan.c b/usr/src/lib/libm/atan.c new file mode 100644 index 0000000000..3c8d07ed4e --- /dev/null +++ b/usr/src/lib/libm/atan.c @@ -0,0 +1,111 @@ + +/* + floating-point arctangent + + atan returns the value of the arctangent of its + argument in the range [-pi/2,pi/2]. + + atan2 returns the arctangent of arg1/arg2 + in the range [-pi,pi]. + + there are no error returns. + + coefficients are #5077 from Hart & Cheney. (19.56D) +*/ + + +double static sq2p1 =2.414213562373095048802e0; +static double sq2m1 = .414213562373095048802e0; +static double pio2 =1.570796326794896619231e0; +static double pio4 = .785398163397448309615e0; +static double p4 = .161536412982230228262e2; +static double p3 = .26842548195503973794141e3; +static double p2 = .11530293515404850115428136e4; +static double p1 = .178040631643319697105464587e4; +static double p0 = .89678597403663861959987488e3; +static double q4 = .5895697050844462222791e2; +static double q3 = .536265374031215315104235e3; +static double q2 = .16667838148816337184521798e4; +static double q1 = .207933497444540981287275926e4; +static double q0 = .89678597403663861962481162e3; + + +/* + atan makes its argument positive and + calls the inner routine satan. +*/ + +double +atan(arg) +double arg; +{ + double satan(); + + if(arg>0) + return(satan(arg)); + else + return(-satan(-arg)); +} + + +/* + atan2 discovers what quadrant the angle + is in and calls atan. +*/ + +double +atan2(arg1,arg2) +double arg1,arg2; +{ + double satan(); + + if((arg1+arg2)==arg1) + if(arg1 >= 0.) return(pio2); + else return(-pio2); + else if(arg2 <0.) + if(arg1 >= 0.) + return(pio2+pio2 - satan(-arg1/arg2)); + else + return(-pio2-pio2 + satan(arg1/arg2)); + else if(arg1>0) + return(satan(arg1/arg2)); + else + return(-satan(-arg1/arg2)); +} + +/* + satan reduces its argument (known to be positive) + to the range [0,0.414...] and calls xatan. +*/ + +static double +satan(arg) +double arg; +{ + double xatan(); + + if(arg < sq2m1) + return(xatan(arg)); + else if(arg > sq2p1) + return(pio2 - xatan(1.0/arg)); + else + return(pio4 + xatan((arg-1.0)/(arg+1.0))); +} + +/* + xatan evaluates a series valid in the + range [-0.414...,+0.414...]. +*/ + +static double +xatan(arg) +double arg; +{ + double argsq; + double value; + + argsq = arg*arg; + value = ((((p4*argsq + p3)*argsq + p2)*argsq + p1)*argsq + p0); + value = value/(((((argsq + q4)*argsq + q3)*argsq + q2)*argsq + q1)*argsq + q0); + return(value*arg); +} diff --git a/usr/src/lib/libm/erf.c b/usr/src/lib/libm/erf.c new file mode 100644 index 0000000000..b724b905b4 --- /dev/null +++ b/usr/src/lib/libm/erf.c @@ -0,0 +1,116 @@ +/* + C program for floating point error function + + erf(x) returns the error function of its argument + erfc(x) returns 1.0-erf(x) + + erf(x) is defined by + ${2 over sqrt(pi)} int from 0 to x e sup {-t sup 2} dt$ + + the entry for erfc is provided because of the + extreme loss of relative accuracy if erf(x) is + called for large x and the result subtracted + from 1. (e.g. for x= 10, 12 places are lost). + + There are no error returns. + + Calls exp. + + Coefficients for large x are #5667 from Hart & Cheney (18.72D). +*/ + +#define M 7 +#define N 9 +int errno; +static double torp = 1.1283791670955125738961589031; +static double p1[] = { + 0.804373630960840172832162e5, + 0.740407142710151470082064e4, + 0.301782788536507577809226e4, + 0.380140318123903008244444e2, + 0.143383842191748205576712e2, + -.288805137207594084924010e0, + 0.007547728033418631287834e0, +}; +static double q1[] = { + 0.804373630960840172826266e5, + 0.342165257924628539769006e5, + 0.637960017324428279487120e4, + 0.658070155459240506326937e3, + 0.380190713951939403753468e2, + 0.100000000000000000000000e1, + 0.0, +}; +static double p2[] = { + 0.18263348842295112592168999e4, + 0.28980293292167655611275846e4, + 0.2320439590251635247384768711e4, + 0.1143262070703886173606073338e4, + 0.3685196154710010637133875746e3, + 0.7708161730368428609781633646e2, + 0.9675807882987265400604202961e1, + 0.5641877825507397413087057563e0, + 0.0, +}; +static double q2[] = { + 0.18263348842295112595576438e4, + 0.495882756472114071495438422e4, + 0.60895424232724435504633068e4, + 0.4429612803883682726711528526e4, + 0.2094384367789539593790281779e4, + 0.6617361207107653469211984771e3, + 0.1371255960500622202878443578e3, + 0.1714980943627607849376131193e2, + 1.0, +}; + +double +erf(arg) double arg;{ + double erfc(); + int sign; + double argsq; + double d, n; + int i; + + errno = 0; + sign = 1; + if(arg < 0.){ + arg = -arg; + sign = -1; + } + if(arg < 0.5){ + argsq = arg*arg; + for(n=0,d=0,i=M-1; i>=0; i--){ + n = n*argsq + p1[i]; + d = d*argsq + q1[i]; + } + return(sign*torp*arg*n/d); + } + if(arg >= 10.) + return(sign*1.); + return(sign*(1. - erfc(arg))); +} + +double +erfc(arg) double arg;{ + double erf(); + double exp(); + double n, d; + int i; + + errno = 0; + if(arg < 0.) + return(2. - erfc(-arg)); +/* + if(arg < 0.5) + return(1. - erf(arg)); +*/ + if(arg >= 10.) + return(0.); + + for(n=0,d=0,i=N-1; i>=0; i--){ + n = n*arg + p2[i]; + d = d*arg + q2[i]; + } + return(exp(-arg*arg)*n/d); +} diff --git a/usr/src/lib/libm/exp.c b/usr/src/lib/libm/exp.c new file mode 100644 index 0000000000..84d28f0550 --- /dev/null +++ b/usr/src/lib/libm/exp.c @@ -0,0 +1,45 @@ +/* + exp returns the exponential function of its + floating-point argument. + + The coefficients are #1069 from Hart and Cheney. (22.35D) +*/ + +#include +#include + +int errno; +static double p0 = .2080384346694663001443843411e7; +static double p1 = .3028697169744036299076048876e5; +static double p2 = .6061485330061080841615584556e2; +static double q0 = .6002720360238832528230907598e7; +static double q1 = .3277251518082914423057964422e6; +static double q2 = .1749287689093076403844945335e4; +static double log2e = 1.4426950408889634073599247; +static double sqrt2 = 1.4142135623730950488016887; +static double maxf = 10000; + +double +exp(arg) +double arg; +{ + double fract; + double temp1, temp2, xsq; + int ent; + + if(arg == 0.) + return(1.); + if(arg < -maxf) + return(0.); + if(arg > maxf) { + errno = ERANGE; + return(HUGE); + } + arg *= log2e; + ent = floor(arg); + fract = (arg-ent) - 0.5; + xsq = fract*fract; + temp1 = ((p2*xsq+p1)*xsq+p0)*fract; + temp2 = ((1.0*xsq+q2)*xsq+q1)*xsq + q0; + return(ldexp(sqrt2*(temp2+temp1)/(temp2-temp1), ent)); +} diff --git a/usr/src/lib/libm/fabs.c b/usr/src/lib/libm/fabs.c new file mode 100644 index 0000000000..f05d5981fa --- /dev/null +++ b/usr/src/lib/libm/fabs.c @@ -0,0 +1,9 @@ +double +fabs(arg) +double arg; +{ + + if(arg < 0.) + arg = -arg; + return(arg); +} diff --git a/usr/src/lib/libm/floor.c b/usr/src/lib/libm/floor.c new file mode 100644 index 0000000000..6c4aa70128 --- /dev/null +++ b/usr/src/lib/libm/floor.c @@ -0,0 +1,30 @@ +/* + * floor and ceil-- greatest integer <= arg + * (resp least >=) + */ + +double modf(); + +double +floor(d) +double d; +{ + double fract; + + if (d<0.0) { + d = -d; + fract = modf(d, &d); + if (fract != 0.0) + d += 1; + d = -d; + } else + modf(d, &d); + return(d); +} + +double +ceil(d) +double d; +{ + return(-floor(-d)); +} diff --git a/usr/src/lib/libm/hypot.c b/usr/src/lib/libm/hypot.c new file mode 100644 index 0000000000..73d009f723 --- /dev/null +++ b/usr/src/lib/libm/hypot.c @@ -0,0 +1,41 @@ +/* + * sqrt(a^2 + b^2) + * (but carefully) + */ + +double sqrt(); +double +hypot(a,b) +double a,b; +{ + double t; + if(a<0) a = -a; + if(b<0) b = -b; + if(a > b) { + t = a; + a = b; + b = t; + } + if(b==0) return(0.); + a /= b; + /* + * pathological overflow possible + * in the next line. + */ + return(b*sqrt(1. + a*a)); +} + +struct complex +{ + double r; + double i; +}; + +double +cabs(arg) +struct complex arg; +{ + double hypot(); + + return(hypot(arg.r, arg.i)); +} diff --git a/usr/src/lib/libm/j0.c b/usr/src/lib/libm/j0.c new file mode 100644 index 0000000000..2b2eb5448c --- /dev/null +++ b/usr/src/lib/libm/j0.c @@ -0,0 +1,187 @@ +/* + floating point Bessel's function + of the first and second kinds + of order zero + + j0(x) returns the value of J0(x) + for all real values of x. + + There are no error returns. + Calls sin, cos, sqrt. + + There is a niggling bug in J0 which + causes errors up to 2e-16 for x in the + interval [-8,8]. + The bug is caused by an inappropriate order + of summation of the series. rhm will fix it + someday. + + Coefficients are from Hart & Cheney. + #5849 (19.22D) + #6549 (19.25D) + #6949 (19.41D) + + y0(x) returns the value of Y0(x) + for positive real values of x. + For x<=0, error number EDOM is set and a + large negative value is returned. + + Calls sin, cos, sqrt, log, j0. + + The values of Y0 have not been checked + to more than ten places. + + Coefficients are from Hart & Cheney. + #6245 (18.78D) + #6549 (19.25D) + #6949 (19.41D) +*/ + +#include +#include + +int errno; +static double pzero, qzero; +static double tpi = .6366197723675813430755350535e0; +static double pio4 = .7853981633974483096156608458e0; +static double p1[] = { + 0.4933787251794133561816813446e21, + -.1179157629107610536038440800e21, + 0.6382059341072356562289432465e19, + -.1367620353088171386865416609e18, + 0.1434354939140344111664316553e16, + -.8085222034853793871199468171e13, + 0.2507158285536881945555156435e11, + -.4050412371833132706360663322e8, + 0.2685786856980014981415848441e5, +}; +static double q1[] = { + 0.4933787251794133562113278438e21, + 0.5428918384092285160200195092e19, + 0.3024635616709462698627330784e17, + 0.1127756739679798507056031594e15, + 0.3123043114941213172572469442e12, + 0.6699987672982239671814028660e9, + 0.1114636098462985378182402543e7, + 0.1363063652328970604442810507e4, + 1.0 +}; +static double p2[] = { + 0.5393485083869438325262122897e7, + 0.1233238476817638145232406055e8, + 0.8413041456550439208464315611e7, + 0.2016135283049983642487182349e7, + 0.1539826532623911470917825993e6, + 0.2485271928957404011288128951e4, + 0.0, +}; +static double q2[] = { + 0.5393485083869438325560444960e7, + 0.1233831022786324960844856182e8, + 0.8426449050629797331554404810e7, + 0.2025066801570134013891035236e7, + 0.1560017276940030940592769933e6, + 0.2615700736920839685159081813e4, + 1.0, +}; +static double p3[] = { + -.3984617357595222463506790588e4, + -.1038141698748464093880530341e5, + -.8239066313485606568803548860e4, + -.2365956170779108192723612816e4, + -.2262630641933704113967255053e3, + -.4887199395841261531199129300e1, + 0.0, +}; +static double q3[] = { + 0.2550155108860942382983170882e6, + 0.6667454239319826986004038103e6, + 0.5332913634216897168722255057e6, + 0.1560213206679291652539287109e6, + 0.1570489191515395519392882766e5, + 0.4087714673983499223402830260e3, + 1.0, +}; +static double p4[] = { + -.2750286678629109583701933175e20, + 0.6587473275719554925999402049e20, + -.5247065581112764941297350814e19, + 0.1375624316399344078571335453e18, + -.1648605817185729473122082537e16, + 0.1025520859686394284509167421e14, + -.3436371222979040378171030138e11, + 0.5915213465686889654273830069e8, + -.4137035497933148554125235152e5, +}; +static double q4[] = { + 0.3726458838986165881989980e21, + 0.4192417043410839973904769661e19, + 0.2392883043499781857439356652e17, + 0.9162038034075185262489147968e14, + 0.2613065755041081249568482092e12, + 0.5795122640700729537480087915e9, + 0.1001702641288906265666651753e7, + 0.1282452772478993804176329391e4, + 1.0, +}; + +double +j0(arg) double arg;{ + double argsq, n, d; + double sin(), cos(), sqrt(); + int i; + + if(arg < 0.) arg = -arg; + if(arg > 8.){ + asympt(arg); + n = arg - pio4; + return(sqrt(tpi/arg)*(pzero*cos(n) - qzero*sin(n))); + } + argsq = arg*arg; + for(n=0,d=0,i=8;i>=0;i--){ + n = n*argsq + p1[i]; + d = d*argsq + q1[i]; + } + return(n/d); +} + +double +y0(arg) double arg;{ + double argsq, n, d; + double sin(), cos(), sqrt(), log(), j0(); + int i; + + errno = 0; + if(arg <= 0.){ + errno = EDOM; + return(-HUGE); + } + if(arg > 8.){ + asympt(arg); + n = arg - pio4; + return(sqrt(tpi/arg)*(pzero*sin(n) + qzero*cos(n))); + } + argsq = arg*arg; + for(n=0,d=0,i=8;i>=0;i--){ + n = n*argsq + p4[i]; + d = d*argsq + q4[i]; + } + return(n/d + tpi*j0(arg)*log(arg)); +} + +static +asympt(arg) double arg;{ + double zsq, n, d; + int i; + zsq = 64./(arg*arg); + for(n=0,d=0,i=6;i>=0;i--){ + n = n*zsq + p2[i]; + d = d*zsq + q2[i]; + } + pzero = n/d; + for(n=0,d=0,i=6;i>=0;i--){ + n = n*zsq + p3[i]; + d = d*zsq + q3[i]; + } + qzero = (8./arg)*(n/d); +} diff --git a/usr/src/lib/libm/j1.c b/usr/src/lib/libm/j1.c new file mode 100644 index 0000000000..13b397fcf6 --- /dev/null +++ b/usr/src/lib/libm/j1.c @@ -0,0 +1,193 @@ +/* + floating point Bessel's function + of the first and second kinds + of order one + + j1(x) returns the value of J1(x) + for all real values of x. + + There are no error returns. + Calls sin, cos, sqrt. + + There is a niggling bug in J1 which + causes errors up to 2e-16 for x in the + interval [-8,8]. + The bug is caused by an inappropriate order + of summation of the series. rhm will fix it + someday. + + Coefficients are from Hart & Cheney. + #6050 (20.98D) + #6750 (19.19D) + #7150 (19.35D) + + y1(x) returns the value of Y1(x) + for positive real values of x. + For x<=0, error number EDOM is set and a + large negative value is returned. + + Calls sin, cos, sqrt, log, j1. + + The values of Y1 have not been checked + to more than ten places. + + Coefficients are from Hart & Cheney. + #6447 (22.18D) + #6750 (19.19D) + #7150 (19.35D) +*/ + +#include +#include + +int errno; +static double pzero, qzero; +static double tpi = .6366197723675813430755350535e0; +static double pio4 = .7853981633974483096156608458e0; +static double p1[] = { + 0.581199354001606143928050809e21, + -.6672106568924916298020941484e20, + 0.2316433580634002297931815435e19, + -.3588817569910106050743641413e17, + 0.2908795263834775409737601689e15, + -.1322983480332126453125473247e13, + 0.3413234182301700539091292655e10, + -.4695753530642995859767162166e7, + 0.2701122710892323414856790990e4, +}; +static double q1[] = { + 0.1162398708003212287858529400e22, + 0.1185770712190320999837113348e20, + 0.6092061398917521746105196863e17, + 0.2081661221307607351240184229e15, + 0.5243710262167649715406728642e12, + 0.1013863514358673989967045588e10, + 0.1501793594998585505921097578e7, + 0.1606931573481487801970916749e4, + 1.0, +}; +static double p2[] = { + -.4435757816794127857114720794e7, + -.9942246505077641195658377899e7, + -.6603373248364939109255245434e7, + -.1523529351181137383255105722e7, + -.1098240554345934672737413139e6, + -.1611616644324610116477412898e4, + 0.0, +}; +static double q2[] = { + -.4435757816794127856828016962e7, + -.9934124389934585658967556309e7, + -.6585339479723087072826915069e7, + -.1511809506634160881644546358e7, + -.1072638599110382011903063867e6, + -.1455009440190496182453565068e4, + 1.0, +}; +static double p3[] = { + 0.3322091340985722351859704442e5, + 0.8514516067533570196555001171e5, + 0.6617883658127083517939992166e5, + 0.1849426287322386679652009819e5, + 0.1706375429020768002061283546e4, + 0.3526513384663603218592175580e2, + 0.0, +}; +static double q3[] = { + 0.7087128194102874357377502472e6, + 0.1819458042243997298924553839e7, + 0.1419460669603720892855755253e7, + 0.4002944358226697511708610813e6, + 0.3789022974577220264142952256e5, + 0.8638367769604990967475517183e3, + 1.0, +}; +static double p4[] = { + -.9963753424306922225996744354e23, + 0.2655473831434854326894248968e23, + -.1212297555414509577913561535e22, + 0.2193107339917797592111427556e20, + -.1965887462722140658820322248e18, + 0.9569930239921683481121552788e15, + -.2580681702194450950541426399e13, + 0.3639488548124002058278999428e10, + -.2108847540133123652824139923e7, + 0.0, +}; +static double q4[] = { + 0.5082067366941243245314424152e24, + 0.5435310377188854170800653097e22, + 0.2954987935897148674290758119e20, + 0.1082258259408819552553850180e18, + 0.2976632125647276729292742282e15, + 0.6465340881265275571961681500e12, + 0.1128686837169442121732366891e10, + 0.1563282754899580604737366452e7, + 0.1612361029677000859332072312e4, + 1.0, +}; + +double +j1(arg) double arg;{ + double xsq, n, d, x; + double sin(), cos(), sqrt(); + int i; + + x = arg; + if(x < 0.) x = -x; + if(x > 8.){ + asympt(x); + n = x - 3.*pio4; + n = sqrt(tpi/x)*(pzero*cos(n) - qzero*sin(n)); + if(arg <0.) n = -n; + return(n); + } + xsq = x*x; + for(n=0,d=0,i=8;i>=0;i--){ + n = n*xsq + p1[i]; + d = d*xsq + q1[i]; + } + return(arg*n/d); +} + +double +y1(arg) double arg;{ + double xsq, n, d, x; + double sin(), cos(), sqrt(), log(), j1(); + int i; + + errno = 0; + x = arg; + if(x <= 0.){ + errno = EDOM; + return(-HUGE); + } + if(x > 8.){ + asympt(x); + n = x - 3*pio4; + return(sqrt(tpi/x)*(pzero*sin(n) + qzero*cos(n))); + } + xsq = x*x; + for(n=0,d=0,i=9;i>=0;i--){ + n = n*xsq + p4[i]; + d = d*xsq + q4[i]; + } + return(x*n/d + tpi*(j1(x)*log(x)-1./x)); +} + +static +asympt(arg) double arg;{ + double zsq, n, d; + int i; + zsq = 64./(arg*arg); + for(n=0,d=0,i=6;i>=0;i--){ + n = n*zsq + p2[i]; + d = d*zsq + q2[i]; + } + pzero = n/d; + for(n=0,d=0,i=6;i>=0;i--){ + n = n*zsq + p3[i]; + d = d*zsq + q3[i]; + } + qzero = (8./arg)*(n/d); +} diff --git a/usr/src/lib/libm/jn.c b/usr/src/lib/libm/jn.c new file mode 100644 index 0000000000..f9713a084b --- /dev/null +++ b/usr/src/lib/libm/jn.c @@ -0,0 +1,107 @@ +/* + floating point Bessel's function of + the first and second kinds and of + integer order. + + int n; + double x; + jn(n,x); + + returns the value of Jn(x) for all + integer values of n and all real values + of x. + + There are no error returns. + Calls j0, j1. + + For n=0, j0(x) is called, + for n=1, j1(x) is called, + for nx, a continued fraction approximation to + j(n,x)/j(n-1,x) is evaluated and then backward + recursion is used starting from a supposed value + for j(n,x). The resulting value of j(0,x) is + compared with the actual value to correct the + supposed value of j(n,x). + + yn(n,x) is similar in all respects, except + that forward recursion is used for all + values of n>1. +*/ + +#include +#include + +int errno; + +double +jn(n,x) int n; double x;{ + int i; + double a, b, temp; + double xsq, t; + double j0(), j1(); + + if(n<0){ + n = -n; + x = -x; + } + if(n==0) return(j0(x)); + if(n==1) return(j1(x)); + if(x == 0.) return(0.); + if(n>x) goto recurs; + + a = j0(x); + b = j1(x); + for(i=1;in;i--){ + t = xsq/(2.*i - t); + } + t = x/(2.*n-t); + + a = t; + b = 1; + for(i=n-1;i>0;i--){ + temp = b; + b = (2.*i/x)*b - a; + a = temp; + } + return(t*j0(x)/b); +} + +double +yn(n,x) int n; double x;{ + int i; + int sign; + double a, b, temp; + double y0(), y1(); + + if (x <= 0) { + errno = EDOM; + return(-HUGE); + } + sign = 1; + if(n<0){ + n = -n; + if(n%2 == 1) sign = -1; + } + if(n==0) return(y0(x)); + if(n==1) return(sign*y1(x)); + + a = y0(x); + b = y1(x); + for(i=1;i +#include + +int errno; +double frexp(); +static double log2 = 0.693147180559945309e0; +static double ln10 = 2.302585092994045684; +static double sqrto2 = 0.707106781186547524e0; +static double p0 = -.240139179559210510e2; +static double p1 = 0.309572928215376501e2; +static double p2 = -.963769093368686593e1; +static double p3 = 0.421087371217979714e0; +static double q0 = -.120069589779605255e2; +static double q1 = 0.194809660700889731e2; +static double q2 = -.891110902798312337e1; + +double +log(arg) +double arg; +{ + double x,z, zsq, temp; + int exp; + + if(arg <= 0.) { + errno = EDOM; + return(-HUGE); + } + x = frexp(arg,&exp); + while(x<0.5) { + x = x*2; + exp = exp-1; + } + if(x +int errno; +double log(), exp(); + +double +pow(arg1,arg2) +double arg1, arg2; +{ + double temp; + long l; + + if(arg1 <= 0.) { + if(arg1 == 0.) { + if(arg2 <= 0.) + goto domain; + return(0.); + } + l = arg2; + if(l != arg2) + goto domain; + temp = exp(arg2 * log(-arg1)); + if(l & 1) + temp = -temp; + return(temp); + } + return(exp(arg2 * log(arg1))); + +domain: + errno = EDOM; + return(0.); +} diff --git a/usr/src/lib/libm/sin.c b/usr/src/lib/libm/sin.c new file mode 100644 index 0000000000..3f76374215 --- /dev/null +++ b/usr/src/lib/libm/sin.c @@ -0,0 +1,74 @@ +/* + C program for floating point sin/cos. + Calls modf. + There are no error exits. + Coefficients are #3370 from Hart & Cheney (18.80D). +*/ + +static double twoopi = 0.63661977236758134308; +static double p0 = .1357884097877375669092680e8; +static double p1 = -.4942908100902844161158627e7; +static double p2 = .4401030535375266501944918e6; +static double p3 = -.1384727249982452873054457e5; +static double p4 = .1459688406665768722226959e3; +static double q0 = .8644558652922534429915149e7; +static double q1 = .4081792252343299749395779e6; +static double q2 = .9463096101538208180571257e4; +static double q3 = .1326534908786136358911494e3; + +double +cos(arg) +double arg; +{ + double sinus(); + if(arg<0) + arg = -arg; + return(sinus(arg, 1)); +} + +double +sin(arg) +double arg; +{ + double sinus(); + return(sinus(arg, 0)); +} + +static double +sinus(arg, quad) +double arg; +int quad; +{ + double modf(); + double e, f; + double ysq; + double x,y; + int k; + double temp1, temp2; + + x = arg; + if(x<0) { + x = -x; + quad = quad + 2; + } + x = x*twoopi; /*underflow?*/ + if(x>32764){ + y = modf(x,&e); + e = e + quad; + modf(0.25*e,&f); + quad = e - 4*f; + }else{ + k = x; + y = x - k; + quad = (quad + k) & 03; + } + if (quad & 01) + y = 1-y; + if(quad > 1) + y = -y; + + ysq = y*y; + temp1 = ((((p4*ysq+p3)*ysq+p2)*ysq+p1)*ysq+p0)*y; + temp2 = ((((ysq+q3)*ysq+q2)*ysq+q1)*ysq+q0); + return(temp1/temp2); +} diff --git a/usr/src/lib/libm/sinh.c b/usr/src/lib/libm/sinh.c new file mode 100644 index 0000000000..e0e88629fd --- /dev/null +++ b/usr/src/lib/libm/sinh.c @@ -0,0 +1,67 @@ +/* + sinh(arg) returns the hyperbolic sine of its floating- + point argument. + + The exponential function is called for arguments + greater in magnitude than 0.5. + + A series is used for arguments smaller in magnitude than 0.5. + The coefficients are #2029 from Hart & Cheney. (20.36D) + + cosh(arg) is computed from the exponential function for + all arguments. +*/ + +double exp(); + +static double p0 = -0.6307673640497716991184787251e+6; +static double p1 = -0.8991272022039509355398013511e+5; +static double p2 = -0.2894211355989563807284660366e+4; +static double p3 = -0.2630563213397497062819489e+2; +static double q0 = -0.6307673640497716991212077277e+6; +static double q1 = 0.1521517378790019070696485176e+5; +static double q2 = -0.173678953558233699533450911e+3; + +double +sinh(arg) +double arg; +{ + double temp, argsq; + register sign; + + sign = 1; + if(arg < 0) { + arg = - arg; + sign = -1; + } + + if(arg > 21.) { + temp = exp(arg)/2; + if (sign>0) + return(temp); + else + return(-temp); + } + + if(arg > 0.5) { + return(sign*(exp(arg) - exp(-arg))/2); + } + + argsq = arg*arg; + temp = (((p3*argsq+p2)*argsq+p1)*argsq+p0)*arg; + temp /= (((argsq+q2)*argsq+q1)*argsq+q0); + return(sign*temp); +} + +double +cosh(arg) +double arg; +{ + if(arg < 0) + arg = - arg; + if(arg > 21.) { + return(exp(arg)/2); + } + + return((exp(arg) + exp(-arg))/2); +} diff --git a/usr/src/lib/libm/sqrt.c b/usr/src/lib/libm/sqrt.c new file mode 100644 index 0000000000..028233325d --- /dev/null +++ b/usr/src/lib/libm/sqrt.c @@ -0,0 +1,56 @@ +/* + sqrt returns the square root of its floating + point argument. Newton's method. + + calls frexp +*/ + +#include + +int errno; +double frexp(); + +double +sqrt(arg) +double arg; +{ + double x, temp; + int exp; + int i; + + if(arg <= 0.) { + if(arg < 0.) + errno = EDOM; + return(0.); + } + x = frexp(arg,&exp); + while(x < 0.5) { + x *= 2; + exp--; + } + /* + * NOTE + * this wont work on 1's comp + */ + if(exp & 1) { + x *= 2; + exp--; + } + temp = 0.5*(1.0+x); + + while(exp > 60) { + temp *= (1L<<30); + exp -= 60; + } + while(exp < -60) { + temp /= (1L<<30); + exp += 60; + } + if(exp >= 0) + temp *= 1L << (exp/2); + else + temp /= 1L << (-exp/2); + for(i=0; i<=4; i++) + temp = 0.5*(temp + arg/temp); + return(temp); +} diff --git a/usr/src/lib/libm/tan.c b/usr/src/lib/libm/tan.c new file mode 100644 index 0000000000..7df1719423 --- /dev/null +++ b/usr/src/lib/libm/tan.c @@ -0,0 +1,73 @@ +/* + floating point tangent + + A series is used after range reduction. + Coefficients are #4285 from Hart & Cheney. (19.74D) +*/ + +#include +#include + +int errno; +static double invpi = 1.27323954473516268; +static double p0 = -0.1306820264754825668269611177e+5; +static double p1 = 0.1055970901714953193602353981e+4; +static double p2 = -0.1550685653483266376941705728e+2; +static double p3 = 0.3422554387241003435328470489e-1; +static double p4 = 0.3386638642677172096076369e-4; +static double q0 = -0.1663895238947119001851464661e+5; +static double q1 = 0.4765751362916483698926655581e+4; +static double q2 = -0.1555033164031709966900124574e+3; + +double +tan(arg) +double arg; +{ + double modf(); + double sign, temp, e, x, xsq; + int flag, i; + + flag = 0; + sign = 1.; + if(arg < 0.){ + arg = -arg; + sign = -1.; + } + arg = arg*invpi; /*overflow?*/ + x = modf(arg,&e); + i = e; + switch(i%4) { + case 1: + x = 1. - x; + flag = 1; + break; + + case 2: + sign = - sign; + flag = 1; + break; + + case 3: + x = 1. - x; + sign = - sign; + break; + + case 0: + break; + } + + xsq = x*x; + temp = ((((p4*xsq+p3)*xsq+p2)*xsq+p1)*xsq+p0)*x; + temp = temp/(((1.0*xsq+q2)*xsq+q1)*xsq+q0); + + if(flag == 1) { + if(temp == 0.) { + errno = ERANGE; + if (sign>0) + return(HUGE); + return(-HUGE); + } + temp = 1./temp; + } + return(sign*temp); +} diff --git a/usr/src/lib/libm/tanh.c b/usr/src/lib/libm/tanh.c new file mode 100644 index 0000000000..3f83a3fe7a --- /dev/null +++ b/usr/src/lib/libm/tanh.c @@ -0,0 +1,27 @@ +/* + tanh(arg) computes the hyperbolic tangent of its floating + point argument. + + sinh and cosh are called except for large arguments, which + would cause overflow improperly. +*/ + +double sinh(), cosh(); + +double +tanh(arg) +double arg; +{ + double sign; + + sign = 1.; + if(arg < 0.){ + arg = -arg; + sign = -1.; + } + + if(arg > 21.) + return(sign); + + return(sign*sinh(arg)/cosh(arg)); +} diff --git a/usr/src/lib/libmp/gcd.c b/usr/src/lib/libmp/gcd.c new file mode 100644 index 0000000000..cedad0ab58 --- /dev/null +++ b/usr/src/lib/libmp/gcd.c @@ -0,0 +1,46 @@ +#include +gcd(a,b,c) MINT *a,*b,*c; +{ MINT x,y,z,w; + x.len=y.len=z.len=w.len=0; + move(a,&x); + move(b,&y); + while(y.len!=0) + { mdiv(&x,&y,&w,&z); + move(&y,&x); + move(&z,&y); + } + move(&x,c); + xfree(&x); + xfree(&y); + xfree(&z); + xfree(&w); + return; +} +invert(a, b, c) MINT *a, *b, *c; +{ MINT x, y, z, w, Anew, Aold; + int i = 0; + x.len = y.len = z.len = w.len = Aold.len = 0; + Anew.len = 1; + Anew.val = xalloc(1); + *Anew.val = 1; + move(b, &x); + move(a, &y); + while(y.len != 0) + { mdiv(&x, &y, &w, &z); + move(&Anew, &x); + mult(&w, &Anew, &Anew); + madd(&Anew, &Aold, &Anew); + move(&x, &Aold); + move(&y, &x); + move(&z, &y); + i++; + } + move(&Aold, c); + if( (i&01) == 0) msub(b, c, c); + xfree(&x); + xfree(&y); + xfree(&z); + xfree(&w); + xfree(&Aold); + xfree(&Anew); +} diff --git a/usr/src/lib/libmp/madd.c b/usr/src/lib/libmp/madd.c new file mode 100644 index 0000000000..155d8c06ac --- /dev/null +++ b/usr/src/lib/libmp/madd.c @@ -0,0 +1,146 @@ +#include +m_add(a,b,c) struct mint *a,*b,*c; +{ int carry,i; + int x; + short *cval; + cval=xalloc(a->len+1,"m_add"); + carry=0; + for(i=0;ilen;i++) + { x=carry+a->val[i]+b->val[i]; + if(x&0100000) + { carry=1; + cval[i]=x&077777; + } + else + { carry=0; + cval[i]=x; + } + } + for(;ilen;i++) + { x=carry+a->val[i]; + if(x&0100000) cval[i]=x&077777; + else + { carry=0; + cval[i]=x; + } + + } + if(carry==1) + { cval[i]=1; + c->len=i+1; + } + else c->len=a->len; + c->val=cval; + if(c->len==0) shfree(cval); + return; +} +madd(a,b,c) struct mint *a,*b,*c; +{ struct mint x,y,z; + int sign; + x.len=a->len; + x.val=a->val; + y.len=b->len; + y.val=b->val; + z.len=0; + sign=1; + if(x.len>=0) + if(y.len>=0) + if(x.len>=y.len) m_add(&x,&y,&z); + else m_add(&y,&x,&z); + else + { y.len= -y.len; + msub(&x,&y,&z); + } + else if(y.len<=0) + { x.len = -x.len; + y.len= -y.len; + sign= -1; + madd(&x,&y,&z); + } + else + { x.len= -x.len; + msub(&y,&x,&z); + } + xfree(c); + c->val=z.val; + c->len=sign*z.len; + return; +} +m_sub(a,b,c) struct mint *a,*b,*c; +{ int x,i; + int borrow; + short one; + struct mint mone; + one=1; mone.len= 1; mone.val= &one; + c->val=xalloc(a->len,"m_sub"); + borrow=0; + for(i=0;ilen;i++) + { x=borrow+a->val[i]-b->val[i]; + if(x&0100000) + { borrow= -1; + c->val[i]=x&077777; + } + else + { borrow=0; + c->val[i]=x; + } + } + for(;ilen;i++) + { x=borrow+a->val[i]; + if(x&0100000) c->val[i]=x&077777; + else + { borrow=0; + c->val[i]=x; + } + } + if(borrow<0) + { for(i=0;ilen;i++) c->val[i] ^= 077777; + c->len=a->len; + madd(c,&mone,c); + } + for(i=a->len-1;i>=0;--i) if(c->val[i]>0) + { if(borrow==0) c->len=i+1; + else c->len= -i-1; + return; + } + shfree(c->val); + return; +} +msub(a,b,c) struct mint *a,*b,*c; +{ struct mint x,y,z; + int sign; + x.len=a->len; + y.len=b->len; + x.val=a->val; + y.val=b->val; + z.len=0; + sign=1; + if(x.len>=0) + if(y.len>=0) + if(x.len>=y.len) m_sub(&x,&y,&z); + else + { sign= -1; + msub(&y,&x,&z); + } + else + { y.len= -y.len; + madd(&x,&y,&z); + } + else if(y.len<=0) + { sign= -1; + x.len= -x.len; + y.len= -y.len; + msub(&y,&x,&z); + } + else + { x.len= -x.len; + madd(&x,&y,&z); + sign= -1; + } + if(a==c && x.len!=0) xfree(a); + else if(b==c && y.len!=0) xfree(b); + else xfree(c); + c->val=z.val; + c->len=sign*z.len; + return; +} diff --git a/usr/src/lib/libmp/mdiv.c b/usr/src/lib/libmp/mdiv.c new file mode 100644 index 0000000000..1f8a0fc950 --- /dev/null +++ b/usr/src/lib/libmp/mdiv.c @@ -0,0 +1,106 @@ +#include +mdiv(a,b,q,r) MINT *a,*b,*q,*r; +{ MINT x,y; + int sign; + sign=1; + x.val=a->val; + y.val=b->val; + x.len=a->len; + if(x.len<0) {sign= -1; x.len= -x.len;} + y.len=b->len; + if(y.len<0) {sign= -sign; y.len= -y.len;} + xfree(q); + xfree(r); + m_div(&x,&y,q,r); + if(sign==-1) + { q->len= -q->len; + r->len = - r->len; + } + return; +} +m_dsb(q,n,a,b) short *a,*b; +{ long int x,qx; + int borrow,j,u; + qx=q; + borrow=0; + for(j=0;j>15; + } + x=borrow+b[j]; + b[j]=x&077777; + if(x>>15 ==0) { return(0);} + borrow=0; + for(j=0;jlen==0) { fatal("mdiv divide by zero"); return;} + if(b->len==1) + { r->val=xalloc(1,"m_div1"); + sdiv(a,b->val[0],q,r->val); + if(r->val[0]==0) + { shfree(r->val); + r->len=0; + } + else r->len=1; + return; + } + if(a->len < b->len) + { q->len=0; + r->len=a->len; + r->val=xalloc(r->len,"m_div2"); + for(qq=0;qqlen;qq++) r->val[qq]=a->val[qq]; + return; + } + x.len=1; + x.val = &d; + n=b->len; + d=0100000L/(b->val[n-1]+1L); + mult(a,&x,&u); /*subtle: relies on fact that mult allocates extra space */ + mult(b,&x,&v); + v1=v.val[n-1]; + v2=v.val[n-2]; + qval=xalloc(a->len-n+1,"m_div3"); + for(j=a->len-n;j>=0;j--) + { qq=m_trq(v1,v2,u.val[j+n],u.val[j+n-1],u.val[j+n-2]); + if(m_dsb(qq,n,v.val,&(u.val[j]))) qq -= 1; + qval[j]=qq; + } + x.len=n; + x.val=u.val; + mcan(&x); + sdiv(&x,d,&w,(short *)&qq); + r->len=w.len; + r->val=w.val; + q->val=qval; + qq=a->len-n+1; + if(qq>0 && qval[qq-1]==0) qq -= 1; + q->len=qq; + if(qq==0) shfree(qval); + if(x.len!=0) xfree(&u); + xfree(&v); + return; +} diff --git a/usr/src/lib/libmp/mout.c b/usr/src/lib/libmp/mout.c new file mode 100644 index 0000000000..afb30a82c5 --- /dev/null +++ b/usr/src/lib/libmp/mout.c @@ -0,0 +1,141 @@ +#include +#include +m_in(a,b,f) MINT *a; FILE *f; +{ MINT x,y,ten; + int sign,c; + short qten,qy; + xfree(a); + sign=1; + ten.len=1; + ten.val= &qten; + qten=b; + x.len=0; + y.len=1; + y.val= &qy; + while((c=getc(f))!=EOF) + switch(c) + { + case '\\': getc(f); + continue; + case '\t': + case '\n': a->len *= sign; + xfree(&x); + return(0); + case ' ': + continue; + case '-': sign = -sign; + continue; + default: if(c>='0' && c<= '9') + { qy=c-'0'; + mult(&x,&ten,a); + madd(a,&y,a); + move(a,&x); + continue; + } + else + { VOID ungetc(c,stdin); + a->len *= sign; + return(0); + } + } + return(EOF); +} +m_out(a,b,f) MINT *a; FILE *f; +{ int sign,xlen,i; + short r; + MINT x; + char *obuf; + register char *bp; + sign=1; + xlen=a->len; + if(xlen<0) + { xlen= -xlen; + sign= -1; + } + if(xlen==0) + { fprintf(f,"0\n"); + return; + } + x.len=xlen; + x.val=xalloc(xlen,"m_out"); + for(i=0;ival[i]; + obuf=(char *)malloc(7*xlen); + bp=obuf+7*xlen-1; + *bp--=0; + while(x.len>0) + { for(i=0;i<10&&x.len>0;i++) + { sdiv(&x,b,&x,&r); + *bp--=r+'0'; + } + if(x.len>0) *bp--=' '; + } + if(sign==-1) *bp--='-'; + fprintf(f,"%s\n",bp+1); + free(obuf); + FREE(x) + return; +} +sdiv(a,n,q,r) MINT *a,*q; short *r; +{ MINT x,y; + int sign; + sign=1; + x.len=a->len; + x.val=a->val; + if(n<0) + { sign= -sign; + n= -n; + } + if(x.len<0) + { sign = -sign; + x.len= -x.len; + } + s_div(&x,n,&y,r); + xfree(q); + q->val=y.val; + q->len=sign*y.len; + *r = *r*sign; + return; +} +s_div(a,n,q,r) MINT *a,*q; short *r; +{ int qlen,i; + long int x; + short *qval; + x=0; + qlen=a->len; + qval=xalloc(qlen,"s_div"); + for(i=qlen-1;i>=0;i--) + { + x=x*0100000L+a->val[i]; + qval[i]=x/n; + x=x%n; + } + *r=x; + if(qval[qlen-1]==0) qlen--; + q->len=qlen; + q->val=qval; + if(qlen==0) shfree(qval); + return; +} +min(a) MINT *a; +{ + return(m_in(a,10,stdin)); +} +omin(a) MINT *a; +{ + return(m_in(a,8,stdin)); +} +mout(a) MINT *a; +{ + m_out(a,10,stdout); +} +omout(a) MINT *a; +{ + m_out(a,8,stdout); +} +fmout(a,f) MINT *a; FILE *f; +{ m_out(a,10,f); +} +fmin(a,f) MINT *a; FILE *f; +{ + return(m_in(a,10,f)); +} diff --git a/usr/src/lib/libmp/msqrt.c b/usr/src/lib/libmp/msqrt.c new file mode 100644 index 0000000000..a9545938be --- /dev/null +++ b/usr/src/lib/libmp/msqrt.c @@ -0,0 +1,37 @@ +#include +msqrt(a,b,r) MINT *a,*b,*r; +{ MINT x,junk,y; + int j; + x.len=junk.len=y.len=0; + if(a->len<0) fatal("msqrt: neg arg"); + if(a->len==0) + { b->len=0; + r->len=0; + return(0); + } + if(a->len%2==1) x.len=(1+a->len)/2; + else x.len=1+a->len/2; + x.val=xalloc(x.len,"msqrt"); + for(j=0;jlen%2==1) x.val[x.len-1]=0400; + else x.val[x.len-1]=1; + xfree(b); + xfree(r); +loop: + mdiv(a,&x,&y,&junk); + xfree(&junk); + madd(&x,&y,&y); + sdiv(&y,2,&y,(short *)&j); + if(mcmp(&x,&y)>0) + { xfree(&x); + move(&y,&x); + xfree(&y); + goto loop; + } + xfree(&y); + move(&x,b); + mult(&x,&x,&x); + msub(a,&x,r); + xfree(&x); + return(r->len); +} diff --git a/usr/src/lib/libmp/mult.c b/usr/src/lib/libmp/mult.c new file mode 100644 index 0000000000..d4d8de924b --- /dev/null +++ b/usr/src/lib/libmp/mult.c @@ -0,0 +1,87 @@ +#include +mult(a,b,c) struct mint *a,*b,*c; +{ struct mint x,y,z; + int sign; + sign = 1; + x.val=a->val; + y.val=b->val; + z.len=0; + if(a->len<0) + { x.len= -a->len; + sign= -sign; + } + else x.len=a->len; + if(b->len<0) + { y.len= -b->len; + sign= -sign; + } + else y.len=b->len; + if(x.lenlen= -z.len; + else c->len=z.len; + if(c->len==0) shfree(z.val); + else c->val=z.val; + return; +} +#define S2 x=a->val[j]; +#define S3 x=x*b->val[i-j]; +#define S4 tradd(&carry,&sum,x); +#define S5 c->val[i]=sum.yy.low&077777; +#define S6 sum.xx=sum.xx>>15; +#define S7 sum.yy.high=carry; +m_mult(a,b,c) struct mint *a,*b,*c; +{ long x; + union {long xx; struct half yy;} sum; + int carry; + int i,j; + c->val=xalloc(a->len+b->len,"m_mult"); + sum.xx=0; + for(i=0;ilen;i++) + { carry=0; + for(j=0;jlen;i++) + { carry=0; + for(j=i-b->len+1;jlen+b->len;i++) + { carry=0; + for(j=i-b->len+1;jlen;j++) + { S2 + S3 + S4 + } + S5 + S6 + S7 + } + if(c->val[i-1]!=0) + c->len=a->len+b->len; + else c->len=a->len+b->len-1; + return; +} +tradd(a,b,c) long c; int *a; union g {long xx; struct half yy;} *b; +{ + b->xx= b->xx+c; + if(b->yy.high&0100000) + { b->yy.high= b->yy.high&077777; + *a += 1; + } + return; +} diff --git a/usr/src/lib/libmp/pow.c b/usr/src/lib/libmp/pow.c new file mode 100644 index 0000000000..4a745e4cb8 --- /dev/null +++ b/usr/src/lib/libmp/pow.c @@ -0,0 +1,40 @@ +#include +pow(a,b,c,d) MINT *a,*b,*c,*d; +{ int i,j,n; + MINT x,y; + x.len=y.len=0; + xfree(d); + d->len=1; + d->val=xalloc(1,"pow"); + *d->val=1; + for(j=0;jlen;j++) + { n=b->val[b->len-j-1]; + for(i=0;i<15;i++) + { mult(d,d,&x); + mdiv(&x,c,&y,d); + if((n=n<<1)&0100000) + { mult(a,d,&x); + mdiv(&x,c,&y,d); + } + } + } + xfree(&x); + xfree(&y); + return; +} +rpow(a,n,b) MINT *a,*b; +{ MINT x,y; + int i; + x.len=1; + x.val=xalloc(1,"rpow"); + *x.val=n; + y.len=n*a->len+4; + y.val=xalloc(y.len,"rpow2"); + for(i=0;i +#include +move(a,b) MINT *a,*b; +{ int i,j; + xfree(b); + b->len=a->len; + if((i=a->len)<0) i = -i; + if(i==0) return; + b->val=xalloc(i,"move"); + for(j=0;jval[j]=a->val[j]; + return; +} +dummy(){} +short *xalloc(nint,s) char *s; +{ short *i; + i=(short *)malloc(2*(unsigned)nint+4); +#ifdef DBG + if(dbg) fprintf(stderr, "%s: %o\n",s,i); +#endif + if(i!=NULL) return(i); + fatal("mp: no free space"); + return(0); +} +fatal(s) char *s; +{ + fprintf(stderr,"%s\n",s); + VOID fflush(stdout); + sleep(2); + abort(); +} +xfree(c) MINT *c; +{ +#ifdef DBG + if(dbg) fprintf(stderr, "xfree "); +#endif + if(c->len==0) return; + shfree(c->val); + c->len=0; + return; +} +mcan(a) MINT *a; +{ int i,j; + if((i=a->len)==0) return; + else if(i<0) i= -i; + for(j=i;j>0 && a->val[j-1]==0;j--); + if(j==i) return; + if(j==0) + { xfree(a); + return; + } + if(a->len > 0) a->len=j; + else a->len = -j; +} +MINT *itom(n) +{ MINT *a; + a=(MINT *)xalloc(2,"itom"); + if(n>0) + { a->len=1; + a->val=xalloc(1,"itom1"); + *a->val=n; + return(a); + } + else if(n<0) + { a->len = -1; + a->val=xalloc(1,"itom2"); + *a->val= -n; + return(a); + } + else + { a->len=0; + return(a); + } +} +mcmp(a,b) MINT *a,*b; +{ MINT c; + int res; + if(a->len!=b->len) return(a->len-b->len); + c.len=0; + msub(a,b,&c); + res=c.len; + xfree(&c); + return(res); +} diff --git a/usr/src/libc/crt/cerror.s b/usr/src/libc/crt/cerror.s new file mode 100644 index 0000000000..3859b03b08 --- /dev/null +++ b/usr/src/libc/crt/cerror.s @@ -0,0 +1,10 @@ +# C return sequence which +# sets errno, returns -1. + +.globl cerror +.comm _errno,4 + +cerror: + movl r0,_errno + mnegl $1,r0 + ret diff --git a/usr/src/libc/crt/mcount.s b/usr/src/libc/crt/mcount.s new file mode 100644 index 0000000000..e9d84a73c5 --- /dev/null +++ b/usr/src/libc/crt/mcount.s @@ -0,0 +1,19 @@ +# count subroutine called during profiling + +.globl mcount +.comm countbase,4 + +mcount: + movl (r0),r1 + beql init +incr: + incl (r1) +return: + rsb +init: + movl countbase,r1 + beql return + addl2 $8,countbase + movl (sp),(r1)+ + movl r1,(r0) + brb incr diff --git a/usr/src/libc/csu/crt0.s b/usr/src/libc/csu/crt0.s new file mode 100644 index 0000000000..90fa265e50 --- /dev/null +++ b/usr/src/libc/csu/crt0.s @@ -0,0 +1,33 @@ +# C runtime startoff + + .set exit,1 +.globl _exit +.globl start +.globl _main +.globl _environ + +# +# C language startup routine + +start: + .word 0x0000 + subl2 $8,sp + movl 8(sp),(sp) # argc + movab 12(sp),r0 + movl r0,4(sp) # argv +L1: + tstl (r0)+ # null args term ? + bneq L1 + cmpl r0,*4(sp) # end of 'env' or 'argv' ? + blss L2 + tstl -(r0) # envp's are in list +L2: + movl r0,8(sp) # env + movl r0,_environ # indir is 0 if no env ; not 0 if env + calls $3,_main + pushl r0 + calls $1,_exit + chmk $exit +# + .data +_environ: .space 4 diff --git a/usr/src/libc/csu/mcrt0.s b/usr/src/libc/csu/mcrt0.s new file mode 100644 index 0000000000..fdc0dc16e9 --- /dev/null +++ b/usr/src/libc/csu/mcrt0.s @@ -0,0 +1,83 @@ +# C runtime startoff including monitoring + + .set exit,1 + .set cbufs,300 + +.globl start +.globl _monitor +.globl _sbrk +.globl _main +.globl _exit +.globl _IEH3exit +.globl _etext +.globl _environ +.globl __cleanup +.comm countbase,4 + + +start: + .word 0x0000 + subl2 $8,sp + movl 8(sp),(sp) # argc + movab 12(sp),r0 + movl r0,4(sp) # argv +L1: + tstl (r0)+ # null args term ? + bneq L1 + cmpl r0,*4(sp) # end of 'env' or 'argv' ? + blss L2 + tstl -(r0) # envp's are in list +L2: + movl r0,8(sp) # env + movl r0,_environ # indir is 0 if no env ; not 0 if env + + subl3 $eprol,$_etext,r1 + addl2 $7,r1 + extzv $3,$16,r1,r1 + addl2 r1,r1 # tally size + addl2 $8*cbufs+12,r1 # entrance count plus header + pushl $cbufs # # entrance counters + pushl r1 # bufsiz + pushl r1 # for sbrk + calls $1,_sbrk + cmpl r0,$-1 + beql nospace +# bandaid for sbrk not clearing memory (remove bandaid when fixed) +# addl3 (sp),(sp),r1 +#L100: +# clrb -1(r0)[r1] +# sobgtr r1,L100 +# end bandaid + pushl r0 + addl3 $12,r0,countbase + pushab _etext + pushab eprol + calls $5,_monitor + calls $3,_main + pushl r0 + calls $1,_exit + + .data +_environ: .space 4 +emsg: + .byte 'N,'o,' ,'s,'p,'a,'c,'e,' ,'f,'o,'r,' + .byte 'm,'o,'n,'i,'t,'o,'r,' ,'b,'u,'f,'f,'e,'r,0xa,0x0 +em1: + .text + +nospace: + pushl $em1-emsg + pushab emsg + pushl $2 + calls $3,_write + +_exit: +_IEH3exit: + .word 0x0000 + calls $0,__cleanup + pushl $0 + calls $1,_monitor + chmk $exit +eprol: + + diff --git a/usr/src/libc/gen/atof.c b/usr/src/libc/gen/atof.c new file mode 100644 index 0000000000..281890716d --- /dev/null +++ b/usr/src/libc/gen/atof.c @@ -0,0 +1,49 @@ +union { + short foo0[4]; + double big; +} bar0 /* = {0x5c80,0,0,0} */ ; /* 2**56 as double floating point */ +union { + short foo1[4]; + double huge; +} bar1 /* = {0x8000,0,0,0} */ ; /* reserved operand */ + +double atof(p) register char *p; { +register double exp,val; +register char c; register int dpdig; +int scale; char sign,esign; + +abort(); /* THE REAL ROUTINE IS atofo.s !!!!! */ +while ((c= *p++)==' '); /* skip leading spaces */ +sign=0; +if (c=='-') ++sign; /* mark negative */ +else if (c=='+') ; /* ignore plus */ +else --p; /* get back on track */ + +val=0; dpdig=0; +/* true value is aproximately ((-1)**sign) * val * (10 ** dpdig) */ +while ((c= *p++)<='9' && c>='0') + if(val='0') + if(val='0') {scale *= 10; scale += c-'0';} + if (esign) scale = -scale; +} +dpdig += scale; +if (dpdig==0) return(val); +esign=0; if (dpdig<0) {++esign; dpdig = -dpdig;} +if (dpdig>38) if (esign) return(0); else return(sign? -bar1.huge : bar1.huge); +exp=1; while (dpdig) { + if (dpdig==21) {exp *= 1.0e+21; break;} + exp *= 10; --dpdig; +} +if (esign) return(val/exp); return(val*exp); +} diff --git a/usr/src/libc/gen/atofo.s b/usr/src/libc/gen/atofo.s new file mode 100644 index 0000000000..4397fe20ef --- /dev/null +++ b/usr/src/libc/gen/atofo.s @@ -0,0 +1,148 @@ + # optimized (and corrected) from output of C compiler + # -16(fp) --> r0 + # -20(fp) --> r8 + # -8(fp) --> r6 + # -21(fp) --> r5 + # -22(fp) --> r4 + .set one,010 # 1.0 in floating immediate format + .set ten,042 # 10.0 in floating immediate format +big: .word 0x5c80,0,0,0 # 2**56 in double floating +huge: .word 0x8000,0,0,0 # reserved operand +L49: .double 0d1.00000000000000000000e+21 + .set .R1,0xff0 + .set .F1,24 + .globl _atof +_atof: + .word .R1 + movl 4(ap),r11 +L15: + cvtbl (r11)+,r10 + cmpl r10,$32 + jeql L15 + clrb r5 + cmpb r10,$45 + jneq L17 + incb r5 + jbr L18 +L17: + cmpb r10,$43 + jeql L18 + decl r11 +L18: + clrd r0 + clrl r9 + jbr L22 +L20001: + muld2 $ten,r0 + subl3 $48,r10,r6 + cvtld r6,r6 + addd2 r6,r0 + jbr L22 +L20003: + cmpb r10,$48 + jlss L23 + cmpd r0,big + jlss L20001 + incl r9 +L22: + cvtbl (r11)+,r10 + cmpl r10,$57 + jleq L20003 +L23: + cmpb r10,$46 + jeql L28 + jbr L27 +L20005: + cmpb r10,$48 + jlss L27 + cmpd r0,big + jgeq L28 + decl r9 + muld2 $ten,r0 + subl3 $48,r10,r6 + cvtld r6,r6 + addd2 r6,r0 +L28: + cvtbl (r11)+,r10 + cmpl r10,$57 + jleq L20005 +L27: + tstb r5 + jeql L8827 + mnegd r0,r0 +L8827: + clrl r8 + cmpb r10,$69 + jeql L10000 + cmpb r10,$101 + jneq L32 +L10000: + clrb r4 + cvtbl (r11)+,r10 + cmpl r10,$45 + jneq L33 + incb r4 + jbr L37 +L33: + cmpb r10,$43 + jeql L37 + decl r11 + jbr L37 +L20007: + cmpb r10,$48 + jlss L38 + moval (r8)[r8],r8 + movaw -48(r10)[r8],r8 +L37: + cvtbl (r11)+,r10 + cmpl r10,$57 + jleq L20007 +L38: + tstb r4 + jeql L32 + mnegl r8,r8 +L32: + addl2 r8,r9 + jneq L40 + ret +L40: + clrb r4 + tstl r9 + jgeq L41 + incb r4 + mnegl r9,r9 +L41: + cmpl r9,$38 + jleq L42 + tstb r4 + jeql L43 + clrd r0 + ret +L43: + tstb r5 + jeql L8843 + mnegd huge,r0 + ret +L8843: + movd huge,r0 + ret +L42: + movd $one,r6 + jbr L46 +L20009: + divd2 r6,r0 + ret +L48: + muld2 $ten,r6 + decl r9 +L46: + tstl r9 + jeql L47 + cmpl r9,$21 + jneq L48 + muld2 L49,r6 +L47: + tstb r4 + jneq L20009 + muld2 r6,r0 + ret diff --git a/usr/src/libc/gen/atol.c b/usr/src/libc/gen/atol.c new file mode 100644 index 0000000000..71ae769206 --- /dev/null +++ b/usr/src/libc/gen/atol.c @@ -0,0 +1,25 @@ +long +atol(p) +register char *p; +{ + long n; + register int f; + + n = 0; + f = 0; + for(;;p++) { + switch(*p) { + case ' ': + case '\t': + continue; + case '-': + f++; + case '+': + p++; + } + break; + } + while(*p >= '0' && *p <= '9') + n = n*10 + *p++ - '0'; + return(f? -n: n); +} diff --git a/usr/src/libc/gen/calloc.c b/usr/src/libc/gen/calloc.c new file mode 100644 index 0000000000..52f46d41b7 --- /dev/null +++ b/usr/src/libc/gen/calloc.c @@ -0,0 +1,31 @@ +/* calloc - allocate and clear memory block +*/ +#define CHARPERINT (sizeof(int)/sizeof(char)) +#define NULL 0 + +char * +calloc(num, size) +unsigned num, size; +{ + register char *mp; + char *malloc(); + register int *q; + register m; + + num *= size; + mp = malloc(num); + if(mp == NULL) + return(NULL); + q = (int *) mp; + m = (num+CHARPERINT-1)/CHARPERINT; + while(--m>=0) + *q++ = 0; + return(mp); +} + +cfree(p, num, size) +char *p; +unsigned num, size; +{ + free(p); +} diff --git a/usr/src/libc/gen/chrtab.c b/usr/src/libc/gen/chrtab.c new file mode 100644 index 0000000000..4d8a81acc9 --- /dev/null +++ b/usr/src/libc/gen/chrtab.c @@ -0,0 +1,98 @@ +char chrtab[][16] = { +0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, sp, */ +0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0010,0000,0000,0000,0000,0000, /*, !, */ +0024,0024,0024,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ", */ +0000,0000,0000,0044,0044,0176,0044,0044,0176,0044,0044,0000,0000,0000,0000,0000, /*, #, */ +0000,0010,0010,0010,0076,0101,0100,0076,0001,0101,0076,0010,0010,0000,0000,0000, /*, $, */ +0000,0000,0000,0141,0142,0004,0010,0010,0020,0043,0103,0000,0000,0000,0000,0000, /*, %, */ +0000,0000,0070,0104,0110,0060,0060,0111,0106,0106,0071,0000,0000,0000,0000,0000, /*, &, */ +0004,0010,0020,0040,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ', */ +0000,0004,0010,0020,0040,0040,0040,0040,0040,0040,0020,0010,0004,0000,0000,0000, /*, (, */ +0000,0040,0020,0010,0004,0004,0004,0004,0004,0004,0010,0020,0040,0000,0000,0000, /*, ), */ +0000,0000,0000,0010,0111,0052,0034,0177,0034,0052,0111,0010,0000,0000,0000,0000, /*, *, */ +0000,0000,0000,0000,0010,0010,0010,0177,0010,0010,0010,0000,0000,0000,0000,0000, /*, +, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0010,0020,0000,0000,0000, /*, ,, */ +0000,0000,0000,0000,0000,0000,0000,0176,0000,0000,0000,0000,0000,0000,0000,0000, /*, -, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0030,0030,0000,0000,0000,0000,0000, /*, ., */ +0000,0000,0001,0002,0004,0010,0010,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, /, */ +0000,0030,0044,0102,0102,0102,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 0, */ +0000,0010,0030,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, 1, */ +0000,0070,0104,0004,0004,0010,0020,0040,0100,0100,0174,0000,0000,0000,0000,0000, /*, 2, */ +0000,0176,0004,0004,0010,0014,0002,0002,0002,0104,0070,0000,0000,0000,0000,0000, /*, 3, */ +0000,0004,0014,0024,0044,0104,0176,0004,0004,0004,0004,0000,0000,0000,0000,0000, /*, 4, */ +0000,0174,0100,0100,0130,0144,0002,0002,0102,0044,0030,0000,0000,0000,0000,0000, /*, 5, */ +0000,0074,0102,0100,0130,0144,0102,0102,0102,0044,0030,0000,0000,0000,0000,0000, /*, 6, */ +0000,0176,0004,0004,0010,0010,0020,0020,0040,0040,0040,0000,0000,0000,0000,0000, /*, 7, */ +0000,0034,0042,0101,0042,0076,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, 8, */ +0000,0034,0042,0101,0101,0101,0043,0036,0004,0010,0020,0040,0000,0000,0000,0000, /*, 9, */ +0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0000,0000,0000,0000,0000, /*, :, */ +0000,0000,0000,0000,0000,0000,0030,0030,0000,0030,0030,0020,0040,0000,0000,0000, /*, ;, */ +0002,0004,0010,0020,0040,0100,0040,0020,0010,0004,0002,0000,0000,0000,0000,0000, /*, <, */ +0000,0000,0000,0000,0177,0000,0177,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, =, */ +0100,0040,0020,0010,0004,0002,0004,0010,0020,0040,0100,0000,0000,0000,0000,0000, /*, >, */ +0000,0030,0044,0102,0001,0002,0004,0010,0010,0000,0010,0000,0000,0000,0000,0000, /*, ?, */ +0000,0074,0102,0101,0115,0123,0121,0121,0121,0111,0046,0000,0000,0000,0000,0000, /*, @, */ +0000,0010,0024,0042,0101,0101,0177,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, A, */ +0000,0176,0101,0101,0101,0176,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, B, */ +0000,0076,0101,0100,0100,0100,0100,0100,0100,0101,0076,0000,0000,0000,0000,0000, /*, C, */ +0000,0176,0101,0101,0101,0101,0101,0101,0101,0101,0176,0000,0000,0000,0000,0000, /*, D, */ +0000,0176,0100,0100,0100,0170,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, E, */ +0000,0177,0100,0100,0100,0174,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, F, */ +0000,0076,0101,0100,0100,0117,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, G, */ +0000,0101,0101,0101,0101,0176,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, H, */ +0000,0034,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, I, */ +0000,0016,0004,0004,0004,0004,0004,0004,0104,0104,0070,0000,0000,0000,0000,0000, /*, J, */ +0000,0101,0102,0104,0110,0120,0160,0110,0104,0102,0101,0000,0000,0000,0000,0000, /*, K, */ +0000,0100,0100,0100,0100,0100,0100,0100,0100,0100,0177,0000,0000,0000,0000,0000, /*, L, */ +0000,0101,0143,0125,0111,0101,0101,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, M, */ +0000,0101,0141,0121,0111,0105,0103,0101,0101,0101,0101,0000,0000,0000,0000,0000, /*, N, */ +0000,0076,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, O, */ +0000,0176,0101,0101,0101,0176,0100,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, P, */ +0000,0076,0101,0101,0101,0101,0101,0101,0131,0105,0076,0002,0001,0000,0000,0000, /*, Q, */ +0000,0176,0101,0101,0101,0176,0104,0102,0101,0101,0101,0000,0000,0000,0000,0000, /*, R, */ +0000,0076,0101,0100,0100,0076,0001,0001,0001,0101,0076,0000,0000,0000,0000,0000, /*, S, */ +0000,0177,0010,0010,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, T, */ +0000,0101,0101,0101,0101,0101,0101,0101,0101,0101,0076,0000,0000,0000,0000,0000, /*, U, */ +0000,0101,0101,0101,0101,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, V, */ +0000,0101,0101,0101,0101,0111,0111,0125,0143,0101,0101,0000,0000,0000,0000,0000, /*, W, */ +0000,0101,0101,0042,0024,0010,0024,0042,0101,0101,0101,0000,0000,0000,0000,0000, /*, X, */ +0000,0101,0042,0024,0010,0010,0010,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, Y, */ +0000,0177,0001,0002,0004,0010,0020,0040,0100,0100,0177,0000,0000,0000,0000,0000, /*, Z, */ +0000,0034,0020,0020,0020,0020,0020,0020,0020,0020,0020,0034,0000,0000,0000,0000, /*, [, */ +0000,0000,0100,0040,0020,0010,0010,0010,0004,0002,0001,0000,0000,0000,0000,0000, /*, , \, */ +0000,0070,0010,0010,0010,0010,0010,0010,0010,0010,0010,0070,0000,0000,0000,0000, /*, ], */ +0010,0024,0042,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ^, */ +0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0377,0000,0000, /*, _, */ +0040,0020,0010,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, `, */ +0000,0000,0000,0000,0000,0074,0002,0076,0102,0102,0076,0000,0000,0000,0000,0000, /*, a, */ +0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0174,0000,0000,0000,0000,0000, /*, b, */ +0000,0000,0000,0000,0000,0074,0102,0100,0100,0102,0074,0000,0000,0000,0000,0000, /*, c, */ +0002,0002,0002,0002,0002,0076,0102,0102,0102,0102,0076,0000,0000,0000,0000,0000, /*, d, */ +0000,0000,0000,0000,0000,0074,0102,0174,0100,0102,0074,0000,0000,0000,0000,0000, /*, e, */ +0000,0016,0020,0020,0020,0176,0020,0020,0020,0020,0020,0000,0000,0000,0000,0000, /*, f, */ +0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0102,0076,0000, /*, g, */ +0000,0100,0100,0100,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, h, */ +0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, i, */ +0000,0000,0000,0010,0000,0030,0010,0010,0010,0010,0010,0010,0010,0050,0020,0000, /*, j, */ +0000,0100,0100,0100,0100,0106,0110,0120,0160,0110,0106,0000,0000,0000,0000,0000, /*, k, */ +0000,0030,0010,0010,0010,0010,0010,0010,0010,0010,0034,0000,0000,0000,0000,0000, /*, l, */ +0000,0000,0000,0000,0000,0166,0111,0111,0111,0111,0111,0000,0000,0000,0000,0000, /*, m, */ +0000,0000,0000,0000,0100,0174,0102,0102,0102,0102,0102,0000,0000,0000,0000,0000, /*, n, */ +0000,0000,0000,0000,0000,0074,0102,0102,0102,0102,0074,0000,0000,0000,0000,0000, /*, o, */ +0000,0000,0000,0000,0000,0174,0102,0102,0102,0102,0174,0100,0100,0100,0100,0000, /*, p, */ +0000,0000,0000,0000,0000,0076,0102,0102,0102,0102,0076,0002,0002,0002,0002,0000, /*, q, */ +0000,0000,0000,0000,0000,0134,0142,0100,0100,0100,0100,0000,0000,0000,0000,0000, /*, r, */ +0000,0000,0000,0000,0000,0076,0100,0074,0002,0102,0074,0000,0000,0000,0000,0000, /*, s, */ +0000,0020,0020,0020,0020,0176,0020,0020,0020,0020,0014,0000,0000,0000,0000,0000, /*, t, */ +0000,0000,0000,0000,0000,0102,0102,0102,0102,0102,0075,0000,0000,0000,0000,0000, /*, u, */ +0000,0000,0000,0000,0000,0101,0101,0101,0042,0024,0010,0000,0000,0000,0000,0000, /*, v, */ +0000,0000,0000,0000,0000,0111,0111,0111,0111,0111,0066,0000,0000,0000,0000,0000, /*, w, */ +0000,0000,0000,0000,0000,0102,0044,0030,0030,0044,0102,0000,0000,0000,0000,0000, /*, x, */ +0000,0000,0000,0000,0000,0102,0102,0102,0042,0024,0010,0020,0040,0100,0000,0000, /*, y, */ +0000,0000,0000,0000,0000,0176,0004,0010,0020,0040,0176,0000,0000,0000,0000,0000, /*, z, */ +0000,0014,0020,0020,0020,0020,0040,0020,0020,0020,0020,0014,0000,0000,0000,0000, /*, {, */ +0000,0010,0010,0010,0010,0000,0000,0010,0010,0010,0010,0000,0000,0000,0000,0000, /*, |, */ +0000,0030,0010,0010,0010,0010,0004,0010,0010,0010,0010,0030,0000,0000,0000,0000, /*, }, */ +0020,0052,0004,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000,0000, /*, ~, */ +0000,0176,0176,0176,0176,0176,0176,0176,0176,0176,0176,0000,0000,0000,0000,0000, /*, del, */ +}; diff --git a/usr/src/libc/gen/crypt.c b/usr/src/libc/gen/crypt.c new file mode 100644 index 0000000000..164fd5c775 --- /dev/null +++ b/usr/src/libc/gen/crypt.c @@ -0,0 +1,380 @@ +/* + * 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, +}; + +/* + * The C and D arrays used to calculate the key schedule. + */ + +static char C[28]; +static char D[28]; +/* + * The key schedule. + * Generated from the key. + */ +static char KS[16][48]; + +/* + * Set up the key schedule from the key. + */ + +setkey(key) +char *key; +{ + register i, j, k; + int t; + + /* + * 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>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; +char *salt; +{ + register i, j, c; + int temp; + static char block[66], iobuf[16]; + for(i=0; i<66; i++) + block[i] = 0; + for(i=0; (c= *pw) && i<64; pw++){ + for(j=0; j<7; j++, i++) + block[i] = (c>>(6-j)) & 01; + i++; + } + + setkey(block); + + for(i=0; i<66; i++) + block[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(block,0); + + for(i=0; i<11; i++){ + c = 0; + for(j=0; j<6; j++){ + c <<= 1; + c |= block[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); +} diff --git a/usr/src/libc/gen/ctime.c b/usr/src/libc/gen/ctime.c new file mode 100644 index 0000000000..cd8b9aa5e1 --- /dev/null +++ b/usr/src/libc/gen/ctime.c @@ -0,0 +1,245 @@ +/* + * This routine converts time as follows. + * The epoch is 0000 Jan 1 1970 GMT. + * The argument time is in seconds since then. + * The localtime(t) entry returns a pointer to an array + * containing + * seconds (0-59) + * minutes (0-59) + * hours (0-23) + * day of month (1-31) + * month (0-11) + * year-1970 + * weekday (0-6, Sun is 0) + * day of the year + * daylight savings flag + * + * The routine calls the system to determine the local + * timezone and whether Daylight Saving Time is permitted locally. + * (DST is then determined by the current US standard rules) + * There is a table that accounts for the peculiarities + * undergone by daylight time in 1974-1975. + * + * The routine does not work + * in Saudi Arabia which runs on Solar time. + * + * asctime(tvec)) + * where tvec is produced by localtime + * returns a ptr to a character string + * that has the ascii time in the form + * Thu Jan 01 00:00:00 1970n0\\ + * 01234567890123456789012345 + * 0 1 2 + * + * ctime(t) just calls localtime, then asctime. + */ + +#include +#include +#include + +static char cbuf[26]; +static int dmsize[12] = +{ + 31, + 28, + 31, + 30, + 31, + 30, + 31, + 31, + 30, + 31, + 30, + 31 +}; + +/* + * The following table is used for 1974 and 1975 and + * gives the day number of the first day after the Sunday of the + * change. + */ +static struct { + int daylb; + int dayle; +} daytab[] = { + 5, 333, /* 1974: Jan 6 - last Sun. in Nov */ + 58, 303, /* 1975: Last Sun. in Feb - last Sun in Oct */ +}; + +struct tm *gmtime(); +char *ct_numb(); +struct tm *localtime(); +char *ctime(); +char *ct_num(); +char *asctime(); + +char * +ctime(t) +long *t; +{ + return(asctime(localtime(t))); +} + +struct tm * +localtime(tim) +long *tim; +{ + register int dayno; + register struct tm *ct; + register daylbegin, daylend; + long copyt; + struct timeb systime; + + ftime(&systime); + copyt = *tim - (long)systime.timezone*60; + ct = gmtime(©t); + dayno = ct->tm_yday; + daylbegin = 119; /* last Sun in Apr */ + daylend = 303; /* Last Sun in Oct */ + if (ct->tm_year==74 || ct->tm_year==75) { + daylbegin = daytab[ct->tm_year-74].daylb; + daylend = daytab[ct->tm_year-74].dayle; + } + daylbegin = sunday(ct, daylbegin); + daylend = sunday(ct, daylend); + if (systime.dstflag && + (dayno>daylbegin || (dayno==daylbegin && ct->tm_hour>=2)) && + (daynotm_hour<1))) { + copyt += 1*60*60; + ct = gmtime(©t); + ct->tm_isdst++; + } + return(ct); +} + +/* + * The argument is a 0-origin day number. + * The value is the day number of the first + * Sunday on or after the day. + */ +static +sunday(t, d) +register struct tm *t; +register int d; +{ + if (d >= 58) + d += dysize(t->tm_year) - 365; + return(d - (d - t->tm_yday + t->tm_wday + 700) % 7); +} + +struct tm * +gmtime(tim) +long *tim; +{ + register int d0, d1; + long hms, day; + register int *tp; + static struct tm xtime; + + /* + * break initial number into days + */ + hms = *tim % 86400; + day = *tim / 86400; + if (hms<0) { + hms += 86400; + day -= 1; + } + tp = (int *)&xtime; + + /* + * generate hours:minutes:seconds + */ + *tp++ = hms%60; + d1 = hms/60; + *tp++ = d1%60; + d1 /= 60; + *tp++ = d1; + + /* + * day is the day number. + * generate day of the week. + * The addend is 4 mod 7 (1/1/1970 was Thursday) + */ + + xtime.tm_wday = (day+7340036)%7; + + /* + * year number + */ + if (day>=0) for(d1=70; day >= dysize(d1); d1++) + day -= dysize(d1); + else for (d1=70; day<0; d1--) + day += dysize(d1-1); + xtime.tm_year = d1; + xtime.tm_yday = d0 = day; + + /* + * generate month + */ + + if (dysize(d1)==366) + dmsize[1] = 29; + for(d1=0; d0 >= dmsize[d1]; d1++) + d0 -= dmsize[d1]; + dmsize[1] = 28; + *tp++ = d0+1; + *tp++ = d1; + xtime.tm_isdst = 0; + return(&xtime); +} + +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); + if (t->tm_year>=100) { + cp[1] = '2'; + cp[2] = '0'; + } + cp += 2; + cp = ct_numb(cp, t->tm_year+100); + return(cbuf); +} + +dysize(y) +{ + if((y%4) == 0) + return(366); + return(365); +} + +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/libc/gen/ecvt.c b/usr/src/libc/gen/ecvt.c new file mode 100644 index 0000000000..43d17fc404 --- /dev/null +++ b/usr/src/libc/gen/ecvt.c @@ -0,0 +1,104 @@ +/* + * ecvt converts to decimal + * the number of digits is specified by ndigit + * decpt is set to the position of the decimal point + * sign is set to 0 for positive, 1 for negative + */ + +char *cvt(); + +#define NDIG 80 +char* +ecvt(arg, ndigits, decpt, sign) +double arg; +int ndigits, *decpt, *sign; +{ + return(cvt(arg, ndigits, decpt, sign, 1)); +} + +char* +fcvt(arg, ndigits, decpt, sign) +double arg; +int ndigits, *decpt, *sign; +{ + return(cvt(arg, ndigits, decpt, sign, 0)); +} + +static char* +cvt(arg, ndigits, decpt, sign, eflag) +double arg; +int ndigits, *decpt, *sign; +{ + register int r2; + double fi, fj; + register char *p, *p1; + static char buf[NDIG]; + double modf(); + + if (ndigits<0) + ndigits = 0; + if (ndigits>=NDIG-1) + ndigits = NDIG-2; + r2 = 0; + *sign = 0; + p = &buf[0]; + if (arg<0) { + *sign = 1; + arg = -arg; + } + arg = modf(arg, &fi); + p1 = &buf[NDIG]; + /* + * Do integer part + */ + if (fi != 0) { + p1 = &buf[NDIG]; + while (fi != 0) { + fj = modf(fi/10, &fi); + *--p1 = (int)((fj+.03)*10) + '0'; + r2++; + } + while (p1 < &buf[NDIG]) + *p++ = *p1++; + } else if (arg > 0) { + while ((fj = arg*10) < 1) { + arg = fj; + r2--; + } + } + p1 = &buf[ndigits]; + if (eflag==0) + p1 += r2; + *decpt = r2; + if (p1 < &buf[0]) { + buf[0] = '\0'; + return(buf); + } + while (p<=p1 && p<&buf[NDIG]) { + arg *= 10; + arg = modf(arg, &fj); + *p++ = (int)fj + '0'; + } + if (p1 >= &buf[NDIG]) { + buf[NDIG-1] = '\0'; + return(buf); + } + p = p1; + *p1 += 5; + while (*p1 > '9') { + *p1 = '0'; + if (p1>buf) + ++*--p1; + else { + *p1 = '1'; + (*decpt)++; + if (eflag==0) { + if (p>buf) + *p = '0'; + p++; + } + } + } + *p = '\0'; + return(buf); +} diff --git a/usr/src/libc/gen/errlst.c b/usr/src/libc/gen/errlst.c new file mode 100644 index 0000000000..a9770d5bed --- /dev/null +++ b/usr/src/libc/gen/errlst.c @@ -0,0 +1,38 @@ +char *sys_errlist[] = { + "Error 0", + "Not owner", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Arg list too long", + "Exec format error", + "Bad file number", + "No children", + "No more processes", + "Not enough core", + "Permission denied", + "Bad address", + "Block device required", + "Mount device busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Argument too large", + "Result too large", +}; +int sys_nerr = { sizeof sys_errlist/sizeof sys_errlist[0] }; diff --git a/usr/src/libc/gen/execvp.c b/usr/src/libc/gen/execvp.c new file mode 100644 index 0000000000..4942d5e79d --- /dev/null +++ b/usr/src/libc/gen/execvp.c @@ -0,0 +1,83 @@ +/* + * execlp(name, arg,...,0) (like execl, but does path search) + * execvp(name, argv) (like execv, but does path search) + */ +#include +#define NULL 0 + +static char shell[] = "/bin/sh"; +char *execat(), *getenv(); +extern errno; + +execlp(name, argv) +char *name, *argv; +{ + return(execvp(name, &argv)); +} + +execvp(name, argv) +char *name, **argv; +{ + char *pathstr; + register char *cp; + char fname[128]; + char *newargs[256]; + int i; + register unsigned etxtbsy = 1; + register eacces = 0; + + if ((pathstr = getenv("PATH")) == NULL) + pathstr = ":/bin:/usr/bin"; + cp = index(name, '/')? "": pathstr; + + do { + cp = execat(cp, name, fname); + retry: + 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); + } + } + execv(shell, newargs); + return(-1); + case ETXTBSY: + if (++etxtbsy > 5) + return(-1); + sleep(etxtbsy); + goto retry; + case EACCES: + eacces++; + break; + case ENOMEM: + case E2BIG: + 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; + + s = si; + while (*s1 && *s1 != ':' && *s1 != '-') + *s++ = *s1++; + if (si != s) + *s++ = '/'; + while (*s2) + *s++ = *s2++; + *s = '\0'; + return(*s1? ++s1: 0); +} diff --git a/usr/src/libc/gen/frexp.c b/usr/src/libc/gen/frexp.c new file mode 100644 index 0000000000..8d9425ac3b --- /dev/null +++ b/usr/src/libc/gen/frexp.c @@ -0,0 +1,36 @@ +/* + 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; + int j; + j = 0; + neg = 0; + if(x<0){ + x = -x; + neg = 1; + } + if(x>1.0) + while(x>1){ + j = j+1; + x = x/2; + } + else if(x<0.5) + while(x<0.5){ + j = j-1; + x = 2*x; + } + *i = j; + if(neg) x = -x; + return(x); + } diff --git a/usr/src/libc/gen/getenv.c b/usr/src/libc/gen/getenv.c new file mode 100644 index 0000000000..8fb727e5ac --- /dev/null +++ b/usr/src/libc/gen/getenv.c @@ -0,0 +1,40 @@ +/* + * getenv(name) + * returns ptr to value associated with name, if any, else NULL + */ +#define NULL 0 +extern char **environ; +char *nvmatch(); + +char * +getenv(name) +register char *name; +{ + register char **p = environ; + register char *v; + + 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/libc/gen/getlogin.c b/usr/src/libc/gen/getlogin.c new file mode 100644 index 0000000000..f8a8c1cde2 --- /dev/null +++ b/usr/src/libc/gen/getlogin.c @@ -0,0 +1,25 @@ +#include + +static char UTMP[] = "/etc/utmp"; +static struct utmp ubuf; + +char * +getlogin() +{ + register me, uf; + register char *cp; + + if( !(me = ttyslot()) ) + return(0); + if( (uf = open( UTMP, 0 )) < 0 ) + return(0); + lseek( uf, (long)(me*sizeof(ubuf)), 0 ); + if (read(uf, (char *)&ubuf, sizeof(ubuf)) != sizeof(ubuf)) + return(0); + close(uf); + ubuf.ut_name[8] = ' '; + for (cp=ubuf.ut_name; *cp++!=' ';) + ; + *--cp = '\0'; + return( ubuf.ut_name ); +} diff --git a/usr/src/libc/gen/index.c b/usr/src/libc/gen/index.c new file mode 100644 index 0000000000..f525edb862 --- /dev/null +++ b/usr/src/libc/gen/index.c @@ -0,0 +1,17 @@ +/* + * 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/libc/gen/isatty.c b/usr/src/libc/gen/isatty.c new file mode 100644 index 0000000000..0743e62ca6 --- /dev/null +++ b/usr/src/libc/gen/isatty.c @@ -0,0 +1,14 @@ +/* + * Returns 1 iff file is a tty + */ + +#include + +isatty(f) +{ + struct sgttyb ttyb; + + if (gtty(f, &ttyb) < 0) + return(0); + return(1); +} diff --git a/usr/src/libc/gen/l3tol.c b/usr/src/libc/gen/l3tol.c new file mode 100644 index 0000000000..645d486e0d --- /dev/null +++ b/usr/src/libc/gen/l3tol.c @@ -0,0 +1,24 @@ +l3tol(lp, cp, n) +long *lp; +char *cp; +int n; +{ + register i; + register char *a, *b; + + a = (char *)lp; + b = cp; + for(i=0;i127) + if(neg) + return(-huge); + else + return(huge); + if(exp<-127) + return(0); + while(exp>30){ + fr = fr*(1L<<30); + exp = exp-30; + } + while(exp<-30){ + fr = fr/(1L<<30); + exp = exp+30; + } + if(exp>0) + fr = fr*(1L<=allocs && allocp<=alloct); + ASSERT(allock()); + for(p=allocp; ; ) { + for(temp=0; ; ) { + if(!testbusy(p->ptr)) { + while(!testbusy((q=p->ptr)->ptr)) { + ASSERT(q>p&&qptr = q->ptr; + } + if(q>=p+nw && p+nw>=p) + goto found; + } + q = p; + p = clearbusy(p->ptr); + if(p>q) + ASSERT(p<=alloct); + else if(q!=alloct || p!=allocs) { + ASSERT(q==alloct&&p==allocs); + return(NULL); + } else if(++temp>1) + break; + } + temp = ((nw+BLOCK/WORD)/(BLOCK/WORD))*(BLOCK/WORD); + q = (union store *)sbrk(0); + if(q+temp+GRANULE < q) { + return(NULL); + } + q = (union store *)sbrk(temp*WORD); + if((INT)q == -1) { + return(NULL); + } + ASSERT(q>alloct); + alloct->ptr = q; + if(q!=alloct+1) + alloct->ptr = setbusy(alloct->ptr); + alloct = q->ptr = q+temp-1; + alloct->ptr = setbusy(allocs); + } +found: + allocp = p + nw; + ASSERT(allocp<=alloct); + if(q>allocp) { + allocx = allocp->ptr; + allocp->ptr = p->ptr; + } + p->ptr = setbusy(allocp); + return((char *)(p+1)); +} + +/* freeing strategy tuned for LIFO allocation +*/ +free(ap) +register char *ap; +{ + register union store *p = (union store *)ap; + + ASSERT(p>clearbusy(allocs[1].ptr)&&p<=alloct); + ASSERT(allock()); + allocp = --p; + ASSERT(testbusy(p->ptr)); + p->ptr = clearbusy(p->ptr); + ASSERT(p->ptr > allocp && p->ptr <= alloct); +} + +/* realloc(p, nbytes) reallocates a block obtained from malloc() + * and freed since last call of malloc() + * to have new size nbytes, and old content + * returns new location, or 0 on failure +*/ + +char * +realloc(p, nbytes) +register union store *p; +unsigned nbytes; +{ + register union store *q; + union store *s, *t; + register unsigned nw; + unsigned onw; + + if(testbusy(p[-1].ptr)) + free((char *)p); + onw = p[-1].ptr - p; + q = (union store *)malloc(nbytes); + if(q==NULL || q==p) + return((char *)q); + s = p; + t = q; + nw = (nbytes+WORD-1)/WORD; + if(nw=p) + (q+(q+nw-p))->ptr = allocx; + return((char *)q); +} + +#ifdef debug +allock() +{ +#ifdef longdebug + register union store *p; + int x; + x = 0; + for(p= &allocs[0]; clearbusy(p->ptr) > p; p=clearbusy(p->ptr)) { + if(p==allocp) + x++; + } + ASSERT(p==alloct); + return(x==1|p==allocp); +#else + return(1); +#endif +} +#endif diff --git a/usr/src/libc/gen/mktemp.c b/usr/src/libc/gen/mktemp.c new file mode 100644 index 0000000000..164e9af5a9 --- /dev/null +++ b/usr/src/libc/gen/mktemp.c @@ -0,0 +1,26 @@ +char * +mktemp(as) +char *as; +{ + register char *s; + register unsigned pid; + register i; + + pid = getpid(); + s = as; + while (*s++) + ; + s--; + while (*--s == 'X') { + *s = (pid%10) + '0'; + pid /= 10; + } + s++; + i = 'a'; + while (access(as, 0) != -1) { + if (i=='z') + return("/"); + *s = i++; + } + return(as); +} diff --git a/usr/src/libc/gen/modf.c b/usr/src/libc/gen/modf.c new file mode 100644 index 0000000000..32acfa5d87 --- /dev/null +++ b/usr/src/libc/gen/modf.c @@ -0,0 +1,46 @@ +double +modf(arg,ent) +double arg; +double *ent; +{ + int neg; + int i; + double two30 = 1073741824.; + double big = 72057594037927936.; /*2^56*/ + double x, temp; + double ldexp(); + double frexp(); + long l; + + neg = 1; + if(arg<0){ + neg = -1; + arg = -arg; + } + if(arg>big){ + *ent = neg*arg; + return(0); + } + if(arg<1){ + *ent = 0; + return(neg*arg); + } + + temp = 0; + while(arg>two30){ + x = frexp(arg,&i); + if(arg<0.5){ + arg = 2*arg; + i = i-1; + } + x = ldexp(0.5,i); + arg = arg - x; + temp = temp + x; + } + + l = arg; + arg = arg-l; + temp = temp+l; + *ent = neg*temp; + return(neg*arg); + } diff --git a/usr/src/libc/gen/perror.c b/usr/src/libc/gen/perror.c new file mode 100644 index 0000000000..39c1cc919b --- /dev/null +++ b/usr/src/libc/gen/perror.c @@ -0,0 +1,25 @@ +/* + * Print the error indicated + * in the cerror cell. + */ + +int errno; +int sys_nerr; +char *sys_errlist[]; +perror(s) +char *s; +{ + register char *c; + register n; + + c = "Unknown error"; + if(errno < sys_nerr) + c = sys_errlist[errno]; + n = strlen(s); + if(n) { + write(2, s, n); + write(2, ": ", 2); + } + write(2, c, strlen(c)); + write(2, "\n", 1); +} diff --git a/usr/src/libc/gen/qsort.c b/usr/src/libc/gen/qsort.c new file mode 100644 index 0000000000..202c759222 --- /dev/null +++ b/usr/src/libc/gen/qsort.c @@ -0,0 +1,120 @@ + +static int (*qscmp)(); +static int qses; + +qsort(a, n, es, fc) +char *a; +unsigned n; +int es; +int (*fc)(); +{ + qscmp = fc; + qses = es; + qs1(a, a+n*es); +} + +static qs1(a, l) +char *a, *l; +{ + register char *i, *j; + register es; + char **k; + char *lp, *hp; + int c; + unsigned n; + + + es = qses; + +start: + if((n=l-a) <= es) + return; + n = es * (n / (2*es)); + hp = lp = a+n; + i = a; + j = l-es; + for(;;) { + if(i < lp) { + if((c = (*qscmp)(i, lp)) == 0) { + qsexc(i, lp -= es); + continue; + } + if(c < 0) { + i += es; + continue; + } + } + +loop: + if(j > hp) { + if((c = (*qscmp)(hp, j)) == 0) { + qsexc(hp += es, j); + goto loop; + } + if(c > 0) { + if(i == lp) { + qstexc(i, hp += es, j); + i = lp += es; + goto loop; + } + qsexc(i, j); + j -= es; + i += es; + continue; + } + j -= es; + goto loop; + } + + + if(i == lp) { + if(lp-a >= l-hp) { + qs1(hp+es, l); + l = lp; + } else { + qs1(a, lp); + a = hp+es; + } + goto start; + } + + + qstexc(j, lp -= es, i); + j = hp -= es; + } +} + +static qsexc(i, j) +char *i, *j; +{ + register char *ri, *rj, c; + int n; + + n = qses; + ri = i; + rj = j; + do { + c = *ri; + *ri++ = *rj; + *rj++ = c; + } while(--n); +} + +static qstexc(i, j, k) +char *i, *j, *k; +{ + register char *ri, *rj, *rk; + int c; + int n; + + n = qses; + ri = i; + rj = j; + rk = k; + do { + c = *ri; + *ri++ = *rk; + *rk++ = *rj; + *rj++ = c; + } while(--n); +} diff --git a/usr/src/libc/gen/rand.c b/usr/src/libc/gen/rand.c new file mode 100644 index 0000000000..eff67350d5 --- /dev/null +++ b/usr/src/libc/gen/rand.c @@ -0,0 +1,12 @@ +static long randx = 1; + +srand(x) +unsigned x; +{ + randx = x; +} + +rand() +{ + return((randx = randx * 1103515245 + 12345) & 0x7fffffff); +} diff --git a/usr/src/libc/gen/rin.c b/usr/src/libc/gen/rin.c new file mode 100644 index 0000000000..1f12da3001 --- /dev/null +++ b/usr/src/libc/gen/rin.c @@ -0,0 +1,35 @@ +#include + +rin() +{ + double d; + register n, c, f; + + d = 0.; + f = 0; + n = 0; +loop: + c = getchar(); + if(c == EOF) + exit(); + if(c == '-') { + f++; + goto loop; + } + if(c == '.') { + n++; + goto loop; + } + if(isdigit(c)) { + if(n) + n++; + d = d*10.+c-'0'; + goto loop; + } + if(f) + d = -d; + for(f=1; fs2: >0 s1==s2: 0 s1s2: >0 s1==s2: 0 s1= 0 && *s1 == *s2++) + if (*s1++ == '\0') + return(0); + return(n<0 ? 0 : *s1 - *--s2); +} diff --git a/usr/src/libc/gen/strcpy.c b/usr/src/libc/gen/strcpy.c new file mode 100644 index 0000000000..da2acb57e7 --- /dev/null +++ b/usr/src/libc/gen/strcpy.c @@ -0,0 +1,16 @@ +/* + * Copy string s2 to s1. s1 must be large enough. + * return s1 + */ + +char * +strcpy(s1, s2) +register char *s1, *s2; +{ + register char *os1; + + os1 = s1; + while (*s1++ = *s2++) + ; + return(os1); +} diff --git a/usr/src/libc/gen/strcpyn.c b/usr/src/libc/gen/strcpyn.c new file mode 100644 index 0000000000..eebf2aceb6 --- /dev/null +++ b/usr/src/libc/gen/strcpyn.c @@ -0,0 +1,21 @@ +/* + * Copy s2 to s1, truncating or null-padding to always copy n bytes + * return s1 + */ + +char * +strcpyn(s1, s2, n) +register char *s1, *s2; +{ + register i; + register char *os1; + + os1 = s1; + for (i = 0; i < n; i++) + if ((*s1++ = *s2++) == '\0') { + while (++i < n) + *s1++ = '\0'; + return(os1); + } + return(os1); +} diff --git a/usr/src/libc/gen/strlen.c b/usr/src/libc/gen/strlen.c new file mode 100644 index 0000000000..2abf6a5c69 --- /dev/null +++ b/usr/src/libc/gen/strlen.c @@ -0,0 +1,15 @@ +/* + * Returns the number of + * non-NULL bytes in string argument. + */ + +strlen(s) +register char *s; +{ + register n; + + n = 0; + while (*s++) + n++; + return(n); +} diff --git a/usr/src/libc/gen/strncat.c b/usr/src/libc/gen/strncat.c new file mode 100644 index 0000000000..34dcabe913 --- /dev/null +++ b/usr/src/libc/gen/strncat.c @@ -0,0 +1,24 @@ +/* + * 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/libc/gen/strncmp.c b/usr/src/libc/gen/strncmp.c new file mode 100644 index 0000000000..a46514e58d --- /dev/null +++ b/usr/src/libc/gen/strncmp.c @@ -0,0 +1,14 @@ +/* + * Compare strings (at most n bytes): s1>s2: >0 s1==s2: 0 s1= 0 && *s1 == *s2++) + if (*s1++ == '\0') + return(0); + return(n<0 ? 0 : *s1 - *--s2); +} diff --git a/usr/src/libc/gen/strncpy.c b/usr/src/libc/gen/strncpy.c new file mode 100644 index 0000000000..40c511e7f7 --- /dev/null +++ b/usr/src/libc/gen/strncpy.c @@ -0,0 +1,21 @@ +/* + * Copy s2 to s1, truncating or null-padding to always copy n bytes + * return s1 + */ + +char * +strncpy(s1, s2, n) +register char *s1, *s2; +{ + register i; + register char *os1; + + os1 = s1; + for (i = 0; i < n; i++) + if ((*s1++ = *s2++) == '\0') { + while (++i < n) + *s1++ = '\0'; + return(os1); + } + return(os1); +} diff --git a/usr/src/libc/gen/stty.c b/usr/src/libc/gen/stty.c new file mode 100644 index 0000000000..1712124223 --- /dev/null +++ b/usr/src/libc/gen/stty.c @@ -0,0 +1,17 @@ +/* + * Writearound to old stty and gtty system calls + */ + +#include + +stty(fd, ap) +struct sgtty *ap; +{ + return(ioctl(fd, TIOCSETP, ap)); +} + +gtty(fd, ap) +struct sgtty *ap; +{ + return(ioctl(fd, TIOCGETP, ap)); +} diff --git a/usr/src/libc/gen/swab.c b/usr/src/libc/gen/swab.c new file mode 100644 index 0000000000..9b11fe94c6 --- /dev/null +++ b/usr/src/libc/gen/swab.c @@ -0,0 +1,16 @@ +/* + * Swap bytes in 16-bit [half-]words + * for going between the 11 and the interdata + */ + +swab(pf, pt, n) +register short *pf, *pt; +register n; +{ + + n /= 2; + while (--n >= 0) { + *pt++ = (*pf << 8) + ((*pf >> 8) & 0377); + pf++; + } +} diff --git a/usr/src/libc/gen/tell.c b/usr/src/libc/gen/tell.c new file mode 100644 index 0000000000..12e6bf23ae --- /dev/null +++ b/usr/src/libc/gen/tell.c @@ -0,0 +1,10 @@ +/* + * return offset in file. + */ + +long lseek(); + +long tell(f) +{ + return(lseek(f, 0L, 1)); +} diff --git a/usr/src/libc/gen/timezone.c b/usr/src/libc/gen/timezone.c new file mode 100644 index 0000000000..c80ddd8d28 --- /dev/null +++ b/usr/src/libc/gen/timezone.c @@ -0,0 +1,44 @@ +/* + * 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[] = { + 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 */ + 0, "GMT", 0, /* Greenwich */ + -1 +}; + +char *timezone(zone, dst) +{ + register struct zone *zp; + static char czone[10]; + char *sign; + + 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/libc/gen/ttyname.c b/usr/src/libc/gen/ttyname.c new file mode 100644 index 0000000000..c7724e004a --- /dev/null +++ b/usr/src/libc/gen/ttyname.c @@ -0,0 +1,49 @@ +/* + * ttyname(f): return "/dev/ttyXX" which the the name of the + * tty belonging to file f. + * NULL if it is not a tty + */ + +#define NULL 0 +#include +#include +#include + +static char dev[] = "/dev/"; +char *strcpy(); +char *strcat(); + +char * +ttyname(f) +{ + struct stat fsb; + struct stat tsb; + struct direct db; + static char rbuf[32]; + register df; + + if (isatty(f)==0) + return(NULL); + if (fstat(f, &fsb) < 0) + return(NULL); + if ((fsb.st_mode&S_IFMT) != S_IFCHR) + return(NULL); + if ((df = open(dev, 0)) < 0) + return(NULL); + while (read(df, (char *)&db, sizeof(db)) == sizeof(db)) { + if (db.d_ino == 0) + continue; + if (db.d_ino != fsb.st_ino) + continue; + strcpy(rbuf, dev); + strcat(rbuf, db.d_name); + if (stat(rbuf, &tsb) < 0) + continue; + if (tsb.st_dev==fsb.st_dev && tsb.st_ino==fsb.st_ino) { + close(df); + return(rbuf); + } + } + close(df); + return(NULL); +} diff --git a/usr/src/libc/gen/ttyslot.c b/usr/src/libc/gen/ttyslot.c new file mode 100644 index 0000000000..6449aabc3d --- /dev/null +++ b/usr/src/libc/gen/ttyslot.c @@ -0,0 +1,58 @@ +/* + * Return the number of the slot in the utmp file + * corresponding to the current user: try for file 0, 1, 2. + * Definition is the line number in the /etc/ttys file. + */ + + +char *ttyname(); +char *getttys(); +char *rindex(); +static char ttys[] = "/etc/ttys"; + +#define NULL 0 + +ttyslot() +{ + register char *tp, *p; + register s, tf; + + 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 ((tf=open(ttys, 0)) < 0) + return(0); + s = 0; + while (tp = getttys(tf)) { + s++; + if (strcmp(p, tp)==0) { + close(tf); + return(s); + } + } + close(tf); + return(0); +} + +static char * +getttys(f) +{ + static char line[32]; + register char *lp; + + lp = line; + for (;;) { + if (read(f, lp, 1) != 1) + return(NULL); + if (*lp =='\n') { + *lp = '\0'; + return(line+2); + } + if (lp >= &line[32]) + return(line+2); + lp++; + } +} diff --git a/usr/src/libc/stdio/clrerr.c b/usr/src/libc/stdio/clrerr.c new file mode 100644 index 0000000000..d0bb284394 --- /dev/null +++ b/usr/src/libc/stdio/clrerr.c @@ -0,0 +1,7 @@ +#include + +clearerr(iop) +register struct _iobuf *iop; +{ + iop->_flag &= ~(_IOERR|_IOEOF); +} diff --git a/usr/src/libc/stdio/data.c b/usr/src/libc/stdio/data.c new file mode 100644 index 0000000000..85c559ee62 --- /dev/null +++ b/usr/src/libc/stdio/data.c @@ -0,0 +1,13 @@ +#include +char _sibuf[BUFSIZ]; +char _sobuf[BUFSIZ]; + +struct _iobuf _iob[_NFILE] ={ + { 0, _sibuf, _sibuf, _IOREAD, 0}, + { 0, NULL, NULL, _IOWRT, 1}, + { 0, NULL, NULL, _IOWRT+_IONBF, 2}, +}; +/* + * Ptr to end of buffers + */ +struct _iobuf *_lastbuf ={ &_iob[_NFILE] }; diff --git a/usr/src/libc/stdio/doscan.c b/usr/src/libc/stdio/doscan.c new file mode 100644 index 0000000000..bafc4ab0b9 --- /dev/null +++ b/usr/src/libc/stdio/doscan.c @@ -0,0 +1,275 @@ +#include +#include + +#define SPC 01 +#define STP 02 + +#define SHORT 0 +#define REGULAR 1 +#define LONG 2 +#define INT 0 +#define FLOAT 1 + +char *_getccl(); + +char _sctab[128] = { + 0,0,0,0,0,0,0,0, + 0,SPC,SPC,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + SPC,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0, +}; + +_doscan(iop, fmt, argp) +FILE *iop; +register char *fmt; +register int **argp; +{ + register int ch; + int nmatch, len, ch1; + int **ptr, fileended, size; + + nmatch = 0; + fileended = 0; + for (;;) switch (ch = *fmt++) { + case '\0': + return (nmatch); + case '%': + if ((ch = *fmt++) == '%') + goto def; + ptr = 0; + if (ch != '*') + ptr = argp++; + else + ch = *fmt++; + len = 0; + size = REGULAR; + while (isdigit(ch)) { + len = len*10 + ch - '0'; + ch = *fmt++; + } + if (len == 0) + len = 30000; + if (ch=='l') { + size = LONG; + ch = *fmt++; + } else if (ch=='h') { + size = SHORT; + ch = *fmt++; + } else if (ch=='[') + fmt = _getccl(fmt); + if (isupper(ch)) { + ch = tolower(ch); + size = LONG; + } + if (ch == '\0') + return(-1); + if (_innum(ptr, ch, len, size, iop, &fileended) && ptr) + nmatch++; + if (fileended) + return(nmatch? nmatch: -1); + break; + + case ' ': + case '\n': + case '\t': + while ((ch1 = getc(iop))==' ' || ch1=='\t' || ch1=='\n') + ; + if (ch1 != EOF) + ungetc(ch1, iop); + break; + + default: + def: + ch1 = getc(iop); + if (ch1 != ch) { + if (ch1==EOF) + return(-1); + ungetc(ch1, iop); + return(nmatch); + } + } +} + +_innum(ptr, type, len, size, iop, eofptr) +int **ptr, *eofptr; +struct _iobuf *iop; +{ + extern double atof(); + register char *np; + char numbuf[64]; + register c, base; + int expseen, scale, negflg, c1, ndigit; + long lcval; + + if (type=='c' || type=='s' || type=='[') + return(_instr(ptr? *(char **)ptr: (char *)NULL, type, len, iop, eofptr)); + lcval = 0; + ndigit = 0; + scale = INT; + if (type=='e'||type=='f') + scale = FLOAT; + base = 10; + if (type=='o') + base = 8; + else if (type=='x') + base = 16; + np = numbuf; + expseen = 0; + negflg = 0; + while ((c = getc(iop))==' ' || c=='\t' || c=='\n'); + if (c=='-') { + negflg++; + *np++ = c; + c = getc(iop); + len--; + } else if (c=='+') { + len--; + c = getc(iop); + } + for ( ; --len>=0; *np++ = c, c = getc(iop)) { + if (isdigit(c) + || base==16 && ('a'<=c && c<='f' || 'A'<=c && c<='F')) { + ndigit++; + if (base==8) + lcval <<=3; + else if (base==10) + lcval = ((lcval<<2) + lcval)<<1; + else + lcval <<= 4; + c1 = c; + if (isdigit(c)) + c -= '0'; + else if ('a'<=c && c<='f') + c -= 'a'-10; + else + c -= 'A'-10; + lcval += c; + c = c1; + continue; + } else if (c=='.') { + if (base!=10 || scale==INT) + break; + ndigit++; + continue; + } else if ((c=='e'||c=='E') && expseen==0) { + if (base!=10 || scale==INT || ndigit==0) + break; + expseen++; + *np++ = c; + c = getc(iop); + if (c!='+'&&c!='-'&&('0'>c||c>'9')) + break; + } else + break; + } + if (negflg) + lcval = -lcval; + if (c != EOF) { + ungetc(c, iop); + *eofptr = 0; + } else + *eofptr = 1; + if (ptr==NULL || np==numbuf) + return(0); + *np++ = 0; + switch((scale<<4) | size) { + + case (FLOAT<<4) | SHORT: + case (FLOAT<<4) | REGULAR: + **(float **)ptr = atof(numbuf); + break; + + case (FLOAT<<4) | LONG: + **(double **)ptr = atof(numbuf); + break; + + case (INT<<4) | SHORT: + **(short **)ptr = lcval; + break; + + case (INT<<4) | REGULAR: + **(int **)ptr = lcval; + break; + + case (INT<<4) | LONG: + **(long **)ptr = lcval; + break; + } + return(1); +} + +_instr(ptr, type, len, iop, eofptr) +register char *ptr; +register struct _iobuf *iop; +int *eofptr; +{ + register ch; + register char *optr; + int ignstp; + + *eofptr = 0; + optr = ptr; + if (type=='c' && len==30000) + len = 1; + ignstp = 0; + if (type=='s') + ignstp = SPC; + while (_sctab[ch = getc(iop)] & ignstp) + if (ch==EOF) + break; + ignstp = SPC; + if (type=='c') + ignstp = 0; + else if (type=='[') + ignstp = STP; + while (ch!=EOF && (_sctab[ch]&ignstp)==0) { + if (ptr) + *ptr++ = ch; + if (--len <= 0) + break; + ch = getc(iop); + } + if (ch != EOF) { + if (len > 0) + ungetc(ch, iop); + *eofptr = 0; + } else + *eofptr = 1; + if (ptr && ptr!=optr) { + if (type!='c') + *ptr++ = '\0'; + return(1); + } + return(0); +} + +char * +_getccl(s) +register char *s; +{ + register c, t; + + t = 0; + if (*s == '^') { + t++; + s++; + } + for (c = 0; c < 128; c++) + if (t) + _sctab[c] &= ~STP; + else + _sctab[c] |= STP; + while (((c = *s++)&0177) != ']') { + if (t) + _sctab[c++] |= STP; + else + _sctab[c++] &= ~STP; + if (c==0) + return(--s); + } + return(s); +} diff --git a/usr/src/libc/stdio/error.c b/usr/src/libc/stdio/error.c new file mode 100644 index 0000000000..482b0b2bb5 --- /dev/null +++ b/usr/src/libc/stdio/error.c @@ -0,0 +1,12 @@ +#include + +_error(s) +register char *s; +{ + static reentered; + + if (reentered++) + _exit(0177); + write(2, s, strlen(s)); + exit(0176); +} diff --git a/usr/src/libc/stdio/fdopen.c b/usr/src/libc/stdio/fdopen.c new file mode 100644 index 0000000000..d47ad5f3d3 --- /dev/null +++ b/usr/src/libc/stdio/fdopen.c @@ -0,0 +1,30 @@ +/* + * Unix routine to do an "fopen" on file descriptor + * The mode has to be repeated because you can't query its + * status + */ + +#include +#include + +FILE * +fdopen(fd, mode) +register char *mode; +{ + extern int errno; + register FILE *iop; + extern FILE *_lastbuf; + + for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++) + if (iop >= _lastbuf) + return(NULL); + iop->_cnt = 0; + iop->_file = fd; + if (*mode != 'r') { + iop->_flag |= _IOWRT; + if (*mode == 'a') + lseek(fd, 0L, 2); + } else + iop->_flag |= _IOREAD; + return(iop); +} diff --git a/usr/src/libc/stdio/fgetc.c b/usr/src/libc/stdio/fgetc.c new file mode 100644 index 0000000000..3fdee12b52 --- /dev/null +++ b/usr/src/libc/stdio/fgetc.c @@ -0,0 +1,7 @@ +#include + +fgetc(fp) +FILE *fp; +{ + return(getc(fp)); +} diff --git a/usr/src/libc/stdio/fgets.c b/usr/src/libc/stdio/fgets.c new file mode 100644 index 0000000000..fc7ee731c9 --- /dev/null +++ b/usr/src/libc/stdio/fgets.c @@ -0,0 +1,21 @@ +#include + +char * +fgets(s, n, iop) +char *s; +register FILE *iop; +{ + register c; + register char *cs; + + cs = s; + while (--n>0 && (c = getc(iop))>=0) { + *cs++ = c; + if (c=='\n') + break; + } + if (c<0 && cs==s) + return(NULL); + *cs++ = '\0'; + return(s); +} diff --git a/usr/src/libc/stdio/filbuf.c b/usr/src/libc/stdio/filbuf.c new file mode 100644 index 0000000000..7705792966 --- /dev/null +++ b/usr/src/libc/stdio/filbuf.c @@ -0,0 +1,36 @@ +#include +char *malloc(); + +_filbuf(iop) +register FILE *iop; +{ + static char smallbuf[_NFILE]; + + if ((iop->_flag&_IOREAD) == 0) + return(EOF); + if (iop->_flag&_IOSTRG) + return(EOF); +tryagain: + if (iop->_base==NULL) { + if (iop->_flag&_IONBF) { + iop->_base = &smallbuf[fileno(iop)]; + goto tryagain; + } + if ((iop->_base = malloc(BUFSIZ)) == NULL) { + iop->_flag |= _IONBF; + goto tryagain; + } + iop->_flag |= _IOMYBUF; + } + iop->_ptr = iop->_base; + iop->_cnt = read(fileno(iop), iop->_ptr, iop->_flag&_IONBF?1:BUFSIZ); + if (--iop->_cnt < 0) { + if (iop->_cnt == -1) + iop->_flag |= _IOEOF; + else + iop->_flag |= _IOERR; + iop->_cnt = 0; + return(-1); + } + return(*iop->_ptr++&0377); +} diff --git a/usr/src/libc/stdio/flsbuf.c b/usr/src/libc/stdio/flsbuf.c new file mode 100644 index 0000000000..a4763aa5f0 --- /dev/null +++ b/usr/src/libc/stdio/flsbuf.c @@ -0,0 +1,102 @@ +#include + +char *malloc(); + +_flsbuf(c, iop) +register FILE *iop; +{ + register char *base; + register n, rn; + char c1; + extern char _sobuf[]; + + if ((iop->_flag&_IOWRT)==0) + return(EOF); +tryagain: + if (iop->_flag&_IONBF) { + c1 = c; + rn = 1; + n = write(fileno(iop), &c1, rn); + iop->_cnt = 0; + } else { + if ((base=iop->_base)==NULL) { + if (iop==stdout) { + if (isatty(fileno(stdout))) { + iop->_flag |= _IONBF; + goto tryagain; + } + iop->_base = _sobuf; + iop->_ptr = _sobuf; + goto tryagain; + } + if ((iop->_base=base=malloc(BUFSIZ)) == NULL) { + iop->_flag |= _IONBF; + goto tryagain; + } + iop->_flag |= _IOMYBUF; + rn = n = 0; + } else if ((rn = n = iop->_ptr - base) > 0) { + iop->_ptr = base; + n = write(fileno(iop), base, n); + } + iop->_cnt = BUFSIZ-1; + *base++ = c; + iop->_ptr = base; + } + if (rn != n) { + iop->_flag |= _IOERR; + return(EOF); + } + return(c); +} + +fflush(iop) +register struct _iobuf *iop; +{ + register char *base; + register n; + + if ((iop->_flag&(_IONBF|_IOWRT))==_IOWRT + && (base=iop->_base)!=NULL && (n=iop->_ptr-base)>0) { + iop->_ptr = base; + iop->_cnt = BUFSIZ; + if (write(fileno(iop), base, n)!=n) { + iop->_flag |= _IOERR; + return(EOF); + } + } + return(0); +} + +/* + * Flush buffers on exit + */ + +_cleanup() +{ + register struct _iobuf *iop; + extern struct _iobuf *_lastbuf; + + for (iop = _iob; iop < _lastbuf; iop++) + fclose(iop); +} + +fclose(iop) +register struct _iobuf *iop; +{ + register r; + + r = EOF; + if (iop->_flag&(_IOREAD|_IOWRT) && (iop->_flag&_IOSTRG)==0) { + r = fflush(iop); + if (close(fileno(iop)) < 0) + r = EOF; + if (iop->_flag&_IOMYBUF) + free(iop->_base); + if (iop->_flag&(_IOMYBUF|_IONBF)) + iop->_base = NULL; + } + iop->_flag &= ~(_IOREAD|_IOWRT|_IONBF|_IOMYBUF|_IOERR|_IOEOF|_IOSTRG); + iop->_cnt = 0; + return(r); +} diff --git a/usr/src/libc/stdio/fprintf.c b/usr/src/libc/stdio/fprintf.c new file mode 100644 index 0000000000..3abd1f9c83 --- /dev/null +++ b/usr/src/libc/stdio/fprintf.c @@ -0,0 +1,9 @@ +#include + +fprintf(iop, fmt, args) +FILE *iop; +char *fmt; +{ + _doprnt(fmt, &args, iop); + return(ferror(iop)? EOF: 0); +} diff --git a/usr/src/libc/stdio/fputc.c b/usr/src/libc/stdio/fputc.c new file mode 100644 index 0000000000..780547f0cb --- /dev/null +++ b/usr/src/libc/stdio/fputc.c @@ -0,0 +1,7 @@ +#include + +fputc(c, fp) +FILE *fp; +{ + return(putc(c, fp)); +} diff --git a/usr/src/libc/stdio/fputs.c b/usr/src/libc/stdio/fputs.c new file mode 100644 index 0000000000..f5435869e4 --- /dev/null +++ b/usr/src/libc/stdio/fputs.c @@ -0,0 +1,13 @@ +#include + +fputs(s, iop) +register char *s; +register FILE *iop; +{ + register r; + register c; + + while (c = *s++) + r = putc(c, iop); + return(r); +} diff --git a/usr/src/libc/stdio/freopen.c b/usr/src/libc/stdio/freopen.c new file mode 100644 index 0000000000..1ef88b7e70 --- /dev/null +++ b/usr/src/libc/stdio/freopen.c @@ -0,0 +1,28 @@ +#include + +FILE * +freopen(file, mode, iop) +char *file; +register char *mode; +register FILE *iop; +{ + register f; + + fclose(iop); + if (*mode=='w') + f = creat(file, 0666); + else if (*mode=='a') { + if ((f = open(file, 1)) < 0) + f = creat(file, 0666); + lseek(f, 0L, 2); + } else + f = open(file, 0); + if (f < 0) + return(NULL); + iop->_file = f; + if (*mode != 'r') + iop->_flag |= _IOWRT; + else + iop->_flag |= _IOREAD; + return(iop); +} diff --git a/usr/src/libc/stdio/fseek.c b/usr/src/libc/stdio/fseek.c new file mode 100644 index 0000000000..6ac9b3f0df --- /dev/null +++ b/usr/src/libc/stdio/fseek.c @@ -0,0 +1,44 @@ +/* + * Seek for standard library. Coordinates with buffering. + */ + +#include + +long lseek(); + +fseek(iop, offset, ptrname) +FILE *iop; +long offset; +{ + register resync, c; + long p; + + iop->_flag &= ~_IOEOF; + if (iop->_flag&_IOREAD) { + if (ptrname<2 && iop->_base && + !(iop->_flag&_IONBF)) { + c = iop->_cnt; + p = offset; + if (ptrname==0) + p += c - lseek(fileno(iop),0L,1); + else + offset -= c; + if(c>0&&p<=c&&p>=iop->_base-iop->_ptr){ + iop->_ptr += (int)p; + iop->_cnt -= (int)p; + return(0); + } + resync = offset&01; + } else + resync = 0; + p = lseek(fileno(iop), offset-resync, ptrname); + iop->_cnt = 0; + if (resync) + getc(iop); + } + else if (iop->_flag&_IOWRT) { + fflush(iop); + p = lseek(fileno(iop), offset, ptrname); + } + return(p==-1?-1:0); +} diff --git a/usr/src/libc/stdio/ftell.c b/usr/src/libc/stdio/ftell.c new file mode 100644 index 0000000000..b33252b8cd --- /dev/null +++ b/usr/src/libc/stdio/ftell.c @@ -0,0 +1,31 @@ +/* + * Return file offset. + * Coordinates with buffering. + */ + +#include +long lseek(); + + +long ftell(iop) +FILE *iop; +{ + long tres; + register adjust; + + if (iop->_cnt < 0) + iop->_cnt = 0; + if (iop->_flag&_IOREAD) + adjust = - iop->_cnt; + else if (iop->_flag&_IOWRT) { + adjust = 0; + if (iop->_base && (iop->_flag&_IONBF)==0) + adjust = iop->_ptr - iop->_base; + } else + return(-1); + tres = lseek(fileno(iop), 0L, 1); + if (tres<0) + return(tres); + tres += adjust; + return(tres); +} diff --git a/usr/src/libc/stdio/gcvt.c b/usr/src/libc/stdio/gcvt.c new file mode 100644 index 0000000000..db39bb72c9 --- /dev/null +++ b/usr/src/libc/stdio/gcvt.c @@ -0,0 +1,62 @@ +/* + * gcvt - Floating output conversion to + * minimal length string + */ + +char *ecvt(); + +char * +gcvt(number, ndigit, buf) +double number; +char *buf; +{ + int sign, decpt; + register char *p1, *p2; + register i; + + p1 = ecvt(number, ndigit, &decpt, &sign); + p2 = buf; + if (sign) + *p2++ = '-'; + for (i=ndigit-1; i>0 && p1[i]=='0'; i--) + ndigit--; + if (decpt >= 0 && decpt-ndigit > 4 + || decpt < 0 && decpt < -3) { /* use E-style */ + decpt--; + *p2++ = *p1++; + *p2++ = '.'; + for (i=1; i + +#undef getchar + +getchar() +{ + return(getc(stdin)); +} diff --git a/usr/src/libc/stdio/getgrent.c b/usr/src/libc/stdio/getgrent.c new file mode 100644 index 0000000000..bbe7ab71ca --- /dev/null +++ b/usr/src/libc/stdio/getgrent.c @@ -0,0 +1,63 @@ +#include +#include + +#define CL ':' +#define CM ',' +#define NL '\n' +#define MAXGRP 100 + +static char GROUP[] = "/etc/group"; +static FILE *grf = NULL; +static char line[BUFSIZ+1]; +static struct group group; +static char *gr_mem[MAXGRP]; + +setgrent() +{ + if( !grf ) + grf = fopen( GROUP, "r" ); + else + rewind( grf ); +} + +endgrent() +{ + if( grf ){ + fclose( grf ); + grf = NULL; + } +} + +static char * +grskip(p,c) +register char *p; +register c; +{ + while( *p && *p != c ) ++p; + if( *p ) *p++ = 0; + return( p ); +} + +struct group * +getgrent() +{ + register char *p, **q; + + if( !grf && !(grf = fopen( GROUP, "r" )) ) + return(NULL); + if( !(p = fgets( line, BUFSIZ, grf )) ) + return(NULL); + group.gr_name = p; + group.gr_passwd = p = grskip(p,CL); + group.gr_gid = atoi( p = grskip(p,CL) ); + group.gr_mem = gr_mem; + p = grskip(p,CL); + grskip(p,NL); + q = gr_mem; + while( *p ){ + *q++ = p; + p = grskip(p,CM); + } + *q = NULL; + return( &group ); +} diff --git a/usr/src/libc/stdio/getgrgid.c b/usr/src/libc/stdio/getgrgid.c new file mode 100644 index 0000000000..62fa18c0d3 --- /dev/null +++ b/usr/src/libc/stdio/getgrgid.c @@ -0,0 +1,14 @@ +#include + +struct group * +getgrgid(gid) +register gid; +{ + register struct group *p; + struct group *getgrent(); + + setgrent(); + while( (p = getgrent()) && p->gr_gid != gid ); + endgrent(); + return(p); +} diff --git a/usr/src/libc/stdio/getgrnam.c b/usr/src/libc/stdio/getgrnam.c new file mode 100644 index 0000000000..28e4612508 --- /dev/null +++ b/usr/src/libc/stdio/getgrnam.c @@ -0,0 +1,14 @@ +#include + +struct group * +getgrnam(name) +register char *name; +{ + register struct group *p; + struct group *getgrent(); + + setgrent(); + while( (p = getgrent()) && strcmp(p->gr_name,name) ); + endgrent(); + return(p); +} diff --git a/usr/src/libc/stdio/getpass.c b/usr/src/libc/stdio/getpass.c new file mode 100644 index 0000000000..51bf36b72a --- /dev/null +++ b/usr/src/libc/stdio/getpass.c @@ -0,0 +1,40 @@ +#include +#include +#include + +char * +getpass(prompt) +char *prompt; +{ + struct sgttyb ttyb; + int flags; + register char *p; + register c; + FILE *fi; + static char pbuf[9]; + int (*signal())(); + int (*sig)(); + + if ((fi = fopen("/dev/tty", "r")) == NULL) + fi = stdin; + else + setbuf(fi, (char *)NULL); + sig = signal(SIGINT, SIG_IGN); + gtty(fileno(fi), &ttyb); + flags = ttyb.sg_flags; + ttyb.sg_flags &= ~ECHO; + stty(fileno(fi), &ttyb); + fprintf(stderr, prompt); + for (p=pbuf; (c = getc(fi))!='\n' && c!=EOF;) { + if (p < &pbuf[8]) + *p++ = c; + } + *p = '\0'; + fprintf(stderr, "\n"); + ttyb.sg_flags = flags; + stty(fileno(fi), &ttyb); + signal(SIGINT, sig); + if (fi != stdin) + fclose(fi); + return(pbuf); +} diff --git a/usr/src/libc/stdio/getpw.c b/usr/src/libc/stdio/getpw.c new file mode 100644 index 0000000000..22fc86cfff --- /dev/null +++ b/usr/src/libc/stdio/getpw.c @@ -0,0 +1,39 @@ +#include + +getpw(uid, buf) +int uid; +char buf[]; +{ + static FILE *pwf; + register n, c; + register char *bp; + + if(pwf == 0) + pwf = fopen("/etc/passwd", "r"); + if(pwf == NULL) + return(1); + rewind(pwf); + + for (;;) { + bp = buf; + while((c=getc(pwf)) != '\n') { + if(c == EOF) + return(1); + *bp++ = c; + } + *bp++ = '\0'; + bp = buf; + n = 3; + while(--n) + while((c = *bp++) != ':') + if(c == '\n') + return(1); + while((c = *bp++) != ':') { + if(c<'0' || c>'9') + continue; + n = n*10+c-'0'; + } + if(n == uid) + return(0); + } +} diff --git a/usr/src/libc/stdio/getpwent.c b/usr/src/libc/stdio/getpwent.c new file mode 100644 index 0000000000..5aebd40f07 --- /dev/null +++ b/usr/src/libc/stdio/getpwent.c @@ -0,0 +1,66 @@ +#include +#include + +static char PASSWD[] = "/etc/passwd"; +static char EMPTY[] = ""; +static FILE *pwf = NULL; +static char line[BUFSIZ+1]; +static struct passwd passwd; + +setpwent() +{ + if( pwf == NULL ) + pwf = fopen( PASSWD, "r" ); + else + rewind( pwf ); +} + +endpwent() +{ + if( pwf != NULL ){ + fclose( pwf ); + pwf = NULL; + } +} + +static char * +pwskip(p) +register char *p; +{ + while( *p && *p != ':' ) + ++p; + if( *p ) *p++ = 0; + return(p); +} + +struct passwd * +getpwent() +{ + register char *p; + + if (pwf == NULL) { + if( (pwf = fopen( PASSWD, "r" )) == NULL ) + return(0); + } + p = fgets(line, BUFSIZ, pwf); + if (p==NULL) + return(0); + passwd.pw_name = p; + p = pwskip(p); + passwd.pw_passwd = p; + p = pwskip(p); + passwd.pw_uid = atoi(p); + p = pwskip(p); + passwd.pw_gid = atoi(p); + passwd.pw_quota = 0; + passwd.pw_comment = EMPTY; + p = pwskip(p); + passwd.pw_gecos = p; + p = pwskip(p); + passwd.pw_dir = p; + p = pwskip(p); + passwd.pw_shell = p; + while(*p && *p != '\n') p++; + *p = '\0'; + return(&passwd); +} diff --git a/usr/src/libc/stdio/getpwnam.c b/usr/src/libc/stdio/getpwnam.c new file mode 100644 index 0000000000..34cc0e79cc --- /dev/null +++ b/usr/src/libc/stdio/getpwnam.c @@ -0,0 +1,14 @@ +#include + +struct passwd * +getpwnam(name) +char *name; +{ + register struct passwd *p; + struct passwd *getpwent(); + + setpwent(); + while( (p = getpwent()) && strcmp(name,p->pw_name) ); + endpwent(); + return(p); +} diff --git a/usr/src/libc/stdio/getpwuid.c b/usr/src/libc/stdio/getpwuid.c new file mode 100644 index 0000000000..d086574b07 --- /dev/null +++ b/usr/src/libc/stdio/getpwuid.c @@ -0,0 +1,14 @@ +#include + +struct passwd * +getpwuid(uid) +register uid; +{ + register struct passwd *p; + struct passwd *getpwent(); + + setpwent(); + while( (p = getpwent()) && p->pw_uid != uid ); + endpwent(); + return(p); +} diff --git a/usr/src/libc/stdio/gets.c b/usr/src/libc/stdio/gets.c new file mode 100644 index 0000000000..da51cb33cb --- /dev/null +++ b/usr/src/libc/stdio/gets.c @@ -0,0 +1,17 @@ +#include + +char * +gets(s) +char *s; +{ + register c; + register char *cs; + + cs = s; + while ((c = getchar()) != '\n' && c >= 0) + *cs++ = c; + if (c<0 && cs==s) + return(NULL); + *cs++ = '\0'; + return(s); +} diff --git a/usr/src/libc/stdio/getw.c b/usr/src/libc/stdio/getw.c new file mode 100644 index 0000000000..0c78110ab7 --- /dev/null +++ b/usr/src/libc/stdio/getw.c @@ -0,0 +1,16 @@ +#include + +getw(iop) +register FILE *iop; +{ + register i; + register char *p; + int w; + + p = (char *)&w; + for (i=sizeof(int); --i>=0;) + *p++ = getc(iop); + if (feof(iop)) + return(EOF); + return(w); +} diff --git a/usr/src/libc/stdio/intss.c b/usr/src/libc/stdio/intss.c new file mode 100644 index 0000000000..26e8535f01 --- /dev/null +++ b/usr/src/libc/stdio/intss.c @@ -0,0 +1,4 @@ +intss() +{ + return(ttyn(0) != 'x'); +} diff --git a/usr/src/libc/stdio/ios.r b/usr/src/libc/stdio/ios.r new file mode 100644 index 0000000000..6a7aa160c4 --- /dev/null +++ b/usr/src/libc/stdio/ios.r @@ -0,0 +1,685 @@ +.de s +.sp .5v +.. +.de sr +.ft I +.ne 2 +\\$1 +.if t .sp .2 +.br +.ft R +.. +.de it +\fI\\$1\fR +.. +.TL +A New Input-Output Package +.AU +D. M. Ritchie +.AI +.MH +.PP +A new package of IO routines is available. +It was designed with the following goals in mind. +.IP 1. +It should be similar in spirit to the earlier Portable +Library, and, to the extent possible, be compatible with it. +At the same time a few dubious design choices +in the Portable Library will be corrected. +.IP 2. +It must be as efficient as possible, both in time and in space, +so that there will be no hesitation in using it +no matter how critical the application. +.IP 3. +It must be simple to use, and also free of the magic +numbers and mysterious calls the use +of which mars the understandability and portability +of many programs using older packages. +.IP 4. +The interface provided should be applicable on all machines, +whether or not the programs which implement it are directly portable +to other systems, +or to machines other than the PDP11 running a version of Unix. +.PP +It is intended that this package replace the Portable Library. +Although it is not directly compatible, as discussed below, +it is sufficiently similar that +modifying programs to use it should be a simple exercise. +.PP +The most crucial difference between this package and the Portable +Library is that the current offering names streams in terms +of pointers rather than by +the integers known as `file descriptors.' +Thus, for example, the routine which opens a named file +returns a pointer to a certain structure rather than a number; +the routine which reads an open file +takes as an argument the pointer returned from the open call. +.SH +General Usage +.PP +Each program using the library must have the line +.DS + #include +.DE +which defines certain macros and variables. +The library containing the routines is `/usr/lib/libS.a,' +so the command to compile is +.DS + cc . . . \-lS +.DE +All names in the include file intended only for internal use begin +with an underscore `\_' to reduce the possibility +of collision with a user name. +The names intended to be visible outside the package are +.IP stdin 10 +The name of the standard input file +.IP stdout 10 +The name of the standard output file +.IP stderr 10 +The name of the standard error file +.IP EOF 10 +is actually \-1, and is the value returned by +the read routines on end-of-file or error. +.IP NULL 10 +is a notation for the null pointer, returned by +pointer-valued functions +to indicate an error +.IP FILE 10 +expands to `struct \_iob' and is a useful +shorthand when declaring pointers +to streams. +.IP BUFSIZ +is a number (viz. 512) +of the size suitable for an IO buffer supplied by the user. +See +.it setbuf, +below. +.IP "getc, getchar, putc, putchar, feof, ferror, fileno" 10 + +.br +are defined as macros. +Their actions are described below; +they are mentioned here +to point out that it is not possible to +redeclare them +and that they are not actually functions; +thus, for example, they may not have breakpoints set on them. +.PP +The routines in this package, like the Portable +Library, +offer the convenience of automatic buffer allocation +and output flushing where appropriate. +Absent, however, is the facility +of changing the default input and output streams +by assigning to `cin' and `cout.' +The names `stdin,' stdout,' and `stderr' +are in effect constants and may not be assigned to. +.SH +Calls +.PP +The routines in the library are in nearly one-to-one +correspondence with those in the Portable Library. +In several cases the name has been changed. +This is an attempt to reduce confusion. +.s +.sr "FILE *fopen(filename, type) char *filename, *type" +.it Fopen +opens the file and, if needed, allocates a buffer for it. +.it Filename +is a character string specifying the name. +.it Type +is a character string (not a single character). +It may be `"r",' `"w",' or `"a"' to indicate +intent to read, write, or append. +The value returned is a file pointer. +If it is NULL the attempt to open failed. +.s +.sr "FILE *freopen(filename, type, ioptr) char *filename, *type; FILE *ioptr +The stream named by +.it ioptr +is closed, if necessary, and then reopened +as if by +.it fopen. +If the attempt to open fails, NULL is returned, +otherwise +.it ioptr, +which will now refer to the new file. +Often the reopened stream is +.it stdin +or +.it stdout. +.s +.sr "int getc(ioptr) FILE *ioptr +returns the next character from the stream named by +.it ioptr, +which is a pointer to a file such as returned by +.it fopen, +or the name +.it stdin. +The integer EOF is returned on end-of-file or when +an error occurs. +The null character \(aa\e0\(aa is a legal character. +.s +.sr "int fgetc(ioptr) FILE *ioptr +acts like +.it getc +but is a genuine function, +not a macro. +.s +.sr "putc(c, ioptr) FILE *ioptr +.it Putc +writes the character +.it c +on the output stream named by +.it ioptr, +which is a value returned from +.it fopen +or perhaps +.it stdout +or +.it stderr. +The character is returned as value, +but EOF is returned on error. +.s +.sr "fputc(c, ioptr) FILE *ioptr +.it Fputc +acts like +.it putc +but is a genuine +function, not a macro. +.s +.sr "fclose(ioptr) FILE *ioptr +The file corresponding to +.it ioptr +is closed after any buffers are emptied. +A buffer allocated by the IO system is freed. +.it Fclose +is automatic on normal termination of the program. +.s +.sr "fflush(ioptr) FILE *ioptr +Any buffered information on the (output) stream named by +.it ioptr +is written out. +Output files are normally buffered +if and only if they are not directed to the terminal, +but +.it stderr +is unbuffered unless +.it setbuf +is used. +.s +.sr exit(errcode) +.it Exit +terminates the process and returns its argument as status +to the parent. +This is a special version of the routine +which calls +.it fflush +for each output file. +To terminate without flushing, +use +.it \_exit. +.s +.sr "feof(ioptr) FILE *ioptr +returns non-zero when end-of-file +has occurred on the specified input stream. +.s +.sr "ferror(ioptr) FILE *ioptr +returns non-zero when an error has occurred while reading +or writing the named stream. +The error indication lasts until the file has been closed. +.s +.sr "getchar( )" +is identical to +.it "getc(stdin). +.s +.sr "putchar(c)" +is identical to +.it "putc(c, stdout). +.s +.sr "char *gets(s) char *s +reads characters up to a new-line from the standard input. +The new-line character is replaced by a null character. +It is the user's responsibility to make sure that the character array +.it s +is large enough. +.it Gets +returns its argument, or NULL if end-of-file or error occurred. +Note that this routine is not compatible with +.it fgets; +it is included for downward compatibility. +.s +.sr "char *fgets(s, n, ioptr) char *s; FILE *ioptr +reads up to +.it n +characters from the stream +.it ioptr +into the character pointer +.it s. +The read terminates with a new-line character. +The new-line character is placed in the buffer +followed by a null character. +The first argument, +or NULL if error or end-of-file occurred, +is returned. +.s +.sr "puts(s) char *s +writes the null-terminated string (character array) +.it s +on the standard output. +A new-line is appended. +No value is returned. +Note that this routine +is not compatible with +.it fputs; +it is included for downward compatibility. +.s +.sr "*fputs(s, ioptr) char *s; FILE *ioptr +writes the null-terminated string (character array) +.it s +on the stream +.it ioptr. +No new-line is appended. +No value is returned. +.s +.sr "ungetc(c, ioptr) FILE *ioptr +The argument character +.it c +is pushed back on the input stream named by +.it ioptr. +Only one character may be pushed back. +.s +.sr "printf(format, a1, . . .) char *format +.sr "fprintf(ioptr, format, a1, . . .) FILE *ioptr; char *format +.sr "sprintf(s, format, a1, . . .)char *s, *format +.it Printf +writes on the standard output. +.it Fprintf +writes on the named output stream. +.it Sprintf +puts characters in the character array (string) +named by +.it s. +The specifications are as described in section +.it "printf +(III) +of the Unix Programmer's Manual. +There is a new conversion: +.it %m.n\fB\|g\fI +converts a double argument in the style of +.it e +or +.it f +as most appropriate. +.s +.sr "scanf(format, a1, . . .) char *format +.sr "fscanf(ioptr, format, a1, . . .) FILE *ioptr; char *format +.sr "sscanf(s, format, a1, . . .) char *s, *format +.it Scanf +reads from the standard input. +.it Fscanf +reads from the named input stream. +.it Sscanf +reads from the character string +supplied as +.it s. +The specifications are identical +to those of the Portable Library. +.it Scanf +reads characters, interprets +them according to a format, and stores the results in its arguments. +It expects as arguments +a control string +.it format, +described below, +and a set of arguments, +.I +each of which must be a pointer, +.R +indicating where the converted input should be stored. +.PP +The +control string +usually contains +conversion specifications, which are used to direct interpretation +of input sequences. +The control string may contain: +.IP 1. +Blanks, tabs or newlines, which are ignored. +.IP 2. +Ordinary characters (not %) which are expected to match +the next non-space character of the input stream +(where space characters are defined as blank, tab or newline). +.IP 3. +Conversion specifications, consisting of the +character %, an optional assignment suppressing character \**, +an optional numerical maximum field width, and a conversion +character. +.PP +A conversion specification is used to direct the conversion of the +next input field; the result +is placed in the variable pointed to by the corresponding argument, +unless assignment suppression was +indicated by the \** character. +An input field is defined as a string of non-space characters; +it extends either to the next space character or until the field +width, if specified, is exhausted. +.PP +The conversion character indicates the interpretation of the +input field; the corresponding pointer argument must +usually be of a restricted type. +The following conversion characters are legal: +.IP % +indicates that a single % character is expected +in the input stream at this point; +no assignment is done. +.IP d +indicates that a decimal integer is expected +in the input stream; +the corresponding argument should be an integer pointer. +.IP o +indicates that an octal integer is expected in the +input stream; the corresponding argument should be a integer pointer. +.IP x +indicates that a hexadecimal integer is expected in the input stream; +the corresponding argument should be an integer pointer. +.ti -0.2i +.IP s +indicates that a character string is expected; +the corresponding argument should be a character pointer +pointing to an array of characters large enough to accept the +string and a terminating `\e0', which will be added. +The input field is terminated by a space character +or a newline. +.IP c +indicates that a character is expected; the +corresponding argument should be a character pointer; +the next input character is placed at the indicated spot. +The normal skip over space characters is suppressed +in this case; +to read the next non-space character, try +.I +%1s. +.R +If a field width is given, the corresponding argument +should refer to a character array, and the +indicated number of characters is read. +.IP e +(or +.I f\|\fR) +.R +indicates that a floating point number is expected in the input stream; +the next field is converted accordingly and stored through the +corresponding argument, which should be a pointer to a +.it float. +The input format for +floating point numbers is +an optionally signed +string of digits +possibly containing a decimal point, followed by an optional +exponent field beginning with an E or e followed by an optionally signed integer. +.IP [ +indicates a string not to be delimited by space characters. +The left bracket is followed by a set of characters and a right +bracket; the characters between the brackets define a set +of characters making up the string. +If the first character +is not circumflex (\|^\|), the input field +is all characters until the first character not in the set between +the brackets; if the first character +after the left bracket is ^, the input field is all characters +until the first character which is in the remaining set of characters +between the brackets. +The corresponding argument must point to a character array. +.PP +The conversion characters +.I +d, o +.R +and +.I +x +.R +may be capitalized or preceded +by +.I +l +.R +to indicate that a pointer to +.I +long +.R +rather than +.I +int +.R +is expected. +Similarly, the conversion characters +.I +e +.R +or +.I +f +.R +may be capitalized or +preceded by +.I +l +.R +to indicate that a pointer to +.I +double +.R +rather than +.I +float +.R +is in the argument list. +The character +.I +h +.R +will function similarly in the future to indicate +.I +short +.R +data items. +.PP +For example, the call +.DS +int i; float x; char name[50]; +scanf( "%d%f%s", &i, &x, name); +.DE +with the input line +.DS +25 54.32E\(mi1 thompson +.DE +will assign to +.it i +the value +25, +.it x +the value 5.432, and +.it name +will contain +.it ``thompson\e0''. +Or, +.DS +int i; float x; char name[50]; +scanf("%2d%f%\**d%[1234567890]", &i, &x, name); +.DE +with input +.DS +56789 0123 56a72 +.DE +will assign 56 to +.it i, +789.0 to +.it x, +skip ``0123'', +and place the string ``56\e0'' in +.it name. +The next call to +.it getchar +will return `a'. +.PP +.it Scanf +returns as its value the number of successfully matched and assigned input +items. +This can be used to decide how many input items were found. +On end of file, EOF is returned; note that this is different +from 0, which means that the next input character does not +match what was called for in the control string. +.s +.sr "fread(ptr, sizeof(*ptr), nitems, ioptr) FILE *ioptr +reads +.it nitems +of data beginning at +.it ptr +from file +.it ioptr. +It behaves identically to the Portable Library's +.it cread. +No advance notification +that binary IO is being done is required; +when, for portability reasons, +it becomes required, it will be done +by adding an additional character to the mode-string on the +fopen call. +.s +.sr "fwrite(ptr, sizeof(*ptr), nitems, ioptr) FILE *ioptr +Like +.it fread, +but in the other direction. +.s +.sr "rewind(ioptr) FILE *ioptr +rewinds the stream +named by +.it ioptr. +It is not very useful except on input, +since a rewound output file is still open only for output. +.s +.sr "system(string) char *string +The +.it string +is executed by the shell as if typed at the terminal. +.s +.sr "getw(ioptr) FILE *ioptr +returns the next word from the input stream named by +.it ioptr. +EOF is returned on end-of-file or error, +but since this a perfectly good +integer +.it feof +and +.it ferror +should be used. +.s +.sr "putw(w, ioptr) FILE *ioptr +writes the integer +.it w +on the named output stream. +.s +.sr "setbuf(ioptr, buf) FILE *ioptr; char *buf +.it Setbuf +may be used after a stream has been opened +but before IO has started. +If +.it buf +is NULL, +the stream will be unbuffered. +Otherwise the buffer supplied will be used. +It is a character array of sufficient size: +.DS +char buf[BUFSIZ]; +.DE +.s +.sr "fileno(ioptr) FILE *ioptr +returns the integer file descriptor associated with the file. +.s +.sr "fseek(ioptr, offset, ptrname) FILE *ioptr; long offset +The location of the next byte in the stream +named by +.it ioptr +is adjusted. +.it Offset +is a long integer. +If +.it ptrname +is 0, the offset is measured from the beginning of the file; +if +.it ptrname +is 1, the offset is measured from the current read or +write pointer; +if +.it ptrname +is 2, the offset is measured from the end of the file. +The routine accounts properly for any buffering. +(When this routine is used on non-Unix systems, +the offset must be a value returned from +.it ftell +and the ptrname must be 0). +.s +.sr "long ftell(ioptr) FILE *ioptr +The byte offset, measured from the beginning of the file, +associated with the named stream is returned. +Any buffering is properly accounted for. +(On non-Unix systems the value of this call is useful only +for handing to +.it fseek, +so as to position the file to the same place it was when +.it ftell +was called.) +.s +.sr "getpw(uid, buf) char *buf +The password file is searched for the given integer user ID. +If an appropriate line is found, it is copied into +the character array +.it buf, +and 0 is returned. +If no line is found corresponding to the user ID +then 1 is returned. +.s +.sr "char *calloc(num, size) +allocates space for +.it num +items each of size +.it size. +The space is guaranteed to be set to 0 and the pointer is +sufficiently well aligned to be usable for any purpose. +NULL is returned if no space is available. +.s +.sr "cfree(ptr) char *ptr +Space is returned to the pool used by +.it calloc. +Disorder can be expected if the pointer was not obtained +from +.it calloc. +.LP +The following are macros defined by stdio.h. +.s +.sr isalpha(c) +returns non-zero if the argument is alphabetic. +.s +.sr isupper(c) +returns non-zero if the argument is upper-case alphabetic. +.s +.sr islower(c) +returns non-zero if the argument is lower-case alphabetic. +.s +.sr isdigit(c) +returns non-zero if the argument is a digit. +.s +.sr isspace(c) +returns non-zero if the argument is a spacing character: +tab, new-line, carriage return, vertical tab, +form feed, space. +.s +.sr toupper(c) +returns the upper-case character corresponding to the lower-case +letter c. +.s +.sr tolower(c) +returns the lower-case character corresponding to the upper-case +letter c. diff --git a/usr/src/libc/stdio/portli.cc b/usr/src/libc/stdio/portli.cc new file mode 100644 index 0000000000..480d069d99 --- /dev/null +++ b/usr/src/libc/stdio/portli.cc @@ -0,0 +1,136 @@ +#include +#define ntof(n) (&_iob[n]) + +int cin 0; +int cout 1; + +cclose(n) +{ + return(fclose(ntof(n))); +} + +ceof(n) +{ + return(feof(ntof(n))); +} + +cexit(x) +{ + exit(x); +} + +cflush(n) +{ + return(fflush(ntof(n))); +} + +cgetc(n) +{ + register c; + + if ((c = getc(ntof(n))) < 0) + return(0); + return(c); +} + +copen(f, m) +char m; +{ + register struct _iobuf *iop; + + if ((iop = fopen(f, &m)) == NULL) + return(-1); + return(fileno(iop)); +} + +cputc(c, n) +{ + putc(c, ntof(n)); +} + +cread(a, b, c, n) +{ + return(fread(a, b, c, ntof(n))); +} + +cwrite(a, b, c, n) +{ + return(fwrite(a, b, c, ntof(n))); +} +getcharz() +{ + register c; + + if ((c = getc(ntof(cin))) < 0) + return(0); + return(c); +} + +printf(a, b, c, d) +{ + struct _iobuf _strbuf; + if (a==-1) { + _strbuf._flag = _IOWRT+_IOSTRG; + _strbuf._ptr = b; + _strbuf._cnt = 32767; + _doprnt(c, &d, &_strbuf); + putc('\0', &_strbuf); + } else if (a<=10) { + _doprnt(b, &c, ntof(a)); + } else + _doprnt(a, &b, ntof(cout)); +} + +putcharz(c) +{ + return(putc(c, ntof(cout))); +} + +gets(s) +char *s; +{ + register c; + register char *cs; + + cs = s; + while ((c = getc(ntof(cin))) != '\n' && c>=0) + *cs++ = c; + if (c<0 && cs==s) + return(NULL); + *cs++ = '\0'; + return(s); +} + +puts(s) +char *s; +{ + register c; + + while (c = *s++) + putc(c, ntof(cout)); + putc('\n', ntof(cout)); +} + +rew(n) +{ + rewind(ntof(n)); +} + +scanf(a, b, c, d) +{ + struct _iobuf strbuf; + register char *s; + + if (a == -1) { + strbuf._flag = _IOREAD|_IOSTRG; + strbuf._ptr = strbuf._base = b; + strbuf._cnt = 0; + s = b; + while (*s++) + strbuf._cnt++; + return(_doscan(&strbuf, c, &d)); + } else if (a<=10) + return(_doscan(ntof(a), b, &c)); + else + return(_doscan(ntof(cin), a, &b)); +} diff --git a/usr/src/libc/stdio/printf.c b/usr/src/libc/stdio/printf.c new file mode 100644 index 0000000000..bfc28fb6e5 --- /dev/null +++ b/usr/src/libc/stdio/printf.c @@ -0,0 +1,8 @@ +#include + +printf(fmt, args) +char *fmt; +{ + _doprnt(fmt, &args, stdout); + return(ferror(stdout)? EOF: 0); +} diff --git a/usr/src/libc/stdio/putchar.c b/usr/src/libc/stdio/putchar.c new file mode 100644 index 0000000000..83ad2c66b1 --- /dev/null +++ b/usr/src/libc/stdio/putchar.c @@ -0,0 +1,12 @@ +/* + * A subroutine version of the macro putchar + */ +#include + +#undef putchar + +putchar(c) +register c; +{ + putc(c, stdout); +} diff --git a/usr/src/libc/stdio/puts.c b/usr/src/libc/stdio/puts.c new file mode 100644 index 0000000000..45fd37b3ba --- /dev/null +++ b/usr/src/libc/stdio/puts.c @@ -0,0 +1,11 @@ +#include + +puts(s) +register char *s; +{ + register c; + + while (c = *s++) + putchar(c); + return(putchar('\n')); +} diff --git a/usr/src/libc/stdio/putw.c b/usr/src/libc/stdio/putw.c new file mode 100644 index 0000000000..b77541385c --- /dev/null +++ b/usr/src/libc/stdio/putw.c @@ -0,0 +1,13 @@ +#include + +putw(w, iop) +register FILE *iop; +{ + register char *p; + register i; + + p = (char *)&w; + for (i=sizeof(int); --i>=0;) + putc(*p++, iop); + return(ferror(iop)); +} diff --git a/usr/src/libc/stdio/rdwr.c b/usr/src/libc/stdio/rdwr.c new file mode 100644 index 0000000000..26385a8946 --- /dev/null +++ b/usr/src/libc/stdio/rdwr.c @@ -0,0 +1,44 @@ +#include + +fread(ptr, size, count, iop) +unsigned size, count; +register char *ptr; +register FILE *iop; +{ + register c; + unsigned ndone, s; + + ndone = 0; + if (size) + for (; ndone= 0) + *ptr++ = c; + else + return(ndone); + } while (--s); + } + return(ndone); +} + +fwrite(ptr, size, count, iop) +unsigned size, count; +register char *ptr; +register FILE *iop; +{ + register unsigned s; + unsigned ndone; + + ndone = 0; + if (size) + for (; ndone + +rewind(iop) +register struct _iobuf *iop; +{ + fflush(iop); + lseek(fileno(iop), 0L, 0); + iop->_cnt = 0; + iop->_ptr = iop->_base; + iop->_flag &= ~(_IOERR|_IOEOF); +} diff --git a/usr/src/libc/stdio/scanf.c b/usr/src/libc/stdio/scanf.c new file mode 100644 index 0000000000..012c56777d --- /dev/null +++ b/usr/src/libc/stdio/scanf.c @@ -0,0 +1,28 @@ +#include + +scanf(fmt, args) +char *fmt; +{ + return(_doscan(stdin, fmt, &args)); +} + +fscanf(iop, fmt, args) +FILE *iop; +char *fmt; +{ + return(_doscan(iop, fmt, &args)); +} + +sscanf(str, fmt, args) +register char *str; +char *fmt; +{ + FILE _strbuf; + + _strbuf._flag = _IOREAD|_IOSTRG; + _strbuf._ptr = _strbuf._base = str; + _strbuf._cnt = 0; + while (*str++) + _strbuf._cnt++; + return(_doscan(&_strbuf, fmt, &args)); +} diff --git a/usr/src/libc/stdio/setbuf.c b/usr/src/libc/stdio/setbuf.c new file mode 100644 index 0000000000..58aa65a469 --- /dev/null +++ b/usr/src/libc/stdio/setbuf.c @@ -0,0 +1,15 @@ +#include + +setbuf(iop, buf) +register struct _iobuf *iop; +char *buf; +{ + if (iop->_base != NULL && iop->_flag&_IOMYBUF) + free(iop->_base); + iop->_flag &= ~(_IOMYBUF|_IONBF); + if ((iop->_base = buf) == NULL) + iop->_flag |= _IONBF; + else + iop->_ptr = iop->_base; + iop->_cnt = 0; +} diff --git a/usr/src/libc/stdio/sprintf.c b/usr/src/libc/stdio/sprintf.c new file mode 100644 index 0000000000..a9c5ef9d99 --- /dev/null +++ b/usr/src/libc/stdio/sprintf.c @@ -0,0 +1,14 @@ +#include + +char *sprintf(str, fmt, args) +char *str, *fmt; +{ + struct _iobuf _strbuf; + + _strbuf._flag = _IOWRT+_IOSTRG; + _strbuf._ptr = str; + _strbuf._cnt = 32767; + _doprnt(fmt, &args, &_strbuf); + putc('\0', &_strbuf); + return(str); +} diff --git a/usr/src/libc/stdio/strout.c b/usr/src/libc/stdio/strout.c new file mode 100644 index 0000000000..545a0018c3 --- /dev/null +++ b/usr/src/libc/stdio/strout.c @@ -0,0 +1,23 @@ +#include + +_strout(count, string, adjust, file, fillch) +register char *string; +register count; +int adjust; +register struct _iobuf *file; +{ + while (adjust < 0) { + if (*string=='-' && fillch=='0') { + putc(*string++, file); + count--; + } + putc(fillch, file); + adjust++; + } + while (--count>=0) + putc(*string++, file); + while (adjust) { + putc(fillch, file); + adjust--; + } +} diff --git a/usr/src/libc/stdio/stuff.c b/usr/src/libc/stdio/stuff.c new file mode 100644 index 0000000000..10b0ed13cd --- /dev/null +++ b/usr/src/libc/stdio/stuff.c @@ -0,0 +1,6 @@ +int yyportlib =1; + +wdleng() +{ + return(32); +} diff --git a/usr/src/libc/stdio/tmpnam.c b/usr/src/libc/stdio/tmpnam.c new file mode 100644 index 0000000000..b8035332ad --- /dev/null +++ b/usr/src/libc/stdio/tmpnam.c @@ -0,0 +1,8 @@ +char *tmpnam(s) +char *s; +{ + static seed; + + sprintf(s, "temp.%d.%d", getpid(), seed++); + return(s); +} diff --git a/usr/src/libc/stdio/ungetc.c b/usr/src/libc/stdio/ungetc.c new file mode 100644 index 0000000000..23c525498d --- /dev/null +++ b/usr/src/libc/stdio/ungetc.c @@ -0,0 +1,16 @@ +#include + +ungetc(c, iop) +register FILE *iop; +{ + if (c == EOF) + return(-1); + if ((iop->_flag&_IOREAD)==0 || iop->_ptr <= iop->_base) + if (iop->_ptr == iop->_base && iop->_cnt==0) + *iop->_ptr++; + else + return(-1); + iop->_cnt++; + *--iop->_ptr = c; + return(0); +} diff --git a/usr/src/libc/sys/_exit.s b/usr/src/libc/sys/_exit.s new file mode 100644 index 0000000000..000f393380 --- /dev/null +++ b/usr/src/libc/sys/_exit.s @@ -0,0 +1,14 @@ +# C library -- _exit + +# _exit(code) +# code is return in r0 to system +# Same as plain exit, for user who want to define their own exit. + + .set exit,1 +.globl __exit + + .align 1 +__exit: + .word 0x0000 + chmk $exit + halt diff --git a/usr/src/libc/sys/abort.s b/usr/src/libc/sys/abort.s new file mode 100644 index 0000000000..7acecb27bd --- /dev/null +++ b/usr/src/libc/sys/abort.s @@ -0,0 +1,10 @@ +# C library -- abort + +.globl _abort + + .align 1 +_abort: + .word 0x0000 + halt + clrl r0 + ret diff --git a/usr/src/libc/sys/abs.s b/usr/src/libc/sys/abs.s new file mode 100644 index 0000000000..a0a92bb678 --- /dev/null +++ b/usr/src/libc/sys/abs.s @@ -0,0 +1,22 @@ +# abs - int absolute value. +# fabs - floating abs + +.globl _abs + .align 1 +_abs: + .word 0x0000 + movl 4(ap),r0 + bgeq absl + mnegl r0,r0 +absl: + ret + +.globl _fabs + .align 1 +_fabs: + .word 0x0000 + movd 4(ap),r0 + bgeq fabsl + mnegd r0,r0 +fabsl: + ret diff --git a/usr/src/libc/sys/access.s b/usr/src/libc/sys/access.s new file mode 100644 index 0000000000..a70f1f8b73 --- /dev/null +++ b/usr/src/libc/sys/access.s @@ -0,0 +1,16 @@ +# access(file, request) +# test ability to access file in all indicated ways +# 1 - read +# 2 - write +# 4 - execute + + .set access,33 +.globl _access + +_access: + .word 0x0000 + chmk $access + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/acct.s b/usr/src/libc/sys/acct.s new file mode 100644 index 0000000000..8703355afc --- /dev/null +++ b/usr/src/libc/sys/acct.s @@ -0,0 +1,13 @@ +# C library -- acct + + .set acct,51 +.globl _acct +.globl cerror + +_acct: + .word 0x0000 + chmk $acct + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/alarm.s b/usr/src/libc/sys/alarm.s new file mode 100644 index 0000000000..461c330ea4 --- /dev/null +++ b/usr/src/libc/sys/alarm.s @@ -0,0 +1,18 @@ +# C library - alarm, pause + + .set alarm,27 +.globl _alarm + .set pause,29 +.globl _pause + + .align 1 +_alarm: + .word 0x0000 + chmk $alarm + ret + + .align 1 +_pause: + .word 0x0000 + chmk $pause + ret diff --git a/usr/src/libc/sys/alloca.s b/usr/src/libc/sys/alloca.s new file mode 100644 index 0000000000..2a51f6ed4e --- /dev/null +++ b/usr/src/libc/sys/alloca.s @@ -0,0 +1,13 @@ +# like alloc, but automatic +# automatic free in return + +.globl _alloca +_alloca: + .word 0x0000 + subl2 4(ap),sp # crude allocation + movl 16(fp),r1 # pc + movq 8(fp),ap # new (old) ap and fp + bicl2 $3,sp # 4-byte align + addl2 $7*4,sp # reuse space of mscp + movl sp,r0 # return value + jmp (r1) # funny return diff --git a/usr/src/libc/sys/cerror.s b/usr/src/libc/sys/cerror.s new file mode 100644 index 0000000000..3859b03b08 --- /dev/null +++ b/usr/src/libc/sys/cerror.s @@ -0,0 +1,10 @@ +# C return sequence which +# sets errno, returns -1. + +.globl cerror +.comm _errno,4 + +cerror: + movl r0,_errno + mnegl $1,r0 + ret diff --git a/usr/src/libc/sys/chdir.s b/usr/src/libc/sys/chdir.s new file mode 100644 index 0000000000..913e6ef5ee --- /dev/null +++ b/usr/src/libc/sys/chdir.s @@ -0,0 +1,15 @@ +# C library -- chdir + +# error = chdir(string); + + .set chdir,12 +.globl _chdir + +_chdir: + .word 0x0000 + chmk $chdir + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/chmod.s b/usr/src/libc/sys/chmod.s new file mode 100644 index 0000000000..cc2e8338d6 --- /dev/null +++ b/usr/src/libc/sys/chmod.s @@ -0,0 +1,15 @@ +# C library -- chmod + +# error = chmod(string, mode); + + .set chmod,15 +.globl _chmod + +_chmod: + .word 0x0000 + chmk $chmod + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/chown.s b/usr/src/libc/sys/chown.s new file mode 100644 index 0000000000..ec49e51bd1 --- /dev/null +++ b/usr/src/libc/sys/chown.s @@ -0,0 +1,15 @@ +# C library -- chown + +# error = chown(string, owner); + + .set chown,16 +.globl _chown + +_chown: + .word 0x0000 + chmk $chown + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/chroot.s b/usr/src/libc/sys/chroot.s new file mode 100644 index 0000000000..139df3f2d2 --- /dev/null +++ b/usr/src/libc/sys/chroot.s @@ -0,0 +1,15 @@ +# C library -- chroot + +# error = chroot(string); + + .set chroot,61 + +.globl _chroot +.globl cerror +_chroot: + .word 0x0000 + chmk $chroot + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/cleanup.s b/usr/src/libc/sys/cleanup.s new file mode 100644 index 0000000000..75e7782b24 --- /dev/null +++ b/usr/src/libc/sys/cleanup.s @@ -0,0 +1,8 @@ +# +# dummy cleanup routine if none supplied by user. + +.globl __cleanup + +__cleanup: + .word 0x0000 + ret diff --git a/usr/src/libc/sys/close.s b/usr/src/libc/sys/close.s new file mode 100644 index 0000000000..dfec1113e7 --- /dev/null +++ b/usr/src/libc/sys/close.s @@ -0,0 +1,15 @@ +# C library -- close + +# error = close(file); + + .set close,6 +.globl _close + +_close: + .word 0x0000 + chmk $close + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/creat.s b/usr/src/libc/sys/creat.s new file mode 100644 index 0000000000..933b55067e --- /dev/null +++ b/usr/src/libc/sys/creat.s @@ -0,0 +1,16 @@ +# C library -- creat + +# file = creat(string, mode); +# +# file == -1 if error + + .set creat,8 +.globl _creat + +_creat: + .word 0x0000 + chmk $creat + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/crt0.s b/usr/src/libc/sys/crt0.s new file mode 100644 index 0000000000..90fa265e50 --- /dev/null +++ b/usr/src/libc/sys/crt0.s @@ -0,0 +1,33 @@ +# C runtime startoff + + .set exit,1 +.globl _exit +.globl start +.globl _main +.globl _environ + +# +# C language startup routine + +start: + .word 0x0000 + subl2 $8,sp + movl 8(sp),(sp) # argc + movab 12(sp),r0 + movl r0,4(sp) # argv +L1: + tstl (r0)+ # null args term ? + bneq L1 + cmpl r0,*4(sp) # end of 'env' or 'argv' ? + blss L2 + tstl -(r0) # envp's are in list +L2: + movl r0,8(sp) # env + movl r0,_environ # indir is 0 if no env ; not 0 if env + calls $3,_main + pushl r0 + calls $1,_exit + chmk $exit +# + .data +_environ: .space 4 diff --git a/usr/src/libc/sys/dup.s b/usr/src/libc/sys/dup.s new file mode 100644 index 0000000000..bcd847eea0 --- /dev/null +++ b/usr/src/libc/sys/dup.s @@ -0,0 +1,22 @@ +# C library -- dup + +# f = dup(of [ ,nf]) +# f == -1 for error + + .set dup,41 +.globl _dup +.globl _dup2 +.globl cerror + +_dup2: + .word 0x0000 + bisb2 $0100,4(ap) + brb L1 +_dup: + .word 0x0000 +L1: + chmk $dup + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/execl.s b/usr/src/libc/sys/execl.s new file mode 100644 index 0000000000..43c2a89616 --- /dev/null +++ b/usr/src/libc/sys/execl.s @@ -0,0 +1,13 @@ +# C library -- execl + +# execl(file, arg1, arg2, ... , 0); +# + +.globl _execl + +_execl: + .word 0x0000 + pushab 8(ap) + pushl 4(ap) + calls $2,_execv + ret diff --git a/usr/src/libc/sys/execle.s b/usr/src/libc/sys/execle.s new file mode 100644 index 0000000000..d02bf1bb6e --- /dev/null +++ b/usr/src/libc/sys/execle.s @@ -0,0 +1,15 @@ +# C library -- execle + +# execle(file, arg1, arg2, ... , env); +# + +.globl _execle + +_execle: + .word 0x0000 + movl (ap),r0 # nargs + pushl (ap)[r0] # env + pushab 8(ap) # argv + pushl 4(ap) # file + calls $3,_execve + ret diff --git a/usr/src/libc/sys/execv.s b/usr/src/libc/sys/execv.s new file mode 100644 index 0000000000..87faf4e546 --- /dev/null +++ b/usr/src/libc/sys/execv.s @@ -0,0 +1,17 @@ +# C library -- execv + +# execv(file, argv); +# +# where argv is a vector argv[0] ... argv[x], 0 +# last vector element must be 0 + +.globl _execv +.globl _environ + +_execv: + .word 0x0000 + pushl _environ # default environ + pushl 8(ap) # argv + pushl 4(ap) # file + calls $3,_execve + ret diff --git a/usr/src/libc/sys/execve.s b/usr/src/libc/sys/execve.s new file mode 100644 index 0000000000..c240eb0795 --- /dev/null +++ b/usr/src/libc/sys/execve.s @@ -0,0 +1,14 @@ +# C library -- execve + +# execve(file, argv, env); +# +# where argv is a vector argv[0] ... argv[x], 0 +# last vector element must be 0 + + .set exece,59 +.globl _execve + +_execve: + .word 0x0000 + chmk $exece + jmp cerror diff --git a/usr/src/libc/sys/exit.s b/usr/src/libc/sys/exit.s new file mode 100644 index 0000000000..36f14bf6dc --- /dev/null +++ b/usr/src/libc/sys/exit.s @@ -0,0 +1,15 @@ +# C library -- exit + +# exit(code) +# code is return in r0 to system + + .set exit,1 +.globl _exit +.globl __cleanup + + .align 1 +_exit: + .word 0x0000 + calls $0,__cleanup + chmk $exit + halt diff --git a/usr/src/libc/sys/fstat.s b/usr/src/libc/sys/fstat.s new file mode 100644 index 0000000000..6b5aff5f9c --- /dev/null +++ b/usr/src/libc/sys/fstat.s @@ -0,0 +1,17 @@ +# C library -- fstat + +# error = fstat(file, statbuf); + +# char statbuf[34] + + .set fstat,28 +.globl _fstat + +_fstat: + .word 0x0000 + chmk $fstat + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/getcsw.s b/usr/src/libc/sys/getcsw.s new file mode 100644 index 0000000000..18bbe9d7bc --- /dev/null +++ b/usr/src/libc/sys/getcsw.s @@ -0,0 +1,11 @@ +# C library - getcsw + +# csw = getcsw(); + + .set getcsw,38 +.globl _getcsw + +_getcsw: + .word 0x0000 + chmk $getcsw + ret diff --git a/usr/src/libc/sys/getgid.s b/usr/src/libc/sys/getgid.s new file mode 100644 index 0000000000..476bc400bd --- /dev/null +++ b/usr/src/libc/sys/getgid.s @@ -0,0 +1,25 @@ +# C library -- getgid + +# gid = getgid(); +# + + .set getgid,47 +.globl _getgid + +_getgid: + .word 0x0000 + chmk $getgid + ret + +# C library -- getegid + +# gid = getegid(); +# returns effective gid + +.globl _getegid + +_getegid: + .word 0x0000 + chmk $getgid + movl r1,r0 + ret diff --git a/usr/src/libc/sys/getpid.s b/usr/src/libc/sys/getpid.s new file mode 100644 index 0000000000..602e885e89 --- /dev/null +++ b/usr/src/libc/sys/getpid.s @@ -0,0 +1,17 @@ +# getpid -- get process ID + + .set getpid,20 +.globl _getpid + +_getpid: + .word 0x0000 + chmk $getpid + ret + +.globl _getppid + +_getppid: + .word 0x0000 + chmk $getpid + movl r1,r0 + ret diff --git a/usr/src/libc/sys/getuid.s b/usr/src/libc/sys/getuid.s new file mode 100644 index 0000000000..ee6f2e3768 --- /dev/null +++ b/usr/src/libc/sys/getuid.s @@ -0,0 +1,27 @@ +# C library -- getuid + +# uid = getuid(); +# + + .set getuid,24 +.globl _getuid + +_getuid: + .word 0x0000 + chmk $getuid + ret + + + +# C library -- geteuid + +# uid = geteuid(); +# returns effective uid + +.globl _geteuid + +_geteuid: + .word 0x0000 + chmk $getuid + movl r1,r0 + ret diff --git a/usr/src/libc/sys/ioctl.s b/usr/src/libc/sys/ioctl.s new file mode 100644 index 0000000000..3e5c072bfc --- /dev/null +++ b/usr/src/libc/sys/ioctl.s @@ -0,0 +1,18 @@ +# C library -- ioctl + +# ioctl(fdes,command,arg) +# struct * arg; +# +# result == -1 if error + + .set ioctl,54 +.globl _ioctl +.globl cerror + +_ioctl: + .word 0x0000 + chmk $ioctl + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/itol.s b/usr/src/libc/sys/itol.s new file mode 100644 index 0000000000..1764cbcd92 --- /dev/null +++ b/usr/src/libc/sys/itol.s @@ -0,0 +1,12 @@ +# +# Convert pair of integers to a long +# + +.globl _itol + +_itol: + .word 0x0000 + ashl $16,4(ap),r0 + bicl3 $0xffff0000,8(ap),r1 + addl2 r1,r0 + ret diff --git a/usr/src/libc/sys/kill.s b/usr/src/libc/sys/kill.s new file mode 100644 index 0000000000..6d5ba88438 --- /dev/null +++ b/usr/src/libc/sys/kill.s @@ -0,0 +1,14 @@ +# C library -- kill + + .set kill,37 +.globl _kill +.globl cerror + +_kill: + .word 0x0000 + chmk $kill + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/link.s b/usr/src/libc/sys/link.s new file mode 100644 index 0000000000..d1aec44a0d --- /dev/null +++ b/usr/src/libc/sys/link.s @@ -0,0 +1,17 @@ +# C library -- link + +# error = link(old-file, new-file); +# + + .set link,9 +.globl _link +.globl cerror + +_link: + .word 0x0000 + chmk $link + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/locv.s b/usr/src/libc/sys/locv.s new file mode 100644 index 0000000000..e02a2e8e42 --- /dev/null +++ b/usr/src/libc/sys/locv.s @@ -0,0 +1,15 @@ +# C library -- long output conversion + +.globl _locv + +_locv: + .word 0x0000 + subl2 $8,sp + cvtlp 4(ap),$11,(sp) + editpc $11,(sp),edpat,str + skpc $' ,$11,str + movl r1,r0 + ret + .data +edpat: .byte 0xaa,0x01,0x91,0x44,0x00,0x00 +str: .space 13 diff --git a/usr/src/libc/sys/ltod.s b/usr/src/libc/sys/ltod.s new file mode 100644 index 0000000000..36d7b05d71 --- /dev/null +++ b/usr/src/libc/sys/ltod.s @@ -0,0 +1,18 @@ +# C library +# return floating-point from long integer +# d = ltod(l) + +.globl _ltod +_ltod: + .word 0x0000 + cvtld 4(ap),r0 + ret + +# return long integer from floating +# dtol(d, l) + +.globl _dtol +_dtol: + .word 0x0000 + cvtdl 4(ap),*12(ap) + ret diff --git a/usr/src/libc/sys/ltoi.s b/usr/src/libc/sys/ltoi.s new file mode 100644 index 0000000000..b01ae7cc80 --- /dev/null +++ b/usr/src/libc/sys/ltoi.s @@ -0,0 +1,8 @@ +# +# ltoi(long) returns the long as an int. + +.globl _ltoi +_ltoi: + .word 0x0000 + movl 4(ap),r0 + ret diff --git a/usr/src/libc/sys/makdir.s b/usr/src/libc/sys/makdir.s new file mode 100644 index 0000000000..dd4596ca69 --- /dev/null +++ b/usr/src/libc/sys/makdir.s @@ -0,0 +1,16 @@ +# C library -- makdir + +# error = makdir(string); + + .set mknod,14 +.globl _makdir +.globl cerror + +_makdir: + .word 0x0000 + chmk $mknod + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/mcount.s b/usr/src/libc/sys/mcount.s new file mode 100644 index 0000000000..e9d84a73c5 --- /dev/null +++ b/usr/src/libc/sys/mcount.s @@ -0,0 +1,19 @@ +# count subroutine called during profiling + +.globl mcount +.comm countbase,4 + +mcount: + movl (r0),r1 + beql init +incr: + incl (r1) +return: + rsb +init: + movl countbase,r1 + beql return + addl2 $8,countbase + movl (sp),(r1)+ + movl r1,(r0) + brb incr diff --git a/usr/src/libc/sys/mcrt0.s b/usr/src/libc/sys/mcrt0.s new file mode 100644 index 0000000000..fdc0dc16e9 --- /dev/null +++ b/usr/src/libc/sys/mcrt0.s @@ -0,0 +1,83 @@ +# C runtime startoff including monitoring + + .set exit,1 + .set cbufs,300 + +.globl start +.globl _monitor +.globl _sbrk +.globl _main +.globl _exit +.globl _IEH3exit +.globl _etext +.globl _environ +.globl __cleanup +.comm countbase,4 + + +start: + .word 0x0000 + subl2 $8,sp + movl 8(sp),(sp) # argc + movab 12(sp),r0 + movl r0,4(sp) # argv +L1: + tstl (r0)+ # null args term ? + bneq L1 + cmpl r0,*4(sp) # end of 'env' or 'argv' ? + blss L2 + tstl -(r0) # envp's are in list +L2: + movl r0,8(sp) # env + movl r0,_environ # indir is 0 if no env ; not 0 if env + + subl3 $eprol,$_etext,r1 + addl2 $7,r1 + extzv $3,$16,r1,r1 + addl2 r1,r1 # tally size + addl2 $8*cbufs+12,r1 # entrance count plus header + pushl $cbufs # # entrance counters + pushl r1 # bufsiz + pushl r1 # for sbrk + calls $1,_sbrk + cmpl r0,$-1 + beql nospace +# bandaid for sbrk not clearing memory (remove bandaid when fixed) +# addl3 (sp),(sp),r1 +#L100: +# clrb -1(r0)[r1] +# sobgtr r1,L100 +# end bandaid + pushl r0 + addl3 $12,r0,countbase + pushab _etext + pushab eprol + calls $5,_monitor + calls $3,_main + pushl r0 + calls $1,_exit + + .data +_environ: .space 4 +emsg: + .byte 'N,'o,' ,'s,'p,'a,'c,'e,' ,'f,'o,'r,' + .byte 'm,'o,'n,'i,'t,'o,'r,' ,'b,'u,'f,'f,'e,'r,0xa,0x0 +em1: + .text + +nospace: + pushl $em1-emsg + pushab emsg + pushl $2 + calls $3,_write + +_exit: +_IEH3exit: + .word 0x0000 + calls $0,__cleanup + pushl $0 + calls $1,_monitor + chmk $exit +eprol: + + diff --git a/usr/src/libc/sys/mdate.s b/usr/src/libc/sys/mdate.s new file mode 100644 index 0000000000..b4596d6d76 --- /dev/null +++ b/usr/src/libc/sys/mdate.s @@ -0,0 +1,14 @@ +# C library-- mdate + + .set mdate,30 +.globl _mdate +.globl cerror + +_mdate: + .word 0x0000 + chmk $mdate + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/mknod.s b/usr/src/libc/sys/mknod.s new file mode 100644 index 0000000000..218a43a395 --- /dev/null +++ b/usr/src/libc/sys/mknod.s @@ -0,0 +1,16 @@ +# C library -- mknod + +# error = mknod(string, mode, major.minor); + + .set mknod,14 +.globl _mknod +.globl cerror + +_mknod: + .word 0x0000 + chmk $mknod + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/mount.s b/usr/src/libc/sys/mount.s new file mode 100644 index 0000000000..d4273ebc09 --- /dev/null +++ b/usr/src/libc/sys/mount.s @@ -0,0 +1,16 @@ +# C library -- mount + +# error = mount(dev, file, flag) + + .set mount,21 +.globl _mount +.globl cerror + +_mount: + .word 0x0000 + chmk $mount + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/nargs.s b/usr/src/libc/sys/nargs.s new file mode 100644 index 0000000000..a493983c7a --- /dev/null +++ b/usr/src/libc/sys/nargs.s @@ -0,0 +1,9 @@ +# C library -- nargs + + +.globl _nargs + +_nargs: + .word 0x0000 + movzbl *8(fp),r0 # 8(fp) is old ap + ret diff --git a/usr/src/libc/sys/nexect.s b/usr/src/libc/sys/nexect.s new file mode 100644 index 0000000000..865313e5b6 --- /dev/null +++ b/usr/src/libc/sys/nexect.s @@ -0,0 +1,20 @@ +# C library -- exect + +# exect(file, argv, env); +# +# where argv is a vector argv[0] ... argv[x], 0 +# last vector element must be 0 +# +# The same as execve except that it sets the TBIT causing +# a trace trap on the first instruction of the executed process, +# to give a chance to set breakpoints. + +.globl _exect +.globl cerror + + .set execve,59 +_exect: + .word 0x0000 + bispsw $0x10 # set tbit + chmk $execve + jmp cerror diff --git a/usr/src/libc/sys/nice.s b/usr/src/libc/sys/nice.s new file mode 100644 index 0000000000..41bcd29e4c --- /dev/null +++ b/usr/src/libc/sys/nice.s @@ -0,0 +1,16 @@ +# C library-- nice + +# error = nice(hownice) + + .set nice,34 +.globl _nice +.globl cerror + +_nice: + .word 0x0000 + chmk $nice + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/open.s b/usr/src/libc/sys/open.s new file mode 100644 index 0000000000..4da292b69b --- /dev/null +++ b/usr/src/libc/sys/open.s @@ -0,0 +1,17 @@ +# C library -- open + +# file = open(string, mode) +# +# file == -1 means error + + .set open,5 +.globl _open +.globl cerror + +_open: + .word 0x0000 + chmk $open + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/pipe.s b/usr/src/libc/sys/pipe.s new file mode 100644 index 0000000000..fe28ed0cf7 --- /dev/null +++ b/usr/src/libc/sys/pipe.s @@ -0,0 +1,20 @@ +# pipe -- C library + +# pipe(f) +# int f[2]; + + .set pipe,42 +.globl _pipe +.globl cerror + +_pipe: + .word 0x0000 + chmk $pipe + bcc noerror + jmp cerror +noerror: + movl 4(ap),r2 + movl r0,(r2)+ + movl r1,(r2) + clrl r0 + ret diff --git a/usr/src/libc/sys/prof.s b/usr/src/libc/sys/prof.s new file mode 100644 index 0000000000..bac187b8e4 --- /dev/null +++ b/usr/src/libc/sys/prof.s @@ -0,0 +1,8 @@ +# profil + + .set prof,44 +.globl _profil +_profil: + .word 0x0000 + chmk $prof + ret diff --git a/usr/src/libc/sys/ptrace.s b/usr/src/libc/sys/ptrace.s new file mode 100644 index 0000000000..be6b9dbade --- /dev/null +++ b/usr/src/libc/sys/ptrace.s @@ -0,0 +1,17 @@ +# ptrace -- C library + +# result = ptrace(req, pid, addr, data); + + .set ptrace,26 +.globl _ptrace +.globl cerror +.globl _errno + +_ptrace: + .word 0x0000 + clrl _errno + chmk $ptrace + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/read.s b/usr/src/libc/sys/read.s new file mode 100644 index 0000000000..e4b1cbfbe8 --- /dev/null +++ b/usr/src/libc/sys/read.s @@ -0,0 +1,17 @@ +# C library -- read + +# nread = read(file, buffer, count); +# +# nread ==0 means eof; nread == -1 means error + + .set read,3 +.globl _read +.globl cerror + +_read: + .word 0x0000 + chmk $read + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/reset.s b/usr/src/libc/sys/reset.s new file mode 100644 index 0000000000..acfce11617 --- /dev/null +++ b/usr/src/libc/sys/reset.s @@ -0,0 +1,45 @@ +# C library -- reset, setexit + +# reset(x) +# will generate a "return" from +# the last call to +# setexit() +# by restoring r6 - r12, ap, fp +# and doing a return. +# The returned value is x; on the original +# call the returned value is 0. +# +# useful for going back to the main loop +# after a horrible error in a lowlevel +# routine. + +.globl _setexit +.globl _reset + + .align 1 +_setexit: + .word 0x0000 + movab setsav,r0 + movq r6,(r0)+ + movq r8,(r0)+ + movq r10,(r0)+ + movq 8(fp),(r0)+ # ap, fp + movab 4(ap),(r0)+ # sp + movl 16(fp),(r0) # pc + clrl r0 + ret + + .align 1 +_reset: + .word 0x0000 + movl 4(ap),r0 # returned value + movab setsav,r1 + movq (r1)+,r6 + movq (r1)+,r8 + movq (r1)+,r10 + movq (r1)+,r12 + movl (r1)+,sp + jmp *(r1) + + .data +setsav: .space 10*4 diff --git a/usr/src/libc/sys/sbrk.s b/usr/src/libc/sys/sbrk.s new file mode 100644 index 0000000000..3b79e1626d --- /dev/null +++ b/usr/src/libc/sys/sbrk.s @@ -0,0 +1,42 @@ +#old = sbrk(increment); +# +#sbrk gets increment more core, and returns a pointer +# to the beginning of the new core area +# + .set break,17 +.globl _sbrk +.globl _end +.globl cerror + + .align 1 +_sbrk: + .word 0x0000 + addl3 nd,4(ap),-(sp) + pushl $1 + movl ap,r3 + movl sp,ap + chmk $break + bcc noerr1 + jmp cerror +noerr1: + movl nd,r0 + addl2 4(r3),nd + ret + +.globl _brk +# brk(value) +# as described in man2. +# returns 0 for ok, -1 for error. + +_brk: + .word 0x0000 + chmk $break + bcc noerr2 + jmp cerror +noerr2: + movl 4(ap),nd + clrl r0 + ret + + .data +nd: .long _end diff --git a/usr/src/libc/sys/setgid.s b/usr/src/libc/sys/setgid.s new file mode 100644 index 0000000000..9e8e7490f2 --- /dev/null +++ b/usr/src/libc/sys/setgid.s @@ -0,0 +1,16 @@ +# C library -- setgid + +# error = setgid(uid); + + .set setgid,46 +.globl _setgid +.globl cerror + +_setgid: + .word 0x0000 + chmk $setgid + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/setuid.s b/usr/src/libc/sys/setuid.s new file mode 100644 index 0000000000..a86667755f --- /dev/null +++ b/usr/src/libc/sys/setuid.s @@ -0,0 +1,16 @@ +# C library -- setuid + +# error = setuid(uid); + + .set setuid,23 +.globl _setuid +.globl cerror + +_setuid: + .word 0x0000 + chmk $setuid + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/signal.s b/usr/src/libc/sys/signal.s new file mode 100644 index 0000000000..e365336182 --- /dev/null +++ b/usr/src/libc/sys/signal.s @@ -0,0 +1,19 @@ +# C library -- signal + +# signal(n, 0); /* default action on signal(n) */ +# signal(n, odd); /* ignore signal(n) */ +# signal(n, label); /* goto label on signal(n) */ +# returns old label, only one level. + + .set signal,48 +.globl _signal +.globl cerror + + .align 1 +_signal: + .word 0x0000 + chmk $signal + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/stat.s b/usr/src/libc/sys/stat.s new file mode 100644 index 0000000000..3d59d7e488 --- /dev/null +++ b/usr/src/libc/sys/stat.s @@ -0,0 +1,18 @@ +# C library -- stat + +# error = stat(string, statbuf); + +# char statbuf[36] + + .set stat,18 +.globl _stat +.globl cerror + +_stat: + .word 0x0000 + chmk $stat + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/stime.s b/usr/src/libc/sys/stime.s new file mode 100644 index 0000000000..294d0c5fcc --- /dev/null +++ b/usr/src/libc/sys/stime.s @@ -0,0 +1,13 @@ + .set stime,25 +.globl _stime +.globl cerror + +_stime: + .word 0x0000 + movl *4(ap),4(ap) # copy time to set + chmk $stime + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/sync.s b/usr/src/libc/sys/sync.s new file mode 100644 index 0000000000..0617de7e09 --- /dev/null +++ b/usr/src/libc/sys/sync.s @@ -0,0 +1,7 @@ + .set sync,36 +.globl _sync + +_sync: + .word 0x0000 + chmk $sync + ret diff --git a/usr/src/libc/sys/syscall.s b/usr/src/libc/sys/syscall.s new file mode 100644 index 0000000000..8beda6454c --- /dev/null +++ b/usr/src/libc/sys/syscall.s @@ -0,0 +1,11 @@ + .globl _syscall + .globl cerror +_syscall: + .word 0x0000 + movl 4(ap),r0 # syscall number + subl3 $1,(ap)+,(ap) # one fewer arguments + chmk r0 # do it + bcs L1 + ret +L1: + jmp cerror diff --git a/usr/src/libc/sys/time.s b/usr/src/libc/sys/time.s new file mode 100644 index 0000000000..023d77293e --- /dev/null +++ b/usr/src/libc/sys/time.s @@ -0,0 +1,26 @@ +# C library -- time + +# tvec = time(tvec); +# + + .set time,13 +.globl _time + +_time: + .word 0x0000 + chmk $time + movl 4(ap),r1 + beql nostore + movl r0,(r1) +nostore: + ret + +# ftime +# + .set ftime,35 +.globl _ftime + +_ftime: + .word 0x0000 + chmk $ftime + ret diff --git a/usr/src/libc/sys/times.s b/usr/src/libc/sys/times.s new file mode 100644 index 0000000000..c761654896 --- /dev/null +++ b/usr/src/libc/sys/times.s @@ -0,0 +1,9 @@ +# C library -- times + + .set times,43 +.globl _times + +_times: + .word 0x0000 + chmk $times + ret diff --git a/usr/src/libc/sys/umask.s b/usr/src/libc/sys/umask.s new file mode 100644 index 0000000000..04d47ee47a --- /dev/null +++ b/usr/src/libc/sys/umask.s @@ -0,0 +1,15 @@ +# C library -- umask + +# omask = umask(mode); + + .set umask,60 +.globl _umask +.globl cerror + +_umask: + .word 0x0000 + chmk $umask + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/umount.s b/usr/src/libc/sys/umount.s new file mode 100644 index 0000000000..bd993a7f37 --- /dev/null +++ b/usr/src/libc/sys/umount.s @@ -0,0 +1,15 @@ +# C library -- umount/ + + .set umount,22 +.globl _umount +.globl cerror +.comm _errno,4 + +_umount: + .word 0x0000 + chmk $umount + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/unlink.s b/usr/src/libc/sys/unlink.s new file mode 100644 index 0000000000..1846a6ea9a --- /dev/null +++ b/usr/src/libc/sys/unlink.s @@ -0,0 +1,17 @@ +# C library -- unlink + +# error = unlink(string); +# + + .set unlink,10 +.globl _unlink +.globl cerror + +_unlink: + .word 0x0000 + chmk $unlink + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/utime.s b/usr/src/libc/sys/utime.s new file mode 100644 index 0000000000..4e6b235c9e --- /dev/null +++ b/usr/src/libc/sys/utime.s @@ -0,0 +1,15 @@ +# C library -- utime + +# error = utime(string,timev); + +.globl _utime +.globl cerror + .set utime,30 + +_utime: + .word 0x0000 + chmk $utime + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/wait.s b/usr/src/libc/sys/wait.s new file mode 100644 index 0000000000..94267fbad1 --- /dev/null +++ b/usr/src/libc/sys/wait.s @@ -0,0 +1,25 @@ +# C library -- wait + +# pid = wait(0); +# or, +# pid = wait(&status); +# +# pid == -1 if error +# status indicates fate of process, if given + + .set wait,7 +.globl _wait +.globl cerror + + .align 1 +_wait: + .word 0x0000 + chmk $wait + bcc noerror + jmp cerror +noerror: + tstl 4(ap) # status desired? + beql nostatus # no + movl r1,*4(ap) # store child's status +nostatus: + ret diff --git a/usr/src/libc/sys/write.s b/usr/src/libc/sys/write.s new file mode 100644 index 0000000000..2b6421f4b0 --- /dev/null +++ b/usr/src/libc/sys/write.s @@ -0,0 +1,17 @@ +# C library -- write + +# nwritten = write(file, buffer, count); +# +# nwritten == -1 means error + + .set write,4 +.globl _write +.globl cerror + +_write: + .word 0x0000 + chmk $write + bcc noerror + jmp cerror +noerror: + ret -- 2.20.1