Changeset 4cc0c9ee in mainline


Ignore:
Timestamp:
2009-01-22T14:22:12Z (15 years ago)
Author:
Tim Post <echo@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
bf226890
Parents:
fc11b8a
Message:

Get rid of cli_strdup(), cli_strtok(), cli_strtok_r(), just use facilities in libc

Location:
uspace/app/bdsh
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/AUTHORS

    rfc11b8a r4cc0c9ee  
    99* Based on the HelenOS testing sub-system written by Martin Decky
    1010
    11 * cli_strtok() and cli_strtok_r() (util.c) were adapted from the FreeBSD
    12   strtok() and strtok_r() functions written by Wes Peters.
    13 
    1411* read_line() (input.c) was written by Jiri Svoboda
    1512
  • uspace/app/bdsh/cmds/modules/mkdir/mkdir.c

    rfc11b8a r4cc0c9ee  
    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 = cli_strdup(path))) {
     96        if (NULL == (tmp = strdup(path))) {
    9797                cli_error(CL_ENOMEM, "%s: path too big?", cmdname);
    9898                return 1;
     
    129129
    130130        /* TODO: Canonify the path prior to tokenizing it, see below */
    131         dirs[i] = cli_strtok(tmp, "/");
     131        dirs[i] = strtok(tmp, "/");
    132132        while (dirs[i] && i < 255)
    133                 dirs[++i] = cli_strtok(NULL, "/");
     133                dirs[++i] = strtok(NULL, "/");
    134134
    135135        if (NULL == dirs[0])
  • uspace/app/bdsh/cmds/modules/touch/touch.c

    rfc11b8a r4cc0c9ee  
    3838#include <dirent.h>
    3939#include <sys/types.h>
     40#include <string.h>
    4041
    4142#include "config.h"
     
    8081
    8182        for (i = 1; i < argc; i ++) {
    82                 buff = cli_strdup(argv[i]);
     83                buff = strdup(argv[i]);
    8384                dirp = opendir(buff);
    8485                if (dirp) {
  • uspace/app/bdsh/exec.c

    rfc11b8a r4cc0c9ee  
    8181        }
    8282
    83         path_tok = cli_strdup(PATH);
     83        path_tok = strdup(PATH);
    8484
    8585        /* Extract the PATH env to a path[] array */
    86         path[n] = cli_strtok(path_tok, PATH_DELIM);
     86        path[n] = strtok(path_tok, PATH_DELIM);
    8787        while (NULL != path[n]) {
    8888                if ((strlen(path[n]) + x ) > PATH_MAX) {
     
    9292                        break;
    9393                }
    94                 path[++n] = cli_strtok(NULL, PATH_DELIM);
     94                path[++n] = strtok(NULL, PATH_DELIM);
    9595        }
    9696
     
    115115        char *tmp;
    116116
    117         tmp = cli_strdup(find_command(cmd));
     117        tmp = strdup(find_command(cmd));
    118118        free(found);
    119119
  • uspace/app/bdsh/input.c

    rfc11b8a r4cc0c9ee  
    5858                return CL_EFAIL;
    5959
    60         tmp = cli_strdup(usr->line);
     60        tmp = strdup(usr->line);
    6161
    62         cmd[n] = cli_strtok(tmp, " ");
     62        cmd[n] = strtok(tmp, " ");
    6363        while (cmd[n] && n < WORD_MAX) {
    64                 cmd[++n] = cli_strtok(NULL, " ");
     64                cmd[++n] = strtok(NULL, " ");
    6565        }
    6666
     
    139139        if (len == 0 || line[0] == '\n')
    140140                return;
    141         usr->line = cli_strdup(line);
     141        usr->line = strdup(line);
    142142
    143143        return;
  • uspace/app/bdsh/util.c

    rfc11b8a r4cc0c9ee  
    1 /* Copyright (c) 2008, Tim Post <tinkertim@gmail.com>
    2  * Copyright (C) 1998 by Wes Peters <wes@softweyr.com>
    3  * Copyright (c) 1988, 1993 The Regents of the University of California.
    4  * All rights reserved by all copyright holders.
     1/* Copyright (c) 2008, Tim Post <tinkertim@gmail.com> - All rights reserved
    52 *
    63 * Redistribution and use in source and binary forms, with or without
     
    3128 */
    3229
    33 /* NOTES:
    34  * 1 - Various functions were adapted from FreeBSD (copyright holders noted above)
    35  *     these functions are identified with comments.
    36  *
    37  * 2 - Some of these have since appeared in libc. They remain here for various
    38  *     reasons, such as the eventual integration of garbage collection for things
    39  *     that allocate memory and don't automatically free it.
    40  *
    41  * 3 - Things that expect a pointer to an allocated string do _no_ sanity checking
    42  *     if developing on a simulator with no debugger, take care :)
    43  */
    44 
    4530#include <stdio.h>
    4631#include <string.h>
     
    5439
    5540extern volatile int cli_errno;
    56 
    57 /* some platforms do not have strdup, implement it here.
    58  * Returns a pointer to an allocated string or NULL on failure */
    59 char * cli_strdup(const char *s1)
    60 {
    61         size_t len = strlen(s1) + 1;
    62         void *ret = malloc(len);
    63 
    64         if (ret == NULL) {
    65                 cli_errno = CL_ENOMEM;
    66                 return (char *) NULL;
    67         }
    68 
    69         cli_errno = CL_EOK;
    70         return (char *) memcpy(ret, s1, len);
    71 }
    72 
    73 /* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
    74 char * cli_strtok_r(char *s, const char *delim, char **last)
    75 {
    76         char *spanp, *tok;
    77         int c, sc;
    78 
    79         if (s == NULL && (s = *last) == NULL) {
    80                 cli_errno = CL_EFAIL;
    81                 return (NULL);
    82         }
    83 
    84 cont:
    85         c = *s++;
    86         for (spanp = (char *)delim; (sc = *spanp++) != 0;) {
    87                 if (c == sc)
    88                         goto cont;
    89         }
    90 
    91         if (c == 0) {           /* no non-delimiter characters */
    92                 *last = NULL;
    93                 return (NULL);
    94         }
    95 
    96         tok = s - 1;
    97 
    98         for (;;) {
    99                 c = *s++;
    100                 spanp = (char *)delim;
    101                 do {
    102                         if ((sc = *spanp++) == c) {
    103                                 if (c == 0)
    104                                         s = NULL;
    105                                 else
    106                                         s[-1] = '\0';
    107                                 *last = s;
    108                                 return (tok);
    109                         }
    110                 } while (sc != 0);
    111         }
    112 }
    113 
    114 /* Ported from FBSD strtok.c 8.1 (Berkeley) 6/4/93 */
    115 char * cli_strtok(char *s, const char *delim)
    116 {
    117         static char *last;
    118 
    119         return (cli_strtok_r(s, delim, &last));
    120 }
    12141
    12242/* Count and return the # of elements in an array */
  • uspace/app/bdsh/util.h

    rfc11b8a r4cc0c9ee  
    33
    44#include "scli.h"
    5 
    6 /* Internal string handlers */
    7 extern char * cli_strdup(const char *);
    8 extern char * cli_strtok_r(char *, const char *, char **);
    9 extern char * cli_strtok(char *, const char *);
    105
    116/* Utility functions */
Note: See TracChangeset for help on using the changeset viewer.