From 9c8fc5ca001f8a6f28261bc52d874e4091c1f3ed Mon Sep 17 00:00:00 2001 From: Bill Joy Date: Wed, 15 Oct 1980 12:53:20 -0800 Subject: [PATCH] BSD 4 development Work on file usr/src/libc/crt/mcount.s Work on file usr/src/libc/crt/cerror.s Work on file usr/src/libc/crt/urem.s Work on file usr/src/libc/crt/udiv.s 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/atof.s Work on file usr/src/libc/gen/calloc.c Work on file usr/src/libc/gen/atol.c Work on file usr/src/libc/gen/atoi.c Work on file usr/src/libc/gen/crypt.c Work on file usr/src/libc/gen/ctime.c Work on file usr/src/libc/gen/chrtab.c Work on file usr/src/libc/gen/errlst.c Work on file usr/src/libc/gen/ctype_.c Work on file usr/src/libc/gen/execvp.c Work on file usr/src/libc/gen/ecvt.c Work on file usr/src/libc/gen/index.c Work on file usr/src/libc/gen/getlogin.c Work on file usr/src/libc/gen/frexp.c Work on file usr/src/libc/gen/isatty.c Work on file usr/src/libc/gen/ldexp.s Work on file usr/src/libc/gen/l3tol.c Work on file usr/src/libc/gen/getenv.c Work on file usr/src/libc/gen/ltol3.c Work on file usr/src/libc/gen/mktemp.c Work on file usr/src/libc/gen/modf.s Work on file usr/src/libc/gen/malloc.c Work on file usr/src/libc/gen/mon.c Work on file usr/src/libc/gen/nlist.c Work on file usr/src/libc/gen/mpx.c Work on file usr/src/libc/gen/qsort.c Work on file usr/src/libc/gen/perror.c Work on file usr/src/libc/gen/rand.c Work on file usr/src/libc/gen/regex.c Work on file usr/src/libc/gen/rin.c Work on file usr/src/libc/gen/strcat.c Work on file usr/src/libc/gen/strcatn.c Work on file usr/src/libc/gen/rindex.c Work on file usr/src/libc/gen/sleep.c Work on file usr/src/libc/gen/strlen.c Work on file usr/src/libc/gen/strcpyn.c Work on file usr/src/libc/gen/strcmp.c Work on file usr/src/libc/gen/strcpy.c Work on file usr/src/libc/gen/strcmpn.c Work on file usr/src/libc/gen/strncat.c Work on file usr/src/libc/gen/strncmp.c Work on file usr/src/libc/gen/strncpy.c Work on file usr/src/libc/gen/tell.c Work on file usr/src/libc/gen/stty.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/gen/ttyslot.c Work on file usr/src/libc/gen/ttyname.c Work on file usr/src/libc/gen/valloc.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/sys/abort.s Work on file usr/src/libc/sys/_exit.s Work on file usr/src/libc/sys/alarm.s Work on file usr/src/libc/sys/abs.s Work on file usr/src/libc/stdio/doprnt.s Work on file usr/src/libc/sys/access.s Work on file usr/src/libc/sys/acct.s Work on file usr/src/libc/stdio/doscan.c Work on file usr/src/libc/stdio/doprnt.s.old Work on file usr/src/libc/stdio/error.c Work on file usr/src/libc/sys/alloca.s Work on file usr/src/libc/sys/cerror.s Work on file usr/src/libc/sys/chdir.s Work on file usr/src/libc/sys/chmod.s Work on file usr/src/libc/stdio/fgets.c Work on file usr/src/libc/sys/chroot.s Work on file usr/src/libc/stdio/fgetc.c Work on file usr/src/libc/sys/close.s Work on file usr/src/libc/stdio/fdopen.c Work on file usr/src/libc/sys/chown.s Work on file usr/src/libc/stdio/filbuf.c Work on file usr/src/libc/sys/cleanup.s.dead Work on file usr/src/libc/sys/creat.s Work on file usr/src/libc/stdio/fopen.c Work on file usr/src/libc/stdio/flsbuf.c Work on file usr/src/libc/sys/execle.s Work on file usr/src/libc/sys/dup.s Work on file usr/src/libc/stdio/freopen.c Work on file usr/src/libc/stdio/fputc.c Work on file usr/src/libc/stdio/fprintf.c Work on file usr/src/libc/sys/execl.s Work on file usr/src/libc/stdio/fputs.c Work on file usr/src/libc/sys/exit.s Work on file usr/src/libc/sys/execv.s Work on file usr/src/libc/stdio/fseek.c Work on file usr/src/libc/stdio/fstab.c Work on file usr/src/libc/sys/execve.s Work on file usr/src/libc/sys/fstat.s Work on file usr/src/libc/stdio/ftell.c Work on file usr/src/libc/sys/fabs.s Work on file usr/src/libc/stdio/gcvt.c Work on file usr/src/libc/stdio/getchar.c Work on file usr/src/libc/sys/fork.s Work on file usr/src/libc/sys/getgid.s Work on file usr/src/libc/sys/getcsw.s Work on file usr/src/libc/sys/getpid.s Work on file usr/src/libc/stdio/getgrgid.c Work on file usr/src/libc/stdio/getgrent.c Work on file usr/src/libc/stdio/getgrnam.c Work on file usr/src/libc/sys/getuid.s 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/getpass.c Work on file usr/src/libc/sys/itol.s Work on file usr/src/libc/stdio/getpwnam.c Work on file usr/src/libc/sys/ioctl.s Work on file usr/src/libc/stdio/getpwuid.c Work on file usr/src/libc/stdio/gets.c Work on file usr/src/libc/sys/kill.s Work on file usr/src/libc/sys/link.s Work on file usr/src/libc/stdio/getw.c Work on file usr/src/libc/stdio/intss.c Work on file usr/src/libc/sys/locv.s Work on file usr/src/libc/sys/lseek.s Work on file usr/src/libc/sys/ltod.s Work on file usr/src/libc/sys/ltoi.s Work on file usr/src/libc/stdio/ios.r Work on file usr/src/libc/sys/mcount.s Work on file usr/src/libc/sys/makdir.s Work on file usr/src/libc/stdio/makefile Work on file usr/src/libc/stdio/popen.c Work on file usr/src/libc/sys/mdate.s Work on file usr/src/libc/sys/mknod.s Work on file usr/src/libc/stdio/portli.cc Work on file usr/src/libc/stdio/printf.c Work on file usr/src/libc/sys/mount.s Work on file usr/src/libc/sys/mpxcall.s Work on file usr/src/libc/stdio/putchar.c Work on file usr/src/libc/sys/nargs.s Work on file usr/src/libc/stdio/rdwr.c Work on file usr/src/libc/sys/nice.s Work on file usr/src/libc/stdio/puts.c Work on file usr/src/libc/sys/nexect.s Work on file usr/src/libc/stdio/putw.c Work on file usr/src/libc/sys/pipe.s Work on file usr/src/libc/stdio/setbuf.c Work on file usr/src/libc/stdio/rew.c Work on file usr/src/libc/stdio/scanf.c Work on file usr/src/libc/sys/open.s Work on file usr/src/libc/sys/sbrk.s Work on file usr/src/libc/sys/ptrace.s Work on file usr/src/libc/stdio/strout.c Work on file usr/src/libc/sys/read.s Work on file usr/src/libc/stdio/stuff.c Work on file usr/src/libc/sys/reset.s Work on file usr/src/libc/sys/setgid.s Work on file usr/src/libc/stdio/sprintf.c Work on file usr/src/libc/sys/prof.s Work on file usr/src/libc/stdio/system.c Work on file usr/src/libc/sys/setjmp.s Work on file usr/src/libc/sys/stat.s Work on file usr/src/libc/stdio/tmpnam.c Work on file usr/src/libc/sys/setuid.s Work on file usr/src/libc/sys/signal.s Work on file usr/src/libc/stdio/ungetc.c Work on file usr/src/libc/sys/stime.s Work on file usr/src/libc/sys/sync.s Work on file usr/src/libc/sys/times.s Work on file usr/src/libc/sys/syscall.s Work on file usr/src/libc/sys/time.s Work on file usr/src/libc/sys/umount.s Work on file usr/src/libc/sys/umask.s Work on file usr/src/libc/sys/vadvise.s Work on file usr/src/libc/sys/unlink.s Work on file usr/src/libc/sys/vfork.s Work on file usr/src/libc/sys/utime.s Work on file usr/src/libc/sys/vhangup.s Work on file usr/src/libc/sys/vread.s Work on file usr/src/libc/sys/vlimit.s Work on file usr/src/libc/sys/vtimes.s Work on file usr/src/libc/sys/vwrite.s Work on file usr/src/libc/sys/wait.s Work on file usr/src/libc/sys/vwait.s Work on file usr/src/libc/sys/write.s Synthesized-from: CSRG//cd1/4.0 --- usr/src/libc/crt/cerror.s | 10 + usr/src/libc/crt/mcount.s | 19 + usr/src/libc/crt/udiv.s | 37 ++ usr/src/libc/crt/urem.s | 37 ++ usr/src/libc/csu/crt0.s | 33 ++ usr/src/libc/csu/mcrt0.s | 83 ++++ usr/src/libc/gen/atof.s | 319 ++++++++++++++ usr/src/libc/gen/atoi.c | 24 ++ 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/ctype_.c | 21 + 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.s | 60 +++ 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.s | 32 ++ usr/src/libc/gen/mon.c | 40 ++ usr/src/libc/gen/mpx.c | 83 ++++ usr/src/libc/gen/nlist.c | 81 ++++ 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/regex.c | 391 +++++++++++++++++ usr/src/libc/gen/rin.c | 35 ++ usr/src/libc/gen/rindex.c | 20 + usr/src/libc/gen/sleep.c | 40 ++ 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/gen/valloc.c | 14 + usr/src/libc/stdio/clrerr.c | 7 + usr/src/libc/stdio/data.c | 13 + usr/src/libc/stdio/doprnt.s | 736 ++++++++++++++++++++++++++++++++ usr/src/libc/stdio/doprnt.s.old | 524 +++++++++++++++++++++++ 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 | 38 ++ usr/src/libc/stdio/flsbuf.c | 109 +++++ usr/src/libc/stdio/fopen.c | 37 ++ 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/fstab.c | 114 +++++ 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/makefile | 32 ++ usr/src/libc/stdio/popen.c | 54 +++ 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/system.c | 22 + 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 | 12 + 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.dead | 8 + usr/src/libc/sys/close.s | 15 + usr/src/libc/sys/creat.s | 16 + 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/fabs.s | 9 + usr/src/libc/sys/fork.s | 20 + 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/lseek.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/mdate.s | 14 + usr/src/libc/sys/mknod.s | 16 + usr/src/libc/sys/mount.s | 16 + usr/src/libc/sys/mpxcall.s | 17 + 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/setjmp.s | 41 ++ 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/vadvise.s | 15 + usr/src/libc/sys/vfork.s | 37 ++ usr/src/libc/sys/vhangup.s | 9 + usr/src/libc/sys/vlimit.s | 15 + usr/src/libc/sys/vread.s | 17 + usr/src/libc/sys/vtimes.s | 9 + usr/src/libc/sys/vwait.s | 26 ++ usr/src/libc/sys/vwrite.s | 17 + usr/src/libc/sys/wait.s | 25 ++ usr/src/libc/sys/write.s | 17 + 181 files changed, 8155 insertions(+) create mode 100644 usr/src/libc/crt/cerror.s create mode 100644 usr/src/libc/crt/mcount.s create mode 100644 usr/src/libc/crt/udiv.s create mode 100644 usr/src/libc/crt/urem.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.s create mode 100644 usr/src/libc/gen/atoi.c 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/ctype_.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.s 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.s create mode 100644 usr/src/libc/gen/mon.c create mode 100644 usr/src/libc/gen/mpx.c create mode 100644 usr/src/libc/gen/nlist.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/regex.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/sleep.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/gen/valloc.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/doprnt.s create mode 100644 usr/src/libc/stdio/doprnt.s.old 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/fopen.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/fstab.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/makefile create mode 100644 usr/src/libc/stdio/popen.c 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/system.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.dead 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/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/fabs.s create mode 100644 usr/src/libc/sys/fork.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/lseek.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/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/mpxcall.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/setjmp.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/vadvise.s create mode 100644 usr/src/libc/sys/vfork.s create mode 100644 usr/src/libc/sys/vhangup.s create mode 100644 usr/src/libc/sys/vlimit.s create mode 100644 usr/src/libc/sys/vread.s create mode 100644 usr/src/libc/sys/vtimes.s create mode 100644 usr/src/libc/sys/vwait.s create mode 100644 usr/src/libc/sys/vwrite.s create mode 100644 usr/src/libc/sys/wait.s create mode 100644 usr/src/libc/sys/write.s 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/crt/udiv.s b/usr/src/libc/crt/udiv.s new file mode 100644 index 0000000000..9f98a4659b --- /dev/null +++ b/usr/src/libc/crt/udiv.s @@ -0,0 +1,37 @@ +# +# udiv - unsigned division for vax-11 +# +# arguments: dividend, divisor. +# result: quotient. +# uses r0-r2 +# +# If 1 < divisor <= 2147483647, zero-extend the dividend +# to 64 bits and let ediv do the work. If the divisor is 1, +# ediv will overflow if bit 31 of the dividend is on, so +# just return the dividend unchanged. If the divisor is 0, +# do the ediv also, so it will generate the proper exception. +# All other values of the divisor have bit 31 on: in this case +# the quotient must be 0 if divisor > dividend, and 1 otherwise, +# provided that the comparison is made as unsigned. +# + .text + .align 1 + .globl udiv +udiv: .word 0x0000 + movl 4(ap),r0 # Dividend + movl 8(ap),r2 # Divisor + jeql div # If divisor=0, force exception + cmpl r2,$1 # If divisor <= 1 (signed), + jleq nodiv # no division is necessary +div: clrl r1 # Zero-extend the dividend + ediv r2,r0,r0,r2 # Divide. q->r0, r->r2 (discarded) + ret +nodiv: jeql retn # If divisor=1, return dividend + cmpl r0,r2 # Unsigned comparison between + jgequ one # dividend and divisor + clrl r0 # Dividend < divisor, return 0 + ret +one: movl $1,r0 # Dividend >= divisor, return 1 +retn: ret + + diff --git a/usr/src/libc/crt/urem.s b/usr/src/libc/crt/urem.s new file mode 100644 index 0000000000..ffecb6a401 --- /dev/null +++ b/usr/src/libc/crt/urem.s @@ -0,0 +1,37 @@ +# +# urem - unsigned remainder for vax-11 +# +# arguments: dividend, divisor +# result: remainder +# uses r0-r2 +# +# if 1 < divisor <= 2147483647, zero-extend the dividend +# to 64 bits and let ediv do the work. If the divisor is 1, +# ediv will overflow if bit 31 of the dividend is on, so +# just return 0. If the divisor is 0, do the ediv also, +# so it will generate the proper exception. All other values +# of the divisor have bit 31 on: in this case the remainder +# must be the dividend if divisor > dividend, and the dividend +# minus the divisor otherwise. The comparison must be unsigned. +# + .text + .align 1 + .globl urem +urem: .word 0x0000 + movl 4(ap),r0 # Dividend + movl 8(ap),r2 # Divisor + jeql div # If divisor=0, force exception + cmpl r2,$1 # If divisor <= 1 (signed), + jleq nodiv # no division is necessary +div: clrl r1 # Zero-extend the dividend + ediv r2,r0,r2,r0 # Divide. q->r2 (discarded), r->r0 + ret +nodiv: jneq nzero # If divisor=1, return 0 + clrl r0 # (because doing the divide will overflow + ret # if the dividend has its high bit on) +nzero: cmpl r0,r2 # If dividend < divisor (unsigned) + jlssu retn # remainder is dividend + subl2 r2,r0 # else remainder is dividend - divisor +retn: ret + + 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.s b/usr/src/libc/gen/atof.s new file mode 100644 index 0000000000..3871de8b36 --- /dev/null +++ b/usr/src/libc/gen/atof.s @@ -0,0 +1,319 @@ +# +# atof: convert ascii to floating +# +# C usage: +# +# double atof (s) +# char *s; +# +# Register usage: +# +# r0-1: value being developed +# r2: first section: pointer to the next character +# second section: binary exponent +# r3: flags +# r4: first section: the current character +# second section: scratch +# r5: the decimal exponent +# r6-7: scratch +# +# Flag definitions +# + .set msign,0 # mantissa has negative sign + .set esign,1 # exponent has negative sign + .set decpt,2 # decimal point encountered + + .align 2 +two31: .word 0x5000 # 2 ** 31 + .word 0 # (=2147483648) + .word 0 # in floating-point + .word 0 # (so atof doesn't have to convert it) +# +# Entry point +# + .text + .align 2 + .globl _atof +_atof: .word 0x00c0 # Save r7, r6 (we use r0-r7) +# +# Initialization +# + clrl r3 # All flags start out false + movl 4(ap),r2 # Address the first character + clrl r5 # Clear starting exponent +# +# Skip leading white space +# +sk0: movzbl (r2)+,r4 # Fetch the next (first) character + cmpb $' ,r4 # Is it blank? + jeql sk0 # ...yes + cmpb r4,$8 # 8 is lowest of white-space group + jlss sk1 # Jump if char too low to be white space + cmpb r4,$13 # 13 is highest of white-space group + jleq sk0 # Jump if character is white space +sk1: +# +# Check for a sign +# + cmpb $'+,r4 # Positive sign? + jeql cs1 # ... yes + cmpb $'-,r4 # Negative sign? + jneq cs2 # ... no + bisb2 $1= '0' && *p <= '9') + n = n*10 + *p++ - '0'; + if(f) + n = -n; + return(n); +} 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/ctype_.c b/usr/src/libc/gen/ctype_.c new file mode 100644 index 0000000000..927df2825c --- /dev/null +++ b/usr/src/libc/gen/ctype_.c @@ -0,0 +1,21 @@ +#include + +char _ctype_[] = { + 0, + _C, _C, _C, _C, _C, _C, _C, _C, + _C, _S, _S, _S, _S, _S, _C, _C, + _C, _C, _C, _C, _C, _C, _C, _C, + _C, _C, _C, _C, _C, _C, _C, _C, + _S, _P, _P, _P, _P, _P, _P, _P, + _P, _P, _P, _P, _P, _P, _P, _P, + _N, _N, _N, _N, _N, _N, _N, _N, + _N, _N, _P, _P, _P, _P, _P, _P, + _P, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U|_X, _U, + _U, _U, _U, _U, _U, _U, _U, _U, + _U, _U, _U, _U, _U, _U, _U, _U, + _U, _U, _U, _P, _P, _P, _P, _P, + _P, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L|_X, _L, + _L, _L, _L, _L, _L, _L, _L, _L, + _L, _L, _L, _L, _L, _L, _L, _L, + _L, _L, _L, _P, _P, _P, _P, _C +}; 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..0e7162b3a5 --- /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[sizeof (ubuf.ut_name)] = ' '; + 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;i=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.s b/usr/src/libc/gen/modf.s new file mode 100644 index 0000000000..8e4d0b90a1 --- /dev/null +++ b/usr/src/libc/gen/modf.s @@ -0,0 +1,32 @@ +# +# double modf (value, iptr) +# double value; +# double *iptr; +# +# Modf returns the fractional part of "value", and stores the integer +# part indirectly through "iptr". +# +# Entry point +# + .text + .align 1 + .globl _modf +_modf: .word 0x0000 # We use r0-r2, but do not save them +# +# This instruction does the following: +# +# Extend the long floating value at 4(ap) with 0, and +# multiply it by 1.0. Store the integer part of the result +# in r2, and the fractional part of the result in r0-r1. +# + emodf 4(ap),$0,$0f1.0,r2,r0 # How did you like + # THAT, sports fans? + jvs iovfl # Jump if integer overflow + cvtld r2,*12(ap) # Else store integer result + ret # and return +# +# Integer overflow occurred...develop the integer part by +# subtracting the fractional part from the argument. +# +iovfl: subd3 r0,4(ap),*12(ap) # Develop integer part + ret diff --git a/usr/src/libc/gen/mon.c b/usr/src/libc/gen/mon.c new file mode 100644 index 0000000000..7cbe7f0c06 --- /dev/null +++ b/usr/src/libc/gen/mon.c @@ -0,0 +1,40 @@ +monitor(lowpc, highpc, buf, bufsiz, cntsiz) +char *lowpc, *highpc; +int *buf, bufsiz; +{ + register o; + static *sbuf, ssiz; + struct phdr { + int *lpc; + int *hpc; + int ncnt; + }; + struct cnt { + int *pc; + long ncall; + }; + + if (lowpc == 0) { + profil(0, 0, 0, 0); + o = creat("mon.out", 0666); + write(o, sbuf, ssiz); + close(o); + return; + } + sbuf = buf; + ssiz = bufsiz; + buf[0] = (int)lowpc; + buf[1] = (int)highpc; + buf[2] = cntsiz; + o = sizeof(struct phdr) + cntsiz*sizeof(struct cnt); + buf = (int *) (((int)buf) + o); + bufsiz -= o; + if (bufsiz<=0) + return; + o = ((highpc - lowpc)>>1); + if(bufsiz < o) + o = ((float) bufsiz / o) * 32768; + else + o = 0177777; + profil(buf, bufsiz, lowpc, o); +} diff --git a/usr/src/libc/gen/mpx.c b/usr/src/libc/gen/mpx.c new file mode 100644 index 0000000000..8b3db62fe9 --- /dev/null +++ b/usr/src/libc/gen/mpx.c @@ -0,0 +1,83 @@ +#include +#include +#include + +static struct mx_args vec; +int mpxcall(); + + +mpx(name,mode) +char *name; +{ + if (name && *name) { + vec.m_name = name; + vec.m_arg[1] = mode; + return(mpxcall(MPX, &vec)); + } else + return(mpxcall(MPXN, 0)); +} + +chan(gr) +{ + vec.m_arg[1] = gr; + return(mpxcall(CHAN, &vec)); +} + +join(fd,ch) +{ + vec.m_arg[0] = fd; + vec.m_arg[1] = ch; + return(mpxcall(JOIN, &vec)); +} + +connect(fd,ch,side) +{ + vec.m_arg[0] = fd; + vec.m_arg[1] = ch; + vec.m_arg[2] = side; + return(mpxcall(CONNECT, &vec)); +} + +attach(sub,gp) +{ + vec.m_arg[0] = sub; + vec.m_arg[1] = gp; + return(mpxcall(ATTACH, &vec)); +} + +detach(sub,gp) +{ + vec.m_arg[0] = sub; + vec.m_arg[1] = gp; + return(mpxcall(DETACH, &vec)); +} + +extract(sub,ch,side) +{ + vec.m_arg[0] = sub; + vec.m_arg[1] = ch; + vec.m_arg[2] = 1 /* side */; /* 0 seems to be useless */ + return(mpxcall(EXTR, &vec)); +} + +debug(var,val) +{ + vec.m_arg[0] = var; + vec.m_arg[1] = val; + return(mpxcall(DEBUG, &vec)); +} + +npgrp(ch, gfd, pid) +{ + vec.m_arg[0] = ch; + vec.m_arg[1] = gfd; + vec.m_arg[2] = pid; + return(mpxcall(NPGRP, &vec)); +} +ckill(index,gp,sig) +{ + vec.m_arg[0] = index; + vec.m_arg[1] = gp; + vec.m_arg[2] = sig; + return(mpxcall(CSIG, &vec)); +} diff --git a/usr/src/libc/gen/nlist.c b/usr/src/libc/gen/nlist.c new file mode 100644 index 0000000000..bb945d1220 --- /dev/null +++ b/usr/src/libc/gen/nlist.c @@ -0,0 +1,81 @@ +#include +#include +#include +#include + +/* + * nlist - retreive attributes from name list (string table version) + */ +nlist(name, list) + char *name; + struct nlist *list; +{ + register struct nlist *p, *q; + register n, m, i, nreq; + FILE *f; + off_t sa; /* symbol address */ + off_t ss; /* start of strings */ + struct exec buf; + struct nlist space[BUFSIZ/sizeof (struct nlist)]; + int maxlen; + + maxlen = 0; + for (q = list, nreq = 0; q->n_un.n_name && q->n_un.n_name[0]; q++, nreq++) { + q->n_type = 0; + q->n_value = 0; + q->n_desc = 0; + q->n_other = 0; + i = strlen(q->n_un.n_name); + if (i > maxlen) + maxlen = i; + } + f = fopen(name, "r"); + if (f == NULL) + return (NULL); + fread((char *)&buf, sizeof buf, 1, f); + if (N_BADMAG(buf)) { + close(f); + return (-1); + } + sa = N_SYMOFF(buf); + ss = sa + buf.a_syms; + n = buf.a_syms; + while (n) { + m = sizeof (space); + if (n < m) + m = n; + fseek(f, sa, 0); + i = fread((char *)space, m, 1, f); + sa += m; + n -= m; + for (q = space; (m -= sizeof(struct nlist)) >= 0; q++) { + char nambuf[BUFSIZ]; + + if (q->n_un.n_strx == 0 || q->n_type & N_STAB) + continue; + fseek(f, ss+q->n_un.n_strx, 0); + fread(nambuf, maxlen+1, 1, f); + for (p = list; p->n_un.n_name[0]; p++) { + i = 0; + while (p->n_un.n_name[i]) { + if (p->n_un.n_name[i] != nambuf[i]) + goto cont; + i++; + } + if (nambuf[i]) + goto cont; + p->n_value = q->n_value; + p->n_type = q->n_type; + p->n_desc = q->n_desc; + p->n_other = q->n_other; + if (--nreq == 0) + goto alldone; + break; + cont: ; + } + } + } +alldone: + fclose(f); + return (0); +} 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/regex.c b/usr/src/libc/gen/regex.c new file mode 100644 index 0000000000..0ae91f1972 --- /dev/null +++ b/usr/src/libc/gen/regex.c @@ -0,0 +1,391 @@ +# + +/* + * routines to do regular expression matching + * + * Entry points: + * + * re_comp(s) + * char *s; + * ... returns 0 if the string s was compiled successfully, + * a pointer to an error message otherwise. + * If passed 0 or a null string returns without changing + * the currently compiled re (see note 11 below). + * + * re_exec(s) + * char *s; + * ... returns 1 if the string s matches the last compiled regular + * expression, + * 0 if the string s failed to match the last compiled + * regular expression, and + * -1 if the compiled regular expression was invalid + * (indicating an internal error). + * + * The strings passed to both re_comp and re_exec may have trailing or + * embedded newline characters; they are terminated by nulls. + * + * The identity of the author of these routines is lost in antiquity; + * this is essentially the same as the re code in the original V6 ed. + * + * The regular expressions recognized are described below. This description + * is essentially the same as that for ed. + * + * A regular expression specifies a set of strings of characters. + * A member of this set of strings is said to be matched by + * the regular expression. In the following specification for + * regular expressions the word `character' means any character but NUL. + * + * 1. Any character except a special character matches itself. + * Special characters are the regular expression delimiter plus + * \ [ . and sometimes ^ * $. + * 2. A . matches any character. + * 3. A \ followed by any character except a digit or ( ) + * matches that character. + * 4. A nonempty string s bracketed [s] (or [^s]) matches any + * character in (or not in) s. In s, \ has no special meaning, + * and ] may only appear as the first letter. A substring + * a-b, with a and b in ascending ASCII order, stands for + * the inclusive range of ASCII characters. + * 5. A regular expression of form 1-4 followed by * matches a + * sequence of 0 or more matches of the regular expression. + * 6. A regular expression, x, of form 1-8, bracketed \(x\) + * matches what x matches. + * 7. A \ followed by a digit n matches a copy of the string that the + * bracketed regular expression beginning with the nth \( matched. + * 8. A regular expression of form 1-8, x, followed by a regular + * expression of form 1-7, y matches a match for x followed by + * a match for y, with the x match being as long as possible + * while still permitting a y match. + * 9. A regular expression of form 1-8 preceded by ^ (or followed + * by $), is constrained to matches that begin at the left + * (or end at the right) end of a line. + * 10. A regular expression of form 1-9 picks out the longest among + * the leftmost matches in a line. + * 11. An empty regular expression stands for a copy of the last + * regular expression encountered. + */ + +/* + * constants for re's + */ +#define CBRA 1 +#define CCHR 2 +#define CDOT 4 +#define CCL 6 +#define NCCL 8 +#define CDOL 10 +#define CEOF 11 +#define CKET 12 +#define CBACK 18 + +#define CSTAR 01 + +#define ESIZE 512 +#define NBRA 9 + +static char expbuf[ESIZE], *braslist[NBRA], *braelist[NBRA]; +static char circf; + +/* + * compile the regular expression argument into a dfa + */ +char * +re_comp(sp) + register char *sp; +{ + register int c; + register char *ep = expbuf; + int cclcnt, numbra = 0; + char *lastep = 0; + char bracket[NBRA]; + char *bracketp = &bracket[0]; + static char *retoolong = "Regular expression too long"; + +#define comerr(msg) {expbuf[0] = 0; numbra = 0; return(msg); } + + if (sp == 0 || *sp == '\0') { + if (*ep == 0) + return("No previous regular expression"); + return(0); + } + if (*sp == '^') { + circf = 1; + sp++; + } + else + circf = 0; + for (;;) { + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + if ((c = *sp++) == '\0') { + if (bracketp != bracket) + comerr("unmatched \\("); + *ep++ = CEOF; + *ep++ = 0; + return(0); + } + if (c != '*') + lastep = ep; + switch (c) { + + case '.': + *ep++ = CDOT; + continue; + + case '*': + if (lastep == 0 || *lastep == CBRA || *lastep == CKET) + goto defchar; + *lastep |= CSTAR; + continue; + + case '$': + if (*sp != '\0') + goto defchar; + *ep++ = CDOL; + continue; + + case '[': + *ep++ = CCL; + *ep++ = 0; + cclcnt = 1; + if ((c = *sp++) == '^') { + c = *sp++; + ep[-2] = NCCL; + } + do { + if (c == '\0') + comerr("missing ]"); + if (c == '-' && ep [-1] != 0) { + if ((c = *sp++) == ']') { + *ep++ = '-'; + cclcnt++; + break; + } + while (ep[-1] < c) { + *ep = ep[-1] + 1; + ep++; + cclcnt++; + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + } + } + *ep++ = c; + cclcnt++; + if (ep >= &expbuf[ESIZE]) + comerr(retoolong); + } while ((c = *sp++) != ']'); + lastep[1] = cclcnt; + continue; + + case '\\': + if ((c = *sp++) == '(') { + if (numbra >= NBRA) + comerr("too many \\(\\) pairs"); + *bracketp++ = numbra; + *ep++ = CBRA; + *ep++ = numbra++; + continue; + } + if (c == ')') { + if (bracketp <= bracket) + comerr("unmatched \\)"); + *ep++ = CKET; + *ep++ = *--bracketp; + continue; + } + if (c >= '1' && c < ('1' + NBRA)) { + *ep++ = CBACK; + *ep++ = c - '1'; + continue; + } + *ep++ = CCHR; + *ep++ = c; + continue; + + defchar: + default: + *ep++ = CCHR; + *ep++ = c; + } + } +} + +/* + * match the argument string against the compiled re + */ +int +re_exec(p1) + register char *p1; +{ + register char *p2 = expbuf; + register int c; + int rv; + + for (c = 0; c < NBRA; c++) { + braslist[c] = 0; + braelist[c] = 0; + } + if (circf) + return((advance(p1, p2))); + /* + * fast check for first character + */ + if (*p2 == CCHR) { + c = p2[1]; + do { + if (*p1 != c) + continue; + if (rv = advance(p1, p2)) + return(rv); + } while (*p1++); + return(0); + } + /* + * regular algorithm + */ + do + if (rv = advance(p1, p2)) + return(rv); + while (*p1++); + return(0); +} + +/* + * try to match the next thing in the dfa + */ +static int +advance(lp, ep) + register char *lp, *ep; +{ + register char *curlp; + int ct, i; + int rv; + + for (;;) + switch (*ep++) { + + case CCHR: + if (*ep++ == *lp++) + continue; + return(0); + + case CDOT: + if (*lp++) + continue; + return(0); + + case CDOL: + if (*lp == '\0') + continue; + return(0); + + case CEOF: + return(1); + + case CCL: + if (cclass(ep, *lp++, 1)) { + ep += *ep; + continue; + } + return(0); + + case NCCL: + if (cclass(ep, *lp++, 0)) { + ep += *ep; + continue; + } + return(0); + + case CBRA: + braslist[*ep++] = lp; + continue; + + case CKET: + braelist[*ep++] = lp; + continue; + + case CBACK: + if (braelist[i = *ep++] == 0) + return(-1); + if (backref(i, lp)) { + lp += braelist[i] - braslist[i]; + continue; + } + return(0); + + case CBACK|CSTAR: + if (braelist[i = *ep++] == 0) + return(-1); + curlp = lp; + ct = braelist[i] - braslist[i]; + while (backref(i, lp)) + lp += ct; + while (lp >= curlp) { + if (rv = advance(lp, ep)) + return(rv); + lp -= ct; + } + continue; + + case CDOT|CSTAR: + curlp = lp; + while (*lp++) + ; + goto star; + + case CCHR|CSTAR: + curlp = lp; + while (*lp++ == *ep) + ; + ep++; + goto star; + + case CCL|CSTAR: + case NCCL|CSTAR: + curlp = lp; + while (cclass(ep, *lp++, ep[-1] == (CCL|CSTAR))) + ; + ep += *ep; + goto star; + + star: + do { + lp--; + if (rv = advance(lp, ep)) + return(rv); + } while (lp > curlp); + return(0); + + default: + return(-1); + } +} + +backref(i, lp) + register int i; + register char *lp; +{ + register char *bp; + + bp = braslist[i]; + while (*bp++ == *lp++) + if (bp >= braelist[i]) + return(1); + return(0); +} + +int +cclass(set, c, af) + register char *set, c; + int af; +{ + register int n; + + if (c == 0) + return(0); + n = *set++; + while (--n) + if (*set++ == c) + return(af); + return(! af); +} diff --git a/usr/src/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; f +#include + +static jmp_buf jmp; + +sleep(n) +unsigned n; +{ + int sleepx(); + unsigned altime; + int (*alsig)() = SIG_DFL; + + if (n==0) + return; + altime = alarm(1000); /* time to maneuver */ + if (setjmp(jmp)) { + signal(SIGALRM, alsig); + alarm(altime); + return; + } + if (altime) { + if (altime > n) + altime -= n; + else { + n = altime; + altime = 1; + } + } + alsig = signal(SIGALRM, sleepx); + alarm(n); + for(;;) + pause(); + /*NOTREACHED*/ +} + +static +sleepx() +{ + longjmp(jmp, 1); +} diff --git a/usr/src/libc/gen/strcat.c b/usr/src/libc/gen/strcat.c new file mode 100644 index 0000000000..9d2a52cb99 --- /dev/null +++ b/usr/src/libc/gen/strcat.c @@ -0,0 +1,19 @@ +/* + * Concatenate s2 on the end of s1. S1's space must be large enough. + * Return s1. + */ + +char * +strcat(s1, s2) +register char *s1, *s2; +{ + register char *os1; + + os1 = s1; + while (*s1++) + ; + --s1; + while (*s1++ = *s2++) + ; + return(os1); +} diff --git a/usr/src/libc/gen/strcatn.c b/usr/src/libc/gen/strcatn.c new file mode 100644 index 0000000000..80e4a9933d --- /dev/null +++ b/usr/src/libc/gen/strcatn.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 * +strcatn(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/strcmp.c b/usr/src/libc/gen/strcmp.c new file mode 100644 index 0000000000..3159719842 --- /dev/null +++ b/usr/src/libc/gen/strcmp.c @@ -0,0 +1,13 @@ +/* + * Compare strings: s1>s2: >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/gen/valloc.c b/usr/src/libc/gen/valloc.c new file mode 100644 index 0000000000..a5777dc8dd --- /dev/null +++ b/usr/src/libc/gen/valloc.c @@ -0,0 +1,14 @@ +#include + +char *malloc(); + +char * +valloc(i) + int i; +{ + char *cp = malloc(i + (VALSIZ-1)); + int j; + + j = ((int)cp + (VALSIZ-1)) &~ (VALSIZ-1); + return ((char *)j); +} 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/doprnt.s b/usr/src/libc/stdio/doprnt.s new file mode 100644 index 0000000000..06f7405595 --- /dev/null +++ b/usr/src/libc/stdio/doprnt.s @@ -0,0 +1,736 @@ + # C library -- conversions + +.globl __doprnt +.globl __flsbuf + +#define vbit 1 +#define flags r10 +#define ndfnd 0 +#define prec 1 +#define zfill 2 +#define minsgn 3 +#define plssgn 4 +#define numsgn 5 +#define caps 6 +#define blank 7 +#define gflag 8 +#define dpflag 9 +#define width r9 +#define ndigit r8 +#define llafx r7 +#define lrafx r6 +#define fdesc -4(fp) +#define exp -8(fp) +#define sexp -12(fp) +#define nchar -16(fp) +#define sign -17(fp) + .set ch.zer,'0 # cpp doesn't like single appostrophes + + .align 2 +strtab: # translate table for detecting null and percent + .byte 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 + .byte 16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 + .byte ' ,'!,'",'#,'$, 0,'&,'','(,'),'*,'+,',,'-,'.,'/ + .byte '0,'1,'2,'3,'4,'5,'6,'7,'8,'9,':,';,'<,'=,'>,'? + .byte '@,'A,'B,'C,'D,'E,'F,'G,'H,'I,'J,'K,'L,'M,'N,'O + .byte 'P,'Q,'R,'S,'T,'U,'V,'W,'X,'Y,'Z,'[,'\,'],'^,'_ + .byte '`,'a,'b,'c,'d,'e,'f,'g,'h,'i,'j,'k,'l,'m,'n,'o + .byte 'p,'q,'r,'s,'t,'u,'v,'w,'x,'y,'z,'{,'|,'},'~,127 + .byte 128,129,130,131,132,133,134,135,136,137,138,139,140,141,142,143 + .byte 144,145,146,147,148,149,150,151,152,153,154,155,156,157,158,159 + .byte 160,161,162,163,164,165,166,167,168,169,170,171,172,173,174,175 + .byte 176,177,178,179,180,181,182,183,184,185,186,187,188,189,190,191 + .byte 192,193,194,195,196,197,198,199,200,201,202,203,204,205,206,207 + .byte 208,209,210,211,212,213,214,215,216,217,218,219,220,221,222,223 + .byte 224,225,226,227,228,229,230,231,232,233,234,235,236,237,238,239 + .byte 240,241,242,243,244,245,246,247,248,249,250,251,252,253,254,255 + +strfoo: + clrl r4 # fix interrupt race + jbr strok # and try again +strmore: + movzbl (r1)+,r2 # one char + tstb (r3)[r2] # translate + jeql stresc2 # bad guy in disguise (outbuf is full) +strout2: # enter here to force out r2; r0,r1 must be set + pushr $3 # save input descriptor + pushl fdesc # FILE + pushl r2 # the char + calls $2,__flsbuf # please empty the buffer and handle 1 char + tstl r0 # successful? + jgeq strm1 # yes + jbcs $31,nchar,strm1 # turn on sign bit of nchar to signify error +strm1: + incl nchar # count the char + popr $3 # get input descriptor back +strout: # enter via bsb with (r0,r1)=input descriptor + movab strtab,r3 # table address + movq *fdesc,r4 # output descriptor + jbs $31,r4,strfoo # negative count is a no no +strok: + addl2 r0,nchar # we intend to move this many chars + movtuc r0,(r1),$0,(r3),r4,(r5) + movpsl r2 # squirrel away condition codes + movq r4,*fdesc # update output descriptor + subl2 r0,nchar # some chars not moved + jbs $vbit,r2,stresc # terminated by escape? + sobgeq r0,strmore # no; but out buffer might be full +stresc: + rsb +stresc2: + incl r0 # fix the length + decl r1 # and the addr + movl $1 + .word fmtbad-L5 # ? + .word fmtbad-L5 # @ + .word fmtbad-L5 # A + .word fmtbad-L5 # B + .word fmtbad-L5 # C + .word decimal-L5 # D + .word capital-L5 # E + .word fmtbad-L5 # F + .word capital-L5 # G + .word fmtbad-L5 # H + .word fmtbad-L5 # I + .word fmtbad-L5 # J + .word fmtbad-L5 # K + .word fmtbad-L5 # L + .word fmtbad-L5 # M + .word fmtbad-L5 # N + .word octal-L5 # O + .word fmtbad-L5 # P + .word fmtbad-L5 # Q + .word fmtbad-L5 # R + .word fmtbad-L5 # S + .word fmtbad-L5 # T + .word unsigned-L5 # U + .word fmtbad-L5 # V + .word fmtbad-L5 # W + .word hex-L5 # X + .word fmtbad-L5 # Y + .word fmtbad-L5 # Z + .word fmtbad-L5 # [ + .word fmtbad-L5 # \ + .word fmtbad-L5 # ] + .word fmtbad-L5 # ^ + .word fmtbad-L5 # _ + .word fmtbad-L5 # ` + .word fmtbad-L5 # a + .word fmtbad-L5 # b + .word charac-L5 # c + .word decimal-L5 # d + .word scien-L5 # e + .word float-L5 # f + .word general-L5 # g + .word short-L5 # h + .word fmtbad-L5 # i + .word fmtbad-L5 # j + .word fmtbad-L5 # k + .word longorunsg-L5 # l + .word fmtbad-L5 # m + .word fmtbad-L5 # n + .word octal-L5 # o + .word fmtbad-L5 # p + .word fmtbad-L5 # q + .word fmtbad-L5 # r + .word string-L5 # s + .word fmtbad-L5 # t + .word unsigned-L5 # u + .word fmtbad-L5 # v + .word fmtbad-L5 # w + .word hex-L5 # x +fmtbad: + movb r0,(r5)+ # print the unfound character + jeql errdone # dumb users who end the format with a % + jbr prbuf +capital: + bisl2 $1 + subl3 r1,r5,ndigit # raw width + subl3 ndigit,width,r0 # pad length + jleq padlno # in particular, no left padding + jbs $minsgn,flags,padlno + # extension for %0 flag causing left zero padding to field width + jbs $zfill,flags,padlz + # this bsbb needed even if %0 flag extension is removed + bsbb padb # blank pad on left + jbr padnlz +padlz: + movl llafx,r0 + jleq padnlx # left zero pad requires left affix first + subl2 r0,ndigit # part of total length will be transferred + subl2 r0,width # and will account for part of minimum width + bsbw strout # left affix +padnlx: + subl3 ndigit,width,r0 # pad length + bsbb padz # zero pad on left +padnlz: + # end of extension for left zero padding +padlno: # remaining: root, possible right padding + subl2 ndigit,width # root reduces minimum width + movl ndigit,r0 # root length +p1: bsbw strout # transfer to output buffer +p3: jbc $vbit,r2,padnpct # percent sign (or null byte via %c) ? + decl r0 # yes; adjust count + movzbl (r1)+,r2 # fetch byte + movq *fdesc,r4 # output buffer descriptor + sobgeq r4,p2 # room at the out [inn] ? + bsbw strout2 # no; force it, then try rest + jbr p3 # here we go 'round the mullberry bush, ... +p2: movb r2,(r5)+ # hand-deposit the percent or null + incl nchar # count it + movq r4,*fdesc # store output descriptor + jbr p1 # what an expensive hiccup! +padnpct: + movl width,r0 # size of pad + jleq loop + bsbb padb + jbr loop + +padz: + movb $'0,r2 + jbr pad +padb: + movb $' ,r2 +pad: + subl2 r0,width # pad width decreases minimum width + pushl r1 # save non-pad addr + movl r0,llafx # remember width of pad + subl2 r0,sp # allocate + movc5 $0,(r0),r2,llafx,(sp) # create pad string + movl llafx,r0 # length + movl sp,r1 # addr + bsbw strout + addl2 llafx,sp # deallocate + movl (sp)+,r1 # recover non-pad addr + rsb + +pone: .byte 0x1C # packed 1 + +charac: + movl (ap)+,r0 # word containing the char + movb r0,(r5)+ # one byte, that's all + +prbuf: + movl sp,r1 # addr first byte + jbr prstr + +space: bisl2 $1n, e>=n +gfmtf: + movl r7,r6 + subl2 r0,ndigit # n-e-1 + movab 16(sp),r1 + bsbw fedit +g1: jbs $numsgn,flags,g2 + jbs $dpflag,flags,g2 # dont strip if no decimal point +g3: cmpb -(r5),$'0 # strip trailing zeroes + jeql g3 + cmpb (r5),$'. # and trailing decimal point + jeql g2 + incl r5 +g2: jbc $gflag,flags,eexp + jbr prnum +gfmte: + movab 16(sp),r1 # packed source + bsbw eedit + jbsc $gflag,flags,g1 # gflag now means "use %f" [hence no exponent] + +general: + jbs $prec,flags,gn1 + movl $6,ndigit # default precision is 6 significant digits +gn1: tstl ndigit # cannot allow precision of 0 + jgtr gn2 + movl $1,ndigit # change 0 to 1, willy-nilly +gn2: jbcs $gflag,flags,L23 + jbr L23 # safety net + + # convert double-floating at (ap) to 17-digit packed at (sp), + # set 'sign' and 'exp', advance ap. +fltcvt: + clrb sign + movd (ap)+,r5 + jeql fzero + bgtr fpos + mnegd r5,r5 + incb sign +fpos: + extzv $7,$8,r5,r2 # exponent of 2 + movab -0200(r2),r2 # unbias + mull2 $59,r2 # 59/196: 3rd convergent continued frac of log10(2) + jlss eneg + movab 196(r2),r2 +eneg: + movab -98(r2),r2 + divl2 $196,r2 + bsbw expten + cmpd r0,r5 + bgtr ceil + incl r2 +ceil: movl r2,exp + mnegl r2,r2 + cmpl r2,$29 # 10^(29+9) is all we can handle + bleq getman + muld2 ten16,r5 + subl2 $16,r2 +getman: addl2 $9,r2 # -ceil(log10(x)) + 9 + bsbb expten + emodd r0,r4,r5,r0,r5 # (r0+r4)*r5; r0=int, r5=frac +fz1: cvtlp r0,$9,16(sp) # leading 9 digits + ashp $8,$9,16(sp),$0,$17,4(sp) # as top 9 of 17 + emodd ten8,$0,r5,r0,r5 + cvtlp r0,$8,16(sp) # trailing 8 digits + # if precision >= 17, must round here + movl ndigit,r7 # so figure out what precision is + pushab scien + cmpl (sp)+,(sp) + jleq gm1 # who called us? + addl2 exp,r7 # float; adjust for exponent +gm1: cmpl r7,$17 + jlss gm2 + cmpd r5,$0d0.5 # must round here; check fraction + jlss gm2 + bisb2 $0x10,8+4(sp) # increment l.s. digit +gm2: # end of "round here" code + addp4 $8,16(sp),$17,4(sp) # combine leading and trailing + bisb2 sign,12(sp) # and insert sign + rsb +fzero: clrl r0 + movl $1,exp # 0.000e+00 and 0.000 rather than 0.000e-01 and .000 + jbr fz1 + + .align 2 +lsb: .long 0x00010000 # lsb in the crazy floating-point format + + # return 10^r2 as a double float in r0||r1 and 8 extra bits of precision in r4 + # preserve r2, r5||r6 +expten: + movd $0d1.0,r0 # begin computing 10^exp10 + clrl r4 # bit counter + movad ten1,r3 # table address + tstl r2 + bgeq e10lp + mnegl r2,r2 # get absolute value + jbss $6,r2,e10lp # flag as negative +e10lp: jbc r4,r2,el1 # want this power? + muld2 (r3),r0 # yes +el1: addl2 $8,r3 # advance to next power + aobleq $5,r4,e10lp # through 10^32 + jbcc $6,r2,el2 # correct for negative exponent + divd3 r0,$0d1.0,r0 # by taking reciprocal + cmpl $28,r2 + jneq enm28 + addl2 lsb,r1 # 10**-28 needs lsb incremented +enm28: mnegl r2,r2 # original exponent of 10 +el2: addl3 $5*8,r2,r3 # negative bit positions are illegal? + jbc r3,xlsbh-5,eoklsb + subl2 lsb,r1 # lsb was too high +eoklsb: + movzbl xprec[r2],r4 # 8 extra bits + rsb + + # powers of ten + .align 2 +ten1: .word 0x4220,0,0,0 +ten2: .word 0x43c8,0,0,0 +ten4: .word 0x471c,0x4000,0,0 +ten8: .word 0x4dbe,0xbc20,0,0 +ten16: .word 0x5b0e,0x1bc9,0xbf04,0 +ten32: .word 0x759d,0xc5ad,0xa82b,0x70b6 + + # whether lsb is too high or not + .byte 1:0,1:0,1:0,1:0,1:1,1:0,1:1,1:0 # -40 thru -33 + .byte 1:0,1:1,1:0,1:0,1:0,1:0,1:1,1:0 # -32 thru -25 + .byte 1:0,1:0,1:1,1:1,1:1,1:1,1:0,1:0 # -24 thru -17 + .byte 1:0,1:1,1:0,1:0,1:1,1:1,1:1,1:1 # -16 thru -9 + .byte 1:1,1:1,1:1,1:0,1:0,1:0,1:0,1:1 # -8 thru -1 +xlsbh: + .byte 1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0 # 0 thru 7 + .byte 1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0 # 8 thru 15 + .byte 1:0,1:0,1:0,1:0,1:0,1:0,1:0,1:0 # 16 thru 23 + .byte 1:0,1:1,1:1,1:0,1:1,1:1,1:1,1:1 # 24 thru 31 + .byte 1:1,1:1,1:1,1:1,1:1,1:1,1:1 # 32 thru 38 + + # bytes of extra precision + .byte 0x56,0x76,0xd3,0x88,0xb5,0x62 # -38 thru -33 + .byte 0xba,0xf5,0x32,0x3e,0x0e,0x48,0xdb,0x51 # -32 thru -25 + .byte 0x53,0x27,0xb1,0xef,0xeb,0xa5,0x07,0x49 # -24 thru -17 + .byte 0x5b,0xd9,0x0f,0x13,0xcd,0xff,0xbf,0x97 # -16 thru -9 + .byte 0xfd,0xbc,0xb6,0x23,0x2c,0x3b,0x0a,0xcd # -8 thru -1 +xprec: + .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 # 0 thru 7 + .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 # 8 thru 15 + .byte 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 # 16 thru 23 + .byte 0x00,0xa0,0xc8,0x3a,0x84,0xe4,0xdc,0x92 # 24 thru 31 + .byte 0x9b,0x00,0xc0,0x58,0xae,0x18,0xef # 32 thru 38 diff --git a/usr/src/libc/stdio/doprnt.s.old b/usr/src/libc/stdio/doprnt.s.old new file mode 100644 index 0000000000..36211462fe --- /dev/null +++ b/usr/src/libc/stdio/doprnt.s.old @@ -0,0 +1,524 @@ + # C library -- conversions + +.globl __doprnt +.globl __strout + +#define flags r10 +#define literb 0 +#define liter 1 +#define ndfndb 0 +#define ndfnd 1 +#define ljustb 1 +#define ljust 2 +#define zfillb 2 +#define zfill 4 +#define precb 3 +#define prec 8 +#define psignb 4 +#define psign 16 +#define gflagb 5 +#define gflag 32 +#define width r9 +#define ndigit r8 +#define fdesc -4(fp) +#define exp -8(fp) +#define fmtend -12(fp) +#define sign -13(fp) + .set one,010 # 1.0 in floating immediate + .set ch.zer,'0 # cpp doesn't like single appostrophes + + .align 1 +__doprnt: + .word 0xfc0 # uses r11-r6 + subl2 $128,sp + movl 4(ap),r11 # addr of format string + movl 12(ap),fdesc # output FILE ptr + movl 8(ap),ap # addr of first arg +loop: + locc $0,$-1,(r11) # find end of format string + movl r1,fmtend # save addr of end of string +L1: + movl r11,r2 # current point in format + subl3 r2,fmtend,r3 # length of format remaining + beql L2 # if zero, all done + locc $'%,r3,(r2) # find next format command + movl r1,r11 # update format pointer + subl2 r0,r3 # length of string preceeding format + beql L3 # if none process directly + pushl fdesc # file pointer + pushl $0 # no left/right adjust + pushl r2 # addr + pushl r3 # length excluding % or null + calls $4,__strout # dump the literal + blbs (r11),L3 # % is odd; end of forrmat? +L2: + ret # yes + +L3: incl r11 # skip % char + movl sp,r5 # reset output buffer pointer + clrq r9 # width; flags ljustb,ndfndb,zfillb +L4: movzbl (r11)+,r0 # supposed format +L4a: cmpb $'*,r0 # caseb fails to check for values + jgtru notfnd # below lower range! + caseb r0,$'*,$'x +L5: .word indir-L5 # * + .word plus-L5 # + + .word notfnd-L5 # , + .word minus-L5 # - + .word dot-L5 # . + .word notfnd-L5 # / + .word gnum0-L5 # 0 + .word gnum-L5 # 1 + .word gnum-L5 # 2 + .word gnum-L5 # 3 + .word gnum-L5 # 4 + .word gnum-L5 # 5 + .word gnum-L5 # 6 + .word gnum-L5 # 7 + .word gnum-L5 # 8 + .word gnum-L5 # 9 + .word notfnd-L5 # : + .word notfnd-L5 # ; + .word notfnd-L5 # < + .word notfnd-L5 # = + .word notfnd-L5 # > + .word notfnd-L5 # ? + .word notfnd-L5 # @ + .word notfnd-L5 # A + .word notfnd-L5 # B + .word charac-L5 # C + .word long-L5 # D + .word lscien-L5 # E + .word lfloat-L5 # F + .word lgeneral-L5 # G + .word notfnd-L5 # H + .word notfnd-L5 # I + .word notfnd-L5 # J + .word notfnd-L5 # K + .word longorunsg-L5 # L + .word notfnd-L5 # M + .word notfnd-L5 # N + .word loct-L5 # O + .word notfnd-L5 # P + .word notfnd-L5 # Q + .word remote-L5 # R + .word string-L5 # S + .word notfnd-L5 # T + .word lunsigned-L5 # U + .word notfnd-L5 # V + .word notfnd-L5 # W + .word lhex-L5 # X + .word notfnd-L5 # Y + .word notfnd-L5 # Z + .word notfnd-L5 # [ + .word notfnd-L5 # \ + .word notfnd-L5 # ] + .word notfnd-L5 # ^ + .word notfnd-L5 # _ + .word notfnd-L5 # ` + .word notfnd-L5 # a + .word notfnd-L5 # b + .word charac-L5 # c + .word decimal-L5 # d + .word scien-L5 # e + .word float-L5 # f + .word general-L5 # g + .word notfnd-L5 # h + .word notfnd-L5 # i + .word notfnd-L5 # j + .word notfnd-L5 # k + .word longorunsg-L5 # l + .word notfnd-L5 # m + .word notfnd-L5 # n + .word octal-L5 # o + .word notfnd-L5 # p + .word notfnd-L5 # q + .word remote-L5 # r + .word string-L5 # s + .word notfnd-L5 # t + .word unsigned-L5 # u + .word notfnd-L5 # v + .word notfnd-L5 # w + .word hex-L5 # x + +notfnd: movb r0,(r5)+ # print the unfound character + jbr prbuf + +nulstr: + .byte '(,'n,'u,'l,'l,'),0 + +string: + movl ndigit,r0 + jbs $precb,flags,L20 # max length was specified + mnegl $1,r0 # default max length +L20: movl (ap)+,r2 # addr first byte + bneq L21 + movab nulstr,r2 +L21: locc $0,r0,(r2) # find the zero at the end + movl r1,r5 # addr last byte +1 + movl r2,r1 # addr first byte + jbr prstr + + +longorunsg: + movb (r11)+,r0 + cmpb r0,$'o + jeql loct + cmpb r0,$'x + jeql lhex + cmpb r0,$'d + jeql long + cmpb r0,$'u + jeql lunsigned + decl r11 + jbr unsigned + + +loct: +octal: + movl $30,r2 # init position + movl $3,r3 # field width + movl $10,r4 # result length -1 + jbr L10 + +lhex: +hex: + movl $28,r2 # init position + movl $4,r3 # field width + movl $7,r4 # result length -1 +L10: mnegl r3,r6 # increment + clrl r1 + movl (ap)+,r0 # fetch arg +L11: extzv r2,r3,r0,r1 # pull out a digit + movb htab[r1],(r5)+ # convert to character +L12: acbl $0,r6,r2,L11 # continue until done + clrb (r5) # flag end + skpc $'0,r4,(sp) # skip over leading zeroes + jbr prstr + +htab: .byte '0,'1,'2,'3,'4,'5,'6,'7,'8,'9,'a,'b,'c,'d,'e,'f + +patdec: # editpc pattern for decimal printing + .byte 0xA9 # eo$float 9 + .byte 0x01 # eo$end_float + .byte 0x91 # eo$move 1 + .byte 0 # eo$end + +long: +decimal: + cvtlp (ap)+,$10,(sp) # 10 digits max +L14: editpc $10,(sp),patdec,8(sp) # ascii at 8(sp); r5=end+1 + skpc $' ,$10,8(sp) # skip leading blanks; r1=first + +prstr: # r1=addr first byte; r5=addr last byte +1 + cvtbl $' ,-(sp) # blank fill + jbc $zfillb,flags,L15 + cvtbl $'0,(sp) # zero fill +L15: pushl fdesc # FILE + subl2 r1,r5 # r5=actual length=end+1-first + subl3 r5,width,r0 # if >0, how much to fill + bgeq L24 + clrl r0 # no fill +L24: jbs $ljustb,flags,L25 + mnegl r0,r0 +L25: pushl r0 # fill count + pushl r1 # addr first byte + pushl r5 # length + calls $5,__strout + jbr L1 + +pone: .byte 0x1C # packed 1 + +unsigned: +lunsigned: + extzv $1,$31,(ap),r0 # right shift logical 1 bit + cvtlp r0,$10,(sp) # convert [n/2] to packed + movp $10,(sp),8(sp) # copy packed + addp4 $10,8(sp),$10,(sp) # 2*[n/2] in packed, at (sp) + blbc (ap)+,L14 # n was even + addp4 $1,pone,$10,(sp) # n was odd + jbr L14 + +charac: + movl $4,r0 # chars per word +L18: movb (ap)+,(r5)+ # transfer char + bneq L19 + decl r5 # omit null characters +L19: sobgtr r0,L18 + +prbuf: + movl sp,r1 # addr first byte + jbr prstr + +plus: bisl2 $psign,flags # always print sign for floats + jbr L4 +minus: bisl2 $ljust,flags # left justification, please + jbr L4 +gnum0: jbs $ndfndb,flags,gnum + jbs $precb,flags,gnump # ignore when reading precision + bisl2 $zfill,flags # leading zero fill, please +gnum: jbs $precb,flags,gnump + moval (width)[width],width # width *= 5; + movaw -ch.zer(r0)[width],width # width = 2*witdh + r0 - '0'; + bisl2 $ndfnd,flags # digit seen + jbr L4 +gnump: moval (ndigit)[ndigit],ndigit # ndigit *= 5; + movaw -ch.zer(r0)[ndigit],ndigit # ndigit = 2*ndigit + r0 - '0'; + bisl2 $ndfnd,flags # digit seen + jbr L4 +dot: clrl ndigit # start on the precision + bisl2 $prec,flags + bicl2 $ndfnd,flags + jbr L4 +indir: jbs $precb,flags,indirp # check for width spec + movl (ap)+,width # width specified by parameter + bisl2 $ndfnd,flags # digit seen + jbr L4 +indirp: movl (ap)+,ndigit + bisl2 $ndfnd,flags # digit seen + jbr L4 +remote: movl (ap)+,ap + movl (ap)+,r11 + jbr loop + +lfloat: +float: + bsbw fltcvt +fltg: jbs $ndfndb,flags,float1 + movl $6,ndigit # default # digits to right of decpt. +float1: addl3 exp,ndigit,r7 + movl r7,r6 # for later "underflow" checking + bgeq fxplrd + clrl r7 # poor programmer planning +fxplrd: cmpl r7,$31 # expressible in packed decimal? + bleq fnarro # yes + movl $31,r7 +fnarro: subl3 $17,r7,r0 # where to round + ashp r0,$17,(sp),$5,r7,16(sp) # do it + bvc fnovfl + # band-aid for microcode error (spurious overflow) + clrl r0 # assume even length result + jlbc r7,fleven # right + movl $4,r0 # odd length result +fleven: cmpv r0,$4,16(sp),$0 # top digit zero iff true overflow + bneq fnovfl + # end band-aid + aobleq $0,r6,fnovfl # if "underflow" then jump + movl r7,r0 + incl exp + incl r7 + ashp r0,$1,pone,$0,r7,16(sp) + ashl $-1,r7,r0 # displ to last byte + bisb2 sign,16(sp)[r0] # insert sign +fnovfl: + movc3 $4,patsci,(sp) + clrl r6 # # digits moved so far + movl exp,r0 + bleq fexpng + bsbb patmov # digits to left of decpt. +fexpng: tstl ndigit + jeql fnodp + movc3 $2,fpatdp,(r3) + tstl exp + bgeq fxppos + addl3 exp,ndigit,r6 + bgeq flfakl + clrl r6 # it's all fill +flfakl: subl3 r6,$31,r6 # fake length for patmov +flfill: movc3 $2,fpatzf,(r3) # zero fill to right of dec.pt +fxppos: movl ndigit,r0 + bsbb patmov +fnodp: sobgeq r6,fledit # must move at least 1 digit + movl $31,r6 # none moved; fake it + aobleq $1,ndigit,flfill # with a one-character zero fill +fledit: editpc r7,16(sp),(sp),32(sp) + jbr prflt + +patexp: .byte 0x03 # eo$set_signif + .byte 0x44,'e # eo$insert 'e + .byte 0x42,'+ # eo$load_plus '+ + .byte 0x04 # eo$store_sign + .byte 0x92 # eo$move 2 + .byte 0 # eo$end +patsci: .byte 0x42,'+ # eo$load_plus '+ + .byte 0x03 # eo$set_signif + .byte 0x04 # eo$store_sign + .byte 0x91 # eo$move 1 +fpatdp: .byte 0x44,'. # eo$insert '. +fpatzf: .byte 0x40,'0 # eo$load_fill '0 + + # construct pattern at (r3) to move r0 digits in editpc; + # r6 digits already moved for this number +patmov: + movb $0x90,r2 # eo$move + subl3 r6,$31,r1 # # digits remaining in packed + addl2 r0,r6 + cmpl r0,r1 # enough digits remaining? + bleq patsml # yes + tstl exp # zero 'fill'; before or after rest? + bgeq pataft # after + pushl r1 # # digits remaining + movb $0x80,r2 # eo$fill + subl3 $31,r6,r0 # number of fill bytes + bsbb patsml # recursion! + movl (sp)+,r0 + movb $0x90,r2 # eo$move + jbr patsml +pataft: movl r1,r0 # last of the 31 + bsbb patsml # recursion! + subl3 $31,r6,r0 # number of fill bytes + movb $0x80,r2 # eo$fill +patsml: tstl r0 + bleq patzer # DEC doesn't like repetition counts of 0 + mnegl $15,r1 # 15 digits at a time + subl2 r1,r0 # counteract acbl + jbr pattst +patmlp: bisb3 r2,$15,(r3)+ # 15 +pattst: acbl $16,r1,r0,patmlp # until <= 15 left + bisb3 r2,r0,(r3)+ # rest +patzer: clrb (r3) # eo$end + rsb + +lscien: +scien: + bsbw fltcvt # get packed digits +scig: incl ndigit + jbs $ndfndb,flags,L23 + movl $7,ndigit +L23: subl3 $17,ndigit,r0 # rounding position + ashp r0,$17,(sp),$5,ndigit,16(sp) # shift and round + bvc snovfl + # band-aid for microcode error (spurious overflow) + clrl r0 # assume even length result + jlbc ndigit,sceven # right + movl $4,r0 # odd length result +sceven: cmpv r0,$4,16(sp),$0 # top digit zero iff true overflow + bneq snovfl + # end band-aid + incl exp # rounding overflowed to 100... + subl3 $1,ndigit,r0 + ashp r0,$1,pone,$0,ndigit,16(sp) + ashl $-1,ndigit,r0 # displ to last byte + bisb2 sign,16(sp)[r0] # insert sign +snovfl: + jbc $gflagb,flags,enotg # not %g format + # find trailing zeroes in packed number + ashl $-1,ndigit,r0 + addl2 r3,r0 # addr of l.s.digit and sign + movl $4,r1 # bit position of digit + movl ndigit,r7 # current length of packed + jbr gtz +gtz1: xorl2 $4,r1 # position of next digit + bneq gtz # same byte + decl r0 # different byte +gtz: cmpv r1,$4,(r0),$0 # a trailing zero? + jneq gntz + sobgtr r7,gtz1 + incl r7 +gntz: # r7: minimum width of fraction + cmpl exp,$-4 + jleq eg # small exponents use %e + subl3 r7,exp,r0 + cmpl $5,r0 + jleq eg # so do (w+5) <= exp + tstl r0 # rest use %f + jleq fg # did we trim too many trailing zeroes? + movl exp,r7 # yes +fg: subl3 ndigit,r7,r0 + ashp r0,ndigit,16(sp),$0,r7,(sp) + movp r7,(sp),16(sp) + subl3 exp,r7,ndigit # correct ndigit for %f + jbr fnovfl +eg: subl3 ndigit,r7,r0 + ashp r0,ndigit,16(sp),$0,r7,(sp) + movp r7,(sp),16(sp) + movl r7,ndigit # packed number has been trimmed +enotg: + movc3 $7,patsci,(sp) + movl $1,r6 # 1P + subl3 $1,ndigit,r0 # digits after dec.pt + bsbw patmov + editpc ndigit,16(sp),(sp),32(sp) # 32(sp)->result, r5->(end+1) + decl exp # compensate: 1 digit left of dec.pt + cvtlp exp,$2,(sp) # exponent + editpc $2,(sp),patexp,(r5) +prflt: movab 32(sp),r1 + jbs $psignb,flags,prflt1 + cmpb (r1)+,$'+ + beql prflt1 + decl r1 +prflt1: skpc $' ,$63,(r1) + jbr prstr + +lgeneral: +general: + jbcs $gflagb,flags,scien + jbr scien # safety net + + # convert double-floating at (ap) to 17-digit packed at (sp), + # set 'sign' and 'exp', advance ap. +fltcvt: + clrb sign + movd (ap)+,r5 + jeql fzero + bgtr fpos + mnegd r5,r5 + incb sign +fpos: + extzv $7,$8,r5,r2 # exponent of 2 + movaw -0600(r2)[r2],r2 # unbias and mult by 3 + bgeq epos + subl2 $9,r2 +epos: divl2 $10,r2 + bsbb expten + cmpd r0,r5 + bgtr ceil + incl r2 +ceil: movl r2,exp + mnegl r2,r2 + cmpl r2,$29 # 10^(29+9) is all we can handle + bleq getman + muld2 ten16,r5 + subl2 $16,r2 +getman: addl2 $9,r2 # -ceil(log10(x)) + 9 + bsbb expten + emodd r0,r4,r5,r0,r5 # (r0+r4)*r5; r0=int, r5=frac +fz1: cvtlp r0,$9,16(sp) # leading 9 digits + ashp $8,$9,16(sp),$0,$17,4(sp) # as top 9 of 17 + emodd ten8,$0,r5,r0,r5 + cvtlp r0,$8,16(sp) # trailing 8 digits + addp4 $8,16(sp),$17,4(sp) # combine leading and trailing + bisb2 sign,12(sp) # and insert sign + rsb +fzero: clrl r0 + movl $1,exp # 0.000e+00 and 0.000 rather than 0.000e-01 and .000 + jbr fz1 + + # return 10^r2 as a double float in r0||r1 and 8 extra bits of precision in r4 + # preserve r2, r5||r6 +expten: + movd $one,r0 # begin computing 10^exp10 + clrl r4 # bit counter + movad ten1,r3 # table address + tstl r2 + bgeq e10lp + mnegl r2,r2 # get absolute value + jbss $6,r2,e10lp # flag as negative +e10lp: jbc r4,r2,el1 # want this power? + muld2 (r3),r0 # yes +el1: addl2 $8,r3 # advance to next power + aobleq $5,r4,e10lp # through 10^32 + jbcc $6,r2,el2 # correct for negative exponent + divd3 r0,$one,r0 # by taking reciprocal + mnegl r2,r2 +el2: clrl r4 # 8 extra bits of precision + rsb + + # powers of ten + .align 3 +ten1: .word 0x4220,0,0,0 +ten2: .word 0x43c8,0,0,0 +ten4: .word 0x471c,0x4000,0,0 +ten8: .word 0x4dbe,0xbc20,0,0 +ten16: .word 0x5b0e,0x1bc9,0xbf04,0 +ten32: .word 0x759d,0xc5ad,0xa82b,0x70b6 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..7401847e1c --- /dev/null +++ b/usr/src/libc/stdio/filbuf.c @@ -0,0 +1,38 @@ +#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; + if (iop == stdin && (stdout->_flag&_IOLBF)) + fflush(stdout); + 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..fbbb167c93 --- /dev/null +++ b/usr/src/libc/stdio/flsbuf.c @@ -0,0 +1,109 @@ +#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&_IOLBF) { + base = iop->_base; + *iop->_ptr++ = c; + if (iop->_ptr >= base+BUFSIZ || c == '\n') { + n = write(fileno(iop), base, rn = iop->_ptr - base); + iop->_ptr = base; + } else + rn = n = 0; + iop->_cnt = 0; + } else 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 |= _IOLBF; + 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 = (iop->_flag&(_IOLBF|_IONBF)) ? 0 : 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|_IOLBF)) + iop->_base = NULL; + } + iop->_flag &= ~(_IOREAD|_IOWRT|_IOLBF|_IONBF|_IOMYBUF|_IOERR|_IOEOF|_IOSTRG); + iop->_cnt = 0; + return(r); +} diff --git a/usr/src/libc/stdio/fopen.c b/usr/src/libc/stdio/fopen.c new file mode 100644 index 0000000000..ed3b998b98 --- /dev/null +++ b/usr/src/libc/stdio/fopen.c @@ -0,0 +1,37 @@ +#include +#include + +FILE * +fopen(file, mode) +char *file; +register char *mode; +{ + extern int errno; + register f; + register FILE *iop; + extern FILE *_lastbuf; + + for (iop = _iob; iop->_flag&(_IOREAD|_IOWRT); iop++) + if (iop >= _lastbuf) + return(NULL); + if (*mode=='w') + f = creat(file, 0666); + else if (*mode=='a') { + if ((f = open(file, 1)) < 0) { + if (errno == ENOENT) + f = creat(file, 0666); + } + if (f >= 0) + lseek(f, 0L, 2); + } else + f = open(file, 0); + if (f < 0) + return(NULL); + iop->_cnt = 0; + iop->_file = f; + if (*mode != 'r') + iop->_flag |= _IOWRT; + else + iop->_flag |= _IOREAD; + return(iop); +} 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/fstab.c b/usr/src/libc/stdio/fstab.c new file mode 100644 index 0000000000..ccd51eac65 --- /dev/null +++ b/usr/src/libc/stdio/fstab.c @@ -0,0 +1,114 @@ +#include +#include +#include + +static struct fstab fs; +static FILE *fs_file = 0; + +static char *fs_string(back, string, lg, end) + char *string, *back; + int lg; /* length of field to stuff into */ + char end; +{ + register char *cp; + for (cp = string; *cp && *cp != end; cp++) + continue; + if (*cp == '\0') return(0); + *cp = '\0'; + strncpy(back, string, lg-1); + return(cp+1); +} +static char *fs_digit(backp, string, end) + int *backp; + char *string; + char end; +{ + register int value = 0; + register char *cp; + for (cp = string; *cp && isdigit(*cp); cp++){ + value *= 10; + value += *cp - '0'; + } + if (*cp == '\0') return(0); + *backp = value; + while ( *cp && *cp != end) + cp++; + if (*cp == '\0') return(0); + return(cp+1); +} + +static int fstabscan(fsp) + struct fstab *fsp; +{ + register char *cp; + char buf[256]; + if (fgets(buf, 256, fs_file) == NULL) + return(EOF); + cp = buf; + cp = fs_string(&fsp->fs_spec[0], cp, FSNMLG, ':'); + if (cp == 0) return(0); + cp = fs_string(&fsp->fs_file[0], cp, FSNMLG, ':'); + if (cp == 0) return(1); + cp = fs_string(&fsp->fs_type[0], cp, 3, ':'); + if (cp == 0) return(2); + cp = fs_digit(&fsp->fs_freq, cp, ':'); + if (cp == 0) return(3); + cp = fs_digit(&fsp->fs_passno, cp, '\n'); + if (cp == 0) return(4); + return(5); +} + +int setfsent() +{ + if (fs_file) + endfsent(); + if ( (fs_file = fopen(FSTAB, "r")) == NULL){ + fs_file = 0; + return(0); + } + return(1); +} + +int endfsent() +{ + if (fs_file){ + fclose(fs_file); + } + return(1); +} + +struct fstab *getfsent() +{ + int nfields; + + if ( (fs_file == 0) && (setfsent() == 0) ) + return(0); + nfields = fstabscan(&fs); + if (nfields == EOF || nfields != FSTABNARGS) + return(0); + return(&fs); +} +struct fstab *getfsspec(name) + char *name; +{ + register struct fstab *fsp; + if (setfsent() == 0) /* start from the beginning */ + return(0); + while( (fsp = getfsent()) != 0){ + if (strncmp(fsp->fs_spec, name, sizeof(fsp->fs_spec)) == 0) + return(fsp); + } + return(0); +} +struct fstab *getfsfile(name) + char *name; +{ + register struct fstab *fsp; + if (setfsent() == 0) /* start from the beginning */ + return(0); + while ( (fsp = getfsent()) != 0){ + if (strncmp(fsp->fs_file, name, sizeof(fsp->fs_spec)) == 0) + return(fsp); + } + return(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..c8bc9fb5cc --- /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 = fdopen(open("/dev/tty", 2), "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/makefile b/usr/src/libc/stdio/makefile new file mode 100644 index 0000000000..167ca19fcd --- /dev/null +++ b/usr/src/libc/stdio/makefile @@ -0,0 +1,32 @@ +CFLAGS=-O + +o=getgrgid.o getgrnam.o getgrent.o getpwnam.o getpwuid.o getpwent.o\ +intss.o getchar.o putchar.o fgetc.o fputc.o freopen.o fdopen.o\ +fgets.o fputs.o getpw.o fseek.o rew.o rdwr.o stuff.o\ +system.o tmpnam.o popen.o fopen.o scanf.o doscan.o\ +fprintf.o gets.o getw.o printf.o puts.o putw.o\ +sprintf.o ungetc.o filbuf.o setbuf.o doprnt.o ffltpr.o\ +strout.o flsbuf.o error.o ftell.o gcvt.o clrerr.o\ +data.o + +libS.a : $o + ar cr libS.a $o + +clean : + rm -f *.o + +doprnt.o : + cp doprnt.s doprnt.c + cc -E doprnt.c | as -o doprnt.o + -ld -x -r doprnt.o + mv a.out doprnt.o + rm doprnt.c + +.c.o : + cc $(CFLAGS) -c $*.c + -ld -x -r $*.o + mv a.out $*.o + +.s.o : + as -o $*.o $*.s + diff --git a/usr/src/libc/stdio/popen.c b/usr/src/libc/stdio/popen.c new file mode 100644 index 0000000000..09b725e901 --- /dev/null +++ b/usr/src/libc/stdio/popen.c @@ -0,0 +1,54 @@ +#include +#include +#define tst(a,b) (*mode == 'r'? (b) : (a)) +#define RDR 0 +#define WTR 1 +static int popen_pid[20]; + +FILE * +popen(cmd,mode) +char *cmd; +char *mode; +{ + int p[2]; + register myside, hisside, pid; + + if(pipe(p) < 0) + return NULL; + myside = tst(p[WTR], p[RDR]); + hisside = tst(p[RDR], p[WTR]); + if((pid = vfork()) == 0) { + /* myside and hisside reverse roles in child */ + close(myside); + dup2(hisside, tst(0, 1)); + close(hisside); + execl("/bin/sh", "sh", "-c", cmd, 0); + _exit(1); + } + if(pid == -1) + return NULL; + popen_pid[myside] = pid; + close(hisside); + return(fdopen(myside, mode)); +} + +pclose(ptr) +FILE *ptr; +{ + register f, r, (*hstat)(), (*istat)(), (*qstat)(); + int status; + + f = fileno(ptr); + fclose(ptr); + istat = signal(SIGINT, SIG_IGN); + qstat = signal(SIGQUIT, SIG_IGN); + hstat = signal(SIGHUP, SIG_IGN); + while((r = wait(&status)) != popen_pid[f] && r != -1) + ; + if(r == -1) + status = -1; + signal(SIGINT, istat); + signal(SIGQUIT, qstat); + signal(SIGHUP, hstat); + return(status); +} 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..94de0d44af --- /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|_IOLBF); + 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/system.c b/usr/src/libc/stdio/system.c new file mode 100644 index 0000000000..c8ed4ca592 --- /dev/null +++ b/usr/src/libc/stdio/system.c @@ -0,0 +1,22 @@ +#include + +system(s) +char *s; +{ + int status, pid, w; + register int (*istat)(), (*qstat)(); + + if ((pid = vfork()) == 0) { + execl("/bin/sh", "sh", "-c", s, 0); + _exit(127); + } + istat = signal(SIGINT, SIG_IGN); + qstat = signal(SIGQUIT, SIG_IGN); + while ((w = wait(&status)) != pid && w != -1) + ; + if (w == -1) + status = -1; + signal(SIGINT, istat); + signal(SIGQUIT, qstat); + return(status); +} 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..27589a9a72 --- /dev/null +++ b/usr/src/libc/sys/abs.s @@ -0,0 +1,12 @@ +# 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 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.dead b/usr/src/libc/sys/cleanup.s.dead new file mode 100644 index 0000000000..75e7782b24 --- /dev/null +++ b/usr/src/libc/sys/cleanup.s.dead @@ -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/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/fabs.s b/usr/src/libc/sys/fabs.s new file mode 100644 index 0000000000..67f209a976 --- /dev/null +++ b/usr/src/libc/sys/fabs.s @@ -0,0 +1,9 @@ +.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/fork.s b/usr/src/libc/sys/fork.s new file mode 100644 index 0000000000..9862d698c4 --- /dev/null +++ b/usr/src/libc/sys/fork.s @@ -0,0 +1,20 @@ +# C library -- fork + +# pid = fork(); +# +# r1 == 0 in parent process, r1 == 1 in child process. +# r0 == pid of child in parent, r0 == pid of parent in child. + + .set fork,2 +.globl _fork + +_fork: + .word 0x0000 + chmk $fork + bcc forkok + jmp cerror +forkok: + jlbc r1,parent + clrl r0 # signify child +parent: + ret 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/lseek.s b/usr/src/libc/sys/lseek.s new file mode 100644 index 0000000000..afd125f66c --- /dev/null +++ b/usr/src/libc/sys/lseek.s @@ -0,0 +1,15 @@ +# C library -- lseek + +# error = lseek(file, offset, ptr); + + .set lseek,19 +.globl _lseek +.globl cerror + +_lseek: + .word 0x0000 + chmk $lseek + bcc noerror + jmp cerror +noerror: + ret 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/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/mpxcall.s b/usr/src/libc/sys/mpxcall.s new file mode 100644 index 0000000000..4e05b466bf --- /dev/null +++ b/usr/src/libc/sys/mpxcall.s @@ -0,0 +1,17 @@ +# C library -- mpxcall + +# mpxcall(file, buffer, count); +# +# + + .set mpxcall,56 +.globl _mpxcall +.globl cerror + +_mpxcall: + .word 0x0000 + chmk $mpxcall + bcc noerror + jmp cerror +noerror: + 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/setjmp.s b/usr/src/libc/sys/setjmp.s new file mode 100644 index 0000000000..c514b229b0 --- /dev/null +++ b/usr/src/libc/sys/setjmp.s @@ -0,0 +1,41 @@ +# C library -- setjmp, longjmp + +# longjmp(a,v) +# will generate a "return(v)" from +# the last call to +# setjmp(a) +# by restoring r6-pc from 'a' +# and doing a return. +# + +.globl _setjmp +.globl _longjmp + + .align 1 +_setjmp: + .word 0x0000 + movl 4(ap),r0 + movq r6,(r0)+ + movq r8,(r0)+ + movq r10,(r0)+ + movq 8(fp),(r0)+ # ap, fp + movab 8(ap),(r0)+ # sp + movl 16(fp),(r0) # pc + clrl r0 + ret + + .align 1 +_longjmp: + .word 0x0000 + movl 8(ap),r0 # return(v) + movl 4(ap),r1 + movq (r1)+,r6 + movq (r1)+,r8 + movq (r1)+,r10 + movq (r1)+,r12 + movl (r1)+,sp + tstl r0 + bneq L1 + movzbl $1,r0 +L1: + jmp *(r1) 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/vadvise.s b/usr/src/libc/sys/vadvise.s new file mode 100644 index 0000000000..48d214c94e --- /dev/null +++ b/usr/src/libc/sys/vadvise.s @@ -0,0 +1,15 @@ +# C library -- vadvise + +# error = vadvise(how); + + .set vadvise,64+8 +.globl _vadvise + +_vadvise: + .word 0x0000 + chmk $vadvise + bcc noerror + jmp cerror +noerror: + clrl r0 + ret diff --git a/usr/src/libc/sys/vfork.s b/usr/src/libc/sys/vfork.s new file mode 100644 index 0000000000..c4a99c8acc --- /dev/null +++ b/usr/src/libc/sys/vfork.s @@ -0,0 +1,37 @@ +# C library -- vfork + +# pid = vfork(); +# +# r1 == 0 in parent process, r1 == 1 in child process. +# r0 == pid of child in parent, r0 == pid of parent in child. +# +# trickery here, due to keith sklower, uses ret to clear the stack, +# and then returns with a jump indirect, since only one person can return +# with a ret off this stack... we do the ret before we vfork! +# + + .set vfork,66 +.globl _vfork + +_vfork: + .word 0x0000 + movl 16(fp),r2 + movab here,16(fp) + ret +here: + chmk $vfork + bcc vforkok + jmp verror +vforkok: + tstl r1 # child process ? + bneq child # yes + bcc parent # if c-bit not set, fork ok +.globl _errno +verror: + movl r0,_errno + mnegl $1,r0 + jmp (r2) +child: + clrl r0 +parent: + jmp (r2) diff --git a/usr/src/libc/sys/vhangup.s b/usr/src/libc/sys/vhangup.s new file mode 100644 index 0000000000..8ee941990b --- /dev/null +++ b/usr/src/libc/sys/vhangup.s @@ -0,0 +1,9 @@ +# vhangup -- revoke access to terminal + + .set vhangup,64+12 +.globl _vhangup + +_vhangup: + .word 0x0000 + chmk $vhangup + ret diff --git a/usr/src/libc/sys/vlimit.s b/usr/src/libc/sys/vlimit.s new file mode 100644 index 0000000000..60140b39b9 --- /dev/null +++ b/usr/src/libc/sys/vlimit.s @@ -0,0 +1,15 @@ +# C library -- vlimit + +# oldvalue = vlimit(what, newvalue); +# if newvalue == -1 old value is returned and the limit is not changed + + .set vlimit,64+13 +.globl _vlimit + +_vlimit: + .word 0x0000 + chmk $vlimit + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/vread.s b/usr/src/libc/sys/vread.s new file mode 100644 index 0000000000..cb44a6ed01 --- /dev/null +++ b/usr/src/libc/sys/vread.s @@ -0,0 +1,17 @@ +# C library -- vread + +# nread = vread(file, buffer, count); +# +# nread ==0 means eof; nread == -1 means error + + .set vread,3+64 +.globl _vread +.globl cerror + +_vread: + .word 0x0000 + chmk $vread + bcc noerror + jmp cerror +noerror: + ret diff --git a/usr/src/libc/sys/vtimes.s b/usr/src/libc/sys/vtimes.s new file mode 100644 index 0000000000..fda798f230 --- /dev/null +++ b/usr/src/libc/sys/vtimes.s @@ -0,0 +1,9 @@ +# C library -- times + + .set vtimes,64+43 +.globl _vtimes + +_vtimes: + .word 0x0000 + chmk $vtimes + ret diff --git a/usr/src/libc/sys/vwait.s b/usr/src/libc/sys/vwait.s new file mode 100644 index 0000000000..aade10a958 --- /dev/null +++ b/usr/src/libc/sys/vwait.s @@ -0,0 +1,26 @@ +# C library -- vwait + +# pid = vwait(0, &vms); +# or, +# pid = vwait(&status, &vms); +# +# pid == -1 if error +# status indicates fate of process, if given +# vms is a vmstat structure + + .set vwait,64+7 +.globl _vwait +.globl cerror + + .align 1 +_vwait: + .word 0x0000 + chmk $vwait + 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/vwrite.s b/usr/src/libc/sys/vwrite.s new file mode 100644 index 0000000000..b4978d1387 --- /dev/null +++ b/usr/src/libc/sys/vwrite.s @@ -0,0 +1,17 @@ +# C library -- vwrite + +# nwritten = vwrite(file, buffer, count); +# +# nwritten == -1 means error + + .set vwrite,4+64 +.globl _vwrite +.globl cerror + +_vwrite: + .word 0x0000 + chmk $vwrite + 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