Changeset 7f9df7b9 in mainline for uspace/lib/posix/src/stdlib.c


Ignore:
Timestamp:
2018-01-22T22:42:57Z (7 years ago)
Author:
Jiří Zárevúcky <zarevucky.jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
7a08c70
Parents:
e0f47f5
Message:

Remove unnecessary symbol renaming from libposix.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/posix/src/stdlib.c

    re0f47f5 r7f9df7b9  
    3434 */
    3535
    36 #define LIBPOSIX_INTERNAL
    37 #define __POSIX_DEF__(x) posix_##x
    38 
    3936#include "internal/common.h"
    4037#include "posix/stdlib.h"
     
    6057 * @param compare
    6158 */
    62 int posix_atexit(void (*func)(void))
     59int atexit(void (*func)(void))
    6360{
    6461        // TODO: low priority, just a compile-time dependency of binutils
     
    7370 * @return Absolute value of the parameter.
    7471 */
    75 int posix_abs(int i)
     72int abs(int i)
    7673{
    7774        return i < 0 ? -i : i;
     
    8481 * @return Absolute value of the parameter.
    8582 */
    86 long posix_labs(long i)
     83long labs(long i)
    8784{
    8885        return i < 0 ? -i : i;
     
    9592 * @return Absolute value of the parameter.
    9693 */
    97 long long posix_llabs(long long i)
     94long long llabs(long long i)
    9895{
    9996        return i < 0 ? -i : i;
     
    107104 * @return Quotient and remainder packed into structure.
    108105 */
    109 posix_div_t posix_div(int numer, int denom)
    110 {
    111         return (posix_div_t) { .quot = numer / denom, .rem = numer % denom };
     106div_t div(int numer, int denom)
     107{
     108        return (div_t) { .quot = numer / denom, .rem = numer % denom };
    112109}
    113110
     
    119116 * @return Quotient and remainder packed into structure.
    120117 */
    121 posix_ldiv_t posix_ldiv(long numer, long denom)
    122 {
    123         return (posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };
     118ldiv_t ldiv(long numer, long denom)
     119{
     120        return (ldiv_t) { .quot = numer / denom, .rem = numer % denom };
    124121}
    125122
     
    131128 * @return Quotient and remainder packed into structure.
    132129 */
    133 posix_lldiv_t posix_lldiv(long long numer, long long denom)
    134 {
    135         return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom };
    136 }
    137 
    138 /**
    139  * Array sorting utilizing the quicksort algorithm.
    140  *
    141  * @param array Array of elements to sort.
    142  * @param count Number of elements in the array.
    143  * @param size Width of each element.
    144  * @param compare Decides relative ordering of two elements.
    145  */
    146 void posix_qsort(void *array, size_t count, size_t size,
    147     int (*compare)(const void *, const void *))
    148 {
    149         qsort(array, count, size, compare);
     130lldiv_t lldiv(long long numer, long long denom)
     131{
     132        return (lldiv_t) { .quot = numer / denom, .rem = numer % denom };
    150133}
    151134
     
    160143 * @return Pointer to a matching element, or NULL if none can be found.
    161144 */
    162 void *posix_bsearch(const void *key, const void *base,
     145void *bsearch(const void *key, const void *base,
    163146    size_t nmemb, size_t size, int (*compar)(const void *, const void *))
    164147{
     
    195178 * @return Value of the variable or NULL if such variable does not exist.
    196179 */
    197 char *posix_getenv(const char *name)
     180char *getenv(const char *name)
    198181{
    199182        return NULL;
     
    206189 * @return
    207190 */
    208 int posix_putenv(char *string)
     191int putenv(char *string)
    209192{
    210193        // TODO: low priority, just a compile-time dependency of binutils
     
    221204 *     or not (zero).
    222205 */
    223 int posix_system(const char *string) {
     206int system(const char *string) {
    224207        // TODO: does nothing at the moment
    225208        not_implemented();
     
    237220 *
    238221 */
    239 char *posix_realpath(const char *restrict name, char *restrict resolved)
     222char *realpath(const char *restrict name, char *restrict resolved)
    240223{
    241224        #ifndef PATH_MAX
     
    279262/**
    280263 * Converts a string representation of a floating-point number to
    281  * its native representation. See posix_strtold().
     264 * its native representation. See strtold().
    282265 *
    283266 * @param nptr String representation of a floating-point number.
    284267 * @return Double-precision number resulting from the string conversion.
    285268 */
    286 double posix_atof(const char *nptr)
    287 {
    288         return posix_strtod(nptr, NULL);
     269double atof(const char *nptr)
     270{
     271        return strtod(nptr, NULL);
    289272}
    290273
    291274/**
    292275 * Converts a string representation of a floating-point number to
    293  * its native representation. See posix_strtold().
     276 * its native representation. See strtold().
    294277 *
    295278 * @param nptr String representation of a floating-point number.
     
    298281 * @return Single-precision number resulting from the string conversion.
    299282 */
    300 float posix_strtof(const char *restrict nptr, char **restrict endptr)
    301 {
    302         return (float) posix_strtold(nptr, endptr);
     283float strtof(const char *restrict nptr, char **restrict endptr)
     284{
     285        return (float) strtold(nptr, endptr);
    303286}
    304287
    305288/**
    306289 * Converts a string representation of a floating-point number to
    307  * its native representation. See posix_strtold().
     290 * its native representation. See strtold().
    308291 *
    309292 * @param nptr String representation of a floating-point number.
     
    312295 * @return Double-precision number resulting from the string conversion.
    313296 */
    314 double posix_strtod(const char *restrict nptr, char **restrict endptr)
    315 {
    316         return (double) posix_strtold(nptr, endptr);
    317 }
    318 
    319 /**
    320  * Allocate memory chunk.
    321  *
    322  * @param size Size of the chunk to allocate.
    323  * @return Either pointer to the allocated chunk or NULL if not possible.
    324  */
    325 void *posix_malloc(size_t size)
    326 {
    327         return malloc(size);
    328 }
    329 
    330 /**
    331  * Allocate memory for an array of elements.
    332  *
    333  * @param nelem Number of elements in the array.
    334  * @param elsize Size of each element.
    335  * @return Either pointer to the allocated array or NULL if not possible.
    336  */
    337 void *posix_calloc(size_t nelem, size_t elsize)
    338 {
    339         return calloc(nelem, elsize);
    340 }
    341 
    342 /**
    343  * Reallocate memory chunk to a new size.
    344  *
    345  * @param ptr Memory chunk to reallocate. Might be NULL.
    346  * @param size Size of the reallocated chunk. Might be zero.
    347  * @return Either NULL or the pointer to the newly reallocated chunk.
    348  */
    349 void *posix_realloc(void *ptr, size_t size)
    350 {
    351         if (ptr != NULL && size == 0) {
    352                 /* Native realloc does not handle this special case. */
    353                 free(ptr);
    354                 return NULL;
    355         } else {
    356                 return realloc(ptr, size);
    357         }
    358 }
    359 
    360 /**
    361  * Free allocated memory chunk.
    362  *
    363  * @param ptr Memory chunk to be freed.
    364  */
    365 void posix_free(void *ptr)
    366 {
    367         if (ptr) {
    368                 free(ptr);
    369         }
    370 }
    371 
    372 /**
    373  * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive.
    374  *
    375  * @return The pseudo random integer.
    376  */
    377 int posix_rand(void)
    378 {
    379         return (int) rand();
    380 }
    381 
    382 /**
    383  * Initialize a new sequence of pseudo-random integers.
    384  *
    385  * @param seed The seed of the new sequence.
    386  */
    387 void posix_srand(unsigned int seed)
    388 {
    389         srand(seed);
     297double strtod(const char *restrict nptr, char **restrict endptr)
     298{
     299        return (double) strtold(nptr, endptr);
    390300}
    391301
     
    396306 * @return The opened file descriptor or -1 on error.
    397307 */
    398 int posix_mkstemp(char *tmpl)
     308int mkstemp(char *tmpl)
    399309{
    400310        int fd = -1;
    401311       
    402         char *tptr = tmpl + posix_strlen(tmpl) - 6;
     312        char *tptr = tmpl + strlen(tmpl) - 6;
    403313       
    404314        while (fd < 0) {
    405                 if (*posix_mktemp(tmpl) == '\0') {
     315                if (*mktemp(tmpl) == '\0') {
    406316                        /* Errno set by mktemp(). */
    407317                        return -1;
    408318                }
    409319               
    410                 fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
     320                fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
    411321               
    412322                if (fd == -1) {
     
    427337 *    reduced to an empty string.
    428338 */
    429 char *posix_mktemp(char *tmpl)
    430 {
    431         int tmpl_len = posix_strlen(tmpl);
     339char *mktemp(char *tmpl)
     340{
     341        int tmpl_len = strlen(tmpl);
    432342        if (tmpl_len < 6) {
    433343                errno = EINVAL;
     
    437347       
    438348        char *tptr = tmpl + tmpl_len - 6;
    439         if (posix_strcmp(tptr, "XXXXXX") != 0) {
     349        if (strcmp(tptr, "XXXXXX") != 0) {
    440350                errno = EINVAL;
    441351                *tmpl = '\0';
     
    451361                errno = 0;
    452362                /* Check if the file exists. */
    453                 if (posix_access(tmpl, F_OK) == -1) {
     363                if (access(tmpl, F_OK) == -1) {
    454364                        if (errno == ENOENT) {
    455365                                errno = orig_errno;
Note: See TracChangeset for help on using the changeset viewer.