summaryrefslogtreecommitdiff
path: root/libc
diff options
context:
space:
mode:
authorRobert de Bath <rdebath@poboxes.com>1996-05-31 21:33:17 +0200
committerLubomir Rintel <lkundrak@v3.sk>2013-10-23 23:30:46 +0200
commite85ee07172eccafd9441362e774f7b184810d008 (patch)
tree5dc12259ab7a61b12d9df284fe58ad5cb312c526 /libc
parentdcc973ea3e31710429858c99d4f040334ac67c06 (diff)
downloaddev86-e85ee07172eccafd9441362e774f7b184810d008.tar.gz
Import Dev86-0.0.6.tar.gzv0.0.6
Diffstat (limited to 'libc')
-rw-r--r--libc/Changes130
-rw-r--r--libc/Make.defs10
-rw-r--r--libc/Makefile2
-rw-r--r--libc/README14
-rw-r--r--libc/TODO9
-rw-r--r--libc/include/bsd/bsd.h49
-rw-r--r--libc/include/bsd/errno.h9
-rw-r--r--libc/include/bsd/sgtty.h113
-rw-r--r--libc/include/bsd/signal.h25
-rw-r--r--libc/include/bsd/stdlib.h12
-rw-r--r--libc/include/bsd/sys/ttychars.h3
-rw-r--r--libc/include/bsd/tzfile.h10
-rw-r--r--libc/include/bsd/unistd.h4
-rw-r--r--libc/include/paths.h1
-rw-r--r--libc/include/sgtty.h1
-rw-r--r--libc/include/stdarg.h5
-rw-r--r--libc/include/sys/resource.h73
-rw-r--r--libc/include/sys/stat.h4
-rw-r--r--libc/include/sys/time.h1
-rw-r--r--libc/include/sys/wait.h77
-rw-r--r--libc/include/sys/x3
-rw-r--r--libc/include/termios.h4
-rw-r--r--libc/kinclude/Makefile5
-rw-r--r--libc/kinclude/arch/types.h4
-rw-r--r--libc/kinclude/linuxmt/stat.h4
-rw-r--r--libc/kinclude/linuxmt/termios.h8
-rw-r--r--libc/kinclude/linuxmt/types.h2
-rw-r--r--libc/libc.abin74344 -> 78644 bytes
-rw-r--r--libc/misc/cputype.c145
-rw-r--r--libc/msdos/Makefile6
-rw-r--r--libc/msdos/i86.c32
-rw-r--r--libc/msdos/msdos.c75
-rw-r--r--libc/stdio1/BUGS15
-rw-r--r--libc/stdio1/Config3
-rw-r--r--libc/stdio1/Makefile36
-rw-r--r--libc/stdio1/NOTICE17
-rw-r--r--libc/stdio1/README13
-rw-r--r--libc/stdio1/TODO33
-rw-r--r--libc/stdio1/__ffillbuf.c55
-rw-r--r--libc/stdio1/__stdio_init.c66
-rw-r--r--libc/stdio1/fclose.c41
-rw-r--r--libc/stdio1/fcntl.h72
-rw-r--r--libc/stdio1/fflush.c36
-rw-r--r--libc/stdio1/fgetc.c39
-rw-r--r--libc/stdio1/fgets.c50
-rw-r--r--libc/stdio1/fopen.c80
-rw-r--r--libc/stdio1/fputc.c53
-rw-r--r--libc/stdio1/fputs.c32
-rw-r--r--libc/stdio1/idealgetline.c67
-rw-r--r--libc/stdio1/old_printf.c230
-rw-r--r--libc/stdio1/printf.c649
-rw-r--r--libc/stdio1/puts.c26
-rw-r--r--libc/stdio1/scanf.c151
-rw-r--r--libc/stdio1/stdio.h135
-rwxr-xr-xlibc/stdio1/test.sh12
-rw-r--r--libc/stdio2/Makefile2
-rw-r--r--libc/stdio2/stdio.c28
-rw-r--r--libc/syscall/Makefile7
-rw-r--r--libc/syscall/execve.c94
-rw-r--r--libc/syscall/signal.c5
-rw-r--r--libc/syscall/syscall.dat57
-rw-r--r--libc/syscall/syslibc.c39
-rw-r--r--libc/termios/Makefile2
-rw-r--r--libc/termios/termios.c39
64 files changed, 838 insertions, 2186 deletions
diff --git a/libc/Changes b/libc/Changes
deleted file mode 100644
index 3066545..0000000
--- a/libc/Changes
+++ /dev/null
@@ -1,130 +0,0 @@
-# Copyright (C) 1995,1996 Robert de Bath <rdebath@cix.compulink.co.uk>
-# This file is part of the Linux-8086 C library which is distributed
-# under the GNU Library General Public License.
-
-If you make any changes please put a little note here. -RDB
-
--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
-
------ Mar 21 '96 - RDB
-Add -Md -Mf flags to bcc.c
-corrected oops on ../Makefile
-Changes to READMEs
------ Mar 18 '96 - RDB
-Re-written to wetware storage "Robert must remember to fill in changes!"
-Ok, there's now some makefiles in the directory above for creating an
-environment with cleanup of bcc/as/ld makefiles and new home for bcc files.
-My version of a standard I/O package has been added, I've split the
-output libs for Linux-86 and MSDOS.
-A couple of functions (including reboot) added to elksemu.
------ Mar 3 '96 - RDB
-open/close in doselks
------ Feb 25 '96 - RDB
-iota.c - oops -ve numbers give infinite loop
-altered a.out.h changed size of n_name from 8 to 24, ld needs recompile,
-dis88 bombed (bad malloc), nm etc will need to know.
-added popen, pclose, system
------ Feb 24 '96 - RDB
-Problem with __lseek syscall, was trying to return a long - no way jose
-Little change to malloc1/* if you #define __MINI_MALLOC__ (used in LIB)
-a _much_ smaller but more limited version of malloc is used.
-Added assert.h - no __assert() in lib yet.
-Added in printf c/o Steven Huang <sthuang@hns.com>.
-ELKSemu; added -Wall, cleaned up mess.
------ Feb 23 '96 - RDB
-Release 0.0.3, bump version to 0.0.4
------ Feb 18 '96 - RDB
-ELKSemu signals now seem to be working.
-ELKSemu; Added symlinks
-ELKSemu; Added opendir support
-ELKSemu; now runs as ELF executable
-Added exec* functions except exec*p ones
-Small cleanup of doselks.
-Start final checks for 0.0.3
------ Feb 16 '96 - RDB
-I do _NOT_ believe this - sbrk() yet again!! RIGHT! This time it WILL work!!
-Groan! There was no problem with sbrk, it was elksemu :-( fixed!
------ Feb 12 '96 - RDB
-Yet another problem with sbrk() return val wrong! - FIXed
-Alter elksemu change in way *_tab.v files work.
------ Feb 11 '96 - RDB
-Fix on strchr (asm86) - SI not saved
-First cut at opendir/readdir/closedir
-Move in ar.h
-add in 'make config' - (split malloc's and options for stdio packages)
-Merge in Nat's grp and other pieces.
-ELKSemu; Little i386 kernel patch, i8086 programs now run transparently :-)
------ Feb 10 '96 - RDB
-Found a _nasty_ bug with atexit; the actual problem was in cstartup but ...
------ Feb 4 '96 - RDB
-Corrected minor problem in atexit/on_exit
------ Jan 28 '96 - RDB
-Debug, execve in libc _and_ elksemu
-perror added
------ Jan 27 '96 - RDB
-Debug pwd, pw_fd was static
-Started modifing syscall.dat, adjusting elksemu to match.
------ Jan 21 '96 - RDB
-Altered fflush to test return status. Corrected porting bug in printf.c
------ Jan 20 '96 - RDB
-Imported printf from the 'DLibs' library, I've now found the rest of the
-Dlibs stdio, it appears to be very ST specific tho :-(
-NB: This is not in the dist, still sending out Joel's
------ Jan 19 '96 - RDB
-Making some test alterations to stdio.
-Made ungetc into function, removed ungetc specific structure items
-Altered putc() to micro-macro.
------ Jan 16 '96 - RDB
-Added in patches from Nat, corrected minor oops in misc/alias.c
------ Jan 11 '96 - RDB
-Final checks, release version 0.0.2
------ Jan 9 '96 - RDB
-Added 'signal' function.
-Added 'setjmp' Is it right for SI & DI to be saved ?
------ Jan 8 '96 - RDB
-Added various MS-DOS functions, COM files are now starting to be able to
-do something useful.
------ Jan 7 '96 - RDB
-Added the 'New_subdir' script.
-Now YOU (Yes I mean you reading this!) can use it :-)
------ Jan 6 '96 - RDB
-Problem with sbrk() shown up by Joel's malloc, the error checks failed if
-you were allocating big blocks, fixed.
------ Jan 6 '96 - RDB
-Added in Joel's malloc routine after a solid hack to actually debug it
-it seems to work now but I haven't really tested it; I can't do it under
-x386 Linux as something tried to link in 'realloc' too.
------ Jan 5 '96 - RDB
-Ok, I've messed around and joined in Joel's stdio.h routines
------ Jan 3 '96 - RDB
-(This is a good idea, dates, Always overlook the little things, ho hum!)
------ - RDB
-Added 'movedata' function like MSC version to string/string.h
------ - RDB
-Added support for the -C-f and -C-c options of BCC. BUT note for the moment
-the string functions degenerate to the C versions for -C-f
------ - RDB
-Added getenv/putenv
------ - RDB
-Changed crt0.c. It now only jmps to ___cstartup. This is so the same crt0
-can be used for both DOS and Linux, only the libc needs to be changed.
-Cost is 4 bytes at the start of the exe.
------ - RDB
-Added support for automatic calling of functions before main. (See Pre_main)
-Added support for atexit() and onexit() functions.
------ - RDB
-Added fast strchr
-Altered strstr to use strchr.
------ - RDB
-Added cputype function - CPU detector.
------ - RDB
-Dec 12 95
-Just completed a working debugged malloc set _including_ a 'fake' alloca
-function. (The assembler version will not work for BCC) It's a classical
-algorthm so may be slow in some cases. I had a look at the GNU malloc ...
-erm ... I _think_ I see what they're doing! :-)
------ - RDB
-Added tiny printf, to be replaced by Joel.
-Added HP-UX long->ascii function.
------ - RDB
-Split off brk/sbrk etc into own file. Asm alloca not compiled.
diff --git a/libc/Make.defs b/libc/Make.defs
index 3cee160..1cf9b30 100644
--- a/libc/Make.defs
+++ b/libc/Make.defs
@@ -18,7 +18,7 @@ endif
VERMAJOR=0
VERMINOR=0
-VERPATCH=5
+VERPATCH=6
VER=$(VERMAJOR).$(VERMINOR).$(VERPATCH)
LIBDEFS=-D__LIBC__
@@ -28,18 +28,18 @@ ifneq ($(PLATFORM),i386-Linux)
# Normal standard 8086 code
ifeq ($(PLATFORM),i86-ELKS)
-ARCH=-0
+ARCH=
endif
# 8086 elks code With "Caller saves" and "First arg in AX"
ifeq ($(PLATFORM),i86-FAST)
-ARCH=-0 -Mf
+ARCH=-Mf
LIBC=libc_f.a
endif
# MSDOS COM file (msdos libs don't support "First arg in AX")
ifeq ($(PLATFORM),i86-DOS)
-ARCH=-0 -Md
+ARCH=-Md
LIBC=libdos.a
endif
@@ -49,7 +49,7 @@ ARCH=-3
endif
CC=bcc $(ARCH)
-CCFLAGS=-O -I -I$(TOP)/include
+CCFLAGS=-I -I$(TOP)/include # -O
LKFLAGS=-L -L$(TOP)/ -s
else # ifeq ($(PLATFORM),i386-Linux)
diff --git a/libc/Makefile b/libc/Makefile
index 41fd68d..0076f8b 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -9,7 +9,7 @@ SRC=crt0.c
OBJ=crt0.o
TARGETS=$(OBJ) $(LIBC)
-TXT=Makefile Make.defs README TODO KERNEL COPYING Changes Contributors MAGIC \
+TXT=Makefile Make.defs README TODO KERNEL COPYING Contributors MAGIC \
New_subdir Pre_main Config_sh
all: .config.lst $(TARGETS)
diff --git a/libc/README b/libc/README
index 2b4bbdc..feb6e4a 100644
--- a/libc/README
+++ b/libc/README
@@ -1,10 +1,3 @@
-
-This is the README for libc-8086-0.0.4.tar.gz
-Robert de Bath, 21/Mar/96, rdebath@cix.compulink.co.uk
-
-The lib is now positivly plump, there's a new standard IO package, passwd,
-group, utmp, crypt and lots of other pieces.
-
The lib can be compiled five different ways for Linux-8086 standard,
Linux-8086 with 'First arg in AX', MS-DOS, BCC-386 or for GNU-386. At
the moment the 386 versions are missing some _very_ important bits.
@@ -16,13 +9,13 @@ an so on.
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.
-For this lib you should use the same version of elksemu (0.0.4).
+For this lib you should use the same version of elksemu.
The system call table will only be frozen when the linux-86 kernel is
running and reasonably stable.
THE COMPILER
You should use the versions of bcc, unproto, as86, ld86 and elksemu that
-are in version 0.0.4 combined development environment. Some other
+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 and looks in the wrong place for
@@ -59,8 +52,7 @@ Directory structure:
Make config will look in all subdirectories for a file 'Config'
any it finds will be displayed and can be used to switch a directory
- on or off by renaming Makefile<->makefile.
- (This seemed like a good idea, I'm not so sure now ...)
+ on or off.
The exit(rv) function is already defined. It will call the contents
of the function pointer (*__cleanup)() before it calls _exit();
diff --git a/libc/TODO b/libc/TODO
index 83e1a4e..f6baaa0 100644
--- a/libc/TODO
+++ b/libc/TODO
@@ -17,21 +17,14 @@ hsearch &co -
tsearch &co -
locale processing - multi national, unicode (string stuff has a couple
of stubs)
-login - getpass and friends - Some, rest soon.
rpc -
-syslog &co - make stubs to splatter to console.
time calcs - mktime gmtime localtime etc, Nat
timezone - Probably V simplistic, List of UTC's
offsets & STDvDST
i386 support - For both GCC and BCC-386.
-Stdio - Joel is on this. (stdio1) (RDB stdio2)
-getgrent &co - Nat -Done
-getpwent &co - Nat -Done
-utmp/wtmp - Nat -Done
-setjmp - Done, Rob
shadow password - Do we need ? Do we want :-) [No! Ick! ;) -Nat]
-termcap - and curses; what does ncurses need ? (150kb!!)
+curses - What does ncurses need ? (150kb!!)
crypt - TEA version, first cut.
signal stuff - Got a basic 'signal' appears to work correctly.
getenv/setenv - Done
diff --git a/libc/include/bsd/bsd.h b/libc/include/bsd/bsd.h
new file mode 100644
index 0000000..5ab1173
--- /dev/null
+++ b/libc/include/bsd/bsd.h
@@ -0,0 +1,49 @@
+/* bsd.h - simplify porting BSD programs to Linux - rick sladkey */
+
+/* make sure BSD features are enabled, i.e. __USE_BSD and _FAVOR_BSD */
+
+/* cpp in gcc 2.3.3 is broken.
+#ifndef _BSD_BSD_H
+#define _BSD_BSD_H
+*/
+
+#define _BSD_SOURCE 1
+#include <features.h>
+#include <endian.h>
+
+/* some BSD progs expect MIN and MAX to be defined */
+
+#define MIN(a, b) ((a) < (b) ? (a) : (b))
+#define MAX(a, b) ((a) > (b) ? (a) : (b))
+
+/* make sure we get L_SET and L_INCR, which is in a different place */
+
+#include <sys/file.h>
+
+/* BSD has slight non-POSIX names (and meanings :-) for some things */
+
+#define FAPPEND O_APPEND
+
+#include <limits.h>
+
+/* (absolute) max # characters in exec arglist */
+
+#define NCARGS ARG_MAX
+
+/* ftpd uses this as bits per byte, I don't know why it's called NBBY */
+
+#define NBBY CHAR_BIT
+
+/* gloss over slight differences between BSD direct and POSIX dirent */
+
+#define d_namlen d_reclen
+
+#if 0
+
+/* See <bsd/signal.h> */
+
+typedef void sig_t;
+
+#endif
+
+/* #endif _BSD_BSD_H */
diff --git a/libc/include/bsd/errno.h b/libc/include/bsd/errno.h
new file mode 100644
index 0000000..c2d464e
--- /dev/null
+++ b/libc/include/bsd/errno.h
@@ -0,0 +1,9 @@
+/* make sure EWOULDBLOCK doesn't screw us up */
+#ifndef _BSD_ERRNO_H
+#define _BSD_ERRNO_H
+
+#include_next <errno.h>
+#undef EWOULDBLOCK
+#define EWOULDBLOCK EAGAIN
+
+#endif /* _BSD_ERRNO_H */
diff --git a/libc/include/bsd/sgtty.h b/libc/include/bsd/sgtty.h
new file mode 100644
index 0000000..4e21901
--- /dev/null
+++ b/libc/include/bsd/sgtty.h
@@ -0,0 +1,113 @@
+/* sgtty.h */
+
+/* This file contains defintions to help make linux termios look like
+ bsd sgtty. */
+
+/* Copyright (c) 1992 Ross Biro
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public
+License as published by the Free Software Foundation; either
+version 2 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with this library; if not, write to the Free
+Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+
+#ifndef _BSD_SGTTY_H
+#define _BSD_SGTTY_H
+
+#include <termios.h>
+
+#define TIOCGETP 0x5481
+#define TIOCSETP 0x5482
+#define TIOCGETC 0x5483
+#define TIOCSETC 0x5484
+#define TIOCGLTC 0x5485
+#define TIOCSLTC 0x5486
+#define TIOCLGET 0x5487
+#define TIOCLSET 0x5488
+#define TIOCFLUSH 0x5489
+#define TIOCSETN 0x548a
+
+struct sgttyb
+{
+ unsigned short sg_flags;
+ char sg_ispeed;
+ char sg_ospeed;
+ char sg_erase;
+ char sg_kill;
+ struct termios t;
+ int check;
+};
+
+struct tchars
+{
+ char t_intrc;
+ char t_quitc;
+ char t_eofc;
+ char t_startc;
+ char t_stopc;
+ char t_brkc;
+};
+
+struct ltchars
+{
+ char t_werasc;
+ char t_suspc;
+ char t_dsuspc;
+ char t_rprntc;
+ char t_flushc;
+ char t_lnextc;
+};
+
+#define O_RAW 1
+#define O_LCASE 2
+#define O_CRMOD 4
+#define O_ECHO 8
+#define O_ODDP 16
+#define O_EVENP 32
+#define O_CBREAK 64
+/* these don't do anything yet. */
+#define O_TBDELAY 0
+#define O_LLITOUT 0
+#define O_XTABS 0
+#define O_ANYP 0
+
+#ifndef _SGTTY_SOURCE
+
+#undef ioctl
+#define ioctl bsd_ioctl
+
+#undef RAW
+#define RAW O_RAW
+#undef LCASE
+#define LCASE O_LCASE
+#undef ECHO
+#define ECHO O_ECHO
+#undef CRMOD
+#define CRMOD O_CRMOD
+#undef ODDP
+#define ODDP O_ODDP
+#undef EVENP
+#define EVENP O_EVENP
+#undef CBREAK
+#define CBREAK O_CBREAK
+#undef TBDELAY
+#define TBDELAY O_TBDELAY
+#undef LLITOUT
+#define LLITOUT O_LLITOUT
+#undef XTABS
+#define XTABS O_XTABS
+#undef ANYP
+#define ANYP O_ANYP
+#endif
+
+#endif /* _BSD_SGTTY_H */
diff --git a/libc/include/bsd/signal.h b/libc/include/bsd/signal.h
new file mode 100644
index 0000000..24d4502
--- /dev/null
+++ b/libc/include/bsd/signal.h
@@ -0,0 +1,25 @@
+#ifndef _BSD_SIGNAL_H
+#define _BSD_SIGNAL_H
+
+/* make sure we get BSD style signals (that don't need to be reset) */
+
+#define __USE_BSD_SIGNAL
+#include_next <signal.h>
+
+/* use rough approximation of sigaction to sigvec, not completely safe! */
+
+#define sigvec sigaction
+#define sv_mask sa_mask
+#define sv_flags sa_flags
+#define sv_handler sa_handler
+#define sv_onstack sa_mask /* ouch, this one really hurts */
+
+/* BSD uses some non-POSIX signals without ifdefs */
+
+#define SIGSYS SIGUNUSED
+
+/* BSD wants this typedef for signal handlers */
+
+#define sig_t __sighandler_t
+
+#endif /* _BSD_SIGNAL_H */
diff --git a/libc/include/bsd/stdlib.h b/libc/include/bsd/stdlib.h
new file mode 100644
index 0000000..20d34f9
--- /dev/null
+++ b/libc/include/bsd/stdlib.h
@@ -0,0 +1,12 @@
+/* some things shouldn't be macros, get out your barf bag */
+
+#ifndef _BSD_STDLIB_H
+#define _BSD_STDLIB_H
+
+#undef __MALLOC_0_RETURNS_NULL
+#define __MALLOC_0_RETURNS_NULL
+#include_next <stdlib.h>
+#undef atoi
+#undef atol
+
+#endif /* _BSD_STDLIB_H */
diff --git a/libc/include/bsd/sys/ttychars.h b/libc/include/bsd/sys/ttychars.h
new file mode 100644
index 0000000..b3a2036
--- /dev/null
+++ b/libc/include/bsd/sys/ttychars.h
@@ -0,0 +1,3 @@
+#ifndef _BSD_SYS_TTYCHARS_H
+#define _BSD_SYS_TTYCHARS_H
+#endif /* _BSD_SYS_TTYCHARS_H */
diff --git a/libc/include/bsd/tzfile.h b/libc/include/bsd/tzfile.h
new file mode 100644
index 0000000..459a603
--- /dev/null
+++ b/libc/include/bsd/tzfile.h
@@ -0,0 +1,10 @@
+#ifndef _BSD_TZFILE_H
+#define _BSD_TZFILE_H
+
+#define SECSPERDAY (60*60*24)
+#define DAYSPERNYEAR 365
+#define DAYSPERLYEAR 366
+
+#define isleap(y) (((y) % 4) == 0 && ((y) % 100) != 0 || ((y) % 400) == 0)
+
+#endif /* _BSD_TZFILE_H */
diff --git a/libc/include/bsd/unistd.h b/libc/include/bsd/unistd.h
new file mode 100644
index 0000000..20c2ccc
--- /dev/null
+++ b/libc/include/bsd/unistd.h
@@ -0,0 +1,4 @@
+#include_next <unistd.h>
+#include <sys/time.h>
+#include <fcntl.h>
+#include <sys/stat.h>
diff --git a/libc/include/paths.h b/libc/include/paths.h
index 58bade7..dc76939 100644
--- a/libc/include/paths.h
+++ b/libc/include/paths.h
@@ -13,6 +13,7 @@
#define _PATH_WTMP "/var/log/wtmp"
#define _PATH_DEFPATH "/bin:/usr/bin:/usr/local/bin:."
#define _PATH_DEV "/dev/"
+#define _PATH_DEVNULL "/dev/null"
#define _PATH_TMP "/tmp/"
#define _PATH_LASTLOG "/var/log/lastlog"
#define _PATH_LOCALE "/usr/lib/locale"
diff --git a/libc/include/sgtty.h b/libc/include/sgtty.h
deleted file mode 100644
index 9e26956..0000000
--- a/libc/include/sgtty.h
+++ /dev/null
@@ -1 +0,0 @@
-#include <termios.h>
diff --git a/libc/include/stdarg.h b/libc/include/stdarg.h
index 978529b..d30fbd8 100644
--- a/libc/include/stdarg.h
+++ b/libc/include/stdarg.h
@@ -24,6 +24,9 @@
* verify that the stdarg.h file has been set up correctly.
*/
+#ifndef __STDARG_H
+#define __STDARG_H
+
#ifdef sparc
# define _VA_ALIST_ "__builtin_va_alist"
typedef char *va_list;
@@ -36,3 +39,5 @@
# define va_arg(ap, type) ((type *) (ap += sizeof(type)))[-1]
# define va_end(ap)
#endif
+
+#endif /* __STDARG_H */
diff --git a/libc/include/sys/resource.h b/libc/include/sys/resource.h
new file mode 100644
index 0000000..19ed06f
--- /dev/null
+++ b/libc/include/sys/resource.h
@@ -0,0 +1,73 @@
+/*
+ * Resource control/accounting header file for linux-86
+ */
+
+#ifndef _SYS_RESOURCE_H
+#define _SYS_RESOURCE_H
+
+#include <features.h>
+#include <sys/time.h>
+#include <limits.h>
+
+#define RUSAGE_SELF 0
+#define RUSAGE_CHILDREN (-1)
+#define RUSAGE_BOTH (-2) /* sys_wait4() uses this */
+
+struct rusage {
+ struct timeval ru_utime; /* user time used */
+ struct timeval ru_stime; /* system time used */
+ long ru_maxrss; /* maximum resident set size */
+ long ru_ixrss; /* integral shared memory size */
+ long ru_idrss; /* integral unshared data size */
+ long ru_isrss; /* integral unshared stack size */
+ long ru_minflt; /* page reclaims */
+ long ru_majflt; /* page faults */
+ long ru_nswap; /* swaps */
+ long ru_inblock; /* block input operations */
+ long ru_oublock; /* block output operations */
+ long ru_msgsnd; /* messages sent */
+ long ru_msgrcv; /* messages received */
+ long ru_nsignals; /* signals received */
+ long ru_nvcsw; /* voluntary context switches */
+ long ru_nivcsw; /* involuntary " */
+};
+
+#define RLIM_INFINITY ((long)(~0UL>>1))
+
+struct rlimit {
+ long rlim_cur;
+ long rlim_max;
+};
+
+#define PRIO_MIN (-20)
+#define PRIO_MAX 20
+
+#define PRIO_PROCESS 0
+#define PRIO_PGRP 1
+#define PRIO_USER 2
+
+#define RLIMIT_CPU 0 /* CPU time in ms */
+#define RLIMIT_FSIZE 1 /* Maximum filesize */
+#define RLIMIT_DATA 2 /* max data size */
+#define RLIMIT_STACK 3 /* max stack size */
+#define RLIMIT_CORE 4 /* max core file size */
+#define RLIMIT_RSS 5 /* max resident set size */
+#define RLIMIT_NPROC 6 /* max number of processes */
+#define RLIMIT_NOFILE 7 /* max number of open files */
+#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */
+
+#define RLIM_NLIMITS 9
+
+extern int getrlimit __P ((int __resource,
+ struct rlimit *__rlp));
+extern int setrlimit __P ((int __resource,
+ __const struct rlimit *__rlp));
+
+extern int getpriority __P((int __which, int __who));
+extern int setpriority __P((int __which, int __who,
+ int __prio));
+
+extern int __getrusage __P ((int __who, struct rusage *__rusage));
+extern int getrusage __P ((int __who, struct rusage *__rusage));
+
+#endif /* _SYS_RESOURCE_H */
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 4a4bdbd..b8c5ee0 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -24,4 +24,8 @@ int stat __P((__const char * __path, struct stat * __statbuf));
int lstat __P((__const char * __path, struct stat * __statbuf));
int fstat __P((int __fd, struct stat * __statbuf));
+/* hysterical raisins */
+#define S_IREAD S_IRUSR /* read permission, owner */
+#define S_IWRITE S_IWUSR /* write permission, owner */
+#define S_IEXEC S_IXUSR /* execute/search permission, owner */
#endif
diff --git a/libc/include/sys/time.h b/libc/include/sys/time.h
new file mode 100644
index 0000000..91fd187
--- /dev/null
+++ b/libc/include/sys/time.h
@@ -0,0 +1 @@
+#include <time.h>
diff --git a/libc/include/sys/wait.h b/libc/include/sys/wait.h
index 70a0e4a..566aac7 100644
--- a/libc/include/sys/wait.h
+++ b/libc/include/sys/wait.h
@@ -1,2 +1,77 @@
-/** FIXME **/
+#ifndef _SYS_WAIT_H
+#define _SYS_WAIT_H
+
+#include <features.h>
+
+/* Bits in the third argument to `waitpid'. */
+#define WNOHANG 1 /* Don't block waiting. */
+#define WUNTRACED 2 /* Report status of stopped children. */
+
+/* Everything extant so far uses these same bits. */
+/* If WIFEXITED(STATUS), the low-order 8 bits of the status. */
+#define WEXITSTATUS(status) (((status) & 0xff00) >> 8)
+
+/* If WIFSIGNALED(STATUS), the terminating signal. */
+#define WTERMSIG(status) ((status) & 0x7f)
+
+/* If WIFSTOPPED(STATUS), the signal that stopped the child. */
+#define WSTOPSIG(status) WEXITSTATUS(status)
+
+/* Nonzero if STATUS indicates normal termination. */
+#define WIFEXITED(status) (((status) & 0xff) == 0)
+
+/* Nonzero if STATUS indicates termination by a signal. */
+#define WIFSIGNALED(status) (((unsigned int)((status)-1) & 0xFFFF) < 0xFF)
+
+/* Nonzero if STATUS indicates the child is stopped. */
+#define WIFSTOPPED(status) (((status) & 0xff) == 0x7f)
+
+/* Nonzero if STATUS indicates the child dumped core. */
+#define WCOREDUMP(status) ((status) & 0200)
+
+/* Macros for constructing status values. */
+#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
+#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
+
+/* Wait for a child to die. When one does, put its status in *STAT_LOC
+ and return its process ID. For errors, return (pid_t) -1. */
+extern pid_t wait __P ((__WAIT_STATUS __stat_loc));
+
+/* Special values for the PID argument to `waitpid' and `wait4'. */
+#define WAIT_ANY (-1) /* Any process. */
+#define WAIT_MYPGRP 0 /* Any process in my process group. */
+
+/* Wait for a child matching PID to die.
+ If PID is greater than 0, match any process whose process ID is PID.
+ If PID is (pid_t) -1, match any process.
+ If PID is (pid_t) 0, match any process with the
+ same process group as the current process.
+ If PID is less than -1, match any process whose
+ process group is the absolute value of PID.
+ If the WNOHANG bit is set in OPTIONS, and that child
+ is not already dead, return (pid_t) 0. If successful,
+ return PID and store the dead child's status in STAT_LOC.
+ Return (pid_t) -1 for errors. If the WUNTRACED bit is
+ set in OPTIONS, return status for stopped children; otherwise don't. */
+
+extern pid_t waitpid __P ((pid_t __pid, int *__stat_loc,
+ int __options));
+
+/* This being here makes the prototypes valid whether or not
+ we have already included <sys/resource.h> to define `struct rusage'. */
+struct rusage;
+
+/* Wait for a child to exit. When one does, put its status in *STAT_LOC and
+ return its process ID. For errors return (pid_t) -1. If USAGE is not
+ nil, store information about the child's resource usage there. If the
+ WUNTRACED bit is set in OPTIONS, return status for stopped children;
+ otherwise don't. */
+extern pid_t wait3 __P ((__WAIT_STATUS __stat_loc,
+ int __options, struct rusage * __usage));
+
+/* PID is like waitpid. Other args are like wait3. */
+extern pid_t wait4 __P ((pid_t __pid, __WAIT_STATUS __stat_loc,
+ int __options, struct rusage *__usage));
+
+#endif /* sys/wait.h */
diff --git a/libc/include/sys/x b/libc/include/sys/x
new file mode 100644
index 0000000..edb5794
--- /dev/null
+++ b/libc/include/sys/x
@@ -0,0 +1,3 @@
+#define S_IREAD S_IRUSR /* read permission, owner */
+#define S_IWRITE S_IWUSR /* write permission, owner */
+#define S_IEXEC S_IXUSR /* execute/search permission, owner */
diff --git a/libc/include/termios.h b/libc/include/termios.h
index 4ca1ec8..604e654 100644
--- a/libc/include/termios.h
+++ b/libc/include/termios.h
@@ -5,8 +5,8 @@
#include <sys/types.h>
#include <linuxmt/termios.h>
-extern int cfgetispeed __P ((struct termios *__termios_p));
-extern int cfgetospeed __P ((struct termios *__termios_p));
+extern speed_t cfgetispeed __P ((struct termios *__termios_p));
+extern speed_t cfgetospeed __P ((struct termios *__termios_p));
extern int cfsetispeed __P ((struct termios *__termios_p, speed_t __speed));
extern int cfsetospeed __P ((struct termios *__termios_p, speed_t __speed));
diff --git a/libc/kinclude/Makefile b/libc/kinclude/Makefile
index 79dd5c2..83d05ed 100644
--- a/libc/kinclude/Makefile
+++ b/libc/kinclude/Makefile
@@ -15,4 +15,9 @@ transfer:
-@rm -f ../include/linuxmt
ln -s ../kinclude/linuxmt ../include
+# This is for use once linuxmt's syscall interface really gets working.
+real_transfer:
+ -@rm -f ../include/linuxmt
+ cd ../include ; ln -s ../../linuxmt/include/linuxmt .
+
clean:
diff --git a/libc/kinclude/arch/types.h b/libc/kinclude/arch/types.h
index d6690d1..b77ad8e 100644
--- a/libc/kinclude/arch/types.h
+++ b/libc/kinclude/arch/types.h
@@ -1,7 +1,7 @@
/* arch/i86/include/asm/types.h - Basic Linux/MT data types. */
-#ifndef LINUXMT_8086_TYPES
-#define LINUXMT_8086_TYPES
+#ifndef __LINUXMT_8086_TYPES
+#define __LINUXMT_8086_TYPES
/* First we define all of the __u and __s types...*/
diff --git a/libc/kinclude/linuxmt/stat.h b/libc/kinclude/linuxmt/stat.h
index 0eb1c0e..48256a5 100644
--- a/libc/kinclude/linuxmt/stat.h
+++ b/libc/kinclude/linuxmt/stat.h
@@ -1,5 +1,5 @@
-#ifndef _LINUX_STAT_H
-#define _LINUX_STAT_H
+#ifndef __LINUXMT_STAT_H
+#define __LINUXMT_STAT_H
#ifdef __KERNEL__
diff --git a/libc/kinclude/linuxmt/termios.h b/libc/kinclude/linuxmt/termios.h
index 52bde9a..2aff58a 100644
--- a/libc/kinclude/linuxmt/termios.h
+++ b/libc/kinclude/linuxmt/termios.h
@@ -1,5 +1,5 @@
-#ifndef _LINUXMT_TERMIOS_H
-#define _LINUXMT_TERMIOS_H
+#ifndef __LINUXMT_TERMIOS_H
+#define __LINUXMT_TERMIOS_H
#include <linuxmt/types.h>
/* This is just a magic number to make these relatively unique ('T') */
@@ -255,4 +255,6 @@ struct termios {
#define N_MOUSE 2
#define N_PPP 3
-#endif /* _LINUXMT_TERMIOS_H */
+#define _POSIX_VDISABLE '\0'
+
+#endif /* __LINUXMT_TERMIOS_H */
diff --git a/libc/kinclude/linuxmt/types.h b/libc/kinclude/linuxmt/types.h
index 437d985..785d250 100644
--- a/libc/kinclude/linuxmt/types.h
+++ b/libc/kinclude/linuxmt/types.h
@@ -21,7 +21,7 @@ typedef __u16 umode_t;
typedef __u16 nlink_t;
typedef __u16 mode_t;
typedef __u32 loff_t;
-typedef unsigned int speed_t;
+typedef __u32 speed_t;
typedef __u16 dev_t;
typedef __u16 ino_t;
diff --git a/libc/libc.a b/libc/libc.a
index 9c13df0..5f92616 100644
--- a/libc/libc.a
+++ b/libc/libc.a
Binary files differ
diff --git a/libc/misc/cputype.c b/libc/misc/cputype.c
index 642edf6..7dd7088 100644
--- a/libc/misc/cputype.c
+++ b/libc/misc/cputype.c
@@ -2,7 +2,6 @@
* This does a determination of the cpu type that is actually being used.
* It can determine the CPU on anything upto and including a 386 accuratly
* whatever mode the CPU is in (This is 16 bit code)
- * An MSDOS compiled version is available.
*
* For Post 386 interpretation the argument must be set to 1, if this is done
* an attempt to determine the CPU type will be made using MSDOS calls and
@@ -10,27 +9,30 @@
*
* If STANDALONE is defined this will decode and print the output from cputype
*
- * $ cputype # Call cputype(0) and interpret
- * $ cputype + # Call cputype(1) get a SIGILL (or perhaps interpret)
+ * $ cputype # Call cputype(0) and interpret
+ * $ cputype + # Call cputype(1) get a SIGILL (or perhaps interpret)
*
* NOTE: This code is COPYRIGHT and not under the GNU Lib copyright, this
- * may be distributed freely as source or as a standalone binary
- * compiled from this unmodified source.
+ * may be distributed freely as source or as a standalone binary
+ * compiled from this unmodified source.
*
- * You may use the cputype() function in your own personal code.
- * You may distribute a binary version of code containing the
- * cputype() function if either you distribute this source with
- * the binary version or distribute a clear reference to a freely
- * available copy of this source code and the source code to the
- * rest of your package with the binary version of the package.
+ * You may use the cputype() function in your own personal code.
+ * You may distribute a binary version of code containing the
+ * cputype() function if either you distribute this source with
+ * the binary version or distribute a clear reference to a freely
+ * available copy of this source code and the source code to the
+ * rest of your package with the binary version of the package.
*
- * (C) Copyright R de Bath 1989-1995
+ * (C) Copyright R de Bath 1989-1996
*/
#ifdef STANDALONE
+#define cputype cpu
#include <stdio.h>
+#ifndef __MSDOS__
#include <signal.h>
+#endif
char * name_808x[] = {
"8088", "8086", "80C88", "80C86", "NEC V20", "NEC V30", "808x Clone"
@@ -100,8 +102,13 @@ int argc; char **argv;
#ifdef __AS386_16__
#asm
.text
+#ifdef STANDALONE
+export _cpu
+_cpu:
+#else
export _cputype
_cputype:
+#endif
; First save everything ...
push bp
mov bp,sp
@@ -121,7 +128,7 @@ _cputype:
mov ax, cs
mov es, ax
mov ds, ax
- mov bx, #0 ; Init to 8086
+ mov bx, #0 ; Init to 8086
; First easy check is it a 286 or better ...
push sp
@@ -133,7 +140,7 @@ _cputype:
; Come here when we`re done (286+)
cpu_prot:
; .286P
- smsw ax ; Fetch 5 LSB of MSW (PE,MP,EP,...)
+ smsw ax ; Fetch 5 LSB of MSW (PE,MP,EP,...)
and al,#31
mov bl,al
@@ -149,11 +156,11 @@ cpu_prot:
or bh,#$80
; Another check for FPU *BUT* I think this only get`s 287+
-; finit
-; fstsw ax
-; or al,al
-; jnz cpuend
-; or bh,#$80
+; finit
+; fstsw ax
+; or al,al
+; jnz cpuend
+; or bh,#$80
; .8086
cpuend:
@@ -167,29 +174,31 @@ cpuend:
pop bp
ret
-ge286: ; .286P
+ge286: ; .286P
; Does the caller want the exact CPU
cmp cx,#0
jne try_486
; Simple test for a 286 ...
- mov bh,#2 ; Major CPU type >= 80286
+ mov bh,#2 ; Major CPU type >= 80286
; What`s the contents of the GDT pointer
sub sp,#6
mov bp,sp
sgdt [bp]
add sp,#4
- pop ax ; 286 == FFFF, 386+ anything else
- inc ax
+ pop ax ; For 286, ah can only be 0xFF
+ inc ah
jz cpu_prot
- mov bh,#$13 ; Major CPU type >= 80386
+ mov bh,#$13 ; Major CPU type >= 80386
-; smsw ax
-; ror ax,#1
-; jnc try_486 ; If in real mode and running MSDOS
+#ifdef __MSDOS__
+ smsw ax ; If we`re in MSDOS and running in real mode
+ ror ax,#1 ; we can do the int 6 detection.
+ jnc try_486
+#endif
- jmp cpu_prot ; Assume 486 test will NOT work in prot mode
+ jmp cpu_prot ; Assume 486 test will NOT work in prot mode
; This is an alternate way of finding a 386 ...
; But it *can* be hidden by V86 mode.
@@ -201,14 +210,12 @@ ge286: ; .286P
; pop ax
; popf
; and ax,#$7000
-; jz cpu_prot ; It`s id`ed as a 286 we already know
- ; different but it`s probably a bad idea
- ; to try for a 486.
+; jz is_a_286
try_486:
; This trys to trap undefined instructions
; it may not work if the CPU is in protected mode
- ; Note: This does actually re-test 286 v 386
+ ; Note: This code works for anything 286+
cli
push bp
mov bp, sp
@@ -219,18 +226,23 @@ try_486:
mov ax,#$2506
lea dx, [int6]
int #$21
- mov bh,#2 ; 286
+ mov bh,#2 ; 286
; .486
test386:
- mov ebx,#$00040300 ; 386 or 486
+ mov ebx,#$00040300 ; 386 or 486
test486:
- bswap ebx ; Byte twiddle now 486
+ bswap ebx ; Byte twiddle now 486
mov ax,#1
do_cpuid:
db $0F ; CPUID instruction
db $A2
+
+ mov ax,#1 ; And again cause of Nasty EMM386s
+ db $0F ; CPUID instruction
+ db $A2
+
and ah,#15 ; Select family number
mov bh,ah ; put it where we want it
@@ -258,14 +270,14 @@ pre286:
; Try for an NEC V20/30
mov ax, #$0208
db $D5
- db 16 ; Only the 8088 actually checks the arg to AAD
- cmp al, #$28 ; as intel ran out of microcode space
+ db 16 ; Only the 8088 actually checks the arg to AAD
+ cmp al, #$28 ; as intel ran out of microcode space
jz cmos
- mov bx,#4 ; NEC V20
+ mov bx,#4 ; NEC V20
jmp test8
; The CMOS 8088/6 had the bug with rep lods repaired.
-cmos: push si
+cmos: push si
sti
mov cx, #$FFFF
rep
@@ -273,11 +285,11 @@ cmos: push si
pop si
or cx,cx
jne test8
- mov bx,#2 ; Intel 80C88
+ mov bx,#2 ; Intel 80C88
; This tests the prefetch of the CPU, 8 bit ones have 4 bytes
; 16 bit cpus have a queue of 6 bytes.
-test8: push di
+test8: push di
push bx
mov dx,#0
mov bx,#4
@@ -293,9 +305,9 @@ retest: lea di,[_nop]
nop
nop
nop
-_inc: inc dx
+_inc: inc dx
nop
-_nop: nop
+_nop: nop
sti
mov byte ptr [_inc], #$42
dec bx
@@ -304,7 +316,7 @@ _nop: nop
cmp dx,#0
jz done8
inc bx
-done8: pop di
+done8: pop di
cld
br cpuend
@@ -314,28 +326,29 @@ done8: pop di
int6:
mov sp, bp
jmp fail386
-;;
- push bp
- mov bp, sp
- push ax
- mov ax,cs
- cmp 4[bp],ax
- pop ax
- jnz pass
- cmp bh,#2
- je move23
- cmp bh,#3
- je move34
- add [bp+2], #(fail386 - do_cpuid)
- jmp return
-move34: add [bp+2], #(fail386 - test486)
- jmp return
-move23: add [bp+2], #(fail386 - test386)
-return: pop bp
- iret
-
-pass: pop bp
- jmp [vector]
+
+; This was the old way, didn't always work tho.
+; push bp
+; mov bp, sp
+; push ax
+; mov ax,cs
+; cmp 4[bp],ax
+; pop ax
+; jnz pass
+; cmp bh,#2
+; je move23
+; cmp bh,#3
+; je move34
+; add [bp+2], #(fail386 - do_cpuid)
+; jmp return
+;move34: add [bp+2], #(fail386 - test486)
+; jmp return
+;move23: add [bp+2], #(fail386 - test386)
+;return: pop bp
+; iret
+;
+;pass: pop bp
+; jmp [vector]
vector: dd 0
diff --git a/libc/msdos/Makefile b/libc/msdos/Makefile
index 2dd3497..cdafaa3 100644
--- a/libc/msdos/Makefile
+++ b/libc/msdos/Makefile
@@ -8,10 +8,12 @@ include $(TOP)/Make.defs
ASRC=msdos.c
AOBJ= dos_start.o __mkargv.o dos__fconv.o dos_read.o dos_write.o \
dos_open.o dos_close.o dos_unlink.o dos_lseek.o \
- dos_segalloc.o dos_setvect.o dos_getvect.o dos_isatty.o
+ dos_segalloc.o dos_segfree.o dos_setvect.o dos_getvect.o \
+ dos_isatty.o dos_getmod.o dos_stat.o
BSRC=i86.c
-BOBJ= __set_es.o __peek_es.o __poke_es.o __deek_es.o __strchr_es.o
+BOBJ= __seg_regs.o __peek_es.o __poke_es.o __deek_es.o __doke_es.o \
+ __strchr_es.o
ifeq ($(PLATFORM),i86-DOS)
OBJ=$(AOBJ) $(BOBJ)
diff --git a/libc/msdos/i86.c b/libc/msdos/i86.c
index 0613756..44de3e3 100644
--- a/libc/msdos/i86.c
+++ b/libc/msdos/i86.c
@@ -9,7 +9,15 @@
#ifdef __AS386_16__
-#ifdef L___set_es
+#ifdef L___seg_regs
+unsigned int
+__get_cs()
+{
+#asm
+ mov ax,cs
+#endasm
+}
+
unsigned int
__get_ds()
{
@@ -100,6 +108,28 @@ unsigned int off;
}
#endif
+#ifdef L___doke_es
+int
+__doke_es(off, value)
+unsigned int off;
+int value;
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov bx,sp
+ mov bx,[bx+2]
+ xchg ax,bx
+#else
+ mov bx,sp
+ mov ax,[bx+4]
+ mov bx,[bx+2]
+#endif
+ seg es
+ mov [bx],ax
+#endasm
+}
+#endif
+
#ifdef L___strchr_es
char *
__strchr_es(s, c)
diff --git a/libc/msdos/msdos.c b/libc/msdos/msdos.c
index 02c35db..ddb49d9 100644
--- a/libc/msdos/msdos.c
+++ b/libc/msdos/msdos.c
@@ -421,6 +421,25 @@ ok:
}
#endif
+#ifdef L_dos_segfree
+unsigned int
+__segfree(segno)
+unsigned int segno;
+{
+#asm
+ push es
+ mov bx,sp
+ mov es,[bx+4]
+ mov ah,#$49
+ int $21
+ jc err
+ mov ax,#0
+err:
+ pop es
+#endasm
+}
+#endif
+
#ifdef L_dos_setvect
void
__setvect(i,j)
@@ -463,6 +482,62 @@ int vecno;
}
#endif
+#ifdef L_dos_getmod
+int
+__dos_getmod(fname)
+{
+#asm
+#if __FIRST_ARG_IN_AX__
+ mov dx,ax
+#else
+ mov bx,sp
+ mov dx,[bx+2]
+#endif
+ mov ax,#$4300
+ int #$21
+ jnc statok
+ mov cx,#-1
+statok:
+ mov ax,cx
+#endasm
+}
+#endif
+
+#ifdef L_dos_stat
+int
+__dos_stat(fname, dtaptr)
+{
+#asm
+ mov bx,sp
+#if __FIRST_ARG_IN_AX__
+ mov cx,ax
+ mov dx,[bx+2]
+#else
+ mov dx,[bx+4]
+#endif
+ mov ah,#$1A ; Set DTA to requested
+ int #$21
+#if __FIRST_ARG_IN_AX__
+ mov ax,cx
+#else
+ mov dx,[bx+2]
+#endif
+ mov ax,#$4300 ; Locate the file
+ int #$21
+ jc nonesuch
+ mov ax,#$4e00 ; Get all the available information.
+ int #$21
+ jc nonesuch
+ xor ax,ax
+ ret
+nonesuch:
+ mov ax,#2
+ mov _errno,ax
+ mov ax,#-1
+#endasm
+}
+#endif
+
#ifdef L_dos_isatty
isatty(fd)
int fd;
diff --git a/libc/stdio1/BUGS b/libc/stdio1/BUGS
deleted file mode 100644
index 0e8e0db..0000000
--- a/libc/stdio1/BUGS
+++ /dev/null
@@ -1,15 +0,0 @@
-Error checking is known to be wanting. However the author just wants to
-get it working right now.
-
-fread() and fwrite() are not supported. open(), read(), write(), and close()
-work very well for binary data.
-
-fopen() is the only way to open a file. None of the temp stuff is supported,
-and frepon() is unsupported.
-
-GNU extensions are unsupported.
-
-Some printf specifications may not work. Read the code for details of what
-IS supported.
-
-Other than that, this should be a perfectly normal stdio lib when it's finished.
diff --git a/libc/stdio1/Config b/libc/stdio1/Config
deleted file mode 100644
index 3b3b35f..0000000
--- a/libc/stdio1/Config
+++ /dev/null
@@ -1,3 +0,0 @@
-
-
-stdio: Joel's stdio package altered by Nat
diff --git a/libc/stdio1/Makefile b/libc/stdio1/Makefile
deleted file mode 100644
index d8058b0..0000000
--- a/libc/stdio1/Makefile
+++ /dev/null
@@ -1,36 +0,0 @@
-TOP=..
-include $(TOP)/Make.defs
-OBJ = __ffillbuf.o __stdio_init.o fflush.o fgetc.o fgets.o \
- fputc.o fputs.o puts.o printf.o fopen.o fclose.o scanf.o
-
-#missing functions from above: printf etc, scanf etc, idealgetline
-#seek
-
-#fopen.c, fclose.c removed because of malloc() use
-
-CFLAGS+=$(WALL)
-
-ifeq ($(PLATFORM),i86-ELKS)
-CFLAGS=$(CCFLAGS) $(DEFS) -ansi
-endif
-
-all: $(OBJ)
-
-libc.a: $(OBJ)
- ar r ../$(LIBC) $(OBJ)
- @touch libc.a
-
-$(OBJ): stdio.h
-
-test: test.o $(OBJ)
- $(CC) -o test test.o $(OBJ)
-
-%.o: %.c
- $(CC) $(CFLAGS) -o $@ $< -c
-
-clean:
- rm -f *.o test libc.a
-
-transfer:
- -@rm -f ../include/stdio.h
- cp -p stdio.h ../include/.
diff --git a/libc/stdio1/NOTICE b/libc/stdio1/NOTICE
deleted file mode 100644
index 25ca5b6..0000000
--- a/libc/stdio1/NOTICE
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
diff --git a/libc/stdio1/README b/libc/stdio1/README
deleted file mode 100644
index 5dc59aa..0000000
--- a/libc/stdio1/README
+++ /dev/null
@@ -1,13 +0,0 @@
-I found that it was helpful to have the extern stuff actually defined in
-one file as not external...
-
-Still trying to find the other problems
-
-Whether it is desireable to list stdio.h as a dependency is debateable
-
--Joel
-
-I've made a horrible number of changes here, look in 'Reverse_Patch' for
-how to go back ...
-
--Robert
diff --git a/libc/stdio1/TODO b/libc/stdio1/TODO
deleted file mode 100644
index 481f6d9..0000000
--- a/libc/stdio1/TODO
+++ /dev/null
@@ -1,33 +0,0 @@
-Sun Jan 21 18:16:03 EST 1996 -- Nat Friedman
-============================================
-I've made a load of changes to this code, but there's still a lot to be done.
-- scanf, fscanf
-
-
-
-
-input, file positioning, eof, declarations of functions, printf
-
-look for unsigned char references
-
-specifically
-fix printf and figure out what's going on in there.
-write idealgetline, scanf, other stuff
-then deal with above stuff...
-
-
-LATEST LIST:
-printf, fprintf
-scanf, fscanf
-feof
-seek support
-error handling (not too hard since system calls only in a few places)
-atexit stuff (close files; will need to add a linked list of files)
-setvbuf if desired
-check that fopen() and stdio_init() fill in ALL the fields
-testing!
-
-rm NOTICE
-
-
-
diff --git a/libc/stdio1/__ffillbuf.c b/libc/stdio1/__ffillbuf.c
deleted file mode 100644
index e705cbf..0000000
--- a/libc/stdio1/__ffillbuf.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/* simplified linux __ffillbuf.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include <unistd.h>
-#include "stdio.h"
-
-/* this function makes the mistake of assuming the buffer really DOES
-need to be filled. */
-
-/* RDB:
- * Added simple processing for EOF and errors
- * As this is _only_ called from getc() the memory footprint is smaller
- * if it pretends to be getc in the complex case.
- */
-
-int
-__ffillbuf(stream)
-FILE *stream;
-{
- int stat;
-
- if( stream->fd < 0 || ferror(stream) ) return EOF;
-
- stat = read(stream->fd, (char *) stream->bufstart, stream->bufend - stream->bufstart);
- if( stat > 0 )
- stream->bufread = stream->bufstart + stat;
- else if( stat == 0 )
- {
- stream->fc_eof = 1;
- return EOF;
- }
- else
- {
- stream->fc_err = 1;
- return EOF;
- }
-
- stream->bufpos = stream->bufstart;
-
- return getc(stream);
-}
diff --git a/libc/stdio1/__stdio_init.c b/libc/stdio1/__stdio_init.c
deleted file mode 100644
index b49bb28..0000000
--- a/libc/stdio1/__stdio_init.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/* simplified linux __stdio_init.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include "stdio.h"
-
-/*
- OK, Complete hackup here, I've removed the need for the init function.
- Not also I've make the types into 'unsigned char' this is so it doesn't
- return EOF when it really means '\377'
- */
-
-static unsigned char __stdinbuf[BUFSIZ], __stdoutbuf[BUFSIZ], __stderrbuf[80];
-
-static FILE __the_stdin = {
- 0,
- __stdinbuf,
- __stdinbuf,
- __stdinbuf,
- __stdinbuf+sizeof(__stdinbuf),
- _IOLBF,
- _MODE_READ,
- 0, 0,
- 0, 0, 1
-};
-
-static FILE __the_stdout = {
- 1,
- __stdoutbuf,
- __stdoutbuf,
- __stdoutbuf,
- __stdoutbuf+sizeof(__stdoutbuf),
- _IOLBF,
- _MODE_WRITE,
- 0, 0,
- 0, 0, 1
-};
-
-static FILE __the_stderr = {
- 2,
- __stderrbuf,
- __stderrbuf,
- __stderrbuf,
- __stderrbuf+sizeof(__stderrbuf),
- _IOLBF,
- _MODE_WRITE,
- 0, 0,
- 0, 0, 1
-};
-
-FILE *stdin = &__the_stdin,
- *stdout = &__the_stdout,
- *stderr = &__the_stderr;
diff --git a/libc/stdio1/fclose.c b/libc/stdio1/fclose.c
deleted file mode 100644
index 7ec233e..0000000
--- a/libc/stdio1/fclose.c
+++ /dev/null
@@ -1,41 +0,0 @@
-/* simplified linux fclose.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include <unistd.h>
-#include "stdio.h"
-
-int fclose (stream)
-FILE *stream;
-{
- /* only allow fclose() on what was fopen()ed. */
- /*
- This isn't right, there's nothing wrong with fclosing stdin
- but the next fopen/open will be given fd 0 and so become stdin
- Of course you do have to be a little careful :-)
- RDB
- */
-
- if ((stream == stdin) || (stream == stdout) || (stream == stderr)) return EOF;
-
- if (fflush(stream)) return EOF;
-
- if (close(stream->fd)) return EOF;
-
- free(stream->bufstart);
- free(stream);
- return 0;
-}
diff --git a/libc/stdio1/fcntl.h b/libc/stdio1/fcntl.h
deleted file mode 100644
index 69fdb90..0000000
--- a/libc/stdio1/fcntl.h
+++ /dev/null
@@ -1,72 +0,0 @@
-#ifndef __FCNTL_H
-#define __FCNTL_H
-
-/*
- * Definitions taken from the i386 Linux kernel.
- */
-
-/* open/fcntl */
-
-#define O_ACCMODE 0003
-#define O_RDONLY 00
-#define O_WRONLY 01
-#define O_RDWR 02
-#define O_CREAT 0100 /* not fcntl */
-#define O_EXCL 0200 /* not fcntl */
-#define O_NOCTTY 0400 /* not fcntl */
-#define O_TRUNC 01000 /* not fcntl */
-#define O_APPEND 02000
-#define O_NONBLOCK 04000
-#define O_NDELAY O_NONBLOCK
-#if 0
-#define O_SYNC 010000 /* Not supported */
-#define FASYNC 020000 /* Not supported */
-#endif
-
-#define F_DUPFD 0 /* dup */
-#define F_GETFD 1 /* get f_flags */
-#define F_SETFD 2 /* set f_flags */
-#define F_GETFL 3 /* more flags (cloexec) */
-#define F_SETFL 4
-#define F_GETLK 5
-#define F_SETLK 6
-#define F_SETLKW 7
-
-#define F_SETOWN 8 /* for sockets. */
-#define F_GETOWN 9 /* for sockets. */
-
-/* for F_[GET|SET]FL */
-#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
-
-/* for posix fcntl() and lockf() */
-#define F_RDLCK 0
-#define F_WRLCK 1
-#define F_UNLCK 2
-
-/* for old implementation of bsd flock () */
-#define F_EXLCK 4 /* or 3 */
-#define F_SHLCK 8 /* or 4 */
-
-/* operations for bsd flock(), also used by the kernel implementation */
-#define LOCK_SH 1 /* shared lock */
-#define LOCK_EX 2 /* exclusive lock */
-#define LOCK_NB 4 /* or'd with one of the above to prevent
- blocking */
-#define LOCK_UN 8 /* remove lock */
-
-#ifdef __KERNEL__
-#define F_POSIX 1
-#define F_FLOCK 2
-#endif /* __KERNEL__ */
-
-#if 0
-struct flock {
- short l_type;
- short l_whence;
- off_t l_start;
- off_t l_len;
- pid_t l_pid;
-};
-#endif
-
-#endif
diff --git a/libc/stdio1/fflush.c b/libc/stdio1/fflush.c
deleted file mode 100644
index c9cdac7..0000000
--- a/libc/stdio1/fflush.c
+++ /dev/null
@@ -1,36 +0,0 @@
-/* simplified linux fflush.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <unistd.h>
-#include "stdio.h"
-
-int fflush(stream)
-FILE *stream;
-{
- if (stream == 0) return 0;
- if ((stream->file_mode == _MODE_WRITE)
- ||(stream->file_mode == (_MODE_WRITE & _MODE_RDWR))){
- write(stream->fd, (char *) stream->bufstart,
- stream->bufpos - stream->bufstart);
- stream->bufpos = stream->bufstart;
- }
- return 0;
-}
-/* TODO: return EOF or 0; support NULL stream */
-/* The only place an error can come from is the write; you're not checking RDB
- */
diff --git a/libc/stdio1/fgetc.c b/libc/stdio1/fgetc.c
deleted file mode 100644
index 2c41062..0000000
--- a/libc/stdio1/fgetc.c
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "stdio.h"
-
-/*
- * Make this not dependent on getc() then we can:
- #define getc(fp) fgetc(fp)
- * if memory is _really_ tight.
- */
-
-int fgetc(stream)
-FILE *stream;
-{
- if( stream->ungetted )
- {
- stream->ungetted = 0;
- return stream->ungetchar;
- }
- if( stream->bufpos == stream->bufread )
- return __ffillbuf(stream);
- else
- return *stream->bufpos++;
-}
diff --git a/libc/stdio1/fgets.c b/libc/stdio1/fgets.c
deleted file mode 100644
index c085970..0000000
--- a/libc/stdio1/fgets.c
+++ /dev/null
@@ -1,50 +0,0 @@
-/* fgets.c for limited linux stdio
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include "stdio.h"
-
-/*
- RDB BZZZT! This should only read upto and including any newline!
-*/
-
-char *fgets(s, count, f)
-char *s;
-size_t count;
-FILE *f;
-{
- char *ret;
- register size_t i;
- register int ch;
-
- ret = s;
- for(i=count; i>0; i--)
- {
- ch = getc(f);
- if( ch == EOF )
- {
- if(s==ret) return 0;
- break;
- }
- *s++ = (char) ch;
- if( ch == '\n' ) break;
- }
- *s = 0;
-
- if( ferror(f) ) return 0;
- return ret;
-}
diff --git a/libc/stdio1/fopen.c b/libc/stdio1/fopen.c
deleted file mode 100644
index 1265ff5..0000000
--- a/libc/stdio1/fopen.c
+++ /dev/null
@@ -1,80 +0,0 @@
-/* simplified linux fopen.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include "stdio.h"
-#include <malloc.h>
-
-FILE * fopen(name, openmode)
-char *name;
-char *openmode;
-{
- FILE *new;
- int openplus=0;
- char basemode;
-
- basemode = openmode[0];
- while (openmode[0] != 0){
- switch(openmode[0]){
- case '+': openplus=1; break;
- }
- openmode++;
- }
-
- new = malloc(sizeof(new));
- if( new == 0 ) return 0;
- new->bufread = new->bufpos = new->bufstart = malloc(BUFSIZ);
- if( new->bufstart == 0 ) { free(new) ; return 0; }
-
- new->bufend = new->bufstart + BUFSIZ;
- new->buffer_mode = _IOFBF;
- new->iotrans = 0;
- new->fd = -1;
- if (openplus){
- new->file_mode = _MODE_RDWR;
- switch (basemode){
- case 'a':
- new->fd = open(name, O_RDWR | O_APPEND | O_CREAT);
- break;
- case 'r':
- new->fd = open(name, O_RDWR);
- break;
- case 'w':
- new->fd = open(name, O_RDWR | O_TRUNC | O_CREAT);
- break;
- }
- } else switch (basemode){
- case 'a':
- new->fd = open(name, O_WRONLY | O_APPEND | O_CREAT);
- new->file_mode = _MODE_WRITE;
- break;
- case 'r':
- new->fd = open(name, O_RDONLY);
- new->file_mode = _MODE_READ;
- break;
- case 'w':
- new->fd = open(name, O_WRONLY | O_TRUNC | O_CREAT);
- new->file_mode = _MODE_WRITE;
- break;
- }
- if( new->fd < 0 )
- {
- free(new->bufstart);
- free(new);
- return 0;
- }
- return new;
-}
diff --git a/libc/stdio1/fputc.c b/libc/stdio1/fputc.c
deleted file mode 100644
index 939a721..0000000
--- a/libc/stdio1/fputc.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* simplified linux fputc.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include "stdio.h"
-
-/*
- * Make this not dependent on putc() then we can:
- #define putc(c, fp) fputc(c, fp)
- * if memory is _really_ tight.
- */
-
-#undef putc
-#define putc(c, stream) \
- (((stream)->bufpos[0] = (c)), \
- ((stream)->bufpos++), \
- ((((stream)->bufpos == (stream)->bufend) \
- ||((stream)->buffer_mode == _IONBF) \
- ||(((stream)->buffer_mode == _IOLBF) \
- && ((stream)->bufpos != (stream)->bufstart) \
- && ((stream)->bufpos[-1] == '\n'))) \
- ? fflush(stream):0))
-
-#define new_putc(c, stream) \
- ((unsigned char)( \
- ((stream)->bufpos>=(stream)->bufread) ? fputc((c), (stream)) \
- : *(stream)->bufpos++ = (c) \
- ))
-
-int
-fputc(int c, FILE * stream)
-{
-#ifdef __MSDOS__
- if( c == '\n' && stream->iotrans ) fputc('\r', stream);
-#endif
- return putc(c, stream);
-}
-
-
-
diff --git a/libc/stdio1/fputs.c b/libc/stdio1/fputs.c
deleted file mode 100644
index 41e2998..0000000
--- a/libc/stdio1/fputs.c
+++ /dev/null
@@ -1,32 +0,0 @@
-/* simplified linux fputs.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include <unistd.h>
-#include <string.h>
-#include "stdio.h"
-
-int
-fputs(__const char * string, FILE * stream)
-{
- if (stream->buffer_mode != _IONBF){
- while (string[0] != 0){
- putc(string[0], stream);
- string++;
- }
- } else write(stream->fd, string, strlen(string));
- return 0;
-}
diff --git a/libc/stdio1/idealgetline.c b/libc/stdio1/idealgetline.c
deleted file mode 100644
index 7eacc9e..0000000
--- a/libc/stdio1/idealgetline.c
+++ /dev/null
@@ -1,67 +0,0 @@
-/* idealgetline.c -- my idea of an ideal getline function for stdio
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/* I actually intend to use this in 32 bit programs, unlike the other stuff
- in this lib. IMHO GNU getline is broken. It is too hard to use.
-
- Just pass this function a FILE * and it will retrieve a line for you using
- getc(). It will realloc() exactly the amount of memory needed, and will
- generate error messages for non-ascii characters on stderr.
-
- This may not be your ideal. It probably generates far too many errors.
- It doesn't work well for those who don't use English (but since
- Linux-less-than-32 libc and kernels are each being produced by one
- person in the US and one in the UK, this isn't a problem). It probably
- is not what you (or I) want for interactive input.
-
- You're welcome to modify this routine to meet your needs. However, if
- you change the semantics significantly, please change the name.
-
- (Maybe I should have put my own name on it so there will be no confusion
- about who thought it was ideal). */
-
-#include <stdio.h>
-#include <malloc.h>
-
-char *idealgetline(f)
-FILE *f;
-{
- char c;
- char *ret;
- int size = 0, bufsize = 256;
-
- ret = malloc(256);
- c = getc(f);
- while ((c != EOF) && (c != '\n')){
- if ((c >= ' ') && (c <= 126)){
- ret[size] = c;
- size++;
- if (size == bufsize){
- bufsize += 256;
- ret = realloc(ret, bufsize);
- }
- } else {
- fprintf(stderr, "Unexpected character 0x%x encountered in input", c);
- free(ret);
- return 0;
- }
- }
- ret[size] = '\0';
- size++;
- return realloc(ret, size);
-}
diff --git a/libc/stdio1/old_printf.c b/libc/stdio1/old_printf.c
deleted file mode 100644
index 81d62ac..0000000
--- a/libc/stdio1/old_printf.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/* fprintf.c for limited Linux libc
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* Thanks Alan for writing the hard routine for me :-)
- * Alan said that this works "most of the time". Something tells me I'm making
- * it even worse! */
-/* The basic idea here is to make fprintf the core routine. printf obviously
- can just call fprintf with stdout followed by all of its arguments.
- sprintf() works using the fake file &the_sprintf. It's marked as fully
- buffered, so that it will only write(2) when &the_sprintf->bufpos ==
- &the_sprintf->bufend, which I doubt will happen since &the_sprintf->bufend
- = 0. The trick is that sprintf must set &the_sprintf->bufstart =
- &the_sprintf->bufpos = its first argument. Not as orthagonal (is that
- the right word?) as glibc's facilities for non-files, but this isn't a
- library for people who have unlimited RAM budgets. (not like the libc
- I use on linux/i586 enjoys an unlimited RAM budget either; I only have
- 8 MB
-
- I'm not sure what the "correct" way to pass the variable arguments
- from one function to the next is. Rather than pass the arguments
- themselves, I'm passing a pointer to them. However, the following
- explaination from Alan is probably a polite way of saying it will not
- work on a 386 anyway.
- Joel Weber
-
- [ I've migrated all of this code over to the ELKS stdarg that I wrote.
- The accepted way to do it is for the wrapper function to accept a
- variable number of arguments, use stdarg to make an argument pointer,
- and then pass the argument pointer on to the core function, as I've
- done here. This should definitely work on a 386, as the arguments
- are still passed in the stack, and stack order is maintained. -Nat ]
- */
-
-/*
- * This is NOT stunningly portable, but works
- * for pretty dumb non ANSI compilers and is
- * tight. Adjust the sizes to taste.
- *
- * Illegal format strings will break it. Only the
- * following simple subset is supported
- *
- * %x - hex
- * %d - decimal
- * %s - string
- * %c - char
- *
- * And the h/l length specifiers for %d/%x
- *
- * Alan Cox.
- */
-
-#include <stdarg.h>
-#include "stdio.h"
-
-/* 17 to make sure that there's room for the trailing newline.
- I'm not really sure if this is ideal... */
-static char nstring[17]="0123456789ABCDEF";
-
-static unsigned char *
-__numout(long i, int base)
-{
- static unsigned char out[16];
- int n;
- int flg = 0;
- unsigned long val;
-
- if (i<0 && base==10)
- {
- flg = 1;
- i = -i;
- }
- val = i;
-
- for (n = 0; n < 15; n++)
- out[n] = ' ';
- out[15] = '\0';
- n = 14;
- do{
- out[n] = nstring[val % base];
- n--;
- val /= base;
- }
- while(val);
- if(flg) out[n--] = '-';
- return &out[n+1];
-}
-
-static int
-internal_fprintf(FILE * stream, __const char * fmt, va_list ap)
-{
- register int c;
- int count = 0;
- int type, base;
-
- while(c=*fmt++)
- {
- if(c!='%')
- {
- putc(c, stream);
- count++;
- }
- else
- {
- type=1;
- do { c=*fmt++; } while( c=='.' || (c>='0' && c<='9'));
- if( c == 0 ) break;
- if(c=='h')
- {
- c=*fmt++;
- type = 0;
- }
- else if(c=='l')
- {
- c=*fmt++;
- type = 2;
- }
-
- switch(c)
- {
- case 'x':
- case 'o':
- case 'd':
- if (c=='x') base=16;
- if (c=='o') base=8;
- if (c=='d') base=10;
- {
- long val=0;
- switch(type)
- {
- case 0:
- val=va_arg(ap, short);
- break;
- case 1:
- val=va_arg(ap, int);
- break;
- case 2:
- val=va_arg(ap, long);
- break;
- }
- fputs((__const char *)__numout(val,base),stream);
- }
- break;
- case 's':
- {
- char *cp;
- cp=va_arg(ap, char *);
- while(*cp)
- putc(*cp++, stream);
- break;
- }
- case 'c':
- putc(va_arg(ap, int), stream);
- break;
- default:
- putc(c, stream);
- }
- }
- }
- return count;
-}
-
-
-int
-fprintf(FILE * stream, __const char * fmt, ...)
-{
- va_list ap;
- int retval;
- va_start(ap, fmt);
- retval=internal_fprintf(stream, fmt, ap);
- va_end(ap);
- return(retval);
-}
-
-int
-printf(__const char * fmt, ...)
-{
- va_list ap;
- int retval;
- va_start(ap, fmt);
- retval=internal_fprintf(stdout, fmt, ap);
- va_end(ap);
- return(retval);
-}
-
-/* This is a strange way of doing sprintf, but it should work */
-int sprintf(char * s, __const char * fmt, ...)
-{
- static FILE the_sprintf = {
- -1,
- 0,
- 0,
- 0,
- 0,
- _IOFBF,
- _MODE_WRITE,
- 0, 0,
- 0, 0};
- va_list ap;
- int retval;
-
- va_start(ap, fmt);
- the_sprintf.bufstart = the_sprintf.bufpos = (unsigned char *) s;
- the_sprintf.fc_err = 0;
-
- retval = internal_fprintf(&the_sprintf, fmt, ap);
- /* null-terminate the string */
- putc('\0', &the_sprintf);
-
- va_end(ap);
- return retval;
-}
-
-
-
-
-
diff --git a/libc/stdio1/printf.c b/libc/stdio1/printf.c
deleted file mode 100644
index f2a39bd..0000000
--- a/libc/stdio1/printf.c
+++ /dev/null
@@ -1,649 +0,0 @@
-/* fprintf.c for limited Linux libc
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* Thanks Alan for writing the hard routine for me :-)
- * Alan said that this works "most of the time". Something tells me I'm making
- * it even worse! */
-/* The basic idea here is to make fprintf the core routine. printf obviously
- can just call fprintf with stdout followed by all of its arguments.
- sprintf() works using the fake file &the_sprintf. It's marked as fully
- buffered, so that it will only write(2) when &the_sprintf->bufpos ==
- &the_sprintf->bufend, which I doubt will happen since &the_sprintf->bufend
- = 0. The trick is that sprintf must set &the_sprintf->bufstart =
- &the_sprintf->bufpos = its first argument. Not as orthagonal (is that
- the right word?) as glibc's facilities for non-files, but this isn't a
- library for people who have unlimited RAM budgets. (not like the libc
- I use on linux/i586 enjoys an unlimited RAM budget either; I only have
- 8 MB
-
- I'm not sure what the "correct" way to pass the variable arguments
- from one function to the next is. Rather than pass the arguments
- themselves, I'm passing a pointer to them. However, the following
- explaination from Alan is probably a polite way of saying it will not
- work on a 386 anyway.
- Joel Weber
-
- [ I've migrated all of this code over to the ELKS stdarg that I wrote.
- The accepted way to do it is for the wrapper function to accept a
- variable number of arguments, use stdarg to make an argument pointer,
- and then pass the argument pointer on to the core function, as I've
- done here. This should definitely work on a 386, as the arguments
- are still passed in the stack, and stack order is maintained. -Nat ]
- */
-
-/*
- * This is NOT stunningly portable, but works
- * for pretty dumb non ANSI compilers and is
- * tight. Adjust the sizes to taste.
- *
- * Illegal format strings will break it. Only the
- * following simple subset is supported
- *
- * %x - hex
- * %d - decimal
- * %s - string
- * %c - char
- *
- * And the h/l length specifiers for %d/%x
- *
- * Alan Cox.
- */
-
-#include <stdarg.h>
-#include "stdio.h"
-
-/* 17 to make sure that there's room for the trailing newline.
- I'm not really sure if this is ideal... */
-static char nstring[17]="0123456789ABCDEF";
-
-static unsigned char *
-__numout(long i, int base)
-{
- static unsigned char out[16];
- int n;
- int flg = 0;
- unsigned long val;
-
- if (i<0 && base==10)
- {
- flg = 1;
- i = -i;
- }
- val = i;
-
- for (n = 0; n < 15; n++)
- out[n] = ' ';
- out[15] = '\0';
- n = 14;
- do{
- out[n] = nstring[val % base];
- n--;
- val /= base;
- }
- while(val);
- if(flg) out[n--] = '-';
- return &out[n+1];
-}
-
-int
-fprintf(FILE * stream, __const char * fmt, ...)
-{
- va_list ap;
- int retval;
- va_start(ap, fmt);
- retval=internal_fprintf(stream, fmt, ap);
- va_end(ap);
- return(retval);
-}
-
-int
-printf(__const char * fmt, ...)
-{
- va_list ap;
- int retval;
- va_start(ap, fmt);
- retval=internal_fprintf(stdout, fmt, ap);
- va_end(ap);
- return(retval);
-}
-
-/* This is a strange way of doing sprintf, but it should work */
-int sprintf(char * s, __const char * fmt, ...)
-{
- static FILE the_sprintf = {
- -1,
- 0,
- 0,
- 0,
- 0,
- _IOFBF,
- _MODE_WRITE,
- 0, 0,
- 0, 0};
- va_list ap;
- int retval;
-
- va_start(ap, fmt);
- the_sprintf.bufstart = the_sprintf.bufpos = (unsigned char *) s;
- the_sprintf.fc_err = 0;
-
- retval = internal_fprintf(&the_sprintf, fmt, ap);
- /* null-terminate the string */
- putc('\0', &the_sprintf);
-
- va_end(ap);
- return retval;
-}
-
-
-
-
-
-/*
- * printf.c - This is the more complete fprintf() replacement for libc8086
- * Copyright (C) 1996 Steven Huang <sthuang@hns.com>.
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <stdio.h>
-#include <string.h>
-#include <ctype.h>
-
-/*
- * This decides if the little test main program gets included
- */
-#undef TEST
-/*
- * This decides if printf() should act like standard. When undefined,
- * - prints out "(err)" if a bad format is encountered
- * - supports the %b (binary) format
- */
-#define STANDARD
-
-/*
- * Shut bcc up about 'const', which doesn't seem to be handled right
- * by unproto.
- */
-#ifdef __BCC__
-#define const
-#endif
-
-#define BUF_SIZE 128
-#define OUTC(c) { putc(c, stream); n++; }
-#define max(a, b) ((a > b) ? a : b)
-/*
- * if you change the ff, you need to change the order of characters in
- * the string 'flagstr' defined in _printf()
- */
-#define FLAG_PADZERO (1<<0)
-#define FLAG_LEFTJUST (1<<1)
-#define FLAG_SIGNED (1<<2)
-#define FLAG_ALT (1<<3)
-#define FLAG_SPACE (1<<4)
-
-static char *utoa(unsigned int val, char *buf, int radix)
-/*
- * Converts an integer to a variable-radix string representation
- *
- * Note:
- * Does not perform sanity checking for 'radix'
- * Assumes 'buf' has memory allocated to it
- */
-{
- int divisor;
- char *p = buf;
- const char *digitstr = "0123456789abcdef";
-
- for (divisor = 1; val / divisor >= radix; divisor *= radix);
- do {
- *p++ = digitstr[val / divisor];
- val %= divisor;
- divisor /= radix;
- } while (divisor >= 1);
- *p = '\0';
- return(buf);
-}
-
-static
-internal_fprintf(FILE * stream, const char * fmt, char *args)
-
-/* static int _printf(FILE *stream, const char *fmt, char *args) */
-/*
- * The one that does all the work.
- * This is a fairly complete implementation of printf(), supporting
- * everything EXCEPT:
- * - floating point (eEDOUfg formats)
- * - pointers (realizes them but doesn't understand how to print them)
- * - short and long (h/l) modifiers (dunno what to do about them)
- * It's even slightly faster than gcc's printf() on Linux. Can't beat
- * HP-UX's printf() though ;)
- *
- * Supports:
- * d, signed integer
- * i
- * o unsigned octal integer
- * u unsigned integer
- * x unsigned hex lowercase a-f
- * X unsigned hex uppercase A-F
- * c character
- * s string (character pointer)
- * p void pointer (ignores it)
- * % % character
- * n number of characters output so far
- *
- * Special feature: (no really, it's not a bug =) )
- * b prints an integer in binary form (i think this might come
- * in handy *somewhere*)
- *
- * # alternate format for octal (leading 0) and hex (0x/0X)
- * 0 leading zeroes for d, i, o, u, x, and X
- * - left justify, overrides '0'
- * ' ' (space) force a blank in front of positive numbers
- * + force a sign in front of any number
- *
- * width.precision, including support for '*' (reads value from
- * the parameter list (MUST BE INT))
- *
- * h, short/long modifiers, recognized but ignored.
- * l
- *
- * Warning:
- * The way varargs is implemented in libc is evil. Don't think
- * there's a better way, but misaligned or wrong parameters
- * passed to printf() can break a lot of things. I've tried my
- * best to handle errors in the format string, though.
- *
- * Each %something field cannot exceed 'BUF_SIZE' characters,
- * which I set to 128 right now. %s fields are not subject to
- * this limit.
- *
- * Note:
- * The semicolon -looks- missing in a few places but that's
- * because of the macro def of 'OUTC'. did it that way to
- * save a few lines of source ;)
- *
- * Expects a 'char *' as varargs parameter, unlike libc8086's
- * printf(), which takes a 'int *' then casts it to a 'char *'.
- * Either has to change, but it should be trivial.
- *
- * This function aborts whenever it scans an illegal format, unlike
- * gcc's libc which prints out the illegal format as if it's -not-
- * a format string. The 'STANDARD' preprocessor flag controls if
- * if just aborts (when defined) or prints out "(err)" (when undefined).
- */
-{
- /*
- * the "0-+# " and "dcs..." strings are listed in my idea of their
- * frequency of use, with the most popular in front. not terribly
- * important but strchr() might have an easier time that way.
- * if you change the ordering of 'flagstr', make sure you update
- * the #define FLAG_* stuff on top of this file too.
- */
- char c, *s, *f;
- const char *flagstr = "0-+# ",
-#ifdef STANDARD
- *typestr = "dcsixXuop";
-#else
- *typestr = "dcsixXuopb";
-#endif
- int n = 0, flags, width, actwidth, prec, bad = 0, neg, i;
- static char buf[BUF_SIZE];
-
- for (c = *fmt++; c && !bad;) {
- if (c != '%') { /* just copy */
- OUTC(c);
- c = *fmt++;
- }
- else {
- c = *fmt++; /* chew the % sign */
- flags = width = prec = 0;
- /*
- * Parse the "0-+# " flags
- */
- while ((f = strchr(flagstr, c)) != NULL) {
- flags |= 1 << (f - flagstr);
- c = *fmt++;
- }
- /*
- * The '*' parameter says fetch width value from varargs
- */
- if (c == '*') {
- width = *(int *) args;
- args += sizeof(int);
- if (width < 0) {
- width = abs(width);
- flags |= FLAG_LEFTJUST; /* set '-' flag */
- }
- c = *fmt++;
- }
- else
- /*
- * scan and convert the width parameter
- */
- if (isdigit(c))
- while (isdigit(c)) {
- width *= 10;
- width += c - '0';
- c = *fmt++;
- }
- /*
- * a '.' means there may be a precision parameter
- */
- if (c == '.') {
- c = *fmt++;
- /*
- * fetch precision value from varargs
- */
- if (c == '*') {
- prec = *(int *) args;
- if (prec < 0)
- prec = 0;
- args += sizeof(int);
- c = *fmt++;
- }
- else
- /*
- * scan and convert precision field
- */
- if (isdigit(c))
- while (isdigit(c)) {
- prec *= 10;
- prec += c - '0';
- c = *fmt++;
- }
- }
- /*
- * short and long modifiers. ignored for the moment
- */
- if (c == 'h') {
- c = *fmt++;
- }
- else
- if (c == 'l') {
- c = *fmt++;
- }
- /*
- * check if it's a valid type "dioux..."
- */
- if (strchr(typestr, c) != NULL) {
- neg = 0;
- switch (c) {
- case 'd':
- case 'i': {
- int val = *(int *) args;
- args += sizeof(int);
- neg = (val < 0);
- val = abs(val);
- actwidth = strlen(utoa(val, buf, 10)); }
- /*
- * if negative or '+'/' ' flags set
- */
- if (neg || (flags & FLAG_SIGNED) || (flags & FLAG_SPACE))
- actwidth++;
- break;
- case 'u': {
- unsigned int uval = *(unsigned int *) args;
- args += sizeof(unsigned int);
- actwidth = strlen(utoa(uval, buf, 10)); }
- /*
- * if '+'/' ' flags set
- */
- if ((flags & FLAG_SIGNED) || (flags & FLAG_SPACE))
- actwidth++;
- break;
- case 'x':
- case 'X': {
- int val = *(int *) args;
- args += sizeof(int);
- actwidth = strlen(utoa(val, buf, 16)); }
- if (flags & FLAG_ALT)
- actwidth += 2;
- break;
- case 'o': {
- int val = *(int *) args;
- args += sizeof(int);
- actwidth = strlen(utoa(val, buf, 8)); }
- if (flags & FLAG_ALT)
- actwidth++;
- break;
- case 's':
- s = *(char **) args;
- args += sizeof(char *);
- actwidth = strlen(s);
- break;
- case 'c':
- buf[0] = *(char *) args;
- buf[1] = '\0';
- args += sizeof(char);
- actwidth = 1;
- break;
- /*
- * dunno how to handle pointers - what's the format of
- * linux86 pointers?! right now just prints "(ptr)"
- */
- case 'p':
- strcpy(buf, "(ptr)");
- args += sizeof(void *);
- actwidth = strlen(buf);
- s = buf; /* pretend we're a string */
- c = 's';
- break;
-#ifndef STANDARD
- case 'b': {
- int val = *(int *) args;
- args += sizeof(int);
- actwidth = strlen(utoa(val, buf, 2)); }
- break;
-#endif
- }
- /*
- * strings behave differently to the width.precision
- * parameters, so handle separately. besides, we avoid
- * an extra 'memcpy' to 'buf'
- */
- if (c == 's') {
- if (prec == 0)
- prec = actwidth;
- width = max(width, prec);
- /*
- * pad to the left if not left justified
- */
- if (!(flags & FLAG_LEFTJUST)) {
- for (i = width; i > prec; i--)
- OUTC(' ');
- }
- /*
- * print out entire string if no precision specified, otherwise
- * that's our upper limit
- */
- if (prec == 0)
- for (; *s; s++)
- OUTC(*s) /* no semicolon here */
- else
- for (i = 0; i < prec; i++)
- OUTC(s[i]);
- }
- else {
- /*
- * precision is as wide as width if it's not specified and
- * the leading zero '0' flag is set, and left-justify is
- * -not- set. c standard says left justify overrides the
- * leading 0.
- */
- if (prec == 0 && (flags & FLAG_PADZERO) && !(flags & FLAG_LEFTJUST))
- prec = width;
- /*
- * expand width.precision to fit the actual width. printf
- * width specifies the -minimum-, and aside from the
- * precision of %s fields, there's no way to specify maximum
- */
- prec = max(prec, actwidth);
- width = max(width, prec);
- /*
- * pad to the left if we're not left justified
- */
- if (!(flags & FLAG_LEFTJUST)) {
- for (i = width; i > prec; i--)
- OUTC(' ');
- }
- /*
- * check if we might need to print the sign
- */
- if (strchr("diu", c) != NULL) {
- if (neg) /* print if negative */
- OUTC('-') /* yes, no ';' here =) */
- else
- if (flags & FLAG_SIGNED) /* or '+' specified */
- OUTC('+') /* nor here */
- else
- if (flags & FLAG_SPACE) /* or ' ' specified */
- OUTC(' ') /* nor here */
- }
- /*
- * the alternate '#' flag is set. doesn't affect all though
- */
- if (flags & FLAG_ALT) {
- switch (c) {
- case 'o':
- OUTC('0'); /* leading zero for octals */
- break;
- case 'x':
- case 'X': /* prints 0x or 0X */
- OUTC('0');
- OUTC(c);
- break;
- }
- }
- /*
- * fill the precision field with either spaces or zeroes,
- * depending if we're printing numbers
- */
- if (strchr("diuxXo", c) != NULL)
- for (i = prec; i > actwidth; i--)
- OUTC('0')
- else
- for (i = prec; i > actwidth; i--)
- OUTC(' ');
- /*
- * print the field, except for 'X', which we convert to caps
- */
- if (c != 'X')
- for (f = buf; *f; f++)
- OUTC(*f) /* none here either */
- else
- for (f = buf; *f; f++)
- OUTC(toupper(*f));
- }
- /*
- * if we're left justified, we now need to pad spaces to the
- * right so that width will be correct
- */
- if (flags & FLAG_LEFTJUST)
- for (i = width; i > prec; i--)
- OUTC(' ');
- }
- else {
- /*
- * miscellaneous %thingies
- */
- switch (c) {
- case '%': /* %% -> % */
- OUTC('%');
- break;
- case 'n': /* %n writes current output count */
- *(*(int **) args) = n;
- args += sizeof(int *);
- break;
- default: /* oops, got a bad %thingy */
- bad = 1;
- }
- }
- c = *fmt++;
- }
- }
-#ifndef STANDARD
- /*
- * dunno what the standard wants if the format string is badly
- * formed, so i print (err) if the debug flag is set
- */
- if (bad) {
- OUTC('(');
- OUTC('e');
- OUTC('r');
- OUTC('r');
- OUTC(')');
- }
-#endif
- return(n);
-}
-
-#ifdef TEST
-
-#include <time.h>
-
-int main()
-{
- static unsigned char xbuf[128], *x;
- char *fmt = "%s, %s %d, %.*d:%.*d\n";
- int rv1, rv2, i, dt1, dt2;
- clock_t t1, t2;
-
- x = xbuf;
- *(char **) x = "Sun";
- x += sizeof(char *);
- *(char **) x = "Feb";
- x += sizeof(char *);
- *(int *) x = 18;
- x += sizeof(int);
- *(int *) x = 2;
- x += sizeof(int);
- *(int *) x = 10;
- x += sizeof(int);
- *(int *) x = 2;
- x += sizeof(int);
- *(int *) x = 56;
- x += sizeof(int);
- t1 = clock();
- for (i = 0; i < 1000; i++)
- rv1 = _printf(stdout, fmt, xbuf);
- t2 = clock();
- dt1 = t2 - t1;
-
- t1 = clock();
- for (i = 0; i < 1000; i++)
- rv2 = printf(fmt, "Sun", "Feb", 18, 2, 10, 2, 56);
- t2 = clock();
- dt2 = t2 - t1;
-
- printf("\nrv1: %d, rv2: %d, dt1: %d, dt2: %d\n", rv1, rv2, dt1, dt2);
- return(0);
-}
-
-#endif
diff --git a/libc/stdio1/puts.c b/libc/stdio1/puts.c
deleted file mode 100644
index d9bb8d0..0000000
--- a/libc/stdio1/puts.c
+++ /dev/null
@@ -1,26 +0,0 @@
-/* simplified linux puts.c
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-#include "stdio.h"
-
-int puts (string)
-char *string;
-{
- fputs(string, stdout);
- putc('\n', stdout);
- return 0;
-}
diff --git a/libc/stdio1/scanf.c b/libc/stdio1/scanf.c
deleted file mode 100644
index 81900a1..0000000
--- a/libc/stdio1/scanf.c
+++ /dev/null
@@ -1,151 +0,0 @@
-/* scanf.c for limited Linux libc
- Copyright (C) 1996 Joel N. Weber II <nemo@koa.iolani.honolulu.hi.us>
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-/* This scanf code was derived from my printf code, which in turn was
- * derived from Alan Cox's printk. It was tested by [no one so far...]
- */
-
-/* Disclaimer: I haven't even THOUGHT about testing this. If you do decide
- * to be brave and test it, and it doesn't work, you have the following
- * options:
- * o Send me mail telling me it doesn't work, which I will ignore
- * since I already knew that.
- * o Fix it yourself
- * o isolate the problem and send it to the list, and maybe
- * I'll fix it
- */
-
-/* BTW, the above comment may be destroyed once this has been tested. It's
- * not nessisary for my great great grandchildren to see it when they
- * take Ancient Linux History...
- */
-
-/* Incidentally, if it doesn't work, it may well be because I never bothered
- * to learn how to use scanf()...I briefly tried it for the usaco qualification
- * round, but had some wierd problems...ask me after mid February...BTW the
- * problems had nothing to do with scanf(); it was still broken (hopelessly)
- * when I went to getchar().
- */
-
-/* Note, too that the current version probably assumes some things with
- * variable argument handling that it shouldn't. Don't expect this to
- * work on a 386 in 32 bit mode, don't expect this to work on a Z80,
- * or anything other than an 8086. In fact, don't expect it to even
- * work on an 8086 ;-)
- */
-
-/* One of these days the headers will work painlessly... */
-/* #include <linuxmt/types.h> */
-/* #include <linuxmt/fcntl.h> */
-#include "stdio.h"
-
-/* note that we assume base == 10... */
-static int numin(int *num, int base, FILE *stream, int c)
-{
- if ((c < '0') || (c > '9')) return 0;
- *num = 0;
- while ((c >= '0') && (c <= '9')) {
- *num = *num * base + c - '0';
- c = getc(stream);
- }
- ungetc(c, stream);
-}
-
-/* currently, the h/l specifications are ignored */
-static int internal_scanf(stream,fmt,a1)
-FILE *stream;
-char *fmt;
-int *a1;
-{
- unsigned char *p=(char *)a1;
- char c;
- int inc;
- int count = 0;
-
- while(c=*fmt++)
- {
- do {
- inc = getc(stream);
- } while ((inc == ' ') || (inc == '\t') || (inc == '\n'));
-
- if ((c == '\n') || (c == '\t') || (c == ' '))
- ;
- else if (c!='%') {
- if (c != inc) {
- ungetc(inc, stream);
- return count;
- }
- } else {
- int len=2;
- c=*fmt++;
- if(c=='h') c=*fmt++;
- else if(c=='l') c=*fmt++;
-
- switch(c)
- {
- case 'x':
- if (numin(p, 16, stream, inc)) count++;
- else return count;
- p+=2;
- break;
- case 'd':
- if (numin(p, 10, stream, inc)) count++;
- else return count;
- p+=2;
- break;
- case 's':
- {
- char *cp=*((char **)p);
- p+=sizeof(char *);
- while(*cp)
- putc(cp++, stream);
- while ((inc != ' ') && (inc != '\t')
- && (inc != '\n') && (inc != EOF)) {
- *cp++ = inc;
- inc = getc(stream);
- }
- ungetc(inc, stream);
- break;
- }
- case 'c':
- *p++ = inc;
- p++;
- break;
- default:
- putc('?', stream);
- }
- }
- }
- return count;
-}
-
-
-int fscanf(stream,fmt,a1)
-FILE *stream;
-char *fmt;
-int a1;
-{
- return internal_fscanf(stream,fmt,&a1);
-}
-
-int scanf(fmt,a1)
-char *fmt;
-int a1;
-{
- return internal_fscanf(stdout,fmt,&a1);
-}
diff --git a/libc/stdio1/stdio.h b/libc/stdio1/stdio.h
deleted file mode 100644
index 4bd1989..0000000
--- a/libc/stdio1/stdio.h
+++ /dev/null
@@ -1,135 +0,0 @@
-/* simplified linux stdio.h
- Copyright (C) 1995 Joel N. Weber II
-
- This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License
- as published by the Free Software Foundation; either version 2
- of the License, or (at your option) any later version.
-
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
-
- You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <fcntl.h>
-#include <sys/types.h>
-#include <malloc.h>
-
-#ifndef __STDIO_H
-#define __STDIO_H
-
-/* when you add or change fields here, be sure to change the initialization
- * in stdio_init and fopen */
-struct __stdio_file {
- int fd; /* the file descriptor associated with the stream */
- unsigned char *bufstart; /* the start of the buffer */
- unsigned char *bufpos; /* the next byte to write to or read from */
- unsigned char *bufread; /* the end of data returned by last read() */
- unsigned char *bufend; /* the end of the buffer; ie the byte after the last
- malloc()ed byte */
- int buffer_mode;
-#define _IONBF 0xB111 /* no buffering */
-#define _IOLBF 0xB112 /* line buffering */
-#define _IOFBF 0xB113 /* full buffering */
- int file_mode;
-#define _MODE_READ 0xB121
-#define _MODE_WRITE 0xB122
-#define _MODE_RDWR 0xB124 /* used when a file is readwrite and is ord with
- what's in the buffer now */
- unsigned char ungetted, ungetchar;
- /* ungetted = 1 if there's data unread; else 0
- ungetchar contains the character */
- int fc_eof:1;
- int fc_err:1; /* eof and error conditions */
- int iotrans:1; /* Translate \n -> \r\n on MSDOS */
-};
-
-#define EOF (-1)
-
-typedef struct __stdio_file FILE;
-
-#define BUFSIZ 256
-
-extern FILE *stdin, *stdout, *stderr, *__stdsprintf;
-
-/* The following macros are used for all access to the buffers. If you
- * know the file is unbuffered, however, you may write to it directly, as
- * fputs.c does. However, be aware that sprintf assumes that by setting
- * bufend to 0, no file writing will occur. Also, since NO streams use
- * unbuffered mode by default and the function to change this behavior is
- * not implemented yet, I'm considering disallowing raw access at the cost
- * of having each byte of a string written individually. However, that
- * IS what you're asking for with non-buffered mode.
- *
- * RDB: It's considered very bad form to use the raw read() & write()
- * calls on the same files you use the stdio functions.
- */
-#ifdef __MSDOS__
-#define putc(c, fp) fputc(c, fp)
-#define getc(fp) fgetc(fp)
-#else
-#define putc(c, stream) \
- (((stream)->bufpos[0] = (c)), \
- ((stream)->bufpos++), \
- ((((stream)->bufpos == (stream)->bufend) \
- ||((stream)->buffer_mode == _IONBF) \
- ||(((stream)->buffer_mode == _IOLBF) \
- && ((stream)->bufpos != (stream)->bufstart) \
- && ((stream)->bufpos[-1] == '\n'))) \
- ? fflush(stream):0))
-
-#define getc(stream) \
- ((stream)->ungetted ? (((stream)->ungetted = 0), ((stream)->ungetchar)) : \
- (((stream)->bufpos == (stream)->bufread)?__ffillbuf(stream): \
- (*(stream)->bufpos++)))
-
-#endif
-
-#define putchar(c) putc((c), stdout)
-#define getchar() getc(stdin)
-#define ungetc(c, stream) (((stream)->ungetted = 1), ((stream)->ungetchar = c))
-
-#define ferror(fp) ((fp)->fc_err)
-#define feof(fp) ((fp)->fc_eof)
-
-#define fileno(fp) ((fp)->fd)
-/* declare functions; not like it makes much difference without ANSI */
-/* RDB: The return values _are_ important, especially if we ever use
- 8086 'large' model
- */
-
-#ifndef __P
-#define __P(x) ()
-#endif
-
-int setvbuf __P((FILE*, char*, int, size_t));
-int __ffillbuf __P((FILE*));
-void __stdio_init __P((void));
-int fclose __P((FILE*));
-int fflush __P((FILE*));
-int fgetc __P((FILE*));
-char *fgets __P((char*, size_t, FILE*));
-FILE *fopen __P((char*, char*));
-
-int fputc __P((int, FILE*));
-int fputs __P((__const char*, FILE*));
-char *idealgetline __P((FILE*));
-int puts __P((char*));
-
-int printf __P ((__const char *, ...));
-int fprintf __P ((FILE *, __const char *, ...));
-int sprintf __P ((char *, __const char *, ...));
-
-#ifndef SEEK_SET
-#define SEEK_SET 0
-#define SEEK_CUR 1
-#define SEEK_END 2
-#endif
-
-#endif /* __STDIO_H */
-/* TODO: add scanf, fscanf */
diff --git a/libc/stdio1/test.sh b/libc/stdio1/test.sh
deleted file mode 100755
index 9d872dc..0000000
--- a/libc/stdio1/test.sh
+++ /dev/null
@@ -1,12 +0,0 @@
-#!/bin/sh
-
-echo 'rm -f *.o test *.a'
-rm -f *.o test *.a
-echo 'make'
-make
-echo 'ar r libnat.a *.o'
-ar r libnat.a *.o
-echo 'ranlib libnat.a'
-ranlib libnat.a
-echo 'gcc test.c -I- -I../include -fno-builtin -o test.o -L./ -lnat'
-gcc test.c -I- -I../include -fno-builtin -o test.o -L./ -lnat
diff --git a/libc/stdio2/Makefile b/libc/stdio2/Makefile
index 56b9862..ef96567 100644
--- a/libc/stdio2/Makefile
+++ b/libc/stdio2/Makefile
@@ -5,7 +5,7 @@ include $(TOP)/Make.defs
ASRC=stdio.c
AOBJ=_stdio_init.o fputc.o fgetc.o fflush.o fgets.o gets.o fputs.o \
puts.o fread.o fwrite.o fopen.o fclose.o fseek.o rewind.o ftell.o \
- setbuffer.o ungetc.o
+ setbuffer.o setvbuf.o ungetc.o
PSRC=printf.c
POBJ=printf.o sprintf.o fprintf.o vprintf.o vsprintf.o vfprintf.o
diff --git a/libc/stdio2/stdio.c b/libc/stdio2/stdio.c
index 062a982..fa10644 100644
--- a/libc/stdio2/stdio.c
+++ b/libc/stdio2/stdio.c
@@ -715,6 +715,34 @@ int size;
}
#endif
+#ifdef L_setvbuf
+int setvbuf(fp, buf, mode, size)
+FILE * fp;
+char * buf;
+int mode;
+size_t size;
+{
+ fflush(fp);
+ if( fp->mode & __MODE_FREEBUF ) free(fp->bufstart);
+ fp->mode &= ~(__MODE_FREEBUF|__MODE_BUF);
+ fp->bufstart = fp->unbuf;
+ fp->bufend = fp->unbuf + sizeof(fp->unbuf);
+ fp->mode |= _IONBF;
+
+ if( mode == _IOFBF || mode == _IOLBF )
+ {
+ if( size <= 0 ) size = BUFSIZ;
+ if( buf == 0 ) buf = malloc(size);
+ if( buf == 0 ) return EOF;
+
+ fp->bufstart = buf;
+ fp->bufend = buf+size;
+ fp->mode |= mode;
+ }
+ fp->bufpos = fp->bufread = fp->bufwrite = fp->bufstart;
+}
+#endif
+
#ifdef L_ungetc
int
ungetc(c, fp)
diff --git a/libc/syscall/Makefile b/libc/syscall/Makefile
index 2cc4494..21991ee 100644
--- a/libc/syscall/Makefile
+++ b/libc/syscall/Makefile
@@ -6,9 +6,10 @@ TOP=..
include $(TOP)/Make.defs
LSRC=syslibc.c
-LOBJ=__cstartup.o time.o lseek.o getpid.o getppid.o \
- getuid.o geteuid.o getgid.o getegid.o \
- dup2.o dup.o abort.o wait.o waitpid.o sleep.o
+LOBJ=__cstartup.o time.o lseek.o getpid.o getppid.o \
+ getuid.o geteuid.o getgid.o getegid.o \
+ dup2.o dup.o abort.o wait.o waitpid.o sleep.o \
+ killpg.o setpgrp.o getpgrp.o
ESRC=execve.c
EOBJ=execve.o execl.o execv.o execle.o
diff --git a/libc/syscall/execve.c b/libc/syscall/execve.c
index aee7182..33643ca 100644
--- a/libc/syscall/execve.c
+++ b/libc/syscall/execve.c
@@ -112,3 +112,97 @@ char ** envp;
return rv;
}
#endif
+
+#ifdef L_execvve
+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
diff --git a/libc/syscall/signal.c b/libc/syscall/signal.c
index dbeac4a..dad3389 100644
--- a/libc/syscall/signal.c
+++ b/libc/syscall/signal.c
@@ -51,7 +51,12 @@ Sig pointer;
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
diff --git a/libc/syscall/syscall.dat b/libc/syscall/syscall.dat
index d83be4f..df61a4f 100644
--- a/libc/syscall/syscall.dat
+++ b/libc/syscall/syscall.dat
@@ -14,18 +14,19 @@
READ 3 3
WRITE 4 3
CLOSE 6 1
-LSEEK 19 3 * NB 2nd arg is a ptr to long not a long.
+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
-FCHMOD 94 X
-FCHOWN 95 X
+FTRUNCATE 93 3
+FCHMOD 94 2
+FCHOWN 95 3
FSYNC 118 1
-FCHDIR 133 X
-LLSEEK 140 X
-READV 145 X
-WRITEV 146 X
-FLOCK 143 X - Use fcntl
+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
#
@@ -67,52 +68,46 @@ MKDIR 39 2
RMDIR 40 1
PIPE 42 1
TIMES 43 1
-PROF 44 X
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
-PHYS 52 X
-LOCK 53 X
-MPX 56 X
+ACCT 51 1 -
SETPGID 57 2
ULIMIT 58 2
UMASK 60 1
CHROOT 61 1
USTAT 62 2
-GETPGRP 65 X
+GETPGRP 65 0 - use getpgid(0)
SETSID 66 X
SIGACTION 67 X
SGETMASK 68 X
SSETMASK 69 X
-SETREUID 70 X
-SETREGID 71 X
+SETREUID 70 2
+SETREGID 71 2
SIGSUSPEND 72 X
SIGPENDING 73 X
SETHOSTNAME 74 2
-SETRLIMIT 75 X
-GETRLIMIT 76 X
-REBOOT 76 3 . The magic number is 0xfee1,0xdead,...
-GETRUSAGE 77 X
+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 X
+REBOOT 88 3 . The magic number is 0xfee1,0xdead,...
MUNMAP 91 X
-TRUNCATE 92 X
-FTRUNCATE 93 X
-GETPRIORITY 96 X
-SETPRIORITY 97 X
+TRUNCATE 92 3
+GETPRIORITY 96 2
+SETPRIORITY 97 3
PROFIL 98 X
-STATFS 99 X
-FSTATFS 100 X
+STATFS 99 2
+FSTATFS 100 2
SOCKETCALL 102 X
SYSLOG 103 X
-SETITIMER 104 X
-GETITIMER 105 X
+SETITIMER 104 3
+GETITIMER 105 2
UNAME 109 1
VHANGUP 111 0
SWAPOFF 115 X
@@ -127,8 +122,8 @@ QUOTACTL 131 X
GETPGID 132 1
SYSFS 135 X
PERSONALITY 136 X
-SETFSUID 138 X
-SETFSGID 139 X
+SETFSUID 138 1
+SETFSGID 139 1
GETDENTS 141 X
SELECT 142 5 *
MSYNC 144 X
diff --git a/libc/syscall/syslibc.c b/libc/syscall/syslibc.c
index 1e604e8..1dcb013 100644
--- a/libc/syscall/syslibc.c
+++ b/libc/syscall/syslibc.c
@@ -4,6 +4,7 @@
*/
#include <sys/types.h>
+#include <errno.h>
#include <time.h>
/* MSDOS has it's own versions */
@@ -124,7 +125,6 @@ int fd;
off_t posn;
int where;
{
- off_t __lseek();
if( __lseek(fd, &posn, where) < 0 ) return -1;
else return posn;
}
@@ -280,6 +280,43 @@ int opts;
}
#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 getpgrp ************************************/
+
+#ifdef L_getpgrp
+int
+getpgrp()
+{
+ return getpgid(0);
+}
+#endif
+
+/********************** Function setpgrp ************************************/
+
+#ifdef L_setpgrp
+int
+setpgrp()
+{
+ return setpgid(0,0);
+}
+#endif
+
/********************** Function sleep ************************************/
#ifdef L_sleep
diff --git a/libc/termios/Makefile b/libc/termios/Makefile
index 5c6d3c1..c978638 100644
--- a/libc/termios/Makefile
+++ b/libc/termios/Makefile
@@ -8,7 +8,7 @@ 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 \
- cfgetospeed.o cfgetispeed.o cfsetospeed.o cfsetispeed.o
+ cfgetospeed.o cfgetispeed.o cfsetospeed.o cfsetispeed.o cfmakeraw.o
OBJ=$(TOBJ) ttyname.o
diff --git a/libc/termios/termios.c b/libc/termios/termios.c
index 3789c38..a617e86 100644
--- a/libc/termios/termios.c
+++ b/libc/termios/termios.c
@@ -140,7 +140,7 @@ int fd;
#endif
#ifdef L_cfgetospeed
-int cfgetospeed(tp)
+speed_t cfgetospeed(tp)
struct termios *tp;
{
return (tp->c_cflag & CBAUD);
@@ -148,7 +148,7 @@ struct termios *tp;
#endif
#ifdef L_cfgetispeed
-int cfgetispeed(tp)
+speed_t cfgetispeed(tp)
struct termios *tp;
{
return (tp->c_cflag & CBAUD);
@@ -181,5 +181,40 @@ struct termios *tp; speed_t speed;
return cfsetospeed(tp, speed);
}
#endif
+
+/* From linux libc-4.6.27 again */
+#ifdef L_cfmakeraw
+/* Copyright (C) 1992 Free Software Foundation, Inc.
+This file is part of the GNU C Library.*/
+
+void
+cfmakeraw(t)
+struct termios *t;
+{
+/* I changed it to the current form according to the suggestions
+ * from Bruce Evans. Thanks Bruce. Please report the problems to
+ * H.J. Lu (hlu@eecs.wsu.edu).
+ */
+
+/*
+ * I took out the bits commented out by #if 1...#else - RHP
+ */
+
+ /* VMIN = 0 means non-blocking for Linux */
+ t->c_cc[VMIN] = 1; t->c_cc[VTIME] = 1;
+ /* clear some bits with &= ~(bits), set others with |= */
+ t->c_cflag &= ~(CSIZE|PARENB|CSTOPB);
+ t->c_cflag |= (CS8|HUPCL|CREAD);
+ t->c_iflag &= ~(IGNBRK|BRKINT|PARMRK|INPCK|ISTRIP);
+ t->c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON|IXOFF);
+ t->c_iflag |= (BRKINT|IGNPAR);
+ t->c_oflag &= ~(OPOST|OLCUC|OCRNL|ONOCR|ONLRET|OFILL|OFDEL);
+ t->c_oflag &= ~(NLDLY|CRDLY|TABDLY|BSDLY|VTDLY|FFDLY);
+ t->c_oflag |= (ONLCR|NL0|CR0|TAB3|BS0|VT0|FF0);
+ t->c_lflag &= ~(ISIG|ICANON|IEXTEN|ECHO|ECHOE|ECHOK|ECHONL);
+ t->c_lflag &= ~(NOFLSH|XCASE);
+ t->c_lflag &= ~(ECHOPRT|ECHOCTL|ECHOKE);
+}
+#endif
#endif