[libc] Add new libc

This new libc is mostly from scratch, with *printf() functions provided
by Marco Paland and Eyal Rozenberg's tiny printf library, and malloc and
friends provided by dlmalloc.
This commit is contained in:
Justin C. Miller
2022-02-06 21:39:04 -08:00
parent 5ddac353a0
commit 346c172b32
90 changed files with 9848 additions and 25 deletions

View File

@@ -2,6 +2,7 @@
/// \file arch/amd64/memory.h
/// Architecture-specific constants related to memory and paging
#include <stddef.h>
#include <stdint.h>
namespace arch {

View File

@@ -16,6 +16,6 @@ install(uintptr_t entrypoint, const void *symbol_data)
} // namespace panic
extern "C"
void _PDCLIB_assert(const char *message, const char *function, const char *file, unsigned line) {
void __assert_fail(const char *message, const char *file, unsigned line, const char *function) {
panic::panic(message, nullptr, function, file, line);
}

View File

@@ -2,6 +2,7 @@
/// \file frame_allocator.h
/// Allocator for physical memory frames
#include <stddef.h>
#include <stdint.h>
#include <util/spinlock.h>

View File

@@ -2,21 +2,22 @@
// but should not include the user-specific code.
#ifndef __j6kernel
#include <stddef.h>
#include <stdint.h>
#include <j6/errors.h>
#include <j6/init.h>
#include <j6/syscalls.h>
#include <j6/types.h>
j6_handle_t __handle_sys = j6_handle_invalid;
j6_handle_t __handle_self = j6_handle_invalid;
j6_handle_t __handle_sys;
j6_handle_t __handle_self;
namespace {
constexpr size_t __static_arr_size = 4;
j6_handle_t __handle_array[__static_arr_size];
static j6_status_t
__load_handles()
load_handles()
{
size_t count = __static_arr_size;
j6_handle_t *handles = __handle_array;
@@ -41,9 +42,10 @@ namespace {
} // namespace
extern "C" void
_init_libj6(uint64_t *rsp)
__init_libj6(uint64_t *rsp)
{
__load_handles();
__handle_sys = __handle_self = j6_handle_invalid;
load_handles();
}
#endif // __j6kernel

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file arch/amd64/errno.h
* Errors
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
extern int errno;

View File

@@ -0,0 +1,9 @@
#include <assert.h>
#include <stdlib.h>
noreturn void
__assert_fail( const char *, const char *, unsigned, const char * )
{
// TODO: display message
abort();
}

View File

@@ -0,0 +1,41 @@
#pragma once
/** \file j6libc/bits.h
* Internal helpers for bitwise math.
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
#error "__j6libc/bits.h included by non-C++ code"
#endif
#include <stdint.h>
#include <__j6libc/size_t.h>
namespace __j6libc {
constexpr size_t log2(size_t n) {
return n < 2 ? 1 : 1 + log2(n/2);
}
constexpr size_t word_bytes = sizeof(void*);
constexpr size_t word_bits = word_bytes << 3;
constexpr uintptr_t word_align_mask = word_bytes - 1;
constexpr unsigned word_shift = log2(word_bytes);
template <typename T>
inline bool is_aligned(uintptr_t addr) {
return (addr & (sizeof(T)-1)) == 0;
}
template <typename T, typename S>
inline bool is_aligned(S *p) {
return is_aligned<T>(reinterpret_cast<uintptr_t>(p));
}
} // namespace __j6libc

View File

@@ -0,0 +1,38 @@
#pragma once
/** \file j6libc/casts.h
* Internal implementations of casting helpers for C's bad lib types
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
#error "__j6libc/casts.h included by non-C++ code"
#endif
namespace __j6libc {
template <typename T> struct non_const { using type = T; };
template <typename T> struct non_const<T*> { using type = T*; };
template <typename T> struct non_const<const T> { using type = T; };
template <typename T> struct non_const<const T*> { using type = T*; };
// cast_to: like reinterpret_cast, with an optional const_cast. Useful
// when C's stdlib wants to _take_ a const pointer, but return that
// pointer as non-const.
/*
template <typename T, typename S>
inline T cast_to(S p) { return reinterpret_cast<T>(p); }
*/
template <typename T, typename S>
inline T cast_to(S p) {
return reinterpret_cast<T>(const_cast<typename non_const<S>::type>(p));
}
} // namespace __j6libc

View File

@@ -0,0 +1,55 @@
#pragma once
/** \file j6libc/copy.h
* Internal implementations to aid in implementing mem* functions
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
#error "__j6libc/copy.h included by non-C++ code"
#endif
#include <stddef.h>
#include <__j6libc/size_t.h>
namespace __j6libc {
template <size_t N>
inline void do_copy(char *s1, const char *s2) {
#if __has_builtin(__builtin_memcpy_inline)
__builtin_memcpy_inline(s1, s2, N);
#else
#warn "Not using __builtin_memcpy_inline for memcpy"
for (size_t i = 0; i < N; ++i)
s1[i] = s2[i];
#endif
}
template <size_t N>
inline void do_double_copy(char *s1, const char *s2, size_t n) {
do_copy<N>(s1, s2);
ptrdiff_t off = n - N;
if (!off) return;
do_copy<N>(s1+off, s2+off);
}
__attribute__((always_inline))
inline void do_large_copy(char *s1, const char *s2, size_t n) {
asm volatile ("rep movsb" : "+D"(s1), "+S"(s2), "+c"(n) :: "memory");
}
__attribute__((always_inline))
inline void do_backward_copy(char *s1, const char *s2, size_t n) {
for (size_t i = n - 1; i < n; --i)
s1[i] = s2[i];
}
} // namespace __j6libc

View File

@@ -0,0 +1,14 @@
#pragma once
/** \file j6libc/file.h
* Internal definition of FILE
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
typedef struct {
} FILE;

View File

@@ -0,0 +1,52 @@
#include <stddef.h>
#include <stdint.h>
namespace __j6libc {
using j6_status_t = uint64_t;
using j6_handle_t = uint64_t;
constexpr j6_handle_t j6_handle_invalid = -1ull;
constexpr j6_status_t j6_status_ok = 0;
static j6_handle_t core_handle = j6_handle_invalid;
static intptr_t core_size = 0;
static const uintptr_t core_base = 0x1c0000000;
static const void *error_val = (void*)-1;
extern "C" {
j6_status_t j6_vma_create_map(j6_handle_t *, size_t, uintptr_t, unsigned);
j6_status_t j6_vma_resize(j6_handle_t, size_t *);
}
void * increase_core(intptr_t i)
{
if (i == 0)
return (void*)core_base;
if (core_size == 0) {
if (i < 0)
return (void*)-1;
j6_status_t result = j6_vma_create_map(&core_handle, i, core_base, 1);
if (result != j6_status_ok)
return (void*)-1;
core_size = i;
return (void*)core_base;
}
size_t new_size = core_size + i;
j6_status_t result = j6_vma_resize(core_handle, &new_size);
if (result != j6_status_ok)
return (void*)-1;
uintptr_t prev = core_base + core_size;
core_size += i;
return (void*)prev;
}
} // namespace __j6libc

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file j6libc/mbstate_t.h
* Internal definition of mbstate_t
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
typedef __UINT64_TYPE__ mbstate_t;

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file j6libc/null.h
* Internal definition of NULL
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#define NULL ((void*)0)

View File

@@ -0,0 +1,15 @@
#pragma once
/** \file j6libc/restrict.h
* Internal handling of restrict keyword for C++
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifdef __cplusplus
#define restrict __restrict__
#endif

View File

@@ -0,0 +1,24 @@
#pragma once
/** \file j6libc/size_t.h
* Internal definition of size_t
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
typedef __SIZE_TYPE__ size_t;
#define SIZE_MAX __SIZE_MAX__
#if __SIZE_WIDTH__ == 32
#define SIZE_C( x ) x ## __UINT32_C_SUFFIX__
#elif __SIZE_WIDTH__ == 64
#define SIZE_C( x ) x ## __UINT64_C_SUFFIX__
#elif __SIZE_WIDTH__ == 128
#define SIZE_C( x ) x ## __UINT128_C_SUFFIX__
#else
#error Unsupported size_t width
#endif

View File

@@ -0,0 +1,14 @@
#pragma once
/** \file j6libc/uchar.h
* Internal definition of char16_t and char32_t
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
typedef __UINT_LEAST16_TYPE__ char16_t;
typedef __UINT_LEAST32_TYPE__ char32_t;

View File

@@ -0,0 +1,18 @@
#pragma once
/** \file j6libc/wchar_t.h
* Internal definition of wchar_t
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
typedef __WCHAR_TYPE__ wchar_t;
#endif
#define WCHAR_MAX __WCHAR_MAX__
#define WCHAR_MIN ((-__WCHAR_MAX__) - 1)

View File

@@ -0,0 +1,17 @@
extern main
extern exit
extern __init_libj6
global _start:function (_start.end - _start)
_start:
mov rbp, rsp
mov rdi, rsp
call __init_libj6
pop rdi
mov rsi, rsp
call main
mov rdi, rax
call exit
.end:

View File

@@ -0,0 +1,5 @@
#pragma once
/// \file arch/amd64/errno.h
/// errno implementation for amd64
extern int errno;

View File

@@ -0,0 +1,36 @@
#pragma once
/** \file assert.h
* Diagnostics
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdnoreturn.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifdef NDEBUG
#define assert( argument ) ( (void) 0 )
#else
noreturn void __assert_fail( const char *, const char *, unsigned, const char * );
#define assert( argument ) \
do { if (!(argument)) { __assert_fail( #argument, __FILE__, __LINE__, __func__ ); }} while(0)
#endif
#ifndef __cplusplus
#define static_assert _Static_assert
#endif
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file complex.h
* Complex arithmetic
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error complex.h is not yet implemented.

View File

@@ -0,0 +1,35 @@
#pragma once
/** \file ctype.h
* Character handling
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifdef __cplusplus
extern "C" {
#endif
int isalnum( int ch );
int isalpha( int ch );
int islower( int ch );
int isupper( int ch );
int isdigit( int ch );
int isxdigit( int ch );
int iscntrl( int ch );
int isgraph( int ch );
int isspace( int ch );
int isblank( int ch );
int isprint( int ch );
int ispunct( int ch );
int tolower( int ch );
int toupper( int ch );
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,17 @@
/** \file isalnum.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale
int isalnum( int c ) {
return isalpha(c) || isdigit(c);
}

View File

@@ -0,0 +1,17 @@
/** \file isalpha.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isalpha( int c ) {
return isupper(c) || islower(c);
}

View File

@@ -0,0 +1,17 @@
/** \file isblank.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isblank( int c ) {
return c == ' ' || c == '\t';
}

View File

@@ -0,0 +1,17 @@
/** \file iscntrl.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int iscntrl( int c ) {
return (c < ' ') || (c > '~');
}

View File

@@ -0,0 +1,17 @@
/** \file isdigit.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isdigit( int c ) {
return c >= '0' && c <= '9';
}

View File

@@ -0,0 +1,17 @@
/** \file isgraph.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isgraph( int c ) {
return isprint(c) && c != ' ';
}

View File

@@ -0,0 +1,17 @@
/** \file islower.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int islower( int c ) {
return c >= 'a' && c <= 'z';
}

View File

@@ -0,0 +1,17 @@
/** \file isprint.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isprint( int c ) {
return !iscntrl(c);
}

View File

@@ -0,0 +1,17 @@
/** \file ispunct.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int ispunct( int c ) {
return isgraph(c) && !isalnum(c);
}

View File

@@ -0,0 +1,27 @@
/** \file isspace.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isspace( int c ) {
switch (c) {
case '\t':
case '\n':
case '\v':
case '\f':
case '\r':
case ' ':
return true;
default:
return false;
}
}

View File

@@ -0,0 +1,17 @@
/** \file isupper.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isupper( int c ) {
return c >= 'A' && c <= 'Z';
}

View File

@@ -0,0 +1,20 @@
/** \file isxdigit.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int isxdigit( int c ) {
return
(c >= '0' && c <= '9') ||
(c >= 'A' && c <= 'F') ||
(c >= 'a' && c <= 'f');
}

View File

@@ -0,0 +1,19 @@
/** \file tolower.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int tolower( int c ) {
if (c >= 'A' && c <= 'Z')
c += 0x20;
return c;
}

View File

@@ -0,0 +1,19 @@
/** \file toupper.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <ctype.h>
// Currently only implemented for "C" locale.
int toupper( int c ) {
if (c >= 'a' && c <= 'z')
c -= 0x20;
return c;
}

View File

@@ -0,0 +1,28 @@
#pragma once
/** \file errno.h
* Errors
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**[[[cog code generation
from j6libc import arch_includes
arch_includes("errno.h")
]]]*/
/*[[[end]]]*/
#define EDOM 0x800
#define EILSEQ 0x801
#define ERANGE 0x802
#define EINVAL 0x803
#define ENOMEM 0x804
/* vim: set ft=c: */

View File

@@ -0,0 +1,13 @@
/** \file errno.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <errno.h>
int errno = 0;

13
src/libraries/libc/fenv.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
/** \file fenv.h
* Floating-point environment
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error fenv.h is not yet implemented.

View File

@@ -0,0 +1,58 @@
#pragma once
/** \file float.h
* Characteristics of floating types
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#define FLT_RADIX __FLT_RADIX__
#define FLT_MANT_DIG __FLT_MANT_DIG__
#define DBL_MANT_DIG __DBL_MANT_DIG__
#define LDBL_MANT_DIG __LDBL_MANT_DIG__
#define FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__
#define DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__
#define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
#define DECIMAL_DIG __DECIMAL_DIG__
#define FLT_DIG __FLT_DIG__
#define DBL_DIG __DBL_DIG__
#define LDBL_DIG __LDBL_DIG__
#define FLT_MIN_EXP __FLT_MIN_EXP__
#define DBL_MIN_EXP __DBL_MIN_EXP__
#define LDBL_MIN_EXP __LDBL_MIN_EXP__
#define FLT_MAX_EXP __FLT_MAX_EXP__
#define DBL_MAX_EXP __DBL_MAX_EXP__
#define LDBL_MAX_EXP __LDBL_MAX_EXP__
#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__
#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__
#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__
#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__
#define FLT_MIN __FLT_MIN__
#define FLT_MAX __FLT_MAX__
#define FLT_EPSILON __FLT_EPSILON__
#define FLT_TRUE_MIN FLT_MIN
#define DBL_MIN __DBL_MIN__
#define DBL_MAX __DBL_MAX__
#define DBL_EPSILON __DBL_EPSILON__
#define DBL_TRUE_MIN DBL_MIN
#define LDBL_MIN __LDBL_MIN__
#define LDBL_MAX __LDBL_MAX__
#define LDBL_EPSILON __LDBL_EPSILON__
#define LDBL_TRUE_MIN LDBL_MIN

View File

@@ -0,0 +1,82 @@
#pragma once
/** \file inttypes.h
* Format conversion of integer types
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**[[[cog code generation
import cog
from j6libc import definition, int_widths, int_mods
for width in int_widths:
definition("#define", f"PRId{width}", f"__INT{width}_FMTd__")
definition("#define", f"PRIi{width}", f"__INT{width}_FMTi__")
definition("#define", f"PRIu{width}", f"__UINT{width}_FMTu__")
definition("#define", f"PRIo{width}", f"__UINT{width}_FMTo__")
definition("#define", f"PRIx{width}", f"__UINT{width}_FMTx__")
definition("#define", f"PRIX{width}", f"__UINT{width}_FMTX__")
cog.outl()
definition("#define", f"SCNd{width}", f"__INT{width}_FMTd__")
definition("#define", f"SCNi{width}", f"__INT{width}_FMTi__")
definition("#define", f"SCNu{width}", f"__UINT{width}_FMTu__")
definition("#define", f"SCNo{width}", f"__UINT{width}_FMTo__")
definition("#define", f"SCNx{width}", f"__UINT{width}_FMTx__")
definition("#define", f"SCNX{width}", f"__UINT{width}_FMTX__")
for mod in int_mods:
cog.outl()
definition("#define", f"PRId{mod.upper()}{width}", f"__INT_{mod.upper()}{width}_FMTd__")
definition("#define", f"PRIi{mod.upper()}{width}", f"__INT_{mod.upper()}{width}_FMTi__")
definition("#define", f"PRIu{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTu__")
definition("#define", f"PRIo{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTo__")
definition("#define", f"PRIx{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTx__")
definition("#define", f"PRIX{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTX__")
cog.outl()
definition("#define", f"SCNd{mod.upper()}{width}", f"__INT_{mod.upper()}{width}_FMTd__")
definition("#define", f"SCNi{mod.upper()}{width}", f"__INT_{mod.upper()}{width}_FMTi__")
definition("#define", f"SCNu{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTu__")
definition("#define", f"SCNo{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTo__")
definition("#define", f"SCNx{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTx__")
definition("#define", f"SCNX{mod.upper()}{width}", f"__UINT{mod.upper()}{width}_FMTX__")
cog.outl()
]]]*/
/*[[[end]]]*/
#define PRIdMAX __INTMAX_FMTd__
#define PRIiMAX __INTMAX_FMTi__
#define PRIuMAX __UINTMAX_FMTu__
#define PRIoMAX __UINTMAX_FMTo__
#define PRIxMAX __UINTMAX_FMTx__
#define PRIXMAX __UINTMAX_FMTX__
#define SCNdMAX __INTMAX_FMTd__
#define SCNiMAX __INTMAX_FMTi__
#define SCNuMAX __UINTMAX_FMTu__
#define SCNoMAX __UINTMAX_FMTo__
#define SCNxMAX __UINTMAX_FMTx__
#define SCNXMAX __UINTMAX_FMTX__
#define PRIdPTR __INTPTR_FMTd__
#define PRIiPTR __INTPTR_FMTi__
#define PRIuPTR __UINTPTR_FMTu__
#define PRIoPTR __UINTPTR_FMTo__
#define PRIxPTR __UINTPTR_FMTx__
#define PRIXPTR __UINTPTR_FMTX__
#define SCNdPTR __INTPTR_FMTd__
#define SCNiPTR __INTPTR_FMTi__
#define SCNuPTR __UINTPTR_FMTu__
#define SCNoPTR __UINTPTR_FMTo__
#define SCNxPTR __UINTPTR_FMTx__
#define SCNXPTR __UINTPTR_FMTX__
/* vim: set ft=c: */

View File

@@ -0,0 +1,23 @@
#pragma once
/** \file iso646.h
* Alternative spellings
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#define and &&
#define and_eq &=
#define bitand &
#define bitor |
#define compl ~
#define not !
#define not_eq !=
#define or ||
#define or_eq |=
#define xor ^
#define xor_eq ^=

View File

@@ -15,28 +15,23 @@ def glob(ext):
return list(map(resolve, glob(f"{module_root}/**/*.{ext}", recursive=True)))
sources = []
for ext in ("c", "cpp", "s"):
for ext in ("c", "cpp", "s", "inc"):
sources += glob(ext) + glob(ext + ".cog")
headers = []
for ext in ("h", "inc"):
for ext in ("h",):
headers += glob(ext) + glob(ext + ".cog")
libc = module("libc",
kind = "lib",
deps = [ "j6" ],
output = "libc.a",
sources = sources,
public_headers = headers,
)
libc.variables["ccflags"] = [
"${ccflags}",
"-DDISABLE_SSE",
"-DLACKS_UNISTD_H",
"-DLACKS_FCNTL_H",
"-DLACKS_SYS_PARAM_H",
"-DLACKS_SYS_MMAN_H",
"-DLACKS_SCHED_H",
"-DLACKS_STRINGS_H",
"-DHAVE_MMAP=0",
"${ccflags}",
"-DPRINTF_SUPPORT_DECIMAL_SPECIFIERS=0",
"-DPRINTF_SUPPORT_EXPONENTIAL_SPECIFIERS=0",
]

View File

@@ -0,0 +1,84 @@
#pragma once
/** \file limits.h
* Sizes of integer types
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#define CHAR_BIT __CHAR_BIT__
#define SCHAR_MAX __SCHAR_MAX__
#define SCHAR_MIN ((-__SCHAR_MAX__) - 1)
#define UCHAR_MAX __UCHAR_MAX__
#if ((char)-1) < 0
// char is signed
#define CHAR_MAX SCHAR_MAX
#define CHAR_MIN SCHAR_MIN
#else
// char is unsigned
#define CHAR_MAX UCHAR_MAX
#define CHAR_MIN 0
#endif
#define MB_LEN_MAX
#define SHRT_MAX __SHRT_MAX__
#define SHRT_MIN ((-__SHRT_MAX__) - 1)
#if __SIZEOF_SHORT__ == 1
#define USHRT_MAX __UINT8_MAX__
#elif __SIZEOF_SHORT__ == 2
#define USHRT_MAX __UINT16_MAX__
#elif __SIZEOF_SHORT__ == 4
#define USHRT_MAX __UINT32_MAX__
#endif
#define INT_MAX __INT_MAX__
#define INT_MIN ((-__INT_MAX__) - 1)
#if __SIZEOF_INT__ == 1
#define UINT_MAX __UINT8_MAX__
#elif __SIZEOF_INT__ == 2
#define UINT_MAX __UINT16_MAX__
#elif __SIZEOF_INT__ == 4
#define UINT_MAX __UINT32_MAX__
#elif __SIZEOF_INT__ == 8
#define UINT_MAX __UINT64_MAX__
#endif
#define LONG_MAX __LONG_MAX__
#define LONG_MIN ((-__LONG_MAX__) - 1)
#if __SIZEOF_LONG__ == 1
#define ULONG_MAX __UINT8_MAX__
#elif __SIZEOF_LONG__ == 2
#define ULONG_MAX __UINT16_MAX__
#elif __SIZEOF_LONG__ == 4
#define ULONG_MAX __UINT32_MAX__
#elif __SIZEOF_LONG__ == 8
#define ULONG_MAX __UINT64_MAX__
#elif __SIZEOF_LONG__ == 16
#define ULONG_MAX __UINT128_MAX__
#endif
#define LLONG_MAX __LONG_LONG_MAX__
#define LLONG_MIN ((-__LONG_LONG_MAX__) - 1)
#if __SIZEOF_LONG_LONG__ == 1
#define ULLONG_MAX __UINT8_MAX__
#elif __SIZEOF_LONG_LONG__ == 2
#define ULLONG_MAX __UINT16_MAX__
#elif __SIZEOF_LONG_LONG__ == 4
#define ULLONG_MAX __UINT32_MAX__
#elif __SIZEOF_LONG_LONG__ == 8
#define ULLONG_MAX __UINT64_MAX__
#elif __SIZEOF_LONG_LONG__ == 16
#define ULLONG_MAX __UINT128_MAX__
#endif

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file locale.h
* Localization
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error locale.h is not yet implemented.

13
src/libraries/libc/math.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
/** \file math.h
* Mathematics
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error math.h is not yet implemented.

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file setjmp.h
* Nonlocal jumps
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error setjmp.h is not yet implemented.

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file signal.h
* Signal handling
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error signal.h is not yet implemented.

View File

@@ -0,0 +1,20 @@
#pragma once
/** \file stdalign.h
* Alignment
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
#define alignas _Alignas
#define alignof _Alignof
#endif
#define __alignas_is_defined 1
#define __alignof_is_defined 1

View File

@@ -0,0 +1,18 @@
#pragma once
/** \file stdarg.h
* Variable arguments
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
typedef __builtin_va_list va_list;
#define va_arg( ap, type ) (__builtin_va_arg( (ap), type ))
#define va_copy( dest, src ) (__builtin_va_copy( (dest), (src) ))
#define va_end( ap ) (__builtin_va_end( (ap) ))
#define va_start( ap, parmN ) (__builtin_va_start( (ap), (parmN) ))

View File

@@ -0,0 +1,157 @@
#pragma once
/** \file stdatomic.h
* Atomics
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdint.h>
#include <__j6libc/uchar.h>
#ifdef __cplusplus
extern "C" {
#endif
/**[[[cog code generation
from j6libc import atomic_types
deftypes = ["BOOL", "CHAR16", "CHAR32", "CHAR", "INT",
"LLONG", "SHORT", "WCHAR_T", "POINTER"]
for t in deftypes:
name = f"ATOMIC_{t}_LOCK_FREE"
cog.outl(f"#define {name:24} __CLANG_ATOMIC_{t}_LOCK_FREE")
cog.outl()
for name, abbrev in atomic_types.items():
cog.outl(f"typedef _Atomic {name:18} atomic_{abbrev};")
]]]*/
/*[[[end]]]*/
typedef enum {
memory_order_relaxed = __ATOMIC_RELAXED,
memory_order_consume = __ATOMIC_CONSUME,
memory_order_acquire = __ATOMIC_ACQUIRE,
memory_order_release = __ATOMIC_RELEASE,
memory_order_acq_rel = __ATOMIC_ACQ_REL,
memory_order_seq_cst = __ATOMIC_SEQ_CST,
} memory_order;
#define ATOMIC_FLAG_INIT {0}
typedef struct {
atomic_uint flag;
} atomic_flag;
#define ATOMIC_VAR_INIT(value) (value)
#define kill_dependency(value) (value)
#define atomic_init(obj, value) __c11_atomic_init((obj), (value))
#define atomic_thread_fence(order) __c11_atomic_thread_fence((order))
#define atomic_signal_fence(order) __c11_atomic_signal_fence((order))
#define atomic_is_lock_free(obj) __c11_atomic_is_lock_free((sizeof(*(obj))))
/**[[[cog code generation
default_ordering = ("order",)
cas_ordering = ("success", "failure")
def make_atomic_generic(fname, *arg_names, orders = None):
if orders is None:
orders = default_ordering
args = ', '.join(arg_names)
oargs = ', '.join(orders)
clang_args = ', '.join([f"({n})" for n in arg_names])
clang_oargs = ', '.join([f"({n})" for n in orders])
clang_oarg_def = ', '.join(["memory_order_seq_cst" for n in orders])
fnames = (f"atomic_{fname}", f"atomic_{fname}_explicit")
argnames = (f"({args})", f"({args}, {oargs})")
dn = len(fnames[1]) - len(fnames[0])
al = len(argnames[1])
cog.outl(f"#define {fnames[0]}{argnames[0]} \\")
cog.outl(f" __c11_{fnames[0]}({clang_args}, {clang_oarg_def})")
cog.outl()
cog.outl(f"#define {fnames[1]}{argnames[1]} \\")
cog.outl(f" __c11_{fnames[0]}({clang_args}, {clang_oargs})")
cog.outl()
make_atomic_generic("store", "obj", "desired")
make_atomic_generic("load", "obj")
make_atomic_generic("exchange", "obj", "desired")
make_atomic_generic("compare_exchange_strong", "obj", "expected", "desired", orders=cas_ordering)
make_atomic_generic("compare_exchange_weak", "obj", "expected", "desired", orders=cas_ordering)
cog.outl()
make_atomic_generic("fetch_add", "obj", "operand")
make_atomic_generic("fetch_sub", "obj", "operand")
make_atomic_generic("fetch_or", "obj", "operand")
make_atomic_generic("fetch_xor", "obj", "operand")
make_atomic_generic("fetch_and", "obj", "operand")
]]]*/
/*[[[end]]]*/
inline _Bool atomic_flag_set_and_set (volatile atomic_flag *object) {
return atomic_fetch_or(&object->flag, 1) != 0;
}
inline _Bool atomic_flag_set_and_set_explicit (volatile atomic_flag *object, memory_order order) {
return atomic_fetch_or_explicit(&object->flag, 1, order) != 0;
}
inline void atomic_flag_clear (volatile atomic_flag *object) {
atomic_store(&object->flag, 0);
}
inline void atomic_flag_clear_explicit (volatile atomic_flag *object, memory_order order) {
atomic_store_explicit(&object->flag, 0, order);
}
/**[[[cog code generation
def make_atomic_generic(return_type, fname, arg_types, arg_names, generic_arg = 0):
cog.outl(f"#define {fname}(" + ', '.join(arg_names) + ") \\")
cog.outl(f" _Generic(({arg_names[generic_arg]}), \\")
for name, abbrev in atypes.items():
casetype = arg_types[generic_arg].format(atomic=f"atomic_{abbrev}", standard=name)
cog.outl(f" {casetype}: __{fname}_{abbrev}, \\")
cog.outl(" )(" + ', '.join(arg_names) + ")")
cog.outl()
for name, abbrev in atypes.items():
args = [
f"{arg_types[i]} {arg_names[i]}".format(atomic=f"atomic_{abbrev}", standard=name)
for i in range(len(arg_types))]
cog.out(f"{return_type} __{fname}_{abbrev} (")
cog.out(', '.join(args))
if body:
cog.outl(f") {body}")
else:
cog.outl(f");")
cog.outl()
#make_atomic_generic(
#"void", "atomic_init",
#("volatile {atomic} *", "{standard}"),
#("obj", "value"),
#body = "{ *obj = value; }")
]]]*/
/*[[[end]]]*/
#ifdef __cplusplus
} // extern "C"
#endif
/* vim: set ft=c: */

View File

@@ -0,0 +1,19 @@
#pragma once
/** \file stdbool.h
* Boolean type and values
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifndef __cplusplus
#define bool _Bool
#define true 1
#define false 0
#endif
#define __bool_true_false_are_defined 1

View File

@@ -0,0 +1,27 @@
#pragma once
/** \file stddef.h
* Common definitions
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/null.h>
#include <__j6libc/size_t.h>
#include <__j6libc/wchar_t.h>
typedef __PTRDIFF_TYPE__ ptrdiff_t;
#if __BIGGEST_ALIGNMENT__ == __SIZEOF_LONG_DOUBLE__
typedef long double max_align_t;
#else
typedef long long max_align_t;
#endif
#define offsetof(x, y) __builtin_offsetof((x), (y))
#define NULL ((void*)0)

View File

@@ -0,0 +1,68 @@
#pragma once
/** \file stdint.h
* Fixed-width integer types
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
/**[[[cog code generation
import cog
from j6libc import definition, int_widths, int_mods
for width in int_widths:
definition("typedef", f"__INT{width}_TYPE__", f"int{width}_t;")
definition("#define", f"INT{width}_WIDTH", f"{width}")
definition("#define", f"INT{width}_MAX", f"__INT{width}_MAX__")
definition("#define", f"INT{width}_MIN", f"((-__INT{width}_MAX__) - 1)")
definition("#define", f"INT{width}_C( x )", f"x ## __INT{width}_C_SUFFIX__")
cog.outl()
definition("typedef", f"__UINT{width}_TYPE__", f"uint{width}_t;")
definition("#define", f"UINT{width}_WIDTH", f"{width}")
definition("#define", f"UINT{width}_MAX", f"__UINT{width}_MAX__")
definition("#define", f"UINT{width}_C( x )", f"x ## __UINT{width}_C_SUFFIX__")
for mod in int_mods:
cog.outl()
definition("typedef", f"__INT_{mod.upper()}{width}_TYPE__", f"int_{mod}{width}_t;")
definition("typedef", f"__UINT_{mod.upper()}{width}_TYPE__", f"uint_{mod}{width}_t;")
definition("#define", f"INT_{mod.upper()}{width}_WIDTH", f"{width}")
definition("#define", f"INT_{mod.upper()}{width}_MAX", f"__INT_{mod.upper()}{width}_MAX__")
definition("#define", f"INT_{mod.upper()}{width}_MIN", f"((-__INT_{mod.upper()}{width}_MAX) - 1)")
cog.outl()
definition("typedef", f"__UINT_{mod.upper()}{width}_TYPE__", f"uint_least{width}_t;")
definition("#define", f"UINT_{mod.upper()}{width}_WIDTH", f"{width}")
definition("#define", f"UINT_{mod.upper()}{width}_MAX", f"__UINT_{mod.upper()}{width}_MAX__")
cog.outl()
]]]*/
/*[[[end]]]*/
typedef __INTMAX_TYPE__ intmax_t;
#define INTMAX_WIDTH __INTMAX_WIDTH__
#define INTMAX_MAX __INTMAX_MAX__
#define INTMAX_MIN ((-__INTMAX_MAX__) - 1)
#define INTMAX_C( x ) x ## __INTMAX_C_SUFFIX__
typedef __UINTMAX_TYPE__ uintmax_t;
#define UINTMAX_WIDTH __UINTMAX_WIDTH__
#define UINTMAX_MAX __UINTMAX_MAX__
#define UINTMAX_C( x ) x ## __UINTMAX_C_SUFFIX__
typedef __INTPTR_TYPE__ intptr_t;
#define INTPTR_WIDTH __INTPTR_WIDTH__
#define INTPTR_MAX __INTPTR_MAX__
#define INTPTR_MIN ((-__INTPTR_MAX__) - 1)
typedef __UINTPTR_TYPE__ uintptr_t;
#define UINTPTR_WIDTH __UINTPTR_WIDTH__
#define UINTPTR_MAX __UINTPTR_MAX__
/* vim: set ft=c: */

117
src/libraries/libc/stdio.h Normal file
View File

@@ -0,0 +1,117 @@
#pragma once
/** \file stdio.h
* Input/output
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/file.h>
#include <__j6libc/null.h>
#include <__j6libc/restrict.h>
#include <__j6libc/size_t.h>
#include <stdarg.h>
typedef size_t fpos_t;
#define _IOFBF 0
#define _IOLBF 1
#define _IONBF 2
#define BUFSIZ 0
#define EOF (-127)
#define FOPEN_MAX 16
#define FILENAME_MAX 256
#define L_tmpnam FILENAME_MAX
#define TMP_MAX 100
#define SEEK_CUR 0
#define SEEK_END 1
#define SEEK_SET 2
#ifdef __cplusplus
extern "C" {
#endif
// Operations on files
//
int remove(const char *filename);
int rename(const char *old_name, const char *new_name);
FILE * tmpfile(void);
char * tmpnam(char *s);
// File access functions
//
int fclose(FILE *stream);
int fflush(FILE *stream);
FILE * fopen(const char * restrict filename, const char * restrict mode);
FILE * freopen(const char * restrict filename, const char * restrict mode, FILE * restrict stream);
void setbuf(FILE * restrict stream, char * restrict buf);
int setvbuf(FILE * restrict stream, char * restrict buf, int mode, size_t size);
// Formatted input/output functions
//
int printf(const char * restrict format, ...);
int vprintf(const char * restrict format, va_list arg);
int fprintf(FILE * restrict stream, const char * restrict format, ...);
int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg);
int sprintf(char * restrict s, const char * restrict format, ...);
int vsprintf(char * restrict s, const char * restrict format, va_list arg);
int snprintf(char * restrict s, size_t n, const char * restrict format, ...);
int vsnprintf(char * restrict s, size_t n, const char * restrict format, va_list arg);
int scanf(const char * restrict format, ...);
int vscanf(const char * restrict format, va_list arg);
int fscanf(FILE * restrict stream, const char * restrict format, ...);
int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
int sscanf(const char * restrict s, const char * restrict format, ...);
int vsscanf(const char * restrict s, const char * restrict format, va_list arg);
// Character input/output functions
//
int fgetc(FILE *stream);
char * fgets(char * restrict s, int n, FILE * restrict stream);
int fputc(char c, FILE *stream);
int fputs(const char * restrict s, FILE * restrict stream);
int getc(FILE *stream);
int getchar(void);
int putc(char c, FILE *stream);
int putchar(char c);
int puts(const char *s);
int ungetc(char c, FILE *stream);
// Direct input/output functions
//
size_t fread(void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
size_t fwrite(const void * restrict ptr, size_t size, size_t nmemb, FILE * restrict stream);
// File positioning functions
//
int fgetpos(FILE * restrict stream, fpos_t * restrict pos);
int fseek(FILE *stream, long int offset, int whence);
int fsetpos(FILE *stream, const fpos_t *pos);
long ftell(FILE *stream);
void rewind(FILE *stream);
// Error-handling functions
//
void clearerr(FILE *stream);
int feof(FILE *stream);
int ferror(FILE *stream);
void perror(const char *s);
#ifdef __cplusplus
} // extern "C"
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,3 @@
#include <stdio.h>
int putchar(char c) {return 0;}

108
src/libraries/libc/stdlib.h Normal file
View File

@@ -0,0 +1,108 @@
#pragma once
/** \file stdlib.h
* General utilities
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/null.h>
#include <__j6libc/restrict.h>
#include <__j6libc/size_t.h>
#include <__j6libc/wchar_t.h>
#ifdef __cplusplus
extern "C" {
#endif
// Numeric conversion functions
//
double atof( const char *nptr );
int atoi( const char *nptr );
long atol( const char *nptr );
long long atoll( const char *nptr );
double strtod( const char * restrict nptr, char ** restrict endptr );
float strtof( const char * restrict nptr, char ** restrict endptr );
long double strtold( const char * restrict nptr, char ** restrict endptr );
long strtol( const char * restrict nptr, char ** restrict endptr, int base );
long long strtoll( const char * restrict nptr, char ** restrict endptr, int base );
unsigned long strtoul( const char * restrict nptr, char ** restrict endptr, int base );
unsigned long long strtoull( const char * restrict nptr, char ** restrict endptr, int base );
// Pseudo-random sequence generation functions
//
#define RAND_MAX 0
int rand( void );
void srand( unsigned int seed );
// Memory management functions
//
void *aligned_alloc( size_t alignment, size_t size );
void *calloc( size_t nmemb, size_t size);
void free( void *ptr );
void *malloc( size_t size );
void *realloc( void *ptr, size_t size );
// Bonus functions from dlmalloc
void* realloc_in_place( void *ptr, size_t size );
void* memalign(size_t, size_t);
int posix_memalign(void**, size_t, size_t);
void* valloc(size_t);
void* pvalloc(size_t);
// Communication with the environment
//
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 127
_Noreturn void abort( void );
int atexit( void (*func)(void) );
int at_quick_exit( void (*func)(void) );
_Noreturn void exit( int status );
_Noreturn void _Exit( int status );
char *getenv( const char *name );
_Noreturn void quick_exit( int status );
int system( const char *string );
// Searching and sorting utilities
//
typedef int (*__cmp)( const void *, const void *);
void *bsearch( const void *key, const void *base, size_t nmemb, size_t size, __cmp compar );
void qsort( const void *base, size_t nmemb, size_t size, __cmp compar );
// Integer arithmetic functions
//
struct div_t { int quot; int rem; };
struct ldiv_t { long quot; long rem; };
struct lldiv_t { long long quot; long long rem; };
int abs( int j );
long labs( long j );
long long llabs( long long j );
struct div_t div( int numer, int denom );
struct ldiv_t ldiv( long numer, long denom );
struct lldiv_t lldiv( long long numer, long long denom );
// Multibyte / wide character conversion functions
//
#define MB_CUR_MAX SIZE_C(4)
int mblen( const char *s, size_t n );
int mbtowc( wchar_t * restrict pwc, const char * restrict s, size_t n );
int wctomb( char *s, wchar_t wc );
int mbstowcs( wchar_t * restrict pwcs, const char * restrict s, size_t n );
int wcstombs( char * restrict s, const wchar_t * restrict pwcs, size_t n );
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,18 @@
/** \file _Exit.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdlib.h>
#include <j6/syscalls.h>
void
_Exit( int status )
{
j6_process_exit(status);
}

View File

@@ -0,0 +1,18 @@
/** \file abort.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdlib.h>
#include <stdint.h>
void
abort()
{
_Exit(INT32_MIN);
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,17 @@
/** \file exit.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <stdlib.h>
void
exit( int status )
{
_Exit(status);
}

View File

@@ -0,0 +1,19 @@
#pragma once
/** \file stdnoreturn.h
* noreturn convenience macros
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#ifdef __cplusplus
#define noreturn [[noreturn]]
#elif __STDC_VERSION__ >= 201103L
#define noreturn _Noreturn
#else
#define noreturn
#endif

View File

@@ -0,0 +1,65 @@
#pragma once
/** \file string.h
* String handling
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/null.h>
#include <__j6libc/restrict.h>
#include <__j6libc/size_t.h>
#ifdef __cplusplus
extern "C" {
#endif
// Copying functions
//
void *memcpy(void * restrict s1, const void * restrict s2, size_t n);
void *memmove(void * restrict s1, const void * restrict s2, size_t n);
char *strncpy(char * restrict s1, const char * restrict s2, size_t n);
// Concatenation functions
//
char *strncat(char * restrict s1, const char * restrict s2, size_t n);
// Comparison functions
//
int memcmp(const void *s1, const void *s2, size_t n);
int strcmp(const char *s1, const char *s2);
int strcoll(const char *s1, const char *s2);
int strncmp(const char *s1, const char *s2, size_t n);
size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n);
// Search functions
//
void *memchr(const void *s, int c, size_t n);
char *strchr(const char *s, int c);
size_t strcspn(const char *s1, const char *s2);
char *strpbrk(const char *s1, const char *s2);
char *strrchr(const char *s, int c);
size_t strspn(const char *s1, const char *s2);
char *strstr(const char *s1, const char *s2);
char *strtok(char * restrict s1, const char * restrict s2);
// Miscellaneous functions
//
void *memset(void *s, int c, size_t n);
char *strerror(int errnum);
size_t strlen(const char *s);
// Deprecated functions
//
char *strcpy(char * restrict, const char * restrict)
__attribute__((deprecated("strcpy is unsafe, do not use", "strncpy")));
char *strcat(char * restrict, const char * restrict)
__attribute__((deprecated("strcat is unsafe, do not use", "strncat")));
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,23 @@
/** \file memchr.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/casts.h>
using namespace __j6libc;
void *memchr(const void *s, int c, size_t n) {
if (!s || !n) return nullptr;
char const *b = reinterpret_cast<char const*>(s);
while(n && *b && *b != c) { b++; n--; }
return (n && *b) ? cast_to<void*>(b) : nullptr;
}

View File

@@ -0,0 +1,25 @@
/** \file memcmp.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
int memcmp(const void *s1, const void *s2, size_t n) {
if (!s1 || !s2) return 0;
char const * c1 = reinterpret_cast<char const*>(s1);
char const * c2 = reinterpret_cast<char const*>(s2);
while (n && *c1++ == *c2++) n--;
if (!n) return 0;
if (c1 > c2) return 1;
return -1;
}

View File

@@ -0,0 +1,42 @@
/** \file memcpy.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <stddef.h>
#include <__j6libc/copy.h>
using namespace __j6libc;
inline void memcpy_dispatch(char *s1, const char *s2, size_t n) {
if (n == 0) return;
if (n == 1) return do_copy<1>(s1, s2);
if (n == 2) return do_copy<2>(s1, s2);
if (n == 3) return do_copy<3>(s1, s2);
if (n == 4) return do_copy<4>(s1, s2);
if (n < 8) return do_double_copy<4>(s1, s2, n);
if (n == 8) return do_copy<8>(s1, s2);
if (n < 16) return do_double_copy<8>(s1, s2, n);
if (n < 32) return do_double_copy<16>(s1, s2, n);
if (n < 64) return do_double_copy<32>(s1, s2, n);
if (n < 128)
return do_double_copy<64>(s1, s2, n);
else
return do_large_copy(s1, s2, n);
}
void *memcpy(void * restrict s1, const void * restrict s2, size_t n) {
memcpy_dispatch(
reinterpret_cast<char*>(s1),
reinterpret_cast<const char*>(s2),
n);
return s1;
}

View File

@@ -0,0 +1,33 @@
/** \file memmove.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/copy.h>
using namespace __j6libc;
void memmove_dispatch(char *s1, const char *s2, size_t n) {
if (s1 == s2) return;
if (s1 < s2 || s1 > s2 + n)
memcpy(s1, s2, n);
else
do_backward_copy(s1, s2, n);
}
void *memmove(void * restrict s1, const void * restrict s2, size_t n) {
memmove_dispatch(
reinterpret_cast<char*>(s1),
reinterpret_cast<const char*>(s2),
n);
return s1;
}

View File

@@ -0,0 +1,57 @@
/** \file memset.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/bits.h>
#include <__j6libc/casts.h>
using namespace __j6libc;
#if __UINTPTR_WIDTH__ != 64 && __UINTPTR_WIDTH__ != 32
#error "memset: uintptr_t isn't 4 or 8 bytes"
#endif
static inline uintptr_t repval(uint8_t c) {
uintptr_t r = c;
r |= r << 8;
r |= r << 16;
#if __UINTPTR_WIDTH__ == 64
r |= r << 32;
#endif
return r;
}
void *memset(void *s, int c, size_t n) {
if (!s) return nullptr;
// First, any unalined initial bytes
uint8_t *b = cast_to<uint8_t*>(s);
uint8_t bval = c & 0xff;
while (n && !is_aligned<uintptr_t>(b)) {
*b++ = bval;
--n;
}
// As many word-sized writes as possible
size_t words = n >> word_shift;
uintptr_t pval = repval(c);
uintptr_t *p = cast_to<uintptr_t*>(b);
for (size_t i = 0; i < words; ++i)
*p++ = pval;
// Remaining unaligned bytes
b = reinterpret_cast<uint8_t*>(p);
size_t remainder = n & word_align_mask;
for (size_t i = 0; i < remainder; ++i)
*b++ = bval;
return s;
}

View File

@@ -0,0 +1,22 @@
/** \file strchr.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/casts.h>
using namespace __j6libc;
char *strchr(const char *s, int c) {
if (!s) return nullptr;
while(*s && *s != c) s++;
return *s ? cast_to<char*>(s) : nullptr;
}

View File

@@ -0,0 +1,25 @@
/** \file memcpy.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
int strcmp(const char *s1, const char *s2) {
if (!s1 || !s2) return 0;
char const * c1 = s1;
char const * c2 = s2;
while (*c1 && *c2 && *c1++ == *c2++);
if (*c1 == *c2) return 0;
if (!*c2 || *c1 > *c2) return 1;
return -1;
}

View File

@@ -0,0 +1,16 @@
/** \file memcpy.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
// Currently only implemented for "C" locale
int strcoll(const char *s1, const char *s2) {
return strcmp(s1, s2);
}

View File

@@ -0,0 +1,25 @@
/** \file strcspn.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
size_t strcspn(const char *s1, const char *s2) {
if (!s1 || !s2) return 0;
char const *p = s1;
size_t s2len = strlen(s2);
size_t total = 0;
while (char c = *p) {
for (size_t i = 0; i < s2len; ++i)
if (c == s2[i]) return total;
++total;
}
return total;
}

View File

@@ -0,0 +1,19 @@
/** \file strlen.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
size_t strlen(const char *s) {
if (!s) return 0;
size_t len = 0;
while(*s++) len++;
return len;
}

View File

@@ -0,0 +1,27 @@
/** \file strncat.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <stddef.h>
#include <__j6libc/copy.h>
char *strncat(char * restrict s1, const char * restrict s2, size_t n) {
if (!s1 || !s2 || !n)
return s1;
char *dest = s1;
char const *src = s2;
while (*dest++);
while (*src && n--) *dest++ = *src++;
*dest = 0;
return s1;
}

View File

@@ -0,0 +1,25 @@
/** \file memcpy.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
int strncmp(const char *s1, const char *s2, size_t n) {
if (!s1 || !s2) return 0;
char const * c1 = s1;
char const * c2 = s2;
while (n && *c1 && *c2 && *c1++ == *c2++) n--;
if (!n || *c1 == *c2) return 0;
if (!*c2 || *c1 > *c2) return 1;
return -1;
}

View File

@@ -0,0 +1,28 @@
/** \file strncpy.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
char *strncpy(char * restrict s1, const char * restrict s2, size_t n) {
if (!s1 || !s2 || !n)
return s1;
char *dest = s1;
char const *src = s2;
while (n && *src) {
*dest++ = *src++;
n--;
}
while (n--) *dest++ = 0;
return s1;
}

View File

@@ -0,0 +1,25 @@
/** \file strpbrk.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/casts.h>
using namespace __j6libc;
char *strpbrk(const char *s1, const char *s2) {
if (!s1 || !s2) return nullptr;
char const *p = s1;
size_t s2len = strlen(s2);
while (char c = *p)
for (size_t i = 0; i < s2len; ++i)
if (c == s2[i]) return cast_to<char*>(p);
return nullptr;
}

View File

@@ -0,0 +1,27 @@
/** \file strrchr.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
#include <__j6libc/casts.h>
using namespace __j6libc;
char *strrchr(const char *s, int c) {
if (!s) return nullptr;
char const *p = nullptr;
while(*s) {
if (*s == c)
p = s;
s++;
}
return cast_to<char*>(p);
}

View File

@@ -0,0 +1,21 @@
/** \file strxfrm.cpp
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <string.h>
size_t strxfrm(char * restrict s1, const char * restrict s2, size_t n) {
size_t l = strlen(s2) + 1;
l = l > n ? n : l;
memcpy(s1, s2, l);
s1[l - 1] = 0;
return l;
}

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file tgmath.h
* Type-generic math
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error tgmath.h is not yet implemented.

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file threads.h
* Threads
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error threads.h is not yet implemented.

13
src/libraries/libc/time.h Normal file
View File

@@ -0,0 +1,13 @@
#pragma once
/** \file time.h
* Date and time
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error time.h is not yet implemented.

View File

@@ -0,0 +1,15 @@
#pragma once
/** \file uchar.h
* Unicode utilities
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/mbstate_t.h>
#include <__j6libc/size_t.h>
#include <__j6libc/uchar.h>

139
src/libraries/libc/wchar.h Normal file
View File

@@ -0,0 +1,139 @@
#pragma once
/** \file wchar.h
* Extended mutlibyte and wide character utilities
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <__j6libc/file.h>
#include <__j6libc/null.h>
#include <__j6libc/restrict.h>
#include <__j6libc/size_t.h>
#include <__j6libc/wchar_t.h>
#include <stdarg.h>
typedef unsigned int wint_t;
#define WEOF ((wint_t)-1)
struct tm;
typedef struct {
} mbstate_t;
#ifdef __cplusplus
extern "C" {
#endif
// Formatted wide character input/output functions
//
int wprintf(const wchar_t * restrict format, ...);
int vwprintf(const wchar_t * restrict format, va_list arg);
int fwprintf(FILE * restrict stream, const wchar_t * restrict format, ...);
int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg);
int swprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, ...);
int vswprintf(wchar_t * restrict s, size_t n, const wchar_t * restrict format, va_list arg);
int wscanf(const wchar_t * restrict format, ...);
int vwscanf(const wchar_t * restrict format, va_list arg);
int fwscanf(FILE * restrict stream, const wchar_t * restrict format, ...);
int vfwscanf(FILE * restrict stream, const wchar_t * restrict format, va_list arg);
int swscanf(const wchar_t * restrict s, const wchar_t * restrict format, ...);
int vswscanf(const wchar_t * restrict s, const wchar_t * restrict format, va_list arg);
// Wide character input/output functions
//
wint_t fgetwc(FILE * stream);
wchar_t * fgetws(wchar_t * restrict s, size_t n, FILE * stream);
wint_t fputwc(wchar_t c, FILE * stream);
int fputws(const wchar_t * restrict s, FILE * stream);
int fwide(FILE * stream, int mode);
wint_t getwc(FILE * stream);
wint_t getwchar(void);
wint_t putwc(wchar_t c, FILE * stream);
wint_t putwchar(wchar_t c);
wint_t ungetwc(wchar_t c, FILE * stream);
// General wide string utilities: numeric conversion functions
//
double wcstod(const wchar_t * restrict nptr, wchar_t ** restrict endptr);
float wcstof(const wchar_t * restrict nptr, wchar_t ** restrict endptr);
long double wcstold(const wchar_t * restrict nptr, wchar_t ** restrict endptr);
long wcstol(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
long long wcstoll(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
unsigned long wcstoul(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
unsigned long long wcstoull(const wchar_t * restrict nptr, wchar_t ** restrict endptr, int base);
// General wide string utilities: numeric conversion functions
//
wchar_t * wcscpy(wchar_t * restrict s1, const wchar_t * restrict s2);
wchar_t * wcsncpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
wchar_t * wmemcpy(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
wchar_t * wmemmove(wchar_t * s1, const wchar_t * s2, size_t n);
// General wide string utilities: concatenation functions
//
wchar_t * wcscat(wchar_t * restrict s1, const wchar_t * restrict s2);
wchar_t * wcsncat(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
// General wide string utilities: comparison functions
//
int wcscmp(const wchar_t * s1, const wchar_t * s2);
int wcscoll(const wchar_t * s1, const wchar_t * s2);
int wcsncmp(const wchar_t * s1, const wchar_t * s2, size_t n);
size_t wcsxfrm(wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
int wmemcmp(const wchar_t * s1, const wchar_t * s2, size_t n);
// General wide string utilities: search functions
//
wchar_t * wcschr(const wchar_t * s, wchar_t c);
size_t wcscspn(const wchar_t * s1, const wchar_t * s2);
wchar_t * wcspbrk(const wchar_t * s1, const wchar_t * s2);
wchar_t * wcsrchr(const wchar_t * s, wchar_t c);
size_t wcsspn(const wchar_t * s1, const wchar_t * s2);
wchar_t * wcsstr(const wchar_t * s1, const wchar_t * s2);
wchar_t * wcstok(wchar_t * restrict s1, const wchar_t * restrict s2, wchar_t ** restrict ptr);
wchar_t * wmemchr(const wchar_t * s, wchar_t c, size_t n);
// Miscellaneous functions
//
size_t wcslen(const wchar_t * s);
wchar_t wmemset(wchar_t * s, wchar_t c, size_t n);
// Wide character time conversion functions
//
size_t wcsftime(wchar_t * restrict s, size_t maxsize, const wchar_t * restrict format,
const struct tm * restrict timeptr);
// Extended multi-byte/wide character conversion utilities
//
wint_t btowc(int c);
int wctob(wint_t c);
int mbsinit(const mbstate_t *ps);
size_t mbrlen(const char * restrict s, size_t n, mbstate_t * restrict ps);
size_t mbrtowc(wchar_t * restrict pwc, const char * restrict s, size_t n, mbstate_t * restrict ps);
size_t wcrtomb(char * restrict s, wchar_t wc, mbstate_t * restrict ps);
size_t mbsrtowcs(wchar_t * restrict dst, const char ** restrict src, size_t len, mbstate_t * restrict ps);
size_t wcsrtombs(char * restrict dst, const wchar_t ** restrict src, size_t len, mbstate_t * restrict ps);
#ifdef __cplusplus
} // extern "C"
#endif

View File

@@ -0,0 +1,13 @@
#pragma once
/** \file wctype.h
* Wide character classification and mapping utilities
*
* This file is part of the C standard library for the jsix operating
* system.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#error wctype.h is not yet implemented.

View File

@@ -1,6 +1,6 @@
extern main
extern exit
extern _init_libj6
extern __init_libj6
extern _arg_modules_phys
section .bss
@@ -27,7 +27,7 @@ _start:
mov rbp, rsp
mov rdi, rsp
call _init_libj6
call __init_libj6
pop rdi
mov rsi, rsp