Subversion Repositories tendra.SVN

Rev

Rev 5 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5 Rev 6
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2005 The TenDRA Project <http://www.tendra.org/>.
-
 
3
 * All rights reserved.
-
 
4
 *
-
 
5
 * Redistribution and use in source and binary forms, with or without
-
 
6
 * modification, are permitted provided that the following conditions are met:
-
 
7
 *
-
 
8
 * 1. Redistributions of source code must retain the above copyright notice,
-
 
9
 *    this list of conditions and the following disclaimer.
-
 
10
 * 2. Redistributions in binary form must reproduce the above copyright notice,
-
 
11
 *    this list of conditions and the following disclaimer in the documentation
-
 
12
 *    and/or other materials provided with the distribution.
-
 
13
 * 3. Neither the name of The TenDRA Project nor the names of its contributors
-
 
14
 *    may be used to endorse or promote products derived from this software
-
 
15
 *    without specific, prior written permission.
-
 
16
 *
-
 
17
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS
-
 
18
 * IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
-
 
19
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-
 
20
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR
-
 
21
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-
 
22
 * EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
-
 
23
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
-
 
24
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-
 
25
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
-
 
26
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
-
 
27
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
 
28
 *
-
 
29
 * $Id$
-
 
30
 */
1
/*
31
/*
2
    		 Crown Copyright (c) 1997
32
    		 Crown Copyright (c) 1997
3
    
33
 
4
    This TenDRA(r) Computer Program is subject to Copyright
34
    This TenDRA(r) Computer Program is subject to Copyright
5
    owned by the United Kingdom Secretary of State for Defence
35
    owned by the United Kingdom Secretary of State for Defence
6
    acting through the Defence Evaluation and Research Agency
36
    acting through the Defence Evaluation and Research Agency
7
    (DERA).  It is made available to Recipients with a
37
    (DERA).  It is made available to Recipients with a
8
    royalty-free licence for its use, reproduction, transfer
38
    royalty-free licence for its use, reproduction, transfer
9
    to other parties and amendment for any purpose not excluding
39
    to other parties and amendment for any purpose not excluding
10
    product development provided that any such use et cetera
40
    product development provided that any such use et cetera
11
    shall be deemed to be acceptance of the following conditions:-
41
    shall be deemed to be acceptance of the following conditions:-
12
    
42
 
13
        (1) Its Recipients shall ensure that this Notice is
43
        (1) Its Recipients shall ensure that this Notice is
14
        reproduced upon any copies or amended versions of it;
44
        reproduced upon any copies or amended versions of it;
15
    
45
 
16
        (2) Any amended version of it shall be clearly marked to
46
        (2) Any amended version of it shall be clearly marked to
17
        show both the nature of and the organisation responsible
47
        show both the nature of and the organisation responsible
18
        for the relevant amendment or amendments;
48
        for the relevant amendment or amendments;
19
    
49
 
20
        (3) Its onward transfer from a recipient to another
50
        (3) Its onward transfer from a recipient to another
21
        party shall be deemed to be that party's acceptance of
51
        party shall be deemed to be that party's acceptance of
22
        these conditions;
52
        these conditions;
23
    
53
 
24
        (4) DERA gives no warranty or assurance as to its
54
        (4) DERA gives no warranty or assurance as to its
25
        quality or suitability for any purpose and DERA accepts
55
        quality or suitability for any purpose and DERA accepts
26
        no liability whatsoever in relation to any use to which
56
        no liability whatsoever in relation to any use to which
27
        it may be put.
57
        it may be put.
28
*/
58
*/
Line 57... Line 87...
57
#include "cstring.h"
87
#include "cstring.h"
58
#include "syntax.h"
88
#include "syntax.h"
59
 
89
 
60
/*--------------------------------------------------------------------------*/
90
/*--------------------------------------------------------------------------*/
61
 
91
 
62
ExceptionP XX_ostream_write_error = EXCEPTION ("error writing to stream");
92
ExceptionP XX_ostream_write_error = EXCEPTION("error writing to stream");
63
 
93
 
64
static OStreamT			ostream_output_1 = {
94
static OStreamT ostream_output_1 = {
65
    NIL (FILE *),
95
    NIL(FILE *),
66
    "<stdout>",
96
    "<stdout>",
67
    "<stdout>",
97
    "<stdout>",
68
    0,
98
    0,
69
    1
99
    1
70
};
100
};
71
static OStreamT			ostream_error_1 = {
101
static OStreamT ostream_error_1 = {
72
    NIL (FILE *),
102
    NIL(FILE *),
73
    "<stderr>",
103
    "<stderr>",
74
    "<stderr>",
104
    "<stderr>",
75
    0,
105
    0,
76
    1
106
    1
77
};
107
};
78
 
108
 
79
OStreamT		 *const ostream_output = &ostream_output_1;
109
OStreamT *const ostream_output = &ostream_output_1;
80
OStreamT		 *const ostream_error  = &ostream_error_1;
110
OStreamT *const ostream_error  = &ostream_error_1;
81
 
111
 
82
/*--------------------------------------------------------------------------*/
112
/*--------------------------------------------------------------------------*/
83
 
113
 
84
#define OSTREAM_WRITE_ERROR_CHECK(ostream) \
114
#define OSTREAM_WRITE_ERROR_CHECK(ostream)\
85
if (ferror ((ostream)->file)) { \
115
if (ferror((ostream)->file)) { \
86
    CStringP X___name = cstring_duplicate (ostream_name (ostream)); \
116
    CStringP X___name = cstring_duplicate(ostream_name(ostream)); \
87
    THROW_VALUE (XX_ostream_write_error, X___name); \
117
    THROW_VALUE(XX_ostream_write_error, X___name); \
88
}
118
}
89
 
119
 
90
/*--------------------------------------------------------------------------*/
120
/*--------------------------------------------------------------------------*/
91
 
121
 
92
void
122
void
93
ostream_setup PROTO_Z ()
123
ostream_setup(void)
94
{
124
{
95
    ostream_output_1.file = stdout;
125
    ostream_output_1.file = stdout;
96
    ostream_error_1.file  = stderr;
126
    ostream_error_1.file  = stderr;
97
}
127
}
98
 
128
 
99
#ifdef FS_FAST
129
#ifdef FS_FAST
100
#undef ostream_init
130
#undef ostream_init
101
#endif /* defined (FS_FAST) */
131
#endif /* defined (FS_FAST) */
102
void
132
void
103
ostream_init PROTO_N ((ostream))
133
ostream_init(OStreamP ostream)
104
	     PROTO_T (OStreamP ostream)
-
 
105
{
134
{
106
    ostream->name = NIL (CStringP);
135
    ostream->name = NIL(CStringP);
107
}
136
}
108
#ifdef FS_FAST
137
#ifdef FS_FAST
109
#define ostream_init(os) ((os)->name = NIL (CStringP))
138
#define ostream_init(os)	((os)->name = NIL(CStringP))
110
#endif /* defined (FS_FAST) */
139
#endif /* defined (FS_FAST) */
111
 
140
 
112
BoolT
141
BoolT
113
ostream_open PROTO_N ((ostream, name))
142
ostream_open(OStreamP ostream, CStringP name)
114
	     PROTO_T (OStreamP ostream X
-
 
115
		      CStringP name)
-
 
116
{
143
{
117
    CStringP oname = name;
144
    CStringP oname = name;
118
    CStringP pname = cstring_find_reverse (name, '@');
145
    CStringP pname = cstring_find_reverse(name, '@');
119
    if (pname != NIL (CStringP)) {
146
    if (pname != NIL(CStringP)) {
120
	oname = ALLOCATE_VECTOR (char, cstring_length (name) + 10);
147
	oname = ALLOCATE_VECTOR(char, cstring_length(name) + 10);
121
	(void) sprintf (oname, "%.*s%d%s", (int) (pname - name), name,
148
	(void)sprintf(oname, "%.*s%d%s", (int)(pname - name), name,
122
			++ostream->no, pname + 1);
149
		      ++ostream->no, pname + 1);
123
    }
150
    }
124
    if ((ostream->file = fopen (oname, "w")) == NIL (FILE *)) {
151
    if ((ostream->file = fopen(oname, "w")) == NIL(FILE *)) {
125
	return (FALSE);
152
	return(FALSE);
126
    }
153
    }
127
    ostream->name = oname;
154
    ostream->name = oname;
128
    ostream->gen_name = name;
155
    ostream->gen_name = name;
129
    ostream->line = 1;
156
    ostream->line = 1;
130
    (void) setvbuf (ostream->file, NIL (CStringP), _IOFBF, (SizeT) BUFSIZ);
157
    (void)setvbuf(ostream->file, NIL(CStringP), _IOFBF, (SizeT)BUFSIZ);
131
    return (TRUE);
158
    return(TRUE);
132
}
159
}
133
 
160
 
134
#ifdef FS_FAST
161
#ifdef FS_FAST
135
#undef ostream_is_open
162
#undef ostream_is_open
136
#endif /* defined (FS_FAST) */
163
#endif /* defined (FS_FAST) */
137
BoolT
164
BoolT
138
ostream_is_open PROTO_N ((ostream))
165
ostream_is_open(OStreamP ostream)
139
		PROTO_T (OStreamP ostream)
-
 
140
{
166
{
141
    return (ostream->name != NIL (CStringP));
167
    return(ostream->name != NIL(CStringP));
142
}
168
}
143
#ifdef FS_FAST
169
#ifdef FS_FAST
144
#define ostream_is_open(os) ((os)->name != NIL (CStringP))
170
#define ostream_is_open(os)	((os)->name != NIL(CStringP))
145
#endif /* defined (FS_FAST) */
171
#endif /* defined (FS_FAST) */
146
 
172
 
147
void
173
void
148
ostream_buffer PROTO_N ((ostream))
174
ostream_buffer(OStreamP ostream)
149
	       PROTO_T (OStreamP ostream)
-
 
150
{
175
{
151
    (void) setvbuf (ostream->file, NIL (CStringP), _IOFBF, (SizeT) BUFSIZ);
176
    (void)setvbuf(ostream->file, NIL(CStringP), _IOFBF, (SizeT)BUFSIZ);
152
}
177
}
153
 
178
 
154
void
179
void
155
ostream_unbuffer PROTO_N ((ostream))
180
ostream_unbuffer(OStreamP ostream)
156
		 PROTO_T (OStreamP ostream)
-
 
157
{
181
{
158
    (void) setvbuf (ostream->file, NIL (CStringP), _IONBF, (SizeT) 0);
182
    (void)setvbuf(ostream->file, NIL(CStringP), _IONBF, (SizeT)0);
159
}
183
}
160
 
184
 
161
void
185
void
162
ostream_close PROTO_N ((ostream))
186
ostream_close(OStreamP ostream)
163
	      PROTO_T (OStreamP ostream)
-
 
164
{
187
{
165
    if (fclose (ostream->file)) {
188
    if (fclose(ostream->file)) {
166
	CStringP name = cstring_duplicate (ostream_name (ostream));
189
	CStringP name = cstring_duplicate(ostream_name(ostream));
167
 
190
 
168
	THROW_VALUE (XX_ostream_write_error, name);
191
	THROW_VALUE(XX_ostream_write_error, name);
169
    }
192
    }
170
    ostream_init (ostream);
193
    ostream_init(ostream);
171
}
194
}
172
 
195
 
173
void
196
void
174
ostream_flush PROTO_N ((ostream))
197
ostream_flush(OStreamP ostream)
175
	      PROTO_T (OStreamP ostream)
-
 
176
{
198
{
177
    if (fflush (ostream->file)) {
199
    if (fflush(ostream->file)) {
178
	CStringP name = cstring_duplicate (ostream_name (ostream));
200
	CStringP name = cstring_duplicate(ostream_name(ostream));
179
 
201
 
180
	THROW_VALUE (XX_ostream_write_error, name);
202
	THROW_VALUE(XX_ostream_write_error, name);
181
    }
203
    }
182
}
204
}
183
 
205
 
184
#ifdef FS_FAST
206
#ifdef FS_FAST
185
#undef ostream_name
207
#undef ostream_name
186
#endif /* defined (FS_FAST) */
208
#endif /* defined (FS_FAST) */
187
CStringP
209
CStringP
188
ostream_name PROTO_N ((ostream))
210
ostream_name(OStreamP ostream)
189
	     PROTO_T (OStreamP ostream)
-
 
190
{
211
{
191
    return (ostream->name);
212
    return(ostream->name);
192
}
213
}
193
#ifdef FS_FAST
214
#ifdef FS_FAST
194
#define ostream_name(os) ((os)->name)
215
#define ostream_name(os)	((os)->name)
195
#endif /* defined (FS_FAST) */
216
#endif /* defined (FS_FAST) */
196
 
217
 
197
#ifdef FS_FAST
218
#ifdef FS_FAST
198
#undef ostream_gen_name
219
#undef ostream_gen_name
199
#endif /* defined (FS_FAST) */
220
#endif /* defined (FS_FAST) */
200
CStringP
221
CStringP
201
ostream_gen_name PROTO_N ((ostream))
222
ostream_gen_name(OStreamP ostream)
202
		 PROTO_T (OStreamP ostream)
-
 
203
{
223
{
204
    return (ostream->gen_name);
224
    return(ostream->gen_name);
205
}
225
}
206
#ifdef FS_FAST
226
#ifdef FS_FAST
207
#define ostream_gen_name(os) ((os)->gen_name)
227
#define ostream_gen_name(os)	((os)->gen_name)
208
#endif /* defined (FS_FAST) */
228
#endif /* defined (FS_FAST) */
209
 
229
 
210
#ifdef FS_FAST
230
#ifdef FS_FAST
211
#undef ostream_line
231
#undef ostream_line
212
#endif /* defined (FS_FAST) */
232
#endif /* defined (FS_FAST) */
213
unsigned
233
unsigned
214
ostream_line PROTO_N ((ostream))
234
ostream_line(OStreamP ostream)
215
	     PROTO_T (OStreamP ostream)
-
 
216
{
235
{
217
    return (ostream->line);
236
    return(ostream->line);
218
}
237
}
219
#ifdef FS_FAST
238
#ifdef FS_FAST
220
#define ostream_line(os) ((os)->line)
239
#define ostream_line(os)	((os)->line)
221
#endif /* defined (FS_FAST) */
240
#endif /* defined (FS_FAST) */
222
 
241
 
223
void
242
void
224
write_newline PROTO_N ((ostream))
243
write_newline(OStreamP ostream)
225
	      PROTO_T (OStreamP ostream)
-
 
226
{
244
{
227
    ostream->line ++;
245
    ostream->line++;
228
    (void) putc ('\n', ostream->file);
246
    (void)putc('\n', ostream->file);
229
    OSTREAM_WRITE_ERROR_CHECK (ostream);
247
    OSTREAM_WRITE_ERROR_CHECK(ostream);
230
}
248
}
231
 
249
 
232
void
250
void
233
write_tab PROTO_N ((ostream))
-
 
234
	  PROTO_T (OStreamP ostream)
251
write_tab(OStreamP ostream)
235
{
252
{
236
    (void) putc ('\t', ostream->file);
253
    (void)putc('\t', ostream->file);
237
    OSTREAM_WRITE_ERROR_CHECK (ostream);
254
    OSTREAM_WRITE_ERROR_CHECK(ostream);
238
}
255
}
239
 
256
 
240
void
257
void
241
write_byte PROTO_N ((ostream, c))
258
write_byte(OStreamP ostream, ByteT c)
242
	   PROTO_T (OStreamP ostream X
-
 
243
		    ByteT    c)
-
 
244
{
259
{
245
    if (c == '\n') {
260
    if (c == '\n') {
246
	ostream->line ++;
261
	ostream->line++;
247
    }
262
    }
248
    (void) putc ((int) c, ostream->file);
263
    (void)putc((int)c, ostream->file);
249
    OSTREAM_WRITE_ERROR_CHECK (ostream);
264
    OSTREAM_WRITE_ERROR_CHECK(ostream);
250
}
265
}
251
 
266
 
252
void
267
void
253
write_char PROTO_N ((ostream, c))
268
write_char(OStreamP ostream, char c)
254
	   PROTO_T (OStreamP ostream X
-
 
255
		    char     c)
-
 
256
{
269
{
257
    if (c == '\n') {
270
    if (c == '\n') {
258
	ostream->line ++;
271
	ostream->line++;
259
    }
272
    }
260
    (void) putc ((int) c, ostream->file);
273
    (void)putc((int)c, ostream->file);
261
    OSTREAM_WRITE_ERROR_CHECK (ostream);
274
    OSTREAM_WRITE_ERROR_CHECK(ostream);
262
}
275
}
263
 
276
 
264
void
277
void
265
write_escaped_char PROTO_N ((ostream, c))
278
write_escaped_char(OStreamP ostream, char c)
266
		   PROTO_T (OStreamP ostream X
-
 
267
			    char     c)
-
 
268
{
279
{
269
    switch (c) {
280
    switch (c) {
270
      case '\0':
281
      case '\0':
271
	(void) fputs ("\\0", ostream->file);
282
	(void)fputs("\\0", ostream->file);
272
	break;
283
	break;
273
      case '\f':
284
      case '\f':
274
	(void) fputs ("\\f", ostream->file);
285
	(void)fputs("\\f", ostream->file);
275
	break;
286
	break;
276
      case '\n':
287
      case '\n':
277
	ostream->line ++;
288
	ostream->line++;
278
	(void) fputc ('\n', ostream->file);
289
	(void)fputc('\n', ostream->file);
279
	break;
290
	break;
280
      case '\r':
291
      case '\r':
281
	(void) fputs ("\\r", ostream->file);
292
	(void)fputs("\\r", ostream->file);
282
	break;
293
	break;
283
      case '\t':
294
      case '\t':
284
	(void) fputc ('\t', ostream->file);
295
	(void)fputc('\t', ostream->file);
285
	break;
296
	break;
286
      case '\\':
297
      case '\\':
287
	(void) fputs ("\\\\", ostream->file);
298
	(void)fputs("\\\\", ostream->file);
288
	break;
299
	break;
289
      default:
300
      default:
290
	if (syntax_is_printable (c)) {
301
	if (syntax_is_printable(c)) {
291
	    (void) fputc ((int) c, ostream->file);
302
	    (void)fputc((int)c, ostream->file);
292
	} else {
303
	} else {
293
	    (void) fprintf (ostream->file, "\\x%02x",
304
	    (void)fprintf(ostream->file, "\\x%02x",
294
			    (unsigned) (unsigned char) c);
305
			  (unsigned)(unsigned char)c);
295
	}
306
	}
296
    }
307
    }
297
    OSTREAM_WRITE_ERROR_CHECK (ostream);
308
    OSTREAM_WRITE_ERROR_CHECK(ostream);
298
}
309
}
299
 
310
 
300
void
311
void
301
write_int PROTO_N ((ostream, i))
312
write_int(OStreamP ostream, int i)
302
	  PROTO_T (OStreamP ostream X
-
 
303
		   int      i)
-
 
304
{
313
{
305
    (void) fprintf (ostream->file, "%d", i);
314
    (void)fprintf(ostream->file, "%d", i);
306
    OSTREAM_WRITE_ERROR_CHECK (ostream);
315
    OSTREAM_WRITE_ERROR_CHECK(ostream);
307
}
316
}
308
 
317
 
309
void
318
void
310
write_unsigned PROTO_N ((ostream, i))
319
write_unsigned(OStreamP ostream, unsigned i)
311
	       PROTO_T (OStreamP ostream X
-
 
312
			unsigned i)
-
 
313
{
320
{
314
    (void) fprintf (ostream->file, "%u", i);
321
    (void)fprintf(ostream->file, "%u", i);
315
    OSTREAM_WRITE_ERROR_CHECK (ostream);
322
    OSTREAM_WRITE_ERROR_CHECK(ostream);
316
}
323
}
317
 
324
 
318
void
325
void
319
write_cstring PROTO_N ((ostream, cstring))
326
write_cstring(OStreamP ostream, CStringP cstring)
320
	      PROTO_T (OStreamP ostream X
-
 
321
		       CStringP cstring)
-
 
322
{
327
{
323
    CStringP tmp = cstring;
328
    CStringP tmp = cstring;
324
 
329
 
325
    while (*tmp) {
330
    while (*tmp) {
326
	if (*tmp ++ == '\n') {
331
	if (*tmp++ == '\n') {
327
	    ostream->line ++;
332
	    ostream->line++;
328
	}
333
	}
329
    }
334
    }
330
    (void) fputs (cstring, ostream->file);
335
    (void)fputs(cstring, ostream->file);
331
    OSTREAM_WRITE_ERROR_CHECK (ostream);
336
    OSTREAM_WRITE_ERROR_CHECK(ostream);
332
}
337
}
333
 
338
 
334
void
339
void
335
write_bytes PROTO_N ((ostream, bytes, length))
340
write_bytes(OStreamP ostream, ByteP bytes, unsigned length)
336
	    PROTO_T (OStreamP ostream X
-
 
337
		     ByteP    bytes X
-
 
338
		     unsigned length)
-
 
339
{
341
{
340
    unsigned tmp_length = length;
342
    unsigned tmp_length = length;
341
    ByteP    tmp_bytes  = bytes;
343
    ByteP    tmp_bytes  = bytes;
342
 
344
 
343
    while (tmp_length --) {
345
    while (tmp_length--) {
344
	if (*tmp_bytes ++ == '\n') {
346
	if (*tmp_bytes++ == '\n') {
345
	    ostream->line ++;
347
	    ostream->line++;
346
	}
348
	}
347
    }
349
    }
348
    (void) fwrite ((GenericP) bytes, sizeof (ByteT), (SizeT) length,
350
    (void)fwrite((GenericP)bytes, sizeof(ByteT), (SizeT)length,
349
		   ostream->file);
351
		 ostream->file);
350
    OSTREAM_WRITE_ERROR_CHECK (ostream);
352
    OSTREAM_WRITE_ERROR_CHECK(ostream);
351
}
353
}
352
 
354
 
353
void
355
void
354
write_chars PROTO_N ((ostream, chars, length))
356
write_chars(OStreamP ostream, CStringP chars, unsigned length)
355
	    PROTO_T (OStreamP ostream X
-
 
356
		     CStringP chars X
-
 
357
		     unsigned length)
-
 
358
{
357
{
359
    while (length --) {
358
    while (length--) {
360
	write_char (ostream, *chars ++);
359
	write_char(ostream, *chars++);
361
    }
360
    }
362
}
361
}
363
 
362
 
364
void
363
void
365
write_escaped_chars PROTO_N ((ostream, chars, length))
364
write_escaped_chars(OStreamP ostream, CStringP chars, unsigned length)
366
		    PROTO_T (OStreamP ostream X
-
 
367
			     CStringP chars X
-
 
368
			     unsigned length)
-
 
369
{
365
{
370
    while (length --) {
366
    while (length--) {
371
	write_escaped_char (ostream, *chars ++);
367
	write_escaped_char(ostream, *chars++);
372
    }
368
    }
373
}
369
}
374
 
370
 
375
void
371
void
376
write_system_error PROTO_N ((ostream))
372
write_system_error(OStreamP ostream)
377
		   PROTO_T (OStreamP ostream)
-
 
378
{
373
{
379
#if (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST))
374
#if (defined(FS_STRERROR) || defined(FS_SYS_ERRLIST))
380
# ifdef FS_STRERROR
375
# ifdef FS_STRERROR
381
    CStringP message = strerror (errno);
376
    CStringP message = strerror(errno);
382
# else
377
# else
383
    CStringP message;
378
    CStringP message;
384
 
379
 
385
    if ((errno >= 0) && (errno < sys_nerr)) {
380
    if ((errno >= 0) && (errno < sys_nerr)) {
386
	message = sys_errlist [errno];
381
	message = sys_errlist[errno];
387
    } else {
382
    } else {
388
	message = "unknown error";
383
	message = "unknown error";
389
    }
384
    }
390
# endif /* defined (FS_STRERROR) */
385
# endif /* defined (FS_STRERROR) */
391
    write_cstring (ostream, message);
386
    write_cstring(ostream, message);
392
#else
387
#else
393
    write_cstring (ostream, "error ");
388
    write_cstring(ostream, "error ");
394
    write_int (ostream, errno);
389
    write_int(ostream, errno);
395
#endif /* (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST)) */
390
#endif /* (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST)) */
396
}
391
}
397
 
392
 
398
void
393
void
399
write_pointer PROTO_N ((ostream, pointer))
394
write_pointer(OStreamP ostream, GenericP pointer)
400
	      PROTO_T (OStreamP ostream X
-
 
401
		       GenericP pointer)
-
 
402
{
395
{
403
    (void) fprintf (ostream->file, "%p", pointer);
396
    (void)fprintf(ostream->file, "%p", pointer);
404
    OSTREAM_WRITE_ERROR_CHECK (ostream);
397
    OSTREAM_WRITE_ERROR_CHECK(ostream);
405
}
398
}