Changes in uspace/lib/c/generic/str.c [d066259:09ab0a9a] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/str.c
rd066259 r09ab0a9a 1 1 /* 2 * Copyright (c) 2001-2004 Jakub Jermar3 2 * Copyright (c) 2005 Martin Decky 4 3 * Copyright (c) 2008 Jiri Svoboda … … 34 33 * @{ 35 34 */ 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 * 35 /** @file 106 36 */ 107 37 108 38 #include <str.h> 109 39 #include <stddef.h> 40 #include <stdint.h> 41 #include <stdlib.h> 110 42 #include <assert.h> 111 43 #include <ctype.h> 112 44 #include <errno.h> 113 #include <stdbool.h>114 #include <stddef.h>115 #include <stdint.h>116 #include <stdlib.h>117 118 45 #include <align.h> 119 46 #include <mem.h> 47 #include <limits.h> 120 48 121 49 /** Check the condition if wchar_t is signed */ … … 819 747 /* There must be space for a null terminator in the buffer. */ 820 748 assert(size > 0); 821 assert(src != NULL);822 749 823 750 size_t src_off = 0; … … 1384 1311 { 1385 1312 size_t size = str_size(src) + 1; 1386 char *dest = malloc(size);1387 if ( !dest)1388 return NULL;1313 char *dest = (char *) malloc(size); 1314 if (dest == NULL) 1315 return (char *) NULL; 1389 1316 1390 1317 str_cpy(dest, size, src); … … 1418 1345 size = n; 1419 1346 1420 char *dest = malloc(size + 1);1421 if ( !dest)1422 return NULL;1347 char *dest = (char *) malloc(size + 1); 1348 if (dest == NULL) 1349 return (char *) NULL; 1423 1350 1424 1351 str_ncpy(dest, size + 1, src, size);
Note:
See TracChangeset
for help on using the changeset viewer.