* lib/rand.c: New file, based on glibc/stdlib/rand.c.
* m4/rand.m4: New file.
* modules/rand: New file.
* doc/posix-functions/rand.texi: Mention the new module.
+2023-11-09 Bruno Haible <bruno@clisp.org>
+
+ rand: New module.
+ * lib/rand.c: New file, based on glibc/stdlib/rand.c.
+ * m4/rand.m4: New file.
+ * modules/rand: New file.
+ * doc/posix-functions/rand.texi: Mention the new module.
+
2023-11-09 Bruno Haible <bruno@clisp.org>
random: Fix multithread-safety bug on CheriBSD.
POSIX specification:@* @url{https://pubs.opengroup.org/onlinepubs/9699919799/functions/rand.html}
-Gnulib module: ---
+Gnulib module: rand
Portability problems fixed by Gnulib:
@itemize
+@item
+This function crashes when used in multithreaded programs on some platforms:
+CheriBSD.
@end itemize
Portability problems not fixed by Gnulib:
--- /dev/null
+/* Copyright (C) 1991-2023 Free Software Foundation, Inc.
+
+ This file is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as
+ published by the Free Software Foundation, either version 3 of the
+ License, or (at your option) any later version.
+
+ This file 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 Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with this program. If not, see <https://www.gnu.org/licenses/>. */
+
+#include <config.h>
+
+/* Specification. */
+#include <stdlib.h>
+
+#ifndef _LIBC
+# define __random random
+#endif
+
+/* Return a random integer between 0 and RAND_MAX. */
+int
+rand (void)
+{
+ return (int) __random ();
+}
--- /dev/null
+# rand.m4 serial 1
+dnl Copyright (C) 2023 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_RAND],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
+ dnl On CheriBSD, rand() lacks locking, leading to an out-of-bounds read
+ dnl inside random_r.
+ case "$host" in
+ aarch64c-*-freebsd*) REPLACE_RAND=1 ;;
+ esac
+])
--- /dev/null
+Description:
+global random number generator
+
+Files:
+lib/rand.c
+m4/rand.m4
+
+Depends-on:
+stdlib
+random [test $REPLACE_RAND = 1]
+
+configure.ac:
+gl_FUNC_RAND
+gl_CONDITIONAL([GL_COND_OBJ_RAND], [test $REPLACE_RAND = 1])
+gl_STDLIB_MODULE_INDICATOR([rand])
+
+Makefile.am:
+if GL_COND_OBJ_RAND
+lib_SOURCES += rand.c
+endif
+
+Include:
+<stdlib.h>
+
+License:
+LGPL
+
+Maintainer:
+glibc