source: mainline/uspace/lib/posix/include/posix/string.h@ fdf97f6

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since fdf97f6 was fdf97f6, checked in by Vojtech Horky <vojtechhorky@…>, 13 years ago

Libposix functions are without posix_ prefix

Prior this commit, libposix headers declared all functions as posix_*
and used macros to rename e.g. strncpy to posix_strncpy in all (ported)
sources.

After this change, libposix headers look as normal POSIX compliant headers
(well, almost) and no renaming is done in the source codei (of the ported
applications). Instead, the renaming is done at object files level to
bypass weird problems that are bound to happen if you use macros.

The scheme is following. libposix headers use special macro to declare
the names. When included from outside, the functions have their normal
(standard) names. When included from the libposix sources, posix_ prefix
is added. Thus, when libposix is compiled and linked, it contains the
posix_* naming while compiling of ported software uses the normal
non-prefixed versions. This way the posix_* can use HelenOS libc without
any problem. Before linking, the posix_* prefix is removed from all
symbols and special prefix helenos_libc_ is added to all functions
that exists in our (HelenOS) libc and its name clashes with the POSIX
one.

The following happens, for example, to the open() function that exists in
both libposix and in libc.

  • Headers and sources of libc are left intact.
  • Copy of libc.a is made and to all clashing functions is added the helenos_libc prefix. This library is called libc4posix.a.
  • POSIX_DEF(open)(const char *) is used in libposix headers. This macro expands to plain open when included from the "outside world". But it expands to posix_open when included from libposix sources.
  • Libposix is compiled and linked, containing posix_open() that internally calls open() [the original one from libc].
  • Libposix is transformed - all open() are replaced with prefix variant: helenos_libc_open() and all posix_open() are replaced with open(). The transformed library is stored as libposixaslibc.a

Binutils and PCC are then linked with libc4posix and libposixaslibc
libraries instead of libc and libposix as was done previously.

WARNING: it looks that binutils, PCC and MSIM still works but not all
architectures were tested.

  • Property mode set to 100644
File size: 4.9 KB
Line 
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. */
67extern char * strtok_r(char *, const char *, char **);
68extern char * strtok(char *, const char *);
69
70/* From mem.h */
71// #define bzero(ptr, len) memset((ptr), 0, (len))
72extern void *memset(void *, int, size_t);
73extern void *memcpy(void *, const void *, size_t);
74extern void *memmove(void *, const void *, size_t);
75
76
77/* Copying and Concatenation */
78extern char *__POSIX_DEF__(strcpy)(char *restrict dest, const char *restrict src);
79extern char *__POSIX_DEF__(strncpy)(char *restrict dest, const char *restrict src, size_t n);
80extern char *__POSIX_DEF__(stpcpy)(char *restrict dest, const char *restrict src);
81extern char *__POSIX_DEF__(stpncpy)(char *restrict dest, const char *restrict src, size_t n);
82extern char *__POSIX_DEF__(strcat)(char *restrict dest, const char *restrict src);
83extern char *__POSIX_DEF__(strncat)(char *restrict dest, const char *restrict src, size_t n);
84extern void *__POSIX_DEF__(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
85extern char *__POSIX_DEF__(strdup)(const char *s);
86extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
87
88/* String/Array Comparison */
89extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);
90extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);
91extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);
92
93/* Search Functions */
94extern void *__POSIX_DEF__(memchr)(const void *mem, int c, size_t n);
95extern char *__POSIX_DEF__(strchr)(const char *s, int c);
96extern char *__POSIX_DEF__(strrchr)(const char *s, int c);
97extern char *gnu_strchrnul(const char *s, int c);
98extern char *__POSIX_DEF__(strpbrk)(const char *s1, const char *s2);
99extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);
100extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);
101extern char *__POSIX_DEF__(strstr)(const char *haystack, const char *needle);
102
103/* Collation Functions */
104extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);
105extern size_t __POSIX_DEF__(strxfrm)(char *restrict s1, const char *restrict s2, size_t n);
106
107/* Error Messages */
108extern char *__POSIX_DEF__(strerror)(int errnum);
109extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
110
111/* String Length */
112extern size_t __POSIX_DEF__(strlen)(const char *s);
113extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
114
115/* Signal Messages */
116extern char *__POSIX_DEF__(strsignal)(int signum);
117
118/* Legacy Declarations */
119#ifndef POSIX_STRINGS_H_
120extern int __POSIX_DEF__(ffs)(int i);
121extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
122extern 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 */
Note: See TracBrowser for help on using the repository browser.