aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2016-01-24 14:50:47 -0800
committerPaul Eggert2016-01-24 14:51:22 -0800
commit1698036a43d9e2c55ead6216ea7156df8615da47 (patch)
tree60bb61c907536ebc38c6b301fd754028b8a9b542
parentfbce4757a874cc43806eb41b8637538b101c3c69 (diff)
downloademacs-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.
-rwxr-xr-xbuild-aux/gitlog-to-changelog4
-rwxr-xr-xbuild-aux/update-copyright4
-rw-r--r--doc/misc/texinfo.tex25
-rw-r--r--lib/acl-internal.c2
-rw-r--r--lib/acl-internal.h2
-rw-r--r--lib/binary-io.h2
-rw-r--r--lib/dirent.in.h7
-rw-r--r--lib/dirfd.c66
-rw-r--r--lib/dup2.c51
-rw-r--r--lib/fcntl.c87
-rw-r--r--lib/fdopendir.c36
-rw-r--r--lib/mktime.c12
-rw-r--r--lib/openat-proc.c144
-rw-r--r--lib/sig2str.h2
-rw-r--r--lib/stdint.in.h5
-rw-r--r--m4/dirfd.m416
-rw-r--r--m4/dup2.m414
-rw-r--r--m4/fcntl.m413
-rw-r--r--m4/gnulib-comp.m43
-rw-r--r--m4/utimes.m422
20 files changed, 424 insertions, 93 deletions
diff --git a/build-aux/gitlog-to-changelog b/build-aux/gitlog-to-changelog
index a42650478a2..a2513d0efc7 100755
--- a/build-aux/gitlog-to-changelog
+++ b/build-aux/gitlog-to-changelog
@@ -1,9 +1,9 @@
1eval '(exit $?0)' && eval 'exec perl -wS "$0" ${1+"$@"}' 1eval '(exit $?0)' && eval 'exec perl -wS "$0" "$@"'
2 & eval 'exec perl -wS "$0" $argv:q' 2 & eval 'exec perl -wS "$0" $argv:q'
3 if 0; 3 if 0;
4# Convert git log output to ChangeLog format. 4# Convert git log output to ChangeLog format.
5 5
6my $VERSION = '2016-01-11 22:04'; # UTC 6my $VERSION = '2016-01-12 23:09'; # UTC
7# The definition above must lie within the first 8 lines in order 7# The definition above must lie within the first 8 lines in order
8# for the Emacs time-stamp write hook (at end) to update it. 8# for the Emacs time-stamp write hook (at end) to update it.
9# If you change this file with Emacs, please let the write hook 9# If you change this file with Emacs, please let the write hook
diff --git a/build-aux/update-copyright b/build-aux/update-copyright
index 8c6ee1fdd3c..17ee6b14d11 100755
--- a/build-aux/update-copyright
+++ b/build-aux/update-copyright
@@ -1,9 +1,9 @@
1eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" ${1+"$@"}' 1eval '(exit $?0)' && eval 'exec perl -wS -0777 -pi "$0" "$@"'
2 & eval 'exec perl -wS -0777 -pi "$0" $argv:q' 2 & eval 'exec perl -wS -0777 -pi "$0" $argv:q'
3 if 0; 3 if 0;
4# Update an FSF copyright year list to include the current year. 4# Update an FSF copyright year list to include the current year.
5 5
6my $VERSION = '2016-01-11.22:04'; # UTC 6my $VERSION = '2016-01-12.23:13'; # UTC
7 7
8# Copyright (C) 2009-2016 Free Software Foundation, Inc. 8# Copyright (C) 2009-2016 Free Software Foundation, Inc.
9# 9#
diff --git a/doc/misc/texinfo.tex b/doc/misc/texinfo.tex
index 936c32dc5f4..8b3c9490f09 100644
--- a/doc/misc/texinfo.tex
+++ b/doc/misc/texinfo.tex
@@ -3,7 +3,7 @@
3% Load plain if necessary, i.e., if running under initex. 3% Load plain if necessary, i.e., if running under initex.
4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi 4\expandafter\ifx\csname fmtname\endcsname\relax\input plain\fi
5% 5%
6\def\texinfoversion{2016-01-11.19} 6\def\texinfoversion{2016-01-20.20}
7% 7%
8% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995, 8% Copyright 1985, 1986, 1988, 1990, 1991, 1992, 1993, 1994, 1995,
9% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 9% 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006,
@@ -4737,11 +4737,10 @@ end
4737 \def\_{\normalunderscore}% 4737 \def\_{\normalunderscore}%
4738 \def\-{}% @- shouldn't affect sorting 4738 \def\-{}% @- shouldn't affect sorting
4739 % 4739 %
4740 \def\lbracechar{{\indexlbrace}}% 4740 \uccode`\1=`\{ \uppercase{\def\{{1}}%
4741 \def\rbracechar{{\indexrbrace}}% 4741 \uccode`\1=`\} \uppercase{\def\}{1}}%
4742 \let\{=\lbracechar 4742 \let\lbracechar\{
4743 \let\}=\rbracechar 4743 \let\rbracechar\}
4744 %
4745 % 4744 %
4746 % Non-English letters. 4745 % Non-English letters.
4747 \def\AA{AA}% 4746 \def\AA{AA}%
@@ -4901,9 +4900,15 @@ end
4901 \indexdummies % Must do this here, since \bf, etc expand at this stage 4900 \indexdummies % Must do this here, since \bf, etc expand at this stage
4902 \useindexbackslash % \indexbackslash isn't defined now so it will be output 4901 \useindexbackslash % \indexbackslash isn't defined now so it will be output
4903 % as is; and it will print as backslash. 4902 % as is; and it will print as backslash.
4903 % The braces around \indexbrace are recognized by texindex.
4904 %
4904 % Get the string to sort by, by processing the index entry with all 4905 % Get the string to sort by, by processing the index entry with all
4905 % font commands turned off. 4906 % font commands turned off.
4906 {\indexnofonts 4907 {\indexnofonts
4908 \def\lbracechar{{\indexlbrace}}%
4909 \def\rbracechar{{\indexrbrace}}%
4910 \let\{=\lbracechar
4911 \let\}=\rbracechar
4907 \indexnonalnumdisappear 4912 \indexnonalnumdisappear
4908 \xdef\indexsortkey{}% 4913 \xdef\indexsortkey{}%
4909 \let\sortas=\indexwritesortas 4914 \let\sortas=\indexwritesortas
@@ -8526,10 +8531,6 @@ end
8526 }% 8531 }%
8527 \setcolor{\linkcolor}% 8532 \setcolor{\linkcolor}%
8528 \fi 8533 \fi
8529 %
8530 % Float references are printed completely differently: "Figure 1.2"
8531 % instead of "[somenode], p.3". We distinguish them by the
8532 % LABEL-title being set to a magic string.
8533 {% 8534 {%
8534 % Have to otherify everything special to allow the \csname to 8535 % Have to otherify everything special to allow the \csname to
8535 % include an _ in the xref name, etc. 8536 % include an _ in the xref name, etc.
@@ -8538,6 +8539,10 @@ end
8538 \expandafter\global\expandafter\let\expandafter\Xthisreftitle 8539 \expandafter\global\expandafter\let\expandafter\Xthisreftitle
8539 \csname XR#1-title\endcsname 8540 \csname XR#1-title\endcsname
8540 }% 8541 }%
8542 %
8543 % Float references are printed completely differently: "Figure 1.2"
8544 % instead of "[somenode], p.3". \iffloat distinguishes them by
8545 % \Xthisreftitle being set to a magic string.
8541 \iffloat\Xthisreftitle 8546 \iffloat\Xthisreftitle
8542 % If the user specified the print name (third arg) to the ref, 8547 % If the user specified the print name (third arg) to the ref,
8543 % print it instead of our usual "Figure 1.2". 8548 % print it instead of our usual "Figure 1.2".
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)
478void 478void
479free_permission_context (struct permission_context *ctx) 479free_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
256struct permission_context { 256struct 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
29static 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. */
37int
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 */
54void
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
25int 78int
26dirfd (DIR *dir_p) 79dirfd (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
92static int
93klibc_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
120static int
121klibc_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
90int 141int
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
170static int
171klibc_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
68DIR *
69fdopendir (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
65DIR * 100DIR *
66fdopendir (int fd) 101fdopendir (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)
600libc_hidden_weak (timelocal) 600libc_hidden_weak (timelocal)
601#endif 601#endif
602 602
603#if defined DEBUG && DEBUG 603#if defined DEBUG_MKTIME && DEBUG_MKTIME
604 604
605static int 605static int
606not_equal_tm (const struct tm *a, const struct tm *b) 606not_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/*
738Local Variables: 738Local Variables:
739compile-command: "gcc -DDEBUG -I. -Wall -W -O2 -g mktime.c -o mktime" 739compile-command: "gcc -DDEBUG_MKTIME -I. -Wall -W -O2 -g mktime.c -o mktime"
740End: 740End:
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. */
47char * 43char *
48openat_proc_name (char buf[OPENAT_BUFFER_SIZE], int fd, char const *file) 44openat_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
293typedef long int gl_intptr_t; 297typedef long int gl_intptr_t;
294typedef unsigned long int gl_uintptr_t; 298typedef 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
diff --git a/m4/dirfd.m4 b/m4/dirfd.m4
index e9532e60a99..1d7cb080d8e 100644
--- a/m4/dirfd.m4
+++ b/m4/dirfd.m4
@@ -1,4 +1,4 @@
1# serial 22 -*- Autoconf -*- 1# serial 24 -*- Autoconf -*-
2 2
3dnl Find out how to get the file descriptor associated with an open DIR*. 3dnl Find out how to get the file descriptor associated with an open DIR*.
4 4
@@ -35,13 +35,15 @@ AC_DEFUN([gl_FUNC_DIRFD],
35 gl_cv_func_dirfd_macro=yes, 35 gl_cv_func_dirfd_macro=yes,
36 gl_cv_func_dirfd_macro=no)]) 36 gl_cv_func_dirfd_macro=no)])
37 37
38 # Use the replacement only if we have no function or macro with that name. 38 # Use the replacement if we have no function or macro with that name,
39 if test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no; then 39 # or if OS/2 kLIBC whose dirfd() does not work.
40 if test $ac_cv_have_decl_dirfd = yes; then 40 # Replace only if the system declares dirfd already.
41 # If the system declares dirfd already, let's declare rpl_dirfd instead. 41 case $ac_cv_func_dirfd,$gl_cv_func_dirfd_macro,$host_os,$ac_cv_have_decl_dirfd in
42 no,no,*,yes | *,*,os2*,yes)
42 REPLACE_DIRFD=1 43 REPLACE_DIRFD=1
43 fi 44 AC_DEFINE([REPLACE_DIRFD], [1],
44 fi 45 [Define to 1 if gnulib's dirfd() replacement is used.]);;
46 esac
45]) 47])
46 48
47dnl Prerequisites of lib/dirfd.c. 49dnl Prerequisites of lib/dirfd.c.
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index 63d6d8eb6e2..5b68312b1e7 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,4 +1,4 @@
1#serial 24 1#serial 25
2dnl Copyright (C) 2002, 2005, 2007, 2009-2016 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2005, 2007, 2009-2016 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -62,6 +62,16 @@ AC_DEFUN([gl_FUNC_DUP2],
62 result |= 32; 62 result |= 32;
63 dup2 (2, 255); 63 dup2 (2, 255);
64 dup2 (2, 256); 64 dup2 (2, 256);
65 /* On OS/2 kLIBC, dup2() does not work on a directory fd. */
66 {
67 int fd = open (".", O_RDONLY);
68 if (fd == -1)
69 result |= 64;
70 else if (dup2 (fd, fd + 1) == -1)
71 result |= 128;
72
73 close (fd);
74 }
65 return result;]]) 75 return result;]])
66 ], 76 ],
67 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no], 77 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
@@ -78,6 +88,8 @@ AC_DEFUN([gl_FUNC_DUP2],
78 gl_cv_func_dup2_works="guessing no" ;; 88 gl_cv_func_dup2_works="guessing no" ;;
79 *-android*) # implemented using dup3(), which fails if oldfd == newfd 89 *-android*) # implemented using dup3(), which fails if oldfd == newfd
80 gl_cv_func_dup2_works="guessing no" ;; 90 gl_cv_func_dup2_works="guessing no" ;;
91 os2*) # on OS/2 kLIBC, dup2() does not work on a directory fd.
92 gl_cv_func_dup2_works="guessing no" ;;
81 *) gl_cv_func_dup2_works="guessing yes" ;; 93 *) gl_cv_func_dup2_works="guessing yes" ;;
82 esac]) 94 esac])
83 ]) 95 ])
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
index 0037e5fb650..bb61470b2e1 100644
--- a/m4/fcntl.m4
+++ b/m4/fcntl.m4
@@ -1,4 +1,4 @@
1# fcntl.m4 serial 8 1# fcntl.m4 serial 9
2dnl Copyright (C) 2009-2016 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2016 Free Software Foundation, Inc.
3dnl This file is free software; the Free Software Foundation 3dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 4dnl gives unlimited permission to copy and/or distribute it,
@@ -54,6 +54,17 @@ AC_DEFUN([gl_FUNC_FCNTL],
54 if (errno != EINVAL) result |= 2; 54 if (errno != EINVAL) result |= 2;
55 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4; 55 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
56 if (errno != EINVAL) result |= 8; 56 if (errno != EINVAL) result |= 8;
57 /* On OS/2 kLIBC, F_DUPFD does not work on a directory fd */
58 {
59 int fd;
60 fd = open (".", O_RDONLY);
61 if (fd == -1)
62 result |= 16;
63 else if (fcntl (fd, F_DUPFD, STDERR_FILENO + 1) == -1)
64 result |= 32;
65
66 close (fd);
67 }
57 return result;]])], 68 return result;]])],
58 [gl_cv_func_fcntl_f_dupfd_works=yes], 69 [gl_cv_func_fcntl_f_dupfd_works=yes],
59 [gl_cv_func_fcntl_f_dupfd_works=no], 70 [gl_cv_func_fcntl_f_dupfd_works=no],
diff --git a/m4/gnulib-comp.m4 b/m4/gnulib-comp.m4
index 27ca70a0d09..547af6641a1 100644
--- a/m4/gnulib-comp.m4
+++ b/m4/gnulib-comp.m4
@@ -436,7 +436,8 @@ AC_DEFUN([gl_INIT],
436 { 436 {
437 if ! $gl_gnulib_enabled_dirfd; then 437 if ! $gl_gnulib_enabled_dirfd; then
438 gl_FUNC_DIRFD 438 gl_FUNC_DIRFD
439 if test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no; then 439 if test $ac_cv_func_dirfd = no && test $gl_cv_func_dirfd_macro = no \
440 || test $REPLACE_DIRFD = 1; then
440 AC_LIBOBJ([dirfd]) 441 AC_LIBOBJ([dirfd])
441 gl_PREREQ_DIRFD 442 gl_PREREQ_DIRFD
442 fi 443 fi
diff --git a/m4/utimes.m4 b/m4/utimes.m4
index a016723e24a..1876bec7996 100644
--- a/m4/utimes.m4
+++ b/m4/utimes.m4
@@ -1,5 +1,5 @@
1# Detect some bugs in glibc's implementation of utimes. 1# Detect some bugs in glibc's implementation of utimes.
2# serial 3 2# serial 4
3 3
4dnl Copyright (C) 2003-2005, 2009-2016 Free Software Foundation, Inc. 4dnl Copyright (C) 2003-2005, 2009-2016 Free Software Foundation, Inc.
5dnl This file is free software; the Free Software Foundation 5dnl This file is free software; the Free Software Foundation
@@ -33,6 +33,7 @@ AC_DEFUN([gl_FUNC_UTIMES],
33#include <stdlib.h> 33#include <stdlib.h>
34#include <stdio.h> 34#include <stdio.h>
35#include <utime.h> 35#include <utime.h>
36#include <errno.h>
36 37
37static int 38static int
38inorder (time_t a, time_t b, time_t c) 39inorder (time_t a, time_t b, time_t c)
@@ -45,7 +46,10 @@ main ()
45{ 46{
46 int result = 0; 47 int result = 0;
47 char const *file = "conftest.utimes"; 48 char const *file = "conftest.utimes";
48 static struct timeval timeval[2] = {{9, 10}, {999999, 999999}}; 49 /* On OS/2, file timestamps must be on or after 1980 in local time,
50 with an even number of seconds. */
51 static struct timeval timeval[2] = {{315620000 + 10, 10},
52 {315620000 + 1000000, 999998}};
49 53
50 /* Test whether utimes() essentially works. */ 54 /* Test whether utimes() essentially works. */
51 { 55 {
@@ -82,9 +86,19 @@ main ()
82 result |= 1; 86 result |= 1;
83 else if (fstat (fd, &st0) != 0) 87 else if (fstat (fd, &st0) != 0)
84 result |= 1; 88 result |= 1;
85 else if (utimes (file, timeval) != 0) 89 else if (utimes (file, timeval) != 0
90 && (errno != EACCES
91 /* OS/2 kLIBC utimes fails on opened files. */
92 || close (fd) != 0
93 || utimes (file, timeval) != 0
94 || (fd = open (file, O_WRONLY)) < 0))
86 result |= 2; 95 result |= 2;
87 else if (utimes (file, NULL) != 0) 96 else if (utimes (file, NULL) != 0
97 && (errno != EACCES
98 /* OS/2 kLIBC utimes fails on opened files. */
99 || close (fd) != 0
100 || utimes (file, NULL) != 0
101 || (fd = open (file, O_WRONLY)) < 0))
88 result |= 8; 102 result |= 8;
89 else if (fstat (fd, &st1) != 0) 103 else if (fstat (fd, &st1) != 0)
90 result |= 1; 104 result |= 1;