Skip to content

Commit 8e9b208

Browse files
j6tgitster
authored andcommitted
Windows: shorten code by re-using convert_slashes()
Make a few more spots more readable by using the recently introduced, Windows-specific helper. Signed-off-by: Johannes Sixt <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8257d3b commit 8e9b208

File tree

2 files changed

+3
-11
lines changed

2 files changed

+3
-11
lines changed

abspath.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,17 +167,14 @@ const char *prefix_filename(const char *pfx, int pfx_len, const char *arg)
167167
strbuf_add(&path, pfx, pfx_len);
168168
strbuf_addstr(&path, arg);
169169
#else
170-
char *p;
171170
/* don't add prefix to absolute paths, but still replace '\' by '/' */
172171
strbuf_reset(&path);
173172
if (is_absolute_path(arg))
174173
pfx_len = 0;
175174
else if (pfx_len)
176175
strbuf_add(&path, pfx, pfx_len);
177176
strbuf_addstr(&path, arg);
178-
for (p = path.buf + pfx_len; *p; p++)
179-
if (*p == '\\')
180-
*p = '/';
177+
convert_slashes(path.buf + pfx_len);
181178
#endif
182179
return path.buf;
183180
}

compat/mingw.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -763,15 +763,12 @@ struct tm *localtime_r(const time_t *timep, struct tm *result)
763763

764764
char *mingw_getcwd(char *pointer, int len)
765765
{
766-
int i;
767766
wchar_t wpointer[MAX_PATH];
768767
if (!_wgetcwd(wpointer, ARRAY_SIZE(wpointer)))
769768
return NULL;
770769
if (xwcstoutf(pointer, wpointer, len) < 0)
771770
return NULL;
772-
for (i = 0; pointer[i]; i++)
773-
if (pointer[i] == '\\')
774-
pointer[i] = '/';
771+
convert_slashes(pointer);
775772
return pointer;
776773
}
777774

@@ -2112,9 +2109,7 @@ static void setup_windows_environment()
21122109
* executable (by not mistaking the dir separators
21132110
* for escape characters).
21142111
*/
2115-
for (; *tmp; tmp++)
2116-
if (*tmp == '\\')
2117-
*tmp = '/';
2112+
convert_slashes(tmp);
21182113
}
21192114

21202115
/* simulate TERM to enable auto-color (see color.c) */

0 commit comments

Comments
 (0)