#ifndef WH_UTIL_H_3431399a_ #define WH_UTIL_H_3431399a_ #include /* * util_memopen_w(char **sp, int *lp) opens a FILE * which accumulates * everything written to it. Once the stream is closed, *sp is set to * point to the accumulated data; *lp is set to its length. sp and/or * lp may be nil, in which case that is not returned. No terminating * NUL is implicit. After the open and before the close, *sp and *lp * (when sp resp. lp non-nil) are unspecified, may point to anything * or nothing, and may be modified at any moment. If sp is non-nil, * the final value of *sp is memory suitable for handing directly to * free(). */ extern FILE *util_memopen_w(char **, int *); /* * util_memopen_r opens a block of memory for reading. The returned * FILE * reads from the block of memory, showing EOF once the end of * the block is reached. */ extern FILE *util_memopen_r(const char *, int); /* * util_teeopen_r(rf,tf,flags) returns a FILE * that, when read from, * reads from rf and returns the data read, but, as a side effect, a * copy of everything read is written to tf. (Because of buffering, * tf may receive data that hasn't yet been returned by the tee * streem.) * * flags contains flag bits: * * TEE_F_CLOSE_R * If this flag bit is set, closing the returned stream * automatically closes rf. By default, rf is left * untouched when the tee streem is closed. * TEE_F_CLOSE_TEE * If this flag bit is set, closing the returned stream * automatically closes tf. By default, tf is left * untouched when the tee streem is closed. * * util_teeopen_r returns nil if it finds an unrecognized bit set in * flags. */ extern FILE *util_teeopen_r(FILE *, FILE *, unsigned int); #define TEE_F_CLOSE_R 0x00000001 #define TEE_F_CLOSE_TEE 0x00000002 /* * util_teeopen_w(fa,fb,flags) returns a FILE * that, when written to, * writes the data to both fa and fb. (Because of buffering, these * writes may be delayed.) * * flags contains flag bits: * * TEE_F_CLOSE_A * If this flag bit is set, closing the returned stream * automatically closes fa. By default, fa is left * untouched when the tee streem is closed. * TEE_F_CLOSE_B * If this flag bit is set, closing the returned stream * automatically closes fb. By default, fb is left * untouched when the tee streem is closed. * * util_teeopen_w returns nil if it finds an unrecognized bit set in * flags. */ extern FILE *util_teeopen_w(FILE *, FILE *, unsigned int); #define TEE_F_CLOSE_A 0x00000001 #define TEE_F_CLOSE_B 0x00000002 #endif