Skip to content

Commit

Permalink
Fill out functions in <inttypes.h> except [w]strto*
Browse files Browse the repository at this point in the history
  • Loading branch information
mysterymath committed Jan 13, 2024
1 parent ddb30b1 commit c517e8b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
3 changes: 3 additions & 0 deletions mos-platform/common/c/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ add_platform_library(common-c
# errno.h
errno.c

# inttypes.h
inttypes.c

# setjmp.h
setjmp.S

Expand Down
10 changes: 10 additions & 0 deletions mos-platform/common/c/inttypes.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#include <inttypes.h>

intmax_t imaxabs(intmax_t j) {
return __builtin_llabs(j);
}

imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom) {
imaxdiv_t result = {numer / denom, numer % denom};
return result;
}
8 changes: 8 additions & 0 deletions mos-platform/common/include/inttypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,4 +169,12 @@
#define SCNxMAX __UINTMAX_FMTx__
#define SCNxPTR __UINTPTR_FMTx__

intmax_t imaxabs(intmax_t j);

typedef struct {
intmax_t quot, rem;
} imaxdiv_t;

imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom);

#endif // not _INTTYPES_H_

0 comments on commit c517e8b

Please sign in to comment.