aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Eggert2015-02-20 23:31:17 -0800
committerPaul Eggert2015-02-20 23:32:45 -0800
commit066b17df681fabb40108d719086669957aebbc51 (patch)
tree27f9362ed6a6e68ef6b61925932f84bb1afb37b8
parent43fb42da8bd6851b5b22d2bbb5d2cd8ceede9c09 (diff)
downloademacs-066b17df681fabb40108d719086669957aebbc51.tar.gz
emacs-066b17df681fabb40108d719086669957aebbc51.zip
Merge from gnulib
* doc/misc/texinfo.tex: Update from gnulib. * lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c: * lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4: Update from gnulib, incorporating: 2015-02-20 getdtablesize: port better for Android 2015-02-19 fcntl: Fix cross compiling 2015-02-18 dup2, fcntl: cross-compile better for Android 2015-02-18 getopt: don't crash on memory exhaustion 2015-02-17 tempname: allow compilation with C++ (trivial) 2015-02-17 dup2, fcntl: port to AIX 2015-02-16 getdtablesize, dup2, fcntl: port to Android 2015-02-11 getdtablesize, signal_h: Fix Android build 2015-02-11 maint: various whitespace cleanups in tempname
-rw-r--r--ChangeLog16
-rw-r--r--doc/misc/ChangeLog4
-rw-r--r--doc/misc/texinfo.tex55
-rw-r--r--lib/getdtablesize.c35
-rw-r--r--lib/getopt.c52
-rw-r--r--lib/signal.in.h8
-rw-r--r--lib/tempname.c118
-rw-r--r--lib/tempname.h15
-rw-r--r--m4/dup2.m476
-rw-r--r--m4/fcntl.m452
-rw-r--r--m4/getdtablesize.m46
11 files changed, 281 insertions, 156 deletions
diff --git a/ChangeLog b/ChangeLog
index 43656680f9c..41bff0ef30a 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
12015-02-21 Paul Eggert <eggert@cs.ucla.edu>
2
3 Merge from gnulib
4 * lib/getdtablesize.c, lib/getopt.c, lib/signal.in.h, lib/tempname.c:
5 * lib/tempname.h, m4/dup2.m4, m4/fcntl.m4, m4/getdtablesize.m4:
6 Update from gnulib, incorporating:
7 2015-02-20 getdtablesize: port better for Android
8 2015-02-19 fcntl: Fix cross compiling
9 2015-02-18 dup2, fcntl: cross-compile better for Android
10 2015-02-18 getopt: don't crash on memory exhaustion
11 2015-02-17 tempname: allow compilation with C++ (trivial)
12 2015-02-17 dup2, fcntl: port to AIX
13 2015-02-16 getdtablesize, dup2, fcntl: port to Android
14 2015-02-11 getdtablesize, signal_h: Fix Android build
15 2015-02-11 maint: various whitespace cleanups in tempname
16
12015-02-13 Jan Djärv <jan.h.d@swipnet.se> 172015-02-13 Jan Djärv <jan.h.d@swipnet.se>
2 18
3 * configure.ac: Set locallisppath to empty for NS self contained, 19 * configure.ac: Set locallisppath to empty for NS self contained,
diff --git a/doc/misc/ChangeLog b/doc/misc/ChangeLog
index c796b751f05..d04a8bbb083 100644
--- a/doc/misc/ChangeLog
+++ b/doc/misc/ChangeLog
@@ -1,3 +1,7 @@
12015-02-21 Paul Eggert <eggert@cs.ucla.edu>
2
3 * texinfo.tex: Update from gnulib.
4
12015-02-10 Lars Ingebrigtsen <larsi@gnus.org> 52015-02-10 Lars Ingebrigtsen <larsi@gnus.org>
2 6
3 * eww.texi (Basics): Mention eww-toggle-fonts. 7 * eww.texi (Basics): Mention eww-toggle-fonts.
diff --git a/doc/misc/texinfo.tex b/doc/misc/texinfo.tex
index 96b212d2ad1..8236d7d2f82 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{2015-01-31.10} 6\def\texinfoversion{2015-02-05.16}
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,
@@ -4489,7 +4489,6 @@ end
4489% Called from \indexdummies and \atdummies. 4489% Called from \indexdummies and \atdummies.
4490% 4490%
4491\def\commondummies{% 4491\def\commondummies{%
4492 %
4493 % \definedummyword defines \#1 as \string\#1\space, thus effectively 4492 % \definedummyword defines \#1 as \string\#1\space, thus effectively
4494 % preventing its expansion. This is used only for control words, 4493 % preventing its expansion. This is used only for control words,
4495 % not control letters, because the \space would be incorrect for 4494 % not control letters, because the \space would be incorrect for
@@ -4566,6 +4565,7 @@ end
4566 \definedummyword\guilsinglright 4565 \definedummyword\guilsinglright
4567 \definedummyword\lbracechar 4566 \definedummyword\lbracechar
4568 \definedummyword\leq 4567 \definedummyword\leq
4568 \definedummyword\mathopsup
4569 \definedummyword\minus 4569 \definedummyword\minus
4570 \definedummyword\ogonek 4570 \definedummyword\ogonek
4571 \definedummyword\pounds 4571 \definedummyword\pounds
@@ -4579,6 +4579,8 @@ end
4579 \definedummyword\quotesinglbase 4579 \definedummyword\quotesinglbase
4580 \definedummyword\rbracechar 4580 \definedummyword\rbracechar
4581 \definedummyword\result 4581 \definedummyword\result
4582 \definedummyword\sub
4583 \definedummyword\sup
4582 \definedummyword\textdegree 4584 \definedummyword\textdegree
4583 % 4585 %
4584 % We want to disable all macros so that they are not expanded by \write. 4586 % We want to disable all macros so that they are not expanded by \write.
@@ -4653,6 +4655,7 @@ end
4653 \definedummyword\samp 4655 \definedummyword\samp
4654 \definedummyword\strong 4656 \definedummyword\strong
4655 \definedummyword\tie 4657 \definedummyword\tie
4658 \definedummyword\U
4656 \definedummyword\uref 4659 \definedummyword\uref
4657 \definedummyword\url 4660 \definedummyword\url
4658 \definedummyword\var 4661 \definedummyword\var
@@ -8335,14 +8338,7 @@ end
8335 \catcode`\\=\other 8338 \catcode`\\=\other
8336 % 8339 %
8337 % Make the characters 128-255 be printing characters. 8340 % Make the characters 128-255 be printing characters.
8338 {% 8341 {\setnonasciicharscatcodenonglobal\other}%
8339 \count1=128
8340 \def\loop{%
8341 \catcode\count1=\other
8342 \advance\count1 by 1
8343 \ifnum \count1<256 \loop \fi
8344 }%
8345 }%
8346 % 8342 %
8347 % @ is our escape character in .aux files, and we need braces. 8343 % @ is our escape character in .aux files, and we need braces.
8348 \catcode`\{=1 8344 \catcode`\{=1
@@ -9831,15 +9827,51 @@ directory should work if nowhere else does.}
9831 \DeclareUnicodeCharacter{2261}{\equiv} 9827 \DeclareUnicodeCharacter{2261}{\equiv}
9832}% end of \utfeightchardefs 9828}% end of \utfeightchardefs
9833 9829
9834
9835% US-ASCII character definitions. 9830% US-ASCII character definitions.
9836\def\asciichardefs{% nothing need be done 9831\def\asciichardefs{% nothing need be done
9837 \relax 9832 \relax
9838} 9833}
9839 9834
9835% Latin1 (ISO-8859-1) character definitions.
9836\def\nonasciistringdefs{%
9837 \setnonasciicharscatcode\active
9838 \def\defstringchar##1{\def##1{\string##1}}%
9839 \defstringchar^^a0\defstringchar^^a1\defstringchar^^a2\defstringchar^^a3%
9840 \defstringchar^^a4\defstringchar^^a5\defstringchar^^a6\defstringchar^^a7%
9841 \defstringchar^^a8\defstringchar^^a9\defstringchar^^aa\defstringchar^^ab%
9842 \defstringchar^^ac\defstringchar^^ad\defstringchar^^ae\defstringchar^^af%
9843 %
9844 \defstringchar^^b0\defstringchar^^b1\defstringchar^^b2\defstringchar^^b3%
9845 \defstringchar^^b4\defstringchar^^b5\defstringchar^^b6\defstringchar^^b7%
9846 \defstringchar^^b8\defstringchar^^b9\defstringchar^^ba\defstringchar^^bb%
9847 \defstringchar^^bc\defstringchar^^bd\defstringchar^^be\defstringchar^^bf%
9848 %
9849 \defstringchar^^c0\defstringchar^^c1\defstringchar^^c2\defstringchar^^c3%
9850 \defstringchar^^c4\defstringchar^^c5\defstringchar^^c6\defstringchar^^c7%
9851 \defstringchar^^c8\defstringchar^^c9\defstringchar^^ca\defstringchar^^cb%
9852 \defstringchar^^cc\defstringchar^^cd\defstringchar^^ce\defstringchar^^cf%
9853 %
9854 \defstringchar^^d0\defstringchar^^d1\defstringchar^^d2\defstringchar^^d3%
9855 \defstringchar^^d4\defstringchar^^d5\defstringchar^^d6\defstringchar^^d7%
9856 \defstringchar^^d8\defstringchar^^d9\defstringchar^^da\defstringchar^^db%
9857 \defstringchar^^dc\defstringchar^^dd\defstringchar^^de\defstringchar^^df%
9858 %
9859 \defstringchar^^e0\defstringchar^^e1\defstringchar^^e2\defstringchar^^e3%
9860 \defstringchar^^e4\defstringchar^^e5\defstringchar^^e6\defstringchar^^e7%
9861 \defstringchar^^e8\defstringchar^^e9\defstringchar^^ea\defstringchar^^eb%
9862 \defstringchar^^ec\defstringchar^^ed\defstringchar^^ee\defstringchar^^ef%
9863 %
9864 \defstringchar^^f0\defstringchar^^f1\defstringchar^^f2\defstringchar^^f3%
9865 \defstringchar^^f4\defstringchar^^f5\defstringchar^^f6\defstringchar^^f7%
9866 \defstringchar^^f8\defstringchar^^f9\defstringchar^^fa\defstringchar^^fb%
9867 \defstringchar^^fc\defstringchar^^fd\defstringchar^^fe\defstringchar^^ff%
9868}
9869
9870
9840% define all the unicode characters we know about, for the sake of @U. 9871% define all the unicode characters we know about, for the sake of @U.
9841\utfeightchardefs 9872\utfeightchardefs
9842 9873
9874
9843% Make non-ASCII characters printable again for compatibility with 9875% Make non-ASCII characters printable again for compatibility with
9844% existing Texinfo documents that may use them, even without declaring a 9876% existing Texinfo documents that may use them, even without declaring a
9845% document encoding. 9877% document encoding.
@@ -10193,6 +10225,7 @@ directory should work if nowhere else does.}
10193% 10225%
10194{@catcode`- = @active 10226{@catcode`- = @active
10195 @gdef@normalturnoffactive{% 10227 @gdef@normalturnoffactive{%
10228 @nonasciistringdefs
10196 @let-=@normaldash 10229 @let-=@normaldash
10197 @let"=@normaldoublequote 10230 @let"=@normaldoublequote
10198 @let$=@normaldollar %$ font-lock fix 10231 @let$=@normaldollar %$ font-lock fix
diff --git a/lib/getdtablesize.c b/lib/getdtablesize.c
index 59b97360bc5..bad45f7e32f 100644
--- a/lib/getdtablesize.c
+++ b/lib/getdtablesize.c
@@ -84,32 +84,31 @@ getdtablesize (void)
84 return dtablesize; 84 return dtablesize;
85} 85}
86 86
87#elif HAVE_GETDTABLESIZE 87#else
88 88
89# include <limits.h>
89# include <sys/resource.h> 90# include <sys/resource.h>
90# undef getdtablesize 91
92# ifdef __CYGWIN__
93 /* Cygwin 1.7.25 auto-increases the RLIMIT_NOFILE soft limit until it
94 hits the compile-time constant hard limit of 3200. We might as
95 well just report the hard limit. */
96# define rlim_cur rlim_max
97# endif
91 98
92int 99int
93rpl_getdtablesize(void) 100getdtablesize (void)
94{ 101{
95 /* To date, this replacement is only compiled for Cygwin 1.7.25,
96 which auto-increased the RLIMIT_NOFILE soft limit until it
97 hits the compile-time constant hard limit of 3200. Although
98 that version of cygwin supported a child process inheriting
99 a smaller soft limit, the smaller limit is not enforced, so
100 we might as well just report the hard limit. */
101 struct rlimit lim; 102 struct rlimit lim;
102 if (!getrlimit (RLIMIT_NOFILE, &lim) && lim.rlim_max != RLIM_INFINITY)
103 return lim.rlim_max;
104 return getdtablesize ();
105}
106 103
107#elif defined _SC_OPEN_MAX 104 if (getrlimit (RLIMIT_NOFILE, &lim) == 0
105 && 0 <= lim.rlim_cur && lim.rlim_cur <= INT_MAX
106 && lim.rlim_cur != RLIM_INFINITY
107 && lim.rlim_cur != RLIM_SAVED_CUR
108 && lim.rlim_cur != RLIM_SAVED_MAX)
109 return lim.rlim_cur;
108 110
109int 111 return INT_MAX;
110getdtablesize (void)
111{
112 return sysconf (_SC_OPEN_MAX);
113} 112}
114 113
115#endif 114#endif
diff --git a/lib/getopt.c b/lib/getopt.c
index 3b9c585a28c..212cbf73410 100644
--- a/lib/getopt.c
+++ b/lib/getopt.c
@@ -487,7 +487,20 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
487 const struct option *p; 487 const struct option *p;
488 struct option_list *next; 488 struct option_list *next;
489 } *ambig_list = NULL; 489 } *ambig_list = NULL;
490#ifdef _LIBC
491/* malloc() not used for _LIBC to simplify failure messages. */
492# define free_option_list(l)
493#else
494# define free_option_list(l) \
495 while (l != NULL) \
496 { \
497 struct option_list *pn = l->next; \
498 free (l); \
499 l = pn; \
500 }
501#endif
490 int exact = 0; 502 int exact = 0;
503 int ambig = 0;
491 int indfound = -1; 504 int indfound = -1;
492 int option_index; 505 int option_index;
493 506
@@ -514,22 +527,37 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
514 pfound = p; 527 pfound = p;
515 indfound = option_index; 528 indfound = option_index;
516 } 529 }
530 else if (ambig)
531 ; /* Taking simpler path to handling ambiguities. */
517 else if (long_only 532 else if (long_only
518 || pfound->has_arg != p->has_arg 533 || pfound->has_arg != p->has_arg
519 || pfound->flag != p->flag 534 || pfound->flag != p->flag
520 || pfound->val != p->val) 535 || pfound->val != p->val)
521 { 536 {
522 /* Second or later nonexact match found. */ 537 /* Second or later nonexact match found. */
538#ifdef _LIBC
539 struct option_list *newp = alloca (sizeof (*newp));
540#else
523 struct option_list *newp = malloc (sizeof (*newp)); 541 struct option_list *newp = malloc (sizeof (*newp));
524 newp->p = p; 542 if (newp == NULL)
525 newp->next = ambig_list; 543 {
526 ambig_list = newp; 544 free_option_list (ambig_list);
545 ambig_list = NULL;
546 ambig = 1; /* Use simpler fallback message. */
547 }
548 else
549#endif
550 {
551 newp->p = p;
552 newp->next = ambig_list;
553 ambig_list = newp;
554 }
527 } 555 }
528 } 556 }
529 557
530 if (ambig_list != NULL && !exact) 558 if ((ambig || ambig_list) && !exact)
531 { 559 {
532 if (print_errors) 560 if (print_errors && ambig_list)
533 { 561 {
534 struct option_list first; 562 struct option_list first;
535 first.p = pfound; 563 first.p = pfound;
@@ -585,18 +613,20 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
585 fputc ('\n', stderr); 613 fputc ('\n', stderr);
586#endif 614#endif
587 } 615 }
616 else if (print_errors && ambig)
617 {
618 fprintf (stderr,
619 _("%s: option '%s' is ambiguous\n"),
620 argv[0], argv[d->optind]);
621 }
588 d->__nextchar += strlen (d->__nextchar); 622 d->__nextchar += strlen (d->__nextchar);
589 d->optind++; 623 d->optind++;
590 d->optopt = 0; 624 d->optopt = 0;
625 free_option_list (ambig_list);
591 return '?'; 626 return '?';
592 } 627 }
593 628
594 while (ambig_list != NULL) 629 free_option_list (ambig_list);
595 {
596 struct option_list *pn = ambig_list->next;
597 free (ambig_list);
598 ambig_list = pn;
599 }
600 630
601 if (pfound != NULL) 631 if (pfound != NULL)
602 { 632 {
diff --git a/lib/signal.in.h b/lib/signal.in.h
index 0f2ff5af843..265b72ab0ec 100644
--- a/lib/signal.in.h
+++ b/lib/signal.in.h
@@ -55,11 +55,13 @@
55#ifndef _@GUARD_PREFIX@_SIGNAL_H 55#ifndef _@GUARD_PREFIX@_SIGNAL_H
56#define _@GUARD_PREFIX@_SIGNAL_H 56#define _@GUARD_PREFIX@_SIGNAL_H
57 57
58/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6 declare 58/* Mac OS X 10.3, FreeBSD 6.4, OpenBSD 3.8, OSF/1 4.0, Solaris 2.6, Android
59 pthread_sigmask in <pthread.h>, not in <signal.h>. 59 declare pthread_sigmask in <pthread.h>, not in <signal.h>.
60 But avoid namespace pollution on glibc systems.*/ 60 But avoid namespace pollution on glibc systems.*/
61#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \ 61#if (@GNULIB_PTHREAD_SIGMASK@ || defined GNULIB_POSIXCHECK) \
62 && ((defined __APPLE__ && defined __MACH__) || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ || defined __sun) \ 62 && ((defined __APPLE__ && defined __MACH__) \
63 || defined __FreeBSD__ || defined __OpenBSD__ || defined __osf__ \
64 || defined __sun || defined __ANDROID__) \
63 && ! defined __GLIBC__ 65 && ! defined __GLIBC__
64# include <pthread.h> 66# include <pthread.h>
65#endif 67#endif
diff --git a/lib/tempname.c b/lib/tempname.c
index 088b224ab96..8e6d26cc485 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -62,6 +62,7 @@
62# define struct_stat64 struct stat64 62# define struct_stat64 struct stat64
63#else 63#else
64# define struct_stat64 struct stat 64# define struct_stat64 struct stat
65# define __try_tempname try_tempname
65# define __gen_tempname gen_tempname 66# define __gen_tempname gen_tempname
66# define __getpid getpid 67# define __getpid getpid
67# define __gettimeofday gettimeofday 68# define __gettimeofday gettimeofday
@@ -176,21 +177,9 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
176static const char letters[] = 177static const char letters[] =
177"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; 178"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
178 179
179/* Generate a temporary file name based on TMPL. TMPL must match the
180 rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
181 The name constructed does not exist at the time of the call to
182 __gen_tempname. TMPL is overwritten with the result.
183
184 KIND may be one of:
185 __GT_NOCREATE: simply verify that the name does not exist
186 at the time of the call.
187 __GT_FILE: create the file using open(O_CREAT|O_EXCL)
188 and return a read-write fd. The file is mode 0600.
189 __GT_DIR: create a directory, which will be mode 0700.
190
191 We use a clever algorithm to get hard-to-predict names. */
192int 180int
193__gen_tempname (char *tmpl, int suffixlen, int flags, int kind) 181__try_tempname (char *tmpl, int suffixlen, void *args,
182 int (*tryfunc) (char *, void *))
194{ 183{
195 int len; 184 int len;
196 char *XXXXXX; 185 char *XXXXXX;
@@ -199,7 +188,6 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
199 unsigned int count; 188 unsigned int count;
200 int fd = -1; 189 int fd = -1;
201 int save_errno = errno; 190 int save_errno = errno;
202 struct_stat64 st;
203 191
204 /* A lower bound on the number of temporary files to attempt to 192 /* A lower bound on the number of temporary files to attempt to
205 generate. The maximum total number of temporary file names that 193 generate. The maximum total number of temporary file names that
@@ -256,41 +244,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
256 v /= 62; 244 v /= 62;
257 XXXXXX[5] = letters[v % 62]; 245 XXXXXX[5] = letters[v % 62];
258 246
259 switch (kind) 247 fd = tryfunc (tmpl, args);
260 {
261 case __GT_FILE:
262 fd = __open (tmpl,
263 (flags & ~O_ACCMODE)
264 | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
265 break;
266
267 case __GT_DIR:
268 fd = __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
269 break;
270
271 case __GT_NOCREATE:
272 /* This case is backward from the other three. __gen_tempname
273 succeeds if __xstat fails because the name does not exist.
274 Note the continue to bypass the common logic at the bottom
275 of the loop. */
276 if (__lxstat64 (_STAT_VER, tmpl, &st) < 0)
277 {
278 if (errno == ENOENT)
279 {
280 __set_errno (save_errno);
281 return 0;
282 }
283 else
284 /* Give up now. */
285 return -1;
286 }
287 continue;
288
289 default:
290 assert (! "invalid KIND in __gen_tempname");
291 abort ();
292 }
293
294 if (fd >= 0) 248 if (fd >= 0)
295 { 249 {
296 __set_errno (save_errno); 250 __set_errno (save_errno);
@@ -304,3 +258,67 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
304 __set_errno (EEXIST); 258 __set_errno (EEXIST);
305 return -1; 259 return -1;
306} 260}
261
262static int
263try_file (char *tmpl, void *flags)
264{
265 int *openflags = flags;
266 return __open (tmpl,
267 (*openflags & ~O_ACCMODE)
268 | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
269}
270
271static int
272try_dir (char *tmpl, void *flags)
273{
274 return __mkdir (tmpl, S_IRUSR | S_IWUSR | S_IXUSR);
275}
276
277static int
278try_nocreate (char *tmpl, void *flags)
279{
280 struct_stat64 st;
281
282 if (__lxstat64 (_STAT_VER, tmpl, &st) == 0)
283 __set_errno (EEXIST);
284 return errno == ENOENT ? 0 : -1;
285}
286
287/* Generate a temporary file name based on TMPL. TMPL must match the
288 rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
289 The name constructed does not exist at the time of the call to
290 __gen_tempname. TMPL is overwritten with the result.
291
292 KIND may be one of:
293 __GT_NOCREATE: simply verify that the name does not exist
294 at the time of the call.
295 __GT_FILE: create the file using open(O_CREAT|O_EXCL)
296 and return a read-write fd. The file is mode 0600.
297 __GT_DIR: create a directory, which will be mode 0700.
298
299 We use a clever algorithm to get hard-to-predict names. */
300int
301__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
302{
303 int (*tryfunc) (char *, void *);
304
305 switch (kind)
306 {
307 case __GT_FILE:
308 tryfunc = try_file;
309 break;
310
311 case __GT_DIR:
312 tryfunc = try_dir;
313 break;
314
315 case __GT_NOCREATE:
316 tryfunc = try_nocreate;
317 break;
318
319 default:
320 assert (! "invalid KIND in __gen_tempname");
321 abort ();
322 }
323 return __try_tempname (tmpl, suffixlen, &flags, tryfunc);
324}
diff --git a/lib/tempname.h b/lib/tempname.h
index b560ee5cb14..e6093607463 100644
--- a/lib/tempname.h
+++ b/lib/tempname.h
@@ -32,6 +32,10 @@
32# define GT_NOCREATE 2 32# define GT_NOCREATE 2
33# endif 33# endif
34 34
35#ifdef __cplusplus
36extern "C" {
37#endif
38
35/* Generate a temporary file name based on TMPL. TMPL must match the 39/* Generate a temporary file name based on TMPL. TMPL must match the
36 rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix). 40 rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
37 The name constructed does not exist at the time of the call to 41 The name constructed does not exist at the time of the call to
@@ -47,4 +51,15 @@
47 We use a clever algorithm to get hard-to-predict names. */ 51 We use a clever algorithm to get hard-to-predict names. */
48extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind); 52extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
49 53
54/* Similar to gen_tempname, but TRYFUNC is called for each temporary
55 name to try. If TRYFUNC returns a non-negative number, TRY_GEN_TEMPNAME
56 returns with this value. Otherwise, if errno is set to EEXIST, another
57 name is tried, or else TRY_GEN_TEMPNAME returns -1. */
58extern int try_tempname (char *tmpl, int suffixlen, void *args,
59 int (*tryfunc) (char *, void *));
60
61#ifdef __cplusplus
62}
63#endif
64
50#endif /* GL_TEMPNAME_H */ 65#endif /* GL_TEMPNAME_H */
diff --git a/m4/dup2.m4 b/m4/dup2.m4
index 0354c6ad478..9aa2ea85ebd 100644
--- a/m4/dup2.m4
+++ b/m4/dup2.m4
@@ -1,4 +1,4 @@
1#serial 20 1#serial 22
2dnl Copyright (C) 2002, 2005, 2007, 2009-2015 Free Software Foundation, Inc. 2dnl Copyright (C) 2002, 2005, 2007, 2009-2015 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,
@@ -8,7 +8,6 @@ AC_DEFUN([gl_FUNC_DUP2],
8[ 8[
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) 10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CHECK_FUNCS_ONCE([getdtablesize])
12 m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [ 11 m4_ifdef([gl_FUNC_DUP2_OBSOLETE], [
13 AC_CHECK_FUNCS_ONCE([dup2]) 12 AC_CHECK_FUNCS_ONCE([dup2])
14 if test $ac_cv_func_dup2 = no; then 13 if test $ac_cv_func_dup2 = no; then
@@ -20,38 +19,44 @@ AC_DEFUN([gl_FUNC_DUP2],
20 if test $HAVE_DUP2 = 1; then 19 if test $HAVE_DUP2 = 1; then
21 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works], 20 AC_CACHE_CHECK([whether dup2 works], [gl_cv_func_dup2_works],
22 [AC_RUN_IFELSE([ 21 [AC_RUN_IFELSE([
23 AC_LANG_PROGRAM([[#include <unistd.h> 22 AC_LANG_PROGRAM(
24#include <fcntl.h> 23 [[#include <errno.h>
25#include <errno.h>]], 24 #include <fcntl.h>
26 [int result = 0; 25 #include <limits.h>
27#ifdef HAVE_GETDTABLESIZE 26 #include <sys/resource.h>
28 int bad_fd = getdtablesize (); 27 #include <unistd.h>
29#else 28 ]],
30 int bad_fd = 1000000; 29 [[int result = 0;
31#endif 30 int bad_fd = INT_MAX;
32#ifdef FD_CLOEXEC 31 struct rlimit rlim;
33 if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1) 32 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
34 result |= 1; 33 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
35#endif 34 && rlim.rlim_cur != RLIM_INFINITY
36 if (dup2 (1, 1) == 0) 35 && rlim.rlim_cur != RLIM_SAVED_MAX
37 result |= 2; 36 && rlim.rlim_cur != RLIM_SAVED_CUR)
38#ifdef FD_CLOEXEC 37 bad_fd = rlim.rlim_cur;
39 if (fcntl (1, F_GETFD) != FD_CLOEXEC) 38 #ifdef FD_CLOEXEC
40 result |= 4; 39 if (fcntl (1, F_SETFD, FD_CLOEXEC) == -1)
41#endif 40 result |= 1;
42 close (0); 41 #endif
43 if (dup2 (0, 0) != -1) 42 if (dup2 (1, 1) == 0)
44 result |= 8; 43 result |= 2;
45 /* Many gnulib modules require POSIX conformance of EBADF. */ 44 #ifdef FD_CLOEXEC
46 if (dup2 (2, bad_fd) == -1 && errno != EBADF) 45 if (fcntl (1, F_GETFD) != FD_CLOEXEC)
47 result |= 16; 46 result |= 4;
48 /* Flush out some cygwin core dumps. */ 47 #endif
49 if (dup2 (2, -1) != -1 || errno != EBADF) 48 close (0);
50 result |= 32; 49 if (dup2 (0, 0) != -1)
51 dup2 (2, 255); 50 result |= 8;
52 dup2 (2, 256); 51 /* Many gnulib modules require POSIX conformance of EBADF. */
53 return result; 52 if (dup2 (2, bad_fd) == -1 && errno != EBADF)
54 ]) 53 result |= 16;
54 /* Flush out some cygwin core dumps. */
55 if (dup2 (2, -1) != -1 || errno != EBADF)
56 result |= 32;
57 dup2 (2, 255);
58 dup2 (2, 256);
59 return result;]])
55 ], 60 ],
56 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no], 61 [gl_cv_func_dup2_works=yes], [gl_cv_func_dup2_works=no],
57 [case "$host_os" in 62 [case "$host_os" in
@@ -59,9 +64,6 @@ AC_DEFUN([gl_FUNC_DUP2],
59 gl_cv_func_dup2_works="guessing no" ;; 64 gl_cv_func_dup2_works="guessing no" ;;
60 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0 65 cygwin*) # on cygwin 1.5.x, dup2(1,1) returns 0
61 gl_cv_func_dup2_works="guessing no" ;; 66 gl_cv_func_dup2_works="guessing no" ;;
62 linux*) # On linux between 2008-07-27 and 2009-05-11, dup2 of a
63 # closed fd may yield -EBADF instead of -1 / errno=EBADF.
64 gl_cv_func_dup2_works="guessing no" ;;
65 aix* | freebsd*) 67 aix* | freebsd*)
66 # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE, 68 # on AIX 7.1 and FreeBSD 6.1, dup2 (1,toobig) gives EMFILE,
67 # not EBADF. 69 # not EBADF.
diff --git a/m4/fcntl.m4 b/m4/fcntl.m4
index 733cd2d701b..218e78628ba 100644
--- a/m4/fcntl.m4
+++ b/m4/fcntl.m4
@@ -1,4 +1,4 @@
1# fcntl.m4 serial 5 1# fcntl.m4 serial 7
2dnl Copyright (C) 2009-2015 Free Software Foundation, Inc. 2dnl Copyright (C) 2009-2015 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,
@@ -19,7 +19,7 @@ AC_DEFUN([gl_FUNC_FCNTL],
19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) 19 AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
20 AC_REQUIRE([gl_FCNTL_H_DEFAULTS]) 20 AC_REQUIRE([gl_FCNTL_H_DEFAULTS])
21 AC_REQUIRE([AC_CANONICAL_HOST]) 21 AC_REQUIRE([AC_CANONICAL_HOST])
22 AC_CHECK_FUNCS_ONCE([fcntl getdtablesize]) 22 AC_CHECK_FUNCS_ONCE([fcntl])
23 if test $ac_cv_func_fcntl = no; then 23 if test $ac_cv_func_fcntl = no; then
24 gl_REPLACE_FCNTL 24 gl_REPLACE_FCNTL
25 else 25 else
@@ -27,30 +27,34 @@ AC_DEFUN([gl_FUNC_FCNTL],
27 dnl haiku alpha 2 F_DUPFD has wrong errno 27 dnl haiku alpha 2 F_DUPFD has wrong errno
28 AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly], 28 AC_CACHE_CHECK([whether fcntl handles F_DUPFD correctly],
29 [gl_cv_func_fcntl_f_dupfd_works], 29 [gl_cv_func_fcntl_f_dupfd_works],
30 [AC_RUN_IFELSE([AC_LANG_PROGRAM([[ 30 [AC_RUN_IFELSE(
31#ifdef HAVE_GETDTABLESIZE 31 [AC_LANG_PROGRAM(
32# include <unistd.h> 32 [[#include <errno.h>
33#endif 33 #include <fcntl.h>
34#include <fcntl.h> 34 #include <limits.h>
35#include <errno.h> 35 #include <sys/resource.h>
36]], [[int result = 0; 36 #include <unistd.h>
37#ifdef HAVE_GETDTABLESIZE 37 ]],
38 int bad_fd = getdtablesize (); 38 [[int result = 0;
39#else 39 int bad_fd = INT_MAX;
40 int bad_fd = 1000000; 40 struct rlimit rlim;
41#endif 41 if (getrlimit (RLIMIT_NOFILE, &rlim) == 0
42 if (fcntl (0, F_DUPFD, -1) != -1) result |= 1; 42 && 0 <= rlim.rlim_cur && rlim.rlim_cur <= INT_MAX
43 if (errno != EINVAL) result |= 2; 43 && rlim.rlim_cur != RLIM_INFINITY
44 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4; 44 && rlim.rlim_cur != RLIM_SAVED_MAX
45 if (errno != EINVAL) result |= 8; 45 && rlim.rlim_cur != RLIM_SAVED_CUR)
46 return result; 46 bad_fd = rlim.rlim_cur;
47 ]])], 47 if (fcntl (0, F_DUPFD, -1) != -1) result |= 1;
48 if (errno != EINVAL) result |= 2;
49 if (fcntl (0, F_DUPFD, bad_fd) != -1) result |= 4;
50 if (errno != EINVAL) result |= 8;
51 return result;]])],
48 [gl_cv_func_fcntl_f_dupfd_works=yes], 52 [gl_cv_func_fcntl_f_dupfd_works=yes],
49 [gl_cv_func_fcntl_f_dupfd_works=no], 53 [gl_cv_func_fcntl_f_dupfd_works=no],
50 [# Guess that it works on glibc systems 54 [case $host_os in
51 case $host_os in #(( 55 aix* | cygwin* | haiku*)
52 *-gnu*) gl_cv_func_fcntl_f_dupfd_works="guessing yes";; 56 gl_cv_func_fcntl_f_dupfd_works="guessing no" ;;
53 *) gl_cv_func_fcntl_f_dupfd_works="guessing no";; 57 *) gl_cv_func_fcntl_f_dupfd_works="guessing yes" ;;
54 esac])]) 58 esac])])
55 case $gl_cv_func_fcntl_f_dupfd_works in 59 case $gl_cv_func_fcntl_f_dupfd_works in
56 *yes) ;; 60 *yes) ;;
diff --git a/m4/getdtablesize.m4 b/m4/getdtablesize.m4
index a6b6c1b6c52..25e9968947d 100644
--- a/m4/getdtablesize.m4
+++ b/m4/getdtablesize.m4
@@ -1,4 +1,4 @@
1# getdtablesize.m4 serial 5 1# getdtablesize.m4 serial 6
2dnl Copyright (C) 2008-2015 Free Software Foundation, Inc. 2dnl Copyright (C) 2008-2015 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,
@@ -9,7 +9,9 @@ AC_DEFUN([gl_FUNC_GETDTABLESIZE],
9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) 9 AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
10 AC_REQUIRE([AC_CANONICAL_HOST]) 10 AC_REQUIRE([AC_CANONICAL_HOST])
11 AC_CHECK_FUNCS_ONCE([getdtablesize]) 11 AC_CHECK_FUNCS_ONCE([getdtablesize])
12 if test $ac_cv_func_getdtablesize = yes; then 12 AC_CHECK_DECLS_ONCE([getdtablesize])
13 if test $ac_cv_func_getdtablesize = yes &&
14 test $ac_cv_have_decl_getdtablesize = yes; then
13 # Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft limit 15 # Cygwin 1.7.25 automatically increases the RLIMIT_NOFILE soft limit
14 # up to an unchangeable hard limit; all other platforms correctly 16 # up to an unchangeable hard limit; all other platforms correctly
15 # require setrlimit before getdtablesize() can report a larger value. 17 # require setrlimit before getdtablesize() can report a larger value.