2 * Copyright (C) 2016 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; version 2.1 of
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include <sys/types.h>
28 #include "usterr-signal-safe.h"
30 static int (*__lttng_ust_fd_plibc_close
)(int fd
);
31 static int (*__lttng_ust_fd_plibc_fclose
)(FILE *stream
);
34 int _lttng_ust_fd_libc_close(int fd
)
36 if (!__lttng_ust_fd_plibc_close
) {
37 __lttng_ust_fd_plibc_close
= dlsym(RTLD_NEXT
, "close");
38 if (!__lttng_ust_fd_plibc_close
) {
39 fprintf(stderr
, "%s\n", dlerror());
43 return lttng_ust_safe_close_fd(fd
, __lttng_ust_fd_plibc_close
);
47 int _lttng_ust_fd_libc_fclose(FILE *stream
)
49 if (!__lttng_ust_fd_plibc_fclose
) {
50 __lttng_ust_fd_plibc_fclose
= dlsym(RTLD_NEXT
, "fclose");
51 if (!__lttng_ust_fd_plibc_fclose
) {
52 fprintf(stderr
, "%s\n", dlerror());
56 return lttng_ust_safe_fclose_stream(stream
,
57 __lttng_ust_fd_plibc_fclose
);
62 return _lttng_ust_fd_libc_close(fd
);
66 * Note: fcloseall() is not an issue because it fcloses only the
67 * streams it knows about, which differs from the problems caused by
68 * gnulib close_stdout(), which does an explicit fclose(stdout).
70 int fclose(FILE *stream
)
72 return _lttng_ust_fd_libc_fclose(stream
);
75 #if defined(__sun__) || defined(__FreeBSD__)
76 /* Solaris and FreeBSD. */
77 void closefrom(int lowfd
)
79 (void) lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
81 #elif defined(__NetBSD__) || defined(__OpenBSD__)
82 /* NetBSD and OpenBSD. */
83 int closefrom(int lowfd
)
85 return lttng_ust_safe_closefrom_fd(lowfd
, __lttng_ust_fd_plibc_close
);
88 /* As far as we know, this OS does not implement closefrom. */