2 * SPDX-License-Identifier: LGPL-2.1-only
4 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
10 #include <sys/types.h>
15 #include <ust-helper.h>
17 static int (*__lttng_ust_fd_plibc_close
)(int fd
);
18 static int (*__lttng_ust_fd_plibc_fclose
)(FILE *stream
);
21 int _lttng_ust_fd_libc_close(int fd
)
23 if (!__lttng_ust_fd_plibc_close
) {
24 __lttng_ust_fd_plibc_close
= dlsym(RTLD_NEXT
, "close");
25 if (!__lttng_ust_fd_plibc_close
) {
26 fprintf(stderr
, "%s\n", dlerror());
30 return lttng_ust_safe_close_fd(fd
, __lttng_ust_fd_plibc_close
);
34 int _lttng_ust_fd_libc_fclose(FILE *stream
)
36 if (!__lttng_ust_fd_plibc_fclose
) {
37 __lttng_ust_fd_plibc_fclose
= dlsym(RTLD_NEXT
, "fclose");
38 if (!__lttng_ust_fd_plibc_fclose
) {
39 fprintf(stderr
, "%s\n", dlerror());
43 return lttng_ust_safe_fclose_stream(stream
,
44 __lttng_ust_fd_plibc_fclose
);
49 return _lttng_ust_fd_libc_close(fd
);
53 * Note: fcloseall() is not an issue because it fcloses only the
54 * streams it knows about, which differs from the problems caused by
55 * gnulib close_stdout(), which does an explicit fclose(stdout).
57 int fclose(FILE *stream
)
59 return _lttng_ust_fd_libc_fclose(stream
);
62 #if defined(__sun__) || defined(__FreeBSD__)
63 /* Solaris and FreeBSD. */
64 void closefrom(int lowfd
)
66 (void) lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
68 #elif defined(__NetBSD__) || defined(__OpenBSD__)
69 /* NetBSD and OpenBSD. */
70 int closefrom(int lowfd
)
72 return lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
75 /* As far as we know, this OS does not implement closefrom. */