mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:57:45 +00:00
LibC: Add imaxdiv and lldiv
This commit is contained in:
parent
42a8186728
commit
857b0e1dc3
5 changed files with 74 additions and 0 deletions
|
@ -9,6 +9,7 @@ set(LIBC_SOURCES
|
||||||
fenv.cpp
|
fenv.cpp
|
||||||
getopt.cpp
|
getopt.cpp
|
||||||
grp.cpp
|
grp.cpp
|
||||||
|
inttypes.cpp
|
||||||
ioctl.cpp
|
ioctl.cpp
|
||||||
libcinit.cpp
|
libcinit.cpp
|
||||||
libgen.cpp
|
libgen.cpp
|
||||||
|
|
44
Userland/Libraries/LibC/inttypes.cpp
Normal file
44
Userland/Libraries/LibC/inttypes.cpp
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, Mițca Dumitru <dumitru0mitca@gmail.com>
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
* modification, are permitted provided that the following conditions are met:
|
||||||
|
*
|
||||||
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
* list of conditions and the following disclaimer.
|
||||||
|
*
|
||||||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
* this list of conditions and the following disclaimer in the documentation
|
||||||
|
* and/or other materials provided with the distribution.
|
||||||
|
*
|
||||||
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
|
||||||
|
imaxdiv_t imaxdiv(intmax_t numerator, intmax_t denominator)
|
||||||
|
{
|
||||||
|
imaxdiv_t result;
|
||||||
|
result.quot = numerator / denominator;
|
||||||
|
result.rem = numerator % denominator;
|
||||||
|
|
||||||
|
if (numerator >= 0 && result.rem < 0) {
|
||||||
|
result.quot++;
|
||||||
|
result.rem -= denominator;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -27,6 +27,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <bits/stdint.h>
|
#include <bits/stdint.h>
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
__BEGIN_DECLS
|
||||||
|
|
||||||
#define PRId8 "d"
|
#define PRId8 "d"
|
||||||
#define PRId16 "d"
|
#define PRId16 "d"
|
||||||
|
@ -68,3 +71,11 @@
|
||||||
|
|
||||||
#define SCNu64 __PRI64_PREFIX "u"
|
#define SCNu64 __PRI64_PREFIX "u"
|
||||||
#define SCNd64 __PRI64_PREFIX "d"
|
#define SCNd64 __PRI64_PREFIX "d"
|
||||||
|
|
||||||
|
typedef struct imaxdiv_t {
|
||||||
|
intmax_t quot;
|
||||||
|
intmax_t rem;
|
||||||
|
} imaxdiv_t;
|
||||||
|
imaxdiv_t imaxdiv(intmax_t, intmax_t);
|
||||||
|
|
||||||
|
__END_DECLS
|
||||||
|
|
|
@ -836,6 +836,19 @@ ldiv_t ldiv(long numerator, long denominator)
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lldiv_t lldiv(long long numerator, long long denominator)
|
||||||
|
{
|
||||||
|
lldiv_t result;
|
||||||
|
result.quot = numerator / denominator;
|
||||||
|
result.rem = numerator % denominator;
|
||||||
|
|
||||||
|
if (numerator >= 0 && result.rem < 0) {
|
||||||
|
result.quot++;
|
||||||
|
result.rem -= denominator;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
size_t mbstowcs(wchar_t*, const char*, size_t)
|
size_t mbstowcs(wchar_t*, const char*, size_t)
|
||||||
{
|
{
|
||||||
dbgln("FIXME: Implement mbstowcs()");
|
dbgln("FIXME: Implement mbstowcs()");
|
||||||
|
|
|
@ -102,6 +102,11 @@ typedef struct {
|
||||||
long rem;
|
long rem;
|
||||||
} ldiv_t;
|
} ldiv_t;
|
||||||
ldiv_t ldiv(long, long);
|
ldiv_t ldiv(long, long);
|
||||||
|
typedef struct {
|
||||||
|
long long quot;
|
||||||
|
long long rem;
|
||||||
|
} lldiv_t;
|
||||||
|
lldiv_t lldiv(long long, long long);
|
||||||
|
|
||||||
int posix_openpt(int flags);
|
int posix_openpt(int flags);
|
||||||
int grantpt(int fd);
|
int grantpt(int fd);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue