Mercurial > trustbridge
annotate common/strhelp.c @ 192:103daf2d39c0
Added some content and a close button to the help dialog.
author | Raimund Renkert <rrenkert@intevation.de> |
---|---|
date | Wed, 26 Mar 2014 12:22:09 +0100 |
parents | 4def8b263dd3 |
children | c596568fa45b |
rev | line source |
---|---|
134 | 1 #include <ctype.h> |
131
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
2 #include <stdbool.h> |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
3 #include <stdio.h> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
4 #include <stdlib.h> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
5 #include <string.h> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
6 #include <assert.h> |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
7 |
160
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
8 #include <polarssl/base64.h> |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
9 |
143
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
10 /* Remarks regarding the "Flawfinder: ignore" comments in this file: |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
11 * |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
12 * - strlen: |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
13 * |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
14 * It's true that strlen might crash if input is not null |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
15 * terminated. But by design there is not safe way to get the |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
16 * length of an string in C, and defining an additional length |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
17 * parameter for string parameter will only transfere the problem to |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
18 * the caller. |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
19 */ |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
20 |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
21 static void |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
22 out_of_core(void) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
23 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
24 fputs("\nfatal: out of memory\n", stderr); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
25 exit(2); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
26 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
27 void * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
28 xmalloc( size_t n ) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
29 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
30 void *p = malloc( n ); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
31 if( !p ) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
32 out_of_core(); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
33 return p; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
34 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
35 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
36 void * |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
37 xrealloc( void *a, size_t n ) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
38 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
39 void *p = realloc( a, n ); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
40 if( !p ) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
41 out_of_core(); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
42 return p; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
43 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
44 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
45 char * |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
46 xstrndup( const char *string, const size_t len ) |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
47 { |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
48 char *p = xmalloc( len + 1 ); |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
49 memcpy( p, string, len ); |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
50 p[len] = '\0'; |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
51 return p; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
52 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
53 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
54 unsigned int |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
55 strv_length (char **str_array) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
56 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
57 unsigned int i = 0; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
58 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
59 if (!str_array) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
60 return 0; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
61 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
62 while (str_array[i]) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
63 ++i; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
64 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
65 return i; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
66 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
67 |
116
c602d8cfa619
Refactoring: unified naming of string vector functions.
Sascha Wilde <wilde@intevation.de>
parents:
91
diff
changeset
|
68 void strv_append (char ***pArray, const char *string, const size_t len) |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
69 { |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
70 unsigned int old_len = 0; |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
71 |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
72 if (!*pArray) { |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
73 *pArray = xmalloc(2 * sizeof(char*)); |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
74 (*pArray)[0] = xstrndup(string, len); |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
75 (*pArray)[1] = NULL; |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
76 return; |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
77 } |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
78 old_len = strv_length(*pArray); |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
79 *pArray = xrealloc(*pArray, sizeof(char**) * (old_len + 2)); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
80 |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
81 (*pArray)[old_len] = xstrndup(string, len); |
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
82 (*pArray)[old_len + 1] = NULL; |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
83 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
84 |
91
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
85 void |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
86 str_append_str(char **pDst, size_t *dst_len, const char *appendage, const size_t len) |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
87 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
88 if (!appendage) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
89 return; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
90 |
91
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
91 if (!(*pDst)) { |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
92 *pDst = xstrndup(appendage, len); |
91
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
93 *dst_len = len; |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
94 } else { |
91
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
95 size_t new_size = (*dst_len) + len + 1; |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
96 char *p_old = *pDst; |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
97 *pDst = xmalloc(new_size); |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
98 strncpy(*pDst, p_old, *dst_len); |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
99 strncpy(*pDst + *dst_len, appendage, len); |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
100 *dst_len = new_size - 1; |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
101 (*pDst)[*dst_len] = '\0'; |
80ab2168760f
Also add output size handling to str_append_str
Andre Heinecke <aheinecke@intevation.de>
parents:
63
diff
changeset
|
102 free (p_old); |
60
6acb1dae6185
Use strn functions and improve error handling.
Andre Heinecke <aheinecke@intevation.de>
parents:
59
diff
changeset
|
103 } |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
104 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
105 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
106 void |
116
c602d8cfa619
Refactoring: unified naming of string vector functions.
Sascha Wilde <wilde@intevation.de>
parents:
91
diff
changeset
|
107 strv_free (char **str_array) |
59
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
108 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
109 if (str_array) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
110 { |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
111 int i; |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
112 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
113 for (i = 0; str_array[i] != NULL; i++) |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
114 free (str_array[i]); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
115 |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
116 free (str_array); |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
117 } |
3f6378647371
Start work on cinst. Strhelp new helpers to work with C String
Andre Heinecke <aheinecke@intevation.de>
parents:
diff
changeset
|
118 } |
131
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
119 |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
120 bool |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
121 str_equal (char *s1, char *s2) |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
122 { |
143
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
123 size_t l1 = strlen(s1); /* Flawfinder: ignore */ |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
124 size_t l2 = strlen(s2); /* Flawfinder: ignore */ |
131
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
125 if ((l1 == l2) && |
136
5fa4791d6d0e
Replaced unnecessary strncmp with strcmp.
Sascha Wilde <wilde@intevation.de>
parents:
135
diff
changeset
|
126 (strcmp(s1, s2) == 0)) |
131
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
127 return true; |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
128 else |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
129 return false; |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
130 } |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
131 |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
132 bool |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
133 str_starts_with (char *s1, char *s2) |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
134 { |
143
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
135 size_t l2 = strlen(s2); /* Flawfinder: ignore */ |
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
136 if (strncmp(s1, s2, l2) == 0) |
131
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
137 return true; |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
138 else |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
139 return false; |
9104b1b2e4da
Added string comparison functions.
Sascha Wilde <wilde@intevation.de>
parents:
116
diff
changeset
|
140 } |
133
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
141 |
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
142 void |
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
143 str_trim (char **s) |
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
144 { |
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
145 size_t i; |
135
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
146 if (*s != NULL) |
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
147 { |
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
148 while (isspace(**s)) |
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
149 (*s)++; |
143
b026e6d2a161
Make flawfinder (a bit more) happy.
Sascha Wilde <wilde@intevation.de>
parents:
136
diff
changeset
|
150 i = strlen(*s); /* Flawfinder: ignore */ |
135
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
151 while (isspace((*s)[--i])) |
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
152 (*s)[i] = '\0'; |
3fb6ddd6b70d
str_trim: do nothing if *s is NULL.
Sascha Wilde <wilde@intevation.de>
parents:
134
diff
changeset
|
153 } |
133
c719d3fdbc15
Added functrion to trim white space from string.
Sascha Wilde <wilde@intevation.de>
parents:
131
diff
changeset
|
154 } |
160
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
155 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
156 int str_base64_decode(char **dst, size_t *dst_size, char *src, |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
157 size_t src_size) |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
158 { |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
159 int ret = -1; |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
160 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
161 if (!dst || *dst) { |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
162 return -1; |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
163 } |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
164 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
165 /* Check the needed size for the buffer */ |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
166 ret = base64_decode(NULL, dst_size, |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
167 (unsigned char *)src, src_size); |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
168 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
169 if (ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) { |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
170 return ret; |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
171 } |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
172 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
173 *dst = xmalloc(*dst_size); |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
174 memset (*dst, 0, *dst_size); |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
175 |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
176 ret = base64_decode((unsigned char *)*dst, dst_size, |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
177 (unsigned char *)src, src_size); |
183
4def8b263dd3
Fix str_base64_decode
Andre Heinecke <aheinecke@intevation.de>
parents:
160
diff
changeset
|
178 if (ret) { |
160
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
179 free (*dst); |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
180 *dst = NULL; |
183
4def8b263dd3
Fix str_base64_decode
Andre Heinecke <aheinecke@intevation.de>
parents:
160
diff
changeset
|
181 *dst_size = 0; |
160
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
182 } |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
183 return ret; |
bf4bfd8843bd
Add memory allocating base64 decode function
Andre Heinecke <aheinecke@intevation.de>
parents:
143
diff
changeset
|
184 } |