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 | c1310be00c13ab4b949fcbc0e09c629ba2828eef (diff) | |
parent | 0539ecfdfce677b05992af5e9899a9e974130400 (diff) | |
download | git-a795b324b75807365085ab87862a2abb072fd34e.tar.gz |
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; +} |