YetAnotherCoupler 3.2.0
Loading...
Searching...
No Matches
xstdio.c
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Thomas Jahns <jahns@dkrz.de>
2//
3// SPDX-License-Identifier: BSD-3-Clause
4
14/*
15 * Maintainer: Thomas Jahns <jahns@dkrz.de>
16 * URL: https://www.dkrz.de/redmine/projects/scales-ppm
17 *
18 * Redistribution and use in source and binary forms, with or without
19 * modification, are permitted provided that the following conditions are
20 * met:
21 *
22 * Redistributions of source code must retain the above copyright notice,
23 * this list of conditions and the following disclaimer.
24 *
25 * Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
28 *
29 * Neither the name of the DKRZ GmbH nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
32 *
33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
34 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
35 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
36 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
37 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
38 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
39 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
40 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
41 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
42 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
43 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 */
45#include <errno.h>
46#include <stdio.h>
47#include <string.h>
48
49#include "ppm/core.h"
50#include "ppm/ppm_xfuncs.h"
51#include "ppm/symprefix.h"
52
53FILE *
54symprefix(xfopen)(const char *path, const char *mode,
55 const char *source, int line)
56{
57 FILE *fp = fopen(path, mode);
58 if (fp == NULL) {
59 // GCOVR_EXCL_START
60 char const format_string[] = "%s (path: \"%s\")";
61 char const * err_string = strerror(errno);
62 char * error_buffer =
63 xmalloc(strlen(format_string) + strlen(err_string) + strlen(path));
64 sprintf(error_buffer, "xfopen: %s (path: \"%s\")", err_string, path);
65 symprefix(abort_message)(error_buffer, source, line);
66 free(error_buffer);
67 // GCOVR_EXCL_STOP
68 }
69 return fp;
70}
71
72void
73symprefix(xfclose)(FILE *fp, const char *source, int line)
74{
75 if (fclose(fp) != 0)
76 symprefix(abort_message)(strerror(errno), source, line); // GCOVR_EXCL_LINE
77}
78/*
79 * Local Variables:
80 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
81 * license-markup: "doxygen"
82 * license-default: "bsd"
83 * End:
84 */
void symprefix() abort_message(const char *msg, const char *source, int line)
Definition core.c:100
add versions of standard API functions not returning on error
#define xmalloc(size)
Definition ppm_xfuncs.h:66
#define xfclose(fp)
Definition ppm_xfuncs.h:79
#define xfopen(path, mode)
Definition ppm_xfuncs.h:74
Define library-specific symbol prefix macros.
#define symprefix(symbol)
Definition symprefix.h:55