Line |
Branch |
Exec |
Source |
1 |
|
|
/** |
2 |
|
|
* @file xstdio.c |
3 |
|
|
* @brief fail-safe stdio function wrappers |
4 |
|
|
* |
5 |
|
|
* @copyright (C) 2012 Thomas Jahns <jahns@dkrz.de> |
6 |
|
|
* |
7 |
|
|
* @version 1.0 |
8 |
|
|
* @author Thomas Jahns <jahns@dkrz.de> |
9 |
|
|
*/ |
10 |
|
|
/* |
11 |
|
|
* Maintainer: Thomas Jahns <jahns@dkrz.de> |
12 |
|
|
* URL: https://swprojects.dkrz.de/redmine/projects/scales-ppm |
13 |
|
|
* |
14 |
|
|
* Redistribution and use in source and binary forms, with or without |
15 |
|
|
* modification, are permitted provided that the following conditions are |
16 |
|
|
* met: |
17 |
|
|
* |
18 |
|
|
* Redistributions of source code must retain the above copyright notice, |
19 |
|
|
* this list of conditions and the following disclaimer. |
20 |
|
|
* |
21 |
|
|
* Redistributions in binary form must reproduce the above copyright |
22 |
|
|
* notice, this list of conditions and the following disclaimer in the |
23 |
|
|
* documentation and/or other materials provided with the distribution. |
24 |
|
|
* |
25 |
|
|
* Neither the name of the DKRZ GmbH nor the names of its contributors |
26 |
|
|
* may be used to endorse or promote products derived from this software |
27 |
|
|
* without specific prior written permission. |
28 |
|
|
* |
29 |
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS |
30 |
|
|
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
31 |
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A |
32 |
|
|
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER |
33 |
|
|
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
34 |
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
35 |
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
36 |
|
|
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
37 |
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
38 |
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
39 |
|
|
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
40 |
|
|
*/ |
41 |
|
|
#ifdef HAVE_CONFIG_H |
42 |
|
|
# include <config.h> |
43 |
|
|
#endif |
44 |
|
|
|
45 |
|
|
#include <errno.h> |
46 |
|
|
#include <stdio.h> |
47 |
|
|
#include <string.h> |
48 |
|
|
|
49 |
|
|
#include "core/core.h" |
50 |
|
|
#include "core/ppm_xfuncs.h" |
51 |
|
|
#include "core/symprefix.h" |
52 |
|
|
|
53 |
|
|
FILE * |
54 |
|
✗ |
SymPrefix(xfopen)(const char *path, const char *mode, |
55 |
|
|
const char *source, int line) |
56 |
|
|
{ |
57 |
|
|
FILE *fp; |
58 |
|
✗ |
if ((fp = fopen(path, mode)) == NULL) |
59 |
|
✗ |
SymPrefix(abort)(SymPrefix(default_comm), strerror(errno), source, line); |
60 |
|
✗ |
return fp; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
void |
64 |
|
✗ |
SymPrefix(xfclose)(FILE *fp, const char *source, int line) |
65 |
|
|
{ |
66 |
|
✗ |
if (fclose(fp) != 0) |
67 |
|
✗ |
SymPrefix(abort)(SymPrefix(default_comm), strerror(errno), source, line); |
68 |
|
|
} |
69 |
|
|
|
70 |
|
|
|
71 |
|
|
int |
72 |
|
✗ |
SymPrefix(xfputc)(int c, FILE *stream, const char *source, int line) |
73 |
|
|
{ |
74 |
|
|
int r; |
75 |
|
✗ |
if ((r = fputc(c, stream)) == EOF) |
76 |
|
✗ |
SymPrefix(abort)(SymPrefix(default_comm), strerror(errno), source, line); |
77 |
|
✗ |
return r; |
78 |
|
|
} |
79 |
|
|
/* |
80 |
|
|
* Local Variables: |
81 |
|
|
* license-project-url: "https://swprojects.dkrz.de/redmine/projects/scales-ppm" |
82 |
|
|
* license-markup: "doxygen" |
83 |
|
|
* license-default: "bsd" |
84 |
|
|
* End: |
85 |
|
|
*/ |
86 |
|
|
|