From 98c082489bec0a0ce4db1daf4390e785381f229a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 28 Dec 2006 21:50:31 +0000 Subject: r20394: This is a *VERY* early start of my work on notify. Checking in because Jeremy was bugging me. Potentially this becomes quite intrusive, I'm not sure if I should open a temporary branch for this. Jeremy, Jerry, do you think 3_0 is the right place for this? Volker (This used to be commit bcf5c751cbe203c00814642e26440cf88f300bce) --- source3/lib/util.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'source3/lib/util.c') diff --git a/source3/lib/util.c b/source3/lib/util.c index 9ac0b37612..5e2588e5b9 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -2620,6 +2620,37 @@ char *parent_dirname(const char *path) return dirpath; } +BOOL parent_dirname_talloc(TALLOC_CTX *mem_ctx, const char *dir, + char **parent, const char **name) +{ + char *p; + ptrdiff_t len; + + p = strrchr_m(dir, '/'); /* Find final '/', if any */ + + if (p == NULL) { + if (!(*parent = talloc_strdup(mem_ctx, "."))) { + return False; + } + if (name) { + *name = ""; + } + return True; + } + + len = p-dir; + + if (!(*parent = TALLOC_ARRAY(mem_ctx, char, len+1))) { + return False; + } + memcpy(*parent, dir, len); + (*parent)[len] = '\0'; + + if (name) { + *name = p+1; + } + return True; +} /******************************************************************* Determine if a pattern contains any Microsoft wildcard characters. -- cgit