aboutsummaryrefslogtreecommitdiff
path: root/plugins/utils.c
diff options
context:
space:
mode:
authorGravatar Ton Voon <tonvoon@users.sourceforge.net> 2006-04-27 13:25:10 +0000
committerGravatar Ton Voon <tonvoon@users.sourceforge.net> 2006-04-27 13:25:10 +0000
commit34cb16d283298885b73f75146433a703e93c0d4f (patch)
treec1e7b1b0ff0ad3e59e4921dd5e65d4527cd23d3f /plugins/utils.c
parent37ebbab7fbd251c4c357459ff738847f5a5a4883 (diff)
downloadmonitoring-plugins-34cb16d283298885b73f75146433a703e93c0d4f.tar.gz
Internal version of basename if one not found in system
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1383 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins/utils.c')
-rw-r--r--plugins/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/plugins/utils.c b/plugins/utils.c
index bb4ffbc2..f2593a16 100644
--- a/plugins/utils.c
+++ b/plugins/utils.c
@@ -5,6 +5,7 @@
* Library of useful functions for plugins
*
* Copyright (c) 2000 Karl DeBisschop (karl@debisschop.net)
+ * Copyright (c) 2006 Nagios Plugin Development Team
* License: GPL
*
* $Revision$
@@ -639,6 +640,32 @@ strpcat (char *dest, const char *src, const char *str)
return dest;
}
+#ifndef HAVE_BASENAME
+/* function modified from coreutils base_name function - see ACKNOWLEDGEMENTS */
+char *basename(const char *path) {
+ char const *base = path;
+ char const *p;
+ for (p = base; *p; p++) {
+ if (*p == '/') {
+ /* Treat multiple adjacent slashes like single slash */
+ do p++;
+ while (*p == '/');
+
+ /* If filename ends in slash, use trailing slash
+ as basename if no non-slashes found */
+ if (! *p) {
+ if (*base == '/')
+ base = p - 1;
+ break;
+ }
+
+ /* *p is non-slash preceded by slash */
+ base = p;
+ }
+ }
+ return (char *) base;
+}
+#endif
/******************************************************************************
*