Changeset 3608 for trunk

Show
Ignore:
Timestamp:
09/26/08 20:42:40 (3 months ago)
Author:
stepan
Message:

* Add strsep (since strtok is considered obsolete)
* add a bunch of string function doxygen comments.

Signed-off-by: Stefan Reinauer <stepan@…>
Acked-by: Uwe Hermann <uwe@…>

Location:
trunk/payloads/libpayload
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/payloads/libpayload/include/libpayload.h

    r3605 r3608  
    111111 
    112112/** 
     113 * @defgroup usb USB functions 
     114 * @{ 
     115 */ 
     116int usb_initialize(void);                                                       
     117/** @} */ 
     118 
     119/** 
    113120 * @defgroup input Device functions 
    114121 * @{ @} 
     
    316323char *strdup(const char *s); 
    317324char *strstr(const char *h, const char *n); 
     325char *strsep(char **stringp, const char *delim); 
    318326/** @} */ 
    319327 
  • trunk/payloads/libpayload/libc/string.c

    r3539 r3608  
    129129} 
    130130 
     131/** 
     132 * Copy a string with a maximum length. 
     133 * 
     134 * @param d The destination memory. 
     135 * @param s The source string. 
     136 * @param n Copy at most n characters as length of the string. 
     137 * @return A pointer to the destination memory. 
     138 */ 
    131139char *strncpy(char *d, const char *s, size_t n) 
    132140{ 
     
    141149} 
    142150 
     151/** 
     152 * Copy a string. 
     153 * 
     154 * @param d The destination memory. 
     155 * @param s The source string. 
     156 * @return A pointer to the destination memory. 
     157 */ 
    143158char *strcpy(char *d, const char *s) 
    144159{ 
     
    146161} 
    147162 
     163/** 
     164 * Concatenates two strings with a maximum length. 
     165 * 
     166 * @param d The destination string. 
     167 * @param s The source string. 
     168 * @param n The target string will have a length of n characters at most. 
     169 * @return A pointer to the destination string. 
     170 */ 
    148171char *strncat(char *d, const char *s, size_t n) 
    149172{ 
     
    159182} 
    160183 
     184/** 
     185 * Find a character in a string. 
     186 * 
     187 * @param s The string. 
     188 * @param c The character. 
     189 * @return A pointer to the first occurence of the character in the 
     190 * string, or NULL if the character was not encountered within the string. 
     191 */ 
    161192char *strchr(const char *s, int c) 
    162193{ 
     
    171202} 
    172203 
     204/** 
     205 * Duplicate a string. 
     206 * 
     207 * @param s The string to duplicate. 
     208 * @return A pointer to the copy of the original string. 
     209 */ 
    173210char *strdup(const char *s) 
    174211{ 
     
    183220} 
    184221 
     222/** 
     223 * Find a substring within a string. 
     224 * 
     225 * @param h The haystack string. 
     226 * @param n The needle string (substring). 
     227 * @return A pointer to the first occurence of the substring in 
     228 * the string, or NULL if the substring was not encountered within the string. 
     229 */ 
    185230char *strstr(const char *h, const char *n) 
    186231{ 
     
    195240        return NULL; 
    196241} 
     242 
     243/** 
     244 * Separate strings. 
     245 * 
     246 * @param stringp reference of the string to separate. 
     247 * @param delim string containing all delimiters. 
     248 * @return Token string. 
     249 */ 
     250char *strsep(char **stringp, const char *delim) 
     251{ 
     252        char *walk, *token; 
     253 
     254        if (!stringp || !*stringp || !**stringp) 
     255                return NULL; 
     256 
     257        token = walk = *stringp; 
     258 
     259        /* Walk, search for delimiters */ 
     260        while(*walk && !strchr(delim, *walk)) 
     261                walk++; 
     262 
     263        if (*walk) { 
     264                /* NUL terminate */ 
     265                *walk = '\0'; 
     266                walk++; 
     267        } 
     268 
     269        *stringp = walk; 
     270 
     271        return token; 
     272} 
     273