aboutsummaryrefslogtreecommitdiff
path: root/src/util/getopt.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-09-28 09:22:57 +0000
committerChristian Grothoff <christian@grothoff.org>2012-09-28 09:22:57 +0000
commita36bf48b6976f86398669a71e72fe078737410bc (patch)
tree4cb232747583770154aa9a776223af6217e43282 /src/util/getopt.c
parent601e24eca9012c462021ccacb04c70dffdb31264 (diff)
downloadgnunet-a36bf48b6976f86398669a71e72fe078737410bc.tar.gz
gnunet-a36bf48b6976f86398669a71e72fe078737410bc.zip
-DCE: _LIBC never defined
Diffstat (limited to 'src/util/getopt.c')
-rw-r--r--src/util/getopt.c99
1 files changed, 0 insertions, 99 deletions
diff --git a/src/util/getopt.c b/src/util/getopt.c
index 572e534c5..c37272442 100644
--- a/src/util/getopt.c
+++ b/src/util/getopt.c
@@ -238,45 +238,7 @@ strlen (const char *);
238static int first_nonopt; 238static int first_nonopt;
239static int last_nonopt; 239static int last_nonopt;
240 240
241#ifdef _LIBC
242/* Bash 2.0 gives us an environment variable containing flags
243 indicating ARGV elements that should not be considered arguments. */
244
245/* Defined in getopt_init.c */
246extern char *__getopt_nonoption_flags;
247
248static int nonoption_flags_max_len;
249static int nonoption_flags_len;
250
251static int original_argc;
252static char *const *original_argv;
253
254extern pid_t __libc_pid;
255
256/* Make sure the environment variable bash 2.0 puts in the environment
257 is valid for the getopt call we must make sure that the ARGV passed
258 to getopt is that one passed to the process. */
259static void GNUNET_UNUSED
260store_args_and_env (int argc, char *const *argv)
261{
262 /* XXX This is no good solution. We should rather copy the args so
263 * that we can compare them later. But we must not use malloc(3). */
264 original_argc = argc;
265 original_argv = argv;
266}
267
268text_set_element (__libc_subinit, store_args_and_env);
269
270#define SWAP_FLAGS(ch1, ch2) \
271 if (nonoption_flags_len > 0) \
272 { \
273 char __tmp = __getopt_nonoption_flags[ch1]; \
274 __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \
275 __getopt_nonoption_flags[ch2] = __tmp; \
276 }
277#else /* !_LIBC */
278#define SWAP_FLAGS(ch1, ch2) 241#define SWAP_FLAGS(ch1, ch2)
279#endif /* _LIBC */
280 242
281/* Exchange two adjacent subsequences of ARGV. 243/* Exchange two adjacent subsequences of ARGV.
282 One subsequence is elements [first_nonopt,last_nonopt) 244 One subsequence is elements [first_nonopt,last_nonopt)
@@ -305,29 +267,6 @@ exchange (char **argv)
305 * It leaves the longer segment in the right place overall, 267 * It leaves the longer segment in the right place overall,
306 * but it consists of two parts that need to be swapped next. */ 268 * but it consists of two parts that need to be swapped next. */
307 269
308#ifdef _LIBC
309 /* First make sure the handling of the `__getopt_nonoption_flags'
310 * string can work normally. Our top argument must be in the range
311 * of the string. */
312 if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len)
313 {
314 /* We must extend the array. The user plays games with us and
315 * presents new arguments. */
316 char *new_str = malloc (top + 1);
317
318 if (new_str == NULL)
319 nonoption_flags_len = nonoption_flags_max_len = 0;
320 else
321 {
322 memcpy (new_str, __getopt_nonoption_flags, nonoption_flags_max_len);
323 memset (&new_str[nonoption_flags_max_len], '\0',
324 top + 1 - nonoption_flags_max_len);
325 nonoption_flags_max_len = top + 1;
326 __getopt_nonoption_flags = new_str;
327 }
328 }
329#endif
330
331 while (top > middle && middle > bottom) 270 while (top > middle && middle > bottom)
332 { 271 {
333 if (top - middle > middle - bottom) 272 if (top - middle > middle - bottom)
@@ -410,38 +349,6 @@ _getopt_initialize (int argc,
410 else 349 else
411 ordering = PERMUTE; 350 ordering = PERMUTE;
412 351
413#ifdef _LIBC
414 if (posixly_correct == NULL && argc == original_argc && argv == original_argv)
415 {
416 if (nonoption_flags_max_len == 0)
417 {
418 if (__getopt_nonoption_flags == NULL ||
419 __getopt_nonoption_flags[0] == '\0')
420 nonoption_flags_max_len = -1;
421 else
422 {
423 const char *orig_str = __getopt_nonoption_flags;
424 int len = nonoption_flags_max_len = strlen (orig_str);
425
426 if (nonoption_flags_max_len < argc)
427 nonoption_flags_max_len = argc;
428 __getopt_nonoption_flags = (char *) malloc (nonoption_flags_max_len);
429 if (__getopt_nonoption_flags == NULL)
430 nonoption_flags_max_len = -1;
431 else
432 {
433 memcpy (__getopt_nonoption_flags, orig_str, len);
434 memset (&__getopt_nonoption_flags[len], '\0',
435 nonoption_flags_max_len - len);
436 }
437 }
438 }
439 nonoption_flags_len = nonoption_flags_max_len;
440 }
441 else
442 nonoption_flags_len = 0;
443#endif
444
445 return optstring; 352 return optstring;
446} 353}
447 354
@@ -523,13 +430,7 @@ GN_getopt_internal (int argc, char *const *argv, const char *optstring,
523 * Either it does not have option syntax, or there is an environment flag 430 * Either it does not have option syntax, or there is an environment flag
524 * from the shell indicating it is not an option. The later information 431 * from the shell indicating it is not an option. The later information
525 * is only used when the used in the GNU libc. */ 432 * is only used when the used in the GNU libc. */
526#ifdef _LIBC
527#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0' \
528 || (GNoptind < nonoption_flags_len \
529 && __getopt_nonoption_flags[GNoptind] == '1'))
530#else
531#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0') 433#define NONOPTION_P (argv[GNoptind][0] != '-' || argv[GNoptind][1] == '\0')
532#endif
533 434
534 if (nextchar == NULL || *nextchar == '\0') 435 if (nextchar == NULL || *nextchar == '\0')
535 { 436 {