From ae5dae6fd1caa993e969b869e42820a119385cbc Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Mon, 19 Jan 2009 09:27:47 -0700 Subject: [PATCH] unistd: guarantee STDIN_FILENO here, for OS/2 EMX * lib/unistd.in.h (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): Guarantee a definition. * doc/posix-headers/unistd.texi (unistd.h): Document the bug. * modules/unistd-safer (Depends-on): Add dependency on unistd. * lib/c-stack.c (STDERR_FILENO): Rely on . * lib/dup-safer.c (STDERR_FILENO): Likewise. * lib/execute.c (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): Likewise. * lib/fd-safer.c (STDIN_FILENO, STDERR_FILENO): Likewise. * lib/fopen-safer.c (STDERR_FILENO): Likewise. * lib/pipe.c (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): Likewise. * lib/tmpfile-safer.c (STDERR_FILENO): Likewise. * tests/test-posix_spawn1.c (STDIN_FILENO, STDOUT_FILENO) (STDERR_FILENO): Likewise. * tests/test-posix_spawn2.c (STDIN_FILENO, STDOUT_FILENO) (STDERR_FILENO): Likewise. * tests/test-posix_spawn3.c (STDIN_FILENO, STDOUT_FILENO) (STDERR_FILENO): Likewise. Reported by Elbert Pol. Signed-off-by: Eric Blake --- ChangeLog | 24 ++++++++++++++++++++++++ doc/posix-headers/unistd.texi | 6 +++++- lib/c-stack.c | 6 ++---- lib/dup-safer.c | 6 ++---- lib/execute.c | 12 +----------- lib/fd-safer.c | 8 +------- lib/fopen-safer.c | 7 ++----- lib/pipe.c | 12 +----------- lib/tmpfile-safer.c | 6 +----- lib/unistd.in.h | 13 ++++++++++++- modules/unistd-safer | 1 + tests/test-posix_spawn1.c | 12 +----------- tests/test-posix_spawn2.c | 12 +----------- tests/test-posix_spawn3.c | 12 +----------- 14 files changed, 55 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 12adb30e0..22ad726a0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,29 @@ 2009-01-19 Eric Blake + unistd: guarantee STDIN_FILENO here, for OS/2 EMX + * lib/unistd.in.h (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): + Guarantee a definition. + * doc/posix-headers/unistd.texi (unistd.h): Document the bug. + * modules/unistd-safer (Depends-on): Add dependency on unistd. + * lib/c-stack.c (STDERR_FILENO): Rely on . + * lib/dup-safer.c (STDERR_FILENO): Likewise. + * lib/execute.c (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): + Likewise. + * lib/fd-safer.c (STDIN_FILENO, STDERR_FILENO): Likewise. + * lib/fopen-safer.c (STDERR_FILENO): Likewise. + * lib/pipe.c (STDIN_FILENO, STDOUT_FILENO, STDERR_FILENO): + Likewise. + * lib/tmpfile-safer.c (STDERR_FILENO): Likewise. + * tests/test-posix_spawn1.c (STDIN_FILENO, STDOUT_FILENO) + (STDERR_FILENO): Likewise. + * tests/test-posix_spawn2.c (STDIN_FILENO, STDOUT_FILENO) + (STDERR_FILENO): Likewise. + * tests/test-posix_spawn3.c (STDIN_FILENO, STDOUT_FILENO) + (STDERR_FILENO): Likewise. + Reported by Elbert Pol. + +2009-01-19 Eric Blake + doc: mention more functions added in cygwin 1.7.0 * doc/posix-functions/abort.texi (abort): Update wording related to cygwin. diff --git a/doc/posix-headers/unistd.texi b/doc/posix-headers/unistd.texi index b4336a6bb..855eefbbe 100644 --- a/doc/posix-headers/unistd.texi +++ b/doc/posix-headers/unistd.texi @@ -10,7 +10,11 @@ Portability problems fixed by Gnulib: @item This header file is missing on some platforms: msvc. @item -The SEEK_* macros are not defined in this file on some platforms: mingw. +The SEEK_* macros are not defined in this file on some platforms: +mingw. +@item +The *_FILENO macros are not defined in this file on some platforms: +OS/2 EMX, mingw. @item The @code{_exit} function is not declared in this file on some platforms: mingw. diff --git a/lib/c-stack.c b/lib/c-stack.c index 023f8479a..e5e3ab610 100644 --- a/lib/c-stack.c +++ b/lib/c-stack.c @@ -1,6 +1,7 @@ /* Stack overflow handling. - Copyright (C) 2002, 2004, 2006, 2008 Free Software Foundation, Inc. + Copyright (C) 2002, 2004, 2006, 2008, 2009 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -67,9 +68,6 @@ typedef struct sigaltstack stack_t; #endif #include -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif #if HAVE_LIBSIGSEGV # include diff --git a/lib/dup-safer.c b/lib/dup-safer.c index a6908511a..7d9b2be34 100644 --- a/lib/dup-safer.c +++ b/lib/dup-safer.c @@ -1,6 +1,7 @@ /* Invoke dup, but avoid some glitches. - Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2004, 2005, 2006, 2009 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,9 +25,6 @@ #include #include -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif /* Like dup, but do not return STDIN_FILENO, STDOUT_FILENO, or STDERR_FILENO. */ diff --git a/lib/execute.c b/lib/execute.c index 231f46738..71da46fb7 100644 --- a/lib/execute.c +++ b/lib/execute.c @@ -1,5 +1,5 @@ /* Creation of autonomous subprocesses. - Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -54,16 +54,6 @@ #endif -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - /* The results of open() in this file are not used with fchdir, therefore save some unnecessary work in fchdir.c. */ #undef open diff --git a/lib/fd-safer.c b/lib/fd-safer.c index df38c8f7e..fb9900180 100644 --- a/lib/fd-safer.c +++ b/lib/fd-safer.c @@ -1,6 +1,6 @@ /* Return a safer copy of a file descriptor. - Copyright (C) 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2005, 2006, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,12 +24,6 @@ #include #include -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif /* Return FD, unless FD would be a copy of standard input, output, or error; in that case, return a duplicate of FD, closing FD. On diff --git a/lib/fopen-safer.c b/lib/fopen-safer.c index 55991a255..9c7992237 100644 --- a/lib/fopen-safer.c +++ b/lib/fopen-safer.c @@ -1,6 +1,7 @@ /* Invoke fopen, but avoid some glitches. - Copyright (C) 2001, 2004, 2005, 2006 Free Software Foundation, Inc. + Copyright (C) 2001, 2004, 2005, 2006, 2009 Free Software + Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -25,10 +26,6 @@ #include #include "unistd-safer.h" -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - /* Like fopen, but do not return stdin, stdout, or stderr. */ FILE * diff --git a/lib/pipe.c b/lib/pipe.c index 05bd4ece6..d842c77f9 100644 --- a/lib/pipe.c +++ b/lib/pipe.c @@ -1,5 +1,5 @@ /* Creation of subprocesses, communicating via pipes. - Copyright (C) 2001-2004, 2006-2008 Free Software Foundation, Inc. + Copyright (C) 2001-2004, 2006-2009 Free Software Foundation, Inc. Written by Bruno Haible , 2001. This program is free software: you can redistribute it and/or modify @@ -54,16 +54,6 @@ #endif -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - /* The results of open() in this file are not used with fchdir, therefore save some unnecessary work in fchdir.c. */ #undef open diff --git a/lib/tmpfile-safer.c b/lib/tmpfile-safer.c index eec401a40..e8d05aec3 100644 --- a/lib/tmpfile-safer.c +++ b/lib/tmpfile-safer.c @@ -1,5 +1,5 @@ /* Invoke tmpfile, but avoid some glitches. - Copyright (C) 2006 Free Software Foundation, Inc. + Copyright (C) 2006, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,10 +26,6 @@ #include "binary-io.h" -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - /* Like tmpfile, but do not return stdin, stdout, or stderr. Remember that tmpfile can leave files behind if your program calls _exit, diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 52db71c0f..d8276b1e1 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -29,7 +29,7 @@ #ifndef _GL_UNISTD_H #define _GL_UNISTD_H -/* mingw doesn't define the SEEK_* macros in . */ +/* mingw doesn't define the SEEK_* or *_FILENO macros in . */ #if !(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) # include #endif @@ -87,6 +87,17 @@ /* The definition of GL_LINK_WARNING is copied here. */ +/* OS/2 EMX lacks these macros. */ +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + /* Declare overridden functions. */ #ifdef __cplusplus diff --git a/modules/unistd-safer b/modules/unistd-safer index 4f167e4b2..86e23abe0 100644 --- a/modules/unistd-safer +++ b/modules/unistd-safer @@ -10,6 +10,7 @@ lib/unistd-safer.h m4/unistd-safer.m4 Depends-on: +unistd configure.ac: gl_UNISTD_SAFER diff --git a/tests/test-posix_spawn1.c b/tests/test-posix_spawn1.c index 0c30b88d2..d3951ebae 100644 --- a/tests/test-posix_spawn1.c +++ b/tests/test-posix_spawn1.c @@ -1,5 +1,5 @@ /* Test of posix_spawn() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,16 +33,6 @@ extern char **environ; -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - #define CHILD_PROGRAM_FILENAME "test-posix_spawn1.sh" static int diff --git a/tests/test-posix_spawn2.c b/tests/test-posix_spawn2.c index 826d38b96..ca57713e4 100644 --- a/tests/test-posix_spawn2.c +++ b/tests/test-posix_spawn2.c @@ -1,5 +1,5 @@ /* Test of posix_spawn() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,16 +33,6 @@ extern char **environ; -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - #define CHILD_PROGRAM_FILENAME "test-posix_spawn2.sh" static int diff --git a/tests/test-posix_spawn3.c b/tests/test-posix_spawn3.c index ec5d46826..af71068fe 100644 --- a/tests/test-posix_spawn3.c +++ b/tests/test-posix_spawn3.c @@ -1,5 +1,5 @@ /* Test of posix_spawn() function. - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008, 2009 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -35,16 +35,6 @@ extern char **environ; -#ifndef STDIN_FILENO -# define STDIN_FILENO 0 -#endif -#ifndef STDOUT_FILENO -# define STDOUT_FILENO 1 -#endif -#ifndef STDERR_FILENO -# define STDERR_FILENO 2 -#endif - #define CHILD_PROGRAM_FILENAME "test-posix_spawn3" #define DATA_FILENAME "t!#$%&'()*+,-;=?@[\\]^_`{|}~.tmp" -- 2.11.0