summaryrefslogtreecommitdiff
path: root/sysdeps
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps')
-rw-r--r--sysdeps/generic/inttypes.h65
-rw-r--r--sysdeps/unix/dirstream.h9
-rw-r--r--sysdeps/unix/opendir.c45
-rw-r--r--sysdeps/unix/sysv/linux/getsysstats.c64
4 files changed, 69 insertions, 114 deletions
diff --git a/sysdeps/generic/inttypes.h b/sysdeps/generic/inttypes.h
index 3f1b316c09..bf0fffa5c2 100644
--- a/sysdeps/generic/inttypes.h
+++ b/sysdeps/generic/inttypes.h
@@ -323,13 +323,11 @@ extern uintmax_t wcstoumax (__const __gwchar_t *__restrict __nptr,
# if __WORDSIZE == 64
-/* Like `strtol' but convert to `intmax_t'. */
-# ifndef __strtol_internal_defined
extern long int __strtol_internal (__const char *__restrict __nptr,
char **__restrict __endptr,
- int __base, int __group) __THROW;
-# define __strtol_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `strtol' but convert to `intmax_t'. */
__extern_inline intmax_t
__NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
int base))
@@ -337,14 +335,12 @@ __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
return __strtol_internal (nptr, endptr, base, 0);
}
-/* Like `strtoul' but convert to `uintmax_t'. */
-# ifndef __strtoul_internal_defined
extern unsigned long int __strtoul_internal (__const char *
__restrict __nptr,
char ** __restrict __endptr,
- int __base, int __group) __THROW;
-# define __strtoul_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `strtoul' but convert to `uintmax_t'. */
__extern_inline uintmax_t
__NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
int base))
@@ -352,13 +348,11 @@ __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
return __strtoul_internal (nptr, endptr, base, 0);
}
-/* Like `wcstol' but convert to `intmax_t'. */
-# ifndef __wcstol_internal_defined
extern long int __wcstol_internal (__const __gwchar_t * __restrict __nptr,
__gwchar_t **__restrict __endptr,
- int __base, int __group) __THROW;
-# define __wcstol_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `wcstol' but convert to `intmax_t'. */
__extern_inline intmax_t
__NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
__gwchar_t **__restrict endptr, int base))
@@ -366,16 +360,13 @@ __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
return __wcstol_internal (nptr, endptr, base, 0);
}
-
-/* Like `wcstoul' but convert to `uintmax_t'. */
-# ifndef __wcstoul_internal_defined
extern unsigned long int __wcstoul_internal (__const __gwchar_t *
__restrict __nptr,
__gwchar_t **
__restrict __endptr,
- int __base, int __group) __THROW;
-# define __wcstoul_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `wcstoul' but convert to `uintmax_t'. */
__extern_inline uintmax_t
__NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
__gwchar_t **__restrict endptr, int base))
@@ -385,14 +376,12 @@ __NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
# else /* __WORDSIZE == 32 */
-/* Like `strtol' but convert to `intmax_t'. */
-# ifndef __strtoll_internal_defined
__extension__
extern long long int __strtoll_internal (__const char *__restrict __nptr,
char **__restrict __endptr,
- int __base, int __group) __THROW;
-# define __strtoll_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `strtol' but convert to `intmax_t'. */
__extern_inline intmax_t
__NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
int base))
@@ -400,17 +389,15 @@ __NTH (strtoimax (__const char *__restrict nptr, char **__restrict endptr,
return __strtoll_internal (nptr, endptr, base, 0);
}
-/* Like `strtoul' but convert to `uintmax_t'. */
-# ifndef __strtoull_internal_defined
__extension__
extern unsigned long long int __strtoull_internal (__const char *
__restrict __nptr,
char **
__restrict __endptr,
int __base,
- int __group) __THROW;
-# define __strtoull_internal_defined 1
-# endif
+ int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `strtoul' but convert to `uintmax_t'. */
__extern_inline uintmax_t
__NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
int base))
@@ -418,15 +405,13 @@ __NTH (strtoumax (__const char *__restrict nptr, char **__restrict endptr,
return __strtoull_internal (nptr, endptr, base, 0);
}
-/* Like `wcstol' but convert to `intmax_t'. */
-# ifndef __wcstoll_internal_defined
__extension__
extern long long int __wcstoll_internal (__const __gwchar_t *
__restrict __nptr,
__gwchar_t **__restrict __endptr,
- int __base, int __group) __THROW;
-# define __wcstoll_internal_defined 1
-# endif
+ int __base, int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `wcstol' but convert to `intmax_t'. */
__extern_inline intmax_t
__NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
__gwchar_t **__restrict endptr, int base))
@@ -435,17 +420,15 @@ __NTH (wcstoimax (__const __gwchar_t *__restrict nptr,
}
-/* Like `wcstoul' but convert to `uintmax_t'. */
-# ifndef __wcstoull_internal_defined
__extension__
extern unsigned long long int __wcstoull_internal (__const __gwchar_t *
__restrict __nptr,
__gwchar_t **
__restrict __endptr,
int __base,
- int __group) __THROW;
-# define __wcstoull_internal_defined 1
-# endif
+ int __group)
+ __THROW __nonnull ((1)) __wur;
+/* Like `wcstoul' but convert to `uintmax_t'. */
__extern_inline uintmax_t
__NTH (wcstoumax (__const __gwchar_t *__restrict nptr,
__gwchar_t **__restrict endptr, int base))
diff --git a/sysdeps/unix/dirstream.h b/sysdeps/unix/dirstream.h
index a1f74473c6..8303f07fab 100644
--- a/sysdeps/unix/dirstream.h
+++ b/sysdeps/unix/dirstream.h
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 1995, 1996 Free Software Foundation, Inc.
+/* Copyright (C) 1993, 1995, 1996, 2007 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
@@ -17,7 +17,6 @@
02111-1307 USA. */
#ifndef _DIRSTREAM_H
-
#define _DIRSTREAM_H 1
#include <sys/types.h>
@@ -33,14 +32,16 @@ struct __dirstream
{
int fd; /* File descriptor. */
- char *data; /* Directory block. */
+ __libc_lock_define (, lock) /* Mutex lock for this structure. */
+
size_t allocation; /* Space allocated for the block. */
size_t size; /* Total valid data in the block. */
size_t offset; /* Current offset into the block. */
off_t filepos; /* Position of next entry to read. */
- __libc_lock_define (, lock) /* Mutex lock for this structure. */
+ /* Directory block. */
+ char data[0] __attribute__ ((aligned (__alignof__ (void*))));
};
#define _DIR_dirfd(dirp) ((dirp)->fd)
diff --git a/sysdeps/unix/opendir.c b/sysdeps/unix/opendir.c
index 59772cda75..0a116247d2 100644
--- a/sysdeps/unix/opendir.c
+++ b/sysdeps/unix/opendir.c
@@ -31,6 +31,7 @@
#include <dirstream.h>
#include <not-cancel.h>
+#include <kernel-features.h>
/* opendir() must not accidentally open something other than a directory.
@@ -110,7 +111,11 @@ __opendir (const char *name)
}
}
- int fd = open_not_cancel_2 (name, O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE);
+ int flags = O_RDONLY|O_NDELAY|EXTRA_FLAGS|O_LARGEFILE;
+#ifdef O_CLOEXEC
+ flags |= O_CLOEXEC;
+#endif
+ int fd = open_not_cancel_2 (name, flags);
if (__builtin_expect (fd, 0) < 0)
return NULL;
@@ -138,12 +143,33 @@ __opendir (const char *name)
weak_alias (__opendir, opendir)
+#ifdef __ASSUME_O_CLOEXEC
+# define check_have_o_cloexec(fd) 1
+#else
+static int
+check_have_o_cloexec (int fd)
+{
+ if (__have_o_cloexec == 0)
+ __have_o_cloexec = (__fcntl (fd, F_GETFD, 0) & FD_CLOEXEC) == 0 ? -1 : 1;
+ return __have_o_cloexec > 0;
+}
+#endif
+
+
DIR *
internal_function
__alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
{
- if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
- goto lose;
+ /* We always have to set the close-on-exit flag if the user provided
+ the file descriptor. Otherwise only if we have no working
+ O_CLOEXEC support. */
+#ifdef O_CLOEXEC
+ if (! close_fd || ! check_have_o_cloexec (fd))
+#endif
+ {
+ if (__builtin_expect (__fcntl (fd, F_SETFD, FD_CLOEXEC), 0) < 0)
+ goto lose;
+ }
size_t allocation;
#ifdef _STATBUF_ST_BLKSIZE
@@ -155,9 +181,7 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
allocation = (BUFSIZ < sizeof (struct dirent64)
? sizeof (struct dirent64) : BUFSIZ);
- const int pad = -sizeof (DIR) % __alignof__ (struct dirent64);
-
- DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation + pad);
+ DIR *dirp = (DIR *) malloc (sizeof (DIR) + allocation);
if (dirp == NULL)
lose:
{
@@ -169,14 +193,15 @@ __alloc_dir (int fd, bool close_fd, const struct stat64 *statp)
}
return NULL;
}
- memset (dirp, '\0', sizeof (DIR));
- dirp->data = (char *) (dirp + 1) + pad;
- dirp->allocation = allocation;
- dirp->fd = fd;
+ dirp->fd = fd;
#ifndef NOT_IN_libc
__libc_lock_init (dirp->lock);
#endif
+ dirp->allocation = allocation;
+ dirp->size = 0;
+ dirp->offset = 0;
+ dirp->filepos = 0;
return dirp;
}
diff --git a/sysdeps/unix/sysv/linux/getsysstats.c b/sysdeps/unix/sysv/linux/getsysstats.c
index ee7a539a6f..6d4c9c06e8 100644
--- a/sysdeps/unix/sysv/linux/getsysstats.c
+++ b/sysdeps/unix/sysv/linux/getsysstats.c
@@ -68,9 +68,11 @@
#endif
-static int
-count_processors_in_proc (void)
+int
+__get_nprocs ()
{
+ /* XXX Here will come a test for the new system call. */
+
char buffer[8192];
int result = 1;
@@ -102,62 +104,6 @@ count_processors_in_proc (void)
return result;
}
-
-
-int
-__get_nprocs ()
-{
- /* XXX Here will come a test for the new system call. */
-
- /* Try to use the sysfs filesystem. It has actual information about
- online processors. */
- DIR *dir = __opendir ("/sys/devices/system/cpu");
- if (dir != NULL)
- {
- int dfd = dirfd (dir);
- int count = 0;
- struct dirent64 *d;
-
- while ((d = __readdir64 (dir)) != NULL)
- /* NB: the sysfs has d_type support. */
- if (d->d_type == DT_DIR && strncmp (d->d_name, "cpu", 3) == 0)
- {
- char *endp;
- unsigned long int nr = strtoul (d->d_name + 3, &endp, 10);
- if (nr != ULONG_MAX && endp != d->d_name + 3 && *endp == '\0')
- {
- /* Try reading the online file. */
- char oname[_D_ALLOC_NAMLEN (d) + sizeof "/online"];
- strcpy (stpcpy (oname, d->d_name), "/online");
-
- /* We unconditionally use openat since the "online"
- file became readable only after the openat system
- call was introduced. */
- char buf[1];
- int fd = openat_not_cancel_3 (dfd, oname, O_RDONLY);
-
- /* If we cannot read the online file we have to assume
- the CPU is online. */
- if (fd < 0)
- ++count;
- else
- {
- if (read_not_cancel (fd, buf, sizeof (buf)) < 0
- || buf[0] == '1')
- ++count;
-
- close_not_cancel_no_status (fd);
- }
- }
- }
-
- __closedir (dir);
-
- return count;
- }
-
- return count_processors_in_proc ();
-}
weak_alias (__get_nprocs, get_nprocs)
@@ -206,7 +152,7 @@ __get_nprocs_conf ()
fclose (fp);
}
#else
- result = count_processors_in_proc ();
+ result = __get_nprocs ();
#endif
return result;