summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1997-02-25 20:42:19 +0100
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:38:07 +0200
commit4c36e9a0c125ccfff37aa440dab2cf58c4152fff (patch)
treea5d9c84ba2661029ddb2223dacd50529a361c3d5 /libc
parentf8de35da65c5d93bb733073cf40da154bc1c0748 (diff)
parent9696d7b0e1f3a1b0f5fd4a0428eb75afe8ad4ed6 (diff)
downloaddev86-4c36e9a0c125ccfff37aa440dab2cf58c4152fff.tar.gz
Import Dev86src-0.0.11.tar.gzv0.0.11
Diffstat (limited to 'libc')
-rw-r--r--libc/Contributors8
-rw-r--r--libc/MAGIC23
-rw-r--r--libc/Make.defs100
-rw-r--r--libc/Makefile132
-rwxr-xr-xlibc/New_subdir11
-rw-r--r--libc/README27
-rw-r--r--libc/bcc/Makefile49
-rw-r--r--libc/bcc/heap.c4
-rw-r--r--libc/bios/Makefile35
-rw-r--r--libc/bios/bios.c12
-rw-r--r--libc/bios/bios_vid.c24
-rw-r--r--libc/crt0.c2
-rw-r--r--libc/error/Makefile15
-rw-r--r--libc/getent/Config1
-rw-r--r--libc/getent/Makefile (renamed from libc/pwd/Makefile)44
-rw-r--r--libc/getent/__getgrent.c (renamed from libc/grp/__getgrent.c)0
-rw-r--r--libc/getent/__getpwent.c (renamed from libc/pwd/__getpwent.c)0
-rw-r--r--libc/getent/config-grp.h (renamed from libc/grp/config-grp.h)0
-rw-r--r--libc/getent/config.h (renamed from libc/grp/config.h)0
-rw-r--r--libc/getent/fgetgrent.c (renamed from libc/grp/fgetgrent.c)0
-rw-r--r--libc/getent/fgetpwent.c (renamed from libc/pwd/fgetpwent.c)0
-rw-r--r--libc/getent/getgrgid.c (renamed from libc/grp/getgrgid.c)0
-rw-r--r--libc/getent/getgrnam.c (renamed from libc/grp/getgrnam.c)0
-rw-r--r--libc/getent/getpw.c (renamed from libc/pwd/getpw.c)0
-rw-r--r--libc/getent/getpwnam.c (renamed from libc/pwd/getpwnam.c)0
-rw-r--r--libc/getent/getpwuid.c (renamed from libc/pwd/getpwuid.c)0
-rw-r--r--libc/getent/grent.c (renamed from libc/grp/grent.c)0
-rw-r--r--libc/getent/initgroups.c (renamed from libc/grp/initgroups.c)0
-rw-r--r--libc/getent/putpwent.c (renamed from libc/pwd/putpwent.c)0
-rw-r--r--libc/getent/pwent.c (renamed from libc/pwd/pwent.c)0
-rw-r--r--libc/getent/test_grp.c (renamed from libc/grp/test_grp.c)0
-rw-r--r--libc/getent/test_pwd.c (renamed from libc/pwd/test_pwd.c)0
-rw-r--r--libc/getent/utent.c (renamed from libc/utmp/utent.c)0
-rw-r--r--libc/grp/Config1
-rw-r--r--libc/grp/Makefile42
-rw-r--r--libc/gtermcap/Makefile18
-rw-r--r--libc/i386fp/Makefile38
-rw-r--r--libc/i386sys/Config1
-rw-r--r--libc/i386sys/Makefile52
-rw-r--r--libc/i386sys/dirent.c106
-rw-r--r--libc/i386sys/exec.c292
-rw-r--r--libc/i386sys/mksyscall (renamed from libc/syscall/mksys386)29
-rw-r--r--libc/i386sys/signal.c99
-rw-r--r--libc/i386sys/syscall.dat (renamed from libc/syscall/sys386.dat)0
-rw-r--r--libc/i386sys/syslibc.c255
-rw-r--r--libc/include/setjmp.h8
-rw-r--r--libc/include/stdarg.h4
-rw-r--r--libc/include/sys/stat.h4
-rw-r--r--libc/kinclude/Makefile10
-rw-r--r--libc/malloc1/Makefile21
-rw-r--r--libc/malloc2/Makefile20
-rw-r--r--libc/misc/Makefile51
-rw-r--r--libc/misc/strtod.c4
-rw-r--r--libc/msdos/Makefile35
-rw-r--r--libc/pwd/Config1
-rw-r--r--libc/regexp/Makefile27
-rw-r--r--libc/stdio2/Makefile41
-rw-r--r--libc/stdio2/printf.c21
-rw-r--r--libc/stdio2/scanf.c24
-rw-r--r--libc/stdio2/stdio.c4
-rw-r--r--libc/string/Makefile23
-rw-r--r--libc/syscall/Makefile70
-rw-r--r--libc/syscall/TODO2
-rw-r--r--libc/syscall/getinfo.c32
-rw-r--r--libc/syscall/mksyscall25
-rw-r--r--libc/syscall/setjmp.c6
-rw-r--r--libc/syscall/syscall.dat.chad55
-rw-r--r--libc/syscall/syscall.dat.code70
-rw-r--r--libc/syscall/syscall.dat.rdb142
-rw-r--r--libc/syscall/syslib0.c20
-rw-r--r--libc/syscall/syslib3.c109
-rw-r--r--libc/syscall/syslibc.c13
-rw-r--r--libc/termios/Makefile28
-rw-r--r--libc/tests/Config2
-rw-r--r--libc/tests/Makefile20
-rw-r--r--libc/tests/README22
-rw-r--r--libc/tests/Real_make19
-rw-r--r--libc/tests/compr.c383
-rw-r--r--libc/tests/env.c81
-rw-r--r--libc/tests/ft.c1209
-rw-r--r--libc/tests/grab.c81
-rw-r--r--libc/tests/hd.c185
-rw-r--r--libc/tests/line2.c15
-rw-r--r--libc/tests/lines.c36
-rw-r--r--libc/tests/ls.c1049
-rw-r--r--libc/tests/ouch.c27
-rw-r--r--libc/tests/rand.c16
-rw-r--r--libc/tests/size.c51
-rw-r--r--libc/tests/sync.c1
-rw-r--r--libc/tests/ucomp.c108
-rw-r--r--libc/tests/wc.c133
-rw-r--r--libc/time/Makefile12
-rw-r--r--libc/utmp/Makefile26
93 files changed, 1568 insertions, 4198 deletions
diff --git a/libc/Contributors b/libc/Contributors
deleted file mode 100644
index 27a3145..0000000
--- a/libc/Contributors
+++ /dev/null
@@ -1,8 +0,0 @@
-Alan Cox <alan@cymru.net>
-Bruce Evans <bde@FreeBSD.org>
-Chad Page <page0588@sundance.sjsu.edu>
-Dale Schumacher <dal@syntel.UUCP>
-Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-Nat Friedman <ndf@aleph1.mit.edu>
-Robert de Bath <robert@mayday.compulink.co.uk>
-Steven Huang <sthuang@hns.com>
diff --git a/libc/MAGIC b/libc/MAGIC
deleted file mode 100644
index 319751e..0000000
--- a/libc/MAGIC
+++ /dev/null
@@ -1,23 +0,0 @@
-Useful bits for /etc/magic:
-
-#------------------------------------------------------------------------------
-# Localstuff: file(1) magic for locally observed files
-#
-# $Id: Localstuff,v 1.3 1995/01/21 21:09:00 christos Exp $
-# Add any locally observed files here. Remember:
-# text if readable, executable if runnable binary, data if unreadable.
-#
-0 string \01\03\020\04 Linux-8086 impure executable
->28 long !0 not stripped
-0 string \01\03\040\04 Linux-8086 executable
->28 long !0 not stripped
-#
-0 string \243\206\001\0 Linux-8086 object file
-# There is _no_ difference between 16 and 32 bit .o files
-#
-0 string \01\03\020\20 Minix-386 impure executable
->28 long !0 not stripped
-0 string \01\03\040\20 Minix-386 executable
->28 long !0 not stripped
-#
-#------------------------------------------------------------------------------
diff --git a/libc/Make.defs b/libc/Make.defs
index b4f0c28..2b1eca6 100644
--- a/libc/Make.defs
+++ b/libc/Make.defs
@@ -1,108 +1,80 @@
-# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
-# This file is part of the Linux-8086 C library and is distributed
-# under the GNU Library General Public License.
-
-# Set PLATFORM to i386-Linux to build for Linux/386 and to i86-ELKS to
-# build for ELKS. This doesn't quite work yet, though, because of some of
-# the platform and/or compiler-specific code flying around here.
-# Eventually, compiler-specificity won't be an issue, and we can put
-# platform-specific code in i86/ and i386/. -Nat
-
-# Define enviroment var for others.
-ifeq ($(PLATFORM),)
-# PLATFORM=i86-ELKS
-# PLATFORM=i86-FAST PLATFORM=i86-DOS PLATFORM=i386-BCC PLATFORM=i386-Linux
-
-PLATFORM=$(shell if [ -f $(TOP)/.config.otype ] ; \
- then cat $(TOP)/.config.otype ; \
- else echo i86-ELKS ; fi)
-export PLATFORM
-endif
-
-VERMAJOR=0
-VERMINOR=0
-VERPATCH=9
-VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
-
-LIBDEFS='-D__LIBC__="$(VER)"'
-LIBC=libc.a
-
-##############################################################################
-
+############################################################################
# Normal standard 8086 code
+
ifeq ($(PLATFORM),i86-ELKS)
-ARCH=
+OBJ=crt0.o
+LIBC=$(TOP)/libc.a
+ARCH=-Mn
LIB_CPU=i86
LIB_OS=ELKS
endif
+##############################################################################
# 8086 elks code With "Caller saves" and "First arg in AX"
+
ifeq ($(PLATFORM),i86-FAST)
+OBJ=crt0.o
+LIBC=$(TOP)/libc_f.a
ARCH=-Mf
-LIBC=libc_f.a
LIB_CPU=i86
LIB_OS=ELKS
endif
+##############################################################################
# Standalone executable
+
ifeq ($(PLATFORM),i86-BIOS)
+OBJ=crt0.o
+LIBC=$(TOP)/libc_s.a
ARCH=-Ms
-LIBC=libc_s.a
LIB_CPU=i86
LIB_OS=BIOS
endif
+##############################################################################
# MSDOS COM file (msdos libs don't support "First arg in AX")
+
ifeq ($(PLATFORM),i86-DOS)
+OBJ=crt0.o
+LIBC=$(TOP)/libdos.a
ARCH=-Md
-LIBC=libdos.a
LIB_CPU=i86
LIB_OS=DOS
endif
##############################################################################
-
# BCC 386.
+
ifeq ($(PLATFORM),i386-BCC)
-ARCH=-3 -N
+OBJ=crt3.o
+LIBC=$(TOP)/libc3.a
+ARCH=-Ml
LIB_CPU=i386
LIB_OS=ELKS
-
-CC=bcc $(ARCH)
-CCFLAGS=-I -I$(TOP)/include
-LKFLAGS=-L -L$(TOP)/
endif
-ifeq ($(PLATFORM),i386-Linux)
-LIB_CPU=g386
-LIB_OS=ELKS
+##############################################################################
+# Anonymous
-CC=gcc $(ARCH)
-# ARCH=-b i486-linuxaout
-LKFLAGS=-static -N
-CCFLAGS=-O6 -fomit-frame-pointer -I- -I$(TOP)/include -I. -fno-builtin
-WALL= -ansi -pedantic -Wwrite-strings -Wpointer-arith -Wcast-qual \
- -Wcast-align -Wtraditional -Wstrict-prototypes -Wmissing-prototypes \
- -Wnested-externs -Winline -Wshadow
+ifeq ($(PLATFORM),ANON)
+OBJ=crt0.o
+LIBC=$(TOP)/libc.a
+ARCH=
+LIB_CPU=Bigbad
+LIB_OS=Nice
+CC=cc
+CCFLAGS=-I$(TOP)/include
endif
-############################################################################
-
-ifeq ($(LIB_CPU),i86)
-CC=bcc $(ARCH)
-CCFLAGS=-I -I$(TOP)/include # -O
-LKFLAGS=-L -L$(TOP)/ -s
-endif
+##############################################################################
+# Unknown
ifeq ($(LIB_CPU),)
+OBJ=crtX.o
+LIBC=$(TOP)/libc_X.a
+ARCH=
LIB_CPU=Unknown
LIB_OS=Unknown
-LIBC=libc_X.a
-CCFLAGS=-I$(TOP)/include
-LKFLAGS=
endif
-CFLAGS=$(CCFLAGS) $(LIBDEFS)
-LDFLAGS=$(LKFLAGS)
-
.PRECIOUS: $(LIBC)
diff --git a/libc/Makefile b/libc/Makefile
index 0359619..83aded9 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -1,103 +1,101 @@
-# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+# Copyright (C) 1996,1997 Robert de Bath <robert@mayday.cix.co.uk>
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=.
-include $(TOP)/Make.defs
+ifeq ($(TOPDIR),)
+# This should work, but ..
+TOP=..
+else
+TOP=$(TOPDIR)/libc
+endif
-SRC=crt0.c
-OBJ=crt0.o
+VERMAJOR=0
+VERMINOR=0
+VERPATCH=11
+VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
-TARGETS=$(OBJ) $(LIBC)
-TXT=Makefile Make.defs README KERNEL COPYING Contributors MAGIC \
- New_subdir Pre_main Config_sh
+CC=bcc
+CCFLAGS=-I -I$(TOP)/include
+DEFS=-D__LIBC__
-all: .config.dir .config.otype $(TARGETS)
+include Make.defs
-install: all install_incl
- install -d $(BCCHOME)
- install -d $(LIBDIR)/$(LIB_CPU)
- install -m 644 crt0.o $(LIBDIR)/$(LIB_CPU)
- install -m 644 $(LIBC) $(LIBDIR)/$(LIB_CPU)
- -install -d $(DIST)/usr/lib
- -install -m 644 error/liberror.txt $(DIST)/usr/lib/liberror.txt
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-# I've changed this so it'll be easier to make a binary dist.
-old_install_incl:
- rm -rf $(BCCHOME)/include
- ln -s $(TOPDIR)/libc/include $(BCCHOME)/include
+############################################################################
-install_incl:
- rm -rf $(BCCHOME)/include
- cp -pr include $(BCCHOME)/include
- if [ -f kinclude/Used ] ; \
- then cp -pr kinclude/arch $(BCCHOME)/include/arch ; \
- else rm -rf $(BCCHOME)/include/linuxmt ; \
- ln -s $(ELKSSRC)/include/linuxmt $(BCCHOME)/include ; \
- fi
- -chown -R root:root $(BCCHOME)/include 2>/dev/null
- -chmod -R u=rwX,og=rX $(BCCHOME)/include
+MAKEPASS= \
+ LIBC='$(LIBC)' CC='$(CC)' ARCH='$(ARCH)' CCFLAGS='$(CCFLAGS)' \
+ DEFS='$(DEFS)' LIB_CPU='$(LIB_CPU)' LIB_OS='$(LIB_OS)' \
-tests: dummy
- $(MAKE) -C tests
-dummy:
+all: $(OBJ) $(LIBC)
+ @:
$(LIBC): transfer .config.dir
@for i in `cat .config.dir` ; do \
- echo $(MAKE) -C $$i libc.a ; $(MAKE) -C $$i libc.a || exit 1 ; \
+ $(MAKE) $(MAKEPASS) -C $$i all || exit 1 ; \
done
+crt3.o: crt0.c Makefile
+ $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c
+
+crt0.o: crt0.c Makefile
+ $(CC) -c $(CFLAGS) -D__LIBC_VER__='"$(VER)"' -o $@ crt0.c
+
+crtX.o:
+ @echo "You need to define the 'PLATFORM=...' variable"
+ @exit 1
+
+############################################################################
+
transfer: .config.dir
- @echo Checking for transfers
@for i in `cat .config.dir`; do \
- grep -q '^transfer' $$i/Makefile && $(MAKE) -s -C $$i $@ ; \
+ grep -s '^transfer' $$i/Makefile && $(MAKE) -s -C $$i $@ ; \
done ; echo -n
@[ -f kinclude/Used ] || \
{ rm -f include/linuxmt ; \
ln -s $(ELKSSRC)/include/linuxmt include ; }
-realclean: noconfig clean dellib
+############################################################################
+
+realclean: clean noconfig
clean:
- rm -f $(OBJ) $(LIBC)
+ rm -f *.o *.a
@for i in */Makefile ; do \
$(MAKE) -C `dirname $$i` $@ || exit 1 ; \
done
-dellib:
- rm -f *.a
+############################################################################
-##############################################################################
+install_incl:
+ rm -rf $(BCCHOME)/include
+ cp -pr include $(BCCHOME)/include
+ if [ -f kinclude/Used ] ; \
+ then cp -pr kinclude/arch $(BCCHOME)/include/arch ; \
+ else rm -rf $(BCCHOME)/include/linuxmt ; \
+ ln -s $(ELKSSRC)/include/linuxmt $(BCCHOME)/include ; \
+ fi
+ -chown -R root:root $(BCCHOME)/include 2>/dev/null
+ -chmod -R u=rwX,og=rX $(BCCHOME)/include
-.config.lst: Makefile Make.defs Config_sh
- sh Config_sh
-
-config:
+############################################################################
+
+config:
sh Config_sh
+.config.dir: .config.lst
+ @grep '^[^:]*:+:' < .config.lst | sed 's/:.*//' > .config.tmp
+ @mv -f .config.tmp .config.dir
+
+.config.lst: Config_sh
+ sh Config_sh
+
noconfig:
- rm -f .config.dir .config.lst .config.otype
+ rm -f .config.dir .config.lst .config.tmp
-.config.dir: .config.lst
- @grep '^[^:]*:+:' < .config.lst | sed 's/:.*//' > .config.dir
-
-.config.otype: dummy
- @[ -f .config.otype ] || echo $(PLATFORM) > .config.otype
- @[ "$(PLATFORM)" = "`cat .config.otype `" ] || $(MAKE) -$(MAKEFLAGS) clean
- @rm -f .config.otype
- @echo $(PLATFORM) > .config.otype
-
-dist: clean
- -rm -f include/linuxmt
- tar cf temp.tar \
- $(TXT) $(SRC) include \
- `for i in */Makefile */Config; do dirname $$i; done | sort -u`
- rm -rf libc-$(VER)
- mkdir libc-$(VER) ; cd libc-$(VER) ; tar xf ../temp.tar
- tar czf libc-8086-$(VER).tar.gz libc-$(VER)
- rm -rf libc-$(VER) temp.tar
-
-dist_ver: dist
- mv libc-8086-$(VER).tar.gz ..
+############################################################################
+
+Libc_version:
echo $(VER) > ../Libc_version
diff --git a/libc/New_subdir b/libc/New_subdir
index a28a5ec..e3803c7 100755
--- a/libc/New_subdir
+++ b/libc/New_subdir
@@ -28,17 +28,12 @@ cat <<! > $1/Makefile
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include \$(TOP)/Make.defs
-
OBJ=$1.o
-all: \$(OBJ)
-
-libc.a: \$(OBJ)
- ar r ../\$(LIBC) \$(OBJ)
- @touch libc.a
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+all: $(LIBC)($(OBJ))
+ @:
clean:
rm -f *.o libc.a
!
diff --git a/libc/README b/libc/README
index 0b65f99..6f45f26 100644
--- a/libc/README
+++ b/libc/README
@@ -1,14 +1,3 @@
-The lib can be compiled six different ways for Linux-8086 standard,
-Linux-8086 with 'First arg in AX', Linx-8086 standalone, MS-DOS, BCC-386
-or for GNU-386. At the moment the 386 GNU version will NOT work, the
-BCC-386 is just barely working.
-
-This can be done by running one of.
- make PLATFORM=i86-FAST clean all
- make PLATFORM=i86-DOS clean all
- make PLATFORM=i86-BIOS clean all
- make PLATFORM=i386-BCC clean all
-
SYSTEM CALLS
The system call table (syscalls/syscall.dat) is constantly changing, using
skewed versions is _very_ likely to give you segfaults and strange behaviour.
@@ -21,8 +10,8 @@ THE COMPILER
You should use the versions of bcc, unproto, as86, ld86 and elksemu that
are in this version of the combined development environment. Some other
versions will work but often they'll just appear to work or not work at
-all. The standard bcc-cc1 won't pickup the right header files, the
-standard ld86 won't generate COM files or 386-Linux files and looks in
+all. The original bcc-cc1 won't pickup the right header files, the
+original ld86 won't generate COM files or 386-Linux files and looks in
the wrong place for crt0.o and libc.a.
Main Subdirectories.
@@ -30,23 +19,21 @@ Main Subdirectories.
bcc Lots of BCC helper functions
bios Minimal 'system' calls for standalone executables.
error The C error functions.
-grp Routines for /etc/group, from Nat
+getent Routines for /etc/group, /etc/passwd and /etc/utmp
+gtermcap GNU termcap
i386fp BCC's floating point routines for 386 code.
include Some include files, some new others Glib or Glib hacked.
kinclude Kernel include files, here for now.
-malloc1 My malloc routines
+malloc1 Robert's malloc routines
malloc2 Joel's malloc routines
misc Various larger functions
-msdos This is the equlivent of the syscall directory for msdos.
-pwd Routines for /etc/passwd, from Nat
+msdos This is the syscall directory for msdos.
regexp Standard regular expression parser
-stdio2 My standard I/O
+stdio2 Robert's standard I/O
string The functions for string.h
syscall All the system call functions, and some tied lib ones.
termios Termimal mode control.
-utmp /etc/utmp updating
time Unix time related functions.
-tests Various C programs used to test the lib.
Directory structure:
diff --git a/libc/bcc/Makefile b/libc/bcc/Makefile
index 991b50e..f4cce3d 100644
--- a/libc/bcc/Makefile
+++ b/libc/bcc/Makefile
@@ -2,10 +2,6 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-CFLAGS=$(CCFLAGS)
-
# Support for integer arithmetic
ifeq ($(LIB_CPU),i86)
IOBJ=__idiv.o __idivu.o __imod.o __imodu.o __imul.o __isl.o __isr.o __isru.o
@@ -49,26 +45,43 @@ endif
OLDOBJ=$(ROBJ) $(POBJ)
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+ifneq ($(OBJ),)
-$(IOBJ): $(ISRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ISRC)
+all: $(LIBC)
+ @:
-$(LOBJ): $(LSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(LSRC)
+$(LIBC): $(LIBC)($(OBJ))
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
+$(LIBC)($(IOBJ)): $(ISRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(ROBJ): $(RSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(RSRC)
+$(LIBC)($(LOBJ)): $(LSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(POBJ): $(PSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(PSRC)
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC)($(ROBJ)): $(RSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+$(LIBC)($(POBJ)): $(PSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+else
+all:
+ @:
+endif
clean:
rm -f *.o libc.a
diff --git a/libc/bcc/heap.c b/libc/bcc/heap.c
index 2cab16e..c5b2457 100644
--- a/libc/bcc/heap.c
+++ b/libc/bcc/heap.c
@@ -49,7 +49,7 @@ has_change:
jb Enomem
sbrk_ok:
-#ifndef __MSDOS__
+#if !defined(__MSDOS__) && !defined(__STANDALONE__)
push ax ! MSDOS `kernel` doesn`t care
call ___brk ! Tell the kernel
test ax,ax
@@ -96,7 +96,7 @@ Enomem:
mov ax,#-1
ret
brk_ok:
-#ifndef __MSDOS__
+#if !defined(__MSDOS__) && !defined(__STANDALONE__)
push ax
call ___brk ! Tell the kernel
test ax,ax
diff --git a/libc/bios/Makefile b/libc/bios/Makefile
index 934ec07..5fcc964 100644
--- a/libc/bios/Makefile
+++ b/libc/bios/Makefile
@@ -2,29 +2,34 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
ifeq ($(LIB_OS),BIOS)
ASRC=bios.c
AOBJ=bios_start.o bios_isatty.o \
bios_open.o bios_read.o bios_write.o bios_lseek.o bios_close.o
BSRC=bios_vid.c
-BOBJ=bios_putc.o bios_getc.o bios_rdline.o
-endif
+BOBJ=bios_putc.o bios_getc.o bios_khit.o bios_rdline.o
-all: $(AOBJ) $(BOBJ)
+OBJ=$(AOBJ) $(BOBJ)
-libc.a: $(AOBJ) $(BOBJ)
- ar r ../$(LIBC) $(AOBJ) $(BOBJ)
- @touch libc.a
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-clean:
- rm -f *.o libc.a
+all: $(LIBC)($(OBJ))
+ @:
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(BOBJ): $(BSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(BSRC)
+$(LIBC)($(BOBJ)): $(BSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+else
+all:
+ @:
+endif
+
+clean:
+ rm -f *.o libc.a
diff --git a/libc/bios/bios.c b/libc/bios/bios.c
index 3059fd9..a8d2079 100644
--- a/libc/bios/bios.c
+++ b/libc/bios/bios.c
@@ -26,6 +26,8 @@ defarg:
.word boot_str, 0
boot_str:
.asciz "boot"
+loop_save:
+ .word 0
.text
export ___cstartup ! Crt0 startup
@@ -54,15 +56,17 @@ zap_bss: ! Clear the BSS
mov ax,#1
push ax
- mov si,#auto_start ! Pointer to first autostart function
+ mov bx,#auto_start ! Pointer to first autostart function
auto_run:
- mov bx,[si]
+ mov [loop_save],bx
+ mov bx,[bx]
test bx,bx
jz no_entry
call bx ! Call the function
no_entry:
- inc si ! SI at next
- inc si
+ mov bx,[loop_save]
+ inc bx ! next
+ inc bx
jmp auto_run ! And round for the next.
call_exit: ! Last item called by above.
diff --git a/libc/bios/bios_vid.c b/libc/bios/bios_vid.c
index 0d891a0..db2e91d 100644
--- a/libc/bios/bios_vid.c
+++ b/libc/bios/bios_vid.c
@@ -84,6 +84,9 @@ static int ctrl = 0;
default:
asm_putc(c);
break;
+ case CTRL('I'):
+ asm_putc(' '); /* Only some BIOS's have this, so play safe */
+ break;
case CTRL('L'):
asm_cpos(0,0);
asm_cls();
@@ -424,6 +427,7 @@ int len;
return 1;
}
ch &= 0x7F;
+ if( ch == '\033' ) ch=3; /* ESC= Interrupt too */
}
if( ch == '\r' )
{
@@ -460,6 +464,26 @@ bios_getc()
/****************************************************************************/
+#ifdef L_bios_khit
+bios_khit()
+{
+#asm
+ mov ah,#1
+ int $16
+ jz nokey
+ cmp ax,#0
+ jnz dort
+ mov ax,#3
+dort:
+ ret
+nokey:
+ xor ax,ax
+#endasm
+}
+#endif
+
+/****************************************************************************/
+
#endif
#endif
#endif
diff --git a/libc/crt0.c b/libc/crt0.c
index b21b525..bdf1585 100644
--- a/libc/crt0.c
+++ b/libc/crt0.c
@@ -23,7 +23,7 @@ export no_op
no_op: ! Generic no operation call
ret
- .ascii __LIBC__ ! Version id.
+ .ascii __LIBC_VER__ ! Version id.
loc 1 ! Segment 1 is where the pointers to the autostart
! functions are stored.
diff --git a/libc/error/Makefile b/libc/error/Makefile
index dc9b98e..ae3d1c0 100644
--- a/libc/error/Makefile
+++ b/libc/error/Makefile
@@ -2,18 +2,17 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifeq ($(LIB_OS),ELKS)
OBJ=error.o sys_errlist.o perror.o sys_siglist.o __assert.o
-endif
-
-all: $(OBJ)
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+all: $(LIBC)($(OBJ))
+ @:
+else
+all:
+ @:
+endif
clean:
rm -f *.o libc.a
diff --git a/libc/getent/Config b/libc/getent/Config
new file mode 100644
index 0000000..0349aba
--- /dev/null
+++ b/libc/getent/Config
@@ -0,0 +1 @@
+getent: Managment for /etc/passwd /etc/group /etc/utmp
diff --git a/libc/pwd/Makefile b/libc/getent/Makefile
index eb4b844..9321ced 100644
--- a/libc/pwd/Makefile
+++ b/libc/getent/Makefile
@@ -2,43 +2,35 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
ifeq ($(PLATFORM),i386-ELKS)
-CFLAGS+=$(WALL)
+CFLAGS=$(ARCH) $(WALL) $(CCFLAGS) $(DEFS)
else
-CFLAGS=$(CCFLAGS) $(LIBDEFS) -ansi
+CFLAGS=$(ARCH) -ansi $(CCFLAGS) $(DEFS)
endif
PSRC=__getpwent.c pwent.c getpwnam.c getpwuid.c putpwent.c getpw.c fgetpwent.c
-ifeq ($(LIB_OS),ELKS)
-POBJ=__getpwent.o pwent.o getpwnam.o getpwuid.o putpwent.o getpw.o fgetpwent.o
-else
-POBJ=
-endif
+GSRC=__getgrent.c grent.c getgrnam.c getgrgid.c fgetgrent.c initgroups.c \
+ config-grp.h
+USRC=utent.c
-all: $(POBJ)
+POBJ=__getpwent.o pwent.o getpwnam.o getpwuid.o putpwent.o getpw.o fgetpwent.o
+GOBJ=__getgrent.o grent.o getgrnam.o getgrgid.o fgetgrent.o initgroups.o
+UOBJ=utent.o
-%.o: %.c
- $(CC) $(CFLAGS) -o $@ $< -c
+ifeq ($(LIB_OS),ELKS)
-libc.a: $(POBJ)
- ar r ../$(LIBC) $(POBJ)
- @touch libc.a
+OBJ=$(POBJ) $(GOBJ) $(UOBJ)
-test: test_pwd.c libpwd.a
- $(CC) $(CFLAGS) test_pwd.c -o test_pwd -L. -lpwd
+all: $(LIBC)($(OBJ))
+ @:
-libpwd.a: $(POBJ)
- ar r libpwd.a $(POBJ)
- ranlib libpwd.a
+$(LIBC)($(GOBJ)): config-grp.h
-libpwd: libpwd.a
+else
+all:
+ @:
+endif
clean:
- rm -f *.o libc.a libpwd.a
-
-
-
+ rm -f *.o libc.a
diff --git a/libc/grp/__getgrent.c b/libc/getent/__getgrent.c
index 612f112..612f112 100644
--- a/libc/grp/__getgrent.c
+++ b/libc/getent/__getgrent.c
diff --git a/libc/pwd/__getpwent.c b/libc/getent/__getpwent.c
index 9836ca7..9836ca7 100644
--- a/libc/pwd/__getpwent.c
+++ b/libc/getent/__getpwent.c
diff --git a/libc/grp/config-grp.h b/libc/getent/config-grp.h
index 337d54b..337d54b 100644
--- a/libc/grp/config-grp.h
+++ b/libc/getent/config-grp.h
diff --git a/libc/grp/config.h b/libc/getent/config.h
index 337d54b..337d54b 100644
--- a/libc/grp/config.h
+++ b/libc/getent/config.h
diff --git a/libc/grp/fgetgrent.c b/libc/getent/fgetgrent.c
index 800236f..800236f 100644
--- a/libc/grp/fgetgrent.c
+++ b/libc/getent/fgetgrent.c
diff --git a/libc/pwd/fgetpwent.c b/libc/getent/fgetpwent.c
index e12b890..e12b890 100644
--- a/libc/pwd/fgetpwent.c
+++ b/libc/getent/fgetpwent.c
diff --git a/libc/grp/getgrgid.c b/libc/getent/getgrgid.c
index c1dd20e..c1dd20e 100644
--- a/libc/grp/getgrgid.c
+++ b/libc/getent/getgrgid.c
diff --git a/libc/grp/getgrnam.c b/libc/getent/getgrnam.c
index e6c27fc..e6c27fc 100644
--- a/libc/grp/getgrnam.c
+++ b/libc/getent/getgrnam.c
diff --git a/libc/pwd/getpw.c b/libc/getent/getpw.c
index 4f4e390..4f4e390 100644
--- a/libc/pwd/getpw.c
+++ b/libc/getent/getpw.c
diff --git a/libc/pwd/getpwnam.c b/libc/getent/getpwnam.c
index 85dbc8e..85dbc8e 100644
--- a/libc/pwd/getpwnam.c
+++ b/libc/getent/getpwnam.c
diff --git a/libc/pwd/getpwuid.c b/libc/getent/getpwuid.c
index ffd58c1..ffd58c1 100644
--- a/libc/pwd/getpwuid.c
+++ b/libc/getent/getpwuid.c
diff --git a/libc/grp/grent.c b/libc/getent/grent.c
index 19d618b..19d618b 100644
--- a/libc/grp/grent.c
+++ b/libc/getent/grent.c
diff --git a/libc/grp/initgroups.c b/libc/getent/initgroups.c
index 35e1d03..35e1d03 100644
--- a/libc/grp/initgroups.c
+++ b/libc/getent/initgroups.c
diff --git a/libc/pwd/putpwent.c b/libc/getent/putpwent.c
index a0035ea..a0035ea 100644
--- a/libc/pwd/putpwent.c
+++ b/libc/getent/putpwent.c
diff --git a/libc/pwd/pwent.c b/libc/getent/pwent.c
index fd65db2..fd65db2 100644
--- a/libc/pwd/pwent.c
+++ b/libc/getent/pwent.c
diff --git a/libc/grp/test_grp.c b/libc/getent/test_grp.c
index b5ecd36..b5ecd36 100644
--- a/libc/grp/test_grp.c
+++ b/libc/getent/test_grp.c
diff --git a/libc/pwd/test_pwd.c b/libc/getent/test_pwd.c
index 74f7657..74f7657 100644
--- a/libc/pwd/test_pwd.c
+++ b/libc/getent/test_pwd.c
diff --git a/libc/utmp/utent.c b/libc/getent/utent.c
index 7f9e19a..7f9e19a 100644
--- a/libc/utmp/utent.c
+++ b/libc/getent/utent.c
diff --git a/libc/grp/Config b/libc/grp/Config
deleted file mode 100644
index 9f49d93..0000000
--- a/libc/grp/Config
+++ /dev/null
@@ -1 +0,0 @@
-grp: /etc/group managment
diff --git a/libc/grp/Makefile b/libc/grp/Makefile
deleted file mode 100644
index f5d42a0..0000000
--- a/libc/grp/Makefile
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (C) 1996 Nat Friedman <ndf@aleph1.mit.edu>
-# This file is part of the Linux-8086 C library and is distributed
-# under the GNU Library General Public License.
-
-TOP=..
-include $(TOP)/Make.defs
-
-ifeq ($(LIB_CPU),g386)
-CFLAGS+=$(WALL)
-else
-CFLAGS=$(CCFLAGS) $(LIBDEFS) -ansi
-endif
-
-GSRC=__getgrent.c grent.c getgrnam.c getgrgid.c fgetgrent.c initgroups.c \
- config-grp.h
-
-ifeq ($(LIB_OS),ELKS)
-GOBJ=__getgrent.o grent.o getgrnam.o getgrgid.o fgetgrent.o initgroups.o
-else
-GOBJ=
-endif
-
-all: $(GOBJ)
-
-%.o: %.c config-grp.h
- $(CC) $(CFLAGS) -o $@ $< -c
-
-libc.a: $(GOBJ)
- ar r ../$(LIBC) $(GOBJ)
- @touch libc.a
-
-test: test_grp.c libgrp.a
- $(CC) $(CFLAGS) test_grp.c -o test_grp -L -lgrp # -static
-
-libgrp: libgrp.a
-
-libgrp.a: $(GOBJ)
- ar r libgrp.a $(GOBJ)
- ranlib libgrp.a
-
-clean:
- rm -f *.o libc.a libgrp.a
diff --git a/libc/gtermcap/Makefile b/libc/gtermcap/Makefile
index 62a966d..44e21da 100644
--- a/libc/gtermcap/Makefile
+++ b/libc/gtermcap/Makefile
@@ -2,22 +2,18 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifeq ($(LIB_OS),ELKS)
OBJ=termcap.o tparam.o
-endif
-
-all: $(OBJ)
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+all: $(LIBC)($(OBJ))
+ @:
+else
+all:
+ @:
+endif
clean:
rm -f *.o libc.a
-$(SOBJ): $(SSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(SSRC)
-
diff --git a/libc/i386fp/Makefile b/libc/i386fp/Makefile
index 88158f7..55d06da 100644
--- a/libc/i386fp/Makefile
+++ b/libc/i386fp/Makefile
@@ -1,19 +1,10 @@
# Makefile for bcc 386 software floating point library
-TOP=..
-include $(TOP)/Make.defs
-
.SUFFIXES: .x # .x files are .s files that need C-preprocessing
.x.o:
cp $< tmp.c
- $(CC) $(CFLAGS) -P tmp.c | $(AS) - -n $* -o $@
-
-# $(ASCPP) $(ASCPPFLAGS) $< >tmp
-# $(AS) tmp -n $* -l tmp.lst -o $@
-
-AS =as86 -3
-ASCPP =/lib/cpp
-ASCPPFLAGS =-P -traditional
+ $(CC) $(CFLAGS) -E tmp.c >tmp.s
+ $(CC) $(CFLAGS) -c tmp.s -A-n -A$* -o $@
FPDIST =Makefile $(FPSRC) test.c bccfp.tex
FPSRC =fadd.x fcomp.x fdiv.x fmul.x fbsr.x \
@@ -26,33 +17,22 @@ FPOBJ =fadd.o fcomp.o fdiv.o fmul.o fpbsr.o \
fperr.o fperror.o fptoi.o fpushd.o fpulld.o \
fpushi.o fpushf.o fpullf.o frexp.o ftst.o \
fabs.o ldexp.o modf.o
-JUNK =tmp tmp.c tmp.lst
+JUNK =tmp tmp.c tmp.s tmp.lst
LIB =.
-test: test.c $(LIB)/libfp.a
- $(CC) -o $@ test.c $(LIB)/libfp.a -lm
-
-$(FPOBJ): fplib.h
-fperr.c fperror.x: fperr.h
-
-$(LIB)/libfp.a: $(FPOBJ)
- ar rc $(LIB)/libfp.a $(FPOBJ)
- rm -f $(JUNK)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
ifeq ($(LIB_CPU),i386)
-libc.a: $(FPOBJ)
+all: $(LIBC)($(FPOBJ))
rm -f $(JUNK)
- ar rc ../libc.a $(FPOBJ)
else
-libc.a:
+all:
+ @:
endif
-dist: $(FPDIST)
- /bin/tar cvf - $(FPDIST) | /bin/compress -b 13 >bccfp.tar.Z
- uue bccfp.tar.Z
+$(LIBC)($(FPOBJ)): fplib.h
+$(LIBC)(fperr.o fperror.o): fperr.h
clean:
rm -f $(FPOBJ) $(JUNK) test
rm -f $(LIB)/libfp.a bccfp.tar.Z bccfp.uue
-
-realclean: clean
diff --git a/libc/i386sys/Config b/libc/i386sys/Config
new file mode 100644
index 0000000..1bf0110
--- /dev/null
+++ b/libc/i386sys/Config
@@ -0,0 +1 @@
+sys386: Linux-i386 system call routines
diff --git a/libc/i386sys/Makefile b/libc/i386sys/Makefile
new file mode 100644
index 0000000..ef01ac9
--- /dev/null
+++ b/libc/i386sys/Makefile
@@ -0,0 +1,52 @@
+# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+# This file is part of the Linux-8086 C library and is distributed
+# under the GNU Library General Public License.
+
+LSRC=syslibc.c
+LOBJ=__cstart3.o time.o abort.o wait.o waitpid.o wait3.o killpg.o setpgrp.o \
+ sleep.o usleep.o
+
+ESRC=exec.c
+EOBJ=execl.o execv.o execle.o execlp.o execvp.o
+
+DSRC=dirent.c
+DOBJ=opendir.o closedir.o readdir.o
+
+ifeq ($(LIB_CPU)-$(LIB_OS),i386-ELKS)
+OBJ=$(LOBJ3) $(LOBJ) $(EOBJ) $(DOBJ)
+SYSCALLS=syscalls
+
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+all: $(SYSCALLS) $(LIBC)($(OBJ))
+ @:
+
+syscalls: syscall.mak
+ $(MAKE) -f syscall.mak LIBC="$(LIBC)" CFLAGS="$(CFLAGS)"
+
+syscall.mak: mksyscall syscall.dat
+ sh mksyscall
+
+$(LIBC)($(LOBJ)): $(LSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+$(LIBC)($(DOBJ)): $(DSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+$(LIBC)($(EOBJ)): $(ESRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+else
+all:
+ @:
+endif
+
+clean:
+ rm -f *.o libc.a
+ rm -f syscall.c syscall.mak
+
diff --git a/libc/i386sys/dirent.c b/libc/i386sys/dirent.c
new file mode 100644
index 0000000..8f7574c
--- /dev/null
+++ b/libc/i386sys/dirent.c
@@ -0,0 +1,106 @@
+
+#include <errno.h>
+#include <sys/types.h>
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <dirent.h>
+#include <malloc.h>
+
+#ifdef L_opendir
+DIR *
+opendir(dname)
+const char *dname;
+{
+ struct stat st;
+ int fd;
+ DIR *p;
+
+ if (stat(dname, &st) < 0)
+ return 0;
+
+ if (!S_ISDIR(st.st_mode))
+ {
+ errno = ENOTDIR;
+ return 0;
+ }
+ if ((fd = open(dname, O_RDONLY)) < 0)
+ return 0;
+
+ p = malloc(sizeof(DIR));
+ if (p == 0)
+ {
+ close(fd);
+ return 0;
+ }
+
+ p->dd_buf = malloc(sizeof(struct dirent));
+ if (p->dd_buf == 0)
+ {
+ free(p);
+ close(fd);
+ return 0;
+ }
+ p->dd_fd = fd;
+ p->dd_loc = p->dd_size = 0;
+
+ return p;
+}
+#endif
+
+#ifdef L_closedir
+int
+closedir(dirp)
+DIR *dirp;
+{
+ int fd;
+ fd = dirp->dd_fd;
+ free(dirp->dd_buf);
+ free(dirp);
+ return close(fd);
+}
+#endif
+
+#ifdef __AS386_16__
+#ifdef L_readdir
+/*
+ * This currently assumes we see a v. simple diectory structure, it's
+ * probably faked!
+ */
+struct dirent *
+readdir(dirp)
+DIR *dirp;
+{
+ int cc;
+ cc = read(dirp->dd_fd, dirp->dd_buf, sizeof(struct dirent));
+
+ if (cc <= 0)
+ return 0;
+ if (cc != sizeof(struct dirent))
+ {
+ errno = EBADF;
+ return 0;
+ }
+ return dirp->dd_buf;
+}
+#endif
+#else
+
+/* This is for 386 linux */
+
+#ifdef L_readdir
+struct dirent *
+readdir(dirp)
+DIR *dirp;
+{
+ int cc;
+
+ cc = __readdir(dirp->dd_fd, dirp->dd_buf, 1);
+ if (cc <= 0)
+ return 0;
+ if (cc>1) dirp->dd_buf->d_name[cc] = 0;
+
+ return dirp->dd_buf;
+}
+#endif
+
+#endif
diff --git a/libc/i386sys/exec.c b/libc/i386sys/exec.c
new file mode 100644
index 0000000..411b744
--- /dev/null
+++ b/libc/i386sys/exec.c
@@ -0,0 +1,292 @@
+
+#include <errno.h>
+#include <sys/stat.h>
+
+extern char ** environ;
+
+#ifdef L_execl
+int
+execl(fname, arg0)
+char * fname, *arg0;
+{
+ return execve(fname, &arg0, environ);
+}
+#endif
+
+#ifdef L_execv
+int
+execv(fname, argv)
+char * fname, **argv;
+{
+ return execve(fname, argv, environ);
+}
+#endif
+
+#ifdef L_execle
+int
+execle(fname, arg0)
+char *fname, *arg0;
+{
+ char ** envp = &arg0;
+ while(*envp) envp++;
+ return execve(fname, &arg0, envp+1);
+}
+#endif
+
+#ifdef L_execve
+int
+execve(fname, argv, envp)
+char * fname;
+char ** argv;
+char ** envp;
+{
+ char **p;
+ int argv_len=0, argv_count=0;
+ int envp_len=0, envp_count=0;
+ int stack_bytes;
+ unsigned short * pip;
+ char * pcp, * stk_ptr, *baseoff;
+ int rv;
+
+ /* How much space for argv */
+ for(p=argv; p && *p && argv_len >= 0; p++)
+ {
+ argv_count++; argv_len += strlen(*p)+1;
+ }
+
+ /* How much space for envp */
+ for(p=envp; p && *p && envp_len >= 0; p++)
+ {
+ envp_count++; envp_len += strlen(*p)+1;
+ }
+
+ /* tot it all up */
+ stack_bytes = 2 /* argc */
+ + argv_count * 2 + 2 /* argv */
+ + argv_len
+ + envp_count * 2 + 2 /* envp */
+ + envp_len;
+
+ /* Allocate it */
+ if( argv_len < 0 || envp_len < 0 || stack_bytes <= 0
+ || (int)(stk_ptr = (char*)sbrk(stack_bytes)) == -1)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+
+/* Sanity check
+ printf("Argv = (%d,%d), Envp=(%d,%d), stack=%d\n",
+ argv_count, argv_len, envp_count, envp_len, stack_bytes);
+*/
+
+ /* Now copy in the strings */
+ pip=(unsigned short *) stk_ptr;
+ pcp=stk_ptr+2*(1+argv_count+1+envp_count+1);
+
+ /* baseoff = stk_ptr + stack_bytes; */
+ baseoff = stk_ptr;
+ *pip++ = argv_count;
+ for(p=argv; p && *p; p++)
+ {
+ int l;
+ *pip++ = pcp-baseoff;
+ l = strlen(*p)+1;
+ memcpy(pcp, *p, l);
+ pcp += l;
+ }
+ *pip++ = 0;
+
+ for(p=envp; p && *p; p++)
+ {
+ int l;
+ *pip++ = pcp-baseoff;
+ l = strlen(*p)+1;
+ memcpy(pcp, *p, l);
+ pcp += l;
+ }
+ *pip++ = 0;
+
+ rv = __exec(fname, stk_ptr, stack_bytes);
+ /* FIXME: This will probably have to interpret '#!' style exe's */
+ sbrk(-stack_bytes);
+ return rv;
+}
+#endif
+
+#ifdef L_execlp
+int
+execlp(fname, arg0)
+char * fname, *arg0;
+{
+ return execvp(fname, &arg0);
+}
+#endif
+
+#ifdef L_execvp
+int
+execvp(fname, argv)
+char * fname, **argv;
+{
+ char *pname = fname, *path;
+ int besterr = ENOENT;
+ int flen, plen;
+ char * bp = sbrk(0);
+
+ if( *fname != '/' && (path = getenv("PATH")) != 0 )
+ {
+ flen = strlen(fname)+2;
+
+ for(;path;)
+ {
+ if( *path == ':' || *path == '\0' )
+ {
+ tryrun(fname, argv);
+ if( errno == EACCES ) besterr = EACCES;
+ if( *path ) path++; else break;
+ }
+ else
+ {
+ char * p = strchr(path, ':');
+ if(p) *p = '\0';
+ plen = strlen(path);
+ pname = sbrk(plen+flen);
+
+ strcpy(pname, path);
+ strcat(pname, "/");
+ strcat(pname, fname);
+
+ tryrun(pname, argv);
+ if( errno == EACCES ) besterr = EACCES;
+
+ brk(pname);
+ pname = fname;
+ if(p) *p++ = ':';
+ path=p;
+ }
+ }
+ }
+
+ tryrun(pname, argv);
+ brk(bp);
+ if( errno == ENOENT || errno == 0 ) errno = besterr;
+ return -1;
+}
+
+static int tryrun(pname, argv)
+char * pname;
+char ** argv;
+{
+static char *shprog[] = {"/bin/sh", "", 0};
+ struct stat st;
+
+ if( stat(pname, &st) < 0 ) return;
+ if( !S_ISREG(st.st_mode) ) return;
+
+#ifdef __AS386_16__
+ __execvve(pname, (void*)0, argv, environ);
+ if( errno == ENOEXEC )
+ {
+ shprog[1] = pname;
+ __execvve(shprog[0], shprog, argv, environ);
+ }
+#else
+ execve(pname, argv, environ);
+ /* FIXME - running /bin/sh in 386 mode */
+#endif
+}
+
+#ifdef __AS386_16__
+static int
+__execvve(fname, interp, argv, envp)
+char * fname;
+char ** interp;
+char ** argv;
+char ** envp;
+{
+ char **p;
+ int argv_len=0, argv_count=0;
+ int envp_len=0, envp_count=0;
+ int stack_bytes;
+ unsigned short * pip;
+ char * pcp, * stk_ptr, *baseoff;
+ int rv;
+
+ /* How much space for argv */
+ for(p=interp; p && *p && argv_len >= 0; p++)
+ {
+ argv_count++; argv_len += strlen(*p)+1;
+ }
+ for(p=argv; p && *p && argv_len >= 0; p++)
+ {
+ argv_count++; argv_len += strlen(*p)+1;
+ }
+
+ /* How much space for envp */
+ for(p=envp; p && *p && envp_len >= 0; p++)
+ {
+ envp_count++; envp_len += strlen(*p)+1;
+ }
+
+ /* tot it all up */
+ stack_bytes = 2 /* argc */
+ + argv_count * 2 + 2 /* argv */
+ + argv_len
+ + envp_count * 2 + 2 /* envp */
+ + envp_len;
+
+ /* Allocate it */
+ if( argv_len < 0 || envp_len < 0 || stack_bytes <= 0
+ || (int)(stk_ptr = (char*)sbrk(stack_bytes)) == -1)
+ {
+ errno = ENOMEM;
+ return -1;
+ }
+
+/* Sanity check
+ printf("Argv = (%d,%d), Envp=(%d,%d), stack=%d\n",
+ argv_count, argv_len, envp_count, envp_len, stack_bytes);
+*/
+
+ /* Now copy in the strings */
+ pip=(unsigned short *) stk_ptr;
+ pcp=stk_ptr+2*(1+argv_count+1+envp_count+1);
+
+ /* baseoff = stk_ptr + stack_bytes; */
+ baseoff = stk_ptr;
+ *pip++ = argv_count;
+ for(p=interp; p && *p; p++)
+ {
+ int l;
+ *pip++ = pcp-baseoff;
+ l = strlen(*p)+1;
+ memcpy(pcp, *p, l);
+ pcp += l;
+ }
+ for(p=argv; p && *p; p++)
+ {
+ int l;
+ *pip++ = pcp-baseoff;
+ l = strlen(*p)+1;
+ memcpy(pcp, *p, l);
+ pcp += l;
+ }
+ *pip++ = 0;
+
+ for(p=envp; p && *p; p++)
+ {
+ int l;
+ *pip++ = pcp-baseoff;
+ l = strlen(*p)+1;
+ memcpy(pcp, *p, l);
+ pcp += l;
+ }
+ *pip++ = 0;
+
+ rv = __exec(fname, stk_ptr, stack_bytes);
+ /* FIXME: This will probably have to interpret '#!' style exe's */
+ sbrk(-stack_bytes);
+ return rv;
+}
+#endif
+#endif
diff --git a/libc/syscall/mksys386 b/libc/i386sys/mksyscall
index 5abcbf8..d9b7f3a 100644
--- a/libc/syscall/mksys386
+++ b/libc/i386sys/mksyscall
@@ -13,9 +13,9 @@
# 0 = each is complete
# 1 = Short codes calling common function
-rm -f syscall.c syscall.mak call_tab.v defn_tab.v
+rm -f syscall.c syscall.mak
-tr '[A-Z]' '[a-z]' < sys386.dat | \
+tr '[A-Z]' '[a-z]' < syscall.dat | \
awk 'BEGIN{
print "# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>" > "syscall.mak";
print "# This file is part of the Linux-8086 C library and is distributed" > "syscall.mak";
@@ -129,24 +129,15 @@ END{
cat >> syscall.mak <<\!
-TOP=..
-include $(TOP)/Make.defs
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-all: $(OBJ)
+all: $(LIBC)($(OBJ))
+ @:
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
-
-$(OBJ): sys386.dat mksys386
- $(CC) $(CFLAGS) -c -DL_$* -o $@ syscall.c
+$(LIBC)($(OBJ)): syscall.dat
+ $(CC) $(CFLAGS) -DL_$* syscall.c -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
!
-rv=$?
-if [ "$rv" != 0 ]
-then exit $rv
-fi
-
-export MAKELEVEL
-MAKELEVEL=0
-exec make -f syscall.mak $1
+exit $?
diff --git a/libc/i386sys/signal.c b/libc/i386sys/signal.c
new file mode 100644
index 0000000..dad3389
--- /dev/null
+++ b/libc/i386sys/signal.c
@@ -0,0 +1,99 @@
+
+#ifndef __MSDOS__
+#ifdef __AS386_16__
+
+#include <errno.h>
+#include <signal.h>
+
+typedef __sighandler_t Sig;
+
+extern int __signal __P((int, __sighandler_t));
+static Sig system_signal();
+
+Sig __sigtable[_NSIG-1];
+
+/*
+ * Signal handler.
+ *
+ */
+
+/*
+ * KERNEL INTERFACE:
+ * It is assumed the kernel will never give us a signal we haven't
+ * _explicitly_ asked for!
+ *
+ * The Kernel need only save space for _one_ function pointer
+ * (to system_signal) and must deal with SIG_DFL and SIG_IGN
+ * in kernel space.
+ *
+ * When a signal is required the kernel must set all the registers as if
+ * returning from a interrupt normally then push the number of the signal
+ * to be generated, push the current pc value, then set the pc to the
+ * address of the 'system_signal' function.
+ */
+
+Sig
+signal(number, pointer)
+int number;
+Sig pointer;
+{
+ Sig old_sig;
+ int rv;
+ if( number < 1 || number >= _NSIG ) { errno=EINVAL; return SIG_ERR; }
+
+ if( pointer == SIG_DFL || pointer == SIG_IGN )
+ rv = __signal(number, pointer);
+ else
+ rv = __signal(number, (__sighandler_t) system_signal);
+
+ if( rv < 0 ) return SIG_ERR;
+
+ old_sig = __sigtable[number-1];
+ __sigtable[number-1] = pointer;
+
+ switch(rv)
+ {
+ case 0: return SIG_DFL;
+ case 1: return SIG_IGN;
+ return old_sig;
+ }
+}
+
+#asm
+ .text
+_system_signal: ! When this is called by the kernel the stack contains
+ pushf ! in order:
+ push ax !
+ push bx ! The signal number, (NOS)
+ push cx ! The program counter, (TOS)
+ push dx !
+ push si ! It does NOT contain the CS register or the flags.
+ push di ! This means it cannot be unraveled by an iret.
+ push bp
+ push es ! Note also only ES segment register is saved.
+ mov bx,sp ! Unlike minix the rv from a system call is in AX.
+ mov bx,[bx+20]
+#if __FIRST_ARG_IN_AX__
+ mov ax,bx
+#else
+ push bx ! NB this is _unchecked_, do we want to ?
+#endif
+ add bx,bx
+ mov bx,[bx+___sigtable-2] ! Offset by 2 cause no entry for signal 0
+ call bx ! Do we want to check BX for 0 or 1 ?
+ inc sp
+ inc sp
+ pop es
+ pop bp
+ pop di
+ pop si
+ pop dx
+ pop cx
+ pop bx
+ pop ax
+ popf
+ ret #2 ! Get rid of the signum too.
+#endasm
+
+#endif /* __AS386_16__ */
+#endif /* __MSDOS__ */
diff --git a/libc/syscall/sys386.dat b/libc/i386sys/syscall.dat
index da9ad6c..da9ad6c 100644
--- a/libc/syscall/sys386.dat
+++ b/libc/i386sys/syscall.dat
diff --git a/libc/i386sys/syslibc.c b/libc/i386sys/syslibc.c
new file mode 100644
index 0000000..60dda42
--- /dev/null
+++ b/libc/i386sys/syslibc.c
@@ -0,0 +1,255 @@
+/* Copyright (C) 1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+ * This file is part of the Linux-8086 C library and is distributed
+ * under the GNU Library General Public License.
+ */
+
+#include <sys/types.h>
+#include <errno.h>
+#include <time.h>
+#include <sys/times.h>
+
+/* MSDOS has it's own versions */
+#ifndef __MSDOS__
+#ifdef __AS386_32__
+
+/********************** Function __cstartup *******************************/
+
+#ifdef L___cstart3
+
+void (*__cleanup)() = 0;
+char ** environ;
+
+#asm
+ loc 2
+call_main:
+ .long _main ! Segment 2 is the trailing pointers, main and the
+ .long call_exit ! routine to call exit.
+#if __FIRST_ARG_IN_AX__
+ .data
+saved_arg1:
+ .long 0
+#endif
+ .data
+loop_safe:
+ .long 0
+ .text
+
+export ___mkargv
+___mkargv: ! BCC Tells linker to init argv ... none needed.
+
+export ___cstartup
+___cstartup: ! Crt0 startup (Linux style)
+ mov eax,[esp]
+ test eax,eax
+ jz call_exit ! If argc == 0 this is being called by ldd, exit.
+ mov eax,[esp+8]
+ mov [_environ],eax
+#if __FIRST_ARG_IN_AX__
+ pop [saved_arg1] ! Argc will go into eax
+#endif
+
+ mov ebx,#auto_start ! Pointer to first autostart function
+auto_run:
+#if __FIRST_ARG_IN_AX__
+ mov eax,[saved_arg1]
+#endif
+ mov [loop_safe],ebx
+ mov ebx,[ebx]
+ test ebx,ebx
+ jz no_func
+ call ebx ! Call the function
+no_func:
+ mov ebx,[loop_safe]
+ add ebx,#4 ! next
+ jmp auto_run ! And round for the next.
+
+call_exit: ! Last item called by above.
+ pop ebx ! Be tidy.
+#if !__FIRST_ARG_IN_AX__
+ push eax ! At the end the last called was main() push it`s
+#endif
+ call _exit ! return val and call exit();
+bad_exit:
+ jmp bad_exit ! Exit returned !!
+
+export _exit
+export __exit
+_exit: ! exit(rv) function
+#if __FIRST_ARG_IN_AX__
+ mov [saved_arg1],eax
+#else
+ push [esp+4] ! Copy the `rv` for the exit fuctions.
+#endif
+ mov ebx,[___cleanup] ! Call exit, normally this is `__do_exit`
+ test ebx,ebx
+ je no_clean ! But it`s default is null
+ call ebx
+no_clean:
+#if __FIRST_ARG_IN_AX__
+ mov eax,[saved_arg1]
+#else
+ add esp,#4
+#endif
+__exit: ! _exit(rv)
+ br ___exit ! This is just an alias for __exit();
+
+#endasm
+#endif
+
+/********************** Function time ************************************/
+
+#ifdef L_time
+time_t time(where)
+time_t *where;
+{
+ struct timeval rv;
+ if( gettimeofday(&rv, (void*)0) < 0 ) return -1;
+ if(where) *where = rv.tv_sec;
+ return rv.tv_sec;
+}
+#endif
+
+/********************** Function abort ************************************/
+
+#ifdef L_abort
+#include <signal.h>
+
+int abort()
+{
+ signal(SIGABRT, SIG_DFL);
+ kill(SIGABRT, getpid()); /* Correct one */
+ pause(); /* System may just schedule */
+ signal(SIGKILL, SIG_DFL);
+ kill(SIGKILL, getpid()); /* Can't trap this! */
+ __exit(255); /* WHAT!! */
+}
+#endif
+
+/********************** Function wait ************************************/
+
+#ifdef L_wait
+int
+wait(status)
+int * status;
+{
+ return wait4(-1, status, 0, (void*)0);
+}
+#endif
+
+/********************** Function wait3 **************************************/
+
+#ifdef L_wait3
+int
+wait3(status, opts, usage)
+int * status;
+int opts;
+struct rusage * usage;
+{
+ return wait4(-1, status, opts, usage);
+}
+#endif
+
+/********************** Function waitpid ************************************/
+
+#ifdef L_waitpid
+int
+waitpid(pid, status, opts)
+int pid;
+int * status;
+int opts;
+{
+ return wait4(pid, status, opts, (void*)0);
+}
+#endif
+
+/********************** Function killpg ************************************/
+
+#ifdef L_killpg
+int
+killpg(pid, sig)
+int pid;
+int sig;
+{
+ if(pid == 0)
+ pid = getpgrp();
+ if(pid > 1)
+ return kill(-pid, sig);
+ errno = EINVAL;
+ return -1;
+}
+#endif
+
+/********************** Function setpgrp ************************************/
+
+#ifdef L_setpgrp
+int
+setpgrp()
+{
+ return setpgid(0,0);
+}
+#endif
+
+/********************** Function sleep ************************************/
+
+#ifdef L_sleep
+#include <signal.h>
+
+/* This uses SIGALRM, it does keep the previous alarm call but will lose
+ * any alarms that go off during the sleep
+ */
+
+static void alrm() { }
+
+unsigned int sleep(seconds)
+unsigned int seconds;
+{
+ void (*last_alarm)();
+ unsigned int prev_sec;
+
+ prev_sec = alarm(0);
+ if( prev_sec <= seconds ) prev_sec = 1; else prev_sec -= seconds;
+
+ last_alarm = signal(SIGALRM, alrm);
+ alarm(seconds);
+ pause();
+ seconds = alarm(prev_sec);
+ signal(SIGALRM, last_alarm);
+ return seconds;
+}
+#if 0
+ /* Is this a better way ? If we have select of course :-) */
+#include <sys/time.h>
+unsigned int
+sleep(seconds)
+unsigned int seconds;
+{
+ struct timeval timeout;
+ time_t start = time((void*)0);
+ timeout.tv_sec = seconds;
+ timeout.tv_usec = 0;
+ select(1, NULL, NULL, NULL, &timeout);
+ return seconds - (time((void*)0) - start);
+}
+#endif
+
+#endif
+
+/********************** Function usleep ************************************/
+
+#ifdef L_usleep
+#include <sys/time.h>
+void
+usleep(useconds)
+unsigned long useconds;
+{
+ struct timeval timeout;
+ timeout.tv_sec = useconds%1000000L;
+ timeout.tv_usec = useconds/1000000L;
+ select(1, NULL, NULL, NULL, &timeout);
+}
+#endif
+
+/********************** THE END ********************************************/
+
+#endif /* __MSDOS__ */
+#endif
diff --git a/libc/include/setjmp.h b/libc/include/setjmp.h
index c2bfadb..162743b 100644
--- a/libc/include/setjmp.h
+++ b/libc/include/setjmp.h
@@ -17,10 +17,14 @@ typedef struct
unsigned int di;
} jmp_buf[1];
-int setjmp __P((jmp_buf env));
-void longjmp __P((jmp_buf env, int rv));
+int _setjmp __P((jmp_buf env));
+void _longjmp __P((jmp_buf env, int rv));
/* LATER: Seems GNU beat me to it, must be OK then :-)
* Humm, what's this about setjmp being a macro !?
+ * Ok, use the BSD names as normal use the ANSI as macros
*/
+
+#define setjmp(a_env) _setjmp(a_env)
+#define longjmp(a_env, a_rv) _longjmp(a_env, a_rv)
#endif
diff --git a/libc/include/stdarg.h b/libc/include/stdarg.h
index d30fbd8..321e664 100644
--- a/libc/include/stdarg.h
+++ b/libc/include/stdarg.h
@@ -41,3 +41,7 @@
#endif
#endif /* __STDARG_H */
+
+#if __FIRST_ARG_IN_AX__
+#error First arg is in a register, stdarg.h cannot take its address
+#endif
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index d21f986..b1cf558 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -34,9 +34,9 @@ struct stat {
unsigned long __unused4;
unsigned long __unused5;
};
+#endif
-#else
-
+#ifdef __AS386_16__
struct stat
{
dev_t st_dev;
diff --git a/libc/kinclude/Makefile b/libc/kinclude/Makefile
index 8982f57..aa4ef72 100644
--- a/libc/kinclude/Makefile
+++ b/libc/kinclude/Makefile
@@ -2,14 +2,8 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
-OBJ=
-
-all: $(OBJ)
-
-libc.a:
+all:
+ @:
transfer:
-@rm -f ../include/linuxmt
diff --git a/libc/malloc1/Makefile b/libc/malloc1/Makefile
index 6322454..a4107b8 100644
--- a/libc/malloc1/Makefile
+++ b/libc/malloc1/Makefile
@@ -1,24 +1,23 @@
-
-TOP=..
-include $(TOP)/Make.defs
+# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+# This file is part of the Linux-8086 C library and is distributed
+# under the GNU Library General Public License.
ASRC=malloc.c
AOBJ=malloc.o alloca.o free.o calloc.o realloc.o
-OBJ=$(AOBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-all: $(OBJ)
+all: $(LIBC)($(AOBJ))
+ @:
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
clean:
rm -f *.o libc.a
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
-
transfer:
-@rm ../include/malloc.h
cp -p malloc.h ../include/.
diff --git a/libc/malloc2/Makefile b/libc/malloc2/Makefile
index 0396df2..ea944db 100644
--- a/libc/malloc2/Makefile
+++ b/libc/malloc2/Makefile
@@ -1,22 +1,12 @@
-TOP=..
-include $(TOP)/Make.defs
+OBJ=malloc.o stack.o
-MOBJ=malloc.o stack.o
-
-OBJ=$(MOBJ)
-
-all: $(OBJ)
-
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+all: $(LIBC)($(OBJ))
+ @:
clean:
- rm -f $(OBJ) libc.a
-
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
+ rm -f *.o libc.a
transfer:
-@rm ../include/malloc.h
diff --git a/libc/misc/Makefile b/libc/misc/Makefile
index c7ed8fa..9bb579c 100644
--- a/libc/misc/Makefile
+++ b/libc/misc/Makefile
@@ -2,9 +2,6 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
MSRC=aliases.c
MOBJ=abs.o raise.o bcopy.o bzero.o bcmp.o index.o rindex.o remove.o creat.o
@@ -29,31 +26,37 @@ ifneq ($(LIB_CPU),i86)
OBJ+=strtod.o
endif
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+all: $(LIBC)
+ @:
+
+$(LIBC): $(LIBC)($(OBJ))
+
+$(LIBC)($(MOBJ)): $(MSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC)($(EOBJ)): $(ESRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
clean:
rm -f *.o libc.a
-$(MOBJ): $(MSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(MSRC)
+$(LIBC)(strtol.o): strtol.c
+ $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(EOBJ): $(ESRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ESRC)
+$(LIBC)(strtod.o): strtod.c
+ $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-crypt.o: crypt.c
-ifeq ($(LIB_CPU),g386)
- $(CC) $(CFLAGS) $< -c -o $@ $(WALL)
-else
- $(CC) $(CFLAGS) $< -c -o $@ -ansi
-endif
-
-strto%.o: strto%.c
-ifeq ($(LIB_CPU),g386)
- $(CC) $(CFLAGS) $< -c -o $@ $(WALL)
-else
- $(CC) $(CFLAGS) $< -c -o $@ -ansi
-endif
+$(LIBC)(crypt.o): crypt.c
+ $(CC) -c -ansi $(ARCH) $(CCFLAGS) $(DEFS) $*.c
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
diff --git a/libc/misc/strtod.c b/libc/misc/strtod.c
index 8acb423..cef9d9f 100644
--- a/libc/misc/strtod.c
+++ b/libc/misc/strtod.c
@@ -20,6 +20,9 @@
#include <stdlib.h>
#include <ctype.h>
+#ifndef __AS386_16__
+/* BCC-16 has broken FP code */
+
double
strtod(const char *nptr, char ** endptr)
{
@@ -94,3 +97,4 @@ strtod(const char *nptr, char ** endptr)
}
return (negative ? -number:number);
}
+#endif
diff --git a/libc/msdos/Makefile b/libc/msdos/Makefile
index f069699..7a5eaa6 100644
--- a/libc/msdos/Makefile
+++ b/libc/msdos/Makefile
@@ -2,9 +2,6 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
ASRC=msdos.c
AOBJ= dos_start.o __mkargv.o __mkenvp.o dos__fconv.o dos_read.o \
dos_write.o dos_open.o dos_close.o dos_unlink.o dos_lseek.o \
@@ -17,24 +14,32 @@ BOBJ= __seg_regs.o __peek_es.o __poke_es.o __deek_es.o __doke_es.o \
ifeq ($(LIB_CPU),i86)
ifeq ($(LIB_OS),DOS)
-OBJ=$(AOBJ) $(BOBJ)
+OBJ=$(AOBJ) $(BOBJ) time.o
else
OBJ=$(BOBJ)
endif
-endif
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+all: $(LIBC)
+ @:
-clean:
- rm -f *.o libc.a
+$(LIBC): $(LIBC)($(OBJ))
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(BOBJ): $(BSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(BSRC)
+$(LIBC)($(BOBJ)): $(BSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+else
+all:
+ @:
+endif
+
+clean:
+ rm -f *.o libc.a
diff --git a/libc/pwd/Config b/libc/pwd/Config
deleted file mode 100644
index b5aaad0..0000000
--- a/libc/pwd/Config
+++ /dev/null
@@ -1 +0,0 @@
-pwd: /etc/passwd managment
diff --git a/libc/regexp/Makefile b/libc/regexp/Makefile
index 71c2b81..0276aba 100644
--- a/libc/regexp/Makefile
+++ b/libc/regexp/Makefile
@@ -1,28 +1,27 @@
-TOP=..
-include $(TOP)/Make.defs
-
OBJ=regexp.o regsub.o
LSRC=regexp.c regsub.c regerror.c
-try: try.o $(OBJ)
- $(CC) $(CFLAGS) try.o $(OBJ) -o try
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-# Regression test.
-test: try tests
- @echo 'No news is good news...'
- try <tests
+all: $(LIBC)
+ @:
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC): $(LIBC)($(OBJ))
transfer:
-@rm -f ../include/regexp.h ../include/regmagic.h
cp -p regexp.h regmagic.h ../include/.
-regexp.o: regexp.c regexp.h regmagic.h
-regsub.o: regsub.c regexp.h regmagic.h
+$(LIBC)(regexp.o): regexp.c regexp.h regmagic.h
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+$(LIBC)(regsub.o): regsub.c regexp.h regmagic.h
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
clean:
rm -f libc.a *.o core mon.out timer.t.h dMakefile dtr try timer
diff --git a/libc/stdio2/Makefile b/libc/stdio2/Makefile
index f77df3a..80f2e3b 100644
--- a/libc/stdio2/Makefile
+++ b/libc/stdio2/Makefile
@@ -1,6 +1,6 @@
-
-TOP=..
-include $(TOP)/Make.defs
+# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
+# This file is part of the Linux-8086 C library and is distributed
+# under the GNU Library General Public License.
ifneq ($(LIB_CPU),i86)
CFLAGS=$(CCFLAGS) $(LIBDEFS) -DFLOATS
@@ -19,11 +19,27 @@ SOBJ=scanf.o sscanf.o fscanf.o vscanf.o vsscanf.o vfscanf.o
OBJ= $(AOBJ) $(POBJ) $(SOBJ)
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+all: $(LIBC)
+ @:
+
+$(LIBC): $(LIBC)($(OBJ))
+
+$(LIBC)($(AOBJ)): $(ASRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC)($(POBJ)): $(PSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+$(LIBC)($(SOBJ)): $(SSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
transfer:
-@rm -f ../include/stdio.h
@@ -32,14 +48,5 @@ transfer:
clean:
rm -f *.o libc.a
-$(OBJ): stdio.h
-
-$(AOBJ): $(ASRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ASRC)
-
-$(POBJ): $(PSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(PSRC)
-
-$(SOBJ): $(SSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(SSRC)
+$(LIBC)($(OBJ)): stdio.h
diff --git a/libc/stdio2/printf.c b/libc/stdio2/printf.c
index 5a5744d..45c4aa7 100644
--- a/libc/stdio2/printf.c
+++ b/libc/stdio2/printf.c
@@ -19,7 +19,13 @@
#include <sys/types.h>
#include <fcntl.h>
+#ifdef __STDC__
#include <stdarg.h>
+#define va_strt va_start
+#else
+#include <varargs.h>
+#define va_strt(p,i) va_start(p)
+#endif
#include "stdio.h"
@@ -28,13 +34,14 @@
#ifdef __STDC__
int printf(const char * fmt, ...)
#else
-int printf(fmt)
+int printf(fmt, va_alist)
__const char *fmt;
+va_dcl
#endif
{
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
rv = vfprintf(stdout,fmt,ptr);
va_end(ptr);
return rv;
@@ -45,9 +52,10 @@ __const char *fmt;
#ifdef __STDC__
int sprintf(char * sp, const char * fmt, ...)
#else
-int sprintf(sp, fmt)
+int sprintf(sp, fmt, va_alist)
char * sp;
__const char *fmt;
+va_dcl
#endif
{
static FILE string[1] =
@@ -58,7 +66,7 @@ static FILE string[1] =
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
string->bufpos = sp;
rv = vfprintf(string,fmt,ptr);
va_end(ptr);
@@ -71,14 +79,15 @@ static FILE string[1] =
#ifdef __STDC__
int fprintf(FILE * fp, const char * fmt, ...)
#else
-int fprintf(fp, fmt)
+int fprintf(fp, fmt, va_alist)
FILE * fp;
__const char *fmt;
+va_dcl
#endif
{
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
rv = vfprintf(fp,fmt,ptr);
va_end(ptr);
return rv;
diff --git a/libc/stdio2/scanf.c b/libc/stdio2/scanf.c
index c43320d..2d61ab2 100644
--- a/libc/stdio2/scanf.c
+++ b/libc/stdio2/scanf.c
@@ -1,19 +1,27 @@
#include <stdio.h>
#include <ctype.h>
-#include <stdarg.h>
#include <string.h>
+#ifdef __STDC__
+#include <stdarg.h>
+#define va_strt va_start
+#else
+#include <varargs.h>
+#define va_strt(p,i) va_start(p)
+#endif
+
#ifdef L_scanf
#ifdef __STDC__
int scanf(const char * fmt, ...)
#else
-int scanf(fmt)
+int scanf(fmt, va_alist)
__const char *fmt;
+va_dcl
#endif
{
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
rv = vfscanf(stdin,fmt,ptr);
va_end(ptr);
return rv;
@@ -24,9 +32,10 @@ __const char *fmt;
#ifdef __STDC__
int sscanf(char * sp, const char * fmt, ...)
#else
-int sscanf(sp, fmt)
+int sscanf(sp, fmt, va_alist)
char * sp;
__const char *fmt;
+va_dcl
#endif
{
static FILE string[1] =
@@ -37,7 +46,7 @@ static FILE string[1] =
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
string->bufpos = sp;
rv = vfscanf(string,fmt,ptr);
va_end(ptr);
@@ -49,14 +58,15 @@ static FILE string[1] =
#ifdef __STDC__
int fscanf(FILE * fp, const char * fmt, ...)
#else
-int fscanf(fp, fmt)
+int fscanf(fp, fmt, va_alist)
FILE * fp;
__const char *fmt;
+va_dcl
#endif
{
va_list ptr;
int rv;
- va_start(ptr, fmt);
+ va_strt(ptr, fmt);
rv = vfscanf(fp,fmt,ptr);
va_end(ptr);
return rv;
diff --git a/libc/stdio2/stdio.c b/libc/stdio2/stdio.c
index bab246b..156d3e3 100644
--- a/libc/stdio2/stdio.c
+++ b/libc/stdio2/stdio.c
@@ -506,12 +506,12 @@ int ref;
{
/* Use fflush to sync the pointers */
-#if 0
+#if 1
/* if __MODE_READING and no ungetc ever done can just move pointer */
/* This needs testing! */
if ( (fp->mode &(__MODE_READING | __MODE_UNGOT)) == __MODE_READING &&
- ( ref == SEEK_SET || ref == SEEK_CUR )
+ ( ref == SEEK_SET || ref == SEEK_CUR ))
{
long fpos = lseek(fp->fd, 0L, SEEK_CUR);
if( fpos == -1 ) return EOF;
diff --git a/libc/string/Makefile b/libc/string/Makefile
index d72c2e0..61fad41 100644
--- a/libc/string/Makefile
+++ b/libc/string/Makefile
@@ -2,9 +2,6 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
SSRC=string.c
SOBJ=strlen.o strcat.o strcpy.o strcmp.o strncat.o strncpy.o strncmp.o \
strchr.o strrchr.o strdup.o memcpy.o memccpy.o memchr.o memset.o \
@@ -13,19 +10,21 @@ SOBJ=strlen.o strcat.o strcpy.o strcmp.o strncat.o strncpy.o strncmp.o \
OBJ=$(SOBJ) strpbrk.o strsep.o strstr.o strtok.o strcspn.o \
strspn.o strcasecmp.o strncasecmp.o
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+all: $(LIBC)
+ @:
+
+$(LIBC): $(LIBC)($(OBJ))
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC)($(SOBJ)): $(SSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
transfer:
-@rm -f ../include/string.h
cp -p string.h ../include/.
clean:
- rm -f *.o libc.a
-
-$(SOBJ): $(SSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(SSRC)
-
+ rm -f *.o
diff --git a/libc/syscall/Makefile b/libc/syscall/Makefile
index b487655..fd1b187 100644
--- a/libc/syscall/Makefile
+++ b/libc/syscall/Makefile
@@ -2,67 +2,63 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
LSRC=syslibc.c
-LOBJ=time.o abort.o wait.o waitpid.o killpg.o setpgrp.o sleep.o \
+LOBJ=time.o abort.o wait.o waitpid.o wait3.o killpg.o setpgrp.o sleep.o \
usleep.o
-LSRC3=syslib3.c
-LOBJ3=__cstart3.o
-
LSRC0=syslib0.c
LOBJ0=__cstartup.o lseek.o getpid.o getppid.o getuid.o geteuid.o getgid.o \
getegid.o dup2.o dup.o getpgrp.o times.o
ESRC=exec.c
-E2OBJ=execl.o execv.o execle.o execlp.o execvp.o
-EOBJ=execve.o $(E2OBJ)
+EOBJ=execve.o execl.o execv.o execle.o execlp.o execvp.o
DSRC=dirent.c
DOBJ=opendir.o closedir.o readdir.o
ifeq ($(LIB_CPU)-$(LIB_OS),i86-ELKS)
-SYSCALLS=sh mksyscall
OBJ=$(LOBJ0) $(LOBJ) $(DOBJ) $(EOBJ) signal.o setjmp.o
-DEP=mksyscall syscall.dat
-endif
-
-ifeq ($(LIB_CPU)-$(LIB_OS),i386-ELKS)
-SYSCALLS=sh mksys386
-OBJ=setjmp.o $(LOBJ3) $(LOBJ) $(E2OBJ) $(DOBJ)
-DEP=mksys386 sys386.dat
+SYSCALLS=call_i86
endif
ifeq ($(SYSCALLS),)
-SYSCALLS=true
OBJ=setjmp.o
-DEP=
endif
-all: $(DEP) $(OBJ)
- $(SYSCALLS)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-libc.a: $(DEP) $(OBJ)
- $(SYSCALLS) libc.a
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+all: $(SYSCALLS) $(LIBC)
+ @:
-clean:
- rm -f *.o libc.a syscall.c syscall.mak call_tab.v defn_tab.v
+call_i86: syscall.mak
+ $(MAKE) -f syscall.mak LIBC="$(LIBC)" CFLAGS="$(CFLAGS)"
+
+syscall.mak: mksyscall syscall.dat
+ sh mksyscall
-$(LOBJ): $(LSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(LSRC)
+$(LIBC): $(LIBC)($(OBJ))
-$(DOBJ): $(DSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(DSRC)
+$(LIBC)($(LOBJ)): $(LSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(EOBJ): $(ESRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(ESRC)
+$(LIBC)($(DOBJ)): $(DSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(LOBJ0): $(LSRC0)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(LSRC0)
+$(LIBC)($(EOBJ)): $(ESRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
-$(LOBJ3): $(LSRC3)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(LSRC3)
+$(LIBC)($(LOBJ0)): $(LSRC0)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+
+clean:
+ rm -f *.o libc.a
+ rm -f syscall.c syscall.mak
+ rm -f call_tab.v defn_tab.v
diff --git a/libc/syscall/TODO b/libc/syscall/TODO
index 90085d9..b178a96 100644
--- a/libc/syscall/TODO
+++ b/libc/syscall/TODO
@@ -1,5 +1,3 @@
-It appears that a 386 version of the syscall libs is also wanted ...
-
SYSV IPC, there's and __ipc syscall and the hardware can manage messages and
semaphores.
diff --git a/libc/syscall/getinfo.c b/libc/syscall/getinfo.c
deleted file mode 100644
index a5ab89a..0000000
--- a/libc/syscall/getinfo.c
+++ /dev/null
@@ -1,32 +0,0 @@
-
-#define PERM_GETINFO 0x100
-#define PERM_GETGROUP 0x200
-
-struct {
- int pid;
- int ppid;
- int uid;
- int gid;
- int euid;
- int egid;
-}
- __info_safe;
-
-getgroups(count, locn)
-int count;
-void * locn;
-{
- if( count < 0 ) {errno = EINVAL; return -1; }
- return __permissions(PERM_GETGROUP, count, locn);
-}
-
-getpid()
-{
- __permissions(PERM_GETINFO, 6, &__info_safe);
- return __info_safe.pid;
-}
-
-getppid()
-{
- return __permissions(PERM_GETITEM(1) /*, 0, 0 */);
-}
diff --git a/libc/syscall/mksyscall b/libc/syscall/mksyscall
index 1e98836..2005029 100644
--- a/libc/syscall/mksyscall
+++ b/libc/syscall/mksyscall
@@ -277,24 +277,13 @@ END{
cat >> syscall.mak <<\!
-TOP=..
-include $(TOP)/Make.defs
+all: $(LIBC)($(OBJ))
+ @:
-all: $(OBJ)
-
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
-
-$(OBJ): syscall.dat mksyscall
- $(CC) $(CFLAGS) -c -DL_$* -o $@ syscall.c
+$(LIBC)($(OBJ)): syscall.dat
+ $(CC) $(CFLAGS) -DL_$* syscall.c -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
!
-rv=$?
-if [ "$rv" != 0 ]
-then exit $rv
-fi
-
-export MAKELEVEL
-MAKELEVEL=0
-exec make -f syscall.mak $1
+exit $?
diff --git a/libc/syscall/setjmp.c b/libc/syscall/setjmp.c
index 52c3ff1..58b57ad 100644
--- a/libc/syscall/setjmp.c
+++ b/libc/syscall/setjmp.c
@@ -8,6 +8,9 @@ setjmp(env)
jmp_buf env;
{
#asm
+export __setjmp
+__setjmp:
+
pop cx ! PC
#if __FIRST_ARG_IN_AX__
mov bx,ax
@@ -31,6 +34,9 @@ jmp_buf env;
int rv;
{
#asm
+export __longjmp
+__longjmp:
+
pop cx ! pc
#if __FIRST_ARG_IN_AX__
mov bx,ax ! env->
diff --git a/libc/syscall/syscall.dat.chad b/libc/syscall/syscall.dat.chad
new file mode 100644
index 0000000..a6e8b06
--- /dev/null
+++ b/libc/syscall/syscall.dat.chad
@@ -0,0 +1,55 @@
+exit 1 1 * c exit does stdio, _exit in crt0
+fork 2 0
+read 3 3
+write 4 3
+open 5 3
+close 6 1
+wait 7 0 . THIS one is different
+creat 8 0 . THIS one is different
+link 9 2
+unlink 10 1
+exec 11 3 * minix style exec
+chdir 12 1
+time 13 0 . THIS one is different
+mknod 14 3
+chmod 15 2
+chown 16 3
+brk 17 1 * This is only to tell the system
+stat 18 2
+lseek 19 3 * nb 2nd arg is an io ptr to long not a long.
+getpid 20 1 * this gets both pid & ppid
+mount 21 5
+umount 22 1
+setuid 23 1
+getuid 24 1 * this gets both uid and euid
+stime 25 2 - this must not exist - even as a libc.
+ptrace 26 4
+alarm 27 2
+fstat 28 2
+pause 29 0
+utime 30 2
+access 33 2
+nice 34 1 .
+sleep 35 0 . THIS one is different
+sync 36 0
+kill 37 2
+rename 38 2
+mkdir 39 2
+rmdir 40 1
+dup 41 1 - using nasty fcntl function
+pipe 42 1
+times 43 2 * 2nd arg is pointer for long ret val.
+profil 44 0
+setgid 46 1
+getgid 47 1 * this gets both gid and egid
+signal 48 2 * have put the despatch table in user space.
+getinfo 49 1 - possible? gets pid,ppid,uid,euid etc
+fcntl 50 3
+acct 51 1 -
+phys 52 0 . THIS one is different
+lock 53 0 . THIS one is different
+ioctl 54 3 . make this and fcntl the same ?
+reboot 55 3 . the magic number is 0xfee1,0xdead,...
+mpx 56 0 . THIS one is different
+dup2 57 0 . THIS one is different
+umask 60 1
diff --git a/libc/syscall/syscall.dat.code b/libc/syscall/syscall.dat.code
new file mode 100644
index 0000000..a91ca86
--- /dev/null
+++ b/libc/syscall/syscall.dat.code
@@ -0,0 +1,70 @@
+(
+tr '[A-Z]' '[a-z]' < syscall.dat.rdb
+echo %%%
+cat <<!
+exit 1 0
+fork 2 0
+read 3 0
+write 4 0
+open 5 0
+close 6 0
+wait 7 0
+creat 8 0
+link 9 0
+unlink 10 0
+exec 11 0
+chdir 12 0
+time 13 0
+mknod 14 0
+chmod 15 0
+chown 16 0
+brk 17 0
+stat 18 0
+lseek 19 0
+getpid 20 0
+mount 21 0
+umount 22 0
+setuid 23 0
+getuid 24 0
+stime 25 0
+ptrace 26 0
+alarm 27 0
+fstat 28 0
+pause 29 0
+utime 30 0
+access 33 0
+nice 34 0
+sleep 35 0
+sync 36 0
+kill 37 0
+rename 38 0
+mkdir 39 0
+rmdir 40 0
+dup 41 0
+pipe 42 0
+times 43 0
+profil 44 0
+setgid 46 0
+getgid 47 0
+signal 48 0
+getinfo 49 0
+fcntl 50 0
+acct 51 0
+phys 52 0
+lock 53 0
+ioctl 54 0
+reboot 55 0
+mpx 56 0
+dup2 57 0
+umask 60 0
+!
+) | awk '/%%%/{ flg++; OFS="\t"; next;}
+flg==0 { save4[$1] = $4; save3[$1] = $3;
+ for(i=5; i<=NF; i++) saverest[$1] = saverest[$1] " " $i;
+}
+flg==1 {
+ if( $1 in save3 )
+ print $1, $2, save3[$1]+0, save4[$1] " " saverest[$1] ;
+ else
+ print $1, $2, "0", ". THIS one is different";
+ }'
diff --git a/libc/syscall/syscall.dat.rdb b/libc/syscall/syscall.dat.rdb
new file mode 100644
index 0000000..de5ed9b
--- /dev/null
+++ b/libc/syscall/syscall.dat.rdb
@@ -0,0 +1,142 @@
+#
+# Name No Args Flag, comment
+#
+# . = Ok, with comment
+# * = Needs libc code (Prefix __)
+# - = Obsolete/not required
+#
+# WARNING!
+# This file is used to generate includes for ELKSemu too.
+# This file is continually changing, when you upgrade you _MUST_ ensure
+# that ELKSemu is of a matching build!
+#
+# Calls that use one fd
+READ 3 3
+WRITE 4 3
+CLOSE 6 1
+LSEEK 19 3 * NB 2nd arg is an IO ptr to long not a long.
+FSTAT 28 2
+IOCTL 54 3 . Make this and fcntl the same ?
+FCNTL 55 3
+FTRUNCATE 93 3
+FCHMOD 94 2
+FCHOWN 95 3
+FSYNC 118 1
+FCHDIR 133 1
+LLSEEK 140 3 * 2nd arg is ptr to two longs
+READV 145 3
+WRITEV 146 3
+FLOCK 143 2 - Use fcntl
+DUP 41 1 - Using nasty fcntl function
+
+#
+SETUP 0 X
+EXIT 1 1 * C exit does stdio, _exit in crt0
+FORK 2 0
+OPEN 5 3
+WAIT4 7 4
+VFORK 8 0 . Needed for 8086
+GETINFO 49 1 - Possible? Gets pid,ppid,uid,euid etc
+LINK 9 2
+UNLINK 10 1
+EXEC 11 3 * Minix style exec
+CHDIR 12 1
+GETTIMEOFDAY 13 2 . time() exists only in libc
+MKNOD 14 3
+CHMOD 15 2
+CHOWN 16 3
+BRK 17 1 * This is only to tell the system
+STAT 18 2
+GETPID 20 1 * This gets both pid & ppid
+MOUNT 21 5
+UMOUNT 22 1
+SETUID 23 1
+GETUID 24 1 * This gets both uid and euid
+SETTIMEOFDAY 25 2 . STIME should _NOT_ exist even as a libc.
+STIME 25 2 - This must NOT exist - even as a libc.
+PTRACE 26 4
+ALARM 27 2
+PAUSE 29 0
+UTIME 30 2
+ACCESS 33 2
+NICE 34 1 .
+FTIME 35 1 - Use gettimeofday
+SYNC 36 0
+KILL 37 2
+RENAME 38 2
+MKDIR 39 2
+RMDIR 40 1
+PIPE 42 1
+TIMES 43 2 * 2nd arg is pointer for long ret val.
+SETGID 46 1
+GETGID 47 1 * This gets both gid and egid
+SIGNAL 48 2 * Have put the despatch table in user space.
+ACCT 51 1 -
+SETPGID 57 2
+ULIMIT 58 2
+UMASK 60 1
+CHROOT 61 1
+USTAT 62 2
+GETPGRP 65 0 - use getpgid(0)
+SETSID 66 0
+SIGACTION 67 X
+SGETMASK 68 X
+SSETMASK 69 X
+SETREUID 70 2
+SETREGID 71 2
+SIGSUSPEND 72 X
+SIGPENDING 73 X
+SETHOSTNAME 74 2
+SETRLIMIT 75 2
+GETRLIMIT 76 2
+GETRUSAGE 77 2
+GETGROUPS 80 2
+SETGROUPS 81 2
+SYMLINK 83 2
+LSTAT 84 2
+READLINK 85 3
+SWAPON 87 X
+REBOOT 88 3 . The magic number is 0xfee1,0xdead,...
+MUNMAP 91 X
+TRUNCATE 92 3
+GETPRIORITY 96 2
+SETPRIORITY 97 3
+PROFIL 98 X
+STATFS 99 2
+FSTATFS 100 2
+SOCKETCALL 102 X
+SYSLOG 103 X
+SETITIMER 104 3
+GETITIMER 105 2
+UNAME 109 1
+VHANGUP 111 0
+SWAPOFF 115 X
+SYSINFO 116 X - Use /proc
+IPC 117 5 * This is for all SYSV IPC
+SIGRETURN 119 X
+SETDOMAINNAME 121 X
+ADJTIMEX 124 X
+MPROTECT 125 X
+SIGPROCMASK 126 X
+QUOTACTL 131 X
+GETPGID 132 1
+SYSFS 135 X
+PERSONALITY 136 X
+SETFSUID 138 1
+SETFSGID 139 1
+GETDENTS 141 X
+SELECT 142 5 *
+MSYNC 144 X
+GETSID 147 X
+FDATASYNC 148 X
+SYSCTL 149 X
+MUNLOCK 151 X
+MUNLOCKALL 153 X
+SCHED_SETPARAM 154 X
+SCHED_GETPARAM 155 X
+SCHED_SETSCHEDULER 156 X
+SCHED_GETSCHEDULER 157 X
+SCHED_YIELD 158 X
+SCHED_GET_PRIORITY_MAX 159 X
+SCHED_GET_PRIORITY_MIN 160 X
+SCHED_RR_GET_INTERVAL 161 X
diff --git a/libc/syscall/syslib0.c b/libc/syscall/syslib0.c
index 98f59e6..1a92179 100644
--- a/libc/syscall/syslib0.c
+++ b/libc/syscall/syslib0.c
@@ -29,11 +29,9 @@ call_main:
saved_arg1:
.word 0
#endif
-#if __CALLER_SAVES__
.data
-loopy_safe:
+loop_safe:
.word 0
-#endif
.text
export ___cstartup
@@ -57,24 +55,20 @@ ___mkargv: ! BCC tells the linker to init argc,argv with this.
push cx ! Push argc
#endif
- mov si,#auto_start ! Pointer to first autostart function
+ mov bx,#auto_start ! Pointer to first autostart function
auto_run:
#if __FIRST_ARG_IN_AX__
mov ax,[saved_arg1]
#endif
-#if __CALLER_SAVES__
- mov [loopy_safe],si
-#endif
- mov bx,[si]
+ mov [loop_safe],bx
+ mov bx,[bx]
test bx,bx
jz no_entry
call bx ! Call the function
no_entry:
-#if __CALLER_SAVES__
- mov si,[loopy_safe]
-#endif
- inc si ! SI at next
- inc si
+ mov bx,[loop_safe]
+ inc bx ! next
+ inc bx
jmp auto_run ! And round for the next.
call_exit: ! Last item called by above.
diff --git a/libc/syscall/syslib3.c b/libc/syscall/syslib3.c
deleted file mode 100644
index c4df1fc..0000000
--- a/libc/syscall/syslib3.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/* Copyright (C) 1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This file is part of the Linux-8086 C library and is distributed
- * under the GNU Library General Public License.
- */
-
-#include <sys/types.h>
-#include <errno.h>
-#include <time.h>
-#include <sys/times.h>
-
-/* MSDOS has it's own versions */
-#ifndef __MSDOS__
-#ifdef __AS386_32__
-
-/********************** Function __cstartup *******************************/
-
-#ifdef L___cstart3
-
-void (*__cleanup)() = 0;
-char ** environ;
-
-#asm
- loc 2
-call_main:
- .long _main ! Segment 2 is the trailing pointers, main and the
- .long call_exit ! routine to call exit.
-#if __FIRST_ARG_IN_AX__
- .data
-saved_arg1:
- .long 0
-#endif
-#if __CALLER_SAVES__
- .data
-loopy_safe:
- .long 0
-#endif
- .text
-
-export ___mkargv
-___mkargv: ! BCC Tells linker to init argv ... none needed.
-
-export ___cstartup
-___cstartup: ! Crt0 startup (Linux style)
- mov eax,[esp]
- test eax,eax
- jz call_exit ! If argc == 0 this is being called by ldd, exit.
- mov eax,[esp+8]
- mov [_environ],eax
-#if __FIRST_ARG_IN_AX__
- pop [saved_arg1] ! Argc will go into eax
-#endif
-
- mov esi,#auto_start ! Pointer to first autostart function
-auto_run:
-#if __FIRST_ARG_IN_AX__
- mov eax,[saved_arg1]
-#endif
-#if __CALLER_SAVES__
- mov [loopy_safe],esi
-#endif
- mov ebx,[esi]
- test ebx,ebx
- jz no_func
- call ebx ! Call the function
-no_func:
-#if __CALLER_SAVES__
- mov esi,[loopy_safe]
-#endif
- add esi,#4 ! SI at next
- jmp auto_run ! And round for the next.
-
-call_exit: ! Last item called by above.
- pop ebx ! Be tidy.
-#if !__FIRST_ARG_IN_AX__
- push eax ! At the end the last called was main() push it`s
-#endif
- call _exit ! return val and call exit();
-bad_exit:
- jmp bad_exit ! Exit returned !!
-
-export _exit
-export __exit
-_exit: ! exit(rv) function
-#if __FIRST_ARG_IN_AX__
- mov [saved_arg1],eax
-#else
- push [esp+4] ! Copy the `rv` for the exit fuctions.
-#endif
- mov ebx,[___cleanup] ! Call exit, normally this is `__do_exit`
- test ebx,ebx
- je no_clean ! But it`s default is null
- call ebx
-no_clean:
-#if __FIRST_ARG_IN_AX__
- mov eax,[saved_arg1]
-#else
- add esp,#4
-#endif
-__exit: ! _exit(rv)
- br ___exit ! This is just an alias for __exit();
-
-#endasm
-#endif
-
-/********************** Function ? ************************************/
-
-/*---*/
-#endif
-#endif
diff --git a/libc/syscall/syslibc.c b/libc/syscall/syslibc.c
index 68f5a0b..3486ef6 100644
--- a/libc/syscall/syslibc.c
+++ b/libc/syscall/syslibc.c
@@ -50,6 +50,19 @@ int * status;
}
#endif
+/********************** Function wait3 **************************************/
+
+#ifdef L_wait3
+int
+wait3(status, opts, usage)
+int * status;
+int opts;
+struct rusage * usage;
+{
+ return wait4(-1, status, opts, usage);
+}
+#endif
+
/********************** Function waitpid ************************************/
#ifdef L_waitpid
diff --git a/libc/termios/Makefile b/libc/termios/Makefile
index 7903bc2..cfc3baa 100644
--- a/libc/termios/Makefile
+++ b/libc/termios/Makefile
@@ -2,9 +2,6 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
TSRC=termios.c
TOBJ=tcsetattr.o tcgetattr.o tcdrain.o tcflow.o tcflush.o tcsendbreak.o \
tcsetpgrp.o tcgetpgrp.o isatty.o \
@@ -12,19 +9,22 @@ TOBJ=tcsetattr.o tcgetattr.o tcdrain.o tcflow.o tcflush.o tcsendbreak.o \
ifeq ($(LIB_OS),ELKS)
OBJ=$(TOBJ) ttyname.o
-else
-OBJ=
-endif
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+all: $(LIBC)
+ @:
-clean:
- rm -f *.o libc.a
+$(LIBC): $(LIBC)($(OBJ))
-$(TOBJ): $(TSRC)
- $(CC) $(CFLAGS) -c -DL_$* -o $@ $(TSRC)
+$(LIBC)($(TOBJ)): $(TSRC)
+ $(CC) $(CFLAGS) -DL_$* $< -c -o $*.o
+ $(AR) $(ARFLAGS) $@ $*.o
+ $(RM) $*.o
+else
+all:
+ @:
+endif
+clean:
+ rm -f *.o libc.a
diff --git a/libc/tests/Config b/libc/tests/Config
deleted file mode 100644
index 4bdf884..0000000
--- a/libc/tests/Config
+++ /dev/null
@@ -1,2 +0,0 @@
-
-tools: These are tools to test libc - make directly
diff --git a/libc/tests/Makefile b/libc/tests/Makefile
deleted file mode 100644
index 37e57b8..0000000
--- a/libc/tests/Makefile
+++ /dev/null
@@ -1,20 +0,0 @@
-# Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
-# This file is part of the Linux-8086 C library and is distributed
-# under the GNU Library General Public License.
-
-TOP=..
-include $(TOP)/Make.defs
-CFLAGS=$(CCFLAGS) -ansi
-
-default: all
-
-libc.a:
- @echo -n
-
-include Real_make
-
-fetch_them:
- cp -p $(SRC) Real_make $(TOPDIR)/tests/.
-
-clean:
- rm -f $(OBJ) $(EXE) $(LINK_FILES)
diff --git a/libc/tests/README b/libc/tests/README
deleted file mode 100644
index 4d308c7..0000000
--- a/libc/tests/README
+++ /dev/null
@@ -1,22 +0,0 @@
-Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
-This file is part of the Linux-8086 C library and is distributed
-under the GNU Library General Public License.
-
-These are user level tools, they're being used to test libc routines.
-
-env.c Prints the environment and arguments (Plus some junk)
-compr.c Mini compression program (rather slow at times)
-ucomp.c Mini uncompression program (Very fast)
-ft.c Multiple simple file tools.
-hd.c Hex dump.
-line2.c Print lines from /etc/passwd (stdio)
-lines.c Print lines from /etc/passwd
-ouch.c Signal test
-size.c Size of executables and object files.
-sync.c :-)
-wc.c Word count.
-
-BTW: i386 OMAGIC files can be converted to deformed ELFs with this:
- $ ld -N -Ttext 0 --defsym _start=0 sync -o sync1 -s
-
--Robert
diff --git a/libc/tests/Real_make b/libc/tests/Real_make
deleted file mode 100644
index 38c4232..0000000
--- a/libc/tests/Real_make
+++ /dev/null
@@ -1,19 +0,0 @@
-# Copyright (C) 1996 Robert de Bath <robert@mayday.compulink.co.uk>
-# This file is part of the Linux-8086 C library and is distributed
-# under the GNU Library General Public License.
-
-SRC=env.c ft.c hd.c size.c sync.c compr.c ucomp.c ouch.c lines.c \
- wc.c line2.c rand.c grab.c
-OBJ=
-EXE=env ft hd size sync compr ucomp ouch lines wc line2 rand grab
-
-LINK_FILES=cat chgrp chmod chown cp install ln mkdir mkfifo mknod mv rm
-
-all: $(EXE)
-
-links:
- for i in $(LINK_FILES) ; do ln -s ft $$i ; done
-
-no_links:
- rm -f $(LINK_FILES)
-
diff --git a/libc/tests/compr.c b/libc/tests/compr.c
deleted file mode 100644
index 8e53443..0000000
--- a/libc/tests/compr.c
+++ /dev/null
@@ -1,383 +0,0 @@
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <malloc.h>
-
-#define MAXNO 32767
-#define MAXLEN 127
-#define XXQSCAN /* Speed up scanning at the cost of not being optimal */
-
-unsigned char *fptr;
-unsigned short *vptr;
-FILE * fd;
-
-#define ITBSIZE 4096
-#define itbfunc() (ptr[mainscan]^(ptr[mainscan+1]<<4)^(ptr[mainscan+2]<<2))
-/*
-#define ITBSIZE 4001
-#define itbfunc() ((ptr[mainscan]+ptr[mainscan+1]*79+ptr[mainscan+2]*307)%4001)
-*/
-int * itb;
-
-int size;
-int maxno= 8000;
-long cnt=0;
-
-long icount = 0;
-long ocount = 0;
-
-unsigned char key;
-
-int fl;
-
-main(argc, argv)
-int argc;
-char ** argv;
-{
- if( argc < 2 ) { fprintf(stderr, "Usage; ... \n"); exit(1); }
-
- if( argc == 3 )
- {
- maxno = atoi(argv[2]);
- if( maxno < 256 ) maxno = 256;
- if( maxno > MAXNO) maxno = MAXNO;
- }
-
- if( strcmp(argv[1], "-") == 0 )
- fd = stdin;
- else
- fd = fopen(argv[1], "r" );
- if( fd == 0 ) { perror("Open failed\n"); exit(1); }
-
- fptr = (unsigned char * ) malloc((unsigned)maxno*2);
- itb = (int * ) malloc(ITBSIZE*sizeof(int));
- if( itb )
- vptr = (unsigned short * ) malloc((unsigned)maxno * sizeof(short)*2 );
- else
- vptr = 0;
-
- if( fptr == 0 )
- {
- perror("Cannot allocate RAM");
- exit(1);
- }
- if( vptr == 0 && itb ) free(itb);
-
- fl = 0;
- {
- if( (size = fread(fptr, 1, (int)maxno, fd )) < 0 ) { fprintf(stderr, "\nRead failed\n"); exit(1); }
-
- if( size )
- {
- icount += size;
- if( fl == 0 )
- {
- key = scan_min();
- putchar(key); ocount++;
- fl = 1;
- }
- else
- fprintf(stderr, "\rBlock %d \r", fl++ );
- if( vptr) compress();
- else slo_compress();
- }
- }
-
- fprintf(stderr, "\n");
- exit(0);
-}
-
-scan_min()
-{
- long count[256];
- long i;
- int j, n;
-
- for( j=0; j<256; j++ ) count[j] = 0;
-
- for( i=0; i<size; i++) count[ fptr[i] & 0xFF ]++;
-
- for( i= (((unsigned long) -1) >> 1), j=0; j<256; j++ )
- if( count[j] < i )
- {
- i = count[j] ;
- n = j;
- }
-
- fprintf(stderr, "Most unused in 0x%lx to 0x%lx is 0x%02x at %ld\n", cnt, cnt+size, n, i );
- cnt+= size;
-
- return n;
-}
-
-compress()
-{
- register long mainscan;
- register long secondscan;
- register unsigned char * ptr = (unsigned char * ) fptr;
- register int len;
- register int matchlen;
- long notepos;
- long emark;
-#ifdef QSCAN
- int count;
-#endif
-
- for( mainscan=0; mainscan <ITBSIZE; itb[mainscan++] = -1 );
-
- mainscan=0;
- emark = size - 130 ;
-loopback:
-
- for( ; mainscan < emark; )
- {
- matchlen = 3;
- notepos = -1;
-#ifdef QSCAN
- count = 0;
-#endif
- for( secondscan=itb[itbfunc()];
- secondscan >= 0 && mainscan - secondscan < maxno;
- secondscan -= vptr[secondscan] )
- {
-#ifdef DEBUG
-if( vptr[secondscan] == 0 )
-{
- fprintf(stderr, "\nOh !!!!! mainsc %ld, sec-scan %ld\n", mainscan, secondscan);
- vptr[secondscan] = secondscan+1;
-}
-#endif
-
- for( len = 0; len < MAXLEN ; len++ )
- if( mainscan+len >= size || ptr[mainscan+len] != ptr[secondscan+len] ) break;
- if( len > matchlen && (len != 4 || mainscan - secondscan < 256 ) )
- {
- notepos = secondscan;
- matchlen = len;
- if( len == MAXLEN ) break;
- }
-#ifdef QSCAN
- if( matchlen > 20 && len > 3 && ++count > 5 )
- break;
-#endif
- }
-
- if( notepos == -1 )
- {
- if( ptr[mainscan] == key )
- {
- ocount+=2;
- putchar(key);
- putchar(0);
- }
- else
- {
- ocount++;
- putchar(ptr[mainscan]);
- }
- matchlen = 1;
- }
- else
- {
- long x = mainscan - notepos;
- ocount+=3;
- putchar(key);
- if( x > 255 ) putchar(matchlen | 0x80);
- else putchar(matchlen);
- putchar((int)x);
- if( x > 255 ) { putchar((int)x>>8); ocount++; }
- }
-
- while( matchlen-- )
- {
- len = itbfunc();
- vptr[mainscan] = mainscan - itb[len];
-#if 1
- if( vptr[mainscan] == 0 )
- {
- fprintf(stderr, "\nHumm.. ms=%ld, hash=%d, itb[hash]=%ld\n", mainscan, len, itb[len]);
- vptr[mainscan] = mainscan+1;
- }
-#endif
- itb[len] = mainscan;
- mainscan++;
- }
- }
-
- fprintf(stderr, "\rBlock %d ..In:%ld Out:%ld \r", fl-1, icount, ocount );
-
- if( emark < size-4 )
- {
- int cnt;
- long l ;
- if(mainscan > maxno )
- {
- for(cnt=0; cnt<ITBSIZE; cnt++)
- {
- if( itb[cnt] < maxno) itb[cnt] = -1;
- else itb[cnt] -= maxno;
- }
- for(l=0; l<maxno; l++)
- {
- ptr[l] = ptr[l+maxno];
- vptr[l] = vptr[l+maxno];
- }
- mainscan -= maxno;
- size -= maxno;
- }
- if( size <= maxno )
- {
- if(( cnt = fread(ptr+size, 1, (int)maxno, fd)) < 0 )
- { fprintf(stderr, "\nRead failed\n"); exit(1); }
- size += cnt;
- icount += cnt;
- fprintf(stderr, "\rBlock %d \r", fl++ );
- }
- emark = size - 130;
- if( mainscan >= emark )
- emark = size -4;
-
- goto loopback;
- }
-
- for( ; mainscan < size; )
- {
- if( ptr[mainscan] == key )
- {
- ocount+=2;
- putchar(key);
- putchar(0);
- }
- else
- {
- ocount++;
- putchar(fptr[mainscan]);
- }
- mainscan++;
- }
- fprintf(stderr, "\rBlock %d ..In:%ld Out:%ld \r", fl-1, icount, ocount );
- /* end */
-}
-
-slo_compress()
-{
- register long mainscan;
- register long secondscan;
- register unsigned char * ptr = (unsigned char * ) fptr;
- register int len;
- register int matchlen;
- long notepos;
- long emark;
-#ifdef QSCAN
- int count;
-#endif
-
- mainscan=0;
- emark = size - 130 ;
-loopback:
-
- for( ; mainscan < emark; )
- {
- matchlen = 3;
- notepos = -1;
-#ifdef QSCAN
- count = 0;
-#endif
- for( secondscan=mainscan-1;
- secondscan >= 0 && mainscan - secondscan < maxno;
- secondscan-- )
- {
- for( len = 0; len < MAXLEN ; len++ )
- if( mainscan+len >= size || ptr[mainscan+len] != ptr[secondscan+len] ) break;
- if( len > matchlen && (len != 4 || mainscan - secondscan < 256 ) )
- {
- notepos = secondscan;
- matchlen = len;
- if( len == MAXLEN ) break;
- }
-#ifdef QSCAN
- if( matchlen > 20 && len > 3 && ++count > 5 )
- break;
-#endif
- }
-
- if( notepos == -1 )
- {
- if( ptr[mainscan] == key )
- {
- ocount+=2;
- putchar(key);
- putchar(0);
- }
- else
- {
- ocount++;
- putchar(ptr[mainscan]);
- }
- matchlen = 1;
- }
- else
- {
- long x = mainscan - notepos;
- ocount+=3;
- putchar(key);
- if( x > 255 ) putchar(matchlen | 0x80);
- else putchar(matchlen);
- putchar((int)x);
- if( x > 255 ) { putchar((int)x>>8); ocount++; }
- }
-
- mainscan += matchlen;
- }
-
- fprintf(stderr, "\rBlock %d ..In:%ld Out:%ld \r", fl-1, icount, ocount );
-
- if( emark < size-4 )
- {
- int cnt;
- long l ;
- if(mainscan > maxno )
- {
- for(l=0; l<maxno; l++)
- {
- ptr[l] = ptr[l+maxno];
- }
- mainscan -= maxno;
- size -= maxno;
- }
- if( size <= maxno )
- {
- if(( cnt = fread(ptr+size, 1, (int)maxno, fd)) < 0 )
- { fprintf(stderr, "\nRead failed\n"); exit(1); }
- size += cnt;
- icount += cnt;
- fprintf(stderr, "\rBlock %d \r", fl++ );
- }
- emark = size - 130;
- if( mainscan >= emark )
- emark = size -4;
-
- goto loopback;
- }
-
- for( ; mainscan < size; )
- {
- if( ptr[mainscan] == key )
- {
- ocount+=2;
- putchar(key);
- putchar(0);
- }
- else
- {
- ocount++;
- putchar(fptr[mainscan]);
- }
- mainscan++;
- }
- fprintf(stderr, "\rBlock %d ..In:%ld Out:%ld \r", fl-1, icount, ocount );
- /* end */
-}
-
diff --git a/libc/tests/env.c b/libc/tests/env.c
deleted file mode 100644
index c904969..0000000
--- a/libc/tests/env.c
+++ /dev/null
@@ -1,81 +0,0 @@
-
-char hex[] = "0123456789ABCDEF";
-
-char buf[20];
-main(argc, argv, envp)
-int argc;
-char ** argv;
-char ** envp;
-{
- int i,j; char *p; char * str;
- int * arg = &argc;
-
- for(j=0; j<8; j++)
- {
- phex(arg);
- putstr(":");
- for(i=0; i<8; i++)
- {
- putstr(" ");
- phex(*arg++);
- }
- putstr("\n");
- }
-
-#if 0
- str = alloca(sizeof(hex)+2);
- putstr("Alloca = ");
- phex(&str);
- putstr(",");
- phex(str);
- putstr("\n");
-#endif
-
- p = (char*) &argc;
-
- putstr("ARGC="); phex(argc); putstr("\n");
- for(i=0; i<argc; i++)
- {
- phex(argv[i]);
- putstr(":");
- putstr(argv[i]);
- putstr("\n");
- }
- putstr("ENV=>\n");
- for(; *envp; envp++)
- {
- phex(envp);
- putstr(":");
- phex(*envp);
- putstr(":");
- putstr(*envp);
- putstr("\n");
- }
-}
-
-phex(val)
-{
- int i;
- printf("%04x", val);
-}
-
-putstr(str)
-{
- printf("%s", str);
-}
-
-#if 0
-int global_var_that_needs_init = 0x201;
-
-#asm
- loc 1 ! Make sure the pointer is in the correct segment
-auto_func: ! Label for bcc -M to work.
- .word _init_vars ! Pointer to the autorun function
- .text ! So the function after is also in the correct seg.
-#endasm
-
-static void init_vars()
-{
- global_var_that_needs_init = getuid();
-}
-#endif
diff --git a/libc/tests/ft.c b/libc/tests/ft.c
deleted file mode 100644
index 1bdc737..0000000
--- a/libc/tests/ft.c
+++ /dev/null
@@ -1,1209 +0,0 @@
-/* Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
- * This program is distributed under the GNU General Public License.
- */
-
-/*
- * File Tool, This program is a collection of basic file tools
- * it includes cat, cp, ln, mkdir, mknod, chmod, chown, mv, rm
- *
- * Links may be used to call it under any of these names.
- */
-#include <stdio.h>
-#ifdef __STDC__
-#include <unistd.h>
-#include <stdlib.h>
-#endif
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <errno.h>
-#include <string.h>
-#include <dirent.h>
-#include <sys/param.h>
-#include <utime.h>
-#include <pwd.h>
-#include <grp.h>
-
-#ifdef S_IFSOCK
-#include <sys/socket.h>
-#endif
-#ifndef S_IFLNK
-#define lstat stat
-#endif
-
-/* Ansi prototypes */
-#ifdef __STTDC__
-#define PR(x) x
-#else
-#define PR(x) ()
-#endif
-
-void main PR((int argc, char ** argv));
-int select_command PR((char * argv));
-void do_prep PR((void));
-void do_post PR((void));
-void execute PR((char * dname, char * fname));
-int exec_for_subdir PR((char * dname));
-void exec_for_item PR((int when, char * fname));
-void parse_perms PR((char * prefix, char * ustring));
-int edit_mode PR((int mode, char * mode_str));
-int cmd_ft PR((char * fname));
-int cmd_mkfifo PR((char * fname));
-int cmd_mksock PR((char * fname));
-int cmd_rm PR((char * fname));
-void build_dest PR((char * dest, char * name, char * newpath));
-int strisdigit PR((char * str));
-int cmd_mv PR((char * fname));
-int cmd_ln PR((char * fname));
-int cmd_cp PR((char * fname));
-int copy_modes PR((char * file));
-int copy_file PR((char * source, char * dest));
-void Usage PR((void));
-int cmd_mkdir PR((char * dirname));
-int cmd_mknod PR((void));
-int warning PR((int enumber, char * estr, char * eobj));
-int error PR((int enumber, char * estr, char * eobj));
-
-#define DO_BDIR 0x0010 /* Do Dir before contents */
-#define DO_ADIR 0x0020 /* Do Dir after contents */
-#define DO_MCOPY 0x0040 /* Preserve modes flag forced */
-#define OK_DIR 0x0080 /* Directorys OK even if no flg_recurse */
-#define IGN_LNK 0x0100 /* Not interested in symlinks */
-#define NO_SOURCE 0x0200 /* Named files created */
-#define OK_NO_SOURCE 0x0400 /* Don't need the source */
-
-#define CMD_FT (0+OK_DIR+DO_BDIR)
-#define CMD_CAT (1+IGN_LNK)
-#define CMD_CHGRP (2+OK_DIR+IGN_LNK+DO_ADIR)
-#define CMD_CHMOD (3+OK_DIR+IGN_LNK+DO_ADIR)
-#define CMD_CHOWN (4+OK_DIR+IGN_LNK+DO_ADIR)
-#define CMD_CP (5+IGN_LNK)
-#define CMD_EXTAR (6+DO_MCOPY+DO_BDIR)
-#define CMD_INSTALL (7+DO_MCOPY)
-#define CMD_LN (8+IGN_LNK+DO_BDIR)
-#define CMD_MKDIR (9+NO_SOURCE)
-#define CMD_MKFIFO (10+NO_SOURCE)
-#define CMD_MKSOCK (11+NO_SOURCE)
-#define CMD_MKNOD (12+NO_SOURCE)
-#define CMD_MV (13+DO_MCOPY+OK_DIR+DO_BDIR)
-#define CMD_RM (14+DO_ADIR)
-
-struct {
- char * name;
- int cmd;
- int argpat;
- char * opts;
-} command_list[] =
-{
- { "ft", CMD_FT, 0, "-Rv" },
- { "cat", CMD_CAT, 0, "uR" },
- { "chgrp", CMD_CHGRP, 1, "vfR" },
- { "chmod", CMD_CHMOD, 1, "vfR" },
- { "chown", CMD_CHOWN, 1, "vfR" },
- { "cp", CMD_CP, -1, "vifRrpsda" },
- { "extar", CMD_EXTAR, 1, "" },
- { "install", CMD_INSTALL, -1, "cdso:g:m:" },
- { "ln", CMD_LN, -1, "vifs" },
- { "mkdir", CMD_MKDIR, 0, "m:" },
- { "mkfifo", CMD_MKFIFO, 0, "m:" },
-#ifdef S_IFSOCK
- { "mksock", CMD_MKSOCK, 0, "m:" },
-#endif
- { "mknod", CMD_MKNOD, 4, "m:" },
- { "mv", CMD_MV, -1, "vif" },
- { "rm", CMD_RM, 0, "vifr" },
- { 0 }
-};
-
-int cmd_arg = 0;
-int cmd_tok = CMD_FT;
-char * cmd_opt = "-";
-char * cmd_string = 0; /* the first (or last) arg where special */
-char * prog_name = "";
-
-char ** flist = 0;
-int fcount = 0;
-int add_base=0;
-char * or_name = 0;
-int or_offset = 0;
-
-int flg_recurse = 0;
-int flg_verbose = 1;
-int flg_preserve= 0;
-int flg_mkpdir = 0;
-int flg_noderef = 0;
-int flg_symlink = 0;
-int flg_exestrip= 0;
-
-int flg_r, flg_force;
-char *str_o, *str_g, *str_m;
-
-/* Things to set on the new file */
-int set_user = -1;
-int set_group = -1;
-int set_mode = -1;
-time_t set_time = -1;
-char mode_str[32] = "";
-int u_mask = 0; /* 07777 altered by umask() */
-
-struct stat cur_file_stat;
-struct stat dest_item;
-struct stat access_stat;
-
-int done_something = 0;
-
-void
-main(argc, argv)
-int argc; char ** argv;
-{
- int ar;
- (void) select_command(argv[0]);
-
- for(ar=1;
- argv[ar] && argv[ar][0] == '-' && argv[ar][1];
- ar++)
- {
- char * p = argv[ar]+1;
- /* For symbolic changes of the form -rwx */
- if( cmd_tok == CMD_CHMOD && strchr("rwx", *p) != 0 ) break;
- while(*p)
- {
- char * ap=0, *av=0;
- char ch;
- /* Is it a valid opt for this cmd */
- if(*p == ':' || (ap=strchr(cmd_opt, *p)) == 0) Usage();
-
- /* Got an argument ? */
- if(ap[1] == ':')
- {
- if(!argv[ar+1]) Usage();
- av = argv[++ar];
- }
-
- if( (ch = *p) == '-' )
- {
- if( (ch=select_command(p)) < 0 ) Usage();
- }
- switch(ch)
- {
- case '\0': break;
- case 'r':
- case 'R': flg_recurse++; break;
- case 'v': flg_verbose++; break;
- case 'p': if(cmd_tok == CMD_MKDIR) flg_mkpdir++;
- else flg_preserve++;
- break;
- case 'd': if(cmd_tok == CMD_INSTALL)
- { flg_mkpdir++; cmd_arg=0; } /* Special mkdir */
- else flg_noderef++; /* cmd_copy */
- break;
-
- case 'f': flg_force++; flg_verbose=0; break;
- case 'o': str_o = av; break;
- case 'g': str_g = av; break;
- case 'm': str_m = av; break;
-
- case 's': flg_symlink++;
- if( cmd_tok == CMD_LN) cmd_tok |= OK_DIR+OK_NO_SOURCE;
- break;
- case 'a': flg_recurse++; flg_preserve++; flg_noderef++;
- break;
- }
- if(*p == '-') break;
- p++;
- }
- }
-
- switch(cmd_arg)
- {
- case 1:
- if( ar >= argc ) Usage();
- cmd_string = argv[ar++];
- fcount = argc-ar;
- flist = argv+ar;
- break;
- case 0:
- fcount = argc-ar;
- flist = argv+ar;
- break;
- case -1:
- if( ar >= argc ) Usage();
- cmd_string = argv[argc-1];
- fcount = argc-ar-1;
- flist = argv+ar;
- break;
- default:
- if( ar != argc-cmd_arg ) Usage();
- fcount = argc-ar;
- flist = argv+ar;
- break;
- }
-
- do_prep();
-
- for(ar=0; ar<fcount; ar++)
- {
- done_something=1;
- or_name = flist[ar]; or_offset = strlen(or_name)+1;
- execute(flist[ar], (char*)0);
- }
-
- do_post();
-
- if( !done_something )
- {
- if( cmd_tok == CMD_CAT )
- execute("-", (char*)0);
- else
- Usage();
- }
- exit(0);
-}
-
-int select_command(argv)
-char * argv;
-{
- int ar;
- char *p, *s;
- prog_name = argv;
- for(ar=0; command_list[ar].name; ar++)
- {
- p = strrchr(argv, '-'); if(p) p++; else p=argv;
- s = strrchr(p, '/'); if(s) s++; else s=p;
- if( strcmp(s, command_list[ar].name) == 0 )
- {
- cmd_arg = command_list[ar].argpat;
- cmd_tok = command_list[ar].cmd;
- cmd_opt = command_list[ar].opts;
- return 0;
- }
- }
- return -1;
-}
-
-void do_prep()
-{
- char * prefix = "::";
-
- u_mask = umask(077);
- umask(u_mask);
- u_mask = (07777&(~u_mask));
-
- if(cmd_tok&DO_MCOPY) flg_preserve++;
- if(str_m) parse_perms(prefix, str_m);
-
- switch(cmd_tok)
- {
- /* mknod is very different */
- case CMD_MKNOD: cmd_mknod(); exit(0); break;
-
- case CMD_CP:
- if(strcmp(cmd_string, "-") == 0)
- {
- cmd_tok = CMD_CAT;
- cmd_arg = 0;
- break;
- }
- if(flg_symlink)
- {
- cmd_tok = CMD_LN+OK_DIR+OK_NO_SOURCE;
- flg_preserve = 0;
- }
- break;
-
- case CMD_CHOWN: prefix++;
- case CMD_CHGRP: prefix++;
- case CMD_CHMOD:
- parse_perms(prefix, cmd_string);
- set_time = 0;
- break;
- case CMD_INSTALL:
- flg_exestrip = flg_symlink;
- flg_symlink = 0;
- if(str_o) parse_perms(prefix+2, str_o);
- if(str_g) parse_perms(prefix+1, str_g);
- if(flg_mkpdir) cmd_tok = CMD_MKDIR;
- else
- {
- cmd_tok = CMD_CP;
- flg_preserve = 1;
- }
- break;
- }
-
-#ifndef S_IFLNK
- if(flg_symlink)
- {
- error(0, "No support for symlinks available:", cmd_string);
- exit(1);
- }
-#endif
-
- /* Are we transfering many to one ? Then it must be a directory */
- if(cmd_arg == -1)
- {
- if( stat(cmd_string, &dest_item) == -1)
- {
- if( fcount > 1 )
- {
- if( cmd_mkdir(cmd_string) < 0 )
- exit(1);
- stat(cmd_string, &dest_item);
- add_base = 1;
- }
- }
- else
- {
- if( !S_ISDIR(dest_item.st_mode) )
- {
- if( fcount > 1 )
- {
- error(0, "Destination must be a directory:", cmd_string);
- exit(1);
- }
- }
- else add_base = 1;
- }
- }
-}
-
-void do_post()
-{
- /* Oh! It seems there's nothing to do, ah well. */
-}
-
-void execute(dname, fname)
-char * dname; char * fname;
-{
- char * buf;
- if( strcmp(dname, "-") == 0 )
- {
- exec_for_item(0, dname);
- return;
- }
- if( fname )
- {
- buf = alloca(strlen(dname) + strlen(fname) + 4);
- if( buf == 0 )
- {
- error(errno, "Can't allocate memory for path beyond ", dname);
- return ;
- }
- strcpy(buf, dname);
- if(strcmp(dname, "/")) strcat(buf, "/");
- strcat(buf, fname);
- }
- else buf = dname;
-
- if( lstat(buf, &cur_file_stat) == -1 )
- {
- if( cmd_tok&(NO_SOURCE|OK_NO_SOURCE) )
- exec_for_item(0, buf);
- else
- warning(errno, "", buf);
- return;
- }
- if( !flg_force && ( cmd_tok&NO_SOURCE ))
- {
- error(EEXIST, "", buf);
- return;
- }
-
- if( S_ISDIR(cur_file_stat.st_mode))
- {
- if( (cmd_tok&OK_DIR) || flg_recurse )
- (void) exec_for_subdir(buf);
- else
- error(EISDIR, "", buf);
- return;
- }
-
-#ifdef S_IFLNK
- if( S_ISLNK(cur_file_stat.st_mode))
- {
- /* Links are special */
- if( cmd_tok&IGN_LNK )
- {
- if( stat(buf, &cur_file_stat) == -1 )
- {
- warning(errno, "", buf);
- return;
- }
- }
- }
-#endif
- exec_for_item(0, buf);
-}
-
-int exec_for_subdir(dname)
-char * dname;
-{
- DIR * dfd;
- struct dirent * ent;
- int old_mode = -1;
-
- if( cmd_tok&DO_BDIR ) exec_for_item(-1, dname);
-
- if( flg_recurse )
- {
- dfd = opendir(dname);
- if( dfd == 0 && errno == EACCES && flg_force )
- {
- old_mode = (cur_file_stat.st_mode & 07777);
- if( chmod(dname, (0700|old_mode)) )
- return error(errno, "", dname);
-
- dfd = opendir(dname);
- }
- if( dfd == 0 ) return error(errno, "", dname);
-
- while((ent=readdir(dfd)))
- {
- if( strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0 )
- continue;
-
- alloca(0); /* Free up if using fake version */
- execute(dname, ent->d_name);
- }
- closedir(dfd);
- if( old_mode != -1 )
- chmod(dname, old_mode);
- }
-
- if( cmd_tok&DO_ADIR )
- {
- lstat(dname, &cur_file_stat);
- exec_for_item(1, dname);
- }
- return 0;
-}
-
-void exec_for_item(when, fname)
-int when; char * fname;
-{
- int rv = -1;
- switch(cmd_tok)
- {
- case CMD_FT: rv = cmd_ft(fname); break;
-
- case CMD_CAT: rv = copy_file(fname, "-"); break;
-
- case CMD_CHGRP: /* And fall */
- case CMD_CHMOD: /* And fall */
- case CMD_CHOWN: rv = copy_modes(fname); break;
-
- case CMD_CP: rv = cmd_cp(fname); break;
- case CMD_MV: rv = cmd_mv(fname); break;
- case CMD_RM: rv = cmd_rm(fname); break;
-
- case CMD_EXTAR: error(EINVAL, "", "No code."); exit(1);
-
- case CMD_LN+OK_DIR+OK_NO_SOURCE:
- case CMD_LN: rv = cmd_ln(fname); break;
-
- case CMD_INSTALL: error(EINVAL, "", ""); exit(1);
-
- case CMD_MKDIR: rv = cmd_mkdir(fname); break;
- case CMD_MKFIFO: rv = cmd_mkfifo(fname); break;
-#ifdef S_IFSOCK
- case CMD_MKSOCK: rv = cmd_mksock(fname); break;
-#endif
- case CMD_MKNOD: break;
- }
-}
-
-void parse_perms(prefix, ustring)
-char * prefix; char * ustring;
-{
- char * userstr;
- char * groupstr;
- char * modestr;
- char * cp;
- struct passwd * pwd = 0;
- struct group * grp;
-
- userstr = alloca(strlen(prefix) + strlen(ustring) + 2);
- strcpy(userstr, prefix);
- strcat(userstr, ustring);
-
- /* Select User */
- cp = strchr(userstr, ':');
- if(!cp) cp = strchr(userstr, '.');
- if(cp) *cp = '\0';
-
- /* If there's a user */
- if( *userstr != 0 )
- {
- pwd = getpwnam(userstr);
- if(pwd == NULL)
- {
- if(!strisdigit(userstr) )
- {
- error(EINVAL, "Unknown user ", userstr);
- exit(1);
- }
- set_user = atoi(userstr);
- }
- else set_user = pwd->pw_uid;
- endpwent();
- }
- if(cp)
- {
- groupstr = cp+1;
- cp = strchr(groupstr, ':');
- if(!cp) cp = strchr(groupstr, '.');
- if(cp) *cp = '\0';
- if( *groupstr != '\0' )
- {
- grp = getgrnam(groupstr);
- if(grp == NULL)
- {
- if(!strisdigit(groupstr) )
- {
- error(EINVAL, "Unknown group ", groupstr);
- exit(1);
- }
- set_group = atoi(groupstr);
- }
- else set_group = grp->gr_gid;
- endgrent();
- }
- else if( pwd )
- set_group = pwd->pw_gid;
- }
- if(cp)
- {
- modestr = cp+1;
- if(strisdigit(modestr))
- set_mode = strtol(modestr, NULL, 8);
- else
- {
- strncpy(mode_str, modestr, sizeof(mode_str)-1);
- /* This is the time that the mode change will fail on syn error */
- (void) edit_mode(u_mask, mode_str);
- }
- }
-
- if( set_user < 0 && set_group < 0 && set_mode < 0 && *mode_str == 0)
- {
- error(EINVAL, "", "Permission string has no changes");
- exit(1);
- }
-}
-
-int edit_mode(mode, mode_str)
-int mode; char * mode_str;
-{
- char * str=mode_str;
-static mtab[] = {0, 0111, 0222, 0333, 0444, 0555, 0666, 0777 };
-
- int done_change = 0;
- int isdir = S_ISDIR(mode);
- int change_op = 0;
- int change_mask = u_mask;
- int v=0, s=0, nm=0;
-
- for(; *mode_str; mode_str++)
- {
- switch(*mode_str)
- {
- case ',': change_op = 0;
- change_mask=u_mask; continue;
- case '=': change_op = 1; if(0) {
- case '+': change_op = 2; } if(0) {
- case '-': change_op = 3; }
- v=0; nm=0;
- if(strchr(",=+-", mode_str[1]) == 0 ) continue;
- break;
- case 'a': if(change_op) goto ch_error;
- nm |= 07777; if(0) {
- case 'u': nm |= 04700; s= 6; } if(0) {
- case 'g': nm |= 02070; s= 3; } if(0) {
- case 'o': nm |= 01007; s= 0; }
- if(change_op==0) { change_mask=nm; continue; }
- v |= mtab[(mode>>s)&7];
- break;
- case 'r': v |= 0444; break;
- case 'w': v |= 0222; break;
- case 'x': v |= 0111; break;
- case 's': v |=06000; break;
- case 't': v |=01000; break;
- case 'X': v |= mtab[isdir]; break;
- default: goto ch_error;
- }
- switch(change_op)
- {
- case 0: goto ch_error;
- case 1: mode= ((mode&(~change_mask)) | (v&change_mask));
- break;
- case 2: mode= ( mode | (v&change_mask));
- break;
- case 3: mode= ( mode & ~(v&change_mask));
- break;
- }
- done_change=1;
- }
- if(!done_change)
- {
-ch_error:
- error(EINVAL, "Invalid mode string ", str);
- exit(1);
- }
- return mode;
-}
-
-int
-cmd_ft(fname)
-char * fname;
-{
-static char oldpath[2048] = "~";
-static int last_uid=-1, last_gid=-1, last_mode=-1;
- struct passwd * pptr;
- struct group * gptr;
-
- if( flg_verbose>1 )
- {
- char *p = 0;
- if( fname[1] ) p = strrchr(fname, '/');
- if( p )
- {
- *p = '\0';
- if( strcmp(fname, oldpath) != 0 )
- {
- strcpy(oldpath, fname);
- printf("%s/\n", oldpath);
- }
- *p = '/';
- }
- else if( *oldpath )
- *oldpath = '\0';
- if(p) printf("%s", p+1);
- else printf("%s", fname);
-
-#ifdef S_IFLNK
- if( S_ISLNK(cur_file_stat.st_mode))
- {
- char linkbuf[1024];
- int v;
- *linkbuf='\0';
- v = readlink(fname, linkbuf, sizeof(linkbuf));
- if(v>0) linkbuf[v] = '\0';
- printf("\t+%s", linkbuf);
- }
- else
-#endif
- if( cur_file_stat.st_mode != last_mode
- || cur_file_stat.st_uid != last_uid
- || cur_file_stat.st_gid != last_gid)
- {
- printf("\t");
- if( cur_file_stat.st_uid != last_uid )
- {
- pptr = getpwuid(cur_file_stat.st_uid);
- if( pptr )
- printf("%s", pptr->pw_name);
- else
- printf("%d", cur_file_stat.st_uid);
- }
- printf(":");
- if( cur_file_stat.st_gid != last_gid )
- {
- gptr = getgrgid(cur_file_stat.st_gid);
- if( gptr )
- printf("%s", gptr->gr_name);
- else
- printf("%d", cur_file_stat.st_gid);
- }
- if( (cur_file_stat.st_mode&07777) != (last_mode&07777) )
- printf(":%03o", cur_file_stat.st_mode & 07777);
-
- switch(cur_file_stat.st_mode & S_IFMT)
- {
- case S_IFDIR: printf("\td"); break;
- case S_IFIFO: printf("\tp"); break;
-#ifdef S_IFSOCK
- case S_IFSOCK: printf("\ts"); break;
-#endif
- case S_IFBLK: printf("\tb,%d,%d", cur_file_stat.st_rdev>>8,
- cur_file_stat.st_rdev&0xFF);
- break;
- case S_IFCHR: printf("\tc,%d,%d", cur_file_stat.st_rdev>>8,
- cur_file_stat.st_rdev&0xFF);
- break;
- }
- last_mode = ((cur_file_stat.st_mode&07777)|S_IFREG);
- if( (cur_file_stat.st_mode&07000) ) last_mode = -1;
- last_uid = cur_file_stat.st_uid;
- last_gid = cur_file_stat.st_gid;
- }
- printf("\n");
- }
- else printf("%s\n", fname);
-
- return 0;
-}
-
-int
-cmd_mkfifo(fname)
-char * fname;
-{
- int rv;
- int mode=0666;
- if( set_mode >= 0 ) mode=set_mode;
- rv = mknod(fname, S_IFIFO|mode, 0);
- if(rv<0)
- warning(errno, "Cannot create fifo ", fname);
- return rv;
-}
-
-#ifdef S_IFSOCK
-int
-cmd_mksock(fname)
-char * fname;
-{
- int rv, fd, len;
- struct sockaddr *adr;
-
- len = strlen(fname)+1 + sizeof(*adr) - sizeof(adr->sa_data);
- if( len < sizeof(*adr) ) len = sizeof(*adr);
-
- adr = alloca(len+2);
- adr->sa_family = AF_UNIX;
- strcpy(adr->sa_data, fname);
-
- rv = fd = socket(AF_UNIX, SOCK_STREAM, 0);
- if( fd>=0 ) rv = bind(fd, adr, len);
- if( fd>=0 ) close(fd);
- if(set_mode >= 0 && chmod(fname, set_mode&07777) < 0 )
- warning(errno, "Chmod ", fname);
-
- if(rv<0)
- warning(errno, "Cannot create socket ", fname);
- return rv;
-}
-#endif
-
-int
-cmd_rm(fname)
-char * fname;
-{
- struct stat dirstat;
- int rv;
- char * buf, * p;
-
- if( S_ISDIR(cur_file_stat.st_mode) )
- if( !flg_recurse ) return error(EISDIR, "", fname);
-
- if( S_ISDIR(cur_file_stat.st_mode) )
- {
- if( rmdir(fname) >= 0 ) return 0;
- }
- else
- {
- if( unlink(fname) >= 0 ) return 0;
- }
-
- if( !flg_force )
- return error(errno, "", fname);
-
- /* Try VERY hard */
- buf = alloca(strlen(fname)+4);
- strcpy(buf, fname);
- p = strrchr(buf, '/');
- if( p ) strcpy(p+1, "."); else strcpy(buf, ".");
-
- if( stat(buf, &dirstat) < 0 ) return -1;
- if( chmod(buf, dirstat.st_mode|0700) < 0 ) return -1;
-
- if( S_ISDIR(cur_file_stat.st_mode) )
- rv = rmdir(fname);
- else
- rv = unlink(fname);
-
- chmod(buf, dirstat.st_mode);
-
- return rv;
-}
-
-void
-build_dest(dest, name, newpath)
-char * dest; char * name; char * newpath;
-{
- char * p;
- strcpy(dest, newpath);
- if( add_base )
- {
- strcat(dest, "/");
- p = strrchr(or_name, '/');
- if(p==0) strcat(dest, or_name);
- else strcat(dest, p+1);
- }
- if(strlen(name) <= or_offset) return;
- strcat(dest, name+or_offset);
-}
-
-int
-strisdigit(str)
-char * str;
-{
- if( str==0 || *str == 0 ) return 0;
-
- for(;*str; str++)
- if(*str>'9'|| *str<'0') return 0;
- return 1;
-}
-
-int
-cmd_mv(fname)
-char * fname;
-{
- char * destfile;
- destfile = alloca(strlen(fname)+strlen(cmd_string)+4);
-
- build_dest(destfile, fname, cmd_string);
-
- if( !flg_force && lstat(destfile, &access_stat) == 0 )
- return error(EEXIST, "", destfile);
-
- if( rename(fname, destfile) == 0 ) return 0;
-
- if( errno != EXDEV )
- return error(errno, "", fname);
-
- if( S_ISDIR(cur_file_stat.st_mode) )
- return error(EISDIR, "Can't rename across devices ", fname);
-
- if( copy_file(fname, destfile) != 0 ) return -1;
- copy_modes(destfile);
- return unlink(fname);
-}
-
-int
-cmd_ln(fname)
-char * fname;
-{
- char * destfile;
- destfile = alloca(strlen(fname)+strlen(cmd_string)+4);
-
- build_dest(destfile, fname, cmd_string);
-
- if( lstat(destfile, &access_stat) != -1 )
- {
- if( !flg_force ) return error(EEXIST, "", destfile);
- cmd_rm(destfile);
- }
-
-#ifdef S_IFLNK
- if( flg_symlink )
- {
- if( symlink(fname, destfile) == 0 ) return 0;
- }
- else
- {
-#endif
- if( link(fname, destfile) == 0 ) return 0;
-#ifdef S_IFLNK
- }
-#endif
-
- return error(errno, "", destfile);
-}
-
-int
-cmd_cp(fname)
-char * fname;
-{
- struct stat dest_stat;
- char * destfile;
- int no_dest = 0;
-
- destfile = alloca(strlen(fname)+strlen(cmd_string)+4);
-
- build_dest(destfile, fname, cmd_string);
-
- if( stat(destfile, &dest_stat) >= 0 )
- {
- if( dest_stat.st_ino == cur_file_stat.st_ino
- && dest_stat.st_dev == cur_file_stat.st_dev )
- {
- warning(EPERM, "Can't copy file to itself ", fname);
- return -1;
- }
- }
- else no_dest = 1;
-
- if( S_ISDIR(cur_file_stat.st_mode) )
- {
- if( !no_dest )
- {
- if( S_ISDIR(dest_stat.st_mode) ) return 0;
- if( unlink(destfile) < 0 )
- return error(errno, "Can't delete ", destfile);
- }
- return cmd_mkdir(destfile);
- }
- else if( S_ISDIR(dest_stat.st_mode) )
- return error(EPERM, "Can't copy non-directory to directory ", destfile);
- else if( S_ISREG(cur_file_stat.st_mode) )
- {
- /* Copy_ok - do we want to force a real file */;
- if( flg_force && !no_dest && !S_ISREG(dest_stat.st_mode) )
- cmd_rm(destfile);
- }
- else if( flg_recurse ) /* Don't copy other things while recursing */
- {
- return error(EPERM, "Can't copy ", fname);
- }
-
- if( copy_file(fname, destfile) != 0 ) return -1;
- if( flg_preserve ) copy_modes(destfile);
- return 0;
-}
-
-int
-copy_modes(file)
-char * file;
-{
- int user, group, mode;
- /* chown turns off set[ug]id bits for non-root,
- so do the chmod last. */
-
- /* Try to copy the old file's modtime and access time. */
- if(set_time)
- {
- struct utimbuf tv;
-
- tv.actime = cur_file_stat.st_atime;
- tv.modtime = cur_file_stat.st_mtime;
- if( set_time != -1 )
- tv.modtime = set_time;
- if (utime (file, &tv) && !flg_force)
- return error (errno, "", file);
- }
-
- /* Try to preserve ownership. For non-root it might fail, but that's ok.
- But root probably wants to know, e.g. if NFS disallows it. */
- user = cur_file_stat.st_uid; if(set_user>=0) user = set_user;
- group = cur_file_stat.st_gid; if(set_group>=0) group = set_group;
-
- if (chown (file, user, group)
- && (errno != EPERM || geteuid() == 0 || (flg_preserve==0 && flg_force==0)))
- error (errno, "Can't change perms for ", file);
-
- mode = cur_file_stat.st_mode;
- if(set_mode>=0) mode=set_mode;
- else if(*mode_str)
- mode = edit_mode(mode, mode_str);
-
- if (chmod (file, mode & 07777))
- return error (errno, "", file);
-
- return 0;
-}
-
-/* This copies from something to a file or stdout */
-/* If the source has zero blocks (possibly holes) the destination
- * is built with holes (assuming it's a normal file) */
-
-int
-copy_file(source, dest)
-char * source; char * dest;
-{
- char * buf;
- int sfd, dfd;
- struct stat st;
- int blksz = BUFSIZ;
- int cc;
- char * ptr;
- int hole_flag = 0;
- int retv = 0;
- int no_seek;
- int mmode = 0666;
-
- if(flg_verbose>1) printf("%s -> %s\n", source, dest);
- if( strcmp(source, "-") == 0 )
- sfd = 0;
- else
- {
- sfd = open(source, O_RDONLY);
- if(sfd<0) return error(errno, "", source);
- mmode = (cur_file_stat.st_mode&0777);
- }
-
- if( strcmp(dest, "-") == 0 )
- dfd = 1;
- else
- {
- dfd = open(dest, O_WRONLY|O_TRUNC|O_CREAT, mmode);
- if(dfd<0)
- {
- close(sfd);
- return error(errno, "Cannot create ", source);
- }
- }
-
- if( fstat(dfd, &st) )
- {
- retv = error(errno, "", dest);
- no_seek = 1;
- }
- else
- {
-#ifndef __BCC__
- blksz = st.st_blksize;
-#endif
- no_seek = !S_ISREG(st.st_mode);
- }
- buf = alloca(blksz + sizeof(int));
- if( buf == 0 ) return error(0, "Out of memory", "");
-
- for(;;)
- {
- cc = read(sfd, buf, blksz);
- if(cc<0)
- {
- retv = error(errno, "", source);
- goto exit_now;
- }
- if(cc==0) break;
- buf[cc] = 1;
- for(ptr=buf; *ptr==0 ; ptr++) ;
- if((hole_flag = (ptr == buf+cc)))
- { /* Make a hole */
- if( lseek(dfd, (off_t) cc, SEEK_CUR) < 0 )
- {
- retv = error(errno, "", dest);
- goto exit_now;
- }
- }
- else
- {
- if( cc != write(dfd, buf, cc))
- {
- retv = error(errno, "", dest);
- goto exit_now;
- }
- }
- }
- if( hole_flag )
- {
- if( lseek(dfd, (off_t) -1, SEEK_CUR) < 0
- || write(dfd, "", 1) != 1 )
- {
- retv = error(errno, "", dest);
- goto exit_now;
- }
- }
-
-exit_now:
- if(sfd>2) close(sfd);
- if(dfd>2) close(dfd);
- return retv;
-}
-
-void
-Usage()
-{
- int i;
-
- printf("FileTool Usage: %s%s", prog_name[0]=='-'?"ft -":"", prog_name);
- if( cmd_tok == CMD_FT )
- {
- printf(" --[com_name] [-options] [files]\n");
- printf("\nAvailable commands are:\n");
- }
-
- for(i=1; command_list[i].name; i++)
- {
- if( cmd_tok == CMD_FT )
- printf(" %s --%s", prog_name, command_list[i].name);
- else if( cmd_tok != command_list[i].cmd )
- continue;
-
- if( *command_list[i].opts )
- printf(" [-%s]", command_list[i].opts);
- switch(command_list[i].argpat)
- {
- case 1: printf(" <info> [files]"); break;
- case -1: printf(" [files] [dest]"); break;
- case 0: printf(" [files]"); break;
- default: printf(" path [bcu] major minor"); break;
- }
- printf("\n");
- }
-
- exit(99);
-}
-
-int
-cmd_mkdir(dirname)
-char * dirname;
-{
- int retv;
- int mode = 0777;
- if( set_mode >= 0 ) mode = set_mode;
-
- retv = mkdir(dirname, mode);
- if(retv<0)
- {
- if(flg_mkpdir && errno == ENOENT)
- {
- /* Create parents */
- }
- }
- if( retv>=0 && cmd_tok == CMD_MKDIR )
- {
- if( set_user > 0 || set_group > 0 )
- {
- if( chown(dirname, set_user, set_group) < 0)
- warning(errno, "Cannot change directory owner ", dirname);
- else if( chmod (dirname, mode & 07777) )
- warning(errno, "", dirname);
- }
- }
-
- if(retv<0) error(errno, "Cannot create directory ", dirname);
- return retv;
-}
-
-int
-cmd_mknod()
-{
- int device;
- int rv = -1;
- int mode=0666;
- if( set_mode >= 0 ) mode=set_mode;
-
- device = (atoi(flist[2])<<8) + atoi(flist[3]);
-
- if(flist[1][0] == 'b')
- rv = mknod(flist[0], S_IFBLK|mode, device);
- else if(flist[1][0] == 'c' || flist[1][0] == 'u')
- rv = mknod(flist[0], S_IFCHR|mode, device);
- else Usage();
-
- if(rv<0)
- {
- error(errno, "", flist[0]);
- exit(1);
- }
- return rv;
-}
-
-int
-warning(enumber, estr, eobj)
-int enumber; char * estr; char * eobj;
-{
- if(flg_verbose)
- return error(enumber, estr, eobj);
- return 0;
-}
-
-int
-error(enumber, estr, eobj)
-int enumber; char * estr; char * eobj;
-{
- fprintf(stderr, "%s%s: ", prog_name[0]=='-'?"ft":"", prog_name);
- fprintf(stderr, "%s%s: %s\n", estr, eobj, strerror(enumber));
- return -1;
-}
diff --git a/libc/tests/grab.c b/libc/tests/grab.c
deleted file mode 100644
index b65fa28..0000000
--- a/libc/tests/grab.c
+++ /dev/null
@@ -1,81 +0,0 @@
-
-#include <stdio.h>
-#include <malloc.h>
-
-struct s
-{
- struct s * n;
- char v[1];
-};
-
-#define M ((unsigned)-1>>1)
-#define V (M^(M>>1))
-
-main (argc,argv)
-int argc;
-char ** argv;
-{
- struct s * ptr1 = 0;
- struct s * ptr2;
- struct s * ptr3;
- int i,sz;
- unsigned long total = 0;
-
- for(i=0, sz=256 ; i<32; i++, sz = ((sz << 1) | (sz & V)) & M)
- {
- ptr2 = (struct s *) malloc(sz-sizeof(int));
- printf("%2d(%8u)..%08lx..%ld\n",i,sz,(long)ptr2,(long)ptr2);
- if(ptr2==0) break;
- total+=sz;
- if(ptr1==0)
- {
- ptr1 = ptr3 = ptr2;
- ptr3->n = 0;
- }
- else
- {
- ptr3->n = ptr2;
- ptr3 = ptr2;
- ptr3->n = 0;
- }
- }
- for(sz>>=1; sz>3; )
- {
- ptr2 = (struct s *) malloc(sz-sizeof(int));
- if(ptr2==0) { sz >>=1; continue; }
- printf("%2d(%8u)..%08lx..%ld\n",i++,sz,(long)ptr2,(long)ptr2);
- total+=sz;
- if(ptr1==0)
- {
- ptr1 = ptr3 = ptr2;
- ptr3->n = 0;
- }
- else
- {
- ptr3->n = ptr2;
- ptr3 = ptr2;
- ptr3->n = 0;
- }
- }
- printf("Free all - total was %ldK bytes\n", total/1024);
- while( ptr1 )
- {
- ptr3 = ptr1->n;
- free(ptr1);
- ptr1 = ptr3;
- }
- ptr2 = (struct s *) malloc(200);
- printf("%2d(%8u)..%08lx..%ld\n",i++,200,(long)ptr2,(long)ptr2);
- ptr2 = (struct s *) malloc(30000);
- printf("%2d(%8u)..%08lx..%ld\n",i++,30000,(long)ptr2,(long)ptr2);
- ptr2 = (struct s *) malloc(20000);
- printf("%2d(%8u)..%08lx..%ld\n",i++,20000,(long)ptr2,(long)ptr2);
- sz = (256<<sizeof(int));
- do
- {
- ptr2 = (struct s *) malloc(sz-sizeof(int));
- printf("%2d(%8u)..%08lx..%ld\n",i++,sz,(long)ptr2,(long)ptr2);
- }
- while(ptr2 && i < 100);
- exit(0);
-}
diff --git a/libc/tests/hd.c b/libc/tests/hd.c
deleted file mode 100644
index 341185f..0000000
--- a/libc/tests/hd.c
+++ /dev/null
@@ -1,185 +0,0 @@
-
-#include <stdio.h>
-#include <ctype.h>
-#include <errno.h>
-
-int lastnum[16] = {-1};
-long lastaddr = -1;
-long offset = 0;
-
-FILE *fd;
-
-main(argc, argv)
-int argc;
-char **argv;
-{
- int done = 0;
- int ar;
- int aflag = 1;
-
- for (ar = 1; ar < argc; ar++)
- if (aflag && argv[ar][0] == '-')
- switch (argv[ar][1])
- {
- case 'r':
- return reverse_hd(argc, argv);
- case 'o':
- offset = strtol(argv[ar] + 2, (void *) 0, 0);
- break;
- case '-':
- aflag = 0;
- break;
- default:
- Usage();
- }
- else
- {
- fd = fopen(argv[ar], "rb");
- if (fd == 0)
- fprintf(stderr, "Cannot open file '%s'\n", argv[ar]);
- else
- {
- do_fd();
- fclose(fd);
- }
- done = 1;
- }
-
- if (!done)
-#ifdef MSDOS
- Usage();
-#else
- {
- fd = stdin;
- do_fd();
- }
-#endif
-}
-
-Usage()
-{
- fprintf(stderr, "Usage: hd [-r]|[[-oOffset] file]\n");
- exit(1);
-}
-
-do_fd()
-{
- int j, ch;
- char buf[20];
- int num[16];
-
- if (offset)
- fseek(fd, offset, 0);
-
- for (ch = 0; ch != EOF; offset += 16)
- {
- memset(buf, '\0', 16);
- for (j = 0; j < 16; j++)
- num[j] = -1;
- for (j = 0; j < 16; j++)
- {
- ch = fgetc(fd);
- if (ch == EOF)
- break;
-
- num[j] = ch;
- if (isascii(ch) && isprint(ch))
- buf[j] = ch;
- else
- buf[j] = '.';
- }
- printline(offset, num, buf, ch == EOF);
- }
-}
-
-printline(address, num, chr, eofflag)
-long address;
-int *num;
-char *chr;
-int eofflag;
-{
- int j;
-
- if (lastaddr >= 0)
- {
- for (j = 0; j < 16; j++)
- if (num[j] != lastnum[j])
- break;
- if (j == 16 && !eofflag)
- {
- if (lastaddr + 16 == address)
- {
- printf("*\n");
- fflush(stdout);
- }
- return;
- }
- }
-
- lastaddr = address;
- printf("%06lx:", address);
- for (j = 0; j < 16; j++)
- {
- if (j == 8)
- putchar(' ');
- if (num[j] >= 0)
- printf(" %02x", num[j]);
- else
- printf(" ");
- lastnum[j] = num[j];
- num[j] = -1;
- }
-
- printf(" %.16s\n", chr);
-}
-
-
-/*
- * This function takes output from hd and converts it back into a binary
- * file
- */
-
-/* -- 0 1 2 3 4 5 6 7 8 9 a b c d e f */
-static char *datafmt = "%x: %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x %x\n";
-reverse_hd()
-{
- char str[160];
- char * ptr;
- int c[16], d[16], x, i, nxtaddr, addr;
-
- for (i = 0; i < 16; i++)
- c[i] = 0;
- nxtaddr = 0;
-
- for (nxtaddr = 0;;)
- {
- if (gets(str) == NULL)
- break;
-
- str[57] = 0;
- ptr = str;
-
- if( !isxdigit(*ptr) ) continue;
- addr = strtol(ptr, &ptr, 16);
- if( *ptr == ':' ) ptr++;
-
- if (nxtaddr == 0)
- nxtaddr = addr;
- while (nxtaddr < addr)
- {
- nxtaddr += 16;
- for (i = 0; i < 16; i++)
- putchar(c[i]);
- }
- for (i = 0; i < 16 && *ptr; i++)
- {
- char * ptr2;
- c[i] = strtol(ptr, &ptr2, 16);
- if( ptr == ptr2 ) break;
- putchar(c[i]);
- ptr = ptr2;
- }
- nxtaddr += 16;
- }
- return 0;
-}
diff --git a/libc/tests/line2.c b/libc/tests/line2.c
deleted file mode 100644
index 6cc11ff..0000000
--- a/libc/tests/line2.c
+++ /dev/null
@@ -1,15 +0,0 @@
-
-#include <stdio.h>
-
-char buf[256];
-
-main()
-{
- FILE * fd;
- fd = fopen("/etc/passwd", "r");
-
- while(fgets(buf, sizeof(buf), fd) != NULL)
- {
- printf(">>%s", buf);
- }
-}
diff --git a/libc/tests/lines.c b/libc/tests/lines.c
deleted file mode 100644
index 6f3afb0..0000000
--- a/libc/tests/lines.c
+++ /dev/null
@@ -1,36 +0,0 @@
-
-#include <string.h>
-#include <fcntl.h>
-
-char *
-readline(fd)
-{
-static char linebuf[256];
- int cc;
- char * p;
-
- cc = read(fd, linebuf, sizeof(linebuf)-1);
- if( cc <= 0 ) return 0;
- p = strchr(linebuf, '\n');
- if( p == 0 ) p = linebuf+sizeof(linebuf)-1;
- else
- {
- p++; lseek(fd, (long)(p-linebuf)-cc, 1);
- }
- *p = 0;
- return linebuf;
-}
-
-main()
-{
- int fd = open("/etc/passwd", O_RDONLY);
- char * p;
-
- if(fd<0) exit(1);
-
- while( p=readline(fd) )
- {
- write(1, ">>", 2);
- write(1, p, strlen(p));
- }
-}
diff --git a/libc/tests/ls.c b/libc/tests/ls.c
deleted file mode 100644
index 8cae4d0..0000000
--- a/libc/tests/ls.c
+++ /dev/null
@@ -1,1049 +0,0 @@
-/* ls 3.2 - List files. Author: Kees J. Bot
- *
- * About the amount of bytes for heap + stack under Minix:
- * Ls needs a average amount of 42 bytes per unserviced directory entry, so
- * scanning 10 directory levels deep in an ls -R with 100 entries per directory
- * takes 42000 bytes of heap. So giving ls 10000 bytes is tight, 20000 is
- * usually enough, 40000 is pessimistic.
- */
-
-/* Compile with the proper -D flag for your system:
- *
- * _MINIX Minix (1.5 or later)
- * BSD BSD derived (has st_blocks)
- * AMOEBA Amoeba's emulation of UNIX
- */
-
-/* The array _ifmt[] is used in an 'ls -l' to map the type of a file to a
- * letter. This is done so that ls can list any future file or device type
- * other than symlinks, without recompilation. (Yes it's dirty.)
- */
-char _ifmt[] = "0pcCd?bB-?l?s???";
-
-#define ifmt(mode) _ifmt[((mode) >> 12) & 0xF]
-
-#define nil 0
-#include <stdio.h>
-#include <string.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <stddef.h>
-#include <stdlib.h>
-#include <unistd.h>
-#ifdef AMOEBA
-#undef S_IFLNK /* Liars */
-#endif
-#include <dirent.h>
-#include <time.h>
-#include <pwd.h>
-#include <grp.h>
-#include <errno.h>
-#include <fcntl.h>
-#if BSD || __minix_vmd
-#include <termios.h>
-#endif
-#if __minix_vmd
-#include <sys/ioctl.h>
-#endif
-
-#ifndef major
-#define major(dev) ((int) (((dev) >> 8) & 0xFF))
-#define minor(dev) ((int) (((dev) >> 0) & 0xFF))
-#endif
-
-#if !_MINIX
-#define SUPER_ID uid /* Let -A flag be default for SUPER_ID == 0. */
-#else
-#define SUPER_ID gid
-#endif
-
-#ifdef S_IFLNK
-int (*status)(const char *file, struct stat *stp);
-#else
-#define status stat
-#endif
-
-/* Basic disk block size is 512 except for one niche O.S. */
-#if _MINIX
-#define BLOCK 1024
-#else
-#define BLOCK 512
-#endif
-
-/* Some terminals ignore more than 80 characters on a line. Dumb ones wrap
- * when the cursor hits the side. Nice terminals don't wrap until they have
- * to print the 81st character. Wether we like it or not, no column 80.
- */
-#ifdef TIOCGWINSZ
-int ncols= 79;
-#else
-#define ncols 79
-#endif
-
-#define NSEP 2 /* # spaces between columns. */
-
-#ifdef TIOCGWINSZ
-#define MAXCOLS 150
-#else
-#define MAXCOLS (1 + (ncols / (1+NSEP))) /* Max # of files per line. */
-#endif
-
-char *arg0; /* Last component of argv[0]. */
-int uid, gid; /* callers id. */
-int ex= 0; /* Exit status to be. */
-int istty; /* Output is on a terminal. */
-
-/* Safer versions of malloc and realloc: */
-
-void heaperr(void)
-{
- fprintf(stderr, "%s: Out of memory\n", arg0);
- exit(-1);
-}
-
-void *allocate(size_t n)
-/* Deliver or die. */
-{
- void *a;
-
- if ((a= malloc(n)) == nil) heaperr();
- return a;
-}
-
-#define reallocate rllct /* Same as realloc under some compilers. */
-
-void *reallocate(void *a, size_t n)
-{
- if ((a= realloc(a, n)) == nil) heaperr();
- return a;
-}
-
-char allowed[] = "acdfgilnqrstu1ACFLMRTX";
-char flags[sizeof(allowed)];
-
-char arg0flag[] = "cfmrtx"; /* These in argv[0] go to upper case. */
-
-void setflags(char *flgs)
-{
- int c;
-
- while ((c= *flgs++) != 0) {
- if (strchr(allowed, c) == nil) {
- fprintf(stderr, "Usage: %s -[%s] [file ...]\n",
- arg0, allowed);
- exit(1);
- } else
- if (strchr(flags, c) == nil)
- flags[strlen(flags)] = c;
- }
-}
-
-int present(int f)
-{
- return f == 0 || strchr(flags, f) != nil;
-}
-
-void report(char *f)
-/* Like perror(3), but in the style: "ls: junk: No such file or directory. */
-{
- fprintf(stderr, "%s: %s: %s\n", arg0, f, strerror(errno));
- ex= 1;
-}
-
-/* Two functions, uidname and gidname, translate id's to readable names.
- * All names are remembered to avoid searching the password file.
- */
-#define NNAMES (1 << (sizeof(int) + sizeof(char *)))
-enum whatmap { PASSWD, GROUP };
-
-struct idname { /* Hash list of names. */
- struct idname *next;
- char *name;
- uid_t id;
-} *uids[NNAMES], *gids[NNAMES];
-
-char *idname(unsigned id, enum whatmap map)
-/* Return name for a given user/group id. */
-{
- struct idname *i;
- struct idname **ids= &(map == PASSWD ? uids : gids)[id % NNAMES];
-
- while ((i= *ids) != nil && id < i->id) ids= &i->next;
-
- if (i == nil || id != i->id) {
- /* Not found, go look in the password or group map. */
- char *name= nil;
- char noname[3 * sizeof(uid_t)];
-
- if (!present('n')) {
- if (map == PASSWD) {
- struct passwd *pw= getpwuid(id);
-
- if (pw != nil) name= pw->pw_name;
- } else {
- struct group *gr= getgrgid(id);
-
- if (gr != nil) name= gr->gr_name;
- }
- }
- if (name == nil) {
- /* Can't find it, weird. Use numerical "name." */
- sprintf(noname, "%u", id);
- name= noname;
- }
-
- /* Add a new id-to-name cell. */
- i= allocate(sizeof(*i));
- i->id= id;
- i->name= allocate(strlen(name) + 1);
- strcpy(i->name, name);
- i->next= *ids;
- *ids= i;
- }
- return i->name;
-}
-
-#define uidname(uid) idname((uid), PASSWD)
-#define gidname(gid) idname((gid), GROUP)
-
-/* Path name construction, addpath adds a component, delpath removes it.
- * The string path is used throughout the program as the file under examination.
- */
-
-char *path; /* Path name constructed in path[]. */
-int plen= 0, pidx= 0; /* Lenght/index for path[]. */
-
-void addpath(int *didx, char *name)
-/* Add a component to path. (name may also be a full path at the first call)
- * The index where the current path ends is stored in *pdi.
- */
-{
- if (plen == 0) path= (char *) allocate((plen= 32) * sizeof(path[0]));
-
- if (pidx == 1 && path[0] == '.') pidx= 0; /* Remove "." */
-
- *didx= pidx; /* Record point to go back to for delpath. */
-
- if (pidx > 0 && path[pidx-1] != '/') path[pidx++]= '/';
-
- do {
- if (*name != '/' || pidx == 0 || path[pidx-1] != '/') {
- if (pidx == plen)
- path= (char *) reallocate((void *) path,
- (plen*= 2) * sizeof(path[0]));
- path[pidx++]= *name;
- }
- } while (*name++ != 0);
-
- --pidx; /* Put pidx back at the null. The path[pidx++]= '/'
- * statement will overwrite it at the next call.
- */
-}
-
-#define delpath(didx) (path[pidx= didx]= 0) /* Remove component. */
-
-int field = 0; /* (used to be) Fields that must be printed. */
- /* (now) Effects triggered by certain flags. */
-
-#define F_INODE 0x001 /* -i */
-#define F_BLOCKS 0x002 /* -s */
-#define F_EXTRA 0x004 /* -X */
-#define F_MODE 0x008 /* -lMX */
-#define F_LONG 0x010 /* -l */
-#define F_GROUP 0x020 /* -g */
-#define F_BYTIME 0x040 /* -tuc */
-#define F_ATIME 0x080 /* -u */
-#define F_CTIME 0x100 /* -c */
-#define F_MARK 0x200 /* -F */
-#define F_TYPE 0x400 /* -T */
-#define F_DIR 0x800 /* -d */
-
-struct file { /* A file plus stat(2) information. */
- struct file *next; /* Lists are made of them. */
- char *name; /* Null terminated name. */
- ino_t ino;
- mode_t mode;
- uid_t uid;
- gid_t gid;
- nlink_t nlink;
- dev_t rdev;
- off_t size;
- time_t mtime;
- time_t atime;
- time_t ctime;
-#if BSD
- long blocks;
-#endif
-};
-
-void setstat(struct file *f, struct stat *stp)
-{
- f->ino= stp->st_ino;
- f->mode= stp->st_mode;
- f->nlink= stp->st_nlink;
- f->uid= stp->st_uid;
- f->gid= stp->st_gid;
- f->rdev= stp->st_rdev;
- f->size= stp->st_size;
- f->mtime= stp->st_mtime;
- f->atime= stp->st_atime;
- f->ctime= stp->st_ctime;
-#if BSD
- f->blocks= stp->st_blocks;
-#endif
-}
-
-#define PAST (26*7*24*3600L) /* Half a year ago. */
-/* Between PAST and FUTURE from now a time is printed, otherwise a year. */
-#define FUTURE (15*60L) /* Fifteen minutes. */
-
-static char *timestamp(struct file *f)
-/* Transform the right time field into something readable. */
-{
- struct tm *tm;
- time_t t;
- static time_t now;
- static int drift= 0;
- static char date[] = "Jan 19 2038";
- static char month[] = "JanFebMarAprMayJunJulAugSepOctNovDec";
-
- t= f->mtime;
- if (field & F_ATIME) t= f->atime;
- if (field & F_CTIME) t= f->ctime;
-
- tm= localtime(&t);
- if (--drift < 0) { time(&now); drift= 50; } /* limit time() calls */
-
- if (t < now - PAST || t > now + FUTURE) {
- sprintf(date, "%.3s %2d %4d",
- month + 3*tm->tm_mon,
- tm->tm_mday,
- 1900 + tm->tm_year);
- } else {
- sprintf(date, "%.3s %2d %02d:%02d",
- month + 3*tm->tm_mon,
- tm->tm_mday,
- tm->tm_hour, tm->tm_min);
- }
- return date;
-}
-
-char *permissions(struct file *f)
-/* Compute long or short rwx bits. */
-{
- static char rwx[] = "drwxr-x--x";
-
- rwx[0] = ifmt(f->mode);
- /* Note that rwx[0] is a guess for the more alien file types. It is
- * correct for BSD4.3 and derived systems. I just don't know how
- * "standardized" these numbers are.
- */
-
- if (field & F_EXTRA) { /* Short style */
- int mode = f->mode, ucase= 0;
-
- if (uid == f->uid) /* What group of bits to use. */
- /* mode<<= 0, */
- ucase= (mode<<3) | (mode<<6);
- /* Remember if group or others have permissions. */
- else
- if (gid == f->gid)
- mode<<= 3;
- else
- mode<<= 6;
-
- rwx[1]= mode&S_IRUSR ? (ucase&S_IRUSR ? 'R' : 'r') : '-';
- rwx[2]= mode&S_IWUSR ? (ucase&S_IWUSR ? 'W' : 'w') : '-';
-
- if (mode&S_IXUSR) {
- static char sbit[]= { 'x', 'g', 'u', 's' };
-
- rwx[3]= sbit[(f->mode&(S_ISUID|S_ISGID))>>10];
- if (ucase&S_IXUSR) rwx[3] += 'A'-'a';
- } else
- rwx[3]= f->mode&(S_ISUID|S_ISGID) ? '=' : '-';
- rwx[4]= 0;
- } else { /* Long form. */
- char *p= rwx+1;
- int mode= f->mode;
-
- do {
- p[0] = (mode & S_IRUSR) ? 'r' : '-';
- p[1] = (mode & S_IWUSR) ? 'w' : '-';
- p[2] = (mode & S_IXUSR) ? 'x' : '-';
- mode<<= 3;
- } while ((p+=3) <= rwx+7);
-
- if (f->mode&S_ISUID) rwx[3]= f->mode&(S_IXUSR>>0) ? 's' : '=';
- if (f->mode&S_ISGID) rwx[6]= f->mode&(S_IXUSR>>3) ? 's' : '=';
- if (f->mode&S_ISVTX) rwx[9]= f->mode&(S_IXUSR>>6) ? 't' : '=';
- }
- return rwx;
-}
-
-void numeral(int i, char **pp)
-{
- char itoa[3*sizeof(int)], *a=itoa;
-
- do *a++ = i%10 + '0'; while ((i/=10) > 0);
-
- do *(*pp)++ = *--a; while (a>itoa);
-}
-
-#define K 1024L /* A kilobyte counts in multiples of K */
-#define T 1000L /* A megabyte in T*K, a gigabyte in T*T*K */
-
-char *cxsize(struct file *f)
-/* Try and fail to turn a 32 bit size into 4 readable characters. */
-{
- static char siz[] = "1.2m";
- char *p= siz;
- off_t z;
-
- siz[1]= siz[2]= siz[3]= 0;
-
- if (f->size <= 5*K) { /* <= 5K prints as is. */
- numeral((int) f->size, &p);
- return siz;
- }
- z= (f->size + K-1) / K;
-
- if (z <= 999) { /* Print as 123k. */
- numeral((int) z, &p);
- *p = 'k'; /* Can't use 'K', looks bad */
- } else
- if (z*10 <= 99*T) { /* 1.2m (Try ls -X /dev/at0) */
- z= (z*10 + T-1) / T; /* Force roundup */
- numeral((int) z / 10, &p);
- *p++ = '.';
- numeral((int) z % 10, &p);
- *p = 'm';
- } else
- if (z <= 999*T) { /* 123m */
- numeral((int) ((z + T-1) / T), &p);
- *p = 'm';
- } else { /* 1.2g */
- z= (z*10 + T*T-1) / (T*T);
- numeral((int) z / 10, &p);
- *p++ = '.';
- numeral((int) z % 10, &p);
- *p = 'g';
- }
- return siz;
-}
-
-/* Transform size of file to number of blocks. This was once a function that
- * guessed the number of indirect blocks, but that nonsense has been removed.
- */
-#if BSD
-#define nblocks(f) ((f)->blocks)
-#else
-#define nblocks(f) (((f)->size + BLOCK-1) / BLOCK)
-#endif
-
-/* From number of blocks to kilobytes. */
-#if BLOCK < 1024
-#define nblk2k(nb) (((nb) + (1024 / BLOCK - 1)) / (1024 / BLOCK))
-#else
-#define nblk2k(nb) ((nb) * (BLOCK / 1024))
-#endif
-
-static int (*CMP)(struct file *f1, struct file *f2);
-static int (*rCMP)(struct file *f1, struct file *f2);
-
-static void mergesort(struct file **al)
-/* This is either a stable mergesort, or thermal noise, I'm no longer sure.
- * It must be called like this: if (L != nil && L->next != nil) mergesort(&L);
- */
-{
- /* static */ struct file *l1, **mid; /* Need not be local */
- struct file *l2;
-
- l1= *(mid= &(*al)->next);
- do {
- if ((l1= l1->next) == nil) break;
- mid= &(*mid)->next;
- } while ((l1= l1->next) != nil);
-
- l2= *mid;
- *mid= nil;
-
- if ((*al)->next != nil) mergesort(al);
- if (l2->next != nil) mergesort(&l2);
-
- l1= *al;
- for (;;) {
- if ((*CMP)(l1, l2) <= 0) {
- if ((l1= *(al= &l1->next)) == nil) {
- *al= l2;
- break;
- }
- } else {
- *al= l2;
- l2= *(al= &l2->next);
- *al= l1;
- if (l2 == nil) break;
- }
- }
-}
-
-int namecmp(struct file *f1, struct file *f2)
-{
- return strcmp(f1->name, f2->name);
-}
-
-int mtimecmp(struct file *f1, struct file *f2)
-{
- return f1->mtime == f2->mtime ? 0 : f1->mtime > f2->mtime ? -1 : 1;
-}
-
-int atimecmp(struct file *f1, struct file *f2)
-{
- return f1->atime == f2->atime ? 0 : f1->atime > f2->atime ? -1 : 1;
-}
-
-int ctimecmp(struct file *f1, struct file *f2)
-{
- return f1->ctime == f2->ctime ? 0 : f1->ctime > f2->ctime ? -1 : 1;
-}
-
-int typecmp(struct file *f1, struct file *f2)
-{
- return ifmt(f1->mode) - ifmt(f2->mode);
-}
-
-int revcmp(struct file *f1, struct file *f2) { return (*rCMP)(f2, f1); }
-
-static void sort(struct file **al)
-/* Sort the files according to the flags. */
-{
- if (!present('f') && *al != nil && (*al)->next != nil) {
- CMP= namecmp;
-
- if (!(field & F_BYTIME)) {
- /* Sort on name */
-
- if (present('r')) { rCMP= CMP; CMP= revcmp; }
- mergesort(al);
- } else {
- /* Sort on name first, then sort on time. */
-
- mergesort(al);
- if (field & F_CTIME)
- CMP= ctimecmp;
- else
- if (field & F_ATIME)
- CMP= atimecmp;
- else
- CMP= mtimecmp;
-
- if (present('r')) { rCMP= CMP; CMP= revcmp; }
- mergesort(al);
- }
- /* Separate by file type if so desired. */
-
- if (field & F_TYPE) {
- CMP= typecmp;
- mergesort(al);
- }
- }
-}
-
-struct file *newfile(char *name)
-/* Create file structure for given name. */
-{
- struct file *new;
-
- new= (struct file *) allocate(sizeof(*new));
- new->name= strcpy((char *) allocate(strlen(name)+1), name);
- return new;
-}
-
-void pushfile(struct file **flist, struct file *new)
-/* Add file to the head of a list. */
-{
- new->next= *flist;
- *flist= new;
-}
-
-void delfile(struct file *old)
-/* Release old file structure. */
-{
- free((void *) old->name);
- free((void *) old);
-}
-
-struct file *popfile(struct file **flist)
-/* Pop file off top of file list. */
-{
- struct file *f;
-
- f= *flist;
- *flist= f->next;
- return f;
-}
-
-int dotflag(char *name)
-/* Return flag that would make ls list this name: -a or -A. */
-{
- if (*name++ != '.') return 0;
-
- switch (*name++) {
- case 0: return 'a'; /* "." */
- case '.': if (*name == 0) return 'a'; /* ".." */
- default: return 'A'; /* ".*" */
- }
-}
-
-int adddir(struct file **aflist, char *name)
-/* Add directory entries of directory name to a file list. */
-{
- DIR *d;
- struct dirent *e;
-
- if (access(name, 0) < 0) {
- report(name);
- return 0;
- }
-
- if ((d= opendir(name)) == nil) {
- report(name);
- return 0;
- }
- while ((e= readdir(d)) != nil) {
- if (e->d_ino != 0 && present(dotflag(e->d_name))) {
- pushfile(aflist, newfile(e->d_name));
- aflist= &(*aflist)->next;
- }
- }
- closedir(d);
- return 1;
-}
-
-off_t countblocks(struct file *flist)
-/* Compute total block count for a list of files. */
-{
- off_t cb = 0;
-
- while (flist != nil) {
- switch (flist->mode & S_IFMT) {
- case S_IFDIR:
- case S_IFREG:
-#ifdef S_IFLNK
- case S_IFLNK:
-#endif
- cb += nblocks(flist);
- }
- flist= flist->next;
- }
- return cb;
-}
-
-void printname(char *name)
-/* Print a name with control characters as '?' (unless -q). The terminal is
- * assumed to be eight bit clean.
- */
-{
- int c, q= present('q');
-
- while ((c= *name++) != 0) {
- if (q && (c <= ' ' || c == 0177)) c= '?';
- putchar(c);
- }
-}
-
-int mark(struct file *f, int doit)
-{
- int c;
-
- if (!(field & F_MARK)) return 0;
-
- switch (f->mode & S_IFMT) {
- case S_IFDIR: c= '/'; break;
-#ifdef S_IFIFO
- case S_IFIFO: c= '|'; break;
-#endif
-#ifdef S_IFLNK
- case S_IFLNK: c= '@'; break;
-#endif
-#ifdef S_IFSOCK
- case S_IFSOCK: c= '='; break;
-#endif
- case S_IFREG:
- if (f->mode & (S_IXUSR | S_IXGRP | S_IXOTH)) {
- c= '*';
- break;
- }
- default:
- c= 0;
- }
- if (doit && c != 0) putchar(c);
- return c;
-}
-
-int colwidth[MAXCOLS]; /* Need colwidth[i] spaces to print column i. */
-int sizwidth[MAXCOLS]; /* Spaces for the size field in a -X print. */
-int namwidth[MAXCOLS]; /* Name field. */
-
-int maxise(int *aw, int w)
-/* Set *aw to the larger of it and w. Then return it. */
-{
- if (w > *aw) *aw= w;
- return *aw;
-}
-
-static int nsp= 0; /* This many spaces have not been printed yet. */
-#define spaces(n) (nsp= (n))
-#define terpri() (nsp= 0, putchar('\n')) /* No trailing spaces */
-
-void print1(struct file *f, int col, int doit)
-/* Either compute the number of spaces needed to print file f (doit == 0) or
- * really print it (doit == 1).
- */
-{
- int width= 0, n;
- char *p;
-
- while (nsp>0) { putchar(' '); nsp--; }/* Fill gap between two columns */
-
- if (field & F_INODE) {
- if (doit) printf("%5d ", f->ino); else width+= 6;
- }
- if (field & F_BLOCKS) {
- if (doit) printf("%4ld ", nblk2k(nblocks(f))); else width+= 5;
- }
- if (field & F_MODE) {
- if (doit)
- printf("%s ", permissions(f));
- else
- width+= (field & F_EXTRA) ? 5 : 11;
- }
- if (field & F_EXTRA) {
- p= cxsize(f);
- n= strlen(p)+1;
-
- if (doit) {
- n= sizwidth[col] - n;
- while (n > 0) { putchar(' '); --n; }
- printf("%s ", p);
- } else
- width+= maxise(&sizwidth[col], n);
- }
- if (field & F_LONG) {
- if (doit) {
- printf("%2d %-8s ", f->nlink, uidname(f->uid));
- if (field & F_GROUP) printf("%-8s ", gidname(f->gid));
-
- switch (f->mode & S_IFMT) {
- case S_IFBLK:
- case S_IFCHR:
-#ifdef S_IFMPB
- case S_IFMPB:
-#endif
-#ifdef S_IFMPC
- case S_IFMPC:
-#endif
- printf("%3d, %3d ",
- major(f->rdev), minor(f->rdev));
- break;
- default:
- printf("%8ld ", (long) f->size);
- }
- printf("%s ", timestamp(f));
- } else
- width += (field & F_GROUP) ? 43 : 34;
- }
- n= strlen(f->name);
- if (doit) {
- printname(f->name);
- if (mark(f, 1) != 0) n++;
-#ifdef S_IFLNK
- if ((field & F_LONG) && (f->mode & S_IFMT) == S_IFLNK) {
- char *buf;
- int r, didx;
-
- buf= (char *) allocate(((size_t) f->size + 1)
- * sizeof(buf[0]));
- addpath(&didx, f->name);
- r= readlink(path, buf, (int) f->size);
- delpath(didx);
- if (r > 0) buf[r] = 0; else r=1, strcpy(buf, "?");
- printf(" -> ");
- printname(buf);
- free((void *) buf);
- n+= 4 + r;
- }
-#endif
- spaces(namwidth[col] - n);
- } else {
- if (mark(f, 0) != 0) n++;
-#ifdef S_IFLNK
- if ((field & F_LONG) && (f->mode & S_IFMT) == S_IFLNK) {
- n+= 4 + (int) f->size;
- }
-#endif
- width+= maxise(&namwidth[col], n + NSEP);
- maxise(&colwidth[col], width);
- }
-}
-
-int countfiles(struct file *flist)
-/* Return number of files in the list. */
-{
- int n= 0;
-
- while (flist != nil) { n++; flist= flist->next; }
-
- return n;
-}
-
-struct file *filecol[MAXCOLS]; /* filecol[i] is list of files for column i. */
-int nfiles, nlines; /* # files to print, # of lines needed. */
-
-int columnise(struct file *flist, int nplin)
-/* Chop list of files up in columns. Note that 3 columns are used for 5 files
- * even though nplin may be 4, filecol[3] will simply be nil.
- */
-{
- int i, j;
-
- nlines= (nfiles + nplin - 1) / nplin; /* nlines needed for nfiles */
-
- filecol[0]= flist;
-
- for (i=1; i<nplin; i++) { /* Give nlines files to each column. */
- for (j=0; j<nlines && flist != nil; j++) flist= flist->next;
-
- filecol[i]= flist;
- }
-}
-
-int print(struct file *flist, int nplin, int doit)
-/* Try (doit == 0), or really print the list of files over nplin columns.
- * Return true if it can be done in nplin columns or if nplin == 1.
- */
-{
- register struct file *f;
- register int i, totlen;
-
- columnise(flist, nplin);
-
- if (!doit) {
- if (nplin==1 && !(field & F_EXTRA))
- return 1; /* No need to try 1 column. */
-
- for (i=0; i<nplin; i++)
- colwidth[i]= sizwidth[i]= namwidth[i]= 0;
- }
- while (--nlines >= 0) {
- totlen=0;
-
- for (i=0; i<nplin; i++) {
- if ((f= filecol[i]) != nil) {
- filecol[i]= f->next;
- print1(f, i, doit);
- }
- if (!doit && nplin>1) {
- /* See if this line is not too long. */
- totlen+= colwidth[i];
- if (totlen > ncols+NSEP) return 0;
- }
- }
- if (doit) terpri();
- }
- return 1;
-}
-
-enum depth { SURFACE, SURFACE1, SUBMERGED };
-enum state { BOTTOM, SINKING, FLOATING };
-
-void listfiles(struct file *flist, enum depth depth, enum state state)
-/* Main workhorse of ls, it sorts and prints the list of files. Flags:
- * depth: working with the command line / just one file / listing dir.
- * state: How "recursive" do we have to be.
- */
-{
- struct file *dlist= nil, **afl= &flist, **adl= &dlist;
- int nplin;
- static int white = 1; /* Nothing printed yet. */
-
- /* Flush everything previously printed, so new error output will
- * not intermix with files listed earlier.
- */
- fflush(stdout);
-
- if (field != 0 || state != BOTTOM) { /* Need stat(2) info. */
- while (*afl != nil) {
- static struct stat st;
- int r, didx;
-
- addpath(&didx, (*afl)->name);
-
- if ((r= status(path, &st)) < 0
-#ifdef S_IFLNK
- && (status == lstat || lstat(path, &st) < 0)
-#endif
- ) {
- if (depth != SUBMERGED || errno != ENOENT)
- report((*afl)->name);
- delfile(popfile(afl));
- } else {
- setstat(*afl, &st);
- afl= &(*afl)->next;
- }
- delpath(didx);
- }
- }
- sort(&flist);
-
- if (depth == SUBMERGED && (field & (F_BLOCKS | F_LONG)))
- printf("total %ld\n", nblk2k(countblocks(flist)));
-
- if (state == SINKING || depth == SURFACE1) {
- /* Don't list directories themselves, list their contents later. */
- afl= &flist;
- while (*afl != nil) {
- if (((*afl)->mode & S_IFMT) == S_IFDIR) {
- pushfile(adl, popfile(afl));
- adl= &(*adl)->next;
- } else
- afl= &(*afl)->next;
- }
- }
-
- if ((nfiles= countfiles(flist)) > 0) {
- /* Print files in how many columns? */
- nplin= !present('C') ? 1 : nfiles < MAXCOLS ? nfiles : MAXCOLS;
-
- while (!print(flist, nplin, 0)) nplin--; /* Try first */
-
- print(flist, nplin, 1); /* Then do it! */
- white = 0;
- }
-
- while (flist != nil) { /* Destroy file list */
- if (state == FLOATING && (flist->mode & S_IFMT) == S_IFDIR) {
- /* But keep these directories for ls -R. */
- pushfile(adl, popfile(&flist));
- adl= &(*adl)->next;
- } else
- delfile(popfile(&flist));
- }
-
- while (dlist != nil) { /* List directories */
- if (dotflag(dlist->name) != 'a' || depth != SUBMERGED) {
- int didx;
-
- addpath(&didx, dlist->name);
-
- flist= nil;
- if (adddir(&flist, path)) {
- if (depth != SURFACE1) {
- if (!white) putchar('\n');
- printf("%s:\n", path);
- white = 0;
- }
- listfiles(flist, SUBMERGED,
- state == FLOATING ? FLOATING : BOTTOM);
- }
- delpath(didx);
- }
- delfile(popfile(&dlist));
- }
-}
-
-int main(int argc, char **argv)
-{
- struct file *flist= nil, **aflist= &flist;
- enum depth depth;
- char *lsflags;
-#ifdef TIOCGWINSZ
- struct winsize ws;
-#endif
-
- uid= geteuid();
- gid= getegid();
-
- if ((arg0= strrchr(argv[0], '/')) == nil) arg0= argv[0]; else arg0++;
- argv++;
-
- if (strcmp(arg0, "ls") != 0) {
- char *p= arg0+1;
-
- while (*p != 0) {
- if (strchr(arg0flag, *p) != nil) *p += 'A' - 'a';
- p++;
- }
- setflags(arg0+1);
- }
- while (*argv != nil && (*argv)[0] == '-') {
- if ((*argv)[1] == '-' && (*argv)[2] == 0) {
- argv++;
- break;
- }
- setflags(*argv++ + 1);
- }
-
- istty= isatty(1);
-
- if (istty && (lsflags= getenv("LSOPTS")) != nil) {
- if (*lsflags == '-') lsflags++;
- setflags(lsflags);
- }
-
- if (!present('1') && !present('C') && !present('l')
- && (istty || present('M') || present('X') || present('F'))
- ) setflags("C");
-
- if (istty) setflags("q");
-
- if (SUPER_ID == 0 || present('a')) setflags("A");
-
- if (present('i')) field|= F_INODE;
- if (present('s')) field|= F_BLOCKS;
- if (present('M')) field|= F_MODE;
- if (present('X')) field|= F_EXTRA|F_MODE;
- if (present('t')) field|= F_BYTIME;
- if (present('u')) field|= F_ATIME;
- if (present('c')) field|= F_CTIME;
- if (present('l')) {
- field= (field | F_MODE | F_LONG) & ~F_EXTRA;
- if (present('g')) field|= F_GROUP;
- }
- if (present('F')) field|= F_MARK;
- if (present('T')) field|= F_TYPE;
- if (present('d')) field|= F_DIR;
-
-#ifdef S_IFLNK
- status= present('L') ? stat : lstat;
-#endif
-
-#ifdef TIOCGWINSZ
- if (present('C')) {
- int t= istty ? 1 : open("/dev/tty", O_WRONLY);
-
- if (t >= 0 && ioctl(t, TIOCGWINSZ, &ws) == 0 && ws.ws_col > 0)
- ncols= ws.ws_col - 1;
-
- if (t != 1) close(t);
- }
-#endif
-
- depth= SURFACE;
-
- if (*argv == nil) {
- if (!(field & F_DIR)) depth= SURFACE1;
- pushfile(aflist, newfile("."));
- } else {
- if (argv[1] == nil && !(field & F_DIR)) depth= SURFACE1;
-
- do {
- pushfile(aflist, newfile(*argv++));
- aflist= &(*aflist)->next;
- } while (*argv!=nil);
- }
- listfiles(flist, depth,
- (field & F_DIR) ? BOTTOM : present('R') ? FLOATING : SINKING);
- exit(ex);
-}
-/* Kees J. Bot 25-4-89. */
diff --git a/libc/tests/ouch.c b/libc/tests/ouch.c
deleted file mode 100644
index c2925c6..0000000
--- a/libc/tests/ouch.c
+++ /dev/null
@@ -1,27 +0,0 @@
-
-#include <signal.h>
-#include <stdio.h>
-#include <errno.h>
-
-void trap()
-{
- write(1, "Ouch!!\n", 7);
-}
-
-main()
-{
- char buf[2];
- int cc;
-
- signal(SIGINT, trap);
- while( (cc=read(0, buf, 1)) > 0 || (cc == -1 && errno == EINTR) )
- {
- if( cc < 0 )
- fprintf(stderr, "INTR\n");
- else
- fprintf(stderr, "%x\n", buf[0]);
- }
-
-
- write(1, "\nExit!\n", 7);
-}
diff --git a/libc/tests/rand.c b/libc/tests/rand.c
deleted file mode 100644
index c4fc6d2..0000000
--- a/libc/tests/rand.c
+++ /dev/null
@@ -1,16 +0,0 @@
-#include <stdio.h>
-
-FILE * popen();
-
-main()
-{
- FILE * fd = popen("./hd", "w");
- int ch;
-
- srand(time((void*)0));
-
- for(ch=0; ch<256; ch++)
- putc(rand(), fd);
-
- pclose(fd);
-}
diff --git a/libc/tests/size.c b/libc/tests/size.c
deleted file mode 100644
index 2d6676b..0000000
--- a/libc/tests/size.c
+++ /dev/null
@@ -1,51 +0,0 @@
-#include <fcntl.h>
-#include <a.out.h>
-
-void size(filename)
- char *filename;
-{
- int f;
- struct exec ex;
- long total;
- int cc;
-
- if ((f = open(filename, O_RDONLY)) < 0 )
- {
- perror(filename);
- return;
- }
- cc = read(f, &ex, sizeof(ex));
-
- if (cc == sizeof(ex) && !BADMAG(ex))
- {
- total = ex.a_text + ex.a_data + ex.a_bss;
- printf("%-ld\t%-ld\t%-ld\t%-ld\t%-lx\t%s\n",
- ex.a_text, ex.a_data, ex.a_bss, total, total,
- filename);
- }
- else if( cc > 16 && memcmp(&ex, "\243\206\001\000*", 5) == 0 )
- { /* *.o file */
- total = ((unsigned char*)&ex)[9] +
- ((unsigned char*)&ex)[10] * 256;
- printf("\t\t\t%-ld\t%-lx\t%s\n",
- total, total, filename);
- }
- else
- printf("%s: Not an a.out file\n", filename);
- close(f);
-}
-
-int main(argc, argv)
- int argc;
- char **argv;
-{
- if (argc < 2)
- {
- printf("Usage: %s file\n", argv[0]);
- exit(1);
- }
- printf("text\tdata\tbss\tdec\thex\tfilename\n");
- for (--argc, ++argv; argc > 0; --argc, ++argv)
- size(*argv);
- exit(0);
-}
diff --git a/libc/tests/sync.c b/libc/tests/sync.c
deleted file mode 100644
index 03ca096..0000000
--- a/libc/tests/sync.c
+++ /dev/null
@@ -1 +0,0 @@
-int main() { return sync(); }
diff --git a/libc/tests/ucomp.c b/libc/tests/ucomp.c
deleted file mode 100644
index cc3eef8..0000000
--- a/libc/tests/ucomp.c
+++ /dev/null
@@ -1,108 +0,0 @@
-
-/*
- * Uncompress program this is very very fast
- *
- */
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <malloc.h>
-
-#define MAXLEN 255
-
-#define maxno 61000U
-#define USE_BSS
-
-#ifdef USE_BSS
-unsigned char fptr[maxno];
-#else
-unsigned char *fptr;
-#endif
-FILE * fd;
-int key;
-
-main(argc, argv)
-int argc;
-char ** argv;
-{
-#ifndef USE_BSS
- fptr = (unsigned char * ) malloc(maxno);
-
- if( fptr == 0 )
- {
- perror("Cannot allocate memory");
- exit(1);
- }
-#endif
-
- if( argc < 2 )
- {
- fd = stdin;
- key = getc(fd);
- uncompress();
- }
- else
- {
- fd = fopen(argv[1], "r" );
- if( fd == 0 ) { perror("Open failed"); exit(1); }
-
- key = getc(fd);
- uncompress();
- }
-}
-
-/*
-
- Uncompression routine -- v.v.fast
-*/
-
-uncompress()
-{
- register unsigned char * mainscan;
- register unsigned char * secondscan;
- register unsigned char * ptr = (unsigned char * ) fptr;
- register unsigned char * eptr = ptr+maxno;
- register unsigned int len;
- register int ch;
-
- mainscan = ptr;
-
- for(;;)
- {
- ch = getc(fd);
- if(ch == EOF) break;
- ch &= 0xFF;
- if(ch == key)
- {
- ch = getc(fd);
- if( ch == 0 )
- *mainscan++ = key;
- else
- {
- len = (unsigned char) getc(fd);
- if( ch & 0x80 )
- len += ((unsigned char) getc(fd)) << 8;
- secondscan = mainscan - len;
- if(len > mainscan - ptr) secondscan += maxno;
- len = (unsigned char) ch & 0x7F;
- for( ; len>0; len-- )
- {
- *mainscan++ = *secondscan++;
- if( secondscan == eptr ) secondscan = ptr;
- if( mainscan == eptr )
- { write(1, ptr, (int)(mainscan-ptr)); mainscan = ptr; }
- }
- }
- }
- else
- *mainscan++ = ch;
-
- if( mainscan == eptr )
- { write(1, ptr, (int)(mainscan-ptr)); mainscan = ptr; }
- }
- if( mainscan != ptr )
- { write(1, ptr, (int)(mainscan-ptr)); mainscan = ptr; }
-}
-
diff --git a/libc/tests/wc.c b/libc/tests/wc.c
deleted file mode 100644
index 08b93ca..0000000
--- a/libc/tests/wc.c
+++ /dev/null
@@ -1,133 +0,0 @@
-
-#include <stdio.h>
-#include <ctype.h>
-
-int lflag; /* Want count lines */
-int wflag; /* Want count words */
-int cflag; /* Want count characters */
-
-long lcount; /* File count of lines */
-long wcount; /* File count of words */
-long ccount; /* File count of characters */
-
-long ltotal; /* Total count of lines */
-long wtotal; /* Total count of words */
-long ctotal; /* Total count of characters */
-
-int
-main(argc, argv)
-int argc;
-char **argv;
-{
- char *p;
- int ar;
-
- if (argc > 1 && argv[1][0] == '-')
- {
- for (p = argv[1] + 1; *p; p++)
- {
- switch (*p)
- {
- case 'l':
- lflag++;
- break;
- case 'w':
- wflag++;
- break;
- case 'c':
- cflag++;
- break;
- default:
- Usage();
- }
- }
- argc--;
- argv++;
- }
-
- /* If no flags are set, treat as wc -lwc. */
- if (!lflag && !wflag && !cflag)
- lflag = wflag = cflag = 1;
-
- /* No filename, use stdin */
- if (argc == 1)
- {
- count(stdin, "");
- exit(0);
- }
-
- /* There is an explicit list of files. Loop on files. */
- for (ar = 1; ar < argc; ar++)
- {
- FILE *f;
-
- if ((f = fopen(argv[ar], "r")) == NULL)
- fprintf(stderr, "wc: cannot open %s\n", argv[ar]);
- else
- {
- count(f, argv[ar]);
- fclose(f);
- }
- }
-
- if (argc > 2)
- {
- if (lflag)
- printf("%7ld ", ltotal);
- if (wflag)
- printf("%7ld ", wtotal);
- if (cflag)
- printf("%7ld ", ctotal);
- printf("total\n");
- }
- exit(0);
-}
-
-count(f, fname)
-FILE *f;
-char *fname;
-{
- register int c;
- register int inword = 0;
-
- lcount = 0;
- wcount = 0;
- ccount = 0;
-
- while ((c = getc(f)) != EOF)
- {
- ccount++;
-
- if (isspace(c))
- {
- if (inword)
- wcount++;
- inword = 0;
- }
- else
- inword = 1;
-
- if (c == '\n' || c == '\f')
- lcount++;
- }
-
- ltotal += lcount;
- wtotal += wcount;
- ctotal += ccount;
-
- if (lflag)
- printf("%7ld ", lcount);
- if (wflag)
- printf("%7ld ", wcount);
- if (cflag)
- printf("%7ld ", ccount);
- if (fname && *fname)
- printf("%s", fname);
- printf("\n");
-}
-
-Usage()
-{
- fprintf(stderr, "Usage: wc [-lwc] [name ...]\n");
- exit(1);
-}
diff --git a/libc/time/Makefile b/libc/time/Makefile
index d04e5f4..6e95444 100644
--- a/libc/time/Makefile
+++ b/libc/time/Makefile
@@ -2,16 +2,14 @@
# This file is part of the Linux-8086 C library and is distributed
# under the GNU Library General Public License.
-TOP=..
-include $(TOP)/Make.defs
-
OBJ=localtime.o gmtime.o asctime.o ctime.o asc_conv.o tm_conv.o
-all: $(OBJ)
+CFLAGS=$(ARCH) $(CCFLAGS) $(DEFS)
+
+all: $(LIBC)
+ @:
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
+$(LIBC): $(LIBC)($(OBJ))
clean:
rm -f *.o libc.a
diff --git a/libc/utmp/Makefile b/libc/utmp/Makefile
deleted file mode 100644
index 2c88bd2..0000000
--- a/libc/utmp/Makefile
+++ /dev/null
@@ -1,26 +0,0 @@
-# Copyright (C) 1996 Nat Friedman <ndf@aleph1.mit.edu>
-# This file is part of the Linux-8086 C library and is distributed
-# under the GNU Library General Public License.
-
-TOP=..
-include $(TOP)/Make.defs
-
-ifeq ($(LIB_OS),ELKS)
-OBJ=utent.o
-endif
-
-all: $(OBJ)
-
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
-
-%.o:%.c
-ifeq ($(PLATFORM),i386-Linux)
- $(CC) $(CFLAGS) $< -c -o $@ $(WALL)
-else
- $(CC) $(CFLAGS) $< -c -o $@ -ansi
-endif
-
-clean:
- rm -f *.o libc.a