parent
8a4f3c4cb2
commit
1965abf2f7
@ -0,0 +1,12 @@
|
||||
.PHONY: all, execve
|
||||
all: execve
|
||||
|
||||
execve:
|
||||
gcc $@.c -o $@
|
||||
gcc $@2.c -o $@2
|
||||
$@
|
||||
$@2
|
||||
|
||||
clean:
|
||||
-rm execve execve2
|
||||
-rm *.o
|
||||
Binary file not shown.
@ -0,0 +1,62 @@
|
||||
#
|
||||
# Makefile for the Linux library
|
||||
#
|
||||
|
||||
# define this for now. it used in modf.c. it will be dropped when 0.13
|
||||
# kernel is released.
|
||||
XCFLAGS = -DSOFT_387
|
||||
|
||||
LIBS = Libc.a Libm.a Libtermcap.a
|
||||
#AR =/usr2/linux/cross/lib/gar
|
||||
AR =/usr/local/bin/ar
|
||||
#AS =/usr2/linux/cross/lib/gcc-as
|
||||
AS =/usr/local/bin/as
|
||||
#LD =/usr2/linux/cross/bin/gld
|
||||
LD =/usr/local/bin/ld
|
||||
#RANLIB =/usr2/linux/cross/bin/ranlib
|
||||
RANLIB =/usr/local/bin/ranlib
|
||||
LDFLAGS =-s -x
|
||||
CC =/usr/local/bin/gcc -B/usr/local/bin/
|
||||
#CC =/local/bin/gcc-i386-sysv -DPRE_GCC_2
|
||||
INC =-nostdinc -I. -I../soft -I../include
|
||||
#INC =-nostdinc -I. -I../soft \
|
||||
# -I/usr2/linux/src/lib.new/2.0 \
|
||||
# -I/usr2/linux/usr/include
|
||||
CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
|
||||
-fcombine-regs -finline-functions -mstring-insns $(INC)
|
||||
CPP =$(CC) -E $(INC)
|
||||
RM =/usr/bin/rm
|
||||
|
||||
#DIRS =ansi crt dirent grp malloc math misc other posix pwd \
|
||||
# stdio termcap unistd
|
||||
#DIRS =ansi crt dirent grp malloc mlinux misc other posix pwd \
|
||||
# termcap unistd
|
||||
DIRS =ansi crt dirent malloc other posix unistd
|
||||
|
||||
MFLAGS =CC="$(CC)" AR="$(AR)" LD="$(LD)" CPP="$(CPP)" AS="$(AS)" \
|
||||
RANLIB="$(RANLIB)" INC="$(INC)" RM="$(RM)" \
|
||||
XCFLAGS="$(XCFLAGS)"
|
||||
|
||||
# To record the "newlibc" directory, by yjwen.
|
||||
# Maybe a bug exists in the "make" of Linux 0.11.
|
||||
SRCDIR =/usr/root/newlibc
|
||||
|
||||
all:
|
||||
for i in $(DIRS); \
|
||||
do \
|
||||
(cd $(SRCDIR)/$$i; make $(MFLAGS)); \
|
||||
done
|
||||
$(RANLIB) $(LIBS)
|
||||
|
||||
dep:
|
||||
for i in $(DIRS); \
|
||||
do \
|
||||
(cd $(SRCDIR)/$$i; make dep $(MFLAGS)); \
|
||||
done
|
||||
|
||||
clean:
|
||||
rm -f $(LIBS)
|
||||
for i in $(DIRS); \
|
||||
do \
|
||||
(cd $(SRCDIR)/$$i; make clean $(MFLAGS)); \
|
||||
done
|
||||
@ -0,0 +1,73 @@
|
||||
[ Note: This package was submitted to tsx-11.mit.edu by hlu@wsu.edu, on
|
||||
Feb 20, 1992. -TYT ]
|
||||
|
||||
Release Note
|
||||
-------------------------------------------------------------------
|
||||
This is the package of gcc 1.40 with 387 support and the libraries,
|
||||
which include two math libraries, libm.a for with a 387 and libsoft.a
|
||||
for without a 387, and a separate libtermcap.a taken from GNU's
|
||||
tput 1.10.
|
||||
|
||||
This gcc supports 387. There are enough 387 emulations in 0.12
|
||||
kernel to let gcc run without a 387. But libm.a definitely needs a
|
||||
387 for now. If you don't have a 387, use -lsoft instead of -lm.
|
||||
|
||||
GNU's binary utilities 1.9 are also included. They should be also used
|
||||
instead of the old ones.
|
||||
|
||||
The buggy estdio is replaced by BSD stdio (non ANSI). The stdio used in
|
||||
this package is from BSD 4.3, I think it's the one before networking
|
||||
release. Make sure not to define USG stdio.
|
||||
|
||||
Some header files must be replaced by the ones included in this package.
|
||||
|
||||
The -mstring-insns option is no longer needed, which is added to the
|
||||
old gcc for Linux and is not among the options for the standard gcc.
|
||||
|
||||
The -O option may fail when the INLINE functions (string.h) are passed
|
||||
as parameters. There is nothing wrong with compiler(?). They will be
|
||||
fixed in gcc 2.0. You can change the source to avoid that.
|
||||
|
||||
They are some PRE_GCC_2. Please DOT NOT defines them. They are for
|
||||
testing gcc 2.0 only.
|
||||
|
||||
Since there is no ptrace() in the 0.12 kernel. The -g option is
|
||||
permanently disabled. It will be there in gcc 2.0. If you really need it,
|
||||
please drop me a note. I just add a new cc1, called cc1.g, which
|
||||
supports gdb. But it has not been tested.
|
||||
|
||||
I hope somebody will recompile all the binaries with this new gcc and
|
||||
make them available for ftp. The new binaries should be smaller and
|
||||
have less bugs.
|
||||
|
||||
The directory, crt, is used to make a crt0.o you like, although I
|
||||
think the current one is quite reasonable.
|
||||
|
||||
When you use perror (), you may want to declare it first somewhere. The
|
||||
current stdio.h doesn't declare it. It will find its place in some
|
||||
header file when gcc 2.0 is released.
|
||||
|
||||
There is a new 387 math library which is better but has not been
|
||||
tested. You can test it by replacing "math" with "mlinux" of DIRS in
|
||||
Makefile. The hyperbolic functions may be not very accurate when x is
|
||||
very small, like 1e-6. You will see what I mean. I don't think it will
|
||||
cause much trouble.
|
||||
---------------------------------------------------------------------
|
||||
---------------------------------------------------------------------
|
||||
|
||||
INSTALL
|
||||
---------------------------------------------------------------------
|
||||
|
||||
You only need to modify the top level Makefile to suit your system.
|
||||
Make sure compiler and binary utilities are OK as well as header files.
|
||||
|
||||
You should have ../soft in your search path for header files.
|
||||
|
||||
You should only issue make at the top directory. Otherwise, some
|
||||
variables may not be defined.
|
||||
|
||||
You can modify crt0.s to get the crt0.o you like.
|
||||
|
||||
H.J.
|
||||
hlu@eecs.wsu.edu
|
||||
02/18/92
|
||||
@ -0,0 +1 @@
|
||||
To compile the lib, you should set the variable SRCDIR (in Makefile) to correct path.
|
||||
@ -0,0 +1,46 @@
|
||||
#
|
||||
# Makefile for some ansi-library functions
|
||||
#
|
||||
|
||||
LIB =../Libc.a
|
||||
AR =gar
|
||||
AS =gas
|
||||
LD =gld
|
||||
LDFLAGS =-s -x
|
||||
CC =/usr/local/bin/gcc -B/usr/local/bin/
|
||||
#CC =/local/bin/gcc-i386-sysv
|
||||
INC =-nostdinc -I../include
|
||||
CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
|
||||
-finline-functions $(INC)
|
||||
CPP =$(CC) -E $(INC)
|
||||
|
||||
.c.s:
|
||||
$(CC) $(CFLAGS) -S -v -o $*.s $<
|
||||
.s.o:
|
||||
$(CC) -c -o $*.o $<
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
OBJS = abs.o errno.o ctype.o string.o abort.o bsearch.o \
|
||||
strtol.o atoi.o rand.o div.o isatty.o strerror.o \
|
||||
getenv.o atof.o ctime.o qsort.o system.o strftime.o \
|
||||
tzset.o ftime.o
|
||||
# gettimeofday.o # why is it not here? unfinished?
|
||||
|
||||
all: library
|
||||
|
||||
library: $(OBJS)
|
||||
$(AR) uvc $(LIB) $(OBJS)
|
||||
sync
|
||||
|
||||
clean:
|
||||
$(RM) -f core *.o *.a tmp_make
|
||||
for i in *.c;do $(RM) -f `basename $$i .c`.s;done
|
||||
|
||||
dep:
|
||||
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
|
||||
(for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \
|
||||
$(CPP) -M $$i;done) >> tmp_make
|
||||
cp tmp_make Makefile
|
||||
|
||||
### Dependencies:
|
||||
@ -0,0 +1,12 @@
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/*
|
||||
* More of these kind of library routines, please. Linus
|
||||
*/
|
||||
|
||||
void abort(void)
|
||||
{
|
||||
kill(getpid(), SIGABRT);
|
||||
_exit(-1);
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* These I liked writing. More library routines like these. Linus
|
||||
*/
|
||||
|
||||
int abs(int n)
|
||||
{
|
||||
return (n<0)?-n:n;
|
||||
}
|
||||
|
||||
long labs(long n)
|
||||
{
|
||||
return (n<0)?-n:n;
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
#include <ctype.h>
|
||||
|
||||
/*
|
||||
* braindead atof.
|
||||
* Seems to work now. Linus
|
||||
*/
|
||||
|
||||
double atof(char * s)
|
||||
{
|
||||
double f = 0.0;
|
||||
int frac = 0, sign, esign, exp = 0;
|
||||
|
||||
f = 0.0;
|
||||
while (isspace(*s))
|
||||
s++;
|
||||
if ((sign=(*s == '-')) || (*s == '+'))
|
||||
s++;
|
||||
while (isdigit(*s))
|
||||
f = f*10.0 + (*s++ - '0');
|
||||
if (*s == '.') {
|
||||
s++;
|
||||
while (isdigit(*s)) {
|
||||
f = f*10.0 + (*s++ - '0');
|
||||
frac++;
|
||||
}
|
||||
}
|
||||
if (toupper(*s) == 'E') {
|
||||
if ((esign=(*++s == '-')) || (*s == '+'))
|
||||
s++;
|
||||
while (isdigit(*s))
|
||||
exp = exp*10 + (*s++ - '0');
|
||||
if (esign)
|
||||
exp = -exp;
|
||||
}
|
||||
exp -= frac;
|
||||
if (exp>0)
|
||||
while (exp--)
|
||||
f *= 10.0;
|
||||
else
|
||||
while (exp++)
|
||||
f /= 10.0;
|
||||
return sign ? -f : f;
|
||||
}
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* see strtol.c for these. Linus
|
||||
*/
|
||||
|
||||
int atoi(const char *s)
|
||||
{
|
||||
return (int) strtol(s, (char **) NULL, 10);
|
||||
}
|
||||
|
||||
long atol(const char *s)
|
||||
{
|
||||
return strtol(s, (char **) NULL, 10);
|
||||
}
|
||||
|
||||
@ -0,0 +1,56 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
|
||||
/* Perform a binary search for KEY in BASE which has NMEMB elements
|
||||
of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
|
||||
PTR
|
||||
DEFUN(bsearch, (key, base, nmemb, size, compar),
|
||||
register CONST PTR key AND register CONST PTR base AND
|
||||
size_t nmemb AND register size_t size AND
|
||||
register int EXFUN((*compar), (CONST PTR, CONST PTR)))
|
||||
{
|
||||
register size_t l, u, idx;
|
||||
register CONST PTR p;
|
||||
register int comparison;
|
||||
|
||||
l = 0;
|
||||
u = nmemb - 1;
|
||||
while (l <= u)
|
||||
{
|
||||
idx = (l + u) / 2;
|
||||
p = (PTR) (((CONST char *) base) + (idx * size));
|
||||
comparison = (*compar)(key, p);
|
||||
/* Don't make U negative because it will wrap around. */
|
||||
if (comparison < 0)
|
||||
{
|
||||
if (idx == 0)
|
||||
break;
|
||||
u = idx - 1;
|
||||
}
|
||||
else if (comparison > 0)
|
||||
l = idx + 1;
|
||||
else
|
||||
return (PTR) p;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
@ -0,0 +1,142 @@
|
||||
/* mktime, localtime, gmtime */
|
||||
/* written by ERS and placed in the public domain */
|
||||
|
||||
#include <time.h>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define SECS_PER_MIN (60L)
|
||||
#define SECS_PER_HOUR (60*SECS_PER_MIN)
|
||||
#define SECS_PER_DAY (24*SECS_PER_HOUR)
|
||||
#define SECS_PER_YEAR (365*SECS_PER_DAY)
|
||||
#define SECS_PER_LEAPYEAR (SECS_PER_DAY + SECS_PER_YEAR)
|
||||
|
||||
static int days_per_mth[12] =
|
||||
{31, 28, 31, 30,
|
||||
31, 30, 31, 31,
|
||||
30, 31, 30, 31 };
|
||||
|
||||
time_t timezone = -1; /* holds # seconds west of GMT */
|
||||
static int dst = -1; /* whether dst holds in current timezone */
|
||||
|
||||
/*
|
||||
* FIXME: none of these routines is very efficient. Also, none of them
|
||||
* handle dates before Jan 1, 1970.
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* mktime: take a time structure representing the local time (such as is
|
||||
* returned by localtime() and convert it into the standard representation
|
||||
* (as seconds since midnight Jan. 1 1970, GMT).
|
||||
*
|
||||
*/
|
||||
|
||||
time_t mktime(struct tm * t)
|
||||
{
|
||||
time_t s;
|
||||
int y;
|
||||
|
||||
y = t->tm_year - 70;
|
||||
if (y < 0) /* year before 1970 */
|
||||
return (time_t) -1;
|
||||
s = (SECS_PER_YEAR * y) + ( ((y+1)/4) * SECS_PER_DAY);
|
||||
/* extra days for leap years */
|
||||
if ( (y+2)%4 )
|
||||
days_per_mth[1] = 28;
|
||||
else
|
||||
days_per_mth[1] = 29;
|
||||
|
||||
for (y = 0; y < t->tm_mon; y++)
|
||||
s += SECS_PER_DAY * days_per_mth[y];
|
||||
|
||||
s += (t->tm_mday - 1) * SECS_PER_DAY;
|
||||
s += t->tm_hour * SECS_PER_HOUR;
|
||||
s += t->tm_min * SECS_PER_MIN;
|
||||
s += t->tm_sec;
|
||||
return s;
|
||||
}
|
||||
|
||||
static struct tm the_time;
|
||||
|
||||
struct tm *gmtime(const time_t *t)
|
||||
{
|
||||
struct tm *stm = &the_time;
|
||||
time_t time = *t;
|
||||
int year, mday, i;
|
||||
|
||||
if (time < 0) /* negative times are bad */
|
||||
return 0;
|
||||
stm->tm_wday = ((time/SECS_PER_DAY) + 4) % 7;
|
||||
|
||||
year = 70;
|
||||
for (;;) {
|
||||
if (time < SECS_PER_YEAR) break;
|
||||
if ((year % 4) == 0) {
|
||||
if (time < SECS_PER_LEAPYEAR)
|
||||
break;
|
||||
else
|
||||
time -= SECS_PER_LEAPYEAR;
|
||||
}
|
||||
else
|
||||
time -= SECS_PER_YEAR;
|
||||
year++;
|
||||
}
|
||||
stm->tm_year = year;
|
||||
mday = stm->tm_yday = time/SECS_PER_DAY;
|
||||
days_per_mth[1] = (year % 4) ? 28 : 29;
|
||||
for (i = 0; mday >= days_per_mth[i]; i++)
|
||||
mday -= days_per_mth[i];
|
||||
stm->tm_mon = i;
|
||||
stm->tm_mday = mday + 1;
|
||||
time = time % SECS_PER_DAY;
|
||||
stm->tm_hour = time/SECS_PER_HOUR;
|
||||
time = time % SECS_PER_HOUR;
|
||||
stm->tm_min = time/SECS_PER_MIN;
|
||||
stm->tm_sec = time % SECS_PER_MIN;
|
||||
stm->tm_isdst = 0;
|
||||
return stm;
|
||||
}
|
||||
|
||||
/* given a standard time, convert it to a local time */
|
||||
|
||||
struct tm *localtime(const time_t * t)
|
||||
{
|
||||
struct tm *stm;
|
||||
time_t offset; /* seconds between local time and GMT */
|
||||
|
||||
if (timezone == -1) tzset();
|
||||
offset = *t - timezone;
|
||||
stm = gmtime(&offset);
|
||||
if (stm == (struct tm *)NULL) return stm; /* check for illegal time */
|
||||
stm->tm_isdst = (dst == -1) ? -1 : 0;
|
||||
return stm;
|
||||
}
|
||||
|
||||
static const char *day[] =
|
||||
{"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
|
||||
static const char *month[] =
|
||||
{"Jan", "Feb", "Mar", "Apr",
|
||||
"May", "Jun", "Jul", "Aug",
|
||||
"Sep", "Oct", "Nov", "Dec"};
|
||||
|
||||
char * asctime(const struct tm * time)
|
||||
{
|
||||
static char buf[40];
|
||||
|
||||
if (time == (struct tm *)NULL)
|
||||
strcpy(buf, "??? ??? ?? ??:??:?? ????\n");
|
||||
else
|
||||
sprintf(buf, "%.3s %.3s %2d %02d:%02d:%02d %04d\n",
|
||||
day[time->tm_wday], month[time->tm_mon], time->tm_mday,
|
||||
time->tm_hour, time->tm_min, time->tm_sec, 1900+time->tm_year);
|
||||
return(buf);
|
||||
}
|
||||
|
||||
char *ctime(const time_t *tp)
|
||||
{
|
||||
return(asctime(localtime(tp)));
|
||||
}
|
||||
@ -0,0 +1,29 @@
|
||||
#include <ctype.h>
|
||||
|
||||
char _ctmp;
|
||||
unsigned char _ctype[] = {0x00, /* EOF */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 0-7 */
|
||||
_C,_C|_S,_C|_S,_C|_S,_C|_S,_C|_S,_C,_C, /* 8-15 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 16-23 */
|
||||
_C,_C,_C,_C,_C,_C,_C,_C, /* 24-31 */
|
||||
_S|_SP,_P,_P,_P,_P,_P,_P,_P, /* 32-39 */
|
||||
_P,_P,_P,_P,_P,_P,_P,_P, /* 40-47 */
|
||||
_D,_D,_D,_D,_D,_D,_D,_D, /* 48-55 */
|
||||
_D,_D,_P,_P,_P,_P,_P,_P, /* 56-63 */
|
||||
_P,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U|_X,_U, /* 64-71 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 72-79 */
|
||||
_U,_U,_U,_U,_U,_U,_U,_U, /* 80-87 */
|
||||
_U,_U,_U,_P,_P,_P,_P,_P, /* 88-95 */
|
||||
_P,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L|_X,_L, /* 96-103 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 104-111 */
|
||||
_L,_L,_L,_L,_L,_L,_L,_L, /* 112-119 */
|
||||
_L,_L,_L,_P,_P,_P,_P,_C, /* 120-127 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 128-143 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 144-159 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 160-175 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 176-191 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 192-207 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 208-223 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, /* 224-239 */
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}; /* 240-255 */
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/*
|
||||
* Ok, there are probably buggy: sign etc. Linus
|
||||
*/
|
||||
|
||||
div_t div(int num, int denom)
|
||||
{
|
||||
div_t res;
|
||||
|
||||
__asm__("idivl %3":"=a" (res.quot),"=d" (res.rem)
|
||||
:"0" (num),"g" (denom));
|
||||
return res;
|
||||
}
|
||||
|
||||
ldiv_t ldiv(long num, long denom)
|
||||
{
|
||||
ldiv_t res;
|
||||
|
||||
__asm__("idivl %3":"=a" (res.quot),"=d" (res.rem)
|
||||
:"0" (num),"g" (denom));
|
||||
return res;
|
||||
}
|
||||
|
||||
@ -0,0 +1,5 @@
|
||||
/*
|
||||
* Great file. Linus
|
||||
*/
|
||||
|
||||
int errno;
|
||||
@ -0,0 +1,19 @@
|
||||
#include <sys/timeb.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/*
|
||||
* I simply don't know what all these time-fns should do. Linus
|
||||
*/
|
||||
|
||||
int ftime(struct timeb * tp)
|
||||
{
|
||||
time_t t;
|
||||
|
||||
if (time(&t)<0)
|
||||
return -1;
|
||||
tp->time = t;
|
||||
tp->millitm = 0;
|
||||
tp->timezone = -120;
|
||||
tp->dstflag = 0;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,25 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Simple getenv. Linus
|
||||
*/
|
||||
|
||||
extern char ** environ;
|
||||
|
||||
char * getenv(const char * name)
|
||||
{
|
||||
int len;
|
||||
char * tmp;
|
||||
char ** env;
|
||||
|
||||
len = strlen(name);
|
||||
if (env=environ)
|
||||
while (tmp=*(env++)) {
|
||||
if (strncmp(name,tmp,len))
|
||||
continue;
|
||||
if (tmp[len]=='=')
|
||||
return tmp+len+1;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
@ -0,0 +1,17 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/*
|
||||
* Another of these time-functions. I sure wish I knew what I am doing.
|
||||
* Linus
|
||||
*/
|
||||
|
||||
int gettimeofday(struct timeval * tp, struct timezone * tz)
|
||||
{
|
||||
tp->tv_sec = time(NULL);
|
||||
tp->tv_usec = 0;
|
||||
tz->tz_minuteswest = -120;
|
||||
tz->tz_dsttime = DST_NONE;
|
||||
return 0;
|
||||
}
|
||||
@ -0,0 +1,15 @@
|
||||
#include <unistd.h>
|
||||
#include <termios.h>
|
||||
|
||||
/*
|
||||
* Simple isatty for Linux.
|
||||
*/
|
||||
|
||||
int isatty(int fd)
|
||||
{
|
||||
struct termios tmp;
|
||||
|
||||
if (ioctl(fd,TCGETS,&tmp)<0)
|
||||
return (0);
|
||||
return 1;
|
||||
}
|
||||
@ -0,0 +1,239 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
Written by Douglas C. Schmidt (schmidt@ics.uci.edu).
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
/* Byte-wise swap two items of size SIZE. */
|
||||
#define SWAP(a, b, size) \
|
||||
do \
|
||||
{ \
|
||||
register size_t __size = (size); \
|
||||
register char *__a = (a), *__b = (b); \
|
||||
do \
|
||||
{ \
|
||||
char __tmp = *__a; \
|
||||
*__a++ = *__b; \
|
||||
*__b++ = __tmp; \
|
||||
} while (--__size > 0); \
|
||||
} while (0)
|
||||
|
||||
/* Discontinue quicksort algorithm when partition gets below this size.
|
||||
This particular magic number was chosen to work best on a Sun 4/260. */
|
||||
#define MAX_THRESH 4
|
||||
|
||||
/* Stack node declarations used to store unfulfilled partition obligations. */
|
||||
typedef struct
|
||||
{
|
||||
char *lo;
|
||||
char *hi;
|
||||
} stack_node;
|
||||
|
||||
/* The next 4 #defines implement a very fast in-line stack abstraction. */
|
||||
#define STACK_SIZE (8 * sizeof(unsigned long int))
|
||||
#define PUSH(low, high) ((void) ((top->lo = (low)), (top->hi = (high)), ++top))
|
||||
#define POP(low, high) ((void) (--top, (low = top->lo), (high = top->hi)))
|
||||
#define STACK_NOT_EMPTY (stack < top)
|
||||
|
||||
|
||||
/* Order size using quicksort. This implementation incorporates
|
||||
four optimizations discussed in Sedgewick:
|
||||
|
||||
1. Non-recursive, using an explicit stack of pointer that store the
|
||||
next array partition to sort. To save time, this maximum amount
|
||||
of space required to store an array of MAX_INT is allocated on the
|
||||
stack. Assuming a 32-bit integer, this needs only 32 *
|
||||
sizeof(stack_node) == 136 bits. Pretty cheap, actually.
|
||||
|
||||
2. Chose the pivot element using a median-of-three decision tree.
|
||||
This reduces the probability of selecting a bad pivot value and
|
||||
eliminates certain extraneous comparisons.
|
||||
|
||||
3. Only quicksorts TOTAL_ELEMS / MAX_THRESH partitions, leaving
|
||||
insertion sort to order the MAX_THRESH items within each partition.
|
||||
This is a big win, since insertion sort is faster for small, mostly
|
||||
sorted array segements.
|
||||
|
||||
4. The larger of the two sub-partitions is always pushed onto the
|
||||
stack first, with the algorithm then concentrating on the
|
||||
smaller partition. This *guarantees* no more than log (n)
|
||||
stack size is needed (actually O(1) in this case)! */
|
||||
|
||||
void
|
||||
DEFUN(qsort, (pbase, total_elems, size, cmp),
|
||||
PTR CONST pbase AND size_t total_elems AND size_t size AND
|
||||
int EXFUN((*cmp), (CONST PTR, CONST PTR)))
|
||||
{
|
||||
register char *base_ptr = (char *) pbase;
|
||||
|
||||
/* Allocating SIZE bytes for a pivot buffer facilitates a better
|
||||
algorithm below since we can do comparisons directly on the pivot. */
|
||||
char *pivot_buffer = (char *) __alloca (size);
|
||||
CONST size_t max_thresh = MAX_THRESH * size;
|
||||
|
||||
if (total_elems > MAX_THRESH)
|
||||
{
|
||||
char *lo = base_ptr;
|
||||
char *hi = &lo[size * (total_elems - 1)];
|
||||
/* Largest size needed for 32-bit int!!! */
|
||||
stack_node stack[STACK_SIZE];
|
||||
stack_node *top = stack + 1;
|
||||
|
||||
while (STACK_NOT_EMPTY)
|
||||
{
|
||||
char *left_ptr;
|
||||
char *right_ptr;
|
||||
|
||||
char *pivot = pivot_buffer;
|
||||
|
||||
/* Select median value from among LO, MID, and HI. Rearrange
|
||||
LO and HI so the three values are sorted. This lowers the
|
||||
probability of picking a pathological pivot value and
|
||||
skips a comparison for both the LEFT_PTR and RIGHT_PTR. */
|
||||
|
||||
char *mid = lo + size * ((hi - lo) / size >> 1);
|
||||
|
||||
if ((*cmp)((PTR) mid, (PTR) lo) < 0)
|
||||
SWAP(mid, lo, size);
|
||||
if ((*cmp)((PTR) hi, (PTR) mid) < 0)
|
||||
SWAP(mid, hi, size);
|
||||
else
|
||||
goto jump_over;
|
||||
if ((*cmp)((PTR) mid, (PTR) lo) < 0)
|
||||
SWAP(mid, lo, size);
|
||||
jump_over:;
|
||||
memcpy(pivot, mid, size);
|
||||
pivot = pivot_buffer;
|
||||
|
||||
left_ptr = lo + size;
|
||||
right_ptr = hi - size;
|
||||
|
||||
/* Here's the famous ``collapse the walls'' section of quicksort.
|
||||
Gotta like those tight inner loops! They are the main reason
|
||||
that this algorithm runs much faster than others. */
|
||||
do
|
||||
{
|
||||
while ((*cmp)((PTR) left_ptr, (PTR) pivot) < 0)
|
||||
left_ptr += size;
|
||||
|
||||
while ((*cmp)((PTR) pivot, (PTR) right_ptr) < 0)
|
||||
right_ptr -= size;
|
||||
|
||||
if (left_ptr < right_ptr)
|
||||
{
|
||||
SWAP(left_ptr, right_ptr, size);
|
||||
left_ptr += size;
|
||||
right_ptr -= size;
|
||||
}
|
||||
else if (left_ptr == right_ptr)
|
||||
{
|
||||
left_ptr += size;
|
||||
right_ptr -= size;
|
||||
break;
|
||||
}
|
||||
}
|
||||
while (left_ptr <= right_ptr);
|
||||
|
||||
/* Set up pointers for next iteration. First determine whether
|
||||
left and right partitions are below the threshold size. If so,
|
||||
ignore one or both. Otherwise, push the larger partition's
|
||||
bounds on the stack and continue sorting the smaller one. */
|
||||
|
||||
if ((size_t) (right_ptr - lo) <= max_thresh)
|
||||
{
|
||||
if ((size_t) (hi - left_ptr) <= max_thresh)
|
||||
/* Ignore both small partitions. */
|
||||
POP(lo, hi);
|
||||
else
|
||||
/* Ignore small left partition. */
|
||||
lo = left_ptr;
|
||||
}
|
||||
else if ((size_t) (hi - left_ptr) <= max_thresh)
|
||||
/* Ignore small right partition. */
|
||||
hi = right_ptr;
|
||||
else if ((right_ptr - lo) > (hi - left_ptr))
|
||||
{
|
||||
/* Push larger left partition indices. */
|
||||
PUSH(lo, right_ptr);
|
||||
lo = left_ptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Push larger right partition indices. */
|
||||
PUSH(left_ptr, hi);
|
||||
hi = right_ptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Once the BASE_PTR array is partially sorted by quicksort the rest
|
||||
is completely sorted using insertion sort, since this is efficient
|
||||
for partitions below MAX_THRESH size. BASE_PTR points to the beginning
|
||||
of the array to sort, and END_PTR points at the very last element in
|
||||
the array (*not* one beyond it!). */
|
||||
|
||||
#define min(x, y) ((x) < (y) ? (x) : (y))
|
||||
|
||||
{
|
||||
char *CONST end_ptr = &base_ptr[size * (total_elems - 1)];
|
||||
char *tmp_ptr = base_ptr;
|
||||
char *thresh = min(end_ptr, base_ptr + max_thresh);
|
||||
register char *run_ptr;
|
||||
|
||||
/* Find smallest element in first threshold and place it at the
|
||||
array's beginning. This is the smallest array element,
|
||||
and the operation speeds up insertion sort's inner loop. */
|
||||
|
||||
for (run_ptr = tmp_ptr + size; run_ptr <= thresh; run_ptr += size)
|
||||
if ((*cmp)((PTR) run_ptr, (PTR) tmp_ptr) < 0)
|
||||
tmp_ptr = run_ptr;
|
||||
|
||||
if (tmp_ptr != base_ptr)
|
||||
SWAP(tmp_ptr, base_ptr, size);
|
||||
|
||||
/* Insertion sort, running from left-hand-side up to right-hand-side. */
|
||||
|
||||
run_ptr = base_ptr + size;
|
||||
while ((run_ptr += size) <= end_ptr)
|
||||
{
|
||||
tmp_ptr = run_ptr - size;
|
||||
while ((*cmp)((PTR) run_ptr, (PTR) tmp_ptr) < 0)
|
||||
tmp_ptr -= size;
|
||||
|
||||
tmp_ptr += size;
|
||||
if (tmp_ptr != run_ptr)
|
||||
{
|
||||
char *trav;
|
||||
|
||||
trav = run_ptr + size;
|
||||
while (--trav >= run_ptr)
|
||||
{
|
||||
char c = *trav;
|
||||
char *hi, *lo;
|
||||
|
||||
for (hi = lo = trav; (lo -= size) >= tmp_ptr; hi = lo)
|
||||
*hi = *lo;
|
||||
*hi = c;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
/* we're useing GGUBS - should work, but it isn't the best algorithm */
|
||||
|
||||
static unsigned long _seed;
|
||||
|
||||
int rand(void)
|
||||
{
|
||||
if (!_seed)
|
||||
_seed++;
|
||||
_seed *= 16807;
|
||||
_seed %= 0x7fffffff;
|
||||
return _seed-1;
|
||||
}
|
||||
|
||||
void srand(unsigned int seed)
|
||||
{
|
||||
_seed = seed;
|
||||
}
|
||||
@ -0,0 +1,60 @@
|
||||
#include <string.h>
|
||||
|
||||
/*
|
||||
* Yeah, I obviously put down a lot of thinking in the error messages.
|
||||
* Linus
|
||||
*/
|
||||
|
||||
char * sys_errlist[] = {
|
||||
"Unknown error",
|
||||
"Not owner",
|
||||
"No such file or directory",
|
||||
"No such process",
|
||||
"Interrupted system call",
|
||||
"I/O error",
|
||||
"No such device",
|
||||
"Arg list too big",
|
||||
"Unable to exec binary file",
|
||||
"Bad file nr",
|
||||
"No children",
|
||||
"Try again",
|
||||
"Out of memory",
|
||||
"EACCES",
|
||||
"EFAULT",
|
||||
"ENOTBLK",
|
||||
"EBUSY",
|
||||
"EEXIST",
|
||||
"EXDEV",
|
||||
"ENODEV",
|
||||
"ENOTDIR",
|
||||
"EISDIR",
|
||||
"EINVAL",
|
||||
"ENFILE",
|
||||
"EMFILE",
|
||||
"ENOTTY",
|
||||
"ETXTBSY",
|
||||
"EFBIG",
|
||||
"ENOSPC",
|
||||
"ESPIPE",
|
||||
"EROFS",
|
||||
"EMLINK",
|
||||
"EPIPE",
|
||||
"EDOM",
|
||||
"ERANGE",
|
||||
"EDEADLK",
|
||||
"ENAMETOOLONG",
|
||||
"ENOLCK",
|
||||
"ENOSYS",
|
||||
"ENOTEMPTY"};
|
||||
|
||||
#define NR_ERRORS ((sizeof (sys_errlist))/(sizeof(char *))-1)
|
||||
|
||||
int sys_nerr = NR_ERRORS;
|
||||
|
||||
char * strerror(int n)
|
||||
{
|
||||
if (n<0 || n>NR_ERRORS)
|
||||
return ("unknown error");
|
||||
return sys_errlist[n];
|
||||
}
|
||||
|
||||
@ -0,0 +1,312 @@
|
||||
/*
|
||||
* strftime.c
|
||||
*
|
||||
* Public-domain relatively quick-and-dirty implemenation of
|
||||
* ANSI library routine for System V Unix systems.
|
||||
*
|
||||
* If you want stuff in the System V ascftime routine, add the SYSV_EXT define.
|
||||
* For stuff needed to implement the P1003.2 date command, add POSIX2_DATE.
|
||||
*
|
||||
* The code for %c, %x, and %X is my best guess as to what's "appropriate".
|
||||
* This version ignores LOCALE information.
|
||||
* It also doesn't worry about multi-byte characters.
|
||||
* So there.
|
||||
*
|
||||
* Arnold Robbins
|
||||
* January, February, March, 1991
|
||||
*
|
||||
* Fixes from ado@elsie.nci.nih.gov
|
||||
* February 1991
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <ctype.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
static int weeknumber(const struct tm *timeptr, int firstweekday);
|
||||
|
||||
static char *tzname[2] = {"",""};
|
||||
int daylight = 1;
|
||||
|
||||
#define SYSV_EXT 1 /* stuff in System V ascftime routine */
|
||||
#define POSIX2_DATE 1 /* stuff in Posix 1003.2 date command */
|
||||
#define VMS_EXT 1 /* include %V for VMS date format */
|
||||
|
||||
#if defined(POSIX2_DATE) && ! defined(SYSV_EXT)
|
||||
#define SYSV_EXT 1
|
||||
#endif
|
||||
|
||||
/* strftime --- produce formatted time */
|
||||
|
||||
size_t strftime(char *s, size_t maxsize, const char *format,
|
||||
const struct tm *timeptr)
|
||||
{
|
||||
char *endp = s + maxsize;
|
||||
char *start = s;
|
||||
char tbuf[100];
|
||||
int i;
|
||||
static short first = 1;
|
||||
|
||||
/* various tables, useful in North America */
|
||||
static char *days_a[] = {
|
||||
"Sun", "Mon", "Tue", "Wed",
|
||||
"Thu", "Fri", "Sat",
|
||||
};
|
||||
static char *days_l[] = {
|
||||
"Sunday", "Monday", "Tuesday", "Wednesday",
|
||||
"Thursday", "Friday", "Saturday",
|
||||
};
|
||||
static char *months_a[] = {
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
|
||||
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
};
|
||||
static char *months_l[] = {
|
||||
"January", "February", "March", "April",
|
||||
"May", "June", "July", "August", "September",
|
||||
"October", "November", "December",
|
||||
};
|
||||
static char *ampm[] = { "AM", "PM", };
|
||||
|
||||
if (s == NULL || format == NULL || timeptr == NULL || maxsize == 0)
|
||||
return 0;
|
||||
|
||||
if (strchr(format, '%') == NULL && strlen(format) + 1 >= maxsize)
|
||||
return 0;
|
||||
|
||||
if (first) {
|
||||
tzset();
|
||||
first = 0;
|
||||
}
|
||||
|
||||
for (; *format && s < endp - 1; format++) {
|
||||
tbuf[0] = '\0';
|
||||
if (*format != '%') {
|
||||
*s++ = *format;
|
||||
continue;
|
||||
}
|
||||
again:
|
||||
switch (*++format) {
|
||||
case '\0':
|
||||
*s++ = '%';
|
||||
goto out;
|
||||
|
||||
case '%':
|
||||
*s++ = '%';
|
||||
continue;
|
||||
|
||||
case 'a': /* abbreviated weekday name */
|
||||
if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
|
||||
strcpy(tbuf, "?");
|
||||
else
|
||||
strcpy(tbuf, days_a[timeptr->tm_wday]);
|
||||
break;
|
||||
|
||||
case 'A': /* full weekday name */
|
||||
if (timeptr->tm_wday < 0 || timeptr->tm_wday > 6)
|
||||
strcpy(tbuf, "?");
|
||||
else
|
||||
strcpy(tbuf, days_l[timeptr->tm_wday]);
|
||||
break;
|
||||
|
||||
#ifdef SYSV_EXT
|
||||
case 'h': /* abbreviated month name */
|
||||
#endif
|
||||
case 'b': /* abbreviated month name */
|
||||
if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
|
||||
strcpy(tbuf, "?");
|
||||
else
|
||||
strcpy(tbuf, months_a[timeptr->tm_mon]);
|
||||
break;
|
||||
|
||||
case 'B': /* full month name */
|
||||
if (timeptr->tm_mon < 0 || timeptr->tm_mon > 11)
|
||||
strcpy(tbuf, "?");
|
||||
else
|
||||
strcpy(tbuf, months_l[timeptr->tm_mon]);
|
||||
break;
|
||||
|
||||
case 'c': /* appropriate date and time representation */
|
||||
sprintf(tbuf, "%s %s %2d %02d:%02d:%02d %d",
|
||||
days_a[timeptr->tm_wday],
|
||||
months_a[timeptr->tm_mon],
|
||||
timeptr->tm_mday,
|
||||
timeptr->tm_hour,
|
||||
timeptr->tm_min,
|
||||
timeptr->tm_sec,
|
||||
timeptr->tm_year + 1900);
|
||||
break;
|
||||
|
||||
case 'd': /* day of the month, 01 - 31 */
|
||||
sprintf(tbuf, "%02d", timeptr->tm_mday);
|
||||
break;
|
||||
|
||||
case 'H': /* hour, 24-hour clock, 00 - 23 */
|
||||
sprintf(tbuf, "%02d", timeptr->tm_hour);
|
||||
break;
|
||||
|
||||
case 'I': /* hour, 12-hour clock, 01 - 12 */
|
||||
i = timeptr->tm_hour;
|
||||
if (i == 0)
|
||||
i = 12;
|
||||
else if (i > 12)
|
||||
i -= 12;
|
||||
sprintf(tbuf, "%02d", i);
|
||||
break;
|
||||
|
||||
case 'j': /* day of the year, 001 - 366 */
|
||||
sprintf(tbuf, "%03d", timeptr->tm_yday + 1);
|
||||
break;
|
||||
|
||||
case 'm': /* month, 01 - 12 */
|
||||
sprintf(tbuf, "%02d", timeptr->tm_mon + 1);
|
||||
break;
|
||||
|
||||
case 'M': /* minute, 00 - 59 */
|
||||
sprintf(tbuf, "%02d", timeptr->tm_min);
|
||||
break;
|
||||
|
||||
case 'p': /* am or pm based on 12-hour clock */
|
||||
if (timeptr->tm_hour < 12)
|
||||
strcpy(tbuf, ampm[0]);
|
||||
else
|
||||
strcpy(tbuf, ampm[1]);
|
||||
break;
|
||||
|
||||
case 'S': /* second, 00 - 61 */
|
||||
sprintf(tbuf, "%02d", timeptr->tm_sec);
|
||||
break;
|
||||
|
||||
case 'U': /* week of year, Sunday is first day of week */
|
||||
sprintf(tbuf, "%d", weeknumber(timeptr, 0));
|
||||
break;
|
||||
|
||||
case 'w': /* weekday, Sunday == 0, 0 - 6 */
|
||||
sprintf(tbuf, "%d", timeptr->tm_wday);
|
||||
break;
|
||||
|
||||
case 'W': /* week of year, Monday is first day of week */
|
||||
sprintf(tbuf, "%d", weeknumber(timeptr, 1));
|
||||
break;
|
||||
|
||||
case 'x': /* appropriate date representation */
|
||||
sprintf(tbuf, "%s %s %2d %d",
|
||||
days_a[timeptr->tm_wday],
|
||||
months_a[timeptr->tm_mon],
|
||||
timeptr->tm_mday,
|
||||
timeptr->tm_year + 1900);
|
||||
break;
|
||||
|
||||
case 'X': /* appropriate time representation */
|
||||
sprintf(tbuf, "%02d:%02d:%02d",
|
||||
timeptr->tm_hour,
|
||||
timeptr->tm_min,
|
||||
timeptr->tm_sec);
|
||||
break;
|
||||
|
||||
case 'y': /* year without a century, 00 - 99 */
|
||||
i = timeptr->tm_year % 100;
|
||||
sprintf(tbuf, "%d", i);
|
||||
break;
|
||||
|
||||
case 'Y': /* year with century */
|
||||
sprintf(tbuf, "%d", 1900 + timeptr->tm_year);
|
||||
break;
|
||||
|
||||
case 'Z': /* time zone name or abbrevation */
|
||||
i = 0;
|
||||
if (daylight && timeptr->tm_isdst)
|
||||
i = 1;
|
||||
strcpy(tbuf, tzname[i]);
|
||||
break;
|
||||
|
||||
#ifdef SYSV_EXT
|
||||
case 'n': /* same as \n */
|
||||
tbuf[0] = '\n';
|
||||
tbuf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 't': /* same as \t */
|
||||
tbuf[0] = '\t';
|
||||
tbuf[1] = '\0';
|
||||
break;
|
||||
|
||||
case 'D': /* date as %m/%d/%y */
|
||||
strftime(tbuf, sizeof tbuf, "%m/%d/%y", timeptr);
|
||||
break;
|
||||
|
||||
case 'e': /* day of month, blank padded */
|
||||
sprintf(tbuf, "%2d", timeptr->tm_mday);
|
||||
break;
|
||||
|
||||
case 'r': /* time as %I:%M:%S %p */
|
||||
strftime(tbuf, sizeof tbuf, "%I:%M:%S %p", timeptr);
|
||||
break;
|
||||
|
||||
case 'R': /* time as %H:%M */
|
||||
strftime(tbuf, sizeof tbuf, "%H:%M", timeptr);
|
||||
break;
|
||||
|
||||
case 'T': /* time as %H:%M:%S */
|
||||
strftime(tbuf, sizeof tbuf, "%H:%M:%S", timeptr);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef VMS_EXT
|
||||
case 'V': /* date as dd-bbb-YYYY */
|
||||
sprintf(tbuf, "%2d-%3.3s-%4d",
|
||||
timeptr->tm_mday,
|
||||
months_a[timeptr->tm_mon],
|
||||
timeptr->tm_year + 1900);
|
||||
for (i = 3; i < 6; i++)
|
||||
if (islower(tbuf[i]))
|
||||
tbuf[i] = toupper(tbuf[i]);
|
||||
break;
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef POSIX2_DATE
|
||||
case 'C':
|
||||
sprintf(tbuf, "%02d", (timeptr->tm_year + 1900) / 100);
|
||||
break;
|
||||
|
||||
|
||||
case 'E':
|
||||
case 'O':
|
||||
/* POSIX locale extensions, ignored for now */
|
||||
goto again;
|
||||
#endif
|
||||
default:
|
||||
tbuf[0] = '%';
|
||||
tbuf[1] = *format;
|
||||
tbuf[2] = '\0';
|
||||
break;
|
||||
}
|
||||
i = strlen(tbuf);
|
||||
if (i)
|
||||
if (s + i < endp - 1) {
|
||||
strcpy(s, tbuf);
|
||||
s += i;
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
out:
|
||||
if (s < endp && *format == '\0') {
|
||||
*s = '\0';
|
||||
return (s - start);
|
||||
} else
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* weeknumber --- figure how many weeks into the year */
|
||||
|
||||
static int weeknumber(const struct tm *timeptr, int firstweekday)
|
||||
{
|
||||
if (firstweekday == 0)
|
||||
return (timeptr->tm_yday + 7 - timeptr->tm_wday) / 7;
|
||||
else
|
||||
return (timeptr->tm_yday + 7 -
|
||||
(timeptr->tm_wday ? (timeptr->tm_wday - 1) : 6)) / 7;
|
||||
}
|
||||
@ -0,0 +1,13 @@
|
||||
#ifndef __GNUC__
|
||||
#error I want gcc!
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Quick and dirty way of getting all the string routines into the lib.
|
||||
* Linus
|
||||
*/
|
||||
|
||||
#define extern
|
||||
#define inline
|
||||
#define __LIBRARY__
|
||||
#include <string.h>
|
||||
@ -0,0 +1,91 @@
|
||||
#include <stdlib.h>
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <errno.h>
|
||||
|
||||
/*
|
||||
* strtoul etc... Hope it works. Linus
|
||||
*/
|
||||
|
||||
/* ok, this isn't portable, but it works */
|
||||
|
||||
#define do_mul(base,result,overflow) \
|
||||
__asm__("mull %3":"=a" (result),"=d" (overflow):"0" (result),"g" (base))
|
||||
|
||||
#define NUM(c) (isdigit(c)?c-'0':islower(c)?c-'a'+10:isupper(c)?c-'A'+10:127)
|
||||
|
||||
static unsigned long _strtoul(const char * s, char **endp, int base)
|
||||
{
|
||||
unsigned long overflow,num,result;
|
||||
|
||||
if (!base)
|
||||
if (*s=='0')
|
||||
if (toupper(s[1])=='X')
|
||||
base=16;
|
||||
else
|
||||
base=8;
|
||||
else
|
||||
base=10;
|
||||
if (base == 16 && *s=='0' && toupper(s[1])=='X')
|
||||
s += 2;
|
||||
overflow = 1; /* forces error if no while */
|
||||
result = 0;
|
||||
while ((num=NUM(*s))<base) {
|
||||
s++;
|
||||
do_mul(base,result,overflow);
|
||||
if ((result += num)<num)
|
||||
overflow=1;
|
||||
if (overflow) break;
|
||||
}
|
||||
if (overflow) {
|
||||
result = ULONG_MAX;
|
||||
errno = ERANGE;
|
||||
}
|
||||
*endp = (char *) s;
|
||||
return result;
|
||||
}
|
||||
|
||||
long strtol(const char * s, char **endp, int base)
|
||||
{
|
||||
int sign;
|
||||
unsigned long result;
|
||||
char * tmp;
|
||||
|
||||
if (!endp) /* tmp is never really used, this just */
|
||||
endp = &tmp; /* is a hack so that we never have to check */
|
||||
*endp = (char *) s;
|
||||
if (base<0 || base==1 || base>36)
|
||||
return LONG_MAX;
|
||||
while (isspace(*s))
|
||||
s++;
|
||||
*endp = (char *) s;
|
||||
if (sign=(*s=='-'))
|
||||
s++;
|
||||
result = _strtoul(s,endp,base);
|
||||
if (!sign && result > (unsigned) LONG_MAX) {
|
||||
errno = ERANGE;
|
||||
return LONG_MAX;
|
||||
} else if (sign && result > (unsigned) LONG_MAX+1) {
|
||||
errno = ERANGE;
|
||||
return LONG_MIN;
|
||||
}
|
||||
return sign?-result:result;
|
||||
}
|
||||
|
||||
unsigned long strtoul(const char * s, char **endp, int base)
|
||||
{
|
||||
char * tmp;
|
||||
|
||||
if (!endp) /* tmp is never really used, this just */
|
||||
endp = &tmp; /* is a hack so that we never have to check */
|
||||
*endp = (char *) s;
|
||||
if (base<0 || base==1 || base>36) {
|
||||
errno = ERANGE;
|
||||
return ULONG_MAX;
|
||||
}
|
||||
while (isspace(*s))
|
||||
s++;
|
||||
*endp = (char *) s;
|
||||
return _strtoul(s,endp,base);
|
||||
}
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
#include <stdlib.h>
|
||||
#include <signal.h>
|
||||
#include <sys/wait.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*
|
||||
* Urgh. If this works I'm surprised. Linus
|
||||
*
|
||||
* Should be updated to use sigactions, I think.
|
||||
*/
|
||||
|
||||
int system(const char * cmd)
|
||||
{
|
||||
int ret, pid, waitstat;
|
||||
void (*sigint) (), (*sigquit) ();
|
||||
|
||||
if ((pid = fork()) == 0) {
|
||||
execl("/bin/sh", "sh", "-c", cmd, NULL);
|
||||
exit(127);
|
||||
}
|
||||
if (pid < 0) return(127 << 8);
|
||||
sigint = signal(SIGINT, SIG_IGN);
|
||||
sigquit = signal(SIGQUIT, SIG_IGN);
|
||||
while ((waitstat = wait(&ret)) != pid && waitstat != -1);
|
||||
if (waitstat == -1) ret = -1;
|
||||
signal(SIGINT, sigint);
|
||||
signal(SIGQUIT, sigquit);
|
||||
return(ret);
|
||||
}
|
||||
@ -0,0 +1,47 @@
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sys/time.h>
|
||||
|
||||
/*
|
||||
* More of these damn time-functions. I hope somebody has a complete
|
||||
* PD library out there. Linus
|
||||
*/
|
||||
|
||||
static char tz1[1024];
|
||||
static char tz2[1024];
|
||||
|
||||
char *tzname[2] = {
|
||||
tz1, tz2
|
||||
};
|
||||
extern int daylight;
|
||||
|
||||
/* I don't know how to implement this - the results are ... */
|
||||
static char *timezone(int minutes, int dst)
|
||||
{
|
||||
static char tmp[40];
|
||||
|
||||
if (dst)
|
||||
minutes += 60;
|
||||
strcpy(tmp,"GMT");
|
||||
if (!minutes)
|
||||
return tmp;
|
||||
if (minutes<0) {
|
||||
tmp[3] = '-';
|
||||
minutes = -minutes;
|
||||
} else
|
||||
tmp[3] = '+';
|
||||
tmp[4] = '0'+(minutes/60);
|
||||
tmp[5] = 0;
|
||||
return tmp;
|
||||
}
|
||||
|
||||
void tzset(void)
|
||||
{
|
||||
struct timeval tp;
|
||||
struct timezone tz;
|
||||
|
||||
gettimeofday(&tp, &tz);
|
||||
strcpy(tz1, timezone(tz.tz_minuteswest, 0));
|
||||
strcpy(tz2, timezone(tz.tz_minuteswest, 1));
|
||||
daylight = tz.tz_dsttime;
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
This is the file "copying.dj".
|
||||
|
||||
Copyright Information for sources and executables that are marked
|
||||
Copyright (C) DJ Delorie
|
||||
24 Kirsten Ave
|
||||
Rochester NH 03867-2954
|
||||
|
||||
This document is Copyright (C) DJ Delorie and may be distributed
|
||||
verbatim, but changing it is not allowed.
|
||||
|
||||
Source code and executables copyright DJ Delorie are referred to as
|
||||
"djcode" in this document.
|
||||
|
||||
Source code copyright DJ Delorie is distributed under the terms of the
|
||||
GNU General Public Licence, with the following exceptions:
|
||||
|
||||
1 If the user of this software develops an application that requires
|
||||
djcode to run, and that application is distributed under the terms
|
||||
of the GNU General Public License (GPL), a binary executable of
|
||||
djcode may be distributed with binary executables of the application,
|
||||
and source files for djcode must be available with source files for
|
||||
the application, under the terms of the GNU GPL.
|
||||
|
||||
2 If the user of this software develops an application that requires
|
||||
djcode to run, and that application is NOT distributed under the terms
|
||||
of the GNU General Public License (GPL), a binary executable of
|
||||
djcode may be distributed with binary executables of the application,
|
||||
provided a royalty of 5% of the total sale price or $5 (whichever is
|
||||
more) per copy sold is paid to DJ Delorie (at the address above).
|
||||
|
||||
3 A person or organization who develops software that requires djcode
|
||||
but does not distribute that software under the terms of the GNU GPL
|
||||
relinquishes all rights to obtain or redistribute the source code
|
||||
for djcode, including any rights granted by the GNU General Public
|
||||
License, and may only distribute executables of djcode under the
|
||||
terms of exception 2, above.
|
||||
|
||||
Basically, the GNU GPL only applies to my code if it applies to your code.
|
||||
|
||||
A copy of the file "COPYING" is included with this document. If you did not
|
||||
receive a copy of "COPYING", you may obtain one from whence this document
|
||||
was obtained, or by writing:
|
||||
Free Software Foundation
|
||||
675 Mass Ave
|
||||
Cambridge, MA 02139
|
||||
USA
|
||||
@ -0,0 +1,40 @@
|
||||
#
|
||||
# Makefile for crt0.o of Linux
|
||||
#
|
||||
#AR =/usr/local/bin/gar
|
||||
AR =/usr/local/bin/ar
|
||||
#AS =/usr/local/bin/gcc-as
|
||||
AS =/usr/local/bin/as
|
||||
#LD =/usr/local/bin/gld
|
||||
LD =/usr/local/bin/ld
|
||||
RANLIB =/usr/local/bin/ranlib
|
||||
LDFLAGS =-s -x
|
||||
CC =/usr/local/bin/gcc -B/usr/local/bin/ -v
|
||||
#CC =/local/bin/gcc-i386-sysv -v
|
||||
INC =-nostdinc -I. -I../include
|
||||
CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
|
||||
$(INC)# -DNEW_CRT0
|
||||
CPP =$(CC) -E $(INC)
|
||||
RM =/usr/bin/rm
|
||||
|
||||
.c.s:
|
||||
$(CC) $(CFLAGS) -S -o $*.s $<
|
||||
.s.o:
|
||||
$(CC) -c -o $*.o $<
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) -c -o $*.o $<
|
||||
|
||||
OBJS = crt0.o
|
||||
|
||||
all: $(OBJS)
|
||||
|
||||
clean:
|
||||
$(RM) -f core *.o *.a tmp_make
|
||||
|
||||
dep:
|
||||
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
|
||||
(for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \
|
||||
$(CPP) -M $$i;done) >> tmp_make
|
||||
cp tmp_make Makefile
|
||||
|
||||
### Dependencies:
|
||||
@ -0,0 +1,55 @@
|
||||
.text
|
||||
|
||||
.globl _environ
|
||||
|
||||
__entry:
|
||||
fldcw init_cw
|
||||
# movl $45,%eax
|
||||
# movl $0,%ebx
|
||||
# int $0x80
|
||||
# movl %eax,____brk_addr
|
||||
movl 8(%esp),%eax
|
||||
movl %eax,_environ
|
||||
call _main
|
||||
pushl %eax
|
||||
1: call _exit
|
||||
jmp 1b
|
||||
|
||||
.data
|
||||
.align 2
|
||||
_environ:
|
||||
.long 0
|
||||
init_cw:
|
||||
.word 0x0262
|
||||
|
||||
/* Here is the dirty part. Settup up your 387 through the control word
|
||||
* (cw) register.
|
||||
*
|
||||
* 15-13 12 11-10 9-8 7-6 5 4 3 2 1 0
|
||||
* | reserved | IC | RC | PC | reserved | PM | UM | OM | ZM | DM | IM
|
||||
*
|
||||
* IM: Invalid operation mask
|
||||
* DM: Denormalized operand mask
|
||||
* ZM: Zero-divide mask
|
||||
* OM: Overflow mask
|
||||
* UM: Underflow mask
|
||||
* PM: Precision (inexact result) mask
|
||||
*
|
||||
* Mask bit is 1 means no interrupt.
|
||||
*
|
||||
* PC: Precision control
|
||||
* 11 - round to extended precision
|
||||
* 10 - round to double precision
|
||||
* 00 - round to single precision
|
||||
*
|
||||
* RC: Rounding control
|
||||
* 00 - rounding to nearest
|
||||
* 01 - rounding down (toward - infinity)
|
||||
* 10 - rounding up (toward + infinity)
|
||||
* 11 - rounding toward zero
|
||||
*
|
||||
* IC: Infinity control
|
||||
* That is for 8087 and 80287 only.
|
||||
*
|
||||
* The hardware default is 0x037f. I choose 0x0262.
|
||||
*/
|
||||
@ -0,0 +1,46 @@
|
||||
#
|
||||
# Makefile for the direntry-library functions
|
||||
#
|
||||
|
||||
LIB =../Libc.a
|
||||
#AR =gar
|
||||
#AS =gas
|
||||
#LD =gld
|
||||
AR =ar
|
||||
AS =as
|
||||
LD =ld
|
||||
LDFLAGS =-s -x
|
||||
CC =gcc
|
||||
INC =-nostdinc -I../include
|
||||
CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
|
||||
-finline-functions $(INC)
|
||||
CPP =$(CC) -E $(INC)
|
||||
|
||||
.c.s:
|
||||
$(CC) $(CFLAGS) \
|
||||
-S -o $*.s $<
|
||||
.s.o:
|
||||
$(CC) -c -o $*.o $<
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) \
|
||||
-c -o $*.o $<
|
||||
|
||||
OBJS = closedir.o opendir.o readdir.o rewinddir.o
|
||||
|
||||
all: library
|
||||
|
||||
library: $(OBJS)
|
||||
$(AR) uvc $(LIB) $(OBJS)
|
||||
sync
|
||||
|
||||
clean:
|
||||
$(RM) -f core *.o *.a tmp_make
|
||||
for i in *.c;do $(RM) -f `basename $$i .c`.s;done
|
||||
|
||||
dep:
|
||||
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
|
||||
(for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \
|
||||
$(CPP) -M $$i;done) >> tmp_make
|
||||
cp tmp_make Makefile
|
||||
|
||||
### Dependencies:
|
||||
@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Simple dirent routines for Linux.
|
||||
*
|
||||
* (C) 1991 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
int closedir(DIR * dir)
|
||||
{
|
||||
int fd;
|
||||
|
||||
if (!dir) {
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
fd = dir->dd_fd;
|
||||
free(dir->dd_buf);
|
||||
free(dir);
|
||||
return close(fd);
|
||||
}
|
||||
@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Simple dirent routines for Linux.
|
||||
*
|
||||
* (C) 1991 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <string.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
DIR * opendir(const char * dirname)
|
||||
{
|
||||
int fd;
|
||||
struct stat stat_buf;
|
||||
DIR * ptr;
|
||||
|
||||
if ((fd = open(dirname,O_RDONLY))<0)
|
||||
return NULL;
|
||||
if (fstat(fd,&stat_buf)<0 ||
|
||||
!S_ISDIR(stat_buf.st_mode) ||
|
||||
!(ptr=malloc(sizeof(*ptr)))) {
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
memset(ptr,0,sizeof(*ptr));
|
||||
ptr->dd_fd = fd;
|
||||
return ptr;
|
||||
}
|
||||
@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Simple dirent routines for Linux.
|
||||
*
|
||||
* (C) 1991 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <dirent.h>
|
||||
#include <sys/dir.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
static struct dirent result;
|
||||
|
||||
struct dirent * readdir(DIR * dir)
|
||||
{
|
||||
struct direct * ptr;
|
||||
|
||||
if (!dir) {
|
||||
errno = EBADF;
|
||||
return NULL;
|
||||
}
|
||||
if (!dir->dd_buf)
|
||||
if (!(dir->dd_buf = malloc(DIRBUF)))
|
||||
return NULL;
|
||||
else
|
||||
dir->dd_size = dir->dd_loc = 0;
|
||||
while (1) {
|
||||
if (dir->dd_size <= dir->dd_loc) {
|
||||
dir->dd_loc = 0;
|
||||
dir->dd_size = read(dir->dd_fd,dir->dd_buf,DIRBUF);
|
||||
}
|
||||
if (dir->dd_size <= 0)
|
||||
return NULL;
|
||||
ptr = (struct direct *) (dir->dd_loc + dir->dd_buf);
|
||||
dir->dd_loc += sizeof (*ptr);
|
||||
if (!ptr->d_ino)
|
||||
continue;
|
||||
result.d_ino = ptr->d_ino;
|
||||
strncpy(result.d_name,ptr->d_name,NAME_MAX);
|
||||
result.d_name[NAME_MAX] = 0;
|
||||
result.d_reclen = strlen(result.d_name);
|
||||
return &result;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Simple dirent routines for Linux.
|
||||
*
|
||||
* (C) 1991 Linus Torvalds
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
void rewinddir(DIR * dir)
|
||||
{
|
||||
if (!dir) {
|
||||
errno = EBADF;
|
||||
return;
|
||||
}
|
||||
dir->dd_size = dir->dd_loc = 0;
|
||||
lseek(dir->dd_fd,0L,SEEK_SET);
|
||||
}
|
||||
@ -0,0 +1,44 @@
|
||||
#
|
||||
# Makefile for some ansi-library functions
|
||||
#
|
||||
|
||||
LIB =../Libc.a
|
||||
AR =gar
|
||||
AS =gas
|
||||
LD =gld
|
||||
LDFLAGS =-s -x
|
||||
CC =gcc
|
||||
#INC =-nostdinc -I/linux/usr/include
|
||||
CFLAGS =-Wall -O -fstrength-reduce -fomit-frame-pointer \
|
||||
-finline-functions $(INC)
|
||||
CPP =(CC) -E $(INC)
|
||||
|
||||
.c.s:
|
||||
$(CC) $(CFLAGS) \
|
||||
-S -o $*.s $<
|
||||
.s.o:
|
||||
$(CC) -c -o $*.o $<
|
||||
.c.o:
|
||||
$(CC) $(CFLAGS) \
|
||||
-c -o $*.o $<
|
||||
|
||||
OBJS = fgetgrent.o getgrent.o getgrgid.o getgrnam.o grpopen.o \
|
||||
grpread.o initgroups.o
|
||||
|
||||
all: library
|
||||
|
||||
library: $(OBJS)
|
||||
$(AR) uvc $(LIB) $(OBJS)
|
||||
sync
|
||||
|
||||
clean:
|
||||
$(RM) -f core *.o *.a tmp_make
|
||||
for i in *.c;do $(RM) -f `basename $$i .c`.s;done
|
||||
|
||||
dep:
|
||||
sed '/\#\#\# Dependencies/q' < Makefile > tmp_make
|
||||
(for i in *.c;do echo -n `echo $$i | sed 's,\.c,\.s,'`" "; \
|
||||
$(CPP) -M $$i;done) >> tmp_make
|
||||
cp tmp_make Makefile
|
||||
|
||||
### Dependencies:
|
||||
@ -0,0 +1,41 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
|
||||
|
||||
/* Read a group entry from STREAM. */
|
||||
struct group *
|
||||
DEFUN(fgetgrent, (stream), FILE *stream)
|
||||
{
|
||||
static PTR info = NULL;
|
||||
if (info == NULL)
|
||||
{
|
||||
info = __grpalloc();
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return __grpread(stream, info);
|
||||
}
|
||||
@ -0,0 +1,67 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
|
||||
static FILE *stream = NULL;
|
||||
|
||||
/* Rewind the stream. */
|
||||
void
|
||||
DEFUN_VOID(setgrent)
|
||||
{
|
||||
if (stream != NULL)
|
||||
rewind(stream);
|
||||
}
|
||||
|
||||
|
||||
/* Close the stream. */
|
||||
void
|
||||
DEFUN_VOID(endgrent)
|
||||
{
|
||||
if (stream != NULL)
|
||||
{
|
||||
(void) fclose(stream);
|
||||
stream = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Read an entry from the stream. */
|
||||
struct group *
|
||||
DEFUN_VOID(getgrent)
|
||||
{
|
||||
static PTR info = NULL;
|
||||
if (info == NULL)
|
||||
{
|
||||
info = __grpalloc();
|
||||
if (info == NULL)
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if (stream == NULL)
|
||||
{
|
||||
stream = __grpopen();
|
||||
if (stream == NULL)
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
return(__grpread(stream, info));
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/types.h>
|
||||
#include <grp.h>
|
||||
|
||||
/* Search for an entry with a matching group ID. */
|
||||
struct group *
|
||||
DEFUN(getgrgid, (gid), register gid_t gid)
|
||||
{
|
||||
static PTR info = NULL;
|
||||
register FILE *stream;
|
||||
register struct group *g;
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
info = __grpalloc();
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stream = __grpopen();
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((g = __grpread(stream, info)) != NULL)
|
||||
if (g->gr_gid == (gid_t) gid)
|
||||
break;
|
||||
|
||||
(void) fclose(stream);
|
||||
return g;
|
||||
}
|
||||
@ -0,0 +1,50 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
|
||||
/* Search for an entry with a matching name. */
|
||||
struct group *
|
||||
DEFUN(getgrnam, (name), register CONST char *name)
|
||||
{
|
||||
static PTR info = NULL;
|
||||
register FILE *stream;
|
||||
register struct group *g;
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
info = __grpalloc();
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
stream = __grpopen();
|
||||
if (stream == NULL)
|
||||
return NULL;
|
||||
|
||||
while ((g = __grpread(stream, info)) != NULL)
|
||||
if (!strcmp(g->gr_name, name))
|
||||
break;
|
||||
|
||||
(void) fclose(stream);
|
||||
return g;
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <stdio.h>
|
||||
#include <grp.h>
|
||||
|
||||
/* Return a new stream open on the group file. */
|
||||
FILE *
|
||||
DEFUN_VOID(__grpopen)
|
||||
{
|
||||
return fopen("/etc/group", "r");
|
||||
}
|
||||
@ -0,0 +1,132 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
#include <grp.h>
|
||||
|
||||
/* This is the function that all the others are based on.
|
||||
The format of the group file is known only here. */
|
||||
|
||||
/* Structure containing info kept by each __grpread caller. */
|
||||
typedef struct
|
||||
{
|
||||
#define NAME_SIZE 8
|
||||
#define PASSWD_SIZE 20
|
||||
#define MEMLIST_SIZE 1000
|
||||
char buf[NAME_SIZE + 1 + PASSWD_SIZE + 1 + 20 + 1 + 20 + MEMLIST_SIZE + 1];
|
||||
size_t max_members;
|
||||
char **members;
|
||||
struct group g;
|
||||
} grpread_info;
|
||||
|
||||
|
||||
/* Return a chunk of memory containing a pre-initialized `grpread_info'. */
|
||||
PTR
|
||||
DEFUN_VOID(__grpalloc)
|
||||
{
|
||||
grpread_info *info = (PTR) malloc(sizeof(grpread_info));
|
||||
if (info == NULL)
|
||||
return NULL;
|
||||
|
||||
info->max_members = 5;
|
||||
info->members = (char **) malloc(5 * sizeof(char *));
|
||||
if (info->members == NULL)
|
||||
{
|
||||
free((PTR) info);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
|
||||
/* Read a group entry from STREAM, filling in G. */
|
||||
struct group *
|
||||
DEFUN(__grpread, (stream, g), FILE *stream AND PTR CONST g)
|
||||
{
|
||||
register grpread_info *CONST info = (grpread_info *) g;
|
||||
char *start, *end;
|
||||
register size_t i;
|
||||
|
||||
/* Idiocy checks. */
|
||||
if (stream == NULL)
|
||||
{
|
||||
errno = EINVAL;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (fgets (info->buf, sizeof(info->buf), stream) == NULL)
|
||||
return NULL;
|
||||
|
||||
start = info->buf;
|
||||
end = strchr (start, ':');
|
||||
if (end == NULL)
|
||||
return NULL;
|
||||
*end = '\0';
|
||||
info->g.gr_name = start;
|
||||
|
||||
start = end + 1;
|
||||
end = strchr (start, ':');
|
||||
if (end == NULL)
|
||||
return NULL;
|
||||
*end = '\0';
|
||||
info->g.gr_passwd = start;
|
||||
|
||||
info->g.gr_gid = (gid_t) strtol (end + 1, &end, 10);
|
||||
if (*end != ':')
|
||||
return NULL;
|
||||
|
||||
i = 0;
|
||||
do
|
||||
{
|
||||
start = end + 1;
|
||||
end = strchr (start, ',');
|
||||
if (end == NULL)
|
||||
{
|
||||
end = strchr (start, '\n');
|
||||
if (end == start)
|
||||
break;
|
||||
if (end == NULL)
|
||||
return NULL;
|
||||
*end = '\0';
|
||||
end = NULL;
|
||||
}
|
||||
else
|
||||
*end = '\0';
|
||||
|
||||
if (i == info->max_members - 2)
|
||||
{
|
||||
info->max_members += 5;
|
||||
info->members = (char **)
|
||||
realloc ((PTR) info->members, info->max_members * sizeof (char *));
|
||||
if (info->members == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
info->members[i++] = start;
|
||||
} while (end != NULL);
|
||||
info->members[i] = NULL;
|
||||
info->g.gr_mem = info->members;
|
||||
|
||||
return &info->g;
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
/* Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <grp.h>
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
/* Initialize the group set for the current user
|
||||
by reading the group database and using all groups
|
||||
of which USER is a member. Also include GROUP. */
|
||||
int
|
||||
DEFUN(initgroups, (user, group),
|
||||
CONST char *user AND gid_t group)
|
||||
{
|
||||
static PTR info = NULL;
|
||||
register FILE *stream;
|
||||
register struct group *g;
|
||||
gid_t groups[NGROUPS_MAX];
|
||||
register size_t n;
|
||||
|
||||
if (info == NULL)
|
||||
{
|
||||
info = __grpalloc();
|
||||
if (info == NULL)
|
||||
return -1;
|
||||
}
|
||||
|
||||
stream = __grpopen();
|
||||
if (stream == NULL)
|
||||
return -1;
|
||||
|
||||
n = 0;
|
||||
if (group >= 0)
|
||||
groups[n++] = group;
|
||||
|
||||
while (n < NGROUPS_MAX && (g = __grpread(stream, info)) != NULL)
|
||||
if (g->gr_gid != group)
|
||||
{
|
||||
register char **m;
|
||||
|
||||
for (m = g->gr_mem; *m != NULL; ++m)
|
||||
if (!strcmp(*m, user))
|
||||
groups[n++] = g->gr_gid;
|
||||
}
|
||||
|
||||
return setgroups(n, groups);
|
||||
}
|
||||
@ -0,0 +1,222 @@
|
||||
/* Gnu a.out.h modified for linux */
|
||||
#ifndef __A_OUT_H__
|
||||
#define __A_OUT_H__
|
||||
|
||||
#define __GNU_EXEC_MACROS__
|
||||
|
||||
struct exec
|
||||
{
|
||||
unsigned long a_magic; /* Use macros N_MAGIC, etc for access */
|
||||
unsigned a_text; /* length of text, in bytes */
|
||||
unsigned a_data; /* length of data, in bytes */
|
||||
unsigned a_bss; /* length of uninitialized data area for file, in bytes */
|
||||
unsigned a_syms; /* length of symbol table data in file, in bytes */
|
||||
unsigned a_entry; /* start address */
|
||||
unsigned a_trsize; /* length of relocation info for text, in bytes */
|
||||
unsigned a_drsize; /* length of relocation info for data, in bytes */
|
||||
};
|
||||
|
||||
#ifndef N_MAGIC
|
||||
#define N_MAGIC(exec) ((exec).a_magic)
|
||||
#endif
|
||||
|
||||
#ifndef OMAGIC
|
||||
/* Code indicating object file or impure executable. */
|
||||
#define OMAGIC 0407
|
||||
/* Code indicating pure executable. */
|
||||
#define NMAGIC 0410
|
||||
/* Code indicating demand-paged executable. */
|
||||
#define ZMAGIC 0413
|
||||
#endif /* not OMAGIC */
|
||||
|
||||
#ifndef N_BADMAG
|
||||
#define N_BADMAG(x) \
|
||||
(N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
|
||||
&& N_MAGIC(x) != ZMAGIC)
|
||||
#endif
|
||||
|
||||
#define _N_BADMAG(x) \
|
||||
(N_MAGIC(x) != OMAGIC && N_MAGIC(x) != NMAGIC \
|
||||
&& N_MAGIC(x) != ZMAGIC)
|
||||
|
||||
#define _N_HDROFF(x) (SEGMENT_SIZE - sizeof (struct exec))
|
||||
|
||||
#ifndef N_TXTOFF
|
||||
#define N_TXTOFF(x) \
|
||||
(N_MAGIC(x) == ZMAGIC ? _N_HDROFF((x)) + sizeof (struct exec) : sizeof (struct exec))
|
||||
#endif
|
||||
|
||||
#ifndef N_DATOFF
|
||||
#define N_DATOFF(x) (N_TXTOFF(x) + (x).a_text)
|
||||
#endif
|
||||
|
||||
#ifndef N_TRELOFF
|
||||
#define N_TRELOFF(x) (N_DATOFF(x) + (x).a_data)
|
||||
#endif
|
||||
|
||||
#ifndef N_DRELOFF
|
||||
#define N_DRELOFF(x) (N_TRELOFF(x) + (x).a_trsize)
|
||||
#endif
|
||||
|
||||
#ifndef N_SYMOFF
|
||||
#define N_SYMOFF(x) (N_DRELOFF(x) + (x).a_drsize)
|
||||
#endif
|
||||
|
||||
#ifndef N_STROFF
|
||||
#define N_STROFF(x) (N_SYMOFF(x) + (x).a_syms)
|
||||
#endif
|
||||
|
||||
/* Address of text segment in memory after it is loaded. */
|
||||
#ifndef N_TXTADDR
|
||||
#define N_TXTADDR(x) 0
|
||||
#endif
|
||||
|
||||
/* Address of data segment in memory after it is loaded.
|
||||
Note that it is up to you to define SEGMENT_SIZE
|
||||
on machines not listed here. */
|
||||
#if defined(vax) || defined(hp300) || defined(pyr)
|
||||
#define SEGMENT_SIZE PAGE_SIZE
|
||||
#endif
|
||||
#ifdef hp300
|
||||
#define PAGE_SIZE 4096
|
||||
#endif
|
||||
#ifdef sony
|
||||
#define SEGMENT_SIZE 0x2000
|
||||
#endif /* Sony. */
|
||||
#ifdef is68k
|
||||
#define SEGMENT_SIZE 0x20000
|
||||
#endif
|
||||
#if defined(m68k) && defined(PORTAR)
|
||||
#define PAGE_SIZE 0x400
|
||||
#define SEGMENT_SIZE PAGE_SIZE
|
||||
#endif
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
#define SEGMENT_SIZE 1024
|
||||
|
||||
#define _N_SEGMENT_ROUND(x) (((x) + SEGMENT_SIZE - 1) & ~(SEGMENT_SIZE - 1))
|
||||
|
||||
#define _N_TXTENDADDR(x) (N_TXTADDR(x)+(x).a_text)
|
||||
|
||||
#ifndef N_DATADDR
|
||||
#define N_DATADDR(x) \
|
||||
(N_MAGIC(x)==OMAGIC? (_N_TXTENDADDR(x)) \
|
||||
: (_N_SEGMENT_ROUND (_N_TXTENDADDR(x))))
|
||||
#endif
|
||||
|
||||
/* Address of bss segment in memory after it is loaded. */
|
||||
#ifndef N_BSSADDR
|
||||
#define N_BSSADDR(x) (N_DATADDR(x) + (x).a_data)
|
||||
#endif
|
||||
|
||||
#ifndef N_NLIST_DECLARED
|
||||
struct nlist {
|
||||
union {
|
||||
char *n_name;
|
||||
struct nlist *n_next;
|
||||
long n_strx;
|
||||
} n_un;
|
||||
unsigned char n_type;
|
||||
char n_other;
|
||||
short n_desc;
|
||||
unsigned long n_value;
|
||||
};
|
||||
#endif
|
||||
|
||||
#ifndef N_UNDF
|
||||
#define N_UNDF 0
|
||||
#endif
|
||||
#ifndef N_ABS
|
||||
#define N_ABS 2
|
||||
#endif
|
||||
#ifndef N_TEXT
|
||||
#define N_TEXT 4
|
||||
#endif
|
||||
#ifndef N_DATA
|
||||
#define N_DATA 6
|
||||
#endif
|
||||
#ifndef N_BSS
|
||||
#define N_BSS 8
|
||||
#endif
|
||||
#ifndef N_COMM
|
||||
#define N_COMM 18
|
||||
#endif
|
||||
#ifndef N_FN
|
||||
#define N_FN 15
|
||||
#endif
|
||||
|
||||
#ifndef N_EXT
|
||||
#define N_EXT 1
|
||||
#endif
|
||||
#ifndef N_TYPE
|
||||
#define N_TYPE 036
|
||||
#endif
|
||||
#ifndef N_STAB
|
||||
#define N_STAB 0340
|
||||
#endif
|
||||
|
||||
/* The following type indicates the definition of a symbol as being
|
||||
an indirect reference to another symbol. The other symbol
|
||||
appears as an undefined reference, immediately following this symbol.
|
||||
|
||||
Indirection is asymmetrical. The other symbol's value will be used
|
||||
to satisfy requests for the indirect symbol, but not vice versa.
|
||||
If the other symbol does not have a definition, libraries will
|
||||
be searched to find a definition. */
|
||||
#define N_INDR 0xa
|
||||
|
||||
/* The following symbols refer to set elements.
|
||||
All the N_SET[ATDB] symbols with the same name form one set.
|
||||
Space is allocated for the set in the text section, and each set
|
||||
element's value is stored into one word of the space.
|
||||
The first word of the space is the length of the set (number of elements).
|
||||
|
||||
The address of the set is made into an N_SETV symbol
|
||||
whose name is the same as the name of the set.
|
||||
This symbol acts like a N_DATA global symbol
|
||||
in that it can satisfy undefined external references. */
|
||||
|
||||
/* These appear as input to LD, in a .o file. */
|
||||
#define N_SETA 0x14 /* Absolute set element symbol */
|
||||
#define N_SETT 0x16 /* Text set element symbol */
|
||||
#define N_SETD 0x18 /* Data set element symbol */
|
||||
#define N_SETB 0x1A /* Bss set element symbol */
|
||||
|
||||
/* This is output from LD. */
|
||||
#define N_SETV 0x1C /* Pointer to set vector in data area. */
|
||||
|
||||
#ifndef N_RELOCATION_INFO_DECLARED
|
||||
|
||||
/* This structure describes a single relocation to be performed.
|
||||
The text-relocation section of the file is a vector of these structures,
|
||||
all of which apply to the text section.
|
||||
Likewise, the data-relocation section applies to the data section. */
|
||||
|
||||
struct relocation_info
|
||||
{
|
||||
/* Address (within segment) to be relocated. */
|
||||
int r_address;
|
||||
/* The meaning of r_symbolnum depends on r_extern. */
|
||||
unsigned int r_symbolnum:24;
|
||||
/* Nonzero means value is a pc-relative offset
|
||||
and it should be relocated for changes in its own address
|
||||
as well as for changes in the symbol or section specified. */
|
||||
unsigned int r_pcrel:1;
|
||||
/* Length (as exponent of 2) of the field to be relocated.
|
||||
Thus, a value of 2 indicates 1<<2 bytes. */
|
||||
unsigned int r_length:2;
|
||||
/* 1 => relocate with value of symbol.
|
||||
r_symbolnum is the index of the symbol
|
||||
in file's the symbol table.
|
||||
0 => relocate with the address of a segment.
|
||||
r_symbolnum is N_TEXT, N_DATA, N_BSS or N_ABS
|
||||
(the N_EXT bit may be set also, but signifies nothing). */
|
||||
unsigned int r_extern:1;
|
||||
/* Four bits that aren't used, but when writing an object file
|
||||
it is desirable to clear them. */
|
||||
unsigned int r_pad:4;
|
||||
};
|
||||
#endif /* no N_RELOCATION_INFO_DECLARED. */
|
||||
|
||||
|
||||
#endif /* __A_OUT_GNU_H__ */
|
||||
@ -0,0 +1,108 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C Library 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 1, or (at your option)
|
||||
any later version.
|
||||
|
||||
The GNU C 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with the GNU C Library; see the file COPYING. If not, write to
|
||||
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
|
||||
|
||||
/* ANSI and traditional C compatibility macros
|
||||
|
||||
ANSI C is assumed if __STDC__ is #defined.
|
||||
|
||||
Macro ANSI C definition Traditional C definition
|
||||
----- ---- - ---------- ----------- - ----------
|
||||
PTR `void *' `char *'
|
||||
LONG_DOUBLE `long double' `double'
|
||||
CONST `const' `'
|
||||
VOLATILE `volatile' `'
|
||||
SIGNED `signed' `'
|
||||
PTRCONST `void *const' `char *'
|
||||
|
||||
DEFUN(name, arglist, args)
|
||||
|
||||
Defines function NAME.
|
||||
|
||||
ARGLIST lists the arguments, separated by commas and enclosed in
|
||||
parentheses. ARGLIST becomes the argument list in traditional C.
|
||||
|
||||
ARGS list the arguments with their types. It becomes a prototype in
|
||||
ANSI C, and the type declarations in traditional C. Arguments should
|
||||
be separated with `AND'. For functions with a variable number of
|
||||
arguments, the last thing listed should be `DOTS'.
|
||||
|
||||
DEFUN_VOID(name)
|
||||
|
||||
Defines a function NAME, which takes no arguments.
|
||||
|
||||
EXFUN(name, prototype)
|
||||
|
||||
Is used in an external function declaration.
|
||||
In ANSI C it is `NAMEPROTOTYPE' (so PROTOTYPE should be enclosed in
|
||||
parentheses). In traditional C it is `NAME()'.
|
||||
For a function that takes no arguments, PROTOTYPE should be `(NOARGS)'.
|
||||
|
||||
For example:
|
||||
extern int EXFUN(printf, (CONST char *format DOTS));
|
||||
int DEFUN(fprintf, (stream, format),
|
||||
FILE *stream AND CONST char *format DOTS) { ... }
|
||||
void DEFUN_VOID(abort) { ... }
|
||||
*/
|
||||
|
||||
#ifndef _ANSIDECL_H
|
||||
|
||||
#define _ANSIDECL_H 1
|
||||
|
||||
|
||||
/* Every source file includes this file,
|
||||
so they will all get the switch for lint. */
|
||||
/* LINTLIBRARY */
|
||||
|
||||
|
||||
#ifdef __STDC__
|
||||
|
||||
#define PTR void *
|
||||
#define PTRCONST void *CONST
|
||||
#define LONG_DOUBLE long double
|
||||
|
||||
#define AND ,
|
||||
#define NOARGS void
|
||||
#define CONST const
|
||||
#define VOLATILE volatile
|
||||
#define SIGNED signed
|
||||
#define DOTS , ...
|
||||
|
||||
#define EXFUN(name, proto) name proto
|
||||
#define DEFUN(name, arglist, args) name(args)
|
||||
#define DEFUN_VOID(name) name(NOARGS)
|
||||
|
||||
#else /* Not ANSI C. */
|
||||
|
||||
#define PTR char *
|
||||
#define PTRCONST PTR
|
||||
#define LONG_DOUBLE double
|
||||
|
||||
#define AND ;
|
||||
#define NOARGS
|
||||
#define CONST
|
||||
#define VOLATILE
|
||||
#define SIGNED
|
||||
#define DOTS
|
||||
|
||||
#define EXFUN(name, proto) name()
|
||||
#define DEFUN(name, arglist, args) name arglist args;
|
||||
#define DEFUN_VOID(name) name()
|
||||
|
||||
#endif /* ANSI C. */
|
||||
|
||||
|
||||
#endif /* ansidecl.h */
|
||||
@ -0,0 +1,20 @@
|
||||
/* Typed in by Richard */
|
||||
/* minor changes for linux */
|
||||
#ifndef _AR_H
|
||||
#define _AR_H
|
||||
|
||||
#define ARMAG "!<arch>\n"
|
||||
#define SARMAG 8
|
||||
#define ARFMAG "`\n"
|
||||
|
||||
struct ar_hdr {
|
||||
char ar_name[16],
|
||||
ar_date[12],
|
||||
ar_uid[6],
|
||||
ar_gid[6],
|
||||
ar_mode[8],
|
||||
ar_size[10],
|
||||
ar_fmag[2];
|
||||
};
|
||||
|
||||
#endif /* _AR_H */
|
||||
@ -0,0 +1,24 @@
|
||||
#define outb(value,port) \
|
||||
__asm__ ("outb %%al,%%dx"::"a" (value),"d" (port))
|
||||
|
||||
|
||||
#define inb(port) ({ \
|
||||
unsigned char _v; \
|
||||
__asm__ volatile ("inb %%dx,%%al":"=a" (_v):"d" (port)); \
|
||||
_v; \
|
||||
})
|
||||
|
||||
#define outb_p(value,port) \
|
||||
__asm__ ("outb %%al,%%dx\n" \
|
||||
"\tjmp 1f\n" \
|
||||
"1:\tjmp 1f\n" \
|
||||
"1:"::"a" (value),"d" (port))
|
||||
|
||||
#define inb_p(port) ({ \
|
||||
unsigned char _v; \
|
||||
__asm__ volatile ("inb %%dx,%%al\n" \
|
||||
"\tjmp 1f\n" \
|
||||
"1:\tjmp 1f\n" \
|
||||
"1:":"=a" (_v):"d" (port)); \
|
||||
_v; \
|
||||
})
|
||||
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* NOTE!!! memcpy(dest,src,n) assumes ds=es=normal data segment. This
|
||||
* goes for all kernel functions (ds=es=kernel space, fs=local data,
|
||||
* gs=null), as well as for all well-behaving user programs (ds=es=
|
||||
* user data space). This is NOT a bug, as any user program that changes
|
||||
* es deserves to die if it isn't careful.
|
||||
*/
|
||||
#define memcpy(dest,src,n) ({ \
|
||||
void * _res = dest; \
|
||||
__asm__ ("cld;rep;movsb" \
|
||||
::"D" ((long)(_res)),"S" ((long)(src)),"c" ((long) (n)) \
|
||||
:"di","si","cx"); \
|
||||
_res; \
|
||||
})
|
||||
@ -0,0 +1,65 @@
|
||||
extern inline unsigned char get_fs_byte(const char * addr)
|
||||
{
|
||||
unsigned register char _v;
|
||||
|
||||
__asm__ ("movb %%fs:%1,%0":"=r" (_v):"m" (*addr));
|
||||
return _v;
|
||||
}
|
||||
|
||||
extern inline unsigned short get_fs_word(const unsigned short *addr)
|
||||
{
|
||||
unsigned short _v;
|
||||
|
||||
__asm__ ("movw %%fs:%1,%0":"=r" (_v):"m" (*addr));
|
||||
return _v;
|
||||
}
|
||||
|
||||
extern inline unsigned long get_fs_long(const unsigned long *addr)
|
||||
{
|
||||
unsigned long _v;
|
||||
|
||||
__asm__ ("movl %%fs:%1,%0":"=r" (_v):"m" (*addr)); \
|
||||
return _v;
|
||||
}
|
||||
|
||||
extern inline void put_fs_byte(char val,char *addr)
|
||||
{
|
||||
__asm__ ("movb %0,%%fs:%1"::"r" (val),"m" (*addr));
|
||||
}
|
||||
|
||||
extern inline void put_fs_word(short val,short * addr)
|
||||
{
|
||||
__asm__ ("movw %0,%%fs:%1"::"r" (val),"m" (*addr));
|
||||
}
|
||||
|
||||
extern inline void put_fs_long(unsigned long val,unsigned long * addr)
|
||||
{
|
||||
__asm__ ("movl %0,%%fs:%1"::"r" (val),"m" (*addr));
|
||||
}
|
||||
|
||||
/*
|
||||
* Someone who knows GNU asm better than I should double check the followig.
|
||||
* It seems to work, but I don't know if I'm doing something subtly wrong.
|
||||
* --- TYT, 11/24/91
|
||||
* [ nothing wrong here, Linus ]
|
||||
*/
|
||||
|
||||
extern inline unsigned long get_fs()
|
||||
{
|
||||
unsigned short _v;
|
||||
__asm__("mov %%fs,%%ax":"=a" (_v):);
|
||||
return _v;
|
||||
}
|
||||
|
||||
extern inline unsigned long get_ds()
|
||||
{
|
||||
unsigned short _v;
|
||||
__asm__("mov %%ds,%%ax":"=a" (_v):);
|
||||
return _v;
|
||||
}
|
||||
|
||||
extern inline void set_fs(unsigned long val)
|
||||
{
|
||||
__asm__("mov %0,%%fs"::"a" ((unsigned short) val));
|
||||
}
|
||||
|
||||
@ -0,0 +1,66 @@
|
||||
#define move_to_user_mode() \
|
||||
__asm__ ("movl %%esp,%%eax\n\t" \
|
||||
"pushl $0x17\n\t" \
|
||||
"pushl %%eax\n\t" \
|
||||
"pushfl\n\t" \
|
||||
"pushl $0x0f\n\t" \
|
||||
"pushl $1f\n\t" \
|
||||
"iret\n" \
|
||||
"1:\tmovl $0x17,%%eax\n\t" \
|
||||
"movw %%ax,%%ds\n\t" \
|
||||
"movw %%ax,%%es\n\t" \
|
||||
"movw %%ax,%%fs\n\t" \
|
||||
"movw %%ax,%%gs" \
|
||||
:::"ax")
|
||||
|
||||
#define sti() __asm__ ("sti"::)
|
||||
#define cli() __asm__ ("cli"::)
|
||||
#define nop() __asm__ ("nop"::)
|
||||
|
||||
#define iret() __asm__ ("iret"::)
|
||||
|
||||
#define _set_gate(gate_addr,type,dpl,addr) \
|
||||
__asm__ ("movw %%dx,%%ax\n\t" \
|
||||
"movw %0,%%dx\n\t" \
|
||||
"movl %%eax,%1\n\t" \
|
||||
"movl %%edx,%2" \
|
||||
: \
|
||||
: "i" ((short) (0x8000+(dpl<<13)+(type<<8))), \
|
||||
"o" (*((char *) (gate_addr))), \
|
||||
"o" (*(4+(char *) (gate_addr))), \
|
||||
"d" ((char *) (addr)),"a" (0x00080000))
|
||||
|
||||
#define set_intr_gate(n,addr) \
|
||||
_set_gate(&idt[n],14,0,addr)
|
||||
|
||||
#define set_trap_gate(n,addr) \
|
||||
_set_gate(&idt[n],15,0,addr)
|
||||
|
||||
#define set_system_gate(n,addr) \
|
||||
_set_gate(&idt[n],15,3,addr)
|
||||
|
||||
#define _set_seg_desc(gate_addr,type,dpl,base,limit) {\
|
||||
*(gate_addr) = ((base) & 0xff000000) | \
|
||||
(((base) & 0x00ff0000)>>16) | \
|
||||
((limit) & 0xf0000) | \
|
||||
((dpl)<<13) | \
|
||||
(0x00408000) | \
|
||||
((type)<<8); \
|
||||
*((gate_addr)+1) = (((base) & 0x0000ffff)<<16) | \
|
||||
((limit) & 0x0ffff); }
|
||||
|
||||
#define _set_tssldt_desc(n,addr,type) \
|
||||
__asm__ ("movw $104,%1\n\t" \
|
||||
"movw %%ax,%2\n\t" \
|
||||
"rorl $16,%%eax\n\t" \
|
||||
"movb %%al,%3\n\t" \
|
||||
"movb $" type ",%4\n\t" \
|
||||
"movb $0x00,%5\n\t" \
|
||||
"movb %%ah,%6\n\t" \
|
||||
"rorl $16,%%eax" \
|
||||
::"a" (addr), "m" (*(n)), "m" (*(n+2)), "m" (*(n+4)), \
|
||||
"m" (*(n+5)), "m" (*(n+6)), "m" (*(n+7)) \
|
||||
)
|
||||
|
||||
#define set_tss_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x89")
|
||||
#define set_ldt_desc(n,addr) _set_tssldt_desc(((char *) (n)),addr,"0x82")
|
||||
@ -0,0 +1,34 @@
|
||||
/* Allow this file to be included multiple times
|
||||
with different settings of NDEBUG. */
|
||||
#undef assert
|
||||
#undef __assert
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define assert(ignore) ((void)0)
|
||||
#else
|
||||
|
||||
void __eprintf (); /* Defined in gnulib */
|
||||
|
||||
#ifdef __STDC__
|
||||
|
||||
#define assert(expression) \
|
||||
((expression) ? 0 : (__assert (#expression, __FILE__, __LINE__), 0))
|
||||
|
||||
#define __assert(expression, file, line) \
|
||||
(__eprintf ("Failed assertion `%s' at line %d of `%s'.\n", \
|
||||
expression, line, file), \
|
||||
abort ())
|
||||
|
||||
#else /* no __STDC__; i.e. -traditional. */
|
||||
|
||||
#define assert(expression) \
|
||||
((expression) ? 0 : __assert (expression, __FILE__, __LINE__))
|
||||
|
||||
#define __assert(expression, file, lineno) \
|
||||
(__eprintf ("Failed assertion `%s' at line %d of `%s'.\n", \
|
||||
"expression", lineno, file), \
|
||||
abort ())
|
||||
|
||||
#endif /* no __STDC__; i.e. -traditional. */
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,6 @@
|
||||
#ifndef _BLOCK_SIZE_H
|
||||
#define _BLOCK_SIZE_H
|
||||
|
||||
#define BLOCK_SIZE 1024 /* file system data block size */
|
||||
|
||||
#endif /* _BLOCK_SIZE_H */
|
||||
@ -0,0 +1,16 @@
|
||||
#ifndef _CONST_H
|
||||
|
||||
#define _CONST_H
|
||||
|
||||
#define BUFFER_END 0x200000
|
||||
|
||||
#define I_TYPE 0170000
|
||||
#define I_DIRECTORY 0040000
|
||||
#define I_REGULAR 0100000
|
||||
#define I_BLOCK_SPECIAL 0060000
|
||||
#define I_CHAR_SPECIAL 0020000
|
||||
#define I_NAMED_PIPE 0010000
|
||||
#define I_SET_UID_BIT 0004000
|
||||
#define I_SET_GID_BIT 0002000
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,34 @@
|
||||
#ifndef _CTYPE_H
|
||||
#define _CTYPE_H
|
||||
|
||||
#define _U 0x01 /* upper */
|
||||
#define _L 0x02 /* lower */
|
||||
#define _D 0x04 /* digit */
|
||||
#define _C 0x08 /* cntrl */
|
||||
#define _P 0x10 /* punct */
|
||||
#define _S 0x20 /* white space (space/lf/tab) */
|
||||
#define _X 0x40 /* hex digit */
|
||||
#define _SP 0x80 /* hard space (0x20) */
|
||||
|
||||
extern unsigned char _ctype[];
|
||||
extern char _ctmp;
|
||||
|
||||
#define isalnum(c) ((_ctype+1)[c]&(_U|_L|_D))
|
||||
#define isalpha(c) ((_ctype+1)[c]&(_U|_L))
|
||||
#define iscntrl(c) ((_ctype+1)[c]&(_C))
|
||||
#define isdigit(c) ((_ctype+1)[c]&(_D))
|
||||
#define isgraph(c) ((_ctype+1)[c]&(_P|_U|_L|_D))
|
||||
#define islower(c) ((_ctype+1)[c]&(_L))
|
||||
#define isprint(c) ((_ctype+1)[c]&(_P|_U|_L|_D|_SP))
|
||||
#define ispunct(c) ((_ctype+1)[c]&(_P))
|
||||
#define isspace(c) ((_ctype+1)[c]&(_S))
|
||||
#define isupper(c) ((_ctype+1)[c]&(_U))
|
||||
#define isxdigit(c) ((_ctype+1)[c]&(_D|_X))
|
||||
|
||||
#define isascii(c) (((unsigned) c)<=0x7f)
|
||||
#define toascii(c) (((unsigned) c)&0x7f)
|
||||
|
||||
#define tolower(c) (_ctmp=c,isupper(_ctmp)?_ctmp-('A'-'a'):_ctmp)
|
||||
#define toupper(c) (_ctmp=c,islower(_ctmp)?_ctmp-('a'-'A'):_ctmp)
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,33 @@
|
||||
/*
|
||||
<dirent.h> -- definitions for SVR3 directory access routines
|
||||
|
||||
last edit: 25-Apr-1987 D A Gwyn
|
||||
|
||||
Prerequisite: <sys/types.h>
|
||||
*/
|
||||
|
||||
/* NOTE! The actual routines by D A Gwyn aren't used in linux - I though
|
||||
* they were too complicated, so I wrote my own. I use the header files,
|
||||
* though, as I didn't know what should be in them.
|
||||
*/
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/dirent.h>
|
||||
|
||||
#define DIRBUF 8192 /* buffer size for fs-indep. dirs */
|
||||
/* must in general be larger than the filesystem buffer size */
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int dd_fd; /* file descriptor */
|
||||
int dd_loc; /* offset in block */
|
||||
int dd_size; /* amount of valid data */
|
||||
char *dd_buf; /* -> directory block */
|
||||
} DIR; /* stream data from opendir() */
|
||||
|
||||
extern DIR *opendir();
|
||||
extern struct dirent *readdir();
|
||||
extern off_t telldir();
|
||||
extern void seekdir();
|
||||
extern void rewinddir();
|
||||
extern int closedir();
|
||||
@ -0,0 +1,60 @@
|
||||
#ifndef _ERRNO_H
|
||||
#define _ERRNO_H
|
||||
|
||||
/*
|
||||
* ok, as I hadn't got any other source of information about
|
||||
* possible error numbers, I was forced to use the same numbers
|
||||
* as minix.
|
||||
* Hopefully these are posix or something. I wouldn't know (and posix
|
||||
* isn't telling me - they want $$$ for their f***ing standard).
|
||||
*
|
||||
* We don't use the _SIGN cludge of minix, so kernel returns must
|
||||
* see to the sign by themselves.
|
||||
*
|
||||
* NOTE! Remember to change strerror() if you change this file!
|
||||
*/
|
||||
|
||||
extern int errno;
|
||||
|
||||
#define ERROR 99
|
||||
#define EPERM 1
|
||||
#define ENOENT 2
|
||||
#define ESRCH 3
|
||||
#define EINTR 4
|
||||
#define EIO 5
|
||||
#define ENXIO 6
|
||||
#define E2BIG 7
|
||||
#define ENOEXEC 8
|
||||
#define EBADF 9
|
||||
#define ECHILD 10
|
||||
#define EAGAIN 11
|
||||
#define ENOMEM 12
|
||||
#define EACCES 13
|
||||
#define EFAULT 14
|
||||
#define ENOTBLK 15
|
||||
#define EBUSY 16
|
||||
#define EEXIST 17
|
||||
#define EXDEV 18
|
||||
#define ENODEV 19
|
||||
#define ENOTDIR 20
|
||||
#define EISDIR 21
|
||||
#define EINVAL 22
|
||||
#define ENFILE 23
|
||||
#define EMFILE 24
|
||||
#define ENOTTY 25
|
||||
#define ETXTBSY 26
|
||||
#define EFBIG 27
|
||||
#define ENOSPC 28
|
||||
#define ESPIPE 29
|
||||
#define EROFS 30
|
||||
#define EMLINK 31
|
||||
#define EPIPE 32
|
||||
#define EDOM 33
|
||||
#define ERANGE 34
|
||||
#define EDEADLK 35
|
||||
#define ENAMETOOLONG 36
|
||||
#define ENOLCK 37
|
||||
#define ENOSYS 38
|
||||
#define ENOTEMPTY 39
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,56 @@
|
||||
#ifndef _FCNTL_H
|
||||
#define _FCNTL_H
|
||||
|
||||
/* I don't think this should be included like this, but it's easier */
|
||||
#include <sys/types.h>
|
||||
|
||||
/* open/fcntl - NOCTTY, NDELAY isn't implemented yet */
|
||||
#define O_ACCMODE 00003
|
||||
#define O_RDONLY 00
|
||||
#define O_WRONLY 01
|
||||
#define O_RDWR 02
|
||||
#define O_CREAT 00100 /* not fcntl */
|
||||
#define O_EXCL 00200 /* not fcntl */
|
||||
#define O_NOCTTY 00400 /* not fcntl */
|
||||
#define O_TRUNC 01000 /* not fcntl */
|
||||
#define O_APPEND 02000
|
||||
#define O_NONBLOCK 04000 /* not fcntl */
|
||||
#define O_NDELAY O_NONBLOCK
|
||||
|
||||
/* Defines for fcntl-commands. Note that currently
|
||||
* locking isn't supported, and other things aren't really
|
||||
* tested.
|
||||
*/
|
||||
#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 /* not implemented */
|
||||
#define F_SETLK 6
|
||||
#define F_SETLKW 7
|
||||
|
||||
/* for F_[GET|SET]FL */
|
||||
#define FD_CLOEXEC 1 /* actually anything with low bit set goes */
|
||||
|
||||
/* Ok, these are locking features, and aren't implemented at any
|
||||
* level. POSIX wants them.
|
||||
*/
|
||||
#define F_RDLCK 0
|
||||
#define F_WRLCK 1
|
||||
#define F_UNLCK 2
|
||||
|
||||
/* Once again - not implemented, but ... */
|
||||
struct flock {
|
||||
short l_type;
|
||||
short l_whence;
|
||||
off_t l_start;
|
||||
off_t l_len;
|
||||
pid_t l_pid;
|
||||
};
|
||||
|
||||
extern int creat(const char * filename,mode_t mode);
|
||||
extern int fcntl(int fildes,int cmd, ...);
|
||||
extern int open(const char * filename, int flags, ...);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,25 @@
|
||||
/* float.h */
|
||||
/* Produced by hard-params version 4.1, CWI, Amsterdam */
|
||||
|
||||
#define FLT_RADIX 2
|
||||
#define FLT_MANT_DIG 24
|
||||
#define FLT_DIG 6
|
||||
#define FLT_ROUNDS 1
|
||||
#define FLT_EPSILON ((float)1.19209290e-07)
|
||||
#define FLT_MIN_EXP (-125)
|
||||
#define FLT_MIN ((float)1.17549435e-38)
|
||||
#define FLT_MIN_10_EXP (-37)
|
||||
#define FLT_MAX_EXP 128
|
||||
#define FLT_MAX ((float)3.40282347e+38)
|
||||
#define FLT_MAX_10_EXP 38
|
||||
|
||||
#define DBL_MANT_DIG 53
|
||||
#define DBL_DIG 15
|
||||
#define DBL_EPSILON 2.2204460492503131e-16
|
||||
#define DBL_MIN_EXP (-1021)
|
||||
#define DBL_MIN 2.2250738585072014e-308
|
||||
#define DBL_MIN_10_EXP (-307)
|
||||
#define DBL_MAX_EXP 1024
|
||||
#define DBL_MAX 1.7976931348623157e+308
|
||||
#define DBL_MAX_10_EXP 308
|
||||
|
||||
@ -0,0 +1,11 @@
|
||||
#ifndef _GETOPT_H
|
||||
#define _GETOPT_H
|
||||
|
||||
extern int opterr;
|
||||
extern int optind;
|
||||
extern int optopt;
|
||||
extern char *optarg;
|
||||
|
||||
extern int getopt(int argc, char ** argv, char * opts);
|
||||
|
||||
#endif /* _GETOPT_H */
|
||||
@ -0,0 +1,83 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
#ifndef __GNU_STABS_H
|
||||
|
||||
#define __GNU_STABS_H 1
|
||||
|
||||
#ifdef __GNU_STAB__
|
||||
|
||||
/* Alias a function:
|
||||
function_alias(creat, _creat, int, (file, mode),
|
||||
DEFUN(creat, (file, mode),
|
||||
CONST char *file AND int mode))
|
||||
Yes, this is very repetitive. Nothing you can do about it, so shut up. */
|
||||
#define function_alias(name, _name, type, args, defun) \
|
||||
symbol_alias(_name, name);
|
||||
|
||||
/* Make references to ALIAS refer to SYMBOL. */
|
||||
#ifdef __STDC__
|
||||
#define symbol_alias(symbol, alias) \
|
||||
asm(".stabs \"" "_" #alias "\",11,0,0,0\n"\
|
||||
".stabs \"" "_" #symbol "\",1,0,0,0")
|
||||
#else
|
||||
/* Your assembler better grok this right! */
|
||||
#define symbol_alias(symbol, alias) \
|
||||
asm(".stabs \"_/**/alias\",11,0,0,0\n.stabs \"_/**/symbol\",1,0,0,0")
|
||||
#endif
|
||||
|
||||
/* Issue a warning message from the linker whenever SYMBOL is referenced. */
|
||||
#ifdef __STDC__
|
||||
#define warn_references(symbol, msg) \
|
||||
asm(".stabs \"" msg "\",30,0,0,0\n" \
|
||||
".stabs \"_" #symbol "\",1,0,0,0")
|
||||
#else
|
||||
#define warn_references(symbol, msg) \
|
||||
asm(".stabs msg,30,0,0,0\n.stabs \"_/**/symbol\",1,0,0,0")
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
#define stub_warning(name) \
|
||||
warn_references(name, \
|
||||
"warning: " #name " is not implemented and will always fail")
|
||||
#else
|
||||
#define stub_warning(name) \
|
||||
warn_references(name, \
|
||||
"warning: name is not implemented and will always fail")
|
||||
#endif
|
||||
|
||||
#ifdef __STDC__
|
||||
#define text_set_element(set, symbol) \
|
||||
asm(".stabs \"_" #set "\",23,0,0,_" #symbol)
|
||||
#define data_set_element(set, symbol) \
|
||||
asm(".stabs \"_" #set "\",25,0,0,_" #symbol)
|
||||
#else
|
||||
#define text_set_element(set, symbol) \
|
||||
asm(".stabs \"_/**/set\",23,0,0,_/**/symbol")
|
||||
#define data_set_element(set, symbol) \
|
||||
asm(".stabs \"_/**/set\",25,0,0,_/**/symbol")
|
||||
#endif
|
||||
|
||||
#else /* No GNU stabs. */
|
||||
|
||||
#define function_alias(name, _name, type, args, defun) \
|
||||
type defun { return name args; }
|
||||
|
||||
#endif /* GNU stabs. */
|
||||
|
||||
#endif /* gnu-stabs.h */
|
||||
@ -0,0 +1,101 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
/*
|
||||
* POSIX Standard: 9.2.1 Group Database Access <grp.h>
|
||||
*/
|
||||
|
||||
#ifndef _GRP_H
|
||||
|
||||
#define _GRP_H 1
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define __USE_SVID
|
||||
#define __USE_BSD
|
||||
#define __USE_GNU
|
||||
|
||||
/* The group structure. */
|
||||
struct group
|
||||
{
|
||||
char *gr_name; /* Group name. */
|
||||
char *gr_passwd; /* Password. */
|
||||
gid_t gr_gid; /* Group ID. */
|
||||
char **gr_mem; /* Member list. */
|
||||
};
|
||||
|
||||
|
||||
#if defined(__USE_SVID) || defined(__USE_GNU)
|
||||
#define __need_FILE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef __USE_GNU
|
||||
/* Return a new stream open on the group file. */
|
||||
extern FILE *EXFUN(__grpopen, (NOARGS));
|
||||
|
||||
/* Read a group entry from STREAM, filling in G.
|
||||
Return the `struct group' of G if successful, NULL on failure. */
|
||||
extern struct group *EXFUN(__grpread, (FILE *__stream, PTR __g));
|
||||
|
||||
/* Return a chunk of memory containing pre-initialized data for __grpread. */
|
||||
extern PTR EXFUN(__grpalloc, (NOARGS));
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__USE_SVID) || defined(__USE_MISC)
|
||||
/* Rewind the group-file stream. */
|
||||
extern void EXFUN(setgrent, (NOARGS));
|
||||
|
||||
/* Close the group-file stream. */
|
||||
extern void EXFUN(endgrent, (NOARGS));
|
||||
|
||||
/* Read an entry from the group-file stream, opening it if necessary. */
|
||||
extern struct group *EXFUN(getgrent, (NOARGS));
|
||||
#endif
|
||||
|
||||
#ifdef __USE_SVID
|
||||
/* Read a group entry from STREAM. */
|
||||
extern struct group *EXFUN(fgetgrent, (FILE *__stream));
|
||||
#endif
|
||||
|
||||
/* Search for an entry with a matching group ID. */
|
||||
extern struct group *EXFUN(getgrgid, (gid_t __gid));
|
||||
|
||||
/* Search for an entry with a matching group name. */
|
||||
extern struct group *EXFUN(getgrnam, (CONST char *__name));
|
||||
|
||||
|
||||
#ifdef __USE_BSD
|
||||
|
||||
#define __need_size_t
|
||||
#include <stddef.h>
|
||||
|
||||
/* Set the group set for the current user to GROUPS (N of them). */
|
||||
extern int EXFUN(setgroups, (size_t __n, CONST gid_t *groups));
|
||||
|
||||
/* Initialize the group set for the current user
|
||||
by reading the group database and using all groups
|
||||
of which USER is a member. Also include GROUP. */
|
||||
extern int EXFUN(initgroups, (CONST char *user, gid_t group));
|
||||
|
||||
#endif /* Use BSD. */
|
||||
|
||||
|
||||
#endif /* grp.h */
|
||||
@ -0,0 +1,59 @@
|
||||
#ifndef _LIMITS_H
|
||||
#define _LIMITS_H
|
||||
|
||||
#define RAND_MAX 0x7ffffffd /* don't ask - see rand.c */
|
||||
|
||||
#define CHAR_BIT 8
|
||||
#define MB_LEN_MAX 1
|
||||
|
||||
#define SCHAR_MIN (-128)
|
||||
#define SCHAR_MAX 127
|
||||
|
||||
#define UCHAR_MAX 255U
|
||||
|
||||
#ifdef __CHAR_UNSIGNED__
|
||||
#define CHAR_MIN 0
|
||||
#define CHAR_MAX UCHAR_MAX
|
||||
#else
|
||||
#define CHAR_MIN SCHAR_MIN
|
||||
#define CHAR_MAX SCHAR_MAX
|
||||
#endif
|
||||
|
||||
#define SHRT_MIN (-32768)
|
||||
#define SHRT_MAX 32767
|
||||
|
||||
#define USHRT_MAX 65535U
|
||||
|
||||
#define INT_MIN (-2147483648)
|
||||
#define INT_MAX 2147483647
|
||||
|
||||
#define UINT_MAX 4294967295U
|
||||
|
||||
#define LONG_MIN (-2147483648)
|
||||
#define LONG_MAX 2147483647
|
||||
|
||||
#define ULONG_MAX 4294967295U
|
||||
|
||||
#define _POSIX_ARG_MAX 40960 /* exec() may have 40K worth of args */
|
||||
#define _POSIX_CHILD_MAX 6 /* a process may have 6 children */
|
||||
#define _POSIX_LINK_MAX 8 /* a file may have 8 links */
|
||||
#define _POSIX_MAX_CANON 255 /* size of the canonical input queue */
|
||||
#define _POSIX_MAX_INPUT 255 /* you can type 255 chars ahead */
|
||||
#define _POSIX_NAME_MAX 14 /* a file name may have 14 chars */
|
||||
#define _POSIX_NGROUPS_MAX 0 /* supplementary group IDs are optional */
|
||||
#define _POSIX_OPEN_MAX 16 /* a process may have 16 files open */
|
||||
#define _POSIX_PATH_MAX 255 /* a pathname may contain 255 chars */
|
||||
#define _POSIX_PIPE_BUF 512 /* pipes writes of 512 bytes must be atomic */
|
||||
|
||||
#define NGROUPS_MAX 0 /* supplemental group IDs not available */
|
||||
#define ARG_MAX 40960 /* # bytes of args + environ for exec() */
|
||||
#define CHILD_MAX 999 /* no limit :-) */
|
||||
#define OPEN_MAX 20 /* # open files a process may have */
|
||||
#define LINK_MAX 127 /* # links a file may have */
|
||||
#define MAX_CANON 255 /* size of the canonical input queue */
|
||||
#define MAX_INPUT 255 /* size of the type-ahead buffer */
|
||||
#define NAME_MAX 14 /* # chars in a file name */
|
||||
#define PATH_MAX 1024 /* # chars in a path name */
|
||||
#define PIPE_BUF 4095 /* # bytes in atomic write to a pipe */
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,48 @@
|
||||
#ifndef _CONFIG_H
|
||||
#define _CONFIG_H
|
||||
|
||||
/*
|
||||
* The root-device is no longer hard-coded. You can change the default
|
||||
* root-device by changing the line ROOT_DEV = XXX in boot/bootsect.s
|
||||
*/
|
||||
|
||||
/*
|
||||
* define your keyboard here -
|
||||
* KBD_FINNISH for Finnish keyboards
|
||||
* KBD_US for US-type
|
||||
* KBD_GR for German keyboards
|
||||
* KBD_FR for Frech keyboard
|
||||
*/
|
||||
/*#define KBD_US */
|
||||
/*#define KBD_GR */
|
||||
/*#define KBD_FR */
|
||||
#define KBD_FINNISH
|
||||
|
||||
/*
|
||||
* Normally, Linux can get the drive parameters from the BIOS at
|
||||
* startup, but if this for some unfathomable reason fails, you'd
|
||||
* be left stranded. For this case, you can define HD_TYPE, which
|
||||
* contains all necessary info on your harddisk.
|
||||
*
|
||||
* The HD_TYPE macro should look like this:
|
||||
*
|
||||
* #define HD_TYPE { head, sect, cyl, wpcom, lzone, ctl}
|
||||
*
|
||||
* In case of two harddisks, the info should be sepatated by
|
||||
* commas:
|
||||
*
|
||||
* #define HD_TYPE { h,s,c,wpcom,lz,ctl },{ h,s,c,wpcom,lz,ctl }
|
||||
*/
|
||||
/*
|
||||
This is an example, two drives, first is type 2, second is type 3:
|
||||
|
||||
#define HD_TYPE { 4,17,615,300,615,8 }, { 6,17,615,300,615,0 }
|
||||
|
||||
NOTE: ctl is 0 for all drives with heads<=8, and ctl=8 for drives
|
||||
with more than 8 heads.
|
||||
|
||||
If you want the BIOS to tell what kind of drive you have, just
|
||||
leave HD_TYPE undefined. This is the normal thing to do.
|
||||
*/
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,71 @@
|
||||
/*
|
||||
* This file contains some defines for the floppy disk controller.
|
||||
* Various sources. Mostly "IBM Microcomputers: A Programmers
|
||||
* Handbook", Sanches and Canton.
|
||||
*/
|
||||
#ifndef _FDREG_H
|
||||
#define _FDREG_H
|
||||
|
||||
extern int ticks_to_floppy_on(unsigned int nr);
|
||||
extern void floppy_on(unsigned int nr);
|
||||
extern void floppy_off(unsigned int nr);
|
||||
extern void floppy_select(unsigned int nr);
|
||||
extern void floppy_deselect(unsigned int nr);
|
||||
|
||||
/* Fd controller regs. S&C, about page 340 */
|
||||
#define FD_STATUS 0x3f4
|
||||
#define FD_DATA 0x3f5
|
||||
#define FD_DOR 0x3f2 /* Digital Output Register */
|
||||
#define FD_DIR 0x3f7 /* Digital Input Register (read) */
|
||||
#define FD_DCR 0x3f7 /* Diskette Control Register (write)*/
|
||||
|
||||
/* Bits of main status register */
|
||||
#define STATUS_BUSYMASK 0x0F /* drive busy mask */
|
||||
#define STATUS_BUSY 0x10 /* FDC busy */
|
||||
#define STATUS_DMA 0x20 /* 0- DMA mode */
|
||||
#define STATUS_DIR 0x40 /* 0- cpu->fdc */
|
||||
#define STATUS_READY 0x80 /* Data reg ready */
|
||||
|
||||
/* Bits of FD_ST0 */
|
||||
#define ST0_DS 0x03 /* drive select mask */
|
||||
#define ST0_HA 0x04 /* Head (Address) */
|
||||
#define ST0_NR 0x08 /* Not Ready */
|
||||
#define ST0_ECE 0x10 /* Equipment chech error */
|
||||
#define ST0_SE 0x20 /* Seek end */
|
||||
#define ST0_INTR 0xC0 /* Interrupt code mask */
|
||||
|
||||
/* Bits of FD_ST1 */
|
||||
#define ST1_MAM 0x01 /* Missing Address Mark */
|
||||
#define ST1_WP 0x02 /* Write Protect */
|
||||
#define ST1_ND 0x04 /* No Data - unreadable */
|
||||
#define ST1_OR 0x10 /* OverRun */
|
||||
#define ST1_CRC 0x20 /* CRC error in data or addr */
|
||||
#define ST1_EOC 0x80 /* End Of Cylinder */
|
||||
|
||||
/* Bits of FD_ST2 */
|
||||
#define ST2_MAM 0x01 /* Missing Addess Mark (again) */
|
||||
#define ST2_BC 0x02 /* Bad Cylinder */
|
||||
#define ST2_SNS 0x04 /* Scan Not Satisfied */
|
||||
#define ST2_SEH 0x08 /* Scan Equal Hit */
|
||||
#define ST2_WC 0x10 /* Wrong Cylinder */
|
||||
#define ST2_CRC 0x20 /* CRC error in data field */
|
||||
#define ST2_CM 0x40 /* Control Mark = deleted */
|
||||
|
||||
/* Bits of FD_ST3 */
|
||||
#define ST3_HA 0x04 /* Head (Address) */
|
||||
#define ST3_TZ 0x10 /* Track Zero signal (1=track 0) */
|
||||
#define ST3_WP 0x40 /* Write Protect */
|
||||
|
||||
/* Values for FD_COMMAND */
|
||||
#define FD_RECALIBRATE 0x07 /* move to track 0 */
|
||||
#define FD_SEEK 0x0F /* seek track */
|
||||
#define FD_READ 0xE6 /* read with MT, MFM, SKip deleted */
|
||||
#define FD_WRITE 0xC5 /* write with MT, MFM */
|
||||
#define FD_SENSEI 0x08 /* Sense Interrupt Status */
|
||||
#define FD_SPECIFY 0x03 /* specify HUT etc */
|
||||
|
||||
/* DMA commands */
|
||||
#define DMA_READ 0x46
|
||||
#define DMA_WRITE 0x4A
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,202 @@
|
||||
/*
|
||||
* This file has definitions for some important file table
|
||||
* structures etc.
|
||||
*/
|
||||
|
||||
#ifndef _FS_H
|
||||
#define _FS_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
/* devices are as follows: (same as minix, so we can use the minix
|
||||
* file system. These are major numbers.)
|
||||
*
|
||||
* 0 - unused (nodev)
|
||||
* 1 - /dev/mem
|
||||
* 2 - /dev/fd
|
||||
* 3 - /dev/hd
|
||||
* 4 - /dev/ttyx
|
||||
* 5 - /dev/tty
|
||||
* 6 - /dev/lp
|
||||
* 7 - unnamed pipes
|
||||
*/
|
||||
|
||||
#define IS_SEEKABLE(x) ((x)>=1 && (x)<=3)
|
||||
|
||||
#define READ 0
|
||||
#define WRITE 1
|
||||
#define READA 2 /* read-ahead - don't pause */
|
||||
#define WRITEA 3 /* "write-ahead" - silly, but somewhat useful */
|
||||
|
||||
void buffer_init(long buffer_end);
|
||||
|
||||
#define MAJOR(a) (((unsigned)(a))>>8)
|
||||
#define MINOR(a) ((a)&0xff)
|
||||
|
||||
#define NAME_LEN 14
|
||||
#define ROOT_INO 1
|
||||
|
||||
#define I_MAP_SLOTS 8
|
||||
#define Z_MAP_SLOTS 8
|
||||
#define SUPER_MAGIC 0x137F
|
||||
|
||||
#define NR_OPEN 20
|
||||
#define NR_INODE 32
|
||||
#define NR_FILE 64
|
||||
#define NR_SUPER 8
|
||||
#define NR_HASH 307
|
||||
#define NR_BUFFERS nr_buffers
|
||||
#define BLOCK_SIZE 1024
|
||||
#define BLOCK_SIZE_BITS 10
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
#define INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct d_inode)))
|
||||
#define DIR_ENTRIES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct dir_entry)))
|
||||
|
||||
#define PIPE_HEAD(inode) ((inode).i_zone[0])
|
||||
#define PIPE_TAIL(inode) ((inode).i_zone[1])
|
||||
#define PIPE_SIZE(inode) ((PIPE_HEAD(inode)-PIPE_TAIL(inode))&(PAGE_SIZE-1))
|
||||
#define PIPE_EMPTY(inode) (PIPE_HEAD(inode)==PIPE_TAIL(inode))
|
||||
#define PIPE_FULL(inode) (PIPE_SIZE(inode)==(PAGE_SIZE-1))
|
||||
#define INC_PIPE(head) \
|
||||
__asm__("incl %0\n\tandl $4095,%0"::"m" (head))
|
||||
|
||||
typedef char buffer_block[BLOCK_SIZE];
|
||||
|
||||
struct buffer_head {
|
||||
char * b_data; /* pointer to data block (1024 bytes) */
|
||||
unsigned long b_blocknr; /* block number */
|
||||
unsigned short b_dev; /* device (0 = free) */
|
||||
unsigned char b_uptodate;
|
||||
unsigned char b_dirt; /* 0-clean,1-dirty */
|
||||
unsigned char b_count; /* users using this block */
|
||||
unsigned char b_lock; /* 0 - ok, 1 -locked */
|
||||
struct task_struct * b_wait;
|
||||
struct buffer_head * b_prev;
|
||||
struct buffer_head * b_next;
|
||||
struct buffer_head * b_prev_free;
|
||||
struct buffer_head * b_next_free;
|
||||
};
|
||||
|
||||
struct d_inode {
|
||||
unsigned short i_mode;
|
||||
unsigned short i_uid;
|
||||
unsigned long i_size;
|
||||
unsigned long i_time;
|
||||
unsigned char i_gid;
|
||||
unsigned char i_nlinks;
|
||||
unsigned short i_zone[9];
|
||||
};
|
||||
|
||||
struct m_inode {
|
||||
unsigned short i_mode;
|
||||
unsigned short i_uid;
|
||||
unsigned long i_size;
|
||||
unsigned long i_mtime;
|
||||
unsigned char i_gid;
|
||||
unsigned char i_nlinks;
|
||||
unsigned short i_zone[9];
|
||||
/* these are in memory also */
|
||||
struct task_struct * i_wait;
|
||||
unsigned long i_atime;
|
||||
unsigned long i_ctime;
|
||||
unsigned short i_dev;
|
||||
unsigned short i_num;
|
||||
unsigned short i_count;
|
||||
unsigned char i_lock;
|
||||
unsigned char i_dirt;
|
||||
unsigned char i_pipe;
|
||||
unsigned char i_mount;
|
||||
unsigned char i_seek;
|
||||
unsigned char i_update;
|
||||
};
|
||||
|
||||
struct file {
|
||||
unsigned short f_mode;
|
||||
unsigned short f_flags;
|
||||
unsigned short f_count;
|
||||
struct m_inode * f_inode;
|
||||
off_t f_pos;
|
||||
};
|
||||
|
||||
struct super_block {
|
||||
unsigned short s_ninodes;
|
||||
unsigned short s_nzones;
|
||||
unsigned short s_imap_blocks;
|
||||
unsigned short s_zmap_blocks;
|
||||
unsigned short s_firstdatazone;
|
||||
unsigned short s_log_zone_size;
|
||||
unsigned long s_max_size;
|
||||
unsigned short s_magic;
|
||||
/* These are only in memory */
|
||||
struct buffer_head * s_imap[8];
|
||||
struct buffer_head * s_zmap[8];
|
||||
unsigned short s_dev;
|
||||
struct m_inode * s_isup;
|
||||
struct m_inode * s_imount;
|
||||
unsigned long s_time;
|
||||
struct task_struct * s_wait;
|
||||
unsigned char s_lock;
|
||||
unsigned char s_rd_only;
|
||||
unsigned char s_dirt;
|
||||
};
|
||||
|
||||
struct d_super_block {
|
||||
unsigned short s_ninodes;
|
||||
unsigned short s_nzones;
|
||||
unsigned short s_imap_blocks;
|
||||
unsigned short s_zmap_blocks;
|
||||
unsigned short s_firstdatazone;
|
||||
unsigned short s_log_zone_size;
|
||||
unsigned long s_max_size;
|
||||
unsigned short s_magic;
|
||||
};
|
||||
|
||||
struct dir_entry {
|
||||
unsigned short inode;
|
||||
char name[NAME_LEN];
|
||||
};
|
||||
|
||||
extern struct m_inode inode_table[NR_INODE];
|
||||
extern struct file file_table[NR_FILE];
|
||||
extern struct super_block super_block[NR_SUPER];
|
||||
extern struct buffer_head * start_buffer;
|
||||
extern int nr_buffers;
|
||||
|
||||
extern void check_disk_change(int dev);
|
||||
extern int floppy_change(unsigned int nr);
|
||||
extern int ticks_to_floppy_on(unsigned int dev);
|
||||
extern void floppy_on(unsigned int dev);
|
||||
extern void floppy_off(unsigned int dev);
|
||||
extern void truncate(struct m_inode * inode);
|
||||
extern void sync_inodes(void);
|
||||
extern void wait_on(struct m_inode * inode);
|
||||
extern int bmap(struct m_inode * inode,int block);
|
||||
extern int create_block(struct m_inode * inode,int block);
|
||||
extern struct m_inode * namei(const char * pathname);
|
||||
extern int open_namei(const char * pathname, int flag, int mode,
|
||||
struct m_inode ** res_inode);
|
||||
extern void iput(struct m_inode * inode);
|
||||
extern struct m_inode * iget(int dev,int nr);
|
||||
extern struct m_inode * get_empty_inode(void);
|
||||
extern struct m_inode * get_pipe_inode(void);
|
||||
extern struct buffer_head * get_hash_table(int dev, int block);
|
||||
extern struct buffer_head * getblk(int dev, int block);
|
||||
extern void ll_rw_block(int rw, struct buffer_head * bh);
|
||||
extern void brelse(struct buffer_head * buf);
|
||||
extern struct buffer_head * bread(int dev,int block);
|
||||
extern void bread_page(unsigned long addr,int dev,int b[4]);
|
||||
extern struct buffer_head * breada(int dev,int block,...);
|
||||
extern int new_block(int dev);
|
||||
extern void free_block(int dev, int block);
|
||||
extern struct m_inode * new_inode(int dev);
|
||||
extern void free_inode(struct m_inode * inode);
|
||||
extern int sync_dev(int dev);
|
||||
extern struct super_block * get_super(int dev);
|
||||
extern int ROOT_DEV;
|
||||
|
||||
extern void mount_root(void);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,65 @@
|
||||
/*
|
||||
* This file contains some defines for the AT-hd-controller.
|
||||
* Various sources. Check out some definitions (see comments with
|
||||
* a ques).
|
||||
*/
|
||||
#ifndef _HDREG_H
|
||||
#define _HDREG_H
|
||||
|
||||
/* Hd controller regs. Ref: IBM AT Bios-listing */
|
||||
#define HD_DATA 0x1f0 /* _CTL when writing */
|
||||
#define HD_ERROR 0x1f1 /* see err-bits */
|
||||
#define HD_NSECTOR 0x1f2 /* nr of sectors to read/write */
|
||||
#define HD_SECTOR 0x1f3 /* starting sector */
|
||||
#define HD_LCYL 0x1f4 /* starting cylinder */
|
||||
#define HD_HCYL 0x1f5 /* high byte of starting cyl */
|
||||
#define HD_CURRENT 0x1f6 /* 101dhhhh , d=drive, hhhh=head */
|
||||
#define HD_STATUS 0x1f7 /* see status-bits */
|
||||
#define HD_PRECOMP HD_ERROR /* same io address, read=error, write=precomp */
|
||||
#define HD_COMMAND HD_STATUS /* same io address, read=status, write=cmd */
|
||||
|
||||
#define HD_CMD 0x3f6
|
||||
|
||||
/* Bits of HD_STATUS */
|
||||
#define ERR_STAT 0x01
|
||||
#define INDEX_STAT 0x02
|
||||
#define ECC_STAT 0x04 /* Corrected error */
|
||||
#define DRQ_STAT 0x08
|
||||
#define SEEK_STAT 0x10
|
||||
#define WRERR_STAT 0x20
|
||||
#define READY_STAT 0x40
|
||||
#define BUSY_STAT 0x80
|
||||
|
||||
/* Values for HD_COMMAND */
|
||||
#define WIN_RESTORE 0x10
|
||||
#define WIN_READ 0x20
|
||||
#define WIN_WRITE 0x30
|
||||
#define WIN_VERIFY 0x40
|
||||
#define WIN_FORMAT 0x50
|
||||
#define WIN_INIT 0x60
|
||||
#define WIN_SEEK 0x70
|
||||
#define WIN_DIAGNOSE 0x90
|
||||
#define WIN_SPECIFY 0x91
|
||||
|
||||
/* Bits for HD_ERROR */
|
||||
#define MARK_ERR 0x01 /* Bad address mark ? */
|
||||
#define TRK0_ERR 0x02 /* couldn't find track 0 */
|
||||
#define ABRT_ERR 0x04 /* ? */
|
||||
#define ID_ERR 0x10 /* ? */
|
||||
#define ECC_ERR 0x40 /* ? */
|
||||
#define BBD_ERR 0x80 /* ? */
|
||||
|
||||
struct partition {
|
||||
unsigned char boot_ind; /* 0x80 - active (unused) */
|
||||
unsigned char head; /* ? */
|
||||
unsigned char sector; /* ? */
|
||||
unsigned char cyl; /* ? */
|
||||
unsigned char sys_ind; /* ? */
|
||||
unsigned char end_head; /* ? */
|
||||
unsigned char end_sector; /* ? */
|
||||
unsigned char end_cyl; /* ? */
|
||||
unsigned int start_sect; /* starting sector counting from 0 */
|
||||
unsigned int nr_sects; /* nr of sectors in partition */
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,20 @@
|
||||
#ifndef _HEAD_H
|
||||
#define _HEAD_H
|
||||
|
||||
typedef struct desc_struct {
|
||||
unsigned long a,b;
|
||||
} desc_table[256];
|
||||
|
||||
extern unsigned long pg_dir[1024];
|
||||
extern desc_table idt,gdt;
|
||||
|
||||
#define GDT_NUL 0
|
||||
#define GDT_CODE 1
|
||||
#define GDT_DATA 2
|
||||
#define GDT_TMP 3
|
||||
|
||||
#define LDT_NUL 0
|
||||
#define LDT_CODE 1
|
||||
#define LDT_DATA 2
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,22 @@
|
||||
/*
|
||||
* 'kernel.h' contains some often-used function prototypes etc
|
||||
*/
|
||||
void verify_area(void * addr,int count);
|
||||
volatile void panic(const char * str);
|
||||
int printf(const char * fmt, ...);
|
||||
int printk(const char * fmt, ...);
|
||||
int tty_write(unsigned ch,char * buf,int count);
|
||||
void * malloc(unsigned int size);
|
||||
void free_s(void * obj, int size);
|
||||
|
||||
#define free(x) free_s((x), 0)
|
||||
|
||||
/*
|
||||
* This is defined as a macro, but at some point this might become a
|
||||
* real subroutine that sets a flag if it returns true (to do
|
||||
* BSD-style accounting where the process is flagged if it uses root
|
||||
* privs). The implication of this is that you should do normal
|
||||
* permissions checks first, and check suser() last.
|
||||
*/
|
||||
#define suser() (current->euid == 0)
|
||||
|
||||
@ -0,0 +1,10 @@
|
||||
#ifndef _MM_H
|
||||
#define _MM_H
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
extern unsigned long get_free_page(void);
|
||||
extern unsigned long put_page(unsigned long page,unsigned long address);
|
||||
extern void free_page(unsigned long addr);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,233 @@
|
||||
#ifndef _SCHED_H
|
||||
#define _SCHED_H
|
||||
|
||||
#define NR_TASKS 64
|
||||
#define HZ 100
|
||||
|
||||
#define FIRST_TASK task[0]
|
||||
#define LAST_TASK task[NR_TASKS-1]
|
||||
|
||||
#include <linux/head.h>
|
||||
#include <linux/fs.h>
|
||||
#include <linux/mm.h>
|
||||
#include <signal.h>
|
||||
|
||||
#if (NR_OPEN > 32)
|
||||
#error "Currently the close-on-exec-flags are in one word, max 32 files/proc"
|
||||
#endif
|
||||
|
||||
#define TASK_RUNNING 0
|
||||
#define TASK_INTERRUPTIBLE 1
|
||||
#define TASK_UNINTERRUPTIBLE 2
|
||||
#define TASK_ZOMBIE 3
|
||||
#define TASK_STOPPED 4
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
extern int copy_page_tables(unsigned long from, unsigned long to, long size);
|
||||
extern int free_page_tables(unsigned long from, unsigned long size);
|
||||
|
||||
extern void sched_init(void);
|
||||
extern void schedule(void);
|
||||
extern void trap_init(void);
|
||||
extern void panic(const char * str);
|
||||
extern int tty_write(unsigned minor,char * buf,int count);
|
||||
|
||||
typedef int (*fn_ptr)();
|
||||
|
||||
struct i387_struct {
|
||||
long cwd;
|
||||
long swd;
|
||||
long twd;
|
||||
long fip;
|
||||
long fcs;
|
||||
long foo;
|
||||
long fos;
|
||||
long st_space[20]; /* 8*10 bytes for each FP-reg = 80 bytes */
|
||||
};
|
||||
|
||||
struct tss_struct {
|
||||
long back_link; /* 16 high bits zero */
|
||||
long esp0;
|
||||
long ss0; /* 16 high bits zero */
|
||||
long esp1;
|
||||
long ss1; /* 16 high bits zero */
|
||||
long esp2;
|
||||
long ss2; /* 16 high bits zero */
|
||||
long cr3;
|
||||
long eip;
|
||||
long eflags;
|
||||
long eax,ecx,edx,ebx;
|
||||
long esp;
|
||||
long ebp;
|
||||
long esi;
|
||||
long edi;
|
||||
long es; /* 16 high bits zero */
|
||||
long cs; /* 16 high bits zero */
|
||||
long ss; /* 16 high bits zero */
|
||||
long ds; /* 16 high bits zero */
|
||||
long fs; /* 16 high bits zero */
|
||||
long gs; /* 16 high bits zero */
|
||||
long ldt; /* 16 high bits zero */
|
||||
long trace_bitmap; /* bits: trace 0, bitmap 16-31 */
|
||||
struct i387_struct i387;
|
||||
};
|
||||
|
||||
struct task_struct {
|
||||
/* these are hardcoded - don't touch */
|
||||
long state; /* -1 unrunnable, 0 runnable, >0 stopped */
|
||||
long counter;
|
||||
long priority;
|
||||
long signal;
|
||||
struct sigaction sigaction[32];
|
||||
long blocked; /* bitmap of masked signals */
|
||||
/* various fields */
|
||||
int exit_code;
|
||||
unsigned long start_code,end_code,end_data,brk,start_stack;
|
||||
long pid,father,pgrp,session,leader;
|
||||
unsigned short uid,euid,suid;
|
||||
unsigned short gid,egid,sgid;
|
||||
long alarm;
|
||||
long utime,stime,cutime,cstime,start_time;
|
||||
unsigned short used_math;
|
||||
/* file system info */
|
||||
int tty; /* -1 if no tty, so it must be signed */
|
||||
unsigned short umask;
|
||||
struct m_inode * pwd;
|
||||
struct m_inode * root;
|
||||
struct m_inode * executable;
|
||||
unsigned long close_on_exec;
|
||||
struct file * filp[NR_OPEN];
|
||||
/* ldt for this task 0 - zero 1 - cs 2 - ds&ss */
|
||||
struct desc_struct ldt[3];
|
||||
/* tss for this task */
|
||||
struct tss_struct tss;
|
||||
};
|
||||
|
||||
/*
|
||||
* INIT_TASK is used to set up the first task table, touch at
|
||||
* your own risk!. Base=0, limit=0x9ffff (=640kB)
|
||||
*/
|
||||
#define INIT_TASK \
|
||||
/* state etc */ { 0,15,15, \
|
||||
/* signals */ 0,{{},},0, \
|
||||
/* ec,brk... */ 0,0,0,0,0,0, \
|
||||
/* pid etc.. */ 0,-1,0,0,0, \
|
||||
/* uid etc */ 0,0,0,0,0,0, \
|
||||
/* alarm */ 0,0,0,0,0,0, \
|
||||
/* math */ 0, \
|
||||
/* fs info */ -1,0022,NULL,NULL,NULL,0, \
|
||||
/* filp */ {NULL,}, \
|
||||
{ \
|
||||
{0,0}, \
|
||||
/* ldt */ {0x9f,0xc0fa00}, \
|
||||
{0x9f,0xc0f200}, \
|
||||
}, \
|
||||
/*tss*/ {0,PAGE_SIZE+(long)&init_task,0x10,0,0,0,0,(long)&pg_dir,\
|
||||
0,0,0,0,0,0,0,0, \
|
||||
0,0,0x17,0x17,0x17,0x17,0x17,0x17, \
|
||||
_LDT(0),0x80000000, \
|
||||
{} \
|
||||
}, \
|
||||
}
|
||||
|
||||
extern struct task_struct *task[NR_TASKS];
|
||||
extern struct task_struct *last_task_used_math;
|
||||
extern struct task_struct *current;
|
||||
extern long volatile jiffies;
|
||||
extern long startup_time;
|
||||
|
||||
#define CURRENT_TIME (startup_time+jiffies/HZ)
|
||||
|
||||
extern void add_timer(long jiffies, void (*fn)(void));
|
||||
extern void sleep_on(struct task_struct ** p);
|
||||
extern void interruptible_sleep_on(struct task_struct ** p);
|
||||
extern void wake_up(struct task_struct ** p);
|
||||
|
||||
/*
|
||||
* Entry into gdt where to find first TSS. 0-nul, 1-cs, 2-ds, 3-syscall
|
||||
* 4-TSS0, 5-LDT0, 6-TSS1 etc ...
|
||||
*/
|
||||
#define FIRST_TSS_ENTRY 4
|
||||
#define FIRST_LDT_ENTRY (FIRST_TSS_ENTRY+1)
|
||||
#define _TSS(n) ((((unsigned long) n)<<4)+(FIRST_TSS_ENTRY<<3))
|
||||
#define _LDT(n) ((((unsigned long) n)<<4)+(FIRST_LDT_ENTRY<<3))
|
||||
#define ltr(n) __asm__("ltr %%ax"::"a" (_TSS(n)))
|
||||
#define lldt(n) __asm__("lldt %%ax"::"a" (_LDT(n)))
|
||||
#define str(n) \
|
||||
__asm__("str %%ax\n\t" \
|
||||
"subl %2,%%eax\n\t" \
|
||||
"shrl $4,%%eax" \
|
||||
:"=a" (n) \
|
||||
:"a" (0),"i" (FIRST_TSS_ENTRY<<3))
|
||||
/*
|
||||
* switch_to(n) should switch tasks to task nr n, first
|
||||
* checking that n isn't the current task, in which case it does nothing.
|
||||
* This also clears the TS-flag if the task we switched to has used
|
||||
* tha math co-processor latest.
|
||||
*/
|
||||
#define switch_to(n) {\
|
||||
struct {long a,b;} __tmp; \
|
||||
__asm__("cmpl %%ecx,_current\n\t" \
|
||||
"je 1f\n\t" \
|
||||
"movw %%dx,%1\n\t" \
|
||||
"xchgl %%ecx,_current\n\t" \
|
||||
"ljmp %0\n\t" \
|
||||
"cmpl %%ecx,_last_task_used_math\n\t" \
|
||||
"jne 1f\n\t" \
|
||||
"clts\n" \
|
||||
"1:" \
|
||||
::"m" (*&__tmp.a),"m" (*&__tmp.b), \
|
||||
"d" (_TSS(n)),"c" ((long) task[n])); \
|
||||
}
|
||||
|
||||
#define PAGE_ALIGN(n) (((n)+0xfff)&0xfffff000)
|
||||
|
||||
#define _set_base(addr,base) \
|
||||
__asm__("movw %%dx,%0\n\t" \
|
||||
"rorl $16,%%edx\n\t" \
|
||||
"movb %%dl,%1\n\t" \
|
||||
"movb %%dh,%2" \
|
||||
::"m" (*((addr)+2)), \
|
||||
"m" (*((addr)+4)), \
|
||||
"m" (*((addr)+7)), \
|
||||
"d" (base) \
|
||||
:"dx")
|
||||
|
||||
#define _set_limit(addr,limit) \
|
||||
__asm__("movw %%dx,%0\n\t" \
|
||||
"rorl $16,%%edx\n\t" \
|
||||
"movb %1,%%dh\n\t" \
|
||||
"andb $0xf0,%%dh\n\t" \
|
||||
"orb %%dh,%%dl\n\t" \
|
||||
"movb %%dl,%1" \
|
||||
::"m" (*(addr)), \
|
||||
"m" (*((addr)+6)), \
|
||||
"d" (limit) \
|
||||
:"dx")
|
||||
|
||||
#define set_base(ldt,base) _set_base( ((char *)&(ldt)) , base )
|
||||
#define set_limit(ldt,limit) _set_limit( ((char *)&(ldt)) , (limit-1)>>12 )
|
||||
|
||||
#define _get_base(addr) ({\
|
||||
unsigned long __base; \
|
||||
__asm__("movb %3,%%dh\n\t" \
|
||||
"movb %2,%%dl\n\t" \
|
||||
"shll $16,%%edx\n\t" \
|
||||
"movw %1,%%dx" \
|
||||
:"=d" (__base) \
|
||||
:"m" (*((addr)+2)), \
|
||||
"m" (*((addr)+4)), \
|
||||
"m" (*((addr)+7))); \
|
||||
__base;})
|
||||
|
||||
#define get_base(ldt) _get_base( ((char *)&(ldt)) )
|
||||
|
||||
#define get_limit(segment) ({ \
|
||||
unsigned long __limit; \
|
||||
__asm__("lsll %1,%0\n\tincl %0":"=r" (__limit):"r" (segment)); \
|
||||
__limit;})
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,86 @@
|
||||
extern int sys_setup();
|
||||
extern int sys_exit();
|
||||
extern int sys_fork();
|
||||
extern int sys_read();
|
||||
extern int sys_write();
|
||||
extern int sys_open();
|
||||
extern int sys_close();
|
||||
extern int sys_waitpid();
|
||||
extern int sys_creat();
|
||||
extern int sys_link();
|
||||
extern int sys_unlink();
|
||||
extern int sys_execve();
|
||||
extern int sys_chdir();
|
||||
extern int sys_time();
|
||||
extern int sys_mknod();
|
||||
extern int sys_chmod();
|
||||
extern int sys_chown();
|
||||
extern int sys_break();
|
||||
extern int sys_stat();
|
||||
extern int sys_lseek();
|
||||
extern int sys_getpid();
|
||||
extern int sys_mount();
|
||||
extern int sys_umount();
|
||||
extern int sys_setuid();
|
||||
extern int sys_getuid();
|
||||
extern int sys_stime();
|
||||
extern int sys_ptrace();
|
||||
extern int sys_alarm();
|
||||
extern int sys_fstat();
|
||||
extern int sys_pause();
|
||||
extern int sys_utime();
|
||||
extern int sys_stty();
|
||||
extern int sys_gtty();
|
||||
extern int sys_access();
|
||||
extern int sys_nice();
|
||||
extern int sys_ftime();
|
||||
extern int sys_sync();
|
||||
extern int sys_kill();
|
||||
extern int sys_rename();
|
||||
extern int sys_mkdir();
|
||||
extern int sys_rmdir();
|
||||
extern int sys_dup();
|
||||
extern int sys_pipe();
|
||||
extern int sys_times();
|
||||
extern int sys_prof();
|
||||
extern int sys_brk();
|
||||
extern int sys_setgid();
|
||||
extern int sys_getgid();
|
||||
extern int sys_signal();
|
||||
extern int sys_geteuid();
|
||||
extern int sys_getegid();
|
||||
extern int sys_acct();
|
||||
extern int sys_phys();
|
||||
extern int sys_lock();
|
||||
extern int sys_ioctl();
|
||||
extern int sys_fcntl();
|
||||
extern int sys_mpx();
|
||||
extern int sys_setpgid();
|
||||
extern int sys_ulimit();
|
||||
extern int sys_uname();
|
||||
extern int sys_umask();
|
||||
extern int sys_chroot();
|
||||
extern int sys_ustat();
|
||||
extern int sys_dup2();
|
||||
extern int sys_getppid();
|
||||
extern int sys_getpgrp();
|
||||
extern int sys_setsid();
|
||||
extern int sys_sigaction();
|
||||
extern int sys_sgetmask();
|
||||
extern int sys_ssetmask();
|
||||
extern int sys_setreuid();
|
||||
extern int sys_setregid();
|
||||
|
||||
fn_ptr sys_call_table[] = { sys_setup, sys_exit, sys_fork, sys_read,
|
||||
sys_write, sys_open, sys_close, sys_waitpid, sys_creat, sys_link,
|
||||
sys_unlink, sys_execve, sys_chdir, sys_time, sys_mknod, sys_chmod,
|
||||
sys_chown, sys_break, sys_stat, sys_lseek, sys_getpid, sys_mount,
|
||||
sys_umount, sys_setuid, sys_getuid, sys_stime, sys_ptrace, sys_alarm,
|
||||
sys_fstat, sys_pause, sys_utime, sys_stty, sys_gtty, sys_access,
|
||||
sys_nice, sys_ftime, sys_sync, sys_kill, sys_rename, sys_mkdir,
|
||||
sys_rmdir, sys_dup, sys_pipe, sys_times, sys_prof, sys_brk, sys_setgid,
|
||||
sys_getgid, sys_signal, sys_geteuid, sys_getegid, sys_acct, sys_phys,
|
||||
sys_lock, sys_ioctl, sys_fcntl, sys_mpx, sys_setpgid, sys_ulimit,
|
||||
sys_uname, sys_umask, sys_chroot, sys_ustat, sys_dup2, sys_getppid,
|
||||
sys_getpgrp, sys_setsid, sys_sigaction, sys_sgetmask, sys_ssetmask,
|
||||
sys_setreuid,sys_setregid };
|
||||
@ -0,0 +1,77 @@
|
||||
/*
|
||||
* 'tty.h' defines some structures used by tty_io.c and some defines.
|
||||
*
|
||||
* NOTE! Don't touch this without checking that nothing in rs_io.s or
|
||||
* con_io.s breaks. Some constants are hardwired into the system (mainly
|
||||
* offsets into 'tty_queue'
|
||||
*/
|
||||
|
||||
#ifndef _TTY_H
|
||||
#define _TTY_H
|
||||
|
||||
#include <termios.h>
|
||||
|
||||
#define TTY_BUF_SIZE 1024
|
||||
|
||||
struct tty_queue {
|
||||
unsigned long data;
|
||||
unsigned long head;
|
||||
unsigned long tail;
|
||||
struct task_struct * proc_list;
|
||||
char buf[TTY_BUF_SIZE];
|
||||
};
|
||||
|
||||
#define INC(a) ((a) = ((a)+1) & (TTY_BUF_SIZE-1))
|
||||
#define DEC(a) ((a) = ((a)-1) & (TTY_BUF_SIZE-1))
|
||||
#define EMPTY(a) ((a).head == (a).tail)
|
||||
#define LEFT(a) (((a).tail-(a).head-1)&(TTY_BUF_SIZE-1))
|
||||
#define LAST(a) ((a).buf[(TTY_BUF_SIZE-1)&((a).head-1)])
|
||||
#define FULL(a) (!LEFT(a))
|
||||
#define CHARS(a) (((a).head-(a).tail)&(TTY_BUF_SIZE-1))
|
||||
#define GETCH(queue,c) \
|
||||
(void)({c=(queue).buf[(queue).tail];INC((queue).tail);})
|
||||
#define PUTCH(c,queue) \
|
||||
(void)({(queue).buf[(queue).head]=(c);INC((queue).head);})
|
||||
|
||||
#define INTR_CHAR(tty) ((tty)->termios.c_cc[VINTR])
|
||||
#define QUIT_CHAR(tty) ((tty)->termios.c_cc[VQUIT])
|
||||
#define ERASE_CHAR(tty) ((tty)->termios.c_cc[VERASE])
|
||||
#define KILL_CHAR(tty) ((tty)->termios.c_cc[VKILL])
|
||||
#define EOF_CHAR(tty) ((tty)->termios.c_cc[VEOF])
|
||||
#define START_CHAR(tty) ((tty)->termios.c_cc[VSTART])
|
||||
#define STOP_CHAR(tty) ((tty)->termios.c_cc[VSTOP])
|
||||
#define SUSPEND_CHAR(tty) ((tty)->termios.c_cc[VSUSP])
|
||||
|
||||
struct tty_struct {
|
||||
struct termios termios;
|
||||
int pgrp;
|
||||
int stopped;
|
||||
void (*write)(struct tty_struct * tty);
|
||||
struct tty_queue read_q;
|
||||
struct tty_queue write_q;
|
||||
struct tty_queue secondary;
|
||||
};
|
||||
|
||||
extern struct tty_struct tty_table[];
|
||||
|
||||
/* intr=^C quit=^| erase=del kill=^U
|
||||
eof=^D vtime=\0 vmin=\1 sxtc=\0
|
||||
start=^Q stop=^S susp=^Z eol=\0
|
||||
reprint=^R discard=^U werase=^W lnext=^V
|
||||
eol2=\0
|
||||
*/
|
||||
#define INIT_C_CC "\003\034\177\025\004\0\1\0\021\023\032\0\022\017\027\026\0"
|
||||
|
||||
void rs_init(void);
|
||||
void con_init(void);
|
||||
void tty_init(void);
|
||||
|
||||
int tty_read(unsigned c, char * buf, int n);
|
||||
int tty_write(unsigned c, char * buf, int n);
|
||||
|
||||
void rs_write(struct tty_struct * tty);
|
||||
void con_write(struct tty_struct * tty);
|
||||
|
||||
void copy_to_cooked(struct tty_struct * tty);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,208 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
/* Locale-specific information. */
|
||||
|
||||
#ifndef _LOCALEINFO_H
|
||||
|
||||
#define _LOCALEINFO_H 1
|
||||
|
||||
#define __need_size_t
|
||||
#define __need_wchar_t
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
|
||||
|
||||
/* Change these if the `wchar_t' type is changed. */
|
||||
#define WCHAR_MAX ((wchar_t) UCHAR_MAX)
|
||||
|
||||
|
||||
/* Used by multibyte char functions. */
|
||||
typedef struct
|
||||
{
|
||||
char *string; /* Bytes. */
|
||||
size_t len; /* # of bytes. */
|
||||
long int shift; /* # of mb_char's to shift. */
|
||||
} mb_char;
|
||||
|
||||
struct ctype_mbchar_info
|
||||
{
|
||||
size_t mb_max; /* Max MB char length. */
|
||||
mb_char *mb_chars; /* MB chars. */
|
||||
};
|
||||
|
||||
struct ctype_ctype_info
|
||||
{
|
||||
unsigned short int *ctype_b; /* Characteristics. */
|
||||
unsigned char *ctype_tolower; /* Case mappings. */
|
||||
unsigned char *ctype_toupper; /* Case mappings. */
|
||||
};
|
||||
|
||||
struct ctype_info
|
||||
{
|
||||
struct ctype_ctype_info *ctype;
|
||||
struct ctype_mbchar_info *mbchar;
|
||||
};
|
||||
|
||||
extern CONST struct ctype_info *_ctype_info;
|
||||
|
||||
/* These are necessary because they are used in a header file. */
|
||||
extern CONST unsigned short int *__ctype_b;
|
||||
extern CONST unsigned char *__ctype_tolower;
|
||||
extern CONST unsigned char *__ctype_toupper;
|
||||
|
||||
|
||||
/* Used by strcoll and strxfrm. */
|
||||
typedef struct
|
||||
{
|
||||
unsigned char *values;
|
||||
size_t nvalues;
|
||||
} literal_value;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
union
|
||||
{
|
||||
literal_value literal;
|
||||
/* %%% This may become a regex_t in the future. */
|
||||
char *regexp;
|
||||
} replace, with;
|
||||
unsigned int regexp:1;
|
||||
} subst;
|
||||
|
||||
struct collate_info
|
||||
{
|
||||
size_t nsubsts;
|
||||
subst *substs;
|
||||
|
||||
unsigned char *values;
|
||||
unsigned char *offsets;
|
||||
};
|
||||
|
||||
extern CONST struct collate_info *_collate_info;
|
||||
|
||||
|
||||
/* Used by strtod, atof. */
|
||||
struct numeric_info
|
||||
{
|
||||
char *decimal_point;
|
||||
char *thousands_sep;
|
||||
char *grouping;
|
||||
};
|
||||
|
||||
extern CONST struct numeric_info *_numeric_info;
|
||||
|
||||
|
||||
/* Used in the return value of localeconv. */
|
||||
struct monetary_info
|
||||
{
|
||||
char *int_curr_symbol;
|
||||
char *currency_symbol;
|
||||
char *mon_decimal_point;
|
||||
char *mon_thousands_sep;
|
||||
char *mon_grouping;
|
||||
char *positive_sign;
|
||||
char *negative_sign;
|
||||
char int_frac_digits;
|
||||
char frac_digits;
|
||||
char p_cs_precedes;
|
||||
char p_sep_by_space;
|
||||
char n_cs_precedes;
|
||||
char n_sep_by_space;
|
||||
char p_sign_posn;
|
||||
char n_sign_posn;
|
||||
};
|
||||
|
||||
extern CONST struct monetary_info *_monetary_info;
|
||||
|
||||
|
||||
/* Used by strftime, asctime. */
|
||||
struct time_info
|
||||
{
|
||||
char *abbrev_wkday[7]; /* Short weekday names. */
|
||||
char *full_wkday[7]; /* Full weekday names. */
|
||||
char *abbrev_month[12]; /* Short month names. */
|
||||
char *full_month[12]; /* Full month names. */
|
||||
char *ampm[2]; /* "AM" and "PM" strings. */
|
||||
|
||||
char *date_time; /* Appropriate date and time format. */
|
||||
char *date; /* Appropriate date format. */
|
||||
char *time; /* Appropriate time format. */
|
||||
|
||||
char *ut0; /* Name for GMT. */
|
||||
char *tz; /* Default TZ value. */
|
||||
};
|
||||
|
||||
extern CONST struct time_info *_time_info;
|
||||
|
||||
struct response_info
|
||||
{
|
||||
/* Regexp for affirmative answers. */
|
||||
char *yesexpr;
|
||||
|
||||
/* Regexp for negative answers. */
|
||||
char *noexpr;
|
||||
};
|
||||
|
||||
extern CONST struct response_info *_response_info;
|
||||
|
||||
/* Locale structure. */
|
||||
typedef struct
|
||||
{
|
||||
char *name;
|
||||
int categories;
|
||||
|
||||
unsigned int allocated:1;
|
||||
|
||||
int subcategories;
|
||||
size_t num_sublocales;
|
||||
struct sub_locale *sublocales;
|
||||
|
||||
PTR *info;
|
||||
} locale;
|
||||
|
||||
typedef struct sub_locale
|
||||
{
|
||||
unsigned int pointer:1;
|
||||
|
||||
int categories;
|
||||
char *name;
|
||||
|
||||
locale *locale;
|
||||
} sublocale;
|
||||
|
||||
|
||||
/* This is the magic number that localeinfo object files begin with.
|
||||
In case you're wondering why I chose the value 0x051472CA, it's
|
||||
because I was born on 05-14-72 in Oakland, CA. */
|
||||
#define LIMAGIC 0x051472CA
|
||||
/* This is the magic number that precedes each category-specific section
|
||||
of a localeinfo object file. It's the arbitrary magic number above,
|
||||
but modified by the category so that it's different from the per-file
|
||||
magic number and unique for each category. */
|
||||
#define CATEGORY_MAGIC(x) (LIMAGIC ^ (x))
|
||||
|
||||
extern CONST char *__lidir, *__lidefault;
|
||||
|
||||
extern locale *EXFUN(__find_locale, (int categories, CONST char *name));
|
||||
extern locale *EXFUN(__new_locale, (locale *));
|
||||
extern locale *EXFUN(__localefile, (CONST char *file));
|
||||
extern void EXFUN(__free_locale, (locale *));
|
||||
|
||||
|
||||
#endif /* localeinfo.h */
|
||||
@ -0,0 +1,31 @@
|
||||
/* The <math.h> header contains prototypes for mathematical functions. */
|
||||
|
||||
#ifndef _MATH_H
|
||||
#define _MATH_H
|
||||
|
||||
#define HUGE_VAL 9.9e+307
|
||||
|
||||
double acos(double x);
|
||||
double asin(double x);
|
||||
double atan(double x);
|
||||
double atan2(double y, double x);
|
||||
double ceil(double x);
|
||||
double cos(double x);
|
||||
double cosh(double x);
|
||||
double exp(double x);
|
||||
double fabs(double x);
|
||||
double floor(double x);
|
||||
double fmod(double x, double y);
|
||||
double frexp(double x, int *exp);
|
||||
double ldexp(double x, int exp);
|
||||
double log(double x);
|
||||
double log10(double x);
|
||||
double modf(double x, double *iptr);
|
||||
double pow(double x, double y);
|
||||
double sin(double x);
|
||||
double sinh(double x);
|
||||
double sqrt(double x);
|
||||
double tan(double x);
|
||||
double tanh(double x);
|
||||
|
||||
#endif /* _MATH_H */
|
||||
@ -0,0 +1,89 @@
|
||||
/* Copyright (C) 1991 Free Software Foundation, Inc.
|
||||
This file is part of the GNU C Library.
|
||||
|
||||
The GNU C 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.
|
||||
|
||||
The GNU C 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 the GNU C Library; see the file COPYING.LIB. If
|
||||
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
|
||||
Cambridge, MA 02139, USA. */
|
||||
|
||||
/*
|
||||
* POSIX Standard: 9.2.2 User Database Access <pwd.h>
|
||||
*/
|
||||
|
||||
#ifndef _PWD_H
|
||||
#define _PWD_H 1
|
||||
|
||||
#include <ansidecl.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define __USE_SVID
|
||||
#define __USE_GNU
|
||||
|
||||
/* The passwd structure. */
|
||||
struct passwd
|
||||
{
|
||||
char *pw_name; /* Username. */
|
||||
char *pw_passwd; /* Password. */
|
||||
uid_t pw_uid; /* User ID. */
|
||||
gid_t pw_gid; /* Group ID. */
|
||||
char *pw_gecos; /* Real name. */
|
||||
char *pw_dir; /* Home directory. */
|
||||
char *pw_shell; /* Shell program. */
|
||||
};
|
||||
|
||||
|
||||
#if defined(__USE_SVID) || defined(__USE_GNU)
|
||||
#define __need_FILE
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
#ifdef __USE_GNU
|
||||
/* Return a new stream open on the password file. */
|
||||
extern FILE *EXFUN(__pwdopen, (NOARGS));
|
||||
|
||||
/* Read a password entry from STREAM, filling in P.
|
||||
Return the `struct passwd' of P if successful, NULL on failure. */
|
||||
extern struct passwd *EXFUN(__pwdread, (FILE *__stream, PTR __p));
|
||||
|
||||
/* Return a chunk of memory containing pre-initialized data for __pwdread. */
|
||||
extern PTR EXFUN(__pwdalloc, (NOARGS));
|
||||
#endif
|
||||
|
||||
|
||||
#if defined(__USE_SVID) || defined(__USE_MISC)
|
||||
/* Rewind the password-file stream. */
|
||||
extern void EXFUN(setpwent, (NOARGS));
|
||||
|
||||
/* Close the password-file stream. */
|
||||
extern void EXFUN(endpwent, (NOARGS));
|
||||
|
||||
/* Read an entry from the password-file stream, opening it if necessary. */
|
||||
extern struct passwd *EXFUN(getpwent, (NOARGS));
|
||||
#endif
|
||||
|
||||
#ifdef __USE_SVID
|
||||
/* Read an entry from STREAM. */
|
||||
extern struct passwd *EXFUN(fgetpwent, (FILE *__stream));
|
||||
|
||||
/* Write the given entry onto the given stream. */
|
||||
extern int EXFUN(putpwent, (CONST struct passwd *__p, FILE *__f));
|
||||
#endif
|
||||
|
||||
/* Search for an entry with a matching user ID. */
|
||||
extern struct passwd *EXFUN(getpwuid, (uid_t __uid));
|
||||
|
||||
/* Search for an entry with a matching username. */
|
||||
extern struct passwd *EXFUN(getpwnam, (CONST char *__name));
|
||||
|
||||
|
||||
#endif /* pwd.h */
|
||||
@ -0,0 +1,16 @@
|
||||
#ifndef _SETJMP_H
|
||||
#define _SETJMP_H
|
||||
|
||||
/* longjump wants %ebp, %esp, %eip, %ebx, %esi, %edi */
|
||||
#define _JBLEN 32
|
||||
#define _SJBLEN (_JBLEN+4)
|
||||
|
||||
typedef char * jmp_buf[_JBLEN];
|
||||
typedef char * sigjmp_buf[_SJBLEN];
|
||||
|
||||
int setjmp(jmp_buf env);
|
||||
void longjmp(jmp_buf env, int val);
|
||||
int sigsetjmp(sigjmp_buf env, int savemask);
|
||||
int siglongjmp(sigjmp_buf env, int val);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,69 @@
|
||||
#ifndef _SIGNAL_H
|
||||
#define _SIGNAL_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
typedef int sig_atomic_t;
|
||||
typedef unsigned int sigset_t; /* 32 bits */
|
||||
|
||||
#define _NSIG 32
|
||||
#define NSIG _NSIG
|
||||
|
||||
#define SIGHUP 1
|
||||
#define SIGINT 2
|
||||
#define SIGQUIT 3
|
||||
#define SIGILL 4
|
||||
#define SIGTRAP 5
|
||||
#define SIGABRT 6
|
||||
#define SIGIOT 6
|
||||
#define SIGUNUSED 7
|
||||
#define SIGFPE 8
|
||||
#define SIGKILL 9
|
||||
#define SIGUSR1 10
|
||||
#define SIGSEGV 11
|
||||
#define SIGUSR2 12
|
||||
#define SIGPIPE 13
|
||||
#define SIGALRM 14
|
||||
#define SIGTERM 15
|
||||
#define SIGSTKFLT 16
|
||||
#define SIGCHLD 17
|
||||
#define SIGCONT 18
|
||||
#define SIGSTOP 19
|
||||
#define SIGTSTP 20
|
||||
#define SIGTTIN 21
|
||||
#define SIGTTOU 22
|
||||
|
||||
/* Ok, I haven't implemented sigactions, but trying to keep headers POSIX */
|
||||
#define SA_NOCLDSTOP 1
|
||||
#define SA_NOMASK 0x40000000
|
||||
#define SA_ONESHOT 0x80000000
|
||||
|
||||
#define SIG_BLOCK 0 /* for blocking signals */
|
||||
#define SIG_UNBLOCK 1 /* for unblocking signals */
|
||||
#define SIG_SETMASK 2 /* for setting the signal mask */
|
||||
|
||||
#define SIG_DFL ((void (*)(int))0) /* default signal handling */
|
||||
#define SIG_IGN ((void (*)(int))1) /* ignore signal */
|
||||
#define SIG_ERR ((void (*)(int))-1) /* error return from signal */
|
||||
|
||||
struct sigaction {
|
||||
void (*sa_handler)(int);
|
||||
sigset_t sa_mask;
|
||||
int sa_flags;
|
||||
void (*sa_restorer)(void);
|
||||
};
|
||||
|
||||
void (*signal(int _sig, void (*_func)(int)))(int);
|
||||
int raise(int sig);
|
||||
int kill(pid_t pid, int sig);
|
||||
int sigaddset(sigset_t *mask, int signo);
|
||||
int sigdelset(sigset_t *mask, int signo);
|
||||
int sigemptyset(sigset_t *mask);
|
||||
int sigfillset(sigset_t *mask);
|
||||
int sigismember(sigset_t *mask, int signo); /* 1 - is, 0 - not, -1 error */
|
||||
int sigpending(sigset_t *set);
|
||||
int sigprocmask(int how, sigset_t *set, sigset_t *oldset);
|
||||
int sigsuspend(sigset_t *sigmask);
|
||||
int sigaction(int sig, struct sigaction *act, struct sigaction *oldact);
|
||||
|
||||
#endif /* _SIGNAL_H */
|
||||
@ -0,0 +1,28 @@
|
||||
#ifndef _STDARG_H
|
||||
#define _STDARG_H
|
||||
|
||||
typedef char *va_list;
|
||||
|
||||
/* Amount of space required in an argument list for an arg of type TYPE.
|
||||
TYPE may alternatively be an expression whose type is used. */
|
||||
|
||||
#define __va_rounded_size(TYPE) \
|
||||
(((sizeof (TYPE) + sizeof (int) - 1) / sizeof (int)) * sizeof (int))
|
||||
|
||||
#ifndef __sparc__
|
||||
#define va_start(AP, LASTARG) \
|
||||
(AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
|
||||
#else
|
||||
#define va_start(AP, LASTARG) \
|
||||
(__builtin_saveregs (), \
|
||||
AP = ((char *) &(LASTARG) + __va_rounded_size (LASTARG)))
|
||||
#endif
|
||||
|
||||
void va_end (va_list); /* Defined in gnulib */
|
||||
#define va_end(AP)
|
||||
|
||||
#define va_arg(AP, TYPE) \
|
||||
(AP += __va_rounded_size (TYPE), \
|
||||
*((TYPE *) (AP - __va_rounded_size (TYPE))))
|
||||
|
||||
#endif /* _STDARG_H */
|
||||
@ -0,0 +1,19 @@
|
||||
#ifndef _STDDEF_H
|
||||
#define _STDDEF_H
|
||||
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
typedef long ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned long size_t;
|
||||
#endif
|
||||
|
||||
#undef NULL
|
||||
#define NULL ((void *)0)
|
||||
|
||||
#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,256 @@
|
||||
#ifndef _STDIO_H
|
||||
#define _STDIO_H
|
||||
|
||||
/* s t d i o
|
||||
*
|
||||
* Author: C. E. Chew
|
||||
* Date: August 1989
|
||||
*
|
||||
* (C) Copyright C E Chew
|
||||
*
|
||||
* Feel free to copy, use and distribute this software provided:
|
||||
*
|
||||
* 1. you do not pretend that you wrote it
|
||||
* 2. you leave this copyright notice intact.
|
||||
*
|
||||
* Definitions and user interface for the stream io package.
|
||||
*
|
||||
* Patchlevel 2.0
|
||||
*
|
||||
* Edit History:
|
||||
*/
|
||||
|
||||
/* Site specific definitions */
|
||||
/*@*/
|
||||
#ifndef NULL
|
||||
# define NULL ((void *)0)
|
||||
#endif
|
||||
#define _STDIO_UCHAR_ 0
|
||||
#define _STDIO_VA_LIST_ char *
|
||||
#define _STDIO_SIZE_T_ unsigned int /* type returned by sizeof */
|
||||
#define _STDIO_USIZE_T_ unsigned int
|
||||
/*=*/
|
||||
|
||||
/* Definitions based on ANSI compiler */
|
||||
#ifdef __STDC__
|
||||
# ifndef _STDIO_P_
|
||||
# define _STDIO_P_(x) x
|
||||
# endif
|
||||
# ifndef _STDIO_VA_
|
||||
# define _STDIO_VA_ , ...
|
||||
# endif
|
||||
# ifndef _STDIO_UCHAR_
|
||||
# define _STDIO_UCHAR_ 0
|
||||
# endif
|
||||
#else
|
||||
# ifndef _STDIO_P_
|
||||
# define _STDIO_P_(x) ()
|
||||
# endif
|
||||
# ifndef _STDIO_VA_
|
||||
# define _STDIO_VA_
|
||||
# endif
|
||||
# ifndef _STDIO_UCHAR_
|
||||
# define _STDIO_UCHAR_ (0xff)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifndef _STDIO_VA_LIST_
|
||||
# define _STDIO_VA_LIST_ void *
|
||||
#endif
|
||||
|
||||
#ifndef _STDIO_SIZE_T_
|
||||
# define _STDIO_SIZE_T_ unsigned int
|
||||
#endif
|
||||
|
||||
#ifndef _STDIO_USIZE_T_
|
||||
# define _STDIO_USIZE_T_ unsigned int
|
||||
#endif
|
||||
|
||||
/* ANSI Definitions */
|
||||
#define BUFSIZ 1024 /* default buffer size */
|
||||
|
||||
#ifndef NULL
|
||||
# define NULL ((void *) 0) /* null pointer */
|
||||
#endif
|
||||
|
||||
#define EOF (-1) /* eof flag */
|
||||
#define FOPEN_MAX 16 /* minimum guarantee */
|
||||
#define FILENAME_MAX 127 /* maximum length of file name */
|
||||
|
||||
#define SEEK_SET 0 /* seek from beginning */
|
||||
#define SEEK_CUR 1 /* seek from here */
|
||||
#define SEEK_END 2 /* seek from end */
|
||||
|
||||
#define TMP_MAX (0xffff) /* maximum number of temporaries */
|
||||
|
||||
#define L_tmpnam (5 + 8 + 4 + 1 + 1) /* length of temporary file name */
|
||||
|
||||
#ifndef _FPOS_T
|
||||
# define _FPOS_T
|
||||
typedef long fpos_t; /* stream positioning */
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T
|
||||
# define _SIZE_T
|
||||
typedef _STDIO_SIZE_T_ size_t; /* sizeof type */
|
||||
#endif
|
||||
|
||||
#define _IOFBF 000000 /* fully buffered io */
|
||||
#define _IOREAD 000001 /* opened for reading */
|
||||
#define _IOWRITE 000002 /* opened for writing */
|
||||
#define _IONBF 000004 /* unbuffered */
|
||||
#define _IOMYBUF 000010 /* allocated buffer */
|
||||
#define _IOPOOLBUF 000020 /* buffer belongs to pool */
|
||||
#define _IOEOF 000040 /* eof encountered */
|
||||
#define _IOERR 000100 /* error encountered */
|
||||
#define _IOSTRING 000200 /* strings */
|
||||
#define _IOLBF 000400 /* line buffered */
|
||||
#define _IORW 001000 /* opened for reading and writing */
|
||||
#define _IOAPPEND 002000 /* append mode */
|
||||
#define _IOINSERT 004000 /* insert into __iop chain */
|
||||
#define _IOSTDX 030000 /* standard stream */
|
||||
|
||||
#define _IOSTDIN 010000 /* stdin indication */
|
||||
#define _IOSTDOUT 020000 /* stdout indication */
|
||||
#define _IOSTDERR 030000 /* stderr indication */
|
||||
|
||||
#define _IORETAIN (_IOSTDX | _IOINSERT) /* flags to be retained */
|
||||
|
||||
/* Implementation Definitions */
|
||||
|
||||
typedef char __stdiobuf_t; /* stdio buffer type */
|
||||
typedef _STDIO_USIZE_T_ __stdiosize_t; /* unsigned size_t */
|
||||
|
||||
typedef struct __iobuf {
|
||||
__stdiobuf_t *__rptr; /* pointer into read buffer */
|
||||
__stdiobuf_t *__rend; /* point at end of read buffer */
|
||||
__stdiobuf_t *__wptr; /* pointer into write buffer */
|
||||
__stdiobuf_t *__wend; /* point at end of write buffer */
|
||||
__stdiobuf_t *__base; /* base of buffer */
|
||||
__stdiosize_t __bufsiz; /* size of buffer */
|
||||
short __flag; /* flags */
|
||||
char __file; /* channel number */
|
||||
__stdiobuf_t __buf; /* small buffer */
|
||||
int (*__filbuf) _STDIO_P_((struct __iobuf *)); /* fill input buffer */
|
||||
int (*__flsbuf) _STDIO_P_((int, struct __iobuf *)); /* flush output buffer */
|
||||
int (*__flush) _STDIO_P_((struct __iobuf *)); /* flush buffer */
|
||||
struct __iobuf *__next; /* next in chain */
|
||||
} FILE;
|
||||
|
||||
extern FILE __stdin; /* stdin */
|
||||
extern FILE __stdout; /* stdout */
|
||||
extern FILE __stderr; /* stderr */
|
||||
|
||||
#define stdin (&__stdin)
|
||||
#define stdout (&__stdout)
|
||||
#define stderr (&__stderr)
|
||||
|
||||
/* ANSI Stdio Requirements */
|
||||
|
||||
int getc _STDIO_P_((FILE *));
|
||||
#if _STDIO_UCHAR_
|
||||
# define getc(p) ((p)->__rptr>=(p)->__rend\
|
||||
?(*(p)->__filbuf)(p)\
|
||||
:(int)(*(p)->__rptr++&_STDIO_UCHAR_))
|
||||
#else
|
||||
# define getc(p) ((p)->__rptr>=(p)->__rend\
|
||||
?(*(p)->__filbuf)(p)\
|
||||
:(int)((unsigned char)(*(p)->__rptr++)))
|
||||
#endif
|
||||
|
||||
int getchar _STDIO_P_((void));
|
||||
#define getchar() getc(stdin)
|
||||
|
||||
int putc _STDIO_P_((int, FILE *));
|
||||
#if _STDIO_UCHAR_
|
||||
# define putc(x,p) ((p)->__wptr>=(p)->__wend\
|
||||
?(*(p)->__flsbuf)((x),(p))\
|
||||
:(int)(*(p)->__wptr++=(x)&_STDIO_UCHAR_))
|
||||
#else
|
||||
# define putc(x,p) ((p)->__wptr>=(p)->__wend\
|
||||
?(*(p)->__flsbuf)((x),(p))\
|
||||
:(int)((unsigned char)(*(p)->__wptr++=(x))))
|
||||
#endif
|
||||
|
||||
int putchar _STDIO_P_((int));
|
||||
#define putchar(x) putc(x,stdout)
|
||||
|
||||
int feof _STDIO_P_((FILE *));
|
||||
#define feof(p) (((p)->__flag&_IOEOF)!=0)
|
||||
|
||||
int ferror _STDIO_P_((FILE *));
|
||||
#define ferror(p) (((p)->__flag&_IOERR)!=0)
|
||||
|
||||
void clearerr _STDIO_P_((FILE *));
|
||||
#define clearerr(p) ((p)->__flag&=~(_IOEOF|_IOERR))
|
||||
|
||||
FILE *fopen _STDIO_P_((const char *, const char *));
|
||||
FILE *freopen _STDIO_P_((const char *, const char *, FILE *));
|
||||
int fflush _STDIO_P_((FILE *));
|
||||
int fclose _STDIO_P_((FILE *));
|
||||
|
||||
int fgetpos _STDIO_P_((FILE *, fpos_t *));
|
||||
int fsetpos _STDIO_P_((FILE *, fpos_t *));
|
||||
long ftell _STDIO_P_((FILE *));
|
||||
int fseek _STDIO_P_((FILE *, long, int));
|
||||
void rewind _STDIO_P_((FILE *));
|
||||
|
||||
int fgetc _STDIO_P_((FILE *));
|
||||
int fputc _STDIO_P_((int, FILE *));
|
||||
__stdiosize_t fread _STDIO_P_((void *, __stdiosize_t,
|
||||
__stdiosize_t, FILE *));
|
||||
__stdiosize_t fwrite _STDIO_P_((void *, __stdiosize_t,
|
||||
__stdiosize_t, FILE *));
|
||||
|
||||
int getw _STDIO_P_((FILE *));
|
||||
int putw _STDIO_P_((int, FILE *));
|
||||
char *gets _STDIO_P_((char *));
|
||||
char *fgets _STDIO_P_((char *, int, FILE *));
|
||||
int puts _STDIO_P_((const char *));
|
||||
int fputs _STDIO_P_((const char *, FILE *));
|
||||
|
||||
int ungetc _STDIO_P_((int, FILE *));
|
||||
|
||||
int printf _STDIO_P_((const char * _STDIO_VA_));
|
||||
int fprintf _STDIO_P_((FILE *, const char * _STDIO_VA_));
|
||||
int sprintf _STDIO_P_((char *, const char * _STDIO_VA_));
|
||||
int vprintf _STDIO_P_((const char *, _STDIO_VA_LIST_));
|
||||
int vfprintf _STDIO_P_((FILE *, const char *, _STDIO_VA_LIST_));
|
||||
int vsprintf _STDIO_P_((char *, const char *, _STDIO_VA_LIST_));
|
||||
int scanf _STDIO_P_((const char * _STDIO_VA_));
|
||||
int fscanf _STDIO_P_((FILE *, const char * _STDIO_VA_));
|
||||
int sscanf _STDIO_P_((const char *, const char * _STDIO_VA_));
|
||||
|
||||
void setbuf _STDIO_P_((FILE *, char *));
|
||||
int setvbuf _STDIO_P_((FILE *, char *, int, __stdiosize_t));
|
||||
|
||||
int rename _STDIO_P_((const char *, const char *));
|
||||
int remove _STDIO_P_((const char *));
|
||||
|
||||
void perror _STDIO_P_((const char *));
|
||||
|
||||
char * tmpnam _STDIO_P_((char *));
|
||||
FILE * tmpfile _STDIO_P_((void));
|
||||
|
||||
/* Posix Definitions */
|
||||
int unlink _STDIO_P_((const char *));
|
||||
#define remove(x) unlink((x))
|
||||
|
||||
#define L_ctermid 9
|
||||
char * ctermid _STDIO_P_((char *s));
|
||||
|
||||
#define L_cuserid 9
|
||||
char * cuserid _STDIO_P_((char *s));
|
||||
|
||||
FILE *fdopen _STDIO_P_((int, const char *));
|
||||
|
||||
int fileno _STDIO_P_((FILE *));
|
||||
#define fileno(p) ((p)->__file)
|
||||
|
||||
#undef _STDIO_P_
|
||||
#undef _STDIO_VA_
|
||||
#undef _STDIO_VA_LIST_
|
||||
/*ndef _STDIO_UCHAR_*/
|
||||
#undef _STDIO_SIZE_T_
|
||||
#undef _STDIO_USIZE_T_
|
||||
#endif
|
||||
@ -0,0 +1,43 @@
|
||||
#ifndef _STDLIB_H
|
||||
#define _STDLIB_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
#define EXIT_SUCCESS 0
|
||||
#define EXIT_FAILURE 1
|
||||
|
||||
extern double atof(const char * s);
|
||||
extern int atoi(const char *s);
|
||||
extern long atol(const char *s);
|
||||
extern double strtod(const char *s, char **endp);
|
||||
extern long strtol(const char *s, char **endp, int base);
|
||||
extern unsigned long strtoul(const char *s, char **endp, int base);
|
||||
extern int rand(void);
|
||||
extern void srand(unsigned int seed);
|
||||
extern void * calloc(size_t nobj, size_t size);
|
||||
extern void * malloc(size_t size);
|
||||
extern void * realloc(void * p, size_t size);
|
||||
extern void free(void * p);
|
||||
extern void abort(void);
|
||||
extern volatile void exit(int status);
|
||||
extern int atexit(void (*fcn)(void));
|
||||
extern int system(const char *s);
|
||||
extern char * getenv(const char *name);
|
||||
extern void * bsearch(const void *key, const void *base,
|
||||
size_t n, size_t size,
|
||||
int (*cmp)(const void *keyval, const void *datum));
|
||||
extern void qsort(void *base, size_t n, size_t size,
|
||||
int (*cmp)(const void *,const void *));
|
||||
extern int abs(int n);
|
||||
extern long labs(long n);
|
||||
extern div_t div(int num, int denom);
|
||||
extern ldiv_t ldiv(long num, long denom);
|
||||
extern char * getcwd(char * buf, size_t size);
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define __alloca(n) __builtin_alloca(n)
|
||||
#else
|
||||
#define __alloca(n) alloca(n)
|
||||
#endif
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,405 @@
|
||||
#ifndef _STRING_H_
|
||||
#define _STRING_H_
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
|
||||
extern char * strerror(int errno);
|
||||
|
||||
/*
|
||||
* This string-include defines all string functions as inline
|
||||
* functions. Use gcc. It also assumes ds=es=data space, this should be
|
||||
* normal. Most of the string-functions are rather heavily hand-optimized,
|
||||
* see especially strtok,strstr,str[c]spn. They should work, but are not
|
||||
* very easy to understand. Everything is done entirely within the register
|
||||
* set, making the functions fast and clean. String instructions have been
|
||||
* used through-out, making for "slightly" unclear code :-)
|
||||
*
|
||||
* (C) 1991 Linus Torvalds
|
||||
*/
|
||||
|
||||
extern inline char * strcpy(char * dest,const char *src)
|
||||
{
|
||||
__asm__("cld\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b"
|
||||
::"S" (src),"D" (dest):"si","di","ax");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline char * strncpy(char * dest,const char *src,int count)
|
||||
{
|
||||
__asm__("cld\n"
|
||||
"1:\tdecl %2\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"rep\n\t"
|
||||
"stosb\n"
|
||||
"2:"
|
||||
::"S" (src),"D" (dest),"c" (count):"si","di","ax","cx");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline char * strcat(char * dest,const char * src)
|
||||
{
|
||||
__asm__("cld\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"decl %1\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b"
|
||||
::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff):"si","di","ax","cx");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline char * strncat(char * dest,const char * src,int count)
|
||||
{
|
||||
__asm__("cld\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"decl %1\n\t"
|
||||
"movl %4,%3\n"
|
||||
"1:\tdecl %3\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"stosb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n"
|
||||
"2:\txorl %2,%2\n\t"
|
||||
"stosb"
|
||||
::"S" (src),"D" (dest),"a" (0),"c" (0xffffffff),"g" (count)
|
||||
:"si","di","ax","cx");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline int strcmp(const char * cs,const char * ct)
|
||||
{
|
||||
register int __res __asm__("ax");
|
||||
__asm__("cld\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 2f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"xorl %%eax,%%eax\n\t"
|
||||
"jmp 3f\n"
|
||||
"2:\tmovl $1,%%eax\n\t"
|
||||
"jl 3f\n\t"
|
||||
"negl %%eax\n"
|
||||
"3:"
|
||||
:"=a" (__res):"D" (cs),"S" (ct):"si","di");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline int strncmp(const char * cs,const char * ct,int count)
|
||||
{
|
||||
register int __res __asm__("ax");
|
||||
__asm__("cld\n"
|
||||
"1:\tdecl %3\n\t"
|
||||
"js 2f\n\t"
|
||||
"lodsb\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 3f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n"
|
||||
"2:\txorl %%eax,%%eax\n\t"
|
||||
"jmp 4f\n"
|
||||
"3:\tmovl $1,%%eax\n\t"
|
||||
"jl 4f\n\t"
|
||||
"negl %%eax\n"
|
||||
"4:"
|
||||
:"=a" (__res):"D" (cs),"S" (ct),"c" (count):"si","di","cx");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline char * strchr(const char * s,char c)
|
||||
{
|
||||
register char * __res __asm__("ax");
|
||||
__asm__("cld\n\t"
|
||||
"movb %%al,%%ah\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"cmpb %%ah,%%al\n\t"
|
||||
"je 2f\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"jne 1b\n\t"
|
||||
"movl $1,%1\n"
|
||||
"2:\tmovl %1,%0\n\t"
|
||||
"decl %0"
|
||||
:"=a" (__res):"S" (s),"0" (c):"si");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline char * strrchr(const char * s,char c)
|
||||
{
|
||||
register char * __res __asm__("dx");
|
||||
__asm__("cld\n\t"
|
||||
"movb %%al,%%ah\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"cmpb %%ah,%%al\n\t"
|
||||
"jne 2f\n\t"
|
||||
"movl %%esi,%0\n\t"
|
||||
"decl %0\n"
|
||||
"2:\ttestb %%al,%%al\n\t"
|
||||
"jne 1b"
|
||||
:"=d" (__res):"0" (0),"S" (s),"a" (c):"ax","si");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline int strspn(const char * cs, const char * ct)
|
||||
{
|
||||
register char * __res __asm__("si");
|
||||
__asm__("cld\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %%ecx\n\t"
|
||||
"decl %%ecx\n\t"
|
||||
"movl %%ecx,%%edx\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"je 2f\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"je 1b\n"
|
||||
"2:\tdecl %0"
|
||||
:"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct)
|
||||
:"ax","cx","dx","di");
|
||||
return __res-cs;
|
||||
}
|
||||
|
||||
extern inline int strcspn(const char * cs, const char * ct)
|
||||
{
|
||||
register char * __res __asm__("si");
|
||||
__asm__("cld\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %%ecx\n\t"
|
||||
"decl %%ecx\n\t"
|
||||
"movl %%ecx,%%edx\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"je 2f\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 1b\n"
|
||||
"2:\tdecl %0"
|
||||
:"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct)
|
||||
:"ax","cx","dx","di");
|
||||
return __res-cs;
|
||||
}
|
||||
|
||||
extern inline char * strpbrk(const char * cs,const char * ct)
|
||||
{
|
||||
register char * __res __asm__("si");
|
||||
__asm__("cld\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %%ecx\n\t"
|
||||
"decl %%ecx\n\t"
|
||||
"movl %%ecx,%%edx\n"
|
||||
"1:\tlodsb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"je 2f\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 1b\n\t"
|
||||
"decl %0\n\t"
|
||||
"jmp 3f\n"
|
||||
"2:\txorl %0,%0\n"
|
||||
"3:"
|
||||
:"=S" (__res):"a" (0),"c" (0xffffffff),"0" (cs),"g" (ct)
|
||||
:"ax","cx","dx","di");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline char * strstr(const char * cs,const char * ct)
|
||||
{
|
||||
register char * __res __asm__("ax");
|
||||
__asm__("cld\n\t" \
|
||||
"movl %4,%%edi\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %%ecx\n\t"
|
||||
"decl %%ecx\n\t" /* NOTE! This also sets Z if searchstring='' */
|
||||
"movl %%ecx,%%edx\n"
|
||||
"1:\tmovl %4,%%edi\n\t"
|
||||
"movl %%esi,%%eax\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repe\n\t"
|
||||
"cmpsb\n\t"
|
||||
"je 2f\n\t" /* also works for empty string, see above */
|
||||
"xchgl %%eax,%%esi\n\t"
|
||||
"incl %%esi\n\t"
|
||||
"cmpb $0,-1(%%eax)\n\t"
|
||||
"jne 1b\n\t"
|
||||
"xorl %%eax,%%eax\n\t"
|
||||
"2:"
|
||||
:"=a" (__res):"0" (0),"c" (0xffffffff),"S" (cs),"g" (ct)
|
||||
:"cx","dx","di","si");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline int strlen(const char * s)
|
||||
{
|
||||
register int __res __asm__("cx");
|
||||
__asm__("cld\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %0\n\t"
|
||||
"decl %0"
|
||||
:"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern char * ___strtok;
|
||||
|
||||
extern inline char * strtok(char * s,const char * ct)
|
||||
{
|
||||
register char * __res __asm__("si");
|
||||
__asm__("testl %1,%1\n\t"
|
||||
"jne 1f\n\t"
|
||||
"testl %0,%0\n\t"
|
||||
"je 8f\n\t"
|
||||
"movl %0,%1\n"
|
||||
"1:\txorl %0,%0\n\t"
|
||||
"movl $-1,%%ecx\n\t"
|
||||
"xorl %%eax,%%eax\n\t"
|
||||
"cld\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"notl %%ecx\n\t"
|
||||
"decl %%ecx\n\t"
|
||||
"je 7f\n\t" /* empty delimeter-string */
|
||||
"movl %%ecx,%%edx\n"
|
||||
"2:\tlodsb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"je 7f\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"je 2b\n\t"
|
||||
"decl %1\n\t"
|
||||
"cmpb $0,(%1)\n\t"
|
||||
"je 7f\n\t"
|
||||
"movl %1,%0\n"
|
||||
"3:\tlodsb\n\t"
|
||||
"testb %%al,%%al\n\t"
|
||||
"je 5f\n\t"
|
||||
"movl %4,%%edi\n\t"
|
||||
"movl %%edx,%%ecx\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"jne 3b\n\t"
|
||||
"decl %1\n\t"
|
||||
"cmpb $0,(%1)\n\t"
|
||||
"je 5f\n\t"
|
||||
"movb $0,(%1)\n\t"
|
||||
"incl %1\n\t"
|
||||
"jmp 6f\n"
|
||||
"5:\txorl %1,%1\n"
|
||||
"6:\tcmpb $0,(%0)\n\t"
|
||||
"jne 7f\n\t"
|
||||
"xorl %0,%0\n"
|
||||
"7:\ttestl %0,%0\n\t"
|
||||
"jne 8f\n\t"
|
||||
"movl %0,%1\n"
|
||||
"8:"
|
||||
:"=b" (__res),"=S" (___strtok)
|
||||
:"0" (___strtok),"1" (s),"g" (ct)
|
||||
:"ax","cx","dx","di");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline void * memcpy(void * dest,const void * src, int n)
|
||||
{
|
||||
__asm__("cld\n\t"
|
||||
"rep\n\t"
|
||||
"movsb"
|
||||
::"c" (n),"S" (src),"D" (dest)
|
||||
:"cx","si","di");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline void * memmove(void * dest,const void * src, int n)
|
||||
{
|
||||
if (dest<src)
|
||||
__asm__("cld\n\t"
|
||||
"rep\n\t"
|
||||
"movsb"
|
||||
::"c" (n),"S" (src),"D" (dest)
|
||||
:"cx","si","di");
|
||||
else
|
||||
__asm__("std\n\t"
|
||||
"rep\n\t"
|
||||
"movsb"
|
||||
::"c" (n),"S" (src+n-1),"D" (dest+n-1)
|
||||
:"cx","si","di");
|
||||
return dest;
|
||||
}
|
||||
|
||||
extern inline int memcmp(const void * cs,const void * ct,int count)
|
||||
{
|
||||
register int __res __asm__("ax");
|
||||
__asm__("cld\n\t"
|
||||
"repe\n\t"
|
||||
"cmpsb\n\t"
|
||||
"je 1f\n\t"
|
||||
"movl $1,%%eax\n\t"
|
||||
"jl 1f\n\t"
|
||||
"negl %%eax\n"
|
||||
"1:"
|
||||
:"=a" (__res):"0" (0),"D" (cs),"S" (ct),"c" (count)
|
||||
:"si","di","cx");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline void * memchr(const void * cs,char c,int count)
|
||||
{
|
||||
register void * __res __asm__("di");
|
||||
if (!count)
|
||||
return NULL;
|
||||
__asm__("cld\n\t"
|
||||
"repne\n\t"
|
||||
"scasb\n\t"
|
||||
"je 1f\n\t"
|
||||
"movl $1,%0\n"
|
||||
"1:\tdecl %0"
|
||||
:"=D" (__res):"a" (c),"D" (cs),"c" (count)
|
||||
:"cx");
|
||||
return __res;
|
||||
}
|
||||
|
||||
extern inline void * memset(void * s,char c,int count)
|
||||
{
|
||||
__asm__("cld\n\t"
|
||||
"rep\n\t"
|
||||
"stosb"
|
||||
::"a" (c),"D" (s),"c" (count)
|
||||
:"cx","di");
|
||||
return s;
|
||||
}
|
||||
|
||||
#endif
|
||||
@ -0,0 +1 @@
|
||||
#include <string.h>
|
||||
@ -0,0 +1,16 @@
|
||||
#ifndef _SYS_DIR_H
|
||||
#define _SYS_DIR_H
|
||||
|
||||
#include <limits.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#ifndef DIRSIZ
|
||||
#define DIRSIZ NAME_MAX
|
||||
#endif
|
||||
|
||||
struct direct {
|
||||
ino_t d_ino;
|
||||
char d_name[NAME_MAX];
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,13 @@
|
||||
#ifndef _SYS_DIRENT_H
|
||||
#define _SYS_DIRENT_H
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
struct dirent {
|
||||
long d_ino;
|
||||
off_t d_off;
|
||||
unsigned short d_reclen;
|
||||
char d_name[NAME_MAX+1];
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,10 @@
|
||||
#ifndef _SYS_FILE_H
|
||||
#define _SYS_FILE_H
|
||||
|
||||
#include <fcntl.h>
|
||||
|
||||
#define L_SET 0 /* absolute offset */
|
||||
#define L_INCR 1 /* relative to current offset */
|
||||
#define L_XTND 2 /* relative to end of file */
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,4 @@
|
||||
#ifndef _SYS_IOCTL_H
|
||||
#define _SYS_IOCTL_H
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,6 @@
|
||||
#ifndef _SYS_PARAM_H
|
||||
#define _SYS_PARAM_H
|
||||
|
||||
#define HZ 100
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,58 @@
|
||||
#ifndef _SYS_STAT_H
|
||||
#define _SYS_STAT_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct stat {
|
||||
dev_t st_dev;
|
||||
ino_t st_ino;
|
||||
umode_t st_mode;
|
||||
nlink_t st_nlink;
|
||||
uid_t st_uid;
|
||||
gid_t st_gid;
|
||||
dev_t st_rdev;
|
||||
off_t st_size;
|
||||
time_t st_atime;
|
||||
time_t st_mtime;
|
||||
time_t st_ctime;
|
||||
};
|
||||
|
||||
#define S_IFMT 00170000
|
||||
#define S_IFREG 0100000
|
||||
#define S_IFBLK 0060000
|
||||
#define S_IFDIR 0040000
|
||||
#define S_IFCHR 0020000
|
||||
#define S_IFIFO 0010000
|
||||
#define S_ISUID 0004000
|
||||
#define S_ISGID 0002000
|
||||
#define S_ISVTX 0001000
|
||||
|
||||
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
|
||||
#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR)
|
||||
#define S_ISCHR(m) (((m) & S_IFMT) == S_IFCHR)
|
||||
#define S_ISBLK(m) (((m) & S_IFMT) == S_IFBLK)
|
||||
#define S_ISFIFO(m) (((m) & S_IFMT) == S_IFIFO)
|
||||
|
||||
#define S_IRWXU 00700
|
||||
#define S_IRUSR 00400
|
||||
#define S_IWUSR 00200
|
||||
#define S_IXUSR 00100
|
||||
|
||||
#define S_IRWXG 00070
|
||||
#define S_IRGRP 00040
|
||||
#define S_IWGRP 00020
|
||||
#define S_IXGRP 00010
|
||||
|
||||
#define S_IRWXO 00007
|
||||
#define S_IROTH 00004
|
||||
#define S_IWOTH 00002
|
||||
#define S_IXOTH 00001
|
||||
|
||||
extern int chmod(const char *_path, mode_t mode);
|
||||
extern int fstat(int fildes, struct stat *stat_buf);
|
||||
extern int mkdir(const char *_path, mode_t mode);
|
||||
extern int mkfifo(const char *_path, mode_t mode);
|
||||
extern int stat(const char *filename, struct stat *stat_buf);
|
||||
extern mode_t umask(mode_t mask);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,8 @@
|
||||
#ifndef _SYS_SYSMACROS_H
|
||||
#define _SYS_SYSMACROS_H
|
||||
|
||||
#define major(dev) (((unsigned) (dev))>>8)
|
||||
#define minor(dev) ((dev)&0xff)
|
||||
#define makedev(major,minor) ((major<<8)|minor)
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,55 @@
|
||||
#ifndef _SYS_TIME_H
|
||||
#define _SYS_TIME_H
|
||||
|
||||
/* gettimofday returns this */
|
||||
struct timeval {
|
||||
long tv_sec; /* seconds */
|
||||
long tv_usec; /* microseconds */
|
||||
};
|
||||
|
||||
struct timezone {
|
||||
int tz_minuteswest; /* minutes west of Greenwich */
|
||||
int tz_dsttime; /* type of dst correction */
|
||||
};
|
||||
|
||||
#define DST_NONE 0 /* not on dst */
|
||||
#define DST_USA 1 /* USA style dst */
|
||||
#define DST_AUST 2 /* Australian style dst */
|
||||
#define DST_WET 3 /* Western European dst */
|
||||
#define DST_MET 4 /* Middle European dst */
|
||||
#define DST_EET 5 /* Eastern European dst */
|
||||
#define DST_CAN 6 /* Canada */
|
||||
#define DST_GB 7 /* Great Britain and Eire */
|
||||
#define DST_RUM 8 /* Rumania */
|
||||
#define DST_TUR 9 /* Turkey */
|
||||
#define DST_AUSTALT 10 /* Australian style with shift in 1986 */
|
||||
|
||||
/*
|
||||
* Operations on timevals.
|
||||
*
|
||||
* NB: timercmp does not work for >= or <=.
|
||||
*/
|
||||
#define timerisset(tvp) ((tvp)->tv_sec || (tvp)->tv_usec)
|
||||
#define timercmp(tvp, uvp, cmp) \
|
||||
((tvp)->tv_sec cmp (uvp)->tv_sec || \
|
||||
(tvp)->tv_sec == (uvp)->tv_sec && (tvp)->tv_usec cmp (uvp)->tv_usec)
|
||||
#define timerclear(tvp) ((tvp)->tv_sec = (tvp)->tv_usec = 0)
|
||||
|
||||
/*
|
||||
* Names of the interval timers, and structure
|
||||
* defining a timer setting.
|
||||
*/
|
||||
#define ITIMER_REAL 0
|
||||
#define ITIMER_VIRTUAL 1
|
||||
#define ITIMER_PROF 2
|
||||
|
||||
struct itimerval {
|
||||
struct timeval it_interval; /* timer interval */
|
||||
struct timeval it_value; /* current value */
|
||||
};
|
||||
|
||||
#include <time.h>
|
||||
|
||||
int gettimeofday(struct timeval * tp, struct timezone * tz);
|
||||
|
||||
#endif /*_SYS_TIME_H*/
|
||||
@ -0,0 +1,13 @@
|
||||
#ifndef _SYS_TIMEB_H
|
||||
#define _SYS_TIMEB_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct timeb {
|
||||
time_t time;
|
||||
unsigned short millitm;
|
||||
short timezone;
|
||||
short dstflag;
|
||||
};
|
||||
|
||||
#endif /* _SYS_TIMEB_H */
|
||||
@ -0,0 +1,15 @@
|
||||
#ifndef _TIMES_H
|
||||
#define _TIMES_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct tms {
|
||||
time_t tms_utime;
|
||||
time_t tms_stime;
|
||||
time_t tms_cutime;
|
||||
time_t tms_cstime;
|
||||
};
|
||||
|
||||
extern time_t times(struct tms * tp);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,46 @@
|
||||
#ifndef _SYS_TYPES_H
|
||||
#define _SYS_TYPES_H
|
||||
|
||||
#ifndef _SIZE_T
|
||||
#define _SIZE_T
|
||||
typedef unsigned int size_t;
|
||||
#endif
|
||||
|
||||
#ifndef _TIME_T
|
||||
#define _TIME_T
|
||||
typedef long time_t;
|
||||
#endif
|
||||
|
||||
#ifndef _PTRDIFF_T
|
||||
#define _PTRDIFF_T
|
||||
typedef long ptrdiff_t;
|
||||
#endif
|
||||
|
||||
#ifndef NULL
|
||||
#define NULL ((void *) 0)
|
||||
#endif
|
||||
|
||||
typedef int pid_t;
|
||||
typedef unsigned short uid_t;
|
||||
typedef unsigned char gid_t;
|
||||
typedef unsigned short dev_t;
|
||||
typedef unsigned short ino_t;
|
||||
typedef unsigned short mode_t;
|
||||
typedef unsigned short umode_t;
|
||||
typedef unsigned char nlink_t;
|
||||
typedef int daddr_t;
|
||||
typedef long off_t;
|
||||
typedef unsigned char u_char;
|
||||
typedef unsigned short ushort;
|
||||
|
||||
typedef struct { int quot,rem; } div_t;
|
||||
typedef struct { long quot,rem; } ldiv_t;
|
||||
|
||||
struct ustat {
|
||||
daddr_t f_tfree;
|
||||
ino_t f_tinode;
|
||||
char f_fname[6];
|
||||
char f_fpack[6];
|
||||
};
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,16 @@
|
||||
#ifndef _SYS_UTSNAME_H
|
||||
#define _SYS_UTSNAME_H
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
struct utsname {
|
||||
char sysname[9];
|
||||
char nodename[9];
|
||||
char release[9];
|
||||
char version[9];
|
||||
char machine[9];
|
||||
};
|
||||
|
||||
extern int uname(struct utsname * utsbuf);
|
||||
|
||||
#endif
|
||||
@ -0,0 +1,19 @@
|
||||
/* @(#)varargs.h 1.11 89/06/14 SMI; from UCB 4.1 83/05/03 */
|
||||
|
||||
#ifndef _sys_varargs_h
|
||||
#define _sys_varargs_h
|
||||
|
||||
typedef char *va_list;
|
||||
#if defined(sparc)
|
||||
# define va_alist __builtin_va_alist
|
||||
#endif
|
||||
# define va_dcl int va_alist;
|
||||
# define va_start(list) list = (char *) &va_alist
|
||||
# define va_end(list)
|
||||
# if defined(__BUILTIN_VA_ARG_INCR) && !defined(lint)
|
||||
# define va_arg(list,mode) ((mode*)__builtin_va_arg_incr((mode *)list))[0]
|
||||
# else
|
||||
# define va_arg(list,mode) ((mode *)(list += sizeof(mode)))[-1]
|
||||
# endif
|
||||
|
||||
#endif /*!_sys_varargs_h*/
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue