Fossil

Check-in [ff8f2dec]
Login

Check-in [ff8f2dec]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Add a configure time check for the existence of setenv(3) in libc for use by fossil_setenv() which has nicer semantics than its current underlying implementation on POSIX systems, 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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | setenv-alternative
Files: files | file ages | folders
SHA3-256: ff8f2decf53f466db1677d45228445a5e09a7f8d985c7c21ba53325c1b421805
User & Date: wyoung 2020-03-19 15:11:14
Original Comment: 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.
Context
2020-03-19
15:11
Add a configure time check for the existence of setenv(3) in libc for use by fossil_setenv() which has nicer semantics than its current underlying implementation on POSIX systems, 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. ... (Closed-Leaf check-in: ff8f2dec user: wyoung tags: setenv-alternative)
2020-03-18
17:25
Merged glob-docs branch down to trunk. ... (check-in: b45a985c user: wyoung tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to auto.def.
269
270
271
272
273
274
275










276
277
278
279
280
281
282
} else {
    define-append EXTRA_CFLAGS -DFOSSIL_DYNAMIC_BUILD=1
    define FOSSIL_DYNAMIC_BUILD
}

# Check for libraries that need to be sorted out early
cc-check-function-in-lib iconv iconv











# Helper for OpenSSL checking
proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
    msg-checking "Checking for $msg..."
    set rc 0
    if {[is_mingw]} {
        lappend libs -lgdi32 -lwsock32 -lcrypt32







>
>
>
>
>
>
>
>
>
>







269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
} else {
    define-append EXTRA_CFLAGS -DFOSSIL_DYNAMIC_BUILD=1
    define FOSSIL_DYNAMIC_BUILD
}

# Check for libraries that need to be sorted out early
cc-check-function-in-lib iconv iconv

# Check for existence of POSIX setenv(), which has nicer semantics than
# putenv() which we fall back on if it isn't available.
msg-checking "Checking for setenv(3) in libc..."
if {[cctest -includes stdlib.h -code {setenv("", "", 0);} -link 1]} {
    msg-result "yes"
    define HAVE_SETENV
} else {
    msg-result "no"
}

# Helper for OpenSSL checking
proc check-for-openssl {msg {cflags {}} {libs {-lssl -lcrypto}}} {
    msg-checking "Checking for $msg..."
    set rc 0
    if {[is_mingw]} {
        lappend libs -lgdi32 -lwsock32 -lcrypt32
Changes to src/file.c.
1727
1728
1729
1730
1731
1732
1733



1734
1735
1736
1737
1738
1739
1740
  int rc;
  char *zString = mprintf("%s=%s", zName, zValue);
#ifdef _WIN32
  wchar_t *uString = fossil_utf8_to_unicode(zString);
  rc = _wputenv(uString);
  fossil_unicode_free(uString);
  fossil_free(zString);



#else
  rc = putenv(zString);
  /* NOTE: Cannot free the string on POSIX. */
  /* fossil_free(zString); */
#endif
  return rc;
}







>
>
>







1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
  int rc;
  char *zString = mprintf("%s=%s", zName, zValue);
#ifdef _WIN32
  wchar_t *uString = fossil_utf8_to_unicode(zString);
  rc = _wputenv(uString);
  fossil_unicode_free(uString);
  fossil_free(zString);
#elif defined(HAVE_SETENV)
  rc = setenv(zName, zValue, 0);
  fossil_free(zString);
#else
  rc = putenv(zString);
  /* NOTE: Cannot free the string on POSIX. */
  /* fossil_free(zString); */
#endif
  return rc;
}