#ifndef _STDIO_UTIL_H_deb75da3_ #define _STDIO_UTIL_H_deb75da3_ /* This file is in the public domain. */ #include /* * Stdio-related utilities. */ /* * fopen_alloc() returns a stream which can be written to. Stuff * written is remembered; when the stream is closed, the accumulated * string and its length are written through the pointers passed to * fopen_alloc(). Either pointer may be nil, in which case that * information is not returned; if the string pointer is not wanted, * the bytes are not actually remembered, since they aren't needed. * (Actually, the pointers may both be nil, but that is not a very * useful case.) * * No automatic trailing \0 is provided; if you want a trailing \0, you * must write one to the stream. */ extern FILE *fopen_alloc(char **, int *); /* * Open a block of data for read. The return FILE * is a read-only * stream open on the data (which is passed as pointer-and-length; * 0x00 octets in it have no particular significance). */ extern FILE *fopen_rstr(const char *, int); /* * Returns a data-sink stream. This is a write-only stream which * accept anything and throws it away - a stdio analog of /dev/null. */ extern FILE *fopen_null(void); /* * Returns the next input character from the argument stream, but * ungetc()s it so that it is effectively not read. (If EOF is read, * no attempt is made to ungetc() it.) */ extern int peekc(FILE *); /* * Returns a stream which, on write, passes data to the argument * stream, but with each line bracketed by the two strings: the first * string, the line's contents, and the second string. The fourth * argument is flag bits: * * FWB_NOTEMPTY Don't bracket zero-length lines. * * FWB_CLOSE When the wrapper stream is closed, close the * inner stream as well. * * FWB_COPY Normally, the argument strings must remain * valid for the lifetime of the returned stream. * When FWB_COPY is specified, they need not * remain valid past the time fopen_w_bracket() * returns; copies will be made as necessary. */ #define FWB_NOTEMPTY 0x00000001 #define FWB_CLOSE 0x00000002 #define FWB_COPY 0x00000004 extern FILE *fopen_w_bracket(FILE *, const char *, const char *, unsigned int); #endif