1 #ifndef MEMORY_STREAM_H 2 #define MEMORY_STREAM_H 3 4 /** 5 * Utility functions for memory streams. 6 */ 7 8 #include <stdio.h> 9 #include <stddef.h> 10 #include <stdbool.h> 11 12 struct memory_stream { 13 FILE *fp; 14 char *str; 15 size_t str_len; 16 }; 17 18 bool 19 memory_stream_open(struct memory_stream *m); 20 21 char * 22 memory_stream_close(struct memory_stream *m); 23 24 /** 25 * A small cleanup helper that simply 26 * calls free(memory_stream_close(m)) to avoid 27 * any dangling string pointers in cleanup/error paths. 28 */ 29 void 30 memory_stream_cleanup(struct memory_stream *m); 31 32 #endif 33