/trunk/uspace/app/bdsh/cmds/modules/ls/ls.c |
---|
182,7 → 182,7 |
if (argc == 1) |
getcwd(buff, PATH_MAX); |
else |
str_ncpy(buff, argv[1], PATH_MAX); |
str_cpy(buff, PATH_MAX, argv[1]); |
scope = ls_scope(buff); |
/trunk/uspace/app/tetris/scores.c |
---|
117,7 → 117,8 |
*/ |
static void copyhiscore(int dest, int src) |
{ |
strcpy(scores[dest].hs_name, scores[src].hs_name); |
str_cpy(scores[dest].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
scores[src].hs_name); |
scores[dest].hs_score = scores[src].hs_score; |
scores[dest].hs_level = scores[src].hs_level; |
} |
131,7 → 132,8 |
clear_screen(); |
moveto(10 , 10); |
puts("Insert your name: "); |
str_ncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME); |
str_cpy(scores[NUMSPOTS - 1].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, |
"Player"); |
i = 6; off = 6; |
moveto(10 , 28); |
195,7 → 197,7 |
{ |
int i; |
for(i = 0; i < NUMSPOTS; i++) { |
str_ncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME); |
str_cpy(scores[i].hs_name, STR_BOUNDS(MAXLOGNAME) + 1, "HelenOS Team"); |
scores[i].hs_score = (NUMSPOTS - i) * 200; |
scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1); |
} |
/trunk/uspace/app/tetris/tetris.c |
---|
311,7 → 311,7 |
errx(1, "duplicate command keys specified."); |
} |
if (keys[i] == ' ') |
str_ncpy(key_write[i], "<space>", sizeof key_write[i]); |
str_cpy(key_write[i], sizeof key_write[i], "<space>"); |
else { |
key_write[i][0] = keys[i]; |
key_write[i][1] = '\0'; |
/trunk/uspace/lib/libc/include/string.h |
---|
69,7 → 69,9 |
extern int str_cmp(const char *s1, const char *s2); |
extern int str_lcmp(const char *s1, const char *s2, count_t max_len); |
extern void str_ncpy(char *dst, const char *src, size_t size); |
extern void str_cpy(char *dest, size_t size, const char *src); |
extern void str_ncpy(char *dest, size_t size, const char *src, size_t n); |
extern void wstr_nstr(char *dst, const wchar_t *src, size_t size); |
extern const char *str_chr(const char *str, wchar_t ch); |
87,7 → 89,6 |
extern int strncmp(const char *, const char *, size_t); |
extern int stricmp(const char *, const char *); |
extern char *strcpy(char *, const char *); |
extern char *strcat(char *, const char *); |
extern long int strtol(const char *, char **, int); |
/trunk/uspace/lib/libc/generic/string.c |
---|
462,38 → 462,71 |
} |
/** Copy NULL-terminated string. |
/** Copy string. |
* |
* Copy source string @a src to destination buffer @a dst. |
* No more than @a size bytes are written. NULL-terminator is always |
* written after the last succesfully copied character (i.e. if the |
* destination buffer is has at least 1 byte, it will be always |
* NULL-terminated). |
* Copy source string @a src to destination buffer @a dest. |
* No more than @a size bytes are written. If the size of the output buffer |
* is at least one byte, the output string will always be well-formed, i.e. |
* null-terminated and containing only complete characters. |
* |
* @param src Source string. |
* @param dst Destination buffer. |
* @param count Size of the destination buffer. |
* |
* @param src Source string. |
*/ |
void str_ncpy(char *dst, const char *src, size_t size) |
void str_cpy(char *dest, size_t size, const char *src) |
{ |
/* No space for the NULL-terminator in the buffer */ |
wchar_t ch; |
size_t src_off; |
size_t dest_off; |
/* No space for the NULL-terminator in the buffer. */ |
if (size == 0) |
return; |
src_off = 0; |
dest_off = 0; |
while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) { |
if (chr_encode(ch, dest, &dest_off, size - 1) != EOK) |
break; |
} |
dest[dest_off] = '\0'; |
} |
/** Copy size-limited substring. |
* |
* Copy source string @a src to destination buffer @a dest. |
* No more than @a size bytes are written. If the size of the output buffer |
* is at least one byte, the output string will always be well-formed, i.e. |
* null-terminated and containing only complete characters. |
* |
* No more than @a n bytes are read from the input string, so it does not |
* have to be null-terminated. |
* |
* @param dst Destination buffer. |
* @param count Size of the destination buffer. |
* @param src Source string. |
*/ |
void str_ncpy(char *dest, size_t size, const char *src, size_t n) |
{ |
wchar_t ch; |
size_t str_off = 0; |
size_t dst_off = 0; |
size_t src_off; |
size_t dest_off; |
/* No space for the null terminator in the buffer. */ |
if (size == 0) |
return; |
while ((ch = str_decode(src, &str_off, STR_NO_LIMIT)) != 0) { |
if (chr_encode(ch, dst, &dst_off, size) != EOK) |
src_off = 0; |
dest_off = 0; |
while ((ch = str_decode(src, &src_off, n)) != 0) { |
if (chr_encode(ch, dest, &dest_off, size - 1) != EOK) |
break; |
} |
if (dst_off >= size) |
dst[size - 1] = 0; |
else |
dst[dst_off] = 0; |
dest[dest_off] = '\0'; |
} |
/** Copy NULL-terminated wide string to string |
798,15 → 831,6 |
return (sgn ? -number : number); |
} |
char *strcpy(char *dest, const char *src) |
{ |
char *orig = dest; |
while ((*(dest++) = *(src++))) |
; |
return orig; |
} |
char *strcat(char *dest, const char *src) |
{ |
char *orig = dest; |
/trunk/uspace/lib/libc/generic/loader.c |
---|
180,7 → 180,7 |
dp = arg_buf; |
while (*ap != NULL) { |
str_ncpy(dp, *ap, buffer_size - (dp - arg_buf)); |
str_cpy(dp, buffer_size - (dp - arg_buf), *ap); |
dp += str_size(*ap) + 1; |
++ap; |
/trunk/uspace/lib/libc/generic/vfs/vfs.c |
---|
76,7 → 76,7 |
futex_up(&cwd_futex); |
return NULL; |
} |
str_ncpy(ncwd_path_nc, cwd_path, cwd_size + 1 + size + 1); |
str_cpy(ncwd_path_nc, cwd_size + 1 + size + 1, cwd_path); |
ncwd_path_nc[cwd_size] = '/'; |
ncwd_path_nc[cwd_size + 1] = '\0'; |
} else { |
534,7 → 534,7 |
futex_up(&cwd_futex); |
return NULL; |
} |
str_ncpy(buf, cwd_path, size); |
str_cpy(buf, size, cwd_path); |
futex_up(&cwd_futex); |
return buf; |
} |
/trunk/uspace/srv/fs/tmpfs/tmpfs_ops.c |
---|
325,7 → 325,7 |
free(namep); |
return ENOMEM; |
} |
strcpy(namep->name, nm); |
str_cpy(namep->name, size + 1, nm); |
namep->parent = parentp; |
childp->lnkcnt++; |
/trunk/uspace/srv/fs/fat/fat_ops.c |
---|
489,8 → 489,8 |
if (fat_classify_dentry(d) == FAT_DENTRY_LAST || |
str_cmp(d->name, FAT_NAME_DOT) == 0) { |
memset(d, 0, sizeof(fat_dentry_t)); |
strcpy(d->name, FAT_NAME_DOT); |
strcpy(d->ext, FAT_EXT_PAD); |
str_cpy(d->name, 8, FAT_NAME_DOT); |
str_cpy(d->ext, 3, FAT_EXT_PAD); |
d->attr = FAT_ATTR_SUBDIR; |
d->firstc = host2uint16_t_le(childp->firstc); |
/* TODO: initialize also the date/time members. */ |
499,8 → 499,8 |
if (fat_classify_dentry(d) == FAT_DENTRY_LAST || |
str_cmp(d->name, FAT_NAME_DOT_DOT) == 0) { |
memset(d, 0, sizeof(fat_dentry_t)); |
strcpy(d->name, FAT_NAME_DOT_DOT); |
strcpy(d->ext, FAT_EXT_PAD); |
str_cpy(d->name, 8, FAT_NAME_DOT_DOT); |
str_cpy(d->ext, 3, FAT_EXT_PAD); |
d->attr = FAT_ATTR_SUBDIR; |
d->firstc = (parentp->firstc == FAT_CLST_ROOT) ? |
host2uint16_t_le(FAT_CLST_RES0) : |