Line data Source code
1 : #include "mem.h"
2 :
3 1332 : Return memory_string_length(
4 : const memory *memory_structure,
5 : size_t *length_out)
6 : {
7 : /** Return status
8 : * The status that will be passed to return() before exiting
9 : * By default, the function worked without errors
10 : */
11 1332 : Return status = SUCCESS;
12 :
13 1332 : if(memory_structure == NULL || length_out == NULL)
14 : {
15 0 : slog(ERROR,"Memory management; Invalid arguments for string length helper");
16 0 : status = FAILURE;
17 1332 : } else if(memory_structure->length == 0){
18 154 : *length_out = 0;
19 1178 : } else if(memory_structure->data == NULL){
20 0 : *length_out = 0;
21 : } else {
22 1178 : const unsigned char *bytes = (const unsigned char *)memory_structure->data;
23 1178 : size_t index = 0;
24 :
25 1370294 : for(; index < memory_structure->length; ++index)
26 : {
27 1370294 : if(bytes[index] == '\0')
28 : {
29 1178 : break;
30 : }
31 : }
32 :
33 1178 : *length_out = index;
34 : }
35 :
36 1332 : provide(status);
37 : }
|