add directory gnu

This commit is contained in:
gohigh
2024-02-19 00:24:47 -05:00
parent 32616db5a4
commit a40f4cadb0
5086 changed files with 1860970 additions and 0 deletions

View File

@@ -0,0 +1,9 @@
make_siglist.c signame.c signame.h
det_endian.c
../../math/bsd/common_source/mathimpl.h
../../math/bsd/common/trig.h
../../math/bsd/sys/stdc.h
../../math/bsd/common/sincos.c
../../math/bsd/common_source/asincos.c
../../math/bsd/common_source/exp__E.c
../../math/bsd/common_source/log__L.c

View File

@@ -0,0 +1,60 @@
# Copyright (C) 1992 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.
ifeq ($(subdir),math)
ifndef math-twiddled
routines:= $(filter-out acos asin cos sin ceil __rint hypot,$(routines)) \
sincos asincos
aux := $(aux) exp__E log__L
math-twiddled := t
endif
bsdmath_dirs := $(bsdmath_dirs) common common_source
endif
ifeq ($(subdir),string)
dont_distribute := $(dont_distribute) endian.h # Generated.
endif
$(objpfx)endian.h: $(objpfx)det_endian
$(dir $<)$(notdir $<) > $@-tmp
mv $@-tmp $@
$(objpfx)det_endian: $(sysdep_dir)/generic/det_endian.c
cd $(objdir); $(CC) $(<:$(objpfx)%=%) -o $(@:$(objpfx)%=%)
before-compile := $(before-compile) $(objpfx)endian.h
ifeq ($(subdir),stdio)
ifeq "$(filter $(objpfx)siglist.c,$(before-compile))" ""
before-compile := $(before-compile) $(objpfx)siglist.c
$(objpfx)siglist.c: $(objpfx)make_siglist
@rm -f $@
$< > $@-tmp
mv $@-tmp $@
$(objpfx)make_siglist: $(sysdep_dir)/generic/make_siglist.c
cd $(objdir); $(CC) $< -o $(@:$(objpfx)%=%)
endif
endif

View File

@@ -0,0 +1,46 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
/* Deal with an infinite or NaN result.
If ERROR is ERANGE, result is +Inf;
if ERROR is - ERANGE, result is -Inf;
otherwise result is NaN.
This will set `errno' to either ERANGE or EDOM,
and may return an infinity or NaN, or may do something else. */
double
DEFUN(__infnan, (error), int error)
{
switch (error)
{
case ERANGE:
errno = ERANGE;
return HUGE_VAL;
case - ERANGE:
errno = ERANGE;
return - HUGE_VAL;
default:
errno = EDOM;
return 0.0;
}
}

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
/* Return nonzero if VALUE is not a number. */
int
DEFUN(__isnan, (value), double value)
{
return value != value;
}

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <stddef.h>
#include <sys/stat.h>
#include <gnu-stabs.h>
function_alias (__lstat, __stat, int, (file, buf),
DEFUN(__lstat, (file, buf),
CONST char *file AND struct stat *buf))

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h> /* For size_t and NULL. */
/*
* Copy no more than N bytes of SRC to DEST, stopping when C is found.
* Return the position in DEST one byte past where C was copied,
* or NULL if C was not found in the first N bytes of SRC.
*/
PTR
DEFUN(__memccpy, (dest, src, c, n),
PTR dest AND CONST PTR src AND int c AND size_t n)
{
register CONST char *s = src;
register char *d = dest;
register CONST int x = (unsigned char) c;
register size_t i = n;
while (i-- > 0)
if ((*d++ = *s++) == x)
return d;
return NULL;
}

View File

@@ -0,0 +1,25 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <gnu-stabs.h>
/* We decide by fiat that the prevailing rounding mode is towards zero. */
function_alias(__rint, floor, double, (x),
DEFUN(__rint, (x), double x))

View File

@@ -0,0 +1,42 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
/* Return the inverse cosine of X. */
double
DEFUN(acos, (x), double x)
{
double t;
if (__isnan(x))
{
errno = EDOM;
return x;
}
if (x == -1.0)
/* If X is -1, the general formula blows up (zero divided by zero loses),
but we know that acos(-1) = pi. */
t = atan2(1.0, 0.0);
else
t = atan2(sqrt((1.0 - x) / (1.0 + x)), 1.0);
return t + t;
}

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
/* Return the inverse sine of X. */
double
DEFUN(asin, (x), double x)
{
double abs_x;
if (__isnan(x))
{
errno = EDOM;
return x;
}
abs_x = fabs(x);
if (abs_x <= 0.5)
return atan2(x, sqrt(1.0 - (x * x)));
else
{
double t = 1.0 - abs_x;
return atan2(x, sqrt((t + t) - (t * t)));
}
}

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
/* Return the inverse tangent of X. */
double
DEFUN(atan, (x), register double x)
{
return atan2(x, 1.0);
}

View File

@@ -0,0 +1,32 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <bstring.h>
#include <string.h>
#define memmove bcopy
#define rettype void
#define RETURN(s) return
#define a1 src
#define a1const CONST
#define a2 dest
#define a2const
#include <memmove.c>

View File

@@ -0,0 +1,81 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <bstring.h>
#include <memcopy.h>
/* Set N bytes of S to 0. */
void
DEFUN(bzero, (s, n), PTR s AND size_t len)
{
long int dstp = (long int) s;
CONST op_t zero = 0;
if (len >= 8)
{
size_t xlen;
/* There are at least some bytes to zero. No need to test
for LEN == 0 in this alignment loop. */
while (dstp % OPSIZ != 0)
{
((byte *) dstp)[0] = 0;
dstp += 1;
len -= 1;
}
/* Write 8 op_t per iteration until less than 8 op_t remain. */
xlen = len / (OPSIZ * 8);
while (xlen != 0)
{
((op_t *) dstp)[0] = zero;
((op_t *) dstp)[1] = zero;
((op_t *) dstp)[2] = zero;
((op_t *) dstp)[3] = zero;
((op_t *) dstp)[4] = zero;
((op_t *) dstp)[5] = zero;
((op_t *) dstp)[6] = zero;
((op_t *) dstp)[7] = zero;
dstp += 8 * OPSIZ;
xlen -= 1;
}
len %= OPSIZ * 8;
/* Write 1 op_t per iteration until less than op_t remain. */
xlen = len / OPSIZ;
while (xlen != 0)
{
((op_t *) dstp)[0] = zero;
dstp += OPSIZ;
xlen -= 1;
}
len %= OPSIZ;
}
/* Write the last few bytes. */
while (len != 0)
{
((byte *) dstp)[0] = 0;
dstp += 1;
len -= 1;
}
}

View File

@@ -0,0 +1,43 @@
/* Determine the "endianess" of the CPU.
Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
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 <stdio.h>
main()
{
unsigned long int i;
puts("#ifndef\t_ENDIAN_H\n#define\t_ENDIAN_H\t1");
if (sizeof(i) != 4)
puts("#error \"Not a 32-bit machine!\"");
i = (((((('A' << 8) + 'B') << 8) + 'C') << 8) + 'D');
if (!strncmp ("ABCD", (char *) &i, 4))
puts ("#define __BIG_ENDIAN");
else if (!strncmp ("DCBA", (char *) &i, 4))
puts ("#define __LITTLE_ENDIAN");
else
puts ("#define __MIXED_ENDIAN");
puts("#endif\t/* endian.h */");
exit (0);
}

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
/* Return the absolute value of X. */
double
DEFUN(fabs, (x), register double x)
{
return x < 0.0 ? -x : x;
}

View File

@@ -0,0 +1,47 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <limits.h>
#include <bstring.h>
#undef ffs
/* Find the first bit set in I. */
int
DEFUN(ffs, (i), int i)
{
static CONST unsigned char table[] =
{
0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,
6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,
8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8,8
};
unsigned long int a;
unsigned long int x = i & -i;
a = x <= 0xffff ? (x <= 0xff ? 0 : 8) : (x <= 0xffffff ? 16 : 24);
return table[x >> a] + a;
}

View File

@@ -0,0 +1,31 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
/* Break VALUE into a normalized fraction and an integral power of 2. */
double
DEFUN(frexp, (value, exp), double value AND int *exp)
{
/* Add one to the exponent of the number,
so we have one digit before the binary point. */
*exp = (int) __logb (value) + 1;
return ldexp (value, - *exp);
}

View File

@@ -0,0 +1,10 @@
#include <ansidecl.h>
#include <netinet/in.h>
#undef htonl
unsigned long int
DEFUN(htonl, (x), unsigned long int x)
{
return x;
}

View File

@@ -0,0 +1,10 @@
#include <ansidecl.h>
#include <netinet/in.h>
#undef htons
unsigned short int
DEFUN(htons, (x), unsigned short int x)
{
return x;
}

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
/* Return `sqrt(x*x + y*y)'. */
double
DEFUN(hypot, (x, y), double x AND double y)
{
return sqrt(x*x + y*y);
}

View File

@@ -0,0 +1,16 @@
/* Generic Internet number representation conversion macros. */
#undef ntohl
#undef ntohs
#undef htonl
#undef htons
extern unsigned long int EXFUN(ntohl, (unsigned long int));
extern unsigned short int EXFUN(ntohs, (unsigned short int));
extern unsigned long int EXFUN(htonl, (unsigned long int));
extern unsigned short int EXFUN(htons, (unsigned short int));
#define ntohl(x) (x)
#define ntohs(x) (x)
#define htonl(x) (x)
#define htons(x) (x)

View File

@@ -0,0 +1,27 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
/* Return X times (two to the EXP power). */
double
DEFUN(ldexp, (x, exp), register double x AND register int exp)
{
return x * pow(2.0, (double) exp);
}

View File

@@ -0,0 +1,37 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
#ifndef LN10
#define LN10 log(10.0)
#endif
/* Return the base-ten logarithm of X. */
double
DEFUN(log10, (x), double x)
{
static double ln10 = 0.0;
if (ln10 == 0.0)
ln10 = LN10;
return log(x) / ln10;
}

View File

@@ -0,0 +1,52 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with the GNU C Library; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <signal.h>
#include <stdio.h>
/* Make a definition for sys_siglist. */
#undef SYS_SIGLIST_MISSING
#include "signame.c"
int
main()
{
register int i;
init_sigs ();
puts ("#include \"ansidecl.h\"\n#include <stddef.h>\n");
puts ("#ifndef HAVE_GNU_LD");
puts ("#define _sys_siglist\tsys_siglist");
puts ("#endif");
puts ("\n/* This is a list of all known signal numbers. */");
puts ("\nCONST char *CONST _sys_siglist[] =\n {");
for (i = 0; i < NSIG; ++i)
printf (" \"%s\",\n", sys_siglist[i]);
puts (" NULL\n };\n");
exit (0);
}

View File

@@ -0,0 +1,143 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Based on strlen implemention by Torbjorn Granlund (tege@sics.se),
with help from Dan Sahlin (dan@sics.se) and
commentary by Jim Blandy (jimb@ai.mit.edu);
adaptation to memchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
and implemented by Roland McGrath (roland@ai.mit.edu).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Search no more than N bytes of S for C. */
PTR
DEFUN(memchr, (s, c, n), CONST PTR s AND int c AND size_t n)
{
CONST unsigned char *char_ptr;
CONST unsigned long int *longword_ptr;
unsigned long int longword, magic_bits, charmask;
c = (unsigned char) c;
/* Handle the first few characters by reading one character at a time.
Do this until CHAR_PTR is aligned on a 4-byte border. */
for (char_ptr = s; n > 0 && ((unsigned long int) char_ptr & 3) != 0;
--n, ++char_ptr)
if (*char_ptr == c)
return (PTR) char_ptr;
longword_ptr = (unsigned long int *) char_ptr;
/* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
the "holes." Note that there is a hole just to the left of
each byte, with an extra at the end:
bits: 01111110 11111110 11111110 11111111
bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
magic_bits = 0x7efefeff;
/* Set up a longword, each of whose bytes is C. */
charmask = c | (c << 8);
charmask |= charmask << 16;
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
if *any of the four* bytes in the longword in question are zero. */
while (n >= 4)
{
/* We tentatively exit the loop if adding MAGIC_BITS to
LONGWORD fails to change any of the hole bits of LONGWORD.
1) Is this safe? Will it catch all the zero bytes?
Suppose there is a byte with all zeros. Any carry bits
propagating from its left will fall into the hole at its
least significant bit and stop. Since there will be no
carry from its most significant bit, the LSB of the
byte to the left will be unchanged, and the zero will be
detected.
2) Is this worthwhile? Will it ignore everything except
zero bytes? Suppose every byte of LONGWORD has a bit set
somewhere. There will be a carry into bit 8. If bit 8
is set, this will carry into bit 16. If bit 8 is clear,
one of bits 9-15 must be set, so there will be a carry
into bit 16. Similarly, there will be a carry into bit
24. If one of bits 24-30 is set, there will be a carry
into bit 31, so all of the hole bits will be changed.
The one misfire occurs when bits 24-30 are clear and bit
31 is set; in this case, the hole at bit 31 is not
changed. If we had access to the processor carry flag,
we could close this loophole by putting the fourth hole
at bit 32!
So it ignores everything except 128's, when they're aligned
properly.
3) But wait! Aren't we looking for C, not zero?
Good point. So what we do is XOR LONGWORD with a longword,
each of whose bytes is C. This turns each byte that is C
into a zero. */
longword = *longword_ptr++ ^ charmask;
/* Add MAGIC_BITS to LONGWORD. */
if ((((longword + magic_bits)
/* Set those bits that were unchanged by the addition. */
^ ~longword)
/* Look at only the hole bits. If any of the hole bits
are unchanged, most likely one of the bytes was a
zero. */
& ~magic_bits) != 0)
{
/* Which of the bytes was C? If none of them were, it was
a misfire; continue the search. */
CONST unsigned char *cp = (CONST unsigned char *) (longword_ptr - 1);
if (cp[0] == c)
return (PTR) cp;
if (cp[1] == c)
return (PTR) &cp[1];
if (cp[2] == c)
return (PTR) &cp[2];
if (cp[3] == c)
return (PTR) &cp[3];
}
n -= 4;
}
char_ptr = (CONST unsigned char *) longword_ptr;
while (n-- > 0)
{
if (*char_ptr == c)
return (PTR) char_ptr;
else
++char_ptr;
}
return NULL;
}

View File

@@ -0,0 +1,285 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
/* BE VERY CAREFUL IF YOU CHANGE THIS CODE! */
/* The strategy of this memcmp is:
1. Compare bytes until one of the block pointers is aligned.
2. Compare using memcmp_common_alignment or
memcmp_not_common_alignment, regarding the alignment of the other
block after the initial byte operations. The maximum number of
full words (of type op_t) are compared in this way.
3. Compare the few remaining bytes. */
/* memcmp_common_alignment -- Compare blocks at SRCP1 and SRCP2 with LEN `op_t'
objects (not LEN bytes!). Both SRCP1 and SRCP2 should be aligned for
memory operations on `op_t's. */
#ifdef __GNUC__
__inline
#endif
static int
DEFUN(memcmp_common_alignment, (srcp1, srcp2, len),
long int srcp1 AND long int srcp2 AND size_t len)
{
op_t a0, a1;
op_t b0, b1;
op_t res;
switch (len % 4)
{
case 2:
a0 = ((op_t *) srcp1)[0];
b0 = ((op_t *) srcp2)[0];
srcp1 -= 2 * OPSIZ;
srcp2 -= 2 * OPSIZ;
len += 2;
goto do1;
case 3:
a1 = ((op_t *) srcp1)[0];
b1 = ((op_t *) srcp2)[0];
srcp1 -= OPSIZ;
srcp2 -= OPSIZ;
len += 1;
goto do2;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return 0;
a0 = ((op_t *) srcp1)[0];
b0 = ((op_t *) srcp2)[0];
goto do3;
case 1:
a1 = ((op_t *) srcp1)[0];
b1 = ((op_t *) srcp2)[0];
srcp1 += OPSIZ;
srcp2 += OPSIZ;
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
/* Fall through. */
}
do
{
a0 = ((op_t *) srcp1)[0];
b0 = ((op_t *) srcp2)[0];
res = a1 - b1;
if (res != 0)
return res;
do3:
a1 = ((op_t *) srcp1)[1];
b1 = ((op_t *) srcp2)[1];
res = a0 - b0;
if (res != 0)
return res;
do2:
a0 = ((op_t *) srcp1)[2];
b0 = ((op_t *) srcp2)[2];
res = a1 - b1;
if (res != 0)
return res;
do1:
a1 = ((op_t *) srcp1)[3];
b1 = ((op_t *) srcp2)[3];
res = a0 - b0;
if (res != 0)
return res;
srcp1 += 4 * OPSIZ;
srcp2 += 4 * OPSIZ;
len -= 4;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
return a1 - b1;
}
/* SRCP2 should be aligned for memory operations on `op_t',
but SRCP1 *should be unaligned*. */
#ifdef __GNUC__
__inline
#endif
static int
DEFUN(memcmp_not_common_alignment, (srcp1, srcp2, len),
long int srcp1 AND long int srcp2 AND size_t len)
{
op_t a0, a1, a2, a3;
op_t b0, b1, b2, b3;
op_t res;
op_t x;
int shl, shr;
/* Calculate how to shift a word read at the memory operation
aligned srcp1 to make it aligned for comparison. */
shl = 8 * (srcp1 % OPSIZ);
shr = 8 * OPSIZ - shl;
/* Make SRCP1 aligned by rounding it down to the beginning of the `op_t'
it points in the middle of. */
srcp1 &= -OPSIZ;
switch (len % 4)
{
case 2:
a1 = ((op_t *) srcp1)[0];
a2 = ((op_t *) srcp1)[1];
b2 = ((op_t *) srcp2)[0];
srcp1 -= 1 * OPSIZ;
srcp2 -= 2 * OPSIZ;
len += 2;
goto do1;
case 3:
a0 = ((op_t *) srcp1)[0];
a1 = ((op_t *) srcp1)[1];
b1 = ((op_t *) srcp2)[0];
srcp2 -= 1 * OPSIZ;
len += 1;
goto do2;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return 0;
a3 = ((op_t *) srcp1)[0];
a0 = ((op_t *) srcp1)[1];
b0 = ((op_t *) srcp2)[0];
srcp1 += 1 * OPSIZ;
goto do3;
case 1:
a2 = ((op_t *) srcp1)[0];
a3 = ((op_t *) srcp1)[1];
b3 = ((op_t *) srcp2)[0];
srcp1 += 2 * OPSIZ;
srcp2 += 1 * OPSIZ;
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
/* Fall through. */
}
do
{
a0 = ((op_t *) srcp1)[0];
b0 = ((op_t *) srcp2)[0];
x = MERGE(a2, shl, a3, shr);
res = x - b3;
if (res != 0)
return res;
do3:
a1 = ((op_t *) srcp1)[1];
b1 = ((op_t *) srcp2)[1];
x = MERGE(a3, shl, a0, shr);
res = x - b0;
if (res != 0)
return res;
do2:
a2 = ((op_t *) srcp1)[2];
b2 = ((op_t *) srcp2)[2];
x = MERGE(a0, shl, a1, shr);
res = x - b1;
if (res != 0)
return res;
do1:
a3 = ((op_t *) srcp1)[3];
b3 = ((op_t *) srcp2)[3];
x = MERGE(a1, shl, a2, shr);
res = x - b2;
if (res != 0)
return res;
srcp1 += 4 * OPSIZ;
srcp2 += 4 * OPSIZ;
len -= 4;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
x = MERGE(a2, shl, a3, shr);
return x - b3;
}
int
DEFUN(memcmp, (s1, s2, n),
CONST PTR s1 AND CONST PTR s2 AND size_t len)
{
op_t a0;
op_t b0;
long int srcp1 = (long int) s1;
long int srcp2 = (long int) s2;
op_t res;
if (len >= OP_T_THRES)
{
/* There are at least some bytes to compare. No need to test
for LEN == 0 in this alignment loop. */
while (srcp2 % OPSIZ != 0)
{
a0 = ((byte *) srcp1)[0];
b0 = ((byte *) srcp2)[0];
srcp1 += 1;
srcp2 += 1;
res = a0 - b0;
if (res != 0)
return res;
len -= 1;
}
/* SRCP2 is now aligned for memory operations on `op_t'.
SRCP1 alignment determines if we can do a simple,
aligned compare or need to shuffle bits. */
if (srcp1 % OPSIZ == 0)
res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ);
else
res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ);
if (res != 0)
return res;
/* Number of bytes remaining in the interval [0..OPSIZ-1]. */
srcp1 += len & -OPSIZ;
srcp2 += len & -OPSIZ;
len %= OPSIZ;
}
/* There are just a few bytes to compare. Use byte memory operations. */
while (len != 0)
{
a0 = ((byte *) srcp1)[0];
b0 = ((byte *) srcp2)[0];
srcp1 += 1;
srcp2 += 1;
res = a0 - b0;
if (res != 0)
return res;
len -= 1;
}
return 0;
}

View File

@@ -0,0 +1,148 @@
/* memcopy.h -- definitions for memory copy functions. Generic C version.
Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
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. */
/* The strategy of the memory functions is:
1. Copy bytes until the destination pointer is aligned.
2. Copy words in unrolled loops. If the source and destination
are not aligned in the same way, use word memory operations,
but shift and merge two read words before writing.
3. Copy the few remaining bytes.
This is fast on processors that have at least 10 registers for
allocation by GCC, and that can access memory at reg+const in one
instruction.
I made an "exhaustive" test of this memmove when I wrote it,
exhaustive in the sense that I tried all alignment and length
combinations, with and without overlap. */
#include <endian.h>
/* The macros defined in this file are:
BYTE_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_to_copy)
BYTE_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_to_copy)
WORD_COPY_FWD(dst_beg_ptr, src_beg_ptr, nbytes_remaining, nbytes_to_copy)
WORD_COPY_BWD(dst_end_ptr, src_end_ptr, nbytes_remaining, nbytes_to_copy)
MERGE(old_word, sh_1, new_word, sh_2)
[I fail to understand. I feel stupid. --roland]
*/
/* Type to use for aligned memory operations.
This should normally be the biggest type supported by a single load
and store. */
#define op_t unsigned long int
#define OPSIZ (sizeof(op_t))
/* Type to use for unaligned operations. */
typedef unsigned char byte;
/* Optimal type for storing bytes in registers. */
#define reg_char char
#ifdef __LITTLE_ENDIAN
#define MERGE(w0, sh_1, w1, sh_2) (((w0) >> (sh_1)) | ((w1) << (sh_2)))
#endif
#ifdef __BIG_ENDIAN
#define MERGE(w0, sh_1, w1, sh_2) (((w0) << (sh_1)) | ((w1) >> (sh_2)))
#endif
/* Copy exactly NBYTES bytes from SRC_BP to DST_BP,
without any assumptions about alignment of the pointers. */
#define BYTE_COPY_FWD(dst_bp, src_bp, nbytes) \
do \
{ \
size_t __nbytes = (nbytes); \
while (__nbytes > 0) \
{ \
byte __x = ((byte *) src_bp)[0]; \
src_bp += 1; \
__nbytes -= 1; \
((byte *) dst_bp)[0] = __x; \
dst_bp += 1; \
} \
} while (0)
/* Copy exactly NBYTES_TO_COPY bytes from SRC_END_PTR to DST_END_PTR,
beginning at the bytes right before the pointers and continuing towards
smaller addresses. Don't assume anything about alignment of the
pointers. */
#define BYTE_COPY_BWD(dst_ep, src_ep, nbytes) \
do \
{ \
size_t __nbytes = (nbytes); \
while (__nbytes > 0) \
{ \
byte __x; \
src_ep -= 1; \
__x = ((byte *) src_ep)[0]; \
dst_ep -= 1; \
__nbytes -= 1; \
((byte *) dst_ep)[0] = __x; \
} \
} while (0)
/* Copy *up to* NBYTES bytes from SRC_BP to DST_BP, with
the assumption that DST_BP is aligned on an OPSIZ multiple. If
not all bytes could be easily copied, store remaining number of bytes
in NBYTES_LEFT, otherwise store 0. */
extern void EXFUN(_wordcopy_fwd_aligned, (long int, long int, size_t));
extern void EXFUN(_wordcopy_fwd_dest_aligned, (long int, long int, size_t));
#define WORD_COPY_FWD(dst_bp, src_bp, nbytes_left, nbytes) \
do \
{ \
if (src_bp % OPSIZ == 0) \
_wordcopy_fwd_aligned (dst_bp, src_bp, (nbytes) / OPSIZ); \
else \
_wordcopy_fwd_dest_aligned (dst_bp, src_bp, (nbytes) / OPSIZ); \
src_bp += (nbytes) & -OPSIZ; \
dst_bp += (nbytes) & -OPSIZ; \
(nbytes_left) = (nbytes) % OPSIZ; \
} while (0)
/* Copy *up to* NBYTES_TO_COPY bytes from SRC_END_PTR to DST_END_PTR,
beginning at the words (of type op_t) right before the pointers and
continuing towards smaller addresses. May take advantage of that
DST_END_PTR is aligned on an OPSIZ multiple. If not all bytes could be
easily copied, store remaining number of bytes in NBYTES_REMAINING,
otherwise store 0. */
extern void EXFUN(_wordcopy_bwd_aligned, (long int, long int, size_t));
extern void EXFUN(_wordcopy_bwd_dest_aligned, (long int, long int, size_t));
#define WORD_COPY_BWD(dst_ep, src_ep, nbytes_left, nbytes) \
do \
{ \
if (src_ep % OPSIZ == 0) \
_wordcopy_bwd_aligned (dst_ep, src_ep, (nbytes) / OPSIZ); \
else \
_wordcopy_bwd_dest_aligned (dst_ep, src_ep, (nbytes) / OPSIZ); \
src_ep -= (nbytes) & -OPSIZ; \
dst_ep -= (nbytes) & -OPSIZ; \
(nbytes_left) = (nbytes) % OPSIZ; \
} while (0)
/* Threshold value for when to enter the unrolled loops. */
#define OP_T_THRES 16

View File

@@ -0,0 +1,55 @@
/* memcpy -- copy memory to memory until the specified number of bytes
has been copied. Overlap is NOT handled correctly.
Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
PTR
DEFUN(memcpy, (dstpp, srcpp, len),
PTR dstpp AND CONST PTR srcpp AND size_t len)
{
unsigned long int dstp = (long int) dstpp;
unsigned long int srcp = (long int) srcpp;
/* Copy from the beginning to the end. */
/* If there not too few bytes to copy, use word copy. */
if (len >= OP_T_THRES)
{
/* Copy just a few bytes to make DSTP aligned. */
len -= (-dstp) % OPSIZ;
BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
/* Copy from SRCP to DSTP taking advantage of the known
alignment of DSTP. Number of bytes remaining is put
in the third argumnet, i.e. in LEN. This number may
vary from machine to machine. */
WORD_COPY_FWD (dstp, srcp, len, len);
/* Fall out and copy the tail. */
}
/* There are just a few bytes to copy. Use byte memory operations. */
BYTE_COPY_FWD (dstp, srcp, len);
return dstpp;
}

View File

@@ -0,0 +1,99 @@
/* memmove -- copy memory to memory until the specified number of bytes
has been copied. Overlap is handled correctly.
Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
/* All this is so that bcopy.c can #include
this file after defining some things. */
#ifndef a1
#define a1 dest /* First arg is DEST. */
#define a1const
#define a2 src /* Second arg is SRC. */
#define a2const CONST
#endif
#if !defined(RETURN) || !defined(rettype)
#define RETURN(s) return (s) /* Return DEST. */
#define rettype PTR
#endif
rettype
DEFUN(memmove, (a1, a2, len),
a1const PTR a1 AND a2const PTR a2 AND size_t len)
{
unsigned long int dstp = (long int) dest;
unsigned long int srcp = (long int) src;
/* This test makes the forward copying code be used whenever possible.
Reduces the working set. */
if (dstp - srcp >= len) /* *Unsigned* compare! */
{
/* Copy from the beginning to the end. */
/* If there not too few bytes to copy, use word copy. */
if (len >= OP_T_THRES)
{
/* Copy just a few bytes to make DSTP aligned. */
len -= (-dstp) % OPSIZ;
BYTE_COPY_FWD (dstp, srcp, (-dstp) % OPSIZ);
/* Copy from SRCP to DSTP taking advantage of the known
alignment of DSTP. Number of bytes remaining is put
in the third argumnet, i.e. in LEN. This number may
vary from machine to machine. */
WORD_COPY_FWD (dstp, srcp, len, len);
/* Fall out and copy the tail. */
}
/* There are just a few bytes to copy. Use byte memory operations. */
BYTE_COPY_FWD (dstp, srcp, len);
}
else
{
/* Copy from the end to the beginning. */
srcp += len;
dstp += len;
/* If there not too few bytes to copy, use word copy. */
if (len >= OP_T_THRES)
{
/* Copy just a few bytes to make DSTP aligned. */
len -= dstp % OPSIZ;
BYTE_COPY_BWD (dstp, srcp, dstp % OPSIZ);
/* Copy from SRCP to DSTP taking advantage of the known
alignment of DSTP. Number of bytes remaining is put
in the third argumnet, i.e. in LEN. This number may
vary from machine to machine. */
WORD_COPY_BWD (dstp, srcp, len, len);
/* Fall out and copy the tail. */
}
/* There are just a few bytes to copy. Use byte memory operations. */
BYTE_COPY_BWD (dstp, srcp, len);
}
RETURN(dest);
}

View File

@@ -0,0 +1,85 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
PTR
DEFUN(memset, (dstpp, c, len), PTR dstpp AND int c AND size_t len)
{
long int dstp = (long int) dstpp;
if (len >= 8)
{
size_t xlen;
op_t cccc;
cccc = (unsigned char) c;
cccc |= cccc << 8;
cccc |= cccc << 16;
if (OPSIZ > 4)
cccc |= cccc << 32;
/* There are at least some bytes to set.
No need to test for LEN == 0 in this alignment loop. */
while (dstp % OPSIZ != 0)
{
((byte *) dstp)[0] = c;
dstp += 1;
len -= 1;
}
/* Write 8 `op_t' per iteration until less than 8 `op_t' remain. */
xlen = len / (OPSIZ * 8);
while (xlen > 0)
{
((op_t *) dstp)[0] = cccc;
((op_t *) dstp)[1] = cccc;
((op_t *) dstp)[2] = cccc;
((op_t *) dstp)[3] = cccc;
((op_t *) dstp)[4] = cccc;
((op_t *) dstp)[5] = cccc;
((op_t *) dstp)[6] = cccc;
((op_t *) dstp)[7] = cccc;
dstp += 8 * OPSIZ;
xlen -= 1;
}
len %= OPSIZ * 8;
/* Write 1 `op_t' per iteration until less than OPSIZ bytes remain. */
xlen = len / OPSIZ;
while (xlen > 0)
{
((op_t *) dstp)[0] = cccc;
dstp += OPSIZ;
xlen -= 1;
}
len %= OPSIZ;
}
/* Write the last few bytes. */
while (len > 0)
{
((byte *) dstp)[0] = c;
dstp += 1;
len -= 1;
}
return dstpp;
}

View File

@@ -0,0 +1,31 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <math.h>
#undef modf
/* Break VALUE into integral and fractional parts. */
double
DEFUN(modf, (value, iptr), double value AND double *iptr)
{
register double ipart = floor(value);
*iptr = ipart;
return value - ipart;
}

View File

@@ -0,0 +1,10 @@
#include <ansidecl.h>
#include <netinet/in.h>
#undef ntohl
unsigned long int
DEFUN(ntohl, (x), unsigned long int x)
{
return x;
}

View File

@@ -0,0 +1,10 @@
#include <ansidecl.h>
#include <netinet/in.h>
#undef ntohs
unsigned short int
DEFUN(ntohs, (x), unsigned short int x)
{
return x;
}

View File

@@ -0,0 +1,37 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <math.h>
/* Return X to the Y power. */
double
DEFUN(pow, (x, y), double x AND double y)
{
if (y == 0.0 || x == 1.0)
return 1.0;
else if (y == 1.0)
return x;
else if (y == 2.0)
return x * x;
else if (y == -1.0)
return 1.0 / x;
return exp(y * log(x));
}

View File

@@ -0,0 +1,499 @@
/* Floating-point printing for `printf'.
This is an implementation of a restricted form of the `Dragon4'
algorithm described in "How to Print Floating-Point Numbers Accurately",
by Guy L. Steele, Jr. and Jon L. White, presented at the ACM SIGPLAN '90
Conference on Programming Language Design and Implementation.
Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <ctype.h>
#include <stdio.h>
#include <float.h>
#include <math.h>
#include <stdarg.h>
#include <stdlib.h>
#include <localeinfo.h>
#include <printf.h>
#define outchar(x) \
do \
{ \
register CONST int outc = (x); \
if (putc(outc, s) == EOF) \
return -1; \
else \
++done; \
} while (0)
#if FLT_RADIX != 2
double
frexp (double f, int *e)
{
#error "Don't know how to extract fraction and exponent from `double'."
}
#undef ldexp
#ifdef __GNUC__
inline
#endif
static double
ldexp (double f, int e)
{
while (e > 0)
{
f *= FLT_RADIX;
--e;
}
while (e < 0)
{
f /= FLT_RADIX;
++e;
}
}
#endif
int
DEFUN(__printf_fp, (s, info, args),
FILE *s AND CONST struct printf_info *info AND va_list *args)
{
int done = 0;
/* Decimal point character. */
CONST char *CONST decimal = _numeric_info->decimal_point;
LONG_DOUBLE fpnum; /* Input. */
int is_neg;
LONG_DOUBLE f; /* Fraction. */
int e; /* Base-2 exponent of the input. */
CONST int p = DBL_MANT_DIG; /* Internal precision. */
LONG_DOUBLE scale, scale10; /* Scale factor. */
LONG_DOUBLE loerr, hierr; /* Potential error in the fraction. */
int k; /* Digits to the left of the decimal point. */
int cutoff; /* Where to stop generating digits. */
LONG_DOUBLE r, r2, r10; /* Remainder. */
int roundup;
int low, high;
char digit;
int j;
char type = tolower (info->spec);
int prec = info->prec;
int width = info->width;
/* This algorithm has the nice property of not needing a buffer.
However, to get the padding right for %g format, we need to know
the length of the number before printing it. */
char *buf = __alloca ((prec > LDBL_DIG ? prec : LDBL_DIG) +
LDBL_MAX_10_EXP + 3); /* Dot, e, exp. sign. */
register char *bp = buf;
#define put(c) *bp++ = (c)
/* Fetch the argument value. */
if (info->is_long_double)
fpnum = va_arg (*args, LONG_DOUBLE);
else
fpnum = (LONG_DOUBLE) va_arg (*args, double);
#ifdef HANDLE_SPECIAL
/* Allow for machine-dependent (or floating point format-dependent) code. */
HANDLE_SPECIAL (done, s, info, fpnum);
#endif
#ifndef IS_NEGATIVE
#define IS_NEGATIVE(num) ((num) < 0)
#endif
is_neg = IS_NEGATIVE (fpnum);
if (is_neg)
fpnum = - fpnum;
if (prec == -1)
prec = 6;
if (type == 'g')
{
if (prec == 0)
prec = 1;
if (fpnum != 0)
{
if (fpnum < 1e-4)
type = 'e';
else
{
f = 10;
j = prec;
if (j > p)
j = p;
while (--j > 0)
{
f *= 10;
if (f > fpnum)
{
type = 'e';
break;
}
}
}
}
/* For 'g'/'G' format, the precision specifies "significant digits",
not digits to come after the decimal point. */
--prec;
}
if (fpnum == 0)
/* Special case for zero.
The general algorithm does not work for zero. */
{
put ('0');
if (tolower (info->spec) != 'g' || info->alt)
{
if (prec > 0 || info->alt)
put (*decimal);
while (--prec > 0)
put ('0');
}
if (type == 'e')
{
put (info->spec);
put ('+');
put ('0');
put ('0');
}
}
else
{
/* Split the number into a fraction and base-2 exponent. */
f = frexp (fpnum, &e);
/* Scale the fractional part by the highest possible number of
significant bits of fraction. We want to represent the
fractional part as a (very) large integer. */
f = ldexp (f, p);
cutoff = -prec;
roundup = 0;
if (e > p)
{
/* The exponent is bigger than the number of fractional digits. */
r = ldexp (f, e - p);
scale = 1;
/* The number is (E - P) factors of two larger than
the fraction can represent; this is the potential error. */
loerr = ldexp (1.0, e - p);
}
else
{
/* The number of fractional digits is greater than the exponent.
Scale by the difference factors of two. */
r = f;
scale = ldexp (1.0, p - e);
loerr = 1.0;
}
hierr = loerr;
/* Fixup. */
if (f == ldexp (1.0, p - 1))
{
/* Account for unequal gaps. */
hierr = ldexp (hierr, 1);
r = ldexp (r, 1);
scale = ldexp (scale, 1);
}
scale10 = ceil (scale / 10.0);
k = 0;
while (r < scale10)
{
--k;
r *= 10;
loerr *= 10;
hierr *= 10;
}
do
{
r2 = 2 * r;
while (r2 + hierr >= 2 * scale)
{
scale *= 10;
++k;
}
/* Perform any necessary adjustment of loerr and hierr to
take into account the formatting requirements. */
if (type == 'e')
cutoff += k; /* CutOffMode == "relative". */
/* Otherwise CutOffMode == "absolute". */
{ /* CutOffAdjust. */
int a = cutoff - k;
double y = scale;
while (a > 0)
{
y *= 10;
--a;
}
while (a < 0)
{
y = ceil (y / 10);
++a;
}
/* y == ceil (scale * pow (10.0, (double) (cutoff - k))) */
if (y > loerr)
loerr = y;
if (y > hierr)
{
hierr = y;
roundup = 1;
}
} /* End CutOffAdjust. */
} while (r2 + hierr >= 2 * scale);
/* End Fixup. */
/* First digit. */
--k;
r10 = r * 10;
digit = '0' + (unsigned int) floor (r10 / scale);
r = fmod (r10, scale);
loerr *= 10;
hierr *= 10;
low = 2 * r < loerr;
if (roundup)
high = 2 * r >= (2 * scale) - hierr;
else
high = 2 * r > (2 * scale) - hierr;
if (low || high || k == cutoff)
{
if ((high && !low) || (2 * r > scale))
++digit;
}
if (type == 'e')
{
/* Exponential notation. */
int expt = k; /* Base-10 exponent. */
/* Find the magnitude of the exponent. */
j = 1;
do
j *= 10;
while (j <= expt);
/* Write the first digit. */
put (digit);
if (low || high || k == cutoff)
{
if (prec > 0 || info->alt)
put (*decimal);
}
else
{
put (*decimal);
/* First post-decimal digit. */
--k;
r10 = r * 10;
digit = '0' + (unsigned int) floor (r10 / scale);
r = fmod (r10, scale);
loerr *= 10;
hierr *= 10;
low = 2 * r < loerr;
if (roundup)
high = 2 * r >= (2 * scale) - hierr;
else
high = 2 * r > (2 * scale) - hierr;
if (low || high || k == cutoff)
{
if ((high && !low) || (2 * r > scale))
++digit;
put (digit);
}
else
{
put (digit);
/* Remaining digits. */
while (1)
{
--k;
r10 = r * 10;
digit = '0' + (unsigned int) floor (r10 / scale);
r = fmod (r10, scale);
loerr *= 10;
hierr *= 10;
low = 2 * r < loerr;
if (roundup)
high = 2 * r >= (2 * scale) - hierr;
else
high = 2 * r > (2 * scale) - hierr;
if (low || high || k == cutoff)
{
if ((high && !low) || (2 * r > scale))
++digit;
put (digit);
break;
}
put (digit);
}
}
}
if (tolower (info->spec) != 'g' || info->alt)
/* Pad with zeros. */
while (k-- >= cutoff)
put ('0');
/* Write the exponent. */
put (isupper (info->spec) ? 'E' : 'e');
put (expt < 0 ? '-' : '+');
expt = abs (expt);
if (expt < 10)
/* Exponent always has at least two digits. */
put ('0');
do
{
j /= 10;
put ('0' + (expt / j));
expt %= j;
}
while (j > 1);
}
else
{
/* Decimal fraction notation. */
if (k < 0)
{
put ('0');
if (prec > 0 || info->alt)
put (*decimal);
}
/* Write leading fractional zeros. */
j = 0;
while (--j > k)
put ('0');
if (low || high || k == cutoff)
put (digit);
else
while (1)
{
put (digit);
--k;
digit = '0' + (unsigned int) floor ((r * 10) / scale);
r = fmod (r * 10, scale);
loerr *= 10;
hierr *= 10;
low = 2 * r < loerr;
if (roundup)
high = 2 * r >= (2 * scale) - hierr;
else
high = 2 * r > (2 * scale) - hierr;
if (low || high || k == cutoff)
{
if ((high && !low) || (2 * r > scale))
++digit;
put (digit);
break;
}
if (k == -1)
put (*decimal);
}
while (k > 0)
{
put ('0');
--k;
}
if (k == 0 && (prec > 0 || info->alt))
{
put (*decimal);
while (prec-- > 0)
put ('0');
}
}
}
#undef put
/* The number is all converted in BUF.
Now write it with sign and appropriate padding. */
if (is_neg || info->showsign || info->space)
--width;
width -= bp - buf;
if (!info->left && info->pad == ' ')
/* Pad with spaces on the left. */
while (width-- > 0)
outchar (' ');
/* Write the sign. */
if (is_neg)
outchar ('-');
else if (info->showsign)
outchar ('+');
else if (info->space)
outchar (' ');
if (!info->left && info->pad == '0')
/* Pad with zeros on the left. */
while (width-- > 0)
outchar ('0');
if (fwrite (buf, bp - buf, 1, s) != 1)
return -1;
done += bp - buf;
if (info->left)
/* Pad with spaces on the right. */
while (width-- > 0)
outchar (' ');
return done;
}

View File

@@ -0,0 +1,248 @@
/* Convert between signal names and numbers.
Copyright (C) 1990 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#include <stdio.h>
#include <signal.h>
#include "signame.h"
#ifdef __STDC__
#define CONST const
#else
#define CONST
#endif
#ifdef SYS_SIGLIST_MISSING
/* There is too much variation in Sys V signal numbers and names, so
we must initialize them at runtime. */
static CONST char undoc[] = "unknown signal";
CONST char *sys_siglist[NSIG];
#endif /* SYS_SIGLIST_MISSING */
/* Table of abbreviations for signals. Note: A given number can
appear more than once with different abbreviations. */
typedef struct
{
int number;
CONST char *abbrev;
} num_abbrev;
static num_abbrev sig_table[NSIG*2];
/* Number of elements of sig_table used. */
static int sig_table_nelts = 0;
/* Enter signal number NUMBER into the tables with ABBREV and NAME. */
static void
init_sig (number, abbrev, name)
int number;
CONST char *abbrev;
CONST char *name;
{
#ifdef SYS_SIGLIST_MISSING
sys_siglist[number] = name;
#endif
sig_table[sig_table_nelts].number = number;
sig_table[sig_table_nelts++].abbrev = abbrev;
}
static void
init_sigs ()
{
#ifdef SYS_SIGLIST_MISSING
int i;
/* Initialize signal names. */
for (i = 0; i < NSIG; i++)
sys_siglist[i] = undoc;
#endif /* SYS_SIGLIST_MISSING */
/* Initialize signal names. */
#if defined (SIGHUP)
init_sig (SIGHUP, "HUP", "Hangup");
#endif
#if defined (SIGINT)
init_sig (SIGINT, "INT", "Interrupt");
#endif
#if defined (SIGQUIT)
init_sig (SIGQUIT, "QUIT", "Quit");
#endif
#if defined (SIGILL)
init_sig (SIGILL, "ILL", "Illegal Instruction");
#endif
#if defined (SIGTRAP)
init_sig (SIGTRAP, "TRAP", "Trace/breakpoint trap");
#endif
/* If SIGIOT == SIGABRT, we want to print it as SIGABRT because
SIGABRT is in ANSI and POSIX.1 and SIGIOT isn't. */
#if defined (SIGABRT)
init_sig (SIGABRT, "ABRT", "Aborted");
#endif
#if defined (SIGIOT)
init_sig (SIGIOT, "IOT", "IOT trap");
#endif
#if defined (SIGEMT)
init_sig (SIGEMT, "EMT", "EMT trap");
#endif
#if defined (SIGFPE)
init_sig (SIGFPE, "FPE", "Floating point exception");
#endif
#if defined (SIGKILL)
init_sig (SIGKILL, "KILL", "Killed");
#endif
#if defined (SIGBUS)
init_sig (SIGBUS, "BUS", "Bus error");
#endif
#if defined (SIGSEGV)
init_sig (SIGSEGV, "SEGV", "Segmentation fault");
#endif
#if defined (SIGSYS)
init_sig (SIGSYS, "SYS", "Bad system call");
#endif
#if defined (SIGPIPE)
init_sig (SIGPIPE, "PIPE", "Broken pipe");
#endif
#if defined (SIGALRM)
init_sig (SIGALRM, "ALRM", "Alarm clock");
#endif
#if defined (SIGTERM)
init_sig (SIGTERM, "TERM", "Terminated");
#endif
#if defined (SIGUSR1)
init_sig (SIGUSR1, "USR1", "User defined signal 1");
#endif
#if defined (SIGUSR2)
init_sig (SIGUSR2, "USR2", "User defined signal 2");
#endif
/* If SIGCLD == SIGCHLD, we want to print it as SIGCHLD because that
is what is in POSIX.1. */
#if defined (SIGCHLD)
init_sig (SIGCHLD, "CHLD", "Child exited");
#endif
#if defined (SIGCLD)
init_sig (SIGCLD, "CLD", "Child exited");
#endif
#if defined (SIGPWR)
init_sig (SIGPWR, "PWR", "Power failure");
#endif
#if defined (SIGTSTP)
init_sig (SIGTSTP, "TSTP", "Stopped");
#endif
#if defined (SIGTTIN)
init_sig (SIGTTIN, "TTIN", "Stopped (tty input)");
#endif
#if defined (SIGTTOU)
init_sig (SIGTTOU, "TTOU", "Stopped (tty output)");
#endif
#if defined (SIGSTOP)
init_sig (SIGSTOP, "STOP", "Stopped (signal)");
#endif
#if defined (SIGXCPU)
init_sig (SIGXCPU, "XCPU", "CPU time limit exceeded");
#endif
#if defined (SIGXFSZ)
init_sig (SIGXFSZ, "XFSZ", "File size limit exceeded");
#endif
#if defined (SIGVTALRM)
init_sig (SIGVTALRM, "VTALRM", "Virtual timer expired");
#endif
#if defined (SIGPROF)
init_sig (SIGPROF, "PROF", "Profiling timer expired");
#endif
#if defined (SIGWINCH)
/* "Window size changed" might be more accurate, but even if that
is all that it means now, perhaps in the future it will be
extended to cover other kinds of window changes. */
init_sig (SIGWINCH, "WINCH", "Window changed");
#endif
#if defined (SIGCONT)
init_sig (SIGCONT, "CONT", "Continued");
#endif
#if defined (SIGURG)
init_sig (SIGURG, "URG", "Urgent I/O condition");
#endif
#if defined (SIGIO)
/* "I/O pending" has also been suggested. A disadvantage is
that signal only happens when the process has
asked for it, not everytime I/O is pending. Another disadvantage
is the confusion from giving it a different name than under Unix. */
init_sig (SIGIO, "IO", "I/O possible");
#endif
#if defined (SIGWIND)
init_sig (SIGWIND, "WIND", "SIGWIND");
#endif
#if defined (SIGPHONE)
init_sig (SIGPHONE, "PHONE", "SIGPHONE");
#endif
#if defined (SIGPOLL)
init_sig (SIGPOLL, "POLL", "I/O possible");
#endif
#if defined (SIGLOST)
init_sig (SIGLOST, "LOST", "Resource lost");
#endif
}
/* Return the abbreviation for signal NUMBER. */
char *
sig_abbrev (number)
int number;
{
int i;
if (sig_table_nelts == 0)
init_sigs ();
for (i = 0; i < sig_table_nelts; i++)
if (sig_table[i].number == number)
return (char *)sig_table[i].abbrev;
return NULL;
}
/* Return the signal number for an ABBREV, or -1 if there is no
signal by that name. */
int
sig_number (abbrev)
CONST char *abbrev;
{
int i;
if (sig_table_nelts == 0)
init_sigs ();
/* Skip over "SIG" if present. */
if (abbrev[0] == 'S' && abbrev[1] == 'I' && abbrev[2] == 'G')
abbrev += 3;
for (i = 0; i < sig_table_nelts; i++)
if (abbrev[0] == sig_table[i].abbrev[0]
&& strcmp (abbrev, sig_table[i].abbrev) == 0)
return sig_table[i].number;
return -1;
}
#if defined (SYS_SIGLIST_MISSING)
/* Print to standard error the name of SIGNAL, preceded by MESSAGE and
a colon, and followed by a newline. */
void
psignal (signal, message)
int signal;
CONST char *message;
{
if (signal <= 0 || signal >= NSIG)
fprintf (stderr, "%s: unknown signal", message);
else
fprintf (stderr, "%s: %s\n", message, sys_siglist[signal]);
}
#endif

View File

@@ -0,0 +1,42 @@
/* Convert between signal names and numbers.
Copyright (C) 1990 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING. If not, write to
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
#ifdef __STDC__
/* Return the abbreviation (e.g. ABRT, FPE, etc.) for signal NUMBER.
Do not return this as a const char *. The caller might want to
assign it to a char *. */
char *sig_abbrev (int number);
/* Return the signal number for an ABBREV, or -1 if there is no
signal by that name. */
int sig_number (const char *abbrev);
/* Print to standard error the name of SIGNAL, preceded by MESSAGE and
a colon, and followed by a newline. */
void psignal (int signal, const char *message);
/* Names for signals from 0 to NSIG-1. */
extern const char *sys_siglist[];
#else
char *sig_abbrev ();
int sig_number ();
void psignal ();
extern char *sys_siglist[];
#endif

View File

@@ -0,0 +1,35 @@
/* Copyright (C) 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
char *
DEFUN(stpcpy, (dest, src), char *dest AND CONST char *src)
{
register char *d = dest;
register CONST char *s = src;
do
*d++ = *s;
while (*s++ != '\0');
return d - 1;
}

View File

@@ -0,0 +1,51 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <ctype.h>
/* Compare S1 and S2, ignoring case, returning less than, equal to or
greater than zero if S1 is lexiographically less than,
equal to or greater than S2. */
int
DEFUN(strcasecmp, (s1, s2), CONST char *s1 AND CONST char *s2)
{
register CONST unsigned char *p1 = (CONST unsigned char *) s1;
register CONST unsigned char *p2 = (CONST unsigned char *) s2;
unsigned char c1, c2;
if (p1 == p2)
return 0;
do
{
c1 = tolower(*p1++);
c2 = tolower(*p2++);
if (c1 != c2)
break;
}
while (c1 != '\0');
if (c1 == '\0')
return -1;
else if (c2 == '\0')
return 1;
return c1 - c2;
}

View File

@@ -0,0 +1,48 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
/* Append SRC on the end of DEST. */
char *
DEFUN(strcat, (dest, src), char *dest AND CONST char *src)
{
register char *s1 = dest;
register CONST char *s2 = src;
reg_char c;
/* Find the end of the string. */
do
c = *s1++;
while (c != '\0');
/* Make S1 point before the next character, so we can increment
it while memory is read (wins on pipelined cpus). */
s1 -= 2;
do
{
c = *s2++;
*++s1 = c;
}
while (c != '\0');
return dest;
}

View File

@@ -0,0 +1,146 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Based on strlen implemention by Torbjorn Granlund (tege@sics.se),
with help from Dan Sahlin (dan@sics.se) and
bug fix and commentary by Jim Blandy (jimb@ai.mit.edu);
adaptation to strchr suggested by Dick Karpinski (dick@cca.ucsf.edu),
and implemented by Roland McGrath (roland@ai.mit.edu).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Find the first ocurrence of C in S. */
char *
DEFUN(strchr, (s, c), CONST char *s AND int c)
{
CONST unsigned char *char_ptr;
CONST unsigned long int *longword_ptr;
unsigned long int longword, magic_bits, charmask;
c = (unsigned char) c;
/* Handle the first few characters by reading one character at a time.
Do this until CHAR_PTR is aligned on a 4-byte border. */
for (char_ptr = (CONST unsigned char *) s;
((unsigned long int) char_ptr & 3) != 0; ++char_ptr)
{
if (*char_ptr == c)
return (char *) char_ptr;
else if (*char_ptr == '\0')
return NULL;
}
longword_ptr = (unsigned long int *) char_ptr;
/* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
the "holes." Note that there is a hole just to the left of
each byte, with an extra at the end:
bits: 01111110 11111110 11111110 11111111
bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
magic_bits = 0x7efefeff;
/* Set up a longword, each of whose bytes is C. */
charmask = (c << 24) | (c << 16) | (c << 8) | c;
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
if *any of the four* bytes in the longword in question are zero. */
for (;;)
{
/* We tentatively exit the loop if adding MAGIC_BITS to
LONGWORD fails to change any of the hole bits of LONGWORD.
1) Is this safe? Will it catch all the zero bytes?
Suppose there is a byte with all zeros. Any carry bits
propagating from its left will fall into the hole at its
least significant bit and stop. Since there will be no
carry from its most significant bit, the LSB of the
byte to the left will be unchanged, and the zero will be
detected.
2) Is this worthwhile? Will it ignore everything except
zero bytes? Suppose every byte of LONGWORD has a bit set
somewhere. There will be a carry into bit 8. If bit 8
is set, this will carry into bit 16. If bit 8 is clear,
one of bits 9-15 must be set, so there will be a carry
into bit 16. Similarly, there will be a carry into bit
24. If one of bits 24-30 is set, there will be a carry
into bit 31, so all of the hole bits will be changed.
The one misfire occurs when bits 24-30 are clear and bit
31 is set; in this case, the hole at bit 31 is not
changed. If we had access to the processor carry flag,
we could close this loophole by putting the fourth hole
at bit 32!
So it ignores everything except 128's, when they're aligned
properly.
3) But wait! Aren't we looking for C as well as zero?
Good point. So what we do is XOR LONGWORD with a longword,
each of whose bytes is C. This turns each byte that is C
into a zero. */
longword = *longword_ptr++;
/* Add MAGIC_BITS to LONGWORD. */
if ((((longword + magic_bits)
/* Set those bits that were unchanged by the addition. */
^ ~longword)
/* Look at only the hole bits. If any of the hole bits
are unchanged, most likely one of the bytes was a
zero. */
& ~magic_bits) != 0 ||
/* That caught zeroes. Now test for C. */
((((longword ^ charmask) + magic_bits) ^ ~(longword ^ charmask))
& ~magic_bits) != 0)
{
/* Which of the bytes was C or zero?
If none of them were, it was a misfire; continue the search. */
CONST unsigned char *cp = (CONST unsigned char *) (longword_ptr - 1);
if (*cp == c)
return (char *) cp;
else if (*cp == '\0')
return NULL;
if (*++cp == c)
return (char *) cp;
else if (*cp == '\0')
return NULL;
if (*++cp == c)
return (char *) cp;
else if (*cp == '\0')
return NULL;
if (*++cp == c)
return (char *) cp;
else if (*cp == '\0')
return NULL;
}
}
return NULL;
}

View File

@@ -0,0 +1,43 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
/* Compare S1 and S2, returning less than, equal to or
greater than zero if S1 is lexiographically less than,
equal to or greater than S2. */
int
DEFUN(strcmp, (p1, p2), CONST char *p1 AND CONST char *p2)
{
register CONST unsigned char *s1 = (CONST unsigned char *) p1;
register CONST unsigned char *s2 = (CONST unsigned char *) p2;
unsigned reg_char c1, c2;
do
{
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0')
return c1 - c2;
}
while (c1 == c2);
return c1 - c2;
}

View File

@@ -0,0 +1,41 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <string.h>
#include <memcopy.h>
/* Copy SRC to DEST. */
char *
DEFUN(strcpy, (dest, src), char *dest AND CONST char *src)
{
reg_char c;
char *s = (char *) src;
CONST ptrdiff_t off = dest - src - 1;
do
{
c = *s++;
s[off] = c;
}
while (c != '\0');
return dest;
}

View File

@@ -0,0 +1,38 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Return the length of the maximum inital segment of S
which contains no characters from REJECT. */
size_t
DEFUN(strcspn, (s, reject),
register CONST char *s AND register CONST char *reject)
{
register size_t count = 0;
while (*s != '\0')
if (strchr(reject, *s++) == NULL)
++count;
else
return count;
return count;
}

View File

@@ -0,0 +1,125 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
Written by Torbjorn Granlund (tege@sics.se),
with help from Dan Sahlin (dan@sics.se);
commentary by Jim Blandy (jimb@ai.mit.edu).
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Return the length of the null-terminated string STR. Scan for
the null terminator quickly by testing four bytes at a time. */
size_t
DEFUN(strlen, (str), CONST char *str)
{
CONST char *char_ptr;
CONST unsigned long int *longword_ptr;
unsigned long int longword, magic_bits, himagic, lomagic;
/* Handle the first few characters by reading one character at a time.
Do this until STR is aligned on a 4-byte border. */
for (char_ptr = str; ((unsigned long int) char_ptr & 3) != 0; ++char_ptr)
if (*char_ptr == 0)
return char_ptr - str;
longword_ptr = (unsigned long int *) char_ptr;
/* Bits 31, 24, 16, and 8 of this number are zero. Call these bits
the "holes." Note that there is a hole just to the left of
each byte, with an extra at the end:
bits: 01111110 11111110 11111110 11111111
bytes: AAAAAAAA BBBBBBBB CCCCCCCC DDDDDDDD
The 1-bits make sure that carries propagate to the next 0-bit.
The 0-bits provide holes for carries to fall into. */
magic_bits = 0x7efefeff;
himagic = 0x80808080;
lomagic = 0x01010101;
/* Instead of the traditional loop which tests each character,
we will test a longword at a time. The tricky part is testing
if *any of the four* bytes in the longword in question are zero. */
for (;;)
{
/* We tentatively exit the loop if adding MAGIC_BITS to
LONGWORD fails to change any of the hole bits of LONGWORD.
1) Is this safe? Will it catch all the zero bytes?
Suppose there is a byte with all zeros. Any carry bits
propagating from its left will fall into the hole at its
least significant bit and stop. Since there will be no
carry from its most significant bit, the LSB of the
byte to the left will be unchanged, and the zero will be
detected.
2) Is this worthwhile? Will it ignore everything except
zero bytes? Suppose every byte of LONGWORD has a bit set
somewhere. There will be a carry into bit 8. If bit 8
is set, this will carry into bit 16. If bit 8 is clear,
one of bits 9-15 must be set, so there will be a carry
into bit 16. Similarly, there will be a carry into bit
24. If one of bits 24-30 is set, there will be a carry
into bit 31, so all of the hole bits will be changed.
The one misfire occurs when bits 24-30 are clear and bit
31 is set; in this case, the hole at bit 31 is not
changed. If we had access to the processor carry flag,
we could close this loophole by putting the fourth hole
at bit 32!
So it ignores everything except 128's, when they're aligned
properly. */
longword = *longword_ptr++;
if (
#if 0
/* Add MAGIC_BITS to LONGWORD. */
(((longword + magic_bits)
/* Set those bits that were unchanged by the addition. */
^ ~longword)
/* Look at only the hole bits. If any of the hole bits
are unchanged, most likely one of the bytes was a
zero. */
& ~magic_bits)
#else
((longword - lomagic) & himagic)
#endif
!= 0)
{
/* Which of the bytes was the zero? If none of them were, it was
a misfire; continue the search. */
CONST char *cp = (CONST char *) (longword_ptr - 1);
if (cp[0] == 0)
return cp - str;
if (cp[1] == 0)
return cp - str + 1;
if (cp[2] == 0)
return cp - str + 2;
if (cp[3] == 0)
return cp - str + 3;
}
}
}

View File

@@ -0,0 +1,76 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
char *
DEFUN(strncat, (s1, s2, n), char *s1 AND CONST char *s2 AND size_t n)
{
reg_char c;
char *s = s1;
/* Find the end of S1. */
do
c = *s1++;
while (c != '\0');
/* Make S1 point before next character, so we can increment
it while memory is read (wins on pipelined cpus). */
s1 -= 2;
if (n >= 4)
{
size_t n4 = n >> 2;
do
{
c = *s2++;
*++s1 = c;
if (c == '\0')
return s;
c = *s2++;
*++s1 = c;
if (c == '\0')
return s;
c = *s2++;
*++s1 = c;
if (c == '\0')
return s;
c = *s2++;
*++s1 = c;
if (c == '\0')
return s;
} while (--n4 > 0);
n &= 3;
}
while (n > 0)
{
c = *s2++;
*++s1 = c;
if (c == '\0')
return s;
n--;
}
if (c != '\0')
*++s1 = '\0';
return s;
}

View File

@@ -0,0 +1,69 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
/* Compare no more than N characters of S1 and S2,
returning less than, equal to or greater than zero
if S1 is lexiographically less than, equal to or
greater than S2. */
int
DEFUN(strncmp, (s1, s2, n),
CONST char *s1 AND CONST char *s2 AND size_t n)
{
unsigned reg_char c1 = '\0';
unsigned reg_char c2 = '\0';
if (n >= 4)
{
size_t n4 = n >> 2;
do
{
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
} while (--n4 > 0);
n &= 3;
}
while (n > 0)
{
c1 = (unsigned char) *s1++;
c2 = (unsigned char) *s2++;
if (c1 == '\0' || c1 != c2)
return c1 - c2;
n--;
}
return c1 - c2;
}

View File

@@ -0,0 +1,82 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <memcopy.h>
char *
DEFUN(strncpy, (s1, s2, n), char *s1 AND CONST char *s2 AND size_t n)
{
reg_char c;
char *s = s1;
--s1;
if (n >= 4)
{
size_t n4 = n >> 2;
for (;;)
{
c = *s2++;
*++s1 = c;
if (c == '\0')
break;
c = *s2++;
*++s1 = c;
if (c == '\0')
break;
c = *s2++;
*++s1 = c;
if (c == '\0')
break;
c = *s2++;
*++s1 = c;
if (c == '\0')
break;
if (--n4 == 0)
goto last_chars;
}
n = n - (s1 - s) - 1;
if (n == 0)
return s;
goto zero_fill;
}
last_chars:
n &= 3;
if (n == 0)
return s;
do
{
c = *s2++;
*++s1 = c;
if (--n == 0)
return s;
}
while (c != '\0');
zero_fill:
do
*++s1 = '\0';
while (--n > 0);
return s;
}

View File

@@ -0,0 +1,35 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Find the first ocurrence in S of any character in ACCEPT. */
char *
DEFUN(strpbrk, (s, accept),
register CONST char *s AND register CONST char *accept)
{
while (*s != '\0')
if (strchr(accept, *s) == NULL)
++s;
else
return (char *) s;
return NULL;
}

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Find the last ocurrence of C in S. */
char *
DEFUN(strrchr, (s, c), CONST char *s AND int c)
{
register CONST char *found, *p;
c = (unsigned char) c;
/* Since strchr is fast, we use it rather than the obvious loop. */
if (c == '\0')
return strchr(s, '\0');
found = NULL;
while ((p = strchr(s, c)) != NULL)
{
found = p;
s = p + 1;
}
return (char *) found;
}

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
/* Return the length of the maximum initial segment
of S which contains only characters in ACCEPT. */
size_t
DEFUN(strspn, (s, accept), CONST char *s AND CONST char *accept)
{
register CONST char *p;
register CONST char *a;
register size_t count = 0;
for (p = s; *p != '\0'; ++p)
{
for (a = accept; *a != '\0'; ++a)
if (*p == *a)
break;
if (*a == '\0')
return count;
else
++count;
}
return count;
}

View File

@@ -0,0 +1,55 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <string.h>
/* Return the first ocurrence of NEEDLE in HAYSTACK. */
char *
DEFUN(strstr, (haystack, needle),
CONST char *CONST haystack AND
CONST char *CONST needle)
{
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;
if (needle_len == 0)
return (char *) haystack_end;
if ((size_t) (haystack_end - haystack) < needle_len)
return NULL;
for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
{
register CONST char *n = &needle[needle_last];
register CONST char *h = begin;
do
if (*h != *n)
goto loop;
while (--n >= needle && --h >= haystack);
return (char *) h;
loop:;
}
return NULL;
}

View File

@@ -0,0 +1,61 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <string.h>
#include <sys/utsname.h>
#include <unistd.h>
/* This file is created by the configuration process, and defines
LIBC_MACHINE to a string containing the machine configured for. */
#include <config-name.h>
/* Put information about the system in NAME. */
int
DEFUN(uname, (name), struct utsname *name)
{
extern CONST char __libc_release[], __libc_version[];
int save;
if (name == NULL)
{
errno = EINVAL;
return -1;
}
save = errno;
if (__gethostname (name->nodename, sizeof (name->nodename)) < 0)
{
if (errno == ENOSYS)
{
/* Hostname is meaningless for this machine. */
name->nodename[0] = '\0';
errno = save;
}
else
return -1;
}
strcpy (name->sysname, "GNU C Library");
strncpy (name->release, __libc_release, sizeof (name->release));
strncpy (name->version, __libc_version, sizeof (name->version));
strncpy (name->machine, LIBC_MACHINE, sizeof (name->machine));
return 0;
}

View File

@@ -0,0 +1,51 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/* This is generic in the sense that it will work with the BSD, SYSV,
or stub versions of getrlimit. Separate versions could be written
for efficiency, but it's probably not worth it. */
#include <ansidecl.h>
#include <sys/vlimit.h>
#include <sys/resource.h>
#include <errno.h>
/* Set the soft limit for RESOURCE to be VALUE.
Returns 0 for success, -1 for failure. */
int
DEFUN(vlimit, (resource, value),
enum __vlimit_resource resource AND int value)
{
if (resource >= LIM_CPU && resource <= LIM_MAXRSS)
{
/* The rlimit codes happen to each be one less
than the corresponding vlimit codes. */
enum __rlimit_resource rlimit_res =
(enum __rlimit_resource) ((int) resource - 1);
struct rlimit lims;
if (getrlimit(rlimit_res, &lims) < 0)
return -1;
lims.rlim_cur = value;
return setrlimit(rlimit_res, &lims);
}
errno = EINVAL;
return -1;
}

View File

@@ -0,0 +1,66 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <sys/vtimes.h>
#include <sys/resource.h>
/* Return the number of 1/VTIMES_UNITS_PER_SECOND-second
units in the `struct timeval' TV. */
#define TIMEVAL_TO_VTIMES(tv) \
((tv.tv_sec * VTIMES_UNITS_PER_SECOND) + \
(tv.tv_usec * VTIMES_UNITS_PER_SECOND / 1000000))
/* If VT is not NULL, write statistics for WHO into *VT.
Return 0 for success, -1 for failure. */
static int
DEFUN(vtimes_one, (vt, who),
struct vtimes *vt AND enum __rusage_who who)
{
if (vt != NULL)
{
struct rusage usage;
if (getrusage(who, &usage) < 0)
return -1;
vt->vm_utime = TIMEVAL_TO_VTIMES(usage.ru_utime);
vt->vm_stime = TIMEVAL_TO_VTIMES(usage.ru_stime);
vt->vm_idsrss = usage.ru_idrss + usage.ru_isrss;
vt->vm_majflt = usage.ru_majflt;
vt->vm_minflt = usage.ru_minflt;
vt->vm_nswap = usage.ru_nswap;
vt->vm_inblk = usage.ru_inblock;
vt->vm_oublk = usage.ru_oublock;
}
return 0;
}
/* If CURRENT is not NULL, write statistics for the current process into
*CURRENT. If CHILD is not NULL, write statistics for all terminated child
processes into *CHILD. Returns 0 for success, -1 for failure. */
int
DEFUN(vtimes, (current, child),
struct vtimes *current AND struct vtimes *child)
{
if (vtimes_one(current, RUSAGE_SELF) < 0 ||
vtimes_one(child, RUSAGE_CHILDREN) < 0)
return -1;
return 0;
}

View File

@@ -0,0 +1,405 @@
/* _memcopy.c -- subroutines for memory copy functions.
Copyright (C) 1991 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
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. */
/* BE VERY CAREFUL IF YOU CHANGE THIS CODE...! */
#include <ansidecl.h>
#include <stddef.h>
#include <memcopy.h>
/* _wordcopy_fwd_aligned -- Copy block beginning at SRCP to
block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
Both SRCP and DSTP should be aligned for memory operations on `op_t's. */
void
DEFUN(_wordcopy_fwd_aligned, (dstp, srcp, len),
long int dstp AND long int srcp AND size_t len)
{
op_t a0, a1;
switch (len % 8)
{
case 2:
a0 = ((op_t *) srcp)[0];
srcp -= 6 * OPSIZ;
dstp -= 7 * OPSIZ;
len += 6;
goto do1;
case 3:
a1 = ((op_t *) srcp)[0];
srcp -= 5 * OPSIZ;
dstp -= 6 * OPSIZ;
len += 5;
goto do2;
case 4:
a0 = ((op_t *) srcp)[0];
srcp -= 4 * OPSIZ;
dstp -= 5 * OPSIZ;
len += 4;
goto do3;
case 5:
a1 = ((op_t *) srcp)[0];
srcp -= 3 * OPSIZ;
dstp -= 4 * OPSIZ;
len += 3;
goto do4;
case 6:
a0 = ((op_t *) srcp)[0];
srcp -= 2 * OPSIZ;
dstp -= 3 * OPSIZ;
len += 2;
goto do5;
case 7:
a1 = ((op_t *) srcp)[0];
srcp -= 1 * OPSIZ;
dstp -= 2 * OPSIZ;
len += 1;
goto do6;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return;
a0 = ((op_t *) srcp)[0];
srcp -= 0 * OPSIZ;
dstp -= 1 * OPSIZ;
goto do7;
case 1:
a1 = ((op_t *) srcp)[0];
srcp -=-1 * OPSIZ;
dstp -= 0 * OPSIZ;
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
goto do8; /* No-op. */
}
do
{
do8:
a0 = ((op_t *) srcp)[0];
((op_t *) dstp)[0] = a1;
do7:
a1 = ((op_t *) srcp)[1];
((op_t *) dstp)[1] = a0;
do6:
a0 = ((op_t *) srcp)[2];
((op_t *) dstp)[2] = a1;
do5:
a1 = ((op_t *) srcp)[3];
((op_t *) dstp)[3] = a0;
do4:
a0 = ((op_t *) srcp)[4];
((op_t *) dstp)[4] = a1;
do3:
a1 = ((op_t *) srcp)[5];
((op_t *) dstp)[5] = a0;
do2:
a0 = ((op_t *) srcp)[6];
((op_t *) dstp)[6] = a1;
do1:
a1 = ((op_t *) srcp)[7];
((op_t *) dstp)[7] = a0;
srcp += 8 * OPSIZ;
dstp += 8 * OPSIZ;
len -= 8;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
((op_t *) dstp)[0] = a1;
}
/* _wordcopy_fwd_dest_aligned -- Copy block beginning at SRCP to
block beginning at DSTP with LEN `op_t' words (not LEN bytes!).
DSTP should be aligned for memory operations on `op_t's, but SRCP must
*not* be aligned. */
void
DEFUN(_wordcopy_fwd_dest_aligned, (dstp, srcp, len),
long int dstp AND long int srcp AND size_t len)
{
op_t a0, a1, a2, a3;
int sh_1, sh_2;
/* Calculate how to shift a word read at the memory operation
aligned srcp to make it aligned for copy. */
sh_1 = 8 * (srcp % OPSIZ);
sh_2 = 8 * OPSIZ - sh_1;
/* Make SRCP aligned by rounding it down to the beginning of the `op_t'
it points in the middle of. */
srcp &= -OPSIZ;
switch (len % 4)
{
case 2:
a1 = ((op_t *) srcp)[0];
a2 = ((op_t *) srcp)[1];
srcp -= 1 * OPSIZ;
dstp -= 3 * OPSIZ;
len += 2;
goto do1;
case 3:
a0 = ((op_t *) srcp)[0];
a1 = ((op_t *) srcp)[1];
srcp -= 0 * OPSIZ;
dstp -= 2 * OPSIZ;
len += 1;
goto do2;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return;
a3 = ((op_t *) srcp)[0];
a0 = ((op_t *) srcp)[1];
srcp -=-1 * OPSIZ;
dstp -= 1 * OPSIZ;
len += 0;
goto do3;
case 1:
a2 = ((op_t *) srcp)[0];
a3 = ((op_t *) srcp)[1];
srcp -=-2 * OPSIZ;
dstp -= 0 * OPSIZ;
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
goto do4; /* No-op. */
}
do
{
do4:
a0 = ((op_t *) srcp)[0];
((op_t *) dstp)[0] = MERGE (a2, sh_1, a3, sh_2);
do3:
a1 = ((op_t *) srcp)[1];
((op_t *) dstp)[1] = MERGE (a3, sh_1, a0, sh_2);
do2:
a2 = ((op_t *) srcp)[2];
((op_t *) dstp)[2] = MERGE (a0, sh_1, a1, sh_2);
do1:
a3 = ((op_t *) srcp)[3];
((op_t *) dstp)[3] = MERGE (a1, sh_1, a2, sh_2);
srcp += 4 * OPSIZ;
dstp += 4 * OPSIZ;
len -= 4;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
((op_t *) dstp)[0] = MERGE (a2, sh_1, a3, sh_2);
}
/* _wordcopy_bwd_aligned -- Copy block finishing right before
SRCP to block finishing right before DSTP with LEN `op_t' words
(not LEN bytes!). Both SRCP and DSTP should be aligned for memory
operations on `op_t's. */
void
DEFUN(_wordcopy_bwd_aligned, (dstp, srcp, len),
long int dstp AND long int srcp AND size_t len)
{
op_t a0, a1;
switch (len % 8)
{
case 2:
srcp -= 2 * OPSIZ;
dstp -= 1 * OPSIZ;
a0 = ((op_t *) srcp)[1];
len += 6;
goto do1;
case 3:
srcp -= 3 * OPSIZ;
dstp -= 2 * OPSIZ;
a1 = ((op_t *) srcp)[2];
len += 5;
goto do2;
case 4:
srcp -= 4 * OPSIZ;
dstp -= 3 * OPSIZ;
a0 = ((op_t *) srcp)[3];
len += 4;
goto do3;
case 5:
srcp -= 5 * OPSIZ;
dstp -= 4 * OPSIZ;
a1 = ((op_t *) srcp)[4];
len += 3;
goto do4;
case 6:
srcp -= 6 * OPSIZ;
dstp -= 5 * OPSIZ;
a0 = ((op_t *) srcp)[5];
len += 2;
goto do5;
case 7:
srcp -= 7 * OPSIZ;
dstp -= 6 * OPSIZ;
a1 = ((op_t *) srcp)[6];
len += 1;
goto do6;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return;
srcp -= 8 * OPSIZ;
dstp -= 7 * OPSIZ;
a0 = ((op_t *) srcp)[7];
goto do7;
case 1:
srcp -= 9 * OPSIZ;
dstp -= 8 * OPSIZ;
a1 = ((op_t *) srcp)[8];
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
goto do8; /* No-op. */
}
do
{
do8:
a0 = ((op_t *) srcp)[7];
((op_t *) dstp)[7] = a1;
do7:
a1 = ((op_t *) srcp)[6];
((op_t *) dstp)[6] = a0;
do6:
a0 = ((op_t *) srcp)[5];
((op_t *) dstp)[5] = a1;
do5:
a1 = ((op_t *) srcp)[4];
((op_t *) dstp)[4] = a0;
do4:
a0 = ((op_t *) srcp)[3];
((op_t *) dstp)[3] = a1;
do3:
a1 = ((op_t *) srcp)[2];
((op_t *) dstp)[2] = a0;
do2:
a0 = ((op_t *) srcp)[1];
((op_t *) dstp)[1] = a1;
do1:
a1 = ((op_t *) srcp)[0];
((op_t *) dstp)[0] = a0;
srcp -= 8 * OPSIZ;
dstp -= 8 * OPSIZ;
len -= 8;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
((op_t *) dstp)[7] = a1;
}
/* _wordcopy_bwd_dest_aligned -- Copy block finishing right
before SRCP to block finishing right before DSTP with LEN `op_t'
words (not LEN bytes!). DSTP should be aligned for memory
operations on `op_t', but SRCP must *not* be aligned. */
void
DEFUN(_wordcopy_bwd_dest_aligned, (dstp, srcp, len),
long int dstp AND long int srcp AND size_t len)
{
op_t a0, a1, a2, a3;
int sh_1, sh_2;
/* Calculate how to shift a word read at the memory operation
aligned srcp to make it aligned for copy. */
sh_1 = 8 * (srcp % OPSIZ);
sh_2 = 8 * OPSIZ - sh_1;
/* Make srcp aligned by rounding it down to the beginning of the op_t
it points in the middle of. */
srcp &= -OPSIZ;
srcp += OPSIZ;
switch (len % 4)
{
case 2:
srcp -= 3 * OPSIZ;
dstp -= 1 * OPSIZ;
a2 = ((op_t *) srcp)[2];
a1 = ((op_t *) srcp)[1];
len += 2;
goto do1;
case 3:
srcp -= 4 * OPSIZ;
dstp -= 2 * OPSIZ;
a3 = ((op_t *) srcp)[3];
a2 = ((op_t *) srcp)[2];
len += 1;
goto do2;
case 0:
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
return;
srcp -= 5 * OPSIZ;
dstp -= 3 * OPSIZ;
a0 = ((op_t *) srcp)[4];
a3 = ((op_t *) srcp)[3];
goto do3;
case 1:
srcp -= 6 * OPSIZ;
dstp -= 4 * OPSIZ;
a1 = ((op_t *) srcp)[5];
a0 = ((op_t *) srcp)[4];
len -= 1;
if (OP_T_THRES <= 3 * OPSIZ && len == 0)
goto do0;
goto do4; /* No-op. */
}
do
{
do4:
a3 = ((op_t *) srcp)[3];
((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
do3:
a2 = ((op_t *) srcp)[2];
((op_t *) dstp)[2] = MERGE (a3, sh_1, a0, sh_2);
do2:
a1 = ((op_t *) srcp)[1];
((op_t *) dstp)[1] = MERGE (a2, sh_1, a3, sh_2);
do1:
a0 = ((op_t *) srcp)[0];
((op_t *) dstp)[0] = MERGE (a1, sh_1, a2, sh_2);
srcp -= 4 * OPSIZ;
dstp -= 4 * OPSIZ;
len -= 4;
}
while (len != 0);
/* This is the right position for do0. Please don't move
it into the loop. */
do0:
((op_t *) dstp)[3] = MERGE (a0, sh_1, a1, sh_2);
}