X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;ds=sidebyside;f=dir.c;h=cfaa28ff23acb462aa0cfd54a405316320ec3bc8;hb=4a92d1bfb784b09641180d164e7d719080165dc4;hp=109e05b01346ac13296dfbcfa2355a43d97731cd;hpb=b9b378a001d35a64a30a652a45f8084ee2be6cdf;p=git.git diff --git a/dir.c b/dir.c index 109e05b01..cfaa28ff2 100644 --- a/dir.c +++ b/dir.c @@ -837,3 +837,23 @@ void setup_standard_excludes(struct dir_struct *dir) if (excludes_file && !access(excludes_file, R_OK)) add_excludes_from_file(dir, excludes_file); } + +int remove_path(const char *name) +{ + char *slash; + + if (unlink(name) && errno != ENOENT) + return -1; + + slash = strrchr(name, '/'); + if (slash) { + char *dirs = xstrdup(name); + slash = dirs + (slash - name); + do { + *slash = '\0'; + } while (rmdir(dirs) && (slash = strrchr(dirs, '/'))); + free(dirs); + } + return 0; +} +