Rev 3685 | Rev 3886 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3685 | Rev 3846 | ||
---|---|---|---|
Line 28... | Line 28... | ||
28 | 28 | ||
29 | /** @addtogroup net |
29 | /** @addtogroup net |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | 32 | ||
33 | /** |
- | |
34 | * @file |
33 | /** @file |
- | 34 | * A character string with measured length implementation file. |
|
- | 35 | * @see measured_strings.h |
|
35 | */ |
36 | */ |
36 | 37 | ||
37 | #include <errno.h> |
38 | #include <errno.h> |
38 | #include <malloc.h> |
39 | #include <malloc.h> |
39 | #include <stdio.h> |
40 | #include <stdio.h> |
40 | #include <string.h> |
41 | #include <string.h> |
41 | #include <unistd.h> |
42 | #include <unistd.h> |
- | 43 | ||
42 | #include <ipc/ipc.h> |
44 | #include <ipc/ipc.h> |
43 | 45 | ||
44 | #include "err.h" |
46 | #include "err.h" |
45 | #include "measured_strings.h" |
47 | #include "measured_strings.h" |
46 | #include "modules.h" |
48 | #include "modules.h" |
47 | 49 | ||
- | 50 | /** Computes the lengths of the measured strings in the given array. |
|
- | 51 | * @param strings The measured strings array to be processed. Input parameter. |
|
- | 52 | * @param count The measured strings array size. Input parameter. |
|
- | 53 | * @returns The computed sizes array. |
|
- | 54 | * @returns NULL if there is no memory left. |
|
- | 55 | */ |
|
48 | size_t * prepare_lengths( measured_string_ref strings, size_t count ); |
56 | size_t * prepare_lengths( const measured_string_ref strings, size_t count ); |
49 | 57 | ||
50 | measured_string_ref measured_string_create_bulk( const char * string, size_t length ){ |
58 | measured_string_ref measured_string_create_bulk( const char * string, size_t length ){ |
51 | measured_string_ref new; |
59 | measured_string_ref new; |
52 | 60 | ||
53 | if( length == 0 ){ |
61 | if( length == 0 ){ |
Line 55... | Line 63... | ||
55 | } |
63 | } |
56 | new = ( measured_string_ref ) malloc( sizeof( measured_string_t ) + ( sizeof( char ) * ( length + 1 ))); |
64 | new = ( measured_string_ref ) malloc( sizeof( measured_string_t ) + ( sizeof( char ) * ( length + 1 ))); |
57 | if( ! new ) return NULL; |
65 | if( ! new ) return NULL; |
58 | new->length = length; |
66 | new->length = length; |
59 | new->value = (( char * ) new ) + sizeof( measured_string_t ); |
67 | new->value = (( char * ) new ) + sizeof( measured_string_t ); |
- | 68 | // append terminating zero explicitly - to be safe |
|
60 | memcpy( new->value, string, new->length + 1 ); |
69 | memcpy( new->value, string, new->length ); |
- | 70 | new->value[ new->length ] = '\0'; |
|
61 | return new; |
71 | return new; |
62 | } |
72 | } |
63 | 73 | ||
64 | int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ){ |
74 | int measured_strings_receive( measured_string_ref * strings, char ** data, size_t count ){ |
65 | ERROR_DECLARE; |
75 | ERROR_DECLARE; |
Line 115... | Line 125... | ||
115 | } |
125 | } |
116 | free( lengths ); |
126 | free( lengths ); |
117 | return EOK; |
127 | return EOK; |
118 | } |
128 | } |
119 | 129 | ||
120 | int measured_strings_reply( measured_string_ref strings, size_t count ){ |
130 | int measured_strings_reply( const measured_string_ref strings, size_t count ){ |
121 | ERROR_DECLARE; |
131 | ERROR_DECLARE; |
122 | 132 | ||
123 | size_t * lengths; |
133 | size_t * lengths; |
124 | int index; |
134 | int index; |
125 | size_t length; |
135 | size_t length; |
Line 191... | Line 201... | ||
191 | } |
201 | } |
192 | free( lengths ); |
202 | free( lengths ); |
193 | return EOK; |
203 | return EOK; |
194 | } |
204 | } |
195 | 205 | ||
196 | int measured_strings_send( int phone, measured_string_ref strings, size_t count ){ |
206 | int measured_strings_send( int phone, const measured_string_ref strings, size_t count ){ |
197 | ERROR_DECLARE; |
207 | ERROR_DECLARE; |
198 | 208 | ||
199 | size_t * lengths; |
209 | size_t * lengths; |
200 | int index; |
210 | int index; |
201 | 211 | ||
Line 215... | Line 225... | ||
215 | } |
225 | } |
216 | } |
226 | } |
217 | return EOK; |
227 | return EOK; |
218 | } |
228 | } |
219 | 229 | ||
220 | size_t * prepare_lengths( measured_string_ref strings, size_t count ){ |
230 | size_t * prepare_lengths( const measured_string_ref strings, size_t count ){ |
221 | size_t * lengths; |
231 | size_t * lengths; |
222 | int index; |
232 | int index; |
223 | size_t length; |
233 | size_t length; |
224 | 234 | ||
225 | lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |
235 | lengths = ( size_t * ) malloc( sizeof( size_t ) * ( count + 1 )); |