Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/mem.c

    r1433ecda 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 */
Note: See TracChangeset for help on using the changeset viewer.