PageRenderTime 28ms CodeModel.GetById 13ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/uspace/lib/posix/include/posix/string.h

https://gitlab.com/vhelen/vhelen
C Header | 131 lines | 47 code | 22 blank | 62 comment | 0 complexity | c1488fbbdf547a9d6c15945e3547c0ea MD5 | raw file
  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
 67/* From mem.h */
 68// #define bzero(ptr, len)  memset((ptr), 0, (len))
 69extern void *memset(void *, int, size_t);
 70extern void *memcpy(void *, const void *, size_t);
 71extern void *memmove(void *, const void *, size_t);
 72
 73
 74/* Copying and Concatenation */
 75extern char *__POSIX_DEF__(strcpy)(char *restrict dest, const char *restrict src);
 76extern char *__POSIX_DEF__(strncpy)(char *restrict dest, const char *restrict src, size_t n);
 77extern char *__POSIX_DEF__(stpcpy)(char *restrict dest, const char *restrict src);
 78extern char *__POSIX_DEF__(stpncpy)(char *restrict dest, const char *restrict src, size_t n);
 79extern char *__POSIX_DEF__(strcat)(char *restrict dest, const char *restrict src);
 80extern char *__POSIX_DEF__(strncat)(char *restrict dest, const char *restrict src, size_t n);
 81extern void *__POSIX_DEF__(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
 82extern char *__POSIX_DEF__(strdup)(const char *s);
 83extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
 84
 85/* String/Array Comparison */
 86extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);
 87extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);
 88extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);
 89
 90/* Search Functions */
 91extern void *__POSIX_DEF__(memchr)(const void *mem, int c, size_t n);
 92extern char *__POSIX_DEF__(strchr)(const char *s, int c);
 93extern char *__POSIX_DEF__(strrchr)(const char *s, int c);
 94extern char *gnu_strchrnul(const char *s, int c);
 95extern char *__POSIX_DEF__(strpbrk)(const char *s1, const char *s2);
 96extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);
 97extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);
 98extern char *__POSIX_DEF__(strstr)(const char *haystack, const char *needle);
 99
100/* Tokenization functions. */
101extern char *__POSIX_DEF__(strtok_r)(char *, const char *, char **);
102extern char *__POSIX_DEF__(strtok)(char *, const char *);
103
104
105/* Collation Functions */
106extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);
107extern size_t __POSIX_DEF__(strxfrm)(char *restrict s1, const char *restrict s2, size_t n);
108
109/* Error Messages */
110extern char *__POSIX_DEF__(strerror)(int errnum);
111extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
112
113/* String Length */
114extern size_t __POSIX_DEF__(strlen)(const char *s);
115extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
116
117/* Signal Messages */
118extern char *__POSIX_DEF__(strsignal)(int signum);
119
120/* Legacy Declarations */
121#ifndef POSIX_STRINGS_H_
122extern int __POSIX_DEF__(ffs)(int i);
123extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
124extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);
125#endif
126
127
128#endif  // POSIX_STRING_H_
129
130/** @}
131 */