From 539c3f82a6097c5cfdfa4677f33bbf93a8a85911 Mon Sep 17 00:00:00 2001 From: jshepher <> Date: Thu, 9 Sep 2004 22:52:26 +0000 Subject: [PATCH] libnix 2.0 import --- libnix/Makefile.in | 131 ++--- libnix/README.BETA | 31 ++ libnix/configure | 274 +++------- libnix/configure.in | 20 +- libnix/examples/simpledev.c | 15 +- libnix/examples/simplelib.c | 16 +- libnix/install-sh | 251 +++++++++ libnix/sources/Makefile.in | 33 +- libnix/sources/amiga/Makefile.in | 26 +- libnix/sources/amiga/misc/AbsExecBase.c | 2 +- libnix/sources/amiga/misc/AsmAllocPooled.c | 2 +- libnix/sources/amiga/misc/AsmCreatePool.c | 2 +- libnix/sources/amiga/misc/AsmFreePooled.c | 2 +- libnix/sources/amiga/misc/BeginIO.c | 4 +- libnix/sources/amiga/misc/Cia.c | 2 +- libnix/sources/amiga/misc/CreateIO.c | 2 +- libnix/sources/amiga/misc/CreateTask.c | 5 +- libnix/sources/amiga/misc/Custom.c | 2 +- libnix/sources/amiga/misc/DeleteTask.c | 4 +- libnix/sources/amiga/misc/DoPktn.c | 7 + libnix/sources/amiga/misc/LibAllocPooled.c | 2 +- libnix/sources/amiga/misc/LibCreatePool.c | 2 +- libnix/sources/amiga/misc/LibFreePooled.c | 2 +- libnix/sources/amiga/misc/WaitBeam.c | 2 +- libnix/sources/headers/bases.h | 6 +- libnix/sources/headers/debuglib.h | 25 +- libnix/sources/headers/dirent.h | 9 +- libnix/sources/headers/inline/amitcp.h | 201 +++++++ libnix/sources/headers/inline/as225.h | 296 +++++++++++ libnix/sources/headers/inline/usergroup.h | 173 ++++++ libnix/sources/headers/libinit.h | 43 +- libnix/sources/headers/pool.h | 7 +- libnix/sources/headers/rand48.h | 5 + libnix/sources/headers/regparm.h | 4 + libnix/sources/headers/select.h | 28 + libnix/sources/headers/socket.h | 104 ++++ libnix/sources/headers/stabs.h | 8 +- libnix/sources/headers/stdio.h | 120 ++++- libnix/sources/headers/strsup.h | 14 +- libnix/sources/history | 73 ++- libnix/sources/math/Makefile.in | 19 +- libnix/sources/misc/Makefile.in | 7 +- libnix/sources/misc/detach.c | 2 +- libnix/sources/nix/Makefile.in | 13 +- libnix/sources/nix/errno/__seterrno.c | 28 +- libnix/sources/nix/extra/__amigapath.c | 2 +- libnix/sources/nix/extra/access.c | 4 +- libnix/sources/nix/extra/bcmp.c | 2 +- libnix/sources/nix/extra/chdir.c | 4 +- libnix/sources/nix/extra/chmod.c | 29 +- libnix/sources/nix/extra/creat.c | 2 - libnix/sources/nix/extra/dirent.c | 36 +- libnix/sources/nix/extra/fdtofh.c | 9 +- libnix/sources/nix/extra/fstat.c | 40 +- libnix/sources/nix/extra/getrusage.c | 3 +- libnix/sources/nix/extra/gettimeofday.c | 31 ++ libnix/sources/nix/extra/mkdir.c | 2 +- libnix/sources/nix/extra/mktemp.c | 18 +- libnix/sources/nix/extra/rmdir.c | 2 +- libnix/sources/nix/extra/setbuffer.c | 5 +- libnix/sources/nix/extra/setlinebuf.c | 6 +- libnix/sources/nix/extra/stat.c | 2 +- libnix/sources/nix/extra/stpcpy.c | 4 +- libnix/sources/nix/extra/strdup.c | 8 +- libnix/sources/nix/extra/stricmp.c | 4 +- libnix/sources/nix/extra/strlower.c | 10 +- libnix/sources/nix/extra/strnicmp.c | 5 +- libnix/sources/nix/extra/strupper.c | 10 +- libnix/sources/nix/extra/times.c | 36 +- libnix/sources/nix/extra/unlink.c | 2 +- libnix/sources/nix/extra/utime.c | 15 +- libnix/sources/nix/extra/utimes.c | 11 +- libnix/sources/nix/locale/setlocale.c | 19 +- libnix/sources/nix/math/__divsi3.c | 2 +- libnix/sources/nix/math/__eqdf2.c | 2 +- libnix/sources/nix/math/__eqsf2.c | 2 +- libnix/sources/nix/math/__mulsi3.c | 2 +- libnix/sources/nix/math/__udivsi3.c | 2 +- libnix/sources/nix/misc/__request.c | 2 +- libnix/sources/nix/misc/bcopy.c | 62 ++- libnix/sources/nix/misc/bzero.c | 31 +- libnix/sources/nix/stdio/__fflush.c | 22 +- libnix/sources/nix/stdio/__srget.c | 18 +- libnix/sources/nix/stdio/__stdio.c | 20 +- libnix/sources/nix/stdio/__swbuf.c | 20 +- libnix/sources/nix/stdio/clearerr.c | 2 +- libnix/sources/nix/stdio/fdopen.c | 32 ++ libnix/sources/nix/stdio/feof.c | 4 +- libnix/sources/nix/stdio/ferror.c | 4 +- libnix/sources/nix/stdio/fflush.c | 5 +- libnix/sources/nix/stdio/fgets.c | 11 +- libnix/sources/nix/stdio/fileno.c | 4 +- libnix/sources/nix/stdio/fopen.c | 45 +- libnix/sources/nix/stdio/fread.c | 2 +- libnix/sources/nix/stdio/freopen.c | 98 ++-- libnix/sources/nix/stdio/fseek.c | 12 +- libnix/sources/nix/stdio/fsetpos.c | 3 +- libnix/sources/nix/stdio/ftell.c | 11 +- libnix/sources/nix/stdio/fwrite.c | 2 +- libnix/sources/nix/stdio/gets.c | 11 +- libnix/sources/nix/stdio/open.c | 305 +++++++---- libnix/sources/nix/stdio/remove.c | 6 +- libnix/sources/nix/stdio/rename.c | 25 +- libnix/sources/nix/stdio/setbuf.c | 2 +- libnix/sources/nix/stdio/setvbuf.c | 30 +- libnix/sources/nix/stdio/snprintf.c | 11 + libnix/sources/nix/stdio/ungetc.c | 10 +- libnix/sources/nix/stdio/vfprintf.c | 30 +- libnix/sources/nix/stdio/vsnprintf.c | 19 + libnix/sources/nix/stdio/vsprintf.c | 5 +- libnix/sources/nix/stdio/vsscanf.c | 7 +- libnix/sources/nix/stdlib/atexit.c | 2 +- libnix/sources/nix/stdlib/calloc.c | 13 +- libnix/sources/nix/stdlib/free.c | 33 +- libnix/sources/nix/stdlib/malloc.c | 11 +- libnix/sources/nix/stdlib/qsort.c | 7 +- libnix/sources/nix/stdlib/realloc.c | 4 +- libnix/sources/nix/stdlib/system.c | 11 +- libnix/sources/nix/string/memset.c | 25 +- libnix/sources/nix/string/strchr.c | 2 +- libnix/sources/nix/string/strrchr.c | 2 +- libnix/sources/nix/time/clock.c | 17 +- libnix/sources/nix/time/mktime.c | 9 +- libnix/sources/nix/time/strftime.c | 4 +- libnix/sources/nix13/Makefile.in | 13 +- libnix/sources/nix13/extra/stricmp.c | 2 +- libnix/sources/nix13/extra/strnicmp.c | 2 +- libnix/sources/nix_main/Makefile.in | 11 +- libnix/sources/nix_main/__nocommandline.c | 6 +- libnix/sources/nix_main/_main.c | 2 +- libnix/sources/nixmain/Makefile.in | 11 +- libnix/sources/nixmain/__nocommandline.c | 2 +- libnix/sources/socket/Makefile.in | 74 +++ libnix/sources/socket/arpa/inet_aton.c | 149 ++++++ libnix/sources/socket/arpa/inet_lnaof.c | 57 ++ libnix/sources/socket/arpa/inet_makeaddr.c | 60 +++ libnix/sources/socket/arpa/inet_netof.c | 56 ++ libnix/sources/socket/arpa/inet_network.c | 89 ++++ libnix/sources/socket/arpa/inet_ntoa.c | 51 ++ libnix/sources/socket/extra/dup.c | 16 + libnix/sources/socket/extra/fdtofh.c | 1 + libnix/sources/socket/extra/fstat.c | 14 + libnix/sources/socket/extra/strsep.c | 35 ++ libnix/sources/socket/ft.c | 12 + libnix/sources/socket/netdb/gethostbyaddr.c | 18 + libnix/sources/socket/netdb/gethostbyname.c | 18 + libnix/sources/socket/netdb/gethostent.c | 32 ++ libnix/sources/socket/netdb/getnetbyaddr.c | 18 + libnix/sources/socket/netdb/getnetbyname.c | 18 + libnix/sources/socket/netdb/getnetent.c | 125 +++++ libnix/sources/socket/netdb/getprotobyname.c | 18 + .../sources/socket/netdb/getprotobynumber.c | 18 + libnix/sources/socket/netdb/getprotoent.c | 123 +++++ libnix/sources/socket/netdb/getservbyname.c | 18 + libnix/sources/socket/netdb/getservbyport.c | 18 + libnix/sources/socket/netdb/getservent.c | 126 +++++ libnix/sources/socket/netdb/herrno.c | 2 + libnix/sources/socket/netdb/herror.c | 36 ++ libnix/sources/socket/socket/__initsock.c | 480 +++++++++++++++++ libnix/sources/socket/socket/accept.c | 39 ++ libnix/sources/socket/socket/bind.c | 32 ++ libnix/sources/socket/socket/connect.c | 29 + libnix/sources/socket/socket/getpeername.c | 26 + libnix/sources/socket/socket/getsockname.c | 26 + libnix/sources/socket/socket/getsockopt.c | 26 + libnix/sources/socket/socket/ioctl.c | 85 +++ libnix/sources/socket/socket/listen.c | 29 + libnix/sources/socket/socket/obtain_socket.c | 22 + libnix/sources/socket/socket/recfrom.c | 26 + libnix/sources/socket/socket/recv.c | 26 + libnix/sources/socket/socket/recvmsg.c | 26 + libnix/sources/socket/socket/release_socket.c | 33 ++ libnix/sources/socket/socket/send.c | 26 + libnix/sources/socket/socket/sendmsg.c | 26 + libnix/sources/socket/socket/sendto.c | 29 + libnix/sources/socket/socket/setsockopt.c | 26 + libnix/sources/socket/socket/shutdown.c | 26 + libnix/sources/socket/socket/socket.c | 39 ++ libnix/sources/socket/socket/socketpair.c | 8 + libnix/sources/socket/stdio/open.c | 497 ++++++++++++++++++ libnix/sources/socket/unistd/__inituser.c | 237 +++++++++ libnix/sources/socket/unistd/crypt.c | 11 + libnix/sources/socket/unistd/getdomainname.c | 27 + libnix/sources/socket/unistd/getgrent.c | 228 ++++++++ libnix/sources/socket/unistd/gethostid.c | 23 + libnix/sources/socket/unistd/gethostname.c | 44 ++ libnix/sources/socket/unistd/getpwent.c | 323 ++++++++++++ libnix/sources/socket/unistd/select.c | 280 ++++++++++ libnix/sources/stack/Makefile.in | 13 +- libnix/sources/stack/init_stk.c | 4 +- libnix/sources/stack/link_a5_0_f.c | 2 +- libnix/sources/stack/link_a5_d0_f.c | 2 +- libnix/sources/stack/stkchk_d0.c | 2 +- libnix/sources/stack/stkext.c | 4 +- libnix/sources/stack/stkovf.c | 2 +- libnix/sources/stack/stkrst.c | 2 +- libnix/sources/stack/stkrst_f.c | 2 +- libnix/sources/stack/sub_d0_sp.c | 4 +- libnix/sources/startup/Makefile.in | 9 +- libnix/sources/startup/devinit.c | 414 +++++++-------- libnix/sources/startup/libinit.c | 10 +- libnix/sources/startup/libinitr.c | 16 +- libnix/sources/stubs/Makefile.in | 11 +- libnix/sources/stubs/libbases/.keepme | 0 libnix/sources/stubs/libnames/.keepme | 0 libnix/sources/stubs/misc/__DOSBase.c | 2 +- .../stubs/misc/__MathIeeeDoubBasBase.c | 2 +- .../stubs/misc/__MathIeeeDoubTransBase.c | 2 +- .../stubs/misc/__MathIeeeSingBasBase.c | 2 +- .../stubs/misc/__MathIeeeSingTransBase.c | 2 +- libnix/sources/stubs/misc/__UtilityBase.c | 2 +- libnix/sources/stubs/misc/__cpucheck.c | 4 +- libnix/sources/stubs/misc/__initlibraries.c | 6 +- 213 files changed, 6541 insertions(+), 1350 deletions(-) create mode 100644 libnix/README.BETA create mode 100644 libnix/install-sh create mode 100644 libnix/sources/amiga/misc/DoPktn.c create mode 100644 libnix/sources/headers/inline/amitcp.h create mode 100644 libnix/sources/headers/inline/as225.h create mode 100644 libnix/sources/headers/inline/usergroup.h create mode 100644 libnix/sources/headers/select.h create mode 100644 libnix/sources/headers/socket.h create mode 100644 libnix/sources/nix/extra/gettimeofday.c create mode 100644 libnix/sources/nix/stdio/fdopen.c create mode 100644 libnix/sources/nix/stdio/snprintf.c create mode 100644 libnix/sources/nix/stdio/vsnprintf.c create mode 100644 libnix/sources/socket/Makefile.in create mode 100644 libnix/sources/socket/arpa/inet_aton.c create mode 100644 libnix/sources/socket/arpa/inet_lnaof.c create mode 100644 libnix/sources/socket/arpa/inet_makeaddr.c create mode 100644 libnix/sources/socket/arpa/inet_netof.c create mode 100644 libnix/sources/socket/arpa/inet_network.c create mode 100644 libnix/sources/socket/arpa/inet_ntoa.c create mode 100644 libnix/sources/socket/extra/dup.c create mode 100644 libnix/sources/socket/extra/fdtofh.c create mode 100644 libnix/sources/socket/extra/fstat.c create mode 100644 libnix/sources/socket/extra/strsep.c create mode 100644 libnix/sources/socket/ft.c create mode 100644 libnix/sources/socket/netdb/gethostbyaddr.c create mode 100644 libnix/sources/socket/netdb/gethostbyname.c create mode 100644 libnix/sources/socket/netdb/gethostent.c create mode 100644 libnix/sources/socket/netdb/getnetbyaddr.c create mode 100644 libnix/sources/socket/netdb/getnetbyname.c create mode 100644 libnix/sources/socket/netdb/getnetent.c create mode 100644 libnix/sources/socket/netdb/getprotobyname.c create mode 100644 libnix/sources/socket/netdb/getprotobynumber.c create mode 100644 libnix/sources/socket/netdb/getprotoent.c create mode 100644 libnix/sources/socket/netdb/getservbyname.c create mode 100644 libnix/sources/socket/netdb/getservbyport.c create mode 100644 libnix/sources/socket/netdb/getservent.c create mode 100644 libnix/sources/socket/netdb/herrno.c create mode 100644 libnix/sources/socket/netdb/herror.c create mode 100644 libnix/sources/socket/socket/__initsock.c create mode 100644 libnix/sources/socket/socket/accept.c create mode 100644 libnix/sources/socket/socket/bind.c create mode 100644 libnix/sources/socket/socket/connect.c create mode 100644 libnix/sources/socket/socket/getpeername.c create mode 100644 libnix/sources/socket/socket/getsockname.c create mode 100644 libnix/sources/socket/socket/getsockopt.c create mode 100644 libnix/sources/socket/socket/ioctl.c create mode 100644 libnix/sources/socket/socket/listen.c create mode 100644 libnix/sources/socket/socket/obtain_socket.c create mode 100644 libnix/sources/socket/socket/recfrom.c create mode 100644 libnix/sources/socket/socket/recv.c create mode 100644 libnix/sources/socket/socket/recvmsg.c create mode 100644 libnix/sources/socket/socket/release_socket.c create mode 100644 libnix/sources/socket/socket/send.c create mode 100644 libnix/sources/socket/socket/sendmsg.c create mode 100644 libnix/sources/socket/socket/sendto.c create mode 100644 libnix/sources/socket/socket/setsockopt.c create mode 100644 libnix/sources/socket/socket/shutdown.c create mode 100644 libnix/sources/socket/socket/socket.c create mode 100644 libnix/sources/socket/socket/socketpair.c create mode 100644 libnix/sources/socket/stdio/open.c create mode 100644 libnix/sources/socket/unistd/__inituser.c create mode 100644 libnix/sources/socket/unistd/crypt.c create mode 100644 libnix/sources/socket/unistd/getdomainname.c create mode 100644 libnix/sources/socket/unistd/getgrent.c create mode 100644 libnix/sources/socket/unistd/gethostid.c create mode 100644 libnix/sources/socket/unistd/gethostname.c create mode 100644 libnix/sources/socket/unistd/getpwent.c create mode 100644 libnix/sources/socket/unistd/select.c create mode 100644 libnix/sources/stubs/libbases/.keepme create mode 100644 libnix/sources/stubs/libnames/.keepme diff --git a/libnix/Makefile.in b/libnix/Makefile.in index 7fe84ba..9918cc7 100644 --- a/libnix/Makefile.in +++ b/libnix/Makefile.in @@ -29,36 +29,31 @@ INSTALL = @INSTALL@ INSTALL_PROGRAM = @INSTALL_PROGRAM@ INSTALL_DATA = @INSTALL_DATA@ -CC = @CC@ -CPP = @CPP@ -AS = as - -RANLIB = @RANLIB@ - #### End system configuration section #### -V=VER: libnix 1.2 (14.7.98) +V=VER: libnix 2.0 BETA (12.4.2000) CURDIR := $(shell pwd) -MAKE=make -f $(CURDIR)/sources/Makefile +MAK2=$(MAKE) -f $(CURDIR)/sources/Makefile -SUBDIRS=startup lib libb lib020 libb020 lib881 libb881#lib060 libb060 libb32 libb32881 +SUBDIRS=startup lib libb lib020 libb020 lib881 libb881#lib060 libb060 libb32 libb32881 libb32060 all: libnix.guide libnix.info $(SUBDIRS) - cd sources; make filelists - cd startup; make -f $(CURDIR)/sources/startup/Makefile V="$(V)" - cd lib; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer" - cd libb; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA" - cd lib020; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68020" - cd libb020; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68020" - cd lib881; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68020 -m68881" - cd libb881; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68020 -m68881" -# cd lib060; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68060 -m68881" -# cd libb060; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68060 -m68881" -# cd libb32; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel32 -DSMALL_DATA -m68020" -# cd libb32881; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel32 -DSMALL_DATA -m68020 -m68881" -# cd libix; $(MAKE) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -DIXPATHS" + cd sources; $(MAKE) filelists + cd startup; $(MAKE) -f $(CURDIR)/sources/startup/Makefile V="$(V)" + cd lib; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer" + cd libb; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA" + cd lib020; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68020" + cd libb020; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68020" + cd lib881; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68020 -m68881" + cd libb881; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68020 -m68881" +# cd lib060; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -m68060 -m68881" +# cd libb060; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel -DSMALL_DATA -m68060 -m68881" +# cd libb32; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel32 -DSMALL_DATA -m68020" +# cd libb32881; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel32 -DSMALL_DATA -m68020 -m68881" +# cd libb32060; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -fbaserel32 -DSMALL_DATA -m68060 -m68881" +# cd libix; $(MAK2) V="$(V)" CFLAGS="-Wall -O3 -fomit-frame-pointer -DIXPATHS" $(SUBDIRS): mkdir $@ @@ -67,37 +62,39 @@ libamiga: if [ ! -d lib ] ; then mkdir lib ; else true ; fi if [ ! -d libb ] ; then mkdir libb ; else true ; fi if [ ! -d libb32 ] ; then mkdir libb32 ; else true ; fi - cd sources; make filelists - cd lib; $(MAKE) libamiga CFLAGS="-O3 -fomit-frame-pointer" - cd libb; $(MAKE) libamiga CFLAGS="-O3 -fomit-frame-pointer -fbaserel" - cd libb32; $(MAKE) libamiga CFLAGS="-O3 -fomit-frame-pointer -fbaserel32 -m68020" + cd sources; $(MAK2) filelists + cd lib; $(MAK2) libamiga CFLAGS="-O3 -fomit-frame-pointer" + cd libb; $(MAK2) libamiga CFLAGS="-O3 -fomit-frame-pointer -fbaserel" +# cd libb32; $(MAK2) libamiga CFLAGS="-O3 -fomit-frame-pointer -fbaserel32 -m68020" clean: - cd lib; $(MAKE) clean - cd libb; $(MAKE) clean - cd lib020; $(MAKE) clean - cd libb020; $(MAKE) clean - cd lib881; $(MAKE) clean - cd libb881; $(MAKE) clean -# cd lib060; $(MAKE) clean -# cd libb060; $(MAKE) clean -# cd lib32; $(MAKE) clean -# cd libb32881; $(MAKE) clean -# cd libix; $(MAKE) clean + cd lib; $(MAK2) clean + cd libb; $(MAK2) clean + cd lib020; $(MAK2) clean + cd libb020; $(MAK2) clean + cd lib881; $(MAK2) clean + cd libb881; $(MAK2) clean +# cd lib060; $(MAK2) clean +# cd libb060; $(MAK2) clean +# cd lib32; $(MAK2) clean +# cd libb32881; $(MAK2) clean +# cd libb32060; $(MAK2) clean +# cd libix; $(MAK2) clean -rm -f sources/*/filelist sources/stubs/libbases/* sources/stubs/libnames/* veryclean: - cd lib; $(MAKE) veryclean - cd libb; $(MAKE) veryclean - cd lib020; $(MAKE) veryclean - cd libb020; $(MAKE) veryclean - cd lib881; $(MAKE) veryclean - cd libb881; $(MAKE) veryclean -# cd lib060; $(MAKE) veryclean -# cd libb060; $(MAKE) veryclean -# cd lib32; $(MAKE) veryclean -# cd libb32881; $(MAKE) veryclean -# cd libix; $(MAKE) veryclean + cd lib; $(MAK2) veryclean + cd libb; $(MAK2) veryclean + cd lib020; $(MAK2) veryclean + cd libb020; $(MAK2) veryclean + cd lib881; $(MAK2) veryclean + cd libb881; $(MAK2) veryclean +# cd lib060; $(MAK2) veryclean +# cd libb060; $(MAK2) veryclean +# cd lib32; $(MAK2) veryclean +# cd libb32881; $(MAK2) veryclean +# cd libb32060; $(MAK2) veryclean +# cd libix; $(MAK2) veryclean -rm sources/*/filelist libnix.guide: libnix.texi @@ -120,16 +117,18 @@ install: installdirs $(INSTALL) lib881/misc/*.o $(prefix)/lib/libm020/libm881/libnix $(INSTALL) libb881/*/lib*.a $(prefix)/lib/libb/libm020/libm881/libnix $(INSTALL) libb881/misc/*.o $(prefix)/lib/libb/libm020/libm881/libnix - $(INSTALL_DATA) *.info* $(infodir) - $(INSTALL_DATA) libnix.guide $(guidedir)/libnix.guide # $(INSTALL) lib060/*/lib*.a $(prefix)/lib/libm060/libnix # $(INSTALL) lib060/misc/*.o $(prefix)/lib/libm060/libnix # $(INSTALL) libb060/*/lib*.a $(prefix)/lib/libb/libm060/libnix # $(INSTALL) libb060/misc/*.o $(prefix)/lib/libb/libm060/libnix -# $(INSTALL) libb32/*/lib*.a $(prefix)/lib/libb32/libm020/libnix -# $(INSTALL) libb32/misc/*.o $(prefix)/lib/libb32/libm020/libnix -# $(INSTALL) libb32881/*/lib*.a $(prefix)/lib/libb32/libm020/libm881/libnix -# $(INSTALL) libb32881/misc/*.o $(prefix)/lib/libb32/libm020/libm881/libnix +# $(INSTALL) libb32/*/lib*.a $(prefix)/lib/libb32/libm020/libnix +# $(INSTALL) libb32/misc/*.o $(prefix)/lib/libb32/libm020/libnix +# $(INSTALL) libb32881/*/lib*.a $(prefix)/lib/libb32/libm020/libm881/libnix +# $(INSTALL) libb32881/misc/*.o $(prefix)/lib/libb32/libm020/libm881/libnix +# $(INSTALL) libb32060/*/lib*.a $(prefix)/lib/libb32/libm060/libnix +# $(INSTALL) libb32060/misc/*.o $(prefix)/lib/libb32/libm060/libnix + $(INSTALL_DATA) *.info* $(infodir) + $(INSTALL_DATA) libnix.guide $(guidedir)/libnix.guide installdirs: mkinstalldirs $(srcdir)/mkinstalldirs \ @@ -151,12 +150,14 @@ installdirs: mkinstalldirs # $(libdir)/libm060/libnix \ # $(libdir)/libb/libm060 \ # $(libdir)/libb/libm060/libnix -# $(libdir)/libb32 \ -# $(libdir)/libb32/libnix \ -# $(libdir)/libb32/libm020 \ -# $(libdir)/libb32/libm020/libnix \ -# $(libdir)/libb32/libm020/libm881 \ -# $(libdir)/libb32/libm020/libm881/libnix +# $(libdir)/libb32 \ +# $(libdir)/libb32/libnix \ +# $(libdir)/libb32/libm020 \ +# $(libdir)/libb32/libm020/libnix \ +# $(libdir)/libb32/libm020/libm881 \ +# $(libdir)/libb32/libm020/libm881/libnix \ +# $(libdir)/libb32/libm060 \ +# $(libdir)/libb32/libm060/libnix distribution: mkdir t:gg t:gg/lib t:gg/lib/libnix @@ -180,6 +181,16 @@ distribution: cp -p lib881/misc/*.o t:gg/lib/libm020/libm881/libnix cp -p libb881/*/*.a t:gg/lib/libb/libm020/libm881/libnix cp -p libb881/misc/*.o t:gg/lib/libb/libm020/libm881/libnix +# cp -p lib060/*/*.a t:gg/lib/libm060/libnix +# cp -p lib060/misc/*.o t:gg/lib/libm060/libnix +# cp -p libb060/*/*.a t:gg/lib/libm060/libnix +# cp -p libb060/misc/*.o t:gg/lib/libm060/libnix +# cp -p libb32/*/*.a t:gg/lib/libm020/libnix +# cp -p libb32/misc/*.o t:gg/lib/libm020/libnix +# cp -p libb32881/*/*.a t:gg/lib/libm020/libm881/libnix +# cp -p libb32881/misc/*.o t:gg/lib/libm020/libm881/libnix +# cp -p libb32060/*/*.a t:gg/lib/libm060/libnix +# cp -p libb32060/misc/*.o t:gg/lib/libm060/libnix -rm t:gg/lib/libnix/libglue.a t:gg/lib/libb/libnix/libglue.a -cp * t:gg rm t:gg/Makefile t:gg/libnix.texi diff --git a/libnix/README.BETA b/libnix/README.BETA new file mode 100644 index 0000000..8c96a4f --- /dev/null +++ b/libnix/README.BETA @@ -0,0 +1,31 @@ +This is BETA 2 of libnix and its considered final. Changes compared with +the previous BETA are completed append mode (now works for fdopen()), +stderr behavoir according to the standard (always unbuffered; previosly +it had the normal fopen() mode) since write-only streams are now optimized +(as in *BSD ;-). The internal socket i/o interface was changed for better +system compatibility (used a packet in private memory, now its DOS alloced) +The only change that I consider is a makefile change: changing the +optimization level from -O3 to -O2 or -Os. + +---old--- + +This libnix version is BETA!!! The final version will certainly contain +changes compared to this snapshot. +Its intended for those who are interested and are able to recompile the +libraries. This packaged can be compiled under a cross compiler environment. +The configure script MUST be invoked through an absolute pathname! If you +configure it with a relative pathname you have to modify VPATH and srcdir +in startup/Makefile (remove the first ../). + +libnix 2.0 finally offers support for networking. The network support is +in a new link library called libsocket.a. This code is based on work by +Jeff Sheperd. For a more changes consult sources/history. The list is +probably no complete. + +Send comments and bugreports to: + + gnikl@informatik.uni-rostock.de + +with a subject including "libnix BETA". + +Flames to dev/null :-) diff --git a/libnix/configure b/libnix/configure index 4f4379d..e9a945b 100755 --- a/libnix/configure +++ b/libnix/configure @@ -1,7 +1,7 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 2.13 +# Generated automatically using autoconf version 2.12.1 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc. # # This configure script is free software; the Free Software Foundation @@ -357,7 +357,7 @@ EOF verbose=yes ;; -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 2.13" + echo "configure generated by autoconf version 2.12.1" exit 0 ;; -with-* | --with-*) @@ -527,11 +527,9 @@ ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross -ac_exeext= -ac_objext=o if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then @@ -549,16 +547,15 @@ fi # Extract the first word of "gcc", so it can be a program name with args. set dummy gcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:553: checking for $ac_word" >&5 +echo "configure:551: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="gcc" @@ -579,16 +576,15 @@ if test -z "$CC"; then # Extract the first word of "bcc", so it can be a program name with args. set dummy bcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:583: checking for $ac_word" >&5 +echo "configure:580: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="bcc" @@ -607,50 +603,18 @@ fi fi if test -z "$CC"; then - machine=`(uname -m 2>/dev/null)` || machine=unknown - case "$machine" in - BePC) # Extract the first word of "mwccx86", so it can be a program name with args. -set dummy mwccx86; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:616: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="mwccx86" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CC="$ac_cv_prog_CC" -if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - ;; - BeBox | BeMac ) # Extract the first word of "mwcc", so it can be a program name with args. + # Extract the first word of "mwcc", so it can be a program name with args. set dummy mwcc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:645: checking for $ac_word" >&5 +echo "configure:610: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_CC="mwcc" @@ -666,25 +630,22 @@ if test -n "$CC"; then else echo "$ac_t""no" 1>&6 fi - ;; - *) ;; - esac + fi if test -z "$CC"; then # Extract the first word of "cc", so it can be a program name with args. set dummy cc; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:678: checking for $ac_word" >&5 +echo "configure:640: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$CC"; then ac_cv_prog_CC="$CC" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" ac_prog_rejected=no - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then if test "$ac_dir/$ac_word" = "/usr/ucb/cc"; then @@ -719,61 +680,25 @@ else echo "$ac_t""no" 1>&6 fi -fi -if test -z "$CC"; then - case "`uname -s`" in - *win32* | *WIN32*) - # Extract the first word of "cl", so it can be a program name with args. -set dummy cl; ac_word=$2 -echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:730: checking for $ac_word" >&5 -if eval "test \"`echo '$''{'ac_cv_prog_CC'+set}'`\" = set"; then - echo $ac_n "(cached) $ac_c" 1>&6 -else - if test -n "$CC"; then - ac_cv_prog_CC="$CC" # Let the user override the test. -else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do - test -z "$ac_dir" && ac_dir=. - if test -f $ac_dir/$ac_word; then - ac_cv_prog_CC="cl" - break - fi - done - IFS="$ac_save_ifs" -fi -fi -CC="$ac_cv_prog_CC" -if test -n "$CC"; then - echo "$ac_t""$CC" 1>&6 -else - echo "$ac_t""no" 1>&6 -fi - ;; - esac fi test -z "$CC" && { echo "configure: error: no acceptable cc found in \$PATH" 1>&2; exit 1; } echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works""... $ac_c" 1>&6 -echo "configure:761: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 +echo "configure:688: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) works" >&5 ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. ac_cpp='$CPP $CPPFLAGS' ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' +ac_link='${CC-cc} -o conftest $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' cross_compiling=$ac_cv_prog_cc_cross -cat > conftest.$ac_ext << EOF - -#line 772 "configure" +cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:702: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest; then ac_cv_prog_cc_works=yes # If we can't run a trivial program, we are probably using a cross compiler. if (./conftest; exit) 2>/dev/null; then @@ -787,24 +712,18 @@ else ac_cv_prog_cc_works=no fi rm -fr conftest* -ac_ext=c -# CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='$CPP $CPPFLAGS' -ac_compile='${CC-cc} -c $CFLAGS $CPPFLAGS conftest.$ac_ext 1>&5' -ac_link='${CC-cc} -o conftest${ac_exeext} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $LIBS 1>&5' -cross_compiling=$ac_cv_prog_cc_cross echo "$ac_t""$ac_cv_prog_cc_works" 1>&6 if test $ac_cv_prog_cc_works = no; then { echo "configure: error: installation or configuration problem: C compiler cannot create executables." 1>&2; exit 1; } fi echo $ac_n "checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler""... $ac_c" 1>&6 -echo "configure:803: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 +echo "configure:722: checking whether the C compiler ($CC $CFLAGS $LDFLAGS) is a cross-compiler" >&5 echo "$ac_t""$ac_cv_prog_cc_cross" 1>&6 cross_compiling=$ac_cv_prog_cc_cross echo $ac_n "checking whether we are using GNU C""... $ac_c" 1>&6 -echo "configure:808: checking whether we are using GNU C" >&5 +echo "configure:727: checking whether we are using GNU C" >&5 if eval "test \"`echo '$''{'ac_cv_prog_gcc'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -813,7 +732,7 @@ else yes; #endif EOF -if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:817: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then +if { ac_try='${CC-cc} -E conftest.c'; { (eval echo configure:736: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; }; } | egrep yes >/dev/null 2>&1; then ac_cv_prog_gcc=yes else ac_cv_prog_gcc=no @@ -824,15 +743,11 @@ echo "$ac_t""$ac_cv_prog_gcc" 1>&6 if test $ac_cv_prog_gcc = yes; then GCC=yes -else - GCC= -fi - -ac_test_CFLAGS="${CFLAGS+set}" -ac_save_CFLAGS="$CFLAGS" -CFLAGS= -echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 -echo "configure:836: checking whether ${CC-cc} accepts -g" >&5 + ac_test_CFLAGS="${CFLAGS+set}" + ac_save_CFLAGS="$CFLAGS" + CFLAGS= + echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&6 +echo "configure:751: checking whether ${CC-cc} accepts -g" >&5 if eval "test \"`echo '$''{'ac_cv_prog_cc_g'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else @@ -847,47 +762,28 @@ rm -f conftest* fi echo "$ac_t""$ac_cv_prog_cc_g" 1>&6 -if test "$ac_test_CFLAGS" = set; then - CFLAGS="$ac_save_CFLAGS" -elif test $ac_cv_prog_cc_g = yes; then - if test "$GCC" = yes; then + if test "$ac_test_CFLAGS" = set; then + CFLAGS="$ac_save_CFLAGS" + elif test $ac_cv_prog_cc_g = yes; then CFLAGS="-g -O2" else - CFLAGS="-g" + CFLAGS="-O2" fi else - if test "$GCC" = yes; then - CFLAGS="-O2" - else - CFLAGS= - fi + GCC= + test "${CFLAGS+set}" = set || CFLAGS="-g" +fi +if test "$CC" = "mwcc"; then + CC="mwcc -I- -I. -I/boot/apps/GeekGadgets/include -L/boot/apps/GeekGadgets/lib -opt global -nodup" + AR="mwld" + RANLIB="true" +elif test "$CC" = "bcc"; then + AR="mwld" + RANLIB="true" fi -case "$CC" in - bcc ) - AR=${AR-mwld} - LD=${LD-mwld} - RANLIB=${RANLIB-true};; - mwcc ) - CC="mwcc -I- -I. -I/boot/apps/GeekGadgets/include -L/boot/apps/GeekGadgets/lib -opt global -nodup" - AR=${AR-mwld} - LD=${LD-mwld} - RANLIB=${RANLIB-true};; - mwccx86 ) - CC="mwccx86 -I- -I. -I/boot/apps/GeekGadgets/include -L/boot/apps/GeekGadgets/lib" - AR=${AR-mwldx86} - LD=${LD-mwldx86} - RANLIB=${RANLIB-true};; - ${host_alias}-gcc) - ;; - *) - AR=${AR-ar} - LD=${LD-ld} - RANLIB=${RANLIB-ranlib};; -esac - echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&6 -echo "configure:891: checking how to run the C preprocessor" >&5 +echo "configure:787: checking how to run the C preprocessor" >&5 # On Suns, sometimes $CPP names a directory. if test -n "$CPP" && test -d "$CPP"; then CPP= @@ -902,14 +798,14 @@ else # On the NeXT, cc -E runs the code through the compiler's parser, # not just through cpp. cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:912: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +{ (eval echo configure:808: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else @@ -919,31 +815,14 @@ else rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" cat > conftest.$ac_ext < Syntax Error EOF ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:929: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` -if test -z "$ac_err"; then - : -else - echo "$ac_err" >&5 - echo "configure: failed program was:" >&5 - cat conftest.$ac_ext >&5 - rm -rf conftest* - CPP="${CC-cc} -nologo -E" - cat > conftest.$ac_ext < -Syntax Error -EOF -ac_try="$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" -{ (eval echo configure:946: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } -ac_err=`grep -v '^ *+' conftest.out | grep -v "^conftest.${ac_ext}\$"` +{ (eval echo configure:825: \"$ac_try\") 1>&5; (eval $ac_try) 2>&5; } +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else @@ -955,8 +834,6 @@ else fi rm -f conftest* fi -rm -f conftest* -fi rm -f conftest* ac_cv_prog_CPP="$CPP" fi @@ -971,16 +848,15 @@ do # Extract the first word of "$ac_prog", so it can be a program name with args. set dummy $ac_prog; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:975: checking for $ac_word" >&5 +echo "configure:852: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_AWK'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$AWK"; then ac_cv_prog_AWK="$AWK" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_AWK="$ac_prog" @@ -1003,16 +879,15 @@ done # Extract the first word of "ranlib", so it can be a program name with args. set dummy ranlib; ac_word=$2 echo $ac_n "checking for $ac_word""... $ac_c" 1>&6 -echo "configure:1007: checking for $ac_word" >&5 +echo "configure:883: checking for $ac_word" >&5 if eval "test \"`echo '$''{'ac_cv_prog_RANLIB'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else if test -n "$RANLIB"; then ac_cv_prog_RANLIB="$RANLIB" # Let the user override the test. else - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS=":" - ac_dummy="$PATH" - for ac_dir in $ac_dummy; do + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" + for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then ac_cv_prog_RANLIB="ranlib" @@ -1062,12 +937,12 @@ ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. # SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" # ./install, which can be erroneously created by make from ./install.sh. echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&6 -echo "configure:1066: checking for a BSD compatible install" >&5 +echo "configure:941: checking for a BSD compatible install" >&5 if test -z "$INSTALL"; then if eval "test \"`echo '$''{'ac_cv_path_install'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else - IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS=":" + IFS="${IFS= }"; ac_save_IFS="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do # Account for people who put trailing slashes in PATH elements. case "$ac_dir/" in @@ -1110,8 +985,6 @@ echo "$ac_t""$INSTALL" 1>&6 # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' -test -z "$INSTALL_SCRIPT" && INSTALL_SCRIPT='${INSTALL_PROGRAM}' - test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' @@ -1138,7 +1011,7 @@ EOF # Ultrix sh set writes to stderr and can't be redirected directly, # and sets the high bit in the cache file unless we assign to the vars. (set) 2>&1 | - case `(ac_space=' '; set | grep ac_space) 2>&1` in + case `(ac_space=' '; set) 2>&1 | grep ac_space` in *ac_space=\ *) # `set' does not quote correctly, so add quotes (double-quote substitution # turns \\\\ into \\, and sed turns \\ into \). @@ -1178,7 +1051,6 @@ fi trap 'rm -f $CONFIG_STATUS conftest*; exit 1' 1 2 15 - # Transform confdefs.h into DEFS. # Protect against shell expansion while executing Makefile rules. # Protect against Makefile macro expansion. @@ -1220,7 +1092,7 @@ do echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "$CONFIG_STATUS generated by autoconf version 2.13" + echo "$CONFIG_STATUS generated by autoconf version 2.12.1" exit 0 ;; -help | --help | --hel | --he | --h) echo "\$ac_cs_usage"; exit 0 ;; @@ -1249,7 +1121,6 @@ s%@SHELL@%$SHELL%g s%@CFLAGS@%$CFLAGS%g s%@CPPFLAGS@%$CPPFLAGS%g s%@CXXFLAGS@%$CXXFLAGS%g -s%@FFLAGS@%$FFLAGS%g s%@DEFS@%$DEFS%g s%@LDFLAGS@%$LDFLAGS%g s%@LIBS@%$LIBS%g @@ -1274,11 +1145,10 @@ s%@dvidir@%$dvidir%g s%@mandir@%$mandir%g s%@CC@%$CC%g s%@AR@%$AR%g -s%@RANLIB@%$RANLIB%g s%@CPP@%$CPP%g s%@AWK@%$AWK%g +s%@RANLIB@%$RANLIB%g s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_SCRIPT@%$INSTALL_SCRIPT%g s%@INSTALL_DATA@%$INSTALL_DATA%g CEOF @@ -1321,12 +1191,20 @@ EOF cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then diff --git a/libnix/configure.in b/libnix/configure.in index a9bfbef..73c7f2a 100644 --- a/libnix/configure.in +++ b/libnix/configure.in @@ -8,9 +8,17 @@ AC_PROG_AWK AC_PROG_RANLIB AC_PROG_INSTALL -AC_OUTPUT(Makefile sources/Makefile sources/amiga/Makefile - sources/math/Makefile sources/misc/Makefile - sources/nix/Makefile sources/nix13/Makefile - sources/nixmain/Makefile sources/nix_main/Makefile - sources/stack/Makefile sources/startup/Makefile - sources/stubs/Makefile examples/Makefile) +AC_OUTPUT(Makefile + sources/Makefile + sources/amiga/Makefile + sources/math/Makefile + sources/misc/Makefile + sources/nix/Makefile + sources/nix13/Makefile + sources/nixmain/Makefile + sources/nix_main/Makefile + sources/socket/Makefile + sources/stack/Makefile + sources/startup/Makefile + sources/stubs/Makefile + examples/Makefile) diff --git a/libnix/examples/simpledev.c b/libnix/examples/simpledev.c index ac301b5..2af0b4b 100755 --- a/libnix/examples/simpledev.c +++ b/libnix/examples/simpledev.c @@ -4,9 +4,7 @@ /* */ /******************************************************************************/ -#include #include -#include #include #include "stabs.h" @@ -16,8 +14,8 @@ /* */ /******************************************************************************/ -const BYTE DevName[]="simple.device"; -const BYTE DevIdString[]="version 1.0"; +const char DevName[]="simple.device"; +const char DevIdString[]="version 1.0"; const UWORD DevVersion=1; const UWORD DevRevision=0; @@ -41,8 +39,8 @@ struct ExecBase *SysBase; int __UserDevInit(struct Device *myDev) { - /* required !!! */ - SysBase=*(struct ExecBase **)4; + /* !!! required !!! */ + SysBase = *(struct ExecBase **)4L; /* setup your device base - to access device functions over *this* basePtr! */ @@ -65,7 +63,7 @@ int __UserDevInit(struct Device *myDev) /* */ /******************************************************************************/ -void __UserDevCleanup() +void __UserDevCleanup(void) { /* your cleanup comes here */ @@ -84,7 +82,7 @@ void __UserDevCleanup() int __UserDevOpen(struct IORequest *iorq,ULONG unit,ULONG flags) { - int io_err=IOERR_OPENFAIL; + int io_err = IOERR_OPENFAIL; /* return a bool to indicate success */ @@ -101,7 +99,6 @@ int __UserDevOpen(struct IORequest *iorq,ULONG unit,ULONG flags) void __UserDevClose(struct IORequest *iorq) { - /* nothing to return */ } diff --git a/libnix/examples/simplelib.c b/libnix/examples/simplelib.c index 82decd7..f11c603 100755 --- a/libnix/examples/simplelib.c +++ b/libnix/examples/simplelib.c @@ -4,8 +4,6 @@ /* */ /******************************************************************************/ -#include -#include #include #include #include "stabs.h" @@ -16,8 +14,8 @@ /* */ /******************************************************************************/ -const BYTE LibName[]="simple.library"; -const BYTE LibIdString[]="version 1.0"; +const char LibName[]="simple.library"; +const char LibIdString[]="version 1.0"; const UWORD LibVersion=1; const UWORD LibRevision=0; @@ -46,10 +44,10 @@ int __UserLibInit(struct Library *myLib) myLibPtr = myLib; - /* required !!! */ - SysBase=*(struct ExecBase **)4; + /* !!! required !!! */ + SysBase = *(struct ExecBase **)4L; - return (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",33))==NULL; + return (DOSBase=(struct DosLibrary *)OpenLibrary("dos.library",33L))==NULL; } /******************************************************************************/ @@ -60,9 +58,9 @@ int __UserLibInit(struct Library *myLib) /* */ /******************************************************************************/ -void __UserLibCleanup() +void __UserLibCleanup(void) { - CloseLibrary((struct Library *)DOSBase); + CloseLibrary(&DOSBase->dl_lib); } /******************************************************************************/ diff --git a/libnix/install-sh b/libnix/install-sh new file mode 100644 index 0000000..e9de238 --- /dev/null +++ b/libnix/install-sh @@ -0,0 +1,251 @@ +#!/bin/sh +# +# install - install a program, script, or datafile +# This comes from X11R5 (mit/util/scripts/install.sh). +# +# Copyright 1991 by the Massachusetts Institute of Technology +# +# Permission to use, copy, modify, distribute, and sell this software and its +# documentation for any purpose is hereby granted without fee, provided that +# the above copyright notice appear in all copies and that both that +# copyright notice and this permission notice appear in supporting +# documentation, and that the name of M.I.T. not be used in advertising or +# publicity pertaining to distribution of the software without specific, +# written prior permission. M.I.T. makes no representations about the +# suitability of this software for any purpose. It is provided "as is" +# without express or implied warranty. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +transformbasename="" +transform_arg="" +instcmd="$mvprog" +chmodcmd="$chmodprog 0755" +chowncmd="" +chgrpcmd="" +stripcmd="" +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src="" +dst="" +dir_arg="" + +while [ x"$1" != x ]; do + case $1 in + -c) instcmd="$cpprog" + shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + -s) stripcmd="$stripprog" + shift + continue;; + + -t=*) transformarg=`echo $1 | sed 's/-t=//'` + shift + continue;; + + -b=*) transformbasename=`echo $1 | sed 's/-b=//'` + shift + continue;; + + *) if [ x"$src" = x ] + then + src=$1 + else + # this colon is to work around a 386BSD /bin/sh bug + : + dst=$1 + fi + shift + continue;; + esac +done + +if [ x"$src" = x ] +then + echo "install: no input file specified" + exit 1 +else + true +fi + +if [ x"$dir_arg" != x ]; then + dst=$src + src="" + + if [ -d $dst ]; then + instcmd=: + chmodcmd="" + else + instcmd=mkdir + fi +else + +# Waiting for this to be detected by the "$instcmd $src $dsttmp" command +# might cause directories to be created, which would be especially bad +# if $src (and thus $dsttmp) contains '*'. + + if [ -f $src -o -d $src ] + then + true + else + echo "install: $src does not exist" + exit 1 + fi + + if [ x"$dst" = x ] + then + echo "install: no destination specified" + exit 1 + else + true + fi + +# If destination is a directory, append the input filename; if your system +# does not like double slashes in filenames, you may need to add some logic + + if [ -d $dst ] + then + dst="$dst"/`basename $src` + else + true + fi +fi + +## this sed command emulates the dirname command +dstdir=`echo $dst | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + +# Make sure that the destination directory exists. +# this part is taken from Noah Friedman's mkinstalldirs script + +# Skip lots of stat calls in the usual case. +if [ ! -d "$dstdir" ]; then +defaultIFS=' +' +IFS="${IFS-${defaultIFS}}" + +oIFS="${IFS}" +# Some sh's can't handle IFS=/ for some reason. +IFS='%' +set - `echo ${dstdir} | sed -e 's@/@%@g' -e 's@^%@/@'` +IFS="${oIFS}" + +pathcomp='' + +while [ $# -ne 0 ] ; do + pathcomp="${pathcomp}${1}" + shift + + if [ ! -d "${pathcomp}" ] ; + then + $mkdirprog "${pathcomp}" + else + true + fi + + pathcomp="${pathcomp}/" +done +fi + +if [ x"$dir_arg" != x ] +then + $doit $instcmd $dst && + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dst; else true ; fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dst; else true ; fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dst; else true ; fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dst; else true ; fi +else + +# If we're going to rename the final executable, determine the name now. + + if [ x"$transformarg" = x ] + then + dstfile=`basename $dst` + else + dstfile=`basename $dst $transformbasename | + sed $transformarg`$transformbasename + fi + +# don't allow the sed command to completely eliminate the filename + + if [ x"$dstfile" = x ] + then + dstfile=`basename $dst` + else + true + fi + +# Make a temp file name in the proper directory. + + dsttmp=$dstdir/#inst.$$# + +# Move or copy the file name to the temp name + + $doit $instcmd $src $dsttmp && + + trap "rm -f ${dsttmp}" 0 && + +# and set any options; do chmod last to preserve setuid bits + +# If any of these fail, we abort the whole thing. If we want to +# ignore errors from any of these, just make sure not to ignore +# errors from the above "$doit $instcmd $src $dsttmp" command. + + if [ x"$chowncmd" != x ]; then $doit $chowncmd $dsttmp; else true;fi && + if [ x"$chgrpcmd" != x ]; then $doit $chgrpcmd $dsttmp; else true;fi && + if [ x"$stripcmd" != x ]; then $doit $stripcmd $dsttmp; else true;fi && + if [ x"$chmodcmd" != x ]; then $doit $chmodcmd $dsttmp; else true;fi && + +# Now rename the file to the real destination. + + $doit $rmcmd -f $dstdir/$dstfile && + $doit $mvcmd $dsttmp $dstdir/$dstfile + +fi && + + +exit 0 diff --git a/libnix/sources/Makefile.in b/libnix/sources/Makefile.in index 734624c..37e01f9 100644 --- a/libnix/sources/Makefile.in +++ b/libnix/sources/Makefile.in @@ -18,24 +18,19 @@ srcdir = @srcdir@ VPATH = @srcdir@ -CC = @CC@ -CPP = @CPP@ -AS = as - -RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### CURDIR = $(shell pwd) -MAKELIST=make -f $(CURDIR)/Makefile +MAKELIST=$(MAKE) -f $(CURDIR)/Makefile -SUBDIRS=nixmain nix_main misc nix nix13 math stack stubs +SUBDIRS=nixmain nix_main misc math nix nix13 socket stack stubs all: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) for subdir in $(SUBDIRS); do \ - ( cd $$subdir;make -f ../../sources/$$subdir/Makefile V="$(V)" \ + ( cd $$subdir;$(MAKE) -f ../../sources/$$subdir/Makefile V="$(V)" \ CFLAGS="$(CFLAGS)" ); \ done @@ -44,19 +39,20 @@ $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)): libamiga: if [ ! -d amiga ] ; then mkdir amiga ; else true ; fi - cd amiga;make -f $(CURDIR)/../sources/amiga/Makefile CFLAGS="$(CFLAGS)" + cd amiga;$(MAKE) -f $(CURDIR)/../sources/amiga/Makefile CFLAGS="$(CFLAGS)" filelists: -cd $(srcdir)/math; $(MAKELIST) SOURCEFILES="*/*" FLDIR=$(CURDIR)/math $(CURDIR)/math/filelist - -cd $(srcdir)/stack; $(MAKELIST) SOURCEFILES="*.c" FLDIR=$(CURDIR)/stack $(CURDIR)/stack/filelist -cd $(srcdir)/nix; $(MAKELIST) SOURCEFILES="*/*" FLDIR=$(CURDIR)/nix $(CURDIR)/nix/filelist -cd $(srcdir)/nix13; $(MAKELIST) SOURCEFILES="*/*" FLDIR=$(CURDIR)/nix13 $(CURDIR)/nix13/filelist - -cd $(srcdir)/stubs; make -f $(CURDIR)/Makefile STUBDIR=$(CURDIR)/stubs libbases/dos.c; \ + -cd $(srcdir)/socket; $(MAKELIST) SOURCEFILES="*/*" FLDIR=$(CURDIR)/socket $(CURDIR)/socket/filelist + -cd $(srcdir)/stack; $(MAKELIST) SOURCEFILES="*.c" FLDIR=$(CURDIR)/stack $(CURDIR)/stack/filelist + -cd $(srcdir)/stubs; $(MAKE) -f $(CURDIR)/Makefile STUBDIR=$(CURDIR)/stubs libbases/dos.c; \ $(MAKELIST) SOURCEFILES=" \ libbases/* misc/__DOSBase.c misc/__UtilityBase.c \ misc/__MathIeeeSingBasBase.c misc/__MathIeeeDoubBasBase.c \ misc/__MathIeeeSingTransBase.c misc/__MathIeeeDoubTransBase.c \ - misc/__initlibraries.c misc/__flush_cache.c misc/__cpucheck.c \ + misc/__cpucheck.c misc/__flush_cache.c misc/__initlibraries.c \ libnames/* stubs/*" \ FLDIR=$(CURDIR)/stubs $(CURDIR)/stubs/filelist -cd $(srcdir)/amiga; $(MAKELIST) SOURCEFILES="*/*" FLDIR=$(CURDIR)/amiga $(CURDIR)/amiga/filelist @@ -85,14 +81,9 @@ libbases/dos.c: $(STUBDIR)/Makefile library.list print "char __" sname "name[]=\"" $$2 "\";" >fname;}' clean: - if [ -d nixmain ] ; then (cd nixmain; make -f ../../sources/nixmain/Makefile TARGET=clean clean) ; else true ; fi - if [ -d nix_main ] ; then (cd nix_main; make -f ../../sources/nix_main/Makefile TARGET=clean clean) ; else true ; fi - if [ -d misc ] ; then (cd misc; make -f ../../sources/misc/Makefile TARGET=clean clean) ; else true ; fi - if [ -d math ] ; then (cd math; make -f ../../sources/math/Makefile TARGET=clean clean) ; else true ; fi - if [ -d stack ] ; then (cd stack; make -f ../../sources/stack/Makefile TARGET=clean clean) ; else true ; fi - if [ -d nix ] ; then (cd nix; make -f ../../sources/nix/Makefile TARGET=clean clean) ; else true ; fi - if [ -d nix13 ] ; then (cd nix13; make -f ../../sources/nix13/Makefile TARGET=clean clean) ; else true ; fi - if [ -d stubs ] ; then (cd stubs; make -f ../../sources/stubs/Makefile TARGET=clean clean) ; else true ; fi + for subdir in $(SUBDIRS); do \ + ( if [ -d $$subdir ] ; then (cd $$subdir; $(MAKE) -f ../../sources/$$subdir/Makefile clean) ; else true ; fi ) \ + done veryclean: -rm -rf * diff --git a/libnix/sources/amiga/Makefile.in b/libnix/sources/amiga/Makefile.in index cba2584..a95c1cf 100644 --- a/libnix/sources/amiga/Makefile.in +++ b/libnix/sources/amiga/Makefile.in @@ -4,15 +4,16 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ -FD2INLINE = fd2inline +AWK = @AWK@ -CLIBPATH = $(prefix)/os-include/clib/ +FD2INLINE = fd2inline FDPATH = $(prefix)/os-lib/fd/ +CLIBPATH = $(prefix)/os-include/clib/ #### End system configuration section #### @@ -20,15 +21,12 @@ include ../../sources/amiga/filelist CURDIR = $(shell pwd) -OPTIONS=-I $(srcdir)/../headers -I../../sources/headers $(CFLAGS) - -SOURCEFILES=*/* +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) FDFILES = $(wildcard $(FDPATH)*.fd) CLIB = $(addprefix $(CLIBPATH),$(subst _lib.fd,_protos.h,$(notdir $(fd)))) STUB = $(subst _lib.fd,,$(notdir $(fd))) - %.o: %.c $(CC) $(OPTIONS) -c $^ -o $@ 2>&1|tee $*.err -if test ! -s $*.err; then rm $*.err; fi @@ -50,12 +48,12 @@ veryclean: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)): mkdir $@ -##libamiga.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) libglue.a ../../sources/amiga/makefile ../../sources/amiga/filelist -libamiga.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) newlibglue.a ../../sources/amiga/makefile ../../sources/amiga/filelist +#libamiga.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) libglue.a ../../sources/amiga/Makefile ../../sources/amiga/filelist +libamiga.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) newlibglue.a ../../sources/amiga/Makefile ../../sources/amiga/filelist -rm -f libamiga.a -## -cp libglue.a libamiga.a +# -cp libglue.a libamiga.a -cp newlibglue.a libamiga.a - ar -q libamiga.a $(OBJECTS) + $(AR) -q libamiga.a $(OBJECTS) $(RANLIB) libamiga.a libglue.a: @@ -87,7 +85,7 @@ libglue.a: { if(file!="") print $$0 >file; }' ); done -cd tmp;rm vararg.c dummy.c;$(CC) -c *.s -rm libglue.a - -cd tmp;ar -q ../libglue.a *.o + -cd tmp;$(AR) -q ../libglue.a *.o -rm -rf tmp newlibglue.a: stublibs @@ -97,7 +95,7 @@ newlibglue.a: stublibs rm -f $@;\ $(foreach fd, $(FDFILES),\ echo "adding $(STUB) stubs to $@ ...";\ - ar -q $@ stubs/$(STUB)/*.o;)\ + $(AR) -q $@ stubs/$(STUB)/*.o;)\ touch stamp-libglue;\ else\ true;\ diff --git a/libnix/sources/amiga/misc/AbsExecBase.c b/libnix/sources/amiga/misc/AbsExecBase.c index 714c6f5..9192ecb 100755 --- a/libnix/sources/amiga/misc/AbsExecBase.c +++ b/libnix/sources/amiga/misc/AbsExecBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" ABSDEF(AbsExecBase,0x00000004); ABSDEF(cartridge, 0x00f00000); diff --git a/libnix/sources/amiga/misc/AsmAllocPooled.c b/libnix/sources/amiga/misc/AsmAllocPooled.c index ae13362..3aba7b6 100644 --- a/libnix/sources/amiga/misc/AsmAllocPooled.c +++ b/libnix/sources/amiga/misc/AsmAllocPooled.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" APTR ASM AsmAllocPooled(REG(a0,POOL *poolHeader),REG(d0,ULONG memSize),REG(a6,APTR SysBase)) { diff --git a/libnix/sources/amiga/misc/AsmCreatePool.c b/libnix/sources/amiga/misc/AsmCreatePool.c index ebd3bd2..92f4495 100644 --- a/libnix/sources/amiga/misc/AsmCreatePool.c +++ b/libnix/sources/amiga/misc/AsmCreatePool.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" #define NEWLIST(l) ((l)->mlh_Head = (struct MinNode *)&(l)->mlh_Tail, \ (l)->mlh_Tail = NULL, \ diff --git a/libnix/sources/amiga/misc/AsmFreePooled.c b/libnix/sources/amiga/misc/AsmFreePooled.c index c7a2706..0322bbb 100644 --- a/libnix/sources/amiga/misc/AsmFreePooled.c +++ b/libnix/sources/amiga/misc/AsmFreePooled.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" VOID ASM AsmFreePooled(REG(a0,POOL *poolHeader),REG(a1,APTR memory),REG(d0,ULONG memSize),REG(a6,APTR SysBase)) { diff --git a/libnix/sources/amiga/misc/BeginIO.c b/libnix/sources/amiga/misc/BeginIO.c index c4dc0a6..96101d5 100755 --- a/libnix/sources/amiga/misc/BeginIO.c +++ b/libnix/sources/amiga/misc/BeginIO.c @@ -1,10 +1,10 @@ #ifdef __GNUC__ -#include #include +#include void BeginIO(struct IORequest *iorequest) { register struct IORequest *a1 asm("a1")=iorequest; register struct Device *a6 asm("a6")=iorequest->io_Device; - asm("jsr a6@(-30)"::"r"(a1),"r"(a6):"a0","a1","d0","d1"); + __asm __volatile ("jsr a6@(-30:W)"::"r"(a1),"r"(a6):"a0","a1","d0","d1"); } #endif diff --git a/libnix/sources/amiga/misc/Cia.c b/libnix/sources/amiga/misc/Cia.c index 76a9b16..688be32 100755 --- a/libnix/sources/amiga/misc/Cia.c +++ b/libnix/sources/amiga/misc/Cia.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" /* Absolute definitions for the cia registers * some of the are recommended to use diff --git a/libnix/sources/amiga/misc/CreateIO.c b/libnix/sources/amiga/misc/CreateIO.c index 15348e6..3510310 100755 --- a/libnix/sources/amiga/misc/CreateIO.c +++ b/libnix/sources/amiga/misc/CreateIO.c @@ -2,7 +2,7 @@ #include #include #include -#include +#include "stabs.h" struct IORequest *CreateExtIO(struct MsgPort *port,LONG iosize) { APTR SysBase = *(APTR *)4L; diff --git a/libnix/sources/amiga/misc/CreateTask.c b/libnix/sources/amiga/misc/CreateTask.c index e08c524..5864c30 100755 --- a/libnix/sources/amiga/misc/CreateTask.c +++ b/libnix/sources/amiga/misc/CreateTask.c @@ -30,8 +30,7 @@ struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize) stacksize=(stacksize+3)&~3; - { - long *p1,*p2; + { long *p1,*p2; int i; for (p1=(long *)&nml,p2=(long*)&MemTemplate,i=7; i; *p1++=*p2++,i--) ; @@ -60,6 +59,7 @@ struct Task *CreateTask(STRPTR name, LONG pri, APTR initpc, ULONG stacksize) } #else + asm(" .globl _CreateTask @@ -123,4 +123,5 @@ Lmemlist: .long 0,0 | Succ,Pred .long 0x10000 | MemType | .long 0 | Length "); + #endif diff --git a/libnix/sources/amiga/misc/Custom.c b/libnix/sources/amiga/misc/Custom.c index 4989a83..db97b57 100755 --- a/libnix/sources/amiga/misc/Custom.c +++ b/libnix/sources/amiga/misc/Custom.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" /* Absolute definitions for the custom chips * Most of them are recommended not to use diff --git a/libnix/sources/amiga/misc/DeleteTask.c b/libnix/sources/amiga/misc/DeleteTask.c index 1148deb..488e7e2 100755 --- a/libnix/sources/amiga/misc/DeleteTask.c +++ b/libnix/sources/amiga/misc/DeleteTask.c @@ -1,3 +1,3 @@ -#include +#include "stabs.h" -ALIAS (DeleteTask,RemTask); +ALIAS(DeleteTask,RemTask); diff --git a/libnix/sources/amiga/misc/DoPktn.c b/libnix/sources/amiga/misc/DoPktn.c new file mode 100644 index 0000000..8f50858 --- /dev/null +++ b/libnix/sources/amiga/misc/DoPktn.c @@ -0,0 +1,7 @@ +#include "stabs.h" + +ALIAS(DoPkt0,DoPkt); +ALIAS(DoPkt1,DoPkt); +ALIAS(DoPkt2,DoPkt); +ALIAS(DoPkt3,DoPkt); +ALIAS(DoPkt4,DoPkt); diff --git a/libnix/sources/amiga/misc/LibAllocPooled.c b/libnix/sources/amiga/misc/LibAllocPooled.c index 545a613..179d482 100755 --- a/libnix/sources/amiga/misc/LibAllocPooled.c +++ b/libnix/sources/amiga/misc/LibAllocPooled.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" APTR LibAllocPooled(APTR poolHeader, ULONG memSize) { diff --git a/libnix/sources/amiga/misc/LibCreatePool.c b/libnix/sources/amiga/misc/LibCreatePool.c index e1de3a6..0112511 100755 --- a/libnix/sources/amiga/misc/LibCreatePool.c +++ b/libnix/sources/amiga/misc/LibCreatePool.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" APTR LibCreatePool(ULONG requirements, ULONG puddleSize, ULONG threshSize) { diff --git a/libnix/sources/amiga/misc/LibFreePooled.c b/libnix/sources/amiga/misc/LibFreePooled.c index b934b3b..589f2d3 100755 --- a/libnix/sources/amiga/misc/LibFreePooled.c +++ b/libnix/sources/amiga/misc/LibFreePooled.c @@ -1,4 +1,4 @@ -#include +#include "pool.h" VOID LibFreePooled(APTR poolHeader, APTR memory, ULONG memSize) { diff --git a/libnix/sources/amiga/misc/WaitBeam.c b/libnix/sources/amiga/misc/WaitBeam.c index 2bdf43e..980402b 100755 --- a/libnix/sources/amiga/misc/WaitBeam.c +++ b/libnix/sources/amiga/misc/WaitBeam.c @@ -3,5 +3,5 @@ VOID waitbeam(LONG pos) { - do {} while(pos>VBeamPos()); + do{}while(pos>VBeamPos()); } diff --git a/libnix/sources/headers/bases.h b/libnix/sources/headers/bases.h index 44790b8..c2f44bf 100755 --- a/libnix/sources/headers/bases.h +++ b/libnix/sources/headers/bases.h @@ -1,5 +1,5 @@ -#ifndef _BASE_H_ -#define _BASE_H_ +#ifndef _HEADERS_BASE_H +#define _HEADERS_BASE_H #ifndef SMALL_DATA #define A4(x) #x @@ -21,4 +21,4 @@ #define GETUTLBASE movel A4(_UtilityBase),a6 #define GETWBBASE movel A4(_WorkbenchBase),a6 -#endif _BASE_H_ +#endif /* _HEADERS_BASE_H */ diff --git a/libnix/sources/headers/debuglib.h b/libnix/sources/headers/debuglib.h index 20a49a6..4fda8af 100755 --- a/libnix/sources/headers/debuglib.h +++ b/libnix/sources/headers/debuglib.h @@ -1,14 +1,15 @@ +#ifndef _DEBUGLIB_H +#define _DEBUGLIB_H + #ifdef DEBUG_LIB -#ifndef _DEBUGLIB_H_ -#define _DEBUGLIB_H_ +extern int KPrintF(const char *, ...); +#define DB(x) x +#define BUG KPrintF +#define ASSERT(x) { if (!(x)) KPrintF("Assertion failed: " #x " at file " __FILE__ ", line %ld\n", __LINE__); } +#else +#define DB(x) +#define BUG +#define ASSERT(x) +#endif /* DEBUG_LIB */ -/* Yet nothing - could be a debug-requester or something */ - -/* - - #define FATALERROR(a) - -*/ - -#endif -#endif +#endif /* _DEBUGLIB_H */ diff --git a/libnix/sources/headers/dirent.h b/libnix/sources/headers/dirent.h index f2fad48..cbfb45a 100755 --- a/libnix/sources/headers/dirent.h +++ b/libnix/sources/headers/dirent.h @@ -1,3 +1,6 @@ +#ifndef _HEADERS_DIRENT_H +#define _HEADERS_DIRENT_H + #include #include @@ -25,9 +28,13 @@ typedef struct _dirdesc { #define d_ead _dirun.ead #define d_info _dirun.fib -/* prototypes */ +/* +** prototypes +*/ DIR *opendir(const char *dirname); struct dirent *readdir(DIR *dirp); void rewinddir(DIR *dirp); int closedir(DIR *dirp); + +#endif /* _HEADERS_DIRENT_H */ diff --git a/libnix/sources/headers/inline/amitcp.h b/libnix/sources/headers/inline/amitcp.h new file mode 100644 index 0000000..f8272e8 --- /dev/null +++ b/libnix/sources/headers/inline/amitcp.h @@ -0,0 +1,201 @@ +#ifndef _INLINE_AMITCP_H +#define _INLINE_AMITCP_H + +#ifndef __INLINE_MACROS_H +#include +#endif + +#ifndef AMITCP_BASE_NAME +#define AMITCP_BASE_NAME lss->lx_BsdSocketBase +#endif + +#define TCP_Accept(s, addr, addrlen) \ + LP3(0x30, LONG, TCP_Accept, LONG, s, d0, struct sockaddr *, addr, a0, int *, addrlen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_Bind(s, name, namelen) \ + LP3(0x24, LONG, TCP_Bind, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_CloseSocket(d) \ + LP1(0x78, LONG, TCP_CloseSocket, LONG, d, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Connect(s, name, namelen) \ + LP3(0x36, LONG, TCP_Connect, LONG, s, d0, const struct sockaddr *, name, a0, LONG, namelen, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Dup2Socket(fd1, fd2) \ + LP2(0x108, LONG, TCP_Dup2Socket, LONG, fd1, d0, LONG, fd2, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Errno() \ + LP0(0xa2, LONG, TCP_Errno, \ + , AMITCP_BASE_NAME) + +#define TCP_GetDTableSize() \ + LP0(0x8a, LONG, TCP_GetDTableSize, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostByAddr(addr, len, type) \ + LP3(0xd8, struct hostent *, TCP_GetHostByAddr, const UBYTE *, addr, a0, LONG, len, d0, LONG, type, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostByName(name) \ + LP1(0xd2, struct hostent *, TCP_GetHostByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostId() \ + LP0(0x120, ULONG, TCP_GetHostId, \ + , AMITCP_BASE_NAME) + +#define TCP_GetHostName(hostname, size) \ + LP2(0x11a, LONG, TCP_GetHostName, STRPTR, hostname, a0, LONG, size, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetNetByAddr(net, type) \ + LP2(0xe4, struct netent *, TCP_GetNetByAddr, LONG, net, d0, LONG, type, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetNetByName(name) \ + LP1(0xde, struct netent *, TCP_GetNetByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetPeerName(s, hostname, namelen) \ + LP3(0x6c, LONG, TCP_GetPeerName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetProtoByName(name) \ + LP1(0xf6, struct protoent *, TCP_GetProtoByName, const UBYTE *, name, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetProtoByNumber(proto) \ + LP1(0xfc, struct protoent *, TCP_GetProtoByNumber, LONG, proto, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetServByName(name, proto) \ + LP2(0xea, struct servent *, TCP_GetServByName, const UBYTE *, name, a0, const UBYTE *, proto, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetServByPort(port, proto) \ + LP2(0xf0, struct servent *, TCP_GetServByPort, LONG, port, d0, const UBYTE *, proto, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSockName(s, hostname, namelen) \ + LP3(0x66, LONG, TCP_GetSockName, LONG, s, d0, struct sockaddr *, hostname, a0, int *, namelen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSockOpt(s, level, optname, optval, optlen) \ + LP5(0x60, LONG, TCP_GetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, void *, optval, a0, int *, optlen, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_GetSocketEvents(eventmaskp) \ + LP1(0x12c, LONG, TCP_GetSocketEvents, ULONG *, eventmaskp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_Addr(cp) \ + LP1(0xb4, ULONG, TCP_Inet_Addr, const UBYTE *, cp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_LnaOf(in) \ + LP1(0xba, ULONG, TCP_Inet_LnaOf, LONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_MakeAddr(net, host) \ + LP2(0xc6, ULONG, TCP_Inet_MakeAddr, ULONG, net, d0, ULONG, host, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_NetOf(in) \ + LP1(0xc0, ULONG, TCP_Inet_NetOf, LONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_Network(cp) \ + LP1(0xcc, ULONG, TCP_Inet_Network, const UBYTE *, cp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Inet_NtoA(in) \ + LP1(0xae, char *, TCP_Inet_NtoA, ULONG, in, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_IoctlSocket(d, request, argp) \ + LP3(0x72, LONG, TCP_IoctlSocket, LONG, d, d0, ULONG, request, d1, char *, argp, a0, \ + , AMITCP_BASE_NAME) + +#define TCP_Listen(s, backlog) \ + LP2(0x2a, LONG, TCP_Listen, LONG, s, d0, LONG, backlog, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ObtainSocket(id, domain, type, protocol) \ + LP4(0x90, LONG, TCP_ObtainSocket, LONG, id, d0, LONG, domain, d1, LONG, type, d2, LONG, protocol, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_Recv(s, buf, len, flags) \ + LP4(0x4e, LONG, TCP_Recv, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_RecvFrom(s, buf, len, flags, from, fromlen) \ + LP6(0x48, LONG, TCP_RecvFrom, LONG, s, d0, UBYTE *, buf, a0, LONG, len, d1, LONG, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \ + , AMITCP_BASE_NAME) + +#define TCP_RecvMsg(s, msg, flags) \ + LP3(0x114, LONG, TCP_RecvMsg, LONG, s, d0, struct msghdr *, msg, a0, LONG, flags, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ReleaseCopyOfSocket(fd, id) \ + LP2(0x9c, LONG, TCP_ReleaseCopyOfSocket, LONG, fd, d0, LONG, id, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_ReleaseSocket(fd, id) \ + LP2(0x96, LONG, TCP_ReleaseSocket, LONG, fd, d0, LONG, id, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Send(s, msg, len, flags) \ + LP4(0x42, LONG, TCP_Send, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_SendMsg(s, msg, flags) \ + LP3(0x10e, LONG, TCP_SendMsg, LONG, s, d0, const struct msghdr *, msg, a0, LONG, flags, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_SendTo(s, msg, len, flags, to, tolen) \ + LP6(0x3c, LONG, TCP_SendTo, LONG, s, d0, const UBYTE *, msg, a0, LONG, len, d1, LONG, flags, d2, const struct sockaddr *, to, a1, LONG, tolen, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_SetErrnoPtr(errno_p, size) \ + LP2(0xa8, LONG, TCP_SetErrnoPtr, void *, errno_p, a0, LONG, size, d0, \ + , AMITCP_BASE_NAME) + +#define TCP_SetSockOpt(s, level, optname, optval, optlen) \ + LP5(0x5a, LONG, TCP_SetSockOpt, LONG, s, d0, LONG, level, d1, LONG, optname, d2, const void *, optval, a0, LONG, optlen, d3, \ + , AMITCP_BASE_NAME) + +#define TCP_SetSocketSignals(SIGINTR, SIGIO, SIGURG) \ + LP3NR(0x84, TCP_SetSocketSignals, ULONG, SIGINTR, d0, ULONG, SIGIO, d1, ULONG, SIGURG, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_ShutDown(s, how) \ + LP2(0x54, LONG, TCP_ShutDown, LONG, s, d0, LONG, how, d1, \ + , AMITCP_BASE_NAME) + +#define TCP_Socket(domain, type, protocol) \ + LP3(0x1e, LONG, TCP_Socket, LONG, domain, d0, LONG, type, d1, LONG, protocol, d2, \ + , AMITCP_BASE_NAME) + +#define TCP_SocketBaseTagList(taglist) \ + LP1(0x126, LONG, TCP_SocketBaseTagList, struct TagItem *, taglist, a0, \ + , AMITCP_BASE_NAME) + +#ifndef NO_INLINE_STDARG +#define TCP_SocketBaseTags(tags...) \ + ({ULONG _tags[] = { tags }; TCP_SocketBaseTagList((struct TagItem *)_tags);}) +#endif /* !NO_INLINE_STDARG */ + +#define TCP_SyslogA(level, format, ap) \ + LP3NR(0x102, TCP_SyslogA, ULONG, level, d0, const char *, format, a0, va_list, ap, a1, \ + , AMITCP_BASE_NAME) + +#define TCP_WaitSelect(nfds, readfds, writefds, execptfds, timeout, maskp) \ + LP6(0x7e, LONG, TCP_WaitSelect, LONG, nfds, d0, fd_set *, readfds, a0, fd_set *, writefds, a1, fd_set *, execptfds, a2, struct timeval *, timeout, a3, ULONG *, maskp, d1, \ + , AMITCP_BASE_NAME) + +#endif /* _INLINE_AMITCP_H */ diff --git a/libnix/sources/headers/inline/as225.h b/libnix/sources/headers/inline/as225.h new file mode 100644 index 0000000..48d8d7c --- /dev/null +++ b/libnix/sources/headers/inline/as225.h @@ -0,0 +1,296 @@ +#ifndef _INLINE_AS225_H +#define _INLINE_AS225_H + +#ifndef __INLINE_MACROS_H +#include +#endif + +#ifndef AS225_BASE_NAME +#define AS225_BASE_NAME lss->lx_SocketBase +#endif + +#define SOCK_accept(s, name, lenp) \ + LP3(0xba, int, SOCK_accept, int, s, d0, struct sockaddr *, name, a0, int *, lenp, a1, \ + , AS225_BASE_NAME) + +#define SOCK_bind(s, name, namelen) \ + LP3(0xc0, int, SOCK_bind, int, s, d0, const struct sockaddr *, name, a1, int, namelen, d1, \ + , AS225_BASE_NAME) + +#define SOCK_cleanup_sockets() \ + LP0NR(0x24, SOCK_cleanup_sockets, \ + , AS225_BASE_NAME) + +#define SOCK_close(socket) \ + LP1(0x30, int, SOCK_close, int, socket, d0, \ + , AS225_BASE_NAME) + +#define SOCK_connect(s, name, namelen) \ + LP3(0xc6, int, SOCK_connect, int, s, d0, const struct sockaddr *, name, a1, int, namelen, d1, \ + , AS225_BASE_NAME) + +#define SOCK_dev_list(res, size) \ + LP2NR(0x1bc, SOCK_dev_list, u_long, res, d0, int, size, d1, \ + , AS225_BASE_NAME) + +#define SOCK_endhostent() \ + LP0NR(0x7e, SOCK_endhostent, \ + , AS225_BASE_NAME) + +#define SOCK_endnetent() \ + LP0NR(0x120, SOCK_endnetent, \ + , AS225_BASE_NAME) + +#define SOCK_endprotoent() \ + LP0NR(0x13e, SOCK_endprotoent, \ + , AS225_BASE_NAME) + +#define SOCK_endpwent() \ + LP0NR(0x18c, SOCK_endpwent, \ + , AS225_BASE_NAME) + +#define SOCK_endservent() \ + LP0NR(0x15c, SOCK_endservent, \ + , AS225_BASE_NAME) + +#define SOCK_get_tz() \ + LP0(0x5a, short, SOCK_get_tz, \ + , AS225_BASE_NAME) + +#define SOCK_getdomainname(name, namelen) \ + LP2(0x60, int, SOCK_getdomainname, char *, name, a1, int, namelen, d1, \ + , AS225_BASE_NAME) + +#define SOCK_getgid() \ + LP0(0x48, gid_t, SOCK_getgid, \ + , AS225_BASE_NAME) + +#define SOCK_getgroups(num, gids) \ + LP2(0x4e, int, SOCK_getgroups, int, num, d0, int *, gids, a0, \ + , AS225_BASE_NAME) + +#define SOCK_gethostbyaddr(addr, len, type) \ + LP3(0x90, struct hostent *, SOCK_gethostbyaddr, const char *, addr, a0, int, len, d0, int, type, d1, \ + , AS225_BASE_NAME) + +#define SOCK_gethostbyname(name) \ + LP1(0x8a, struct hostent *, SOCK_gethostbyname, const char *, name, a0, \ + , AS225_BASE_NAME) + +#define SOCK_gethostent() \ + LP0(0x84, struct hostent *, SOCK_gethostent, \ + , AS225_BASE_NAME) + +#define SOCK_gethostname(name, length) \ + LP2(0x72, int, SOCK_gethostname, char *, name, a0, int, length, d0, \ + , AS225_BASE_NAME) + +#define SOCK_getlogin() \ + LP0(0x54, char *, SOCK_getlogin, \ + , AS225_BASE_NAME) + +#define SOCK_getnetbyaddr(net, type) \ + LP2(0x12c, struct netent *, SOCK_getnetbyaddr, long, net, d0, int, type, d1, \ + , AS225_BASE_NAME) + +#define SOCK_getnetbyname(name) \ + LP1(0x132, struct netent *, SOCK_getnetbyname, const char *, name, a0, \ + , AS225_BASE_NAME) + +#define SOCK_getnetent() \ + LP0(0x126, struct netent *, SOCK_getnetent, \ + , AS225_BASE_NAME) + +#define SOCK_getpeername(s, name, lenp) \ + LP3(0x198, int, SOCK_getpeername, int, s, d0, struct sockaddr *, name, a0, int *, lenp, a1, \ + , AS225_BASE_NAME) + +#define SOCK_getprotobyname(name) \ + LP1(0x14a, struct protoent *, SOCK_getprotobyname, const char *, name, a0, \ + , AS225_BASE_NAME) + +#define SOCK_getprotobynumber(proto) \ + LP1(0x150, struct protoent *, SOCK_getprotobynumber, int, proto, d0, \ + , AS225_BASE_NAME) + +#define SOCK_getprotoent() \ + LP0(0x144, struct protoent *, SOCK_getprotoent, \ + , AS225_BASE_NAME) + +#define SOCK_getpwent() \ + LP0(0x180, struct AS225_passwd *, SOCK_getpwent, \ + , AS225_BASE_NAME) + +#define SOCK_getpwnam(name) \ + LP1(0x17a, struct AS225_passwd *, SOCK_getpwnam, char *, name, a0, \ + , AS225_BASE_NAME) + +#define SOCK_getpwuid(uid) \ + LP1(0x174, struct AS225_passwd *, SOCK_getpwuid, uid_t, uid, d1, \ + , AS225_BASE_NAME) + +#define SOCK_getservbyname(name, proto) \ + LP2(0x168, struct servent *, SOCK_getservbyname, const char *, name, a0, const char *, proto, a1, \ + , AS225_BASE_NAME) + +#define SOCK_getservbyport(port, proto) \ + LP2(0x16e, struct servent *, SOCK_getservbyport, u_short, port, d0, const char *, proto, a0, \ + , AS225_BASE_NAME) + +#define SOCK_getservent() \ + LP0(0x162, struct servent *, SOCK_getservent, \ + , AS225_BASE_NAME) + +#define SOCK_getsignal(type) \ + LP1(0x36, BYTE, SOCK_getsignal, UWORD, type, d1, \ + , AS225_BASE_NAME) + +#define SOCK_getsockname(s, name, lenp) \ + LP3(0x19e, int, SOCK_getsockname, int, s, d0, struct sockaddr *, name, a0, int *, lenp, a1, \ + , AS225_BASE_NAME) + +#define SOCK_getsockopt(s, level, optname, optval, optlenp) \ + LP5(0x114, int, SOCK_getsockopt, int, s, d0, int, level, d1, int, optname, d2, char *, optval, a0, int *, optlenp, a1, \ + , AS225_BASE_NAME) + +#define SOCK_getuid() \ + LP0(0x42, uid_t, SOCK_getuid, \ + , AS225_BASE_NAME) + +#define SOCK_getumask() \ + LP0(0x66, mode_t, SOCK_getumask, \ + , AS225_BASE_NAME) + +#define SOCK_inet_addr(cp) \ + LP1(0x96, u_long, SOCK_inet_addr, char *, cp, a1, \ + , AS225_BASE_NAME) + +#define SOCK_inet_lnaof(in) \ + LP1(0xa2, int, SOCK_inet_lnaof, struct, in, d1, \ + , AS225_BASE_NAME) + +#define SOCK_inet_makeaddr(net, lna) \ + LP2(0x9c, struct in_addr, SOCK_inet_makeaddr, int, net, d0, int, lna, d1, \ + , AS225_BASE_NAME) + +#define SOCK_inet_netof(in) \ + LP1(0xa8, int, SOCK_inet_netof, struct, in, d1, \ + , AS225_BASE_NAME) + +#define SOCK_inet_network(str) \ + LP1(0xae, int, SOCK_inet_network, char *, str, a1, \ + , AS225_BASE_NAME) + +#define SOCK_inet_ntoa(in) \ + LP1(0xb4, char *, SOCK_inet_ntoa, struct, in, d1, \ + , AS225_BASE_NAME) + +#define SOCK_inherit(sp) \ + LP1(0x1b6, int, SOCK_inherit, void *, sp, d1, \ + , AS225_BASE_NAME) + +#define SOCK_ioctl(s, cmd, data) \ + LP3(0xcc, int, SOCK_ioctl, int, s, d0, int, cmd, d1, char *, data, a0, \ + , AS225_BASE_NAME) + +#define SOCK_listen(s, backlog) \ + LP2(0xd2, int, SOCK_listen, int, s, d0, int, backlog, d1, \ + , AS225_BASE_NAME) + +#define SOCK_rcmd(ahost, inport, luser, ruser, cmd, fd2p) \ + LP6(0x192, int, SOCK_rcmd, char **, ahost, d0, u_short, inport, d1, char *, luser, a0, char *, ruser, a1, char *, cmd, a2, int *, fd2p, d2, \ + , AS225_BASE_NAME) + +#define SOCK_reconfig() \ + LP0(0x1aa, int, SOCK_reconfig, \ + , AS225_BASE_NAME) + +#define SOCK_recv(s, buf, len, flags) \ + LP4(0xd8, int, SOCK_recv, int, s, d0, char *, buf, a0, int, len, d1, int, flags, d2, \ + , AS225_BASE_NAME) + +#define SOCK_recvfrom(s, buf, len, flags, from, fromlen) \ + LP6(0xde, int, SOCK_recvfrom, int, s, d0, char *, buf, a0, int, len, d1, int, flags, d2, struct sockaddr *, from, a1, int *, fromlen, a2, \ + , AS225_BASE_NAME) + +#define SOCK_recvmsg(s, msg, flags) \ + LP3(0xe4, int, SOCK_recvmsg, int, s, d0, struct msghdr *, msg, a0, int, flags, d1, \ + , AS225_BASE_NAME) + +#define SOCK_release(s) \ + LP1(0x1b0, void *,SOCK_release, int, s, d1, \ + , AS225_BASE_NAME) + +#define SOCK_select(numfds, rfds, wfds, efds, timeout) \ + LP5(0xea, int, SOCK_select, int, numfds, d0, fd_set *, rfds, a0, fd_set *, wfds, a1, fd_set *, efds, a2, struct timeval *, timeout, d1, \ + , AS225_BASE_NAME) + +#define SOCK_selectwait(numfds, rfds, wfds, efds, timeout, umask) \ + LP6(0xf0, int, SOCK_selectwait, int, numfds, d0, fd_set *, rfds, a0, fd_set *, wfds, a1, fd_set *, efds, a2, struct timeval *, timeout, d1, long *, umask, d2, \ + , AS225_BASE_NAME) + +#define SOCK_send(s, buf, len, flags) \ + LP4(0xf6, int, SOCK_send, int, s, d0, const char *, buf, a0, int, len, d1, int, flags, a1, \ + , AS225_BASE_NAME) + +#define SOCK_sendmsg(s, msg, flags) \ + LP3(0x102, int, SOCK_sendmsg, int, s, d0, const struct msghdr *, msg, a0, int, flags, d1, \ + , AS225_BASE_NAME) + +#define SOCK_sendto(s, buf, len, flags, to, to_len) \ + LP6(0xfc, int, SOCK_sendto, int, s, d0, const char *, buf, a0, int, len, d1, int, flags, d2, const struct sockaddr *, to, a1, int, to_len, d3, \ + , AS225_BASE_NAME) + +#define SOCK_sethostent(flag) \ + LP1NR(0x78, SOCK_sethostent, int, flag, d1, \ + , AS225_BASE_NAME) + +#define SOCK_setnetent(flag) \ + LP1NR(0x11a, SOCK_setnetent, int, flag, d1, \ + , AS225_BASE_NAME) + +#define SOCK_setprotoent(flag) \ + LP1NR(0x138, SOCK_setprotoent, int, flag, d1, \ + , AS225_BASE_NAME) + +#define SOCK_setpwent(flag) \ + LP1NR(0x186, SOCK_setpwent, int, flag, d1, \ + , AS225_BASE_NAME) + +#define SOCK_setservent(flag) \ + LP1NR(0x156, SOCK_setservent, int, flag, d1, \ + , AS225_BASE_NAME) + +#define SOCK_setsockopt(s, level, optname, optval, optlen) \ + LP5(0x10e, int, SOCK_setsockopt, int, s, d0, int, level, d1, int, optname, d2, const char *, optval, a0, int, optlen, d3, \ + , AS225_BASE_NAME) + +#define SOCK_setup_sockets(max_socks, errno_ptr) \ + LP2(0x1e, ULONG, SOCK_setup_sockets, UWORD, max_socks, d1, int *, errno_ptr, a0, \ + , AS225_BASE_NAME) + +#define SOCK_shutdown(s, how) \ + LP2(0x108, int, SOCK_shutdown, int, s, d0, int, how, d1, \ + , AS225_BASE_NAME) + +#define SOCK_socket(family, type, protocol) \ + LP3(0x2a, int, SOCK_socket, int, family, d0, int, type, d1, int, protocol, d2, \ + , AS225_BASE_NAME) + +#define SOCK_strerror(num) \ + LP1(0x3c, char *, SOCK_strerror, int, num, d1, \ + , AS225_BASE_NAME) + +#define SOCK_syslog(pri, msg) \ + LP2(0x1a4, int, SOCK_syslog, int, pri, d0, char *, msg, a0, \ + , AS225_BASE_NAME) + +#define SOCK_umask(cmask) \ + LP1(0x6c, mode_t, SOCK_umask, mode_t, cmask, d0, \ + , AS225_BASE_NAME) + +#define SOCK_dup(fd) \ + LP1(0x2b2, int, SOCK_dup, int, fd, d0, \ + , AS225_BASE_NAME) + +#endif /* _INLINE_AS225_H */ diff --git a/libnix/sources/headers/inline/usergroup.h b/libnix/sources/headers/inline/usergroup.h new file mode 100644 index 0000000..5bc5c57 --- /dev/null +++ b/libnix/sources/headers/inline/usergroup.h @@ -0,0 +1,173 @@ +#ifndef _INLINE_USERGROUP_H +#define _INLINE_USERGROUP_H + +#ifndef __INLINE_MACROS_H +#include +#endif + +#ifndef USERGROUP_BASE_NAME +#define USERGROUP_BASE_NAME lss->lx_UserGroupBase +#endif + +#define UG_crypt(key, salt) \ + LP2(0xae, char *, UG_crypt, const char *, key, a0, const char *, salt, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_endgrent() \ + LP0NR(0xa8, UG_endgrent, \ + , USERGROUP_BASE_NAME) + +#define UG_endpwent() \ + LP0NR(0x8a, UG_endpwent, \ + , USERGROUP_BASE_NAME) + +#define UG_endutent() \ + LP0NR(0xf0, UG_endutent, \ + , USERGROUP_BASE_NAME) + +#define UG_getcredentials(task) \ + LP1(0x102, struct UserGroupCredentials *, UG_getcredentials, struct Task *, task, a0, \ + , USERGROUP_BASE_NAME) + +#define UG_getegid() \ + LP0(0x4e, gid_t, UG_getegid, \ + , USERGROUP_BASE_NAME) + +#define UG_geteuid() \ + LP0(0x36, uid_t, UG_geteuid, \ + , USERGROUP_BASE_NAME) + +#define UG_getgid() \ + LP0(0x48, gid_t, UG_getgid, \ + , USERGROUP_BASE_NAME) + +#define UG_getgrent() \ + LP0(0xa2, struct group *, UG_getgrent, \ + , USERGROUP_BASE_NAME) + +#define UG_getgrgid(gid) \ + LP1(0x96, struct group *, UG_getgrgid, gid_t, gid, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_getgrnam(name) \ + LP1(0x90, struct group *, UG_getgrnam, const char *, name, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_getgroups(ngroups, groups) \ + LP2(0x60, int, UG_getgroups, int, ngroups, d0, int *, groups, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_getlastlog(uid) \ + LP1(0xf6, struct lastlog *, UG_getlastlog, uid_t, uid, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_getlogin() \ + LP0(0xd8, char *, UG_getlogin, \ + , USERGROUP_BASE_NAME) + +#define UG_getpass(prompt) \ + LP1(0xba, char *, UG_getpass, const char *, prompt, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_getpgrp() \ + LP0(0xd2, pid_t, UG_getpgrp, \ + , USERGROUP_BASE_NAME) + +#define UG_getpwent() \ + LP0(0x84, struct TCP_passwd *, UG_getpwent, \ + , USERGROUP_BASE_NAME) + +#define UG_getpwnam(name) \ + LP1(0x72, struct TCP_passwd *, UG_getpwnam, const char *, name, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_getpwuid(uid) \ + LP1(0x78, struct TCP_passwd *, UG_getpwuid, uid_t, uid, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_getuid() \ + LP0(0x30, uid_t, UG_getuid, \ + , USERGROUP_BASE_NAME) + +#define UG_getumask() \ + LP0(0xc6, mode_t, UG_getumask, \ + , USERGROUP_BASE_NAME) + +#define UG_getutent() \ + LP0(0xea, struct utmp *, UG_getutent, \ + , USERGROUP_BASE_NAME) + +#define UG_initgroups(name, basegroup) \ + LP2(0x6c, int, UG_initgroups, const char *, name, a1, gid_t, basegroup, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_setgid(id) \ + LP1(0x5a, int, UG_setgid, gid_t, id, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_setgrent() \ + LP0NR(0x9c, UG_setgrent, \ + , USERGROUP_BASE_NAME) + +#define UG_setgroups(ngroups, groups) \ + LP2(0x66, int, UG_setgroups, int, ngroups, d0, const int *, groups, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_setlastlog(uid, name, host) \ + LP3(0xfc, int, UG_setlastlog, uid_t, uid, d0, char *, name, a0, char *, host, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_setlogin(buffer) \ + LP1(0xde, int, UG_setlogin, const char *, buffer, a1, \ + , USERGROUP_BASE_NAME) + +#define UG_setpwent() \ + LP0NR(0x7e, UG_setpwent, \ + , USERGROUP_BASE_NAME) + +#define UG_setregid(real, eff) \ + LP2(0x54, int, UG_setregid, gid_t, real, d0, gid_t, eff, d1, \ + , USERGROUP_BASE_NAME) + +#define UG_setreuid(real, eff) \ + LP2(0x3c, int, UG_setreuid, uid_t, real, d0, uid_t, eff, d1, \ + , USERGROUP_BASE_NAME) + +#define UG_setsid() \ + LP0(0xcc, pid_t, UG_setsid, \ + , USERGROUP_BASE_NAME) + +#define UG_setuid(id) \ + LP1(0x42, int, UG_setuid, uid_t, id, d0, \ + , USERGROUP_BASE_NAME) + +#define UG_setutent() \ + LP0NR(0xe4, UG_setutent, \ + , USERGROUP_BASE_NAME) + +#define UG_umask(mask) \ + LP1(0xc0, mode_t, UG_umask, mode_t, mask, d0, \ + , USERGROUP_BASE_NAME) + +#define ug_GetErr() \ + LP0(0x24, int, ug_GetErr, \ + , USERGROUP_BASE_NAME) + +#define ug_GetSalt(user, buffer, size) \ + LP3(0xb4, char *, ug_GetSalt, const struct TCP_passwd *, user, a0, char *, buffer, a1, ULONG, size, d0, \ + , USERGROUP_BASE_NAME) + +#define ug_SetupContextTagList(pname, taglist) \ + LP2(0x1e, int, ug_SetupContextTagList, const UBYTE*, pname, a0, struct TagItem *, taglist, a1, \ + , USERGROUP_BASE_NAME) + +#ifndef NO_INLINE_STDARG +#define ug_SetupContextTags(a0, tags...) \ + ({ULONG _tags[] = { tags }; ug_SetupContextTagList((a0), (struct TagItem *)_tags);}) +#endif /* !NO_INLINE_STDARG */ + +#define ug_StrError(code) \ + LP1(0x2a, const char *, ug_StrError, LONG, code, d1, \ + , USERGROUP_BASE_NAME) + +#endif /* _INLINE_USERGROUP_H */ diff --git a/libnix/sources/headers/libinit.h b/libnix/sources/headers/libinit.h index 470a449..aecada9 100755 --- a/libnix/sources/headers/libinit.h +++ b/libnix/sources/headers/libinit.h @@ -1,3 +1,6 @@ +#ifndef _HEADERS_LIBINIT_H +#define _HEADERS_LIBINIT_H + /******************************************************************************/ /* */ /* special define(s) */ @@ -19,7 +22,7 @@ /* */ /******************************************************************************/ -struct LibBase { +typedef struct libBase { struct Library LibNode; UWORD Pad; LONG SegList; @@ -27,9 +30,9 @@ struct LibBase { SysBase; #ifdef EXTENDED ULONG DataSize; - struct LibBase *Parent; + struct libBase *Parent; #endif -}; +} *__LIB, *__DEV; /******************************************************************************/ /* */ @@ -38,10 +41,10 @@ struct LibBase { /******************************************************************************/ LONG LibExtFunc(VOID); -LONG LibExpunge(REG(a6,struct LibBase *)); -LONG LibClose(REG(a6,struct LibBase *)); -APTR LibOpen(REG(a6,struct LibBase *)); -APTR LibInit(REG(a0,LONG),REG(d0,struct LibBase *),REG(a6,struct Library *)); +LONG LibExpunge(REG(a6,__LIB)); +LONG LibClose(REG(a6,__LIB)); +APTR LibOpen(REG(a6,__LIB)); +APTR LibInit(REG(a0,LONG),REG(d0,__LIB),REG(a6,struct Library *)); /******************************************************************************/ /* */ @@ -49,11 +52,11 @@ APTR LibInit(REG(a0,LONG),REG(d0,struct LibBase *),REG(a6,struct Library *)); /* */ /******************************************************************************/ -APTR DevInit(); -VOID DevOpen(); -APTR DevClose(); -APTR DevExpunge(); -APTR DevExtFunc(); +LONG DevExtFunc(VOID); +LONG DevExpunge(REG(a6,__DEV)); +LONG DevClose(REG(a1,APTR),REG(a6,__DEV)); +VOID DevOpen(REG(d0,ULONG),REG(a1,APTR),REG(d1,ULONG),REG(a6,__DEV)); +APTR DevInit(REG(a0,LONG),REG(d0,__DEV),REG(a6,struct Library *)); /******************************************************************************/ /* */ @@ -69,13 +72,19 @@ extern const UWORD LibRevision; extern const char LibIdString[]; extern const char LibName[]; +extern LONG __stdargs __UserDevInit(struct Library *,REG(a4,APTR)); +extern LONG __stdargs __UserDevOpen(struct IORequest *,ULONG,ULONG,REG(a4,APTR)); +extern VOID __stdargs __UserDevClose(struct IORequest *,REG(a4,APTR)); +extern VOID __stdargs __UserDevCleanup(REG(a4,APTR)); + +extern const UWORD DevVersion; +extern const UWORD DevRevision; +extern const char DevIdString[]; +extern const char DevName[]; + extern APTR __LibTable__[]; extern APTR __FuncTable__[]; extern LONG __datadata_relocs[]; -/******************************************************************************/ -/* */ -/* end of libinit.h */ -/* */ -/******************************************************************************/ +#endif /* _HEADERS_LIBINIT_H */ diff --git a/libnix/sources/headers/pool.h b/libnix/sources/headers/pool.h index 1af70f7..ec69602 100755 --- a/libnix/sources/headers/pool.h +++ b/libnix/sources/headers/pool.h @@ -1,3 +1,6 @@ +#ifndef _HEADERS_POOL_H +#define _HEADERS_POOL_H + #include #if defined(__GNUC__) @@ -25,10 +28,12 @@ typedef struct Pool { } POOL; /* -** required prototypes ;) +** required prototypes */ APTR ASM AsmCreatePool(REG(d0,ULONG),REG(d1,ULONG),REG(d2,ULONG),REG(a6,APTR)); APTR ASM AsmAllocPooled(REG(a0,POOL *),REG(d0,ULONG),REG(a6,APTR)); VOID ASM AsmFreePooled(REG(a0,POOL *),REG(a1,APTR),REG(d0,ULONG),REG(a6,APTR)); VOID ASM AsmDeletePool(REG(a0,POOL *),REG(a6,APTR)); + +#endif /* _HEADERS_POOL_H */ diff --git a/libnix/sources/headers/rand48.h b/libnix/sources/headers/rand48.h index d8225af..d94495d 100755 --- a/libnix/sources/headers/rand48.h +++ b/libnix/sources/headers/rand48.h @@ -1,3 +1,6 @@ +#ifndef _HEADERS_RAND48_H +#define _HEADERS_RAND48_H + void srand48(long); unsigned short *seed48(unsigned short *); void lcong48(unsigned short *); @@ -7,3 +10,5 @@ long mrand48(void); long jrand48(unsigned short *); double drand48(void); double erand48(unsigned short *seed); + +#endif /* _HEADERS_RAND48_H */ diff --git a/libnix/sources/headers/regparm.h b/libnix/sources/headers/regparm.h index 38be755..82022c5 100755 --- a/libnix/sources/headers/regparm.h +++ b/libnix/sources/headers/regparm.h @@ -1,3 +1,6 @@ +#ifndef _HEADERS_REGPARM_H +#define _HEADERS_REGPARM_H + #define ___PUSH(a) "movel\t" #a ",sp@-\n" #define ___POP(a) "movel\tsp@+," #a "\n" @@ -29,3 +32,4 @@ __REGP(functype,funcname,___PUSH(r3)___PUSH(r2)___PUSH(r1),12) (a1,a2,a3) #define REGPARM4(functype,funcname,a1,r1,a2,r2,a3,r3,a4,r4) \ __REGP(functype,funcname,___PUSH(r4)___PUSH(r3)___PUSH(r2)___PUSH(r1),16) (a1,a2,a3,a4) +#endif /* _HEADERS_REGPARM_H */ diff --git a/libnix/sources/headers/select.h b/libnix/sources/headers/select.h new file mode 100644 index 0000000..93b077d --- /dev/null +++ b/libnix/sources/headers/select.h @@ -0,0 +1,28 @@ +#ifndef _HEADERS_SELECT_H +#define _HEADERS_SELECT_H + +#define SELCMD_PREPARE 0 +#define SELCMD_CHECK 1 +#define SELCMD_POLL 2 + +#define SELMODE_IN 0 +#define SELMODE_OUT 1 +#define SELMODE_EXC 2 + +#define SELPKT_IN_USE(fp) ((fp)->lx_packet->sp_Pkt.dp_Port != NULL) + +#define SelLastResult(fp) ((fp)->lx_packet->sp_Pkt.dp_Res1) +#define SelLastError(fp) ((fp)->lx_packet->sp_Pkt.dp_Res2) + +#define PutPacket(port,pack) PutMsg((port),(pack)) +#define GetPacket(port) ((struct StandardPacket *)GetMsg(port)) +#define SelSendPacket1(fp,port,act,arg1) \ + do { \ + struct StandardPacket *sp = (fp)->lx_packet; \ + sp->sp_Pkt.dp_Port = (port); \ + sp->sp_Pkt.dp_Type = (act); \ + sp->sp_Pkt.dp_Arg1 = (arg1); \ + PutPacket(((struct FileHandle *)BADDR((fp)->lx_fh))->fh_Type,&sp->sp_Msg); \ + } while(0) + +#endif /* _HEADERS_SELECT_H */ diff --git a/libnix/sources/headers/socket.h b/libnix/sources/headers/socket.h new file mode 100644 index 0000000..609528a --- /dev/null +++ b/libnix/sources/headers/socket.h @@ -0,0 +1,104 @@ +#ifndef _HEADERS_SOCKET_H +#define _HEADERS_SOCKET_H + +/* +** +*/ +#include +#include +#include +#include "inline/usergroup.h" +#include "inline/amitcp.h" +#include "inline/as225.h" +#include "stdio.h" + +/* +** +*/ +typedef enum {LX_NONE, LX_AMITCP, LX_AS225} LX_NETWORK_TYPE; + +/* +** +*/ +struct SocketSettings { + LX_NETWORK_TYPE lx_network_type; + union { + struct { + struct Library *BsdSocketBase; + struct Library *UserGroupBase; + } AMITCP; + struct { + struct Library *SocketBase; + } AS225; + } lx_stack; +#define lx_BsdSocketBase lx_stack.AMITCP.BsdSocketBase +#define lx_UserGroupBase lx_stack.AMITCP.UserGroupBase +#define lx_SocketBase lx_stack.AS225.SocketBase + + unsigned long lx_sigurg; + unsigned long lx_sigio; + int lx_sockid; + int lx_isdaemon; + + /* Support for net functions */ + FILE *lx_pwd_fp; /* File pointer to the passwd file */ + char *lx_pwd_line; /* buffer for reading a line from the passwd file */ + struct passwd lx_pwd; /* static buffer to hold the data */ + int lx_pwd_stayopen;/* TRUE if passwd file should stay open */ + + FILE *lx_grp_fp; /* File pointer to the groups file */ + char *lx_grp_line; /* buffer for reading a line from the group file */ + struct group lx_grp; /* static buffer to hold the data */ + char **lx_members; /* array of group members */ + int lx_grp_stayopen;/* TRUE if group file should stay open */ + + FILE *lx_net_fp; /* File pointer to protocol file */ + char *lx_net_line; /* buffer for reading a line from the protocol file */ + struct netent lx_net; + char **lx_net_aliases; + int lx_net_stayopen; + + FILE *lx_serv_fp; /* File pointer to services file */ + char *lx_serv_line; /* buffer for reading a line from the services file */ + struct servent lx_serv; + char **lx_serv_aliases; + int lx_serv_stayopen; + + FILE *lx_proto_fp; /* File pointer to protocol file */ + char *lx_proto_line; /* buffer for reading a line from the protocol file */ + struct protoent lx_proto; + char **lx_proto_aliases; + int lx_proto_stayopen; + + /* resolv state structure */ + struct __res_state *lx_res; + int *lx_res_socket; + + /* XXX unused XXX */ + int lx_logname_valid; + char lx_logname[MAXLOGNAME + 1]; + char lx_logname_buf[MAXLOGNAME + 1]; + + /* XXX unused XXX */ + char lx_ntoa_buf[18]; /* used by inet_ntoa */ + + /* logfile handling */ + int lx_LogFile; /* fd for log */ + int lx_LogStat; /* status bits, set by openlog() */ + char *lx_LogTag; /* string to tag the entry with */ + int lx_LogFacility; /* default facility code */ + int lx_LogMask; /* mask of priorities to be logged */ + int lx_setuid; /* used for setuid() - have to remember to log out */ +}; + +/* +** +*/ +extern struct SocketSettings *_lx_get_socket_settings(void); + +/* +** +*/ +extern StdFileDes *_create_socket(int family, int type, int protocol); + +#endif /* _HEADERS_SOCKET_H */ diff --git a/libnix/sources/headers/stabs.h b/libnix/sources/headers/stabs.h index e4051f3..584f2ca 100755 --- a/libnix/sources/headers/stabs.h +++ b/libnix/sources/headers/stabs.h @@ -1,11 +1,11 @@ -#ifndef _STABS_H_ -#define _STABS_H_ +#ifndef _HEADERS_STABS_H +#define _HEADERS_STABS_H /* These are some macros for handling of symboltable information */ /* linker can use symbol b for symbol a if a is not defined */ -#define ALIAS(a,b) asm(".stabs \"_" #a "\",11,0,0,0\n.stabs \"_" #b "\",1,0,0,0") +#define ALIAS(a,b) asm(".stabs \"_" #a "\",11,0,0,0;.stabs \"_" #b "\",1,0,0,0") /* add symbol a to list b (type c (22=text 24=data 26=bss)) */ #define ADD2LIST(a,b,c) asm(".stabs \"_" #b "\"," #c ",0,0,_" #a ) @@ -99,4 +99,4 @@ _ADDTABL_ENDN(name,4) #define ADDTABL_END() asm(".stabs \"___FuncTable__\",20,0,0,-1") -#endif +#endif /* _HEADERS_STABS_H */ diff --git a/libnix/sources/headers/stdio.h b/libnix/sources/headers/stdio.h index 3f2b457..e2c0b33 100755 --- a/libnix/sources/headers/stdio.h +++ b/libnix/sources/headers/stdio.h @@ -1,9 +1,8 @@ -#ifndef STDIO_H -#define STDIO_H -#include +#ifndef _HEADERS_STDIO_H +#define _HEADERS_STDIO_H #include +#include #include -#include /* Adjusted to be compatible with the bsd headers * (At least for normal ANSI stuff) @@ -19,15 +18,17 @@ typedef struct __FILE int outcount; /* Space left in buffer for writing + fp->linebufsize, * readmode: 0 */ - short flags; /* Some flags: 0x01 line buffered - * 0x02 unbuffered - * 0x04 read mode - * 0x08 write mode - * 0x20 EOF read - * 0x40 error encountered - * 0x80 buffer malloc'ed by library - * 0x200 sprintf/sscanf buffer - */ + short flags; +#define __SLBF 0x0001 /* line buffered */ +#define __SNBF 0x0002 /* unbuffered */ +#define __SRD 0x0004 /* read mode */ +#define __SWR 0x0008 /* write mode */ +#define __SEOF 0x0020 /* EOF read */ +#define __SERR 0x0040 /* error encountered */ +#define __SMBF 0x0080 /* buffer malloc'ed by library */ +#define __SSTR 0x0200 /* sprintf/sscanf buffer */ +#define __SWO 0x8000 /* write-only mode */ + short file; /* The filehandle */ unsigned char *buffer; /* original buffer pointer */ int bufsize; /* size of the buffer */ @@ -59,6 +60,7 @@ typedef struct __FILE extern FILE *fopen(const char *filename,const char *mode); extern FILE *freopen(const char *filename,const char *mode,FILE *stream); +extern FILE *fdopen(int filedes,const char *mode); extern int fclose(FILE *stream); extern int fgetc(FILE *stream); extern int fputc(int c,FILE *stream); @@ -74,11 +76,13 @@ extern int vfscanf(FILE *stream,const char *format,va_list args); extern int snprintf(char *s,size_t size,const char *format,...); extern int vsnprintf(char *s,size_t size,const char *format,va_list args); extern int fseek(FILE *stream,long int offset,int whence); +extern char *fgets(char *s,int size,FILE *stream); extern int fputs(const char *s,FILE *stream); -extern long int ftell(FILE *stream); -extern int setvbuf(FILE *stream,char *buf,int mode,unsigned long size); -extern int fread(void *,unsigned long,unsigned long,FILE *); -extern int fwrite(const void *,unsigned long,unsigned long,FILE *); +extern void rewind(FILE *stream); +extern long ftell(FILE *stream); +extern int setvbuf(FILE *stream,char *buf,int mode,size_t size); +extern int fread(void *,size_t,size_t,FILE *); +extern int fwrite(const void *,size_t,size_t,FILE *); /* More bsd headers compatibility */ @@ -91,26 +95,92 @@ extern FILE **__sF; /* Standard I/O streams */ /* Be careful: We have side effects and use incount in __srget - must use comma-operator */ -#define getc(fp) ((fp)->incount--,(fp)->incount>=0?(int)*(fp)->p++:__srget(fp)) +#define getc(fp) ((fp)->incount-=1,(fp)->incount>=0?(int)*(fp)->p++:__srget(fp)) #define putc(c,fp) \ -((fp)->outcount--,(fp)->outcount>=0|| \ +((fp)->outcount-=1,(fp)->outcount>=0|| \ ((fp)->outcount>=(fp)->linebufsize&&(char)(c)!='\n')? \ *(fp)->p++=(c):__swbuf((c),(fp))) -#define ferror(fp) ((fp)->flags&64) -#define feof(fp) ((fp)->flags&32) +#define ferror(fp) ((fp)->flags&__SERR) +#define feof(fp) ((fp)->flags&__SEOF) /* own stuff */ extern struct MinList __filelist; /* List of all fopen'ed files */ -extern unsigned long *__stdfiledes; /* List of Amiga OS filehandles */ extern struct MinList __memorylist; /* List of memory puddles */ extern int __fflush(FILE *stream); /* fflush single file */ extern void __chkabort(void); /* check for SIGABRT */ -struct filenode /* objects in __filelist */ -{ +/* objects in __filelist */ +struct filenode { struct MinNode node; FILE FILE; }; -#endif +/* +** FILE/SOCKET abstraction layer +*/ + +#ifndef _SOCKET_IO + +typedef struct _StdFileDes { + long lx_fh; + int lx_pos; /* __stdfiledes[lx_pos]; */ + int lx_inuse; + int lx_oflags; + char lx_isatty; + char lx_sys; +} StdFileDes; + +#else + +#include +#include + +struct stat; + +typedef enum {LX_FILE,LX_SOCKET} LX_FILE_TYPE; + +typedef struct _StdFileDes { + LX_FILE_TYPE lx_type; + int lx_pos; /* __stdfiledes[lx_pos]; */ + int lx_inuse; + union { + struct { + int lx_oflags; + long lx_fh; + char lx_isatty; + char lx_sys,lx_pad[2]; + struct StandardPacket *lx_packet; + } file; + struct { + int lx_sock; + int lx_family; + int lx_protocol; + int lx_domain; + } sock; + } fd; +#define lx_oflags fd.file.lx_oflags +#define lx_fh fd.file.lx_fh +#define lx_isatty fd.file.lx_isatty +#define lx_sys fd.file.lx_sys +#define lx_packet fd.file.lx_packet +#define lx_sock fd.sock.lx_sock +#define lx_family fd.sock.lx_family +#define lx_protocol fd.sock.lx_protocol +#define lx_domain fd.sock.lx_domain + + ssize_t (*lx_read)(struct _StdFileDes *,void *,size_t); + ssize_t (*lx_write)(struct _StdFileDes *,const void *,size_t); + int (*lx_close)(struct _StdFileDes *); + int (*lx_dup)(struct _StdFileDes *); + int (*lx_fstat)(struct _StdFileDes *,struct stat *); + int (*lx_select)(struct _StdFileDes *sfd,int select_cmd,int io_mode,fd_set *,u_long *); +} StdFileDes; + +extern StdFileDes *_lx_fdfromfh(int fh, LX_FILE_TYPE type); + +#endif /* _SOCKET_IO */ + +extern StdFileDes *_lx_fhfromfd(int fd); + +#endif /* _HEADERS_STDIO_H */ diff --git a/libnix/sources/headers/strsup.h b/libnix/sources/headers/strsup.h index d581337..21ecd09 100755 --- a/libnix/sources/headers/strsup.h +++ b/libnix/sources/headers/strsup.h @@ -6,7 +6,11 @@ #ifdef __OPTIMIZE__ extern __inline__ void *memcpy(void *s1,const void *s2,size_t n) -{ register char *a6 __asm("a6") = *(char **)4; +{ + #ifndef __NOLIBBASE__ + extern struct ExecBase *SysBase; + #endif + register char *a6 __asm("a6") = (char *)SysBase; register const void *a0 __asm("a0") = s2; register const void *a1 __asm("a1") = s1; register size_t d0 __asm("d0") = n; @@ -14,26 +18,26 @@ extern __inline__ void *memcpy(void *s1,const void *s2,size_t n) : /* no output */ : "r" (a6), "r" (a0), "r" (a1), "r" (d0) : "a0","a1","d0","d1", "memory"); - return s1; } extern __inline__ void *memmove(void *s1,const void *s2,size_t n) { extern void bcopy(); + bcopy(s2,s1,n); return s1; } extern __inline__ void *memset(void *s,int c,size_t n) { if (n) { - unsigned char *p=s; + unsigned char *p=(unsigned char *)s; do;while(*p++=c,--n); } return s; } extern __inline__ int memcmp(const void *s1,const void *s2,size_t n) -{ const unsigned char *p1=s1,*p2=s2; +{ const unsigned char *p1=(const unsigned char *)s1,*p2=(const unsigned char *)s2; unsigned long r,c; if ((r=n)) @@ -148,7 +152,7 @@ extern __inline__ char *strlwr(char *s) return s; } -extern __inline__ char *stpcpy(char *dst,char *src) +extern __inline__ char *stpcpy(char *dst,const char *src) { do;while((*dst++=*src++)); return(--dst); } diff --git a/libnix/sources/history b/libnix/sources/history index 64807f5..ae8107a 100755 --- a/libnix/sources/history +++ b/libnix/sources/history @@ -68,7 +68,7 @@ B Symbol redirections didn't work the way I expected - removed most of them. B -lm links libm.a BEFORE libnix. Moved some functions. -B vfscanf() does no longer ungetc EOF +B vfscanf() does no longer ungetc EOF. M Optimized __udivsi3, __umodsi3, __divsi3, __modsi3, div, ldiv. @@ -158,7 +158,7 @@ B LocaleBase was defined twice - fixed. B Moved __decimalpoint from libm.a into libnix.a. -F Added 3.1 system libraries to libstubs.a +F Added 3.1 system libraries to libstubs.a. F Added Un*x functions (mkdir,chdir,rmdir,getwd,getcwd,opendir,readdir,closedir) @@ -262,6 +262,7 @@ F Added CPU check with error requester for the non-68000 versions (changed startups, too). V1.1 + F cache flush function for gcc support added B fixed a macro in stabs.h for shared library support @@ -276,13 +277,13 @@ V1.1a B fixed "off-by-one" error of portable strncpy() -B fixed open() so that it ignores stdio slots now +B fixed open() to ignore stdio slots now V1.1b B fixed longjmp() not returning 1 if passed a 0 -M changed automatic library opening once again ;( +M changed automatic library opening once again ;-( (moved openliberror() function into __initlibraries source) P tweaked string functions and removed some asm versions @@ -296,7 +297,8 @@ S added some const qualifiers at several places F tweaked libamiga.a functions -F rewrote libinit.c, libinitr.c and devinit.c (requires ADE/GG GCC 2.7.2.1 or up) +F rewrote libinit.c, libinitr.c and devinit.c + (requires ADE/GG GCC 2.7.2.1 or up) F added three math functions from vc.lib: frexp.c, ldexp.c and modf.c @@ -306,3 +308,64 @@ S added "/WAIT" to default stdiowin options (suggested by Martin Hauner) V1.2 + +S updated headers/strsup.h once again + +F added fdopen() (required changes in freopen()) + +B fixed auto-initilization of init_stk.c + (broken since 1.2) + +B fixed bug in mktime() (tm_mday starts with 1!) + (reported by Detlef Wuerkner) + +S modified rename() according to man-page + +S __seterrno() does map rename() error now + (was disabled!?) + +V1.3 + +F added networking support based on initial work by Jeff Sheperd + (supports AmiTCP and AS225 compatible stacks) + +B strftime() formats for date and date/time were swapped + (apparently this was due to an outdated manpage...) + +B fixed incorrect types usage with proper system types + (makes the library better prepared for PPC ;-) + +P improved memset(), bcopy() and bzero() + (hopefully ;-) + +B fixed (harmless?) bug in freopen() open mode handling + (did only handle rwa[b]+ but not rwa+[b]) + +B fixed append filemode to really write at end of file only + +S changed fdopen() to be independed from freopen() + +S stdin/stdout/stderr initialization now use fdopen() + (-> removed freopen()'s stdio open kludge) + +S adapted chmod() to return success if SetProtection + fails because source is locked + +F finally rewrote devinit.c to use GCC 2.7.2.1 features + (now in sync with libinit.c/libinitr.c) + +B fixed Makefiles for case sensitives filesystems, cross + compilation support (dosesn't use ar directly anymore) + and proper $(MAKE) handling + +B fixed hole in math/Makefile.in :-( + (didn't reference *all* objects leading to vfprint/vfscanf) + +F added a better and more general debug scheme + +F added gettimeofday() from libnixPPC package + +S general code cleanup + (eg. replaced all numerical stdio flags with #defines) + +V2.0 diff --git a/libnix/sources/math/Makefile.in b/libnix/sources/math/Makefile.in index a1d2653..e85d436 100644 --- a/libnix/sources/math/Makefile.in +++ b/libnix/sources/math/Makefile.in @@ -4,11 +4,12 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### @@ -18,17 +19,17 @@ endif CURDIR = $(shell pwd) -OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers -DFULL_SPECIFIERS $(CFLAGS) - -SOURCEFILES=*/* +OPTIONS=-I$(srcdir)/../headers -DFULL_SPECIFIERS $(CFLAGS) OBJECTS2=$(OBJECTS) \ + ../nix/assert/__eprintf.o \ ../nix/stdio/printf.o ../nix/stdio/fprintf.o ../nix/stdio/sprintf.o \ ../nix/stdio/vprintf.o ../nix/stdio/vsprintf.o stdio/vfprintf.o \ ../nix/stdio/scanf.o ../nix/stdio/fscanf.o ../nix/stdio/sscanf.o \ - ../nix/stdio/vscanf.o ../nix/stdio/vsscanf.o stdio/vfscanf.o + ../nix/stdio/vscanf.o ../nix/stdio/vsscanf.o stdio/vfscanf.o \ + ../nix/stdio/tmpfile.o ../nix/stdio/tmpnam.o -SUBDIRS2=$(SUBDIRS) ../nix/stdio +SUBDIRS2=$(SUBDIRS) ../nix/assert ../nix/stdio REDEF=-D_DOSBase=___DOSBase \ -D_UtilityBase=___UtilityBase \ @@ -58,9 +59,9 @@ veryclean: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)): mkdir $@ -libm.a: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)) $(OBJECTS2) ../../sources/math/makefile ../../sources/math/filelist +libm.a: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)) $(OBJECTS2) ../../sources/math/Makefile ../../sources/math/filelist -rm -f $@ - ar -q $@ $(OBJECTS2) + $(AR) -q $@ $(OBJECTS2) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/misc/Makefile.in b/libnix/sources/misc/Makefile.in index d4bd924..eeec0a5 100644 --- a/libnix/sources/misc/Makefile.in +++ b/libnix/sources/misc/Makefile.in @@ -4,17 +4,18 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### OBJECTS=detach.o swapstack.o -OPTIONS=-I $(srcdir)/../headers -I../../sources/headers $(CFLAGS) +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) vpath %.c $(SOURCEDIR) diff --git a/libnix/sources/misc/detach.c b/libnix/sources/misc/detach.c index 94b4034..0d9344f 100755 --- a/libnix/sources/misc/detach.c +++ b/libnix/sources/misc/detach.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "stabs.h" /* Sorry, but the assembler code produced by gcc for this function is too bad. * This one is much better! diff --git a/libnix/sources/nix/Makefile.in b/libnix/sources/nix/Makefile.in index 6a3b25c..9342a72 100644 --- a/libnix/sources/nix/Makefile.in +++ b/libnix/sources/nix/Makefile.in @@ -4,11 +4,12 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### @@ -18,9 +19,7 @@ endif CURDIR = $(shell pwd) -OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers $(CFLAGS) - -SOURCEFILES=*/* +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) REDEF=-D_DOSBase=___DOSBase \ -D_UtilityBase=___UtilityBase \ @@ -50,8 +49,8 @@ veryclean: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)): mkdir $@ -libnix.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) ../../sources/nix/makefile ../../sources/nix/filelist +libnix.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) ../../sources/nix/Makefile ../../sources/nix/filelist -rm -f $@ - ar -q $@ $(OBJECTS) + $(AR) -q $@ $(OBJECTS) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/nix/errno/__seterrno.c b/libnix/sources/nix/errno/__seterrno.c index b79207c..7349397 100755 --- a/libnix/sources/nix/errno/__seterrno.c +++ b/libnix/sources/nix/errno/__seterrno.c @@ -4,10 +4,7 @@ /* Table to convert amigados error messages to unix ones */ -extern int errno; - -static long _errortable[]= -{ +static long _errortable[] = { ERROR_NO_FREE_STORE ,ENOMEM, ERROR_TASK_TABLE_FULL ,EPROCLIM, /*ERROR_BAD_TEMPLATE @@ -32,7 +29,7 @@ static long _errortable[]= ERROR_OBJECT_WRONG_TYPE*/ ERROR_DISK_NOT_VALIDATED ,EBUSY, ERROR_DISK_WRITE_PROTECTED ,EROFS, -/*ERROR_RENAME_ACROSS_DEVICES*/ + ERROR_RENAME_ACROSS_DEVICES ,EXDEV, ERROR_DIRECTORY_NOT_EMPTY ,ENOTEMPTY, ERROR_TOO_MANY_LEVELS ,ENAMETOOLONG, ERROR_DEVICE_NOT_MOUNTED ,ENXIO, @@ -56,22 +53,13 @@ static long _errortable[]= ERROR_BUFFER_OVERFLOW ERROR_BREAK*/ ERROR_NOT_EXECUTABLE ,EACCES, - 0 + 0 ,EPERM }; void __seterrno(void) -{ - long amigaerror; - long *ptr=_errortable; - amigaerror=IoErr(); - while(*ptr) - { - if(*ptr++==amigaerror) - { - errno=*ptr; - return; - } - ptr++; - } - errno=EPERM; +{ long amigaerror=IoErr(),*ptr=_errortable,err; + + while((err=*ptr++)&&(err!=amigaerror)) + ++ptr; + errno=*ptr; } diff --git a/libnix/sources/nix/extra/__amigapath.c b/libnix/sources/nix/extra/__amigapath.c index d2e45d8..065d5e6 100755 --- a/libnix/sources/nix/extra/__amigapath.c +++ b/libnix/sources/nix/extra/__amigapath.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include "stabs.h" static int __pathconv; diff --git a/libnix/sources/nix/extra/access.c b/libnix/sources/nix/extra/access.c index acb2c13..caba52c 100755 --- a/libnix/sources/nix/extra/access.c +++ b/libnix/sources/nix/extra/access.c @@ -1,7 +1,7 @@ -#include -#include #include #include +#include +#include extern void __seterrno(void); extern char *__amigapath(const char *path); diff --git a/libnix/sources/nix/extra/bcmp.c b/libnix/sources/nix/extra/bcmp.c index 3317fbb..8a9a413 100755 --- a/libnix/sources/nix/extra/bcmp.c +++ b/libnix/sources/nix/extra/bcmp.c @@ -1,3 +1,3 @@ -#include +#include "stabs.h" ALIAS(bcmp,memcmp); diff --git a/libnix/sources/nix/extra/chdir.c b/libnix/sources/nix/extra/chdir.c index fc2b14c..a46ed52 100755 --- a/libnix/sources/nix/extra/chdir.c +++ b/libnix/sources/nix/extra/chdir.c @@ -1,7 +1,7 @@ -#include #include #include -#include +#include +#include "stabs.h" extern void __seterrno(void); diff --git a/libnix/sources/nix/extra/chmod.c b/libnix/sources/nix/extra/chmod.c index fc28af6..580048a 100755 --- a/libnix/sources/nix/extra/chmod.c +++ b/libnix/sources/nix/extra/chmod.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -7,23 +8,21 @@ extern void __seterrno(void); extern char *__amigapath(const char *path); int chmod(const char *name, mode_t mode) -{ int ret; - +{ #ifdef IXPATHS if((name=__amigapath(name))==NULL) return -1; #endif - - if ((ret=~(SetProtection((STRPTR)name,((mode&S_IRUSR?0:FIBF_READ)| - (mode&S_IWUSR?0:FIBF_WRITE|FIBF_DELETE)| - (mode&S_IXUSR?0:FIBF_EXECUTE)| - (mode&S_IRGRP?FIBF_GRP_READ:0)| - (mode&S_IWGRP?FIBF_GRP_WRITE|FIBF_GRP_DELETE:0)| - (mode&S_IXGRP?FIBF_GRP_EXECUTE:0)| - (mode&S_IROTH?FIBF_OTR_READ:0)| - (mode&S_IWOTH?FIBF_OTR_WRITE|FIBF_OTR_DELETE:0)| - (mode&S_IXOTH?FIBF_OTR_EXECUTE:0)))))) - __seterrno(); - - return ret; + if(!SetProtection((STRPTR)name,((mode&S_IRUSR?0:FIBF_READ)| + (mode&S_IWUSR?0:FIBF_WRITE|FIBF_DELETE)| + (mode&S_IXUSR?0:FIBF_EXECUTE)| + (mode&S_IRGRP?FIBF_GRP_READ:0)| + (mode&S_IWGRP?FIBF_GRP_WRITE|FIBF_GRP_DELETE:0)| + (mode&S_IXGRP?FIBF_GRP_EXECUTE:0)| + (mode&S_IROTH?FIBF_OTR_READ:0)| + (mode&S_IWOTH?FIBF_OTR_WRITE|FIBF_OTR_DELETE:0)| + (mode&S_IXOTH?FIBF_OTR_EXECUTE:0)))) + if(__seterrno(),errno!=ETXTBSY) + return -1; + return 0; } diff --git a/libnix/sources/nix/extra/creat.c b/libnix/sources/nix/extra/creat.c index f8c5181..020b1f1 100755 --- a/libnix/sources/nix/extra/creat.c +++ b/libnix/sources/nix/extra/creat.c @@ -1,7 +1,5 @@ #include -extern void __seterrno(void); - int creat(const char *path, mode_t mode) { return open(path, O_CREAT | O_TRUNC | O_WRONLY, mode); diff --git a/libnix/sources/nix/extra/dirent.c b/libnix/sources/nix/extra/dirent.c index 68f0926..6ca3a0d 100755 --- a/libnix/sources/nix/extra/dirent.c +++ b/libnix/sources/nix/extra/dirent.c @@ -1,29 +1,24 @@ #include #include +#include #include #include #include #include DIR *opendir(const char *dirname) -{ - DIR *dirp; +{ DIR *dirp; - if ((dirp=(DIR *)AllocVec(sizeof(DIR),MEMF_PUBLIC)) != NULL) - { - if ((dirp->d_lock=(Lock((STRPTR)dirname,SHARED_LOCK))) != 0ul) - { + if ((dirp=(DIR *)AllocVec(sizeof(DIR),MEMF_PUBLIC)) != NULL) { + if ((dirp->d_lock=(Lock((STRPTR)dirname,SHARED_LOCK))) != 0ul) { dirp->d_count=0; dirp->d_more = DOSTRUE; - - if ((dirp->d_eac=AllocDosObject(DOS_EXALLCONTROL,NULL)) != NULL) - { + if ((dirp->d_eac=AllocDosObject(DOS_EXALLCONTROL,NULL)) != NULL) { #if 0 dirp->d_eac->eac_LastKey=0; dirp->d_eac->eac_MatchString=NULL; dirp->d_eac->eac_MatchFunc=NULL; #endif - if (Examine(dirp->d_lock,&dirp->d_info)) - { + if (Examine(dirp->d_lock,&dirp->d_info)) { if (dirp->d_info.fib_EntryType>=0) return dirp; } @@ -37,20 +32,15 @@ DIR *opendir(const char *dirname) } struct dirent *readdir(DIR *dirp) -{ - struct dirent *result; +{ struct dirent *result; - if (dirp->d_count==0 && dirp->d_more!=DOSFALSE) - { + if (!dirp->d_count && dirp->d_more!=DOSFALSE) { dirp->d_more=ExAll(dirp->d_lock,(APTR)&dirp->d_ead[0],sizeof(dirp->d_ead),ED_NAME,dirp->d_eac); dirp->current=(struct ExAllData *)&dirp->d_ead[0]; dirp->d_count=dirp->d_eac->eac_Entries; } - result = NULL; - - if (dirp->d_count) - { + if (result=NULL,dirp->d_count) { dirp->dd_ent.d_fileno = dirp->dd_ent.d_reclen = 1; strcpy(dirp->dd_ent.d_name,dirp->current->ed_Name); dirp->dd_ent.d_namlen = strlen(dirp->dd_ent.d_name); @@ -58,16 +48,16 @@ struct dirent *readdir(DIR *dirp) dirp->d_count--; result=&dirp->dd_ent; } + return result; } void rewinddir(DIR *dirp) { if (dirp->d_more!=DOSFALSE) - do - { - dirp->d_more=ExAll(dirp->d_lock,(APTR)&dirp->d_ead[0],sizeof(dirp->d_ead),ED_NAME,dirp->d_eac); - } + do { + dirp->d_more=ExAll(dirp->d_lock,(APTR)&dirp->d_ead[0],sizeof(dirp->d_ead),ED_NAME,dirp->d_eac); + } while(dirp->d_more!=DOSFALSE); dirp->d_count=0; dirp->d_more = DOSTRUE; dirp->d_eac->eac_LastKey=0; } diff --git a/libnix/sources/nix/extra/fdtofh.c b/libnix/sources/nix/extra/fdtofh.c index 37b4e8b..9916660 100755 --- a/libnix/sources/nix/extra/fdtofh.c +++ b/libnix/sources/nix/extra/fdtofh.c @@ -6,9 +6,8 @@ * It's not ANSI but it's encapsulated and may be useful - so why not :-). * */ -unsigned long *__stdfiledes; -unsigned long fdtofh(int filedescriptor) -{ - return __stdfiledes[filedescriptor]; -} +#include "stdio.h" + +long fdtofh(int filedescriptor) +{ return _lx_fhfromfd(filedescriptor)->lx_fh; } diff --git a/libnix/sources/nix/extra/fstat.c b/libnix/sources/nix/extra/fstat.c index d1d0b6a..d8be805 100755 --- a/libnix/sources/nix/extra/fstat.c +++ b/libnix/sources/nix/extra/fstat.c @@ -2,46 +2,39 @@ #include #include #include -#include +#include +#include extern void __seterrno(void); -extern int __stat(struct stat *buf,struct FileInfoBlock *fib); - -extern unsigned long *__stdfiledes; - int fstat(int d,struct stat *buf) -{ +{ extern int __stat(struct stat *buf,struct FileInfoBlock *fib); #if defined (__GNUC__) #undef DOS_BASE_NAME #define DOS_BASE_NAME dosbase - struct DosLibrary *dosbase = DOSBase; + register APTR dosbase __asm("a6") = DOSBase; #endif + StdFileDes *fp = _lx_fhfromfd(d); struct FileInfoBlock *fib; - LONG pos,len; - BPTR fh; + LONG pos,len,fh; - if (/*dlx_fh)) { + if ((fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL)) == NULL) { __seterrno(); return -1; } - else - return -1; + } else return -1; - memset(buf,0,sizeof(struct stat)); + memset(buf,0,sizeof(*buf)); buf->st_mode = S_IFCHR | 0777; buf->st_nlink = 1; buf->st_blksize = 512; /*buf->st_blocks = 0;*/ - if (((struct FileHandle *)BADDR(fh))->fh_Type != NULL) - { - if (!ExamineFH(fh,fib)) - { + if (((struct FileHandle *)BADDR(fh))->fh_Type) { + + if (!ExamineFH(fh,fib)) { + len = 0; pos = Seek(fh,0,OFFSET_END); if (pos >= 0 && (IoErr() != ERROR_ACTION_NOT_KNOWN)) len = Seek(fh,pos,OFFSET_BEGINNING); @@ -50,14 +43,13 @@ int fstat(int d,struct stat *buf) fib->fib_DirEntryType = -1; fib->fib_Size = len; fib->fib_Protection = 0xff0; - fib->fib_NumBlocks = ((len + 511) >> 9); + fib->fib_NumBlocks = (len+=511,len>>=9); DateStamp(&fib->fib_Date); } __stat(buf,fib); - Seek(fh,0,OFFSET_CURRENT); - if (IoErr()) + if (Seek(fh,0,OFFSET_CURRENT),IoErr()) buf->st_mode = ((buf->st_mode & ~S_IFREG) | S_IFCHR); } diff --git a/libnix/sources/nix/extra/getrusage.c b/libnix/sources/nix/extra/getrusage.c index f172d61..877a353 100755 --- a/libnix/sources/nix/extra/getrusage.c +++ b/libnix/sources/nix/extra/getrusage.c @@ -2,8 +2,9 @@ #include #include #include +#include #include -#include +#include "stabs.h" extern void timer(long *); diff --git a/libnix/sources/nix/extra/gettimeofday.c b/libnix/sources/nix/extra/gettimeofday.c new file mode 100644 index 0000000..b43075a --- /dev/null +++ b/libnix/sources/nix/extra/gettimeofday.c @@ -0,0 +1,31 @@ +#include +#include +#include + +extern long __gmtoffset; + +int gettimeofday(struct timeval *tv, struct timezone *tzp) +{ + if (tv) { + struct DateStamp t; + DateStamp(&t); /* Get timestamp */ + tv->tv_sec=((t.ds_Days+2922)*1440+t.ds_Minute+__gmtoffset)*60+ + t.ds_Tick/TICKS_PER_SECOND; + tv->tv_usec=(t.ds_Tick%TICKS_PER_SECOND)*1000000/TICKS_PER_SECOND; + } + if (tzp) { + /* since AmigaOS doesn't support timezones, we always return + * GMT... + */ + tzp->tz_minuteswest = 0; + tzp->tz_dsttime = 0; + } + + return 0; +} + +/* + * 2922 is the number of days between 1.1.1970 and 1.1.1978 (2 leap years and 6 normal) + * 1440 is the number of minutes per day + * 60 is the number of seconds per minute + */ diff --git a/libnix/sources/nix/extra/mkdir.c b/libnix/sources/nix/extra/mkdir.c index df88a13..597e852 100755 --- a/libnix/sources/nix/extra/mkdir.c +++ b/libnix/sources/nix/extra/mkdir.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include "stabs.h" extern void __seterrno(void); diff --git a/libnix/sources/nix/extra/mktemp.c b/libnix/sources/nix/extra/mktemp.c index a4703fc..80d983e 100755 --- a/libnix/sources/nix/extra/mktemp.c +++ b/libnix/sources/nix/extra/mktemp.c @@ -1,25 +1,25 @@ #include -#include #include -#include "strsup.h" char *mktemp(char *buf) -{ - long pid = (long)FindTask(0L); - char *c = buf + strlen(buf); +{ long pid = (long)FindTask(0L); + char *c = buf; - while (*--c == 'X') { + while(*c++); --c; + + while(*--c == 'X') { *c = pid % 10 + '0'; pid /= 10; } - c++; - if (*c) { + + if (++c,*c) { for(*c='A'; *c <= 'Z'; (*c)++) { - if (access(buf, 0)) { + if (access(buf,0)) { return buf; } } *c = 0; } + return buf; } diff --git a/libnix/sources/nix/extra/rmdir.c b/libnix/sources/nix/extra/rmdir.c index 9645553..ba9b2b9 100755 --- a/libnix/sources/nix/extra/rmdir.c +++ b/libnix/sources/nix/extra/rmdir.c @@ -1,3 +1,3 @@ -#include +#include "stabs.h" ALIAS(rmdir,remove); diff --git a/libnix/sources/nix/extra/setbuffer.c b/libnix/sources/nix/extra/setbuffer.c index 43e5185..bf1ba61 100755 --- a/libnix/sources/nix/extra/setbuffer.c +++ b/libnix/sources/nix/extra/setbuffer.c @@ -1,5 +1,4 @@ #include -#include -int setbuffer(FILE *stream,char *buf,size_t size) -{ return setvbuf(stream,buf,buf!=NULL?_IOFBF:_IONBF,size); } +void setbuffer(FILE *stream,char *buf,size_t size) +{ (void)setvbuf(stream,buf,buf?_IOFBF:_IONBF,size); } diff --git a/libnix/sources/nix/extra/setlinebuf.c b/libnix/sources/nix/extra/setlinebuf.c index 8396655..3206b93 100755 --- a/libnix/sources/nix/extra/setlinebuf.c +++ b/libnix/sources/nix/extra/setlinebuf.c @@ -1,6 +1,4 @@ #include -int setlinebuf(FILE *f) -{ - return setvbuf(f, NULL, _IOLBF, 0); -} +int setlinebuf(FILE *stream) +{ return setvbuf(stream,NULL,_IOLBF,0); } diff --git a/libnix/sources/nix/extra/stat.c b/libnix/sources/nix/extra/stat.c index 9fe5e3e..c50572f 100755 --- a/libnix/sources/nix/extra/stat.c +++ b/libnix/sources/nix/extra/stat.c @@ -3,7 +3,7 @@ #include #include #include -#include +#include "stabs.h" extern int __stat(struct stat *buf,struct FileInfoBlock *fib); extern void __seterrno(void); diff --git a/libnix/sources/nix/extra/stpcpy.c b/libnix/sources/nix/extra/stpcpy.c index 299ff30..7b16134 100755 --- a/libnix/sources/nix/extra/stpcpy.c +++ b/libnix/sources/nix/extra/stpcpy.c @@ -1,4 +1,6 @@ -char *stpcpy(char *dest,char *source) +#include + +char *stpcpy(char *dest,const char *source) { while((*dest++=*source++)); return(dest-1); } diff --git a/libnix/sources/nix/extra/strdup.c b/libnix/sources/nix/extra/strdup.c index 915ca0e..9887fd0 100755 --- a/libnix/sources/nix/extra/strdup.c +++ b/libnix/sources/nix/extra/strdup.c @@ -1,12 +1,10 @@ -#include #include +#include #include char *strdup(const char *s) -{ - char *s1; - - if ((s1=malloc(strlen_plus_one(s)))) +{ char *s1=malloc(strlen_plus_one(s)); + if (s1) strcpy(s1,s); return s1; } diff --git a/libnix/sources/nix/extra/stricmp.c b/libnix/sources/nix/extra/stricmp.c index 87d9880..1edf5e1 100755 --- a/libnix/sources/nix/extra/stricmp.c +++ b/libnix/sources/nix/extra/stricmp.c @@ -1,6 +1,6 @@ -#include #include -#include +#include +#include "stabs.h" int stricmp(const char *s1,const char *s2) { diff --git a/libnix/sources/nix/extra/strlower.c b/libnix/sources/nix/extra/strlower.c index b7f4de2..bd6d010 100755 --- a/libnix/sources/nix/extra/strlower.c +++ b/libnix/sources/nix/extra/strlower.c @@ -1,16 +1,14 @@ #include -#include +#include "stabs.h" char *strlower(char *s) -{ - unsigned char *s1; +{ unsigned char *s1; s1=(unsigned char *)s; - while(*s1) - { + while(*s1) { if (isupper(*s1)) *s1+='a'-'A'; - s1++; + ++s1; } return s; } diff --git a/libnix/sources/nix/extra/strnicmp.c b/libnix/sources/nix/extra/strnicmp.c index 13f46d4..ea22771 100755 --- a/libnix/sources/nix/extra/strnicmp.c +++ b/libnix/sources/nix/extra/strnicmp.c @@ -1,10 +1,9 @@ -#include #include -#include +#include +#include "stabs.h" int strnicmp(const char *s1,const char *s2,size_t len) { - return Strnicmp((STRPTR)s1,(STRPTR)s2,(LONG)len); } diff --git a/libnix/sources/nix/extra/strupper.c b/libnix/sources/nix/extra/strupper.c index 138765e..ab6c802 100755 --- a/libnix/sources/nix/extra/strupper.c +++ b/libnix/sources/nix/extra/strupper.c @@ -1,16 +1,14 @@ #include -#include +#include "stabs.h" char *strupper(char *s) -{ - unsigned char *s1; +{ unsigned char *s1; s1=(unsigned char *)s; - while(*s1) - { + while(*s1) { if (islower(*s1)) *s1-='a'-'A'; - s1++; + ++s1; } return s; } diff --git a/libnix/sources/nix/extra/times.c b/libnix/sources/nix/extra/times.c index 54ca8be..2f48fbd 100755 --- a/libnix/sources/nix/extra/times.c +++ b/libnix/sources/nix/extra/times.c @@ -1,35 +1,29 @@ -#include #include #include #include #include clock_t times(struct tms *tp) -{ - struct rusage r1, r2; - clock_t tim; - int status; +{ struct rusage r; + time_t tim; - status = getrusage(RUSAGE_SELF, &r1); - if (status != 0) { - return status; - } - status = getrusage(RUSAGE_CHILDREN, &r2); - if (status != 0) { - return status; - } + if (getrusage(RUSAGE_SELF, &r) < 0) + return (clock_t)-1; - tim = time(0L); - if (errno != 0) { - return tim; - } + tp->tms_utime = r.ru_utime.tv_sec * CLK_TCK + + (r.ru_utime.tv_usec * CLK_TCK) / 1000000; + tp->tms_stime = r.ru_stime.tv_sec * CLK_TCK + + (r.ru_stime.tv_usec * CLK_TCK) / 1000000; + + if (getrusage(RUSAGE_CHILDREN, &r) < 0) + return (clock_t)-1; - tp->tms_utime = r1.ru_utime.tv_sec * CLK_TCK + - (r1.ru_utime.tv_usec * CLK_TCK) /1000000; tp->tms_cutime = 0; - tp->tms_stime = r1.ru_stime.tv_sec * CLK_TCK + - (r1.ru_stime.tv_usec * CLK_TCK) / 1000000; tp->tms_cstime = 0; + + if ((tim=time(NULL)) == (time_t)-1) + return (clock_t)-1; + /* The value we are supposed to return does not fit in 32 bits. Still, it is useful if you are interested in time differences in CLK_TCKths of a second. diff --git a/libnix/sources/nix/extra/unlink.c b/libnix/sources/nix/extra/unlink.c index fc0877a..96f49c2 100755 --- a/libnix/sources/nix/extra/unlink.c +++ b/libnix/sources/nix/extra/unlink.c @@ -1,3 +1,3 @@ -#include +#include "stabs.h" ALIAS(unlink,remove); diff --git a/libnix/sources/nix/extra/utime.c b/libnix/sources/nix/extra/utime.c index 5c5d45c..53ab2b2 100755 --- a/libnix/sources/nix/extra/utime.c +++ b/libnix/sources/nix/extra/utime.c @@ -2,16 +2,15 @@ #include int utime(const char *file, const struct utimbuf *timep) -{ - struct timeval times[2],*t=NULL; +{ struct timeval times[2],*t=NULL; - if (timep != NULL) - { - t=×[0]; - t[0].tv_sec = timep->actime; + if (timep) { + t = ×[0]; + t[0].tv_sec = timep->actime; t[0].tv_usec = 0; - t[1].tv_sec = timep->modtime; + t[1].tv_sec = timep->modtime; t[1].tv_usec = 0; } - return utimes(file, t); + + return utimes(file,t); } diff --git a/libnix/sources/nix/extra/utimes.c b/libnix/sources/nix/extra/utimes.c index 5d7d51b..4098af5 100755 --- a/libnix/sources/nix/extra/utimes.c +++ b/libnix/sources/nix/extra/utimes.c @@ -5,18 +5,15 @@ #include #include -#define MAX(x,y) (((x) > (y)) ? (x) : (y)) - #define SECSPERDAY (24L * 60L * 60L) int utimes(const char *file, const struct timeval *times) -{ - struct timeval modtime; - struct DateStamp d; - time_t t; +{ struct DateStamp d; if (times) { - modtime = times[1]; + struct timeval modtime = times[1]; + time_t t; + if (modtime.tv_usec > 1000000) { modtime.tv_sec += (modtime.tv_usec / 1000000); modtime.tv_usec %= 1000000; diff --git a/libnix/sources/nix/locale/setlocale.c b/libnix/sources/nix/locale/setlocale.c index fe4bd0c..ca13474 100755 --- a/libnix/sources/nix/locale/setlocale.c +++ b/libnix/sources/nix/locale/setlocale.c @@ -1,18 +1,13 @@ -#include -#include -#include -#include -#include -#ifdef __GNUC__ /* This is very sad :-( */ -#undef BITSPERBYTE -#undef MAXINT -#undef MININT -#endif #include -#include +#include +#include +#include +#include +#include #include +#include #include -#include +#include "stabs.h" extern struct LocaleBase *LocaleBase; extern char __localename[]; diff --git a/libnix/sources/nix/math/__divsi3.c b/libnix/sources/nix/math/__divsi3.c index c5ae764..c66288b 100755 --- a/libnix/sources/nix/math/__divsi3.c +++ b/libnix/sources/nix/math/__divsi3.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .globl _div diff --git a/libnix/sources/nix/math/__eqdf2.c b/libnix/sources/nix/math/__eqdf2.c index aa37e76..d5167f4 100755 --- a/libnix/sources/nix/math/__eqdf2.c +++ b/libnix/sources/nix/math/__eqdf2.c @@ -1,5 +1,5 @@ #include -#include +#include "stabs.h" signed long __eqdf2(double x,double y) { return IEEEDPCmp(x,y); } diff --git a/libnix/sources/nix/math/__eqsf2.c b/libnix/sources/nix/math/__eqsf2.c index b5af8ec..adf4ca5 100755 --- a/libnix/sources/nix/math/__eqsf2.c +++ b/libnix/sources/nix/math/__eqsf2.c @@ -1,5 +1,5 @@ #include -#include +#include "stabs.h" signed long __eqsf2(float x,float y) { return IEEESPCmp(x,y); } diff --git a/libnix/sources/nix/math/__mulsi3.c b/libnix/sources/nix/math/__mulsi3.c index f870c89..126b769 100755 --- a/libnix/sources/nix/math/__mulsi3.c +++ b/libnix/sources/nix/math/__mulsi3.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .globl ___mulsi3 diff --git a/libnix/sources/nix/math/__udivsi3.c b/libnix/sources/nix/math/__udivsi3.c index 1220933..d26c00d 100755 --- a/libnix/sources/nix/math/__udivsi3.c +++ b/libnix/sources/nix/math/__udivsi3.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .globl ___umodsi3 diff --git a/libnix/sources/nix/misc/__request.c b/libnix/sources/nix/misc/__request.c index 23f7f0b..8741d2d 100755 --- a/libnix/sources/nix/misc/__request.c +++ b/libnix/sources/nix/misc/__request.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .data diff --git a/libnix/sources/nix/misc/bcopy.c b/libnix/sources/nix/misc/bcopy.c index 3141922..c99fa1d 100755 --- a/libnix/sources/nix/misc/bcopy.c +++ b/libnix/sources/nix/misc/bcopy.c @@ -1,36 +1,52 @@ #include -/* This is a _fast_ block move routine */ +/* This is a _fast_ block move routine! */ void bcopy(const void *s1,void *s2,size_t n) { size_t m; if(!n) return; if(s215) + { if((long)s1&1) + { *((char *)s2)++=*((char *)s1)++; + n--; } + if(!((long)s2&1)) + { if((long)s1&2) + { *((short *)s2)++=*((short *)s1)++; + n-=2; } + for(m=n/(8*sizeof(long));m;--m) + { *((long *)s2)++=*((long *)s1)++; *((long *)s2)++=*((long *)s1)++; + *((long *)s2)++=*((long *)s1)++; *((long *)s2)++=*((long *)s1)++; + *((long *)s2)++=*((long *)s1)++; *((long *)s2)++=*((long *)s1)++; + *((long *)s2)++=*((long *)s1)++; *((long *)s2)++=*((long *)s1)++; } + n&=8*sizeof(long)-1; + for(m=n/sizeof(long);m;--m) + *((long *)s2)++=*((long *)s1)++; + n&=sizeof(long)-1; } + if(!n) return; + } do;while(*((char *)s2)++=*((char *)s1)++,--n); }else { (char *)s1+=n; (char *)s2+=n; - if((long)s1&1) - { *--((char *)s2)=*--((char *)s1); - n--; } - if(!((long)s2&1)) - { m=n/sizeof(long); - n&=sizeof(long)-1; - for(;m;m--) - *--((long *)s2)=*--((long *)s1); - } - for(;n;n--) - *--((char *)s2)=*--((char *)s1); + if(n>15) + { if((long)s1&1) + { *--((char *)s2)=*--((char *)s1); + n--; } + if(!((long)s2&1)) + { if((long)s1&2) + { *--((short *)s2)=*--((short *)s1); + n-=2; } + for(m=n/(8*sizeof(long));m;--m) + { *--((long *)s2)=*--((long *)s1); *--((long *)s2)=*--((long *)s1); + *--((long *)s2)=*--((long *)s1); *--((long *)s2)=*--((long *)s1); + *--((long *)s2)=*--((long *)s1); *--((long *)s2)=*--((long *)s1); + *--((long *)s2)=*--((long *)s1); *--((long *)s2)=*--((long *)s1); } + n&=8*sizeof(long)-1; + for(m=n/sizeof(long);m;--m) + *--((long *)s2)=*--((long *)s1); + n&=sizeof(long)-1; } + if(!n) return; + } do;while(*--((char *)s2)=*--((char *)s1),--n); } } diff --git a/libnix/sources/nix/misc/bzero.c b/libnix/sources/nix/misc/bzero.c index 817770e..97065da 100755 --- a/libnix/sources/nix/misc/bzero.c +++ b/libnix/sources/nix/misc/bzero.c @@ -1,14 +1,23 @@ #include -void bzero(void *b,size_t len) -{ size_t n; - if((unsigned long)b&1) - { *((char *)b)++=0; - len--; } - n=len/sizeof(long); - len-=n*sizeof(long); - while(n--) - *((long *)b)++=0; - while(len--) - *((char *)b)++=0; +void bzero(void *b,size_t n) +{ size_t m; + if(!n) + return; + if(n>15) + { if((long)b&1) + { *((char *)b)++=0; + n--; } + if((long)b&2) + { *((short *)b)++=0; + n-=2; } + for(m=n/(8*sizeof(long));m;--m) + { *((long *)b)++=0; *((long *)b)++=0; *((long *)b)++=0; *((long *)b)++=0; + *((long *)b)++=0; *((long *)b)++=0; *((long *)b)++=0; *((long *)b)++=0; } + n&=8*sizeof(long)-1; + for(m=n/sizeof(long);m;--m) + *((long *)b)++=0; + if((n&=sizeof(long)-1)==0) return; + } + do;while(*((char *)b)++=0,--n); } diff --git a/libnix/sources/nix/stdio/__fflush.c b/libnix/sources/nix/stdio/__fflush.c index 083ef2d..9eda317 100755 --- a/libnix/sources/nix/stdio/__fflush.c +++ b/libnix/sources/nix/stdio/__fflush.c @@ -3,27 +3,23 @@ #include int __fflush(FILE *stream) /* fflush exactly one file */ -{ +{ unsigned char *subbuf; long size,subsize; - unsigned char *subbuf; - if(stream->flags&0x40) /* Error on stream */ + + if(stream->flags&__SERR) /* Error on stream */ { errno=EPERM; return EOF; } - if(stream->flags&8) /* Works only on output streams */ - { - size=stream->p-stream->buffer; /* calculate size */ + if(stream->flags&__SWR) /* Works only on output streams */ + { size=stream->p-stream->buffer; /* calculate size */ subbuf=stream->buffer; while(size) - { - if((subsize=write(stream->file,subbuf,size))<0) - { - stream->flags|=64; /* error flag */ - return EOF; - } + { if((subsize=write(stream->file,subbuf,size))<0) + { stream->flags|=__SERR; /* error flag */ + return EOF; } size-=subsize; subbuf+=subsize; } - stream->flags&=~8; /* unset write state */ + stream->flags&=~__SWR; /* unset write state */ stream->outcount=0; stream->linebufsize=0; } /* Nothing to be done for input streams */ diff --git a/libnix/sources/nix/stdio/__srget.c b/libnix/sources/nix/stdio/__srget.c index f260471..da0621b 100755 --- a/libnix/sources/nix/stdio/__srget.c +++ b/libnix/sources/nix/stdio/__srget.c @@ -4,13 +4,13 @@ int __srget(FILE *stream) /* Get next input block */ { - if(stream->flags&96) /* Error on stream / EOF */ + if(stream->flags&(__SERR|__SEOF)) /* Error on stream / EOF */ { stream->incount=0; errno=EPERM; return EOF; } - if(stream->flags&8) + if(stream->flags&__SWR) { if(__fflush(stream)) return EOF; @@ -22,28 +22,28 @@ int __srget(FILE *stream) /* Get next input block */ if(--stream->incount>=0) return *stream->p++; } - if(stream->flags&0x200) /* Is a sscanf buffer */ + if(stream->flags&__SSTR) /* it's a sscanf buffer */ return EOF; - if(stream->flags&3) /* Before reading from line- or unbuffered input file */ + if(stream->flags&(__SNBF|__SLBF)) /* Before reading from line- or unbuffered input file */ { /* fflush all line buffered output files (ANSI) */ struct filenode *fp=(struct filenode *)__filelist.mlh_Head; while(fp->node.mln_Succ) { - if((fp->FILE.flags&9)==9) + if((fp->FILE.flags&(__SWR|__SLBF))==(__SWR|__SLBF)) __fflush(&fp->FILE); /* Don't return EOF if this fails */ fp=(struct filenode *)fp->node.mln_Succ; } } - stream->flags|=4; + stream->flags|=__SRD; stream->incount=read(stream->file,stream->buffer,stream->bufsize); - if(stream->incount==0) /* EOF found */ + if(!stream->incount) /* EOF found */ { - stream->flags|=32; + stream->flags|=__SEOF; return EOF; }else if(stream->incount<0) /* Error */ { stream->incount=0; - stream->flags|=64; + stream->flags|=__SERR; return EOF; } stream->incount--; diff --git a/libnix/sources/nix/stdio/__stdio.c b/libnix/sources/nix/stdio/__stdio.c index 7a9aafe..a5fd85f 100755 --- a/libnix/sources/nix/stdio/__stdio.c +++ b/libnix/sources/nix/stdio/__stdio.c @@ -1,19 +1,23 @@ #include -#include +#include +#include +#include "stabs.h" static FILE *__files[3]; FILE **__sF=__files; /* stdin, stdout, stderr */ void __initstdfio(void) -{ FILE **f=__sF; +{ FILE **f=__sF, *err; - if((*f++=fopen((char *)1,NULL))!=NULL) - if((*f++=fopen((char *)2,NULL))!=NULL) - if((*f=fopen((char *)3,NULL))!=NULL) - return; - exit(20); + if(((*f++=fdopen(STDIN_FILENO,"r"))==NULL)|| + ((*f++=fdopen(STDOUT_FILENO,"w"))==NULL)|| + ((*f=err=fdopen(STDERR_FILENO,"w"))==NULL)) + exit(20); + free(err->buffer); + err->flags&=~(__SMBF|__SLBF); err->flags|=__SNBF; + err->buffer=NULL; } /* Call our private constructor */ -ADD2INIT(__initstdfio,-10); +ADD2INIT(__initstdfio,-20); diff --git a/libnix/sources/nix/stdio/__swbuf.c b/libnix/sources/nix/stdio/__swbuf.c index 081fe19..ca7b3e0 100755 --- a/libnix/sources/nix/stdio/__swbuf.c +++ b/libnix/sources/nix/stdio/__swbuf.c @@ -2,24 +2,24 @@ #include int __swbuf(int c,FILE *stream) /* Get next output block */ -{ - int out,lbs; - if(stream->flags&0x240) /* sprintf buffer | error on stream */ +{ int out,lbs; + + if(stream->flags&(__SSTR|__SERR)) /* sprintf buffer | error on stream */ { stream->outcount=0; errno=EPERM; return EOF; - }else if(stream->flags&4) + }else if(stream->flags&__SRD) { stream->incount=0; /* throw away input buffer */ stream->tmpp=NULL; - stream->flags&=~4; + stream->flags&=~__SRD; } - lbs=stream->flags&_IOLBF?-stream->bufsize:0; - out=(stream->flags&_IONBF?0:stream->bufsize-1)+lbs; - if(!(stream->flags&8)) /* File wasn't in write mode */ + lbs=stream->flags&__SLBF?-stream->bufsize:0; + out=(stream->flags&__SNBF?0:stream->bufsize-1)+lbs; + if(!(stream->flags&__SWR)) /* File wasn't in write mode */ { stream->p=stream->buffer; /* set buffer */ stream->outcount=--out; /* and buffercount */ - stream->flags|=8; } /* and write mode */ + stream->flags|=__SWR; } /* and write mode */ *stream->p++=c; /* put this character */ if(stream->outcount<0&&(stream->outcountlinebufsize=lbs; stream->outcount=out; - stream->flags|=8; + stream->flags|=__SWR; return c; } diff --git a/libnix/sources/nix/stdio/clearerr.c b/libnix/sources/nix/stdio/clearerr.c index 958bae0..89e6631 100755 --- a/libnix/sources/nix/stdio/clearerr.c +++ b/libnix/sources/nix/stdio/clearerr.c @@ -1,4 +1,4 @@ #include void clearerr(FILE *stream) -{ stream->flags&=~96; } +{ stream->flags&=~(__SERR|__SEOF); } diff --git a/libnix/sources/nix/stdio/fdopen.c b/libnix/sources/nix/stdio/fdopen.c new file mode 100644 index 0000000..2ed8dc0 --- /dev/null +++ b/libnix/sources/nix/stdio/fdopen.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +#include + +FILE *fdopen(int filedes,const char *mode) +{ extern int _lx_addflags(int,int); + if (mode!=NULL) + { struct filenode *node = (struct filenode *)calloc(1,sizeof(*node)); + if(node!=NULL) + { if((node->FILE.buffer=(char *)malloc(BUFSIZ))!=NULL) + { node->FILE.bufsize=BUFSIZ; + node->FILE.file=filedes; + node->FILE.flags|=__SMBF; /* Buffer is malloc'ed */ + if(isatty(filedes)) + node->FILE.flags|=__SLBF; /* set linebuffered flag */ + if(_lx_addflags(filedes,*mode=='a'?O_APPEND:0)&O_WRONLY) + node->FILE.flags|=__SWO; /* set write-only flag */ + AddHead((struct List *)&__filelist,(struct Node *)&node->node); + return &node->FILE; + } + else + errno=ENOMEM; + free(node); + } + else + errno=ENOMEM; + } + return NULL; +} diff --git a/libnix/sources/nix/stdio/feof.c b/libnix/sources/nix/stdio/feof.c index 13d592f..9161607 100755 --- a/libnix/sources/nix/stdio/feof.c +++ b/libnix/sources/nix/stdio/feof.c @@ -1,8 +1,6 @@ #include -#ifdef feof #undef feof -#endif int feof(FILE *stream) -{ return (stream->flags&32)!=0; } +{ return (stream->flags&__SEOF)!=0; } diff --git a/libnix/sources/nix/stdio/ferror.c b/libnix/sources/nix/stdio/ferror.c index 46a21f3..b4e196c 100755 --- a/libnix/sources/nix/stdio/ferror.c +++ b/libnix/sources/nix/stdio/ferror.c @@ -1,8 +1,6 @@ #include -#ifdef ferror #undef ferror -#endif int ferror(FILE *stream) -{ return (stream->flags&64)!=0; } +{ return (stream->flags&__SERR)!=0; } diff --git a/libnix/sources/nix/stdio/fflush.c b/libnix/sources/nix/stdio/fflush.c index 94e97b6..71ccd01 100755 --- a/libnix/sources/nix/stdio/fflush.c +++ b/libnix/sources/nix/stdio/fflush.c @@ -1,11 +1,10 @@ #include -#include #include int fflush(FILE *stream) /* fflush one or all files */ -{ +{ struct MinNode *node,*nextnode; int retval; - struct MinNode *node,*nextnode; + if(stream!=NULL) return __fflush(stream); retval=0; diff --git a/libnix/sources/nix/stdio/fgets.c b/libnix/sources/nix/stdio/fgets.c index 7db7502..2ab9bfc 100755 --- a/libnix/sources/nix/stdio/fgets.c +++ b/libnix/sources/nix/stdio/fgets.c @@ -1,15 +1,12 @@ #include char *fgets(char *s,int n,FILE *stream) -{ - int c; - char *s2=s; +{ char *s2=s; + while(--n) - { - c=fgetc(stream); + { int c=fgetc(stream); if(c==EOF) - { - if(s2==s) + { if(s2==s) return NULL; break; } diff --git a/libnix/sources/nix/stdio/fileno.c b/libnix/sources/nix/stdio/fileno.c index e470ba8..dddba22 100755 --- a/libnix/sources/nix/stdio/fileno.c +++ b/libnix/sources/nix/stdio/fileno.c @@ -1,6 +1,4 @@ #include int fileno(FILE *file) -{ - return file->file; -} +{ return file->file; } diff --git a/libnix/sources/nix/stdio/fopen.c b/libnix/sources/nix/stdio/fopen.c index bb5b48a..bbac775 100755 --- a/libnix/sources/nix/stdio/fopen.c +++ b/libnix/sources/nix/stdio/fopen.c @@ -1,29 +1,24 @@ +#include #include #include /* If you use normal file I/O, the memory functions don't count that much on memory */ -#include -#include -#include #include -#include -#include +#include +#include "debuglib.h" +#include "stabs.h" -struct MinList __filelist= /* list of open files (fflush() needs also access) */ -{ +struct MinList __filelist = { /* list of open files (fflush() needs also access) */ (struct MinNode *)&__filelist.mlh_Tail, NULL, (struct MinNode *)&__filelist.mlh_Head }; FILE *fopen(const char *filename,const char *mode) -{ - struct filenode *node; - if((node=(struct filenode *)calloc(1,sizeof(struct filenode)))!=NULL) - { - if((node->FILE.buffer=(char *)malloc(BUFSIZ))!=NULL) - { - node->FILE.bufsize=BUFSIZ; - node->FILE.flags|=0x80; /* Buffer is malloc'ed */ +{ struct filenode *node = (struct filenode *)calloc(1,sizeof(*node)); + if(node!=NULL) + { if((node->FILE.buffer=(char *)malloc(BUFSIZ))!=NULL) + { node->FILE.bufsize=BUFSIZ; + node->FILE.flags|=__SMBF; /* Buffer is malloc'ed */ if(freopen(filename,mode,&node->FILE)!=NULL) { AddHead((struct List *)&__filelist,(struct Node *)&node->node); return &node->FILE; } @@ -39,18 +34,13 @@ FILE *fopen(const char *filename,const char *mode) } int fclose(FILE *stream) -{ - int retval=0; - struct filenode *node; - if(stream==NULL) - { -#ifdef DEBUG_LIB - FATALERROR("NULL pointer fclose'd\n"); -#endif - return EOF; - } +{ struct filenode *node; + int retval; + if(!stream) + { DB( BUG("NULL pointer fclose'd\n"); ) + return EOF; } retval=freopen(NULL,NULL,stream)==NULL?EOF:0; - if(stream->flags&0x80) /* Free buffer if necessary */ + if(stream->flags&__SMBF) /* Free buffer if necessary */ { free(stream->buffer); stream->buffer=NULL; } node=(struct filenode *)((struct MinNode *)stream-1); @@ -60,8 +50,7 @@ int fclose(FILE *stream) } void __exitstdfio(void) -{ - struct MinNode *node; +{ struct MinNode *node; while((node=__filelist.mlh_Head)->mln_Succ!=NULL) fclose(&((struct filenode *)node)->FILE); } diff --git a/libnix/sources/nix/stdio/fread.c b/libnix/sources/nix/stdio/fread.c index b3a061d..3ea2d42 100755 --- a/libnix/sources/nix/stdio/fread.c +++ b/libnix/sources/nix/stdio/fread.c @@ -24,7 +24,7 @@ int fread(void *ptr,size_t size,size_t nmemb,FILE *stream) { int c; if((c=__srget(stream))==EOF) - break; + break; *b++=c; total--; } diff --git a/libnix/sources/nix/stdio/freopen.c b/libnix/sources/nix/stdio/freopen.c index bd30b4a..c248318 100755 --- a/libnix/sources/nix/stdio/freopen.c +++ b/libnix/sources/nix/stdio/freopen.c @@ -1,81 +1,65 @@ #include #include -#include +#include #include +#include #include #include -#include extern void __seterrno(void); FILE *freopen(const char *filename,const char *mode,FILE *stream) -{ int error; - error=__fflush(stream); - if(stream->file>2) - { close(stream->file); - if(stream->name!=NULL) /* file is temporary */ - { BPTR cd; - cd=CurrentDir(stream->tmpdir); /* cd t: */ - if(!DeleteFile(stream->name)) /* delete file */ - { __seterrno(); - error=1; } - free(stream->name); /* free filename */ - stream->name=NULL; - UnLock(CurrentDir(cd)); /* cd back, unlock t: */ - } - stream->file=0l; +{ int error=__fflush(stream); + + close(stream->file); + if(stream->name!=NULL) /* file is temporary */ + { BPTR cd=CurrentDir(stream->tmpdir); /* cd t: */ + if(!DeleteFile(stream->name)) /* delete file */ + { __seterrno(); + error=1; } + free(stream->name); /* free filename */ + stream->name=NULL; + UnLock(CurrentDir(cd)); /* cd back, unlock t: */ } + stream->file=0; + if(error) return NULL; if(filename!=NULL) - { long file; - long flags=O_RDONLY; - int append=0,plus=1; - if(mode!=NULL) - { switch(mode[0]) - { - case 'r': - break; - case 'w': - flags=O_WRONLY|O_CREAT|O_TRUNC; - break; - case 'a': - flags=O_WRONLY|O_CREAT; - append=1; - break; - default: + { long file,flags=O_RDONLY; + char ch; + if(mode==NULL) + return NULL; + if(ch=*mode++,ch!='r') + if(flags=O_WRONLY|O_CREAT|O_TRUNC,ch!='w') + if(flags=O_WRONLY|O_CREAT|O_APPEND,ch!='a') return NULL; - } - if(mode[1]=='b') - plus=2; - switch(mode[plus]) - { - case '+': - flags=(flags&~O_ACCMODE)|O_RDWR; - if(mode[plus+1]) - return NULL; - break; - case '\0': - break; - default: + if((ch=*mode++)) + { if(ch=='+') + { if((ch=*mode++) && (ch!='b'||*mode)) return NULL; - } + flags=(flags&~O_ACCMODE)|O_RDWR; } + else if(ch!='b') + return NULL; + else if((ch=*mode++)) + { if(ch!='+'||*mode) + return NULL; + flags=(flags&~O_ACCMODE)|O_RDWR; } } - if((long)filename<4) - file=(long)filename-1; - else - if((file=open(filename,flags,0777))<0) - return NULL; - - if(append&&lseek(file,0,SEEK_END)<0) + if((file=open(filename,flags,0777))<0) return NULL; - stream->flags&=~0x6f; /* clear a lot of flags */ + if(flags&O_APPEND) + (void)lseek(file,0,SEEK_END); + + /* clear a lot of flags */ + stream->flags&=~(__SWO|__SERR|__SEOF|__SWR|__SRD|__SNBF|__SLBF); + if(flags&O_WRONLY) + stream->flags|=__SWO; /* set write-only flag */ if(isatty(file)) - stream->flags|=1; /* set linebuffered flag */ - + stream->flags|=__SLBF; /* set linebuffered flag */ stream->file=file; } diff --git a/libnix/sources/nix/stdio/fseek.c b/libnix/sources/nix/stdio/fseek.c index fbdf85c..a0bfd2d 100755 --- a/libnix/sources/nix/stdio/fseek.c +++ b/libnix/sources/nix/stdio/fseek.c @@ -4,21 +4,19 @@ int fseek(FILE *stream,long int offset,int whence) { - if(stream->flags&64) /* Error on stream */ + if(stream->flags&__SERR) /* Error on stream */ { errno=EPERM; return EOF; } - if(stream->flags&8) + if(stream->flags&__SWR) if(__fflush(stream)) return EOF; if(whence==SEEK_CUR) offset-=stream->incount+(stream->tmpp!=NULL?stream->tmpinc:0); stream->incount=0; stream->tmpp=NULL; - stream->flags&=~36; + stream->flags&=~(__SEOF|__SRD); if(lseek(stream->file,offset,whence)==EOF) - { - stream->flags|=64; - return EOF; - } + { stream->flags|=__SERR; + return EOF; } return 0; } diff --git a/libnix/sources/nix/stdio/fsetpos.c b/libnix/sources/nix/stdio/fsetpos.c index ddbfb44..820c1fc 100755 --- a/libnix/sources/nix/stdio/fsetpos.c +++ b/libnix/sources/nix/stdio/fsetpos.c @@ -1,5 +1,4 @@ #include int fgetpos(FILE *stream,fpos_t *pos) -{ *pos=ftell(stream); - return 0; } +{ *pos=ftell(stream); return 0; } diff --git a/libnix/sources/nix/stdio/ftell.c b/libnix/sources/nix/stdio/ftell.c index 61ef6b2..f93a0cf 100755 --- a/libnix/sources/nix/stdio/ftell.c +++ b/libnix/sources/nix/stdio/ftell.c @@ -3,17 +3,16 @@ #include long ftell(FILE *stream) -{ - long pos; - if(stream->flags&64) /* Error on stream */ +{ long pos; + if(stream->flags&__SERR) /* Error on stream */ { errno=EPERM; return EOF; } if((pos=lseek(stream->file,0,SEEK_CUR))==EOF) - { stream->flags|=64; + { stream->flags|=__SERR; return pos; } - if(stream->flags&4) + if(stream->flags&__SRD) pos-=stream->incount+(stream->tmpp!=NULL?stream->tmpinc:0); - else if(stream->flags&8) + else if(stream->flags&__SWR) pos+=stream->p-stream->buffer; return pos; } diff --git a/libnix/sources/nix/stdio/fwrite.c b/libnix/sources/nix/stdio/fwrite.c index 4aae63c..0c5e29c 100755 --- a/libnix/sources/nix/stdio/fwrite.c +++ b/libnix/sources/nix/stdio/fwrite.c @@ -25,7 +25,7 @@ int fwrite(const void *ptr,size_t size,size_t nmemb,FILE *stream) int c; c=*b++; if(putc(c,stream)==EOF) - break; + break; total--; } }while(total); diff --git a/libnix/sources/nix/stdio/gets.c b/libnix/sources/nix/stdio/gets.c index e6d95b8..5b9e503 100755 --- a/libnix/sources/nix/stdio/gets.c +++ b/libnix/sources/nix/stdio/gets.c @@ -1,15 +1,12 @@ #include char *gets(char *s) -{ - int c; - char *s2=s; +{ char *s2=s; + for(;;) - { - c=fgetc(stdin); + { int c=fgetc(stdin); if(c==EOF) - { - if(s2==s) + { if(s2==s) return NULL; break; } diff --git a/libnix/sources/nix/stdio/open.c b/libnix/sources/nix/stdio/open.c index 7eac724..af7b356 100755 --- a/libnix/sources/nix/stdio/open.c +++ b/libnix/sources/nix/stdio/open.c @@ -1,138 +1,243 @@ -#include -#include -#include -#include -#include #include -#undef LONGBITS -#undef BITSPERBYTE -#undef MAXINT -#undef MININT -#include +#include +#include +#include +#include #define DEVICES_TIMER_H #include #include #include -#include +#include +#include "stabs.h" +/* +** +*/ extern void __seterrno(void); -extern char *__amigapath(const char *path); -extern struct WBStartup *_WBenchMsg; -unsigned long *__stdfiledes; -static unsigned long stdfilesize=3; +/* +** +*/ +static StdFileDes **stdfiledes; +static unsigned long stdfilesize=0; static long stderrdes=0; /* The normal Amiga shell sets no process->pr_CES stream - * we use Open("*",MODE_NEWFILE) in this case */ -void __initstdio(void) -{ unsigned long *sfd; - - if((sfd=__stdfiledes=(unsigned long *)malloc(3*sizeof(unsigned long)))==NULL) - exit(20); - sfd[STDIN_FILENO ]=Input(); - sfd[STDOUT_FILENO]=Output(); - if(!(sfd[STDERR_FILENO]=((struct Process *)FindTask(NULL))->pr_CES)) - if(_WBenchMsg!=NULL||!(sfd[STDERR_FILENO]=stderrdes=Open("*",MODE_OLDFILE))) - sfd[STDERR_FILENO]=sfd[STDOUT_FILENO]; +/* +** +*/ +static void _setup_file(StdFileDes *fp) +{ fp->lx_inuse = 1; + fp->lx_isatty = IsInteractive(fp->lx_fh) ? -1 : 0; } -/* Call our private constructor */ -ADD2INIT(__initstdio,-30); - -void __exitstdio(void) -{ long file,*sfd; - int i,max; - - for(sfd=&__stdfiledes[3],max=stdfilesize,i=3;ilx_inuse) + break; + + if(file>SHRT_MAX) + { errno=EMFILE; + return NULL; + } + + if(file==max) + { if((sfd=realloc(stdfiledes,(file+1)*sizeof(fp)))==NULL) + { errno=ENOMEM; + return NULL; + } + stdfiledes=sfd; + stdfilesize++; + *(sfd=&sfd[file]) = 0; + } + + if((fp=sfd[0])==NULL) + { if((sfd[0]=fp=malloc(sizeof(*fp)))==NULL) + { errno=ENOMEM; + return NULL; + } + fp->lx_pos = file; + } + + return fp; +} + +/* +** +*/ +int open(const char *path,int flags,...) +{ extern char *__amigapath(const char *path); + StdFileDes *sfd; + #ifdef IXPATHS if((path=__amigapath(path))==NULL) return -1; #endif - for(sfd=__stdfiledes,max=stdfilesize,file=3;fileSHRT_MAX) - { errno=EMFILE; - return -1; } - - if(file==max) - { if((sfd=realloc(sfd,(file+1)*sizeof(unsigned long)))==NULL) - { errno=ENOMEM; - return -1; } - __stdfiledes=sfd; - stdfilesize++; + if ((sfd=_allocfd())) { + sfd->lx_sys=0; + sfd->lx_oflags=flags; + if ((sfd->lx_fh=Open((char *)path,flags&O_TRUNC?MODE_NEWFILE: + flags&(O_WRONLY|O_RDWR)?MODE_READWRITE:MODE_OLDFILE))) { + _setup_file(sfd); return sfd->lx_pos; + } + __seterrno(); + sfd->lx_inuse = 0; } - if((sfd[file]=Open((char *)path,flags&O_TRUNC?MODE_NEWFILE: - flags&(O_WRONLY|O_RDWR)?MODE_READWRITE:MODE_OLDFILE))) - return file; - __seterrno(); - return EOF; + return -1; } int close(int d) -{ - int ret=0; - if(d>2) - { - if(!Close(__stdfiledes[d])) - { ret=EOF; - __seterrno(); } - __stdfiledes[d]=0; - } - return ret; -} +{ StdFileDes *sfd = _lx_fhfromfd(d); -off_t lseek(int d,off_t offset,int whence) -{ - long r,file=__stdfiledes[d]; - __chkabort(); - r=Seek(file,offset,whence==SEEK_SET?OFFSET_BEGINNING: - whence==SEEK_END?OFFSET_END:OFFSET_CURRENT); - if(r!=EOF) - r=Seek(file,0,OFFSET_CURRENT); - if(r==EOF) - __seterrno(); - return r; + if (sfd) { + if (!(sfd->lx_inuse-=1)) { + if (sfd->lx_pos=d,!sfd->lx_sys) { + if (!Close(sfd->lx_fh)) { + __seterrno(); return EOF; + } + } + } + else { + stdfiledes[d] = 0; + } + } + + return 0; } ssize_t read(int d,void *buf,size_t nbytes) -{ - long r; - __chkabort(); - r=Read(__stdfiledes[d],buf,nbytes); - if(r==EOF) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + long r; + __chkabort(); + if((r=Read(sfd->lx_fh,buf,nbytes))!=EOF) + return r; __seterrno(); - return r; + } + + return EOF; } ssize_t write(int d,const void *buf,size_t nbytes) -{ - long r; - __chkabort(); - r=Write(__stdfiledes[d],(char *)buf,nbytes); - if(r==EOF) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + long r; + __chkabort(); + switch((sfd->lx_oflags&O_APPEND)!=0) { + case 1: + if(!sfd->lx_isatty&&(Seek(sfd->lx_fh,0,OFFSET_END)==EOF)) + break; + default: + if((r=Write(sfd->lx_fh,(char *)buf,nbytes))!=EOF) + return r; + } __seterrno(); - return r; + } + + return EOF; +} + +off_t lseek(int d,off_t offset,int whence) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + long r,file=sfd->lx_fh; + __chkabort(); + if (Seek(file,offset,whence==SEEK_SET?OFFSET_BEGINNING: + whence==SEEK_END?OFFSET_END:OFFSET_CURRENT)!=EOF) + if ((r=Seek(file,0,OFFSET_CURRENT))!=EOF) + return r; + __seterrno(); + } + + return EOF; } int isatty(int d) -{ return IsInteractive(__stdfiledes[d]); } +{ StdFileDes *sfd = _lx_fhfromfd(d); + + return sfd?sfd->lx_isatty:0; +} + +/* +** +*/ +int _lx_addflags(int d,int oflags) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + return sfd?sfd->lx_oflags|=oflags:0; +} + +/* +** convert fd to a StdFileDes +*/ +StdFileDes *_lx_fhfromfd(int d) +{ if(d<(int)stdfilesize) + { StdFileDes *sfd=stdfiledes[d]; + if(sfd&&sfd->lx_inuse) + return sfd; } + return NULL; +} + +/* +** +*/ +void __initstdio(void) +{ extern struct WBStartup *_WBenchMsg; + StdFileDes *fp,**sfd; + + if((stdfiledes=sfd=(StdFileDes **)malloc(3*sizeof(StdFileDes *)))) { + if((sfd[STDIN_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + fp->lx_fh = Input(); + fp->lx_pos = STDIN_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_RDONLY; + _setup_file(fp); + if((sfd[STDOUT_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + fp->lx_fh = Output(); + fp->lx_pos = STDOUT_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_WRONLY; + _setup_file(fp); + if((sfd[STDERR_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + if((fp->lx_fh=((struct Process *)FindTask(NULL))->pr_CES)==0) + if(_WBenchMsg||(fp->lx_fh=stderrdes=Open("*",MODE_OLDFILE))==0) + fp->lx_fh=sfd[STDOUT_FILENO]->lx_fh; + fp->lx_pos = STDERR_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_WRONLY; + _setup_file(fp); + stdfilesize += 3; return; + } + } + } + } + exit(20); +} +ADD2INIT(__initstdio,-30); + +void __exitstdio(void) +{ int i,max; + + for(max=stdfilesize,i=0;ilx_inuse) { + close(i); + } + } + + if(stderrdes) + Close(stderrdes); +} +ADD2EXIT(__exitstdio,-30); diff --git a/libnix/sources/nix/stdio/remove.c b/libnix/sources/nix/stdio/remove.c index 6e57a24..0aed031 100755 --- a/libnix/sources/nix/stdio/remove.c +++ b/libnix/sources/nix/stdio/remove.c @@ -1,6 +1,5 @@ -#include #include -#include +#include #include extern void __seterrno(void); @@ -16,6 +15,5 @@ int remove(const char *filename) if(DeleteFile((char *)filename)) return 0; else - { __seterrno(); - return -1; } + { __seterrno(); return -1; } } diff --git a/libnix/sources/nix/stdio/rename.c b/libnix/sources/nix/stdio/rename.c index c73d216..cc9cef2 100755 --- a/libnix/sources/nix/stdio/rename.c +++ b/libnix/sources/nix/stdio/rename.c @@ -17,10 +17,27 @@ int rename(const char *old,const char *new) if((new=__amigapath(new))!=NULL) { #endif - if(Rename((char *)old,(char *)new)) - ret=0; - else - __seterrno(); + +#if defined (__GNUC__) + #undef DOS_BASE_NAME + #define DOS_BASE_NAME dosbase + register APTR dosbase __asm("a6") = DOSBase; +#endif + + BPTR lnew=Lock((char *)new,SHARED_LOCK); + if(lnew) { + BPTR lold=Lock((char *)old,SHARED_LOCK); + if(lold) + ret=SameLock(lold,lnew),UnLock(lold); + UnLock(lnew); + } + + if(ret) { + if(ret==1) + DeleteFile((char *)new); + if(ret=0,!Rename((char *)old,(char *)new)) + __seterrno(),ret=-1; + } #ifdef IXPATHS } diff --git a/libnix/sources/nix/stdio/setbuf.c b/libnix/sources/nix/stdio/setbuf.c index 2837ac8..670550d 100755 --- a/libnix/sources/nix/stdio/setbuf.c +++ b/libnix/sources/nix/stdio/setbuf.c @@ -1,4 +1,4 @@ #include int setbuf(FILE *stream,char *buf) -{ return setvbuf(stream,buf,buf!=NULL?_IOFBF:_IONBF,BUFSIZ); } +{ return setvbuf(stream,buf,buf?_IOFBF:_IONBF,BUFSIZ); } diff --git a/libnix/sources/nix/stdio/setvbuf.c b/libnix/sources/nix/stdio/setvbuf.c index 093786d..a3285c6 100755 --- a/libnix/sources/nix/stdio/setvbuf.c +++ b/libnix/sources/nix/stdio/setvbuf.c @@ -1,29 +1,31 @@ -#include -#include #include +#include +#include int setvbuf(FILE *stream,char *buf,int mode,size_t size) -{ stream->flags&=~3; - stream->flags|=mode==_IOLBF?1:(mode==_IONBF?2:0); - if(size!=stream->bufsize||buf!=(char *)stream->buffer) +{ short flags=stream->flags&~(__SNBF|__SLBF); + if(mode==_IONBF) + flags|=__SNBF; + else if(mode==_IOLBF) + flags|=__SLBF; + if(size!=(size_t)stream->bufsize||buf!=(char *)stream->buffer) { if(__fflush(stream)) return -1; stream->incount=0; + stream->flags=(flags&=~__SRD); stream->tmpp=0; - stream->flags&=~4; mode=(buf==NULL); - if(mode) - if((buf=malloc(size))==NULL) - { errno=ENOMEM; - return -1; } - if(stream->flags&0x80) + if(mode&&(buf=malloc(size=size?size:1))==NULL) + { errno=ENOMEM; + return -1; } + if(flags&__SMBF) free(stream->buffer); if(mode) - stream->flags|=0x80; + flags|=__SMBF; else - stream->flags&=~0x80; + flags&=~__SMBF; stream->buffer=buf; stream->bufsize=size; } /* Need not adjust outcount, since setvbuf affects only the NEXT full buffer */ - return 0; + stream->flags=flags; return 0; } diff --git a/libnix/sources/nix/stdio/snprintf.c b/libnix/sources/nix/stdio/snprintf.c new file mode 100644 index 0000000..5de977e --- /dev/null +++ b/libnix/sources/nix/stdio/snprintf.c @@ -0,0 +1,11 @@ +#include +#include + +int snprintf(char *s,size_t size,const char *format,...) +{ int retval; + va_list args; + va_start(args,format); + retval=vsnprintf(s,size,format,args); + va_end(args); + return retval; +} diff --git a/libnix/sources/nix/stdio/ungetc.c b/libnix/sources/nix/stdio/ungetc.c index 0897c00..bb9c8a6 100755 --- a/libnix/sources/nix/stdio/ungetc.c +++ b/libnix/sources/nix/stdio/ungetc.c @@ -5,14 +5,14 @@ int ungetc(int c,FILE *stream) { if(c==EOF) return EOF; - if(stream->flags&64) /* Error on stream */ + if(stream->flags&__SERR)/* Error on stream */ { errno=EPERM; return EOF; } - if(stream->flags&8) /* File is in write mode */ - if(__fflush(stream)) /* write buffer */ + if(stream->flags&__SWR) /* File is in write mode */ + if(__fflush(stream)) /* write buffer */ return EOF; if(stream->tmpp==NULL) - { if(stream->flags&4) /* File is in read mode */ + { if(stream->flags&__SRD) /* File is in read mode */ { stream->tmpp=stream->p; /* store actual position */ stream->tmpinc=stream->incount; stream->p=&stream->unget[4]; /* and use other buffer */ @@ -22,7 +22,7 @@ int ungetc(int c,FILE *stream) stream->tmpinc=0; stream->p=&stream->unget[4]; /* use other buffer */ stream->incount=0; - stream->flags|=4; + stream->flags|=__SRD; } } if(stream->incount==4) /* ungetc buffer overflow */ diff --git a/libnix/sources/nix/stdio/vfprintf.c b/libnix/sources/nix/stdio/vfprintf.c index d35aa5b..6e4eef8 100755 --- a/libnix/sources/nix/stdio/vfprintf.c +++ b/libnix/sources/nix/stdio/vfprintf.c @@ -1,12 +1,10 @@ +#include +#include +#include #include #include #include #include -#include -#include -#include -#include -#include /* a little macro to make life easier */ @@ -31,10 +29,32 @@ extern unsigned char *__decimalpoint; +static int __vfprintf(FILE *stream,const char *format,va_list args) +{ unsigned char buf[((BUFSIZ/4)+3)&~3]; + FILE fp; + int ret; + + fp.outcount = 0; + fp.flags = stream->flags&~(__SWO|__SWR|__SNBF); + fp.file = stream->file; + fp.buffer = buf; + fp.bufsize = sizeof(buf); + fp.linebufsize = 0; + if(((ret=vfprintf(&fp,format,args))>=0) && __fflush(&fp)) + ret = -1; + if(fp.flags&__SERR) + stream->flags|=__SERR; + return ret; +} + int vfprintf(FILE *stream,const char *format,va_list args) { size_t outcount=0; + /* optimize unbuffered write-only files */ + if((stream->flags&(__SWO|__SNBF))==(__SWO|__SNBF)) + return __vfprintf(stream,format,args); + while(*format) { if(*format=='%') diff --git a/libnix/sources/nix/stdio/vsnprintf.c b/libnix/sources/nix/stdio/vsnprintf.c new file mode 100644 index 0000000..e167870 --- /dev/null +++ b/libnix/sources/nix/stdio/vsnprintf.c @@ -0,0 +1,19 @@ +#include +#include + +int vsnprintf(char *s,size_t size,const char *format,va_list args) +{ if ((int)size>0) { + int retval; + FILE buffer; + buffer.p=s; + buffer.incount=0; + buffer.outcount=size-1; + buffer.flags=__SSTR|__SWR; + buffer.linebufsize=0; + retval=vfprintf(&buffer,format,args); + buffer.outcount++; + fputc('\0',&buffer); + return retval; + } + return EOF; +} diff --git a/libnix/sources/nix/stdio/vsprintf.c b/libnix/sources/nix/stdio/vsprintf.c index 93781f7..a177ab3 100755 --- a/libnix/sources/nix/stdio/vsprintf.c +++ b/libnix/sources/nix/stdio/vsprintf.c @@ -3,13 +3,12 @@ #include int vsprintf(char *s,const char *format,va_list args) -{ - int retval; +{ int retval; FILE buffer; buffer.p=s; buffer.incount=0; buffer.outcount=INT_MAX; - buffer.flags=0x208; + buffer.flags=__SSTR|__SWR; buffer.linebufsize=0; retval=vfprintf(&buffer,format,args); fputc('\0',&buffer); diff --git a/libnix/sources/nix/stdio/vsscanf.c b/libnix/sources/nix/stdio/vsscanf.c index 103a1f5..9f2f0d2 100755 --- a/libnix/sources/nix/stdio/vsscanf.c +++ b/libnix/sources/nix/stdio/vsscanf.c @@ -1,15 +1,14 @@ #include -#include #include +#include #include int vsscanf(const char *s,const char *format,va_list args) -{ - FILE buffer; +{ FILE buffer; buffer.p=(char *)s; - buffer.flags=0x204; buffer.incount=strlen(s); buffer.outcount=0; + buffer.flags=__SSTR|__SRD; buffer.tmpp=NULL; return vfscanf(&buffer,format,args); } diff --git a/libnix/sources/nix/stdlib/atexit.c b/libnix/sources/nix/stdlib/atexit.c index c1f3f4b..80bbd72 100755 --- a/libnix/sources/nix/stdlib/atexit.c +++ b/libnix/sources/nix/stdlib/atexit.c @@ -1,7 +1,7 @@ #include #include #include -#include +#include "stabs.h" struct atexitnode { diff --git a/libnix/sources/nix/stdlib/calloc.c b/libnix/sources/nix/stdlib/calloc.c index 75c1b58..cf38410 100755 --- a/libnix/sources/nix/stdlib/calloc.c +++ b/libnix/sources/nix/stdlib/calloc.c @@ -1,18 +1,17 @@ -#include #include -void *calloc(unsigned long nmemb,unsigned long size) +void *calloc(size_t nmemb,size_t size) { - unsigned long l; - unsigned long *a; + size_t l; + size_t *a; void *b; - l=(nmemb*size+(sizeof(unsigned long)-1))&~(sizeof(unsigned long)-1); - a=(unsigned long *)(b=malloc(l)); + l=(nmemb*size+(sizeof(size_t)-1))&~(sizeof(size_t)-1); + a=(size_t *)(b=malloc(l)); if(b!=NULL) { do *a++=0; - while((l-=sizeof(unsigned long))!=0); + while((l-=sizeof(size_t))!=0); } return b; } diff --git a/libnix/sources/nix/stdlib/free.c b/libnix/sources/nix/stdlib/free.c index 8eca237..420dde7 100755 --- a/libnix/sources/nix/stdlib/free.c +++ b/libnix/sources/nix/stdlib/free.c @@ -1,35 +1,24 @@ -#include #include -#include -#include -#include -#include #include +#include +#include +#include "debuglib.h" extern struct MinList __memorylist; void free(void *ptr) -{ - struct MemHeader *a; +{ struct MemHeader *a; - if(ptr==NULL) /* What does that mean ????? */ - { -#ifdef DEBUG_LIB - FATALERROR("NULL pointer free'd\n"); -#endif - return; - } + if(!ptr) /* What does that mean ????? */ + { DB( BUG("NULL pointer free'd\n"); ) + return; } a=(struct MemHeader *)__memorylist.mlh_Head; for(;;) { if(((struct MinNode *)a)->mln_Succ==NULL) /* Is not in list ????? */ - { -#ifdef DEBUG_LIB - FATALERROR("Fake memory free'd\n"); -#endif - return; - } + { DB( BUG("Fake memory free'd\n"); ) + return; } if(ptr>=a->mh_Lower&&ptrmh_Upper) /* Entry found */ break; @@ -37,9 +26,7 @@ void free(void *ptr) a=(struct MemHeader *)((struct MinNode *)a)->mln_Succ; } -#ifdef DEBUG_LIB - memset(ptr,0xcc,((ULONG *)ptr)[-1]); /* Destroy contents */ -#endif + DB( memset(ptr,0xcc,((ULONG *)ptr)[-1]); ) /* Destroy contents */ Deallocate(a,(ULONG *)ptr-1,((ULONG *)ptr)[-1]); if(a->mh_Free==(char *)a->mh_Upper-(char *)a->mh_Lower) /* All free ? */ diff --git a/libnix/sources/nix/stdlib/malloc.c b/libnix/sources/nix/stdlib/malloc.c index 7ee2a2d..180f160 100755 --- a/libnix/sources/nix/stdlib/malloc.c +++ b/libnix/sources/nix/stdlib/malloc.c @@ -1,15 +1,14 @@ /* 10-Apr-94 bug fix M. Fleischer - * 11-Apr-94 bug fix & readjastment G. Nikl + * 11-Apr-94 bug fix & readjustment G. Nikl * 14-Apr-94 readjustment M. Fleischer * 24-Apr-94 cleanup for malloc changed */ -#include -#include -#include +#include #include +#include #include -#include +#include "stabs.h" extern ULONG _MSTEP; @@ -20,7 +19,7 @@ struct MinList __memorylist= /* memorylist (empty): free needs also access */ (struct MinNode *)&__memorylist.mlh_Head }; -void *malloc(unsigned long size) +void *malloc(size_t size) { struct MinNode *node=__memorylist.mlh_Head; struct MemHeader *b; diff --git a/libnix/sources/nix/stdlib/qsort.c b/libnix/sources/nix/stdlib/qsort.c index b87bc42..eeb038b 100755 --- a/libnix/sources/nix/stdlib/qsort.c +++ b/libnix/sources/nix/stdlib/qsort.c @@ -16,7 +16,6 @@ void qsort (void *base,size_t nmemb,size_t size,int (*compar)(const void *,const void *)) { char *base2=(char *)base; - char tmp; size_t i,a,b,c; while(nmemb>1) { a=0; @@ -30,7 +29,7 @@ void qsort if(a>=b) break; /* We found no pair */ for(i=0;i #include -void *realloc(void *ptr,unsigned long size) +void *realloc(void *ptr,size_t size) { void *a; - unsigned long l; + size_t l; if(size) a=malloc(size); else diff --git a/libnix/sources/nix/stdlib/system.c b/libnix/sources/nix/stdlib/system.c index 31a5171..95b7fc6 100755 --- a/libnix/sources/nix/stdlib/system.c +++ b/libnix/sources/nix/stdlib/system.c @@ -1,13 +1,12 @@ -#include #include +#include #include -static struct TagItem list[]={ { TAG_END,0 } }; /* No Tags */ - int system(const char *string) -{ - if(string==NULL) +{ static struct TagItem notags[]={ { TAG_END,0 } }; + + if(!string) return 1; else - return SystemTagList((char *)string,list); + return SystemTagList((char *)string,notags); } diff --git a/libnix/sources/nix/string/memset.c b/libnix/sources/nix/string/memset.c index 0bf120c..1c9934c 100755 --- a/libnix/sources/nix/string/memset.c +++ b/libnix/sources/nix/string/memset.c @@ -1,10 +1,27 @@ #include void *memset(void *s,int c,size_t n) -{ - if (n) { - unsigned char *p=s; - do;while(*p++=c,--n); +{ size_t m; + if(n) + { unsigned long *p=(unsigned long *)s; + if(n>15) + { c*=0x01010101; + if((long)p&1) + { *((char *)p)++=c; + n--; } + if((long)p&2) + { *((short *)p)++=c; + n-=2; } + for(m=n/(8*sizeof(long));m;--m) + { *p++=c; *p++=c; *p++=c; *p++=c; + *p++=c; *p++=c; *p++=c; *p++=c; } + n&=(8*sizeof(long)-1); + for(m=n/sizeof(long);m;--m) + *p++=c; + if((n&=sizeof(long)-1)==0) goto leave; + } + do;while(*((char *)p)++=c,--n); } +leave: return s; } diff --git a/libnix/sources/nix/string/strchr.c b/libnix/sources/nix/string/strchr.c index 7bf18e3..73a063e 100755 --- a/libnix/sources/nix/string/strchr.c +++ b/libnix/sources/nix/string/strchr.c @@ -1,5 +1,5 @@ #include -#include +#include "stabs.h" char *strchr(const char *s,int c) { diff --git a/libnix/sources/nix/string/strrchr.c b/libnix/sources/nix/string/strrchr.c index f17ce87..c246a83 100755 --- a/libnix/sources/nix/string/strrchr.c +++ b/libnix/sources/nix/string/strrchr.c @@ -1,5 +1,5 @@ #include -#include +#include "stabs.h" char *strrchr(const char *s,int c) { char *c1=(char *)0; diff --git a/libnix/sources/nix/time/clock.c b/libnix/sources/nix/time/clock.c index 82cc1b7..e0efe0e 100755 --- a/libnix/sources/nix/time/clock.c +++ b/libnix/sources/nix/time/clock.c @@ -1,20 +1,13 @@ #include -#include -#ifdef __GNUC__ /* This is very sad :-( */ -#undef BITSPERBYTE -#undef MAXINT -#undef MININT -#endif #include +#include #include -#include +#include "stabs.h" static struct DateStamp ds; -int __initclock(void) -{ DateStamp(&ds); - return 0; -} +void __initclock(void) +{ DateStamp(&ds); } ADD2INIT(__initclock,-10); @@ -23,5 +16,5 @@ clock_t clock(void) DateStamp(&ds2); return (((ds2.ds_Days-ds.ds_Days)*(24*60)+ ds2.ds_Minute-ds.ds_Minute)*(60*TICKS_PER_SECOND)+ - ds2.ds_Tick-ds.ds_Tick)*CLK_TCK/TICKS_PER_SECOND; + ds2.ds_Tick-ds.ds_Tick)*CLOCKS_PER_SEC/TICKS_PER_SECOND; } diff --git a/libnix/sources/nix/time/mktime.c b/libnix/sources/nix/time/mktime.c index 0c1337a..04bc099 100755 --- a/libnix/sources/nix/time/mktime.c +++ b/libnix/sources/nix/time/mktime.c @@ -1,10 +1,9 @@ #include -static char monthtable[]= -{ 31,29,31,30,31,30,31,31,30,31,30 }; - time_t mktime(struct tm *t) -{ +{ static const char monthtable[] = { + 31,29,31,30,31,30,31,31,30,31,30 + }; time_t tim,year; int leapyear=0,i; year=t->tm_year+1899; /* years from year 1 */ @@ -20,7 +19,7 @@ time_t mktime(struct tm *t) year%=4; if(year==3) leapyear++; - tim+=year*365-719162+t->tm_mday; + tim+=year*365-719162+t->tm_mday-1; for(i=0;itm_mon;i++) tim+=monthtable[i]; if(!leapyear&&t->tm_mon>1) /* Sub 1 if no leap year */ diff --git a/libnix/sources/nix/time/strftime.c b/libnix/sources/nix/time/strftime.c index 51c5c1f..78dff58 100755 --- a/libnix/sources/nix/time/strftime.c +++ b/libnix/sources/nix/time/strftime.c @@ -48,7 +48,7 @@ size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timep case 'h': ADDS(STR(ABMON_1+timeptr->tm_mon)); case 'c': - ADDS("%m/%d/%y"); + ADDS("%m/%d/%y %H:%M:%S"); case 'd': ADDN(2,timeptr->tm_mday); case 'e': @@ -68,7 +68,7 @@ size_t strftime(char *s,size_t maxsize,const char *format,const struct tm *timep case 'w': ADDN(1,timeptr->tm_wday); case 'x': - ADDS("%m/%d/%y %H:%M:%S"); + ADDS("%m/%d/%y"); case 'y': ADDN(2,timeptr->tm_year%100); case 'A': diff --git a/libnix/sources/nix13/Makefile.in b/libnix/sources/nix13/Makefile.in index a18047f..0aa7aea 100644 --- a/libnix/sources/nix13/Makefile.in +++ b/libnix/sources/nix13/Makefile.in @@ -4,11 +4,12 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### @@ -18,9 +19,7 @@ endif CURDIR = $(shell pwd) -OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers $(CFLAGS) -msmall-code - -SOURCEFILES=*/* +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) -msmall-code REDEF=-D_DOSBase=___DOSBase \ -D_UtilityBase=___UtilityBase \ @@ -50,8 +49,8 @@ veryclean: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)): mkdir $@ -libnix13.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) ../../sources/nix13/makefile ../../sources/nix13/filelist +libnix13.a: $(foreach f,$(SUBDIRS),$(CURDIR)/$(f)) $(OBJECTS) ../../sources/nix13/Makefile ../../sources/nix13/filelist -rm -f $@ - ar -q $@ $(OBJECTS) + $(AR) -q $@ $(OBJECTS) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/nix13/extra/stricmp.c b/libnix/sources/nix13/extra/stricmp.c index 00a9e63..e4868c6 100644 --- a/libnix/sources/nix13/extra/stricmp.c +++ b/libnix/sources/nix13/extra/stricmp.c @@ -1,6 +1,6 @@ #include #include -#include +#include "stabs.h" int stricmp(const char *s1,const char *s2) { unsigned char c1,c2; diff --git a/libnix/sources/nix13/extra/strnicmp.c b/libnix/sources/nix13/extra/strnicmp.c index 3d71a38..abc7e2c 100644 --- a/libnix/sources/nix13/extra/strnicmp.c +++ b/libnix/sources/nix13/extra/strnicmp.c @@ -1,6 +1,6 @@ #include #include -#include +#include "stabs.h" int strnicmp(const char *s1,const char *s2,size_t len) { unsigned char c1,c2; diff --git a/libnix/sources/nix_main/Makefile.in b/libnix/sources/nix_main/Makefile.in index a4870b4..6e7447f 100644 --- a/libnix/sources/nix_main/Makefile.in +++ b/libnix/sources/nix_main/Makefile.in @@ -4,17 +4,18 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### OBJECTS=__nocommandline.o _main.o -OPTIONS=-I $(srcdir)/../headers -I../../sources/headers $(CFLAGS) +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) REDEF=-D_DOSBase=___DOSBase \ -D_UtilityBase=___UtilityBase \ @@ -46,8 +47,8 @@ clean: veryclean: clean -rm -f libnix_main.a -libnix_main.a: $(OBJECTS) ../../sources/nix_main/makefile +libnix_main.a: $(OBJECTS) ../../sources/nix_main/Makefile -rm -f $@ - ar -q $@ $(OBJECTS) + $(AR) -q $@ $(OBJECTS) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/nix_main/__nocommandline.c b/libnix/sources/nix_main/__nocommandline.c index 148dc23..3cceebb 100755 --- a/libnix/sources/nix_main/__nocommandline.c +++ b/libnix/sources/nix_main/__nocommandline.c @@ -1,5 +1,5 @@ /* - * This is a different calling convention for main (actually its _main): + * This is a different calling convention for main (actually it's _main): * * int main(char *commandline); * void exit(int returncode); @@ -11,10 +11,10 @@ #include #include #include -#include +#include "stabs.h" extern char *__argc; /* Defined in startup */ -extern char *__commandline; +extern char *__commandline; extern unsigned long __commandlen; extern struct WBStartup *_WBenchMsg; diff --git a/libnix/sources/nix_main/_main.c b/libnix/sources/nix_main/_main.c index 1a9e515..326403e 100755 --- a/libnix/sources/nix_main/_main.c +++ b/libnix/sources/nix_main/_main.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" /* main is now called _main! */ ALIAS(main,_main); diff --git a/libnix/sources/nixmain/Makefile.in b/libnix/sources/nixmain/Makefile.in index 255768f..bfac275 100644 --- a/libnix/sources/nixmain/Makefile.in +++ b/libnix/sources/nixmain/Makefile.in @@ -4,17 +4,18 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### OBJECTS=__nocommandline.o __stdiowin.o -OPTIONS=-I $(srcdir)/../headers -I../../sources/headers $(CFLAGS) +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) REDEF=-D_DOSBase=___DOSBase \ -D_UtilityBase=___UtilityBase \ @@ -46,8 +47,8 @@ clean: veryclean: clean -rm -f libnixmain.a -libnixmain.a: $(OBJECTS) ../../sources/nixmain/makefile +libnixmain.a: $(OBJECTS) ../../sources/nixmain/Makefile -rm -f $@ - ar -q $@ $(OBJECTS) + $(AR) -q $@ $(OBJECTS) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/nixmain/__nocommandline.c b/libnix/sources/nixmain/__nocommandline.c index bbb8e1c..920f55b 100755 --- a/libnix/sources/nixmain/__nocommandline.c +++ b/libnix/sources/nixmain/__nocommandline.c @@ -4,7 +4,7 @@ #include #include #include -#include +#include "stabs.h" extern int __argc; /* Defined in startup */ extern char **__argv; diff --git a/libnix/sources/socket/Makefile.in b/libnix/sources/socket/Makefile.in new file mode 100644 index 0000000..67246e4 --- /dev/null +++ b/libnix/sources/socket/Makefile.in @@ -0,0 +1,74 @@ +#### Start of system configuration section. #### + +srcdir = @srcdir@ +VPATH = @srcdir@ + +CC = @CC@ +CPP = @CPP@ +AS = as + +AR = ar +RANLIB = @RANLIB@ +AWK = @AWK@ + +#### End system configuration section #### + +ifneq ($(TARGET),clean) +include ../../sources/socket/filelist +endif + +CURDIR = $(shell pwd) + +OPTIONS=-I$(srcdir)/../headers -D_SOCKET_IO $(CFLAGS) + +OBJECTS2=$(OBJECTS) \ + ../nix/assert/__eprintf.o \ + ../nix/extra/creat.o ../nix/extra/getw.o ../nix/extra/putw.o \ + ../nix/extra/setbuffer.o ../nix/extra/setlinebuf.o \ + ../nix/signal/raise.o ../nix/signal/signal.o ../nix/signal/__chkabort.o \ + ../nix/stdio/fdopen.o ../nix/stdio/fflush.o ../nix/stdio/fgetc.o \ + ../nix/stdio/fgetpos.o ../nix/stdio/fgets.o ../nix/stdio/fopen.o \ + ../nix/stdio/fprintf.o ../nix/stdio/fputc.o ../nix/stdio/fputs.o \ + ../nix/stdio/fread.o ../nix/stdio/freopen.o ../nix/stdio/fscanf.o \ + ../nix/stdio/fseek.o ../nix/stdio/fsetpos.o ../nix/stdio/ftell.o \ + ../nix/stdio/fwrite.o ../nix/stdio/gets.o ../nix/stdio/perror.o \ + ../nix/stdio/printf.o ../nix/stdio/puts.o ../nix/stdio/rewind.o \ + ../nix/stdio/scanf.o ../nix/stdio/setbuf.o ../nix/stdio/setvbuf.o \ + ../nix/stdio/snprintf.o ../nix/stdio/sprintf.o ../nix/stdio/sscanf.o \ + ../nix/stdio/tmpfile.o ../nix/stdio/tmpnam.o ../nix/stdio/ungetc.o \ + ../nix/stdio/vfprintf.o ../nix/stdio/vfscanf.o ../nix/stdio/vprintf.o \ + ../nix/stdio/vscanf.o ../nix/stdio/vsnprintf.o ../nix/stdio/vsprintf.o \ + ../nix/stdio/vsscanf.o ../nix/stdio/__fflush.o ../nix/stdio/__srget.o \ + ../nix/stdio/__stdio.o ../nix/stdio/__swbuf.o \ + ../nix/stdlib/abort.o + +SUBDIRS2=$(SUBDIRS) \ + ../nix/assert ../nix/extra ../nix/signal ../nix/stdio ../nix/stdlib + +REDEF=-D_DOSBase=___DOSBase + +%.o: %.c + $(CC) $(OPTIONS) -S $^ -o $*.S 2>&1|tee $*.err + $(CPP) -traditional $(REDEF) $*.S -o $*2.S + $(CC) $(OPTIONS) $*2.S -c -o $*.o + -rm $*.S $*2.S + -if test ! -s $*.err; then rm $*.err; fi + +.PHONY: all clean veryclean + +all: libsocket.a + +clean: + -rm -rf $(SUBDIRS2) + +veryclean: + -rm -rf * + +$(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)): + mkdir $@ + +libsocket.a: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)) $(OBJECTS2) ../../sources/socket/Makefile ../../sources/socket/filelist + -rm -f $@ + $(AR) -q $@ $(OBJECTS2) + $(RANLIB) $@ + echo "\$$$(V)" >>$@ diff --git a/libnix/sources/socket/arpa/inet_aton.c b/libnix/sources/socket/arpa/inet_aton.c new file mode 100644 index 0000000..dae3d44 --- /dev/null +++ b/libnix/sources/socket/arpa/inet_aton.c @@ -0,0 +1,149 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include +#include + +/* + * Ascii internet address interpretation routine. + * The value returned is in network order. + */ +u_long +inet_addr(const char *cp) +{ + struct in_addr val; + + if (inet_aton(cp, &val)) + return (val.s_addr); + return (u_long)-1; +} + +/* + * Check whether "cp" is a valid ascii representation + * of an Internet address and convert to a binary address. + * Returns 1 if the address is valid, 0 if not. + * This replaces inet_addr, the return value from which + * cannot distinguish between failure and a local broadcast address. + */ +int +inet_aton(const char *cp, struct in_addr *addr) +{ + u_long parts[4], val, base, n, *pp = parts; + char c; + + for (;;) { + /* + * Collect number up to ``.''. + * Values are specified as for C: + * 0x=hex, 0=octal, other=decimal. + */ + val = 0; base = 10; + if (*cp == '0') { + if (*++cp == 'x' || *cp == 'X') + base = 16, cp++; + else + base = 8; + } + while ((c = *cp) != '\0') { + if (isascii(c) && isdigit(c)) { + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isascii(c) && isxdigit(c)) { + val = (val << 4) + + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + /* + * Internet format: + * a.b.c.d + * a.b.c (with c treated as 16-bits) + * a.b (with b treated as 24 bits) + */ + if (pp >= parts + 3 || val > 0xff) + return (0); + *pp++ = val, cp++; + } else + break; + } + + /* + * Check for trailing characters. + */ + if (*cp && (!isascii(*cp) || !isspace(*cp))) + return (0); + + /* + * Concoct the address according to + * the number of parts specified. + */ + n = pp - parts + 1; + switch (n) { + + case 1: /* a -- 32 bits */ + break; + + case 2: /* a.b -- 8.24 bits */ + if (val > 0xffffff) + return (0); + val |= parts[0] << 24; + break; + + case 3: /* a.b.c -- 8.8.16 bits */ + if (val > 0xffff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16); + break; + + case 4: /* a.b.c.d -- 8.8.8.8 bits */ + if (val > 0xff) + return (0); + val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8); + break; + } + if (addr) + addr->s_addr = htonl(val); + + return 1; +} diff --git a/libnix/sources/socket/arpa/inet_lnaof.c b/libnix/sources/socket/arpa/inet_lnaof.c new file mode 100644 index 0000000..608448b --- /dev/null +++ b/libnix/sources/socket/arpa/inet_lnaof.c @@ -0,0 +1,57 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Return the local network address portion of an + * internet address; handles class a/b/c network + * number formats. + */ +u_long +inet_lnaof(struct in_addr in) +{ + u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return ((i)&IN_CLASSA_HOST); + else if (IN_CLASSB(i)) + return ((i)&IN_CLASSB_HOST); + else + return ((i)&IN_CLASSC_HOST); +} diff --git a/libnix/sources/socket/arpa/inet_makeaddr.c b/libnix/sources/socket/arpa/inet_makeaddr.c new file mode 100644 index 0000000..e06423b --- /dev/null +++ b/libnix/sources/socket/arpa/inet_makeaddr.c @@ -0,0 +1,60 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Formulate an Internet address from network + host. Used in + * building addresses stored in the ifnet structure. + */ +struct in_addr +inet_makeaddr(u_long net, u_long host) +{ + u_long addr; + + if (net < 128) + addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); + else if (net < 65536) + addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); + else if (net < 16777216L) + addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); + else + addr = net | host; + addr = htonl(addr); + return (*(struct in_addr *)&addr); +} diff --git a/libnix/sources/socket/arpa/inet_netof.c b/libnix/sources/socket/arpa/inet_netof.c new file mode 100644 index 0000000..b29abed --- /dev/null +++ b/libnix/sources/socket/arpa/inet_netof.c @@ -0,0 +1,56 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include + +/* + * Return the network number from an internet + * address; handles class a/b/c network #'s. + */ +u_long +inet_netof(struct in_addr in) +{ + register u_long i = ntohl(in.s_addr); + + if (IN_CLASSA(i)) + return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); + else if (IN_CLASSB(i)) + return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); + else + return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); +} diff --git a/libnix/sources/socket/arpa/inet_network.c b/libnix/sources/socket/arpa/inet_network.c new file mode 100644 index 0000000..b832283 --- /dev/null +++ b/libnix/sources/socket/arpa/inet_network.c @@ -0,0 +1,89 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +/* + * Internet network address interpretation routine. + * The library routines call this routine to interpret + * network numbers. + */ +u_long +inet_network(const char *cp) +{ + u_long parts[4], val, base, n, i, *pp = parts; + char c; + +again: + val = 0; base = 10; + if (*cp == '0') + base = 8, cp++; + if (*cp == 'x' || *cp == 'X') + base = 16, cp++; + while ((c = *cp)) { + if (isdigit(c)) { + val = (val * base) + (c - '0'); + cp++; + continue; + } + if (base == 16 && isxdigit(c)) { + val = (val << 4) + (c + 10 - (islower(c) ? 'a' : 'A')); + cp++; + continue; + } + break; + } + if (*cp == '.') { + if (pp >= parts + 4) + return (u_long)-1; + *pp++ = val, cp++; + goto again; + } + if (*cp && !isspace(*cp)) + return (u_long)-1; + *pp++ = val; + n = pp - parts; + if (n > 4) + return (u_long)-1; + for (val = 0, i = 0; i < n; i++) { + val <<= 8; + val |= parts[i] & 0xff; + } + return val; +} diff --git a/libnix/sources/socket/arpa/inet_ntoa.c b/libnix/sources/socket/arpa/inet_ntoa.c new file mode 100644 index 0000000..28abc58 --- /dev/null +++ b/libnix/sources/socket/arpa/inet_ntoa.c @@ -0,0 +1,51 @@ +/* + * Copyright (c) 1983, 1990 Regents of the University of California. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)inet_addr.c 5.10 (Berkeley) 2/24/91"; +#endif /* LIBC_SCCS and not lint */ + +#include +#include +#include + +char * +inet_ntoa(struct in_addr in) +{ static char buf[18]; + char *p = (char *)∈ + +#define UC(b) (((int)b)&0xff) + + snprintf(buf, sizeof(buf), "%d.%d.%d.%d", UC(p[0]), UC(p[1]), UC(p[2]), UC(p[3])); + return buf; +} diff --git a/libnix/sources/socket/extra/dup.c b/libnix/sources/socket/extra/dup.c new file mode 100644 index 0000000..b333d11 --- /dev/null +++ b/libnix/sources/socket/extra/dup.c @@ -0,0 +1,16 @@ +#include +#include +// +#include "stdio.h" + +int dup(int d) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + return sfd->lx_dup(sfd); + } + else { + errno = EBADF; + return -1; + } +} diff --git a/libnix/sources/socket/extra/fdtofh.c b/libnix/sources/socket/extra/fdtofh.c new file mode 100644 index 0000000..b4b39c0 --- /dev/null +++ b/libnix/sources/socket/extra/fdtofh.c @@ -0,0 +1 @@ +#include "../nix/extra/fdtofh.c" diff --git a/libnix/sources/socket/extra/fstat.c b/libnix/sources/socket/extra/fstat.c new file mode 100644 index 0000000..695b5c0 --- /dev/null +++ b/libnix/sources/socket/extra/fstat.c @@ -0,0 +1,14 @@ +#include +// +#include "stdio.h" + +int fstat(int d, struct stat *buf) +{ StdFileDes *fp = _lx_fhfromfd(d); + if (fp) { + return fp->lx_fstat(fp, buf); + } + else { + errno = EBADF; + return -1; + } +} diff --git a/libnix/sources/socket/extra/strsep.c b/libnix/sources/socket/extra/strsep.c new file mode 100644 index 0000000..c031c1b --- /dev/null +++ b/libnix/sources/socket/extra/strsep.c @@ -0,0 +1,35 @@ +/* + * Get next token from string *stringp, where tokens are nonempty + * strings separated by characters from delim. + * + * Writes NULs into the string at *stringp to end tokens. + * delim need not remain constant from call to call. + * On return, *stringp points past the last NUL written (if there might + * be further tokens), or is NULL (if there are definitely no more tokens). + * + * If *stringp is NULL, strsep returns NULL. + */ + +#include + +char *strsep(char **stringp, const char *delim) +{ char *s,*tok; + + if ((tok=*stringp)) + for (s=tok;;) { + const char *spanp=delim; + int sc,c=*s++; + do { + if ((sc = *spanp++) == c) { + if (c) + s[-1] = 0; + else + s = NULL; + tok = *stringp; + *stringp = s; + return tok; + } + } while (sc != 0); + } + return tok; +} diff --git a/libnix/sources/socket/ft.c b/libnix/sources/socket/ft.c new file mode 100644 index 0000000..61cd79d --- /dev/null +++ b/libnix/sources/socket/ft.c @@ -0,0 +1,12 @@ +#include +#include + +int main(void) +{ + int fd1 = open("t:t1",O_TRUNC); + int fd2 = open("t:t2",O_TRUNC); + int fd3 = dup2(fd1,fd2); + int fd4 = dup(fd1); + close(fd2); + fd2 = open("t:t2",O_RDONLY); +} diff --git a/libnix/sources/socket/netdb/gethostbyaddr.c b/libnix/sources/socket/netdb/gethostbyaddr.c new file mode 100644 index 0000000..967b258 --- /dev/null +++ b/libnix/sources/socket/netdb/gethostbyaddr.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct hostent *gethostbyaddr(const char *addr, int len, int type) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_gethostbyaddr(addr,len,type); + + case LX_AMITCP: + return TCP_GetHostByAddr(addr,len,type); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/gethostbyname.c b/libnix/sources/socket/netdb/gethostbyname.c new file mode 100644 index 0000000..a6f8456 --- /dev/null +++ b/libnix/sources/socket/netdb/gethostbyname.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct hostent *gethostbyname(const char *name) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_gethostbyname(name); + + case LX_AMITCP: + return TCP_GetHostByName(name); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/gethostent.c b/libnix/sources/socket/netdb/gethostent.c new file mode 100644 index 0000000..d845d07 --- /dev/null +++ b/libnix/sources/socket/netdb/gethostent.c @@ -0,0 +1,32 @@ +#include +#include +#include +#include +#include +// +#include "socket.h" + +void sethostent(int stayopen) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AS225) { + SOCK_sethostent(stayopen); + } + else if (stayopen && lss->lx_res) { + lss->lx_res->options |= RES_STAYOPEN | RES_USEVC; + } +} + +void endhostent(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AS225) { + SOCK_endhostent(); + } + else if (lss->lx_res) { + lss->lx_res->options &= ~(RES_STAYOPEN | RES_USEVC); + if (*lss->lx_res_socket >= 0) { + close(*lss->lx_res_socket); *lss->lx_res_socket = -1; + } + } +} diff --git a/libnix/sources/socket/netdb/getnetbyaddr.c b/libnix/sources/socket/netdb/getnetbyaddr.c new file mode 100644 index 0000000..0e0e780 --- /dev/null +++ b/libnix/sources/socket/netdb/getnetbyaddr.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct netent *getnetbyaddr(long net, int type) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getnetbyaddr(net,type); + + case LX_AMITCP: + return TCP_GetNetByAddr(net,type); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getnetbyname.c b/libnix/sources/socket/netdb/getnetbyname.c new file mode 100644 index 0000000..3d0abac --- /dev/null +++ b/libnix/sources/socket/netdb/getnetbyname.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct netent *getnetbyname(const char *name) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getnetbyname(name); + + case LX_AMITCP: + return TCP_GetNetByName(name); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getnetent.c b/libnix/sources/socket/netdb/getnetent.c new file mode 100644 index 0000000..79373d2 --- /dev/null +++ b/libnix/sources/socket/netdb/getnetent.c @@ -0,0 +1,125 @@ +#include +#include +#include +#include +#include +#include +#include +// +#include "socket.h" + +#define MAXALIASES 35 +#define TCP_PATH_NETWORKS "AmiTCP:db/networks" + +void setnetent(int stayopen) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_setnetent(stayopen); + break; + + case LX_AMITCP: + if (!lss->lx_net_fp) + lss->lx_net_fp = fopen(TCP_PATH_NETWORKS, "r"); + else + rewind(lss->lx_net_fp); + lss->lx_net_stayopen = stayopen; + break; + + default: + /* silence compiler */ + break; + } +} + +void endnetent(void) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_endnetent(); + break; + + default: + lss->lx_net_stayopen = 0; + if (lss->lx_net_fp) { + fclose(lss->lx_net_fp); lss->lx_net_fp = NULL; + } +#if 0 + if (lss->lx_net_aliases) { + free(lss->lx_net_aliases); lss->lx_net_aliases = NULL; + } + if (lss->lx_net_line) { + free(lss->lx_net_line); lss->lx_net_line = NULL; + } +#endif + break; + } +} + +struct netent *getnetent(void) +{ struct SocketSettings *lss; + + switch(lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getnetent(); + break; + + case LX_AMITCP: + + if (!lss->lx_net_line) + lss->lx_net_line = malloc(BUFSIZ + 1); + + if (!lss->lx_net_aliases) + lss->lx_net_aliases = malloc(MAXALIASES * sizeof(char *)); + + if (!lss->lx_net_line || !lss->lx_net_aliases) { + errno = ENOMEM; return NULL; + } + + if (lss->lx_net_fp || (lss->lx_net_fp=fopen(TCP_PATH_NETWORKS, "r"))) { + for(;;) { + char *s, *cp, **q; + + if ((s=fgets(lss->lx_net_line, BUFSIZ, lss->lx_net_fp)) == NULL) + break; + + if ((*s == '#') || ((cp=strpbrk(s, "#\n")) == NULL)) + continue; + *cp = '\0'; + lss->lx_net.n_name = s; + + if ((cp=strpbrk(s, " \t")) == NULL) + continue; + *cp++ = '\0'; + while (*cp == ' ' || *cp == '\t') + cp++; + if ((s=strpbrk(cp, " \t"))) + *s++ = '\0'; + lss->lx_net.n_net = inet_network(cp); + lss->lx_net.n_addrtype = AF_INET; + + q = lss->lx_net.n_aliases = lss->lx_net_aliases; + if ((cp=s)) { + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; continue; + } + if (q < &lss->lx_net_aliases[MAXALIASES - 1]) + *q++ = cp; + if ((cp=strpbrk(cp, " \t"))) + *cp++ = '\0'; + } + } + *q = NULL; return &lss->lx_net; + } + } + + /* fall through */ + + default: + return NULL; + break; + } +} diff --git a/libnix/sources/socket/netdb/getprotobyname.c b/libnix/sources/socket/netdb/getprotobyname.c new file mode 100644 index 0000000..6a0d4f8 --- /dev/null +++ b/libnix/sources/socket/netdb/getprotobyname.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct protoent *getprotobyname(const char *name) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getprotobyname(name); + + case LX_AMITCP: + return TCP_GetProtoByName(name); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getprotobynumber.c b/libnix/sources/socket/netdb/getprotobynumber.c new file mode 100644 index 0000000..ad7fcd7 --- /dev/null +++ b/libnix/sources/socket/netdb/getprotobynumber.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct protoent *getprotobynumber(int proto) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getprotobynumber(proto); + + case LX_AMITCP: + return TCP_GetProtoByNumber(proto); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getprotoent.c b/libnix/sources/socket/netdb/getprotoent.c new file mode 100644 index 0000000..5da2c5e --- /dev/null +++ b/libnix/sources/socket/netdb/getprotoent.c @@ -0,0 +1,123 @@ +#include +#include +#include +#include +#include +// +#include "socket.h" + +#define MAXALIASES 35 +#define TCP_PATH_PROTOCOLS "AmiTCP:db/protocols" + +void setprotoent(int stayopen) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_setprotoent(stayopen); + break; + + case LX_AMITCP: + if (!lss->lx_proto_fp) + lss->lx_proto_fp = fopen(TCP_PATH_PROTOCOLS, "r"); + else + rewind(lss->lx_proto_fp); + lss->lx_proto_stayopen = stayopen; + break; + + default: + /* silence compiler */ + break; + } +} + +void endprotoent(void) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_endprotoent(); + break; + + default: + lss->lx_proto_stayopen = 0; + if (lss->lx_proto_fp) { + fclose(lss->lx_proto_fp); lss->lx_proto_fp = NULL; + } +#if 0 + if (lss->lx_proto_aliases) { + free(lss->lx_proto_aliases); lss->lx_proto_aliases = NULL; + } + if (lss->lx_proto_line) { + free(lss->lx_proto_line); lss->lx_proto_line = NULL; + } +#endif + break; + } +} + +struct protoent *getprotoent(void) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getprotoent(); + break; + + case LX_AMITCP: + + if (!lss->lx_proto_line) + lss->lx_proto_line = malloc(BUFSIZ + 1); + + if (!lss->lx_proto_aliases) + lss->lx_proto_aliases = malloc(MAXALIASES * sizeof(char *)); + + if (!lss->lx_proto_line || !lss->lx_proto_aliases) { + errno = ENOMEM; return NULL; + } + + if (lss->lx_proto_fp || (lss->lx_proto_fp=fopen(TCP_PATH_PROTOCOLS, "r"))) { + for(;;) { + char *s, *cp, **q; + + if ((s=fgets(lss->lx_proto_line, BUFSIZ, lss->lx_proto_fp)) == NULL) + break; + + if ((*s == '#') || ((cp=strpbrk(s, "#\n")) == NULL)) + continue; + *cp = '\0'; + lss->lx_proto.p_name = s; + + if ((cp=strpbrk(s, " \t")) == NULL) + continue; + *cp++ = '\0'; + while (*cp == ' ' || *cp == '\t') + cp++; + if ((s=strpbrk(cp, " \t"))) + *s++ = '\0'; + lss->lx_proto.p_proto = atoi(cp); + + q = lss->lx_proto.p_aliases = lss->lx_proto_aliases; + if ((cp=s)) { + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; continue; + } + if (q < &lss->lx_proto_aliases[MAXALIASES - 1]) + *q++ = cp; + + if ((cp=strpbrk(cp, " \t"))) + *cp++ = '\0'; + } + } + *q = NULL; return &lss->lx_proto; + } + } + + /* fall through */ + + default: + return NULL; + break; + } +} diff --git a/libnix/sources/socket/netdb/getservbyname.c b/libnix/sources/socket/netdb/getservbyname.c new file mode 100644 index 0000000..ea2a23e --- /dev/null +++ b/libnix/sources/socket/netdb/getservbyname.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct servent *getservbyname(const char *name, const char *proto) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getservbyname(name,proto); + + case LX_AMITCP: + return TCP_GetServByName(name,proto); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getservbyport.c b/libnix/sources/socket/netdb/getservbyport.c new file mode 100644 index 0000000..8ceb2f8 --- /dev/null +++ b/libnix/sources/socket/netdb/getservbyport.c @@ -0,0 +1,18 @@ +#include +// +#include "socket.h" + +struct servent *getservbyport(int port, const char *proto) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + switch (lss->lx_network_type) { + case LX_AS225: + return SOCK_getservbyport(port,proto); + + case LX_AMITCP: + return TCP_GetServByPort(port,proto); + + default: + return NULL; + } +} diff --git a/libnix/sources/socket/netdb/getservent.c b/libnix/sources/socket/netdb/getservent.c new file mode 100644 index 0000000..b0a1465 --- /dev/null +++ b/libnix/sources/socket/netdb/getservent.c @@ -0,0 +1,126 @@ +#include +#include +#include +#include +#include +// +#include "socket.h" + +#define MAXALIASES 35 +#define TCP_PATH_SERVICES "AmiTCP:db/services" + +void setservent(int stayopen) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_setservent(stayopen); + break; + + case LX_AMITCP: + if (!lss->lx_serv_fp) + lss->lx_serv_fp = fopen(TCP_PATH_SERVICES, "r"); + else + rewind(lss->lx_serv_fp); + lss->lx_serv_stayopen = stayopen; + break; + + default: + /* silence compiler */ + break; + } +} + +void endservent(void) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_endservent(); + break; + + default: + lss->lx_serv_stayopen = 0; + if (lss->lx_serv_fp) { + fclose(lss->lx_serv_fp); lss->lx_serv_fp = NULL; + } +#if 0 + if (lss->lx_serv_aliases) { + free(lss->lx_serv_aliases); lss->lx_serv_aliases = NULL; + } + if (lss->lx_serv_line) { + free(lss->lx_serv_line); lss->lx_serv_line = NULL; + } +#endif + break; + } +} + +struct servent *getservent(void) +{ struct SocketSettings *lss; + + switch(lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return SOCK_getservent(); + break; + + + case LX_AMITCP: + + if (!lss->lx_serv_line) + lss->lx_serv_line = malloc(BUFSIZ + 1); + + if (!lss->lx_serv_aliases) + lss->lx_serv_aliases = malloc(MAXALIASES * sizeof(char *)); + + if (!lss->lx_serv_line || !lss->lx_serv_aliases) { + errno = ENOMEM; return NULL; + } + + if (lss->lx_serv_fp || (lss->lx_serv_fp=fopen(TCP_PATH_SERVICES, "r"))) { + for(;;) { + char *s, *cp, **q; + + if ((s=fgets(lss->lx_serv_line, BUFSIZ, lss->lx_serv_fp)) == NULL) + break; + + if ((*s == '#') || ((cp=strpbrk(s, "#\n")) == NULL)) + continue; + *cp = '\0'; + lss->lx_serv.s_name = s; + + if ((s=strpbrk(s, " \t")) == NULL) + continue; + *s++ = '\0'; + while (*s == ' ' || *s == '\t') + s++; + if ((cp=strpbrk(s, ",/")) == NULL) + continue; + *cp++ = '\0'; + lss->lx_serv.s_port = htonl(atoi(s)); + lss->lx_serv.s_proto = cp; + + q = lss->lx_serv.s_aliases = lss->lx_serv_aliases; + if ((cp=strpbrk(cp, " \t")) != NULL) { + *cp++ = '\0'; + while (cp && *cp) { + if (*cp == ' ' || *cp == '\t') { + cp++; continue; + } + if (q < &lss->lx_serv_aliases[MAXALIASES - 1]) + *q++ = cp; + if ((cp=strpbrk(cp, " \t")) != NULL) + *cp++ = '\0'; + } + } + *q = NULL; return &lss->lx_serv; + } + } + + /* fall through */ + + default: + return NULL; + break; + } +} diff --git a/libnix/sources/socket/netdb/herrno.c b/libnix/sources/socket/netdb/herrno.c new file mode 100644 index 0000000..722f766 --- /dev/null +++ b/libnix/sources/socket/netdb/herrno.c @@ -0,0 +1,2 @@ +int h_errno = 0; +int network_installed = 0; diff --git a/libnix/sources/socket/netdb/herror.c b/libnix/sources/socket/netdb/herror.c new file mode 100644 index 0000000..e2a9076 --- /dev/null +++ b/libnix/sources/socket/netdb/herror.c @@ -0,0 +1,36 @@ +#include +#include +#include +// +#include "socket.h" + +char *hstrerror(int err) +{ static char *const h_errlist[] = { + "Resolver Error 0 (no error)", + "Unknown host", /* 1 HOST_NOT_FOUND */ + "Host name lookup failure", /* 2 TRY_AGAIN */ + "Unknown server error", /* 3 NO_RECOVERY */ + "No address associated with name", /* 4 NO_ADDRESS */ + }; + struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + struct TagItem list[] = { + {SBTM_GETREF(SBTC_HERRNOSTRPTR),0}, {TAG_END,TAG_END} + }; + list[0].ti_Data=(ULONG)&err; return (char *)TCP_SocketBaseTagList(list); + } + else if (err < 0) + return "Resolver internal error"; + else if (err < (int)(sizeof(h_errlist)/sizeof(h_errlist[0]))) + return h_errlist[err]; + return "Unknown resolver error"; +} + +void herror(const char *s) +{ + if (s && *s) + write(STDERR_FILENO,s,strlen(s)),write(STDERR_FILENO,": ",2); + s = hstrerror(h_errno); + write(STDERR_FILENO,s,strlen(s)),write(STDERR_FILENO,"\n",1); +} diff --git a/libnix/sources/socket/socket/__initsock.c b/libnix/sources/socket/socket/__initsock.c new file mode 100644 index 0000000..d1ac7a1 --- /dev/null +++ b/libnix/sources/socket/socket/__initsock.c @@ -0,0 +1,480 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "debuglib.h" +#include "select.h" +#include "socket.h" +#include "stabs.h" + +/* +** +*/ +extern int __argc; +extern char **__argv; + +/* +** +*/ +static ssize_t _sock_read(StdFileDes *fp,void *buf,size_t len) +{ + return recv(fp->lx_pos,buf,len,0); +} + +static ssize_t _sock_write(StdFileDes *fp,const void *buf,size_t len) +{ + return send(fp->lx_pos,buf,len,0); +} + +static int _sock_close(StdFileDes *fp) +{ struct SocketSettings *lss; + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + + case LX_AS225: + rc = SOCK_close(fp->lx_sock); + break; + + case LX_AMITCP: + rc = TCP_CloseSocket(fp->lx_sock); + break; + + default: + rc = 0; + break; + } + + return rc; +} + +static int _sock_dup(StdFileDes *fp) +{ struct SocketSettings *lss; + StdFileDes *fp2; + int rc; + + if ((fp2=_create_socket(fp->lx_family, fp->lx_domain, fp->lx_protocol)) == NULL) + return -1; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + + case LX_AS225: + /* only INET-225 has dup */ + if (lss->lx_SocketBase->lib_Version >= 8) + rc = SOCK_dup(fp->lx_sock); + else + rc = fp->lx_sock; + break; + + case LX_AMITCP: + rc = TCP_Dup2Socket(fp->lx_sock, -1); + break; + + default: + rc = -1; + break; + } + + if (rc >= 0) { + fp2->lx_sock = rc; rc = fp2->lx_pos; + } + else { + fp2->lx_inuse = 0; + } + + return rc; +} + +static int _sock_fstat(StdFileDes *fp,struct stat *sb) +{ long value; + int size = sizeof(value); + + memset(sb, 0, sizeof(*sb)); + +//sb->st_uid = 0; +//sb->st_gid = 0; + + if (getsockopt(fp->lx_sock, SOL_SOCKET, SO_SNDBUF,(void *)&value, &size) == 0) + sb->st_blksize = value; + + return 0; +} + +static int _sock_poll(StdFileDes *fp,int io_mode,struct SocketSettings *lss) +{ struct timeval tv = {0, 0}; + fd_set in, out, exc; + int rc; + + FD_ZERO(&in); + FD_ZERO(&out); + FD_ZERO(&exc); + + switch (io_mode) { + case SELMODE_IN: + FD_SET(fp->lx_sock,&in); + break; + + case SELMODE_OUT: + FD_SET(fp->lx_sock,&out); + break; + + case SELMODE_EXC: + FD_SET(fp->lx_sock,&exc); + break; + } + + switch (lss->lx_network_type) { + + case LX_AS225: + rc = SOCK_selectwait(fp->lx_sock, &in, &out, &exc, &tv, NULL); + break; + + case LX_AMITCP: + rc = TCP_WaitSelect(fp->lx_sock, &in, &out, &exc, &tv, NULL); + break; + + default: + rc = -1; + break; + } + + return ((rc == 1) ? 1 : 0); +} + +static int _sock_select(StdFileDes *fp,int select_cmd,int io_mode,fd_set *set,u_long *nfds) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (select_cmd == SELCMD_PREPARE) { + FD_SET(fp->lx_sock, set); + if (fp->lx_sock > *nfds) + *nfds = fp->lx_sock; + return (1L << lss->lx_sigurg | 1L << lss->lx_sigio); + } + + if (select_cmd == SELCMD_CHECK) + return FD_ISSET(fp->lx_sock, set); + + if (select_cmd == SELCMD_POLL) + return _sock_poll(fp, io_mode, lss); + + return 0; +} + +StdFileDes *_create_socket(int family,int type,int protocol) +{ extern StdFileDes *_allocfd(void); + StdFileDes *sfd = _allocfd(); + + if (sfd) { + sfd->lx_type = LX_SOCKET; + sfd->lx_inuse = 1; + sfd->lx_family = family; + sfd->lx_domain = type; + sfd->lx_protocol = protocol; + sfd->lx_read = _sock_read; + sfd->lx_write = _sock_write; + sfd->lx_close = _sock_close; + sfd->lx_dup = _sock_dup; + sfd->lx_fstat = _sock_fstat; + sfd->lx_select = _sock_select; + } + + return sfd; +} + +/* +** Redirect stdio (stdin, stdout and stderr) to/from socket 'sock'. +** This is done by dup2()'ing 'sock' to the level 1 files underneath +** the stdin, stdout and stderr. +*/ +static int set_socket_stdio(int sock) +{ + if (sock>=0 && dup2(sock,0)>=0 && dup2(sock,1)>=0 && dup2(sock,2)>=0) { + /* + * Close the original reference to the sock if necessary + */ + if (sock > 2) + close(sock); + + return 0; + } + + return -1; +} + +/* + * init_inet_daemon.c - obtain socket accepted by the inetd + * + * Copyright © 1994 AmiTCP/IP Group, + * Network Solutions Development Inc. + * All rights reserved. + * Portions Copyright © 1995 by Jeff Shepherd + */ + +static int init_inet_daemon(int *argc,char ***argv,struct SocketSettings *lss) +{ StdFileDes *fp = NULL; + int sock, err, i; + + lss->lx_isdaemon = 0; + + if (lss->lx_network_type == LX_AS225) { + + /* code loosely derived from timed.c from AS225r2 */ + /* this program was called from inetd if : + * 1> the first arg is a valid protocol(call getprotobyname) + * 2> inetd is started - FindPort("inetd") returns non-NULL + * NOT 3> argv[0] is the program found in inetd.conf for the program (scan inetd.conf) + */ + + /* save a little time with this comparison */ + if (err=-1,*argc >= 4) { + + struct servent *serv1 = SOCK_getservbyname((*argv)[1],"tcp"); + struct servent *serv2 = SOCK_getservbyname((*argv)[1],"udp"); + + if ((serv1 || serv2) && FindPort("inetd")) { + + long sock_arg; + + sock_arg = atol((*argv)[2]); + lss->lx_sockid = atoi((*argv)[3]); + sock = SOCK_inherit((void *)sock_arg); + if (sock >= 0) { + lss->lx_isdaemon = 1; /* I was started from inetd */ + do { + if ((fp=_create_socket(AF_INET, SOCK_STREAM, 0)) == NULL) + break; + fp->lx_sock = sock; + /* get rid of the args that AS225 put in */ + for (i=1; i < (*argc)-3; i++) + (*argv)[i] = (*argv)[i+3]; + (*argc) -= 3; + err = 0; + } while (0); + } + } + } + + return ((errno=err) ? -1 : fp->lx_pos); + } + + if (lss->lx_network_type == LX_AMITCP) { + struct Process *me = (struct Process *)FindTask(NULL); + struct DaemonMessage *dm = (struct DaemonMessage *)me->pr_ExitData; + + DB( BUG("daemon message is %lx\n", dm); ) + if (dm == NULL) { + /* + * No DaemonMessage, return error code - probably not an inet daemon + */ + return -1; + } + + /* + * Obtain the server socket + */ + sock = TCP_ObtainSocket(dm->dm_Id, dm->dm_Family, dm->dm_Type, 0); + DB( BUG("Obtained socket is %ld\n", sock); ) + + if (sock < 0) { + /* + * If ObtainSocket fails we need to exit with this specific exit code + * so that the inetd knows to clean things up + */ + exit(DERR_OBTAIN); + } + + err = -1; + + do { + + if ((fp=_create_socket(dm->dm_Family, dm->dm_Type, 0)) == NULL) + break; + fp->lx_sock = sock; + + DB( BUG("FD for daemon socket is %ld\n", fp->lx_pos); ) + + err = 0; + } while (0); + + return ((errno=err) ? -1 : fp->lx_pos); + } + + return -1; +} + +/* This is only needed for AS225 */ +static void shutdown_inet_daemon(struct SocketSettings *lss) +{ + if (lss->lx_network_type == LX_AS225 && lss->lx_isdaemon) { + + /* AS225 inet daemon stuff */ + struct inetmsg { struct Message msg; ULONG id; } inet_message; + + if ((inet_message.id=lss->lx_sockid)) { + + struct MsgPort *msgport,*replyport; + + if ((replyport=CreateMsgPort())) { + + inet_message.msg.mn_Node.ln_Type = NT_MESSAGE; + inet_message.msg.mn_ReplyPort = replyport; + inet_message.msg.mn_Length = sizeof(struct inetmsg); + + Forbid(); + if ((msgport=FindPort("inetd"))) { + PutMsg(msgport,&inet_message.msg); + /* we can't exit until we received a reply */ + WaitPort(replyport); + } + Permit(); + DeleteMsgPort(replyport); + } + } + } +} + +/* +** +*/ +struct SocketSettings *_lx_get_socket_settings(void) +{ static struct SocketSettings lx_socket_settings; + return &lx_socket_settings; +} + +/* +** +*/ +extern int network_installed; + +/* +** +*/ +void __initsocket(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + int sock; + + lss->lx_sigurg = AllocSignal(-1l); + lss->lx_sigio = AllocSignal(-1l); + DB( BUG("sigurg is %ld\nsigio is %ld\n", lss->lx_sigurg, lss->lx_sigio); ) + + /* We could check for the existance of the AMITCP port here + to make sure we're using the AmiTCP bsdsocket.library, + and not the bsdsocket.library emulation for AS225. + But in that case, the Miami package isn't recognized, + because they don't open an AMITCP port. Oh well... */ + lss->lx_network_type = LX_AMITCP; + if ((lss->lx_BsdSocketBase=OpenLibrary("bsdsocket.library",3))) { + struct Process *pr = (struct Process *)FindTask(NULL); + struct CommandLineInterface *cli = BADDR(pr->pr_CLI); + char *progname = (cli ? BADDR(cli->cli_CommandName) : pr->pr_Task.tc_Node.ln_Name); + struct TagItem list[] = { + { SBTM_SETVAL(SBTC_ERRNOPTR(sizeof(int))), (ULONG)&errno }, + { SBTM_SETVAL(SBTC_HERRNOLONGPTR), (ULONG)&h_errno }, + { SBTM_SETVAL(SBTC_LOGTAGPTR), (ULONG)progname }, + { SBTM_SETVAL(SBTC_SIGURGMASK), 0 }, + { SBTM_SETVAL(SBTC_SIGIOMASK), 0 }, + { SBTM_SETVAL(SBTC_BREAKMASK), SIGBREAKF_CTRL_C }, + { TAG_END,TAG_END } + }; + + DB( BUG("lss->lx_BsdSocketBase is %lx\n", lss->lx_BsdSocketBase); ) + DB( BUG("progname is %s\n", progname); ) + + list[3].ti_Data = (1L << lss->lx_sigurg); + list[4].ti_Data = (1L << lss->lx_sigio); + + /* I will assume this always is successful */ + TCP_SocketBaseTagList(list); + + /* only use usergroup stuff when AmiTCP is started only */ + /* I call OpenLibrary() with the full path since + * usergroup.library might open yet - some people bypass the + * "login" command which loads usergroup.library + */ + lss->lx_UserGroupBase = OpenLibrary("AmiTCP:libs/usergroup.library",1); + if (lss->lx_UserGroupBase) { + struct TagItem ug_list[] = { + { UGT_ERRNOPTR(sizeof(int)), (ULONG)&errno }, + { UGT_INTRMASK, SIGBREAKB_CTRL_C }, + { TAG_END,TAG_END } + }; + ug_SetupContextTagList(progname, ug_list); + + sock = init_inet_daemon(&__argc, &__argv, lss); + if (sock >= 0) { + set_socket_stdio(sock); + } + + network_installed = 1; + return; + } + CloseLibrary(lss->lx_BsdSocketBase); + } + + lss->lx_network_type = LX_AS225; + if ((lss->lx_SocketBase=OpenLibrary("socket.library",3))) { + + SOCK_setup_sockets(128, &errno); + + sock = init_inet_daemon(&__argc, &__argv, lss); + if (sock >= 0) { + set_socket_stdio(sock); + } + + network_installed = 1; + return; + } + + FreeSignal(lss->lx_sigio); + FreeSignal(lss->lx_sigurg); + + lss->lx_network_type = LX_NONE; +} + +void __exitsocket(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + DB( BUG("__exitsocket start\n"); ) + + shutdown_inet_daemon(lss); + + switch (lss->lx_network_type) { + case LX_AS225: + DB( BUG("lss->lx_SocketBase is %lx\n", lss->lx_SocketBase); ) + if (lss->lx_SocketBase) { + SOCK_cleanup_sockets(); + CloseLibrary(lss->lx_SocketBase); + FreeSignal(lss->lx_sigio); + FreeSignal(lss->lx_sigurg); + } + break; + + case LX_AMITCP: + DB( BUG("lss->lx_UserGroupBase is %lx\n", lss->lx_UserGroupBase); ) + if (lss->lx_UserGroupBase) + CloseLibrary(lss->lx_UserGroupBase); + DB( BUG("lss->lx_BsdSocketBase is %lx\n", lss->lx_BsdSocketBase); ) + if (lss->lx_BsdSocketBase) { + CloseLibrary(lss->lx_BsdSocketBase); + FreeSignal(lss->lx_sigio); + FreeSignal(lss->lx_sigurg); + } + break; + + default: + /* silence compiler */ + break; + } + + DB( BUG("__exitsocket done\n"); ) +} + +ADD2INIT(__initsocket, -35); // used to be -10 +ADD2EXIT(__exitsocket, -35); // need to clean up FD's before closing socket library diff --git a/libnix/sources/socket/socket/accept.c b/libnix/sources/socket/socket/accept.c new file mode 100644 index 0000000..ce364d9 --- /dev/null +++ b/libnix/sources/socket/socket/accept.c @@ -0,0 +1,39 @@ +#include +#include +// +#include "socket.h" + +int accept(int s, struct sockaddr *name, int *namelen) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + StdFileDes *fp,*fp2; + int rc; + + if ((fp=_lx_fhfromfd(s)) == NULL) + return NULL; + + if ((fp2=_create_socket(fp->lx_family, fp->lx_domain, fp->lx_protocol)) == NULL) + return -1; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_accept(fp->lx_sock, name, namelen); + break; + + case LX_AMITCP: + rc = TCP_Accept(fp->lx_sock, name, namelen); + break; + + default: + rc = -1; + break; + } + + if (rc >= 0) { + fp2->lx_sock = rc; rc = fp2->lx_pos; + } + else { + fp2->lx_inuse = 0; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/bind.c b/libnix/sources/socket/socket/bind.c new file mode 100644 index 0000000..91aa027 --- /dev/null +++ b/libnix/sources/socket/socket/bind.c @@ -0,0 +1,32 @@ +#include +#include +// +#include "socket.h" + +int bind(int s, const struct sockaddr *name, int namelen) +{ struct SocketSettings *lss; + StdFileDes *fp; + int oldlen,rc; + + if ((fp=_lx_fhfromfd(s))) { + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + oldlen = name->sa_len; + ((struct sockaddr *)name)->sa_len = 0; + rc = SOCK_bind(fp->lx_sock, name, namelen); + ((struct sockaddr *)name)->sa_len = oldlen; + break; + + case LX_AMITCP: + rc = TCP_Bind(fp->lx_sock, name, namelen); + break; + + default: + rc = -1; + break; + } + } + else rc = -1; + + return rc; +} diff --git a/libnix/sources/socket/socket/connect.c b/libnix/sources/socket/socket/connect.c new file mode 100644 index 0000000..d4948ea --- /dev/null +++ b/libnix/sources/socket/socket/connect.c @@ -0,0 +1,29 @@ +#include +#include +// +#include "socket.h" + +int connect(int s, const struct sockaddr *name, int namelen) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int oldlen,rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + oldlen = name->sa_len; + ((struct sockaddr *)name)->sa_len = 0; + rc = SOCK_connect(fp->lx_sock, name,namelen); + ((struct sockaddr *)name)->sa_len = oldlen; + break; + + case LX_AMITCP: + rc = TCP_Connect(fp->lx_sock, name,namelen); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/getpeername.c b/libnix/sources/socket/socket/getpeername.c new file mode 100644 index 0000000..5033196 --- /dev/null +++ b/libnix/sources/socket/socket/getpeername.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int getpeername(int s, struct sockaddr *asa, int *alen) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_getpeername(fp->lx_sock,asa,alen); + break; + + case LX_AMITCP: + rc = TCP_GetPeerName(fp->lx_sock,asa,alen); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/getsockname.c b/libnix/sources/socket/socket/getsockname.c new file mode 100644 index 0000000..f2a776f --- /dev/null +++ b/libnix/sources/socket/socket/getsockname.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int getsockname(int s, struct sockaddr *asa, int *alen) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_getsockname(fp->lx_sock,asa,alen); + break; + + case LX_AMITCP: + rc = TCP_GetSockName(fp->lx_sock,asa,alen); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/getsockopt.c b/libnix/sources/socket/socket/getsockopt.c new file mode 100644 index 0000000..12cab20 --- /dev/null +++ b/libnix/sources/socket/socket/getsockopt.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int getsockopt(int s, int level, int name, void *val, int *valsize) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_getsockopt(fp->lx_sock,level,name,val, valsize); + break; + + case LX_AMITCP: + rc = TCP_GetSockOpt(fp->lx_sock,level,name,val, valsize); + break; + + default: + rc = 0; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/ioctl.c b/libnix/sources/socket/socket/ioctl.c new file mode 100644 index 0000000..9166e2a --- /dev/null +++ b/libnix/sources/socket/socket/ioctl.c @@ -0,0 +1,85 @@ +#include +#include +#include +#include +#include +#include +#include +// +#include "socket.h" + +int ioctl(int s, unsigned long cmd, ...) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int arglen,inout,rc; + caddr_t data; + va_list va; + + if (fp->lx_type == LX_FILE) { + errno = EBADF; return -1; + } + + va_start(va, cmd); + inout = va_arg(va, int); + arglen = va_arg(va, int); + data = va_arg(va, caddr_t); + va_end(va); + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + + case LX_AS225: + + /* _SIGH_... they left almost everything neatly as it was in the BSD kernel + * code they used, but for whatever reason they decided they needed their + * own kind of ioctl encoding :-(( + * + * Well then, here we go, and map `normal' cmds into CBM cmds: + */ + + switch (cmd) { + case SIOCADDRT : cmd = ('r'<<8)|1; break; + case SIOCDELRT : cmd = ('r'<<8)|2; break; + case SIOCSIFADDR : cmd = ('i'<<8)|3; break; + case SIOCGIFADDR : cmd = ('i'<<8)|4; break; + case SIOCSIFDSTADDR : cmd = ('i'<<8)|5; break; + case SIOCGIFDSTADDR : cmd = ('i'<<8)|6; break; + case SIOCSIFFLAGS : cmd = ('i'<<8)|7; break; + case SIOCGIFFLAGS : cmd = ('i'<<8)|8; break; + case SIOCGIFCONF : cmd = ('i'<<8)|9; break; + case SIOCSIFMTU : cmd = ('i'<<8)|10; break; + case SIOCGIFMTU : cmd = ('i'<<8)|11; break; + case SIOCGIFBRDADDR : cmd = ('i'<<8)|12; break; + case SIOCSIFBRDADDR : cmd = ('i'<<8)|13; break; + case SIOCGIFNETMASK : cmd = ('i'<<8)|14; break; + case SIOCSIFNETMASK : cmd = ('i'<<8)|15; break; + case SIOCGIFMETRIC : cmd = ('i'<<8)|16; break; + case SIOCSIFMETRIC : cmd = ('i'<<8)|17; break; + case SIOCSARP : cmd = ('i'<<8)|18; break; + case SIOCGARP : cmd = ('i'<<8)|19; break; + case SIOCDARP : cmd = ('i'<<8)|20; break; + case SIOCATMARK : cmd = ('i'<<8)|21; break; + case FIONBIO : cmd = ('m'<<8)|22; break; + case FIONREAD : cmd = ('m'<<8)|23; break; + case FIOASYNC : cmd = ('m'<<8)|24; break; + case SIOCSPGRP : cmd = ('m'<<8)|25; break; + case SIOCGPGRP : cmd = ('m'<<8)|26; break; + + default: + /* we really don't have to bother the library with cmds we can't even + * map over... + */ + } + rc = SOCK_ioctl(fp->lx_sock,cmd,data); + break; + + case LX_AMITCP: + rc = TCP_IoctlSocket(fp->lx_sock,cmd,data); + break; + + default: + rc = 0; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/listen.c b/libnix/sources/socket/socket/listen.c new file mode 100644 index 0000000..4eba7a3 --- /dev/null +++ b/libnix/sources/socket/socket/listen.c @@ -0,0 +1,29 @@ +#include +#include +// +#include "socket.h" + +int listen(int s, int backlog) +{ struct SocketSettings *lss; + register StdFileDes *fp; + int rc; + + if ((fp=_lx_fhfromfd(s))) { + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_listen(fp->lx_sock, backlog); + break; + + case LX_AMITCP: + rc = TCP_Listen(fp->lx_sock, backlog); + break; + + default: + rc = -1; + break; + } + } + else rc = -1; + + return rc; +} diff --git a/libnix/sources/socket/socket/obtain_socket.c b/libnix/sources/socket/socket/obtain_socket.c new file mode 100644 index 0000000..251e499 --- /dev/null +++ b/libnix/sources/socket/socket/obtain_socket.c @@ -0,0 +1,22 @@ +#include "socket.h" + +int obtain_socket(long id, int inet, int stream, int protocol) +{ struct SocketSettings *lss; + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_inherit((void *)id); + break; + + case LX_AMITCP: + rc = TCP_ObtainSocket(id, inet, stream, protocol); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/recfrom.c b/libnix/sources/socket/socket/recfrom.c new file mode 100644 index 0000000..256697e --- /dev/null +++ b/libnix/sources/socket/socket/recfrom.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int recvfrom(int s, void *buf, size_t len, int flags, struct sockaddr *from, int *fromlen) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_recvfrom(fp->lx_sock,buf,len,flags, from, fromlen); + break; + + case LX_AMITCP: + rc = TCP_RecvFrom(fp->lx_sock,buf,len,flags, from, fromlen); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/recv.c b/libnix/sources/socket/socket/recv.c new file mode 100644 index 0000000..2842c30 --- /dev/null +++ b/libnix/sources/socket/socket/recv.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int recv(int s, void *buf, size_t len, int flags) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_recv(fp->lx_sock,buf,len,flags); + break; + + case LX_AMITCP: + rc = TCP_Recv(fp->lx_sock,buf,len,flags); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/recvmsg.c b/libnix/sources/socket/socket/recvmsg.c new file mode 100644 index 0000000..4438e00 --- /dev/null +++ b/libnix/sources/socket/socket/recvmsg.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int recvmsg(int s, struct msghdr *msg, int flags) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_recvmsg(fp->lx_sock,msg,flags); + break; + + case LX_AMITCP: + rc = TCP_RecvMsg(fp->lx_sock,msg,flags); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/release_socket.c b/libnix/sources/socket/socket/release_socket.c new file mode 100644 index 0000000..660fe68 --- /dev/null +++ b/libnix/sources/socket/socket/release_socket.c @@ -0,0 +1,33 @@ +#include +// +#include "socket.h" + +/* TODO: fix me */ +int release_socket(int s) +{ struct SocketSettings *lss; + /* TODO: Finish me */ + /* dup the socket first, since for AmiTCP, we can only release once */ + int s2 = dup(s); + /*StdFileDes *fp = _lx_fhfromfd(s);*/ + int rc = -1; + + if (s2 >= 0) { + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = (int)SOCK_release(s2); + SOCK_close(s2); + break; + + case LX_AMITCP: + rc = TCP_ReleaseSocket(s2, -1); + TCP_CloseSocket(s2); + break; + + default: + /* silence compiler */ + break; + } + } + + return rc; +} diff --git a/libnix/sources/socket/socket/send.c b/libnix/sources/socket/socket/send.c new file mode 100644 index 0000000..f10ccec --- /dev/null +++ b/libnix/sources/socket/socket/send.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int send(int s, const void *buf, size_t len, int flags) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_send(fp->lx_sock,buf,len,flags); + break; + + case LX_AMITCP: + rc = TCP_Send(fp->lx_sock,buf,len,flags); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/sendmsg.c b/libnix/sources/socket/socket/sendmsg.c new file mode 100644 index 0000000..2046495 --- /dev/null +++ b/libnix/sources/socket/socket/sendmsg.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int sendmsg(int s, const struct msghdr *msg, int flags) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_sendmsg(fp->lx_sock,msg,flags); + break; + + case LX_AMITCP: + rc = TCP_SendMsg(fp->lx_sock,msg,flags); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/sendto.c b/libnix/sources/socket/socket/sendto.c new file mode 100644 index 0000000..493325c --- /dev/null +++ b/libnix/sources/socket/socket/sendto.c @@ -0,0 +1,29 @@ +#include +#include +// +#include "socket.h" + +int sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, int tolen) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int oldlen,rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + oldlen = to->sa_len; + ((struct sockaddr *)to)->sa_len = 0; + rc = SOCK_sendto(fp->lx_sock,buf,len,flags,to,tolen); + ((struct sockaddr *)to)->sa_len = oldlen; + break; + + case LX_AMITCP: + rc = TCP_SendTo(fp->lx_sock,buf,len,flags,to,tolen); + break; + + default: + rc = -1; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/setsockopt.c b/libnix/sources/socket/socket/setsockopt.c new file mode 100644 index 0000000..ed75933 --- /dev/null +++ b/libnix/sources/socket/socket/setsockopt.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int setsockopt(int s, int level, int name, const void *val, int valsize) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_setsockopt(fp->lx_sock,level,name,val, valsize); + break; + + case LX_AMITCP: + rc = TCP_SetSockOpt(fp->lx_sock,level,name,val, valsize); + break; + + default: + rc = 0; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/shutdown.c b/libnix/sources/socket/socket/shutdown.c new file mode 100644 index 0000000..621916c --- /dev/null +++ b/libnix/sources/socket/socket/shutdown.c @@ -0,0 +1,26 @@ +#include +#include +// +#include "socket.h" + +int shutdown(int s, int how) +{ struct SocketSettings *lss; + StdFileDes *fp = _lx_fhfromfd(s); + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_shutdown(fp->lx_sock,how); + break; + + case LX_AMITCP: + rc = TCP_ShutDown(fp->lx_sock,how); + break; + + default: + rc = 0; + break; + } + + return rc; +} diff --git a/libnix/sources/socket/socket/socket.c b/libnix/sources/socket/socket/socket.c new file mode 100644 index 0000000..0e6e27f --- /dev/null +++ b/libnix/sources/socket/socket/socket.c @@ -0,0 +1,39 @@ +#include +#include +// +#include "debuglib.h" +#include "socket.h" + +int socket(int domain, int type, int protocol) +{ struct SocketSettings *lss; + StdFileDes *fp; + int rc; + + if ((fp=_create_socket(domain, type, protocol)) == NULL) + return -1; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_socket(domain, type, protocol); + break; + + case LX_AMITCP: + rc = TCP_Socket(domain, type, protocol); + break; + + default: + rc = -1; + break; + } + DB( BUG("Return from net_socket is %ld\n", rc); ) + + if (rc >= 0) { + fp->lx_sock = rc; rc = fp->lx_pos; + } + else { + fp->lx_inuse = 0; + } + + DB( BUG("Return fd from socket() is %ld, inuse is %ld\n", fp->lx_pos, fp->lx_inuse); ) + return rc; +} diff --git a/libnix/sources/socket/socket/socketpair.c b/libnix/sources/socket/socket/socketpair.c new file mode 100644 index 0000000..15eff44 --- /dev/null +++ b/libnix/sources/socket/socket/socketpair.c @@ -0,0 +1,8 @@ +#include +#include +#include + +int socketpair(int d, int type, int protocol, int sv[2]) +{ + errno = ENOSYS; return -1; +} diff --git a/libnix/sources/socket/stdio/open.c b/libnix/sources/socket/stdio/open.c new file mode 100644 index 0000000..ae26286 --- /dev/null +++ b/libnix/sources/socket/stdio/open.c @@ -0,0 +1,497 @@ +#include +#include +#include +#include +#include +#include +#define DEVICES_TIMER_H +#include +#include +#include +#include "debuglib.h" +#include "select.h" +#include "stdio.h" +#include "stabs.h" + +/* +** +*/ +extern void __seterrno(void); + +/* +** +*/ +struct MsgPort *__selport=0; + +/* +** +*/ +static StdFileDes **stdfiledes; +static unsigned long stdfilesize=0; +static long stderrdes=0; /* The normal Amiga shell sets no process->pr_CES stream + * -> we use Open("*",MODE_NEWFILE) in this case */ + +/* +** +*/ +static ssize_t _file_read(StdFileDes *sfd,void *buf,size_t nbytes) +{ long r; + __chkabort(); + if ((r=Read(sfd->lx_fh,buf,nbytes))!=EOF) + return r; + __seterrno(); return EOF; +} + +static ssize_t _file_write(StdFileDes *sfd,const void *buf,size_t nbytes) +{ long r; + __chkabort(); + switch((sfd->lx_oflags&O_APPEND)!=0) { + case 1: + if(!sfd->lx_isatty&&(Seek(sfd->lx_fh,0,OFFSET_END)==EOF)) + break; + default: + if((r=Write(sfd->lx_fh,(char *)buf,nbytes))!=EOF) + return r; + } + __seterrno(); return EOF; +} + +static int _file_close(StdFileDes *sfd) +{ + /* this is the synchronous way of dealing with packets that may + * arrive at a port. + */ + if (SELPKT_IN_USE(sfd)) + for (;;) { + struct StandardPacket *pkt = GetPacket(__selport); + if (pkt) { + DB( BUG("Got packet %lx, sp is %lx\n", pkt, sfd->lx_packet); ) + pkt->sp_Pkt.dp_Port = NULL; + if (pkt == sfd->lx_packet) + break; + } + else { + DB( BUG("Waiting for select packet\n"); ) + Wait(1<<__selport->mp_SigBit); + } + } + + FreeDosObject(DOS_STDPKT,sfd->lx_packet); + + if (!sfd->lx_sys&&!Close(sfd->lx_fh)) { + __seterrno(); return EOF; + } + + return 0; +} + +static int _file_dup(StdFileDes *sfd) +{ extern StdFileDes *_allocfd(void); + StdFileDes *fp2 = _allocfd(); + + if (fp2) { + int fd = fp2->lx_pos; + fp2->lx_inuse = 0; + stdfiledes[fd] = sfd; + sfd->lx_inuse++; + return fd; + } + + return -1; +} + +static int _file_fstat(StdFileDes *fp,struct stat *buf) +{ extern int __stat(struct stat *buf,struct FileInfoBlock *fib); + struct FileInfoBlock *fib; + long pos,len,fh; + + if ((fh=fp->lx_fh)) { + if ((fib=(struct FileInfoBlock *)AllocDosObject(DOS_FIB,NULL)) == NULL) { + __seterrno(); return -1; + } + } else return -1; + + memset(buf,0,sizeof(*buf)); + + buf->st_mode = S_IFCHR | 0777; + buf->st_nlink = 1; + buf->st_blksize = 512; + /*buf->st_blocks = 0;*/ + + if (((struct FileHandle *)BADDR(fh))->fh_Type) { + + if (!ExamineFH(fh,fib)) { + + len = 0; pos = Seek(fh,0,OFFSET_END); + if (pos >= 0 && (IoErr() != ERROR_ACTION_NOT_KNOWN)) + len = Seek(fh,pos,OFFSET_BEGINNING); + + fib->fib_DiskKey = (ino_t)~((LONG)fh); + fib->fib_DirEntryType = -1; + fib->fib_Size = len; + fib->fib_Protection = 0xff0; + fib->fib_NumBlocks = (len+=511,len>>=9); + DateStamp(&fib->fib_Date); + } + + __stat(buf,fib); + + if (Seek(fh,0,OFFSET_CURRENT),IoErr()) + buf->st_mode = ((buf->st_mode & ~S_IFREG) | S_IFCHR); + } + + FreeDosObject(DOS_FIB,fib); return 0; +} + +static int _file_select(StdFileDes *sfd,int select_cmd,int io_mode,fd_set *fd,u_long *sigs) +{ int result; + + DB( BUG("file_select %ld, %ld for fd %ld\n", select_cmd, io_mode, sfd->lx_pos); ) + switch (select_cmd) { + case SELCMD_PREPARE: + if (!SELPKT_IN_USE(sfd)) { + DB( BUG("Sending WAIT_FOR_CHAR packet\n"); ) + SelSendPacket1(sfd, __selport, ACTION_WAIT_CHAR, 10 * 1000000); + } + DB( BUG("Prepare for fd %ld is 0x%lx\n", sfd->lx_pos, (1 << __selport->mp_SigBit)); ) + return (1 << __selport->mp_SigBit); + + case SELCMD_CHECK: + /* only read is supported, other modes default to `ok' */ + if (io_mode != SELMODE_IN) + return 1; + + if (SELPKT_IN_USE(sfd) /*IsMsgPortEmpty(__selport)*/) { + DB( BUG("Check: packet in use\n"); ) + return 0; + } + + (void)GetPacket(__selport); + /* there are two possible answers: error (packet not supported) + * and the `real' answer. + * An error is treated as to allow input, so select() won't block + * indefinitely... + * & 1 converts dos-true (-1) into normal true (1) ;-) + */ + DB( BUG("LastError is %ld, LastResult is %ld\n", SelLastError(sfd), SelLastResult(sfd)); ) + + result = SelLastError(sfd); + /*(SelLastError(sfd) != 0) ? 1 : (SelLastResult(sfd) & 1);*/ + /* don't make __write() think its last packet failed.. */ + SelLastError(sfd) = 0; + sfd->lx_packet->sp_Pkt.dp_Port = NULL; /* packet not being used anymore */ + + DB( BUG("check result for fd %ld is %ld\n", sfd->lx_pos, result); ) + return result; + + case SELCMD_POLL: + if (io_mode != SELMODE_IN) + return 1; + result = !sfd->lx_isatty || WaitForChar(sfd->lx_fh, 0); + DB( BUG("Poll result for fd %ld is %ld\n", sfd->lx_pos, result); ) + return result; + } + /*NOTREACHED*/ + return 0; +} + +static void *_setup_file(StdFileDes *fp) +{ + fp->lx_type = LX_FILE; + fp->lx_inuse = 1; + fp->lx_isatty = IsInteractive(fp->lx_fh) ? -1 : 0; + fp->lx_packet = AllocDosObject(DOS_STDPKT,NULL); + fp->lx_read = _file_read; + fp->lx_write = _file_write; + fp->lx_fstat = _file_fstat; + fp->lx_close = _file_close; + fp->lx_dup = _file_dup; + fp->lx_select = _file_select; + + return fp->lx_packet; +} + +/* +** +*/ +StdFileDes *_allocfd(void) +{ StdFileDes *fp,**sfd; + int file,max; + + for(sfd=stdfiledes,max=stdfilesize,file=0;filelx_inuse) + break; + DB( BUG("Allocfd: file is %ld, max is %ld\n", file, max); ) + + if(file>SHRT_MAX) + { errno=EMFILE; + return NULL; + } + + if(file==max) + { if((sfd=realloc(stdfiledes,(file+1)*sizeof(fp)))==NULL) + { errno=ENOMEM; + return NULL; + } + stdfiledes=sfd; + stdfilesize++; + *(sfd=&sfd[file]) = 0; + } + + if((fp=sfd[0])==NULL) + { if((sfd[0]=fp=malloc(sizeof(*fp)))==NULL) + { errno=ENOMEM; + return NULL; + } + fp->lx_pos = file; + } + DB( BUG("Allocfd returning fd %ld\n", fp->lx_pos); ) + + return fp; +} + +/* +** +*/ +int open(const char *path,int flags,...) +{ extern char *__amigapath(const char *path); + StdFileDes *sfd; + +#ifdef IXPATHS + if((path=__amigapath(path))==NULL) + return -1; +#endif + + if ((sfd=_allocfd())) { + sfd->lx_sys=0; + sfd->lx_oflags=flags; + if ((sfd->lx_fh=Open((char *)path,flags&O_TRUNC?MODE_NEWFILE: + flags&(O_WRONLY|O_RDWR)?MODE_READWRITE:MODE_OLDFILE))) { + if (_setup_file(sfd)) + return sfd->lx_pos; + } + __seterrno(); + if (sfd->lx_fh) Close(sfd->lx_fh); + sfd->lx_inuse = 0; + } + + return -1; +} + +int close(int d) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + DB( BUG("Close: FD %ld, inuse is %ld\n", d, sfd->lx_inuse); ) + if (sfd) { + DB( BUG("close %ld, inuse is %ld\n", d, sfd->lx_inuse); ) + if (!(sfd->lx_inuse-=1)) { + sfd->lx_pos=d; return sfd->lx_close(sfd); + } + else { + stdfiledes[d] = 0; + } + } + + return 0; +} + +ssize_t read(int d,void *buf,size_t nbytes) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + return sfd->lx_read(sfd, buf, nbytes); + } + else { + errno = EBADF; + return -1; + } +} + +ssize_t write(int d,const void *buf,size_t nbytes) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd) { + return sfd->lx_write(sfd, buf, nbytes); + } + else { + errno = EBADF; + return -1; + } +} + +off_t lseek(int d,off_t offset,int whence) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + if (sfd && sfd->lx_type==LX_FILE) { + long r,file=sfd->lx_fh; + __chkabort(); + if (Seek(file,offset,whence==SEEK_SET?OFFSET_BEGINNING: + whence==SEEK_END?OFFSET_END:OFFSET_CURRENT)!=EOF) + if ((r=Seek(file,0,OFFSET_CURRENT))!=EOF) + return r; + __seterrno(); + } + else { + errno = EBADF; + } + + return -1; +} + +int isatty(int d) +{ StdFileDes *sfd = _lx_fhfromfd(d); + if (sfd && sfd->lx_type==LX_FILE) { + return sfd->lx_isatty; + } + else { + errno = EBADF; + return 0; + } +} + +int dup2(int d1,int d2) +{ + if (d1 != d2) { + + StdFileDes *sfd2 = _lx_fhfromfd(d2); + StdFileDes *sfd1 = _lx_fhfromfd(d1); + + DB( BUG("dup2 %ld %ld\n", d1, d2); ) + + if (!sfd1 || (d2 > (int)stdfilesize)) { + errno=EBADF; return -1; + } + + if (sfd2) { + close(d2); + //if (!sfd2->lx_inuse) + // free(sfd2); + } + + stdfiledes[d2] = stdfiledes[d1]; + stdfiledes[d1]->lx_inuse++; + + return d2; + } + + return d1; +} + +/* +** +*/ +int _lx_addflags(int d,int oflags) +{ StdFileDes *sfd = _lx_fhfromfd(d); + + return sfd&&sfd->lx_type==LX_FILE?sfd->lx_oflags|=oflags:0; +} + +/* +** convert fd to a StdFileDes +*/ +StdFileDes *_lx_fhfromfd(int d) +{ if(d<(int)stdfilesize) + { StdFileDes *sfd=stdfiledes[d]; + if(sfd&&sfd->lx_inuse) + return sfd; } + return NULL; +} + +#if 0 +/* +** convert StdFileDes->lx_sock to StdFileDes +*/ +StdFileDes *_lx_fdfromfh(int sock,LX_FILE_TYPE type) +{ int i; + for (i = 0; i < stdfilesize; i++) { + StdFileDes *sfd = stdfiledes[i]; + if (sfd->lx_inuse && sfd->lx_type == type) { + switch (sfd->lx_type) { + case LX_SOCKET: + if (sfd->lx_sock == sock) + return sfd; + break; + + case LX_FILE: + if (sfd->lx_fh == sock) + return sfd; + break; + } + } + } + return NULL; +} +#endif + +/* +** +*/ +void __initstdio(void) +{ extern struct WBStartup *_WBenchMsg; + StdFileDes *fp,**sfd; + + if((__selport=CreateMsgPort())) { + if((stdfiledes=sfd=(StdFileDes **)malloc(3*sizeof(StdFileDes *)))) { + if((sfd[STDIN_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + fp->lx_pos = STDIN_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_RDONLY; + fp->lx_fh = Input(); + if(_setup_file(fp)) { + ++stdfilesize; + if((sfd[STDOUT_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + fp->lx_pos = STDOUT_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_WRONLY; + fp->lx_fh = Output(); + if(_setup_file(fp)) { + ++stdfilesize; + if((sfd[STDERR_FILENO]=fp=(StdFileDes *)malloc(sizeof(StdFileDes)))) { + fp->lx_pos = STDERR_FILENO; + fp->lx_sys = -1; + fp->lx_oflags = O_WRONLY; + if((fp->lx_fh=((struct Process *)FindTask(NULL))->pr_CES)==0) + if(_WBenchMsg||(fp->lx_fh=stderrdes=Open("*",MODE_OLDFILE))==0) + fp->lx_fh=sfd[STDOUT_FILENO]->lx_fh; + if(_setup_file(fp)) { + ++stdfilesize; return; + } + } + } + } + } + } + } + } + + exit(20); +} +ADD2INIT(__initstdio,-30); + +void __exitstdio(void) +{ int i,max; + + DB( BUG("In __exitstdio max # of fds are %ld\n", stdfilesize); ) + + for(max=stdfilesize,i=0;ilx_inuse) { + DB( BUG("Closing file %ld\n", i); ) + DB( BUG("sfd is %lx\n", sfd); ) + DB( BUG("Type is %ld\n", sfd->lx_type); ) + DB( BUG("inuse is %ld\n", sfd->lx_inuse); ) + close(i); + } + } + DB( BUG("Done closing files\n"); ) + + if(stderrdes) { + DB( BUG("Closing stderrdes"); ) + Close(stderrdes); + } + + if(__selport) { + DeleteMsgPort(__selport); + } +} +ADD2EXIT(__exitstdio,-30); diff --git a/libnix/sources/socket/unistd/__inituser.c b/libnix/sources/socket/unistd/__inituser.c new file mode 100644 index 0000000..8b5d33b --- /dev/null +++ b/libnix/sources/socket/unistd/__inituser.c @@ -0,0 +1,237 @@ +#include +#include +#include +#include +#include "socket.h" +#include "stabs.h" + +/* +** +*/ +static int logname_valid = 1; +static char logname[MAXLOGNAME]; +static uid_t ruid, euid; +static gid_t rgid, egid; +static int ngroups; +static gid_t grouplist[NGROUPS_MAX]; + +/* +** +*/ +uid_t getuid(void) +{ + return ruid; +} + +uid_t geteuid(void) +{ + return euid; +} + +int setuid(uid_t uid) +{ + return setreuid((int)uid, (int)uid); +} + +int seteuid(uid_t uid) +{ + return setreuid(-1, (int)uid); +} + +int setreuid(int truid, int teuid) +{ + if (truid != -1) + ruid = (uid_t)truid; + + if (teuid != -1) + euid = (uid_t)teuid; + + /* just always succeed... */ + return 0; +} + +/* +** +*/ +gid_t getgid(void) +{ + return rgid; +} + +gid_t getegid(void) +{ + return egid; +} + +int setgid(gid_t tgid) +{ + return setregid((int)tgid, (int)tgid); +} + +int setegid(gid_t tgid) +{ + return setregid(-1, (int)tgid); +} + +int setregid(int trgid, int tegid) +{ + if (trgid != -1) + rgid = (gid_t)trgid; + + if (tegid != -1) { + egid = (gid_t)tegid; + grouplist[0] = egid; + } + + /* just always succeed... */ + return 0; +} + +/* +** +*/ +char *getlogin(void) +{ + return (logname_valid && *logname ? logname : 0); +} + +int setlogin(const char *name) +{ + strncpy (logname, name, MAXLOGNAME); + logname[MAXLOGNAME] = '\0'; + logname_valid = 1; + + return 0; +} + +/* +** +*/ +int getgroups(int gidsetlen, int *gidset) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) + return UG_getgroups(gidsetlen,gidset); + + /* parameter check */ + if (!gidset || gidsetlen < 0) { + errno = EFAULT; + return -1; + } + + if ((gidsetlen < 1) || (gidsetlen < ngroups)) { + errno = EINVAL; + return -1; + } + + for (gidsetlen = 0; gidsetlen < ngroups; gidsetlen++) + gidset[gidsetlen] = grouplist[gidsetlen]; + + return ngroups; +} + +int setgroups(int gidsetlen, const int *gidset) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) + return UG_setgroups(gidsetlen,gidset); + + /* parameter check */ + if (!gidset || gidsetlen < 0) { + errno = EFAULT; + return -1; + } + + if (!gidsetlen || gidsetlen > NGROUPS_MAX) { + errno = EINVAL; + return -1; + } + + ngroups = gidsetlen; + + for (gidsetlen = 0; gidsetlen < ngroups; gidsetlen++) { + grouplist[gidsetlen] = gidset[gidsetlen]; + } + + egid = (gid_t)(grouplist[0]); + + return 0; +} + +int initgroups(const char *name, int basegid) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + int gidset[NGROUPS_MAX], ngroups = 2; + struct group *gr; + char **grm; + + if (lss->lx_network_type == LX_AMITCP) + return UG_initgroups(name,basegid); + + /* parameter check */ + if (!name || basegid < 0) { + errno = EFAULT; return -1; + } + + gidset[0] = gidset[1] = (gid_t)basegid; + + setgrent(); + + while ((gr = getgrent())) { + if (gr->gr_gid != (gid_t)basegid) { + for (grm = gr->gr_mem; grm && *grm; grm++) { + if (!strcmp(name,*grm)) { + gidset[ngroups++] = (int)(gr->gr_gid); + break; + } + } + } + if (ngroups == NGROUPS_MAX) break; + } + + endgrent(); + + return setgroups(ngroups, gidset); +} + +/* +** +*/ +void __inituser(void) +{ struct passwd *pw; + char *var; + + if (((var=getenv("LOGNAME")) == NULL) && ((var=getenv("USER")) == NULL)) + var = "nobody"; + strncpy(logname,var,MAXLOGNAME); + logname[MAXLOGNAME] = '\0'; + logname_valid = 1; + + if ((pw=getpwnam(logname))) { + ruid = euid = pw->pw_uid; + rgid = egid = pw->pw_gid; + } + else { + ruid = euid = (uid_t)(-2); + rgid = egid = (uid_t)(-2); + } + + if (initgroups(logname, (int)rgid)) { + grouplist[1] = (int)rgid; + ngroups = 2; + } + + if ((var = getenv("UID"))) + ruid = euid = (uid_t)atoi(var); + + if ((var = getenv("GID"))) + rgid = egid = (gid_t)atoi(var); + + if ((var = getenv("EUID"))) + euid = (uid_t)atoi(var); + + if ((var = getenv("EGID"))) + egid = (gid_t)atoi(var); + + grouplist[0] = (int)egid; +} +ADD2INIT(__inituser, -9); diff --git a/libnix/sources/socket/unistd/crypt.c b/libnix/sources/socket/unistd/crypt.c new file mode 100644 index 0000000..949bd17 --- /dev/null +++ b/libnix/sources/socket/unistd/crypt.c @@ -0,0 +1,11 @@ +#include +// +#include "socket.h" + +char *crypt(const char *key, const char *setting) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) + return UG_crypt(key,setting); + return NULL; +} diff --git a/libnix/sources/socket/unistd/getdomainname.c b/libnix/sources/socket/unistd/getdomainname.c new file mode 100644 index 0000000..96b84b7 --- /dev/null +++ b/libnix/sources/socket/unistd/getdomainname.c @@ -0,0 +1,27 @@ +#include +#include +// +#include "socket.h" + +static inline int tcp_getdomainname(char *domainname, int dsize) +{ char hname[MAXHOSTNAMELEN+1], *dn; + + gethostname(hname, MAXHOSTNAMELEN); + strncpy(domainname, (dn=strchr(hname,'.')) ? dn+1 : hname, dsize-1); + domainname[dsize-1] = '\0'; return 0; +} + +int getdomainname(char *name, int namelen) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + switch (lss->lx_network_type) { + case LX_AMITCP: + return tcp_getdomainname(name, namelen); + + case LX_AS225: + return SOCK_getdomainname(name, namelen); + + default: + return -1; + } +} diff --git a/libnix/sources/socket/unistd/getgrent.c b/libnix/sources/socket/unistd/getgrent.c new file mode 100644 index 0000000..6c32c90 --- /dev/null +++ b/libnix/sources/socket/unistd/getgrent.c @@ -0,0 +1,228 @@ +#include +#include +#include +// +#include "socket.h" + +/* for AS225 */ +#define PATH_GROUP "inet:db/group" + +#define MAXGRP 200 +#define MAXLINELENGTH 1024 + +#define UNIX_STRSEP ":\n" +#define AMIGAOS_STRSEP "|\n" + +static gid_t nextgid; + +/* +** builtin group info +*/ +static const char *dummy_members[] = +{ 0 }; + +static const struct group builtin_wheel = +{ "wheel", "*", 0, (char **)dummy_members }; + +static const struct group builtin_nogroup = +{ "nogroup", "*", -2, (char **)dummy_members }; + +/* +** +*/ +static int gr_start(struct SocketSettings *lss) +{ + if (lss->lx_grp_fp) { + rewind(lss->lx_grp_fp); return 1; + } + return ((lss->lx_grp_fp = fopen(PATH_GROUP, "r")) ? 1 : 0); +} + +static int gr_scan(int search, gid_t gid, const char *name, struct SocketSettings *lss) +{ + if (!lss->lx_grp_line) + lss->lx_grp_line = malloc(MAXLINELENGTH + 1); + + if (!lss->lx_members) + lss->lx_members = malloc(MAXGRP * sizeof(char *)); + + if (!lss->lx_grp_line || !lss->lx_members) { + errno = ENOMEM; return 0; + } + + for (;;) { + char *sep, *bp, *cp, **m; + + if (!fgets(lss->lx_grp_line, MAXLINELENGTH, lss->lx_grp_fp)) + return 0; + + /* skip lines that are too big */ + if (!strchr(lss->lx_grp_line, '\n')) { + int ch; + + while ((ch = getc(lss->lx_grp_fp)) != '\n' && ch != EOF) + ; + + continue; + } + + sep = strchr(bp=lss->lx_grp_line,'|') ? AMIGAOS_STRSEP : UNIX_STRSEP; + + lss->lx_grp.gr_name = strsep(&bp, sep); + + if (search && name && strcmp(lss->lx_grp.gr_name, name)) + continue; + + lss->lx_grp.gr_passwd = strsep(&bp, sep); + + if (!(cp = strsep(&bp, sep))) + continue; + + lss->lx_grp.gr_gid = atoi(cp); + + if (search && !name && lss->lx_grp.gr_gid != gid) + continue; + + for (m = lss->lx_grp.gr_mem = lss->lx_members;; ++m) { + if (m == &lss->lx_members[MAXGRP - 1]) { + *m = NULL; break; + } + + if ((*m = strsep(&bp, ", \n")) == NULL) + break; + } + return 1; + } + /* NOTREACHED */ +} + +/* +** +*/ + +int setgrent(void) +{ + return setgroupent(0); +} + +int setgroupent(int stayopen) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + UG_setgrent(); + } + else if (nextgid=0,gr_start(lss)) { + lss->lx_grp_stayopen = stayopen; + } + + return 1; +} + +void endgrent(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + UG_endgrent(); + } + else if (nextgid=0,lss->lx_grp_fp) { + fclose(lss->lx_grp_fp); lss->lx_grp_fp = NULL; + } +} + +struct group *getgrent(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + return UG_getgrent(); + } + else if ((lss->lx_grp_fp || gr_start(lss)) && gr_scan(0, 0, NULL, lss)) { + return &lss->lx_grp; + } + else if (lss->lx_network_type == LX_NONE) { + char *name; + switch (nextgid) { + case 0: + nextgid = 1; + return (struct group *)&builtin_wheel; + default: + nextgid = -2; + if ((name = getenv("GROUP"))) + return getgrnam(name); + case (gid_t)(-2): + nextgid = -1; + return (struct group *)&builtin_nogroup; + case (gid_t)(-1): + //return NULL; + } + } + + return NULL; +} + +struct group *getgrgid(gid_t gid) +{ struct SocketSettings *lss; + + if (gid == (gid_t)(-2)) + return (struct group *)&builtin_nogroup; /* always handle nogroup */ + + lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + struct group *grp = UG_getgrgid(gid); + if (!grp) + errno = ug_GetErr(); + return grp; + } + else if (gr_start(lss)) { + int rval = gr_scan(1, gid, NULL, lss); + if (!lss->lx_grp_stayopen) + endgrent(); + return(rval ? &lss->lx_grp : NULL); + } + else if (lss->lx_network_type == LX_NONE) { + if (gid == 0) + return (struct group *)&builtin_wheel; + if ((gid == getgid()) && (lss->lx_grp.gr_name = getenv("GROUP"))) { + lss->lx_grp.gr_gid = gid; + lss->lx_grp.gr_passwd = "*"; + lss->lx_grp.gr_mem = (char **)dummy_members; + return &lss->lx_grp; + } + } + + return NULL; +} + +struct group *getgrnam(const char *name) +{ struct SocketSettings *lss; + + if (!strcmp(name,"nogroup")) + return (struct group *)&builtin_nogroup; /* always handle nogroup */ + + lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + struct group *grp = UG_getgrnam(name); + if (!grp) + errno = ug_GetErr(); + return grp; + } + else if (gr_start(lss)) { + int rval = gr_scan(1, 0, name, lss); + if (!lss->lx_grp_stayopen) + endgrent(); + return(rval ? &lss->lx_grp : NULL); + } + else if (lss->lx_network_type == LX_NONE) { + if (!strcmp(name,"wheel")) + return (struct group *)&builtin_wheel; + if ((lss->lx_grp.gr_name = getenv("GROUP")) && !strcmp(lss->lx_grp.gr_name,name)) { + lss->lx_grp.gr_gid = getgid(); + lss->lx_grp.gr_passwd = "*"; + lss->lx_grp.gr_mem = (char **)dummy_members; + return &lss->lx_grp; + } + } + + return NULL; +} diff --git a/libnix/sources/socket/unistd/gethostid.c b/libnix/sources/socket/unistd/gethostid.c new file mode 100644 index 0000000..da4f935 --- /dev/null +++ b/libnix/sources/socket/unistd/gethostid.c @@ -0,0 +1,23 @@ +#include +// +#include "socket.h" + +long gethostid(void) +{ struct SocketSettings *lss; + char hostname[MAXPATHLEN]; + struct hostent *ht; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + gethostname(hostname,MAXPATHLEN); + if ((ht=SOCK_gethostbyname(hostname))) + return (long)ht->h_addr; + return 0; + + case LX_AMITCP: + return (long)TCP_GetHostId(); + + default: + return -1; + } +} diff --git a/libnix/sources/socket/unistd/gethostname.c b/libnix/sources/socket/unistd/gethostname.c new file mode 100644 index 0000000..a66e3d8 --- /dev/null +++ b/libnix/sources/socket/unistd/gethostname.c @@ -0,0 +1,44 @@ +#include +#include +#include +// +#include "socket.h" + +int gethostname(char *name, int namelen) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type == LX_AMITCP) { + return TCP_GetHostName(name,namelen); + } + else { /* LX_AS225, default */ + char *host, domain[257+1]; + int len; + if ((host=getenv("HOSTNAME")) || (host=getenv("hostname"))) { + if (!strchr(host, '.')) { + strcpy(domain, host); + domain[len=strlen(domain)] = '.'; + if (++len,!getdomainname(domain+len,sizeof(domain)-len)) + domain[len]=0,host=domain; + } + } + else + host = "localhost"; + strncpy(name, host, namelen); return 0; + } +} + +int +sethostname (const char *name, int namelen) +{ +#if 0 // XXX + static char hostname[MAXHOSTNAMELEN] = "localhost"; + struct SocketSettings *lss = _lx_get_socket_settings(); + + if (lss->lx_network_type != LX_AMITCP) { + int len = namelen < sizeof (hostname) - 1 ? namelen : sizeof (hostname) - 1; + strncpy (hostname, name, len); + hostname[len] = 0; + } +#endif + return 0; +} diff --git a/libnix/sources/socket/unistd/getpwent.c b/libnix/sources/socket/unistd/getpwent.c new file mode 100644 index 0000000..a011bf6 --- /dev/null +++ b/libnix/sources/socket/unistd/getpwent.c @@ -0,0 +1,323 @@ +#include +#include +#include +#include +// +#define _KERNEL +#include "socket.h" + +#define PATH_PASSWD "etc:passwd" + +#define MAXLINELENGTH 1024 + +#define UNIX_STRSEP ":\n" +#define AMIGAOS_STRSEP "|\n" + +static uid_t nextuid; + +/* +** builtin passwd info +*/ +static const struct passwd builtin_root = +{ "root", "", 0, 0, 0, "", "The Master of All Things", "SYS:", "sh", 0 }; + +static const struct passwd builtin_nobody = +{ "nobody", "", -2, -2, 0, "", "The Anonymous One", "T:", "sh", 0 }; + +/* +** +*/ +static int pw_start(struct SocketSettings *lss) +{ + if (lss->lx_pwd_fp) { + rewind(lss->lx_pwd_fp); return 1; + } + return ((lss->lx_pwd_fp = fopen(PATH_PASSWD, "r")) ? 1 : 0); +} + +static int pw_scan(int search, uid_t uid, const char *name, struct SocketSettings *lss) +{ + if (!lss->lx_pwd_line) + if ((lss->lx_pwd_line=malloc(MAXLINELENGTH + 1)) == NULL) { + errno = ENOMEM; return 0; + } + + for (;;) { + char *sep, *bp, *cp; + + if (!fgets(lss->lx_pwd_line, MAXLINELENGTH, lss->lx_pwd_fp)) + return 0; + + /* skip lines that are too big */ + if (!strchr(lss->lx_pwd_line, '\n')) { + int ch; + + while ((ch = getc(lss->lx_pwd_fp)) != '\n' && ch != EOF) + ; + + continue; + } + + sep = strchr(bp=lss->lx_pwd_line,'|') ? AMIGAOS_STRSEP : UNIX_STRSEP; + + lss->lx_pwd.pw_name = strsep(&bp, sep); + + if (search && name && strcmp(lss->lx_pwd.pw_name, name)) + continue; + + lss->lx_pwd.pw_passwd = strsep(&bp, sep); + + if (!(cp = strsep(&bp, sep))) + continue; + + lss->lx_pwd.pw_uid = (uid_t)atoi(cp); + + if (search && !name && lss->lx_pwd.pw_uid != uid) + continue; + + if (!(cp = strsep(&bp, sep))) + continue; + + lss->lx_pwd.pw_gid = (gid_t)atoi(cp); + + lss->lx_pwd.pw_gecos = strsep(&bp, sep); + if (!lss->lx_pwd.pw_gecos) + continue; + + lss->lx_pwd.pw_dir = strsep(&bp, sep); + if (!lss->lx_pwd.pw_dir) + continue; + + lss->lx_pwd.pw_shell = strsep(&bp, "\n"); + if (!lss->lx_pwd.pw_shell) + continue; + + return 1; + } + /* NOTREACHED */ +} + +/* +** change the AS225/INet225's password structure to the global format +*/ +static struct passwd *__AS225InetPwd(struct AS225_passwd *pwd,struct SocketSettings *lss) +{ + if (pwd) { + lss->lx_pwd.pw_name = pwd->pw_name; + lss->lx_pwd.pw_passwd = pwd->pw_passwd; + lss->lx_pwd.pw_uid = pwd->pw_uid; + lss->lx_pwd.pw_gid = pwd->pw_gid; + lss->lx_pwd.pw_change = time((time_t *)NULL); + lss->lx_pwd.pw_class = NULL; + lss->lx_pwd.pw_gecos = pwd->pw_gecos; + lss->lx_pwd.pw_dir = pwd->pw_dir; + lss->lx_pwd.pw_shell = pwd->pw_shell; + lss->lx_pwd.pw_expire = (time_t)-1; + lss->lx_pwd.pw_change = (time_t)-1; + return &lss->lx_pwd; + } + return NULL; +} + +/* +** change the AmiTCP password structure to the global format +*/ +static struct passwd *__TCP2InetPwd(struct TCP_passwd *pwd,struct SocketSettings *lss) +{ + if (pwd) { + lss->lx_pwd.pw_name = pwd->pw_name; + lss->lx_pwd.pw_passwd = pwd->pw_passwd; + lss->lx_pwd.pw_uid = pwd->pw_uid; + lss->lx_pwd.pw_gid = pwd->pw_gid; + lss->lx_pwd.pw_change = time((time_t *)NULL); + lss->lx_pwd.pw_class = NULL; + lss->lx_pwd.pw_gecos = pwd->pw_gecos; + lss->lx_pwd.pw_dir = pwd->pw_dir; + lss->lx_pwd.pw_shell = pwd->pw_shell; + lss->lx_pwd.pw_expire = (time_t)-1; + return &lss->lx_pwd; + } + return NULL; +} + +/* +** +*/ + +int setpwent(void) +{ + return setpassent(0); +} + +int setpassent(int stayopen) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_setpwent(stayopen); + break; + + case LX_AMITCP: + UG_setpwent(); + break; + + default: + if (nextuid=0,pw_start(lss)) + lss->lx_pwd_stayopen = stayopen; + break; + } + + return 1; +} + +void endpwent(void) +{ struct SocketSettings *lss; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + SOCK_endpwent(); + break; + + case LX_AMITCP: + UG_endpwent(); + break; + + default: + if (nextuid=0,lss->lx_pwd_fp) { + fclose(lss->lx_pwd_fp); lss->lx_pwd_fp = NULL; + } + break; + } +} + +struct passwd *getpwent(void) +{ struct SocketSettings *lss = _lx_get_socket_settings(); + struct passwd *pwd; + char *name; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return __AS225InetPwd(SOCK_getpwent(),lss); + break; + + case LX_AMITCP: + if ((pwd=__TCP2InetPwd(UG_getpwent(),lss)) == NULL) + errno = ug_GetErr(); + return pwd; + break; + + default: + if ((lss->lx_pwd_fp || pw_start(lss)) && pw_scan(0, 0, NULL, lss)) + return &lss->lx_pwd; + switch (nextuid) { + case 0: + nextuid = 1; + return (struct passwd *)&builtin_root; + default: + nextuid = -2; + if ((name = (char *)getlogin())) + return getpwnam(name); + case (uid_t)(-2): + nextuid = -1; + return (struct passwd *)&builtin_nobody; + case (uid_t)(-1): + return 0; + } + break; + } +} + +struct passwd *getpwuid(uid_t uid) +{ struct SocketSettings *lss; + struct passwd *pwd; + + if (uid == (uid_t)(-2)) + return (struct passwd *)&builtin_nobody; /* always handle nobody */ + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return __AS225InetPwd(SOCK_getpwuid(uid),lss); + break; + + case LX_AMITCP: + /* Don't do this if uid == -2 (nobody2) */ + /* This happens when someone doesn't use AmiTCP's login */ + if (uid != (uid_t)-2) { + if ((pwd=__TCP2InetPwd(UG_getpwuid(uid),lss)) == NULL) + errno = ug_GetErr(); + return pwd; + } + else { + return getpwnam(getenv("USER")); + } + break; + + default: + if (pw_start(lss)) { + int rval = pw_scan(1, uid, NULL, lss); + if (!lss->lx_pwd_stayopen) + endpwent(); + return (rval ? &lss->lx_pwd : NULL); + } + if (uid == 0) + return (struct passwd *)&builtin_root; + if ((uid == getuid()) && (lss->lx_pwd.pw_name=getlogin())) + if ((lss->lx_pwd.pw_dir=getenv("HOME")) == NULL) + lss->lx_pwd.pw_dir = "SYS:"; + if ((lss->lx_pwd.pw_gecos=getenv("REALNAME")) == NULL) + lss->lx_pwd.pw_gecos = "Amiga User"; + lss->lx_pwd.pw_uid = uid; + lss->lx_pwd.pw_gid = getgid(); + lss->lx_pwd.pw_change = 0; + lss->lx_pwd.pw_expire = 0; + lss->lx_pwd.pw_class = ""; + lss->lx_pwd.pw_passwd = "*"; + lss->lx_pwd.pw_shell = "sh"; + return &lss->lx_pwd; + break; + } +} + +struct passwd *getpwnam(const char *name) +{ struct SocketSettings *lss; + struct passwd *pwd; + + if (!strcmp(name,"nobody")) + return (struct passwd *)&builtin_nobody; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + return __AS225InetPwd(SOCK_getpwnam((char *)name),lss); + break; + + case LX_AMITCP: + if ((pwd=__TCP2InetPwd(UG_getpwnam(name),lss)) == NULL) + errno = ug_GetErr(); + return pwd; + break; + + default: + if (pw_start(lss)) { + int rval = pw_scan(1, 0, name, lss); + if (!lss->lx_pwd_stayopen) + endpwent(); + return (rval ? &lss->lx_pwd : NULL); + } + if (!strcmp(name,"root")) + return (struct passwd *)&builtin_root; + if ((lss->lx_pwd.pw_name=getlogin()) && !strcmp(lss->lx_pwd.pw_name,name)) + if ((lss->lx_pwd.pw_dir=getenv("HOME")) == NULL) + lss->lx_pwd.pw_dir = "SYS:"; + if ((lss->lx_pwd.pw_gecos=getenv("REALNAME")) == NULL) + lss->lx_pwd.pw_gecos = "Amiga User"; + lss->lx_pwd.pw_uid = getuid(); + lss->lx_pwd.pw_gid = getgid(); + lss->lx_pwd.pw_change = 0; + lss->lx_pwd.pw_expire = 0; + lss->lx_pwd.pw_class = ""; + lss->lx_pwd.pw_passwd = "*"; + lss->lx_pwd.pw_shell = "sh"; + return &lss->lx_pwd; + break; + } +} diff --git a/libnix/sources/socket/unistd/select.c b/libnix/sources/socket/unistd/select.c new file mode 100644 index 0000000..83e7f43 --- /dev/null +++ b/libnix/sources/socket/unistd/select.c @@ -0,0 +1,280 @@ +#include +#include +#include +#include +#include +#include +#include +#include "debuglib.h" +#include "select.h" +#include "socket.h" +#include "stabs.h" + +/* +** +*/ +static struct MsgPort *_tport=NULL; +static struct timerequest *_treq=NULL; + +/* +** +*/ +void __setupselect(void) +{ + if (((_tport=CreateMsgPort())==NULL) || + ((_treq=CreateIORequest(_tport,sizeof(*_treq)))==NULL)) + exit(20); +} +ADD2INIT(__setupselect,-10); + +void __cleanupselect(void) +{ + if (_treq) { + DeleteIORequest(_treq); _treq=NULL; + } + + if (_tport) { + DeleteMsgPort(_tport); _tport=NULL; + } +} +ADD2EXIT(__cleanupselect,-10); + +/* +** +*/ +static inline void handle_select_port(void) +{ extern struct MsgPort *__selport; + struct StandardPacket *pkt; + + while((pkt=GetPacket(__selport))) { + DB( BUG("handle_select_port got packet %lx\n", pkt); ) + pkt->sp_Pkt.dp_Port = NULL; + } +} + +static inline void setcopy(int nfd, u_int *ifd, u_int *ofd) +{ + /* this procedure is here, because it's "normal" that if you only + * want to select on fd 0,1,2 eg. you only pass a long to select, + * not a whole fd_set, so we can't simply copy over results in the + * full size of an fd_set.. */ + + /* we have to copy that many longs... */ + for (nfd=(nfd+31)>>5; nfd; *ofd++=*ifd++,--nfd); +} + +static inline int net_select(int s, fd_set *in, fd_set *out, fd_set *exc, struct timeval *timeout, u_long *sigs) +{ struct SocketSettings *lss; + int rc; + + switch (lss=_lx_get_socket_settings(),lss->lx_network_type) { + case LX_AS225: + rc = SOCK_selectwait(s, in, out, exc, timeout, sigs); + break; + + case LX_AMITCP: + rc = TCP_WaitSelect(s, in, out, exc, timeout, sigs); + break; + + default: + rc = -1; + break; + } + + return rc; +} + +static inline int lx_select(int nfd, fd_set *ifd, fd_set *ofd, fd_set *efd, struct timeval *timeout, u_long *mask) +{ int i, waitin, waitout, waitexc, dotout, result, skipped_wait; + u_long net_nfds, wait_sigs, recv_wait_sigs=0, origmask = mask ? *mask : 0; + StdFileDes *f; + + /* as long as I don't support anything similar to a network, I surely + * won't get any exceptional conditions, so *efd is mapped into + * *ifd, if it's set. + */ + + /* first check, that all included descriptors are valid and support + * the requested operation. If the user included a request to wait + * for a descriptor to be ready to read, while the descriptor was only + * opened for writing, the requested bit is immediately cleared + */ + waitin = waitout = waitexc = 0; + /*if (nfd > NOFILE) nfd = NOFILE;*/ + + for (i = 0; i < nfd; i++) { + if (ifd && FD_ISSET(i, ifd) && (f = _lx_fhfromfd(i))) { + if (!f->lx_read || !f->lx_select) + FD_CLR(i, ifd); + else + ++waitin; + } + + if (ofd && FD_ISSET(i, ofd) && (f = _lx_fhfromfd(i))) { + if (!f->lx_write || !f->lx_select) + FD_CLR(i, ofd); + else + ++waitout; + } + + if (efd && FD_ISSET(i, efd) && (f = _lx_fhfromfd(i))) { + /* question: can an exceptional condition also occur on a + * write-only fd?? */ + if (!f->lx_read || !f->lx_select) + FD_CLR(i, efd); + else + ++waitexc; + } + } + + dotout = (timeout && timerisset(timeout)); + + for (skipped_wait = 0; ; skipped_wait=1) { + fd_set readyin, readyout, readyexc; + fd_set netin, netout, netexc; + extern int network_installed; + int tout, readydesc, cmd; + + FD_ZERO(&readyin); + FD_ZERO(&readyout); + FD_ZERO(&readyexc); + + if (network_installed) { + FD_ZERO(&netin); + FD_ZERO(&netout); + FD_ZERO(&netexc); + net_nfds = 0; + } + + handle_select_port(); + + tout = readydesc = 0; + + wait_sigs = SIGBREAKF_CTRL_C | origmask; + + if (cmd=SELCMD_POLL,skipped_wait) { + + if (dotout) { + _treq->tr_node.io_Command = TR_ADDREQUEST; + _treq->tr_time.tv_sec = timeout->tv_sec; + _treq->tr_time.tv_usec = timeout->tv_usec; + SendIO(&_treq->tr_node); + /* clear the bit, it's used for sync packets too, and might be set */ + SetSignal (0, 1 << _tport->mp_SigBit); + wait_sigs |= 1 << _tport->mp_SigBit; + } + + /* have all watched files get prepared for selecting */ + for (i = 0; i < nfd; i++) { + if (ifd && FD_ISSET (i, ifd) && (f = _lx_fhfromfd(i))) + wait_sigs |= f->lx_select (f, SELCMD_PREPARE, SELMODE_IN, &netin, &net_nfds); + if (ofd && FD_ISSET (i, ofd) && (f = _lx_fhfromfd(i))) + wait_sigs |= f->lx_select (f, SELCMD_PREPARE, SELMODE_OUT, &netout, &net_nfds); + if (efd && FD_ISSET (i, efd) && (f = _lx_fhfromfd(i))) + wait_sigs |= f->lx_select (f, SELCMD_PREPARE, SELMODE_EXC, &netexc, &net_nfds); + } + + /* now wait for all legally possible signals, this includes BSD + * signals (but want at least one signal set!) + */ + if (network_installed) { + int res; + DB( BUG("Calling _net_select, signals are %lx\n", wait_sigs); ) + res = net_select(net_nfds, &netin, &netout, &netexc, NULL, &wait_sigs); + recv_wait_sigs = wait_sigs; + DB( BUG("Net select returns %ld, wait_sigs are %lx\n", res, wait_sigs); ) + } + else + while (!(recv_wait_sigs = Wait (wait_sigs))) ; + + if (mask) + *mask = recv_wait_sigs & origmask; + + if (dotout) { + /* IMPORTANT: unqueue the timer request BEFORE polling the fd's, + * or __wait_packet() will treat the timer request + * as a packet... + */ + if (!CheckIO(&_treq->tr_node)) + AbortIO(&_treq->tr_node); + else + recv_wait_sigs |= 1 << _tport->mp_SigBit; + WaitIO(&_treq->tr_node); + } + + handle_select_port(); + + cmd = SELCMD_CHECK; + } + + /* no matter what caused Wait() to return, wait for all requests + * to complete (we CAN'T abort a DOS packet, sigh...) + */ + + /* collect information from the file descriptors */ + for (i = 0; i < nfd; i++) { + if (ifd && FD_ISSET (i, ifd) && (f = _lx_fhfromfd(i)) + && f->lx_select (f, cmd, SELMODE_IN, &netin, NULL)) { + DB( BUG("Select: fd %ld, has data ready for reading\n", i); ) + FD_SET (i, &readyin); + ++readydesc; + } + + if (ofd && FD_ISSET (i, ofd) && (f = _lx_fhfromfd(i)) + && f->lx_select (f, cmd, SELMODE_OUT, &netout, NULL)) { + DB( BUG("Select: fd %ld, has data ready for writing\n", i); ) + FD_SET (i, &readyout); + ++readydesc; + } + + if (efd && FD_ISSET (i, efd) && (f = _lx_fhfromfd(i)) + && f->lx_select (f, cmd, SELMODE_EXC, &netexc, NULL)) { + DB( BUG("Select: fd %ld, has an exception\n", i); ) + FD_SET (i, &readyexc); + ++readydesc; + } + } + + /* we have a timeout condition, if readydesc == 0, dotout == 1 and + * end_time < current time + */ + + DB( BUG("After loop, readydesc is %ld\n", readydesc); ) + + if (!readydesc && dotout) + tout = recv_wait_sigs & (1 << _tport->mp_SigBit); + + DB( BUG("readydesc is %ld, tout is %ld, timeout is %lx\n", readydesc, tout, timeout); ) + + if (readydesc || tout || (timeout && !timerisset(timeout))) { + if (ifd) setcopy(nfd, (u_int *)&readyin, (u_int *)ifd); + if (ofd) setcopy(nfd, (u_int *)&readyout, (u_int *)ofd); + if (efd) setcopy(nfd, (u_int *)&readyexc, (u_int *)efd); + result = readydesc; /* ok for tout, since then readydesc is already 0 */ + DB( BUG("Breaking out of loop, result is %ld\n", result); ) + break; + } + + if (recv_wait_sigs & SIGBREAKF_CTRL_C) { + DB( BUG("Found CTRL-C\n"); ) + /* clear it and resend it so the outer stuff can catch it */ + SetSignal(0, SIGBREAKF_CTRL_C); + Signal(FindTask(NULL), SIGBREAKF_CTRL_C); + result = -1; + break; + } + } + + if (recv_wait_sigs == (u_long)-1) + return -1; + + /* have to set this here, since errno can be changed in signal handlers */ + if (result == -1) + errno = EINTR; + + DB( BUG("SELECT: returning %ld\n", result); ) + return result; +} + +int select(int nfd, fd_set *ifd, fd_set *ofd, fd_set *efd, struct timeval *timeout) +{ return lx_select(nfd, ifd, ofd, efd, timeout, NULL); } diff --git a/libnix/sources/stack/Makefile.in b/libnix/sources/stack/Makefile.in index 7b13e5a..0eaf709 100644 --- a/libnix/sources/stack/Makefile.in +++ b/libnix/sources/stack/Makefile.in @@ -4,11 +4,12 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### @@ -16,9 +17,7 @@ ifneq ($(TARGET),clean) include ../../sources/stack/filelist endif -OPTIONS=-I $(srcdir)/../headers -I../../sources/headers $(CFLAGS) - -SOURCEFILES=*.c +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) REDEF=-D_DOSBase=___DOSBase @@ -39,8 +38,8 @@ clean: veryclean: -rm -rf * -libstack.a: $(OBJECTS) ../../sources/stack/makefile ../../sources/stack/filelist +libstack.a: $(OBJECTS) ../../sources/stack/Makefile ../../sources/stack/filelist -rm -f $@ - ar -q $@ $(OBJECTS) + $(AR) -q $@ $(OBJECTS) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/stack/init_stk.c b/libnix/sources/stack/init_stk.c index 63c1f2e..f74ed32 100755 --- a/libnix/sources/stack/init_stk.c +++ b/libnix/sources/stack/init_stk.c @@ -1,10 +1,10 @@ #include #include -#include +#include "stabs.h" extern ULONG __stk_safezone; -APTR *__stackborders,__stk_limit; +APTR *__stackborders=0,__stk_limit=0; /* * This way to find the bottom of the current stackframe diff --git a/libnix/sources/stack/link_a5_0_f.c b/libnix/sources/stack/link_a5_0_f.c index 3882157..8cf8bde 100755 --- a/libnix/sources/stack/link_a5_0_f.c +++ b/libnix/sources/stack/link_a5_0_f.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .text diff --git a/libnix/sources/stack/link_a5_d0_f.c b/libnix/sources/stack/link_a5_d0_f.c index 9e2ed12..8f68d3f 100755 --- a/libnix/sources/stack/link_a5_d0_f.c +++ b/libnix/sources/stack/link_a5_d0_f.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .text diff --git a/libnix/sources/stack/stkchk_d0.c b/libnix/sources/stack/stkchk_d0.c index 05241aa..3d9fbcb 100755 --- a/libnix/sources/stack/stkchk_d0.c +++ b/libnix/sources/stack/stkchk_d0.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .text diff --git a/libnix/sources/stack/stkext.c b/libnix/sources/stack/stkext.c index 8952046..254ddf1 100755 --- a/libnix/sources/stack/stkext.c +++ b/libnix/sources/stack/stkext.c @@ -1,5 +1,5 @@ -#include -#include +#include "bases.h" +#include "stabs.h" asm(" .text diff --git a/libnix/sources/stack/stkovf.c b/libnix/sources/stack/stkovf.c index 8150fc9..5a8d2cf 100755 --- a/libnix/sources/stack/stkovf.c +++ b/libnix/sources/stack/stkovf.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .text diff --git a/libnix/sources/stack/stkrst.c b/libnix/sources/stack/stkrst.c index efc168b..469f5ed 100755 --- a/libnix/sources/stack/stkrst.c +++ b/libnix/sources/stack/stkrst.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" | the stack consists of a single linked linear list like this: diff --git a/libnix/sources/stack/stkrst_f.c b/libnix/sources/stack/stkrst_f.c index e2527c0..20271b0 100755 --- a/libnix/sources/stack/stkrst_f.c +++ b/libnix/sources/stack/stkrst_f.c @@ -1,4 +1,4 @@ -#include +#include "bases.h" asm(" .text diff --git a/libnix/sources/stack/sub_d0_sp.c b/libnix/sources/stack/sub_d0_sp.c index 75fbed3..45576a6 100755 --- a/libnix/sources/stack/sub_d0_sp.c +++ b/libnix/sources/stack/sub_d0_sp.c @@ -1,5 +1,5 @@ -#include -#include +#include "bases.h" +#include "stabs.h" asm(" .text diff --git a/libnix/sources/startup/Makefile.in b/libnix/sources/startup/Makefile.in index 7ff6cbb..d5674dd 100644 --- a/libnix/sources/startup/Makefile.in +++ b/libnix/sources/startup/Makefile.in @@ -8,15 +8,16 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### -OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers -O -fomit-frame-pointer +OPTIONS=-I$(srcdir)/../headers -O -fomit-frame-pointer %.o: %.c $(CC) $(OPTIONS) -c $^ 2>&1|tee $*.err @@ -25,7 +26,7 @@ OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers -O -fomit-frame-pointer .PHONY: all filelist subdirs clean veryclean -all: nrcrt0.o nbcrt0.o ncrt0.o libinit.o libinitr.o#devinit.o +all: nrcrt0.o nbcrt0.o ncrt0.o libinit.o libinitr.o devinit.o subdirs: diff --git a/libnix/sources/startup/devinit.c b/libnix/sources/startup/devinit.c index aa98d4c..3f6da9e 100755 --- a/libnix/sources/startup/devinit.c +++ b/libnix/sources/startup/devinit.c @@ -1,22 +1,10 @@ /******************************************************************************/ /* */ -/* this works with gcc too and makes life easier */ +/* our include */ /* */ /******************************************************************************/ -#define _USEOLDEXEC_ - -/******************************************************************************/ -/* */ -/* includes */ -/* */ -/******************************************************************************/ - -#include -#include -#include #include "libinit.h" -#include "stabs.h" /******************************************************************************/ /* */ @@ -24,218 +12,21 @@ /* */ /******************************************************************************/ -int safefail() +LONG safefail(VOID) { return -1; } /******************************************************************************/ /* */ -/* imports */ +/* a do nothing stub (required!) */ /* */ /******************************************************************************/ -extern const UWORD DevVersion; -extern const UWORD DevRevision; - -extern const BYTE DevName[]; -extern const BYTE DevIdString[]; - -extern APTR __FuncTable__[]; - -extern int __UserDevInit(_DEV *); -extern int __UserDevOpen(struct IORequest *,ULONG,ULONG); -extern VOID __UserDevClose(); -extern VOID __UserDevCleanUp(); - -/******************************************************************************/ -/* */ -/* resident structure */ -/* */ -/******************************************************************************/ - -const APTR InitTab[4]; - -static const struct Resident RomTag = { - RTC_MATCHWORD, - (struct Resident *)&RomTag, - (APTR)((&RomTag)+1), - RTF_AUTOINIT, - 0, - NT_DEVICE, - 0, - (BYTE *)DevName, - (BYTE *)DevIdString, - (APTR)&InitTab -}; - -/******************************************************************************/ -/* */ -/* autoinit table for use with initial MakeLibrary() */ -/* */ -/******************************************************************************/ - -const APTR InitTab[4] = { - (APTR)sizeof(_DEV), - (APTR)&__FuncTable__[1], - 0, - (APTR)DevInit -}; - -/******************************************************************************/ -/* */ -/* support function(s) to be inlined */ -/* */ -/******************************************************************************/ - -static inline APTR __GetDataSeg() +LONG +DevExtFunc(VOID) { - APTR res; - asm ("lea ___a4_init,%0" : "=a" (res)); - return res; -} - -static inline ULONG __BSize() -{ - ULONG res; - asm ("movel #___bss_size,%0" : "=d" (res)); - return res; -} - -static inline ULONG *__GetBssStart() -{ - ULONG *res; - asm ("lea __edata,%0" : "=a" (res)); - return res; -} - -/******************************************************************************/ -/* */ -/* initialization function called by MakeLibrary() */ -/* */ -/******************************************************************************/ - -struct Library *DevInit() -{ - register APTR DataSeg asm("a4"); - register APTR SegList asm("a0"); - register struct Library *dev asm("d0"); - _DEV *Device = (_DEV *)dev; - ULONG size,result; - - /* init library base */ - - Device->DevNode.lib_Node.ln_Type = NT_DEVICE; - Device->DevNode.lib_Node.ln_Name = (UBYTE *)DevName; - Device->DevNode.lib_Flags = LIBF_CHANGED | LIBF_SUMUSED; - Device->DevNode.lib_Version = (UWORD)DevVersion; - Device->DevNode.lib_Revision = (UWORD)DevRevision; - Device->DevNode.lib_IdString = (UBYTE *)DevIdString; - Device->SegList = SegList; - Device->DataSeg = __GetDataSeg(); - - /* clear the bss part */ - - if ((size=__BSize())) - { - ULONG *p=__GetBssStart(); - - do - { - *p++=0; - } - while((size-=sizeof(ULONG))); - } - - DataSeg=Device->DataSeg; asm volatile ("" : /**/ : "r" (DataSeg)); - - /* now call user-init */ - - result=__UserDevInit(Device); - - /* all ok? */ - - if (result!=0) - Device=NULL; - - /* this will be added to SysBase->DevList or NULL (init error) */ - - return (struct Library *)Device; -} - -/******************************************************************************/ -/* */ -/* DevOpen() will be called for every OpenDevice() */ -/* */ -/* !!! CAUTION: This function runs in a forbidden state !!! */ -/* */ -/******************************************************************************/ - -VOID DevOpen() -{ - register struct Library *dev asm("a6"); - register struct IORequest *iorq asm("a1"); - register ULONG flags asm("d1"); - register ULONG unit asm("d0"); - register APTR DataSeg asm("a4"); - int result; - - /* any memory allocation can cause a call of THIS device expunge vector. - if OpenCnt is zero the library might go away ... so fake a user :-) */ - - dev->lib_OpenCnt++; - - DataSeg=((_DEV *)dev)->DataSeg; asm volatile ("" : /**/ : "r" (DataSeg)); - - /* call user-open */ - - result=__UserDevOpen(iorq,unit,flags); - - if (result==0) - { - /* clear delayed expunge flag */ - - dev->lib_Flags &= ~LIBF_DELEXP; - - /* one new user */ - - dev->lib_OpenCnt++; - } - - /* end of expunge protection */ - - --dev->lib_OpenCnt; - - /* exec returns io_error later */ -} - -/******************************************************************************/ -/* */ -/* DevClose() will be called for every CloseDevice() */ -/* */ -/* !!! CAUTION: This function runs in a forbidden state !!! */ -/* */ -/******************************************************************************/ - -APTR DevClose() -{ - register struct Library *dev asm("a6"); - register struct IORequest *iorq asm("a1"); - register APTR DataSeg asm("a4"); - APTR SegList=0; - - DataSeg=((_DEV *)dev)->DataSeg; asm volatile ("" : /**/ : "r" (DataSeg)); - - __UserDevClose(iorq); - - /* one less user */ - - if (--dev->lib_OpenCnt==0 && (dev->lib_Flags&LIBF_DELEXP)) - SegList=DevExpunge(); - - /* SegList or NULL (still in use) */ - - return SegList; + return 0; } /******************************************************************************/ @@ -246,56 +37,207 @@ APTR DevClose() /* */ /******************************************************************************/ -APTR DevExpunge() +LONG +DevExpunge(REG(a6,__DEV dev)) { - register struct Library *dev asm("a6"); - register APTR DataSeg asm("a4"); - _DEV *Device = (_DEV *)dev; - APTR SegList=0; + LONG SegList = 0; /* set delayed expunge flag */ - Device->DevNode.lib_Flags |= LIBF_DELEXP; + dev->LibNode.lib_Flags |= LIBF_DELEXP; /* still in use? */ - if (Device->DevNode.lib_OpenCnt == 0) - { - ULONG NegSize; + if (!dev->LibNode.lib_OpenCnt) { - /* return the seglist for UnLoadSeg() */ - - SegList = Device->SegList; + APTR SysBase = dev->SysBase; /* remove device from SysBase->DevList */ - Remove((struct Node *)Device); + Remove((struct Node *)dev); - DataSeg=Device->DataSeg; asm volatile ("" : /**/ : "r" (DataSeg)); - /* now call user-exit */ - __UserDevCleanup(); + __UserDevCleanup(dev->DataSeg); + + /* return the seglist for UnLoadSeg() */ + + SegList = dev->SegList; /* free device */ - NegSize = Device->DevNode.lib_NegSize; - FreeMem((APTR)((UBYTE *)Device-(UBYTE *)NegSize),NegSize+Device->DevNode.lib_PosSize); + FreeMem((UBYTE *)dev-dev->LibNode.lib_NegSize,dev->LibNode.lib_NegSize+dev->LibNode.lib_PosSize); } + return SegList; } /******************************************************************************/ /* */ -/* a do nothing stub (required!) */ +/* DevClose() will be called for every CloseDevice() */ +/* */ +/* !!! CAUTION: This function runs in a forbidden state !!! */ /* */ /******************************************************************************/ -APTR DevExtFunc() +LONG +DevClose(REG(a1,APTR iorq),REG(a6,__DEV dev)) { - return 0; + LONG SegList = 0; + + /* call user-close */ + + __UserDevClose(iorq,dev->DataSeg); + + /* one less user */ + + if (!--dev->LibNode.lib_OpenCnt && (dev->LibNode.lib_Flags&LIBF_DELEXP)) + SegList = DevExpunge(dev); + + /* SegList or NULL (still in use) */ + + return SegList; } +/******************************************************************************/ +/* */ +/* DevOpen() will be called for every OpenDevice() */ +/* */ +/* !!! CAUTION: This function runs in a forbidden state !!! */ +/* */ +/******************************************************************************/ + +VOID +DevOpen(REG(d0,ULONG unit),REG(a1,APTR iorq),REG(d1,ULONG flags),REG(a6,__DEV dev)) +{ + /* any memory allocation can cause a call of THIS device expunge vector. + if OpenCnt is zero the library might go away ... so fake a user :-) */ + + ++dev->LibNode.lib_OpenCnt; + + /* call user-open */ + + if (!__UserDevOpen(iorq,unit,flags,dev->DataSeg)) { + + /* clear delayed expunge flag */ + + dev->LibNode.lib_Flags &= ~LIBF_DELEXP; + + /* one new user */ + + ++dev->LibNode.lib_OpenCnt; + } + + /* end of expunge protection */ + + --dev->LibNode.lib_OpenCnt; + + /* exec returns io_error later */ +} + +/******************************************************************************/ +/* */ +/* initialization function called by MakeLibrary() */ +/* */ +/******************************************************************************/ + +static inline APTR __GetDataSeg(void) +{ APTR res; + + __asm("lea ___a4_init,%0" : "=a" (res)); return res; +} + +static inline ULONG __BSize(void) +{ ULONG res; + + __asm("movel #___bss_size,%0" : "=d" (res)); return res; +} + +static inline APTR __GetBssStart(void) +{ APTR res; + + __asm("lea __edata,%0" : "=a" (res)); return res; +} + +APTR +DevInit(REG(a0,LONG SegList),REG(d0,__DEV dev),REG(a6,struct Library *SysBase)) +{ ULONG size; + + /* set up header data */ + + dev->LibNode.lib_Node.ln_Type = NT_DEVICE; + dev->LibNode.lib_Node.ln_Name = (UBYTE *)DevName; + dev->LibNode.lib_Flags = LIBF_CHANGED | LIBF_SUMUSED; + dev->LibNode.lib_Version = (UWORD)DevVersion; + dev->LibNode.lib_Revision = (UWORD)DevRevision; + dev->LibNode.lib_IdString = (char *)DevIdString; + + /* setup private data */ + + dev->SegList = SegList; + dev->SysBase = SysBase; + +#if 1 + + dev->DataSeg = __GetDataSeg(); + + /* clear the bss part */ + + if ((size=__BSize())) { + + ULONG *p = __GetBssStart(); + + do { + *p++=0; + } while ((size-=sizeof(*p))); + } + +#endif + + /* now call user-init */ + + if (!__UserDevInit(&dev->LibNode,dev->DataSeg)) { + FreeMem((UBYTE *)dev-dev->LibNode.lib_NegSize,dev->LibNode.lib_NegSize+dev->LibNode.lib_PosSize); + dev = NULL; + } + + /* this will be added to SysBase->DevList or NULL (init error) */ + + return dev; +} + +/******************************************************************************/ +/* */ +/* autoinit table for use with initial MakeLibrary() */ +/* */ +/******************************************************************************/ + +static const APTR InitTab[4] = { + (APTR)sizeof(struct libBase), + (APTR)&__FuncTable__[1], + (APTR)NULL, + (APTR)&LibInit +}; + +/******************************************************************************/ +/* */ +/* resident structure */ +/* */ +/******************************************************************************/ + +static const struct Resident RomTag = { + RTC_MATCHWORD, + (struct Resident *)&RomTag, + (struct Resident *)&RomTag+1, + RTF_AUTOINIT, + 0, + NT_DEVICE, + 0, + (char *)DevName, + (char *)DevIdString, + (APTR)&InitTab +}; + /******************************************************************************/ /* */ /* add these functions to 'funclist' */ diff --git a/libnix/sources/startup/libinit.c b/libnix/sources/startup/libinit.c index b6261e3..3dc240f 100755 --- a/libnix/sources/startup/libinit.c +++ b/libnix/sources/startup/libinit.c @@ -38,7 +38,7 @@ LibExtFunc(VOID) /******************************************************************************/ LONG -LibExpunge(REG(a6,struct LibBase *lib)) +LibExpunge(REG(a6,__LIB lib)) { LONG SegList = 0; @@ -81,7 +81,7 @@ LibExpunge(REG(a6,struct LibBase *lib)) /******************************************************************************/ LONG -LibClose(REG(a6,struct LibBase *lib)) +LibClose(REG(a6,__LIB lib)) { LONG SegList = 0; @@ -104,7 +104,7 @@ LibClose(REG(a6,struct LibBase *lib)) /******************************************************************************/ APTR -LibOpen(REG(a6,struct LibBase *lib)) +LibOpen(REG(a6,__LIB lib)) { /* clear delayed expunge flag */ @@ -144,7 +144,7 @@ static __inline APTR __GetBssStart(void) } APTR -LibInit(REG(a0,LONG SegList),REG(d0,struct LibBase *lib),REG(a6,struct Library *SysBase)) +LibInit(REG(a0,LONG SegList),REG(d0,__LIB lib),REG(a6,struct Library *SysBase)) { ULONG size; /* set up header data */ @@ -197,7 +197,7 @@ LibInit(REG(a0,LONG SegList),REG(d0,struct LibBase *lib),REG(a6,struct Library * /******************************************************************************/ static const APTR InitTab[] = { - (APTR)sizeof(struct LibBase), + (APTR)sizeof(struct libBase), (APTR)&__FuncTable__[1], (APTR)NULL, (APTR)&LibInit diff --git a/libnix/sources/startup/libinitr.c b/libnix/sources/startup/libinitr.c index 36aa330..9c4a30b 100755 --- a/libnix/sources/startup/libinitr.c +++ b/libnix/sources/startup/libinitr.c @@ -4,7 +4,7 @@ /* */ /******************************************************************************/ -#define EXTENDED /* multibase library */ +#define EXTENDED /* multibase library! */ #include "libinit.h" /******************************************************************************/ @@ -39,7 +39,7 @@ LibExtFunc(VOID) /******************************************************************************/ LONG -LibExpunge(REG(a6,struct LibBase *lib)) +LibExpunge(REG(a6,__LIB lib)) { LONG SegList = 0; @@ -82,7 +82,7 @@ LibExpunge(REG(a6,struct LibBase *lib)) /******************************************************************************/ LONG -LibClose(REG(a6,struct LibBase *lib)) +LibClose(REG(a6,__LIB lib)) { APTR SysBase = lib->SysBase; LONG SegList = 0; @@ -118,10 +118,10 @@ static __inline ULONG __DSize(void) } APTR -LibOpen(REG(a6,struct LibBase *lib)) +LibOpen(REG(a6,__LIB lib)) { APTR dataseg, SysBase = lib->SysBase; - struct LibBase *child; + __LIB child; /* any memory allocation can cause a call of THIS library expunge vector. if OpenCnt is zero the library might go away ... So fake a user :-) */ @@ -130,7 +130,7 @@ LibOpen(REG(a6,struct LibBase *lib)) /* create new library base */ - if ((child=(struct LibBase *)MakeLibrary(&__FuncTable__[1],NULL,(ULONG (*)())LibInit,sizeof(*lib)+lib->DataSize,0))) { + if ((child=(__LIB)MakeLibrary(&__FuncTable__[1],NULL,(ULONG (*)())LibInit,sizeof(*lib)+lib->DataSize,0))) { LONG *relocs,numrel; @@ -198,7 +198,7 @@ static __inline ULONG __GetDBSize(void) } APTR -LibInit(REG(a0,LONG SegList),REG(d0,struct LibBase *lib),REG(a6,struct Library *SysBase)) +LibInit(REG(a0,LONG SegList),REG(d0,__LIB lib),REG(a6,struct Library *SysBase)) { /* set up header data */ @@ -228,7 +228,7 @@ LibInit(REG(a0,LONG SegList),REG(d0,struct LibBase *lib),REG(a6,struct Library * /******************************************************************************/ static const APTR InitTab[] = { - (APTR)sizeof(struct LibBase), + (APTR)sizeof(struct libBase), (APTR)&__LibTable__[1], (APTR)NULL, (APTR)&LibInit diff --git a/libnix/sources/stubs/Makefile.in b/libnix/sources/stubs/Makefile.in index 06e62ab..99ac82f 100644 --- a/libnix/sources/stubs/Makefile.in +++ b/libnix/sources/stubs/Makefile.in @@ -4,11 +4,12 @@ srcdir = @srcdir@ VPATH = @srcdir@ CC = @CC@ -CPP = @CPP@ +CPP = @CPP@ AS = as +AR = ar RANLIB = @RANLIB@ -AWK = @AWK@ +AWK = @AWK@ #### End system configuration section #### @@ -18,7 +19,7 @@ endif CURDIR = $(shell pwd) -OPTIONS=-I $(srcdir)/../headers -I ../../sources/headers $(CFLAGS) +OPTIONS=-I$(srcdir)/../headers $(CFLAGS) OBJECTS2=$(OBJECTS) ../nix/misc/__request.o @@ -41,8 +42,8 @@ veryclean: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)): mkdir $@ -libstubs.a: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)) $(OBJECTS2) ../../sources/stubs/makefile ../../sources/stubs/filelist +libstubs.a: $(foreach f,$(SUBDIRS2),$(CURDIR)/$(f)) $(OBJECTS2) ../../sources/stubs/Makefile ../../sources/stubs/filelist rm -f $@ - ar -q $@ $(OBJECTS2) + $(AR) -q $@ $(OBJECTS2) $(RANLIB) $@ echo "\$$$(V)" >>$@ diff --git a/libnix/sources/stubs/libbases/.keepme b/libnix/sources/stubs/libbases/.keepme new file mode 100644 index 0000000..e69de29 diff --git a/libnix/sources/stubs/libnames/.keepme b/libnix/sources/stubs/libnames/.keepme new file mode 100644 index 0000000..e69de29 diff --git a/libnix/sources/stubs/misc/__DOSBase.c b/libnix/sources/stubs/misc/__DOSBase.c index 0c1643c..48fc200 100755 --- a/libnix/sources/stubs/misc/__DOSBase.c +++ b/libnix/sources/stubs/misc/__DOSBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __dosname[]; void *__DOSBase[2]={ 0l,__dosname }; ADD2LIB(__DOSBase); diff --git a/libnix/sources/stubs/misc/__MathIeeeDoubBasBase.c b/libnix/sources/stubs/misc/__MathIeeeDoubBasBase.c index b17ebbc..03d1202 100755 --- a/libnix/sources/stubs/misc/__MathIeeeDoubBasBase.c +++ b/libnix/sources/stubs/misc/__MathIeeeDoubBasBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __mathieeedoubbasname[]; void *__MathIeeeDoubBasBase[2]={ 0l,__mathieeedoubbasname }; ADD2LIB(__MathIeeeDoubBasBase); diff --git a/libnix/sources/stubs/misc/__MathIeeeDoubTransBase.c b/libnix/sources/stubs/misc/__MathIeeeDoubTransBase.c index c892566..90b27da 100755 --- a/libnix/sources/stubs/misc/__MathIeeeDoubTransBase.c +++ b/libnix/sources/stubs/misc/__MathIeeeDoubTransBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __mathieeedoubtransname[]; void *__MathIeeeDoubTransBase[2]={ 0l,__mathieeedoubtransname }; ADD2LIB(__MathIeeeDoubTransBase); diff --git a/libnix/sources/stubs/misc/__MathIeeeSingBasBase.c b/libnix/sources/stubs/misc/__MathIeeeSingBasBase.c index c19c1f6..ed54115 100755 --- a/libnix/sources/stubs/misc/__MathIeeeSingBasBase.c +++ b/libnix/sources/stubs/misc/__MathIeeeSingBasBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __mathieeesingbasname[]; void *__MathIeeeSingBasBase[2]={ 0l,__mathieeesingbasname }; ADD2LIB(__MathIeeeSingBasBase); diff --git a/libnix/sources/stubs/misc/__MathIeeeSingTransBase.c b/libnix/sources/stubs/misc/__MathIeeeSingTransBase.c index 5e5dc4a..74eafcc 100755 --- a/libnix/sources/stubs/misc/__MathIeeeSingTransBase.c +++ b/libnix/sources/stubs/misc/__MathIeeeSingTransBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __mathieeesingtransname[]; void *__MathIeeeSingTransBase[2]={ 0l,__mathieeesingtransname }; ADD2LIB(__MathIeeeSingTransBase); diff --git a/libnix/sources/stubs/misc/__UtilityBase.c b/libnix/sources/stubs/misc/__UtilityBase.c index 77e50e7..43ece09 100755 --- a/libnix/sources/stubs/misc/__UtilityBase.c +++ b/libnix/sources/stubs/misc/__UtilityBase.c @@ -1,4 +1,4 @@ -#include +#include "stabs.h" extern char __utilityname[]; void *__UtilityBase[2]={ 0l,__utilityname }; ADD2LIB(__UtilityBase); diff --git a/libnix/sources/stubs/misc/__cpucheck.c b/libnix/sources/stubs/misc/__cpucheck.c index 07ae453..348c881 100755 --- a/libnix/sources/stubs/misc/__cpucheck.c +++ b/libnix/sources/stubs/misc/__cpucheck.c @@ -1,5 +1,5 @@ -#include -#include +#include "bases.h" +#include "stabs.h" #if defined(mc68020) || defined(__HAVE_68881__) diff --git a/libnix/sources/stubs/misc/__initlibraries.c b/libnix/sources/stubs/misc/__initlibraries.c index f34c16b..0a515af 100755 --- a/libnix/sources/stubs/misc/__initlibraries.c +++ b/libnix/sources/stubs/misc/__initlibraries.c @@ -1,5 +1,5 @@ #include -#include +#include "stabs.h" extern struct lib /* These are the elements pointed to by __LIB_LIST__ */ { struct Library *base; @@ -10,9 +10,9 @@ extern ULONG __oslibversion; extern void __request(const char *text); extern void exit(int returncode); -static void __openliberror(ULONG, char *,...) __attribute__ ((noreturn)); +static void __openliberror(ULONG,...) __attribute__ ((noreturn)); -static void __openliberror(ULONG version, char *name,...) +static void __openliberror(ULONG version,...) { static const ULONG tricky=0x16c04e75; /* move.b d0,(a3)+ ; rts */ char buf[60];