Ignore:
Timestamp:
2013-02-25T19:11:50Z (13 years ago)
Author:
Vojtech Horky <vojtechhorky@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
1935591
Parents:
c84f1a4
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/include/posix/string.h

    rc84f1a4 rfdf97f6  
    3737#define POSIX_STRING_H_
    3838
     39#ifndef __POSIX_DEF__
     40#define __POSIX_DEF__(x) x
     41#endif
     42
    3943#include "sys/types.h"
    4044
     
    6569
    6670/* From mem.h */
    67 #define bzero(ptr, len)  memset((ptr), 0, (len))
     71// #define bzero(ptr, len)  memset((ptr), 0, (len))
    6872extern void *memset(void *, int, size_t);
    6973extern void *memcpy(void *, const void *, size_t);
     
    7276
    7377/* Copying and Concatenation */
    74 extern char *posix_strcpy(char *restrict dest, const char *restrict src);
    75 extern char *posix_strncpy(char *restrict dest, const char *restrict src, size_t n);
    76 extern char *posix_stpcpy(char *restrict dest, const char *restrict src);
    77 extern char *posix_stpncpy(char *restrict dest, const char *restrict src, size_t n);
    78 extern char *posix_strcat(char *restrict dest, const char *restrict src);
    79 extern char *posix_strncat(char *restrict dest, const char *restrict src, size_t n);
    80 extern void *posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n);
    81 extern char *posix_strdup(const char *s);
    82 extern char *posix_strndup(const char *s, size_t n);
     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);
    8387
    8488/* String/Array Comparison */
    85 extern int posix_memcmp(const void *mem1, const void *mem2, size_t n);
    86 extern int posix_strcmp(const char *s1, const char *s2);
    87 extern int posix_strncmp(const char *s1, const char *s2, size_t n);
     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);
    8892
    8993/* Search Functions */
    90 extern void *posix_memchr(const void *mem, int c, size_t n);
    91 extern char *posix_strchr(const char *s, int c);
    92 extern char *posix_strrchr(const char *s, int c);
     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);
    9397extern char *gnu_strchrnul(const char *s, int c);
    94 extern char *posix_strpbrk(const char *s1, const char *s2);
    95 extern size_t posix_strcspn(const char *s1, const char *s2);
    96 extern size_t posix_strspn(const char *s1, const char *s2);
    97 extern char *posix_strstr(const char *haystack, const char *needle);
     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);
    98102
    99103/* Collation Functions */
    100 extern int posix_strcoll(const char *s1, const char *s2);
    101 extern size_t posix_strxfrm(char *restrict s1, const char *restrict s2, size_t n);
     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);
    102106
    103107/* Error Messages */
    104 extern char *posix_strerror(int errnum);
    105 extern int posix_strerror_r(int errnum, char *buf, size_t bufsz);
     108extern char *__POSIX_DEF__(strerror)(int errnum);
     109extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
    106110
    107111/* String Length */
    108 extern size_t posix_strlen(const char *s);
    109 extern size_t posix_strnlen(const char *s, size_t n);
     112extern size_t __POSIX_DEF__(strlen)(const char *s);
     113extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
    110114
    111115/* Signal Messages */
    112 extern char *posix_strsignal(int signum);
     116extern char *__POSIX_DEF__(strsignal)(int signum);
    113117
    114118/* Legacy Declarations */
    115119#ifndef POSIX_STRINGS_H_
    116 extern int posix_ffs(int i);
    117 extern int posix_strcasecmp(const char *s1, const char *s2);
    118 extern int posix_strncasecmp(const char *s1, const char *s2, size_t n);
     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);
    119123#endif
    120124
    121 #ifndef LIBPOSIX_INTERNAL
    122         #define strcpy posix_strcpy
    123         #define strncpy posix_strncpy
    124         #define stpcpy posix_stpcpy
    125         #define stpncpy posix_stpncpy
    126         #define strcat posix_strcat
    127         #define strncat posix_strncat
    128         #define memccpy posix_memccpy
    129         #define strdup posix_strdup
    130         #define strndup posix_strndup
    131 
    132         #define memcmp posix_memcmp
    133         #define strcmp posix_strcmp
    134         #define strncmp posix_strncmp
    135 
    136         #define memchr posix_memchr
    137         #define strchr posix_strchr
    138         #define strrchr posix_strrchr
    139         #define strchrnul gnu_strchrnul
    140         #define strpbrk posix_strpbrk
    141         #define strcspn posix_strcspn
    142         #define strspn posix_strspn
    143         #define strstr posix_strstr
    144 
    145         #define strcoll posix_strcoll
    146         #define strxfrm posix_strxfrm
    147 
    148         #define strerror posix_strerror
    149         #define strerror_r posix_strerror_r
    150 
    151         #define strlen posix_strlen
    152         #define strnlen posix_strnlen
    153 
    154         #define strsignal posix_strsignal
    155 
    156         #define ffs posix_ffs
    157         #define strcasecmp posix_strcasecmp
    158         #define strncasecmp posix_strncasecmp
    159 #endif
    160125
    161126#endif  // POSIX_STRING_H_
Note: See TracChangeset for help on using the changeset viewer.