comparison lib/freopen.c @ 30223:d4c4e46404f1

Override freopen more carefully.
author Bruno Haible <bruno@clisp.org>
date Sun, 28 Sep 2008 16:17:51 +0200
parents e90249a0454f
children b5e42ef33b49
comparison
equal deleted inserted replaced
30222:3c8170dabe46 30223:d4c4e46404f1
1 /* Open a stream to a file. 1 /* Open a stream to a file.
2 Copyright (C) 2007 Free Software Foundation, Inc. 2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
3 3
4 This program is free software: you can redistribute it and/or modify 4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or 6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version. 7 (at your option) any later version.
16 16
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ 17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
18 18
19 #include <config.h> 19 #include <config.h>
20 20
21 /* Get the original definition of freopen. It might be defined as a macro. */
22 #define __need_FILE
23 #include <stdio.h>
24 #undef __need_FILE
25
26 static inline FILE *
27 orig_freopen (const char *filename, const char *mode, FILE *stream)
28 {
29 return freopen (filename, mode, stream);
30 }
31
21 /* Specification. */ 32 /* Specification. */
22 #include <stdio.h> 33 #include <stdio.h>
23 34
24 #include <string.h> 35 #include <string.h>
25 36
26 FILE * 37 FILE *
27 rpl_freopen (const char *filename, const char *mode, FILE *stream) 38 rpl_freopen (const char *filename, const char *mode, FILE *stream)
28 #undef freopen
29 { 39 {
30 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__ 40 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
31 if (strcmp (filename, "/dev/null") == 0) 41 if (strcmp (filename, "/dev/null") == 0)
32 filename = "NUL"; 42 filename = "NUL";
33 #endif 43 #endif
34 44
35 return freopen (filename, mode, stream); 45 return orig_freopen (filename, mode, stream);
36 } 46 }