diff options
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | lib/basename.c | 79 | ||||
-rw-r--r-- | lib/dirname.h | 47 | ||||
-rw-r--r-- | m4/basename.m4 | 14 | ||||
-rw-r--r-- | m4/dos.m4 | 58 | ||||
-rw-r--r-- | m4/np_coreutils.m4 | 1 | ||||
-rw-r--r-- | plugins/check_procs.c | 2 | ||||
-rw-r--r-- | plugins/utils.c | 27 | ||||
-rw-r--r-- | plugins/utils.h | 3 |
9 files changed, 201 insertions, 32 deletions
diff --git a/configure.in b/configure.in index 27b2b40..54d5700 100644 --- a/configure.in +++ b/configure.in | |||
@@ -602,7 +602,7 @@ AC_TRY_COMPILE([#include <sys/time.h>], | |||
602 | 602 | ||
603 | dnl Checks for library functions. | 603 | dnl Checks for library functions. |
604 | AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul floor) | 604 | AC_CHECK_FUNCS(memmove select socket strdup strstr strtod strtol strtoul floor) |
605 | AC_CHECK_FUNCS(basename poll) | 605 | AC_CHECK_FUNCS(poll) |
606 | 606 | ||
607 | AC_MSG_CHECKING(return type of socket size) | 607 | AC_MSG_CHECKING(return type of socket size) |
608 | AC_TRY_COMPILE([#include <stdlib.h> | 608 | AC_TRY_COMPILE([#include <stdlib.h> |
diff --git a/lib/basename.c b/lib/basename.c new file mode 100644 index 0000000..5cc97cd --- /dev/null +++ b/lib/basename.c | |||
@@ -0,0 +1,79 @@ | |||
1 | /* basename.c -- return the last element in a file name | ||
2 | |||
3 | Copyright (C) 1990, 1998, 1999, 2000, 2001, 2003, 2004, 2005 Free | ||
4 | Software Foundation, Inc. | ||
5 | |||
6 | This program is free software; you can redistribute it and/or modify | ||
7 | it under the terms of the GNU General Public License as published by | ||
8 | the Free Software Foundation; either version 2, or (at your option) | ||
9 | any later version. | ||
10 | |||
11 | This program is distributed in the hope that it will be useful, | ||
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | GNU General Public License for more details. | ||
15 | |||
16 | You should have received a copy of the GNU General Public License | ||
17 | along with this program; if not, write to the Free Software Foundation, | ||
18 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
19 | |||
20 | #ifdef HAVE_CONFIG_H | ||
21 | # include <config.h> | ||
22 | #endif | ||
23 | |||
24 | #include "dirname.h" | ||
25 | #include <string.h> | ||
26 | |||
27 | /* In general, we can't use the builtin `basename' function if available, | ||
28 | since it has different meanings in different environments. | ||
29 | In some environments the builtin `basename' modifies its argument. | ||
30 | |||
31 | Return the address of the last file name component of NAME. If | ||
32 | NAME has no file name components because it is all slashes, return | ||
33 | NAME if it is empty, the address of its last slash otherwise. */ | ||
34 | |||
35 | char * | ||
36 | base_name (char const *name) | ||
37 | { | ||
38 | char const *base = name + FILE_SYSTEM_PREFIX_LEN (name); | ||
39 | char const *p; | ||
40 | |||
41 | for (p = base; *p; p++) | ||
42 | { | ||
43 | if (ISSLASH (*p)) | ||
44 | { | ||
45 | /* Treat multiple adjacent slashes like a single slash. */ | ||
46 | do p++; | ||
47 | while (ISSLASH (*p)); | ||
48 | |||
49 | /* If the file name ends in slash, use the trailing slash as | ||
50 | the basename if no non-slashes have been found. */ | ||
51 | if (! *p) | ||
52 | { | ||
53 | if (ISSLASH (*base)) | ||
54 | base = p - 1; | ||
55 | break; | ||
56 | } | ||
57 | |||
58 | /* *P is a non-slash preceded by a slash. */ | ||
59 | base = p; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | return (char *) base; | ||
64 | } | ||
65 | |||
66 | /* Return the length of of the basename NAME. Typically NAME is the | ||
67 | value returned by base_name. Act like strlen (NAME), except omit | ||
68 | redundant trailing slashes. */ | ||
69 | |||
70 | size_t | ||
71 | base_len (char const *name) | ||
72 | { | ||
73 | size_t len; | ||
74 | |||
75 | for (len = strlen (name); 1 < len && ISSLASH (name[len - 1]); len--) | ||
76 | continue; | ||
77 | |||
78 | return len; | ||
79 | } | ||
diff --git a/lib/dirname.h b/lib/dirname.h new file mode 100644 index 0000000..1688ae8 --- /dev/null +++ b/lib/dirname.h | |||
@@ -0,0 +1,47 @@ | |||
1 | /* Take file names apart into directory and base names. | ||
2 | |||
3 | Copyright (C) 1998, 2001, 2003, 2004, 2005 Free Software Foundation, Inc. | ||
4 | |||
5 | This program is free software; you can redistribute it and/or modify | ||
6 | it under the terms of the GNU General Public License as published by | ||
7 | the Free Software Foundation; either version 2, or (at your option) | ||
8 | any later version. | ||
9 | |||
10 | This program is distributed in the hope that it will be useful, | ||
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | GNU General Public License for more details. | ||
14 | |||
15 | You should have received a copy of the GNU General Public License | ||
16 | along with this program; if not, write to the Free Software Foundation, | ||
17 | Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ | ||
18 | |||
19 | #ifndef DIRNAME_H_ | ||
20 | # define DIRNAME_H_ 1 | ||
21 | |||
22 | # include <stdbool.h> | ||
23 | # include <stddef.h> | ||
24 | |||
25 | # ifndef DIRECTORY_SEPARATOR | ||
26 | # define DIRECTORY_SEPARATOR '/' | ||
27 | # endif | ||
28 | |||
29 | # ifndef ISSLASH | ||
30 | # define ISSLASH(C) ((C) == DIRECTORY_SEPARATOR) | ||
31 | # endif | ||
32 | |||
33 | # ifndef FILE_SYSTEM_PREFIX_LEN | ||
34 | # define FILE_SYSTEM_PREFIX_LEN(File_name) 0 | ||
35 | # endif | ||
36 | |||
37 | # define IS_ABSOLUTE_FILE_NAME(F) ISSLASH ((F)[FILE_SYSTEM_PREFIX_LEN (F)]) | ||
38 | # define IS_RELATIVE_FILE_NAME(F) (! IS_ABSOLUTE_FILE_NAME (F)) | ||
39 | |||
40 | char *base_name (char const *file); | ||
41 | char *dir_name (char const *file); | ||
42 | size_t base_len (char const *file); | ||
43 | size_t dir_len (char const *file); | ||
44 | |||
45 | bool strip_trailing_slashes (char *file); | ||
46 | |||
47 | #endif /* not DIRNAME_H_ */ | ||
diff --git a/m4/basename.m4 b/m4/basename.m4 new file mode 100644 index 0000000..69a0996 --- /dev/null +++ b/m4/basename.m4 | |||
@@ -0,0 +1,14 @@ | |||
1 | # basename.m4 serial 1 | ||
2 | dnl Copyright (C) 2005 Free Software Foundation, Inc. | ||
3 | dnl This file is free software; the Free Software Foundation | ||
4 | dnl gives unlimited permission to copy and/or distribute it, | ||
5 | dnl with or without modifications, as long as this notice is preserved. | ||
6 | |||
7 | AC_DEFUN([gl_BASENAME], | ||
8 | [ | ||
9 | AC_LIBSOURCES([basename.c, dirname.h]) | ||
10 | AC_LIBOBJ([basename]) | ||
11 | |||
12 | dnl Prerequisites of lib/basename.c. | ||
13 | AC_REQUIRE([gl_AC_DOS]) | ||
14 | ]) | ||
diff --git a/m4/dos.m4 b/m4/dos.m4 new file mode 100644 index 0000000..0713cf1 --- /dev/null +++ b/m4/dos.m4 | |||
@@ -0,0 +1,58 @@ | |||
1 | #serial 9 | ||
2 | |||
3 | # Define some macros required for proper operation of code in lib/*.c | ||
4 | # on MSDOS/Windows systems. | ||
5 | |||
6 | # Copyright (C) 2000, 2001, 2004 Free Software Foundation, Inc. | ||
7 | # This file is free software; the Free Software Foundation | ||
8 | # gives unlimited permission to copy and/or distribute it, | ||
9 | # with or without modifications, as long as this notice is preserved. | ||
10 | |||
11 | # From Jim Meyering. | ||
12 | |||
13 | AC_DEFUN([gl_AC_DOS], | ||
14 | [ | ||
15 | AC_CACHE_CHECK([whether system is Windows or MSDOS], [ac_cv_win_or_dos], | ||
16 | [ | ||
17 | AC_TRY_COMPILE([], | ||
18 | [#if !defined _WIN32 && !defined __WIN32__ && !defined __MSDOS__ && !defined __CYGWIN__ | ||
19 | neither MSDOS nor Windows | ||
20 | #endif], | ||
21 | [ac_cv_win_or_dos=yes], | ||
22 | [ac_cv_win_or_dos=no]) | ||
23 | ]) | ||
24 | |||
25 | if test x"$ac_cv_win_or_dos" = xyes; then | ||
26 | ac_fs_accepts_drive_letter_prefix=1 | ||
27 | ac_fs_backslash_is_file_name_separator=1 | ||
28 | else | ||
29 | ac_fs_accepts_drive_letter_prefix=0 | ||
30 | ac_fs_backslash_is_file_name_separator=0 | ||
31 | fi | ||
32 | |||
33 | AH_VERBATIM(FILE_SYSTEM_PREFIX_LEN, | ||
34 | [#if FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX | ||
35 | # define FILE_SYSTEM_PREFIX_LEN(Filename) \ | ||
36 | ((Filename)[0] && (Filename)[1] == ':' ? 2 : 0) | ||
37 | #else | ||
38 | # define FILE_SYSTEM_PREFIX_LEN(Filename) 0 | ||
39 | #endif]) | ||
40 | |||
41 | AC_DEFINE_UNQUOTED([FILE_SYSTEM_ACCEPTS_DRIVE_LETTER_PREFIX], | ||
42 | $ac_fs_accepts_drive_letter_prefix, | ||
43 | [Define on systems for which file names may have a so-called | ||
44 | `drive letter' prefix, define this to compute the length of that | ||
45 | prefix, including the colon.]) | ||
46 | |||
47 | AH_VERBATIM(ISSLASH, | ||
48 | [#if FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR | ||
49 | # define ISSLASH(C) ((C) == '/' || (C) == '\\') | ||
50 | #else | ||
51 | # define ISSLASH(C) ((C) == '/') | ||
52 | #endif]) | ||
53 | |||
54 | AC_DEFINE_UNQUOTED([FILE_SYSTEM_BACKSLASH_IS_FILE_NAME_SEPARATOR], | ||
55 | $ac_fs_backslash_is_file_name_separator, | ||
56 | [Define if the backslash character may also serve as a file name | ||
57 | component separator.]) | ||
58 | ]) | ||
diff --git a/m4/np_coreutils.m4 b/m4/np_coreutils.m4 index 5360bbd..77cb9f6 100644 --- a/m4/np_coreutils.m4 +++ b/m4/np_coreutils.m4 | |||
@@ -11,6 +11,7 @@ dnl Usually in coreutils' prereq.m4, but this is a subset that we need | |||
11 | AC_DEFUN([np_COREUTILS], | 11 | AC_DEFUN([np_COREUTILS], |
12 | [ | 12 | [ |
13 | AC_REQUIRE([AM_STDBOOL_H]) | 13 | AC_REQUIRE([AM_STDBOOL_H]) |
14 | AC_REQUIRE([gl_BASENAME]) | ||
14 | AC_REQUIRE([gl_C_STRTOLD]) | 15 | AC_REQUIRE([gl_C_STRTOLD]) |
15 | AC_REQUIRE([gl_EXITFAIL]) | 16 | AC_REQUIRE([gl_EXITFAIL]) |
16 | AC_REQUIRE([gl_FCNTL_SAFER]) | 17 | AC_REQUIRE([gl_FCNTL_SAFER]) |
diff --git a/plugins/check_procs.c b/plugins/check_procs.c index f6438f2..82a21eb 100644 --- a/plugins/check_procs.c +++ b/plugins/check_procs.c | |||
@@ -189,7 +189,7 @@ main (int argc, char **argv) | |||
189 | strip (procargs); | 189 | strip (procargs); |
190 | 190 | ||
191 | /* Some ps return full pathname for command. This removes path */ | 191 | /* Some ps return full pathname for command. This removes path */ |
192 | procprog = basename(procprog); | 192 | procprog = base_name(procprog); |
193 | 193 | ||
194 | /* we need to convert the elapsed time to seconds */ | 194 | /* we need to convert the elapsed time to seconds */ |
195 | procseconds = convert_to_seconds(procetime); | 195 | procseconds = convert_to_seconds(procetime); |
diff --git a/plugins/utils.c b/plugins/utils.c index a455f22..cb01341 100644 --- a/plugins/utils.c +++ b/plugins/utils.c | |||
@@ -640,33 +640,6 @@ strpcat (char *dest, const char *src, const char *str) | |||
640 | return dest; | 640 | return dest; |
641 | } | 641 | } |
642 | 642 | ||
643 | #ifndef HAVE_BASENAME | ||
644 | /* function modified from coreutils base_name function - see ACKNOWLEDGEMENTS */ | ||
645 | char *basename(const char *path) { | ||
646 | char const *base = path; | ||
647 | char const *p; | ||
648 | for (p = base; *p; p++) { | ||
649 | if (*p == '/') { | ||
650 | /* Treat multiple adjacent slashes like single slash */ | ||
651 | do p++; | ||
652 | while (*p == '/'); | ||
653 | |||
654 | /* If filename ends in slash, use trailing slash | ||
655 | as basename if no non-slashes found */ | ||
656 | if (! *p) { | ||
657 | if (*base == '/') | ||
658 | base = p - 1; | ||
659 | break; | ||
660 | } | ||
661 | |||
662 | /* *p is non-slash preceded by slash */ | ||
663 | base = p; | ||
664 | } | ||
665 | } | ||
666 | return (char *) base; | ||
667 | } | ||
668 | #endif | ||
669 | |||
670 | /****************************************************************************** | 643 | /****************************************************************************** |
671 | * | 644 | * |
672 | * Print perfdata in a standard format | 645 | * Print perfdata in a standard format |
diff --git a/plugins/utils.h b/plugins/utils.h index ed6243d..4bbe33d 100644 --- a/plugins/utils.h +++ b/plugins/utils.h | |||
@@ -80,9 +80,6 @@ void set_thresholds(thresholds **, char *, char *); | |||
80 | int check_range(double, range *); | 80 | int check_range(double, range *); |
81 | int get_status(double, thresholds *); | 81 | int get_status(double, thresholds *); |
82 | 82 | ||
83 | /* I think this needs to be defined even if you use the system version */ | ||
84 | char *basename(const char *path); | ||
85 | |||
86 | #ifndef HAVE_GETTIMEOFDAY | 83 | #ifndef HAVE_GETTIMEOFDAY |
87 | int gettimeofday(struct timeval *, struct timezone *); | 84 | int gettimeofday(struct timeval *, struct timezone *); |
88 | #endif | 85 | #endif |