Subversion Repositories tendra.SVN

Rev

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

Rev 2 Rev 7
Line -... Line 1...
-
 
1
/*
-
 
2
 * Copyright (c) 2002-2006 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
*/
29
 
59
 
30
 
60
 
31
/**** ostream.c --- Output stream handling.
61
/**** ostream.c --- Output stream handling.
32
 *
62
 *
33
 ** Author: Steve Folkes <smf@hermes.mod.uk>
63
 ** Author: Steve Folkes <smf@hermes.mod.uk>
34
 *
64
 *
35
 **** Commentary:
65
 **** Commentary:
36
 *
66
 *
37
 * This file implements the output stream facility specified in the file
67
 * This file implements the output stream facility specified in the file
38
 * "ostream.h".  See that file for more details.
68
 * "ostream.h".  See that file for more details.
39
 *
69
 *
40
 **** Change Log:
70
 **** Change Log:
41
 * $Log: ostream.c,v $
71
 * $Log: ostream.c,v $
Line 43... Line 73...
43
 * First version to be checked into rolling release.
73
 * First version to be checked into rolling release.
44
 *
74
 *
45
 * Revision 1.2  1994/12/12  11:45:47  smf
75
 * Revision 1.2  1994/12/12  11:45:47  smf
46
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
76
 * Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
47
 * OSSG C Coding Standards.
77
 * OSSG C Coding Standards.
48
 *
78
 *
49
 * Revision 1.1.1.1  1994/07/25  16:06:11  smf
79
 * Revision 1.1.1.1  1994/07/25  16:06:11  smf
50
 * Initial import of os-interface shared files.
80
 * Initial import of os-interface shared files.
51
 *
81
 *
52
**/
82
**/
53
 
83
 
54
/****************************************************************************/
84
/****************************************************************************/
-
 
85
 
-
 
86
#include <stdio.h>
55
 
87
 
56
#include "ostream.h"
88
#include "ostream.h"
57
#include "cstring.h"
89
#include "cstring.h"
58
#include "syntax.h"
90
#include "syntax.h"
59
 
91
 
60
/*--------------------------------------------------------------------------*/
92
/*--------------------------------------------------------------------------*/
61
 
93
 
62
ExceptionP XX_ostream_write_error = EXCEPTION ("error writing to stream");
94
ExceptionP XX_ostream_write_error = EXCEPTION("error writing to stream");
63
 
95
 
64
static OStreamT			ostream_output_1 = {
96
static OStreamT			ostream_output_1 = {
65
    NIL (FILE *),
97
    NIL(FILE *),
66
    "<stdout>",
98
    "<stdout>",
67
    1
99
    1
68
};
100
};
69
static OStreamT			ostream_error_1 = {
101
static OStreamT			ostream_error_1 = {
70
    NIL (FILE *),
102
    NIL(FILE *),
71
    "<stderr>",
103
    "<stderr>",
72
    1
104
    1
73
};
105
};
74
 
106
 
75
OStreamT		 *const ostream_output = &ostream_output_1;
107
OStreamT		 *const ostream_output = &ostream_output_1;
76
OStreamT		 *const ostream_error  = &ostream_error_1;
108
OStreamT		 *const ostream_error  = &ostream_error_1;
77
 
109
 
78
/*--------------------------------------------------------------------------*/
110
/*--------------------------------------------------------------------------*/
79
 
111
 
80
#define OSTREAM_WRITE_ERROR_CHECK(ostream) \
112
#define OSTREAM_WRITE_ERROR_CHECK(ostream)\
81
if (ferror ((ostream)->file)) { \
113
    if (ferror((ostream)->file)) { \
82
    CStringP X___name = cstring_duplicate (ostream_name (ostream)); \
114
	    CStringP X___name = cstring_duplicate(ostream_name(ostream)); \
83
    THROW_VALUE (XX_ostream_write_error, X___name); \
115
	    THROW_VALUE(XX_ostream_write_error, X___name); \
84
}
116
}
85
 
117
 
86
/*--------------------------------------------------------------------------*/
118
/*--------------------------------------------------------------------------*/
87
 
119
 
88
void
120
void
89
ostream_setup PROTO_Z ()
121
ostream_setup(void)
90
{
122
{
91
    ostream_output_1.file = stdout;
123
    ostream_output_1.file = stdout;
92
    ostream_error_1.file  = stderr;
124
    ostream_error_1.file  = stderr;
93
}
125
}
94
 
126
 
95
#ifdef FS_FAST
127
#ifdef FS_FAST
96
#undef ostream_init
128
#undef ostream_init
97
#endif /* defined (FS_FAST) */
129
#endif /* defined (FS_FAST) */
98
void
130
void
99
ostream_init PROTO_N ((ostream))
131
ostream_init(OStreamP ostream)
100
	     PROTO_T (OStreamP ostream)
-
 
101
{
132
{
102
    ostream->name = NIL (CStringP);
133
    ostream->name = NIL(CStringP);
103
}
134
}
104
#ifdef FS_FAST
135
#ifdef FS_FAST
105
#define ostream_init(os) ((os)->name = NIL (CStringP))
136
#define ostream_init(os)	((os)->name = NIL(CStringP))
106
#endif /* defined (FS_FAST) */
137
#endif /* defined (FS_FAST) */
107
 
138
 
108
BoolT
139
BoolT
109
ostream_open PROTO_N ((ostream, name))
140
ostream_open(OStreamP ostream,		      CStringP name)
110
	     PROTO_T (OStreamP ostream X
-
 
111
		      CStringP name)
-
 
112
{
141
{
113
    if ((ostream->file = fopen (name, "w")) == NIL (FILE *)) {
142
    if ((ostream->file = fopen(name, "w")) == NIL(FILE *)) {
114
	return (FALSE);
143
	return(FALSE);
115
    }
144
    }
116
    ostream->name = name;
145
    ostream->name = name;
117
    ostream->line = 1;
146
    ostream->line = 1;
118
    (void) setvbuf (ostream->file, NIL (CStringP), _IOFBF, (SizeT) BUFSIZ);
147
   (void)setvbuf(ostream->file, NIL(CStringP), _IOFBF,(SizeT)BUFSIZ);
119
    return (TRUE);
148
    return(TRUE);
120
}
149
}
121
 
150
 
122
#ifdef FS_FAST
151
#ifdef FS_FAST
123
#undef ostream_is_open
152
#undef ostream_is_open
124
#endif /* defined (FS_FAST) */
153
#endif /* defined (FS_FAST) */
125
BoolT
154
BoolT
126
ostream_is_open PROTO_N ((ostream))
155
ostream_is_open(OStreamP ostream)
127
		PROTO_T (OStreamP ostream)
-
 
128
{
156
{
129
    return (ostream->name != NIL (CStringP));
157
    return(ostream->name != NIL(CStringP));
130
}
158
}
131
#ifdef FS_FAST
159
#ifdef FS_FAST
132
#define ostream_is_open(os) ((os)->name != NIL (CStringP))
160
#define ostream_is_open(os)	((os)->name != NIL(CStringP))
133
#endif /* defined (FS_FAST) */
161
#endif /* defined (FS_FAST) */
134
 
162
 
135
void
163
void
136
ostream_buffer PROTO_N ((ostream))
164
ostream_buffer(OStreamP ostream)
137
	       PROTO_T (OStreamP ostream)
-
 
138
{
165
{
139
    (void) setvbuf (ostream->file, NIL (CStringP), _IOFBF, (SizeT) BUFSIZ);
166
   (void)setvbuf(ostream->file, NIL(CStringP), _IOFBF,(SizeT)BUFSIZ);
140
}
167
}
141
 
168
 
142
void
169
void
143
ostream_unbuffer PROTO_N ((ostream))
170
ostream_unbuffer(OStreamP ostream)
144
		 PROTO_T (OStreamP ostream)
-
 
145
{
171
{
146
    (void) setvbuf (ostream->file, NIL (CStringP), _IONBF, (SizeT) 0);
172
   (void)setvbuf(ostream->file, NIL(CStringP), _IONBF,(SizeT)0);
147
}
173
}
148
 
174
 
149
void
175
void
150
ostream_close PROTO_N ((ostream))
176
ostream_close(OStreamP ostream)
151
	      PROTO_T (OStreamP ostream)
-
 
152
{
177
{
153
    if (fclose (ostream->file)) {
178
    if (fclose(ostream->file)) {
154
	CStringP name = cstring_duplicate (ostream_name (ostream));
179
	CStringP name = cstring_duplicate(ostream_name(ostream));
155
 
180
 
156
	THROW_VALUE (XX_ostream_write_error, name);
181
	THROW_VALUE(XX_ostream_write_error, name);
157
    }
182
    }
158
    ostream_init (ostream);
183
    ostream_init(ostream);
159
}
184
}
160
 
185
 
161
void
186
void
162
ostream_flush PROTO_N ((ostream))
187
ostream_flush(OStreamP ostream)
163
	      PROTO_T (OStreamP ostream)
-
 
164
{
188
{
165
    if (fflush (ostream->file)) {
189
    if (fflush(ostream->file)) {
166
	CStringP name = cstring_duplicate (ostream_name (ostream));
190
	CStringP name = cstring_duplicate(ostream_name(ostream));
167
 
191
 
168
	THROW_VALUE (XX_ostream_write_error, name);
192
	THROW_VALUE(XX_ostream_write_error, name);
169
    }
193
    }
170
}
194
}
171
 
195
 
172
#ifdef FS_FAST
196
#ifdef FS_FAST
173
#undef ostream_name
197
#undef ostream_name
174
#endif /* defined (FS_FAST) */
198
#endif /* defined (FS_FAST) */
175
CStringP
199
CStringP
176
ostream_name PROTO_N ((ostream))
200
ostream_name(OStreamP ostream)
177
	     PROTO_T (OStreamP ostream)
-
 
178
{
201
{
179
    return (ostream->name);
202
    return(ostream->name);
180
}
203
}
181
#ifdef FS_FAST
204
#ifdef FS_FAST
182
#define ostream_name(os) ((os)->name)
205
#define ostream_name(os)	((os)->name)
183
#endif /* defined (FS_FAST) */
206
#endif /* defined (FS_FAST) */
184
 
207
 
185
#ifdef FS_FAST
208
#ifdef FS_FAST
186
#undef ostream_line
209
#undef ostream_line
187
#endif /* defined (FS_FAST) */
210
#endif /* defined (FS_FAST) */
188
unsigned
211
unsigned
189
ostream_line PROTO_N ((ostream))
212
ostream_line(OStreamP ostream)
190
	     PROTO_T (OStreamP ostream)
-
 
191
{
213
{
192
    return (ostream->line);
214
    return(ostream->line);
193
}
215
}
194
#ifdef FS_FAST
216
#ifdef FS_FAST
195
#define ostream_line(os) ((os)->line)
217
#define ostream_line(os)	((os)->line)
196
#endif /* defined (FS_FAST) */
218
#endif /* defined (FS_FAST) */
197
 
219
 
198
void
220
void
199
write_newline PROTO_N ((ostream))
221
write_newline(OStreamP ostream)
200
	      PROTO_T (OStreamP ostream)
-
 
201
{
222
{
202
    ostream->line ++;
223
    ostream->line++;
203
    (void) putc ('\n', ostream->file);
224
   (void)putc('\n', ostream->file);
204
    OSTREAM_WRITE_ERROR_CHECK (ostream);
225
    OSTREAM_WRITE_ERROR_CHECK(ostream);
205
}
226
}
206
 
227
 
207
void
228
void
208
write_tab PROTO_N ((ostream))
-
 
209
	  PROTO_T (OStreamP ostream)
229
write_tab(OStreamP ostream)
210
{
230
{
211
    (void) putc ('\t', ostream->file);
231
   (void)putc('\t', ostream->file);
212
    OSTREAM_WRITE_ERROR_CHECK (ostream);
232
    OSTREAM_WRITE_ERROR_CHECK(ostream);
213
}
233
}
214
 
234
 
215
void
235
void
216
write_byte PROTO_N ((ostream, c))
236
write_byte(OStreamP ostream,		    ByteT    c)
217
	   PROTO_T (OStreamP ostream X
-
 
218
		    ByteT    c)
-
 
219
{
237
{
220
    if (c == '\n') {
238
    if (c == '\n') {
221
	ostream->line ++;
239
	ostream->line++;
222
    }
240
    }
223
    (void) putc ((int) c, ostream->file);
241
   (void)putc((int)c, ostream->file);
224
    OSTREAM_WRITE_ERROR_CHECK (ostream);
242
    OSTREAM_WRITE_ERROR_CHECK(ostream);
225
}
243
}
226
 
244
 
227
void
245
void
228
write_char PROTO_N ((ostream, c))
246
write_char(OStreamP ostream,		    char     c)
229
	   PROTO_T (OStreamP ostream X
-
 
230
		    char     c)
-
 
231
{
247
{
232
    if (c == '\n') {
248
    if (c == '\n') {
233
	ostream->line ++;
249
	ostream->line++;
234
    }
250
    }
235
    (void) putc ((int) c, ostream->file);
251
   (void)putc((int)c, ostream->file);
236
    OSTREAM_WRITE_ERROR_CHECK (ostream);
252
    OSTREAM_WRITE_ERROR_CHECK(ostream);
237
}
253
}
238
 
254
 
239
void
255
void
240
write_escaped_char PROTO_N ((ostream, c))
256
write_escaped_char(OStreamP ostream,			    char     c)
241
		   PROTO_T (OStreamP ostream X
-
 
242
			    char     c)
-
 
243
{
257
{
244
    switch (c) {
258
    switch (c) {
245
      case '\0':
259
      case '\0':
246
	(void) fputs ("\\0", ostream->file);
260
	(void)fputs("\\0", ostream->file);
247
	break;
261
	break;
248
      case '\f':
262
      case '\f':
249
	(void) fputs ("\\f", ostream->file);
263
	(void)fputs("\\f", ostream->file);
250
	break;
264
	break;
251
      case '\n':
265
      case '\n':
252
	ostream->line ++;
266
	ostream->line++;
253
	(void) fputc ('\n', ostream->file);
267
	(void)fputc('\n', ostream->file);
254
	break;
268
	break;
255
      case '\r':
269
      case '\r':
256
	(void) fputs ("\\r", ostream->file);
270
	(void)fputs("\\r", ostream->file);
257
	break;
271
	break;
258
      case '\t':
272
      case '\t':
259
	(void) fputc ('\t', ostream->file);
273
	(void)fputc('\t', ostream->file);
260
	break;
274
	break;
261
      case '\\':
275
      case '\\':
262
	(void) fputs ("\\\\", ostream->file);
276
	(void)fputs("\\\\", ostream->file);
263
	break;
277
	break;
264
      default:
278
      default:
265
	if (syntax_is_printable (c)) {
279
	if (syntax_is_printable(c)) {
266
	    (void) fputc ((int) c, ostream->file);
280
	   (void)fputc((int)c, ostream->file);
267
	} else {
281
	} else {
268
	    (void) fprintf (ostream->file, "\\x%02x",
282
	   (void)fprintf(ostream->file, "\\x%02x",
269
			    (unsigned) (unsigned char) c);
283
			   (unsigned)(unsigned char)c);
270
	}
284
	}
271
    }
285
    }
272
    OSTREAM_WRITE_ERROR_CHECK (ostream);
286
    OSTREAM_WRITE_ERROR_CHECK(ostream);
273
}
287
}
274
 
288
 
275
void
289
void
276
write_int PROTO_N ((ostream, i))
290
write_int(OStreamP ostream,		   int      i)
277
	  PROTO_T (OStreamP ostream X
-
 
278
		   int      i)
-
 
279
{
291
{
280
    (void) fprintf (ostream->file, "%d", i);
292
   (void)fprintf(ostream->file, "%d", i);
281
    OSTREAM_WRITE_ERROR_CHECK (ostream);
293
    OSTREAM_WRITE_ERROR_CHECK(ostream);
282
}
294
}
283
 
295
 
284
void
296
void
285
write_unsigned PROTO_N ((ostream, i))
297
write_unsigned(OStreamP ostream,			unsigned i)
286
	       PROTO_T (OStreamP ostream X
-
 
287
			unsigned i)
-
 
288
{
298
{
289
    (void) fprintf (ostream->file, "%u", i);
299
   (void)fprintf(ostream->file, "%u", i);
290
    OSTREAM_WRITE_ERROR_CHECK (ostream);
300
    OSTREAM_WRITE_ERROR_CHECK(ostream);
291
}
301
}
292
 
302
 
293
void
303
void
294
write_cstring PROTO_N ((ostream, cstring))
304
write_cstring(OStreamP ostream,		       CStringP cstring)
295
	      PROTO_T (OStreamP ostream X
-
 
296
		       CStringP cstring)
-
 
297
{
305
{
298
    CStringP tmp = cstring;
306
    CStringP tmp = cstring;
299
 
307
 
300
    while (*tmp) {
308
    while (*tmp) {
301
	if (*tmp ++ == '\n') {
309
	if (*tmp++ == '\n') {
302
	    ostream->line ++;
310
	    ostream->line++;
303
	}
311
	}
304
    }
312
    }
305
    (void) fputs (cstring, ostream->file);
313
   (void)fputs(cstring, ostream->file);
306
    OSTREAM_WRITE_ERROR_CHECK (ostream);
314
    OSTREAM_WRITE_ERROR_CHECK(ostream);
307
}
315
}
308
 
316
 
309
void
317
void
310
write_bytes PROTO_N ((ostream, bytes, length))
318
write_bytes(OStreamP ostream,		     ByteP    bytes ,
311
	    PROTO_T (OStreamP ostream X
-
 
312
		     ByteP    bytes X
-
 
313
		     unsigned length)
319
		     unsigned length)
314
{
320
{
315
    unsigned tmp_length = length;
321
    unsigned tmp_length = length;
316
    ByteP    tmp_bytes  = bytes;
322
    ByteP    tmp_bytes  = bytes;
317
 
323
 
318
    while (tmp_length --) {
324
    while (tmp_length--) {
319
	if (*tmp_bytes ++ == '\n') {
325
	if (*tmp_bytes++ == '\n') {
320
	    ostream->line ++;
326
	    ostream->line++;
321
	}
327
	}
322
    }
328
    }
323
    (void) fwrite ((GenericP) bytes, sizeof (ByteT), (SizeT) length,
329
   (void)fwrite((GenericP)bytes, sizeof(ByteT), (SizeT)length,
324
		   ostream->file);
330
		   ostream->file);
325
    OSTREAM_WRITE_ERROR_CHECK (ostream);
331
    OSTREAM_WRITE_ERROR_CHECK(ostream);
326
}
332
}
327
 
333
 
328
void
334
void
329
write_chars PROTO_N ((ostream, chars, length))
335
write_chars(OStreamP ostream,		     CStringP chars ,
330
	    PROTO_T (OStreamP ostream X
-
 
331
		     CStringP chars X
-
 
332
		     unsigned length)
336
		     unsigned length)
333
{
337
{
334
    while (length --) {
338
    while (length--) {
335
	write_char (ostream, *chars ++);
339
	write_char(ostream, *chars++);
336
    }
340
    }
337
}
341
}
338
 
342
 
339
void
343
void
340
write_escaped_chars PROTO_N ((ostream, chars, length))
344
write_escaped_chars(OStreamP ostream,			     CStringP chars ,
341
		    PROTO_T (OStreamP ostream X
-
 
342
			     CStringP chars X
-
 
343
			     unsigned length)
345
			     unsigned length)
344
{
346
{
345
    while (length --) {
347
    while (length--) {
346
	write_escaped_char (ostream, *chars ++);
348
	write_escaped_char(ostream, *chars++);
347
    }
349
    }
348
}
350
}
349
 
351
 
350
void
352
void
351
write_system_error PROTO_N ((ostream))
353
write_system_error(OStreamP ostream)
352
		   PROTO_T (OStreamP ostream)
-
 
353
{
354
{
354
#if (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST))
355
#if (defined(FS_STRERROR) || defined(FS_SYS_ERRLIST))
355
# ifdef FS_STRERROR
356
# ifdef FS_STRERROR
356
    CStringP message = strerror (errno);
357
    CStringP message = strerror(errno);
357
# else
358
# else
358
    CStringP message;
359
    CStringP message;
359
 
360
 
360
    if ((errno >= 0) && (errno < sys_nerr)) {
361
    if ((errno >= 0) && (errno < sys_nerr)) {
361
	message = sys_errlist [errno];
362
	message = sys_errlist[errno];
362
    } else {
363
    } else {
363
	message = "unknown error";
364
	message = "unknown error";
364
    }
365
    }
365
# endif /* defined (FS_STRERROR) */
366
# endif /* defined (FS_STRERROR) */
366
    write_cstring (ostream, message);
367
    write_cstring(ostream, message);
367
#else
368
#else
368
    write_cstring (ostream, "error ");
369
    write_cstring(ostream, "error ");
369
    write_int (ostream, errno);
370
    write_int(ostream, errno);
370
#endif /* (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST)) */
371
#endif /* (defined (FS_STRERROR) || defined (FS_SYS_ERRLIST)) */
371
}
372
}
372
 
373
 
373
void
374
void
374
write_pointer PROTO_N ((ostream, pointer))
375
write_pointer(OStreamP ostream,		       GenericP pointer)
375
	      PROTO_T (OStreamP ostream X
-
 
376
		       GenericP pointer)
-
 
377
{
376
{
378
    (void) fprintf (ostream->file, "%p", pointer);
377
   (void)fprintf(ostream->file, "%p", pointer);
379
    OSTREAM_WRITE_ERROR_CHECK (ostream);
378
    OSTREAM_WRITE_ERROR_CHECK(ostream);
380
}
379
}