Changeset 8338a81 in mainline


Ignore:
Timestamp:
2018-06-16T22:20:39Z (6 years ago)
Author:
Jiri Svoboda <jiri@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
379db9ef
Parents:
55092672
Message:

div, ldiv, lldiv should go to libc's stdio.h Add MB_CUR_MAX. Adjust MB_LEN_MAX. Add tests.

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • abi/include/_bits/limits.h

    r55092672 r8338a81  
    5959#define CHAR_MAX  __CHAR_MAX__
    6060
    61 #define MB_LEN_MAX  16
     61#define MB_LEN_MAX  4
    6262
    6363#define SHRT_MIN  __SHRT_MIN__
  • uspace/lib/c/Makefile

    r55092672 r8338a81  
    193193        test/qsort.c \
    194194        test/sprintf.c \
     195        test/stdlib.c \
    195196        test/str.c
    196197
  • uspace/lib/c/generic/stdlib.c

    r55092672 r8338a81  
    4747}
    4848
     49/** Compute quotient and remainder of int division.
     50 *
     51 * @param numer Numerator
     52 * @param denom Denominator
     53 * @return Structure containing quotient and remainder
     54 */
     55div_t div(int numer, int denom)
     56{
     57        div_t d;
     58
     59        d.quot = numer / denom;
     60        d.rem = numer % denom;
     61
     62        return d;
     63}
     64
     65/** Compute quotient and remainder of long division.
     66 *
     67 * @param numer Numerator
     68 * @param denom Denominator
     69 * @return Structure containing quotient and remainder
     70 */
     71ldiv_t ldiv(long numer, long denom)
     72{
     73        ldiv_t d;
     74
     75        d.quot = numer / denom;
     76        d.rem = numer % denom;
     77
     78        return d;
     79}
     80
     81/** Compute quotient and remainder of long long division.
     82 *
     83 * @param numer Numerator
     84 * @param denom Denominator
     85 * @return Structure containing quotient and remainder
     86 */
     87lldiv_t lldiv(long long numer, long long denom)
     88{
     89        lldiv_t d;
     90
     91        d.quot = numer / denom;
     92        d.rem = numer % denom;
     93
     94        return d;
     95}
     96
    4997/** @}
    5098 */
  • uspace/lib/c/include/stdlib.h

    r55092672 r8338a81  
    3636#define LIBC_STDLIB_H_
    3737
     38#include <_bits/size_t.h>
     39#include <_bits/wchar_t.h>
    3840#include <malloc.h>
    3941#include <qsort.h>
    4042
    41 #define RAND_MAX  714025
     43/** Type returned by the div function */
     44typedef struct {
     45        /** Quotient */
     46        int quot;
     47        /** Remainder */
     48        int rem;
     49} div_t;
     50
     51/** Type returned by the ldiv function */
     52typedef struct {
     53        /** Quotient */
     54        long quot;
     55        /** Remainder */
     56        long rem;
     57} ldiv_t;
     58
     59/** Type returned by the lldiv function */
     60typedef struct {
     61        /** Quotient */
     62        long long quot;
     63        /** Remainder */
     64        long long rem;
     65} lldiv_t;
     66
    4267
    4368#define EXIT_FAILURE 1
    4469#define EXIT_SUCCESS 0
     70
     71#define RAND_MAX  714025
     72
     73#define MB_CUR_MAX 4
    4574
    4675extern int rand(void);
     
    5988extern unsigned long long strtoull(const char *__restrict__, char **__restrict__, int);
    6089
     90extern div_t div(int, int);
     91extern ldiv_t ldiv(long, long);
     92extern lldiv_t lldiv(long long, long long);
     93
    6194#endif
    6295
  • uspace/lib/c/test/main.c

    r55092672 r8338a81  
    3838PCUT_IMPORT(scanf);
    3939PCUT_IMPORT(sprintf);
     40PCUT_IMPORT(stdlib);
    4041PCUT_IMPORT(str);
    4142PCUT_IMPORT(table);
  • uspace/lib/posix/include/posix/stdlib.h

    r55092672 r8338a81  
    5252extern long long llabs(long long i);
    5353
    54 /* Integer Division */
    55 
    56 typedef struct {
    57         int quot, rem;
    58 } div_t;
    59 
    60 typedef struct {
    61         long quot, rem;
    62 } ldiv_t;
    63 
    64 typedef struct {
    65         long long quot, rem;
    66 } lldiv_t;
    67 
    68 extern div_t div(int numer, int denom);
    69 extern ldiv_t ldiv(long numer, long denom);
    70 extern lldiv_t lldiv(long long numer, long long denom);
    71 
    7254/* Array Functions */
    7355extern void *bsearch(const void *key, const void *base,
  • uspace/lib/posix/src/stdlib.c

    r55092672 r8338a81  
    9595{
    9696        return i < 0 ? -i : i;
    97 }
    98 
    99 /**
    100  * Compute the quotient and remainder of an integer division.
    101  *
    102  * @param numer Numerator.
    103  * @param denom Denominator.
    104  * @return Quotient and remainder packed into structure.
    105  */
    106 div_t div(int numer, int denom)
    107 {
    108         return (div_t) { .quot = numer / denom, .rem = numer % denom };
    109 }
    110 
    111 /**
    112  * Compute the quotient and remainder of a long integer division.
    113  *
    114  * @param numer Numerator.
    115  * @param denom Denominator.
    116  * @return Quotient and remainder packed into structure.
    117  */
    118 ldiv_t ldiv(long numer, long denom)
    119 {
    120         return (ldiv_t) { .quot = numer / denom, .rem = numer % denom };
    121 }
    122 
    123 /**
    124  * Compute the quotient and remainder of a long long integer division.
    125  *
    126  * @param numer Numerator.
    127  * @param denom Denominator.
    128  * @return Quotient and remainder packed into structure.
    129  */
    130 lldiv_t lldiv(long long numer, long long denom)
    131 {
    132         return (lldiv_t) { .quot = numer / denom, .rem = numer % denom };
    13397}
    13498
Note: See TracChangeset for help on using the changeset viewer.