Commit 2287ac98 authored by Paul Eggert's avatar Paul Eggert

Merge from gnulib.

parents a63e0781 4a621aae
2011-07-08 Paul Eggert <eggert@cs.ucla.edu>
* lib/getopt.c, lib/unistd.in.h, m4/getopt.m4: Merge from gnulib.
2011-07-07 Andreas Schwab <schwab@linux-m68k.org> 2011-07-07 Andreas Schwab <schwab@linux-m68k.org>
* configure.in (maintainer-mode): Reflect default in help string. * configure.in (maintainer-mode): Reflect default in help string.
......
...@@ -829,7 +829,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ...@@ -829,7 +829,7 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
return '?'; return '?';
} }
/* Convenience. Treat POSIX -W foo same as long option --foo */ /* Convenience. Treat POSIX -W foo same as long option --foo */
if (temp[0] == 'W' && temp[1] == ';' && longopts) if (temp[0] == 'W' && temp[1] == ';')
{ {
char *nameend; char *nameend;
const struct option *p; const struct option *p;
...@@ -839,6 +839,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ...@@ -839,6 +839,9 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
int indfound = 0; int indfound = 0;
int option_index; int option_index;
if (longopts == NULL)
goto no_longs;
/* This is an option that requires an argument. */ /* This is an option that requires an argument. */
if (*d->__nextchar != '\0') if (*d->__nextchar != '\0')
{ {
...@@ -1046,8 +1049,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring, ...@@ -1046,8 +1049,10 @@ _getopt_internal_r (int argc, char **argv, const char *optstring,
} }
return pfound->val; return pfound->val;
} }
d->__nextchar = NULL;
return 'W'; /* Let the application handle it. */ no_longs:
d->__nextchar = NULL;
return 'W'; /* Let the application handle it. */
} }
if (temp[1] == ':') if (temp[1] == ':')
{ {
......
...@@ -117,78 +117,77 @@ ...@@ -117,78 +117,77 @@
/* The definition of _GL_WARN_ON_USE is copied here. */ /* The definition of _GL_WARN_ON_USE is copied here. */
#if @GNULIB_GETHOSTNAME@ /* Hide some function declarations from <winsock2.h>. */
/* Get all possible declarations of gethostname(). */
# if @UNISTD_H_HAVE_WINSOCK2_H@ #if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@
# if !defined _@GUARD_PREFIX@_SYS_SOCKET_H # if !defined _@GUARD_PREFIX@_SYS_SOCKET_H
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef socket # undef socket
# define socket socket_used_without_including_sys_socket_h # define socket socket_used_without_including_sys_socket_h
# undef connect # undef connect
# define connect connect_used_without_including_sys_socket_h # define connect connect_used_without_including_sys_socket_h
# undef accept # undef accept
# define accept accept_used_without_including_sys_socket_h # define accept accept_used_without_including_sys_socket_h
# undef bind # undef bind
# define bind bind_used_without_including_sys_socket_h # define bind bind_used_without_including_sys_socket_h
# undef getpeername # undef getpeername
# define getpeername getpeername_used_without_including_sys_socket_h # define getpeername getpeername_used_without_including_sys_socket_h
# undef getsockname # undef getsockname
# define getsockname getsockname_used_without_including_sys_socket_h # define getsockname getsockname_used_without_including_sys_socket_h
# undef getsockopt # undef getsockopt
# define getsockopt getsockopt_used_without_including_sys_socket_h # define getsockopt getsockopt_used_without_including_sys_socket_h
# undef listen # undef listen
# define listen listen_used_without_including_sys_socket_h # define listen listen_used_without_including_sys_socket_h
# undef recv # undef recv
# define recv recv_used_without_including_sys_socket_h # define recv recv_used_without_including_sys_socket_h
# undef send # undef send
# define send send_used_without_including_sys_socket_h # define send send_used_without_including_sys_socket_h
# undef recvfrom # undef recvfrom
# define recvfrom recvfrom_used_without_including_sys_socket_h # define recvfrom recvfrom_used_without_including_sys_socket_h
# undef sendto # undef sendto
# define sendto sendto_used_without_including_sys_socket_h # define sendto sendto_used_without_including_sys_socket_h
# undef setsockopt # undef setsockopt
# define setsockopt setsockopt_used_without_including_sys_socket_h # define setsockopt setsockopt_used_without_including_sys_socket_h
# undef shutdown # undef shutdown
# define shutdown shutdown_used_without_including_sys_socket_h # define shutdown shutdown_used_without_including_sys_socket_h
# else # else
_GL_WARN_ON_USE (socket, _GL_WARN_ON_USE (socket,
"socket() used without including <sys/socket.h>"); "socket() used without including <sys/socket.h>");
_GL_WARN_ON_USE (connect, _GL_WARN_ON_USE (connect,
"connect() used without including <sys/socket.h>"); "connect() used without including <sys/socket.h>");
_GL_WARN_ON_USE (accept, _GL_WARN_ON_USE (accept,
"accept() used without including <sys/socket.h>"); "accept() used without including <sys/socket.h>");
_GL_WARN_ON_USE (bind, _GL_WARN_ON_USE (bind,
"bind() used without including <sys/socket.h>"); "bind() used without including <sys/socket.h>");
_GL_WARN_ON_USE (getpeername, _GL_WARN_ON_USE (getpeername,
"getpeername() used without including <sys/socket.h>"); "getpeername() used without including <sys/socket.h>");
_GL_WARN_ON_USE (getsockname, _GL_WARN_ON_USE (getsockname,
"getsockname() used without including <sys/socket.h>"); "getsockname() used without including <sys/socket.h>");
_GL_WARN_ON_USE (getsockopt, _GL_WARN_ON_USE (getsockopt,
"getsockopt() used without including <sys/socket.h>"); "getsockopt() used without including <sys/socket.h>");
_GL_WARN_ON_USE (listen, _GL_WARN_ON_USE (listen,
"listen() used without including <sys/socket.h>"); "listen() used without including <sys/socket.h>");
_GL_WARN_ON_USE (recv, _GL_WARN_ON_USE (recv,
"recv() used without including <sys/socket.h>"); "recv() used without including <sys/socket.h>");
_GL_WARN_ON_USE (send, _GL_WARN_ON_USE (send,
"send() used without including <sys/socket.h>"); "send() used without including <sys/socket.h>");
_GL_WARN_ON_USE (recvfrom, _GL_WARN_ON_USE (recvfrom,
"recvfrom() used without including <sys/socket.h>"); "recvfrom() used without including <sys/socket.h>");
_GL_WARN_ON_USE (sendto, _GL_WARN_ON_USE (sendto,
"sendto() used without including <sys/socket.h>"); "sendto() used without including <sys/socket.h>");
_GL_WARN_ON_USE (setsockopt, _GL_WARN_ON_USE (setsockopt,
"setsockopt() used without including <sys/socket.h>"); "setsockopt() used without including <sys/socket.h>");
_GL_WARN_ON_USE (shutdown, _GL_WARN_ON_USE (shutdown,
"shutdown() used without including <sys/socket.h>"); "shutdown() used without including <sys/socket.h>");
# endif
# endif # endif
# if !defined _@GUARD_PREFIX@_SYS_SELECT_H # endif
# if !(defined __cplusplus && defined GNULIB_NAMESPACE) # if !defined _@GUARD_PREFIX@_SYS_SELECT_H
# undef select # if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# define select select_used_without_including_sys_select_h # undef select
# else # define select select_used_without_including_sys_select_h
_GL_WARN_ON_USE (select, # else
"select() used without including <sys/select.h>"); _GL_WARN_ON_USE (select,
# endif "select() used without including <sys/select.h>");
# endif # endif
# endif # endif
#endif #endif
......
# getopt.m4 serial 35 # getopt.m4 serial 38
dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc. dnl Copyright (C) 2002-2006, 2008-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
...@@ -89,15 +89,15 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS], ...@@ -89,15 +89,15 @@ AC_DEFUN([gl_GETOPT_CHECK_HEADERS],
AC_CACHE_CHECK([whether getopt is POSIX compatible], AC_CACHE_CHECK([whether getopt is POSIX compatible],
[gl_cv_func_getopt_posix], [gl_cv_func_getopt_posix],
[ [
dnl BSD getopt_long uses an incompatible method to reset dnl BSD getopt_long uses an incompatible method to reset option
dnl option processing. Existence of the variable, in and of dnl processing. Existence of the optreset variable, in and of
dnl itself, is not a reason to replace getopt, but knowledge dnl itself, is not a reason to replace getopt, but knowledge
dnl of the variable is needed to determine how to reset and dnl of the variable is needed to determine how to reset and
dnl whether a reset reparses the environment. Solaris dnl whether a reset reparses the environment. Solaris
dnl supports neither optreset nor optind=0, but keeps no state dnl supports neither optreset nor optind=0, but keeps no state
dnl that needs a reset beyond setting optind=1; detect Solaris dnl that needs a reset beyond setting optind=1; detect Solaris
dnl by getopt_clip. dnl by getopt_clip.
AC_COMPILE_IFELSE( AC_LINK_IFELSE(
[AC_LANG_PROGRAM( [AC_LANG_PROGRAM(
[[#include <unistd.h>]], [[#include <unistd.h>]],
[[int *p = &optreset; return optreset;]])], [[int *p = &optreset; return optreset;]])],
...@@ -121,22 +121,20 @@ int ...@@ -121,22 +121,20 @@ int
main () main ()
{ {
{ {
int argc = 0; static char program[] = "program";
char *argv[10]; static char a[] = "-a";
static char foo[] = "foo";
static char bar[] = "bar";
char *argv[] = { program, a, foo, bar, NULL };
int c; int c;
argv[argc++] = "program";
argv[argc++] = "-a";
argv[argc++] = "foo";
argv[argc++] = "bar";
argv[argc] = NULL;
optind = OPTIND_MIN; optind = OPTIND_MIN;
opterr = 0; opterr = 0;
c = getopt (argc, argv, "ab"); c = getopt (4, argv, "ab");
if (!(c == 'a')) if (!(c == 'a'))
return 1; return 1;
c = getopt (argc, argv, "ab"); c = getopt (4, argv, "ab");
if (!(c == -1)) if (!(c == -1))
return 2; return 2;
if (!(optind == 2)) if (!(optind == 2))
...@@ -144,22 +142,20 @@ main () ...@@ -144,22 +142,20 @@ main ()
} }
/* Some internal state exists at this point. */ /* Some internal state exists at this point. */
{ {
int argc = 0; static char program[] = "program";
char *argv[10]; static char donald[] = "donald";
static char p[] = "-p";
static char billy[] = "billy";
static char duck[] = "duck";
static char a[] = "-a";
static char bar[] = "bar";
char *argv[] = { program, donald, p, billy, duck, a, bar, NULL };
int c; int c;
argv[argc++] = "program";
argv[argc++] = "donald";
argv[argc++] = "-p";
argv[argc++] = "billy";
argv[argc++] = "duck";
argv[argc++] = "-a";
argv[argc++] = "bar";
argv[argc] = NULL;
optind = OPTIND_MIN; optind = OPTIND_MIN;
opterr = 0; opterr = 0;
c = getopt (argc, argv, "+abp:q:"); c = getopt (7, argv, "+abp:q:");
if (!(c == -1)) if (!(c == -1))
return 4; return 4;
if (!(strcmp (argv[0], "program") == 0)) if (!(strcmp (argv[0], "program") == 0))
...@@ -181,7 +177,9 @@ main () ...@@ -181,7 +177,9 @@ main ()
} }
/* Detect MacOS 10.5, AIX 7.1 bug. */ /* Detect MacOS 10.5, AIX 7.1 bug. */
{ {
char *argv[3] = { "program", "-ab", NULL }; static char program[] = "program";
static char ab[] = "-ab";
char *argv[3] = { program, ab, NULL };
optind = OPTIND_MIN; optind = OPTIND_MIN;
opterr = 0; opterr = 0;
if (getopt (2, argv, "ab:") != 'a') if (getopt (2, argv, "ab:") != 'a')
...@@ -239,19 +237,22 @@ dnl is ambiguous with environment values that contain newlines. ...@@ -239,19 +237,22 @@ dnl is ambiguous with environment values that contain newlines.
and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5, and fails on MacOS X 10.5, AIX 5.2, HP-UX 11, IRIX 6.5,
OSF/1 5.1, Solaris 10. */ OSF/1 5.1, Solaris 10. */
{ {
char *myargv[3]; static char conftest[] = "conftest";
myargv[0] = "conftest"; static char plus[] = "-+";
myargv[1] = "-+"; char *argv[3] = { conftest, plus, NULL };
myargv[2] = 0;
opterr = 0; opterr = 0;
if (getopt (2, myargv, "+a") != '?') if (getopt (2, argv, "+a") != '?')
result |= 1; result |= 1;
} }
/* This code succeeds on glibc 2.8, mingw, /* This code succeeds on glibc 2.8, mingw,
and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11, and fails on MacOS X 10.5, OpenBSD 4.0, AIX 5.2, HP-UX 11,
IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x. */ IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin 1.5.x. */
{ {
char *argv[] = { "program", "-p", "foo", "bar", NULL }; static char program[] = "program";
static char p[] = "-p";
static char foo[] = "foo";
static char bar[] = "bar";
char *argv[] = { program, p, foo, bar, NULL };
optind = 1; optind = 1;
if (getopt (4, argv, "p::") != 'p') if (getopt (4, argv, "p::") != 'p')
...@@ -265,7 +266,10 @@ dnl is ambiguous with environment values that contain newlines. ...@@ -265,7 +266,10 @@ dnl is ambiguous with environment values that contain newlines.
} }
/* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */ /* This code succeeds on glibc 2.8 and fails on Cygwin 1.7.0. */
{ {
char *argv[] = { "program", "foo", "-p", NULL }; static char program[] = "program";
static char foo[] = "foo";
static char p[] = "-p";
char *argv[] = { program, foo, p, NULL };
optind = 0; optind = 0;
if (getopt (3, argv, "-p") != 1) if (getopt (3, argv, "-p") != 1)
result |= 16; result |= 16;
...@@ -274,13 +278,26 @@ dnl is ambiguous with environment values that contain newlines. ...@@ -274,13 +278,26 @@ dnl is ambiguous with environment values that contain newlines.
} }
/* This code fails on glibc 2.11. */ /* This code fails on glibc 2.11. */
{ {
char *argv[] = { "program", "-b", "-a", NULL }; static char program[] = "program";
static char b[] = "-b";
static char a[] = "-a";
char *argv[] = { program, b, a, NULL };
optind = opterr = 0; optind = opterr = 0;
if (getopt (3, argv, "+:a:b") != 'b') if (getopt (3, argv, "+:a:b") != 'b')
result |= 64; result |= 64;
else if (getopt (3, argv, "+:a:b") != ':') else if (getopt (3, argv, "+:a:b") != ':')
result |= 64; result |= 64;
} }
/* This code dumps core on glibc 2.14. */
{
static char program[] = "program";
static char w[] = "-W";
static char dummy[] = "dummy";
char *argv[] = { program, w, dummy, NULL };
optind = opterr = 1;
if (getopt (3, argv, "W;") != 'W')
result |= 128;
}
return result; return result;
]])], ]])],
[gl_cv_func_getopt_gnu=yes], [gl_cv_func_getopt_gnu=yes],
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment