Ignore:
Timestamp:
2013-02-25T19:11:50Z (11 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/stdlib.h

    rc84f1a4 rfdf97f6  
    3737#define POSIX_STDLIB_H_
    3838
     39#ifndef __POSIX_DEF__
     40#define __POSIX_DEF__(x) x
     41#endif
     42
    3943#include "sys/types.h"
    4044
     
    4953#define EXIT_SUCCESS 0
    5054#define _Exit exit
    51 extern int posix_atexit(void (*func)(void));
     55extern int __POSIX_DEF__(atexit)(void (*func)(void));
    5256extern void exit(int status);
    5357extern void abort(void) __attribute__((noreturn));
    5458
    5559/* Absolute Value */
    56 extern int posix_abs(int i);
    57 extern long posix_labs(long i);
    58 extern long long posix_llabs(long long i);
     60extern int __POSIX_DEF__(abs)(int i);
     61extern long __POSIX_DEF__(labs)(long i);
     62extern long long __POSIX_DEF__(llabs)(long long i);
    5963
    6064/* Integer Division */
     
    6266typedef struct {
    6367        int quot, rem;
    64 } posix_div_t;
     68} __POSIX_DEF__(div_t);
    6569
    6670typedef struct {
    6771        long quot, rem;
    68 } posix_ldiv_t;
     72} __POSIX_DEF__(ldiv_t);
    6973
    7074typedef struct {
    7175        long long quot, rem;
    72 } posix_lldiv_t;
     76} __POSIX_DEF__(lldiv_t);
    7377
    74 extern posix_div_t posix_div(int numer, int denom);
    75 extern posix_ldiv_t posix_ldiv(long numer, long denom);
    76 extern posix_lldiv_t posix_lldiv(long long numer, long long denom);
     78extern __POSIX_DEF__(div_t) __POSIX_DEF__(div)(int numer, int denom);
     79extern __POSIX_DEF__(ldiv_t) __POSIX_DEF__(ldiv)(long numer, long denom);
     80extern __POSIX_DEF__(lldiv_t) __POSIX_DEF__(lldiv)(long long numer, long long denom);
    7781
    7882/* Array Functions */
    79 extern void posix_qsort(void *array, size_t count, size_t size,
     83extern void __POSIX_DEF__(qsort)(void *array, size_t count, size_t size,
    8084    int (*compare)(const void *, const void *));
    81 extern void *posix_bsearch(const void *key, const void *base,
     85extern void *__POSIX_DEF__(bsearch)(const void *key, const void *base,
    8286    size_t nmemb, size_t size, int (*compar)(const void *, const void *));
    8387
    8488/* Environment Access */
    85 extern char *posix_getenv(const char *name);
    86 extern int posix_putenv(char *string);
    87 extern int posix_system(const char *string);
     89extern char *__POSIX_DEF__(getenv)(const char *name);
     90extern int __POSIX_DEF__(putenv)(char *string);
     91extern int __POSIX_DEF__(system)(const char *string);
    8892
    8993/* Symbolic Links */
    90 extern char *posix_realpath(const char *restrict name, char *restrict resolved);
     94extern char *__POSIX_DEF__(realpath)(const char *restrict name, char *restrict resolved);
    9195
    9296/* Floating Point Conversion */
    93 extern double posix_atof(const char *nptr);
    94 extern float posix_strtof(const char *restrict nptr, char **restrict endptr);
    95 extern double posix_strtod(const char *restrict nptr, char **restrict endptr);
    96 extern long double posix_strtold(const char *restrict nptr, char **restrict endptr);
     97extern double __POSIX_DEF__(atof)(const char *nptr);
     98extern float __POSIX_DEF__(strtof)(const char *restrict nptr, char **restrict endptr);
     99extern double __POSIX_DEF__(strtod)(const char *restrict nptr, char **restrict endptr);
     100extern long double __POSIX_DEF__(strtold)(const char *restrict nptr, char **restrict endptr);
    97101
    98102/* Integer Conversion */
    99 extern int posix_atoi(const char *nptr);
    100 extern long int posix_atol(const char *nptr);
    101 extern long long int posix_atoll(const char *nptr);
    102 extern long int posix_strtol(const char *restrict nptr,
     103extern int __POSIX_DEF__(atoi)(const char *nptr);
     104extern long int __POSIX_DEF__(atol)(const char *nptr);
     105extern long long int __POSIX_DEF__(atoll)(const char *nptr);
     106extern long int __POSIX_DEF__(strtol)(const char *restrict nptr,
    103107    char **restrict endptr, int base);
    104 extern long long int posix_strtoll(const char *restrict nptr,
     108extern long long int __POSIX_DEF__(strtoll)(const char *restrict nptr,
    105109    char **restrict endptr, int base);
    106 extern unsigned long int posix_strtoul(const char *restrict nptr,
     110extern unsigned long int __POSIX_DEF__(strtoul)(const char *restrict nptr,
    107111    char **restrict endptr, int base);
    108 extern unsigned long long int posix_strtoull(
     112extern unsigned long long int __POSIX_DEF__(strtoull)(
    109113    const char *restrict nptr, char **restrict endptr, int base);
    110114
    111115/* Memory Allocation */
    112 extern void *posix_malloc(size_t size);
    113 extern void *posix_calloc(size_t nelem, size_t elsize);
    114 extern void *posix_realloc(void *ptr, size_t size);
    115 extern void posix_free(void *ptr);
     116extern void *__POSIX_DEF__(malloc)(size_t size);
     117extern void *__POSIX_DEF__(calloc)(size_t nelem, size_t elsize);
     118extern void *__POSIX_DEF__(realloc)(void *ptr, size_t size);
     119extern void __POSIX_DEF__(free)(void *ptr);
    116120
    117121/* Temporary Files */
    118 extern int posix_mkstemp(char *tmpl);
     122extern int __POSIX_DEF__(mkstemp)(char *tmpl);
    119123
    120124/* Legacy Declarations */
    121 extern char *posix_mktemp(char *tmpl);
     125extern char *__POSIX_DEF__(mktemp)(char *tmpl);
    122126extern int bsd_getloadavg(double loadavg[], int nelem);
    123 
    124 #ifndef LIBPOSIX_INTERNAL
    125         #define atexit posix_atexit
    126 
    127         #define abs posix_abs
    128         #define labs posix_labs
    129         #define llabs posix_llabs
    130 
    131         #define div_t posix_div_t
    132         #define ldiv_t posix_ldiv_t
    133         #define lldiv_t posix_lldiv_t
    134         #define div posix_div
    135         #define ldiv posix_ldiv
    136         #define lldiv posix_lldiv
    137 
    138         #define qsort posix_qsort
    139         #define bsearch posix_bsearch
    140 
    141         #define getenv posix_getenv
    142         #define putenv posix_putenv
    143         #define system posix_system
    144 
    145         #define realpath posix_realpath
    146        
    147         #define atof posix_atof
    148         #define strtof posix_strtof
    149         #define strtod posix_strtod
    150         #define strtold posix_strtold
    151        
    152         #define atoi posix_atoi
    153         #define atol posix_atol
    154         #define atoll posix_atoll
    155         #define strtol posix_strtol
    156         #define strtoll posix_strtoll
    157         #define strtoul posix_strtoul
    158         #define strtoull posix_strtoull
    159 
    160         #define malloc posix_malloc
    161         #define calloc posix_calloc
    162         #define realloc posix_realloc
    163         #define free posix_free
    164 
    165         #define mkstemp posix_mkstemp
    166 
    167         #define mktemp posix_mktemp
    168         #define getloadavg bsd_getloadavg
    169 #endif
    170127
    171128#endif  // POSIX_STDLIB_H_
Note: See TracChangeset for help on using the changeset viewer.