Changeset a35b458 in mainline for uspace/lib/posix/src/string.c


Ignore:
Timestamp:
2018-03-02T20:10:49Z (6 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f1380b7
Parents:
3061bc1
git-author:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
git-committer:
Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
Message:

style: Remove trailing whitespace on _all_ lines, including empty ones, for particular file types.

Command used: tools/srepl '\s\+$' '' -- *.c *.h *.py *.sh *.s *.S *.ag

Currently, whitespace on empty lines is very inconsistent.
There are two basic choices: Either remove the whitespace, or keep empty lines
indented to the level of surrounding code. The former is AFAICT more common,
and also much easier to do automatically.

Alternatively, we could write script for automatic indentation, and use that
instead. However, if such a script exists, it's possible to use the indented
style locally, by having the editor apply relevant conversions on load/save,
without affecting remote repository. IMO, it makes more sense to adopt
the simpler rule.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/src/string.c

    r3061bc1 ra35b458  
    6262                ++s1;
    6363        }
    64        
     64
    6565        return (char *) s1;
    6666}
     
    107107        for (size_t i = 0; ; ++i) {
    108108                dest[i] = src[i];
    109                
     109
    110110                if (src[i] == '\0') {
    111111                        /* pointer to the terminating nul character */
     
    113113                }
    114114        }
    115        
     115
    116116        /* unreachable */
    117117        return NULL;
     
    133133        for (size_t i = 0; i < n; ++i) {
    134134                dest[i] = src[i];
    135        
     135
    136136                /* the standard requires that nul characters
    137137                 * are appended to the length of n, in case src is shorter
     
    145145                }
    146146        }
    147        
     147
    148148        return &dest[n];
    149149}
     
    197197        assert(dest != NULL);
    198198        assert(src != NULL);
    199        
     199
    200200        unsigned char* bdest = dest;
    201201        const unsigned char* bsrc = src;
    202        
     202
    203203        for (size_t i = 0; i < n; ++i) {
    204204                bdest[i] = bsrc[i];
    205        
     205
    206206                if (bsrc[i] == (unsigned char) c) {
    207207                        /* pointer to the next byte */
     
    209209                }
    210210        }
    211        
     211
    212212        return NULL;
    213213}
     
    301301{
    302302        assert(mem != NULL);
    303        
     303
    304304        const unsigned char *s = mem;
    305        
     305
    306306        for (size_t i = 0; i < n; ++i) {
    307307                if (s[i] == (unsigned char) c) {
     
    323323{
    324324        assert(s != NULL);
    325        
     325
    326326        char *res = gnu_strchrnul(s, c);
    327327        return (*res == c) ? res : NULL;
     
    339339{
    340340        assert(s != NULL);
    341        
     341
    342342        const char *ptr = strchr(s, '\0');
    343        
     343
    344344        /* the same as in strchr, except it loops in reverse direction */
    345345        while (*ptr != (char) c) {
     
    365365{
    366366        assert(s != NULL);
    367        
     367
    368368        while (*s != c && *s != '\0') {
    369369                s++;
    370370        }
    371        
     371
    372372        return (char *) s;
    373373}
     
    439439        assert(haystack != NULL);
    440440        assert(needle != NULL);
    441        
     441
    442442        /* Special case - needle is an empty string. */
    443443        if (needle[0] == '\0') {
    444444                return (char *) haystack;
    445445        }
    446        
     446
    447447        /* Preprocess needle. */
    448448        size_t nlen = strlen(needle);
    449449        size_t prefix_table[nlen + 1];
    450        
     450
    451451        {
    452452                size_t i = 0;
    453453                ssize_t j = -1;
    454                
     454
    455455                prefix_table[i] = j;
    456                
     456
    457457                while (i < nlen) {
    458458                        while (j >= 0 && needle[i] != needle[j]) {
     
    463463                }
    464464        }
    465        
     465
    466466        /* Search needle using the precomputed table. */
    467467        size_t npos = 0;
    468        
     468
    469469        for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) {
    470470                while (npos != 0 && haystack[hpos] != needle[npos]) {
    471471                        npos = prefix_table[npos];
    472472                }
    473                
     473
    474474                if (haystack[hpos] == needle[npos]) {
    475475                        npos++;
    476                        
     476
    477477                        if (npos == nlen) {
    478478                                return (char *) (haystack + hpos - nlen + 1);
     
    480480                }
    481481        }
    482        
     482
    483483        return NULL;
    484484}
     
    604604{
    605605        assert(buf != NULL);
    606        
     606
    607607        char *errstr = strerror(errnum);
    608        
     608
    609609        if (strlen(errstr) + 1 > bufsz) {
    610610                return ERANGE;
     
    625625{
    626626        assert(s != NULL);
    627        
     627
    628628        return (size_t) (strchr(s, '\0') - s);
    629629}
     
    639639{
    640640        assert(s != NULL);
    641        
     641
    642642        for (size_t sz = 0; sz < n; ++sz) {
    643                
     643
    644644                if (s[sz] == '\0') {
    645645                        return sz;
    646646                }
    647647        }
    648        
     648
    649649        return n;
    650650}
Note: See TracChangeset for help on using the changeset viewer.