YetAnotherCoupler 3.2.0_a
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;
58 if ((fp = fopen(path, mode)) == NULL) {
59 char const format_string[] = "%s (path: \"%s\")";
60 char const * err_string = strerror(errno);
61 char * error_buffer =
62 xmalloc(strlen(format_string) + strlen(err_string) + strlen(path));
63 sprintf(error_buffer, "xfopen: %s (path: \"%s\")", err_string, path);
64 symprefix(abort_message)(error_buffer, source, line);
65 free(error_buffer);
66 }
67 return fp;
68}
69
70void
71symprefix(xfclose)(FILE *fp, const char *source, int line)
72{
73 if (fclose(fp) != 0)
74 symprefix(abort_message)(strerror(errno), source, line);
75}
76/*
77 * Local Variables:
78 * license-project-url: "https://www.dkrz.de/redmine/projects/scales-ppm"
79 * license-markup: "doxygen"
80 * license-default: "bsd"
81 * End:
82 */
void symprefix() abort_message(const char *msg, const char *source, int line)
Definition core.c:98
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