Changeset 051bc69a in mainline for uspace/app/sbi/src/os
- Timestamp:
- 2010-05-08T08:10:44Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 640ffe6, c5cb943d
- Parents:
- 25a76ab8
- Location:
- uspace/app/sbi/src/os
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/sbi/src/os/helenos.c
r25a76ab8 r051bc69a 29 29 /** @file HelenOS-specific code. */ 30 30 31 #include <assert.h> 31 32 #include <errno.h> 32 33 #include <stdio.h> … … 75 76 } 76 77 78 /** Return slice (substring) of a string. 79 * 80 * Copies the specified range of characters from @a str and returns it 81 * as a newly allocated string. @a start + @a length must be less than 82 * or equal to the length of @a str. 83 * 84 * @param str String 85 * @param start Index of first character (starting from zero). 86 * @param length Number of characters to copy. 87 * 88 * @return Newly allocated string holding the slice. 89 */ 90 char *os_str_aslice(const char *str, size_t start, size_t length) 91 { 92 char *slice; 93 size_t offset; 94 size_t i; 95 size_t size; 96 wchar_t c; 97 98 assert(start + length <= str_length(str)); 99 100 offset = 0; 101 for (i = 0; i < start; ++i) { 102 c = str_decode(str, &offset, STR_NO_LIMIT); 103 assert(c != '\0'); 104 assert(c != U_SPECIAL); 105 (void) c; 106 } 107 108 size = str_lsize(str, length); 109 slice = str_ndup(str + offset, size); 110 111 return slice; 112 } 113 77 114 /** Compare two strings. 78 115 * -
uspace/app/sbi/src/os/os.h
r25a76ab8 r051bc69a 31 31 32 32 char *os_str_acat(const char *a, const char *b); 33 char *os_str_aslice(const char *str, size_t start, size_t length); 33 34 int os_str_cmp(const char *a, const char *b); 34 35 char *os_str_dup(const char *str); -
uspace/app/sbi/src/os/posix.c
r25a76ab8 r051bc69a 29 29 /** @file POSIX-specific code. */ 30 30 31 #include <assert.h> 31 32 #include <libgen.h> 32 33 #include <stdio.h> … … 78 79 } 79 80 81 /** Return slice (substring) of a string. 82 * 83 * Copies the specified range of characters from @a str and returns it 84 * as a newly allocated string. @a start + @a length must be less than 85 * or equal to the length of @a str. 86 * 87 * @param str String 88 * @param start Index of first character (starting from zero). 89 * @param length Number of characters to copy. 90 * 91 * @return Newly allocated string holding the slice. 92 */ 93 char *os_str_aslice(const char *str, size_t start, size_t length) 94 { 95 char *slice; 96 97 assert(start + length <= strlen(str)); 98 slice = malloc(length + 1); 99 if (slice == NULL) { 100 printf("Memory allocation error.\n"); 101 exit(1); 102 } 103 104 strncpy(slice, str + start, length); 105 slice[length] = '\0'; 106 107 return slice; 108 } 109 80 110 /** Compare two strings. 81 111 *
Note:
See TracChangeset
for help on using the changeset viewer.
