summaryrefslogtreecommitdiff
path: root/src/path.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/path.c')
-rw-r--r--src/path.c132
1 files changed, 66 insertions, 66 deletions
diff --git a/src/path.c b/src/path.c
index ce4203ff3..2c6b76dd0 100644
--- a/src/path.c
+++ b/src/path.c
@@ -23,8 +23,8 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* Empty or NULL string gets treated as "." */
if (path == NULL || *path == '\0') {
- startp = ".";
- len = 1;
+ startp = ".";
+ len = 1;
goto Exit;
}
@@ -36,7 +36,7 @@ int git_path_basename_r(char *buffer, size_t bufflen, const char *path)
/* All slashes becomes "/" */
if (endp == path && *endp == '/') {
startp = "/";
- len = 1;
+ len = 1;
goto Exit;
}
@@ -53,7 +53,7 @@ Exit:
return result;
}
if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
+ len = (int)bufflen-1;
result = GIT_ENOMEM;
}
@@ -70,103 +70,103 @@ Exit:
*/
int git_path_dirname_r(char *buffer, size_t bufflen, const char *path)
{
- const char *endp;
- int result, len;
-
- /* Empty or NULL string gets treated as "." */
- if (path == NULL || *path == '\0') {
- path = ".";
- len = 1;
- goto Exit;
- }
-
- /* Strip trailing slashes */
- endp = path + strlen(path) - 1;
- while (endp > path && *endp == '/')
- endp--;
-
- /* Find the start of the dir */
- while (endp > path && *endp != '/')
- endp--;
-
- /* Either the dir is "/" or there are no slashes */
- if (endp == path) {
- path = (*endp == '/') ? "/" : ".";
- len = 1;
- goto Exit;
- }
-
- do {
- endp--;
- } while (endp > path && *endp == '/');
-
- len = endp - path +1;
+ const char *endp;
+ int result, len;
+
+ /* Empty or NULL string gets treated as "." */
+ if (path == NULL || *path == '\0') {
+ path = ".";
+ len = 1;
+ goto Exit;
+ }
+
+ /* Strip trailing slashes */
+ endp = path + strlen(path) - 1;
+ while (endp > path && *endp == '/')
+ endp--;
+
+ /* Find the start of the dir */
+ while (endp > path && *endp != '/')
+ endp--;
+
+ /* Either the dir is "/" or there are no slashes */
+ if (endp == path) {
+ path = (*endp == '/') ? "/" : ".";
+ len = 1;
+ goto Exit;
+ }
+
+ do {
+ endp--;
+ } while (endp > path && *endp == '/');
+
+ len = endp - path +1;
#ifdef GIT_WIN32
- /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
- 'C:/' here */
+ /* Mimic unix behavior where '/.git' returns '/': 'C:/.git' will return
+ 'C:/' here */
- if (len == 2 && isalpha(path[0]) && path[1] == ':') {
- len = 3;
- goto Exit;
- }
+ if (len == 2 && isalpha(path[0]) && path[1] == ':') {
+ len = 3;
+ goto Exit;
+ }
#endif
Exit:
- result = len;
- if (len+1 > GIT_PATH_MAX) {
- return GIT_ENOMEM;
- }
- if (buffer == NULL)
- return result;
-
- if (len > (int)bufflen-1) {
- len = (int)bufflen-1;
- result = GIT_ENOMEM;
- }
-
- if (len >= 0) {
- memmove(buffer, path, len);
- buffer[len] = 0;
- }
- return result;
+ result = len;
+ if (len+1 > GIT_PATH_MAX) {
+ return GIT_ENOMEM;
+ }
+ if (buffer == NULL)
+ return result;
+
+ if (len > (int)bufflen-1) {
+ len = (int)bufflen-1;
+ result = GIT_ENOMEM;
+ }
+
+ if (len >= 0) {
+ memmove(buffer, path, len);
+ buffer[len] = 0;
+ }
+ return result;
}
char *git_path_dirname(const char *path)
{
- char *dname = NULL;
- int len;
+ char *dname = NULL;
+ int len;
len = (path ? strlen(path) : 0) + 2;
dname = (char *)git__malloc(len);
if (dname == NULL)
return NULL;
- if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
+ if (git_path_dirname_r(dname, len, path) < GIT_SUCCESS) {
free(dname);
return NULL;
}
- return dname;
+ return dname;
}
char *git_path_basename(const char *path)
{
- char *bname = NULL;
- int len;
+ char *bname = NULL;
+ int len;
len = (path ? strlen(path) : 0) + 2;
bname = (char *)git__malloc(len);
if (bname == NULL)
return NULL;
- if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
+ if (git_path_basename_r(bname, len, path) < GIT_SUCCESS) {
free(bname);
return NULL;
}
- return bname;
+ return bname;
}