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