Overview
Comment: | Add cfw_strndup(). |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
587d349f8dffa3dbdadd0d9ba87dec6b |
User & Date: | js on 2012-09-29 23:17:01 |
Other Links: | manifest | tags |
Context
2012-09-29
| ||
23:22 | Add cfw_string_set_nocopy(). check-in: ebf63ac6c8 user: js tags: trunk | |
23:17 | Add cfw_strndup(). check-in: 587d349f8d user: js tags: trunk | |
22:50 | Add cfw_std{in,out,err}. check-in: 999088161e user: js tags: trunk | |
Changes
Modified src/string.c from [cebb101511] to [3b8850abd4].
︙ | |||
42 43 44 45 46 47 48 49 50 51 52 53 54 55 | 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | + + + + + + + + + + + + + + + + + + + + + + | char* cfw_strdup(const char *s) { char *copy; size_t len; len = strlen(s); if ((copy = malloc(len + 1)) == NULL) { errno = ENOMEM; return NULL; } memcpy(copy, s, len); copy[len] = 0; return copy; } char* cfw_strndup(const char *s, size_t max) { char *copy; size_t len; len = strlen(s); if (len > max) len = max; if ((copy = malloc(len + 1)) == NULL) { errno = ENOMEM; return NULL; } memcpy(copy, s, len); |
︙ |
Modified src/string.h from [5343bc593c] to [3ca4b8968d].
︙ | |||
29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | + | #include "class.h" #include "range.h" typedef struct CFWString CFWString; extern CFWClass *cfw_string; extern char* cfw_strdup(const char*); extern char* cfw_strndup(const char*, size_t); extern const char* cfw_string_c(CFWString*); extern size_t cfw_string_length(CFWString*); extern bool cfw_string_set(CFWString*, const char*); extern bool cfw_string_append(CFWString*, CFWString*); extern size_t cfw_string_find(CFWString*, CFWString*, cfw_range_t); #endif |