aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorPaul Eggert2011-01-08 23:33:50 -0800
committerPaul Eggert2011-01-08 23:33:50 -0800
commite275c824b0fe255bbb5af98a6c9a21bb8321d6e8 (patch)
tree55f731672b2aa769d9807f3d014ffbf33c5a759e /lib
parent84bbb1add53329f6059958a9609240aed336258c (diff)
downloademacs-e275c824b0fe255bbb5af98a6c9a21bb8321d6e8.tar.gz
emacs-e275c824b0fe255bbb5af98a6c9a21bb8321d6e8.zip
Regenerate.
Diffstat (limited to 'lib')
-rw-r--r--lib/Makefile.in279
-rw-r--r--lib/getopt.c1192
-rw-r--r--lib/getopt.in.h250
-rw-r--r--lib/getopt1.c170
-rw-r--r--lib/getopt_int.h135
-rw-r--r--lib/gettext.h280
-rw-r--r--lib/gnulib.mk165
-rw-r--r--lib/unistd.in.h1378
8 files changed, 3835 insertions, 14 deletions
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 40254045808..22aadb78ad7 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -24,7 +24,7 @@
24# the same distribution terms as the rest of that program. 24# the same distribution terms as the rest of that program.
25# 25#
26# Generated by gnulib-tool. 26# Generated by gnulib-tool.
27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr mktime 27# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr getopt-gnu mktime
28 28
29VPATH = @srcdir@ 29VPATH = @srcdir@
30pkgdatadir = $(datadir)/@PACKAGE@ 30pkgdatadir = $(datadir)/@PACKAGE@
@@ -51,13 +51,13 @@ subdir = lib
51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 51ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \ 52am__aclocal_m4_deps = $(top_srcdir)/m4/00gnulib.m4 \
53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \ 53 $(top_srcdir)/m4/c-strtod.m4 $(top_srcdir)/m4/extensions.m4 \
54 $(top_srcdir)/m4/gnulib-common.m4 \ 54 $(top_srcdir)/m4/getopt.m4 $(top_srcdir)/m4/gnulib-common.m4 \
55 $(top_srcdir)/m4/gnulib-comp.m4 \ 55 $(top_srcdir)/m4/gnulib-comp.m4 \
56 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/mktime.m4 \ 56 $(top_srcdir)/m4/include_next.m4 $(top_srcdir)/m4/mktime.m4 \
57 $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/stddef_h.m4 \ 57 $(top_srcdir)/m4/multiarch.m4 $(top_srcdir)/m4/stddef_h.m4 \
58 $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \ 58 $(top_srcdir)/m4/time_h.m4 $(top_srcdir)/m4/time_r.m4 \
59 $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/m4/getopt.m4 \ 59 $(top_srcdir)/m4/unistd_h.m4 $(top_srcdir)/m4/warn-on-use.m4 \
60 $(top_srcdir)/configure.in 60 $(top_srcdir)/m4/wchar_t.m4 $(top_srcdir)/configure.in
61am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ 61am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
62 $(ACLOCAL_M4) 62 $(ACLOCAL_M4)
63mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs 63mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs
@@ -132,14 +132,54 @@ FREETYPE_LIBS = @FREETYPE_LIBS@
132GCONF_CFLAGS = @GCONF_CFLAGS@ 132GCONF_CFLAGS = @GCONF_CFLAGS@
133GCONF_LIBS = @GCONF_LIBS@ 133GCONF_LIBS = @GCONF_LIBS@
134GETLOADAVG_LIBS = @GETLOADAVG_LIBS@ 134GETLOADAVG_LIBS = @GETLOADAVG_LIBS@
135GETOPTOBJS = @GETOPTOBJS@
136GETOPT_H = @GETOPT_H@ 135GETOPT_H = @GETOPT_H@
137GMALLOC_OBJ = @GMALLOC_OBJ@ 136GMALLOC_OBJ = @GMALLOC_OBJ@
137GNULIB_CHOWN = @GNULIB_CHOWN@
138GNULIB_CLOSE = @GNULIB_CLOSE@
139GNULIB_DUP2 = @GNULIB_DUP2@
140GNULIB_DUP3 = @GNULIB_DUP3@
141GNULIB_ENVIRON = @GNULIB_ENVIRON@
142GNULIB_EUIDACCESS = @GNULIB_EUIDACCESS@
143GNULIB_FACCESSAT = @GNULIB_FACCESSAT@
144GNULIB_FCHDIR = @GNULIB_FCHDIR@
145GNULIB_FCHOWNAT = @GNULIB_FCHOWNAT@
146GNULIB_FSYNC = @GNULIB_FSYNC@
147GNULIB_FTRUNCATE = @GNULIB_FTRUNCATE@
148GNULIB_GETCWD = @GNULIB_GETCWD@
149GNULIB_GETDOMAINNAME = @GNULIB_GETDOMAINNAME@
150GNULIB_GETDTABLESIZE = @GNULIB_GETDTABLESIZE@
151GNULIB_GETGROUPS = @GNULIB_GETGROUPS@
152GNULIB_GETHOSTNAME = @GNULIB_GETHOSTNAME@
153GNULIB_GETLOGIN = @GNULIB_GETLOGIN@
154GNULIB_GETLOGIN_R = @GNULIB_GETLOGIN_R@
155GNULIB_GETPAGESIZE = @GNULIB_GETPAGESIZE@
156GNULIB_GETUSERSHELL = @GNULIB_GETUSERSHELL@
157GNULIB_LCHOWN = @GNULIB_LCHOWN@
158GNULIB_LINK = @GNULIB_LINK@
159GNULIB_LINKAT = @GNULIB_LINKAT@
160GNULIB_LSEEK = @GNULIB_LSEEK@
138GNULIB_MKTIME = @GNULIB_MKTIME@ 161GNULIB_MKTIME = @GNULIB_MKTIME@
139GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@ 162GNULIB_NANOSLEEP = @GNULIB_NANOSLEEP@
163GNULIB_PIPE = @GNULIB_PIPE@
164GNULIB_PIPE2 = @GNULIB_PIPE2@
165GNULIB_PREAD = @GNULIB_PREAD@
166GNULIB_PWRITE = @GNULIB_PWRITE@
167GNULIB_READLINK = @GNULIB_READLINK@
168GNULIB_READLINKAT = @GNULIB_READLINKAT@
169GNULIB_RMDIR = @GNULIB_RMDIR@
170GNULIB_SLEEP = @GNULIB_SLEEP@
140GNULIB_STRPTIME = @GNULIB_STRPTIME@ 171GNULIB_STRPTIME = @GNULIB_STRPTIME@
172GNULIB_SYMLINK = @GNULIB_SYMLINK@
173GNULIB_SYMLINKAT = @GNULIB_SYMLINKAT@
141GNULIB_TIMEGM = @GNULIB_TIMEGM@ 174GNULIB_TIMEGM = @GNULIB_TIMEGM@
142GNULIB_TIME_R = @GNULIB_TIME_R@ 175GNULIB_TIME_R = @GNULIB_TIME_R@
176GNULIB_TTYNAME_R = @GNULIB_TTYNAME_R@
177GNULIB_UNISTD_H_GETOPT = @GNULIB_UNISTD_H_GETOPT@
178GNULIB_UNISTD_H_SIGPIPE = @GNULIB_UNISTD_H_SIGPIPE@
179GNULIB_UNLINK = @GNULIB_UNLINK@
180GNULIB_UNLINKAT = @GNULIB_UNLINKAT@
181GNULIB_USLEEP = @GNULIB_USLEEP@
182GNULIB_WRITE = @GNULIB_WRITE@
143GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@ 183GNU_OBJC_CFLAGS = @GNU_OBJC_CFLAGS@
144GREP = @GREP@ 184GREP = @GREP@
145GTK_CFLAGS = @GTK_CFLAGS@ 185GTK_CFLAGS = @GTK_CFLAGS@
@@ -147,11 +187,50 @@ GTK_LIBS = @GTK_LIBS@
147GTK_OBJ = @GTK_OBJ@ 187GTK_OBJ = @GTK_OBJ@
148GZIP_INFO = @GZIP_INFO@ 188GZIP_INFO = @GZIP_INFO@
149GZIP_PROG = @GZIP_PROG@ 189GZIP_PROG = @GZIP_PROG@
190HAVE_CHOWN = @HAVE_CHOWN@
191HAVE_DECL_ENVIRON = @HAVE_DECL_ENVIRON@
192HAVE_DECL_FCHDIR = @HAVE_DECL_FCHDIR@
193HAVE_DECL_GETDOMAINNAME = @HAVE_DECL_GETDOMAINNAME@
194HAVE_DECL_GETLOGIN_R = @HAVE_DECL_GETLOGIN_R@
195HAVE_DECL_GETPAGESIZE = @HAVE_DECL_GETPAGESIZE@
196HAVE_DECL_GETUSERSHELL = @HAVE_DECL_GETUSERSHELL@
150HAVE_DECL_LOCALTIME_R = @HAVE_DECL_LOCALTIME_R@ 197HAVE_DECL_LOCALTIME_R = @HAVE_DECL_LOCALTIME_R@
198HAVE_DECL_TTYNAME_R = @HAVE_DECL_TTYNAME_R@
199HAVE_DUP2 = @HAVE_DUP2@
200HAVE_DUP3 = @HAVE_DUP3@
201HAVE_EUIDACCESS = @HAVE_EUIDACCESS@
202HAVE_FACCESSAT = @HAVE_FACCESSAT@
203HAVE_FCHDIR = @HAVE_FCHDIR@
204HAVE_FCHOWNAT = @HAVE_FCHOWNAT@
205HAVE_FSYNC = @HAVE_FSYNC@
206HAVE_FTRUNCATE = @HAVE_FTRUNCATE@
207HAVE_GETDTABLESIZE = @HAVE_GETDTABLESIZE@
208HAVE_GETGROUPS = @HAVE_GETGROUPS@
209HAVE_GETHOSTNAME = @HAVE_GETHOSTNAME@
210HAVE_GETLOGIN = @HAVE_GETLOGIN@
211HAVE_GETOPT_H = @HAVE_GETOPT_H@
212HAVE_GETPAGESIZE = @HAVE_GETPAGESIZE@
213HAVE_LCHOWN = @HAVE_LCHOWN@
214HAVE_LINK = @HAVE_LINK@
215HAVE_LINKAT = @HAVE_LINKAT@
151HAVE_MAKEINFO = @HAVE_MAKEINFO@ 216HAVE_MAKEINFO = @HAVE_MAKEINFO@
152HAVE_NANOSLEEP = @HAVE_NANOSLEEP@ 217HAVE_NANOSLEEP = @HAVE_NANOSLEEP@
218HAVE_OS_H = @HAVE_OS_H@
219HAVE_PIPE = @HAVE_PIPE@
220HAVE_PIPE2 = @HAVE_PIPE2@
221HAVE_PREAD = @HAVE_PREAD@
222HAVE_PWRITE = @HAVE_PWRITE@
223HAVE_READLINK = @HAVE_READLINK@
224HAVE_READLINKAT = @HAVE_READLINKAT@
225HAVE_SLEEP = @HAVE_SLEEP@
153HAVE_STRPTIME = @HAVE_STRPTIME@ 226HAVE_STRPTIME = @HAVE_STRPTIME@
227HAVE_SYMLINK = @HAVE_SYMLINK@
228HAVE_SYMLINKAT = @HAVE_SYMLINKAT@
229HAVE_SYS_PARAM_H = @HAVE_SYS_PARAM_H@
154HAVE_TIMEGM = @HAVE_TIMEGM@ 230HAVE_TIMEGM = @HAVE_TIMEGM@
231HAVE_UNISTD_H = @HAVE_UNISTD_H@
232HAVE_UNLINKAT = @HAVE_UNLINKAT@
233HAVE_USLEEP = @HAVE_USLEEP@
155HAVE_WCHAR_T = @HAVE_WCHAR_T@ 234HAVE_WCHAR_T = @HAVE_WCHAR_T@
156HAVE_XSERVER = @HAVE_XSERVER@ 235HAVE_XSERVER = @HAVE_XSERVER@
157IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@ 236IMAGEMAGICK_CFLAGS = @IMAGEMAGICK_CFLAGS@
@@ -181,6 +260,7 @@ LIBGNU_LIBDEPS = @LIBGNU_LIBDEPS@
181LIBGNU_LTLIBDEPS = @LIBGNU_LTLIBDEPS@ 260LIBGNU_LTLIBDEPS = @LIBGNU_LTLIBDEPS@
182LIBGPM = @LIBGPM@ 261LIBGPM = @LIBGPM@
183LIBHESIOD = @LIBHESIOD@ 262LIBHESIOD = @LIBHESIOD@
263LIBINTL = @LIBINTL@
184LIBJPEG = @LIBJPEG@ 264LIBJPEG = @LIBJPEG@
185LIBOBJS = @LIBOBJS@ 265LIBOBJS = @LIBOBJS@
186LIBOTF_CFLAGS = @LIBOTF_CFLAGS@ 266LIBOTF_CFLAGS = @LIBOTF_CFLAGS@
@@ -206,6 +286,7 @@ LIBX_OTHER = @LIBX_OTHER@
206LIB_GCC = @LIB_GCC@ 286LIB_GCC = @LIB_GCC@
207LIB_MATH = @LIB_MATH@ 287LIB_MATH = @LIB_MATH@
208LIB_STANDARD = @LIB_STANDARD@ 288LIB_STANDARD = @LIB_STANDARD@
289LTLIBINTL = @LTLIBINTL@
209LTLIBOBJS = @LTLIBOBJS@ 290LTLIBOBJS = @LTLIBOBJS@
210M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@ 291M17N_FLT_CFLAGS = @M17N_FLT_CFLAGS@
211M17N_FLT_LIBS = @M17N_FLT_LIBS@ 292M17N_FLT_LIBS = @M17N_FLT_LIBS@
@@ -216,10 +297,14 @@ MKDIR_P = @MKDIR_P@
216MOUSE_SUPPORT = @MOUSE_SUPPORT@ 297MOUSE_SUPPORT = @MOUSE_SUPPORT@
217M_FILE = @M_FILE@ 298M_FILE = @M_FILE@
218NEED_SETGID = @NEED_SETGID@ 299NEED_SETGID = @NEED_SETGID@
300NEXT_AS_FIRST_DIRECTIVE_GETOPT_H = @NEXT_AS_FIRST_DIRECTIVE_GETOPT_H@
219NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@ 301NEXT_AS_FIRST_DIRECTIVE_STDDEF_H = @NEXT_AS_FIRST_DIRECTIVE_STDDEF_H@
220NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@ 302NEXT_AS_FIRST_DIRECTIVE_TIME_H = @NEXT_AS_FIRST_DIRECTIVE_TIME_H@
303NEXT_AS_FIRST_DIRECTIVE_UNISTD_H = @NEXT_AS_FIRST_DIRECTIVE_UNISTD_H@
304NEXT_GETOPT_H = @NEXT_GETOPT_H@
221NEXT_STDDEF_H = @NEXT_STDDEF_H@ 305NEXT_STDDEF_H = @NEXT_STDDEF_H@
222NEXT_TIME_H = @NEXT_TIME_H@ 306NEXT_TIME_H = @NEXT_TIME_H@
307NEXT_UNISTD_H = @NEXT_UNISTD_H@
223NS_OBJ = @NS_OBJ@ 308NS_OBJ = @NS_OBJ@
224NS_SUPPORT = @NS_SUPPORT@ 309NS_SUPPORT = @NS_SUPPORT@
225OBJEXT = @OBJEXT@ 310OBJEXT = @OBJEXT@
@@ -244,11 +329,36 @@ PROFILING_CFLAGS = @PROFILING_CFLAGS@
244PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@ 329PTHREAD_H_DEFINES_STRUCT_TIMESPEC = @PTHREAD_H_DEFINES_STRUCT_TIMESPEC@
245RALLOC_OBJ = @RALLOC_OBJ@ 330RALLOC_OBJ = @RALLOC_OBJ@
246RANLIB = @RANLIB@ 331RANLIB = @RANLIB@
332REPLACE_CHOWN = @REPLACE_CHOWN@
333REPLACE_CLOSE = @REPLACE_CLOSE@
334REPLACE_DUP = @REPLACE_DUP@
335REPLACE_DUP2 = @REPLACE_DUP2@
336REPLACE_FCHOWNAT = @REPLACE_FCHOWNAT@
337REPLACE_GETCWD = @REPLACE_GETCWD@
338REPLACE_GETDOMAINNAME = @REPLACE_GETDOMAINNAME@
339REPLACE_GETGROUPS = @REPLACE_GETGROUPS@
340REPLACE_GETLOGIN_R = @REPLACE_GETLOGIN_R@
341REPLACE_GETPAGESIZE = @REPLACE_GETPAGESIZE@
342REPLACE_LCHOWN = @REPLACE_LCHOWN@
343REPLACE_LINK = @REPLACE_LINK@
344REPLACE_LINKAT = @REPLACE_LINKAT@
247REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@ 345REPLACE_LOCALTIME_R = @REPLACE_LOCALTIME_R@
346REPLACE_LSEEK = @REPLACE_LSEEK@
248REPLACE_MKTIME = @REPLACE_MKTIME@ 347REPLACE_MKTIME = @REPLACE_MKTIME@
249REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@ 348REPLACE_NANOSLEEP = @REPLACE_NANOSLEEP@
250REPLACE_NULL = @REPLACE_NULL@ 349REPLACE_NULL = @REPLACE_NULL@
350REPLACE_PREAD = @REPLACE_PREAD@
351REPLACE_PWRITE = @REPLACE_PWRITE@
352REPLACE_READLINK = @REPLACE_READLINK@
353REPLACE_RMDIR = @REPLACE_RMDIR@
354REPLACE_SLEEP = @REPLACE_SLEEP@
355REPLACE_SYMLINK = @REPLACE_SYMLINK@
251REPLACE_TIMEGM = @REPLACE_TIMEGM@ 356REPLACE_TIMEGM = @REPLACE_TIMEGM@
357REPLACE_TTYNAME_R = @REPLACE_TTYNAME_R@
358REPLACE_UNLINK = @REPLACE_UNLINK@
359REPLACE_UNLINKAT = @REPLACE_UNLINKAT@
360REPLACE_USLEEP = @REPLACE_USLEEP@
361REPLACE_WRITE = @REPLACE_WRITE@
252RSVG_CFLAGS = @RSVG_CFLAGS@ 362RSVG_CFLAGS = @RSVG_CFLAGS@
253RSVG_LIBS = @RSVG_LIBS@ 363RSVG_LIBS = @RSVG_LIBS@
254SET_MAKE = @SET_MAKE@ 364SET_MAKE = @SET_MAKE@
@@ -264,6 +374,8 @@ TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
264TOOLKIT_LIBW = @TOOLKIT_LIBW@ 374TOOLKIT_LIBW = @TOOLKIT_LIBW@
265TOOLTIP_SUPPORT = @TOOLTIP_SUPPORT@ 375TOOLTIP_SUPPORT = @TOOLTIP_SUPPORT@
266UNEXEC_OBJ = @UNEXEC_OBJ@ 376UNEXEC_OBJ = @UNEXEC_OBJ@
377UNISTD_H_HAVE_WINSOCK2_H = @UNISTD_H_HAVE_WINSOCK2_H@
378UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
267VERSION = @VERSION@ 379VERSION = @VERSION@
268VMLIMIT_OBJ = @VMLIMIT_OBJ@ 380VMLIMIT_OBJ = @VMLIMIT_OBJ@
269WIDGET_OBJ = @WIDGET_OBJ@ 381WIDGET_OBJ = @WIDGET_OBJ@
@@ -356,20 +468,22 @@ x_default_search_path = @x_default_search_path@
356# statements but through direct file reference. Therefore this snippet must be 468# statements but through direct file reference. Therefore this snippet must be
357# present in all Makefile.am that need it. This is ensured by the applicability 469# present in all Makefile.am that need it. This is ensured by the applicability
358# 'all' defined above. 470# 'all' defined above.
359BUILT_SOURCES = arg-nonnull.h c++defs.h $(STDDEF_H) time.h \ 471BUILT_SOURCES = arg-nonnull.h c++defs.h $(GETOPT_H) $(STDDEF_H) time.h \
360 warn-on-use.h 472 unistd.h warn-on-use.h
361EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \ 473EXTRA_DIST = $(top_srcdir)/./arg-nonnull.h $(top_srcdir)/./c++defs.h \
362 intprops.h mktime-internal.h mktime.c stddef.in.h time.in.h \ 474 getopt.c getopt.in.h getopt1.c getopt_int.h intprops.h \
363 time_r.c $(top_srcdir)/./warn-on-use.h 475 mktime-internal.h mktime.c stddef.in.h time.in.h time_r.c \
476 unistd.in.h $(top_srcdir)/./warn-on-use.h
364MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \ 477MOSTLYCLEANFILES = core *.stackdump arg-nonnull.h arg-nonnull.h-t \
365 c++defs.h c++defs.h-t stddef.h stddef.h-t time.h time.h-t \ 478 c++defs.h c++defs.h-t getopt.h getopt.h-t stddef.h stddef.h-t \
366 warn-on-use.h warn-on-use.h-t 479 time.h time.h-t unistd.h unistd.h-t warn-on-use.h \
480 warn-on-use.h-t
367noinst_LIBRARIES = libgnu.a 481noinst_LIBRARIES = libgnu.a
368DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src 482DEFAULT_INCLUDES = -I. -I../src -I$(top_srcdir)/src
369libgnu_a_SOURCES = ftoastr.h ftoastr.c dtoastr.c ldtoastr.c 483libgnu_a_SOURCES = ftoastr.h ftoastr.c dtoastr.c ldtoastr.c gettext.h
370libgnu_a_LIBADD = $(gl_LIBOBJS) 484libgnu_a_LIBADD = $(gl_LIBOBJS)
371libgnu_a_DEPENDENCIES = $(gl_LIBOBJS) 485libgnu_a_DEPENDENCIES = $(gl_LIBOBJS)
372EXTRA_libgnu_a_SOURCES = mktime.c time_r.c 486EXTRA_libgnu_a_SOURCES = getopt.c getopt1.c mktime.c time_r.c
373ARG_NONNULL_H = arg-nonnull.h 487ARG_NONNULL_H = arg-nonnull.h
374CXXDEFS_H = c++defs.h 488CXXDEFS_H = c++defs.h
375WARN_ON_USE_H = warn-on-use.h 489WARN_ON_USE_H = warn-on-use.h
@@ -424,6 +538,8 @@ distclean-compile:
424 538
425@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@ 539@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/dtoastr.Po@am__quote@
426@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@ 540@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ftoastr.Po@am__quote@
541@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt.Po@am__quote@
542@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/getopt1.Po@am__quote@
427@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldtoastr.Po@am__quote@ 543@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ldtoastr.Po@am__quote@
428@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@ 544@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mktime.Po@am__quote@
429@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_r.Po@am__quote@ 545@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/time_r.Po@am__quote@
@@ -659,6 +775,21 @@ c++defs.h: $(top_srcdir)/./c++defs.h
659 > $@-t && \ 775 > $@-t && \
660 mv $@-t $@ 776 mv $@-t $@
661 777
778# We need the following in order to create <getopt.h> when the system
779# doesn't have one that works with the given compiler.
780getopt.h: getopt.in.h $(ARG_NONNULL_H)
781 $(AM_V_GEN)rm -f $@-t $@ && \
782 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
783 sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
784 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
785 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
786 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
787 -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
788 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
789 < $(srcdir)/getopt.in.h; \
790 } > $@-t && \
791 mv -f $@-t $@
792
662# We need the following in order to create <stddef.h> when the system 793# We need the following in order to create <stddef.h> when the system
663# doesn't have one that works with the given compiler. 794# doesn't have one that works with the given compiler.
664stddef.h: stddef.in.h 795stddef.h: stddef.in.h
@@ -705,6 +836,128 @@ time.h: time.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
705 < $(srcdir)/time.in.h; \ 836 < $(srcdir)/time.in.h; \
706 } > $@-t && \ 837 } > $@-t && \
707 mv $@-t $@ 838 mv $@-t $@
839
840# We need the following in order to create an empty placeholder for
841# <unistd.h> when the system doesn't have one.
842unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
843 $(AM_V_GEN)rm -f $@-t $@ && \
844 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
845 sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
846 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
847 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
848 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
849 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
850 -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \
851 -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
852 -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
853 -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \
854 -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
855 -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
856 -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \
857 -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
858 -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \
859 -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
860 -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
861 -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
862 -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
863 -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
864 -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \
865 -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
866 -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \
867 -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
868 -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
869 -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
870 -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
871 -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
872 -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \
873 -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
874 -e 's|@''GNULIB_PIPE''@|$(GNULIB_PIPE)|g' \
875 -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \
876 -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \
877 -e 's|@''GNULIB_PWRITE''@|$(GNULIB_PWRITE)|g' \
878 -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
879 -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \
880 -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \
881 -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
882 -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \
883 -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \
884 -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \
885 -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \
886 -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \
887 -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \
888 -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \
889 -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \
890 -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \
891 < $(srcdir)/unistd.in.h | \
892 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
893 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
894 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
895 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
896 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
897 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
898 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
899 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
900 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
901 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
902 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
903 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
904 -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
905 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
906 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
907 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
908 -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
909 -e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \
910 -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
911 -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
912 -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \
913 -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
914 -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \
915 -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
916 -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
917 -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
918 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
919 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
920 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
921 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
922 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
923 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
924 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
925 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
926 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
927 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
928 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
929 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
930 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
931 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
932 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
933 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
934 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
935 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
936 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
937 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
938 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
939 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
940 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
941 -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \
942 -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
943 -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \
944 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
945 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
946 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
947 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
948 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
949 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
950 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
951 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
952 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
953 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
954 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
955 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
956 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
957 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
958 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
959 } > $@-t && \
960 mv $@-t $@
708# The warn-on-use.h that gets inserted into generated .h files is the same as 961# The warn-on-use.h that gets inserted into generated .h files is the same as
709# build-aux/warn-on-use.h, except that it has the copyright header cut off. 962# build-aux/warn-on-use.h, except that it has the copyright header cut off.
710warn-on-use.h: $(top_srcdir)/./warn-on-use.h 963warn-on-use.h: $(top_srcdir)/./warn-on-use.h
diff --git a/lib/getopt.c b/lib/getopt.c
new file mode 100644
index 00000000000..c8b301363f1
--- /dev/null
+++ b/lib/getopt.c
@@ -0,0 +1,1192 @@
1/* Getopt for GNU.
2 NOTE: getopt is part of the C library, so if you don't know what
3 "Keep this file name-space clean" means, talk to drepper@gnu.org
4 before changing it!
5 Copyright (C) 1987-1996, 1998-2004, 2006, 2008-2011 Free Software
6 Foundation, Inc.
7 This file is part of the GNU C Library.
8
9 This program is free software: you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
13
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
18
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
21
22#ifndef _LIBC
23# include <config.h>
24#endif
25
26#include "getopt.h"
27
28#include <stdio.h>
29#include <stdlib.h>
30#include <string.h>
31#include <unistd.h>
32
33#ifdef _LIBC
34# include <libintl.h>
35#else
36# include "gettext.h"
37# define _(msgid) gettext (msgid)
38#endif
39
40#if defined _LIBC && defined USE_IN_LIBIO
41# include <wchar.h>
42#endif
43
44/* This version of `getopt' appears to the caller like standard Unix `getopt'
45 but it behaves differently for the user, since it allows the user
46 to intersperse the options with the other arguments.
47
48 As `getopt_long' works, it permutes the elements of ARGV so that,
49 when it is done, all the options precede everything else. Thus
50 all application programs are extended to handle flexible argument order.
51
52 Using `getopt' or setting the environment variable POSIXLY_CORRECT
53 disables permutation.
54 Then the behavior is completely standard.
55
56 GNU application programs can use a third alternative mode in which
57 they can distinguish the relative order of options and other arguments. */
58
59#include "getopt_int.h"
60
61/* For communication from `getopt' to the caller.
62 When `getopt' finds an option that takes an argument,
63 the argument value is returned here.
64 Also, when `ordering' is RETURN_IN_ORDER,
65 each non-option ARGV-element is returned here. */
66
67char *optarg;
68
69/* Index in ARGV of the next element to be scanned.
70 This is used for communication to and from the caller
71 and for communication between successive calls to `getopt'.
72
73 On entry to `getopt', zero means this is the first call; initialize.
74
75 When `getopt' returns -1, this is the index of the first of the
76 non-option elements that the caller should itself scan.
77
78 Otherwise, `optind' communicates from one call to the next
79 how much of ARGV has been scanned so far. */
80
81/* 1003.2 says this must be 1 before any call. */
82int optind = 1;
83
84/* Callers store zero here to inhibit the error message
85 for unrecognized options. */
86
87int opterr = 1;
88
89/* Set to an option character which was unrecognized.
90 This must be initialized on some systems to avoid linking in the
91 system's own getopt implementation. */
92
93int optopt = '?';
94
95/* Keep a global copy of all internal members of getopt_data. */
96
97static struct _getopt_data getopt_data;
98
99
100#if defined HAVE_DECL_GETENV && !HAVE_DECL_GETENV
101extern char *getenv ();
102#endif
103
104#ifdef _LIBC
105/* Stored original parameters.
106 XXX This is no good solution. We should rather copy the args so
107 that we can compare them later. But we must not use malloc(3). */
108extern int __libc_argc;
109extern char **__libc_argv;
110
111/* Bash 2.0 gives us an environment variable containing flags
112 indicating ARGV elements that should not be considered arguments. */
113
114# ifdef USE_NONOPTION_FLAGS
115/* Defined in getopt_init.c */
116extern char *__getopt_nonoption_flags;
117# endif
118
119# ifdef USE_NONOPTION_FLAGS
120# define SWAP_FLAGS(ch1, ch2) \
121 if (d->__nonoption_flags_len > 0) \
122 { \
123 char __tmp = __getopt_nonoption_flags[ch1]; \
124 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
125 __getopt_nonoption_flags[ch2] = __tmp; \
126 }
127# else
128# define SWAP_FLAGS(ch1, ch2)
129# endif
130#else /* !_LIBC */
131# define SWAP_FLAGS(ch1, ch2)
132#endif /* _LIBC */
133
134/* Exchange two adjacent subsequences of ARGV.
135 One subsequence is elements [first_nonopt,last_nonopt)
136 which contains all the non-options that have been skipped so far.
137 The other is elements [last_nonopt,optind), which contains all
138 the options processed since those non-options were skipped.
139
140 `first_nonopt' and `last_nonopt' are relocated so that they describe
141 the new indices of the non-options in ARGV after they are moved. */
142
143static void
144exchange (char **argv, struct _getopt_data *d)
145{
146 int bottom = d->__first_nonopt;
147 int middle = d->__last_nonopt;
148 int top = d->optind;
149 char *tem;
150
151 /* Exchange the shorter segment with the far end of the longer segment.
152 That puts the shorter segment into the right place.
153 It leaves the longer segment in the right place overall,
154 but it consists of two parts that need to be swapped next. */
155
156#if defined _LIBC && defined USE_NONOPTION_FLAGS
157 /* First make sure the handling of the `__getopt_nonoption_flags'
158 string can work normally. Our top argument must be in the range
159 of the string. */
160 if (d->__nonoption_flags_len > 0 && top >= d->__nonoption_flags_max_len)
161 {
162 /* We must extend the array. The user plays games with us and
163 presents new arguments. */
164 char *new_str = malloc (top + 1);
165 if (new_str == NULL)
166 d->__nonoption_flags_len = d->__nonoption_flags_max_len = 0;
167 else
168 {
169 memset (__mempcpy (new_str, __getopt_nonoption_flags,
170 d->__nonoption_flags_max_len),
171 '\0', top + 1 - d->__nonoption_flags_max_len);
172 d->__nonoption_flags_max_len = top + 1;
173 __getopt_nonoption_flags = new_str;
174 }
175 }
176#endif
177
178 while (top > middle && middle > bottom)
179 {
180 if (top - middle > middle - bottom)
181 {
182 /* Bottom segment is the short one. */
183 int len = middle - bottom;
184 register int i;
185
186 /* Swap it with the top part of the top segment. */
187 for (i = 0; i < len; i++)
188 {
189 tem = argv[bottom + i];
190 argv[bottom + i] = argv[top - (middle - bottom) + i];
191 argv[top - (middle - bottom) + i] = tem;
192 SWAP_FLAGS (bottom + i, top - (middle - bottom) + i);
193 }
194 /* Exclude the moved bottom segment from further swapping. */
195 top -= len;
196 }
197 else
198 {
199 /* Top segment is the short one. */
200 int len = top - middle;
201 register int i;
202
203 /* Swap it with the bottom part of the bottom segment. */
204 for (i = 0; i < len; i++)
205 {
206 tem = argv[bottom + i];
207 argv[bottom + i] = argv[middle + i];
208 argv[middle + i] = tem;
209 SWAP_FLAGS (bottom + i, middle + i);
210 }
211 /* Exclude the moved top segment from further swapping. */
212 bottom += len;
213 }
214 }
215
216 /* Update records for the slots the non-options now occupy. */
217
218 d->__first_nonopt += (d->optind - d->__last_nonopt);
219 d->__last_nonopt = d->optind;
220}
221
222/* Initialize the internal data when the first call is made. */
223
224static const char *
225_getopt_initialize (int argc _GL_UNUSED,
226 char **argv _GL_UNUSED, const char *optstring,
227 struct _getopt_data *d, int posixly_correct)
228{
229 /* Start processing options with ARGV-element 1 (since ARGV-element 0
230 is the program name); the sequence of previously skipped
231 non-option ARGV-elements is empty. */
232
233 d->__first_nonopt = d->__last_nonopt = d->optind;
234
235 d->__nextchar = NULL;
236
237 d->__posixly_correct = posixly_correct || !!getenv ("POSIXLY_CORRECT");
238
239 /* Determine how to handle the ordering of options and nonoptions. */
240
241 if (optstring[0] == '-')
242 {
243 d->__ordering = RETURN_IN_ORDER;
244 ++optstring;
245 }
246 else if (optstring[0] == '+')
247 {
248 d->__ordering = REQUIRE_ORDER;
249 ++optstring;
250 }
251 else if (d->__posixly_correct)
252 d->__ordering = REQUIRE_ORDER;
253 else
254 d->__ordering = PERMUTE;
255
256#if defined _LIBC && defined USE_NONOPTION_FLAGS
257 if (!d->__posixly_correct
258 && argc == __libc_argc && argv == __libc_argv)
259 {
260 if (d->__nonoption_flags_max_len == 0)
261 {
262 if (__getopt_nonoption_flags == NULL
263 || __getopt_nonoption_flags[0] == '\0')
264 d->__nonoption_flags_max_len = -1;
265 else
266 {
267 const char *orig_str = __getopt_nonoption_flags;
268 int len = d->__nonoption_flags_max_len = strlen (orig_str);
269 if (d->__nonoption_flags_max_len < argc)
270 d->__nonoption_flags_max_len = argc;
271 __getopt_nonoption_flags =
272 (char *) malloc (d->__nonoption_flags_max_len);
273 if (__getopt_nonoption_flags == NULL)
274 d->__nonoption_flags_max_len = -1;
275 else
276 memset (__mempcpy (__getopt_nonoption_flags, orig_str, len),
277 '\0', d->__nonoption_flags_max_len - len);
278 }
279 }
280 d->__nonoption_flags_len = d->__nonoption_flags_max_len;
281 }
282 else
283 d->__nonoption_flags_len = 0;
284#endif
285
286 return optstring;
287}
288
289/* Scan elements of ARGV (whose length is ARGC) for option characters
290 given in OPTSTRING.
291
292 If an element of ARGV starts with '-', and is not exactly "-" or "--",
293 then it is an option element. The characters of this element
294 (aside from the initial '-') are option characters. If `getopt'
295 is called repeatedly, it returns successively each of the option characters
296 from each of the option elements.
297
298 If `getopt' finds another option character, it returns that character,
299 updating `optind' and `nextchar' so that the next call to `getopt' can
300 resume the scan with the following option character or ARGV-element.
301
302 If there are no more option characters, `getopt' returns -1.
303 Then `optind' is the index in ARGV of the first ARGV-element
304 that is not an option. (The ARGV-elements have been permuted
305 so that those that are not options now come last.)
306
307 OPTSTRING is a string containing the legitimate option characters.
308 If an option character is seen that is not listed in OPTSTRING,
309 return '?' after printing an error message. If you set `opterr' to
310 zero, the error message is suppressed but we still return '?'.
311
312 If a char in OPTSTRING is followed by a colon, that means it wants an arg,
313 so the following text in the same ARGV-element, or the text of the following
314 ARGV-element, is returned in `optarg'. Two colons mean an option that
315 wants an optional arg; if there is text in the current ARGV-element,
316 it is returned in `optarg', otherwise `optarg' is set to zero.
317
318 If OPTSTRING starts with `-' or `+', it requests different methods of
319 handling the non-option ARGV-elements.
320 See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above.
321
322 Long-named options begin with `--' instead of `-'.
323 Their names may be abbreviated as long as the abbreviation is unique
324 or is an exact match for some defined option. If they have an
325 argument, it follows the option name in the same ARGV-element, separated
326 from the option name by a `=', or else the in next ARGV-element.
327 When `getopt' finds a long-named option, it returns 0 if that option's
328 `flag' field is nonzero, the value of the option's `val' field
329 if the `flag' field is zero.
330
331 The elements of ARGV aren't really const, because we permute them.
332 But we pretend they're const in the prototype to be compatible
333 with other systems.
334
335 LONGOPTS is a vector of `struct option' terminated by an
336 element containing a name which is zero.
337
338 LONGIND returns the index in LONGOPT of the long-named option found.
339 It is only valid when a long-named option has been found by the most
340 recent call.
341
342 If LONG_ONLY is nonzero, '-' as well as '--' can introduce
343 long-named options. */
344
345int
346_getopt_internal_r (int argc, char **argv, const char *optstring,
347 const struct option *longopts, int *longind,
348 int long_only, struct _getopt_data *d, int posixly_correct)
349{
350 int print_errors = d->opterr;
351
352 if (argc < 1)
353 return -1;
354
355 d->optarg = NULL;
356
357 if (d->optind == 0 || !d->__initialized)
358 {
359 if (d->optind == 0)
360 d->optind = 1; /* Don't scan ARGV[0], the program name. */
361 optstring = _getopt_initialize (argc, argv, optstring, d,
362 posixly_correct);
363 d->__initialized = 1;
364 }
365 else if (optstring[0] == '-' || optstring[0] == '+')
366 optstring++;
367 if (optstring[0] == ':')
368 print_errors = 0;
369
370 /* Test whether ARGV[optind] points to a non-option argument.
371 Either it does not have option syntax, or there is an environment flag
372 from the shell indicating it is not an option. The later information
373 is only used when the used in the GNU libc. */
374#if defined _LIBC && defined USE_NONOPTION_FLAGS
375# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0' \
376 || (d->optind < d->__nonoption_flags_len \
377 && __getopt_nonoption_flags[d->optind] == '1'))
378#else
379# define NONOPTION_P (argv[d->optind][0] != '-' || argv[d->optind][1] == '\0')
380#endif
381
382 if (d->__nextchar == NULL || *d->__nextchar == '\0')
383 {
384 /* Advance to the next ARGV-element. */
385
386 /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been
387 moved back by the user (who may also have changed the arguments). */
388 if (d->__last_nonopt > d->optind)
389 d->__last_nonopt = d->optind;
390 if (d->__first_nonopt > d->optind)
391 d->__first_nonopt = d->optind;
392
393 if (d->__ordering == PERMUTE)
394 {
395 /* If we have just processed some options following some non-options,
396 exchange them so that the options come first. */
397
398 if (d->__first_nonopt != d->__last_nonopt
399 && d->__last_nonopt != d->optind)
400 exchange ((char **) argv, d);
401 else if (d->__last_nonopt != d->optind)
402 d->__first_nonopt = d->optind;
403
404 /* Skip any additional non-options
405 and extend the range of non-options previously skipped. */
406
407 while (d->optind < argc && NONOPTION_P)
408 d->optind++;
409 d->__last_nonopt = d->optind;
410 }
411
412 /* The special ARGV-element `--' means premature end of options.
413 Skip it like a null option,
414 then exchange with previous non-options as if it were an option,
415 then skip everything else like a non-option. */
416
417 if (d->optind != argc && !strcmp (argv[d->optind], "--"))
418 {
419 d->optind++;
420
421 if (d->__first_nonopt != d->__last_nonopt
422 && d->__last_nonopt != d->optind)
423 exchange ((char **) argv, d);
424 else if (d->__first_nonopt == d->__last_nonopt)
425 d->__first_nonopt = d->optind;
426 d->__last_nonopt = argc;
427
428 d->optind = argc;
429 }
430
431 /* If we have done all the ARGV-elements, stop the scan
432 and back over any non-options that we skipped and permuted. */
433
434 if (d->optind == argc)
435 {
436 /* Set the next-arg-index to point at the non-options
437 that we previously skipped, so the caller will digest them. */
438 if (d->__first_nonopt != d->__last_nonopt)
439 d->optind = d->__first_nonopt;
440 return -1;
441 }
442
443 /* If we have come to a non-option and did not permute it,
444 either stop the scan or describe it to the caller and pass it by. */
445
446 if (NONOPTION_P)
447 {
448 if (d->__ordering == REQUIRE_ORDER)
449 return -1;
450 d->optarg = argv[d->optind++];
451 return 1;
452 }
453
454 /* We have found another option-ARGV-element.
455 Skip the initial punctuation. */
456
457 d->__nextchar = (argv[d->optind] + 1
458 + (longopts != NULL && argv[d->optind][1] == '-'));
459 }
460
461 /* Decode the current option-ARGV-element. */
462
463 /* Check whether the ARGV-element is a long option.
464
465 If long_only and the ARGV-element has the form "-f", where f is
466 a valid short option, don't consider it an abbreviated form of
467 a long option that starts with f. Otherwise there would be no
468 way to give the -f short option.
469
470 On the other hand, if there's a long option "fubar" and
471 the ARGV-element is "-fu", do consider that an abbreviation of
472 the long option, just like "--fu", and not "-f" with arg "u".
473
474 This distinction seems to be the most useful approach. */
475
476 if (longopts != NULL
477 && (argv[d->optind][1] == '-'
478 || (long_only && (argv[d->optind][2]
479 || !strchr (optstring, argv[d->optind][1])))))
480 {
481 char *nameend;
482 const struct option *p;
483 const struct option *pfound = NULL;
484 int exact = 0;
485 int ambig = 0;
486 int indfound = -1;
487 int option_index;
488
489 for (nameend = d->__nextchar; *nameend && *nameend != '='; nameend++)
490 /* Do nothing. */ ;
491
492 /* Test all long options for either exact match
493 or abbreviated matches. */
494 for (p = longopts, option_index = 0; p->name; p++, option_index++)
495 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
496 {
497 if ((unsigned int) (nameend - d->__nextchar)
498 == (unsigned int) strlen (p->name))
499 {
500 /* Exact match found. */
501 pfound = p;
502 indfound = option_index;
503 exact = 1;
504 break;
505 }
506 else if (pfound == NULL)
507 {
508 /* First nonexact match found. */
509 pfound = p;
510 indfound = option_index;
511 }
512 else if (long_only
513 || pfound->has_arg != p->has_arg
514 || pfound->flag != p->flag
515 || pfound->val != p->val)
516 /* Second or later nonexact match found. */
517 ambig = 1;
518 }
519
520 if (ambig && !exact)
521 {
522 if (print_errors)
523 {
524#if defined _LIBC && defined USE_IN_LIBIO
525 char *buf;
526
527 if (__asprintf (&buf, _("%s: option '%s' is ambiguous\n"),
528 argv[0], argv[d->optind]) >= 0)
529 {
530 _IO_flockfile (stderr);
531
532 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
533 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
534
535 __fxprintf (NULL, "%s", buf);
536
537 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
538 _IO_funlockfile (stderr);
539
540 free (buf);
541 }
542#else
543 fprintf (stderr, _("%s: option '%s' is ambiguous\n"),
544 argv[0], argv[d->optind]);
545#endif
546 }
547 d->__nextchar += strlen (d->__nextchar);
548 d->optind++;
549 d->optopt = 0;
550 return '?';
551 }
552
553 if (pfound != NULL)
554 {
555 option_index = indfound;
556 d->optind++;
557 if (*nameend)
558 {
559 /* Don't test has_arg with >, because some C compilers don't
560 allow it to be used on enums. */
561 if (pfound->has_arg)
562 d->optarg = nameend + 1;
563 else
564 {
565 if (print_errors)
566 {
567#if defined _LIBC && defined USE_IN_LIBIO
568 char *buf;
569 int n;
570#endif
571
572 if (argv[d->optind - 1][1] == '-')
573 {
574 /* --option */
575#if defined _LIBC && defined USE_IN_LIBIO
576 n = __asprintf (&buf, _("\
577%s: option '--%s' doesn't allow an argument\n"),
578 argv[0], pfound->name);
579#else
580 fprintf (stderr, _("\
581%s: option '--%s' doesn't allow an argument\n"),
582 argv[0], pfound->name);
583#endif
584 }
585 else
586 {
587 /* +option or -option */
588#if defined _LIBC && defined USE_IN_LIBIO
589 n = __asprintf (&buf, _("\
590%s: option '%c%s' doesn't allow an argument\n"),
591 argv[0], argv[d->optind - 1][0],
592 pfound->name);
593#else
594 fprintf (stderr, _("\
595%s: option '%c%s' doesn't allow an argument\n"),
596 argv[0], argv[d->optind - 1][0],
597 pfound->name);
598#endif
599 }
600
601#if defined _LIBC && defined USE_IN_LIBIO
602 if (n >= 0)
603 {
604 _IO_flockfile (stderr);
605
606 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
607 ((_IO_FILE *) stderr)->_flags2
608 |= _IO_FLAGS2_NOTCANCEL;
609
610 __fxprintf (NULL, "%s", buf);
611
612 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
613 _IO_funlockfile (stderr);
614
615 free (buf);
616 }
617#endif
618 }
619
620 d->__nextchar += strlen (d->__nextchar);
621
622 d->optopt = pfound->val;
623 return '?';
624 }
625 }
626 else if (pfound->has_arg == 1)
627 {
628 if (d->optind < argc)
629 d->optarg = argv[d->optind++];
630 else
631 {
632 if (print_errors)
633 {
634#if defined _LIBC && defined USE_IN_LIBIO
635 char *buf;
636
637 if (__asprintf (&buf, _("\
638%s: option '--%s' requires an argument\n"),
639 argv[0], pfound->name) >= 0)
640 {
641 _IO_flockfile (stderr);
642
643 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
644 ((_IO_FILE *) stderr)->_flags2
645 |= _IO_FLAGS2_NOTCANCEL;
646
647 __fxprintf (NULL, "%s", buf);
648
649 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
650 _IO_funlockfile (stderr);
651
652 free (buf);
653 }
654#else
655 fprintf (stderr,
656 _("%s: option '--%s' requires an argument\n"),
657 argv[0], pfound->name);
658#endif
659 }
660 d->__nextchar += strlen (d->__nextchar);
661 d->optopt = pfound->val;
662 return optstring[0] == ':' ? ':' : '?';
663 }
664 }
665 d->__nextchar += strlen (d->__nextchar);
666 if (longind != NULL)
667 *longind = option_index;
668 if (pfound->flag)
669 {
670 *(pfound->flag) = pfound->val;
671 return 0;
672 }
673 return pfound->val;
674 }
675
676 /* Can't find it as a long option. If this is not getopt_long_only,
677 or the option starts with '--' or is not a valid short
678 option, then it's an error.
679 Otherwise interpret it as a short option. */
680 if (!long_only || argv[d->optind][1] == '-'
681 || strchr (optstring, *d->__nextchar) == NULL)
682 {
683 if (print_errors)
684 {
685#if defined _LIBC && defined USE_IN_LIBIO
686 char *buf;
687 int n;
688#endif
689
690 if (argv[d->optind][1] == '-')
691 {
692 /* --option */
693#if defined _LIBC && defined USE_IN_LIBIO
694 n = __asprintf (&buf, _("%s: unrecognized option '--%s'\n"),
695 argv[0], d->__nextchar);
696#else
697 fprintf (stderr, _("%s: unrecognized option '--%s'\n"),
698 argv[0], d->__nextchar);
699#endif
700 }
701 else
702 {
703 /* +option or -option */
704#if defined _LIBC && defined USE_IN_LIBIO
705 n = __asprintf (&buf, _("%s: unrecognized option '%c%s'\n"),
706 argv[0], argv[d->optind][0], d->__nextchar);
707#else
708 fprintf (stderr, _("%s: unrecognized option '%c%s'\n"),
709 argv[0], argv[d->optind][0], d->__nextchar);
710#endif
711 }
712
713#if defined _LIBC && defined USE_IN_LIBIO
714 if (n >= 0)
715 {
716 _IO_flockfile (stderr);
717
718 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
719 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
720
721 __fxprintf (NULL, "%s", buf);
722
723 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
724 _IO_funlockfile (stderr);
725
726 free (buf);
727 }
728#endif
729 }
730 d->__nextchar = (char *) "";
731 d->optind++;
732 d->optopt = 0;
733 return '?';
734 }
735 }
736
737 /* Look at and handle the next short option-character. */
738
739 {
740 char c = *d->__nextchar++;
741 const char *temp = strchr (optstring, c);
742
743 /* Increment `optind' when we start to process its last character. */
744 if (*d->__nextchar == '\0')
745 ++d->optind;
746
747 if (temp == NULL || c == ':' || c == ';')
748 {
749 if (print_errors)
750 {
751#if defined _LIBC && defined USE_IN_LIBIO
752 char *buf;
753 int n;
754#endif
755
756#if defined _LIBC && defined USE_IN_LIBIO
757 n = __asprintf (&buf, _("%s: invalid option -- '%c'\n"),
758 argv[0], c);
759#else
760 fprintf (stderr, _("%s: invalid option -- '%c'\n"), argv[0], c);
761#endif
762
763#if defined _LIBC && defined USE_IN_LIBIO
764 if (n >= 0)
765 {
766 _IO_flockfile (stderr);
767
768 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
769 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
770
771 __fxprintf (NULL, "%s", buf);
772
773 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
774 _IO_funlockfile (stderr);
775
776 free (buf);
777 }
778#endif
779 }
780 d->optopt = c;
781 return '?';
782 }
783 /* Convenience. Treat POSIX -W foo same as long option --foo */
784 if (temp[0] == 'W' && temp[1] == ';')
785 {
786 char *nameend;
787 const struct option *p;
788 const struct option *pfound = NULL;
789 int exact = 0;
790 int ambig = 0;
791 int indfound = 0;
792 int option_index;
793
794 /* This is an option that requires an argument. */
795 if (*d->__nextchar != '\0')
796 {
797 d->optarg = d->__nextchar;
798 /* If we end this ARGV-element by taking the rest as an arg,
799 we must advance to the next element now. */
800 d->optind++;
801 }
802 else if (d->optind == argc)
803 {
804 if (print_errors)
805 {
806#if defined _LIBC && defined USE_IN_LIBIO
807 char *buf;
808
809 if (__asprintf (&buf,
810 _("%s: option requires an argument -- '%c'\n"),
811 argv[0], c) >= 0)
812 {
813 _IO_flockfile (stderr);
814
815 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
816 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
817
818 __fxprintf (NULL, "%s", buf);
819
820 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
821 _IO_funlockfile (stderr);
822
823 free (buf);
824 }
825#else
826 fprintf (stderr,
827 _("%s: option requires an argument -- '%c'\n"),
828 argv[0], c);
829#endif
830 }
831 d->optopt = c;
832 if (optstring[0] == ':')
833 c = ':';
834 else
835 c = '?';
836 return c;
837 }
838 else
839 /* We already incremented `d->optind' once;
840 increment it again when taking next ARGV-elt as argument. */
841 d->optarg = argv[d->optind++];
842
843 /* optarg is now the argument, see if it's in the
844 table of longopts. */
845
846 for (d->__nextchar = nameend = d->optarg; *nameend && *nameend != '=';
847 nameend++)
848 /* Do nothing. */ ;
849
850 /* Test all long options for either exact match
851 or abbreviated matches. */
852 for (p = longopts, option_index = 0; p->name; p++, option_index++)
853 if (!strncmp (p->name, d->__nextchar, nameend - d->__nextchar))
854 {
855 if ((unsigned int) (nameend - d->__nextchar) == strlen (p->name))
856 {
857 /* Exact match found. */
858 pfound = p;
859 indfound = option_index;
860 exact = 1;
861 break;
862 }
863 else if (pfound == NULL)
864 {
865 /* First nonexact match found. */
866 pfound = p;
867 indfound = option_index;
868 }
869 else if (long_only
870 || pfound->has_arg != p->has_arg
871 || pfound->flag != p->flag
872 || pfound->val != p->val)
873 /* Second or later nonexact match found. */
874 ambig = 1;
875 }
876 if (ambig && !exact)
877 {
878 if (print_errors)
879 {
880#if defined _LIBC && defined USE_IN_LIBIO
881 char *buf;
882
883 if (__asprintf (&buf, _("%s: option '-W %s' is ambiguous\n"),
884 argv[0], d->optarg) >= 0)
885 {
886 _IO_flockfile (stderr);
887
888 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
889 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
890
891 __fxprintf (NULL, "%s", buf);
892
893 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
894 _IO_funlockfile (stderr);
895
896 free (buf);
897 }
898#else
899 fprintf (stderr, _("%s: option '-W %s' is ambiguous\n"),
900 argv[0], d->optarg);
901#endif
902 }
903 d->__nextchar += strlen (d->__nextchar);
904 d->optind++;
905 return '?';
906 }
907 if (pfound != NULL)
908 {
909 option_index = indfound;
910 if (*nameend)
911 {
912 /* Don't test has_arg with >, because some C compilers don't
913 allow it to be used on enums. */
914 if (pfound->has_arg)
915 d->optarg = nameend + 1;
916 else
917 {
918 if (print_errors)
919 {
920#if defined _LIBC && defined USE_IN_LIBIO
921 char *buf;
922
923 if (__asprintf (&buf, _("\
924%s: option '-W %s' doesn't allow an argument\n"),
925 argv[0], pfound->name) >= 0)
926 {
927 _IO_flockfile (stderr);
928
929 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
930 ((_IO_FILE *) stderr)->_flags2
931 |= _IO_FLAGS2_NOTCANCEL;
932
933 __fxprintf (NULL, "%s", buf);
934
935 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
936 _IO_funlockfile (stderr);
937
938 free (buf);
939 }
940#else
941 fprintf (stderr, _("\
942%s: option '-W %s' doesn't allow an argument\n"),
943 argv[0], pfound->name);
944#endif
945 }
946
947 d->__nextchar += strlen (d->__nextchar);
948 return '?';
949 }
950 }
951 else if (pfound->has_arg == 1)
952 {
953 if (d->optind < argc)
954 d->optarg = argv[d->optind++];
955 else
956 {
957 if (print_errors)
958 {
959#if defined _LIBC && defined USE_IN_LIBIO
960 char *buf;
961
962 if (__asprintf (&buf, _("\
963%s: option '-W %s' requires an argument\n"),
964 argv[0], pfound->name) >= 0)
965 {
966 _IO_flockfile (stderr);
967
968 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
969 ((_IO_FILE *) stderr)->_flags2
970 |= _IO_FLAGS2_NOTCANCEL;
971
972 __fxprintf (NULL, "%s", buf);
973
974 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
975 _IO_funlockfile (stderr);
976
977 free (buf);
978 }
979#else
980 fprintf (stderr, _("\
981%s: option '-W %s' requires an argument\n"),
982 argv[0], pfound->name);
983#endif
984 }
985 d->__nextchar += strlen (d->__nextchar);
986 return optstring[0] == ':' ? ':' : '?';
987 }
988 }
989 else
990 d->optarg = NULL;
991 d->__nextchar += strlen (d->__nextchar);
992 if (longind != NULL)
993 *longind = option_index;
994 if (pfound->flag)
995 {
996 *(pfound->flag) = pfound->val;
997 return 0;
998 }
999 return pfound->val;
1000 }
1001 d->__nextchar = NULL;
1002 return 'W'; /* Let the application handle it. */
1003 }
1004 if (temp[1] == ':')
1005 {
1006 if (temp[2] == ':')
1007 {
1008 /* This is an option that accepts an argument optionally. */
1009 if (*d->__nextchar != '\0')
1010 {
1011 d->optarg = d->__nextchar;
1012 d->optind++;
1013 }
1014 else
1015 d->optarg = NULL;
1016 d->__nextchar = NULL;
1017 }
1018 else
1019 {
1020 /* This is an option that requires an argument. */
1021 if (*d->__nextchar != '\0')
1022 {
1023 d->optarg = d->__nextchar;
1024 /* If we end this ARGV-element by taking the rest as an arg,
1025 we must advance to the next element now. */
1026 d->optind++;
1027 }
1028 else if (d->optind == argc)
1029 {
1030 if (print_errors)
1031 {
1032#if defined _LIBC && defined USE_IN_LIBIO
1033 char *buf;
1034
1035 if (__asprintf (&buf, _("\
1036%s: option requires an argument -- '%c'\n"),
1037 argv[0], c) >= 0)
1038 {
1039 _IO_flockfile (stderr);
1040
1041 int old_flags2 = ((_IO_FILE *) stderr)->_flags2;
1042 ((_IO_FILE *) stderr)->_flags2 |= _IO_FLAGS2_NOTCANCEL;
1043
1044 __fxprintf (NULL, "%s", buf);
1045
1046 ((_IO_FILE *) stderr)->_flags2 = old_flags2;
1047 _IO_funlockfile (stderr);
1048
1049 free (buf);
1050 }
1051#else
1052 fprintf (stderr,
1053 _("%s: option requires an argument -- '%c'\n"),
1054 argv[0], c);
1055#endif
1056 }
1057 d->optopt = c;
1058 if (optstring[0] == ':')
1059 c = ':';
1060 else
1061 c = '?';
1062 }
1063 else
1064 /* We already incremented `optind' once;
1065 increment it again when taking next ARGV-elt as argument. */
1066 d->optarg = argv[d->optind++];
1067 d->__nextchar = NULL;
1068 }
1069 }
1070 return c;
1071 }
1072}
1073
1074int
1075_getopt_internal (int argc, char **argv, const char *optstring,
1076 const struct option *longopts, int *longind, int long_only,
1077 int posixly_correct)
1078{
1079 int result;
1080
1081 getopt_data.optind = optind;
1082 getopt_data.opterr = opterr;
1083
1084 result = _getopt_internal_r (argc, argv, optstring, longopts,
1085 longind, long_only, &getopt_data,
1086 posixly_correct);
1087
1088 optind = getopt_data.optind;
1089 optarg = getopt_data.optarg;
1090 optopt = getopt_data.optopt;
1091
1092 return result;
1093}
1094
1095/* glibc gets a LSB-compliant getopt.
1096 Standalone applications get a POSIX-compliant getopt. */
1097#if _LIBC
1098enum { POSIXLY_CORRECT = 0 };
1099#else
1100enum { POSIXLY_CORRECT = 1 };
1101#endif
1102
1103int
1104getopt (int argc, char *const *argv, const char *optstring)
1105{
1106 return _getopt_internal (argc, (char **) argv, optstring,
1107 (const struct option *) 0,
1108 (int *) 0,
1109 0, POSIXLY_CORRECT);
1110}
1111
1112#ifdef _LIBC
1113int
1114__posix_getopt (int argc, char *const *argv, const char *optstring)
1115{
1116 return _getopt_internal (argc, argv, optstring,
1117 (const struct option *) 0,
1118 (int *) 0,
1119 0, 1);
1120}
1121#endif
1122
1123
1124#ifdef TEST
1125
1126/* Compile with -DTEST to make an executable for use in testing
1127 the above definition of `getopt'. */
1128
1129int
1130main (int argc, char **argv)
1131{
1132 int c;
1133 int digit_optind = 0;
1134
1135 while (1)
1136 {
1137 int this_option_optind = optind ? optind : 1;
1138
1139 c = getopt (argc, argv, "abc:d:0123456789");
1140 if (c == -1)
1141 break;
1142
1143 switch (c)
1144 {
1145 case '0':
1146 case '1':
1147 case '2':
1148 case '3':
1149 case '4':
1150 case '5':
1151 case '6':
1152 case '7':
1153 case '8':
1154 case '9':
1155 if (digit_optind != 0 && digit_optind != this_option_optind)
1156 printf ("digits occur in two different argv-elements.\n");
1157 digit_optind = this_option_optind;
1158 printf ("option %c\n", c);
1159 break;
1160
1161 case 'a':
1162 printf ("option a\n");
1163 break;
1164
1165 case 'b':
1166 printf ("option b\n");
1167 break;
1168
1169 case 'c':
1170 printf ("option c with value '%s'\n", optarg);
1171 break;
1172
1173 case '?':
1174 break;
1175
1176 default:
1177 printf ("?? getopt returned character code 0%o ??\n", c);
1178 }
1179 }
1180
1181 if (optind < argc)
1182 {
1183 printf ("non-option ARGV-elements: ");
1184 while (optind < argc)
1185 printf ("%s ", argv[optind++]);
1186 printf ("\n");
1187 }
1188
1189 exit (0);
1190}
1191
1192#endif /* TEST */
diff --git a/lib/getopt.in.h b/lib/getopt.in.h
new file mode 100644
index 00000000000..9b0a9a58bc9
--- /dev/null
+++ b/lib/getopt.in.h
@@ -0,0 +1,250 @@
1/* Declarations for getopt.
2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2007, 2009-2011 Free Software
3 Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef _GL_GETOPT_H
20
21#if __GNUC__ >= 3
22@PRAGMA_SYSTEM_HEADER@
23#endif
24@PRAGMA_COLUMNS@
25
26/* The include_next requires a split double-inclusion guard. We must
27 also inform the replacement unistd.h to not recursively use
28 <getopt.h>; our definitions will be present soon enough. */
29#if @HAVE_GETOPT_H@
30# define _GL_SYSTEM_GETOPT
31# @INCLUDE_NEXT@ @NEXT_GETOPT_H@
32# undef _GL_SYSTEM_GETOPT
33#endif
34
35#ifndef _GL_GETOPT_H
36
37#ifndef __need_getopt
38# define _GL_GETOPT_H 1
39#endif
40
41/* Standalone applications should #define __GETOPT_PREFIX to an
42 identifier that prefixes the external functions and variables
43 defined in this header. When this happens, include the
44 headers that might declare getopt so that they will not cause
45 confusion if included after this file (if the system had <getopt.h>,
46 we have already included it). Then systematically rename
47 identifiers so that they do not collide with the system functions
48 and variables. Renaming avoids problems with some compilers and
49 linkers. */
50#if defined __GETOPT_PREFIX && !defined __need_getopt
51# if !@HAVE_GETOPT_H@
52# include <stdlib.h>
53# include <stdio.h>
54# include <unistd.h>
55# endif
56# undef __need_getopt
57# undef getopt
58# undef getopt_long
59# undef getopt_long_only
60# undef optarg
61# undef opterr
62# undef optind
63# undef optopt
64# undef option
65# define __GETOPT_CONCAT(x, y) x ## y
66# define __GETOPT_XCONCAT(x, y) __GETOPT_CONCAT (x, y)
67# define __GETOPT_ID(y) __GETOPT_XCONCAT (__GETOPT_PREFIX, y)
68# define getopt __GETOPT_ID (getopt)
69# define getopt_long __GETOPT_ID (getopt_long)
70# define getopt_long_only __GETOPT_ID (getopt_long_only)
71# define optarg __GETOPT_ID (optarg)
72# define opterr __GETOPT_ID (opterr)
73# define optind __GETOPT_ID (optind)
74# define optopt __GETOPT_ID (optopt)
75# define option __GETOPT_ID (option)
76# define _getopt_internal __GETOPT_ID (getopt_internal)
77#endif
78
79/* Standalone applications get correct prototypes for getopt_long and
80 getopt_long_only; they declare "char **argv". libc uses prototypes
81 with "char *const *argv" that are incorrect because getopt_long and
82 getopt_long_only can permute argv; this is required for backward
83 compatibility (e.g., for LSB 2.0.1).
84
85 This used to be `#if defined __GETOPT_PREFIX && !defined __need_getopt',
86 but it caused redefinition warnings if both unistd.h and getopt.h were
87 included, since unistd.h includes getopt.h having previously defined
88 __need_getopt.
89
90 The only place where __getopt_argv_const is used is in definitions
91 of getopt_long and getopt_long_only below, but these are visible
92 only if __need_getopt is not defined, so it is quite safe to rewrite
93 the conditional as follows:
94*/
95#if !defined __need_getopt
96# if defined __GETOPT_PREFIX
97# define __getopt_argv_const /* empty */
98# else
99# define __getopt_argv_const const
100# endif
101#endif
102
103/* If __GNU_LIBRARY__ is not already defined, either we are being used
104 standalone, or this is the first header included in the source file.
105 If we are being used with glibc, we need to include <features.h>, but
106 that does not exist if we are standalone. So: if __GNU_LIBRARY__ is
107 not defined, include <ctype.h>, which will pull in <features.h> for us
108 if it's from glibc. (Why ctype.h? It's guaranteed to exist and it
109 doesn't flood the namespace with stuff the way some other headers do.) */
110#if !defined __GNU_LIBRARY__
111# include <ctype.h>
112#endif
113
114#ifndef __THROW
115# ifndef __GNUC_PREREQ
116# define __GNUC_PREREQ(maj, min) (0)
117# endif
118# if defined __cplusplus && __GNUC_PREREQ (2,8)
119# define __THROW throw ()
120# else
121# define __THROW
122# endif
123#endif
124
125/* The definition of _GL_ARG_NONNULL is copied here. */
126
127#ifdef __cplusplus
128extern "C" {
129#endif
130
131/* For communication from `getopt' to the caller.
132 When `getopt' finds an option that takes an argument,
133 the argument value is returned here.
134 Also, when `ordering' is RETURN_IN_ORDER,
135 each non-option ARGV-element is returned here. */
136
137extern char *optarg;
138
139/* Index in ARGV of the next element to be scanned.
140 This is used for communication to and from the caller
141 and for communication between successive calls to `getopt'.
142
143 On entry to `getopt', zero means this is the first call; initialize.
144
145 When `getopt' returns -1, this is the index of the first of the
146 non-option elements that the caller should itself scan.
147
148 Otherwise, `optind' communicates from one call to the next
149 how much of ARGV has been scanned so far. */
150
151extern int optind;
152
153/* Callers store zero here to inhibit the error message `getopt' prints
154 for unrecognized options. */
155
156extern int opterr;
157
158/* Set to an option character which was unrecognized. */
159
160extern int optopt;
161
162#ifndef __need_getopt
163/* Describe the long-named options requested by the application.
164 The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
165 of `struct option' terminated by an element containing a name which is
166 zero.
167
168 The field `has_arg' is:
169 no_argument (or 0) if the option does not take an argument,
170 required_argument (or 1) if the option requires an argument,
171 optional_argument (or 2) if the option takes an optional argument.
172
173 If the field `flag' is not NULL, it points to a variable that is set
174 to the value given in the field `val' when the option is found, but
175 left unchanged if the option is not found.
176
177 To have a long-named option do something other than set an `int' to
178 a compiled-in constant, such as set a value from `optarg', set the
179 option's `flag' field to zero and its `val' field to a nonzero
180 value (the equivalent single-letter option character, if there is
181 one). For long options that have a zero `flag' field, `getopt'
182 returns the contents of the `val' field. */
183
184struct option
185{
186 const char *name;
187 /* has_arg can't be an enum because some compilers complain about
188 type mismatches in all the code that assumes it is an int. */
189 int has_arg;
190 int *flag;
191 int val;
192};
193
194/* Names for the values of the `has_arg' field of `struct option'. */
195
196# define no_argument 0
197# define required_argument 1
198# define optional_argument 2
199#endif /* need getopt */
200
201
202/* Get definitions and prototypes for functions to process the
203 arguments in ARGV (ARGC of them, minus the program name) for
204 options given in OPTS.
205
206 Return the option character from OPTS just read. Return -1 when
207 there are no more options. For unrecognized options, or options
208 missing arguments, `optopt' is set to the option letter, and '?' is
209 returned.
210
211 The OPTS string is a list of characters which are recognized option
212 letters, optionally followed by colons, specifying that that letter
213 takes an argument, to be placed in `optarg'.
214
215 If a letter in OPTS is followed by two colons, its argument is
216 optional. This behavior is specific to the GNU `getopt'.
217
218 The argument `--' causes premature termination of argument
219 scanning, explicitly telling `getopt' that there are no more
220 options.
221
222 If OPTS begins with `-', then non-option arguments are treated as
223 arguments to the option '\1'. This behavior is specific to the GNU
224 `getopt'. If OPTS begins with `+', or POSIXLY_CORRECT is set in
225 the environment, then do not permute arguments. */
226
227extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
228 __THROW _GL_ARG_NONNULL ((2, 3));
229
230#ifndef __need_getopt
231extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
232 const char *__shortopts,
233 const struct option *__longopts, int *__longind)
234 __THROW _GL_ARG_NONNULL ((2, 3));
235extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
236 const char *__shortopts,
237 const struct option *__longopts, int *__longind)
238 __THROW _GL_ARG_NONNULL ((2, 3));
239
240#endif
241
242#ifdef __cplusplus
243}
244#endif
245
246/* Make sure we later can get all the definitions and declarations. */
247#undef __need_getopt
248
249#endif /* getopt.h */
250#endif /* getopt.h */
diff --git a/lib/getopt1.c b/lib/getopt1.c
new file mode 100644
index 00000000000..36568024cc2
--- /dev/null
+++ b/lib/getopt1.c
@@ -0,0 +1,170 @@
1/* getopt_long and getopt_long_only entry points for GNU getopt.
2 Copyright (C) 1987-1994, 1996-1998, 2004, 2006, 2009-2011 Free Software
3 Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifdef _LIBC
20# include <getopt.h>
21#else
22# include <config.h>
23# include "getopt.h"
24#endif
25#include "getopt_int.h"
26
27#include <stdio.h>
28
29/* This needs to come after some library #include
30 to get __GNU_LIBRARY__ defined. */
31#ifdef __GNU_LIBRARY__
32#include <stdlib.h>
33#endif
34
35#ifndef NULL
36#define NULL 0
37#endif
38
39int
40getopt_long (int argc, char *__getopt_argv_const *argv, const char *options,
41 const struct option *long_options, int *opt_index)
42{
43 return _getopt_internal (argc, (char **) argv, options, long_options,
44 opt_index, 0, 0);
45}
46
47int
48_getopt_long_r (int argc, char **argv, const char *options,
49 const struct option *long_options, int *opt_index,
50 struct _getopt_data *d)
51{
52 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
53 0, d, 0);
54}
55
56/* Like getopt_long, but '-' as well as '--' can indicate a long option.
57 If an option that starts with '-' (not '--') doesn't match a long option,
58 but does match a short option, it is parsed as a short option
59 instead. */
60
61int
62getopt_long_only (int argc, char *__getopt_argv_const *argv,
63 const char *options,
64 const struct option *long_options, int *opt_index)
65{
66 return _getopt_internal (argc, (char **) argv, options, long_options,
67 opt_index, 1, 0);
68}
69
70int
71_getopt_long_only_r (int argc, char **argv, const char *options,
72 const struct option *long_options, int *opt_index,
73 struct _getopt_data *d)
74{
75 return _getopt_internal_r (argc, argv, options, long_options, opt_index,
76 1, d, 0);
77}
78
79
80#ifdef TEST
81
82#include <stdio.h>
83
84int
85main (int argc, char **argv)
86{
87 int c;
88 int digit_optind = 0;
89
90 while (1)
91 {
92 int this_option_optind = optind ? optind : 1;
93 int option_index = 0;
94 static const struct option long_options[] =
95 {
96 {"add", 1, 0, 0},
97 {"append", 0, 0, 0},
98 {"delete", 1, 0, 0},
99 {"verbose", 0, 0, 0},
100 {"create", 0, 0, 0},
101 {"file", 1, 0, 0},
102 {0, 0, 0, 0}
103 };
104
105 c = getopt_long (argc, argv, "abc:d:0123456789",
106 long_options, &option_index);
107 if (c == -1)
108 break;
109
110 switch (c)
111 {
112 case 0:
113 printf ("option %s", long_options[option_index].name);
114 if (optarg)
115 printf (" with arg %s", optarg);
116 printf ("\n");
117 break;
118
119 case '0':
120 case '1':
121 case '2':
122 case '3':
123 case '4':
124 case '5':
125 case '6':
126 case '7':
127 case '8':
128 case '9':
129 if (digit_optind != 0 && digit_optind != this_option_optind)
130 printf ("digits occur in two different argv-elements.\n");
131 digit_optind = this_option_optind;
132 printf ("option %c\n", c);
133 break;
134
135 case 'a':
136 printf ("option a\n");
137 break;
138
139 case 'b':
140 printf ("option b\n");
141 break;
142
143 case 'c':
144 printf ("option c with value `%s'\n", optarg);
145 break;
146
147 case 'd':
148 printf ("option d with value `%s'\n", optarg);
149 break;
150
151 case '?':
152 break;
153
154 default:
155 printf ("?? getopt returned character code 0%o ??\n", c);
156 }
157 }
158
159 if (optind < argc)
160 {
161 printf ("non-option ARGV-elements: ");
162 while (optind < argc)
163 printf ("%s ", argv[optind++]);
164 printf ("\n");
165 }
166
167 exit (0);
168}
169
170#endif /* TEST */
diff --git a/lib/getopt_int.h b/lib/getopt_int.h
new file mode 100644
index 00000000000..7a01a6aa422
--- /dev/null
+++ b/lib/getopt_int.h
@@ -0,0 +1,135 @@
1/* Internal declarations for getopt.
2 Copyright (C) 1989-1994, 1996-1999, 2001, 2003-2004, 2009-2011 Free Software
3 Foundation, Inc.
4 This file is part of the GNU C Library.
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef _GETOPT_INT_H
20#define _GETOPT_INT_H 1
21
22#include <getopt.h>
23
24extern int _getopt_internal (int ___argc, char **___argv,
25 const char *__shortopts,
26 const struct option *__longopts, int *__longind,
27 int __long_only, int __posixly_correct);
28
29
30/* Reentrant versions which can handle parsing multiple argument
31 vectors at the same time. */
32
33/* Describe how to deal with options that follow non-option ARGV-elements.
34
35 If the caller did not specify anything,
36 the default is REQUIRE_ORDER if the environment variable
37 POSIXLY_CORRECT is defined, PERMUTE otherwise.
38
39 REQUIRE_ORDER means don't recognize them as options;
40 stop option processing when the first non-option is seen.
41 This is what Unix does.
42 This mode of operation is selected by either setting the environment
43 variable POSIXLY_CORRECT, or using `+' as the first character
44 of the list of option characters, or by calling getopt.
45
46 PERMUTE is the default. We permute the contents of ARGV as we
47 scan, so that eventually all the non-options are at the end.
48 This allows options to be given in any order, even with programs
49 that were not written to expect this.
50
51 RETURN_IN_ORDER is an option available to programs that were
52 written to expect options and other ARGV-elements in any order
53 and that care about the ordering of the two. We describe each
54 non-option ARGV-element as if it were the argument of an option
55 with character code 1. Using `-' as the first character of the
56 list of option characters selects this mode of operation.
57
58 The special argument `--' forces an end of option-scanning regardless
59 of the value of `ordering'. In the case of RETURN_IN_ORDER, only
60 `--' can cause `getopt' to return -1 with `optind' != ARGC. */
61
62enum __ord
63 {
64 REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
65 };
66
67/* Data type for reentrant functions. */
68struct _getopt_data
69{
70 /* These have exactly the same meaning as the corresponding global
71 variables, except that they are used for the reentrant
72 versions of getopt. */
73 int optind;
74 int opterr;
75 int optopt;
76 char *optarg;
77
78 /* Internal members. */
79
80 /* True if the internal members have been initialized. */
81 int __initialized;
82
83 /* The next char to be scanned in the option-element
84 in which the last option character we returned was found.
85 This allows us to pick up the scan where we left off.
86
87 If this is zero, or a null string, it means resume the scan
88 by advancing to the next ARGV-element. */
89 char *__nextchar;
90
91 /* See __ord above. */
92 enum __ord __ordering;
93
94 /* If the POSIXLY_CORRECT environment variable is set
95 or getopt was called. */
96 int __posixly_correct;
97
98
99 /* Handle permutation of arguments. */
100
101 /* Describe the part of ARGV that contains non-options that have
102 been skipped. `first_nonopt' is the index in ARGV of the first
103 of them; `last_nonopt' is the index after the last of them. */
104
105 int __first_nonopt;
106 int __last_nonopt;
107
108#if defined _LIBC && defined USE_NONOPTION_FLAGS
109 int __nonoption_flags_max_len;
110 int __nonoption_flags_len;
111# endif
112};
113
114/* The initializer is necessary to set OPTIND and OPTERR to their
115 default values and to clear the initialization flag. */
116#define _GETOPT_DATA_INITIALIZER { 1, 1 }
117
118extern int _getopt_internal_r (int ___argc, char **___argv,
119 const char *__shortopts,
120 const struct option *__longopts, int *__longind,
121 int __long_only, struct _getopt_data *__data,
122 int __posixly_correct);
123
124extern int _getopt_long_r (int ___argc, char **___argv,
125 const char *__shortopts,
126 const struct option *__longopts, int *__longind,
127 struct _getopt_data *__data);
128
129extern int _getopt_long_only_r (int ___argc, char **___argv,
130 const char *__shortopts,
131 const struct option *__longopts,
132 int *__longind,
133 struct _getopt_data *__data);
134
135#endif /* getopt_int.h */
diff --git a/lib/gettext.h b/lib/gettext.h
new file mode 100644
index 00000000000..eb74aecb9a8
--- /dev/null
+++ b/lib/gettext.h
@@ -0,0 +1,280 @@
1/* Convenience header for conditional use of GNU <libintl.h>.
2 Copyright (C) 1995-1998, 2000-2002, 2004-2006, 2009-2011 Free Software
3 Foundation, Inc.
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3, or (at your option)
8 any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License along
16 with this program; if not, write to the Free Software Foundation,
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
18
19#ifndef _LIBGETTEXT_H
20#define _LIBGETTEXT_H 1
21
22/* NLS can be disabled through the configure --disable-nls option. */
23#if ENABLE_NLS
24
25/* Get declarations of GNU message catalog functions. */
26# include <libintl.h>
27
28/* You can set the DEFAULT_TEXT_DOMAIN macro to specify the domain used by
29 the gettext() and ngettext() macros. This is an alternative to calling
30 textdomain(), and is useful for libraries. */
31# ifdef DEFAULT_TEXT_DOMAIN
32# undef gettext
33# define gettext(Msgid) \
34 dgettext (DEFAULT_TEXT_DOMAIN, Msgid)
35# undef ngettext
36# define ngettext(Msgid1, Msgid2, N) \
37 dngettext (DEFAULT_TEXT_DOMAIN, Msgid1, Msgid2, N)
38# endif
39
40#else
41
42/* Solaris /usr/include/locale.h includes /usr/include/libintl.h, which
43 chokes if dcgettext is defined as a macro. So include it now, to make
44 later inclusions of <locale.h> a NOP. We don't include <libintl.h>
45 as well because people using "gettext.h" will not include <libintl.h>,
46 and also including <libintl.h> would fail on SunOS 4, whereas <locale.h>
47 is OK. */
48#if defined(__sun)
49# include <locale.h>
50#endif
51
52/* Many header files from the libstdc++ coming with g++ 3.3 or newer include
53 <libintl.h>, which chokes if dcgettext is defined as a macro. So include
54 it now, to make later inclusions of <libintl.h> a NOP. */
55#if defined(__cplusplus) && defined(__GNUG__) && (__GNUC__ >= 3)
56# include <cstdlib>
57# if (__GLIBC__ >= 2 && !defined __UCLIBC__) || _GLIBCXX_HAVE_LIBINTL_H
58# include <libintl.h>
59# endif
60#endif
61
62/* Disabled NLS.
63 The casts to 'const char *' serve the purpose of producing warnings
64 for invalid uses of the value returned from these functions.
65 On pre-ANSI systems without 'const', the config.h file is supposed to
66 contain "#define const". */
67# undef gettext
68# define gettext(Msgid) ((const char *) (Msgid))
69# undef dgettext
70# define dgettext(Domainname, Msgid) ((void) (Domainname), gettext (Msgid))
71# undef dcgettext
72# define dcgettext(Domainname, Msgid, Category) \
73 ((void) (Category), dgettext (Domainname, Msgid))
74# undef ngettext
75# define ngettext(Msgid1, Msgid2, N) \
76 ((N) == 1 \
77 ? ((void) (Msgid2), (const char *) (Msgid1)) \
78 : ((void) (Msgid1), (const char *) (Msgid2)))
79# undef dngettext
80# define dngettext(Domainname, Msgid1, Msgid2, N) \
81 ((void) (Domainname), ngettext (Msgid1, Msgid2, N))
82# undef dcngettext
83# define dcngettext(Domainname, Msgid1, Msgid2, N, Category) \
84 ((void) (Category), dngettext (Domainname, Msgid1, Msgid2, N))
85# undef textdomain
86# define textdomain(Domainname) ((const char *) (Domainname))
87# undef bindtextdomain
88# define bindtextdomain(Domainname, Dirname) \
89 ((void) (Domainname), (const char *) (Dirname))
90# undef bind_textdomain_codeset
91# define bind_textdomain_codeset(Domainname, Codeset) \
92 ((void) (Domainname), (const char *) (Codeset))
93
94#endif
95
96/* A pseudo function call that serves as a marker for the automated
97 extraction of messages, but does not call gettext(). The run-time
98 translation is done at a different place in the code.
99 The argument, String, should be a literal string. Concatenated strings
100 and other string expressions won't work.
101 The macro's expansion is not parenthesized, so that it is suitable as
102 initializer for static 'char[]' or 'const char[]' variables. */
103#define gettext_noop(String) String
104
105/* The separator between msgctxt and msgid in a .mo file. */
106#define GETTEXT_CONTEXT_GLUE "\004"
107
108/* Pseudo function calls, taking a MSGCTXT and a MSGID instead of just a
109 MSGID. MSGCTXT and MSGID must be string literals. MSGCTXT should be
110 short and rarely need to change.
111 The letter 'p' stands for 'particular' or 'special'. */
112#ifdef DEFAULT_TEXT_DOMAIN
113# define pgettext(Msgctxt, Msgid) \
114 pgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
115#else
116# define pgettext(Msgctxt, Msgid) \
117 pgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
118#endif
119#define dpgettext(Domainname, Msgctxt, Msgid) \
120 pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, LC_MESSAGES)
121#define dcpgettext(Domainname, Msgctxt, Msgid, Category) \
122 pgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, Category)
123#ifdef DEFAULT_TEXT_DOMAIN
124# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
125 npgettext_aux (DEFAULT_TEXT_DOMAIN, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
126#else
127# define npgettext(Msgctxt, Msgid, MsgidPlural, N) \
128 npgettext_aux (NULL, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
129#endif
130#define dnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
131 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, LC_MESSAGES)
132#define dcnpgettext(Domainname, Msgctxt, Msgid, MsgidPlural, N, Category) \
133 npgettext_aux (Domainname, Msgctxt GETTEXT_CONTEXT_GLUE Msgid, Msgid, MsgidPlural, N, Category)
134
135#ifdef __GNUC__
136__inline
137#else
138#ifdef __cplusplus
139inline
140#endif
141#endif
142static const char *
143pgettext_aux (const char *domain,
144 const char *msg_ctxt_id, const char *msgid,
145 int category)
146{
147 const char *translation = dcgettext (domain, msg_ctxt_id, category);
148 if (translation == msg_ctxt_id)
149 return msgid;
150 else
151 return translation;
152}
153
154#ifdef __GNUC__
155__inline
156#else
157#ifdef __cplusplus
158inline
159#endif
160#endif
161static const char *
162npgettext_aux (const char *domain,
163 const char *msg_ctxt_id, const char *msgid,
164 const char *msgid_plural, unsigned long int n,
165 int category)
166{
167 const char *translation =
168 dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
169 if (translation == msg_ctxt_id || translation == msgid_plural)
170 return (n == 1 ? msgid : msgid_plural);
171 else
172 return translation;
173}
174
175/* The same thing extended for non-constant arguments. Here MSGCTXT and MSGID
176 can be arbitrary expressions. But for string literals these macros are
177 less efficient than those above. */
178
179#include <string.h>
180
181#define _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS \
182 (((__GNUC__ >= 3 || __GNUG__ >= 2) && !__STRICT_ANSI__) \
183 /* || __STDC_VERSION__ >= 199901L */ )
184
185#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
186#include <stdlib.h>
187#endif
188
189#define pgettext_expr(Msgctxt, Msgid) \
190 dcpgettext_expr (NULL, Msgctxt, Msgid, LC_MESSAGES)
191#define dpgettext_expr(Domainname, Msgctxt, Msgid) \
192 dcpgettext_expr (Domainname, Msgctxt, Msgid, LC_MESSAGES)
193
194#ifdef __GNUC__
195__inline
196#else
197#ifdef __cplusplus
198inline
199#endif
200#endif
201static const char *
202dcpgettext_expr (const char *domain,
203 const char *msgctxt, const char *msgid,
204 int category)
205{
206 size_t msgctxt_len = strlen (msgctxt) + 1;
207 size_t msgid_len = strlen (msgid) + 1;
208 const char *translation;
209#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
210 char msg_ctxt_id[msgctxt_len + msgid_len];
211#else
212 char buf[1024];
213 char *msg_ctxt_id =
214 (msgctxt_len + msgid_len <= sizeof (buf)
215 ? buf
216 : (char *) malloc (msgctxt_len + msgid_len));
217 if (msg_ctxt_id != NULL)
218#endif
219 {
220 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
221 msg_ctxt_id[msgctxt_len - 1] = '\004';
222 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
223 translation = dcgettext (domain, msg_ctxt_id, category);
224#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
225 if (msg_ctxt_id != buf)
226 free (msg_ctxt_id);
227#endif
228 if (translation != msg_ctxt_id)
229 return translation;
230 }
231 return msgid;
232}
233
234#define npgettext_expr(Msgctxt, Msgid, MsgidPlural, N) \
235 dcnpgettext_expr (NULL, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
236#define dnpgettext_expr(Domainname, Msgctxt, Msgid, MsgidPlural, N) \
237 dcnpgettext_expr (Domainname, Msgctxt, Msgid, MsgidPlural, N, LC_MESSAGES)
238
239#ifdef __GNUC__
240__inline
241#else
242#ifdef __cplusplus
243inline
244#endif
245#endif
246static const char *
247dcnpgettext_expr (const char *domain,
248 const char *msgctxt, const char *msgid,
249 const char *msgid_plural, unsigned long int n,
250 int category)
251{
252 size_t msgctxt_len = strlen (msgctxt) + 1;
253 size_t msgid_len = strlen (msgid) + 1;
254 const char *translation;
255#if _LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
256 char msg_ctxt_id[msgctxt_len + msgid_len];
257#else
258 char buf[1024];
259 char *msg_ctxt_id =
260 (msgctxt_len + msgid_len <= sizeof (buf)
261 ? buf
262 : (char *) malloc (msgctxt_len + msgid_len));
263 if (msg_ctxt_id != NULL)
264#endif
265 {
266 memcpy (msg_ctxt_id, msgctxt, msgctxt_len - 1);
267 msg_ctxt_id[msgctxt_len - 1] = '\004';
268 memcpy (msg_ctxt_id + msgctxt_len, msgid, msgid_len);
269 translation = dcngettext (domain, msg_ctxt_id, msgid_plural, n, category);
270#if !_LIBGETTEXT_HAVE_VARIABLE_SIZE_ARRAYS
271 if (msg_ctxt_id != buf)
272 free (msg_ctxt_id);
273#endif
274 if (!(translation == msg_ctxt_id || translation == msgid_plural))
275 return translation;
276 }
277 return (n == 1 ? msgid : msgid_plural);
278}
279
280#endif /* _LIBGETTEXT_H */
diff --git a/lib/gnulib.mk b/lib/gnulib.mk
index a091e399be1..f7f1aae5ca2 100644
--- a/lib/gnulib.mk
+++ b/lib/gnulib.mk
@@ -9,7 +9,7 @@
9# the same distribution terms as the rest of that program. 9# the same distribution terms as the rest of that program.
10# 10#
11# Generated by gnulib-tool. 11# Generated by gnulib-tool.
12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr mktime 12# Reproduce by: gnulib-tool --import --dir=. --lib=libgnu --source-base=lib --m4-base=m4 --doc-base=doc --tests-base=tests --aux-dir=. --makefile-name=gnulib.mk --no-libtool --macro-prefix=gl --no-vc-files ftoastr getopt-gnu mktime
13 13
14 14
15MOSTLYCLEANFILES += core *.stackdump 15MOSTLYCLEANFILES += core *.stackdump
@@ -75,6 +75,38 @@ libgnu_a_SOURCES += ftoastr.h ftoastr.c dtoastr.c ldtoastr.c
75 75
76## end gnulib module ftoastr 76## end gnulib module ftoastr
77 77
78## begin gnulib module getopt-posix
79
80BUILT_SOURCES += $(GETOPT_H)
81
82# We need the following in order to create <getopt.h> when the system
83# doesn't have one that works with the given compiler.
84getopt.h: getopt.in.h $(ARG_NONNULL_H)
85 $(AM_V_GEN)rm -f $@-t $@ && \
86 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
87 sed -e 's|@''HAVE_GETOPT_H''@|$(HAVE_GETOPT_H)|g' \
88 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
89 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
90 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
91 -e 's|@''NEXT_GETOPT_H''@|$(NEXT_GETOPT_H)|g' \
92 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
93 < $(srcdir)/getopt.in.h; \
94 } > $@-t && \
95 mv -f $@-t $@
96MOSTLYCLEANFILES += getopt.h getopt.h-t
97
98EXTRA_DIST += getopt.c getopt.in.h getopt1.c getopt_int.h
99
100EXTRA_libgnu_a_SOURCES += getopt.c getopt1.c
101
102## end gnulib module getopt-posix
103
104## begin gnulib module gettext-h
105
106libgnu_a_SOURCES += gettext.h
107
108## end gnulib module gettext-h
109
78## begin gnulib module intprops 110## begin gnulib module intprops
79 111
80 112
@@ -165,6 +197,137 @@ EXTRA_libgnu_a_SOURCES += time_r.c
165 197
166## end gnulib module time_r 198## end gnulib module time_r
167 199
200## begin gnulib module unistd
201
202BUILT_SOURCES += unistd.h
203
204# We need the following in order to create an empty placeholder for
205# <unistd.h> when the system doesn't have one.
206unistd.h: unistd.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
207 $(AM_V_GEN)rm -f $@-t $@ && \
208 { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
209 sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
210 -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
211 -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
212 -e 's|@''PRAGMA_COLUMNS''@|@PRAGMA_COLUMNS@|g' \
213 -e 's|@''NEXT_UNISTD_H''@|$(NEXT_UNISTD_H)|g' \
214 -e 's|@''GNULIB_CHOWN''@|$(GNULIB_CHOWN)|g' \
215 -e 's|@''GNULIB_CLOSE''@|$(GNULIB_CLOSE)|g' \
216 -e 's|@''GNULIB_DUP2''@|$(GNULIB_DUP2)|g' \
217 -e 's|@''GNULIB_DUP3''@|$(GNULIB_DUP3)|g' \
218 -e 's|@''GNULIB_ENVIRON''@|$(GNULIB_ENVIRON)|g' \
219 -e 's|@''GNULIB_EUIDACCESS''@|$(GNULIB_EUIDACCESS)|g' \
220 -e 's|@''GNULIB_FACCESSAT''@|$(GNULIB_FACCESSAT)|g' \
221 -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
222 -e 's|@''GNULIB_FCHOWNAT''@|$(GNULIB_FCHOWNAT)|g' \
223 -e 's|@''GNULIB_FSYNC''@|$(GNULIB_FSYNC)|g' \
224 -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
225 -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
226 -e 's|@''GNULIB_GETDOMAINNAME''@|$(GNULIB_GETDOMAINNAME)|g' \
227 -e 's|@''GNULIB_GETDTABLESIZE''@|$(GNULIB_GETDTABLESIZE)|g' \
228 -e 's|@''GNULIB_GETGROUPS''@|$(GNULIB_GETGROUPS)|g' \
229 -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
230 -e 's|@''GNULIB_GETLOGIN''@|$(GNULIB_GETLOGIN)|g' \
231 -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
232 -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
233 -e 's|@''GNULIB_GETUSERSHELL''@|$(GNULIB_GETUSERSHELL)|g' \
234 -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \
235 -e 's|@''GNULIB_LINK''@|$(GNULIB_LINK)|g' \
236 -e 's|@''GNULIB_LINKAT''@|$(GNULIB_LINKAT)|g' \
237 -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \
238 -e 's|@''GNULIB_PIPE''@|$(GNULIB_PIPE)|g' \
239 -e 's|@''GNULIB_PIPE2''@|$(GNULIB_PIPE2)|g' \
240 -e 's|@''GNULIB_PREAD''@|$(GNULIB_PREAD)|g' \
241 -e 's|@''GNULIB_PWRITE''@|$(GNULIB_PWRITE)|g' \
242 -e 's|@''GNULIB_READLINK''@|$(GNULIB_READLINK)|g' \
243 -e 's|@''GNULIB_READLINKAT''@|$(GNULIB_READLINKAT)|g' \
244 -e 's|@''GNULIB_RMDIR''@|$(GNULIB_RMDIR)|g' \
245 -e 's|@''GNULIB_SLEEP''@|$(GNULIB_SLEEP)|g' \
246 -e 's|@''GNULIB_SYMLINK''@|$(GNULIB_SYMLINK)|g' \
247 -e 's|@''GNULIB_SYMLINKAT''@|$(GNULIB_SYMLINKAT)|g' \
248 -e 's|@''GNULIB_TTYNAME_R''@|$(GNULIB_TTYNAME_R)|g' \
249 -e 's|@''GNULIB_UNISTD_H_GETOPT''@|$(GNULIB_UNISTD_H_GETOPT)|g' \
250 -e 's|@''GNULIB_UNISTD_H_SIGPIPE''@|$(GNULIB_UNISTD_H_SIGPIPE)|g' \
251 -e 's|@''GNULIB_UNLINK''@|$(GNULIB_UNLINK)|g' \
252 -e 's|@''GNULIB_UNLINKAT''@|$(GNULIB_UNLINKAT)|g' \
253 -e 's|@''GNULIB_USLEEP''@|$(GNULIB_USLEEP)|g' \
254 -e 's|@''GNULIB_WRITE''@|$(GNULIB_WRITE)|g' \
255 < $(srcdir)/unistd.in.h | \
256 sed -e 's|@''HAVE_CHOWN''@|$(HAVE_CHOWN)|g' \
257 -e 's|@''HAVE_DUP2''@|$(HAVE_DUP2)|g' \
258 -e 's|@''HAVE_DUP3''@|$(HAVE_DUP3)|g' \
259 -e 's|@''HAVE_EUIDACCESS''@|$(HAVE_EUIDACCESS)|g' \
260 -e 's|@''HAVE_FACCESSAT''@|$(HAVE_FACCESSAT)|g' \
261 -e 's|@''HAVE_FCHDIR''@|$(HAVE_FCHDIR)|g' \
262 -e 's|@''HAVE_FCHOWNAT''@|$(HAVE_FCHOWNAT)|g' \
263 -e 's|@''HAVE_FSYNC''@|$(HAVE_FSYNC)|g' \
264 -e 's|@''HAVE_FTRUNCATE''@|$(HAVE_FTRUNCATE)|g' \
265 -e 's|@''HAVE_GETDTABLESIZE''@|$(HAVE_GETDTABLESIZE)|g' \
266 -e 's|@''HAVE_GETGROUPS''@|$(HAVE_GETGROUPS)|g' \
267 -e 's|@''HAVE_GETHOSTNAME''@|$(HAVE_GETHOSTNAME)|g' \
268 -e 's|@''HAVE_GETLOGIN''@|$(HAVE_GETLOGIN)|g' \
269 -e 's|@''HAVE_GETPAGESIZE''@|$(HAVE_GETPAGESIZE)|g' \
270 -e 's|@''HAVE_LCHOWN''@|$(HAVE_LCHOWN)|g' \
271 -e 's|@''HAVE_LINK''@|$(HAVE_LINK)|g' \
272 -e 's|@''HAVE_LINKAT''@|$(HAVE_LINKAT)|g' \
273 -e 's|@''HAVE_PIPE''@|$(HAVE_PIPE)|g' \
274 -e 's|@''HAVE_PIPE2''@|$(HAVE_PIPE2)|g' \
275 -e 's|@''HAVE_PREAD''@|$(HAVE_PREAD)|g' \
276 -e 's|@''HAVE_PWRITE''@|$(HAVE_PWRITE)|g' \
277 -e 's|@''HAVE_READLINK''@|$(HAVE_READLINK)|g' \
278 -e 's|@''HAVE_READLINKAT''@|$(HAVE_READLINKAT)|g' \
279 -e 's|@''HAVE_SLEEP''@|$(HAVE_SLEEP)|g' \
280 -e 's|@''HAVE_SYMLINK''@|$(HAVE_SYMLINK)|g' \
281 -e 's|@''HAVE_SYMLINKAT''@|$(HAVE_SYMLINKAT)|g' \
282 -e 's|@''HAVE_UNLINKAT''@|$(HAVE_UNLINKAT)|g' \
283 -e 's|@''HAVE_USLEEP''@|$(HAVE_USLEEP)|g' \
284 -e 's|@''HAVE_DECL_ENVIRON''@|$(HAVE_DECL_ENVIRON)|g' \
285 -e 's|@''HAVE_DECL_FCHDIR''@|$(HAVE_DECL_FCHDIR)|g' \
286 -e 's|@''HAVE_DECL_GETDOMAINNAME''@|$(HAVE_DECL_GETDOMAINNAME)|g' \
287 -e 's|@''HAVE_DECL_GETLOGIN_R''@|$(HAVE_DECL_GETLOGIN_R)|g' \
288 -e 's|@''HAVE_DECL_GETPAGESIZE''@|$(HAVE_DECL_GETPAGESIZE)|g' \
289 -e 's|@''HAVE_DECL_GETUSERSHELL''@|$(HAVE_DECL_GETUSERSHELL)|g' \
290 -e 's|@''HAVE_DECL_TTYNAME_R''@|$(HAVE_DECL_TTYNAME_R)|g' \
291 -e 's|@''HAVE_OS_H''@|$(HAVE_OS_H)|g' \
292 -e 's|@''HAVE_SYS_PARAM_H''@|$(HAVE_SYS_PARAM_H)|g' \
293 -e 's|@''REPLACE_CHOWN''@|$(REPLACE_CHOWN)|g' \
294 -e 's|@''REPLACE_CLOSE''@|$(REPLACE_CLOSE)|g' \
295 -e 's|@''REPLACE_DUP''@|$(REPLACE_DUP)|g' \
296 -e 's|@''REPLACE_DUP2''@|$(REPLACE_DUP2)|g' \
297 -e 's|@''REPLACE_FCHOWNAT''@|$(REPLACE_FCHOWNAT)|g' \
298 -e 's|@''REPLACE_GETCWD''@|$(REPLACE_GETCWD)|g' \
299 -e 's|@''REPLACE_GETDOMAINNAME''@|$(REPLACE_GETDOMAINNAME)|g' \
300 -e 's|@''REPLACE_GETLOGIN_R''@|$(REPLACE_GETLOGIN_R)|g' \
301 -e 's|@''REPLACE_GETGROUPS''@|$(REPLACE_GETGROUPS)|g' \
302 -e 's|@''REPLACE_GETPAGESIZE''@|$(REPLACE_GETPAGESIZE)|g' \
303 -e 's|@''REPLACE_LCHOWN''@|$(REPLACE_LCHOWN)|g' \
304 -e 's|@''REPLACE_LINK''@|$(REPLACE_LINK)|g' \
305 -e 's|@''REPLACE_LINKAT''@|$(REPLACE_LINKAT)|g' \
306 -e 's|@''REPLACE_LSEEK''@|$(REPLACE_LSEEK)|g' \
307 -e 's|@''REPLACE_PREAD''@|$(REPLACE_PREAD)|g' \
308 -e 's|@''REPLACE_PWRITE''@|$(REPLACE_PWRITE)|g' \
309 -e 's|@''REPLACE_READLINK''@|$(REPLACE_READLINK)|g' \
310 -e 's|@''REPLACE_RMDIR''@|$(REPLACE_RMDIR)|g' \
311 -e 's|@''REPLACE_SLEEP''@|$(REPLACE_SLEEP)|g' \
312 -e 's|@''REPLACE_SYMLINK''@|$(REPLACE_SYMLINK)|g' \
313 -e 's|@''REPLACE_TTYNAME_R''@|$(REPLACE_TTYNAME_R)|g' \
314 -e 's|@''REPLACE_UNLINK''@|$(REPLACE_UNLINK)|g' \
315 -e 's|@''REPLACE_UNLINKAT''@|$(REPLACE_UNLINKAT)|g' \
316 -e 's|@''REPLACE_USLEEP''@|$(REPLACE_USLEEP)|g' \
317 -e 's|@''REPLACE_WRITE''@|$(REPLACE_WRITE)|g' \
318 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H''@|$(UNISTD_H_HAVE_WINSOCK2_H)|g' \
319 -e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
320 -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \
321 -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
322 -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)'; \
323 } > $@-t && \
324 mv $@-t $@
325MOSTLYCLEANFILES += unistd.h unistd.h-t
326
327EXTRA_DIST += unistd.in.h
328
329## end gnulib module unistd
330
168## begin gnulib module warn-on-use 331## begin gnulib module warn-on-use
169 332
170BUILT_SOURCES += warn-on-use.h 333BUILT_SOURCES += warn-on-use.h
diff --git a/lib/unistd.in.h b/lib/unistd.in.h
new file mode 100644
index 00000000000..14d685e0c8f
--- /dev/null
+++ b/lib/unistd.in.h
@@ -0,0 +1,1378 @@
1/* Substitute for and wrapper around <unistd.h>.
2 Copyright (C) 2003-2011 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software Foundation,
16 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
17
18#if __GNUC__ >= 3
19@PRAGMA_SYSTEM_HEADER@
20#endif
21@PRAGMA_COLUMNS@
22
23/* Special invocation convention:
24 - On mingw, several headers, including <winsock2.h>, include <unistd.h>,
25 but we need to ensure that both the system <unistd.h> and <winsock2.h>
26 are completely included before we replace gethostname. */
27#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
28 && !defined _GL_WINSOCK2_H_WITNESS && defined _WINSOCK2_H
29/* <unistd.h> is being indirectly included for the first time from
30 <winsock2.h>; avoid declaring any overrides. */
31# if @HAVE_UNISTD_H@
32# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
33# else
34# error unexpected; report this to bug-gnulib@gnu.org
35# endif
36# define _GL_WINSOCK2_H_WITNESS
37
38/* Normal invocation. */
39#elif !defined _GL_UNISTD_H
40
41/* The include_next requires a split double-inclusion guard. */
42#if @HAVE_UNISTD_H@
43# @INCLUDE_NEXT@ @NEXT_UNISTD_H@
44#endif
45
46/* Get all possible declarations of gethostname(). */
47#if @GNULIB_GETHOSTNAME@ && @UNISTD_H_HAVE_WINSOCK2_H@ \
48 && !defined _GL_INCLUDING_WINSOCK2_H
49# define _GL_INCLUDING_WINSOCK2_H
50# include <winsock2.h>
51# undef _GL_INCLUDING_WINSOCK2_H
52#endif
53
54#if !defined _GL_UNISTD_H && !defined _GL_INCLUDING_WINSOCK2_H
55#define _GL_UNISTD_H
56
57/* NetBSD 5.0 mis-defines NULL. Also get size_t. */
58#include <stddef.h>
59
60/* mingw doesn't define the SEEK_* or *_FILENO macros in <unistd.h>. */
61/* Cygwin 1.7.1 declares symlinkat in <stdio.h>, not in <unistd.h>. */
62/* But avoid namespace pollution on glibc systems. */
63#if (!(defined SEEK_CUR && defined SEEK_END && defined SEEK_SET) \
64 || ((@GNULIB_SYMLINKAT@ || defined GNULIB_POSIXCHECK) \
65 && defined __CYGWIN__)) \
66 && ! defined __GLIBC__
67# include <stdio.h>
68#endif
69
70/* Cygwin 1.7.1 declares unlinkat in <fcntl.h>, not in <unistd.h>. */
71/* But avoid namespace pollution on glibc systems. */
72#if (@GNULIB_UNLINKAT@ || defined GNULIB_POSIXCHECK) && defined __CYGWIN__ \
73 && ! defined __GLIBC__
74# include <fcntl.h>
75#endif
76
77/* mingw fails to declare _exit in <unistd.h>. */
78/* mingw, BeOS, Haiku declare environ in <stdlib.h>, not in <unistd.h>. */
79/* Solaris declares getcwd not only in <unistd.h> but also in <stdlib.h>. */
80/* But avoid namespace pollution on glibc systems. */
81#ifndef __GLIBC__
82# include <stdlib.h>
83#endif
84
85/* mingw declares getcwd in <io.h>, not in <unistd.h>. */
86#if ((@GNULIB_GETCWD@ || defined GNULIB_POSIXCHECK) \
87 && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__))
88# include <io.h>
89#endif
90
91/* AIX and OSF/1 5.1 declare getdomainname in <netdb.h>, not in <unistd.h>.
92 NonStop Kernel declares gethostname in <netdb.h>, not in <unistd.h>. */
93/* But avoid namespace pollution on glibc systems. */
94#if ((@GNULIB_GETDOMAINNAME@ && (defined _AIX || defined __osf__)) \
95 || (@GNULIB_GETHOSTNAME@ && defined __TANDEM)) \
96 && !defined __GLIBC__
97# include <netdb.h>
98#endif
99
100#if (@GNULIB_WRITE@ || @GNULIB_READLINK@ || @GNULIB_READLINKAT@ \
101 || @GNULIB_PREAD@ || @GNULIB_PWRITE@ || defined GNULIB_POSIXCHECK)
102/* Get ssize_t. */
103# include <sys/types.h>
104#endif
105
106/* Get getopt(), optarg, optind, opterr, optopt.
107 But avoid namespace pollution on glibc systems. */
108#if @GNULIB_UNISTD_H_GETOPT@ && !defined __GLIBC__ && !defined _GL_SYSTEM_GETOPT
109# include <getopt.h>
110#endif
111
112/* The definitions of _GL_FUNCDECL_RPL etc. are copied here. */
113
114/* The definition of _GL_ARG_NONNULL is copied here. */
115
116/* The definition of _GL_WARN_ON_USE is copied here. */
117
118
119#if @GNULIB_GETHOSTNAME@
120/* Get all possible declarations of gethostname(). */
121# if @UNISTD_H_HAVE_WINSOCK2_H@
122# if !defined _GL_SYS_SOCKET_H
123# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
124# undef socket
125# define socket socket_used_without_including_sys_socket_h
126# undef connect
127# define connect connect_used_without_including_sys_socket_h
128# undef accept
129# define accept accept_used_without_including_sys_socket_h
130# undef bind
131# define bind bind_used_without_including_sys_socket_h
132# undef getpeername
133# define getpeername getpeername_used_without_including_sys_socket_h
134# undef getsockname
135# define getsockname getsockname_used_without_including_sys_socket_h
136# undef getsockopt
137# define getsockopt getsockopt_used_without_including_sys_socket_h
138# undef listen
139# define listen listen_used_without_including_sys_socket_h
140# undef recv
141# define recv recv_used_without_including_sys_socket_h
142# undef send
143# define send send_used_without_including_sys_socket_h
144# undef recvfrom
145# define recvfrom recvfrom_used_without_including_sys_socket_h
146# undef sendto
147# define sendto sendto_used_without_including_sys_socket_h
148# undef setsockopt
149# define setsockopt setsockopt_used_without_including_sys_socket_h
150# undef shutdown
151# define shutdown shutdown_used_without_including_sys_socket_h
152# else
153 _GL_WARN_ON_USE (socket,
154 "socket() used without including <sys/socket.h>");
155 _GL_WARN_ON_USE (connect,
156 "connect() used without including <sys/socket.h>");
157 _GL_WARN_ON_USE (accept,
158 "accept() used without including <sys/socket.h>");
159 _GL_WARN_ON_USE (bind,
160 "bind() used without including <sys/socket.h>");
161 _GL_WARN_ON_USE (getpeername,
162 "getpeername() used without including <sys/socket.h>");
163 _GL_WARN_ON_USE (getsockname,
164 "getsockname() used without including <sys/socket.h>");
165 _GL_WARN_ON_USE (getsockopt,
166 "getsockopt() used without including <sys/socket.h>");
167 _GL_WARN_ON_USE (listen,
168 "listen() used without including <sys/socket.h>");
169 _GL_WARN_ON_USE (recv,
170 "recv() used without including <sys/socket.h>");
171 _GL_WARN_ON_USE (send,
172 "send() used without including <sys/socket.h>");
173 _GL_WARN_ON_USE (recvfrom,
174 "recvfrom() used without including <sys/socket.h>");
175 _GL_WARN_ON_USE (sendto,
176 "sendto() used without including <sys/socket.h>");
177 _GL_WARN_ON_USE (setsockopt,
178 "setsockopt() used without including <sys/socket.h>");
179 _GL_WARN_ON_USE (shutdown,
180 "shutdown() used without including <sys/socket.h>");
181# endif
182# endif
183# if !defined _GL_SYS_SELECT_H
184# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
185# undef select
186# define select select_used_without_including_sys_select_h
187# else
188 _GL_WARN_ON_USE (select,
189 "select() used without including <sys/select.h>");
190# endif
191# endif
192# endif
193#endif
194
195
196/* OS/2 EMX lacks these macros. */
197#ifndef STDIN_FILENO
198# define STDIN_FILENO 0
199#endif
200#ifndef STDOUT_FILENO
201# define STDOUT_FILENO 1
202#endif
203#ifndef STDERR_FILENO
204# define STDERR_FILENO 2
205#endif
206
207/* Ensure *_OK macros exist. */
208#ifndef F_OK
209# define F_OK 0
210# define X_OK 1
211# define W_OK 2
212# define R_OK 4
213#endif
214
215
216/* Declare overridden functions. */
217
218
219#if defined GNULIB_POSIXCHECK
220/* The access() function is a security risk. */
221_GL_WARN_ON_USE (access, "the access function is a security risk - "
222 "use the gnulib module faccessat instead");
223#endif
224
225
226#if @GNULIB_CHOWN@
227/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
228 to GID (if GID is not -1). Follow symbolic links.
229 Return 0 if successful, otherwise -1 and errno set.
230 See the POSIX:2001 specification
231 <http://www.opengroup.org/susv3xsh/chown.html>. */
232# if @REPLACE_CHOWN@
233# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
234# undef chown
235# define chown rpl_chown
236# endif
237_GL_FUNCDECL_RPL (chown, int, (const char *file, uid_t uid, gid_t gid)
238 _GL_ARG_NONNULL ((1)));
239_GL_CXXALIAS_RPL (chown, int, (const char *file, uid_t uid, gid_t gid));
240# else
241# if !@HAVE_CHOWN@
242_GL_FUNCDECL_SYS (chown, int, (const char *file, uid_t uid, gid_t gid)
243 _GL_ARG_NONNULL ((1)));
244# endif
245_GL_CXXALIAS_SYS (chown, int, (const char *file, uid_t uid, gid_t gid));
246# endif
247_GL_CXXALIASWARN (chown);
248#elif defined GNULIB_POSIXCHECK
249# undef chown
250# if HAVE_RAW_DECL_CHOWN
251_GL_WARN_ON_USE (chown, "chown fails to follow symlinks on some systems and "
252 "doesn't treat a uid or gid of -1 on some systems - "
253 "use gnulib module chown for portability");
254# endif
255#endif
256
257
258#if @GNULIB_CLOSE@
259# if @REPLACE_CLOSE@
260/* Automatically included by modules that need a replacement for close. */
261# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
262# undef close
263# define close rpl_close
264# endif
265_GL_FUNCDECL_RPL (close, int, (int fd));
266_GL_CXXALIAS_RPL (close, int, (int fd));
267# else
268_GL_CXXALIAS_SYS (close, int, (int fd));
269# endif
270_GL_CXXALIASWARN (close);
271#elif @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
272# undef close
273# define close close_used_without_requesting_gnulib_module_close
274#elif defined GNULIB_POSIXCHECK
275# undef close
276/* Assume close is always declared. */
277_GL_WARN_ON_USE (close, "close does not portably work on sockets - "
278 "use gnulib module close for portability");
279#endif
280
281
282#if @REPLACE_DUP@
283# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
284# define dup rpl_dup
285# endif
286_GL_FUNCDECL_RPL (dup, int, (int oldfd));
287_GL_CXXALIAS_RPL (dup, int, (int oldfd));
288#else
289_GL_CXXALIAS_SYS (dup, int, (int oldfd));
290#endif
291_GL_CXXALIASWARN (dup);
292
293
294#if @GNULIB_DUP2@
295/* Copy the file descriptor OLDFD into file descriptor NEWFD. Do nothing if
296 NEWFD = OLDFD, otherwise close NEWFD first if it is open.
297 Return newfd if successful, otherwise -1 and errno set.
298 See the POSIX:2001 specification
299 <http://www.opengroup.org/susv3xsh/dup2.html>. */
300# if @REPLACE_DUP2@
301# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
302# define dup2 rpl_dup2
303# endif
304_GL_FUNCDECL_RPL (dup2, int, (int oldfd, int newfd));
305_GL_CXXALIAS_RPL (dup2, int, (int oldfd, int newfd));
306# else
307# if !@HAVE_DUP2@
308_GL_FUNCDECL_SYS (dup2, int, (int oldfd, int newfd));
309# endif
310_GL_CXXALIAS_SYS (dup2, int, (int oldfd, int newfd));
311# endif
312_GL_CXXALIASWARN (dup2);
313#elif defined GNULIB_POSIXCHECK
314# undef dup2
315# if HAVE_RAW_DECL_DUP2
316_GL_WARN_ON_USE (dup2, "dup2 is unportable - "
317 "use gnulib module dup2 for portability");
318# endif
319#endif
320
321
322#if @GNULIB_DUP3@
323/* Copy the file descriptor OLDFD into file descriptor NEWFD, with the
324 specified flags.
325 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
326 and O_TEXT, O_BINARY (defined in "binary-io.h").
327 Close NEWFD first if it is open.
328 Return newfd if successful, otherwise -1 and errno set.
329 See the Linux man page at
330 <http://www.kernel.org/doc/man-pages/online/pages/man2/dup3.2.html>. */
331# if @HAVE_DUP3@
332# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
333# define dup3 rpl_dup3
334# endif
335_GL_FUNCDECL_RPL (dup3, int, (int oldfd, int newfd, int flags));
336_GL_CXXALIAS_RPL (dup3, int, (int oldfd, int newfd, int flags));
337# else
338_GL_FUNCDECL_SYS (dup3, int, (int oldfd, int newfd, int flags));
339_GL_CXXALIAS_SYS (dup3, int, (int oldfd, int newfd, int flags));
340# endif
341_GL_CXXALIASWARN (dup3);
342#elif defined GNULIB_POSIXCHECK
343# undef dup3
344# if HAVE_RAW_DECL_DUP3
345_GL_WARN_ON_USE (dup3, "dup3 is unportable - "
346 "use gnulib module dup3 for portability");
347# endif
348#endif
349
350
351#if @GNULIB_ENVIRON@
352# if !@HAVE_DECL_ENVIRON@
353/* Set of environment variables and values. An array of strings of the form
354 "VARIABLE=VALUE", terminated with a NULL. */
355# if defined __APPLE__ && defined __MACH__
356# include <crt_externs.h>
357# define environ (*_NSGetEnviron ())
358# else
359# ifdef __cplusplus
360extern "C" {
361# endif
362extern char **environ;
363# ifdef __cplusplus
364}
365# endif
366# endif
367# endif
368#elif defined GNULIB_POSIXCHECK
369# if HAVE_RAW_DECL_ENVIRON
370static inline char ***
371rpl_environ (void)
372{
373 return &environ;
374}
375_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
376 "use gnulib module environ for portability");
377# undef environ
378# define environ (*rpl_environ ())
379# endif
380#endif
381
382
383#if @GNULIB_EUIDACCESS@
384/* Like access(), except that it uses the effective user id and group id of
385 the current process. */
386# if !@HAVE_EUIDACCESS@
387_GL_FUNCDECL_SYS (euidaccess, int, (const char *filename, int mode)
388 _GL_ARG_NONNULL ((1)));
389# endif
390_GL_CXXALIAS_SYS (euidaccess, int, (const char *filename, int mode));
391_GL_CXXALIASWARN (euidaccess);
392# if defined GNULIB_POSIXCHECK
393/* Like access(), this function is a security risk. */
394_GL_WARN_ON_USE (euidaccess, "the euidaccess function is a security risk - "
395 "use the gnulib module faccessat instead");
396# endif
397#elif defined GNULIB_POSIXCHECK
398# undef euidaccess
399# if HAVE_RAW_DECL_EUIDACCESS
400_GL_WARN_ON_USE (euidaccess, "euidaccess is unportable - "
401 "use gnulib module euidaccess for portability");
402# endif
403#endif
404
405
406#if @GNULIB_FACCESSAT@
407# if !@HAVE_FACCESSAT@
408_GL_FUNCDECL_SYS (faccessat, int,
409 (int fd, char const *file, int mode, int flag)
410 _GL_ARG_NONNULL ((2)));
411# endif
412_GL_CXXALIAS_SYS (faccessat, int,
413 (int fd, char const *file, int mode, int flag));
414_GL_CXXALIASWARN (faccessat);
415#elif defined GNULIB_POSIXCHECK
416# undef faccessat
417# if HAVE_RAW_DECL_FACCESSAT
418_GL_WARN_ON_USE (faccessat, "faccessat is not portable - "
419 "use gnulib module faccessat for portability");
420# endif
421#endif
422
423
424#if @GNULIB_FCHDIR@
425/* Change the process' current working directory to the directory on which
426 the given file descriptor is open.
427 Return 0 if successful, otherwise -1 and errno set.
428 See the POSIX:2001 specification
429 <http://www.opengroup.org/susv3xsh/fchdir.html>. */
430# if ! @HAVE_FCHDIR@
431_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
432
433/* Gnulib internal hooks needed to maintain the fchdir metadata. */
434_GL_EXTERN_C int _gl_register_fd (int fd, const char *filename)
435 _GL_ARG_NONNULL ((2));
436_GL_EXTERN_C void _gl_unregister_fd (int fd);
437_GL_EXTERN_C int _gl_register_dup (int oldfd, int newfd);
438_GL_EXTERN_C const char *_gl_directory_name (int fd);
439
440# else
441# if !@HAVE_DECL_FCHDIR@
442_GL_FUNCDECL_SYS (fchdir, int, (int /*fd*/));
443# endif
444# endif
445_GL_CXXALIAS_SYS (fchdir, int, (int /*fd*/));
446_GL_CXXALIASWARN (fchdir);
447#elif defined GNULIB_POSIXCHECK
448# undef fchdir
449# if HAVE_RAW_DECL_FCHDIR
450_GL_WARN_ON_USE (fchdir, "fchdir is unportable - "
451 "use gnulib module fchdir for portability");
452# endif
453#endif
454
455
456#if @GNULIB_FCHOWNAT@
457# if @REPLACE_FCHOWNAT@
458# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
459# undef fchownat
460# define fchownat rpl_fchownat
461# endif
462_GL_FUNCDECL_RPL (fchownat, int, (int fd, char const *file,
463 uid_t owner, gid_t group, int flag)
464 _GL_ARG_NONNULL ((2)));
465_GL_CXXALIAS_RPL (fchownat, int, (int fd, char const *file,
466 uid_t owner, gid_t group, int flag));
467# else
468# if !@HAVE_FCHOWNAT@
469_GL_FUNCDECL_SYS (fchownat, int, (int fd, char const *file,
470 uid_t owner, gid_t group, int flag)
471 _GL_ARG_NONNULL ((2)));
472# endif
473_GL_CXXALIAS_SYS (fchownat, int, (int fd, char const *file,
474 uid_t owner, gid_t group, int flag));
475# endif
476_GL_CXXALIASWARN (fchownat);
477#elif defined GNULIB_POSIXCHECK
478# undef fchownat
479# if HAVE_RAW_DECL_FCHOWNAT
480_GL_WARN_ON_USE (fchownat, "fchownat is not portable - "
481 "use gnulib module openat for portability");
482# endif
483#endif
484
485
486#if @GNULIB_FSYNC@
487/* Synchronize changes to a file.
488 Return 0 if successful, otherwise -1 and errno set.
489 See POSIX:2001 specification
490 <http://www.opengroup.org/susv3xsh/fsync.html>. */
491# if !@HAVE_FSYNC@
492_GL_FUNCDECL_SYS (fsync, int, (int fd));
493# endif
494_GL_CXXALIAS_SYS (fsync, int, (int fd));
495_GL_CXXALIASWARN (fsync);
496#elif defined GNULIB_POSIXCHECK
497# undef fsync
498# if HAVE_RAW_DECL_FSYNC
499_GL_WARN_ON_USE (fsync, "fsync is unportable - "
500 "use gnulib module fsync for portability");
501# endif
502#endif
503
504
505#if @GNULIB_FTRUNCATE@
506/* Change the size of the file to which FD is opened to become equal to LENGTH.
507 Return 0 if successful, otherwise -1 and errno set.
508 See the POSIX:2001 specification
509 <http://www.opengroup.org/susv3xsh/ftruncate.html>. */
510# if !@HAVE_FTRUNCATE@
511_GL_FUNCDECL_SYS (ftruncate, int, (int fd, off_t length));
512# endif
513_GL_CXXALIAS_SYS (ftruncate, int, (int fd, off_t length));
514_GL_CXXALIASWARN (ftruncate);
515#elif defined GNULIB_POSIXCHECK
516# undef ftruncate
517# if HAVE_RAW_DECL_FTRUNCATE
518_GL_WARN_ON_USE (ftruncate, "ftruncate is unportable - "
519 "use gnulib module ftruncate for portability");
520# endif
521#endif
522
523
524#if @GNULIB_GETCWD@
525/* Get the name of the current working directory, and put it in SIZE bytes
526 of BUF.
527 Return BUF if successful, or NULL if the directory couldn't be determined
528 or SIZE was too small.
529 See the POSIX:2001 specification
530 <http://www.opengroup.org/susv3xsh/getcwd.html>.
531 Additionally, the gnulib module 'getcwd' guarantees the following GNU
532 extension: If BUF is NULL, an array is allocated with 'malloc'; the array
533 is SIZE bytes long, unless SIZE == 0, in which case it is as big as
534 necessary. */
535# if @REPLACE_GETCWD@
536# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
537# define getcwd rpl_getcwd
538# endif
539_GL_FUNCDECL_RPL (getcwd, char *, (char *buf, size_t size));
540_GL_CXXALIAS_RPL (getcwd, char *, (char *buf, size_t size));
541# else
542/* Need to cast, because on mingw, the second parameter is
543 int size. */
544_GL_CXXALIAS_SYS_CAST (getcwd, char *, (char *buf, size_t size));
545# endif
546_GL_CXXALIASWARN (getcwd);
547#elif defined GNULIB_POSIXCHECK
548# undef getcwd
549# if HAVE_RAW_DECL_GETCWD
550_GL_WARN_ON_USE (getcwd, "getcwd is unportable - "
551 "use gnulib module getcwd for portability");
552# endif
553#endif
554
555
556#if @GNULIB_GETDOMAINNAME@
557/* Return the NIS domain name of the machine.
558 WARNING! The NIS domain name is unrelated to the fully qualified host name
559 of the machine. It is also unrelated to email addresses.
560 WARNING! The NIS domain name is usually the empty string or "(none)" when
561 not using NIS.
562
563 Put up to LEN bytes of the NIS domain name into NAME.
564 Null terminate it if the name is shorter than LEN.
565 If the NIS domain name is longer than LEN, set errno = EINVAL and return -1.
566 Return 0 if successful, otherwise set errno and return -1. */
567# if @REPLACE_GETDOMAINNAME@
568# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
569# undef getdomainname
570# define getdomainname rpl_getdomainname
571# endif
572_GL_FUNCDECL_RPL (getdomainname, int, (char *name, size_t len)
573 _GL_ARG_NONNULL ((1)));
574_GL_CXXALIAS_RPL (getdomainname, int, (char *name, size_t len));
575# else
576# if !@HAVE_DECL_GETDOMAINNAME@
577_GL_FUNCDECL_SYS (getdomainname, int, (char *name, size_t len)
578 _GL_ARG_NONNULL ((1)));
579# endif
580_GL_CXXALIAS_SYS (getdomainname, int, (char *name, size_t len));
581# endif
582_GL_CXXALIASWARN (getdomainname);
583#elif defined GNULIB_POSIXCHECK
584# undef getdomainname
585# if HAVE_RAW_DECL_GETDOMAINNAME
586_GL_WARN_ON_USE (getdomainname, "getdomainname is unportable - "
587 "use gnulib module getdomainname for portability");
588# endif
589#endif
590
591
592#if @GNULIB_GETDTABLESIZE@
593/* Return the maximum number of file descriptors in the current process.
594 In POSIX, this is same as sysconf (_SC_OPEN_MAX). */
595# if !@HAVE_GETDTABLESIZE@
596_GL_FUNCDECL_SYS (getdtablesize, int, (void));
597# endif
598_GL_CXXALIAS_SYS (getdtablesize, int, (void));
599_GL_CXXALIASWARN (getdtablesize);
600#elif defined GNULIB_POSIXCHECK
601# undef getdtablesize
602# if HAVE_RAW_DECL_GETDTABLESIZE
603_GL_WARN_ON_USE (getdtablesize, "getdtablesize is unportable - "
604 "use gnulib module getdtablesize for portability");
605# endif
606#endif
607
608
609#if @GNULIB_GETGROUPS@
610/* Return the supplemental groups that the current process belongs to.
611 It is unspecified whether the effective group id is in the list.
612 If N is 0, return the group count; otherwise, N describes how many
613 entries are available in GROUPS. Return -1 and set errno if N is
614 not 0 and not large enough. Fails with ENOSYS on some systems. */
615# if @REPLACE_GETGROUPS@
616# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
617# undef getgroups
618# define getgroups rpl_getgroups
619# endif
620_GL_FUNCDECL_RPL (getgroups, int, (int n, gid_t *groups));
621_GL_CXXALIAS_RPL (getgroups, int, (int n, gid_t *groups));
622# else
623# if !@HAVE_GETGROUPS@
624_GL_FUNCDECL_SYS (getgroups, int, (int n, gid_t *groups));
625# endif
626_GL_CXXALIAS_SYS (getgroups, int, (int n, gid_t *groups));
627# endif
628_GL_CXXALIASWARN (getgroups);
629#elif defined GNULIB_POSIXCHECK
630# undef getgroups
631# if HAVE_RAW_DECL_GETGROUPS
632_GL_WARN_ON_USE (getgroups, "getgroups is unportable - "
633 "use gnulib module getgroups for portability");
634# endif
635#endif
636
637
638#if @GNULIB_GETHOSTNAME@
639/* Return the standard host name of the machine.
640 WARNING! The host name may or may not be fully qualified.
641
642 Put up to LEN bytes of the host name into NAME.
643 Null terminate it if the name is shorter than LEN.
644 If the host name is longer than LEN, set errno = EINVAL and return -1.
645 Return 0 if successful, otherwise set errno and return -1. */
646# if @UNISTD_H_HAVE_WINSOCK2_H@
647# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
648# undef gethostname
649# define gethostname rpl_gethostname
650# endif
651_GL_FUNCDECL_RPL (gethostname, int, (char *name, size_t len)
652 _GL_ARG_NONNULL ((1)));
653_GL_CXXALIAS_RPL (gethostname, int, (char *name, size_t len));
654# else
655# if !@HAVE_GETHOSTNAME@
656_GL_FUNCDECL_SYS (gethostname, int, (char *name, size_t len)
657 _GL_ARG_NONNULL ((1)));
658# endif
659/* Need to cast, because on Solaris 10 and OSF/1 5.1 systems, the second
660 parameter is
661 int len. */
662_GL_CXXALIAS_SYS_CAST (gethostname, int, (char *name, size_t len));
663# endif
664_GL_CXXALIASWARN (gethostname);
665#elif @UNISTD_H_HAVE_WINSOCK2_H@
666# undef gethostname
667# define gethostname gethostname_used_without_requesting_gnulib_module_gethostname
668#elif defined GNULIB_POSIXCHECK
669# undef gethostname
670# if HAVE_RAW_DECL_GETHOSTNAME
671_GL_WARN_ON_USE (gethostname, "gethostname is unportable - "
672 "use gnulib module gethostname for portability");
673# endif
674#endif
675
676
677#if @GNULIB_GETLOGIN@
678/* Returns the user's login name, or NULL if it cannot be found. Upon error,
679 returns NULL with errno set.
680
681 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
682
683 Most programs don't need to use this function, because the information is
684 available through environment variables:
685 ${LOGNAME-$USER} on Unix platforms,
686 $USERNAME on native Windows platforms.
687 */
688# if !@HAVE_GETLOGIN@
689_GL_FUNCDECL_SYS (getlogin, char *, (void));
690# endif
691_GL_CXXALIAS_SYS (getlogin, char *, (void));
692_GL_CXXALIASWARN (getlogin);
693#elif defined GNULIB_POSIXCHECK
694# undef getlogin
695# if HAVE_RAW_DECL_GETLOGIN
696_GL_WARN_ON_USE (getlogin, "getlogin is unportable - "
697 "use gnulib module getlogin for portability");
698# endif
699#endif
700
701
702#if @GNULIB_GETLOGIN_R@
703/* Copies the user's login name to NAME.
704 The array pointed to by NAME has room for SIZE bytes.
705
706 Returns 0 if successful. Upon error, an error number is returned, or -1 in
707 the case that the login name cannot be found but no specific error is
708 provided (this case is hopefully rare but is left open by the POSIX spec).
709
710 See <http://www.opengroup.org/susv3xsh/getlogin.html>.
711
712 Most programs don't need to use this function, because the information is
713 available through environment variables:
714 ${LOGNAME-$USER} on Unix platforms,
715 $USERNAME on native Windows platforms.
716 */
717# if @REPLACE_GETLOGIN_R@
718# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
719# define getlogin_r rpl_getlogin_r
720# endif
721_GL_FUNCDECL_RPL (getlogin_r, int, (char *name, size_t size)
722 _GL_ARG_NONNULL ((1)));
723_GL_CXXALIAS_RPL (getlogin_r, int, (char *name, size_t size));
724# else
725# if !@HAVE_DECL_GETLOGIN_R@
726_GL_FUNCDECL_SYS (getlogin_r, int, (char *name, size_t size)
727 _GL_ARG_NONNULL ((1)));
728# endif
729/* Need to cast, because on Solaris 10 systems, the second argument is
730 int size. */
731_GL_CXXALIAS_SYS_CAST (getlogin_r, int, (char *name, size_t size));
732# endif
733_GL_CXXALIASWARN (getlogin_r);
734#elif defined GNULIB_POSIXCHECK
735# undef getlogin_r
736# if HAVE_RAW_DECL_GETLOGIN_R
737_GL_WARN_ON_USE (getlogin_r, "getlogin_r is unportable - "
738 "use gnulib module getlogin_r for portability");
739# endif
740#endif
741
742
743#if @GNULIB_GETPAGESIZE@
744# if @REPLACE_GETPAGESIZE@
745# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
746# define getpagesize rpl_getpagesize
747# endif
748_GL_FUNCDECL_RPL (getpagesize, int, (void));
749_GL_CXXALIAS_RPL (getpagesize, int, (void));
750# else
751# if !@HAVE_GETPAGESIZE@
752# if !defined getpagesize
753/* This is for POSIX systems. */
754# if !defined _gl_getpagesize && defined _SC_PAGESIZE
755# if ! (defined __VMS && __VMS_VER < 70000000)
756# define _gl_getpagesize() sysconf (_SC_PAGESIZE)
757# endif
758# endif
759/* This is for older VMS. */
760# if !defined _gl_getpagesize && defined __VMS
761# ifdef __ALPHA
762# define _gl_getpagesize() 8192
763# else
764# define _gl_getpagesize() 512
765# endif
766# endif
767/* This is for BeOS. */
768# if !defined _gl_getpagesize && @HAVE_OS_H@
769# include <OS.h>
770# if defined B_PAGE_SIZE
771# define _gl_getpagesize() B_PAGE_SIZE
772# endif
773# endif
774/* This is for AmigaOS4.0. */
775# if !defined _gl_getpagesize && defined __amigaos4__
776# define _gl_getpagesize() 2048
777# endif
778/* This is for older Unix systems. */
779# if !defined _gl_getpagesize && @HAVE_SYS_PARAM_H@
780# include <sys/param.h>
781# ifdef EXEC_PAGESIZE
782# define _gl_getpagesize() EXEC_PAGESIZE
783# else
784# ifdef NBPG
785# ifndef CLSIZE
786# define CLSIZE 1
787# endif
788# define _gl_getpagesize() (NBPG * CLSIZE)
789# else
790# ifdef NBPC
791# define _gl_getpagesize() NBPC
792# endif
793# endif
794# endif
795# endif
796# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
797# define getpagesize() _gl_getpagesize ()
798# else
799static inline int
800getpagesize ()
801{
802 return _gl_getpagesize ();
803}
804# endif
805# endif
806# endif
807/* Need to cast, because on Cygwin 1.5.x systems, the return type is size_t. */
808_GL_CXXALIAS_SYS_CAST (getpagesize, int, (void));
809# endif
810# if @HAVE_DECL_GETPAGESIZE@
811_GL_CXXALIASWARN (getpagesize);
812# endif
813#elif defined GNULIB_POSIXCHECK
814# undef getpagesize
815# if HAVE_RAW_DECL_GETPAGESIZE
816_GL_WARN_ON_USE (getpagesize, "getpagesize is unportable - "
817 "use gnulib module getpagesize for portability");
818# endif
819#endif
820
821
822#if @GNULIB_GETUSERSHELL@
823/* Return the next valid login shell on the system, or NULL when the end of
824 the list has been reached. */
825# if !@HAVE_DECL_GETUSERSHELL@
826_GL_FUNCDECL_SYS (getusershell, char *, (void));
827# endif
828_GL_CXXALIAS_SYS (getusershell, char *, (void));
829_GL_CXXALIASWARN (getusershell);
830#elif defined GNULIB_POSIXCHECK
831# undef getusershell
832# if HAVE_RAW_DECL_GETUSERSHELL
833_GL_WARN_ON_USE (getusershell, "getusershell is unportable - "
834 "use gnulib module getusershell for portability");
835# endif
836#endif
837
838#if @GNULIB_GETUSERSHELL@
839/* Rewind to pointer that is advanced at each getusershell() call. */
840# if !@HAVE_DECL_GETUSERSHELL@
841_GL_FUNCDECL_SYS (setusershell, void, (void));
842# endif
843_GL_CXXALIAS_SYS (setusershell, void, (void));
844_GL_CXXALIASWARN (setusershell);
845#elif defined GNULIB_POSIXCHECK
846# undef setusershell
847# if HAVE_RAW_DECL_SETUSERSHELL
848_GL_WARN_ON_USE (setusershell, "setusershell is unportable - "
849 "use gnulib module getusershell for portability");
850# endif
851#endif
852
853#if @GNULIB_GETUSERSHELL@
854/* Free the pointer that is advanced at each getusershell() call and
855 associated resources. */
856# if !@HAVE_DECL_GETUSERSHELL@
857_GL_FUNCDECL_SYS (endusershell, void, (void));
858# endif
859_GL_CXXALIAS_SYS (endusershell, void, (void));
860_GL_CXXALIASWARN (endusershell);
861#elif defined GNULIB_POSIXCHECK
862# undef endusershell
863# if HAVE_RAW_DECL_ENDUSERSHELL
864_GL_WARN_ON_USE (endusershell, "endusershell is unportable - "
865 "use gnulib module getusershell for portability");
866# endif
867#endif
868
869
870#if @GNULIB_LCHOWN@
871/* Change the owner of FILE to UID (if UID is not -1) and the group of FILE
872 to GID (if GID is not -1). Do not follow symbolic links.
873 Return 0 if successful, otherwise -1 and errno set.
874 See the POSIX:2001 specification
875 <http://www.opengroup.org/susv3xsh/lchown.html>. */
876# if @REPLACE_LCHOWN@
877# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
878# undef lchown
879# define lchown rpl_lchown
880# endif
881_GL_FUNCDECL_RPL (lchown, int, (char const *file, uid_t owner, gid_t group)
882 _GL_ARG_NONNULL ((1)));
883_GL_CXXALIAS_RPL (lchown, int, (char const *file, uid_t owner, gid_t group));
884# else
885# if !@HAVE_LCHOWN@
886_GL_FUNCDECL_SYS (lchown, int, (char const *file, uid_t owner, gid_t group)
887 _GL_ARG_NONNULL ((1)));
888# endif
889_GL_CXXALIAS_SYS (lchown, int, (char const *file, uid_t owner, gid_t group));
890# endif
891_GL_CXXALIASWARN (lchown);
892#elif defined GNULIB_POSIXCHECK
893# undef lchown
894# if HAVE_RAW_DECL_LCHOWN
895_GL_WARN_ON_USE (lchown, "lchown is unportable to pre-POSIX.1-2001 systems - "
896 "use gnulib module lchown for portability");
897# endif
898#endif
899
900
901#if @GNULIB_LINK@
902/* Create a new hard link for an existing file.
903 Return 0 if successful, otherwise -1 and errno set.
904 See POSIX:2001 specification
905 <http://www.opengroup.org/susv3xsh/link.html>. */
906# if @REPLACE_LINK@
907# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
908# define link rpl_link
909# endif
910_GL_FUNCDECL_RPL (link, int, (const char *path1, const char *path2)
911 _GL_ARG_NONNULL ((1, 2)));
912_GL_CXXALIAS_RPL (link, int, (const char *path1, const char *path2));
913# else
914# if !@HAVE_LINK@
915_GL_FUNCDECL_SYS (link, int, (const char *path1, const char *path2)
916 _GL_ARG_NONNULL ((1, 2)));
917# endif
918_GL_CXXALIAS_SYS (link, int, (const char *path1, const char *path2));
919# endif
920_GL_CXXALIASWARN (link);
921#elif defined GNULIB_POSIXCHECK
922# undef link
923# if HAVE_RAW_DECL_LINK
924_GL_WARN_ON_USE (link, "link is unportable - "
925 "use gnulib module link for portability");
926# endif
927#endif
928
929
930#if @GNULIB_LINKAT@
931/* Create a new hard link for an existing file, relative to two
932 directories. FLAG controls whether symlinks are followed.
933 Return 0 if successful, otherwise -1 and errno set. */
934# if @REPLACE_LINKAT@
935# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
936# undef linkat
937# define linkat rpl_linkat
938# endif
939_GL_FUNCDECL_RPL (linkat, int,
940 (int fd1, const char *path1, int fd2, const char *path2,
941 int flag)
942 _GL_ARG_NONNULL ((2, 4)));
943_GL_CXXALIAS_RPL (linkat, int,
944 (int fd1, const char *path1, int fd2, const char *path2,
945 int flag));
946# else
947# if !@HAVE_LINKAT@
948_GL_FUNCDECL_SYS (linkat, int,
949 (int fd1, const char *path1, int fd2, const char *path2,
950 int flag)
951 _GL_ARG_NONNULL ((2, 4)));
952# endif
953_GL_CXXALIAS_SYS (linkat, int,
954 (int fd1, const char *path1, int fd2, const char *path2,
955 int flag));
956# endif
957_GL_CXXALIASWARN (linkat);
958#elif defined GNULIB_POSIXCHECK
959# undef linkat
960# if HAVE_RAW_DECL_LINKAT
961_GL_WARN_ON_USE (linkat, "linkat is unportable - "
962 "use gnulib module linkat for portability");
963# endif
964#endif
965
966
967#if @GNULIB_LSEEK@
968/* Set the offset of FD relative to SEEK_SET, SEEK_CUR, or SEEK_END.
969 Return the new offset if successful, otherwise -1 and errno set.
970 See the POSIX:2001 specification
971 <http://www.opengroup.org/susv3xsh/lseek.html>. */
972# if @REPLACE_LSEEK@
973# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
974# define lseek rpl_lseek
975# endif
976_GL_FUNCDECL_RPL (lseek, off_t, (int fd, off_t offset, int whence));
977_GL_CXXALIAS_RPL (lseek, off_t, (int fd, off_t offset, int whence));
978# else
979_GL_CXXALIAS_SYS (lseek, off_t, (int fd, off_t offset, int whence));
980# endif
981_GL_CXXALIASWARN (lseek);
982#elif defined GNULIB_POSIXCHECK
983# undef lseek
984# if HAVE_RAW_DECL_LSEEK
985_GL_WARN_ON_USE (lseek, "lseek does not fail with ESPIPE on pipes on some "
986 "systems - use gnulib module lseek for portability");
987# endif
988#endif
989
990
991#if @GNULIB_PIPE@
992/* Create a pipe, defaulting to O_BINARY mode.
993 Store the read-end as fd[0] and the write-end as fd[1].
994 Return 0 upon success, or -1 with errno set upon failure. */
995# if !@HAVE_PIPE@
996_GL_FUNCDECL_SYS (pipe, int, (int fd[2]) _GL_ARG_NONNULL ((1)));
997# endif
998_GL_CXXALIAS_SYS (pipe, int, (int fd[2]));
999_GL_CXXALIASWARN (pipe);
1000#elif defined GNULIB_POSIXCHECK
1001# undef pipe
1002# if HAVE_RAW_DECL_PIPE
1003_GL_WARN_ON_USE (pipe, "pipe is unportable - "
1004 "use gnulib module pipe-posix for portability");
1005# endif
1006#endif
1007
1008
1009#if @GNULIB_PIPE2@
1010/* Create a pipe, applying the given flags when opening the read-end of the
1011 pipe and the write-end of the pipe.
1012 The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
1013 and O_TEXT, O_BINARY (defined in "binary-io.h").
1014 Store the read-end as fd[0] and the write-end as fd[1].
1015 Return 0 upon success, or -1 with errno set upon failure.
1016 See also the Linux man page at
1017 <http://www.kernel.org/doc/man-pages/online/pages/man2/pipe2.2.html>. */
1018# if @HAVE_PIPE2@
1019# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1020# define pipe2 rpl_pipe2
1021# endif
1022_GL_FUNCDECL_RPL (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1023_GL_CXXALIAS_RPL (pipe2, int, (int fd[2], int flags));
1024# else
1025_GL_FUNCDECL_SYS (pipe2, int, (int fd[2], int flags) _GL_ARG_NONNULL ((1)));
1026_GL_CXXALIAS_SYS (pipe2, int, (int fd[2], int flags));
1027# endif
1028_GL_CXXALIASWARN (pipe2);
1029#elif defined GNULIB_POSIXCHECK
1030# undef pipe2
1031# if HAVE_RAW_DECL_PIPE2
1032_GL_WARN_ON_USE (pipe2, "pipe2 is unportable - "
1033 "use gnulib module pipe2 for portability");
1034# endif
1035#endif
1036
1037
1038#if @GNULIB_PREAD@
1039/* Read at most BUFSIZE bytes from FD into BUF, starting at OFFSET.
1040 Return the number of bytes placed into BUF if successful, otherwise
1041 set errno and return -1. 0 indicates EOF. See the POSIX:2001
1042 specification <http://www.opengroup.org/susv3xsh/pread.html>. */
1043# if @REPLACE_PREAD@
1044# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1045# define pread rpl_pread
1046# endif
1047_GL_FUNCDECL_RPL (pread, ssize_t,
1048 (int fd, void *buf, size_t bufsize, off_t offset)
1049 _GL_ARG_NONNULL ((2)));
1050_GL_CXXALIAS_RPL (pread, ssize_t,
1051 (int fd, void *buf, size_t bufsize, off_t offset));
1052# else
1053# if !@HAVE_PREAD@
1054_GL_FUNCDECL_SYS (pread, ssize_t,
1055 (int fd, void *buf, size_t bufsize, off_t offset)
1056 _GL_ARG_NONNULL ((2)));
1057# endif
1058_GL_CXXALIAS_SYS (pread, ssize_t,
1059 (int fd, void *buf, size_t bufsize, off_t offset));
1060# endif
1061_GL_CXXALIASWARN (pread);
1062#elif defined GNULIB_POSIXCHECK
1063# undef pread
1064# if HAVE_RAW_DECL_PREAD
1065_GL_WARN_ON_USE (pread, "pread is unportable - "
1066 "use gnulib module pread for portability");
1067# endif
1068#endif
1069
1070
1071#if @GNULIB_PWRITE@
1072/* Write at most BUFSIZE bytes from BUF into FD, starting at OFFSET.
1073 Return the number of bytes written if successful, otherwise
1074 set errno and return -1. 0 indicates nothing written. See the
1075 POSIX:2001 specification
1076 <http://www.opengroup.org/susv3xsh/pwrite.html>. */
1077# if @REPLACE_PWRITE@
1078# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1079# define pwrite rpl_pwrite
1080# endif
1081_GL_FUNCDECL_RPL (pwrite, ssize_t,
1082 (int fd, const void *buf, size_t bufsize, off_t offset)
1083 _GL_ARG_NONNULL ((2)));
1084_GL_CXXALIAS_RPL (pwrite, ssize_t,
1085 (int fd, const void *buf, size_t bufsize, off_t offset));
1086# else
1087# if !@HAVE_PWRITE@
1088_GL_FUNCDECL_SYS (pwrite, ssize_t,
1089 (int fd, const void *buf, size_t bufsize, off_t offset)
1090 _GL_ARG_NONNULL ((2)));
1091# endif
1092_GL_CXXALIAS_SYS (pwrite, ssize_t,
1093 (int fd, const void *buf, size_t bufsize, off_t offset));
1094# endif
1095_GL_CXXALIASWARN (pwrite);
1096#elif defined GNULIB_POSIXCHECK
1097# undef pwrite
1098# if HAVE_RAW_DECL_PWRITE
1099_GL_WARN_ON_USE (pwrite, "pwrite is unportable - "
1100 "use gnulib module pwrite for portability");
1101# endif
1102#endif
1103
1104
1105#if @GNULIB_READLINK@
1106/* Read the contents of the symbolic link FILE and place the first BUFSIZE
1107 bytes of it into BUF. Return the number of bytes placed into BUF if
1108 successful, otherwise -1 and errno set.
1109 See the POSIX:2001 specification
1110 <http://www.opengroup.org/susv3xsh/readlink.html>. */
1111# if @REPLACE_READLINK@
1112# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1113# define readlink rpl_readlink
1114# endif
1115_GL_FUNCDECL_RPL (readlink, ssize_t,
1116 (const char *file, char *buf, size_t bufsize)
1117 _GL_ARG_NONNULL ((1, 2)));
1118_GL_CXXALIAS_RPL (readlink, ssize_t,
1119 (const char *file, char *buf, size_t bufsize));
1120# else
1121# if !@HAVE_READLINK@
1122_GL_FUNCDECL_SYS (readlink, ssize_t,
1123 (const char *file, char *buf, size_t bufsize)
1124 _GL_ARG_NONNULL ((1, 2)));
1125# endif
1126_GL_CXXALIAS_SYS (readlink, ssize_t,
1127 (const char *file, char *buf, size_t bufsize));
1128# endif
1129_GL_CXXALIASWARN (readlink);
1130#elif defined GNULIB_POSIXCHECK
1131# undef readlink
1132# if HAVE_RAW_DECL_READLINK
1133_GL_WARN_ON_USE (readlink, "readlink is unportable - "
1134 "use gnulib module readlink for portability");
1135# endif
1136#endif
1137
1138
1139#if @GNULIB_READLINKAT@
1140# if !@HAVE_READLINKAT@
1141_GL_FUNCDECL_SYS (readlinkat, ssize_t,
1142 (int fd, char const *file, char *buf, size_t len)
1143 _GL_ARG_NONNULL ((2, 3)));
1144# endif
1145_GL_CXXALIAS_SYS (readlinkat, ssize_t,
1146 (int fd, char const *file, char *buf, size_t len));
1147_GL_CXXALIASWARN (readlinkat);
1148#elif defined GNULIB_POSIXCHECK
1149# undef readlinkat
1150# if HAVE_RAW_DECL_READLINKAT
1151_GL_WARN_ON_USE (readlinkat, "readlinkat is not portable - "
1152 "use gnulib module readlinkat for portability");
1153# endif
1154#endif
1155
1156
1157#if @GNULIB_RMDIR@
1158/* Remove the directory DIR. */
1159# if @REPLACE_RMDIR@
1160# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1161# define rmdir rpl_rmdir
1162# endif
1163_GL_FUNCDECL_RPL (rmdir, int, (char const *name) _GL_ARG_NONNULL ((1)));
1164_GL_CXXALIAS_RPL (rmdir, int, (char const *name));
1165# else
1166_GL_CXXALIAS_SYS (rmdir, int, (char const *name));
1167# endif
1168_GL_CXXALIASWARN (rmdir);
1169#elif defined GNULIB_POSIXCHECK
1170# undef rmdir
1171# if HAVE_RAW_DECL_RMDIR
1172_GL_WARN_ON_USE (rmdir, "rmdir is unportable - "
1173 "use gnulib module rmdir for portability");
1174# endif
1175#endif
1176
1177
1178#if @GNULIB_SLEEP@
1179/* Pause the execution of the current thread for N seconds.
1180 Returns the number of seconds left to sleep.
1181 See the POSIX:2001 specification
1182 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1183# if @REPLACE_SLEEP@
1184# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1185# undef sleep
1186# define sleep rpl_sleep
1187# endif
1188_GL_FUNCDECL_RPL (sleep, unsigned int, (unsigned int n));
1189_GL_CXXALIAS_RPL (sleep, unsigned int, (unsigned int n));
1190# else
1191# if !@HAVE_SLEEP@
1192_GL_FUNCDECL_SYS (sleep, unsigned int, (unsigned int n));
1193# endif
1194_GL_CXXALIAS_SYS (sleep, unsigned int, (unsigned int n));
1195# endif
1196_GL_CXXALIASWARN (sleep);
1197#elif defined GNULIB_POSIXCHECK
1198# undef sleep
1199# if HAVE_RAW_DECL_SLEEP
1200_GL_WARN_ON_USE (sleep, "sleep is unportable - "
1201 "use gnulib module sleep for portability");
1202# endif
1203#endif
1204
1205
1206#if @GNULIB_SYMLINK@
1207# if @REPLACE_SYMLINK@
1208# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1209# undef symlink
1210# define symlink rpl_symlink
1211# endif
1212_GL_FUNCDECL_RPL (symlink, int, (char const *contents, char const *file)
1213 _GL_ARG_NONNULL ((1, 2)));
1214_GL_CXXALIAS_RPL (symlink, int, (char const *contents, char const *file));
1215# else
1216# if !@HAVE_SYMLINK@
1217_GL_FUNCDECL_SYS (symlink, int, (char const *contents, char const *file)
1218 _GL_ARG_NONNULL ((1, 2)));
1219# endif
1220_GL_CXXALIAS_SYS (symlink, int, (char const *contents, char const *file));
1221# endif
1222_GL_CXXALIASWARN (symlink);
1223#elif defined GNULIB_POSIXCHECK
1224# undef symlink
1225# if HAVE_RAW_DECL_SYMLINK
1226_GL_WARN_ON_USE (symlink, "symlink is not portable - "
1227 "use gnulib module symlink for portability");
1228# endif
1229#endif
1230
1231
1232#if @GNULIB_SYMLINKAT@
1233# if !@HAVE_SYMLINKAT@
1234_GL_FUNCDECL_SYS (symlinkat, int,
1235 (char const *contents, int fd, char const *file)
1236 _GL_ARG_NONNULL ((1, 3)));
1237# endif
1238_GL_CXXALIAS_SYS (symlinkat, int,
1239 (char const *contents, int fd, char const *file));
1240_GL_CXXALIASWARN (symlinkat);
1241#elif defined GNULIB_POSIXCHECK
1242# undef symlinkat
1243# if HAVE_RAW_DECL_SYMLINKAT
1244_GL_WARN_ON_USE (symlinkat, "symlinkat is not portable - "
1245 "use gnulib module symlinkat for portability");
1246# endif
1247#endif
1248
1249
1250#if @GNULIB_TTYNAME_R@
1251/* Store at most BUFLEN characters of the pathname of the terminal FD is
1252 open on in BUF. Return 0 on success, otherwise an error number. */
1253# if @REPLACE_TTYNAME_R@
1254# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1255# undef ttyname_r
1256# define ttyname_r rpl_ttyname_r
1257# endif
1258_GL_FUNCDECL_RPL (ttyname_r, int,
1259 (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1260_GL_CXXALIAS_RPL (ttyname_r, int,
1261 (int fd, char *buf, size_t buflen));
1262# else
1263# if !@HAVE_DECL_TTYNAME_R@
1264_GL_FUNCDECL_SYS (ttyname_r, int,
1265 (int fd, char *buf, size_t buflen) _GL_ARG_NONNULL ((2)));
1266# endif
1267_GL_CXXALIAS_SYS (ttyname_r, int,
1268 (int fd, char *buf, size_t buflen));
1269# endif
1270_GL_CXXALIASWARN (ttyname_r);
1271#elif defined GNULIB_POSIXCHECK
1272# undef ttyname_r
1273# if HAVE_RAW_DECL_TTYNAME_R
1274_GL_WARN_ON_USE (ttyname_r, "ttyname_r is not portable - "
1275 "use gnulib module ttyname_r for portability");
1276# endif
1277#endif
1278
1279
1280#if @GNULIB_UNLINK@
1281# if @REPLACE_UNLINK@
1282# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1283# undef unlink
1284# define unlink rpl_unlink
1285# endif
1286_GL_FUNCDECL_RPL (unlink, int, (char const *file) _GL_ARG_NONNULL ((1)));
1287_GL_CXXALIAS_RPL (unlink, int, (char const *file));
1288# else
1289_GL_CXXALIAS_SYS (unlink, int, (char const *file));
1290# endif
1291_GL_CXXALIASWARN (unlink);
1292#elif defined GNULIB_POSIXCHECK
1293# undef unlink
1294# if HAVE_RAW_DECL_UNLINK
1295_GL_WARN_ON_USE (unlink, "unlink is not portable - "
1296 "use gnulib module unlink for portability");
1297# endif
1298#endif
1299
1300
1301#if @GNULIB_UNLINKAT@
1302# if @REPLACE_UNLINKAT@
1303# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1304# undef unlinkat
1305# define unlinkat rpl_unlinkat
1306# endif
1307_GL_FUNCDECL_RPL (unlinkat, int, (int fd, char const *file, int flag)
1308 _GL_ARG_NONNULL ((2)));
1309_GL_CXXALIAS_RPL (unlinkat, int, (int fd, char const *file, int flag));
1310# else
1311# if !@HAVE_UNLINKAT@
1312_GL_FUNCDECL_SYS (unlinkat, int, (int fd, char const *file, int flag)
1313 _GL_ARG_NONNULL ((2)));
1314# endif
1315_GL_CXXALIAS_SYS (unlinkat, int, (int fd, char const *file, int flag));
1316# endif
1317_GL_CXXALIASWARN (unlinkat);
1318#elif defined GNULIB_POSIXCHECK
1319# undef unlinkat
1320# if HAVE_RAW_DECL_UNLINKAT
1321_GL_WARN_ON_USE (unlinkat, "unlinkat is not portable - "
1322 "use gnulib module openat for portability");
1323# endif
1324#endif
1325
1326
1327#if @GNULIB_USLEEP@
1328/* Pause the execution of the current thread for N microseconds.
1329 Returns 0 on completion, or -1 on range error.
1330 See the POSIX:2001 specification
1331 <http://www.opengroup.org/susv3xsh/sleep.html>. */
1332# if @REPLACE_USLEEP@
1333# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1334# undef usleep
1335# define usleep rpl_usleep
1336# endif
1337_GL_FUNCDECL_RPL (usleep, int, (useconds_t n));
1338_GL_CXXALIAS_RPL (usleep, int, (useconds_t n));
1339# else
1340# if !@HAVE_USLEEP@
1341_GL_FUNCDECL_SYS (usleep, int, (useconds_t n));
1342# endif
1343_GL_CXXALIAS_SYS (usleep, int, (useconds_t n));
1344# endif
1345_GL_CXXALIASWARN (usleep);
1346#elif defined GNULIB_POSIXCHECK
1347# undef usleep
1348# if HAVE_RAW_DECL_USLEEP
1349_GL_WARN_ON_USE (usleep, "usleep is unportable - "
1350 "use gnulib module usleep for portability");
1351# endif
1352#endif
1353
1354
1355#if @GNULIB_WRITE@
1356/* Write up to COUNT bytes starting at BUF to file descriptor FD.
1357 See the POSIX:2001 specification
1358 <http://www.opengroup.org/susv3xsh/write.html>. */
1359# if @REPLACE_WRITE@ && @GNULIB_UNISTD_H_SIGPIPE@
1360# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
1361# undef write
1362# define write rpl_write
1363# endif
1364_GL_FUNCDECL_RPL (write, ssize_t, (int fd, const void *buf, size_t count)
1365 _GL_ARG_NONNULL ((2)));
1366_GL_CXXALIAS_RPL (write, ssize_t, (int fd, const void *buf, size_t count));
1367# else
1368/* Need to cast, because on mingw, the third parameter is
1369 unsigned int count
1370 and the return type is 'int'. */
1371_GL_CXXALIAS_SYS_CAST (write, ssize_t, (int fd, const void *buf, size_t count));
1372# endif
1373_GL_CXXALIASWARN (write);
1374#endif
1375
1376
1377#endif /* _GL_UNISTD_H */
1378#endif /* _GL_UNISTD_H */