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
23 #include <sys/types.h>
29 #include "usterr-signal-safe.h"
31 static int (*__lttng_ust_fd_plibc_close
)(int fd
);
32 static int (*__lttng_ust_fd_plibc_fclose
)(FILE *stream
);
35 int _lttng_ust_fd_libc_close(int fd
)
37 if (!__lttng_ust_fd_plibc_close
) {
38 __lttng_ust_fd_plibc_close
= dlsym(RTLD_NEXT
, "close");
39 if (!__lttng_ust_fd_plibc_close
) {
40 fprintf(stderr
, "%s\n", dlerror());
44 return lttng_ust_safe_close_fd(fd
, __lttng_ust_fd_plibc_close
);
48 int _lttng_ust_fd_libc_fclose(FILE *stream
)
50 if (!__lttng_ust_fd_plibc_fclose
) {
51 __lttng_ust_fd_plibc_fclose
= dlsym(RTLD_NEXT
, "fclose");
52 if (!__lttng_ust_fd_plibc_fclose
) {
53 fprintf(stderr
, "%s\n", dlerror());
57 return lttng_ust_safe_fclose_stream(stream
,
58 __lttng_ust_fd_plibc_fclose
);
63 return _lttng_ust_fd_libc_close(fd
);
67 * Note: fcloseall() is not an issue because it fcloses only the
68 * streams it knows about, which differs from the problems caused by
69 * gnulib close_stdout(), which does an explicit fclose(stdout).
71 int fclose(FILE *stream
)
73 return _lttng_ust_fd_libc_fclose(stream
);
76 #if defined(__sun__) || defined(__FreeBSD__)
77 /* Solaris and FreeBSD. */
78 void closefrom(int lowfd
)
80 (void) lttng_ust_safe_closefrom(lowfd
, __lttng_ust_fd_plibc_close
);
82 #elif defined(__NetBSD__) || defined(__OpenBSD__)
83 /* NetBSD and OpenBSD. */
84 int closefrom(int lowfd
)
86 return lttng_ust_safe_closefrom(lowfd
, __lttng_ust_fd_plibc_close
);
89 /* As far as we know, this OS does not implement closefrom. */