Merge branch 'master' of https://bdgit.educoder.net/p9e3htngw/SystemCall
commit
f02f42a140
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -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
|
||||
@ -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);
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue