/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. /** @addtogroup libposix
  30. * @{
  31. */
  32. /** @file String manipulation.
  33. */
  34. #ifndef POSIX_STRING_H_
  35. #define POSIX_STRING_H_
  36. #ifndef __POSIX_DEF__
  37. #define __POSIX_DEF__(x) x
  38. #endif
  39. #include "sys/types.h"
  40. /*
  41. * TODO: not implemented due to missing locale support
  42. *
  43. * int strcoll_l(const char *, const char *, locale_t);
  44. * char *strerror_l(int, locale_t);
  45. * size_t strxfrm_l(char *restrict, const char *restrict, size_t, locale_t);
  46. */
  47. #ifndef NULL
  48. #define NULL ((void *) 0)
  49. #endif
  50. /*
  51. * These are the same as in HelenOS libc.
  52. * It would be possible to directly include <str.h> and <mem.h> but
  53. * it is better not to pollute POSIX namespace with other functions
  54. * defined in that header.
  55. *
  56. * Because libposix is always linked with libc, providing only these
  57. * forward declarations ought to be enough.
  58. */
  59. /* From mem.h */
  60. // #define bzero(ptr, len) memset((ptr), 0, (len))
  61. extern void *memset(void *, int, size_t);
  62. extern void *memcpy(void *, const void *, size_t);
  63. extern void *memmove(void *, const void *, size_t);
  64. /* Copying and Concatenation */
  65. extern char *__POSIX_DEF__(strcpy)(char *restrict dest, const char *restrict src);
  66. extern char *__POSIX_DEF__(strncpy)(char *restrict dest, const char *restrict src, size_t n);
  67. extern char *__POSIX_DEF__(stpcpy)(char *restrict dest, const char *restrict src);
  68. extern char *__POSIX_DEF__(stpncpy)(char *restrict dest, const char *restrict src, size_t n);
  69. extern char *__POSIX_DEF__(strcat)(char *restrict dest, const char *restrict src);
  70. extern char *__POSIX_DEF__(strncat)(char *restrict dest, const char *restrict src, size_t n);
  71. extern void *__POSIX_DEF__(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
  72. extern char *__POSIX_DEF__(strdup)(const char *s);
  73. extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
  74. /* String/Array Comparison */
  75. extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);
  76. extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);
  77. extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);
  78. /* Search Functions */
  79. extern void *__POSIX_DEF__(memchr)(const void *mem, int c, size_t n);
  80. extern char *__POSIX_DEF__(strchr)(const char *s, int c);
  81. extern char *__POSIX_DEF__(strrchr)(const char *s, int c);
  82. extern char *gnu_strchrnul(const char *s, int c);
  83. extern char *__POSIX_DEF__(strpbrk)(const char *s1, const char *s2);
  84. extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);
  85. extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);
  86. extern char *__POSIX_DEF__(strstr)(const char *haystack, const char *needle);
  87. /* Tokenization functions. */
  88. extern char *__POSIX_DEF__(strtok_r)(char *, const char *, char **);
  89. extern char *__POSIX_DEF__(strtok)(char *, const char *);
  90. /* Collation Functions */
  91. extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);
  92. extern size_t __POSIX_DEF__(strxfrm)(char *restrict s1, const char *restrict s2, size_t n);
  93. /* Error Messages */
  94. extern char *__POSIX_DEF__(strerror)(int errnum);
  95. extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
  96. /* String Length */
  97. extern size_t __POSIX_DEF__(strlen)(const char *s);
  98. extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
  99. /* Signal Messages */
  100. extern char *__POSIX_DEF__(strsignal)(int signum);
  101. /* Legacy Declarations */
  102. #ifndef POSIX_STRINGS_H_
  103. extern int __POSIX_DEF__(ffs)(int i);
  104. extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
  105. extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);
  106. #endif
  107. #endif // POSIX_STRING_H_
  108. /** @}
  109. */