diff options
Diffstat (limited to 'source3/lib')
-rw-r--r-- | source3/lib/interfaces.c | 3 | ||||
-rw-r--r-- | source3/lib/util.c | 28 |
2 files changed, 31 insertions, 0 deletions
diff --git a/source3/lib/interfaces.c b/source3/lib/interfaces.c index 29181c394a..e7b9efa1f0 100644 --- a/source3/lib/interfaces.c +++ b/source3/lib/interfaces.c @@ -39,6 +39,9 @@ #include <arpa/inet.h> #include <netdb.h> #include <sys/ioctl.h> +#ifdef HAVE_SYS_TIME_H +#include <sys/time.h> +#endif #include <net/if.h> #ifndef SIOCGIFCONF diff --git a/source3/lib/util.c b/source3/lib/util.c index a39dc1a516..001baa0e3e 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -3280,3 +3280,31 @@ char *lock_path(char *name) return fname; } + +/******************************************************************* + Given a filename - get its directory name + NB: Returned in static storage. Caveats: + o Not safe in thread environment. + o Caller must not free. + o If caller wishes to preserve, they should copy. +********************************************************************/ + +char *parent_dirname(const char *path) +{ + static pstring dirpath; + char *p; + + if (!path) + return(NULL); + + pstrcpy(dirpath, path); + p = strrchr(dirpath, '/'); /* Find final '/', if any */ + if (!p) { + pstrcpy(dirpath, "."); /* No final "/", so dir is "." */ + } else { + if (p == dirpath) + ++p; /* For root "/", leave "/" in place */ + *p = '\0'; + } + return dirpath; +} |