Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 095003a8 in mainline


Ignore:
Timestamp:
2009-04-09T22:32:23Z (12 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master
Children:
f4b1535
Parents:
7afb4a5
Message:

strdup() → str_dup()

Location:
uspace
Files:
10 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/ls/ls.c

    r7afb4a5 r095003a8  
    183183                getcwd(buff, PATH_MAX);
    184184        else
    185                 strncpy(buff, argv[1], PATH_MAX);
     185                str_ncpy(buff, argv[1], PATH_MAX);
    186186
    187187        scope = ls_scope(buff);
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    r7afb4a5 r095003a8  
    9494        /* Its a good idea to allocate path, plus we (may) need a copy of
    9595         * path to tokenize if parents are specified */
    96         if (NULL == (tmp = strdup(path))) {
     96        if (NULL == (tmp = str_dup(path))) {
    9797                cli_error(CL_ENOMEM, "%s: path too big?", cmdname);
    9898                return 1;
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    r7afb4a5 r095003a8  
    8181
    8282        for (i = 1; i < argc; i ++) {
    83                 buff = strdup(argv[i]);
     83                buff = str_dup(argv[i]);
    8484                dirp = opendir(buff);
    8585                if (dirp) {
  • uspace/app/bdsh/exec.c

    r7afb4a5 r095003a8  
    8181        }
    8282
    83         path_tok = strdup(PATH);
     83        path_tok = str_dup(PATH);
    8484
    8585        /* Extract the PATH env to a path[] array */
     
    115115        char *tmp;
    116116
    117         tmp = strdup(find_command(cmd));
     117        tmp = str_dup(find_command(cmd));
    118118        free(found);
    119119
  • uspace/app/bdsh/input.c

    r7afb4a5 r095003a8  
    6262                return CL_EFAIL;
    6363
    64         tmp = strdup(usr->line);
     64        tmp = str_dup(usr->line);
    6565
    6666        cmd[n] = strtok(tmp, " ");
     
    156156        if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0)
    157157                return;
    158         usr->line = strdup(line);
     158        usr->line = str_dup(line);
    159159
    160160        return;
  • uspace/app/tetris/scores.c

    r7afb4a5 r095003a8  
    132132        moveto(10 , 10);
    133133        puts("Insert your name: ");
    134         strncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
     134        str_ncpy(scores[NUMSPOTS - 1].hs_name, "Player", MAXLOGNAME);
    135135        i = 6; off = 6;
    136136
     
    196196        int i;
    197197        for(i = 0; i < NUMSPOTS; i++) {
    198                 strncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME);
     198                str_ncpy(scores[i].hs_name, "HelenOS Team", MAXLOGNAME);
    199199                scores[i].hs_score = (NUMSPOTS - i) * 200;     
    200200                scores[i].hs_level = (i + 1 > MAXLEVEL?MAXLEVEL:i + 1);
  • uspace/app/tetris/tetris.c

    r7afb4a5 r095003a8  
    312312                }
    313313                if (keys[i] == ' ')
    314                         strncpy(key_write[i], "<space>", sizeof key_write[i]);
     314                        str_ncpy(key_write[i], "<space>", sizeof key_write[i]);
    315315                else {
    316316                        key_write[i][0] = keys[i];
  • uspace/lib/libc/generic/string.c

    r7afb4a5 r095003a8  
    4141#include <errno.h>
    4242#include <align.h>
     43#include <mem.h>
    4344#include <string.h>
    4445
     
    807808}
    808809
    809 char *strncpy(char *dest, const char *src, size_t n)
    810 {
    811         char *orig = dest;
    812        
    813         while ((*(dest++) = *(src++)) && --n)
    814                 ;
    815         return orig;
    816 }
    817 
    818810char *strcat(char *dest, const char *src)
    819811{
     
    827819}
    828820
    829 char * strdup(const char *s1)
    830 {
    831         size_t len = str_size(s1) + 1;
    832         void *ret = malloc(len);
    833 
    834         if (ret == NULL)
     821char *str_dup(const char *src)
     822{
     823        size_t size = str_size(src);
     824        void *dest = malloc(size + 1);
     825
     826        if (dest == NULL)
    835827                return (char *) NULL;
    836828
    837         return (char *) memcpy(ret, s1, len);
     829        return (char *) memcpy(dest, src, size + 1);
    838830}
    839831
  • uspace/lib/libc/generic/vfs/vfs.c

    r7afb4a5 r095003a8  
    100100         * though they both point into the same dynamically allocated buffer.
    101101         */
    102         ncwd_path = strdup(ncwd_path);
     102        ncwd_path = str_dup(ncwd_path);
    103103        free(ncwd_path_nc);
    104104        if (!ncwd_path) {
  • uspace/lib/libc/include/string.h

    r7afb4a5 r095003a8  
    7979extern bool wstr_remove(wchar_t *str, count_t pos);
    8080
     81extern char *str_dup(const char *);
     82
    8183/*
    8284 * TODO: Get rid of this.
     
    8789
    8890extern char *strcpy(char *, const char *);
    89 extern char *strncpy(char *, const char *, size_t);
    90 
    9191extern char *strcat(char *, const char *);
    92 
    93 extern char *strdup(const char *);
    9492
    9593extern long int strtol(const char *, char **, int);
Note: See TracChangeset for help on using the changeset viewer.