summaryrefslogtreecommitdiffstats
path: root/meta/recipes-core/uclibc/uclibc-git
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-core/uclibc/uclibc-git')
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-Add-eventfd_read-and-eventfd_write.patch120
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-Revert-utent.c-wtent.c-move-functions-from-utxent.c.patch319
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-atexit_old-Do-not-add-it-to-shared-libc.patch44
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-librt-Use-nodefaultlibs-instead-of-nostdlib.patch33
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-nptl-arm-Move-aeabi_read_tp-to-uclibc_nonshared.a.patch28
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0001-nptl-atfork-Hide-pthread_atfork-in-shared-versions.patch74
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0002-wire-setns-syscall.patch68
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0003-fcntl.h-Define-F_SETPIPE_SZ-and-F_GETPIPE_SZ.patch377
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/0004-Add-clock_adjtime-syscall.patch73
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/argp-headers.patch583
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/argp-support.patch5192
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/compile-arm-fork-with-O2.patch21
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/locale.cfg3
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/obstack.cfg1
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/orign_path.patch186
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/powerpc_copysignl.patch113
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/remove_attribute_optimize_Os.patch140
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/uClibc.distro192
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/uClibc.machine14
-rw-r--r--meta/recipes-core/uclibc/uclibc-git/uclibc_enable_log2_test.patch35
20 files changed, 7616 insertions, 0 deletions
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-Add-eventfd_read-and-eventfd_write.patch b/meta/recipes-core/uclibc/uclibc-git/0001-Add-eventfd_read-and-eventfd_write.patch
new file mode 100644
index 0000000000..dd0efc0f36
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-Add-eventfd_read-and-eventfd_write.patch
@@ -0,0 +1,120 @@
1From e3aae24ede969e2dede1aa19c2ee520cab71ce11 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Thu, 20 Feb 2014 00:30:18 -0800
4Subject: [PATCH 1/3] Add eventfd_read() and eventfd_write()
5
6Signed-off-by: Khem Raj <raj.khem@gmail.com>
7Upstream-Status: Pending
8---
9 libc/sysdeps/linux/common/Makefile.in | 2 ++
10 libc/sysdeps/linux/common/eventfd_read.c | 27 +++++++++++++++++++++++++++
11 libc/sysdeps/linux/common/eventfd_write.c | 28 ++++++++++++++++++++++++++++
12 libc/sysdeps/linux/common/sys/eventfd.h | 4 ----
13 4 files changed, 57 insertions(+), 4 deletions(-)
14 create mode 100644 libc/sysdeps/linux/common/eventfd_read.c
15 create mode 100644 libc/sysdeps/linux/common/eventfd_write.c
16
17diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
18index dbf0b0f..45d2e21 100644
19--- a/libc/sysdeps/linux/common/Makefile.in
20+++ b/libc/sysdeps/linux/common/Makefile.in
21@@ -25,6 +25,8 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \
22 capset.c \
23 dup3.c \
24 eventfd.c \
25+ eventfd_read.c \
26+ eventfd_write.c \
27 inotify.c \
28 ioperm.c \
29 iopl.c \
30diff --git a/libc/sysdeps/linux/common/eventfd_read.c b/libc/sysdeps/linux/common/eventfd_read.c
31new file mode 100644
32index 0000000..75f2aaa
33--- /dev/null
34+++ b/libc/sysdeps/linux/common/eventfd_read.c
35@@ -0,0 +1,27 @@
36+/* Copyright (C) 2007-2014 Free Software Foundation, Inc.
37+ This file is part of the GNU C Library.
38+
39+ The GNU C Library is free software; you can redistribute it and/or
40+ modify it under the terms of the GNU Lesser General Public
41+ License as published by the Free Software Foundation; either
42+ version 2.1 of the License, or (at your option) any later version.
43+
44+ The GNU C Library is distributed in the hope that it will be useful,
45+ but WITHOUT ANY WARRANTY; without even the implied warranty of
46+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47+ Lesser General Public License for more details.
48+
49+ You should have received a copy of the GNU Lesser General Public
50+ License along with the GNU C Library; if not, see
51+ <http://www.gnu.org/licenses/>. */
52+
53+#include <errno.h>
54+#include <unistd.h>
55+#include <sys/eventfd.h>
56+
57+
58+int
59+eventfd_read (int fd, eventfd_t *value)
60+{
61+ return read (fd, value, sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
62+}
63diff --git a/libc/sysdeps/linux/common/eventfd_write.c b/libc/sysdeps/linux/common/eventfd_write.c
64new file mode 100644
65index 0000000..e1509cf
66--- /dev/null
67+++ b/libc/sysdeps/linux/common/eventfd_write.c
68@@ -0,0 +1,28 @@
69+/* Copyright (C) 2007-2014 Free Software Foundation, Inc.
70+ This file is part of the GNU C Library.
71+
72+ The GNU C Library is free software; you can redistribute it and/or
73+ modify it under the terms of the GNU Lesser General Public
74+ License as published by the Free Software Foundation; either
75+ version 2.1 of the License, or (at your option) any later version.
76+
77+ The GNU C Library is distributed in the hope that it will be useful,
78+ but WITHOUT ANY WARRANTY; without even the implied warranty of
79+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
80+ Lesser General Public License for more details.
81+
82+ You should have received a copy of the GNU Lesser General Public
83+ License along with the GNU C Library; if not, see
84+ <http://www.gnu.org/licenses/>. */
85+
86+#include <errno.h>
87+#include <unistd.h>
88+#include <sys/eventfd.h>
89+
90+
91+int
92+eventfd_write (int fd, eventfd_t value)
93+{
94+ return write (fd, &value,
95+ sizeof (eventfd_t)) != sizeof (eventfd_t) ? -1 : 0;
96+}
97diff --git a/libc/sysdeps/linux/common/sys/eventfd.h b/libc/sysdeps/linux/common/sys/eventfd.h
98index 1bf785f..91b265b 100644
99--- a/libc/sysdeps/linux/common/sys/eventfd.h
100+++ b/libc/sysdeps/linux/common/sys/eventfd.h
101@@ -33,16 +33,12 @@ __BEGIN_DECLS
102 value to COUNT. */
103 extern int eventfd (int __count, int __flags) __THROW;
104
105-#if 0 /* not (yet) implemented in uClibc */
106-
107 /* Read event counter and possibly wait for events. */
108 extern int eventfd_read (int __fd, eventfd_t *__value);
109
110 /* Increment event counter. */
111 extern int eventfd_write (int __fd, eventfd_t __value);
112
113-#endif
114-
115 __END_DECLS
116
117 #endif /* sys/eventfd.h */
118--
1191.9.0
120
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-Revert-utent.c-wtent.c-move-functions-from-utxent.c.patch b/meta/recipes-core/uclibc/uclibc-git/0001-Revert-utent.c-wtent.c-move-functions-from-utxent.c.patch
new file mode 100644
index 0000000000..4ac765c334
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-Revert-utent.c-wtent.c-move-functions-from-utxent.c.patch
@@ -0,0 +1,319 @@
1Upstream-Status: Pending
2
3From 096abf14d2dc978607ccd8a0d7f42da65d8991f3 Mon Sep 17 00:00:00 2001
4From: Khem Raj <raj.khem@gmail.com>
5Date: Sun, 9 Sep 2012 22:00:04 -0700
6Subject: [PATCH] Revert "utent.c, wtent.c: move functions from utxent.c"
7
8This reverts commit 84135275cfeebc0b233c1c96eeada4d4178a0b18.
9---
10 include/utmp.h | 8 +++++
11 libc/misc/utmp/utent.c | 80 +++++++++++------------------------------------
12 libc/misc/utmp/utxent.c | 4 +--
13 libc/misc/utmp/wtent.c | 14 ++-------
14 4 files changed, 30 insertions(+), 76 deletions(-)
15
16Index: git/include/utmp.h
17===================================================================
18--- git.orig/include/utmp.h 2013-01-21 16:37:18.000000000 -0800
19+++ git/include/utmp.h 2013-01-21 16:40:56.987583099 -0800
20@@ -56,30 +56,37 @@
21 /* Append entry UTMP to the wtmp-like file WTMP_FILE. */
22 extern void updwtmp (const char *__wtmp_file, const struct utmp *__utmp)
23 __THROW;
24+libc_hidden_proto(updwtmp)
25
26 /* Change name of the utmp file to be examined. */
27 extern int utmpname (const char *__file) __THROW;
28+libc_hidden_proto(utmpname)
29
30 /* Read next entry from a utmp-like file. */
31 extern struct utmp *getutent (void) __THROW;
32+libc_hidden_proto(getutent)
33
34 /* Reset the input stream to the beginning of the file. */
35 extern void setutent (void) __THROW;
36+libc_hidden_proto(setutent)
37
38 /* Close the current open file. */
39 extern void endutent (void) __THROW;
40+libc_hidden_proto(endutent)
41
42 /* Search forward from the current point in the utmp file until the
43 next entry with a ut_type matching ID->ut_type. */
44 extern struct utmp *getutid (const struct utmp *__id) __THROW;
45+libc_hidden_proto(getutid)
46
47 /* Search forward from the current point in the utmp file until the
48 next entry with a ut_line matching LINE->ut_line. */
49 extern struct utmp *getutline (const struct utmp *__line) __THROW;
50+libc_hidden_proto(getutline)
51
52 /* Write out entry pointed to by UTMP_PTR into the utmp file. */
53 extern struct utmp *pututline (const struct utmp *__utmp_ptr) __THROW;
54-
55+libc_hidden_proto(pututline)
56
57 #if 0 /* def __USE_MISC */
58 /* Reentrant versions of the file for handling utmp files. */
59Index: git/libc/misc/utmp/utent.c
60===================================================================
61--- git.orig/libc/misc/utmp/utent.c 2013-01-21 16:37:18.000000000 -0800
62+++ git/libc/misc/utmp/utent.c 2013-01-21 16:38:14.035578638 -0800
63@@ -19,9 +19,6 @@
64 #include <errno.h>
65 #include <string.h>
66 #include <utmp.h>
67-#ifdef __UCLIBC_HAS_UTMPX__
68-# include <utmpx.h>
69-#endif
70 #include <not-cancel.h>
71
72 #include <bits/uClibc_mutex.h>
73@@ -34,7 +31,7 @@
74 static const char *static_ut_name = default_file_name;
75
76 /* This function must be called with the LOCK held */
77-static void __setutent_unlocked(void)
78+static void __setutent(void)
79 {
80 if (static_fd < 0) {
81 static_fd = open_not_cancel_2(static_ut_name, O_RDWR | O_CLOEXEC);
82@@ -53,24 +50,19 @@
83 lseek(static_fd, 0, SEEK_SET);
84 }
85 #if defined __UCLIBC_HAS_THREADS__
86-static void __setutent(void)
87+void setutent(void)
88 {
89 __UCLIBC_MUTEX_LOCK(utmplock);
90- __setutent_unlocked();
91+ __setutent();
92 __UCLIBC_MUTEX_UNLOCK(utmplock);
93 }
94 #else
95-static void __setutent(void);
96-strong_alias(__setutent_unlocked,__setutent)
97-#endif
98 strong_alias(__setutent,setutent)
99-
100-#ifdef __UCLIBC_HAS_UTMPX__
101-strong_alias(__setutent,setutxent)
102 #endif
103+libc_hidden_def(setutent)
104
105 /* This function must be called with the LOCK held */
106-static struct utmp *__getutent_unlocked(void)
107+static struct utmp *__getutent(void)
108 {
109 if (static_fd < 0) {
110 __setutent();
111@@ -86,27 +78,19 @@
112 return NULL;
113 }
114 #if defined __UCLIBC_HAS_THREADS__
115-static struct utmp *__getutent(void)
116+struct utmp *getutent(void)
117 {
118 struct utmp *ret;
119
120 __UCLIBC_MUTEX_LOCK(utmplock);
121- ret = __getutent_unlocked();
122+ ret = __getutent();
123 __UCLIBC_MUTEX_UNLOCK(utmplock);
124 return ret;
125 }
126 #else
127-static struct utmp *__getutent(void);
128-strong_alias(__getutent_unlocked,__getutent)
129-#endif
130 strong_alias(__getutent,getutent)
131-
132-#ifdef __UCLIBC_HAS_UTMPX__
133-struct utmpx *getutxent(void)
134-{
135- return (struct utmpx *) __getutent ();
136-}
137 #endif
138+libc_hidden_def(getutent)
139
140 static void __endutent(void)
141 {
142@@ -117,13 +101,10 @@
143 __UCLIBC_MUTEX_UNLOCK(utmplock);
144 }
145 strong_alias(__endutent,endutent)
146-
147-#ifdef __UCLIBC_HAS_UTMPX__
148-strong_alias(__endutent,endutxent)
149-#endif
150+libc_hidden_def(endutent)
151
152 /* This function must be called with the LOCK held */
153-static struct utmp *__getutid_unlocked(const struct utmp *utmp_entry)
154+static struct utmp *__getutid(const struct utmp *utmp_entry)
155 {
156 struct utmp *lutmp;
157 unsigned type;
158@@ -133,7 +114,7 @@
159 type = utmp_entry->ut_type - 1;
160 type /= 4;
161
162- while ((lutmp = __getutent_unlocked()) != NULL) {
163+ while ((lutmp = __getutent()) != NULL) {
164 if (type == 0 && lutmp->ut_type == utmp_entry->ut_type) {
165 /* one of RUN_LVL, BOOT_TIME, NEW_TIME, OLD_TIME */
166 return lutmp;
167@@ -147,34 +128,26 @@
168 return NULL;
169 }
170 #if defined __UCLIBC_HAS_THREADS__
171-static struct utmp *__getutid(const struct utmp *utmp_entry)
172+struct utmp *getutid(const struct utmp *utmp_entry)
173 {
174 struct utmp *ret;
175
176 __UCLIBC_MUTEX_LOCK(utmplock);
177- ret = __getutid_unlocked(utmp_entry);
178+ ret = __getutid(utmp_entry);
179 __UCLIBC_MUTEX_UNLOCK(utmplock);
180 return ret;
181 }
182 #else
183-static struct utmp *__getutid(const struct utmp *utmp_entry);
184-strong_alias(__getutid_unlocked,__getutid)
185-#endif
186 strong_alias(__getutid,getutid)
187-
188-#ifdef __UCLIBC_HAS_UTMPX__
189-struct utmpx *getutxid(const struct utmpx *utmp_entry)
190-{
191- return (struct utmpx *) __getutid ((const struct utmp *) utmp_entry);
192-}
193 #endif
194+libc_hidden_def(getutid)
195
196 static struct utmp *__getutline(const struct utmp *utmp_entry)
197 {
198 struct utmp *lutmp;
199
200 __UCLIBC_MUTEX_LOCK(utmplock);
201- while ((lutmp = __getutent_unlocked()) != NULL) {
202+ while ((lutmp = __getutent()) != NULL) {
203 if (lutmp->ut_type == USER_PROCESS || lutmp->ut_type == LOGIN_PROCESS) {
204 if (strncmp(lutmp->ut_line, utmp_entry->ut_line, sizeof(lutmp->ut_line)) == 0) {
205 break;
206@@ -185,13 +158,7 @@
207 return lutmp;
208 }
209 strong_alias(__getutline,getutline)
210-
211-#ifdef __UCLIBC_HAS_UTMPX__
212-struct utmpx *getutxline(const struct utmpx *utmp_entry)
213-{
214- return (struct utmpx *) __getutline ((const struct utmp *) utmp_entry);
215-}
216-#endif
217+libc_hidden_def(getutline)
218
219 static struct utmp *__pututline(const struct utmp *utmp_entry)
220 {
221@@ -200,7 +167,7 @@
222 the file pointer where they want it, everything will work out. */
223 lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
224
225- if (__getutid_unlocked(utmp_entry) != NULL)
226+ if (__getutid(utmp_entry) != NULL)
227 lseek(static_fd, (off_t) - sizeof(struct utmp), SEEK_CUR);
228 else
229 lseek(static_fd, (off_t) 0, SEEK_END);
230@@ -211,13 +178,7 @@
231 return (struct utmp *)utmp_entry;
232 }
233 strong_alias(__pututline,pututline)
234-
235-#ifdef __UCLIBC_HAS_UTMPX__
236-struct utmpx *pututxline (const struct utmpx *utmp_entry)
237-{
238- return (struct utmpx *) __pututline ((const struct utmp *) utmp_entry);
239-}
240-#endif
241+libc_hidden_def(pututline)
242
243 static int __utmpname(const char *new_ut_name)
244 {
245@@ -241,7 +202,4 @@
246 return 0; /* or maybe return -(static_ut_name != new_ut_name)? */
247 }
248 strong_alias(__utmpname,utmpname)
249-
250-#ifdef __UCLIBC_HAS_UTMPX__
251-strong_alias(__utmpname,utmpxname)
252-#endif
253+libc_hidden_def(utmpname)
254Index: git/libc/misc/utmp/utxent.c
255===================================================================
256--- git.orig/libc/misc/utmp/utxent.c 2013-01-21 16:37:18.000000000 -0800
257+++ git/libc/misc/utmp/utxent.c 2013-01-21 16:38:14.035578638 -0800
258@@ -13,7 +13,6 @@
259 #include <utmpx.h>
260 #include <utmp.h>
261
262-#if 0 /* moved to utent.c */
263 void setutxent(void)
264 {
265 setutent ();
266@@ -49,12 +48,10 @@
267 return utmpname (new_ut_name);
268 }
269
270-/* moved to wtent.c */
271 void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
272 {
273 updwtmp (wtmpx_file, (const struct utmp *) utmpx);
274 }
275-#endif
276
277 /* Copy the information in UTMPX to UTMP. */
278 void getutmp (const struct utmpx *utmpx, struct utmp *utmp)
279@@ -107,3 +104,4 @@
280 utmpx->ut_time = utmp->ut_time;
281 #endif
282 }
283+
284Index: git/libc/misc/utmp/wtent.c
285===================================================================
286--- git.orig/libc/misc/utmp/wtent.c 2013-01-21 16:37:18.000000000 -0800
287+++ git/libc/misc/utmp/wtent.c 2013-01-21 16:38:14.035578638 -0800
288@@ -11,9 +11,6 @@
289 #include <time.h>
290 #include <unistd.h>
291 #include <utmp.h>
292-#ifdef __UCLIBC_HAS_UTMPX__
293-# include <utmpx.h>
294-#endif
295 #include <fcntl.h>
296 #include <sys/file.h>
297 #include <not-cancel.h>
298@@ -36,7 +33,7 @@
299 }
300 #endif
301
302-static void __updwtmp(const char *wtmp_file, const struct utmp *lutmp)
303+void updwtmp(const char *wtmp_file, const struct utmp *lutmp)
304 {
305 int fd;
306
307@@ -49,11 +46,4 @@
308 }
309 }
310 }
311-strong_alias(__updwtmp,updwtmp)
312-
313-#ifdef __UCLIBC_HAS_UTMPX__
314-void updwtmpx (const char *wtmpx_file, const struct utmpx *utmpx)
315-{
316- __updwtmp (wtmpx_file, (const struct utmp *) utmpx);
317-}
318-#endif
319+libc_hidden_def(updwtmp)
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-atexit_old-Do-not-add-it-to-shared-libc.patch b/meta/recipes-core/uclibc/uclibc-git/0001-atexit_old-Do-not-add-it-to-shared-libc.patch
new file mode 100644
index 0000000000..b6dfce483e
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-atexit_old-Do-not-add-it-to-shared-libc.patch
@@ -0,0 +1,44 @@
1From 74667582526b39a1906228574d73a6528f4587eb Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 23 Jun 2012 13:26:30 -0700
4Subject: [PATCH] atexit_old: Do not add it to shared libc
5
6atexit should only be in either uclibc_nonshared.a
7shared libc case or libc.a in static build case
8
9Signed-off-by: Khem Raj <raj.khem@gmail.com>
10
11Upstream-Status: Pending
12---
13 libc/stdlib/Makefile.in | 4 ++--
14 1 file changed, 2 insertions(+), 2 deletions(-)
15
16diff --git a/libc/stdlib/Makefile.in b/libc/stdlib/Makefile.in
17index 3166b8e..3d686d9 100644
18--- a/libc/stdlib/Makefile.in
19+++ b/libc/stdlib/Makefile.in
20@@ -60,7 +60,6 @@ CSRC-$(if $(findstring yyy,$(UCLIBC_HAS_FLOATS)$(UCLIBC_HAS_WCHAR)$(UCLIBC_HAS_X
21
22 # multi source _atexit.c
23 CSRC-y += __cxa_atexit.c __cxa_finalize.c __exit_handler.c exit.c on_exit.c
24-CSRC-$(COMPAT_ATEXIT) += old_atexit.c
25
26 STDLIB_DIR := $(top_srcdir)libc/stdlib
27 STDLIB_OUT := $(top_builddir)libc/stdlib
28@@ -70,11 +69,12 @@ STDLIB_OBJ := $(patsubst %.c,$(STDLIB_OUT)/%.o,$(CSRC-y))
29
30 libc-y += $(STDLIB_OBJ)
31 libc-static-y += $(STDLIB_OUT)/atexit.o $(STDLIB_OUT)/system.o
32+libc-static-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.o
33 libc-shared-y += $(STDLIB_OUT)/system.oS
34
35 # this should always be the PIC version, because it could be used in shared libs
36 libc-nonshared-y += $(STDLIB_OUT)/atexit.os
37-
38+libc-nonshared-$(COMPAT_ATEXIT) += $(STDLIB_OUT)/old_atexit.os
39 libc-nomulti-y += $(STDLIB_OUT)/labs.o $(STDLIB_OUT)/atol.o $(STDLIB_OUT)/_stdlib_strto_l.o $(STDLIB_OUT)/_stdlib_strto_ll.o
40 libc-nomulti-$(UCLIBC_HAS_XLOCALE) += $(STDLIB_OUT)/_stdlib_strto_l_l.o $(STDLIB_OUT)/_stdlib_strto_ll_l.o
41
42--
431.7.9.5
44
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-librt-Use-nodefaultlibs-instead-of-nostdlib.patch b/meta/recipes-core/uclibc/uclibc-git/0001-librt-Use-nodefaultlibs-instead-of-nostdlib.patch
new file mode 100644
index 0000000000..ecb9d31645
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-librt-Use-nodefaultlibs-instead-of-nostdlib.patch
@@ -0,0 +1,33 @@
1From 95f9b6f37152b8316735d3c86c0db963ff59e22d Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 23 Jun 2012 16:51:52 -0700
4Subject: [PATCH] librt: Use -nodefaultlibs instead of -nostdlib
5
6nostdlib disables linking in startup files too which is not
7what we want here since it needs to resolve __dso_handle
8which comes from crtbeginS.o, otherwise librt has this
9undefined reference to a weak undefined __dso_handle that
10shows up as error (with gold linker)
11when shared libraries are being built which are
12linking in librt
13
14Signed-off-by: Khem Raj <raj.khem@gmail.com>
15Upstream-Status: Pending
16---
17 librt/Makefile.in | 1 +
18 1 file changed, 1 insertion(+)
19
20Index: git/librt/Makefile.in
21===================================================================
22--- git.orig/librt/Makefile.in 2012-06-24 10:32:59.512653237 -0700
23+++ git/librt/Makefile.in 2012-06-24 11:31:00.660821666 -0700
24@@ -15,6 +15,9 @@
25 ifeq ($(UCLIBC_HAS_THREADS_NATIVE),y)
26 LIBS-librt.so += $(top_builddir)lib/libdl.so $(top_builddir)lib/libpthread.so
27 endif
28+START_FILE-librt.so := $(SHARED_START_FILES)
29+END_FILE-librt.so := $(SHARED_END_FILES)
30+
31
32 librt_FULL_NAME := librt-$(VERSION).so
33
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-nptl-arm-Move-aeabi_read_tp-to-uclibc_nonshared.a.patch b/meta/recipes-core/uclibc/uclibc-git/0001-nptl-arm-Move-aeabi_read_tp-to-uclibc_nonshared.a.patch
new file mode 100644
index 0000000000..7e7c5793f1
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-nptl-arm-Move-aeabi_read_tp-to-uclibc_nonshared.a.patch
@@ -0,0 +1,28 @@
1From 714f543f4fa8fb3911449b6ce1517481359e0cff Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 23 Jun 2012 14:21:17 -0700
4Subject: [PATCH] nptl/arm: Move aeabi_read_tp to uclibc_nonshared.a
5
6Otherwise it creates wrong references from shared libs
7
8Signed-off-by: Khem Raj <raj.khem@gmail.com>
9Upstream-Status: Pending
10---
11 libc/sysdeps/linux/arm/Makefile.arch | 4 +++-
12 1 file changed, 3 insertions(+), 1 deletion(-)
13
14Index: git/libc/sysdeps/linux/arm/Makefile.arch
15===================================================================
16--- git.orig/libc/sysdeps/linux/arm/Makefile.arch 2013-05-23 11:13:32.000000000 -0700
17+++ git/libc/sysdeps/linux/arm/Makefile.arch 2013-05-23 11:16:18.304333131 -0700
18@@ -13,7 +13,9 @@
19 vfork.S clone.S
20
21 SSRC-$(UCLIBC_HAS_LFS) += mmap64.S
22-SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-aeabi_read_tp.S libc-thumb_atomics.S
23+SSRC-$(UCLIBC_HAS_THREADS_NATIVE) += libc-thumb_atomics.S
24+libc-nonshared-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.os
25+libc-static-$(UCLIBC_HAS_THREADS_NATIVE) += $(ARCH_OUT)/libc-aeabi_read_tp.o
26 CSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += makecontext.c
27 SSRC-$(UCLIBC_HAS_CONTEXT_FUNCS) += getcontext.S setcontext.S swapcontext.S
28
diff --git a/meta/recipes-core/uclibc/uclibc-git/0001-nptl-atfork-Hide-pthread_atfork-in-shared-versions.patch b/meta/recipes-core/uclibc/uclibc-git/0001-nptl-atfork-Hide-pthread_atfork-in-shared-versions.patch
new file mode 100644
index 0000000000..297a40bd04
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0001-nptl-atfork-Hide-pthread_atfork-in-shared-versions.patch
@@ -0,0 +1,74 @@
1From d021e6252b33e779857846714fb1899a25c9965d Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 23 Jun 2012 15:59:01 -0700
4Subject: [PATCH] nptl/atfork: Hide pthread_atfork in shared versions
5
6Signed-off-by: Khem Raj <raj.khem@gmail.com>
7Upstream-Status: Pending
8---
9 libpthread/nptl/Makefile.in | 4 +++-
10 libpthread/nptl/pthread_atfork.c | 12 ++++++++++--
11 2 files changed, 13 insertions(+), 3 deletions(-)
12
13diff --git a/libpthread/nptl/Makefile.in b/libpthread/nptl/Makefile.in
14index 158bcae..3ef7175 100644
15--- a/libpthread/nptl/Makefile.in
16+++ b/libpthread/nptl/Makefile.in
17@@ -16,6 +16,7 @@ libc-shared-routines-y = forward.c libc-cancellation.c
18 libc-static-routines-y = alloca_cutoff.c libc-cancellation.c
19 libpthread-shared-only-routines-y = version.c
20 libpthread-static-only-routines-y = pthread_atfork.c
21+
22 libpthread-routines- += $(notdir $(wildcard $(libpthread_DIR)/gen_*.c)) # dummy generated files
23 libpthread-routines- += allocatestack.c # dummy included by pthread_create.c
24 libpthread-routines- += pthread_mutex_getprioceiling.c pthread_mutex_setprioceiling.c # XXX: delete those or use them!
25@@ -208,7 +209,7 @@ CFLAGS-msgsnd.c = -fexceptions -fasynchronous-unwind-tables
26 CFLAGS-tcdrain.c = -fexceptions -fasynchronous-unwind-tables
27
28 CFLAGS-pt-system.c = -fexceptions -I$(top_srcdir)libc/stdlib
29-
30+CFLAGS-pthread_atfork.c = -DNOT_IN_libc
31 #
32 # The rest of this file is uClibc specific.
33 #
34@@ -224,3 +225,4 @@ CFLAGS-OMIT-alloca_cutoff.c = $(CFLAGS-nptl)
35 CFLAGS-OMIT-forward.c = $(CFLAGS-nptl)
36 CFLAGS-OMIT-libc-lowlevelock.c = $(CFLAGS-nptl)
37 CFLAGS-OMIT-libc-cancellation.c = $(CFLAGS-nptl)
38+
39diff --git a/libpthread/nptl/pthread_atfork.c b/libpthread/nptl/pthread_atfork.c
40index e607d49..6224c17 100644
41--- a/libpthread/nptl/pthread_atfork.c
42+++ b/libpthread/nptl/pthread_atfork.c
43@@ -38,13 +38,17 @@
44 #include <fork.h>
45
46 /* This is defined by newer gcc version unique for each module. */
47-extern void *__dso_handle __attribute__ ((__weak__));
48- //,__visibility__ ("hidden")));
49+extern void *__dso_handle __attribute__ ((__weak__,
50+ __visibility__ ("hidden")));
51
52
53 /* Hide the symbol so that no definition but the one locally in the
54 executable or DSO is used. */
55 int
56+#ifndef __pthread_atfork
57+/* Don't mark the compatibility function as hidden. */
58+attribute_hidden
59+#endif
60 __pthread_atfork (
61 void (*prepare) (void),
62 void (*parent) (void),
63@@ -53,4 +57,8 @@ __pthread_atfork (
64 return __register_atfork (prepare, parent, child,
65 &__dso_handle == NULL ? NULL : __dso_handle);
66 }
67+#ifndef __pthread_atfork
68+extern int pthread_atfork (void (*prepare) (void), void (*parent) (void),
69+ void (*child) (void)) attribute_hidden;
70 strong_alias (__pthread_atfork, pthread_atfork)
71+#endif
72--
731.7.9.5
74
diff --git a/meta/recipes-core/uclibc/uclibc-git/0002-wire-setns-syscall.patch b/meta/recipes-core/uclibc/uclibc-git/0002-wire-setns-syscall.patch
new file mode 100644
index 0000000000..94c6f68571
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0002-wire-setns-syscall.patch
@@ -0,0 +1,68 @@
1From db575359d4b8164ad6c2ac5f36c7a50c065a2864 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Thu, 20 Feb 2014 00:44:34 -0800
4Subject: [PATCH 2/3] wire setns syscall
5
6Signed-off-by: Khem Raj <raj.khem@gmail.com>
7Upstream-Status: Pending
8---
9 libc/sysdeps/linux/common/Makefile.in | 1 +
10 libc/sysdeps/linux/common/bits/sched.h | 4 ++++
11 libc/sysdeps/linux/common/setns.c | 18 ++++++++++++++++++
12 3 files changed, 23 insertions(+)
13 create mode 100644 libc/sysdeps/linux/common/setns.c
14
15diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
16index 45d2e21..10d9884 100644
17--- a/libc/sysdeps/linux/common/Makefile.in
18+++ b/libc/sysdeps/linux/common/Makefile.in
19@@ -45,6 +45,7 @@ CSRC-$(UCLIBC_LINUX_SPECIFIC) += \
20 sendfile.c \
21 setfsgid.c \
22 setfsuid.c \
23+ setns.c \
24 setresgid.c \
25 setresuid.c \
26 signalfd.c \
27diff --git a/libc/sysdeps/linux/common/bits/sched.h b/libc/sysdeps/linux/common/bits/sched.h
28index a5eb6ee..9436f66 100644
29--- a/libc/sysdeps/linux/common/bits/sched.h
30+++ b/libc/sysdeps/linux/common/bits/sched.h
31@@ -85,6 +85,10 @@ extern int unshare (int __flags) __THROW;
32
33 /* Get index of currently used CPU. */
34 extern int sched_getcpu (void) __THROW;
35+
36+/* Switch process to namespace of type NSTYPE indicated by FD. */
37+extern int setns (int __fd, int __nstype) __THROW;
38+
39 #endif
40
41 __END_DECLS
42diff --git a/libc/sysdeps/linux/common/setns.c b/libc/sysdeps/linux/common/setns.c
43new file mode 100644
44index 0000000..376bf26
45--- /dev/null
46+++ b/libc/sysdeps/linux/common/setns.c
47@@ -0,0 +1,18 @@
48+/* vi: set sw=4 ts=4: */
49+/*
50+ * setns() for uClibc
51+ *
52+ * Copyright (C) 2014 Khem Raj <raj.khem@gmail.com>
53+ *
54+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
55+ */
56+
57+#include <sys/syscall.h>
58+#include <sched.h>
59+
60+/*
61+ * setns()
62+ */
63+#ifdef __NR_setns
64+_syscall2(int, setns, int, fd, int, nstype)
65+#endif
66--
671.9.0
68
diff --git a/meta/recipes-core/uclibc/uclibc-git/0003-fcntl.h-Define-F_SETPIPE_SZ-and-F_GETPIPE_SZ.patch b/meta/recipes-core/uclibc/uclibc-git/0003-fcntl.h-Define-F_SETPIPE_SZ-and-F_GETPIPE_SZ.patch
new file mode 100644
index 0000000000..f4387db9c7
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0003-fcntl.h-Define-F_SETPIPE_SZ-and-F_GETPIPE_SZ.patch
@@ -0,0 +1,377 @@
1From 7791d129d777e481a1e429815edcd05978438840 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Thu, 20 Feb 2014 01:12:14 -0800
4Subject: [PATCH 3/3] fcntl.h: Define F_SETPIPE_SZ and F_GETPIPE_SZ
5
6Signed-off-by: Khem Raj <raj.khem@gmail.com>
7Upstream-Status: Pending
8---
9 libc/sysdeps/linux/alpha/bits/fcntl.h | 2 ++
10 libc/sysdeps/linux/arc/bits/fcntl.h | 2 ++
11 libc/sysdeps/linux/arm/bits/fcntl.h | 2 ++
12 libc/sysdeps/linux/bfin/bits/fcntl.h | 2 ++
13 libc/sysdeps/linux/cris/bits/fcntl.h | 2 ++
14 libc/sysdeps/linux/e1/bits/fcntl.h | 2 ++
15 libc/sysdeps/linux/frv/bits/fcntl.h | 2 ++
16 libc/sysdeps/linux/h8300/bits/fcntl.h | 2 ++
17 libc/sysdeps/linux/hppa/bits/fcntl.h | 2 ++
18 libc/sysdeps/linux/i386/bits/fcntl.h | 2 ++
19 libc/sysdeps/linux/i960/bits/fcntl.h | 2 ++
20 libc/sysdeps/linux/ia64/bits/fcntl.h | 2 ++
21 libc/sysdeps/linux/m68k/bits/fcntl.h | 2 ++
22 libc/sysdeps/linux/metag/bits/fcntl.h | 2 ++
23 libc/sysdeps/linux/microblaze/bits/fcntl.h | 2 ++
24 libc/sysdeps/linux/mips/bits/fcntl.h | 2 ++
25 libc/sysdeps/linux/nios/bits/fcntl.h | 2 ++
26 libc/sysdeps/linux/nios2/bits/fcntl.h | 2 ++
27 libc/sysdeps/linux/powerpc/bits/fcntl.h | 2 ++
28 libc/sysdeps/linux/sh/bits/fcntl.h | 2 ++
29 libc/sysdeps/linux/sh64/bits/fcntl.h | 2 ++
30 libc/sysdeps/linux/sparc/bits/fcntl.h | 2 ++
31 libc/sysdeps/linux/v850/bits/fcntl.h | 2 ++
32 libc/sysdeps/linux/vax/bits/fcntl.h | 2 ++
33 libc/sysdeps/linux/x86_64/bits/fcntl.h | 2 ++
34 libc/sysdeps/linux/xtensa/bits/fcntl.h | 2 ++
35 26 files changed, 52 insertions(+)
36
37diff --git a/libc/sysdeps/linux/alpha/bits/fcntl.h b/libc/sysdeps/linux/alpha/bits/fcntl.h
38index dd32529..a44be9e 100644
39--- a/libc/sysdeps/linux/alpha/bits/fcntl.h
40+++ b/libc/sysdeps/linux/alpha/bits/fcntl.h
41@@ -94,6 +94,8 @@
42 # define F_NOTIFY 1026 /* Request notfications on a directory. */
43 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
44 close-on-exit set on new fd. */
45+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
46+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
47 #endif
48
49 /* for F_[GET|SET]FD */
50diff --git a/libc/sysdeps/linux/arc/bits/fcntl.h b/libc/sysdeps/linux/arc/bits/fcntl.h
51index 71136da..1cb9600 100755
52--- a/libc/sysdeps/linux/arc/bits/fcntl.h
53+++ b/libc/sysdeps/linux/arc/bits/fcntl.h
54@@ -87,6 +87,8 @@
55 # define F_NOTIFY 1026 /* Request notfications on a directory. */
56 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
57 close-on-exit set on new fd. */
58+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
59+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
60 #endif
61
62 /* For F_[GET|SET]FL. */
63diff --git a/libc/sysdeps/linux/arm/bits/fcntl.h b/libc/sysdeps/linux/arm/bits/fcntl.h
64index f1a54f0..aedc154 100644
65--- a/libc/sysdeps/linux/arm/bits/fcntl.h
66+++ b/libc/sysdeps/linux/arm/bits/fcntl.h
67@@ -99,6 +99,8 @@
68 # define F_NOTIFY 1026 /* Request notfications on a directory. */
69 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
70 close-on-exit set on new fd. */
71+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
72+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
73 #endif
74
75 /* For F_[GET|SET]FD. */
76diff --git a/libc/sysdeps/linux/bfin/bits/fcntl.h b/libc/sysdeps/linux/bfin/bits/fcntl.h
77index c6cba56..e987824 100644
78--- a/libc/sysdeps/linux/bfin/bits/fcntl.h
79+++ b/libc/sysdeps/linux/bfin/bits/fcntl.h
80@@ -98,6 +98,8 @@
81 # define F_NOTIFY 1026 /* Request notfications on a directory. */
82 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
83 close-on-exit set on new fd. */
84+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
85+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
86 #endif
87
88 /* For F_[GET|SET]FL. */
89diff --git a/libc/sysdeps/linux/cris/bits/fcntl.h b/libc/sysdeps/linux/cris/bits/fcntl.h
90index acc5e25..029bb80 100644
91--- a/libc/sysdeps/linux/cris/bits/fcntl.h
92+++ b/libc/sysdeps/linux/cris/bits/fcntl.h
93@@ -99,6 +99,8 @@
94 # define F_NOTIFY 1026 /* Request notfications on a directory. */
95 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
96 close-on-exit set on new fd. */
97+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
98+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
99 #endif
100
101 /* For F_[GET|SET]FL. */
102diff --git a/libc/sysdeps/linux/e1/bits/fcntl.h b/libc/sysdeps/linux/e1/bits/fcntl.h
103index da699c8..2e0e6ba 100644
104--- a/libc/sysdeps/linux/e1/bits/fcntl.h
105+++ b/libc/sysdeps/linux/e1/bits/fcntl.h
106@@ -93,6 +93,8 @@
107 # define F_NOTIFY 1026 /* Request notfications on a directory. */
108 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
109 close-on-exit set on new fd. */
110+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
111+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
112 #endif
113
114 /* For F_[GET|SET]FL. */
115diff --git a/libc/sysdeps/linux/frv/bits/fcntl.h b/libc/sysdeps/linux/frv/bits/fcntl.h
116index 3aacc9d..5a7d9ef 100644
117--- a/libc/sysdeps/linux/frv/bits/fcntl.h
118+++ b/libc/sysdeps/linux/frv/bits/fcntl.h
119@@ -95,6 +95,8 @@
120 # define F_NOTIFY 1026 /* Request notfications on a directory. */
121 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
122 close-on-exit set on new fd. */
123+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
124+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
125 #endif
126
127 /* For F_[GET|SET]FL. */
128diff --git a/libc/sysdeps/linux/h8300/bits/fcntl.h b/libc/sysdeps/linux/h8300/bits/fcntl.h
129index d0b8310..45deec4 100644
130--- a/libc/sysdeps/linux/h8300/bits/fcntl.h
131+++ b/libc/sysdeps/linux/h8300/bits/fcntl.h
132@@ -93,6 +93,8 @@
133 # define F_NOTIFY 1026 /* Request notfications on a directory. */
134 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
135 close-on-exit set on new fd. */
136+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
137+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
138 #endif
139
140 /* For F_[GET|SET]FL. */
141diff --git a/libc/sysdeps/linux/hppa/bits/fcntl.h b/libc/sysdeps/linux/hppa/bits/fcntl.h
142index 1bb41ce..abb3372 100644
143--- a/libc/sysdeps/linux/hppa/bits/fcntl.h
144+++ b/libc/sysdeps/linux/hppa/bits/fcntl.h
145@@ -96,6 +96,8 @@
146 # define F_NOTIFY 1026 /* Request notfications on a directory. */
147 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
148 close-on-exit set on new fd. */
149+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
150+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
151 #endif
152
153 /* for F_[GET|SET]FL */
154diff --git a/libc/sysdeps/linux/i386/bits/fcntl.h b/libc/sysdeps/linux/i386/bits/fcntl.h
155index d48e62a..79b69d4 100644
156--- a/libc/sysdeps/linux/i386/bits/fcntl.h
157+++ b/libc/sysdeps/linux/i386/bits/fcntl.h
158@@ -99,6 +99,8 @@
159 # define F_NOTIFY 1026 /* Request notfications on a directory. */
160 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
161 close-on-exit set on new fd. */
162+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
163+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
164 #endif
165
166 /* For F_[GET|SET]FD. */
167diff --git a/libc/sysdeps/linux/i960/bits/fcntl.h b/libc/sysdeps/linux/i960/bits/fcntl.h
168index e2fcbe6..f6e145d 100644
169--- a/libc/sysdeps/linux/i960/bits/fcntl.h
170+++ b/libc/sysdeps/linux/i960/bits/fcntl.h
171@@ -93,6 +93,8 @@
172 # define F_NOTIFY 1026 /* Request notfications on a directory. */
173 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
174 close-on-exit set on new fd. */
175+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
176+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
177 #endif
178
179 /* For F_[GET|SET]FL. */
180diff --git a/libc/sysdeps/linux/ia64/bits/fcntl.h b/libc/sysdeps/linux/ia64/bits/fcntl.h
181index 1ff0ed5..fedefb6 100644
182--- a/libc/sysdeps/linux/ia64/bits/fcntl.h
183+++ b/libc/sysdeps/linux/ia64/bits/fcntl.h
184@@ -95,6 +95,8 @@
185 # define F_NOTIFY 1026 /* Request notfications on a directory. */
186 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
187 close-on-exit set on new fd. */
188+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
189+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
190 #endif
191
192 /* For F_[GET|SET]FD. */
193diff --git a/libc/sysdeps/linux/m68k/bits/fcntl.h b/libc/sysdeps/linux/m68k/bits/fcntl.h
194index d7beb6c..66df337 100644
195--- a/libc/sysdeps/linux/m68k/bits/fcntl.h
196+++ b/libc/sysdeps/linux/m68k/bits/fcntl.h
197@@ -98,6 +98,8 @@
198 # define F_NOTIFY 1026 /* Request notfications on a directory. */
199 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
200 close-on-exit set on new fd. */
201+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
202+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
203 #endif
204
205 /* For F_[GET|SET]FL. */
206diff --git a/libc/sysdeps/linux/metag/bits/fcntl.h b/libc/sysdeps/linux/metag/bits/fcntl.h
207index c4f641b..e10abd7 100644
208--- a/libc/sysdeps/linux/metag/bits/fcntl.h
209+++ b/libc/sysdeps/linux/metag/bits/fcntl.h
210@@ -100,6 +100,8 @@
211 # define F_NOTIFY 1026 /* Request notfications on a directory. */
212 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
213 close-on-exit set on new fd. */
214+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
215+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
216 #endif
217
218 /* For F_[GET|SET]FD. */
219diff --git a/libc/sysdeps/linux/microblaze/bits/fcntl.h b/libc/sysdeps/linux/microblaze/bits/fcntl.h
220index a2e3573..20b7597 100644
221--- a/libc/sysdeps/linux/microblaze/bits/fcntl.h
222+++ b/libc/sysdeps/linux/microblaze/bits/fcntl.h
223@@ -98,6 +98,8 @@
224 # define F_NOTIFY 1026 /* Request notfications on a directory. */
225 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
226 close-on-exit set on new fd. */
227+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
228+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
229 # define F_SETPIPE_SZ 1031 /* Set of pipe page size array */
230 # define F_GETPIPE_SZ 1032 /* Get of pipe page size array */
231 #endif
232diff --git a/libc/sysdeps/linux/mips/bits/fcntl.h b/libc/sysdeps/linux/mips/bits/fcntl.h
233index 4291f6e..8c4c115 100644
234--- a/libc/sysdeps/linux/mips/bits/fcntl.h
235+++ b/libc/sysdeps/linux/mips/bits/fcntl.h
236@@ -111,6 +111,8 @@
237 # define F_NOTIFY 1026 /* Request notfications on a directory. */
238 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
239 close-on-exit set on new fd. */
240+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
241+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
242 #endif
243
244 /* For F_[GET|SET]FL. */
245diff --git a/libc/sysdeps/linux/nios/bits/fcntl.h b/libc/sysdeps/linux/nios/bits/fcntl.h
246index 5854c18..36ca766 100644
247--- a/libc/sysdeps/linux/nios/bits/fcntl.h
248+++ b/libc/sysdeps/linux/nios/bits/fcntl.h
249@@ -96,6 +96,8 @@
250 # define F_NOTIFY 1026 /* Request notfications on a directory. */
251 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
252 close-on-exit set on new fd. */
253+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
254+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
255 #endif
256
257 /* For F_[GET|SET]FL. */
258diff --git a/libc/sysdeps/linux/nios2/bits/fcntl.h b/libc/sysdeps/linux/nios2/bits/fcntl.h
259index d7beb6c..66df337 100644
260--- a/libc/sysdeps/linux/nios2/bits/fcntl.h
261+++ b/libc/sysdeps/linux/nios2/bits/fcntl.h
262@@ -98,6 +98,8 @@
263 # define F_NOTIFY 1026 /* Request notfications on a directory. */
264 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
265 close-on-exit set on new fd. */
266+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
267+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
268 #endif
269
270 /* For F_[GET|SET]FL. */
271diff --git a/libc/sysdeps/linux/powerpc/bits/fcntl.h b/libc/sysdeps/linux/powerpc/bits/fcntl.h
272index 217f54a..d150a31 100644
273--- a/libc/sysdeps/linux/powerpc/bits/fcntl.h
274+++ b/libc/sysdeps/linux/powerpc/bits/fcntl.h
275@@ -99,6 +99,8 @@
276 # define F_NOTIFY 1026 /* Request notfications on a directory. */
277 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
278 close-on-exit set on new fd. */
279+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
280+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
281 #endif
282
283 /* For F_[GET|SET]FD. */
284diff --git a/libc/sysdeps/linux/sh/bits/fcntl.h b/libc/sysdeps/linux/sh/bits/fcntl.h
285index 5c9f047..aceaec6 100644
286--- a/libc/sysdeps/linux/sh/bits/fcntl.h
287+++ b/libc/sysdeps/linux/sh/bits/fcntl.h
288@@ -99,6 +99,8 @@
289 # define F_NOTIFY 1026 /* Request notfications on a directory. */
290 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
291 close-on-exit set on new fd. */
292+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
293+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
294 #endif
295
296 /* For F_[GET|SET]FD. */
297diff --git a/libc/sysdeps/linux/sh64/bits/fcntl.h b/libc/sysdeps/linux/sh64/bits/fcntl.h
298index ff741cb..b319e8b 100644
299--- a/libc/sysdeps/linux/sh64/bits/fcntl.h
300+++ b/libc/sysdeps/linux/sh64/bits/fcntl.h
301@@ -95,6 +95,8 @@
302 # define F_NOTIFY 1026 /* Request notfications on a directory. */
303 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
304 close-on-exit set on new fd. */
305+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
306+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
307 #endif
308
309 /* For F_[GET|SET]FL. */
310diff --git a/libc/sysdeps/linux/sparc/bits/fcntl.h b/libc/sysdeps/linux/sparc/bits/fcntl.h
311index 235d2ad..7e80d9e 100644
312--- a/libc/sysdeps/linux/sparc/bits/fcntl.h
313+++ b/libc/sysdeps/linux/sparc/bits/fcntl.h
314@@ -106,6 +106,8 @@
315 # define F_NOTIFY 1026 /* Request notfications on a directory. */
316 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
317 close-on-exit set on new fd. */
318+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
319+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
320 #endif
321
322 #if __WORDSIZE == 64
323diff --git a/libc/sysdeps/linux/v850/bits/fcntl.h b/libc/sysdeps/linux/v850/bits/fcntl.h
324index d0b8310..45deec4 100644
325--- a/libc/sysdeps/linux/v850/bits/fcntl.h
326+++ b/libc/sysdeps/linux/v850/bits/fcntl.h
327@@ -93,6 +93,8 @@
328 # define F_NOTIFY 1026 /* Request notfications on a directory. */
329 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
330 close-on-exit set on new fd. */
331+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
332+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
333 #endif
334
335 /* For F_[GET|SET]FL. */
336diff --git a/libc/sysdeps/linux/vax/bits/fcntl.h b/libc/sysdeps/linux/vax/bits/fcntl.h
337index ff5bff3..a30d5e1 100644
338--- a/libc/sysdeps/linux/vax/bits/fcntl.h
339+++ b/libc/sysdeps/linux/vax/bits/fcntl.h
340@@ -92,6 +92,8 @@
341 # define F_NOTIFY 1026 /* Request notfications on a directory. */
342 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
343 close-on-exit set on new fd. */
344+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
345+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
346 #endif
347
348 /* For F_[GET|SET]FL. */
349diff --git a/libc/sysdeps/linux/x86_64/bits/fcntl.h b/libc/sysdeps/linux/x86_64/bits/fcntl.h
350index a899dcf..02e011d 100644
351--- a/libc/sysdeps/linux/x86_64/bits/fcntl.h
352+++ b/libc/sysdeps/linux/x86_64/bits/fcntl.h
353@@ -113,6 +113,8 @@
354 # define F_NOTIFY 1026 /* Request notfications on a directory. */
355 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
356 close-on-exit set on new fd. */
357+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
358+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
359 #endif
360
361 /* For F_[GET|SET]FD. */
362diff --git a/libc/sysdeps/linux/xtensa/bits/fcntl.h b/libc/sysdeps/linux/xtensa/bits/fcntl.h
363index 5d28547..4e9aa7e 100644
364--- a/libc/sysdeps/linux/xtensa/bits/fcntl.h
365+++ b/libc/sysdeps/linux/xtensa/bits/fcntl.h
366@@ -99,6 +99,8 @@
367 # define F_NOTIFY 1026 /* Request notfications on a directory. */
368 # define F_DUPFD_CLOEXEC 1030 /* Duplicate file descriptor with
369 close-on-exit set on new fd. */
370+# define F_SETPIPE_SZ 1031 /* Set pipe page size array. */
371+# define F_GETPIPE_SZ 1032 /* Get pipe page size array. */
372 #endif
373
374 /* For F_[GET|SET]FD. */
375--
3761.9.0
377
diff --git a/meta/recipes-core/uclibc/uclibc-git/0004-Add-clock_adjtime-syscall.patch b/meta/recipes-core/uclibc/uclibc-git/0004-Add-clock_adjtime-syscall.patch
new file mode 100644
index 0000000000..3062ae4abc
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/0004-Add-clock_adjtime-syscall.patch
@@ -0,0 +1,73 @@
1From 8e19e651145554fbcb90179f3dfbc7ea8a07c900 Mon Sep 17 00:00:00 2001
2From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 15 Mar 2014 09:32:20 -0700
4Subject: [PATCH 4/4] Add clock_adjtime syscall
5
6Signed-off-by: Khem Raj <raj.khem@gmail.com>
7---
8 include/sys/timex.h | 5 ++++-
9 libc/sysdeps/linux/common/Makefile.in | 2 +-
10 libc/sysdeps/linux/common/clock_adjtime.c | 15 +++++++++++++++
11 3 files changed, 20 insertions(+), 2 deletions(-)
12 create mode 100644 libc/sysdeps/linux/common/clock_adjtime.c
13
14diff --git a/include/sys/timex.h b/include/sys/timex.h
15index 621afce..9082a28 100644
16--- a/include/sys/timex.h
17+++ b/include/sys/timex.h
18@@ -20,6 +20,7 @@
19
20 #include <features.h>
21 #include <sys/time.h>
22+#include <time.h>
23
24 /* These definitions from linux/timex.h as of 2.2.0. */
25
26@@ -125,7 +126,9 @@ libc_hidden_proto(adjtimex)
27 extern int ntp_gettime (struct ntptimeval *__ntv) __THROW;
28 extern int ntp_adjtime (struct timex *__tntx) __THROW;
29 #endif
30-
31+#if defined __UCLIBC_HAS_REALTIME__
32+extern int clock_adjtime (clockid_t __clock_id, struct timex *__ntx) __THROW;
33+#endif
34 __END_DECLS
35
36 #endif /* sys/timex.h */
37diff --git a/libc/sysdeps/linux/common/Makefile.in b/libc/sysdeps/linux/common/Makefile.in
38index 10d9884..bb985b6 100644
39--- a/libc/sysdeps/linux/common/Makefile.in
40+++ b/libc/sysdeps/linux/common/Makefile.in
41@@ -84,7 +84,7 @@ CSRC-$(ARCH_USE_MMU) += msync.c
42 CSRC-$(UCLIBC_BSD_SPECIFIC) += mincore.c setdomainname.c
43 CSRC-$(UCLIBC_NTP_LEGACY) += ntp_gettime.c
44 # aio_cancel|aio_error|aio_fsync|aio_read|aio_return|aio_suspend|aio_write|clock_getres|clock_gettime|clock_settime|clock_settime|fdatasync|lio_listio|mlockall|munlockall|mlock|munlock|mq_close|mq_getattr|mq_notify|mq_open|mq_receive|mq_timedreceive|mq_send|mq_timedsend|mq_setattr|mq_unlink|nanosleep|sched_getparam|sched_get_priority_max|sched_get_priority_min|sched_getscheduler|sched_rr_get_interval|sched_setparam|sched_setscheduler|sem_close|sem_destroy|sem_getvalue|sem_init|sem_open|sem_post|sem_trywait|sem_wait|sem_unlink|sem_wait|shm_open|shm_unlink|sigqueue|sigtimedwait|sigwaitinfo|timer_create|timer_delete|timer_getoverrun|timer_gettime|timer_settime
45-CSRC-$(UCLIBC_HAS_REALTIME) += clock_getres.c clock_gettime.c clock_settime.c \
46+CSRC-$(UCLIBC_HAS_REALTIME) += clock_adjtime.c clock_getres.c clock_gettime.c clock_settime.c \
47 fdatasync.c mlockall.c mlock.c munlockall.c munlock.c \
48 nanosleep.c __rt_sigtimedwait.c __rt_sigwaitinfo.c sched_getparam.c \
49 sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
50diff --git a/libc/sysdeps/linux/common/clock_adjtime.c b/libc/sysdeps/linux/common/clock_adjtime.c
51new file mode 100644
52index 0000000..968ec27
53--- /dev/null
54+++ b/libc/sysdeps/linux/common/clock_adjtime.c
55@@ -0,0 +1,15 @@
56+/*
57+ * clock_adjtime() for uClibc
58+ *
59+ * Copyright (C) 2005 by Peter Kjellerstedt <pkj@axis.com>
60+ * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
61+ *
62+ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
63+ */
64+
65+#include <sys/syscall.h>
66+#include <sys/timex.h>
67+
68+#ifdef __NR_clock_adjtime
69+_syscall2(int, clock_adjtime, clockid_t, clock_id, struct timex*, ntx)
70+#endif
71--
721.9.0
73
diff --git a/meta/recipes-core/uclibc/uclibc-git/argp-headers.patch b/meta/recipes-core/uclibc/uclibc-git/argp-headers.patch
new file mode 100644
index 0000000000..b31b991846
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/argp-headers.patch
@@ -0,0 +1,583 @@
1Added headers file needed by argp sources.
2
3Signed-off-by: Salvatore Cro <salvatore.cro at st.com>
4---
5 include/argp.h | 566 ++++++++++++++++++++++++++++++++++++++++++++
6 libc/argp/argp-fmtstream.h | 314 ++++++++++++++++++++++++
7 2 files changed, 880 insertions(+), 0 deletions(-)
8 create mode 100644 include/argp.h
9 create mode 100644 libc/argp/argp-fmtstream.h
10
11Upstream-Status: Pending
12
13Index: git/include/argp.h
14===================================================================
15--- /dev/null
16+++ git/include/argp.h
17@@ -0,0 +1,566 @@
18+/* Hierarchial argument parsing, layered over getopt.
19+ Copyright (C) 1995-1999, 2003, 2004, 2005, 2006, 2007, 2009
20+ Free Software Foundation, Inc.
21+ This file is part of the GNU C Library.
22+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
23+
24+ The GNU C Library is free software; you can redistribute it and/or
25+ modify it under the terms of the GNU Lesser General Public
26+ License as published by the Free Software Foundation; either
27+ version 2.1 of the License, or (at your option) any later version.
28+
29+ The GNU C Library is distributed in the hope that it will be useful,
30+ but WITHOUT ANY WARRANTY; without even the implied warranty of
31+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32+ Lesser General Public License for more details.
33+
34+ You should have received a copy of the GNU Lesser General Public
35+ License along with the GNU C Library; if not, write to the Free
36+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
37+ 02111-1307 USA.
38+
39+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
40+*/
41+
42+#ifndef _ARGP_H
43+#define _ARGP_H
44+
45+#include <stdio.h>
46+#include <ctype.h>
47+#include <limits.h>
48+
49+#define __need_error_t
50+#include <errno.h>
51+
52+#ifndef __const
53+# define __const const
54+#endif
55+
56+#ifndef __THROW
57+# define __THROW
58+#endif
59+#ifndef __NTH
60+# define __NTH(fct) fct __THROW
61+#endif
62+
63+#ifndef __attribute__
64+/* This feature is available in gcc versions 2.5 and later. */
65+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__)
66+# define __attribute__(Spec) /* empty */
67+# endif
68+/* The __-protected variants of `format' and `printf' attributes
69+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
70+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(__STRICT_ANSI__)
71+# define __format__ format
72+# define __printf__ printf
73+# endif
74+#endif
75+
76+/* GCC 2.95 and later have "__restrict"; C99 compilers have
77+ "restrict", and "configure" may have defined "restrict". */
78+#ifndef __restrict
79+# if ! (2 < __GNUC__ || (2 == __GNUC__ && 95 <= __GNUC_MINOR__))
80+# if defined restrict || 199901L <= __STDC_VERSION__
81+# define __restrict restrict
82+# else
83+# define __restrict
84+# endif
85+# endif
86+#endif
87+
88+#ifndef __error_t_defined
89+typedef int error_t;
90+# define __error_t_defined
91+#endif
92+
93+#ifdef __cplusplus
94+extern "C" {
95+#endif
96+
97+/* A description of a particular option. A pointer to an array of
98+ these is passed in the OPTIONS field of an argp structure. Each option
99+ entry can correspond to one long option and/or one short option; more
100+ names for the same option can be added by following an entry in an option
101+ array with options having the OPTION_ALIAS flag set. */
102+struct argp_option
103+{
104+ /* The long option name. For more than one name for the same option, you
105+ can use following options with the OPTION_ALIAS flag set. */
106+ __const char *name;
107+
108+ /* What key is returned for this option. If > 0 and printable, then it's
109+ also accepted as a short option. */
110+ int key;
111+
112+ /* If non-NULL, this is the name of the argument associated with this
113+ option, which is required unless the OPTION_ARG_OPTIONAL flag is set. */
114+ __const char *arg;
115+
116+ /* OPTION_ flags. */
117+ int flags;
118+
119+ /* The doc string for this option. If both NAME and KEY are 0, This string
120+ will be printed outdented from the normal option column, making it
121+ useful as a group header (it will be the first thing printed in its
122+ group); in this usage, it's conventional to end the string with a `:'. */
123+ __const char *doc;
124+
125+ /* The group this option is in. In a long help message, options are sorted
126+ alphabetically within each group, and the groups presented in the order
127+ 0, 1, 2, ..., n, -m, ..., -2, -1. Every entry in an options array with
128+ if this field 0 will inherit the group number of the previous entry, or
129+ zero if it's the first one, unless its a group header (NAME and KEY both
130+ 0), in which case, the previous entry + 1 is the default. Automagic
131+ options such as --help are put into group -1. */
132+ int group;
133+};
134+
135+/* The argument associated with this option is optional. */
136+#define OPTION_ARG_OPTIONAL 0x1
137+
138+/* This option isn't displayed in any help messages. */
139+#define OPTION_HIDDEN 0x2
140+
141+/* This option is an alias for the closest previous non-alias option. This
142+ means that it will be displayed in the same help entry, and will inherit
143+ fields other than NAME and KEY from the aliased option. */
144+#define OPTION_ALIAS 0x4
145+
146+/* This option isn't actually an option (and so should be ignored by the
147+ actual option parser), but rather an arbitrary piece of documentation that
148+ should be displayed in much the same manner as the options. If this flag
149+ is set, then the option NAME field is displayed unmodified (e.g., no `--'
150+ prefix is added) at the left-margin (where a *short* option would normally
151+ be displayed), and the documentation string in the normal place. For
152+ purposes of sorting, any leading whitespace and punctuation is ignored,
153+ except that if the first non-whitespace character is not `-', this entry
154+ is displayed after all options (and OPTION_DOC entries with a leading `-')
155+ in the same group. */
156+#define OPTION_DOC 0x8
157+
158+/* This option shouldn't be included in `long' usage messages (but is still
159+ included in help messages). This is mainly intended for options that are
160+ completely documented in an argp's ARGS_DOC field, in which case including
161+ the option in the generic usage list would be redundant. For instance,
162+ if ARGS_DOC is "FOO BAR\n-x BLAH", and the `-x' option's purpose is to
163+ distinguish these two cases, -x should probably be marked
164+ OPTION_NO_USAGE. */
165+#define OPTION_NO_USAGE 0x10
166+
167+struct argp; /* fwd declare this type */
168+struct argp_state; /* " */
169+struct argp_child; /* " */
170+
171+/* The type of a pointer to an argp parsing function. */
172+typedef error_t (*argp_parser_t) (int __key, char *__arg,
173+ struct argp_state *__state);
174+
175+/* What to return for unrecognized keys. For special ARGP_KEY_ keys, such
176+ returns will simply be ignored. For user keys, this error will be turned
177+ into EINVAL (if the call to argp_parse is such that errors are propagated
178+ back to the user instead of exiting); returning EINVAL itself would result
179+ in an immediate stop to parsing in *all* cases. */
180+#define ARGP_ERR_UNKNOWN E2BIG /* Hurd should never need E2BIG. XXX */
181+
182+/* Special values for the KEY argument to an argument parsing function.
183+ ARGP_ERR_UNKNOWN should be returned if they aren't understood.
184+
185+ The sequence of keys to a parsing function is either (where each
186+ uppercased word should be prefixed by `ARGP_KEY_' and opt is a user key):
187+
188+ INIT opt... NO_ARGS END SUCCESS -- No non-option arguments at all
189+ or INIT (opt | ARG)... END SUCCESS -- All non-option args parsed
190+ or INIT (opt | ARG)... SUCCESS -- Some non-option arg unrecognized
191+
192+ The third case is where every parser returned ARGP_KEY_UNKNOWN for an
193+ argument, in which case parsing stops at that argument (returning the
194+ unparsed arguments to the caller of argp_parse if requested, or stopping
195+ with an error message if not).
196+
197+ If an error occurs (either detected by argp, or because the parsing
198+ function returned an error value), then the parser is called with
199+ ARGP_KEY_ERROR, and no further calls are made. */
200+
201+/* This is not an option at all, but rather a command line argument. If a
202+ parser receiving this key returns success, the fact is recorded, and the
203+ ARGP_KEY_NO_ARGS case won't be used. HOWEVER, if while processing the
204+ argument, a parser function decrements the NEXT field of the state it's
205+ passed, the option won't be considered processed; this is to allow you to
206+ actually modify the argument (perhaps into an option), and have it
207+ processed again. */
208+#define ARGP_KEY_ARG 0
209+/* There are remaining arguments not parsed by any parser, which may be found
210+ starting at (STATE->argv + STATE->next). If success is returned, but
211+ STATE->next left untouched, it's assumed that all arguments were consume,
212+ otherwise, the parser should adjust STATE->next to reflect any arguments
213+ consumed. */
214+#define ARGP_KEY_ARGS 0x1000006
215+/* There are no more command line arguments at all. */
216+#define ARGP_KEY_END 0x1000001
217+/* Because it's common to want to do some special processing if there aren't
218+ any non-option args, user parsers are called with this key if they didn't
219+ successfully process any non-option arguments. Called just before
220+ ARGP_KEY_END (where more general validity checks on previously parsed
221+ arguments can take place). */
222+#define ARGP_KEY_NO_ARGS 0x1000002
223+/* Passed in before any parsing is done. Afterwards, the values of each
224+ element of the CHILD_INPUT field, if any, in the state structure is
225+ copied to each child's state to be the initial value of the INPUT field. */
226+#define ARGP_KEY_INIT 0x1000003
227+/* Use after all other keys, including SUCCESS & END. */
228+#define ARGP_KEY_FINI 0x1000007
229+/* Passed in when parsing has successfully been completed (even if there are
230+ still arguments remaining). */
231+#define ARGP_KEY_SUCCESS 0x1000004
232+/* Passed in if an error occurs. */
233+#define ARGP_KEY_ERROR 0x1000005
234+
235+/* An argp structure contains a set of options declarations, a function to
236+ deal with parsing one, documentation string, a possible vector of child
237+ argp's, and perhaps a function to filter help output. When actually
238+ parsing options, getopt is called with the union of all the argp
239+ structures chained together through their CHILD pointers, with conflicts
240+ being resolved in favor of the first occurrence in the chain. */
241+struct argp
242+{
243+ /* An array of argp_option structures, terminated by an entry with both
244+ NAME and KEY having a value of 0. */
245+ __const struct argp_option *options;
246+
247+ /* What to do with an option from this structure. KEY is the key
248+ associated with the option, and ARG is any associated argument (NULL if
249+ none was supplied). If KEY isn't understood, ARGP_ERR_UNKNOWN should be
250+ returned. If a non-zero, non-ARGP_ERR_UNKNOWN value is returned, then
251+ parsing is stopped immediately, and that value is returned from
252+ argp_parse(). For special (non-user-supplied) values of KEY, see the
253+ ARGP_KEY_ definitions below. */
254+ argp_parser_t parser;
255+
256+ /* A string describing what other arguments are wanted by this program. It
257+ is only used by argp_usage to print the `Usage:' message. If it
258+ contains newlines, the strings separated by them are considered
259+ alternative usage patterns, and printed on separate lines (lines after
260+ the first are prefix by ` or: ' instead of `Usage:'). */
261+ __const char *args_doc;
262+
263+ /* If non-NULL, a string containing extra text to be printed before and
264+ after the options in a long help message (separated by a vertical tab
265+ `\v' character). */
266+ __const char *doc;
267+
268+ /* A vector of argp_children structures, terminated by a member with a 0
269+ argp field, pointing to child argps should be parsed with this one. Any
270+ conflicts are resolved in favor of this argp, or early argps in the
271+ CHILDREN list. This field is useful if you use libraries that supply
272+ their own argp structure, which you want to use in conjunction with your
273+ own. */
274+ __const struct argp_child *children;
275+
276+ /* If non-zero, this should be a function to filter the output of help
277+ messages. KEY is either a key from an option, in which case TEXT is
278+ that option's help text, or a special key from the ARGP_KEY_HELP_
279+ defines, below, describing which other help text TEXT is. The function
280+ should return either TEXT, if it should be used as-is, a replacement
281+ string, which should be malloced, and will be freed by argp, or NULL,
282+ meaning `print nothing'. The value for TEXT is *after* any translation
283+ has been done, so if any of the replacement text also needs translation,
284+ that should be done by the filter function. INPUT is either the input
285+ supplied to argp_parse, or NULL, if argp_help was called directly. */
286+ char *(*help_filter) (int __key, __const char *__text, void *__input);
287+
288+ /* If non-zero the strings used in the argp library are translated using
289+ the domain described by this string. Otherwise the currently installed
290+ default domain is used. */
291+ const char *argp_domain;
292+};
293+
294+/* Possible KEY arguments to a help filter function. */
295+#define ARGP_KEY_HELP_PRE_DOC 0x2000001 /* Help text preceeding options. */
296+#define ARGP_KEY_HELP_POST_DOC 0x2000002 /* Help text following options. */
297+#define ARGP_KEY_HELP_HEADER 0x2000003 /* Option header string. */
298+#define ARGP_KEY_HELP_EXTRA 0x2000004 /* After all other documentation;
299+ TEXT is NULL for this key. */
300+/* Explanatory note emitted when duplicate option arguments have been
301+ suppressed. */
302+#define ARGP_KEY_HELP_DUP_ARGS_NOTE 0x2000005
303+#define ARGP_KEY_HELP_ARGS_DOC 0x2000006 /* Argument doc string. */
304+
305+/* When an argp has a non-zero CHILDREN field, it should point to a vector of
306+ argp_child structures, each of which describes a subsidiary argp. */
307+struct argp_child
308+{
309+ /* The child parser. */
310+ __const struct argp *argp;
311+
312+ /* Flags for this child. */
313+ int flags;
314+
315+ /* If non-zero, an optional header to be printed in help output before the
316+ child options. As a side-effect, a non-zero value forces the child
317+ options to be grouped together; to achieve this effect without actually
318+ printing a header string, use a value of "". */
319+ __const char *header;
320+
321+ /* Where to group the child options relative to the other (`consolidated')
322+ options in the parent argp; the values are the same as the GROUP field
323+ in argp_option structs, but all child-groupings follow parent options at
324+ a particular group level. If both this field and HEADER are zero, then
325+ they aren't grouped at all, but rather merged with the parent options
326+ (merging the child's grouping levels with the parents). */
327+ int group;
328+};
329+
330+/* Parsing state. This is provided to parsing functions called by argp,
331+ which may examine and, as noted, modify fields. */
332+struct argp_state
333+{
334+ /* The top level ARGP being parsed. */
335+ __const struct argp *root_argp;
336+
337+ /* The argument vector being parsed. May be modified. */
338+ int argc;
339+ char **argv;
340+
341+ /* The index in ARGV of the next arg that to be parsed. May be modified. */
342+ int next;
343+
344+ /* The flags supplied to argp_parse. May be modified. */
345+ unsigned flags;
346+
347+ /* While calling a parsing function with a key of ARGP_KEY_ARG, this is the
348+ number of the current arg, starting at zero, and incremented after each
349+ such call returns. At all other times, this is the number of such
350+ arguments that have been processed. */
351+ unsigned arg_num;
352+
353+ /* If non-zero, the index in ARGV of the first argument following a special
354+ `--' argument (which prevents anything following being interpreted as an
355+ option). Only set once argument parsing has proceeded past this point. */
356+ int quoted;
357+
358+ /* An arbitrary pointer passed in from the user. */
359+ void *input;
360+ /* Values to pass to child parsers. This vector will be the same length as
361+ the number of children for the current parser. */
362+ void **child_inputs;
363+
364+ /* For the parser's use. Initialized to 0. */
365+ void *hook;
366+
367+ /* The name used when printing messages. This is initialized to ARGV[0],
368+ or PROGRAM_INVOCATION_NAME if that is unavailable. */
369+ char *name;
370+
371+ /* Streams used when argp prints something. */
372+ FILE *err_stream; /* For errors; initialized to stderr. */
373+ FILE *out_stream; /* For information; initialized to stdout. */
374+
375+ void *pstate; /* Private, for use by argp. */
376+};
377+
378+/* Flags for argp_parse (note that the defaults are those that are
379+ convenient for program command line parsing): */
380+
381+/* Don't ignore the first element of ARGV. Normally (and always unless
382+ ARGP_NO_ERRS is set) the first element of the argument vector is
383+ skipped for option parsing purposes, as it corresponds to the program name
384+ in a command line. */
385+#define ARGP_PARSE_ARGV0 0x01
386+
387+/* Don't print error messages for unknown options to stderr; unless this flag
388+ is set, ARGP_PARSE_ARGV0 is ignored, as ARGV[0] is used as the program
389+ name in the error messages. This flag implies ARGP_NO_EXIT (on the
390+ assumption that silent exiting upon errors is bad behaviour). */
391+#define ARGP_NO_ERRS 0x02
392+
393+/* Don't parse any non-option args. Normally non-option args are parsed by
394+ calling the parse functions with a key of ARGP_KEY_ARG, and the actual arg
395+ as the value. Since it's impossible to know which parse function wants to
396+ handle it, each one is called in turn, until one returns 0 or an error
397+ other than ARGP_ERR_UNKNOWN; if an argument is handled by no one, the
398+ argp_parse returns prematurely (but with a return value of 0). If all
399+ args have been parsed without error, all parsing functions are called one
400+ last time with a key of ARGP_KEY_END. This flag needn't normally be set,
401+ as the normal behavior is to stop parsing as soon as some argument can't
402+ be handled. */
403+#define ARGP_NO_ARGS 0x04
404+
405+/* Parse options and arguments in the same order they occur on the command
406+ line -- normally they're rearranged so that all options come first. */
407+#define ARGP_IN_ORDER 0x08
408+
409+/* Don't provide the standard long option --help, which causes usage and
410+ option help information to be output to stdout, and exit (0) called. */
411+#define ARGP_NO_HELP 0x10
412+
413+/* Don't exit on errors (they may still result in error messages). */
414+#define ARGP_NO_EXIT 0x20
415+
416+/* Use the gnu getopt `long-only' rules for parsing arguments. */
417+#define ARGP_LONG_ONLY 0x40
418+
419+/* Turns off any message-printing/exiting options. */
420+#define ARGP_SILENT (ARGP_NO_EXIT | ARGP_NO_ERRS | ARGP_NO_HELP)
421+
422+/* Parse the options strings in ARGC & ARGV according to the options in ARGP.
423+ FLAGS is one of the ARGP_ flags above. If ARG_INDEX is non-NULL, the
424+ index in ARGV of the first unparsed option is returned in it. If an
425+ unknown option is present, ARGP_ERR_UNKNOWN is returned; if some parser
426+ routine returned a non-zero value, it is returned; otherwise 0 is
427+ returned. This function may also call exit unless the ARGP_NO_HELP flag
428+ is set. INPUT is a pointer to a value to be passed in to the parser. */
429+extern error_t argp_parse (__const struct argp *__restrict __argp,
430+ int __argc, char **__restrict __argv,
431+ unsigned __flags, int *__restrict __arg_index,
432+ void *__restrict __input);
433+
434+/* Global variables. */
435+
436+/* If defined or set by the user program to a non-zero value, then a default
437+ option --version is added (unless the ARGP_NO_HELP flag is used), which
438+ will print this string followed by a newline and exit (unless the
439+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
440+extern __const char *argp_program_version;
441+
442+/* If defined or set by the user program to a non-zero value, then a default
443+ option --version is added (unless the ARGP_NO_HELP flag is used), which
444+ calls this function with a stream to print the version to and a pointer to
445+ the current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
446+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
447+extern void (*argp_program_version_hook) (FILE *__restrict __stream,
448+ struct argp_state *__restrict
449+ __state);
450+
451+/* If defined or set by the user program, it should point to string that is
452+ the bug-reporting address for the program. It will be printed by
453+ argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various
454+ standard help messages), embedded in a sentence that says something like
455+ `Report bugs to ADDR.'. */
456+extern __const char *argp_program_bug_address;
457+
458+/* The exit status that argp will use when exiting due to a parsing error.
459+ If not defined or set by the user program, this defaults to EX_USAGE from
460+ <sysexits.h>. */
461+extern error_t argp_err_exit_status;
462+
463+/* Flags for argp_help. */
464+#define ARGP_HELP_USAGE 0x01 /* a Usage: message. */
465+#define ARGP_HELP_SHORT_USAGE 0x02 /* " but don't actually print options. */
466+#define ARGP_HELP_SEE 0x04 /* a `Try ... for more help' message. */
467+#define ARGP_HELP_LONG 0x08 /* a long help message. */
468+#define ARGP_HELP_PRE_DOC 0x10 /* doc string preceding long help. */
469+#define ARGP_HELP_POST_DOC 0x20 /* doc string following long help. */
470+#define ARGP_HELP_DOC (ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)
471+#define ARGP_HELP_BUG_ADDR 0x40 /* bug report address */
472+#define ARGP_HELP_LONG_ONLY 0x80 /* modify output appropriately to
473+ reflect ARGP_LONG_ONLY mode. */
474+
475+/* These ARGP_HELP flags are only understood by argp_state_help. */
476+#define ARGP_HELP_EXIT_ERR 0x100 /* Call exit(1) instead of returning. */
477+#define ARGP_HELP_EXIT_OK 0x200 /* Call exit(0) instead of returning. */
478+
479+/* The standard thing to do after a program command line parsing error, if an
480+ error message has already been printed. */
481+#define ARGP_HELP_STD_ERR \
482+ (ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
483+/* The standard thing to do after a program command line parsing error, if no
484+ more specific error message has been printed. */
485+#define ARGP_HELP_STD_USAGE \
486+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_SEE | ARGP_HELP_EXIT_ERR)
487+/* The standard thing to do in response to a --help option. */
488+#define ARGP_HELP_STD_HELP \
489+ (ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG | ARGP_HELP_EXIT_OK \
490+ | ARGP_HELP_DOC | ARGP_HELP_BUG_ADDR)
491+
492+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
493+ ARGP_HELP_*. */
494+extern void argp_help (__const struct argp *__restrict __argp,
495+ FILE *__restrict __stream,
496+ unsigned __flags, char *__restrict __name);
497+
498+/* The following routines are intended to be called from within an argp
499+ parsing routine (thus taking an argp_state structure as the first
500+ argument). They may or may not print an error message and exit, depending
501+ on the flags in STATE -- in any case, the caller should be prepared for
502+ them *not* to exit, and should return an appropiate error after calling
503+ them. [argp_usage & argp_error should probably be called argp_state_...,
504+ but they're used often enough that they should be short] */
505+
506+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
507+ from the set ARGP_HELP_*. */
508+extern void argp_state_help (__const struct argp_state *__restrict __state,
509+ FILE *__restrict __stream,
510+ unsigned int __flags);
511+/* Possibly output the standard usage message for ARGP to stderr and exit. */
512+extern void argp_usage (__const struct argp_state *__state);
513+
514+/* If appropriate, print the printf string FMT and following args, preceded
515+ by the program name and `:', to stderr, and followed by a `Try ... --help'
516+ message, then exit (1). */
517+extern void argp_error (__const struct argp_state *__restrict __state,
518+ __const char *__restrict __fmt, ...)
519+ __attribute__ ((__format__ (__printf__, 2, 3)));
520+/* Similar to the standard gnu error-reporting function error(), but will
521+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
522+ to STATE->err_stream. This is useful for argument parsing code that is
523+ shared between program startup (when exiting is desired) and runtime
524+ option parsing (when typically an error code is returned instead). The
525+ difference between this function and argp_error is that the latter is for
526+ *parsing errors*, and the former is for other problems that occur during
527+ parsing but don't reflect a (syntactic) problem with the input. */
528+extern void argp_failure (__const struct argp_state *__restrict __state,
529+ int __status, int __errnum,
530+ __const char *__restrict __fmt, ...)
531+ __attribute__ ((__format__ (__printf__, 4, 5)));
532+/* Returns true if the option OPT is a valid short option. */
533+extern int _option_is_short (__const struct argp_option *__opt) __THROW;
534+extern int __option_is_short (__const struct argp_option *__opt) __THROW;
535+
536+/* Returns true if the option OPT is in fact the last (unused) entry in an
537+ options array. */
538+extern int _option_is_end (__const struct argp_option *__opt) __THROW;
539+extern int __option_is_end (__const struct argp_option *__opt) __THROW;
540+
541+/* Return the input field for ARGP in the parser corresponding to STATE; used
542+ by the help routines. */
543+/* We think this should not be exported */
544+extern void *__argp_input (__const struct argp *__restrict __argp,
545+ __const struct argp_state *__restrict __state)
546+ __THROW;
547+
548+#ifdef __USE_EXTERN_INLINES
549+
550+# ifndef ARGP_EI
551+# define ARGP_EI __extern_inline
552+# endif
553+
554+ARGP_EI void
555+argp_usage (__const struct argp_state *__state)
556+{
557+ argp_state_help (__state, stderr, ARGP_HELP_STD_USAGE);
558+}
559+
560+ARGP_EI int
561+__NTH (__option_is_short (__const struct argp_option *__opt))
562+{
563+ if (__opt->flags & OPTION_DOC)
564+ return 0;
565+ else
566+ {
567+ int __key = __opt->key;
568+ return __key > 0 && __key <= UCHAR_MAX && isprint (__key);
569+ }
570+}
571+
572+ARGP_EI int
573+__NTH (__option_is_end (__const struct argp_option *__opt))
574+{
575+ return !__opt->key && !__opt->name && !__opt->doc && !__opt->group;
576+}
577+#endif /* Use extern inlines. */
578+
579+#ifdef __cplusplus
580+}
581+#endif
582+
583+#endif /* argp.h */
diff --git a/meta/recipes-core/uclibc/uclibc-git/argp-support.patch b/meta/recipes-core/uclibc/uclibc-git/argp-support.patch
new file mode 100644
index 0000000000..bcec6a593a
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/argp-support.patch
@@ -0,0 +1,5192 @@
1From: Salvatore Cro <salvatore.cro at st.com>
2
3Argp is an advanced support for parsing unix-style argument vectors.
4In addition to the common getopt interface, it provides automatic response
5to `--help' and `--version' options and use of custom parser in conjunction
6with argp native option parser, among others.
7Argp support is required by elfutils package and prelink.
8
9In uClibc argp functionalities has been moved from C library to libuargp.so
10Further the libc.so linker script contains an AS_NEEDED entry so that
11it doesn't need to link libuargp.so explicitely.
12
13Signed-off-by: Salvatore Cro <salvatore.cro at st.com>
14Signed-off-by: Filippo Arcidiacono <filippo.arcidiacono at st.com>
15Signed-off-by: Carmelo Amoroso <carmelo.amoroso at st.com>
16
17Upstream-Status: Pending
18
19---
20 Makefile.in | 8 +
21 Makerules | 8 +-
22 Rules.mak | 7 +
23 extra/Configs/Config.in | 17 +
24 libc/sysdeps/linux/common/bits/getopt_int.h | 136 ++
25 libc/unistd/getopt.c | 18 +-
26 libc/unistd/getopt_int.h | 134 --
27 libuargp/Makefile | 14 +
28 libuargp/Makefile.in | 76 ++
29 libuargp/argp-ba.c | 26 +
30 libuargp/argp-eexst.c | 32 +
31 libuargp/argp-fmtstream.c | 439 +++++++
32 libuargp/argp-fmtstream.h | 314 +++++
33 libuargp/argp-fs-xinl.c | 44 +
34 libuargp/argp-help.c | 1882 +++++++++++++++++++++++++++
35 libuargp/argp-parse.c | 949 ++++++++++++++
36 libuargp/argp-pv.c | 25 +
37 libuargp/argp-pvh.c | 32 +
38 libuargp/argp-xinl.c | 35 +
39 test/argp/Makefile | 7 +
40 test/argp/Makefile.in | 12 +
41 test/argp/argp-ex1.c | 15 +
42 test/argp/argp-ex2.c | 45 +
43 test/argp/argp-ex3.c | 153 +++
44 test/argp/argp-ex4.c | 167 +++
45 test/argp/argp-test.c | 209 +++
46 test/argp/bug-argp1.c | 26 +
47 test/argp/tst-argp1.c | 118 ++
48 test/argp/tst-argp2.c | 101 ++
49 29 files changed, 4911 insertions(+), 138 deletions(-)
50 create mode 100644 libc/sysdeps/linux/common/bits/getopt_int.h
51 delete mode 100644 libc/unistd/getopt_int.h
52 create mode 100644 libuargp/Makefile
53 create mode 100644 libuargp/Makefile.in
54 create mode 100644 libuargp/argp-ba.c
55 create mode 100644 libuargp/argp-eexst.c
56 create mode 100644 libuargp/argp-fmtstream.c
57 create mode 100644 libuargp/argp-fmtstream.h
58 create mode 100644 libuargp/argp-fs-xinl.c
59 create mode 100644 libuargp/argp-help.c
60 create mode 100644 libuargp/argp-parse.c
61 create mode 100644 libuargp/argp-pv.c
62 create mode 100644 libuargp/argp-pvh.c
63 create mode 100644 libuargp/argp-xinl.c
64 create mode 100644 test/argp/Makefile
65 create mode 100644 test/argp/Makefile.in
66 create mode 100644 test/argp/argp-ex1.c
67 create mode 100644 test/argp/argp-ex2.c
68 create mode 100644 test/argp/argp-ex3.c
69 create mode 100644 test/argp/argp-ex4.c
70 create mode 100644 test/argp/argp-test.c
71 create mode 100644 test/argp/bug-argp1.c
72 create mode 100644 test/argp/tst-argp1.c
73 create mode 100644 test/argp/tst-argp2.c
74
75Index: git/Makefile.in
76===================================================================
77--- git.orig/Makefile.in 2012-06-18 13:10:12.000000000 -0700
78+++ git/Makefile.in 2012-06-18 13:12:06.448829343 -0700
79@@ -48,6 +48,7 @@
80 include $(top_srcdir)libutil/Makefile.in
81 include $(top_srcdir)libpthread/Makefile.in
82 include $(top_srcdir)librt/Makefile.in
83+include $(top_srcdir)libuargp/Makefile.in
84 include $(top_srcdir)libubacktrace/Makefile.in
85 include $(top_srcdir)extra/locale/Makefile.in
86
87@@ -250,6 +251,7 @@
88 endif
89 HEADERS_RM-$(HAVE_SHARED) += dlfcn.h bits/dlfcn.h
90 HEADERS_RM-$(PTHREADS_DEBUG_SUPPORT) += thread_db.h
91+HEADERS_RM-$(UCLIBC_HAS_ARGP) += argp.h
92 HEADERS_RM-$(UCLIBC_HAS_BSD_ERR) += err.h
93 HEADERS_RM-$(UCLIBC_HAS_CRYPT) += crypt.h
94 HEADERS_RM-$(UCLIBC_HAS_EPOLL) += sys/epoll.h
95@@ -368,6 +370,12 @@
96 -$(INSTALL) -m 755 $(top_builddir)lib/libc.so $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/
97 endif
98 echo "$(UBACKTRACE_ASNEEDED)" >> $(PREFIX)$(DEVEL_PREFIX)$(MULTILIB_DIR)/libc.so
99+ifeq ($(UCLIBC_HAS_ARGP),y)
100+# Add the AS_NEEDED entry for libuargp.so
101+ if [ -f $(top_builddir)lib/libc.so -a -f $(PREFIX)$(RUNTIME_PREFIX)lib/$(SHARED_MAJORNAME) ] ; then \
102+ echo "GROUP ( $(UARGP_ASNEEDED) )" >> $(PREFIX)$(DEVEL_PREFIX)lib/libc.so; \
103+ fi
104+endif
105 ifeq ($(UCLIBC_HAS_THREADS),y)
106 ifneq ($(LINUXTHREADS_OLD),y)
107 ifeq ($(HARDWIRED_ABSPATH),y)
108Index: git/Makerules
109===================================================================
110--- git.orig/Makerules 2012-06-18 13:10:12.000000000 -0700
111+++ git/Makerules 2012-06-18 13:10:44.052825547 -0700
112@@ -32,12 +32,12 @@
113 $(libpthread-so-y) $(libpthread-nonshared-y) $(libthread_db-so-y) \
114 $(libresolv-so-y) $(librt-so-y) \
115 $(ldso-y) \
116- $(libutil-so-y) $(libubacktrace-so-y)
117+ $(libutil-so-y) $(libubacktrace-so-y) $(libuargp-so-y)
118
119 ar_objs = $(libc-y) $(libc-static-y) $(libcrypt-a-y) \
120 $(libdl-a-y) $(libintl-a-y) $(libm-a-y) $(libnsl-a-y) \
121 $(libpthread-a-y) $(libthread_db-a-y) \
122- $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y)
123+ $(libresolv-a-y) $(librt-a-y) $(libutil-a-y) $(libubacktrace-a-y) $(libuargp-a-y)
124 ifeq ($(DOPIC),y)
125 ar_objs := $(ar_objs:.o=.os)
126 endif
127@@ -472,7 +472,7 @@
128 $(librt-a-y) $(librt-so-y) $(libresolv-a-y) $(libresolv-so-y) \
129 $(libcrypt-a-y) $(libcrypt-so-y) $(libutil-a-y) $(libutil-so-y) \
130 $(libnsl-a-y) $(libnsl-so-y) $(ldso-y) $(libdl-a-y) $(libdl-so-y) \
131- $(libubacktrace-a-y) $(libubacktrace-so-y)
132+ $(libubacktrace-a-y) $(libubacktrace-so-y) $(libuargp-so-y) $(libuargp-a-y)
133 .depends.dep := \
134 $(patsubst %.s,%.s.dep,$(filter %.s,$(files.dep))) \
135 $(patsubst %.o,%.o.dep,$(filter %.o,$(files.dep))) \
136Index: git/Rules.mak
137===================================================================
138--- git.orig/Rules.mak 2012-06-18 13:10:12.000000000 -0700
139+++ git/Rules.mak 2012-06-18 13:10:44.056825544 -0700
140@@ -589,6 +589,13 @@
141 else
142 export UBACKTRACE_ASNEEDED:=""
143 endif
144+ifeq ($(UCLIBC_HAS_ARGP),y)
145+# Only used in installed libc.so linker script
146+UARGP_FULL_NAME := $(RUNTIME_PREFIX)lib/libuargp.so.$(MAJOR_VERSION)
147+export UARGP_ASNEEDED:=$(shell $(LD) --help 2>/dev/null | grep -q -- --as-needed && echo "AS_NEEDED ( $(UARGP_FULL_NAME) )" || echo "$(UARGP_FULL_NAME)")
148+else
149+export UARGP_ASNEEDED:=""
150+endif
151 endif
152
153 # Add a bunch of extra pedantic annoyingly strict checks
154Index: git/extra/Configs/Config.in
155===================================================================
156--- git.orig/extra/Configs/Config.in 2012-06-18 13:10:12.000000000 -0700
157+++ git/extra/Configs/Config.in 2012-06-18 13:10:44.056825544 -0700
158@@ -1853,6 +1853,23 @@
159 smaller SUSv3 compatible getsubopt().
160
161 Most people will answer Y.
162+
163+config UCLIBC_HAS_ARGP
164+ bool "Support argp (as standalone shared object)"
165+ default n
166+ help
167+ Argp is an interface for parsing unix-style argument vectors. Unlike
168+ the common getopt interface, it provides many advanced features in
169+ addition to parsing options, such as automatic output in response to
170+ `--help' and `--version' options.
171+ A library can export an argp option parser, which programs can easily
172+ use in conjunction with their own option parser.
173+ A new shared object "libuargp" is created. The "libc.so" linker script
174+ contains the AS_NEEDED entry for getting the libuargp linked automatically.
175+ Argp support is needed by elfutils libdw.
176+
177+ Most people can safely answer N.
178+
179 endmenu
180
181
182Index: git/libc/sysdeps/linux/common/bits/getopt_int.h
183===================================================================
184--- /dev/null 1970-01-01 00:00:00.000000000 +0000
185+++ git/libc/sysdeps/linux/common/bits/getopt_int.h 2012-06-18 13:10:44.056825544 -0700
186@@ -0,0 +1,136 @@
187+/* Internal declarations for getopt.
188+ Copyright (C) 1989-1994,1996-1999,2001,2003,2004
189+ Free Software Foundation, Inc.
190+ This file is part of the GNU C Library.
191+
192+ The GNU C Library is free software; you can redistribute it and/or
193+ modify it under the terms of the GNU Lesser General Public
194+ License as published by the Free Software Foundation; either
195+ version 2.1 of the License, or (at your option) any later version.
196+
197+ The GNU C Library is distributed in the hope that it will be useful,
198+ but WITHOUT ANY WARRANTY; without even the implied warranty of
199+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
200+ Lesser General Public License for more details.
201+
202+ You should have received a copy of the GNU Lesser General Public
203+ License along with the GNU C Library; if not, write to the Free
204+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
205+ 02111-1307 USA. */
206+
207+#ifndef _GETOPT_INT_H
208+#define _GETOPT_INT_H 1
209+
210+extern int _getopt_internal (int ___argc, char *const *___argv,
211+ const char *__shortopts,
212+ const struct option *__longopts, int *__longind,
213+ int __long_only) attribute_hidden;
214+
215+
216+/* Reentrant versions which can handle parsing multiple argument
217+ vectors at the same time. */
218+
219+/* For __ordering member */
220+enum {
221+ REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER
222+};
223+
224+/* Data type for reentrant functions. */
225+
226+struct _getopt_data
227+{
228+ /* These have exactly the same meaning as the corresponding global
229+ variables, except that they are used for the reentrant
230+ versions of getopt. */
231+ int optind;
232+ int opterr;
233+ char *optarg;
234+ smalluint optopt; /* we store characters here, a byte is enough */
235+
236+ /* Internal members. */
237+
238+ /* True if the internal members have been initialized. */
239+ smallint __initialized;
240+
241+ /* Describe how to deal with options that follow non-option ARGV-elements.
242+
243+ If the caller did not specify anything,
244+ the default is REQUIRE_ORDER if the environment variable
245+ POSIXLY_CORRECT is defined, PERMUTE otherwise.
246+
247+ REQUIRE_ORDER means don't recognize them as options;
248+ stop option processing when the first non-option is seen.
249+ This is what Unix does.
250+ This mode of operation is selected by either setting the environment
251+ variable POSIXLY_CORRECT, or using `+' as the first character
252+ of the list of option characters.
253+
254+ PERMUTE is the default. We permute the contents of ARGV as we
255+ scan, so that eventually all the non-options are at the end.
256+ This allows options to be given in any order, even with programs
257+ that were not written to expect this.
258+
259+ RETURN_IN_ORDER is an option available to programs that were
260+ written to expect options and other ARGV-elements in any order
261+ and that care about the ordering of the two. We describe each
262+ non-option ARGV-element as if it were the argument of an option
263+ with character code 1. Using `-' as the first character of the
264+ list of option characters selects this mode of operation.
265+
266+ The special argument `--' forces an end of option-scanning regardless
267+ of the value of `ordering'. In the case of RETURN_IN_ORDER, only
268+ `--' can cause `getopt' to return -1 with `optind' != ARGC. */
269+ smallint __ordering;
270+
271+ /* If the POSIXLY_CORRECT environment variable is set. */
272+ smallint __posixly_correct;
273+
274+ /* The next char to be scanned in the option-element
275+ in which the last option character we returned was found.
276+ This allows us to pick up the scan where we left off.
277+
278+ If this is zero, or a null string, it means resume the scan
279+ by advancing to the next ARGV-element. */
280+ char *__nextchar;
281+
282+
283+ /* Handle permutation of arguments. */
284+
285+ /* Describe the part of ARGV that contains non-options that have
286+ been skipped. `first_nonopt' is the index in ARGV of the first
287+ of them; `last_nonopt' is the index after the last of them. */
288+
289+ int __first_nonopt;
290+ int __last_nonopt;
291+
292+#if defined _LIBC && defined USE_NONOPTION_FLAGS
293+ int __nonoption_flags_max_len;
294+ int __nonoption_flags_len;
295+# endif
296+};
297+
298+/* The initializer is necessary to set OPTIND and OPTERR to their
299+ default values and to clear the initialization flag. */
300+#define _GETOPT_DATA_INITIALIZER { 1, 1 }
301+
302+#if 0 /* first is static on uClibc, the others not used */
303+extern int _getopt_internal_r (int ___argc, char *const *___argv,
304+ const char *__shortopts,
305+ const struct option *__longopts, int *__longind,
306+ int __long_only, struct _getopt_data *__data);
307+#endif
308+#if defined __UCLIBC_HAS_GNU_GETOPT__ || defined __UCLIBC_HAS_GETOPT_LONG__
309+#ifndef __need_getopt
310+extern int _getopt_long_r (int ___argc, char *const *___argv,
311+ const char *__shortopts,
312+ const struct option *__longopts, int *__longind,
313+ struct _getopt_data *__data);
314+
315+extern int _getopt_long_only_r (int ___argc, char *const *___argv,
316+ const char *__shortopts,
317+ const struct option *__longopts,
318+ int *__longind,
319+ struct _getopt_data *__data);
320+#endif
321+#endif
322+#endif /* getopt_int.h */
323Index: git/libc/unistd/getopt.c
324===================================================================
325--- git.orig/libc/unistd/getopt.c 2012-06-18 13:10:12.000000000 -0700
326+++ git/libc/unistd/getopt.c 2012-06-18 13:10:44.056825544 -0700
327@@ -106,7 +106,7 @@
328 they can distinguish the relative order of options and other arguments. */
329
330 #include <getopt.h>
331-#include "getopt_int.h"
332+#include <bits/getopt_int.h>
333
334
335 /* For communication from `getopt' to the caller.
336@@ -1170,6 +1170,15 @@
337 return _getopt_internal (argc, argv, options, long_options, opt_index, 0);
338 }
339
340+int
341+_getopt_long_r (int argc, char *const *argv, const char *options,
342+ const struct option *long_options, int *opt_index,
343+ struct _getopt_data *d)
344+{
345+ return _getopt_internal_r (argc, argv, options, long_options, opt_index,
346+ 0, d);
347+}
348+
349 /* Like getopt_long, but '-' as well as '--' can indicate a long option.
350 If an option that starts with '-' (not '--') doesn't match a long option,
351 but does match a short option, it is parsed as a short option
352@@ -1182,4 +1191,12 @@
353 return _getopt_internal (argc, argv, options, long_options, opt_index, 1);
354 }
355
356+int
357+_getopt_long_only_r (int argc, char *const *argv, const char *options,
358+ const struct option *long_options, int *opt_index,
359+ struct _getopt_data *d)
360+{
361+ return _getopt_internal_r (argc, argv, options, long_options, opt_index, 1, d);
362+}
363+
364 #endif /* Not ELIDE_CODE. */
365Index: git/libuargp/Makefile
366===================================================================
367--- /dev/null 1970-01-01 00:00:00.000000000 +0000
368+++ git/libuargp/Makefile 2012-06-18 13:10:44.056825544 -0700
369@@ -0,0 +1,14 @@
370+# Makefile for uClibc (libuargp)
371+#
372+# Copyright (C) 2010 STMicroelectronics Ltd
373+# Author(s): Filippo Arcidiacono <filippo.arcidiacono at st.com>
374+#
375+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
376+#
377+
378+top_srcdir=../
379+top_builddir=../
380+include $(top_builddir)Rules.mak
381+all: libs
382+include Makefile.in
383+include $(top_srcdir)Makerules
384Index: git/libuargp/Makefile.in
385===================================================================
386--- /dev/null 1970-01-01 00:00:00.000000000 +0000
387+++ git/libuargp/Makefile.in 2012-06-18 13:10:44.056825544 -0700
388@@ -0,0 +1,73 @@
389+# Makefile for uClibc (libuargp)
390+#
391+# Copyright (C) 2009, 2010 STMicroelectronics Ltd.
392+# Author(s): Salvatore Cro <salvatore.cro at st.com>
393+# - First implementation, embedded into libc
394+# Filippo Arcidiacono <filippo.arcidiacono at st.com>
395+# - Reworked for stand-alone libuargp implementation
396+
397+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
398+#
399+
400+CFLAGS-libuargp := -DNOT_IN_libc -DIS_IN_libuargp $(SSP_ALL_CFLAGS)
401+
402+LDFLAGS-libuargp.so := $(LDFLAGS)
403+
404+LIBS-libuargp.so := $(LIBS)
405+
406+libuargp_FULL_NAME := libuargp-$(VERSION).so
407+
408+libuargp_DIR := $(top_srcdir)libuargp
409+libuargp_OUT := $(top_builddir)libuargp
410+
411+libuargp_SRC-y :=
412+libuargp_SRC-$(UCLIBC_HAS_ARGP) := $(addsuffix .c,$(addprefix argp-, ba \
413+ eexst fmtstream fs-xinl help parse pv pvh xinl))
414+
415+CFLAGS-argp-xinl.c = -fgnu89-inline
416+
417+libuargp_SRC := $(addprefix $(libuargp_DIR)/,$(libuargp_SRC-y))
418+libuargp_OBJ := $(patsubst $(libuargp_DIR)/%.c,$(libuargp_OUT)/%.o,$(libuargp_SRC))
419+
420+libuargp_SRCS := $(libuargp_SRC)
421+libuargp_OBJS := $(libuargp_OBJ)
422+
423+ifeq ($(DOPIC),y)
424+libuargp-a-y := $(libuargp_OBJS:.o=.os)
425+else
426+libuargp-a-y := $(libuargp_OBJS)
427+endif
428+libuargp-so-y := $(libuargp_OBJS:.o=.os)
429+
430+lib-a-$(UCLIBC_HAS_ARGP) += $(top_builddir)lib/libuargp.a
431+lib-so-$(UCLIBC_HAS_ARGP) += $(top_builddir)lib/libuargp.so
432+
433+objclean-y += CLEAN_libuargp
434+
435+ifeq ($(DOMULTI),n)
436+ifeq ($(DOPIC),y)
437+$(top_builddir)lib/libuargp.so: $(top_builddir)lib/libuargp.a $(libc.depend)
438+else
439+$(top_builddir)lib/libuargp.so: $(libuargp_OUT)/libuargp_so.a $(libc.depend)
440+endif
441+ $(call link.so,$(libuargp_FULL_NAME),$(MAJOR_VERSION))
442+else
443+$(top_builddir)lib/libuargp.so: $(libuargp_OUT)/libuargp.oS $(libc.depend)
444+ $(call linkm.so,$(libuargp_FULL_NAME),$(MAJOR_VERSION))
445+endif
446+
447+$(libuargp_OUT)/libuargp_so.a: $(libuargp-so-y)
448+ $(Q)$(RM) $@
449+ $(do_ar)
450+
451+$(libuargp_OUT)/libuargp.oS: $(libuargp_SRCS)
452+ $(Q)$(RM) $@
453+ $(compile-m)
454+
455+$(top_builddir)lib/libuargp.a: $(libuargp-a-y)
456+ $(Q)$(INSTALL) -d $(dir $@)
457+ $(Q)$(RM) $@
458+ $(do_ar)
459+
460+CLEAN_libuargp:
461+ $(do_rm) $(addprefix $(libuargp_OUT)/*., o os oS a)
462Index: git/libuargp/argp-ba.c
463===================================================================
464--- /dev/null 1970-01-01 00:00:00.000000000 +0000
465+++ git/libuargp/argp-ba.c 2012-06-18 13:10:44.056825544 -0700
466@@ -0,0 +1,26 @@
467+/* Default definition for ARGP_PROGRAM_BUG_ADDRESS.
468+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
469+ This file is part of the GNU C Library.
470+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
471+
472+ The GNU C Library is free software; you can redistribute it and/or
473+ modify it under the terms of the GNU Lesser General Public
474+ License as published by the Free Software Foundation; either
475+ version 2.1 of the License, or (at your option) any later version.
476+
477+ The GNU C Library is distributed in the hope that it will be useful,
478+ but WITHOUT ANY WARRANTY; without even the implied warranty of
479+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
480+ Lesser General Public License for more details.
481+
482+ You should have received a copy of the GNU Lesser General Public
483+ License along with the GNU C Library; if not, write to the Free
484+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
485+ 02111-1307 USA. */
486+
487+/* If set by the user program, it should point to string that is the
488+ bug-reporting address for the program. It will be printed by argp_help if
489+ the ARGP_HELP_BUG_ADDR flag is set (as it is by various standard help
490+ messages), embedded in a sentence that says something like `Report bugs to
491+ ADDR.'. */
492+const char *argp_program_bug_address;
493Index: git/libuargp/argp-eexst.c
494===================================================================
495--- /dev/null 1970-01-01 00:00:00.000000000 +0000
496+++ git/libuargp/argp-eexst.c 2012-06-18 13:10:44.056825544 -0700
497@@ -0,0 +1,32 @@
498+/* Default definition for ARGP_ERR_EXIT_STATUS
499+ Copyright (C) 1997 Free Software Foundation, Inc.
500+ This file is part of the GNU C Library.
501+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
502+
503+ The GNU C Library is free software; you can redistribute it and/or
504+ modify it under the terms of the GNU Lesser General Public
505+ License as published by the Free Software Foundation; either
506+ version 2.1 of the License, or (at your option) any later version.
507+
508+ The GNU C Library is distributed in the hope that it will be useful,
509+ but WITHOUT ANY WARRANTY; without even the implied warranty of
510+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
511+ Lesser General Public License for more details.
512+
513+ You should have received a copy of the GNU Lesser General Public
514+ License along with the GNU C Library; if not, write to the Free
515+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
516+ 02111-1307 USA. */
517+
518+#ifdef HAVE_CONFIG_H
519+# include <config.h>
520+#endif
521+
522+#include <sysexits.h>
523+
524+#include <argp.h>
525+
526+/* The exit status that argp will use when exiting due to a parsing error.
527+ If not defined or set by the user program, this defaults to EX_USAGE from
528+ <sysexits.h>. */
529+error_t argp_err_exit_status = EX_USAGE;
530Index: git/libuargp/argp-fmtstream.c
531===================================================================
532--- /dev/null 1970-01-01 00:00:00.000000000 +0000
533+++ git/libuargp/argp-fmtstream.c 2012-06-18 13:10:44.056825544 -0700
534@@ -0,0 +1,439 @@
535+/* Word-wrapping and line-truncating streams
536+ Copyright (C) 1997-1999,2001,2002,2003,2005 Free Software Foundation, Inc.
537+ This file is part of the GNU C Library.
538+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
539+
540+ The GNU C Library is free software; you can redistribute it and/or
541+ modify it under the terms of the GNU Lesser General Public
542+ License as published by the Free Software Foundation; either
543+ version 2.1 of the License, or (at your option) any later version.
544+
545+ The GNU C Library is distributed in the hope that it will be useful,
546+ but WITHOUT ANY WARRANTY; without even the implied warranty of
547+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
548+ Lesser General Public License for more details.
549+
550+ You should have received a copy of the GNU Lesser General Public
551+ License along with the GNU C Library; if not, write to the Free
552+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
553+ 02111-1307 USA.
554+
555+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
556+*/
557+
558+/* This package emulates glibc `line_wrap_stream' semantics for systems that
559+ don't have that. */
560+
561+#ifdef HAVE_CONFIG_H
562+# include <config.h>
563+#endif
564+
565+#include <stdlib.h>
566+#include <string.h>
567+#include <errno.h>
568+#include <stdarg.h>
569+#include <ctype.h>
570+
571+#include "argp-fmtstream.h"
572+
573+#ifndef ARGP_FMTSTREAM_USE_LINEWRAP
574+
575+#ifndef isblank
576+#define isblank(ch) ((ch)==' ' || (ch)=='\t')
577+#endif
578+
579+#if defined _LIBC && defined USE_IN_LIBIO
580+# include <wchar.h>
581+# include <libio/libioP.h>
582+# define __vsnprintf(s, l, f, a) _IO_vsnprintf (s, l, f, a)
583+#else
584+# define __vsnprintf(s, l, f, a) vsnprintf (s, l, f, a)
585+#endif
586+
587+#define INIT_BUF_SIZE 200
588+#define PRINTF_SIZE_GUESS 150
589+
590+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
591+ written on it with LMARGIN spaces and limits them to RMARGIN columns
592+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
593+ replacing the whitespace before them with a newline and WMARGIN spaces.
594+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
595+ Returns NULL if there was an error. */
596+argp_fmtstream_t
597+__argp_make_fmtstream (FILE *stream,
598+ size_t lmargin, size_t rmargin, ssize_t wmargin)
599+{
600+ argp_fmtstream_t fs;
601+
602+ fs = (struct argp_fmtstream *) malloc (sizeof (struct argp_fmtstream));
603+ if (fs != NULL)
604+ {
605+ fs->stream = stream;
606+
607+ fs->lmargin = lmargin;
608+ fs->rmargin = rmargin;
609+ fs->wmargin = wmargin;
610+ fs->point_col = 0;
611+ fs->point_offs = 0;
612+
613+ fs->buf = (char *) malloc (INIT_BUF_SIZE);
614+ if (! fs->buf)
615+ {
616+ free (fs);
617+ fs = 0;
618+ }
619+ else
620+ {
621+ fs->p = fs->buf;
622+ fs->end = fs->buf + INIT_BUF_SIZE;
623+ }
624+ }
625+
626+ return fs;
627+}
628+#if 0
629+/* Not exported. */
630+#ifdef weak_alias
631+weak_alias (__argp_make_fmtstream, argp_make_fmtstream)
632+#endif
633+#endif
634+
635+/* Flush FS to its stream, and free it (but don't close the stream). */
636+void
637+__argp_fmtstream_free (argp_fmtstream_t fs)
638+{
639+ __argp_fmtstream_update (fs);
640+ if (fs->p > fs->buf)
641+ {
642+#ifdef USE_IN_LIBIO
643+ __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
644+#else
645+ fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
646+#endif
647+ }
648+ free (fs->buf);
649+ free (fs);
650+}
651+#if 0
652+/* Not exported. */
653+#ifdef weak_alias
654+weak_alias (__argp_fmtstream_free, argp_fmtstream_free)
655+#endif
656+#endif
657+
658+/* Process FS's buffer so that line wrapping is done from POINT_OFFS to the
659+ end of its buffer. This code is mostly from glibc stdio/linewrap.c. */
660+void
661+__argp_fmtstream_update (argp_fmtstream_t fs)
662+{
663+ char *buf, *nl;
664+ size_t len;
665+
666+ /* Scan the buffer for newlines. */
667+ buf = fs->buf + fs->point_offs;
668+ while (buf < fs->p)
669+ {
670+ size_t r;
671+
672+ if (fs->point_col == 0 && fs->lmargin != 0)
673+ {
674+ /* We are starting a new line. Print spaces to the left margin. */
675+ const size_t pad = fs->lmargin;
676+ if (fs->p + pad < fs->end)
677+ {
678+ /* We can fit in them in the buffer by moving the
679+ buffer text up and filling in the beginning. */
680+ memmove (buf + pad, buf, fs->p - buf);
681+ fs->p += pad; /* Compensate for bigger buffer. */
682+ memset (buf, ' ', pad); /* Fill in the spaces. */
683+ buf += pad; /* Don't bother searching them. */
684+ }
685+ else
686+ {
687+ /* No buffer space for spaces. Must flush. */
688+ size_t i;
689+ for (i = 0; i < pad; i++)
690+ {
691+#ifdef USE_IN_LIBIO
692+ if (_IO_fwide (fs->stream, 0) > 0)
693+ putwc_unlocked (L' ', fs->stream);
694+ else
695+#endif
696+ putc_unlocked (' ', fs->stream);
697+ }
698+ }
699+ fs->point_col = pad;
700+ }
701+
702+ len = fs->p - buf;
703+ nl = memchr (buf, '\n', len);
704+
705+ if (fs->point_col < 0)
706+ fs->point_col = 0;
707+
708+ if (!nl)
709+ {
710+ /* The buffer ends in a partial line. */
711+
712+ if (fs->point_col + len < fs->rmargin)
713+ {
714+ /* The remaining buffer text is a partial line and fits
715+ within the maximum line width. Advance point for the
716+ characters to be written and stop scanning. */
717+ fs->point_col += len;
718+ break;
719+ }
720+ else
721+ /* Set the end-of-line pointer for the code below to
722+ the end of the buffer. */
723+ nl = fs->p;
724+ }
725+ else if (fs->point_col + (nl - buf) < (ssize_t) fs->rmargin)
726+ {
727+ /* The buffer contains a full line that fits within the maximum
728+ line width. Reset point and scan the next line. */
729+ fs->point_col = 0;
730+ buf = nl + 1;
731+ continue;
732+ }
733+
734+ /* This line is too long. */
735+ r = fs->rmargin - 1;
736+
737+ if (fs->wmargin < 0)
738+ {
739+ /* Truncate the line by overwriting the excess with the
740+ newline and anything after it in the buffer. */
741+ if (nl < fs->p)
742+ {
743+ memmove (buf + (r - fs->point_col), nl, fs->p - nl);
744+ fs->p -= buf + (r - fs->point_col) - nl;
745+ /* Reset point for the next line and start scanning it. */
746+ fs->point_col = 0;
747+ buf += r + 1; /* Skip full line plus \n. */
748+ }
749+ else
750+ {
751+ /* The buffer ends with a partial line that is beyond the
752+ maximum line width. Advance point for the characters
753+ written, and discard those past the max from the buffer. */
754+ fs->point_col += len;
755+ fs->p -= fs->point_col - r;
756+ break;
757+ }
758+ }
759+ else
760+ {
761+ /* Do word wrap. Go to the column just past the maximum line
762+ width and scan back for the beginning of the word there.
763+ Then insert a line break. */
764+
765+ char *p, *nextline;
766+ int i;
767+
768+ p = buf + (r + 1 - fs->point_col);
769+ while (p >= buf && !isblank (*p))
770+ --p;
771+ nextline = p + 1; /* This will begin the next line. */
772+
773+ if (nextline > buf)
774+ {
775+ /* Swallow separating blanks. */
776+ if (p >= buf)
777+ do
778+ --p;
779+ while (p >= buf && isblank (*p));
780+ nl = p + 1; /* The newline will replace the first blank. */
781+ }
782+ else
783+ {
784+ /* A single word that is greater than the maximum line width.
785+ Oh well. Put it on an overlong line by itself. */
786+ p = buf + (r + 1 - fs->point_col);
787+ /* Find the end of the long word. */
788+ do
789+ ++p;
790+ while (p < nl && !isblank (*p));
791+ if (p == nl)
792+ {
793+ /* It already ends a line. No fussing required. */
794+ fs->point_col = 0;
795+ buf = nl + 1;
796+ continue;
797+ }
798+ /* We will move the newline to replace the first blank. */
799+ nl = p;
800+ /* Swallow separating blanks. */
801+ do
802+ ++p;
803+ while (isblank (*p));
804+ /* The next line will start here. */
805+ nextline = p;
806+ }
807+
808+ /* Note: There are a bunch of tests below for
809+ NEXTLINE == BUF + LEN + 1; this case is where NL happens to fall
810+ at the end of the buffer, and NEXTLINE is in fact empty (and so
811+ we need not be careful to maintain its contents). */
812+
813+ if ((nextline == buf + len + 1
814+ ? fs->end - nl < fs->wmargin + 1
815+ : nextline - (nl + 1) < fs->wmargin)
816+ && fs->p > nextline)
817+ {
818+ /* The margin needs more blanks than we removed. */
819+ if (fs->end - fs->p > fs->wmargin + 1)
820+ /* Make some space for them. */
821+ {
822+ size_t mv = fs->p - nextline;
823+ memmove (nl + 1 + fs->wmargin, nextline, mv);
824+ nextline = nl + 1 + fs->wmargin;
825+ len = nextline + mv - buf;
826+ *nl++ = '\n';
827+ }
828+ else
829+ /* Output the first line so we can use the space. */
830+ {
831+#if defined _LIBC && defined USE_IN_LIBIO
832+ __fxprintf (fs->stream, "%.*s\n",
833+ (int) (nl - fs->buf), fs->buf);
834+#else
835+ if (nl > fs->buf)
836+ fwrite_unlocked (fs->buf, 1, nl - fs->buf, fs->stream);
837+ putc_unlocked ('\n', fs->stream);
838+#endif
839+
840+ len += buf - fs->buf;
841+ nl = buf = fs->buf;
842+ }
843+ }
844+ else
845+ /* We can fit the newline and blanks in before
846+ the next word. */
847+ *nl++ = '\n';
848+
849+ if (nextline - nl >= fs->wmargin
850+ || (nextline == buf + len + 1 && fs->end - nextline >= fs->wmargin))
851+ /* Add blanks up to the wrap margin column. */
852+ for (i = 0; i < fs->wmargin; ++i)
853+ *nl++ = ' ';
854+ else
855+ for (i = 0; i < fs->wmargin; ++i)
856+#ifdef USE_IN_LIBIO
857+ if (_IO_fwide (fs->stream, 0) > 0)
858+ putwc_unlocked (L' ', fs->stream);
859+ else
860+#endif
861+ putc_unlocked (' ', fs->stream);
862+
863+ /* Copy the tail of the original buffer into the current buffer
864+ position. */
865+ if (nl < nextline)
866+ memmove (nl, nextline, buf + len - nextline);
867+ len -= nextline - buf;
868+
869+ /* Continue the scan on the remaining lines in the buffer. */
870+ buf = nl;
871+
872+ /* Restore bufp to include all the remaining text. */
873+ fs->p = nl + len;
874+
875+ /* Reset the counter of what has been output this line. If wmargin
876+ is 0, we want to avoid the lmargin getting added, so we set
877+ point_col to a magic value of -1 in that case. */
878+ fs->point_col = fs->wmargin ? fs->wmargin : -1;
879+ }
880+ }
881+
882+ /* Remember that we've scanned as far as the end of the buffer. */
883+ fs->point_offs = fs->p - fs->buf;
884+}
885+
886+/* Ensure that FS has space for AMOUNT more bytes in its buffer, either by
887+ growing the buffer, or by flushing it. True is returned iff we succeed. */
888+int
889+__argp_fmtstream_ensure (struct argp_fmtstream *fs, size_t amount)
890+{
891+ if ((size_t) (fs->end - fs->p) < amount)
892+ {
893+ ssize_t wrote;
894+
895+ /* Flush FS's buffer. */
896+ __argp_fmtstream_update (fs);
897+
898+#if defined _LIBC && defined USE_IN_LIBIO
899+ __fxprintf (fs->stream, "%.*s", (int) (fs->p - fs->buf), fs->buf);
900+ wrote = fs->p - fs->buf;
901+#else
902+ wrote = fwrite_unlocked (fs->buf, 1, fs->p - fs->buf, fs->stream);
903+#endif
904+ if (wrote == fs->p - fs->buf)
905+ {
906+ fs->p = fs->buf;
907+ fs->point_offs = 0;
908+ }
909+ else
910+ {
911+ fs->p -= wrote;
912+ fs->point_offs -= wrote;
913+ memmove (fs->buf, fs->buf + wrote, fs->p - fs->buf);
914+ return 0;
915+ }
916+
917+ if ((size_t) (fs->end - fs->buf) < amount)
918+ /* Gotta grow the buffer. */
919+ {
920+ size_t old_size = fs->end - fs->buf;
921+ size_t new_size = old_size + amount;
922+ char *new_buf;
923+
924+ if (new_size < old_size || ! (new_buf = realloc (fs->buf, new_size)))
925+ {
926+ __set_errno (ENOMEM);
927+ return 0;
928+ }
929+
930+ fs->buf = new_buf;
931+ fs->end = new_buf + new_size;
932+ fs->p = fs->buf;
933+ }
934+ }
935+
936+ return 1;
937+}
938+
939+ssize_t
940+__argp_fmtstream_printf (struct argp_fmtstream *fs, const char *fmt, ...)
941+{
942+ int out;
943+ size_t avail;
944+ size_t size_guess = PRINTF_SIZE_GUESS; /* How much space to reserve. */
945+
946+ do
947+ {
948+ va_list args;
949+
950+ if (! __argp_fmtstream_ensure (fs, size_guess))
951+ return -1;
952+
953+ va_start (args, fmt);
954+ avail = fs->end - fs->p;
955+ out = __vsnprintf (fs->p, avail, fmt, args);
956+ va_end (args);
957+ if ((size_t) out >= avail)
958+ size_guess = out + 1;
959+ }
960+ while ((size_t) out >= avail);
961+
962+ fs->p += out;
963+
964+ return out;
965+}
966+#if 0
967+/* Not exported. */
968+#ifdef weak_alias
969+weak_alias (__argp_fmtstream_printf, argp_fmtstream_printf)
970+#endif
971+#endif
972+
973+#endif /* !ARGP_FMTSTREAM_USE_LINEWRAP */
974Index: git/libuargp/argp-fmtstream.h
975===================================================================
976--- /dev/null 1970-01-01 00:00:00.000000000 +0000
977+++ git/libuargp/argp-fmtstream.h 2012-06-18 13:10:44.056825544 -0700
978@@ -0,0 +1,314 @@
979+/* Word-wrapping and line-truncating streams.
980+ Copyright (C) 1997 Free Software Foundation, Inc.
981+ This file is part of the GNU C Library.
982+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
983+
984+ The GNU C Library is free software; you can redistribute it and/or
985+ modify it under the terms of the GNU Lesser General Public
986+ License as published by the Free Software Foundation; either
987+ version 2.1 of the License, or (at your option) any later version.
988+
989+ The GNU C Library is distributed in the hope that it will be useful,
990+ but WITHOUT ANY WARRANTY; without even the implied warranty of
991+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
992+ Lesser General Public License for more details.
993+
994+ You should have received a copy of the GNU Lesser General Public
995+ License along with the GNU C Library; if not, write to the Free
996+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
997+ 02111-1307 USA.
998+
999+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
1000+*/
1001+
1002+/* This package emulates glibc `line_wrap_stream' semantics for systems that
1003+ don't have that. If the system does have it, it is just a wrapper for
1004+ that. This header file is only used internally while compiling argp, and
1005+ shouldn't be installed. */
1006+
1007+#ifndef _ARGP_FMTSTREAM_H
1008+#define _ARGP_FMTSTREAM_H
1009+
1010+#include <stdio.h>
1011+#include <string.h>
1012+#include <unistd.h>
1013+
1014+#ifndef __attribute__
1015+/* This feature is available in gcc versions 2.5 and later. */
1016+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || defined(__STRICT_ANSI__)
1017+# define __attribute__(Spec) /* empty */
1018+# endif
1019+/* The __-protected variants of `format' and `printf' attributes
1020+ are accepted by gcc versions 2.6.4 (effectively 2.7) and later. */
1021+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(__STRICT_ANSI__)
1022+# define __format__ format
1023+# define __printf__ printf
1024+# endif
1025+#endif
1026+
1027+#if 0 /* uClibc: disabled */
1028+#if (_LIBC - 0 && !defined (USE_IN_LIBIO)) \
1029+ || (defined (__GNU_LIBRARY__) && defined (HAVE_LINEWRAP_H))
1030+/* line_wrap_stream is available, so use that. */
1031+#define ARGP_FMTSTREAM_USE_LINEWRAP
1032+#endif
1033+#else
1034+/* line_wrap stream NOT available */
1035+# undef ARGP_FMTSTREAM_USE_LINEWRAP
1036+#endif
1037+
1038+#ifdef ARGP_FMTSTREAM_USE_LINEWRAP
1039+/* Just be a simple wrapper for line_wrap_stream; the semantics are
1040+ *slightly* different, as line_wrap_stream doesn't actually make a new
1041+ object, it just modifies the given stream (reversibly) to do
1042+ line-wrapping. Since we control who uses this code, it doesn't matter. */
1043+
1044+#include <linewrap.h>
1045+
1046+typedef FILE *argp_fmtstream_t;
1047+
1048+#define argp_make_fmtstream line_wrap_stream
1049+#define __argp_make_fmtstream line_wrap_stream
1050+#define argp_fmtstream_free line_unwrap_stream
1051+#define __argp_fmtstream_free line_unwrap_stream
1052+
1053+#define __argp_fmtstream_putc(fs,ch) putc(ch,fs)
1054+#define argp_fmtstream_putc(fs,ch) putc(ch,fs)
1055+#define __argp_fmtstream_puts(fs,str) fputs(str,fs)
1056+#define argp_fmtstream_puts(fs,str) fputs(str,fs)
1057+#define __argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
1058+#define argp_fmtstream_write(fs,str,len) fwrite(str,1,len,fs)
1059+#define __argp_fmtstream_printf fprintf
1060+#define argp_fmtstream_printf fprintf
1061+
1062+#define __argp_fmtstream_lmargin line_wrap_lmargin
1063+#define argp_fmtstream_lmargin line_wrap_lmargin
1064+#define __argp_fmtstream_set_lmargin line_wrap_set_lmargin
1065+#define argp_fmtstream_set_lmargin line_wrap_set_lmargin
1066+#define __argp_fmtstream_rmargin line_wrap_rmargin
1067+#define argp_fmtstream_rmargin line_wrap_rmargin
1068+#define __argp_fmtstream_set_rmargin line_wrap_set_rmargin
1069+#define argp_fmtstream_set_rmargin line_wrap_set_rmargin
1070+#define __argp_fmtstream_wmargin line_wrap_wmargin
1071+#define argp_fmtstream_wmargin line_wrap_wmargin
1072+#define __argp_fmtstream_set_wmargin line_wrap_set_wmargin
1073+#define argp_fmtstream_set_wmargin line_wrap_set_wmargin
1074+#define __argp_fmtstream_point line_wrap_point
1075+#define argp_fmtstream_point line_wrap_point
1076+
1077+#else /* !ARGP_FMTSTREAM_USE_LINEWRAP */
1078+/* Guess we have to define our own version. */
1079+
1080+#ifndef __const
1081+#define __const const
1082+#endif
1083+
1084+struct argp_fmtstream
1085+{
1086+ FILE *stream; /* The stream we're outputting to. */
1087+
1088+ size_t lmargin, rmargin; /* Left and right margins. */
1089+ ssize_t wmargin; /* Margin to wrap to, or -1 to truncate. */
1090+
1091+ /* Point in buffer to which we've processed for wrapping, but not output. */
1092+ size_t point_offs;
1093+ /* Output column at POINT_OFFS, or -1 meaning 0 but don't add lmargin. */
1094+ ssize_t point_col;
1095+
1096+ char *buf; /* Output buffer. */
1097+ char *p; /* Current end of text in BUF. */
1098+ char *end; /* Absolute end of BUF. */
1099+};
1100+
1101+typedef struct argp_fmtstream *argp_fmtstream_t;
1102+
1103+/* Return an argp_fmtstream that outputs to STREAM, and which prefixes lines
1104+ written on it with LMARGIN spaces and limits them to RMARGIN columns
1105+ total. If WMARGIN >= 0, words that extend past RMARGIN are wrapped by
1106+ replacing the whitespace before them with a newline and WMARGIN spaces.
1107+ Otherwise, chars beyond RMARGIN are simply dropped until a newline.
1108+ Returns NULL if there was an error. */
1109+extern argp_fmtstream_t __argp_make_fmtstream (FILE *__stream,
1110+ size_t __lmargin,
1111+ size_t __rmargin,
1112+ ssize_t __wmargin);
1113+extern argp_fmtstream_t argp_make_fmtstream (FILE *__stream,
1114+ size_t __lmargin,
1115+ size_t __rmargin,
1116+ ssize_t __wmargin);
1117+
1118+/* Flush __FS to its stream, and free it (but don't close the stream). */
1119+extern void __argp_fmtstream_free (argp_fmtstream_t __fs);
1120+extern void argp_fmtstream_free (argp_fmtstream_t __fs);
1121+
1122+extern ssize_t __argp_fmtstream_printf (argp_fmtstream_t __fs,
1123+ __const char *__fmt, ...)
1124+ __attribute__ ((__format__ (printf, 2, 3)));
1125+extern ssize_t argp_fmtstream_printf (argp_fmtstream_t __fs,
1126+ __const char *__fmt, ...)
1127+ __attribute__ ((__format__ (printf, 2, 3)));
1128+
1129+extern int __argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
1130+extern int argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch);
1131+
1132+extern int __argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
1133+extern int argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str);
1134+
1135+extern size_t __argp_fmtstream_write (argp_fmtstream_t __fs,
1136+ __const char *__str, size_t __len);
1137+extern size_t argp_fmtstream_write (argp_fmtstream_t __fs,
1138+ __const char *__str, size_t __len);
1139+
1140+/* Access macros for various bits of state. */
1141+#define argp_fmtstream_lmargin(__fs) ((__fs)->lmargin)
1142+#define argp_fmtstream_rmargin(__fs) ((__fs)->rmargin)
1143+#define argp_fmtstream_wmargin(__fs) ((__fs)->wmargin)
1144+#define __argp_fmtstream_lmargin argp_fmtstream_lmargin
1145+#define __argp_fmtstream_rmargin argp_fmtstream_rmargin
1146+#define __argp_fmtstream_wmargin argp_fmtstream_wmargin
1147+
1148+/* Set __FS's left margin to LMARGIN and return the old value. */
1149+extern size_t argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
1150+ size_t __lmargin);
1151+extern size_t __argp_fmtstream_set_lmargin (argp_fmtstream_t __fs,
1152+ size_t __lmargin);
1153+
1154+/* Set __FS's right margin to __RMARGIN and return the old value. */
1155+extern size_t argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
1156+ size_t __rmargin);
1157+extern size_t __argp_fmtstream_set_rmargin (argp_fmtstream_t __fs,
1158+ size_t __rmargin);
1159+
1160+/* Set __FS's wrap margin to __WMARGIN and return the old value. */
1161+extern size_t argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
1162+ size_t __wmargin);
1163+extern size_t __argp_fmtstream_set_wmargin (argp_fmtstream_t __fs,
1164+ size_t __wmargin);
1165+
1166+/* Return the column number of the current output point in __FS. */
1167+extern size_t argp_fmtstream_point (argp_fmtstream_t __fs);
1168+extern size_t __argp_fmtstream_point (argp_fmtstream_t __fs);
1169+
1170+/* Internal routines. */
1171+extern void _argp_fmtstream_update (argp_fmtstream_t __fs);
1172+extern void __argp_fmtstream_update (argp_fmtstream_t __fs);
1173+extern int _argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
1174+extern int __argp_fmtstream_ensure (argp_fmtstream_t __fs, size_t __amount);
1175+
1176+#ifdef __OPTIMIZE__
1177+/* Inline versions of above routines. */
1178+
1179+#if !_LIBC
1180+#define __argp_fmtstream_putc argp_fmtstream_putc
1181+#define __argp_fmtstream_puts argp_fmtstream_puts
1182+#define __argp_fmtstream_write argp_fmtstream_write
1183+#define __argp_fmtstream_set_lmargin argp_fmtstream_set_lmargin
1184+#define __argp_fmtstream_set_rmargin argp_fmtstream_set_rmargin
1185+#define __argp_fmtstream_set_wmargin argp_fmtstream_set_wmargin
1186+#define __argp_fmtstream_point argp_fmtstream_point
1187+#define __argp_fmtstream_update _argp_fmtstream_update
1188+#define __argp_fmtstream_ensure _argp_fmtstream_ensure
1189+#endif
1190+
1191+#ifndef ARGP_FS_EI
1192+#define ARGP_FS_EI __extern_inline
1193+#endif
1194+
1195+ARGP_FS_EI size_t
1196+__argp_fmtstream_write (argp_fmtstream_t __fs,
1197+ __const char *__str, size_t __len)
1198+{
1199+ if (__fs->p + __len <= __fs->end || __argp_fmtstream_ensure (__fs, __len))
1200+ {
1201+ memcpy (__fs->p, __str, __len);
1202+ __fs->p += __len;
1203+ return __len;
1204+ }
1205+ else
1206+ return 0;
1207+}
1208+
1209+ARGP_FS_EI int
1210+__argp_fmtstream_puts (argp_fmtstream_t __fs, __const char *__str)
1211+{
1212+ size_t __len = strlen (__str);
1213+ if (__len)
1214+ {
1215+ size_t __wrote = __argp_fmtstream_write (__fs, __str, __len);
1216+ return __wrote == __len ? 0 : -1;
1217+ }
1218+ else
1219+ return 0;
1220+}
1221+
1222+ARGP_FS_EI int
1223+__argp_fmtstream_putc (argp_fmtstream_t __fs, int __ch)
1224+{
1225+ if (__fs->p < __fs->end || __argp_fmtstream_ensure (__fs, 1))
1226+ return *__fs->p++ = __ch;
1227+ else
1228+ return EOF;
1229+}
1230+
1231+/* Set __FS's left margin to __LMARGIN and return the old value. */
1232+ARGP_FS_EI size_t
1233+__argp_fmtstream_set_lmargin (argp_fmtstream_t __fs, size_t __lmargin)
1234+{
1235+ size_t __old;
1236+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1237+ __argp_fmtstream_update (__fs);
1238+ __old = __fs->lmargin;
1239+ __fs->lmargin = __lmargin;
1240+ return __old;
1241+}
1242+
1243+/* Set __FS's right margin to __RMARGIN and return the old value. */
1244+ARGP_FS_EI size_t
1245+__argp_fmtstream_set_rmargin (argp_fmtstream_t __fs, size_t __rmargin)
1246+{
1247+ size_t __old;
1248+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1249+ __argp_fmtstream_update (__fs);
1250+ __old = __fs->rmargin;
1251+ __fs->rmargin = __rmargin;
1252+ return __old;
1253+}
1254+
1255+/* Set FS's wrap margin to __WMARGIN and return the old value. */
1256+ARGP_FS_EI size_t
1257+__argp_fmtstream_set_wmargin (argp_fmtstream_t __fs, size_t __wmargin)
1258+{
1259+ size_t __old;
1260+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1261+ __argp_fmtstream_update (__fs);
1262+ __old = __fs->wmargin;
1263+ __fs->wmargin = __wmargin;
1264+ return __old;
1265+}
1266+
1267+/* Return the column number of the current output point in __FS. */
1268+ARGP_FS_EI size_t
1269+__argp_fmtstream_point (argp_fmtstream_t __fs)
1270+{
1271+ if ((size_t) (__fs->p - __fs->buf) > __fs->point_offs)
1272+ __argp_fmtstream_update (__fs);
1273+ return __fs->point_col >= 0 ? __fs->point_col : 0;
1274+}
1275+
1276+#if !_LIBC
1277+#undef __argp_fmtstream_putc
1278+#undef __argp_fmtstream_puts
1279+#undef __argp_fmtstream_write
1280+#undef __argp_fmtstream_set_lmargin
1281+#undef __argp_fmtstream_set_rmargin
1282+#undef __argp_fmtstream_set_wmargin
1283+#undef __argp_fmtstream_point
1284+#undef __argp_fmtstream_update
1285+#undef __argp_fmtstream_ensure
1286+#endif
1287+
1288+#endif /* __OPTIMIZE__ */
1289+
1290+#endif /* ARGP_FMTSTREAM_USE_LINEWRAP */
1291+
1292+#endif /* argp-fmtstream.h */
1293Index: git/libuargp/argp-fs-xinl.c
1294===================================================================
1295--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1296+++ git/libuargp/argp-fs-xinl.c 2012-06-18 13:10:44.056825544 -0700
1297@@ -0,0 +1,44 @@
1298+/* Real definitions for extern inline functions in argp-fmtstream.h
1299+ Copyright (C) 1997, 2003, 2004 Free Software Foundation, Inc.
1300+ This file is part of the GNU C Library.
1301+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
1302+
1303+ The GNU C Library is free software; you can redistribute it and/or
1304+ modify it under the terms of the GNU Lesser General Public
1305+ License as published by the Free Software Foundation; either
1306+ version 2.1 of the License, or (at your option) any later version.
1307+
1308+ The GNU C Library is distributed in the hope that it will be useful,
1309+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1310+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1311+ Lesser General Public License for more details.
1312+
1313+ You should have received a copy of the GNU Lesser General Public
1314+ License along with the GNU C Library; if not, write to the Free
1315+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1316+ 02111-1307 USA. */
1317+
1318+#ifdef HAVE_CONFIG_H
1319+# include <config.h>
1320+#endif
1321+
1322+#define ARGP_FS_EI
1323+#undef __OPTIMIZE__
1324+#define __OPTIMIZE__ 1
1325+#include "argp-fmtstream.h"
1326+
1327+#if 0
1328+/* Not exported. */
1329+/* Add weak aliases. */
1330+#if _LIBC - 0 && !defined (ARGP_FMTSTREAM_USE_LINEWRAP) && defined (weak_alias)
1331+
1332+weak_alias (__argp_fmtstream_putc, argp_fmtstream_putc)
1333+weak_alias (__argp_fmtstream_puts, argp_fmtstream_puts)
1334+weak_alias (__argp_fmtstream_write, argp_fmtstream_write)
1335+weak_alias (__argp_fmtstream_set_lmargin, argp_fmtstream_set_lmargin)
1336+weak_alias (__argp_fmtstream_set_rmargin, argp_fmtstream_set_rmargin)
1337+weak_alias (__argp_fmtstream_set_wmargin, argp_fmtstream_set_wmargin)
1338+weak_alias (__argp_fmtstream_point, argp_fmtstream_point)
1339+
1340+#endif
1341+#endif
1342Index: git/libuargp/argp-help.c
1343===================================================================
1344--- /dev/null 1970-01-01 00:00:00.000000000 +0000
1345+++ git/libuargp/argp-help.c 2012-06-18 13:10:44.060825542 -0700
1346@@ -0,0 +1,1882 @@
1347+/* Hierarchial argument parsing help output
1348+ Copyright (C) 1995-2003, 2004, 2005, 2006, 2007
1349+ Free Software Foundation, Inc.
1350+ This file is part of the GNU C Library.
1351+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
1352+
1353+ The GNU C Library is free software; you can redistribute it and/or
1354+ modify it under the terms of the GNU Lesser General Public
1355+ License as published by the Free Software Foundation; either
1356+ version 2.1 of the License, or (at your option) any later version.
1357+
1358+ The GNU C Library is distributed in the hope that it will be useful,
1359+ but WITHOUT ANY WARRANTY; without even the implied warranty of
1360+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1361+ Lesser General Public License for more details.
1362+
1363+ You should have received a copy of the GNU Lesser General Public
1364+ License along with the GNU C Library; if not, write to the Free
1365+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1366+ 02111-1307 USA.
1367+
1368+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
1369+*/
1370+
1371+#ifndef _GNU_SOURCE
1372+# define _GNU_SOURCE 1
1373+#endif
1374+
1375+#ifdef HAVE_CONFIG_H
1376+#include <config.h>
1377+#endif
1378+
1379+/* AIX requires this to be the first thing in the file. */
1380+#ifndef __GNUC__
1381+# if HAVE_ALLOCA_H || defined _LIBC
1382+# include <alloca.h>
1383+# else
1384+# ifdef _AIX
1385+#pragma alloca
1386+# else
1387+# ifndef alloca /* predefined by HP cc +Olibcalls */
1388+char *alloca ();
1389+# endif
1390+# endif
1391+# endif
1392+#endif
1393+
1394+#include <stddef.h>
1395+#include <stdlib.h>
1396+#include <string.h>
1397+#include <assert.h>
1398+#include <stdarg.h>
1399+#include <ctype.h>
1400+#include <limits.h>
1401+#ifdef _LIBC
1402+# include <wchar.h>
1403+#endif
1404+
1405+#include <features.h>
1406+#ifndef _
1407+/* This is for other GNU distributions with internationalized messages. */
1408+# if (defined HAVE_LIBINTL_H || defined _LIBC) && defined __UCLIBC_HAS_GETTEXT_AWARENESS__
1409+# include <libintl.h>
1410+# ifdef _LIBC
1411+# undef dgettext
1412+# define dgettext(domain, msgid) \
1413+ INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
1414+# endif
1415+# else
1416+# define dgettext(domain, msgid) (msgid)
1417+# endif
1418+#endif
1419+
1420+#ifndef _LIBC
1421+# if HAVE_STRERROR_R
1422+# if !HAVE_DECL_STRERROR_R
1423+char *strerror_r (int errnum, char *buf, size_t buflen);
1424+# endif
1425+# else
1426+# if !HAVE_DECL_STRERROR
1427+char *strerror (int errnum);
1428+# endif
1429+# endif
1430+#endif
1431+
1432+#include <argp.h>
1433+#include "argp-fmtstream.h"
1434+#include <stdbool.h>
1435+#include <stdint.h>
1436+
1437+#ifndef SIZE_MAX
1438+# define SIZE_MAX ((size_t) -1)
1439+#endif
1440+
1441+/* User-selectable (using an environment variable) formatting parameters.
1442+
1443+ These may be specified in an environment variable called `ARGP_HELP_FMT',
1444+ with a contents like: VAR1=VAL1,VAR2=VAL2,BOOLVAR2,no-BOOLVAR2
1445+ Where VALn must be a positive integer. The list of variables is in the
1446+ UPARAM_NAMES vector, below. */
1447+
1448+/* Default parameters. */
1449+#define DUP_ARGS 0 /* True if option argument can be duplicated. */
1450+#define DUP_ARGS_NOTE 1 /* True to print a note about duplicate args. */
1451+#define SHORT_OPT_COL 2 /* column in which short options start */
1452+#define LONG_OPT_COL 6 /* column in which long options start */
1453+#define DOC_OPT_COL 2 /* column in which doc options start */
1454+#define OPT_DOC_COL 29 /* column in which option text starts */
1455+#define HEADER_COL 1 /* column in which group headers are printed */
1456+#define USAGE_INDENT 12 /* indentation of wrapped usage lines */
1457+#define RMARGIN 79 /* right margin used for wrapping */
1458+
1459+/* User-selectable (using an environment variable) formatting parameters.
1460+ They must all be of type `int' for the parsing code to work. */
1461+struct uparams
1462+{
1463+ /* If true, arguments for an option are shown with both short and long
1464+ options, even when a given option has both, e.g. `-x ARG, --longx=ARG'.
1465+ If false, then if an option has both, the argument is only shown with
1466+ the long one, e.g., `-x, --longx=ARG', and a message indicating that
1467+ this really means both is printed below the options. */
1468+ int dup_args;
1469+
1470+ /* This is true if when DUP_ARGS is false, and some duplicate arguments have
1471+ been suppressed, an explanatory message should be printed. */
1472+ int dup_args_note;
1473+
1474+ /* Various output columns. */
1475+ int short_opt_col;
1476+ int long_opt_col;
1477+ int doc_opt_col;
1478+ int opt_doc_col;
1479+ int header_col;
1480+ int usage_indent;
1481+ int rmargin;
1482+};
1483+
1484+/* This is a global variable, as user options are only ever read once. */
1485+static struct uparams uparams = {
1486+ DUP_ARGS, DUP_ARGS_NOTE,
1487+ SHORT_OPT_COL, LONG_OPT_COL, DOC_OPT_COL, OPT_DOC_COL, HEADER_COL,
1488+ USAGE_INDENT, RMARGIN
1489+};
1490+
1491+/* A particular uparam, and what the user name is. */
1492+struct uparam_name
1493+{
1494+ const char name[14]; /* User name. */
1495+ bool is_bool; /* Whether it's `boolean'. */
1496+ uint8_t uparams_offs; /* Location of the (int) field in UPARAMS. */
1497+};
1498+
1499+/* The name-field mappings we know about. */
1500+static const struct uparam_name uparam_names[] =
1501+{
1502+ { "dup-args", true, offsetof (struct uparams, dup_args) },
1503+ { "dup-args-note", true, offsetof (struct uparams, dup_args_note) },
1504+ { "short-opt-col", false, offsetof (struct uparams, short_opt_col) },
1505+ { "long-opt-col", false, offsetof (struct uparams, long_opt_col) },
1506+ { "doc-opt-col", false, offsetof (struct uparams, doc_opt_col) },
1507+ { "opt-doc-col", false, offsetof (struct uparams, opt_doc_col) },
1508+ { "header-col", false, offsetof (struct uparams, header_col) },
1509+ { "usage-indent", false, offsetof (struct uparams, usage_indent) },
1510+ { "rmargin", false, offsetof (struct uparams, rmargin) }
1511+};
1512+#define nuparam_names (sizeof (uparam_names) / sizeof (uparam_names[0]))
1513+
1514+/* Read user options from the environment, and fill in UPARAMS appropiately. */
1515+static void
1516+fill_in_uparams (const struct argp_state *state)
1517+{
1518+ const char *var = getenv ("ARGP_HELP_FMT");
1519+
1520+#define SKIPWS(p) do { while (isspace (*p)) p++; } while (0);
1521+
1522+ if (var)
1523+ /* Parse var. */
1524+ while (*var)
1525+ {
1526+ SKIPWS (var);
1527+
1528+ if (isalpha (*var))
1529+ {
1530+ size_t var_len;
1531+ const struct uparam_name *un;
1532+ int unspec = 0, val = 0;
1533+ const char *arg = var;
1534+
1535+ while (isalnum (*arg) || *arg == '-' || *arg == '_')
1536+ arg++;
1537+ var_len = arg - var;
1538+
1539+ SKIPWS (arg);
1540+
1541+ if (*arg == '\0' || *arg == ',')
1542+ unspec = 1;
1543+ else if (*arg == '=')
1544+ {
1545+ arg++;
1546+ SKIPWS (arg);
1547+ }
1548+
1549+ if (unspec)
1550+ {
1551+ if (var[0] == 'n' && var[1] == 'o' && var[2] == '-')
1552+ {
1553+ val = 0;
1554+ var += 3;
1555+ var_len -= 3;
1556+ }
1557+ else
1558+ val = 1;
1559+ }
1560+ else if (isdigit (*arg))
1561+ {
1562+ val = atoi (arg);
1563+ while (isdigit (*arg))
1564+ arg++;
1565+ SKIPWS (arg);
1566+ }
1567+
1568+ un = uparam_names;
1569+ size_t u;
1570+ for (u = 0; u < nuparam_names; ++un, ++u)
1571+ if (strlen (un->name) == var_len
1572+ && strncmp (var, un->name, var_len) == 0)
1573+ {
1574+ if (unspec && !un->is_bool)
1575+ argp_failure (state, 0, 0,
1576+ dgettext (state == NULL ? NULL
1577+ : state->root_argp->argp_domain,
1578+ "\
1579+%.*s: ARGP_HELP_FMT parameter requires a value"),
1580+ (int) var_len, var);
1581+ else
1582+ *(int *)((char *)&uparams + un->uparams_offs) = val;
1583+ break;
1584+ }
1585+ if (u == nuparam_names)
1586+ argp_failure (state, 0, 0,
1587+ dgettext (state == NULL ? NULL
1588+ : state->root_argp->argp_domain, "\
1589+%.*s: Unknown ARGP_HELP_FMT parameter"),
1590+ (int) var_len, var);
1591+
1592+ var = arg;
1593+ if (*var == ',')
1594+ var++;
1595+ }
1596+ else if (*var)
1597+ {
1598+ argp_failure (state, 0, 0,
1599+ dgettext (state == NULL ? NULL
1600+ : state->root_argp->argp_domain,
1601+ "Garbage in ARGP_HELP_FMT: %s"), var);
1602+ break;
1603+ }
1604+ }
1605+}
1606+
1607+/* Returns true if OPT hasn't been marked invisible. Visibility only affects
1608+ whether OPT is displayed or used in sorting, not option shadowing. */
1609+#define ovisible(opt) (! ((opt)->flags & OPTION_HIDDEN))
1610+
1611+/* Returns true if OPT is an alias for an earlier option. */
1612+#define oalias(opt) ((opt)->flags & OPTION_ALIAS)
1613+
1614+/* Returns true if OPT is an documentation-only entry. */
1615+#define odoc(opt) ((opt)->flags & OPTION_DOC)
1616+
1617+/* Returns true if OPT is the end-of-list marker for a list of options. */
1618+#define oend(opt) __option_is_end (opt)
1619+
1620+/* Returns true if OPT has a short option. */
1621+#define oshort(opt) __option_is_short (opt)
1622+
1623+/*
1624+ The help format for a particular option is like:
1625+
1626+ -xARG, -yARG, --long1=ARG, --long2=ARG Documentation...
1627+
1628+ Where ARG will be omitted if there's no argument, for this option, or
1629+ will be surrounded by "[" and "]" appropiately if the argument is
1630+ optional. The documentation string is word-wrapped appropiately, and if
1631+ the list of options is long enough, it will be started on a separate line.
1632+ If there are no short options for a given option, the first long option is
1633+ indented slighly in a way that's supposed to make most long options appear
1634+ to be in a separate column.
1635+
1636+ For example, the following output (from ps):
1637+
1638+ -p PID, --pid=PID List the process PID
1639+ --pgrp=PGRP List processes in the process group PGRP
1640+ -P, -x, --no-parent Include processes without parents
1641+ -Q, --all-fields Don't elide unusable fields (normally if there's
1642+ some reason ps can't print a field for any
1643+ process, it's removed from the output entirely)
1644+ -r, --reverse, --gratuitously-long-reverse-option
1645+ Reverse the order of any sort
1646+ --session[=SID] Add the processes from the session SID (which
1647+ defaults to the sid of the current process)
1648+
1649+ Here are some more options:
1650+ -f ZOT, --foonly=ZOT Glork a foonly
1651+ -z, --zaza Snit a zar
1652+
1653+ -?, --help Give this help list
1654+ --usage Give a short usage message
1655+ -V, --version Print program version
1656+
1657+ The struct argp_option array for the above could look like:
1658+
1659+ {
1660+ {"pid", 'p', "PID", 0, "List the process PID"},
1661+ {"pgrp", OPT_PGRP, "PGRP", 0, "List processes in the process group PGRP"},
1662+ {"no-parent", 'P', 0, 0, "Include processes without parents"},
1663+ {0, 'x', 0, OPTION_ALIAS},
1664+ {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
1665+ " if there's some reason ps can't"
1666+ " print a field for any process, it's"
1667+ " removed from the output entirely)" },
1668+ {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
1669+ {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
1670+ {"session", OPT_SESS, "SID", OPTION_ARG_OPTIONAL,
1671+ "Add the processes from the session"
1672+ " SID (which defaults to the sid of"
1673+ " the current process)" },
1674+
1675+ {0,0,0,0, "Here are some more options:"},
1676+ {"foonly", 'f', "ZOT", 0, "Glork a foonly"},
1677+ {"zaza", 'z', 0, 0, "Snit a zar"},
1678+
1679+ {0}
1680+ }
1681+
1682+ Note that the last three options are automatically supplied by argp_parse,
1683+ unless you tell it not to with ARGP_NO_HELP.
1684+
1685+*/
1686+
1687+/* Returns true if CH occurs between BEG and END. */
1688+static int
1689+find_char (char ch, char *beg, char *end)
1690+{
1691+ while (beg < end)
1692+ if (*beg == ch)
1693+ return 1;
1694+ else
1695+ beg++;
1696+ return 0;
1697+}
1698+
1699+struct hol_cluster; /* fwd decl */
1700+
1701+struct hol_entry
1702+{
1703+ /* First option. */
1704+ const struct argp_option *opt;
1705+ /* Number of options (including aliases). */
1706+ unsigned num;
1707+
1708+ /* A pointers into the HOL's short_options field, to the first short option
1709+ letter for this entry. The order of the characters following this point
1710+ corresponds to the order of options pointed to by OPT, and there are at
1711+ most NUM. A short option recorded in a option following OPT is only
1712+ valid if it occurs in the right place in SHORT_OPTIONS (otherwise it's
1713+ probably been shadowed by some other entry). */
1714+ char *short_options;
1715+
1716+ /* Entries are sorted by their group first, in the order:
1717+ 1, 2, ..., n, 0, -m, ..., -2, -1
1718+ and then alphabetically within each group. The default is 0. */
1719+ int group;
1720+
1721+ /* The cluster of options this entry belongs to, or 0 if none. */
1722+ struct hol_cluster *cluster;
1723+
1724+ /* The argp from which this option came. */
1725+ const struct argp *argp;
1726+};
1727+
1728+/* A cluster of entries to reflect the argp tree structure. */
1729+struct hol_cluster
1730+{
1731+ /* A descriptive header printed before options in this cluster. */
1732+ const char *header;
1733+
1734+ /* Used to order clusters within the same group with the same parent,
1735+ according to the order in which they occurred in the parent argp's child
1736+ list. */
1737+ int index;
1738+
1739+ /* How to sort this cluster with respect to options and other clusters at the
1740+ same depth (clusters always follow options in the same group). */
1741+ int group;
1742+
1743+ /* The cluster to which this cluster belongs, or 0 if it's at the base
1744+ level. */
1745+ struct hol_cluster *parent;
1746+
1747+ /* The argp from which this cluster is (eventually) derived. */
1748+ const struct argp *argp;
1749+
1750+ /* The distance this cluster is from the root. */
1751+ int depth;
1752+
1753+ /* Clusters in a given hol are kept in a linked list, to make freeing them
1754+ possible. */
1755+ struct hol_cluster *next;
1756+};
1757+
1758+/* A list of options for help. */
1759+struct hol
1760+{
1761+ /* An array of hol_entry's. */
1762+ struct hol_entry *entries;
1763+ /* The number of entries in this hol. If this field is zero, the others
1764+ are undefined. */
1765+ unsigned num_entries;
1766+
1767+ /* A string containing all short options in this HOL. Each entry contains
1768+ pointers into this string, so the order can't be messed with blindly. */
1769+ char *short_options;
1770+
1771+ /* Clusters of entries in this hol. */
1772+ struct hol_cluster *clusters;
1773+};
1774+
1775+/* Create a struct hol from the options in ARGP. CLUSTER is the
1776+ hol_cluster in which these entries occur, or 0, if at the root. */
1777+static struct hol *
1778+make_hol (const struct argp *argp, struct hol_cluster *cluster)
1779+{
1780+ char *so;
1781+ const struct argp_option *o;
1782+ const struct argp_option *opts = argp->options;
1783+ struct hol_entry *entry;
1784+ unsigned num_short_options = 0;
1785+ struct hol *hol = malloc (sizeof (struct hol));
1786+
1787+ assert (hol);
1788+
1789+ hol->num_entries = 0;
1790+ hol->clusters = 0;
1791+
1792+ if (opts)
1793+ {
1794+ int cur_group = 0;
1795+
1796+ /* The first option must not be an alias. */
1797+ assert (! oalias (opts));
1798+
1799+ /* Calculate the space needed. */
1800+ for (o = opts; ! oend (o); o++)
1801+ {
1802+ if (! oalias (o))
1803+ hol->num_entries++;
1804+ if (oshort (o))
1805+ num_short_options++; /* This is an upper bound. */
1806+ }
1807+
1808+ hol->entries = malloc (sizeof (struct hol_entry) * hol->num_entries);
1809+ hol->short_options = malloc (num_short_options + 1);
1810+
1811+ assert (hol->entries && hol->short_options);
1812+#if SIZE_MAX <= UINT_MAX
1813+ assert (hol->num_entries <= SIZE_MAX / sizeof (struct hol_entry));
1814+#endif
1815+
1816+ /* Fill in the entries. */
1817+ so = hol->short_options;
1818+ for (o = opts, entry = hol->entries; ! oend (o); entry++)
1819+ {
1820+ entry->opt = o;
1821+ entry->num = 0;
1822+ entry->short_options = so;
1823+ entry->group = cur_group =
1824+ o->group
1825+ ? o->group
1826+ : ((!o->name && !o->key)
1827+ ? cur_group + 1
1828+ : cur_group);
1829+ entry->cluster = cluster;
1830+ entry->argp = argp;
1831+
1832+ do
1833+ {
1834+ entry->num++;
1835+ if (oshort (o) && ! find_char (o->key, hol->short_options, so))
1836+ /* O has a valid short option which hasn't already been used.*/
1837+ *so++ = o->key;
1838+ o++;
1839+ }
1840+ while (! oend (o) && oalias (o));
1841+ }
1842+ *so = '\0'; /* null terminated so we can find the length */
1843+ }
1844+
1845+ return hol;
1846+}
1847+
1848+/* Add a new cluster to HOL, with the given GROUP and HEADER (taken from the
1849+ associated argp child list entry), INDEX, and PARENT, and return a pointer
1850+ to it. ARGP is the argp that this cluster results from. */
1851+static struct hol_cluster *
1852+hol_add_cluster (struct hol *hol, int group, const char *header, int index,
1853+ struct hol_cluster *parent, const struct argp *argp)
1854+{
1855+ struct hol_cluster *cl = malloc (sizeof (struct hol_cluster));
1856+ if (cl)
1857+ {
1858+ cl->group = group;
1859+ cl->header = header;
1860+
1861+ cl->index = index;
1862+ cl->parent = parent;
1863+ cl->argp = argp;
1864+ cl->depth = parent ? parent->depth + 1 : 0;
1865+
1866+ cl->next = hol->clusters;
1867+ hol->clusters = cl;
1868+ }
1869+ return cl;
1870+}
1871+
1872+/* Free HOL and any resources it uses. */
1873+static void
1874+hol_free (struct hol *hol)
1875+{
1876+ struct hol_cluster *cl = hol->clusters;
1877+
1878+ while (cl)
1879+ {
1880+ struct hol_cluster *next = cl->next;
1881+ free (cl);
1882+ cl = next;
1883+ }
1884+
1885+ if (hol->num_entries > 0)
1886+ {
1887+ free (hol->entries);
1888+ free (hol->short_options);
1889+ }
1890+
1891+ free (hol);
1892+}
1893+
1894+static int
1895+hol_entry_short_iterate (const struct hol_entry *entry,
1896+ int (*func)(const struct argp_option *opt,
1897+ const struct argp_option *real,
1898+ const char *domain, void *cookie),
1899+ const char *domain, void *cookie)
1900+{
1901+ unsigned nopts;
1902+ int val = 0;
1903+ const struct argp_option *opt, *real = entry->opt;
1904+ char *so = entry->short_options;
1905+
1906+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
1907+ if (oshort (opt) && *so == opt->key)
1908+ {
1909+ if (!oalias (opt))
1910+ real = opt;
1911+ if (ovisible (opt))
1912+ val = (*func)(opt, real, domain, cookie);
1913+ so++;
1914+ }
1915+
1916+ return val;
1917+}
1918+
1919+static __inline__ int
1920+__attribute__ ((always_inline))
1921+hol_entry_long_iterate (const struct hol_entry *entry,
1922+ int (*func)(const struct argp_option *opt,
1923+ const struct argp_option *real,
1924+ const char *domain, void *cookie),
1925+ const char *domain, void *cookie)
1926+{
1927+ unsigned nopts;
1928+ int val = 0;
1929+ const struct argp_option *opt, *real = entry->opt;
1930+
1931+ for (opt = real, nopts = entry->num; nopts > 0 && !val; opt++, nopts--)
1932+ if (opt->name)
1933+ {
1934+ if (!oalias (opt))
1935+ real = opt;
1936+ if (ovisible (opt))
1937+ val = (*func)(opt, real, domain, cookie);
1938+ }
1939+
1940+ return val;
1941+}
1942+
1943+/* Iterator that returns true for the first short option. */
1944+static __inline__ int
1945+until_short (const struct argp_option *opt, const struct argp_option *real,
1946+ const char *domain, void *cookie)
1947+{
1948+ return oshort (opt) ? opt->key : 0;
1949+}
1950+
1951+/* Returns the first valid short option in ENTRY, or 0 if there is none. */
1952+static char
1953+hol_entry_first_short (const struct hol_entry *entry)
1954+{
1955+ return hol_entry_short_iterate (entry, until_short,
1956+ entry->argp->argp_domain, 0);
1957+}
1958+
1959+/* Returns the first valid long option in ENTRY, or 0 if there is none. */
1960+static const char *
1961+hol_entry_first_long (const struct hol_entry *entry)
1962+{
1963+ const struct argp_option *opt;
1964+ unsigned num;
1965+ for (opt = entry->opt, num = entry->num; num > 0; opt++, num--)
1966+ if (opt->name && ovisible (opt))
1967+ return opt->name;
1968+ return 0;
1969+}
1970+
1971+/* Returns the entry in HOL with the long option name NAME, or 0 if there is
1972+ none. */
1973+static struct hol_entry *
1974+hol_find_entry (struct hol *hol, const char *name)
1975+{
1976+ struct hol_entry *entry = hol->entries;
1977+ unsigned num_entries = hol->num_entries;
1978+
1979+ while (num_entries-- > 0)
1980+ {
1981+ const struct argp_option *opt = entry->opt;
1982+ unsigned num_opts = entry->num;
1983+
1984+ while (num_opts-- > 0)
1985+ if (opt->name && ovisible (opt) && strcmp (opt->name, name) == 0)
1986+ return entry;
1987+ else
1988+ opt++;
1989+
1990+ entry++;
1991+ }
1992+
1993+ return 0;
1994+}
1995+
1996+/* If an entry with the long option NAME occurs in HOL, set it's special
1997+ sort position to GROUP. */
1998+static void
1999+hol_set_group (struct hol *hol, const char *name, int group)
2000+{
2001+ struct hol_entry *entry = hol_find_entry (hol, name);
2002+ if (entry)
2003+ entry->group = group;
2004+}
2005+
2006+/* Order by group: 0, 1, 2, ..., n, -m, ..., -2, -1.
2007+ EQ is what to return if GROUP1 and GROUP2 are the same. */
2008+static int
2009+group_cmp (int group1, int group2, int eq)
2010+{
2011+ if (group1 == group2)
2012+ return eq;
2013+ else if ((group1 < 0 && group2 < 0) || (group1 >= 0 && group2 >= 0))
2014+ return group1 - group2;
2015+ else
2016+ return group2 - group1;
2017+}
2018+
2019+/* Compare clusters CL1 & CL2 by the order that they should appear in
2020+ output. */
2021+static int
2022+hol_cluster_cmp (const struct hol_cluster *cl1, const struct hol_cluster *cl2)
2023+{
2024+ /* If one cluster is deeper than the other, use its ancestor at the same
2025+ level, so that finding the common ancestor is straightforward. */
2026+ while (cl1->depth > cl2->depth)
2027+ cl1 = cl1->parent;
2028+ while (cl2->depth > cl1->depth)
2029+ cl2 = cl2->parent;
2030+
2031+ /* Now reduce both clusters to their ancestors at the point where both have
2032+ a common parent; these can be directly compared. */
2033+ while (cl1->parent != cl2->parent)
2034+ cl1 = cl1->parent, cl2 = cl2->parent;
2035+
2036+ return group_cmp (cl1->group, cl2->group, cl2->index - cl1->index);
2037+}
2038+
2039+/* Return the ancestor of CL that's just below the root (i.e., has a parent
2040+ of 0). */
2041+static struct hol_cluster *
2042+hol_cluster_base (struct hol_cluster *cl)
2043+{
2044+ while (cl->parent)
2045+ cl = cl->parent;
2046+ return cl;
2047+}
2048+
2049+/* Return true if CL1 is a child of CL2. */
2050+static int
2051+hol_cluster_is_child (const struct hol_cluster *cl1,
2052+ const struct hol_cluster *cl2)
2053+{
2054+ while (cl1 && cl1 != cl2)
2055+ cl1 = cl1->parent;
2056+ return cl1 == cl2;
2057+}
2058+
2059+/* Given the name of a OPTION_DOC option, modifies NAME to start at the tail
2060+ that should be used for comparisons, and returns true iff it should be
2061+ treated as a non-option. */
2062+static int
2063+canon_doc_option (const char **name)
2064+{
2065+ int non_opt;
2066+ /* Skip initial whitespace. */
2067+ while (isspace (**name))
2068+ (*name)++;
2069+ /* Decide whether this looks like an option (leading `-') or not. */
2070+ non_opt = (**name != '-');
2071+ /* Skip until part of name used for sorting. */
2072+ while (**name && !isalnum (**name))
2073+ (*name)++;
2074+ return non_opt;
2075+}
2076+
2077+/* Order ENTRY1 & ENTRY2 by the order which they should appear in a help
2078+ listing. */
2079+static int
2080+hol_entry_cmp (const struct hol_entry *entry1,
2081+ const struct hol_entry *entry2)
2082+{
2083+ /* The group numbers by which the entries should be ordered; if either is
2084+ in a cluster, then this is just the group within the cluster. */
2085+ int group1 = entry1->group, group2 = entry2->group;
2086+
2087+ if (entry1->cluster != entry2->cluster)
2088+ {
2089+ /* The entries are not within the same cluster, so we can't compare them
2090+ directly, we have to use the appropiate clustering level too. */
2091+ if (! entry1->cluster)
2092+ /* ENTRY1 is at the `base level', not in a cluster, so we have to
2093+ compare it's group number with that of the base cluster in which
2094+ ENTRY2 resides. Note that if they're in the same group, the
2095+ clustered option always comes laster. */
2096+ return group_cmp (group1, hol_cluster_base (entry2->cluster)->group, -1);
2097+ else if (! entry2->cluster)
2098+ /* Likewise, but ENTRY2's not in a cluster. */
2099+ return group_cmp (hol_cluster_base (entry1->cluster)->group, group2, 1);
2100+ else
2101+ /* Both entries are in clusters, we can just compare the clusters. */
2102+ return hol_cluster_cmp (entry1->cluster, entry2->cluster);
2103+ }
2104+ else if (group1 == group2)
2105+ /* The entries are both in the same cluster and group, so compare them
2106+ alphabetically. */
2107+ {
2108+ int short1 = hol_entry_first_short (entry1);
2109+ int short2 = hol_entry_first_short (entry2);
2110+ int doc1 = odoc (entry1->opt);
2111+ int doc2 = odoc (entry2->opt);
2112+ const char *long1 = hol_entry_first_long (entry1);
2113+ const char *long2 = hol_entry_first_long (entry2);
2114+
2115+ if (doc1)
2116+ doc1 = long1 != NULL && canon_doc_option (&long1);
2117+ if (doc2)
2118+ doc2 = long2 != NULL && canon_doc_option (&long2);
2119+
2120+ if (doc1 != doc2)
2121+ /* `documentation' options always follow normal options (or
2122+ documentation options that *look* like normal options). */
2123+ return doc1 - doc2;
2124+ else if (!short1 && !short2 && long1 && long2)
2125+ /* Only long options. */
2126+ return strcasecmp (long1, long2);
2127+ else
2128+ /* Compare short/short, long/short, short/long, using the first
2129+ character of long options. Entries without *any* valid
2130+ options (such as options with OPTION_HIDDEN set) will be put
2131+ first, but as they're not displayed, it doesn't matter where
2132+ they are. */
2133+ {
2134+ char first1 = short1 ? short1 : long1 ? *long1 : 0;
2135+ char first2 = short2 ? short2 : long2 ? *long2 : 0;
2136+#ifdef _tolower
2137+ int lower_cmp = _tolower (first1) - _tolower (first2);
2138+#else
2139+ int lower_cmp = tolower (first1) - tolower (first2);
2140+#endif
2141+ /* Compare ignoring case, except when the options are both the
2142+ same letter, in which case lower-case always comes first. */
2143+ return lower_cmp ? lower_cmp : first2 - first1;
2144+ }
2145+ }
2146+ else
2147+ /* Within the same cluster, but not the same group, so just compare
2148+ groups. */
2149+ return group_cmp (group1, group2, 0);
2150+}
2151+
2152+/* Version of hol_entry_cmp with correct signature for qsort. */
2153+static int
2154+hol_entry_qcmp (const void *entry1_v, const void *entry2_v)
2155+{
2156+ return hol_entry_cmp (entry1_v, entry2_v);
2157+}
2158+
2159+/* Sort HOL by group and alphabetically by option name (with short options
2160+ taking precedence over long). Since the sorting is for display purposes
2161+ only, the shadowing of options isn't effected. */
2162+static void
2163+hol_sort (struct hol *hol)
2164+{
2165+ if (hol->num_entries > 0)
2166+ qsort (hol->entries, hol->num_entries, sizeof (struct hol_entry),
2167+ hol_entry_qcmp);
2168+}
2169+
2170+/* Append MORE to HOL, destroying MORE in the process. Options in HOL shadow
2171+ any in MORE with the same name. */
2172+static void
2173+hol_append (struct hol *hol, struct hol *more)
2174+{
2175+ struct hol_cluster **cl_end = &hol->clusters;
2176+
2177+ /* Steal MORE's cluster list, and add it to the end of HOL's. */
2178+ while (*cl_end)
2179+ cl_end = &(*cl_end)->next;
2180+ *cl_end = more->clusters;
2181+ more->clusters = 0;
2182+
2183+ /* Merge entries. */
2184+ if (more->num_entries > 0)
2185+ {
2186+ if (hol->num_entries == 0)
2187+ {
2188+ hol->num_entries = more->num_entries;
2189+ hol->entries = more->entries;
2190+ hol->short_options = more->short_options;
2191+ more->num_entries = 0; /* Mark MORE's fields as invalid. */
2192+ }
2193+ else
2194+ /* Append the entries in MORE to those in HOL, taking care to only add
2195+ non-shadowed SHORT_OPTIONS values. */
2196+ {
2197+ unsigned left;
2198+ char *so, *more_so;
2199+ struct hol_entry *e;
2200+ unsigned num_entries = hol->num_entries + more->num_entries;
2201+ struct hol_entry *entries =
2202+ malloc (num_entries * sizeof (struct hol_entry));
2203+ unsigned hol_so_len = strlen (hol->short_options);
2204+ char *short_options =
2205+ malloc (hol_so_len + strlen (more->short_options) + 1);
2206+
2207+ assert (entries && short_options);
2208+#if SIZE_MAX <= UINT_MAX
2209+ assert (num_entries <= SIZE_MAX / sizeof (struct hol_entry));
2210+#endif
2211+
2212+ mempcpy (mempcpy (entries, hol->entries,
2213+ hol->num_entries * sizeof (struct hol_entry)),
2214+ more->entries,
2215+ more->num_entries * sizeof (struct hol_entry));
2216+
2217+ mempcpy (short_options, hol->short_options, hol_so_len);
2218+
2219+ /* Fix up the short options pointers from HOL. */
2220+ for (e = entries, left = hol->num_entries; left > 0; e++, left--)
2221+ e->short_options += (short_options - hol->short_options);
2222+
2223+ /* Now add the short options from MORE, fixing up its entries
2224+ too. */
2225+ so = short_options + hol_so_len;
2226+ more_so = more->short_options;
2227+ for (left = more->num_entries; left > 0; e++, left--)
2228+ {
2229+ int opts_left;
2230+ const struct argp_option *opt;
2231+
2232+ e->short_options = so;
2233+
2234+ for (opts_left = e->num, opt = e->opt; opts_left; opt++, opts_left--)
2235+ {
2236+ int ch = *more_so;
2237+ if (oshort (opt) && ch == opt->key)
2238+ /* The next short option in MORE_SO, CH, is from OPT. */
2239+ {
2240+ if (! find_char (ch, short_options,
2241+ short_options + hol_so_len))
2242+ /* The short option CH isn't shadowed by HOL's options,
2243+ so add it to the sum. */
2244+ *so++ = ch;
2245+ more_so++;
2246+ }
2247+ }
2248+ }
2249+
2250+ *so = '\0';
2251+
2252+ free (hol->entries);
2253+ free (hol->short_options);
2254+
2255+ hol->entries = entries;
2256+ hol->num_entries = num_entries;
2257+ hol->short_options = short_options;
2258+ }
2259+ }
2260+
2261+ hol_free (more);
2262+}
2263+
2264+/* Inserts enough spaces to make sure STREAM is at column COL. */
2265+static void
2266+indent_to (argp_fmtstream_t stream, unsigned col)
2267+{
2268+ int needed = col - __argp_fmtstream_point (stream);
2269+ while (needed-- > 0)
2270+ __argp_fmtstream_putc (stream, ' ');
2271+}
2272+
2273+/* Output to STREAM either a space, or a newline if there isn't room for at
2274+ least ENSURE characters before the right margin. */
2275+static void
2276+space (argp_fmtstream_t stream, size_t ensure)
2277+{
2278+ if (__argp_fmtstream_point (stream) + ensure
2279+ >= __argp_fmtstream_rmargin (stream))
2280+ __argp_fmtstream_putc (stream, '\n');
2281+ else
2282+ __argp_fmtstream_putc (stream, ' ');
2283+}
2284+
2285+/* If the option REAL has an argument, we print it in using the printf
2286+ format REQ_FMT or OPT_FMT depending on whether it's a required or
2287+ optional argument. */
2288+static void
2289+arg (const struct argp_option *real, const char *req_fmt, const char *opt_fmt,
2290+ const char *domain, argp_fmtstream_t stream)
2291+{
2292+ if (real->arg)
2293+ {
2294+ if (real->flags & OPTION_ARG_OPTIONAL)
2295+ __argp_fmtstream_printf (stream, opt_fmt,
2296+ dgettext (domain, real->arg));
2297+ else
2298+ __argp_fmtstream_printf (stream, req_fmt,
2299+ dgettext (domain, real->arg));
2300+ }
2301+}
2302+
2303+/* Helper functions for hol_entry_help. */
2304+
2305+/* State used during the execution of hol_help. */
2306+struct hol_help_state
2307+{
2308+ /* PREV_ENTRY should contain the previous entry printed, or 0. */
2309+ struct hol_entry *prev_entry;
2310+
2311+ /* If an entry is in a different group from the previous one, and SEP_GROUPS
2312+ is true, then a blank line will be printed before any output. */
2313+ int sep_groups;
2314+
2315+ /* True if a duplicate option argument was suppressed (only ever set if
2316+ UPARAMS.dup_args is false). */
2317+ int suppressed_dup_arg;
2318+};
2319+
2320+/* Some state used while printing a help entry (used to communicate with
2321+ helper functions). See the doc for hol_entry_help for more info, as most
2322+ of the fields are copied from its arguments. */
2323+struct pentry_state
2324+{
2325+ const struct hol_entry *entry;
2326+ argp_fmtstream_t stream;
2327+ struct hol_help_state *hhstate;
2328+
2329+ /* True if nothing's been printed so far. */
2330+ int first;
2331+
2332+ /* If non-zero, the state that was used to print this help. */
2333+ const struct argp_state *state;
2334+};
2335+
2336+/* If a user doc filter should be applied to DOC, do so. */
2337+static const char *
2338+filter_doc (const char *doc, int key, const struct argp *argp,
2339+ const struct argp_state *state)
2340+{
2341+ if (argp && argp->help_filter)
2342+ /* We must apply a user filter to this output. */
2343+ {
2344+ void *input = __argp_input (argp, state);
2345+ return (*argp->help_filter) (key, doc, input);
2346+ }
2347+ else
2348+ /* No filter. */
2349+ return doc;
2350+}
2351+
2352+/* Prints STR as a header line, with the margin lines set appropiately, and
2353+ notes the fact that groups should be separated with a blank line. ARGP is
2354+ the argp that should dictate any user doc filtering to take place. Note
2355+ that the previous wrap margin isn't restored, but the left margin is reset
2356+ to 0. */
2357+static void
2358+print_header (const char *str, const struct argp *argp,
2359+ struct pentry_state *pest)
2360+{
2361+ const char *tstr = dgettext (argp->argp_domain, str);
2362+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_HEADER, argp, pest->state);
2363+
2364+ if (fstr)
2365+ {
2366+ if (*fstr)
2367+ {
2368+ if (pest->hhstate->prev_entry)
2369+ /* Precede with a blank line. */
2370+ __argp_fmtstream_putc (pest->stream, '\n');
2371+ indent_to (pest->stream, uparams.header_col);
2372+ __argp_fmtstream_set_lmargin (pest->stream, uparams.header_col);
2373+ __argp_fmtstream_set_wmargin (pest->stream, uparams.header_col);
2374+ __argp_fmtstream_puts (pest->stream, fstr);
2375+ __argp_fmtstream_set_lmargin (pest->stream, 0);
2376+ __argp_fmtstream_putc (pest->stream, '\n');
2377+ }
2378+
2379+ pest->hhstate->sep_groups = 1; /* Separate subsequent groups. */
2380+ }
2381+
2382+ if (fstr != tstr)
2383+ free ((char *) fstr);
2384+}
2385+
2386+/* Inserts a comma if this isn't the first item on the line, and then makes
2387+ sure we're at least to column COL. If this *is* the first item on a line,
2388+ prints any pending whitespace/headers that should precede this line. Also
2389+ clears FIRST. */
2390+static void
2391+comma (unsigned col, struct pentry_state *pest)
2392+{
2393+ if (pest->first)
2394+ {
2395+ const struct hol_entry *pe = pest->hhstate->prev_entry;
2396+ const struct hol_cluster *cl = pest->entry->cluster;
2397+
2398+ if (pest->hhstate->sep_groups && pe && pest->entry->group != pe->group)
2399+ __argp_fmtstream_putc (pest->stream, '\n');
2400+
2401+ if (cl && cl->header && *cl->header
2402+ && (!pe
2403+ || (pe->cluster != cl
2404+ && !hol_cluster_is_child (pe->cluster, cl))))
2405+ /* If we're changing clusters, then this must be the start of the
2406+ ENTRY's cluster unless that is an ancestor of the previous one
2407+ (in which case we had just popped into a sub-cluster for a bit).
2408+ If so, then print the cluster's header line. */
2409+ {
2410+ int old_wm = __argp_fmtstream_wmargin (pest->stream);
2411+ print_header (cl->header, cl->argp, pest);
2412+ __argp_fmtstream_set_wmargin (pest->stream, old_wm);
2413+ }
2414+
2415+ pest->first = 0;
2416+ }
2417+ else
2418+ __argp_fmtstream_puts (pest->stream, ", ");
2419+
2420+ indent_to (pest->stream, col);
2421+}
2422+
2423+/* Print help for ENTRY to STREAM. */
2424+static void
2425+hol_entry_help (struct hol_entry *entry, const struct argp_state *state,
2426+ argp_fmtstream_t stream, struct hol_help_state *hhstate)
2427+{
2428+ unsigned num;
2429+ const struct argp_option *real = entry->opt, *opt;
2430+ char *so = entry->short_options;
2431+ int have_long_opt = 0; /* We have any long options. */
2432+ /* Saved margins. */
2433+ int old_lm = __argp_fmtstream_set_lmargin (stream, 0);
2434+ int old_wm = __argp_fmtstream_wmargin (stream);
2435+ /* PEST is a state block holding some of our variables that we'd like to
2436+ share with helper functions. */
2437+ struct pentry_state pest = { entry, stream, hhstate, 1, state };
2438+
2439+ if (! odoc (real))
2440+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2441+ if (opt->name && ovisible (opt))
2442+ {
2443+ have_long_opt = 1;
2444+ break;
2445+ }
2446+
2447+ /* First emit short options. */
2448+ __argp_fmtstream_set_wmargin (stream, uparams.short_opt_col); /* For truly bizarre cases. */
2449+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2450+ if (oshort (opt) && opt->key == *so)
2451+ /* OPT has a valid (non shadowed) short option. */
2452+ {
2453+ if (ovisible (opt))
2454+ {
2455+ comma (uparams.short_opt_col, &pest);
2456+ __argp_fmtstream_putc (stream, '-');
2457+ __argp_fmtstream_putc (stream, *so);
2458+ if (!have_long_opt || uparams.dup_args)
2459+ arg (real, " %s", "[%s]",
2460+ state == NULL ? NULL : state->root_argp->argp_domain,
2461+ stream);
2462+ else if (real->arg)
2463+ hhstate->suppressed_dup_arg = 1;
2464+ }
2465+ so++;
2466+ }
2467+
2468+ /* Now, long options. */
2469+ if (odoc (real))
2470+ /* A `documentation' option. */
2471+ {
2472+ __argp_fmtstream_set_wmargin (stream, uparams.doc_opt_col);
2473+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2474+ if (opt->name && ovisible (opt))
2475+ {
2476+ comma (uparams.doc_opt_col, &pest);
2477+ /* Calling gettext here isn't quite right, since sorting will
2478+ have been done on the original; but documentation options
2479+ should be pretty rare anyway... */
2480+ __argp_fmtstream_puts (stream,
2481+ dgettext (state == NULL ? NULL
2482+ : state->root_argp->argp_domain,
2483+ opt->name));
2484+ }
2485+ }
2486+ else
2487+ /* A real long option. */
2488+ {
2489+ __argp_fmtstream_set_wmargin (stream, uparams.long_opt_col);
2490+ for (opt = real, num = entry->num; num > 0; opt++, num--)
2491+ if (opt->name && ovisible (opt))
2492+ {
2493+ comma (uparams.long_opt_col, &pest);
2494+ __argp_fmtstream_printf (stream, "--%s", opt->name);
2495+ arg (real, "=%s", "[=%s]",
2496+ state == NULL ? NULL : state->root_argp->argp_domain, stream);
2497+ }
2498+ }
2499+
2500+ /* Next, documentation strings. */
2501+ __argp_fmtstream_set_lmargin (stream, 0);
2502+
2503+ if (pest.first)
2504+ {
2505+ /* Didn't print any switches, what's up? */
2506+ if (!oshort (real) && !real->name)
2507+ /* This is a group header, print it nicely. */
2508+ print_header (real->doc, entry->argp, &pest);
2509+ else
2510+ /* Just a totally shadowed option or null header; print nothing. */
2511+ goto cleanup; /* Just return, after cleaning up. */
2512+ }
2513+ else
2514+ {
2515+ const char *tstr = real->doc ? dgettext (state == NULL ? NULL
2516+ : state->root_argp->argp_domain,
2517+ real->doc) : 0;
2518+ const char *fstr = filter_doc (tstr, real->key, entry->argp, state);
2519+ if (fstr && *fstr)
2520+ {
2521+ unsigned int col = __argp_fmtstream_point (stream);
2522+
2523+ __argp_fmtstream_set_lmargin (stream, uparams.opt_doc_col);
2524+ __argp_fmtstream_set_wmargin (stream, uparams.opt_doc_col);
2525+
2526+ if (col > (unsigned int) (uparams.opt_doc_col + 3))
2527+ __argp_fmtstream_putc (stream, '\n');
2528+ else if (col >= (unsigned int) uparams.opt_doc_col)
2529+ __argp_fmtstream_puts (stream, " ");
2530+ else
2531+ indent_to (stream, uparams.opt_doc_col);
2532+
2533+ __argp_fmtstream_puts (stream, fstr);
2534+ }
2535+ if (fstr && fstr != tstr)
2536+ free ((char *) fstr);
2537+
2538+ /* Reset the left margin. */
2539+ __argp_fmtstream_set_lmargin (stream, 0);
2540+ __argp_fmtstream_putc (stream, '\n');
2541+ }
2542+
2543+ hhstate->prev_entry = entry;
2544+
2545+cleanup:
2546+ __argp_fmtstream_set_lmargin (stream, old_lm);
2547+ __argp_fmtstream_set_wmargin (stream, old_wm);
2548+}
2549+
2550+/* Output a long help message about the options in HOL to STREAM. */
2551+static void
2552+hol_help (struct hol *hol, const struct argp_state *state,
2553+ argp_fmtstream_t stream)
2554+{
2555+ unsigned num;
2556+ struct hol_entry *entry;
2557+ struct hol_help_state hhstate = { 0, 0, 0 };
2558+
2559+ for (entry = hol->entries, num = hol->num_entries; num > 0; entry++, num--)
2560+ hol_entry_help (entry, state, stream, &hhstate);
2561+
2562+ if (hhstate.suppressed_dup_arg && uparams.dup_args_note)
2563+ {
2564+ const char *tstr = dgettext (state == NULL ? NULL
2565+ : state->root_argp->argp_domain, "\
2566+Mandatory or optional arguments to long options are also mandatory or \
2567+optional for any corresponding short options.");
2568+ const char *fstr = filter_doc (tstr, ARGP_KEY_HELP_DUP_ARGS_NOTE,
2569+ state ? state->root_argp : 0, state);
2570+ if (fstr && *fstr)
2571+ {
2572+ __argp_fmtstream_putc (stream, '\n');
2573+ __argp_fmtstream_puts (stream, fstr);
2574+ __argp_fmtstream_putc (stream, '\n');
2575+ }
2576+ if (fstr && fstr != tstr)
2577+ free ((char *) fstr);
2578+ }
2579+}
2580+
2581+/* Helper functions for hol_usage. */
2582+
2583+/* If OPT is a short option without an arg, append its key to the string
2584+ pointer pointer to by COOKIE, and advance the pointer. */
2585+static int
2586+add_argless_short_opt (const struct argp_option *opt,
2587+ const struct argp_option *real,
2588+ const char *domain, void *cookie)
2589+{
2590+ char **snao_end = cookie;
2591+ if (!(opt->arg || real->arg)
2592+ && !((opt->flags | real->flags) & OPTION_NO_USAGE))
2593+ *(*snao_end)++ = opt->key;
2594+ return 0;
2595+}
2596+
2597+/* If OPT is a short option with an arg, output a usage entry for it to the
2598+ stream pointed at by COOKIE. */
2599+static int
2600+usage_argful_short_opt (const struct argp_option *opt,
2601+ const struct argp_option *real,
2602+ const char *domain, void *cookie)
2603+{
2604+ argp_fmtstream_t stream = cookie;
2605+ const char *arg = opt->arg;
2606+ int flags = opt->flags | real->flags;
2607+
2608+ if (! arg)
2609+ arg = real->arg;
2610+
2611+ if (arg && !(flags & OPTION_NO_USAGE))
2612+ {
2613+ arg = dgettext (domain, arg);
2614+
2615+ if (flags & OPTION_ARG_OPTIONAL)
2616+ __argp_fmtstream_printf (stream, " [-%c[%s]]", opt->key, arg);
2617+ else
2618+ {
2619+ /* Manually do line wrapping so that it (probably) won't
2620+ get wrapped at the embedded space. */
2621+ space (stream, 6 + strlen (arg));
2622+ __argp_fmtstream_printf (stream, "[-%c %s]", opt->key, arg);
2623+ }
2624+ }
2625+
2626+ return 0;
2627+}
2628+
2629+/* Output a usage entry for the long option opt to the stream pointed at by
2630+ COOKIE. */
2631+static int
2632+usage_long_opt (const struct argp_option *opt,
2633+ const struct argp_option *real,
2634+ const char *domain, void *cookie)
2635+{
2636+ argp_fmtstream_t stream = cookie;
2637+ const char *arg = opt->arg;
2638+ int flags = opt->flags | real->flags;
2639+
2640+ if (! arg)
2641+ arg = real->arg;
2642+
2643+ if (! (flags & OPTION_NO_USAGE))
2644+ {
2645+ if (arg)
2646+ {
2647+ arg = dgettext (domain, arg);
2648+ if (flags & OPTION_ARG_OPTIONAL)
2649+ __argp_fmtstream_printf (stream, " [--%s[=%s]]", opt->name, arg);
2650+ else
2651+ __argp_fmtstream_printf (stream, " [--%s=%s]", opt->name, arg);
2652+ }
2653+ else
2654+ __argp_fmtstream_printf (stream, " [--%s]", opt->name);
2655+ }
2656+
2657+ return 0;
2658+}
2659+
2660+/* Print a short usage description for the arguments in HOL to STREAM. */
2661+static void
2662+hol_usage (struct hol *hol, argp_fmtstream_t stream)
2663+{
2664+ if (hol->num_entries > 0)
2665+ {
2666+ unsigned nentries;
2667+ struct hol_entry *entry;
2668+ char *short_no_arg_opts = alloca (strlen (hol->short_options) + 1);
2669+ char *snao_end = short_no_arg_opts;
2670+
2671+ /* First we put a list of short options without arguments. */
2672+ for (entry = hol->entries, nentries = hol->num_entries
2673+ ; nentries > 0
2674+ ; entry++, nentries--)
2675+ hol_entry_short_iterate (entry, add_argless_short_opt,
2676+ entry->argp->argp_domain, &snao_end);
2677+ if (snao_end > short_no_arg_opts)
2678+ {
2679+ *snao_end++ = 0;
2680+ __argp_fmtstream_printf (stream, " [-%s]", short_no_arg_opts);
2681+ }
2682+
2683+ /* Now a list of short options *with* arguments. */
2684+ for (entry = hol->entries, nentries = hol->num_entries
2685+ ; nentries > 0
2686+ ; entry++, nentries--)
2687+ hol_entry_short_iterate (entry, usage_argful_short_opt,
2688+ entry->argp->argp_domain, stream);
2689+
2690+ /* Finally, a list of long options (whew!). */
2691+ for (entry = hol->entries, nentries = hol->num_entries
2692+ ; nentries > 0
2693+ ; entry++, nentries--)
2694+ hol_entry_long_iterate (entry, usage_long_opt,
2695+ entry->argp->argp_domain, stream);
2696+ }
2697+}
2698+
2699+/* Make a HOL containing all levels of options in ARGP. CLUSTER is the
2700+ cluster in which ARGP's entries should be clustered, or 0. */
2701+static struct hol *
2702+argp_hol (const struct argp *argp, struct hol_cluster *cluster)
2703+{
2704+ const struct argp_child *child = argp->children;
2705+ struct hol *hol = make_hol (argp, cluster);
2706+ if (child)
2707+ while (child->argp)
2708+ {
2709+ struct hol_cluster *child_cluster =
2710+ ((child->group || child->header)
2711+ /* Put CHILD->argp within its own cluster. */
2712+ ? hol_add_cluster (hol, child->group, child->header,
2713+ child - argp->children, cluster, argp)
2714+ /* Just merge it into the parent's cluster. */
2715+ : cluster);
2716+ hol_append (hol, argp_hol (child->argp, child_cluster)) ;
2717+ child++;
2718+ }
2719+ return hol;
2720+}
2721+
2722+/* Calculate how many different levels with alternative args strings exist in
2723+ ARGP. */
2724+static size_t
2725+argp_args_levels (const struct argp *argp)
2726+{
2727+ size_t levels = 0;
2728+ const struct argp_child *child = argp->children;
2729+
2730+ if (argp->args_doc && strchr (argp->args_doc, '\n'))
2731+ levels++;
2732+
2733+ if (child)
2734+ while (child->argp)
2735+ levels += argp_args_levels ((child++)->argp);
2736+
2737+ return levels;
2738+}
2739+
2740+/* Print all the non-option args documented in ARGP to STREAM. Any output is
2741+ preceded by a space. LEVELS is a pointer to a byte vector the length
2742+ returned by argp_args_levels; it should be initialized to zero, and
2743+ updated by this routine for the next call if ADVANCE is true. True is
2744+ returned as long as there are more patterns to output. */
2745+static int
2746+argp_args_usage (const struct argp *argp, const struct argp_state *state,
2747+ char **levels, int advance, argp_fmtstream_t stream)
2748+{
2749+ char *our_level = *levels;
2750+ int multiple = 0;
2751+ const struct argp_child *child = argp->children;
2752+ const char *tdoc = dgettext (argp->argp_domain, argp->args_doc), *nl = 0;
2753+ const char *fdoc = filter_doc (tdoc, ARGP_KEY_HELP_ARGS_DOC, argp, state);
2754+
2755+ if (fdoc)
2756+ {
2757+ const char *cp = fdoc;
2758+ nl = strchrnul (cp, '\n');
2759+ if (*nl != '\0')
2760+ /* This is a `multi-level' args doc; advance to the correct position
2761+ as determined by our state in LEVELS, and update LEVELS. */
2762+ {
2763+ int i;
2764+ multiple = 1;
2765+ for (i = 0; i < *our_level; i++)
2766+ cp = nl + 1, nl = strchrnul (cp, '\n');
2767+ (*levels)++;
2768+ }
2769+
2770+ /* Manually do line wrapping so that it (probably) won't get wrapped at
2771+ any embedded spaces. */
2772+ space (stream, 1 + nl - cp);
2773+
2774+ __argp_fmtstream_write (stream, cp, nl - cp);
2775+ }
2776+ if (fdoc && fdoc != tdoc)
2777+ free ((char *)fdoc); /* Free user's modified doc string. */
2778+
2779+ if (child)
2780+ while (child->argp)
2781+ advance = !argp_args_usage ((child++)->argp, state, levels, advance, stream);
2782+
2783+ if (advance && multiple)
2784+ {
2785+ /* Need to increment our level. */
2786+ if (*nl)
2787+ /* There's more we can do here. */
2788+ {
2789+ (*our_level)++;
2790+ advance = 0; /* Our parent shouldn't advance also. */
2791+ }
2792+ else if (*our_level > 0)
2793+ /* We had multiple levels, but used them up; reset to zero. */
2794+ *our_level = 0;
2795+ }
2796+
2797+ return !advance;
2798+}
2799+
2800+/* Print the documentation for ARGP to STREAM; if POST is false, then
2801+ everything preceeding a `\v' character in the documentation strings (or
2802+ the whole string, for those with none) is printed, otherwise, everything
2803+ following the `\v' character (nothing for strings without). Each separate
2804+ bit of documentation is separated a blank line, and if PRE_BLANK is true,
2805+ then the first is as well. If FIRST_ONLY is true, only the first
2806+ occurrence is output. Returns true if anything was output. */
2807+static int
2808+argp_doc (const struct argp *argp, const struct argp_state *state,
2809+ int post, int pre_blank, int first_only,
2810+ argp_fmtstream_t stream)
2811+{
2812+ const char *text;
2813+ const char *inp_text;
2814+ void *input = 0;
2815+ int anything = 0;
2816+ size_t inp_text_limit = 0;
2817+ const char *doc = dgettext (argp->argp_domain, argp->doc);
2818+ const struct argp_child *child = argp->children;
2819+
2820+ if (doc)
2821+ {
2822+ char *vt = strchr (doc, '\v');
2823+ inp_text = post ? (vt ? vt + 1 : 0) : doc;
2824+ inp_text_limit = (!post && vt) ? (vt - doc) : 0;
2825+ }
2826+ else
2827+ inp_text = 0;
2828+
2829+ if (argp->help_filter)
2830+ /* We have to filter the doc strings. */
2831+ {
2832+ if (inp_text_limit)
2833+ /* Copy INP_TEXT so that it's nul-terminated. */
2834+ inp_text = strndup (inp_text, inp_text_limit);
2835+ input = __argp_input (argp, state);
2836+ text =
2837+ (*argp->help_filter) (post
2838+ ? ARGP_KEY_HELP_POST_DOC
2839+ : ARGP_KEY_HELP_PRE_DOC,
2840+ inp_text, input);
2841+ }
2842+ else
2843+ text = (const char *) inp_text;
2844+
2845+ if (text)
2846+ {
2847+ if (pre_blank)
2848+ __argp_fmtstream_putc (stream, '\n');
2849+
2850+ if (text == inp_text && inp_text_limit)
2851+ __argp_fmtstream_write (stream, inp_text, inp_text_limit);
2852+ else
2853+ __argp_fmtstream_puts (stream, text);
2854+
2855+ if (__argp_fmtstream_point (stream) > __argp_fmtstream_lmargin (stream))
2856+ __argp_fmtstream_putc (stream, '\n');
2857+
2858+ anything = 1;
2859+ }
2860+
2861+ if (text && text != inp_text)
2862+ free ((char *) text); /* Free TEXT returned from the help filter. */
2863+ if (inp_text && inp_text_limit && argp->help_filter)
2864+ free ((char *) inp_text); /* We copied INP_TEXT, so free it now. */
2865+
2866+ if (post && argp->help_filter)
2867+ /* Now see if we have to output a ARGP_KEY_HELP_EXTRA text. */
2868+ {
2869+ text = (*argp->help_filter) (ARGP_KEY_HELP_EXTRA, 0, input);
2870+ if (text)
2871+ {
2872+ if (anything || pre_blank)
2873+ __argp_fmtstream_putc (stream, '\n');
2874+ __argp_fmtstream_puts (stream, text);
2875+ free ((char *) text);
2876+ if (__argp_fmtstream_point (stream)
2877+ > __argp_fmtstream_lmargin (stream))
2878+ __argp_fmtstream_putc (stream, '\n');
2879+ anything = 1;
2880+ }
2881+ }
2882+
2883+ if (child)
2884+ while (child->argp && !(first_only && anything))
2885+ anything |=
2886+ argp_doc ((child++)->argp, state,
2887+ post, anything || pre_blank, first_only,
2888+ stream);
2889+
2890+ return anything;
2891+}
2892+
2893+/* Output a usage message for ARGP to STREAM. If called from
2894+ argp_state_help, STATE is the relevent parsing state. FLAGS are from the
2895+ set ARGP_HELP_*. NAME is what to use wherever a `program name' is
2896+ needed. */
2897+static void
2898+_help (const struct argp *argp, const struct argp_state *state, FILE *stream,
2899+ unsigned flags, char *name)
2900+{
2901+ int anything = 0; /* Whether we've output anything. */
2902+ struct hol *hol = 0;
2903+ argp_fmtstream_t fs;
2904+
2905+ if (! stream)
2906+ return;
2907+
2908+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
2909+ flockfile (stream);
2910+#endif
2911+
2912+ fill_in_uparams (state);
2913+
2914+ fs = __argp_make_fmtstream (stream, 0, uparams.rmargin, 0);
2915+ if (! fs)
2916+ {
2917+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
2918+ funlockfile (stream);
2919+#endif
2920+ return;
2921+ }
2922+
2923+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE | ARGP_HELP_LONG))
2924+ {
2925+ hol = argp_hol (argp, 0);
2926+
2927+ /* If present, these options always come last. */
2928+ hol_set_group (hol, "help", -1);
2929+ hol_set_group (hol, "version", -1);
2930+
2931+ hol_sort (hol);
2932+ }
2933+
2934+ if (flags & (ARGP_HELP_USAGE | ARGP_HELP_SHORT_USAGE))
2935+ /* Print a short `Usage:' message. */
2936+ {
2937+ int first_pattern = 1, more_patterns;
2938+ size_t num_pattern_levels = argp_args_levels (argp);
2939+ char *pattern_levels = alloca (num_pattern_levels);
2940+
2941+ memset (pattern_levels, 0, num_pattern_levels);
2942+
2943+ do
2944+ {
2945+ int old_lm;
2946+ int old_wm = __argp_fmtstream_set_wmargin (fs, uparams.usage_indent);
2947+ char *levels = pattern_levels;
2948+
2949+ if (first_pattern)
2950+ __argp_fmtstream_printf (fs, "%s %s",
2951+ dgettext (argp->argp_domain, "Usage:"),
2952+ name);
2953+ else
2954+ __argp_fmtstream_printf (fs, "%s %s",
2955+ dgettext (argp->argp_domain, " or: "),
2956+ name);
2957+
2958+ /* We set the lmargin as well as the wmargin, because hol_usage
2959+ manually wraps options with newline to avoid annoying breaks. */
2960+ old_lm = __argp_fmtstream_set_lmargin (fs, uparams.usage_indent);
2961+
2962+ if (flags & ARGP_HELP_SHORT_USAGE)
2963+ /* Just show where the options go. */
2964+ {
2965+ if (hol->num_entries > 0)
2966+ __argp_fmtstream_puts (fs, dgettext (argp->argp_domain,
2967+ " [OPTION...]"));
2968+ }
2969+ else
2970+ /* Actually print the options. */
2971+ {
2972+ hol_usage (hol, fs);
2973+ flags |= ARGP_HELP_SHORT_USAGE; /* But only do so once. */
2974+ }
2975+
2976+ more_patterns = argp_args_usage (argp, state, &levels, 1, fs);
2977+
2978+ __argp_fmtstream_set_wmargin (fs, old_wm);
2979+ __argp_fmtstream_set_lmargin (fs, old_lm);
2980+
2981+ __argp_fmtstream_putc (fs, '\n');
2982+ anything = 1;
2983+
2984+ first_pattern = 0;
2985+ }
2986+ while (more_patterns);
2987+ }
2988+
2989+ if (flags & ARGP_HELP_PRE_DOC)
2990+ anything |= argp_doc (argp, state, 0, 0, 1, fs);
2991+
2992+ if (flags & ARGP_HELP_SEE)
2993+ {
2994+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain, "\
2995+Try `%s --help' or `%s --usage' for more information.\n"),
2996+ name, name);
2997+ anything = 1;
2998+ }
2999+
3000+ if (flags & ARGP_HELP_LONG)
3001+ /* Print a long, detailed help message. */
3002+ {
3003+ /* Print info about all the options. */
3004+ if (hol->num_entries > 0)
3005+ {
3006+ if (anything)
3007+ __argp_fmtstream_putc (fs, '\n');
3008+ hol_help (hol, state, fs);
3009+ anything = 1;
3010+ }
3011+ }
3012+
3013+ if (flags & ARGP_HELP_POST_DOC)
3014+ /* Print any documentation strings at the end. */
3015+ anything |= argp_doc (argp, state, 1, anything, 0, fs);
3016+
3017+ if ((flags & ARGP_HELP_BUG_ADDR) && argp_program_bug_address)
3018+ {
3019+ if (anything)
3020+ __argp_fmtstream_putc (fs, '\n');
3021+ __argp_fmtstream_printf (fs, dgettext (argp->argp_domain,
3022+ "Report bugs to %s.\n"),
3023+ argp_program_bug_address);
3024+ anything = 1;
3025+ }
3026+
3027+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3028+ funlockfile (stream);
3029+#endif
3030+
3031+ if (hol)
3032+ hol_free (hol);
3033+
3034+ __argp_fmtstream_free (fs);
3035+}
3036+
3037+/* Output a usage message for ARGP to STREAM. FLAGS are from the set
3038+ ARGP_HELP_*. NAME is what to use wherever a `program name' is needed. */
3039+void argp_help (const struct argp *argp, FILE *stream,
3040+ unsigned flags, char *name)
3041+{
3042+ _help (argp, 0, stream, flags, name);
3043+}
3044+
3045+char *
3046+__argp_short_program_name (void)
3047+{
3048+# ifdef __UCLIBC_HAS_PROGRAM_INVOCATION_NAME__
3049+/*
3050+ * uClibc provides both program_invocation_name and
3051+ * program_invocation_short_name
3052+ */
3053+ return (char *) program_invocation_short_name;
3054+# else
3055+ /* FIXME: What now? Miles suggests that it is better to use NULL,
3056+ but currently the value is passed on directly to fputs_unlocked,
3057+ so that requires more changes. */
3058+# if __GNUC__
3059+# warning No reasonable value to return
3060+# endif /* __GNUC__ */
3061+ return "";
3062+# endif
3063+}
3064+
3065+/* Output, if appropriate, a usage message for STATE to STREAM. FLAGS are
3066+ from the set ARGP_HELP_*. */
3067+void
3068+argp_state_help (const struct argp_state *state, FILE *stream, unsigned flags)
3069+{
3070+ if ((!state || ! (state->flags & ARGP_NO_ERRS)) && stream)
3071+ {
3072+ if (state && (state->flags & ARGP_LONG_ONLY))
3073+ flags |= ARGP_HELP_LONG_ONLY;
3074+
3075+ _help (state ? state->root_argp : 0, state, stream, flags,
3076+ state ? state->name : __argp_short_program_name ());
3077+
3078+ if (!state || ! (state->flags & ARGP_NO_EXIT))
3079+ {
3080+ if (flags & ARGP_HELP_EXIT_ERR)
3081+ exit (argp_err_exit_status);
3082+ if (flags & ARGP_HELP_EXIT_OK)
3083+ exit (0);
3084+ }
3085+ }
3086+}
3087+
3088+/* If appropriate, print the printf string FMT and following args, preceded
3089+ by the program name and `:', to stderr, and followed by a `Try ... --help'
3090+ message, then exit (1). */
3091+void
3092+argp_error (const struct argp_state *state, const char *fmt, ...)
3093+{
3094+ if (!state || !(state->flags & ARGP_NO_ERRS))
3095+ {
3096+ FILE *stream = state ? state->err_stream : stderr;
3097+
3098+ if (stream)
3099+ {
3100+ va_list ap;
3101+
3102+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3103+ flockfile (stream);
3104+#endif
3105+
3106+ va_start (ap, fmt);
3107+
3108+#if defined _LIBC && defined USE_IN_LIBIO
3109+ char *buf;
3110+
3111+ if (_IO_vasprintf (&buf, fmt, ap) < 0)
3112+ buf = NULL;
3113+
3114+ __fxprintf (stream, "%s: %s\n",
3115+ state ? state->name : __argp_short_program_name (), buf);
3116+
3117+ free (buf);
3118+#else
3119+ fputs_unlocked (state ? state->name : __argp_short_program_name (),
3120+ stream);
3121+ putc_unlocked (':', stream);
3122+ putc_unlocked (' ', stream);
3123+
3124+ vfprintf (stream, fmt, ap);
3125+
3126+ putc_unlocked ('\n', stream);
3127+#endif
3128+
3129+ argp_state_help (state, stream, ARGP_HELP_STD_ERR);
3130+
3131+ va_end (ap);
3132+
3133+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3134+ funlockfile (stream);
3135+#endif
3136+ }
3137+ }
3138+}
3139+
3140+/* Similar to the standard gnu error-reporting function error(), but will
3141+ respect the ARGP_NO_EXIT and ARGP_NO_ERRS flags in STATE, and will print
3142+ to STATE->err_stream. This is useful for argument parsing code that is
3143+ shared between program startup (when exiting is desired) and runtime
3144+ option parsing (when typically an error code is returned instead). The
3145+ difference between this function and argp_error is that the latter is for
3146+ *parsing errors*, and the former is for other problems that occur during
3147+ parsing but don't reflect a (syntactic) problem with the input. */
3148+void
3149+argp_failure (const struct argp_state *state, int status, int errnum,
3150+ const char *fmt, ...)
3151+{
3152+ if (!state || !(state->flags & ARGP_NO_ERRS))
3153+ {
3154+ FILE *stream = state ? state->err_stream : stderr;
3155+
3156+ if (stream)
3157+ {
3158+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3159+ flockfile (stream);
3160+#endif
3161+
3162+#if defined _LIBC && defined USE_IN_LIBIO
3163+ __fxprintf (stream, "%s",
3164+ state ? state->name : __argp_short_program_name ());
3165+#else
3166+ fputs_unlocked (state ? state->name : __argp_short_program_name (),
3167+ stream);
3168+#endif
3169+
3170+ if (fmt)
3171+ {
3172+ va_list ap;
3173+
3174+ va_start (ap, fmt);
3175+#if defined _LIBC && defined USE_IN_LIBIO
3176+ char *buf;
3177+
3178+ if (_IO_vasprintf (&buf, fmt, ap) < 0)
3179+ buf = NULL;
3180+
3181+ __fxprintf (stream, ": %s", buf);
3182+
3183+ free (buf);
3184+#else
3185+ putc_unlocked (':', stream);
3186+ putc_unlocked (' ', stream);
3187+
3188+ vfprintf (stream, fmt, ap);
3189+#endif
3190+
3191+ va_end (ap);
3192+ }
3193+
3194+ if (errnum)
3195+ {
3196+#if (defined _LIBC && defined USE_IN_LIBIO) || defined HAVE_STRERROR_R
3197+ char buf[200];
3198+#endif
3199+#if defined _LIBC && defined USE_IN_LIBIO
3200+ __fxprintf (stream, ": %s",
3201+ strerror_r (errnum, buf, sizeof (buf)));
3202+#else
3203+ putc_unlocked (':', stream);
3204+ putc_unlocked (' ', stream);
3205+# ifdef HAVE_STRERROR_R
3206+ fputs (strerror_r (errnum, buf, sizeof (buf)), stream);
3207+# else
3208+ fputs (strerror (errnum), stream);
3209+# endif
3210+#endif
3211+ }
3212+
3213+#ifdef USE_IN_LIBIO
3214+ if (_IO_fwide (stream, 0) > 0)
3215+ putwc_unlocked (L'\n', stream);
3216+ else
3217+#endif
3218+ putc_unlocked ('\n', stream);
3219+
3220+#if _LIBC || (HAVE_FLOCKFILE && HAVE_FUNLOCKFILE)
3221+ funlockfile (stream);
3222+#endif
3223+
3224+ if (status && (!state || !(state->flags & ARGP_NO_EXIT)))
3225+ exit (status);
3226+ }
3227+ }
3228+}
3229Index: git/libuargp/argp-parse.c
3230===================================================================
3231--- /dev/null 1970-01-01 00:00:00.000000000 +0000
3232+++ git/libuargp/argp-parse.c 2012-06-18 13:10:44.060825542 -0700
3233@@ -0,0 +1,949 @@
3234+/* Hierarchial argument parsing, layered over getopt
3235+ Copyright (C) 1995-2000, 2002, 2003, 2004 Free Software Foundation, Inc.
3236+ This file is part of the GNU C Library.
3237+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
3238+
3239+ The GNU C Library is free software; you can redistribute it and/or
3240+ modify it under the terms of the GNU Lesser General Public
3241+ License as published by the Free Software Foundation; either
3242+ version 2.1 of the License, or (at your option) any later version.
3243+
3244+ The GNU C Library is distributed in the hope that it will be useful,
3245+ but WITHOUT ANY WARRANTY; without even the implied warranty of
3246+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
3247+ Lesser General Public License for more details.
3248+
3249+ You should have received a copy of the GNU Lesser General Public
3250+ License along with the GNU C Library; if not, write to the Free
3251+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
3252+ 02111-1307 USA.
3253+
3254+ Modified for uClibc by: Salvatore Cro <salvatore.cro at st.com>
3255+*/
3256+
3257+#ifdef HAVE_CONFIG_H
3258+#include <config.h>
3259+#endif
3260+
3261+/* AIX requires this to be the first thing in the file. */
3262+#ifndef __GNUC__
3263+# if HAVE_ALLOCA_H || defined _LIBC
3264+# include <alloca.h>
3265+# else
3266+# ifdef _AIX
3267+#pragma alloca
3268+# else
3269+# ifndef alloca /* predefined by HP cc +Olibcalls */
3270+char *alloca ();
3271+# endif
3272+# endif
3273+# endif
3274+#endif
3275+
3276+#include <stdlib.h>
3277+#include <string.h>
3278+#include <unistd.h>
3279+#include <limits.h>
3280+#include <getopt.h>
3281+#include <bits/getopt_int.h>
3282+
3283+#include <features.h>
3284+#ifndef _
3285+/* This is for other GNU distributions with internationalized messages.
3286+ When compiling libc, the _ macro is predefined. */
3287+# if (defined HAVE_LIBINTL_H || defined _LIBC) && defined __UCLIBC_HAS_GETTEXT_AWARENESS__
3288+# include <libintl.h>
3289+# ifdef _LIBC
3290+# undef dgettext
3291+# define dgettext(domain, msgid) \
3292+ INTUSE(__dcgettext) (domain, msgid, LC_MESSAGES)
3293+# endif
3294+# else
3295+# define dgettext(domain, msgid) (msgid)
3296+# define gettext(msgid) (msgid)
3297+# endif
3298+#endif
3299+#ifndef N_
3300+# define N_(msgid) (msgid)
3301+#endif
3302+
3303+#include <argp.h>
3304+
3305+/* Getopt return values. */
3306+#define KEY_END (-1) /* The end of the options. */
3307+#define KEY_ARG 1 /* A non-option argument. */
3308+#define KEY_ERR '?' /* An error parsing the options. */
3309+
3310+/* The meta-argument used to prevent any further arguments being interpreted
3311+ as options. */
3312+#define QUOTE "--"
3313+
3314+/* The number of bits we steal in a long-option value for our own use. */
3315+#define GROUP_BITS CHAR_BIT
3316+
3317+/* The number of bits available for the user value. */
3318+#define USER_BITS ((sizeof ((struct option *)0)->val * CHAR_BIT) - GROUP_BITS)
3319+#define USER_MASK ((1 << USER_BITS) - 1)
3320+
3321+/* EZ alias for ARGP_ERR_UNKNOWN. */
3322+#define EBADKEY ARGP_ERR_UNKNOWN
3323+
3324+/* Default options. */
3325+
3326+/* When argp is given the --HANG switch, _ARGP_HANG is set and argp will sleep
3327+ for one second intervals, decrementing _ARGP_HANG until it's zero. Thus
3328+ you can force the program to continue by attaching a debugger and setting
3329+ it to 0 yourself. */
3330+static volatile int _argp_hang;
3331+
3332+#define OPT_PROGNAME -2
3333+#define OPT_USAGE -3
3334+#define OPT_HANG -4
3335+
3336+static const struct argp_option argp_default_options[] =
3337+{
3338+ {"help", '?', 0, 0, N_("Give this help list"), -1},
3339+ {"usage", OPT_USAGE, 0, 0, N_("Give a short usage message")},
3340+ {"program-name",OPT_PROGNAME,"NAME", OPTION_HIDDEN, N_("Set the program name")},
3341+ {"HANG", OPT_HANG, "SECS", OPTION_ARG_OPTIONAL | OPTION_HIDDEN,
3342+ N_("Hang for SECS seconds (default 3600)")},
3343+ {0, 0}
3344+};
3345+
3346+static error_t
3347+argp_default_parser (int key, char *arg, struct argp_state *state)
3348+{
3349+ switch (key)
3350+ {
3351+ case '?':
3352+ argp_state_help (state, state->out_stream, ARGP_HELP_STD_HELP);
3353+ break;
3354+ case OPT_USAGE:
3355+ argp_state_help (state, state->out_stream,
3356+ ARGP_HELP_USAGE | ARGP_HELP_EXIT_OK);
3357+ break;
3358+
3359+ case OPT_PROGNAME: /* Set the program name. */
3360+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_NAME
3361+ program_invocation_name = arg;
3362+#endif
3363+ /* [Note that some systems only have PROGRAM_INVOCATION_SHORT_NAME (aka
3364+ __PROGNAME), in which case, PROGRAM_INVOCATION_NAME is just defined
3365+ to be that, so we have to be a bit careful here.] */
3366+
3367+ /* Update what we use for messages. */
3368+ state->name = strrchr (arg, '/');
3369+ if (state->name)
3370+ state->name++;
3371+ else
3372+ state->name = arg;
3373+
3374+#if defined _LIBC || HAVE_DECL_PROGRAM_INVOCATION_SHORT_NAME
3375+ program_invocation_short_name = state->name;
3376+#endif
3377+
3378+ if ((state->flags & (ARGP_PARSE_ARGV0 | ARGP_NO_ERRS))
3379+ == ARGP_PARSE_ARGV0)
3380+ /* Update what getopt uses too. */
3381+ state->argv[0] = arg;
3382+
3383+ break;
3384+
3385+ case OPT_HANG:
3386+ _argp_hang = atoi (arg ? arg : "3600");
3387+ while (_argp_hang-- > 0)
3388+ sleep (1);
3389+ break;
3390+
3391+ default:
3392+ return EBADKEY;
3393+ }
3394+ return 0;
3395+}
3396+
3397+static const struct argp argp_default_argp =
3398+ {argp_default_options, &argp_default_parser, NULL, NULL, NULL, NULL, "libc"};
3399+
3400+
3401+static const struct argp_option argp_version_options[] =
3402+{
3403+ {"version", 'V', 0, 0, N_("Print program version"), -1},
3404+ {0, 0}
3405+};
3406+
3407+static error_t
3408+argp_version_parser (int key, char *arg, struct argp_state *state)
3409+{
3410+ switch (key)
3411+ {
3412+ case 'V':
3413+ if (argp_program_version_hook)
3414+ (*argp_program_version_hook) (state->out_stream, state);
3415+ else if (argp_program_version)
3416+ fprintf (state->out_stream, "%s\n", argp_program_version);
3417+ else
3418+ argp_error (state, dgettext (state->root_argp->argp_domain,
3419+ "(PROGRAM ERROR) No version known!?"));
3420+ if (! (state->flags & ARGP_NO_EXIT))
3421+ exit (0);
3422+ break;
3423+ default:
3424+ return EBADKEY;
3425+ }
3426+ return 0;
3427+}
3428+
3429+static const struct argp argp_version_argp =
3430+ {argp_version_options, &argp_version_parser, NULL, NULL, NULL, NULL, "libc"};
3431+
3432+/* Returns the offset into the getopt long options array LONG_OPTIONS of a
3433+ long option with called NAME, or -1 if none is found. Passing NULL as
3434+ NAME will return the number of options. */
3435+static int
3436+find_long_option (struct option *long_options, const char *name)
3437+{
3438+ struct option *l = long_options;
3439+ while (l->name != NULL)
3440+ if (name != NULL && strcmp (l->name, name) == 0)
3441+ return l - long_options;
3442+ else
3443+ l++;
3444+ if (name == NULL)
3445+ return l - long_options;
3446+ else
3447+ return -1;
3448+}
3449+
3450+
3451+/* The state of a `group' during parsing. Each group corresponds to a
3452+ particular argp structure from the tree of such descending from the top
3453+ level argp passed to argp_parse. */
3454+struct group
3455+{
3456+ /* This group's parsing function. */
3457+ argp_parser_t parser;
3458+
3459+ /* Which argp this group is from. */
3460+ const struct argp *argp;
3461+
3462+ /* Points to the point in SHORT_OPTS corresponding to the end of the short
3463+ options for this group. We use it to determine from which group a
3464+ particular short options is from. */
3465+ char *short_end;
3466+
3467+ /* The number of non-option args sucessfully handled by this parser. */
3468+ unsigned args_processed;
3469+
3470+ /* This group's parser's parent's group. */
3471+ struct group *parent;
3472+ unsigned parent_index; /* And the our position in the parent. */
3473+
3474+ /* These fields are swapped into and out of the state structure when
3475+ calling this group's parser. */
3476+ void *input, **child_inputs;
3477+ void *hook;
3478+};
3479+
3480+/* Call GROUP's parser with KEY and ARG, swapping any group-specific info
3481+ from STATE before calling, and back into state afterwards. If GROUP has
3482+ no parser, EBADKEY is returned. */
3483+static error_t
3484+group_parse (struct group *group, struct argp_state *state, int key, char *arg)
3485+{
3486+ if (group->parser)
3487+ {
3488+ error_t err;
3489+ state->hook = group->hook;
3490+ state->input = group->input;
3491+ state->child_inputs = group->child_inputs;
3492+ state->arg_num = group->args_processed;
3493+ err = (*group->parser)(key, arg, state);
3494+ group->hook = state->hook;
3495+ return err;
3496+ }
3497+ else
3498+ return EBADKEY;
3499+}
3500+
3501+struct parser
3502+{
3503+ const struct argp *argp;
3504+
3505+ /* SHORT_OPTS is the getopt short options string for the union of all the
3506+ groups of options. */
3507+ char *short_opts;
3508+ /* LONG_OPTS is the array of getop long option structures for the union of
3509+ all the groups of options. */
3510+ struct option *long_opts;
3511+ /* OPT_DATA is the getopt data used for the re-entrant getopt. */
3512+ struct _getopt_data opt_data;
3513+
3514+ /* States of the various parsing groups. */
3515+ struct group *groups;
3516+ /* The end of the GROUPS array. */
3517+ struct group *egroup;
3518+ /* An vector containing storage for the CHILD_INPUTS field in all groups. */
3519+ void **child_inputs;
3520+
3521+ /* True if we think using getopt is still useful; if false, then
3522+ remaining arguments are just passed verbatim with ARGP_KEY_ARG. This is
3523+ cleared whenever getopt returns KEY_END, but may be set again if the user
3524+ moves the next argument pointer backwards. */
3525+ int try_getopt;
3526+
3527+ /* State block supplied to parsing routines. */
3528+ struct argp_state state;
3529+
3530+ /* Memory used by this parser. */
3531+ void *storage;
3532+};
3533+
3534+/* The next usable entries in the various parser tables being filled in by
3535+ convert_options. */
3536+struct parser_convert_state
3537+{
3538+ struct parser *parser;
3539+ char *short_end;
3540+ struct option *long_end;
3541+ void **child_inputs_end;
3542+};
3543+
3544+/* Converts all options in ARGP (which is put in GROUP) and ancestors
3545+ into getopt options stored in SHORT_OPTS and LONG_OPTS; SHORT_END and
3546+ CVT->LONG_END are the points at which new options are added. Returns the
3547+ next unused group entry. CVT holds state used during the conversion. */
3548+static struct group *
3549+convert_options (const struct argp *argp,
3550+ struct group *parent, unsigned parent_index,
3551+ struct group *group, struct parser_convert_state *cvt)
3552+{
3553+ /* REAL is the most recent non-alias value of OPT. */
3554+ const struct argp_option *real = argp->options;
3555+ const struct argp_child *children = argp->children;
3556+
3557+ if (real || argp->parser)
3558+ {
3559+ const struct argp_option *opt;
3560+
3561+ if (real)
3562+ for (opt = real; !__option_is_end (opt); opt++)
3563+ {
3564+ if (! (opt->flags & OPTION_ALIAS))
3565+ /* OPT isn't an alias, so we can use values from it. */
3566+ real = opt;
3567+
3568+ if (! (real->flags & OPTION_DOC))
3569+ /* A real option (not just documentation). */
3570+ {
3571+ if (__option_is_short (opt))
3572+ /* OPT can be used as a short option. */
3573+ {
3574+ *cvt->short_end++ = opt->key;
3575+ if (real->arg)
3576+ {
3577+ *cvt->short_end++ = ':';
3578+ if (real->flags & OPTION_ARG_OPTIONAL)
3579+ *cvt->short_end++ = ':';
3580+ }
3581+ *cvt->short_end = '\0'; /* keep 0 terminated */
3582+ }
3583+
3584+ if (opt->name
3585+ && find_long_option (cvt->parser->long_opts, opt->name) < 0)
3586+ /* OPT can be used as a long option. */
3587+ {
3588+ cvt->long_end->name = opt->name;
3589+ cvt->long_end->has_arg =
3590+ (real->arg
3591+ ? (real->flags & OPTION_ARG_OPTIONAL
3592+ ? optional_argument
3593+ : required_argument)
3594+ : no_argument);
3595+ cvt->long_end->flag = 0;
3596+ /* we add a disambiguating code to all the user's
3597+ values (which is removed before we actually call
3598+ the function to parse the value); this means that
3599+ the user loses use of the high 8 bits in all his
3600+ values (the sign of the lower bits is preserved
3601+ however)... */
3602+ cvt->long_end->val =
3603+ ((opt->key | real->key) & USER_MASK)
3604+ + (((group - cvt->parser->groups) + 1) << USER_BITS);
3605+
3606+ /* Keep the LONG_OPTS list terminated. */
3607+ (++cvt->long_end)->name = NULL;
3608+ }
3609+ }
3610+ }
3611+
3612+ group->parser = argp->parser;
3613+ group->argp = argp;
3614+ group->short_end = cvt->short_end;
3615+ group->args_processed = 0;
3616+ group->parent = parent;
3617+ group->parent_index = parent_index;
3618+ group->input = 0;
3619+ group->hook = 0;
3620+ group->child_inputs = 0;
3621+
3622+ if (children)
3623+ /* Assign GROUP's CHILD_INPUTS field some space from
3624+ CVT->child_inputs_end.*/
3625+ {
3626+ unsigned num_children = 0;
3627+ while (children[num_children].argp)
3628+ num_children++;
3629+ group->child_inputs = cvt->child_inputs_end;
3630+ cvt->child_inputs_end += num_children;
3631+ }
3632+
3633+ parent = group++;
3634+ }
3635+ else
3636+ parent = 0;
3637+
3638+ if (children)
3639+ {
3640+ unsigned index = 0;
3641+ while (children->argp)
3642+ group =
3643+ convert_options (children++->argp, parent, index++, group, cvt);
3644+ }
3645+
3646+ return group;
3647+}
3648+
3649+/* Find the merged set of getopt options, with keys appropiately prefixed. */
3650+static void
3651+parser_convert (struct parser *parser, const struct argp *argp, int flags)
3652+{
3653+ struct parser_convert_state cvt;
3654+
3655+ cvt.parser = parser;
3656+ cvt.short_end = parser->short_opts;
3657+ cvt.long_end = parser->long_opts;
3658+ cvt.child_inputs_end = parser->child_inputs;
3659+
3660+ if (flags & ARGP_IN_ORDER)
3661+ *cvt.short_end++ = '-';
3662+ else if (flags & ARGP_NO_ARGS)
3663+ *cvt.short_end++ = '+';
3664+ *cvt.short_end = '\0';
3665+
3666+ cvt.long_end->name = NULL;
3667+
3668+ parser->argp = argp;
3669+
3670+ if (argp)
3671+ parser->egroup = convert_options (argp, 0, 0, parser->groups, &cvt);
3672+ else
3673+ parser->egroup = parser->groups; /* No parsers at all! */
3674+}
3675+
3676+/* Lengths of various parser fields which we will allocated. */
3677+struct parser_sizes
3678+{
3679+ size_t short_len; /* Getopt short options string. */
3680+ size_t long_len; /* Getopt long options vector. */
3681+ size_t num_groups; /* Group structures we allocate. */
3682+ size_t num_child_inputs; /* Child input slots. */
3683+};
3684+
3685+/* For ARGP, increments the NUM_GROUPS field in SZS by the total number of
3686+ argp structures descended from it, and the SHORT_LEN & LONG_LEN fields by
3687+ the maximum lengths of the resulting merged getopt short options string and
3688+ long-options array, respectively. */
3689+static void
3690+calc_sizes (const struct argp *argp, struct parser_sizes *szs)
3691+{
3692+ const struct argp_child *child = argp->children;
3693+ const struct argp_option *opt = argp->options;
3694+
3695+ if (opt || argp->parser)
3696+ {
3697+ szs->num_groups++;
3698+ if (opt)
3699+ {
3700+ int num_opts = 0;
3701+ while (!__option_is_end (opt++))
3702+ num_opts++;
3703+ szs->short_len += num_opts * 3; /* opt + up to 2 `:'s */
3704+ szs->long_len += num_opts;
3705+ }
3706+ }
3707+
3708+ if (child)
3709+ while (child->argp)
3710+ {
3711+ calc_sizes ((child++)->argp, szs);
3712+ szs->num_child_inputs++;
3713+ }
3714+}
3715+
3716+
3717+extern char * __argp_short_program_name (void);
3718+/* Initializes PARSER to parse ARGP in a manner described by FLAGS. */
3719+static error_t
3720+parser_init (struct parser *parser, const struct argp *argp,
3721+ int argc, char **argv, int flags, void *input)
3722+{
3723+ error_t err = 0;
3724+ struct group *group;
3725+ struct parser_sizes szs;
3726+ struct _getopt_data opt_data = _GETOPT_DATA_INITIALIZER;
3727+
3728+ szs.short_len = (flags & ARGP_NO_ARGS) ? 0 : 1;
3729+ szs.long_len = 0;
3730+ szs.num_groups = 0;
3731+ szs.num_child_inputs = 0;
3732+
3733+ if (argp)
3734+ calc_sizes (argp, &szs);
3735+
3736+ /* Lengths of the various bits of storage used by PARSER. */
3737+#define GLEN (szs.num_groups + 1) * sizeof (struct group)
3738+#define CLEN (szs.num_child_inputs * sizeof (void *))
3739+#define LLEN ((szs.long_len + 1) * sizeof (struct option))
3740+#define SLEN (szs.short_len + 1)
3741+
3742+ parser->storage = malloc (GLEN + CLEN + LLEN + SLEN);
3743+ if (! parser->storage)
3744+ return ENOMEM;
3745+
3746+ parser->groups = parser->storage;
3747+ parser->child_inputs = parser->storage + GLEN;
3748+ parser->long_opts = parser->storage + GLEN + CLEN;
3749+ parser->short_opts = parser->storage + GLEN + CLEN + LLEN;
3750+ parser->opt_data = opt_data;
3751+
3752+ memset (parser->child_inputs, 0, szs.num_child_inputs * sizeof (void *));
3753+ parser_convert (parser, argp, flags);
3754+
3755+ memset (&parser->state, 0, sizeof (struct argp_state));
3756+ parser->state.root_argp = parser->argp;
3757+ parser->state.argc = argc;
3758+ parser->state.argv = argv;
3759+ parser->state.flags = flags;
3760+ parser->state.err_stream = stderr;
3761+ parser->state.out_stream = stdout;
3762+ parser->state.next = 0; /* Tell getopt to initialize. */
3763+ parser->state.pstate = parser;
3764+
3765+ parser->try_getopt = 1;
3766+
3767+ /* Call each parser for the first time, giving it a chance to propagate
3768+ values to child parsers. */
3769+ if (parser->groups < parser->egroup)
3770+ parser->groups->input = input;
3771+ for (group = parser->groups;
3772+ group < parser->egroup && (!err || err == EBADKEY);
3773+ group++)
3774+ {
3775+ if (group->parent)
3776+ /* If a child parser, get the initial input value from the parent. */
3777+ group->input = group->parent->child_inputs[group->parent_index];
3778+
3779+ if (!group->parser
3780+ && group->argp->children && group->argp->children->argp)
3781+ /* For the special case where no parsing function is supplied for an
3782+ argp, propagate its input to its first child, if any (this just
3783+ makes very simple wrapper argps more convenient). */
3784+ group->child_inputs[0] = group->input;
3785+
3786+ err = group_parse (group, &parser->state, ARGP_KEY_INIT, 0);
3787+ }
3788+ if (err == EBADKEY)
3789+ err = 0; /* Some parser didn't understand. */
3790+
3791+ if (err)
3792+ return err;
3793+
3794+ if (parser->state.flags & ARGP_NO_ERRS)
3795+ {
3796+ parser->opt_data.opterr = 0;
3797+ if (parser->state.flags & ARGP_PARSE_ARGV0)
3798+ /* getopt always skips ARGV[0], so we have to fake it out. As long
3799+ as OPTERR is 0, then it shouldn't actually try to access it. */
3800+ parser->state.argv--, parser->state.argc++;
3801+ }
3802+ else
3803+ parser->opt_data.opterr = 1; /* Print error messages. */
3804+
3805+ if (parser->state.argv == argv && argv[0])
3806+ /* There's an argv[0]; use it for messages. */
3807+ {
3808+ char *short_name = strrchr (argv[0], '/');
3809+ parser->state.name = short_name ? short_name + 1 : argv[0];
3810+ }
3811+ else
3812+ parser->state.name = __argp_short_program_name ();
3813+
3814+ return 0;
3815+}
3816+
3817+/* Free any storage consumed by PARSER (but not PARSER itself). */
3818+static error_t
3819+parser_finalize (struct parser *parser,
3820+ error_t err, int arg_ebadkey, int *end_index)
3821+{
3822+ struct group *group;
3823+
3824+ if (err == EBADKEY && arg_ebadkey)
3825+ /* Suppress errors generated by unparsed arguments. */
3826+ err = 0;
3827+
3828+ if (! err)
3829+ {
3830+ if (parser->state.next == parser->state.argc)
3831+ /* We successfully parsed all arguments! Call all the parsers again,
3832+ just a few more times... */
3833+ {
3834+ for (group = parser->groups;
3835+ group < parser->egroup && (!err || err==EBADKEY);
3836+ group++)
3837+ if (group->args_processed == 0)
3838+ err = group_parse (group, &parser->state, ARGP_KEY_NO_ARGS, 0);
3839+ for (group = parser->egroup - 1;
3840+ group >= parser->groups && (!err || err==EBADKEY);
3841+ group--)
3842+ err = group_parse (group, &parser->state, ARGP_KEY_END, 0);
3843+
3844+ if (err == EBADKEY)
3845+ err = 0; /* Some parser didn't understand. */
3846+
3847+ /* Tell the user that all arguments are parsed. */
3848+ if (end_index)
3849+ *end_index = parser->state.next;
3850+ }
3851+ else if (end_index)
3852+ /* Return any remaining arguments to the user. */
3853+ *end_index = parser->state.next;
3854+ else
3855+ /* No way to return the remaining arguments, they must be bogus. */
3856+ {
3857+ if (!(parser->state.flags & ARGP_NO_ERRS)
3858+ && parser->state.err_stream)
3859+ fprintf (parser->state.err_stream,
3860+ dgettext (parser->argp->argp_domain,
3861+ "%s: Too many arguments\n"),
3862+ parser->state.name);
3863+ err = EBADKEY;
3864+ }
3865+ }
3866+
3867+ /* Okay, we're all done, with either an error or success; call the parsers
3868+ to indicate which one. */
3869+
3870+ if (err)
3871+ {
3872+ /* Maybe print an error message. */
3873+ if (err == EBADKEY)
3874+ /* An appropriate message describing what the error was should have
3875+ been printed earlier. */
3876+ argp_state_help (&parser->state, parser->state.err_stream,
3877+ ARGP_HELP_STD_ERR);
3878+
3879+ /* Since we didn't exit, give each parser an error indication. */
3880+ for (group = parser->groups; group < parser->egroup; group++)
3881+ group_parse (group, &parser->state, ARGP_KEY_ERROR, 0);
3882+ }
3883+ else
3884+ /* Notify parsers of success, and propagate back values from parsers. */
3885+ {
3886+ /* We pass over the groups in reverse order so that child groups are
3887+ given a chance to do there processing before passing back a value to
3888+ the parent. */
3889+ for (group = parser->egroup - 1
3890+ ; group >= parser->groups && (!err || err == EBADKEY)
3891+ ; group--)
3892+ err = group_parse (group, &parser->state, ARGP_KEY_SUCCESS, 0);
3893+ if (err == EBADKEY)
3894+ err = 0; /* Some parser didn't understand. */
3895+ }
3896+
3897+ /* Call parsers once more, to do any final cleanup. Errors are ignored. */
3898+ for (group = parser->egroup - 1; group >= parser->groups; group--)
3899+ group_parse (group, &parser->state, ARGP_KEY_FINI, 0);
3900+
3901+ if (err == EBADKEY)
3902+ err = EINVAL;
3903+
3904+ free (parser->storage);
3905+
3906+ return err;
3907+}
3908+
3909+/* Call the user parsers to parse the non-option argument VAL, at the current
3910+ position, returning any error. The state NEXT pointer is assumed to have
3911+ been adjusted (by getopt) to point after this argument; this function will
3912+ adjust it correctly to reflect however many args actually end up being
3913+ consumed. */
3914+static error_t
3915+parser_parse_arg (struct parser *parser, char *val)
3916+{
3917+ /* Save the starting value of NEXT, first adjusting it so that the arg
3918+ we're parsing is again the front of the arg vector. */
3919+ int index = --parser->state.next;
3920+ error_t err = EBADKEY;
3921+ struct group *group;
3922+ int key = 0; /* Which of ARGP_KEY_ARG[S] we used. */
3923+
3924+ /* Try to parse the argument in each parser. */
3925+ for (group = parser->groups
3926+ ; group < parser->egroup && err == EBADKEY
3927+ ; group++)
3928+ {
3929+ parser->state.next++; /* For ARGP_KEY_ARG, consume the arg. */
3930+ key = ARGP_KEY_ARG;
3931+ err = group_parse (group, &parser->state, key, val);
3932+
3933+ if (err == EBADKEY)
3934+ /* This parser doesn't like ARGP_KEY_ARG; try ARGP_KEY_ARGS instead. */
3935+ {
3936+ parser->state.next--; /* For ARGP_KEY_ARGS, put back the arg. */
3937+ key = ARGP_KEY_ARGS;
3938+ err = group_parse (group, &parser->state, key, 0);
3939+ }
3940+ }
3941+
3942+ if (! err)
3943+ {
3944+ if (key == ARGP_KEY_ARGS)
3945+ /* The default for ARGP_KEY_ARGS is to assume that if NEXT isn't
3946+ changed by the user, *all* arguments should be considered
3947+ consumed. */
3948+ parser->state.next = parser->state.argc;
3949+
3950+ if (parser->state.next > index)
3951+ /* Remember that we successfully processed a non-option
3952+ argument -- but only if the user hasn't gotten tricky and set
3953+ the clock back. */
3954+ (--group)->args_processed += (parser->state.next - index);
3955+ else
3956+ /* The user wants to reparse some args, give getopt another try. */
3957+ parser->try_getopt = 1;
3958+ }
3959+
3960+ return err;
3961+}
3962+
3963+/* Call the user parsers to parse the option OPT, with argument VAL, at the
3964+ current position, returning any error. */
3965+static error_t
3966+parser_parse_opt (struct parser *parser, int opt, char *val)
3967+{
3968+ /* The group key encoded in the high bits; 0 for short opts or
3969+ group_number + 1 for long opts. */
3970+ int group_key = opt >> USER_BITS;
3971+ error_t err = EBADKEY;
3972+
3973+ if (group_key == 0)
3974+ /* A short option. By comparing OPT's position in SHORT_OPTS to the
3975+ various starting positions in each group's SHORT_END field, we can
3976+ determine which group OPT came from. */
3977+ {
3978+ struct group *group;
3979+ char *short_index = strchr (parser->short_opts, opt);
3980+
3981+ if (short_index)
3982+ for (group = parser->groups; group < parser->egroup; group++)
3983+ if (group->short_end > short_index)
3984+ {
3985+ err = group_parse (group, &parser->state, opt,
3986+ parser->opt_data.optarg);
3987+ break;
3988+ }
3989+ }
3990+ else
3991+ /* A long option. We use shifts instead of masking for extracting
3992+ the user value in order to preserve the sign. */
3993+ err =
3994+ group_parse (&parser->groups[group_key - 1], &parser->state,
3995+ (opt << GROUP_BITS) >> GROUP_BITS,
3996+ parser->opt_data.optarg);
3997+
3998+ if (err == EBADKEY)
3999+ /* At least currently, an option not recognized is an error in the
4000+ parser, because we pre-compute which parser is supposed to deal
4001+ with each option. */
4002+ {
4003+ static const char bad_key_err[] =
4004+ N_("(PROGRAM ERROR) Option should have been recognized!?");
4005+ if (group_key == 0)
4006+ argp_error (&parser->state, "-%c: %s", opt,
4007+ dgettext (parser->argp->argp_domain, bad_key_err));
4008+ else
4009+ {
4010+ struct option *long_opt = parser->long_opts;
4011+ while (long_opt->val != opt && long_opt->name)
4012+ long_opt++;
4013+ argp_error (&parser->state, "--%s: %s",
4014+ long_opt->name ? long_opt->name : "???",
4015+ dgettext (parser->argp->argp_domain, bad_key_err));
4016+ }
4017+ }
4018+
4019+ return err;
4020+}
4021+
4022+/* Parse the next argument in PARSER (as indicated by PARSER->state.next).
4023+ Any error from the parsers is returned, and *ARGP_EBADKEY indicates
4024+ whether a value of EBADKEY is due to an unrecognized argument (which is
4025+ generally not fatal). */
4026+static error_t
4027+parser_parse_next (struct parser *parser, int *arg_ebadkey)
4028+{
4029+ int opt;
4030+ error_t err = 0;
4031+
4032+ if (parser->state.quoted && parser->state.next < parser->state.quoted)
4033+ /* The next argument pointer has been moved to before the quoted
4034+ region, so pretend we never saw the quoting `--', and give getopt
4035+ another chance. If the user hasn't removed it, getopt will just
4036+ process it again. */
4037+ parser->state.quoted = 0;
4038+
4039+ if (parser->try_getopt && !parser->state.quoted)
4040+ /* Give getopt a chance to parse this. */
4041+ {
4042+ /* Put it back in OPTIND for getopt. */
4043+ parser->opt_data.optind = parser->state.next;
4044+ /* Distinguish KEY_ERR from a real option. */
4045+ parser->opt_data.optopt = KEY_END;
4046+ if (parser->state.flags & ARGP_LONG_ONLY)
4047+ opt = _getopt_long_only_r (parser->state.argc, parser->state.argv,
4048+ parser->short_opts, parser->long_opts, 0,
4049+ &parser->opt_data);
4050+ else
4051+ opt = _getopt_long_r (parser->state.argc, parser->state.argv,
4052+ parser->short_opts, parser->long_opts, 0,
4053+ &parser->opt_data);
4054+ /* And see what getopt did. */
4055+ parser->state.next = parser->opt_data.optind;
4056+
4057+ if (opt == KEY_END)
4058+ /* Getopt says there are no more options, so stop using
4059+ getopt; we'll continue if necessary on our own. */
4060+ {
4061+ parser->try_getopt = 0;
4062+ if (parser->state.next > 1
4063+ && strcmp (parser->state.argv[parser->state.next - 1], QUOTE)
4064+ == 0)
4065+ /* Not only is this the end of the options, but it's a
4066+ `quoted' region, which may have args that *look* like
4067+ options, so we definitely shouldn't try to use getopt past
4068+ here, whatever happens. */
4069+ parser->state.quoted = parser->state.next;
4070+ }
4071+ else if (opt == KEY_ERR && parser->opt_data.optopt != KEY_END)
4072+ /* KEY_ERR can have the same value as a valid user short
4073+ option, but in the case of a real error, getopt sets OPTOPT
4074+ to the offending character, which can never be KEY_END. */
4075+ {
4076+ *arg_ebadkey = 0;
4077+ return EBADKEY;
4078+ }
4079+ }
4080+ else
4081+ opt = KEY_END;
4082+
4083+ if (opt == KEY_END)
4084+ {
4085+ /* We're past what getopt considers the options. */
4086+ if (parser->state.next >= parser->state.argc
4087+ || (parser->state.flags & ARGP_NO_ARGS))
4088+ /* Indicate that we're done. */
4089+ {
4090+ *arg_ebadkey = 1;
4091+ return EBADKEY;
4092+ }
4093+ else
4094+ /* A non-option arg; simulate what getopt might have done. */
4095+ {
4096+ opt = KEY_ARG;
4097+ parser->opt_data.optarg = parser->state.argv[parser->state.next++];
4098+ }
4099+ }
4100+
4101+ if (opt == KEY_ARG)
4102+ /* A non-option argument; try each parser in turn. */
4103+ err = parser_parse_arg (parser, parser->opt_data.optarg);
4104+ else
4105+ err = parser_parse_opt (parser, opt, parser->opt_data.optarg);
4106+
4107+ if (err == EBADKEY)
4108+ *arg_ebadkey = (opt == KEY_END || opt == KEY_ARG);
4109+
4110+ return err;
4111+}
4112+
4113+/* Parse the options strings in ARGC & ARGV according to the argp in ARGP.
4114+ FLAGS is one of the ARGP_ flags above. If END_INDEX is non-NULL, the
4115+ index in ARGV of the first unparsed option is returned in it. If an
4116+ unknown option is present, EINVAL is returned; if some parser routine
4117+ returned a non-zero value, it is returned; otherwise 0 is returned. */
4118+error_t
4119+argp_parse (const struct argp *argp, int argc, char **argv, unsigned flags,
4120+ int *end_index, void *input)
4121+{
4122+ error_t err;
4123+ struct parser parser;
4124+
4125+ /* If true, then err == EBADKEY is a result of a non-option argument failing
4126+ to be parsed (which in some cases isn't actually an error). */
4127+ int arg_ebadkey = 0;
4128+
4129+ if (! (flags & ARGP_NO_HELP))
4130+ /* Add our own options. */
4131+ {
4132+ struct argp_child *child = alloca (4 * sizeof (struct argp_child));
4133+ struct argp *top_argp = alloca (sizeof (struct argp));
4134+
4135+ /* TOP_ARGP has no options, it just serves to group the user & default
4136+ argps. */
4137+ memset (top_argp, 0, sizeof (*top_argp));
4138+ top_argp->children = child;
4139+
4140+ memset (child, 0, 4 * sizeof (struct argp_child));
4141+
4142+ if (argp)
4143+ (child++)->argp = argp;
4144+ (child++)->argp = &argp_default_argp;
4145+ if (argp_program_version || argp_program_version_hook)
4146+ (child++)->argp = &argp_version_argp;
4147+ child->argp = 0;
4148+
4149+ argp = top_argp;
4150+ }
4151+
4152+ /* Construct a parser for these arguments. */
4153+ err = parser_init (&parser, argp, argc, argv, flags, input);
4154+
4155+ if (! err)
4156+ /* Parse! */
4157+ {
4158+ while (! err)
4159+ err = parser_parse_next (&parser, &arg_ebadkey);
4160+ err = parser_finalize (&parser, err, arg_ebadkey, end_index);
4161+ }
4162+
4163+ return err;
4164+}
4165+
4166+/* Return the input field for ARGP in the parser corresponding to STATE; used
4167+ by the help routines. */
4168+void *
4169+__argp_input (const struct argp *argp, const struct argp_state *state)
4170+{
4171+ if (state)
4172+ {
4173+ struct group *group;
4174+ struct parser *parser = state->pstate;
4175+
4176+ for (group = parser->groups; group < parser->egroup; group++)
4177+ if (group->argp == argp)
4178+ return group->input;
4179+ }
4180+
4181+ return 0;
4182+}
4183Index: git/libuargp/argp-pv.c
4184===================================================================
4185--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4186+++ git/libuargp/argp-pv.c 2012-06-18 13:10:44.060825542 -0700
4187@@ -0,0 +1,25 @@
4188+/* Default definition for ARGP_PROGRAM_VERSION.
4189+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4190+ This file is part of the GNU C Library.
4191+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4192+
4193+ The GNU C Library is free software; you can redistribute it and/or
4194+ modify it under the terms of the GNU Lesser General Public
4195+ License as published by the Free Software Foundation; either
4196+ version 2.1 of the License, or (at your option) any later version.
4197+
4198+ The GNU C Library is distributed in the hope that it will be useful,
4199+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4200+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4201+ Lesser General Public License for more details.
4202+
4203+ You should have received a copy of the GNU Lesser General Public
4204+ License along with the GNU C Library; if not, write to the Free
4205+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4206+ 02111-1307 USA. */
4207+
4208+/* If set by the user program to a non-zero value, then a default option
4209+ --version is added (unless the ARGP_NO_HELP flag is used), which will
4210+ print this this string followed by a newline and exit (unless the
4211+ ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. */
4212+const char *argp_program_version;
4213Index: git/libuargp/argp-pvh.c
4214===================================================================
4215--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4216+++ git/libuargp/argp-pvh.c 2012-06-18 13:10:44.060825542 -0700
4217@@ -0,0 +1,32 @@
4218+/* Default definition for ARGP_PROGRAM_VERSION_HOOK.
4219+ Copyright (C) 1996, 1997, 1999 Free Software Foundation, Inc.
4220+ This file is part of the GNU C Library.
4221+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4222+
4223+ The GNU C Library is free software; you can redistribute it and/or
4224+ modify it under the terms of the GNU Lesser General Public
4225+ License as published by the Free Software Foundation; either
4226+ version 2.1 of the License, or (at your option) any later version.
4227+
4228+ The GNU C Library is distributed in the hope that it will be useful,
4229+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4230+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4231+ Lesser General Public License for more details.
4232+
4233+ You should have received a copy of the GNU Lesser General Public
4234+ License along with the GNU C Library; if not, write to the Free
4235+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4236+ 02111-1307 USA. */
4237+
4238+#ifdef HAVE_CONFIG_H
4239+#include <config.h>
4240+#endif
4241+
4242+#include <argp.h>
4243+
4244+/* If set by the user program to a non-zero value, then a default option
4245+ --version is added (unless the ARGP_NO_HELP flag is used), which calls
4246+ this function with a stream to print the version to and a pointer to the
4247+ current parsing state, and then exits (unless the ARGP_NO_EXIT flag is
4248+ used). This variable takes precedent over ARGP_PROGRAM_VERSION. */
4249+void (*argp_program_version_hook) (FILE *stream, struct argp_state *state);
4250Index: git/libuargp/argp-xinl.c
4251===================================================================
4252--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4253+++ git/libuargp/argp-xinl.c 2012-06-18 13:10:44.060825542 -0700
4254@@ -0,0 +1,35 @@
4255+/* Real definitions for extern inline functions in argp.h
4256+ Copyright (C) 1997, 1998, 2004 Free Software Foundation, Inc.
4257+ This file is part of the GNU C Library.
4258+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4259+
4260+ The GNU C Library is free software; you can redistribute it and/or
4261+ modify it under the terms of the GNU Lesser General Public
4262+ License as published by the Free Software Foundation; either
4263+ version 2.1 of the License, or (at your option) any later version.
4264+
4265+ The GNU C Library is distributed in the hope that it will be useful,
4266+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4267+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4268+ Lesser General Public License for more details.
4269+
4270+ You should have received a copy of the GNU Lesser General Public
4271+ License along with the GNU C Library; if not, write to the Free
4272+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4273+ 02111-1307 USA. */
4274+
4275+#ifdef HAVE_CONFIG_H
4276+# include <config.h>
4277+#endif
4278+
4279+#if defined _LIBC || defined HAVE_FEATURES_H
4280+# include <features.h>
4281+#endif
4282+
4283+#ifndef __USE_EXTERN_INLINES
4284+# define __USE_EXTERN_INLINES 1
4285+#endif
4286+#define ARGP_EI
4287+#undef __OPTIMIZE__
4288+#define __OPTIMIZE__ 1
4289+#include <argp.h>
4290Index: git/test/argp/Makefile
4291===================================================================
4292--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4293+++ git/test/argp/Makefile 2012-06-18 13:10:44.060825542 -0700
4294@@ -0,0 +1,7 @@
4295+# uClibc argp tests
4296+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
4297+
4298+top_builddir=../../
4299+include ../Rules.mak
4300+-include Makefile.in
4301+include ../Test.mak
4302Index: git/test/argp/Makefile.in
4303===================================================================
4304--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4305+++ git/test/argp/Makefile.in 2012-06-18 13:10:44.060825542 -0700
4306@@ -0,0 +1,12 @@
4307+# uClibc argp tests
4308+# Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
4309+
4310+TESTS := $(addprefix argp-, ex1 ex2 ex3 ex4 test) \
4311+ bug-argp1 tst-argp1 tst-argp2
4312+
4313+EXTRA_LDFLAGS = -luargp
4314+
4315+OPTS_argp-ex3 = ARG1 ARG2
4316+OPTS_argp-ex4 = ARG1 string1 string2 string3
4317+OPTS_bug-argp1 = -- --help
4318+
4319Index: git/test/argp/argp-ex1.c
4320===================================================================
4321--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4322+++ git/test/argp/argp-ex1.c 2012-06-18 13:10:44.060825542 -0700
4323@@ -0,0 +1,15 @@
4324+/* Argp example #1 -- a minimal program using argp */
4325+
4326+/* This is (probably) the smallest possible program that
4327+ uses argp. It won't do much except give an error
4328+ messages and exit when there are any arguments, and print
4329+ a (rather pointless) messages for --help. */
4330+
4331+#include <stdlib.h>
4332+#include <argp.h>
4333+
4334+int main (int argc, char **argv)
4335+{
4336+ argp_parse (0, argc, argv, 0, 0, 0);
4337+ exit (0);
4338+}
4339Index: git/test/argp/argp-ex2.c
4340===================================================================
4341--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4342+++ git/test/argp/argp-ex2.c 2012-06-18 13:10:44.060825542 -0700
4343@@ -0,0 +1,45 @@
4344+/* Argp example #2 -- a pretty minimal program using argp */
4345+
4346+/* This program doesn't use any options or arguments, but uses
4347+ argp to be compliant with the GNU standard command line
4348+ format.
4349+
4350+ In addition to making sure no arguments are given, and
4351+ implementing a --help option, this example will have a
4352+ --version option, and will put the given documentation string
4353+ and bug address in the --help output, as per GNU standards.
4354+
4355+ The variable ARGP contains the argument parser specification;
4356+ adding fields to this structure is the way most parameters are
4357+ passed to argp_parse (the first three fields are usually used,
4358+ but not in this small program). There are also two global
4359+ variables that argp knows about defined here,
4360+ ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
4361+ global variables because they will almost always be constant
4362+ for a given program, even if it uses different argument
4363+ parsers for various tasks). */
4364+
4365+#include <stdlib.h>
4366+#include <argp.h>
4367+
4368+const char *argp_program_version =
4369+ "argp-ex2 1.0";
4370+const char *argp_program_bug_address =
4371+ "<bug-gnu-utils@@gnu.org>";
4372+
4373+/* Program documentation. */
4374+static char doc[] =
4375+ "Argp example #2 -- a pretty minimal program using argp";
4376+
4377+/* Our argument parser. The @code{options}, @code{parser}, and
4378+ @code{args_doc} fields are zero because we have neither options or
4379+ arguments; @code{doc} and @code{argp_program_bug_address} will be
4380+ used in the output for @samp{--help}, and the @samp{--version}
4381+ option will print out @code{argp_program_version}. */
4382+static struct argp argp = { 0, 0, 0, doc };
4383+
4384+int main (int argc, char **argv)
4385+{
4386+ argp_parse (&argp, argc, argv, 0, 0, 0);
4387+ exit (0);
4388+}
4389Index: git/test/argp/argp-ex3.c
4390===================================================================
4391--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4392+++ git/test/argp/argp-ex3.c 2012-06-18 13:10:44.060825542 -0700
4393@@ -0,0 +1,153 @@
4394+/* Argp example #3 -- a program with options and arguments using argp */
4395+
4396+/* This program uses the same features as example 2, and uses options and
4397+ arguments.
4398+
4399+ We now use the first four fields in ARGP, so here's a description of them:
4400+ OPTIONS -- A pointer to a vector of struct argp_option (see below)
4401+ PARSER -- A function to parse a single option, called by argp
4402+ ARGS_DOC -- A string describing how the non-option arguments should look
4403+ DOC -- A descriptive string about this program; if it contains a
4404+ vertical tab character (\v), the part after it will be
4405+ printed *following* the options
4406+
4407+ The function PARSER takes the following arguments:
4408+ KEY -- An integer specifying which option this is (taken
4409+ from the KEY field in each struct argp_option), or
4410+ a special key specifying something else; the only
4411+ special keys we use here are ARGP_KEY_ARG, meaning
4412+ a non-option argument, and ARGP_KEY_END, meaning
4413+ that all arguments have been parsed
4414+ ARG -- For an option KEY, the string value of its
4415+ argument, or NULL if it has none
4416+ STATE-- A pointer to a struct argp_state, containing
4417+ various useful information about the parsing state; used here
4418+ are the INPUT field, which reflects the INPUT argument to
4419+ argp_parse, and the ARG_NUM field, which is the number of the
4420+ current non-option argument being parsed
4421+ It should return either 0, meaning success, ARGP_ERR_UNKNOWN, meaning the
4422+ given KEY wasn't recognized, or an errno value indicating some other
4423+ error.
4424+
4425+ Note that in this example, main uses a structure to communicate with the
4426+ parse_opt function, a pointer to which it passes in the INPUT argument to
4427+ argp_parse. Of course, it's also possible to use global variables
4428+ instead, but this is somewhat more flexible.
4429+
4430+ The OPTIONS field contains a pointer to a vector of struct argp_option's;
4431+ that structure has the following fields (if you assign your option
4432+ structures using array initialization like this example, unspecified
4433+ fields will be defaulted to 0, and need not be specified):
4434+ NAME -- The name of this option's long option (may be zero)
4435+ KEY -- The KEY to pass to the PARSER function when parsing this option,
4436+ *and* the name of this option's short option, if it is a
4437+ printable ascii character
4438+ ARG -- The name of this option's argument, if any
4439+ FLAGS -- Flags describing this option; some of them are:
4440+ OPTION_ARG_OPTIONAL -- The argument to this option is optional
4441+ OPTION_ALIAS -- This option is an alias for the
4442+ previous option
4443+ OPTION_HIDDEN -- Don't show this option in --help output
4444+ DOC -- A documentation string for this option, shown in --help output
4445+
4446+ An options vector should be terminated by an option with all fields zero. */
4447+
4448+#include <stdlib.h>
4449+#include <argp.h>
4450+
4451+const char *argp_program_version =
4452+ "argp-ex3 1.0";
4453+const char *argp_program_bug_address =
4454+ "<bug-gnu-utils@@gnu.org>";
4455+
4456+/* Program documentation. */
4457+static char doc[] =
4458+ "Argp example #3 -- a program with options and arguments using argp";
4459+
4460+/* A description of the arguments we accept. */
4461+static char args_doc[] = "ARG1 ARG2";
4462+
4463+/* The options we understand. */
4464+static struct argp_option options[] = {
4465+ {"verbose", 'v', 0, 0, "Produce verbose output" },
4466+ {"quiet", 'q', 0, 0, "Don't produce any output" },
4467+ {"silent", 's', 0, OPTION_ALIAS },
4468+ {"output", 'o', "FILE", 0,
4469+ "Output to FILE instead of standard output" },
4470+ { 0 }
4471+};
4472+
4473+/* Used by @code{main} to communicate with @code{parse_opt}. */
4474+struct arguments
4475+{
4476+ char *args[2]; /* @var{arg1} & @var{arg2} */
4477+ int silent, verbose;
4478+ char *output_file;
4479+};
4480+
4481+/* Parse a single option. */
4482+static error_t
4483+parse_opt (int key, char *arg, struct argp_state *state)
4484+{
4485+ /* Get the @var{input} argument from @code{argp_parse}, which we
4486+ know is a pointer to our arguments structure. */
4487+ struct arguments *arguments = state->input;
4488+
4489+ switch (key)
4490+ {
4491+ case 'q': case 's':
4492+ arguments->silent = 1;
4493+ break;
4494+ case 'v':
4495+ arguments->verbose = 1;
4496+ break;
4497+ case 'o':
4498+ arguments->output_file = arg;
4499+ break;
4500+
4501+ case ARGP_KEY_ARG:
4502+ if (state->arg_num >= 2)
4503+ /* Too many arguments. */
4504+ argp_usage (state);
4505+
4506+ arguments->args[state->arg_num] = arg;
4507+
4508+ break;
4509+
4510+ case ARGP_KEY_END:
4511+ if (state->arg_num < 2)
4512+ /* Not enough arguments. */
4513+ argp_usage (state);
4514+ break;
4515+
4516+ default:
4517+ return ARGP_ERR_UNKNOWN;
4518+ }
4519+ return 0;
4520+}
4521+
4522+/* Our argp parser. */
4523+static struct argp argp = { options, parse_opt, args_doc, doc };
4524+
4525+int main (int argc, char **argv)
4526+{
4527+ struct arguments arguments;
4528+
4529+ /* Default values. */
4530+ arguments.silent = 0;
4531+ arguments.verbose = 0;
4532+ arguments.output_file = "-";
4533+
4534+ /* Parse our arguments; every option seen by @code{parse_opt} will
4535+ be reflected in @code{arguments}. */
4536+ argp_parse (&argp, argc, argv, 0, 0, &arguments);
4537+
4538+ printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n"
4539+ "VERBOSE = %s\nSILENT = %s\n",
4540+ arguments.args[0], arguments.args[1],
4541+ arguments.output_file,
4542+ arguments.verbose ? "yes" : "no",
4543+ arguments.silent ? "yes" : "no");
4544+
4545+ exit (0);
4546+}
4547Index: git/test/argp/argp-ex4.c
4548===================================================================
4549--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4550+++ git/test/argp/argp-ex4.c 2012-06-18 13:10:44.060825542 -0700
4551@@ -0,0 +1,167 @@
4552+/* Argp example #4 -- a program with somewhat more complicated options */
4553+
4554+/* This program uses the same features as example 3, but has more
4555+ options, and somewhat more structure in the -help output. It
4556+ also shows how you can `steal' the remainder of the input
4557+ arguments past a certain point, for programs that accept a
4558+ list of items. It also shows the special argp KEY value
4559+ ARGP_KEY_NO_ARGS, which is only given if no non-option
4560+ arguments were supplied to the program.
4561+
4562+ For structuring the help output, two features are used,
4563+ *headers* which are entries in the options vector with the
4564+ first four fields being zero, and a two part documentation
4565+ string (in the variable DOC), which allows documentation both
4566+ before and after the options; the two parts of DOC are
4567+ separated by a vertical-tab character ('\v', or '\013'). By
4568+ convention, the documentation before the options is just a
4569+ short string saying what the program does, and that afterwards
4570+ is longer, describing the behavior in more detail. All
4571+ documentation strings are automatically filled for output,
4572+ although newlines may be included to force a line break at a
4573+ particular point. All documentation strings are also passed to
4574+ the `gettext' function, for possible translation into the
4575+ current locale. */
4576+
4577+#include <stdlib.h>
4578+#include <error.h>
4579+#include <argp.h>
4580+
4581+const char *argp_program_version =
4582+ "argp-ex4 1.0";
4583+const char *argp_program_bug_address =
4584+ "<bug-gnu-utils@@prep.ai.mit.edu>";
4585+
4586+/* Program documentation. */
4587+static char doc[] =
4588+ "Argp example #4 -- a program with somewhat more complicated\
4589+options\
4590+\vThis part of the documentation comes *after* the options;\
4591+ note that the text is automatically filled, but it's possible\
4592+ to force a line-break, e.g.\n<-- here.";
4593+
4594+/* A description of the arguments we accept. */
4595+static char args_doc[] = "ARG1 [STRING...]";
4596+
4597+/* Keys for options without short-options. */
4598+#define OPT_ABORT 1 /* --abort */
4599+
4600+/* The options we understand. */
4601+static struct argp_option options[] = {
4602+ {"verbose", 'v', 0, 0, "Produce verbose output" },
4603+ {"quiet", 'q', 0, 0, "Don't produce any output" },
4604+ {"silent", 's', 0, OPTION_ALIAS },
4605+ {"output", 'o', "FILE", 0,
4606+ "Output to FILE instead of standard output" },
4607+
4608+ {0,0,0,0, "The following options should be grouped together:" },
4609+ {"repeat", 'r', "COUNT", OPTION_ARG_OPTIONAL,
4610+ "Repeat the output COUNT (default 10) times"},
4611+ {"abort", OPT_ABORT, 0, 0, "Abort before showing any output"},
4612+
4613+ { 0 }
4614+};
4615+
4616+/* Used by @code{main} to communicate with @code{parse_opt}. */
4617+struct arguments
4618+{
4619+ char *arg1; /* @var{arg1} */
4620+ char **strings; /* [@var{string}@dots{}] */
4621+ int silent, verbose, abort; /* @samp{-s}, @samp{-v}, @samp{--abort} */
4622+ char *output_file; /* @var{file} arg to @samp{--output} */
4623+ int repeat_count; /* @var{count} arg to @samp{--repeat} */
4624+};
4625+
4626+/* Parse a single option. */
4627+static error_t
4628+parse_opt (int key, char *arg, struct argp_state *state)
4629+{
4630+ /* Get the @code{input} argument from @code{argp_parse}, which we
4631+ know is a pointer to our arguments structure. */
4632+ struct arguments *arguments = state->input;
4633+
4634+ switch (key)
4635+ {
4636+ case 'q': case 's':
4637+ arguments->silent = 1;
4638+ break;
4639+ case 'v':
4640+ arguments->verbose = 1;
4641+ break;
4642+ case 'o':
4643+ arguments->output_file = arg;
4644+ break;
4645+ case 'r':
4646+ arguments->repeat_count = arg ? atoi (arg) : 10;
4647+ break;
4648+ case OPT_ABORT:
4649+ arguments->abort = 1;
4650+ break;
4651+
4652+ case ARGP_KEY_NO_ARGS:
4653+ argp_usage (state);
4654+
4655+ case ARGP_KEY_ARG:
4656+ /* Here we know that @code{state->arg_num == 0}, since we
4657+ force argument parsing to end before any more arguments can
4658+ get here. */
4659+ arguments->arg1 = arg;
4660+
4661+ /* Now we consume all the rest of the arguments.
4662+ @code{state->next} is the index in @code{state->argv} of the
4663+ next argument to be parsed, which is the first @var{string}
4664+ we're interested in, so we can just use
4665+ @code{&state->argv[state->next]} as the value for
4666+ arguments->strings.
4667+
4668+ @emph{In addition}, by setting @code{state->next} to the end
4669+ of the arguments, we can force argp to stop parsing here and
4670+ return. */
4671+ arguments->strings = &state->argv[state->next];
4672+ state->next = state->argc;
4673+
4674+ break;
4675+
4676+ default:
4677+ return ARGP_ERR_UNKNOWN;
4678+ }
4679+ return 0;
4680+}
4681+
4682+/* Our argp parser. */
4683+static struct argp argp = { options, parse_opt, args_doc, doc };
4684+
4685+int main (int argc, char **argv)
4686+{
4687+ int i, j;
4688+ struct arguments arguments;
4689+
4690+ /* Default values. */
4691+ arguments.silent = 0;
4692+ arguments.verbose = 0;
4693+ arguments.output_file = "-";
4694+ arguments.repeat_count = 1;
4695+ arguments.abort = 0;
4696+
4697+ /* Parse our arguments; every option seen by @code{parse_opt} will be
4698+ reflected in @code{arguments}. */
4699+ argp_parse (&argp, argc, argv, 0, 0, &arguments);
4700+
4701+ if (arguments.abort)
4702+ error (10, 0, "ABORTED");
4703+
4704+ for (i = 0; i < arguments.repeat_count; i++)
4705+ {
4706+ printf ("ARG1 = %s\n", arguments.arg1);
4707+ printf ("STRINGS = ");
4708+ for (j = 0; arguments.strings[j]; j++)
4709+ printf (j == 0 ? "%s" : ", %s", arguments.strings[j]);
4710+ printf ("\n");
4711+ printf ("OUTPUT_FILE = %s\nVERBOSE = %s\nSILENT = %s\n",
4712+ arguments.output_file,
4713+ arguments.verbose ? "yes" : "no",
4714+ arguments.silent ? "yes" : "no");
4715+ }
4716+
4717+ exit (0);
4718+}
4719Index: git/test/argp/argp-test.c
4720===================================================================
4721--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4722+++ git/test/argp/argp-test.c 2012-06-18 13:10:44.060825542 -0700
4723@@ -0,0 +1,209 @@
4724+/* Test program for argp argument parser
4725+ Copyright (C) 1997 Free Software Foundation, Inc.
4726+ This file is part of the GNU C Library.
4727+ Written by Miles Bader <miles at gnu.ai.mit.edu>.
4728+
4729+ The GNU C Library is free software; you can redistribute it and/or
4730+ modify it under the terms of the GNU Lesser General Public
4731+ License as published by the Free Software Foundation; either
4732+ version 2.1 of the License, or (at your option) any later version.
4733+
4734+ The GNU C Library is distributed in the hope that it will be useful,
4735+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4736+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4737+ Lesser General Public License for more details.
4738+
4739+ You should have received a copy of the GNU Lesser General Public
4740+ License along with the GNU C Library; if not, write to the Free
4741+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4742+ 02111-1307 USA. */
4743+
4744+#ifdef HAVE_CONFIG_H
4745+#include <config.h>
4746+#endif
4747+
4748+#include <stdlib.h>
4749+#include <time.h>
4750+#include <string.h>
4751+#include <argp.h>
4752+
4753+const char *argp_program_version = "argp-test 1.0";
4754+
4755+struct argp_option sub_options[] =
4756+{
4757+ {"subopt1", 's', 0, 0, "Nested option 1"},
4758+ {"subopt2", 'S', 0, 0, "Nested option 2"},
4759+
4760+ { 0, 0, 0, 0, "Some more nested options:", 10},
4761+ {"subopt3", 'p', 0, 0, "Nested option 3"},
4762+
4763+ {"subopt4", 'q', 0, 0, "Nested option 4", 1},
4764+
4765+ {0}
4766+};
4767+
4768+static const char sub_args_doc[] = "STRING...\n-";
4769+static const char sub_doc[] = "\vThis is the doc string from the sub-arg-parser.";
4770+
4771+static error_t
4772+sub_parse_opt (int key, char *arg, struct argp_state *state)
4773+{
4774+ switch (key)
4775+ {
4776+ case ARGP_KEY_NO_ARGS:
4777+ printf ("NO SUB ARGS\n");
4778+ break;
4779+ case ARGP_KEY_ARG:
4780+ printf ("SUB ARG: %s\n", arg);
4781+ break;
4782+
4783+ case 's' : case 'S': case 'p': case 'q':
4784+ printf ("SUB KEY %c\n", key);
4785+ break;
4786+
4787+ default:
4788+ return ARGP_ERR_UNKNOWN;
4789+ }
4790+ return 0;
4791+}
4792+
4793+static char *
4794+sub_help_filter (int key, const char *text, void *input)
4795+{
4796+ if (key == ARGP_KEY_HELP_EXTRA)
4797+ return strdup ("This is some extra text from the sub parser (note that it \
4798+is preceded by a blank line).");
4799+ else
4800+ return (char *)text;
4801+}
4802+
4803+static struct argp sub_argp = {
4804+ sub_options, sub_parse_opt, sub_args_doc, sub_doc, 0, sub_help_filter
4805+};
4806+
4807+/* Structure used to communicate with the parsing functions. */
4808+struct params
4809+{
4810+ unsigned foonly; /* Value parsed for foonly. */
4811+ unsigned foonly_default; /* Default value for it. */
4812+};
4813+
4814+#define OPT_PGRP 1
4815+#define OPT_SESS 2
4816+
4817+struct argp_option options[] =
4818+{
4819+ {"pid", 'p', "PID", 0, "List the process PID"},
4820+ {"pgrp", OPT_PGRP,"PGRP",0, "List processes in the process group PGRP"},
4821+ {"no-parent", 'P', 0, 0, "Include processes without parents"},
4822+ {0, 'x', 0, OPTION_ALIAS},
4823+ {"all-fields",'Q', 0, 0, "Don't elide unusable fields (normally"
4824+ " if there's some reason ps can't"
4825+ " print a field for any process, it's"
4826+ " removed from the output entirely)" },
4827+ {"reverse", 'r', 0, 0, "Reverse the order of any sort"},
4828+ {"gratuitously-long-reverse-option", 0, 0, OPTION_ALIAS},
4829+ {"session", OPT_SESS,"SID", OPTION_ARG_OPTIONAL,
4830+ "Add the processes from the session"
4831+ " SID (which defaults to the sid of"
4832+ " the current process)" },
4833+
4834+ {0,0,0,0, "Here are some more options:"},
4835+ {"foonly", 'f', "ZOT", OPTION_ARG_OPTIONAL, "Glork a foonly"},
4836+ {"zaza", 'z', 0, 0, "Snit a zar"},
4837+
4838+ {0}
4839+};
4840+
4841+static const char args_doc[] = "STRING";
4842+static const char doc[] = "Test program for argp."
4843+ "\vThis doc string comes after the options."
4844+ "\nHey! Some manual formatting!"
4845+ "\nThe current time is: %s";
4846+
4847+static void
4848+popt (int key, char *arg)
4849+{
4850+ char buf[10];
4851+ if (isprint (key))
4852+ sprintf (buf, "%c", key);
4853+ else
4854+ sprintf (buf, "%d", key);
4855+ if (arg)
4856+ printf ("KEY %s: %s\n", buf, arg);
4857+ else
4858+ printf ("KEY %s\n", buf);
4859+}
4860+
4861+static error_t
4862+parse_opt (int key, char *arg, struct argp_state *state)
4863+{
4864+ struct params *params = state->input;
4865+
4866+ switch (key)
4867+ {
4868+ case ARGP_KEY_NO_ARGS:
4869+ printf ("NO ARGS\n");
4870+ break;
4871+
4872+ case ARGP_KEY_ARG:
4873+ if (state->arg_num > 0)
4874+ return ARGP_ERR_UNKNOWN; /* Leave it for the sub-arg parser. */
4875+ printf ("ARG: %s\n", arg);
4876+ break;
4877+
4878+ case 'f':
4879+ if (arg)
4880+ params->foonly = atoi (arg);
4881+ else
4882+ params->foonly = params->foonly_default;
4883+ popt (key, arg);
4884+ break;
4885+
4886+ case 'p': case 'P': case OPT_PGRP: case 'x': case 'Q':
4887+ case 'r': case OPT_SESS: case 'z':
4888+ popt (key, arg);
4889+ break;
4890+
4891+ default:
4892+ return ARGP_ERR_UNKNOWN;
4893+ }
4894+ return 0;
4895+}
4896+
4897+static char *
4898+help_filter (int key, const char *text, void *input)
4899+{
4900+ char *new_text;
4901+ struct params *params = input;
4902+
4903+ if (key == ARGP_KEY_HELP_POST_DOC && text)
4904+ {
4905+ time_t now = time (0);
4906+ asprintf (&new_text, text, ctime (&now));
4907+ }
4908+ else if (key == 'f')
4909+ /* Show the default for the --foonly option. */
4910+ asprintf (&new_text, "%s (ZOT defaults to %x)",
4911+ text, params->foonly_default);
4912+ else
4913+ new_text = (char *)text;
4914+
4915+ return new_text;
4916+}
4917+
4918+static struct argp_child argp_children[] = { { &sub_argp }, { 0 } };
4919+static struct argp argp = {
4920+ options, parse_opt, args_doc, doc, argp_children, help_filter
4921+};
4922+
4923+int
4924+main (int argc, char **argv)
4925+{
4926+ struct params params;
4927+ params.foonly = 0;
4928+ params.foonly_default = random ();
4929+ argp_parse (&argp, argc, argv, 0, 0, &params);
4930+ printf ("After parsing: foonly = %x\n", params.foonly);
4931+ return 0;
4932+}
4933Index: git/test/argp/bug-argp1.c
4934===================================================================
4935--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4936+++ git/test/argp/bug-argp1.c 2012-06-18 13:10:44.060825542 -0700
4937@@ -0,0 +1,26 @@
4938+#include <argp.h>
4939+
4940+
4941+static const struct argp_option test_options[] =
4942+{
4943+ { NULL, 'a', NULL, OPTION_DOC, NULL },
4944+ { NULL, 'b', NULL, OPTION_DOC, NULL },
4945+ { NULL, 0, NULL, 0, NULL }
4946+};
4947+
4948+static struct argp test_argp =
4949+{
4950+ test_options
4951+};
4952+
4953+
4954+static int
4955+do_test (int argc, char *argv[])
4956+{
4957+ int i;
4958+ argp_parse (&test_argp, argc, argv, 0, &i, NULL);
4959+ return 0;
4960+}
4961+
4962+#define TEST_FUNCTION do_test (argc, argv)
4963+#include "../test-skeleton.c"
4964Index: git/test/argp/tst-argp1.c
4965===================================================================
4966--- /dev/null 1970-01-01 00:00:00.000000000 +0000
4967+++ git/test/argp/tst-argp1.c 2012-06-18 13:10:44.060825542 -0700
4968@@ -0,0 +1,118 @@
4969+/* Copyright (C) 2002, 2003 Free Software Foundation, Inc.
4970+ This file is part of the GNU C Library.
4971+ Contributed by Ulrich Drepper <drepper at redhat.com>, 2002.
4972+
4973+ The GNU C Library is free software; you can redistribute it and/or
4974+ modify it under the terms of the GNU Lesser General Public
4975+ License as published by the Free Software Foundation; either
4976+ version 2.1 of the License, or (at your option) any later version.
4977+
4978+ The GNU C Library is distributed in the hope that it will be useful,
4979+ but WITHOUT ANY WARRANTY; without even the implied warranty of
4980+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
4981+ Lesser General Public License for more details.
4982+
4983+ You should have received a copy of the GNU Lesser General Public
4984+ License along with the GNU C Library; if not, write to the Free
4985+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
4986+ 02111-1307 USA. */
4987+
4988+#include <argp.h>
4989+
4990+
4991+
4992+
4993+#define OPT_TO_THREAD 300
4994+#define OPT_TO_PROCESS 301
4995+#define OPT_SYNC_SIGNAL 302
4996+#define OPT_SYNC_JOIN 303
4997+#define OPT_TOPLEVEL 304
4998+
4999+
5000+static const struct argp_option test_options[] =
5001+ {
5002+ { NULL, 0, NULL, 0, "\
5003+This is a test for threads so we allow ther user to selection the number of \
5004+threads which are used at any one time. Independently the total number of \
5005+rounds can be selected. This is the total number of threads which will have \
5006+run when the process terminates:" },
5007+ { "threads", 't', "NUMBER", 0, "Number of threads used at once" },
5008+ { "starts", 's', "NUMBER", 0, "Total number of working threads" },
5009+ { "toplevel", OPT_TOPLEVEL, "NUMBER", 0,
5010+ "Number of toplevel threads which start the other threads; this \
5011+implies --sync-join" },
5012+
5013+ { NULL, 0, NULL, 0, "\
5014+Each thread can do one of two things: sleep or do work. The latter is 100% \
5015+CPU bound. The work load is the probability a thread does work. All values \
5016+from zero to 100 (inclusive) are valid. How often each thread repeats this \
5017+can be determined by the number of rounds. The work cost determines how long \
5018+each work session (not sleeping) takes. If it is zero a thread would \
5019+effectively nothing. By setting the number of rounds to zero the thread \
5020+does no work at all and pure thread creation times can be measured." },
5021+ { "workload", 'w', "PERCENT", 0, "Percentage of time spent working" },
5022+ { "workcost", 'c', "NUMBER", 0,
5023+ "Factor in the cost of each round of working" },
5024+ { "rounds", 'r', "NUMBER", 0, "Number of rounds each thread runs" },
5025+
5026+ { NULL, 0, NULL, 0, "\
5027+There are a number of different methods how thread creation can be \
5028+synchronized. Synchronization is necessary since the number of concurrently \
5029+running threads is limited." },
5030+ { "sync-signal", OPT_SYNC_SIGNAL, NULL, 0,
5031+ "Synchronize using a signal (default)" },
5032+ { "sync-join", OPT_SYNC_JOIN, NULL, 0, "Synchronize using pthread_join" },
5033+
5034+ { NULL, 0, NULL, 0, "\
5035+One parameter for each threads execution is the size of the stack. If this \
5036+parameter is not used the system's default stack size is used. If many \
5037+threads are used the stack size should be chosen quite small." },
5038+ { "stacksize", 'S', "BYTES", 0, "Size of threads stack" },
5039+ { "guardsize", 'g', "BYTES", 0,
5040+ "Size of stack guard area; must fit into the stack" },
5041+
5042+ { NULL, 0, NULL, 0, "Signal options:" },
5043+ { "to-thread", OPT_TO_THREAD, NULL, 0, "Send signal to main thread" },
5044+ { "to-process", OPT_TO_PROCESS, NULL, 0,
5045+ "Send signal to process (default)" },
5046+
5047+ { NULL, 0, NULL, 0, "Administrative options:" },
5048+ { "progress", 'p', NULL, 0, "Show signs of progress" },
5049+ { "timing", 'T', NULL, 0,
5050+ "Measure time from startup to the last thread finishing" },
5051+ { NULL, 0, NULL, 0, NULL }
5052+ };
5053+
5054+/* Prototype for option handler. */
5055+static error_t parse_opt (int key, char *arg, struct argp_state *state);
5056+
5057+/* Data structure to communicate with argp functions. */
5058+static struct argp argp =
5059+{
5060+ test_options, parse_opt
5061+};
5062+
5063+
5064+static int
5065+do_test (void)
5066+{
5067+ int argc = 2;
5068+ char *argv[3] = { (char *) "tst-argp1", (char *) "--help", NULL };
5069+ int remaining;
5070+
5071+ /* Parse and process arguments. */
5072+ argp_parse (&argp, argc, argv, 0, &remaining, NULL);
5073+
5074+ return 0;
5075+}
5076+
5077+
5078+/* Handle program arguments. */
5079+static error_t
5080+parse_opt (int key, char *arg, struct argp_state *state)
5081+{
5082+ return ARGP_ERR_UNKNOWN;
5083+}
5084+
5085+#define TEST_FUNCTION do_test ()
5086+#include "../test-skeleton.c"
5087Index: git/test/argp/tst-argp2.c
5088===================================================================
5089--- /dev/null 1970-01-01 00:00:00.000000000 +0000
5090+++ git/test/argp/tst-argp2.c 2012-06-18 13:10:44.064825538 -0700
5091@@ -0,0 +1,101 @@
5092+/* Copyright (C) 2007 Free Software Foundation, Inc.
5093+ This file is part of the GNU C Library.
5094+ Contributed by Jakub Jelinek <jakub at redhat.com>, 2007.
5095+
5096+ The GNU C Library is free software; you can redistribute it and/or
5097+ modify it under the terms of the GNU Lesser General Public
5098+ License as published by the Free Software Foundation; either
5099+ version 2.1 of the License, or (at your option) any later version.
5100+
5101+ The GNU C Library is distributed in the hope that it will be useful,
5102+ but WITHOUT ANY WARRANTY; without even the implied warranty of
5103+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
5104+ Lesser General Public License for more details.
5105+
5106+ You should have received a copy of the GNU Lesser General Public
5107+ License along with the GNU C Library; if not, write to the Free
5108+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
5109+ 02111-1307 USA. */
5110+
5111+#include <argp.h>
5112+
5113+static const struct argp_option opt1[] =
5114+ {
5115+ { "opt1", '1', "NUMBER", 0, "Option 1" },
5116+ { NULL, 0, NULL, 0, NULL }
5117+ };
5118+
5119+static const struct argp_option opt2[] =
5120+ {
5121+ { "opt2", '2', "NUMBER", 0, "Option 2" },
5122+ { NULL, 0, NULL, 0, NULL }
5123+ };
5124+
5125+static const struct argp_option opt3[] =
5126+ {
5127+ { "opt3", '3', "NUMBER", 0, "Option 3" },
5128+ { NULL, 0, NULL, 0, NULL }
5129+ };
5130+
5131+static const struct argp_option opt4[] =
5132+ {
5133+ { "opt4", '4', "NUMBER", 0, "Option 4" },
5134+ { NULL, 0, NULL, 0, NULL }
5135+ };
5136+
5137+static const struct argp_option opt5[] =
5138+ {
5139+ { "opt5", '5', "NUMBER", 0, "Option 5" },
5140+ { NULL, 0, NULL, 0, NULL }
5141+ };
5142+
5143+static struct argp argp5 =
5144+ {
5145+ opt5, NULL, "args doc5", "doc5", NULL, NULL, NULL
5146+ };
5147+
5148+static struct argp argp4 =
5149+ {
5150+ opt4, NULL, "args doc4", "doc4", NULL, NULL, NULL
5151+ };
5152+
5153+static struct argp argp3 =
5154+ {
5155+ opt3, NULL, "args doc3", "doc3", NULL, NULL, NULL
5156+ };
5157+
5158+static struct argp_child children2[] =
5159+ {
5160+ { &argp4, 0, "child3", 3 },
5161+ { &argp5, 0, "child4", 4 },
5162+ { NULL, 0, NULL, 0 }
5163+ };
5164+
5165+static struct argp argp2 =
5166+ {
5167+ opt2, NULL, "args doc2", "doc2", children2, NULL, NULL
5168+ };
5169+
5170+static struct argp_child children1[] =
5171+ {
5172+ { &argp2, 0, "child1", 1 },
5173+ { &argp3, 0, "child2", 2 },
5174+ { NULL, 0, NULL, 0 }
5175+ };
5176+
5177+static struct argp argp1 =
5178+ {
5179+ opt1, NULL, "args doc1", "doc1", children1, NULL, NULL
5180+ };
5181+
5182+
5183+static int
5184+do_test (void)
5185+{
5186+ argp_help (&argp1, stdout, ARGP_HELP_LONG, (char *) "tst-argp2");
5187+ return 0;
5188+}
5189+
5190+
5191+#define TEST_FUNCTION do_test ()
5192+#include "../test-skeleton.c"
diff --git a/meta/recipes-core/uclibc/uclibc-git/compile-arm-fork-with-O2.patch b/meta/recipes-core/uclibc/uclibc-git/compile-arm-fork-with-O2.patch
new file mode 100644
index 0000000000..15ee0ca156
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/compile-arm-fork-with-O2.patch
@@ -0,0 +1,21 @@
1When compiling in thumb mode for arm with -Os gcc gives up since it can not find registers
2to spill. So we use -O2 option for compiling fork.c It may be addressable in gcc.
3
4Signed-off-by: Khem Raj <raj.khem@gmail.com>
5
6Upstream-Status: Pending
7
8diff --git a/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch b/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
9index 329d8a9..41e3646 100644
10--- a/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
11+++ b/libpthread/nptl/sysdeps/unix/sysv/linux/arm/Makefile.arch
12@@ -30,3 +30,9 @@ CFLAGS-OMIT-libc-lowlevellock.c = -DNOT_IN_libc -DIS_IN_libpthread
13 # This macro should be alternatively implemented in THUMB
14 # assembly.
15 ASFLAGS-vfork.S = -marm
16+
17+# For arm fork.c does not compile with -Os when in compiling
18+# in thumb1 mode
19+ifeq ($(COMPILE_IN_THUMB_MODE),y)
20+CFLAGS-fork.c = -O2
21+endif
diff --git a/meta/recipes-core/uclibc/uclibc-git/locale.cfg b/meta/recipes-core/uclibc/uclibc-git/locale.cfg
new file mode 100644
index 0000000000..fc66435163
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/locale.cfg
@@ -0,0 +1,3 @@
1UCLIBC_HAS_LOCALE=y
2UCLIBC_HAS_XLOCALE=y
3UCLIBC_BUILD_MINIMAL_LOCALE=y
diff --git a/meta/recipes-core/uclibc/uclibc-git/obstack.cfg b/meta/recipes-core/uclibc/uclibc-git/obstack.cfg
new file mode 100644
index 0000000000..36bf9d6e4a
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/obstack.cfg
@@ -0,0 +1 @@
UCLIBC_HAS_OBSTACK=y
diff --git a/meta/recipes-core/uclibc/uclibc-git/orign_path.patch b/meta/recipes-core/uclibc/uclibc-git/orign_path.patch
new file mode 100644
index 0000000000..81bb8f8459
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/orign_path.patch
@@ -0,0 +1,186 @@
1Patch is backported from
2http://lists.busybox.net/pipermail/uclibc/2011-March/045003.html
3
4Upstream-Status: Pending
5
6Index: git/ldso/ldso/dl-elf.c
7===================================================================
8--- git.orig/ldso/ldso/dl-elf.c 2012-06-19 18:29:08.629931662 -0700
9+++ git/ldso/ldso/dl-elf.c 2012-06-19 21:21:14.798431393 -0700
10@@ -133,56 +133,60 @@
11 * in uClibc/ldso/util/ldd.c */
12 static struct elf_resolve *
13 search_for_named_library(const char *name, unsigned rflags, const char *path_list,
14- struct dyn_elf **rpnt)
15+ struct dyn_elf **rpnt, const char* origin)
16 {
17- char *path, *path_n, *mylibname;
18+ char *mylibname;
19 struct elf_resolve *tpnt;
20- int done;
21+ const char *p, *pn;
22+ int plen;
23
24 if (path_list==NULL)
25 return NULL;
26
27- /* We need a writable copy of this string, but we don't
28- * need this allocated permanently since we don't want
29- * to leak memory, so use alloca to put path on the stack */
30- done = _dl_strlen(path_list);
31- path = alloca(done + 1);
32-
33 /* another bit of local storage */
34 mylibname = alloca(2050);
35
36- _dl_memcpy(path, path_list, done+1);
37-
38 /* Unlike ldd.c, don't bother to eliminate double //s */
39
40 /* Replace colons with zeros in path_list */
41 /* : at the beginning or end of path maps to CWD */
42 /* :: anywhere maps CWD */
43 /* "" maps to CWD */
44- done = 0;
45- path_n = path;
46- do {
47- if (*path == 0) {
48- *path = ':';
49- done = 1;
50+ for (p = path_list; p != NULL; p = pn) {
51+ pn = _dl_strchr(p + 1, ':');
52+ if (pn != NULL) {
53+ plen = pn - p;
54+ pn++;
55+ } else
56+ plen = _dl_strlen(p);
57+
58+ if (plen >= 7 && _dl_memcmp(p, "$ORIGIN", 7) == 0) {
59+ int olen;
60+ if (rflags && plen != 7)
61+ continue;
62+ if (origin == NULL)
63+ continue;
64+ for (olen = _dl_strlen(origin) - 1; olen >= 0 && origin[olen] != '/'; olen--)
65+ ;
66+ if (olen <= 0)
67+ continue;
68+ _dl_memcpy(&mylibname[0], origin, olen);
69+ _dl_memcpy(&mylibname[olen], p + 7, plen - 7);
70+ mylibname[olen + plen - 7] = 0;
71+ } else if (plen != 0) {
72+ _dl_memcpy(mylibname, p, plen);
73+ mylibname[plen] = 0;
74+ } else {
75+ _dl_strcpy(mylibname, ".");
76 }
77- if (*path == ':') {
78- *path = 0;
79- if (*path_n)
80- _dl_strcpy(mylibname, path_n);
81- else
82- _dl_strcpy(mylibname, "."); /* Assume current dir if empty path */
83- _dl_strcat(mylibname, "/");
84- _dl_strcat(mylibname, name);
85+ _dl_strcat(mylibname, "/");
86+ _dl_strcat(mylibname, name);
87 #ifdef __LDSO_SAFE_RUNPATH__
88- if (*mylibname == '/')
89+ if (*mylibname == '/')
90 #endif
91- if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
92- return tpnt;
93- path_n = path+1;
94- }
95- path++;
96- } while (!done);
97+ if ((tpnt = _dl_load_elf_shared_library(rflags, rpnt, mylibname)) != NULL)
98+ return tpnt;
99+ }
100 return NULL;
101 }
102
103@@ -234,8 +238,10 @@
104 if (pnt) {
105 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
106 _dl_if_debug_dprint("\tsearching RPATH='%s'\n", pnt);
107- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
108+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt,
109+ tpnt->libname)) != NULL)
110 return tpnt1;
111+
112 }
113 #endif
114
115@@ -243,7 +249,7 @@
116 /* Check in LD_{ELF_}LIBRARY_PATH, if specified and allowed */
117 if (_dl_library_path) {
118 _dl_if_debug_dprint("\tsearching LD_LIBRARY_PATH='%s'\n", _dl_library_path);
119- if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt)) != NULL)
120+ if ((tpnt1 = search_for_named_library(libname, rflags, _dl_library_path, rpnt, NULL)) != NULL)
121 {
122 return tpnt1;
123 }
124@@ -257,7 +263,7 @@
125 if (pnt) {
126 pnt += (unsigned long) tpnt->dynamic_info[DT_STRTAB];
127 _dl_if_debug_dprint("\tsearching RUNPATH='%s'\n", pnt);
128- if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt)) != NULL)
129+ if ((tpnt1 = search_for_named_library(libname, rflags, pnt, rpnt, NULL)) != NULL)
130 return tpnt1;
131 }
132 #endif
133@@ -291,7 +297,7 @@
134 /* Look for libraries wherever the shared library loader
135 * was installed */
136 _dl_if_debug_dprint("\tsearching ldso dir='%s'\n", _dl_ldsopath);
137- tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt);
138+ tpnt1 = search_for_named_library(libname, rflags, _dl_ldsopath, rpnt, NULL);
139 if (tpnt1 != NULL)
140 return tpnt1;
141 #endif
142@@ -304,7 +310,7 @@
143 #ifndef __LDSO_CACHE_SUPPORT__
144 ":" UCLIBC_RUNTIME_PREFIX "usr/X11R6/lib"
145 #endif
146- , rpnt);
147+ , rpnt, NULL);
148 if (tpnt1 != NULL)
149 return tpnt1;
150
151Index: git/ldso/ldso/ldso.c
152===================================================================
153--- git.orig/ldso/ldso/ldso.c 2012-06-19 18:29:08.633931663 -0700
154+++ git/ldso/ldso/ldso.c 2012-06-19 18:29:10.197931738 -0700
155@@ -403,6 +403,20 @@
156 return p - list;
157 }
158
159+static void _dl_setup_progname(const char *argv0)
160+{
161+ char image[PATH_MAX];
162+ ssize_t s;
163+
164+ s = _dl_readlink("/proc/self/exe", image, sizeof(image));
165+ if (s > 0 && image[0] == '/') {
166+ image[s] = 0;
167+ _dl_progname = _dl_strdup(image);
168+ } else if (argv0) {
169+ _dl_progname = argv0;
170+ }
171+}
172+
173 void *_dl_get_ready_to_run(struct elf_resolve *tpnt, DL_LOADADDR_TYPE load_addr,
174 ElfW(auxv_t) auxvt[AT_EGID + 1], char **envp, char **argv
175 DL_GET_READY_TO_RUN_EXTRA_PARMS)
176@@ -454,9 +468,7 @@
177 * been fixed up by now. Still no function calls outside of this
178 * library, since the dynamic resolver is not yet ready.
179 */
180- if (argv[0]) {
181- _dl_progname = argv[0];
182- }
183+ _dl_setup_progname(argv[0]);
184
185 #ifdef __DSBT__
186 _dl_ldso_dsbt = (void *)tpnt->dynamic_info[DT_DSBT_BASE_IDX];
diff --git a/meta/recipes-core/uclibc/uclibc-git/powerpc_copysignl.patch b/meta/recipes-core/uclibc/uclibc-git/powerpc_copysignl.patch
new file mode 100644
index 0000000000..2f014cd91e
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/powerpc_copysignl.patch
@@ -0,0 +1,113 @@
1Add ppc copysignl implementation
2
3Upstream-Status: Pending
4
5Signed-off-by: Khem Raj <raj.khem@gmail.com>
6
7Index: git/libc/sysdeps/linux/powerpc/Makefile.arch
8===================================================================
9--- git.orig/libc/sysdeps/linux/powerpc/Makefile.arch 2013-05-23 11:09:50.000000000 -0700
10+++ git/libc/sysdeps/linux/powerpc/Makefile.arch 2013-05-23 11:12:06.072328399 -0700
11@@ -5,7 +5,7 @@
12 # Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
13 #
14
15-CSRC-y := __syscall_error.c ioctl.c
16+CSRC-y := __syscall_error.c ioctl.c copysignl.c
17
18 SSRC-y := \
19 __longjmp.S setjmp.S bsd-setjmp.S bsd-_setjmp.S brk.S \
20Index: git/libc/sysdeps/linux/powerpc/copysignl.c
21===================================================================
22--- /dev/null 1970-01-01 00:00:00.000000000 +0000
23+++ git/libc/sysdeps/linux/powerpc/copysignl.c 2013-05-23 11:11:37.600327865 -0700
24@@ -0,0 +1,89 @@
25+/* s_copysignl.c -- long double version of s_copysign.c.
26+ * Conversion to long double by Ulrich Drepper,
27+ * Cygnus Support, drepper@cygnus.com.
28+ */
29+
30+/*
31+ * ====================================================
32+ * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
33+ *
34+ * Developed at SunPro, a Sun Microsystems, Inc. business.
35+ * Permission to use, copy, modify, and distribute this
36+ * software is freely granted, provided that this notice
37+ * is preserved.
38+ * ====================================================
39+ */
40+
41+/*
42+ * copysignl(long double x, long double y)
43+ * copysignl(x,y) returns a value with the magnitude of x and
44+ * with the sign bit of y.
45+ */
46+
47+#include <endian.h>
48+#include <stdint.h>
49+
50+#if __FLOAT_WORD_ORDER == BIG_ENDIAN
51+
52+typedef union
53+{
54+ long double value;
55+ struct
56+ {
57+ int sign_exponent:16;
58+ unsigned int empty:16;
59+ uint32_t msw;
60+ uint32_t lsw;
61+ } parts;
62+} ieee_long_double_shape_type;
63+
64+#endif
65+
66+#if __FLOAT_WORD_ORDER == LITTLE_ENDIAN
67+
68+typedef union
69+{
70+ long double value;
71+ struct
72+ {
73+ uint32_t lsw;
74+ uint32_t msw;
75+ int sign_exponent:16;
76+ unsigned int empty:16;
77+ } parts;
78+} ieee_long_double_shape_type;
79+
80+#endif
81+
82+/* Get int from the exponent of a long double. */
83+
84+#define GET_LDOUBLE_EXP(exp,d) \
85+do { \
86+ ieee_long_double_shape_type ge_u; \
87+ ge_u.value = (d); \
88+ (exp) = ge_u.parts.sign_exponent; \
89+} while (0)
90+
91+/* Set exponent of a long double from an int. */
92+
93+#define SET_LDOUBLE_EXP(d,exp) \
94+do { \
95+ ieee_long_double_shape_type se_u; \
96+ se_u.value = (d); \
97+ se_u.parts.sign_exponent = (exp); \
98+ (d) = se_u.value; \
99+} while (0)
100+
101+long double copysignl(long double x, long double y);
102+libc_hidden_proto(copysignl);
103+
104+long double copysignl(long double x, long double y)
105+{
106+ uint32_t es1,es2;
107+ GET_LDOUBLE_EXP(es1,x);
108+ GET_LDOUBLE_EXP(es2,y);
109+ SET_LDOUBLE_EXP(x,(es1&0x7fff)|(es2&0x8000));
110+ return x;
111+}
112+
113+libc_hidden_def(copysignl);
diff --git a/meta/recipes-core/uclibc/uclibc-git/remove_attribute_optimize_Os.patch b/meta/recipes-core/uclibc/uclibc-git/remove_attribute_optimize_Os.patch
new file mode 100644
index 0000000000..d2a8a81b94
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/remove_attribute_optimize_Os.patch
@@ -0,0 +1,140 @@
1Dont support localised optimizations this helps to have a global -O level
2
3Signed-off-by: Khem Raj <raj.khem@gmail.com>
4Upstream-Status: Pending
5
6Index: git/libpthread/nptl/pthread_mutex_timedlock.c
7===================================================================
8--- git.orig/libpthread/nptl/pthread_mutex_timedlock.c 2013-01-21 16:22:20.000000000 -0800
9+++ git/libpthread/nptl/pthread_mutex_timedlock.c 2013-01-21 16:24:12.275557670 -0800
10@@ -28,7 +28,9 @@
11 * error: can't find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
12 */
13 int
14+#ifndef __OPTIMIZE__
15 attribute_optimize("Os")
16+#endif
17 pthread_mutex_timedlock (
18 pthread_mutex_t *mutex,
19 const struct timespec *abstime)
20Index: git/libc/sysdeps/linux/powerpc/bits/mathinline.h
21===================================================================
22--- git.orig/libc/sysdeps/linux/powerpc/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
23+++ git/libc/sysdeps/linux/powerpc/bits/mathinline.h 2013-01-21 16:24:12.275557670 -0800
24@@ -26,7 +26,7 @@
25 #ifdef __cplusplus
26 # define __MATH_INLINE __inline
27 #else
28-# define __MATH_INLINE extern __inline
29+# define __MATH_INLINE __extern_inline
30 #endif /* __cplusplus */
31
32 #if defined __GNUC__ && !defined _SOFT_FLOAT
33Index: git/libc/sysdeps/linux/alpha/bits/mathinline.h
34===================================================================
35--- git.orig/libc/sysdeps/linux/alpha/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
36+++ git/libc/sysdeps/linux/alpha/bits/mathinline.h 2013-01-21 16:24:12.275557670 -0800
37@@ -24,7 +24,7 @@
38 #ifdef __cplusplus
39 # define __MATH_INLINE __inline
40 #else
41-# define __MATH_INLINE extern __inline
42+# define __MATH_INLINE __extern_inline
43 #endif
44
45 #if defined __USE_ISOC99 && defined __GNUC__ && !__GNUC_PREREQ(3,0)
46Index: git/libc/sysdeps/linux/i386/bits/mathinline.h
47===================================================================
48--- git.orig/libc/sysdeps/linux/i386/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
49+++ git/libc/sysdeps/linux/i386/bits/mathinline.h 2013-01-21 16:24:12.275557670 -0800
50@@ -25,7 +25,7 @@
51 #ifdef __cplusplus
52 # define __MATH_INLINE __inline
53 #else
54-# define __MATH_INLINE extern __inline
55+# define __MATH_INLINE __extern_inline
56 #endif
57
58
59Index: git/libc/sysdeps/linux/ia64/bits/mathinline.h
60===================================================================
61--- git.orig/libc/sysdeps/linux/ia64/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
62+++ git/libc/sysdeps/linux/ia64/bits/mathinline.h 2013-01-21 16:24:12.275557670 -0800
63@@ -23,7 +23,7 @@
64 #ifdef __cplusplus
65 # define __MATH_INLINE __inline
66 #else
67-# define __MATH_INLINE extern __inline
68+# define __MATH_INLINE __extern_inline
69 #endif
70
71 #if defined __USE_ISOC99 && defined __GNUC__ && __GNUC__ >= 2
72Index: git/libc/sysdeps/linux/m68k/bits/mathinline.h
73===================================================================
74--- git.orig/libc/sysdeps/linux/m68k/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
75+++ git/libc/sysdeps/linux/m68k/bits/mathinline.h 2013-01-21 16:24:12.275557670 -0800
76@@ -91,7 +91,7 @@
77 # ifdef __cplusplus
78 # define __m81_inline __inline
79 # else
80-# define __m81_inline extern __inline
81+# define __m81_inline __extern_inline
82 # endif
83 # define __M81_MATH_INLINES 1
84 #endif
85@@ -350,14 +350,14 @@
86 /* Note that there must be no whitespace before the argument passed for
87 NAME, to make token pasting work correctly with -traditional. */
88 # define __inline_forward_c(rettype, name, args1, args2) \
89-extern __inline rettype __attribute__((__const__)) \
90+__extern_inline rettype __attribute__((__const__)) \
91 name args1 \
92 { \
93 return __CONCAT(__,name) args2; \
94 }
95
96 # define __inline_forward(rettype, name, args1, args2) \
97-extern __inline rettype name args1 \
98+__extern_inline rettype name args1 \
99 { \
100 return __CONCAT(__,name) args2; \
101 }
102Index: git/libc/sysdeps/linux/mips/sys/tas.h
103===================================================================
104--- git.orig/libc/sysdeps/linux/mips/sys/tas.h 2013-01-21 16:22:20.000000000 -0800
105+++ git/libc/sysdeps/linux/mips/sys/tas.h 2013-01-21 16:24:12.275557670 -0800
106@@ -29,7 +29,7 @@
107 #ifdef __USE_EXTERN_INLINES
108
109 # ifndef _EXTERN_INLINE
110-# define _EXTERN_INLINE extern __inline
111+# define _EXTERN_INLINE __extern_inline
112 # endif
113
114 _EXTERN_INLINE int
115Index: git/libc/sysdeps/linux/sparc/bits/mathinline.h
116===================================================================
117--- git.orig/libc/sysdeps/linux/sparc/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
118+++ git/libc/sysdeps/linux/sparc/bits/mathinline.h 2013-01-21 16:24:12.279557671 -0800
119@@ -130,7 +130,7 @@
120 # ifdef __cplusplus
121 # define __MATH_INLINE __inline
122 # else
123-# define __MATH_INLINE extern __inline
124+# define __MATH_INLINE __extern_inline
125 # endif /* __cplusplus */
126
127 /* The gcc, version 2.7 or below, has problems with all this inlining
128Index: git/libc/sysdeps/linux/x86_64/bits/mathinline.h
129===================================================================
130--- git.orig/libc/sysdeps/linux/x86_64/bits/mathinline.h 2013-01-21 16:22:20.000000000 -0800
131+++ git/libc/sysdeps/linux/x86_64/bits/mathinline.h 2013-01-21 16:24:12.279557671 -0800
132@@ -24,7 +24,7 @@
133 #ifdef __cplusplus
134 # define __MATH_INLINE __inline
135 #else
136-# define __MATH_INLINE extern __inline
137+# define __MATH_INLINE __extern_inline
138 #endif
139
140
diff --git a/meta/recipes-core/uclibc/uclibc-git/uClibc.distro b/meta/recipes-core/uclibc/uclibc-git/uClibc.distro
new file mode 100644
index 0000000000..c309e6f79a
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/uClibc.distro
@@ -0,0 +1,192 @@
1#
2# General Library Settings
3#
4# HAVE_NO_PIC is not set
5# DOPIC is not set
6# HAVE_NO_SHARED is not set
7# ARCH_HAS_NO_LDSO is not set
8HAVE_SHARED=y
9# FORCE_SHAREABLE_TEXT_SEGMENTS is not set
10LDSO_LDD_SUPPORT=y
11LDSO_CACHE_SUPPORT=y
12# LDSO_PRELOAD_FILE_SUPPORT is not set
13LDSO_BASE_FILENAME="ld.so"
14# UCLIBC_STATIC_LDCONFIG is not set
15LDSO_RUNPATH=y
16UCLIBC_CTOR_DTOR=y
17LDSO_GNU_HASH_SUPPORT=y
18# HAS_NO_THREADS is not set
19UCLIBC_HAS_THREADS=y
20UCLIBC_HAS_THREADS_NATIVE=y
21PTHREADS_DEBUG_SUPPORT=y
22# LINUXTHREADS_OLD is not set
23UCLIBC_HAS_LFS=y
24# MALLOC is not set
25# MALLOC_SIMPLE is not set
26MALLOC_STANDARD=y
27MALLOC_GLIBC_COMPAT=y
28UCLIBC_DYNAMIC_ATEXIT=y
29COMPAT_ATEXIT=y
30UCLIBC_SUSV3_LEGACY=y
31UCLIBC_SUSV3_LEGACY_MACROS=y
32UCLIBC_SUSV4_LEGACY=y
33UCLIBC_HAS_SHADOW=y
34UCLIBC_HAS_PROGRAM_INVOCATION_NAME=y
35UCLIBC_HAS___PROGNAME=y
36UNIX98PTY_ONLY=y
37ASSUME_DEVPTS=y
38UCLIBC_HAS_LIBUTIL=y
39UCLIBC_HAS_TM_EXTENSIONS=y
40UCLIBC_HAS_TZ_CACHING=y
41UCLIBC_HAS_TZ_FILE=y
42UCLIBC_HAS_TZ_FILE_READ_MANY=y
43UCLIBC_TZ_FILE_PATH="/etc/TZ"
44
45#
46# Advanced Library Settings
47#
48UCLIBC_PWD_BUFFER_SIZE=256
49UCLIBC_GRP_BUFFER_SIZE=256
50
51#
52# Networking Support
53#
54UCLIBC_HAS_IPV6=y
55UCLIBC_HAS_RPC=y
56UCLIBC_HAS_FULL_RPC=y
57UCLIBC_HAS_REENTRANT_RPC=y
58UCLIBC_USE_NETLINK=y
59UCLIBC_SUPPORT_AI_ADDRCONFIG=y
60
61UCLIBC_HAS_BSD_RES_CLOSE=y
62UCLIBC_HAS_LIBRESOLV_STUB=y
63UCLIBC_HAS_LIBNSL_STUB=y
64
65#
66# String and Stdio Support
67#
68UCLIBC_HAS_STRING_GENERIC_OPT=y
69UCLIBC_HAS_STRING_ARCH_OPT=y
70UCLIBC_HAS_CTYPE_TABLES=y
71UCLIBC_HAS_CTYPE_SIGNED=y
72# UCLIBC_HAS_CTYPE_UNSAFE is not set
73UCLIBC_HAS_CTYPE_CHECKED=y
74# UCLIBC_HAS_CTYPE_ENFORCED is not set
75UCLIBC_HAS_WCHAR=y
76# UCLIBC_HAS_LOCALE is not set
77UCLIBC_HAS_HEXADECIMAL_FLOATS=y
78UCLIBC_HAS_GLIBC_CUSTOM_PRINTF=y
79UCLIBC_PRINTF_SCANF_POSITIONAL_ARGS=9
80UCLIBC_HAS_SCANF_GLIBC_A_FLAG=y
81# UCLIBC_HAS_STDIO_BUFSIZ_NONE is not set
82UCLIBC_HAS_STDIO_BUFSIZ_256=y
83# UCLIBC_HAS_STDIO_BUFSIZ_512 is not set
84# UCLIBC_HAS_STDIO_BUFSIZ_1024 is not set
85# UCLIBC_HAS_STDIO_BUFSIZ_2048 is not set
86# UCLIBC_HAS_STDIO_BUFSIZ_4096 is not set
87# UCLIBC_HAS_STDIO_BUFSIZ_8192 is not set
88UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE=y
89# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4 is not set
90# UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8 is not set
91# UCLIBC_HAS_STDIO_SHUTDOWN_ON_ABORT is not set
92UCLIBC_HAS_STDIO_GETC_MACRO=y
93UCLIBC_HAS_STDIO_PUTC_MACRO=y
94UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION=y
95# UCLIBC_HAS_FOPEN_LARGEFILE_MODE is not set
96UCLIBC_HAS_FOPEN_EXCLUSIVE_MODE=y
97UCLIBC_HAS_GLIBC_CUSTOM_STREAMS=y
98UCLIBC_HAS_PRINTF_M_SPEC=y
99UCLIBC_HAS_ERRNO_MESSAGES=y
100# UCLIBC_HAS_SYS_ERRLIST is not set
101UCLIBC_HAS_SIGNUM_MESSAGES=y
102# UCLIBC_HAS_SYS_SIGLIST is not set
103UCLIBC_HAS_GNU_GETOPT=y
104UCLIBC_HAS_GNU_GETSUBOPT=y
105
106#
107# Big and Tall
108#
109UCLIBC_HAS_REGEX=y
110# UCLIBC_HAS_REGEX_OLD is not set
111UCLIBC_HAS_FNMATCH=y
112# UCLIBC_HAS_FNMATCH_OLD is not set
113UCLIBC_HAS_WORDEXP=y
114UCLIBC_HAS_NFTW=y
115UCLIBC_HAS_FTW=y
116UCLIBC_HAS_FTS=y
117UCLIBC_HAS_GLOB=y
118UCLIBC_HAS_GNU_GLOB=y
119
120#
121# Library Installation Options
122#
123SHARED_LIB_LOADER_PREFIX="/lib"
124RUNTIME_PREFIX="/"
125DEVEL_PREFIX="//usr"
126
127#
128# Security options
129#
130# UCLIBC_BUILD_PIE is not set
131# UCLIBC_HAS_ARC4RANDOM is not set
132# HAVE_NO_SSP is not set
133# UCLIBC_HAS_SSP is not set
134UCLIBC_BUILD_RELRO=y
135UCLIBC_BUILD_NOW=y
136UCLIBC_BUILD_NOEXECSTACK=y
137
138#
139# uClibc development/debugging options
140#
141CROSS_COMPILER_PREFIX=""
142UCLIBC_EXTRA_CFLAGS=""
143# DODEBUG is not set
144# DODEBUG_PT is not set
145# DOSTRIP is not set
146# DOASSERTS is not set
147# SUPPORT_LD_DEBUG is not set
148# SUPPORT_LD_DEBUG_EARLY is not set
149# UCLIBC_MALLOC_DEBUGGING is not set
150UCLIBC_HAS_BACKTRACE=y
151WARNINGS="-Wall"
152# EXTRA_WARNINGS is not set
153# DOMULTI is not set
154# UCLIBC_MJN3_ONLY is not set
155
156# math stuff for perl
157DO_C99_MATH=y
158UCLIBC_HAS_LONG_DOUBLE_MATH=y
159UCLIBC_HAS_FENV=y
160UCLIBC_LINUX_MODULE_26=y
161# UCLIBC_LINUX_MODULE_24 is not set
162UCLIBC_LINUX_SPECIFIC=y
163UCLIBC_HAS_REALTIME=y
164UCLIBC_HAS_ADVANCED_REALTIME=y
165UCLIBC_HAS_NETWORK_SUPPORT=y
166UCLIBC_HAS_SOCKET=y
167UCLIBC_HAS_BSD_ERR=y
168UCLIBC_HAS_SYSLOG=y
169UCLIBC_HAS_CRYPT=y
170UCLIBC_HAS_CRYPT_IMPL=y
171UCLIBC_HAS_GNU_ERROR=y
172UCLIBC_HAS_PTY=y
173UCLIBC_BSD_SPECIFIC=y
174UCLIBC_HAS_EPOLL=y
175UCLIBC_HAS_FLOATS=y
176
177# The below option is needed for ARM since depending
178# upong what intruction set is chosen this will be
179# enabled. As such it is harmless and will be punted
180# by menuconfig for other arches.
181
182# COMPILE_IN_THUMB_MODE is not set
183
184# needed by systemd
185UCLIBC_HAS_UTMPX=y
186UCLIBC_LINUX_MODULE_26=y
187UCLIBC_HAS_RESOLVER_SUPPORT=y
188# needed for LTP
189UCLIBC_SUSV4_LEGACY=y
190UCLIBC_HAS_OBSOLETE_BSD_SIGNAL=y
191DO_XSI_MATH=y
192UCLIBC_SV4_DEPRECATED=y
diff --git a/meta/recipes-core/uclibc/uclibc-git/uClibc.machine b/meta/recipes-core/uclibc/uclibc-git/uClibc.machine
new file mode 100644
index 0000000000..595f444dac
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/uClibc.machine
@@ -0,0 +1,14 @@
1#
2# Automatically generated make config: don't edit
3# Version: 0.9.32-git
4# Mon Jul 19 01:34:29 2010
5#
6#
7# Using ELF file format
8#
9FORCE_OPTIONS_FOR_ARCH=y
10ARCH_HAS_MMU=y
11ARCH_USE_MMU=y
12KERNEL_HEADERS="/usr/include"
13HAVE_DOT_CONFIG=y
14
diff --git a/meta/recipes-core/uclibc/uclibc-git/uclibc_enable_log2_test.patch b/meta/recipes-core/uclibc/uclibc-git/uclibc_enable_log2_test.patch
new file mode 100644
index 0000000000..37a59884b8
--- /dev/null
+++ b/meta/recipes-core/uclibc/uclibc-git/uclibc_enable_log2_test.patch
@@ -0,0 +1,35 @@
1uclibc now has log2 so enable the tests
2
3Signed-off-by: Khem Raj <raj.khem@gmail.com>
4Upstream-Status: Pending
5
6Index: uClibc/test/math/libm-test.inc
7===================================================================
8--- uClibc/test/math/libm-test.inc (revision 23784)
9+++ uClibc/test/math/libm-test.inc (working copy)
10@@ -3414,7 +3414,6 @@
11 }
12
13
14-#if 0
15 static void
16 log2_test (void)
17 {
18@@ -3444,7 +3443,6 @@
19
20 END (log2);
21 }
22-#endif
23
24
25 static void
26@@ -4967,9 +4965,7 @@
27 log_test ();
28 log10_test ();
29 log1p_test ();
30-#if 0
31 log2_test ();
32-#endif
33 logb_test ();
34 modf_test ();
35 ilogb_test ();