mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-06-23 16:51:16 -03:00
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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user