| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Petr Koupy
|
|---|
| 3 | * Copyright (c) 2011 Jiri Zarevucky
|
|---|
| 4 | * All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
|---|
| 7 | * modification, are permitted provided that the following conditions
|
|---|
| 8 | * are met:
|
|---|
| 9 | *
|
|---|
| 10 | * - Redistributions of source code must retain the above copyright
|
|---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 14 | * documentation and/or other materials provided with the distribution.
|
|---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 16 | * derived from this software without specific prior written permission.
|
|---|
| 17 | *
|
|---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 28 | */
|
|---|
| 29 |
|
|---|
| 30 | /** @addtogroup libposix
|
|---|
| 31 | * @{
|
|---|
| 32 | */
|
|---|
| 33 | /** @file String manipulation.
|
|---|
| 34 | */
|
|---|
| 35 |
|
|---|
| 36 | #ifndef POSIX_STRING_H_
|
|---|
| 37 | #define POSIX_STRING_H_
|
|---|
| 38 |
|
|---|
| 39 | #ifndef __POSIX_DEF__
|
|---|
| 40 | #define __POSIX_DEF__(x) x
|
|---|
| 41 | #endif
|
|---|
| 42 |
|
|---|
| 43 | #include "sys/types.h"
|
|---|
| 44 |
|
|---|
| 45 | /*
|
|---|
| 46 | * TODO: not implemented due to missing locale support
|
|---|
| 47 | *
|
|---|
| 48 | * int strcoll_l(const char *, const char *, locale_t);
|
|---|
| 49 | * char *strerror_l(int, locale_t);
|
|---|
| 50 | * size_t strxfrm_l(char *restrict, const char *restrict, size_t, locale_t);
|
|---|
| 51 | */
|
|---|
| 52 |
|
|---|
| 53 | #ifndef NULL
|
|---|
| 54 | #define NULL ((void *) 0)
|
|---|
| 55 | #endif
|
|---|
| 56 |
|
|---|
| 57 | /*
|
|---|
| 58 | * These are the same as in HelenOS libc.
|
|---|
| 59 | * It would be possible to directly include <str.h> and <mem.h> but
|
|---|
| 60 | * it is better not to pollute POSIX namespace with other functions
|
|---|
| 61 | * defined in that header.
|
|---|
| 62 | *
|
|---|
| 63 | * Because libposix is always linked with libc, providing only these
|
|---|
| 64 | * forward declarations ought to be enough.
|
|---|
| 65 | */
|
|---|
| 66 | /* From str.h. */
|
|---|
| 67 | extern char * strtok_r(char *, const char *, char **);
|
|---|
| 68 | extern char * strtok(char *, const char *);
|
|---|
| 69 |
|
|---|
| 70 | /* From mem.h */
|
|---|
| 71 | // #define bzero(ptr, len) memset((ptr), 0, (len))
|
|---|
| 72 | extern void *memset(void *, int, size_t);
|
|---|
| 73 | extern void *memcpy(void *, const void *, size_t);
|
|---|
| 74 | extern void *memmove(void *, const void *, size_t);
|
|---|
| 75 |
|
|---|
| 76 |
|
|---|
| 77 | /* Copying and Concatenation */
|
|---|
| 78 | extern char *__POSIX_DEF__(strcpy)(char *restrict dest, const char *restrict src);
|
|---|
| 79 | extern char *__POSIX_DEF__(strncpy)(char *restrict dest, const char *restrict src, size_t n);
|
|---|
| 80 | extern char *__POSIX_DEF__(stpcpy)(char *restrict dest, const char *restrict src);
|
|---|
| 81 | extern char *__POSIX_DEF__(stpncpy)(char *restrict dest, const char *restrict src, size_t n);
|
|---|
| 82 | extern char *__POSIX_DEF__(strcat)(char *restrict dest, const char *restrict src);
|
|---|
| 83 | extern char *__POSIX_DEF__(strncat)(char *restrict dest, const char *restrict src, size_t n);
|
|---|
| 84 | extern void *__POSIX_DEF__(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
|
|---|
| 85 | extern char *__POSIX_DEF__(strdup)(const char *s);
|
|---|
| 86 | extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
|
|---|
| 87 |
|
|---|
| 88 | /* String/Array Comparison */
|
|---|
| 89 | extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);
|
|---|
| 90 | extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);
|
|---|
| 91 | extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);
|
|---|
| 92 |
|
|---|
| 93 | /* Search Functions */
|
|---|
| 94 | extern void *__POSIX_DEF__(memchr)(const void *mem, int c, size_t n);
|
|---|
| 95 | extern char *__POSIX_DEF__(strchr)(const char *s, int c);
|
|---|
| 96 | extern char *__POSIX_DEF__(strrchr)(const char *s, int c);
|
|---|
| 97 | extern char *gnu_strchrnul(const char *s, int c);
|
|---|
| 98 | extern char *__POSIX_DEF__(strpbrk)(const char *s1, const char *s2);
|
|---|
| 99 | extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);
|
|---|
| 100 | extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);
|
|---|
| 101 | extern char *__POSIX_DEF__(strstr)(const char *haystack, const char *needle);
|
|---|
| 102 |
|
|---|
| 103 | /* Collation Functions */
|
|---|
| 104 | extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);
|
|---|
| 105 | extern size_t __POSIX_DEF__(strxfrm)(char *restrict s1, const char *restrict s2, size_t n);
|
|---|
| 106 |
|
|---|
| 107 | /* Error Messages */
|
|---|
| 108 | extern char *__POSIX_DEF__(strerror)(int errnum);
|
|---|
| 109 | extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
|
|---|
| 110 |
|
|---|
| 111 | /* String Length */
|
|---|
| 112 | extern size_t __POSIX_DEF__(strlen)(const char *s);
|
|---|
| 113 | extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
|
|---|
| 114 |
|
|---|
| 115 | /* Signal Messages */
|
|---|
| 116 | extern char *__POSIX_DEF__(strsignal)(int signum);
|
|---|
| 117 |
|
|---|
| 118 | /* Legacy Declarations */
|
|---|
| 119 | #ifndef POSIX_STRINGS_H_
|
|---|
| 120 | extern int __POSIX_DEF__(ffs)(int i);
|
|---|
| 121 | extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
|
|---|
| 122 | extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);
|
|---|
| 123 | #endif
|
|---|
| 124 |
|
|---|
| 125 |
|
|---|
| 126 | #endif // POSIX_STRING_H_
|
|---|
| 127 |
|
|---|
| 128 | /** @}
|
|---|
| 129 | */
|
|---|