Changeset 2498b95 in mainline
- Timestamp:
- 2018-06-25T15:49:26Z (7 years ago)
- 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)
- Location:
- uspace/lib
- Files:
-
- 1 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/bithenge/src/helenos/common.h
rbfe90b6 r2498b95 73 73 } 74 74 75 static inline void *memchr(const void *s, int c, size_t n)76 {77 for (size_t i = 0; i < n; i++)78 if (((char *)s)[i] == c)79 return (void *)(s + i);80 return NULL;81 }82 83 75 static inline errno_t bithenge_parse_int(const char *start, bithenge_int_t *result) 84 76 { -
uspace/lib/c/Makefile
rbfe90b6 r2498b95 193 193 test/fibril/timer.c \ 194 194 test/main.c \ 195 test/mem.c \ 195 196 test/io/table.c \ 196 197 test/stdio/scanf.c \ -
uspace/lib/c/generic/mem.c
rbfe90b6 r2498b95 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 20 08 Jiri Svoboda3 * Copyright (c) 2018 Jiri Svoboda 4 4 * All rights reserved. 5 5 * … … 252 252 } 253 253 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 */ 263 void *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 254 277 /** @} 255 278 */ -
uspace/lib/c/include/mem.h
rbfe90b6 r2498b95 1 1 /* 2 2 * Copyright (c) 2005 Martin Decky 3 * Copyright (c) 2018 Jiri Svoboda 3 4 * All rights reserved. 4 5 * … … 49 50 extern int memcmp(const void *, const void *, size_t) 50 51 __attribute__((nonnull(1, 2))); 52 extern void *memchr(const void *, int, size_t) 53 __attribute__((nonnull(1))); 51 54 52 55 #endif -
uspace/lib/c/test/main.c
rbfe90b6 r2498b95 34 34 PCUT_IMPORT(circ_buf); 35 35 PCUT_IMPORT(fibril_timer); 36 PCUT_IMPORT(mem); 36 37 PCUT_IMPORT(odict); 37 38 PCUT_IMPORT(qsort); -
uspace/lib/posix/include/posix/string.h
rbfe90b6 r2498b95 36 36 #ifndef POSIX_STRING_H_ 37 37 #define POSIX_STRING_H_ 38 39 #include "sys/types.h"40 41 38 /* 42 39 * TODO: not implemented due to missing locale support … … 48 45 49 46 #include <_bits/NULL.h> 47 #include <_bits/size_t.h> 50 48 51 /* 52 * These are the same as in HelenOS libc. 53 * It would be possible to directly include <str.h> and <mem.h> but 54 * it is better not to pollute POSIX namespace with other functions 55 * defined in that header. 56 * 57 * Because libposix is always linked with libc, providing only these 58 * forward declarations ought to be enough. 59 */ 60 61 /* From mem.h */ 62 // #define bzero(ptr, len) memset((ptr), 0, (len)) 63 extern void *memset(void *, int, size_t) 64 __attribute__((nonnull(1))); 65 extern void *memcpy(void *, const void *, size_t) 66 __attribute__((nonnull(1, 2))); 67 extern void *memmove(void *, const void *, size_t) 68 __attribute__((nonnull(1, 2))); 69 49 #include "libc/mem.h" 70 50 71 51 /* Copying and Concatenation */ … … 80 60 extern char *strndup(const char *s, size_t n); 81 61 82 /* String/Array Comparison */ 83 extern int memcmp(const void *mem1, const void *mem2, size_t n); 62 /* String Comparison */ 84 63 extern int strcmp(const char *s1, const char *s2); 85 64 extern int strncmp(const char *s1, const char *s2, size_t n); 86 65 87 66 /* Search Functions */ 88 extern void *memchr(const void *mem, int c, size_t n);89 67 extern char *strchr(const char *s, int c); 90 68 extern char *strrchr(const char *s, int c); … … 122 100 #endif 123 101 124 125 102 #endif // POSIX_STRING_H_ 126 103 -
uspace/lib/posix/src/string.c
rbfe90b6 r2498b95 288 288 289 289 return 0; 290 }291 292 /**293 * Find byte in memory.294 *295 * @param mem Memory area in which to look for the byte.296 * @param c Byte to look for.297 * @param n Maximum number of bytes to be inspected.298 * @return Pointer to the specified byte on success,299 * NULL pointer otherwise.300 */301 void *memchr(const void *mem, int c, size_t n)302 {303 assert(mem != NULL);304 305 const unsigned char *s = mem;306 307 for (size_t i = 0; i < n; ++i) {308 if (s[i] == (unsigned char) c) {309 return (void *) &s[i];310 }311 }312 return NULL;313 290 } 314 291
Note:
See TracChangeset
for help on using the changeset viewer.