Fossil SCM

Add a configure tiem check for the existence of setenv(3) in libc for use by fossil_putenv() which has nicer semantics than putenv(3). This doesn't fix any known issue other than a technical memory leak, but I'm checking it in in case someone finds the code useful someday.

wyoung 2020-03-19 15:11 trunk
Commit ff8f2decf53f466db1677d45228445a5e09a7f8d985c7c21ba53325c1b421805
2 files changed +10 +3
+10
--- auto.def
+++ auto.def
@@ -271,10 +271,20 @@
271271
define FOSSIL_DYNAMIC_BUILD
272272
}
273273
274274
# Check for libraries that need to be sorted out early
275275
cc-check-function-in-lib iconv iconv
276
+
277
+# Check for existence of POSIX setenv(), which has nicer semantics than
278
+# putenv() which we fall back on if it isn't available.
279
+msg-checking "Checking for setenv(3) in libc..."
280
+if {[cctest -includes stdlib.h -code {setenv("", "", 0);} -link 1]} {
281
+ msg-result "yes"
282
+ define HAVE_SETENV
283
+} else {
284
+ msg-result "no"
285
+}
276286
277287
# Helper for OpenSSL checking
278288
proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
279289
msg-checking "Checking for $msg..."
280290
set rc 0
281291
--- auto.def
+++ auto.def
@@ -271,10 +271,20 @@
271 define FOSSIL_DYNAMIC_BUILD
272 }
273
274 # Check for libraries that need to be sorted out early
275 cc-check-function-in-lib iconv iconv
 
 
 
 
 
 
 
 
 
 
276
277 # Helper for OpenSSL checking
278 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
279 msg-checking "Checking for $msg..."
280 set rc 0
281
--- auto.def
+++ auto.def
@@ -271,10 +271,20 @@
271 define FOSSIL_DYNAMIC_BUILD
272 }
273
274 # Check for libraries that need to be sorted out early
275 cc-check-function-in-lib iconv iconv
276
277 # Check for existence of POSIX setenv(), which has nicer semantics than
278 # putenv() which we fall back on if it isn't available.
279 msg-checking "Checking for setenv(3) in libc..."
280 if {[cctest -includes stdlib.h -code {setenv("", "", 0);} -link 1]} {
281 msg-result "yes"
282 define HAVE_SETENV
283 } else {
284 msg-result "no"
285 }
286
287 # Helper for OpenSSL checking
288 proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
289 msg-checking "Checking for $msg..."
290 set rc 0
291
+3
--- src/file.c
+++ src/file.c
@@ -1729,10 +1729,13 @@
17291729
#ifdef _WIN32
17301730
wchar_t *uString = fossil_utf8_to_unicode(zString);
17311731
rc = _wputenv(uString);
17321732
fossil_unicode_free(uString);
17331733
fossil_free(zString);
1734
+#elif defined(HAVE_SETENV)
1735
+ rc = setenv(zName, zValue, 0);
1736
+ fossil_free(zString);
17341737
#else
17351738
rc = putenv(zString);
17361739
/* NOTE: Cannot free the string on POSIX. */
17371740
/* fossil_free(zString); */
17381741
#endif
17391742
--- src/file.c
+++ src/file.c
@@ -1729,10 +1729,13 @@
1729 #ifdef _WIN32
1730 wchar_t *uString = fossil_utf8_to_unicode(zString);
1731 rc = _wputenv(uString);
1732 fossil_unicode_free(uString);
1733 fossil_free(zString);
 
 
 
1734 #else
1735 rc = putenv(zString);
1736 /* NOTE: Cannot free the string on POSIX. */
1737 /* fossil_free(zString); */
1738 #endif
1739
--- src/file.c
+++ src/file.c
@@ -1729,10 +1729,13 @@
1729 #ifdef _WIN32
1730 wchar_t *uString = fossil_utf8_to_unicode(zString);
1731 rc = _wputenv(uString);
1732 fossil_unicode_free(uString);
1733 fossil_free(zString);
1734 #elif defined(HAVE_SETENV)
1735 rc = setenv(zName, zValue, 0);
1736 fossil_free(zString);
1737 #else
1738 rc = putenv(zString);
1739 /* NOTE: Cannot free the string on POSIX. */
1740 /* fossil_free(zString); */
1741 #endif
1742

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button