The utils.c is basically an internal general purpose function library.
display.c display.h \
report.c report.h \
select.c select.h \
+ utils.c utils.h \
mtr-curses.h \
img/mtr_icon.xpm \
mtr-gtk.h
#include "report.h"
#include "net.h"
#include "asn.h"
+#include "utils.h"
#ifdef HAVE_GETOPT
#include <getopt.h>
exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
}
-enum {
- STRTO_INT,
- STRTO_U32INT
-};
-
-/* Parse string, and return positive signed int. */
-static int
-strtonum_or_err (const char *str, const char *errmesg, const int type)
-{
- unsigned long int num;
- char *end = NULL;
-
- if (str != NULL && *str != '\0') {
- errno = 0;
- num = strtoul (str, &end, 10);
- if (errno == 0 && str != end && end != NULL && *end == '\0') {
- switch (type) {
- case STRTO_INT:
- if (num < INT_MAX)
- return num;
- break;
- case STRTO_U32INT:
- if (num < UINT32_MAX)
- return num;
- break;
- }
- }
- }
- error (EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
- return 0;
-}
-
-static float
-strtofloat_or_err (const char *str, const char *errmesg)
-{
- double num;
- char *end = NULL;
-
- if (str != NULL && *str != '\0') {
- errno = 0;
- num = strtod (str, &end);
- if (errno == 0 && str != end && end != NULL && *end == '\0'
-#ifdef FLT_MAX
- && num < FLT_MAX
-#endif
- )
- return num;
- }
- error (EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
- return 0;
-}
-
-
-extern char *
-trim(char * s) {
-
- char * p = s;
- int l = strlen(p);
-
- while(isspace(p[l-1]) && l) p[--l] = 0;
- while(*p && isspace(*p) && l) ++p, --l;
-
- return p;
-}
static void
append_to_names(const char* item) {
--- /dev/null
+/*
+ mtr -- a network diagnostic tool
+ Copyright (C) 1997,1998 Matt Kimball
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <ctype.h>
+#include <errno.h>
+#include <limits.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef HAVE_ERROR_H
+# include <error.h>
+#else
+# include "portability/error.h"
+#endif
+
+#include "utils.h"
+
+extern char *trim(char *s)
+{
+ char *p = s;
+ int l = strlen(p);
+
+ while (isspace(p[l - 1]) && l)
+ p[--l] = 0;
+ while (*p && isspace(*p) && l)
+ ++p, --l;
+
+ return p;
+}
+
+/* Parse string, and return positive signed int. */
+extern int strtonum_or_err(const char *str, const char *errmesg, const int type)
+{
+ unsigned long int num;
+ char *end = NULL;
+
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtoul(str, &end, 10);
+ if (errno == 0 && str != end && end != NULL && *end == '\0') {
+ switch (type) {
+ case STRTO_INT:
+ if (num < INT_MAX)
+ return num;
+ break;
+ case STRTO_U32INT:
+ if (num < UINT32_MAX)
+ return num;
+ break;
+ }
+ }
+ }
+ error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
+ return 0;
+}
+
+extern float strtofloat_or_err(const char *str, const char *errmesg)
+{
+ double num;
+ char *end = NULL;
+
+ if (str != NULL && *str != '\0') {
+ errno = 0;
+ num = strtod(str, &end);
+ if (errno == 0 && str != end && end != NULL && *end == '\0'
+#ifdef FLT_MAX
+ && num < FLT_MAX
+#endif
+ )
+ return num;
+ }
+ error(EXIT_FAILURE, errno, "%s: '%s'", errmesg, str);
+ return 0;
+}
--- /dev/null
+/*
+ mtr -- a network diagnostic tool
+ Copyright (C) 1997,1998 Matt Kimball
+ Copyright (C) 2005 R.E.Wolff@BitWizard.nl
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License version 2 as
+ published by the Free Software Foundation.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+enum {
+ STRTO_INT,
+ STRTO_U32INT
+};
+
+extern char *trim(char *s);
+extern int strtonum_or_err(const char *str, const char *errmesg, const int type);
+extern float strtofloat_or_err(const char *str, const char *errmesg);