2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <sys/types.h>
16 #include "usterr-signal-safe.h"
18 static int (*__lttng_ust_fd_plibc_close
)(int fd
);
19 static int (*__lttng_ust_fd_plibc_fclose
)(FILE *stream
);
22 int _lttng_ust_fd_libc_close(int fd
)
24 if (!__lttng_ust_fd_plibc_close
) {
25 __lttng_ust_fd_plibc_close
= dlsym(RTLD_NEXT
, "close");
26 if (!__lttng_ust_fd_plibc_close
) {
27 fprintf(stderr
, "%s\n", dlerror());
31 return lttng_ust_safe_close_fd(fd
, __lttng_ust_fd_plibc_close
);
35 int _lttng_ust_fd_libc_fclose(FILE *stream
)
37 if (!__lttng_ust_fd_plibc_fclose
) {
38 __lttng_ust_fd_plibc_fclose
= dlsym(RTLD_NEXT
, "fclose");
39 if (!__lttng_ust_fd_plibc_fclose
) {
40 fprintf(stderr
, "%s\n", dlerror());
44 return lttng_ust_safe_fclose_stream(stream
,
45 __lttng_ust_fd_plibc_fclose
);
50 return _lttng_ust_fd_libc_close(fd
);
54 * Note: fcloseall() is not an issue because it fcloses only the
55 * streams it knows about, which differs from the problems caused by
56 * gnulib close_stdout(), which does an explicit fclose(stdout).
58 int fclose(FILE *stream
)
60 return _lttng_ust_fd_libc_fclose(stream
);
63 #if defined(__sun__) || defined(__FreeBSD__)
64 /* Solaris and FreeBSD. */
65 void closefrom(int lowfd
)
67 (void) lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
69 #elif defined(__NetBSD__) || defined(__OpenBSD__)
70 /* NetBSD and OpenBSD. */
71 int closefrom(int lowfd
)
73 return lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
76 /* As far as we know, this OS does not implement closefrom. */