Changeset 9d8307a in mainline for uspace/lib/c/generic/stdlib.c


Ignore:
Timestamp:
2018-07-19T11:55:19Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
0d83cf6f
Parents:
42f5860
git-author:
Jiri Svoboda <jiri@…> (2018-07-18 17:54:45)
git-committer:
Jiri Svoboda <jiri@…> (2018-07-19 11:55:19)
Message:

Reimplement strtold function in libc.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/stdlib.c

    r42f5860 r9d8307a  
    3838#include <stdlib.h>
    3939#include "private/libc.h"
     40#include "private/scanf.h"
    4041#include "private/stdlib.h"
     42#include "private/stdio.h"
     43#include "private/sstream.h"
    4144
    4245static int glbl_seed = 1;
     
    4851static FIBRIL_MUTEX_INITIALIZE(quick_exit_handlers_lock);
    4952
     53/** Convert string to long double.
     54 *
     55 */
     56long double strtold(const char *nptr, char **endptr)
     57{
     58        int numchar;
     59        long double ld;
     60        errno_t rc;
     61        FILE f;
     62
     63        numchar = 0;
     64        __sstream_init(nptr, &f);
     65
     66        rc = __fstrtold(&f, &numchar, SIZE_MAX, &ld);
     67        if (rc != EOK) {
     68                ld = 0;
     69                if (endptr != NULL)
     70                        *endptr = (char *) nptr;
     71                errno = rc;
     72        } else {
     73                if (endptr != NULL)
     74                        *endptr = (char *) __sstream_getpos(&f);
     75        }
     76
     77        return ld;
     78}
    5079
    5180int rand(void)
Note: See TracChangeset for help on using the changeset viewer.