Changeset 2498b95 in mainline for uspace/lib/c


Ignore:
Timestamp:
2018-06-25T15:49:26Z (7 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
fbfe59d
Parents:
bfe90b6
git-author:
Jiri Svoboda <jiri@…> (2018-06-24 19:48:37)
git-committer:
Jiri Svoboda <jiri@…> (2018-06-25 15:49:26)
Message:

Move memchr to libc and add tests for other memxxx functions.

Location:
uspace/lib/c
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/Makefile

    rbfe90b6 r2498b95  
    193193        test/fibril/timer.c \
    194194        test/main.c \
     195        test/mem.c \
    195196        test/io/table.c \
    196197        test/stdio/scanf.c \
  • uspace/lib/c/generic/mem.c

    rbfe90b6 r2498b95  
    11/*
    22 * Copyright (c) 2005 Martin Decky
    3  * Copyright (c) 2008 Jiri Svoboda
     3 * Copyright (c) 2018 Jiri Svoboda
    44 * All rights reserved.
    55 *
     
    252252}
    253253
     254/** Search memory area.
     255 *
     256 * @param s Memory area
     257 * @param c Character (byte) to search for
     258 * @param n Size of memory area in bytes
     259 *
     260 * @return Pointer to the first occurrence of @a c in the first @a n
     261 *         bytes of @a s or @c NULL if not found.
     262 */
     263void *memchr(const void *s, int c, size_t n)
     264{
     265        uint8_t *u = (uint8_t *) s;
     266        unsigned char uc = (unsigned char) c;
     267        size_t i;
     268
     269        for (i = 0; i < n; i++) {
     270                if (u[i] == uc)
     271                        return (void *) &u[i];
     272        }
     273
     274        return NULL;
     275}
     276
    254277/** @}
    255278 */
  • uspace/lib/c/include/mem.h

    rbfe90b6 r2498b95  
    11/*
    22 * Copyright (c) 2005 Martin Decky
     3 * Copyright (c) 2018 Jiri Svoboda
    34 * All rights reserved.
    45 *
     
    4950extern int memcmp(const void *, const void *, size_t)
    5051    __attribute__((nonnull(1, 2)));
     52extern void *memchr(const void *, int, size_t)
     53    __attribute__((nonnull(1)));
    5154
    5255#endif
  • uspace/lib/c/test/main.c

    rbfe90b6 r2498b95  
    3434PCUT_IMPORT(circ_buf);
    3535PCUT_IMPORT(fibril_timer);
     36PCUT_IMPORT(mem);
    3637PCUT_IMPORT(odict);
    3738PCUT_IMPORT(qsort);
Note: See TracChangeset for help on using the changeset viewer.