system_path: move RUNTIME_PREFIX to a sub-function
The system_path() function has an #ifdef in the middle of it. Let's move the conditional logic into a sub-function. This isolates it more, which will make it easier to change and add to. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Sep 6, 2017 at 08:30 UTC
39b2f6af6e009c2c087eeec293e98222eb396263
1 file changed
+21
-12
exec_cmd.c
+21
-12
@@ -7,19 +7,12 @@
7
static const char *argv_exec_path;
8
static const char *argv0_path;
9
10
-char *system_path(const char *path)
11
-{
10
#ifdef RUNTIME_PREFIX
13
- static const char *prefix;
14
-#else
15
- static const char *prefix = PREFIX;
16
-#endif
17
- struct strbuf d = STRBUF_INIT;
11
19
- if (is_absolute_path(path))
20
- return xstrdup(path);
12
+static const char *system_prefix(void)
13
+{
14
+ static const char *prefix;
15
22
-#ifdef RUNTIME_PREFIX
16
assert(argv0_path);
17
assert(is_absolute_path(argv0_path));
18
@@ -32,9 +25,25 @@ char *system_path(const char *path)
25
"but prefix computation failed. "
26
"Using static fallback '%s'.\n", prefix);
27
}
35
-#endif
28
+ return prefix;
29
+}
30
+#else
31
+
32
+static const char *system_prefix(void)
33
+{
34
+ return PREFIX;
35
+}
36
+
37
+#endif /* RUNTIME_PREFIX */
38
+
39
+char *system_path(const char *path)
40
+{
41
+ struct strbuf d = STRBUF_INIT;
42
+
43
+ if (is_absolute_path(path))
44
+ return xstrdup(path);
45
37
- strbuf_addf(&d, "%s/%s", prefix, path);
46
+ strbuf_addf(&d, "%s/%s", system_prefix(), path);
47
return strbuf_detach(&d, NULL);
48
}
49