aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
committerRoland McGrath <roland@gnu.org>1995-02-18 01:27:10 +0000
commit28f540f45bbacd939bfd07f213bcad2bf730b1bf (patch)
tree15f07c4c43d635959c6afee96bde71fb1b3614ee /stdlib
downloadglibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.tar.xz
glibc-28f540f45bbacd939bfd07f213bcad2bf730b1bf.zip
initial import
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile43
-rw-r--r--stdlib/abs.c30
-rw-r--r--stdlib/alloca.h44
-rw-r--r--stdlib/atexit.c65
-rw-r--r--stdlib/atof.c30
-rw-r--r--stdlib/atoi.c30
-rw-r--r--stdlib/atol.c30
-rw-r--r--stdlib/bsearch.c51
-rw-r--r--stdlib/div.c92
-rw-r--r--stdlib/exit.c70
-rw-r--r--stdlib/exit.h44
-rw-r--r--stdlib/labs.c31
-rw-r--r--stdlib/ldiv.c92
-rw-r--r--stdlib/mblen.c31
-rw-r--r--stdlib/mbstowcs.c78
-rw-r--r--stdlib/mbtowc.c84
-rw-r--r--stdlib/msort.c103
-rw-r--r--stdlib/on_exit.c37
-rw-r--r--stdlib/qsort.c243
-rw-r--r--stdlib/rand.c30
-rw-r--r--stdlib/random.c357
-rw-r--r--stdlib/stdlib.h289
-rw-r--r--stdlib/strtod.c1027
-rw-r--r--stdlib/strtof.c12
-rw-r--r--stdlib/strtol.c189
-rw-r--r--stdlib/strtold.c12
-rw-r--r--stdlib/strtoq.c22
-rw-r--r--stdlib/strtoul.c21
-rw-r--r--stdlib/strtouq.c22
-rw-r--r--stdlib/testdiv.c33
-rw-r--r--stdlib/testdiv.input2
-rw-r--r--stdlib/testmb.c69
-rw-r--r--stdlib/testrand.c51
-rw-r--r--stdlib/testsort.c38
-rw-r--r--stdlib/tst-strtod.c94
-rw-r--r--stdlib/tst-strtol.c127
-rw-r--r--stdlib/wcstombs.c77
-rw-r--r--stdlib/wctomb.c72
38 files changed, 3772 insertions, 0 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
new file mode 100644
index 0000000000..1a1498c662
--- /dev/null
+++ b/stdlib/Makefile
@@ -0,0 +1,43 @@
+# Copyright (C) 1991, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
+# This file is part of the GNU C Library.
+
+# The GNU C Library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Library General Public License as
+# published by the Free Software Foundation; either version 2 of the
+# License, or (at your option) any later version.
+
+# The GNU C Library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Library General Public License for more details.
+
+# You should have received a copy of the GNU Library General Public
+# License along with the GNU C Library; see the file COPYING.LIB. If
+# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+# Cambridge, MA 02139, USA.
+
+#
+# Makefile for stdlib routines
+#
+subdir := stdlib
+
+headers := stdlib.h alloca.h
+
+routines := \
+ atof atoi atol \
+ abort \
+ bsearch qsort msort \
+ getenv putenv setenv \
+ exit on_exit atexit \
+ abs labs \
+ div ldiv \
+ mblen mbstowcs mbtowc wcstombs wctomb \
+ random rand \
+ strtol strtoul strtoq strtouq \
+ strtof strtod strtold \
+ system
+
+distribute := exit.h
+tests := tst-strtol tst-strtod testmb testrand testsort testdiv
+
+include ../Rules
diff --git a/stdlib/abs.c b/stdlib/abs.c
new file mode 100644
index 0000000000..b8db100b41
--- /dev/null
+++ b/stdlib/abs.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+
+#undef abs
+
+/* Return the absolute value of I. */
+__CONSTVALUE
+int
+DEFUN(abs, (i), int i)
+{
+ return(i < 0 ? -i : i);
+}
diff --git a/stdlib/alloca.h b/stdlib/alloca.h
new file mode 100644
index 0000000000..4e9de464a3
--- /dev/null
+++ b/stdlib/alloca.h
@@ -0,0 +1,44 @@
+/* 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, 1992 Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#ifndef _ALLOCA_H
+#define _ALLOCA_H 1
+#include <features.h>
+
+#define __need_size_t
+#include <stddef.h>
+
+__BEGIN_DECLS
+
+/* Remove any previous definitions. */
+#undef __alloca
+#undef alloca
+
+/* Allocate a block that will be freed when the calling function exits. */
+extern __ptr_t __alloca __P ((size_t __size));
+extern __ptr_t alloca __P ((size_t __size));
+
+#ifdef __GNUC__
+#define __alloca(size) __builtin_alloca(size)
+#endif /* GCC. */
+
+#define alloca(size) __alloca(size)
+
+__END_DECLS
+
+#endif /* alloca.h */
diff --git a/stdlib/atexit.c b/stdlib/atexit.c
new file mode 100644
index 0000000000..a2ab453576
--- /dev/null
+++ b/stdlib/atexit.c
@@ -0,0 +1,65 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+#include "exit.h"
+
+
+/* Register FUNC to be executed by `exit'. */
+int
+DEFUN(atexit, (func), void EXFUN((*func), (NOARGS)))
+{
+ struct exit_function *new = __new_exitfn();
+
+ if (new == NULL)
+ return -1;
+
+ new->flavor = ef_at;
+ new->func.at = func;
+ return 0;
+}
+
+
+static struct exit_function_list fnlist = { NULL, 0, };
+struct exit_function_list *__exit_funcs = &fnlist;
+
+struct exit_function *
+DEFUN_VOID(__new_exitfn)
+{
+ register struct exit_function_list *l;
+
+ for (l = __exit_funcs; l != NULL; l = l->next)
+ {
+ register size_t i;
+ for (i = 0; i < l->idx; ++i)
+ if (l->fns[i].flavor == ef_free)
+ return &l->fns[i];
+ if (l->idx < sizeof(l->fns) / sizeof(l->fns[0]))
+ return &l->fns[l->idx++];
+ }
+
+ l = (struct exit_function_list *) malloc(sizeof(struct exit_function_list));
+ if (l == NULL)
+ return NULL;
+ l->next = __exit_funcs;
+ __exit_funcs = l;
+
+ l->idx = 1;
+ return &l->fns[0];
+}
diff --git a/stdlib/atof.c b/stdlib/atof.c
new file mode 100644
index 0000000000..79585464d1
--- /dev/null
+++ b/stdlib/atof.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+
+#undef atof
+
+
+/* Convert a string to a double. */
+double
+DEFUN(atof, (nptr), CONST char *nptr)
+{
+ return(strtod(nptr, (char **) NULL));
+}
diff --git a/stdlib/atoi.c b/stdlib/atoi.c
new file mode 100644
index 0000000000..9fe280cc3e
--- /dev/null
+++ b/stdlib/atoi.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+
+#undef atoi
+
+
+/* Convert a string to an int. */
+int
+DEFUN(atoi, (nptr), CONST char *nptr)
+{
+ return((int) strtol(nptr, (char **) NULL, 10));
+}
diff --git a/stdlib/atol.c b/stdlib/atol.c
new file mode 100644
index 0000000000..75f599c107
--- /dev/null
+++ b/stdlib/atol.c
@@ -0,0 +1,30 @@
+/* Copyright (C) 1991 Free Software Foundation, Inc.
+This file is part of the GNU C Library.
+
+The GNU C Library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Library General Public License as
+published by the Free Software Foundation; either version 2 of the
+License, or (at your option) any later version.
+
+The GNU C Library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+Library General Public License for more details.
+
+You should have received a copy of the GNU Library General Public
+License along with the GNU C Library; see the file COPYING.LIB. If
+not, write to the Free Software Foundation, Inc., 675 Mass Ave,
+Cambridge, MA 02139, USA. */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+
+#undef atol
+
+
+/* Convert a string to a long int. */
+long int
+DEFUN(atol, (nptr), CONST char *nptr)
+{
+ return(strtol(nptr, (char **) NULL, 10));
+}
diff --git a/stdlib/bsearch.c b/stdlib/bsearch.c
new file mode 100644
index 0000000000..d798eabd2b
--- /dev/null
+++ b/stdlib/bsearch.c
@@ -0,0 +1,51 @@
+/* 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 <stdlib.h>
+
+
+/* Perform a binary search for KEY in BASE which has NMEMB elements
+ of SIZE bytes each. The comparisons are done by (*COMPAR)(). */
+PTR
+DEFUN(bsearch, (key, base, nmemb, size, compar),
+ register CONST PTR key AND register CONST PTR base AND
+ size_t nmemb AND register size_t size AND
+ register int EXFUN((*compar), (CONST PTR, CONST PTR)))
+{
+ register size_t l, u, idx;
+ register CONST PTR p;
+ register int comparison;
+
+ l = 0;
+ u = nmemb;
+ while (l < u)
+ {
+ idx = (l + u) / 2;
+ p = (PTR) (((CONST char *) base) + (idx * size));
+ comparison = (*compar)(key, p);
+ if (comparison < 0)
+ u = idx;
+ else if (comparison > 0)
+ l = idx + 1;
+ else
+ return (PTR) p;
+ }
+
+ return NULL;
+}
diff --git a/stdlib/div.c b/stdlib/div.c
new file mode 100644
index 0000000000..5a0ee7da38
--- /dev/null
+++ b/stdlib/div.c
@@ -0,0 +1,92 @@
+/* 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. */
+
+/*
+ * Copyright (c) 1990 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Chris Torek.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#include <ansidecl.h>
+#include <stdlib.h>
+
+
+/* Return the `div_t' representation of NUMER over DENOM. */
+__CONSTVALUE
+div_t
+DEFUN(div, (numer, denom), int numer AND int denom)
+{
+ div_t result;
+
+ result.quot = numer / denom;
+ result.rem = numer % denom;