1/* @(#) interface to memory-buffer printf API 2 * 3 * Copyright 2008-2011 Pavel V. Cherenkov (pcherenkov@gmail.com) 4 * 5 * This file is part of udpxy. 6 * 7 * udpxy is free software: you can redistribute it and/or modify 8 * it under the terms of the GNU General Public License as published by 9 * the Free Software Foundation, either version 3 of the License, or 10 * (at your option) any later version. 11 * 12 * udpxy is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU General Public License for more details. 16 * 17 * You should have received a copy of the GNU General Public License 18 * along with udpxy. If not, see <http://www.gnu.org/licenses/>. 19 */ 20 21#ifndef PRBUF_H_12272007bsl_ 22#define PRBUF_H_12272007bsl_ 23 24typedef struct printbuf* prbuf_t; 25 26#ifdef __cplusplus 27 extern "C" { 28#endif 29 30 31/* create/open print buffer 32 * 33 * @param pb - address of the new print buffer 34 * @param buf - (pre-allocated) memory buffer 35 * to associate new printbuffer with 36 * @param n - size (in bytes) of the memory buffer 37 * 38 * @return 0 if success: contents of pb are updated with 39 * the address on new printbuffer; -1 otherwise 40 */ 41int prbuf_open( prbuf_t* pb, void* buf, size_t n ); 42 43 44/* close print buffer 45 * 46 * @param pb - print buffer to close 47 * 48 * @return 0 if success, -1 otherwise 49 */ 50int prbuf_close( prbuf_t pb ); 51 52 53/* write a formatted string into the print buffer, 54 * beginning at the current position (each write 55 * advances the position appropriately) 56 * 57 * @param - destination print buffer 58 * @param - printf-style format string 59 * 60 * @return 0 if end of buffer has been reached, 61 * -1 in case of error, 62 * n > 0, where n is the number of characters written 63 * into the buffer (not including trailing zero character) 64 */ 65int prbuf_printf( prbuf_t pb, const char* format, ... ); 66 67 68/* @ return length of the text inside the buffer 69 * NOT including the termination zero character 70 * 71 */ 72size_t prbuf_len( prbuf_t pb ); 73 74 75/* set current position to the beginning of the print buffer 76 * 77 * @param pb - destination print buffer 78 */ 79void prbuf_rewind( prbuf_t pb ); 80 81#ifdef __cplusplus 82} 83#endif 84 85#endif /* PRBUF_H_12272007bsl_ */ 86 87/* __EOF__ */ 88 89