Skip to content

Commit 831651f

Browse files
mhaggergitster
authored andcommitted
safe_create_leading_directories(): add explicit "slash" pointer
Keep track of the position of the slash character independently of "pos", thereby making the purpose of each variable clearer and working towards other upcoming changes. Signed-off-by: Michael Haggerty <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f050233 commit 831651f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

sha1_file.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,34 +111,36 @@ int safe_create_leading_directories(char *path)
111111

112112
while (pos) {
113113
struct stat st;
114+
char *slash = strchr(pos, '/');
114115

115-
pos = strchr(pos, '/');
116-
if (!pos)
116+
if (!slash)
117117
break;
118-
while (*++pos == '/')
119-
;
118+
while (*(slash + 1) == '/')
119+
slash++;
120+
pos = slash + 1;
120121
if (!*pos)
121122
break;
122-
*--pos = '\0';
123+
124+
*slash = '\0';
123125
if (!stat(path, &st)) {
124126
/* path exists */
125127
if (!S_ISDIR(st.st_mode)) {
126-
*pos = '/';
128+
*slash = '/';
127129
return -3;
128130
}
129131
} else if (mkdir(path, 0777)) {
130132
if (errno == EEXIST &&
131133
!stat(path, &st) && S_ISDIR(st.st_mode)) {
132134
; /* somebody created it since we checked */
133135
} else {
134-
*pos = '/';
136+
*slash = '/';
135137
return -1;
136138
}
137139
} else if (adjust_shared_perm(path)) {
138-
*pos = '/';
140+
*slash = '/';
139141
return -2;
140142
}
141-
*pos++ = '/';
143+
*slash = '/';
142144
}
143145
return 0;
144146
}

0 commit comments

Comments
 (0)