diff options
author | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:54:37 -0700 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2012-09-03 15:54:37 -0700 |
commit | a795b324b75807365085ab87862a2abb072fd34e (patch) | |
tree | a525d004b370f7790606b8a1a8d13b4ab95e741d /compat | |
parent | Merge branch 'js/no-curl-easy-strerror-on-old-curl' (diff) | |
parent | compat: some mkdir() do not like a slash at the end (diff) | |
download | tgif-a795b324b75807365085ab87862a2abb072fd34e.tar.xz |
Merge branch 'js/compat-mkdir'
Some mkdir(2) implementations do not want to see trailing slash in
its parameter.
* js/compat-mkdir:
compat: some mkdir() do not like a slash at the end
Diffstat (limited to 'compat')
-rw-r--r-- | compat/mkdir.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/compat/mkdir.c b/compat/mkdir.c new file mode 100644 index 0000000000..9e253fb72f --- /dev/null +++ b/compat/mkdir.c @@ -0,0 +1,24 @@ +#include "../git-compat-util.h" +#undef mkdir + +/* for platforms that can't deal with a trailing '/' */ +int compat_mkdir_wo_trailing_slash(const char *dir, mode_t mode) +{ + int retval; + char *tmp_dir = NULL; + size_t len = strlen(dir); + + if (len && dir[len-1] == '/') { + if ((tmp_dir = strdup(dir)) == NULL) + return -1; + tmp_dir[len-1] = '\0'; + } + else + tmp_dir = (char *)dir; + + retval = mkdir(tmp_dir, mode); + if (tmp_dir != dir) + free(tmp_dir); + + return retval; +} |