Commit | Line | Data |
---|---|---|
ac119ae8 DD |
1 | /* Implement fopen_unlocked and related functions. |
2 | Copyright (C) 2005 Free Software Foundation, Inc. | |
3 | Written by Kaveh R. Ghazi <ghazi@caip.rutgers.edu>. | |
4 | ||
5 | This file is part of the libiberty library. | |
6 | Libiberty is free software; you can redistribute it and/or | |
7 | modify it under the terms of the GNU Library General Public | |
8 | License as published by the Free Software Foundation; either | |
9 | version 2 of the License, or (at your option) any later version. | |
10 | ||
11 | Libiberty is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | Library General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU Library General Public | |
17 | License along with libiberty; see the file COPYING.LIB. If | |
18 | not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | Boston, MA 02111-1307, USA. */ | |
20 | ||
21 | /* | |
22 | ||
23 | @deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode}) | |
24 | ||
25 | Opens and returns a @code{FILE} pointer via @code{fopen}. If the | |
26 | operating system supports it, ensure that the stream is setup to avoid | |
27 | any multi-threaded locking. Otherwise return the @code{FILE} pointer | |
28 | unchanged. | |
29 | ||
30 | @end deftypefn | |
31 | ||
32 | @deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode}) | |
33 | ||
34 | Opens and returns a @code{FILE} pointer via @code{fdopen}. If the | |
35 | operating system supports it, ensure that the stream is setup to avoid | |
36 | any multi-threaded locking. Otherwise return the @code{FILE} pointer | |
37 | unchanged. | |
38 | ||
39 | @end deftypefn | |
40 | ||
41 | @deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream}) | |
42 | ||
43 | Opens and returns a @code{FILE} pointer via @code{freopen}. If the | |
44 | operating system supports it, ensure that the stream is setup to avoid | |
45 | any multi-threaded locking. Otherwise return the @code{FILE} pointer | |
46 | unchanged. | |
47 | ||
48 | @end deftypefn | |
49 | ||
50 | */ | |
51 | ||
52 | #ifdef HAVE_CONFIG_H | |
53 | #include "config.h" | |
54 | #endif | |
55 | #include <stdio.h> | |
56 | #ifdef HAVE_STDIO_EXT_H | |
57 | #include <stdio_ext.h> | |
58 | #endif | |
59 | ||
60 | #include "libiberty.h" | |
61 | ||
62 | FILE * | |
63 | fopen_unlocked (const char *path, const char *mode) | |
64 | { | |
65 | FILE *const fp = fopen (path, mode); | |
66 | #if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER) | |
67 | if (fp) | |
68 | __fsetlocking (fp, FSETLOCKING_BYCALLER); | |
69 | #endif | |
70 | return fp; | |
71 | } | |
72 | ||
73 | FILE * | |
74 | fdopen_unlocked (int fildes, const char *mode) | |
75 | { | |
76 | FILE *const fp = fdopen (fildes, mode); | |
77 | #if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER) | |
78 | if (fp) | |
79 | __fsetlocking (fp, FSETLOCKING_BYCALLER); | |
80 | #endif | |
81 | return fp; | |
82 | } | |
83 | ||
84 | FILE * | |
85 | freopen_unlocked (const char *path, const char *mode, FILE *stream) | |
86 | { | |
87 | FILE *const fp = freopen (path, mode, stream); | |
88 | #if defined(HAVE___FSETLOCKING) && defined(FSETLOCKING_BYCALLER) | |
89 | if (fp) | |
90 | __fsetlocking (fp, FSETLOCKING_BYCALLER); | |
91 | #endif | |
92 | return fp; | |
93 | } |