adds a new module cloexec.
-2004-03-09 Paul Eggert <eggert@cs.ucla.edu>
+2004-03-29 Paul Eggert <eggert@twinsun.com>
+
+ * modules/getloadvg: Depend on cloexec and xalloc.
+
+2004-03-09 Paul Eggert <eggert@twinsun.com>
* modules/getopt: Add lib/getopt_int.h.
-2004-03-18 Paul Eggert <eggert@cs.ucla.edu>
+2004-03-29 Paul Eggert <eggert@twinsun.com>
+
+ Merge changes to getloadavg.c from coreutils and Emacs.
+
+ * lib/getloadavg.c [!defined HAVE_SETLOCALE] (setlocale):
+ Define to an expression, not to the empty string.
+ Include cloexec.h and xalloc.h.
+ (getloadavg): Restore LC_NUMERIC locale after setting it temporarily.
+ Use set_cloexec_flag rather than rolling our own.
+ * lib/cloexec.c, lib/cloexec.h: New files.
+
+2004-03-18 Paul Eggert <eggert@twinsun.com>
* getopt.h: Sync with libc CVS.
not on all platforms that have <wchar.h>.
* mbswidth.c: Include <stdio.h> and <time.h> before <wchar.h>.
-2004-03-09 Paul Eggert <eggert@cs.ucla.edu>
+2004-03-09 Paul Eggert <eggert@twinsun.com>
* argp-parse.c, getopt.c, getopt.h, getopt1.c:
Sync with libc CVS.
--- /dev/null
+/* closexec.c - set or clear the close-on-exec descriptor flag
+ Copyright (C) 1991, 2004 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; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ The code is taken from glibc/manual/llio.texi */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include "cloexec.h"
+
+#if HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+#if HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+
+#ifndef FD_CLOEXEC
+# define FD_CLOEXEC 1
+#endif
+
+/* Set the `FD_CLOEXEC' flag of DESC if VALUE is true,
+ or clear the flag if VALUE is false.
+ Return true on success, or false on error with `errno' set. */
+
+bool
+set_cloexec_flag (int desc, bool value)
+{
+#if defined F_GETFD && defined F_SETFD
+
+ int flags = fcntl (desc, F_GETFD, 0);
+ int newflags;
+
+ if (flags < 0)
+ return false;
+
+ newflags = (value ? flags | FD_CLOEXEC : flags & ~FD_CLOEXEC);
+
+ return (flags == newflags
+ || fcntl (desc, F_SETFD, newflags) != -1);
+
+#else
+
+ return true;
+
+#endif
+}
--- /dev/null
+#include <stdbool.h>
+bool set_cloexec_flag (int desc, bool value);
/* Get the system load averages.
Copyright (C) 1985, 1986, 1987, 1988, 1989, 1991, 1992, 1993, 1994,
- 1995, 1997, 1999, 2000, 2003 Free Software Foundation, Inc.
+ 1995, 1997, 1999, 2000, 2003, 2004 Free Software Foundation, Inc.
NOTE: The canonical source of this file is maintained with gnulib.
Bugs can be reported to bug-gnulib@gnu.org.
# include <locale.h>
#endif
#ifndef HAVE_SETLOCALE
-# define setlocale(Category, Locale) /* empty */
+# define setlocale(Category, Locale) ((char *) NULL)
#endif
+#include "cloexec.h"
+#include "xalloc.h"
+
#ifndef HAVE_GETLOADAVG
/* The existing Emacs configuration files define a macro called
char ldavgbuf[40];
double load_ave[3];
int fd, count;
+ char *old_locale;
fd = open (LINUX_LDAV_FILE, O_RDONLY);
if (fd == -1)
return -1;
/* The following sscanf must use the C locale. */
+ old_locale = xstrdup (setlocale (LC_NUMERIC, NULL));
setlocale (LC_NUMERIC, "C");
count = sscanf (ldavgbuf, "%lf %lf %lf",
&load_ave[0], &load_ave[1], &load_ave[2]);
- setlocale (LC_NUMERIC, "");
+ setlocale (LC_NUMERIC, old_locale);
+ free (old_locale);
if (count < 1)
return -1;
{
/* Set the channel to close on exec, so it does not
litter any child's descriptor table. */
-# ifdef F_SETFD
-# ifndef FD_CLOEXEC
-# define FD_CLOEXEC 1
-# endif
- (void) fcntl (channel, F_SETFD, FD_CLOEXEC);
-# endif
+ set_cloexec_flag (channel, true);
getloadavg_initialized = 1;
}
# else /* SUNOS_5 */
+2004-03-29 Paul Eggert <eggert@twinsun.com>
+
+ * cloexec.m4: New file.
+
2004-03-18 Paul Eggert <eggert@twinsun.com>
Bruno Haible <bruno@clisp.org>
--- /dev/null
+# cloexec.m4 serial 1
+dnl Copyright (C) 2004 Free Software Foundation, Inc.
+dnl This file is free software, distributed under the terms of the GNU
+dnl General Public License. As a special exception to the GNU General
+dnl Public License, this file may be distributed as part of a program
+dnl that contains a configuration script generated by Autoconf, under
+dnl the same distribution terms as the rest of that program.
+
+AC_DEFUN([gl_CLOEXEC],
+[
+ dnl Prerequisites of lib/cloexec.c.
+ AC_CHECK_HEADERS_ONCE(fcntl.h unistd.h)
+])
--- /dev/null
+Description:
+Set or clear the close-on-exec descriptor flag.
+
+Files:
+lib/cloexec.c
+lib/cloexec.h
+m4/cloexec.m4
+
+Depends-on:
+stdbool
+
+configure.ac:
+gl_CLOEXEC
+
+Makefile.am:
+lib_SOURCES += cloexec.c cloexec.h
+
+Include:
+"cloexec.h"
+
+Maintainer:
+Jim Meyering
m4/getloadavg.m4
Depends-on:
+cloexec
+xalloc
configure.ac:
gl_FUNC_GETLOADAVG