]> git.ipfire.org Git - thirdparty/gcc.git/blame - libiberty/fopen_unlocked.c
libiberty.h (fopen_unlocked, [...]): Provide prototypes for new functions.
[thirdparty/gcc.git] / libiberty / fopen_unlocked.c
CommitLineData
78a7dc90
KG
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
5This file is part of the libiberty library.
6Libiberty is free software; you can redistribute it and/or
7modify it under the terms of the GNU Library General Public
8License as published by the Free Software Foundation; either
9version 2 of the License, or (at your option) any later version.
10
11Libiberty is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14Library General Public License for more details.
15
16You should have received a copy of the GNU Library General Public
17License along with libiberty; see the file COPYING.LIB. If
18not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21/*
22
23@deftypefn Extension FILE * fopen_unlocked (const char *@var{path}, const char * @var{mode})
24
25Opens and returns a @code{FILE} pointer via @code{fopen}. If the
26operating system supports it, ensure that the stream is setup to avoid
27any multi-threaded locking. Otherwise return the @code{FILE} pointer
28unchanged.
29
30@end deftypefn
31
32@deftypefn Extension FILE * fdopen_unlocked (int @var{fildes}, const char * @var{mode})
33
34Opens and returns a @code{FILE} pointer via @code{fdopen}. If the
35operating system supports it, ensure that the stream is setup to avoid
36any multi-threaded locking. Otherwise return the @code{FILE} pointer
37unchanged.
38
39@end deftypefn
40
41@deftypefn Extension FILE * freopen_unlocked (const char * @var{path}, const char * @var{mode}, FILE * @var{stream})
42
43Opens and returns a @code{FILE} pointer via @code{freopen}. If the
44operating system supports it, ensure that the stream is setup to avoid
45any multi-threaded locking. Otherwise return the @code{FILE} pointer
46unchanged.
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
62FILE *
63fopen_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
73FILE *
74fdopen_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
84FILE *
85freopen_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}