1 /*
2  * libEtPan! -- a mail stuff library
3  *
4  * Copyright (C) 2001, 2002 - DINH Viet Hoa
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. Neither the name of the libEtPan! project nor the names of its
16  *    contributors may be used to endorse or promote products derived
17  *    from this software without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20  * 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 REGENTS OR CONTRIBUTORS BE LIABLE
23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * $Id$
34  */
35 
36 #ifndef __MMAP_STRING_H__
37 
38 #define __MMAP_STRING_H__
39 
40 #include <sys/types.h>
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 /*
47 #define TMPDIR "/tmp"
48 */
49 
50 typedef struct _MMAPString MMAPString;
51 
52 struct _MMAPString
53 {
54   char * str;
55   size_t len;
56   size_t allocated_len;
57   int fd;
58   size_t mmapped_size;
59   /*
60   char * old_non_mmapped_str;
61   */
62 };
63 
64 /* configure location of mmaped files */
65 
66 void mmap_string_set_tmpdir(char * directory);
67 
68 /* Strings
69  */
70 
71 MMAPString * mmap_string_new (const char * init);
72 
73 MMAPString * mmap_string_new_len (const char * init,
74 				  size_t len);
75 
76 MMAPString * mmap_string_sized_new (size_t dfl_size);
77 
78 void mmap_string_free (MMAPString * string);
79 
80 MMAPString * mmap_string_assign (MMAPString * string,
81 				 const char * rval);
82 
83 MMAPString * mmap_string_truncate (MMAPString *string,
84 				   size_t len);
85 
86 MMAPString * mmap_string_set_size (MMAPString * string,
87 				   size_t len);
88 
89 MMAPString * mmap_string_insert_len (MMAPString * string,
90 				     size_t pos,
91 				     const char * val,
92 				     size_t len);
93 
94 MMAPString * mmap_string_append (MMAPString * string,
95 				 const char * val);
96 
97 MMAPString * mmap_string_append_len (MMAPString * string,
98 				     const char * val,
99 				     size_t len);
100 
101 MMAPString * mmap_string_append_c (MMAPString * string,
102 				   char c);
103 
104 MMAPString * mmap_string_prepend (MMAPString * string,
105 				  const char * val);
106 
107 MMAPString * mmap_string_prepend_c (MMAPString * string,
108 				    char c);
109 
110 MMAPString * mmap_string_prepend_len (MMAPString * string,
111 				      const char * val,
112 				      size_t len);
113 
114 MMAPString * mmap_string_insert (MMAPString * string,
115 				 size_t pos,
116 				 const char * val);
117 
118 MMAPString * mmap_string_insert_c (MMAPString *string,
119 				   size_t pos,
120 				   char c);
121 
122 MMAPString * mmap_string_erase(MMAPString * string,
123 			       size_t pos,
124 			       size_t len);
125 
126 void mmap_string_set_ceil(size_t ceil);
127 
128 int mmap_string_ref(MMAPString * string);
129 int mmap_string_unref(char * str);
130 
131 #ifdef __cplusplus
132 }
133 #endif
134 
135 
136 #endif /* __MMAP_STRING_H__ */
137