diff options
author | Michael Haggerty <mhagger@alum.mit.edu> | 2014-01-06 14:45:25 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-01-06 18:34:21 +0100 |
commit | 0be0521b23f46dac586e1b464fafe8b97027b645 (patch) | |
tree | cc77526800270ba7e2d569ad94f2d31e16ca87c0 /sha1_file.c | |
parent | safe_create_leading_directories(): always restore slash at end of loop (diff) | |
download | git-0be0521b23f46dac586e1b464fafe8b97027b645.tar.xz git-0be0521b23f46dac586e1b464fafe8b97027b645.zip |
safe_create_leading_directories(): introduce enum for return values
Instead of returning magic integer values (which a couple of callers
go to the trouble of distinguishing), return values from an enum. Add
a docstring.
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r-- | sha1_file.c | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/sha1_file.c b/sha1_file.c index 60d6fce074..2a86912e14 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -105,12 +105,12 @@ int mkdir_in_gitdir(const char *path) return adjust_shared_perm(path); } -int safe_create_leading_directories(char *path) +enum scld_error safe_create_leading_directories(char *path) { char *next_component = path + offset_1st_component(path); - int ret = 0; + enum scld_error ret = SCLD_OK; - while (!ret && next_component) { + while (ret == SCLD_OK && next_component) { struct stat st; char *slash = strchr(next_component, '/'); @@ -127,26 +127,26 @@ int safe_create_leading_directories(char *path) if (!stat(path, &st)) { /* path exists */ if (!S_ISDIR(st.st_mode)) - ret = -3; + ret = SCLD_EXISTS; } else if (mkdir(path, 0777)) { if (errno == EEXIST && !stat(path, &st) && S_ISDIR(st.st_mode)) ; /* somebody created it since we checked */ else - ret = -1; + ret = SCLD_FAILED; } else if (adjust_shared_perm(path)) { - ret = -2; + ret = SCLD_PERMS; } *slash = '/'; } return ret; } -int safe_create_leading_directories_const(const char *path) +enum scld_error safe_create_leading_directories_const(const char *path) { /* path points to cache entries, so xstrdup before messing with it */ char *buf = xstrdup(path); - int result = safe_create_leading_directories(buf); + enum scld_error result = safe_create_leading_directories(buf); free(buf); return result; } |