Enable mkostemp to be weak-linked

mkostemp is not available on some older versions of macOS. In order
for our built binaries to run on them, mkostemp must be weak-linked.
On other systems, we use the autoconf check.

Introduce a function fish_mkstemp_cloexec which uses mkostemp if
it was detected and is available at runtime, else falls back to
mkstemp. This isolates some logic that is currently duplicated in
two places.

See #3138 for more on weak linking.
This commit is contained in:
ridiculousfish
2017-01-08 01:32:49 -08:00
parent 6eb88dc13f
commit e5bfdb99b6
4 changed files with 23 additions and 20 deletions

View File

@@ -91,6 +91,20 @@ char *tparm_solaris_kludge(char *str, ...) {
#endif
int fish_mkstemp_cloexec(char *name_template) {
#if HAVE_MKOSTEMP
// null check because mkostemp may be a weak symbol
if (&mkostemp != nullptr) {
return mkostemp(name_template, O_CLOEXEC);
}
#endif
int result_fd = mkstemp(name_template);
if (result_fd != -1) {
fcntl(result_fd, F_SETFD, FD_CLOEXEC);
}
return result_fd;
}
/// Fallback implementations of wcsdup and wcscasecmp. On systems where these are not needed (e.g.
/// building on Linux) these should end up just being stripped, as they are static functions that
/// are not referenced in this file.