aboutsummaryrefslogtreecommitdiff
path: root/stdlib
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib')
-rw-r--r--stdlib/Makefile2
-rw-r--r--stdlib/canonicalize.c50
-rw-r--r--stdlib/rand_r.c49
3 files changed, 81 insertions, 20 deletions
diff --git a/stdlib/Makefile b/stdlib/Makefile
index 66f28ffe5c..9d5744fc78 100644
--- a/stdlib/Makefile
+++ b/stdlib/Makefile
@@ -32,7 +32,7 @@ routines := \
abs labs llabs \
div ldiv lldiv \
mblen mbstowcs mbtowc wcstombs wctomb \
- random random_r rand \
+ random random_r rand rand_r \
drand48 erand48 lrand48 nrand48 mrand48 jrand48 \
srand48 seed48 lcong48 \
drand48_r erand48_r lrand48_r nrand48_r mrand48_r jrand48_r \
diff --git a/stdlib/canonicalize.c b/stdlib/canonicalize.c
index 554e1b2cba..8c0074a11c 100644
--- a/stdlib/canonicalize.c
+++ b/stdlib/canonicalize.c
@@ -1,21 +1,21 @@
/* Return the canonical absolute name of a given file.
-Copyright (C) 1996 Free Software Foundation, Inc.
-This file is part of the GNU C Library.
+ Copyright (C) 1996 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 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.
+ 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. */
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include <assert.h>
#include <stdlib.h>
@@ -58,10 +58,22 @@ canonicalize (const char *name, char *resolved)
if (!resolved)
rpath = malloc (path_max);
- strcpy (rpath, "/");
- if (name[0] != '/' && !getcwd (rpath, path_max))
- goto error;
- dest = rpath + strlen (rpath);
+ if (name[0] != '/')
+ {
+ /* We don't write to RPATH directly since the application and
+ the library might disagree about the value for PATH_MAX. */
+ char tmpbuf[path_max];
+
+ if (!getcwd (rpath, path_max))
+ goto error;
+
+ dest = __stpcpy (rpath, tmpbuf);
+ }
+ else
+ {
+ rpath[0] = '/';
+ dest = rpath + 1;
+ }
for (start = end = name; *start; start = end)
{
@@ -164,9 +176,9 @@ error:
free (rpath);
return NULL;
}
-
weak_alias (canonicalize, realpath)
+
char *
canonicalize_file_name (const char *name)
{
diff --git a/stdlib/rand_r.c b/stdlib/rand_r.c
new file mode 100644
index 0000000000..3e0b8b2bc0
--- /dev/null
+++ b/stdlib/rand_r.c
@@ -0,0 +1,49 @@
+/* Reentrant random function frm POSIX.1c.
+ Copyright (C) 1996 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the GNU C Library; see the file COPYING.LIB. If not,
+ write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#include <stdlib.h>
+
+
+/* This algorithm is mentioned in the ISO C standard, here extended
+ for 32 bits. */
+int
+rand_r (unsigned int *seed)
+{
+ unsigned int next = *seed;
+ int result;
+
+ next *= 1103515245;
+ next += 12345;
+ result = (unsigned int) (next / 65536) % 2048;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 11;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ next *= 1103515245;
+ next += 12345;
+ result <<= 10;
+ result ^= (unsigned int) (next / 65536) % 1024;
+
+ *seed = next;
+
+ return result;
+}