Sat Sep 16 17:47:19 1995 Ulrich Drepper <drepper@ipd.info.uni-karlsruhe.de>

* elf/elf.h (AT_GID): Fix typo: Read -> Real.

	* misc/efgvt_r.c: New file.  Reentrant version of [efg]cvt functions.
	* misc/efgcvt.c: Rewrite to use reentrant functions.
	* misc/hsearch_r.c: New file.  Reentrant version of functions from
	hsearch family.
	* misc/hsearch.c, misc/tsearch.c: New files.
	* misc/Makefile (routines): Add efgcvt_r, hsearch_r, hsearch, tsearch.

	* posix/unistd.h (ttyname_r): Add prototype for new function.

	* stdlib/drand48_r.c, stdlib/erand48_r.c, stdlib/jrand48_r.c,
	stdlib/lrand48_r.c, stdlib/mrand48_r.c, stdlib/nrand48_r.c,
	stdlib/seed48_r.c, stdlib/srand48_r.c, stdlib/lcong48_r.c,
	stdlib/drand48-iter.c: New files implementing reentrant versions
	of functions from drand48 family.
	* stdlib/seed48.c, stdlib/drand48.c, stdlib/erand48.c,
	stdlib/jrand48.c, stdlib/lrand48.c, stdlib/mrand48.c,
	stdlib/nrand48.c, stdlib/srand48.c, stdlib/lcong48.c:
	Rewrite to use reentrant versions.
	* stdlib/a64l.c, stdlib/l64a.c: New files.  Implement a64l()
	and l64a() functions from SysV library.
	* stdlib/Makefile (routines): Add drand48_r, erand48_r, lrand48_r,
	nrand48_r, mrand48_r, jrand48_r, srand48_r, seed48_r, lcong48_r,
	drand48-iter, a64l, l64a.
	* stdlib/stdlib.h: Declare them.

	* stdlib/random_r.c: New file.  Reentrant version of functions
	from random family.
	* stdlib/stdlib.h: Declare them.
	* stdlib/random.c: Rewrite to use reentrant functions.

	* string/strerror_r.c: New file.  Reentrant version.
	* string/strerror.c: Change for new _strerror_internal form.
	* string/Makefile (routines): Add strerror_r.

	* sysdeps/generic/dl-sysdep.c (_dl_sysdep_start): Set default
	value of user_entry to `_start'.
	Close AT_ENTRY case with `break'.

	* sysdeps/generic/strstr.c: New and much faster implementation
	by Stephen R. van den Berg.

	* sysdeps/generic/_strerror.c: _strerror_internal now takes
	three argument and has and explicit buffer length.
	* sysdeps/mach/_strerror.c: Change for new interface with three
	arguments.
	* stdio/perror.c, stdio/vfprintf.c: Callers changed.
	
	* sysdeps/mach/hurd/ttyname_r.c: New file.  Reentrant version.
	* sysdeps/posix/ttyname_r.c: New file.  Reentrant version.
	* sysdeps/stub/ttyname_r: New file.  Define as dummy function.

	* sysdeps/posix/utimes.c: Include <utime.h> for prototype.
	(utimes): First parameter to utime must be file, not path.

	* sysdeps/posix/sysconf.c (__sysconf): Test for CLK_TCK in case
	_SC_CLK_TCK and return it when available.
	Test for STREAM_MAX in case _SC_STREAM_MAX and return it when
	available.
	Add case for _SC_2_LOCALEDEF which is now available.

	* posix/sys/types.h [__USE_SVID] (key_t): New type.
	* sysvipc/Makefile, sysvipc/ftok.c, sysvipc/sys/ipc.h,
	sysvipc/sys/msg.h, sysvipc/sys/sem.h, sysvipc/sys/shm.h,
	sysdeps/stub/sys/msq_buf.h, sysdeps/stub/sys/sem_buf.h,
	sysdeps/stub/sys/shm_buf.h, sysdeps/stub/sys/ipc_buf.h,
	sysdeps/stub/semctl.c, sysdeps/stub/semget.c, sysdeps/stub/semop.c,
	sysdeps/stub/shmat.c, sysdeps/stub/shmctl.c, sysdeps/stub/shmdt.c,
	sysdeps/stub/shmget.c, sysdeps/stub/msgctl.c, sysdeps/stub/msgget.c,
	sysdeps/stub/msgrcv.c, sysdeps/stub/msgsnd.c: New files.
	Add implementation of System V IPC.
This commit is contained in:
Roland McGrath 1995-09-17 20:23:15 +00:00
parent 9fd18b6c1b
commit 60478656fa
71 changed files with 3275 additions and 231 deletions

View File

@ -1,3 +1,77 @@
Sat Sep 16 17:47:19 1995 Ulrich Drepper <drepper@ipd.info.uni-karlsruhe.de>
* elf/elf.h (AT_GID): Fix typo: Read -> Real.
* misc/efgvt_r.c: New file. Reentrant version of [efg]cvt functions.
* misc/efgcvt.c: Rewrite to use reentrant functions.
* misc/hsearch_r.c: New file. Reentrant version of functions from
hsearch family.
* misc/hsearch.c, misc/tsearch.c: New files.
* misc/Makefile (routines): Add efgcvt_r, hsearch_r, hsearch, tsearch.
* posix/unistd.h (ttyname_r): Add prototype for new function.
* stdlib/drand48_r.c, stdlib/erand48_r.c, stdlib/jrand48_r.c,
stdlib/lrand48_r.c, stdlib/mrand48_r.c, stdlib/nrand48_r.c,
stdlib/seed48_r.c, stdlib/srand48_r.c, stdlib/lcong48_r.c,
stdlib/drand48-iter.c: New files implementing reentrant versions
of functions from drand48 family.
* stdlib/seed48.c, stdlib/drand48.c, stdlib/erand48.c,
stdlib/jrand48.c, stdlib/lrand48.c, stdlib/mrand48.c,
stdlib/nrand48.c, stdlib/srand48.c, stdlib/lcong48.c:
Rewrite to use reentrant versions.
* stdlib/a64l.c, stdlib/l64a.c: New files. Implement a64l()
and l64a() functions from SysV library.
* stdlib/Makefile (routines): Add drand48_r, erand48_r, lrand48_r,
nrand48_r, mrand48_r, jrand48_r, srand48_r, seed48_r, lcong48_r,
drand48-iter, a64l, l64a.
* stdlib/stdlib.h: Declare them.
* stdlib/random_r.c: New file. Reentrant version of functions
from random family.
* stdlib/stdlib.h: Declare them.
* stdlib/random.c: Rewrite to use reentrant functions.
* string/strerror_r.c: New file. Reentrant version.
* string/strerror.c: Change for new _strerror_internal form.
* string/Makefile (routines): Add strerror_r.
* sysdeps/generic/dl-sysdep.c (_dl_sysdep_start): Set default
value of user_entry to `_start'.
Close AT_ENTRY case with `break'.
* sysdeps/generic/strstr.c: New and much faster implementation
by Stephen R. van den Berg.
* sysdeps/generic/_strerror.c: _strerror_internal now takes
three argument and has and explicit buffer length.
* sysdeps/mach/_strerror.c: Change for new interface with three
arguments.
* stdio/perror.c, stdio/vfprintf.c: Callers changed.
* sysdeps/mach/hurd/ttyname_r.c: New file. Reentrant version.
* sysdeps/posix/ttyname_r.c: New file. Reentrant version.
* sysdeps/stub/ttyname_r: New file. Define as dummy function.
* sysdeps/posix/utimes.c: Include <utime.h> for prototype.
(utimes): First parameter to utime must be file, not path.
* sysdeps/posix/sysconf.c (__sysconf): Test for CLK_TCK in case
_SC_CLK_TCK and return it when available.
Test for STREAM_MAX in case _SC_STREAM_MAX and return it when
available.
Add case for _SC_2_LOCALEDEF which is now available.
* posix/sys/types.h [__USE_SVID] (key_t): New type.
* sysvipc/Makefile, sysvipc/ftok.c, sysvipc/sys/ipc.h,
sysvipc/sys/msg.h, sysvipc/sys/sem.h, sysvipc/sys/shm.h,
sysdeps/stub/sys/msq_buf.h, sysdeps/stub/sys/sem_buf.h,
sysdeps/stub/sys/shm_buf.h, sysdeps/stub/sys/ipc_buf.h,
sysdeps/stub/semctl.c, sysdeps/stub/semget.c, sysdeps/stub/semop.c,
sysdeps/stub/shmat.c, sysdeps/stub/shmctl.c, sysdeps/stub/shmdt.c,
sysdeps/stub/shmget.c, sysdeps/stub/msgctl.c, sysdeps/stub/msgget.c,
sysdeps/stub/msgrcv.c, sysdeps/stub/msgsnd.c: New files.
Add implementation of System V IPC.
Fri Sep 15 21:34:28 1995 Roland McGrath <roland@churchy.gnu.ai.mit.edu>
* hurd/hurdsig.c: Include <hurd/crash.h> in place of <hurd/core.h>.

View File

@ -430,7 +430,7 @@ typedef struct
#define AT_NOTELF 10 /* Program is not ELF */
#define AT_UID 11 /* Real uid */
#define AT_EUID 12 /* Effective uid */
#define AT_GID 13 /* Read gid */
#define AT_GID 13 /* Real gid */
#define AT_EGID 14 /* Effective gid */
/* Intel 80386 specific definitions. */

View File

@ -25,7 +25,7 @@ subdir := misc
headers := sys/uio.h sys/ioctl.h sys/ptrace.h ioctls.h sys/file.h \
a.out.h nlist.h stab.h stab.def sgtty.h sys/dir.h sys/cdefs.h \
ttyent.h syscall.h syslog.h sys/syslog.h paths.h sys/reboot.h \
sys/mman.h sys/param.h fstab.h mntent.h search.h utmp.h
sys/mman.h sys/param.h fstab.h search.h utmp.h
routines := brk sbrk sstk ioctl \
readv writev \
@ -42,14 +42,15 @@ routines := brk sbrk sstk ioctl \
ualarm usleep \
gtty stty \
ptrace \
nlist fstab mntent \
nlist fstab \
utimes \
truncate ftruncate \
chflags fchflags \
insremque getttyent getusershell getpass ttyslot \
syslog syscall daemon \
mmap munmap mprotect msync madvise \
efgcvt
efgcvt efgcvt_r \
hsearch hsearch_r tsearch
aux := progname init-misc
distribute := bsd-compat.c
extra-objs := bsd-compat.o

View File

@ -1,4 +1,4 @@
/* [efg]cvt -- compatibility functions for floating point formatting
/* [efg]cvt -- compatibility functions for floating point formatting.
Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
@ -18,9 +18,7 @@ not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <stdlib.h>
char *
fcvt (value, ndigit, decpt, sign)
@ -28,24 +26,8 @@ fcvt (value, ndigit, decpt, sign)
int ndigit, *decpt, *sign;
{
static char buf[100];
int n, i;
*sign = value < 0.0;
if (*sign)
value = - value;
n = snprintf (buf, sizeof buf, "%.*f", ndigit, value);
if (n < 0)
return NULL;
i = 0;
while (i < n && isdigit (buf[i]))
++i;
*decpt = i;
do
++i;
while (! isdigit (buf[i]));
memmove (&buf[i - *decpt], buf, n - (i - *decpt));
(void) fcvt_r (value, ndigit, decpt, sign, buf, sizeof buf);
return buf;
}
@ -55,10 +37,11 @@ ecvt (value, ndigit, decpt, sign)
double value;
int ndigit, *decpt, *sign;
{
ndigit -= (int) floor (log10 (value));
if (ndigit < 0)
ndigit = 0;
return fcvt (value, ndigit, decpt, sign);
static char buf[100];
(void) ecvt_r (value, ndigit, decpt, sign, buf, sizeof buf);
return buf;
}
char *

73
misc/efgcvt_r.c Normal file
View File

@ -0,0 +1,73 @@
/* [efg]cvt -- compatibility functions for floating point formatting,
reentrent versions.
Copyright (C) 1995 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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
int
fcvt_r (value, ndigit, decpt, sign, buf, len)
double value;
int ndigit, *decpt, *sign;
char *buf;
int len;
{
int n, i;
if (buf == NULL)
{
errno = EINVAL;
return -1;
}
*sign = value < 0.0;
if (*sign)
value = - value;
n = snprintf (buf, len, "%.*f", ndigit, value);
if (n < 0)
return -1;
i = 0;
while (i < n && isdigit (buf[i]))
++i;
*decpt = i;
do
++i;
while (! isdigit (buf[i]));
memmove (&buf[i - *decpt], buf, n - (i - *decpt));
return 0;
}
int
ecvt_r (value, ndigit, decpt, sign, buf, len)
double value;
int ndigit, *decpt, *sign;
char *buf;
int len;
{
ndigit -= (int) floor (log10 (value));
if (ndigit < 0)
ndigit = 0;
return fcvt_r (value, ndigit, decpt, sign, buf, len);
}

52
misc/hsearch.c Normal file
View File

@ -0,0 +1,52 @@
/* Copyright (C) 1993, 1995 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <search.h>
/* The non-reenttrent version use a global space for storing the table. */
static struct hsearch_data htab;
/* Define the non-reentrent function using the reentrent counterparts. */
ENTRY *
hsearch (item, action)
ENTRY item;
ACTION action;
{
ENTRY *result;
(void) hsearch_r (item, action, &result, &htab);
return result;
}
int
hcreate (nel)
unsigned int nel;
{
return hcreate_r (nel, &htab);
}
void
hdestroy ()
{
hdestroy_r (&htab);
}

229
misc/hsearch_r.c Normal file
View File

@ -0,0 +1,229 @@
/* Copyright (C) 1993, 1995 Free Software Foundation, Inc.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <malloc.h>
#include <string.h>
#include <search.h>
/* [Aho,Sethi,Ullman] Compilers: Principles, Techniques and Tools, 1986
[Knuth] The Art of Computer Programming, part 3 (6.4) */
/* The reentrent version has no static variables to maintain the state.
Instead the interface of all functions is extended to take an argument
which describes the current status. */
typedef struct _ENTRY
{
int used;
ENTRY entry;
}
_ENTRY;
/* For the used double hash method the table size has to be a prime. To
correct the user given table size we need a prime test. This trivial
algorithm is adequate because
a) the code is (most probably) called a few times per program run and
b) the number is small because the table must fit in the core */
static int
isprime (number)
unsigned int number;
{
/* no even number will be passed */
unsigned int div = 3;
while (div * div < number && number % div != 0)
div += 2;
return number % div != 0;
}
/* Before using the hash table we must allocate memory for it.
Test for an existing table are done. We allocate one element
more as the found prime number says. This is done for more effective
indexing as explained in the comment for the hsearch function.
The contents of the table is zeroed, especially the field used
becomes zero. */
int
hcreate_r (nel, htab)
unsigned int nel;
struct hsearch_data *htab;
{
/* Test for correct arguments. */
if (htab == NULL)
{
errno = EINVAL;
return 0;
}
/* There is still another table active. Return with error. */
if (htab->table != NULL)
return 0;
/* Change nel to the first prime number not smaller as nel. */
nel |= 1; /* make odd */
while (!isprime (nel))
nel += 2;
htab->size = nel;
htab->filled = 0;
/* allocate memory and zero out */
htab->table = (_ENTRY *) calloc (htab->size + 1, sizeof (_ENTRY));
if (htab->table == NULL)
return 0;
/* everything went alright */
return 1;
}
/* After using the hash table it has to be destroyed. The used memory can
be freed and the local static variable can be marked as not used. */
void
hdestroy_r (htab)
struct hsearch_data *htab;
{
/* Test for correct arguments. */
if (htab == NULL)
{
errno = EINVAL;
return;
}
if (htab->table != NULL)
/* free used memory */
free (htab->table);
/* the sign for an existing table is an value != NULL in htable */
htab->table = NULL;
}
/* This is the search function. It uses double hashing with open adressing.
The argument item.key has to be a pointer to an zero terminated, most
probably strings of chars. The function for generating a number of the
strings is simple but fast. It can be replaced by a more complex function
like ajw (see [Aho,Sethi,Ullman]) if the needs are shown.
We use an trick to speed up the lookup. The table is created by hcreate
with one more element available. This enables us to use the index zero
special. This index will never be used because we store the first hash
index in the field used where zero means not used. Every other value
means used. The used field can be used as a first fast comparison for
equality of the stored and the parameter value. This helps to prevent
unnecessary expensive calls of strcmp. */
int
hsearch_r (item, action, retval, htab)
ENTRY item;
ACTION action;
ENTRY **retval;
struct hsearch_data *htab;
{
unsigned int hval;
unsigned int count;
unsigned int len = strlen (item.key);
unsigned int idx;
/* If table is full and another entry should be entered return with
error. */
if (action == ENTER && htab->filled == htab->size)
{
errno = ENOMEM;
*retval = NULL;
return 0;
}
/* Compute an value for the given string. Perhaps use a better method. */
hval = len;
count = len;
while (count-- > 0)
{
hval <<= 4;
hval += item.key[count];
}
/* First hash function: simply take the modul but prevent zero. */
hval %= htab->size;
if (hval == 0)
++hval;
/* The first index tried. */
idx = hval;
if (htab->table[idx].used)
{
/* Further action might be required according to the action value. */
unsigned hval2;
if (htab->table[idx].used == hval
&& strcmp (item.key, htab->table[idx].entry.key) == 0)
{
if (action == ENTER)
htab->table[idx].entry.data = item.data;
*retval = &htab->table[idx].entry;
return 1;
}
/* Second hash function, as suggested in [Knuth] */
hval2 = 1 + hval % (htab->size - 2);
do
{
/* Because SIZE is prime this guarantees to step through all
available indeces. */
if (idx <= hval2)
idx = htab->size + idx - hval2;
else
idx -= hval2;
/* If entry is found use it. */
if (htab->table[idx].used == hval
&& strcmp (item.key, htab->table[idx].entry.key) == 0)
{
if (action == ENTER)
htab->table[idx].entry.data = item.data;
*retval = &htab->table[idx].entry;
return 1;
}
}
while (htab->table[idx].used);
}
/* An empty bucket has been found. */
if (action == ENTER)
{
htab->table[idx].used = hval;
htab->table[idx].entry = item;
++htab->filled;
*retval = &htab->table[idx].entry;
return 1;
}
errno = ESRCH;
*retval = NULL;
return 0;
}

215
misc/tsearch.c Normal file
View File

@ -0,0 +1,215 @@
/* Copyright (C) 1995 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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
/* Tree search generalized from Knuth (6.2.2) Algorithm T just like
the AT&T man page says.
The node_t structure is for internal use only, lint doesn't grok it.
Written by reading the System V Interface Definition, not the code.
Totally public domain. */
/*LINTLIBRARY*/
#include <stdlib.h>
#include <search.h>
/* This routine is not very bad. It makes many assumptions about
the compiler. It assumpts that the first field in node must be
the "key" field, which points to the datum. It is a very trick
stuff. H.J. */
typedef struct node_t
{
const void *key;
struct node_t *left;
struct node_t *right;
}
node;
/* Prototype fpr local function. */
static void trecurse __P ((const void *vroot, __action_fn_t action, int level));
/* find or insert datum into search tree.
char *key; key to be located
node **rootp; address of tree root
int (*compar)(); ordering function
*/
void *
tsearch (key, vrootp, compar)
const void *key;
void **vrootp;
__compar_fn_t compar;
{
node *q;
node **rootp = (node **) vrootp;
if (rootp == NULL)
return NULL;
while (*rootp != NULL) /* Knuth's T1: */
{
int r;
r = (*compar) (key, (*rootp)->key);
if (r == 0) /* T2: */
return *rootp; /* we found it! */
rootp = (r < 0)
? &(*rootp)->left /* T3: follow left branch */
: &(*rootp)->right; /* T4: follow right branch */
}
q = (node *) malloc (sizeof (node)); /* T5: key not found */
if (q != NULL) /* make new node */
{
*rootp = q; /* link new node to old */
q->key = key; /* initialize new node */
q->left = q->right = NULL;
}
return q;
}
void *
tfind (key, vrootp, compar)
const void *key;
const void **vrootp;
__compar_fn_t compar;
{
node **rootp = (node **) vrootp;
if (rootp == NULL)
return NULL;
while (*rootp != NULL) /* Knuth's T1: */
{
int r;
r = (*compar)(key, (*rootp)->key);
if (r == 0) /* T2: */
return *rootp; /* we found it! */
rootp = (r < 0)
? &(*rootp)->left /* T3: follow left branch */
: &(*rootp)->right; /* T4: follow right branch */
}
return NULL;
}
/* delete node with given key
char *key; key to be deleted
node **rootp; address of the root of tree
int (*compar)(); comparison function
*/
void *
tdelete (key, vrootp, compar)
const void *key;
void **vrootp;
__compar_fn_t compar;
{
node *p;
node *q;
node *r;
int cmp;
node **rootp = (node **) vrootp;
if (rootp == NULL || (p = *rootp) == NULL)
return NULL;
while ((cmp = (*compar) (key, (*rootp)->key)) != 0)
{
p = *rootp;
rootp = (cmp < 0)
? &(*rootp)->left /* follow left branch */
: &(*rootp)->right; /* follow right branch */
if (*rootp == NULL)
return NULL; /* key not found */
}
r = (*rootp)->right; /* D1: */
q = (*rootp)->left;
if (q == NULL) /* Left NULL? */
q = r;
else if (r != NULL) /* Right link is NULL? */
{
if (r->left == NULL) /* D2: Find successor */
{
r->left = q;
q = r;
}
else
{ /* D3: Find (struct node_t *)0 link */
for (q = r->left; q->left != NULL; q = r->left)
r = q;
r->left = q->right;
q->left = (*rootp)->left;
q->right = (*rootp)->right;
}
}
free ((struct node_t *) *rootp); /* D4: Free node */
*rootp = q; /* link parent to new node */
return p;
}
/* Walk the nodes of a tree
node *root; Root of the tree to be walked
void (*action)(); Function to be called at each node
int level;
*/
static void
trecurse (vroot, action, level)
const void *vroot;
__action_fn_t action;
int level;
{
node *root = (node *) vroot;
if (root->left == NULL && root->right == NULL)
(*action) (root, leaf, level);
else
{
(*action) (root, preorder, level);
if (root->left != NULL)
trecurse (root->left, action, level + 1);
(*action) (root, postorder, level);
if (root->right != NULL)
trecurse (root->right, action, level + 1);
(*action) (root, endorder, level);
}
}
/* void twalk(root, action) Walk the nodes of a tree
node *root; Root of the tree to be walked
void (*action)(); Function to be called at each node
PTR
*/
void
twalk (vroot, action)
const void *vroot;
__action_fn_t action;
{
const node *root = (node *) vroot;
if (root != NULL && action != NULL)
trecurse (root, action, 0);
}

View File

@ -89,6 +89,12 @@ typedef int register_t __attribute__ ((__mode__ (word)));
#endif
#ifdef __USE_SVID
/* Data type for key value used in System V IPC functions. */
typedef long int key_t;
#endif
#ifdef __USE_BSD
#define FD_SETSIZE __FD_SETSIZE

View File

@ -419,6 +419,11 @@ extern __pid_t vfork __P ((void));
/* Return the pathname of the terminal FD is open on, or NULL on errors.
The returned storage is good only until the next call to this function. */
extern char *ttyname __P ((int __fd));
#ifdef __USE_REENTRANT
/* Store at most BUFLEN characters of the pathname of the terminal FD is
open on in BUF. Return 0 on success, -1 otherwise. */
extern int ttyname_r __P ((int __fd, char *__buf, int __buflen));
#endif
/* Return 1 if FD is a valid descriptor associated
with a terminal, zero if not. */

1
search.h Normal file
View File

@ -0,0 +1 @@
#include <misc/search.h>

View File

@ -20,7 +20,7 @@ Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <errno.h>
extern char *_strerror_internal __P ((int, char buf[1024]));
extern char *_strerror_internal __P ((int, char *buf, size_t));
/* Print a line on stderr consisting of the text in S, a colon, a space,
a message describing the meaning of the contents of `errno' and a newline.
@ -38,5 +38,5 @@ DEFUN(perror, (s), register CONST char *s)
colon = ": ";
(void) fprintf (stderr, "%s%s%s\n",
s, colon, _strerror_internal (errnum, buf));
s, colon, _strerror_internal (errnum, buf, sizeof buf));
}

View File

@ -534,7 +534,7 @@ vfprintf (s, format, ap)
else if (specs[cnt].info.prec != -1)
{
/* Search for the end of the string, but don't search
past the length specified by the precision. */
past the length specified by the precision. */
const char *end = memchr (str, '\0', specs[cnt].info.prec);
if (end)
len = end - str;
@ -600,8 +600,8 @@ vfprintf (s, format, ap)
case 'm':
{
extern char *_strerror_internal __P ((int, char buf[1024]));
str = _strerror_internal (errno, errorbuf);
extern char *_strerror_internal __P ((int, char *buf, size_t));
str = _strerror_internal (errno, errorbuf, sizeof errorbuf);
goto string;
}

View File

@ -32,10 +32,16 @@ routines := \
abs labs \
div ldiv \
mblen mbstowcs mbtowc wcstombs wctomb \
random rand \
random random_r rand \
drand48 erand48 lrand48 nrand48 mrand48 jrand48 \
srand48 seed48 lcong48 \
drand48_r erand48_r lrand48_r nrand48_r mrand48_r jrand48_r \
srand48_r seed48_r lcong48_r \
drand48-iter \
strtol strtoul strtoq strtouq \
strtof strtod strtold \
system
system \
a64l l64a
distribute := exit.h grouping.h
tests := tst-strtol tst-strtod testmb testrand testsort testdiv

54
stdlib/a64l.c Normal file
View File

@ -0,0 +1,54 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
long
a64l (string)
const char *string;
{
int cnt;
long result = 0l;
for (cnt = 0; cnt < 6; ++cnt)
{
result <<= 6;
switch (string[cnt])
{
case '.':
break;
case '/':
result |= 1;
break;
case '0' ... '9':
result |= 2 + string[cnt] - '0';
break;
case 'A' ... 'Z':
result |= 12 + string[cnt] - 'A';
break;
case 'a' ... 'z':
result |= 38 + string[cnt] - 'a';
break;
default:
return result >> 6;
}
}
return result;
}

102
stdlib/drand48-iter.c Normal file
View File

@ -0,0 +1,102 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <stdlib.h>
/* Global state for non-reentrent functions. */
struct drand48_data __libc_drand48_data;
int
__drand48_iterate (xsubi, buffer)
unsigned short int xsubi[3];
struct drand48_data *buffer;
{
/* Be generous for the arguments, detect some errors. */
if (xsubi == NULL || buffer == NULL)
{
errno = EFAULT;
return -1;
}
/* Initialize buffer, if not yet done. */
if (!buffer->init)
{
if (sizeof (unsigned short int) == 2)
{
buffer->a[2] = 0x5;
buffer->a[1] = 0xdeec;
buffer->a[0] = 0xe66d;
}
else
{
buffer->a[2] = 0x5deec;
buffer->a[1] = 0xe66d0000;
buffer->a[0] = 0;
}
buffer->c = 0xb;
buffer->init = 1;
}
/* Do the real work. We choose a data type which contains at least
48 bits. Because we compute the modulus it does not care how
many bits really are computed. */
if (sizeof (long int) >= 6)
{
/* The `long' data type is sufficent. */
unsigned long int X, a, result;
#define ONE_STEP \
if (sizeof (unsigned short int) == 2) \
{ \
X = (xsubi[2] << 16 | xsubi[1]) << 16 | xsubi[0]; \
a = (buffer->a[2] << 16 | buffer->a[1]) << 16 | buffer->a[0]; \
\
result = X * a + buffer->c; \
\
xsubi[0] = result & 0xffff; \
result >>= 16; \
xsubi[1] = result & 0xffff; \
result >>= 16; \
xsubi[2] = result & 0xffff; \
} \
else \
{ \
X = xsubi[2] << 16 | xsubi[1] >> 16; \
a = buffer->a[2] << 16 | buffer->a[1] >> 16; \
\
result = X * a + buffer->c; \
\
xsubi[0] = result >> 16 & 0xffffffffl; \
xsubi[1] = result << 16 & 0xffff0000l; \
}
ONE_STEP;
}
else
{
/* We have to use the `long long' data type. */
unsigned long long int X, a, result;
ONE_STEP;
}
return 0;
}

33
stdlib/drand48.c Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
double
drand48 ()
{
double result;
(void) erand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
return result;
}

37
stdlib/drand48_r.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <math.h>
#include <stdlib.h>
int
drand48_r (buffer, result)
struct drand48_data *buffer;
double *result;
{
/* be generous for the arguments, detect some errors. */
if (buffer == NULL)
{
errno = EFAULT;
return -1;
}
return erand48_r (buffer->X, buffer, result);
}

34
stdlib/erand48.c Normal file
View File

@ -0,0 +1,34 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
double
erand48 (xsubi)
unsigned short int xsubi[3];
{
double result;
(void) erand48_r (xsubi, &__libc_drand48_data, &result);
return result;
}

52
stdlib/erand48_r.c Normal file
View File

@ -0,0 +1,52 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <errno.h>
#include <math.h>
#include <stdlib.h>
int
erand48_r (xsubi, buffer, result)
unsigned short int xsubi[3];
struct drand48_data *buffer;
double *result;
{
int i;
/* Be generous for the arguments, detect some errors. */
if (result == NULL)
{
errno = EFAULT;
return -1;
}
/* Compute next state. */
if (__drand48_iterate (xsubi, buffer) < 0)
return -1;
*result = 0.0;
for (i = 4 / sizeof (unsigned short int); i >= 0; --i)
{
double factor = ldexp (1.0, (i - 6) * sizeof (unsigned short int));
*result += factor * (double) xsubi[i];
}
return 0;
}

34
stdlib/jrand48.c Normal file
View File

@ -0,0 +1,34 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
long
jrand48 (xsubi)
unsigned short int xsubi[3];
{
long result;
(void) jrand48_r (xsubi, &__libc_drand48_data, &result);
return result;
}

49
stdlib/jrand48_r.c Normal file
View File

@ -0,0 +1,49 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
jrand48_r (xsubi, buffer, result)
unsigned short int xsubi[3];
struct drand48_data *buffer;
long *result;
{
/* Be generous for the arguments, detect some errors. */
if (result == NULL)
{
errno = EFAULT;
return -1;
}
/* Compute next state. */
if (__drand48_iterate (xsubi, buffer) < 0)
return -1;
/* Store the result. */
if (sizeof (unsigned short int) == 2)
*result = (xsubi[2] & 0x7fff) | xsubi[1];
else
*result = xsubi[2] & 0x7fffffffl;
if (xsubi[2] & (1 << (sizeof (xsubi[2]) * 8 - 1)))
*result *= -1;
return 0;
}

51
stdlib/l64a.c Normal file
View File

@ -0,0 +1,51 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Conversion table. */
static const char conv_tab[64] =
{
'.', '/', '0', '1', '2', '3', '4', '5',
'6', '7', '8', '9', 'A', 'B', 'C', 'D',
'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L',
'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b',
'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
};
const char *
l64a (n)
long n;
{
static char result[7];
int cnt;
result[6] = '\0';
for (cnt = 5; cnt >= 0; --cnt)
{
result[cnt] = n & 0x3f;
n >>= 6;
}
return result;
}

30
stdlib/lcong48.c Normal file
View File

@ -0,0 +1,30 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
void
lcong48 (param)
unsigned short int param[7];
{
(void) lcong48_r (param, &__libc_drand48_data);
}

41
stdlib/lcong48_r.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
lcong48_r (param, buffer)
unsigned short int param[7];
struct drand48_data *buffer;
{
/* Be generous for the arguments, detect some errors. */
if (buffer == NULL)
{
errno = EFAULT;
return -1;
}
/* Store the given values. */
memcpy (buffer->X, &param[0], sizeof (buffer->X));
memcpy (buffer->a, &param[3], sizeof (buffer->a));
buffer->c = param[6];
buffer->init = 1;
return 0;
}

33
stdlib/lrand48.c Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
long
lrand48 ()
{
long result;
(void) nrand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
return result;
}

32
stdlib/lrand48_r.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
lrand48_r (buffer, result)
struct drand48_data *buffer;
long *result;
{
/* Be generous for the arguments, detect some errors. */
if (buffer == NULL)
return -1;
return nrand48_r (buffer->X, buffer, result);
}

33
stdlib/mrand48.c Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
long
mrand48 ()
{
long result;
(void) jrand48_r (__libc_drand48_data.X, &__libc_drand48_data, &result);
return result;
}

32
stdlib/mrand48_r.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
mrand48_r (buffer, result)
struct drand48_data *buffer;
long *result;
{
/* Be generous for the arguments, detect some errors. */
if (buffer == NULL)
return -1;
return jrand48_r (buffer->X, buffer, result);
}

34
stdlib/nrand48.c Normal file
View File

@ -0,0 +1,34 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
long
nrand48 (xsubi)
unsigned short int xsubi[3];
{
long result;
(void) nrand48_r (xsubi, &__libc_drand48_data, &result);
return result;
}

46
stdlib/nrand48_r.c Normal file
View File

@ -0,0 +1,46 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
nrand48_r (xsubi, buffer, result)
unsigned short int xsubi[3];
struct drand48_data *buffer;
long *result;
{
/* Be generous for the arguments, detect some errors. */
if (result == NULL)
{
errno = EFAULT;
return -1;
}
/* Compute next state. */
if (__drand48_iterate (xsubi, buffer) < 0)
return -1;
/* Store the result. */
if (sizeof (unsigned short int) == 2)
*result = xsubi[2] << 15 | xsubi[1] >> 1;
else
*result = xsubi[2] >> 1;
return 0;
}

View File

@ -19,10 +19,9 @@
* This is derived from the Berkeley source:
* @(#)random.c 5.5 (Berkeley) 7/6/88
* It was reworked for the GNU C Library by Roland McGrath.
* Rewritten to use reentrent functions by Ulrich Drepper, 1995.
*/
#include <ansidecl.h>
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
@ -105,10 +104,6 @@
#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);
@ -132,6 +127,9 @@ static long int randtbl[DEG_3 + 1] =
-205601318,
};
static struct random_data unsafe_state =
{
/* 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 through the state information. (Yes, this does mean we could get
@ -142,10 +140,8 @@ static long int randtbl[DEG_3 + 1] =
in the initialization of randtbl) because the state table pointer is set
to point to randtbl[1] (as explained below).) */
static long int *fptr = &randtbl[SEP_3 + 1];
static long int *rptr = &randtbl[1];
fptr : &randtbl[SEP_3 + 1],
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
@ -157,13 +153,14 @@ static long int *rptr = &randtbl[1];
indexing every time to find the address of the last element to see if
the front and rear pointers have wrapped. */
static long int *state = &randtbl[1];
state : &randtbl[1],
static int rand_type = TYPE_3;
static int rand_deg = DEG_3;
static int rand_sep = SEP_3;
rand_type : TYPE_3,
rand_deg : DEG_3,
rand_sep : SEP_3,
static long int *end_ptr = &randtbl[sizeof(randtbl) / sizeof(randtbl[0])];
end_ptr : &randtbl[sizeof (randtbl) / sizeof (randtbl[0])]
};
/* Initialize the random number generator based on the given seed. If the
type is the trivial no-state-information type, just remember the seed.
@ -174,27 +171,10 @@ static long int *end_ptr = &randtbl[sizeof(randtbl) / sizeof(randtbl[0])];
introduced by the L.C.R.N.G. Note that the initialization of randtbl[]
for default usage relies on values produced by this routine. */
void
DEFUN(__srandom, (x), unsigned int x)
__srandom (x)
unsigned int x;
{
state[0] = x;
if (rand_type != TYPE_0)
{
register long int i;
for (i = 1; i < rand_deg; ++i)
{
/* This does:
state[i] = (16807 * state[i - 1]) % 2147483647;
but avoids overflowing 31 bits. */
long int hi = state[i - 1] / 127773;
long int lo = state[i - 1] % 127773;
long int test = 16807 * lo - 2836 * hi;
state[i] = test + (test < 0 ? 2147483647 : 0);
}
fptr = &state[rand_sep];
rptr = &state[0];
for (i = 0; i < 10 * rand_deg; ++i)
(void) __random ();
}
(void) __srandom_r (x, &unsafe_state);
}
weak_alias (__srandom, srandom)
@ -211,60 +191,15 @@ weak_alias (__srandom, srand)
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. */
PTR
DEFUN(__initstate, (seed, arg_state, n),
unsigned int seed AND PTR arg_state AND size_t n)
void *
__initstate (seed, arg_state, n)
unsigned int seed;
void *arg_state;
size_t n;
{
PTR ostate = (PTR) &state[-1];
void *ostate = (void *) &unsafe_state.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)
{
errno = EINVAL;
return NULL;
}
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 int *) arg_state)[1]; /* First location. */
/* Must set END_PTR before srandom. */
end_ptr = &state[rand_deg];
__srandom(seed);
if (rand_type == TYPE_0)
state[-1] = rand_type;
else
state[-1] = (MAX_TYPES * (rptr - state)) + rand_type;
__initstate_r (seed, arg_state, n, &unsafe_state);
return ostate;
}
@ -279,44 +214,14 @@ weak_alias (__initstate, initstate)
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. */
PTR
DEFUN(__setstate, (arg_state), PTR arg_state)
void *
__setstate (arg_state)
void *arg_state;
{
register long int *new_state = (long int *) arg_state;
register int type = new_state[0] % MAX_TYPES;
register int rear = new_state[0] / MAX_TYPES;
PTR ostate = (PTR) &state[-1];
void *ostate = (void *) &unsafe_state.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;
default:
/* State info munged. */
errno = EINVAL;
return NULL;
}
state = &new_state[1];
if (rand_type != TYPE_0)
{
rptr = &state[rear];
fptr = &state[(rear + rand_sep) % rand_deg];
}
/* Set end_ptr too. */
end_ptr = &state[rand_deg];
if (__setstate_r (arg_state, &unsafe_state) < 0)
return NULL;
return ostate;
}
@ -335,33 +240,13 @@ weak_alias (__setstate, setstate)
pointer if the front one has wrapped. Returns a 31-bit random number. */
long int
DEFUN_VOID(__random)
__random ()
{
if (rand_type == TYPE_0)
{
state[0] = ((state[0] * 1103515245) + 12345) & LONG_MAX;
return state[0];
}
else
{
long int i;
*fptr += *rptr;
/* Chucking least random bit. */
i = (*fptr >> 1) & LONG_MAX;
++fptr;
if (fptr >= end_ptr)
{
fptr = state;
++rptr;
}
else
{
++rptr;
if (rptr >= end_ptr)
rptr = state;
}
return i;
}
long int retval;
(void) __random_r (&unsafe_state, &retval);
return retval;
}
weak_alias (__random, random)

337
stdlib/random_r.c Normal file
View File

@ -0,0 +1,337 @@
/*
* Copyright (c) 1983 Regents of the University of California.
* All rights reserved.
*
* Redistribution and use in source and binary forms are permitted
* provided that the above copyright notice and this paragraph are
* duplicated in all such forms and that any documentation,
* advertising materials, and other materials related to such
* distribution and use acknowledge that the software was developed
* by the University of California, Berkeley. The name of the
* University may not 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 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*/
/*
* This is derived from the Berkeley source:
* @(#)random.c 5.5 (Berkeley) 7/6/88
* It was reworked for the GNU C Library by Roland McGrath.
* Rewritten to be reentrent by Ulrich Drepper, 1995
*/
#include <errno.h>
#include <limits.h>
#include <stddef.h>
#include <stdlib.h>
/* 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() function 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 thi
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
separation between the two lower order coefficients of the trinomial. */
/* Linear congruential. */
#define TYPE_0 0
#define BREAK_0 8
#define DEG_0 0
#define SEP_0 0
/* x**7 + x**3 + 1. */
#define TYPE_1 1
#define BREAK_1 32
#define DEG_1 7
#define SEP_1 3
/* x**15 + x + 1. */
#define TYPE_2 2
#define BREAK_2 64
#define DEG_2 15
#define SEP_2 1
/* x**31 + x**3 + 1. */
#define TYPE_3 3
#define BREAK_3 128
#define DEG_3 31
#define SEP_3 3
/* x**63 + x + 1. */
#define TYPE_4 4
#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 const int degrees[MAX_TYPES] = { DEG_0, DEG_1, DEG_2, DEG_3, DEG_4 };
static const int seps[MAX_TYPES] = { SEP_0, SEP_1, SEP_2, SEP_3, SEP_4 };
/* 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_r (x, buf)
unsigned int x;
struct random_data *buf;
{
if (buf == NULL || buf->rand_type < TYPE_0 || buf->rand_type > TYPE_4)
return -1;
buf->state[0] = x;
if (buf->rand_type != TYPE_0)
{
long int i;
for (i = 1; i < buf->rand_deg; ++i)
{
/* This does:
state[i] = (16807 * state[i - 1]) % 2147483647;
but avoids overflowing 31 bits. */
long int hi = buf->state[i - 1] / 127773;
long int lo = buf->state[i - 1] % 127773;
long int test = 16807 * lo - 2836 * hi;
buf->state[i] = test + (test < 0 ? 2147483647 : 0);
}
buf->fptr = &buf->state[buf->rand_sep];
buf->rptr = &buf->state[0];
for (i = 0; i < 10 * buf->rand_deg; ++i)
{
long int discard;
(void) __random_r (buf, &discard);
}
}
return 0;
}
weak_alias (__srandom_r, srandom_r)
weak_alias (__srandom_r, srand_r)
/* 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. */
int
__initstate_r (seed, arg_state, n, buf)
unsigned int seed;
void *arg_state;
size_t n;
struct random_data *buf;
{
if (buf == NULL)
return -1;
if (buf->rand_type == TYPE_0)
buf->state[-1] = buf->rand_type;
else
buf->state[-1] = (MAX_TYPES * (buf->rptr - buf->state)) + buf->rand_type;
if (n < BREAK_1)
{
if (n < BREAK_0)
{
errno = EINVAL;
return -1;
}
buf->rand_type = TYPE_0;
buf->rand_deg = DEG_0;
buf->rand_sep = SEP_0;
}
else if (n < BREAK_2)
{
buf->rand_type = TYPE_1;
buf->rand_deg = DEG_1;
buf->rand_sep = SEP_1;
}
else if (n < BREAK_3)
{
buf->rand_type = TYPE_2;
buf->rand_deg = DEG_2;
buf->rand_sep = SEP_2;
}
else if (n < BREAK_4)
{
buf->rand_type = TYPE_3;
buf->rand_deg = DEG_3;
buf->rand_sep = SEP_3;
}
else
{
buf->rand_type = TYPE_4;
buf->rand_deg = DEG_4;
buf->rand_sep = SEP_4;
}
buf->state = &((long int *) arg_state)[1]; /* First location. */
/* Must set END_PTR before srandom. */
buf->end_ptr = &buf->state[buf->rand_deg];
__srandom_r (seed, buf);
if (buf->rand_type == TYPE_0)
buf->state[-1] = buf->rand_type;
else
buf->state[-1] = (MAX_TYPES * (buf->rptr - buf->state)) + buf->rand_type;
return 0;
}
weak_alias (__initstate_r, initstate_r)
/* 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. */
int
__setstate_r (arg_state, buf)
void *arg_state;
struct random_data *buf;
{
long int *new_state = (long int *) arg_state;
int type = new_state[0] % MAX_TYPES;
int rear = new_state[0] / MAX_TYPES;
if (buf == NULL)
return -1;
if (buf->rand_type == TYPE_0)
buf->state[-1] = buf->rand_type;
else
buf->state[-1] = (MAX_TYPES * (buf->rptr - buf->state)) + buf->rand_type;
switch (type)
{
case TYPE_0:
case TYPE_1:
case TYPE_2:
case TYPE_3:
case TYPE_4:
buf->rand_type = type;
buf->rand_deg = degrees[type];
buf->rand_sep = seps[type];
break;
default:
/* State info munged. */
errno = EINVAL;
return -1;
}
buf->state = &new_state[1];
if (buf->rand_type != TYPE_0)
{
buf->rptr = &buf->state[rear];
buf->fptr = &buf->state[(rear + buf->rand_sep) % buf->rand_deg];
}
/* Set end_ptr too. */
buf->end_ptr = &buf->state[buf->rand_deg];
return 0;
}
weak_alias (__setstate_r, setstate_r)
/* 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. */
int
__random_r (buf, result)
struct random_data *buf;
long int *result;
{
if (buf == NULL || result == NULL)
return -1;
if (buf->rand_type == TYPE_0)
{
buf->state[0] = ((buf->state[0] * 1103515245) + 12345) & LONG_MAX;
*result = buf->state[0];
}
else
{
*buf->fptr += *buf->rptr;
/* Chucking least random bit. */
*result = (*buf->fptr >> 1) & LONG_MAX;
++buf->fptr;
if (buf->fptr >= buf->end_ptr)
{
buf->fptr = buf->state;
++buf->rptr;
}
else
{
++buf->rptr;
if (buf->rptr >= buf->end_ptr)
buf->rptr = buf->state;
}
}
return 0;
}
weak_alias (__random_r, random_r)

32
stdlib/seed48.c Normal file
View File

@ -0,0 +1,32 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
unsigned short int *
seed48 (seed16v)
unsigned short int seed16v[3];
{
(void) seed48_r (seed16v, &__libc_drand48_data);
return __libc_drand48_data.old_X;
}

41
stdlib/seed48_r.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
seed48_r (seed16v, buffer)
unsigned short int seed16v[3];
struct drand48_data *buffer;
{
/* Be generous for the arguments, detect some errors. */
if (buffer == NULL)
{
errno = EFAULT;
return -1;
}
/* Save old value at a private place to be used as return value. */
memcpy (buffer->old_X, buffer->X, sizeof (buffer->X));
/* Install new state. */
memcpy (buffer->X, seed16v, sizeof (buffer->X));
return 0;
}

30
stdlib/srand48.c Normal file
View File

@ -0,0 +1,30 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
/* Global state for non-reentrent functions. Defined in drand48-iter.c. */
extern struct drand48_data __libc_drand48_data;
void
srand48 (seedval)
long seedval;
{
(void) srand48_r (seedval, &__libc_drand48_data);
}

52
stdlib/srand48_r.c Normal file
View File

@ -0,0 +1,52 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdlib.h>
int
srand48_r (seedval, buffer)
long seedval;
struct drand48_data *buffer;
{
/* Be generous for the arguments, detect some errors. */
if (buffer == NULL)
{
errno = EFAULT;
return -1;
}
/* The standards say we only have 32 bits. */
if (sizeof (long) > 4)
seedval &= 0xffffffffl;
if (sizeof (unsigned short int) == 2)
{
buffer->X[2] = seedval >> 16;
buffer->X[1] = seedval & 0xffffl;
buffer->X[0] = 0x330e;
}
else
{
buffer->X[2] = seedval;
buffer->X[1] = 0x330e0000;
buffer->X[0] = 0;
}
return 0;
}

View File

@ -198,7 +198,83 @@ extern __inline __ptr_t initstate (unsigned int __seed,
extern __inline __ptr_t setstate (__ptr_t __statebuf)
{ return __setstate (__statebuf); }
#endif /* Optimizing GCC >=2. */
#endif /* Use BSD. */
#ifdef __USE_REENTRANT
/* Reentrant versions of the `random' family of functions.
These functions all use the following data structure to contain
state, rather than global state variables. */
struct random_data
{
long int *fptr; /* Front pointer. */
long int *rptr; /* Rear pointer. */
long int *state; /* Array of state values. */
int rand_type; /* Type of random number generator. */
int rand_deg; /* Degree of random number generator. */
int rand_sep; /* Distance between front and rear. */
long int *end_ptr; /* Pointer behind state table. */
};
extern int __random_r __P ((struct random_data *__buf, long int *__result));
extern int __srandom_r __P ((unsigned int __seed, struct random_data *__buf));
extern int __initstate_r __P ((unsigned int __seed, __ptr_t __statebuf,
size_t __statelen, struct random_data *__buf));
extern int __setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf));
extern int random_r __P ((struct random_data *__buf, long int *__result));
extern int srandom_r __P ((unsigned int __seed, struct random_data *__buf));
extern int initstate_r __P ((unsigned int __seed, __ptr_t __statebuf,
size_t __statelen, struct random_data *__buf));
extern int setstate_r __P ((__ptr_t __statebuf, struct random_data *__buf));
#endif /* __USE_REENTRANT. */
#endif /* Use BSD. */
#ifdef __USE_SVID
/* System V style 48-bit random number generator functions. */
/* Data structure for communication with thread safe versions. */
struct drand48_data
{
unsigned short int X[3]; /* Current state. */
unsigned short int a[3]; /* Factor in congruential formula. */
unsigned short int c; /* Additive const. in congruential formula. */
unsigned short int old_X[3]; /* Old state. */
int init; /* Flag for initializing. */
};
/* Return non-negative, double-precision floating-point value in [0.0,1.0). */
extern double drand48 __P ((void));
extern int drand48_r __P ((struct drand48_data *__buffer, double *__result));
extern double erand48 __P ((unsigned short int __xsubi[3]));
extern int erand48_r __P ((unsigned short int __xsubi[3],
struct drand48_data *__buffer, double *__result));
/* Return non-negative, long integer in [0,2^31). */
extern long lrand48 __P ((void));
extern int lrand48_r __P ((struct drand48_data *__buffer, long *__result));
extern long nrand48 __P ((unsigned short int __xsubi[3]));
extern int nrand48_r __P ((unsigned short int __xsubi[3],
struct drand48_data *__buffer, long *__result));
/* Return signed, long integers in [-2^31,2^31). */
extern long mrand48 __P ((void));
extern int mrand48_r __P ((struct drand48_data *__buffer, long *__result));
extern long jrand48 __P ((unsigned short int __xsubi[3]));
extern int jrand48_r __P ((unsigned short int __xsubi[3],
struct drand48_data *__buffer, long *__result));
/* Seed random number generator. */
extern void srand48 __P ((long __seedval));
extern int srand48_r __P ((long __seedval, struct drand48_data *__buffer));
extern unsigned short int *seed48 __P ((unsigned short int __seed16v[3]));
extern int seed48_r __P ((unsigned short int __seed16v[3],
struct drand48_data *__buffer));
extern void lcong48 __P ((unsigned short int __param[7]));
extern int lcong48_r __P ((unsigned short int __param[7],
struct drand48_data *__buffer));
/* Internal function to compute next state of the generator. */
extern int __drand48_iterate __P ((unsigned short int __xsubi[3],
struct drand48_data *__buffer));
#endif /* __USE_SVID. */
/* Allocate SIZE bytes of memory. */
@ -268,7 +344,10 @@ extern int system __P ((__const char *__command));
/* Shorthand for type of comparison functions. */
#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
#endif
#ifdef __USE_GNU
typedef __compar_fn_t comparison_fn_t;
@ -308,6 +387,34 @@ extern __CONSTVALUE div_t div __P ((int __numer, int __denom));
extern __CONSTVALUE ldiv_t ldiv __P ((long int __numer, long int __denom));
#ifdef __USE_SVID
/* Convert floating point numbers to strings. The returned values are
valid only until another call to the same function. */
/* Convert VALUE to a string with NDIGIT digits and return a pointer to
this. Set *DECPT with the position of the decimal character and *SIGN
with the sign of the number. */
char *ecvt __P ((double __value, int __ndigit, int *__decpt, int *sign));
/* Convert VALUE to a string rounded to NDIGIT decimal digits. Set *DECPT
with the position of the decimal character and *SIGN with the sign of
the number. */
char *fcvt __P ((double __value, int __ndigit, int *__decpt, int *sign));
/* If possible convert VALUE to a string with NDIGIT significant digits.
Otherwise use exponential representation. The resulting string will
be written to BUF. */
char *gcvt __P ((double __value, int __ndigit, char *__buf));
/* Reentrant version of the functions above which provide their own
buffers. */
int ecvt_r __P ((double __value, int __ndigit, int *__decpt, int *sign,
char *__buf, int *__len));
int fcvt_r __P ((double __value, int __ndigit, int *__decpt, int *sign,
char *__buf, int *__len));
#endif
/* Return the length of the multibyte character
in S, which is no longer than N. */
extern int mblen __P ((__const char *__s, size_t __n));

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1993, 1994 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1993, 1994, 1995 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
@ -13,21 +13,21 @@ 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. */
not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <ansidecl.h>
#include <stdio.h>
#include <string.h>
extern char *_strerror_internal __P ((int, char buf[1024]));
extern char *_strerror_internal __P ((int, char *, size_t));
/* Return a string descibing the errno code in ERRNUM.
The storage is good only until the next call to strerror.
Writing to the storage causes undefined behavior. */
char *
DEFUN(strerror, (errnum), int errnum)
strerror (errnum)
int errnum;
{
static char buf[1024];
return _strerror_internal (errnum, buf);
return _strerror_internal (errnum, buf, sizeof buf);
}

30
string/strerror_r.c Normal file
View File

@ -0,0 +1,30 @@
/* Copyright (C) 1991, 1993, 1994, 1995 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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <stdio.h>
#include <string.h>
extern char *_strerror_internal __P ((int, char *, size_t));
/* Return a string descibing the errno code in ERRNUM. At most BUFLEN
characters of the result will be placed in STRERRBUF. */
char *
strerror_r (int errnum, char *buf, size_t buflen)
{
return _strerror_internal (errnum, buf, buflen);
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992, 1993 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1992, 1993, 1995 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
@ -120,8 +120,13 @@ extern __ptr_t memmem __P ((__const __ptr_t __haystack, size_t __haystacklen,
/* Return the length of S. */
extern size_t strlen __P ((__const char *__s));
/* Return a string describing the meaning of the errno code in ERRNUM. */
/* Return a string describing the meaning of the `errno' code in ERRNUM. */
extern char *strerror __P ((int __errnum));
#ifdef __USE_REENTRANT
/* Reentrant version of `strerror'. If a temporary buffer is required, at
most BUFLEN bytes of BUF will be used. */
extern char *strerror_r __P ((int __errnum, char *__buf, int __buflen));
#endif
#ifdef __USE_BSD
/* Find the first occurrence of C in S (same as strchr). */

View File

@ -1,4 +1,4 @@
/* Copyright (C) 19911993 Free Software Foundation, Inc.
/* Copyright (C) 1991, 1993, 1995 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
@ -16,7 +16,6 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stdio.h>
#include <string.h>
@ -27,13 +26,16 @@ Cambridge, MA 02139, USA. */
/* Return a string describing the errno code in ERRNUM. */
char *
DEFUN(_strerror_internal, (errnum, buf), int errnum AND char buf[1024])
_strerror_internal (errnum, buf, buflen)
int errnum;
char *buf;
size_t buflen;
{
if (errnum < 0 || errnum > _sys_nerr)
{
static char fmt[] = "Unknown error %d";
size_t len = sprintf (buf, fmt, errnum);
if (len < sizeof(fmt) - 2)
size_t len = snprintf (buf, buflen, fmt, errnum);
if (len < sizeof (fmt) - 2)
return NULL;
buf[len - 1] = '\0';
return buf;

View File

@ -26,6 +26,7 @@ Cambridge, MA 02139, USA. */
extern int _dl_argc;
extern char **_dl_argv;
extern char **_environ;
extern void _start (void);
Elf32_Addr
_dl_sysdep_start (void **start_argptr,
@ -39,6 +40,7 @@ _dl_sysdep_start (void **start_argptr,
uid_t uid, euid;
gid_t gid, egid;
user_entry = (Elf32_Addr) &_start;
_dl_argc = *(int *) start_argptr;
_dl_argv = start_argptr + 1;
_environ = &_dl_argv[_dl_argc + 1];
@ -57,6 +59,7 @@ _dl_sysdep_start (void **start_argptr,
break;
case AT_ENTRY:
user_entry = av->a_un.a_val;
break;
case AT_UID:
uid = av->a_un.a_val;
break;

View File

@ -1,4 +1,4 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
/* Copyright (C) 1994 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
@ -16,41 +16,102 @@ License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
/*
* My personal strstr() implementation that beats most other algorithms.
* Until someone tells me otherwise, I assume that this is the
* fastest implementation of strstr() in C.
* I deliberately chose not to comment it. You should have at least
* as much fun trying to understand it, as I had to write it :-).
*
* Stephen R. van den Berg, berg@pool.informatik.rwth-aachen.de */
#include <string.h>
#include <sys/types.h>
typedef unsigned chartype;
/* Return the first ocurrence of NEEDLE in HAYSTACK. */
char *
DEFUN(strstr, (haystack, needle),
CONST char *CONST haystack AND
CONST char *CONST needle)
strstr (phaystack, pneedle)
const char *phaystack;
const char *pneedle;
{
register CONST char *CONST needle_end = strchr(needle, '\0');
register CONST char *CONST haystack_end = strchr(haystack, '\0');
register CONST size_t needle_len = needle_end - needle;
register CONST size_t needle_last = needle_len - 1;
register CONST char *begin;
register const unsigned char *haystack, *needle;
register chartype b, c;
if (needle_len == 0)
return (char *) haystack; /* ANSI 4.11.5.7, line 25. */
if ((size_t) (haystack_end - haystack) < needle_len)
return NULL;
haystack = (const unsigned char *) phaystack;
needle = (const unsigned char *) pneedle;
for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
b = *needle;
if (b != '\0')
{
register CONST char *n = &needle[needle_last];
register CONST char *h = begin;
haystack--; /* possible ANSI violation */
do
if (*h != *n)
goto loop; /* continue for loop */
while (--n >= needle && --h >= haystack);
{
c = *++haystack;
if (c == '\0')
goto ret0;
}
while (c != b);
return (char *) h;
c = *++needle;
if (c == '\0')
goto foundneedle;
++needle;
goto jin;
loop:;
for (;;)
{
register chartype a;
register const unsigned char *rhaystack, *rneedle;
do
{
a = *++haystack;
if (a == '\0')
goto ret0;
if (a == b)
break;
a = *++haystack;
if (a == '\0')
goto ret0;
shloop: }
while (a != b);
jin: a = *++haystack;
if (a == '\0')
goto ret0;
if (a != c)
goto shloop;
rhaystack = haystack-- + 1;
rneedle = needle;
a = *rneedle;
if (*rhaystack == a)
do
{
if (a == '\0')
goto foundneedle;
++rhaystack;
a = *++needle;
if (*rhaystack != a)
break;
if (a == '\0')
goto foundneedle;
++rhaystack;
a = *++needle;
}
while (*rhaystack == a);
needle = rneedle; /* took the register-poor aproach */
if (a == '\0')
break;
}
}
return NULL;
foundneedle:
return (char*) haystack;
ret0:
return 0;
}

View File

@ -24,7 +24,7 @@ Cambridge, MA 02139, USA. */
/* Return a string describing the errno code in ERRNUM. */
char *
_strerror_internal (int errnum, char buf[1024])
_strerror_internal (int errnum, char *buf, size_t buflen)
{
int system;
int sub;
@ -41,7 +41,7 @@ _strerror_internal (int errnum, char buf[1024])
if (system > err_max_system || ! __mach_error_systems[system].bad_sub)
{
static const char unk[] = "Error in unknown error system: ";
char *p = buf + sizeof buf;
char *p = buf + buflen;
*p-- = '\0';
p = _itoa (errnum, p, 16, 1);
p -= sizeof unk - 1;
@ -56,7 +56,7 @@ _strerror_internal (int errnum, char buf[1024])
if (code >= es->subsystem[sub].max_code)
{
static const char unk[] = "Unknown error ";
char *p = buf + sizeof buf;
char *p = buf + buflen;
size_t len = strlen (es->subsystem[sub].subsys_name);
*p-- = '\0';
p = _itoa (errnum, p, 16, 1);

View File

@ -0,0 +1,49 @@
/* Copyright (C) 1994, 1995 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 <errno.h>
#include <string.h>
#include <unistd.h>
#include <hurd.h>
#include <hurd/term.h>
#include <hurd/fd.h>
/* Store at most BUFLEN characters of the pathname of the terminal FD is
open on in BUF. Return 0 on success, -1 otherwise. */
int
ttyname_r (int fd, char *buf, int buflen)
{
error_t err;
char nodename[1024]; /* XXX */
char *cp;
int len;
nodename[0] = '\0';
if (err = HURD_DPORT_USE (fd, __term_get_nodename (port, nodename)))
return __hurd_dfail (fd, err), -1;
len = (int) strlen (nodename) + 1;
if (len > buflen)
{
errno = EINVAL;
return -1;
}
memcpy (buf, nodename, len);
return 0;
}

View File

@ -52,7 +52,11 @@ DEFUN(__sysconf, (name), int name)
#endif
case _SC_CLK_TCK:
#ifdef CLK_TCK
return CLK_TCK;
#else
return 60;
#endif
case _SC_NGROUPS_MAX:
#ifdef NGROUPS_MAX
@ -65,7 +69,11 @@ DEFUN(__sysconf, (name), int name)
return __getdtablesize ();
case _SC_STREAM_MAX:
#ifdef STREAM_MAX
return STREAM_MAX;
#else
return FOPEN_MAX;
#endif
case _SC_TZNAME_MAX:
return __tzname_max ();
@ -171,6 +179,13 @@ DEFUN(__sysconf, (name), int name)
return -1;
#endif
case _SC_2_LOCALEDEF:
#ifdef _POSIX2_LOCALEDEF
return _POSIX2_LOCALEDEF;
#else
return -1;
#endif
case _SC_2_SW_DEV:
#ifdef _POSIX2_SW_DEV
return _POSIX2_SW_DEV;

91
sysdeps/posix/ttyname_r.c Normal file
View File

@ -0,0 +1,91 @@
/* Copyright (C) 1991, 1992, 1993, 1995 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 <errno.h>
#include <limits.h>
#include <stddef.h>
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
#ifndef MIN
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
/* Store at most BUFLEN character of the pathname of the terminal FD is
open on in BUF. Return 0 on success, -1 otherwise. */
int
ttyname_r (fd, buf, buflen)
int fd;
char *buf;
int buflen;
{
static const char dev[] = "/dev";
struct stat st;
dev_t mydev;
ino_t myino;
DIR *dirstream;
struct dirent *d;
int save = errno;
/* Test for the absolute minimal size. This makes life easier inside
the loop. */
if (buflen < sizeof (dev) + 2)
{
errno = EINVAL;
return -1;
}
if (fstat (fd, &st) < 0)
return -1;
mydev = st.st_dev;
myino = st.st_ino;
dirstream = opendir (dev);
if (dirstream == NULL)
return -1;
/* Prepare the result buffer. */
memcpy (buf, dev, sizeof (dev));
buf[sizeof (dev)] = '/';
buflen -= sizeof (dev) + 1;
while ((d = readdir (dirstream)) != NULL)
if (d->d_fileno == myino)
{
char *cp;
cp = stpncpy (&buf[sizeof (dev) + 1], d->d_name,
MIN (d->d_namlen + 1, buflen));
cp[0] = '\0';
if (stat (buf, &st) == 0 && st.st_dev == mydev)
{
(void) closedir (dirstream);
errno = save;
return 0;
}
}
(void) closedir (dirstream);
errno = save;
return -1;
}

View File

@ -16,6 +16,7 @@ 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 <utime.h>
#include <sys/time.h>
#include <errno.h>
#include <stddef.h>
@ -36,7 +37,7 @@ __utimes (const char *file, struct timeval tvp[2])
else
times = NULL;
return utime (path, times);
return utime (file, times);
}
weak_alias (__utimes, utimes)

36
sysdeps/stub/msgctl.c Normal file
View File

@ -0,0 +1,36 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/msg.h>
#include <errno.h>
/* Allows to control internal state and destruction of message queue
objects. */
int
msgctl (msqid, cmd, buf)
int msqid;
int cmd;
struct msqid_ds *buf;
{
errno = ENOSYS;
return -1;
}
stub_warning (msgctl)

35
sysdeps/stub/msgget.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/msg.h>
#include <errno.h>
/* Return descriptor for message queue associated with KEY. The MSGFLG
parameter describes how to proceed with clashing of key values. */
int
msgget (key, msgflg)
key_t key;
int msgflg;
{
errno = ENOSYS;
return -1;
}
stub_warning (msgget)

41
sysdeps/stub/msgrcv.c Normal file
View File

@ -0,0 +1,41 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/msg.h>
#include <errno.h>
/* Read a message from the queue associated with the message queue
descriptor MSQID. At most MSGSZ bytes of the message are placed
in the buffer specified by the MSGP parameter. The MSGTYP parameter
describes which message is returned in MSGFLG describes the behaviour
in buffer overflow or queue underflow. */
int
msgrcv (msqid, msgp, msgsz, msgtyp, msgflg)
int msqid;
void *msgp;
size_t msgsz;
long msgtyp;
int msgflg;
{
errno = ENOSYS;
return -1;
}
stub_warning (msgrcv)

40
sysdeps/stub/msgsnd.c Normal file
View File

@ -0,0 +1,40 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/msg.h>
#include <errno.h>
/* Send a message to the queue associated with the message queue
descriptor MSQID. The parameter MSGP points to a structure
describing messages where the parameter MSGSZ gives the length
of the text. The MSGFLG parameter describes the action taken
when the limit of the message queue length is reached. */
int
msgsnd (msqid, msgp, msgsz, msgflg)
int msqid;
void *msgp;
size_t msgsz;
int msgflg;
{
errno = ENOSYS;
return -1;
}
stub_warning (msgsnd)

37
sysdeps/stub/semctl.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/sem.h>
#include <errno.h>
/* Return identifier for array of NSEMS semaphores associated with
KEY. */
int
semctl (semid, semnum, cmd, arg)
int semid;
int semnum;
int cmd;
union semun arg;
{
errno = ENOSYS;
return -1;
}
stub_warning (semctl)

36
sysdeps/stub/semget.c Normal file
View File

@ -0,0 +1,36 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/sem.h>
#include <errno.h>
/* Return identifier for array of NSEMS semaphores associated with
KEY. */
int
semget (key, nsems, semflg)
key_t key;
int nsems;
int semflg;
{
errno = ENOSYS;
return -1;
}
stub_warning (semget)

35
sysdeps/stub/semop.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/sem.h>
#include <errno.h>
/* Perform user-defined atomical operation of array of semaphores. */
int
semop (semid, sops, nsops)
int semid;
struct sembuf *sops;
unsigned int nsops;
{
errno = ENOSYS;
return -1;
}
stub_warning (semop)

37
sysdeps/stub/shmat.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/shm.h>
#include <errno.h>
/* Attach the shared memory segment associated with SHMID to the data
segment of the calling process. SHMADDR and SHMFLG determine how
and where the segment is attached. */
char *
shmat (shmid, shmaddr, shmflg)
int shmid;
char *shmaddr;
int shmflg;
{
errno = ENOSYS;
return (char *) -1;
}
stub_warning (shmat)

35
sysdeps/stub/shmctl.c Normal file
View File

@ -0,0 +1,35 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/shm.h>
#include <errno.h>
/* Provide operations to control over shared memory segments. */
int
shmctl (shmid, cmd, buf)
int shmid;
int cmd;
struct shmid_ds *buf;
{
errno = ENOSYS;
return -1;
}
stub_warning (shmctl)

34
sysdeps/stub/shmdt.c Normal file
View File

@ -0,0 +1,34 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/shm.h>
#include <errno.h>
/* Detach shared memory segment starting at address specified by SHMADDR
from the caller's data segment. */
int
shmdt (shmaddr)
char *shmaddr;
{
errno = ENOSYS;
return -1;
}
stub_warning (shmdt)

36
sysdeps/stub/shmget.c Normal file
View File

@ -0,0 +1,36 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/shm.h>
#include <errno.h>
/* Return an identifier for an shared memory segment of at least size SIZE
which is associated with KEY. */
int
shmget (key, size, shmflg)
key_t key;
int size;
int shmflg;
{
errno = ENOSYS;
return -1;
}
stub_warning (shmget)

View File

@ -0,0 +1,58 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_IPC_BUF_H
#define _SYS_IPC_BUF_H
#include <features.h>
#include <sys/types.h>
/* Mode bits for `msgget', `semget', and `shmget'. */
#define IPC_CREAT 01000 /* create key if key does not exist */
#define IPC_EXCL 02000 /* fail if key exists */
#define IPC_NOWAIT 04000 /* return error on wait */
/* Control commands for `msgctl', `semctl', and `shmctl'. */
#define IPC_RMID 0 /* remove identifier */
#define IPC_SET 1 /* set `ipc_perm' options */
#define IPC_STAT 2 /* get `ipc_perm' options */
__BEGIN_DECLS
/* Data type for key value. */
typedef int key_t;
/* Special key values. */
#define IPC_PRIVATE ((key_t) 0) /* private key */
/* Data structure used to pass permission information to IPC operations. */
struct ipc_perm
{
__uid_t uid; /* owner's user ID */
__gid_t gid; /* owner's group ID */
__uid_t cuid; /* creator's user ID */
__gid_t cgid; /* creator's group ID */
__mode_t mode; /* read/write permission */
};
__END_DECLS
#endif /* sys/ipc_buf.h */

View File

@ -0,0 +1,47 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_MSQ_BUF_H
#define _SYS_MSQ_BUF_H
#include <features.h>
#include <sys/types.h>
/* Define options for message queue functions. */
#define MSG_NOERROR 010000 /* no error if message is too big */
__BEGIN_DECLS
/* Structure of record for one message inside the kernel.
The type `struct __msg' is opaque. */
struct msqid_ds
{
struct ipc_perm msg_perm; /* structure describing operation permission */
__time_t msg_stime; /* time of last msgsnd command */
__time_t msg_rtime; /* time of last msgrcv command */
__time_t msg_ctime; /* time of last change */
unsigned short int msg_qnum; /* number of messages currently on queue */
unsigned short int msg_qbytes;/* max number of bytes allowed on queue */
__pid_t msg_lspid; /* pid of last msgsnd() */
__pid_t msg_lrpid; /* pid of last msgrcv() */
};
__END_DECLS
#endif /* sys/msq_buf.h */

View File

@ -0,0 +1,52 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_SEM_BUF_H
#define _SYS_SEM_BUF_H
#include <features.h>
#include <sys/types.h>
/* Flags for `semop'. */
#define SEM_UNDO 0x1000 /* undo the operation on exit */
/* Commands for `semctl'. */
#define GETPID 11 /* get sempid */
#define GETVAL 12 /* get semval */
#define GETALL 13 /* get all semval's */
#define GETNCNT 14 /* get semncnt */
#define GETZCNT 15 /* get semzcnt */
#define SETVAL 16 /* set semval */
#define SETALL 17 /* set all semval's */
__BEGIN_DECLS
/* Data structure describing a set of semaphores. */
struct semid_ds
{
struct ipc_perm sem_perm; /* operation permisson struct */
__time_t sem_otime; /* last semop() time */
__time_t sem_ctime; /* last time changed by semctl() */
unsigned short int sem_nsems; /* number of semaphores in set */
};
__END_DECLS
#endif /* sys/sem_buf.h */

View File

@ -0,0 +1,53 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_SHM_BUF_H
#define _SYS_SHM_BUF_H
#include <features.h>
#include <sys/types.h>
/* Flags for `shmat'. */
#define SHM_RDONLY 010000 /* attach read-only else read-write */
#define SHM_RND 020000 /* round attach address to SHMLBA */
#define SHM_REMAP 040000 /* take-over region on attach */
/* Commands for `shmctl'. */
#define SHM_LOCK 11 /* lock segment (root only) */
#define SHM_UNLOCK 12 /* unlock segment (root only) */
__BEGIN_DECLS
/* Data structure describing a set of semaphores. */
struct shmid_ds
{
struct ipc_perm sem_perm; /* operation permisson struct */
int shm_segsz; /* size of segment in bytes */
__time_t sem_atime; /* time of last shmat() */
__time_t sem_dtime; /* time of last shmdt() */
__time_t sem_ctime; /* time of last change by shmctl() */
__pid_t shm_cpid; /* pid of creator */
__pid_t shm_lpid; /* pid of last shmop */
unsigned short int shm_nattch; /* number of current attaches */
};
__END_DECLS
#endif /* sys/shm_buf.h */

42
sysdeps/stub/ttyname_r.c Normal file
View File

@ -0,0 +1,42 @@
/* Copyright (C) 1991, 1995 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 <errno.h>
#include <unistd.h>
/* Store at most BUFLEN characters the pathname of the terminal FD is
open on in BUF. Return 0 on success, -1 otherwise. */
int
ttyname_r (fd, buf, buflen)
int fd;
char *buf;
int buflen;
{
errno = ENOSYS;
return -1;
}
#ifdef HAVE_GNU_LD
#include <gnu-stabs.h>
stub_warning(ttyname_r);
#endif /* GNU stabs. */

31
sysvipc/Makefile Normal file
View File

@ -0,0 +1,31 @@
# Copyright (C) 1995 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.
#
# Sub-makefile for sysvipc portion of the library.
#
subdir := sysvipc
headers := sys/ipc.h sys/msg.h sys/sem.h sys/shm.h \
sys/ipc_buf.h sys/msq_buf.h sys/sem_buf.h sys/shm_buf.h
routines := msgsnd msgrcv msgget msgctl \
semop semget semctl \
shmat shmdt shmget shmctl
include ../Rules

37
sysvipc/ftok.c Normal file
View File

@ -0,0 +1,37 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#include <sys/ipc.h>
#include <sys/stat.h>
key_t
ftok (pathname, proj_id)
char *pathname;
char proj_id;
{
struct stat st;
key_t key;
if (__stat (pathname, &st) < 0)
return (key_t) -1;
key = (st.st_ino & 0xffff) | ((st.st_dev & 0xff) << 16) | (id << 24);
return key;
}

33
sysvipc/sys/ipc.h Normal file
View File

@ -0,0 +1,33 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_IPC_H
#define _SYS_IPC_H
/* Get system dependent definition of `struct ipc_perm' and more. */
#include <sys/ipc_buf.h>
__BEGIN_DECLS
/* Generates key for System V style IPC. */
extern key_t ftok __P ((char *__pathname, char __proj_id));
__END_DECLS
#endif /* sys/ipc.h */

61
sysvipc/sys/msg.h Normal file
View File

@ -0,0 +1,61 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_MSG_H
#define _SYS_MSG_H
#include <features.h>
#include <sys/types.h>
/* Get common definition of System V style IPC. */
#include <sys/ipc.h>
/* Get system dependent definition of `struct msqid_ds' and more. */
#include <sys/msq_buf.h>
__BEGIN_DECLS
/* The following System V style IPC functions implement a message queue
system. The definition is found in XPG2. */
/* Template for struct to be used as argument for `msgsnd' and `msgrcv'. */
struct msgbuf
{
long mtype; /* type of received/sent message */
char mtext[1]; /* text of the message */
};
/* Message queue control operation. */
extern int msgctl __P ((int __msqid, int __cmd, struct msqid_ds *__buf));
/* Get messages queue. */
extern int msgget __P ((key_t __key, int __msgflg));
/* Receive message from message queue. */
extern int msgrcv __P ((int __msqid, void *__msgp, size_t __msgsz,
long __msgtyp, int __msgflg));
/* Send message to message queue. */
extern int msgsnd __P ((int __msqid, void *__msgp, size_t __msgsz,
int __msgflg));
__END_DECLS
#endif /* sys/msg.h */

59
sysvipc/sys/sem.h Normal file
View File

@ -0,0 +1,59 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_SEM_H
#define _SYS_SEM_H
#include <features.h>
#include <sys/types.h>
/* Get common definition of System V style IPC. */
#include <sys/ipc.h>
/* Get system dependent definition of `struct semid_ds' and more. */
#include <sys/sem_buf.h>
__BEGIN_DECLS
/* The following System V style IPC functions implement a semaphore
handling. The definition is found in XPG2. */
/* Structure used for argument to `semop' to describe operations. */
struct sembuf
{
short int sem_num; /* semaphore number */
short int sem_op; /* semaphore operation */
short int sem_flg; /* operation flag */
};
/* Semaphore control operation. */
extern int semctl __P ((int __semid, int __semnum, int __cmd,
union semun __arg));
/* Get semaphore. */
extern int semget __P ((key_t __key, int __nsems, int __semflg));
/* Operate on semaphore. */
extern int semop __P ((int __semid, struct sembuf *__sops,
unsigned int __nsops));
__END_DECLS
#endif /* sys/sem.h */

56
sysvipc/sys/shm.h Normal file
View File

@ -0,0 +1,56 @@
/* Copyright (C) 1995 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@gnu.ai.mit.edu>, August 1995.
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., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA. */
#ifndef _SYS_SHM_H
#define _SYS_SHM_H
#include <features.h>
#include <unistd.h> /* for `getpagesize' declaration */
#include <sys/types.h>
/* Get common definition of System V style IPC. */
#include <sys/ipc.h>
/* Get system dependent definition of `struct shmid_ds' and more. */
#include <sys/shm_buf.h>
/* Segment low boundary address multiple. */
#define SHMLBA getpagesize ()
__BEGIN_DECLS
/* The following System V style IPC functions implement a shared memory
facility. The definition is found in XPG2. */
/* Shared memory control operation. */
extern int shmctl __P ((int __shmid, int __cmd, struct shmid_ds *__buf));
/* Get shared memory segment. */
extern int shmget __P ((key_t __key, int __size, int __shmflg));
/* Attach shared memory segment. */
extern int shmat __P ((int __shmid, char *__shmaddr, int __shmflg));
/* Detach shared memory segment. */
extern int shmdt __P ((char *__shmaddr));
__END_DECLS
#endif /* sys/shm.h */