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.
Commit
ff8f2decf53f466db1677d45228445a5e09a7f8d985c7c21ba53325c1b421805
Parent
b45a985c864d06a…
2 files changed
+10
+3
M
auto.def
+10
| --- auto.def | ||
| +++ auto.def | ||
| @@ -271,10 +271,20 @@ | ||
| 271 | 271 | define FOSSIL_DYNAMIC_BUILD |
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | # Check for libraries that need to be sorted out early |
| 275 | 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 | +} | |
| 276 | 286 | |
| 277 | 287 | # Helper for OpenSSL checking |
| 278 | 288 | proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} { |
| 279 | 289 | msg-checking "Checking for $msg..." |
| 280 | 290 | set rc 0 |
| 281 | 291 |
| --- 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 @@ | ||
| 1729 | 1729 | #ifdef _WIN32 |
| 1730 | 1730 | wchar_t *uString = fossil_utf8_to_unicode(zString); |
| 1731 | 1731 | rc = _wputenv(uString); |
| 1732 | 1732 | fossil_unicode_free(uString); |
| 1733 | 1733 | fossil_free(zString); |
| 1734 | +#elif defined(HAVE_SETENV) | |
| 1735 | + rc = setenv(zName, zValue, 0); | |
| 1736 | + fossil_free(zString); | |
| 1734 | 1737 | #else |
| 1735 | 1738 | rc = putenv(zString); |
| 1736 | 1739 | /* NOTE: Cannot free the string on POSIX. */ |
| 1737 | 1740 | /* fossil_free(zString); */ |
| 1738 | 1741 | #endif |
| 1739 | 1742 |
| --- 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 |