Changeset 92fd52d7 in mainline


Ignore:
Timestamp:
2009-04-09T21:16:50Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7afb4a5
Parents:
a2c58f6
Message:

Nuke strcpy() and strcmp().

Location:
uspace
Files:
25 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/builtin_cmds.c

    ra2c58f6 r92fd52d7  
    5050
    5151        for (cmd = builtins; cmd->name != NULL; cmd++, i++) {
    52                 if (!strcmp(cmd->name, command))
     52                if (!str_cmp(cmd->name, command))
    5353                        return i;
    5454        }
     
    6565
    6666        for(i=0; builtin_aliases[i] != NULL; i+=2) {
    67                 if (!strcmp(builtin_aliases[i], command))
     67                if (!str_cmp(builtin_aliases[i], command))
    6868                        return 1;
    6969        }
     
    8080
    8181        for(i=0; builtin_aliases[i] != NULL; i++) {
    82                 if (!strcmp(builtin_aliases[i], command))
     82                if (!str_cmp(builtin_aliases[i], command))
    8383                        return (char *)builtin_aliases[++i];
    8484                i++;
  • uspace/app/bdsh/cmds/mod_cmds.c

    ra2c58f6 r92fd52d7  
    6565
    6666        for (mod = modules; mod->name != NULL; mod++, i++) {
    67                 if (!strcmp(mod->name, command))
     67                if (!str_cmp(mod->name, command))
    6868                        return i;
    6969        }
     
    8282
    8383        for(i=0; mod_aliases[i] != NULL; i+=2) {
    84                 if (!strcmp(mod_aliases[i], command))
     84                if (!str_cmp(mod_aliases[i], command))
    8585                        return 1;
    8686        }
     
    9898
    9999        for(i=0; mod_aliases[i] != NULL; i++) {
    100                 if (!strcmp(mod_aliases[i], command))
     100                if (!str_cmp(mod_aliases[i], command))
    101101                        return (char *)mod_aliases[++i];
    102102                i++;
  • uspace/app/bdsh/cmds/modules/help/help.c

    ra2c58f6 r92fd52d7  
    108108
    109109        if (argc == 3) {
    110                 if (!strcmp("extended", argv[2]))
     110                if (!str_cmp("extended", argv[2]))
    111111                        level = HELP_LONG;
    112112                else
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    ra2c58f6 r92fd52d7  
    150150                /* Sometimes make or scripts conjoin odd paths. Account for something
    151151                 * like this: ../../foo/bar/../foo/foofoo/./bar */
    152                 if (!strcmp(dirs[i], "..") || !strcmp(dirs[i], ".")) {
     152                if (!str_cmp(dirs[i], "..") || !str_cmp(dirs[i], ".")) {
    153153                        if (0 != (chdir(dirs[i]))) {
    154154                                cli_error(CL_EFAIL, "%s: impossible path: %s",
  • uspace/app/bdsh/cmds/modules/rm/rm.c

    ra2c58f6 r92fd52d7  
    217217        i = optind;
    218218        while (NULL != argv[i]) {
    219                 len = strlen(argv[i]) + 2;
     219                len = str_size(argv[i]) + 2;
    220220                buff = (char *) realloc(buff, len);
    221221                if (buff == NULL) {
  • uspace/app/bdsh/exec.c

    ra2c58f6 r92fd52d7  
    7272        char *path[PATH_MAX];
    7373        int n = 0, i = 0;
    74         size_t x = strlen(cmd) + 2;
     74        size_t x = str_size(cmd) + 2;
    7575
    7676        found = (char *)malloc(PATH_MAX);
     
    8686        path[n] = strtok(path_tok, PATH_DELIM);
    8787        while (NULL != path[n]) {
    88                 if ((strlen(path[n]) + x ) > PATH_MAX) {
     88                if ((str_size(path[n]) + x ) > PATH_MAX) {
    8989                        cli_error(CL_ENOTSUP,
    9090                                "Segment %d of path is too large, search ends at segment %d",
  • uspace/app/bdsh/input.c

    ra2c58f6 r92fd52d7  
    147147{
    148148        char line[INPUT_MAX];
    149         size_t len = 0;
    150149
    151150        console_set_style(STYLE_EMPHASIS);
     
    154153
    155154        read_line(line, INPUT_MAX);
    156         len = strlen(line);
    157155        /* Make sure we don't have rubbish or a C/R happy user */
    158         if (len == 0 || line[0] == '\n')
     156        if (str_cmp(line, "") == 0 || str_cmp(line, "\n") == 0)
    159157                return;
    160158        usr->line = strdup(line);
  • uspace/app/tester/devmap/devmap1.c

    ra2c58f6 r92fd52d7  
    141141        req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    142142
    143         retval = ipc_data_write_start(phone, (char *)name, strlen(name) + 1);
     143        retval = ipc_data_write_start(phone, (char *)name, str_size(name) + 1);
    144144
    145145        if (retval != EOK) {
     
    174174            &answer);
    175175
    176         retval = ipc_data_write_start(driver_phone, name, strlen(name) + 1);
     176        retval = ipc_data_write_start(driver_phone, name, str_size(name) + 1);
    177177
    178178        if (retval != EOK) {
     
    216216
    217217        retval = ipc_data_write_start(driver_phone, (char *)name,
    218             strlen(name) + 1);
     218            str_size(name) + 1);
    219219
    220220        if (retval != EOK) {
  • uspace/app/tetris/scores.c

    ra2c58f6 r92fd52d7  
    290290/*      me = thisuser(); */
    291291/*      for (i = 0, sp = &scores[0]; i < nscores; i++, sp++) { */
    292 /*              if (sp->hs_level != level || strcmp(sp->hs_name, me) != 0) */
     292/*              if (sp->hs_level != level || str_cmp(sp->hs_name, me) != 0) */
    293293/*                      continue; */
    294294/*              if (score > sp->hs_score) { */
     
    418418/*               *\/ */
    419419/*              for (j = 0, pu = count; j < numnames; j++, pu++) */
    420 /*                      if (strcmp(sp->hs_name, pu->name) == 0) */
     420/*                      if (str_cmp(sp->hs_name, pu->name) == 0) */
    421421/*                              break; */
    422422/*              if (j == numnames) { */
     
    555555/*                  sp->hs_level == level && */
    556556/*                  sp->hs_score == score && */
    557 /*                  strcmp(sp->hs_name, me) == 0) { */
     557/*                  str_cmp(sp->hs_name, me) == 0) { */
    558558/*                      putpad(SOstr); */
    559559/*                      highlight = 1; */
  • uspace/app/tetris/screen.c

    ra2c58f6 r92fd52d7  
    281281{
    282282       
    283         int l = strlen(s);
     283        int l = str_size(s);
    284284       
    285285        moveto(Rows - 2, ((Cols - l) >> 1) - 1);
  • uspace/app/tetris/tetris.c

    ra2c58f6 r92fd52d7  
    278278/*                      break; */
    279279/*              case 'k': */
    280 /*                      if (strlen(keys = optarg) != 6) */
     280/*                      if (str_size(keys = optarg) != 6) */
    281281/*                              usage(); */
    282282/*                      break; */
  • uspace/lib/libc/generic/console.c

    ra2c58f6 r92fd52d7  
    220220        ssize_t rc;
    221221
    222         len = strlen(s);
     222        len = str_size(s);
    223223        while (len > 0) {
    224224                rc = console_write(s, len);
  • uspace/lib/libc/generic/getopt.c

    ra2c58f6 r92fd52d7  
    383383                        has_equal++;
    384384                } else
    385                         current_argv_len = strlen(current_argv);
     385                        current_argv_len = str_size(current_argv);
    386386           
    387387                for (i = 0; long_options[i].name; i++) {
     
    391391                                continue;
    392392
    393                         if (strlen(long_options[i].name) ==
     393                        if (str_size(long_options[i].name) ==
    394394                            (unsigned)current_argv_len) {
    395395                                /* exact match */
  • uspace/lib/libc/generic/string.c

    ra2c58f6 r92fd52d7  
    607607}
    608608
    609 /** Count the number of characters in the string, not including terminating 0.
    610  *
    611  * @param str           String.
    612  * @return              Number of characters in string.
    613  */
    614 size_t strlen(const char *str)
    615 {
    616         size_t counter = 0;
    617 
    618         while (str[counter] != 0)
    619                 counter++;
    620 
    621         return counter;
    622 }
    623 
    624 int strcmp(const char *a, const char *b)
    625 {
    626         int c = 0;
    627        
    628         while (a[c] && b[c] && (!(a[c] - b[c])))
    629                 c++;
    630        
    631         return (a[c] - b[c]);
    632 }
    633 
    634609int strncmp(const char *a, const char *b, size_t n)
    635610{
     
    871846char * strdup(const char *s1)
    872847{
    873         size_t len = strlen(s1) + 1;
     848        size_t len = str_size(s1) + 1;
    874849        void *ret = malloc(len);
    875850
  • uspace/lib/libc/include/stdio.h

    ra2c58f6 r92fd52d7  
    5050        n = snprintf(buf, sizeof(buf), fmt, ##__VA_ARGS__); \
    5151        if (n > 0) \
    52                 (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, strlen(buf)); \
     52                (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) buf, str_size(buf)); \
    5353}
    5454
  • uspace/lib/libc/include/string.h

    ra2c58f6 r92fd52d7  
    4646#define STR_NO_LIMIT  ((size_t) -1)
    4747
    48 /**< Maximum size of a string containing cnt characters */
    49 #define STR_BOUNDS(cnt)  (cnt << 2)
     48/**< Maximum size of a string containing @c length characters */
     49#define STR_BOUNDS(length)  ((length) << 2)
    5050
    5151extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
     
    8282 */
    8383
    84 extern int strcmp(const char *, const char *);
    8584extern int strncmp(const char *, const char *, size_t);
    8685extern int stricmp(const char *, const char *);
     
    9089
    9190extern char *strcat(char *, const char *);
    92 
    93 extern size_t strlen(const char *);
    9491
    9592extern char *strdup(const char *);
  • uspace/srv/devmap/devmap.c

    ra2c58f6 r92fd52d7  
    564564        ipc_answer_0(iid, EOK);
    565565       
    566         size_t name_size = strlen(device->name);
     566        size_t name_size = str_size(device->name);
    567567       
    568568        /* FIXME:
  • uspace/srv/fs/fat/fat_dentry.c

    ra2c58f6 r92fd52d7  
    6363{
    6464        int rc;
     65        size_t size;
     66
    6567        if (!(rc = stricmp(name, component)))
    6668                return rc;
     
    7072                 * space for appending an extra '.' to name.
    7173                 */
    72                 name[strlen(name)] = '.';
    73                 name[strlen(name) + 1] = '\0';
     74                size = str_size(name);
     75                name[size] = '.';
     76                name[size + 1] = '\0';
    7477                rc = stricmp(name, component);
    7578        }
  • uspace/srv/fs/fat/fat_ops.c

    ra2c58f6 r92fd52d7  
    488488        d = (fat_dentry_t *)b->data;
    489489        if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    490             strcmp(d->name, FAT_NAME_DOT) == 0) {
     490            str_cmp(d->name, FAT_NAME_DOT) == 0) {
    491491                memset(d, 0, sizeof(fat_dentry_t));
    492492                strcpy(d->name, FAT_NAME_DOT);
     
    498498        d++;
    499499        if (fat_classify_dentry(d) == FAT_DENTRY_LAST ||
    500             strcmp(d->name, FAT_NAME_DOT_DOT) == 0) {
     500            str_cmp(d->name, FAT_NAME_DOT_DOT) == 0) {
    501501                memset(d, 0, sizeof(fat_dentry_t));
    502502                strcpy(d->name, FAT_NAME_DOT_DOT);
     
    938938                return;
    939939hit:
    940                 (void) ipc_data_read_finalize(callid, name, strlen(name) + 1);
     940                (void) ipc_data_read_finalize(callid, name, str_size(name) + 1);
    941941                bytes = (pos - spos) + 1;
    942942        }
  • uspace/srv/fs/tmpfs/tmpfs_dump.c

    ra2c58f6 r92fd52d7  
    178178       
    179179        tag[5] = 0;
    180         if (strcmp(tag, "TMPFS") != 0)
     180        if (str_cmp(tag, "TMPFS") != 0)
    181181                goto error;
    182182       
  • uspace/srv/fs/tmpfs/tmpfs_ops.c

    ra2c58f6 r92fd52d7  
    256256        assert(hlp);
    257257        tmpfs_name_t *namep = hash_table_get_instance(hlp, tmpfs_name_t, link);
    258         return !strcmp(namep->name, component);
     258        return !str_cmp(namep->name, component);
    259259}
    260260
     
    320320                return ENOMEM;
    321321        tmpfs_name_initialize(namep);
    322         size_t len = strlen(nm);
    323         namep->name = malloc(len + 1);
     322        size_t size = str_size(nm);
     323        namep->name = malloc(size + 1);
    324324        if (!namep->name) {
    325325                free(namep);
     
    455455         */
    456456        ipc_callid_t callid;
    457         size_t len;
    458         if (!ipc_data_read_receive(&callid, &len)) {
     457        size_t size;
     458        if (!ipc_data_read_receive(&callid, &size)) {
    459459                ipc_answer_0(callid, EINVAL);   
    460460                ipc_answer_0(rid, EINVAL);
     
    464464        size_t bytes;
    465465        if (dentry->type == TMPFS_FILE) {
    466                 bytes = max(0, min(dentry->size - pos, len));
     466                bytes = max(0, min(dentry->size - pos, size));
    467467                (void) ipc_data_read_finalize(callid, dentry->data + pos,
    468468                    bytes);
     
    495495
    496496                (void) ipc_data_read_finalize(callid, namep->name,
    497                     strlen(namep->name) + 1);
     497                    str_size(namep->name) + 1);
    498498                bytes = 1;
    499499        }
     
    528528         */
    529529        ipc_callid_t callid;
    530         size_t len;
    531         if (!ipc_data_write_receive(&callid, &len)) {
     530        size_t size;
     531        if (!ipc_data_write_receive(&callid, &size)) {
    532532                ipc_answer_0(callid, EINVAL);   
    533533                ipc_answer_0(rid, EINVAL);
     
    538538         * Check whether the file needs to grow.
    539539         */
    540         if (pos + len <= dentry->size) {
     540        if (pos + size <= dentry->size) {
    541541                /* The file size is not changing. */
    542                 (void) ipc_data_write_finalize(callid, dentry->data + pos, len);
    543                 ipc_answer_2(rid, EOK, len, dentry->size);
    544                 return;
    545         }
    546         size_t delta = (pos + len) - dentry->size;
     542                (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
     543                ipc_answer_2(rid, EOK, size, dentry->size);
     544                return;
     545        }
     546        size_t delta = (pos + size) - dentry->size;
    547547        /*
    548548         * At this point, we are deliberately extremely straightforward and
     
    562562        dentry->size += delta;
    563563        dentry->data = newdata;
    564         (void) ipc_data_write_finalize(callid, dentry->data + pos, len);
    565         ipc_answer_2(rid, EOK, len, dentry->size);
     564        (void) ipc_data_write_finalize(callid, dentry->data + pos, size);
     565        ipc_answer_2(rid, EOK, size, dentry->size);
    566566}
    567567
  • uspace/srv/loader/main.c

    ra2c58f6 r92fd52d7  
    151151{
    152152        ipc_callid_t callid;
    153         size_t buf_len, arg_len;
     153        size_t buf_size, arg_size;
    154154        char *p;
    155155        int n;
    156156       
    157         if (!ipc_data_write_receive(&callid, &buf_len)) {
     157        if (!ipc_data_write_receive(&callid, &buf_size)) {
    158158                ipc_answer_0(callid, EINVAL);
    159159                ipc_answer_0(rid, EINVAL);
     
    171171        }
    172172       
    173         arg_buf = malloc(buf_len + 1);
     173        arg_buf = malloc(buf_size + 1);
    174174        if (!arg_buf) {
    175175                ipc_answer_0(callid, ENOMEM);
     
    178178        }
    179179       
    180         ipc_data_write_finalize(callid, arg_buf, buf_len);
    181        
    182         arg_buf[buf_len] = '\0';
     180        ipc_data_write_finalize(callid, arg_buf, buf_size);
     181       
     182        arg_buf[buf_size] = '\0';
    183183       
    184184        /*
     
    187187        p = arg_buf;
    188188        n = 0;
    189         while (p < arg_buf + buf_len) {
    190                 arg_len = strlen(p);
    191                 p = p + arg_len + 1;
     189        while (p < arg_buf + buf_size) {
     190                arg_size = str_size(p);
     191                p = p + arg_size + 1;
    192192                ++n;
    193193        }
     
    207207        p = arg_buf;
    208208        n = 0;
    209         while (p < arg_buf + buf_len) {
     209        while (p < arg_buf + buf_size) {
    210210                argv[n] = p;
    211211               
    212                 arg_len = strlen(p);
    213                 p = p + arg_len + 1;
     212                arg_size = str_size(p);
     213                p = p + arg_size + 1;
    214214                ++n;
    215215        }
  • uspace/srv/pci/libpci/names.c

    ra2c58f6 r92fd52d7  
    104104        unsigned int h = id_hash(cat, id12, id34);
    105105        struct id_entry *n = a->id_hash[h];
    106         int len = strlen((char *) text);
     106        int len = str_size((char *) text);
    107107
    108108        while (n && (n->id12 != id12 || n->id34 != id34 || n->cat != cat))
  • uspace/srv/rd/rd.c

    ra2c58f6 r92fd52d7  
    197197        req = async_send_2(phone, DEVMAP_DRIVER_REGISTER, 0, 0, &answer);
    198198
    199         retval = ipc_data_write_start(phone, (char *) name, strlen(name) + 1);
     199        retval = ipc_data_write_start(phone, (char *) name, str_size(name) + 1);
    200200
    201201        if (retval != EOK) {
     
    220220        req = async_send_2(driver_phone, DEVMAP_DEVICE_REGISTER, 0, 0, &answer);
    221221
    222         retval = ipc_data_write_start(driver_phone, (char *) name, strlen(name) + 1);
     222        retval = ipc_data_write_start(driver_phone, (char *) name,
     223            str_size(name) + 1);
    223224
    224225        if (retval != EOK) {
  • uspace/srv/vfs/vfs_ops.c

    ra2c58f6 r92fd52d7  
    9292                /* We already have the root FS. */
    9393                rwlock_write_lock(&namespace_rwlock);
    94                 if ((strlen(mp) == 1) && (mp[0] == '/')) {
     94                if (str_cmp(mp, "/") == 0) {
    9595                        /* Trying to mount root FS over root FS */
    9696                        rwlock_write_unlock(&namespace_rwlock);
     
    125125        } else {
    126126                /* We still don't have the root file system mounted. */
    127                 if ((strlen(mp) == 1) && (mp[0] == '/')) {
     127                if (str_cmp(mp, "/") == 0) {
    128128                        vfs_lookup_res_t mr_res;
    129129                        vfs_node_t *mr_node;
Note: See TracChangeset for help on using the changeset viewer.