Changes in uspace/lib/c/generic/str.c [09ab0a9a:d066259] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
r09ab0a9a rd066259 1 1 /* 2 * Copyright (c) 2001-2004 Jakub Jermar 2 3 * Copyright (c) 2005 Martin Decky 3 4 * Copyright (c) 2008 Jiri Svoboda … … 33 34 * @{ 34 35 */ 35 /** @file 36 37 /** 38 * @file 39 * @brief String functions. 40 * 41 * Strings and characters use the Universal Character Set (UCS). The standard 42 * strings, called just strings are encoded in UTF-8. Wide strings (encoded 43 * in UTF-32) are supported to a limited degree. A single character is 44 * represented as wchar_t.@n 45 * 46 * Overview of the terminology:@n 47 * 48 * Term Meaning 49 * -------------------- ---------------------------------------------------- 50 * byte 8 bits stored in uint8_t (unsigned 8 bit integer) 51 * 52 * character UTF-32 encoded Unicode character, stored in wchar_t 53 * (signed 32 bit integer), code points 0 .. 1114111 54 * are valid 55 * 56 * ASCII character 7 bit encoded ASCII character, stored in char 57 * (usually signed 8 bit integer), code points 0 .. 127 58 * are valid 59 * 60 * string UTF-8 encoded NULL-terminated Unicode string, char * 61 * 62 * wide string UTF-32 encoded NULL-terminated Unicode string, 63 * wchar_t * 64 * 65 * [wide] string size number of BYTES in a [wide] string (excluding 66 * the NULL-terminator), size_t 67 * 68 * [wide] string length number of CHARACTERS in a [wide] string (excluding 69 * the NULL-terminator), size_t 70 * 71 * [wide] string width number of display cells on a monospace display taken 72 * by a [wide] string, size_t 73 * 74 * 75 * Overview of string metrics:@n 76 * 77 * Metric Abbrev. Type Meaning 78 * ------ ------ ------ ------------------------------------------------- 79 * size n size_t number of BYTES in a string (excluding the 80 * NULL-terminator) 81 * 82 * length l size_t number of CHARACTERS in a string (excluding the 83 * null terminator) 84 * 85 * width w size_t number of display cells on a monospace display 86 * taken by a string 87 * 88 * 89 * Function naming prefixes:@n 90 * 91 * chr_ operate on characters 92 * ascii_ operate on ASCII characters 93 * str_ operate on strings 94 * wstr_ operate on wide strings 95 * 96 * [w]str_[n|l|w] operate on a prefix limited by size, length 97 * or width 98 * 99 * 100 * A specific character inside a [wide] string can be referred to by:@n 101 * 102 * pointer (char *, wchar_t *) 103 * byte offset (size_t) 104 * character index (size_t) 105 * 36 106 */ 37 107 38 108 #include <str.h> 109 110 #include <assert.h> 111 #include <ctype.h> 112 #include <errno.h> 113 #include <stdbool.h> 39 114 #include <stddef.h> 40 115 #include <stdint.h> 41 116 #include <stdlib.h> 42 #include <assert.h> 43 #include <ctype.h> 44 #include <errno.h> 117 45 118 #include <align.h> 46 119 #include <mem.h> 47 #include <limits.h>48 120 49 121 /** Check the condition if wchar_t is signed */ … … 747 819 /* There must be space for a null terminator in the buffer. */ 748 820 assert(size > 0); 821 assert(src != NULL); 749 822 750 823 size_t src_off = 0; … … 1311 1384 { 1312 1385 size_t size = str_size(src) + 1; 1313 char *dest = (char *)malloc(size);1314 if ( dest == NULL)1315 return (char *)NULL;1386 char *dest = malloc(size); 1387 if (!dest) 1388 return NULL; 1316 1389 1317 1390 str_cpy(dest, size, src); … … 1345 1418 size = n; 1346 1419 1347 char *dest = (char *)malloc(size + 1);1348 if ( dest == NULL)1349 return (char *)NULL;1420 char *dest = malloc(size + 1); 1421 if (!dest) 1422 return NULL; 1350 1423 1351 1424 str_ncpy(dest, size + 1, src, size);
Note:
See TracChangeset
for help on using the changeset viewer.