diff options
| author | Paul Eggert | 2016-01-24 14:50:47 -0800 |
|---|---|---|
| committer | Paul Eggert | 2016-01-24 14:51:22 -0800 |
| commit | 1698036a43d9e2c55ead6216ea7156df8615da47 (patch) | |
| tree | 60bb61c907536ebc38c6b301fd754028b8a9b542 /lib | |
| parent | fbce4757a874cc43806eb41b8637538b101c3c69 (diff) | |
| download | emacs-1698036a43d9e2c55ead6216ea7156df8615da47.tar.gz emacs-1698036a43d9e2c55ead6216ea7156df8615da47.zip | |
Merge from gnulib
This incorporates:
2016-01-24 openat_proc_name: fix last '/' overwritten on OS/2 kLIBC
2016-01-24 closedir, dirfd, opendir: port to OpenSolaris 5.10
2016-01-15 detect utimes() correctly on OS/2 kLIBC
2016-01-15 openat_proc_name: port to OS/2 kLIBC
2016-01-14 stdint: check _INTPTR_T_DECLARED for intptr_t etc.
2016-01-14 opendir, closedir, dirfd, fdopendir: port to OS/2 kLIBC
2016-01-14 dup, dup2, fcntl: support a directory fd on OS/2 kLIBC
2016-01-14 binary-io: don't put fd in binary mode if a console on EMX
2016-01-14 sig2str: list all signals on FreeBSD >= 7
2016-01-13 acl-permissions: port to USE_ACL==0 platforms
2016-01-12 mktime: rename macro to avoid glibc clash
2016-01-12 Port "$@" to OpenIndiana ksh93
2016-01-12 Port Universal Time settings to strict POSIX
* build-aux/gitlog-to-changelog, build-aux/update-copyright:
* doc/misc/texinfo.tex, lib/acl-internal.c, lib/acl-internal.h:
* lib/binary-io.h, lib/dirent.in.h, lib/dirfd.c, lib/dup2.c:
* lib/fcntl.c, lib/fdopendir.c, lib/mktime.c, lib/openat-proc.c:
* lib/sig2str.h, lib/stdint.in.h, m4/dirfd.m4, m4/dup2.m4:
* m4/fcntl.m4, m4/utimes.m4:
Copy from gnulib.
* m4/gnulib-comp.m4: Regenerate.
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/acl-internal.c | 2 | ||||
| -rw-r--r-- | lib/acl-internal.h | 2 | ||||
| -rw-r--r-- | lib/binary-io.h | 2 | ||||
| -rw-r--r-- | lib/dirent.in.h | 7 | ||||
| -rw-r--r-- | lib/dirfd.c | 66 | ||||
| -rw-r--r-- | lib/dup2.c | 51 | ||||
| -rw-r--r-- | lib/fcntl.c | 87 | ||||
| -rw-r--r-- | lib/fdopendir.c | 36 | ||||
| -rw-r--r-- | lib/mktime.c | 12 | ||||
| -rw-r--r-- | lib/openat-proc.c | 144 | ||||
| -rw-r--r-- | lib/sig2str.h | 2 | ||||
| -rw-r--r-- | lib/stdint.in.h | 5 |
12 files changed, 351 insertions, 65 deletions
diff --git a/lib/acl-internal.c b/lib/acl-internal.c index 569e2f9c9e2..4de60c30ec1 100644 --- a/lib/acl-internal.c +++ b/lib/acl-internal.c | |||
| @@ -478,7 +478,7 @@ acl_nontrivial (int count, struct acl *entries) | |||
| 478 | void | 478 | void |
| 479 | free_permission_context (struct permission_context *ctx) | 479 | free_permission_context (struct permission_context *ctx) |
| 480 | { | 480 | { |
| 481 | #ifdef USE_ACL | 481 | #if USE_ACL |
| 482 | # if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | 482 | # if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ |
| 483 | if (ctx->acl) | 483 | if (ctx->acl) |
| 484 | acl_free (ctx->acl); | 484 | acl_free (ctx->acl); |
diff --git a/lib/acl-internal.h b/lib/acl-internal.h index 526e9f07788..636273e0fb4 100644 --- a/lib/acl-internal.h +++ b/lib/acl-internal.h | |||
| @@ -255,7 +255,7 @@ extern int acl_nontrivial (int count, struct acl *entries); | |||
| 255 | 255 | ||
| 256 | struct permission_context { | 256 | struct permission_context { |
| 257 | mode_t mode; | 257 | mode_t mode; |
| 258 | #ifdef USE_ACL | 258 | #if USE_ACL |
| 259 | # if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ | 259 | # if HAVE_ACL_GET_FILE /* Linux, FreeBSD, Mac OS X, IRIX, Tru64 */ |
| 260 | acl_t acl; | 260 | acl_t acl; |
| 261 | # if !HAVE_ACL_TYPE_EXTENDED | 261 | # if !HAVE_ACL_TYPE_EXTENDED |
diff --git a/lib/binary-io.h b/lib/binary-io.h index d5c82335707..9f17c0d3987 100644 --- a/lib/binary-io.h +++ b/lib/binary-io.h | |||
| @@ -60,7 +60,7 @@ set_binary_mode (int fd, int mode) | |||
| 60 | 60 | ||
| 61 | /* SET_BINARY (fd); | 61 | /* SET_BINARY (fd); |
| 62 | changes the file descriptor fd to perform binary I/O. */ | 62 | changes the file descriptor fd to perform binary I/O. */ |
| 63 | #ifdef __DJGPP__ | 63 | #if defined __DJGPP__ || defined __EMX__ |
| 64 | # include <unistd.h> /* declares isatty() */ | 64 | # include <unistd.h> /* declares isatty() */ |
| 65 | /* Avoid putting stdin/stdout in binary mode if it is connected to | 65 | /* Avoid putting stdin/stdout in binary mode if it is connected to |
| 66 | the console, because that would make it impossible for the user | 66 | the console, because that would make it impossible for the user |
diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 4c62737bdc6..65482d7b7ac 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h | |||
| @@ -158,6 +158,13 @@ _GL_WARN_ON_USE (closedir, "closedir is not portable - " | |||
| 158 | # endif | 158 | # endif |
| 159 | _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); | 159 | _GL_FUNCDECL_RPL (dirfd, int, (DIR *) _GL_ARG_NONNULL ((1))); |
| 160 | _GL_CXXALIAS_RPL (dirfd, int, (DIR *)); | 160 | _GL_CXXALIAS_RPL (dirfd, int, (DIR *)); |
| 161 | |||
| 162 | # ifdef __KLIBC__ | ||
| 163 | /* Gnulib internal hooks needed to maintain the dirfd metadata. */ | ||
| 164 | _GL_EXTERN_C int _gl_register_dirp_fd (int fd, DIR *dirp) | ||
| 165 | _GL_ARG_NONNULL ((2)); | ||
| 166 | _GL_EXTERN_C void _gl_unregister_dirp_fd (int fd); | ||
| 167 | # endif | ||
| 161 | # else | 168 | # else |
| 162 | # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd | 169 | # if defined __cplusplus && defined GNULIB_NAMESPACE && defined dirfd |
| 163 | /* dirfd is defined as a macro and not as a function. | 170 | /* dirfd is defined as a macro and not as a function. |
diff --git a/lib/dirfd.c b/lib/dirfd.c index 1ea2a6373db..a32584856a2 100644 --- a/lib/dirfd.c +++ b/lib/dirfd.c | |||
| @@ -22,11 +22,77 @@ | |||
| 22 | #include <dirent.h> | 22 | #include <dirent.h> |
| 23 | #include <errno.h> | 23 | #include <errno.h> |
| 24 | 24 | ||
| 25 | #ifdef __KLIBC__ | ||
| 26 | # include <stdlib.h> | ||
| 27 | # include <io.h> | ||
| 28 | |||
| 29 | static struct dirp_fd_list | ||
| 30 | { | ||
| 31 | DIR *dirp; | ||
| 32 | int fd; | ||
| 33 | struct dirp_fd_list *next; | ||
| 34 | } *dirp_fd_start = NULL; | ||
| 35 | |||
| 36 | /* Register fd associated with dirp to dirp_fd_list. */ | ||
| 37 | int | ||
| 38 | _gl_register_dirp_fd (int fd, DIR *dirp) | ||
| 39 | { | ||
| 40 | struct dirp_fd_list *new_dirp_fd = malloc (sizeof *new_dirp_fd); | ||
| 41 | if (!new_dirp_fd) | ||
| 42 | return -1; | ||
| 43 | |||
| 44 | new_dirp_fd->dirp = dirp; | ||
| 45 | new_dirp_fd->fd = fd; | ||
| 46 | new_dirp_fd->next = dirp_fd_start; | ||
| 47 | |||
| 48 | dirp_fd_start = new_dirp_fd; | ||
| 49 | |||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | /* Unregister fd from dirp_fd_list with closing it */ | ||
| 54 | void | ||
| 55 | _gl_unregister_dirp_fd (int fd) | ||
| 56 | { | ||
| 57 | struct dirp_fd_list *dirp_fd; | ||
| 58 | struct dirp_fd_list *dirp_fd_prev; | ||
| 59 | |||
| 60 | for (dirp_fd_prev = NULL, dirp_fd = dirp_fd_start; dirp_fd; | ||
| 61 | dirp_fd_prev = dirp_fd, dirp_fd = dirp_fd->next) | ||
| 62 | { | ||
| 63 | if (dirp_fd->fd == fd) | ||
| 64 | { | ||
| 65 | if (dirp_fd_prev) | ||
| 66 | dirp_fd_prev->next = dirp_fd->next; | ||
| 67 | else /* dirp_fd == dirp_fd_start */ | ||
| 68 | dirp_fd_start = dirp_fd_start->next; | ||
| 69 | |||
| 70 | close (fd); | ||
| 71 | free (dirp_fd); | ||
| 72 | break; | ||
| 73 | } | ||
| 74 | } | ||
| 75 | } | ||
| 76 | #endif | ||
| 77 | |||
| 25 | int | 78 | int |
| 26 | dirfd (DIR *dir_p) | 79 | dirfd (DIR *dir_p) |
| 27 | { | 80 | { |
| 28 | int fd = DIR_TO_FD (dir_p); | 81 | int fd = DIR_TO_FD (dir_p); |
| 29 | if (fd == -1) | 82 | if (fd == -1) |
| 83 | #ifndef __KLIBC__ | ||
| 30 | errno = ENOTSUP; | 84 | errno = ENOTSUP; |
| 85 | #else | ||
| 86 | { | ||
| 87 | struct dirp_fd_list *dirp_fd; | ||
| 88 | |||
| 89 | for (dirp_fd = dirp_fd_start; dirp_fd; dirp_fd = dirp_fd->next) | ||
| 90 | if (dirp_fd->dirp == dir_p) | ||
| 91 | return dirp_fd->fd; | ||
| 92 | |||
| 93 | errno = EINVAL; | ||
| 94 | } | ||
| 95 | #endif | ||
| 96 | |||
| 31 | return fd; | 97 | return fd; |
| 32 | } | 98 | } |
diff --git a/lib/dup2.c b/lib/dup2.c index c913f473adc..5d026f21fa7 100644 --- a/lib/dup2.c +++ b/lib/dup2.c | |||
| @@ -85,6 +85,57 @@ ms_windows_dup2 (int fd, int desired_fd) | |||
| 85 | 85 | ||
| 86 | # define dup2 ms_windows_dup2 | 86 | # define dup2 ms_windows_dup2 |
| 87 | 87 | ||
| 88 | # elif defined __KLIBC__ | ||
| 89 | |||
| 90 | # include <InnoTekLIBC/backend.h> | ||
| 91 | |||
| 92 | static int | ||
| 93 | klibc_dup2dirfd (int fd, int desired_fd) | ||
| 94 | { | ||
| 95 | int tempfd; | ||
| 96 | int dupfd; | ||
| 97 | |||
| 98 | tempfd = open ("NUL", O_RDONLY); | ||
| 99 | if (tempfd == -1) | ||
| 100 | return -1; | ||
| 101 | |||
| 102 | if (tempfd == desired_fd) | ||
| 103 | { | ||
| 104 | close (tempfd); | ||
| 105 | |||
| 106 | char path[_MAX_PATH]; | ||
| 107 | if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) | ||
| 108 | return -1; | ||
| 109 | |||
| 110 | return open(path, O_RDONLY); | ||
| 111 | } | ||
| 112 | |||
| 113 | dupfd = klibc_dup2dirfd (fd, desired_fd); | ||
| 114 | |||
| 115 | close (tempfd); | ||
| 116 | |||
| 117 | return dupfd; | ||
| 118 | } | ||
| 119 | |||
| 120 | static int | ||
| 121 | klibc_dup2 (int fd, int desired_fd) | ||
| 122 | { | ||
| 123 | int dupfd; | ||
| 124 | struct stat sbuf; | ||
| 125 | |||
| 126 | dupfd = dup2 (fd, desired_fd); | ||
| 127 | if (dupfd == -1 && errno == ENOTSUP \ | ||
| 128 | && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) | ||
| 129 | { | ||
| 130 | close (desired_fd); | ||
| 131 | |||
| 132 | return klibc_dup2dirfd (fd, desired_fd); | ||
| 133 | } | ||
| 134 | |||
| 135 | return dupfd; | ||
| 136 | } | ||
| 137 | |||
| 138 | # define dup2 klibc_dup2 | ||
| 88 | # endif | 139 | # endif |
| 89 | 140 | ||
| 90 | int | 141 | int |
diff --git a/lib/fcntl.c b/lib/fcntl.c index 1ccc5acea8e..fd17e962f8b 100644 --- a/lib/fcntl.c +++ b/lib/fcntl.c | |||
| @@ -162,6 +162,93 @@ dupfd (int oldfd, int newfd, int flags) | |||
| 162 | } | 162 | } |
| 163 | #endif /* W32 */ | 163 | #endif /* W32 */ |
| 164 | 164 | ||
| 165 | #ifdef __KLIBC__ | ||
| 166 | |||
| 167 | # define INCL_DOS | ||
| 168 | # include <os2.h> | ||
| 169 | |||
| 170 | static int | ||
| 171 | klibc_fcntl (int fd, int action, /* arg */...) | ||
| 172 | { | ||
| 173 | va_list arg_ptr; | ||
| 174 | int arg; | ||
| 175 | struct stat sbuf; | ||
| 176 | int result = -1; | ||
| 177 | |||
| 178 | va_start (arg_ptr, action); | ||
| 179 | arg = va_arg (arg_ptr, int); | ||
| 180 | result = fcntl (fd, action, arg); | ||
| 181 | /* EPERM for F_DUPFD, ENOTSUP for others */ | ||
| 182 | if (result == -1 && (errno == EPERM || errno == ENOTSUP) | ||
| 183 | && !fstat (fd, &sbuf) && S_ISDIR (sbuf.st_mode)) | ||
| 184 | { | ||
| 185 | ULONG ulMode; | ||
| 186 | |||
| 187 | switch (action) | ||
| 188 | { | ||
| 189 | case F_DUPFD: | ||
| 190 | /* Find available fd */ | ||
| 191 | while (fcntl (arg, F_GETFL) != -1 || errno != EBADF) | ||
| 192 | arg++; | ||
| 193 | |||
| 194 | result = dup2 (fd, arg); | ||
| 195 | break; | ||
| 196 | |||
| 197 | /* Using underlying APIs is right ? */ | ||
| 198 | case F_GETFD: | ||
| 199 | if (DosQueryFHState (fd, &ulMode)) | ||
| 200 | break; | ||
| 201 | |||
| 202 | result = (ulMode & OPEN_FLAGS_NOINHERIT) ? FD_CLOEXEC : 0; | ||
| 203 | break; | ||
| 204 | |||
| 205 | case F_SETFD: | ||
| 206 | if (arg & ~FD_CLOEXEC) | ||
| 207 | break; | ||
| 208 | |||
| 209 | if (DosQueryFHState (fd, &ulMode)) | ||
| 210 | break; | ||
| 211 | |||
| 212 | if (arg & FD_CLOEXEC) | ||
| 213 | ulMode |= OPEN_FLAGS_NOINHERIT; | ||
| 214 | else | ||
| 215 | ulMode &= ~OPEN_FLAGS_NOINHERIT; | ||
| 216 | |||
| 217 | /* Filter supported flags. */ | ||
| 218 | ulMode &= (OPEN_FLAGS_WRITE_THROUGH | OPEN_FLAGS_FAIL_ON_ERROR | ||
| 219 | | OPEN_FLAGS_NO_CACHE | OPEN_FLAGS_NOINHERIT); | ||
| 220 | |||
| 221 | if (DosSetFHState (fd, ulMode)) | ||
| 222 | break; | ||
| 223 | |||
| 224 | result = 0; | ||
| 225 | break; | ||
| 226 | |||
| 227 | case F_GETFL: | ||
| 228 | result = 0; | ||
| 229 | break; | ||
| 230 | |||
| 231 | case F_SETFL: | ||
| 232 | if (arg != 0) | ||
| 233 | break; | ||
| 234 | |||
| 235 | result = 0; | ||
| 236 | break; | ||
| 237 | |||
| 238 | default : | ||
| 239 | errno = EINVAL; | ||
| 240 | break; | ||
| 241 | } | ||
| 242 | } | ||
| 243 | |||
| 244 | va_end (arg_ptr); | ||
| 245 | |||
| 246 | return result; | ||
| 247 | } | ||
| 248 | |||
| 249 | # define fcntl klibc_fcntl | ||
| 250 | #endif | ||
| 251 | |||
| 165 | /* Perform the specified ACTION on the file descriptor FD, possibly | 252 | /* Perform the specified ACTION on the file descriptor FD, possibly |
| 166 | using the argument ARG further described below. This replacement | 253 | using the argument ARG further described below. This replacement |
| 167 | handles the following actions, and forwards all others on to the | 254 | handles the following actions, and forwards all others on to the |
diff --git a/lib/fdopendir.c b/lib/fdopendir.c index f30ab2431b5..c1f4dcbaca0 100644 --- a/lib/fdopendir.c +++ b/lib/fdopendir.c | |||
| @@ -62,6 +62,41 @@ static DIR *fd_clone_opendir (int, struct saved_cwd const *); | |||
| 62 | If this function returns successfully, FD is under control of the | 62 | If this function returns successfully, FD is under control of the |
| 63 | dirent.h system, and the caller should not close or modify the state of | 63 | dirent.h system, and the caller should not close or modify the state of |
| 64 | FD other than by the dirent.h functions. */ | 64 | FD other than by the dirent.h functions. */ |
| 65 | # ifdef __KLIBC__ | ||
| 66 | # include <InnoTekLIBC/backend.h> | ||
| 67 | |||
| 68 | DIR * | ||
| 69 | fdopendir (int fd) | ||
| 70 | { | ||
| 71 | char path[_MAX_PATH]; | ||
| 72 | DIR *dirp; | ||
| 73 | |||
| 74 | /* Get a path from fd */ | ||
| 75 | if (__libc_Back_ioFHToPath (fd, path, sizeof (path))) | ||
| 76 | return NULL; | ||
| 77 | |||
| 78 | dirp = opendir (path); | ||
| 79 | if (!dirp) | ||
| 80 | return NULL; | ||
| 81 | |||
| 82 | /* Unregister fd registered by opendir() */ | ||
| 83 | _gl_unregister_dirp_fd (dirfd (dirp)); | ||
| 84 | |||
| 85 | /* Register our fd */ | ||
| 86 | if (_gl_register_dirp_fd (fd, dirp)) | ||
| 87 | { | ||
| 88 | int saved_errno = errno; | ||
| 89 | |||
| 90 | closedir (dirp); | ||
| 91 | |||
| 92 | errno = saved_errno; | ||
| 93 | |||
| 94 | dirp = NULL; | ||
| 95 | } | ||
| 96 | |||
| 97 | return dirp; | ||
| 98 | } | ||
| 99 | # else | ||
| 65 | DIR * | 100 | DIR * |
| 66 | fdopendir (int fd) | 101 | fdopendir (int fd) |
| 67 | { | 102 | { |
| @@ -84,6 +119,7 @@ fdopendir (int fd) | |||
| 84 | 119 | ||
| 85 | return dir; | 120 | return dir; |
| 86 | } | 121 | } |
| 122 | # endif | ||
| 87 | 123 | ||
| 88 | /* Like fdopendir, except that if OLDER_DUPFD is not -1, it is known | 124 | /* Like fdopendir, except that if OLDER_DUPFD is not -1, it is known |
| 89 | to be a dup of FD which is less than FD - 1 and which will be | 125 | to be a dup of FD which is less than FD - 1 and which will be |
diff --git a/lib/mktime.c b/lib/mktime.c index adbf8d482ae..c9738d0daf9 100644 --- a/lib/mktime.c +++ b/lib/mktime.c | |||
| @@ -19,7 +19,7 @@ | |||
| 19 | 19 | ||
| 20 | /* Define this to have a standalone program to test this implementation of | 20 | /* Define this to have a standalone program to test this implementation of |
| 21 | mktime. */ | 21 | mktime. */ |
| 22 | /* #define DEBUG 1 */ | 22 | /* #define DEBUG_MKTIME 1 */ |
| 23 | 23 | ||
| 24 | #ifndef _LIBC | 24 | #ifndef _LIBC |
| 25 | # include <config.h> | 25 | # include <config.h> |
| @@ -38,13 +38,13 @@ | |||
| 38 | 38 | ||
| 39 | #include <string.h> /* For the real memcpy prototype. */ | 39 | #include <string.h> /* For the real memcpy prototype. */ |
| 40 | 40 | ||
| 41 | #if defined DEBUG && DEBUG | 41 | #if defined DEBUG_MKTIME && DEBUG_MKTIME |
| 42 | # include <stdio.h> | 42 | # include <stdio.h> |
| 43 | # include <stdlib.h> | 43 | # include <stdlib.h> |
| 44 | /* Make it work even if the system's libc has its own mktime routine. */ | 44 | /* Make it work even if the system's libc has its own mktime routine. */ |
| 45 | # undef mktime | 45 | # undef mktime |
| 46 | # define mktime my_mktime | 46 | # define mktime my_mktime |
| 47 | #endif /* DEBUG */ | 47 | #endif /* DEBUG_MKTIME */ |
| 48 | 48 | ||
| 49 | /* Some of the code in this file assumes that signed integer overflow | 49 | /* Some of the code in this file assumes that signed integer overflow |
| 50 | silently wraps around. This assumption can't easily be programmed | 50 | silently wraps around. This assumption can't easily be programmed |
| @@ -600,7 +600,7 @@ libc_hidden_def (mktime) | |||
| 600 | libc_hidden_weak (timelocal) | 600 | libc_hidden_weak (timelocal) |
| 601 | #endif | 601 | #endif |
| 602 | 602 | ||
| 603 | #if defined DEBUG && DEBUG | 603 | #if defined DEBUG_MKTIME && DEBUG_MKTIME |
| 604 | 604 | ||
| 605 | static int | 605 | static int |
| 606 | not_equal_tm (const struct tm *a, const struct tm *b) | 606 | not_equal_tm (const struct tm *a, const struct tm *b) |
| @@ -732,10 +732,10 @@ main (int argc, char **argv) | |||
| 732 | return status; | 732 | return status; |
| 733 | } | 733 | } |
| 734 | 734 | ||
| 735 | #endif /* DEBUG */ | 735 | #endif /* DEBUG_MKTIME */ |
| 736 | 736 | ||
| 737 | /* | 737 | /* |
| 738 | Local Variables: | 738 | Local Variables: |
| 739 | compile-command: "gcc -DDEBUG -I. -Wall -W -O2 -g mktime.c -o mktime" | 739 | compile-command: "gcc -DDEBUG_MKTIME -I. -Wall -W -O2 -g mktime.c -o mktime" |
| 740 | End: | 740 | End: |
| 741 | */ | 741 | */ |
diff --git a/lib/openat-proc.c b/lib/openat-proc.c index 15a8c799c80..1712340a002 100644 --- a/lib/openat-proc.c +++ b/lib/openat-proc.c | |||
| @@ -30,24 +30,21 @@ | |||
| 30 | #include <string.h> | 30 | #include <string.h> |
| 31 | #include <unistd.h> | 31 | #include <unistd.h> |
| 32 | 32 | ||
| 33 | #include "intprops.h" | 33 | #ifdef __KLIBC__ |
| 34 | 34 | # include <InnoTekLIBC/backend.h> | |
| 35 | #define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/%s" | 35 | #endif |
| 36 | |||
| 37 | #define PROC_SELF_FD_NAME_SIZE_BOUND(len) \ | ||
| 38 | (sizeof PROC_SELF_FD_FORMAT - sizeof "%d%s" \ | ||
| 39 | + INT_STRLEN_BOUND (int) + (len) + 1) | ||
| 40 | 36 | ||
| 37 | #include "intprops.h" | ||
| 41 | 38 | ||
| 42 | /* Set BUF to the expansion of PROC_SELF_FD_FORMAT, using FD and FILE | 39 | /* Set BUF to the name of the subfile of the directory identified by |
| 43 | respectively for %d and %s. If successful, return BUF if the | 40 | FD, where the subfile is named FILE. If successful, return BUF if |
| 44 | result fits in BUF, dynamically allocated memory otherwise. But | 41 | the result fits in BUF, dynamically allocated memory otherwise. |
| 45 | return NULL if /proc is not reliable, either because the operating | 42 | Return NULL (setting errno) on error. */ |
| 46 | system support is lacking or because memory is low. */ | ||
| 47 | char * | 43 | char * |
| 48 | openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) | 44 | openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) |
| 49 | { | 45 | { |
| 50 | static int proc_status = 0; | 46 | char *result = buf; |
| 47 | int dirlen; | ||
| 51 | 48 | ||
| 52 | /* Make sure the caller gets ENOENT when appropriate. */ | 49 | /* Make sure the caller gets ENOENT when appropriate. */ |
| 53 | if (!*file) | 50 | if (!*file) |
| @@ -56,47 +53,82 @@ openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) | |||
| 56 | return buf; | 53 | return buf; |
| 57 | } | 54 | } |
| 58 | 55 | ||
| 59 | if (! proc_status) | 56 | #ifndef __KLIBC__ |
| 60 | { | 57 | # define PROC_SELF_FD_FORMAT "/proc/self/fd/%d/" |
| 61 | /* Set PROC_STATUS to a positive value if /proc/self/fd is | 58 | { |
| 62 | reliable, and a negative value otherwise. Solaris 10 | 59 | enum { |
| 63 | /proc/self/fd mishandles "..", and any file name might expand | 60 | PROC_SELF_FD_DIR_SIZE_BOUND |
| 64 | to ".." after symbolic link expansion, so avoid /proc/self/fd | 61 | = (sizeof PROC_SELF_FD_FORMAT - (sizeof "%d" - 1) |
| 65 | if it mishandles "..". Solaris 10 has openat, but this | 62 | + INT_STRLEN_BOUND (int)) |
| 66 | problem is exhibited on code that built on Solaris 8 and | 63 | }; |
| 67 | running on Solaris 10. */ | 64 | |
| 68 | 65 | static int proc_status = 0; | |
| 69 | int proc_self_fd = open ("/proc/self/fd", | 66 | if (! proc_status) |
| 70 | O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); | 67 | { |
| 71 | if (proc_self_fd < 0) | 68 | /* Set PROC_STATUS to a positive value if /proc/self/fd is |
| 72 | proc_status = -1; | 69 | reliable, and a negative value otherwise. Solaris 10 |
| 73 | else | 70 | /proc/self/fd mishandles "..", and any file name might expand |
| 74 | { | 71 | to ".." after symbolic link expansion, so avoid /proc/self/fd |
| 75 | /* Detect whether /proc/self/fd/%i/../fd exists, where %i is the | 72 | if it mishandles "..". Solaris 10 has openat, but this |
| 76 | number of a file descriptor open on /proc/self/fd. On Linux, | 73 | problem is exhibited on code that built on Solaris 8 and |
| 77 | that name resolves to /proc/self/fd, which was opened above. | 74 | running on Solaris 10. */ |
| 78 | However, on Solaris, it may resolve to /proc/self/fd/fd, which | 75 | |
| 79 | cannot exist, since all names in /proc/self/fd are numeric. */ | 76 | int proc_self_fd = open ("/proc/self/fd", |
| 80 | char dotdot_buf[PROC_SELF_FD_NAME_SIZE_BOUND (sizeof "../fd" - 1)]; | 77 | O_SEARCH | O_DIRECTORY | O_NOCTTY | O_NONBLOCK); |
| 81 | sprintf (dotdot_buf, PROC_SELF_FD_FORMAT, proc_self_fd, "../fd"); | 78 | if (proc_self_fd < 0) |
| 82 | proc_status = access (dotdot_buf, F_OK) ? -1 : 1; | 79 | proc_status = -1; |
| 83 | close (proc_self_fd); | 80 | else |
| 84 | } | 81 | { |
| 85 | } | 82 | /* Detect whether /proc/self/fd/%i/../fd exists, where %i is the |
| 86 | 83 | number of a file descriptor open on /proc/self/fd. On Linux, | |
| 87 | if (proc_status < 0) | 84 | that name resolves to /proc/self/fd, which was opened above. |
| 88 | return NULL; | 85 | However, on Solaris, it may resolve to /proc/self/fd/fd, which |
| 89 | else | 86 | cannot exist, since all names in /proc/self/fd are numeric. */ |
| 90 | { | 87 | char dotdot_buf[PROC_SELF_FD_DIR_SIZE_BOUND + sizeof "../fd" - 1]; |
| 91 | size_t bufsize = PROC_SELF_FD_NAME_SIZE_BOUND (strlen (file)); | 88 | sprintf (dotdot_buf, PROC_SELF_FD_FORMAT "../fd", proc_self_fd); |
| 92 | char *result = buf; | 89 | proc_status = access (dotdot_buf, F_OK) ? -1 : 1; |
| 93 | if (OPENAT_BUFFER_SIZE < bufsize) | 90 | close (proc_self_fd); |
| 94 | { | 91 | } |
| 95 | result = malloc (bufsize); | 92 | } |
| 96 | if (! result) | 93 | |
| 97 | return NULL; | 94 | if (proc_status < 0) |
| 98 | } | 95 | return NULL; |
| 99 | sprintf (result, PROC_SELF_FD_FORMAT, fd, file); | 96 | else |
| 100 | return result; | 97 | { |
| 101 | } | 98 | size_t bufsize = PROC_SELF_FD_DIR_SIZE_BOUND + strlen (file); |
| 99 | if (OPENAT_BUFFER_SIZE < bufsize) | ||
| 100 | { | ||
| 101 | result = malloc (bufsize); | ||
| 102 | if (! result) | ||
| 103 | return NULL; | ||
| 104 | } | ||
| 105 | |||
| 106 | dirlen = sprintf (result, PROC_SELF_FD_FORMAT, fd); | ||
| 107 | } | ||
| 108 | } | ||
| 109 | #else | ||
| 110 | /* OS/2 kLIBC provides a function to retrieve a path from a fd. */ | ||
| 111 | { | ||
| 112 | char dir[_MAX_PATH]; | ||
| 113 | size_t bufsize; | ||
| 114 | |||
| 115 | if (__libc_Back_ioFHToPath (fd, dir, sizeof dir)) | ||
| 116 | return NULL; | ||
| 117 | |||
| 118 | dirlen = strlen (dir); | ||
| 119 | bufsize = dirlen + 1 + strlen (file) + 1; /* 1 for '/', 1 for null */ | ||
| 120 | if (OPENAT_BUFFER_SIZE < bufsize) | ||
| 121 | { | ||
| 122 | result = malloc (bufsize); | ||
| 123 | if (! result) | ||
| 124 | return NULL; | ||
| 125 | } | ||
| 126 | |||
| 127 | strcpy (result, dir); | ||
| 128 | result[dirlen++] = '/'; | ||
| 129 | } | ||
| 130 | #endif | ||
| 131 | |||
| 132 | strcpy (result + dirlen, file); | ||
| 133 | return result; | ||
| 102 | } | 134 | } |
diff --git a/lib/sig2str.h b/lib/sig2str.h index f3471702bac..2730774d165 100644 --- a/lib/sig2str.h +++ b/lib/sig2str.h | |||
| @@ -44,6 +44,8 @@ int str2sig (char const *, int *); | |||
| 44 | 44 | ||
| 45 | #if defined _sys_nsig | 45 | #if defined _sys_nsig |
| 46 | # define SIGNUM_BOUND (_sys_nsig - 1) | 46 | # define SIGNUM_BOUND (_sys_nsig - 1) |
| 47 | #elif defined _SIG_MAXSIG | ||
| 48 | # define SIGNUM_BOUND (_SIG_MAXSIG - 2) /* FreeBSD >= 7. */ | ||
| 47 | #elif defined NSIG | 49 | #elif defined NSIG |
| 48 | # define SIGNUM_BOUND (NSIG - 1) | 50 | # define SIGNUM_BOUND (NSIG - 1) |
| 49 | #else | 51 | #else |
diff --git a/lib/stdint.in.h b/lib/stdint.in.h index d2413917950..0bb9ad41b29 100644 --- a/lib/stdint.in.h +++ b/lib/stdint.in.h | |||
| @@ -288,12 +288,17 @@ typedef gl_uint_fast32_t gl_uint_fast16_t; | |||
| 288 | 288 | ||
| 289 | /* 7.18.1.4. Integer types capable of holding object pointers */ | 289 | /* 7.18.1.4. Integer types capable of holding object pointers */ |
| 290 | 290 | ||
| 291 | /* kLIBC's stdint.h defines _INTPTR_T_DECLARED and needs its own | ||
| 292 | definitions of intptr_t and uintptr_t (which use int and unsigned) | ||
| 293 | to avoid clashes with declarations of system functions like sbrk. */ | ||
| 294 | #ifndef _INTPTR_T_DECLARED | ||
| 291 | #undef intptr_t | 295 | #undef intptr_t |
| 292 | #undef uintptr_t | 296 | #undef uintptr_t |
| 293 | typedef long int gl_intptr_t; | 297 | typedef long int gl_intptr_t; |
| 294 | typedef unsigned long int gl_uintptr_t; | 298 | typedef unsigned long int gl_uintptr_t; |
| 295 | #define intptr_t gl_intptr_t | 299 | #define intptr_t gl_intptr_t |
| 296 | #define uintptr_t gl_uintptr_t | 300 | #define uintptr_t gl_uintptr_t |
| 301 | #endif | ||
| 297 | 302 | ||
| 298 | /* 7.18.1.5. Greatest-width integer types */ | 303 | /* 7.18.1.5. Greatest-width integer types */ |
| 299 | 304 | ||