From 23928d9923ca0c97c1ff6e07d56d3a5327db8e9e Mon Sep 17 00:00:00 2001 From: Anders Broman Date: Sun, 5 Feb 2012 13:25:36 +0000 Subject: [PATCH] From Alexander Koeppe: Eliminate Mixture of libc and glibc in editcap.c https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=6695 svn path=/trunk/; revision=40866 --- editcap.c | 281 +++++++++++++++++++++++++++--------------------------- 1 file changed, 140 insertions(+), 141 deletions(-) diff --git a/editcap.c b/editcap.c index d643ea45c6..0e64182cef 100644 --- a/editcap.c +++ b/editcap.c @@ -12,11 +12,6 @@ #include "config.h" #endif -#include -#include -#include -#include - /* * Just make sure we include the prototype for strptime as well * (needed for glibc 2.2) but make sure we do this only if not @@ -26,9 +21,13 @@ #ifndef __USE_XOPEN # define __USE_XOPEN #endif +#ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE +#endif #include #include +#include #ifdef HAVE_UNISTD_H #include @@ -196,7 +195,7 @@ fileset_extract_prefix_suffix(const char *fname, gchar **fprefix, gchar **fsuffi save_file = g_strdup(fname); if (save_file == NULL) { - fprintf(stderr, "editcap: Out of memory\n"); + g_fprintf(stderr, "editcap: Out of memory\n"); return FALSE; } @@ -236,32 +235,32 @@ add_selection(char *sel) if (++max_selected >= MAX_SELECTIONS) { /* Let the user know we stopped selecting */ - printf("Out of room for packet selections!\n"); + g_print("Out of room for packet selections!\n"); return(FALSE); } - printf("Add_Selected: %s\n", sel); + g_printf("Add_Selected: %s\n", sel); if ((locn = strchr(sel, '-')) == NULL) { /* No dash, so a single number? */ - printf("Not inclusive ..."); + g_print("Not inclusive ..."); selectfrm[max_selected].inclusive = 0; selectfrm[max_selected].first = atoi(sel); - printf(" %i\n", selectfrm[max_selected].first); + g_printf(" %i\n", selectfrm[max_selected].first); } else { - printf("Inclusive ..."); + g_print("Inclusive ..."); next = locn + 1; selectfrm[max_selected].inclusive = 1; selectfrm[max_selected].first = atoi(sel); selectfrm[max_selected].second = atoi(next); - printf(" %i, %i\n", selectfrm[max_selected].first, selectfrm[max_selected].second); + g_printf(" %i, %i\n", selectfrm[max_selected].first, selectfrm[max_selected].second); } @@ -328,12 +327,12 @@ set_time_adjustment(char *optarg_str_p) } else { val = strtol(optarg_str_p, &frac, 10); if (frac == NULL || frac == optarg_str_p || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } if (val < 0) { /* implies '--' since we caught '-' above */ - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } @@ -350,7 +349,7 @@ set_time_adjustment(char *optarg_str_p) } if (*frac != '.' || end == NULL || end == frac || val < 0 || val > ONE_MILLION || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } @@ -403,12 +402,12 @@ set_strict_time_adj(char *optarg_str_p) } else { val = strtol(optarg_str_p, &frac, 10); if (frac == NULL || frac == optarg_str_p || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } if (val < 0) { /* implies '--' since we caught '-' above */ - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } @@ -425,7 +424,7 @@ set_strict_time_adj(char *optarg_str_p) } if (*frac != '.' || end == NULL || end == frac || val < 0 || val > ONE_MILLION || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", + g_fprintf(stderr, "editcap: \"%s\" isn't a valid time adjustment\n", optarg_str_p); exit(1); } @@ -473,12 +472,12 @@ set_rel_time(char *optarg_str_p) } else { val = strtol(optarg_str_p, &frac, 10); if (frac == NULL || frac == optarg_str_p || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "1: editcap: \"%s\" isn't a valid rel time value\n", + g_fprintf(stderr, "1: editcap: \"%s\" isn't a valid rel time value\n", optarg_str_p); exit(1); } if (val < 0) { /* implies '--' since we caught '-' above */ - fprintf(stderr, "2: editcap: \"%s\" isn't a valid rel time value\n", + g_fprintf(stderr, "2: editcap: \"%s\" isn't a valid rel time value\n", optarg_str_p); exit(1); } @@ -495,7 +494,7 @@ set_rel_time(char *optarg_str_p) } if (*frac != '.' || end == NULL || end == frac || val < 0 || val > ONE_BILLION || val == LONG_MIN || val == LONG_MAX) { - fprintf(stderr, "3: editcap: \"%s\" isn't a valid rel time value\n", + g_fprintf(stderr, "3: editcap: \"%s\" isn't a valid rel time value\n", optarg_str_p); exit(1); } @@ -667,75 +666,75 @@ usage(gboolean is_error) " (" SVNVERSION " from " SVNPATH ")" #endif "\n", VERSION); - fprintf(output, "Edit and/or translate the format of capture files.\n"); - fprintf(output, "See http://www.wireshark.org for more information.\n"); - fprintf(output, "\n"); - fprintf(output, "Usage: editcap [options] ... [ [-] ... ]\n"); - fprintf(output, "\n"); - fprintf(output, " and must both be present.\n"); - fprintf(output, "A single packet or a range of packets can be selected.\n"); - fprintf(output, "\n"); - fprintf(output, "Packet selection:\n"); - fprintf(output, " -r keep the selected packets; default is to delete them.\n"); - fprintf(output, " -A only output packets whose timestamp is after (or equal\n"); - fprintf(output, " to) the given time (format as YYYY-MM-DD hh:mm:ss).\n"); - fprintf(output, " -B only output packets whose timestamp is before the\n"); - fprintf(output, " given time (format as YYYY-MM-DD hh:mm:ss).\n"); - fprintf(output, "\n"); - fprintf(output, "Duplicate packet removal:\n"); - fprintf(output, " -d remove packet if duplicate (window == %d).\n", DEFAULT_DUP_DEPTH); - fprintf(output, " -D remove packet if duplicate; configurable \n"); - fprintf(output, " Valid values are 0 to %d.\n", MAX_DUP_DEPTH); - fprintf(output, " NOTE: A of 0 with -v (verbose option) is\n"); - fprintf(output, " useful to print MD5 hashes.\n"); - fprintf(output, " -w remove packet if duplicate packet is found EQUAL TO OR\n"); - fprintf(output, " LESS THAN prior to current packet.\n"); - fprintf(output, " A is specified in relative seconds\n"); - fprintf(output, " (e.g. 0.000001).\n"); - fprintf(output, "\n"); - fprintf(output, " NOTE: The use of the 'Duplicate packet removal' options with\n"); - fprintf(output, " other editcap options except -v may not always work as expected.\n"); - fprintf(output, " Specifically the -r, -t or -S options will very likely NOT have the\n"); - fprintf(output, " desired effect if combined with the -d, -D or -w.\n"); - fprintf(output, "\n"); - fprintf(output, "Packet manipulation:\n"); - fprintf(output, " -s truncate each packet to max. bytes of data.\n"); - fprintf(output, " -C chop each packet by bytes. Positive values\n"); - fprintf(output, " chop at the packet beginning, negative values at the\n"); - fprintf(output, " packet end.\n"); - fprintf(output, " -t