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 <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Michael Haggerty committed
Jan 6, 2014 at 14:45 UTC
831651fde8f8a8d90543917a8783962aa1a534bf
1 file changed
+11
-9
sha1_file.c
+11
-9
@@ -111,19 +111,21 @@ int safe_create_leading_directories(char *path)
111
112
while (pos) {
113
struct stat st;
114
+ char *slash = strchr(pos, '/');
115
115
- pos = strchr(pos, '/');
116
- if (!pos)
116
+ if (!slash)
117
break;
118
- while (*++pos == '/')
119
- ;
118
+ while (*(slash + 1) == '/')
119
+ slash++;
120
+ pos = slash + 1;
121
if (!*pos)
122
break;
122
- *--pos = '\0';
123
+
124
+ *slash = '\0';
125
if (!stat(path, &st)) {
126
/* path exists */
127
if (!S_ISDIR(st.st_mode)) {
126
- *pos = '/';
128
+ *slash = '/';
129
return -3;
130
}
131
} else if (mkdir(path, 0777)) {
@@ -131,14 +133,14 @@ int safe_create_leading_directories(char *path)
133
!stat(path, &st) && S_ISDIR(st.st_mode)) {
134
; /* somebody created it since we checked */
135
} else {
134
- *pos = '/';
136
+ *slash = '/';
137
return -1;
138
}
139
} else if (adjust_shared_perm(path)) {
138
- *pos = '/';
140
+ *slash = '/';
141
return -2;
142
}
141
- *pos++ = '/';
143
+ *slash = '/';
144
}
145
return 0;
146
}