-
Notifications
You must be signed in to change notification settings - Fork 1
/
#safezlib.cc#
105 lines (69 loc) · 1.68 KB
/
#safezlib.cc#
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// safezlib.cc
// Scott F. Kaplan -- [email protected]
// Provide an interface to the zlib library that performs error
// checking with each call. The assumption is that an error is cause
// to halt the program, and so calls to these functions will rid the
// caller of the need to write error checking conditionals, thus
// cluttering the code.
#include "safezlib.hh"
gzFile
safegzopen(char* pathname, char* mode) {
gzFile file = gzopen(pathname, mode);
if (file == NULL) {
cerr << "safegzopen: error " << pathname << endl;
exit(-1);
}
return file;
}
void
safegzgets(gzFile file,
char* buffer,
unsigned int length) {
char* result = gzgets(file, buffer, length);
if (result == Z_NULL) {
cerr << "safegzgets: error" << endl;
exit(-1);
}
}
void
safegzputs(gzFile file,
char* buffer) {
int result = gzputs(file, buffer);
if (result == -1) {
cerr << "safegzputs: error" << endl;
exit(-1);
}
}
void
safegzread (gzFile file, voidp buffer, unsigned length) {
int result = gzread(file, buffer, length);
if (result != length) {
cerr << "safegzread: error" << endl;
exit(-1);
}
}
void
safegzwrite (gzFile file, const voidp buffer, unsigned length) {
int result = gzwrite(file, buffer, length);
if (result != length) {
cerr << "safegzwrite: error" << endl;
exit(-1);
}
}
int
safegzgetc (gzFile file) {
int result = gzgetc(file);
if (result == -1) {
cerr << "safegzgetc: error" << endl;
exit(-1);
}
return result;
}
void
safegzputc (gzFile file, int character) {
int result = gzputc(file, character);
if (result != character) {
cerr << "safegzputc: error" << endl;
exit(-1);
}
}