Thu, 11 Oct 2012 11:42:31 +0200
added some qualifiers + removed pointer alias in mergesort
ucx/buffer.c | file | annotate | diff | comparison | revisions | |
ucx/buffer.h | file | annotate | diff | comparison | revisions | |
ucx/dlist.c | file | annotate | diff | comparison | revisions | |
ucx/dlist.h | file | annotate | diff | comparison | revisions | |
ucx/list.c | file | annotate | diff | comparison | revisions | |
ucx/list.h | file | annotate | diff | comparison | revisions | |
ucx/logging.c | file | annotate | diff | comparison | revisions | |
ucx/logging.h | file | annotate | diff | comparison | revisions | |
ucx/map.c | file | annotate | diff | comparison | revisions | |
ucx/map.h | file | annotate | diff | comparison | revisions | |
ucx/string.c | file | annotate | diff | comparison | revisions | |
ucx/string.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/buffer.c Thu Oct 11 08:42:56 2012 +0200 1.2 +++ b/ucx/buffer.c Thu Oct 11 11:42:31 2012 +0200 1.3 @@ -33,8 +33,8 @@ 1.4 free(buffer); 1.5 } 1.6 1.7 -UcxBuffer *ucx_buffer_extract( 1.8 - UcxBuffer *src, size_t start, size_t length, int flags) { 1.9 +UcxBuffer *restrict ucx_buffer_extract( 1.10 + UcxBuffer *restrict src, size_t start, size_t length, int flags) { 1.11 if (length == 0) { 1.12 length = src->size - start; 1.13 } 1.14 @@ -42,7 +42,7 @@ 1.15 return NULL; 1.16 } 1.17 1.18 - UcxBuffer *dst = (UcxBuffer*) malloc(sizeof(UcxBuffer)); 1.19 + UcxBuffer *restrict dst = (UcxBuffer*) malloc(sizeof(UcxBuffer)); 1.20 if (dst) { 1.21 dst->space = malloc(length); 1.22 if (!dst->space) {
2.1 --- a/ucx/buffer.h Thu Oct 11 08:42:56 2012 +0200 2.2 +++ b/ucx/buffer.h Thu Oct 11 11:42:31 2012 +0200 2.3 @@ -30,7 +30,7 @@ 2.4 * if length is zero, the whole remaining buffer shall be extracted 2.5 * the position of the new buffer is set to zero 2.6 */ 2.7 -UcxBuffer *ucx_buffer_extract(UcxBuffer *src, 2.8 +UcxBuffer *restrict ucx_buffer_extract(UcxBuffer *restrict src, 2.9 size_t start, size_t length, int flags); 2.10 #define ucx_buffer_clone(src,flags) \ 2.11 ucx_buffer_extract(src, 0, 0, flags)
3.1 --- a/ucx/dlist.c Thu Oct 11 08:42:56 2012 +0200 3.2 +++ b/ucx/dlist.c Thu Oct 11 11:42:31 2012 +0200 3.3 @@ -1,6 +1,7 @@ 3.4 #include "dlist.h" 3.5 3.6 -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void *data) { 3.7 +UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 3.8 + copy_func fnc, void *data) { 3.9 UcxDlist *ret = NULL; 3.10 while (l != NULL) { 3.11 if (fnc != NULL) { 3.12 @@ -13,7 +14,8 @@ 3.13 return ret; 3.14 } 3.15 3.16 -int ucx_dlist_equals(UcxDlist *l1, UcxDlist *l2, cmp_func fnc, void* data) { 3.17 +int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, 3.18 + cmp_func fnc, void* data) { 3.19 if (l1 == l2) return 1; 3.20 3.21 while (l1 != NULL && l2 != NULL) { 3.22 @@ -66,7 +68,7 @@ 3.23 return nl; 3.24 } 3.25 3.26 -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2) { 3.27 +UcxDlist *ucx_dlist_concat(UcxDlist *restrict l1, UcxDlist *restrict l2) { 3.28 if (l1 == NULL) { 3.29 return l2; 3.30 } else { 3.31 @@ -77,32 +79,32 @@ 3.32 } 3.33 } 3.34 3.35 -UcxDlist *ucx_dlist_last(UcxDlist *l) { 3.36 +UcxDlist *ucx_dlist_last(const UcxDlist *l) { 3.37 if (l == NULL) return NULL; 3.38 3.39 - UcxDlist *e = l; 3.40 + const UcxDlist *e = l; 3.41 while (e->next != NULL) { 3.42 e = e->next; 3.43 } 3.44 - return e; 3.45 + return (UcxDlist*)e; 3.46 } 3.47 3.48 -UcxDlist *ucx_dlist_get(UcxDlist *l, int index) { 3.49 +UcxDlist *ucx_dlist_get(const UcxDlist *l, int index) { 3.50 if (l == NULL) return NULL; 3.51 3.52 - UcxDlist *e = l; 3.53 + const UcxDlist *e = l; 3.54 while (e->next != NULL && index > 0) { 3.55 e = e->next; 3.56 index--; 3.57 } 3.58 3.59 - return index == 0 ? e : NULL; 3.60 + return (UcxDlist*)(index == 0 ? e : NULL); 3.61 } 3.62 3.63 -size_t ucx_dlist_size(UcxDlist *l) { 3.64 +size_t ucx_dlist_size(const UcxDlist *l) { 3.65 if (l == NULL) return 0; 3.66 3.67 - UcxDlist *e = l; 3.68 + const UcxDlist *e = l; 3.69 size_t s = 1; 3.70 while (e->next != NULL) { 3.71 e = e->next; 3.72 @@ -113,14 +115,14 @@ 3.73 } 3.74 3.75 UcxDlist *ucx_dlist_sort_merge(int length, 3.76 - UcxDlist* ls, UcxDlist* rs, UcxDlist* le, UcxDlist* re, 3.77 + UcxDlist* restrict ls, UcxDlist* restrict le, UcxDlist* restrict re, 3.78 cmp_func fnc, void* data) { 3.79 UcxDlist *sorted[length]; 3.80 UcxDlist *rc, *lc; 3.81 3.82 - lc = ls; rc = rs; 3.83 + lc = ls; rc = le; 3.84 int n = 0; 3.85 - while (lc != le && rc != re) { 3.86 + while (lc && lc != le && rc != re) { 3.87 if (fnc(lc->data, rc->data, data) <= 0) { 3.88 sorted[n] = lc; 3.89 lc = lc->next; 3.90 @@ -130,12 +132,12 @@ 3.91 } 3.92 n++; 3.93 } 3.94 - while (lc != le) { 3.95 + while (lc && lc != le) { 3.96 sorted[n] = lc; 3.97 lc = lc->next; 3.98 n++; 3.99 } 3.100 - while (rc != re) { 3.101 + while (rc && rc != re) { 3.102 sorted[n] = rc; 3.103 rc = rc->next; 3.104 n++; 3.105 @@ -160,7 +162,7 @@ 3.106 UcxDlist *lc; 3.107 int ln = 1; 3.108 3.109 - UcxDlist *ls = l, *le; 3.110 + UcxDlist *restrict ls = l, *restrict le, *restrict re; 3.111 lc = ls; 3.112 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { 3.113 lc = lc->next; 3.114 @@ -168,13 +170,12 @@ 3.115 } 3.116 le = lc->next; 3.117 3.118 - UcxDlist *rs = le, *re; 3.119 - if (rs == NULL) { 3.120 + if (le == NULL) { 3.121 return l; // this list is already sorted :) 3.122 } else { 3.123 UcxDlist *rc; 3.124 int rn = 1; 3.125 - rc = rs; 3.126 + rc = le; 3.127 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { 3.128 rc = rc->next; 3.129 rn++; 3.130 @@ -190,27 +191,26 @@ 3.131 3.132 // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them 3.133 UcxDlist *sorted = ucx_dlist_sort_merge(ln+rn, 3.134 - ls, rs, le, re, 3.135 + ls, le, re, 3.136 fnc, data); 3.137 3.138 // merge sorted list with (also sorted) remainder 3.139 l = ucx_dlist_sort_merge(ln+rn+remainder_length, 3.140 - sorted, remainder, NULL, NULL, 3.141 - fnc, data); 3.142 + sorted, remainder, NULL, fnc, data); 3.143 3.144 return l; 3.145 } 3.146 } 3.147 3.148 /* dlist specific functions */ 3.149 -UcxDlist *ucx_dlist_first(UcxDlist *l) { 3.150 +UcxDlist *ucx_dlist_first(const UcxDlist *l) { 3.151 if (l == NULL) return NULL; 3.152 3.153 - UcxDlist *e = l; 3.154 + const UcxDlist *e = l; 3.155 while (e->prev != NULL) { 3.156 e = e->prev; 3.157 } 3.158 - return e; 3.159 + return (UcxDlist *)e; 3.160 } 3.161 3.162 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e) {
4.1 --- a/ucx/dlist.h Thu Oct 11 08:42:56 2012 +0200 4.2 +++ b/ucx/dlist.h Thu Oct 11 11:42:31 2012 +0200 4.3 @@ -15,25 +15,27 @@ 4.4 typedef struct UcxDlist UcxDlist; 4.5 struct UcxDlist { 4.6 void *data; 4.7 - UcxDlist *next; 4.8 - UcxDlist *prev; 4.9 + UcxDlist *restrict next; 4.10 + UcxDlist *restrict prev; 4.11 }; 4.12 4.13 -UcxDlist *ucx_dlist_clone(UcxDlist *l, copy_func fnc, void* data); 4.14 -int ucx_dlist_equals(UcxDlist *l1, UcxDlist *l2, cmp_func fnc, void* data); 4.15 +UcxDlist *restrict ucx_dlist_clone(UcxDlist *restrict l, 4.16 + copy_func fnc, void* data); 4.17 +int ucx_dlist_equals(const UcxDlist *l1, const UcxDlist *l2, 4.18 + cmp_func fnc, void* data); 4.19 4.20 void ucx_dlist_free(UcxDlist *l); 4.21 UcxDlist *ucx_dlist_append(UcxDlist *l, void *data); 4.22 UcxDlist *ucx_dlist_prepend(UcxDlist *l, void *data); 4.23 -UcxDlist *ucx_dlist_concat(UcxDlist *l1, UcxDlist *l2); 4.24 -UcxDlist *ucx_dlist_last(UcxDlist *l); 4.25 -UcxDlist *ucx_dlist_get(UcxDlist *l, int index); 4.26 -size_t ucx_dlist_size(UcxDlist *l); 4.27 +UcxDlist *ucx_dlist_concat(UcxDlist *restrict l1, UcxDlist *restrict l2); 4.28 +UcxDlist *ucx_dlist_last(const UcxDlist *l); 4.29 +UcxDlist *ucx_dlist_get(const UcxDlist *l, int index); 4.30 +size_t ucx_dlist_size(const UcxDlist *l); 4.31 4.32 UcxDlist *ucx_dlist_sort(UcxDlist *l, cmp_func fnc, void *data); 4.33 4.34 /* dlist specific functions */ 4.35 -UcxDlist *ucx_dlist_first(UcxDlist *l); 4.36 +UcxDlist *ucx_dlist_first(const UcxDlist *l); 4.37 UcxDlist *ucx_dlist_remove(UcxDlist *l, UcxDlist *e); 4.38 4.39 #ifdef __cplusplus
5.1 --- a/ucx/list.c Thu Oct 11 08:42:56 2012 +0200 5.2 +++ b/ucx/list.c Thu Oct 11 11:42:31 2012 +0200 5.3 @@ -1,6 +1,7 @@ 5.4 #include "list.h" 5.5 5.6 -UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data) { 5.7 +UcxList *restrict ucx_list_clone(UcxList *restrict l, 5.8 + copy_func fnc, void *data) { 5.9 UcxList *ret = NULL; 5.10 while (l != NULL) { 5.11 if (fnc != NULL) { 5.12 @@ -13,7 +14,8 @@ 5.13 return ret; 5.14 } 5.15 5.16 -int ucx_list_equals(UcxList *l1, UcxList *l2, cmp_func fnc, void* data) { 5.17 +int ucx_list_equals(const UcxList *l1, const UcxList *l2, 5.18 + cmp_func fnc, void* data) { 5.19 if (l1 == l2) return 1; 5.20 5.21 while (l1 != NULL && l2 != NULL) { 5.22 @@ -63,7 +65,7 @@ 5.23 return nl; 5.24 } 5.25 5.26 -UcxList *ucx_list_concat(UcxList *l1, UcxList *l2) { 5.27 +UcxList *ucx_list_concat(UcxList *restrict l1, UcxList *restrict l2) { 5.28 if (l1 == NULL) { 5.29 return l2; 5.30 } else { 5.31 @@ -73,32 +75,32 @@ 5.32 } 5.33 } 5.34 5.35 -UcxList *ucx_list_last(UcxList *l) { 5.36 +UcxList *ucx_list_last(const UcxList *l) { 5.37 if (l == NULL) return NULL; 5.38 5.39 - UcxList *e = l; 5.40 + const UcxList *e = l; 5.41 while (e->next != NULL) { 5.42 e = e->next; 5.43 } 5.44 - return e; 5.45 + return (UcxList*)e; 5.46 } 5.47 5.48 -UcxList *ucx_list_get(UcxList *l, int index) { 5.49 +UcxList *ucx_list_get(const UcxList *l, int index) { 5.50 if (l == NULL) return NULL; 5.51 5.52 - UcxList *e = l; 5.53 + const UcxList *e = l; 5.54 while (e->next != NULL && index > 0) { 5.55 e = e->next; 5.56 index--; 5.57 } 5.58 5.59 - return index == 0 ? e : NULL; 5.60 + return (UcxList*)(index == 0 ? e : NULL); 5.61 } 5.62 5.63 -size_t ucx_list_size(UcxList *l) { 5.64 +size_t ucx_list_size(const UcxList *l) { 5.65 if (l == NULL) return 0; 5.66 5.67 - UcxList *e = l; 5.68 + const UcxList *e = l; 5.69 size_t s = 1; 5.70 while (e->next != NULL) { 5.71 e = e->next; 5.72 @@ -109,14 +111,14 @@ 5.73 } 5.74 5.75 UcxList *ucx_list_sort_merge(int length, 5.76 - UcxList* ls, UcxList* rs, UcxList* le, UcxList* re, 5.77 + UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, 5.78 cmp_func fnc, void* data) { 5.79 UcxList *sorted[length]; 5.80 UcxList *rc, *lc; 5.81 5.82 - lc = ls; rc = rs; 5.83 + lc = ls; rc = le; 5.84 int n = 0; 5.85 - while (lc != le && rc != re) { 5.86 + while (lc && lc != le && rc != re) { 5.87 if (fnc(lc->data, rc->data, data) <= 0) { 5.88 sorted[n] = lc; 5.89 lc = lc->next; 5.90 @@ -126,12 +128,12 @@ 5.91 } 5.92 n++; 5.93 } 5.94 - while (lc != le) { 5.95 + while (lc && lc != le) { 5.96 sorted[n] = lc; 5.97 lc = lc->next; 5.98 n++; 5.99 } 5.100 - while (rc != re) { 5.101 + while (rc && rc != re) { 5.102 sorted[n] = rc; 5.103 rc = rc->next; 5.104 n++; 5.105 @@ -154,7 +156,7 @@ 5.106 UcxList *lc; 5.107 int ln = 1; 5.108 5.109 - UcxList *ls = l, *le; 5.110 + UcxList *restrict ls = l, *restrict le, *restrict re; 5.111 lc = ls; 5.112 while (lc->next != NULL && fnc(lc->next->data, lc->data, data) > 0) { 5.113 lc = lc->next; 5.114 @@ -162,13 +164,12 @@ 5.115 } 5.116 le = lc->next; 5.117 5.118 - UcxList *rs = le, *re; 5.119 - if (rs == NULL) { 5.120 + if (le == NULL) { 5.121 return l; // this list is already sorted :) 5.122 } else { 5.123 UcxList *rc; 5.124 int rn = 1; 5.125 - rc = rs; 5.126 + rc = le; 5.127 while (rc->next != NULL && fnc(rc->next->data, rc->data, data) > 0) { 5.128 rc = rc->next; 5.129 rn++; 5.130 @@ -184,13 +185,12 @@ 5.131 5.132 // {ls,...,le->prev} and {rs,...,re->prev} are sorted - merge them 5.133 UcxList *sorted = ucx_list_sort_merge(ln+rn, 5.134 - ls, rs, le, re, 5.135 + ls, le, re, 5.136 fnc, data); 5.137 5.138 // merge sorted list with (also sorted) remainder 5.139 l = ucx_list_sort_merge(ln+rn+remainder_length, 5.140 - sorted, remainder, NULL, NULL, 5.141 - fnc, data); 5.142 + sorted, remainder, NULL, fnc, data); 5.143 5.144 return l; 5.145 }
6.1 --- a/ucx/list.h Thu Oct 11 08:42:56 2012 +0200 6.2 +++ b/ucx/list.h Thu Oct 11 11:42:31 2012 +0200 6.3 @@ -18,16 +18,18 @@ 6.4 UcxList *next; 6.5 }; 6.6 6.7 -UcxList *ucx_list_clone(UcxList *l, copy_func fnc, void *data); 6.8 -int ucx_list_equals(UcxList *l1, UcxList *l2, cmp_func fnc, void *data); 6.9 +UcxList *restrict ucx_list_clone(UcxList *restrict l, 6.10 + copy_func fnc, void *data); 6.11 +int ucx_list_equals(const UcxList *l1, const UcxList *l2, 6.12 + cmp_func fnc, void *data); 6.13 6.14 void ucx_list_free(UcxList *l); 6.15 UcxList *ucx_list_append(UcxList *l, void *data); 6.16 UcxList *ucx_list_prepend(UcxList *l, void *data); 6.17 -UcxList *ucx_list_concat(UcxList *l1, UcxList *l2); 6.18 -UcxList *ucx_list_last(UcxList *l); 6.19 -UcxList *ucx_list_get(UcxList *l, int index); 6.20 -size_t ucx_list_size(UcxList *l); 6.21 +UcxList *ucx_list_concat(UcxList *restrict l1, UcxList *restrict l2); 6.22 +UcxList *ucx_list_last(const UcxList *l); 6.23 +UcxList *ucx_list_get(const UcxList *l, int index); 6.24 +size_t ucx_list_size(const UcxList *l); 6.25 6.26 UcxList *ucx_list_sort(UcxList *l, cmp_func fnc, void *data); 6.27
7.1 --- a/ucx/logging.c Thu Oct 11 08:42:56 2012 +0200 7.2 +++ b/ucx/logging.c Thu Oct 11 11:42:31 2012 +0200 7.3 @@ -11,7 +11,8 @@ 7.4 return logger; 7.5 } 7.6 7.7 -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message) { 7.8 +void ucx_logger_log(UcxLogger *logger, unsigned int level, 7.9 + const sstr_t message) { 7.10 if (level <= logger->level) { 7.11 fwrite(message.ptr, 1, message.length, logger->stream); 7.12 fflush(logger->stream);
8.1 --- a/ucx/logging.h Thu Oct 11 08:42:56 2012 +0200 8.2 +++ b/ucx/logging.h Thu Oct 11 11:42:31 2012 +0200 8.3 @@ -22,7 +22,8 @@ 8.4 UcxLogger *ucx_logger_new(FILE *stream, unsigned int level); 8.5 /* neither provide a free function nor a parameter for an allocator */ 8.6 8.7 -void ucx_logger_log(UcxLogger *logger, unsigned int level, sstr_t message); 8.8 +void ucx_logger_log(UcxLogger *logger, unsigned int level, 8.9 + const sstr_t message); 8.10 #define ucx_logger_error(l,m) ucx_logger_log(l, UCX_LOGGER_ERROR, m) 8.11 #define ucx_logger_info(l,m) ucx_logger_log(l, UCX_LOGGER_INFO, m) 8.12 #define ucx_logger_warn(l,m) ucx_logger_log(l, UCX_LOGGER_WARN, m)
9.1 --- a/ucx/map.c Thu Oct 11 08:42:56 2012 +0200 9.2 +++ b/ucx/map.c Thu Oct 11 11:42:31 2012 +0200 9.3 @@ -44,7 +44,8 @@ 9.4 free(map); 9.5 } 9.6 9.7 -int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data) { 9.8 +int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, 9.9 + copy_func fnc, void *data) { 9.10 UcxMapIterator i = ucx_map_iterator(from); 9.11 void *value; 9.12 UCX_MAP_FOREACH(value, i) { 9.13 @@ -82,6 +83,7 @@ 9.14 } 9.15 map->count = 0; 9.16 ucx_map_copy(&oldmap, map, NULL, NULL); 9.17 + /* TODO: free the UcxMapElement list of oldmap */ 9.18 } 9.19 return 0; 9.20 } 9.21 @@ -92,8 +94,8 @@ 9.22 } 9.23 9.24 size_t slot = key.hash%map->size; 9.25 - UcxMapElement *elm = map->map[slot]; 9.26 - UcxMapElement *prev = NULL; 9.27 + UcxMapElement *restrict elm = map->map[slot]; 9.28 + UcxMapElement *restrict prev = NULL; 9.29 9.30 while (elm != NULL && elm->key.hash < key.hash) { 9.31 prev = elm; 9.32 @@ -136,8 +138,8 @@ 9.33 } 9.34 9.35 size_t slot = key.hash%map->size; 9.36 - UcxMapElement *elm = map->map[slot]; 9.37 - UcxMapElement *pelm = NULL; 9.38 + UcxMapElement *restrict elm = map->map[slot]; 9.39 + UcxMapElement *restrict pelm = NULL; 9.40 while (elm && elm->key.hash <= key.hash) { 9.41 if(elm->key.hash == key.hash) { 9.42 int n = (key.len > elm->key.len) ? elm->key.len : key.len; 9.43 @@ -180,7 +182,7 @@ 9.44 } 9.45 9.46 9.47 -int ucx_hash(char *data, size_t len) { 9.48 +int ucx_hash(const char *data, size_t len) { 9.49 /* murmur hash 2 */ 9.50 9.51 int m = 0x5bd1e995;
10.1 --- a/ucx/map.h Thu Oct 11 08:42:56 2012 +0200 10.2 +++ b/ucx/map.h Thu Oct 11 11:42:31 2012 +0200 10.3 @@ -58,7 +58,8 @@ 10.4 UcxMap *ucx_map_new(size_t size); 10.5 void ucx_map_free(UcxMap *map); 10.6 /* you cannot clone maps with more than 390 mio entries */ 10.7 -int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data); 10.8 +int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, 10.9 + copy_func fnc, void *data); 10.10 UcxMap *ucx_map_clone(UcxMap *map, copy_func fnc, void *data); 10.11 int ucx_map_rehash(UcxMap *map); 10.12 10.13 @@ -75,7 +76,7 @@ 10.14 10.15 UcxKey ucx_key(void *data, size_t len); 10.16 10.17 -int ucx_hash(char *data, size_t len); 10.18 +int ucx_hash(const char *data, size_t len); 10.19 10.20 UcxMapIterator ucx_map_iterator(UcxMap *map); 10.21
11.1 --- a/ucx/string.c Thu Oct 11 08:42:56 2012 +0200 11.2 +++ b/ucx/string.c Thu Oct 11 11:42:31 2012 +0200 11.3 @@ -25,7 +25,7 @@ 11.4 return string; 11.5 } 11.6 11.7 -size_t sstrnlen (size_t n, sstr_t s, ...) { 11.8 +size_t sstrnlen (size_t n, const sstr_t s, ...) { 11.9 va_list ap; 11.10 size_t size = s.length; 11.11 va_start(ap, s); 11.12 @@ -54,7 +54,7 @@ 11.13 return s; 11.14 } 11.15 11.16 -sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...) { 11.17 +sstr_t sstrncat (size_t n, sstr_t s, const sstr_t c1, ...) { 11.18 va_list ap; 11.19 va_start(ap, c1); 11.20 s.ptr[0] = 0; 11.21 @@ -82,11 +82,11 @@ 11.22 return s; 11.23 } 11.24 11.25 -sstr_t sstrsubs (sstr_t s, size_t start) { 11.26 +sstr_t sstrsubs (const sstr_t s, size_t start) { 11.27 return sstrsubsl (s, start, s.length-start); 11.28 } 11.29 11.30 -sstr_t sstrsubsl (sstr_t s, size_t start, size_t length) { 11.31 +sstr_t sstrsubsl (const sstr_t s, size_t start, size_t length) { 11.32 sstr_t new_sstr; 11.33 if (start < 0 || start >= s.length || length < 0) { 11.34 return s; 11.35 @@ -99,7 +99,7 @@ 11.36 return new_sstr; 11.37 } 11.38 11.39 -sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n) { 11.40 +sstr_t* sstrsplit(const sstr_t s, const sstr_t d, size_t *n) { 11.41 if (d.length == 0) { 11.42 return NULL; 11.43 } 11.44 @@ -155,11 +155,11 @@ 11.45 return result; 11.46 } 11.47 11.48 -int sstrcmp(sstr_t s1, sstr_t s2) { 11.49 +int sstrcmp(const sstr_t s1, const sstr_t s2) { 11.50 return strncmp(s1.ptr, s2.ptr, s1.length>s2.length ? s2.length: s1.length); 11.51 } 11.52 11.53 -sstr_t sstrdup(sstr_t s) { 11.54 +sstr_t sstrdup(const sstr_t s) { 11.55 sstr_t newstring; 11.56 newstring.ptr = (char*) malloc(s.length + 1); 11.57 if (newstring.ptr != NULL) {
12.1 --- a/ucx/string.h Thu Oct 11 08:42:56 2012 +0200 12.2 +++ b/ucx/string.h Thu Oct 11 11:42:31 2012 +0200 12.3 @@ -46,7 +46,7 @@ 12.4 * s string 12.5 * ... strings 12.6 */ 12.7 -size_t sstrnlen (size_t n, sstr_t s, ...); 12.8 +size_t sstrnlen (size_t n, const sstr_t s, ...); 12.9 12.10 12.11 /* 12.12 @@ -56,18 +56,18 @@ 12.13 * s new string with enough memory allocated 12.14 * ... strings 12.15 */ 12.16 -sstr_t sstrncat (size_t n, sstr_t s, sstr_t c1, ...); 12.17 +sstr_t sstrncat (size_t n, sstr_t s, const sstr_t c1, ...); 12.18 12.19 12.20 /* 12.21 * 12.22 */ 12.23 -sstr_t sstrsubs (sstr_t s, size_t start); 12.24 +sstr_t sstrsubs (const sstr_t s, size_t start); 12.25 12.26 /* 12.27 * 12.28 */ 12.29 -sstr_t sstrsubsl (sstr_t s, size_t start, size_t length); 12.30 +sstr_t sstrsubsl (const sstr_t s, size_t start, size_t length); 12.31 12.32 /* 12.33 * splits s into n parts 12.34 @@ -85,11 +85,11 @@ 12.35 * 12.36 * Returns NULL on error 12.37 */ 12.38 -sstr_t* sstrsplit(sstr_t s, sstr_t d, size_t *n); 12.39 +sstr_t* sstrsplit(const sstr_t s, const sstr_t d, size_t *n); 12.40 12.41 -int sstrcmp(sstr_t s1, sstr_t s2); 12.42 +int sstrcmp(const sstr_t s1, const sstr_t s2); 12.43 12.44 -sstr_t sstrdup(sstr_t s); 12.45 +sstr_t sstrdup(const sstr_t s); 12.46 12.47 #ifdef __cplusplus 12.48 }