Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_textbuf.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 #if !defined(__OCS_TEXTBUF_H__)
34 #define __OCS_TEXTBUF_H__
35 
36 #include "ocs_list.h"
37 
38 #define OCS_TEXTBUF_MAX_ALLOC_LEN (256*1024)
39 
40 typedef struct {
42  uint8_t user_allocated:1;
43  uint8_t *buffer;
44  uint32_t buffer_length;
45  uint32_t buffer_written;
47 
48 typedef struct {
49  ocs_t *ocs;
50  ocs_list_t segment_list;
51  uint8_t extendable:1;
56 
57 extern int32_t ocs_textbuf_alloc(ocs_t *ocs, ocs_textbuf_t *textbuf, uint32_t length);
58 extern uint32_t ocs_textbuf_initialized(ocs_textbuf_t *textbuf);
59 extern int32_t ocs_textbuf_init(ocs_t *ocs, ocs_textbuf_t *textbuf, void *buffer, uint32_t length);
60 extern void ocs_textbuf_free(ocs_t *ocs, ocs_textbuf_t *textbuf);
61 extern void ocs_textbuf_putc(ocs_textbuf_t *textbuf, uint8_t c);
62 extern void ocs_textbuf_puts(ocs_textbuf_t *textbuf, char *s);
63 __attribute__((format(printf,2,3)))
64 extern void ocs_textbuf_printf(ocs_textbuf_t *textbuf, const char *fmt, ...);
65 __attribute__((format(printf,2,0)))
66 extern void ocs_textbuf_vprintf(ocs_textbuf_t *textbuf, const char *fmt, va_list ap);
67 extern void ocs_textbuf_buffer(ocs_textbuf_t *textbuf, uint8_t *buffer, uint32_t buffer_length);
68 extern void ocs_textbuf_copy(ocs_textbuf_t *textbuf, uint8_t *buffer, uint32_t buffer_length);
69 extern int32_t ocs_textbuf_remaining(ocs_textbuf_t *textbuf);
70 extern void ocs_textbuf_reset(ocs_textbuf_t *textbuf);
71 extern uint8_t *ocs_textbuf_get_buffer(ocs_textbuf_t *textbuf);
72 extern int32_t ocs_textbuf_get_length(ocs_textbuf_t *textbuf);
73 extern int32_t ocs_textbuf_get_written(ocs_textbuf_t *textbuf);
74 extern uint8_t *ocs_textbuf_ext_get_buffer(ocs_textbuf_t *textbuf, uint32_t idx);
75 extern int32_t ocs_textbuf_ext_get_length(ocs_textbuf_t *textbuf, uint32_t idx);
76 extern int32_t ocs_textbuf_ext_get_written(ocs_textbuf_t *textbuf, uint32_t idx);
77 
78 #endif // __OCS_TEXTBUF_H__
int32_t ocs_textbuf_get_length(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:48
int32_t ocs_textbuf_ext_get_length(ocs_textbuf_t *textbuf, uint32_t idx)
Definition: ocs_textbuf.c:75
ocs_list_t ocs_list_link_t
Definition: ocs_list.h:84
int32_t ocs_textbuf_ext_get_written(ocs_textbuf_t *textbuf, uint32_t idx)
Definition: ocs_textbuf.c:84
void ocs_textbuf_copy(ocs_textbuf_t *textbuf, uint8_t *buffer, uint32_t buffer_length)
Definition: ocs_textbuf.c:370
int32_t ocs_textbuf_remaining(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:386
int32_t ocs_textbuf_get_written(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:54
uint8_t * ocs_textbuf_get_buffer(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:42
void ocs_textbuf_free(ocs_t *ocs, ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:213
ocs_list_t segment_list
Definition: ocs_textbuf.h:50
uint32_t allocation_length
Definition: ocs_textbuf.h:52
uint8_t * ocs_textbuf_ext_get_buffer(ocs_textbuf_t *textbuf, uint32_t idx)
Definition: ocs_textbuf.c:66
const char const char va_list ap
Definition: ocs_ramlog.h:54
int32_t ocs_textbuf_init(ocs_t *ocs, ocs_textbuf_t *textbuf, void *buffer, uint32_t length)
Definition: ocs_textbuf.c:190
void ocs_textbuf_puts(ocs_textbuf_t *textbuf, char *s)
Definition: ocs_textbuf.c:325
ocs_t * ocs
Definition: ocs_textbuf.h:49
uint32_t total_allocation_length
Definition: ocs_textbuf.h:53
void ocs_textbuf_vprintf(ocs_textbuf_t *textbuf, const char *fmt, va_list ap)
Definition: ocs_textbuf.c:254
void ocs_textbuf_printf(ocs_textbuf_t *textbuf, const char *fmt,...)
Helper function to dump message.
Definition: ocs_textbuf.c:238
ocs_list_link_t link
Definition: ocs_textbuf.h:41
void ocs_textbuf_putc(ocs_textbuf_t *textbuf, uint8_t c)
Definition: ocs_textbuf.c:308
void ocs_textbuf_buffer(ocs_textbuf_t *textbuf, uint8_t *buffer, uint32_t buffer_length)
Definition: ocs_textbuf.c:335
__attribute__((format(printf, 3, 4))) extern void ocs_ddump_value(ocs_textbuf_t *textbuf
void ocs_textbuf_reset(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:406
int32_t ocs_textbuf_alloc(ocs_t *ocs, ocs_textbuf_t *textbuf, uint32_t length)
Definition: ocs_textbuf.c:105
uint32_t ocs_textbuf_initialized(ocs_textbuf_t *textbuf)
Definition: ocs_textbuf.c:94
const char const char * fmt
Definition: ocs_ddump.h:54
uint32_t max_allocation_length
Definition: ocs_textbuf.h:54