/
utils.c
77 lines (61 loc) · 2.04 KB
/
utils.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef UTILS_C
#define UTILS_C
/* ========================================================================== *
* utils.c
* Time-stamp: <2010-10-28 15:11:20 (mkmcc)>
*
* Some basic utilities. Taken (almost) verbatim from the athena
* source code.
*
* Begun by Mike McCourt Sept. 2010
* ========================================================================== */
/* Copyright information for the original program: */
/*
ATHENA
AUTHORS:
James M. Stone, Princeton Univeristy
Thomas A. Gardiner, Sandia National Laboratory
Peter J. Teuben, University of Maryland
John F. Hawley, University of Virginia
This software was produced with support from NSF Grant AST-0113571
Copyright 2003 James M. Stone, Thomas A. Gardiner,
Peter J. Teuben, John F. Hawley
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
FILE *atherr_fp(void);
void ath_error(char *fmt, ...);
char *ath_strdup(const char *in);
FILE *atherr_fp(void)
{
return (stderr);
}
void ath_error(char *fmt, ...)
{
va_list ap;
FILE *atherr = atherr_fp();
fprintf(atherr,"### Fatal error: "); /* prefix */
va_start(ap, fmt); /* ap starts with string 'fmt' */
vfprintf(atherr, fmt, ap); /* print out on atherr */
fflush(atherr); /* flush it NOW */
va_end(ap); /* end varargs */
exit(EXIT_FAILURE);
}
char *ath_strdup(const char *in)
{
char *out = (char *)malloc((1+strlen(in))*sizeof(char));
if(out == NULL) {
printf("ath_strdup: failed to alloc %d\n", (int)(1+strlen(in)));
return NULL; /* malloc failed */
}
return strcpy(out,in);
}
#endif