Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4972 → Rev 4973

/programs/develop/libraries/menuetlibc/src/libc/compat/Makefile
0,0 → 1,50
all:
make -C bsd
make -C io
make -C math
make -C mman
make -C mntent
make -C search
make -C stdio
make -C stdlib
make -C string
make -C sys
make -C time
make -C unistd
make -C v1
make -C signal
make -C termios
 
clean:
make -C bsd clean
make -C io clean
make -C math clean
make -C mman clean
make -C mntent clean
make -C search clean
make -C stdio clean
make -C stdlib clean
make -C string clean
make -C sys clean
make -C time clean
make -C unistd clean
make -C v1 clean
make -C signal clean
make -C termios clean
 
depend:
make -C bsd depend
make -C io depend
make -C math depend
make -C mman depend
make -C mntent depend
make -C search depend
make -C stdio depend
make -C stdlib depend
make -C string depend
make -C sys depend
make -C time depend
make -C unistd depend
make -C v1 depend
make -C signal depend
make -C termios depend
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/Makefile
0,0 → 1,3
THIS_SRCS = bcmp.c bcopy.c bzero.c index.s rindex.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bcmp.c
0,0 → 1,26
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bcmp
 
int
bcmp(const void *ptr1, const void *ptr2, int length)
{
if (ptr1 == ptr2)
return 0;
 
if (ptr1 == 0 || ptr2 == 0)
return -1;
 
const char* arg1 = ptr1;
const char* arg2 = ptr2;
 
while (length)
{
if (*arg1++ != *arg2++)
return length;
length--;
}
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bcopy.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bcopy
 
void *
bcopy(const void *a, void *b, size_t len)
{
return memmove(b, a, len);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/bzero.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
#undef bzero
 
void *
bzero(void *a, size_t b)
{
return memset(a,0,b);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/index.s
0,0 → 1,6
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
MK_C_SYM(index)
jmp C_SYM(strchr)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/bsd/rindex.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/asmdefs.h>
#include<libc/asm.h>
MK_C_SYM(rindex)
jmp C_SYM(strrchr)
/programs/develop/libraries/menuetlibc/src/libc/compat/io/Makefile
0,0 → 1,3
THIS_SRCS = chsize.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/io/chsize.c
0,0 → 1,9
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <io.h>
#include <unistd.h>
 
int
chsize(int handle, long size)
{
return ftruncate(handle, size);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/math/Makefile
0,0 → 1,3
THIS_SRCS= cbrt.s exmp1.s exp2.s log10.s log2.s sincos.s log1p.s powi.s
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/math/cbrt.s
0,0 → 1,145
#include<libc/asm.h>
 
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
.data
pinf:
.long 0xFF800000
 
NaN:
.long 0xFFC00000
 
temp:
.long 0, 0
 
onethird:
.long 1431655765
 
two54:
.long 0x5A800000
 
a0:
.float +1.87277957900533E+00
 
a1:
.float -1.87243905326548E+00
 
a2:
.float +1.60286399719912E+00
 
a3:
.float -7.46198924594210E-01
 
a4:
.float +1.42994392730009E-01
 
b0:
.float 14.
 
b1:
.float -7.
 
b2:
.float +2.
 
one9th:
.tfloat +0.11111111111111111111
 
.text
MK_C_SYM(cbrt)
 
movl 8(%esp), %eax
movl %eax, %ecx /* Save sign */
 
andl $0x7FFFFFFF, %eax /* fabs */
movl %eax, 8(%esp)
 
cmpl $0x7FF00000, %eax /* Control flows straight through for */
jae abarg /* normal args: 0 < fabs(x) < +inf */
testl $0x7FF00000, %eax
jz verysmall
 
mull onethird
addl $0x2A9F7893, %edx
movl %edx, temp+4 /* First approximation good */
/* to 5.5 bits */
 
have55:
fldl 4(%esp)
fld1
fdivp /* recip */
 
fldl temp /* Load approximation */
/* 4rd-order minimax to 24 bits */
fld %st(0) /* x x recip */
fmul %st(1) /* x^2 x recip */
fmul %st(1) /* x^3 x recip */
fmul %st(2) /* y x recip */
fld %st(0) /* y y x recip */
fmuls a4 /* P1' y x recip */
fadds a3 /* P1 y x recip */
fmul %st(1) /* P2' y x recip */
fadds a2 /* P2 y x recip */
fmul %st(1) /* P3' y x recip */
fadds a1 /* P3 y x recip */
fmulp /* P4' x recip */
fadds a0 /* P4 x recip */
fmulp /* x' recip */
/* 2nd-order Taylor to 64 bits */
fld %st(0) /* x x recip */
fmul %st(1) /* x^2 x recip */
fmul %st(1) /* x^3 x recip */
fmul %st(2) /* y x recip */
ffree %st(2) /* y x */
fld %st(0) /* y y x */
fmuls b2
fadds b1
fmulp /* ccc x */
fadds b0 /* P(y) x */
fmulp /* x'' */
fldt one9th
fmulp
 
cleanup: /* Restore sign */
testl %ecx, %ecx
jns end
fchs
 
end:
ret
 
verysmall: /* Exponent is 0 */
movl 8(%esp), %eax
testl %eax, %eax
jnz denormal
movl 4(%esp), %eax
testl %eax, %eax
jz special /* x = 0 */
denormal:
fldl 4(%esp)
fmuls two54 /* Multiply by 2^54 to normalize */
fstpl temp
 
movl temp+4, %eax
mull onethird
addl $0x297F7893, %edx /* Undo 2^54 multiplier */
movl %edx, temp+4 /* First approximation to 5.5 bits */
movl $0, temp
 
jmp have55
 
abarg: /* x = inf, or NaN */
testl $0x000FFFFF, %eax
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jz special
 
badarg: /* arg is negative or NaN */
movl $1, C_SYM(errno)
flds NaN
ret
 
special:
fldl 4(%esp) /* x = 0 or inf: just load x */
jmp cleanup
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exmp1.s
0,0 → 1,79
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
pinf:
.long 0x7F800000
 
NaN:
.long 0xFFC00000
 
 
MK_C_SYM(expm1)
movl 8(%esp), %eax /* Test for special cases. */
andl $0x7FFFFFFF, %eax
cmpl $0x40862E42, %eax
jge bigarg /* normal args: */
/* 0 < |x| <= log(DBL_MAX) */
argok: /* N.B. */
/* log(DBL_MAX) = 0x40862E42FEFA39EF */
fldl 4(%esp)
fldl2e /* log2(e) x */
fmulp /* xs */
fld %st /* xs xs */
frndint /* nint(xs) xs */
fxch %st(1) /* xs nint */
fsub %st(1),%st /* fract nint */
f2xm1 /* exps-1 nint */
fxch %st(1) /* nint exps-1 */
fld1 /* 1 nint exps-1 */
fscale /* scale nint exps-1 */
fld1 /* 1 scale nint exps-1 */
/* Should be fsubp %st,%st(1) (gas bug) */
.byte 0xDE, 0xE9 /* scale-1 nint exps-1 */
fxch %st(2) /* exps-1 nint scale-1 */
fscale /* expm nint scale-1 */
fstp %st(1) /* exp scale-1 */
faddp /* exp-1 */
ret
 
bigarg:
je edge
andl $0x7FF00000, %eax /* |x| > log(DBL_MAX) */
cmpl $0x7FF00000, %eax
je abarg
 
posneg:
testl $0x80000000, 8(%esp)
jnz argok /* Large negative -- OK */
movl $2, C_SYM(errno) /* |x| is really big, but finite */
jmp argok
 
edge: /* |x| is nearly log(DBL_MAX) */
cmpl $0xFEFA39EF, 4(%esp)
jbe argok
jmp posneg
 
abarg: /* x = +/-inf, or +NaN */
testl $0x000FFFFF, 8(%esp)
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jnz badarg
 
infarg: /* |x| = inf */
testl $0x80000000, 8(%esp)
jz posinf
 
neginf:
fld1
fchs
ret
 
posinf:
movl $2, C_SYM(errno)
flds pinf
ret
 
badarg: /* arg is NaN */
movl $1, C_SYM(errno)
flds NaN
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exp10.s
0,0 → 1,6
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.file "exp10.s"
MK_C_SYM(exp10)
jmp C_SYM(__pow10)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/math/exp2.s
0,0 → 1,5
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(exp2)
jmp C_SYM(__pow2)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log10.s
0,0 → 1,7
/* Copyright (C) 1994 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(log10)
fldlg2
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log1p.s
0,0 → 1,65
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
NaN:
.long 0xFFC00000
 
ninf:
.long 0xFF800000
 
pinf:
.long 0x7F800000
 
.text
MK_C_SYM(log1p) /* ln(1.+x) */
/* log1p(x) */
movl 8(%esp), %eax
movl %eax, %edx
 
cmpl $0xBFF00000,%eax /* x <= -1 ? */
jae nonpos
 
andl $0x7FF00000,%eax
cmpl $0x7FF00000,%eax
je abarg /* x == +inf or +NaN */
 
movl %edx, %eax
andl $0x7FFFFFFF,%eax
cmpl $0x3FD2BEC3,%eax /* 1 - sqrt(0.5) */
fldln2 /* ln(2) */
jbe 1f
fld1
faddl 4(%esp)
fyl2x /* logi(x) */
ret
1: /* log1pi(x) */
fldl 4(%esp)
fyl2xp1
ret
 
nonpos:
cmpl $0xBFF00000,%eax
ja badarg /* x == -1 ? */
movl 4(%esp), %eax
testl %eax, %eax
jz negone
 
badarg:
movl $1, C_SYM(errno)
flds NaN
ret
 
negone:
movl $2, C_SYM(errno)
flds ninf /* arg == -1; load -inf. */
ret
 
abarg:
movl %edx, %eax
testl $0x000FFFFF, %eax
jnz badarg
movl 4(%esp), %eax
testl %eax, %eax
jnz badarg
 
flds pinf /* arg = +inf */
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/log2.s
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(log2)
fld1
fldl 4(%esp)
fyl2x
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/math/powi.s
0,0 → 1,34
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
.text
MK_C_SYM(powi)
/* double powi(double x, int iy) = x^iy */
 
fldl 4(%esp) /* x2p = x; */
movl 12(%esp), %eax
 
testl %eax, %eax /* if (iy < 0) { */
jge Endif1
negl %eax /* iy = -iy; */
fld1 /* x = 1./x; */
/* Should be fdivrp %st, %st(1) (gas bug) */
.byte 0xDE, 0xF1
Endif1: /* } */
 
fld1 /* result = 1.; */
fxch %st(1)
 
jmp Test
.balign 16,,7
Loop:
testb $1, %al /* if (iy & 1) result *= x2p; */
je Endif2
fmul %st, %st(1)
Endif2:
shrl $1, %eax /* (unsigned) iy >>= 1; */
fmul %st(0), %st /* x2p *= x2p; */
Test:
testl %eax, %eax /* } */
jne Loop
fstp %st(0)
ret /* return result; */
/programs/develop/libraries/menuetlibc/src/libc/compat/math/sincos.s
0,0 → 1,43
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
 
NaN:
.long 0x00000000, 0xFFF80000
 
MK_C_SYM(sincos)
 
/* void sincos(double *cosine, double *sine, double x); */
 
movl 16(%esp), %ecx
 
movl 4(%esp), %eax /* Point to cosine. */
movl 8(%esp), %edx /* Point to sine. */
 
andl $0x7FF00000, %ecx /* Examine exponent of x. */
cmpl $0x43E00000, %ecx /* |x| >= 2^63 */
jae bigarg
 
fldl 12(%esp)
fsincos
fstpl (%eax) /* cos */
fstpl (%edx) /* sin */
ret
 
bigarg:
cmpl $0x7FF00000, %ecx /* x is INF or NaN. */
jb finite
movl NaN, %ecx /* Return -NaN */
movl %ecx, (%eax)
movl %ecx, (%edx)
movl NaN+4, %ecx
movl %ecx, 4(%eax)
movl %ecx, 4(%edx)
movl $1, C_SYM(errno)
ret
 
finite:
fld1
fstpl (%eax) /* cos = 1. */
fldz
fstpl (%edx) /* sin = 0. */
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/mman/Makefile
0,0 → 1,3
THIS_SRCS = mprotect.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/mman/mprotect.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/types.h>
#include <sys/mman.h>
#include <errno.h>
#include <assert.h>
 
int mprotect(void *addr, size_t len, int prot)
{
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/mntent/Makefile
0,0 → 1,3
THIS_SRCS = mntent.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/mntent/mntent.c
0,0 → 1,232
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/*
* This is implementation of getmntent() and friends for DJGPP v2.x.
*
* Copyright (c) 1995-96 Eli Zaretskii <eliz@is.elta.co.il>
*
* This software may be used freely so long as this copyright notice is
* left intact. There is no warranty on this software.
*
* ---------------------------------------------------------------------
*
* The primary motivation for these functions was the GNU df program,
* which lists all the mounted filesystems with a summary of the disk
* space available on each one of them. However, they are also useful
* on their own right.
*
* Unlike Unix, where all mountable filesystems can be found on special
* file (and thus implementing these function boils down to reading that
* file), with MS-DOS it's a mess. Every type of drive has its own
* interface; there are JOINed and SUBSTed pseudo-drives and RAM disks;
* different network redirectors hook DOS in a plethora of incompatible
* ways; a single drive A: can be mapped to either A: or B:, etc. That
* is why this implementation uses almost every trick in the book to get
* at the intimate details of every drive. Some places where you might
* find these tricks are: ``Undocumented DOS, 2nd ed.'' by Schulman et al
* and Ralf Brown's Interrupt List.
*
*/
#include <libc/stubs.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <sys/stat.h>
#include <mntent.h>
#include <dir.h>
#include <libc/farptrgs.h>
#include <sys/movedata.h>
#include <libc/unconst.h>
#include <assert.h>
 
/* Macro to convert a segment and an offset to a "far offset" suitable
for _farxxx() functions of DJGPP. */
#ifndef MK_FOFF
#define MK_FOFF(s,o) ((int)((((unsigned long)(s)) << 4) + (unsigned short)(o)))
#endif
 
#define CDS_JOIN 0x2000
#define CDS_VALID 0xc000
#define REMOVABLE 0
#define FIXED 1
 
/* Static variables. */
 
static char drive_number = -1;
static char skip_drive_b = 0;
static char drive_a_mapping = 0;
static char cds_drives = 0;
static unsigned long cds_address;
static int cds_elsize;
static unsigned short dos_mem_base, our_mem_base;
static struct mntent mntent;
static unsigned char drive_string[128];
static char *mnt_type;
static unsigned char mnt_dir[128];
static unsigned char mnt_fsname[128];
static char dev_opts[] = "r ,dev= ";
 
static char NAME_dblsp[] = "dblsp";
static char NAME_stac[] = "stac";
static char NAME_ram[] = "ram";
static char NAME_cdrom[] = "cdrom";
static char NAME_net[] = "net";
static char NAME_fd[] = "fd";
static char NAME_hd[] = "hd";
static char NAME_subst[] = "subst";
static char NAME_join[] = "join";
 
int _is_remote_drive(int);
 
/* Static helper functions. */
 
/*
* Get the entry for this disk in the DOS Current Directory Structure
* (CDS). In case of success, return this drive's attribute word; or
* 0 in case of failure. Fill the buffer at CURRDIR with the current
* directory on that drive.
* The pointer to the CDS array and the size of the array element
* (which are DOS version-dependent) are computed when setmntent() is
* called.
*/
static int
get_cds_entry(int drive_num, char *currdir)
{
unsigned long cds_entry_address;
if (!cds_address)
{
*currdir = '\0';
return 0;
}
 
/* The address of the CDS element for this drive. */
cds_entry_address = cds_address + (drive_num - 1)*cds_elsize;
/* The current directory: 67-byte ASCIIZ string at the beginning
of the CDS structure for our drive. */
movedata(dos_mem_base, (cds_entry_address & 0xfffff),
our_mem_base, (unsigned int)currdir, 0x43);
 
/* The drive attribute word is at the offset 43h, right after the
current directory string. */
return _farpeekw(dos_mem_base, cds_entry_address + 0x43);
}
 
/*
* For a PC with a single floppy drive, that drive can be referenced
* as both A: and B:. This function returns the logical drive number
* which was last used to reference a physical drive, or 0 if the
* drive has only one logical drive assigned to it (which means there
* are two floppies in this system).
*/
static int assigned_to(int drive_num)
{
return drive_num;
}
 
/*
* Check if the drive is compressed with DoubleSpace. If it is,
* get the host drive on which the Compressed Volume File (CVF)
* resides, put the name of that CVF into MNT_FSNAME[] and return
* non-zero.
*/
static int get_doublespace_info(int drive_num)
{
return 0;
}
 
static int get_stacker_info(int drive_num)
{
return 0;
}
 
/*
* Get the network name which corresponds to a drive DRIVE_NUM.
* Ideally, _truename() (Int 21h/AH=60h) should return the same
* string, but some network redirectors don't put a full UNC
* name into the CDS, and others bypass the CDS altogether.
*/
static int get_netredir_entry(int drive_num)
{
return 0;
}
 
/*
* Return 1 if this drive is a CD-ROM drive, 0 otherwise. Works
* with MSCDEX 2.x, but what about other CD-ROM device drivers?
*/
static int is_cdrom_drive(int drive_num)
{
return 0;
}
 
/*
* Return 1 if a CD-ROM drive DRIVE_NUM is ready, i.e. there is a
* disk in the drive and that disk is a data (not AUDIO) disk.
*/
static int cdrom_drive_ready(int drive_num)
{
return 0;
}
 
/*
* Detect a RAM disk. We do this by checking if the number of FAT
* copies (in the Device Parameter Block) is 1, which is typical of
* RAM disks. [This doesn't _have_ to be so, but if it's good
* enough for Andrew Schulman et al (Undocumented DOS, 2nd edition),
* we can use this as well.]
*/
static int is_ram_drive(int drive_num)
{
return -1;
}
 
/*
* Check if the media in this disk drive is fixed or removable.
* Should only be called after we're sure this ain't CD-ROM or
* RAM disk, since these might fool you with this call.
*/
static int media_type(int drive_num)
{
return 0;
}
 
/* Exported library functions. */
 
FILE * setmntent(char *filename, char *type)
{
return NULL;
}
 
static char NAME_unknown[] = "???";
struct mntent * getmntent(FILE *filep)
{
mntent.mnt_fsname = "FAT";
mntent.mnt_dir = "/";
mntent.mnt_freq = -1;
mntent.mnt_passno = -1;
mntent.mnt_time = -1;
}
 
int addmntent(FILE *filep, struct mntent *mnt)
{
unimpl();
}
 
char * hasmntopt(struct mntent *mnt, char *opt)
{
return strstr(mnt->mnt_opts, opt);
}
 
int endmntent(FILE *filep)
{
if (filep != (FILE *)1)
{
errno = EBADF; /* fake errno for invalid handle */
return NULL;
}
drive_number = 0;
skip_drive_b = 0;
return 1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/search/Makefile
0,0 → 1,3
THIS_SRCS= insque.c remque.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/search/insque.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <search.h>
 
void
insque(struct qelem *e, struct qelem *p)
{
if (!e || !p)
return;
e->q_back = p;
e->q_forw = p->q_forw;
p->q_forw->q_back = e;
p->q_forw = e;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/search/remque.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <search.h>
 
void
remque(struct qelem *e)
{
if (!e)
return;
if (e->q_forw)
e->q_forw->q_back = e->q_back;
if (e->q_back)
e->q_back->q_forw = e->q_forw;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/Makefile
0,0 → 1,3
THIS_SRCS= psignal.c siglist.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/psignal.c
0,0 → 1,16
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
 
#include <signal.h>
#include <stdio.h>
 
extern char *sys_siglist[];
 
void
psignal (int sig, const char *msg)
{
if (sig >= 0 && sig < NSIG)
__libclog_printf( "%s: %s\n", msg, sys_siglist[sig]);
else
__libclog_printf( "%s: signal %d\n", msg, sig);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/signal/siglist.c
0,0 → 1,97
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
 
#include <signal.h>
#include <string.h>
#include <stdlib.h>
 
char *sys_siglist[NSIG + 1]; /* initially all-zero */
 
static const char *known_signal[] = {
"Abort termination",
"Floating-point exception",
"Illegal instruction",
"Segmentation violation",
"Software termination signal",
"Alarm clock",
"Hangup",
"Interrupt",
"Kill",
"Write on pipe with no one to read it",
"Quit",
"User-defined signal 1",
"User-defined signal 2",
"Floating-point co-processor not present",
"Debugger/Breakpoint instruction",
"Timer tick signal",
"Profiler signal"
};
 
static char unknown_signal[] = "Unknown signal";
 
static void
put_hex_digits (char *str, int num, size_t idx)
{
static char xdigits[] = "0123456789ABCDEF";
 
str[idx] = xdigits[num / 16];
str[idx + 1] = xdigits[num & 15];
}
 
static char *
xstrdup (const char *src)
{
if (src)
{
size_t src_size = strlen (src) + 1;
char *new = (char *)malloc (src_size);
 
if (new)
{
memcpy (new, src, src_size);
return new;
}
}
 
return NULL;
}
 
static int signum;
 
static void
fill_dull_names (const char *template, size_t tpl_size, int count)
{
int i;
 
for (i = 0; i < count; i++)
{
char *signame = (char *)malloc (tpl_size);
 
memcpy (signame, template, tpl_size);
put_hex_digits (signame, i, tpl_size - 3);
sys_siglist[signum++] = signame;
}
}
 
static void __attribute__((constructor))
init_sys_siglist (void)
{
static char int_name[] = "Interrupt XXh";
static size_t int_size = sizeof(int_name);
static char excpt_name[] = "Exception XXh";
static size_t excpt_size = sizeof(excpt_name);
int i;
 
signum = 0;
 
fill_dull_names (int_name, int_size, 256);
fill_dull_names (excpt_name, excpt_size, 32);
 
for (i = 0; i < 17; i++)
sys_siglist[signum++] = xstrdup (known_signal[i]);
 
for (i = 305; i < 320; i++)
sys_siglist[signum++] = xstrdup (unknown_signal);
 
sys_siglist[signum] = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/Makefile
0,0 → 1,3
THIS_SRCS = mkstemp.c mktemp.c tempnam.c vscanf.c vsscanf.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mkstemp.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <fcntl.h>
#include <errno.h>
 
int
mkstemp (char *_template)
{
if (mktemp (_template))
return creat (_template, 0666);
else {
errno = ENOENT;
return -1;
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/mktemp.c
0,0 → 1,69
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <libc/bss.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
 
static int mktemp_count = -1;
 
char *
mktemp (char *_template)
{
static int count = 0;
char *cp, *dp;
int i, len, xcount, loopcnt;
 
/* Reinitialize counter if we were restarted (emacs). */
if (__bss_count != mktemp_count)
{
mktemp_count = __bss_count;
count = 0;
}
 
len = strlen (_template);
cp = _template + len;
 
xcount = 0;
while (xcount < 6 && cp > _template && cp[-1] == 'X')
xcount++, cp--;
 
if (xcount) {
dp = cp;
while (dp > _template && dp[-1] != '/' && dp[-1] != '\\' && dp[-1] != ':')
dp--;
 
/* Keep the first characters of the template, but turn the rest into
Xs. */
while (cp > dp + 8 - xcount) {
*--cp = 'X';
xcount = (xcount >= 6) ? 6 : 1 + xcount;
}
 
/* If dots occur too early -- squash them. */
while (dp < cp) {
if (*dp == '.') *dp = 'a';
dp++;
}
 
/* Try to add ".tmp" to the filename. Truncate unused Xs. */
if (cp + xcount + 3 < _template + len)
strcpy (cp + xcount, ".tmp");
else
cp[xcount] = 0;
 
/* This loop can run up to 2<<(5*6) times, or about 10^9 times. */
for (loopcnt = 0; loopcnt < (1 << (5 * xcount)); loopcnt++) {
int c = count++;
for (i = 0; i < xcount; i++, c >>= 5)
cp[i] = "abcdefghijklmnopqrstuvwxyz012345"[c & 0x1f];
if (!__file_exists(_template))
return _template;
}
}
 
/* Failure: truncate the template and return NULL. */
*_template = 0;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/tempnam.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
 
char * tempnam(const char *_dir, const char *_prefix)
{
return tmpnam(0);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vscanf.c
0,0 → 1,9
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
 
int
vscanf(const char *fmt, va_list ap)
{
return _doscan(stdin, fmt, ap);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdio/vsscanf.c
0,0 → 1,20
/* Copyright (C) 1999 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdarg.h>
#include <libc/file.h>
#include <libc/unconst.h>
 
int
vsscanf(const char *str, const char *fmt, va_list ap)
{
FILE _strbuf;
 
_strbuf._flag = _IOREAD|_IOSTRG|_IONTERM;
_strbuf._ptr = _strbuf._base = unconst(str, char *);
_strbuf._cnt = 0;
while (*str++)
_strbuf._cnt++;
_strbuf._bufsiz = _strbuf._cnt;
return _doscan(&_strbuf, fmt, ap);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/Makefile
0,0 → 1,4
THIS_SRCS = alloca.c cfree.c getlongp.c getpass.c itoa.c putenv.c \
random.c swab.c xfree.c xmalloc.c xrealloc.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/alloca.c
0,0 → 1,128
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* alloca.c -- allocate automatically reclaimed memory
(Mostly) portable public-domain implementation -- D A Gwyn
 
This implementation of the PWB library alloca function,
which is used to allocate space off the run-time stack so
that it is automatically reclaimed upon procedure exit,
was inspired by discussions with J. Q. Johnson of Cornell.
J.Otto Tennant <jot@cray.com> contributed the Cray support.
 
There are some preprocessor constants that can
be defined when compiling for your specific system, for
improved efficiency; however, the defaults should be okay.
 
The general concept of this implementation is to keep
track of all alloca-allocated blocks, and reclaim any
that are found to be deeper in the stack than the current
invocation. This heuristic does not reclaim storage as
soon as it becomes invalid, but it will do so eventually.
 
As a special case, alloca(0) reclaims storage without
allocating any. It is a good idea to use alloca(0) in
your main control loop, etc. to force garbage collection. */
 
#include <stdlib.h>
 
#ifdef alloca
#undef alloca
#endif
 
/* If your stack is a linked list of frames, you have to
provide an "address metric" ADDRESS_FUNCTION macro. */
 
#define ADDRESS_FUNCTION(arg) &(arg)
 
#define NULL 0
 
/* Define STACK_DIRECTION if you know the direction of stack
growth for your system; otherwise it will be automatically
deduced at run-time.
 
STACK_DIRECTION > 0 => grows toward higher addresses
STACK_DIRECTION < 0 => grows toward lower addresses
STACK_DIRECTION = 0 => direction of growth unknown */
 
#define STACK_DIRECTION -1
 
#define STACK_DIR STACK_DIRECTION /* Known at compile-time. */
 
/* An "alloca header" is used to:
(a) chain together all alloca'ed blocks;
(b) keep track of stack depth.
 
It is very important that sizeof(header) agree with malloc
alignment chunk size. The following default should work okay. */
 
#ifndef ALIGN_SIZE
#define ALIGN_SIZE sizeof(double)
#endif
 
typedef union hdr
{
char align[ALIGN_SIZE]; /* To force sizeof(header). */
struct
{
union hdr *next; /* For chaining headers. */
char *deep; /* For stack depth measure. */
} h;
} header;
 
static header *last_alloca_header = NULL; /* -> last alloca header. */
 
/* Return a pointer to at least SIZE bytes of storage,
which will be automatically reclaimed upon exit from
the procedure that called alloca. Originally, this space
was supposed to be taken from the current stack frame of the
caller, but that method cannot be made to work for some
implementations of C, for example under Gould's UTX/32. */
 
void *
alloca(size_t size)
{
char probe; /* Probes stack depth: */
char *depth = &probe;
/* Reclaim garbage, defined as all alloca storage that
was allocated from deeper in the stack than currently. */
{
header *hp; /* Traverses linked list. */
 
for (hp = last_alloca_header; hp != NULL;)
if ((STACK_DIR > 0 && hp->h.deep > depth)
|| (STACK_DIR < 0 && hp->h.deep < depth))
{
header *np = hp->h.next;
 
free ((void *) hp); /* Collect garbage. */
 
hp = np; /* -> next header. */
}
else
break; /* Rest are not deeper. */
 
last_alloca_header = hp; /* -> last valid storage. */
}
 
if (size == 0)
return NULL; /* No allocation required. */
 
/* Allocate combined header + user data storage. */
 
{
void * newp = malloc (sizeof (header) + size);
if (newp == 0)
abort();
/* Address of header. */
 
((header *) newp)->h.next = last_alloca_header;
((header *) newp)->h.deep = depth;
 
last_alloca_header = (header *) newp;
 
/* User storage begins just after header. */
 
return (void *) ((char *) newp + sizeof (header));
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/cfree.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void
cfree(void *_ptr)
{
free(_ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/getlongp.c
0,0 → 1,58
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <stdlib.h>
#include <pc.h>
 
int
getlongpass(const char *prompt, char *password, int max_length)
{
char *p = password;
int c, count = 0;
 
fflush(stdout);
/* If we can't prompt, abort */
if (fputs(prompt, stderr) < 0)
{
*p = '\0';
return -1;
}
 
while (1)
{
/* Get a character with no echo */
c = getkey();
 
/* Exit on interrupt (^c or ^break) */
if (c == '\003' || c == 0x100)
exit(1);
 
/* Terminate on end of line or file (^j, ^m, ^d, ^z) */
if (c == '\r' || c == '\n' || c == '\004' || c == '\032')
break;
 
/* Back up on backspace */
if (c == '\b')
{
if (count)
count--;
else if (p > password)
p--;
continue;
}
 
/* Ignore DOS extended characters */
if ((c & 0xff) != c)
continue;
 
/* Add to password if it isn't full */
if (p < password + max_length - 1)
*p++ = c;
else
count++;
}
*p = '\0';
 
fputc('\n', stderr);
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/getpass.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
char *
getpass(const char *prompt)
{
static char password_buffer[9];
 
if (getlongpass(prompt, password_buffer, 9) < 0)
return 0;
return password_buffer;
}
 
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/itoa.c
0,0 → 1,46
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stdlib.h>
 
char *
itoa(int value, char *string, int radix)
{
char tmp[33];
char *tp = tmp;
int i;
unsigned v;
int sign;
char *sp;
 
if (radix > 36 || radix <= 1)
{
errno = EDOM;
return 0;
}
 
sign = (radix == 10 && value < 0);
if (sign)
v = -value;
else
v = (unsigned)value;
while (v || tp == tmp)
{
i = v % radix;
v = v / radix;
if (i < 10)
*tp++ = i+'0';
else
*tp++ = i + 'a' - 10;
}
 
if (string == 0)
string = (char *)malloc((tp-tmp)+sign+1);
sp = string;
 
if (sign)
*sp++ = '-';
while (tp > tmp)
*sp++ = *--tp;
*sp = 0;
return string;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/putenv.c
0,0 → 1,11
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
#include <libc/bss.h>
 
int putenv(const char *val)
{
return __libc_putenv(val);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/random.c
0,0 → 1,365
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* This is file RANDOM.C */
/* This file may have been modified by DJ Delorie (Jan 1995). If so,
** these modifications are Coyright (C) 1993 DJ Delorie, 24 Kirsten Ave,
** Rochester NH, 03867-2954, USA.
*/
 
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that: (1) source distributions retain this entire copyright
* notice and comment, and (2) distributions including binaries display
* the following acknowledgement: ``This product includes software
* developed by the University of California, Berkeley and its contributors''
* in the documentation or other materials provided with the distribution
* and in all advertising materials mentioning features or use of this
* software. Neither the name of the University nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
 
#include <stdlib.h>
 
/*
* random.c:
* An improved random number generation package. In addition to the standard
* rand()/srand() like interface, this package also has a special state info
* interface. The initstate() routine is called with a seed, an array of
* bytes, and a count of how many bytes are being passed in; this array is then
* initialized to contain information for random number generation with that
* much state information. Good sizes for the amount of state information are
* 32, 64, 128, and 256 bytes. The state can be switched by calling the
* setstate() routine with the same array as was initiallized with initstate().
* By default, the package runs with 128 bytes of state information and
* generates far better random numbers than a linear congruential generator.
* If the amount of state information is less than 32 bytes, a simple linear
* congruential R.N.G. is used.
* Internally, the state information is treated as an array of longs; the
* zeroeth element of the array is the type of R.N.G. being used (small
* integer); the remainder of the array is the state information for the
* R.N.G. Thus, 32 bytes of state information will give 7 longs worth of
* state information, which will allow a degree seven polynomial. (Note: the
* zeroeth word of state information also has some other information stored
* in it -- see setstate() for details).
* The random number generation technique is a linear feedback shift register
* approach, employing trinomials (since there are fewer terms to sum up that
* way). In this approach, the least significant bit of all the numbers in
* the state table will act as a linear feedback shift register, and will have
* period 2^deg - 1 (where deg is the degree of the polynomial being used,
* assuming that the polynomial is irreducible and primitive). The higher
* order bits will have longer periods, since their values are also influenced
* by pseudo-random carries out of the lower bits. The total period of the
* generator is approximately deg*(2**deg - 1); thus doubling the amount of
* state information has a vast influence on the period of the generator.
* Note: the deg*(2**deg - 1) is an approximation only good for large deg,
* when the period of the shift register is the dominant factor. With deg
* equal to seven, the period is actually much longer than the 7*(2**7 - 1)
* predicted by this formula.
*/
 
 
 
/*
* For each of the currently supported random number generators, we have a
* break value on the amount of state information (you need at least this
* many bytes of state info to support this random number generator), a degree
* for the polynomial (actually a trinomial) that the R.N.G. is based on, and
* the separation between the two lower order coefficients of the trinomial.
*/
 
#define TYPE_0 0 /* linear congruential */
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
 
#define TYPE_1 1 /* x**7 + x**3 + 1 */
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
 
#define TYPE_2 2 /* x**15 + x + 1 */
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
 
#define TYPE_3 3 /* x**31 + x**3 + 1 */
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
 
#define TYPE_4 4 /* x**63 + x + 1 */
#define BREAK_4 256
#define DEG_4 63
#define SEP_4 1
 
 
/*
* Array versions of the above information to make code run faster -- relies
* on fact that TYPE_i == i.
*/
 
#define MAX_TYPES 5 /* max number of types above */
static int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
 
/*
* Initially, everything is set up as if from :
* initstate( 1, &randtbl, 128 );
* Note that this initialization takes advantage of the fact that srandom()
* advances the front and rear pointers 10*rand_deg times, and hence the
* rear pointer which starts at 0 will also end up at zero; thus the zeroeth
* element of the state information, which contains info about the current
* position of the rear pointer is just
* MAX_TYPES*(rptr - state) + TYPE_3 == TYPE_3.
*/
 
static unsigned long randtbl[DEG_3 + 1] = { TYPE_3,
0x9a319039U, 0x32d9c024U, 0x9b663182U, 0x5da1f342U,
0xde3b81e0U, 0xdf0a6fb5U, 0xf103bc02U, 0x48f340fbU,
0x7449e56bU, 0xbeb1dbb0U, 0xab5c5918U, 0x946554fdU,
0x8c2e680fU, 0xeb3d799fU, 0xb11ee0b7U, 0x2d436b86U,
0xda672e2aU, 0x1588ca88U, 0xe369735dU, 0x904f35f7U,
0xd7158fd6U, 0x6fa6f051U, 0x616e6b96U, 0xac94efdcU,
0x36413f93U, 0xc622c298U, 0xf5a42ab8U, 0x8a88d77bU,
0xf5ad9d0eU, 0x8999220bU, 0x27fb47b9U };
 
/*
* fptr and rptr are two pointers into the state info, a front and a rear
* pointer. These two pointers are always rand_sep places aparts, as they cycle
* cyclically through the state information. (Yes, this does mean we could get
* away with just one pointer, but the code for random() is more efficient this
* way). The pointers are left positioned as they would be from the call
* initstate( 1, randtbl, 128 )
* (The position of the rear pointer, rptr, is really 0 (as explained above
* in the initialization of randtbl) because the state table pointer is set
* to point to randtbl[1] (as explained below).
*/
 
static long *fptr = &randtbl[ SEP_3 + 1 ];
static long *rptr = &randtbl[ 1 ];
 
/*
* The following things are the pointer to the state information table,
* the type of the current generator, the degree of the current polynomial
* being used, and the separation between the two pointers.
* Note that for efficiency of random(), we remember the first location of
* the state information, not the zeroeth. Hence it is valid to access
* state[-1], which is used to store the type of the R.N.G.
* Also, we remember the last location, since this is more efficient than
* indexing every time to find the address of the last element to see if
* the front and rear pointers have wrapped.
*/
 
static long *state = &randtbl[ 1 ];
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
static long *end_ptr = &randtbl[ DEG_3 + 1 ];
 
/*
* srandom:
* Initialize the random number generator based on the given seed. If the
* type is the trivial no-state-information type, just remember the seed.
* Otherwise, initializes state[] based on the given "seed" via a linear
* congruential generator. Then, the pointers are set to known locations
* that are exactly rand_sep places apart. Lastly, it cycles the state
* information a given number of times to get rid of any initial dependencies
* introduced by the L.C.R.N.G.
* Note that the initialization of randtbl[] for default usage relies on
* values produced by this routine.
*/
 
int
srandom(int x)
{
int i, j;
 
if (rand_type == TYPE_0)
{
state[ 0 ] = x;
}
else
{
j = 1;
state[ 0 ] = x;
for (i = 1; i < rand_deg; i++)
{
state[i] = 1103515245*state[i - 1] + 12345;
}
fptr = &state[rand_sep];
rptr = &state[0];
for( i = 0; i < 10*rand_deg; i++ )
random();
}
return 0;
}
 
/*
* initstate:
* Initialize the state information in the given array of n bytes for
* future random number generation. Based on the number of bytes we
* are given, and the break values for the different R.N.G.'s, we choose
* the best (largest) one we can and set things up for it. srandom() is
* then called to initialize the state information.
* Note that on return from srandom(), we set state[-1] to be the type
* multiplexed with the current value of the rear pointer; this is so
* successive calls to initstate() won't lose this information and will
* be able to restart with setstate().
* Note: the first thing we do is save the current state, if any, just like
* setstate() so that it doesn't matter when initstate is called.
* Returns a pointer to the old state.
*/
 
char *
initstate (unsigned seed, char *arg_state, int n)
{
char *ostate = (char *)(&state[ -1 ]);
 
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
if (n < BREAK_1)
{
if (n < BREAK_0)
return 0;
rand_type = TYPE_0;
rand_deg = DEG_0;
rand_sep = SEP_0;
}
else
{
if (n < BREAK_2)
{
rand_type = TYPE_1;
rand_deg = DEG_1;
rand_sep = SEP_1;
}
else
{
if (n < BREAK_3)
{
rand_type = TYPE_2;
rand_deg = DEG_2;
rand_sep = SEP_2;
}
else
{
if (n < BREAK_4)
{
rand_type = TYPE_3;
rand_deg = DEG_3;
rand_sep = SEP_3;
}
else
{
rand_type = TYPE_4;
rand_deg = DEG_4;
rand_sep = SEP_4;
}
}
}
}
state = &(((long *)arg_state)[1]); /* first location */
end_ptr = &state[rand_deg]; /* must set end_ptr before srandom */
srandom(seed);
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
return ostate;
}
 
/*
* setstate:
* Restore the state from the given state array.
* Note: it is important that we also remember the locations of the pointers
* in the current state information, and restore the locations of the pointers
* from the old state information. This is done by multiplexing the pointer
* location into the zeroeth word of the state information.
* Note that due to the order in which things are done, it is OK to call
* setstate() with the same state as the current state.
* Returns a pointer to the old state information.
*/
 
char *
setstate(char *arg_state)
{
long *new_state = (long *)arg_state;
int type = new_state[0]%MAX_TYPES;
int rear = new_state[0]/MAX_TYPES;
char *ostate = (char *)( &state[ -1 ] );
 
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = MAX_TYPES * (rptr - state) + rand_type;
switch (type)
{
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
rand_type = type;
rand_deg = degrees[ type ];
rand_sep = seps[ type ];
break;
}
state = &new_state[ 1 ];
if (rand_type != TYPE_0)
{
rptr = &state[rear];
fptr = &state[(rear + rand_sep)%rand_deg];
}
end_ptr = &state[rand_deg]; /* set end_ptr too */
return ostate;
}
 
/*
* random:
* If we are using the trivial TYPE_0 R.N.G., just do the old linear
* congruential bit. Otherwise, we do our fancy trinomial stuff, which is the
* same in all ther other cases due to all the global variables that have been
* set up. The basic operation is to add the number at the rear pointer into
* the one at the front pointer. Then both pointers are advanced to the next
* location cyclically in the table. The value returned is the sum generated,
* reduced to 31 bits by throwing away the "least random" low bit.
* Note: the code takes advantage of the fact that both the front and
* rear pointers can't wrap on the same call by not testing the rear
* pointer if the front one has wrapped.
* Returns a 31-bit random number.
*/
 
long
random(void)
{
long i;
if (rand_type == TYPE_0)
{
i = state[0] = ( state[0]*1103515245 + 12345 )&0x7fffffff;
}
else
{
*fptr += *rptr;
i = (*fptr >> 1)&0x7fffffff; /* chucking least random bit */
if (++fptr >= end_ptr )
{
fptr = state;
++rptr;
}
else
{
if (++rptr >= end_ptr)
rptr = state;
}
}
return i;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/swab.c
0,0 → 1,21
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void
swab(const void *from, void *to, int n)
{
unsigned long temp;
const char* fromc = from;
char* toc = to;
 
n >>= 1; n++;
#define STEP temp = *fromc++,*toc++ = *fromc++,*toc++ = temp
/* round to multiple of 8 */
while ((--n) & 07)
STEP;
n >>= 3;
while (--n >= 0) {
STEP; STEP; STEP; STEP;
STEP; STEP; STEP; STEP;
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xfree.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
 
void xfree(void *_ptr);
void
xfree(void *_ptr)
{
if (_ptr)
free(_ptr);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xmalloc.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <io.h>
#include <unistd.h>
 
static char msg[] = "Fatal: malloc returned NULL\r\n";
 
void * xmalloc(size_t _sz);
void *
xmalloc(size_t _sz)
{
void *rv = malloc(_sz?_sz:1);
if (rv == 0)
{
__libclog_printf(msg);
_exit(1);
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/stdlib/xrealloc.c
0,0 → 1,26
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <io.h>
#include <unistd.h>
 
static char msg[] = "Fatal: xrealloc would have returned NULL\r\n";
 
void * xrealloc(void *ptr, size_t _sz);
void *
xrealloc(void *ptr, size_t _sz)
{
void *rv;
 
if (ptr == 0)
rv = malloc(_sz?_sz:1);
else
rv = realloc(ptr, _sz?_sz:1);
 
if (rv == 0)
{
__libclog_printf(msg);
_exit(1);
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/Makefile
0,0 → 1,4
THIS_SRCS = ffs.s memccpy.c stpcpy.c strcasec.s strdup.c stricmp.c \
strlwr.c strncase.s strnicmp.c strsep.c strupr.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/string/ffs.s
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(ffs)
bsfl 4(%esp), %eax
jnz .Lzero
movl $0,%eax
.Lzero:
ret
/programs/develop/libraries/menuetlibc/src/libc/compat/string/memccpy.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
void *
memccpy(void *t, const void *f, int c, size_t n)
{
c &= 0xff;
if (n)
{
unsigned char *tt = (unsigned char *)t;
const unsigned char *ff = (const unsigned char *)f;
 
do {
if ((*tt++ = *ff++) == c)
return tt;
} while (--n != 0);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/stpcpy.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char *
stpcpy(char *_dest, const char *_src)
{
if (!_dest || !_src)
return 0;
while ((*_dest++ = *_src++));
return --_dest;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strcasec.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(strcasecmp)
jmp C_SYM(stricmp)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strdup.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <stdlib.h>
 
char *
strdup(const char *_s)
{
char *rv;
if (_s == 0)
return 0;
rv = (char *)malloc(strlen(_s) + 1);
if (rv == 0)
return 0;
strcpy(rv, _s);
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/stricmp.c
0,0 → 1,16
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <ctype.h>
 
int
stricmp(const char *s1, const char *s2)
{
while (tolower(*s1) == tolower(*s2))
{
if (*s1 == 0)
return 0;
s1++;
s2++;
}
return (int)tolower(*s1) - (int)tolower(*s2);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strlwr.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <string.h>
 
char *
strlwr(char *_s)
{
char *rv = _s;
while (*_s)
{
*_s = tolower(*_s);
_s++;
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strncase.s
0,0 → 1,5
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(strncasecmp)
jmp C_SYM(strnicmp)
 
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strnicmp.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
#include <ctype.h>
 
int
strnicmp(const char *s1, const char *s2, size_t n)
{
 
if (n == 0)
return 0;
do {
if (tolower(*s1) != tolower(*s2++))
return (int)tolower(*s1) - (int)tolower(*--s2);
if (*s1++ == 0)
break;
} while (--n != 0);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strsep.c
0,0 → 1,32
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <string.h>
 
char *
strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;
int c, sc;
char *tok;
 
if ((s = *stringp) == 0)
return 0;
 
tok = s;
while (1)
{
c = *s++;
spanp = delim;
do {
if ((sc = *spanp++) == c)
{
if (c == 0)
s = 0;
else
s[-1] = 0;
*stringp = s;
return tok;
}
} while (sc != 0);
}
}
/programs/develop/libraries/menuetlibc/src/libc/compat/string/strupr.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <ctype.h>
#include <string.h>
 
char *
strupr(char *_s)
{
char *rv = _s;
while (*_s)
{
*_s = toupper(*_s);
_s++;
}
return rv;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/Makefile
0,0 → 1,14
all:
make -C resource
make -C stat
make -C vfs
 
clean:
make -C resource clean
make -C stat clean
make -C vfs clean
 
depend:
make -C resource depend
make -C stat depend
make -C vfs depend
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/Makefile
0,0 → 1,3
THIS_SRCS = resource.c gtrlimit.c strlimit.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/gtrlimit.c
0,0 → 1,56
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
#include <sys/resource.h>
#include <libc/bss.h>
 
extern unsigned int _stklen;
extern struct rlimit __libc_limits[];
 
static int rlimit_count = -1;
struct rlimit __libc_limits[RLIM_NLIMITS];
 
static void
__limits_initialize (void)
{
int i;
 
/* set hard limit */
__libc_limits[RLIMIT_CPU].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_FSIZE].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_DATA].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_STACK].rlim_max = (long) _stklen;
__libc_limits[RLIMIT_CORE].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_RSS].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_MEMLOCK].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_NPROC].rlim_max = RLIM_INFINITY;
__libc_limits[RLIMIT_NOFILE].rlim_max = sysconf (_SC_OPEN_MAX);
 
/* copy all hard limit to soft limit */
for (i = 0; i < RLIM_NLIMITS; i++)
__libc_limits[i].rlim_cur = __libc_limits[i].rlim_max;
}
 
int
getrlimit (int rltype, struct rlimit *rlimitp)
{
/* check argument range */
if (rltype < 0 || rltype >= RLIM_NLIMITS || rlimitp == NULL)
{
errno = EINVAL;
return -1;
}
 
/* initialize */
if (rlimit_count != __bss_count)
{
rlimit_count = __bss_count;
__limits_initialize ();
}
 
/* copy limit value */
*rlimitp = __libc_limits[rltype];
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/resource.c
0,0 → 1,25
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <errno.h>
#include <string.h>
#include <sys/resource.h>
 
int getrusage(int _who, struct rusage *_rusage)
{
clock_t q;
if (_rusage == 0)
{
errno = EFAULT;
return -1;
}
if (_who != RUSAGE_SELF && _who != RUSAGE_CHILDREN)
{
errno = EINVAL;
return -1;
}
memset(_rusage, 0, sizeof(struct rusage));
q = clock();
_rusage->ru_utime.tv_sec = q / CLOCKS_PER_SEC;
_rusage->ru_utime.tv_usec = q % CLOCKS_PER_SEC * 1000000 / CLOCKS_PER_SEC;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/resource/strlimit.c
0,0 → 1,38
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <sys/resource.h>
 
extern struct rlimit __libc_limits[];
 
int
setrlimit (int rltype, const struct rlimit *rlimitp)
{
/* check argument range */
if (rlimitp->rlim_cur > rlimitp->rlim_max || rlimitp == NULL)
{
errno = EINVAL;
return -1;
}
 
switch (rltype)
{
case RLIMIT_CPU:
case RLIMIT_FSIZE:
case RLIMIT_DATA:
case RLIMIT_STACK:
case RLIMIT_CORE:
case RLIMIT_RSS:
case RLIMIT_MEMLOCK:
case RLIMIT_NPROC:
case RLIMIT_NOFILE:
/* not supported */
errno = EPERM;
return -1;
default:
errno = EINVAL;
return -1;
}
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/stat/Makefile
0,0 → 1,3
THIS_SRCS = mknod.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/stat/mknod.c
0,0 → 1,15
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <sys/stat.h>
#include <errno.h>
#include <fcntl.h>
#include <unistd.h>
#include <assert.h>
 
/* ARGSUSED */
int
mknod(const char *path, mode_t mode, dev_t dev)
{
errno = EACCES;
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/vfs/Makefile
0,0 → 1,3
THIS_SRCS = statfs.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/sys/vfs/statfs.c
0,0 → 1,19
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <sys/vfs.h>
#include <ctype.h>
 
int statfs(const char *path, struct statfs *buf)
{
buf->f_bavail = 0xFFFFFFFF;
buf->f_bfree = 0xFFFFFFFF;
buf->f_blocks = 0xFFFF;
buf->f_bsize = 512;
buf->f_ffree = 0xFFFF;
buf->f_files = 0xFFFF;
buf->f_type = 0;
buf->f_fsid[0] = 0;
buf->f_fsid[1] = MOUNT_UFS;
buf->f_magic = FS_MAGIC;
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/Makefile
0,0 → 1,4
THIS_SRCS = cfmakraw.c cfstspd.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/cfmakraw.c
0,0 → 1,25
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <termios.h>
#include <sys/exceptn.h>
 
void cfmakeraw (struct termios *termiosp)
{
/* check arguments */
if (termiosp == NULL)
{
errno = EINVAL;
return;
}
termiosp->c_iflag &= ~(BRKINT|ICRNL|IGNBRK|IGNCR|INLCR|ISTRIP|PARMRK|IXON);
#if defined (IMAXBEL)
termiosp->c_iflag &= ~IMAXBEL;
#endif
termiosp->c_oflag &= ~OPOST;
termiosp->c_lflag &= ~(ECHONL|ICANON|IEXTEN|ISIG);
termiosp->c_cflag &= ~(CSIZE|PARENB);
termiosp->c_cflag |= CS8;
termiosp->c_cc[VMIN] = 1;
termiosp->c_cc[VTIME] = 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/termios/cfstspd.c
0,0 → 1,21
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <stddef.h>
#include <termios.h>
 
int
cfsetspeed (struct termios *termiosp, speed_t speed)
{
/* check arguments */
if (termiosp == NULL)
{
errno = EINVAL;
return -1;
}
 
/* set input and output speed */
termiosp->c_ispeed = speed;
termiosp->c_ospeed = speed;
 
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/Makefile
0,0 → 1,4
THIS_SRCS = rawclock.c select.c settimeo.c utimes.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
 
/programs/develop/libraries/menuetlibc/src/libc/compat/time/rawclock.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <libc/farptrgs.h>
#include <menuet/os.h>
 
unsigned long rawclock(void)
{
static unsigned long base = 0;
unsigned long rv;
rv=__menuet__getsystemclock();
if (base == 0)
base = rv;
return rv - base;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/select.c
0,0 → 1,206
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
/* An implementation of select()
 
Copyright 1995 by Morten Welinder
This file maybe freely distributed and modified as long as the
copyright notice remains.
 
Notes: In a single process system as Dos this really boils down to
something that can check whether a character from standard input
is ready. However, the code is organised in a way to make it easy
to extend to multi process systems like WinNT and OS/2. */
 
#include <libc/stubs.h>
#include <sys/types.h>
#include <time.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <libc/file.h>
#include <libc/local.h>
#include <libc/dosio.h>
#include <sys/fsext.h>
 
inline static int fp_output_ready(FILE *fp)
{
return !ferror(fp);
}
 
/* This is as close as we get, I think. For a file connected to a printer
we could of course go ask the BIOS, but this should be enough. */
 
inline static int fp_except_ready(FILE *fp)
{
return ferror (fp);
}
 
inline static int fp_input_ready (FILE *fp)
{
/* I think if there is something in the buffer, we should return
``ready'', even if some error was encountered. Let him consume
the buffered characters, *then* return ``not ready''. */
if (fp->_cnt)
return 1;
 
/* The `feof' part is only correct in a single-tasked environment. */
if (ferror (fp) || feof (fp))
return 0;
 
/* There is nothing in the buffer (perhaps because we read unbuffered).
We don't know if we are ready. Return ``ready'' anyway and let
read() or write() tell the truth. */
return 1;
}
 
/* The Dos call 4407 always returns TRUE for disk files. So the
following really is meaningful for character devices only... */
 
inline static int fd_output_ready(int fd)
{
return 0;
}
 
inline static int fd_input_ready(int fd)
{
return 0;
}
 
int select(int nfds,fd_set *readfds,fd_set *writefds,fd_set *exceptfds,
struct timeval *timeout)
{
int ready;
fd_set oread, owrite, oexcept;
struct timeval now, then;
 
if (nfds > FD_SETSIZE)
{
errno = EINVAL;
return -1;
}
 
FD_ZERO (&oread);
FD_ZERO (&owrite);
FD_ZERO (&oexcept);
ready = 0;
 
if (timeout)
{
if (timeout->tv_usec < 0)
{
errno = EINVAL;
return -1;
}
gettimeofday (&now, 0);
then.tv_usec = timeout->tv_usec + now.tv_usec;
then.tv_sec = timeout->tv_sec + now.tv_sec + then.tv_usec / 1000000;
then.tv_usec %= 1000000;
}
 
do {
int i;
int fd0 = 0;
__file_rec *fr = __file_rec_list;
FILE *fp;
 
/* First, check the file handles with low-level DOS calls. */
for (i = 0; i < nfds; i++)
{
register int ioctl_result;
__FSEXT_Function *func = __FSEXT_get_function(i);
int fsext_ready = -1;
 
if (func)
func(__FSEXT_ready, &fsext_ready, &i);
 
if (readfds && FD_ISSET (i, readfds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_read)
ready++, FD_SET(i, &oread);
}
else if ((ioctl_result = fd_input_ready (i)) == -1)
return -1;
else if (ioctl_result)
ready++, FD_SET (i, &oread);
}
if (writefds && FD_ISSET (i, writefds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_write)
ready++, FD_SET(i, &owrite);
}
else if ((ioctl_result = fd_output_ready (i)) == -1)
return -1;
else if (ioctl_result)
ready++, FD_SET (i, &owrite);
}
if (exceptfds && FD_ISSET (i, exceptfds))
{
if (fsext_ready != -1)
{
if (fsext_ready & __FSEXT_ready_error)
ready++, FD_SET(i, &oexcept);
}
}
}
 
/* Now look at the table of FILE ptrs and reset the bits for file
descriptors which we *thought* are ready, but for which the flags
say they're NOT ready. */
for (i = 0; fr; i++)
{
if (i >= fd0 + fr->count) /* done with this subtable, go to next */
{
fd0 += fr->count;
fr = fr->next;
}
if (fr)
{
fp = fr->files[i - fd0];
if (fp->_flag)
{
int this_fd = fileno(fp);
 
if (this_fd < nfds)
{
if (readfds && FD_ISSET (this_fd, readfds) &&
FD_ISSET (this_fd, &oread) && !fp_input_ready (fp))
ready--, FD_CLR (this_fd, &oread);
if (writefds && FD_ISSET (this_fd, writefds) &&
FD_ISSET (this_fd, &owrite) && !fp_output_ready (fp))
ready--, FD_CLR (this_fd, &owrite);
 
/* For exceptional conditions, ferror() is the only one
which can tell us an exception is pending. */
if (exceptfds && FD_ISSET (this_fd, exceptfds) &&
fp_except_ready (fp))
ready++, FD_SET (this_fd, &oexcept);
}
}
}
}
 
/* Exit if we found what we were waiting for. */
if (ready > 0)
{
if (readfds)
*readfds = oread;
if (writefds)
*writefds = owrite;
if (exceptfds)
*exceptfds = oexcept;
return ready;
}
 
/* Exit if we hit the time limit. */
if (timeout)
{
gettimeofday (&now, 0);
if (now.tv_sec > then.tv_sec
|| (now.tv_sec = then.tv_sec && now.tv_usec >= then.tv_usec))
return 0;
}
} while (1);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/settimeo.c
0,0 → 1,9
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <time.h>
#include <assert.h>
#include <errno.h>
 
int settimeofday(struct timeval *_tp, ...)
{
return -EPERM;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/time/utimes.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <sys/time.h>
#include <utime.h>
 
int
utimes(const char *file, struct timeval tvp[2])
{
struct utimbuf utb;
utb.actime = tvp[0].tv_sec;
utb.modtime = tvp[1].tv_sec;
return utime(file, &utb);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/Makefile
0,0 → 1,4
THIS_SRCS= fsync.c ftruncat.c getdtabl.c gethostn.c getpages.c getwd.c \
nice.c sync.c truncate.c usleep.c vfork.c basename.c dirname.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/basename.c
0,0 → 1,28
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <libc/unconst.h>
 
char *
basename (const char *fname)
{
const char *base = fname;
 
if (fname && *fname)
{
if (fname[1] == ':')
{
fname += 2;
base = fname;
}
 
while (*fname)
{
if (*fname == '\\' || *fname == '/')
base = fname + 1;
fname++;
}
}
 
return unconst (base, char *);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/dirname.c
0,0 → 1,62
/* Copyright (C) 1998 DJ Delorie, see COPYING.DJ for details */
/* Copyright (C) 1997 DJ Delorie, see COPYING.DJ for details */
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
 
char *
dirname (const char *fname)
{
const char *p = fname;
const char *slash = NULL;
 
if (fname)
{
size_t dirlen;
char * dirpart;
 
if (*fname && fname[1] == ':')
{
slash = fname + 1;
p += 2;
}
 
/* Find the rightmost slash. */
while (*p)
{
if (*p == '/' || *p == '\\')
slash = p;
p++;
}
 
if (slash == NULL)
{
fname = ".";
dirlen = 1;
}
else
{
/* Remove any trailing slashes. */
while (slash > fname && (slash[-1] == '/' || slash[-1] == '\\'))
slash--;
 
/* How long is the directory we will return? */
dirlen = slash - fname + (slash == fname || slash[-1] == ':');
if (*slash == ':' && dirlen == 1)
dirlen += 2;
}
 
dirpart = (char *)malloc (dirlen + 1);
if (dirpart != NULL)
{
strncpy (dirpart, fname, dirlen);
if (slash && *slash == ':' && dirlen == 3)
dirpart[2] = '.'; /* for "x:foo" return "x:." */
dirpart[dirlen] = '\0';
}
 
return dirpart;
}
 
return NULL;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/fsync.c
0,0 → 1,11
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <libc/dosio.h>
#include <assert.h>
 
int fsync(int _fd)
{
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/ftruncat.c
0,0 → 1,12
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <io.h>
#include <errno.h>
 
int ftruncate(int fd, off_t where)
{
int res = dosemu_truncate(fd, where);
if (res) {errno = res; return -1;}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getdtabl.c
0,0 → 1,7
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
int getdtablesize(void)
{
return 255;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/gethostn.c
0,0 → 1,14
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
 
static char pc_n[]= "pc";
 
int gethostname (char *buf, int size)
{
strcpy(buf,"MenuetOS");
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getpages.c
0,0 → 1,8
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
 
int
getpagesize(void)
{
return 4096;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/getwd.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <limits.h>
 
extern char* __get_curdir(void);
char * getwd(char *buffer)
{
if (buffer == 0)
return 0;
char * p=__get_curdir();
sprintf(buffer,"%s",p);
return buffer;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/nice.c
0,0 → 1,29
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <errno.h>
 
/* The references disagree on the values of these. Higher value
means less important process. */
#define NICE_MIN -20
#define NICE_MAX +20
#define NICE_USER 0
 
static int nice_val = NICE_USER;
 
int nice (int incr)
{
if (incr < 0 && getuid () != 0) {
errno = EPERM;
return -1;
}
 
nice_val += incr;
if (nice_val < NICE_MIN) nice_val = NICE_MIN;
if (nice_val > NICE_MAX) nice_val = NICE_MAX;
 
/* This is braindead by design! If -1 returned you don't know
if you had an error! Luckily you can ignore errors for a
function like this. */
errno = 0;
return (nice_val - NICE_USER);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/sync.c
0,0 → 1,13
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
 
int
sync(void)
{
int i;
/* Update files with handles 0 thru 254 (incl). */
for (i = 0; i < 255; i++)
fsync (i);
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/truncate.c
0,0 → 1,24
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <unistd.h>
#include <fcntl.h>
#include <io.h>
#include <assert.h>
 
int truncate(const char *fn, off_t where)
{
int fd = open(fn, O_WRONLY);
if (fd < 0)
return -1;
if (lseek(fd, where, 0) < 0)
{
close(fd);
return -1;
}
if (_write(fd, 0, 0) < 0)
{
close(fd);
return -1;
}
return close(fd);
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/usleep.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <unistd.h>
#include <time.h>
 
unsigned int usleep(unsigned int _useconds)
{
clock_t cl_time;
clock_t start_time = clock();
_useconds >>= 10;
cl_time = _useconds * CLOCKS_PER_SEC / 977;
while (1)
{
clock_t elapsed = clock() - start_time;
if (elapsed >= cl_time) break;
__menuet__delay100(1);
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/unistd/vfork.c
0,0 → 1,10
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <errno.h>
#include <unistd.h>
 
pid_t
vfork(void)
{
errno = ENOMEM; /* The only other choice is EAGAIN, and we don't want that */
return -1;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/Makefile
0,0 → 1,3
THIS_SRCS = _bcopy.s fpurge.c setenv.c
 
include $(MENUET_LIBC_TOPDIR)/Make.rules
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/_bcopy.s
0,0 → 1,4
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include<libc/asm.h>
MK_C_SYM(_bcopy)
jmp C_SYM(bcopy)
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/fpurge.c
0,0 → 1,18
/* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
#include <stdio.h>
#include <libc/file.h>
 
int
fpurge(FILE *f)
{
char *base;
 
if ((f->_flag&(_IONBF|_IOWRT))==_IOWRT
&& (base = f->_base) != NULL
&& (f->_ptr - base) > 0)
{
f->_ptr = base;
f->_cnt = (f->_flag&(_IOLBF|_IONBF)) ? 0 : f->_bufsiz;
}
return 0;
}
/programs/develop/libraries/menuetlibc/src/libc/compat/v1/setenv.c
0,0 → 1,33
/* Copyright (C) 1996 DJ Delorie, see COPYING.DJ for details */
#include <libc/stubs.h>
#include <stdlib.h>
#include <string.h>
 
int
setenv (const char *var, const char *val, int replace)
{
char *prev;
 
if (var == (char *)0 || val == (char *)0)
return -1;
 
if ((prev = getenv (var)) && !replace)
return 0;
else
{
size_t l_var = strlen (var);
char *envstr = (char *)alloca (l_var + strlen (val) + 2);
char *peq = strchr (var, '=');
 
if (*val == '=')
++val;
if (peq)
l_var = peq - var;
 
strncpy (envstr, var, l_var);
envstr[l_var++] = '=';
strcpy (envstr + l_var, val);
 
return putenv (envstr);
}
}