]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: make `getenv_safe()` a public function
authorPatrick Steinhardt <ps@pks.im>
Tue, 12 Jan 2021 12:27:10 +0000 (13:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Fri, 15 Jan 2021 21:03:45 +0000 (13:03 -0800)
The `getenv_safe()` helper function helps to safely retrieve multiple
environment values without the need to depend on platform-specific
behaviour for the return value's lifetime. We'll make use of this
function in a following patch, so let's make it available by making it
non-static and adding a declaration.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
environment.h [new file with mode: 0644]

index bb518c61cd259caf74f65fc8a080096b54168e48..2234af462ccb13282fd8b07ba20148dbaf41d3d0 100644 (file)
@@ -9,6 +9,7 @@
  */
 #include "cache.h"
 #include "branch.h"
+#include "environment.h"
 #include "repository.h"
 #include "config.h"
 #include "refs.h"
@@ -152,11 +153,7 @@ static char *expand_namespace(const char *raw_namespace)
        return strbuf_detach(&buf, NULL);
 }
 
-/*
- * Wrapper of getenv() that returns a strdup value. This value is kept
- * in argv to be freed later.
- */
-static const char *getenv_safe(struct strvec *argv, const char *name)
+const char *getenv_safe(struct strvec *argv, const char *name)
 {
        const char *value = getenv(name);
 
diff --git a/environment.h b/environment.h
new file mode 100644 (file)
index 0000000..d438b5c
--- /dev/null
@@ -0,0 +1,12 @@
+#ifndef ENVIRONMENT_H
+#define ENVIRONMENT_H
+
+#include "strvec.h"
+
+/*
+ * Wrapper of getenv() that returns a strdup value. This value is kept
+ * in argv to be freed later.
+ */
+const char *getenv_safe(struct strvec *argv, const char *name);
+
+#endif