diff --git a/build.sh b/build.sh index 657a459..c866331 100755 --- a/build.sh +++ b/build.sh @@ -1,20 +1,11 @@ #!/bin/bash -cd rocklibc -make clean -make -cd .. - -cd programs -make clean -make -cd .. +./build_libc.sh +./build_programs.sh make clean -make +bear -- make -cd initrd ./make_img.sh -cd .. make -B \ No newline at end of file diff --git a/build_and_run.sh b/build_and_run.sh index f1ac468..0ad7525 100755 --- a/build_and_run.sh +++ b/build_and_run.sh @@ -1,23 +1,6 @@ #!/bin/bash -# cd rocklibc -# make clean -# make -# cd .. - -cd programs -make clean -make -cd .. - -make clean -make - -cd initrd -./make_img.sh -cd .. - -make -B +./build.sh make run diff --git a/build_libc.sh b/build_libc.sh new file mode 100755 index 0000000..7f4ce6a --- /dev/null +++ b/build_libc.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +cd rocklibc +make clean +bear -- make +cd .. \ No newline at end of file diff --git a/build_programs.sh b/build_programs.sh new file mode 100755 index 0000000..7389f79 --- /dev/null +++ b/build_programs.sh @@ -0,0 +1,17 @@ +#!/bin/bash + + +mkdir -p programs/lib +mkdir -p programs/bin + +cp rocklibc/rlibc.a programs/lib + +cd programs + +cd rocksh + +make clean +bear -- make +cp rocksh.elf ../bin + +cd ../.. \ No newline at end of file diff --git a/clean.sh b/clean.sh index 7895d11..8f42b64 100755 --- a/clean.sh +++ b/clean.sh @@ -4,9 +4,9 @@ cd rocklibc make clean cd .. -cd programs +cd programs/rocksh make clean -cd .. +cd ../.. make clean diff --git a/compile_commands.json b/compile_commands.json index f9c250d..ada386e 100644 --- a/compile_commands.json +++ b/compile_commands.json @@ -1,21 +1,4 @@ [ - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/initrd.c.o", - "kernel/initrd.c" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/initrd.c", - "output": "/home/slinky/source/RockOS/obj/kernel/initrd.c.o" - }, { "arguments": [ "/home/slinky/opt/cross/bin/i686-elf-gcc", @@ -43,12 +26,29 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/gdt.c.o", - "kernel/gdt.c" + "obj/kernel/vfs.c.o", + "kernel/vfs.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/gdt.c", - "output": "/home/slinky/source/RockOS/obj/kernel/gdt.c.o" + "file": "/home/slinky/source/RockOS/kernel/vfs.c", + "output": "/home/slinky/source/RockOS/obj/kernel/vfs.c.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/kmain.c.o", + "kernel/kmain.c" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/kmain.c", + "output": "/home/slinky/source/RockOS/obj/kernel/kmain.c.o" }, { "arguments": [ @@ -67,6 +67,57 @@ "file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.c", "output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.c.o" }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/cpio/cpio.c.o", + "kernel/drivers/cpio/cpio.c" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/cpio/cpio.c", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/cpio/cpio.c.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/vga/vga.c.o", + "kernel/drivers/vga/vga.c" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/vga/vga.c", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/vga/vga.c.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/ide/ide.c.o", + "kernel/drivers/ide/ide.c" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/ide/ide.c", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/ide/ide.c.o" + }, { "arguments": [ "/home/slinky/opt/cross/bin/i686-elf-gcc", @@ -111,12 +162,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/drivers/ide/ide.c.o", - "kernel/drivers/ide/ide.c" + "obj/kernel/gdt.c.o", + "kernel/gdt.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/drivers/ide/ide.c", - "output": "/home/slinky/source/RockOS/obj/kernel/drivers/ide/ide.c.o" + "file": "/home/slinky/source/RockOS/kernel/gdt.c", + "output": "/home/slinky/source/RockOS/obj/kernel/gdt.c.o" }, { "arguments": [ @@ -128,12 +179,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/drivers/vga/vga.c.o", - "kernel/drivers/vga/vga.c" + "obj/kernel/memory/mm.c.o", + "kernel/memory/mm.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/drivers/vga/vga.c", - "output": "/home/slinky/source/RockOS/obj/kernel/drivers/vga/vga.c.o" + "file": "/home/slinky/source/RockOS/kernel/memory/mm.c", + "output": "/home/slinky/source/RockOS/obj/kernel/memory/mm.c.o" }, { "arguments": [ @@ -145,12 +196,29 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/scheduler.c.o", - "kernel/scheduler.c" + "obj/kernel/kbd.c.o", + "kernel/kbd.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/scheduler.c", - "output": "/home/slinky/source/RockOS/obj/kernel/scheduler.c.o" + "file": "/home/slinky/source/RockOS/kernel/kbd.c", + "output": "/home/slinky/source/RockOS/obj/kernel/kbd.c.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/multiboot.c.o", + "kernel/multiboot.c" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/multiboot.c", + "output": "/home/slinky/source/RockOS/obj/kernel/multiboot.c.o" }, { "arguments": [ @@ -186,40 +254,6 @@ "file": "/home/slinky/source/RockOS/kernel/syscall.c", "output": "/home/slinky/source/RockOS/obj/kernel/syscall.c.o" }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/kmain.c.o", - "kernel/kmain.c" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/kmain.c", - "output": "/home/slinky/source/RockOS/obj/kernel/kmain.c.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/lib/tasks.c.o", - "kernel/lib/tasks.c" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/lib/tasks.c", - "output": "/home/slinky/source/RockOS/obj/kernel/lib/tasks.c.o" - }, { "arguments": [ "/home/slinky/opt/cross/bin/i686-elf-gcc", @@ -237,23 +271,6 @@ "file": "/home/slinky/source/RockOS/kernel/lib/stream.c", "output": "/home/slinky/source/RockOS/obj/kernel/lib/stream.c.o" }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/lib/print.c.o", - "kernel/lib/print.c" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/lib/print.c", - "output": "/home/slinky/source/RockOS/obj/kernel/lib/print.c.o" - }, { "arguments": [ "/home/slinky/opt/cross/bin/i686-elf-gcc", @@ -281,12 +298,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/vfs.c.o", - "kernel/vfs.c" + "obj/kernel/lib/print.c.o", + "kernel/lib/print.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/vfs.c", - "output": "/home/slinky/source/RockOS/obj/kernel/vfs.c.o" + "file": "/home/slinky/source/RockOS/kernel/lib/print.c", + "output": "/home/slinky/source/RockOS/obj/kernel/lib/print.c.o" }, { "arguments": [ @@ -298,12 +315,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/memory/mm.c.o", - "kernel/memory/mm.c" + "obj/kernel/lib/tasks.c.o", + "kernel/lib/tasks.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/memory/mm.c", - "output": "/home/slinky/source/RockOS/obj/kernel/memory/mm.c.o" + "file": "/home/slinky/source/RockOS/kernel/lib/tasks.c", + "output": "/home/slinky/source/RockOS/obj/kernel/lib/tasks.c.o" }, { "arguments": [ @@ -315,12 +332,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/drivers/pic/pic.S.o", - "kernel/drivers/pic/pic.S" + "obj/kernel/lib/strtok.c.o", + "kernel/lib/strtok.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.S", - "output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.S.o" + "file": "/home/slinky/source/RockOS/kernel/lib/strtok.c", + "output": "/home/slinky/source/RockOS/obj/kernel/lib/strtok.c.o" }, { "arguments": [ @@ -332,29 +349,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/drivers/ps2/ps2.S.o", - "kernel/drivers/ps2/ps2.S" + "obj/kernel/scheduler.c.o", + "kernel/scheduler.c" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/drivers/ps2/ps2.S", - "output": "/home/slinky/source/RockOS/obj/kernel/drivers/ps2/ps2.S.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/drivers/pit/pit.S.o", - "kernel/drivers/pit/pit.S" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/drivers/pit/pit.S", - "output": "/home/slinky/source/RockOS/obj/kernel/drivers/pit/pit.S.o" + "file": "/home/slinky/source/RockOS/kernel/scheduler.c", + "output": "/home/slinky/source/RockOS/obj/kernel/scheduler.c.o" }, { "arguments": [ @@ -383,12 +383,80 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/interrupts.S.o", - "kernel/interrupts.S" + "obj/kernel/common.S.o", + "kernel/common.S" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/interrupts.S", - "output": "/home/slinky/source/RockOS/obj/kernel/interrupts.S.o" + "file": "/home/slinky/source/RockOS/kernel/common.S", + "output": "/home/slinky/source/RockOS/obj/kernel/common.S.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/pic/pic.S.o", + "kernel/drivers/pic/pic.S" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/pic/pic.S", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/pic/pic.S.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/pit/pit.S.o", + "kernel/drivers/pit/pit.S" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/pit/pit.S", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/pit/pit.S.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/drivers/ps2/ps2.S.o", + "kernel/drivers/ps2/ps2.S" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/drivers/ps2/ps2.S", + "output": "/home/slinky/source/RockOS/obj/kernel/drivers/ps2/ps2.S.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-c", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-Ikernel", + "-o", + "obj/kernel/memory/mm.S.o", + "kernel/memory/mm.S" + ], + "directory": "/home/slinky/source/RockOS", + "file": "/home/slinky/source/RockOS/kernel/memory/mm.S", + "output": "/home/slinky/source/RockOS/obj/kernel/memory/mm.S.o" }, { "arguments": [ @@ -407,23 +475,6 @@ "file": "/home/slinky/source/RockOS/kernel/boot/boot.S", "output": "/home/slinky/source/RockOS/obj/kernel/boot/boot.S.o" }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-c", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Ikernel", - "-o", - "obj/kernel/common.S.o", - "kernel/common.S" - ], - "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/common.S", - "output": "/home/slinky/source/RockOS/obj/kernel/common.S.o" - }, { "arguments": [ "/home/slinky/opt/cross/bin/i686-elf-gcc", @@ -451,12 +502,12 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/memory/mm_stubs.S.o", - "kernel/memory/mm_stubs.S" + "obj/kernel/gdt.S.o", + "kernel/gdt.S" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/memory/mm_stubs.S", - "output": "/home/slinky/source/RockOS/obj/kernel/memory/mm_stubs.S.o" + "file": "/home/slinky/source/RockOS/kernel/gdt.S", + "output": "/home/slinky/source/RockOS/obj/kernel/gdt.S.o" }, { "arguments": [ @@ -468,11 +519,11 @@ "-Wextra", "-Ikernel", "-o", - "obj/kernel/gdt.S.o", - "kernel/gdt.S" + "obj/kernel/interrupts.S.o", + "kernel/interrupts.S" ], "directory": "/home/slinky/source/RockOS", - "file": "/home/slinky/source/RockOS/kernel/gdt.S", - "output": "/home/slinky/source/RockOS/obj/kernel/gdt.S.o" + "file": "/home/slinky/source/RockOS/kernel/interrupts.S", + "output": "/home/slinky/source/RockOS/obj/kernel/interrupts.S.o" } ] diff --git a/initrd/make_img.sh b/initrd/make_img.sh deleted file mode 100755 index dd5dd03..0000000 --- a/initrd/make_img.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/bash - -mkdir -p output -rm -rf output/* -find . -depth -print | cpio -o -H newc > output/initrd.img -cp output/initrd.img ../isodir/boot \ No newline at end of file diff --git a/kernel/drivers/pic/pic.S b/kernel/drivers/pic/pic.S index a41ef5b..38d2870 100644 --- a/kernel/drivers/pic/pic.S +++ b/kernel/drivers/pic/pic.S @@ -33,7 +33,7 @@ init_pic: outb %al, $PIC2_DATA # mask - mov $0xFE, %al + mov $0xF8, %al outb %al, $PIC1_DATA mov $0xFF, %al outb %al, $PIC2_DATA diff --git a/kernel/drivers/ps2/ps2.c b/kernel/drivers/ps2/ps2.c index 36b45d8..7146eff 100644 --- a/kernel/drivers/ps2/ps2.c +++ b/kernel/drivers/ps2/ps2.c @@ -2,13 +2,18 @@ #include +static const char scancode_to_ascii[] = { + 0, 27, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', '\b', + '\t', 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\n', + 0, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', '`', 0, + '\\', 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', 0, '*', 0, ' ' +}; + extern void ps2_wait_input_empty(void); extern void ps2_wait_output_full(void); extern void ps2_write_command(uint8_t); -extern uint8_t ps2_read_data(void); extern void ps2_write_data(uint8_t); extern void ps2_flush_output_buffer(void); - extern void io_wait(void); static uint8_t read_ccb() { @@ -68,4 +73,19 @@ int init_ps2() { write_ccb(ccb); return 0; -} \ No newline at end of file +} + +char ps2_get_ascii(uint8_t scancode) { + if (scancode & 0x80) { + return 0; + } + + if (scancode < sizeof(scancode_to_ascii)) { + char ascii = scancode_to_ascii[scancode]; + if (ascii != 0) { + return ascii; + } + } + + return 0; +} \ No newline at end of file diff --git a/kernel/drivers/ps2/ps2.h b/kernel/drivers/ps2/ps2.h index 9819803..607cf64 100644 --- a/kernel/drivers/ps2/ps2.h +++ b/kernel/drivers/ps2/ps2.h @@ -18,8 +18,11 @@ #ifndef __ASSEMBLER__ #include + int init_ps2(); uint8_t ps2_read_data(); + +char ps2_get_ascii(uint8_t scancode); #endif #endif \ No newline at end of file diff --git a/kernel/interrupts.c b/kernel/interrupts.c index d695670..cadab17 100644 --- a/kernel/interrupts.c +++ b/kernel/interrupts.c @@ -2,8 +2,7 @@ #include -#include "process.h" -#include "scheduler.h" +#include "kbd.h" #include "syscall.h" #include "common.h" #include "gdt.h" @@ -144,6 +143,11 @@ void common_interrupt_handler(intr_regs_t *args) { kprintf("Current cr3: 0x%x\n", fetch_cr3()); if (args->cs == 0x1b) { kprintf("User ESP: 0x%x\n", args->u_esp); + kprintf("ESP: 0x%x\t0x%x\t0x%x\t0x%x\n", + *(uint32_t*)args->u_esp, + *(uint32_t*)(args->u_esp + 4), + *(uint32_t*)(args->u_esp + 8), + *(uint32_t*)(args->u_esp + 12)); kprintf("User SS: 0x%x\n", args->u_ss); } kprintf("Caused by: %s, %s, running in %s mode\n", @@ -158,8 +162,11 @@ void common_interrupt_handler(intr_regs_t *args) { break; } case 33: { - kprintf("ps2 keyboard interrupt\n"); uint8_t data = ps2_read_data(); + char ascii = ps2_get_ascii(data); + if (ascii != 0) { + kbd_push(ascii); + } send_eoi_master(); break; } diff --git a/kernel/kbd.c b/kernel/kbd.c new file mode 100644 index 0000000..c2c90a6 --- /dev/null +++ b/kernel/kbd.c @@ -0,0 +1,84 @@ +#include "kbd.h" +#include "process.h" +#include "scheduler.h" +#include "common.h" + +#include +#include + +#include + +#define KBD_BUFFER_SIZE 256 + +static spinlock_t kbd_lock = {0}; +static process_t* kbd_waiting_task = NULL; + +static char kbd_buffer[KBD_BUFFER_SIZE]; +static int kbd_head = 0; +static int kbd_tail = 0; + +static void lock_kbd() { + disable_interrupts(); + spin_lock(&kbd_lock); +} + +static void unlock_kbd() { + spin_unlock(&kbd_lock); + enable_interrupts(); +} + +static void kbd_set_waiting(process_t* task) { + lock_kbd(); + if (kbd_head == kbd_tail) { + kbd_waiting_task = task; + } + unlock_kbd(); +} + +static char kbd_pop() { + char c = 0; + lock_kbd(); + if (kbd_head != kbd_tail) { + c = kbd_buffer[kbd_tail]; + kbd_tail = (kbd_tail + 1) % KBD_BUFFER_SIZE; + } + unlock_kbd(); + return c; +} + +void kbd_push(char c) { + spin_lock(&kbd_lock); + // push to buffer first, very important + int next_head = (kbd_head + 1) % KBD_BUFFER_SIZE; + if (next_head != kbd_tail) { + kbd_buffer[kbd_head] = c; + kbd_head = next_head; + } + + if (kbd_waiting_task != NULL) { + wake(kbd_waiting_task); + kbd_waiting_task = NULL; + } + spin_unlock(&kbd_lock); +} + +int kbd_ready() { + int ready = 0; + lock_kbd(); + ready = (kbd_head != kbd_tail); + unlock_kbd(); + return ready; +} + +void kbd_wait() { + process_t* task = current_task(); + while (!kbd_ready()) { + task->state = STATE_BLOCKED; + kbd_set_waiting(task); + yield(); + } +} + +char kbd_read() { + return kbd_pop(); +} \ No newline at end of file diff --git a/kernel/kbd.h b/kernel/kbd.h new file mode 100644 index 0000000..5105aa2 --- /dev/null +++ b/kernel/kbd.h @@ -0,0 +1,6 @@ +#pragma once + +char kbd_read(); +void kbd_push(char c); +int kbd_ready(); +void kbd_wait(); \ No newline at end of file diff --git a/kernel/kmain.c b/kernel/kmain.c index 3f558df..1aa8749 100644 --- a/kernel/kmain.c +++ b/kernel/kmain.c @@ -57,6 +57,7 @@ vfs_node_t* load_initrd() { } void load_root_program(const char* path) { + disable_interrupts(); uint32_t kernel_cr3 = fetch_cr3(); void* cr3 = create_task_pd(); load_pd(cr3); @@ -129,6 +130,7 @@ void load_root_program(const char* path) { *(--u_esp) = 0; // argc = 0 create_task(e_hdr->e_entry, (uint32_t)cr3, 1, (uint32_t)u_esp); + enable_interrupts(); load_pd((void*)kernel_cr3); flush_tlb(); @@ -169,7 +171,8 @@ void kmain(uint32_t magic, multiboot_info* mbi) { disable_interrupts(); init_scheduler(); - load_root_program("/origin.elf"); - kprintf("done loading origin program\n"); enable_interrupts(); + + kprintf("loading rocksh...\n"); + load_root_program("/rocksh.elf"); } diff --git a/kernel/lib/print.c b/kernel/lib/print.c index 099ec59..34f8b52 100644 --- a/kernel/lib/print.c +++ b/kernel/lib/print.c @@ -80,6 +80,11 @@ void kprintf(const char* fmt, ...) { kputx(x); break; } + case 'c': { + int c = va_arg(args, int); + vga_putchar((char)c); + break; + } case '%': vga_putchar('%'); break; diff --git a/kernel/scheduler.S b/kernel/scheduler.S index 83181d5..fd0e4e4 100644 --- a/kernel/scheduler.S +++ b/kernel/scheduler.S @@ -6,24 +6,31 @@ yield: # void yield() cli - pushfl - pushl %cs + popl %ecx + + pushfl // EFLAGS + pushl %cs // CS + pushl %ecx // EIP - movl 8(%esp), %eax + pushal + call send_eoi_master + + xor %eax, %eax + mov %ds, %ax pushl %eax - movl 4(%esp), %ebx # Get CS - movl %ebx, 8(%esp) # Move CS over Old EIP - movl 0(%esp), %ebx # Get Return EIP - movl %ebx, 4(%esp) # Move Return EIP over CS - addl $4, %esp # Adjust stack pointer up. - - pushal + mov $0x10, %ax + mov %ax, %ds + mov %ax, %es pushl %esp call switch_context movl %eax, %esp + popl %eax + mov %ax, %ds + mov %ax, %es + popal sti iret \ No newline at end of file diff --git a/kernel/scheduler.c b/kernel/scheduler.c index 8d16410..2cd4765 100644 --- a/kernel/scheduler.c +++ b/kernel/scheduler.c @@ -149,10 +149,16 @@ int create_task(uint32_t entry_point, uint32_t cr3, int user, uint32_t u_esp) { } process_t* current_task() { + lock_scheduler(); process_t* rtn = &process_table[current_process]; + unlock_scheduler(); return rtn; } +process_t* current_task_unsafe() { + return &process_table[current_process]; +} + void sleep(uint32_t ms) { if (ms == 0) return; lock_scheduler(); @@ -169,3 +175,10 @@ void exit() { unlock_scheduler(); } +void wake(process_t* task) { + lock_scheduler(); + if (task->state == STATE_SLEEPING || task->state == STATE_BLOCKED) { + task->state = STATE_READY; + } + unlock_scheduler(); +} \ No newline at end of file diff --git a/kernel/scheduler.h b/kernel/scheduler.h index 63755fe..e771226 100644 --- a/kernel/scheduler.h +++ b/kernel/scheduler.h @@ -12,5 +12,6 @@ process_t* current_task(); void sleep(uint32_t ms); void yield(); void exit(); +void wake(process_t* task); #endif \ No newline at end of file diff --git a/kernel/syscall.c b/kernel/syscall.c index 6da6104..b50d52f 100644 --- a/kernel/syscall.c +++ b/kernel/syscall.c @@ -4,22 +4,18 @@ #include "memory/mm.h" #include "process.h" #include "scheduler.h" +#include "kbd.h" #include #include -typedef struct registers { - uint32_t gs, fs, es, ds; // Pushed manually - uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha - uint32_t int_no, err_code; // Pushed manually - uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU -} registers_t; - static int32_t sys_exit(int status) { - asm volatile("cli"); - asm volatile("hlt"); + process_t* task = current_task(); + task->state = STATE_DEAD; + kprintf("Process %d exited with status %d\n", task->pid, status); + exit(); return 0; } @@ -35,13 +31,18 @@ static int32_t sys_write(int fd, const void* buf, size_t count) { } static int32_t sys_read(int fd, void* buf, size_t count) { - if (fd == 0) { // stdin + if (fd == 0) { char* cbuf = (char*)buf; size_t bytes_read = 0; + while (bytes_read < count) { - char c = 'r'; - cbuf[bytes_read++] = c; - if (c == '\n') break; + kbd_wait(); + + if (kbd_ready()) { + char c = kbd_read(); + cbuf[bytes_read++] = c; + if (c == '\n') break; + } } return bytes_read; } @@ -83,6 +84,12 @@ static int32_t sys_brk(uint32_t new_break) { return current->heap_end; } +typedef struct registers { + uint32_t gs, fs, es, ds; // Pushed manually + uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax; // Pushed by pusha + uint32_t int_no, err_code; // Pushed manually + uint32_t eip, cs, eflags, useresp, ss; // Pushed automatically by CPU +} registers_t; int32_t syscall(registers_t* regs) { switch(regs->eax) { case 1: return sys_exit(regs->ebx); diff --git a/make_img.sh b/make_img.sh new file mode 100755 index 0000000..f72fd01 --- /dev/null +++ b/make_img.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +mkdir -p initrd +rm -f initrd/*.elf + +cp programs/bin/* initrd + +cd initrd +mkdir -p output +find . -depth -print | cpio -o -H newc > output/initrd.img +cd .. + +cp initrd/output/*.img isodir/boot \ No newline at end of file diff --git a/programs/lib/rlibc.a b/programs/lib/rlibc.a new file mode 100644 index 0000000..6844338 Binary files /dev/null and b/programs/lib/rlibc.a differ diff --git a/programs/main.c b/programs/main.c deleted file mode 100644 index abe7ab7..0000000 --- a/programs/main.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char *argv[]) { - printf("RockOS booting...\n"); - return 0; -} \ No newline at end of file diff --git a/programs/makefile b/programs/makefile deleted file mode 100644 index 6fee48f..0000000 --- a/programs/makefile +++ /dev/null @@ -1,24 +0,0 @@ -CC = i686-elf-gcc -LD = i686-elf-ld - -CFLAGS = -ffreestanding -O2 -Wall -Wextra -ffunction-sections -fdata-sections -I../rocklibc/include -LDFLAGS = -m elf_i386 -nostdlib --gc-sections - -TARGET = origin.elf - -all: $(TARGET) - -crt0.o: crt0.S - $(CC) $(CFLAGS) -c crt0.S -o crt0.o - -main.o: main.c - $(CC) $(CFLAGS) -c main.c -o main.o - -$(TARGET): crt0.o main.o ../rocklibc/rlibc.a - $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../rocklibc/rlibc.a $(shell $(CC) -print-libgcc-file-name) -o $(TARGET) - cp $(TARGET) ../initrd - -clean: - rm -f *.o $(TARGET) - -.PHONY: all clean test \ No newline at end of file diff --git a/programs/rocksh/compile_commands.json b/programs/rocksh/compile_commands.json new file mode 100644 index 0000000..33b6549 --- /dev/null +++ b/programs/rocksh/compile_commands.json @@ -0,0 +1,36 @@ +[ + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-I../../rocklibc/include", + "-c", + "-o", + "crt0.o", + "crt0.S" + ], + "directory": "/home/slinky/source/RockOS/programs/rocksh", + "file": "/home/slinky/source/RockOS/programs/rocksh/crt0.S", + "output": "/home/slinky/source/RockOS/programs/rocksh/crt0.o" + }, + { + "arguments": [ + "/home/slinky/opt/cross/bin/i686-elf-gcc", + "-ffreestanding", + "-O2", + "-Wall", + "-Wextra", + "-I../../rocklibc/include", + "-c", + "-o", + "main.o", + "main.c" + ], + "directory": "/home/slinky/source/RockOS/programs/rocksh", + "file": "/home/slinky/source/RockOS/programs/rocksh/main.c", + "output": "/home/slinky/source/RockOS/programs/rocksh/main.o" + } +] diff --git a/programs/crt0.S b/programs/rocksh/crt0.S similarity index 71% rename from programs/crt0.S rename to programs/rocksh/crt0.S index de913e1..d97f158 100644 --- a/programs/crt0.S +++ b/programs/rocksh/crt0.S @@ -1,14 +1,14 @@ .global _start - +.extern exit .section .text _start: xor %ebp, %ebp - push %ebp - mov %esp, %ebp mov (%esp), %eax lea 4(%esp), %ebx - lea 8(%esp, %eax, 4), %ecx + lea 8(%esp,%eax,4), %ecx + + and $-16, %esp push %ecx push %ebx @@ -17,6 +17,5 @@ _start: call main push %eax -1: jmp 1b call exit diff --git a/programs/linker.ld b/programs/rocksh/linker.ld similarity index 100% rename from programs/linker.ld rename to programs/rocksh/linker.ld diff --git a/programs/rocksh/main.c b/programs/rocksh/main.c new file mode 100644 index 0000000..5a2511e --- /dev/null +++ b/programs/rocksh/main.c @@ -0,0 +1,46 @@ +#include +#include +#include + +const char* shell_prompt = "rocksh> "; + +static void process_cmd(const char* cmd) { + size_t cmd_len = strlen(cmd); + if (cmd_len < 1) { + return; + } + + if (strcmp(cmd, "exit") == 0) { + printf("bye!\n"); + exit(0); + } + + printf("command not recognized: %s\n", cmd); +} + +int main(int argc, char *argv[]) { + (void)argc; + (void)argv; + + char cmd[128]; + size_t p = 0; + + printf("%s", shell_prompt); + + while (1) { + char c = getchar(); + printf("%c", c); + if (c != '\n') { + cmd[p++] = c; + continue; + } + + cmd[p] = 0; + process_cmd(cmd); + memset(cmd, 0, 128); + p = 0; + printf("%s", shell_prompt); + } + + return 0; +} \ No newline at end of file diff --git a/programs/rocksh/makefile b/programs/rocksh/makefile new file mode 100644 index 0000000..31e51e6 --- /dev/null +++ b/programs/rocksh/makefile @@ -0,0 +1,23 @@ +CC = i686-elf-gcc +LD = i686-elf-ld + +CFLAGS = -ffreestanding -O2 -Wall -Wextra -I../../rocklibc/include +LDFLAGS = -m elf_i386 -nostdlib + +TARGET = rocksh.elf + +all: $(TARGET) + +crt0.o: crt0.S + $(CC) $(CFLAGS) -c crt0.S -o crt0.o + +main.o: main.c + $(CC) $(CFLAGS) -c main.c -o main.o + +$(TARGET): crt0.o main.o ../lib/rlibc.a + $(LD) $(LDFLAGS) -T linker.ld crt0.o main.o ../lib/rlibc.a -o $(TARGET) + +clean: + rm -f *.o $(TARGET) + +.PHONY: all clean test \ No newline at end of file diff --git a/rocklibc/compile_commands.json b/rocklibc/compile_commands.json index 45110fc..471f792 100644 --- a/rocklibc/compile_commands.json +++ b/rocklibc/compile_commands.json @@ -7,18 +7,14 @@ "-Wall", "-Wextra", "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", "-c", "-o", - "src/locale/localeconv.o", - "src/locale/localeconv.c" + "src/string.o", + "src/string.c" ], "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/locale/localeconv.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/locale/localeconv.o" + "file": "/home/slinky/source/RockOS/rocklibc/src/string.c", + "output": "/home/slinky/source/RockOS/rocklibc/src/string.o" }, { "arguments": [ @@ -28,18 +24,14 @@ "-Wall", "-Wextra", "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", "-c", "-o", - "src/locale/setlocale.o", - "src/locale/setlocale.c" + "src/syscall.o", + "src/syscall.c" ], "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/locale/setlocale.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/locale/setlocale.o" + "file": "/home/slinky/source/RockOS/rocklibc/src/syscall.c", + "output": "/home/slinky/source/RockOS/rocklibc/src/syscall.o" }, { "arguments": [ @@ -49,4889 +41,13 @@ "-Wall", "-Wextra", "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", "-c", "-o", - "src/time/gmtime.o", - "src/time/gmtime.c" + "src/stdio.o", + "src/stdio.c" ], "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/gmtime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/gmtime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/strftime.o", - "src/time/strftime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/strftime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/strftime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/ctime.o", - "src/time/ctime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/ctime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/ctime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/mktime.o", - "src/time/mktime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/mktime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/mktime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/clock.o", - "src/time/clock.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/clock.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/clock.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/localtime_s.o", - "src/time/localtime_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/localtime_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/localtime_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/difftime.o", - "src/time/difftime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/difftime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/difftime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/asctime_s.o", - "src/time/asctime_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/asctime_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/asctime_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/asctime.o", - "src/time/asctime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/asctime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/asctime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/localtime.o", - "src/time/localtime.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/localtime.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/localtime.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/timespec_get.o", - "src/time/timespec_get.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/timespec_get.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/timespec_get.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/gmtime_s.o", - "src/time/gmtime_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/gmtime_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/gmtime_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/ctime_s.o", - "src/time/ctime_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/ctime_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/ctime_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/time/time.o", - "src/time/time.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/time/time.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/time/time.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_timesub.o", - "src/_tzcode/_PDCLIB_timesub.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_timesub.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_timesub.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_increment_overflow.o", - "src/_tzcode/_PDCLIB_increment_overflow.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_increment_overflow.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_increment_overflow.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_mktime_tzname.o", - "src/_tzcode/_PDCLIB_mktime_tzname.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_mktime_tzname.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_mktime_tzname.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_gmtsub.o", - "src/_tzcode/_PDCLIB_gmtsub.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_gmtsub.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_gmtsub.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_init_ttinfo.o", - "src/_tzcode/_PDCLIB_init_ttinfo.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_init_ttinfo.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_init_ttinfo.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_tzset_unlocked.o", - "src/_tzcode/_PDCLIB_tzset_unlocked.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzset_unlocked.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzset_unlocked.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_update_tzname_etc.o", - "src/_tzcode/_PDCLIB_update_tzname_etc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_update_tzname_etc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_update_tzname_etc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_localsub.o", - "src/_tzcode/_PDCLIB_localsub.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_localsub.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_localsub.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_tzload.o", - "src/_tzcode/_PDCLIB_tzload.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzload.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzload.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_localtime_tzset.o", - "src/_tzcode/_PDCLIB_localtime_tzset.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_localtime_tzset.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_localtime_tzset.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_tzparse.o", - "src/_tzcode/_PDCLIB_tzparse.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzparse.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_tzparse.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_tzcode/_PDCLIB_gmtcheck.o", - "src/_tzcode/_PDCLIB_gmtcheck.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_gmtcheck.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_tzcode/_PDCLIB_gmtcheck.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_dlmalloc/malloc.o", - "src/_dlmalloc/malloc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_dlmalloc/malloc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_dlmalloc/malloc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/signal/raise.o", - "src/signal/raise.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/signal/raise.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/signal/raise.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/signal/signal.o", - "src/signal/signal.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/signal/signal.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/signal/signal.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/fdim.o", - "src/math/fdim.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/fdim.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/fdim.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/isnan.o", - "src/math/isnan.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/isnan.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/isnan.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/fabs.o", - "src/math/fabs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/fabs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/fabs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/isfinite.o", - "src/math/isfinite.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/isfinite.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/isfinite.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/fmax.o", - "src/math/fmax.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/fmax.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/fmax.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/fpclassify.o", - "src/math/fpclassify.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/fpclassify.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/fpclassify.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/signbit.o", - "src/math/signbit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/signbit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/signbit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/fmin.o", - "src/math/fmin.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/fmin.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/fmin.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/isinf.o", - "src/math/isinf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/isinf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/isinf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/math/isnormal.o", - "src/math/isnormal.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/math/isnormal.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/math/isnormal.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fscanf.o", - "src/stdio/fscanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fscanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fscanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/tmpnam.o", - "src/stdio/tmpnam.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpnam.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpnam.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vfscanf.o", - "src/stdio/vfscanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vfscanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vfscanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/setbuf.o", - "src/stdio/setbuf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/setbuf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/setbuf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fputc.o", - "src/stdio/fputc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fputc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fputc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/freopen.o", - "src/stdio/freopen.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/freopen.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/freopen.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fgetc.o", - "src/stdio/fgetc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgetc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgetc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/getc.o", - "src/stdio/getc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/getc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/getc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vsprintf.o", - "src/stdio/vsprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/puts.o", - "src/stdio/puts.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/puts.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/puts.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/rewind.o", - "src/stdio/rewind.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/rewind.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/rewind.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fclose.o", - "src/stdio/fclose.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fclose.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fclose.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vfprintf.o", - "src/stdio/vfprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vfprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vfprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fsetpos.o", - "src/stdio/fsetpos.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fsetpos.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fsetpos.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/putchar.o", - "src/stdio/putchar.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/putchar.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/putchar.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/printf.o", - "src/stdio/printf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/printf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/printf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fgets.o", - "src/stdio/fgets.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgets.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgets.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/ftell.o", - "src/stdio/ftell.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/ftell.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/ftell.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fopen.o", - "src/stdio/fopen.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fopen.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fopen.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/scanf.o", - "src/stdio/scanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/scanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/scanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fread.o", - "src/stdio/fread.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fread.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fread.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/tmpfile.o", - "src/stdio/tmpfile.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpfile.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpfile.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vscanf.o", - "src/stdio/vscanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vscanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vscanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/freopen_s.o", - "src/stdio/freopen_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/freopen_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/freopen_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/perror.o", - "src/stdio/perror.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/perror.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/perror.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/getchar.o", - "src/stdio/getchar.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/getchar.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/getchar.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fputs.o", - "src/stdio/fputs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fputs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fputs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/remove.o", - "src/stdio/remove.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/remove.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/remove.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fopen_s.o", - "src/stdio/fopen_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fopen_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fopen_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/tmpfile_s.o", - "src/stdio/tmpfile_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpfile_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/tmpfile_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vprintf.o", - "src/stdio/vprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/putc.o", - "src/stdio/putc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/putc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/putc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fgetpos.o", - "src/stdio/fgetpos.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgetpos.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fgetpos.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/feof.o", - "src/stdio/feof.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/feof.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/feof.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/sprintf.o", - "src/stdio/sprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/sprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/sprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fwrite.o", - "src/stdio/fwrite.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fwrite.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fwrite.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/ferror.o", - "src/stdio/ferror.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/ferror.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/ferror.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fflush.o", - "src/stdio/fflush.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fflush.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fflush.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/ungetc.o", - "src/stdio/ungetc.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/ungetc.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/ungetc.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fprintf.o", - "src/stdio/fprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vsscanf.o", - "src/stdio/vsscanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsscanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsscanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/rename.o", - "src/stdio/rename.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/rename.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/rename.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/vsnprintf.o", - "src/stdio/vsnprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsnprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/vsnprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/fseek.o", - "src/stdio/fseek.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/fseek.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/fseek.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/sscanf.o", - "src/stdio/sscanf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/sscanf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/sscanf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/clearerr.o", - "src/stdio/clearerr.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/clearerr.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/clearerr.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/setvbuf.o", - "src/stdio/setvbuf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/setvbuf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/setvbuf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdio/snprintf.o", - "src/stdio/snprintf.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdio/snprintf.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdio/snprintf.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/system.o", - "src/stdlib/system.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/system.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/system.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/labs.o", - "src/stdlib/labs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/labs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/labs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/div.o", - "src/stdlib/div.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/div.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/div.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/srand.o", - "src/stdlib/srand.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/srand.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/srand.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/qsort_s.o", - "src/stdlib/qsort_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/qsort_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/qsort_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/getenv.o", - "src/stdlib/getenv.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/getenv.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/getenv.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/quick_exit.o", - "src/stdlib/quick_exit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/quick_exit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/quick_exit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/rand.o", - "src/stdlib/rand.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/rand.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/rand.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtof.o", - "src/stdlib/strtof.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtof.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtof.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/getenv_s.o", - "src/stdlib/getenv_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/getenv_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/getenv_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/at_quick_exit.o", - "src/stdlib/at_quick_exit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/at_quick_exit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/at_quick_exit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/atoi.o", - "src/stdlib/atoi.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atoi.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atoi.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtoull.o", - "src/stdlib/strtoull.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoull.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoull.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/abort_handler_s.o", - "src/stdlib/abort_handler_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abort_handler_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abort_handler_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/bsearch.o", - "src/stdlib/bsearch.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/bsearch.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/bsearch.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/atoll.o", - "src/stdlib/atoll.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atoll.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atoll.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/set_constraint_handler_s.o", - "src/stdlib/set_constraint_handler_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/set_constraint_handler_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/set_constraint_handler_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/bsearch_s.o", - "src/stdlib/bsearch_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/bsearch_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/bsearch_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtoul.o", - "src/stdlib/strtoul.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoul.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoul.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtold.o", - "src/stdlib/strtold.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtold.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtold.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/abs.o", - "src/stdlib/abs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/abort.o", - "src/stdlib/abort.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abort.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/abort.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/lldiv.o", - "src/stdlib/lldiv.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/lldiv.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/lldiv.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/atexit.o", - "src/stdlib/atexit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atexit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atexit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/_Exit.o", - "src/stdlib/_Exit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/_Exit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/_Exit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtod.o", - "src/stdlib/strtod.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtod.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtod.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/exit.o", - "src/stdlib/exit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/exit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/exit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/llabs.o", - "src/stdlib/llabs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/llabs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/llabs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/qsort.o", - "src/stdlib/qsort.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/qsort.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/qsort.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/ldiv.o", - "src/stdlib/ldiv.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/ldiv.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/ldiv.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/ignore_handler_s.o", - "src/stdlib/ignore_handler_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/ignore_handler_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/ignore_handler_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/atol.o", - "src/stdlib/atol.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atol.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/atol.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtol.o", - "src/stdlib/strtol.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtol.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtol.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/stdlib/strtoll.o", - "src/stdlib/strtoll.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoll.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/stdlib/strtoll.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isxdigit.o", - "src/ctype/isxdigit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isxdigit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isxdigit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isprint.o", - "src/ctype/isprint.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isprint.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isprint.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isspace.o", - "src/ctype/isspace.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isspace.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isspace.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isblank.o", - "src/ctype/isblank.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isblank.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isblank.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/toupper.o", - "src/ctype/toupper.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/toupper.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/toupper.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/tolower.o", - "src/ctype/tolower.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/tolower.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/tolower.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/iscntrl.o", - "src/ctype/iscntrl.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/iscntrl.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/iscntrl.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isalpha.o", - "src/ctype/isalpha.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isalpha.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isalpha.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/ispunct.o", - "src/ctype/ispunct.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/ispunct.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/ispunct.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isgraph.o", - "src/ctype/isgraph.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isgraph.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isgraph.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/islower.o", - "src/ctype/islower.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/islower.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/islower.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isalnum.o", - "src/ctype/isalnum.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isalnum.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isalnum.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isupper.o", - "src/ctype/isupper.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isupper.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isupper.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/ctype/isdigit.o", - "src/ctype/isdigit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/ctype/isdigit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/ctype/isdigit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/inttypes/strtoimax.o", - "src/inttypes/strtoimax.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/inttypes/strtoimax.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/inttypes/strtoimax.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/inttypes/strtoumax.o", - "src/inttypes/strtoumax.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/inttypes/strtoumax.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/inttypes/strtoumax.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/inttypes/imaxabs.o", - "src/inttypes/imaxabs.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/inttypes/imaxabs.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/inttypes/imaxabs.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/inttypes/imaxdiv.o", - "src/inttypes/imaxdiv.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/inttypes/imaxdiv.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/inttypes/imaxdiv.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strncmp.o", - "src/string/strncmp.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strncmp.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strncmp.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memcpy.o", - "src/string/memcpy.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memcpy.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memcpy.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memcmp.o", - "src/string/memcmp.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memcmp.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memcmp.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memset.o", - "src/string/memset.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memset.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memset.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strxfrm.o", - "src/string/strxfrm.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strxfrm.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strxfrm.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strchr.o", - "src/string/strchr.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strchr.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strchr.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcat.o", - "src/string/strcat.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcat.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcat.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strerror.o", - "src/string/strerror.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strerror.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strerror.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memmove.o", - "src/string/memmove.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memmove.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memmove.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strpbrk.o", - "src/string/strpbrk.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strpbrk.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strpbrk.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strerrorlen_s.o", - "src/string/strerrorlen_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strerrorlen_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strerrorlen_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memset_s.o", - "src/string/memset_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memset_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memset_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strncat_s.o", - "src/string/strncat_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strncat_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strncat_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strerror_s.o", - "src/string/strerror_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strerror_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strerror_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memcpy_s.o", - "src/string/memcpy_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memcpy_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memcpy_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strncpy_s.o", - "src/string/strncpy_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strncpy_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strncpy_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcspn.o", - "src/string/strcspn.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcspn.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcspn.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strncpy.o", - "src/string/strncpy.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strncpy.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strncpy.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strstr.o", - "src/string/strstr.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strstr.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strstr.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memmove_s.o", - "src/string/memmove_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memmove_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memmove_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strtok.o", - "src/string/strtok.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strtok.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strtok.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strtok_s.o", - "src/string/strtok_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strtok_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strtok_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strrchr.o", - "src/string/strrchr.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strrchr.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strrchr.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcpy.o", - "src/string/strcpy.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcpy.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcpy.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcpy_s.o", - "src/string/strcpy_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcpy_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcpy_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcmp.o", - "src/string/strcmp.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcmp.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcmp.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcoll.o", - "src/string/strcoll.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcoll.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcoll.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strcat_s.o", - "src/string/strcat_s.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strcat_s.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strcat_s.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/memchr.o", - "src/string/memchr.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/memchr.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/memchr.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strlen.o", - "src/string/strlen.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strlen.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strlen.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strspn.o", - "src/string/strspn.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strspn.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strspn.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/string/strncat.o", - "src/string/strncat.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/string/strncat.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/string/strncat.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print_fp.o", - "src/_PDCLIB/_PDCLIB_print_fp.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_remove.o", - "src/_PDCLIB/_PDCLIB_remove.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_remove.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_remove.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_mul.o", - "src/_PDCLIB/_PDCLIB_bigint_mul.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_closeall.o", - "src/_PDCLIB/_PDCLIB_closeall.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_closeall.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_closeall.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_mul_pow10.o", - "src/_PDCLIB/_PDCLIB_bigint_mul_pow10.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul_pow10.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul_pow10.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_stdinit.o", - "src/_PDCLIB/_PDCLIB_stdinit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_stdinit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_stdinit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_from_pow2.o", - "src/_PDCLIB/_PDCLIB_bigint_from_pow2.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow2.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow2.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_strtox_prelim.o", - "src/_PDCLIB/_PDCLIB_strtox_prelim.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtox_prelim.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtox_prelim.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_from_bigint.o", - "src/_PDCLIB/_PDCLIB_bigint_from_bigint.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_bigint.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_bigint.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_cmp.o", - "src/_PDCLIB/_PDCLIB_bigint_cmp.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_cmp.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_cmp.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_close.o", - "src/_PDCLIB/_PDCLIB_close.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_close.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_close.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_prepwrite.o", - "src/_PDCLIB/_PDCLIB_prepwrite.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_prepwrite.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_prepwrite.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_from_digit.o", - "src/_PDCLIB/_PDCLIB_bigint_from_digit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_digit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_digit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print.o", - "src/_PDCLIB/_PDCLIB_print.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_atomax.o", - "src/_PDCLIB/_PDCLIB_atomax.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_atomax.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_atomax.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print_string.o", - "src/_PDCLIB/_PDCLIB_print_string.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_string.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_string.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_strtok.o", - "src/_PDCLIB/_PDCLIB_strtok.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtok.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtok.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_digit_log2.o", - "src/_PDCLIB/_PDCLIB_bigint_digit_log2.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_digit_log2.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_digit_log2.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_ctype.o", - "src/_PDCLIB/_PDCLIB_load_lc_ctype.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_ctype.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_ctype.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_digits.o", - "src/_PDCLIB/_PDCLIB_digits.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_digits.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_digits.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_naive_ptod.o", - "src/_PDCLIB/_PDCLIB_naive_ptod.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_naive_ptod.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_naive_ptod.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_fp_from_dbl.o", - "src/_PDCLIB/_PDCLIB_fp_from_dbl.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_dbl.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_dbl.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_realpath.o", - "src/_PDCLIB/_PDCLIB_realpath.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_realpath.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_realpath.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print_integer.o", - "src/_PDCLIB/_PDCLIB_print_integer.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_integer.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_integer.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_rename.o", - "src/_PDCLIB/_PDCLIB_rename.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_rename.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_rename.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_fillbuffer.o", - "src/_PDCLIB/_PDCLIB_fillbuffer.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fillbuffer.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fillbuffer.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_add.o", - "src/_PDCLIB/_PDCLIB_bigint_add.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_add.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_add.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_numeric.o", - "src/_PDCLIB/_PDCLIB_load_lc_numeric.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_numeric.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_numeric.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_from_pow10.o", - "src/_PDCLIB/_PDCLIB_bigint_from_pow10.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow10.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow10.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_Exit.o", - "src/_PDCLIB/_PDCLIB_Exit.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_Exit.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_Exit.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_changemode.o", - "src/_PDCLIB/_PDCLIB_changemode.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_changemode.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_changemode.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lines.o", - "src/_PDCLIB/_PDCLIB_load_lines.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lines.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lines.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_strtod_prelim.o", - "src/_PDCLIB/_PDCLIB_strtod_prelim.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtod_prelim.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtod_prelim.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_filemode.o", - "src/_PDCLIB/_PDCLIB_filemode.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_filemode.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_filemode.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_collate.o", - "src/_PDCLIB/_PDCLIB_load_lc_collate.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_collate.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_collate.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_log2.o", - "src/_PDCLIB/_PDCLIB_bigint_log2.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_log2.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_log2.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/errno.o", - "src/_PDCLIB/errno.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/errno.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/errno.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_scan.o", - "src/_PDCLIB/_PDCLIB_scan.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_scan.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_scan.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_strtox_main.o", - "src/_PDCLIB/_PDCLIB_strtox_main.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtox_main.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_strtox_main.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print_fp_hexa.o", - "src/_PDCLIB/_PDCLIB_print_fp_hexa.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_hexa.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_hexa.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_seek.o", - "src/_PDCLIB/_PDCLIB_seek.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_seek.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_seek.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/assert.o", - "src/_PDCLIB/assert.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/assert.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/assert.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_shl.o", - "src/_PDCLIB/_PDCLIB_bigint_shl.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_shl.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_shl.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_mul10.o", - "src/_PDCLIB/_PDCLIB_bigint_mul10.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul10.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul10.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_bigint_div.o", - "src/_PDCLIB/_PDCLIB_bigint_div.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_div.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_bigint_div.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_flushbuffer.o", - "src/_PDCLIB/_PDCLIB_flushbuffer.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_flushbuffer.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_flushbuffer.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_monetary.o", - "src/_PDCLIB/_PDCLIB_load_lc_monetary.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_monetary.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_monetary.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_print_fp_deci.o", - "src/_PDCLIB/_PDCLIB_print_fp_deci.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_deci.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_deci.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_fp_from_ldbl.o", - "src/_PDCLIB/_PDCLIB_fp_from_ldbl.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_ldbl.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_ldbl.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_prepread.o", - "src/_PDCLIB/_PDCLIB_prepread.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_prepread.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_prepread.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_messages.o", - "src/_PDCLIB/_PDCLIB_load_lc_messages.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_messages.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_messages.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_naive_etod.o", - "src/_PDCLIB/_PDCLIB_naive_etod.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_naive_etod.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_naive_etod.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_getstream.o", - "src/_PDCLIB/_PDCLIB_getstream.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_getstream.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_getstream.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_is_leap.o", - "src/_PDCLIB/_PDCLIB_is_leap.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_is_leap.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_is_leap.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/stdarg.o", - "src/_PDCLIB/stdarg.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/stdarg.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/stdarg.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_seed.o", - "src/_PDCLIB/_PDCLIB_seed.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_seed.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_seed.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_load_lc_time.o", - "src/_PDCLIB/_PDCLIB_load_lc_time.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_time.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_time.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_isstream.o", - "src/_PDCLIB/_PDCLIB_isstream.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_isstream.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_isstream.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/_PDCLIB/_PDCLIB_init_file_t.o", - "src/_PDCLIB/_PDCLIB_init_file_t.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_init_file_t.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/_PDCLIB/_PDCLIB_init_file_t.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/rockos/syscall.o", - "src/rockos/syscall.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/rockos/syscall.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/rockos/syscall.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/rockos/times.o", - "src/rockos/times.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/rockos/times.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/rockos/times.o" - }, - { - "arguments": [ - "/home/slinky/opt/cross/bin/i686-elf-gcc", - "-ffreestanding", - "-O2", - "-Wall", - "-Wextra", - "-Iinclude", - "-DHAVE_MMAP=0", - "-DLACKS_SYS_MMAN_H=1", - "-DUSE_LOCKS=0", - "-DLACKS_SYS_PARAM_H=1", - "-c", - "-o", - "src/rockos/time.o", - "src/rockos/time.c" - ], - "directory": "/home/slinky/source/RockOS/rocklibc", - "file": "/home/slinky/source/RockOS/rocklibc/src/rockos/time.c", - "output": "/home/slinky/source/RockOS/rocklibc/src/rockos/time.o" + "file": "/home/slinky/source/RockOS/rocklibc/src/stdio.c", + "output": "/home/slinky/source/RockOS/rocklibc/src/stdio.o" } ] diff --git a/rocklibc/include/assert.h b/rocklibc/include/assert.h deleted file mode 100644 index 34bea52..0000000 --- a/rocklibc/include/assert.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Diagnostics - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_ASSERT_H -#define _PDCLIB_ASSERT_H _PDCLIB_ASSERT_H -_PDCLIB_PUBLIC void _PDCLIB_assert99( const char * const, const char * const, const char * const ); -_PDCLIB_PUBLIC void _PDCLIB_assert89( const char * const ); -#endif - -/* If NDEBUG is set, assert() is a null operation. */ -#undef assert - -#ifdef NDEBUG -#define assert( ignore ) ( (void) 0 ) -#else -#if __STDC_VERSION__ >= 199901L -#define assert( expression ) ( ( expression ) ? (void) 0 \ - : _PDCLIB_assert99( "Assertion failed: " #expression \ - ", function ", __func__, \ - ", file " __FILE__ \ - ", line " _PDCLIB_value2string( __LINE__ ) \ - ".\n" ) ) -#else -#define assert( expression ) ( ( expression ) ? (void) 0 \ - : _PDCLIB_assert89( "Assertion failed: " #expression \ - ", file " __FILE__ \ - ", line " _PDCLIB_value2string( __LINE__ ) \ - ".\n" ) ) -#endif -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_ASSERT_H -#include _PDCLIB_EXTEND_ASSERT_H -#endif - -#ifdef __cplusplus -} -#endif diff --git a/rocklibc/include/ctype.h b/rocklibc/include/ctype.h deleted file mode 100644 index 551667a..0000000 --- a/rocklibc/include/ctype.h +++ /dev/null @@ -1,110 +0,0 @@ -/* Character handling - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_CTYPE_H -#define _PDCLIB_CTYPE_H _PDCLIB_CTYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -/* Character classification functions */ - -/* Note that there is a difference between "whitespace" (any printing, non- - graph character, like horizontal and vertical tab), and "blank" (the literal - ' ' space character). - - There will be masking macros for each of these later on, but right now I - focus on the functions only. -*/ - -/* Returns isalpha( c ) || isdigit( c ) */ -_PDCLIB_PUBLIC int isalnum( int c ); - -/* Returns isupper( c ) || islower( c ) in the "C" locale. - In any other locale, also returns true for a locale-specific set of - alphabetic characters which are neither control characters, digits, - punctation, or whitespace. -*/ -_PDCLIB_PUBLIC int isalpha( int c ); - -/* Returns true if the character isspace() and used for separating words within - a line of text. In the "C" locale, only ' ' and '\t' are considered blanks. -*/ -_PDCLIB_PUBLIC int isblank( int c ); - -/* Returns true if the character is a control character. */ -_PDCLIB_PUBLIC int iscntrl( int c ); - -/* Returns true if the character is a decimal digit. Locale-independent. */ -_PDCLIB_PUBLIC int isdigit( int c ); - -/* Returns true for every printing character except space (' '). - NOTE: This definition differs from that of iswgraph() in , - which considers any iswspace() character, not only ' '. -*/ -_PDCLIB_PUBLIC int isgraph( int c ); - -/* Returns true for lowercase letters in the "C" locale. - In any other locale, also returns true for a locale-specific set of - characters which are neither control characters, digits, punctation, or - space (' '). In a locale other than the "C" locale, a character might test - true for both islower() and isupper(). -*/ -_PDCLIB_PUBLIC int islower( int c ); - -/* Returns true for every printing character including space (' '). */ -_PDCLIB_PUBLIC int isprint( int c ); - -/* Returns true for a locale-specific set of punctuation charcters; these - may not be whitespace or alphanumeric. In the "C" locale, returns true - for every printing character that is not whitespace or alphanumeric. -*/ -_PDCLIB_PUBLIC int ispunct( int c ); - -/* Returns true for every standard whitespace character (' ', '\f', '\n', '\r', - '\t', '\v') in the "C" locale. In any other locale, also returns true for a - locale-specific set of characters for which isalnum() is false. -*/ -_PDCLIB_PUBLIC int isspace( int c ); - -/* Returns true for uppercase letters in the "C" locale. - In any other locale, also returns true for a locale-specific set of - characters which are neither control characters, digits, punctation, or - space (' '). In a locale other than the "C" locale, a character might test - true for both islower() and isupper(). -*/ -_PDCLIB_PUBLIC int isupper( int c ); - -/* Returns true for any hexadecimal-digit character. Locale-independent. */ -_PDCLIB_PUBLIC int isxdigit( int c ); - -/* Character case mapping functions */ - -/* Converts an uppercase letter to a corresponding lowercase letter. Input that - is not an uppercase letter remains unchanged. -*/ -_PDCLIB_PUBLIC int tolower( int c ); - -/* Converts a lowercase letter to a corresponding uppercase letter. Input that - is not a lowercase letter remains unchanged. -*/ -_PDCLIB_PUBLIC int toupper( int c ); - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_CTYPE_H -#include _PDCLIB_EXTEND_CTYPE_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/errno.h b/rocklibc/include/errno.h deleted file mode 100644 index 28eaf5b..0000000 --- a/rocklibc/include/errno.h +++ /dev/null @@ -1,202 +0,0 @@ -/* Errors - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_ERRNO_H -#define _PDCLIB_ERRNO_H _PDCLIB_ERRNO_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -/* FIXME: With , this needs to be in thread-specific storage. */ -#define errno (*_PDCLIB_errno_func()) - -/* C only requires the following three */ - -/* Result too large */ -#define ERANGE _PDCLIB_ERANGE -/* Mathematics argument out of domain of function */ -#define EDOM _PDCLIB_EDOM -/* Illegal byte sequence */ -#define EILSEQ _PDCLIB_EILSEQ - -/* C++ additionally requires the folloing */ - -/* Argument list too long */ -#define E2BIG _PDCLIB_E2BIG -/* Permission denied */ -#define EACCES _PDCLIB_EACCES -/* Address in use */ -#define EADDRINUSE _PDCLIB_EADDRINUSE -/* Address not available */ -#define EADDRNOTAVAIL _PDCLIB_EADDRNOTAVAIL -/* Address family not supported */ -#define EAFNOSUPPORT _PDCLIB_EAFNOSUPPORT -/* Resource unavailable, try again */ -#define EAGAIN _PDCLIB_EAGAIN -/* Connection already in progress */ -#define EALREADY _PDCLIB_EALREADY -/* Bad file descriptor */ -#define EBADF _PDCLIB_EBADF -/* Bad message */ -#define EBADMSG _PDCLIB_EBADMSG -/* Device or resource busy */ -#define EBUSY _PDCLIB_EBUSY -/* Operation canceled */ -#define ECANCELED _PDCLIB_ECANCELED -/* No child processes */ -#define ECHILD _PDCLIB_ECHILD -/* Connection aborted */ -#define ECONNABORTED _PDCLIB_ECONNABORTED -/* Connection refused */ -#define ECONNREFUSED _PDCLIB_ECONNREFUSED -/* Connection reset */ -#define ECONNRESET _PDCLIB_ECONNRESET -/* Resource deadlock would occur */ -#define EDEADLK _PDCLIB_EDEADLK -/* Destination address required */ -#define EDESTADDRREQ _PDCLIB_EDESTADDRREQ -/* File exists */ -#define EEXIST _PDCLIB_EEXIST -/* Bad address */ -#define EFAULT _PDCLIB_EFAULT -/* File too large */ -#define EFBIG _PDCLIB_EFBIG -/* Host is unreachable */ -#define EHOSTUNREACH _PDCLIB_EHOSTUNREACH -/* Identifier removed */ -#define EIDRM _PDCLIB_EIDRM -/* Operation in progress */ -#define EINPROGRESS _PDCLIB_EINPROGRESS -/* Interrupted function */ -#define EINTR _PDCLIB_EINTR -/* Invalid argument */ -#define EINVAL _PDCLIB_EINVAL -/* I/O error */ -#define EIO _PDCLIB_EIO -/* Socket is connected */ -#define EISCONN _PDCLIB_EISCONN -/* Is a directory */ -#define EISDIR _PDCLIB_EISDIR -/* Too many levels of symbolic links */ -#define ELOOP _PDCLIB_ELOOP -/* File descriptor value too large */ -#define EMFILE _PDCLIB_EMFILE -/* Too many links */ -#define EMLINK _PDCLIB_EMLINK -/* Message too large */ -#define EMSGSIZE _PDCLIB_EMSGSIZE -/* Filename too long */ -#define ENAMETOOLONG _PDCLIB_ENAMETOOLONG -/* Network is down */ -#define ENETDOWN _PDCLIB_ENETDOWN -/* Connection aborted by network */ -#define ENETRESET _PDCLIB_ENETRESET -/* Network unreachable */ -#define ENETUNREACH _PDCLIB_ENETUNREACH -/* Too many files open in system */ -#define ENFILE _PDCLIB_ENFILE -/* No buffer space available */ -#define ENOBUFS _PDCLIB_ENOBUFS -/* No message is available on the STREAM head read queue */ -#define ENODATA _PDCLIB_ENODATA -/* No such device */ -#define ENODEV _PDCLIB_ENODEV -/* No such file or directory */ -#define ENOENT _PDCLIB_ENOENT -/* Executable file format error */ -#define ENOEXEC _PDCLIB_ENOEXEC -/* No locks available */ -#define ENOLCK _PDCLIB_ENOLCK -/* Link has been severed */ -#define ENOLINK _PDCLIB_ENOLINK -/* Not enough space */ -#define ENOMEM _PDCLIB_ENOMEM -/* No message of the desired type */ -#define ENOMSG _PDCLIB_ENOMSG -/* Protocol not available */ -#define ENOPROTOOPT _PDCLIB_ENOPROTOOPT -/* No space left on device */ -#define ENOSPC _PDCLIB_ENOSPC -/* No STREAM resources */ -#define ENOSR _PDCLIB_ENOSR -/* Not a STREAM */ -#define ENOSTR _PDCLIB_ENOSTR -/* Function not supported */ -#define ENOSYS _PDCLIB_ENOSYS -/* The socket is not connected */ -#define ENOTCONN _PDCLIB_ENOTCONN -/* Not a directory */ -#define ENOTDIR _PDCLIB_ENOTDIR -/* Directory not empty */ -#define ENOTEMPTY _PDCLIB_ENOTEMPTY -/* State not recoverable */ -#define ENOTRECOVERABLE _PDCLIB_ENOTRECOVERABLE -/* Not a socket */ -#define ENOTSOCK _PDCLIB_ENOTSOCK -/* Not supported */ -#define ENOTSUP _PDCLIB_ENOTSUP -/* Inappropriate I/O control operation */ -#define ENOTTY _PDCLIB_ENOTTY -/* No such device or address */ -#define ENXIO _PDCLIB_ENXIO -/* Operation not supported on socket */ -#define EOPNOTSUPP _PDCLIB_EOPNOTSUPP -/* Value too large to be stored in data type */ -#define EOVERFLOW _PDCLIB_EOVERFLOW -/* Previous owner died */ -#define EOWNERDEAD _PDCLIB_EOWNERDEAD -/* Operation not permitted */ -#define EPERM _PDCLIB_EPERM -/* Broken pipe */ -#define EPIPE _PDCLIB_EPIPE -/* Protocol error */ -#define EPROTO _PDCLIB_EPROTO -/* Protocol not supported */ -#define EPROTONOSUPPORT _PDCLIB_EPROTONOSUPPORT -/* Protocol wrong type for socket */ -#define EPROTOTYPE _PDCLIB_EPROTOTYPE -/* Read-only file system */ -#define EROFS _PDCLIB_EROFS -/* Invalid seek */ -#define ESPIPE _PDCLIB_ESPIPE -/* No such process */ -#define ESRCH _PDCLIB_ESRCH -/* Stream ioctl() timeout */ -#define ETIME _PDCLIB_ETIME -/* Connection timed out */ -#define ETIMEDOUT _PDCLIB_ETIMEDOUT -/* Text file busy */ -#define ETXTBSY _PDCLIB_ETXTBSY -/* Operation would block */ -#define EWOULDBLOCK _PDCLIB_EWOULDBLOCK -/* Cross-device link */ -#define EXDEV _PDCLIB_EXDEV - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 -#ifndef _PDCLIB_ERRNO_T_DEFINED -#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED -typedef int errno_t; -#endif -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_ERRNO_H -#include _PDCLIB_EXTEND_ERRNO_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/fcntl.h b/rocklibc/include/fcntl.h deleted file mode 100644 index 99d530f..0000000 --- a/rocklibc/include/fcntl.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _FCNTL_H -#define _FCNTL_H - -/* File access modes for open() */ -#define O_RDONLY 00000000 -#define O_WRONLY 00000001 -#define O_RDWR 00000002 - -/* File creation flags */ -#define O_CREAT 00000100 -#define O_EXCL 00000200 -#define O_NOCTTY 00000400 -#define O_TRUNC 00001000 -#define O_APPEND 00002000 -#define O_NONBLOCK 00004000 - -#define AT_FDCWD (-100) - -#endif /* _FCNTL_H */ \ No newline at end of file diff --git a/rocklibc/include/float.h b/rocklibc/include/float.h deleted file mode 100644 index 49d5d2e..0000000 --- a/rocklibc/include/float.h +++ /dev/null @@ -1,82 +0,0 @@ -/* Characteristics of floating types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_FLOAT_H -#define _PDCLIB_FLOAT_H _PDCLIB_FLOAT_H - -#include "pdclib/_PDCLIB_config.h" - -#define FLT_ROUNDS _PDCLIB_FLT_ROUNDS -#define FLT_EVAL_METHOD _PDCLIB_FLT_EVAL_METHOD -#define DECIMAL_DIG _PDCLIB_DECIMAL_DIG - -/* Radix of exponent representation */ -#define FLT_RADIX __FLT_RADIX__ -/* Number of base-FLT_RADIX digits in the significand of a float */ -#define FLT_MANT_DIG __FLT_MANT_DIG__ -/* Number of decimal digits of precision in a float */ -#define FLT_DIG __FLT_DIG__ -/* Difference between 1.0 and the minimum float greater than 1.0 */ -#define FLT_EPSILON __FLT_EPSILON__ -/* Minimum int x such that FLT_RADIX**(x-1) is a normalised float */ -#define FLT_MIN_EXP __FLT_MIN_EXP__ -/* Minimum normalised float */ -#define FLT_MIN __FLT_MIN__ -/* Minimum int x such that 10**x is a normalised float */ -#define FLT_MIN_10_EXP __FLT_MIN_10_EXP__ -/* Maximum int x such that FLT_RADIX**(x-1) is a representable float */ -#define FLT_MAX_EXP __FLT_MAX_EXP__ -/* Maximum float */ -#define FLT_MAX __FLT_MAX__ -/* Maximum int x such that 10**x is a representable float */ -#define FLT_MAX_10_EXP __FLT_MAX_10_EXP__ - -/* Number of base-FLT_RADIX digits in the significand of a double */ -#define DBL_MANT_DIG __DBL_MANT_DIG__ -/* Number of decimal digits of precision in a double */ -#define DBL_DIG __DBL_DIG__ -/* Difference between 1.0 and the minimum double greater than 1.0 */ -#define DBL_EPSILON __DBL_EPSILON__ -/* Minimum int x such that FLT_RADIX**(x-1) is a normalised double */ -#define DBL_MIN_EXP __DBL_MIN_EXP__ -/* Minimum normalised double */ -#define DBL_MIN __DBL_MIN__ -/* Minimum int x such that 10**x is a normalised double */ -#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__ -/* Maximum int x such that FLT_RADIX**(x-1) is a representable double */ -#define DBL_MAX_EXP __DBL_MAX_EXP__ -/* Maximum double */ -#define DBL_MAX __DBL_MAX__ -/* Maximum int x such that 10**x is a representable double */ -#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__ - -/* Number of base-FLT_RADIX digits in the significand of a long double */ -#define LDBL_MANT_DIG __LDBL_MANT_DIG__ -/* Number of decimal digits of precision in a long double */ -#define LDBL_DIG __LDBL_DIG__ -/* Difference between 1.0 and the minimum long double greater than 1.0 */ -#define LDBL_EPSILON __LDBL_EPSILON__ -/* Minimum int x such that FLT_RADIX**(x-1) is a normalised long double */ -#define LDBL_MIN_EXP __LDBL_MIN_EXP__ -/* Minimum normalised long double */ -#define LDBL_MIN __LDBL_MIN__ -/* Minimum int x such that 10**x is a normalised long double */ -#define LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ -/* Maximum int x such that FLT_RADIX**(x-1) is a representable long double */ -#define LDBL_MAX_EXP __LDBL_MAX_EXP__ -/* Maximum long double */ -#define LDBL_MAX __LDBL_MAX__ -/* Maximum int x such that 10**x is a representable long double */ -#define LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_FLOAT_H -#include _PDCLIB_EXTEND_FLOAT_H -#endif - -#endif diff --git a/rocklibc/include/inttypes.h b/rocklibc/include/inttypes.h deleted file mode 100644 index 0be401d..0000000 --- a/rocklibc/include/inttypes.h +++ /dev/null @@ -1,368 +0,0 @@ -/* Format conversion of integer types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_INTTYPES_H -#define _PDCLIB_INTTYPES_H _PDCLIB_INTTYPES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -typedef struct _PDCLIB_imaxdiv_t imaxdiv_t; - -/* 7.8.1 Macros for format specifiers */ - -/* The various leastN_t, fastN_t, intmax_t, and intptr_t types are typedefs - to native types. But the user does not know which ones, which gives some - problems when trying to *printf() / *scanf() those types. The various - macros defined below allow to give the correct conversion specifiers - without knowing the actual native type they represent. -*/ - -#if _PDCLIB_INT_LEAST8_MAX > _PDCLIB_INT_MAX -#define PRIdLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, d ) ) -#define PRIiLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, i ) ) -#define PRIoLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, o ) ) -#define PRIuLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, u ) ) -#define PRIxLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, x ) ) -#define PRIXLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, X ) ) -#else -#define PRIdLEAST8 "d" -#define PRIiLEAST8 "i" -#define PRIoLEAST8 "o" -#define PRIuLEAST8 "u" -#define PRIxLEAST8 "x" -#define PRIXLEAST8 "X" -#endif - -#if _PDCLIB_INT_FAST8_MAX > _PDCLIB_INT_MAX -#define PRIdFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, d ) ) -#define PRIiFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, i ) ) -#define PRIoFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, o ) ) -#define PRIuFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, u ) ) -#define PRIxFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, x ) ) -#define PRIXFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, X ) ) -#else -#define PRIdFAST8 "d" -#define PRIiFAST8 "i" -#define PRIoFAST8 "o" -#define PRIuFAST8 "u" -#define PRIxFAST8 "x" -#define PRIXFAST8 "X" -#endif - -#if _PDCLIB_INT_LEAST16_MAX > _PDCLIB_INT_MAX -#define PRIdLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, d ) ) -#define PRIiLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, i ) ) -#define PRIoLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, o ) ) -#define PRIuLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, u ) ) -#define PRIxLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, x ) ) -#define PRIXLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, X ) ) -#else -#define PRIdLEAST16 "d" -#define PRIiLEAST16 "i" -#define PRIoLEAST16 "o" -#define PRIuLEAST16 "u" -#define PRIxLEAST16 "x" -#define PRIXLEAST16 "X" -#endif - -#if _PDCLIB_INT_FAST16_MAX > _PDCLIB_INT_MAX -#define PRIdFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, d ) ) -#define PRIiFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, i ) ) -#define PRIoFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, o ) ) -#define PRIuFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, u ) ) -#define PRIxFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, x ) ) -#define PRIXFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, X ) ) -#else -#define PRIdFAST16 "d" -#define PRIiFAST16 "i" -#define PRIoFAST16 "o" -#define PRIuFAST16 "u" -#define PRIxFAST16 "x" -#define PRIXFAST16 "X" -#endif - -#if _PDCLIB_INT_LEAST32_MAX > _PDCLIB_INT_MAX -#define PRIdLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, d ) ) -#define PRIiLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, i ) ) -#define PRIoLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, o ) ) -#define PRIuLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, u ) ) -#define PRIxLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, x ) ) -#define PRIXLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, X ) ) -#else -#define PRIdLEAST32 "d" -#define PRIiLEAST32 "i" -#define PRIoLEAST32 "o" -#define PRIuLEAST32 "u" -#define PRIxLEAST32 "x" -#define PRIXLEAST32 "X" -#endif - -#if _PDCLIB_INT_FAST32_MAX > _PDCLIB_INT_MAX -#define PRIdFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, d ) ) -#define PRIiFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, i ) ) -#define PRIoFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, o ) ) -#define PRIuFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, u ) ) -#define PRIxFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, x ) ) -#define PRIXFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, X ) ) -#else -#define PRIdFAST32 "d" -#define PRIiFAST32 "i" -#define PRIoFAST32 "o" -#define PRIuFAST32 "u" -#define PRIxFAST32 "x" -#define PRIXFAST32 "X" -#endif - -#if _PDCLIB_INT_LEAST64_MAX > _PDCLIB_INT_MAX -#define PRIdLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, d ) ) -#define PRIiLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, i ) ) -#define PRIoLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, o ) ) -#define PRIuLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, u ) ) -#define PRIxLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, x ) ) -#define PRIXLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, X ) ) -#else -#define PRIdLEAST64 "d" -#define PRIiLEAST64 "i" -#define PRIoLEAST64 "o" -#define PRIuLEAST64 "u" -#define PRIxLEAST64 "x" -#define PRIXLEAST64 "X" -#endif - -#if _PDCLIB_INT_FAST64_MAX > _PDCLIB_INT_MAX -#define PRIdFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, d ) ) -#define PRIiFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, i ) ) -#define PRIoFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, o ) ) -#define PRIuFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, u ) ) -#define PRIxFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, x ) ) -#define PRIXFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, X ) ) -#else -#define PRIdFAST64 "d" -#define PRIiFAST64 "i" -#define PRIoFAST64 "o" -#define PRIuFAST64 "u" -#define PRIxFAST64 "x" -#define PRIXFAST64 "X" -#endif - -#if _PDCLIB_INTMAX_MAX > _PDCLIB_INT_MAX -#define PRIdMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, d ) ) -#define PRIiMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, i ) ) -#define PRIoMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, o ) ) -#define PRIuMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, u ) ) -#define PRIxMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, x ) ) -#define PRIXMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, X ) ) -#else -#define PRIdMAX "d" -#define PRIiMAX "i" -#define PRIoMAX "o" -#define PRIuMAX "u" -#define PRIxMAX "x" -#define PRIXMAX "X" -#endif - -#if _PDCLIB_INTPTR_MAX > _PDCLIB_INT_MAX -#define PRIdPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, d ) ) -#define PRIiPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, i ) ) -#define PRIoPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, o ) ) -#define PRIuPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, u ) ) -#define PRIxPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, x ) ) -#define PRIXPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, X ) ) -#else -#define PRIdPTR "d" -#define PRIiPTR "i" -#define PRIoPTR "o" -#define PRIuPTR "u" -#define PRIxPTR "x" -#define PRIXPTR "X" -#endif - -#define SCNdLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, d ) ) -#define SCNiLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, i ) ) -#define SCNoLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, o ) ) -#define SCNuLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, u ) ) -#define SCNxLEAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, x ) ) - -#define SCNdFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, d ) ) -#define SCNiFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, i ) ) -#define SCNoFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, o ) ) -#define SCNuFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, u ) ) -#define SCNxFAST8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST8_PREFIX, x ) ) - -#define SCNdLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, d ) ) -#define SCNiLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, i ) ) -#define SCNoLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, o ) ) -#define SCNuLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, u ) ) -#define SCNxLEAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, x ) ) - -#define SCNdFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, d ) ) -#define SCNiFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, i ) ) -#define SCNoFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, o ) ) -#define SCNuFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, u ) ) -#define SCNxFAST16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST16_PREFIX, x ) ) - -#define SCNdLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, d ) ) -#define SCNiLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, i ) ) -#define SCNoLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, o ) ) -#define SCNuLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, u ) ) -#define SCNxLEAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, x ) ) - -#define SCNdFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, d ) ) -#define SCNiFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, i ) ) -#define SCNoFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, o ) ) -#define SCNuFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, u ) ) -#define SCNxFAST32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST32_PREFIX, x ) ) - -#define SCNdLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, d ) ) -#define SCNiLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, i ) ) -#define SCNoLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, o ) ) -#define SCNuLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, u ) ) -#define SCNxLEAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, x ) ) - -#define SCNdFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, d ) ) -#define SCNiFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, i ) ) -#define SCNoFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, o ) ) -#define SCNuFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, u ) ) -#define SCNxFAST64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_FAST64_PREFIX, x ) ) - -#define SCNdMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, d ) ) -#define SCNiMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, i ) ) -#define SCNoMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, o ) ) -#define SCNuMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, u ) ) -#define SCNxMAX _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTMAX_PREFIX, x ) ) - -#define SCNdPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, d ) ) -#define SCNiPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, i ) ) -#define SCNoPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, o ) ) -#define SCNuPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, u ) ) -#define SCNxPTR _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INTPTR_PREFIX, x ) ) - -/* The exact-width types (int8_t, int16_t, ...) are *optional*, as not all - architectures support the necessary 8-bits-per-byte two's complement - native types. -*/ - -#if _PDCLIB_TWOS_COMPLEMENT == 1 - -#if _PDCLIB_INT_LEAST8_MAX == 0x7f -#if _PDCLIB_INT_LEAST8_MAX > _PDCLIB_INT_MAX -#define PRId8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, d ) ) -#define PRIi8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, i ) ) -#define PRIo8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, o ) ) -#define PRIu8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, u ) ) -#define PRIx8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, x ) ) -#define PRIX8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, X ) ) -#endif -#define SCNd8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, d ) ) -#define SCNi8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, i ) ) -#define SCNo8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, o ) ) -#define SCNu8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, u ) ) -#define SCNx8 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST8_PREFIX, x ) ) -#endif - -#if _PDCLIB_INT_LEAST16_MAX == 0x7fff -#if _PDCLIB_INT_LEAST16_MAX > _PDCLIB_INT_MAX -#define PRId16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, d ) ) -#define PRIi16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, i ) ) -#define PRIo16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, o ) ) -#define PRIu16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, u ) ) -#define PRIx16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, x ) ) -#define PRIX16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, X ) ) -#endif -#define SCNd16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, d ) ) -#define SCNi16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, i ) ) -#define SCNo16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, o ) ) -#define SCNu16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, u ) ) -#define SCNx16 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST16_PREFIX, x ) ) -#endif - -#if _PDCLIB_INT_LEAST32_MAX == 0x7fffffffl -#if _PDCLIB_INT_LEAST32_MAX > _PDCLIB_INT_MAX -#define PRId32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, d ) ) -#define PRIi32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, i ) ) -#define PRIo32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, o ) ) -#define PRIu32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, u ) ) -#define PRIx32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, x ) ) -#define PRIX32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, X ) ) -#endif -#define SCNd32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, d ) ) -#define SCNi32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, i ) ) -#define SCNo32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, o ) ) -#define SCNu32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, u ) ) -#define SCNx32 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST32_PREFIX, x ) ) -#endif - -#if _PDCLIB_INT_LEAST64_MAX == 0x7fffffffffffffffll -#if _PDCLIB_INT_LEAST64_MAX > _PDCLIB_INT_MAX -#define PRId64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, d ) ) -#define PRIi64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, i ) ) -#define PRIo64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, o ) ) -#define PRIu64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, u ) ) -#define PRIx64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, x ) ) -#define PRIX64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, X ) ) -#endif -#define SCNd64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, d ) ) -#define SCNi64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, i ) ) -#define SCNo64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, o ) ) -#define SCNu64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, u ) ) -#define SCNx64 _PDCLIB_value2string( _PDCLIB_concat( _PDCLIB_INT_LEAST64_PREFIX, x ) ) -#endif - -#endif - -/* 7.8.2 Functions for greatest-width integer types */ - -/* Calculate the absolute value of j */ -_PDCLIB_PUBLIC intmax_t imaxabs( intmax_t j ); - -/* Return quotient (quot) and remainder (rem) of an integer division in the - imaxdiv_t struct. -*/ -_PDCLIB_PUBLIC imaxdiv_t imaxdiv( intmax_t numer, intmax_t denom ); - -/* Separate the character array nptr into three parts: A (possibly empty) - sequence of whitespace characters, a character representation of an integer - to the given base, and trailing invalid characters (including the terminating - null character). If base is 0, assume it to be 10, unless the integer - representation starts with 0x / 0X (setting base to 16) or 0 (setting base to - 8). If given, base can be anything from 0 to 36, using the 26 letters of the - base alphabet (both lowercase and uppercase) as digits 10 through 35. - The integer representation is then converted into the return type of the - function. It can start with a '+' or '-' sign. If the sign is '-', the result - of the conversion is negated. - If the conversion is successful, the converted value is returned. If endptr - is not a NULL pointer, a pointer to the first trailing invalid character is - returned in *endptr. - If no conversion could be performed, zero is returned (and nptr in *endptr, - if endptr is not a NULL pointer). If the converted value does not fit into - the return type, the functions return INTMAX_MIN, INTMAX_MAX, or UINTMAX_MAX, - respectively, depending on the sign of the integer representation and the - return type, and errno is set to ERANGE. -*/ -/* This function is equivalent to strtol() / strtoul() in , but on - the potentially larger type. -*/ -_PDCLIB_PUBLIC intmax_t strtoimax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); -_PDCLIB_PUBLIC uintmax_t strtoumax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); - -/* TODO: wcstoimax(), wcstoumax() */ - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_INTTYPES_H -#include _PDCLIB_EXTEND_INTTYPES_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/iso646.h b/rocklibc/include/iso646.h deleted file mode 100644 index 88e521c..0000000 --- a/rocklibc/include/iso646.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Alternative spellings - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_ISO646_H -#define _PDCLIB_ISO646_H _PDCLIB_ISO646_H - -#ifndef __cplusplus -#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 ^= -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_ISO646_H -#include _PDCLIB_EXTEND_ISO646_H -#endif - -#endif diff --git a/rocklibc/include/limits.h b/rocklibc/include/limits.h deleted file mode 100644 index 72268a4..0000000 --- a/rocklibc/include/limits.h +++ /dev/null @@ -1,50 +0,0 @@ -/* Sizes of integer types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_LIMITS_H -#define _PDCLIB_LIMITS_H _PDCLIB_LIMITS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -/* TODO: Defined to 1 as multibyte characters are not supported yet. */ -#define MB_LEN_MAX 1 - -#define LLONG_MIN _PDCLIB_LLONG_MIN -#define LLONG_MAX _PDCLIB_LLONG_MAX -#define ULLONG_MAX _PDCLIB_ULLONG_MAX - -#define CHAR_BIT _PDCLIB_CHAR_BIT -#define CHAR_MAX _PDCLIB_CHAR_MAX -#define CHAR_MIN _PDCLIB_CHAR_MIN -#define SCHAR_MAX _PDCLIB_SCHAR_MAX -#define SCHAR_MIN _PDCLIB_SCHAR_MIN -#define UCHAR_MAX _PDCLIB_UCHAR_MAX -#define SHRT_MAX _PDCLIB_SHRT_MAX -#define SHRT_MIN _PDCLIB_SHRT_MIN -#define INT_MAX _PDCLIB_INT_MAX -#define INT_MIN _PDCLIB_INT_MIN -#define LONG_MAX _PDCLIB_LONG_MAX -#define LONG_MIN _PDCLIB_LONG_MIN -#define USHRT_MAX _PDCLIB_USHRT_MAX -#define UINT_MAX _PDCLIB_UINT_MAX -#define ULONG_MAX _PDCLIB_ULONG_MAX - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_LIMITS_H -#include _PDCLIB_EXTEND_LIMITS_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/locale.h b/rocklibc/include/locale.h deleted file mode 100644 index 0c18446..0000000 --- a/rocklibc/include/locale.h +++ /dev/null @@ -1,114 +0,0 @@ -/* Localization - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_LOCALE_H -#define _PDCLIB_LOCALE_H _PDCLIB_LOCALE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -/* The structure returned by localeconv(). - - The values for *_sep_by_space: - 0 - no space - 1 - if symbol and sign are adjacent, a space separates them from the value; - otherwise a space separates the symbol from the value - 2 - if symbol and sign are adjacent, a space separates them; otherwise a - space separates the sign from the value - - The values for *_sign_posn: - 0 - Parentheses surround value and symbol - 1 - sign precedes value and symbol - 2 - sign succeeds value and symbol - 3 - sign immediately precedes symbol - 4 - sign immediately succeeds symbol -*/ -struct lconv -{ - char * decimal_point; /* decimal point character */ /* LC_NUMERIC */ - char * thousands_sep; /* character for separating groups of digits */ /* LC_NUMERIC */ - char * grouping; /* string indicating the size of digit groups */ /* LC_NUMERIC */ - char * mon_decimal_point; /* decimal point for monetary quantities */ /* LC_MONETARY */ - char * mon_thousands_sep; /* thousands_sep for monetary quantities */ /* LC_MONETARY */ - char * mon_grouping; /* grouping for monetary quantities */ /* LC_MONETARY */ - char * positive_sign; /* string indicating nonnegative mty. qty. */ /* LC_MONETARY */ - char * negative_sign; /* string indicating negative mty. qty. */ /* LC_MONETARY */ - char * currency_symbol; /* local currency symbol (e.g. '$') */ /* LC_MONETARY */ - char * int_curr_symbol; /* international currency symbol (e.g. "USD" */ /* LC_MONETARY */ - char frac_digits; /* fractional digits in local monetary qty. */ /* LC_MONETARY */ - char p_cs_precedes; /* if currency_symbol precedes positive qty. */ /* LC_MONETARY */ - char n_cs_precedes; /* if currency_symbol precedes negative qty. */ /* LC_MONETARY */ - char p_sep_by_space; /* if it is separated by space from pos. qty. */ /* LC_MONETARY */ - char n_sep_by_space; /* if it is separated by space from neg. qty. */ /* LC_MONETARY */ - char p_sign_posn; /* positioning of positive_sign for mon. qty. */ /* LC_MONETARY */ - char n_sign_posn; /* positioning of negative_sign for mon. qty. */ /* LC_MONETARY */ - char int_frac_digits; /* Same as above, for international format */ /* LC_MONETARY */ - char int_p_cs_precedes; /* Same as above, for international format */ /* LC_MONETARY */ - char int_n_cs_precedes; /* Same as above, for international format */ /* LC_MONETARY */ - char int_p_sep_by_space; /* Same as above, for international format */ /* LC_MONETARY */ - char int_n_sep_by_space; /* Same as above, for international format */ /* LC_MONETARY */ - char int_p_sign_posn; /* Same as above, for international format */ /* LC_MONETARY */ - char int_n_sign_posn; /* Same as above, for international format */ /* LC_MONETARY */ -}; - -/* First arguments to setlocale(). - NOTE: If you add to / modify these, look at functions/locale/setlocale.c - and keep things in sync. -*/ -/* Entire locale */ -#define LC_ALL _PDCLIB_LC_ALL -/* Collation (strcoll(), strxfrm()) */ -#define LC_COLLATE _PDCLIB_LC_COLLATE -/* Character types (, ) */ -#define LC_CTYPE _PDCLIB_LC_CTYPE -/* Monetary formatting (as returned by localeconv) */ -#define LC_MONETARY _PDCLIB_LC_MONETARY -/* Decimal-point character (for printf() / scanf() functions), string - conversions, nonmonetary formatting as returned by localeconv -*/ -#define LC_NUMERIC _PDCLIB_LC_NUMERIC -/* Time formats (strftime(), wcsftime()) */ -#define LC_TIME _PDCLIB_LC_TIME -/* Messages (not specified but allowed by C99, and specified by POSIX) - (used by perror() / strerror()) -*/ -#define LC_MESSAGES _PDCLIB_LC_MESSAGES - -/* The category parameter can be any of the LC_* macros to specify if the call - to setlocale() shall affect the entire locale or only a portion thereof. - The category locale specifies which locale should be switched to, with "C" - being the minimal default locale, and "" being the locale-specific native - environment. A NULL pointer makes setlocale() return the *current* setting. - Otherwise, returns a pointer to a string associated with the specified - category for the new locale. -*/ -_PDCLIB_PUBLIC char * setlocale( int category, const char * locale ); - -/* Returns a struct lconv initialized to the values appropriate for the current - locale setting. -*/ -_PDCLIB_PUBLIC struct lconv * localeconv( void ); - -#ifdef __cplusplus -} -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_LOCALE_H -#include _PDCLIB_EXTEND_LOCALE_H -#endif - -#endif diff --git a/rocklibc/include/math.h b/rocklibc/include/math.h deleted file mode 100644 index 88b6619..0000000 --- a/rocklibc/include/math.h +++ /dev/null @@ -1,467 +0,0 @@ -/* Mathematics - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_MATH_H -#define _PDCLIB_MATH_H _PDCLIB_MATH_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -typedef float float_t; -typedef double double_t; - -#define HUGE_VALF _PDCLIB_HUGE_VALF; -#define HUGE_VAL _PDCLIB_HUGE_VAL; -#define HUGE_VALL _PDCLIB_HUGE_VALL; - -#define INFINITY (_PDCLIB_FLT_MAX * 2) -#define NAN ( -(0.0f / 0.0f) ) - -#define FP_FAST_FMAF -#define FP_FAST_FMA -#define FP_FAST_FMAL - -#define FP_ILOGB0 INT_MIN -#define FP_ILOGBNAN INT_MAX - -#define MATH_ERRNO 1 -#define MATH_ERREXCEPT 2 - -#define math_errhandling - -/* Classification */ - -/* FP_ZERO, FP_SUBNORMAL, FP_NORMAL */ -#define isfinite( x ) _PDCLIB_GENERIC( isfinite, x ) - -/* FP_INFINITE */ -#define isinf( x ) _PDCLIB_GENERIC( isinf, x ) - -/* FP_NAN */ -#define isnan( x ) _PDCLIB_GENERIC( isnan, x ) - -/* FP_NORMAL */ -#define isnormal( x ) _PDCLIB_GENERIC( isnormal, x ) - -/* Negative */ -#define signbit( x ) _PDCLIB_GENERIC( signbit, x ) - -/* See FP_* classes */ -#define fpclassify( x ) _PDCLIB_GENERIC( fpclassify, x ) - -#define FP_INFINITE 1 -#define FP_NAN 2 -#define FP_NORMAL 3 -#define FP_SUBNORMAL 4 -#define FP_ZERO 5 - -/* Trigonometric functions */ - -/* The principal value of the arc cosine of x. - Domain error for arguments not in the interval -1..+1. - Returns the interval 0..Pi radians. -*/ -double acos( double x ); -float acosf( float x ); -long double acosl( long double x ); - -/* The principal value of the arc sine of x. - Domain error for arguments not in the interval -1..+1. - Returns the interval -Pi/2..Pi/2 radians. -*/ -double asin( double x ); -float asinf( float x ); -long double asinl( long double x ); - -/* The principal value of the arc tangent of x. - Returns the interval -Pi/2..Pi/2 radians. -*/ -double atan( double x ); -float atanf( float x ); -long double atanl( long double x ); - -/* The value of the arc tangent of y/x, using the signs of both - arguments to determine the quadrant of the return value. - Domain error if both arguments are zero. - Returns the interval -Pi..Pi radians. -*/ -double atan2( double y, double x ); -float atan2f( float y, float x ); -long double atan2l( long double y, long double x ); - -/* Cosine of x in radians. */ -double cos( double x ); -float cosf( float x ); -long double cosl( long double x ); - -/* Sine of x in radians. */ -double sin( double x ); -float sinf( float x ); -long double sinl( long double x ); - -/* Tangent of x in radians. */ -double tan( double x ); -float tanf( float x ); -long double tanl( long double x ); - -/* Hyperbolic functions */ - -/* The (nonnegative) arc hyberbolic cosine of x. - Domain error for arguments less than 1. - Returns the interval 0..INF. -*/ -double acosh( double x ); -float acoshf( float x ); -long double acoshl( long double x ); - -/* The arc hyberbolic sine of x. -*/ -double asinh( double x ); -float asinhf( float x ); -long double asinhl( long double x ); - -/* The arc hyberbolic tangent of x. - Domain error for arguments not in -1..1. - Range error if -1 or +1. -*/ -double atanh( double x ); -float atanhf( float x ); -long double atanhl( long double x ); - -/* The hyberbolic cosine of x. - Range error if magnitude of x is too large. -*/ -double cosh( double x ); -float coshf( float x ); -long double coshl( long double x ); - -/* The hyberbolic sine of x. - Range error if magnitude of x is too large. -*/ -double sinh( double x ); -float sinhf( float x ); -long double sinhl( long double x ); - -/* The hyberbolic tangent of x. - Range error if magnitude of x is too large. -*/ -double tanh( double x ); -float tanhf( float x ); -long double tanhl( long double x ); - -/* Exponential and logarithmic functions */ - -/* The base-e exponential of x. - Range error if magnitude of x is too large. -*/ -double exp( double x ); -float expf( float x ); -long double expl( long double x ); - -/* The base-2 exponential of x. - Range error if magnitude of x is too large. -*/ -double exp2( double x ); -float exp2f( float x ); -long double exp2l( long double x ); - -/* The base-e exponential of x, minus 1. - Range error if magnitude of x is too large. - Returns e^x - 1. -*/ -double expm1( double x ); -float expm1f( float x ); -long double expm1l( long double x ); - -/* Breaks a floating-point number into a normalized fraction - and an integral power of 2 (stored in the object pointed - to by exp). -*/ -double frexp( double value, int * exp ); -float frexpf( float value, int * exp ); -long double frexpl( long double value, int * exp ); - -/* Extract the exponent of x as a signed int. - * Returns FP_ILOGB0 if x is zero, INT_MAX if x is infinite, - * FP_ILOGBNAN if x is a NaN. Range error may occur if x is 0. -*/ -double ilogb( double x ); -float ilogbf( float x ); -long double ilogbl( long double x ); - -/* Multiply x by 2^exp. Range error may occur. */ -double ldexp( double x, int exp ); -float ldexpf( float x, int exp ); -long double ldexpl( long double x, int exp ); - -/* Compute the base-e logarithm of x. - Domain error if argument is negative. - Range error if argument is zero. -*/ -double log( double x ); -float logf( float x ); -long double logl( long double x ); - -/* Compute the base-10 logarithm of x. - Domain error if argument is negative. - Range error if argument is zero. -*/ -double log10( double x ); -float log10f( float x ); -long double log10l( long double x ); - -/* Compute the base-e logarithm of 1 plus x. - Domain error if argument is less than -1. - Range error if argument is -1. -*/ -double log1p( double x ); -float log1pf( float x ); -long double log1pl( long double x ); - -/* Compute the base-2 logarithm of x. - Domain error if argument is negative. - Range error if argument is zero. -*/ -double log2( double x ); -float log2f( float x ); -long double log2l( long double x ); - -/* Extract exponent of x, as signed integer in floating-point format. - Subnormal is treated as though normalized. - Domain error if argument is zero. -*/ -double logb( double x ); -float logbf( float x ); -long double logbl( long double x ); - -/* Breaks value into integral and fractional parts, each having - the same type and sign as the argument. The integral part is - stored in the object pointed to by iptr. -*/ -double modf( double value, double * exp ); -float modff( float value, float * exp ); -long double modfl( long double value, long double * exp ); - -/* Compute x * FLT_RADIX^n efficiently. Range error may occur. */ -double scalbn( double x, int n ); -float scalbnf( float x, int n ); -long double scalbnl( long double x, int n ); - -double scalbln( double x, long int * n ); -float scalblnf( float x, long int * n ); -long double scalblnl( long double x, long int * n ); - -/* Power and absolute-value functions */ - -/* Returns x^1/3. */ -double cbrt( double x ); -float cbrtf( float x ); -long double cbrtl( long double x ); - -/* Returns absolute value of x. */ -double fabs( double x ); -float fabsf( float x ); -long double fabsl( long double x ); - -/* Returns square root of the sum of squares of x and y. - Range error may occur. -*/ -double hypot( double x, double y ); -float hypotf( float x, float y ); -long double hypotl( long double x, long double y ); - -/* Returns x^y. - Domain error if x is finite and negative and y is finite and not - an integer value. - Domain error if x is zero and y is less or equal zero. - Range error may occur. -*/ -double pow( double x, double y ); -float powf( float x, float y ); -long double powl( long double x, long double y ); - -/* Returns x^1/2. */ -double sqrt( double x ); -float sqrtf( float x ); -long double sqrtl( long double x ); - -/* Error and gamma functions */ - -/* Compute the error function of x. */ -double erf( double x ); -float erff( float x ); -long double erfl( long double x ); - -/* Compute the complementary error function of x. - Range error if x is too large. -*/ -double erfc( double x ); -float erfcf( float x ); -long double erfcl( long double x ); - -/* Compute the natural logarithm of the absolute value of gamma(x). - Range error if x is too lange, x is negative, or zero. -*/ -double lgamma( double x ); -float lgammaf( float x ); -long double lgammal( long double x ); - -/* Compute the gamma function of x. - Range error if x is negative, or zero, too large or too small. -*/ -double tgamma( double x ); -float tgammaf( float x ); -long double tgammal( long double x ); - -/* Nearest integer functions */ - -/* The smallest integer no less than x. */ -double ceil( double x ); -float ceilf( float x ); -long double ceill( long double x ); - -/* The largest integer no greater than x. */ -double floor( double x ); -float floorf( float x ); -long double floorl( long double x ); - -/* Round in current rounding direction. No "inexact" exception. */ -double nearbyint( double x ); -float nearbyintf( float x ); -long double nearbyintl( long double x ); - -/* Round in current rounding direction. Raises "inexact" exception. */ -double rint( double x ); -float rintf( float x ); -long double rintl( long double x ); - -/* Round in current rounding direction. - Range error if magnitude is too large. -*/ -long int lrint( double x ); -long int lrintf( float x ); -long int lrintl( long double x ); -long long int llrint( double x ); -long long int llrintf( float x ); -long long int llrintl( long double x ); - -/* Round to nearest, breaking ties away from zero. */ -double round( double x ); -float roundf( float x ); -long double roundl( long double x ); - -/* Round to nearest, breaking ties away from zero. - Range error if magnitude is too large. -*/ -long int lround( double x ); -long int lroundf( float x ); -long int lroundl( long double x ); -long long int llround( double x ); -long long int llroundf( float x ); -long long int llroundl( long double x ); - -/* Round toward zero. */ -double trunc( double x ); -float truncf( float x ); -long double truncl( long double x ); - -/* Remainder functions */ - -/* Compute the remainder of x / y. */ -double fmod( double x, double y ); -float fmodf( float x, float y ); -long double fmodl( long double x, long double y ); - -/* Compute the remainder of x REM y. */ -double remainder( double x, double y ); -float remainderf( float x, float y ); -long double remainderl( long double x, long double y ); - -/* Compute the remainder of x REM y. In quo store a value with - the sign of the quotient and magnitude congruent mod 2^n to - the magnitude of the integral quotient of x / y, with n - an implementation-defined integer greater than or equal to 3. -*/ -double rmquo( double x, double y ); -float rmquof( float x, float y ); -long double rmquol( long double x, long double y ); - -/* Manipulation functions */ - -/* Returns a value with magnitude of x and sign of y. */ -double copysign( double x, double y ); -float copysignf( float x, float y ); -long double copysignl( long double x, long double y ); - -/* Returns a NaN value with the given n-char sequence. */ -double nan( const char * tagp ); -float nanf( const char * tagp ); -long double nanl( const char * tagp ); - -/* Determine the next representable value after x in direction y. - Range error if result is not representable. -*/ -double nextafter( double x, double y ); -float nextafterf( float x, float y ); -long double nextafterl( long double x, long double y ); - -/* As nextafter but with long double as second parameter. */ -double nexttoward( double x, double y ); -float nexttowardf( float x, float y ); -long double nexttowardl( long double x, long double y ); - -/* Maximum, minimum, and positive difference functions */ - -/* Positive difference. */ -double fdim( double x, double y ); -float fdimf( float x, float y ); -long double fdiml( long double x, long double y ); - -/* Maximum. */ -double fmax( double x, double y ); -float fmaxf( float x, float y ); -long double fmaxl( long double x, long double y ); - -/* Minimum. */ -double fmin( double x, double y ); -float fminf( float x, float y ); -long double fminl( long double x, long double y ); - -/* Multiply-add. */ -double fma( double x, double y, double z ); -float fmaf( float x, float y, float z ); -long double fmal( long double x, long double y, long double z ); - -/* Comparison macros (without "invalid" FP exception) */ - -#define isgreater( x, y ) - -#define isgreaterequal( x, y ) - -#define isless( x, y ) - -#define islessequal( x, y ) - -#define islessgreater( x, y ) - -#define isunordered( x, y ) - -#ifdef __cplusplus -} -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_MATH_H -#include _PDCLIB_EXTEND_MATH_H -#endif - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_config.h b/rocklibc/include/pdclib/_PDCLIB_config.h deleted file mode 100644 index 653f89e..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_config.h +++ /dev/null @@ -1,915 +0,0 @@ -/* Internal PDCLib configuration <_PDCLIB_config.h> - ("Example" platform target, for PDCLib development) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_CONFIG_H -#define _PDCLIB_CONFIG_H _PDCLIB_CONFIG_H - -/* -------------------------------------------------------------------------- */ -/* Misc */ -/* -------------------------------------------------------------------------- */ - -/* Helper macros also documented in _PDCLIB_internal.h, but defined here as */ -/* they are needed in this file already. */ -/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending. */ -/* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */ -#define _PDCLIB_cc( x, y ) x ## y -#define _PDCLIB_concat( x, y ) _PDCLIB_cc( x, y ) - -/* exit() can signal success to the host environment by the value of zero or */ -/* the constant EXIT_SUCCESS. Failure is signaled by EXIT_FAILURE. Note that */ -/* any other return value is "implementation-defined", i.e. your environment */ -/* is not required to handle it gracefully. Set your definitions here. */ -#define _PDCLIB_SUCCESS 0 -#define _PDCLIB_FAILURE -1 - -/* qsort() in requires a function that swaps two memory areas. */ -/* Below is a naive implementation that can be improved significantly for */ -/* specific platforms, e.g. by swapping int instead of char. */ -#define _PDCLIB_memswp( i, j, size ) \ - char tmp; \ - do { \ - tmp = *i; \ - *i++ = *j; \ - *j++ = tmp; \ - } while ( --size ); - -/* Define this to some compiler directive that can be written after the */ -/* parameter list of a function declaration to indicate the function does */ -/* never return. If your compiler does not support such a directive, define */ -/* to nothing. (This is to avoid warnings with the exit functions under GCC */ -/* when compiling with C99/C++ settings, where C11 _Noreturn is unavailable.) */ -#define _PDCLIB_NORETURN __attribute__(( noreturn )) - -/* -------------------------------------------------------------------------- */ -/* Symbol Visibility */ -/* -------------------------------------------------------------------------- */ - -/* This defines _PDCLIB_PUBLIC to indicate external linkage, and _PDCLIB_LOCAL - to indicate local linkage. -*/ - -#ifdef _PDCLIB_STATIC_DEFINE - #define _PDCLIB_PUBLIC - #define _PDCLIB_LOCAL -#else - #if defined _WIN32 || defined __CYGWIN__ - #ifdef _PDCLIB_BUILD - #ifdef __GNUC__ - #define _PDCLIB_PUBLIC __attribute__ ((dllexport)) - #else - #define _PDCLIB_PUBLIC __declspec(dllexport) - #endif - #else - #ifdef __GNUC__ - #define _PDCLIB_PUBLIC __attribute__ ((dllimport)) - #else - #define _PDCLIB_PUBLIC __declspec(dllimport) - #endif - #endif - #define _PDCLIB_LOCAL - #else - #if __GNUC__ >= 4 - #define _PDCLIB_PUBLIC __attribute__ ((visibility ("default"))) - #define _PDCLIB_LOCAL __attribute__ ((visibility ("hidden"))) - #else - #define _PDCLIB_PUBLIC - #define _PDCLIB_LOCAL - #endif - #endif -#endif - -/* -------------------------------------------------------------------------- */ -/* Integers */ -/* -------------------------------------------------------------------------- */ -/* The defines below make use of predefines offered by GCC and clang. If you */ -/* adapt PDCLib for a different compiler family, you will have to use what */ -/* that compiler provides, or enter actual values. */ -/* -------------------------------------------------------------------------- */ - -/* At the point of writing, PDCLib makes no provisions for, nor has it been */ -/* tested, on a platform that uses signed magnitude or one's complement to */ -/* encode its integers. Most importantly, there are no guarantees that the */ -/* negative zero of those encodings is in any form handled gracefully. */ -#define _PDCLIB_TWOS_COMPLEMENT 1 - -/* 1234 for little endian, 4321 for big endian; other types not supported. */ -#define _PDCLIB_ENDIANESS __BYTE_ORDER__ - -/* Calculation of a minimum value from a given maximum for two's complement. */ -/* (For convenience only, used only in this header file below.) */ -#define _PDCLIB_MIN_CALC( max ) ( ( - max ) - 1 ) - -/* Now, introducting the various predefines to the _PDCLIB_* namespace, so */ -/* the rest of PDCLib can work with that and adapting to a different compiler */ -/* will require changes only in this one file. */ - -/* Bits in a char */ -#define _PDCLIB_CHAR_BIT __CHAR_BIT__ - -/* Maximum and minimum values of signed / unsigned char */ -#define _PDCLIB_SCHAR_MAX __SCHAR_MAX__ -#define _PDCLIB_SCHAR_MIN _PDCLIB_MIN_CALC( __SCHAR_MAX__ ) -#define _PDCLIB_UCHAR_MAX ( __SCHAR_MAX__ * 2 + 1 ) - -/* Whether the 'char' type is unsigned */ -#ifdef __CHAR_UNSIGNED__ -#define _PDCLIB_CHAR_MAX _PDCLIB_UCHAR_MAX -#define _PDCLIB_CHAR_MIN 0 -#else -#define _PDCLIB_CHAR_MAX _PDCLIB_SCHAR_MAX -#define _PDCLIB_CHAR_MIN _PDCLIB_SCHAR_MIN -#endif - -/* Maximum and minimum values of signed / unsigned short */ -#define _PDCLIB_SHRT_MAX __SHRT_MAX__ -#define _PDCLIB_SHRT_MIN _PDCLIB_MIN_CALC( __SHRT_MAX__ ) -#define _PDCLIB_USHRT_MAX ( __SHRT_MAX__ * 2u + 1 ) - -/* Maximum and minimum values of signed / unsigned int */ -#define _PDCLIB_INT_MAX __INT_MAX__ -#define _PDCLIB_INT_MIN _PDCLIB_MIN_CALC( __INT_MAX__ ) -#define _PDCLIB_UINT_MAX ( __INT_MAX__ * 2u + 1 ) - -/* Maximum and minimum values of signed / unsigned long */ -#define _PDCLIB_LONG_MAX __LONG_MAX__ -#define _PDCLIB_LONG_MIN _PDCLIB_MIN_CALC( __LONG_MAX__ ) -#define _PDCLIB_ULONG_MAX ( __LONG_MAX__ * 2ul + 1 ) - -/* Maximum and minimum values of signed / unsigned long long */ -#define _PDCLIB_LLONG_MAX __LONG_LONG_MAX__ -#define _PDCLIB_LLONG_MIN _PDCLIB_MIN_CALC( __LONG_LONG_MAX__ ) -#define _PDCLIB_ULLONG_MAX ( __LONG_LONG_MAX__ * 2ull + 1 ) - -/* -------------------------------------------------------------------------- */ -/* defines a set of integer types that are of a minimum width, and */ -/* "usually fastest" on the system. (If, for example, accessing a single char */ -/* requires the CPU to access a complete int and then mask out the char, the */ -/* "usually fastest" type of at least 8 bits would be int, not char.) */ -/* If you do not have information on the relative performance of the types, */ -/* the standard allows you to define any type that meets minimum width and */ -/* signedness requirements. */ -/* The first define is the appropriate basic type (e.g. "long int"), second */ -/* its max value, the third its min value (both expressed in the given type). */ -/* The same follows for the unsigned type (for which the minimum value is */ -/* obviously zero and need not be defined). */ -/* There *are* predefines provided for the printf()/scanf() length specifiers */ -/* but tunneling them through here would have added many lines of repetitive */ -/* and mostly redundant defines. They are determined in <_PDCLIB_internal.h>. */ -/* -------------------------------------------------------------------------- */ - -/* int_fast8_t / uint_fast8_t */ -#define _PDCLIB_int_fast8_t __INT_FAST8_TYPE__ -#define _PDCLIB_INT_FAST8_MAX __INT_FAST8_MAX__ -#define _PDCLIB_INT_FAST8_MIN _PDCLIB_MIN_CALC( __INT_FAST8_MAX__ ) -#define _PDCLIB_uint_fast8_t __UINT_FAST8_TYPE__ -#define _PDCLIB_UINT_FAST8_MAX __UINT_FAST8_MAX__ - -/* int_least8_t / uint_least8_t */ -#define _PDCLIB_int_least8_t __INT_LEAST8_TYPE__ -#define _PDCLIB_INT_LEAST8_MAX __INT_LEAST8_MAX__ -#define _PDCLIB_INT_LEAST8_MIN _PDCLIB_MIN_CALC( __INT_LEAST8_MAX__ ) -#define _PDCLIB_uint_least8_t __UINT_LEAST8_TYPE__ -#define _PDCLIB_UINT_LEAST8_MAX __UINT_LEAST8_MAX__ - -/* int_fast16_t / uint_fast16_t */ -#define _PDCLIB_int_fast16_t __INT_FAST16_TYPE__ -#define _PDCLIB_INT_FAST16_MAX __INT_FAST16_MAX__ -#define _PDCLIB_INT_FAST16_MIN _PDCLIB_MIN_CALC( __INT_FAST16_MAX__ ) -#define _PDCLIB_uint_fast16_t __UINT_FAST16_TYPE__ -#define _PDCLIB_UINT_FAST16_MAX __UINT_FAST16_MAX__ - -/* int_least16_t / uint_least16_t */ -#define _PDCLIB_int_least16_t __INT_LEAST16_TYPE__ -#define _PDCLIB_INT_LEAST16_MAX __INT_LEAST16_MAX__ -#define _PDCLIB_INT_LEAST16_MIN _PDCLIB_MIN_CALC( __INT_LEAST16_MAX__ ) -#define _PDCLIB_uint_least16_t __UINT_LEAST16_TYPE__ -#define _PDCLIB_UINT_LEAST16_MAX __UINT_LEAST16_MAX__ - -/* int_fast32_t / uint_fast32_t */ -#define _PDCLIB_int_fast32_t __INT_FAST32_TYPE__ -#define _PDCLIB_INT_FAST32_MAX __INT_FAST32_MAX__ -#define _PDCLIB_INT_FAST32_MIN _PDCLIB_MIN_CALC( __INT_FAST32_MAX__ ) -#define _PDCLIB_uint_fast32_t __UINT_FAST32_TYPE__ -#define _PDCLIB_UINT_FAST32_MAX __UINT_FAST32_MAX__ - -/* int_least32_t / uint_least32_t */ -#define _PDCLIB_int_least32_t __INT_LEAST32_TYPE__ -#define _PDCLIB_INT_LEAST32_MAX __INT_LEAST32_MAX__ -#define _PDCLIB_INT_LEAST32_MIN _PDCLIB_MIN_CALC( __INT_LEAST32_MAX__ ) -#define _PDCLIB_uint_least32_t __UINT_LEAST32_TYPE__ -#define _PDCLIB_UINT_LEAST32_MAX __UINT_LEAST32_MAX__ - -/* int_fast64_t / uint_fast64_t */ -#define _PDCLIB_int_fast64_t __INT_FAST64_TYPE__ -#define _PDCLIB_INT_FAST64_MAX __INT_FAST64_MAX__ -#define _PDCLIB_INT_FAST64_MIN _PDCLIB_MIN_CALC( __INT_FAST64_MAX__ ) -#define _PDCLIB_uint_fast64_t __UINT_FAST64_TYPE__ -#define _PDCLIB_UINT_FAST64_MAX __UINT_FAST64_MAX__ - -/* int_least64_t / uint_least64_t */ -#define _PDCLIB_int_least64_t __INT_LEAST64_TYPE__ -#define _PDCLIB_INT_LEAST64_MAX __INT_LEAST64_MAX__ -#define _PDCLIB_INT_LEAST64_MIN _PDCLIB_MIN_CALC( __INT_LEAST64_MAX__ ) -#define _PDCLIB_uint_least64_t __UINT_LEAST64_TYPE__ -#define _PDCLIB_UINT_LEAST64_MAX __UINT_LEAST64_MAX__ - -/* Exact-width integer types. These are *optional*. If your platform does not */ -/* support types of these exact widths in two's complement encoding, just */ -/* leave them undefined. */ -#define _PDCLIB_int8_t __INT8_TYPE__ -#define _PDCLIB_int16_t __INT16_TYPE__ -#define _PDCLIB_int32_t __INT32_TYPE__ -#define _PDCLIB_int64_t __INT64_TYPE__ -#define _PDCLIB_uint8_t __UINT8_TYPE__ -#define _PDCLIB_uint16_t __UINT16_TYPE__ -#define _PDCLIB_uint32_t __UINT32_TYPE__ -#define _PDCLIB_uint64_t __UINT64_TYPE__ - -/* INTn_C / UINTn_C macros to define int_leastN_t / uint_leastN_t literals. */ -#if defined( __INT8_C ) -/* GCC */ -#define _PDCLIB_INT_LEAST8_C __INT8_C -#define _PDCLIB_UINT_LEAST8_C __UINT8_C -#define _PDCLIB_INT_LEAST16_C __INT16_C -#define _PDCLIB_UINT_LEAST16_C __UINT16_C -#define _PDCLIB_INT_LEAST32_C __INT32_C -#define _PDCLIB_UINT_LEAST32_C __UINT32_C -#define _PDCLIB_INT_LEAST64_C __INT64_C -#define _PDCLIB_UINT_LEAST64_C __UINT64_C -#elif defined( __INT8_C_SUFFIX__ ) -/* Clang */ -#define _PDCLIB_INT_LEAST8_C(c) _PDCLIB_concat( c, __INT8_C_SUFFIX__ ) -#define _PDCLIB_UINT_LEAST8_C(c) _PDCLIB_concat( c, __UINT8_C_SUFFIX__ ) -#define _PDCLIB_INT_LEAST16_C(c) _PDCLIB_concat( c, __INT16_C_SUFFIX__ ) -#define _PDCLIB_UINT_LEAST16_C(c) _PDCLIB_concat( c, __UINT16_C_SUFFIX__ ) -#define _PDCLIB_INT_LEAST32_C(c) _PDCLIB_concat( c, __INT32_C_SUFFIX__ ) -#define _PDCLIB_UINT_LEAST32_C(c) _PDCLIB_concat( c, __UINT32_C_SUFFIX__ ) -#define _PDCLIB_INT_LEAST64_C(c) _PDCLIB_concat( c, __INT64_C_SUFFIX__ ) -#define _PDCLIB_UINT_LEAST64_C(c) _PDCLIB_concat( c, __UINT64_C_SUFFIX__ ) -#else -#error Please create your own _PDCLIB_config.h. Using the existing one as-is will not work. (Unsupported *INTn_C macros.) -#endif - -/* defines the div() function family that allows taking quotient */ -/* and remainder of an integer division in one operation. Many platforms */ -/* support this in hardware / opcode, and the standard permits ordering of */ -/* the return structure in any way to fit the hardware. That is why those */ -/* structs can be configured here. */ - -struct _PDCLIB_div_t -{ - int quot; - int rem; -}; - -struct _PDCLIB_ldiv_t -{ - long int quot; - long int rem; -}; - -struct _PDCLIB_lldiv_t -{ - long long int quot; - long long int rem; -}; - -/* -------------------------------------------------------------------------- */ -/* What follows are a couple of "special" typedefs and their limits. */ -/* -------------------------------------------------------------------------- */ - -/* The result type of substracting two pointers */ -#define _PDCLIB_ptrdiff_t __PTRDIFF_TYPE__ -#define _PDCLIB_PTRDIFF_MAX __PTRDIFF_MAX__ -#define _PDCLIB_PTRDIFF_MIN _PDCLIB_MIN_CALC( __PTRDIFF_MAX__ ) - -/* An integer type that can be accessed as atomic entity (think asynchronous */ -/* interrupts). In a freestanding environment, the type itself need not be */ -/* defined, but its limits must. (Don't ask.) GCC is so kind to predefine it, */ -/* but clang is only giving us its MAX value, so we use that to identify the */ -/* type in _PDCLIB_int.h if the type definition is unavailable. */ -#ifdef __SIG_ATOMIC_TYPE__ -#define _PDCLIB_sig_atomic_t __SIG_ATOMIC_TYPE__ -#endif -#define _PDCLIB_SIG_ATOMIC_MAX __SIG_ATOMIC_MAX__ -#define _PDCLIB_SIG_ATOMIC_MIN _PDCLIB_MIN_CALC( __SIG_ATOMIC_MAX__ ) - -/* Result type of the 'sizeof' operator (must be unsigned). */ -/* Note: In , this is taken as the base for RSIZE_MAX, the limit */ -/* for the bounds-checking interfaces of Annex K. The recommendation by the */ -/* standard is to use ( SIZE_MAX >> 1 ) when "targeting machines with large */ -/* addess spaces", whereas small address spaces should use SIZE_MAX directly. */ -#define _PDCLIB_size_t __SIZE_TYPE__ -#define _PDCLIB_SIZE_MAX __SIZE_MAX__ - -/* Large enough an integer to hold all character codes of the widest */ -/* supported locale. */ -#define _PDCLIB_wchar_t __WCHAR_TYPE__ -#define _PDCLIB_WCHAR_MAX __WCHAR_MAX__ -#define _PDCLIB_WCHAR_MIN __WCHAR_MIN__ - -/* Large enough an integer to hold all character codes of the widest */ -/* supported locale plus WEOF (which needs not to be equal to EOF, nor needs */ -/* to be of negative value). */ -#define _PDCLIB_wint_t __WINT_TYPE__ -#define _PDCLIB_WINT_MAX __WINT_MAX__ -#define _PDCLIB_WINT_MIN __WINT_MIN__ - -/* Integer types capable of taking the (cast) value of a void *, and having */ -/* the value cast back to void *, comparing equal to the original. */ -#define _PDCLIB_intptr_t __INTPTR_TYPE__ -#define _PDCLIB_INTPTR_MAX __INTPTR_MAX__ -#define _PDCLIB_INTPTR_MIN _PDCLIB_MIN_CALC( __INTPTR_MAX__ ) -#define _PDCLIB_uintptr_t __UINTPTR_TYPE__ -#define _PDCLIB_UINTPTR_MAX __UINTPTR_MAX__ - -/* Largest supported integer type. Implementation note: see _PDCLIB_atomax(). */ -#define _PDCLIB_intmax_t __INTMAX_TYPE__ -#define _PDCLIB_INTMAX_MAX __INTMAX_MAX__ -#define _PDCLIB_INTMAX_MIN _PDCLIB_MIN_CALC( __INTMAX_MAX__ ) -#define _PDCLIB_INTMAX_C __INTMAX_C -#define _PDCLIB_uintmax_t __UINTMAX_TYPE__ -#define _PDCLIB_UINTMAX_MAX __UINTMAX_MAX__ -#define _PDCLIB_UINTMAX_C __UINTMAX_C - -/* defines imaxdiv(), which is equivalent to the div() function */ -/* family (see further above) with intmax_t as basis. */ -struct _PDCLIB_imaxdiv_t -{ - _PDCLIB_intmax_t quot; - _PDCLIB_intmax_t rem; -}; - -/* -------------------------------------------------------------------------- */ -/* Time types, limits, constants, and paths */ -/* -------------------------------------------------------------------------- */ - -/* _PDCLIB_time is the type for type_t; _PDCLIB_clock for clock_t. Both types */ -/* are defined as "real types capable of representing times". The "range and */ -/* precision of times representable" is implementation-defined. */ - -/* For clock_t, the standard defines that dividing the result of clock() by */ -/* CLOCKS_PER_SEC gives the seconds elapsed. */ -#ifdef __CYGWIN__ -#define _PDCLIB_clock_t unsigned long -#else -#define _PDCLIB_clock_t long -#endif -#define _PDCLIB_CLOCKS_PER_SEC 1000000 - -/* For time_t, no such divider exists. Most implementations use a count of */ -/* seconds since a specified epoch. While PDCLib really should support other */ -/* encodings as well, for now "count of seconds" is the only supported one. */ -/* MIN / MAX values for time_t are not required by the standard (and they are */ -/* not "exported" from the _PDCLIB namespace), but they are useful in support */ -/* of the _tzcode implementation. */ -#ifdef __MINGW64__ -#define _PDCLIB_time_t long long -#define _PDCLIB_TIME_MAX __LONG_LONG_MAX__ -#define _PDCLIB_TIME_MIN _PDCLIB_MIN_CALC( __LONG_LONG_MAX__ ) -#else -#define _PDCLIB_time_t long -#define _PDCLIB_TIME_MAX __LONG_MAX__ -#define _PDCLIB_TIME_MIN _PDCLIB_MIN_CALC( __LONG_MAX__ ) -#endif - -/* "Unix time" uses 1970-01-01T00:00:00 as "epoch". If your system uses a */ -/* different "zero point" for its timestamps, set this to the offset between */ -/* your epoch and Unix epoch. (For example, NTP uses 1900-01-01T00:00:00 as */ -/* epoch, giving an offset of (70 * 365 + 17) * 86400 = 220898800 seconds.) */ -#define _PDCLIB_EPOCH_BIAS INT64_C( 0 ) - -/* Leave this alone for now. */ -#define _PDCLIB_TIME_UTC 1 - -/* Path to TZ data. */ -/* IMPORTANT: *Must* end with separator character! */ -/* It does make it much easier for the time data handling code if this detail */ -/* can be relied upon and need not be handled in code. */ -#define _PDCLIB_TZDIR "/usr/share/zoneinfo/" - -/* Path to default (local) timezone */ -#define _PDCLIB_TZDEFAULT "/etc/localtime" - -/* -------------------------------------------------------------------------- */ -/* Floating Point */ -/* -------------------------------------------------------------------------- */ - -/* Whether the implementation rounds toward zero (0), to nearest (1), toward */ -/* positive infinity (2), or toward negative infinity (3). (-1) signifies */ -/* indeterminable rounding, any other value implementation-specific rounding. */ -#define _PDCLIB_FLT_ROUNDS -1 - -/* Check for explanations on each of these values. */ -#define _PDCLIB_FLT_EVAL_METHOD __FLT_EVAL_METHOD__ - -#define _PDCLIB_FLT_HAS_SUBNORM __FLT_HAS_DENORM__ -#define _PDCLIB_DBL_HAS_SUBNORM __DBL_HAS_DENORM__ -#define _PDCLIB_LDBL_HAS_SUBNORM __LDBL_HAS_DENORM__ - -#define _PDCLIB_FLT_RADIX __FLT_RADIX__ - -#define _PDCLIB_FLT_MANT_DIG __FLT_MANT_DIG__ -#define _PDCLIB_DBL_MANT_DIG __DBL_MANT_DIG__ -#define _PDCLIB_LDBL_MANT_DIG __LDBL_MANT_DIG__ - -#define _PDCLIB_FLT_DECIMAL_DIG __FLT_DECIMAL_DIG__ -#define _PDCLIB_DBL_DECIMAL_DIG __DBL_DECIMAL_DIG__ -#define _PDCLIB_LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__ - -#define _PDCLIB_DECIMAL_DIG __DECIMAL_DIG__ - -#define _PDCLIB_FLT_DIG __FLT_DIG__ -#define _PDCLIB_DBL_DIG __DBL_DIG__ -#define _PDCLIB_LDBL_DIG __LDBL_DIG__ - -#define _PDCLIB_FLT_MIN_EXP __FLT_MIN_EXP__ -#define _PDCLIB_DBL_MIN_EXP __DBL_MIN_EXP__ -#define _PDCLIB_LDBL_MIN_EXP __LDBL_MIN_EXP__ - -#define _PDCLIB_FLT_MIN_10_EXP __FLT_MIN_10_EXP__ -#define _PDCLIB_DBL_MIN_10_EXP __DBL_MIN_10_EXP__ -#define _PDCLIB_LDBL_MIN_10_EXP __LDBL_MIN_10_EXP__ - -#define _PDCLIB_FLT_MAX_EXP __FLT_MAX_EXP__ -#define _PDCLIB_DBL_MAX_EXP __DBL_MAX_EXP__ -#define _PDCLIB_LDBL_MAX_EXP __LDBL_MAX_EXP__ - -#define _PDCLIB_FLT_MAX_10_EXP __FLT_MAX_10_EXP__ -#define _PDCLIB_DBL_MAX_10_EXP __DBL_MAX_10_EXP__ -#define _PDCLIB_LDBL_MAX_10_EXP __LDBL_MAX_10_EXP__ - -#define _PDCLIB_FLT_MAX __FLT_MAX__ -#define _PDCLIB_DBL_MAX __DBL_MAX__ -#define _PDCLIB_LDBL_MAX __LDBL_MAX__ - -#define _PDCLIB_FLT_EPSILON __FLT_EPSILON__ -#define _PDCLIB_DBL_EPSILON __DBL_EPSILON__ -#define _PDCLIB_LDBL_EPSILON __LDBL_EPSILON__ - -#define _PDCLIB_FLT_MIN __FLT_MIN__ -#define _PDCLIB_DBL_MIN __DBL_MIN__ -#define _PDCLIB_LDBL_MIN __LDBL_MIN__ - -#define _PDCLIB_FLT_TRUE_MIN __FLT_DENORM_MIN__ -#define _PDCLIB_DBL_TRUE_MIN __DBL_DENORM_MIN__ -#define _PDCLIB_LDBL_TRUE_MIN __LDBL_DENORM_MIN__ - -/* Macros for deconstructing floating point values */ -/* This assumes that the floating point value has been memcpy'd into an array */ -/* of _PDCLIB_bigint_digit_t (see _PDCLIB_bigint_from_*dbl.c with the array */ -/* passed to the macro as parameter. */ -#define _PDCLIB_FLT_SIGN( data ) ( ( data[1] & 0x8000 ) >> 15 ) -#define _PDCLIB_FLT_EXP( data ) ( ( data[1] & 0x7f80 ) >> 7 ) -#define _PDCLIB_FLT_SIZE( data ) ( data[1] &= 0x007f, 2 ) - -#define _PDCLIB_DBL_SIGN( data ) ( ( data[3] & 0x8000 ) >> 15 ) -#define _PDCLIB_DBL_EXP( data ) ( ( data[3] & 0x7ff0u ) >> 4 ) -#define _PDCLIB_DBL_SIZE( data ) ( data[3] &= 0x000fu, 4 ) - -/* Most platforms today use IEEE 754 single precision for 'float', and double */ -/* precision for 'double'. But type 'long double' varies. We use what the */ -/* compiler states about LDBL_MANT_DIG to determine the type. */ -#if _PDCLIB_LDBL_MANT_DIG == 64 - -/* Intel "Extended Precision" format, using 80 bits (64bit mantissa) */ -#define _PDCLIB_LDBL_SIGN( data ) ( ( data[4] & 0x8000u ) >> 15 ) -#define _PDCLIB_LDBL_EXP( data ) ( data[4] & 0x7fffu ) -#define _PDCLIB_LDBL_SIZE( data ) ( data[3] &= 0x7fffu, 4 ) - -#elif _PDCLIB_LDBL_MANT_DIG == 113 - -/* IEEE "Quadruple Precision" format, using 128 bits (113bit mantissa) */ -#define _PDCLIB_LDBL_SIGN( data ) ( ( data[7] & 0x8000u ) >> 15 ) -#define _PDCLIB_LDBL_EXP( data ) ( data[7] & 0x7fffu ) -#define _PDCLIB_LDBL_SIZE( data ) 7 - -#else - -/* IEEE "Double Precision" format, using 64 bits (53bit mantissa) */ -/* (Same as DBL above) */ -#define _PDCLIB_LDBL_SIGN( data ) ( ( data[3] & 0x8000 ) >> 15 ) -#define _PDCLIB_LDBL_EXP( data ) ( ( data[3] & 0x7ff0u ) >> 4 ) -#define _PDCLIB_LDBL_SIZE( data ) ( data[3] &= 0x000fu, 4 ) - -#endif - -/* Given the definitions for *_MANT_START above, which resolve to "pointer - to most dignificant byte of mantissa", the operand to use to get at the - less significant bytes. (That would be - for i386, x86_64, and ARM.) -*/ -#define _PDCLIB_FLT_OP - - -/* -------------------------------------------------------------------------- */ -/* Big Integer Arithmetic */ -/* -------------------------------------------------------------------------- */ -/* In support of the floating point converstions required by printf() etc., */ -/* PDCLib provides rudimentary big integer arithmetics. The _PDCLIB_bigint_t */ -/* type stores values in a sequence of integer "digits", which may be of any */ -/* uint_leastN_t type with N being 32 or 16. Note that multiplication and */ -/* division require the help of the next larger type. So set the define to */ -/* 32 if efficient 64bit integer arithmetics are available on your platform, */ -/* and to 16 otherwise. */ -/* (The value range of _PDCLIB_bigint_t is not affected by this setting.) */ - -#define _PDCLIB_BIGINT_DIGIT_BITS 16 - -/* -------------------------------------------------------------------------- */ -/* Platform-dependent macros defined by the standard headers. */ -/* -------------------------------------------------------------------------- */ - -/* The offsetof macro */ -/* Contract: Expand to an integer constant expression of type size_t, which */ -/* represents the offset in bytes to the structure member from the beginning */ -/* of the structure. If the specified member is a bitfield, behaviour is */ -/* undefined. */ -/* There is no standard-compliant way to do this. */ -/* This implementation casts an integer zero to 'pointer to type', and then */ -/* takes the address of member. This is undefined behaviour but should work */ -/* on most compilers. */ -#define _PDCLIB_offsetof( type, member ) ( (size_t) &( ( (type *) 0 )->member ) ) - -/* Variable Length Parameter List Handling () */ -/* The macros defined by are highly dependent on the calling */ -/* conventions used, and you probably have to replace them with builtins of */ -/* your compiler. */ - -#if defined( __i386 ) - -/* The following generic implementation works only for pure stack-based */ -/* architectures, and only if arguments are aligned to pointer type. Credits */ -/* to Michael Moody, who contributed this to the Public Domain. */ - -/* Internal helper macro. va_round is not part of . */ -#define _PDCLIB_va_round( type ) ( (sizeof(type) + sizeof(void *) - 1) & ~(sizeof(void *) - 1) ) - -typedef char * _PDCLIB_va_list; -#define _PDCLIB_va_arg( ap, type ) ( (ap) += (_PDCLIB_va_round(type)), ( *(type*) ( (ap) - (_PDCLIB_va_round(type)) ) ) ) -#define _PDCLIB_va_copy( dest, src ) ( (dest) = (src), (void)0 ) -#define _PDCLIB_va_end( ap ) ( (ap) = (void *)0, (void)0 ) -#define _PDCLIB_va_start( ap, parmN ) ( (ap) = (char *) &parmN + ( _PDCLIB_va_round(parmN) ), (void)0 ) - -#elif defined( __x86_64 ) || defined( __arm__ ) || defined( __ARM_NEON ) - -/* No way to cover x86_64 or arm with a generic implementation, as it uses */ -/* register-based parameter passing. Using compiler builtins here. */ -typedef __builtin_va_list _PDCLIB_va_list; -#define _PDCLIB_va_arg( ap, type ) ( __builtin_va_arg( ap, type ) ) -#define _PDCLIB_va_copy( dest, src ) ( __builtin_va_copy( dest, src ) ) -#define _PDCLIB_va_end( ap ) ( __builtin_va_end( ap ) ) -#define _PDCLIB_va_start( ap, parmN ) ( __builtin_va_start( ap, parmN ) ) - -#else - -#error Please create your own _PDCLIB_config.h. Using the existing one as-is will not work. (Unsupported varargs.) - -#endif - -/* -------------------------------------------------------------------------- */ -/* OS "glue", part 1 */ -/* These are values and data type definitions that you would have to adapt to */ -/* the capabilities and requirements of your OS. */ -/* The actual *functions* of the OS interface are declared in _PDCLIB_glue.h. */ -/* -------------------------------------------------------------------------- */ - -/* I/O ---------------------------------------------------------------------- */ - -/* The type of the file descriptor returned by _PDCLIB_open(), i.e. whatever */ -/* the underlying kernel uses for stream identification. */ -typedef int _PDCLIB_fd_t; - -/* The value of type _PDCLIB_fd_t returned by _PDCLIB_open() if the operation */ -/* failed. */ -#define _PDCLIB_NOHANDLE ( (_PDCLIB_fd_t) -1 ) - -/* The default size for file buffers. Must be at least 256. */ -#define _PDCLIB_BUFSIZ 1024 - -/* The minimum number of files the implementation guarantees can opened */ -/* simultaneously. Must be at least 8. Depends largely on how the platform */ -/* does the bookkeeping in whatever is called by _PDCLIB_open(). PDCLib puts */ -/* no further limits on the number of open files other than available memory. */ -#define _PDCLIB_FOPEN_MAX 8 - -/* Length of the longest filename the implementation guarantees to support. */ -#define _PDCLIB_FILENAME_MAX 128 - -/* Maximum length of filenames generated by tmpnam(). (See tmpfile.c.) */ -#define _PDCLIB_L_tmpnam 52 - -/* Number of distinct file names that can be generated by tmpnam(). */ -#define _PDCLIB_TMP_MAX 50 - -/* The values of SEEK_SET, SEEK_CUR and SEEK_END, used by fseek(). */ -/* Since at least one platform (POSIX) uses the same symbols for its own */ -/* "seek" function, you should use whatever the host defines (if it does */ -/* define them). */ -#define _PDCLIB_SEEK_SET 0 -#define _PDCLIB_SEEK_CUR 1 -#define _PDCLIB_SEEK_END 2 - -/* The number of characters that can be buffered with ungetc(). The standard */ -/* guarantees only one (1); PDCLib supports larger values, but applications */ -/* relying on this would rely on implementation-defined behaviour (not good). */ -#define _PDCLIB_UNGETCBUFSIZE 1 - -/* The number of functions that can be registered with atexit(). Needs to be */ -/* at least 33 (32 guaranteed by the standard, plus _PDCLIB_closeall() which */ -/* is used internally by PDCLib to close all open streams). */ -/* TODO: Should expand dynamically. */ -#define _PDCLIB_ATEXIT_SLOTS 40 - -/* errno -------------------------------------------------------------------- */ - -/* These are the values that _PDCLIB_errno can be set to by the library. */ -/* */ -/* By keeping PDCLib's errno in the _PDCLIB_* namespace, the library is */ -/* capable of "translating" between errno values used by the hosting OS and */ -/* those used and passed out by the library. */ -/* */ -/* Example: In the example platform, the remove() function uses the unlink() */ -/* system call as backend. Linux sets its errno to EISDIR if you try to */ -/* unlink() a directory, but POSIX demands EPERM. Within the remove() */ -/* function, you can catch 'errno == EISDIR', and set '*_PDCLIB_errno_func() */ -/* = _PDCLIB_EPERM'. Anyone using PDCLib's will "see" EPERM instead */ -/* of EISDIR. */ -/* */ -/* If you do not want that kind of translation, you might want to "match" the */ -/* values used by PDCLib with those used by the host OS, to avoid confusion. */ -/* auxiliary/errno/errno_readout.c provides a convenience program to read */ -/* those errno values mandated by the standard from a platform's , */ -/* giving output that can readily be pasted here. */ -/* Either way, note that the list below, the list in PDCLib's , and */ -/* the list in _PDCLIB_stdinit.h, need to be kept in sync. */ -/* */ -/* The values below are read from a Linux system. */ - -/* Argument list too long */ -#define _PDCLIB_E2BIG 7 -/* Permission denied */ -#define _PDCLIB_EACCES 13 -/* Address in use */ -#define _PDCLIB_EADDRINUSE 98 -/* Address not available */ -#define _PDCLIB_EADDRNOTAVAIL 99 -/* Address family not supported */ -#define _PDCLIB_EAFNOSUPPORT 97 -/* Resource unavailable, try again */ -#define _PDCLIB_EAGAIN 11 -/* Connection already in progress */ -#define _PDCLIB_EALREADY 114 -/* Bad file descriptor */ -#define _PDCLIB_EBADF 9 -/* Bad message */ -#define _PDCLIB_EBADMSG 74 -/* Device or resource busy */ -#define _PDCLIB_EBUSY 16 -/* Operation canceled */ -#define _PDCLIB_ECANCELED 125 -/* No child processes */ -#define _PDCLIB_ECHILD 10 -/* Connection aborted */ -#define _PDCLIB_ECONNABORTED 103 -/* Connection refused */ -#define _PDCLIB_ECONNREFUSED 111 -/* Connection reset */ -#define _PDCLIB_ECONNRESET 104 -/* Resource deadlock would occur */ -#define _PDCLIB_EDEADLK 35 -/* Destination address required */ -#define _PDCLIB_EDESTADDRREQ 89 -/* Mathematics argument out of domain of function */ -#define _PDCLIB_EDOM 33 -/* File exists */ -#define _PDCLIB_EEXIST 17 -/* Bad address */ -#define _PDCLIB_EFAULT 14 -/* File too large */ -#define _PDCLIB_EFBIG 27 -/* Host is unreachable */ -#define _PDCLIB_EHOSTUNREACH 113 -/* Identifier removed */ -#define _PDCLIB_EIDRM 43 -/* Illegal byte sequence */ -#define _PDCLIB_EILSEQ 84 -/* Operation in progress */ -#define _PDCLIB_EINPROGRESS 115 -/* Interrupted function */ -#define _PDCLIB_EINTR 4 -/* Invalid argument */ -#define _PDCLIB_EINVAL 22 -/* I/O error */ -#define _PDCLIB_EIO 5 -/* Socket is connected */ -#define _PDCLIB_EISCONN 106 -/* Is a directory */ -#define _PDCLIB_EISDIR 21 -/* Too many levels of symbolic links */ -#define _PDCLIB_ELOOP 40 -/* File descriptor value too large */ -#define _PDCLIB_EMFILE 24 -/* Too many links */ -#define _PDCLIB_EMLINK 31 -/* Message too large */ -#define _PDCLIB_EMSGSIZE 90 -/* Filename too long */ -#define _PDCLIB_ENAMETOOLONG 36 -/* Network is down */ -#define _PDCLIB_ENETDOWN 100 -/* Connection aborted by network */ -#define _PDCLIB_ENETRESET 102 -/* Network unreachable */ -#define _PDCLIB_ENETUNREACH 101 -/* Too many files open in system */ -#define _PDCLIB_ENFILE 23 -/* No buffer space available */ -#define _PDCLIB_ENOBUFS 105 -/* No message is available on the STREAM head read queue */ -#define _PDCLIB_ENODATA 61 -/* No such device */ -#define _PDCLIB_ENODEV 19 -/* No such file or directory */ -#define _PDCLIB_ENOENT 2 -/* Executable file format error */ -#define _PDCLIB_ENOEXEC 8 -/* No locks available */ -#define _PDCLIB_ENOLCK 37 -/* Link has been severed */ -#define _PDCLIB_ENOLINK 67 -/* Not enough space */ -#define _PDCLIB_ENOMEM 12 -/* No message of the desired type */ -#define _PDCLIB_ENOMSG 42 -/* Protocol not available */ -#define _PDCLIB_ENOPROTOOPT 92 -/* No space left on device */ -#define _PDCLIB_ENOSPC 28 -/* No STREAM resources */ -#define _PDCLIB_ENOSR 63 -/* Not a STREAM */ -#define _PDCLIB_ENOSTR 60 -/* Function not supported */ -#define _PDCLIB_ENOSYS 38 -/* The socket is not connected */ -#define _PDCLIB_ENOTCONN 107 -/* Not a directory */ -#define _PDCLIB_ENOTDIR 20 -/* Directory not empty */ -#define _PDCLIB_ENOTEMPTY 39 -/* State not recoverable */ -#define _PDCLIB_ENOTRECOVERABLE 131 -/* Not a socket */ -#define _PDCLIB_ENOTSOCK 88 -/* Not supported */ -#define _PDCLIB_ENOTSUP 95 -/* Inappropriate I/O control operation */ -#define _PDCLIB_ENOTTY 25 -/* No such device or address */ -#define _PDCLIB_ENXIO 6 -/* Operation not supported on socket */ -#define _PDCLIB_EOPNOTSUPP 95 -/* Value too large to be stored in data type */ -#define _PDCLIB_EOVERFLOW 75 -/* Previous owner died */ -#define _PDCLIB_EOWNERDEAD 130 -/* Operation not permitted */ -#define _PDCLIB_EPERM 1 -/* Broken pipe */ -#define _PDCLIB_EPIPE 32 -/* Protocol error */ -#define _PDCLIB_EPROTO 71 -/* Protocol not supported */ -#define _PDCLIB_EPROTONOSUPPORT 93 -/* Protocol wrong type for socket */ -#define _PDCLIB_EPROTOTYPE 91 -/* Result too large */ -#define _PDCLIB_ERANGE 34 -/* Read-only file system */ -#define _PDCLIB_EROFS 30 -/* Invalid seek */ -#define _PDCLIB_ESPIPE 29 -/* No such process */ -#define _PDCLIB_ESRCH 3 -/* Stream ioctl() timeout */ -#define _PDCLIB_ETIME 62 -/* Connection timed out */ -#define _PDCLIB_ETIMEDOUT 110 -/* Text file busy */ -#define _PDCLIB_ETXTBSY 26 -/* Operation would block */ -#define _PDCLIB_EWOULDBLOCK 11 -/* Cross-device link */ -#define _PDCLIB_EXDEV 18 - -/* The highest defined errno value, plus one. This is used to set the size */ -/* of the array in struct _PDCLIB_lc_text_t holding error messages for the */ -/* strerror() and perror() functions. (If you change this value because you */ -/* are using additional errno values, you *HAVE* to provide appropriate error */ -/* messages for *ALL* locales.) */ -#define _PDCLIB_ERRNO_MAX 132 - -/* The error message used for unknown error codes (generated by errno_readout */ -/* for consistency between the 'holes' in the list of defined error messages */ -/* and the text generated by e.g. strerror() for out-of-range error values.) */ -#define _PDCLIB_EUNKNOWN_TEXT (char*)"unknown error" - -/* locale data -------------------------------------------------------------- */ - -/* The default path where PDCLib should look for its locale data. */ -/* Must end with the appropriate separator character. */ -#define _PDCLIB_LOCALE_PATH "/usr/share/pdclib/i18n/" - -/* The name of the environment variable that can be used to override that */ -/* path setting. */ -#define _PDCLIB_LOCALE_PATH_ENV PDCLIB_I18N - -#ifdef __CYGWIN__ -typedef unsigned int wint_t; -#endif - -/* threads ------------------------------------------------------------------ */ - -/* This is relying on underlying implementation to provide thread */ -/* support. */ -/* The problem here is we cannot just #include and access the */ -/* original definitions. The standard library must not drag identifiers into */ -/* the user's namespace, so we have to set our own definitions in the _PDCLIB */ -/* namespace. Which are, obviously, platform-specific. */ -/* If you do NOT want to provide threads support, define __STDC_NO_THREADS__ */ -/* to 1 and simply delete the threads.h header and the corresponding files in */ -/* functions/threads/. This makes PDCLib non-thread-safe (obviously), as the */ -/* safeguards against race conditions (e.g. in ) will be omitted. */ - -/* auxiliary/pthread/pthread_readout.c provides a convenience program to read */ -/* appropriate definitions from a platform's , giving output that */ -/* can be copy & pasted here. */ - -#define __STDC_NO_THREADS__ - -#ifndef __STDC_NO_THREADS__ - -typedef unsigned long int _PDCLIB_thrd_t; -typedef union { unsigned char _PDCLIB_cnd_t_data[ 48 ]; long long int _PDCLIB_cnd_t_align; } _PDCLIB_cnd_t; -#if defined( __arm__ ) || defined( __ARM_NEON ) -typedef union { unsigned char _PDCLIB_mtx_t_data[ 24 ]; long int _PDCLIB_mtx_t_align; } _PDCLIB_mtx_t; -#else -typedef union { unsigned char _PDCLIB_mtx_t_data[ 40 ]; long int _PDCLIB_mtx_t_align; } _PDCLIB_mtx_t; -#endif -typedef unsigned int _PDCLIB_tss_t; -typedef int _PDCLIB_once_flag; -#define _PDCLIB_ONCE_FLAG_INIT 0 -#define _PDCLIB_RECURSIVE_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER -/* This one is actually hidden in , and only if __USE_POSIX is */ -/* defined prior to #include (PTHREAD_DESTRUCTOR_ITERATIONS). */ -#define _PDCLIB_TSS_DTOR_ITERATIONS 4 -/* The following are not made public in any header, but used internally for */ -/* interfacing with the pthread API. */ -typedef union { unsigned char _PDCLIB_cnd_attr_t_data[ 4 ]; int _PDCLIB_cnd_attr_t_align; } _PDCLIB_cnd_attr_t; -typedef union { unsigned char _PDCLIB_mtx_attr_t_data[ 4 ]; int _PDCLIB_mtx_attr_t_align; } _PDCLIB_mtx_attr_t; -#if defined( __arm__ ) || defined( __ARM_NEON ) -typedef union { unsigned char _PDCLIB_thrd_attr_t_data[ 36 ]; long int _PDCLIB_thrd_attr_t_align; } _PDCLIB_thrd_attr_t; -#else -typedef union { unsigned char _PDCLIB_thrd_attr_t_data[ 56 ]; long int _PDCLIB_thrd_attr_t_align; } _PDCLIB_thrd_attr_t; -#endif -/* Static initialization of recursive mutex. */ -#if defined( __arm__ ) || defined( __ARM_NEON ) -#define _PDCLIB_MTX_RECURSIVE_INIT { {\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } -/* Static initialization of plain / timeout mutex (identical with pthread). */ -#define _PDCLIB_MTX_PLAIN_INIT { {\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } -#else -#define _PDCLIB_MTX_RECURSIVE_INIT { {\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } -/* Static initialization of plain / timeout mutex (identical with pthread). */ -#define _PDCLIB_MTX_PLAIN_INIT { {\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\ - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } } -#endif - -#endif - -/* Termux defines atexit in crtbegin_so.o leading to a multiple definition */ -/* error from the linker. This is a crude workaround, which does NOT fix */ -/* various run-time issues on Termux likely also related to crt linkage. But */ -/* at least things compile OK, and SOME tests can be run. */ -#if defined( __ARM_NEON ) -#define atexit _PDCLIB_atexit -#endif - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_defguard.h b/rocklibc/include/pdclib/_PDCLIB_defguard.h deleted file mode 100644 index cd51abe..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_defguard.h +++ /dev/null @@ -1,29 +0,0 @@ -/* Definition guard <_PDCLIB_defguard.h> - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_DEFGUARD_H -#define _PDCLIB_DEFGUARD_H _PDCLIB_DEFGUARD_H - -#if defined( __ANDROID__ ) -/* typedef sigset_t */ -#include "bits/signal_types.h" -#endif - -/* Linux defines its own version of struct timespec (from ) in - some internal header (depending on clib implementation), which leads - to problems when accessing e.g. sys/time.h (type redefinition). - The solution is to set the Linux header's include guard (to avoid - Linux' definition), and to include PDCLib's to define the - type unambiguously. -*/ - -#define _TIMESPEC_DEFINED -#define _SYS__TIMESPEC_H_ -#define _STRUCT_TIMESPEC - -#include - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_glue.h b/rocklibc/include/pdclib/_PDCLIB_glue.h deleted file mode 100644 index 3e59302..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_glue.h +++ /dev/null @@ -1,93 +0,0 @@ -/* OS glue functions declaration <_PDCLIB_glue.h> - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_GLUE_H -#define _PDCLIB_GLUE_H _PDCLIB_GLUE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -/* -------------------------------------------------------------------------- */ -/* OS "glue", part 2 */ -/* These are the functions you will have to touch, as they are where PDCLib */ -/* interfaces with the operating system. */ -/* They operate on data types partially defined by _PDCLIB_config.h. */ -/* -------------------------------------------------------------------------- */ - -/* stdlib.h */ - -/* A system call that terminates the calling process, returning a given status - to the environment. -*/ -_PDCLIB_LOCAL _PDCLIB_Noreturn void _PDCLIB_Exit( int status ) _PDCLIB_NORETURN; - - -/* stdio.h */ - -/* A system call that opens a file identified by name in a given mode. Return - a file descriptor uniquely identifying that file. - (The mode is the return value of the _PDCLIB_filemode() function.) -*/ -_PDCLIB_LOCAL _PDCLIB_fd_t _PDCLIB_open( const char * const filename, unsigned int mode ); - -/* A system call that writes a stream's buffer. - Returns 0 on success, EOF on write error. - Sets stream error flags and errno appropriately on error. -*/ -_PDCLIB_LOCAL int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ); - -/* A system call that fills a stream's buffer. - Returns 0 on success, EOF on read error / EOF. - Sets stream EOF / error flags and errno appropriately on error. -*/ -_PDCLIB_LOCAL int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ); - -/* A system call that repositions within a file. Returns new offset on success, - -1 / errno on error. -*/ -_PDCLIB_LOCAL _PDCLIB_int_least64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int_least64_t offset, int whence ); - -/* A system call that closes a file identified by given file descriptor. Return - zero on success, non-zero otherwise. -*/ -_PDCLIB_LOCAL int _PDCLIB_close( _PDCLIB_fd_t fd ); - -/* A system call that changes the mode of a given stream to that passed as - argument (the argument being the value returned by _PDCLIB_filemode()), - *without* closing the stream. See comments in example implementation - for details. Return zero if the requested mode change is not supported - for this stream and freopen() should try to close and reopen the stream; - return INT_MIN if the change is not supported and freopen() should close - and NOT try to close / reopen (i.e., fail). Return any other value on - success. -*/ -_PDCLIB_LOCAL int _PDCLIB_changemode( struct _PDCLIB_file_t * stream, unsigned int mode ); - -/* A system call that returns a canonicalized absolute filename in - dynamically allocated memory, or NULL if the file does not exist. -*/ -_PDCLIB_LOCAL char * _PDCLIB_realpath( const char * path ); - -/* A system call that removes a file. Return zero on success, non-zero - otherwise. -*/ -_PDCLIB_LOCAL int _PDCLIB_remove( const char * pathname ); - -/* A system call that renames a file from given old name to given new name. - Return zero on success, non-zero otherwise. In case of failure, the file - must still be accessible by old name. Any handling of open files etc. is - done by standard rename() already. -*/ -_PDCLIB_LOCAL int _PDCLIB_rename( const char * oldpath, const char * newpath ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_internal.h b/rocklibc/include/pdclib/_PDCLIB_internal.h deleted file mode 100644 index 1ad3c66..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_internal.h +++ /dev/null @@ -1,686 +0,0 @@ -/* PDCLib internal logic <_PDCLIB_internal.h> - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_INTERNAL_H -#define _PDCLIB_INTERNAL_H _PDCLIB_INTERNAL_H - -#ifdef __cplusplus -extern "C" { -#endif - -/* -------------------------------------------------------------------------- */ -/* You should not have to edit anything in this file; if you DO have to, it */ -/* would be considered a bug / missing feature: notify the author(s). */ -/* -------------------------------------------------------------------------- */ - -#include "pdclib/_PDCLIB_config.h" - -/* -------------------------------------------------------------------------- */ -/* Standard Version */ -/* -------------------------------------------------------------------------- */ - -/* Many a compiler gets this wrong, so you might have to hardcode it instead. */ - -#if __STDC__ != 1 -#error Compiler does not define _ _STDC_ _ to 1 (not standard-compliant)! -#endif - -#ifndef __STDC_HOSTED__ -#error Compiler does not define _ _STDC_HOSTED_ _ (not standard-compliant)! -#elif __STDC_HOSTED__ != 0 && __STDC_HOSTED__ != 1 -#error Compiler does not define _ _STDC_HOSTED_ _ to 0 or 1 (not standard-compliant)! -#endif - -/* null pointer constant -- ((void *)0) in C, 0 in C++98, nullptr since C++11 */ -#ifdef __cplusplus -#if __cplusplus >= 201103L -#define _PDCLIB_NULL nullptr -#else -#define _PDCLIB_NULL 0 -#endif -#else -#define _PDCLIB_NULL ((void *)0) -#endif - -/* restrict / inline enabled for C99 onward only */ -#if defined( __cplusplus ) || ! defined( __STDC_VERSION ) || __STDC_VERSION__ < 199901L -#define _PDCLIB_restrict -#define _PDCLIB_inline -#else -#define _PDCLIB_restrict restrict -#define _PDCLIB_inline inline -#endif - -/* noreturn enabled for C11 onward only */ -#if defined( __cplusplus ) && __cplusplus >= 201103L -#define _PDCLIB_Noreturn [[noreturn]] -#else -#if defined( __STDC_VERSION__ ) >= 201112L -#define _PDCLIB_Noreturn _Noreturn -#else -#define _PDCLIB_Noreturn -#endif -#endif - -/* -------------------------------------------------------------------------- */ -/* Helper macros: */ -/* */ -/* (defined in _PDCLIB_config.h) */ -/* _PDCLIB_cc( x, y ) concatenates two preprocessor tokens without extending. */ -/* _PDCLIB_concat( x, y ) concatenates two preprocessor tokens with extending */ -/* */ -/* (defined below) */ -/* _PDCLIB_static_assert( e, m ) does a compile-time assertion of expression */ -/* e, with m as the failure message. */ -/* _PDCLIB_symbol2string( x ) turn symbol into string literal (by adding ""). */ -/* _PDCLIB_value2string( x ) expands a preprocessor token and turns it into a */ -/* string literal (by adding ""). */ -/* _PDCLIB_TYPE_SIGNED( type ) resolves to true if type is signed. */ -/* _PDCLIB_LOCK( mtx ) lock a mutex if library has threads support. */ -/* _PDCLIB_UNLOCK( mtx ) unlock a mutex if library has threads support. */ -/* _PDCLIB_CONSTRAINT_VIOLATION( e ) expand errno number e to parameter list */ -/* fit for Annex K constraint violation */ -/* handler. */ -/* _PDCLIB_Generic( f, fp ) expand to _PDCLIB_f, _PDCLIB_ff, _PDCLIB_fl */ -/* depending on fp being sizeof double, float, or */ -/* long double. */ -/* -------------------------------------------------------------------------- */ - -#define _PDCLIB_static_assert( e, m ) enum { _PDCLIB_concat( _PDCLIB_assert_, __LINE__ ) = 1 / ( !!(e) ) } - -#define _PDCLIB_TYPE_SIGNED( type ) (((type) -1) < 0) - -#define _PDCLIB_symbol2string( x ) #x -#define _PDCLIB_value2string( x ) _PDCLIB_symbol2string( x ) - -#ifndef __STDC_NO_THREADS__ -#define _PDCLIB_LOCK( mtx ) mtx_lock( &mtx ) -#define _PDCLIB_UNLOCK( mtx ) mtx_unlock( &mtx ) -#else -#define _PDCLIB_LOCK( mtx ) -#define _PDCLIB_UNLOCK( mtx ) -#endif - -#define _PDCLIB_CONSTRAINT_VIOLATION( e ) _PDCLIB_lc_messages->errno_texts[e], NULL, e - -#define _PDCLIB_GETC( fh ) ( ( fh->ungetidx == 0 ) ? ( unsigned char )fh->buffer[ fh->bufidx++ ] : ( unsigned char )fh->ungetbuf[ --fh->ungetidx ] ) - -#define _PDCLIB_CHECKBUFFER( fh ) ( ( ( fh->bufidx == fh->bufend ) && ( fh->ungetidx == 0 ) ) ? _PDCLIB_fillbuffer( fh ) : 0 ) - -#define _PDCLIB_GENERIC( func, x ) ( ( sizeof( x ) == sizeof( double ) ) ? _PDCLIB_ ## func ## d( x ) : \ - ( sizeof( x ) == sizeof( float ) ) ? _PDCLIB_ ## func ## f( x ) : \ - ( _PDCLIB_ ## func ## l( x ) ) ) - -/* -------------------------------------------------------------------------- */ -/* Preparing the length modifiers used in . */ -/* -------------------------------------------------------------------------- */ - -/* We use the _MAX value as a proxy for the actual type here. That is crude - but the best we can do, cross-platform wise. - Identifying which type the leastN_t / fastN_t / intmax_t / intptr_t are - and providing the appropriate printf()/scanf() length modifier. -*/ - -#if _PDCLIB_INT_FAST8_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_FAST8_PREFIX hh -#elif _PDCLIB_INT_FAST8_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_FAST8_PREFIX h -#elif _PDCLIB_INT_FAST8_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_FAST8_PREFIX -#elif _PDCLIB_INT_FAST8_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_FAST8_PREFIX l -#elif _PDCLIB_INT_FAST8_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_FAST8_PREFIX ll -#else -#error No matching native type for int_fast8_t. Please check your setup. -#endif - -#if _PDCLIB_INT_FAST16_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_FAST16_PREFIX hh -#elif _PDCLIB_INT_FAST16_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_FAST16_PREFIX h -#elif _PDCLIB_INT_FAST16_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_FAST16_PREFIX -#elif _PDCLIB_INT_FAST16_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_FAST16_PREFIX l -#elif _PDCLIB_INT_FAST16_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_FAST16_PREFIX ll -#else -#error No matching native type for int_fast16_t. Please check your setup. -#endif - -#if _PDCLIB_INT_FAST32_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_FAST32_PREFIX hh -#elif _PDCLIB_INT_FAST32_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_FAST32_PREFIX h -#elif _PDCLIB_INT_FAST32_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_FAST32_PREFIX -#elif _PDCLIB_INT_FAST32_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_FAST32_PREFIX l -#elif _PDCLIB_INT_FAST32_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_FAST32_PREFIX ll -#else -#error No matching native type for int_fast32_t. Please check your setup. -#endif - -#if _PDCLIB_INT_FAST64_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_FAST64_PREFIX hh -#elif _PDCLIB_INT_FAST64_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_FAST64_PREFIX h -#elif _PDCLIB_INT_FAST64_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_FAST64_PREFIX -#elif _PDCLIB_INT_FAST64_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_FAST64_PREFIX l -#elif _PDCLIB_INT_FAST64_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_FAST64_PREFIX ll -#else -#error No matching native type for int_fast64_t. Please check your setup. -#endif - -/* Many of the combinations below can very likely be ruled out logically. - All combinations are still listed for simplicity's sake (and to not fall - into the trap of false assumptions). -*/ - -#if _PDCLIB_INT_LEAST8_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_LEAST8_PREFIX hh -#elif _PDCLIB_INT_LEAST8_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_LEAST8_PREFIX h -#elif _PDCLIB_INT_LEAST8_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_LEAST8_PREFIX -#elif _PDCLIB_INT_LEAST8_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_LEAST8_PREFIX l -#elif _PDCLIB_INT_LEAST8_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_LEAST8_PREFIX ll -#else -#error No matching native type for int_least8_t. Please check your setup. -#endif - -#if _PDCLIB_INT_LEAST16_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_LEAST16_PREFIX hh -#elif _PDCLIB_INT_LEAST16_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_LEAST16_PREFIX h -#elif _PDCLIB_INT_LEAST16_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_LEAST16_PREFIX -#elif _PDCLIB_INT_LEAST16_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_LEAST16_PREFIX l -#elif _PDCLIB_INT_LEAST16_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_LEAST16_PREFIX ll -#else -#error No matching native type for int_least16_t. Please check your setup. -#endif - -#if _PDCLIB_INT_LEAST32_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_LEAST32_PREFIX hh -#elif _PDCLIB_INT_LEAST32_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_LEAST32_PREFIX h -#elif _PDCLIB_INT_LEAST32_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_LEAST32_PREFIX -#elif _PDCLIB_INT_LEAST32_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_LEAST32_PREFIX l -#elif _PDCLIB_INT_LEAST32_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_LEAST32_PREFIX ll -#else -#error No matching native type for int_least32_t. Please check your setup. -#endif - -#if _PDCLIB_INT_LEAST64_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INT_LEAST64_PREFIX hh -#elif _PDCLIB_INT_LEAST64_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INT_LEAST64_PREFIX h -#elif _PDCLIB_INT_LEAST64_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INT_LEAST64_PREFIX -#elif _PDCLIB_INT_LEAST64_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INT_LEAST64_PREFIX l -#elif _PDCLIB_INT_LEAST64_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INT_LEAST64_PREFIX ll -#else -#error No matching native type for int_least64_t. Please check your setup. -#endif - -#if _PDCLIB_INTMAX_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INTMAX_PREFIX hh -#elif _PDCLIB_INTMAX_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INTMAX_PREFIX h -#elif _PDCLIB_INTMAX_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INTMAX_PREFIX -#elif _PDCLIB_INTMAX_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INTMAX_PREFIX l -#elif _PDCLIB_INTMAX_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INTMAX_PREFIX ll -#else -#error No matching native type for intmax_t. Please check your setup. -#endif - -#if _PDCLIB_INTPTR_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_INTPTR_PREFIX hh -#elif _PDCLIB_INTPTR_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_INTPTR_PREFIX h -#elif _PDCLIB_INTPTR_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_INTPTR_PREFIX -#elif _PDCLIB_INTPTR_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_INTPTR_PREFIX l -#elif _PDCLIB_INTPTR_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_INTPTR_PREFIX ll -#else -#error No matching native type for intptr_t. Please check your setup. -#endif - -/* We might not have a type definition for sig_atomic_t at this point. The */ -/* clang compiler does not provide an appropriate predefine for it. So if we */ -/* do not have _PDCLIB_sig_atomic_t, identify the type trough its MAX value. */ - -#ifndef _PDCLIB_sig_atomic_t - -#if _PDCLIB_SIG_ATOMIC_MAX == _PDCLIB_SCHAR_MAX -#define _PDCLIB_sig_atomic_t char -#elif _PDCLIB_SIG_ATOMIC_MAX == _PDCLIB_SHRT_MAX -#define _PDCLIB_sig_atomic_t short -#elif _PDCLIB_SIG_ATOMIC_MAX == _PDCLIB_INT_MAX -#define _PDCLIB_sig_atomic_t int -#elif _PDCLIB_SIG_ATOMIC_MAX == _PDCLIB_LONG_MAX -#define _PDCLIB_sig_atomic_t long -#elif _PDCLIB_SIG_ATOMIC_MAX == _PDCLIB_LLONG_MAX -#define _PDCLIB_sig_atomic_t long long -#else -#error No matching native type for sig_atomic_t. Please check your setup. -#endif - -#endif - -/* -------------------------------------------------------------------------- */ -/* Various internals */ -/* -------------------------------------------------------------------------- */ - -/* Flags for representing mode (see fopen()). Note these must fit the same - status field as the _IO?BF flags in and the internal flags below. -*/ -#define _PDCLIB_FREAD (1u<<3) -#define _PDCLIB_FWRITE (1u<<4) -#define _PDCLIB_FAPPEND (1u<<5) -#define _PDCLIB_FRW (1u<<6) -#define _PDCLIB_FBIN (1u<<7) - -/* Internal flags, made to fit the same status field as the flags above. */ -/* -------------------------------------------------------------------------- */ -/* free() the buffer memory on closing (setvbuf()) */ -#define _PDCLIB_FREEBUFFER (1u<<8) -/* stream has encountered error / EOF */ -#define _PDCLIB_ERRORFLAG (1u<<9) -#define _PDCLIB_EOFFLAG (1u<<10) -/* stream is wide-oriented */ -#define _PDCLIB_WIDESTREAM (1u<<11) -/* stream is byte-oriented */ -#define _PDCLIB_BYTESTREAM (1u<<12) -/* file associated with stream should be remove()d on closing (tmpfile()) */ -#define _PDCLIB_DELONCLOSE (1u<<13) - -/* Position / status structure for getpos() / fsetpos(). */ -struct _PDCLIB_fpos_t -{ - _PDCLIB_uint_least64_t offset; /* File position offset */ - int status; /* Multibyte parsing state (unused, reserved) */ -}; - -/* FILE structure */ -struct _PDCLIB_file_t -{ - _PDCLIB_fd_t handle; /* OS file handle */ - char * buffer; /* Pointer to buffer memory */ - _PDCLIB_size_t bufsize; /* Size of buffer */ - _PDCLIB_size_t bufidx; /* Index of current position in buffer */ - _PDCLIB_size_t bufend; /* Index of last pre-read character in buffer */ - struct _PDCLIB_fpos_t pos; /* Offset and multibyte parsing state */ - _PDCLIB_size_t ungetidx; /* Number of ungetc()'ed characters */ - unsigned char ungetbuf[_PDCLIB_UNGETCBUFSIZE]; /* ungetc() buffer */ - unsigned int status; /* Status flags; see above */ - /* multibyte parsing status to be added later */ -#ifndef __STDC_NO_THREADS__ - _PDCLIB_mtx_t mtx; /* Multithreading safety */ -#endif - char * filename; /* Name the current stream has been opened with */ - struct _PDCLIB_file_t * next; /* Pointer to next struct (internal) */ -}; - -/* -------------------------------------------------------------------------- */ -/* Internal data types */ -/* -------------------------------------------------------------------------- */ - -/* Structure required by both atexit() and exit() for handling atexit functions */ -struct _PDCLIB_exitfunc_t -{ - struct _PDCLIB_exitfunc_t * next; - void ( *func )( void ); -}; - -/* Status structure required by _PDCLIB_print(). */ -struct _PDCLIB_status_t -{ - int base; /* base to which the value shall be converted */ - _PDCLIB_int_fast32_t flags; /* flags and length modifiers */ - _PDCLIB_size_t n; /* print: maximum characters to be written */ - /* scan: number matched conversion specifiers */ - _PDCLIB_size_t i; /* number of characters read/written */ - _PDCLIB_size_t current;/* chars read/written in the CURRENT conversion */ - char * s; /* *sprintf(): target buffer */ - /* *sscanf(): source string */ - _PDCLIB_size_t width; /* specified field width */ - int prec; /* specified field precision */ - struct _PDCLIB_file_t * stream; /* *fprintf() / *fscanf() stream */ - _PDCLIB_va_list arg; /* argument stack */ -}; - -/* -------------------------------------------------------------------------- */ -/* Declaration of helper functions (implemented in functions/_PDCLIB). */ -/* -------------------------------------------------------------------------- */ - -/* This is the main function called by atoi(), atol() and atoll(). */ -_PDCLIB_LOCAL _PDCLIB_intmax_t _PDCLIB_atomax( const char * s ); - -/* Two helper functions used by strtol(), strtoul() and long long variants. */ -_PDCLIB_LOCAL const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ); -_PDCLIB_LOCAL _PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, _PDCLIB_uintmax_t error, _PDCLIB_uintmax_t limit, char * sign ); - -/* Helper function used by strtof(), strtod(), and strtold(). */ -_PDCLIB_LOCAL int _PDCLIB_strtod_prelim( const char * p, char * sign, char ** endptr ); - -/* Digits arrays used by various integer conversion functions */ -extern const char _PDCLIB_digits[]; -extern const char _PDCLIB_Xdigits[]; - -/* The worker for all printf() type of functions. The pointer spec should point - to the introducing '%' of a conversion specifier. The status structure is to - be that of the current printf() function, of which the members n, s, stream - and arg will be preserved; i will be updated; and all others will be trashed - by the function. - Returns a pointer to the first character not parsed as conversion specifier. -*/ -_PDCLIB_LOCAL const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status ); - -/* The worker for all scanf() type of functions. The pointer spec should point - to the introducing '%' of a conversion specifier. The status structure is to - be that of the current scanf() function, of which the member stream will be - preserved; n, i, and s will be updated; and all others will be trashed by - the function. - Returns a pointer to the first character not parsed as conversion specifier, - or NULL in case of error. - FIXME: Should distinguish between matching and input error -*/ -_PDCLIB_LOCAL const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ); - -/* Parsing any fopen() style filemode string into a number of flags. */ -_PDCLIB_LOCAL unsigned int _PDCLIB_filemode( const char * mode ); - -/* Initialize a FILE structure. If the parameter is NULL, a new FILE structure - is malloc'ed. Returns a pointer to the stream if successful, NULL otherwise. -*/ -_PDCLIB_LOCAL struct _PDCLIB_file_t * _PDCLIB_init_file_t( struct _PDCLIB_file_t * stream ); - -/* Sanity checking and preparing of read buffer, should be called first thing - by any stdio read-data function. - Returns 0 on success, EOF on error. - On error, EOF / error flags and errno are set appropriately. -*/ -_PDCLIB_LOCAL int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ); - -/* Sanity checking, should be called first thing by any stdio write-data - function. - Returns 0 on success, EOF on error. - On error, error flags and errno are set appropriately. -*/ -_PDCLIB_LOCAL int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ); - -/* Closing all streams on program exit */ -_PDCLIB_LOCAL void _PDCLIB_closeall( void ); - -/* Check if a given year is a leap year. Parameter is offset to 1900. */ -_PDCLIB_LOCAL int _PDCLIB_is_leap( int year_offset ); - -/* Read a specified number of lines from a file stream; return a pointer to - allocated memory holding the lines (newlines replaced with zero terminators) - or NULL in case of error. -*/ -_PDCLIB_LOCAL char * _PDCLIB_load_lines( struct _PDCLIB_file_t * stream, _PDCLIB_size_t lines ); - -/* Returns the (locale dependent) error message associated with the argument - errno value. -*/ -_PDCLIB_LOCAL char * _PDCLIB_geterrtext( int errnum ); - -/* Returns non-zero if the given stream is on the internal list of open files, - zero otherwise. Sets the second paramenter (if not NULL) to the previous - stream on the list (or NULL if the given stream is the first on the list). - This function does not lock _PDCLIB_filelist_mtx, this needs to be done by - the calling function (_PDCLIB_getstream() or freopen()). -*/ -_PDCLIB_LOCAL int _PDCLIB_isstream( struct _PDCLIB_file_t * stream, struct _PDCLIB_file_t ** previous ); - -/* Removes the given stream from the internal list of open files. Returns zero - if successful, non-zero otherwise. In case of error, sets errno to EBADF. - This function does not lock _PDCLIB_filelist_mtx, this needs to be done by - the calling function (fclose()). -*/ -_PDCLIB_LOCAL int _PDCLIB_getstream( struct _PDCLIB_file_t * stream ); - -/* Backend for strtok and strtok_s (plus potential extensions like strtok_r). */ -_PDCLIB_LOCAL char * _PDCLIB_strtok( char * _PDCLIB_restrict s1, _PDCLIB_size_t * _PDCLIB_restrict s1max, const char * _PDCLIB_restrict s2, char ** _PDCLIB_restrict ptr ); - -/* Conversion of exponent notation to floating point */ -_PDCLIB_LOCAL long double _PDCLIB_naive_etod( const char * s, char ** endptr ); - -/* Conversion of hexadecimal notation to floating point */ -_PDCLIB_LOCAL long double _PDCLIB_naive_ptod( const char * s, char ** endptr ); - -/* -------------------------------------------------------------------------- */ -/* Declaration of math helper functions (implemented in functions/math). */ -/* -------------------------------------------------------------------------- */ - -int _PDCLIB_isnand( double x ); -int _PDCLIB_isnanf( float x ); -int _PDCLIB_isnanl( long double x ); - -int _PDCLIB_isinfd( double x ); -int _PDCLIB_isinff( float x ); -int _PDCLIB_isinfl( long double x ); - -int _PDCLIB_signbitd( double x ); -int _PDCLIB_signbitf( float x ); -int _PDCLIB_signbitl( long double x ); - -int _PDCLIB_isfinited( double x ); -int _PDCLIB_isfinitef( float x ); -int _PDCLIB_isfinitel( long double x ); - -int _PDCLIB_isnormald( double x ); -int _PDCLIB_isnormalf( float x ); -int _PDCLIB_isnormall( long double x ); - -int _PDCLIB_fpclassifyd( double x ); -int _PDCLIB_fpclassifyf( float x ); -int _PDCLIB_fpclassifyl( long double x ); - -/* -------------------------------------------------------------------------- */ -/* errno */ -/* -------------------------------------------------------------------------- */ - -/* A mechanism for delayed evaluation. - If PDCLib would call its error number "errno" directly, there would be no way - to catch its value from underlying system calls that also use it (i.e., POSIX - operating systems). That is why we use an internal name, providing a means to - access it through . -*/ -_PDCLIB_PUBLIC int * _PDCLIB_errno_func( void ); - -/* -------------------------------------------------------------------------- */ -/* support */ -/* -------------------------------------------------------------------------- */ - -#define _PDCLIB_LC_ALL 0 -#define _PDCLIB_LC_COLLATE 1 -#define _PDCLIB_LC_CTYPE 2 -#define _PDCLIB_LC_MONETARY 3 -#define _PDCLIB_LC_NUMERIC 4 -#define _PDCLIB_LC_TIME 5 -#define _PDCLIB_LC_MESSAGES 6 -#define _PDCLIB_LC_COUNT 7 - -#define _PDCLIB_CTYPE_ALPHA 1 -#define _PDCLIB_CTYPE_BLANK 2 -#define _PDCLIB_CTYPE_CNTRL 4 -#define _PDCLIB_CTYPE_GRAPH 8 -#define _PDCLIB_CTYPE_PUNCT 16 -#define _PDCLIB_CTYPE_SPACE 32 -#define _PDCLIB_CTYPE_LOWER 64 -#define _PDCLIB_CTYPE_UPPER 128 - -#define _PDCLIB_CHARSET_SIZE ( 1 << _PDCLIB_CHAR_BIT ) - -struct _PDCLIB_lc_lconv_numeric_t -{ - char * decimal_point; - char * thousands_sep; - char * grouping; -}; - -struct _PDCLIB_lc_lconv_monetary_t -{ - char * mon_decimal_point; - char * mon_thousands_sep; - char * mon_grouping; - char * positive_sign; - char * negative_sign; - char * currency_symbol; - char * int_curr_symbol; - char frac_digits; - char p_cs_precedes; - char n_cs_precedes; - char p_sep_by_space; - char n_sep_by_space; - char p_sign_posn; - char n_sign_posn; - char int_frac_digits; - char int_p_cs_precedes; - char int_n_cs_precedes; - char int_p_sep_by_space; - char int_n_sep_by_space; - char int_p_sign_posn; - char int_n_sign_posn; -}; - -struct _PDCLIB_lc_numeric_monetary_t -{ - struct lconv * lconv; - int numeric_alloced; - int monetary_alloced; -}; - -extern struct _PDCLIB_lc_numeric_monetary_t _PDCLIB_lc_numeric_monetary; - -struct _PDCLIB_lc_collate_t -{ - int alloced; - /* 1..3 code points */ - /* 1..8, 18 collation elements of 3 16-bit integers */ -}; - -extern struct _PDCLIB_lc_collate_t _PDCLIB_lc_collate_C; -extern struct _PDCLIB_lc_collate_t * _PDCLIB_lc_collate; - -/* One entry to the _PDCLIB_lc_ctype_t.entry data table */ -struct _PDCLIB_lc_ctype_entry_t -{ - _PDCLIB_uint_least16_t flags; /* Whether a character is of a given CTYPE */ - unsigned char upper; /* Result for toupper() */ - unsigned char lower; /* Result for tolower() */ -}; - -struct _PDCLIB_lc_ctype_t -{ - int alloced; /* .entry dynamically allocated? */ - int digits_low; /* Where decimal digits start */ - int digits_high; /* Where decimal digits end */ - int Xdigits_low; /* Where A..F start */ - int Xdigits_high; /* Where A..F end */ - int xdigits_low; /* Where a..f start */ - int xdigits_high; /* Where a..f end */ - struct _PDCLIB_lc_ctype_entry_t * entry; /* The data table */ -}; - -extern struct _PDCLIB_lc_ctype_t _PDCLIB_lc_ctype_C; -extern struct _PDCLIB_lc_ctype_t * _PDCLIB_lc_ctype; - -struct _PDCLIB_lc_messages_t -{ - int alloced; - char * errno_texts[_PDCLIB_ERRNO_MAX]; /* strerror() / perror() */ -}; - -extern struct _PDCLIB_lc_messages_t _PDCLIB_lc_messages_C; -extern struct _PDCLIB_lc_messages_t * _PDCLIB_lc_messages; - -struct _PDCLIB_lc_time_t -{ - int alloced; - char * month_name_abbr[12]; /* month names, abbreviated */ - char * month_name_full[12]; /* month names, full */ - char * day_name_abbr[7]; /* weekday names, abbreviated */ - char * day_name_full[7]; /* weekday names, full */ - char * date_time_format; /* date / time format for strftime( "%c" ) */ - char * time_format_12h; /* 12-hour time format for strftime( "%r" ) */ - char * date_format; /* date format for strftime( "%x" ) */ - char * time_format; /* time format for strftime( "%X" ) */ - char * am_pm[2]; /* AM / PM designation */ -}; - -extern struct _PDCLIB_lc_time_t _PDCLIB_lc_time_C; -extern struct _PDCLIB_lc_time_t * _PDCLIB_lc_time; - -_PDCLIB_LOCAL struct _PDCLIB_lc_lconv_numeric_t * _PDCLIB_load_lc_numeric( const char * path, const char * locale ); -_PDCLIB_LOCAL struct _PDCLIB_lc_lconv_monetary_t * _PDCLIB_load_lc_monetary( const char * path, const char * locale ); -_PDCLIB_LOCAL struct _PDCLIB_lc_collate_t * _PDCLIB_load_lc_collate( const char * path, const char * locale ); -_PDCLIB_LOCAL struct _PDCLIB_lc_ctype_t * _PDCLIB_load_lc_ctype( const char * path, const char * locale ); -_PDCLIB_LOCAL struct _PDCLIB_lc_time_t * _PDCLIB_load_lc_time( const char * path, const char * locale ); -_PDCLIB_LOCAL struct _PDCLIB_lc_messages_t * _PDCLIB_load_lc_messages( const char * path, const char * locale ); - -/* -------------------------------------------------------------------------- */ -/* Sanity checks */ -/* -------------------------------------------------------------------------- */ - -/* signed-ness of char */ -_PDCLIB_static_assert( _PDCLIB_CHAR_MIN == ((((char) -1) < 0) ? _PDCLIB_SCHAR_MIN : 0), "Compiler disagrees on signed-ness of 'char'." ); - -/* two's complement */ -#if _PDCLIB_TWOS_COMPLEMENT == 1 -#if _PDCLIB_CHAR_MIN < 0 -_PDCLIB_static_assert( ((char) ~ (char) 0 < 0), "Not two's complement on 'char'." ); -#endif -_PDCLIB_static_assert( ((short) ~ (short) 0 < 0), "Not two's complement on 'short'." ); -_PDCLIB_static_assert( ((int) ~ (int) 0 < 0), "Not two's complement on 'int'." ); -_PDCLIB_static_assert( ((long) ~ (long) 0 < 0), "Not two's complement on 'long'." ); -_PDCLIB_static_assert( ((long long) ~ (long long) 0 < 0), "Not two's complement on 'long long'." ); -#endif - -/* size_t as the result of sizeof */ -_PDCLIB_static_assert( sizeof( sizeof( int ) ) == sizeof( _PDCLIB_size_t ), "Compiler disagrees on size_t." ); - -/* wchar_t as the type of wide character literals */ -_PDCLIB_static_assert( sizeof( _PDCLIB_wchar_t ) == sizeof( L'x' ), "Compiler disagrees on wchar_t." ); -#ifdef __cplusplus -_PDCLIB_static_assert( sizeof( _PDCLIB_wchar_t ) == sizeof( wchar_t ), "Compiler disagrees on wchar_t (C++)." ); -#endif - -/* intptr_t/uintptr_t being wide enough to store the value of a pointer */ -_PDCLIB_static_assert( sizeof( void * ) == sizeof( _PDCLIB_intptr_t ), "Compiler disagrees on intptr_t." ); -_PDCLIB_static_assert( sizeof( void * ) == sizeof( _PDCLIB_uintptr_t ), "Compiler disagrees on uintptr_t." ); - -/* ptrdiff_t as the result of pointer arithmetic */ -_PDCLIB_static_assert( sizeof( &_PDCLIB_digits[1] - &_PDCLIB_digits[0] ) == sizeof( _PDCLIB_ptrdiff_t ), "Compiler disagrees on ptrdiff_t." ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_lib_ext1.h b/rocklibc/include/pdclib/_PDCLIB_lib_ext1.h deleted file mode 100644 index fe96bca..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_lib_ext1.h +++ /dev/null @@ -1,32 +0,0 @@ -/* __STDC_WANT_LIB_EXT1__ redefinition guard - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef __STDC_WANT_LIB_EXT1__ - #ifdef __STDC_WANT_LIB_EXT1_PREVIOUS__ - #if __STDC_WANT_LIB_EXT1_PREVIOUS__ != -1 - #error __STDC_WANT_LIB_EXT1__ undefined when it was defined earlier. - #endif - #else - #define __STDC_WANT_LIB_EXT1_PREVIOUS__ -1 - #endif -#else - #if ( __STDC_WANT_LIB_EXT1__ + 0 ) == 0 && ( 0 - __STDC_WANT_LIB_EXT1__ - 1 ) == 1 - #error __STDC_WANT_LIB_EXT1__ defined but empty. Should be an integer value. - #endif - #ifdef __STDC_WANT_LIB_EXT1_PREVIOUS__ - #if ( __STDC_WANT_LIB_EXT1__ + 0 ) != __STDC_WANT_LIB_EXT1_PREVIOUS__ - #error __STDC_WANT_LIB_EXT1__ redefined from previous value. - #endif - #else - #if ( __STDC_WANT_LIB_EXT1__ + 0 ) == 0 - #define __STDC_WANT_LIB_EXT1_PREVIOUS__ 0 - #elif ( __STDC_WANT_LIB_EXT1__ + 0 ) == 1 - #define __STDC_WANT_LIB_EXT1_PREVIOUS__ 1 - #else - #error __STDC_WANT_LIB_EXT1__ set to value other than 0,1 -- undefined behavior - #endif - #endif -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_platform_errno.h b/rocklibc/include/pdclib/_PDCLIB_platform_errno.h deleted file mode 100644 index 04e4f3d..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_platform_errno.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _PDCLIB_PLATFORM_ERRNO -#define _PDCLIB_PLATFORM_ERRNO - -#include "errno.h" - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_platform_fcntl.h b/rocklibc/include/pdclib/_PDCLIB_platform_fcntl.h deleted file mode 100644 index 8c7c026..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_platform_fcntl.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef _PDCLIB_PLATFORM_FCNTL -#define _PDCLIB_PLATFORM_FCNTL - -#include "fcntl.h" - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_print.h b/rocklibc/include/pdclib/_PDCLIB_print.h deleted file mode 100644 index 015b0ff..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_print.h +++ /dev/null @@ -1,145 +0,0 @@ -/* PDCLib printf logic <_PDCLIB_print.h> - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_PRINT_H -#define _PDCLIB_PRINT_H _PDCLIB_PRINT_H - -#include "pdclib/_PDCLIB_internal.h" - -#include -#include -#include - -/* This macro delivers a given character to either a memory buffer or a stream, - depending on the contents of 'status' (struct _PDCLIB_status_t). - x - the character to be delivered - i - pointer to number of characters already delivered in this call - n - pointer to maximum number of characters to be delivered in this call - s - the buffer into which the character shall be delivered -*/ -#define PUT( x ) \ - do { \ - int character = x; \ - if ( status->i < status->n ) { \ - if ( status->stream != NULL ) \ - putc( character, status->stream ); \ - else \ - status->s[status->i] = character; \ - } \ - ++(status->i); \ - } while ( 0 ) - - -/* Using an integer's bits as flags for both the conversion flags and length - modifiers. -*/ -#define E_minus (INT32_C(1)<<0) -#define E_plus (INT32_C(1)<<1) -#define E_alt (INT32_C(1)<<2) -#define E_space (INT32_C(1)<<3) - -#define E_zero (INT32_C(1)<<4) -#define E_done (INT32_C(1)<<5) -#define E_char (INT32_C(1)<<6) -#define E_short (INT32_C(1)<<7) - -#define E_long (INT32_C(1)<<8) -#define E_llong (INT32_C(1)<<9) -#define E_intmax (INT32_C(1)<<10) -#define E_size (INT32_C(1)<<11) - -#define E_ptrdiff (INT32_C(1)<<12) -#define E_pointer (INT32_C(1)<<13) -#define E_double (INT32_C(1)<<14) -#define E_ldouble (INT32_C(1)<<15) - -#define E_lower (INT32_C(1)<<16) -#define E_unsigned (INT32_C(1)<<17) -#define E_decimal (INT32_C(1)<<18) -#define E_exponent (INT32_C(1)<<19) - -#define E_generic (INT32_C(1)<<20) -#define E_hexa (INT32_C(1)<<21) - -/* -------------------------------------------------------------------------- */ -/* _PDCLIB_bigint_t support (required for floating point conversions) */ -/* -------------------------------------------------------------------------- */ - -/* Must be divisible by 32. */ -/* 1120 is enough for 64bit floats. A 128 float takes 16544 bits. */ -#define _PDCLIB_BIGINT_BITS 1120 - -#if _PDCLIB_BIGINT_DIGIT_BITS == 32 -#define _PDCLIB_BIGINT_DIGIT_MAX _PDCLIB_UINT_LEAST32_C( 0xFFFFFFFF ) -typedef _PDCLIB_uint_least32_t _PDCLIB_bigint_digit_t; -typedef _PDCLIB_int_least32_t _PDCLIB_bigint_sdigit_t; -typedef _PDCLIB_uint_least64_t _PDCLIB_bigint_arith_t; -#elif _PDCLIB_BIGINT_DIGIT_BITS == 16 -#define _PDCLIB_BIGINT_DIGIT_MAX _PDCLIB_UINT_LEAST16_C( 0xFFFF ) -typedef _PDCLIB_uint_least16_t _PDCLIB_bigint_digit_t; -typedef _PDCLIB_int_least16_t _PDCLIB_bigint_sdigit_t; -typedef _PDCLIB_uint_least32_t _PDCLIB_bigint_arith_t; -#else -#error _PDCLIB_BIGINT_DIGIT_BITS.needs to be 16 or 32. -#endif - -/* How many "digits" a _PDCLIB_bigint_t holds. */ -#define _PDCLIB_BIGINT_DIGITS _PDCLIB_BIGINT_BITS / _PDCLIB_BIGINT_DIGIT_BITS - -/* Maximum number of characters needed for _PDCLIB_bigint_tostring() */ -#define _PDCLIB_BIGINT_CHARS ( _PDCLIB_BIGINT_BITS / 4 + _PDCLIB_BIGINT_DIGITS + 2 ) - -/* Type */ -/* ---- */ - -typedef struct -{ - /* Number of digits used; zero value == zero size */ - _PDCLIB_size_t size; - /* Least significant digit first */ - _PDCLIB_bigint_digit_t data[ _PDCLIB_BIGINT_DIGITS ]; -} _PDCLIB_bigint_t; - -typedef struct -{ - _PDCLIB_bigint_t mantissa; - _PDCLIB_int_least16_t exponent; - _PDCLIB_int_least16_t scale; - enum - { - _PDCLIB_FP_NORMAL, - _PDCLIB_FP_SUBNORMAL, - _PDCLIB_FP_INF, - _PDCLIB_FP_NAN - } state; - char sign; -} _PDCLIB_fp_t; - -void _PDCLIB_fp_from_dbl( _PDCLIB_fp_t * fp, double value ); -void _PDCLIB_fp_from_ldbl( _PDCLIB_fp_t * fp, long double value ); - -void _PDCLIB_bigint_from_digit( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_digit_t digit ); -void _PDCLIB_bigint_from_pow2( _PDCLIB_bigint_t * bigint, unsigned pow ); -void _PDCLIB_bigint_from_pow10( _PDCLIB_bigint_t * bigint, unsigned pow ); -void _PDCLIB_bigint_from_bigint( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ); -void _PDCLIB_bigint_add( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ); -void _PDCLIB_bigint_mul( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ); -void _PDCLIB_bigint_mul_pow10( _PDCLIB_bigint_t * bigint, int pow10 ); -int _PDCLIB_bigint_cmp( _PDCLIB_bigint_t const * lhs, _PDCLIB_bigint_t const * rhs ); -void _PDCLIB_bigint_shl( _PDCLIB_bigint_t * bigint, _PDCLIB_size_t bits ); -void _PDCLIB_bigint_mul10( _PDCLIB_bigint_t * bigint ); -int _PDCLIB_bigint_digit_log2( _PDCLIB_bigint_digit_t digit ); -int _PDCLIB_bigint_log2( _PDCLIB_bigint_t const * bigint ); -unsigned _PDCLIB_bigint_div( _PDCLIB_bigint_t * dividend, _PDCLIB_bigint_t const * divisor ); - -void _PDCLIB_print_integer( struct _PDCLIB_imaxdiv_t div, struct _PDCLIB_status_t * status ); -void _PDCLIB_print_string( const char * s, struct _PDCLIB_status_t * status ); -void _PDCLIB_print_fp( _PDCLIB_fp_t * fp, struct _PDCLIB_status_t * status ); -int _PDCLIB_print_fp_deci( _PDCLIB_fp_t * fp, struct _PDCLIB_status_t * status, char * buffer ); -void _PDCLIB_print_fp_hexa( _PDCLIB_fp_t * fp, struct _PDCLIB_status_t * status, char * buffer ); -void _PDCLIB_print_fp_dragon4( _PDCLIB_bigint_t * fp, struct _PDCLIB_status_t * status ); - -#endif diff --git a/rocklibc/include/pdclib/_PDCLIB_tzcode.h b/rocklibc/include/pdclib/_PDCLIB_tzcode.h deleted file mode 100644 index d12c4a7..0000000 --- a/rocklibc/include/pdclib/_PDCLIB_tzcode.h +++ /dev/null @@ -1,153 +0,0 @@ -/* TZ Code declarations and definitions <_PDCLIB_tzcode.h> - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_TZCODE_H -#define _PDCLIB_TZCODE_H _PDCLIB_TZCODE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include - -#include -#include -#include - -/* Handy macros that are independent of tzfile implementation. */ -#define YEARSPERREPEAT 400 /* years before a Gregorian repeat */ - -#define SECSPERMIN 60 -#define MINSPERHOUR 60 -#define HOURSPERDAY 24 -#define DAYSPERWEEK 7 -#define DAYSPERNYEAR 365 -#define DAYSPERLYEAR 366 -#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR) -#define SECSPERDAY ((int_fast32_t) SECSPERHOUR * HOURSPERDAY) -#define MONSPERYEAR 12 - -#define AVGSECSPERYEAR 31556952L -#define SECSPERREPEAT ((int_fast64_t) YEARSPERREPEAT * (int_fast64_t) AVGSECSPERYEAR) -#define SECSPERREPEAT_BITS 34 /* ceil(log2(SECSPERREPEAT)) */ - -#define TM_SUNDAY 0 -#define TM_MONDAY 1 -#define TM_TUESDAY 2 -#define TM_WEDNESDAY 3 -#define TM_THURSDAY 4 -#define TM_FRIDAY 5 -#define TM_SATURDAY 6 - -#define TM_YEAR_BASE 1900 - -#define EPOCH_YEAR 1970 -#define EPOCH_WDAY TM_THURSDAY - -extern struct tm _PDCLIB_tm; -extern int lcl_is_set; - -static const char gmt[] = "GMT"; - -static const int mon_lengths[ 2 ][ MONSPERYEAR ] = -{ - { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, - { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } -}; - -static const int year_lengths[2] = -{ - DAYSPERNYEAR, DAYSPERLYEAR -}; - -/* time type information */ -struct ttinfo -{ - int_fast32_t utoff; /* UT offset in seconds */ - bool isdst; /* used to set tm_isdst */ - int desigidx; /* abbreviation list index */ - bool ttisstd; /* transition is std time */ - bool ttisut; /* transition is UT */ -}; - -/* leap second information */ -struct lsinfo -{ - time_t trans; /* transition time */ - int_fast64_t corr; /* correction to apply */ -}; - -#define BIGGEST( a, b ) (((a) > (b)) ? (a) : (b)) - -#ifndef TZ_MAX_TIMES -#define TZ_MAX_TIMES 2000 -#endif - -#ifndef TZ_MAX_TYPES -/* This must be at least 17 for Europe/Vilnius. */ -/* Limited by what (unsigned char)s can hold */ -#define TZ_MAX_TYPES 256 -#endif - -#ifndef TZ_MAX_CHARS -/* Maximum number of abbreviation characters */ -/* Limited by what (unsigned char)s can hold */ -#define TZ_MAX_CHARS 50 -#endif - -#ifndef TZ_MAX_LEAPS -/* Maximum number of leap second corrections */ -#define TZ_MAX_LEAPS 50 -#endif - -#ifdef TZNAME_MAX -#define MY_TZNAME_MAX TZNAME_MAX -#else -#define MY_TZNAME_MAX 255 -#endif - -struct state -{ - int leapcnt; - int timecnt; - int typecnt; - int charcnt; - bool goback; - bool goahead; - time_t ats[ TZ_MAX_TIMES ]; - unsigned char types[ TZ_MAX_TIMES ]; - struct ttinfo ttis[ TZ_MAX_TYPES ]; - char chars[ BIGGEST( BIGGEST( TZ_MAX_CHARS + 1, sizeof gmt ), ( 2 * ( MY_TZNAME_MAX + 1 ) ) ) ]; - struct lsinfo lsis[ TZ_MAX_LEAPS ]; - - /* The time type to use for early times or if no transitions. - It is always zero for recent tzdb releases. - It might be nonzero for data from tzdb 2018e or earlier. - */ - int defaulttype; -}; - -extern struct state _PDCLIB_lclmem; -extern struct state _PDCLIB_gmtmem; - -void _PDCLIB_gmtcheck(void); -struct tm * _PDCLIB_gmtsub( struct state const * sp, time_t const * timep, int_fast32_t offset, struct tm * tmp ); -bool _PDCLIB_increment_overflow( int * ip, int j ); -void _PDCLIB_init_ttinfo( struct ttinfo * s, int_fast32_t utoff, bool isdst, int desigidx ); -struct tm * _PDCLIB_localsub( struct state const * sp, time_t const * timep, int_fast32_t setname, struct tm * const tmp ); -struct tm * _PDCLIB_localtime_tzset( time_t const * timep, struct tm * tmp, bool setname ); -time_t _PDCLIB_mktime_tzname( struct state * sp, struct tm * tmp, bool setname ); -struct tm * _PDCLIB_timesub( const time_t * timep, int_fast32_t offset, const struct state * sp, struct tm * tmp ); -int _PDCLIB_tzload( char const * name, struct state * sp, bool doextend ); -bool _PDCLIB_tzparse(char const *, struct state *, bool); -void _PDCLIB_tzset_unlocked( void ); -void _PDCLIB_update_tzname_etc( struct state const * sp, struct ttinfo const * ttisp ); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/signal.h b/rocklibc/include/signal.h deleted file mode 100644 index 1f679ec..0000000 --- a/rocklibc/include/signal.h +++ /dev/null @@ -1,91 +0,0 @@ -/* Signal handling - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_SIGNAL_H -#define _PDCLIB_SIGNAL_H _PDCLIB_SIGNAL_H - -#include "pdclib/_PDCLIB_internal.h" - -/* Signals ------------------------------------------------------------------ */ - -/* A word on signals, to the people using PDCLib in their OS projects. - - The definitions of the C standard leave about everything that *could* be - useful to be "implementation defined". Without additional, non-standard - arrangements, it is not possible to turn them into a useful tool. - - This example implementation chose to "not generate any of these signals, - except as a result of explicit calls to the raise function", which is - allowed by the standard but of course does nothing for the usefulness of - . - - A useful signal handling would: - 1) make signal() a system call that registers the signal handler with the OS - 2) make raise() a system call triggering an OS signal to the running process - 3) make provisions that further signals of the same type are blocked until - the signal handler returns (optional for SIGILL) -*/ - -/* These are the values used by Linux. */ - -/* Abnormal termination / abort() */ -#define SIGABRT 6 -/* Arithmetic exception / division by zero / overflow */ -#define SIGFPE 8 -/* Illegal instruction */ -#define SIGILL 4 -/* Interactive attention signal */ -#define SIGINT 2 -/* Invalid memory access */ -#define SIGSEGV 11 -/* Termination request */ -#define SIGTERM 15 - -/* The following should be defined to pointer values that could NEVER point to - a valid signal handler function. (They are used as special arguments to - signal().) Again, these are the values used by Linux. -*/ -#define SIG_DFL (void (*)( int ))0 -#define SIG_ERR (void (*)( int ))-1 -#define SIG_IGN (void (*)( int ))1 - -typedef _PDCLIB_sig_atomic_t sig_atomic_t; - -/* Installs a signal handler "func" for the given signal. - A signal handler is a function that takes an integer as argument (the signal - number) and returns void. - - Note that a signal handler can do very little else than: - 1) assign a value to a static object of type "volatile sig_atomic_t", - 2) call signal() with the value of sig equal to the signal received, - 3) call _Exit(), - 4) call abort(). - Virtually everything else is undefind. - - The signal() function returns the previous installed signal handler, which - at program start may be SIG_DFL or SIG_ILL. (This implementation uses - SIG_DFL for all handlers.) If the request cannot be honored, SIG_ERR is - returned and errno is set to an unspecified positive value. -*/ -_PDCLIB_PUBLIC void ( *signal( int sig, void ( *func )( int ) ) )( int ); - -/* Raises the given signal (executing the registered signal handler with the - given signal number as parameter). - This implementation does not prevent further signals of the same time from - occuring, but executes signal( sig, SIG_DFL ) before entering the signal - handler (i.e., a second signal before the signal handler re-registers itself - or SIG_IGN will end the program). - Returns zero if successful, nonzero otherwise. */ -_PDCLIB_PUBLIC int raise( int sig ); - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_SIGNAL_H -#include _PDCLIB_EXTEND_SIGNAL_H -#endif - -#endif diff --git a/rocklibc/include/stdalign.h b/rocklibc/include/stdalign.h deleted file mode 100644 index b302601..0000000 --- a/rocklibc/include/stdalign.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Alignment - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDALIGN_H -#define _PDCLIB_STDALIGN_H _PDCLIB_STDALIGN_H - -#ifndef __cplusplus -#define __alignas_is_defined 1 -#define __alignof_is_defined 1 - -#if ! defined( __STDC_VERSION__ ) || ( __STDC_VERSION__ < 202311L ) -#define alignas _Alignas -#define alignof _Alignof -#elif __STDC_VERSION__ >= 202311L -#warning has been deprecated as of C23. -#endif -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDALIGN_H -#include _PDCLIB_EXTEND_STDALIGN_H -#endif - -#endif - diff --git a/rocklibc/include/stdarg.h b/rocklibc/include/stdarg.h deleted file mode 100644 index 7741b70..0000000 --- a/rocklibc/include/stdarg.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Variable arguments - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDARG_H -#define _PDCLIB_STDARG_H _PDCLIB_STDARG_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_config.h" - -typedef _PDCLIB_va_list va_list; - -#define va_arg( ap, type ) _PDCLIB_va_arg( ap, type ) -#define va_copy( dest, src ) _PDCLIB_va_copy( dest, src ) -#define va_end( ap ) _PDCLIB_va_end( ap ) -#define va_start( ap, parmN ) _PDCLIB_va_start( ap, parmN ) - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDARG_H -#include _PDCLIB_EXTEND_STDARG_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/stdbool.h b/rocklibc/include/stdbool.h deleted file mode 100644 index e901f63..0000000 --- a/rocklibc/include/stdbool.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Boolean type and values - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDBOOL_H -#define _PDCLIB_STDBOOL_H _PDCLIB_STDBOOL_H - -#ifndef __cplusplus -#define bool _Bool -#define true 1 -#define false 0 -#endif -#define __bool_true_false_are_defined 1 - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDBOOL_H -#include _PDCLIB_EXTEND_STDBOOL_H -#endif - -#endif diff --git a/rocklibc/include/stddef.h b/rocklibc/include/stddef.h deleted file mode 100644 index 7d03d07..0000000 --- a/rocklibc/include/stddef.h +++ /dev/null @@ -1,55 +0,0 @@ -/* Common definitions - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDDEF_H -#define _PDCLIB_STDDEF_H _PDCLIB_STDDEF_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -typedef _PDCLIB_ptrdiff_t ptrdiff_t; - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef __cplusplus -typedef _PDCLIB_wchar_t wchar_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -#define offsetof( type, member ) _PDCLIB_offsetof( type, member ) - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 -#ifndef _PDCLIB_RSIZE_T_DEFINED -#define _PDCLIB_RSIZE_T_DEFINED _PDCLIB_RSIZE_T_DEFINED -typedef size_t rsize_t; -#endif -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDDEF_H -#include _PDCLIB_EXTEND_STDDEF_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/stdint.h b/rocklibc/include/stdint.h deleted file mode 100644 index 04af6b0..0000000 --- a/rocklibc/include/stdint.h +++ /dev/null @@ -1,236 +0,0 @@ -/* Integer types - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDINT_H -#define _PDCLIB_STDINT_H _PDCLIB_STDINT_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -/* 7.18.1.1 Exact-width integer types. */ - -#ifdef _PDCLIB_int8_t -typedef _PDCLIB_int8_t int8_t; -typedef _PDCLIB_uint8_t uint8_t; -#endif - -#ifdef _PDCLIB_int16_t -typedef _PDCLIB_int16_t int16_t; -typedef _PDCLIB_uint16_t uint16_t; -#endif - -#ifdef _PDCLIB_int32_t -typedef _PDCLIB_int32_t int32_t; -typedef _PDCLIB_uint32_t uint32_t; -#endif - -#ifdef _PDCLIB_int64_t -typedef _PDCLIB_int64_t int64_t; -typedef _PDCLIB_uint64_t uint64_t; -#endif - -/* 7.18.1.2 Minimum-width integer types */ - -/* You are allowed to add more types here, e.g. int_least24_t. */ - -typedef _PDCLIB_int_least8_t int_least8_t; -typedef _PDCLIB_int_least16_t int_least16_t; -typedef _PDCLIB_int_least32_t int_least32_t; -typedef _PDCLIB_int_least64_t int_least64_t; - -typedef _PDCLIB_uint_least8_t uint_least8_t; -typedef _PDCLIB_uint_least16_t uint_least16_t; -typedef _PDCLIB_uint_least32_t uint_least32_t; -typedef _PDCLIB_uint_least64_t uint_least64_t; - -/* 7.18.1.3 Fastest minimum-width integer types */ - -/* You are allowed to add more types here, e.g. int_fast24_t. */ - -typedef _PDCLIB_int_fast8_t int_fast8_t; -typedef _PDCLIB_int_fast16_t int_fast16_t; -typedef _PDCLIB_int_fast32_t int_fast32_t; -typedef _PDCLIB_int_fast64_t int_fast64_t; - -typedef _PDCLIB_uint_fast8_t uint_fast8_t; -typedef _PDCLIB_uint_fast16_t uint_fast16_t; -typedef _PDCLIB_uint_fast32_t uint_fast32_t; -typedef _PDCLIB_uint_fast64_t uint_fast64_t; - -/* 7.18.1.4 Integer types capable of holding object pointers */ - -typedef _PDCLIB_intptr_t intptr_t; -typedef _PDCLIB_uintptr_t uintptr_t; - -/* 7.18.1.5 Greatest-width integer types */ - -typedef _PDCLIB_intmax_t intmax_t; -typedef _PDCLIB_uintmax_t uintmax_t; - -/* 7.18.2 Limits of specified-width integer types */ - -#if defined( __cplusplus ) && __cplusplus < 201103L -#ifndef __STDC_LIMIT_MACROS -#define _PDCLIB_NO_LIMIT_MACROS -#endif -#endif - -#ifndef _PDCLIB_NO_LIMIT_MACROS - -/* 7.18.2.1 Limits of exact-width integer types */ - -#if _PDCLIB_TWOS_COMPLEMENT == 1 - -#if _PDCLIB_INT_LEAST8_MAX == 0x7f -#define INT8_MAX _PDCLIB_INT_LEAST8_MAX -#define INT8_MIN _PDCLIB_INT_LEAST8_MIN -#define UINT8_MAX _PDCLIB_UINT_LEAST8_MAX -#endif - -#if _PDCLIB_INT_LEAST16_MAX == 0x7fff -#define INT16_MAX _PDCLIB_INT_LEAST16_MAX -#define INT16_MIN _PDCLIB_INT_LEAST16_MIN -#define UINT16_MAX _PDCLIB_UINT_LEAST16_MAX -#endif - -#if _PDCLIB_INT_LEAST32_MAX == 0x7fffffffl -#define INT32_MAX _PDCLIB_INT_LEAST32_MAX -#define INT32_MIN _PDCLIB_INT_LEAST32_MIN -#define UINT32_MAX _PDCLIB_UINT_LEAST32_MAX -#endif - -#if _PDCLIB_INT_LEAST64_MAX == 0x7fffffffffffffffll -#define INT64_MAX _PDCLIB_INT_LEAST64_MAX -#define INT64_MIN _PDCLIB_INT_LEAST64_MIN -#define UINT64_MAX _PDCLIB_UINT_LEAST64_MAX -#endif - -#endif - -/* 7.18.2.2 Limits of minimum-width integer types */ - -#define INT_LEAST8_MIN _PDCLIB_INT_LEAST8_MIN -#define INT_LEAST8_MAX _PDCLIB_INT_LEAST8_MAX -#define UINT_LEAST8_MAX _PDCLIB_UINT_LEAST8_MAX - -#define INT_LEAST16_MIN _PDCLIB_INT_LEAST16_MIN -#define INT_LEAST16_MAX _PDCLIB_INT_LEAST16_MAX -#define UINT_LEAST16_MAX _PDCLIB_UINT_LEAST16_MAX - -#define INT_LEAST32_MIN _PDCLIB_INT_LEAST32_MIN -#define INT_LEAST32_MAX _PDCLIB_INT_LEAST32_MAX -#define UINT_LEAST32_MAX _PDCLIB_UINT_LEAST32_MAX - -#define INT_LEAST64_MIN _PDCLIB_INT_LEAST64_MIN -#define INT_LEAST64_MAX _PDCLIB_INT_LEAST64_MAX -#define UINT_LEAST64_MAX _PDCLIB_UINT_LEAST64_MAX - -/* 7.18.2.3 Limits of fastest minimum-width integer types */ - -#define INT_FAST8_MIN _PDCLIB_INT_FAST8_MIN -#define INT_FAST8_MAX _PDCLIB_INT_FAST8_MAX -#define UINT_FAST8_MAX _PDCLIB_UINT_FAST8_MAX - -#define INT_FAST16_MIN _PDCLIB_INT_FAST16_MIN -#define INT_FAST16_MAX _PDCLIB_INT_FAST16_MAX -#define UINT_FAST16_MAX _PDCLIB_UINT_FAST16_MAX - -#define INT_FAST32_MIN _PDCLIB_INT_FAST32_MIN -#define INT_FAST32_MAX _PDCLIB_INT_FAST32_MAX -#define UINT_FAST32_MAX _PDCLIB_UINT_FAST32_MAX - -#define INT_FAST64_MIN _PDCLIB_INT_FAST64_MIN -#define INT_FAST64_MAX _PDCLIB_INT_FAST64_MAX -#define UINT_FAST64_MAX _PDCLIB_UINT_FAST64_MAX - -/* 7.18.2.4 Limits of integer types capable of holding object pointers */ - -#define INTPTR_MIN _PDCLIB_INTPTR_MIN -#define INTPTR_MAX _PDCLIB_INTPTR_MAX -#define UINTPTR_MAX _PDCLIB_UINTPTR_MAX - -/* 7.18.2.5 Limits of greatest-width integer types */ - -#define INTMAX_MIN _PDCLIB_INTMAX_MIN -#define INTMAX_MAX _PDCLIB_INTMAX_MAX -#define UINTMAX_MAX _PDCLIB_UINTMAX_MAX - -/* 7.18.3 Limits of other integer types */ - -#define PTRDIFF_MIN _PDCLIB_PTRDIFF_MIN -#define PTRDIFF_MAX _PDCLIB_PTRDIFF_MAX - -#define SIG_ATOMIC_MIN _PDCLIB_SIG_ATOMIC_MIN -#define SIG_ATOMIC_MAX _PDCLIB_SIG_ATOMIC_MAX - -#define SIZE_MAX _PDCLIB_SIZE_MAX - -#define WCHAR_MIN _PDCLIB_WCHAR_MIN -#define WCHAR_MAX _PDCLIB_WCHAR_MAX - -#define WINT_MIN _PDCLIB_WINT_MIN -#define WINT_MAX _PDCLIB_WINT_MAX - -#endif - -/* 7.18.4 Macros for integer constants */ - -#if defined( __cplusplus ) && __cplusplus < 201103L -#ifndef __STDC_CONSTANT_MACROS -#define _PDCLIB_NO_CONSTANT_MACROS -#endif -#endif - -#ifndef _PDCLIB_NO_CONSTANT_MACROS - -/* 7.18.4.1 Macros for minimum-width integer constants */ - -/* Expand to an integer constant of specified value and type int_leastN_t */ - -#define INT8_C _PDCLIB_INT_LEAST8_C -#define INT16_C _PDCLIB_INT_LEAST16_C -#define INT32_C _PDCLIB_INT_LEAST32_C -#define INT64_C _PDCLIB_INT_LEAST64_C - -/* Expand to an integer constant of specified value and type uint_leastN_t */ - -#define UINT8_C _PDCLIB_UINT_LEAST8_C -#define UINT16_C _PDCLIB_UINT_LEAST16_C -#define UINT32_C _PDCLIB_UINT_LEAST32_C -#define UINT64_C _PDCLIB_UINT_LEAST64_C - -/* 7.18.4.2 Macros for greatest-width integer constants */ - -/* Expand to an integer constant of specified value and type intmax_t */ -#define INTMAX_C( value ) _PDCLIB_INTMAX_C( value ) - -/* Expand to an integer constant of specified value and type uintmax_t */ -#define UINTMAX_C( value ) _PDCLIB_UINTMAX_C( value ) - -#endif - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 -#define RSIZE_MAX ( _PDCLIB_SIZE_MAX >> 1 ) -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDINT_H -#include _PDCLIB_EXTEND_STDINT_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/stdio.h b/rocklibc/include/stdio.h index 4ee538f..008aa81 100644 --- a/rocklibc/include/stdio.h +++ b/rocklibc/include/stdio.h @@ -1,935 +1,10 @@ -/* Input/output +#ifndef RLIBC_STDIO_H +#define RLIBC_STDIO_H - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ +#include -#ifndef _PDCLIB_STDIO_H -#define _PDCLIB_STDIO_H _PDCLIB_STDIO_H +int printf(const char *format, ...); -#ifdef __cplusplus -extern "C" { -#endif +char getchar(void); -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -/* See setvbuf(), third argument */ -#define _IOFBF (1u<<0) -#define _IOLBF (1u<<1) -#define _IONBF (1u<<2) - -/* The following are platform-dependent, and defined in _PDCLIB_config.h. */ -typedef struct _PDCLIB_fpos_t fpos_t; -typedef struct _PDCLIB_file_t FILE; -#define EOF (-1) -#define BUFSIZ _PDCLIB_BUFSIZ -#define FOPEN_MAX _PDCLIB_FOPEN_MAX -#define FILENAME_MAX _PDCLIB_FILENAME_MAX -#define L_tmpnam _PDCLIB_L_tmpnam -#define TMP_MAX _PDCLIB_TMP_MAX - -/* See fseek(), third argument */ -#define SEEK_CUR _PDCLIB_SEEK_CUR -#define SEEK_END _PDCLIB_SEEK_END -#define SEEK_SET _PDCLIB_SEEK_SET - -extern FILE * stdin; -extern FILE * stdout; -extern FILE * stderr; - -/* Operations on files */ - -/* Remove the given file. - Returns zero if successful, non-zero otherwise. - This implementation does detect if a file of that name is currently open, - and fails the remove in this case. This does not detect two distinct names - that merely result in the same file (e.g. "/home/user/foo" vs. "~/foo"). -*/ -_PDCLIB_PUBLIC int remove( const char * filename ); - -/* Rename the given old file to the given new name. - Returns zero if successful, non-zero otherwise. - This implementation does detect if the old filename corresponds to an open - file, and fails the rename in this case. - If there already is a file with the new filename, behaviour is defined by - the glue code (see functions/_PDCLIB/rename.c). -*/ -_PDCLIB_PUBLIC int rename( const char * oldpath, const char * newpath ); - -/* Open a temporary file with mode "wb+", i.e. binary-update. Remove the file - automatically if it is closed or the program exits normally (by returning - from main() or calling exit()). - Returns a pointer to a FILE handle for this file. - This implementation does not remove temporary files if the process aborts - abnormally (e.g. abort()). -*/ -_PDCLIB_PUBLIC FILE * tmpfile( void ); - -/* Generate a file name that is not equal to any existing filename AT THE TIME - OF GENERATION. Generate a different name each time it is called. - Returns a pointer to an internal static buffer containing the filename if s - is a NULL pointer. (This is not thread-safe!) - Returns s if it is not a NULL pointer (s is then assumed to point to an array - of at least L_tmpnam characters). - Returns NULL if unable to generate a suitable name (because all possible - names already exist, or the function has been called TMP_MAX times already). - Note that this implementation cannot guarantee a file of the name generated - is not generated between the call to this function and a subsequent fopen(). -*/ -_PDCLIB_PUBLIC char * tmpnam( char * s ); - -/* File access functions */ - -/* Close the file associated with the given stream (after flushing its buffers). - Returns zero if successful, EOF if any errors occur. -*/ -_PDCLIB_PUBLIC int fclose( FILE * stream ); - -/* Flush the buffers of the given output stream. If the stream is an input - stream, or an update stream with the last operation being an input operation, - behaviour is undefined. - If stream is a NULL pointer, perform the buffer flushing for all applicable - streams. - Returns zero if successful, EOF if a write error occurs. - Sets the error indicator of the stream if a write error occurs. -*/ -_PDCLIB_PUBLIC int fflush( FILE * stream ); - -/* Open the file with the given filename in the given mode, and return a stream - handle for it in which error and end-of-file indicator are cleared. Defined - values for mode are: - - READ MODES - text files binary files - without update "r" "rb" - with update "r+" "rb+" or "r+b" - - Opening in read mode fails if no file with the given filename exists, or if - cannot be read. - - WRITE MODES - text files binary files - without update "w" "wb" - with update "w+" "wb+" or "w+b" - - With write modes, if a file with the given filename already exists, it is - truncated to zero length. - - APPEND MODES - text files binary files - without update "a" "ab" - with update "a+" "ab+" or "a+b" - - With update modes, if a file with the given filename already exists, it is - not truncated to zero length, but all writes are forced to end-of-file (this - regardless to fseek() calls). Note that binary files opened in append mode - might have their end-of-file padded with '\0' characters. - - Update modes mean that both input and output functions can be performed on - the stream, but output must be terminated with a call to either fflush(), - fseek(), fsetpos(), or rewind() before input is performed, and input must - be terminated with a call to either fseek(), fsetpos(), or rewind() before - output is performed, unless input encountered end-of-file. - - If a text file is opened with update mode, the implementation is at liberty - to open a binary stream instead. This implementation honors the exact mode - given. - - The stream is fully buffered if and only if it can be determined not to - refer to an interactive device. - - If the mode string begins with but is longer than one of the above sequences - the implementation is at liberty to ignore the additional characters, or do - implementation-defined things. This implementation only accepts the exact - modes above. - - Returns a pointer to the stream handle if successfull, NULL otherwise. -*/ -_PDCLIB_PUBLIC FILE * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ); - -/* Close any file currently associated with the given stream. Open the file - identified by the given filename with the given mode (equivalent to fopen()), - and associate it with the given stream. If filename is a NULL pointer, - attempt to change the mode of the given stream. - This implementation allows any mode changes on "real" files, and associating - of the standard streams with files. It does *not* support mode changes on - standard streams. - (Primary use of this function is to redirect stdin, stdout, and stderr.) - - Returns a pointer to the stream handle if successfull, NULL otherwise. -*/ -_PDCLIB_PUBLIC FILE * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, FILE * _PDCLIB_restrict stream ); - -/* If buf is a NULL pointer, call setvbuf( stream, NULL, _IONBF, BUFSIZ ). - If buf is not a NULL pointer, call setvbuf( stream, buf, _IOFBF, BUFSIZ ). -*/ -_PDCLIB_PUBLIC void setbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf ); - -/* Set the given stream to the given buffering mode. If buf is not a NULL - pointer, use buf as file buffer (of given size). If buf is a NULL pointer, - use a buffer of given size allocated internally. _IONBF causes unbuffered - behaviour, _IOLBF causes line-buffered behaviour, _IOFBF causes fully - buffered behaviour. Calling this function is only valid right after a file is - opened, and before any other operation (except for any unsuccessful calls to - setvbuf()) has been performed. - Returns zero if successful, nonzero otherwise. -*/ -_PDCLIB_PUBLIC int setvbuf( FILE * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size ); - -/* Formatted input/output functions */ - -/* - Write output to the given stream, as defined by the given format string and - 0..n subsequent arguments (the argument stack). - - The format string is written to the given stream verbatim, except for any - conversion specifiers included, which start with the letter '%' and are - documented below. If the given conversion specifiers require more arguments - from the argument stack than provided, behaviour is undefined. Additional - arguments not required by conversion specifiers are evaluated but otherwise - ignored. - - (The standard specifies the format string is allowed to contain multibyte - character sequences as long as it starts and ends in initial shift state, - but this is not yet supported by this implementation, which interprets the - format string as sequence of char.) - TODO: Add multibyte support to printf() functions. - - A conversion specifier consists of: - - Zero or more flags (one of the characters "-+ #0"). - - Optional minimum field width as decimal integer. Default is padding to the - left, using spaces. Note that 0 is taken as a flag, not the beginning of a - field width. Note also that a small field width will not result in the - truncation of a value. - - Optional precision (given as ".#" with # being a decimal integer), - specifying: - - the min. number of digits to appear (diouxX), - - the max. number of digits after the decimal point (aAeEfF), - - the max. number of significant digits (gG), - - the max. number of bytes to be written (s). - - behaviour with other conversion specifiers is undefined. - - Optional length modifier specifying the size of the argument (one of "hh", - "ll", or one of the characters "hljztL"). - - Conversion specifier character specifying the type of conversion to be - applied (and the type of the next argument from the argument stack). One - of the characters "diouxXfFeEgGaAcspn%". - - Minimum field width and/or precision may be given as asterisk ('*') instead - of a decimal integer. In this case, the next argument from the argument - stack is assumed to be an int value specifying the width / precision. A - negative field width is interpreted as flag '-' followed by a positive field - width. A negative precision is interpreted as if no precision was given. - - FLAGS - - Left-justify the conversion result within its field width. - + Prefix a '+' on positive signed conversion results. Prefix a '-' on - floating conversions resulting in negative zero, or negative values - rounding to zero. - space Prefix a space on positive signed conversion results, or if a signed - conversion results in no characters. If both '+' and ' ' are given, - ' ' is ignored. - # Use an "alternative form" for - - 'o' conversion, increasing precision until the first digit of the - result is a zero; - - 'x' or 'X' conversion, prefixing "0x" or "0X" to nonzero results; - - "aAeEfF" conversions, always printing a decimal point even if no - digits are following; - - 'g' or 'G' conversions, always printing a decimal point even if no - digits are following, and not removing trailing zeroes. - - behaviour for other conversions is unspecified. - 0 Use leading zeroes instead of spaces for field width padding. If both - '-' and '0' are given, '0' is ignored. If a precision is specified for - any of the "diouxX" conversions, '0' is ignored. Behaviour is only - defined for "diouxXaAeEfFgG". - - LENGTH MODIFIERS - hh For "diouxX" conversions, the argument from the argument stack is - assumed to be of char width. (It will have been subject to integer - promotion but will be converted back.) For 'n' conversions, the argument - is assumed to be a pointer to signed char. - h For "diouxX" conversions, the argument from the argument stack is - assumed to be of short int width. (It will have been subject to integer - promotion but will be converted back.) For 'n' conversions, the argument - is assumed to be a pointer to short int. - l For "diouxX" conversions, the argument from the argument stack is - assumed to be of long int width. For 'n' conversions, the argument is - assumed to be a pointer to short int. For 'c' conversions, the argument - is assumed to be a wint_t. For 's' conversions, the argument is assumed - to be a pointer to wchar_t. No effect on "aAeEfFgG" conversions. - ll For "diouxX" conversions, the argument from the argument stack is - assumed to be of long long int width. For 'n' conversions, the argument - is assumed to be a pointer to long long int. - j For "diouxX" conversions, the argument from the argument stack is - assumed to be of intmax_t width. For 'n' conversions, the argument is - assumed to be a pointer to intmax_t. - z For "diouxX" conversions, the argument from the argument stack is - assumed to be of size_t width. For 'n' conversions, the argument is - assumed to be a pointer to size_t. - t For "diouxX" conversions, the argument from the argument stack is - assumed to be of ptrdiff_t width. For 'n' conversions, the argument is - assumed to be a pointer to ptrdiff_t. - L For "aAeEfFgG" conversions, the argument from the argument stack is - assumed to be a long double. - Length modifiers appearing for any conversions not mentioned above will have - undefined behaviour. - If a length modifier appears with any conversion specifier other than as - specified above, the behavior is undefined. - - CONVERSION SPECIFIERS - d,i The argument from the argument stack is assumed to be of type int, and - is converted to a signed decimal value with a minimum number of digits - as specified by the precision (default 1), padded with leading zeroes. - A zero value converted with precision zero yields no output. - o The argument from the argument stack is assumed to be of type unsigned - int, and is converted to an unsigned octal value, other behaviour being - as above. - u The argument from the argument stack is assumed to be of type unsigned - int, and converted to an unsigned decimal value, other behaviour being - as above. - x,X The argument from the argument stack is assumed to be of type unsigned - int, and converted to an unsigned hexadecimal value, using lowercase - "abcdef" for 'x' and uppercase "ABCDEF" for 'X' conversion, other - behaviour being as above. - f,F The argument from the argument stack is assumed to be of type double, - and converted to a decimal floating point in decimal-point notation, - with the number of digits after the decimal point as specified by the - precision (default 6) and the value being rounded appropriately. If - precision is zero (and the '#' flag is not given), no decimal point is - printed. At least one digit is always printed before the decimal point. - For 'f' conversions, an infinity value is printed as either [-]inf or - [-]infinity (, depending on the configuration of this implementation. A - NaN value is printed as [-]nan. For 'F' conversions uppercase characters - are used for these special values. The flags '-', '+' and ' ' apply as - usual to these special values, '#' and '0' have no effect. - e,E The argument from the argument stack is assumed to be of type double, - and converted to a decimal floating point in normalized exponential - notation ([?]d.ddd edd). "Normalized" means one nonzero digit before - the decimal point, unless the value is zero. The number of digits after - the decimal point is specified by the precision (default 6), the value - being rounded appropriately. If precision is zero (and the '#' flag is - not given), no decimal point is printed. The exponent has at least two - digits, and not more than necessary to represent the exponent. If the - value is zero, the exponent is zero. The 'e' written to indicate the - exponend is uppercase for 'E' conversions. - Infinity or NaN values are represented as for 'f' and 'F' conversions, - respectively. - g,G The argument from the argument stack is assumed to be of type double, - and converted according to either 'f' or 'e' format for 'g' conversions, - or 'F' or 'E' format for 'G' conversions, respectively, with the actual - conversion chosen depending on the value. 'e' / 'E' conversion is chosen - if the resulting exponent is < -4 or >= the precision (default 1). - Trailing zeroes are removed (unless the '#' flag is given). A decimal - point appears only if followed by a digit. - Infinity or NaN values are represented as for 'f' and 'F' conversions, - respectively. - a,A The argument from the argument stack is assumed to be of type double, - and converted to a floating point hexadecimal notation ([?]0xh.hhhh pd) - with one hexadecimal digit (being nonzero if the value is normalized, - and otherwise unspecified) before the decimal point, and the number of - digits after the decimal point being specified by the precision. If no - precision is given, the default is to print as many digits as nevessary - to give an exact representation of the value (if FLT_RADIX is a power of - 2). If no precision is given and FLT_RADIX is not a power of 2, the - default is to print as many digits to distinguish values of type double - (possibly omitting trailing zeroes). (A precision p is sufficient to - distinguish values of the source type if 16^p-1 > b^n where b is - FLT_RADIX and n is the number of digits in the significand (to base b) - of the source type. A smaller p might suffice depending on the - implementation's scheme for determining the digit to the left of the - decimal point.) The error has the correct sign for the current rounding - direction. - Unless the '#' flag is given, no decimal-point is given for zero - precision. - The 'a' conversion uses lowercase "abcdef", "0x" and 'p', the 'A' - conversion uppercase "ABCDEF", "0X" and 'P'. - The exponent always has at least one digit, and not more than necessary - to represent the decimal exponent of 2. If the value is zero, the - exponent is zero. - Infinity or NaN values are represented as for 'f' and 'F' conversions, - respectively. - Binary implementations are at liberty to chose the hexadecimal digit to - the left of the decimal point so that subsequent digits align to nibble - boundaries. - c The argument from the argument stack is assumed to be of type int, and - converted to a character after the value has been cast to unsigned char. - If the 'l' length modifier is given, the argument is assumed to be of - type wint_t, and converted as by a "%ls" conversion with no precision - and a pointer to a two-element wchar_t array, with the first element - being the wint_t argument and the second a '\0' wide character. - s The argument from the argument stack is assumed to be a char array (i.e. - pointer to char). Characters from that array are printed until a zero - byte is encountered or as many bytes as specified by a given precision - have been written. - If the l length modifier is given, the argument from the argument stack - is assumed to be a wchar_t array (i.e. pointer to wchar_t). Wide - characters from that array are converted to multibyte characters as by - calls to wcrtomb() (using a mbstate_t object initialized to zero prior - to the first conversion), up to and including the terminating null wide - character. The resulting multibyte character sequence is then printed up - to but not including the terminating null character. If a precision is - given, it specifies the maximum number of bytes to be written (including - shift sequences). If the given precision would require access to a wide - character one past the end of the array, the array shall contain a '\0' - wide character. In no case is a partial multibyte character written. - Redundant shift sequences may result if the multibyte characters have a - state-dependent encoding. - TODO: Clarify these statements regarding %ls. - p The argument from the argument stack is assumed to be a void pointer, - and converted to a sequence of printing characters in an implementation- - defined manner. - This implementation casts the pointer to type intptr_t, and prints the - value as if a %#x conversion specifier was given. - n The argument from the argument stack is assumed to be a pointer to a - signed integer, into which the number of characters written so far by - this call to fprintf is stored. The behaviour, should any flags, field - widths, or precisions be given is undefined. - % A verbatim '%' character is written. No argument is taken from the - argument stack. - - Returns the number of characters written if successful, a negative value - otherwise. -*/ -_PDCLIB_PUBLIC int fprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ); - -/* TODO: fscanf() documentation */ -/* - Read input from a given stream, as defined by the given format string, and - store converted input in the objects pointed to by 0..n subsequent arguments - (the argument stack). - - The format string contains a sequence of directives that are expected to - match the input. If such a directive fails to match, the function returns - (matching error). It also returns if an input error occurs (input error). - - Directives can be: - - one or more whitespaces, matching any number of whitespaces in the input; - - printing characters, matching the input verbatim; - - conversion specifications, which convert an input sequence into a value as - defined by the individual specifier, and store that value in a memory - location pointed to by the next pointer on the argument stack. Details are - documented below. If there is an insufficient number of pointers on the - argument stack, behaviour is undefined. Additional arguments not required - by any conversion specifications are evaluated, but otherwise ignored. - - (The standard specifies the format string is allowed to contain multibyte - character sequences as long as it starts and ends in initial shift state, - but this is not yet supported by this implementation, which interprets the - format string as sequence of char.) - TODO: Add multibyte support to scanf() functions. - - A conversion specifier consists of: - - Optional assignment-suppressing character ('*') that makes the conversion - read input as usual, but does not assign the conversion result. - - Optional maximum field width as decimal integer. - - Optional length modifier specifying the size of the argument (one of "hh", - "ll", or one of the characters "hljztL"). - - Conversion specifier character specifying the type of conversion to be - applied (and the type of the next argument from the argument stack). One - of the characters "diouxXaAeEfFgGcs[pn%". - - LENGTH MODIFIERS - hh For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of of char width. - h For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of short int width. - l For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of long int width. - For "aAeEfFgG" conversions, it is assumed to point to a variable of type - double. - For "cs[" conversions, it is assumed to point to a variable of type - wchar_t. - ll For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of long long int width. - j For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of intmax_t width. - z For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of size_t width. - t For "diouxXn" conversions, the next pointer from the argument stack is - assumed to point to a variable of ptrdiff_t width. - L For "aAeEfFgG" conversions, the next pointer from the argument stack is - assumed to point to a variable of type long double. - Length modifiers appearing for any conversions not mentioned above will have - undefined behaviour. - If a length modifier appears with any conversion specifier other than as - specified above, the behavior is undefined. - - CONVERSION SPECIFIERS - d Matches an (optionally signed) decimal integer of the format expected - by strtol() with base 10. The next pointer from the argument stack is - assumed to point to a signed integer. - i Matches an (optionally signed) integer of the format expected by - strtol() with base 0. The next pointer from the argument stack is - assumed to point to a signed integer. - o Matches an (optionally signed) octal integer of the format expected by - strtoul() with base 8. The next pointer from the argument stack is - assumed to point to an unsigned integer. - u Matches an (optionally signed) decimal integer of the format expected - by strtoul() with base 10. The next pointer from the argument stack is - assumed to point to an unsigned integer. - x Matches an (optionally signed) hexadecimal integer of the format - expected by strtoul() with base 16. The next pointer from the argument - stack is assumed to point to an unsigned integer. - aefg Matches an (optionally signed) floating point number, infinity, or not- - a-number-value of the format expected by strtod(). The next pointer - from the argument stack is assumed to point to a float. - c Matches a number of characters as specified by the field width (default - 1). The next pointer from the argument stack is assumed to point to a - character array large enough to hold that many characters. - If the 'l' length modifier is given, the input is assumed to match a - sequence of multibyte characters (starting in the initial shift state), - which will be converted to a wide character sequence as by successive - calls to mbrtowc() with a mbstate_t object initialized to zero prior to - the first conversion. The next pointer from the argument stack is - assumed to point to a wchar_t array large enough to hold that many - characters. - In either case, note that no '\0' character is added to terminate the - sequence. - s Matches a sequence of non-white-space characters. The next pointer from - the argument stack is assumed to point to a character array large - enough to hold the sequence including terminating '\0' character. - If the 'l' length modifier is given, the input is assumed to match a - sequence of multibyte characters (starting in the initial shift state), - which will be converted to a wide character sequence as by a call to - mbrtowc() with a mbstate_t object initialized to zero prior to the - first conversion. The next pointer from the argument stack is assumed - to point to a wchar_t array large enough to hold the sequence including - terminating '\0' character. - [ Matches a nonempty sequence consisting of any of those characters - specified between itself and a corresponding closing bracket (']'). - If the first character in the list is a circumflex ('^'), this matches - a nonempty sequence consisting of any characters NOT specified. If the - closing bracket appears as the first character in the scanset ("[]" or - "[^]", it is assumed to belong to the scanset, which then ends with the - NEXT closing bracket. - If there is a '-' character in the scanset which is not the first after - the opening bracket (or the circumflex, see above) or the last in the - scanset, behaviour is implementation-defined. This implementation - handles this character like any other. - - The extend of the input field is determined byte-by-byte for the above - conversions ('c', 's', '['), with no special provisions being made for - multibyte characters. The resulting field is nevertheless a multibyte - sequence begining in intial shift state. - - p Matches a sequence of characters as produced by the printf() "%p" - conversion. The next pointer from the argument stack is assumed to - point to a void pointer, which will be filled with the same location - as the pointer used in the printf() statement. Note that behaviour is - undefined if the input value is not the result of an earlier printf() - call. - n Does not read input. The next pointer from the argument stack is - assumed to point to a signed integer, into which the number of - characters read from input so far by this call to fscanf() is stored. - This does not affect the return value of fscanf(). The behaviour, - should an assignment-supressing character of field width be given, - is undefined. - This can be used to test the success of literal matches and suppressed - assignments. - % Matches a single, verbatim '%' character. - - A, E, F, G and X are valid, and equivalent to their lowercase counterparts. - - All conversions except [, c, or n imply that whitespace characters from the - input stream are consumed until a non-whitespace character is encountered. - Such whitespaces do not count against a maximum field width. - - Conversions push at most one character back into the input stream. That - implies that some character sequences converted by the strtol() and strtod() - function families are not converted identically by the scnaf() function - family. - - Returns the number of input items successfully assigned. This can be zero if - an early mismatch occurs. Returns EOF if an input failure occurs before the - first conversion. -*/ -_PDCLIB_PUBLIC int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fprintf( stdout, format, ... ). */ -_PDCLIB_PUBLIC int printf( const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fscanf( stdin, format, ... ). */ -_PDCLIB_PUBLIC int scanf( const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fprintf( stdout, format, ... ), except that the result is - written into the buffer pointed to by s, instead of stdout, and that any - characters beyond the (n-1)th are discarded. The (n)th character is - replaced by a '\0' character in this case. - Returns the number of characters that would have been written (not counting - the terminating '\0' character) if n had been sufficiently large, if - successful, and a negative number if an encoding error ocurred. -*/ -_PDCLIB_PUBLIC int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fprintf( stdout, format, ... ), except that the result is - written into the buffer pointed to by s, instead of stdout. -*/ -_PDCLIB_PUBLIC int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fscanf( stdin, format, ... ), except that the input is read - from the buffer pointed to by s, instead of stdin. -*/ -_PDCLIB_PUBLIC int sscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... ); - -/* Equivalent to fprintf( stream, format, ... ), except that the argument stack - is passed as va_list parameter. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vfprintf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to fscanf( stream, format, ... ), except that the argument stack - is passed as va_list parameter. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to fprintf( stdout, format, ... ), except that the argument stack - is passed as va_list parameter. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to fscanf( stdin, format, ... ), except that the argument stack - is passed as va_list parameter. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to snprintf( s, n, format, ... ), except that the argument stack - is passed as va_list parameter. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to fprintf( stdout, format, ... ), except that the argument stack - is passed as va_list parameter, and the result is written to the buffer - pointed to by s, instead of stdout. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Equivalent to fscanf( stdin, format, ... ), except that the argument stack - is passed as va_list parameter, and the input is read from the buffer - pointed to by s, instead of stdin. Note that va_list is not declared by - . -*/ -_PDCLIB_PUBLIC int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); - -/* Character input/output functions */ - -/* Retrieve the next character from given stream. - Returns the character, EOF otherwise. - If end-of-file is reached, the EOF indicator of the stream is set. - If a read error occurs, the error indicator of the stream is set. -*/ -_PDCLIB_PUBLIC int fgetc( FILE * stream ); - -/* Read at most n-1 characters from given stream into the array s, stopping at - \n or EOF. Terminate the read string with \n. If EOF is encountered before - any characters are read, leave the contents of s unchanged. - Returns s if successful, NULL otherwise. - If a read error occurs, the error indicator of the stream is set. In this - case, the contents of s are indeterminate. -*/ -_PDCLIB_PUBLIC char * fgets( char * _PDCLIB_restrict s, int n, FILE * _PDCLIB_restrict stream ); - -/* Write the value c (cast to unsigned char) to the given stream. - Returns c if successful, EOF otherwise. - If a write error occurs, sets the error indicator of the stream is set. -*/ -_PDCLIB_PUBLIC int fputc( int c, FILE * stream ); - -/* Write the string s (not including the terminating \0) to the given stream. - Returns a value >=0 if successful, EOF otherwise. - This implementation does set the error indicator of the stream if a write - error occurs. -*/ -_PDCLIB_PUBLIC int fputs( const char * _PDCLIB_restrict s, FILE * _PDCLIB_restrict stream ); - -/* Equivalent to fgetc( stream ), but may be overloaded by a macro that - evaluates its parameter more than once. -*/ -_PDCLIB_PUBLIC int getc( FILE * stream ); - -/* Equivalent to fgetc( stdin ). */ -_PDCLIB_PUBLIC int getchar( void ); - -/* Equivalent to fputc( c, stream ), but may be overloaded by a macro that - evaluates its parameter more than once. -*/ -_PDCLIB_PUBLIC int putc( int c, FILE * stream ); - -/* Equivalent to fputc( c, stdout ), but may be overloaded by a macro that - evaluates its parameter more than once. -*/ -_PDCLIB_PUBLIC int putchar( int c ); - -/* Write the string s (not including the terminating \0) to stdout, and append - a newline to the output. Returns a value >= 0 when successful, EOF if a - write error occurred. -*/ -_PDCLIB_PUBLIC int puts( const char * s ); - -/* Push the value c (cast to unsigned char) back onto the given (input) stream. - A character pushed back in this way will be delivered by subsequent read - operations (and skipped by subsequent file positioning operations) as if it - has not been read. The external representation of the stream is unaffected - by this pushback (it is a buffer operation). One character of pushback is - guaranteed, further pushbacks may fail. EOF as value for c does not change - the input stream and results in failure of the function. - For text files, the file position indicator is indeterminate until all - pushed-back characters are read. For binary files, the file position - indicator is decremented by each successful call of ungetc(). If the file - position indicator for a binary file was zero before the call of ungetc(), - behaviour is undefined. (Older versions of the library allowed such a call.) - Returns the pushed-back character if successful, EOF if it fails. -*/ -_PDCLIB_PUBLIC int ungetc( int c, FILE * stream ); - -/* Direct input/output functions */ - -/* Read up to nmemb elements of given size from given stream into the buffer - pointed to by ptr. Returns the number of elements successfully read, which - may be less than nmemb if a read error or EOF is encountered. If a read - error is encountered, the value of the file position indicator is - indeterminate. If a partial element is read, its value is indeterminate. - If size or nmemb are zero, the function does nothing and returns zero. -*/ -_PDCLIB_PUBLIC size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream ); - -/* Write up to nmemb elements of given size from buffer pointed to by ptr to - the given stream. Returns the number of elements successfully written, which - will be less than nmemb only if a write error is encountered. If a write - error is encountered, the value of the file position indicator is - indeterminate. If size or nmemb are zero, the function does nothing and - returns zero. -*/ -_PDCLIB_PUBLIC size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, FILE * _PDCLIB_restrict stream ); - -/* File positioning functions */ - -/* Store the current position indicator (and, where appropriate, the current - mbstate_t status object) for the given stream into the given pos object. The - actual contents of the object are unspecified, but it can be used as second - parameter to fsetpos() to reposition the stream to the exact position and - parse state at the time fgetpos() was called. - Returns zero if successful, nonzero otherwise. - TODO: Implementation-defined errno setting for fgetpos(). -*/ -_PDCLIB_PUBLIC int fgetpos( FILE * _PDCLIB_restrict stream, fpos_t * _PDCLIB_restrict pos ); - -/* Set the position indicator for the given stream to the given offset from: - - the beginning of the file if whence is SEEK_SET, - - the current value of the position indicator if whence is SEEK_CUR, - - end-of-file if whence is SEEK_END. - On text streams, non-zero offsets are only allowed with SEEK_SET, and must - have been returned by ftell() for the same file. - Any characters buffered by ungetc() are dropped, the end-of-file indicator - for the stream is cleared. If the given stream is an update stream, the next - operation after a successful fseek() may be either input or output. - Returns zero if successful, nonzero otherwise. If a read/write error occurs, - the error indicator for the given stream is set. -*/ -_PDCLIB_PUBLIC int fseek( FILE * stream, long int offset, int whence ); - -/* Set the position indicator (and, where appropriate the mbstate_t status - object) for the given stream to the given pos object (created by an earlier - call to fgetpos() on the same file). - Any characters buffered by ungetc() are dropped, the end-of-file indicator - for the stream is cleared. If the given stream is an update stream, the next - operation after a successful fsetpos() may be either input or output. - Returns zero if successful, nonzero otherwise. If a read/write error occurs, - the error indicator for the given stream is set. - TODO: Implementation-defined errno setting for fsetpos(). -*/ -_PDCLIB_PUBLIC int fsetpos( FILE * stream, const fpos_t * pos ); - -/* Return the current offset of the given stream from the beginning of the - associated file. For text streams, the exact value returned is unspecified - (and may not be equal to the number of characters), but may be used in - subsequent calls to fseek(). - Returns -1L if unsuccessful. - TODO: Implementation-defined errno setting for ftell(). -*/ -_PDCLIB_PUBLIC long int ftell( FILE * stream ); - -/* Equivalent to (void)fseek( stream, 0L, SEEK_SET ), except that the error - indicator for the stream is also cleared. -*/ -_PDCLIB_PUBLIC void rewind( FILE * stream ); - -/* Error-handling functions */ - -/* Clear the end-of-file and error indicators for the given stream. */ -_PDCLIB_PUBLIC void clearerr( FILE * stream ); - -/* Return zero if the end-of-file indicator for the given stream is not set, - nonzero otherwise. -*/ -_PDCLIB_PUBLIC int feof( FILE * stream ); - -/* Return zero if the error indicator for the given stream is not set, nonzero - otherwise. -*/ -_PDCLIB_PUBLIC int ferror( FILE * stream ); - -/* If s is neither a NULL pointer nor an empty string, print the string to - stderr (with appended colon (':') and a space) first. In any case, print an - error message depending on the current value of errno (being the same as if - strerror( errno ) had been called). -*/ -_PDCLIB_PUBLIC void perror( const char * s ); - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 - -#define L_tmpnam_s _PDCLIB_L_tmpnam -#define TMP_MAX_S _PDCLIB_TMP_MAX - -#ifndef _PDCLIB_ERRNO_T_DEFINED -#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED -typedef int errno_t; -#endif - -#ifndef _PDCLIB_RSIZE_T_DEFINED -#define _PDCLIB_RSIZE_T_DEFINED _PDCLIB_RSIZE_T_DEFINED -typedef _PDCLIB_size_t rsize_t; -#endif - -/* Open a temporary file with mode "wb+", i.e. binary-update. Remove the file - automatically if it is closed or the program exits normally (by returning - from main() or calling exit()). - If successful, the FILE * pointed to by streamptr will be set to point at - the opened file handle, and the function returns zero. If unsuccessful, - the FILE * pointed to by streamptr will be set to NULL and a non-zero - value is returned. - The following conditions will be considered runtime constraint violations: - - streamptr being NULL. - In case of a constraint violation, no file is being created. - This implementation does not remove temporary files if the process aborts - abnormally (e.g. abort()). -*/ -_PDCLIB_PUBLIC errno_t tmpfile_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict streamptr ); - -/* Open the file with the given filename in the given mode, and sets the given - streamptr to point at the file handle for that file, in which error and - end-of-file indicator are cleared. Defined values for mode are: - - READ MODES - text files binary files - without update "r" "rb" - with update "r+" "rb+" or "r+b" - - Opening in read mode fails if no file with the given filename exists, or if - cannot be read. - - WRITE MODES - text files binary files - without update "w" "wb" - with update "w+" "wb+" or "w+b" - - With write modes, if a file with the given filename already exists, it is - truncated to zero length. - - APPEND MODES - text files binary files - without update "a" "ab" - with update "a+" "ab+" or "a+b" - - With update modes, if a file with the given filename already exists, it is - not truncated to zero length, but all writes are forced to end-of-file (this - regardless to fseek() calls). Note that binary files opened in append mode - might have their end-of-file padded with '\0' characters. - - Update modes mean that both input and output functions can be performed on - the stream, but output must be terminated with a call to either fflush(), - fseek(), fsetpos(), or rewind() before input is performed, and input must - be terminated with a call to either fseek(), fsetpos(), or rewind() before - output is performed, unless input encountered end-of-file. - - If a text file is opened with update mode, the implementation is at liberty - to open a binary stream instead. This implementation honors the exact mode - given. - - The stream is fully buffered if and only if it can be determined not to - refer to an interactive device. - - If the mode string begins with but is longer than one of the above sequences - the implementation is at liberty to ignore the additional characters, or do - implementation-defined things. This implementation only accepts the exact - modes above. - - The following conditions will be considered runtime constraint violations: - - streamptr being NULL. - - filename being NULL. - - mode being NULL. - In case of a constraint violation, no file is opened. If streamptr is not - NULL, *streamptr is set to NULL. - - Returns zero if successful, non-zero otherwise. -*/ -_PDCLIB_PUBLIC errno_t fopen_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict streamptr, const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ); - -/* Close any file currently associated with the given stream. Open the file - identified by the given filename with the given mode (equivalent to fopen()), - and associate it with the given stream. If filename is a NULL pointer, - attempt to change the mode of the given stream. - This implementation allows any mode changes on "real" files, and associating - of the standard streams with files. It does *not* support mode changes on - standard streams. - (Primary use of this function is to redirect stdin, stdout, and stderr.) - - The following conditions will be considered runtime constraint violations: - - newstreamptr being NULL. - - mode being NULL. - - stream being NULL. - In case of a constraint violation, no attempt is made to close or open any - file. If newstreamptr is not NULL, *newstreamptr is set to NULL. - - Returns zero if successfull, non-zero otherwise. -*/ -_PDCLIB_PUBLIC errno_t freopen_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict newstreamptr, const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, FILE * _PDCLIB_restrict stream ); - -/* None of these are implemented yet. Placeholder declarations. */ -_PDCLIB_PUBLIC errno_t tmpnam_s( char * s, rsize_t maxsize ); -_PDCLIB_PUBLIC int fprintf_s( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int fscanf_s( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int printf_s( const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int scanf_s( const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int snprintf_s( char * _PDCLIB_restrict s, rsize_t n, const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int sprintf_s( char * _PDCLIB_restrict s, rsize_t n, const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int sscanf_s( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... ); -_PDCLIB_PUBLIC int vfprintf_s( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vfscanf_s( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vprintf_s( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vscanf_s( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vsnprintf_s( char * _PDCLIB_restrict s, rsize_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vsprintf_s( char * _PDCLIB_restrict s, rsize_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC int vsscanf_s( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ); -_PDCLIB_PUBLIC char * gets_s( char * s, rsize_t n ); - -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDIO_H -#include _PDCLIB_EXTEND_STDIO_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif +#endif \ No newline at end of file diff --git a/rocklibc/include/stdlib.h b/rocklibc/include/stdlib.h deleted file mode 100644 index 9dc8b33..0000000 --- a/rocklibc/include/stdlib.h +++ /dev/null @@ -1,379 +0,0 @@ -/* General utilities - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDLIB_H -#define _PDCLIB_STDLIB_H _PDCLIB_STDLIB_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -/* Numeric conversion functions */ - -/* TODO: atof(), strtof(), strtod(), strtold() */ - -_PDCLIB_PUBLIC double atof( const char * nptr ); -_PDCLIB_PUBLIC double strtod( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr ); -_PDCLIB_PUBLIC float strtof( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr ); -_PDCLIB_PUBLIC long double strtold( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr ); - -/* Separate the character array nptr into three parts: A (possibly empty) - sequence of whitespace characters, a character representation of an integer - to the given base, and trailing invalid characters (including the terminating - null character). If base is 0, assume it to be 10, unless the integer - representation starts with 0x / 0X (setting base to 16) or 0 (setting base to - 8). If given, base can be anything from 0 to 36, using the 26 letters of the - base alphabet (both lowercase and uppercase) as digits 10 through 35. - The integer representation is then converted into the return type of the - function. It can start with a '+' or '-' sign. If the sign is '-', the result - of the conversion is negated. - If the conversion is successful, the converted value is returned. If endptr - is not a NULL pointer, a pointer to the first trailing invalid character is - returned in *endptr. - If no conversion could be performed, zero is returned (and nptr in *endptr, - if endptr is not a NULL pointer). If the converted value does not fit into - the return type, the functions return LONG_MIN, LONG_MAX, ULONG_MAX, - LLONG_MIN, LLONG_MAX, or ULLONG_MAX respectively, depending on the sign of - the integer representation and the return type, and errno is set to ERANGE. -*/ -/* There is strtoimax() and strtoumax() in operating on intmax_t / - uintmax_t, if the long long versions do not suit your needs. -*/ -_PDCLIB_PUBLIC long int strtol( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); -_PDCLIB_PUBLIC long long int strtoll( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); -_PDCLIB_PUBLIC unsigned long int strtoul( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); -_PDCLIB_PUBLIC unsigned long long int strtoull( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ); - -/* These functions are the equivalent of (int)strtol( nptr, NULL, 10 ), - strtol( nptr, NULL, 10 ) and strtoll(nptr, NULL, 10 ) respectively, with the - exception that they do not have to handle overflow situations in any defined - way. - (PDCLib does not simply forward these to their strtox() equivalents, but - provides a simpler atox() function that saves a couple of tests and simply - continues with the conversion in case of overflow.) -*/ -_PDCLIB_PUBLIC int atoi( const char * nptr ); -_PDCLIB_PUBLIC long int atol( const char * nptr ); -_PDCLIB_PUBLIC long long int atoll( const char * nptr ); - -/* Pseudo-random sequence generation functions */ - -extern unsigned long int _PDCLIB_seed; - -#define RAND_MAX 32767 - -/* Returns the next number in a pseudo-random sequence, which is between 0 and - RAND_MAX. - (PDCLib uses the implementation suggested by the standard document, which is - next = next * 1103515245 + 12345; return (unsigned int)(next/65536) % 32768;) -*/ -_PDCLIB_PUBLIC int rand( void ); - -/* Initialize a new pseudo-random sequence with the starting seed. Same seeds - result in the same pseudo-random sequence. The default seed is 1. -*/ -_PDCLIB_PUBLIC void srand( unsigned int seed ); - -/* Memory management functions */ - -/* Allocate a chunk of heap memory of given size. If request could not be - satisfied, return NULL. Otherwise, return a pointer to the allocated - memory. Memory contents are undefined. -*/ -_PDCLIB_PUBLIC void * malloc( size_t size ); - -/* Allocate a chunk of heap memory that is large enough to hold nmemb elements - of the given size, and zero-initialize that memory. If request could not be - satisfied, return NULL. Otherwise, return a pointer to the allocated - memory. -*/ -_PDCLIB_PUBLIC void * calloc( size_t nmemb, size_t size ); - -/* De-allocate a chunk of heap memory previously allocated using malloc(), - calloc(), or realloc(), and pointed to by ptr. If ptr does not match a - pointer previously returned by the mentioned allocation functions, or - free() has already been called for this ptr, behaviour is undefined. -*/ -_PDCLIB_PUBLIC void free( void * ptr ); - -/* Resize a chunk of memory previously allocated with malloc() and pointed to - by ptr to the given size (which might be larger or smaller than the original - size). Returns a pointer to the reallocated memory, or NULL if the request - could not be satisfied. Note that the resizing might include a memcpy() - from the original location to a different one, so the return value might or - might not equal ptr. If size is larger than the original size, the value of - memory beyond the original size is undefined. If ptr is NULL, realloc() - behaves like malloc(). -*/ -_PDCLIB_PUBLIC void * realloc( void * ptr, size_t size ); - -/* Communication with the environment */ - -/* These two can be passed to exit() or _Exit() as status values, to signal - successful and unsuccessful program termination, respectively. EXIT_SUCCESS - can be replaced by 0. How successful or unsuccessful program termination are - signaled to the environment, and what happens if exit() or _Exit() are being - called with a value that is neither of the three, is defined by the hosting - OS and its glue function. -*/ -#define EXIT_SUCCESS _PDCLIB_SUCCESS -#define EXIT_FAILURE _PDCLIB_FAILURE - -/* Initiate abnormal process termination, unless programm catches SIGABRT and - does not return from the signal handler. - This implementantion flushes all streams, closes all files, and removes any - temporary files before exiting with EXIT_FAILURE. - abort() does not return. -*/ -_PDCLIB_PUBLIC _PDCLIB_Noreturn void abort( void ) _PDCLIB_NORETURN; - -/* Register a function that will be called on quick_exit(). - At least 32 functions can be registered this way, and will be called in - reverse order of registration (last-in, first-out). - Returns zero if registration is successfull, nonzero if it failed. -*/ -_PDCLIB_PUBLIC int at_quick_exit( void ( *func )( void ) ); - -/* Register a function that will be called on exit(), or when main() returns. - At least 32 functions can be registered this way, and will be called in - reverse order of registration (last-in, first-out). - Returns zero if registration is successfull, nonzero if it failed. -*/ -_PDCLIB_PUBLIC int atexit( void ( *func )( void ) ); - -/* Normal process termination. Functions registered by atexit() (see above) are - called, streams flushed, files closed and temporary files removed before the - program is terminated with the given status. (See comment for EXIT_SUCCESS - and EXIT_FAILURE above.) - exit() does not return. -*/ -_PDCLIB_PUBLIC _PDCLIB_Noreturn void exit( int status ) _PDCLIB_NORETURN; - -/* Normal process termination. Functions registered by at_quick_exit() (see - above) are called, streams flushed, files closed and temporary files removed - before the program is terminated with the given status. (See comment for - EXIT_SUCCESS and EXIT_FAILURE above.) - quick_exit() does not return. -*/ -_PDCLIB_PUBLIC _PDCLIB_Noreturn void quick_exit( int status ) _PDCLIB_NORETURN; - -/* Normal process termination. Functions registered by atexit()/at_quick_exit() - (see above) are NOT CALLED. This implementation DOES flush streams, close - files and removes temporary files before the program is teminated with the - given status. (See comment for EXIT_SUCCESS and EXIT_FAILURE above.) - _Exit() does not return. -*/ -_PDCLIB_PUBLIC _PDCLIB_Noreturn void _Exit( int status ) _PDCLIB_NORETURN; - -/* Search an environment-provided key-value map for the given key name, and - return a pointer to the associated value string (or NULL if key name cannot - be found). The value string pointed to might be overwritten by a subsequent - call to getenv(). The library never calls getenv() itself. - Details on the provided keys and how to set / change them are determined by - the hosting OS and its glue function. -*/ -_PDCLIB_PUBLIC char * getenv( const char * name ); - -/* If string is a NULL pointer, system() returns nonzero if a command processor - is available, and zero otherwise. If string is not a NULL pointer, it is - passed to the command processor. If system() returns, it does so with a - value that is determined by the hosting OS and its glue function. -*/ -_PDCLIB_PUBLIC int system( const char * string ); - -/* Searching and sorting */ - -/* Do a binary search for a given key in the array with a given base pointer, - which consists of nmemb elements that are of the given size each. To compare - the given key with an element from the array, the given function compar is - called (with key as first parameter and a pointer to the array member as - second parameter); the function should return a value less than, equal to, - or greater than 0 if the key is considered to be less than, equal to, or - greater than the array element, respectively. - The function returns a pointer to a matching element found, or NULL if no - match is found. -*/ -_PDCLIB_PUBLIC void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int ( *compar )( const void *, const void * ) ); - -/* Do a quicksort on an array with a given base pointer, which consists of - nmemb elements that are of the given size each. To compare two elements from - the array, the given function compar is called, which should return a value - less than, equal to, or greater than 0 if the first argument is considered - to be less than, equal to, or greater than the second argument, respectively. - If two elements are compared equal, their order in the sorted array is not - specified. -*/ -_PDCLIB_PUBLIC void qsort( void * base, size_t nmemb, size_t size, int ( *compar )( const void *, const void * ) ); - -/* Integer arithmetic functions */ - -/* Return the absolute value of the argument. Note that on machines using two- - complement's notation (most modern CPUs), the largest negative value cannot - be represented as positive value. In this case, behaviour is unspecified. -*/ -_PDCLIB_PUBLIC int abs( int j ); -_PDCLIB_PUBLIC long int labs( long int j ); -_PDCLIB_PUBLIC long long int llabs( long long int j ); - -/* These structures each have a member quot and a member rem, of type int (for - div_t), long int (for ldiv_t) and long long it (for lldiv_t) respectively. - The order of the members is platform-defined to allow the div() functions - below to be implemented efficiently. -*/ -typedef struct _PDCLIB_div_t div_t; -typedef struct _PDCLIB_ldiv_t ldiv_t; -typedef struct _PDCLIB_lldiv_t lldiv_t; - -/* Return quotient (quot) and remainder (rem) of an integer division in one of - the structs above. -*/ -_PDCLIB_PUBLIC div_t div( int numer, int denom ); -_PDCLIB_PUBLIC ldiv_t ldiv( long int numer, long int denom ); -_PDCLIB_PUBLIC lldiv_t lldiv( long long int numer, long long int denom ); - -/* TODO: Multibyte / wide character conversion functions */ - -/* TODO: Macro MB_CUR_MAX */ - -/* -_PDCLIB_PUBLIC int mblen( const char * s, size_t n ); -_PDCLIB_PUBLIC int mbtowc( wchar_t * _PDCLIB_restrict pwc, const char * _PDCLIB_restrict s, size_t n ); -_PDCLIB_PUBLIC int wctomb( char * s, wchar_t wc ); -_PDCLIB_PUBLIC size_t mbstowcs( wchar_t * _PDCLIB_restrict pwcs, const char * _PDCLIB_restrict s, size_t n ); -_PDCLIB_PUBLIC size_t wcstombs( char * _PDCLIB_restrict s, const wchar_t * _PDCLIB_restrict pwcs, size_t n ); -*/ - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 - -#ifndef _PDCLIB_ERRNO_T_DEFINED -#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED -typedef int errno_t; -#endif - -#ifndef _PDCLIB_RSIZE_T_DEFINED -#define _PDCLIB_RSIZE_T_DEFINED _PDCLIB_RSIZE_T_DEFINED -typedef size_t rsize_t; -#endif - -/* A function type that can serve as a constraint handler (see below). The - first parameter is an error message on the constraint violation, the - second parameter a pointer to an implementation-defined object, the - third an error code related to the constraint violation. - If the function calling the constraint handler is defined to return - errno_t, the third parameter will be identical to the return value of - that function. - This implementation sets the second parameter of the constraint handler - call to NULL. -*/ -typedef void ( *constraint_handler_t )( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ); - -/* The currently active constraint violation handler. This implementation - sets abort_handler_s as the default constraint violation handler. -*/ -extern constraint_handler_t _PDCLIB_constraint_handler; - -/* Set the given function as the new constraint violation handler. */ -_PDCLIB_PUBLIC constraint_handler_t set_constraint_handler_s( constraint_handler_t handler ); - -/* One of two predefined constraint violation handlers. When called, it will - print an error message (including the message passed as the first - parameter to the handler function) and call abort(). -*/ -_PDCLIB_PUBLIC void abort_handler_s( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ); - -/* One of two predefined constraint violation handlers. Simply returns, - ignoring the constraint violation. -*/ -_PDCLIB_PUBLIC void ignore_handler_s( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ); - -/* Search an environment-provided key-value map for the given key name. - If the name is found, - - if len is not NULL, the length of the associated value string is stored - in that location. - - if len < maxsize, the value string is copied to the indicated location. - If the name is not found, - - if len is not NULL, a zero is stored in that location. - - if maxsize > 0, value[0] is set to the null character. - Details on the provided keys and how to set / change them are determined by - the hosting OS and its glue function. - The following conditions will be considered runtime constraint violations: - - value being a NULL pointer. - - maxsize == 0 or maxsize > RSIZE_MAX. - In case of a constraint violation, if len is not NULL a zero will be - stored at that location, and the environment key-value map not searched. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t getenv_s( size_t * _PDCLIB_restrict len, char * _PDCLIB_restrict value, rsize_t maxsize, const char * _PDCLIB_restrict name ); - -/* Do a binary search for a given key in the array with a given base pointer, - which consists of nmemb elements that are of the given size each. To compare - the given key with an element from the array, the given function compar is - called (with key as first parameter, a pointer to the array member as - second parameter, and the context parameter passed to bsearch_s() as third - parameter); the function should return a value less than, equal to, - or greater than 0 if the key is considered to be less than, equal to, or - greater than the array element, respectively. - The function returns a pointer to a matching element found, or NULL if no - match is found. - The following conditions will be considered runtime constraint violations: - - nmemb or size > RSIZE_MAX. - - nmemb > 0 and either of key, base, or compar being a null pointer. - In case of a constraint violation, the array will not be searched. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC void * bsearch_s( const void * key, const void * base, rsize_t nmemb, rsize_t size, int ( *compar )( const void * k, const void * y, void * context ), void * context ); - -/* Do a quicksort on an array with a given base pointer, which consists of - nmemb elements that are of the given size each. To compare two elements from - the array, the given function compar is called, with the first two arguments - being pointers to the two objects to be compared, and the third argument - being the context parameter passed to qsort_s. The compar function should - return a value less than, equal to, or greater than 0 if the first argument - is considered to be less than, equal to, or greater than the second argument, - respectively. If two elements are compared equal, their order in the sorted - array is not specified. - The following conditions will be considered runtime constraint violations: - - nmemb or size > RSIZE_MAX. - - nmemb > 0 and either of base or compar being a null pointer. - In case of a constraint violation, the array will not be sorted. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t qsort_s( void * base, rsize_t nmemb, rsize_t size, int ( *compar )( const void * x, const void * y, void * context ), void * context ); - -/* TODO: Multibyte / wide character functions */ - -#endif - -#ifdef __cplusplus -} -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDLIB_H -#include _PDCLIB_EXTEND_STDLIB_H -#endif - -#endif diff --git a/rocklibc/include/stdnoreturn.h b/rocklibc/include/stdnoreturn.h deleted file mode 100644 index ab4ddb4..0000000 --- a/rocklibc/include/stdnoreturn.h +++ /dev/null @@ -1,26 +0,0 @@ -/* _Noreturn - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_STDNORETURN_H -#define _PDCLIB_STDNORETURN_H _PDCLIB_STDNORETURN_H - -#include "pdclib/_PDCLIB_internal.h" - -/* This basically breaks the letter of the standard (which states that - noreturn be defined to _Noreturn). This defines noreturn -> _Noreturn - on C11 compliant compilers only (as older compilers do not know about - _Noreturn). -*/ -#define noreturn _PDCLIB_Noreturn - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STDNORETURN_H -#include _PDCLIB_EXTEND_STDNORETURN_H -#endif - -#endif diff --git a/rocklibc/include/string.h b/rocklibc/include/string.h index 05062fd..e633f4b 100644 --- a/rocklibc/include/string.h +++ b/rocklibc/include/string.h @@ -1,394 +1,14 @@ -/* String handling +#ifndef RLIBC_STRING_H +#define RLIBC_STRING_H - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ +#include -#ifndef _PDCLIB_STRING_H -#define _PDCLIB_STRING_H _PDCLIB_STRING_H +void *memcpy(void *restrict dest, const void *restrict src, size_t n); +void *memmove(void *dest, const void *src, size_t n); +void *memset(void *s, int c, size_t n); -#ifdef __cplusplus -extern "C" { -#endif +size_t strlen(const char *s); +int strcmp(const char *s1, const char *s2); +char *strcpy(char *dest, const char *src); -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -/* String function conventions */ - -/* - In any of the following functions taking a size_t n to specify the length of - an array or size of a memory region, n may be 0, but the pointer arguments to - the call shall still be valid unless otherwise stated. -*/ - -/* Copying functions */ - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1. If the two areas overlap, behaviour is undefined. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1. The two areas may overlap. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC void * memmove( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ); - -/* Copy the character array s2 (including terminating '\0' byte) into the - character array s1. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Copy a maximum of n characters from the character array s2 into the character - array s1. If s2 is shorter than n characters, '\0' bytes will be appended to - the copy in s1 until n characters have been written. If s2 is longer than n - characters, NO terminating '\0' will be written to s1. If the arrays overlap, - behaviour is undefined. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Concatenation functions */ - -/* Append the contents of the character array s2 (including terminating '\0') to - the character array s1 (first character of s2 overwriting the '\0' of s1). If - the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Append a maximum of n characters from the character array s2 to the character - array s1 (first character of s2 overwriting the '\0' of s1). A terminating - '\0' is ALWAYS appended, even if the full n characters have already been - written. If the arrays overlap, behaviour is undefined. - Returns the value of s1. -*/ -_PDCLIB_PUBLIC char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Comparison functions */ - -/* Compare the first n characters of the memory areas pointed to by s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -_PDCLIB_PUBLIC int memcmp( const void * s1, const void * s2, size_t n ); - -/* Compare the character arrays s1 and s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -_PDCLIB_PUBLIC int strcmp( const char * s1, const char * s2 ); - -/* Compare the character arrays s1 and s2, interpreted as specified by the - LC_COLLATE category of the current locale. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. - TODO: Currently a dummy wrapper for strcmp() as PDCLib does not yet support - locales. -*/ -_PDCLIB_PUBLIC int strcoll( const char * s1, const char * s2 ); - -/* Compare no more than the first n characters of the character arrays s1 and - s2. - Returns 0 if s1 == s2, a negative number if s1 < s2, and a positive number if - s1 > s2. -*/ -_PDCLIB_PUBLIC int strncmp( const char * s1, const char * s2, size_t n ); - -/* Transform the character array s2 as appropriate for the LC_COLLATE setting of - the current locale. If length of resulting string is less than n, store it in - the character array pointed to by s1. Return the length of the resulting - string. -*/ -_PDCLIB_PUBLIC size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ); - -/* Search functions */ - -/* Search the first n characters in the memory area pointed to by s for the - character c (interpreted as unsigned char). - Returns a pointer to the first instance found, or NULL. -*/ -_PDCLIB_PUBLIC void * memchr( const void * s, int c, size_t n ); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the first instance found, or NULL. -*/ -_PDCLIB_PUBLIC char * strchr( const char * s, int c ); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters not from the character array s2. - Returns the length of that substring. -*/ -_PDCLIB_PUBLIC size_t strcspn( const char * s1, const char * s2 ); - -/* Search the character array s1 for any character from the character array s2. - Returns a pointer to the first occurrence, or NULL. -*/ -_PDCLIB_PUBLIC char * strpbrk( const char * s1, const char * s2 ); - -/* Search the character array s (including terminating '\0') for the character c - (interpreted as char). - Returns a pointer to the last instance found, or NULL. -*/ -_PDCLIB_PUBLIC char * strrchr( const char * s, int c ); - -/* Determine the length of the initial substring of character array s1 which - consists only of characters from the character array s2. - Returns the length of that substring. -*/ -_PDCLIB_PUBLIC size_t strspn( const char * s1, const char * s2 ); - -/* Search the character array s1 for the substring in character array s2. - Returns a pointer to that sbstring, or NULL. If s2 is of length zero, - returns s1. -*/ -_PDCLIB_PUBLIC char * strstr( const char * s1, const char * s2 ); - -/* In a series of subsequent calls, parse a C string into tokens. - On the first call to strtok(), the first argument is a pointer to the to-be- - parsed C string. On subsequent calls, the first argument is NULL unless you - want to start parsing a new string. s2 holds an array of separator characters - which can differ from call to call. Leading separators are skipped, the first - trailing separator overwritten with '\0'. - Returns a pointer to the next token. - WARNING: This function uses static storage, and as such is not reentrant. -*/ -_PDCLIB_PUBLIC char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ); - -/* Miscellaneous functions */ - -/* Write the character c (interpreted as unsigned char) to the first n - characters of the memory area pointed to by s. - Returns s. -*/ -_PDCLIB_PUBLIC void * memset( void * s, int c, size_t n ); - -/* Map an error number to a (locale-specific) error message string. Error - numbers are typically errno values, but any number is mapped to a message. - TODO: PDCLib does not yet support locales. -*/ -_PDCLIB_PUBLIC char * strerror( int errnum ); - -/* Returns the length of the string s (excluding terminating '\0'). -*/ -_PDCLIB_PUBLIC size_t strlen( const char * s ); - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 - -#ifndef _PDCLIB_ERRNO_T_DEFINED -#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED -typedef int errno_t; -#endif - -#ifndef _PDCLIB_RSIZE_T_DEFINED -#define _PDCLIB_RSIZE_T_DEFINED _PDCLIB_RSIZE_T_DEFINED -typedef _PDCLIB_size_t rsize_t; -#endif - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1 of size s1max. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max or n being > RSIZE_MAX. - - n > s1max (not enough space in s1). - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max <= RSIZE_MAX - then the first s1max characters of s1 will be set to zero. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t memcpy_s( void * _PDCLIB_restrict s1, rsize_t s1max, const void * _PDCLIB_restrict s2, rsize_t n ); - -/* Copy a number of n characters from the memory area pointed to by s2 to the - area pointed to by s1 of size s1max. The two areas may overlap. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max or n being > RSIZE_MAX. - - n > s1max (not enough space in s1). - In case of a constraint violation, if s1 is not NULL and s1max <= RSIZE_MAX - then the first s1max characters of s1 will be set to zero. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t memmove_s( void * _PDCLIB_restrict s1, rsize_t s1max, const void * _PDCLIB_restrict s2, rsize_t n ); - -/* Copy the character array s2 (including terminating '\0' byte) into the - character array s1. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max being zero or > RSIZE_MAX. - - s1max not greater than strnlen_s( s2, s1max ) (not enough space in s1). - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max <= RSIZE_MAX - then s1[0] will be set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t strcpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 ); - -/* Copy a maximum of n characters from the character array s2 into the character - array s1. If s2 is longer than n, s1[n] will be set to '\0'. - Returns zero if successful, non-zero otherwise. - - ATTENTION ATTENTION ATTENTION - - This function differs in two fundamental ways from strncpy(): - - remaining space in s1 will NOT be zeroed. Their value is unspecified. - - s1 WILL be zero-terminated even if there is not enough space to hold - all n characters from s2. - - THANK YOU FOR YOUR ATTENTION. - - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max or n being > RSIZE_MAX. - - s1max being zero. - - n >= s1max and s1max <= strnlen_s( s2, s1max ) (not enough space in s1). - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max is greater - zero and <= RSIZE_MAX, s1[0] will be set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t strncpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n ); - -/* Append the contents of the character array s2 (including terminating '\0') to - the character array s1 (first character of s2 overwriting the '\0' of s1). - Elements following the terminating null character (if any) take unspecified - values. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max being > RSIZE_MAX. - - s1max being zero. - - not enough space in s1 for both s1 and the characters copied from s2. - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max is greater - zero and <= RSIZE_MAX, s1[0] will be set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t strcat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 ); - -/* Append a maximum of n characters from the character array s2 to the - character array s1 (first character of s2 overwriting the '\0' of s1). A - terminating '\0' is ALWAYS appended, even if the full n characters have - already been written. - Elements following the terminating null character (if any) take unspecified - values. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s1 or s2 being NULL. - - s1max or n being > RSIZE_MAX. - - s1max being zero. - - not enough space in s1 for both s1 and the characters copied from s2. - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max is greater - zero and <= RSIZE_MAX, s1[0] will be set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t strncat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n ); - -/* In a series of subsequent calls, parse a C string into tokens. - On the first call to strtok(), the first argument is a pointer to the to-be- - parsed C string of size *s1max. On subsequent calls, the first argument is - NULL unless you want to start parsing a new string. s2 holds an array of - separator characters which can differ from call to call. Leading separators - are skipped, the first trailing separator overwritten with '\0'. - Returns a pointer to the next token. - The following conditions will be considered runtime constraint violations: - - s1max, s2, or ptr being NULL. - - s1max or n being > RSIZE_MAX. - - s1max being zero. - - not enough space in s1 for both s1 and the characters copied from s2. - - copying between overlapping objects. - In case of a constraint violation, if s1 is not NULL and s1max is greater - zero and <= RSIZE_MAX, s1[0] will be set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC char * strtok_s( char * _PDCLIB_restrict s1, rsize_t * _PDCLIB_restrict s1max, const char * _PDCLIB_restrict s2, char ** _PDCLIB_restrict ptr ); - -/* Write the character c (interpreted as unsigned char) to the first n - characters of the memory area pointed to by s of size smax. - Returns zero if successful, non-zero otherwise. - The following conditions will be considered runtime constraint violations: - - s being NULL. - - smax or n being > RSIZE_MAX. - - n being > smax. - In case of a constraint violation, if s is not NULL and smax is <= RSIZE_MAX - the value of c (interpreted as unsigned char) is written to the first smax - characters of s. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t memset_s( void * s, rsize_t smax, int c, rsize_t n ); - -/* Map an error number to a (locale-specific) error message string. Error - numbers are typically errno values, but any number is mapped to a message. - TODO: PDCLib does not yet support locales. - If the length of the mapped string is < maxsize, the string is copied to s. - Otherwise, if maxsize is greater than zero, as much of the string as does - fit is copied, and s[maxsize-1] set to '\0'. If maxsize is greater than 3, - the partial string is made to end in "...". - Returns zero if the string was copied successfully in full, non-zero - otherwise. - The following conditions will be considered runtime constraint violations: - - s being NULL. - - maxsize being zero or > RSIZE_MAX. - In case of a constraint violation, s is not modified. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t strerror_s( char * s, rsize_t maxsize, errno_t errnum ); - -/* Map an error number to a (locale-specific) error message string, the same - way as strerror_s() would do. Error numbers are typically errno values, - but any number is mapped to a message. - TODO: PDCLib does not yet support locales. - Returns the length of the mapped string. -*/ -_PDCLIB_PUBLIC size_t strerrorlen_s( errno_t errnum ); - -/* Returns the length of the string s (excluding terminating '\0'). - If there is no null character in the first maxsize characters of s, - rerturns maxsize. If s is NULL, returns zero. - At most the first maxsize characters of s shall be accessed by the - function. -*/ -_PDCLIB_PUBLIC size_t strnlen_s( const char * s, size_t maxsize ); - -#endif - -#ifdef __cplusplus -} -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_STRING_H -#include _PDCLIB_EXTEND_STRING_H -#endif - -#endif +#endif \ No newline at end of file diff --git a/rocklibc/include/sys/stat.h b/rocklibc/include/sys/stat.h deleted file mode 100644 index 7225b36..0000000 --- a/rocklibc/include/sys/stat.h +++ /dev/null @@ -1,50 +0,0 @@ -#ifndef _SYS_STAT_H -#define _SYS_STAT_H - -#include - -// Basic POSIX types for i686 execution -typedef uint32_t dev_t; -typedef uint32_t ino_t; -typedef uint32_t mode_t; -typedef uint32_t nlink_t; -typedef uint32_t uid_t; -typedef uint32_t gid_t; -typedef int32_t off_t; -typedef int32_t time_t; - -// The stat layout expected by standard C files -struct stat { - dev_t st_dev; /* ID of device containing file */ - ino_t st_ino; /* Inode number */ - mode_t st_mode; /* File type and mode flags */ - nlink_t st_nlink; /* Number of hard links */ - uid_t st_uid; /* User ID of owner */ - gid_t st_gid; /* Group ID of owner */ - dev_t st_rdev; /* Device ID (if special file) */ - off_t st_size; /* Total size, in bytes */ - time_t st_atime; /* Time of last access */ - time_t st_mtime; /* Time of last modification */ - time_t st_ctime; /* Time of last status change */ -}; - -// Traditional POSIX file permission/type bitmasks -#define S_IFMT 0170000 /* Bitmask for the file type bit fields */ -#define S_IFSOCK 0140000 /* Socket */ -#define S_IFLNK 0120000 /* Symbolic link */ -#define S_IFREG 0100000 /* Regular file */ -#define S_IFBLK 0060000 /* Block device */ -#define S_IFDIR 0040000 /* Directory */ -#define S_IFCHR 0020000 /* Character device */ -#define S_IFIFO 0010000 /* FIFO */ - -#define S_IRUSR 00400 /* Owner has read permission */ -#define S_IWUSR 00200 /* Owner has write permission */ -#define S_IXUSR 00100 /* Owner has execute permission */ -#define S_IRWXU 00700 /* Owner has read, write, and execute permission */ - -// Helper check macros commonly used in PDCLib -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) - -#endif /* _SYS_STAT_H */ \ No newline at end of file diff --git a/rocklibc/include/sys/time.h b/rocklibc/include/sys/time.h deleted file mode 100644 index de1d7ce..0000000 --- a/rocklibc/include/sys/time.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef _SYS_TIME_H -#define _SYS_TIME_H - -#include - -// Represents an exact elapsed time signature -struct timeval { - time_t tv_sec; /* Seconds since Unix Epoch */ - int32_t tv_usec; /* Microseconds component */ -}; - -// Represents traditional timezone offsets (largely obsolete but required) -struct timezone { - int tz_minuteswest; /* Minutes west of Greenwich */ - int tz_dsttime; /* Type of DST correction */ -}; - -/* Prototype for time fetching system operation */ -int gettimeofday(struct timeval *restrict tv, void *restrict tz); - -#endif /* _SYS_TIME_H */ \ No newline at end of file diff --git a/rocklibc/include/sys/times.h b/rocklibc/include/sys/times.h deleted file mode 100644 index 0ca899e..0000000 --- a/rocklibc/include/sys/times.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _SYS_TIMES_H -#define _SYS_TIMES_H - -#include - -/* Structure describing CPU time used by a process and its children */ -struct tms { - clock_t tms_utime; /* User CPU time */ - clock_t tms_stime; /* System CPU time */ - clock_t tms_cutime; /* User CPU time of dead children */ - clock_t tms_cstime; /* System CPU time of dead children */ -}; - -/* Function prototype for timing system call */ -clock_t times(struct tms *buffer); - -#endif /* _SYS_TIMES_H */ \ No newline at end of file diff --git a/rocklibc/include/sys/types.h b/rocklibc/include/sys/types.h index be32cab..4215af9 100644 --- a/rocklibc/include/sys/types.h +++ b/rocklibc/include/sys/types.h @@ -1,29 +1,8 @@ -#ifndef _SYS_TYPES_H -#define _SYS_TYPES_H +#ifndef RLIBC_SYS_TYPES_H +#define RLIBC_SYS_TYPES_H -#include +typedef long off_t; -// Standard signed and unsigned size primitives -typedef int32_t ssize_t; -typedef uint32_t size_t; +typedef int ssize_t; -// Process and Thread IDs -typedef int32_t pid_t; -typedef int32_t id_t; - -// File system block and reference markers -typedef int32_t blkcnt_t; -typedef int32_t blksize_t; -typedef uint32_t dev_t; -typedef uint32_t gid_t; -typedef uint32_t ino_t; -typedef uint32_t mode_t; -typedef uint32_t nlink_t; -typedef int32_t off_t; -typedef uint32_t uid_t; - -// Clock and Timing fields -typedef int32_t time_t; -typedef int32_t clock_t; - -#endif /* _SYS_TYPES_H */ \ No newline at end of file +#endif \ No newline at end of file diff --git a/rocklibc/include/syscall.h b/rocklibc/include/syscall.h new file mode 100644 index 0000000..5838a1b --- /dev/null +++ b/rocklibc/include/syscall.h @@ -0,0 +1,22 @@ +#ifndef RLIBC_SYSCALL_H +#define RLIBC_SYSCALL_H + +#include +#include + +#define SYS_EXIT 1 +#define SYS_READ 3 +#define SYS_WRITE 4 + +int write(int fd, const void *buf, size_t count); +int read(int fd, void *buf, size_t count); +int close(int fd); + +size_t lseek(int fd, size_t offset, int whence); + +void exit(int status) __attribute__((noreturn)); + +void *sbrk(intptr_t increment); +int brk(void *addr); + +#endif \ No newline at end of file diff --git a/rocklibc/include/time.h b/rocklibc/include/time.h deleted file mode 100644 index 17ae34f..0000000 --- a/rocklibc/include/time.h +++ /dev/null @@ -1,191 +0,0 @@ -/* Date and time - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_TIME_H -#define _PDCLIB_TIME_H _PDCLIB_TIMEH - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_lib_ext1.h" -#include "pdclib/_PDCLIB_internal.h" - -#ifndef _PDCLIB_SIZE_T_DEFINED -#define _PDCLIB_SIZE_T_DEFINED _PDCLIB_SIZE_T_DEFINED -typedef _PDCLIB_size_t size_t; -#endif - -#ifndef _PDCLIB_NULL_DEFINED -#define _PDCLIB_NULL_DEFINED _PDCLIB_NULL_DEFINED -#define NULL _PDCLIB_NULL -#endif - -/* See comments in _PDCLIB_config.h on the semantics of time_t and clock_t. */ - -typedef _PDCLIB_time_t time_t; -typedef _PDCLIB_clock_t clock_t; - -#define CLOCKS_PER_SEC _PDCLIB_CLOCKS_PER_SEC -#define TIME_UTC _PDCLIB_TIME_UTC - -/* Implementor's note: If you change this structure, and are using Pthread - threading support, check auxiliary/pthread/pthread_readout.c for its - twin. It is imperative that Pthread and PDCLib use identical layouts for - struct timespec, as they are implicitly cast from one to the other. This - cannot be checked for in this header (as we may not include host system - headers here), so the assert()s are in pthread_readout.c (which, in turn, - cannot include *this* header, which is why this admonishment to keep the - definitions in sync exists...). -*/ -struct timespec -{ - time_t tv_sec; - long tv_nsec; -}; - -struct tm -{ - int tm_sec; /* 0-60 */ - int tm_min; /* 0-59 */ - int tm_hour; /* 0-23 */ - int tm_mday; /* 1-31 */ - int tm_mon; /* 0-11 */ - int tm_year; /* years since 1900 */ - int tm_wday; /* 0-6 */ - int tm_yday; /* 0-365 */ - int tm_isdst; /* >0 DST, 0 no DST, <0 information unavailable */ -}; - -/* Returns the number of "clocks" in processor time since the invocation - of the program. Divide by CLOCKS_PER_SEC to get the value in seconds. - Returns -1 if the value cannot be represented in the return type or is - not available. -*/ -_PDCLIB_PUBLIC clock_t clock( void ); - -/* Returns the difference between two calendar times in seconds. */ -_PDCLIB_PUBLIC double difftime( time_t time1, time_t time0 ); - -/* Normalizes the values in the broken-down time pointed to by timeptr. - Returns the calender time specified by the broken-down time. -*/ -_PDCLIB_PUBLIC time_t mktime( struct tm * timeptr ); - -/* Returns the current calender time. If timer is not a NULL pointer, stores - the current calender time at that address as well. -*/ -_PDCLIB_PUBLIC time_t time( time_t * timer ); - -/* Sets the interval pointed to by ts to the current calender time, based - on the specified base. - Returns base, if successful, otherwise zero. -*/ -_PDCLIB_PUBLIC int timespec_get( struct timespec * ts, int base ); - -/* Converts the broken-down time pointed to by timeptr into a string in the - form "Sun Sep 16 01:03:52 1973\n\0". -*/ -_PDCLIB_PUBLIC char * asctime( const struct tm * timeptr ); - -/* Equivalent to asctime( localtime( timer ) ). */ -_PDCLIB_PUBLIC char * ctime( const time_t * timer ); - -/* Converts the calender time pointed to by timer into a broken-down time - expressed as UTC. - Returns a pointer to the broken-down time, or a NULL pointer if it - cannot be represented. -*/ -_PDCLIB_PUBLIC struct tm * gmtime( const time_t * timer ); - -/* Converts the calender time pointed to by timer into a broken-down time - expressed as local time. - Returns a pointer to the broken-down time, or a NULL pointer if if - cannot be represented. -*/ -_PDCLIB_PUBLIC struct tm * localtime( const time_t * timer ); - -/* Writes the broken-down time pointed to by timeptr into the character - array pointed to by s. The string pointed to by format controls the - exact output. No more than maxsize charactrs will be written. - Returns the number of characters written (excluding the terminating - null character), or zero on failure. -*/ -_PDCLIB_PUBLIC size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ); - -/* Annex K -- Bounds-checking interfaces */ - -#if ( __STDC_WANT_LIB_EXT1__ + 0 ) != 0 - -#ifndef _PDCLIB_ERRNO_T_DEFINED -#define _PDCLIB_ERRNO_T_DEFINED _PDCLIB_ERRNO_T_DEFINED -typedef int errno_t; -#endif - -#ifndef _PDCLIB_RSIZE_T_DEFINED -#define _PDCLIB_RSIZE_T_DEFINED _PDCLIB_RSIZE_T_DEFINED -typedef _PDCLIB_size_t rsize_t; -#endif - -/* Converts the broken-down time pointed to by timeptr into a string in the - form "Sun Sep 16 01:03:52 1973\n\0", which is stored in buffer s of maxsize. - Returns zero if the time was successfully converted and stored, non-zero - otherwise. - The following conditions will be considered runtime constraint violations: - - s or timeptr being NULL. - - maxsize being < 26 or > RSIZE_MAX. - - the broken-down time pointed to by timeptr not being normalized. - - the year represented by the broken-down time pointed to by timeptr - being < 0 or > 9999. - In case of a constraint violation, the time will not be converted. If - s is not NULL and maxsize is neither zero nor > RSIZE_MAX, s[0] will be - set to '\0'. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC errno_t asctime_s( char * s, rsize_t maxsize, const struct tm * timeptr ); - -/* Equivalent to asctime_s( s, maxsize, localtime( timer ) ). */ -_PDCLIB_PUBLIC errno_t ctime_s( char * s, rsize_t maxsize, const time_t * timer ); - -/* Converts the calender time pointed to by timer into a broken-down time - expressed as UTC, which gets stored in the result struct. - Returns a pointer to the broken-down time, or a NULL pointer if if - cannot be represented or stored. - The following conditions will be considered runtime constraint violations: - - timer or result being NULL. - In case of a constraint violation, the time will not be converted. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC struct tm * gmtime_s( const time_t * _PDCLIB_restrict timer, struct tm * _PDCLIB_restrict result ); - -/* Converts the calender time pointed to by timer into a broken-down time - expressed as local time, which gets stored in the result struct. - Returns a pointer to the broken-down time, or a NULL pointer if if - cannot be represented or stored. - The following conditions will be considered runtime constraint violations: - - timer or result being NULL. - In case of a constraint violation, the time will not be converted. - The currently active constraint violation handler function will be called - (see set_constraint_handler_s()). -*/ -_PDCLIB_PUBLIC struct tm * localtime_s( const time_t * _PDCLIB_restrict timer, struct tm * _PDCLIB_restrict result ); - -#endif - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_TIME_H -#include _PDCLIB_EXTEND_TIME_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/include/unistd.h b/rocklibc/include/unistd.h index 35ce2bb..7fe0f4c 100644 --- a/rocklibc/include/unistd.h +++ b/rocklibc/include/unistd.h @@ -1,28 +1,15 @@ -#ifndef _UNISTD_H -#define _UNISTD_H +#ifndef RLIBC_UNISTD_H +#define RLIBC_UNISTD_H +#include #include -/* Standard file descriptors used by streams */ -#define STDIN_FILENO 0 /* Standard input */ -#define STDOUT_FILENO 1 /* Standard output */ -#define STDERR_FILENO 2 /* Standard error output */ +#define STDIN_FILENO 0 +#define STDOUT_FILENO 1 +#define STDERR_FILENO 2 -/* Seek constants for lseek() / _PDCLIB_lseek() */ -#ifndef SEEK_SET -#define SEEK_SET 0 /* Seek from beginning of file */ -#define SEEK_CUR 1 /* Seek from current position */ -#define SEEK_END 2 /* Seek from end of file */ -#endif +#define SEEK_SET 0 +#define SEEK_CUR 1 +#define SEEK_END 2 -/* Null pointer declaration constant */ -#ifndef NULL -#define NULL ((void *)0) -#endif - -int open(const char *pathname, int flags, ...); -int read(int fd, void *buf, size_t count); -int close(int fd); - - -#endif /* _UNISTD_H */ \ No newline at end of file +#endif \ No newline at end of file diff --git a/rocklibc/include/wctype.h b/rocklibc/include/wctype.h deleted file mode 100644 index 3776b7a..0000000 --- a/rocklibc/include/wctype.h +++ /dev/null @@ -1,152 +0,0 @@ -/* Wide character classification and mapping utilities - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef _PDCLIB_WCTYPE_H -#define _PDCLIB_WCTYPE_H _PDCLIB_WCTYPE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "pdclib/_PDCLIB_internal.h" - -typedef _PDCLIB_wint_t wint_t; -typedef int wctrans_t; -typedef int wctype_t; - -#ifndef _PDCLIB_WEOF_DEFINED -#define _PDCLIB_WEOF_DEFINED _PDCLIB_WEOF_DEFINED -#define WEOF (wint_t)-1 -#endif - -/* Wide character classification functions */ - -/* Returns iswalpha( wc ) || iswdigit( wc ) */ -_PDCLIB_PUBLIC int iswalnum( wint_t wc ); - -/* Returns true for wide characters for which either isupper( wc ) or - islower( wc ) is true, as well as a set of locale-specific wide - characters which are neither control characters, digits, punctuation, - or whitespace. -*/ -_PDCLIB_PUBLIC int iswalpha( wint_t wc ); - -/* Returns true if the character iswspace() and used for separating words - within a line of text. In the "C" locale, only L' ' and L'\t' are - considered blanks. -*/ -_PDCLIB_PUBLIC int iswblank( wint_t wc ); - -/* Returns true if the wide character is a control character. */ -_PDCLIB_PUBLIC int iswcntrl( wint_t wc ); - -/* Returns true if the wide character is a decimal digit. Locale- - independent. */ -_PDCLIB_PUBLIC int iswdigit( wint_t wc ); - -/* Returns iswprint( wc ) && ! iswspace( wc ). - NOTE: This definition differs from that of isgraph() in , - which considers only ' ', not all isspace() characters. -*/ -_PDCLIB_PUBLIC int iswgraph( wint_t wc ); - -/* Returns true for lowerspace wide characters, as well as a set of - locale-specific wide characters which are neither control charcters, - digits, punctuation, or whitespace. -*/ -_PDCLIB_PUBLIC int iswlower( wint_t wc ); - -/* Returns true for every printing wide character. */ -_PDCLIB_PUBLIC int iswprint( wint_t wc ); - -/* Returns true for a locale-specific set of punctuation characters that - are neither whitespace nor alphanumeric. -*/ -_PDCLIB_PUBLIC int iswpunct( wint_t wc ); - -/* Returns true for a locale-specific set of whitespace characters that - are neither alphanumeric, graphic, or punctuation. -*/ -_PDCLIB_PUBLIC int iswspace( wint_t wc ); - -/* Returns true for upperspace wide characters, as well as a set of - locale-specific wide characters which are neither control charcters, - digits, punctuation, or whitespace. -*/ -_PDCLIB_PUBLIC int iswupper( wint_t wc ); - -/* Returns true if the wide character is a hexadecimal digit. Locale- - independent. */ -_PDCLIB_PUBLIC int iswxdigit( wint_t wc ); - -/* Extensible wide character classification functions */ - -/* Returns true if the wide character wc has the property described by - desc (which was retrieved by a previous call to wctype() without - changing the LC_CTYPE locale setting between the two calls). -*/ -_PDCLIB_PUBLIC int iswctype( wint_t wc, wctype_t desc ); - -/* Returns a description object for a named character property, to be - used as parameter to the iswctype() function. Supported property - names are: - "alnum" -- alphanumeric, as per iswalnum() - "alpha" -- alphabetic, as per iswalpha() - "blank" -- blank, as per iswblank() - "cntrl" -- control, as per iswcntrl() - "digit" -- decimal digit, as per iswdigit() - "graph" -- graphic, as per iswgraph() - "lower" -- lowercase, as per iswlower() - "print" -- printing, as per iswprint() - "punct" -- punctuation, as per iswprint() - "space" -- whitespace, as per iswspace() - "upper" -- uppercase, as per iswupper() - "xdigit" -- hexadecimal digit, as per iswxdigit() - For unsupported properties, the function returns zero. -*/ -_PDCLIB_PUBLIC wctype_t wctype( const char * property ); - -/* Wide character case mapping utilities */ - -/* Converts an uppercase letter to a corresponding lowercase letter. Input for - which no corresponding lowercase letter exists remains unchanged. -*/ -_PDCLIB_PUBLIC wint_t towlower( wint_t wc ); - -/* Converts a lowercase letter to a corresponding uppercase letter. Input for - which no corresponding uppercase letter exists remains unchanged. -*/ -_PDCLIB_PUBLIC wint_t towupper( wint_t wc ); - -/* Extensible wide character case mapping utilities */ - -/* Converts the wide character wc according to the transition described - by desc (which was retrieved by a previous call to wctrans() without - changing the LC_CTYPE locale setting between the two calls). -*/ -_PDCLIB_PUBLIC wint_t towctrans( wint_t wc, wctrans_t desc ); - -/* Returns a description object for a named character transformation, to - be used as parameter to the towctrans() function. Supported transformation - properties are: - "tolower" -- lowercase mapping, as per towlower() - "toupper" -- uppercase mapping, as per towupper() - For unsupported properties, the function returns zero. -*/ -_PDCLIB_PUBLIC wctrans_t wctrans( const char * property ); - -/* Extension hook for downstream projects that want to have non-standard - extensions to standard headers. -*/ -#ifdef _PDCLIB_EXTEND_WCTYPE_H -#include _PDCLIB_EXTEND_WCTYPE_H -#endif - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/rocklibc/makefile b/rocklibc/makefile index f5a54fe..8fdc2ba 100644 --- a/rocklibc/makefile +++ b/rocklibc/makefile @@ -1,7 +1,6 @@ CC = i686-elf-gcc AR = i686-elf-ar -CFLAGS = -ffreestanding -O2 -Wall -Wextra -Iinclude -DHAVE_MMAP=0 -DLACKS_SYS_MMAN_H=1 -DUSE_LOCKS=0 -DLACKS_SYS_PARAM_H=1 -CFLAGS += -ffunction-sections -fdata-sections +CFLAGS = -ffreestanding -O2 -Wall -Wextra -Iinclude TARGET = rlibc.a SRCS = $(shell find src -name "*.c") diff --git a/rocklibc/src/_PDCLIB/Readme.txt b/rocklibc/src/_PDCLIB/Readme.txt deleted file mode 100644 index 13ad05c..0000000 --- a/rocklibc/src/_PDCLIB/Readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -This directory holds various "internals" of PDCLib: - -- definitions of helper functions not specified by the standard (hidden in the - _PDCLIB_* namespace); - -- definitions of data objects, both internal (like _PDCLIB_digits) and specified by - the standard (_PDCLIB_errno); - -- test drivers for functionality that does not have its own implementation - file to put the test driver in (stdarg). diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_Exit.c b/rocklibc/src/_PDCLIB/_PDCLIB_Exit.c deleted file mode 100644 index b5c5fd2..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_Exit.c +++ /dev/null @@ -1,48 +0,0 @@ -/* _PDCLIB_Exit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_Exit() fit for use with POSIX - kernels. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern _PDCLIB_Noreturn void _exit( int status ) _PDCLIB_NORETURN; - -#ifdef __cplusplus -} -#endif - -void _PDCLIB_Exit( int status ) -{ - _exit( status ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - int UNEXPECTED_RETURN = 0; - _PDCLIB_Exit( 0 ); - TESTCASE( UNEXPECTED_RETURN ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_atomax.c b/rocklibc/src/_PDCLIB/_PDCLIB_atomax.c deleted file mode 100644 index c8fe665..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_atomax.c +++ /dev/null @@ -1,59 +0,0 @@ -/* _PDCLIB_atomax( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -_PDCLIB_intmax_t _PDCLIB_atomax( const char * s ) -{ - _PDCLIB_intmax_t rc = 0; - char sign = '+'; - const char * x; - - /* TODO: In other than "C" locale, additional patterns may be defined */ - while ( isspace( (unsigned char)*s ) ) - { - ++s; - } - - if ( *s == '+' ) - { - ++s; - } - else if ( *s == '-' ) - { - sign = *( s++ ); - } - - /* TODO: Earlier version was missing tolower() but was not caught by tests */ - while ( ( x = (const char *)memchr( _PDCLIB_digits, tolower( (unsigned char)*( s++ ) ), 10 ) ) != NULL ) - { - rc = rc * 10 + ( x - _PDCLIB_digits ); - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - /* basic functionality */ - TESTCASE( _PDCLIB_atomax( "123" ) == 123 ); - /* testing skipping of leading whitespace and trailing garbage */ - TESTCASE( _PDCLIB_atomax( " \n\v\t\f123xyz" ) == 123 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_add.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_add.c deleted file mode 100644 index caf029e..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_add.c +++ /dev/null @@ -1,83 +0,0 @@ -/* _PDCLIB_bigint_add( bigint_t *, bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_add( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ) -{ - unsigned i = 0; - _PDCLIB_bigint_arith_t arith = 0; - - for ( i = bigint->size; i < other->size; ++i ) - { - bigint->data[i] = 0; - } - - bigint->size = i; - - for ( i = 0; i < bigint->size; ++i ) - { - arith += bigint->data[i] + other->data[i]; - bigint->data[i] = arith & ( ( (_PDCLIB_bigint_arith_t)1 << _PDCLIB_BIGINT_DIGIT_BITS ) - 1 ); - arith >>= _PDCLIB_BIGINT_DIGIT_BITS; - } - - if ( arith > 0 ) - { - bigint->data[i] = arith; - --(bigint->size); - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t testdata[] = - { - { 1, { 0x0001u } }, - { 2, { (_PDCLIB_bigint_digit_t)( ( (_PDCLIB_bigint_arith_t)1 << _PDCLIB_BIGINT_DIGIT_BITS ) - 1 ), 0x0001u } }, - { 1, { 0x0002u } }, - { 2, { 0x0001u, 0x0002u } }, - { 2, { 0x0000u, 0x0002u } } - }; - - /* 1 + 1 */ - _PDCLIB_bigint_from_digit( &bigint, 1 ); - _PDCLIB_bigint_add( &bigint, &bigint ); - _PDCLIB_bigint_cmp( &bigint, &testdata[2] ); - - /* 1 + 0x0001 0xFFFF -- carry */ - _PDCLIB_bigint_add( &bigint, &testdata[1] ); - _PDCLIB_bigint_cmp( &bigint, &testdata[3] ); - - /* 0x0001 0xFFFF + 1 -- carry */ - _PDCLIB_bigint_from_bigint( &bigint, &testdata[1] ); - _PDCLIB_bigint_add( &bigint, &testdata[0] ); - _PDCLIB_bigint_cmp( &bigint, &testdata[4] ); - - /* 0 + 0 */ - _PDCLIB_bigint_from_digit( &bigint, 0 ); - _PDCLIB_bigint_add( &bigint, &bigint ); - TESTCASE( bigint.size == 0 ); - - /* 0 + 1 */ - _PDCLIB_bigint_add( &bigint, &testdata[0] ); - _PDCLIB_bigint_cmp( &bigint, &testdata[0] ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_cmp.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_cmp.c deleted file mode 100644 index 664cdc3..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_cmp.c +++ /dev/null @@ -1,74 +0,0 @@ -/* _PDCLIB_bigint_cmp( bigint_t const *, bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -int _PDCLIB_bigint_cmp( _PDCLIB_bigint_t const * lhs, _PDCLIB_bigint_t const * rhs ) -{ - _PDCLIB_size_t i = lhs->size; - - if ( i != rhs->size ) - { - return i > rhs->size ? 1 : -1; - } - - while ( i-- > 0 ) - { - if ( lhs->data[i] != rhs->data[i] ) - { - return lhs->data[i] > rhs->data[i] ? 1 : -1; - } - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t lhs, rhs; - _PDCLIB_bigint_t testdata[] = - { - { 2, { 0, 0x0001u } }, - { 1, { 1 } } - }; - - _PDCLIB_bigint_from_digit( &lhs, 0 ); - _PDCLIB_bigint_from_digit( &rhs, 0 ); - - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) == 0 ); - - _PDCLIB_bigint_add( &lhs, &testdata[1] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) > 0 ); - - _PDCLIB_bigint_add( &rhs, &testdata[1] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) == 0 ); - - _PDCLIB_bigint_add( &rhs, &testdata[1] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) < 0 ); - - _PDCLIB_bigint_from_bigint( &lhs, &testdata[0] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) > 0 ); - - _PDCLIB_bigint_from_bigint( &rhs, &testdata[0] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) == 0 ); - - _PDCLIB_bigint_add( &rhs, &testdata[1] ); - TESTCASE( _PDCLIB_bigint_cmp( &lhs, &rhs ) < 0 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_digit_log2.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_digit_log2.c deleted file mode 100644 index 06946d0..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_digit_log2.c +++ /dev/null @@ -1,83 +0,0 @@ -/* _PDCLIB_bigint_digit_log2( bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_bigint_digit_log2( _PDCLIB_bigint_digit_t digit ) -{ - unsigned char log2_lookup[] = - { - 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, - 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 - }; - _PDCLIB_bigint_digit_t t; - -#if _PDCLIB_BIGINT_DIGIT_BITS > 16 - if ( ( t = ( digit >> 24 ) ) ) - { - return log2_lookup[ t ] + 24; - } - else if ( ( t = ( digit >> 16 ) ) ) - { - return log2_lookup[ t ] + 16; - } - else -#endif - if ( ( t = ( digit >> 8 ) ) ) - { - return log2_lookup[ t ] + 8; - } - else if ( digit > 0 ) - { - return log2_lookup[ digit ]; - } - else - { - return -1; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - unsigned i; - - for ( i = 1; i < (1 << _PDCLIB_BIGINT_DIGIT_BITS); ++i ) - { - //TESTCASE( _PDCLIB_bigint_digit_log2( i ) == (int)log2( i ) ); - } -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_div.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_div.c deleted file mode 100644 index 56a5a0b..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_div.c +++ /dev/null @@ -1,135 +0,0 @@ -/* _PDCLIB_bigint_div( bigint_t *, bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -unsigned _PDCLIB_bigint_div( _PDCLIB_bigint_t * dividend, _PDCLIB_bigint_t const * divisor ) -{ - _PDCLIB_bigint_digit_t quotient; - _PDCLIB_size_t s = dividend->size; - _PDCLIB_size_t i; - - assert( divisor->size > 0 ); - assert( s <= divisor->size ); - assert( divisor->data[ divisor->size - 1 ] < _PDCLIB_BIGINT_DIGIT_MAX ); - - if ( s < divisor->size || dividend->data[ s - 1 ] < divisor->data[ s - 1 ]) - { - return 0; - } - - /* With dividend truncated, and divisor + 1, - this quotient might be one short of correct. - */ - quotient = dividend->data[ s - 1 ] / ( divisor->data[ s - 1 ] + 1 ); - - if ( quotient > 0 ) - { - /* dividend = dividend - (divisor * quotient) */ - _PDCLIB_bigint_arith_t t = 0; - _PDCLIB_bigint_arith_t d = 0; - - for ( i = 0; i < s; ++i ) - { - t += (_PDCLIB_bigint_arith_t)divisor->data[i] * quotient; - d = (_PDCLIB_bigint_arith_t)dividend->data[i] - ( t & _PDCLIB_BIGINT_DIGIT_MAX ) - d; - - dividend->data[i] = d & _PDCLIB_BIGINT_DIGIT_MAX; - t >>= _PDCLIB_BIGINT_DIGIT_BITS; - d >>= _PDCLIB_BIGINT_DIGIT_BITS; - d &= 1; - } - } - - /* dividend might have leading zero digits here, - but that does not matter for the compare or - the subsequent substraction. - */ - if ( _PDCLIB_bigint_cmp( dividend, divisor ) >= 0 ) - { - /* quotient was too small, substract divisor once more. */ - _PDCLIB_bigint_arith_t d = 0; - ++quotient; - - for ( i = 0; i < s; ++i ) - { - d = (_PDCLIB_bigint_arith_t)dividend->data[i] - divisor->data[i] - d; - dividend->data[i] = d & _PDCLIB_BIGINT_DIGIT_MAX; - d >>= _PDCLIB_BIGINT_DIGIT_BITS; - d &= 1; - } - } - - /* size down dividend if it has leading zero digits. */ - while ( dividend->size > 0 && dividend->data[ dividend->size - 1 ] == 0 ) - { - --dividend->size; - } - - return quotient; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t dividend; - _PDCLIB_bigint_t divisor; - _PDCLIB_bigint_t testdata[] = - { - { 1, { 0x1234 } }, - { 2, { 0x2345, 0x0001 } }, - { 1, { 0x4000 } }, - { 1, { 0x3FFF } }, - { 1, { 0x0001 } }, - { 1, { _PDCLIB_BIGINT_DIGIT_MAX } }, - { 1, { 0xFFF9 } }, - { 1, { 0x1C71 } } - }; - - /* dividend < divisor */ - _PDCLIB_bigint_from_bigint( ÷nd, &testdata[0] ); - _PDCLIB_bigint_from_bigint( &divisor, &testdata[1] ); - TESTCASE( _PDCLIB_bigint_div( ÷nd, &divisor ) == 0 ); - TESTCASE( _PDCLIB_bigint_cmp( ÷nd, &testdata[0] ) == 0 ); - - _PDCLIB_bigint_from_bigint( ÷nd, &testdata[3] ); - _PDCLIB_bigint_from_bigint( &divisor, &testdata[2] ); - TESTCASE( _PDCLIB_bigint_div( ÷nd, &divisor ) == 0 ); - TESTCASE( _PDCLIB_bigint_cmp( ÷nd, &testdata[3] ) == 0 ); - - /* dividend = divisor + 1 */ - _PDCLIB_bigint_from_bigint( ÷nd, &testdata[2] ); - _PDCLIB_bigint_from_bigint( &divisor, &testdata[3] ); - TESTCASE( _PDCLIB_bigint_div( ÷nd, &divisor ) == 1 ); - TESTCASE( _PDCLIB_bigint_cmp( ÷nd, &testdata[4] ) == 0 ); - - /* dividend = divisor * 9 */ - _PDCLIB_bigint_from_bigint( ÷nd, &testdata[6] ); - _PDCLIB_bigint_from_bigint( &divisor, &testdata[7] ); - TESTCASE( _PDCLIB_bigint_div( ÷nd, &divisor ) == 9 ); - TESTCASE( dividend.size == 0 ); - - /* dividend = divisor * 9 + rem */ - _PDCLIB_bigint_from_bigint( ÷nd, &testdata[5] ); - _PDCLIB_bigint_from_digit( &divisor, testdata[5].data[0] / 9 ); - TESTCASE( _PDCLIB_bigint_div( ÷nd, &divisor ) == 9 ); - TESTCASE( dividend.data[0] == ( testdata[5].data[0] % 9 ) ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_bigint.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_bigint.c deleted file mode 100644 index 2046e8c..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_bigint.c +++ /dev/null @@ -1,54 +0,0 @@ -/* _PDCLIB_bigint_from_bigint( bigint_t *, bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_from_bigint( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ) -{ - _PDCLIB_size_t i; - - for ( i = 0; i < other->size; ++i ) - { - bigint->data[i] = other->data[i]; - } - - bigint->size = other->size; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t testdata[] = - { - /* Only 16bit, works with 32bit digits as well. */ - { 0, { 0u } }, - { 1, { 0xFFFFu } }, - { 2, { 0xAAAAu, 0xFFFFu } } - }; - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[0] ); - TESTCASE( bigint.size == 0 ); - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[1] ); - _PDCLIB_bigint_cmp( &bigint, &testdata[1] ); - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[2] ); - _PDCLIB_bigint_cmp( &bigint, &testdata[2] ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_digit.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_digit.c deleted file mode 100644 index 5714aea..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_digit.c +++ /dev/null @@ -1,43 +0,0 @@ -/* _PDCLIB_bigint_from_digit( bigint_t *, digit_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_from_digit( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_digit_t digit ) -{ - bigint->size = ( digit > 0 ); - bigint->data[0] = digit; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - - _PDCLIB_bigint_from_digit( &bigint, 0 ); - TESTCASE( bigint.size == 0 ); - - _PDCLIB_bigint_from_digit( &bigint, 1 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 1 ); - - _PDCLIB_bigint_from_digit( &bigint, _PDCLIB_BIGINT_DIGIT_MAX ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == _PDCLIB_BIGINT_DIGIT_MAX ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow10.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow10.c deleted file mode 100644 index 49b7a25..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow10.c +++ /dev/null @@ -1,131 +0,0 @@ -/* _PDCLIB_bigint_from_pow10( bigint_t *, unsigned ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_from_pow10( _PDCLIB_bigint_t * bigint, unsigned pow ) -{ - _PDCLIB_bigint_t powers_of_10[] = - { - { 1, { 0x0001u } }, - { 1, { 0x000au } }, - { 1, { 0x0064u } }, - { 1, { 0x03e8u } }, - { 1, { 0x2710u } }, - { 2, { 0x86a0u, 0x0001u } }, - { 2, { 0x4240u, 0x000fu } }, - { 2, { 0x9680u, 0x0098u } }, - { 2, { 0xe100u, 0x05f5u } }, - { 4, { 0x0000u, 0x6fc1u, 0x86f2u, 0x0023u } }, - { 7, { 0x0000u, 0x0000u, 0xef81u, 0x85acu, - 0x415bu, 0x2d6du, 0x04eeu } }, - { 14, { 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x1f01u, 0xbf6au, 0xed64u, 0x6e38u, - 0x97edu, 0xdaa7u, 0xf9f4u, 0xe93fu, - 0x4f03u, 0x0018u } }, - { 27, { 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x3e01u, 0x2e95u, 0x9909u, 0x03dfu, - 0x38fdu, 0x0f15u, 0xe42fu, 0x2374u, - 0xf5ecu, 0xd3cfu, 0xdc08u, 0xc404u, - 0xb0dau, 0xbccdu, 0x7f19u, 0xa633u, - 0x2603u, 0xe91fu, 0x024eu } }, - { 54, { 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x0000u, 0x0000u, 0x0000u, 0x0000u, - 0x7c01u, 0x982eu, 0x875bu, 0xbed3u, - 0x9f72u, 0xd8d9u, 0x2f87u, 0x1215u, - 0x50c6u, 0x6bdeu, 0x6e70u, 0xcf4au, - 0xd80fu, 0xd595u, 0x716eu, 0x26b2u, - 0x66b0u, 0xadc6u, 0x3624u, 0x1d15u, - 0xd35au, 0x3c42u, 0x540eu, 0x63ffu, - 0x73c0u, 0xcc55u, 0xef17u, 0x65f9u, - 0x28f2u, 0x55bcu, 0xc7f7u, 0x80dcu, - 0xeddcu, 0xf46eu, 0xefceu, 0x5fdcu, - 0x53f7u, 0x0005u } } - }; - - _PDCLIB_size_t index = 8; - - _PDCLIB_bigint_from_bigint( bigint, &powers_of_10[ pow & 7 ] ); - pow >>= 3; - - while ( pow > 0 ) - { - if ( pow & 1 ) - { - _PDCLIB_bigint_mul( bigint, &powers_of_10[ index ] ); - } - - pow >>= 1; - ++index; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - - _PDCLIB_bigint_from_pow10( &bigint, 0 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 1 ); - - _PDCLIB_bigint_from_pow10( &bigint, 1 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 10 ); - - _PDCLIB_bigint_from_pow10( &bigint, 2 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 100 ); - - _PDCLIB_bigint_from_pow10( &bigint, 3 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 1000 ); - - _PDCLIB_bigint_from_pow10( &bigint, 4 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 10000 ); - - _PDCLIB_bigint_from_pow10( &bigint, 5 ); - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[1] == 1 ); - TESTCASE( bigint.data[0] == 34464 ); - - _PDCLIB_bigint_from_pow10( &bigint, 6 ); - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[1] == 15 ); - TESTCASE( bigint.data[0] == 16960 ); - - _PDCLIB_bigint_from_pow10( &bigint, 7 ); - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[1] == 152 ); - TESTCASE( bigint.data[0] == 38528 ); - - _PDCLIB_bigint_from_pow10( &bigint, 8 ); - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[1] == 1525 ); - TESTCASE( bigint.data[0] == 57600 ); - - _PDCLIB_bigint_from_pow10( &bigint, 9 ); - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[1] == 15258 ); - TESTCASE( bigint.data[0] == 51712 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow2.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow2.c deleted file mode 100644 index fbb6cad..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_from_pow2.c +++ /dev/null @@ -1,54 +0,0 @@ -/* _PDCLIB_bigint_from_pow2( bigint_t *, unsigned ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -void _PDCLIB_bigint_from_pow2( _PDCLIB_bigint_t * bigint, unsigned pow ) -{ - ldiv_t dv = ldiv( pow, _PDCLIB_BIGINT_DIGIT_BITS ); - long i; - - for ( i = 0; i < dv.quot; ++i ) - { - bigint->data[i] = 0; - } - - bigint->data[i] = 1u << dv.rem; - bigint->size = i + 1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - - _PDCLIB_bigint_from_pow2( &bigint, 0 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 1 ); - - _PDCLIB_bigint_from_pow2( &bigint, 1 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 2 ); - - _PDCLIB_bigint_from_pow2( &bigint, 2 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 4 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_log2.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_log2.c deleted file mode 100644 index ed1cf51..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_log2.c +++ /dev/null @@ -1,64 +0,0 @@ -/* _PDCLIB_bigint_log2( bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -int _PDCLIB_bigint_log2( _PDCLIB_bigint_t const * bigint ) -{ - _PDCLIB_size_t s = bigint->size; - - if ( s == 0 ) - { - return -1; - } - - --s; - - return _PDCLIB_bigint_digit_log2( bigint->data[ s ] ) + s * _PDCLIB_BIGINT_DIGIT_BITS; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t one; - _PDCLIB_bigint_from_digit( &bigint, 0 ); - _PDCLIB_bigint_from_digit( &one, 1 ); - - TESTCASE( _PDCLIB_bigint_log2( &bigint ) == -1 ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 0 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 3 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 6 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 9 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 13 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 16 ); - - _PDCLIB_bigint_mul10( &one ); - TESTCASE( _PDCLIB_bigint_log2( &one ) == 19 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul.c deleted file mode 100644 index 812cdef..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul.c +++ /dev/null @@ -1,121 +0,0 @@ -/* _PDCLIB_bigint_mul( bigint_t *, bigint_t const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_mul( _PDCLIB_bigint_t * bigint, _PDCLIB_bigint_t const * other ) -{ - _PDCLIB_size_t s = other->size; - _PDCLIB_size_t b = bigint->size; - - if ( s == 0 || b == 0 ) - { - _PDCLIB_bigint_from_digit( bigint, 0 ); - return; - } - - { - _PDCLIB_bigint_t result = { s + b, { 0 } }; - _PDCLIB_bigint_t const * small; - _PDCLIB_bigint_t const * big; - - if ( s <= b ) - { - small = other; - big = bigint; - } - else - { - small = bigint; - big = other; - } - - for ( s = 0; s < small->size; ++s ) - { - _PDCLIB_bigint_arith_t t = 0; - - for ( b = 0; b < big->size; ++b ) - { - t += result.data[ s + b ] - + (_PDCLIB_bigint_arith_t)small->data[ s ] - * (_PDCLIB_bigint_arith_t)big->data[ b ]; - result.data[ s + b ] = t & ( ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS ) - 1 ); - t >>= _PDCLIB_BIGINT_DIGIT_BITS; - } - - result.data[ s + b ] = t & ( ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS ) - 1 ); - } - - while ( result.data[ result.size - 1 ] == 0 ) - { - --result.size; - } - - _PDCLIB_bigint_from_bigint( bigint, &result ); - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t testdata[] = - { - { 1, { 0x0001u } }, - { 1, { 0x0002u } }, - { 1, { ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS) - 1 } }, - { 2, { ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS) - 1, 1u } } - }; - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[0] ); - _PDCLIB_bigint_mul( &bigint, &testdata[0] ); - - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 1u ); - - _PDCLIB_bigint_mul( &bigint, &testdata[1] ); - - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 2u ); - - _PDCLIB_bigint_mul( &bigint, &testdata[2] ); - - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[0] == ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS) - 2 ); - TESTCASE( bigint.data[1] == 1u ); - - _PDCLIB_bigint_mul( &bigint, &testdata[1] ); - - TESTCASE( bigint.size == 2 ); - TESTCASE( bigint.data[0] == ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS) - 4 ); - TESTCASE( bigint.data[1] == 3u ); - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[3] ); - _PDCLIB_bigint_mul( &bigint, &bigint ); - - TESTCASE( bigint.data[0] == 1 ); - TESTCASE( bigint.data[1] == ( (_PDCLIB_bigint_arith_t)1u << _PDCLIB_BIGINT_DIGIT_BITS) - 4 ); - -#if _PDCLIB_BIGINT_DIGIT_BITS == 16 - TESTCASE( bigint.size == 3 ); - TESTCASE( bigint.data[2] == 3 ); -#else - TESTCASE( bigint.size == 2 ); -#endif -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul10.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul10.c deleted file mode 100644 index 76767fc..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul10.c +++ /dev/null @@ -1,58 +0,0 @@ -/* _PDCLIB_bigint_mul10( bigint_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_mul10( _PDCLIB_bigint_t * bigint ) -{ - _PDCLIB_bigint_arith_t t = 0; - _PDCLIB_size_t i; - - for ( i = 0; i < bigint->size; ++i ) - { - t = (_PDCLIB_bigint_arith_t)bigint->data[ i ] * 10 + t; - bigint->data[ i ] = t & _PDCLIB_BIGINT_DIGIT_MAX; - t >>= _PDCLIB_BIGINT_DIGIT_BITS; - } - - if ( t > 0 ) - { - bigint->data[ bigint->size++ ] = t; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t testdata[] = - { - { 2, { 0x8080u, 0x0101u } }, - { 2, { 0x0500u, 0x0a0fu } }, - { 1, { 0x000au } } - }; - - _PDCLIB_bigint_from_digit( &bigint, 1 ); - _PDCLIB_bigint_mul10( &bigint ); - TESTCASE( _PDCLIB_bigint_cmp( &bigint, &testdata[2] ) == 0 ); - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[0] ); - _PDCLIB_bigint_mul10( &bigint ); - TESTCASE( _PDCLIB_bigint_cmp( &bigint, &testdata[1] ) == 0 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul_pow10.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul_pow10.c deleted file mode 100644 index 2924fe2..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_mul_pow10.c +++ /dev/null @@ -1,30 +0,0 @@ -/* _PDCLIB_bigint_mul_pow10( bigint_t *, int pow10 ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -void _PDCLIB_bigint_mul_pow10( _PDCLIB_bigint_t * bigint, int pow10 ) -{ - _PDCLIB_bigint_t multiplier; - _PDCLIB_bigint_from_pow10( &multiplier, pow10 ); - _PDCLIB_bigint_mul( bigint, &multiplier ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_shl.c b/rocklibc/src/_PDCLIB/_PDCLIB_bigint_shl.c deleted file mode 100644 index a04e752..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_bigint_shl.c +++ /dev/null @@ -1,83 +0,0 @@ -/* _PDCLIB_bigint_shl( bigint_t *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -void _PDCLIB_bigint_shl( _PDCLIB_bigint_t * bigint, _PDCLIB_size_t bits ) -{ - ldiv_t dv = ldiv( bits, _PDCLIB_BIGINT_DIGIT_BITS ); - _PDCLIB_bigint_arith_t t = 0; - size_t i; - - if ( dv.quot > 0 ) - { - i = bigint->size; - - /* shifting whole digits */ - while ( i-- > 0 ) - { - bigint->data[ i + dv.quot ] = bigint->data[ i ]; - } - - bigint->size += dv.quot; - - /* zero out shifted low digits */ - while ( (long)i < dv.quot ) - { - bigint->data[ i++ ] = 0; - } - } - - for ( i = dv.quot; i < bigint->size; ++i ) - { - t = ( (_PDCLIB_bigint_arith_t)bigint->data[ i ] << dv.rem ) + t; - bigint->data[ i ] = t & _PDCLIB_BIGINT_DIGIT_MAX; - t >>= _PDCLIB_BIGINT_DIGIT_BITS; - } - - if ( t > 0 ) - { - bigint->data[ bigint->size++ ] = t; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_bigint_t bigint; - _PDCLIB_bigint_t testdata[] = - { - { 2, { 0x8080u, 0x0101u } }, - { 3, { 0x0000u, 0x0100u, 0x0203u } } - }; - - _PDCLIB_bigint_from_digit( &bigint, 1 ); - _PDCLIB_bigint_shl( &bigint, 2 ); - TESTCASE( bigint.size == 1 ); - TESTCASE( bigint.data[0] == 4 ); - - _PDCLIB_bigint_from_bigint( &bigint, &testdata[0] ); - _PDCLIB_bigint_shl( &bigint, _PDCLIB_BIGINT_DIGIT_BITS + 1 ); - TESTCASE( bigint.size == 3 ); - TESTCASE( bigint.data[0] == 0 ); - TESTCASE( bigint.data[1] == 0x0100 ); - TESTCASE( bigint.data[2] == 0x0203 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_changemode.c b/rocklibc/src/_PDCLIB/_PDCLIB_changemode.c deleted file mode 100644 index 0a0cf58..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_changemode.c +++ /dev/null @@ -1,73 +0,0 @@ -/* _PDCLIB_changemode( FILE * stream, int mode ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is a utility function used by freopen, to allow for a rather - specific bit of trickery. - ISO/IEC 9899:2011 (i.e., the ISO C standard) is ambiguous in the case - of the filename argument being NULL. It states that the mode of the - open stream could be _changed_ in implementation-defined circumstances. - While it goes on to state that freopen will "first attempt to close any - file that is associated with the specified stream", it is not quite - clear if the "implementation-defined circumstances" mentioned earlier - would include changing the mode without actually closing the file. - IEEE Std 1003.1, 2004 Edition (POSIX) on the other hand is less - ambiguous, as it states that "the file descriptor associated with the - stream need not be closed if the call to freopen() succeeds" for the - same case (filename being NULL). - This function gets called by PDCLib's freopen() in just that case, - allowing you to perform whatever mode changes YOUR implementation - decides to support. Return zero if the change requested is not - supported and freopen() should attempt the close-and-open-again way. - Return INT_MIN if the change request is not supported and freopen() - should fail. Return any other value if the requested mode change was - supported and successful. -*/ - -/* This is a dummy implementation of _PDCLIB_open() not supporting any - mode changes. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include -#include - -int _PDCLIB_changemode( struct _PDCLIB_file_t * stream, unsigned int mode ) -{ - if ( mode == 0 ) - { - return INT_MIN; - } - - /* Attempt mode change without closing the stream */ - - if ( stream->filename == NULL ) - { - /* Standard stream, no filename for reopen */ - return INT_MIN; - } - else - { - /* Stream with file associated, attempt reopen */ - return 0; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No test drivers. */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_close.c b/rocklibc/src/_PDCLIB/_PDCLIB_close.c deleted file mode 100644 index 55439d6..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_close.c +++ /dev/null @@ -1,44 +0,0 @@ -/* _PDCLIB_close( _PDCLIB_fd_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_close() fit for use with POSIX - kernels. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int close( int fd ); - -#ifdef __cplusplus -} -#endif - -int _PDCLIB_close( int fd ) -{ - return close( fd ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No testdriver; tested in driver for _PDCLIB_open(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_closeall.c b/rocklibc/src/_PDCLIB/_PDCLIB_closeall.c deleted file mode 100644 index eb42cda..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_closeall.c +++ /dev/null @@ -1,38 +0,0 @@ -/* _PDCLIB_closeall( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -void _PDCLIB_closeall( void ) -{ - struct _PDCLIB_file_t * stream = _PDCLIB_filelist; - struct _PDCLIB_file_t * next; - - while ( stream != NULL ) - { - next = stream->next; - fclose( stream ); - stream = next; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_digits.c b/rocklibc/src/_PDCLIB/_PDCLIB_digits.c deleted file mode 100644 index c35702a..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_digits.c +++ /dev/null @@ -1,33 +0,0 @@ -/* _PDCLIB_digits - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -const char _PDCLIB_digits[] = "0123456789abcdefghijklmnopqrstuvwxyz"; - -/* For _PDCLIB/print.c only; obsolete with ctype.h */ -const char _PDCLIB_Xdigits[] = "0123456789ABCDEF"; - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - TESTCASE( strcmp( _PDCLIB_digits, "0123456789abcdefghijklmnopqrstuvwxyz" ) == 0 ); - TESTCASE( strcmp( _PDCLIB_Xdigits, "0123456789ABCDEF" ) == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_filemode.c b/rocklibc/src/_PDCLIB/_PDCLIB_filemode.c deleted file mode 100644 index c34da1d..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_filemode.c +++ /dev/null @@ -1,114 +0,0 @@ -/* _PDCLIB_filemode( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -/* Helper function that parses the C-style mode string passed to fopen() into - the PDCLib flags FREAD, FWRITE, FAPPEND, FRW (read-write) and FBIN (binary - mode). -*/ -unsigned int _PDCLIB_filemode( const char * const mode ) -{ - unsigned rc = 0; - size_t i; - - if ( mode == NULL ) - { - return 0; - } - - switch ( mode[0] ) - { - case 'r': - rc |= _PDCLIB_FREAD; - break; - - case 'w': - rc |= _PDCLIB_FWRITE; - break; - - case 'a': - rc |= _PDCLIB_FAPPEND | _PDCLIB_FWRITE; - break; - - default: - /* Other than read, write, or append - invalid */ - return 0; - } - - for ( i = 1; i < 4; ++i ) - { - switch ( mode[i] ) - { - case '+': - if ( rc & _PDCLIB_FRW ) - { - /* Duplicates are invalid */ - return 0; - } - - rc |= _PDCLIB_FRW; - break; - - case 'b': - if ( rc & _PDCLIB_FBIN ) - { - /* Duplicates are invalid */ - return 0; - } - - rc |= _PDCLIB_FBIN; - break; - - case '\0': - /* End of mode */ - return rc; - - default: - /* Other than read/write or binary - invalid. */ - return 0; - } - } - - /* Longer than three chars - invalid. */ - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - TESTCASE( _PDCLIB_filemode( "r" ) == _PDCLIB_FREAD ); - TESTCASE( _PDCLIB_filemode( "w" ) == _PDCLIB_FWRITE ); - TESTCASE( _PDCLIB_filemode( "a" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE ) ); - TESTCASE( _PDCLIB_filemode( "r+" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW ) ); - TESTCASE( _PDCLIB_filemode( "w+" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW ) ); - TESTCASE( _PDCLIB_filemode( "a+" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW ) ); - TESTCASE( _PDCLIB_filemode( "rb" ) == ( _PDCLIB_FREAD | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "wb" ) == ( _PDCLIB_FWRITE | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "ab" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "r+b" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "w+b" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "a+b" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "rb+" ) == ( _PDCLIB_FREAD | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "wb+" ) == ( _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "ab+" ) == ( _PDCLIB_FAPPEND | _PDCLIB_FWRITE | _PDCLIB_FRW | _PDCLIB_FBIN ) ); - TESTCASE( _PDCLIB_filemode( "x" ) == 0 ); - TESTCASE( _PDCLIB_filemode( "r++" ) == 0 ); - TESTCASE( _PDCLIB_filemode( "wbb" ) == 0 ); - TESTCASE( _PDCLIB_filemode( "a+bx" ) == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_fillbuffer.c b/rocklibc/src/_PDCLIB/_PDCLIB_fillbuffer.c deleted file mode 100644 index f96c7b7..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_fillbuffer.c +++ /dev/null @@ -1,77 +0,0 @@ -/* _PDCLIB_fillbuffer( struct _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_fillbuffer() fit for - use with POSIX kernels. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include "pdclib/_PDCLIB_platform_errno.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef long ssize_t; -extern ssize_t read( int fd, void * buf, size_t count ); - -#ifdef __cplusplus -} -#endif - -int _PDCLIB_fillbuffer( struct _PDCLIB_file_t * stream ) -{ - /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */ - ssize_t rc = read( stream->handle, stream->buffer, stream->bufsize ); - - if ( rc > 0 ) - { - /* Reading successful. */ - if ( !( stream->status & _PDCLIB_FBIN ) ) - { - /* TODO: Text stream conversion here */ - } - - stream->pos.offset += rc; - stream->bufend = rc; - stream->bufidx = 0; - return 0; - } - - if ( rc < 0 ) - { - /* The 1:1 mapping done in _PDCLIB_config.h ensures - this works. - */ - *_PDCLIB_errno_func() = errno; - /* Flag the stream */ - stream->status |= _PDCLIB_ERRORFLAG; - return EOF; - } - - /* End-of-File */ - stream->status |= _PDCLIB_EOFFLAG; - return EOF; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_flushbuffer.c b/rocklibc/src/_PDCLIB/_PDCLIB_flushbuffer.c deleted file mode 100644 index 764c38e..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_flushbuffer.c +++ /dev/null @@ -1,103 +0,0 @@ -/* _PDCLIB_flushbuffer( struct _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_flushbuffer() fit for - use with POSIX kernels. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include "pdclib/_PDCLIB_platform_errno.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef long ssize_t; -extern ssize_t write( int fd, const void * buf, size_t count ); - -#ifdef __cplusplus -} -#endif - -/* The number of attempts of output buffer flushing before giving up. */ -#define _PDCLIB_IO_RETRIES 1 - -/* What the system should do after an I/O operation did not succeed, before */ -/* trying again. (Empty by default.) */ -#define _PDCLIB_IO_RETRY_OP( stream ) - -int _PDCLIB_flushbuffer( struct _PDCLIB_file_t * stream ) -{ - /* No need to handle buffers > INT_MAX, as PDCLib doesn't allow them */ - _PDCLIB_size_t written = 0; - int rc; - unsigned int retries; - - if ( !( stream->status & _PDCLIB_FBIN ) ) - { - /* TODO: Text stream conversion here */ - } - - /* Keep trying to write data until everything is written, an error - occurs, or the configured number of retries is exceeded. - */ - for ( retries = _PDCLIB_IO_RETRIES; retries > 0; --retries ) - { - rc = ( int )write( stream->handle, stream->buffer + written, stream->bufidx - written ); - - if ( rc < 0 ) - { - /* The 1:1 mapping done in _PDCLIB_config.h ensures - this works. - */ - *_PDCLIB_errno_func() = errno; - /* Flag the stream */ - stream->status |= _PDCLIB_ERRORFLAG; - /* Move unwritten remains to begin of buffer. */ - stream->bufidx -= written; - memmove( stream->buffer, stream->buffer + written, stream->bufidx ); - return EOF; - } - - written += ( _PDCLIB_size_t )rc; - stream->pos.offset += rc; - - if ( written == stream->bufidx ) - { - /* Buffer written completely. */ - stream->bufidx = 0; - return 0; - } - } - - /* Number of retries exceeded. */ - *_PDCLIB_errno_func() = _PDCLIB_EAGAIN; - stream->status |= _PDCLIB_ERRORFLAG; - /* Move unwritten remains to begin of buffer. */ - stream->bufidx -= written; - memmove( stream->buffer, stream->buffer + written, stream->bufidx ); - return EOF; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_dbl.c b/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_dbl.c deleted file mode 100644 index 1a1e6a4..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_dbl.c +++ /dev/null @@ -1,106 +0,0 @@ -/* _PDCLIB_fp_from_dbl( _PDCLIB_fp_t *, double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include -#include - -void _PDCLIB_fp_from_dbl( _PDCLIB_fp_t * fp, double d ) -{ - memcpy( fp->mantissa.data, &d, sizeof( double ) ); - - fp->sign = _PDCLIB_DBL_SIGN( fp->mantissa.data ); - fp->exponent = _PDCLIB_DBL_EXP( fp->mantissa.data ); - fp->mantissa.size = _PDCLIB_DBL_SIZE( fp->mantissa.data ); - - switch ( fp->exponent ) - { - case 0: - fp->state = _PDCLIB_FP_SUBNORMAL; - fp->exponent = 1 - ( _PDCLIB_DBL_MAX_EXP - 1 ); - fp->scale = _PDCLIB_DBL_MANT_DIG - 1; - break; - case ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP: - fp->state = _PDCLIB_FP_NAN; - break; - default: - { - div_t dv = div( _PDCLIB_DBL_MANT_DIG - 1, _PDCLIB_BIGINT_DIGIT_BITS ); - fp->state = _PDCLIB_FP_NORMAL; - - if ( dv.rem == 0 ) - { - fp->mantissa.data[ fp->mantissa.size++ ] = 1u; - } - else - { - fp->mantissa.data[ dv.quot ] |= ( 1u << dv.rem ); - } - - fp->exponent -= ( _PDCLIB_DBL_MAX_EXP - 1 ); - fp->scale = _PDCLIB_DBL_MANT_DIG - 1; - break; - } - } - - while ( fp->mantissa.size > 0 && fp->mantissa.data[ fp->mantissa.size - 1 ] == 0 ) - { - --fp->mantissa.size; - } - - if ( ( fp->state == _PDCLIB_FP_NAN ) && ( fp->mantissa.size == 0 ) ) - { - fp->state = _PDCLIB_FP_INF; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_fp_t fp; - _PDCLIB_bigint_t t; - - /* Normal */ - _PDCLIB_fp_from_dbl( &fp, -1.0 ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_DBL_MANT_DIG - 1 ); - TESTCASE( fp.state == _PDCLIB_FP_NORMAL ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - TESTCASE( fp.scale == ( _PDCLIB_DBL_MANT_DIG - 1 ) ); - TESTCASE( fp.exponent == 0 ); - - /* Inf */ - _PDCLIB_fp_from_dbl( &fp, 1e500 ); - TESTCASE( fp.state == _PDCLIB_FP_INF ); - TESTCASE( fp.mantissa.size == 0 ); - - /* NaN */ - _PDCLIB_fp_from_dbl( &fp, -0.0/0.0 ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_DBL_MANT_DIG - 2 ); - TESTCASE( fp.state == _PDCLIB_FP_NAN ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - - /* Subnormal */ - _PDCLIB_fp_from_dbl( &fp, _PDCLIB_DBL_MIN / 2 ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_DBL_MANT_DIG - 2 ); - TESTCASE( fp.state == _PDCLIB_FP_SUBNORMAL ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - TESTCASE( fp.scale == ( _PDCLIB_DBL_MANT_DIG - 1 ) ); - TESTCASE( fp.exponent == (_PDCLIB_int_least16_t)(1 - ( _PDCLIB_DBL_MAX_EXP - 1 ) ) ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_ldbl.c b/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_ldbl.c deleted file mode 100644 index f759523..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_fp_from_ldbl.c +++ /dev/null @@ -1,106 +0,0 @@ -/* _PDCLIB_fp_from_ldbl( _PDCLIB_fp_t *, long double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include -#include - -void _PDCLIB_fp_from_ldbl( _PDCLIB_fp_t * fp, long double ld ) -{ - memcpy( fp->mantissa.data, &ld, sizeof( long double ) ); - - fp->sign = _PDCLIB_LDBL_SIGN( fp->mantissa.data ); - fp->exponent = _PDCLIB_LDBL_EXP( fp->mantissa.data ); - fp->mantissa.size = _PDCLIB_LDBL_SIZE( fp->mantissa.data ); - - switch ( fp->exponent ) - { - case 0: - fp->state = _PDCLIB_FP_SUBNORMAL; - fp->exponent = 1 - ( _PDCLIB_LDBL_MAX_EXP - 1 ); - fp->scale = _PDCLIB_LDBL_MANT_DIG - 1; - break; - case ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP: - fp->state = _PDCLIB_FP_NAN; - break; - default: - { - div_t dv = div( _PDCLIB_LDBL_MANT_DIG - 1, _PDCLIB_BIGINT_DIGIT_BITS ); - fp->state = _PDCLIB_FP_NORMAL; - - if ( dv.rem == 0 ) - { - fp->mantissa.data[ fp->mantissa.size++ ] = 1u; - } - else - { - fp->mantissa.data[ dv.quot ] |= ( 1u << dv.rem ); - } - - fp->exponent -= ( _PDCLIB_LDBL_MAX_EXP - 1 ); - fp->scale = _PDCLIB_LDBL_MANT_DIG - 1; - break; - } - } - - while ( fp->mantissa.size > 0 && fp->mantissa.data[ fp->mantissa.size - 1 ] == 0 ) - { - --fp->mantissa.size; - } - - if ( ( fp->state == _PDCLIB_FP_NAN ) && ( fp->mantissa.size == 0 ) ) - { - fp->state = _PDCLIB_FP_INF; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - _PDCLIB_fp_t fp; - _PDCLIB_bigint_t t; - - /* Normal */ - _PDCLIB_fp_from_ldbl( &fp, -1.0L ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_LDBL_MANT_DIG - 1 ); - TESTCASE( fp.state == _PDCLIB_FP_NORMAL ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - TESTCASE( fp.scale == ( _PDCLIB_LDBL_MANT_DIG - 1 ) ); - TESTCASE( fp.exponent == 0 ); - - /* Inf */ - _PDCLIB_fp_from_ldbl( &fp, 1e5000L ); - TESTCASE( fp.state == _PDCLIB_FP_INF ); - TESTCASE( fp.mantissa.size == 0 ); - - /* NaN */ - _PDCLIB_fp_from_ldbl( &fp, -0.0L/0.0L ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_LDBL_MANT_DIG - 2 ); - TESTCASE( fp.state == _PDCLIB_FP_NAN ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - - /* Subnormal */ - _PDCLIB_fp_from_ldbl( &fp, _PDCLIB_LDBL_MIN / 2L ); - _PDCLIB_bigint_from_pow2( &t, _PDCLIB_LDBL_MANT_DIG - 2 ); - TESTCASE( fp.state == _PDCLIB_FP_SUBNORMAL ); - TESTCASE( _PDCLIB_bigint_cmp( &fp.mantissa, &t ) == 0 ); - TESTCASE( fp.scale == ( _PDCLIB_LDBL_MANT_DIG - 1 ) ); - TESTCASE( fp.exponent == (_PDCLIB_int_least16_t)(1 - ( _PDCLIB_LDBL_MAX_EXP - 1 ) ) ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_getstream.c b/rocklibc/src/_PDCLIB/_PDCLIB_getstream.c deleted file mode 100644 index 610cbf8..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_getstream.c +++ /dev/null @@ -1,49 +0,0 @@ -/* _PDCLIB_getstream( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -int _PDCLIB_getstream( struct _PDCLIB_file_t * stream ) -{ - struct _PDCLIB_file_t * previous; - - if ( ! _PDCLIB_isstream( stream, &previous ) ) - { - *_PDCLIB_errno_func() = _PDCLIB_EBADF; - return EOF; - } - - if ( previous != NULL ) - { - previous->next = stream->next; - } - else - { - _PDCLIB_filelist = stream->next; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_init_file_t.c b/rocklibc/src/_PDCLIB/_PDCLIB_init_file_t.c deleted file mode 100644 index 4021774..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_init_file_t.c +++ /dev/null @@ -1,82 +0,0 @@ -/* _PDCLIB_init_file_t( _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -struct _PDCLIB_file_t * _PDCLIB_init_file_t( struct _PDCLIB_file_t * stream ) -{ - struct _PDCLIB_file_t * rc = stream; - - if ( rc == NULL ) - { - if ( ( rc = (struct _PDCLIB_file_t *)malloc( sizeof( struct _PDCLIB_file_t ) ) ) == NULL ) - { - /* No memory */ - return NULL; - } - } - - if ( ( rc->buffer = (char *)malloc( BUFSIZ ) ) == NULL ) - { - /* No memory */ - free( rc ); - return NULL; - } - - rc->bufsize = BUFSIZ; - rc->bufidx = 0; - rc->bufend = 0; - rc->pos.offset = 0; - rc->pos.status = 0; - rc->ungetidx = 0; - rc->status = _PDCLIB_FREEBUFFER; - -#ifndef __STDC_NO_THREADS__ - - if ( stream == NULL ) - { - /* If called by freopen() (stream not NULL), mutex is already - initialized. - */ - if ( mtx_init( &rc->mtx, mtx_plain | mtx_recursive ) != thrd_success ) - { - /* could not initialize stream mutex */ - free( rc->buffer ); - free( rc ); - return NULL; - } - } - -#endif - - /* TODO: Setting mbstate */ - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - TESTCASE( NO_TESTDRIVER ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_is_leap.c b/rocklibc/src/_PDCLIB/_PDCLIB_is_leap.c deleted file mode 100644 index da05f7f..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_is_leap.c +++ /dev/null @@ -1,39 +0,0 @@ -/* _PDCLIB_is_leap( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -int _PDCLIB_is_leap( int year_offset ) -{ - /* year given as offset from 1900, matching tm.tm_year in */ - long long year = year_offset + 1900ll; - return ( ( year % 4 ) == 0 && ( ( year % 25 ) != 0 || ( year % 400 ) == 0 ) ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - /* 1901 not leap */ - TESTCASE( ! _PDCLIB_is_leap( 1 ) ); - /* 1904 leap */ - TESTCASE( _PDCLIB_is_leap( 4 ) ); - /* 1900 not leap */ - TESTCASE( ! _PDCLIB_is_leap( 0 ) ); - /* 2000 leap */ - TESTCASE( _PDCLIB_is_leap( 100 ) ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_isstream.c b/rocklibc/src/_PDCLIB/_PDCLIB_isstream.c deleted file mode 100644 index 69f28ce..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_isstream.c +++ /dev/null @@ -1,49 +0,0 @@ -/* _PDCLIB_isstream( FILE *, FILE ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -int _PDCLIB_isstream( struct _PDCLIB_file_t * stream, struct _PDCLIB_file_t ** previous ) -{ - struct _PDCLIB_file_t * current = _PDCLIB_filelist; - - if ( previous != NULL ) - { - *previous = NULL; - } - - while ( ( current != NULL ) && ( current != stream ) ) - { - if ( previous != NULL ) - { - *previous = current; - } - - current = current->next; - } - - return current != NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_collate.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_collate.c deleted file mode 100644 index 7bfa711..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_collate.c +++ /dev/null @@ -1,63 +0,0 @@ -/* _PDCLIB_load_lc_collate( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_collate_t * _PDCLIB_load_lc_collate( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_collate_t * rc = NULL; - const char * extension = "_collate.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_collate_t *)malloc( sizeof( struct _PDCLIB_lc_collate_t ) ) ) != NULL ) - { - /* TODO: Collation data */ - - rc->alloced = 1; - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - TESTCASE( NO_TESTDRIVER ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_ctype.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_ctype.c deleted file mode 100644 index 9b3226d..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_ctype.c +++ /dev/null @@ -1,365 +0,0 @@ -/* _PDCLIB_load_lc_ctype( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_ctype_t * _PDCLIB_load_lc_ctype( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_ctype_t * rc = NULL; - const char * extension = "_ctype.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_ctype_t *)malloc( sizeof( struct _PDCLIB_lc_ctype_t ) ) ) != NULL ) - { - struct _PDCLIB_lc_ctype_entry_t * entry; - - if ( ( entry = (struct _PDCLIB_lc_ctype_entry_t *)malloc( sizeof( struct _PDCLIB_lc_ctype_entry_t ) * _PDCLIB_CHARSET_SIZE + 1 ) ) != NULL ) - { - rc->entry = entry + 1; - rc->entry[ -1 ].flags = rc->entry[ -1 ].upper = rc->entry[ -1 ].lower = 0; - - if ( fscanf( fh, "%x %x %x %x %x %x", &rc->digits_low, &_PDCLIB_lc_ctype->digits_high, &_PDCLIB_lc_ctype->Xdigits_low, &_PDCLIB_lc_ctype->Xdigits_high, &_PDCLIB_lc_ctype->xdigits_low, &_PDCLIB_lc_ctype->xdigits_high ) == 6 ) - { - size_t i; - - for ( i = 0; i < _PDCLIB_CHARSET_SIZE; ++i ) - { - if ( fscanf( fh, "%" SCNx16 " %hhx %hhx", &rc->entry[ i ].flags, &rc->entry[ i ].upper, &rc->entry[ i ].lower ) != 3 ) - { - fclose( fh ); - free( file ); - free( rc->entry - 1 ); - free( rc ); - return NULL; - } - } - } - - rc->alloced = 1; - } - else - { - free( rc ); - } - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_ctype.dat", "wb" ); - TESTCASE( fh != NULL ); - /* For test purposes, let's set up a charset that only has the hex digits */ - /* 0x00..0x09 - digits */ - /* 0x11..0x16 - Xdigits */ - /* 0x21..0x26 - xdigits */ - TESTCASE( fprintf( fh, "%x %x\n", 0x00, 0x09 ) ); - TESTCASE( fprintf( fh, "%x %x %x %x\n", 0x11, 0x16, 0x21, 0x26 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x00, 0x00 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x01, 0x01 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x02, 0x02 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x03, 0x03 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x04, 0x04 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x05, 0x05 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x06, 0x06 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x07, 0x07 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x08, 0x08 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH, 0x09, 0x09 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0A, 0x0A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0B, 0x0B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0C, 0x0C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0D, 0x0D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0E, 0x0E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x0F, 0x0F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x10, 0x10 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x11, 0x11 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x12, 0x12 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x13, 0x13 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x14, 0x14 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x15, 0x15 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x16, 0x16 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x17, 0x17 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x18, 0x18 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x19, 0x19 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1A, 0x1A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1B, 0x1B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1C, 0x1C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1D, 0x1D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1E, 0x1E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x1F, 0x1F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x20, 0x20 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x21, 0x21 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x22, 0x22 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x23, 0x23 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x24, 0x24 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x25, 0x25 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x26, 0x26 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x27, 0x27 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x28, 0x28 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x29, 0x29 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2A, 0x2A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2B, 0x2B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2C, 0x2C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2D, 0x2D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2E, 0x2E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x2F, 0x2F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x30, 0x30 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x31, 0x31 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x32, 0x32 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x33, 0x33 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x34, 0x34 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x35, 0x35 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x36, 0x36 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x37, 0x37 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x38, 0x38 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x39, 0x39 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3A, 0x3A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3B, 0x3B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3C, 0x3C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3D, 0x3D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3E, 0x3E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x3F, 0x3F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x40, 0x40 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x41, 0x41 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x42, 0x42 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x43, 0x43 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x44, 0x44 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x45, 0x45 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x46, 0x46 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x47, 0x47 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x48, 0x48 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x49, 0x49 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4A, 0x4A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4B, 0x4B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4C, 0x4C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4D, 0x4D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4E, 0x4E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x4F, 0x4F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x50, 0x50 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x51, 0x51 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x52, 0x52 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x53, 0x53 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x54, 0x54 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x55, 0x55 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x56, 0x56 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x57, 0x57 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x58, 0x58 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x59, 0x59 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5A, 0x5A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5B, 0x5B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5C, 0x5C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5D, 0x5D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5E, 0x5E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x5F, 0x5F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x60, 0x60 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x61, 0x61 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x62, 0x62 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x63, 0x63 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x64, 0x64 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x65, 0x65 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x66, 0x66 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x67, 0x67 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x68, 0x68 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x69, 0x69 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6A, 0x6A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6B, 0x6B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6C, 0x6C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6D, 0x6D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6E, 0x6E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x6F, 0x6F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x70, 0x70 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x71, 0x71 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x72, 0x72 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x73, 0x73 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x74, 0x74 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x75, 0x75 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x76, 0x76 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x77, 0x77 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x78, 0x78 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x79, 0x79 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7A, 0x7A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7B, 0x7B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7C, 0x7C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7D, 0x7D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7E, 0x7E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x7F, 0x7F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x80, 0x80 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x81, 0x81 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x82, 0x82 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x83, 0x83 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x84, 0x84 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x85, 0x85 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x86, 0x86 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x87, 0x87 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x88, 0x88 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x89, 0x89 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8A, 0x8A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8B, 0x8B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8C, 0x8C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8D, 0x8D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8E, 0x8E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x8F, 0x8F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x90, 0x90 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x91, 0x91 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x92, 0x92 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x93, 0x93 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x94, 0x94 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x95, 0x95 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x96, 0x96 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x97, 0x97 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x98, 0x98 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x99, 0x99 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9A, 0x9A ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9B, 0x9B ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9C, 0x9C ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9D, 0x9D ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9E, 0x9E ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0x9F, 0x9F ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA0, 0xA0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA1, 0xA1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA2, 0xA2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA3, 0xA3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA4, 0xA4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA5, 0xA5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA6, 0xA6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA7, 0xA7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA8, 0xA8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xA9, 0xA9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAA, 0xAA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAB, 0xAB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAC, 0xAC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAD, 0xAD ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAE, 0xAE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xAF, 0xAF ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB0, 0xB0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB1, 0xB1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB2, 0xB2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB3, 0xB3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB4, 0xB4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB5, 0xB5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB6, 0xB6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB7, 0xB7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB8, 0xB8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xB9, 0xB9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBA, 0xBA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBB, 0xBB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBC, 0xBC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBD, 0xBD ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBE, 0xBE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xBF, 0xBF ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC0, 0xC0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC1, 0xC1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC2, 0xC2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC3, 0xC3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC4, 0xC4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC5, 0xC5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC6, 0xC6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC7, 0xC7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC8, 0xC8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xC9, 0xC9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCA, 0xCA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCB, 0xCB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCC, 0xCC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCD, 0xCD ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCE, 0xCE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xCF, 0xCF ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD0, 0xD0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD1, 0xD1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD2, 0xD2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD3, 0xD3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD4, 0xD4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD5, 0xD5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD6, 0xD6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD7, 0xD7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD8, 0xD8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xD9, 0xD9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDA, 0xDA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDB, 0xDB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDC, 0xDC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDD, 0xDD ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDE, 0xDE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xDF, 0xDF ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE0, 0xE0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE1, 0xE1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE2, 0xE2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE3, 0xE3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE4, 0xE4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE5, 0xE5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE6, 0xE6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE7, 0xE7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE8, 0xE8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xE9, 0xE9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xEA, 0xEA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xEB, 0xEB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xEC, 0xEC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xED, 0xED ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xEE, 0xEE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xEF, 0xEF ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF0, 0xF0 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF1, 0xF1 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF2, 0xF2 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF3, 0xF3 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF4, 0xF4 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF5, 0xF5 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF6, 0xF6 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF7, 0xF7 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF8, 0xF8 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xF9, 0xF9 ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFA, 0xFA ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFB, 0xFB ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFC, 0xFC ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFD, 0xFD ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFE, 0xFE ) ); - TESTCASE( fprintf( fh, "%x %x %x\n", 0x00, 0xFF, 0xFF ) ); - fclose( fh ); - TESTCASE( _PDCLIB_load_lc_ctype( "./", "test" ) != NULL ); - remove( "test_ctype.dat" ); - /* - TESTCASE( isdigit( 0x00 ) && ! isxdigit( 0x00 ) && ! isalpha( 0x00 ) ); - TESTCASE( ! isdigit( 0x11 ) && isxdigit( 0x11 ) && isalpha( 0x11 ) && isupper( 0x11 ) && ! islower( 0x11 ) ); - TESTCASE( ! isdigit( 0x21 ) && isxdigit( 0x21 ) && isalpha( 0x21 ) && ! isupper( 0x11 ) && islower( 0x11 ) ); - */ -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_messages.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_messages.c deleted file mode 100644 index 507303d..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_messages.c +++ /dev/null @@ -1,88 +0,0 @@ -/* _PDCLIB_load_lc_messages( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_messages_t * _PDCLIB_load_lc_messages( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_messages_t * rc = NULL; - const char * extension = "_messages.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_messages_t *)malloc( sizeof( struct _PDCLIB_lc_messages_t ) ) ) != NULL ) - { - char * data = _PDCLIB_load_lines( fh, _PDCLIB_ERRNO_MAX ); - - if ( data != NULL ) - { - size_t i; - - for ( i = 0; i < _PDCLIB_ERRNO_MAX; ++i ) - { - rc->errno_texts[ i ] = data; - data += strlen( data ) + 1; - } - - rc->alloced = 1; - } - else - { - free( rc ); - rc = NULL; - } - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_numeric.dat", "wb" ); - struct _PDCLIB_lc_lconv_numeric_t * lc; - TESTCASE( fh != NULL ); - TESTCASE( fputs( ",\n.\n\n", fh ) != EOF ); - fclose( fh ); - TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) ); - remove( "test_numeric.dat" ); - TESTCASE( strcmp( lc->decimal_point, "," ) == 0 ); - TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 ); - TESTCASE( strcmp( lc->grouping, "" ) == 0 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_monetary.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_monetary.c deleted file mode 100644 index 1180bb0..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_monetary.c +++ /dev/null @@ -1,158 +0,0 @@ -/* _PDCLIB_load_lc_monetary( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_lconv_monetary_t * _PDCLIB_load_lc_monetary( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_lconv_monetary_t * rc = NULL; - const char * extension = "_monetary.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_lconv_monetary_t *)malloc( sizeof( struct _PDCLIB_lc_lconv_monetary_t ) ) ) != NULL ) - { - char buffer[ 14 ]; - char * data = _PDCLIB_load_lines( fh, 7 ); - - if ( data != NULL ) - { - if ( fread( buffer, 1, 14, fh ) == 14 ) - { - rc->mon_decimal_point = data; - data += strlen( data ) + 1; - rc->mon_thousands_sep = data; - data += strlen( data ) + 1; - rc->mon_grouping = data; - data += strlen( data ) + 1; - rc->positive_sign = data; - data += strlen( data ) + 1; - rc->negative_sign = data; - data += strlen( data ) + 1; - rc->currency_symbol = data; - data += strlen( data ) + 1; - rc->int_curr_symbol = data; - - rc->frac_digits = buffer[ 0 ]; - rc->p_cs_precedes = buffer[ 1 ]; - rc->n_cs_precedes = buffer[ 2 ]; - rc->p_sep_by_space = buffer[ 3 ]; - rc->n_sep_by_space = buffer[ 4 ]; - rc->p_sign_posn = buffer[ 5 ]; - rc->n_sign_posn = buffer[ 6 ]; - rc->int_frac_digits = buffer[ 7 ]; - rc->int_p_cs_precedes = buffer[ 8 ]; - rc->int_n_cs_precedes = buffer[ 9 ]; - rc->int_p_sep_by_space = buffer[ 10 ]; - rc->int_n_sep_by_space = buffer[ 11 ]; - rc->int_p_sign_posn = buffer[ 12 ]; - rc->int_n_sign_posn = buffer[ 13 ]; - } - else - { - free( data ); - free( rc ); - rc = NULL; - } - } - else - { - free( rc ); - rc = NULL; - } - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_monetary.dat", "wb" ); - struct _PDCLIB_lc_lconv_monetary_t * lc; - TESTCASE( fh != NULL ); - fprintf( fh, "%s\n", "," ); /* mon_decimal_point */ - fprintf( fh, "%s\n", "." ); /* mon_thousands_sep */ - fprintf( fh, "%s\n", "3" ); /* mon_grouping */ - fprintf( fh, "%s\n", "" ); /* positive_sign */ - fprintf( fh, "%s\n", "-" ); /* negative_sign */ - fprintf( fh, "%s\n", "\xa4" ); /* currency_symbol */ - fprintf( fh, "%s\n", "EUR" ); /* int_curr_symbol */ - fputc( 2, fh ); /* frac_digits */ - fputc( 0, fh ); /* p_cs_precedes */ - fputc( 0, fh ); /* n_cs_precedes */ - fputc( 1, fh ); /* p_sep_by_space */ - fputc( 1, fh ); /* n_sep_by_space */ - fputc( 1, fh ); /* p_sign_posn */ - fputc( 1, fh ); /* n_sign_posn */ - fputc( 2, fh ); /* int_frac_digits */ - fputc( 0, fh ); /* int_p_cs_precedes */ - fputc( 0, fh ); /* int_n_cs_precedes */ - fputc( 1, fh ); /* int_p_sep_by_space */ - fputc( 1, fh ); /* int_n_sep_by_space */ - fputc( 1, fh ); /* int_p_sign_posn */ - fputc( 1, fh ); /* int_n_sign_posn */ - fprintf( fh, "\n" ); - fclose( fh ); - TESTCASE( ( lc = _PDCLIB_load_lc_monetary( "./", "test" ) ) ); - remove( "test_monetary.dat" ); - TESTCASE( strcmp( lc->mon_decimal_point, "," ) == 0 ); - TESTCASE( strcmp( lc->mon_thousands_sep, "." ) == 0 ); - TESTCASE( strcmp( lc->mon_grouping, "3" ) == 0 ); - TESTCASE( strcmp( lc->positive_sign, "" ) == 0 ); - TESTCASE( strcmp( lc->negative_sign, "-" ) == 0 ); - TESTCASE( strcmp( lc->currency_symbol, "\xa4" ) == 0 ); - TESTCASE( strcmp( lc->int_curr_symbol, "EUR" ) == 0 ); - - TESTCASE( lc->frac_digits == 2 ); - TESTCASE( lc->p_cs_precedes == 0 ); - TESTCASE( lc->n_cs_precedes == 0 ); - TESTCASE( lc->p_sep_by_space == 1 ); - TESTCASE( lc->n_sep_by_space == 1 ); - TESTCASE( lc->p_sign_posn == 1 ); - TESTCASE( lc->n_sign_posn == 1 ); - TESTCASE( lc->int_frac_digits == 2 ); - TESTCASE( lc->int_p_cs_precedes == 0 ); - TESTCASE( lc->int_n_cs_precedes == 0 ); - TESTCASE( lc->int_p_sep_by_space == 1 ); - TESTCASE( lc->int_n_sep_by_space == 1 ); - TESTCASE( lc->int_p_sign_posn == 1 ); - TESTCASE( lc->int_n_sign_posn == 1 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_numeric.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_numeric.c deleted file mode 100644 index 16caedb..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_numeric.c +++ /dev/null @@ -1,84 +0,0 @@ -/* _PDCLIB_load_lc_numeric( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_lconv_numeric_t * _PDCLIB_load_lc_numeric( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_lconv_numeric_t * rc = NULL; - const char * extension = "_numeric.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_lconv_numeric_t *)malloc( sizeof( struct _PDCLIB_lc_lconv_numeric_t ) ) ) != NULL ) - { - char * data = _PDCLIB_load_lines( fh, 3 ); - - if ( data != NULL ) - { - rc->decimal_point = data; - data += strlen( data ) + 1; - rc->thousands_sep = data; - data += strlen( data ) + 1; - rc->grouping = data; - } - else - { - free( rc ); - rc = NULL; - } - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_numeric.dat", "wb" ); - struct _PDCLIB_lc_lconv_numeric_t * lc; - TESTCASE( fh != NULL ); - TESTCASE( fputs( ",\n.\n\n", fh ) != EOF ); - fclose( fh ); - TESTCASE( ( lc = _PDCLIB_load_lc_numeric( "./", "test" ) ) ); - remove( "test_numeric.dat" ); - TESTCASE( strcmp( lc->decimal_point, "," ) == 0 ); - TESTCASE( strcmp( lc->thousands_sep, "." ) == 0 ); - TESTCASE( strcmp( lc->grouping, "" ) == 0 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_time.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_time.c deleted file mode 100644 index 99be781..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lc_time.c +++ /dev/null @@ -1,165 +0,0 @@ -/* _PDCLIB_load_lc_time( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include -#include -#include - -#include "pdclib/_PDCLIB_internal.h" - -struct _PDCLIB_lc_time_t * _PDCLIB_load_lc_time( const char * path, const char * locale ) -{ - struct _PDCLIB_lc_time_t * rc = NULL; - const char * extension = "_time.dat"; - char * file = (char *)malloc( strlen( path ) + strlen( locale ) + strlen( extension ) + 1 ); - - if ( file ) - { - FILE * fh; - - strcpy( file, path ); - strcat( file, locale ); - strcat( file, extension ); - - if ( ( fh = fopen( file, "rb" ) ) != NULL ) - { - if ( ( rc = (struct _PDCLIB_lc_time_t *)malloc( sizeof( struct _PDCLIB_lc_time_t ) ) ) != NULL ) - { - char * data = _PDCLIB_load_lines( fh, 44 ); - - if ( data != NULL ) - { - size_t i; - - for ( i = 0; i < 12; ++i ) - { - rc->month_name_abbr[ i ] = data; - data += strlen( data ) + 1; - } - - for ( i = 0; i < 12; ++i ) - { - rc->month_name_full[ i ] = data; - data += strlen( data ) + 1; - } - - for ( i = 0; i < 7; ++i ) - { - rc->day_name_abbr[ i ] = data; - data += strlen( data ) + 1; - } - - for ( i = 0; i < 7; ++i ) - { - rc->day_name_full[ i ] = data; - data += strlen( data ) + 1; - } - - rc->alloced = 1; - } - else - { - free( rc ); - rc = NULL; - } - } - - fclose( fh ); - } - - free( file ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_time.dat", "wb" ); - struct _PDCLIB_lc_time_t * lc; - - TESTCASE( fh != NULL ); - - /* month name abbreviation */ - TESTCASE( fprintf( fh, "%s\n", "Jan" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Feb" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "M\xe4r" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Apr" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Mai" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Jun" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Jul" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Aug" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Sep" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Okt" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Nov" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Dez" ) == 4 ); - /* month name full */ - TESTCASE( fprintf( fh, "%s\n", "Januar" ) == 7 ); - TESTCASE( fprintf( fh, "%s\n", "Februar" ) == 8 ); - TESTCASE( fprintf( fh, "%s\n", "M\xe4rz" ) == 5 ); - TESTCASE( fprintf( fh, "%s\n", "April" ) == 6 ); - TESTCASE( fprintf( fh, "%s\n", "Mai" ) == 4 ); - TESTCASE( fprintf( fh, "%s\n", "Juni" ) == 5 ); - TESTCASE( fprintf( fh, "%s\n", "Juli" ) == 5 ); - TESTCASE( fprintf( fh, "%s\n", "August" ) == 7 ); - TESTCASE( fprintf( fh, "%s\n", "September" ) == 10 ); - TESTCASE( fprintf( fh, "%s\n", "Oktober" ) == 8 ); - TESTCASE( fprintf( fh, "%s\n", "November" ) == 9 ); - TESTCASE( fprintf( fh, "%s\n", "Dezember" ) == 9 ); - /* day name abbreviation */ - TESTCASE( fprintf( fh, "%s\n", "So" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Mo" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Di" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Mi" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Do" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Fr" ) == 3 ); - TESTCASE( fprintf( fh, "%s\n", "Sa" ) == 3 ); - /* day name full */ - TESTCASE( fprintf( fh, "%s\n", "Sonntag" ) == 8 ); - TESTCASE( fprintf( fh, "%s\n", "Montag" ) == 7 ); - TESTCASE( fprintf( fh, "%s\n", "Dienstag" ) == 9 ); - TESTCASE( fprintf( fh, "%s\n", "Mittwoch" ) == 9 ); - TESTCASE( fprintf( fh, "%s\n", "Donnerstag" ) == 11 ); - TESTCASE( fprintf( fh, "%s\n", "Freitag" ) == 8 ); - TESTCASE( fprintf( fh, "%s\n", "Samstag" ) == 8 ); - - TESTCASE( fprintf( fh, "%s\n", "%a %d %b %Y %T %Z" ) == 18 ); /* date time format (%c) */ - TESTCASE( fprintf( fh, "%s\n", "%I:%M:%S" ) == 9 ); /* 12-hour time format (%r) */ - TESTCASE( fprintf( fh, "%s\n", "%d.%m.%Y" ) == 9 ); /* date format (%x) */ - TESTCASE( fprintf( fh, "%s\n", "%H:%M:%S" ) == 9 ); /* time format (%X) */ - - TESTCASE( fprintf( fh, "%s\n", "" ) == 1 ); /* AM */ - TESTCASE( fprintf( fh, "%s\n", "" ) == 1 ); /* PM */ - fclose( fh ); - TESTCASE( ( lc = _PDCLIB_load_lc_time( "./", "test" ) ) ); - remove( "test_time.dat" ); - - TESTCASE( strcmp( lc->month_name_abbr[ 0 ], "Jan" ) == 0 ); - TESTCASE( strcmp( lc->month_name_abbr[ 11 ], "Dez" ) == 0 ); - TESTCASE( strcmp( lc->month_name_full[ 0 ], "Januar" ) == 0 ); - TESTCASE( strcmp( lc->month_name_full[ 11 ], "Dezember" ) == 0 ); - TESTCASE( strcmp( lc->day_name_abbr[ 0 ], "So" ) == 0 ); - TESTCASE( strcmp( lc->day_name_abbr[ 6 ], "Sa" ) == 0 ); - TESTCASE( strcmp( lc->day_name_full[ 0 ], "Sonntag" ) == 0 ); - TESTCASE( strcmp( lc->day_name_full[ 6 ], "Samstag" ) == 0 ); - -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_load_lines.c b/rocklibc/src/_PDCLIB/_PDCLIB_load_lines.c deleted file mode 100644 index 7529545..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_load_lines.c +++ /dev/null @@ -1,81 +0,0 @@ -/* _PDCLIB_load_lines( FILE *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -char * _PDCLIB_load_lines( FILE * fh, size_t lines ) -{ - size_t required = 0; - long pos = ftell( fh ); - char * rc = NULL; - int c; - - /* Count the number of characters */ - while ( lines && ( c = fgetc( fh ) ) != EOF ) - { - if ( c == '\n' ) - { - --lines; - } - - ++required; - } - - if ( ! feof( fh ) ) - { - if ( ( rc = (char *)malloc( required ) ) != NULL ) - { - size_t i; - - fseek( fh, pos, SEEK_SET ); - fread( rc, 1, required, fh ); - - for ( i = 0; i < required; ++i ) - { - if ( rc[ i ] == '\n' ) - { - rc[ i ] = '\0'; - } - } - } - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - FILE * fh = fopen( "test_lines.txt", "w+" ); - char * rc; - - TESTCASE( fh != NULL ); - TESTCASE( fputs( "Foo\n\nBar\n", fh ) != EOF ); - - rewind( fh ); - rc = _PDCLIB_load_lines( fh, 3 ); - fclose( fh ); - remove( "test_lines.txt" ); - - TESTCASE( rc != NULL ); - TESTCASE( strcmp( rc, "Foo" ) == 0 ); - TESTCASE( strcmp( rc + 4, "" ) == 0 ); - TESTCASE( strcmp( rc + 5, "Bar" ) == 0 ); - -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_naive_etod.c b/rocklibc/src/_PDCLIB/_PDCLIB_naive_etod.c deleted file mode 100644 index 24ba71e..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_naive_etod.c +++ /dev/null @@ -1,96 +0,0 @@ -/* _PDCLIB_naive_ptod( const char *, char ** endptr ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#include -#include - -long double _PDCLIB_naive_etod( const char * s, char ** endptr ) -{ - /* This is nowhere good enough, just a quick approximation */ - long double rc = 0.0; - - while ( isdigit( (unsigned char)*s ) ) - { - rc = rc * 10 + ( *s++ - '0' ); - } - - if ( *s == '.' ) - { - long double fraction = 0.0; - long double scale = 1.0; - ++s; - - while ( isdigit( (unsigned char)*s ) ) - { - fraction = fraction * 10 + ( *s++ - '0' ); - scale *= 10; - } - - rc += ( fraction / scale ); - } - - if ( tolower( (unsigned char)*s ) == 'e' ) - { - char sign = '+'; - long double exp = 0.0; - long double scale = 1.0; - ++s; - - if ( *s == '-' ) - { - sign = *s++; - } - else if ( *s == '+' ) - { - ++s; - } - - while ( isdigit( (unsigned char)*s ) ) - { - exp = ( exp * 10 ) + ( *s++ - '0' ); - } - - while ( exp > 0 ) - { - scale *= 10; - --exp; - } - - if ( sign == '+' ) - { - rc *= scale; - } - else - { - rc /= scale; - } - } - - if ( endptr != NULL ) - { - *endptr = (char *)s; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Tested by strtof / strtol / strtold */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_naive_ptod.c b/rocklibc/src/_PDCLIB/_PDCLIB_naive_ptod.c deleted file mode 100644 index 27e6ed9..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_naive_ptod.c +++ /dev/null @@ -1,97 +0,0 @@ -/* _PDCLIB_naive_ptod( const char *, char ** endptr ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#include -#include - -long double _PDCLIB_naive_ptod( const char * s, char ** endptr ) -{ - /* This is nowhere good enough, just a quick approximation */ - long double rc = 0.0; - const char * x; - - while ( ( x = (const char *)memchr( _PDCLIB_digits, tolower( (unsigned char)*s ), 16 ) ) != NULL ) - { - rc = rc * 16 + ( x - _PDCLIB_digits ); - } - - if ( *s == '.' ) - { - long double fraction = 0.0; - long double scale = 1.0; - ++s; - - while ( ( x = (const char *)memchr( _PDCLIB_digits, tolower( (unsigned char)*s ), 16 ) ) != NULL ) - { - fraction = fraction * 16 + ( x - _PDCLIB_digits ); - scale *= 16; - } - - rc += ( fraction / scale ); - } - - if ( tolower( (unsigned char)*s ) == 'p' ) - { - char sign = '+'; - long double exp = 0.0; - long double scale = 1.0; - ++s; - - if ( *s == '-' ) - { - sign = *s++; - } - else if ( *s == '+' ) - { - ++s; - } - - while ( isdigit( (unsigned char)*s ) ) - { - exp = ( exp * 10 ) + ( *s++ - '0' ); - } - - while ( exp > 0 ) - { - scale *= 2; - --exp; - } - - if ( sign == '+' ) - { - rc *= scale; - } - else - { - rc /= scale; - } - } - - if ( endptr != NULL ) - { - *endptr = (char *)s; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Tested by strtof / strtol / strtold */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_prepread.c b/rocklibc/src/_PDCLIB/_PDCLIB_prepread.c deleted file mode 100644 index 8f50964..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_prepread.c +++ /dev/null @@ -1,42 +0,0 @@ -/* _PDCLIB_prepread( struct _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -int _PDCLIB_prepread( struct _PDCLIB_file_t * stream ) -{ - if ( ( stream->bufidx > stream->bufend ) || - ( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || - !( stream->status & ( _PDCLIB_FREAD | _PDCLIB_FRW ) ) ) - { - /* Function called on illegal (e.g. output) stream. */ - *_PDCLIB_errno_func() = _PDCLIB_EBADF; - stream->status |= _PDCLIB_ERRORFLAG; - return EOF; - } - - stream->status |= _PDCLIB_FREAD | _PDCLIB_BYTESTREAM; - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_prepwrite.c b/rocklibc/src/_PDCLIB/_PDCLIB_prepwrite.c deleted file mode 100644 index 607d61e..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_prepwrite.c +++ /dev/null @@ -1,39 +0,0 @@ -/* _PDCLIB_prepwrite( struct _PDCLIB_file_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int _PDCLIB_prepwrite( struct _PDCLIB_file_t * stream ) -{ - if ( ( stream->bufidx < stream->bufend ) || ( stream->ungetidx > 0 ) || - ( stream->status & ( _PDCLIB_FREAD | _PDCLIB_ERRORFLAG | _PDCLIB_WIDESTREAM | _PDCLIB_EOFFLAG ) ) || - !( stream->status & ( _PDCLIB_FWRITE | _PDCLIB_FAPPEND | _PDCLIB_FRW ) ) ) - { - /* Function called on illegal (e.g. input) stream. */ - *_PDCLIB_errno_func() = _PDCLIB_EBADF; - stream->status |= _PDCLIB_ERRORFLAG; - return EOF; - } - - stream->status |= _PDCLIB_FWRITE | _PDCLIB_BYTESTREAM; - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print.c b/rocklibc/src/_PDCLIB/_PDCLIB_print.c deleted file mode 100644 index 1cd8759..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print.c +++ /dev/null @@ -1,493 +0,0 @@ -/* _PDCLIB_print( const char *, struct _PDCLIB_status_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -const char * _PDCLIB_print( const char * spec, struct _PDCLIB_status_t * status ) -{ - const char * orig_spec = spec; - - if ( *( ++spec ) == '%' ) - { - /* %% -> print single '%' */ - PUT( *spec ); - return ++spec; - } - - /* Initializing status structure */ - status->flags = 0; - status->base = 0; - status->current = 0; - status->width = 0; - status->prec = EOF; - - /* First come 0..n flags */ - do - { - switch ( *spec ) - { - case '-': - /* left-aligned output */ - status->flags |= E_minus; - ++spec; - break; - - case '+': - /* positive numbers prefixed with '+' */ - status->flags |= E_plus; - ++spec; - break; - - case '#': - /* alternative format: leading 0x for hex, 0 for octal, - forced decimal point for floats, trailing zeroes not - removed for %g/%G - */ - status->flags |= E_alt; - ++spec; - break; - - case ' ': - /* positive numbers prefixed with ' ' */ - status->flags |= E_space; - ++spec; - break; - - case '0': - /* right-aligned padding done with '0' instead of ' ' */ - status->flags |= E_zero; - ++spec; - break; - - default: - /* not a flag, exit flag parsing */ - status->flags |= E_done; - break; - } - } while ( !( status->flags & E_done ) ); - - /* Optional field width */ - if ( *spec == '*' ) - { - /* Retrieve width value from argument stack */ - int width = va_arg( status->arg, int ); - - if ( width < 0 ) - { - status->flags |= E_minus; - status->width = abs( width ); - } - else - { - status->width = width; - } - - ++spec; - } - else - { - /* If a width is given, strtol() will return its value. If not given, - strtol() will return zero. In both cases, endptr will point to the - rest of the conversion specifier - just what we need. - */ - status->width = ( int )strtol( spec, ( char ** )&spec, 10 ); - } - - /* Optional precision */ - if ( *spec == '.' ) - { - ++spec; - - if ( *spec == '*' ) - { - /* Retrieve precision value from argument stack. A negative value - is as if no precision is given - as precision is initalized to - EOF (negative), there is no need for testing for negative here. - */ - status->prec = va_arg( status->arg, int ); - ++spec; - } - else - { - char * endptr; - status->prec = ( int )strtol( spec, &endptr, 10 ); - - if ( spec == endptr ) - { - /* Decimal point but no number - equals zero */ - status->prec = 0; - } - - spec = endptr; - } - } - - /* Optional length modifier - We step one character ahead in any case, and step back only if we find - there has been no length modifier (or step ahead another character if it - has been "hh" or "ll"). - */ - switch ( *( spec++ ) ) - { - case 'h': - if ( *spec == 'h' ) - { - /* hh -> char */ - status->flags |= E_char; - ++spec; - } - else - { - /* h -> short */ - status->flags |= E_short; - } - - break; - - case 'l': - if ( *spec == 'l' ) - { - /* ll -> long long */ - status->flags |= E_llong; - ++spec; - } - else - { - /* k -> long */ - status->flags |= E_long; - } - - break; - - case 'j': - /* j -> intmax_t, which might or might not be long long */ - status->flags |= E_intmax; - break; - - case 'z': - /* z -> size_t, which might or might not be unsigned int */ - status->flags |= E_size; - break; - - case 't': - /* t -> ptrdiff_t, which might or might not be long */ - status->flags |= E_ptrdiff; - break; - - case 'L': - /* L -> long double */ - status->flags |= E_ldouble; - break; - - default: - --spec; - break; - } - - /* Conversion specifier */ - switch ( *spec ) - { - case 'd': - /* FALLTHROUGH */ - - case 'i': - status->base = 10; - break; - - case 'o': - status->base = 8; - status->flags |= E_unsigned; - break; - - case 'u': - status->base = 10; - status->flags |= E_unsigned; - break; - - case 'x': - status->base = 16; - status->flags |= ( E_lower | E_unsigned ); - break; - - case 'X': - status->base = 16; - status->flags |= E_unsigned; - break; - - case 'f': - status->base = 2; - status->flags |= ( E_decimal | E_double | E_lower ); - break; - - case 'F': - status->base = 2; - status->flags |= ( E_decimal | E_double ); - break; - - case 'e': - status->base = 2; - status->flags |= ( E_exponent | E_double | E_lower ); - break; - - case 'E': - status->base = 2; - status->flags |= ( E_exponent | E_double ); - break; - - case 'g': - status->base = 2; - status->flags |= ( E_generic | E_double | E_lower ); - break; - - case 'G': - status->base = 2; - status->flags |= ( E_generic | E_double ); - break; - - case 'a': - status->base = 2; - status->flags |= ( E_hexa | E_double | E_lower ); - break; - - case 'A': - status->base = 2; - status->flags |= ( E_hexa | E_double ); - break; - - case 'c': - /* TODO: wide chars. */ - { - char c[1]; - c[0] = ( char )va_arg( status->arg, int ); - status->flags |= E_char; - _PDCLIB_print_string( c, status ); - return ++spec; - } - - case 's': - /* TODO: wide chars. */ - _PDCLIB_print_string( va_arg( status->arg, char * ), status ); - return ++spec; - - case 'p': - status->base = 16; - status->flags |= ( E_lower | E_unsigned | E_alt | E_pointer ); - break; - - case 'n': - { - int * val = va_arg( status->arg, int * ); - *val = status->i; - return ++spec; - } - - default: - /* No conversion specifier. Bad conversion. */ - return orig_spec; - } - - /* Do the actual output based on our findings */ - if ( status->base != 0 ) - { - /* TODO: Check for invalid flag combinations. */ - if ( status->flags & E_double ) - { - /* Floating Point conversions */ - if ( status->flags & E_ldouble ) - { - long double value = va_arg( status->arg, long double ); - _PDCLIB_fp_t fp; - _PDCLIB_fp_from_ldbl( &fp, value ); - _PDCLIB_print_fp( &fp, status ); - } - else - { - double value = va_arg( status->arg, double ); - _PDCLIB_fp_t fp; - _PDCLIB_fp_from_dbl( &fp, value ); - _PDCLIB_print_fp( &fp, status ); - } - } - else - { - /* Having a precision cancels out any zero flag. */ - if ( status->prec != EOF ) - { - status->flags &= ~E_zero; - } - - if ( status->flags & E_unsigned ) - { - /* Integer conversions (unsigned) */ - uintmax_t value; - imaxdiv_t div; - - switch ( status->flags & ( E_char | E_short | E_long | E_llong | E_size | E_pointer | E_intmax ) ) - { - case E_char: - value = ( uintmax_t )( unsigned char )va_arg( status->arg, int ); - break; - - case E_short: - value = ( uintmax_t )( unsigned short )va_arg( status->arg, int ); - break; - - case 0: - value = ( uintmax_t )va_arg( status->arg, unsigned int ); - break; - - case E_long: - value = ( uintmax_t )va_arg( status->arg, unsigned long ); - break; - - case E_llong: - value = ( uintmax_t )va_arg( status->arg, unsigned long long ); - break; - - case E_size: - value = ( uintmax_t )va_arg( status->arg, size_t ); - break; - - case E_pointer: - value = ( uintmax_t )( uintptr_t )va_arg( status->arg, void * ); - break; - - case E_intmax: - value = va_arg( status->arg, uintmax_t ); - break; - - default: - puts( "UNSUPPORTED PRINTF FLAG COMBINATION" ); - return NULL; - } - - div.quot = value / status->base; - div.rem = value % status->base; - _PDCLIB_print_integer( div, status ); - } - else - { - /* Integer conversions (signed) */ - intmax_t value; - - switch ( status->flags & ( E_char | E_short | E_long | E_llong | E_intmax ) ) - { - case E_char: - value = ( intmax_t )( char )va_arg( status->arg, int ); - break; - - case E_short: - value = ( intmax_t )( short )va_arg( status->arg, int ); - break; - - case 0: - value = ( intmax_t )va_arg( status->arg, int ); - break; - - case E_long: - value = ( intmax_t )va_arg( status->arg, long ); - break; - - case E_llong: - value = ( intmax_t )va_arg( status->arg, long long ); - break; - - case E_ptrdiff: - value = ( intmax_t )va_arg( status->arg, ptrdiff_t ); - break; - - case E_intmax: - value = va_arg( status->arg, intmax_t ); - break; - - default: - puts( "UNSUPPORTED PRINTF FLAG COMBINATION" ); - return NULL; - } - - _PDCLIB_print_integer( imaxdiv( value, status->base ), status ); - } - } - - if ( status->flags & E_minus ) - { - /* Left-aligned filling */ - while ( status->current < status->width ) - { - PUT( ' ' ); - ++( status->current ); - } - } - - if ( status->i >= status->n && status->n > 0 ) - { - status->s[status->n - 1] = '\0'; - } - } - - return ++spec; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "_PDCLIB/print.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -#ifndef REGTEST - -static int testprintf( char * buffer, const char * format, ... ) -{ - /* Members: base, flags, n, i, current, s, width, prec, stream, arg */ - struct _PDCLIB_status_t status; - status.base = 0; - status.flags = 0; - status.n = 100; - status.i = 0; - status.current = 0; - status.s = buffer; - status.width = 0; - status.prec = EOF; - status.stream = NULL; - va_start( status.arg, format ); - memset( buffer, '\0', 100 ); - - if ( *( _PDCLIB_print( format, &status ) ) != '\0' ) - { - printf( "_PDCLIB_print() did not return end-of-specifier on '%s'.\n", format ); - ++TEST_RESULTS; - } - - va_end( status.arg ); - return status.i; -} - -#endif - -#define TEST_CONVERSION_ONLY - -#include - -int main( void ) -{ -#ifndef REGTEST - char target[100]; -#include "printf_testcases.h" -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp.c b/rocklibc/src/_PDCLIB/_PDCLIB_print_fp.c deleted file mode 100644 index 0a4b7d4..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp.c +++ /dev/null @@ -1,390 +0,0 @@ -/* _PDCLIB_print_fp( _PDCLIB_fp_t *, struct _PDCLIB_status_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include -#include - -#define MIN( x, y ) ( ( x < y ) ? x : y ) - -static char * exp_to_buffer( int exponent, char * buffer ) -{ - div_t dv = div( exponent, 10 ); - - if ( dv.quot > 0 ) - { - buffer = exp_to_buffer( dv.quot, buffer ); - } - - *buffer++ = _PDCLIB_digits[ dv.rem ]; - return buffer; -} - -static void _PDCLIB_format_e( struct _PDCLIB_status_t * status, char * buffer, int exp10, char sign ) -{ - size_t len = strlen( buffer ); - int exponent = ( len + exp10 ) - 1; - int i; - char exp_buffer[8]; - char * current; - - /* Print exponent to exp_buffer */ - current = exp_buffer; - *current++ = ( status->flags & E_lower ) ? 'e' : 'E'; - - if ( exponent < 0 ) - { - *current++ = '-'; - exponent *= -1; - } - else - { - *current++ = '+'; - } - - if ( exponent > -10 && exponent < 10 ) - { - *current++ = '0'; - } - - current = exp_to_buffer( exponent, current ); - *current = '\0'; - - /* Left padding, if applicable */ - if ( ! ( status->flags & E_minus ) ) - { - i = ( sign != '\0' ) - + 1 - + ( status->prec > 0 || status->flags & E_alt ) - + ( ( status->prec > 0 ) ? status->prec : 0 ) - + ( current - exp_buffer ); - - if ( ( sign != '\0' ) && ( status->flags & E_zero ) ) - { - PUT( sign ); - status->current++; - } - - for ( ; (size_t)i < status->width; ++i ) - { - PUT( ( status->flags & E_zero ) ? '0' : ' ' ); - status->current++; - } - - if ( ( sign != '\0' ) && ! ( status->flags & E_zero ) ) - { - PUT( sign ); - status->current++; - } - } - else if ( sign != '\0' ) - { - PUT( sign ); - status->current++; - } - - /* Print buffer */ - current = buffer; - PUT( _PDCLIB_digits[ (size_t)*current++ ] ); - status->current++; - - if ( status->prec > 0 || status->flags & E_alt ) - { - PUT( '.' ); - status->current++; - } - - for ( i = 0; i < status->prec; ++i ) - { - if ( *current != '\0' ) - { - PUT( _PDCLIB_digits[ (size_t)*current++ ] ); - status->current++; - } - else if ( ! ( status->flags & E_generic ) ) - { - PUT( '0' ); - status->current++; - } - } - - /* Print exponent */ - for ( current = exp_buffer; *current != '\0'; ++current ) - { - PUT( *current ); - status->current++; - } -} - -static void _PDCLIB_format_f( struct _PDCLIB_status_t * status, char * buffer, int exp10, char sign ) -{ - size_t len = strlen( buffer ); - - /* Left padding, if applicable */ - if ( ! ( status->flags & E_minus ) ) - { - size_t i = ( sign != '\0' ) - + ( ( (int)len + exp10 > 0 ) ? ( len + exp10 ) : 1 ) - + ( status->prec > 0 || status->flags & E_alt ) - + ( ( status->prec > 0 ) ? status->prec : 0 ); - - if ( ( sign != '\0' ) && ( status->flags & E_zero ) ) - { - PUT( sign ); - status->current++; - } - - for ( ; i < status->width; ++i ) - { - PUT( ( status->flags & E_zero ) ? '0' : ' ' ); - status->current++; - } - - if ( ( sign != '\0' ) && ! ( status->flags & E_zero ) ) - { - PUT( sign ); - status->current++; - } - } - else if ( sign != '\0' ) - { - PUT( sign ); - status->current++; - } - - if ( exp10 >= 0 ) - { - /* Print buffer, period, zeroes to precision */ - /* len + exp10 + [period + [prec]] */ - int i; - - for ( i = 0; (size_t)i < len; ++i ) - { - PUT( _PDCLIB_digits[ (size_t)buffer[i] ] ); - status->current++; - } - - for ( i = 0; i < exp10; ++i ) - { - PUT( _PDCLIB_digits[0] ); - status->current++; - } - - if ( ( ( ! ( status->flags & E_generic ) ) && status->prec > 0 ) || status->flags & E_alt ) - { - PUT( '.' ); - status->current++; - } - - len = status->prec; - } - else - { - int n = len + exp10; - int i; - - if ( n > 0 ) - { - /* Print n from buffer, period, rest from buffer, zeroes to precision */ - for ( i = 0; i < n; ++i ) - { - PUT( _PDCLIB_digits[ (size_t)buffer[i] ] ); - status->current++; - } - - if ( status->prec > 0 || status->flags & E_alt ) - { - PUT( '.' ); - status->current++; - } - - for ( i = 0; buffer[ i + n ] != '\0'; ++i ) - { - PUT( _PDCLIB_digits[ (size_t)buffer[ i + n ] ] ); - status->current++; - } - - len = status->prec - i; - } - else - { - /* Print zero, period, -n zeroes, buffer, zeroes to precision */ - PUT( _PDCLIB_digits[0] ); - status->current++; - - if ( status->prec > 0 || status->flags & E_alt ) - { - PUT( '.' ); - status->current++; - } - - for ( i = 0; i < -n; ++i ) - { - PUT( _PDCLIB_digits[0] ); - status->current++; - } - - for ( i = 0; buffer[i] != '\0'; ++i ) - { - PUT( _PDCLIB_digits[ (size_t)buffer[i] ] ); - status->current++; - } - - n = -n + i; - len = status->prec - n; - } - } - - if ( ! ( status->flags & E_generic ) ) - { - for ( ; len > 0; --len ) - { - PUT( _PDCLIB_digits[0] ); - status->current++; - } - } -} - -static void _PDCLIB_format_infnan( struct _PDCLIB_status_t * status, int state, char sign ) -{ - size_t i; - char const * s = ( state == _PDCLIB_FP_INF ) - ? ( ( status->flags & E_lower ) ? "inf" : "INF" ) - : ( ( status->flags & E_lower ) ? "nan" : "NAN" ); - - /* Left padding, if applicable */ - if ( ! ( status->flags & E_minus ) ) - { - i = ( sign != '\0' ) ? 4 : 3; - for ( i = ( sign != '\0' ) ? 4 : 3; i < status->width; ++i ) - { - PUT( ' ' ); - status->current++; - } - } - - if ( sign != '\0' ) - { - PUT( sign ); - status->current++; - } - - for ( i = 0; i < 3; ++i ) - { - PUT( s[i] ); - } - - status->current += 3; -} - -void _PDCLIB_print_fp( _PDCLIB_fp_t * fp, - struct _PDCLIB_status_t * status ) -{ - char buffer[ _PDCLIB_LDBL_MANT_DIG + 10 ]; - - /* Turning sign bit into sign character. */ - if ( fp->sign == 1 ) - { - fp->sign = '-'; - } - else if ( status->flags & E_plus ) - { - fp->sign = '+'; - } - else if ( status->flags & E_space ) - { - fp->sign = ' '; - } - else - { - fp->sign = '\0'; - } - - if ( fp->state == _PDCLIB_FP_INF || fp->state == _PDCLIB_FP_NAN ) - { - _PDCLIB_format_infnan( status, fp->state, fp->sign ); - return; - } - - if ( status->flags & E_hexa ) - { - _PDCLIB_print_fp_hexa( fp, status, buffer ); - return; - } - else - { - int exp10; - - if ( status->prec < 0 ) - { - status->prec = 6; - } - - switch ( status->flags & ( E_decimal | E_exponent | E_generic ) ) - { - case E_decimal: - { - exp10 = _PDCLIB_print_fp_deci( fp, status, buffer ); - _PDCLIB_format_f( status, buffer, exp10, fp->sign ); - break; - } - case E_exponent: - { - exp10 = _PDCLIB_print_fp_deci( fp, status, buffer ); - _PDCLIB_format_e( status, buffer, exp10, fp->sign ); - break; - } - case E_generic: - { - _PDCLIB_bigint_t mant; - int exponent; - _PDCLIB_bigint_from_bigint( &mant, &fp->mantissa ); - - if ( status->prec == 0 ) - { - status->prec = 1; - } - - exp10 = _PDCLIB_print_fp_deci( fp, status, buffer ); - exponent = ( strlen( buffer ) + exp10 ) - 1; - - if ( exponent >= -4 && exponent < status->prec ) - { - _PDCLIB_bigint_from_bigint( &fp->mantissa, &mant ); - status->flags &= ~E_generic; - status->flags |= E_decimal; - status->prec -= exponent + 1; - exp10 = _PDCLIB_print_fp_deci( fp, status, buffer ); - status->flags |= E_generic; - _PDCLIB_format_f( status, buffer, exp10, fp->sign ); - } - else - { - status->prec -= 1; - _PDCLIB_format_e( status, buffer, exp10, fp->sign ); - } - break; - } - } - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( int argc, char * argv[] ) -{ - /* Tested by _PDCLIB_print testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_deci.c b/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_deci.c deleted file mode 100644 index 890328f..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_deci.c +++ /dev/null @@ -1,211 +0,0 @@ -/* _PDCLIB_print_fp_deci( _PDCLIB_fp_t *, struct _PDCLIB_status_t *, char ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -static int prep( _PDCLIB_bigint_t * mantissa, int exponent ) -{ - /* log10(2) to 128bit precision */ - const long double log_10_2 = 0.30102999566398119521373889472449302l; - - /* Get an approximation of the base 10 exponent we are looking at - and make it fall one short in most cases as correction is easier - that way. - */ - double guess = (double)( _PDCLIB_bigint_log2( mantissa ) + exponent ) * log_10_2 - 0.69; - int exp10 = ( (int)guess < guess ) ? (int)guess + 1 : (int)guess; - - return exp10; -} - -int _PDCLIB_print_fp_deci( _PDCLIB_fp_t * fp, - struct _PDCLIB_status_t * status, - char * buffer ) -{ - char * current = buffer; - _PDCLIB_bigint_t divisor; - _PDCLIB_bigint_digit_t msd; - int digit; - int cutoff; - - /* No decimal point in the mantissa, so we adjust the exponent. */ - int exponent = fp->exponent - fp->scale; - - int exp10 = prep( &fp->mantissa, exponent ); - - if ( ( status->flags & E_decimal ) && ( status->prec >= 0 ) && ( exp10 <= -status->prec ) ) - { - exp10 = -status->prec + 1; - } - - /* Set up the fraction. */ - if ( exponent > 0 ) - { - _PDCLIB_bigint_shl( &fp->mantissa, exponent ); - _PDCLIB_bigint_from_digit( &divisor, 1 ); - } - else - { - _PDCLIB_bigint_from_pow2( &divisor, -exponent ); - } - - /* Using the approx. exp10, scale the fraction close to where - we could start dividing. - */ - if ( exp10 > 0 ) - { - _PDCLIB_bigint_mul_pow10( &divisor, exp10 ); - } - else if ( exp10 < 0 ) - { - _PDCLIB_bigint_mul_pow10( &fp->mantissa, -exp10 ); - } - - /* Now we know if our approximation was good or needs correction. - This is why we substracted as much as we could in prep(), as - correctiong for one short is the cheaper operation. - */ - if ( _PDCLIB_bigint_cmp( &fp->mantissa, &divisor ) >= 0 ) - { - ++exp10; - } - else - { - _PDCLIB_bigint_mul10( &fp->mantissa ); - } - - /* We make sure the fraction is scaled properly. - The previous operations already ensured that - the mantissa is no more than divisor * 10. - Now we make sure that the divisor has enough - bits in the most significant digit to give a - proper result, and that both mantissa and the - divisor are scaled to the same bigint length. - */ - msd = divisor.data[ divisor.size - 1 ]; - - if ( ( msd < 8 ) || ( msd > ( _PDCLIB_BIGINT_DIGIT_MAX / 10 ) ) ) - { - int shift = ( ( _PDCLIB_BIGINT_DIGIT_BITS * 2 - 5 ) - _PDCLIB_bigint_digit_log2( msd ) ) % 32; - _PDCLIB_bigint_shl( &fp->mantissa, shift ); - _PDCLIB_bigint_shl( &divisor, shift ); - } - - /* Main loop - divide, generate digits, multiply with 10, repeat */ - switch ( status->flags & ( E_decimal | E_exponent | E_generic ) ) - { - case E_decimal: - cutoff = -status->prec; - break; - case E_exponent: - case E_generic: - cutoff = exp10 - status->prec - 1; - break; - } - - for (;;) - { - digit = _PDCLIB_bigint_div( &fp->mantissa, &divisor ); - --exp10; - - if ( fp->mantissa.size == 0 || exp10 == cutoff ) - { - break; - } - - *current++ = _PDCLIB_digits[ digit ]; - _PDCLIB_bigint_mul10( &fp->mantissa ); - } - - /* rounding */ - { - int roundup = 0; - - switch ( FLT_ROUNDS ) - { - case 3: /*FE_DOWNWARD*/ - roundup = ( fp->sign == '-' ); - break; - case 2: /*FE_UPWARD*/ - roundup = ( fp->sign != '-' ); - break; - case 0: /*FE_TOWARDZERO*/ - roundup = 0; - break; - default: - case 1: /*FE_TONEAREST*/ - { - int compare; - _PDCLIB_bigint_shl( &fp->mantissa, 1 ); - compare = _PDCLIB_bigint_cmp( &fp->mantissa, &divisor ); - if ( ( compare > 0 ) /* Over 0.5 */ - || ( ( compare == 0 ) && ( digit & 1 ) ) ) /* Break tie to even */ - { - roundup = 1; - } - } - - if ( roundup ) - { - if ( digit < 9 ) - { - *current++ = _PDCLIB_digits[ ++digit ]; - } - else - { - for (;;) - { - ++exp10; - - if ( current == buffer ) - { - *current++ = _PDCLIB_digits[1]; - ++exp10; - break; - } - - if ( *--current != _PDCLIB_digits[9] ) - { - ++*current++; - break; - } - } - } - } - else - { - *current++ = _PDCLIB_digits[ digit ]; - } - } - - while ( *(current - 1) == '0' ) - { - --current; - ++exp10; - } - } - - *current = '\0'; - return exp10; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( int argc, char * argv[] ) -{ - /* Tested by _PDCLIB_print testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_hexa.c b/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_hexa.c deleted file mode 100644 index d2b56e5..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print_fp_hexa.c +++ /dev/null @@ -1,268 +0,0 @@ -/* _PDCLIB_print_fp_hexa( _PDCLIB_bigint_t *, struct _PDCLIB_status_t *, char ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include -#include -#include - -static inline void round_up( char * buffer, size_t index ) -{ - if ( buffer[ index ] < '\017' ) - { - ++buffer[ index ]; - } - else - { - buffer[ index ] = '\0'; - round_up( buffer, index - 1 ); - } -} - -static inline void round( char * buffer, size_t last_non_zero, size_t prec, char sign ) -{ - switch ( FLT_ROUNDS ) - { - case 0: /*FE_TOWARDZERO*/ - break; - default: /*FE_TONEAREST*/ - case 1: - if ( buffer[ prec + 1 ] > '\005' ) - { - round_up( buffer, prec ); - } - else if ( buffer[ prec + 1 ] == '\005' ) - { - if ( last_non_zero > ( prec + 1 ) || ( buffer[ prec ] % 2 ) ) - { - round_up( buffer, prec ); - } - } - break; - case 2: /*FE_UPWARD*/ - if ( sign != '-' ) - { - round_up( buffer, prec ); - } - break; - case 3: /*FE_DOWNWARD*/ - if ( sign == '-' ) - { - round_up( buffer, prec ); - } - break; - } -} - -static char * print_exp( char * buffer, int exp ) -{ - div_t dv = div( exp, 10 ); - - if ( dv.quot > 0 ) - { - buffer = print_exp( buffer, dv.quot ); - } - - *buffer = _PDCLIB_digits[ dv.rem ]; - return ++buffer; -} - -static size_t print_mant( _PDCLIB_fp_t * fp, struct _PDCLIB_status_t * status, char * buffer ) -{ - size_t i; - int last_non_zero; - size_t mant_dig = ( ( status->flags & E_ldouble ) ? _PDCLIB_LDBL_MANT_DIG : _PDCLIB_DBL_MANT_DIG ) - 1; - size_t log2 = _PDCLIB_bigint_log2( &fp->mantissa ); - char * bufend = buffer; - - if ( ( mant_dig % 4 ) > 0 ) - { - /* alignment */ - int shift = 4 - ( mant_dig % 4 ); - _PDCLIB_bigint_shl( &fp->mantissa, shift ); - mant_dig += shift; - log2 += shift; - } - - if ( mant_dig > log2 ) - { - /* subnormal, leading zeroes */ - for ( i = 0; i <= ( mant_dig - log2 - 1 ) / 4; ++i ) - { - *bufend++ = '\0'; - } - } - - for ( i = log2 / 4 + 1; i > 0; --i, ++bufend ) - { - /* data nibbles */ - div_t dv = div( i - 1, _PDCLIB_BIGINT_DIGIT_BITS / 4 ); - - if ( ( *bufend = ( fp->mantissa.data[ dv.quot ] >> ( dv.rem * 4 ) ) & 0xfu ) > 0 ) - { - last_non_zero = bufend - buffer; - } - } - - if ( status->prec >= 0 ) - { - /* check rounding */ - if ( last_non_zero > ( status->prec + 1 ) ) - { - round( buffer, last_non_zero, status->prec, fp->sign ); - } - - return status->prec + 1; - } - else - { - /* no precision given */ - return last_non_zero + 1; - } -} - -void _PDCLIB_print_fp_hexa( _PDCLIB_fp_t * fp, - struct _PDCLIB_status_t * status, - char * buffer ) -{ - _PDCLIB_static_assert( _PDCLIB_FLT_RADIX == 2, "Assuming 2-based Floating Point" ); - - char const * digits = ( status->flags & E_lower ) ? _PDCLIB_digits : _PDCLIB_Xdigits; - int exp = (_PDCLIB_bigint_sdigit_t)fp->exponent; - /* sign + "0x" + dec + "." + ( LDBL_MANT_DIG / 4 ) - + 'p' + sign + exp[5] + '\0' <= 41 - ...but how could I do THAT? :-) - */ - char * current = buffer; - size_t count; - size_t i; - - /* significant */ - if ( fp->mantissa.size == 0 ) - { - *current++ = '0'; - exp = 0; - } - else - { - count = print_mant( fp, status, current ); - - *current = digits[ (size_t)*current ]; - ++current; - - if ( ( count > 1 && status->prec != 0 ) || status->flags & E_alt ) - { - for ( i = count; i > 1; --i ) - { - current[ i ] = current[ i - 1 ]; - } - - *current++ = '.'; /* TODO: decimal point */ - } - - for ( i = 1; i < count; ++i ) - { - *current = digits[ (size_t)*current ]; - ++current; - } - } - - /* exponent */ - *current++ = ( status->flags & E_lower ) ? 'p' : 'P'; - - if ( exp < 0 ) - { - *current++ = '-'; - exp *= -1; - } - else - { - *current++ = '+'; - } - - current = print_exp( current, exp ); - *current = '\0'; - - /* output */ - count = ( current - buffer ) + ( ( fp->sign == '\0' ) ? 2 : 3 ); - count = ( status->width > count ) ? ( status->width - count ) : 0; - - if ( ( count > 0 ) && ! ( status->flags & E_minus ) && ! ( status->flags & E_zero ) ) - { - for ( i = 0; i < count; ++i ) - { - PUT( ' ' ); - status->current++; - } - } - - if ( fp->sign != '\0' ) - { - PUT( fp->sign ); - status->current++; - } - - PUT( '0' ); - PUT( ( status->flags & E_lower ) ? 'x' : 'X' ); - status->current += 2; - - if ( ( count > 0 ) && ! ( status->flags & E_minus ) && ( status->flags & E_zero ) ) - { - for ( i = 0; i < count; ++i ) - { - PUT( '0' ); - status->current++; - } - } - - current = buffer; - - while ( *current != '\0' ) - { - PUT( *current++ ); - status->current++; - } - - if ( ( count > 0 ) && ( status->flags & E_minus ) ) - { - for ( i = 0; i < count; ++i ) - { - PUT( ' ' ); - status->current++; - } - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( int argc, char * argv[] ) -{ - /* Tested by _PDCLIB_print testdriver */ -#ifndef REGTEST - char buffer[100]; - *(print_exp( buffer, 0 )) = '\0'; - TESTCASE( strcmp( buffer, "0" ) == 0 ); - - *(print_exp( buffer, 9 )) = '\0'; - TESTCASE( strcmp( buffer, "9" ) == 0 ); - - *(print_exp( buffer, 10 )) = '\0'; - TESTCASE( strcmp( buffer, "10" ) == 0 ); - - *(print_exp( buffer, 100 )) = '\0'; - TESTCASE( strcmp( buffer, "100" ) == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print_integer.c b/rocklibc/src/_PDCLIB/_PDCLIB_print_integer.c deleted file mode 100644 index bca0ce4..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print_integer.c +++ /dev/null @@ -1,175 +0,0 @@ -/* _PDCLIB_print_integer - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include - -#include "pdclib/_PDCLIB_print.h" - -static void intformat( intmax_t value, struct _PDCLIB_status_t * status ) -{ - /* At worst, we need two prefix characters (hex prefix). */ - char preface[3] = "\0"; - size_t preidx = 0; - - if ( status->prec < 0 ) - { - status->prec = 1; - } - - if ( ( status->flags & E_alt ) && ( status->base == 16 || status->base == 8 ) && ( value != 0 ) ) - { - /* Octal / hexadecimal prefix for "%#" conversions */ - preface[ preidx++ ] = '0'; - - if ( status->base == 16 ) - { - preface[ preidx++ ] = ( status->flags & E_lower ) ? 'x' : 'X'; - } - } - - if ( value < 0 ) - { - /* Negative sign for negative values - at all times. */ - preface[ preidx++ ] = '-'; - } - else if ( !( status->flags & E_unsigned ) ) - { - /* plus sign / extra space are only for signed conversions */ - if ( status->flags & E_plus ) - { - preface[ preidx++ ] = '+'; - } - else - { - if ( status->flags & E_space ) - { - preface[ preidx++ ] = ' '; - } - } - } - - { - /* At this point, status->current has the number of digits queued up. - Determine if we have a precision requirement to pad those. - */ - size_t prec_pads = ( ( _PDCLIB_size_t )status->prec > status->current ) ? ( ( _PDCLIB_size_t )status->prec - status->current ) : 0; - - if ( !( status->flags & ( E_minus | E_zero ) ) ) - { - /* Space padding is only done if no zero padding or left alignment - is requested. Calculate the number of characters that WILL be - printed, including any prefixes determined above. - */ - /* The number of characters to be printed, plus prefixes if any. */ - /* This line contained probably the most stupid, time-wasting bug - I've ever perpetrated. Greetings to Samface, DevL, and all - sceners at Breakpoint 2006. - */ - size_t characters = preidx + ( ( status->current > ( _PDCLIB_size_t )status->prec ) ? status->current : ( _PDCLIB_size_t )status->prec ); - - if ( status->width > characters ) - { - size_t i; - - for ( i = 0; i < status->width - characters; ++i ) - { - PUT( ' ' ); - ++( status->current ); - } - } - } - - /* Now we did the padding, do the prefixes (if any). */ - preidx = 0; - - while ( preface[ preidx ] != '\0' ) - { - PUT( preface[ preidx++ ] ); - ++( status->current ); - } - - /* Do the precision padding if necessary. */ - while ( prec_pads-- > 0 ) - { - PUT( '0' ); - ++( status->current ); - } - - if ( ( !( status->flags & E_minus ) ) && ( status->flags & E_zero ) ) - { - /* If field is not left aligned, and zero padding is requested, do - so. - */ - while ( status->current < status->width ) - { - PUT( '0' ); - ++( status->current ); - } - } - } -} - -/* This function recursively converts a given integer value to a character - stream. The conversion is done under the control of a given status struct - and written either to a character string or a stream, depending on that - same status struct. The status struct also keeps the function from exceeding - snprintf() limits, and enables any necessary padding / prefixing of the - output once the number of characters to be printed is known, which happens - at the lowermost recursion level. -*/ -void _PDCLIB_print_integer( imaxdiv_t div, struct _PDCLIB_status_t * status ) -{ - if ( status->current == 0 && div.quot == 0 && div.rem == 0 && status->prec == 0 ) - { - intformat( 0, status ); - } - else - { - ++(status->current); - - if ( div.quot != 0 ) - { - _PDCLIB_print_integer( imaxdiv( div.quot, status->base ), status ); - } - else - { - intformat( div.rem, status ); - } - - if ( div.rem < 0 ) - { - div.rem *= -1; - } - - if ( status->flags & E_lower ) - { - PUT( _PDCLIB_digits[ div.rem ] ); - } - else - { - PUT( _PDCLIB_Xdigits[ div.rem ] ); - } - } -} - -#endif - -#ifdef TEST - -#include - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Tested by the various *printf() drivers. */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_print_string.c b/rocklibc/src/_PDCLIB/_PDCLIB_print_string.c deleted file mode 100644 index ab253a8..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_print_string.c +++ /dev/null @@ -1,85 +0,0 @@ -/* _PDCLIB_print_string - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include -#include -#include - -#include "pdclib/_PDCLIB_print.h" - -/* Print a "string" (%c, %s) under control of a given status struct. See - INT2BASE(). -*/ -void _PDCLIB_print_string( const char * s, struct _PDCLIB_status_t * status ) -{ - if ( status->flags & E_char ) - { - status->prec = 1; - } - else - { - if ( status->prec < 0 ) - { - status->prec = strlen( s ); - } - else - { - int i; - - for ( i = 0; i < status->prec; ++i ) - { - if ( s[i] == 0 ) - { - status->prec = i; - break; - } - } - } - } - - if ( !( status->flags & E_minus ) && ( status->width > ( _PDCLIB_size_t )status->prec ) ) - { - while ( status->current < ( status->width - status->prec ) ) - { - PUT( ' ' ); - ++( status->current ); - } - } - - while ( status->prec > 0 ) - { - PUT( *( s++ ) ); - --( status->prec ); - ++( status->current ); - } - - if ( status->flags & E_minus ) - { - while ( status->width > status->current ) - { - PUT( ' ' ); - ++( status->current ); - } - } -} - -#endif - -#ifdef TEST - -#include - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Tested by _PDCLIB_print testdriver */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_realpath.c b/rocklibc/src/_PDCLIB/_PDCLIB_realpath.c deleted file mode 100644 index 8711c36..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_realpath.c +++ /dev/null @@ -1,61 +0,0 @@ -/* _PDCLIB_realpath( const char * path ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -extern char * realpath( const char * file_name, char * resolved_name ); - -#ifdef __cplusplus -} -#endif - -char * _PDCLIB_realpath( const char * path ) -{ - /* TODO: PATH_MAX but that seems difficult to come by */ - char buffer[ 4096 ]; - char * resolved_name; - - if ( realpath( path, buffer ) == NULL ) - { - return NULL; - } - - /* Need to do our own alloc-and-copy here, as realpath() - would be linked to the system malloc(), and if our - fclose() would run our free() on someone else's memory, - results are more interesting than we would like to see. - */ - if ( ( resolved_name = malloc( strlen( buffer + 1 ) ) ) == NULL ) - { - return NULL; - } - - return strcpy( resolved_name, buffer ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* No test drivers. */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_remove.c b/rocklibc/src/_PDCLIB/_PDCLIB_remove.c deleted file mode 100644 index aaad673..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_remove.c +++ /dev/null @@ -1,42 +0,0 @@ -/* _PDCLIB_remove( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_remove() fit for use with - POSIX kernels. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int unlink( const char * ); - -#ifdef __cplusplus -} -#endif - -int _PDCLIB_remove( const char * pathname ) -{ - return unlink( pathname ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c (and several others) */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_rename.c b/rocklibc/src/_PDCLIB/_PDCLIB_rename.c deleted file mode 100644 index 2ff1cea..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_rename.c +++ /dev/null @@ -1,117 +0,0 @@ -/* _PDCLIB_rename( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_rename() fit for use with - POSIX kernels. - */ - -#include - -#ifndef REGTEST - -/* Having to jump through some hoops here so including fcntl.h does - work. Linux struggles with redefinitions of SEEK_SET et al. if - we set _GNU_SOURCE, but Cygwin needs that to actually get to the - AT_FDCWD definition. -*/ -#ifdef __linux__ -#define _ATFILE_SOURCE 1 -#else -#define _GNU_SOURCE 1 -#endif - -#include "pdclib/_PDCLIB_glue.h" -#include "pdclib/_PDCLIB_defguard.h" - -#include "pdclib/_PDCLIB_platform_errno.h" - -/* The system calls provided for renaming are rename(), renameat() - and renameat2(). Using rename() is not possible, since we have - that symbol in our library and would end up with a recursive - call. But we *can* use renameat() with default parameters! - AT_FDCWD is declared in fcntl.h. We need to manually declare - renameat() here as it is declared in system's . -*/ -#include "pdclib/_PDCLIB_platform_fcntl.h" - -#ifdef __cplusplus -extern "C" { -#endif - -int renameat( int, const char *, int, const char * ); - -#ifdef __cplusplus -} -#endif - -int _PDCLIB_rename( const char * oldpath, const char * newpath ) -{ - /* Whether existing newpath is overwritten is implementation- - defined. This system call *does* overwrite. - */ - if ( renameat( AT_FDCWD, oldpath, AT_FDCWD, newpath ) != 0 ) - { - /* The 1:1 mapping in _PDCLIB_config.h ensures this works. */ - *_PDCLIB_errno_func() = errno; - return -1; - } - else - { - return 0; - } -} - -#endif - -#ifdef TEST -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - FILE * file; - remove( testfile1 ); - remove( testfile2 ); - /* check that neither file exists */ - TESTCASE( fopen( testfile1, "r" ) == NULL ); - TESTCASE( fopen( testfile2, "r" ) == NULL ); - /* rename file 1 to file 2 - expected to fail */ - TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == -1 ); - /* create file 1 */ - TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); - TESTCASE( fputc( 'x', file ) == 'x' ); - TESTCASE( fclose( file ) == 0 ); - /* check that file 1 exists */ - TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* rename file 1 to file 2 */ - TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == 0 ); - /* check that file 2 exists, file 1 does not */ - TESTCASE( fopen( testfile1, "r" ) == NULL ); - TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* create another file 1 */ - TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); - TESTCASE( fputc( 'x', file ) == 'x' ); - TESTCASE( fclose( file ) == 0 ); - /* check that file 1 exists */ - TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* Whether existing destination files are overwritten or not - is implementation-defined. - This implementation *does* overwrite. - */ - TESTCASE( _PDCLIB_rename( testfile1, testfile2 ) == 0 ); - /* remove both files */ - remove( testfile1 ); - remove( testfile2 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_scan.c b/rocklibc/src/_PDCLIB/_PDCLIB_scan.c deleted file mode 100644 index 1bc23d0..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_scan.c +++ /dev/null @@ -1,781 +0,0 @@ -/* _PDCLIB_scan( const char *, struct _PDCLIB_status_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -/* Using an integer's bits as flags for both the conversion flags and length - modifiers. -*/ -#define E_suppressed 1<<0 -#define E_char 1<<6 -#define E_short 1<<7 -#define E_long 1<<8 -#define E_llong 1<<9 -#define E_intmax 1<<10 -#define E_size 1<<11 -#define E_ptrdiff 1<<12 -#define E_pointer 1<<13 -#define E_ldouble 1<<14 -#define E_unsigned 1<<16 - - -/* Helper function to get a character from the string or stream, whatever is - used for input. When reading from a string, returns EOF on end-of-string - so that handling of the return value can be uniform for both streams and - strings. -*/ -static int GET( struct _PDCLIB_status_t * status ) -{ - int rc = EOF; - - if ( status->stream != NULL ) - { - if ( _PDCLIB_CHECKBUFFER( status->stream ) != EOF ) - { - rc = _PDCLIB_GETC( status->stream ); - } - } - else - { - rc = ( *status->s == '\0' ) ? EOF : ( unsigned char ) * ( ( status->s )++ ); - } - - if ( rc != EOF ) - { - ++( status->i ); - ++( status->current ); - } - - return rc; -} - - -/* Helper function to put a read character back into the string or stream, - whatever is used for input. -*/ -static void UNGET( int c, struct _PDCLIB_status_t * status ) -{ - if ( status->stream != NULL ) - { - ungetc( c, status->stream ); /* TODO: Error? */ - } - else - { - --( status->s ); - } - - --( status->i ); - --( status->current ); -} - - -/* Helper function to check if a character is part of a given scanset */ -static int IN_SCANSET( const char * scanlist, const char * end_scanlist, int rc ) -{ - /* SOLAR */ - int previous = -1; - - while ( scanlist != end_scanlist ) - { - if ( ( *scanlist == '-' ) && ( previous != -1 ) ) - { - /* possible scangroup ("a-z") */ - if ( ++scanlist == end_scanlist ) - { - /* '-' at end of scanlist does not describe a scangroup */ - return rc == '-'; - } - - while ( ++previous <= ( unsigned char )*scanlist ) - { - if ( previous == rc ) - { - return 1; - } - } - - previous = -1; - } - else - { - /* not a scangroup, check verbatim */ - if ( rc == ( unsigned char )*scanlist ) - { - return 1; - } - - previous = ( unsigned char )( *scanlist++ ); - } - } - - return 0; -} - - -const char * _PDCLIB_scan( const char * spec, struct _PDCLIB_status_t * status ) -{ - /* generic input character */ - int rc; - const char * prev_spec; - const char * orig_spec = spec; - int value_parsed; - - if ( *( ++spec ) == '%' ) - { - /* %% -> match single '%' */ - rc = GET( status ); - - switch ( rc ) - { - case EOF: - - /* input error */ - if ( status->n == 0 ) - { - status->n = -1; - } - - return NULL; - - case '%': - return ++spec; - - default: - UNGET( rc, status ); - break; - } - } - - /* Initializing status structure */ - status->flags = 0; - status->base = -1; - status->current = 0; - status->width = 0; - status->prec = 0; - - /* '*' suppresses assigning parsed value to variable */ - if ( *spec == '*' ) - { - status->flags |= E_suppressed; - ++spec; - } - - /* If a width is given, strtol() will return its value. If not given, - strtol() will return zero. In both cases, endptr will point to the - rest of the conversion specifier - just what we need. - */ - prev_spec = spec; - status->width = ( int )strtol( spec, ( char ** )&spec, 10 ); - - if ( spec == prev_spec ) - { - status->width = SIZE_MAX; - } - - /* Optional length modifier - We step one character ahead in any case, and step back only if we find - there has been no length modifier (or step ahead another character if it - has been "hh" or "ll"). - */ - switch ( *( spec++ ) ) - { - case 'h': - if ( *spec == 'h' ) - { - /* hh -> char */ - status->flags |= E_char; - ++spec; - } - else - { - /* h -> short */ - status->flags |= E_short; - } - - break; - - case 'l': - if ( *spec == 'l' ) - { - /* ll -> long long */ - status->flags |= E_llong; - ++spec; - } - else - { - /* l -> long */ - status->flags |= E_long; - } - - break; - - case 'j': - /* j -> intmax_t, which might or might not be long long */ - status->flags |= E_intmax; - break; - - case 'z': - /* z -> size_t, which might or might not be unsigned int */ - status->flags |= E_size; - break; - - case 't': - /* t -> ptrdiff_t, which might or might not be long */ - status->flags |= E_ptrdiff; - break; - - case 'L': - /* L -> long double */ - status->flags |= E_ldouble; - break; - - default: - --spec; - break; - } - - /* Conversion specifier */ - - /* whether valid input had been parsed */ - value_parsed = 0; - - switch ( *spec ) - { - case 'd': - status->base = 10; - break; - - case 'i': - status->base = 0; - break; - - case 'o': - status->base = 8; - status->flags |= E_unsigned; - break; - - case 'u': - status->base = 10; - status->flags |= E_unsigned; - break; - - case 'x': - status->base = 16; - status->flags |= E_unsigned; - break; - - case 'f': - case 'F': - case 'e': - case 'E': - case 'g': - case 'G': - case 'a': - case 'A': - break; - - case 'c': - { - char * c = NULL; - - if ( !( status->flags & E_suppressed ) ) - { - c = va_arg( status->arg, char * ); - } - - /* for %c, default width is one */ - if ( status->width == SIZE_MAX ) - { - status->width = 1; - } - - /* reading until width reached or input exhausted */ - while ( ( status->current < status->width ) && - ( ( rc = GET( status ) ) != EOF ) ) - { - if ( c != NULL ) - { - *( c++ ) = rc; - } - - value_parsed = 1; - } - - /* width or input exhausted */ - if ( value_parsed ) - { - if ( c != NULL ) - { - ++status->n; - } - - return ++spec; - } - else - { - /* input error, no character read */ - if ( status->n == 0 ) - { - status->n = -1; - } - - return NULL; - } - } - - case 's': - { - char * c = NULL; - - if ( !( status->flags & E_suppressed ) ) - { - c = va_arg( status->arg, char * ); - } - - while ( ( status->current < status->width ) && - ( ( rc = GET( status ) ) != EOF ) ) - { - if ( isspace( (unsigned char)rc ) ) - { - UNGET( rc, status ); - - if ( value_parsed ) - { - /* matching sequence terminated by whitespace */ - if ( c != NULL ) - { - *c = '\0'; - ++status->n; - } - - return ++spec; - } - else - { - /* matching error */ - return NULL; - } - } - else - { - /* match */ - if ( c != NULL ) - { - *( c++ ) = rc; - } - - value_parsed = 1; - } - } - - /* width or input exhausted */ - if ( value_parsed ) - { - if ( c != NULL ) - { - *c = '\0'; - ++status->n; - } - - return ++spec; - } - else - { - /* input error, no character read */ - if ( status->n == 0 ) - { - status->n = -1; - } - - return NULL; - } - } - - case '[': - { - const char * endspec = spec; - int negative_scanlist = 0; - char * c = NULL; - - if ( !( status->flags & E_suppressed ) ) - { - c = va_arg( status->arg, char * ); - } - - if ( *( ++endspec ) == '^' ) - { - negative_scanlist = 1; - ++endspec; - } - - spec = endspec; - - do - { - /* TODO: This can run beyond a malformed format string */ - ++endspec; - } while ( *endspec != ']' ); - - /* read according to scanlist, equiv. to %s above */ - while ( ( status->current < status->width ) && - ( ( rc = GET( status ) ) != EOF ) ) - { - if ( negative_scanlist ) - { - if ( IN_SCANSET( spec, endspec, rc ) ) - { - UNGET( rc, status ); - break; - } - } - else - { - if ( ! IN_SCANSET( spec, endspec, rc ) ) - { - UNGET( rc, status ); - break; - } - } - - if ( c != NULL ) - { - *( c++ ) = rc; - } - - value_parsed = 1; - } - - /* width or input exhausted */ - if ( value_parsed ) - { - if ( c != NULL ) - { - *c = '\0'; - ++status->n; - } - - return ++endspec; - } - else - { - if ( status->n == 0 ) - { - status->n = -1; - } - - return NULL; - } - } - - case 'p': - status->base = 16; - status->flags |= E_pointer; - break; - - case 'n': - { - if ( !( status->flags & E_suppressed ) ) - { - int * val = va_arg( status->arg, int * ); - *val = status->i; - } - - return ++spec; - } - - default: - /* No conversion specifier. Bad conversion. */ - return orig_spec; - } - - if ( status->base != -1 ) - { - /* integer conversion */ - uintmax_t value = 0; /* absolute value read */ - int prefix_parsed = 0; - int sign = 0; - - while ( ( status->current < status->width ) && - ( ( rc = GET( status ) ) != EOF ) ) - { - if ( isspace( (unsigned char)rc ) ) - { - if ( sign ) - { - /* matching sequence terminated by whitespace */ - UNGET( rc, status ); - break; - } - else - { - /* leading whitespace not counted against width */ - status->current--; - } - } - else - { - if ( ! sign ) - { - /* no sign parsed yet */ - switch ( rc ) - { - case '-': - sign = -1; - break; - - case '+': - sign = 1; - break; - - default: - /* not a sign; put back character */ - sign = 1; - UNGET( rc, status ); - break; - } - } - else - { - if ( ! prefix_parsed ) - { - /* no prefix (0x... for hex, 0... for octal) parsed yet */ - prefix_parsed = 1; - - if ( rc != '0' ) - { - /* not a prefix; if base not yet set, set to decimal */ - if ( status->base == 0 ) - { - status->base = 10; - } - - UNGET( rc, status ); - } - else - { - /* starts with zero, so it might be a prefix. */ - /* check what follows next (might be 0x...) */ - if ( ( status->current < status->width ) && - ( ( rc = GET( status ) ) != EOF ) ) - { - if ( tolower( (unsigned char)rc ) == 'x' ) - { - /* 0x... would be prefix for hex base... */ - if ( ( status->base == 0 ) || - ( status->base == 16 ) ) - { - status->base = 16; - } - else - { - /* ...unless already set to other value */ - UNGET( rc, status ); - value_parsed = 1; - } - } - else - { - /* 0... but not 0x.... would be octal prefix */ - UNGET( rc, status ); - - if ( status->base == 0 ) - { - status->base = 8; - } - - /* in any case we have read a zero */ - value_parsed = 1; - } - } - else - { - /* failed to read beyond the initial zero */ - value_parsed = 1; - break; - } - } - } - else - { - char * digitptr = (char *)memchr( _PDCLIB_digits, tolower( (unsigned char)rc ), status->base ); - - if ( digitptr == NULL ) - { - /* end of input item */ - UNGET( rc, status ); - break; - } - - value *= status->base; - value += digitptr - _PDCLIB_digits; - value_parsed = 1; - } - } - } - } - - /* width or input exhausted, or non-matching character */ - if ( ! value_parsed ) - { - /* out of input before anything could be parsed - input error */ - /* FIXME: if first character does not match, value_parsed is not set - but it is NOT an input error */ - if ( ( status->n == 0 ) && ( rc == EOF ) ) - { - status->n = -1; - } - - return NULL; - } - - /* convert value to target type and assign to parameter */ - if ( !( status->flags & E_suppressed ) ) - { - switch ( status->flags & ( E_char | E_short | E_long | E_llong | - E_intmax | E_size | E_ptrdiff | E_pointer | - E_unsigned ) ) - { - case E_char: - *( va_arg( status->arg, char * ) ) = ( char )( value * sign ); - break; - - case E_char | E_unsigned: - *( va_arg( status->arg, unsigned char * ) ) = ( unsigned char )( value * sign ); - break; - - case E_short: - *( va_arg( status->arg, short * ) ) = ( short )( value * sign ); - break; - - case E_short | E_unsigned: - *( va_arg( status->arg, unsigned short * ) ) = ( unsigned short )( value * sign ); - break; - - case 0: - *( va_arg( status->arg, int * ) ) = ( int )( value * sign ); - break; - - case E_unsigned: - *( va_arg( status->arg, unsigned int * ) ) = ( unsigned int )( value * sign ); - break; - - case E_long: - *( va_arg( status->arg, long * ) ) = ( long )( value * sign ); - break; - - case E_long | E_unsigned: - *( va_arg( status->arg, unsigned long * ) ) = ( unsigned long )( value * sign ); - break; - - case E_llong: - *( va_arg( status->arg, long long * ) ) = ( long long )( value * sign ); - break; - - case E_llong | E_unsigned: - *( va_arg( status->arg, unsigned long long * ) ) = ( unsigned long long )( value * sign ); - break; - - case E_intmax: - *( va_arg( status->arg, intmax_t * ) ) = ( intmax_t )( value * sign ); - break; - - case E_intmax | E_unsigned: - *( va_arg( status->arg, uintmax_t * ) ) = ( uintmax_t )( value * sign ); - break; - - case E_size: - /* E_size always implies unsigned */ - *( va_arg( status->arg, size_t * ) ) = ( size_t )( value * sign ); - break; - - case E_ptrdiff: - /* E_ptrdiff always implies signed */ - *( va_arg( status->arg, ptrdiff_t * ) ) = ( ptrdiff_t )( value * sign ); - break; - - case E_pointer: - /* E_pointer always implies unsigned */ - *( uintptr_t * )( va_arg( status->arg, void * ) ) = ( uintptr_t )( value * sign ); - break; - - default: - fputs( "UNSUPPORTED SCANF FLAG COMBINATIONi\n", stdout ); - return NULL; /* behaviour unspecified */ - } - - ++( status->n ); - } - - return ++spec; - } - - /* TODO: Floats. */ - return NULL; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "_PDCLIB/scan.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -#ifndef REGTEST - -static int testscanf( const char * s, const char * format, ... ) -{ - struct _PDCLIB_status_t status; - char const * rc; - - status.n = 0; - status.i = 0; - status.s = ( char * )s; - status.stream = NULL; - va_start( status.arg, format ); - - rc = _PDCLIB_scan( format, &status ); - - if ( rc != NULL && rc[0] != '\0' ) - { - printf( "_PDCLIB_scan() did not return end-of-specifier on '%s'.\n", format ); - ++TEST_RESULTS; - } - - if ( rc == NULL && s[0] != '\0' ) - { - printf( "_PDCLIB_scan() returned NULL on '%s' input.", s ); - ++TEST_RESULTS; - } - - va_end( status.arg ); - return status.n; -} - -#endif - -#define TEST_CONVERSION_ONLY - -int main( void ) -{ -#ifndef REGTEST - char source[100]; -#include "scanf_testcases.h" -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_seed.c b/rocklibc/src/_PDCLIB/_PDCLIB_seed.c deleted file mode 100644 index ce7c31c..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_seed.c +++ /dev/null @@ -1,19 +0,0 @@ -/* _PDCLIB_seed - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -unsigned long int _PDCLIB_seed = 1; - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* no tests for raw data */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_seek.c b/rocklibc/src/_PDCLIB/_PDCLIB_seek.c deleted file mode 100644 index dea648c..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_seek.c +++ /dev/null @@ -1,81 +0,0 @@ -/* int_least64_t _PDCLIB_seek( FILE *, int_least64_t, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of _PDCLIB_seek() fit for use with POSIX - kernels. - */ - -#ifndef REGTEST - -#include -#include - -#include "pdclib/_PDCLIB_glue.h" - -#include "pdclib/_PDCLIB_platform_errno.h" - -#ifdef __cplusplus -extern "C" { -#endif - -extern int64_t lseek64( int fd, _PDCLIB_int_least64_t offset, int whence ); -extern long lseek( int fd, long offset, int whence ); - -#ifdef __cplusplus -} -#endif - -_PDCLIB_int_least64_t _PDCLIB_seek( struct _PDCLIB_file_t * stream, _PDCLIB_int_least64_t offset, int whence ) -{ - _PDCLIB_int_least64_t rc; - - switch ( whence ) - { - case SEEK_SET: - case SEEK_CUR: - case SEEK_END: - /* EMPTY - OK */ - break; - - default: - *_PDCLIB_errno_func() = _PDCLIB_EINVAL; - return EOF; - break; - } - -#ifdef __CYGWIN__ - rc = lseek( stream->handle, offset, whence ); -#else - rc = lseek64( stream->handle, offset, whence ); -#endif - - if ( rc != EOF ) - { - stream->ungetidx = 0; - stream->bufidx = 0; - stream->bufend = 0; - stream->pos.offset = rc; - return rc; - } - - /* The 1:1 mapping in _PDCLIB_config.h ensures that this works. */ - *_PDCLIB_errno_func() = errno; - return EOF; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_stdinit.c b/rocklibc/src/_PDCLIB/_PDCLIB_stdinit.c deleted file mode 100644 index 10d8a8b..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_stdinit.c +++ /dev/null @@ -1,598 +0,0 @@ -/* _PDCLIB_stdinit - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example initialization of stdin, stdout and stderr to the integer - file descriptors 0, 1, and 2, respectively. This applies for a great variety - of operating systems, including POSIX compliant ones. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* In a POSIX system, stdin / stdout / stderr are equivalent to the (int) file - descriptors 0, 1, and 2 respectively. -*/ -/* TODO: This is proof-of-concept, requires finetuning. */ -static char _PDCLIB_sin_buffer[BUFSIZ]; -static char _PDCLIB_sout_buffer[BUFSIZ]; -static char _PDCLIB_serr_buffer[BUFSIZ]; - -static struct _PDCLIB_file_t _PDCLIB_serr = { 2, _PDCLIB_serr_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, { 0 }, _IONBF | _PDCLIB_FWRITE, -#ifndef __STDC_NO_THREADS__ - _PDCLIB_MTX_RECURSIVE_INIT, -#endif - NULL, NULL -}; -static struct _PDCLIB_file_t _PDCLIB_sout = { 1, _PDCLIB_sout_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, { 0 }, _IOLBF | _PDCLIB_FWRITE, -#ifndef __STDC_NO_THREADS__ - _PDCLIB_MTX_RECURSIVE_INIT, -#endif - NULL, &_PDCLIB_serr -}; -static struct _PDCLIB_file_t _PDCLIB_sin = { 0, _PDCLIB_sin_buffer, BUFSIZ, 0, 0, { 0, 0 }, 0, { 0 }, _IOLBF | _PDCLIB_FREAD, -#ifndef __STDC_NO_THREADS__ - _PDCLIB_MTX_RECURSIVE_INIT, -#endif - NULL, &_PDCLIB_sout -}; - -struct _PDCLIB_file_t * stdin = &_PDCLIB_sin; -struct _PDCLIB_file_t * stdout = &_PDCLIB_sout; -struct _PDCLIB_file_t * stderr = &_PDCLIB_serr; - -/* FIXME: This approach is a possible attack vector. */ -struct _PDCLIB_file_t * _PDCLIB_filelist = &_PDCLIB_sin; - -#ifndef __STDC_NO_THREADS__ -_PDCLIB_mtx_t _PDCLIB_filelist_mtx = _PDCLIB_MTX_PLAIN_INIT; -_PDCLIB_mtx_t _PDCLIB_time_mtx = _PDCLIB_MTX_PLAIN_INIT; -#endif - -/* "C" locale - defaulting to ASCII-7. - 1 kByte (+ 4 byte) of data. - Each line: flags, lowercase, uppercase. -*/ -static struct _PDCLIB_lc_ctype_entry_t _ctype_entries_C[ _PDCLIB_CHARSET_SIZE + 1 ] = -{ - { /* EOF */ 0, 0, 0 }, - { /* NUL */ _PDCLIB_CTYPE_CNTRL, 0x00, 0x00 }, - { /* SOH */ _PDCLIB_CTYPE_CNTRL, 0x01, 0x01 }, - { /* STX */ _PDCLIB_CTYPE_CNTRL, 0x02, 0x02 }, - { /* ETX */ _PDCLIB_CTYPE_CNTRL, 0x03, 0x03 }, - { /* EOT */ _PDCLIB_CTYPE_CNTRL, 0x04, 0x04 }, - { /* ENQ */ _PDCLIB_CTYPE_CNTRL, 0x05, 0x05 }, - { /* ACK */ _PDCLIB_CTYPE_CNTRL, 0x06, 0x06 }, - { /* BEL */ _PDCLIB_CTYPE_CNTRL, 0x07, 0x07 }, - { /* BS */ _PDCLIB_CTYPE_CNTRL, 0x08, 0x08 }, - { /* HT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x09, 0x09 }, - { /* LF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0A, 0x0A }, - { /* VT */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0B, 0x0B }, - { /* FF */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0C, 0x0C }, - { /* CR */ _PDCLIB_CTYPE_CNTRL | _PDCLIB_CTYPE_SPACE, 0x0D, 0x0D }, - { /* SO */ _PDCLIB_CTYPE_CNTRL, 0x0E, 0x0E }, - { /* SI */ _PDCLIB_CTYPE_CNTRL, 0x0F, 0x0F }, - { /* DLE */ _PDCLIB_CTYPE_CNTRL, 0x10, 0x10 }, - { /* DC1 */ _PDCLIB_CTYPE_CNTRL, 0x11, 0x11 }, - { /* DC2 */ _PDCLIB_CTYPE_CNTRL, 0x12, 0x12 }, - { /* DC3 */ _PDCLIB_CTYPE_CNTRL, 0x13, 0x13 }, - { /* DC4 */ _PDCLIB_CTYPE_CNTRL, 0x14, 0x14 }, - { /* NAK */ _PDCLIB_CTYPE_CNTRL, 0x15, 0x15 }, - { /* SYN */ _PDCLIB_CTYPE_CNTRL, 0x16, 0x16 }, - { /* ETB */ _PDCLIB_CTYPE_CNTRL, 0x17, 0x17 }, - { /* CAN */ _PDCLIB_CTYPE_CNTRL, 0x18, 0x18 }, - { /* EM */ _PDCLIB_CTYPE_CNTRL, 0x19, 0x19 }, - { /* SUB */ _PDCLIB_CTYPE_CNTRL, 0x1A, 0x1A }, - { /* ESC */ _PDCLIB_CTYPE_CNTRL, 0x1B, 0x1B }, - { /* FS */ _PDCLIB_CTYPE_CNTRL, 0x1C, 0x1C }, - { /* GS */ _PDCLIB_CTYPE_CNTRL, 0x1D, 0x1D }, - { /* RS */ _PDCLIB_CTYPE_CNTRL, 0x1E, 0x1E }, - { /* US */ _PDCLIB_CTYPE_CNTRL, 0x1F, 0x1F }, - { /* SP */ _PDCLIB_CTYPE_BLANK | _PDCLIB_CTYPE_SPACE, 0x20, 0x20 }, - { /* '!' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x21, 0x21 }, - { /* '"' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x22, 0x22 }, - { /* '#' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x23, 0x23 }, - { /* '$' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x24, 0x24 }, - { /* '%' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x25, 0x25 }, - { /* '&' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x26, 0x26 }, - { /* ''' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x27, 0x27 }, - { /* '(' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x28, 0x28 }, - { /* ')' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x29, 0x29 }, - { /* '*' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2A, 0x2A }, - { /* '+' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2B, 0x2B }, - { /* ',' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2C, 0x2C }, - { /* '-' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2D, 0x2D }, - { /* '.' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2E, 0x2E }, - { /* '/' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x2F, 0x2F }, - { /* '0' */ _PDCLIB_CTYPE_GRAPH, 0x30, 0x30 }, - { /* '1' */ _PDCLIB_CTYPE_GRAPH, 0x31, 0x31 }, - { /* '2' */ _PDCLIB_CTYPE_GRAPH, 0x32, 0x32 }, - { /* '3' */ _PDCLIB_CTYPE_GRAPH, 0x33, 0x33 }, - { /* '4' */ _PDCLIB_CTYPE_GRAPH, 0x34, 0x34 }, - { /* '5' */ _PDCLIB_CTYPE_GRAPH, 0x35, 0x35 }, - { /* '6' */ _PDCLIB_CTYPE_GRAPH, 0x36, 0x36 }, - { /* '7' */ _PDCLIB_CTYPE_GRAPH, 0x37, 0x37 }, - { /* '8' */ _PDCLIB_CTYPE_GRAPH, 0x38, 0x38 }, - { /* '9' */ _PDCLIB_CTYPE_GRAPH, 0x39, 0x39 }, - { /* ':' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3A, 0x3A }, - { /* ';' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3B, 0x3B }, - { /* '<' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3C, 0x3C }, - { /* '=' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3D, 0x3D }, - { /* '>' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3E, 0x3E }, - { /* '?' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x3F, 0x3F }, - { /* '@' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x40, 0x40 }, - { /* 'A' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x41, 0x61 }, - { /* 'B' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x42, 0x62 }, - { /* 'C' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x43, 0x63 }, - { /* 'D' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x44, 0x64 }, - { /* 'E' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x45, 0x65 }, - { /* 'F' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x46, 0x66 }, - { /* 'G' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x47, 0x67 }, - { /* 'H' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x48, 0x68 }, - { /* 'I' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x49, 0x69 }, - { /* 'J' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4A, 0x6A }, - { /* 'K' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4B, 0x6B }, - { /* 'L' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4C, 0x6C }, - { /* 'M' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4D, 0x6D }, - { /* 'N' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4E, 0x6E }, - { /* 'O' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x4F, 0x6F }, - { /* 'P' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x50, 0x70 }, - { /* 'Q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x51, 0x71 }, - { /* 'R' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x52, 0x72 }, - { /* 'S' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x53, 0x73 }, - { /* 'T' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x54, 0x74 }, - { /* 'U' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x55, 0x75 }, - { /* 'V' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x56, 0x76 }, - { /* 'W' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x57, 0x77 }, - { /* 'X' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x58, 0x78 }, - { /* 'Y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x59, 0x79 }, - { /* 'Z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_UPPER, 0x5A, 0x7A }, - { /* '[' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5B, 0x5B }, - { /* '\' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5C, 0x5C }, - { /* ']' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5D, 0x5D }, - { /* '^' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5E, 0x5E }, - { /* '_' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x5F, 0x5F }, - { /* '`' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x60, 0x60 }, - { /* 'a' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x41, 0x61 }, - { /* 'b' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x42, 0x62 }, - { /* 'c' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x43, 0x63 }, - { /* 'd' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x44, 0x64 }, - { /* 'e' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x45, 0x65 }, - { /* 'f' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x46, 0x66 }, - { /* 'g' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x47, 0x67 }, - { /* 'h' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x48, 0x68 }, - { /* 'i' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x49, 0x69 }, - { /* 'j' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4A, 0x6A }, - { /* 'k' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4B, 0x6B }, - { /* 'l' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4C, 0x6C }, - { /* 'm' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4D, 0x6D }, - { /* 'n' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4E, 0x6E }, - { /* 'o' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x4F, 0x6F }, - { /* 'p' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x50, 0x70 }, - { /* 'q' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x51, 0x71 }, - { /* 'r' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x52, 0x72 }, - { /* 's' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x53, 0x73 }, - { /* 't' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x54, 0x74 }, - { /* 'u' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x55, 0x75 }, - { /* 'v' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x56, 0x76 }, - { /* 'w' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x57, 0x77 }, - { /* 'x' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x58, 0x78 }, - { /* 'y' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x59, 0x79 }, - { /* 'z' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_ALPHA | _PDCLIB_CTYPE_LOWER, 0x5A, 0x7A }, - { /* '{' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7B, 0x7B }, - { /* '|' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7C, 0x7C }, - { /* '}' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7D, 0x7D }, - { /* '~' */ _PDCLIB_CTYPE_GRAPH | _PDCLIB_CTYPE_PUNCT, 0x7E, 0x7E }, - { /* DEL */ _PDCLIB_CTYPE_CNTRL, 0x7F, 0x7F }, - { 0x00, 0x80, 0x80 }, - { 0x00, 0x81, 0x81 }, - { 0x00, 0x82, 0x82 }, - { 0x00, 0x83, 0x83 }, - { 0x00, 0x84, 0x84 }, - { 0x00, 0x85, 0x85 }, - { 0x00, 0x86, 0x86 }, - { 0x00, 0x87, 0x87 }, - { 0x00, 0x88, 0x88 }, - { 0x00, 0x89, 0x89 }, - { 0x00, 0x8A, 0x8A }, - { 0x00, 0x8B, 0x8B }, - { 0x00, 0x8C, 0x8C }, - { 0x00, 0x8D, 0x8D }, - { 0x00, 0x8E, 0x8E }, - { 0x00, 0x8F, 0x8F }, - { 0x00, 0x90, 0x90 }, - { 0x00, 0x91, 0x91 }, - { 0x00, 0x92, 0x92 }, - { 0x00, 0x93, 0x93 }, - { 0x00, 0x94, 0x94 }, - { 0x00, 0x95, 0x95 }, - { 0x00, 0x96, 0x96 }, - { 0x00, 0x97, 0x97 }, - { 0x00, 0x98, 0x98 }, - { 0x00, 0x99, 0x99 }, - { 0x00, 0x9A, 0x9A }, - { 0x00, 0x9B, 0x9B }, - { 0x00, 0x9C, 0x9C }, - { 0x00, 0x9D, 0x9D }, - { 0x00, 0x9E, 0x9E }, - { 0x00, 0x9F, 0x9F }, - { 0x00, 0xA0, 0xA0 }, - { 0x00, 0xA1, 0xA1 }, - { 0x00, 0xA2, 0xA2 }, - { 0x00, 0xA3, 0xA3 }, - { 0x00, 0xA4, 0xA4 }, - { 0x00, 0xA5, 0xA5 }, - { 0x00, 0xA6, 0xA6 }, - { 0x00, 0xA7, 0xA7 }, - { 0x00, 0xA8, 0xA8 }, - { 0x00, 0xA9, 0xA9 }, - { 0x00, 0xAA, 0xAA }, - { 0x00, 0xAB, 0xAB }, - { 0x00, 0xAC, 0xAC }, - { 0x00, 0xAD, 0xAD }, - { 0x00, 0xAE, 0xAE }, - { 0x00, 0xAF, 0xAF }, - { 0x00, 0xB0, 0xB0 }, - { 0x00, 0xB1, 0xB1 }, - { 0x00, 0xB2, 0xB2 }, - { 0x00, 0xB3, 0xB3 }, - { 0x00, 0xB4, 0xB4 }, - { 0x00, 0xB5, 0xB5 }, - { 0x00, 0xB6, 0xB6 }, - { 0x00, 0xB7, 0xB7 }, - { 0x00, 0xB8, 0xB8 }, - { 0x00, 0xB9, 0xB9 }, - { 0x00, 0xBA, 0xBA }, - { 0x00, 0xBB, 0xBB }, - { 0x00, 0xBC, 0xBC }, - { 0x00, 0xBD, 0xBD }, - { 0x00, 0xBE, 0xBE }, - { 0x00, 0xBF, 0xBF }, - { 0x00, 0xC0, 0xC0 }, - { 0x00, 0xC1, 0xC1 }, - { 0x00, 0xC2, 0xC2 }, - { 0x00, 0xC3, 0xC3 }, - { 0x00, 0xC4, 0xC4 }, - { 0x00, 0xC5, 0xC5 }, - { 0x00, 0xC6, 0xC6 }, - { 0x00, 0xC7, 0xC7 }, - { 0x00, 0xC8, 0xC8 }, - { 0x00, 0xC9, 0xC9 }, - { 0x00, 0xCA, 0xCA }, - { 0x00, 0xCB, 0xCB }, - { 0x00, 0xCC, 0xCC }, - { 0x00, 0xCD, 0xCD }, - { 0x00, 0xCE, 0xCE }, - { 0x00, 0xCF, 0xCF }, - { 0x00, 0xD0, 0xD0 }, - { 0x00, 0xD1, 0xD1 }, - { 0x00, 0xD2, 0xD2 }, - { 0x00, 0xD3, 0xD3 }, - { 0x00, 0xD4, 0xD4 }, - { 0x00, 0xD5, 0xD5 }, - { 0x00, 0xD6, 0xD6 }, - { 0x00, 0xD7, 0xD7 }, - { 0x00, 0xD8, 0xD8 }, - { 0x00, 0xD9, 0xD9 }, - { 0x00, 0xDA, 0xDA }, - { 0x00, 0xDB, 0xDB }, - { 0x00, 0xDC, 0xDC }, - { 0x00, 0xDD, 0xDD }, - { 0x00, 0xDE, 0xDE }, - { 0x00, 0xDF, 0xDF }, - { 0x00, 0xE0, 0xE0 }, - { 0x00, 0xE1, 0xE1 }, - { 0x00, 0xE2, 0xE2 }, - { 0x00, 0xE3, 0xE3 }, - { 0x00, 0xE4, 0xE4 }, - { 0x00, 0xE5, 0xE5 }, - { 0x00, 0xE6, 0xE6 }, - { 0x00, 0xE7, 0xE7 }, - { 0x00, 0xE8, 0xE8 }, - { 0x00, 0xE9, 0xE9 }, - { 0x00, 0xEA, 0xEA }, - { 0x00, 0xEB, 0xEB }, - { 0x00, 0xEC, 0xEC }, - { 0x00, 0xED, 0xED }, - { 0x00, 0xEE, 0xEE }, - { 0x00, 0xEF, 0xEF }, - { 0x00, 0xF0, 0xF0 }, - { 0x00, 0xF1, 0xF1 }, - { 0x00, 0xF2, 0xF2 }, - { 0x00, 0xF3, 0xF3 }, - { 0x00, 0xF4, 0xF4 }, - { 0x00, 0xF5, 0xF5 }, - { 0x00, 0xF6, 0xF6 }, - { 0x00, 0xF7, 0xF7 }, - { 0x00, 0xF8, 0xF8 }, - { 0x00, 0xF9, 0xF9 }, - { 0x00, 0xFA, 0xFA }, - { 0x00, 0xFB, 0xFB }, - { 0x00, 0xFC, 0xFC }, - { 0x00, 0xFD, 0xFD }, - { 0x00, 0xFE, 0xFE }, - { 0x00, 0xFF, 0xFF } -}; - -struct _PDCLIB_lc_ctype_t _PDCLIB_lc_ctype_C = { 0, 0x30, 0x39, 0x41, 0x46, 0x61, 0x66, &_ctype_entries_C[1] }; -struct _PDCLIB_lc_ctype_t * _PDCLIB_lc_ctype = &_PDCLIB_lc_ctype_C; - -struct _PDCLIB_lc_collate_t _PDCLIB_lc_collate_C = { 0 }; -struct _PDCLIB_lc_collate_t * _PDCLIB_lc_collate = &_PDCLIB_lc_collate_C; - -struct lconv _PDCLIB_lconv = -{ - /* decimal_point */ ( char * )".", - /* thousands_sep */ ( char * )"", - /* grouping */ ( char * )"", - /* mon_decimal_point */ ( char * )"", - /* mon_thousands_sep */ ( char * )"", - /* mon_grouping */ ( char * )"", - /* positive_sign */ ( char * )"", - /* negative_sign */ ( char * )"", - /* currency_symbol */ ( char * )"", - /* int_curr_symbol */ ( char * )"", - /* frac_digits */ CHAR_MAX, - /* p_cs_precedes */ CHAR_MAX, - /* n_cs_precedes */ CHAR_MAX, - /* p_sep_by_space */ CHAR_MAX, - /* n_sep_by_space */ CHAR_MAX, - /* p_sign_posn */ CHAR_MAX, - /* n_sign_posn */ CHAR_MAX, - /* int_frac_digits */ CHAR_MAX, - /* int_p_cs_precedes */ CHAR_MAX, - /* int_n_cs_precedes */ CHAR_MAX, - /* int_p_sep_by_space */ CHAR_MAX, - /* int_n_sep_by_space */ CHAR_MAX, - /* int_p_sign_posn */ CHAR_MAX, - /* int_n_sign_posn */ CHAR_MAX -}; - -struct _PDCLIB_lc_numeric_monetary_t _PDCLIB_lc_numeric_monetary = -{ - &_PDCLIB_lconv, - 0, /* numeric_allocated */ - 0 /* monetary_allocated */ -}; - -struct _PDCLIB_lc_messages_t _PDCLIB_lc_messages_C = -{ - 0, - /* _PDCLIB_errno_texts */ - { - /* unknown error */ ( char * )"unknown error", - /* EPERM */ ( char * )"EPERM (Operation not permitted)", - /* ENOENT */ ( char * )"ENOENT (No such file or directory)", - /* ESRCH */ ( char * )"ESRCH (No such process)", - /* EINTR */ ( char * )"EINTR (Interrupted function)", - /* EIO */ ( char * )"EIO (I/O error)", - /* ENXIO */ ( char * )"ENXIO (No such device or address)", - /* E2BIG */ ( char * )"E2BIG (Argument list too long)", - /* ENOEXEC */ ( char * )"ENOEXEC (Executable file format error)", - /* EBADF */ ( char * )"EBADF (Bad file descriptor)", - /* ECHILD */ ( char * )"ECHILD (No child processes)", - /* EAGAIN */ ( char * )"EAGAIN (Resource unavailable, try again)", - /* ENOMEM */ ( char * )"ENOMEM (Not enough space)", - /* EACCES */ ( char * )"EACCES (Permission denied)", - /* EFAULT */ ( char * )"EFAULT (Bad address)", - /* unknown error */ ( char * )"unknown error", - /* EBUSY */ ( char * )"EBUSY (Device or resource busy)", - /* EEXIST */ ( char * )"EEXIST (File exists)", - /* EXDEV */ ( char * )"EXDEV (Cross-device link)", - /* ENODEV */ ( char * )"ENODEV (No such device)", - /* ENOTDIR */ ( char * )"ENOTDIR (Not a directory)", - /* EISDIR */ ( char * )"EISDIR (Is a directory)", - /* EINVAL */ ( char * )"EINVAL (Invalid argument)", - /* ENFILE */ ( char * )"ENFILE (Too many files open in system)", - /* EMFILE */ ( char * )"EMFILE (File descriptor value too large)", - /* ENOTTY */ ( char * )"ENOTTY (Inappropriate I/O control operation)", - /* ETXTBSY */ ( char * )"ETXTBSY (Text file busy)", - /* EFBIG */ ( char * )"EFBIG (File too large)", - /* ENOSPC */ ( char * )"ENOSPC (No space left on device)", - /* ESPIPE */ ( char * )"ESPIPE (Invalid seek)", - /* EROFS */ ( char * )"EROFS (Read-only file system)", - /* EMLINK */ ( char * )"EMLINK (Too many links)", - /* EPIPE */ ( char * )"EPIPE (Broken pipe)", - /* EDOM */ ( char * )"EDOM (Mathematics argument out of domain of function)", - /* ERANGE */ ( char * )"ERANGE (Result too large)", - /* EDEADLK */ ( char * )"EDEADLK (Resource deadlock would occur)", - /* ENAMETOOLONG */ ( char * )"ENAMETOOLONG (Filename too long)", - /* ENOLCK */ ( char * )"ENOLCK (No locks available)", - /* ENOSYS */ ( char * )"ENOSYS (Function not supported)", - /* ENOTEMPTY */ ( char * )"ENOTEMPTY (Directory not empty)", - /* ELOOP */ ( char * )"ELOOP (Too many levels of symbolic links)", - /* unknown error */ ( char * )"unknown error", - /* ENOMSG */ ( char * )"ENOMSG (No message of the desired type)", - /* EIDRM */ ( char * )"EIDRM (Identifier removed)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* ENOSTR */ ( char * )"ENOSTR (Not a STREAM)", - /* ENODATA */ ( char * )"ENODATA (No message is available on the STREAM head read queue)", - /* ETIME */ ( char * )"ETIME (Stream ioctl() timeout)", - /* ENOSR */ ( char * )"ENOSR (No STREAM resources)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* ENOLINK */ ( char * )"ENOLINK (Link has been severed)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* EPROTO */ ( char * )"EPROTO (Protocol error)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* EBADMSG */ ( char * )"EBADMSG (Bad message)", - /* EOVERFLOW */ ( char * )"EOVERFLOW (Value too large to be stored in data type)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* EILSEQ */ ( char * )"EILSEQ (Illegal byte sequence)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* ENOTSOCK */ ( char * )"ENOTSOCK (Not a socket)", - /* EDESTADDRREQ */ ( char * )"EDESTADDRREQ (Destination address required)", - /* EMSGSIZE */ ( char * )"EMSGSIZE (Message too large)", - /* EPROTOTYPE */ ( char * )"EPROTOTYPE (Protocol wrong type for socket)", - /* ENOPROTOOPT */ ( char * )"ENOPROTOOPT (Protocol not available)", - /* EPROTONOSUPPORT */ ( char * )"EPROTONOSUPPORT (Protocol not supported)", - /* unknown error */ ( char * )"unknown error", - /* ENOTSUP */ ( char * )"ENOTSUP (Not supported)", - /* unknown error */ ( char * )"unknown error", - /* EAFNOSUPPORT */ ( char * )"EAFNOSUPPORT (Address family not supported)", - /* EADDRINUSE */ ( char * )"EADDRINUSE (Address in use)", - /* EADDRNOTAVAIL */ ( char * )"EADDRNOTAVAIL (Address not available)", - /* ENETDOWN */ ( char * )"ENETDOWN (Network is down)", - /* ENETUNREACH */ ( char * )"ENETUNREACH (Network unreachable)", - /* ENETRESET */ ( char * )"ENETRESET (Connection aborted by network)", - /* ECONNABORTED */ ( char * )"ECONNABORTED (Connection aborted)", - /* ECONNRESET */ ( char * )"ECONNRESET (Connection reset)", - /* ENOBUFS */ ( char * )"ENOBUFS (No buffer space available)", - /* EISCONN */ ( char * )"EISCONN (Socket is connected)", - /* ENOTCONN */ ( char * )"ENOTCONN (The socket is not connected)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* ETIMEDOUT */ ( char * )"ETIMEDOUT (Connection timed out)", - /* ECONNREFUSED */ ( char * )"ECONNREFUSED (Connection refused)", - /* unknown error */ ( char * )"unknown error", - /* EHOSTUNREACH */ ( char * )"EHOSTUNREACH (Host is unreachable)", - /* EALREADY */ ( char * )"EALREADY (Connection already in progress)", - /* EINPROGRESS */ ( char * )"EINPROGRESS (Operation in progress)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* ECANCELED */ ( char * )"ECANCELED (Operation canceled)", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* unknown error */ ( char * )"unknown error", - /* EOWNERDEAD */ ( char * )"EOWNERDEAD (Previous owner died)", - /* ENOTRECOVERABLE */ ( char * )"ENOTRECOVERABLE (State not recoverable)", - } -}; - -struct _PDCLIB_lc_messages_t * _PDCLIB_lc_messages = &_PDCLIB_lc_messages_C; - -struct _PDCLIB_lc_time_t _PDCLIB_lc_time_C = -{ - 0, - /* _PDCLIB_month_name_abbr */ - { - ( char * )"Jan", - ( char * )"Feb", - ( char * )"Mar", - ( char * )"Apr", - ( char * )"May", - ( char * )"Jun", - ( char * )"Jul", - ( char * )"Aug", - ( char * )"Sep", - ( char * )"Oct", - ( char * )"Nov", - ( char * )"Dec" - }, - /* _PDCLIB_month_name_full */ - { - ( char * )"January", - ( char * )"February", - ( char * )"March", - ( char * )"April", - ( char * )"May", - ( char * )"June", - ( char * )"July", - ( char * )"August", - ( char * )"September", - ( char * )"October", - ( char * )"November", - ( char * )"December" - }, - /* _PDCLIB_day_name_abbr */ - { - ( char * )"Sun", - ( char * )"Mon", - ( char * )"Tue", - ( char * )"Wed", - ( char * )"Thu", - ( char * )"Fri", - ( char * )"Sat" - }, - /* _PDCLIB_day_name_full */ - { - ( char * )"Sunday", - ( char * )"Monday", - ( char * )"Tuesday", - ( char * )"Wednesday", - ( char * )"Thursday", - ( char * )"Friday", - ( char * )"Saturday" - }, - /* date / time format */ ( char * )"%a %b %e %T %Y", - /* 12h time format */ ( char * )"%I:%M:%S %p", - /* date format */ ( char * )"%m/%d/%y", - /* time format */ ( char * )"%T", - /* AM / PM designation */ - { - ( char * )"AM", - ( char * )"PM" - } -}; - -struct _PDCLIB_lc_time_t * _PDCLIB_lc_time = &_PDCLIB_lc_time_C; - -struct state _PDCLIB_lclmem; -struct state _PDCLIB_gmtmem; - -/* Section 4.12.3 of X3.159-1989 requires that - Except for the strftime function, these functions [asctime, - ctime, gmtime, localtime] return values in one of two static - objects: a broken-down time structure and an array of char. - Thanks to Paul Eggert for noting this. -*/ -struct tm _PDCLIB_tm; - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by several other testdrivers using stdin / stdout / - stderr. - */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_strtod_prelim.c b/rocklibc/src/_PDCLIB/_PDCLIB_strtod_prelim.c deleted file mode 100644 index 0e5bc83..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_strtod_prelim.c +++ /dev/null @@ -1,135 +0,0 @@ -/* _PDCLIB_strtod_prelim( const char *, char *, int * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -int _PDCLIB_strtod_prelim( const char * p, char * sign, char ** endptr ) -{ - int base = 10; - - /* skipping leading whitespace */ - while ( isspace( (unsigned char)*p ) ) - { - ++p; - } - - /* determining / skipping sign */ - if ( *p != '+' && *p != '-' ) - { - *sign = '+'; - } - else - { - *sign = *( p++ ); - } - - /* determining base */ - if ( *p == '0' ) - { - ++p; - - if ( *p == 'x' || *p == 'X' ) - { - int period = 0; - base = 16; - ++p; - - if ( *p == '.' ) - { - ++p; - period = 1; - } - - /* catching a border case here: "0x" followed by a non-digit should - be parsed as the unprefixed zero. - We have to "rewind" the parsing. - */ - if ( memchr( _PDCLIB_digits, tolower( (unsigned char)*p ), base ) == NULL ) - { - p -= ( 2 + period ); - } - } - else - { - --p; - } - } - else - { - /* inf / nan(...) */ - /* Repurposing base: 0 for no match, -1 for inf, -2 for nan */ - if ( tolower( (unsigned char)p[0] ) == 'i' && tolower( (unsigned char)p[1] ) == 'n' && tolower( (unsigned char)p[2] ) == 'f' ) - { - p += 3; - base = -1; - } - else if ( tolower( (unsigned char)p[0] ) == 'n' && tolower( (unsigned char)p[1] ) == 'a' && tolower( (unsigned char)p[2] ) == 'n' ) - { - const char * n = p + 3; - p = n; - base = -2; - - if ( *n == '(' ) - { - while ( *++n && *n != ')' ); - - if ( *n == ')' ) - { - p = n + 1; - } - } - } - } - - *endptr = (char *)p; - return base; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - int base = 0; - char sign = '\0'; - char test1[] = " 123"; - char test2[] = "\t+0123"; - char test3[] = "\v-0x123"; - TESTCASE( _PDCLIB_strtox_prelim( test1, &sign, &base ) == &test1[2] ); - TESTCASE( sign == '+' ); - TESTCASE( base == 10 ); - base = 0; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test2, &sign, &base ) == &test2[2] ); - TESTCASE( sign == '+' ); - TESTCASE( base == 8 ); - base = 0; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[4] ); - TESTCASE( sign == '-' ); - TESTCASE( base == 16 ); - base = 10; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[2] ); - TESTCASE( sign == '-' ); - TESTCASE( base == 10 ); - base = 1; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); - base = 37; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_strtok.c b/rocklibc/src/_PDCLIB/_PDCLIB_strtok.c deleted file mode 100644 index e99e719..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_strtok.c +++ /dev/null @@ -1,186 +0,0 @@ -/* _PDCLIB_strtok( char *, rsize_t *, const char *, char ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -char * _PDCLIB_strtok( char * _PDCLIB_restrict s1, rsize_t * _PDCLIB_restrict s1max, const char * _PDCLIB_restrict s2, char ** _PDCLIB_restrict ptr ) -{ - const char * p = s2; - - if ( s1max == NULL || s2 == NULL || ptr == NULL || ( s1 == NULL && *ptr == NULL ) || *s1max > RSIZE_MAX ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - if ( s1 != NULL ) - { - /* new string */ - *ptr = s1; - } - else - { - /* old string continued */ - if ( *ptr == NULL ) - { - /* No old string, no new string, nothing to do */ - return NULL; - } - - s1 = *ptr; - } - - /* skip leading s2 characters */ - while ( *p && *s1 ) - { - if ( *s1 == *p ) - { - /* found separator; skip and start over */ - if ( *s1max == 0 ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - ++s1; - --( *s1max ); - p = s2; - continue; - } - - ++p; - } - - if ( ! *s1 ) - { - /* no more to parse */ - *ptr = s1; - return NULL; - } - - /* skipping non-s2 characters */ - *ptr = s1; - - while ( **ptr ) - { - p = s2; - - while ( *p ) - { - if ( **ptr == *p++ ) - { - /* found separator; overwrite with '\0', position *ptr, return */ - if ( *s1max == 0 ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - --( *s1max ); - *( ( *ptr )++ ) = '\0'; - return s1; - } - } - - if ( *s1max == 0 ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - --( *s1max ); - ++( *ptr ); - } - - /* parsed to end of string */ - return s1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#ifndef REGTEST - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#ifndef REGTEST - /* The original PDCLib strtok() test */ - char s[] = "_a_bc__d_"; - rsize_t max = strlen( s ); - char * p; - - TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[1] ); - TESTCASE( max == 6 ); - TESTCASE( s[1] == 'a' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] ); - TESTCASE( max == 3 ); - TESTCASE( s[3] == 'b' ); - TESTCASE( s[4] == 'c' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[7] ); - TESTCASE( max == 0 ); - TESTCASE( s[6] == '_' ); - TESTCASE( s[7] == 'd' ); - TESTCASE( s[8] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL ); - TESTCASE( max == 0 ); - strcpy( s, "ab_cd" ); - max = strlen( s ); - TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[0] ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[1] == 'b' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] ); - TESTCASE( s[3] == 'c' ); - TESTCASE( s[4] == 'd' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL ); - - /* Testing the constraint handling */ - strcpy( s, "ab.cd" ); - max = 2; - TESTCASE( set_constraint_handler_s( test_handler ) == abort_handler_s ); - TESTCASE( _PDCLIB_strtok( s, &max, ".", &p ) == NULL ); - TESTCASE( HANDLER_CALLS == 1 ); - - { - /* The strtok_s() example code from the standard */ - char str1[] = "?a???b,,,#c"; - char str2[] = "\t \t"; - rsize_t max1 = strlen( str1 ); - rsize_t max2 = strlen( str2 ); - char * ptr1; - char * ptr2; - - TESTCASE( _PDCLIB_strtok( str1, &max1, "?", &ptr1 ) == &str1[1] ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, ",", &ptr1 ) == &str1[3] ); - TESTCASE( _PDCLIB_strtok( str2, &max2, " \t", &ptr2 ) == NULL ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, "#,", &ptr1 ) == &str1[10] ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, "?", &ptr1 ) == NULL ); - } -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_strtox_main.c b/rocklibc/src/_PDCLIB/_PDCLIB_strtox_main.c deleted file mode 100644 index cf50e23..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_strtox_main.c +++ /dev/null @@ -1,99 +0,0 @@ -/* _PDCLIB_strtox_main( const char **, int, _PDCLIB_uintmax_t, _PDCLIB_uintmax_t, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include -#include - -#ifndef REGTEST - -_PDCLIB_uintmax_t _PDCLIB_strtox_main( const char ** p, unsigned int base, uintmax_t error, uintmax_t limit, char * sign ) -{ - _PDCLIB_uintmax_t rc = 0; - int digit = -1; - const char * x; - _PDCLIB_uintmax_t limval = limit / base; - int limdigit = limit % base; - - while ( ( x = (const char *)memchr( _PDCLIB_digits, tolower( (unsigned char)**p ), base ) ) != NULL ) - { - digit = x - _PDCLIB_digits; - - if ( ( rc < limval ) || ( ( rc == limval ) && ( digit <= limdigit ) ) ) - { - rc = rc * base + ( unsigned )digit; - ++( *p ); - } - else - { - errno = ERANGE; - - /* TODO: Only if endptr != NULL - but do we really want *another* parameter? */ - /* TODO: Earlier version was missing tolower() here but was not caught by tests */ - while ( memchr( _PDCLIB_digits, tolower( (unsigned char)**p ), base ) != NULL ) - { - ++( *p ); - } - - /* TODO: This is ugly, but keeps caller from negating the error value */ - *sign = '+'; - return error; - } - } - - if ( digit == -1 ) - { - *p = NULL; - return 0; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - const char * p; - char test[] = "123_"; - char fail[] = "xxx"; - char sign = '-'; - /* basic functionality */ - p = test; - errno = 0; - TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 123 ); - TESTCASE( errno == 0 ); - TESTCASE( p == &test[3] ); - /* proper functioning to smaller base */ - p = test; - TESTCASE( _PDCLIB_strtox_main( &p, 8u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 0123 ); - TESTCASE( errno == 0 ); - TESTCASE( p == &test[3] ); - /* overflowing subject sequence must still return proper endptr */ - p = test; - TESTCASE( _PDCLIB_strtox_main( &p, 4u, ( uintmax_t )999, ( uintmax_t )6, &sign ) == 999 ); - TESTCASE( errno == ERANGE ); - TESTCASE( p == &test[3] ); - TESTCASE( sign == '+' ); - /* testing conversion failure */ - errno = 0; - p = fail; - sign = '-'; - TESTCASE( _PDCLIB_strtox_main( &p, 10u, ( uintmax_t )999, ( uintmax_t )999, &sign ) == 0 ); - TESTCASE( p == NULL ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/_PDCLIB_strtox_prelim.c b/rocklibc/src/_PDCLIB/_PDCLIB_strtox_prelim.c deleted file mode 100644 index 1bbddc1..0000000 --- a/rocklibc/src/_PDCLIB/_PDCLIB_strtox_prelim.c +++ /dev/null @@ -1,113 +0,0 @@ -/* _PDCLIB_strtox_prelim( const char *, char *, int * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -const char * _PDCLIB_strtox_prelim( const char * p, char * sign, int * base ) -{ - /* skipping leading whitespace */ - while ( isspace( (unsigned char)*p ) ) - { - ++p; - } - - /* determining / skipping sign */ - if ( *p != '+' && *p != '-' ) - { - *sign = '+'; - } - else - { - *sign = *( p++ ); - } - - /* determining base */ - if ( *p == '0' ) - { - ++p; - - if ( ( *base == 0 || *base == 16 ) && ( *p == 'x' || *p == 'X' ) ) - { - *base = 16; - ++p; - - /* catching a border case here: "0x" followed by a non-digit should - be parsed as the unprefixed zero. - We have to "rewind" the parsing; having the base set to 16 if it - was zero previously does not hurt, as the result is zero anyway. - */ - if ( memchr( _PDCLIB_digits, tolower( (unsigned char)*p ), *base ) == NULL ) - { - p -= 2; - } - } - else if ( *base == 0 ) - { - *base = 8; - /* back up one digit, so that a plain zero is decoded correctly - (and endptr is set correctly as well). - (2019-01-15, Giovanni Mascellani) - */ - --p; - } - else - { - --p; - } - } - else if ( ! *base ) - { - *base = 10; - } - - return ( ( *base >= 2 ) && ( *base <= 36 ) ) ? p : NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - int base = 0; - char sign = '\0'; - char test1[] = " 123"; - char test2[] = "\t+0123"; - char test3[] = "\v-0x123"; - TESTCASE( _PDCLIB_strtox_prelim( test1, &sign, &base ) == &test1[2] ); - TESTCASE( sign == '+' ); - TESTCASE( base == 10 ); - base = 0; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test2, &sign, &base ) == &test2[2] ); - TESTCASE( sign == '+' ); - TESTCASE( base == 8 ); - base = 0; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[4] ); - TESTCASE( sign == '-' ); - TESTCASE( base == 16 ); - base = 10; - sign = '\0'; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == &test3[2] ); - TESTCASE( sign == '-' ); - TESTCASE( base == 10 ); - base = 1; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); - base = 37; - TESTCASE( _PDCLIB_strtox_prelim( test3, &sign, &base ) == NULL ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/assert.c b/rocklibc/src/_PDCLIB/assert.c deleted file mode 100644 index 4c08716..0000000 --- a/rocklibc/src/_PDCLIB/assert.c +++ /dev/null @@ -1,73 +0,0 @@ -/* _PDCLIB_assert( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -void _PDCLIB_assert99( const char * const message1, const char * const function, const char * const message2 ) -{ - fputs( message1, stderr ); - fputs( function, stderr ); - fputs( message2, stderr ); - abort(); -} - -void _PDCLIB_assert89( const char * const message ) -{ - fputs( message, stderr ); - abort(); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -static int EXPECTED_ABORT = 0; -static int UNEXPECTED_ABORT = 1; - -static void aborthandler( int sig ) -{ - TESTCASE( ! EXPECTED_ABORT ); - exit( ( signed int )TEST_RESULTS ); -} - -#ifdef NDEBUG -#error Compiling test drivers with NDEBUG set is a questionable choice... -#endif - -#define NDEBUG - -#include - -static int disabled_test( void ) -{ - int i = 0; - assert( i == 0 ); /* NDEBUG set, condition met */ - assert( i == 1 ); /* NDEBUG set, condition fails */ - return i; -} - -#undef NDEBUG - -#include - -int main( void ) -{ - TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR ); - TESTCASE( disabled_test() == 0 ); - assert( UNEXPECTED_ABORT ); /* NDEBUG not set, condition met */ - assert( EXPECTED_ABORT ); /* NDEBUG not set, condition fails - should abort */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/errno.c b/rocklibc/src/_PDCLIB/errno.c deleted file mode 100644 index f503b39..0000000 --- a/rocklibc/src/_PDCLIB/errno.c +++ /dev/null @@ -1,71 +0,0 @@ -/* _PDCLIB_errno - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#if __STDC_VERSION__ >= 201112L && ! defined( __STDC_NO_THREADS__ ) -_Thread_local int _PDCLIB_errno = 0; -#else -static int _PDCLIB_errno = 0; -#endif - -int * _PDCLIB_errno_func() -{ - return &_PDCLIB_errno; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -#if ! defined( REGTEST ) && __STDC_VERSION__ >= 201112L && ! defined( __STDC_NO_THREADS__ ) - -#include - -static int thread_func( void * arg ) -{ - TESTCASE( errno == 0 ); - *_PDCLIB_errno_func() = 1; - TESTCASE( errno == 1 ); - thrd_exit( 0 ); -} - -#endif - -int main( void ) -{ - errno = 0; - TESTCASE( errno == 0 ); - errno = EDOM; - TESTCASE( errno == EDOM ); - errno = ERANGE; - TESTCASE( errno == ERANGE ); - -#if ! defined( REGTEST ) && __STDC_VERSION__ >= 201112L && ! defined( __STDC_NO_THREADS__ ) - { - thrd_t t; - struct timespec spec = { 1, 0 }; - int rc; - - TESTCASE( thrd_create( &t, thread_func, NULL ) == thrd_success ); - - TESTCASE( thrd_sleep( &spec, NULL ) == 0 ); - TESTCASE( errno == ERANGE ); - TESTCASE( thrd_join( t, &rc ) == thrd_success ); - TESTCASE( rc == 0 ); - } -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_PDCLIB/stdarg.c b/rocklibc/src/_PDCLIB/stdarg.c deleted file mode 100644 index 0de8320..0000000 --- a/rocklibc/src/_PDCLIB/stdarg.c +++ /dev/null @@ -1,120 +0,0 @@ -/* stdarg - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifdef TEST - -#include "_PDCLIB_test.h" - -typedef int ( *intfunc_t )( void ); - -#define TAG_END 0 -#define TAG_INT 1 -#define TAG_LONG 2 -#define TAG_LLONG 3 -#define TAG_DBL 4 -#define TAG_LDBL 5 -#define TAG_INTPTR 6 -#define TAG_LDBLPTR 7 -#define TAG_FUNCPTR 8 - -static int dummy( void ) -{ - return INT_MAX; -} - -static int test( int s, ... ) -{ - va_list ap; - va_start( ap, s ); - - for ( ;; ) - { - switch ( s ) - { - case TAG_INT: - { - TESTCASE( va_arg( ap, int ) == INT_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_LONG: - { - TESTCASE( va_arg( ap, long ) == LONG_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_LLONG: - { - TESTCASE( va_arg( ap, long long ) == LLONG_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_DBL: - { - TESTCASE( va_arg( ap, double ) == DBL_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_LDBL: - { - TESTCASE( va_arg( ap, long double ) == LDBL_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_INTPTR: - { - TESTCASE( *( va_arg( ap, int * ) ) == INT_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_LDBLPTR: - { - TESTCASE( *( va_arg( ap, long double * ) ) == LDBL_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_FUNCPTR: - { - intfunc_t function; - TESTCASE( ( function = va_arg( ap, intfunc_t ) ) == dummy ); - TESTCASE( function() == INT_MAX ); - s = va_arg( ap, int ); - break; - } - - case TAG_END: - { - va_end( ap ); - return 0; - } - } - } -} - -int main( void ) -{ - int x = INT_MAX; - long double d = LDBL_MAX; - test( TAG_END ); - test( TAG_INT, INT_MAX, TAG_END ); - test( TAG_LONG, LONG_MAX, TAG_LLONG, LLONG_MAX, TAG_END ); - test( TAG_DBL, DBL_MAX, TAG_LDBL, LDBL_MAX, TAG_END ); - test( TAG_INTPTR, &x, TAG_LDBLPTR, &d, TAG_FUNCPTR, dummy, TAG_END ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_dlmalloc/malloc-2.8.6.patch b/rocklibc/src/_dlmalloc/malloc-2.8.6.patch deleted file mode 100644 index 834d81d..0000000 --- a/rocklibc/src/_dlmalloc/malloc-2.8.6.patch +++ /dev/null @@ -1,154 +0,0 @@ ---- malloc-2.8.6.c 2024-05-01 19:50:19.477383272 +0200 -+++ malloc.c 2024-05-02 21:47:51.377419724 +0200 -@@ -1,3 +1,63 @@ -+/* malloc( size_t ) -+ calloc( size_t, size_t ) -+ realloc( void *, size_t ) -+ aligned_alloc( size_t, size_t ) -+ free( void * ) -+ -+ This file is part of the Public Domain C Library (PDCLib). -+ Permission is granted to use, modify, and / or redistribute at will. -+ -+ It is a slightly modified copy of Doug Lea's malloc(), retrieved from -+ ftp://gee.cs.oswego.edu/pub/misc/malloc.c -+ at version 2.8.6, which is released under CC0 license just as PDCLib. -+*/ -+ -+/* Declared implicitly by dlmalloc. This declaration avoids the warning. */ -+#include -+void * sbrk( intptr_t ); -+ -+#ifndef REGTEST -+ -+#include "pdclib/_PDCLIB_config.h" -+#include "pdclib/_PDCLIB_defguard.h" -+ -+/* Have all functions herein use the dl* prefix */ -+#define USE_DL_PREFIX 1 -+ -+/* Thread safety */ -+#define USE_LOCKS 1 -+ -+/* Hide all functions herein as internal to the library */ -+#define DLMALLOC_EXPORT _PDCLIB_LOCAL -+ -+/* Unhide the standard functions. (Their declarations with the -+ DLMALLOC_EXPORT modifier below has been commented out; they -+ are declared _PDCLIB_PUBLIC in , marking them -+ exported from the library.) -+*/ -+#define dlmalloc malloc -+#define dlcalloc calloc -+#define dlrealloc realloc -+#define dlfree free -+#if __STDC_VERSION__ >= 201112L -+#define dlmemalign aligned_alloc -+#endif -+ -+#endif -+ -+#ifdef TEST -+ -+#include "_PDCLIB_test.h" -+ -+int main( void ) -+{ -+ TESTCASE( NO_TESTDRIVER ); -+ return TEST_RESULTS; -+} -+ -+#endif -+ -+/* ------------------------------------------------------------------- */ - /* - This is a version (aka dlmalloc) of malloc/free/realloc written by - Doug Lea and released to the public domain, as explained at -@@ -585,8 +645,15 @@ - #define MAX_SIZE_T (~(size_t)0) - - #ifndef USE_LOCKS /* ensure true if spin or recursive locks set */ --#define USE_LOCKS ((defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \ -- (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0)) -+/* defined() in the expansion of a macro is non-portable behavior -+ and runs afoul of -Wextra. -+*/ -+#if ((defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \ -+ (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0)) -+#define USE_LOCKS 1 -+#else -+#define USE_LOCKS 0 -+#endif - #endif /* USE_LOCKS */ - - #if USE_LOCKS /* Spin locks for gcc >= 4.1, older gcc on x86, MSC >= 1310 */ -@@ -851,7 +918,7 @@ - maximum supported value of n differs across systems, but is in all - cases less than the maximum representable value of a size_t. - */ --DLMALLOC_EXPORT void* dlmalloc(size_t); -+/*DLMALLOC_EXPORT void* dlmalloc(size_t);*/ - - /* - free(void* p) -@@ -860,14 +927,14 @@ - It has no effect if p is null. If p was not malloced or already - freed, free(p) will by default cause the current program to abort. - */ --DLMALLOC_EXPORT void dlfree(void*); -+/*DLMALLOC_EXPORT void dlfree(void*);*/ - - /* - calloc(size_t n_elements, size_t element_size); - Returns a pointer to n_elements * element_size bytes, with all locations - set to zero. - */ --DLMALLOC_EXPORT void* dlcalloc(size_t, size_t); -+/*DLMALLOC_EXPORT void* dlcalloc(size_t, size_t);*/ - - /* - realloc(void* p, size_t n) -@@ -891,7 +958,7 @@ - The old unix realloc convention of allowing the last-free'd chunk - to be used as an argument to realloc is not supported. - */ --DLMALLOC_EXPORT void* dlrealloc(void*, size_t); -+/*DLMALLOC_EXPORT void* dlrealloc(void*, size_t);*/ - - /* - realloc_in_place(void* p, size_t n) -@@ -996,7 +1063,7 @@ - guarantee that this number of bytes can actually be obtained from - the system. - */ --DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(); -+DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(void); - - /* - malloc_set_footprint_limit(); -@@ -1256,8 +1323,8 @@ - - p = malloc(n); - assert(malloc_usable_size(p) >= 256); --*/ - size_t dlmalloc_usable_size(void*); -+*/ - - #endif /* ONLY_MSPACES */ - -@@ -5376,6 +5443,7 @@ - return change_mparam(param_number, value); - } - -+/* - size_t dlmalloc_usable_size(void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); -@@ -5384,6 +5452,7 @@ - } - return 0; - } -+*/ - - #endif /* !ONLY_MSPACES */ - diff --git a/rocklibc/src/_dlmalloc/malloc.c b/rocklibc/src/_dlmalloc/malloc.c deleted file mode 100644 index ce47b08..0000000 --- a/rocklibc/src/_dlmalloc/malloc.c +++ /dev/null @@ -1,6348 +0,0 @@ -/* malloc( size_t ) - calloc( size_t, size_t ) - realloc( void *, size_t ) - aligned_alloc( size_t, size_t ) - free( void * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. - - It is a slightly modified copy of Doug Lea's malloc(), retrieved from - ftp://gee.cs.oswego.edu/pub/misc/malloc.c - at version 2.8.6, which is released under CC0 license just as PDCLib. -*/ - -/* Declared implicitly by dlmalloc. This declaration avoids the warning. */ -#include -void * sbrk( intptr_t ); - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_config.h" -#include "pdclib/_PDCLIB_defguard.h" - -/* Have all functions herein use the dl* prefix */ -#define USE_DL_PREFIX 1 - -/* Thread safety */ - -/* Hide all functions herein as internal to the library */ -#define DLMALLOC_EXPORT _PDCLIB_LOCAL - -/* Unhide the standard functions. (Their declarations with the - DLMALLOC_EXPORT modifier below has been commented out; they - are declared _PDCLIB_PUBLIC in , marking them - exported from the library.) -*/ -#define dlmalloc malloc -#define dlcalloc calloc -#define dlrealloc realloc -#define dlfree free -#if __STDC_VERSION__ >= 201112L -#define dlmemalign aligned_alloc -#endif - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif - -/* ------------------------------------------------------------------- */ -/* - This is a version (aka dlmalloc) of malloc/free/realloc written by - Doug Lea and released to the public domain, as explained at - http://creativecommons.org/publicdomain/zero/1.0/ Send questions, - comments, complaints, performance data, etc to dl@cs.oswego.edu - -* Version 2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea - Note: There may be an updated version of this malloc obtainable at - ftp://gee.cs.oswego.edu/pub/misc/malloc.c - Check before installing! - -* Quickstart - - This library is all in one file to simplify the most common usage: - ftp it, compile it (-O3), and link it into another program. All of - the compile-time options default to reasonable values for use on - most platforms. You might later want to step through various - compile-time and dynamic tuning options. - - For convenience, an include file for code using this malloc is at: - ftp://gee.cs.oswego.edu/pub/misc/malloc-2.8.6.h - You don't really need this .h file unless you call functions not - defined in your system include files. The .h file contains only the - excerpts from this file needed for using this malloc on ANSI C/C++ - systems, so long as you haven't changed compile-time options about - naming and tuning parameters. If you do, then you can create your - own malloc.h that does include all settings by cutting at the point - indicated below. Note that you may already by default be using a C - library containing a malloc that is based on some version of this - malloc (for example in linux). You might still want to use the one - in this file to customize settings or to avoid overheads associated - with library versions. - -* Vital statistics: - - Supported pointer/size_t representation: 4 or 8 bytes - size_t MUST be an unsigned type of the same width as - pointers. (If you are using an ancient system that declares - size_t as a signed type, or need it to be a different width - than pointers, you can use a previous release of this malloc - (e.g. 2.7.2) supporting these.) - - Alignment: 8 bytes (minimum) - This suffices for nearly all current machines and C compilers. - However, you can define MALLOC_ALIGNMENT to be wider than this - if necessary (up to 128bytes), at the expense of using more space. - - Minimum overhead per allocated chunk: 4 or 8 bytes (if 4byte sizes) - 8 or 16 bytes (if 8byte sizes) - Each malloced chunk has a hidden word of overhead holding size - and status information, and additional cross-check word - if FOOTERS is defined. - - Minimum allocated size: 4-byte ptrs: 16 bytes (including overhead) - 8-byte ptrs: 32 bytes (including overhead) - - Even a request for zero bytes (i.e., malloc(0)) returns a - pointer to something of the minimum allocatable size. - The maximum overhead wastage (i.e., number of extra bytes - allocated than were requested in malloc) is less than or equal - to the minimum size, except for requests >= mmap_threshold that - are serviced via mmap(), where the worst case wastage is about - 32 bytes plus the remainder from a system page (the minimal - mmap unit); typically 4096 or 8192 bytes. - - Security: static-safe; optionally more or less - The "security" of malloc refers to the ability of malicious - code to accentuate the effects of errors (for example, freeing - space that is not currently malloc'ed or overwriting past the - ends of chunks) in code that calls malloc. This malloc - guarantees not to modify any memory locations below the base of - heap, i.e., static variables, even in the presence of usage - errors. The routines additionally detect most improper frees - and reallocs. All this holds as long as the static bookkeeping - for malloc itself is not corrupted by some other means. This - is only one aspect of security -- these checks do not, and - cannot, detect all possible programming errors. - - If FOOTERS is defined nonzero, then each allocated chunk - carries an additional check word to verify that it was malloced - from its space. These check words are the same within each - execution of a program using malloc, but differ across - executions, so externally crafted fake chunks cannot be - freed. This improves security by rejecting frees/reallocs that - could corrupt heap memory, in addition to the checks preventing - writes to statics that are always on. This may further improve - security at the expense of time and space overhead. (Note that - FOOTERS may also be worth using with MSPACES.) - - By default detected errors cause the program to abort (calling - "abort()"). You can override this to instead proceed past - errors by defining PROCEED_ON_ERROR. In this case, a bad free - has no effect, and a malloc that encounters a bad address - caused by user overwrites will ignore the bad address by - dropping pointers and indices to all known memory. This may - be appropriate for programs that should continue if at all - possible in the face of programming errors, although they may - run out of memory because dropped memory is never reclaimed. - - If you don't like either of these options, you can define - CORRUPTION_ERROR_ACTION and USAGE_ERROR_ACTION to do anything - else. And if if you are sure that your program using malloc has - no errors or vulnerabilities, you can define INSECURE to 1, - which might (or might not) provide a small performance improvement. - - It is also possible to limit the maximum total allocatable - space, using malloc_set_footprint_limit. This is not - designed as a security feature in itself (calls to set limits - are not screened or privileged), but may be useful as one - aspect of a secure implementation. - - Thread-safety: NOT thread-safe unless USE_LOCKS defined non-zero - When USE_LOCKS is defined, each public call to malloc, free, - etc is surrounded with a lock. By default, this uses a plain - pthread mutex, win32 critical section, or a spin-lock if if - available for the platform and not disabled by setting - USE_SPIN_LOCKS=0. However, if USE_RECURSIVE_LOCKS is defined, - recursive versions are used instead (which are not required for - base functionality but may be needed in layered extensions). - Using a global lock is not especially fast, and can be a major - bottleneck. It is designed only to provide minimal protection - in concurrent environments, and to provide a basis for - extensions. If you are using malloc in a concurrent program, - consider instead using nedmalloc - (http://www.nedprod.com/programs/portable/nedmalloc/) or - ptmalloc (See http://www.malloc.de), which are derived from - versions of this malloc. - - System requirements: Any combination of MORECORE and/or MMAP/MUNMAP - This malloc can use unix sbrk or any emulation (invoked using - the CALL_MORECORE macro) and/or mmap/munmap or any emulation - (invoked using CALL_MMAP/CALL_MUNMAP) to get and release system - memory. On most unix systems, it tends to work best if both - MORECORE and MMAP are enabled. On Win32, it uses emulations - based on VirtualAlloc. It also uses common C library functions - like memset. - - Compliance: I believe it is compliant with the Single Unix Specification - (See http://www.unix.org). Also SVID/XPG, ANSI C, and probably - others as well. - -* Overview of algorithms - - This is not the fastest, most space-conserving, most portable, or - most tunable malloc ever written. However it is among the fastest - while also being among the most space-conserving, portable and - tunable. Consistent balance across these factors results in a good - general-purpose allocator for malloc-intensive programs. - - In most ways, this malloc is a best-fit allocator. Generally, it - chooses the best-fitting existing chunk for a request, with ties - broken in approximately least-recently-used order. (This strategy - normally maintains low fragmentation.) However, for requests less - than 256bytes, it deviates from best-fit when there is not an - exactly fitting available chunk by preferring to use space adjacent - to that used for the previous small request, as well as by breaking - ties in approximately most-recently-used order. (These enhance - locality of series of small allocations.) And for very large requests - (>= 256Kb by default), it relies on system memory mapping - facilities, if supported. (This helps avoid carrying around and - possibly fragmenting memory used only for large chunks.) - - All operations (except malloc_stats and mallinfo) have execution - times that are bounded by a constant factor of the number of bits in - a size_t, not counting any clearing in calloc or copying in realloc, - or actions surrounding MORECORE and MMAP that have times - proportional to the number of non-contiguous regions returned by - system allocation routines, which is often just 1. In real-time - applications, you can optionally suppress segment traversals using - NO_SEGMENT_TRAVERSAL, which assures bounded execution even when - system allocators return non-contiguous spaces, at the typical - expense of carrying around more memory and increased fragmentation. - - The implementation is not very modular and seriously overuses - macros. Perhaps someday all C compilers will do as good a job - inlining modular code as can now be done by brute-force expansion, - but now, enough of them seem not to. - - Some compilers issue a lot of warnings about code that is - dead/unreachable only on some platforms, and also about intentional - uses of negation on unsigned types. All known cases of each can be - ignored. - - For a longer but out of date high-level description, see - http://gee.cs.oswego.edu/dl/html/malloc.html - -* MSPACES - If MSPACES is defined, then in addition to malloc, free, etc., - this file also defines mspace_malloc, mspace_free, etc. These - are versions of malloc routines that take an "mspace" argument - obtained using create_mspace, to control all internal bookkeeping. - If ONLY_MSPACES is defined, only these versions are compiled. - So if you would like to use this allocator for only some allocations, - and your system malloc for others, you can compile with - ONLY_MSPACES and then do something like... - static mspace mymspace = create_mspace(0,0); // for example - #define mymalloc(bytes) mspace_malloc(mymspace, bytes) - - (Note: If you only need one instance of an mspace, you can instead - use "USE_DL_PREFIX" to relabel the global malloc.) - - You can similarly create thread-local allocators by storing - mspaces as thread-locals. For example: - static __thread mspace tlms = 0; - void* tlmalloc(size_t bytes) { - if (tlms == 0) tlms = create_mspace(0, 0); - return mspace_malloc(tlms, bytes); - } - void tlfree(void* mem) { mspace_free(tlms, mem); } - - Unless FOOTERS is defined, each mspace is completely independent. - You cannot allocate from one and free to another (although - conformance is only weakly checked, so usage errors are not always - caught). If FOOTERS is defined, then each chunk carries around a tag - indicating its originating mspace, and frees are directed to their - originating spaces. Normally, this requires use of locks. - - ------------------------- Compile-time options --------------------------- - -Be careful in setting #define values for numerical constants of type -size_t. On some systems, literal values are not automatically extended -to size_t precision unless they are explicitly casted. You can also -use the symbolic values MAX_SIZE_T, SIZE_T_ONE, etc below. - -WIN32 default: defined if _WIN32 defined - Defining WIN32 sets up defaults for MS environment and compilers. - Otherwise defaults are for unix. Beware that there seem to be some - cases where this malloc might not be a pure drop-in replacement for - Win32 malloc: Random-looking failures from Win32 GDI API's (eg; - SetDIBits()) may be due to bugs in some video driver implementations - when pixel buffers are malloc()ed, and the region spans more than - one VirtualAlloc()ed region. Because dlmalloc uses a small (64Kb) - default granularity, pixel buffers may straddle virtual allocation - regions more often than when using the Microsoft allocator. You can - avoid this by using VirtualAlloc() and VirtualFree() for all pixel - buffers rather than using malloc(). If this is not possible, - recompile this malloc with a larger DEFAULT_GRANULARITY. Note: - in cases where MSC and gcc (cygwin) are known to differ on WIN32, - conditions use _MSC_VER to distinguish them. - -DLMALLOC_EXPORT default: extern - Defines how public APIs are declared. If you want to export via a - Windows DLL, you might define this as - #define DLMALLOC_EXPORT extern __declspec(dllexport) - If you want a POSIX ELF shared object, you might use - #define DLMALLOC_EXPORT extern __attribute__((visibility("default"))) - -MALLOC_ALIGNMENT default: (size_t)(2 * sizeof(void *)) - Controls the minimum alignment for malloc'ed chunks. It must be a - power of two and at least 8, even on machines for which smaller - alignments would suffice. It may be defined as larger than this - though. Note however that code and data structures are optimized for - the case of 8-byte alignment. - -MSPACES default: 0 (false) - If true, compile in support for independent allocation spaces. - This is only supported if HAVE_MMAP is true. - -ONLY_MSPACES default: 0 (false) - If true, only compile in mspace versions, not regular versions. - -USE_LOCKS default: 0 (false) - Causes each call to each public routine to be surrounded with - pthread or WIN32 mutex lock/unlock. (If set true, this can be - overridden on a per-mspace basis for mspace versions.) If set to a - non-zero value other than 1, locks are used, but their - implementation is left out, so lock functions must be supplied manually, - as described below. - -USE_SPIN_LOCKS default: 1 iff USE_LOCKS and spin locks available - If true, uses custom spin locks for locking. This is currently - supported only gcc >= 4.1, older gccs on x86 platforms, and recent - MS compilers. Otherwise, posix locks or win32 critical sections are - used. - -USE_RECURSIVE_LOCKS default: not defined - If defined nonzero, uses recursive (aka reentrant) locks, otherwise - uses plain mutexes. This is not required for malloc proper, but may - be needed for layered allocators such as nedmalloc. - -LOCK_AT_FORK default: not defined - If defined nonzero, performs pthread_atfork upon initialization - to initialize child lock while holding parent lock. The implementation - assumes that pthread locks (not custom locks) are being used. In other - cases, you may need to customize the implementation. - -FOOTERS default: 0 - If true, provide extra checking and dispatching by placing - information in the footers of allocated chunks. This adds - space and time overhead. - -INSECURE default: 0 - If true, omit checks for usage errors and heap space overwrites. - -USE_DL_PREFIX default: NOT defined - Causes compiler to prefix all public routines with the string 'dl'. - This can be useful when you only want to use this malloc in one part - of a program, using your regular system malloc elsewhere. - -MALLOC_INSPECT_ALL default: NOT defined - If defined, compiles malloc_inspect_all and mspace_inspect_all, that - perform traversal of all heap space. Unless access to these - functions is otherwise restricted, you probably do not want to - include them in secure implementations. - -ABORT default: defined as abort() - Defines how to abort on failed checks. On most systems, a failed - check cannot die with an "assert" or even print an informative - message, because the underlying print routines in turn call malloc, - which will fail again. Generally, the best policy is to simply call - abort(). It's not very useful to do more than this because many - errors due to overwriting will show up as address faults (null, odd - addresses etc) rather than malloc-triggered checks, so will also - abort. Also, most compilers know that abort() does not return, so - can better optimize code conditionally calling it. - -PROCEED_ON_ERROR default: defined as 0 (false) - Controls whether detected bad addresses cause them to bypassed - rather than aborting. If set, detected bad arguments to free and - realloc are ignored. And all bookkeeping information is zeroed out - upon a detected overwrite of freed heap space, thus losing the - ability to ever return it from malloc again, but enabling the - application to proceed. If PROCEED_ON_ERROR is defined, the - static variable malloc_corruption_error_count is compiled in - and can be examined to see if errors have occurred. This option - generates slower code than the default abort policy. - -DEBUG default: NOT defined - The DEBUG setting is mainly intended for people trying to modify - this code or diagnose problems when porting to new platforms. - However, it may also be able to better isolate user errors than just - using runtime checks. The assertions in the check routines spell - out in more detail the assumptions and invariants underlying the - algorithms. The checking is fairly extensive, and will slow down - execution noticeably. Calling malloc_stats or mallinfo with DEBUG - set will attempt to check every non-mmapped allocated and free chunk - in the course of computing the summaries. - -ABORT_ON_ASSERT_FAILURE default: defined as 1 (true) - Debugging assertion failures can be nearly impossible if your - version of the assert macro causes malloc to be called, which will - lead to a cascade of further failures, blowing the runtime stack. - ABORT_ON_ASSERT_FAILURE cause assertions failures to call abort(), - which will usually make debugging easier. - -MALLOC_FAILURE_ACTION default: sets errno to ENOMEM, or no-op on win32 - The action to take before "return 0" when malloc fails to be able to - return memory because there is none available. - -HAVE_MORECORE default: 1 (true) unless win32 or ONLY_MSPACES - True if this system supports sbrk or an emulation of it. - -MORECORE default: sbrk - The name of the sbrk-style system routine to call to obtain more - memory. See below for guidance on writing custom MORECORE - functions. The type of the argument to sbrk/MORECORE varies across - systems. It cannot be size_t, because it supports negative - arguments, so it is normally the signed type of the same width as - size_t (sometimes declared as "intptr_t"). It doesn't much matter - though. Internally, we only call it with arguments less than half - the max value of a size_t, which should work across all reasonable - possibilities, although sometimes generating compiler warnings. - -MORECORE_CONTIGUOUS default: 1 (true) if HAVE_MORECORE - If true, take advantage of fact that consecutive calls to MORECORE - with positive arguments always return contiguous increasing - addresses. This is true of unix sbrk. It does not hurt too much to - set it true anyway, since malloc copes with non-contiguities. - Setting it false when definitely non-contiguous saves time - and possibly wasted space it would take to discover this though. - -MORECORE_CANNOT_TRIM default: NOT defined - True if MORECORE cannot release space back to the system when given - negative arguments. This is generally necessary only if you are - using a hand-crafted MORECORE function that cannot handle negative - arguments. - -NO_SEGMENT_TRAVERSAL default: 0 - If non-zero, suppresses traversals of memory segments - returned by either MORECORE or CALL_MMAP. This disables - merging of segments that are contiguous, and selectively - releasing them to the OS if unused, but bounds execution times. - -HAVE_MMAP default: 1 (true) - True if this system supports mmap or an emulation of it. If so, and - HAVE_MORECORE is not true, MMAP is used for all system - allocation. If set and HAVE_MORECORE is true as well, MMAP is - primarily used to directly allocate very large blocks. It is also - used as a backup strategy in cases where MORECORE fails to provide - space from system. Note: A single call to MUNMAP is assumed to be - able to unmap memory that may have be allocated using multiple calls - to MMAP, so long as they are adjacent. - -HAVE_MREMAP default: 1 on linux, else 0 - If true realloc() uses mremap() to re-allocate large blocks and - extend or shrink allocation spaces. - -MMAP_CLEARS default: 1 except on WINCE. - True if mmap clears memory so calloc doesn't need to. This is true - for standard unix mmap using /dev/zero and on WIN32 except for WINCE. - -USE_BUILTIN_FFS default: 0 (i.e., not used) - Causes malloc to use the builtin ffs() function to compute indices. - Some compilers may recognize and intrinsify ffs to be faster than the - supplied C version. Also, the case of x86 using gcc is special-cased - to an asm instruction, so is already as fast as it can be, and so - this setting has no effect. Similarly for Win32 under recent MS compilers. - (On most x86s, the asm version is only slightly faster than the C version.) - -malloc_getpagesize default: derive from system includes, or 4096. - The system page size. To the extent possible, this malloc manages - memory from the system in page-size units. This may be (and - usually is) a function rather than a constant. This is ignored - if WIN32, where page size is determined using getSystemInfo during - initialization. - -USE_DEV_RANDOM default: 0 (i.e., not used) - Causes malloc to use /dev/random to initialize secure magic seed for - stamping footers. Otherwise, the current time is used. - -NO_MALLINFO default: 0 - If defined, don't compile "mallinfo". This can be a simple way - of dealing with mismatches between system declarations and - those in this file. - -MALLINFO_FIELD_TYPE default: size_t - The type of the fields in the mallinfo struct. This was originally - defined as "int" in SVID etc, but is more usefully defined as - size_t. The value is used only if HAVE_USR_INCLUDE_MALLOC_H is not set - -NO_MALLOC_STATS default: 0 - If defined, don't compile "malloc_stats". This avoids calls to - fprintf and bringing in stdio dependencies you might not want. - -REALLOC_ZERO_BYTES_FREES default: not defined - This should be set if a call to realloc with zero bytes should - be the same as a call to free. Some people think it should. Otherwise, - since this malloc returns a unique pointer for malloc(0), so does - realloc(p, 0). - -LACKS_UNISTD_H, LACKS_FCNTL_H, LACKS_SYS_PARAM_H, LACKS_SYS_MMAN_H -LACKS_STRINGS_H, LACKS_STRING_H, LACKS_SYS_TYPES_H, LACKS_ERRNO_H -LACKS_STDLIB_H LACKS_SCHED_H LACKS_TIME_H default: NOT defined unless on WIN32 - Define these if your system does not have these header files. - You might need to manually insert some of the declarations they provide. - -DEFAULT_GRANULARITY default: page size if MORECORE_CONTIGUOUS, - system_info.dwAllocationGranularity in WIN32, - otherwise 64K. - Also settable using mallopt(M_GRANULARITY, x) - The unit for allocating and deallocating memory from the system. On - most systems with contiguous MORECORE, there is no reason to - make this more than a page. However, systems with MMAP tend to - either require or encourage larger granularities. You can increase - this value to prevent system allocation functions to be called so - often, especially if they are slow. The value must be at least one - page and must be a power of two. Setting to 0 causes initialization - to either page size or win32 region size. (Note: In previous - versions of malloc, the equivalent of this option was called - "TOP_PAD") - -DEFAULT_TRIM_THRESHOLD default: 2MB - Also settable using mallopt(M_TRIM_THRESHOLD, x) - The maximum amount of unused top-most memory to keep before - releasing via malloc_trim in free(). Automatic trimming is mainly - useful in long-lived programs using contiguous MORECORE. Because - trimming via sbrk can be slow on some systems, and can sometimes be - wasteful (in cases where programs immediately afterward allocate - more large chunks) the value should be high enough so that your - overall system performance would improve by releasing this much - memory. As a rough guide, you might set to a value close to the - average size of a process (program) running on your system. - Releasing this much memory would allow such a process to run in - memory. Generally, it is worth tuning trim thresholds when a - program undergoes phases where several large chunks are allocated - and released in ways that can reuse each other's storage, perhaps - mixed with phases where there are no such chunks at all. The trim - value must be greater than page size to have any useful effect. To - disable trimming completely, you can set to MAX_SIZE_T. Note that the trick - some people use of mallocing a huge space and then freeing it at - program startup, in an attempt to reserve system memory, doesn't - have the intended effect under automatic trimming, since that memory - will immediately be returned to the system. - -DEFAULT_MMAP_THRESHOLD default: 256K - Also settable using mallopt(M_MMAP_THRESHOLD, x) - The request size threshold for using MMAP to directly service a - request. Requests of at least this size that cannot be allocated - using already-existing space will be serviced via mmap. (If enough - normal freed space already exists it is used instead.) Using mmap - segregates relatively large chunks of memory so that they can be - individually obtained and released from the host system. A request - serviced through mmap is never reused by any other request (at least - not directly; the system may just so happen to remap successive - requests to the same locations). Segregating space in this way has - the benefits that: Mmapped space can always be individually released - back to the system, which helps keep the system level memory demands - of a long-lived program low. Also, mapped memory doesn't become - `locked' between other chunks, as can happen with normally allocated - chunks, which means that even trimming via malloc_trim would not - release them. However, it has the disadvantage that the space - cannot be reclaimed, consolidated, and then used to service later - requests, as happens with normal chunks. The advantages of mmap - nearly always outweigh disadvantages for "large" chunks, but the - value of "large" may vary across systems. The default is an - empirically derived value that works well in most systems. You can - disable mmap by setting to MAX_SIZE_T. - -MAX_RELEASE_CHECK_RATE default: 4095 unless not HAVE_MMAP - The number of consolidated frees between checks to release - unused segments when freeing. When using non-contiguous segments, - especially with multiple mspaces, checking only for topmost space - doesn't always suffice to trigger trimming. To compensate for this, - free() will, with a period of MAX_RELEASE_CHECK_RATE (or the - current number of segments, if greater) try to release unused - segments to the OS when freeing chunks that result in - consolidation. The best value for this parameter is a compromise - between slowing down frees with relatively costly checks that - rarely trigger versus holding on to unused memory. To effectively - disable, set to MAX_SIZE_T. This may lead to a very slight speed - improvement at the expense of carrying around more memory. -*/ - -/* Version identifier to allow people to support multiple versions */ -#ifndef DLMALLOC_VERSION -#define DLMALLOC_VERSION 20806 -#endif /* DLMALLOC_VERSION */ - -#ifndef DLMALLOC_EXPORT -#define DLMALLOC_EXPORT extern -#endif - -#ifndef WIN32 -#ifdef _WIN32 -#define WIN32 1 -#endif /* _WIN32 */ -#ifdef _WIN32_WCE -#define LACKS_FCNTL_H -#define WIN32 1 -#endif /* _WIN32_WCE */ -#endif /* WIN32 */ -#ifdef WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#include -#define HAVE_MMAP 1 -#define HAVE_MORECORE 0 -#define LACKS_UNISTD_H -#define LACKS_SYS_PARAM_H -#define LACKS_SYS_MMAN_H -#define LACKS_STRING_H -#define LACKS_STRINGS_H -#define LACKS_SYS_TYPES_H -#define LACKS_ERRNO_H -#define LACKS_SCHED_H -#ifndef MALLOC_FAILURE_ACTION -#define MALLOC_FAILURE_ACTION -#endif /* MALLOC_FAILURE_ACTION */ -#ifndef MMAP_CLEARS -#ifdef _WIN32_WCE /* WINCE reportedly does not clear */ -#define MMAP_CLEARS 0 -#else -#define MMAP_CLEARS 1 -#endif /* _WIN32_WCE */ -#endif /*MMAP_CLEARS */ -#endif /* WIN32 */ - -#if defined(DARWIN) || defined(_DARWIN) -/* Mac OSX docs advise not to use sbrk; it seems better to use mmap */ -#ifndef HAVE_MORECORE -#define HAVE_MORECORE 0 -#define HAVE_MMAP 1 -/* OSX allocators provide 16 byte alignment */ -#ifndef MALLOC_ALIGNMENT -#define MALLOC_ALIGNMENT ((size_t)16U) -#endif -#endif /* HAVE_MORECORE */ -#endif /* DARWIN */ - -#ifndef LACKS_SYS_TYPES_H -#include /* For size_t */ -#endif /* LACKS_SYS_TYPES_H */ - -/* The maximum possible size_t value has all bits set */ -#define MAX_SIZE_T (~(size_t)0) - -#ifndef USE_LOCKS /* ensure true if spin or recursive locks set */ -/* defined() in the expansion of a macro is non-portable behavior - and runs afoul of -Wextra. -*/ -#if ((defined(USE_SPIN_LOCKS) && USE_SPIN_LOCKS != 0) || \ - (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0)) -#define USE_LOCKS 1 -#else -#define USE_LOCKS 0 -#endif -#endif /* USE_LOCKS */ - -#if USE_LOCKS /* Spin locks for gcc >= 4.1, older gcc on x86, MSC >= 1310 */ -#if ((defined(__GNUC__) && \ - ((__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) || \ - defined(__i386__) || defined(__x86_64__))) || \ - (defined(_MSC_VER) && _MSC_VER>=1310)) -#ifndef USE_SPIN_LOCKS -#define USE_SPIN_LOCKS 1 -#endif /* USE_SPIN_LOCKS */ -#elif USE_SPIN_LOCKS -#error "USE_SPIN_LOCKS defined without implementation" -#endif /* ... locks available... */ -#elif !defined(USE_SPIN_LOCKS) -#define USE_SPIN_LOCKS 0 -#endif /* USE_LOCKS */ - -#ifndef ONLY_MSPACES -#define ONLY_MSPACES 0 -#endif /* ONLY_MSPACES */ -#ifndef MSPACES -#if ONLY_MSPACES -#define MSPACES 1 -#else /* ONLY_MSPACES */ -#define MSPACES 0 -#endif /* ONLY_MSPACES */ -#endif /* MSPACES */ -#ifndef MALLOC_ALIGNMENT -#define MALLOC_ALIGNMENT ((size_t)(2 * sizeof(void *))) -#endif /* MALLOC_ALIGNMENT */ -#ifndef FOOTERS -#define FOOTERS 0 -#endif /* FOOTERS */ -#ifndef ABORT -#define ABORT abort() -#endif /* ABORT */ -#ifndef ABORT_ON_ASSERT_FAILURE -#define ABORT_ON_ASSERT_FAILURE 1 -#endif /* ABORT_ON_ASSERT_FAILURE */ -#ifndef PROCEED_ON_ERROR -#define PROCEED_ON_ERROR 0 -#endif /* PROCEED_ON_ERROR */ - -#ifndef INSECURE -#define INSECURE 0 -#endif /* INSECURE */ -#ifndef MALLOC_INSPECT_ALL -#define MALLOC_INSPECT_ALL 0 -#endif /* MALLOC_INSPECT_ALL */ -#ifndef HAVE_MMAP -#define HAVE_MMAP 1 -#endif /* HAVE_MMAP */ -#ifndef MMAP_CLEARS -#define MMAP_CLEARS 1 -#endif /* MMAP_CLEARS */ -#ifndef HAVE_MREMAP -#ifdef linux -#define HAVE_MREMAP 1 -#define _GNU_SOURCE /* Turns on mremap() definition */ -#else /* linux */ -#define HAVE_MREMAP 0 -#endif /* linux */ -#endif /* HAVE_MREMAP */ -#ifndef MALLOC_FAILURE_ACTION -#define MALLOC_FAILURE_ACTION errno = ENOMEM; -#endif /* MALLOC_FAILURE_ACTION */ -#ifndef HAVE_MORECORE -#if ONLY_MSPACES -#define HAVE_MORECORE 0 -#else /* ONLY_MSPACES */ -#define HAVE_MORECORE 1 -#endif /* ONLY_MSPACES */ -#endif /* HAVE_MORECORE */ -#if !HAVE_MORECORE -#define MORECORE_CONTIGUOUS 0 -#else /* !HAVE_MORECORE */ -#define MORECORE_DEFAULT sbrk -#ifndef MORECORE_CONTIGUOUS -#define MORECORE_CONTIGUOUS 1 -#endif /* MORECORE_CONTIGUOUS */ -#endif /* HAVE_MORECORE */ -#ifndef DEFAULT_GRANULARITY -#if (MORECORE_CONTIGUOUS || defined(WIN32)) -#define DEFAULT_GRANULARITY (0) /* 0 means to compute in init_mparams */ -#else /* MORECORE_CONTIGUOUS */ -#define DEFAULT_GRANULARITY ((size_t)64U * (size_t)1024U) -#endif /* MORECORE_CONTIGUOUS */ -#endif /* DEFAULT_GRANULARITY */ -#ifndef DEFAULT_TRIM_THRESHOLD -#ifndef MORECORE_CANNOT_TRIM -#define DEFAULT_TRIM_THRESHOLD ((size_t)2U * (size_t)1024U * (size_t)1024U) -#else /* MORECORE_CANNOT_TRIM */ -#define DEFAULT_TRIM_THRESHOLD MAX_SIZE_T -#endif /* MORECORE_CANNOT_TRIM */ -#endif /* DEFAULT_TRIM_THRESHOLD */ -#ifndef DEFAULT_MMAP_THRESHOLD -#if HAVE_MMAP -#define DEFAULT_MMAP_THRESHOLD ((size_t)256U * (size_t)1024U) -#else /* HAVE_MMAP */ -#define DEFAULT_MMAP_THRESHOLD MAX_SIZE_T -#endif /* HAVE_MMAP */ -#endif /* DEFAULT_MMAP_THRESHOLD */ -#ifndef MAX_RELEASE_CHECK_RATE -#if HAVE_MMAP -#define MAX_RELEASE_CHECK_RATE 4095 -#else -#define MAX_RELEASE_CHECK_RATE MAX_SIZE_T -#endif /* HAVE_MMAP */ -#endif /* MAX_RELEASE_CHECK_RATE */ -#ifndef USE_BUILTIN_FFS -#define USE_BUILTIN_FFS 0 -#endif /* USE_BUILTIN_FFS */ -#ifndef USE_DEV_RANDOM -#define USE_DEV_RANDOM 0 -#endif /* USE_DEV_RANDOM */ -#ifndef NO_MALLINFO -#define NO_MALLINFO 0 -#endif /* NO_MALLINFO */ -#ifndef MALLINFO_FIELD_TYPE -#define MALLINFO_FIELD_TYPE size_t -#endif /* MALLINFO_FIELD_TYPE */ -#ifndef NO_MALLOC_STATS -#define NO_MALLOC_STATS 0 -#endif /* NO_MALLOC_STATS */ -#ifndef NO_SEGMENT_TRAVERSAL -#define NO_SEGMENT_TRAVERSAL 0 -#endif /* NO_SEGMENT_TRAVERSAL */ - -/* - mallopt tuning options. SVID/XPG defines four standard parameter - numbers for mallopt, normally defined in malloc.h. None of these - are used in this malloc, so setting them has no effect. But this - malloc does support the following options. -*/ - -#define M_TRIM_THRESHOLD (-1) -#define M_GRANULARITY (-2) -#define M_MMAP_THRESHOLD (-3) - -/* ------------------------ Mallinfo declarations ------------------------ */ - -#if !NO_MALLINFO -/* - This version of malloc supports the standard SVID/XPG mallinfo - routine that returns a struct containing usage properties and - statistics. It should work on any system that has a - /usr/include/malloc.h defining struct mallinfo. The main - declaration needed is the mallinfo struct that is returned (by-copy) - by mallinfo(). The malloinfo struct contains a bunch of fields that - are not even meaningful in this version of malloc. These fields are - are instead filled by mallinfo() with other numbers that might be of - interest. - - HAVE_USR_INCLUDE_MALLOC_H should be set if you have a - /usr/include/malloc.h file that includes a declaration of struct - mallinfo. If so, it is included; else a compliant version is - declared below. These must be precisely the same for mallinfo() to - work. The original SVID version of this struct, defined on most - systems with mallinfo, declares all fields as ints. But some others - define as unsigned long. If your system defines the fields using a - type of different width than listed here, you MUST #include your - system version and #define HAVE_USR_INCLUDE_MALLOC_H. -*/ - -/* #define HAVE_USR_INCLUDE_MALLOC_H */ - -#ifdef HAVE_USR_INCLUDE_MALLOC_H -#include "/usr/include/malloc.h" -#else /* HAVE_USR_INCLUDE_MALLOC_H */ -#ifndef STRUCT_MALLINFO_DECLARED -/* HP-UX (and others?) redefines mallinfo unless _STRUCT_MALLINFO is defined */ -#define _STRUCT_MALLINFO -#define STRUCT_MALLINFO_DECLARED 1 -struct mallinfo { - MALLINFO_FIELD_TYPE arena; /* non-mmapped space allocated from system */ - MALLINFO_FIELD_TYPE ordblks; /* number of free chunks */ - MALLINFO_FIELD_TYPE smblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblks; /* always 0 */ - MALLINFO_FIELD_TYPE hblkhd; /* space in mmapped regions */ - MALLINFO_FIELD_TYPE usmblks; /* maximum total allocated space */ - MALLINFO_FIELD_TYPE fsmblks; /* always 0 */ - MALLINFO_FIELD_TYPE uordblks; /* total allocated space */ - MALLINFO_FIELD_TYPE fordblks; /* total free space */ - MALLINFO_FIELD_TYPE keepcost; /* releasable (via malloc_trim) space */ -}; -#endif /* STRUCT_MALLINFO_DECLARED */ -#endif /* HAVE_USR_INCLUDE_MALLOC_H */ -#endif /* NO_MALLINFO */ - -/* - Try to persuade compilers to inline. The most critical functions for - inlining are defined as macros, so these aren't used for them. -*/ - -#ifndef FORCEINLINE - #if defined(__GNUC__) -#define FORCEINLINE __inline __attribute__ ((always_inline)) - #elif defined(_MSC_VER) - #define FORCEINLINE __forceinline - #endif -#endif -#ifndef NOINLINE - #if defined(__GNUC__) - #define NOINLINE __attribute__ ((noinline)) - #elif defined(_MSC_VER) - #define NOINLINE __declspec(noinline) - #else - #define NOINLINE - #endif -#endif - -#ifdef __cplusplus -extern "C" { -#ifndef FORCEINLINE - #define FORCEINLINE inline -#endif -#endif /* __cplusplus */ -#ifndef FORCEINLINE - #define FORCEINLINE -#endif - -#if !ONLY_MSPACES - -/* ------------------- Declarations of public routines ------------------- */ - -#ifndef USE_DL_PREFIX -#define dlcalloc calloc -#define dlfree free -#define dlmalloc malloc -#define dlmemalign memalign -#define dlposix_memalign posix_memalign -#define dlrealloc realloc -#define dlrealloc_in_place realloc_in_place -#define dlvalloc valloc -#define dlpvalloc pvalloc -#define dlmallinfo mallinfo -#define dlmallopt mallopt -#define dlmalloc_trim malloc_trim -#define dlmalloc_stats malloc_stats -#define dlmalloc_usable_size malloc_usable_size -#define dlmalloc_footprint malloc_footprint -#define dlmalloc_max_footprint malloc_max_footprint -#define dlmalloc_footprint_limit malloc_footprint_limit -#define dlmalloc_set_footprint_limit malloc_set_footprint_limit -#define dlmalloc_inspect_all malloc_inspect_all -#define dlindependent_calloc independent_calloc -#define dlindependent_comalloc independent_comalloc -#define dlbulk_free bulk_free -#endif /* USE_DL_PREFIX */ - -/* - malloc(size_t n) - Returns a pointer to a newly allocated chunk of at least n bytes, or - null if no space is available, in which case errno is set to ENOMEM - on ANSI C systems. - - If n is zero, malloc returns a minimum-sized chunk. (The minimum - size is 16 bytes on most 32bit systems, and 32 bytes on 64bit - systems.) Note that size_t is an unsigned type, so calls with - arguments that would be negative if signed are interpreted as - requests for huge amounts of space, which will often fail. The - maximum supported value of n differs across systems, but is in all - cases less than the maximum representable value of a size_t. -*/ -/*DLMALLOC_EXPORT void* dlmalloc(size_t);*/ - -/* - free(void* p) - Releases the chunk of memory pointed to by p, that had been previously - allocated using malloc or a related routine such as realloc. - It has no effect if p is null. If p was not malloced or already - freed, free(p) will by default cause the current program to abort. -*/ -/*DLMALLOC_EXPORT void dlfree(void*);*/ - -/* - calloc(size_t n_elements, size_t element_size); - Returns a pointer to n_elements * element_size bytes, with all locations - set to zero. -*/ -/*DLMALLOC_EXPORT void* dlcalloc(size_t, size_t);*/ - -/* - realloc(void* p, size_t n) - Returns a pointer to a chunk of size n that contains the same data - as does chunk p up to the minimum of (n, p's size) bytes, or null - if no space is available. - - The returned pointer may or may not be the same as p. The algorithm - prefers extending p in most cases when possible, otherwise it - employs the equivalent of a malloc-copy-free sequence. - - If p is null, realloc is equivalent to malloc. - - If space is not available, realloc returns null, errno is set (if on - ANSI) and p is NOT freed. - - if n is for fewer bytes than already held by p, the newly unused - space is lopped off and freed if possible. realloc with a size - argument of zero (re)allocates a minimum-sized chunk. - - The old unix realloc convention of allowing the last-free'd chunk - to be used as an argument to realloc is not supported. -*/ -/*DLMALLOC_EXPORT void* dlrealloc(void*, size_t);*/ - -/* - realloc_in_place(void* p, size_t n) - Resizes the space allocated for p to size n, only if this can be - done without moving p (i.e., only if there is adjacent space - available if n is greater than p's current allocated size, or n is - less than or equal to p's size). This may be used instead of plain - realloc if an alternative allocation strategy is needed upon failure - to expand space; for example, reallocation of a buffer that must be - memory-aligned or cleared. You can use realloc_in_place to trigger - these alternatives only when needed. - - Returns p if successful; otherwise null. -*/ -DLMALLOC_EXPORT void* dlrealloc_in_place(void*, size_t); - -/* - memalign(size_t alignment, size_t n); - Returns a pointer to a newly allocated chunk of n bytes, aligned - in accord with the alignment argument. - - The alignment argument should be a power of two. If the argument is - not a power of two, the nearest greater power is used. - 8-byte alignment is guaranteed by normal malloc calls, so don't - bother calling memalign with an argument of 8 or less. - - Overreliance on memalign is a sure way to fragment space. -*/ -DLMALLOC_EXPORT void* dlmemalign(size_t, size_t); - -/* - int posix_memalign(void** pp, size_t alignment, size_t n); - Allocates a chunk of n bytes, aligned in accord with the alignment - argument. Differs from memalign only in that it (1) assigns the - allocated memory to *pp rather than returning it, (2) fails and - returns EINVAL if the alignment is not a power of two (3) fails and - returns ENOMEM if memory cannot be allocated. -*/ -DLMALLOC_EXPORT int dlposix_memalign(void**, size_t, size_t); - -/* - valloc(size_t n); - Equivalent to memalign(pagesize, n), where pagesize is the page - size of the system. If the pagesize is unknown, 4096 is used. -*/ -DLMALLOC_EXPORT void* dlvalloc(size_t); - -/* - mallopt(int parameter_number, int parameter_value) - Sets tunable parameters The format is to provide a - (parameter-number, parameter-value) pair. mallopt then sets the - corresponding parameter to the argument value if it can (i.e., so - long as the value is meaningful), and returns 1 if successful else - 0. To workaround the fact that mallopt is specified to use int, - not size_t parameters, the value -1 is specially treated as the - maximum unsigned size_t value. - - SVID/XPG/ANSI defines four standard param numbers for mallopt, - normally defined in malloc.h. None of these are use in this malloc, - so setting them has no effect. But this malloc also supports other - options in mallopt. See below for details. Briefly, supported - parameters are as follows (listed defaults are for "typical" - configurations). - - Symbol param # default allowed param values - M_TRIM_THRESHOLD -1 2*1024*1024 any (-1 disables) - M_GRANULARITY -2 page size any power of 2 >= page size - M_MMAP_THRESHOLD -3 256*1024 any (or 0 if no MMAP support) -*/ -DLMALLOC_EXPORT int dlmallopt(int, int); - -/* - malloc_footprint(); - Returns the number of bytes obtained from the system. The total - number of bytes allocated by malloc, realloc etc., is less than this - value. Unlike mallinfo, this function returns only a precomputed - result, so can be called frequently to monitor memory consumption. - Even if locks are otherwise defined, this function does not use them, - so results might not be up to date. -*/ -DLMALLOC_EXPORT size_t dlmalloc_footprint(void); - -/* - malloc_max_footprint(); - Returns the maximum number of bytes obtained from the system. This - value will be greater than current footprint if deallocated space - has been reclaimed by the system. The peak number of bytes allocated - by malloc, realloc etc., is less than this value. Unlike mallinfo, - this function returns only a precomputed result, so can be called - frequently to monitor memory consumption. Even if locks are - otherwise defined, this function does not use them, so results might - not be up to date. -*/ -DLMALLOC_EXPORT size_t dlmalloc_max_footprint(void); - -/* - malloc_footprint_limit(); - Returns the number of bytes that the heap is allowed to obtain from - the system, returning the last value returned by - malloc_set_footprint_limit, or the maximum size_t value if - never set. The returned value reflects a permission. There is no - guarantee that this number of bytes can actually be obtained from - the system. -*/ -DLMALLOC_EXPORT size_t dlmalloc_footprint_limit(void); - -/* - malloc_set_footprint_limit(); - Sets the maximum number of bytes to obtain from the system, causing - failure returns from malloc and related functions upon attempts to - exceed this value. The argument value may be subject to page - rounding to an enforceable limit; this actual value is returned. - Using an argument of the maximum possible size_t effectively - disables checks. If the argument is less than or equal to the - current malloc_footprint, then all future allocations that require - additional system memory will fail. However, invocation cannot - retroactively deallocate existing used memory. -*/ -DLMALLOC_EXPORT size_t dlmalloc_set_footprint_limit(size_t bytes); - -#if MALLOC_INSPECT_ALL -/* - malloc_inspect_all(void(*handler)(void *start, - void *end, - size_t used_bytes, - void* callback_arg), - void* arg); - Traverses the heap and calls the given handler for each managed - region, skipping all bytes that are (or may be) used for bookkeeping - purposes. Traversal does not include include chunks that have been - directly memory mapped. Each reported region begins at the start - address, and continues up to but not including the end address. The - first used_bytes of the region contain allocated data. If - used_bytes is zero, the region is unallocated. The handler is - invoked with the given callback argument. If locks are defined, they - are held during the entire traversal. It is a bad idea to invoke - other malloc functions from within the handler. - - For example, to count the number of in-use chunks with size greater - than 1000, you could write: - static int count = 0; - void count_chunks(void* start, void* end, size_t used, void* arg) { - if (used >= 1000) ++count; - } - then: - malloc_inspect_all(count_chunks, NULL); - - malloc_inspect_all is compiled only if MALLOC_INSPECT_ALL is defined. -*/ -DLMALLOC_EXPORT void dlmalloc_inspect_all(void(*handler)(void*, void *, size_t, void*), - void* arg); - -#endif /* MALLOC_INSPECT_ALL */ - -#if !NO_MALLINFO -/* - mallinfo() - Returns (by copy) a struct containing various summary statistics: - - arena: current total non-mmapped bytes allocated from system - ordblks: the number of free chunks - smblks: always zero. - hblks: current number of mmapped regions - hblkhd: total bytes held in mmapped regions - usmblks: the maximum total allocated space. This will be greater - than current total if trimming has occurred. - fsmblks: always zero - uordblks: current total allocated space (normal or mmapped) - fordblks: total free space - keepcost: the maximum number of bytes that could ideally be released - back to system via malloc_trim. ("ideally" means that - it ignores page restrictions etc.) - - Because these fields are ints, but internal bookkeeping may - be kept as longs, the reported values may wrap around zero and - thus be inaccurate. -*/ -DLMALLOC_EXPORT struct mallinfo dlmallinfo(void); -#endif /* NO_MALLINFO */ - -/* - independent_calloc(size_t n_elements, size_t element_size, void* chunks[]); - - independent_calloc is similar to calloc, but instead of returning a - single cleared space, it returns an array of pointers to n_elements - independent elements that can hold contents of size elem_size, each - of which starts out cleared, and can be independently freed, - realloc'ed etc. The elements are guaranteed to be adjacently - allocated (this is not guaranteed to occur with multiple callocs or - mallocs), which may also improve cache locality in some - applications. - - The "chunks" argument is optional (i.e., may be null, which is - probably the most typical usage). If it is null, the returned array - is itself dynamically allocated and should also be freed when it is - no longer needed. Otherwise, the chunks array must be of at least - n_elements in length. It is filled in with the pointers to the - chunks. - - In either case, independent_calloc returns this pointer array, or - null if the allocation failed. If n_elements is zero and "chunks" - is null, it returns a chunk representing an array with zero elements - (which should be freed if not wanted). - - Each element must be freed when it is no longer needed. This can be - done all at once using bulk_free. - - independent_calloc simplifies and speeds up implementations of many - kinds of pools. It may also be useful when constructing large data - structures that initially have a fixed number of fixed-sized nodes, - but the number is not known at compile time, and some of the nodes - may later need to be freed. For example: - - struct Node { int item; struct Node* next; }; - - struct Node* build_list() { - struct Node** pool; - int n = read_number_of_nodes_needed(); - if (n <= 0) return 0; - pool = (struct Node**)(independent_calloc(n, sizeof(struct Node), 0); - if (pool == 0) die(); - // organize into a linked list... - struct Node* first = pool[0]; - for (i = 0; i < n-1; ++i) - pool[i]->next = pool[i+1]; - free(pool); // Can now free the array (or not, if it is needed later) - return first; - } -*/ -DLMALLOC_EXPORT void** dlindependent_calloc(size_t, size_t, void**); - -/* - independent_comalloc(size_t n_elements, size_t sizes[], void* chunks[]); - - independent_comalloc allocates, all at once, a set of n_elements - chunks with sizes indicated in the "sizes" array. It returns - an array of pointers to these elements, each of which can be - independently freed, realloc'ed etc. The elements are guaranteed to - be adjacently allocated (this is not guaranteed to occur with - multiple callocs or mallocs), which may also improve cache locality - in some applications. - - The "chunks" argument is optional (i.e., may be null). If it is null - the returned array is itself dynamically allocated and should also - be freed when it is no longer needed. Otherwise, the chunks array - must be of at least n_elements in length. It is filled in with the - pointers to the chunks. - - In either case, independent_comalloc returns this pointer array, or - null if the allocation failed. If n_elements is zero and chunks is - null, it returns a chunk representing an array with zero elements - (which should be freed if not wanted). - - Each element must be freed when it is no longer needed. This can be - done all at once using bulk_free. - - independent_comallac differs from independent_calloc in that each - element may have a different size, and also that it does not - automatically clear elements. - - independent_comalloc can be used to speed up allocation in cases - where several structs or objects must always be allocated at the - same time. For example: - - struct Head { ... } - struct Foot { ... } - - void send_message(char* msg) { - int msglen = strlen(msg); - size_t sizes[3] = { sizeof(struct Head), msglen, sizeof(struct Foot) }; - void* chunks[3]; - if (independent_comalloc(3, sizes, chunks) == 0) - die(); - struct Head* head = (struct Head*)(chunks[0]); - char* body = (char*)(chunks[1]); - struct Foot* foot = (struct Foot*)(chunks[2]); - // ... - } - - In general though, independent_comalloc is worth using only for - larger values of n_elements. For small values, you probably won't - detect enough difference from series of malloc calls to bother. - - Overuse of independent_comalloc can increase overall memory usage, - since it cannot reuse existing noncontiguous small chunks that - might be available for some of the elements. -*/ -DLMALLOC_EXPORT void** dlindependent_comalloc(size_t, size_t*, void**); - -/* - bulk_free(void* array[], size_t n_elements) - Frees and clears (sets to null) each non-null pointer in the given - array. This is likely to be faster than freeing them one-by-one. - If footers are used, pointers that have been allocated in different - mspaces are not freed or cleared, and the count of all such pointers - is returned. For large arrays of pointers with poor locality, it - may be worthwhile to sort this array before calling bulk_free. -*/ -DLMALLOC_EXPORT size_t dlbulk_free(void**, size_t n_elements); - -/* - pvalloc(size_t n); - Equivalent to valloc(minimum-page-that-holds(n)), that is, - round up n to nearest pagesize. - */ -DLMALLOC_EXPORT void* dlpvalloc(size_t); - -/* - malloc_trim(size_t pad); - - If possible, gives memory back to the system (via negative arguments - to sbrk) if there is unused memory at the `high' end of the malloc - pool or in unused MMAP segments. You can call this after freeing - large blocks of memory to potentially reduce the system-level memory - requirements of a program. However, it cannot guarantee to reduce - memory. Under some allocation patterns, some large free blocks of - memory will be locked between two used chunks, so they cannot be - given back to the system. - - The `pad' argument to malloc_trim represents the amount of free - trailing space to leave untrimmed. If this argument is zero, only - the minimum amount of memory to maintain internal data structures - will be left. Non-zero arguments can be supplied to maintain enough - trailing space to service future expected allocations without having - to re-obtain memory from the system. - - Malloc_trim returns 1 if it actually released any memory, else 0. -*/ -DLMALLOC_EXPORT int dlmalloc_trim(size_t); - -/* - malloc_stats(); - Prints on stderr the amount of space obtained from the system (both - via sbrk and mmap), the maximum amount (which may be more than - current if malloc_trim and/or munmap got called), and the current - number of bytes allocated via malloc (or realloc, etc) but not yet - freed. Note that this is the number of bytes allocated, not the - number requested. It will be larger than the number requested - because of alignment and bookkeeping overhead. Because it includes - alignment wastage as being in use, this figure may be greater than - zero even when no user-level chunks are allocated. - - The reported current and maximum system memory can be inaccurate if - a program makes other calls to system memory allocation functions - (normally sbrk) outside of malloc. - - malloc_stats prints only the most commonly interesting statistics. - More information can be obtained by calling mallinfo. -*/ -DLMALLOC_EXPORT void dlmalloc_stats(void); - -/* - malloc_usable_size(void* p); - - Returns the number of bytes you can actually use in - an allocated chunk, which may be more than you requested (although - often not) due to alignment and minimum size constraints. - You can use this many bytes without worrying about - overwriting other allocated objects. This is not a particularly great - programming practice. malloc_usable_size can be more useful in - debugging and assertions, for example: - - p = malloc(n); - assert(malloc_usable_size(p) >= 256); -size_t dlmalloc_usable_size(void*); -*/ - -#endif /* ONLY_MSPACES */ - -#if MSPACES - -/* - mspace is an opaque type representing an independent - region of space that supports mspace_malloc, etc. -*/ -typedef void* mspace; - -/* - create_mspace creates and returns a new independent space with the - given initial capacity, or, if 0, the default granularity size. It - returns null if there is no system memory available to create the - space. If argument locked is non-zero, the space uses a separate - lock to control access. The capacity of the space will grow - dynamically as needed to service mspace_malloc requests. You can - control the sizes of incremental increases of this space by - compiling with a different DEFAULT_GRANULARITY or dynamically - setting with mallopt(M_GRANULARITY, value). -*/ -DLMALLOC_EXPORT mspace create_mspace(size_t capacity, int locked); - -/* - destroy_mspace destroys the given space, and attempts to return all - of its memory back to the system, returning the total number of - bytes freed. After destruction, the results of access to all memory - used by the space become undefined. -*/ -DLMALLOC_EXPORT size_t destroy_mspace(mspace msp); - -/* - create_mspace_with_base uses the memory supplied as the initial base - of a new mspace. Part (less than 128*sizeof(size_t) bytes) of this - space is used for bookkeeping, so the capacity must be at least this - large. (Otherwise 0 is returned.) When this initial space is - exhausted, additional memory will be obtained from the system. - Destroying this space will deallocate all additionally allocated - space (if possible) but not the initial base. -*/ -DLMALLOC_EXPORT mspace create_mspace_with_base(void* base, size_t capacity, int locked); - -/* - mspace_track_large_chunks controls whether requests for large chunks - are allocated in their own untracked mmapped regions, separate from - others in this mspace. By default large chunks are not tracked, - which reduces fragmentation. However, such chunks are not - necessarily released to the system upon destroy_mspace. Enabling - tracking by setting to true may increase fragmentation, but avoids - leakage when relying on destroy_mspace to release all memory - allocated using this space. The function returns the previous - setting. -*/ -DLMALLOC_EXPORT int mspace_track_large_chunks(mspace msp, int enable); - - -/* - mspace_malloc behaves as malloc, but operates within - the given space. -*/ -DLMALLOC_EXPORT void* mspace_malloc(mspace msp, size_t bytes); - -/* - mspace_free behaves as free, but operates within - the given space. - - If compiled with FOOTERS==1, mspace_free is not actually needed. - free may be called instead of mspace_free because freed chunks from - any space are handled by their originating spaces. -*/ -DLMALLOC_EXPORT void mspace_free(mspace msp, void* mem); - -/* - mspace_realloc behaves as realloc, but operates within - the given space. - - If compiled with FOOTERS==1, mspace_realloc is not actually - needed. realloc may be called instead of mspace_realloc because - realloced chunks from any space are handled by their originating - spaces. -*/ -DLMALLOC_EXPORT void* mspace_realloc(mspace msp, void* mem, size_t newsize); - -/* - mspace_calloc behaves as calloc, but operates within - the given space. -*/ -DLMALLOC_EXPORT void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size); - -/* - mspace_memalign behaves as memalign, but operates within - the given space. -*/ -DLMALLOC_EXPORT void* mspace_memalign(mspace msp, size_t alignment, size_t bytes); - -/* - mspace_independent_calloc behaves as independent_calloc, but - operates within the given space. -*/ -DLMALLOC_EXPORT void** mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void* chunks[]); - -/* - mspace_independent_comalloc behaves as independent_comalloc, but - operates within the given space. -*/ -DLMALLOC_EXPORT void** mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void* chunks[]); - -/* - mspace_footprint() returns the number of bytes obtained from the - system for this space. -*/ -DLMALLOC_EXPORT size_t mspace_footprint(mspace msp); - -/* - mspace_max_footprint() returns the peak number of bytes obtained from the - system for this space. -*/ -DLMALLOC_EXPORT size_t mspace_max_footprint(mspace msp); - - -#if !NO_MALLINFO -/* - mspace_mallinfo behaves as mallinfo, but reports properties of - the given space. -*/ -DLMALLOC_EXPORT struct mallinfo mspace_mallinfo(mspace msp); -#endif /* NO_MALLINFO */ - -/* - malloc_usable_size(void* p) behaves the same as malloc_usable_size; -*/ -DLMALLOC_EXPORT size_t mspace_usable_size(const void* mem); - -/* - mspace_malloc_stats behaves as malloc_stats, but reports - properties of the given space. -*/ -DLMALLOC_EXPORT void mspace_malloc_stats(mspace msp); - -/* - mspace_trim behaves as malloc_trim, but - operates within the given space. -*/ -DLMALLOC_EXPORT int mspace_trim(mspace msp, size_t pad); - -/* - An alias for mallopt. -*/ -DLMALLOC_EXPORT int mspace_mallopt(int, int); - -#endif /* MSPACES */ - -#ifdef __cplusplus -} /* end of extern "C" */ -#endif /* __cplusplus */ - -/* - ======================================================================== - To make a fully customizable malloc.h header file, cut everything - above this line, put into file malloc.h, edit to suit, and #include it - on the next line, as well as in programs that use this malloc. - ======================================================================== -*/ - -/* #include "malloc.h" */ - -/*------------------------------ internal #includes ---------------------- */ - -#ifdef _MSC_VER -#pragma warning( disable : 4146 ) /* no "unsigned" warnings */ -#endif /* _MSC_VER */ -#if !NO_MALLOC_STATS -#include /* for printing in malloc_stats */ -#endif /* NO_MALLOC_STATS */ -#ifndef LACKS_ERRNO_H -#include /* for MALLOC_FAILURE_ACTION */ -#endif /* LACKS_ERRNO_H */ -#ifdef DEBUG -#if ABORT_ON_ASSERT_FAILURE -#undef assert -#define assert(x) if(!(x)) ABORT -#else /* ABORT_ON_ASSERT_FAILURE */ -#include -#endif /* ABORT_ON_ASSERT_FAILURE */ -#else /* DEBUG */ -#ifndef assert -#define assert(x) -#endif -#define DEBUG 0 -#endif /* DEBUG */ -#if !defined(WIN32) && !defined(LACKS_TIME_H) -#include /* for magic initialization */ -#endif /* WIN32 */ -#ifndef LACKS_STDLIB_H -#include /* for abort() */ -#endif /* LACKS_STDLIB_H */ -#ifndef LACKS_STRING_H -#include /* for memset etc */ -#endif /* LACKS_STRING_H */ -#if USE_BUILTIN_FFS -#ifndef LACKS_STRINGS_H -#include /* for ffs */ -#endif /* LACKS_STRINGS_H */ -#endif /* USE_BUILTIN_FFS */ -#if HAVE_MMAP -#ifndef LACKS_SYS_MMAN_H -/* On some versions of linux, mremap decl in mman.h needs __USE_GNU set */ -#if (defined(linux) && !defined(__USE_GNU)) -#define __USE_GNU 1 -#include /* for mmap */ -#undef __USE_GNU -#else -#include /* for mmap */ -#endif /* linux */ -#endif /* LACKS_SYS_MMAN_H */ -#ifndef LACKS_FCNTL_H -#include -#endif /* LACKS_FCNTL_H */ -#endif /* HAVE_MMAP */ -#ifndef LACKS_UNISTD_H -#include /* for sbrk, sysconf */ -#else /* LACKS_UNISTD_H */ -#if !defined(__FreeBSD__) && !defined(__OpenBSD__) && !defined(__NetBSD__) -extern void* sbrk(ptrdiff_t); -#endif /* FreeBSD etc */ -#endif /* LACKS_UNISTD_H */ - -/* Declarations for locking */ -#if USE_LOCKS -#ifndef WIN32 -#if defined (__SVR4) && defined (__sun) /* solaris */ -#include -#elif !defined(LACKS_SCHED_H) -#include -#endif /* solaris or LACKS_SCHED_H */ -#if (defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0) || !USE_SPIN_LOCKS -#include -#endif /* USE_RECURSIVE_LOCKS ... */ -#elif defined(_MSC_VER) -#ifndef _M_AMD64 -/* These are already defined on AMD64 builds */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ -LONG __cdecl _InterlockedCompareExchange(LONG volatile *Dest, LONG Exchange, LONG Comp); -LONG __cdecl _InterlockedExchange(LONG volatile *Target, LONG Value); -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* _M_AMD64 */ -#pragma intrinsic (_InterlockedCompareExchange) -#pragma intrinsic (_InterlockedExchange) -#define interlockedcompareexchange _InterlockedCompareExchange -#define interlockedexchange _InterlockedExchange -#elif defined(WIN32) && defined(__GNUC__) -#define interlockedcompareexchange(a, b, c) __sync_val_compare_and_swap(a, c, b) -#define interlockedexchange __sync_lock_test_and_set -#endif /* Win32 */ -#else /* USE_LOCKS */ -#endif /* USE_LOCKS */ - -#ifndef LOCK_AT_FORK -#define LOCK_AT_FORK 0 -#endif - -/* Declarations for bit scanning on win32 */ -#if defined(_MSC_VER) && _MSC_VER>=1300 -#ifndef BitScanForward /* Try to avoid pulling in WinNT.h */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ -unsigned char _BitScanForward(unsigned long *index, unsigned long mask); -unsigned char _BitScanReverse(unsigned long *index, unsigned long mask); -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#define BitScanForward _BitScanForward -#define BitScanReverse _BitScanReverse -#pragma intrinsic(_BitScanForward) -#pragma intrinsic(_BitScanReverse) -#endif /* BitScanForward */ -#endif /* defined(_MSC_VER) && _MSC_VER>=1300 */ - -#ifndef WIN32 -#ifndef malloc_getpagesize -# ifdef _SC_PAGESIZE /* some SVR4 systems omit an underscore */ -# ifndef _SC_PAGE_SIZE -# define _SC_PAGE_SIZE _SC_PAGESIZE -# endif -# endif -# ifdef _SC_PAGE_SIZE -# define malloc_getpagesize sysconf(_SC_PAGE_SIZE) -# else -# if defined(BSD) || defined(DGUX) || defined(HAVE_GETPAGESIZE) - extern size_t getpagesize(); -# define malloc_getpagesize getpagesize() -# else -# ifdef WIN32 /* use supplied emulation of getpagesize */ -# define malloc_getpagesize getpagesize() -# else -# ifndef LACKS_SYS_PARAM_H -# include -# endif -# ifdef EXEC_PAGESIZE -# define malloc_getpagesize EXEC_PAGESIZE -# else -# ifdef NBPG -# ifndef CLSIZE -# define malloc_getpagesize NBPG -# else -# define malloc_getpagesize (NBPG * CLSIZE) -# endif -# else -# ifdef NBPC -# define malloc_getpagesize NBPC -# else -# ifdef PAGESIZE -# define malloc_getpagesize PAGESIZE -# else /* just guess */ -# define malloc_getpagesize ((size_t)4096U) -# endif -# endif -# endif -# endif -# endif -# endif -# endif -#endif -#endif - -/* ------------------- size_t and alignment properties -------------------- */ - -/* The byte and bit size of a size_t */ -#define SIZE_T_SIZE (sizeof(size_t)) -#define SIZE_T_BITSIZE (sizeof(size_t) << 3) - -/* Some constants coerced to size_t */ -/* Annoying but necessary to avoid errors on some platforms */ -#define SIZE_T_ZERO ((size_t)0) -#define SIZE_T_ONE ((size_t)1) -#define SIZE_T_TWO ((size_t)2) -#define SIZE_T_FOUR ((size_t)4) -#define TWO_SIZE_T_SIZES (SIZE_T_SIZE<<1) -#define FOUR_SIZE_T_SIZES (SIZE_T_SIZE<<2) -#define SIX_SIZE_T_SIZES (FOUR_SIZE_T_SIZES+TWO_SIZE_T_SIZES) -#define HALF_MAX_SIZE_T (MAX_SIZE_T / 2U) - -/* The bit mask value corresponding to MALLOC_ALIGNMENT */ -#define CHUNK_ALIGN_MASK (MALLOC_ALIGNMENT - SIZE_T_ONE) - -/* True if address a has acceptable alignment */ -#define is_aligned(A) (((size_t)((A)) & (CHUNK_ALIGN_MASK)) == 0) - -/* the number of bytes to offset an address to align it */ -#define align_offset(A)\ - ((((size_t)(A) & CHUNK_ALIGN_MASK) == 0)? 0 :\ - ((MALLOC_ALIGNMENT - ((size_t)(A) & CHUNK_ALIGN_MASK)) & CHUNK_ALIGN_MASK)) - -/* -------------------------- MMAP preliminaries ------------------------- */ - -/* - If HAVE_MORECORE or HAVE_MMAP are false, we just define calls and - checks to fail so compiler optimizer can delete code rather than - using so many "#if"s. -*/ - - -/* MORECORE and MMAP must return MFAIL on failure */ -#define MFAIL ((void*)(MAX_SIZE_T)) -#define CMFAIL ((char*)(MFAIL)) /* defined for convenience */ - -#if HAVE_MMAP - -#ifndef WIN32 -#define MUNMAP_DEFAULT(a, s) munmap((a), (s)) -#define MMAP_PROT (PROT_READ|PROT_WRITE) -#if !defined(MAP_ANONYMOUS) && defined(MAP_ANON) -#define MAP_ANONYMOUS MAP_ANON -#endif /* MAP_ANON */ -#ifdef MAP_ANONYMOUS -#define MMAP_FLAGS (MAP_PRIVATE|MAP_ANONYMOUS) -#define MMAP_DEFAULT(s) mmap(0, (s), MMAP_PROT, MMAP_FLAGS, -1, 0) -#else /* MAP_ANONYMOUS */ -/* - Nearly all versions of mmap support MAP_ANONYMOUS, so the following - is unlikely to be needed, but is supplied just in case. -*/ -#define MMAP_FLAGS (MAP_PRIVATE) -static int dev_zero_fd = -1; /* Cached file descriptor for /dev/zero. */ -#define MMAP_DEFAULT(s) ((dev_zero_fd < 0) ? \ - (dev_zero_fd = open("/dev/zero", O_RDWR), \ - mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) : \ - mmap(0, (s), MMAP_PROT, MMAP_FLAGS, dev_zero_fd, 0)) -#endif /* MAP_ANONYMOUS */ - -#define DIRECT_MMAP_DEFAULT(s) MMAP_DEFAULT(s) - -#else /* WIN32 */ - -/* Win32 MMAP via VirtualAlloc */ -static FORCEINLINE void* win32mmap(size_t size) { - void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT, PAGE_READWRITE); - return (ptr != 0)? ptr: MFAIL; -} - -/* For direct MMAP, use MEM_TOP_DOWN to minimize interference */ -static FORCEINLINE void* win32direct_mmap(size_t size) { - void* ptr = VirtualAlloc(0, size, MEM_RESERVE|MEM_COMMIT|MEM_TOP_DOWN, - PAGE_READWRITE); - return (ptr != 0)? ptr: MFAIL; -} - -/* This function supports releasing coalesed segments */ -static FORCEINLINE int win32munmap(void* ptr, size_t size) { - MEMORY_BASIC_INFORMATION minfo; - char* cptr = (char*)ptr; - while (size) { - if (VirtualQuery(cptr, &minfo, sizeof(minfo)) == 0) - return -1; - if (minfo.BaseAddress != cptr || minfo.AllocationBase != cptr || - minfo.State != MEM_COMMIT || minfo.RegionSize > size) - return -1; - if (VirtualFree(cptr, 0, MEM_RELEASE) == 0) - return -1; - cptr += minfo.RegionSize; - size -= minfo.RegionSize; - } - return 0; -} - -#define MMAP_DEFAULT(s) win32mmap(s) -#define MUNMAP_DEFAULT(a, s) win32munmap((a), (s)) -#define DIRECT_MMAP_DEFAULT(s) win32direct_mmap(s) -#endif /* WIN32 */ -#endif /* HAVE_MMAP */ - -#if HAVE_MREMAP -#ifndef WIN32 -#define MREMAP_DEFAULT(addr, osz, nsz, mv) mremap((addr), (osz), (nsz), (mv)) -#endif /* WIN32 */ -#endif /* HAVE_MREMAP */ - -/** - * Define CALL_MORECORE - */ -#if HAVE_MORECORE - #ifdef MORECORE - #define CALL_MORECORE(S) MORECORE(S) - #else /* MORECORE */ - #define CALL_MORECORE(S) MORECORE_DEFAULT(S) - #endif /* MORECORE */ -#else /* HAVE_MORECORE */ - #define CALL_MORECORE(S) MFAIL -#endif /* HAVE_MORECORE */ - -/** - * Define CALL_MMAP/CALL_MUNMAP/CALL_DIRECT_MMAP - */ -#if HAVE_MMAP - #define USE_MMAP_BIT (SIZE_T_ONE) - - #ifdef MMAP - #define CALL_MMAP(s) MMAP(s) - #else /* MMAP */ - #define CALL_MMAP(s) MMAP_DEFAULT(s) - #endif /* MMAP */ - #ifdef MUNMAP - #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) - #else /* MUNMAP */ - #define CALL_MUNMAP(a, s) MUNMAP_DEFAULT((a), (s)) - #endif /* MUNMAP */ - #ifdef DIRECT_MMAP - #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) - #else /* DIRECT_MMAP */ - #define CALL_DIRECT_MMAP(s) DIRECT_MMAP_DEFAULT(s) - #endif /* DIRECT_MMAP */ -#else /* HAVE_MMAP */ - #define USE_MMAP_BIT (SIZE_T_ZERO) - - #define MMAP(s) MFAIL - #define MUNMAP(a, s) (-1) - #define DIRECT_MMAP(s) MFAIL - #define CALL_DIRECT_MMAP(s) DIRECT_MMAP(s) - #define CALL_MMAP(s) MMAP(s) - #define CALL_MUNMAP(a, s) MUNMAP((a), (s)) -#endif /* HAVE_MMAP */ - -/** - * Define CALL_MREMAP - */ -#if HAVE_MMAP && HAVE_MREMAP - #ifdef MREMAP - #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP((addr), (osz), (nsz), (mv)) - #else /* MREMAP */ - #define CALL_MREMAP(addr, osz, nsz, mv) MREMAP_DEFAULT((addr), (osz), (nsz), (mv)) - #endif /* MREMAP */ -#else /* HAVE_MMAP && HAVE_MREMAP */ - #define CALL_MREMAP(addr, osz, nsz, mv) MFAIL -#endif /* HAVE_MMAP && HAVE_MREMAP */ - -/* mstate bit set if continguous morecore disabled or failed */ -#define USE_NONCONTIGUOUS_BIT (4U) - -/* segment bit set in create_mspace_with_base */ -#define EXTERN_BIT (8U) - - -/* --------------------------- Lock preliminaries ------------------------ */ - -/* - When locks are defined, there is one global lock, plus - one per-mspace lock. - - The global lock_ensures that mparams.magic and other unique - mparams values are initialized only once. It also protects - sequences of calls to MORECORE. In many cases sys_alloc requires - two calls, that should not be interleaved with calls by other - threads. This does not protect against direct calls to MORECORE - by other threads not using this lock, so there is still code to - cope the best we can on interference. - - Per-mspace locks surround calls to malloc, free, etc. - By default, locks are simple non-reentrant mutexes. - - Because lock-protected regions generally have bounded times, it is - OK to use the supplied simple spinlocks. Spinlocks are likely to - improve performance for lightly contended applications, but worsen - performance under heavy contention. - - If USE_LOCKS is > 1, the definitions of lock routines here are - bypassed, in which case you will need to define the type MLOCK_T, - and at least INITIAL_LOCK, DESTROY_LOCK, ACQUIRE_LOCK, RELEASE_LOCK - and TRY_LOCK. You must also declare a - static MLOCK_T malloc_global_mutex = { initialization values };. - -*/ - -#if !USE_LOCKS -#define USE_LOCK_BIT (0U) -#define INITIAL_LOCK(l) (0) -#define DESTROY_LOCK(l) (0) -#define ACQUIRE_MALLOC_GLOBAL_LOCK() -#define RELEASE_MALLOC_GLOBAL_LOCK() - -#else -#if USE_LOCKS > 1 -/* ----------------------- User-defined locks ------------------------ */ -/* Define your own lock implementation here */ -/* #define INITIAL_LOCK(lk) ... */ -/* #define DESTROY_LOCK(lk) ... */ -/* #define ACQUIRE_LOCK(lk) ... */ -/* #define RELEASE_LOCK(lk) ... */ -/* #define TRY_LOCK(lk) ... */ -/* static MLOCK_T malloc_global_mutex = ... */ - -#elif USE_SPIN_LOCKS - -/* First, define CAS_LOCK and CLEAR_LOCK on ints */ -/* Note CAS_LOCK defined to return 0 on success */ - -#if defined(__GNUC__)&& (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) -#define CAS_LOCK(sl) __sync_lock_test_and_set(sl, 1) -#define CLEAR_LOCK(sl) __sync_lock_release(sl) - -#elif (defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__))) -/* Custom spin locks for older gcc on x86 */ -static FORCEINLINE int x86_cas_lock(int *sl) { - int ret; - int val = 1; - int cmp = 0; - __asm__ __volatile__ ("lock; cmpxchgl %1, %2" - : "=a" (ret) - : "r" (val), "m" (*(sl)), "0"(cmp) - : "memory", "cc"); - return ret; -} - -static FORCEINLINE void x86_clear_lock(int* sl) { - assert(*sl != 0); - int prev = 0; - int ret; - __asm__ __volatile__ ("lock; xchgl %0, %1" - : "=r" (ret) - : "m" (*(sl)), "0"(prev) - : "memory"); -} - -#define CAS_LOCK(sl) x86_cas_lock(sl) -#define CLEAR_LOCK(sl) x86_clear_lock(sl) - -#else /* Win32 MSC */ -#define CAS_LOCK(sl) interlockedexchange(sl, (LONG)1) -#define CLEAR_LOCK(sl) interlockedexchange (sl, (LONG)0) - -#endif /* ... gcc spins locks ... */ - -/* How to yield for a spin lock */ -#define SPINS_PER_YIELD 63 -#if defined(_MSC_VER) -#define SLEEP_EX_DURATION 50 /* delay for yield/sleep */ -#define SPIN_LOCK_YIELD SleepEx(SLEEP_EX_DURATION, FALSE) -#elif defined (__SVR4) && defined (__sun) /* solaris */ -#define SPIN_LOCK_YIELD thr_yield(); -#elif !defined(LACKS_SCHED_H) -#define SPIN_LOCK_YIELD sched_yield(); -#else -#define SPIN_LOCK_YIELD -#endif /* ... yield ... */ - -#if !defined(USE_RECURSIVE_LOCKS) || USE_RECURSIVE_LOCKS == 0 -/* Plain spin locks use single word (embedded in malloc_states) */ -static int spin_acquire_lock(int *sl) { - int spins = 0; - while (*(volatile int *)sl != 0 || CAS_LOCK(sl)) { - if ((++spins & SPINS_PER_YIELD) == 0) { - SPIN_LOCK_YIELD; - } - } - return 0; -} - -#define MLOCK_T int -#define TRY_LOCK(sl) !CAS_LOCK(sl) -#define RELEASE_LOCK(sl) CLEAR_LOCK(sl) -#define ACQUIRE_LOCK(sl) (CAS_LOCK(sl)? spin_acquire_lock(sl) : 0) -#define INITIAL_LOCK(sl) (*sl = 0) -#define DESTROY_LOCK(sl) (0) -static MLOCK_T malloc_global_mutex = 0; - -#else /* USE_RECURSIVE_LOCKS */ -/* types for lock owners */ -#ifdef WIN32 -#define THREAD_ID_T DWORD -#define CURRENT_THREAD GetCurrentThreadId() -#define EQ_OWNER(X,Y) ((X) == (Y)) -#else -/* - Note: the following assume that pthread_t is a type that can be - initialized to (casted) zero. If this is not the case, you will need to - somehow redefine these or not use spin locks. -*/ -#define THREAD_ID_T pthread_t -#define CURRENT_THREAD pthread_self() -#define EQ_OWNER(X,Y) pthread_equal(X, Y) -#endif - -struct malloc_recursive_lock { - int sl; - unsigned int c; - THREAD_ID_T threadid; -}; - -#define MLOCK_T struct malloc_recursive_lock -static MLOCK_T malloc_global_mutex = { 0, 0, (THREAD_ID_T)0}; - -static FORCEINLINE void recursive_release_lock(MLOCK_T *lk) { - assert(lk->sl != 0); - if (--lk->c == 0) { - CLEAR_LOCK(&lk->sl); - } -} - -static FORCEINLINE int recursive_acquire_lock(MLOCK_T *lk) { - THREAD_ID_T mythreadid = CURRENT_THREAD; - int spins = 0; - for (;;) { - if (*((volatile int *)(&lk->sl)) == 0) { - if (!CAS_LOCK(&lk->sl)) { - lk->threadid = mythreadid; - lk->c = 1; - return 0; - } - } - else if (EQ_OWNER(lk->threadid, mythreadid)) { - ++lk->c; - return 0; - } - if ((++spins & SPINS_PER_YIELD) == 0) { - SPIN_LOCK_YIELD; - } - } -} - -static FORCEINLINE int recursive_try_lock(MLOCK_T *lk) { - THREAD_ID_T mythreadid = CURRENT_THREAD; - if (*((volatile int *)(&lk->sl)) == 0) { - if (!CAS_LOCK(&lk->sl)) { - lk->threadid = mythreadid; - lk->c = 1; - return 1; - } - } - else if (EQ_OWNER(lk->threadid, mythreadid)) { - ++lk->c; - return 1; - } - return 0; -} - -#define RELEASE_LOCK(lk) recursive_release_lock(lk) -#define TRY_LOCK(lk) recursive_try_lock(lk) -#define ACQUIRE_LOCK(lk) recursive_acquire_lock(lk) -#define INITIAL_LOCK(lk) ((lk)->threadid = (THREAD_ID_T)0, (lk)->sl = 0, (lk)->c = 0) -#define DESTROY_LOCK(lk) (0) -#endif /* USE_RECURSIVE_LOCKS */ - -#elif defined(WIN32) /* Win32 critical sections */ -#define MLOCK_T CRITICAL_SECTION -#define ACQUIRE_LOCK(lk) (EnterCriticalSection(lk), 0) -#define RELEASE_LOCK(lk) LeaveCriticalSection(lk) -#define TRY_LOCK(lk) TryEnterCriticalSection(lk) -#define INITIAL_LOCK(lk) (!InitializeCriticalSectionAndSpinCount((lk), 0x80000000|4000)) -#define DESTROY_LOCK(lk) (DeleteCriticalSection(lk), 0) -#define NEED_GLOBAL_LOCK_INIT - -static MLOCK_T malloc_global_mutex; -static volatile LONG malloc_global_mutex_status; - -/* Use spin loop to initialize global lock */ -static void init_malloc_global_mutex() { - for (;;) { - long stat = malloc_global_mutex_status; - if (stat > 0) - return; - /* transition to < 0 while initializing, then to > 0) */ - if (stat == 0 && - interlockedcompareexchange(&malloc_global_mutex_status, (LONG)-1, (LONG)0) == 0) { - InitializeCriticalSection(&malloc_global_mutex); - interlockedexchange(&malloc_global_mutex_status, (LONG)1); - return; - } - SleepEx(0, FALSE); - } -} - -#else /* pthreads-based locks */ -#define MLOCK_T pthread_mutex_t -#define ACQUIRE_LOCK(lk) pthread_mutex_lock(lk) -#define RELEASE_LOCK(lk) pthread_mutex_unlock(lk) -#define TRY_LOCK(lk) (!pthread_mutex_trylock(lk)) -#define INITIAL_LOCK(lk) pthread_init_lock(lk) -#define DESTROY_LOCK(lk) pthread_mutex_destroy(lk) - -#if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0 && defined(linux) && !defined(PTHREAD_MUTEX_RECURSIVE) -/* Cope with old-style linux recursive lock initialization by adding */ -/* skipped internal declaration from pthread.h */ -extern int pthread_mutexattr_setkind_np __P ((pthread_mutexattr_t *__attr, - int __kind)); -#define PTHREAD_MUTEX_RECURSIVE PTHREAD_MUTEX_RECURSIVE_NP -#define pthread_mutexattr_settype(x,y) pthread_mutexattr_setkind_np(x,y) -#endif /* USE_RECURSIVE_LOCKS ... */ - -static MLOCK_T malloc_global_mutex = PTHREAD_MUTEX_INITIALIZER; - -static int pthread_init_lock (MLOCK_T *lk) { - pthread_mutexattr_t attr; - if (pthread_mutexattr_init(&attr)) return 1; -#if defined(USE_RECURSIVE_LOCKS) && USE_RECURSIVE_LOCKS != 0 - if (pthread_mutexattr_settype(&attr, PTHREAD_MUTEX_RECURSIVE)) return 1; -#endif - if (pthread_mutex_init(lk, &attr)) return 1; - if (pthread_mutexattr_destroy(&attr)) return 1; - return 0; -} - -#endif /* ... lock types ... */ - -/* Common code for all lock types */ -#define USE_LOCK_BIT (2U) - -#ifndef ACQUIRE_MALLOC_GLOBAL_LOCK -#define ACQUIRE_MALLOC_GLOBAL_LOCK() ACQUIRE_LOCK(&malloc_global_mutex); -#endif - -#ifndef RELEASE_MALLOC_GLOBAL_LOCK -#define RELEASE_MALLOC_GLOBAL_LOCK() RELEASE_LOCK(&malloc_global_mutex); -#endif - -#endif /* USE_LOCKS */ - -/* ----------------------- Chunk representations ------------------------ */ - -/* - (The following includes lightly edited explanations by Colin Plumb.) - - The malloc_chunk declaration below is misleading (but accurate and - necessary). It declares a "view" into memory allowing access to - necessary fields at known offsets from a given base. - - Chunks of memory are maintained using a `boundary tag' method as - originally described by Knuth. (See the paper by Paul Wilson - ftp://ftp.cs.utexas.edu/pub/garbage/allocsrv.ps for a survey of such - techniques.) Sizes of free chunks are stored both in the front of - each chunk and at the end. This makes consolidating fragmented - chunks into bigger chunks fast. The head fields also hold bits - representing whether chunks are free or in use. - - Here are some pictures to make it clearer. They are "exploded" to - show that the state of a chunk can be thought of as extending from - the high 31 bits of the head field of its header through the - prev_foot and PINUSE_BIT bit of the following chunk header. - - A chunk that's in use looks like: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk (if P = 0) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| - | Size of this chunk 1| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | | - +- -+ - | | - +- -+ - | : - +- size - sizeof(size_t) available payload bytes -+ - : | - chunk-> +- -+ - | | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |1| - | Size of next chunk (may or may not be in use) | +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - And if it's free, it looks like this: - - chunk-> +- -+ - | User payload (must be in use, or we would have merged!) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |P| - | Size of this chunk 0| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Next pointer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Prev pointer | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | : - +- size - sizeof(struct chunk) unused bytes -+ - : | - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of this chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |0| - | Size of next chunk (must be in use, or we would have merged)| +-+ - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | : - +- User payload -+ - : | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - |0| - +-+ - Note that since we always merge adjacent free chunks, the chunks - adjacent to a free chunk must be in use. - - Given a pointer to a chunk (which can be derived trivially from the - payload pointer) we can, in O(1) time, find out whether the adjacent - chunks are free, and if so, unlink them from the lists that they - are on and merge them with the current chunk. - - Chunks always begin on even word boundaries, so the mem portion - (which is returned to the user) is also on an even word boundary, and - thus at least double-word aligned. - - The P (PINUSE_BIT) bit, stored in the unused low-order bit of the - chunk size (which is always a multiple of two words), is an in-use - bit for the *previous* chunk. If that bit is *clear*, then the - word before the current chunk size contains the previous chunk - size, and can be used to find the front of the previous chunk. - The very first chunk allocated always has this bit set, preventing - access to non-existent (or non-owned) memory. If pinuse is set for - any given chunk, then you CANNOT determine the size of the - previous chunk, and might even get a memory addressing fault when - trying to do so. - - The C (CINUSE_BIT) bit, stored in the unused second-lowest bit of - the chunk size redundantly records whether the current chunk is - inuse (unless the chunk is mmapped). This redundancy enables usage - checks within free and realloc, and reduces indirection when freeing - and consolidating chunks. - - Each freshly allocated chunk must have both cinuse and pinuse set. - That is, each allocated chunk borders either a previously allocated - and still in-use chunk, or the base of its memory arena. This is - ensured by making all allocations from the `lowest' part of any - found chunk. Further, no free chunk physically borders another one, - so each free chunk is known to be preceded and followed by either - inuse chunks or the ends of memory. - - Note that the `foot' of the current chunk is actually represented - as the prev_foot of the NEXT chunk. This makes it easier to - deal with alignments etc but can be very confusing when trying - to extend or adapt this code. - - The exceptions to all this are - - 1. The special chunk `top' is the top-most available chunk (i.e., - the one bordering the end of available memory). It is treated - specially. Top is never included in any bin, is used only if - no other chunk is available, and is released back to the - system if it is very large (see M_TRIM_THRESHOLD). In effect, - the top chunk is treated as larger (and thus less well - fitting) than any other available chunk. The top chunk - doesn't update its trailing size field since there is no next - contiguous chunk that would have to index off it. However, - space is still allocated for it (TOP_FOOT_SIZE) to enable - separation or merging when space is extended. - - 3. Chunks allocated via mmap, have both cinuse and pinuse bits - cleared in their head fields. Because they are allocated - one-by-one, each must carry its own prev_foot field, which is - also used to hold the offset this chunk has within its mmapped - region, which is needed to preserve alignment. Each mmapped - chunk is trailed by the first two fields of a fake next-chunk - for sake of usage checks. - -*/ - -struct malloc_chunk { - size_t prev_foot; /* Size of previous chunk (if free). */ - size_t head; /* Size and inuse bits. */ - struct malloc_chunk* fd; /* double links -- used only if free. */ - struct malloc_chunk* bk; -}; - -typedef struct malloc_chunk mchunk; -typedef struct malloc_chunk* mchunkptr; -typedef struct malloc_chunk* sbinptr; /* The type of bins of chunks */ -typedef unsigned int bindex_t; /* Described below */ -typedef unsigned int binmap_t; /* Described below */ -typedef unsigned int flag_t; /* The type of various bit flag sets */ - -/* ------------------- Chunks sizes and alignments ----------------------- */ - -#define MCHUNK_SIZE (sizeof(mchunk)) - -#if FOOTERS -#define CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) -#else /* FOOTERS */ -#define CHUNK_OVERHEAD (SIZE_T_SIZE) -#endif /* FOOTERS */ - -/* MMapped chunks need a second word of overhead ... */ -#define MMAP_CHUNK_OVERHEAD (TWO_SIZE_T_SIZES) -/* ... and additional padding for fake next-chunk at foot */ -#define MMAP_FOOT_PAD (FOUR_SIZE_T_SIZES) - -/* The smallest size we can malloc is an aligned minimal chunk */ -#define MIN_CHUNK_SIZE\ - ((MCHUNK_SIZE + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) - -/* conversion from malloc headers to user pointers, and back */ -#define chunk2mem(p) ((void*)((char*)(p) + TWO_SIZE_T_SIZES)) -#define mem2chunk(mem) ((mchunkptr)((char*)(mem) - TWO_SIZE_T_SIZES)) -/* chunk associated with aligned address A */ -#define align_as_chunk(A) (mchunkptr)((A) + align_offset(chunk2mem(A))) - -/* Bounds on request (not chunk) sizes. */ -#define MAX_REQUEST ((-MIN_CHUNK_SIZE) << 2) -#define MIN_REQUEST (MIN_CHUNK_SIZE - CHUNK_OVERHEAD - SIZE_T_ONE) - -/* pad request bytes into a usable size */ -#define pad_request(req) \ - (((req) + CHUNK_OVERHEAD + CHUNK_ALIGN_MASK) & ~CHUNK_ALIGN_MASK) - -/* pad request, checking for minimum (but not maximum) */ -#define request2size(req) \ - (((req) < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(req)) - - -/* ------------------ Operations on head and foot fields ----------------- */ - -/* - The head field of a chunk is or'ed with PINUSE_BIT when previous - adjacent chunk in use, and or'ed with CINUSE_BIT if this chunk is in - use, unless mmapped, in which case both bits are cleared. - - FLAG4_BIT is not used by this malloc, but might be useful in extensions. -*/ - -#define PINUSE_BIT (SIZE_T_ONE) -#define CINUSE_BIT (SIZE_T_TWO) -#define FLAG4_BIT (SIZE_T_FOUR) -#define INUSE_BITS (PINUSE_BIT|CINUSE_BIT) -#define FLAG_BITS (PINUSE_BIT|CINUSE_BIT|FLAG4_BIT) - -/* Head value for fenceposts */ -#define FENCEPOST_HEAD (INUSE_BITS|SIZE_T_SIZE) - -/* extraction of fields from head words */ -#define cinuse(p) ((p)->head & CINUSE_BIT) -#define pinuse(p) ((p)->head & PINUSE_BIT) -#define flag4inuse(p) ((p)->head & FLAG4_BIT) -#define is_inuse(p) (((p)->head & INUSE_BITS) != PINUSE_BIT) -#define is_mmapped(p) (((p)->head & INUSE_BITS) == 0) - -#define chunksize(p) ((p)->head & ~(FLAG_BITS)) - -#define clear_pinuse(p) ((p)->head &= ~PINUSE_BIT) -#define set_flag4(p) ((p)->head |= FLAG4_BIT) -#define clear_flag4(p) ((p)->head &= ~FLAG4_BIT) - -/* Treat space at ptr +/- offset as a chunk */ -#define chunk_plus_offset(p, s) ((mchunkptr)(((char*)(p)) + (s))) -#define chunk_minus_offset(p, s) ((mchunkptr)(((char*)(p)) - (s))) - -/* Ptr to next or previous physical malloc_chunk. */ -#define next_chunk(p) ((mchunkptr)( ((char*)(p)) + ((p)->head & ~FLAG_BITS))) -#define prev_chunk(p) ((mchunkptr)( ((char*)(p)) - ((p)->prev_foot) )) - -/* extract next chunk's pinuse bit */ -#define next_pinuse(p) ((next_chunk(p)->head) & PINUSE_BIT) - -/* Get/set size at footer */ -#define get_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot) -#define set_foot(p, s) (((mchunkptr)((char*)(p) + (s)))->prev_foot = (s)) - -/* Set size, pinuse bit, and foot */ -#define set_size_and_pinuse_of_free_chunk(p, s)\ - ((p)->head = (s|PINUSE_BIT), set_foot(p, s)) - -/* Set size, pinuse bit, foot, and clear next pinuse */ -#define set_free_with_pinuse(p, s, n)\ - (clear_pinuse(n), set_size_and_pinuse_of_free_chunk(p, s)) - -/* Get the internal overhead associated with chunk p */ -#define overhead_for(p)\ - (is_mmapped(p)? MMAP_CHUNK_OVERHEAD : CHUNK_OVERHEAD) - -/* Return true if malloced space is not necessarily cleared */ -#if MMAP_CLEARS -#define calloc_must_clear(p) (!is_mmapped(p)) -#else /* MMAP_CLEARS */ -#define calloc_must_clear(p) (1) -#endif /* MMAP_CLEARS */ - -/* ---------------------- Overlaid data structures ----------------------- */ - -/* - When chunks are not in use, they are treated as nodes of either - lists or trees. - - "Small" chunks are stored in circular doubly-linked lists, and look - like this: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `head:' | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk in list | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space (may be 0 bytes long) . - . . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Larger chunks are kept in a form of bitwise digital trees (aka - tries) keyed on chunksizes. Because malloc_tree_chunks are only for - free chunks greater than 256 bytes, their size doesn't impose any - constraints on user chunk sizes. Each node looks like: - - chunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Size of previous chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `head:' | Size of chunk, in bytes |P| - mem-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Forward pointer to next chunk of same size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Back pointer to previous chunk of same size | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to left child (child[0]) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to right child (child[1]) | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Pointer to parent | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | bin index of this chunk | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - | Unused space . - . | -nextchunk-> +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - `foot:' | Size of chunk, in bytes | - +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ - - Each tree holding treenodes is a tree of unique chunk sizes. Chunks - of the same size are arranged in a circularly-linked list, with only - the oldest chunk (the next to be used, in our FIFO ordering) - actually in the tree. (Tree members are distinguished by a non-null - parent pointer.) If a chunk with the same size an an existing node - is inserted, it is linked off the existing node using pointers that - work in the same way as fd/bk pointers of small chunks. - - Each tree contains a power of 2 sized range of chunk sizes (the - smallest is 0x100 <= x < 0x180), which is is divided in half at each - tree level, with the chunks in the smaller half of the range (0x100 - <= x < 0x140 for the top nose) in the left subtree and the larger - half (0x140 <= x < 0x180) in the right subtree. This is, of course, - done by inspecting individual bits. - - Using these rules, each node's left subtree contains all smaller - sizes than its right subtree. However, the node at the root of each - subtree has no particular ordering relationship to either. (The - dividing line between the subtree sizes is based on trie relation.) - If we remove the last chunk of a given size from the interior of the - tree, we need to replace it with a leaf node. The tree ordering - rules permit a node to be replaced by any leaf below it. - - The smallest chunk in a tree (a common operation in a best-fit - allocator) can be found by walking a path to the leftmost leaf in - the tree. Unlike a usual binary tree, where we follow left child - pointers until we reach a null, here we follow the right child - pointer any time the left one is null, until we reach a leaf with - both child pointers null. The smallest chunk in the tree will be - somewhere along that path. - - The worst case number of steps to add, find, or remove a node is - bounded by the number of bits differentiating chunks within - bins. Under current bin calculations, this ranges from 6 up to 21 - (for 32 bit sizes) or up to 53 (for 64 bit sizes). The typical case - is of course much better. -*/ - -struct malloc_tree_chunk { - /* The first four fields must be compatible with malloc_chunk */ - size_t prev_foot; - size_t head; - struct malloc_tree_chunk* fd; - struct malloc_tree_chunk* bk; - - struct malloc_tree_chunk* child[2]; - struct malloc_tree_chunk* parent; - bindex_t index; -}; - -typedef struct malloc_tree_chunk tchunk; -typedef struct malloc_tree_chunk* tchunkptr; -typedef struct malloc_tree_chunk* tbinptr; /* The type of bins of trees */ - -/* A little helper macro for trees */ -#define leftmost_child(t) ((t)->child[0] != 0? (t)->child[0] : (t)->child[1]) - -/* ----------------------------- Segments -------------------------------- */ - -/* - Each malloc space may include non-contiguous segments, held in a - list headed by an embedded malloc_segment record representing the - top-most space. Segments also include flags holding properties of - the space. Large chunks that are directly allocated by mmap are not - included in this list. They are instead independently created and - destroyed without otherwise keeping track of them. - - Segment management mainly comes into play for spaces allocated by - MMAP. Any call to MMAP might or might not return memory that is - adjacent to an existing segment. MORECORE normally contiguously - extends the current space, so this space is almost always adjacent, - which is simpler and faster to deal with. (This is why MORECORE is - used preferentially to MMAP when both are available -- see - sys_alloc.) When allocating using MMAP, we don't use any of the - hinting mechanisms (inconsistently) supported in various - implementations of unix mmap, or distinguish reserving from - committing memory. Instead, we just ask for space, and exploit - contiguity when we get it. It is probably possible to do - better than this on some systems, but no general scheme seems - to be significantly better. - - Management entails a simpler variant of the consolidation scheme - used for chunks to reduce fragmentation -- new adjacent memory is - normally prepended or appended to an existing segment. However, - there are limitations compared to chunk consolidation that mostly - reflect the fact that segment processing is relatively infrequent - (occurring only when getting memory from system) and that we - don't expect to have huge numbers of segments: - - * Segments are not indexed, so traversal requires linear scans. (It - would be possible to index these, but is not worth the extra - overhead and complexity for most programs on most platforms.) - * New segments are only appended to old ones when holding top-most - memory; if they cannot be prepended to others, they are held in - different segments. - - Except for the top-most segment of an mstate, each segment record - is kept at the tail of its segment. Segments are added by pushing - segment records onto the list headed by &mstate.seg for the - containing mstate. - - Segment flags control allocation/merge/deallocation policies: - * If EXTERN_BIT set, then we did not allocate this segment, - and so should not try to deallocate or merge with others. - (This currently holds only for the initial segment passed - into create_mspace_with_base.) - * If USE_MMAP_BIT set, the segment may be merged with - other surrounding mmapped segments and trimmed/de-allocated - using munmap. - * If neither bit is set, then the segment was obtained using - MORECORE so can be merged with surrounding MORECORE'd segments - and deallocated/trimmed using MORECORE with negative arguments. -*/ - -struct malloc_segment { - char* base; /* base address */ - size_t size; /* allocated size */ - struct malloc_segment* next; /* ptr to next segment */ - flag_t sflags; /* mmap and extern flag */ -}; - -#define is_mmapped_segment(S) ((S)->sflags & USE_MMAP_BIT) -#define is_extern_segment(S) ((S)->sflags & EXTERN_BIT) - -typedef struct malloc_segment msegment; -typedef struct malloc_segment* msegmentptr; - -/* ---------------------------- malloc_state ----------------------------- */ - -/* - A malloc_state holds all of the bookkeeping for a space. - The main fields are: - - Top - The topmost chunk of the currently active segment. Its size is - cached in topsize. The actual size of topmost space is - topsize+TOP_FOOT_SIZE, which includes space reserved for adding - fenceposts and segment records if necessary when getting more - space from the system. The size at which to autotrim top is - cached from mparams in trim_check, except that it is disabled if - an autotrim fails. - - Designated victim (dv) - This is the preferred chunk for servicing small requests that - don't have exact fits. It is normally the chunk split off most - recently to service another small request. Its size is cached in - dvsize. The link fields of this chunk are not maintained since it - is not kept in a bin. - - SmallBins - An array of bin headers for free chunks. These bins hold chunks - with sizes less than MIN_LARGE_SIZE bytes. Each bin contains - chunks of all the same size, spaced 8 bytes apart. To simplify - use in double-linked lists, each bin header acts as a malloc_chunk - pointing to the real first node, if it exists (else pointing to - itself). This avoids special-casing for headers. But to avoid - waste, we allocate only the fd/bk pointers of bins, and then use - repositioning tricks to treat these as the fields of a chunk. - - TreeBins - Treebins are pointers to the roots of trees holding a range of - sizes. There are 2 equally spaced treebins for each power of two - from TREE_SHIFT to TREE_SHIFT+16. The last bin holds anything - larger. - - Bin maps - There is one bit map for small bins ("smallmap") and one for - treebins ("treemap). Each bin sets its bit when non-empty, and - clears the bit when empty. Bit operations are then used to avoid - bin-by-bin searching -- nearly all "search" is done without ever - looking at bins that won't be selected. The bit maps - conservatively use 32 bits per map word, even if on 64bit system. - For a good description of some of the bit-based techniques used - here, see Henry S. Warren Jr's book "Hacker's Delight" (and - supplement at http://hackersdelight.org/). Many of these are - intended to reduce the branchiness of paths through malloc etc, as - well as to reduce the number of memory locations read or written. - - Segments - A list of segments headed by an embedded malloc_segment record - representing the initial space. - - Address check support - The least_addr field is the least address ever obtained from - MORECORE or MMAP. Attempted frees and reallocs of any address less - than this are trapped (unless INSECURE is defined). - - Magic tag - A cross-check field that should always hold same value as mparams.magic. - - Max allowed footprint - The maximum allowed bytes to allocate from system (zero means no limit) - - Flags - Bits recording whether to use MMAP, locks, or contiguous MORECORE - - Statistics - Each space keeps track of current and maximum system memory - obtained via MORECORE or MMAP. - - Trim support - Fields holding the amount of unused topmost memory that should trigger - trimming, and a counter to force periodic scanning to release unused - non-topmost segments. - - Locking - If USE_LOCKS is defined, the "mutex" lock is acquired and released - around every public call using this mspace. - - Extension support - A void* pointer and a size_t field that can be used to help implement - extensions to this malloc. -*/ - -/* Bin types, widths and sizes */ -#define NSMALLBINS (32U) -#define NTREEBINS (32U) -#define SMALLBIN_SHIFT (3U) -#define SMALLBIN_WIDTH (SIZE_T_ONE << SMALLBIN_SHIFT) -#define TREEBIN_SHIFT (8U) -#define MIN_LARGE_SIZE (SIZE_T_ONE << TREEBIN_SHIFT) -#define MAX_SMALL_SIZE (MIN_LARGE_SIZE - SIZE_T_ONE) -#define MAX_SMALL_REQUEST (MAX_SMALL_SIZE - CHUNK_ALIGN_MASK - CHUNK_OVERHEAD) - -struct malloc_state { - binmap_t smallmap; - binmap_t treemap; - size_t dvsize; - size_t topsize; - char* least_addr; - mchunkptr dv; - mchunkptr top; - size_t trim_check; - size_t release_checks; - size_t magic; - mchunkptr smallbins[(NSMALLBINS+1)*2]; - tbinptr treebins[NTREEBINS]; - size_t footprint; - size_t max_footprint; - size_t footprint_limit; /* zero means no limit */ - flag_t mflags; -#if USE_LOCKS - MLOCK_T mutex; /* locate lock among fields that rarely change */ -#endif /* USE_LOCKS */ - msegment seg; - void* extp; /* Unused but available for extensions */ - size_t exts; -}; - -typedef struct malloc_state* mstate; - -/* ------------- Global malloc_state and malloc_params ------------------- */ - -/* - malloc_params holds global properties, including those that can be - dynamically set using mallopt. There is a single instance, mparams, - initialized in init_mparams. Note that the non-zeroness of "magic" - also serves as an initialization flag. -*/ - -struct malloc_params { - size_t magic; - size_t page_size; - size_t granularity; - size_t mmap_threshold; - size_t trim_threshold; - flag_t default_mflags; -}; - -static struct malloc_params mparams; - -/* Ensure mparams initialized */ -#define ensure_initialization() (void)(mparams.magic != 0 || init_mparams()) - -#if !ONLY_MSPACES - -/* The global malloc_state used for all non-"mspace" calls */ -static struct malloc_state _gm_; -#define gm (&_gm_) -#define is_global(M) ((M) == &_gm_) - -#endif /* !ONLY_MSPACES */ - -#define is_initialized(M) ((M)->top != 0) - -/* -------------------------- system alloc setup ------------------------- */ - -/* Operations on mflags */ - -#define use_lock(M) ((M)->mflags & USE_LOCK_BIT) -#define enable_lock(M) ((M)->mflags |= USE_LOCK_BIT) -#if USE_LOCKS -#define disable_lock(M) ((M)->mflags &= ~USE_LOCK_BIT) -#else -#define disable_lock(M) -#endif - -#define use_mmap(M) ((M)->mflags & USE_MMAP_BIT) -#define enable_mmap(M) ((M)->mflags |= USE_MMAP_BIT) -#if HAVE_MMAP -#define disable_mmap(M) ((M)->mflags &= ~USE_MMAP_BIT) -#else -#define disable_mmap(M) -#endif - -#define use_noncontiguous(M) ((M)->mflags & USE_NONCONTIGUOUS_BIT) -#define disable_contiguous(M) ((M)->mflags |= USE_NONCONTIGUOUS_BIT) - -#define set_lock(M,L)\ - ((M)->mflags = (L)?\ - ((M)->mflags | USE_LOCK_BIT) :\ - ((M)->mflags & ~USE_LOCK_BIT)) - -/* page-align a size */ -#define page_align(S)\ - (((S) + (mparams.page_size - SIZE_T_ONE)) & ~(mparams.page_size - SIZE_T_ONE)) - -/* granularity-align a size */ -#define granularity_align(S)\ - (((S) + (mparams.granularity - SIZE_T_ONE))\ - & ~(mparams.granularity - SIZE_T_ONE)) - - -/* For mmap, use granularity alignment on windows, else page-align */ -#ifdef WIN32 -#define mmap_align(S) granularity_align(S) -#else -#define mmap_align(S) page_align(S) -#endif - -/* For sys_alloc, enough padding to ensure can malloc request on success */ -#define SYS_ALLOC_PADDING (TOP_FOOT_SIZE + MALLOC_ALIGNMENT) - -#define is_page_aligned(S)\ - (((size_t)(S) & (mparams.page_size - SIZE_T_ONE)) == 0) -#define is_granularity_aligned(S)\ - (((size_t)(S) & (mparams.granularity - SIZE_T_ONE)) == 0) - -/* True if segment S holds address A */ -#define segment_holds(S, A)\ - ((char*)(A) >= S->base && (char*)(A) < S->base + S->size) - -/* Return segment holding given address */ -static msegmentptr segment_holding(mstate m, char* addr) { - msegmentptr sp = &m->seg; - for (;;) { - if (addr >= sp->base && addr < sp->base + sp->size) - return sp; - if ((sp = sp->next) == 0) - return 0; - } -} - -/* Return true if segment contains a segment link */ -static int has_segment_link(mstate m, msegmentptr ss) { - msegmentptr sp = &m->seg; - for (;;) { - if ((char*)sp >= ss->base && (char*)sp < ss->base + ss->size) - return 1; - if ((sp = sp->next) == 0) - return 0; - } -} - -#ifndef MORECORE_CANNOT_TRIM -#define should_trim(M,s) ((s) > (M)->trim_check) -#else /* MORECORE_CANNOT_TRIM */ -#define should_trim(M,s) (0) -#endif /* MORECORE_CANNOT_TRIM */ - -/* - TOP_FOOT_SIZE is padding at the end of a segment, including space - that may be needed to place segment records and fenceposts when new - noncontiguous segments are added. -*/ -#define TOP_FOOT_SIZE\ - (align_offset(chunk2mem(0))+pad_request(sizeof(struct malloc_segment))+MIN_CHUNK_SIZE) - - -/* ------------------------------- Hooks -------------------------------- */ - -/* - PREACTION should be defined to return 0 on success, and nonzero on - failure. If you are not using locking, you can redefine these to do - anything you like. -*/ - -#if USE_LOCKS -#define PREACTION(M) ((use_lock(M))? ACQUIRE_LOCK(&(M)->mutex) : 0) -#define POSTACTION(M) { if (use_lock(M)) RELEASE_LOCK(&(M)->mutex); } -#else /* USE_LOCKS */ - -#ifndef PREACTION -#define PREACTION(M) (0) -#endif /* PREACTION */ - -#ifndef POSTACTION -#define POSTACTION(M) -#endif /* POSTACTION */ - -#endif /* USE_LOCKS */ - -/* - CORRUPTION_ERROR_ACTION is triggered upon detected bad addresses. - USAGE_ERROR_ACTION is triggered on detected bad frees and - reallocs. The argument p is an address that might have triggered the - fault. It is ignored by the two predefined actions, but might be - useful in custom actions that try to help diagnose errors. -*/ - -#if PROCEED_ON_ERROR - -/* A count of the number of corruption errors causing resets */ -int malloc_corruption_error_count; - -/* default corruption action */ -static void reset_on_error(mstate m); - -#define CORRUPTION_ERROR_ACTION(m) reset_on_error(m) -#define USAGE_ERROR_ACTION(m, p) - -#else /* PROCEED_ON_ERROR */ - -#ifndef CORRUPTION_ERROR_ACTION -#define CORRUPTION_ERROR_ACTION(m) ABORT -#endif /* CORRUPTION_ERROR_ACTION */ - -#ifndef USAGE_ERROR_ACTION -#define USAGE_ERROR_ACTION(m,p) ABORT -#endif /* USAGE_ERROR_ACTION */ - -#endif /* PROCEED_ON_ERROR */ - - -/* -------------------------- Debugging setup ---------------------------- */ - -#if ! DEBUG - -#define check_free_chunk(M,P) -#define check_inuse_chunk(M,P) -#define check_malloced_chunk(M,P,N) -#define check_mmapped_chunk(M,P) -#define check_malloc_state(M) -#define check_top_chunk(M,P) - -#else /* DEBUG */ -#define check_free_chunk(M,P) do_check_free_chunk(M,P) -#define check_inuse_chunk(M,P) do_check_inuse_chunk(M,P) -#define check_top_chunk(M,P) do_check_top_chunk(M,P) -#define check_malloced_chunk(M,P,N) do_check_malloced_chunk(M,P,N) -#define check_mmapped_chunk(M,P) do_check_mmapped_chunk(M,P) -#define check_malloc_state(M) do_check_malloc_state(M) - -static void do_check_any_chunk(mstate m, mchunkptr p); -static void do_check_top_chunk(mstate m, mchunkptr p); -static void do_check_mmapped_chunk(mstate m, mchunkptr p); -static void do_check_inuse_chunk(mstate m, mchunkptr p); -static void do_check_free_chunk(mstate m, mchunkptr p); -static void do_check_malloced_chunk(mstate m, void* mem, size_t s); -static void do_check_tree(mstate m, tchunkptr t); -static void do_check_treebin(mstate m, bindex_t i); -static void do_check_smallbin(mstate m, bindex_t i); -static void do_check_malloc_state(mstate m); -static int bin_find(mstate m, mchunkptr x); -static size_t traverse_and_check(mstate m); -#endif /* DEBUG */ - -/* ---------------------------- Indexing Bins ---------------------------- */ - -#define is_small(s) (((s) >> SMALLBIN_SHIFT) < NSMALLBINS) -#define small_index(s) (bindex_t)((s) >> SMALLBIN_SHIFT) -#define small_index2size(i) ((i) << SMALLBIN_SHIFT) -#define MIN_SMALL_INDEX (small_index(MIN_CHUNK_SIZE)) - -/* addressing by index. See above about smallbin repositioning */ -#define smallbin_at(M, i) ((sbinptr)((char*)&((M)->smallbins[(i)<<1]))) -#define treebin_at(M,i) (&((M)->treebins[i])) - -/* assign tree index for size S to variable I. Use x86 asm if possible */ -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -#define compute_tree_index(S, I)\ -{\ - unsigned int X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int K = (unsigned) sizeof(X)*__CHAR_BIT__ - 1 - (unsigned) __builtin_clz(X); \ - I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ - }\ -} - -#elif defined (__INTEL_COMPILER) -#define compute_tree_index(S, I)\ -{\ - size_t X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int K = _bit_scan_reverse (X); \ - I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ - }\ -} - -#elif defined(_MSC_VER) && _MSC_VER>=1300 -#define compute_tree_index(S, I)\ -{\ - size_t X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int K;\ - _BitScanReverse((DWORD *) &K, (DWORD) X);\ - I = (bindex_t)((K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1)));\ - }\ -} - -#else /* GNUC */ -#define compute_tree_index(S, I)\ -{\ - size_t X = S >> TREEBIN_SHIFT;\ - if (X == 0)\ - I = 0;\ - else if (X > 0xFFFF)\ - I = NTREEBINS-1;\ - else {\ - unsigned int Y = (unsigned int)X;\ - unsigned int N = ((Y - 0x100) >> 16) & 8;\ - unsigned int K = (((Y <<= N) - 0x1000) >> 16) & 4;\ - N += K;\ - N += K = (((Y <<= K) - 0x4000) >> 16) & 2;\ - K = 14 - N + ((Y <<= K) >> 15);\ - I = (K << 1) + ((S >> (K + (TREEBIN_SHIFT-1)) & 1));\ - }\ -} -#endif /* GNUC */ - -/* Bit representing maximum resolved size in a treebin at i */ -#define bit_for_tree_index(i) \ - (i == NTREEBINS-1)? (SIZE_T_BITSIZE-1) : (((i) >> 1) + TREEBIN_SHIFT - 2) - -/* Shift placing maximum resolved bit in a treebin at i as sign bit */ -#define leftshift_for_tree_index(i) \ - ((i == NTREEBINS-1)? 0 : \ - ((SIZE_T_BITSIZE-SIZE_T_ONE) - (((i) >> 1) + TREEBIN_SHIFT - 2))) - -/* The size of the smallest chunk held in bin with index i */ -#define minsize_for_tree_index(i) \ - ((SIZE_T_ONE << (((i) >> 1) + TREEBIN_SHIFT)) | \ - (((size_t)((i) & SIZE_T_ONE)) << (((i) >> 1) + TREEBIN_SHIFT - 1))) - - -/* ------------------------ Operations on bin maps ----------------------- */ - -/* bit corresponding to given index */ -#define idx2bit(i) ((binmap_t)(1) << (i)) - -/* Mark/Clear bits with given index */ -#define mark_smallmap(M,i) ((M)->smallmap |= idx2bit(i)) -#define clear_smallmap(M,i) ((M)->smallmap &= ~idx2bit(i)) -#define smallmap_is_marked(M,i) ((M)->smallmap & idx2bit(i)) - -#define mark_treemap(M,i) ((M)->treemap |= idx2bit(i)) -#define clear_treemap(M,i) ((M)->treemap &= ~idx2bit(i)) -#define treemap_is_marked(M,i) ((M)->treemap & idx2bit(i)) - -/* isolate the least set bit of a bitmap */ -#define least_bit(x) ((x) & -(x)) - -/* mask with all bits to left of least bit of x on */ -#define left_bits(x) ((x<<1) | -(x<<1)) - -/* mask with all bits to left of or equal to least bit of x on */ -#define same_or_left_bits(x) ((x) | -(x)) - -/* index corresponding to given bit. Use x86 asm if possible */ - -#if defined(__GNUC__) && (defined(__i386__) || defined(__x86_64__)) -#define compute_bit2idx(X, I)\ -{\ - unsigned int J;\ - J = __builtin_ctz(X); \ - I = (bindex_t)J;\ -} - -#elif defined (__INTEL_COMPILER) -#define compute_bit2idx(X, I)\ -{\ - unsigned int J;\ - J = _bit_scan_forward (X); \ - I = (bindex_t)J;\ -} - -#elif defined(_MSC_VER) && _MSC_VER>=1300 -#define compute_bit2idx(X, I)\ -{\ - unsigned int J;\ - _BitScanForward((DWORD *) &J, X);\ - I = (bindex_t)J;\ -} - -#elif USE_BUILTIN_FFS -#define compute_bit2idx(X, I) I = ffs(X)-1 - -#else -#define compute_bit2idx(X, I)\ -{\ - unsigned int Y = X - 1;\ - unsigned int K = Y >> (16-4) & 16;\ - unsigned int N = K; Y >>= K;\ - N += K = Y >> (8-3) & 8; Y >>= K;\ - N += K = Y >> (4-2) & 4; Y >>= K;\ - N += K = Y >> (2-1) & 2; Y >>= K;\ - N += K = Y >> (1-0) & 1; Y >>= K;\ - I = (bindex_t)(N + Y);\ -} -#endif /* GNUC */ - - -/* ----------------------- Runtime Check Support ------------------------- */ - -/* - For security, the main invariant is that malloc/free/etc never - writes to a static address other than malloc_state, unless static - malloc_state itself has been corrupted, which cannot occur via - malloc (because of these checks). In essence this means that we - believe all pointers, sizes, maps etc held in malloc_state, but - check all of those linked or offsetted from other embedded data - structures. These checks are interspersed with main code in a way - that tends to minimize their run-time cost. - - When FOOTERS is defined, in addition to range checking, we also - verify footer fields of inuse chunks, which can be used guarantee - that the mstate controlling malloc/free is intact. This is a - streamlined version of the approach described by William Robertson - et al in "Run-time Detection of Heap-based Overflows" LISA'03 - http://www.usenix.org/events/lisa03/tech/robertson.html The footer - of an inuse chunk holds the xor of its mstate and a random seed, - that is checked upon calls to free() and realloc(). This is - (probabalistically) unguessable from outside the program, but can be - computed by any code successfully malloc'ing any chunk, so does not - itself provide protection against code that has already broken - security through some other means. Unlike Robertson et al, we - always dynamically check addresses of all offset chunks (previous, - next, etc). This turns out to be cheaper than relying on hashes. -*/ - -#if !INSECURE -/* Check if address a is at least as high as any from MORECORE or MMAP */ -#define ok_address(M, a) ((char*)(a) >= (M)->least_addr) -/* Check if address of next chunk n is higher than base chunk p */ -#define ok_next(p, n) ((char*)(p) < (char*)(n)) -/* Check if p has inuse status */ -#define ok_inuse(p) is_inuse(p) -/* Check if p has its pinuse bit on */ -#define ok_pinuse(p) pinuse(p) - -#else /* !INSECURE */ -#define ok_address(M, a) (1) -#define ok_next(b, n) (1) -#define ok_inuse(p) (1) -#define ok_pinuse(p) (1) -#endif /* !INSECURE */ - -#if (FOOTERS && !INSECURE) -/* Check if (alleged) mstate m has expected magic field */ -#define ok_magic(M) ((M)->magic == mparams.magic) -#else /* (FOOTERS && !INSECURE) */ -#define ok_magic(M) (1) -#endif /* (FOOTERS && !INSECURE) */ - -/* In gcc, use __builtin_expect to minimize impact of checks */ -#if !INSECURE -#if defined(__GNUC__) && __GNUC__ >= 3 -#define RTCHECK(e) __builtin_expect(e, 1) -#else /* GNUC */ -#define RTCHECK(e) (e) -#endif /* GNUC */ -#else /* !INSECURE */ -#define RTCHECK(e) (1) -#endif /* !INSECURE */ - -/* macros to set up inuse chunks with or without footers */ - -#if !FOOTERS - -#define mark_inuse_foot(M,p,s) - -/* Macros for setting head/foot of non-mmapped chunks */ - -/* Set cinuse bit and pinuse bit of next chunk */ -#define set_inuse(M,p,s)\ - ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ - ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) - -/* Set cinuse and pinuse of this chunk and pinuse of next chunk */ -#define set_inuse_and_pinuse(M,p,s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - ((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT) - -/* Set size, cinuse and pinuse bit of this chunk */ -#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT)) - -#else /* FOOTERS */ - -/* Set foot of inuse chunk to be xor of mstate and seed */ -#define mark_inuse_foot(M,p,s)\ - (((mchunkptr)((char*)(p) + (s)))->prev_foot = ((size_t)(M) ^ mparams.magic)) - -#define get_mstate_for(p)\ - ((mstate)(((mchunkptr)((char*)(p) +\ - (chunksize(p))))->prev_foot ^ mparams.magic)) - -#define set_inuse(M,p,s)\ - ((p)->head = (((p)->head & PINUSE_BIT)|s|CINUSE_BIT),\ - (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT), \ - mark_inuse_foot(M,p,s)) - -#define set_inuse_and_pinuse(M,p,s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - (((mchunkptr)(((char*)(p)) + (s)))->head |= PINUSE_BIT),\ - mark_inuse_foot(M,p,s)) - -#define set_size_and_pinuse_of_inuse_chunk(M, p, s)\ - ((p)->head = (s|PINUSE_BIT|CINUSE_BIT),\ - mark_inuse_foot(M, p, s)) - -#endif /* !FOOTERS */ - -/* ---------------------------- setting mparams -------------------------- */ - -#if LOCK_AT_FORK -static void pre_fork(void) { ACQUIRE_LOCK(&(gm)->mutex); } -static void post_fork_parent(void) { RELEASE_LOCK(&(gm)->mutex); } -static void post_fork_child(void) { INITIAL_LOCK(&(gm)->mutex); } -#endif /* LOCK_AT_FORK */ - -/* Initialize mparams */ -static int init_mparams(void) { -#ifdef NEED_GLOBAL_LOCK_INIT - if (malloc_global_mutex_status <= 0) - init_malloc_global_mutex(); -#endif - - ACQUIRE_MALLOC_GLOBAL_LOCK(); - if (mparams.magic == 0) { - size_t magic; - size_t psize; - size_t gsize; - -#ifndef WIN32 - psize = malloc_getpagesize; - gsize = ((DEFAULT_GRANULARITY != 0)? DEFAULT_GRANULARITY : psize); -#else /* WIN32 */ - { - SYSTEM_INFO system_info; - GetSystemInfo(&system_info); - psize = system_info.dwPageSize; - gsize = ((DEFAULT_GRANULARITY != 0)? - DEFAULT_GRANULARITY : system_info.dwAllocationGranularity); - } -#endif /* WIN32 */ - - /* Sanity-check configuration: - size_t must be unsigned and as wide as pointer type. - ints must be at least 4 bytes. - alignment must be at least 8. - Alignment, min chunk size, and page size must all be powers of 2. - */ - if ((sizeof(size_t) != sizeof(char*)) || - (MAX_SIZE_T < MIN_CHUNK_SIZE) || - (sizeof(int) < 4) || - (MALLOC_ALIGNMENT < (size_t)8U) || - ((MALLOC_ALIGNMENT & (MALLOC_ALIGNMENT-SIZE_T_ONE)) != 0) || - ((MCHUNK_SIZE & (MCHUNK_SIZE-SIZE_T_ONE)) != 0) || - ((gsize & (gsize-SIZE_T_ONE)) != 0) || - ((psize & (psize-SIZE_T_ONE)) != 0)) - ABORT; - mparams.granularity = gsize; - mparams.page_size = psize; - mparams.mmap_threshold = DEFAULT_MMAP_THRESHOLD; - mparams.trim_threshold = DEFAULT_TRIM_THRESHOLD; -#if MORECORE_CONTIGUOUS - mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT; -#else /* MORECORE_CONTIGUOUS */ - mparams.default_mflags = USE_LOCK_BIT|USE_MMAP_BIT|USE_NONCONTIGUOUS_BIT; -#endif /* MORECORE_CONTIGUOUS */ - -#if !ONLY_MSPACES - /* Set up lock for main malloc area */ - gm->mflags = mparams.default_mflags; - (void)INITIAL_LOCK(&gm->mutex); -#endif -#if LOCK_AT_FORK - pthread_atfork(&pre_fork, &post_fork_parent, &post_fork_child); -#endif - - { -#if USE_DEV_RANDOM - int fd; - unsigned char buf[sizeof(size_t)]; - /* Try to use /dev/urandom, else fall back on using time */ - if ((fd = open("/dev/urandom", O_RDONLY)) >= 0 && - read(fd, buf, sizeof(buf)) == sizeof(buf)) { - magic = *((size_t *) buf); - close(fd); - } - else -#endif /* USE_DEV_RANDOM */ -#ifdef WIN32 - magic = (size_t)(GetTickCount() ^ (size_t)0x55555555U); -#elif defined(LACKS_TIME_H) - magic = (size_t)&magic ^ (size_t)0x55555555U; -#else - magic = (size_t)(time(0) ^ (size_t)0x55555555U); -#endif - magic |= (size_t)8U; /* ensure nonzero */ - magic &= ~(size_t)7U; /* improve chances of fault for bad values */ - /* Until memory modes commonly available, use volatile-write */ - (*(volatile size_t *)(&(mparams.magic))) = magic; - } - } - - RELEASE_MALLOC_GLOBAL_LOCK(); - return 1; -} - -/* support for mallopt */ -static int change_mparam(int param_number, int value) { - size_t val; - ensure_initialization(); - val = (value == -1)? MAX_SIZE_T : (size_t)value; - switch(param_number) { - case M_TRIM_THRESHOLD: - mparams.trim_threshold = val; - return 1; - case M_GRANULARITY: - if (val >= mparams.page_size && ((val & (val-1)) == 0)) { - mparams.granularity = val; - return 1; - } - else - return 0; - case M_MMAP_THRESHOLD: - mparams.mmap_threshold = val; - return 1; - default: - return 0; - } -} - -#if DEBUG -/* ------------------------- Debugging Support --------------------------- */ - -/* Check properties of any chunk, whether free, inuse, mmapped etc */ -static void do_check_any_chunk(mstate m, mchunkptr p) { - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); -} - -/* Check properties of top chunk */ -static void do_check_top_chunk(mstate m, mchunkptr p) { - msegmentptr sp = segment_holding(m, (char*)p); - size_t sz = p->head & ~INUSE_BITS; /* third-lowest bit can be set! */ - assert(sp != 0); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(sz == m->topsize); - assert(sz > 0); - assert(sz == ((sp->base + sp->size) - (char*)p) - TOP_FOOT_SIZE); - assert(pinuse(p)); - assert(!pinuse(chunk_plus_offset(p, sz))); -} - -/* Check properties of (inuse) mmapped chunks */ -static void do_check_mmapped_chunk(mstate m, mchunkptr p) { - size_t sz = chunksize(p); - size_t len = (sz + (p->prev_foot) + MMAP_FOOT_PAD); - assert(is_mmapped(p)); - assert(use_mmap(m)); - assert((is_aligned(chunk2mem(p))) || (p->head == FENCEPOST_HEAD)); - assert(ok_address(m, p)); - assert(!is_small(sz)); - assert((len & (mparams.page_size-SIZE_T_ONE)) == 0); - assert(chunk_plus_offset(p, sz)->head == FENCEPOST_HEAD); - assert(chunk_plus_offset(p, sz+SIZE_T_SIZE)->head == 0); -} - -/* Check properties of inuse chunks */ -static void do_check_inuse_chunk(mstate m, mchunkptr p) { - do_check_any_chunk(m, p); - assert(is_inuse(p)); - assert(next_pinuse(p)); - /* If not pinuse and not mmapped, previous chunk has OK offset */ - assert(is_mmapped(p) || pinuse(p) || next_chunk(prev_chunk(p)) == p); - if (is_mmapped(p)) - do_check_mmapped_chunk(m, p); -} - -/* Check properties of free chunks */ -static void do_check_free_chunk(mstate m, mchunkptr p) { - size_t sz = chunksize(p); - mchunkptr next = chunk_plus_offset(p, sz); - do_check_any_chunk(m, p); - assert(!is_inuse(p)); - assert(!next_pinuse(p)); - assert (!is_mmapped(p)); - if (p != m->dv && p != m->top) { - if (sz >= MIN_CHUNK_SIZE) { - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(is_aligned(chunk2mem(p))); - assert(next->prev_foot == sz); - assert(pinuse(p)); - assert (next == m->top || is_inuse(next)); - assert(p->fd->bk == p); - assert(p->bk->fd == p); - } - else /* markers are always of size SIZE_T_SIZE */ - assert(sz == SIZE_T_SIZE); - } -} - -/* Check properties of malloced chunks at the point they are malloced */ -static void do_check_malloced_chunk(mstate m, void* mem, size_t s) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - size_t sz = p->head & ~INUSE_BITS; - do_check_inuse_chunk(m, p); - assert((sz & CHUNK_ALIGN_MASK) == 0); - assert(sz >= MIN_CHUNK_SIZE); - assert(sz >= s); - /* unless mmapped, size is less than MIN_CHUNK_SIZE more than request */ - assert(is_mmapped(p) || sz < (s + MIN_CHUNK_SIZE)); - } -} - -/* Check a tree and its subtrees. */ -static void do_check_tree(mstate m, tchunkptr t) { - tchunkptr head = 0; - tchunkptr u = t; - bindex_t tindex = t->index; - size_t tsize = chunksize(t); - bindex_t idx; - compute_tree_index(tsize, idx); - assert(tindex == idx); - assert(tsize >= MIN_LARGE_SIZE); - assert(tsize >= minsize_for_tree_index(idx)); - assert((idx == NTREEBINS-1) || (tsize < minsize_for_tree_index((idx+1)))); - - do { /* traverse through chain of same-sized nodes */ - do_check_any_chunk(m, ((mchunkptr)u)); - assert(u->index == tindex); - assert(chunksize(u) == tsize); - assert(!is_inuse(u)); - assert(!next_pinuse(u)); - assert(u->fd->bk == u); - assert(u->bk->fd == u); - if (u->parent == 0) { - assert(u->child[0] == 0); - assert(u->child[1] == 0); - } - else { - assert(head == 0); /* only one node on chain has parent */ - head = u; - assert(u->parent != u); - assert (u->parent->child[0] == u || - u->parent->child[1] == u || - *((tbinptr*)(u->parent)) == u); - if (u->child[0] != 0) { - assert(u->child[0]->parent == u); - assert(u->child[0] != u); - do_check_tree(m, u->child[0]); - } - if (u->child[1] != 0) { - assert(u->child[1]->parent == u); - assert(u->child[1] != u); - do_check_tree(m, u->child[1]); - } - if (u->child[0] != 0 && u->child[1] != 0) { - assert(chunksize(u->child[0]) < chunksize(u->child[1])); - } - } - u = u->fd; - } while (u != t); - assert(head != 0); -} - -/* Check all the chunks in a treebin. */ -static void do_check_treebin(mstate m, bindex_t i) { - tbinptr* tb = treebin_at(m, i); - tchunkptr t = *tb; - int empty = (m->treemap & (1U << i)) == 0; - if (t == 0) - assert(empty); - if (!empty) - do_check_tree(m, t); -} - -/* Check all the chunks in a smallbin. */ -static void do_check_smallbin(mstate m, bindex_t i) { - sbinptr b = smallbin_at(m, i); - mchunkptr p = b->bk; - unsigned int empty = (m->smallmap & (1U << i)) == 0; - if (p == b) - assert(empty); - if (!empty) { - for (; p != b; p = p->bk) { - size_t size = chunksize(p); - mchunkptr q; - /* each chunk claims to be free */ - do_check_free_chunk(m, p); - /* chunk belongs in bin */ - assert(small_index(size) == i); - assert(p->bk == b || chunksize(p->bk) == chunksize(p)); - /* chunk is followed by an inuse chunk */ - q = next_chunk(p); - if (q->head != FENCEPOST_HEAD) - do_check_inuse_chunk(m, q); - } - } -} - -/* Find x in a bin. Used in other check functions. */ -static int bin_find(mstate m, mchunkptr x) { - size_t size = chunksize(x); - if (is_small(size)) { - bindex_t sidx = small_index(size); - sbinptr b = smallbin_at(m, sidx); - if (smallmap_is_marked(m, sidx)) { - mchunkptr p = b; - do { - if (p == x) - return 1; - } while ((p = p->fd) != b); - } - } - else { - bindex_t tidx; - compute_tree_index(size, tidx); - if (treemap_is_marked(m, tidx)) { - tchunkptr t = *treebin_at(m, tidx); - size_t sizebits = size << leftshift_for_tree_index(tidx); - while (t != 0 && chunksize(t) != size) { - t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; - sizebits <<= 1; - } - if (t != 0) { - tchunkptr u = t; - do { - if (u == (tchunkptr)x) - return 1; - } while ((u = u->fd) != t); - } - } - } - return 0; -} - -/* Traverse each chunk and check it; return total */ -static size_t traverse_and_check(mstate m) { - size_t sum = 0; - if (is_initialized(m)) { - msegmentptr s = &m->seg; - sum += m->topsize + TOP_FOOT_SIZE; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - mchunkptr lastq = 0; - assert(pinuse(q)); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - sum += chunksize(q); - if (is_inuse(q)) { - assert(!bin_find(m, q)); - do_check_inuse_chunk(m, q); - } - else { - assert(q == m->dv || bin_find(m, q)); - assert(lastq == 0 || is_inuse(lastq)); /* Not 2 consecutive free */ - do_check_free_chunk(m, q); - } - lastq = q; - q = next_chunk(q); - } - s = s->next; - } - } - return sum; -} - - -/* Check all properties of malloc_state. */ -static void do_check_malloc_state(mstate m) { - bindex_t i; - size_t total; - /* check bins */ - for (i = 0; i < NSMALLBINS; ++i) - do_check_smallbin(m, i); - for (i = 0; i < NTREEBINS; ++i) - do_check_treebin(m, i); - - if (m->dvsize != 0) { /* check dv chunk */ - do_check_any_chunk(m, m->dv); - assert(m->dvsize == chunksize(m->dv)); - assert(m->dvsize >= MIN_CHUNK_SIZE); - assert(bin_find(m, m->dv) == 0); - } - - if (m->top != 0) { /* check top chunk */ - do_check_top_chunk(m, m->top); - /*assert(m->topsize == chunksize(m->top)); redundant */ - assert(m->topsize > 0); - assert(bin_find(m, m->top) == 0); - } - - total = traverse_and_check(m); - assert(total <= m->footprint); - assert(m->footprint <= m->max_footprint); -} -#endif /* DEBUG */ - -/* ----------------------------- statistics ------------------------------ */ - -#if !NO_MALLINFO -static struct mallinfo internal_mallinfo(mstate m) { - struct mallinfo nm = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; - ensure_initialization(); - if (!PREACTION(m)) { - check_malloc_state(m); - if (is_initialized(m)) { - size_t nfree = SIZE_T_ONE; /* top always free */ - size_t mfree = m->topsize + TOP_FOOT_SIZE; - size_t sum = mfree; - msegmentptr s = &m->seg; - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - size_t sz = chunksize(q); - sum += sz; - if (!is_inuse(q)) { - mfree += sz; - ++nfree; - } - q = next_chunk(q); - } - s = s->next; - } - - nm.arena = sum; - nm.ordblks = nfree; - nm.hblkhd = m->footprint - sum; - nm.usmblks = m->max_footprint; - nm.uordblks = m->footprint - mfree; - nm.fordblks = mfree; - nm.keepcost = m->topsize; - } - - POSTACTION(m); - } - return nm; -} -#endif /* !NO_MALLINFO */ - -#if !NO_MALLOC_STATS -static void internal_malloc_stats(mstate m) { - ensure_initialization(); - if (!PREACTION(m)) { - size_t maxfp = 0; - size_t fp = 0; - size_t used = 0; - check_malloc_state(m); - if (is_initialized(m)) { - msegmentptr s = &m->seg; - maxfp = m->max_footprint; - fp = m->footprint; - used = fp - (m->topsize + TOP_FOOT_SIZE); - - while (s != 0) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && - q != m->top && q->head != FENCEPOST_HEAD) { - if (!is_inuse(q)) - used -= chunksize(q); - q = next_chunk(q); - } - s = s->next; - } - } - POSTACTION(m); /* drop lock */ - fprintf(stderr, "max system bytes = %10lu\n", (unsigned long)(maxfp)); - fprintf(stderr, "system bytes = %10lu\n", (unsigned long)(fp)); - fprintf(stderr, "in use bytes = %10lu\n", (unsigned long)(used)); - } -} -#endif /* NO_MALLOC_STATS */ - -/* ----------------------- Operations on smallbins ----------------------- */ - -/* - Various forms of linking and unlinking are defined as macros. Even - the ones for trees, which are very long but have very short typical - paths. This is ugly but reduces reliance on inlining support of - compilers. -*/ - -/* Link a free chunk into a smallbin */ -#define insert_small_chunk(M, P, S) {\ - bindex_t I = small_index(S);\ - mchunkptr B = smallbin_at(M, I);\ - mchunkptr F = B;\ - assert(S >= MIN_CHUNK_SIZE);\ - if (!smallmap_is_marked(M, I))\ - mark_smallmap(M, I);\ - else if (RTCHECK(ok_address(M, B->fd)))\ - F = B->fd;\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - B->fd = P;\ - F->bk = P;\ - P->fd = F;\ - P->bk = B;\ -} - -/* Unlink a chunk from a smallbin */ -#define unlink_small_chunk(M, P, S) {\ - mchunkptr F = P->fd;\ - mchunkptr B = P->bk;\ - bindex_t I = small_index(S);\ - assert(P != B);\ - assert(P != F);\ - assert(chunksize(P) == small_index2size(I));\ - if (RTCHECK(F == smallbin_at(M,I) || (ok_address(M, F) && F->bk == P))) { \ - if (B == F) {\ - clear_smallmap(M, I);\ - }\ - else if (RTCHECK(B == smallbin_at(M,I) ||\ - (ok_address(M, B) && B->fd == P))) {\ - F->bk = B;\ - B->fd = F;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ -} - -/* Unlink the first chunk from a smallbin */ -#define unlink_first_small_chunk(M, B, P, I) {\ - mchunkptr F = P->fd;\ - assert(P != B);\ - assert(P != F);\ - assert(chunksize(P) == small_index2size(I));\ - if (B == F) {\ - clear_smallmap(M, I);\ - }\ - else if (RTCHECK(ok_address(M, F) && F->bk == P)) {\ - F->bk = B;\ - B->fd = F;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ -} - -/* Replace dv node, binning the old one */ -/* Used only when dvsize known to be small */ -#define replace_dv(M, P, S) {\ - size_t DVS = M->dvsize;\ - assert(is_small(DVS));\ - if (DVS != 0) {\ - mchunkptr DV = M->dv;\ - insert_small_chunk(M, DV, DVS);\ - }\ - M->dvsize = S;\ - M->dv = P;\ -} - -/* ------------------------- Operations on trees ------------------------- */ - -/* Insert chunk into tree */ -#define insert_large_chunk(M, X, S) {\ - tbinptr* H;\ - bindex_t I;\ - compute_tree_index(S, I);\ - H = treebin_at(M, I);\ - X->index = I;\ - X->child[0] = X->child[1] = 0;\ - if (!treemap_is_marked(M, I)) {\ - mark_treemap(M, I);\ - *H = X;\ - X->parent = (tchunkptr)H;\ - X->fd = X->bk = X;\ - }\ - else {\ - tchunkptr T = *H;\ - size_t K = S << leftshift_for_tree_index(I);\ - for (;;) {\ - if (chunksize(T) != S) {\ - tchunkptr* C = &(T->child[(K >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]);\ - K <<= 1;\ - if (*C != 0)\ - T = *C;\ - else if (RTCHECK(ok_address(M, C))) {\ - *C = X;\ - X->parent = T;\ - X->fd = X->bk = X;\ - break;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - break;\ - }\ - }\ - else {\ - tchunkptr F = T->fd;\ - if (RTCHECK(ok_address(M, T) && ok_address(M, F))) {\ - T->fd = F->bk = X;\ - X->fd = F;\ - X->bk = T;\ - X->parent = 0;\ - break;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - break;\ - }\ - }\ - }\ - }\ -} - -/* - Unlink steps: - - 1. If x is a chained node, unlink it from its same-sized fd/bk links - and choose its bk node as its replacement. - 2. If x was the last node of its size, but not a leaf node, it must - be replaced with a leaf node (not merely one with an open left or - right), to make sure that lefts and rights of descendents - correspond properly to bit masks. We use the rightmost descendent - of x. We could use any other leaf, but this is easy to locate and - tends to counteract removal of leftmosts elsewhere, and so keeps - paths shorter than minimally guaranteed. This doesn't loop much - because on average a node in a tree is near the bottom. - 3. If x is the base of a chain (i.e., has parent links) relink - x's parent and children to x's replacement (or null if none). -*/ - -#define unlink_large_chunk(M, X) {\ - tchunkptr XP = X->parent;\ - tchunkptr R;\ - if (X->bk != X) {\ - tchunkptr F = X->fd;\ - R = X->bk;\ - if (RTCHECK(ok_address(M, F) && F->bk == X && R->fd == X)) {\ - F->bk = R;\ - R->fd = F;\ - }\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - else {\ - tchunkptr* RP;\ - if (((R = *(RP = &(X->child[1]))) != 0) ||\ - ((R = *(RP = &(X->child[0]))) != 0)) {\ - tchunkptr* CP;\ - while ((*(CP = &(R->child[1])) != 0) ||\ - (*(CP = &(R->child[0])) != 0)) {\ - R = *(RP = CP);\ - }\ - if (RTCHECK(ok_address(M, RP)))\ - *RP = 0;\ - else {\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - }\ - if (XP != 0) {\ - tbinptr* H = treebin_at(M, X->index);\ - if (X == *H) {\ - if ((*H = R) == 0) \ - clear_treemap(M, X->index);\ - }\ - else if (RTCHECK(ok_address(M, XP))) {\ - if (XP->child[0] == X) \ - XP->child[0] = R;\ - else \ - XP->child[1] = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - if (R != 0) {\ - if (RTCHECK(ok_address(M, R))) {\ - tchunkptr C0, C1;\ - R->parent = XP;\ - if ((C0 = X->child[0]) != 0) {\ - if (RTCHECK(ok_address(M, C0))) {\ - R->child[0] = C0;\ - C0->parent = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - if ((C1 = X->child[1]) != 0) {\ - if (RTCHECK(ok_address(M, C1))) {\ - R->child[1] = C1;\ - C1->parent = R;\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ - else\ - CORRUPTION_ERROR_ACTION(M);\ - }\ - }\ -} - -/* Relays to large vs small bin operations */ - -#define insert_chunk(M, P, S)\ - if (is_small(S)) insert_small_chunk(M, P, S)\ - else { tchunkptr TP = (tchunkptr)(P); insert_large_chunk(M, TP, S); } - -#define unlink_chunk(M, P, S)\ - if (is_small(S)) unlink_small_chunk(M, P, S)\ - else { tchunkptr TP = (tchunkptr)(P); unlink_large_chunk(M, TP); } - - -/* Relays to internal calls to malloc/free from realloc, memalign etc */ - -#if ONLY_MSPACES -#define internal_malloc(m, b) mspace_malloc(m, b) -#define internal_free(m, mem) mspace_free(m,mem); -#else /* ONLY_MSPACES */ -#if MSPACES -#define internal_malloc(m, b)\ - ((m == gm)? dlmalloc(b) : mspace_malloc(m, b)) -#define internal_free(m, mem)\ - if (m == gm) dlfree(mem); else mspace_free(m,mem); -#else /* MSPACES */ -#define internal_malloc(m, b) dlmalloc(b) -#define internal_free(m, mem) dlfree(mem) -#endif /* MSPACES */ -#endif /* ONLY_MSPACES */ - -/* ----------------------- Direct-mmapping chunks ----------------------- */ - -/* - Directly mmapped chunks are set up with an offset to the start of - the mmapped region stored in the prev_foot field of the chunk. This - allows reconstruction of the required argument to MUNMAP when freed, - and also allows adjustment of the returned chunk to meet alignment - requirements (especially in memalign). -*/ - -/* Malloc using mmap */ -static void* mmap_alloc(mstate m, size_t nb) { - size_t mmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - if (m->footprint_limit != 0) { - size_t fp = m->footprint + mmsize; - if (fp <= m->footprint || fp > m->footprint_limit) - return 0; - } - if (mmsize > nb) { /* Check for wrap around 0 */ - char* mm = (char*)(CALL_DIRECT_MMAP(mmsize)); - if (mm != CMFAIL) { - size_t offset = align_offset(chunk2mem(mm)); - size_t psize = mmsize - offset - MMAP_FOOT_PAD; - mchunkptr p = (mchunkptr)(mm + offset); - p->prev_foot = offset; - p->head = psize; - mark_inuse_foot(m, p, psize); - chunk_plus_offset(p, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(p, psize+SIZE_T_SIZE)->head = 0; - - if (m->least_addr == 0 || mm < m->least_addr) - m->least_addr = mm; - if ((m->footprint += mmsize) > m->max_footprint) - m->max_footprint = m->footprint; - assert(is_aligned(chunk2mem(p))); - check_mmapped_chunk(m, p); - return chunk2mem(p); - } - } - return 0; -} - -/* Realloc using mmap */ -static mchunkptr mmap_resize(mstate m, mchunkptr oldp, size_t nb, int flags) { - size_t oldsize = chunksize(oldp); - (void)flags; /* placate people compiling -Wunused */ - if (is_small(nb)) /* Can't shrink mmap regions below small size */ - return 0; - /* Keep old chunk if big enough but not too big */ - if (oldsize >= nb + SIZE_T_SIZE && - (oldsize - nb) <= (mparams.granularity << 1)) - return oldp; - else { - size_t offset = oldp->prev_foot; - size_t oldmmsize = oldsize + offset + MMAP_FOOT_PAD; - size_t newmmsize = mmap_align(nb + SIX_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - char* cp = (char*)CALL_MREMAP((char*)oldp - offset, - oldmmsize, newmmsize, flags); - if (cp != CMFAIL) { - mchunkptr newp = (mchunkptr)(cp + offset); - size_t psize = newmmsize - offset - MMAP_FOOT_PAD; - newp->head = psize; - mark_inuse_foot(m, newp, psize); - chunk_plus_offset(newp, psize)->head = FENCEPOST_HEAD; - chunk_plus_offset(newp, psize+SIZE_T_SIZE)->head = 0; - - if (cp < m->least_addr) - m->least_addr = cp; - if ((m->footprint += newmmsize - oldmmsize) > m->max_footprint) - m->max_footprint = m->footprint; - check_mmapped_chunk(m, newp); - return newp; - } - } - return 0; -} - - -/* -------------------------- mspace management -------------------------- */ - -/* Initialize top chunk and its size */ -static void init_top(mstate m, mchunkptr p, size_t psize) { - /* Ensure alignment */ - size_t offset = align_offset(chunk2mem(p)); - p = (mchunkptr)((char*)p + offset); - psize -= offset; - - m->top = p; - m->topsize = psize; - p->head = psize | PINUSE_BIT; - /* set size of fake trailing chunk holding overhead space only once */ - chunk_plus_offset(p, psize)->head = TOP_FOOT_SIZE; - m->trim_check = mparams.trim_threshold; /* reset on each update */ -} - -/* Initialize bins for a new mstate that is otherwise zeroed out */ -static void init_bins(mstate m) { - /* Establish circular links for smallbins */ - bindex_t i; - for (i = 0; i < NSMALLBINS; ++i) { - sbinptr bin = smallbin_at(m,i); - bin->fd = bin->bk = bin; - } -} - -#if PROCEED_ON_ERROR - -/* default corruption action */ -static void reset_on_error(mstate m) { - int i; - ++malloc_corruption_error_count; - /* Reinitialize fields to forget about all memory */ - m->smallmap = m->treemap = 0; - m->dvsize = m->topsize = 0; - m->seg.base = 0; - m->seg.size = 0; - m->seg.next = 0; - m->top = m->dv = 0; - for (i = 0; i < NTREEBINS; ++i) - *treebin_at(m, i) = 0; - init_bins(m); -} -#endif /* PROCEED_ON_ERROR */ - -/* Allocate chunk and prepend remainder with chunk in successor base. */ -static void* prepend_alloc(mstate m, char* newbase, char* oldbase, - size_t nb) { - mchunkptr p = align_as_chunk(newbase); - mchunkptr oldfirst = align_as_chunk(oldbase); - size_t psize = (char*)oldfirst - (char*)p; - mchunkptr q = chunk_plus_offset(p, nb); - size_t qsize = psize - nb; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - - assert((char*)oldfirst > (char*)q); - assert(pinuse(oldfirst)); - assert(qsize >= MIN_CHUNK_SIZE); - - /* consolidate remainder with first chunk of old base */ - if (oldfirst == m->top) { - size_t tsize = m->topsize += qsize; - m->top = q; - q->head = tsize | PINUSE_BIT; - check_top_chunk(m, q); - } - else if (oldfirst == m->dv) { - size_t dsize = m->dvsize += qsize; - m->dv = q; - set_size_and_pinuse_of_free_chunk(q, dsize); - } - else { - if (!is_inuse(oldfirst)) { - size_t nsize = chunksize(oldfirst); - unlink_chunk(m, oldfirst, nsize); - oldfirst = chunk_plus_offset(oldfirst, nsize); - qsize += nsize; - } - set_free_with_pinuse(q, qsize, oldfirst); - insert_chunk(m, q, qsize); - check_free_chunk(m, q); - } - - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); -} - -/* Add a segment to hold a new noncontiguous region */ -static void add_segment(mstate m, char* tbase, size_t tsize, flag_t mmapped) { - /* Determine locations and sizes of segment, fenceposts, old top */ - char* old_top = (char*)m->top; - msegmentptr oldsp = segment_holding(m, old_top); - char* old_end = oldsp->base + oldsp->size; - size_t ssize = pad_request(sizeof(struct malloc_segment)); - char* rawsp = old_end - (ssize + FOUR_SIZE_T_SIZES + CHUNK_ALIGN_MASK); - size_t offset = align_offset(chunk2mem(rawsp)); - char* asp = rawsp + offset; - char* csp = (asp < (old_top + MIN_CHUNK_SIZE))? old_top : asp; - mchunkptr sp = (mchunkptr)csp; - msegmentptr ss = (msegmentptr)(chunk2mem(sp)); - mchunkptr tnext = chunk_plus_offset(sp, ssize); - mchunkptr p = tnext; - int nfences = 0; - - /* reset top to new space */ - init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); - - /* Set up segment record */ - assert(is_aligned(ss)); - set_size_and_pinuse_of_inuse_chunk(m, sp, ssize); - *ss = m->seg; /* Push current record */ - m->seg.base = tbase; - m->seg.size = tsize; - m->seg.sflags = mmapped; - m->seg.next = ss; - - /* Insert trailing fenceposts */ - for (;;) { - mchunkptr nextp = chunk_plus_offset(p, SIZE_T_SIZE); - p->head = FENCEPOST_HEAD; - ++nfences; - if ((char*)(&(nextp->head)) < old_end) - p = nextp; - else - break; - } - assert(nfences >= 2); - - /* Insert the rest of old top into a bin as an ordinary free chunk */ - if (csp != old_top) { - mchunkptr q = (mchunkptr)old_top; - size_t psize = csp - old_top; - mchunkptr tn = chunk_plus_offset(q, psize); - set_free_with_pinuse(q, psize, tn); - insert_chunk(m, q, psize); - } - - check_top_chunk(m, m->top); -} - -/* -------------------------- System allocation -------------------------- */ - -/* Get memory from system using MORECORE or MMAP */ -static void* sys_alloc(mstate m, size_t nb) { - char* tbase = CMFAIL; - size_t tsize = 0; - flag_t mmap_flag = 0; - size_t asize; /* allocation size */ - - ensure_initialization(); - - /* Directly map large chunks, but only if already initialized */ - if (use_mmap(m) && nb >= mparams.mmap_threshold && m->topsize != 0) { - void* mem = mmap_alloc(m, nb); - if (mem != 0) - return mem; - } - - asize = granularity_align(nb + SYS_ALLOC_PADDING); - if (asize <= nb) - return 0; /* wraparound */ - if (m->footprint_limit != 0) { - size_t fp = m->footprint + asize; - if (fp <= m->footprint || fp > m->footprint_limit) - return 0; - } - - /* - Try getting memory in any of three ways (in most-preferred to - least-preferred order): - 1. A call to MORECORE that can normally contiguously extend memory. - (disabled if not MORECORE_CONTIGUOUS or not HAVE_MORECORE or - or main space is mmapped or a previous contiguous call failed) - 2. A call to MMAP new space (disabled if not HAVE_MMAP). - Note that under the default settings, if MORECORE is unable to - fulfill a request, and HAVE_MMAP is true, then mmap is - used as a noncontiguous system allocator. This is a useful backup - strategy for systems with holes in address spaces -- in this case - sbrk cannot contiguously expand the heap, but mmap may be able to - find space. - 3. A call to MORECORE that cannot usually contiguously extend memory. - (disabled if not HAVE_MORECORE) - - In all cases, we need to request enough bytes from system to ensure - we can malloc nb bytes upon success, so pad with enough space for - top_foot, plus alignment-pad to make sure we don't lose bytes if - not on boundary, and round this up to a granularity unit. - */ - - if (MORECORE_CONTIGUOUS && !use_noncontiguous(m)) { - char* br = CMFAIL; - size_t ssize = asize; /* sbrk call size */ - msegmentptr ss = (m->top == 0)? 0 : segment_holding(m, (char*)m->top); - ACQUIRE_MALLOC_GLOBAL_LOCK(); - - if (ss == 0) { /* First time through or recovery */ - char* base = (char*)CALL_MORECORE(0); - if (base != CMFAIL) { - size_t fp; - /* Adjust to end on a page boundary */ - if (!is_page_aligned(base)) - ssize += (page_align((size_t)base) - (size_t)base); - fp = m->footprint + ssize; /* recheck limits */ - if (ssize > nb && ssize < HALF_MAX_SIZE_T && - (m->footprint_limit == 0 || - (fp > m->footprint && fp <= m->footprint_limit)) && - (br = (char*)(CALL_MORECORE(ssize))) == base) { - tbase = base; - tsize = ssize; - } - } - } - else { - /* Subtract out existing available top space from MORECORE request. */ - ssize = granularity_align(nb - m->topsize + SYS_ALLOC_PADDING); - /* Use mem here only if it did continuously extend old space */ - if (ssize < HALF_MAX_SIZE_T && - (br = (char*)(CALL_MORECORE(ssize))) == ss->base+ss->size) { - tbase = br; - tsize = ssize; - } - } - - if (tbase == CMFAIL) { /* Cope with partial failure */ - if (br != CMFAIL) { /* Try to use/extend the space we did get */ - if (ssize < HALF_MAX_SIZE_T && - ssize < nb + SYS_ALLOC_PADDING) { - size_t esize = granularity_align(nb + SYS_ALLOC_PADDING - ssize); - if (esize < HALF_MAX_SIZE_T) { - char* end = (char*)CALL_MORECORE(esize); - if (end != CMFAIL) - ssize += esize; - else { /* Can't use; try to release */ - (void) CALL_MORECORE(-ssize); - br = CMFAIL; - } - } - } - } - if (br != CMFAIL) { /* Use the space we did get */ - tbase = br; - tsize = ssize; - } - else - disable_contiguous(m); /* Don't try contiguous path in the future */ - } - - RELEASE_MALLOC_GLOBAL_LOCK(); - } - - if (HAVE_MMAP && tbase == CMFAIL) { /* Try MMAP */ - char* mp = (char*)(CALL_MMAP(asize)); - if (mp != CMFAIL) { - tbase = mp; - tsize = asize; - mmap_flag = USE_MMAP_BIT; - } - } - - if (HAVE_MORECORE && tbase == CMFAIL) { /* Try noncontiguous MORECORE */ - if (asize < HALF_MAX_SIZE_T) { - char* br = CMFAIL; - char* end = CMFAIL; - ACQUIRE_MALLOC_GLOBAL_LOCK(); - br = (char*)(CALL_MORECORE(asize)); - end = (char*)(CALL_MORECORE(0)); - RELEASE_MALLOC_GLOBAL_LOCK(); - if (br != CMFAIL && end != CMFAIL && br < end) { - size_t ssize = end - br; - if (ssize > nb + TOP_FOOT_SIZE) { - tbase = br; - tsize = ssize; - } - } - } - } - - if (tbase != CMFAIL) { - - if ((m->footprint += tsize) > m->max_footprint) - m->max_footprint = m->footprint; - - if (!is_initialized(m)) { /* first-time initialization */ - if (m->least_addr == 0 || tbase < m->least_addr) - m->least_addr = tbase; - m->seg.base = tbase; - m->seg.size = tsize; - m->seg.sflags = mmap_flag; - m->magic = mparams.magic; - m->release_checks = MAX_RELEASE_CHECK_RATE; - init_bins(m); -#if !ONLY_MSPACES - if (is_global(m)) - init_top(m, (mchunkptr)tbase, tsize - TOP_FOOT_SIZE); - else -#endif - { - /* Offset top by embedded malloc_state */ - mchunkptr mn = next_chunk(mem2chunk(m)); - init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) -TOP_FOOT_SIZE); - } - } - - else { - /* Try to merge with an existing segment */ - msegmentptr sp = &m->seg; - /* Only consider most recent segment if traversal suppressed */ - while (sp != 0 && tbase != sp->base + sp->size) - sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; - if (sp != 0 && - !is_extern_segment(sp) && - (sp->sflags & USE_MMAP_BIT) == mmap_flag && - segment_holds(sp, m->top)) { /* append */ - sp->size += tsize; - init_top(m, m->top, m->topsize + tsize); - } - else { - if (tbase < m->least_addr) - m->least_addr = tbase; - sp = &m->seg; - while (sp != 0 && sp->base != tbase + tsize) - sp = (NO_SEGMENT_TRAVERSAL) ? 0 : sp->next; - if (sp != 0 && - !is_extern_segment(sp) && - (sp->sflags & USE_MMAP_BIT) == mmap_flag) { - char* oldbase = sp->base; - sp->base = tbase; - sp->size += tsize; - return prepend_alloc(m, tbase, oldbase, nb); - } - else - add_segment(m, tbase, tsize, mmap_flag); - } - } - - if (nb < m->topsize) { /* Allocate from new or extended top space */ - size_t rsize = m->topsize -= nb; - mchunkptr p = m->top; - mchunkptr r = m->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(m, p, nb); - check_top_chunk(m, m->top); - check_malloced_chunk(m, chunk2mem(p), nb); - return chunk2mem(p); - } - } - - MALLOC_FAILURE_ACTION; - return 0; -} - -/* ----------------------- system deallocation -------------------------- */ - -/* Unmap and unlink any mmapped segments that don't contain used chunks */ -static size_t release_unused_segments(mstate m) { - size_t released = 0; - int nsegs = 0; - msegmentptr pred = &m->seg; - msegmentptr sp = pred->next; - while (sp != 0) { - char* base = sp->base; - size_t size = sp->size; - msegmentptr next = sp->next; - ++nsegs; - if (is_mmapped_segment(sp) && !is_extern_segment(sp)) { - mchunkptr p = align_as_chunk(base); - size_t psize = chunksize(p); - /* Can unmap if first chunk holds entire segment and not pinned */ - if (!is_inuse(p) && (char*)p + psize >= base + size - TOP_FOOT_SIZE) { - tchunkptr tp = (tchunkptr)p; - assert(segment_holds(sp, (char*)sp)); - if (p == m->dv) { - m->dv = 0; - m->dvsize = 0; - } - else { - unlink_large_chunk(m, tp); - } - if (CALL_MUNMAP(base, size) == 0) { - released += size; - m->footprint -= size; - /* unlink obsoleted record */ - sp = pred; - sp->next = next; - } - else { /* back out if cannot unmap */ - insert_large_chunk(m, tp, psize); - } - } - } - if (NO_SEGMENT_TRAVERSAL) /* scan only first segment */ - break; - pred = sp; - sp = next; - } - /* Reset check counter */ - m->release_checks = (((size_t) nsegs > (size_t) MAX_RELEASE_CHECK_RATE)? - (size_t) nsegs : (size_t) MAX_RELEASE_CHECK_RATE); - return released; -} - -static int sys_trim(mstate m, size_t pad) { - size_t released = 0; - ensure_initialization(); - if (pad < MAX_REQUEST && is_initialized(m)) { - pad += TOP_FOOT_SIZE; /* ensure enough room for segment overhead */ - - if (m->topsize > pad) { - /* Shrink top space in granularity-size units, keeping at least one */ - size_t unit = mparams.granularity; - size_t extra = ((m->topsize - pad + (unit - SIZE_T_ONE)) / unit - - SIZE_T_ONE) * unit; - msegmentptr sp = segment_holding(m, (char*)m->top); - - if (!is_extern_segment(sp)) { - if (is_mmapped_segment(sp)) { - if (HAVE_MMAP && - sp->size >= extra && - !has_segment_link(m, sp)) { /* can't shrink if pinned */ - size_t newsize = sp->size - extra; - (void)newsize; /* placate people compiling -Wunused-variable */ - /* Prefer mremap, fall back to munmap */ - if ((CALL_MREMAP(sp->base, sp->size, newsize, 0) != MFAIL) || - (CALL_MUNMAP(sp->base + newsize, extra) == 0)) { - released = extra; - } - } - } - else if (HAVE_MORECORE) { - if (extra >= HALF_MAX_SIZE_T) /* Avoid wrapping negative */ - extra = (HALF_MAX_SIZE_T) + SIZE_T_ONE - unit; - ACQUIRE_MALLOC_GLOBAL_LOCK(); - { - /* Make sure end of memory is where we last set it. */ - char* old_br = (char*)(CALL_MORECORE(0)); - if (old_br == sp->base + sp->size) { - char* rel_br = (char*)(CALL_MORECORE(-extra)); - char* new_br = (char*)(CALL_MORECORE(0)); - if (rel_br != CMFAIL && new_br < old_br) - released = old_br - new_br; - } - } - RELEASE_MALLOC_GLOBAL_LOCK(); - } - } - - if (released != 0) { - sp->size -= released; - m->footprint -= released; - init_top(m, m->top, m->topsize - released); - check_top_chunk(m, m->top); - } - } - - /* Unmap any unused mmapped segments */ - if (HAVE_MMAP) - released += release_unused_segments(m); - - /* On failure, disable autotrim to avoid repeated failed future calls */ - if (released == 0 && m->topsize > m->trim_check) - m->trim_check = MAX_SIZE_T; - } - - return (released != 0)? 1 : 0; -} - -/* Consolidate and bin a chunk. Differs from exported versions - of free mainly in that the chunk need not be marked as inuse. -*/ -static void dispose_chunk(mstate m, mchunkptr p, size_t psize) { - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - mchunkptr prev; - size_t prevsize = p->prev_foot; - if (is_mmapped(p)) { - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) - m->footprint -= psize; - return; - } - prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(m, prev))) { /* consolidate backward */ - if (p != m->dv) { - unlink_chunk(m, p, prevsize); - } - else if ((next->head & INUSE_BITS) == INUSE_BITS) { - m->dvsize = psize; - set_free_with_pinuse(p, psize, next); - return; - } - } - else { - CORRUPTION_ERROR_ACTION(m); - return; - } - } - if (RTCHECK(ok_address(m, next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == m->top) { - size_t tsize = m->topsize += psize; - m->top = p; - p->head = tsize | PINUSE_BIT; - if (p == m->dv) { - m->dv = 0; - m->dvsize = 0; - } - return; - } - else if (next == m->dv) { - size_t dsize = m->dvsize += psize; - m->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - return; - } - else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(m, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == m->dv) { - m->dvsize = psize; - return; - } - } - } - else { - set_free_with_pinuse(p, psize, next); - } - insert_chunk(m, p, psize); - } - else { - CORRUPTION_ERROR_ACTION(m); - } -} - -/* ---------------------------- malloc --------------------------- */ - -/* allocate a large request from the best fitting chunk in a treebin */ -static void* tmalloc_large(mstate m, size_t nb) { - tchunkptr v = 0; - size_t rsize = -nb; /* Unsigned negation */ - tchunkptr t; - bindex_t idx; - compute_tree_index(nb, idx); - if ((t = *treebin_at(m, idx)) != 0) { - /* Traverse tree for this bin looking for node with size == nb */ - size_t sizebits = nb << leftshift_for_tree_index(idx); - tchunkptr rst = 0; /* The deepest untaken right subtree */ - for (;;) { - tchunkptr rt; - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - v = t; - if ((rsize = trem) == 0) - break; - } - rt = t->child[1]; - t = t->child[(sizebits >> (SIZE_T_BITSIZE-SIZE_T_ONE)) & 1]; - if (rt != 0 && rt != t) - rst = rt; - if (t == 0) { - t = rst; /* set t to least subtree holding sizes > nb */ - break; - } - sizebits <<= 1; - } - } - if (t == 0 && v == 0) { /* set t to root of next non-empty treebin */ - binmap_t leftbits = left_bits(idx2bit(idx)) & m->treemap; - if (leftbits != 0) { - bindex_t i; - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - t = *treebin_at(m, i); - } - } - - while (t != 0) { /* find smallest of tree or subtree */ - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; - } - t = leftmost_child(t); - } - - /* If dv is a better fit, return 0 so malloc will use it */ - if (v != 0 && rsize < (size_t)(m->dvsize - nb)) { - if (RTCHECK(ok_address(m, v))) { /* split */ - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - insert_chunk(m, r, rsize); - } - return chunk2mem(v); - } - } - CORRUPTION_ERROR_ACTION(m); - } - return 0; -} - -/* allocate a small request from the best fitting chunk in a treebin */ -static void* tmalloc_small(mstate m, size_t nb) { - tchunkptr t, v; - size_t rsize; - bindex_t i; - binmap_t leastbit = least_bit(m->treemap); - compute_bit2idx(leastbit, i); - v = t = *treebin_at(m, i); - rsize = chunksize(t) - nb; - - while ((t = leftmost_child(t)) != 0) { - size_t trem = chunksize(t) - nb; - if (trem < rsize) { - rsize = trem; - v = t; - } - } - - if (RTCHECK(ok_address(m, v))) { - mchunkptr r = chunk_plus_offset(v, nb); - assert(chunksize(v) == rsize + nb); - if (RTCHECK(ok_next(v, r))) { - unlink_large_chunk(m, v); - if (rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(m, v, (rsize + nb)); - else { - set_size_and_pinuse_of_inuse_chunk(m, v, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(m, r, rsize); - } - return chunk2mem(v); - } - } - - CORRUPTION_ERROR_ACTION(m); - return 0; -} - -#if !ONLY_MSPACES - -void* dlmalloc(size_t bytes) { - /* - Basic algorithm: - If a small request (< 256 bytes minus per-chunk overhead): - 1. If one exists, use a remainderless chunk in associated smallbin. - (Remainderless means that there are too few excess bytes to - represent as a chunk.) - 2. If it is big enough, use the dv chunk, which is normally the - chunk adjacent to the one used for the most recent small request. - 3. If one exists, split the smallest available chunk in a bin, - saving remainder in dv. - 4. If it is big enough, use the top chunk. - 5. If available, get memory from system and use it - Otherwise, for a large request: - 1. Find the smallest available binned chunk that fits, and use it - if it is better fitting than dv chunk, splitting if necessary. - 2. If better fitting than any binned chunk, use the dv chunk. - 3. If it is big enough, use the top chunk. - 4. If request size >= mmap threshold, try to directly mmap this chunk. - 5. If available, get memory from system and use it - - The ugly goto's here ensure that postaction occurs along all paths. - */ - -#if USE_LOCKS - ensure_initialization(); /* initialize in sys_alloc if not using locks */ -#endif - - if (!PREACTION(gm)) { - void* mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = gm->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(gm, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(gm, b, p, idx); - set_inuse_and_pinuse(gm, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (nb > gm->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(gm, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(gm, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(gm, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(gm, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (gm->treemap != 0 && (mem = tmalloc_small(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - } - } - else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (gm->treemap != 0 && (mem = tmalloc_large(gm, nb)) != 0) { - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - } - - if (nb <= gm->dvsize) { - size_t rsize = gm->dvsize - nb; - mchunkptr p = gm->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = gm->dv = chunk_plus_offset(p, nb); - gm->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - } - else { /* exhaust dv */ - size_t dvs = gm->dvsize; - gm->dvsize = 0; - gm->dv = 0; - set_inuse_and_pinuse(gm, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - else if (nb < gm->topsize) { /* Split top */ - size_t rsize = gm->topsize -= nb; - mchunkptr p = gm->top; - mchunkptr r = gm->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(gm, p, nb); - mem = chunk2mem(p); - check_top_chunk(gm, gm->top); - check_malloced_chunk(gm, mem, nb); - goto postaction; - } - - mem = sys_alloc(gm, nb); - - postaction: - POSTACTION(gm); - return mem; - } - - return 0; -} - -/* ---------------------------- free --------------------------- */ - -void dlfree(void* mem) { - /* - Consolidate freed chunks with preceeding or succeeding bordering - free chunks, if they exist, and then place in a bin. Intermixed - with special cases for top, dv, mmapped chunks, and usage errors. - */ - - if (mem != 0) { - mchunkptr p = mem2chunk(mem); -#if FOOTERS - mstate fm = get_mstate_for(p); - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } -#else /* FOOTERS */ -#define fm gm -#endif /* FOOTERS */ - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if (is_mmapped(p)) { - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } - else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } - else if ((next->head & INUSE_BITS) == INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } - } - else - goto erroraction; - } - } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } - else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; - } - else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } - else - set_free_with_pinuse(p, psize, next); - - if (is_small(psize)) { - insert_small_chunk(fm, p, psize); - check_free_chunk(fm, p); - } - else { - tchunkptr tp = (tchunkptr)p; - insert_large_chunk(fm, tp, psize); - check_free_chunk(fm, p); - if (--fm->release_checks == 0) - release_unused_segments(fm); - } - goto postaction; - } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); - } - } -#if !FOOTERS -#undef fm -#endif /* FOOTERS */ -} - -void* dlcalloc(size_t n_elements, size_t elem_size) { - void* mem; - size_t req = 0; - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t)0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = dlmalloc(req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; -} - -#endif /* !ONLY_MSPACES */ - -/* ------------ Internal support for realloc, memalign, etc -------------- */ - -/* Try to realloc; only in-place unless can_move true */ -static mchunkptr try_realloc_chunk(mstate m, mchunkptr p, size_t nb, - int can_move) { - mchunkptr newp = 0; - size_t oldsize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, oldsize); - if (RTCHECK(ok_address(m, p) && ok_inuse(p) && - ok_next(p, next) && ok_pinuse(next))) { - if (is_mmapped(p)) { - newp = mmap_resize(m, p, nb, can_move); - } - else if (oldsize >= nb) { /* already big enough */ - size_t rsize = oldsize - nb; - if (rsize >= MIN_CHUNK_SIZE) { /* split off remainder */ - mchunkptr r = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - set_inuse(m, r, rsize); - dispose_chunk(m, r, rsize); - } - newp = p; - } - else if (next == m->top) { /* extend into top */ - if (oldsize + m->topsize > nb) { - size_t newsize = oldsize + m->topsize; - size_t newtopsize = newsize - nb; - mchunkptr newtop = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - newtop->head = newtopsize |PINUSE_BIT; - m->top = newtop; - m->topsize = newtopsize; - newp = p; - } - } - else if (next == m->dv) { /* extend into dv */ - size_t dvs = m->dvsize; - if (oldsize + dvs >= nb) { - size_t dsize = oldsize + dvs - nb; - if (dsize >= MIN_CHUNK_SIZE) { - mchunkptr r = chunk_plus_offset(p, nb); - mchunkptr n = chunk_plus_offset(r, dsize); - set_inuse(m, p, nb); - set_size_and_pinuse_of_free_chunk(r, dsize); - clear_pinuse(n); - m->dvsize = dsize; - m->dv = r; - } - else { /* exhaust dv */ - size_t newsize = oldsize + dvs; - set_inuse(m, p, newsize); - m->dvsize = 0; - m->dv = 0; - } - newp = p; - } - } - else if (!cinuse(next)) { /* extend into next free chunk */ - size_t nextsize = chunksize(next); - if (oldsize + nextsize >= nb) { - size_t rsize = oldsize + nextsize - nb; - unlink_chunk(m, next, nextsize); - if (rsize < MIN_CHUNK_SIZE) { - size_t newsize = oldsize + nextsize; - set_inuse(m, p, newsize); - } - else { - mchunkptr r = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - set_inuse(m, r, rsize); - dispose_chunk(m, r, rsize); - } - newp = p; - } - } - } - else { - USAGE_ERROR_ACTION(m, chunk2mem(p)); - } - return newp; -} - -static void* internal_memalign(mstate m, size_t alignment, size_t bytes) { - void* mem = 0; - if (alignment < MIN_CHUNK_SIZE) /* must be at least a minimum chunk size */ - alignment = MIN_CHUNK_SIZE; - if ((alignment & (alignment-SIZE_T_ONE)) != 0) {/* Ensure a power of 2 */ - size_t a = MALLOC_ALIGNMENT << 1; - while (a < alignment) a <<= 1; - alignment = a; - } - if (bytes >= MAX_REQUEST - alignment) { - if (m != 0) { /* Test isn't needed but avoids compiler warning */ - MALLOC_FAILURE_ACTION; - } - } - else { - size_t nb = request2size(bytes); - size_t req = nb + alignment + MIN_CHUNK_SIZE - CHUNK_OVERHEAD; - mem = internal_malloc(m, req); - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - if (PREACTION(m)) - return 0; - if ((((size_t)(mem)) & (alignment - 1)) != 0) { /* misaligned */ - /* - Find an aligned spot inside chunk. Since we need to give - back leading space in a chunk of at least MIN_CHUNK_SIZE, if - the first calculation places us at a spot with less than - MIN_CHUNK_SIZE leader, we can move to the next aligned spot. - We've allocated enough total room so that this is always - possible. - */ - char* br = (char*)mem2chunk((size_t)(((size_t)((char*)mem + alignment - - SIZE_T_ONE)) & - -alignment)); - char* pos = ((size_t)(br - (char*)(p)) >= MIN_CHUNK_SIZE)? - br : br+alignment; - mchunkptr newp = (mchunkptr)pos; - size_t leadsize = pos - (char*)(p); - size_t newsize = chunksize(p) - leadsize; - - if (is_mmapped(p)) { /* For mmapped chunks, just adjust offset */ - newp->prev_foot = p->prev_foot + leadsize; - newp->head = newsize; - } - else { /* Otherwise, give back leader, use the rest */ - set_inuse(m, newp, newsize); - set_inuse(m, p, leadsize); - dispose_chunk(m, p, leadsize); - } - p = newp; - } - - /* Give back spare room at the end */ - if (!is_mmapped(p)) { - size_t size = chunksize(p); - if (size > nb + MIN_CHUNK_SIZE) { - size_t remainder_size = size - nb; - mchunkptr remainder = chunk_plus_offset(p, nb); - set_inuse(m, p, nb); - set_inuse(m, remainder, remainder_size); - dispose_chunk(m, remainder, remainder_size); - } - } - - mem = chunk2mem(p); - assert (chunksize(p) >= nb); - assert(((size_t)mem & (alignment - 1)) == 0); - check_inuse_chunk(m, p); - POSTACTION(m); - } - } - return mem; -} - -/* - Common support for independent_X routines, handling - all of the combinations that can result. - The opts arg has: - bit 0 set if all elements are same size (using sizes[0]) - bit 1 set if elements should be zeroed -*/ -static void** ialloc(mstate m, - size_t n_elements, - size_t* sizes, - int opts, - void* chunks[]) { - - size_t element_size; /* chunksize of each element, if all same */ - size_t contents_size; /* total size of elements */ - size_t array_size; /* request size of pointer array */ - void* mem; /* malloced aggregate space */ - mchunkptr p; /* corresponding chunk */ - size_t remainder_size; /* remaining bytes while splitting */ - void** marray; /* either "chunks" or malloced ptr array */ - mchunkptr array_chunk; /* chunk for malloced ptr array */ - flag_t was_enabled; /* to disable mmap */ - size_t size; - size_t i; - - ensure_initialization(); - /* compute array length, if needed */ - if (chunks != 0) { - if (n_elements == 0) - return chunks; /* nothing to do */ - marray = chunks; - array_size = 0; - } - else { - /* if empty req, must still return chunk representing empty array */ - if (n_elements == 0) - return (void**)internal_malloc(m, 0); - marray = 0; - array_size = request2size(n_elements * (sizeof(void*))); - } - - /* compute total element size */ - if (opts & 0x1) { /* all-same-size */ - element_size = request2size(*sizes); - contents_size = n_elements * element_size; - } - else { /* add up all the sizes */ - element_size = 0; - contents_size = 0; - for (i = 0; i != n_elements; ++i) - contents_size += request2size(sizes[i]); - } - - size = contents_size + array_size; - - /* - Allocate the aggregate chunk. First disable direct-mmapping so - malloc won't use it, since we would not be able to later - free/realloc space internal to a segregated mmap region. - */ - was_enabled = use_mmap(m); - disable_mmap(m); - mem = internal_malloc(m, size - CHUNK_OVERHEAD); - if (was_enabled) - enable_mmap(m); - if (mem == 0) - return 0; - - if (PREACTION(m)) return 0; - p = mem2chunk(mem); - remainder_size = chunksize(p); - - assert(!is_mmapped(p)); - - if (opts & 0x2) { /* optionally clear the elements */ - memset((size_t*)mem, 0, remainder_size - SIZE_T_SIZE - array_size); - } - - /* If not provided, allocate the pointer array as final part of chunk */ - if (marray == 0) { - size_t array_chunk_size; - array_chunk = chunk_plus_offset(p, contents_size); - array_chunk_size = remainder_size - contents_size; - marray = (void**) (chunk2mem(array_chunk)); - set_size_and_pinuse_of_inuse_chunk(m, array_chunk, array_chunk_size); - remainder_size = contents_size; - } - - /* split out elements */ - for (i = 0; ; ++i) { - marray[i] = chunk2mem(p); - if (i != n_elements-1) { - if (element_size != 0) - size = element_size; - else - size = request2size(sizes[i]); - remainder_size -= size; - set_size_and_pinuse_of_inuse_chunk(m, p, size); - p = chunk_plus_offset(p, size); - } - else { /* the final element absorbs any overallocation slop */ - set_size_and_pinuse_of_inuse_chunk(m, p, remainder_size); - break; - } - } - -#if DEBUG - if (marray != chunks) { - /* final element must have exactly exhausted chunk */ - if (element_size != 0) { - assert(remainder_size == element_size); - } - else { - assert(remainder_size == request2size(sizes[i])); - } - check_inuse_chunk(m, mem2chunk(marray)); - } - for (i = 0; i != n_elements; ++i) - check_inuse_chunk(m, mem2chunk(marray[i])); - -#endif /* DEBUG */ - - POSTACTION(m); - return marray; -} - -/* Try to free all pointers in the given array. - Note: this could be made faster, by delaying consolidation, - at the price of disabling some user integrity checks, We - still optimize some consolidations by combining adjacent - chunks before freeing, which will occur often if allocated - with ialloc or the array is sorted. -*/ -static size_t internal_bulk_free(mstate m, void* array[], size_t nelem) { - size_t unfreed = 0; - if (!PREACTION(m)) { - void** a; - void** fence = &(array[nelem]); - for (a = array; a != fence; ++a) { - void* mem = *a; - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - size_t psize = chunksize(p); -#if FOOTERS - if (get_mstate_for(p) != m) { - ++unfreed; - continue; - } -#endif - check_inuse_chunk(m, p); - *a = 0; - if (RTCHECK(ok_address(m, p) && ok_inuse(p))) { - void ** b = a + 1; /* try to merge with next chunk */ - mchunkptr next = next_chunk(p); - if (b != fence && *b == chunk2mem(next)) { - size_t newsize = chunksize(next) + psize; - set_inuse(m, p, newsize); - *b = chunk2mem(p); - } - else - dispose_chunk(m, p, psize); - } - else { - CORRUPTION_ERROR_ACTION(m); - break; - } - } - } - if (should_trim(m, m->topsize)) - sys_trim(m, 0); - POSTACTION(m); - } - return unfreed; -} - -/* Traversal */ -#if MALLOC_INSPECT_ALL -static void internal_inspect_all(mstate m, - void(*handler)(void *start, - void *end, - size_t used_bytes, - void* callback_arg), - void* arg) { - if (is_initialized(m)) { - mchunkptr top = m->top; - msegmentptr s; - for (s = &m->seg; s != 0; s = s->next) { - mchunkptr q = align_as_chunk(s->base); - while (segment_holds(s, q) && q->head != FENCEPOST_HEAD) { - mchunkptr next = next_chunk(q); - size_t sz = chunksize(q); - size_t used; - void* start; - if (is_inuse(q)) { - used = sz - CHUNK_OVERHEAD; /* must not be mmapped */ - start = chunk2mem(q); - } - else { - used = 0; - if (is_small(sz)) { /* offset by possible bookkeeping */ - start = (void*)((char*)q + sizeof(struct malloc_chunk)); - } - else { - start = (void*)((char*)q + sizeof(struct malloc_tree_chunk)); - } - } - if (start < (void*)next) /* skip if all space is bookkeeping */ - handler(start, next, used, arg); - if (q == top) - break; - q = next; - } - } - } -} -#endif /* MALLOC_INSPECT_ALL */ - -/* ------------------ Exported realloc, memalign, etc -------------------- */ - -#if !ONLY_MSPACES - -void* dlrealloc(void* oldmem, size_t bytes) { - void* mem = 0; - if (oldmem == 0) { - mem = dlmalloc(bytes); - } - else if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - } -#ifdef REALLOC_ZERO_BYTES_FREES - else if (bytes == 0) { - dlfree(oldmem); - } -#endif /* REALLOC_ZERO_BYTES_FREES */ - else { - size_t nb = request2size(bytes); - mchunkptr oldp = mem2chunk(oldmem); -#if ! FOOTERS - mstate m = gm; -#else /* FOOTERS */ - mstate m = get_mstate_for(oldp); - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } -#endif /* FOOTERS */ - if (!PREACTION(m)) { - mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1); - POSTACTION(m); - if (newp != 0) { - check_inuse_chunk(m, newp); - mem = chunk2mem(newp); - } - else { - mem = internal_malloc(m, bytes); - if (mem != 0) { - size_t oc = chunksize(oldp) - overhead_for(oldp); - memcpy(mem, oldmem, (oc < bytes)? oc : bytes); - internal_free(m, oldmem); - } - } - } - } - return mem; -} - -void* dlrealloc_in_place(void* oldmem, size_t bytes) { - void* mem = 0; - if (oldmem != 0) { - if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - } - else { - size_t nb = request2size(bytes); - mchunkptr oldp = mem2chunk(oldmem); -#if ! FOOTERS - mstate m = gm; -#else /* FOOTERS */ - mstate m = get_mstate_for(oldp); - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } -#endif /* FOOTERS */ - if (!PREACTION(m)) { - mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0); - POSTACTION(m); - if (newp == oldp) { - check_inuse_chunk(m, newp); - mem = oldmem; - } - } - } - } - return mem; -} - -void* dlmemalign(size_t alignment, size_t bytes) { - if (alignment <= MALLOC_ALIGNMENT) { - return dlmalloc(bytes); - } - return internal_memalign(gm, alignment, bytes); -} - -int dlposix_memalign(void** pp, size_t alignment, size_t bytes) { - void* mem = 0; - if (alignment == MALLOC_ALIGNMENT) - mem = dlmalloc(bytes); - else { - size_t d = alignment / sizeof(void*); - size_t r = alignment % sizeof(void*); - if (r != 0 || d == 0 || (d & (d-SIZE_T_ONE)) != 0) - return EINVAL; - else if (bytes <= MAX_REQUEST - alignment) { - if (alignment < MIN_CHUNK_SIZE) - alignment = MIN_CHUNK_SIZE; - mem = internal_memalign(gm, alignment, bytes); - } - } - if (mem == 0) - return ENOMEM; - else { - *pp = mem; - return 0; - } -} - -void* dlvalloc(size_t bytes) { - size_t pagesz; - ensure_initialization(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, bytes); -} - -void* dlpvalloc(size_t bytes) { - size_t pagesz; - ensure_initialization(); - pagesz = mparams.page_size; - return dlmemalign(pagesz, (bytes + pagesz - SIZE_T_ONE) & ~(pagesz - SIZE_T_ONE)); -} - -void** dlindependent_calloc(size_t n_elements, size_t elem_size, - void* chunks[]) { - size_t sz = elem_size; /* serves as 1-element array */ - return ialloc(gm, n_elements, &sz, 3, chunks); -} - -void** dlindependent_comalloc(size_t n_elements, size_t sizes[], - void* chunks[]) { - return ialloc(gm, n_elements, sizes, 0, chunks); -} - -size_t dlbulk_free(void* array[], size_t nelem) { - return internal_bulk_free(gm, array, nelem); -} - -#if MALLOC_INSPECT_ALL -void dlmalloc_inspect_all(void(*handler)(void *start, - void *end, - size_t used_bytes, - void* callback_arg), - void* arg) { - ensure_initialization(); - if (!PREACTION(gm)) { - internal_inspect_all(gm, handler, arg); - POSTACTION(gm); - } -} -#endif /* MALLOC_INSPECT_ALL */ - -int dlmalloc_trim(size_t pad) { - int result = 0; - ensure_initialization(); - if (!PREACTION(gm)) { - result = sys_trim(gm, pad); - POSTACTION(gm); - } - return result; -} - -size_t dlmalloc_footprint(void) { - return gm->footprint; -} - -size_t dlmalloc_max_footprint(void) { - return gm->max_footprint; -} - -size_t dlmalloc_footprint_limit(void) { - size_t maf = gm->footprint_limit; - return maf == 0 ? MAX_SIZE_T : maf; -} - -size_t dlmalloc_set_footprint_limit(size_t bytes) { - size_t result; /* invert sense of 0 */ - if (bytes == 0) - result = granularity_align(1); /* Use minimal size */ - if (bytes == MAX_SIZE_T) - result = 0; /* disable */ - else - result = granularity_align(bytes); - return gm->footprint_limit = result; -} - -#if !NO_MALLINFO -struct mallinfo dlmallinfo(void) { - return internal_mallinfo(gm); -} -#endif /* NO_MALLINFO */ - -#if !NO_MALLOC_STATS -void dlmalloc_stats() { - internal_malloc_stats(gm); -} -#endif /* NO_MALLOC_STATS */ - -int dlmallopt(int param_number, int value) { - return change_mparam(param_number, value); -} - -/* -size_t dlmalloc_usable_size(void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - if (is_inuse(p)) - return chunksize(p) - overhead_for(p); - } - return 0; -} -*/ - -#endif /* !ONLY_MSPACES */ - -/* ----------------------------- user mspaces ---------------------------- */ - -#if MSPACES - -static mstate init_user_mstate(char* tbase, size_t tsize) { - size_t msize = pad_request(sizeof(struct malloc_state)); - mchunkptr mn; - mchunkptr msp = align_as_chunk(tbase); - mstate m = (mstate)(chunk2mem(msp)); - memset(m, 0, msize); - (void)INITIAL_LOCK(&m->mutex); - msp->head = (msize|INUSE_BITS); - m->seg.base = m->least_addr = tbase; - m->seg.size = m->footprint = m->max_footprint = tsize; - m->magic = mparams.magic; - m->release_checks = MAX_RELEASE_CHECK_RATE; - m->mflags = mparams.default_mflags; - m->extp = 0; - m->exts = 0; - disable_contiguous(m); - init_bins(m); - mn = next_chunk(mem2chunk(m)); - init_top(m, mn, (size_t)((tbase + tsize) - (char*)mn) - TOP_FOOT_SIZE); - check_top_chunk(m, m->top); - return m; -} - -mspace create_mspace(size_t capacity, int locked) { - mstate m = 0; - size_t msize; - ensure_initialization(); - msize = pad_request(sizeof(struct malloc_state)); - if (capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { - size_t rs = ((capacity == 0)? mparams.granularity : - (capacity + TOP_FOOT_SIZE + msize)); - size_t tsize = granularity_align(rs); - char* tbase = (char*)(CALL_MMAP(tsize)); - if (tbase != CMFAIL) { - m = init_user_mstate(tbase, tsize); - m->seg.sflags = USE_MMAP_BIT; - set_lock(m, locked); - } - } - return (mspace)m; -} - -mspace create_mspace_with_base(void* base, size_t capacity, int locked) { - mstate m = 0; - size_t msize; - ensure_initialization(); - msize = pad_request(sizeof(struct malloc_state)); - if (capacity > msize + TOP_FOOT_SIZE && - capacity < (size_t) -(msize + TOP_FOOT_SIZE + mparams.page_size)) { - m = init_user_mstate((char*)base, capacity); - m->seg.sflags = EXTERN_BIT; - set_lock(m, locked); - } - return (mspace)m; -} - -int mspace_track_large_chunks(mspace msp, int enable) { - int ret = 0; - mstate ms = (mstate)msp; - if (!PREACTION(ms)) { - if (!use_mmap(ms)) { - ret = 1; - } - if (!enable) { - enable_mmap(ms); - } else { - disable_mmap(ms); - } - POSTACTION(ms); - } - return ret; -} - -size_t destroy_mspace(mspace msp) { - size_t freed = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - msegmentptr sp = &ms->seg; - (void)DESTROY_LOCK(&ms->mutex); /* destroy before unmapped */ - while (sp != 0) { - char* base = sp->base; - size_t size = sp->size; - flag_t flag = sp->sflags; - (void)base; /* placate people compiling -Wunused-variable */ - sp = sp->next; - if ((flag & USE_MMAP_BIT) && !(flag & EXTERN_BIT) && - CALL_MUNMAP(base, size) == 0) - freed += size; - } - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return freed; -} - -/* - mspace versions of routines are near-clones of the global - versions. This is not so nice but better than the alternatives. -*/ - -void* mspace_malloc(mspace msp, size_t bytes) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - if (!PREACTION(ms)) { - void* mem; - size_t nb; - if (bytes <= MAX_SMALL_REQUEST) { - bindex_t idx; - binmap_t smallbits; - nb = (bytes < MIN_REQUEST)? MIN_CHUNK_SIZE : pad_request(bytes); - idx = small_index(nb); - smallbits = ms->smallmap >> idx; - - if ((smallbits & 0x3U) != 0) { /* Remainderless fit to a smallbin. */ - mchunkptr b, p; - idx += ~smallbits & 1; /* Uses next bin if idx empty */ - b = smallbin_at(ms, idx); - p = b->fd; - assert(chunksize(p) == small_index2size(idx)); - unlink_first_small_chunk(ms, b, p, idx); - set_inuse_and_pinuse(ms, p, small_index2size(idx)); - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (nb > ms->dvsize) { - if (smallbits != 0) { /* Use chunk in next nonempty smallbin */ - mchunkptr b, p, r; - size_t rsize; - bindex_t i; - binmap_t leftbits = (smallbits << idx) & left_bits(idx2bit(idx)); - binmap_t leastbit = least_bit(leftbits); - compute_bit2idx(leastbit, i); - b = smallbin_at(ms, i); - p = b->fd; - assert(chunksize(p) == small_index2size(i)); - unlink_first_small_chunk(ms, b, p, i); - rsize = small_index2size(i) - nb; - /* Fit here cannot be remainderless if 4byte sizes */ - if (SIZE_T_SIZE != 4 && rsize < MIN_CHUNK_SIZE) - set_inuse_and_pinuse(ms, p, small_index2size(i)); - else { - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - r = chunk_plus_offset(p, nb); - set_size_and_pinuse_of_free_chunk(r, rsize); - replace_dv(ms, r, rsize); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (ms->treemap != 0 && (mem = tmalloc_small(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - } - } - else if (bytes >= MAX_REQUEST) - nb = MAX_SIZE_T; /* Too big to allocate. Force failure (in sys alloc) */ - else { - nb = pad_request(bytes); - if (ms->treemap != 0 && (mem = tmalloc_large(ms, nb)) != 0) { - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - } - - if (nb <= ms->dvsize) { - size_t rsize = ms->dvsize - nb; - mchunkptr p = ms->dv; - if (rsize >= MIN_CHUNK_SIZE) { /* split dv */ - mchunkptr r = ms->dv = chunk_plus_offset(p, nb); - ms->dvsize = rsize; - set_size_and_pinuse_of_free_chunk(r, rsize); - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - } - else { /* exhaust dv */ - size_t dvs = ms->dvsize; - ms->dvsize = 0; - ms->dv = 0; - set_inuse_and_pinuse(ms, p, dvs); - } - mem = chunk2mem(p); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - else if (nb < ms->topsize) { /* Split top */ - size_t rsize = ms->topsize -= nb; - mchunkptr p = ms->top; - mchunkptr r = ms->top = chunk_plus_offset(p, nb); - r->head = rsize | PINUSE_BIT; - set_size_and_pinuse_of_inuse_chunk(ms, p, nb); - mem = chunk2mem(p); - check_top_chunk(ms, ms->top); - check_malloced_chunk(ms, mem, nb); - goto postaction; - } - - mem = sys_alloc(ms, nb); - - postaction: - POSTACTION(ms); - return mem; - } - - return 0; -} - -void mspace_free(mspace msp, void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); -#if FOOTERS - mstate fm = get_mstate_for(p); - (void)msp; /* placate people compiling -Wunused */ -#else /* FOOTERS */ - mstate fm = (mstate)msp; -#endif /* FOOTERS */ - if (!ok_magic(fm)) { - USAGE_ERROR_ACTION(fm, p); - return; - } - if (!PREACTION(fm)) { - check_inuse_chunk(fm, p); - if (RTCHECK(ok_address(fm, p) && ok_inuse(p))) { - size_t psize = chunksize(p); - mchunkptr next = chunk_plus_offset(p, psize); - if (!pinuse(p)) { - size_t prevsize = p->prev_foot; - if (is_mmapped(p)) { - psize += prevsize + MMAP_FOOT_PAD; - if (CALL_MUNMAP((char*)p - prevsize, psize) == 0) - fm->footprint -= psize; - goto postaction; - } - else { - mchunkptr prev = chunk_minus_offset(p, prevsize); - psize += prevsize; - p = prev; - if (RTCHECK(ok_address(fm, prev))) { /* consolidate backward */ - if (p != fm->dv) { - unlink_chunk(fm, p, prevsize); - } - else if ((next->head & INUSE_BITS) == INUSE_BITS) { - fm->dvsize = psize; - set_free_with_pinuse(p, psize, next); - goto postaction; - } - } - else - goto erroraction; - } - } - - if (RTCHECK(ok_next(p, next) && ok_pinuse(next))) { - if (!cinuse(next)) { /* consolidate forward */ - if (next == fm->top) { - size_t tsize = fm->topsize += psize; - fm->top = p; - p->head = tsize | PINUSE_BIT; - if (p == fm->dv) { - fm->dv = 0; - fm->dvsize = 0; - } - if (should_trim(fm, tsize)) - sys_trim(fm, 0); - goto postaction; - } - else if (next == fm->dv) { - size_t dsize = fm->dvsize += psize; - fm->dv = p; - set_size_and_pinuse_of_free_chunk(p, dsize); - goto postaction; - } - else { - size_t nsize = chunksize(next); - psize += nsize; - unlink_chunk(fm, next, nsize); - set_size_and_pinuse_of_free_chunk(p, psize); - if (p == fm->dv) { - fm->dvsize = psize; - goto postaction; - } - } - } - else - set_free_with_pinuse(p, psize, next); - - if (is_small(psize)) { - insert_small_chunk(fm, p, psize); - check_free_chunk(fm, p); - } - else { - tchunkptr tp = (tchunkptr)p; - insert_large_chunk(fm, tp, psize); - check_free_chunk(fm, p); - if (--fm->release_checks == 0) - release_unused_segments(fm); - } - goto postaction; - } - } - erroraction: - USAGE_ERROR_ACTION(fm, p); - postaction: - POSTACTION(fm); - } - } -} - -void* mspace_calloc(mspace msp, size_t n_elements, size_t elem_size) { - void* mem; - size_t req = 0; - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - if (n_elements != 0) { - req = n_elements * elem_size; - if (((n_elements | elem_size) & ~(size_t)0xffff) && - (req / n_elements != elem_size)) - req = MAX_SIZE_T; /* force downstream failure on overflow */ - } - mem = internal_malloc(ms, req); - if (mem != 0 && calloc_must_clear(mem2chunk(mem))) - memset(mem, 0, req); - return mem; -} - -void* mspace_realloc(mspace msp, void* oldmem, size_t bytes) { - void* mem = 0; - if (oldmem == 0) { - mem = mspace_malloc(msp, bytes); - } - else if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - } -#ifdef REALLOC_ZERO_BYTES_FREES - else if (bytes == 0) { - mspace_free(msp, oldmem); - } -#endif /* REALLOC_ZERO_BYTES_FREES */ - else { - size_t nb = request2size(bytes); - mchunkptr oldp = mem2chunk(oldmem); -#if ! FOOTERS - mstate m = (mstate)msp; -#else /* FOOTERS */ - mstate m = get_mstate_for(oldp); - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } -#endif /* FOOTERS */ - if (!PREACTION(m)) { - mchunkptr newp = try_realloc_chunk(m, oldp, nb, 1); - POSTACTION(m); - if (newp != 0) { - check_inuse_chunk(m, newp); - mem = chunk2mem(newp); - } - else { - mem = mspace_malloc(m, bytes); - if (mem != 0) { - size_t oc = chunksize(oldp) - overhead_for(oldp); - memcpy(mem, oldmem, (oc < bytes)? oc : bytes); - mspace_free(m, oldmem); - } - } - } - } - return mem; -} - -void* mspace_realloc_in_place(mspace msp, void* oldmem, size_t bytes) { - void* mem = 0; - if (oldmem != 0) { - if (bytes >= MAX_REQUEST) { - MALLOC_FAILURE_ACTION; - } - else { - size_t nb = request2size(bytes); - mchunkptr oldp = mem2chunk(oldmem); -#if ! FOOTERS - mstate m = (mstate)msp; -#else /* FOOTERS */ - mstate m = get_mstate_for(oldp); - (void)msp; /* placate people compiling -Wunused */ - if (!ok_magic(m)) { - USAGE_ERROR_ACTION(m, oldmem); - return 0; - } -#endif /* FOOTERS */ - if (!PREACTION(m)) { - mchunkptr newp = try_realloc_chunk(m, oldp, nb, 0); - POSTACTION(m); - if (newp == oldp) { - check_inuse_chunk(m, newp); - mem = oldmem; - } - } - } - } - return mem; -} - -void* mspace_memalign(mspace msp, size_t alignment, size_t bytes) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - if (alignment <= MALLOC_ALIGNMENT) - return mspace_malloc(msp, bytes); - return internal_memalign(ms, alignment, bytes); -} - -void** mspace_independent_calloc(mspace msp, size_t n_elements, - size_t elem_size, void* chunks[]) { - size_t sz = elem_size; /* serves as 1-element array */ - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - return ialloc(ms, n_elements, &sz, 3, chunks); -} - -void** mspace_independent_comalloc(mspace msp, size_t n_elements, - size_t sizes[], void* chunks[]) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - return 0; - } - return ialloc(ms, n_elements, sizes, 0, chunks); -} - -size_t mspace_bulk_free(mspace msp, void* array[], size_t nelem) { - return internal_bulk_free((mstate)msp, array, nelem); -} - -#if MALLOC_INSPECT_ALL -void mspace_inspect_all(mspace msp, - void(*handler)(void *start, - void *end, - size_t used_bytes, - void* callback_arg), - void* arg) { - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - if (!PREACTION(ms)) { - internal_inspect_all(ms, handler, arg); - POSTACTION(ms); - } - } - else { - USAGE_ERROR_ACTION(ms,ms); - } -} -#endif /* MALLOC_INSPECT_ALL */ - -int mspace_trim(mspace msp, size_t pad) { - int result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - if (!PREACTION(ms)) { - result = sys_trim(ms, pad); - POSTACTION(ms); - } - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; -} - -#if !NO_MALLOC_STATS -void mspace_malloc_stats(mspace msp) { - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - internal_malloc_stats(ms); - } - else { - USAGE_ERROR_ACTION(ms,ms); - } -} -#endif /* NO_MALLOC_STATS */ - -size_t mspace_footprint(mspace msp) { - size_t result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - result = ms->footprint; - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; -} - -size_t mspace_max_footprint(mspace msp) { - size_t result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - result = ms->max_footprint; - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; -} - -size_t mspace_footprint_limit(mspace msp) { - size_t result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - size_t maf = ms->footprint_limit; - result = (maf == 0) ? MAX_SIZE_T : maf; - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; -} - -size_t mspace_set_footprint_limit(mspace msp, size_t bytes) { - size_t result = 0; - mstate ms = (mstate)msp; - if (ok_magic(ms)) { - if (bytes == 0) - result = granularity_align(1); /* Use minimal size */ - if (bytes == MAX_SIZE_T) - result = 0; /* disable */ - else - result = granularity_align(bytes); - ms->footprint_limit = result; - } - else { - USAGE_ERROR_ACTION(ms,ms); - } - return result; -} - -#if !NO_MALLINFO -struct mallinfo mspace_mallinfo(mspace msp) { - mstate ms = (mstate)msp; - if (!ok_magic(ms)) { - USAGE_ERROR_ACTION(ms,ms); - } - return internal_mallinfo(ms); -} -#endif /* NO_MALLINFO */ - -size_t mspace_usable_size(const void* mem) { - if (mem != 0) { - mchunkptr p = mem2chunk(mem); - if (is_inuse(p)) - return chunksize(p) - overhead_for(p); - } - return 0; -} - -int mspace_mallopt(int param_number, int value) { - return change_mparam(param_number, value); -} - -#endif /* MSPACES */ - - -/* -------------------- Alternative MORECORE functions ------------------- */ - -/* - Guidelines for creating a custom version of MORECORE: - - * For best performance, MORECORE should allocate in multiples of pagesize. - * MORECORE may allocate more memory than requested. (Or even less, - but this will usually result in a malloc failure.) - * MORECORE must not allocate memory when given argument zero, but - instead return one past the end address of memory from previous - nonzero call. - * For best performance, consecutive calls to MORECORE with positive - arguments should return increasing addresses, indicating that - space has been contiguously extended. - * Even though consecutive calls to MORECORE need not return contiguous - addresses, it must be OK for malloc'ed chunks to span multiple - regions in those cases where they do happen to be contiguous. - * MORECORE need not handle negative arguments -- it may instead - just return MFAIL when given negative arguments. - Negative arguments are always multiples of pagesize. MORECORE - must not misinterpret negative args as large positive unsigned - args. You can suppress all such calls from even occurring by defining - MORECORE_CANNOT_TRIM, - - As an example alternative MORECORE, here is a custom allocator - kindly contributed for pre-OSX macOS. It uses virtually but not - necessarily physically contiguous non-paged memory (locked in, - present and won't get swapped out). You can use it by uncommenting - this section, adding some #includes, and setting up the appropriate - defines above: - - #define MORECORE osMoreCore - - There is also a shutdown routine that should somehow be called for - cleanup upon program exit. - - #define MAX_POOL_ENTRIES 100 - #define MINIMUM_MORECORE_SIZE (64 * 1024U) - static int next_os_pool; - void *our_os_pools[MAX_POOL_ENTRIES]; - - void *osMoreCore(int size) - { - void *ptr = 0; - static void *sbrk_top = 0; - - if (size > 0) - { - if (size < MINIMUM_MORECORE_SIZE) - size = MINIMUM_MORECORE_SIZE; - if (CurrentExecutionLevel() == kTaskLevel) - ptr = PoolAllocateResident(size + RM_PAGE_SIZE, 0); - if (ptr == 0) - { - return (void *) MFAIL; - } - // save ptrs so they can be freed during cleanup - our_os_pools[next_os_pool] = ptr; - next_os_pool++; - ptr = (void *) ((((size_t) ptr) + RM_PAGE_MASK) & ~RM_PAGE_MASK); - sbrk_top = (char *) ptr + size; - return ptr; - } - else if (size < 0) - { - // we don't currently support shrink behavior - return (void *) MFAIL; - } - else - { - return sbrk_top; - } - } - - // cleanup any allocated memory pools - // called as last thing before shutting down driver - - void osCleanupMem(void) - { - void **ptr; - - for (ptr = our_os_pools; ptr < &our_os_pools[MAX_POOL_ENTRIES]; ptr++) - if (*ptr) - { - PoolDeallocate(*ptr); - *ptr = 0; - } - } - -*/ - - -/* ----------------------------------------------------------------------- -History: - v2.8.6 Wed Aug 29 06:57:58 2012 Doug Lea - * fix bad comparison in dlposix_memalign - * don't reuse adjusted asize in sys_alloc - * add LOCK_AT_FORK -- thanks to Kirill Artamonov for the suggestion - * reduce compiler warnings -- thanks to all who reported/suggested these - - v2.8.5 Sun May 22 10:26:02 2011 Doug Lea (dl at gee) - * Always perform unlink checks unless INSECURE - * Add posix_memalign. - * Improve realloc to expand in more cases; expose realloc_in_place. - Thanks to Peter Buhr for the suggestion. - * Add footprint_limit, inspect_all, bulk_free. Thanks - to Barry Hayes and others for the suggestions. - * Internal refactorings to avoid calls while holding locks - * Use non-reentrant locks by default. Thanks to Roland McGrath - for the suggestion. - * Small fixes to mspace_destroy, reset_on_error. - * Various configuration extensions/changes. Thanks - to all who contributed these. - - V2.8.4a Thu Apr 28 14:39:43 2011 (dl at gee.cs.oswego.edu) - * Update Creative Commons URL - - V2.8.4 Wed May 27 09:56:23 2009 Doug Lea (dl at gee) - * Use zeros instead of prev foot for is_mmapped - * Add mspace_track_large_chunks; thanks to Jean Brouwers - * Fix set_inuse in internal_realloc; thanks to Jean Brouwers - * Fix insufficient sys_alloc padding when using 16byte alignment - * Fix bad error check in mspace_footprint - * Adaptations for ptmalloc; thanks to Wolfram Gloger. - * Reentrant spin locks; thanks to Earl Chew and others - * Win32 improvements; thanks to Niall Douglas and Earl Chew - * Add NO_SEGMENT_TRAVERSAL and MAX_RELEASE_CHECK_RATE options - * Extension hook in malloc_state - * Various small adjustments to reduce warnings on some compilers - * Various configuration extensions/changes for more platforms. Thanks - to all who contributed these. - - V2.8.3 Thu Sep 22 11:16:32 2005 Doug Lea (dl at gee) - * Add max_footprint functions - * Ensure all appropriate literals are size_t - * Fix conditional compilation problem for some #define settings - * Avoid concatenating segments with the one provided - in create_mspace_with_base - * Rename some variables to avoid compiler shadowing warnings - * Use explicit lock initialization. - * Better handling of sbrk interference. - * Simplify and fix segment insertion, trimming and mspace_destroy - * Reinstate REALLOC_ZERO_BYTES_FREES option from 2.7.x - * Thanks especially to Dennis Flanagan for help on these. - - V2.8.2 Sun Jun 12 16:01:10 2005 Doug Lea (dl at gee) - * Fix memalign brace error. - - V2.8.1 Wed Jun 8 16:11:46 2005 Doug Lea (dl at gee) - * Fix improper #endif nesting in C++ - * Add explicit casts needed for C++ - - V2.8.0 Mon May 30 14:09:02 2005 Doug Lea (dl at gee) - * Use trees for large bins - * Support mspaces - * Use segments to unify sbrk-based and mmap-based system allocation, - removing need for emulation on most platforms without sbrk. - * Default safety checks - * Optional footer checks. Thanks to William Robertson for the idea. - * Internal code refactoring - * Incorporate suggestions and platform-specific changes. - Thanks to Dennis Flanagan, Colin Plumb, Niall Douglas, - Aaron Bachmann, Emery Berger, and others. - * Speed up non-fastbin processing enough to remove fastbins. - * Remove useless cfree() to avoid conflicts with other apps. - * Remove internal memcpy, memset. Compilers handle builtins better. - * Remove some options that no one ever used and rename others. - - V2.7.2 Sat Aug 17 09:07:30 2002 Doug Lea (dl at gee) - * Fix malloc_state bitmap array misdeclaration - - V2.7.1 Thu Jul 25 10:58:03 2002 Doug Lea (dl at gee) - * Allow tuning of FIRST_SORTED_BIN_SIZE - * Use PTR_UINT as type for all ptr->int casts. Thanks to John Belmonte. - * Better detection and support for non-contiguousness of MORECORE. - Thanks to Andreas Mueller, Conal Walsh, and Wolfram Gloger - * Bypass most of malloc if no frees. Thanks To Emery Berger. - * Fix freeing of old top non-contiguous chunk im sysmalloc. - * Raised default trim and map thresholds to 256K. - * Fix mmap-related #defines. Thanks to Lubos Lunak. - * Fix copy macros; added LACKS_FCNTL_H. Thanks to Neal Walfield. - * Branch-free bin calculation - * Default trim and mmap thresholds now 256K. - - V2.7.0 Sun Mar 11 14:14:06 2001 Doug Lea (dl at gee) - * Introduce independent_comalloc and independent_calloc. - Thanks to Michael Pachos for motivation and help. - * Make optional .h file available - * Allow > 2GB requests on 32bit systems. - * new WIN32 sbrk, mmap, munmap, lock code from . - Thanks also to Andreas Mueller , - and Anonymous. - * Allow override of MALLOC_ALIGNMENT (Thanks to Ruud Waij for - helping test this.) - * memalign: check alignment arg - * realloc: don't try to shift chunks backwards, since this - leads to more fragmentation in some programs and doesn't - seem to help in any others. - * Collect all cases in malloc requiring system memory into sysmalloc - * Use mmap as backup to sbrk - * Place all internal state in malloc_state - * Introduce fastbins (although similar to 2.5.1) - * Many minor tunings and cosmetic improvements - * Introduce USE_PUBLIC_MALLOC_WRAPPERS, USE_MALLOC_LOCK - * Introduce MALLOC_FAILURE_ACTION, MORECORE_CONTIGUOUS - Thanks to Tony E. Bennett and others. - * Include errno.h to support default failure action. - - V2.6.6 Sun Dec 5 07:42:19 1999 Doug Lea (dl at gee) - * return null for negative arguments - * Added Several WIN32 cleanups from Martin C. Fong - * Add 'LACKS_SYS_PARAM_H' for those systems without 'sys/param.h' - (e.g. WIN32 platforms) - * Cleanup header file inclusion for WIN32 platforms - * Cleanup code to avoid Microsoft Visual C++ compiler complaints - * Add 'USE_DL_PREFIX' to quickly allow co-existence with existing - memory allocation routines - * Set 'malloc_getpagesize' for WIN32 platforms (needs more work) - * Use 'assert' rather than 'ASSERT' in WIN32 code to conform to - usage of 'assert' in non-WIN32 code - * Improve WIN32 'sbrk()' emulation's 'findRegion()' routine to - avoid infinite loop - * Always call 'fREe()' rather than 'free()' - - V2.6.5 Wed Jun 17 15:57:31 1998 Doug Lea (dl at gee) - * Fixed ordering problem with boundary-stamping - - V2.6.3 Sun May 19 08:17:58 1996 Doug Lea (dl at gee) - * Added pvalloc, as recommended by H.J. Liu - * Added 64bit pointer support mainly from Wolfram Gloger - * Added anonymously donated WIN32 sbrk emulation - * Malloc, calloc, getpagesize: add optimizations from Raymond Nijssen - * malloc_extend_top: fix mask error that caused wastage after - foreign sbrks - * Add linux mremap support code from HJ Liu - - V2.6.2 Tue Dec 5 06:52:55 1995 Doug Lea (dl at gee) - * Integrated most documentation with the code. - * Add support for mmap, with help from - Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Use last_remainder in more cases. - * Pack bins using idea from colin@nyx10.cs.du.edu - * Use ordered bins instead of best-fit threshhold - * Eliminate block-local decls to simplify tracing and debugging. - * Support another case of realloc via move into top - * Fix error occuring when initial sbrk_base not word-aligned. - * Rely on page size for units instead of SBRK_UNIT to - avoid surprises about sbrk alignment conventions. - * Add mallinfo, mallopt. Thanks to Raymond Nijssen - (raymond@es.ele.tue.nl) for the suggestion. - * Add `pad' argument to malloc_trim and top_pad mallopt parameter. - * More precautions for cases where other routines call sbrk, - courtesy of Wolfram Gloger (Gloger@lrz.uni-muenchen.de). - * Added macros etc., allowing use in linux libc from - H.J. Lu (hjl@gnu.ai.mit.edu) - * Inverted this history list - - V2.6.1 Sat Dec 2 14:10:57 1995 Doug Lea (dl at gee) - * Re-tuned and fixed to behave more nicely with V2.6.0 changes. - * Removed all preallocation code since under current scheme - the work required to undo bad preallocations exceeds - the work saved in good cases for most test programs. - * No longer use return list or unconsolidated bins since - no scheme using them consistently outperforms those that don't - given above changes. - * Use best fit for very large chunks to prevent some worst-cases. - * Added some support for debugging - - V2.6.0 Sat Nov 4 07:05:23 1995 Doug Lea (dl at gee) - * Removed footers when chunks are in use. Thanks to - Paul Wilson (wilson@cs.texas.edu) for the suggestion. - - V2.5.4 Wed Nov 1 07:54:51 1995 Doug Lea (dl at gee) - * Added malloc_trim, with help from Wolfram Gloger - (wmglo@Dent.MED.Uni-Muenchen.DE). - - V2.5.3 Tue Apr 26 10:16:01 1994 Doug Lea (dl at g) - - V2.5.2 Tue Apr 5 16:20:40 1994 Doug Lea (dl at g) - * realloc: try to expand in both directions - * malloc: swap order of clean-bin strategy; - * realloc: only conditionally expand backwards - * Try not to scavenge used bins - * Use bin counts as a guide to preallocation - * Occasionally bin return list chunks in first scan - * Add a few optimizations from colin@nyx10.cs.du.edu - - V2.5.1 Sat Aug 14 15:40:43 1993 Doug Lea (dl at g) - * faster bin computation & slightly different binning - * merged all consolidations to one part of malloc proper - (eliminating old malloc_find_space & malloc_clean_bin) - * Scan 2 returns chunks (not just 1) - * Propagate failure in realloc if malloc returns 0 - * Add stuff to allow compilation on non-ANSI compilers - from kpv@research.att.com - - V2.5 Sat Aug 7 07:41:59 1993 Doug Lea (dl at g.oswego.edu) - * removed potential for odd address access in prev_chunk - * removed dependency on getpagesize.h - * misc cosmetics and a bit more internal documentation - * anticosmetics: mangled names in macros to evade debugger strangeness - * tested on sparc, hp-700, dec-mips, rs6000 - with gcc & native cc (hp, dec only) allowing - Detlefs & Zorn comparison study (in SIGPLAN Notices.) - - Trial version Fri Aug 28 13:14:29 1992 Doug Lea (dl at g.oswego.edu) - * Based loosely on libg++-1.2X malloc. (It retains some of the overall - structure of old version, but most details differ.) - -*/ diff --git a/rocklibc/src/_tzcode/Readme.txt b/rocklibc/src/_tzcode/Readme.txt deleted file mode 100644 index 8eaa30b..0000000 --- a/rocklibc/src/_tzcode/Readme.txt +++ /dev/null @@ -1,10 +0,0 @@ -Major parts of PDCLib's implementation are based on IANA's reference -implementation, tzcode. - - https://data.iana.org/time-zones/tz-link.html - -The latest version of tzcode can be downloaded at: - - https://www.iana.org/time-zones/repository/tzcode-latest.tar.gz - -At the time of this writing, the latest tzcode version used as basis is 2020a. diff --git a/rocklibc/src/_tzcode/_PDCLIB_gmtcheck.c b/rocklibc/src/_tzcode/_PDCLIB_gmtcheck.c deleted file mode 100644 index 713af2b..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_gmtcheck.c +++ /dev/null @@ -1,53 +0,0 @@ -/* _PDCLIB_gmtcheck( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_time_mtx; -#endif - -static void gmtload( struct state * sp ) -{ - if ( _PDCLIB_tzload( gmt, sp, true ) != 0 ) - { - _PDCLIB_tzparse( gmt, sp, true ); - } -} - -void _PDCLIB_gmtcheck( void ) -{ - static bool gmt_is_set; - - _PDCLIB_LOCK( _PDCLIB_time_mtx ); - - if ( ! gmt_is_set ) - { - gmtload( &_PDCLIB_gmtmem ); - gmt_is_set = true; - } - - _PDCLIB_UNLOCK( _PDCLIB_time_mtx ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_gmtsub.c b/rocklibc/src/_tzcode/_PDCLIB_gmtsub.c deleted file mode 100644 index 59d7b8f..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_gmtsub.c +++ /dev/null @@ -1,43 +0,0 @@ -/* _PDCLIB_gmtsub( struct state const *, time_t const *, int_fast32_t, struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* gmtsub is to gmtime as localsub is to localtime. */ -struct tm * _PDCLIB_gmtsub( struct state const * sp, time_t const * timep, int_fast32_t offset, struct tm * tmp ) -{ - struct tm * result; - - result = _PDCLIB_timesub( timep, offset, &_PDCLIB_gmtmem, tmp ); - -#ifdef TM_ZONE - /* Could get fancy here and deliver something such as - "+xx" or "-xx" if offset is non-zero, - but this is no time for a treasure hunt. - */ - tmp->TM_ZONE = ( (char *)( offset ? wildabbr : &_PDCLIB_gmtmem ? _PDCLIB_gmtptr.chars : gmt ) ); -#endif - - return result; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_increment_overflow.c b/rocklibc/src/_tzcode/_PDCLIB_increment_overflow.c deleted file mode 100644 index 4734e0e..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_increment_overflow.c +++ /dev/null @@ -1,45 +0,0 @@ -/* _PDCLIB_increment_overflow( int *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* Normalize logic courtesy Paul Eggert. */ - -bool _PDCLIB_increment_overflow( int * ip, int j ) -{ - int const i = *ip; - - /* If i >= 0 there can only be overflow if i + j > INT_MAX - or if j > INT_MAX - i; given i >= 0, INT_MAX - i cannot overflow. - If i < 0 there can only be overflow if i + j < INT_MIN - or if j < INT_MIN - i; given i < 0, INT_MIN - i cannot overflow. - */ - if ( ( i >= 0 ) ? ( j > _PDCLIB_INT_MAX - i ) : ( j < _PDCLIB_INT_MIN - i ) ) - { - return true; - } - - *ip += j; - return false; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_init_ttinfo.c b/rocklibc/src/_tzcode/_PDCLIB_init_ttinfo.c deleted file mode 100644 index da18c7c..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_init_ttinfo.c +++ /dev/null @@ -1,35 +0,0 @@ -/* _PDCLIB_init_ttinfo( struct ttinfo *, int_fast32_t, bool, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* Initialize *S to a value based on UTOFF, ISDST, and DESIGIDX. */ -void _PDCLIB_init_ttinfo( struct ttinfo * s, int_fast32_t utoff, bool isdst, int desigidx ) -{ - s->utoff = utoff; - s->isdst = isdst; - s->desigidx = desigidx; - s->ttisstd = false; - s->ttisut = false; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_localsub.c b/rocklibc/src/_tzcode/_PDCLIB_localsub.c deleted file mode 100644 index fbdc186..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_localsub.c +++ /dev/null @@ -1,164 +0,0 @@ -/* _PDCLIB_localsub( struct state const *, time_t const *, int_fast32_t, struct tm * const ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* The easy way to behave "as if no library function calls" localtime - is to not call it, so we drop its guts into "localsub", which can be - freely called. (And no, the PANS doesn't require the above behavior, - but it *is* desirable.) - - If successful and SETNAME is nonzero, - set the applicable parts of tzname, timezone and altzone; - however, it's OK to omit this step if the timezone is POSIX-compatible, - since in that case tzset should have already done this step correctly. - SETNAME's type is intfast32_t for compatibility with gmtsub, - but it is actually a boolean and its value should be 0 or 1. -*/ - -/*ARGSUSED*/ -struct tm * _PDCLIB_localsub( struct state const * sp, time_t const * timep, int_fast32_t setname, struct tm * const tmp ) -{ - const struct ttinfo * ttisp; - int i; - struct tm * result; - const time_t t = *timep; - - if ( sp == NULL ) - { - /* Don't bother to set tzname etc.; tzset has already done it. */ - return _PDCLIB_gmtsub( &_PDCLIB_gmtmem, timep, 0, tmp ); - } - - if ( ( sp->goback && t < sp->ats[ 0 ] ) || ( sp->goahead && t > sp->ats[ sp->timecnt - 1 ] ) ) - { - time_t newt = t; - time_t seconds; - time_t years; - - if ( t < sp->ats[ 0 ] ) - { - seconds = sp->ats[ 0 ] - t; - } - else - { - seconds = t - sp->ats[ sp->timecnt - 1 ]; - } - - --seconds; - years = ( seconds / SECSPERREPEAT + 1 ) * YEARSPERREPEAT; - seconds = years * AVGSECSPERYEAR; - - if ( t < sp->ats[ 0 ] ) - { - newt += seconds; - } - else - { - newt -= seconds; - } - - if ( newt < sp->ats[ 0 ] || newt > sp->ats[ sp->timecnt - 1 ] ) - { - return NULL; /* "cannot happen" */ - } - - result = _PDCLIB_localsub( sp, &newt, setname, tmp ); - - if ( result ) - { - int_fast64_t newy; - - newy = result->tm_year; - - if ( t < sp->ats[ 0 ] ) - { - newy -= years; - } - else - { - newy += years; - } - - if ( ! ( _PDCLIB_INT_MIN <= newy && newy <= _PDCLIB_INT_MAX ) ) - { - return NULL; - } - - result->tm_year = newy; - } - - return result; - } - - if ( sp->timecnt == 0 || t < sp->ats[ 0 ] ) - { - i = sp->defaulttype; - } - else - { - int lo = 1; - int hi = sp->timecnt; - - while ( lo < hi ) - { - int mid = ( lo + hi ) >> 1; - - if ( t < sp->ats[ mid ] ) - { - hi = mid; - } - else - { - lo = mid + 1; - } - } - - i = (int) sp->types[ lo - 1 ]; - } - - ttisp = &sp->ttis[ i ]; - - /* To get (wrong) behavior that's compatible with System V Release 2.0 - you'd replace the statement below with - t += ttisp->utoff; - timesub( &t, 0L, sp, tmp ); - */ - result = _PDCLIB_timesub( &t, ttisp->utoff, sp, tmp ); - - if ( result ) - { - result->tm_isdst = ttisp->isdst; -#ifdef TM_ZONE - result->TM_ZONE = (char *) &sp->chars[ ttisp->desigidx ]; -#endif /* defined TM_ZONE */ - - if ( setname ) - { - _PDCLIB_update_tzname_etc( sp, ttisp ); - } - } - - return result; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_localtime_tzset.c b/rocklibc/src/_tzcode/_PDCLIB_localtime_tzset.c deleted file mode 100644 index 988a042..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_localtime_tzset.c +++ /dev/null @@ -1,46 +0,0 @@ -/* _PDCLIB_localtime_tzset( time_t const *, struct tm *, bool ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_time_mtx; -#endif - -#include - -struct tm * _PDCLIB_localtime_tzset( time_t const * timep, struct tm * tmp, bool setname ) -{ - _PDCLIB_LOCK( _PDCLIB_time_mtx ); - - if ( setname || ! lcl_is_set ) - { - _PDCLIB_tzset_unlocked(); - } - - tmp = _PDCLIB_localsub( &_PDCLIB_lclmem, timep, setname, tmp ); - _PDCLIB_UNLOCK( _PDCLIB_time_mtx ); - return tmp; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_mktime_tzname.c b/rocklibc/src/_tzcode/_PDCLIB_mktime_tzname.c deleted file mode 100644 index 2881370..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_mktime_tzname.c +++ /dev/null @@ -1,528 +0,0 @@ -/* _PDCLIB_mktime_tzname( struct state *, struct tm *, bool ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* Adapted from code provided by Robert Elz, who writes: - The "best" way to do mktime I think is based on an idea of Bob - Kridle's (so its said...) from a long time ago. - It does a binary search of the time_t space. Since time_t's are - just 32 bits, its a max of 32 iterations (even at 64 bits it - would still be very reasonable). -*/ - -#ifndef WRONG -#define WRONG (-1) -#endif - -/* Normalize logic courtesy Paul Eggert. */ - -static bool increment_overflow32( int_fast32_t * lp, int m ) -{ - int_fast32_t const l = *lp; - - if ( ( l >= 0 ) ? ( m > _PDCLIB_INT_FAST32_MAX - l ) : ( m < _PDCLIB_INT_FAST32_MIN - l ) ) - { - return true; - } - - *lp += m; - return false; -} - -static bool normalize_overflow( int * tensptr, int * unitsptr, int base ) -{ - int tensdelta; - - tensdelta = ( *unitsptr >= 0 ) ? - ( *unitsptr / base ) : - ( -1 - ( -1 - *unitsptr ) / base ); - *unitsptr -= tensdelta * base; - return _PDCLIB_increment_overflow( tensptr, tensdelta ); -} - -static bool normalize_overflow32( int_fast32_t * tensptr, int * unitsptr, int base ) -{ - int tensdelta; - - tensdelta = ( *unitsptr >= 0 ) ? - ( *unitsptr / base ) : - ( -1 - ( -1 - *unitsptr ) / base ); - *unitsptr -= tensdelta * base; - return increment_overflow32( tensptr, tensdelta ); -} - -static int tmcomp( const struct tm * atmp, const struct tm * btmp ) -{ - int result; - - if ( atmp->tm_year != btmp->tm_year ) - { - return atmp->tm_year < btmp->tm_year ? -1 : 1; - } - - if ( ( result = ( atmp->tm_mon - btmp->tm_mon ) ) == 0 && - ( result = ( atmp->tm_mday - btmp->tm_mday ) ) == 0 && - ( result = ( atmp->tm_hour - btmp->tm_hour ) ) == 0 && - ( result = ( atmp->tm_min - btmp->tm_min ) ) == 0 ) - { - result = atmp->tm_sec - btmp->tm_sec; - } - - return result; -} - -static time_t time2sub( struct tm * tmp, struct tm *(*funcp)( struct state const *, time_t const *, int_fast32_t, struct tm * ), struct state const * sp, const int_fast32_t offset, bool * okayp, bool do_norm_secs ) -{ - int dir; - int i, j; - int saved_seconds; - int_fast32_t li; - time_t lo; - time_t hi; - int_fast32_t y; - time_t newt; - time_t t; - struct tm yourtm, mytm; - - *okayp = false; - yourtm = *tmp; - - if ( do_norm_secs ) - { - if ( normalize_overflow( &yourtm.tm_min, &yourtm.tm_sec, SECSPERMIN ) ) - { - return WRONG; - } - } - - if ( normalize_overflow( &yourtm.tm_hour, &yourtm.tm_min, MINSPERHOUR ) ) - { - return WRONG; - } - - if ( normalize_overflow( &yourtm.tm_mday, &yourtm.tm_hour, HOURSPERDAY ) ) - { - return WRONG; - } - - y = yourtm.tm_year; - - if ( normalize_overflow32( &y, &yourtm.tm_mon, MONSPERYEAR ) ) - { - return WRONG; - } - - /* Turn y into an actual year number for now. - It is converted back to an offset from TM_YEAR_BASE later. - */ - if ( increment_overflow32( &y, TM_YEAR_BASE ) ) - { - return WRONG; - } - - while ( yourtm.tm_mday <= 0 ) - { - if ( increment_overflow32( &y, -1 ) ) - { - return WRONG; - } - - li = y + ( 1 < yourtm.tm_mon ); - yourtm.tm_mday += year_lengths[ _PDCLIB_is_leap( li ) ]; - } - while ( yourtm.tm_mday > DAYSPERLYEAR ) - { - li = y + ( 1 < yourtm.tm_mon ); - yourtm.tm_mday -= year_lengths[ _PDCLIB_is_leap( li ) ]; - - if ( increment_overflow32( &y, 1 ) ) - { - return WRONG; - } - } - - for ( ; ; ) - { - i = mon_lengths[ _PDCLIB_is_leap( y ) ][ yourtm.tm_mon ]; - - if ( yourtm.tm_mday <= i ) - { - break; - } - - yourtm.tm_mday -= i; - - if ( ++yourtm.tm_mon >= MONSPERYEAR ) - { - yourtm.tm_mon = 0; - - if ( increment_overflow32( &y, 1 ) ) - { - return WRONG; - } - } - } - - if ( increment_overflow32( &y, -TM_YEAR_BASE ) ) - { - return WRONG; - } - - if ( ! ( _PDCLIB_INT_MIN <= y && y <= _PDCLIB_INT_MAX ) ) - { - return WRONG; - } - - yourtm.tm_year = y; - - if ( yourtm.tm_sec >= 0 && yourtm.tm_sec < SECSPERMIN ) - { - saved_seconds = 0; - } - else if ( y + TM_YEAR_BASE < EPOCH_YEAR ) - { - /* We can't set tm_sec to 0, because that might push the - time below the minimum representable time. - Set tm_sec to 59 instead. - This assumes that the minimum representable time is - not in the same minute that a leap second was deleted from, - which is a safer assumption than using 58 would be. - */ - if ( _PDCLIB_increment_overflow( &yourtm.tm_sec, 1 - SECSPERMIN ) ) - { - return WRONG; - } - - saved_seconds = yourtm.tm_sec; - yourtm.tm_sec = SECSPERMIN - 1; - } - else - { - saved_seconds = yourtm.tm_sec; - yourtm.tm_sec = 0; - } - - /* Do a binary search (this works whatever time_t's type is). */ - lo = _PDCLIB_TIME_MIN; - hi = _PDCLIB_TIME_MAX; - - for ( ; ; ) - { - t = lo / 2 + hi / 2; - - if ( t < lo ) - { - t = lo; - } - else if ( t > hi ) - { - t = hi; - } - - if ( ! funcp( sp, &t, offset, &mytm ) ) - { - /* Assume that t is too extreme to be represented in - a struct tm; arrange things so that it is less - extreme on the next pass. - */ - dir = ( t > 0 ) ? 1 : -1; - } - else - { - dir = tmcomp( &mytm, &yourtm ); - } - - if ( dir != 0 ) - { - if ( t == lo ) - { - if ( t == _PDCLIB_TIME_MAX ) - { - return WRONG; - } - - ++t; - ++lo; - } - else if ( t == hi ) - { - if ( t == _PDCLIB_TIME_MIN ) - { - return WRONG; - } - - --t; - --hi; - } - - if ( lo > hi ) - { - return WRONG; - } - - if ( dir > 0 ) - { - hi = t; - } - else - { - lo = t; - } - - continue; - } - -#if defined TM_GMTOFF && ! UNINIT_TRAP - if ( mytm.TM_GMTOFF != yourtm.TM_GMTOFF - && ( yourtm.TM_GMTOFF < 0 - ? ( -SECSPERDAY <= yourtm.TM_GMTOFF - && ( mytm.TM_GMTOFF <= - ( SMALLEST ( _PDCLIB_INT_FAST32_MAX, _PDCLIB_LONG_MAX ) - + yourtm.TM_GMTOFF ) ) ) - : ( yourtm.TM_GMTOFF <= SECSPERDAY - && ( ( BIGGEST ( _PDCLIB_INT_FAST32_MIN, _PDCLIB_LONG_MIN ) - + yourtm.TM_GMTOFF ) - <= mytm.TM_GMTOFF ) ) ) ) - { - /* MYTM matches YOURTM except with the wrong UT offset. - YOURTM.TM_GMTOFF is plausible, so try it instead. - It's OK if YOURTM.TM_GMTOFF contains uninitialized data, - since the guess gets checked. - */ - time_t altt = t; - int_fast32_t diff = mytm.TM_GMTOFF - yourtm.TM_GMTOFF; - - if ( ! increment_overflow_time( &altt, diff ) ) - { - struct tm alttm; - if ( funcp( sp, &altt, offset, &alttm ) - && alttm.tm_isdst == mytm.tm_isdst - && alttm.TM_GMTOFF == yourtm.TM_GMTOFF - && tmcomp( &alttm, &yourtm ) == 0 ) - { - t = altt; - mytm = alttm; - } - } - } -#endif - - if ( yourtm.tm_isdst < 0 || mytm.tm_isdst == yourtm.tm_isdst ) - { - break; - } - - /* Right time, wrong type. - Hunt for right time, right type. - It's okay to guess wrong since the guess - gets checked. - */ - if ( sp == NULL ) - { - return WRONG; - } - - for ( i = sp->typecnt - 1; i >= 0; --i ) - { - if ( sp->ttis[ i ].isdst != yourtm.tm_isdst ) - { - continue; - } - - for ( j = sp->typecnt - 1; j >= 0; --j ) - { - if ( sp->ttis[ j ].isdst == yourtm.tm_isdst ) - { - continue; - } - - newt = ( t + sp->ttis[ j ].utoff - sp->ttis[ i ].utoff ); - - if ( ! funcp( sp, &newt, offset, &mytm ) ) - { - continue; - } - - if ( tmcomp( &mytm, &yourtm ) != 0 ) - { - continue; - } - - if ( mytm.tm_isdst != yourtm.tm_isdst ) - { - continue; - } - - /* We have a match. */ - t = newt; - goto label; - } - } - - return WRONG; - } - -label: - newt = t + saved_seconds; - - if ( ( newt < t ) != ( saved_seconds < 0 ) ) - { - return WRONG; - } - - t = newt; - - if ( funcp( sp, &t, offset, tmp ) ) - { - *okayp = true; - } - - return t; -} - -static time_t time2( struct tm * tmp, struct tm *(*funcp)( struct state const *, time_t const *, int_fast32_t, struct tm * ), struct state const * sp, const int_fast32_t offset, bool * okayp ) -{ - time_t t; - - /* First try without normalization of seconds - (in case tm_sec contains a value associated with a leap second). - If that fails, try with normalization of seconds. - */ - t = time2sub( tmp, funcp, sp, offset, okayp, false ); - return *okayp ? t : time2sub( tmp, funcp, sp, offset, okayp, true ); -} - -static time_t time1( struct tm * tmp, struct tm *(*funcp)( struct state const *, time_t const *, int_fast32_t, struct tm * ), struct state const * sp, const int_fast32_t offset ) -{ - time_t t; - int samei, otheri; - int sameind, otherind; - int i; - int nseen; - char seen[TZ_MAX_TYPES]; - unsigned char types[TZ_MAX_TYPES]; - bool okay; - - if ( tmp == NULL ) - { - *_PDCLIB_errno_func() = _PDCLIB_EINVAL; - return WRONG; - } - - if ( tmp->tm_isdst > 1 ) - { - tmp->tm_isdst = 1; - } - - t = time2( tmp, funcp, sp, offset, &okay ); - - if ( okay ) - { - return t; - } - - if ( tmp->tm_isdst < 0 ) - { -#ifdef PCTS - /* POSIX Conformance Test Suite code courtesy Grant Sullivan. */ - tmp->tm_isdst = 0; /* reset to std and try again */ -#else - return t; -#endif - } - - /* We're supposed to assume that somebody took a time of one type - and did some math on it that yielded a "struct tm" that's bad. - We try to divine the type they started from and adjust to the - type they need. - */ - if ( sp == NULL ) - { - return WRONG; - } - - for ( i = 0; i < sp->typecnt; ++i ) - { - seen[ i ] = false; - } - - nseen = 0; - - for ( i = sp->timecnt - 1; i >= 0; --i ) - { - if ( ! seen[ sp->types[ i ] ] ) - { - seen[ sp->types[ i ] ] = true; - types[ nseen++ ] = sp->types[ i ]; - } - } - - for ( sameind = 0; sameind < nseen; ++sameind ) - { - samei = types[ sameind ]; - - if ( sp->ttis[ samei ].isdst != tmp->tm_isdst ) - { - continue; - } - - for ( otherind = 0; otherind < nseen; ++otherind ) - { - otheri = types[ otherind ]; - - if ( sp->ttis[ otheri ].isdst == tmp->tm_isdst ) - { - continue; - } - - tmp->tm_sec += ( sp->ttis[ otheri ].utoff - sp->ttis[ samei ].utoff ); - tmp->tm_isdst = ! tmp->tm_isdst; - t = time2( tmp, funcp, sp, offset, &okay ); - - if ( okay ) - { - return t; - } - - tmp->tm_sec -= ( sp->ttis[ otheri ].utoff - sp->ttis[ samei ].utoff ); - tmp->tm_isdst = ! tmp->tm_isdst; - } - } - - return WRONG; -} - -time_t _PDCLIB_mktime_tzname( struct state * sp, struct tm * tmp, bool setname ) -{ - if ( sp ) - { - return time1( tmp, _PDCLIB_localsub, sp, setname ); - } - else - { - _PDCLIB_gmtcheck(); - return time1( tmp, _PDCLIB_gmtsub, &_PDCLIB_gmtmem, 0 ); - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_timesub.c b/rocklibc/src/_tzcode/_PDCLIB_timesub.c deleted file mode 100644 index d1b5136..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_timesub.c +++ /dev/null @@ -1,190 +0,0 @@ -/* _PDCLIB_timesub( const time_t *, int_fast32_t, const struct state *, struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -/* Return the number of leap years through the end of the given year - where, to make the math easy, the answer for year zero is defined as zero. -*/ -static int leaps_thru_end_of_nonneg( int y ) -{ - return y / 4 - y / 100 + y / 400; -} - -static int leaps_thru_end_of( const int y ) -{ - return ( y < 0 - ? -1 - leaps_thru_end_of_nonneg( -1 - y ) - : leaps_thru_end_of_nonneg( y ) ); -} - -struct tm * _PDCLIB_timesub( const time_t * timep, int_fast32_t offset, const struct state * sp, struct tm * tmp ) -{ - const struct lsinfo * lp; - time_t tdays; - int idays; /* unsigned would be so 2003 */ - int_fast64_t rem; - int y; - const int * ip; - int_fast64_t corr; - bool hit; - int i; - - corr = 0; - hit = false; - i = ( sp == NULL ) ? 0 : sp->leapcnt; - - while ( --i >= 0 ) - { - lp = &sp->lsis[ i ]; - if ( *timep >= lp->trans ) - { - corr = lp->corr; - hit = ( *timep == lp->trans && ( i == 0 ? 0 : lp[ -1 ].corr ) < corr ); - break; - } - } - - y = EPOCH_YEAR; - tdays = *timep / SECSPERDAY; - rem = *timep % SECSPERDAY; - - while ( tdays < 0 || tdays >= year_lengths[ _PDCLIB_is_leap( y ) ] ) - { - int newy; - time_t tdelta; - int idelta; - int leapdays; - - tdelta = tdays / DAYSPERLYEAR; - - if ( ! ( ( ! _PDCLIB_TYPE_SIGNED( time_t ) || _PDCLIB_INT_MIN <= tdelta ) && tdelta <= _PDCLIB_INT_MAX ) ) - { - goto out_of_range; - } - - idelta = tdelta; - - if ( idelta == 0 ) - { - idelta = ( tdays < 0 ) ? -1 : 1; - } - - newy = y; - - if ( _PDCLIB_increment_overflow( &newy, idelta ) ) - { - goto out_of_range; - } - - leapdays = leaps_thru_end_of( newy - 1 ) - leaps_thru_end_of( y - 1 ); - tdays -= ( (time_t)newy - y ) * DAYSPERNYEAR; - tdays -= leapdays; - y = newy; - } - - /* Given the range, we can now fearlessly cast... */ - idays = tdays; - rem += offset - corr; - - while ( rem < 0 ) - { - rem += SECSPERDAY; - --idays; - } - - while ( rem >= SECSPERDAY ) - { - rem -= SECSPERDAY; - ++idays; - } - - while ( idays < 0 ) - { - if ( _PDCLIB_increment_overflow( &y, -1 ) ) - { - goto out_of_range; - } - - idays += year_lengths[ _PDCLIB_is_leap( y ) ]; - } - - while ( idays >= year_lengths[ _PDCLIB_is_leap( y ) ] ) - { - idays -= year_lengths[ _PDCLIB_is_leap( y ) ]; - - if ( _PDCLIB_increment_overflow( &y, 1 ) ) - { - goto out_of_range; - } - } - - tmp->tm_year = y; - - if ( _PDCLIB_increment_overflow( &tmp->tm_year, -TM_YEAR_BASE ) ) - { - goto out_of_range; - } - - tmp->tm_yday = idays; - /* The "extra" mods below avoid overflow problems. */ - tmp->tm_wday = EPOCH_WDAY + - ( ( y - EPOCH_YEAR ) % DAYSPERWEEK ) * - ( DAYSPERNYEAR % DAYSPERWEEK ) + - leaps_thru_end_of( y - 1 ) - - leaps_thru_end_of( EPOCH_YEAR - 1 ) + - idays; - tmp->tm_wday %= DAYSPERWEEK; - - if ( tmp->tm_wday < 0 ) - { - tmp->tm_wday += DAYSPERWEEK; - } - - tmp->tm_hour = (int)( rem / SECSPERHOUR ); - rem %= SECSPERHOUR; - tmp->tm_min = (int)( rem / SECSPERMIN ); - - /* A positive leap second requires a special - representation. This uses "... ??:59:60" et seq. - */ - tmp->tm_sec = (int) ( rem % SECSPERMIN ) + hit; - ip = mon_lengths[ _PDCLIB_is_leap( y ) ]; - - for ( tmp->tm_mon = 0; idays >= ip[ tmp->tm_mon ]; ++( tmp->tm_mon ) ) - { - idays -= ip[ tmp->tm_mon ]; - } - - tmp->tm_mday = (int)( idays + 1 ); - tmp->tm_isdst = 0; -#ifdef TM_GMTOFF - tmp->TM_GMTOFF = offset; -#endif /* defined TM_GMTOFF */ - return tmp; - - out_of_range: - *_PDCLIB_errno_func() = _PDCLIB_EOVERFLOW; - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_tzload.c b/rocklibc/src/_tzcode/_PDCLIB_tzload.c deleted file mode 100644 index 5e7e0cc..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_tzload.c +++ /dev/null @@ -1,683 +0,0 @@ -/* _PDCLIB_tzload( char const *, struct _PDCLIB_timezone *, bool ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#include -#include -#include - -static int_fast32_t detzcode( const char * codep ) -{ - int_fast32_t result; - int i; - int_fast32_t one = 1; - int_fast32_t halfmaxval = one << ( 32 - 2 ); - int_fast32_t maxval = halfmaxval - 1 + halfmaxval; - int_fast32_t minval = -1 - maxval; - - result = codep[ 0 ] & 0x7f; - - for ( i = 1; i < 4; ++i ) - { - result = ( result << 8 ) | ( codep[ i ] & 0xff ); - } - - if ( codep[ 0 ] & 0x80 ) - { - /* Do two's-complement negation even on non-two's-complement machines. - If the result would be minval - 1, return minval. - */ - result -= ! _PDCLIB_TWOS_COMPLEMENT && result != 0; - result += minval; - } - - return result; -} - -static int_fast64_t detzcode64( const char * codep ) -{ - uint_fast64_t result; - int i; - int_fast64_t one = 1; - int_fast64_t halfmaxval = one << ( 64 - 2 ); - int_fast64_t maxval = halfmaxval - 1 + halfmaxval; - int_fast64_t minval = - _PDCLIB_TWOS_COMPLEMENT - maxval; - - result = codep[ 0 ] & 0x7f; - - for ( i = 1; i < 8; ++i ) - { - result = ( result << 8 ) | ( codep[ i ] & 0xff ); - } - - if ( codep[ 0 ] & 0x80 ) - { - /* Do two's-complement negation even on non-two's-complement machines. - If the result would be minval - 1, return minval. - */ - result -= ! _PDCLIB_TWOS_COMPLEMENT && result != 0; - result += minval; - } - - return result; -} - -static bool differ_by_repeat( const time_t t1, const time_t t0 ) -{ - if ( ( sizeof( time_t ) * _PDCLIB_CHAR_BIT ) - _PDCLIB_TYPE_SIGNED( time_t ) < SECSPERREPEAT_BITS ) - { - return 0; - } - - return ( t1 - t0 ) == SECSPERREPEAT; -} - -static bool typesequiv( const struct state * sp, int a, int b ) -{ - bool result; - - if ( sp == NULL || - a < 0 || a >= sp->typecnt || - b < 0 || b >= sp->typecnt ) - { - result = false; - } - else - { - const struct ttinfo * ap = &sp->ttis[ a ]; - const struct ttinfo * bp = &sp->ttis[ b ]; - - result = ( ap->utoff == bp->utoff && - ap->isdst == bp->isdst && - ap->ttisstd == bp->ttisstd && - ap->ttisut == bp->ttisut && - ( strcmp( &sp->chars[ ap->desigidx ], &sp->chars[ bp->desigidx ] ) == 0 ) - ); - } - - return result; -} - -#define TZ_MAGIC "TZif" - -struct tzhead -{ - char tzh_magic[ 4 ]; /* TZ_MAGIC */ - char tzh_version[ 1 ]; /* '\0' or '2' or '3' as of 2013 */ - char tzh_reserved[ 15 ]; /* reserved; must be zero */ - char tzh_ttisutcnt[ 4 ]; /* coded number of trans. time flags */ - char tzh_ttisstdcnt[ 4 ]; /* coded number of trans. time flags */ - char tzh_leapcnt[ 4 ]; /* coded number of leap seconds */ - char tzh_timecnt[ 4 ]; /* coded number of transition times */ - char tzh_typecnt[ 4 ]; /* coded number of local time types */ - char tzh_charcnt[ 4 ]; /* coded number of abbr. chars */ -}; - -/* Input buffer for data read from a compiled tz file. */ -union input_buffer -{ - /* The first part of the buffer, interpreted as a header. */ - struct tzhead tzhead; - - /* The entire buffer. */ - char buf[ 2 * sizeof ( struct tzhead ) + 2 * sizeof ( struct state ) + 4 * TZ_MAX_TIMES ]; -}; - -/* _PDCLIB_TZDIR with a trailing '/' rather than a trailing '\0'. */ -static char const tzdirslash[ sizeof _PDCLIB_TZDIR + 1 ] = _PDCLIB_TZDIR "/"; - -/* Local storage needed for 'tzloadbody'. */ -union local_storage -{ - /* The results of analyzing the file's contents after it is opened. */ - struct file_analysis - { - /* The input buffer. */ - union input_buffer u; - - /* A temporary state used for parsing a TZ string in the file. */ - struct state st; - } u; - - /* The file name to be opened. */ - char fullname[ BIGGEST ( sizeof ( struct file_analysis ), sizeof tzdirslash + 1024 ) ]; -}; - -static int_fast64_t leapcorr( struct state const * sp, time_t t ) -{ - struct lsinfo const * lp; - int i; - - i = sp->leapcnt; - - while ( --i >= 0 ) - { - lp = &sp->lsis[ i ]; - - if ( t >= lp->trans ) - { - return lp->corr; - } - } - - return 0; -} - -/* Load tz data from the file named NAME into *SP. Read extended - format if DOEXTEND. Use *LSP for temporary storage. Return 0 on - success, an errno value on failure. */ -static int tzloadbody( char const * name, struct state * sp, bool doextend, union local_storage * lsp ) -{ - int i; - FILE * fid; - int stored; - size_t nread; - bool doaccess; - union input_buffer * up = &lsp->u.u; - size_t tzheadsize = sizeof ( struct tzhead ); - - sp->goback = sp->goahead = false; - - if ( ! name ) - { - name = _PDCLIB_TZDEFAULT; - - if ( ! name ) - { - return _PDCLIB_EINVAL; - } - } - - if ( name[ 0 ] == ':' ) - { - ++name; - } - - doaccess = name[ 0 ] == '/'; - - if ( ! doaccess ) - { - char const * dot; - size_t namelen = strlen( name ); - - if ( sizeof lsp->fullname - sizeof tzdirslash <= namelen ) - { - return _PDCLIB_ENAMETOOLONG; - } - - /* Create a string "TZDIR/NAME". Using sprintf here - would pull in stdio (and would fail if the - resulting string length exceeded INT_MAX!). - */ - memcpy( lsp->fullname, tzdirslash, sizeof tzdirslash ); - strcpy( lsp->fullname + sizeof tzdirslash, name ); - - /* Set doaccess if NAME contains a ".." file name - component, as such a name could read a file outside - the TZDIR virtual subtree. - */ - for ( dot = name; ( dot = strchr( dot, '.' ) ); ++dot ) - { - if ( ( dot == name || dot[ -1 ] == '/' ) && dot[ 1 ] == '.' && ( dot[ 2 ] == '/' || ! dot[ 2 ] ) ) - { - doaccess = true; - break; - } - } - - name = lsp->fullname; - } - - fid = fopen( name, "rb" ); - - if ( fid == NULL ) - { - return errno; - } - - nread = fread( up->buf, 1, sizeof up->buf, fid ); - - if ( nread < tzheadsize ) - { - int err = errno; - - if ( ! ferror( fid ) ) - { - err = _PDCLIB_EINVAL; - } - - fclose( fid ); - return err; - } - - if ( fclose( fid ) == EOF ) - { - return errno; - } - - for ( stored = 4; stored <= 8; stored *= 2 ) - { - int_fast32_t ttisstdcnt = detzcode( up->tzhead.tzh_ttisstdcnt ); - int_fast32_t ttisutcnt = detzcode( up->tzhead.tzh_ttisutcnt ); - int_fast64_t prevtr = 0; - int_fast32_t prevcorr = 0; - int_fast32_t leapcnt = detzcode( up->tzhead.tzh_leapcnt ); - int_fast32_t timecnt = detzcode( up->tzhead.tzh_timecnt ); - int_fast32_t typecnt = detzcode( up->tzhead.tzh_typecnt ); - int_fast32_t charcnt = detzcode( up->tzhead.tzh_charcnt ); - char const *p = up->buf + tzheadsize; - /* Although tzfile(5) currently requires typecnt to be nonzero, - support future formats that may allow zero typecnt - in files that have a TZ string and no transitions. - */ - if ( ! ( 0 <= leapcnt && leapcnt < TZ_MAX_LEAPS - && 0 <= typecnt && typecnt < TZ_MAX_TYPES - && 0 <= timecnt && timecnt < TZ_MAX_TIMES - && 0 <= charcnt && charcnt < TZ_MAX_CHARS - && ( ttisstdcnt == typecnt || ttisstdcnt == 0 ) - && ( ttisutcnt == typecnt || ttisutcnt == 0 ) ) ) - { - return _PDCLIB_EINVAL; - } - - if ( nread - < ( tzheadsize /* struct tzhead */ - + timecnt * stored /* ats */ - + timecnt /* types */ - + typecnt * 6 /* ttinfos */ - + charcnt /* chars */ - + leapcnt * ( stored + 4 ) /* lsinfos */ - + ttisstdcnt /* ttisstds */ - + ttisutcnt ) ) /* ttisuts */ - { - return _PDCLIB_EINVAL; - } - - sp->leapcnt = leapcnt; - sp->timecnt = timecnt; - sp->typecnt = typecnt; - sp->charcnt = charcnt; - - /* Read transitions, discarding those out of time_t range. - But pretend the last transition before _PDCLIB_TIME_MIN - occurred at _PDCLIB_TIME_MIN. - */ - timecnt = 0; - - for ( i = 0; i < sp->timecnt; ++i ) - { - int_fast64_t at = stored == 4 ? detzcode( p ) : detzcode64( p ); - sp->types[ i ] = at <= _PDCLIB_TIME_MAX; - - if ( sp->types[ i ] ) - { - time_t attime = ( ( _PDCLIB_TYPE_SIGNED( time_t ) ? at < _PDCLIB_TIME_MIN : at < 0 ) ? _PDCLIB_TIME_MIN : at ); - - if ( timecnt && attime <= sp->ats[ timecnt - 1 ] ) - { - if ( attime < sp->ats[ timecnt - 1 ] ) - { - return _PDCLIB_EINVAL; - } - - sp->types[ i - 1 ] = 0; - timecnt--; - } - - sp->ats[ timecnt++ ] = attime; - } - - p += stored; - } - - timecnt = 0; - - for ( i = 0; i < sp->timecnt; ++i ) - { - unsigned char typ = *p++; - - if ( sp->typecnt <= typ ) - { - return _PDCLIB_EINVAL; - } - - if ( sp->types[ i ] ) - { - sp->types[ timecnt++ ] = typ; - } - } - - sp->timecnt = timecnt; - - for ( i = 0; i < sp->typecnt; ++i ) - { - struct ttinfo * ttisp; - unsigned char isdst, desigidx; - - ttisp = &sp->ttis[ i ]; - ttisp->utoff = detzcode( p ); - p += 4; - isdst = *p++; - - if ( ! ( isdst < 2 ) ) - { - return _PDCLIB_EINVAL; - } - - ttisp->isdst = isdst; - desigidx = *p++; - - if ( ! ( desigidx < sp->charcnt ) ) - { - return _PDCLIB_EINVAL; - } - - ttisp->desigidx = desigidx; - } - - for ( i = 0; i < sp->charcnt; ++i ) - { - sp->chars[ i ] = *p++; - } - - sp->chars[ i ] = '\0'; /* ensure '\0' at end */ - - /* Read leap seconds, discarding those out of time_t range. */ - leapcnt = 0; - - for ( i = 0; i < sp->leapcnt; ++i ) - { - int_fast64_t tr = stored == 4 ? detzcode( p ) : detzcode64( p ); - int_fast32_t corr = detzcode( p + stored ); - p += stored + 4; - - /* Leap seconds cannot occur before the Epoch. */ - if ( tr < 0 ) - { - return _PDCLIB_EINVAL; - } - - if ( tr <= _PDCLIB_TIME_MAX ) - { - /* Leap seconds cannot occur more than once per UTC month, - and UTC months are at least 28 days long (minus 1 - second for a negative leap second). Each leap second's - correction must differ from the previous one's by 1 - second. - */ - if ( tr - prevtr < 28 * SECSPERDAY - 1 || ( corr != prevcorr - 1 && corr != prevcorr + 1 ) ) - { - return _PDCLIB_EINVAL; - } - - sp->lsis[ leapcnt ].trans = prevtr = tr; - sp->lsis[ leapcnt ].corr = prevcorr = corr; - ++leapcnt; - } - } - - sp->leapcnt = leapcnt; - - for ( i = 0; i < sp->typecnt; ++i ) - { - struct ttinfo * ttisp; - - ttisp = &sp->ttis[ i ]; - - if ( ttisstdcnt == 0 ) - { - ttisp->ttisstd = false; - } - else - { - if ( *p != true && *p != false ) - { - return _PDCLIB_EINVAL; - } - - ttisp->ttisstd = *p++; - } - } - - for ( i = 0; i < sp->typecnt; ++i ) - { - struct ttinfo * ttisp; - - ttisp = &sp->ttis[ i ]; - - if ( ttisutcnt == 0 ) - { - ttisp->ttisut = false; - } - else - { - if ( *p != true && *p != false ) - { - return _PDCLIB_EINVAL; - } - - ttisp->ttisut = *p++; - } - } - - /* If this is an old file, we're done. */ - if ( up->tzhead.tzh_version[ 0 ] == '\0' ) - { - break; - } - - nread -= p - up->buf; - memmove( up->buf, p, nread ); - } - - if ( doextend && nread > 2 && up->buf[ 0 ] == '\n' && up->buf[ nread - 1 ] == '\n' && sp->typecnt + 2 <= TZ_MAX_TYPES ) - { - struct state *ts = &lsp->u.st; - - up->buf[ nread - 1 ] = '\0'; - - if ( _PDCLIB_tzparse( &up->buf[ 1 ], ts, false ) ) - { - /* Attempt to reuse existing abbreviations. - Without this, America/Anchorage would be right on - the edge after 2037 when TZ_MAX_CHARS is 50, as - sp->charcnt equals 40 (for LMT AST AWT APT AHST - AHDT YST AKDT AKST) and ts->charcnt equals 10 - (for AKST AKDT). Reusing means sp->charcnt can - stay 40 in this example. */ - int gotabbr = 0; - int charcnt = sp->charcnt; - - for ( i = 0; i < ts->typecnt; ++i ) - { - char * tsabbr = ts->chars + ts->ttis[ i ].desigidx; - int j; - - for ( j = 0; j < charcnt; ++j ) - { - if ( strcmp( sp->chars + j, tsabbr ) == 0 ) - { - ts->ttis[ i ].desigidx = j; - ++gotabbr; - break; - } - } - - if ( ! ( j < charcnt ) ) - { - int tsabbrlen = strlen( tsabbr ); - - if ( j + tsabbrlen < TZ_MAX_CHARS ) - { - strcpy( sp->chars + j, tsabbr ); - charcnt = j + tsabbrlen + 1; - ts->ttis[ i ].desigidx = j; - ++gotabbr; - } - } - } - - if ( gotabbr == ts->typecnt ) - { - sp->charcnt = charcnt; - - /* Ignore any trailing, no-op transitions generated - by zic as they don't help here and can run afoul - of bugs in zic 2016j or earlier. */ - while ( 1 < sp->timecnt && ( sp->types[ sp->timecnt - 1 ] == sp->types[ sp->timecnt - 2 ] ) ) - { - sp->timecnt--; - } - - for ( i = 0; i < ts->timecnt; ++i ) - { - if ( sp->timecnt == 0 || ( sp->ats[ sp->timecnt - 1 ] < ts->ats[ i ] + leapcorr( sp, ts->ats[ i ] ) ) ) - { - break; - } - } - - while ( i < ts->timecnt && sp->timecnt < TZ_MAX_TIMES ) - { - sp->ats[ sp->timecnt ] = ts->ats[ i ] + leapcorr( sp, ts->ats[ i ] ); - sp->types[ sp->timecnt ] = ( sp->typecnt + ts->types[ i ] ); - sp->timecnt++; - ++i; - } - - for ( i = 0; i < ts->typecnt; ++i ) - { - sp->ttis[ sp->typecnt++ ] = ts->ttis[ i ]; - } - } - } - } - - if ( sp->typecnt == 0 ) - { - return _PDCLIB_EINVAL; - } - - if ( sp->timecnt > 1 ) - { - for ( i = 1; i < sp->timecnt; ++i ) - { - if ( typesequiv( sp, sp->types[ i ], sp->types[ 0 ] ) && differ_by_repeat( sp->ats[ i ], sp->ats[ 0 ] ) ) - { - sp->goback = true; - break; - } - } - - for ( i = sp->timecnt - 2; i >= 0; --i ) - { - if ( typesequiv( sp, sp->types[ sp->timecnt - 1 ], sp->types[ i ] ) && differ_by_repeat( sp->ats[ sp->timecnt - 1 ], sp->ats[ i ] ) ) - { - sp->goahead = true; - break; - } - } - } - - /* Infer sp->defaulttype from the data. Although this default - type is always zero for data from recent tzdb releases, - things are trickier for data from tzdb 2018e or earlier. - - The first set of heuristics work around bugs in 32-bit data - generated by tzdb 2013c or earlier. The workaround is for - zones like Australia/Macquarie where timestamps before the - first transition have a time type that is not the earliest - standard-time type. See: - https://mm.icann.org/pipermail/tz/2013-May/019368.html - */ - /* If type 0 is unused in transitions, it's the type to use for early times. */ - for ( i = 0; i < sp->timecnt; ++i ) - { - if ( sp->types[ i ] == 0 ) - { - break; - } - } - - i = i < sp->timecnt ? -1 : 0; - - /* Absent the above, - if there are transition times - and the first transition is to a daylight time - find the standard type less than and closest to - the type of the first transition. - */ - if ( i < 0 && sp->timecnt > 0 && sp->ttis[ sp->types[ 0 ] ].isdst ) - { - i = sp->types[ 0 ]; - - while ( --i >= 0 ) - { - if ( ! sp->ttis[ i ].isdst ) - { - break; - } - } - } - - /* The next heuristics are for data generated by tzdb 2018e or - earlier, for zones like EST5EDT where the first transition - is to DST. - */ - /* If no result yet, find the first standard type. - If there is none, punt to type zero. - */ - if ( i < 0 ) - { - i = 0; - - while ( sp->ttis[ i ].isdst ) - { - if ( ++i >= sp->typecnt ) - { - i = 0; - break; - } - } - } - - /* A simple 'sp->defaulttype = 0;' would suffice here if we - didn't have to worry about 2018e-or-earlier data. Even - simpler would be to remove the defaulttype member and just - use 0 in its place. - */ - sp->defaulttype = i; - - return 0; -} - -/* Load tz data from the file named NAME into *SP. Read extended - format if DOEXTEND. Return 0 on success, an errno value on failure. -*/ -int _PDCLIB_tzload( char const * name, struct state * sp, bool doextend ) -{ - union local_storage ls; - return tzloadbody( name, sp, doextend, &ls ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_tzparse.c b/rocklibc/src/_tzcode/_PDCLIB_tzparse.c deleted file mode 100644 index d139bf5..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_tzparse.c +++ /dev/null @@ -1,775 +0,0 @@ -/* _PDCLIB_tzparse( char const *, struct _PDCLIB_timezone *, bool ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#include -#include - -/* The DST rules to use if TZ has no rules and we can't load TZDEFRULES. - Default to US rules as of 2017-05-07. - POSIX does not specify the default DST rules; - for historical reasons, US rules are a common default. -*/ -#ifndef TZDEFRULESTRING -#define TZDEFRULESTRING ",M3.2.0,M11.1.0" -#endif - -#ifndef TZDEFRULES -#define TZDEFRULES "posixrules" -#endif - -enum rule_t -{ - JULIAN_DAY, /* Jn = Julian day */ - DAY_OF_YEAR, /* n = day of year */ - MONTH_NTH_DAY_OF_WEEK /* Mm.n.d = month, week, day of week */ -}; - -struct rule -{ - enum rule_t type; /* type of rule */ - int day; /* day number of rule */ - int week; /* week number of rule */ - int mon; /* month number of rule */ - int_fast32_t time; /* transition time of rule */ -}; - -/* Given a pointer into a timezone string, extract a number from that string. - Check that the number is within a specified range; if it is not, return - NULL. - Otherwise, return a pointer to the first character not part of the number. -*/ -static const char * getnum( const char * strp, int * nump, int min, int max ) -{ - char c; - int num; - - if ( strp == NULL || ! isdigit( (unsigned char)( c = *strp ) ) ) - { - return NULL; - } - - num = 0; - - do - { - num = num * 10 + ( c - '0' ); - - if ( num > max ) - { - return NULL; /* illegal value */ - } - - c = *++strp; - } while ( isdigit( (unsigned char)c ) ); - - if ( num < min ) - { - return NULL; /* illegal value */ - } - - *nump = num; - return strp; -} - -/* Given a pointer into a timezone string, extract a number of seconds, - in hh[:mm[:ss]] form, from the string. - If any error occurs, return NULL. - Otherwise, return a pointer to the first character not part of the number - of seconds. -*/ -static const char * getsecs( const char * strp, int_fast32_t * secsp ) -{ - int num; - - /* 'HOURSPERDAY * DAYSPERWEEK - 1' allows quasi-Posix rules like - "M10.4.6/26", which does not conform to Posix, - but which specifies the equivalent of - "02:00 on the first Sunday on or after 23 Oct". - */ - strp = getnum( strp, &num, 0, HOURSPERDAY * DAYSPERWEEK - 1 ); - - if ( strp == NULL ) - { - return NULL; - } - - *secsp = num * (int_fast32_t) SECSPERHOUR; - - if ( *strp == ':' ) - { - ++strp; - strp = getnum( strp, &num, 0, MINSPERHOUR - 1 ); - - if ( strp == NULL ) - { - return NULL; - } - - *secsp += num * SECSPERMIN; - - if ( *strp == ':' ) - { - ++strp; - /* 'SECSPERMIN' allows for leap seconds. */ - strp = getnum( strp, &num, 0, SECSPERMIN ); - - if ( strp == NULL ) - { - return NULL; - } - - *secsp += num; - } - } - - return strp; -} - -/* Given a pointer into a timezone string, extract an offset, in - [+-]hh[:mm[:ss]] form, from the string. - If any error occurs, return NULL. - Otherwise, return a pointer to the first character not part of the time. -*/ -static const char * getoffset( const char * strp, int_fast32_t * offsetp ) -{ - bool neg = false; - - if ( *strp == '-' ) - { - neg = true; - ++strp; - } - else if ( *strp == '+' ) - { - ++strp; - } - - strp = getsecs( strp, offsetp ); - - if ( strp == NULL ) - { - return NULL; /* illegal time */ - } - - if ( neg ) - { - *offsetp = - *offsetp; - } - - return strp; -} - -/* Given a pointer into a timezone string, extract a rule in the form - date[/time]. See POSIX section 8 for the format of "date" and "time". - If a valid rule is not found, return NULL. - Otherwise, return a pointer to the first character not part of the rule. -*/ -static const char * getrule( const char * strp, struct rule * rulep ) -{ - if ( *strp == 'J' ) - { - /* Julian day. */ - rulep->type = JULIAN_DAY; - ++strp; - strp = getnum( strp, &rulep->day, 1, DAYSPERNYEAR ); - } - else if ( *strp == 'M' ) - { - /* Month, week, day. */ - rulep->type = MONTH_NTH_DAY_OF_WEEK; - ++strp; - strp = getnum( strp, &rulep->mon, 1, MONSPERYEAR ); - - if ( strp == NULL ) - { - return NULL; - } - - if ( *strp++ != '.' ) - { - return NULL; - } - - strp = getnum( strp, &rulep->week, 1, 5 ); - - if ( strp == NULL ) - { - return NULL; - } - - if ( *strp++ != '.' ) - { - return NULL; - } - - strp = getnum( strp, &rulep->day, 0, DAYSPERWEEK - 1 ); - } - else if ( isdigit( (unsigned char)*strp ) ) - { - /* Day of year. */ - rulep->type = DAY_OF_YEAR; - strp = getnum( strp, &rulep->day, 0, DAYSPERLYEAR - 1 ); - } - else - { - return NULL; /* invalid format */ - } - - if ( strp == NULL ) - { - return NULL; - } - - if ( *strp == '/' ) - { - /* Time specified. */ - ++strp; - strp = getoffset( strp, &rulep->time ); - } - else - { - rulep->time = 2 * SECSPERHOUR; /* default = 2:00:00 */ - } - - return strp; -} - -/* Given a year, a rule, and the offset from UT at the time that rule takes - effect, calculate the year-relative time that rule takes effect. -*/ -static int_fast32_t transtime( const int year, struct rule const * rulep, const int_fast32_t offset ) -{ - bool leapyear; - int_fast32_t value = 0; - int i; - int d; - int m1; - int yy0; - int yy1; - int yy2; - int dow; - - leapyear = _PDCLIB_is_leap( year ); - - switch ( rulep->type ) - { - case JULIAN_DAY: - /* Jn - Julian day, 1 == January 1, 60 == March 1 even in leap - years. - In non-leap years, or if the day number is 59 or less, just - add SECSPERDAY times the day number-1 to the time of - January 1, midnight, to get the day. - */ - value = ( rulep->day - 1 ) * SECSPERDAY; - - if ( leapyear && rulep->day >= 60 ) - { - value += SECSPERDAY; - } - - break; - - case DAY_OF_YEAR: - /* n - day of year. - Just add SECSPERDAY times the day number to the time of - January 1, midnight, to get the day. - */ - value = rulep->day * SECSPERDAY; - break; - - case MONTH_NTH_DAY_OF_WEEK: - /* Mm.n.d - nth "dth day" of month m. */ - - /* Use Zeller's Congruence to get day-of-week of first day of - month. - */ - m1 = ( rulep->mon + 9 ) % 12 + 1; - yy0 = ( rulep->mon <= 2 ) ? ( year - 1 ) : year; - yy1 = yy0 / 100; - yy2 = yy0 % 100; - dow = ( ( 26 * m1 - 2 ) / 10 + 1 + yy2 + yy2 / 4 + yy1 / 4 - 2 * yy1 ) % 7; - - if ( dow < 0 ) - { - dow += DAYSPERWEEK; - } - - /* "dow" is the day-of-week of the first day of the month. Get - the day-of-month (zero-origin) of the first "dow" day of the - month. - */ - d = rulep->day - dow; - - if ( d < 0 ) - { - d += DAYSPERWEEK; - } - - for ( i = 1; i < rulep->week; ++i ) - { - if ( d + DAYSPERWEEK >= mon_lengths[ leapyear ][ rulep->mon - 1 ] ) - { - break; - } - - d += DAYSPERWEEK; - } - - /* "d" is the day-of-month (zero-origin) of the day we want. */ - value = d * SECSPERDAY; - - for ( i = 0; i < rulep->mon - 1; ++i ) - { - value += mon_lengths[ leapyear ][ i ] * SECSPERDAY; - } - - break; - } - - /* "value" is the year-relative time of 00:00:00 UT on the day in - question. To get the year-relative time of the specified local - time on that day, add the transition time and the current offset - from UT. - */ - return value + rulep->time + offset; -} - -/* Given a pointer into a timezone string, scan until a character that is not - a valid character in a time zone abbreviation is found. - Return a pointer to that character. -*/ -static const char * getzname( const char * strp ) -{ - char c; - - while ( ( c = *strp ) != '\0' && ! isdigit( (unsigned char)c ) && c != ',' && c != '-' && c != '+' ) - { - ++strp; - } - - return strp; -} - -/* Given a pointer into an extended timezone string, scan until the ending - delimiter of the time zone abbreviation is located. - Return a pointer to the delimiter. - - As with getzname above, the legal character set is actually quite - restricted, with other characters producing undefined results. - We don't do any checking here; checking is done later in common-case code. -*/ -static const char * getqzname( const char *strp, const int delim ) -{ - int c; - - while ( ( c = *strp ) != '\0' && c != delim ) - { - ++strp; - } - - return strp; -} - -static bool increment_overflow_time( time_t * tp, int_fast32_t j ) -{ - /* This is like - 'if (! (_PDCLIB_TIME_MIN <= *tp + j && *tp + j <= _PDCLIB_TIME_MAX)) ...', - except that it does the right thing even if *tp + j would overflow. - */ - if ( ! ( j < 0 - ? ( _PDCLIB_TYPE_SIGNED( time_t ) ? _PDCLIB_TIME_MIN - j <= *tp : -1 - j < *tp ) - : *tp <= _PDCLIB_TIME_MAX - j ) ) - { - return true; - } - - *tp += j; - return false; -} - -/* Given a POSIX section 8-style TZ string, fill in the rule tables as - appropriate. -*/ -bool _PDCLIB_tzparse( const char * name, struct state * sp, bool lastditch ) -{ - const char * stdname; - const char * dstname; - size_t stdlen; - size_t dstlen; - size_t charcnt; - int_fast32_t stdoffset; - int_fast32_t dstoffset; - char * cp; - bool load_ok; - - stdname = name; - - if ( lastditch ) - { - stdlen = sizeof gmt - 1; - name += stdlen; - stdoffset = 0; - } - else - { - if ( *name == '<' ) - { - name++; - stdname = name; - name = getqzname( name, '>' ); - - if ( *name != '>' ) - { - return false; - } - - stdlen = name - stdname; - name++; - } - else - { - name = getzname( name ); - stdlen = name - stdname; - } - - if ( ! stdlen ) - { - return false; - } - - name = getoffset( name, &stdoffset ); - - if ( name == NULL ) - { - return false; - } - } - - charcnt = stdlen + 1; - - if ( sizeof sp->chars < charcnt ) - { - return false; - } - - load_ok = _PDCLIB_tzload( TZDEFRULES, sp, false ) == 0; - - if ( ! load_ok ) - { - sp->leapcnt = 0; /* so, we're off a little */ - } - - if ( *name != '\0' ) - { - if ( *name == '<' ) - { - dstname = ++name; - name = getqzname( name, '>' ); - - if ( *name != '>' ) - { - return false; - } - - dstlen = name - dstname; - name++; - } - else - { - dstname = name; - name = getzname( name ); - dstlen = name - dstname; /* length of DST abbr. */ - } - - if ( ! dstlen ) - { - return false; - } - - charcnt += dstlen + 1; - - if ( sizeof sp->chars < charcnt ) - { - return false; - } - - if ( *name != '\0' && *name != ',' && *name != ';' ) - { - name = getoffset( name, &dstoffset ); - - if ( name == NULL ) - { - return false; - } - } - else - { - dstoffset = stdoffset - SECSPERHOUR; - } - - if ( *name == '\0' && ! load_ok ) - { - name = TZDEFRULESTRING; - } - - if ( *name == ',' || *name == ';' ) - { - struct rule start; - struct rule end; - int year; - int yearlim; - int timecnt; - time_t janfirst; - int_fast32_t janoffset = 0; - int yearbeg; - - ++name; - - if ( ( name = getrule( name, &start ) ) == NULL ) - { - return false; - } - - if ( *name++ != ',' ) - { - return false; - } - - if ( ( name = getrule( name, &end ) ) == NULL ) - { - return false; - } - - if ( *name != '\0' ) - { - return false; - } - - sp->typecnt = 2; /* standard time and DST */ - /* Two transitions per year, from EPOCH_YEAR forward. */ - _PDCLIB_init_ttinfo( &sp->ttis[ 0 ], -stdoffset, false, 0 ); - _PDCLIB_init_ttinfo( &sp->ttis[ 1 ], -dstoffset, true, stdlen + 1 ); - sp->defaulttype = 0; - timecnt = 0; - janfirst = 0; - yearbeg = EPOCH_YEAR; - - do - { - int_fast32_t yearsecs = year_lengths[ _PDCLIB_is_leap( yearbeg - 1 ) ] * SECSPERDAY; - yearbeg--; - - if ( increment_overflow_time( &janfirst, -yearsecs ) ) - { - janoffset = -yearsecs; - break; - } - } while ( EPOCH_YEAR - YEARSPERREPEAT / 2 < yearbeg ); - - yearlim = yearbeg + YEARSPERREPEAT + 1; - - for ( year = yearbeg; year < yearlim; year++ ) - { - int_fast32_t starttime = transtime( year, &start, stdoffset ), endtime = transtime( year, &end, dstoffset ); - int_fast32_t yearsecs = ( year_lengths[ _PDCLIB_is_leap( year ) ] * SECSPERDAY ); - bool reversed = endtime < starttime; - - if ( reversed ) - { - int_fast32_t swap = starttime; - starttime = endtime; - endtime = swap; - } - - if ( reversed - || ( starttime < endtime - && ( endtime - starttime - < ( yearsecs - + ( stdoffset - dstoffset ) ) ) ) ) - { - if ( TZ_MAX_TIMES - 2 < timecnt ) - { - break; - } - - sp->ats[ timecnt ] = janfirst; - - if ( ! increment_overflow_time( &sp->ats[ timecnt ], janoffset + starttime ) ) - { - sp->types[ timecnt++ ] = ! reversed; - } - - sp->ats[ timecnt ] = janfirst; - - if ( ! increment_overflow_time( &sp->ats[ timecnt ], janoffset + endtime ) ) - { - sp->types[ timecnt++ ] = reversed; - yearlim = year + YEARSPERREPEAT + 1; - } - } - - if ( increment_overflow_time ( &janfirst, janoffset + yearsecs ) ) - { - break; - } - - janoffset = 0; - } - - sp->timecnt = timecnt; - - if ( ! timecnt ) - { - sp->ttis[ 0 ] = sp->ttis[ 1 ]; - sp->typecnt = 1; /* Perpetual DST. */ - } - else if ( YEARSPERREPEAT < year - yearbeg ) - { - sp->goback = sp->goahead = true; - } - } - else - { - int_fast32_t theirstdoffset; - int_fast32_t theirdstoffset; - int_fast32_t theiroffset; - bool isdst; - int i; - int j; - - if ( *name != '\0' ) - { - return false; - } - - /* Initial values of theirstdoffset and theirdstoffset. */ - theirstdoffset = 0; - - for ( i = 0; i < sp->timecnt; ++i ) - { - j = sp->types[ i ]; - - if ( ! sp->ttis[ j ].isdst ) - { - theirstdoffset = - sp->ttis[ j ].utoff; - break; - } - } - - theirdstoffset = 0; - - for ( i = 0; i < sp->timecnt; ++i ) - { - j = sp->types[ i ]; - if ( sp->ttis[ j ].isdst ) - { - theirdstoffset = - sp->ttis[ j ].utoff; - break; - } - } - - /* Initially we're assumed to be in standard time. */ - isdst = false; - theiroffset = theirstdoffset; - - /* Now juggle transition times and types - tracking offsets as you do. - */ - for ( i = 0; i < sp->timecnt; ++i ) - { - j = sp->types[ i ]; - sp->types[ i ] = sp->ttis[ j ].isdst; - - if ( sp->ttis[ j ].ttisut ) - { - /* No adjustment to transition time */ - } - else - { - /* If daylight saving time is in - effect, and the transition time was - not specified as standard time, add - the daylight saving time offset to - the transition time; otherwise, add - the standard time offset to the - transition time. - */ - /* Transitions from DST to DDST - will effectively disappear since - POSIX provides for only one DST - offset. - */ - if ( isdst && ! sp->ttis[ j ].ttisstd ) - { - sp->ats[ i ] += dstoffset - theirdstoffset; - } - else - { - sp->ats[ i ] += stdoffset - theirstdoffset; - } - } - - theiroffset = -sp->ttis[ j ].utoff; - if ( sp->ttis[ j ].isdst ) - { - theirdstoffset = theiroffset; - } - else - { - theirstdoffset = theiroffset; - } - } - - /* Finally, fill in ttis. */ - _PDCLIB_init_ttinfo( &sp->ttis[ 0 ], -stdoffset, false, 0 ); - _PDCLIB_init_ttinfo( &sp->ttis[ 1 ], -dstoffset, true, stdlen + 1 ); - sp->typecnt = 2; - sp->defaulttype = 0; - } - } - else - { - dstlen = 0; - sp->typecnt = 1; /* only standard time */ - sp->timecnt = 0; - _PDCLIB_init_ttinfo( &sp->ttis[ 0 ], -stdoffset, false, 0 ); - sp->defaulttype = 0; - } - - sp->charcnt = charcnt; - cp = sp->chars; - memcpy( cp, stdname, stdlen ); - cp += stdlen; - *cp++ = '\0'; - - if ( dstlen != 0 ) - { - memcpy( cp, dstname, dstlen ); - *( cp + dstlen ) = '\0'; - } - - return true; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_tzset_unlocked.c b/rocklibc/src/_tzcode/_PDCLIB_tzset_unlocked.c deleted file mode 100644 index fe0f53d..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_tzset_unlocked.c +++ /dev/null @@ -1,185 +0,0 @@ -/* _PDCLIB_tzset_unlocked( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#include -#include - -#ifndef TZ_ABBR_MAX_LEN -#define TZ_ABBR_MAX_LEN 16 -#endif - -#ifndef TZ_ABBR_CHAR_SET -#define TZ_ABBR_CHAR_SET "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 :+-._" -#endif - -#ifndef TZ_ABBR_ERR_CHAR -#define TZ_ABBR_ERR_CHAR '_' -#endif - -/* This string was in the Factory zone through version 2016f. */ -#define GRANDPARENTED "Local time zone must be set--see zic manual page" - -#ifndef TZ_STRLEN_MAX -#define TZ_STRLEN_MAX 255 -#endif - -static char lcl_TZname[ TZ_STRLEN_MAX + 1 ]; -int lcl_is_set = 0; - -static void scrub_abbrs( struct state * sp ) -{ - int i; - - /* First, replace bogus characters. */ - for ( i = 0; i < sp->charcnt; ++i ) - { - if ( strchr( TZ_ABBR_CHAR_SET, sp->chars[ i ] ) == NULL ) - { - sp->chars[ i ] = TZ_ABBR_ERR_CHAR; - } - } - - /* Second, truncate long abbreviations. */ - for ( i = 0; i < sp->typecnt; ++i ) - { - const struct ttinfo * const ttisp = &sp->ttis[ i ]; - char * cp = &sp->chars[ ttisp->desigidx ]; - - if ( strlen( cp ) > TZ_ABBR_MAX_LEN && strcmp( cp, GRANDPARENTED ) != 0 ) - { - *( cp + TZ_ABBR_MAX_LEN ) = '\0'; - } - } -} - -/* Initialize *SP to a value appropriate for the TZ setting NAME. - Return 0 on success, an errno value on failure. -*/ -static int zoneinit( struct state * sp, char const * name ) -{ - if (name && ! name[0]) - { - /* User wants it fast rather than right. */ - sp->leapcnt = 0; /* so, we're off a little */ - sp->timecnt = 0; - sp->typecnt = 0; - sp->charcnt = 0; - sp->goback = sp->goahead = false; - _PDCLIB_init_ttinfo( &sp->ttis[ 0 ], 0, false, 0 ); - strcpy( sp->chars, gmt ); - sp->defaulttype = 0; - return 0; - } - else - { - int err = _PDCLIB_tzload( name, sp, true ); - - if ( err != 0 && name && name[ 0 ] != ':' && _PDCLIB_tzparse( name, sp, false ) ) - { - err = 0; - } - - if ( err == 0 ) - { - scrub_abbrs( sp ); - } - - return err; - } -} - -static void settzname( void ) -{ - struct state * const sp = &_PDCLIB_lclmem; - int i; - -#if HAVE_TZNAME - tzname[ 0 ] = tzname[ 1 ] = (char *) ( sp ? wildabbr : gmt ); -#endif -#if USG_COMPAT - daylight = 0; - timezone = 0; -#endif -#if ALTZONE - altzone = 0; -#endif - if ( sp == NULL ) - { - return; - } - /* And to get the latest time zone abbreviations into tzname... */ - for ( i = 0; i < sp->typecnt; ++i ) - { - const struct ttinfo * const ttisp = &sp->ttis[ i ]; - _PDCLIB_update_tzname_etc( sp, ttisp ); - } - - for ( i = 0; i < sp->timecnt; ++i ) - { - const struct ttinfo * const ttisp = &sp->ttis[ sp->types[ i ] ]; - _PDCLIB_update_tzname_etc( sp, ttisp ); -#if USG_COMPAT - if ( ttisp->isdst ) - { - daylight = 1; - } -#endif - } -} - -static void tzsetlcl( char const * name ) -{ - struct state * sp = &_PDCLIB_lclmem; - int lcl = name ? strlen( name ) < sizeof lcl_TZname : -1; - - if ( lcl < 0 - ? lcl_is_set < 0 - : 0 < lcl_is_set && strcmp( lcl_TZname, name ) == 0 ) - { - return; - } - - if ( sp ) - { - if ( zoneinit( sp, name ) != 0 ) - { - zoneinit( sp, "" ); - } - - if ( 0 < lcl ) - { - strcpy( lcl_TZname, name ); - } - } - - settzname(); - lcl_is_set = lcl; -} - -void _PDCLIB_tzset_unlocked( void ) -{ - tzsetlcl( getenv( "TZ" ) ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/_tzcode/_PDCLIB_update_tzname_etc.c b/rocklibc/src/_tzcode/_PDCLIB_update_tzname_etc.c deleted file mode 100644 index b54d4fa..0000000 --- a/rocklibc/src/_tzcode/_PDCLIB_update_tzname_etc.c +++ /dev/null @@ -1,44 +0,0 @@ -/* _PDCLIB_update_tzname_etc( struct state const *, struct ttinfo const * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -void _PDCLIB_update_tzname_etc( struct state const * sp, struct ttinfo const * ttisp ) -{ -#if HAVE_TZNAME - tzname[ ttisp->isdst ] = (char *) &sp->chars[ ttisp->desigidx ]; -#endif -#if USG_COMPAT - if ( ! ttisp->isdst ) - { - timezone = - ttisp->utoff; - } -#endif -#if ALTZONE - if ( ttisp->isdst ) - { - altzone = - ttisp->utoff; - } -#endif -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isalnum.c b/rocklibc/src/ctype/isalnum.c deleted file mode 100644 index d3ef7c9..0000000 --- a/rocklibc/src/ctype/isalnum.c +++ /dev/null @@ -1,38 +0,0 @@ -/* isalnum( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isalnum( int c ) -{ - return ( isdigit( c ) || isalpha( c ) ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isalnum( 'a' ) ); - TESTCASE( isalnum( 'z' ) ); - TESTCASE( isalnum( 'A' ) ); - TESTCASE( isalnum( 'Z' ) ); - TESTCASE( isalnum( '0' ) ); - TESTCASE( isalnum( '9' ) ); - TESTCASE( ! isalnum( ' ' ) ); - TESTCASE( ! isalnum( '\n' ) ); - TESTCASE( ! isalnum( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isalpha.c b/rocklibc/src/ctype/isalpha.c deleted file mode 100644 index 371314d..0000000 --- a/rocklibc/src/ctype/isalpha.c +++ /dev/null @@ -1,34 +0,0 @@ -/* isalpha( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isalpha( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_ALPHA ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isalpha( 'a' ) ); - TESTCASE( isalpha( 'z' ) ); - TESTCASE( ! isalpha( ' ' ) ); - TESTCASE( ! isalpha( '1' ) ); - TESTCASE( ! isalpha( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isblank.c b/rocklibc/src/ctype/isblank.c deleted file mode 100644 index 6b2acee..0000000 --- a/rocklibc/src/ctype/isblank.c +++ /dev/null @@ -1,35 +0,0 @@ -/* isblank( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isblank( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_BLANK ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isblank( ' ' ) ); - TESTCASE( isblank( '\t' ) ); - TESTCASE( ! isblank( '\v' ) ); - TESTCASE( ! isblank( '\r' ) ); - TESTCASE( ! isblank( 'x' ) ); - TESTCASE( ! isblank( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/iscntrl.c b/rocklibc/src/ctype/iscntrl.c deleted file mode 100644 index cc482a8..0000000 --- a/rocklibc/src/ctype/iscntrl.c +++ /dev/null @@ -1,33 +0,0 @@ -/* iscntrl( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int iscntrl( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_CNTRL ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( iscntrl( '\a' ) ); - TESTCASE( iscntrl( '\b' ) ); - TESTCASE( iscntrl( '\n' ) ); - TESTCASE( ! iscntrl( ' ' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isdigit.c b/rocklibc/src/ctype/isdigit.c deleted file mode 100644 index 1a4f77b..0000000 --- a/rocklibc/src/ctype/isdigit.c +++ /dev/null @@ -1,34 +0,0 @@ -/* isdigit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isdigit( int c ) -{ - return ( c >= _PDCLIB_lc_ctype->digits_low && c <= _PDCLIB_lc_ctype->digits_high ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isdigit( '0' ) ); - TESTCASE( isdigit( '9' ) ); - TESTCASE( ! isdigit( ' ' ) ); - TESTCASE( ! isdigit( 'a' ) ); - TESTCASE( ! isdigit( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isgraph.c b/rocklibc/src/ctype/isgraph.c deleted file mode 100644 index 73553a4..0000000 --- a/rocklibc/src/ctype/isgraph.c +++ /dev/null @@ -1,37 +0,0 @@ -/* isgraph( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isgraph( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_GRAPH ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isgraph( 'a' ) ); - TESTCASE( isgraph( 'z' ) ); - TESTCASE( isgraph( 'A' ) ); - TESTCASE( isgraph( 'Z' ) ); - TESTCASE( isgraph( '@' ) ); - TESTCASE( ! isgraph( '\t' ) ); - TESTCASE( ! isgraph( '\0' ) ); - TESTCASE( ! isgraph( ' ' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/islower.c b/rocklibc/src/ctype/islower.c deleted file mode 100644 index 5a1db77..0000000 --- a/rocklibc/src/ctype/islower.c +++ /dev/null @@ -1,35 +0,0 @@ -/* islower( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int islower( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_LOWER ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( islower( 'a' ) ); - TESTCASE( islower( 'z' ) ); - TESTCASE( ! islower( 'A' ) ); - TESTCASE( ! islower( 'Z' ) ); - TESTCASE( ! islower( ' ' ) ); - TESTCASE( ! islower( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isprint.c b/rocklibc/src/ctype/isprint.c deleted file mode 100644 index 5d50ee8..0000000 --- a/rocklibc/src/ctype/isprint.c +++ /dev/null @@ -1,38 +0,0 @@ -/* isprint( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isprint( int c ) -{ - /* FIXME: Space as of current locale charset, not source charset. */ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_GRAPH ) || ( c == ' ' ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isprint( 'a' ) ); - TESTCASE( isprint( 'z' ) ); - TESTCASE( isprint( 'A' ) ); - TESTCASE( isprint( 'Z' ) ); - TESTCASE( isprint( '@' ) ); - TESTCASE( ! isprint( '\t' ) ); - TESTCASE( ! isprint( '\0' ) ); - TESTCASE( isprint( ' ' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/ispunct.c b/rocklibc/src/ctype/ispunct.c deleted file mode 100644 index 1c5a58c..0000000 --- a/rocklibc/src/ctype/ispunct.c +++ /dev/null @@ -1,38 +0,0 @@ -/* ispunct( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int ispunct( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_PUNCT ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( ! ispunct( 'a' ) ); - TESTCASE( ! ispunct( 'z' ) ); - TESTCASE( ! ispunct( 'A' ) ); - TESTCASE( ! ispunct( 'Z' ) ); - TESTCASE( ispunct( '@' ) ); - TESTCASE( ispunct( '.' ) ); - TESTCASE( ! ispunct( '\t' ) ); - TESTCASE( ! ispunct( '\0' ) ); - TESTCASE( ! ispunct( ' ' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isspace.c b/rocklibc/src/ctype/isspace.c deleted file mode 100644 index b7ee8cf..0000000 --- a/rocklibc/src/ctype/isspace.c +++ /dev/null @@ -1,36 +0,0 @@ -/* isspace( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isspace( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_SPACE ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isspace( ' ' ) ); - TESTCASE( isspace( '\f' ) ); - TESTCASE( isspace( '\n' ) ); - TESTCASE( isspace( '\r' ) ); - TESTCASE( isspace( '\t' ) ); - TESTCASE( isspace( '\v' ) ); - TESTCASE( ! isspace( 'a' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isupper.c b/rocklibc/src/ctype/isupper.c deleted file mode 100644 index 4207389..0000000 --- a/rocklibc/src/ctype/isupper.c +++ /dev/null @@ -1,35 +0,0 @@ -/* isupper( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isupper( int c ) -{ - return ( _PDCLIB_lc_ctype->entry[c].flags & _PDCLIB_CTYPE_UPPER ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isupper( 'A' ) ); - TESTCASE( isupper( 'Z' ) ); - TESTCASE( ! isupper( 'a' ) ); - TESTCASE( ! isupper( 'z' ) ); - TESTCASE( ! isupper( ' ' ) ); - TESTCASE( ! isupper( '@' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/isxdigit.c b/rocklibc/src/ctype/isxdigit.c deleted file mode 100644 index 32bef4b..0000000 --- a/rocklibc/src/ctype/isxdigit.c +++ /dev/null @@ -1,42 +0,0 @@ -/* isxdigit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int isxdigit( int c ) -{ - return ( isdigit( c ) || - ( c >= _PDCLIB_lc_ctype->Xdigits_low && c <= _PDCLIB_lc_ctype->Xdigits_high ) || - ( c >= _PDCLIB_lc_ctype->xdigits_low && c <= _PDCLIB_lc_ctype->xdigits_high ) - ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( isxdigit( '0' ) ); - TESTCASE( isxdigit( '9' ) ); - TESTCASE( isxdigit( 'a' ) ); - TESTCASE( isxdigit( 'f' ) ); - TESTCASE( ! isxdigit( 'g' ) ); - TESTCASE( isxdigit( 'A' ) ); - TESTCASE( isxdigit( 'F' ) ); - TESTCASE( ! isxdigit( 'G' ) ); - TESTCASE( ! isxdigit( '@' ) ); - TESTCASE( ! isxdigit( ' ' ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/tolower.c b/rocklibc/src/ctype/tolower.c deleted file mode 100644 index bb14494..0000000 --- a/rocklibc/src/ctype/tolower.c +++ /dev/null @@ -1,35 +0,0 @@ -/* tolower( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int tolower( int c ) -{ - return _PDCLIB_lc_ctype->entry[c].lower; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( tolower( 'A' ) == 'a' ); - TESTCASE( tolower( 'Z' ) == 'z' ); - TESTCASE( tolower( 'a' ) == 'a' ); - TESTCASE( tolower( 'z' ) == 'z' ); - TESTCASE( tolower( '@' ) == '@' ); - TESTCASE( tolower( '[' ) == '[' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/ctype/toupper.c b/rocklibc/src/ctype/toupper.c deleted file mode 100644 index a790a04..0000000 --- a/rocklibc/src/ctype/toupper.c +++ /dev/null @@ -1,35 +0,0 @@ -/* toupper( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int toupper( int c ) -{ - return _PDCLIB_lc_ctype->entry[c].upper; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( toupper( 'a' ) == 'A' ); - TESTCASE( toupper( 'z' ) == 'Z' ); - TESTCASE( toupper( 'A' ) == 'A' ); - TESTCASE( toupper( 'Z' ) == 'Z' ); - TESTCASE( toupper( '@' ) == '@' ); - TESTCASE( toupper( '[' ) == '[' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/inttypes/imaxabs.c b/rocklibc/src/inttypes/imaxabs.c deleted file mode 100644 index 445da06..0000000 --- a/rocklibc/src/inttypes/imaxabs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* imaxabs( intmax_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -intmax_t imaxabs( intmax_t j ) -{ - return ( j >= 0 ) ? j : -j; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - TESTCASE( imaxabs( ( intmax_t )0 ) == 0 ); - TESTCASE( imaxabs( INTMAX_MAX ) == INTMAX_MAX ); - TESTCASE( imaxabs( INTMAX_MIN + 1 ) == -( INTMAX_MIN + 1 ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/inttypes/imaxdiv.c b/rocklibc/src/inttypes/imaxdiv.c deleted file mode 100644 index 3b6b464..0000000 --- a/rocklibc/src/inttypes/imaxdiv.c +++ /dev/null @@ -1,39 +0,0 @@ -/* lldiv( long long int, long long int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -imaxdiv_t imaxdiv( intmax_t numer, intmax_t denom ) -{ - imaxdiv_t rc; - rc.quot = numer / denom; - rc.rem = numer % denom; - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - imaxdiv_t result; - result = imaxdiv( ( intmax_t )5, ( intmax_t )2 ); - TESTCASE( result.quot == 2 && result.rem == 1 ); - result = imaxdiv( ( intmax_t )-5, ( intmax_t )2 ); - TESTCASE( result.quot == -2 && result.rem == -1 ); - result = imaxdiv( ( intmax_t )5, ( intmax_t )-2 ); - TESTCASE( result.quot == -2 && result.rem == 1 ); - TESTCASE( sizeof( result.quot ) == sizeof( intmax_t ) ); - TESTCASE( sizeof( result.rem ) == sizeof( intmax_t ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/inttypes/strtoimax.c b/rocklibc/src/inttypes/strtoimax.c deleted file mode 100644 index 3c7683a..0000000 --- a/rocklibc/src/inttypes/strtoimax.c +++ /dev/null @@ -1,158 +0,0 @@ -/* strtoimax( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -intmax_t strtoimax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ) -{ - intmax_t rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( nptr, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - if ( sign == '+' ) - { - rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MAX, ( uintmax_t )INTMAX_MAX, &sign ); - } - else - { - rc = ( intmax_t )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )INTMAX_MIN, ( ( uintmax_t )INTMAX_MAX + 1 ), &sign ); - } - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) nptr; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtoimax( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtoimax( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtoimax( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtoimax( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtoimax( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtoimax( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtoimax( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtoimax( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtoimax( overflow, &endptr, 36 ) == INTMAX_MIN ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtoimax( overflow + 1, &endptr, 36 ) == INTMAX_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtoimax( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtoimax( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtoimax( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - /* These tests assume two-complement, but conversion should work for */ - /* one-complement and signed magnitude just as well. Anyone having a */ - /* platform to test this on? */ - errno = 0; -#if INTMAX_MAX >> 62 == 1 - /* testing "odd" overflow, i.e. base is not a power of two */ - TESTCASE( strtoimax( "9223372036854775807", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "9223372036854775808", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoimax( "-9223372036854775807", NULL, 0 ) == ( INTMAX_MIN + 1 ) ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-9223372036854775808", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-9223372036854775809", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == ERANGE ); - /* testing "even" overflow, i.e. base is power of two */ - errno = 0; - TESTCASE( strtoimax( "0x7fffffffffffffff", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "0x8000000000000000", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoimax( "-0x7fffffffffffffff", NULL, 0 ) == ( INTMAX_MIN + 1 ) ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-0x8000000000000000", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-0x8000000000000001", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == ERANGE ); -#elif LLONG_MAX >> 126 == 1 - /* testing "odd" overflow, i.e. base is not a power of two */ - TESTCASE( strtoimax( "170141183460469231731687303715884105728", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoimax( "-170141183460469231731687303715884105728", NULL, 0 ) == ( INTMAX_MIN + 1 ) ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-170141183460469231731687303715884105729", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-170141183460469231731687303715884105730", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == ERANGE ); - /* testing "even" overflow, i.e. base is power of two */ - errno = 0; - TESTCASE( strtoimax( "0x7fffffffffffffffffffffffffffffff", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoimax( "-0x7fffffffffffffffffffffffffffffff", NULL, 0 ) == ( INTMAX_MIN + 1 ) ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-0x80000000000000000000000000000000", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoimax( "-0x80000000000000000000000000000001", NULL, 0 ) == INTMAX_MIN ); - TESTCASE( errno == ERANGE ); -#else -#error Unsupported width of 'intmax_t' (neither 64 nor 128 bit). -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/inttypes/strtoumax.c b/rocklibc/src/inttypes/strtoumax.c deleted file mode 100644 index ddda21f..0000000 --- a/rocklibc/src/inttypes/strtoumax.c +++ /dev/null @@ -1,122 +0,0 @@ -/* strtoumax( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -uintmax_t strtoumax( const char * _PDCLIB_restrict nptr, char ** _PDCLIB_restrict endptr, int base ) -{ - uintmax_t rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( nptr, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )UINTMAX_MAX, ( uintmax_t )UINTMAX_MAX, &sign ); - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) nptr; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtoumax( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtoumax( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtoumax( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtoumax( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtoumax( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtoumax( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtoumax( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtoumax( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtoumax( overflow, &endptr, 36 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtoumax( overflow + 1, &endptr, 36 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtoumax( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtoumax( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtoumax( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - errno = 0; -/* uintmax_t -> long long -> 64 bit */ -#if UINTMAX_MAX >> 63 == 1 - /* testing "odd" overflow, i.e. base is not power of two */ - TESTCASE( strtoumax( "18446744073709551615", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoumax( "18446744073709551616", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); - /* testing "even" overflow, i.e. base is power of two */ - errno = 0; - TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoumax( "0x10000000000000000", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); -/* uintmax_t -> long long -> 128 bit */ -#elif UINTMAX_MAX >> 127 == 1 - /* testing "odd" overflow, i.e. base is not power of two */ - TESTCASE( strtoumax( "340282366920938463463374607431768211455", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoumax( "340282366920938463463374607431768211456", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); - /* testing "even" everflow, i.e. base is power of two */ - errno = 0; - TESTCASE( strtoumax( "0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoumax( "0x100000000000000000000000000000000", NULL, 0 ) == UINTMAX_MAX ); - TESTCASE( errno == ERANGE ); -#else -#error Unsupported width of 'uintmax_t' (neither 64 nor 128 bit). -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/locale/localeconv.c b/rocklibc/src/locale/localeconv.c deleted file mode 100644 index 8fbc97f..0000000 --- a/rocklibc/src/locale/localeconv.c +++ /dev/null @@ -1,32 +0,0 @@ -/* localeconv( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -struct lconv * localeconv( void ) -{ - return _PDCLIB_lc_numeric_monetary.lconv; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - struct lconv * lconv; - TESTCASE( ( lconv = localeconv() ) != NULL ); - TESTCASE( strcmp( lconv->decimal_point, "." ) == 0 ); - TESTCASE( strcmp( lconv->thousands_sep, "" ) == 0 ); - TESTCASE( ( strcmp( lconv->grouping, "" ) == 0 ) || ( strcmp( lconv->grouping, "\x7f" ) == 0 ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/locale/setlocale.c b/rocklibc/src/locale/setlocale.c deleted file mode 100644 index fb0d0c1..0000000 --- a/rocklibc/src/locale/setlocale.c +++ /dev/null @@ -1,269 +0,0 @@ -/* setlocale( int, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#if 0 -static const char * _PDCLIB_LC_category_name[ _PDCLIB_LC_COUNT ] = { NULL, "LC_COLLATE", "LC_CTYPE", "LC_MONETARY", "LC_NUMERIC", "LC_TIME", "LC_MESSAGES" }; - -static const char * _PDCLIB_default_locale( int category ) -{ - const char * s; - - /* The standard states (7.22.4.6 (3), "the implementation shall behave - as if no library function calls the getenv function." That is, - however, in context of the previous paragraph stating that getenv - "need not avoid data races with other threads of execution that - modify the environment list". - PDCLib does not provide means of modifying the environment list. - */ - if ( ( s = getenv( "LC_ALL" ) ) == NULL ) - { - if ( category == LC_ALL || ( s = getenv( _PDCLIB_LC_category_name[ category ] ) ) == NULL ) - { - if ( ( s = getenv( "LANG" ) ) == NULL ) - { - s = "C"; - } - } - } - - return s; -} -#endif - -char * setlocale( int category, const char * locale ) -{ - /* All below is very much work-in-progress, so we do a dumb-dummy - return here. - */ - if ( locale == NULL || ! strcmp( locale, "C" ) ) - { - return ( char * )"C"; - } - else - { - return NULL; - } - -#if 0 - /* Path to locale data files - _PDCLIB_LOCALE_PATH unless overruled - by the environment variable whose name is defined by preprocessor - symbol _PDCLIB_LOCALE_PATH_ENV (defaulting to PDCLIB_I18N). - Both of these definitions are set in _PDCLIB_config.h. - */ - const char * path = _PDCLIB_LOCALE_PATH; - - struct _PDCLIB_lc_lconv_numeric_t * numeric = NULL; - struct _PDCLIB_lc_lconv_monetary_t * monetary = NULL; - struct _PDCLIB_lc_collate_t * collate = NULL; - struct _PDCLIB_lc_ctype_t * ctype = NULL; - struct _PDCLIB_lc_messages_t * messages = NULL; - struct _PDCLIB_lc_time_t * time = NULL; - - char * rc = ( char * )locale; - - if ( category < 0 || category >= _PDCLIB_LC_COUNT ) - { - /* Bad category */ - return NULL; - } - - if ( locale == NULL ) - { - /* NULL - Return current locale settings */ - /* TODO */ - } - - if ( strlen( locale ) == 0 ) - { - /* "" - Use default locale */ - locale = _PDCLIB_default_locale( category ); - } - - if ( getenv( _PDCLIB_value2string( _PDCLIB_LOCALE_PATH_ENV ) ) != NULL ) - { - path = getenv( _PDCLIB_value2string( _PDCLIB_LOCALE_PATH_ENV ) ); - } - - /* We have to do this in two runs. As we might be facing LC_ALL, we - need to be certain all the loads are successful before we start - to overwrite the current locale settings, because there is no way - this function could report a _partial_ success. - */ - - /* Run One -- get all the data for the new locale setting */ - if ( category == LC_COLLATE || category == LC_ALL ) - { - if ( !( collate = _PDCLIB_load_lc_collate( path, locale ) ) ) - { - rc = NULL; - } - } - - if ( category == LC_CTYPE || category == LC_ALL ) - { - if ( !( ctype = _PDCLIB_load_lc_ctype( path, locale ) ) ) - { - rc = NULL; - } - } - - if ( category == LC_MONETARY || category == LC_ALL ) - { - if ( !( monetary = _PDCLIB_load_lc_monetary( path, locale ) ) ) - { - rc = NULL; - } - } - - if ( category == LC_NUMERIC || category == LC_ALL ) - { - if ( !( numeric = _PDCLIB_load_lc_numeric( path, locale ) ) ) - { - rc = NULL; - } - } - - if ( category == LC_TIME || category == LC_ALL ) - { - if ( !( time = _PDCLIB_load_lc_time( path, locale ) ) ) - { - rc = NULL; - } - } - - if ( category == LC_MESSAGES || category == LC_ALL ) - { - if ( !( messages = _PDCLIB_load_lc_messages( path, locale ) ) ) - { - rc = NULL; - } - } - - /* Run Two -- continue or release resources */ - if ( rc != NULL ) - { - if ( category == LC_COLLATE || category == LC_ALL ) - { - if ( _PDCLIB_lc_collate->alloced ) - { - /* free resources */ - } - - *_PDCLIB_lc_collate = *collate; - free( collate ); - } - - if ( category == LC_CTYPE || category == LC_ALL ) - { - if ( _PDCLIB_lc_ctype->alloced ) - { - free( _PDCLIB_lc_ctype->entry - 1 ); - } - - *_PDCLIB_lc_ctype = *ctype; - free( ctype ); - } - - if ( category == LC_MONETARY || category == LC_ALL ) - { - if ( _PDCLIB_lc_numeric_monetary.monetary_alloced ) - { - free( _PDCLIB_lc_numeric_monetary.lconv->mon_decimal_point ); - } - - _PDCLIB_lc_numeric_monetary.lconv->mon_decimal_point = monetary->mon_decimal_point; - _PDCLIB_lc_numeric_monetary.lconv->mon_thousands_sep = monetary->mon_thousands_sep; - _PDCLIB_lc_numeric_monetary.lconv->mon_grouping = monetary->mon_grouping; - _PDCLIB_lc_numeric_monetary.lconv->positive_sign = monetary->positive_sign; - _PDCLIB_lc_numeric_monetary.lconv->negative_sign = monetary->negative_sign; - _PDCLIB_lc_numeric_monetary.lconv->currency_symbol = monetary->currency_symbol; - _PDCLIB_lc_numeric_monetary.lconv->int_curr_symbol = monetary->int_curr_symbol; - _PDCLIB_lc_numeric_monetary.lconv->frac_digits = monetary->frac_digits; - _PDCLIB_lc_numeric_monetary.lconv->p_cs_precedes = monetary->p_cs_precedes; - _PDCLIB_lc_numeric_monetary.lconv->n_cs_precedes = monetary->n_cs_precedes; - _PDCLIB_lc_numeric_monetary.lconv->p_sep_by_space = monetary->p_sep_by_space; - _PDCLIB_lc_numeric_monetary.lconv->n_sep_by_space = monetary->n_sep_by_space; - _PDCLIB_lc_numeric_monetary.lconv->p_sign_posn = monetary->p_sign_posn; - _PDCLIB_lc_numeric_monetary.lconv->n_sign_posn = monetary->n_sign_posn; - _PDCLIB_lc_numeric_monetary.lconv->int_frac_digits = monetary->int_frac_digits; - _PDCLIB_lc_numeric_monetary.lconv->int_p_cs_precedes = monetary->int_p_cs_precedes; - _PDCLIB_lc_numeric_monetary.lconv->int_n_cs_precedes = monetary->int_n_cs_precedes; - _PDCLIB_lc_numeric_monetary.lconv->int_p_sep_by_space = monetary->int_p_sep_by_space; - _PDCLIB_lc_numeric_monetary.lconv->int_n_sep_by_space = monetary->int_n_sep_by_space; - _PDCLIB_lc_numeric_monetary.lconv->int_p_sign_posn = monetary->int_p_sign_posn; - _PDCLIB_lc_numeric_monetary.lconv->int_n_sign_posn = monetary->int_n_sign_posn; - - _PDCLIB_lc_numeric_monetary.monetary_alloced = 1; - - free( monetary ); - } - - if ( category == LC_NUMERIC || category == LC_ALL ) - { - if ( _PDCLIB_lc_numeric_monetary.numeric_alloced ) - { - free( _PDCLIB_lc_numeric_monetary.lconv->decimal_point ); - } - - _PDCLIB_lc_numeric_monetary.lconv->decimal_point = numeric->decimal_point; - _PDCLIB_lc_numeric_monetary.lconv->thousands_sep = numeric->thousands_sep; - _PDCLIB_lc_numeric_monetary.lconv->grouping = numeric->grouping; - - _PDCLIB_lc_numeric_monetary.numeric_alloced = 1; - - free( numeric ); - } - - if ( category == LC_TIME || category == LC_ALL ) - { - if ( _PDCLIB_lc_time->alloced ) - { - free( _PDCLIB_lc_time->month_name_abbr[ 0 ] ); - } - - *_PDCLIB_lc_time = *time; - free( time ); - } - - if ( category == LC_MESSAGES || category == LC_ALL ) - { - if ( _PDCLIB_lc_messages->alloced ) - { - free( _PDCLIB_lc_messages->errno_texts[ 0 ] ); - } - - *_PDCLIB_lc_messages = *messages; - free( messages ); - } - } - - return NULL; -#endif -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( strcmp( setlocale( LC_ALL, "C" ), "C" ) == 0 ); -#ifndef REGTEST - TESTCASE( setlocale( LC_ALL, "" ) == NULL ); -#endif - TESTCASE( strcmp( setlocale( LC_ALL, NULL ), "C" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/fabs.c b/rocklibc/src/math/fabs.c deleted file mode 100644 index f7a3a8c..0000000 --- a/rocklibc/src/math/fabs.c +++ /dev/null @@ -1,114 +0,0 @@ - -/* fabs( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -double fabs( double x ) -{ - if ( isnan( x ) ) - { - return NAN; - } - - return ( x < 0.0 ) ? -x : x; -} - -float fabsf( float x ) -{ - if ( isnan( x ) ) - { - return NAN; - } - - return ( x < 0.0 ) ? -x : x; -} - -long double fabsl( long double x ) -{ - if ( isnan( x ) ) - { - return NAN; - } - - return ( x < 0.0 ) ? -x : x; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - float f; - double d; - long double ld; - - TESTCASE( fabsf( 3.15f ) == 3.15f ); - TESTCASE( fabsf( -3.15f ) == 3.15f ); - errno = 0; - TESTCASE( fabsf( INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( fabsf( -INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - f = fabsf( NAN ); - TESTCASE( isnan( f ) ); - TESTCASE( ! signbit( f ) ); - TESTCASE( errno == 0 ); - f = fabsf( -NAN ); - TESTCASE( isnan( f ) ); - TESTCASE( ! signbit( f ) ); - TESTCASE( errno == 0 ); - - TESTCASE( fabs( 3.15 ) == 3.15 ); - TESTCASE( fabs( -3.15 ) == 3.15 ); - errno = 0; - TESTCASE( fabs( INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( fabs( -INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - d = fabs( NAN ); - TESTCASE( isnan( d ) ); - TESTCASE( ! signbit( d ) ); - TESTCASE( errno == 0 ); - d = fabs( -NAN ); - TESTCASE( isnan( d ) ); - TESTCASE( ! signbit( d ) ); - TESTCASE( errno == 0 ); - - TESTCASE( fabsl( 3.15l ) == 3.15l ); - TESTCASE( fabsl( -3.15l ) == 3.15l ); - errno = 0; - TESTCASE( fabsl( INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( fabsl( -INFINITY ) == INFINITY ); - TESTCASE( errno == 0 ); - errno = 0; - ld = fabsl( NAN ); - TESTCASE( isnan( ld ) ); - TESTCASE( ! signbit( ld ) ); - TESTCASE( errno == 0 ); - ld = fabsl( -NAN ); - TESTCASE( isnan( ld ) ); - TESTCASE( ! signbit( ld ) ); - TESTCASE( errno == 0 ); - - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/fdim.c b/rocklibc/src/math/fdim.c deleted file mode 100644 index 02b4902..0000000 --- a/rocklibc/src/math/fdim.c +++ /dev/null @@ -1,74 +0,0 @@ -/* fdim( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -double fdim( double x, double y ) -{ - return fmax( x - y, 0 ); -} - -float fdimf( float x, float y ) -{ - return fmaxf( x - y, 0 ); -} - -long double fdiml( long double x, long double y ) -{ - return fmaxl( x - y, 0 ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f1, f2; - double d1, d2; - long double ld1, ld2; - - f1 = 3.5f; - f2 = 3.75f; - TESTCASE( fdimf( f1, f2 ) == 0.0f ); - TESTCASE( fdimf( f2, f1 ) == 0.25f ); - TESTCASE( fdimf( f1, INFINITY ) == 0.0f ); - TESTCASE( fdimf( INFINITY, f1 ) == INFINITY ); - TESTCASE( fdimf( f1, -INFINITY ) == INFINITY ); - TESTCASE( fdimf( -INFINITY, f1 ) == 0.0f ); - TESTCASE( fdimf( f1, NAN ) != f1 ); - TESTCASE( fdimf( NAN, f1 ) != f1 ); - - d1 = 3.5; - d2 = 3.75; - TESTCASE( fdim( d1, d2 ) == 0.0 ); - TESTCASE( fdim( d2, d1 ) == 0.25 ); - TESTCASE( fdim( d1, INFINITY ) == 0.0 ); - TESTCASE( fdim( INFINITY, d1 ) == INFINITY ); - TESTCASE( fdim( d1, -INFINITY ) == INFINITY ); - TESTCASE( fdim( -INFINITY, d1 ) == 0.0 ); - TESTCASE( fdim( d1, NAN ) != d1 ); - TESTCASE( fdim( NAN, d1 ) != d1 ); - - ld1 = 3.5l; - ld2 = 3.75l; - TESTCASE( fdiml( ld1, ld2 ) == 0.0l ); - TESTCASE( fdiml( ld2, ld1 ) == 0.25l ); - TESTCASE( fdiml( ld1, INFINITY ) == 0.0l ); - TESTCASE( fdiml( INFINITY, ld1 ) == INFINITY ); - TESTCASE( fdiml( ld1, -INFINITY ) == INFINITY ); - TESTCASE( fdiml( -INFINITY, ld1 ) == 0.0l ); - TESTCASE( fdiml( ld1, NAN ) != ld1 ); - TESTCASE( fdiml( NAN, ld1 ) != ld1 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/fmax.c b/rocklibc/src/math/fmax.c deleted file mode 100644 index b6a4886..0000000 --- a/rocklibc/src/math/fmax.c +++ /dev/null @@ -1,105 +0,0 @@ - -/* fmax( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -double fmax( double x, double y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x > y ) ? x : y; -} - -float fmaxf( float x, float y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x > y ) ? x : y; -} - -long double fmaxl( long double x, long double y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x > y ) ? x : y; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f1, f2; - double d1, d2; - long double ld1, ld2; - - f1 = 3.15f; - f2 = 3.16f; - TESTCASE( fmaxf( f1, f2 ) == f2 ); - TESTCASE( fmaxf( f2, f1 ) == f2 ); - TESTCASE( fmaxf( f1, f1 ) == f1 ); - TESTCASE( fmaxf( f1, INFINITY ) == INFINITY ); - TESTCASE( fmaxf( INFINITY, f1 ) == INFINITY ); - TESTCASE( fmaxf( f1, -INFINITY ) == f1 ); - TESTCASE( fmaxf( -INFINITY, f1 ) == f1 ); - TESTCASE( fmaxf( f1, NAN ) == f1 ); - TESTCASE( fmaxf( NAN, f1 ) == f1 ); - TESTCASE( fmaxf( f1, -NAN ) == f1 ); - TESTCASE( fmaxf( -NAN, f1 ) == f1 ); - TESTCASE( fmaxf( NAN, NAN ) != fmaxf( NAN, NAN ) ); - f1 = 0.0f; - f2 = -0.0f; - TESTCASE( fmaxf( f1, f2 ) == f1 ); - TESTCASE( fmaxf( f2, f1 ) == f1 ); - - d1 = 3.15f; - d2 = 3.16f; - TESTCASE( fmax( d1, d2 ) == d2 ); - TESTCASE( fmax( d2, d1 ) == d2 ); - TESTCASE( fmax( d1, d1 ) == d1 ); - TESTCASE( fmax( d1, INFINITY ) == INFINITY ); - TESTCASE( fmax( INFINITY, d1 ) == INFINITY ); - TESTCASE( fmax( d1, -INFINITY ) == d1 ); - TESTCASE( fmax( -INFINITY, d1 ) == d1 ); - TESTCASE( fmax( d1, NAN ) == d1 ); - TESTCASE( fmax( NAN, d1 ) == d1 ); - TESTCASE( fmax( d1, -NAN ) == d1 ); - TESTCASE( fmax( -NAN, d1 ) == d1 ); - TESTCASE( fmax( NAN, NAN ) != fmax( NAN, NAN ) ); - d1 = 0.0; - d2 = -0.0; - TESTCASE( fmax( d1, d2 ) == d1 ); - TESTCASE( fmax( d2, d1 ) == d1 ); - - ld1 = 3.15f; - ld2 = 3.16f; - TESTCASE( fmaxl( ld1, ld2 ) == ld2 ); - TESTCASE( fmaxl( ld2, ld1 ) == ld2 ); - TESTCASE( fmaxl( ld1, ld1 ) == ld1 ); - TESTCASE( fmaxl( ld1, INFINITY ) == INFINITY ); - TESTCASE( fmaxl( INFINITY, ld1 ) == INFINITY ); - TESTCASE( fmaxl( ld1, -INFINITY ) == ld1 ); - TESTCASE( fmaxl( -INFINITY, ld1 ) == ld1 ); - TESTCASE( fmaxl( ld1, NAN ) == ld1 ); - TESTCASE( fmaxl( NAN, ld1 ) == ld1 ); - TESTCASE( fmaxl( ld1, -NAN ) == ld1 ); - TESTCASE( fmaxl( -NAN, ld1 ) == ld1 ); - TESTCASE( fmaxl( NAN, NAN ) != fmaxl( NAN, NAN ) ); - ld1 = 0.0; - ld2 = -0.0; - TESTCASE( fmaxl( ld1, ld2 ) == ld1 ); - TESTCASE( fmaxl( ld2, ld1 ) == ld1 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/fmin.c b/rocklibc/src/math/fmin.c deleted file mode 100644 index 90c2dc0..0000000 --- a/rocklibc/src/math/fmin.c +++ /dev/null @@ -1,105 +0,0 @@ - -/* fmin( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -double fmin( double x, double y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x < y ) ? x : y; -} - -float fminf( float x, float y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x < y ) ? x : y; -} - -long double fminl( long double x, long double y ) -{ - if ( isnan( x ) ) return y; - if ( isnan( y ) ) return x; - return ( x < y ) ? x : y; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f1, f2; - double d1, d2; - long double ld1, ld2; - - f1 = 3.16f; - f2 = 3.15f; - TESTCASE( fminf( f1, f2 ) == f2 ); - TESTCASE( fminf( f2, f1 ) == f2 ); - TESTCASE( fminf( f1, f1 ) == f1 ); - TESTCASE( fminf( f1, INFINITY ) == f1 ); - TESTCASE( fminf( INFINITY, f1 ) == f1 ); - TESTCASE( fminf( f1, -INFINITY ) == -INFINITY ); - TESTCASE( fminf( -INFINITY, f1 ) == -INFINITY ); - TESTCASE( fminf( f1, NAN ) == f1 ); - TESTCASE( fminf( NAN, f1 ) == f1 ); - TESTCASE( fminf( f1, -NAN ) == f1 ); - TESTCASE( fminf( -NAN, f1 ) == f1 ); - TESTCASE( fminf( NAN, NAN ) != fminf( NAN, NAN ) ); - f1 = -0.0f; - f2 = 0.0f; - TESTCASE( fminf( f1, f2 ) == f1 ); - TESTCASE( fminf( f2, f1 ) == f1 ); - - d1 = 3.16f; - d2 = 3.15f; - TESTCASE( fmin( d1, d2 ) == d2 ); - TESTCASE( fmin( d2, d1 ) == d2 ); - TESTCASE( fmin( d1, d1 ) == d1 ); - TESTCASE( fmin( d1, INFINITY ) == d1 ); - TESTCASE( fmin( INFINITY, d1 ) == d1 ); - TESTCASE( fmin( d1, -INFINITY ) == -INFINITY ); - TESTCASE( fmin( -INFINITY, d1 ) == -INFINITY ); - TESTCASE( fmin( d1, NAN ) == d1 ); - TESTCASE( fmin( NAN, d1 ) == d1 ); - TESTCASE( fmin( d1, -NAN ) == d1 ); - TESTCASE( fmin( -NAN, d1 ) == d1 ); - TESTCASE( fmin( NAN, NAN ) != fmin( NAN, NAN ) ); - d1 = -0.0; - d2 = 0.0; - TESTCASE( fmin( d1, d2 ) == d1 ); - TESTCASE( fmin( d2, d1 ) == d1 ); - - ld1 = 3.16f; - ld2 = 3.15f; - TESTCASE( fminl( ld1, ld2 ) == ld2 ); - TESTCASE( fminl( ld2, ld1 ) == ld2 ); - TESTCASE( fminl( ld1, ld1 ) == ld1 ); - TESTCASE( fminl( ld1, INFINITY ) == ld1 ); - TESTCASE( fminl( INFINITY, ld1 ) == ld1 ); - TESTCASE( fminl( ld1, -INFINITY ) == -INFINITY ); - TESTCASE( fminl( -INFINITY, ld1 ) == -INFINITY ); - TESTCASE( fminl( ld1, NAN ) == ld1 ); - TESTCASE( fminl( NAN, ld1 ) == ld1 ); - TESTCASE( fminl( ld1, -NAN ) == ld1 ); - TESTCASE( fminl( -NAN, ld1 ) == ld1 ); - TESTCASE( fminl( NAN, NAN ) != fminl( NAN, NAN ) ); - ld1 = -0.0; - ld2 = 0.0; - TESTCASE( fminl( ld1, ld2 ) == ld1 ); - TESTCASE( fminl( ld2, ld1 ) == ld1 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/fpclassify.c b/rocklibc/src/math/fpclassify.c deleted file mode 100644 index 059aa9a..0000000 --- a/rocklibc/src/math/fpclassify.c +++ /dev/null @@ -1,161 +0,0 @@ -/* fpclassify( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_fpclassifyd( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - _PDCLIB_bigint_digit_t digit = 0; - size_t size; - size_t i; - int exp; - - memcpy( data, &x, sizeof( double ) ); - exp = _PDCLIB_DBL_EXP( data ); - size = _PDCLIB_DBL_SIZE( data ); - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - switch ( exp ) - { - case ( ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP ): - return ( digit == 0 ) ? FP_INFINITE : FP_NAN; - case 0: - return ( digit == 0 ) ? FP_ZERO : FP_SUBNORMAL; - default: - return FP_NORMAL; - } -} - -int _PDCLIB_fpclassifyf( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - _PDCLIB_bigint_digit_t digit = 0; - size_t size; - size_t i; - int exp; - - memcpy( data, &x, sizeof( float ) ); - exp = _PDCLIB_FLT_EXP( data ); - size = _PDCLIB_FLT_SIZE( data ); - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - switch ( exp ) - { - case ( ( _PDCLIB_FLT_MAX_EXP - 1 ) + _PDCLIB_FLT_MAX_EXP ): - return ( digit == 0 ) ? FP_INFINITE : FP_NAN; - case 0: - return ( digit == 0 ) ? FP_ZERO : FP_SUBNORMAL; - default: - return FP_NORMAL; - } -} - -int _PDCLIB_fpclassifyl( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - _PDCLIB_bigint_digit_t digit = 0; - size_t size; - size_t i; - int exp; - - memcpy( data, &x, sizeof( long double ) ); - exp = _PDCLIB_LDBL_EXP( data ); - size = _PDCLIB_LDBL_SIZE( data ); - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - switch ( exp ) - { - case ( ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP ): - return ( digit == 0 ) ? FP_INFINITE : FP_NAN; - case 0: - return ( digit == 0 ) ? FP_ZERO : FP_SUBNORMAL; - default: - return FP_NORMAL; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 0.123; - TESTCASE( fpclassify( f ) == FP_NORMAL ); - f = FLT_MIN; - TESTCASE( fpclassify( f ) == FP_NORMAL ); - f = FLT_MIN / 2; - TESTCASE( fpclassify( f ) == FP_SUBNORMAL ); - f = 0.0; - TESTCASE( fpclassify( f ) == FP_ZERO ); - f = FLT_MAX; - TESTCASE( fpclassify( f ) == FP_NORMAL ); - f = FLT_MAX * 2; - TESTCASE( fpclassify( f ) == FP_INFINITE ); - f = 0.0 / 0.0; - TESTCASE( fpclassify( f ) == FP_NAN ); - - d = 0.123; - TESTCASE( fpclassify( d ) == FP_NORMAL ); - d = DBL_MIN; - TESTCASE( fpclassify( d ) == FP_NORMAL ); - d = DBL_MIN / 2; - TESTCASE( fpclassify( d ) == FP_SUBNORMAL ); - d = 0.0; - TESTCASE( fpclassify( d ) == FP_ZERO ); - d = DBL_MAX; - TESTCASE( fpclassify( d ) == FP_NORMAL ); - d = DBL_MAX * 2; - TESTCASE( fpclassify( d ) == FP_INFINITE ); - d = 0.0 / 0.0; - TESTCASE( fpclassify( d ) == FP_NAN ); - - ld = 0.123; - TESTCASE( fpclassify( ld ) == FP_NORMAL ); - ld = LDBL_MIN; - TESTCASE( fpclassify( ld ) == FP_NORMAL ); - ld = LDBL_MIN / 2; - TESTCASE( fpclassify( ld ) == FP_SUBNORMAL ); - ld = 0.0; - TESTCASE( fpclassify( ld ) == FP_ZERO ); - ld = LDBL_MAX; - TESTCASE( fpclassify( ld ) == FP_NORMAL ); - ld = LDBL_MAX * 2; - TESTCASE( fpclassify( ld ) == FP_INFINITE ); - ld = 0.0 / 0.0; - TESTCASE( fpclassify( ld ) == FP_NAN ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/isfinite.c b/rocklibc/src/math/isfinite.c deleted file mode 100644 index 5c332af..0000000 --- a/rocklibc/src/math/isfinite.c +++ /dev/null @@ -1,92 +0,0 @@ -/* isfinite( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_isfinited( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - memcpy( data, &x, sizeof( double ) ); - return _PDCLIB_DBL_EXP( data ) != ( ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP ); -} - -int _PDCLIB_isfinitef( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - memcpy( data, &x, sizeof( float ) ); - return _PDCLIB_FLT_EXP( data ) != ( ( _PDCLIB_FLT_MAX_EXP - 1 ) + _PDCLIB_FLT_MAX_EXP ); -} - -int _PDCLIB_isfinitel( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - memcpy( data, &x, sizeof( long double ) ); - return _PDCLIB_LDBL_EXP( data ) != ( ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 0.123f; - TESTCASE( isfinite( f ) ); - f = FLT_MAX; - TESTCASE( isfinite( f ) ); - f *= 2; - TESTCASE( ! isfinite( f ) ); - f = FLT_MIN; - TESTCASE( isfinite( f ) ); - f /= 2; - TESTCASE( isfinite( f ) ); - f = 0.0f / 0.0f; - TESTCASE( ! isfinite( f ) ); - - d = 0.123; - TESTCASE( isfinite( d ) ); - d = DBL_MAX; - TESTCASE( isfinite( d ) ); - d *= 2; - TESTCASE( ! isfinite( d ) ); - d = DBL_MIN; - TESTCASE( isfinite( d ) ); - d /= 2; - TESTCASE( isfinite( d ) ); - d = 0.0 / 0.0; - TESTCASE( ! isfinite( d ) ); - - ld = 0.123l; - TESTCASE( isfinite( ld ) ); - ld = LDBL_MAX; - TESTCASE( isfinite( ld ) ); - ld *= 2; - TESTCASE( ! isfinite( ld ) ); - ld = LDBL_MIN; - TESTCASE( isfinite( ld ) ); - ld /= 2; - TESTCASE( isfinite( ld ) ); - ld = 0.0l / 0.0l; - TESTCASE( ! isfinite( ld ) ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/isinf.c b/rocklibc/src/math/isinf.c deleted file mode 100644 index bc1e62a..0000000 --- a/rocklibc/src/math/isinf.c +++ /dev/null @@ -1,123 +0,0 @@ -/* isinf( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_isinfd( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( double ) ); - exp = _PDCLIB_DBL_EXP( data ); - size = _PDCLIB_DBL_SIZE( data ); - - if ( exp == ( ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit == 0; - } - - return 0; -} - -int _PDCLIB_isinff( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( float ) ); - exp = _PDCLIB_FLT_EXP( data ); - size = _PDCLIB_FLT_SIZE( data ); - - if ( exp == ( ( _PDCLIB_FLT_MAX_EXP - 1 ) + _PDCLIB_FLT_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit == 0; - } - - return 0; -} - -int _PDCLIB_isinfl( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( long double ) ); - exp = _PDCLIB_LDBL_EXP( data ); - size = _PDCLIB_LDBL_SIZE( data ); - - if ( exp == ( ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit == 0; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 1e100; - TESTCASE( isinf( f ) == 1 ); - f = 0.0 / 0.0; - TESTCASE( isinf( f ) == 0 ); - - d = 1e500; - TESTCASE( isinf( d ) == 1 ); - d = 0.0 / 0.0; - TESTCASE( isinf( d ) == 0 ); - - ld = 1e500; - TESTCASE( isinf( ld ) == 1 ); - ld = 0.0 / 0.0; - TESTCASE( isinf( ld ) == 0 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/isnan.c b/rocklibc/src/math/isnan.c deleted file mode 100644 index 32eb3ed..0000000 --- a/rocklibc/src/math/isnan.c +++ /dev/null @@ -1,123 +0,0 @@ -/* isnan( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_isnand( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( double ) ); - exp = _PDCLIB_DBL_EXP( data ); - size = _PDCLIB_DBL_SIZE( data ); - - if ( exp == ( ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit != 0; - } - - return 0; -} - -int _PDCLIB_isnanf( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( float ) ); - exp = _PDCLIB_FLT_EXP( data ); - size = _PDCLIB_FLT_SIZE( data ); - - if ( exp == ( ( _PDCLIB_FLT_MAX_EXP - 1 ) + _PDCLIB_FLT_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit != 0; - } - - return 0; -} - -int _PDCLIB_isnanl( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - size_t size; - int exp; - - memcpy( data, &x, sizeof( long double ) ); - exp = _PDCLIB_LDBL_EXP( data ); - size = _PDCLIB_LDBL_SIZE( data ); - - if ( exp == ( ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP ) ) - { - _PDCLIB_bigint_digit_t digit = 0; - size_t i; - - for ( i = 0; i < size; ++i ) - { - digit |= data[i]; - } - - return digit != 0; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 1e100; - TESTCASE( isnan( f ) == 0 ); - f = 0.0 / 0.0; - TESTCASE( isnan( f ) == 1 ); - - d = 1e500; - TESTCASE( isnan( d ) == 0 ); - d = 0.0 / 0.0; - TESTCASE( isnan( d ) == 1 ); - - ld = 1e500; - TESTCASE( isnan( ld ) == 0 ); - ld = 0.0 / 0.0; - TESTCASE( isnan( ld ) == 1 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/isnormal.c b/rocklibc/src/math/isnormal.c deleted file mode 100644 index 2c3ed1d..0000000 --- a/rocklibc/src/math/isnormal.c +++ /dev/null @@ -1,110 +0,0 @@ -/* isnormal( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_isnormald( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - int exp; - memcpy( data, &x, sizeof( double ) ); - exp = _PDCLIB_DBL_EXP( data ); - return ( exp != ( ( _PDCLIB_DBL_MAX_EXP - 1 ) + _PDCLIB_DBL_MAX_EXP ) ) && ( exp != 0 ); -} - -int _PDCLIB_isnormalf( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - int exp; - memcpy( data, &x, sizeof( float ) ); - exp = _PDCLIB_FLT_EXP( data ); - return ( exp != ( ( _PDCLIB_FLT_MAX_EXP - 1 ) + _PDCLIB_FLT_MAX_EXP ) ) && ( exp != 0 ); -} - -int _PDCLIB_isnormall( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - int exp; - memcpy( data, &x, sizeof( long double ) ); - exp = _PDCLIB_LDBL_EXP( data ); - return ( exp != ( ( _PDCLIB_LDBL_MAX_EXP - 1 ) + _PDCLIB_LDBL_MAX_EXP ) ) && ( exp != 0 ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 0.123f; - TESTCASE( isnormal( f ) ); - f = FLT_MAX; - TESTCASE( isnormal( f ) ); - f = FLT_MAX * 2; - TESTCASE( ! isnormal( f ) ); - f = FLT_MIN; - TESTCASE( isnormal( f ) ); - f = FLT_MIN / 2; - TESTCASE( ! isnormal( f ) ); - f = 0.0f; - TESTCASE( ! isnormal( f ) ); - f = 1e100; - TESTCASE( ! isnormal( f ) ); - f = 0.0 / 0.0; - TESTCASE( ! isnormal( f ) ); - - d = 0.123f; - TESTCASE( isnormal( d ) ); - d = DBL_MAX; - TESTCASE( isnormal( d ) ); - d = DBL_MAX * 2; - TESTCASE( ! isnormal( d ) ); - d = DBL_MIN; - TESTCASE( isnormal( d ) ); - d = DBL_MIN / 2; - TESTCASE( ! isnormal( d ) ); - d = 0.0f; - TESTCASE( ! isnormal( d ) ); - d = 1e500; - TESTCASE( ! isnormal( d ) ); - d = 0.0 / 0.0; - TESTCASE( ! isnormal( d ) ); - - ld = 0.123f; - TESTCASE( isnormal( ld ) ); - ld = LDBL_MAX; - TESTCASE( isnormal( ld ) ); - ld = LDBL_MAX * 2; - TESTCASE( ! isnormal( ld ) ); - ld = LDBL_MIN; - TESTCASE( isnormal( ld ) ); - ld = LDBL_MIN / 2; - TESTCASE( ! isnormal( ld ) ); - ld = 0.0f; - TESTCASE( ! isnormal( ld ) ); - ld = 1e1000; - TESTCASE( ! isnormal( ld ) ); - ld = 0.0 / 0.0; - TESTCASE( ! isnormal( ld ) ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/math/signbit.c b/rocklibc/src/math/signbit.c deleted file mode 100644 index 4113450..0000000 --- a/rocklibc/src/math/signbit.c +++ /dev/null @@ -1,69 +0,0 @@ -/* signbit( double ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_print.h" - -#include - -int _PDCLIB_signbitd( double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - - memcpy( data, &x, sizeof( double ) ); - return _PDCLIB_DBL_SIGN( data ) != 0; -} - -int _PDCLIB_signbitf( float x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( float ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - - memcpy( data, &x, sizeof( float ) ); - return _PDCLIB_FLT_SIGN( data ) != 0; -} - -int _PDCLIB_signbitl( long double x ) -{ - _PDCLIB_bigint_digit_t data[ sizeof( long double ) / sizeof( _PDCLIB_bigint_digit_t ) ]; - - memcpy( data, &x, sizeof( long double ) ); - return _PDCLIB_LDBL_SIGN( data ) != 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - float f; - double d; - long double ld; - - f = 0.123f; - TESTCASE( ! signbit( f ) ); - f = -0.123f; - TESTCASE( signbit( f ) ); - - d = 0.123; - TESTCASE( ! signbit( d ) ); - d = -0.123; - TESTCASE( signbit( d ) ); - - ld = 0.123l; - TESTCASE( ! signbit( ld ) ); - ld = -0.123l; - TESTCASE( signbit( ld ) ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/rockos/syscall.c b/rocklibc/src/rockos/syscall.c deleted file mode 100644 index 4afe9d4..0000000 --- a/rocklibc/src/rockos/syscall.c +++ /dev/null @@ -1,114 +0,0 @@ -#include -#include -#include - -typedef int _PDCLIB_fd_t; - -static inline int32_t inline_syscall(uint32_t num, uint32_t arg1, uint32_t arg2, uint32_t arg3) { - int32_t ret; - asm volatile ( - "int $0x80" - : "=a" (ret) - : "a" (num), "b" (arg1), "c" (arg2), "d" (arg3) - : "memory" - ); - return ret; -} - -void _PDCLIB_exit(int status) { - inline_syscall(1, (uint32_t)status, 0, 0);; -} - -int _PDCLIB_read(_PDCLIB_fd_t fd, void *buf, size_t count) { - int32_t ret = inline_syscall(3, (uint32_t)fd, (uint32_t)buf, (uint32_t)count); - if (ret < 0) { - return 0; - } - return ret; -} - -int _PDCLIB_write(_PDCLIB_fd_t fd, const void *buf, size_t count) { - int32_t ret = inline_syscall(4, (uint32_t)fd, (uint32_t)buf, (uint32_t)count); - if (ret < 0) { - return 0; - } - return ret; -} - -_PDCLIB_fd_t _PDCLIB_open(const char *filename, unsigned int mode) { - _PDCLIB_fd_t fd; - fd = inline_syscall(5, (uint32_t)filename, (uint32_t)mode, 0); - return fd; -} - -int _PDCLIB_close(_PDCLIB_fd_t fd) { - return inline_syscall(6, (uint32_t)fd, 0, 0); -} - -void * _PDCLIB_allocpages( size_t n ) { - // 1. Get the current page break - uint32_t current_break = inline_syscall(12, 0, 0, 0); - if (current_break == (uint32_t)-1) { - return NULL; - } - - // 2. PDCLib requests memory in multiples of PAGES (typically 4096 bytes) - uint32_t new_break = current_break + (n * 4096); - - // 3. Request kernel to move the break - uint32_t result = inline_syscall(12, new_break, 0, 0); - if (result != new_break) { - return NULL; // Allocation failed - } - - // Return the start of the newly allocated region - return (void *)current_break; -} - -int _PDCLIB_remove(const char *filename) { return -1; } -int _PDCLIB_rename(const char *old, const char *new) { return -1; } -long _PDCLIB_lseek(_PDCLIB_fd_t fd, long offset, int whence) { return -1; } - -int open(const char *pathname, int flags, ...) { - _PDCLIB_fd_t fd = _PDCLIB_open(pathname, (unsigned int)flags); - return fd; -} - -int read(int fd, void *buf, size_t count) { - _PDCLIB_fd_t file_desc = fd; - return _PDCLIB_read(file_desc, buf, count); -} - -int write(int fd, const void *buf, size_t count) { - return _PDCLIB_write(fd, buf, count); -} - -int close(int fd) { - _PDCLIB_fd_t file_desc = fd; - return _PDCLIB_close(file_desc); -} - -void * sbrk(intptr_t increment) { - uint32_t current_break = inline_syscall(12, 0, 0, 0); - if (current_break == (uint32_t)-1) { - return (void *)-1; - } - - if (increment == 0) { - return (void *)current_break; - } - - uint32_t new_break = (uint32_t)((intptr_t)current_break + increment); - - uint32_t result = inline_syscall(12, new_break, 0, 0); - - if (result == new_break) { - return (void *)current_break; - } - - return (void *)-1; -} - -void _exit(int status) { - _PDCLIB_exit(status); -} \ No newline at end of file diff --git a/rocklibc/src/rockos/time.c b/rocklibc/src/rockos/time.c deleted file mode 100644 index f042989..0000000 --- a/rocklibc/src/rockos/time.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -int gettimeofday(struct timeval *restrict tv, void *restrict tz) { - if (tv) { - tv->tv_sec = 0; /* Default to Jan 1, 1970 */ - tv->tv_usec = 0; - } - return 0; // Return success code -} \ No newline at end of file diff --git a/rocklibc/src/rockos/times.c b/rocklibc/src/rockos/times.c deleted file mode 100644 index 4cdb950..0000000 --- a/rocklibc/src/rockos/times.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -clock_t times(struct tms *buffer) { - if (buffer) { - buffer->tms_utime = 0; - buffer->tms_stime = 0; - buffer->tms_cutime = 0; - buffer->tms_cstime = 0; - } - // Return -1 to safely indicate that timing information is not available - return (clock_t)-1; -} \ No newline at end of file diff --git a/rocklibc/src/signal/raise.c b/rocklibc/src/signal/raise.c deleted file mode 100644 index 9fb428c..0000000 --- a/rocklibc/src/signal/raise.c +++ /dev/null @@ -1,135 +0,0 @@ -/* raise( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include -#include - -extern void ( *_PDCLIB_sigabrt )( int ); -extern void ( *_PDCLIB_sigfpe )( int ); -extern void ( *_PDCLIB_sigill )( int ); -extern void ( *_PDCLIB_sigint )( int ); -extern void ( *_PDCLIB_sigsegv )( int ); -extern void ( *_PDCLIB_sigterm )( int ); - -int raise( int sig ) -{ - void ( *sighandler )( int ); - const char * message; - - switch ( sig ) - { - case SIGABRT: - sighandler = _PDCLIB_sigabrt; - message = "Abnormal termination (SIGABRT)"; - break; - - case SIGFPE: - sighandler = _PDCLIB_sigfpe; - message = "Arithmetic exception (SIGFPE)"; - break; - - case SIGILL: - sighandler = _PDCLIB_sigill; - message = "Illegal instruction (SIGILL)"; - break; - - case SIGINT: - sighandler = _PDCLIB_sigint; - message = "Interactive attention signal (SIGINT)"; - break; - - case SIGSEGV: - sighandler = _PDCLIB_sigsegv; - message = "Invalid memory access (SIGSEGV)"; - break; - - case SIGTERM: - sighandler = _PDCLIB_sigterm; - message = "Termination request (SIGTERM)"; - break; - - default: - fprintf( stderr, "Unknown signal #%d\n", sig ); - _Exit( EXIT_FAILURE ); - } - - if ( sighandler == SIG_DFL ) - { - fputs( message, stderr ); - _Exit( EXIT_FAILURE ); - } - else if ( sighandler != SIG_IGN ) - { - /* FIXME: "The implementation shall behave as if no library function - calls the signal function." - */ - sighandler = signal( sig, SIG_DFL ); - sighandler( sig ); - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -static volatile sig_atomic_t flag = 0; - -static int expected_signal = 0; - -static void test_handler( int sig ) -{ - TESTCASE( sig == expected_signal ); - flag = 1; -} - -int main( void ) -{ - void ( *sighandler )( int ); - /* Could be other than SIG_DFL if you changed the implementation. */ - sighandler = signal( SIGABRT, SIG_IGN ); -#ifndef REGTEST - TESTCASE( sighandler == SIG_DFL ); -#endif - /* Should be ignored. */ - TESTCASE( raise( SIGABRT ) == 0 ); - /* Installing test handler, old handler should be returned */ - TESTCASE( signal( SIGABRT, test_handler ) == SIG_IGN ); - /* Raising and checking SIGABRT */ - expected_signal = SIGABRT; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Re-installing test handler, should have been reset to default */ - /* Could be other than SIG_DFL if you changed the implementation. */ - sighandler = signal( SIGABRT, test_handler ); -#ifndef REGTEST - TESTCASE( sighandler == SIG_DFL ); -#endif - /* Raising and checking SIGABRT */ - flag = 0; - TESTCASE( raise( SIGABRT ) == 0 ); - TESTCASE( flag == 1 ); - /* Installing test handler for different signal... */ - TESTCASE( signal( SIGTERM, test_handler ) == SIG_DFL ); - /* Raising and checking SIGTERM */ - expected_signal = SIGTERM; - TESTCASE( raise( SIGTERM ) == 0 ); - TESTCASE( flag == 1 ); - /* void expression to avoid "unused" warning in regtest */ - (void)sighandler; - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/signal/signal.c b/rocklibc/src/signal/signal.c deleted file mode 100644 index 54d52ac..0000000 --- a/rocklibc/src/signal/signal.c +++ /dev/null @@ -1,84 +0,0 @@ -/* signal( int, void (*)( int ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -void ( *_PDCLIB_sigabrt )( int ) = SIG_DFL; -void ( *_PDCLIB_sigfpe )( int ) = SIG_DFL; -void ( *_PDCLIB_sigill )( int ) = SIG_DFL; -void ( *_PDCLIB_sigint )( int ) = SIG_DFL; -void ( *_PDCLIB_sigsegv )( int ) = SIG_DFL; -void ( *_PDCLIB_sigterm )( int ) = SIG_DFL; - -void ( *signal( int sig, void ( *func )( int ) ) )( int ) -{ - void ( *oldhandler )( int ); - - if ( sig <= 0 || func == SIG_ERR ) - { - return SIG_ERR; - } - - switch ( sig ) - { - case SIGABRT: - oldhandler = _PDCLIB_sigabrt; - _PDCLIB_sigabrt = func; - break; - - case SIGFPE: - oldhandler = _PDCLIB_sigfpe; - _PDCLIB_sigfpe = func; - break; - - case SIGILL: - oldhandler = _PDCLIB_sigill; - _PDCLIB_sigill = func; - break; - - case SIGINT: - oldhandler = _PDCLIB_sigint; - _PDCLIB_sigint = func; - break; - - case SIGSEGV: - oldhandler = _PDCLIB_sigsegv; - _PDCLIB_sigsegv = func; - break; - - case SIGTERM: - oldhandler = _PDCLIB_sigterm; - _PDCLIB_sigterm = func; - break; - - default: - /* The standard calls for an unspecified "positive value". - Copying Linux' behaviour of setting EINVAL. - */ - *_PDCLIB_errno_func() = _PDCLIB_EINVAL; - return SIG_ERR; - } - - return oldhandler; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by raise.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio.c b/rocklibc/src/stdio.c new file mode 100644 index 0000000..f6c4415 --- /dev/null +++ b/rocklibc/src/stdio.c @@ -0,0 +1,122 @@ +#include +#include + +static void utoa(unsigned int value, char *buf, int base) { + char temp[32]; + int i = 0; + + // Handle zero explicitly + if (value == 0) { + buf[0] = '0'; + buf[1] = '\0'; + return; + } + + // Convert digits in reverse order + while (value > 0) { + int remainder = value % base; + if (remainder < 10) { + temp[i++] = '0' + remainder; + } else { + temp[i++] = 'a' + (remainder - 10); + } + value /= base; + } + + // Reverse the string into the output destination buffer + int j = 0; + while (i > 0) { + buf[j++] = temp[--i]; + } + buf[j] = '\0'; +} + +/* Helper function to convert a signed integer to a string */ +static void itoa(int value, char *buf, int base) { + if (value < 0 && base == 10) { + *buf++ = '-'; + value = -value; + } + utoa((unsigned int)value, buf, base); +} + +int printf(const char *format, ...) { + va_list args; + va_start(args, format); + + int written_total = 0; + char num_buf[32]; // Stack-allocated scratchpad for string conversions + + while (*format != '\0') { + if (*format == '%') { + format++; // Move past '%' + + switch (*format) { + case 'c': { + char c = (char)va_arg(args, int); + write(1, &c, 1); + written_total++; + break; + } + case 's': { + char *s = va_arg(args, char *); + if (!s) s = "(null)"; + // Find length manually without dragging headers + int len = 0; + while (s[len] != '\0') len++; + write(1, s, len); + written_total += len; + break; + } + case 'd': + case 'i': { + int n = va_arg(args, int); + itoa(n, num_buf, 10); + int len = 0; + while (num_buf[len] != '\0') len++; + write(1, num_buf, len); + written_total += len; + break; + } + case 'x': { + unsigned int x = va_arg(args, unsigned int); + utoa(x, num_buf, 16); + int len = 0; + while (num_buf[len] != '\0') len++; + write(1, num_buf, len); + written_total += len; + break; + } + case '%': { + write(1, "%", 1); + written_total++; + break; + } + default: + // Unknown conversion, print verbatim + write(1, format - 1, 2); + written_total += 2; + break; + } + } else { + // Standard text character + write(1, format, 1); + written_total++; + } + format++; + } + + va_end(args); + return written_total; +} + +char getchar(void) { + char c; + int res = read(0, &c, 1); + + if (res <= 0) { + return -1; + } + + return (char)c; +} diff --git a/rocklibc/src/stdio/clearerr.c b/rocklibc/src/stdio/clearerr.c deleted file mode 100644 index 12d8ce0..0000000 --- a/rocklibc/src/stdio/clearerr.c +++ /dev/null @@ -1,54 +0,0 @@ -/* clearerr( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void clearerr( struct _PDCLIB_file_t * stream ) -{ - stream->status &= ~( _PDCLIB_ERRORFLAG | _PDCLIB_EOFFLAG ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - FILE * fh; - TESTCASE( ( fh = tmpfile() ) != NULL ); - /* Flags should be clear */ - TESTCASE( ! ferror( fh ) ); - TESTCASE( ! feof( fh ) ); - /* Reading from empty stream - should provoke EOF */ - rewind( fh ); - TESTCASE( fgetc( fh ) == EOF ); - TESTCASE( ! ferror( fh ) ); - TESTCASE( feof( fh ) ); - /* clearerr() should clear flags */ - clearerr( fh ); - TESTCASE( ! ferror( fh ) ); - TESTCASE( ! feof( fh ) ); -#ifndef __ANDROID__ - /* reopen() the file write-only -- this fails on Termix */ - TESTCASE( ( fh = freopen( NULL, "w", fh ) ) != NULL ); - /* Reading from write-only stream - should provoke error */ - TESTCASE( fgetc( fh ) == EOF ); - TESTCASE( ferror( fh ) ); - TESTCASE( ! feof( fh ) ); -#endif - /* clearerr() should clear flags */ - clearerr( fh ); - TESTCASE( ! ferror( fh ) ); - TESTCASE( ! feof( fh ) ); - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fclose.c b/rocklibc/src/stdio/fclose.c deleted file mode 100644 index 23e01c4..0000000 --- a/rocklibc/src/stdio/fclose.c +++ /dev/null @@ -1,117 +0,0 @@ -/* fclose( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -int fclose( struct _PDCLIB_file_t * stream ) -{ - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - _PDCLIB_LOCK( stream->mtx ); - - /* Flush buffer */ - if ( stream->status & _PDCLIB_FWRITE ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - /* Flush failed, errno already set */ - _PDCLIB_UNLOCK( stream->mtx ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return EOF; - } - } - - /* Close handle */ - _PDCLIB_close( stream->handle ); - - /* Remove stream from list */ - if ( _PDCLIB_getstream( stream ) ) - { - _PDCLIB_UNLOCK( stream->mtx ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return EOF; - } - - /* Delete tmpfile() */ - if ( stream->status & _PDCLIB_DELONCLOSE ) - { - _PDCLIB_remove( stream->filename ); - } - - /* Free buffer */ - if ( stream->status & _PDCLIB_FREEBUFFER ) - { - free( stream->buffer ); - } - - /* Free filename (standard streams do not have one, but free( NULL ) - is a valid no-op) - */ - free( stream->filename ); - - _PDCLIB_UNLOCK( stream->mtx ); - -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &stream->mtx ); -#endif - - /* Free stream */ - if ( stream != stdin && stream != stdout && stream != stderr ) - { - free( stream ); - } - - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - struct _PDCLIB_file_t * file1; - struct _PDCLIB_file_t * file2; - remove( testfile1 ); - remove( testfile2 ); - TESTCASE( _PDCLIB_filelist == stdin ); - TESTCASE( ( file1 = fopen( testfile1, "w" ) ) != NULL ); - TESTCASE( _PDCLIB_filelist == file1 ); - TESTCASE( ( file2 = fopen( testfile2, "w" ) ) != NULL ); - TESTCASE( _PDCLIB_filelist == file2 ); - TESTCASE( fclose( file2 ) == 0 ); - TESTCASE( _PDCLIB_filelist == file1 ); - TESTCASE( ( file2 = fopen( testfile2, "w" ) ) != NULL ); - TESTCASE( _PDCLIB_filelist == file2 ); - TESTCASE( fclose( file1 ) == 0 ); - TESTCASE( _PDCLIB_filelist == file2 ); - TESTCASE( fclose( file2 ) == 0 ); - TESTCASE( _PDCLIB_filelist == stdin ); - TESTCASE( remove( testfile1 ) == 0 ); - TESTCASE( remove( testfile2 ) == 0 ); -#else - puts( " NOTEST fclose() test driver is PDCLib-specific." ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/feof.c b/rocklibc/src/stdio/feof.c deleted file mode 100644 index a57071f..0000000 --- a/rocklibc/src/stdio/feof.c +++ /dev/null @@ -1,28 +0,0 @@ -/* feof( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int feof( struct _PDCLIB_file_t * stream ) -{ - return stream->status & _PDCLIB_EOFFLAG; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by clearerr(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/ferror.c b/rocklibc/src/stdio/ferror.c deleted file mode 100644 index 54f43f0..0000000 --- a/rocklibc/src/stdio/ferror.c +++ /dev/null @@ -1,28 +0,0 @@ -/* ferror( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int ferror( struct _PDCLIB_file_t * stream ) -{ - return stream->status & _PDCLIB_ERRORFLAG; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by clearerr(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fflush.c b/rocklibc/src/stdio/fflush.c deleted file mode 100644 index 8f73bae..0000000 --- a/rocklibc/src/stdio/fflush.c +++ /dev/null @@ -1,71 +0,0 @@ -/* fflush( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -int fflush( struct _PDCLIB_file_t * stream ) -{ - int rc = 0; - - if ( stream == NULL ) - { - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - stream = _PDCLIB_filelist; - - /* TODO: Check what happens when fflush( NULL ) encounters write errors, in other libs */ - while ( stream != NULL ) - { - _PDCLIB_LOCK( stream->mtx ); - - if ( stream->status & _PDCLIB_FWRITE ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - rc = EOF; - } - } - - _PDCLIB_UNLOCK( stream->mtx ); - - stream = stream->next; - } - - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - } - else - { - _PDCLIB_LOCK( stream->mtx ); - rc = _PDCLIB_flushbuffer( stream ); - _PDCLIB_UNLOCK( stream->mtx ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fgetc.c b/rocklibc/src/stdio/fgetc.c deleted file mode 100644 index 7dec82f..0000000 --- a/rocklibc/src/stdio/fgetc.c +++ /dev/null @@ -1,48 +0,0 @@ -/* fgetc( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fgetc( struct _PDCLIB_file_t * stream ) -{ - int rc = EOF; - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepread( stream ) != EOF ) - { - if ( _PDCLIB_CHECKBUFFER( stream ) != EOF ) - { - rc = _PDCLIB_GETC( stream ); - } - } - - _PDCLIB_UNLOCK( stream->mtx ); - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fgetpos.c b/rocklibc/src/stdio/fgetpos.c deleted file mode 100644 index eb3d74f..0000000 --- a/rocklibc/src/stdio/fgetpos.c +++ /dev/null @@ -1,49 +0,0 @@ -/* fgetpos( FILE * , fpos_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fgetpos( struct _PDCLIB_file_t * _PDCLIB_restrict stream, struct _PDCLIB_fpos_t * _PDCLIB_restrict pos ) -{ - _PDCLIB_LOCK( stream->mtx ); - pos->offset = ( stream->pos.offset - ( ( ( int )stream->bufend - ( int )stream->bufidx ) + stream->ungetidx ) ); - pos->status = stream->pos.status; - /* TODO: Add mbstate. */ - _PDCLIB_UNLOCK( stream->mtx ); - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - FILE * fh; - fpos_t pos1, pos2; - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( fgetpos( fh, &pos1 ) == 0 ); - TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) ); - TESTCASE( fgetpos( fh, &pos2 ) == 0 ); - TESTCASE( fsetpos( fh, &pos1 ) == 0 ); - TESTCASE( ftell( fh ) == 0 ); - TESTCASE( fsetpos( fh, &pos2 ) == 0 ); - TESTCASE( ( size_t )ftell( fh ) == strlen( teststring ) ); - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fgets.c b/rocklibc/src/stdio/fgets.c deleted file mode 100644 index 12550b7..0000000 --- a/rocklibc/src/stdio/fgets.c +++ /dev/null @@ -1,98 +0,0 @@ -/* fgets( char *, int, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -char * fgets( char * _PDCLIB_restrict s, int size, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) -{ - char * dest = s; - - if ( size == 0 ) - { - return NULL; - } - - if ( size == 1 ) - { - *s = '\0'; - return s; - } - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepread( stream ) != EOF ) - { - do - { - if ( _PDCLIB_CHECKBUFFER( stream ) == EOF ) - { - /* In case of error / EOF before a character is read, this - will lead to a \0 be written anyway. Since the results - are "indeterminate" by definition, this does not hurt. - */ - break; - } - } - while ( ( ( *dest++ = _PDCLIB_GETC( stream ) ) != '\n' ) && ( --size > 0 ) ); - } - - _PDCLIB_UNLOCK( stream->mtx ); - - *dest = '\0'; - return ( dest == s ) ? NULL : s; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - FILE * fh; - char buffer[10]; - const char * fgets_test = "foo\nbar\0baz\nweenie"; - TESTCASE( ( fh = fopen( testfile, "wb+" ) ) != NULL ); - TESTCASE( fwrite( fgets_test, 1, 18, fh ) == 18 ); - rewind( fh ); - TESTCASE( fgets( buffer, 10, fh ) == buffer ); - TESTCASE( strcmp( buffer, "foo\n" ) == 0 ); - TESTCASE( fgets( buffer, 10, fh ) == buffer ); - TESTCASE( memcmp( buffer, "bar\0baz\n", 8 ) == 0 ); - TESTCASE( fgets( buffer, 10, fh ) == buffer ); - TESTCASE( strcmp( buffer, "weenie" ) == 0 ); - TESTCASE( feof( fh ) ); - TESTCASE( fseek( fh, -1, SEEK_END ) == 0 ); - /* newlib returns NULL on any n < 2, so we _NOREG these tests. */ - TESTCASE_NOREG( fgets( buffer, 1, fh ) == buffer ); - TESTCASE_NOREG( strcmp( buffer, "" ) == 0 ); - TESTCASE( fgets( buffer, 0, fh ) == NULL ); - TESTCASE( ! feof( fh ) ); - TESTCASE_NOREG( fgets( buffer, 1, fh ) == buffer ); - TESTCASE_NOREG( strcmp( buffer, "" ) == 0 ); - TESTCASE( ! feof( fh ) ); - TESTCASE( fgets( buffer, 2, fh ) == buffer ); - TESTCASE( strcmp( buffer, "e" ) == 0 ); - TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); - TESTCASE( fgets( buffer, 2, fh ) == NULL ); - TESTCASE( feof( fh ) ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fopen.c b/rocklibc/src/stdio/fopen.c deleted file mode 100644 index 3553e82..0000000 --- a/rocklibc/src/stdio/fopen.c +++ /dev/null @@ -1,104 +0,0 @@ -/* fopen( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -struct _PDCLIB_file_t * fopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ) -{ - struct _PDCLIB_file_t * rc; - unsigned int filemode = _PDCLIB_filemode( mode ); - - if ( filemode == 0 ) - { - /* mode invalid */ - return NULL; - } - - if ( filename == NULL || filename[0] == '\0' ) - { - /* filename invalid */ - return NULL; - } - - /* See tmpfile(), which does much of the same. */ - - if ( ( rc = _PDCLIB_init_file_t( NULL ) ) == NULL ) - { - /* initializing FILE structure failed */ - return NULL; - } - - /* Setting buffer to _IOLBF because "when opened, a stream is fully - buffered if and only if it can be determined not to refer to an - interactive device." - */ - rc->status |= filemode | _IOLBF; - - /* _PDCLIB_realpath() gives us an absolute path to the file, which - a later reopen() would need. - */ - if ( ( rc->handle = _PDCLIB_open( filename, rc->status ) ) == _PDCLIB_NOHANDLE - || ( rc->filename = _PDCLIB_realpath( filename ) ) == NULL ) - { - /* OS open() or realpath() failed */ -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &rc->mtx ); -#endif - free( rc->buffer ); - free( rc ); - return NULL; - } - - /* Adding to list of open files */ - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - rc->next = _PDCLIB_filelist; - _PDCLIB_filelist = rc; - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Some of the tests are not executed for regression tests, as the libc on - my system is at once less forgiving (segfaults on mode NULL) and more - forgiving (accepts undefined modes). - */ - FILE * fh; - remove( testfile ); - TESTCASE_NOREG( fopen( NULL, NULL ) == NULL ); - TESTCASE_NOREG( fopen( NULL, "w" ) == NULL ); - TESTCASE_NOREG( fopen( "", NULL ) == NULL ); - TESTCASE( fopen( "", "w" ) == NULL ); - TESTCASE( fopen( testfile, "" ) == NULL ); - TESTCASE_NOREG( fopen( testfile, "wq" ) == NULL ); /* Undefined mode */ - TESTCASE_NOREG( fopen( testfile, "wr" ) == NULL ); /* Undefined mode */ - TESTCASE( ( fh = fopen( testfile, "w" ) ) != NULL ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fopen_s.c b/rocklibc/src/stdio/fopen_s.c deleted file mode 100644 index 17ce907..0000000 --- a/rocklibc/src/stdio/fopen_s.c +++ /dev/null @@ -1,79 +0,0 @@ -/* fopen_s( FILE **, const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include - -#ifndef REGTEST - -errno_t fopen_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict streamptr, const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode ) -{ - if ( streamptr == NULL || filename == NULL || mode == NULL ) - { - if ( streamptr != NULL ) - { - *streamptr = NULL; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - if ( ( *streamptr = fopen( filename, mode ) ) == NULL ) - { - return *_PDCLIB_errno_func(); - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - /* Some of the tests are not executed for regression tests, as the libc on - my system is at once less forgiving (segfaults on mode NULL) and more - forgiving (accepts undefined modes). - */ - FILE * fh; - remove( testfile ); - set_constraint_handler_s( test_handler ); - - TESTCASE( fopen_s( NULL, NULL, NULL ) != 0 ); - TESTCASE( fopen_s( &fh, NULL, "w" ) != 0 ); - TESTCASE( fopen_s( &fh, "", "w" ) != 0 ); - TESTCASE( fopen_s( &fh, testfile, "" ) != 0 ); - TESTCASE( fopen_s( &fh, testfile, NULL ) != 0 ); - TESTCASE( fopen_s( &fh, testfile, "wq" ) != 0 ); - TESTCASE( fopen_s( &fh, testfile, "wr" ) != 0 ); - TESTCASE( fopen_s( &fh, testfile, "w" ) == 0 ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - TESTCASE( HANDLER_CALLS == 3 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fprintf.c b/rocklibc/src/stdio/fprintf.c deleted file mode 100644 index 522f161..0000000 --- a/rocklibc/src/stdio/fprintf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* fprintf( FILE *, const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int fprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vfprintf( stream, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST - -#include -#include -#include - -#define _PDCLIB_FILEID "stdio/fprintf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -#define testprintf( stream, ... ) fprintf( stream, __VA_ARGS__ ) - -int main( void ) -{ - FILE * target; - TESTCASE( ( target = tmpfile() ) != NULL ); -#include "printf_testcases.h" - TESTCASE( fclose( target ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fputc.c b/rocklibc/src/stdio/fputc.c deleted file mode 100644 index bcf1e61..0000000 --- a/rocklibc/src/stdio/fputc.c +++ /dev/null @@ -1,55 +0,0 @@ -/* fputc( int, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fputc( int c, struct _PDCLIB_file_t * stream ) -{ - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepwrite( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - stream->buffer[stream->bufidx++] = ( char )c; - - if ( ( stream->bufidx == stream->bufsize ) /* _IOFBF */ - || ( ( stream->status & _IOLBF ) && ( ( char )c == '\n' ) ) /* _IOLBF */ - || ( stream->status & _IONBF ) /* _IONBF */ - ) - { - /* buffer filled, unbuffered stream, or end-of-line. */ - c = ( _PDCLIB_flushbuffer( stream ) == 0 ) ? c : EOF; - } - - _PDCLIB_UNLOCK( stream->mtx ); - - return c; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fputs.c b/rocklibc/src/stdio/fputs.c deleted file mode 100644 index 5f9df7d..0000000 --- a/rocklibc/src/stdio/fputs.c +++ /dev/null @@ -1,87 +0,0 @@ -/* fputs( const char *, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fputs( const char * _PDCLIB_restrict s, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) -{ - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepwrite( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - while ( *s != '\0' ) - { - /* Unbuffered and line buffered streams get flushed when fputs() does - write the terminating end-of-line. All streams get flushed if the - buffer runs full. - */ - stream->buffer[ stream->bufidx++ ] = *s; - - if ( ( stream->bufidx == stream->bufsize ) || - ( ( stream->status & _IOLBF ) && *s == '\n' ) - ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - } - - ++s; - } - - if ( stream->status & _IONBF ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - } - - _PDCLIB_UNLOCK( stream->mtx ); - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - const char * const message = "SUCCESS testing fputs()"; - FILE * fh; - size_t i; - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( fputs( message, fh ) >= 0 ); - rewind( fh ); - - for ( i = 0; i < 23; ++i ) - { - TESTCASE( fgetc( fh ) == message[i] ); - } - - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fread.c b/rocklibc/src/stdio/fread.c deleted file mode 100644 index 8d2cde8..0000000 --- a/rocklibc/src/stdio/fread.c +++ /dev/null @@ -1,93 +0,0 @@ -/* fread( void *, size_t, size_t, struct * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -size_t fread( void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) -{ - char * dest = ( char * )ptr; - size_t nmemb_i = 0; - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepread( stream ) != EOF ) - { - for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i ) - { - size_t size_i; - - /* TODO: For better performance, move from stream buffer - to destination block-wise, not byte-wise. - */ - for ( size_i = 0; size_i < size; ++size_i ) - { - if ( _PDCLIB_CHECKBUFFER( stream ) == EOF ) - { - /* Could not read requested data */ - _PDCLIB_UNLOCK( stream->mtx ); - return nmemb_i; - } - - dest[ nmemb_i * size + size_i ] = _PDCLIB_GETC( stream ); - } - } - } - - _PDCLIB_UNLOCK( stream->mtx ); - - return nmemb_i; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - FILE * fh; - const char * message = "Testing fwrite()...\n"; - char buffer[21]; - buffer[20] = 'x'; - TESTCASE( ( fh = tmpfile() ) != NULL ); - /* fwrite() / readback */ - TESTCASE( fwrite( message, 1, 20, fh ) == 20 ); - rewind( fh ); - TESTCASE( fread( buffer, 1, 20, fh ) == 20 ); - TESTCASE( memcmp( buffer, message, 20 ) == 0 ); - TESTCASE( buffer[20] == 'x' ); - /* same, different nmemb / size settings */ - rewind( fh ); - TESTCASE( memset( buffer, '\0', 20 ) == buffer ); - TESTCASE( fwrite( message, 5, 4, fh ) == 4 ); - rewind( fh ); - TESTCASE( fread( buffer, 5, 4, fh ) == 4 ); - TESTCASE( memcmp( buffer, message, 20 ) == 0 ); - TESTCASE( buffer[20] == 'x' ); - /* same... */ - rewind( fh ); - TESTCASE( memset( buffer, '\0', 20 ) == buffer ); - TESTCASE( fwrite( message, 20, 1, fh ) == 1 ); - rewind( fh ); - TESTCASE( fread( buffer, 20, 1, fh ) == 1 ); - TESTCASE( memcmp( buffer, message, 20 ) == 0 ); - TESTCASE( buffer[20] == 'x' ); - /* Done. */ - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/freopen.c b/rocklibc/src/stdio/freopen.c deleted file mode 100644 index 960dd6c..0000000 --- a/rocklibc/src/stdio/freopen.c +++ /dev/null @@ -1,242 +0,0 @@ -/* freopen( const char *, const char *, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -struct _PDCLIB_file_t * freopen( const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) -{ - unsigned int filemode = _PDCLIB_filemode( mode ); - - if ( stream == NULL ) - { - errno = EBADF; - return NULL; - } - - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - - if ( _PDCLIB_isstream( stream, NULL ) ) - { - /* May lock only after established that stream is valid */ - _PDCLIB_LOCK( stream->mtx ); - - /* Flush buffer */ - if ( stream->status & _PDCLIB_FWRITE ) - { - _PDCLIB_flushbuffer( stream ); - } - - if ( filename == NULL ) - { - /* Attempt to change mode without closing stream */ - switch ( _PDCLIB_changemode( stream, filemode ) ) - { - case INT_MIN: - /* fail completely */ - _PDCLIB_UNLOCK( stream->mtx ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - - case 0: - /* fail; try close / reopen */ - filename = stream->filename; - /* Setting to NULL to make the free() below a non-op. */ - stream->filename = NULL; - break; - - default: - /* success */ - _PDCLIB_UNLOCK( stream->mtx ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return stream; - } - } - - /* Close handle */ - _PDCLIB_close( stream->handle ); - - /* Remove stream from list */ - _PDCLIB_getstream( stream ); - - /* Delete tmpfile() */ - if ( stream->status & _PDCLIB_DELONCLOSE ) - { - /* Have to switch here; stream->filename may have moved to - filename after failed in-place mode change above. - */ - _PDCLIB_remove( ( stream->filename == NULL ) ? filename : stream->filename ); - stream->status &= ~_PDCLIB_DELONCLOSE; - } - - /* Free buffer */ - if ( stream->status & _PDCLIB_FREEBUFFER ) - { - free( stream->buffer ); - } - - if ( filename == NULL ) - { - /* Input was filename NULL, stream->filename NULL. - No filename means there is nothing to reopen. In-place - mode change was already attempted (and failed) above. - */ - return NULL; - } - else - { - /* We have a filename, either from input or (if filename - was NULL) from stream. We will attempt the re-open with - that, and will retrieve _PDCLIB_realpath() from that. - So stream->filename is no longer needed. - */ - free( stream->filename ); - } - } - else - { - /* Not a valid stream. As _PDCLIB_init_file_t() cannot tell the - difference, only knows that it has been called by freopen() - (by the non-NULL parameter), we need to initialize the mutex - here (so that either way, _PDCLIB_init_file_t() gets a pre- - initialized mutex). - */ -#ifndef __STDC_NO_THREADS__ - if ( mtx_init( &stream->mtx, mtx_plain | mtx_recursive ) != thrd_success ) - { - /* Could not initialize stream mutex */ - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - } - -#endif - - /* Locking the mutex, so we come out of the if-else with a locked - mutex either way. - */ - _PDCLIB_LOCK( stream->mtx ); - } - - /* Stream is closed, or never was open (even though its mutex exists - and is locked) at this point. - Now we check if we have the whereabouts to open it. - */ - - if ( filemode == 0 ) - { - /* Mode invalid */ - _PDCLIB_UNLOCK( stream->mtx ); -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &stream->mtx ); -#endif - free( stream->filename ); - free( stream ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - } - - if ( filename == NULL || filename[0] == '\0' ) - { - /* No filename available (standard stream?) */ - _PDCLIB_UNLOCK( stream->mtx ); -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &stream->mtx ); -#endif - free( stream->filename ); - free( stream ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - } - - /* (Re-)initializing the structure. */ - if ( _PDCLIB_init_file_t( stream ) == NULL ) - { - /* Re-init failed. */ - _PDCLIB_UNLOCK( stream->mtx ); -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &stream->mtx ); -#endif - free( stream->filename ); - free( stream ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - } - - /* Resetting buffer mode and filemode */ - stream->status |= filemode | _IOLBF; - - /* Attempt open */ - if ( ( stream->handle = _PDCLIB_open( filename, stream->status ) ) == _PDCLIB_NOHANDLE ) - { - /* OS open() failed */ - _PDCLIB_UNLOCK( stream->mtx ); -#ifndef __STDC_NO_THREADS__ - mtx_destroy( &stream->mtx ); -#endif - free( stream->filename ); - free( stream->buffer ); - free( stream ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return NULL; - } - - /* Getting absolute filename */ - stream->filename = _PDCLIB_realpath( filename ); - - /* Adding to list of open files */ - stream->next = _PDCLIB_filelist; - _PDCLIB_filelist = stream; - - _PDCLIB_UNLOCK( stream->mtx ); - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - - return stream; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - FILE * fin; - FILE * fout; - TESTCASE( ( fin = fopen( testfile1, "wb+" ) ) != NULL ); - TESTCASE( fputc( 'x', fin ) == 'x' ); - TESTCASE( fclose( fin ) == 0 ); - TESTCASE( ( fin = freopen( testfile1, "rb", stdin ) ) != NULL ); - TESTCASE( getchar() == 'x' ); - - TESTCASE( ( fout = freopen( testfile2, "wb+", stdout ) ) != NULL ); - TESTCASE( putchar( 'x' ) == 'x' ); - rewind( fout ); - TESTCASE( fgetc( fout ) == 'x' ); - - TESTCASE( fclose( fin ) == 0 ); - TESTCASE( fclose( fout ) == 0 ); - TESTCASE( remove( testfile1 ) == 0 ); - TESTCASE( remove( testfile2 ) == 0 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/freopen_s.c b/rocklibc/src/stdio/freopen_s.c deleted file mode 100644 index f5c7b07..0000000 --- a/rocklibc/src/stdio/freopen_s.c +++ /dev/null @@ -1,88 +0,0 @@ -/* freopen_s( FILE **, const char *, const char *, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include - -#ifndef REGTEST - -_PDCLIB_PUBLIC errno_t freopen_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict newstreamptr, const char * _PDCLIB_restrict filename, const char * _PDCLIB_restrict mode, FILE * _PDCLIB_restrict stream ) -{ - if ( newstreamptr == NULL || mode == NULL || stream == NULL ) - { - if ( newstreamptr != NULL ) - { - *newstreamptr = NULL; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - if ( ( *newstreamptr = freopen( filename, mode, stream ) ) == NULL ) - { - return *_PDCLIB_errno_func(); - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - FILE * fin; - FILE * fout; - FILE * dummy; - set_constraint_handler_s( test_handler ); - - TESTCASE( ( fin = fopen( testfile1, "wb+" ) ) != NULL ); - TESTCASE( fputc( 'x', fin ) == 'x' ); - TESTCASE( fclose( fin ) == 0 ); - TESTCASE( freopen_s( &fin, testfile1, "rb", stdin ) == 0 ); - TESTCASE( getchar() == 'x' ); - - TESTCASE( freopen_s( &fout, testfile2, "wb+", stdout ) == 0 ); - TESTCASE( putchar( 'x' ) == 'x' ); - rewind( fout ); - TESTCASE( fgetc( fout ) == 'x' ); - - dummy = fin; - TESTCASE( freopen_s( &dummy, testfile1, "rb", NULL ) != 0 ); - dummy = fin; - TESTCASE( freopen_s( &dummy, testfile1, NULL, stdin ) != 0 ); - TESTCASE( freopen_s( NULL, testfile1, "rb", fin ) != 0 ); - - TESTCASE( fclose( fin ) == 0 ); - TESTCASE( fclose( fout ) == 0 ); - TESTCASE( remove( testfile1 ) == 0 ); - TESTCASE( remove( testfile2 ) == 0 ); - - TESTCASE( HANDLER_CALLS == 3 ); -#else - TESTCASE( NO_TESTDRIVER ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fscanf.c b/rocklibc/src/stdio/fscanf.c deleted file mode 100644 index b828141..0000000 --- a/rocklibc/src/stdio/fscanf.c +++ /dev/null @@ -1,41 +0,0 @@ -/* fscanf( FILE *, const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int fscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vfscanf( stream, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/fscanf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -#define testscanf( stream, format, ... ) fscanf( stream, format, __VA_ARGS__ ) - -int main( void ) -{ - FILE * source; - TESTCASE( ( source = fopen( testfile, "wb+" ) ) != NULL ); -#include "scanf_testcases.h" - TESTCASE( fclose( source ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fseek.c b/rocklibc/src/stdio/fseek.c deleted file mode 100644 index 1da70c2..0000000 --- a/rocklibc/src/stdio/fseek.c +++ /dev/null @@ -1,103 +0,0 @@ -/* fseek( FILE *, long, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fseek( struct _PDCLIB_file_t * stream, long offset, int whence ) -{ - int rc; - _PDCLIB_LOCK( stream->mtx ); - - if ( stream->status & _PDCLIB_FWRITE ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - } - - stream->status &= ~ _PDCLIB_EOFFLAG; - - if ( stream->status & _PDCLIB_FRW ) - { - stream->status &= ~( _PDCLIB_FREAD | _PDCLIB_FWRITE ); - } - - if ( whence == SEEK_CUR ) - { - offset -= ( ( ( int )stream->bufend - ( int )stream->bufidx ) + stream->ungetidx ); - } - - rc = ( _PDCLIB_seek( stream, offset, whence ) != EOF ) ? 0 : EOF; - _PDCLIB_UNLOCK( stream->mtx ); - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - FILE * fh; - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( fwrite( teststring, 1, strlen( teststring ), fh ) == strlen( teststring ) ); - /* General functionality */ - TESTCASE( fseek( fh, -1, SEEK_END ) == 0 ); - TESTCASE( ( size_t )ftell( fh ) == strlen( teststring ) - 1 ); - TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); - TESTCASE( ( size_t )ftell( fh ) == strlen( teststring ) ); - TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 ); - TESTCASE( ftell( fh ) == 0 ); - TESTCASE( fseek( fh, 5, SEEK_CUR ) == 0 ); - TESTCASE( ftell( fh ) == 5 ); - TESTCASE( fseek( fh, -3, SEEK_CUR ) == 0 ); - TESTCASE( ftell( fh ) == 2 ); - /* Checking behaviour around EOF */ - TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); - TESTCASE( ! feof( fh ) ); - TESTCASE( fgetc( fh ) == EOF ); - TESTCASE( feof( fh ) ); - TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); - TESTCASE( ! feof( fh ) ); - /* Checking undo of ungetc() */ - TESTCASE( fseek( fh, 0, SEEK_SET ) == 0 ); - TESTCASE( fgetc( fh ) == teststring[0] ); - TESTCASE( fgetc( fh ) == teststring[1] ); - TESTCASE( fgetc( fh ) == teststring[2] ); - TESTCASE( ftell( fh ) == 3 ); - TESTCASE( ungetc( teststring[2], fh ) == teststring[2] ); - TESTCASE( ftell( fh ) == 2 ); - TESTCASE( fgetc( fh ) == teststring[2] ); - TESTCASE( ftell( fh ) == 3 ); - TESTCASE( ungetc( 'x', fh ) == 'x' ); - TESTCASE( ftell( fh ) == 2 ); - TESTCASE( fgetc( fh ) == 'x' ); - TESTCASE( ungetc( 'x', fh ) == 'x' ); - TESTCASE( ftell( fh ) == 2 ); - TESTCASE( fseek( fh, 2, SEEK_SET ) == 0 ); - TESTCASE( fgetc( fh ) == teststring[2] ); - /* Checking error handling */ - TESTCASE( fseek( fh, -5, SEEK_SET ) == -1 ); - TESTCASE( fseek( fh, 0, SEEK_END ) == 0 ); - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fsetpos.c b/rocklibc/src/stdio/fsetpos.c deleted file mode 100644 index 638493a..0000000 --- a/rocklibc/src/stdio/fsetpos.c +++ /dev/null @@ -1,56 +0,0 @@ -/* fsetpos( FILE *, const fpos_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int fsetpos( struct _PDCLIB_file_t * stream, const struct _PDCLIB_fpos_t * pos ) -{ - _PDCLIB_LOCK( stream->mtx ); - - if ( stream->status & _PDCLIB_FWRITE ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - } - - if ( _PDCLIB_seek( stream, pos->offset, SEEK_SET ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - stream->pos.status = pos->status; - /* TODO: Add mbstate. */ - - _PDCLIB_UNLOCK( stream->mtx ); - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* fsetpos() tested together with fsetpos(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/ftell.c b/rocklibc/src/stdio/ftell.c deleted file mode 100644 index 13cfa2d..0000000 --- a/rocklibc/src/stdio/ftell.c +++ /dev/null @@ -1,113 +0,0 @@ -/* ftell( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -long int ftell( struct _PDCLIB_file_t * stream ) -{ - /* ftell() must take into account: - - the actual *physical* offset of the file, i.e. the offset as recognized - by the operating system (and stored in stream->pos.offset); and - - any buffers held by PDCLib, which - - in case of unwritten buffers, count in *addition* to the offset; or - - in case of unprocessed pre-read buffers, count in *substraction* to - the offset. (Remember to count ungetidx into this number.) - Conveniently, the calculation ( ( bufend - bufidx ) + ungetidx ) results - in just the right number in both cases: - - in case of unwritten buffers, ( ( 0 - unwritten ) + 0 ) - i.e. unwritten bytes as negative number - - in case of unprocessed pre-read, ( ( preread - processed ) + unget ) - i.e. unprocessed bytes as positive number. - That is how the somewhat obscure return-value calculation works. - */ - /* If offset is too large for return type, report error instead of wrong - offset value. - */ - long int rc; - _PDCLIB_LOCK( stream->mtx ); - - if ( ( stream->pos.offset - stream->bufend ) > ( LONG_MAX - ( stream->bufidx - stream->ungetidx ) ) ) - { - /* integer overflow */ - _PDCLIB_UNLOCK( stream->mtx ); - *_PDCLIB_errno_func() = _PDCLIB_ERANGE; - return -1; - } - - rc = ( stream->pos.offset - ( ( ( int )stream->bufend - ( int )stream->bufidx ) + stream->ungetidx ) ); - _PDCLIB_UNLOCK( stream->mtx ); - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* Testing all the basic I/O functions individually would result in lots - of duplicated code, so I took the liberty of lumping it all together - here. - */ - /* The following functions delegate their tests to here: - fgetc fflush rewind fputc ungetc fseek - flushbuffer seek fillbuffer prepread prepwrite - */ - char buffer[4]; - FILE * fh; - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 ); - /* Testing ungetc() at offset 0 */ - rewind( fh ); - TESTCASE( ungetc( 'x', fh ) == 'x' ); - TESTCASE( ftell( fh ) == -1l ); - rewind( fh ); - TESTCASE( ftell( fh ) == 0l ); - /* Commence "normal" tests */ - TESTCASE( fputc( '1', fh ) == '1' ); - TESTCASE( fputc( '2', fh ) == '2' ); - TESTCASE( fputc( '3', fh ) == '3' ); - /* Positions incrementing as expected? */ - TESTCASE( ftell( fh ) == 3l ); - TESTCASE_NOREG( fh->pos.offset == 0l ); - TESTCASE_NOREG( fh->bufidx == 3l ); - /* Buffer properly flushed when full? */ - TESTCASE( fputc( '4', fh ) == '4' ); - TESTCASE_NOREG( fh->pos.offset == 4l ); - TESTCASE_NOREG( fh->bufidx == 0 ); - /* fflush() resetting positions as expected? */ - TESTCASE( fputc( '5', fh ) == '5' ); - TESTCASE( fflush( fh ) == 0 ); - TESTCASE( ftell( fh ) == 5l ); - TESTCASE_NOREG( fh->pos.offset == 5l ); - TESTCASE_NOREG( fh->bufidx == 0l ); - /* rewind() resetting positions as expected? */ - rewind( fh ); - TESTCASE( ftell( fh ) == 0l ); - TESTCASE_NOREG( fh->pos.offset == 0 ); - TESTCASE_NOREG( fh->bufidx == 0 ); - /* Reading back first character after rewind for basic read check */ - TESTCASE( fgetc( fh ) == '1' ); - /* Check that SEEK_CUR actually uses internal position */ - TESTCASE( fseek( fh, 1l, SEEK_CUR ) == 0 ); - TESTCASE( ftell( fh ) == 2l ); - /* TODO: t.b.c. */ - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/fwrite.c b/rocklibc/src/stdio/fwrite.c deleted file mode 100644 index 6149f73..0000000 --- a/rocklibc/src/stdio/fwrite.c +++ /dev/null @@ -1,117 +0,0 @@ -/* fwrite( const void *, size_t, size_t, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -size_t fwrite( const void * _PDCLIB_restrict ptr, size_t size, size_t nmemb, struct _PDCLIB_file_t * _PDCLIB_restrict stream ) -{ - _PDCLIB_size_t offset = 0; - /* TODO: lineend */ - /* int lineend = 0; */ - size_t nmemb_i; - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepwrite( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return 0; - } - - for ( nmemb_i = 0; nmemb_i < nmemb; ++nmemb_i ) - { - size_t size_i; - - for ( size_i = 0; size_i < size; ++size_i ) - { - if ( ( stream->buffer[ stream->bufidx++ ] = ( ( char * )ptr )[ nmemb_i * size + size_i ] ) == '\n' ) - { - /* Remember last newline, in case we have to do a partial line-buffered flush */ - offset = stream->bufidx; - /* lineend = true; */ - } - - if ( stream->bufidx == stream->bufsize ) - { - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - /* Returning number of objects completely buffered */ - _PDCLIB_UNLOCK( stream->mtx ); - return nmemb_i; - } - - offset = 0; - /* lineend = false; */ - } - } - } - - /* Fully-buffered streams are OK. Non-buffered streams must be flushed, - line-buffered streams only if there's a newline in the buffer. - */ - switch ( stream->status & ( _IONBF | _IOLBF ) ) - { - case _IONBF: - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - /* We are in a pinch here. We have an error, which requires a - return value < nmemb. On the other hand, all objects have - been written to buffer, which means all the caller had to - do was removing the error cause, and re-flush the stream... - Catch 22. We'll return a value one short, to indicate the - error, and can't really do anything about the inconsistency. - */ - _PDCLIB_UNLOCK( stream->mtx ); - return nmemb_i - 1; - } - - break; - - case _IOLBF: - if ( offset > 0 ) - { - size_t bufidx = stream->bufidx; - stream->bufidx = offset; - - if ( _PDCLIB_flushbuffer( stream ) == EOF ) - { - /* See comment above. */ - stream->bufidx = bufidx; - _PDCLIB_UNLOCK( stream->mtx ); - return nmemb_i - 1; - } - - stream->bufidx = bufidx - offset; - memmove( stream->buffer, stream->buffer + offset, stream->bufidx ); - } - } - - _PDCLIB_UNLOCK( stream->mtx ); - return nmemb_i; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by fread(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/getc.c b/rocklibc/src/stdio/getc.c deleted file mode 100644 index 3d082b3..0000000 --- a/rocklibc/src/stdio/getc.c +++ /dev/null @@ -1,28 +0,0 @@ -/* getc( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int getc( struct _PDCLIB_file_t * stream ) -{ - return fgetc( stream ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/getchar.c b/rocklibc/src/stdio/getchar.c deleted file mode 100644 index 34ee545..0000000 --- a/rocklibc/src/stdio/getchar.c +++ /dev/null @@ -1,28 +0,0 @@ -/* getchar( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int getchar( void ) -{ - return fgetc( stdin ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/perror.c b/rocklibc/src/stdio/perror.c deleted file mode 100644 index c84961a..0000000 --- a/rocklibc/src/stdio/perror.c +++ /dev/null @@ -1,67 +0,0 @@ -/* perror( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -/* TODO: Doing this via a static array is not the way to do it. */ -void perror( const char * s ) -{ - _PDCLIB_LOCK( stderr->mtx ); - - if ( ( s != NULL ) && ( s[0] != '\n' ) ) - { - fprintf( stderr, "%s: ", s ); - } - - if ( errno >= _PDCLIB_ERRNO_MAX || errno < 0 ) - { - fprintf( stderr, "%s\n", _PDCLIB_EUNKNOWN_TEXT ); - } - else - { - fprintf( stderr, "%s\n", _PDCLIB_lc_messages->errno_texts[errno] ); - } - - _PDCLIB_UNLOCK( stderr->mtx ); - return; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include -#include - -int main( void ) -{ - FILE * fh; - unsigned long long max = ULLONG_MAX; - char buffer[100]; - sprintf( buffer, "%llu", max ); - TESTCASE( ( fh = freopen( testfile, "wb+", stderr ) ) != NULL ); - TESTCASE( strtol( buffer, NULL, 10 ) == LONG_MAX ); - perror( "Test" ); - rewind( fh ); - TESTCASE( fread( buffer, 1, 7, fh ) == 7 ); - TESTCASE( memcmp( buffer, "Test: ", 6 ) == 0 ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/printf.c b/rocklibc/src/stdio/printf.c deleted file mode 100644 index 5db0a45..0000000 --- a/rocklibc/src/stdio/printf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* printf( const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int printf( const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vfprintf( stdout, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST - -#include -#include -#include - -#define _PDCLIB_FILEID "stdio/printf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -#define testprintf( stream, ... ) printf( __VA_ARGS__ ) - -int main( void ) -{ - FILE * target; - TESTCASE( ( target = freopen( testfile, "wb+", stdout ) ) != NULL ); -#include "printf_testcases.h" - TESTCASE( fclose( target ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/putc.c b/rocklibc/src/stdio/putc.c deleted file mode 100644 index c1eb2b0..0000000 --- a/rocklibc/src/stdio/putc.c +++ /dev/null @@ -1,28 +0,0 @@ -/* putc( int, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int putc( int c, struct _PDCLIB_file_t * stream ) -{ - return fputc( c, stream ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/putchar.c b/rocklibc/src/stdio/putchar.c deleted file mode 100644 index ea01de7..0000000 --- a/rocklibc/src/stdio/putchar.c +++ /dev/null @@ -1,29 +0,0 @@ -/* putchar( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int putchar( int c ) -{ - return fputc( c, stdout ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - putchar( 'x' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/puts.c b/rocklibc/src/stdio/puts.c deleted file mode 100644 index 51585af..0000000 --- a/rocklibc/src/stdio/puts.c +++ /dev/null @@ -1,80 +0,0 @@ -/* puts( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int puts( const char * s ) -{ - _PDCLIB_LOCK( stdout->mtx ); - - if ( _PDCLIB_prepwrite( stdout ) == EOF ) - { - _PDCLIB_UNLOCK( stdout->mtx ); - return EOF; - } - - while ( *s != '\0' ) - { - stdout->buffer[ stdout->bufidx++ ] = *s++; - - if ( stdout->bufidx == stdout->bufsize ) - { - if ( _PDCLIB_flushbuffer( stdout ) == EOF ) - { - _PDCLIB_UNLOCK( stdout->mtx ); - return EOF; - } - } - } - - stdout->buffer[ stdout->bufidx++ ] = '\n'; - - if ( ( stdout->bufidx == stdout->bufsize ) || - ( stdout->status & ( _IOLBF | _IONBF ) ) ) - { - int rc = _PDCLIB_flushbuffer( stdout ); - _PDCLIB_UNLOCK( stdout->mtx ); - return rc; - } - else - { - _PDCLIB_UNLOCK( stdout->mtx ); - return 0; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - FILE * fh; - const char * message = "SUCCESS testing puts()"; - char buffer[23]; - buffer[22] = 'x'; - TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL ); - TESTCASE( puts( message ) >= 0 ); - rewind( fh ); - TESTCASE( fread( buffer, 1, 22, fh ) == 22 ); - TESTCASE( memcmp( buffer, message, 22 ) == 0 ); - TESTCASE( buffer[22] == 'x' ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/remove.c b/rocklibc/src/stdio/remove.c deleted file mode 100644 index 25cbdbc..0000000 --- a/rocklibc/src/stdio/remove.c +++ /dev/null @@ -1,66 +0,0 @@ -/* remove( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of remove() fit for use with POSIX kernels. -*/ - -#include - -#ifndef REGTEST - -#include - -#include "pdclib/_PDCLIB_platform_errno.h" - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -#ifdef __cplusplus -extern "C" { -#endif - -extern int unlink( const char * pathname ); - -#ifdef __cplusplus -} -#endif - -int remove( const char * pathname ) -{ - int rc; - struct _PDCLIB_file_t * current = _PDCLIB_filelist; - - while ( current != NULL ) - { - if ( ( current->filename != NULL ) && ( strcmp( current->filename, pathname ) == 0 ) ) - { - return EOF; - } - - current = current->next; - } - - if ( ( rc = unlink( pathname ) ) == -1 ) - { - /* The 1:1 mapping in _PDCLIB_config.h ensures this works. */ - *_PDCLIB_errno_func() = errno; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c (and several others) */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/rename.c b/rocklibc/src/stdio/rename.c deleted file mode 100644 index 966170b..0000000 --- a/rocklibc/src/stdio/rename.c +++ /dev/null @@ -1,103 +0,0 @@ -/* rename( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -int rename( const char * oldpath, const char * newpath ) -{ - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - - { - struct _PDCLIB_file_t * current = _PDCLIB_filelist; - - while ( current != NULL ) - { - if ( ( current->filename != NULL ) && ( strcmp( current->filename, oldpath ) == 0 ) ) - { - /* File of that name currently open. Do not rename. */ - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return EOF; - } - - current = current->next; - } - } - - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return _PDCLIB_rename( oldpath, newpath ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include - -int main( void ) -{ - FILE * file; - remove( testfile1 ); - remove( testfile2 ); - /* make sure that neither file exists */ - TESTCASE( fopen( testfile1, "r" ) == NULL ); - TESTCASE( fopen( testfile2, "r" ) == NULL ); - /* rename file 1 to file 2 - expected to fail */ - TESTCASE( rename( testfile1, testfile2 ) == -1 ); - /* create file 1 */ - TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); - TESTCASE( fputs( "x", file ) != EOF ); - TESTCASE( fclose( file ) == 0 ); - /* check that file 1 exists */ - TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* rename file 1 to file 2 */ - TESTCASE( rename( testfile1, testfile2 ) == 0 ); - /* check that file 2 exists, file 1 does not */ - TESTCASE( fopen( testfile1, "r" ) == NULL ); - TESTCASE( ( file = fopen( testfile2, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* create another file 1 */ - TESTCASE( ( file = fopen( testfile1, "w" ) ) != NULL ); - TESTCASE( fputs( "x", file ) != EOF ); - TESTCASE( fclose( file ) == 0 ); - /* check that file 1 exists */ - TESTCASE( ( file = fopen( testfile1, "r" ) ) != NULL ); - TESTCASE( fclose( file ) == 0 ); - /* rename file 1 to file 2 - expected to fail, see comment in - _PDCLIB_rename() itself. - */ - /* Whether existing destination files are overwritten or not - is implementation-defined. - See functions/_PDCLIB/_PDCLIB_rename.c for your platform - for details. - */ - /*TESTCASE( rename( testfile1, testfile2 ) == [0|1] );*/ - /* remove both files */ - TESTCASE( remove( testfile1 ) == 0 ); - TESTCASE( remove( testfile2 ) == 0 ); - /* check that they're gone */ - TESTCASE( fopen( testfile1, "r" ) == NULL ); - TESTCASE( fopen( testfile2, "r" ) == NULL ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/rewind.c b/rocklibc/src/stdio/rewind.c deleted file mode 100644 index a449b7d..0000000 --- a/rocklibc/src/stdio/rewind.c +++ /dev/null @@ -1,29 +0,0 @@ -/* rewind( FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void rewind( struct _PDCLIB_file_t * stream ) -{ - stream->status &= ~ _PDCLIB_ERRORFLAG; - fseek( stream, 0L, SEEK_SET ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Testing covered by ftell.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/scanf.c b/rocklibc/src/stdio/scanf.c deleted file mode 100644 index c2c8313..0000000 --- a/rocklibc/src/stdio/scanf.c +++ /dev/null @@ -1,42 +0,0 @@ -/* scanf( const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int scanf( const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vfscanf( stdin, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/scanf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -#define testscanf( stream, format, ... ) scanf( format, __VA_ARGS__ ) - -int main( void ) -{ - FILE * source; - TESTCASE( ( source = freopen( testfile, "wb+", stdin ) ) != NULL ); -#include "scanf_testcases.h" - TESTCASE( fclose( source ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/setbuf.c b/rocklibc/src/stdio/setbuf.c deleted file mode 100644 index 6c32072..0000000 --- a/rocklibc/src/stdio/setbuf.c +++ /dev/null @@ -1,55 +0,0 @@ -/* setbuf( FILE *, char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void setbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf ) -{ - if ( buf == NULL ) - { - setvbuf( stream, buf, _IONBF, BUFSIZ ); - } - else - { - setvbuf( stream, buf, _IOFBF, BUFSIZ ); - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* TODO: Extend testing once setvbuf() is finished. */ -#ifndef REGTEST - char buffer[ BUFSIZ + 1 ]; - FILE * fh; - /* full buffered */ - TESTCASE( ( fh = tmpfile() ) != NULL ); - setbuf( fh, buffer ); - TESTCASE( fh->buffer == buffer ); - TESTCASE( fh->bufsize == BUFSIZ ); - TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF ); - TESTCASE( fclose( fh ) == 0 ); - /* not buffered */ - TESTCASE( ( fh = tmpfile() ) != NULL ); - setbuf( fh, NULL ); - TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF ); - TESTCASE( fclose( fh ) == 0 ); -#else - puts( " NOTEST setbuf() test driver is PDCLib-specific." ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/setvbuf.c b/rocklibc/src/stdio/setvbuf.c deleted file mode 100644 index 3de51b1..0000000 --- a/rocklibc/src/stdio/setvbuf.c +++ /dev/null @@ -1,141 +0,0 @@ -/* setvbuf( FILE *, char *, int, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int setvbuf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, char * _PDCLIB_restrict buf, int mode, size_t size ) -{ - switch ( mode ) - { - case _IONBF: - /* When unbuffered I/O is requested, we keep the buffer anyway, as - we don't want to e.g. flush the stream for every character of a - stream being printed. - */ - _PDCLIB_LOCK( stream->mtx ); - break; - - case _IOFBF: - case _IOLBF: - if ( size > INT_MAX || size == 0 ) - { - /* PDCLib only supports buffers up to INT_MAX in size. A size - of zero doesn't make sense. - */ - return -1; - } - - if ( buf != NULL ) - { - /* User provided buffer. Deallocate existing buffer, and mark - the stream so that fclose() does not try to deallocate the - user's buffer. - */ - if ( stream->status & _PDCLIB_FREEBUFFER ) - { - free( stream->buffer ); - } - - stream->status &= ~_PDCLIB_FREEBUFFER; - } - else - { - /* User requested buffer size, but leaves it to library to - allocate the buffer. - */ - /* If current buffer is big enough for requested size, but not - over twice as big (and wasting memory space), we use the - current buffer (i.e., do nothing), to save the malloc() / - free() overhead. - */ - _PDCLIB_LOCK( stream->mtx ); - - if ( ( stream->bufsize < size ) || ( stream->bufsize > ( size << 1 ) ) ) - { - /* Buffer too small, or much too large - allocate. */ - if ( ( buf = ( char * ) malloc( size ) ) == NULL ) - { - /* Out of memory error. */ - _PDCLIB_UNLOCK( stream->mtx ); - return -1; - } - - if ( stream->status & _PDCLIB_FREEBUFFER ) - { - free( stream->buffer ); - } - - /* This buffer must be free()d on fclose() */ - stream->status |= _PDCLIB_FREEBUFFER; - } - } - - stream->buffer = buf; - stream->bufsize = size; - break; - - default: - /* If mode is something else than _IOFBF, _IOLBF or _IONBF -> exit */ - return -1; - } - - /* Deleting current buffer mode */ - stream->status &= ~( _IOFBF | _IOLBF | _IONBF ); - /* Set user-defined mode */ - stream->status |= mode; - _PDCLIB_UNLOCK( stream->mtx ); - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -#define BUFFERSIZE 500 - -int main( void ) -{ -#ifndef REGTEST - char buffer[ BUFFERSIZE ]; - FILE * fh; - /* full buffered, user-supplied buffer */ - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( setvbuf( fh, buffer, _IOFBF, BUFFERSIZE ) == 0 ); - TESTCASE( fh->buffer == buffer ); - TESTCASE( fh->bufsize == BUFFERSIZE ); - TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOFBF ); - TESTCASE( fclose( fh ) == 0 ); - /* line buffered, lib-supplied buffer */ - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( setvbuf( fh, NULL, _IOLBF, BUFFERSIZE ) == 0 ); - TESTCASE( fh->buffer != NULL ); - TESTCASE( fh->bufsize == BUFFERSIZE ); - TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IOLBF ); - TESTCASE( fclose( fh ) == 0 ); - /* not buffered, user-supplied buffer */ - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( setvbuf( fh, buffer, _IONBF, BUFFERSIZE ) == 0 ); - TESTCASE( ( fh->status & ( _IOFBF | _IONBF | _IOLBF ) ) == _IONBF ); - TESTCASE( fclose( fh ) == 0 ); -#else - puts( " NOTEST setvbuf() test driver is PDCLib-specific." ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/snprintf.c b/rocklibc/src/stdio/snprintf.c deleted file mode 100644 index b92f245..0000000 --- a/rocklibc/src/stdio/snprintf.c +++ /dev/null @@ -1,46 +0,0 @@ -/* snprintf( char *, size_t, const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int snprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vsnprintf( s, n, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST - -#include -#include -#include - -#define _PDCLIB_FILEID "stdio/snprintf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -#define testprintf( s, ... ) snprintf( s, 100, __VA_ARGS__ ) - -int main( void ) -{ - char target[100]; -#include "printf_testcases.h" - TESTCASE( snprintf( NULL, 0, "foo" ) == 3 ); - TESTCASE( snprintf( NULL, 0, "%d", 100 ) == 3 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/sprintf.c b/rocklibc/src/stdio/sprintf.c deleted file mode 100644 index 6ad6cce..0000000 --- a/rocklibc/src/stdio/sprintf.c +++ /dev/null @@ -1,44 +0,0 @@ -/* sprintf( char *, const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -int sprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vsnprintf( s, SIZE_MAX, format, ap ); /* TODO: replace with non-checking call */ - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST - -#include -#include - -#define _PDCLIB_FILEID "stdio/sprintf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -#define testprintf( s, ... ) sprintf( s, __VA_ARGS__ ) - -int main( void ) -{ - char target[100]; -#include "printf_testcases.h" - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/sscanf.c b/rocklibc/src/stdio/sscanf.c deleted file mode 100644 index 9ba830d..0000000 --- a/rocklibc/src/stdio/sscanf.c +++ /dev/null @@ -1,39 +0,0 @@ -/* sscanf( const char *, const char *, ... ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int sscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, ... ) -{ - int rc; - va_list ap; - va_start( ap, format ); - rc = vsscanf( s, format, ap ); - va_end( ap ); - return rc; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/sscanf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -#define testscanf( s, format, ... ) sscanf( s, format, __VA_ARGS__ ) - -int main( void ) -{ - char source[100]; -#include "scanf_testcases.h" - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/tmpfile.c b/rocklibc/src/stdio/tmpfile.c deleted file mode 100644 index 3b41f3e..0000000 --- a/rocklibc/src/stdio/tmpfile.c +++ /dev/null @@ -1,133 +0,0 @@ -/* tmpfile( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_filelist_mtx; -#endif - -#include "pdclib/_PDCLIB_glue.h" -#include "pdclib/_PDCLIB_defguard.h" - -#include -#include - -#include "sys/types.h" -#include "sys/stat.h" -#include "fcntl.h" -#include "unistd.h" - -extern struct _PDCLIB_file_t * _PDCLIB_filelist; - -/* This is an example implementation of tmpfile() fit for use with POSIX - kernels. -*/ -struct _PDCLIB_file_t * tmpfile( void ) -{ - FILE * rc; - char const * tmpdir = getenv("TMPDIR"); - - /* This is the chosen way to get high-quality randomness. Replace as - appropriate. - */ - int randomsource = open( "/dev/urandom", O_RDONLY ); - /* Working under the assumption that the tempfile location is canonical - (absolute), and does not require going through _PDCLIB_realpath(). - */ - char * filename = ( char * )malloc( L_tmpnam ); - _PDCLIB_fd_t fd; - - if ( randomsource == -1 ) - { - return NULL; - } - - for ( ;; ) - { - /* Get a filename candidate. What constitutes a valid filename and - where temporary files are usually located is platform-dependent, - which is one reason why this function is located in the platform - overlay. The other reason is that a *good* implementation should - use high-quality randomness instead of a pseudo-random sequence to - generate the filename candidate, which is *also* platform-dependent. - */ - unsigned int random; - read( randomsource, (void *)&random, sizeof( unsigned int ) ); - sprintf( filename, "%s/%u.tmp", (tmpdir == NULL) ? "/tmp" : tmpdir, random ); - /* Check if file of this name exists. Note that fopen() is a very weak - check, which does not take e.g. access permissions into account - (file might exist but not readable). Replace with something more - appropriate. - */ - fd = open( filename, O_CREAT | O_EXCL | O_RDWR, S_IRUSR | S_IWUSR ); - - if ( fd != -1 ) - { - /* Found a file that does not exist yet */ - break; - } - - close( fd ); - } - - close( randomsource ); - - /* See fopen(), which does much of the same. */ - - if ( ( rc = _PDCLIB_init_file_t( NULL ) ) == NULL ) - { - /* initializing FILE structure failed */ - close( fd ); - return NULL; - } - - rc->status |= _PDCLIB_filemode( "wb+" ) | _IOLBF | _PDCLIB_DELONCLOSE; - rc->handle = fd; - - /* Filename (for potential freopen()) */ - rc->filename = filename; - - /* Adding to list of open files */ - _PDCLIB_LOCK( _PDCLIB_filelist_mtx ); - rc->next = _PDCLIB_filelist; - _PDCLIB_filelist = rc; - _PDCLIB_UNLOCK( _PDCLIB_filelist_mtx ); - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - FILE * fh; -#ifndef REGTEST - char filename[ L_tmpnam ]; - FILE * fhtest; -#endif - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( fputc( 'x', fh ) == 'x' ); - /* Checking that file is actually there */ - TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename ); - TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL ); - TESTCASE_NOREG( fclose( fhtest ) == 0 ); - /* Closing tmpfile */ - TESTCASE( fclose( fh ) == 0 ); - /* Checking that file was deleted */ - TESTCASE_NOREG( fopen( filename, "r" ) == NULL ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/tmpfile_s.c b/rocklibc/src/stdio/tmpfile_s.c deleted file mode 100644 index 98f53c9..0000000 --- a/rocklibc/src/stdio/tmpfile_s.c +++ /dev/null @@ -1,79 +0,0 @@ -/* tmpfile_s( FILE * * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t tmpfile_s( FILE * _PDCLIB_restrict * _PDCLIB_restrict streamptr ) -{ - if ( streamptr == NULL ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - *streamptr = tmpfile(); - - if ( *streamptr == NULL ) - { - assert( *_PDCLIB_errno_func() != 0 ); - return *_PDCLIB_errno_func(); - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - FILE * fh; - char filename[ L_tmpnam ]; - FILE * fhtest; - set_constraint_handler_s( test_handler ); - - TESTCASE( ( tmpfile_s( &fh ) ) == 0 ); - TESTCASE( fputc( 'x', fh ) == 'x' ); - /* Checking that file is actually there */ - TESTCASE_NOREG( strcpy( filename, fh->filename ) == filename ); - TESTCASE_NOREG( ( fhtest = fopen( filename, "r" ) ) != NULL ); - TESTCASE_NOREG( fclose( fhtest ) == 0 ); - /* Closing tmpfile */ - TESTCASE( fclose( fh ) == 0 ); - /* Checking that file was deleted */ - TESTCASE_NOREG( fopen( filename, "r" ) == NULL ); - - /* Constraint violation */ - TESTCASE( ( tmpfile_s( NULL ) ) != 0 ); - - TESTCASE( HANDLER_CALLS == 1 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/tmpnam.c b/rocklibc/src/stdio/tmpnam.c deleted file mode 100644 index 14e0378..0000000 --- a/rocklibc/src/stdio/tmpnam.c +++ /dev/null @@ -1,47 +0,0 @@ -/* tmpnam( char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#include - -char * tmpnam( char * s ) -{ - static char filename[ L_tmpnam ]; - FILE * file = tmpfile(); - - if ( s == NULL ) - { - s = filename; - } - - strcpy( s, file->filename ); - fclose( file ); - return s; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" - TESTCASE( strlen( tmpnam( NULL ) ) < L_tmpnam ); -#pragma GCC diagnostic pop - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/ungetc.c b/rocklibc/src/stdio/ungetc.c deleted file mode 100644 index 51a4cb8..0000000 --- a/rocklibc/src/stdio/ungetc.c +++ /dev/null @@ -1,93 +0,0 @@ -/* ungetc( int, FILE * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int ungetc( int c, struct _PDCLIB_file_t * stream ) -{ - int rc; - - _PDCLIB_LOCK( stream->mtx ); - - if ( c == EOF || stream->ungetidx == _PDCLIB_UNGETCBUFSIZE ) - { - rc = -1; - } - else - { - rc = stream->ungetbuf[stream->ungetidx++] = ( unsigned char ) c; - } - - _PDCLIB_UNLOCK( stream->mtx ); - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char buffer[4]; - char input[4]; - FILE * fh; - int read; - fpos_t pos; - TESTCASE( ( fh = tmpfile() ) != NULL ); - TESTCASE( setvbuf( fh, buffer, _IOLBF, 4 ) == 0 ); - rewind( fh ); - TESTCASE( fprintf( fh, "123" ) == 3 ); - TESTCASE( ftell( fh ) == 3 ); - rewind( fh ); - TESTCASE( fscanf( fh, "12%n", &read ) == 0 ); - TESTCASE( read == 2 ); - TESTCASE( ftell( fh ) == 2 ); - TESTCASE( ungetc( 'x', fh ) == 'x' ); - TESTCASE( ftell( fh ) == 1 ); - read = 0; - TESTCASE( fscanf( fh, "x3%n", &read ) == 0 ); - TESTCASE( ftell( fh ) == 3 ); - TESTCASE( read == 2 ); - TESTCASE( ungetc( 'y', fh ) == 'y' ); - TESTCASE( ftell( fh ) == 2 ); - TESTCASE( fread( input, 1, 1, fh ) == 1 ); - TESTCASE( ftell( fh ) == 3 ); - TESTCASE( input[0] == 'y' ); - rewind( fh ); - TESTCASE( ungetc( 'z', fh ) == 'z' ); - TESTCASE( ftell( fh ) == -1 ); - TESTCASE( fread( input, 1, 4, fh ) == 4 ); - TESTCASE( memcmp( input, "z123", 4 ) == 0 ); - rewind( fh ); - TESTCASE( ungetc( 'z', fh ) == 'z' ); - TESTCASE( ftell( fh ) == -1 ); - TESTCASE( fscanf( fh, "%4c", input ) == 1 ); - TESTCASE( memcmp( input, "z123", 4 ) == 0 ); - rewind( fh ); - TESTCASE( fgetc( fh ) == '1' ); - TESTCASE( ftell( fh ) == 1 ); - TESTCASE( ungetc( 'z', fh ) == 'z' ); - TESTCASE( ftell( fh ) == 0 ); - TESTCASE( fgetpos( fh, &pos ) == 0 ); - TESTCASE( fsetpos( fh, &pos ) == 0 ); - TESTCASE( ftell( fh ) == 0 ); - TESTCASE( fgetc( fh ) == '1' ); - TESTCASE( fclose( fh ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vfprintf.c b/rocklibc/src/stdio/vfprintf.c deleted file mode 100644 index 9cc0949..0000000 --- a/rocklibc/src/stdio/vfprintf.c +++ /dev/null @@ -1,110 +0,0 @@ -/* vfprintf( FILE *, const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int vfprintf( struct _PDCLIB_file_t * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) -{ - /* TODO: This function should interpret format as multibyte characters. */ - struct _PDCLIB_status_t status; - status.base = 0; - status.flags = 0; - status.n = SIZE_MAX; - status.i = 0; - status.current = 0; - status.s = NULL; - status.width = 0; - status.prec = EOF; - status.stream = stream; - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepwrite( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - va_copy( status.arg, arg ); - - while ( *format != '\0' ) - { - const char * rc; - - if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) ) - { - /* No conversion specifier, print verbatim */ - stream->buffer[ stream->bufidx++ ] = *format; - - if ( ( stream->bufidx == stream->bufsize ) - || ( ( stream->status & _IOLBF ) && ( *format == '\n' ) ) - || ( stream->status & _IONBF ) - ) - { - if ( _PDCLIB_flushbuffer( stream ) != 0 ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - } - - ++format; - status.i++; - } - else - { - /* Continue parsing after conversion specifier */ - format = rc; - } - } - - va_end( status.arg ); - _PDCLIB_UNLOCK( stream->mtx ); - return status.i; -} - -#endif - -#ifdef TEST - -#include -#include - -#define _PDCLIB_FILEID "stdio/vfprintf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -static int testprintf( FILE * stream, const char * format, ... ) -{ - int i; - va_list arg; - va_start( arg, format ); - i = vfprintf( stream, format, arg ); - va_end( arg ); - return i; -} - -int main( void ) -{ - FILE * target; - TESTCASE( ( target = tmpfile() ) != NULL ); -#include "printf_testcases.h" - TESTCASE( fclose( target ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vfscanf.c b/rocklibc/src/stdio/vfscanf.c deleted file mode 100644 index 667b8af..0000000 --- a/rocklibc/src/stdio/vfscanf.c +++ /dev/null @@ -1,138 +0,0 @@ -/* vfscanf( FILE *, const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -#ifndef __STDC_NO_THREADS__ -#include -#endif - -int vfscanf( FILE * _PDCLIB_restrict stream, const char * _PDCLIB_restrict format, va_list arg ) -{ - /* TODO: This function should interpret format as multibyte characters. */ - struct _PDCLIB_status_t status; - status.base = 0; - status.flags = 0; - status.n = 0; - status.i = 0; - status.current = 0; - status.s = NULL; - status.width = 0; - status.prec = EOF; - status.stream = stream; - - _PDCLIB_LOCK( stream->mtx ); - - if ( _PDCLIB_prepread( stream ) == EOF || _PDCLIB_CHECKBUFFER( stream ) == EOF ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - va_copy( status.arg, arg ); - - while ( *format != '\0' ) - { - const char * rc; - - if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) ) - { - int c; - - /* No conversion specifier, match verbatim */ - if ( isspace( (unsigned char)*format ) ) - { - /* Whitespace char in format string: Skip all whitespaces */ - /* No whitespaces in input does not result in matching error */ - while ( isspace( (unsigned char)( c = getc( stream ) ) ) ) - { - ++status.i; - } - - if ( ! feof( stream ) ) - { - ungetc( c, stream ); - } - } - else - { - /* Non-whitespace char in format string: Match verbatim */ - if ( ( ( c = getc( stream ) ) != *format ) || feof( stream ) ) - { - /* Matching error */ - if ( ! feof( stream ) && ! ferror( stream ) ) - { - ungetc( c, stream ); - } - else if ( status.n == 0 ) - { - _PDCLIB_UNLOCK( stream->mtx ); - return EOF; - } - - _PDCLIB_UNLOCK( stream->mtx ); - return status.n; - } - else - { - ++status.i; - } - } - - ++format; - } - else - { - /* NULL return code indicates matching error */ - if ( rc == NULL ) - { - break; - } - - /* Continue parsing after conversion specifier */ - format = rc; - } - } - - va_end( status.arg ); - _PDCLIB_UNLOCK( stream->mtx ); - return status.n; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/vfscanf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -static int testscanf( FILE * stream, const char * format, ... ) -{ - va_list ap; - int result; - va_start( ap, format ); - result = vfscanf( stream, format, ap ); - va_end( ap ); - return result; -} - -int main( void ) -{ - FILE * source; - TESTCASE( ( source = fopen( testfile, "wb+" ) ) != NULL ); -#include "scanf_testcases.h" - TESTCASE( fclose( source ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vprintf.c b/rocklibc/src/stdio/vprintf.c deleted file mode 100644 index 342f227..0000000 --- a/rocklibc/src/stdio/vprintf.c +++ /dev/null @@ -1,50 +0,0 @@ -/* vprintf( const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int vprintf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) -{ - return vfprintf( stdout, format, arg ); -} - -#endif - -#ifdef TEST - -#include -#include -#include - -#define _PDCLIB_FILEID "stdio/vprintf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -static int testprintf( FILE * stream, const char * format, ... ) -{ - int i; - va_list arg; - va_start( arg, format ); - i = vprintf( format, arg ); - va_end( arg ); - return i; -} - -int main( void ) -{ - FILE * target; - TESTCASE( ( target = freopen( testfile, "wb+", stdout ) ) != NULL ); -#include "printf_testcases.h" - TESTCASE( fclose( target ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vscanf.c b/rocklibc/src/stdio/vscanf.c deleted file mode 100644 index d5ae5b3..0000000 --- a/rocklibc/src/stdio/vscanf.c +++ /dev/null @@ -1,45 +0,0 @@ -/* vscanf( const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int vscanf( const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) -{ - return vfscanf( stdin, format, arg ); -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/vscanf.c" -#define _PDCLIB_FILEIO - -#include "_PDCLIB_test.h" - -static int testscanf( FILE * stream, const char * format, ... ) -{ - int i; - va_list arg; - va_start( arg, format ); - i = vscanf( format, arg ); - va_end( arg ); - return i; -} - -int main( void ) -{ - FILE * source; - TESTCASE( ( source = freopen( testfile, "wb+", stdin ) ) != NULL ); -#include "scanf_testcases.h" - TESTCASE( fclose( source ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vsnprintf.c b/rocklibc/src/stdio/vsnprintf.c deleted file mode 100644 index 0d3aa65..0000000 --- a/rocklibc/src/stdio/vsnprintf.c +++ /dev/null @@ -1,88 +0,0 @@ -/* vsnprintf( char *, size_t, const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -int vsnprintf( char * _PDCLIB_restrict s, size_t n, const char * _PDCLIB_restrict format, _PDCLIB_va_list arg ) -{ - /* TODO: This function should interpret format as multibyte characters. */ - struct _PDCLIB_status_t status; - status.base = 0; - status.flags = 0; - status.n = n; - status.i = 0; - status.current = 0; - status.s = s; - status.width = 0; - status.prec = EOF; - status.stream = NULL; - va_copy( status.arg, arg ); - - while ( *format != '\0' ) - { - const char * rc; - - if ( ( *format != '%' ) || ( ( rc = _PDCLIB_print( format, &status ) ) == format ) ) - { - /* No conversion specifier, print verbatim */ - if ( status.i < n ) - { - s[ status.i ] = *format; - } - - status.i++; - format++; - } - else - { - /* Continue parsing after conversion specifier */ - format = rc; - } - } - - if ( status.i < n ) - { - s[ status.i ] = '\0'; - } - - va_end( status.arg ); - return status.i; -} - -#endif - -#ifdef TEST - -#include -#include -#include - -#define _PDCLIB_FILEID "stdio/vsnprintf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -static int testprintf( char * s, const char * format, ... ) -{ - int i; - va_list arg; - va_start( arg, format ); - i = vsnprintf( s, 100, format, arg ); - va_end( arg ); - return i; -} - -int main( void ) -{ - char target[100]; -#include "printf_testcases.h" - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vsprintf.c b/rocklibc/src/stdio/vsprintf.c deleted file mode 100644 index 3c539d9..0000000 --- a/rocklibc/src/stdio/vsprintf.c +++ /dev/null @@ -1,47 +0,0 @@ -/* vsprintf( char *, const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -int vsprintf( char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg ) -{ - return vsnprintf( s, SIZE_MAX, format, arg ); /* TODO: Replace with a non-checking call */ -} - -#endif - -#ifdef TEST - -#include -#include - -#define _PDCLIB_FILEID "stdio/vsprintf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -static int testprintf( char * s, const char * format, ... ) -{ - int i; - va_list arg; - va_start( arg, format ); - i = vsprintf( s, format, arg ); - va_end( arg ); - return i; -} - -int main( void ) -{ - char target[100]; -#include "printf_testcases.h" - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdio/vsscanf.c b/rocklibc/src/stdio/vsscanf.c deleted file mode 100644 index aec34ce..0000000 --- a/rocklibc/src/stdio/vsscanf.c +++ /dev/null @@ -1,115 +0,0 @@ -/* vsscanf( const char *, const char *, va_list ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include - -#ifndef REGTEST - -int vsscanf( const char * _PDCLIB_restrict s, const char * _PDCLIB_restrict format, va_list arg ) -{ - /* TODO: This function should interpret format as multibyte characters. */ - struct _PDCLIB_status_t status; - status.base = 0; - status.flags = 0; - status.n = 0; - status.i = 0; - status.current = 0; - status.s = ( char * ) s; - status.width = 0; - status.prec = EOF; - status.stream = NULL; - va_copy( status.arg, arg ); - - while ( *format != '\0' ) - { - const char * rc; - - if ( ( *format != '%' ) || ( ( rc = _PDCLIB_scan( format, &status ) ) == format ) ) - { - /* No conversion specifier, match verbatim */ - if ( isspace( (unsigned char)*format ) ) - { - /* Whitespace char in format string: Skip all whitespaces */ - /* No whitespaces in input do not result in matching error */ - while ( isspace( (unsigned char)*status.s ) ) - { - ++status.s; - ++status.i; - } - } - else - { - /* Non-whitespace char in format string: Match verbatim */ - if ( *status.s != *format ) - { - if ( *status.s == '\0' && status.n == 0 ) - { - /* Early input error */ - return EOF; - } - - /* Matching error */ - return status.n; - } - else - { - ++status.s; - ++status.i; - } - } - - ++format; - } - else - { - /* NULL return code indicates error */ - if ( rc == NULL ) - { - if ( ( *status.s == '\n' ) && ( status.n == 0 ) ) - { - status.n = EOF; - } - - break; - } - - /* Continue parsing after conversion specifier */ - format = rc; - } - } - - va_end( status.arg ); - return status.n; -} - -#endif - -#ifdef TEST -#define _PDCLIB_FILEID "stdio/vsscanf.c" -#define _PDCLIB_STRINGIO - -#include "_PDCLIB_test.h" - -static int testscanf( const char * stream, const char * format, ... ) -{ - va_list ap; - int result; - va_start( ap, format ); - result = vsscanf( stream, format, ap ); - va_end( ap ); - return result; -} - -int main( void ) -{ - char source[100]; -#include "scanf_testcases.h" - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/_Exit.c b/rocklibc/src/stdlib/_Exit.c deleted file mode 100644 index e5548ed..0000000 --- a/rocklibc/src/stdlib/_Exit.c +++ /dev/null @@ -1,34 +0,0 @@ -/* _Exit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_glue.h" - -void _Exit( int status ) -{ - _PDCLIB_closeall(); - _PDCLIB_Exit( status ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - int UNEXPECTED_RETURN = 0; - _Exit( 0 ); - TESTCASE( UNEXPECTED_RETURN ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/abort.c b/rocklibc/src/stdlib/abort.c deleted file mode 100644 index 69422f9..0000000 --- a/rocklibc/src/stdlib/abort.c +++ /dev/null @@ -1,40 +0,0 @@ -/* abort( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -void abort( void ) -{ - raise( SIGABRT ); - exit( EXIT_FAILURE ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -static void aborthandler( int sig ) -{ - exit( 0 ); -} - -int main( void ) -{ - int UNEXPECTED_RETURN_FROM_ABORT = 0; - TESTCASE( signal( SIGABRT, &aborthandler ) != SIG_ERR ); - abort(); - TESTCASE( UNEXPECTED_RETURN_FROM_ABORT ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/abort_handler_s.c b/rocklibc/src/stdlib/abort_handler_s.c deleted file mode 100644 index 995eba3..0000000 --- a/rocklibc/src/stdlib/abort_handler_s.c +++ /dev/null @@ -1,32 +0,0 @@ -/* abort_handler_s( const char *, void *, errno_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include - -#ifndef REGTEST - -#include - -void abort_handler_s( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t errno ) -{ - fprintf( stderr, "abort handler called:\n%s\n", msg ); - abort(); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/abs.c b/rocklibc/src/stdlib/abs.c deleted file mode 100644 index 7a634e3..0000000 --- a/rocklibc/src/stdlib/abs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* abs( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int abs( int j ) -{ - return ( j >= 0 ) ? j : -j; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - TESTCASE( abs( 0 ) == 0 ); - TESTCASE( abs( INT_MAX ) == INT_MAX ); - TESTCASE( abs( INT_MIN + 1 ) == -( INT_MIN + 1 ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/at_quick_exit.c b/rocklibc/src/stdlib/at_quick_exit.c deleted file mode 100644 index d576b0f..0000000 --- a/rocklibc/src/stdlib/at_quick_exit.c +++ /dev/null @@ -1,73 +0,0 @@ -/* at_quick_exit( void (*)( void ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -extern void ( *_PDCLIB_quickexitstack[] )( void ); -extern size_t _PDCLIB_quickexitptr; - -int at_quick_exit( void ( *func )( void ) ) -{ - if ( _PDCLIB_quickexitptr == _PDCLIB_ATEXIT_SLOTS ) - { - return -1; - } - else - { - _PDCLIB_quickexitstack[ _PDCLIB_quickexitptr++ ] = func; - return 0; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -#if ! defined( REGTEST ) || __STDC_VERSION__ >= 201112L - -static int flags[ 32 ]; - -static void counthandler( void ) -{ - static int count = 0; - flags[ count ] = count; - ++count; -} - -static void checkhandler( void ) -{ - int i; - - for ( i = 0; i < 32; ++i ) - { - assert( flags[ i ] == i ); - } -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || __STDC_VERSION__ >= 201112L - int i; - TESTCASE( at_quick_exit( &checkhandler ) == 0 ); - - for ( i = 0; i < 32; ++i ) - { - TESTCASE( at_quick_exit( &counthandler ) == 0 ); - } - -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/atexit.c b/rocklibc/src/stdlib/atexit.c deleted file mode 100644 index 779da1e..0000000 --- a/rocklibc/src/stdlib/atexit.c +++ /dev/null @@ -1,67 +0,0 @@ -/* atexit( void (*)( void ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -extern void ( *_PDCLIB_exitstack[] )( void ); -extern size_t _PDCLIB_exitptr; - -int atexit( void ( *func )( void ) ) -{ - if ( _PDCLIB_exitptr == _PDCLIB_ATEXIT_SLOTS ) - { - return -1; - } - else - { - _PDCLIB_exitstack[ _PDCLIB_exitptr++ ] = func; - return 0; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -static int flags[ 32 ]; - -static void counthandler( void ) -{ - static int count = 0; - flags[ count ] = count; - ++count; -} - -static void checkhandler( void ) -{ - int i; - - for ( i = 0; i < 32; ++i ) - { - assert( flags[ i ] == i ); - } -} - -int main( void ) -{ - int i; - TESTCASE( atexit( &checkhandler ) == 0 ); - - for ( i = 0; i < 32; ++i ) - { - TESTCASE( atexit( &counthandler ) == 0 ); - } - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/atoi.c b/rocklibc/src/stdlib/atoi.c deleted file mode 100644 index 5d0c2fb..0000000 --- a/rocklibc/src/stdlib/atoi.c +++ /dev/null @@ -1,28 +0,0 @@ -/* atoi( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int atoi( const char * s ) -{ - return ( int ) _PDCLIB_atomax( s ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* no tests for a simple wrapper */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/atol.c b/rocklibc/src/stdlib/atol.c deleted file mode 100644 index 750d64d..0000000 --- a/rocklibc/src/stdlib/atol.c +++ /dev/null @@ -1,28 +0,0 @@ -/* atol( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -long int atol( const char * s ) -{ - return ( long int ) _PDCLIB_atomax( s ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* no tests for a simple wrapper */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/atoll.c b/rocklibc/src/stdlib/atoll.c deleted file mode 100644 index 212b4f3..0000000 --- a/rocklibc/src/stdlib/atoll.c +++ /dev/null @@ -1,28 +0,0 @@ -/* atoll( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -long long int atoll( const char * s ) -{ - return ( long long int ) _PDCLIB_atomax( s ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* no tests for a simple wrapper */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/bsearch.c b/rocklibc/src/stdlib/bsearch.c deleted file mode 100644 index 6f578d4..0000000 --- a/rocklibc/src/stdlib/bsearch.c +++ /dev/null @@ -1,64 +0,0 @@ -/* bsearch( const void *, const void *, size_t, size_t, int(*)( const void *, const void * ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void * bsearch( const void * key, const void * base, size_t nmemb, size_t size, int ( *compar )( const void *, const void * ) ) -{ - const void * pivot; - int rc; - size_t corr; - - while ( nmemb ) - { - /* algorithm needs -1 correction if remaining elements are an even number. */ - corr = nmemb % 2; - nmemb /= 2; - pivot = ( const char * )base + ( nmemb * size ); - rc = compar( key, pivot ); - - if ( rc > 0 ) - { - base = ( const char * )pivot + size; - /* applying correction */ - nmemb -= ( 1 - corr ); - } - else if ( rc == 0 ) - { - return ( void * )pivot; - } - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -static int compare( const void * left, const void * right ) -{ - return *( ( unsigned char * )left ) - *( ( unsigned char * )right ); -} - -int main( void ) -{ - TESTCASE( bsearch( "e", abcde, 4, 1, compare ) == NULL ); - TESTCASE( bsearch( "e", abcde, 5, 1, compare ) == &abcde[4] ); - TESTCASE( bsearch( "a", abcde + 1, 4, 1, compare ) == NULL ); - TESTCASE( bsearch( "0", abcde, 1, 1, compare ) == NULL ); - TESTCASE( bsearch( "a", abcde, 1, 1, compare ) == &abcde[0] ); - TESTCASE( bsearch( "a", abcde, 0, 1, compare ) == NULL ); - TESTCASE( bsearch( "e", abcde, 3, 2, compare ) == &abcde[4] ); - TESTCASE( bsearch( "b", abcde, 3, 2, compare ) == NULL ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/bsearch_s.c b/rocklibc/src/stdlib/bsearch_s.c deleted file mode 100644 index 133f0ee..0000000 --- a/rocklibc/src/stdlib/bsearch_s.c +++ /dev/null @@ -1,78 +0,0 @@ -/* bsearch( const void *, const void *, size_t, size_t, int(*)( const void *, const void * ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include - -#ifndef REGTEST - -void * bsearch_s( const void * key, const void * base, rsize_t nmemb, rsize_t size, int ( *compar )( const void *, const void *, void * ), void * context ) -{ - const void * pivot; - int rc; - size_t corr; - - if ( nmemb > RSIZE_MAX || size > RSIZE_MAX || ( nmemb > 0 && ( key == NULL || base == NULL || compar == NULL ) ) ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - while ( nmemb ) - { - /* algorithm needs -1 correction if remaining elements are an even number. */ - corr = nmemb % 2; - nmemb /= 2; - pivot = ( const char * )base + ( nmemb * size ); - rc = compar( key, pivot, context ); - - if ( rc > 0 ) - { - base = ( const char * )pivot + size; - /* applying correction */ - nmemb -= ( 1 - corr ); - } - else if ( rc == 0 ) - { - return ( void * )pivot; - } - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int compare( const void * left, const void * right, void * context ) -{ - return *( ( unsigned char * )left ) - *( ( unsigned char * )right ); -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - TESTCASE( bsearch_s( "e", abcde, 4, 1, compare, NULL ) == NULL ); - TESTCASE( bsearch_s( "e", abcde, 5, 1, compare, NULL ) == &abcde[4] ); - TESTCASE( bsearch_s( "a", abcde + 1, 4, 1, compare, NULL ) == NULL ); - TESTCASE( bsearch_s( "0", abcde, 1, 1, compare, NULL ) == NULL ); - TESTCASE( bsearch_s( "a", abcde, 1, 1, compare, NULL ) == &abcde[0] ); - TESTCASE( bsearch_s( "a", abcde, 0, 1, compare, NULL ) == NULL ); - TESTCASE( bsearch_s( "e", abcde, 3, 2, compare, NULL ) == &abcde[4] ); - TESTCASE( bsearch_s( "b", abcde, 3, 2, compare, NULL ) == NULL ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/div.c b/rocklibc/src/stdlib/div.c deleted file mode 100644 index 5d502c8..0000000 --- a/rocklibc/src/stdlib/div.c +++ /dev/null @@ -1,40 +0,0 @@ -/* div( int, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -div_t div( int numer, int denom ) -{ - div_t rc; - rc.quot = numer / denom; - rc.rem = numer % denom; - /* TODO: pre-C99 compilers might require modulus corrections */ - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - div_t result; - result = div( 5, 2 ); - TESTCASE( result.quot == 2 && result.rem == 1 ); - result = div( -5, 2 ); - TESTCASE( result.quot == -2 && result.rem == -1 ); - result = div( 5, -2 ); - TESTCASE( result.quot == -2 && result.rem == 1 ); - TESTCASE( sizeof( result.quot ) == sizeof( int ) ); - TESTCASE( sizeof( result.rem ) == sizeof( int ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/exit.c b/rocklibc/src/stdlib/exit.c deleted file mode 100644 index 89a6d7b..0000000 --- a/rocklibc/src/stdlib/exit.c +++ /dev/null @@ -1,40 +0,0 @@ -/* exit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -/* TODO - "...except that a function is called after any previously registered - functions that had already been called at the time it was registered." -*/ - -void ( *_PDCLIB_exitstack[ _PDCLIB_ATEXIT_SLOTS ] )( void ); -size_t _PDCLIB_exitptr = 0; - -void exit( int status ) -{ - while ( _PDCLIB_exitptr != 0 ) - { - _PDCLIB_exitstack[ --_PDCLIB_exitptr ](); - } - - _Exit( status ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Unwinding of regstack tested in atexit(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/getenv.c b/rocklibc/src/stdlib/getenv.c deleted file mode 100644 index 0cc991b..0000000 --- a/rocklibc/src/stdlib/getenv.c +++ /dev/null @@ -1,56 +0,0 @@ -/* getenv( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of getenv() fit for use with POSIX kernels. -*/ - -#include -#include - -#ifndef REGTEST - -extern char ** environ; - -/* The standard states (7.22.4.6 (3), "the implementation shall behave - as if no library function calls the getenv function." That is, - however, in context of the previous paragraph stating that getenv - "need not avoid data races with other threads of execution that - modify the environment list". - PDCLib does not provide means of modifying the environment list. -*/ -char * getenv( const char * name ) -{ - size_t len = strlen( name ); - size_t index = 0; - - while ( environ[ index ] != NULL ) - { - if ( strncmp( environ[ index ], name, len ) == 0 ) - { - return environ[ index ] + len + 1; - } - - index++; - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char * env = getenv( "SHELL" ); - size_t len = strlen( env ); - TESTCASE( strcmp( env + ( len - 2 ), "sh" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/getenv_s.c b/rocklibc/src/stdlib/getenv_s.c deleted file mode 100644 index 7e01506..0000000 --- a/rocklibc/src/stdlib/getenv_s.c +++ /dev/null @@ -1,110 +0,0 @@ -/* getenv_s( size_t *, char *, rsize_t, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -/* This is an example implementation of getenv() fit for use with POSIX kernels. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -extern char ** environ; - -/* The standard states (7.22.4.6 (3), "the implementation shall behave - as if no library function calls the getenv function." That is, - however, in context of the previous paragraph stating that getenv - "need not avoid data races with other threads of execution that - modify the environment list". - PDCLib does not provide means of modifying the environment list. -*/ -errno_t getenv_s( size_t * _PDCLIB_restrict len, char * _PDCLIB_restrict value, rsize_t maxsize, const char * _PDCLIB_restrict name ) -{ - size_t nlen; - size_t index = 0; - size_t vlen = 0; - char const * environ_value = ""; - errno_t rc = -1; - - if ( name == NULL || maxsize == 0 || maxsize > RSIZE_MAX || value == NULL ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - nlen = strlen( name ); - - while ( environ[ index ] != NULL ) - { - if ( strncmp( environ[ index ], name, nlen ) == 0 ) - { - environ_value = environ[ index ] + nlen + 1; - vlen = strlen( environ_value ); - rc = 0; - break; - } - - index++; - } - - if ( len != NULL ) - { - *len = vlen; - } - - if ( vlen < maxsize ) - { - strcpy( value, environ_value ); - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - size_t len; - char value[100]; - set_constraint_handler_s( test_handler ); - - TESTCASE( getenv_s( &len, value, 100, "SHELL" ) == 0 ); - TESTCASE( strcmp( value + ( len - 2 ), "sh" ) == 0 ); - /* TESTCASE( strcmp( value, "/bin/sh" ) == 0 ); */ - - /* constraint violations */ - TESTCASE( getenv_s( &len, NULL, 100, "SHELL" ) != 0 ); - TESTCASE( getenv_s( &len, value, 0, "SHELL" ) != 0 ); - TESTCASE( getenv_s( &len, value, RSIZE_MAX + 1, "SHELL" ) != 0 ); - TESTCASE( getenv_s( &len, value, 100, NULL ) != 0 ); - - /* non-existing (hopefully), != 0 but not constraint violation */ - TESTCASE( getenv_s( &len, value, 100, "supercalifragilisticexpialidocius" ) != 0 ); - - TESTCASE( HANDLER_CALLS == 4 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/ignore_handler_s.c b/rocklibc/src/stdlib/ignore_handler_s.c deleted file mode 100644 index 7f220a1..0000000 --- a/rocklibc/src/stdlib/ignore_handler_s.c +++ /dev/null @@ -1,31 +0,0 @@ -/* ignore_handler_s( const char *, void *, errno_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include - -#ifndef REGTEST - -#include - -void ignore_handler_s( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t errno ) -{ - return; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/labs.c b/rocklibc/src/stdlib/labs.c deleted file mode 100644 index 3653453..0000000 --- a/rocklibc/src/stdlib/labs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* labs( long int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -long int labs( long int j ) -{ - return ( j >= 0 ) ? j : -j; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - TESTCASE( labs( 0 ) == 0 ); - TESTCASE( labs( LONG_MAX ) == LONG_MAX ); - TESTCASE( labs( LONG_MIN + 1 ) == -( LONG_MIN + 1 ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/ldiv.c b/rocklibc/src/stdlib/ldiv.c deleted file mode 100644 index 0f51944..0000000 --- a/rocklibc/src/stdlib/ldiv.c +++ /dev/null @@ -1,40 +0,0 @@ -/* ldiv( long int, long int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -ldiv_t ldiv( long int numer, long int denom ) -{ - ldiv_t rc; - rc.quot = numer / denom; - rc.rem = numer % denom; - /* TODO: pre-C99 compilers might require modulus corrections */ - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - ldiv_t result; - result = ldiv( 5, 2 ); - TESTCASE( result.quot == 2 && result.rem == 1 ); - result = ldiv( -5, 2 ); - TESTCASE( result.quot == -2 && result.rem == -1 ); - result = ldiv( 5, -2 ); - TESTCASE( result.quot == -2 && result.rem == 1 ); - TESTCASE( sizeof( result.quot ) == sizeof( long ) ); - TESTCASE( sizeof( result.rem ) == sizeof( long ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/llabs.c b/rocklibc/src/stdlib/llabs.c deleted file mode 100644 index bc05bf3..0000000 --- a/rocklibc/src/stdlib/llabs.c +++ /dev/null @@ -1,32 +0,0 @@ -/* llabs( long int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -long long int llabs( long long int j ) -{ - return ( j >= 0 ) ? j : -j; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - TESTCASE( llabs( 0ll ) == 0 ); - TESTCASE( llabs( LLONG_MAX ) == LLONG_MAX ); - TESTCASE( llabs( LLONG_MIN + 1 ) == -( LLONG_MIN + 1 ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/lldiv.c b/rocklibc/src/stdlib/lldiv.c deleted file mode 100644 index 4219e31..0000000 --- a/rocklibc/src/stdlib/lldiv.c +++ /dev/null @@ -1,40 +0,0 @@ -/* lldiv( long long int, long long int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -lldiv_t lldiv( long long int numer, long long int denom ) -{ - lldiv_t rc; - rc.quot = numer / denom; - rc.rem = numer % denom; - /* TODO: pre-C99 compilers might require modulus corrections */ - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - lldiv_t result; - result = lldiv( 5ll, 2ll ); - TESTCASE( result.quot == 2 && result.rem == 1 ); - result = lldiv( -5ll, 2ll ); - TESTCASE( result.quot == -2 && result.rem == -1 ); - result = lldiv( 5ll, -2ll ); - TESTCASE( result.quot == -2 && result.rem == 1 ); - TESTCASE( sizeof( result.quot ) == sizeof( long long ) ); - TESTCASE( sizeof( result.rem ) == sizeof( long long ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/qsort.c b/rocklibc/src/stdlib/qsort.c deleted file mode 100644 index 26e9f2e..0000000 --- a/rocklibc/src/stdlib/qsort.c +++ /dev/null @@ -1,188 +0,0 @@ -/* qsort( void *, size_t, size_t, int(*)( const void *, const void * ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -/* This implementation is taken from Paul Edward's PDPCLIB. - - Original code is credited to Raymond Gardner, Englewood CO. - Minor mods are credited to Paul Edwards. - Some reformatting and simplification done by Martin Baute. - All code is still Public Domain. -*/ - -/* Wrapper for _PDCLIB_memswp protects against multiple argument evaluation. */ -static _PDCLIB_inline void memswp( char * i, char * j, size_t size ) -{ - _PDCLIB_memswp( i, j, size ); -} - -/* For small sets, insertion sort is faster than quicksort. - T is the threshold below which insertion sort will be used. - Must be 3 or larger. -*/ -#define T 7 - -/* Macros for handling the QSort stack */ -#define PREPARE_STACK char * stack[STACKSIZE]; char ** stackptr = stack -#define PUSH( base, limit ) stackptr[0] = base; stackptr[1] = limit; stackptr += 2 -#define POP( base, limit ) stackptr -= 2; base = stackptr[0]; limit = stackptr[1] -/* TODO: Stack usage is log2( nmemb ) (minus what T shaves off the worst case). - Worst-case nmemb is platform dependent and should probably be - configured through _PDCLIB_config.h. -*/ -#define STACKSIZE 64 - -void qsort( void * base, size_t nmemb, size_t size, int ( *compar )( const void *, const void * ) ) -{ - char * i; - char * j; - _PDCLIB_size_t thresh = T * size; - char * base_ = ( char * )base; - char * limit = base_ + nmemb * size; - PREPARE_STACK; - - for ( ;; ) - { - if ( ( size_t )( limit - base_ ) > thresh ) /* QSort for more than T elements. */ - { - /* We work from second to last - first will be pivot element. */ - i = base_ + size; - j = limit - size; - /* We swap first with middle element, then sort that with second - and last element so that eventually first element is the median - of the three - avoiding pathological pivots. - TODO: Instead of middle element, chose one randomly. - */ - memswp( ( ( ( ( size_t )( limit - base_ ) ) / size ) / 2 ) * size + base_, base_, size ); - - if ( compar( i, j ) > 0 ) - { - memswp( i, j, size ); - } - - if ( compar( base_, j ) > 0 ) - { - memswp( base_, j, size ); - } - - if ( compar( i, base_ ) > 0 ) - { - memswp( i, base_, size ); - } - - /* Now we have the median for pivot element, entering main Quicksort. */ - for ( ;; ) - { - do - { - /* move i right until *i >= pivot */ - i += size; - } while ( compar( i, base_ ) < 0 ); - - do - { - /* move j left until *j <= pivot */ - j -= size; - } while ( compar( j, base_ ) > 0 ); - - if ( i > j ) - { - /* break loop if pointers crossed */ - break; - } - - /* else swap elements, keep scanning */ - memswp( i, j, size ); - } - - /* move pivot into correct place */ - memswp( base_, j, size ); - - /* larger subfile base / limit to stack, sort smaller */ - if ( j - base_ > limit - i ) - { - /* left is larger */ - PUSH( base_, j ); - base_ = i; - } - else - { - /* right is larger */ - PUSH( i, limit ); - limit = j; - } - } - else /* insertion sort for less than T elements */ - { - for ( j = base_, i = j + size; i < limit; j = i, i += size ) - { - for ( ; compar( j, j + size ) > 0; j -= size ) - { - memswp( j, j + size, size ); - - if ( j == base_ ) - { - break; - } - } - } - - if ( stackptr != stack ) /* if any entries on stack */ - { - POP( base_, limit ); - } - else /* else stack empty, done */ - { - break; - } - } - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include - -static int compare( const void * left, const void * right ) -{ - return *( ( unsigned char * )left ) - *( ( unsigned char * )right ); -} - -int main( void ) -{ - char presort[] = { "shreicnyjqpvozxmbt" }; - char sorted1[] = { "bcehijmnopqrstvxyz" }; - char sorted2[] = { "bticjqnyozpvreshxm" }; - char s[19]; - strcpy( s, presort ); - qsort( s, 18, 1, compare ); - TESTCASE( strcmp( s, sorted1 ) == 0 ); - strcpy( s, presort ); - qsort( s, 9, 2, compare ); - TESTCASE( strcmp( s, sorted2 ) == 0 ); - strcpy( s, presort ); - qsort( s, 1, 1, compare ); - TESTCASE( strcmp( s, presort ) == 0 ); -#if defined( REGTEST ) && ( defined( __BSD_VISIBLE ) || defined( __APPLE__ ) ) - puts( "qsort.c: Skipping test #4 for BSD as it goes into endless loop here." ); -#elif defined( REGTEST ) && defined( __ANDROID__ ) - puts( "qsort.c: Skipping test #4 for Android as it crashes." ); -#else - qsort( s, 100, 0, compare ); - TESTCASE( strcmp( s, presort ) == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/qsort_s.c b/rocklibc/src/stdlib/qsort_s.c deleted file mode 100644 index 3bca1c2..0000000 --- a/rocklibc/src/stdlib/qsort_s.c +++ /dev/null @@ -1,202 +0,0 @@ -/* qsort( void *, size_t, size_t, int(*)( const void *, const void * ) ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include - -#ifndef REGTEST - -/* This implementation is taken from Paul Edward's PDPCLIB. - - Original code is credited to Raymond Gardner, Englewood CO. - Minor mods are credited to Paul Edwards. - Some reformatting and simplification done by Martin Baute. - All code is still Public Domain. -*/ - -/* Wrapper for _PDCLIB_memswp protects against multiple argument evaluation. */ -static _PDCLIB_inline void memswp( char * i, char * j, size_t size ) -{ - _PDCLIB_memswp( i, j, size ); -} - -/* For small sets, insertion sort is faster than quicksort. - T is the threshold below which insertion sort will be used. - Must be 3 or larger. -*/ -#define T 7 - -/* Macros for handling the QSort stack */ -#define PREPARE_STACK char * stack[STACKSIZE]; char ** stackptr = stack -#define PUSH( base, limit ) stackptr[0] = base; stackptr[1] = limit; stackptr += 2 -#define POP( base, limit ) stackptr -= 2; base = stackptr[0]; limit = stackptr[1] -/* TODO: Stack usage is log2( nmemb ) (minus what T shaves off the worst case). - Worst-case nmemb is platform dependent and should probably be - configured through _PDCLIB_config.h. -*/ -#define STACKSIZE 64 - -errno_t qsort_s( void * base, rsize_t nmemb, rsize_t size, int ( *compar )( const void *, const void *, void * ), void * context ) -{ - char * i; - char * j; - _PDCLIB_size_t thresh = T * size; - char * base_ = ( char * )base; - char * limit = base_ + nmemb * size; - PREPARE_STACK; - - if ( nmemb > RSIZE_MAX || size > RSIZE_MAX || ( nmemb > 0 && ( base == NULL || compar == NULL ) ) ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - for ( ;; ) - { - if ( ( size_t )( limit - base_ ) > thresh ) /* QSort for more than T elements. */ - { - /* We work from second to last - first will be pivot element. */ - i = base_ + size; - j = limit - size; - /* We swap first with middle element, then sort that with second - and last element so that eventually first element is the median - of the three - avoiding pathological pivots. - TODO: Instead of middle element, chose one randomly. - */ - memswp( ( ( ( ( size_t )( limit - base_ ) ) / size ) / 2 ) * size + base_, base_, size ); - - if ( compar( i, j, context ) > 0 ) - { - memswp( i, j, size ); - } - - if ( compar( base_, j, context ) > 0 ) - { - memswp( base_, j, size ); - } - - if ( compar( i, base_, context ) > 0 ) - { - memswp( i, base_, size ); - } - - /* Now we have the median for pivot element, entering main Quicksort. */ - for ( ;; ) - { - do - { - /* move i right until *i >= pivot */ - i += size; - } while ( compar( i, base_, context ) < 0 ); - - do - { - /* move j left until *j <= pivot */ - j -= size; - } while ( compar( j, base_, context ) > 0 ); - - if ( i > j ) - { - /* break loop if pointers crossed */ - break; - } - - /* else swap elements, keep scanning */ - memswp( i, j, size ); - } - - /* move pivot into correct place */ - memswp( base_, j, size ); - - /* larger subfile base / limit to stack, sort smaller */ - if ( j - base_ > limit - i ) - { - /* left is larger */ - PUSH( base_, j ); - base_ = i; - } - else - { - /* right is larger */ - PUSH( i, limit ); - limit = j; - } - } - else /* insertion sort for less than T elements */ - { - for ( j = base_, i = j + size; i < limit; j = i, i += size ) - { - for ( ; compar( j, j + size, context ) > 0; j -= size ) - { - memswp( j, j + size, size ); - - if ( j == base_ ) - { - break; - } - } - } - - if ( stackptr != stack ) /* if any entries on stack */ - { - POP( base_, limit ); - } - else /* else stack empty, done */ - { - break; - } - } - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int compare( const void * left, const void * right, void * context ) -{ - return *( ( unsigned char * )left ) - *( ( unsigned char * )right ); -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char presort[] = { "shreicnyjqpvozxmbt" }; - char sorted1[] = { "bcehijmnopqrstvxyz" }; - char sorted2[] = { "bticjqnyozpvreshxm" }; - char s[19]; - strcpy( s, presort ); - qsort_s( s, 18, 1, compare, NULL ); - TESTCASE( strcmp( s, sorted1 ) == 0 ); - strcpy( s, presort ); - qsort_s( s, 9, 2, compare, NULL ); - TESTCASE( strcmp( s, sorted2 ) == 0 ); - strcpy( s, presort ); - qsort_s( s, 1, 1, compare, NULL ); - TESTCASE( strcmp( s, presort ) == 0 ); -#if defined( REGTEST ) && ( defined( __BSD_VISIBLE ) || defined( __APPLE__ ) ) - puts( "qsort_s.c: Skipping test #4 for BSD as it goes into endless loop here." ); -#else - qsort_s( s, 100, 0, compare, NULL ); - TESTCASE( strcmp( s, presort ) == 0 ); -#endif -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/quick_exit.c b/rocklibc/src/stdlib/quick_exit.c deleted file mode 100644 index cc01f79..0000000 --- a/rocklibc/src/stdlib/quick_exit.c +++ /dev/null @@ -1,40 +0,0 @@ -/* quick_exit( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -/* TODO - "...except that a function is called after any previously registered - functions that had already been called at the time it was registered." -*/ - -void ( *_PDCLIB_quickexitstack[ _PDCLIB_ATEXIT_SLOTS ] )( void ); -size_t _PDCLIB_quickexitptr = 0; - -void quick_exit( int status ) -{ - while ( _PDCLIB_quickexitptr != 0 ) - { - _PDCLIB_quickexitstack[ --_PDCLIB_quickexitptr ](); - } - - _Exit( status ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* Unwinding of regstack tested in at_quick_exit(). */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/rand.c b/rocklibc/src/stdlib/rand.c deleted file mode 100644 index 36ce9f3..0000000 --- a/rocklibc/src/stdlib/rand.c +++ /dev/null @@ -1,34 +0,0 @@ -/* rand( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int rand( void ) -{ - _PDCLIB_seed = _PDCLIB_seed * 1103515245 + 12345; - return ( int )( _PDCLIB_seed / 65536 ) % 32768; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - int rnd1, rnd2; - TESTCASE( ( rnd1 = rand() ) < RAND_MAX ); - TESTCASE( ( rnd2 = rand() ) < RAND_MAX ); - srand( 1 ); - TESTCASE( rand() == rnd1 ); - TESTCASE( rand() == rnd2 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/set_constraint_handler_s.c b/rocklibc/src/stdlib/set_constraint_handler_s.c deleted file mode 100644 index 89914e1..0000000 --- a/rocklibc/src/stdlib/set_constraint_handler_s.c +++ /dev/null @@ -1,48 +0,0 @@ -/* set_constraint_handler_s( constraint_handler_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include - -#ifndef REGTEST - -constraint_handler_t _PDCLIB_constraint_handler = abort_handler_s; - -constraint_handler_t set_constraint_handler_s( constraint_handler_t handler ) -{ - constraint_handler_t previous = _PDCLIB_constraint_handler; - - if ( handler == NULL ) - { - _PDCLIB_constraint_handler = abort_handler_s; - } - else - { - _PDCLIB_constraint_handler = handler; - } - - return previous; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - TESTCASE( _PDCLIB_constraint_handler == abort_handler_s ); - TESTCASE( set_constraint_handler_s( ignore_handler_s ) == abort_handler_s ); - TESTCASE( _PDCLIB_constraint_handler == ignore_handler_s ); - TESTCASE( set_constraint_handler_s( NULL ) == ignore_handler_s ); - TESTCASE( _PDCLIB_constraint_handler == abort_handler_s ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/srand.c b/rocklibc/src/stdlib/srand.c deleted file mode 100644 index 39c37ec..0000000 --- a/rocklibc/src/stdlib/srand.c +++ /dev/null @@ -1,28 +0,0 @@ -/* srand( unsigned int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void srand( unsigned int seed ) -{ - _PDCLIB_seed = seed; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* tested in rand.c */ - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtod.c b/rocklibc/src/stdlib/strtod.c deleted file mode 100644 index 5f87486..0000000 --- a/rocklibc/src/stdlib/strtod.c +++ /dev/null @@ -1,171 +0,0 @@ -/* strtod( const char *, char ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#include - -double strtod( const char * s, char ** endptr ) -{ - double rc = 0; - char sign = '+'; - int base = _PDCLIB_strtod_prelim( s, &sign, endptr ); - - s = *endptr; - - switch ( base ) - { - case -2: - rc = 0.0/0.0 * -1; - break; - case -1: - /* INF */ - rc = DBL_MAX * 2; - break; - case 0: - /* No match */ - break; - case 10: - rc = (double)_PDCLIB_naive_etod( s, endptr ); - break; - case 16: - rc = (double)_PDCLIB_naive_ptod( s, endptr ); - break; - } - - if ( sign == '-' ) - { - rc *= -1.0; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include -#include - -typedef struct -{ - const char * s; - double d; - ptrdiff_t l; -} testdata_t; - -extern int dprintf( int, char const *, ... ); - -int main( void ) -{ - double d; - char * s; - testdata_t testdata[] = - { - { "123", 123.0, 3 }, - { "123.45", 123.45, 6 }, - { ".45", 0.45, 3 }, - { "123.", 123, 4 }, - { " -0123f", -123.0, 7 }, - { " -.45", -0.45, 5 }, - { " 0.a", 0.0, 3 }, - { "1.23e2", 123.0, 6 }, - { "1.23e-2", 0.0123, 7 }, - { "-0.000123e+6", -123.0, 12 }, - { "-123000e-3", -123, 10 }, - { "-123e-003", -0.123, 9 }, - { " infx", DBL_MAX * 2, 4 }, - { " nanx", 0.0 / 0.0 * -1, 4 }, - { " -infx", DBL_MAX * 2 * -1, 5 }, - { " -nanx", 0.0 / 0.0, 5 }, - { " nan(foo)", 0.0 / 0.0 * -1, 9 }, - { " nan(foo", 0.0 / 0.0 * -1, 4 } - }; - - d = strtod( testdata[0].s, &s ); - TESTCASE( d == testdata[0].d ); - TESTCASE( (s - testdata[0].s) == testdata[0].l ); - - d = strtod( testdata[1].s, &s ); - TESTCASE( d == testdata[1].d ); - TESTCASE( (s - testdata[1].s) == testdata[1].l ); - - d = strtod( testdata[2].s, &s ); - TESTCASE( d == testdata[2].d ); - TESTCASE( (s - testdata[2].s) == testdata[2].l ); - - d = strtod( testdata[3].s, &s ); - TESTCASE( d == testdata[3].d ); - TESTCASE( (s - testdata[3].s) == testdata[3].l ); - - d = strtod( testdata[4].s, &s ); - TESTCASE( d == testdata[4].d ); - TESTCASE( (s - testdata[4].s) == testdata[4].l ); - - d = strtod( testdata[5].s, &s ); - TESTCASE( d == testdata[5].d ); - TESTCASE( (s - testdata[5].s) == testdata[5].l ); - - d = strtod( testdata[6].s, &s ); - TESTCASE( d == testdata[6].d ); - TESTCASE( (s - testdata[6].s) == testdata[6].l ); - - d = strtod( testdata[7].s, &s ); - TESTCASE( d == testdata[7].d ); - TESTCASE( (s - testdata[7].s) == testdata[7].l ); - - d = strtod( testdata[8].s, &s ); - TESTCASE( d == testdata[8].d ); - TESTCASE( (s - testdata[8].s) == testdata[8].l ); - - d = strtod( testdata[9].s, &s ); - TESTCASE( d == testdata[9].d ); - TESTCASE( (s - testdata[9].s) == testdata[9].l ); - - d = strtod( testdata[10].s, &s ); - TESTCASE( d == testdata[10].d ); - TESTCASE( (s - testdata[10].s) == testdata[10].l ); - - d = strtod( testdata[11].s, &s ); - TESTCASE( d == testdata[11].d ); - TESTCASE( (s - testdata[11].s) == testdata[11].l ); - - d = strtod( testdata[12].s, &s ); - TESTCASE( d == testdata[12].d ); - TESTCASE( (s - testdata[12].s) == testdata[12].l ); - - d = strtod( testdata[13].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[13].s) == testdata[13].l ); - - d = strtod( testdata[14].s, &s ); - TESTCASE( d == testdata[14].d ); - TESTCASE( (s - testdata[14].s) == testdata[14].l ); - - d = strtod( testdata[15].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[15].s) == testdata[15].l ); - - d = strtod( testdata[16].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[16].s) == testdata[16].l ); - - d = strtod( testdata[17].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[17].s) == testdata[17].l ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtof.c b/rocklibc/src/stdlib/strtof.c deleted file mode 100644 index 0a81951..0000000 --- a/rocklibc/src/stdlib/strtof.c +++ /dev/null @@ -1,169 +0,0 @@ -/* strtof( const char *, char ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#include - -float strtof( const char * s, char ** endptr ) -{ - float rc = 0; - char sign = '+'; - int base = _PDCLIB_strtod_prelim( s, &sign, endptr ); - - s = *endptr; - - switch ( base ) - { - case -2: - rc = 0.0/0.0 * -1; - break; - case -1: - /* INF */ - rc = FLT_MAX * 2; - break; - case 0: - /* No match */ - break; - case 10: - rc = (float)_PDCLIB_naive_etod( s, endptr ); - break; - case 16: - rc = (float)_PDCLIB_naive_ptod( s, endptr ); - break; - } - - if ( sign == '-' ) - { - rc *= -1.0; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include -#include - -typedef struct -{ - const char * s; - float d; - ptrdiff_t l; -} testdata_t; - -int main( void ) -{ - float d; - char * s; - testdata_t testdata[] = - { - { "123", 123.0, 3 }, - { "123.45", 123.45, 6 }, - { ".45", 0.45, 3 }, - { "123.", 123, 4 }, - { " -0123f", -123.0, 7 }, - { " -.45", -0.45, 5 }, - { " 0.a", 0.0, 3 }, - { "1.23e2", 123.0, 6 }, - { "1.23e-2", 0.0123, 7 }, - { "-0.000123e+6", -123.0, 12 }, - { "-123000e-3", -123, 10 }, - { "-123e-003", -0.123, 9 }, - { " infx", FLT_MAX * 2, 4 }, - { " nanx", 0.0 / 0.0 * -1, 4 }, - { " -infx", FLT_MAX * 2 * -1, 5 }, - { " -nanx", 0.0 / 0.0, 5 }, - { " nan(foo)", 0.0 / 0.0 * -1, 9 }, - { " nan(foo", 0.0 / 0.0 * -1, 4 } - }; - - d = strtod( testdata[0].s, &s ); - TESTCASE( d == testdata[0].d ); - TESTCASE( (s - testdata[0].s) == testdata[0].l ); - - d = strtod( testdata[1].s, &s ); - TESTCASE( d == testdata[1].d ); - TESTCASE( (s - testdata[1].s) == testdata[1].l ); - - d = strtod( testdata[2].s, &s ); - TESTCASE( d == testdata[2].d ); - TESTCASE( (s - testdata[2].s) == testdata[2].l ); - - d = strtod( testdata[3].s, &s ); - TESTCASE( d == testdata[3].d ); - TESTCASE( (s - testdata[3].s) == testdata[3].l ); - - d = strtod( testdata[4].s, &s ); - TESTCASE( d == testdata[4].d ); - TESTCASE( (s - testdata[4].s) == testdata[4].l ); - - d = strtod( testdata[5].s, &s ); - TESTCASE( d == testdata[5].d ); - TESTCASE( (s - testdata[5].s) == testdata[5].l ); - - d = strtod( testdata[6].s, &s ); - TESTCASE( d == testdata[6].d ); - TESTCASE( (s - testdata[6].s) == testdata[6].l ); - - d = strtod( testdata[7].s, &s ); - TESTCASE( d == testdata[7].d ); - TESTCASE( (s - testdata[7].s) == testdata[7].l ); - - d = strtod( testdata[8].s, &s ); - TESTCASE( d == testdata[8].d ); - TESTCASE( (s - testdata[8].s) == testdata[8].l ); - - d = strtod( testdata[9].s, &s ); - TESTCASE( d == testdata[9].d ); - TESTCASE( (s - testdata[9].s) == testdata[9].l ); - - d = strtod( testdata[10].s, &s ); - TESTCASE( d == testdata[10].d ); - TESTCASE( (s - testdata[10].s) == testdata[10].l ); - - d = strtod( testdata[11].s, &s ); - TESTCASE( d == testdata[11].d ); - TESTCASE( (s - testdata[11].s) == testdata[11].l ); - - d = strtod( testdata[12].s, &s ); - TESTCASE( d == testdata[12].d ); - TESTCASE( (s - testdata[12].s) == testdata[12].l ); - - d = strtod( testdata[13].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[13].s) == testdata[13].l ); - - d = strtod( testdata[14].s, &s ); - TESTCASE( d == testdata[14].d ); - TESTCASE( (s - testdata[14].s) == testdata[14].l ); - - d = strtod( testdata[15].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[15].s) == testdata[15].l ); - - d = strtod( testdata[16].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[16].s) == testdata[16].l ); - - d = strtod( testdata[17].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[17].s) == testdata[17].l ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtol.c b/rocklibc/src/stdlib/strtol.c deleted file mode 100644 index 6d6d657..0000000 --- a/rocklibc/src/stdlib/strtol.c +++ /dev/null @@ -1,144 +0,0 @@ -/* strtol( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -long int strtol( const char * s, char ** endptr, int base ) -{ - long int rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - if ( sign == '+' ) - { - rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LONG_MAX, ( uintmax_t )LONG_MAX, &sign ); - } - else - { - rc = ( long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )( unsigned long )LONG_MIN, ( ( uintmax_t )LONG_MAX + 1 ), &sign ); - } - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) s; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtol( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtol( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtol( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtol( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtol( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtol( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtol( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it. */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtol( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* correctly decoding zero */ - TESTCASE( strtol( "0", &endptr, 0 ) == 0 ); - TESTCASE( *endptr == '\0' ); - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtol( overflow, &endptr, 36 ) == LONG_MIN ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtol( overflow + 1, &endptr, 36 ) == LONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtol( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtol( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtol( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - /* TODO: These tests assume two-complement, but conversion should work */ - /* for one-complement and signed magnitude just as well. Anyone having */ - /* a platform to test this on? */ - errno = 0; -#if LONG_MAX >> 30 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtol( "2147483647", NULL, 0 ) == 0x7fffffff ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "2147483648", NULL, 0 ) == LONG_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtol( "-2147483647", NULL, 0 ) == ( long )0x80000001 ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "-2147483648", NULL, 0 ) == LONG_MIN ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "-2147483649", NULL, 0 ) == LONG_MIN ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#elif LONG_MAX >> 62 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtol( "9223372036854775807", NULL, 0 ) == 0x7fffffffffffffff ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "9223372036854775808", NULL, 0 ) == LONG_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtol( "-9223372036854775807", NULL, 0 ) == ( long )0x8000000000000001 ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "-9223372036854775808", NULL, 0 ) == LONG_MIN ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtol( "-9223372036854775809", NULL, 0 ) == LONG_MIN ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#else -#error Unsupported width of 'long' (neither 32 nor 64 bit). -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtold.c b/rocklibc/src/stdlib/strtold.c deleted file mode 100644 index 4c473c7..0000000 --- a/rocklibc/src/stdlib/strtold.c +++ /dev/null @@ -1,169 +0,0 @@ -/* strtold( const char *, char ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_internal.h" - -#include - -long double strtold( const char * s, char ** endptr ) -{ - long double rc = 0; - char sign = '+'; - int base = _PDCLIB_strtod_prelim( s, &sign, endptr ); - - s = *endptr; - - switch ( base ) - { - case -2: - rc = 0.0/0.0 * -1; - break; - case -1: - /* INF */ - rc = LDBL_MAX * 2; - break; - case 0: - /* No match */ - break; - case 10: - rc = (long double)_PDCLIB_naive_etod( s, endptr ); - break; - case 16: - rc = (long double)_PDCLIB_naive_ptod( s, endptr ); - break; - } - - if ( sign == '-' ) - { - rc *= -1.0; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include -#include - -typedef struct -{ - const char * s; - long double d; - ptrdiff_t l; -} testdata_t; - -int main( void ) -{ - long double d; - char * s; - testdata_t testdata[] = - { - { "123", 123.0, 3 }, - { "123.45", 123.45, 6 }, - { ".45", 0.45, 3 }, - { "123.", 123, 4 }, - { " -0123f", -123.0, 7 }, - { " -.45", -0.45, 5 }, - { " 0.a", 0.0, 3 }, - { "1.23e2", 123.0, 6 }, - { "1.23e-2", 0.0123, 7 }, - { "-0.000123e+6", -123.0, 12 }, - { "-123000e-3", -123, 10 }, - { "-123e-003", -0.123, 9 }, - { " infx", LDBL_MAX * 2, 4 }, - { " nanx", 0.0 / 0.0 * -1, 4 }, - { " -infx", LDBL_MAX * 2 * -1, 5 }, - { " -nanx", 0.0 / 0.0, 5 }, - { " nan(foo)", 0.0 / 0.0 * -1, 9 }, - { " nan(foo", 0.0 / 0.0 * -1, 4 } - }; - - d = strtod( testdata[0].s, &s ); - TESTCASE( d == testdata[0].d ); - TESTCASE( (s - testdata[0].s) == testdata[0].l ); - - d = strtod( testdata[1].s, &s ); - TESTCASE( d == testdata[1].d ); - TESTCASE( (s - testdata[1].s) == testdata[1].l ); - - d = strtod( testdata[2].s, &s ); - TESTCASE( d == testdata[2].d ); - TESTCASE( (s - testdata[2].s) == testdata[2].l ); - - d = strtod( testdata[3].s, &s ); - TESTCASE( d == testdata[3].d ); - TESTCASE( (s - testdata[3].s) == testdata[3].l ); - - d = strtod( testdata[4].s, &s ); - TESTCASE( d == testdata[4].d ); - TESTCASE( (s - testdata[4].s) == testdata[4].l ); - - d = strtod( testdata[5].s, &s ); - TESTCASE( d == testdata[5].d ); - TESTCASE( (s - testdata[5].s) == testdata[5].l ); - - d = strtod( testdata[6].s, &s ); - TESTCASE( d == testdata[6].d ); - TESTCASE( (s - testdata[6].s) == testdata[6].l ); - - d = strtod( testdata[7].s, &s ); - TESTCASE( d == testdata[7].d ); - TESTCASE( (s - testdata[7].s) == testdata[7].l ); - - d = strtod( testdata[8].s, &s ); - TESTCASE( d == testdata[8].d ); - TESTCASE( (s - testdata[8].s) == testdata[8].l ); - - d = strtod( testdata[9].s, &s ); - TESTCASE( d == testdata[9].d ); - TESTCASE( (s - testdata[9].s) == testdata[9].l ); - - d = strtod( testdata[10].s, &s ); - TESTCASE( d == testdata[10].d ); - TESTCASE( (s - testdata[10].s) == testdata[10].l ); - - d = strtod( testdata[11].s, &s ); - TESTCASE( d == testdata[11].d ); - TESTCASE( (s - testdata[11].s) == testdata[11].l ); - - d = strtod( testdata[12].s, &s ); - TESTCASE( d == testdata[12].d ); - TESTCASE( (s - testdata[12].s) == testdata[12].l ); - - d = strtod( testdata[13].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[13].s) == testdata[13].l ); - - d = strtod( testdata[14].s, &s ); - TESTCASE( d == testdata[14].d ); - TESTCASE( (s - testdata[14].s) == testdata[14].l ); - - d = strtod( testdata[15].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[15].s) == testdata[15].l ); - - d = strtod( testdata[16].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[16].s) == testdata[16].l ); - - d = strtod( testdata[17].s, &s ); - TESTCASE( d != d ); - TESTCASE( (s - testdata[17].s) == testdata[17].l ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtoll.c b/rocklibc/src/stdlib/strtoll.c deleted file mode 100644 index 0be6b78..0000000 --- a/rocklibc/src/stdlib/strtoll.c +++ /dev/null @@ -1,138 +0,0 @@ -/* strtoll( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -long long int strtoll( const char * s, char ** endptr, int base ) -{ - long long int rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - if ( sign == '+' ) - { - rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )LLONG_MAX, ( uintmax_t )LLONG_MAX, &sign ); - } - else - { - rc = ( long long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )( unsigned long long )LLONG_MIN, ( ( uintmax_t )LLONG_MAX + 1 ), &sign ); - } - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) s; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtoll( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtoll( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtoll( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtoll( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtoll( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtoll( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtoll( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtoll( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* correctly decoding zero */ - TESTCASE( strtoll( "0", &endptr, 0 ) == 0 ); - TESTCASE( *endptr == '\0' ); - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtoll( overflow, &endptr, 36 ) == LLONG_MIN ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtoll( overflow + 1, &endptr, 36 ) == LLONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtoll( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtoll( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtoll( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - /* TODO: These tests assume two-complement, but conversion should work */ - /* for one-complement and signed magnitude just as well. Anyone having */ - /* a platform to test this on? */ - errno = 0; -#if LLONG_MAX >> 62 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoll( "9223372036854775807", NULL, 0 ) == 0x7fffffffffffffff ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "9223372036854775808", NULL, 0 ) == LLONG_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoll( "-9223372036854775807", NULL, 0 ) == ( long long )0x8000000000000001 ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "-9223372036854775808", NULL, 0 ) == LLONG_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "-9223372036854775809", NULL, 0 ) == LLONG_MIN ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#elif LLONG_MAX >> 126 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoll( "170141183460469231731687303715884105728", NULL, 0 ) == 0x7fffffffffffffffffffffffffffffff ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "170141183460469231731687303715884105729", NULL, 0 ) == LLONG_MAX ); - TESTCASE( errno == ERANGE ); - errno = 0; - TESTCASE( strtoll( "-170141183460469231731687303715884105728", NULL, 0 ) == -0x80000000000000000000000000000001 ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "-170141183460469231731687303715884105729", NULL, 0 ) == LLONG_MIN ); - TESTCASE( errno == 0 ); - TESTCASE( strtoll( "-170141183460469231731687303715884105730", NULL, 0 ) == LLONG_MIN ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#else -#error Unsupported width of 'long long' (neither 64 nor 128 bit). -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtoul.c b/rocklibc/src/stdlib/strtoul.c deleted file mode 100644 index c889e2b..0000000 --- a/rocklibc/src/stdlib/strtoul.c +++ /dev/null @@ -1,124 +0,0 @@ -/* strtoul( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -unsigned long int strtoul( const char * s, char ** endptr, int base ) -{ - unsigned long int rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - rc = ( unsigned long int )_PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULONG_MAX, ( uintmax_t )ULONG_MAX, &sign ); - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) s; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtoul( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtoul( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtoul( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtoul( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtoul( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtoul( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtoul( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtoul( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* correctly decoding zero */ - TESTCASE( strtoul( "0", &endptr, 0 ) == 0 ); - TESTCASE( *endptr == '\0' ); - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtoul( overflow, &endptr, 36 ) == ULONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtoul( overflow + 1, &endptr, 36 ) == ULONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtoul( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtoul( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtoul( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - /* TODO: These tests assume two-complement, but conversion should work */ - /* for one-complement and signed magnitude just as well. Anyone having */ - /* a platform to test this on? */ - errno = 0; - /* long -> 32 bit */ -#if ULONG_MAX >> 31 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoul( "4294967295", NULL, 0 ) == ULONG_MAX ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtoul( "4294967296", NULL, 0 ) == ULONG_MAX ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ - /* long -> 64 bit */ -#elif ULONG_MAX >> 63 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoul( "18446744073709551615", NULL, 0 ) == ULONG_MAX ); - TESTCASE( errno == 0 ); - errno = 0; - TESTCASE( strtoul( "18446744073709551616", NULL, 0 ) == ULONG_MAX ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#else -#error Unsupported width of 'long' (neither 32 nor 64 bit). -#endif - errno = 0; - TESTCASE( strtoul( "-1", NULL, 0 ) == ULONG_MAX ); - TESTCASE( errno == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/strtoull.c b/rocklibc/src/stdlib/strtoull.c deleted file mode 100644 index f890912..0000000 --- a/rocklibc/src/stdlib/strtoull.c +++ /dev/null @@ -1,119 +0,0 @@ -/* strtoull( const char *, char **, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include - -#ifndef REGTEST - -#include - -unsigned long long int strtoull( const char * s, char ** endptr, int base ) -{ - unsigned long long int rc; - char sign = '+'; - const char * p = _PDCLIB_strtox_prelim( s, &sign, &base ); - - if ( base < 2 || base > 36 ) - { - return 0; - } - - rc = _PDCLIB_strtox_main( &p, ( unsigned )base, ( uintmax_t )ULLONG_MAX, ( uintmax_t )ULLONG_MAX, &sign ); - - if ( endptr != NULL ) - { - *endptr = ( p != NULL ) ? ( char * ) p : ( char * ) s; - } - - return ( sign == '+' ) ? rc : -rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - char * endptr; - /* this, to base 36, overflows even a 256 bit integer */ - char overflow[] = "-ZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ_"; - /* tricky border case */ - char tricky[] = "+0xz"; - errno = 0; - /* basic functionality */ - TESTCASE( strtoull( "123", NULL, 10 ) == 123 ); - /* proper detecting of default base 10 */ - TESTCASE( strtoull( "456", NULL, 0 ) == 456 ); - /* proper functioning to smaller base */ - TESTCASE( strtoull( "14", NULL, 8 ) == 12 ); - /* proper autodetecting of octal */ - TESTCASE( strtoull( "016", NULL, 0 ) == 14 ); - /* proper autodetecting of hexadecimal, lowercase 'x' */ - TESTCASE( strtoull( "0xFF", NULL, 0 ) == 255 ); - /* proper autodetecting of hexadecimal, uppercase 'X' */ - TESTCASE( strtoull( "0Xa1", NULL, 0 ) == 161 ); - /* proper handling of border case: 0x followed by non-hexdigit */ - TESTCASE( strtoull( tricky, &endptr, 0 ) == 0 ); - /* newlib completely balks at this parse, so we _NOREG it */ - TESTCASE_NOREG( endptr == tricky + 2 ); - /* proper handling of border case: 0 followed by non-octdigit */ - TESTCASE( strtoull( tricky, &endptr, 8 ) == 0 ); - TESTCASE( endptr == tricky + 2 ); - /* errno should still be 0 */ - TESTCASE( errno == 0 ); - /* correctly decoding zero */ - TESTCASE( strtoull( "0", &endptr, 0 ) == 0 ); - TESTCASE( *endptr == '\0' ); - TESTCASE( errno == 0 ); - /* overflowing subject sequence must still return proper endptr */ - TESTCASE( strtoull( overflow, &endptr, 36 ) == ULLONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* same for positive */ - errno = 0; - TESTCASE( strtoull( overflow + 1, &endptr, 36 ) == ULLONG_MAX ); - TESTCASE( errno == ERANGE ); - TESTCASE( ( endptr - overflow ) == 53 ); - /* testing skipping of leading whitespace */ - TESTCASE( strtoull( " \n\v\t\f789", NULL, 0 ) == 789 ); - /* testing conversion failure */ - TESTCASE( strtoull( overflow, &endptr, 10 ) == 0 ); - TESTCASE( endptr == overflow ); - endptr = NULL; - TESTCASE( strtoull( overflow, &endptr, 0 ) == 0 ); - TESTCASE( endptr == overflow ); - errno = 0; - /* long long -> 64 bit */ -#if ULLONG_MAX >> 63 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoull( "18446744073709551615", NULL, 0 ) == ULLONG_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoull( "18446744073709551616", NULL, 0 ) == ULLONG_MAX ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ - /* long long -> 128 bit */ -#elif ULLONG_MAX >> 127 == 1 - /* testing "even" overflow, i.e. base is power of two */ - TESTCASE( strtoull( "340282366920938463463374607431768211455", NULL, 0 ) == ULLONG_MAX ); - TESTCASE( errno == 0 ); - TESTCASE( strtoull( "340282366920938463463374607431768211456", NULL, 0 ) == ULLONG_MAX ); - TESTCASE( errno == ERANGE ); - /* TODO: test "odd" overflow, i.e. base is not power of two */ -#else -#error Unsupported width of 'long long' (neither 64 nor 128 bit). -#endif - errno = 0; - TESTCASE( strtoull( "-1", NULL, 0 ) == ULLONG_MAX ); - TESTCASE( errno == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/stdlib/system.c b/rocklibc/src/stdlib/system.c deleted file mode 100644 index f8b3b80..0000000 --- a/rocklibc/src/stdlib/system.c +++ /dev/null @@ -1,71 +0,0 @@ -/* system( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -/* This is an example implementation of system() fit for use with POSIX kernels. -*/ - -#ifdef __cplusplus -extern "C" { -#endif - -extern int fork( void ); -extern int execve( const char * filename, char * const argv[], char * const envp[] ); -extern int wait( int * status ); - -#ifdef __cplusplus -} -#endif - -int system( const char * string ) -{ - const char * argv[] = { "sh", "-c", NULL, NULL }; - argv[2] = string; - - if ( string != NULL ) - { - int pid = fork(); - - if ( pid == 0 ) - { - execve( "/bin/sh", ( char * const *)argv, NULL ); - } - else if ( pid > 0 ) - { - while ( wait( NULL ) != pid ) - { - /* EMPTY */ - } - } - } - - return -1; -} - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#define SHELLCOMMAND "echo 'SUCCESS testing system()'" - -int main( void ) -{ - FILE * fh; - char buffer[25]; - buffer[24] = 'x'; - TESTCASE( ( fh = freopen( testfile, "wb+", stdout ) ) != NULL ); - TESTCASE( system( SHELLCOMMAND ) ); - rewind( fh ); - TESTCASE( fread( buffer, 1, 24, fh ) == 24 ); - TESTCASE( memcmp( buffer, "SUCCESS testing system()", 24 ) == 0 ); - TESTCASE( buffer[24] == 'x' ); - TESTCASE( fclose( fh ) == 0 ); - TESTCASE( remove( testfile ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string.c b/rocklibc/src/string.c new file mode 100644 index 0000000..cd4a0e1 --- /dev/null +++ b/rocklibc/src/string.c @@ -0,0 +1,68 @@ +#include + +void *memcpy(void *restrict dest, const void *restrict src, size_t n) { + char *d = (char *)dest; + const char *s = (const char *)src; + + for (size_t i = 0; i < n; i++) { + d[i] = s[i]; + } + return dest; +} + +/* Copy memory area: safely handles overlapping regions */ +void *memmove(void *dest, const void *src, size_t n) { + char *d = (char *)dest; + const char *s = (const char *)src; + + if (d < s) { + // Copy forward + for (size_t i = 0; i < n; i++) { + d[i] = s[i]; + } + } else if (d > s) { + // Copy backward to prevent overwriting uncopied data + for (size_t i = n; i > 0; i--) { + d[i - 1] = s[i - 1]; + } + } + return dest; +} + +/* Fill memory block with a constant byte */ +void *memset(void *s, int c, size_t n) { + unsigned char *p = (unsigned char *)s; + for (size_t i = 0; i < n; i++) { + p[i] = (unsigned char)c; + } + return s; +} + +/* Calculate the length of a string */ +size_t strlen(const char *s) { + size_t len = 0; + while (s[len] != '\0') { + len++; + } + return len; +} + +/* Compare two strings */ +int strcmp(const char *s1, const char *s2) { + while (*s1 && (*s1 == *s2)) { + s1++; + s2++; + } + return *(unsigned char *)s1 - *(unsigned char *)s2; +} + +/* Copy a string from src to dest */ +char *strcpy(char *dest, const char *src) { + size_t i = 0; + while (src[i] != '\0') { + dest[i] = src[i]; + i++; + } + dest[i] = '\0'; + return dest; +} \ No newline at end of file diff --git a/rocklibc/src/string/memchr.c b/rocklibc/src/string/memchr.c deleted file mode 100644 index 5e0186c..0000000 --- a/rocklibc/src/string/memchr.c +++ /dev/null @@ -1,44 +0,0 @@ -/* memchr( const void *, int, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void * memchr( const void * s, int c, size_t n ) -{ - const unsigned char * p = ( const unsigned char * ) s; - - while ( n-- ) - { - if ( *p == ( unsigned char ) c ) - { - return ( void * ) p; - } - - ++p; - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( memchr( abcde, 'c', 5 ) == &abcde[2] ); - TESTCASE( memchr( abcde, 'a', 1 ) == &abcde[0] ); - TESTCASE( memchr( abcde, 'a', 0 ) == NULL ); - TESTCASE( memchr( abcde, '\0', 5 ) == NULL ); - TESTCASE( memchr( abcde, '\0', 6 ) == &abcde[5] ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memcmp.c b/rocklibc/src/string/memcmp.c deleted file mode 100644 index 2c9fdfe..0000000 --- a/rocklibc/src/string/memcmp.c +++ /dev/null @@ -1,46 +0,0 @@ -/* memcmp( const void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int memcmp( const void * s1, const void * s2, size_t n ) -{ - const unsigned char * p1 = ( const unsigned char * ) s1; - const unsigned char * p2 = ( const unsigned char * ) s2; - - while ( n-- ) - { - if ( *p1 != *p2 ) - { - return *p1 - *p2; - } - - ++p1; - ++p2; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - const char xxxxx[] = "xxxxx"; - TESTCASE( memcmp( abcde, abcdx, 5 ) < 0 ); - TESTCASE( memcmp( abcde, abcdx, 4 ) == 0 ); - TESTCASE( memcmp( abcde, xxxxx, 0 ) == 0 ); - TESTCASE( memcmp( xxxxx, abcde, 1 ) > 0 ); - return 0; -} - -#endif diff --git a/rocklibc/src/string/memcpy.c b/rocklibc/src/string/memcpy.c deleted file mode 100644 index d2cabb3..0000000 --- a/rocklibc/src/string/memcpy.c +++ /dev/null @@ -1,42 +0,0 @@ -/* memcpy( void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - while ( n-- ) - { - *dest++ = *src++; - } - - return s1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxxxxxxxx"; - TESTCASE( memcpy( s, abcde, 6 ) == s ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( memcpy( s + 5, abcde, 5 ) == s + 5 ); - TESTCASE( s[9] == 'e' ); - TESTCASE( s[10] == 'x' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memcpy_s.c b/rocklibc/src/string/memcpy_s.c deleted file mode 100644 index b5a2f66..0000000 --- a/rocklibc/src/string/memcpy_s.c +++ /dev/null @@ -1,92 +0,0 @@ -/* memcpy_s( void *, rsize_t, const void *, rsize_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t memcpy_s( void * _PDCLIB_restrict s1, rsize_t s1max, const void * _PDCLIB_restrict s2, rsize_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && n <= s1max ) - { - while ( n-- ) - { - if ( dest == s2 || src == s1 ) - { - goto runtime_constraint_violation; - } - - *dest++ = *src++; - } - - return 0; - } - -runtime_constraint_violation: - - if ( s1 != NULL && s1max <= RSIZE_MAX ) - { - memset( s1, 0, s1max ); - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xxxxxxxxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( memcpy_s( s, 11, abcde, 6 ) == 0 ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( memcpy_s( s + 5, 6, abcde, 5 ) == 0 ); - TESTCASE( s[9] == 'e' ); - TESTCASE( s[10] == 'x' ); - - s[5] = 'x'; - - TESTCASE( memcpy_s( s, 5, abcde, 6 ) != 0 ); - TESTCASE( memcmp( s, "\0\0\0\0\0x", 6 ) == 0 ); - - TESTCASE( memcpy_s( s, 3, s + 2, 3 ) != 0 ); - TESTCASE( memcpy_s( s + 2, 3, s, 3 ) != 0 ); - - /* Overlapping */ - TESTCASE( memcpy_s( s, 4, s + 3, 4 ) != 0 ); - TESTCASE( memcpy_s( s + 3, 4, s, 4 ) != 0 ); - - TESTCASE( HANDLER_CALLS == 5 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memmove.c b/rocklibc/src/string/memmove.c deleted file mode 100644 index d361bb5..0000000 --- a/rocklibc/src/string/memmove.c +++ /dev/null @@ -1,55 +0,0 @@ -/* memmove( void *, const void *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void * memmove( void * s1, const void * s2, size_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - if ( dest <= src ) - { - while ( n-- ) - { - *dest++ = *src++; - } - } - else - { - src += n; - dest += n; - - while ( n-- ) - { - *--dest = *--src; - } - } - - return s1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxabcde"; - TESTCASE( memmove( s, s + 4, 5 ) == s ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == 'b' ); - TESTCASE( memmove( s + 4, s, 5 ) == s + 4 ); - TESTCASE( s[4] == 'a' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memmove_s.c b/rocklibc/src/string/memmove_s.c deleted file mode 100644 index 1b02fb1..0000000 --- a/rocklibc/src/string/memmove_s.c +++ /dev/null @@ -1,87 +0,0 @@ -/* memmove_s( void *, rsize_t, const void *, rsize_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t memmove_s( void * s1, rsize_t s1max, const void * s2, rsize_t n ) -{ - char * dest = ( char * ) s1; - const char * src = ( const char * ) s2; - - if ( s1 == NULL || s2 == NULL || s1max > RSIZE_MAX || n > RSIZE_MAX || n > s1max ) - { - if ( s1 != NULL && s1max <= RSIZE_MAX ) - { - memset( s1, 0, s1max ); - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - while ( n ) - { - if ( dest == s2 || src == s1 ) - { - src += n; - dest += n; - - while ( n-- ) - { - *--dest = *--src; - } - - return 0; - } - - *dest++ = *src++; - --n; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xxxxabcde"; - set_constraint_handler_s( test_handler ); - - TESTCASE( memmove_s( s, 10, s + 4, 5 ) == 0 ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == 'b' ); - TESTCASE( memmove_s( s + 4, 6, s, 5 ) == 0 ); - TESTCASE( s[4] == 'a' ); - - TESTCASE( HANDLER_CALLS == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memset.c b/rocklibc/src/string/memset.c deleted file mode 100644 index 4871246..0000000 --- a/rocklibc/src/string/memset.c +++ /dev/null @@ -1,42 +0,0 @@ -/* memset( void *, int, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -void * memset( void * s, int c, size_t n ) -{ - unsigned char * p = ( unsigned char * ) s; - - while ( n-- ) - { - *p++ = ( unsigned char ) c; - } - - return s; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxxxxxx"; - TESTCASE( memset( s, 'o', 10 ) == s ); - TESTCASE( s[9] == 'o' ); - TESTCASE( memset( s, '_', ( 0 ) ) == s ); - TESTCASE( s[0] == 'o' ); - TESTCASE( memset( s, '_', 1 ) == s ); - TESTCASE( s[0] == '_' ); - TESTCASE( s[1] == 'o' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/memset_s.c b/rocklibc/src/string/memset_s.c deleted file mode 100644 index 622c0a8..0000000 --- a/rocklibc/src/string/memset_s.c +++ /dev/null @@ -1,73 +0,0 @@ -/* memset_s( void *, rsize_t, int, rsize_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t memset_s( void * s, rsize_t smax, int c, rsize_t n ) -{ - unsigned char * p = ( unsigned char * ) s; - - if ( s == NULL || smax > RSIZE_MAX || n > RSIZE_MAX || n > smax ) - { - if ( s != NULL && smax <= RSIZE_MAX ) - { - memset( s, c, smax ); - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - while ( n-- ) - { - *p++ = ( unsigned char ) c; - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xxxxxxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( memset_s( s, 10, 'o', 10 ) == 0 ); - TESTCASE( s[9] == 'o' ); - TESTCASE( memset_s( s, 10, '_', ( 0 ) ) == 0 ); - TESTCASE( s[0] == 'o' ); - TESTCASE( memset_s( s, 10, '_', 1 ) == 0 ); - TESTCASE( s[0] == '_' ); - TESTCASE( s[1] == 'o' ); - - TESTCASE( HANDLER_CALLS == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcat.c b/rocklibc/src/string/strcat.c deleted file mode 100644 index f9187cc..0000000 --- a/rocklibc/src/string/strcat.c +++ /dev/null @@ -1,55 +0,0 @@ -/* strcat( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) -{ - char * rc = s1; - - if ( *s1 ) - { - while ( *++s1 ) - { - /* EMPTY */ - } - } - - while ( ( *s1++ = *s2++ ) ) - { - /* EMPTY */ - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xx\0xxxxxx"; - TESTCASE( strcat( s, abcde ) == s ); - TESTCASE( s[2] == 'a' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( s[7] == '\0' ); - TESTCASE( s[8] == 'x' ); - s[0] = '\0'; - TESTCASE( strcat( s, abcdx ) == s ); - TESTCASE( s[4] == 'x' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strcat( s, "\0" ) == s ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcat_s.c b/rocklibc/src/string/strcat_s.c deleted file mode 100644 index e356174..0000000 --- a/rocklibc/src/string/strcat_s.c +++ /dev/null @@ -1,103 +0,0 @@ -/* strcat_s( char *, rsize_t, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t strcat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 ) -{ - char * dest = s1; - const char * src = s2; - - if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && s1max != 0 ) - { - while ( *dest ) - { - if ( s1max-- == 0 || dest++ == s2 ) - { - goto runtime_constraint_violation; - } - } - - do - { - if ( s1max-- == 0 || dest == s2 || src == s1 ) - { - goto runtime_constraint_violation; - } - } while ( ( *dest++ = *src++ ) ); - - return 0; - } - -runtime_constraint_violation: - - if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX ) - { - s1[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xx\0xxxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( strcat_s( s, 10, abcde ) == 0 ); - TESTCASE( s[2] == 'a' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( s[7] == '\0' ); - TESTCASE( s[8] == 'x' ); - s[0] = '\0'; - TESTCASE( strcat_s( s, 10, abcdx ) == 0 ); - TESTCASE( s[4] == 'x' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strcat_s( s, 10, "\0" ) == 0 ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - - TESTCASE( strcat_s( s, 6, "" ) == 0 ); - TESTCASE( strcat_s( s, 5, "" ) != 0 ); - TESTCASE( strcat_s( s, 7, "x" ) == 0 ); - TESTCASE( s[5] == 'x' ); - TESTCASE( s[6] == '\0' ); - - /* Overlapping */ - TESTCASE( strcat_s( s, 7, s + 6 ) != 0 ); - s[3] = '\0'; - TESTCASE( strcat_s( s + 3, 4, s ) != 0 ); - - TESTCASE( HANDLER_CALLS == 3 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strchr.c b/rocklibc/src/string/strchr.c deleted file mode 100644 index 140a2cf..0000000 --- a/rocklibc/src/string/strchr.c +++ /dev/null @@ -1,41 +0,0 @@ -/* strchr( const char *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strchr( const char * s, int c ) -{ - do - { - if ( *s == ( char ) c ) - { - return ( char * ) s; - } - } while ( *s++ ); - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char abccd[] = "abccd"; - TESTCASE( strchr( abccd, 'x' ) == NULL ); - TESTCASE( strchr( abccd, 'a' ) == &abccd[0] ); - TESTCASE( strchr( abccd, 'd' ) == &abccd[4] ); - TESTCASE( strchr( abccd, '\0' ) == &abccd[5] ); - TESTCASE( strchr( abccd, 'c' ) == &abccd[2] ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcmp.c b/rocklibc/src/string/strcmp.c deleted file mode 100644 index ac17d22..0000000 --- a/rocklibc/src/string/strcmp.c +++ /dev/null @@ -1,42 +0,0 @@ -/* strcmp( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int strcmp( const char * s1, const char * s2 ) -{ - while ( ( *s1 ) && ( *s1 == *s2 ) ) - { - ++s1; - ++s2; - } - - return ( *( unsigned char * )s1 - * ( unsigned char * )s2 ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char cmpabcde[] = "abcde"; - char cmpabcd_[] = "abcd\xfc"; - char empty[] = ""; - TESTCASE( strcmp( abcde, cmpabcde ) == 0 ); - TESTCASE( strcmp( abcde, abcdx ) < 0 ); - TESTCASE( strcmp( abcdx, abcde ) > 0 ); - TESTCASE( strcmp( empty, abcde ) < 0 ); - TESTCASE( strcmp( abcde, empty ) > 0 ); - TESTCASE( strcmp( abcde, cmpabcd_ ) < 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcoll.c b/rocklibc/src/string/strcoll.c deleted file mode 100644 index 2b1cb5f..0000000 --- a/rocklibc/src/string/strcoll.c +++ /dev/null @@ -1,37 +0,0 @@ -/* strcoll( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -int strcoll( const char * s1, const char * s2 ) -{ - /* FIXME: This should access _PDCLIB_lc_collate. */ - return strcmp( s1, s2 ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char cmpabcde[] = "abcde"; - char empty[] = ""; - TESTCASE( strcmp( abcde, cmpabcde ) == 0 ); - TESTCASE( strcmp( abcde, abcdx ) < 0 ); - TESTCASE( strcmp( abcdx, abcde ) > 0 ); - TESTCASE( strcmp( empty, abcde ) < 0 ); - TESTCASE( strcmp( abcde, empty ) > 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcpy.c b/rocklibc/src/string/strcpy.c deleted file mode 100644 index 86059c2..0000000 --- a/rocklibc/src/string/strcpy.c +++ /dev/null @@ -1,42 +0,0 @@ -/* strcpy( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strcpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) -{ - char * rc = s1; - - while ( ( *s1++ = *s2++ ) ) - { - /* EMPTY */ - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxx"; - TESTCASE( strcpy( s, "" ) == s ); - TESTCASE( s[0] == '\0' ); - TESTCASE( s[1] == 'x' ); - TESTCASE( strcpy( s, abcde ) == s ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcpy_s.c b/rocklibc/src/string/strcpy_s.c deleted file mode 100644 index 4c89f82..0000000 --- a/rocklibc/src/string/strcpy_s.c +++ /dev/null @@ -1,89 +0,0 @@ -/* strcpy_s( char *, rsize_t, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t strcpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2 ) -{ - char * dest = s1; - const char * src = s2; - - if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && s1max != 0 ) - { - while ( s1max-- ) - { - if ( dest == s2 || src == s1 ) - { - goto runtime_constraint_violation; - } - - if ( ( *dest++ = *src++ ) == '\0' ) - { - return 0; - } - } - } - -runtime_constraint_violation: - - if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX ) - { - s1[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( strcpy_s( s, 6, "" ) == 0 ); - TESTCASE( s[0] == '\0' ); - TESTCASE( s[1] == 'x' ); - TESTCASE( strcpy_s( s, 6, abcde ) == 0 ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - - /* Overrun. */ - TESTCASE( strcpy_s( s, 6, "abcdef" ) != 0 ); - - /* Overlapping. */ - TESTCASE( strcpy_s( s, 3, s + 2 ) != 0 ); - TESTCASE( strcpy_s( s + 2, 3, s ) != 0 ); - - TESTCASE( HANDLER_CALLS == 3 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strcspn.c b/rocklibc/src/string/strcspn.c deleted file mode 100644 index 4a28931..0000000 --- a/rocklibc/src/string/strcspn.c +++ /dev/null @@ -1,54 +0,0 @@ -/* strcspn( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -size_t strcspn( const char * s1, const char * s2 ) -{ - size_t len = 0; - const char * p; - - while ( s1[len] ) - { - p = s2; - - while ( *p ) - { - if ( s1[len] == *p++ ) - { - return len; - } - } - - ++len; - } - - return len; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( strcspn( abcde, "x" ) == 5 ); - TESTCASE( strcspn( abcde, "xyz" ) == 5 ); - TESTCASE( strcspn( abcde, "zyx" ) == 5 ); - TESTCASE( strcspn( abcdx, "x" ) == 4 ); - TESTCASE( strcspn( abcdx, "xyz" ) == 4 ); - TESTCASE( strcspn( abcdx, "zyx" ) == 4 ); - TESTCASE( strcspn( abcde, "a" ) == 0 ); - TESTCASE( strcspn( abcde, "abc" ) == 0 ); - TESTCASE( strcspn( abcde, "cba" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strerror.c b/rocklibc/src/string/strerror.c deleted file mode 100644 index e35d450..0000000 --- a/rocklibc/src/string/strerror.c +++ /dev/null @@ -1,41 +0,0 @@ -/* strerror( int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -/* TODO: Doing this via a static array is not the way to do it. */ -char * strerror( int errnum ) -{ - if ( errnum >= _PDCLIB_ERRNO_MAX || errnum < 0 ) - { - return _PDCLIB_EUNKNOWN_TEXT; - } - else - { - return _PDCLIB_lc_messages->errno_texts[errnum]; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include - -int main( void ) -{ - TESTCASE( strerror( ERANGE ) != strerror( EDOM ) ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strerror_s.c b/rocklibc/src/string/strerror_s.c deleted file mode 100644 index 80adced..0000000 --- a/rocklibc/src/string/strerror_s.c +++ /dev/null @@ -1,69 +0,0 @@ -/* strerror_s( char *, rsize_t, errno_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include -#include - -#ifndef REGTEST - -#include - -errno_t strerror_s( char * s, rsize_t maxsize, errno_t errnum ) -{ - size_t len = strerrorlen_s( errnum ); - - if ( s == NULL || maxsize > RSIZE_MAX || maxsize == 0 ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - if ( len < maxsize ) - { - strcpy( s, strerror( errnum ) ); - } - else - { - strncpy( s, strerror( errnum ), maxsize - 1 ); - - if ( maxsize > 3 ) - { - strcpy( &s[ maxsize - 4 ], "..." ); - } - else - { - s[ maxsize - 1 ] = '\0'; - } - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include -#include - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[14]; - TESTCASE( strerror_s( s, 14, _PDCLIB_ERRNO_MAX ) == 0 ); - TESTCASE( strcmp( s, "unknown error" ) == 0 ); - TESTCASE( strerror_s( s, 13, _PDCLIB_ERRNO_MAX ) == 0 ); - TESTCASE( strcmp( s, "unknown e..." ) == 0 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strerrorlen_s.c b/rocklibc/src/string/strerrorlen_s.c deleted file mode 100644 index 4188c02..0000000 --- a/rocklibc/src/string/strerrorlen_s.c +++ /dev/null @@ -1,29 +0,0 @@ -/* strerrorlen_s( errno_t error ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include - -#ifndef REGTEST - -size_t strerrorlen_s( errno_t errnum ) -{ - return strlen( strerror( errnum ) ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strlen.c b/rocklibc/src/string/strlen.c deleted file mode 100644 index b97582b..0000000 --- a/rocklibc/src/string/strlen.c +++ /dev/null @@ -1,36 +0,0 @@ -/* strlen( const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -size_t strlen( const char * s ) -{ - size_t rc = 0; - - while ( s[rc] ) - { - ++rc; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( strlen( abcde ) == 5 ); - TESTCASE( strlen( "" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strncat.c b/rocklibc/src/string/strncat.c deleted file mode 100644 index c1bca7e..0000000 --- a/rocklibc/src/string/strncat.c +++ /dev/null @@ -1,64 +0,0 @@ -/* strncat( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) -{ - char * rc = s1; - - while ( *s1 ) - { - ++s1; - } - - while ( n && ( *s1++ = *s2++ ) ) - { - --n; - } - - if ( n == 0 ) - { - *s1 = '\0'; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xx\0xxxxxx"; - TESTCASE( strncat( s, abcde, 10 ) == s ); - TESTCASE( s[2] == 'a' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( s[7] == '\0' ); - TESTCASE( s[8] == 'x' ); - s[0] = '\0'; - TESTCASE( strncat( s, abcdx, 10 ) == s ); - TESTCASE( s[4] == 'x' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strncat( s, "\0", 10 ) == s ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( strncat( s, abcde, 0 ) == s ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( strncat( s, abcde, 3 ) == s ); - TESTCASE( s[5] == 'a' ); - TESTCASE( s[7] == 'c' ); - TESTCASE( s[8] == '\0' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strncat_s.c b/rocklibc/src/string/strncat_s.c deleted file mode 100644 index 898e1f9..0000000 --- a/rocklibc/src/string/strncat_s.c +++ /dev/null @@ -1,118 +0,0 @@ -/* strncat_s( char *, rsize_t, const char *, rsize_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t strncat_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n ) -{ - char * dest = s1; - const char * src = s2; - - if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && s1max != 0 ) - { - while ( *dest ) - { - if ( --s1max == 0 || dest++ == s2 ) - { - goto runtime_constraint_violation; - } - } - - do - { - if ( n-- == 0 ) - { - *dest = '\0'; - return 0; - } - - if ( s1max-- == 0 || dest == s2 || src == s1 ) - { - goto runtime_constraint_violation; - } - } while ( ( *dest++ = *src++ ) ); - - return 0; - } - -runtime_constraint_violation: - - if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX ) - { - s1[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xx\0xxxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( strncat_s( s, 10, abcde, 10 ) == 0 ); - TESTCASE( s[2] == 'a' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( s[7] == '\0' ); - TESTCASE( s[8] == 'x' ); - s[0] = '\0'; - TESTCASE( strncat_s( s, 10, abcdx, 10 ) == 0 ); - TESTCASE( s[4] == 'x' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strncat_s( s, 10, "\0", 10 ) == 0 ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( strncat_s( s, 10, abcde, 0 ) == 0 ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'e' ); - TESTCASE( strncat_s( s, 10, abcde, 3 ) == 0 ); - TESTCASE( s[5] == 'a' ); - TESTCASE( s[7] == 'c' ); - TESTCASE( s[8] == '\0' ); - - TESTCASE( strncat_s( s, 9, "", 0 ) == 0 ); - TESTCASE( strncat_s( s, 8, "", 0 ) != 0 ); - TESTCASE( strncat_s( s, 8, "x", 0 ) != 0 ); - TESTCASE( strncat_s( s, 9, "x", 0 ) == 0 ); - TESTCASE( strncat_s( s, 10, "x", 1 ) == 0 ); - TESTCASE( s[8] == 'x' ); - TESTCASE( s[9] == '\0' ); - - /* Overlapping */ - TESTCASE( strcat_s( s, 7, s + 6 ) != 0 ); - s[3] = '\0'; - TESTCASE( strcat_s( s + 3, 4, s ) != 0 ); - - TESTCASE( HANDLER_CALLS == 4 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strncmp.c b/rocklibc/src/string/strncmp.c deleted file mode 100644 index 6b35763..0000000 --- a/rocklibc/src/string/strncmp.c +++ /dev/null @@ -1,55 +0,0 @@ -/* strncmp( const char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -int strncmp( const char * s1, const char * s2, size_t n ) -{ - while ( n && *s1 && ( *s1 == *s2 ) ) - { - ++s1; - ++s2; - --n; - } - - if ( n == 0 ) - { - return 0; - } - else - { - return ( *( unsigned char * )s1 - * ( unsigned char * )s2 ); - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char cmpabcde[] = "abcde\0f"; - char cmpabcd_[] = "abcde\xfc"; - char empty[] = ""; - char x[] = "x"; - TESTCASE( strncmp( abcde, cmpabcde, 5 ) == 0 ); - TESTCASE( strncmp( abcde, cmpabcde, 10 ) == 0 ); - TESTCASE( strncmp( abcde, abcdx, 5 ) < 0 ); - TESTCASE( strncmp( abcdx, abcde, 5 ) > 0 ); - TESTCASE( strncmp( empty, abcde, 5 ) < 0 ); - TESTCASE( strncmp( abcde, empty, 5 ) > 0 ); - TESTCASE( strncmp( abcde, abcdx, 4 ) == 0 ); - TESTCASE( strncmp( abcde, x, 0 ) == 0 ); - TESTCASE( strncmp( abcde, x, 1 ) < 0 ); - TESTCASE( strncmp( abcde, cmpabcd_, 10 ) < 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strncpy.c b/rocklibc/src/string/strncpy.c deleted file mode 100644 index c69703c..0000000 --- a/rocklibc/src/string/strncpy.c +++ /dev/null @@ -1,59 +0,0 @@ -/* strncpy( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) -{ - char * rc = s1; - - while ( n && ( *s1++ = *s2++ ) ) - { - /* Cannot do "n--" in the conditional as size_t is unsigned and we have - to check it again for >0 in the next loop below, so we must not risk - underflow. - */ - --n; - } - - /* Checking against 1 as we missed the last --n in the loop above. */ - while ( n-- > 1 ) - { - *s1++ = '\0'; - } - - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxxxx"; - TESTCASE( strncpy( s, "", 1 ) == s ); - TESTCASE( s[0] == '\0' ); - TESTCASE( s[1] == 'x' ); - TESTCASE( strncpy( s, abcde, 6 ) == s ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'x' ); - TESTCASE( strncpy( s, abcde, 7 ) == s ); - TESTCASE( s[6] == '\0' ); - TESTCASE( strncpy( s, "xxxx", 3 ) == s ); - TESTCASE( s[0] == 'x' ); - TESTCASE( s[2] == 'x' ); - TESTCASE( s[3] == 'd' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strncpy_s.c b/rocklibc/src/string/strncpy_s.c deleted file mode 100644 index f9dc1ca..0000000 --- a/rocklibc/src/string/strncpy_s.c +++ /dev/null @@ -1,95 +0,0 @@ -/* strncpy_s( char *, rsize_t, const char *, rsize_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t strncpy_s( char * _PDCLIB_restrict s1, rsize_t s1max, const char * _PDCLIB_restrict s2, rsize_t n ) -{ - char * dest = s1; - const char * src = s2; - - if ( s1 != NULL && s2 != NULL && s1max <= RSIZE_MAX && n <= RSIZE_MAX && s1max != 0 ) - { - while ( s1max-- ) - { - if ( dest == s2 || src == s1 ) - { - goto runtime_constraint_violation; - } - - if ( n-- == 0 || ( *dest++ = *src++ ) == '\0' ) - { - return 0; - } - } - } - -runtime_constraint_violation: - - if ( s1 != NULL && s1max > 0 && s1max <= RSIZE_MAX ) - { - s1[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - -static int HANDLER_CALLS = 0; - -static void test_handler( const char * _PDCLIB_restrict msg, void * _PDCLIB_restrict ptr, errno_t error ) -{ - ++HANDLER_CALLS; -} - -#endif - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "xxxxxxx"; - set_constraint_handler_s( test_handler ); - - TESTCASE( strncpy_s( s, 8, "", 1 ) == 0 ); - TESTCASE( s[0] == '\0' ); - TESTCASE( s[1] == 'x' ); - TESTCASE( strncpy_s( s, 8, abcde, 6 ) == 0 ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[4] == 'e' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'x' ); - TESTCASE( strncpy_s( s, 8, abcde, 7 ) == 0 ); - /* Different from strncpy()! */ - TESTCASE( s[5] == '\0' ); - TESTCASE( s[6] == 'x' ); - TESTCASE( strncpy_s( s, 8, "xxxx", 3 ) == 0 ); - TESTCASE( s[0] == 'x' ); - TESTCASE( s[2] == 'x' ); - TESTCASE( s[3] == 'd' ); - - /* Overrun. */ - TESTCASE( strncpy_s( s, 8, "abcdefgh", 9 ) != 0 ); - TESTCASE( strncpy_s( s, 8, "abcdefgh", 9 ) != 0 ); - - TESTCASE( HANDLER_CALLS == 2 ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strpbrk.c b/rocklibc/src/string/strpbrk.c deleted file mode 100644 index f68e2e6..0000000 --- a/rocklibc/src/string/strpbrk.c +++ /dev/null @@ -1,53 +0,0 @@ -/* strpbrk( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strpbrk( const char * s1, const char * s2 ) -{ - const char * p1 = s1; - const char * p2; - - while ( *p1 ) - { - p2 = s2; - - while ( *p2 ) - { - if ( *p1 == *p2++ ) - { - return ( char * ) p1; - } - } - - ++p1; - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( strpbrk( abcde, "x" ) == NULL ); - TESTCASE( strpbrk( abcde, "xyz" ) == NULL ); - TESTCASE( strpbrk( abcdx, "x" ) == &abcdx[4] ); - TESTCASE( strpbrk( abcdx, "xyz" ) == &abcdx[4] ); - TESTCASE( strpbrk( abcdx, "zyx" ) == &abcdx[4] ); - TESTCASE( strpbrk( abcde, "a" ) == &abcde[0] ); - TESTCASE( strpbrk( abcde, "abc" ) == &abcde[0] ); - TESTCASE( strpbrk( abcde, "cba" ) == &abcde[0] ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strrchr.c b/rocklibc/src/string/strrchr.c deleted file mode 100644 index 5314d70..0000000 --- a/rocklibc/src/string/strrchr.c +++ /dev/null @@ -1,47 +0,0 @@ -/* strrchr( const char *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strrchr( const char * s, int c ) -{ - size_t i = 0; - - while ( s[i++] ) - { - /* EMPTY */ - } - - do - { - if ( s[--i] == ( char ) c ) - { - return ( char * ) s + i; - } - } while ( i ); - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char abccd[] = "abccd"; - TESTCASE( strrchr( abcde, '\0' ) == &abcde[5] ); - TESTCASE( strrchr( abcde, 'e' ) == &abcde[4] ); - TESTCASE( strrchr( abcde, 'a' ) == &abcde[0] ); - TESTCASE( strrchr( abccd, 'c' ) == &abccd[3] ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strspn.c b/rocklibc/src/string/strspn.c deleted file mode 100644 index f5fec24..0000000 --- a/rocklibc/src/string/strspn.c +++ /dev/null @@ -1,55 +0,0 @@ -/* strspn( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -size_t strspn( const char * s1, const char * s2 ) -{ - size_t len = 0; - const char * p; - - while ( s1[ len ] ) - { - p = s2; - - while ( *p ) - { - if ( s1[len] == *p ) - { - break; - } - - ++p; - } - - if ( ! *p ) - { - return len; - } - - ++len; - } - - return len; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( strspn( abcde, "abc" ) == 3 ); - TESTCASE( strspn( abcde, "b" ) == 0 ); - TESTCASE( strspn( abcde, abcde ) == 5 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strstr.c b/rocklibc/src/string/strstr.c deleted file mode 100644 index 1da7417..0000000 --- a/rocklibc/src/string/strstr.c +++ /dev/null @@ -1,56 +0,0 @@ -/* strstr( const char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * strstr( const char * s1, const char * s2 ) -{ - const char * p1 = s1; - const char * p2; - - while ( *s1 ) - { - p2 = s2; - - while ( *p2 && ( *p1 == *p2 ) ) - { - ++p1; - ++p2; - } - - if ( ! *p2 ) - { - return ( char * ) s1; - } - - ++s1; - p1 = s1; - } - - return NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "abcabcabcdabcde"; - TESTCASE( strstr( s, "x" ) == NULL ); - TESTCASE( strstr( s, "xyz" ) == NULL ); - TESTCASE( strstr( s, "a" ) == &s[0] ); - TESTCASE( strstr( s, "abc" ) == &s[0] ); - TESTCASE( strstr( s, "abcd" ) == &s[6] ); - TESTCASE( strstr( s, "abcde" ) == &s[10] ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strtok.c b/rocklibc/src/string/strtok.c deleted file mode 100644 index b405100..0000000 --- a/rocklibc/src/string/strtok.c +++ /dev/null @@ -1,64 +0,0 @@ -/* strtok( char *, const char * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#ifndef REGTEST -#define __STDC_WANT_LIB_EXT1__ 1 -#endif - -#include - -#ifndef REGTEST - -char * strtok( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 ) -{ - static char * tmp = NULL; - static rsize_t max; - - if ( s1 != NULL ) - { - /* new string */ - tmp = s1; - max = strlen( tmp ); - } - - return _PDCLIB_strtok( s1, &max, s2, &tmp ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "_a_bc__d_"; - TESTCASE( strtok( s, "_" ) == &s[1] ); - TESTCASE( s[1] == 'a' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( strtok( NULL, "_" ) == &s[3] ); - TESTCASE( s[3] == 'b' ); - TESTCASE( s[4] == 'c' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strtok( NULL, "_" ) == &s[7] ); - TESTCASE( s[6] == '_' ); - TESTCASE( s[7] == 'd' ); - TESTCASE( s[8] == '\0' ); - TESTCASE( strtok( NULL, "_" ) == NULL ); - strcpy( s, "ab_cd" ); - TESTCASE( strtok( s, "_" ) == &s[0] ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[1] == 'b' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( strtok( NULL, "_" ) == &s[3] ); - TESTCASE( s[3] == 'c' ); - TESTCASE( s[4] == 'd' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( strtok( NULL, "_" ) == NULL ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strtok_s.c b/rocklibc/src/string/strtok_s.c deleted file mode 100644 index e9fd9f4..0000000 --- a/rocklibc/src/string/strtok_s.c +++ /dev/null @@ -1,72 +0,0 @@ -/* strtok_s( char *, rsize_t *, const char *, char ** ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include - -#ifndef REGTEST - -char * strtok_s( char * _PDCLIB_restrict s1, rsize_t * _PDCLIB_restrict s1max, const char * _PDCLIB_restrict s2, char ** _PDCLIB_restrict ptr ) -{ - return _PDCLIB_strtok( s1, s1max, s2, ptr ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#if ! defined( REGTEST ) || defined( __STDC_LIB_EXT1__ ) - char s[] = "_a_bc__d_"; - char str1[] = "?a???b,,,#c"; - char str2[] = "\t \t"; - rsize_t max = sizeof( s ); - rsize_t max1 = sizeof( str1 ); - rsize_t max2 = sizeof( str2 ); - char * p; - char * ptr1; - char * ptr2; - - TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[1] ); - TESTCASE( s[1] == 'a' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] ); - TESTCASE( s[3] == 'b' ); - TESTCASE( s[4] == 'c' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[7] ); - TESTCASE( s[6] == '_' ); - TESTCASE( s[7] == 'd' ); - TESTCASE( s[8] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL ); - strcpy( s, "ab_cd" ); - max = strlen( s ); - TESTCASE( _PDCLIB_strtok( s, &max, "_", &p ) == &s[0] ); - TESTCASE( s[0] == 'a' ); - TESTCASE( s[1] == 'b' ); - TESTCASE( s[2] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == &s[3] ); - TESTCASE( s[3] == 'c' ); - TESTCASE( s[4] == 'd' ); - TESTCASE( s[5] == '\0' ); - TESTCASE( _PDCLIB_strtok( NULL, &max, "_", &p ) == NULL ); - - TESTCASE( _PDCLIB_strtok( str1, &max1, "?", &ptr1 ) == &str1[1] ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, ",", &ptr1 ) == &str1[3] ); - TESTCASE( _PDCLIB_strtok( str2, &max2, " \t", &ptr2 ) == NULL ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, "#,", &ptr1 ) == &str1[10] ); - TESTCASE( _PDCLIB_strtok( NULL, &max1, "?", &ptr1 ) == NULL ); -#else - /* Most libraries do not implement this function. */ - TESTCASE( NO_TESTDRIVER ); -#endif - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/string/strxfrm.c b/rocklibc/src/string/strxfrm.c deleted file mode 100644 index ac380e2..0000000 --- a/rocklibc/src/string/strxfrm.c +++ /dev/null @@ -1,54 +0,0 @@ -/* strxfrm( char *, const char *, size_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -size_t strxfrm( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n ) -{ - size_t len = strlen( s2 ); - - if ( len < n ) - { - /* Cannot use strncpy() here as the filling of s1 with '\0' is not part - of the spec. - */ - /* FIXME: This should access _PDCLIB_lc_collate. */ - while ( n-- && ( *s1++ = ( unsigned char )*s2++ ) ) - { - /* EMPTY */ - } - } - - return len; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - char s[] = "xxxxxxxxxxx"; - TESTCASE( strxfrm( NULL, "123456789012", 0 ) == 12 ); - TESTCASE( strxfrm( s, "123456789012", 12 ) == 12 ); - /* - The following test case is true in *this* implementation, but doesn't have to. - TESTCASE( s[0] == 'x' ); - */ - TESTCASE( strxfrm( s, "1234567890", 11 ) == 10 ); - TESTCASE( s[0] == '1' ); - TESTCASE( s[9] == '0' ); - TESTCASE( s[10] == '\0' ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/syscall.c b/rocklibc/src/syscall.c new file mode 100644 index 0000000..8c981bb --- /dev/null +++ b/rocklibc/src/syscall.c @@ -0,0 +1,37 @@ +#include + +static inline int syscall1(int num, uint32_t arg1) { + int ret; + asm volatile ( + "int $0x80" + : "=a"(ret) + : "a"(num), "b"(arg1) + : "memory" + ); + return ret; +} + +/* A generic wrapper for a system call with 3 arguments */ +static inline int syscall3(int num, uint32_t arg1, uint32_t arg2, uint32_t arg3) { + int ret; + asm volatile ( + "int $0x80" + : "=a"(ret) + : "a"(num), "b"(arg1), "c"(arg2), "d"(arg3) + : "memory" + ); + return ret; +} + +void exit(int status) { + syscall1(SYS_EXIT, (uint32_t)status); + while(1); +} + +int write(int fd, const void* buf, size_t cnt) { + return syscall3(SYS_WRITE, (uint32_t)fd, (uint32_t)buf, (uint32_t)cnt); +} + +int read(int fd, void* buf, size_t cnt) { + return syscall3(SYS_READ, (uint32_t)fd, (uint32_t)buf, (uint32_t)cnt); +} \ No newline at end of file diff --git a/rocklibc/src/time/asctime.c b/rocklibc/src/time/asctime.c deleted file mode 100644 index b591d57..0000000 --- a/rocklibc/src/time/asctime.c +++ /dev/null @@ -1,47 +0,0 @@ -/* asctime( const struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include - -char * asctime( const struct tm * timeptr ) -{ - static char rc[26]; - sprintf( rc, "%s %s%3d %.2d:%.2d:%.2d %d\n", - _PDCLIB_lc_time_C.day_name_abbr[ timeptr->tm_wday ], - _PDCLIB_lc_time_C.month_name_abbr[ timeptr->tm_mon ], - timeptr->tm_mday, - timeptr->tm_hour, - timeptr->tm_min, - timeptr->tm_sec, - timeptr->tm_year + 1900 ); - return rc; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - struct tm time; - MKTIME( time, 52, 3, 1, 16, 8, 73, 0, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sun Sep 16 01:03:52 1973\n" ) == 0 ); - MKTIME( time, 0, 0, 0, 1, 0, 0, 0, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sun Jan 1 00:00:00 1900\n" ) == 0 ); - MKTIME( time, 60, 59, 23, 31, 11, 8099, 6, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sat Dec 31 23:59:60 9999\n" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/asctime_s.c b/rocklibc/src/time/asctime_s.c deleted file mode 100644 index 4d71d07..0000000 --- a/rocklibc/src/time/asctime_s.c +++ /dev/null @@ -1,63 +0,0 @@ -/* asctime_s( char *, rsize_t, const struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -#include - -errno_t asctime_s( char * s, rsize_t maxsize, const struct tm * timeptr ) -{ - if ( s == NULL || timeptr == NULL || maxsize < 26 || maxsize > RSIZE_MAX || timeptr->tm_year < -1900 || timeptr->tm_year > 8099 /* TODO: || not normalized */ ) - { - if ( s != NULL && maxsize > 0 && maxsize <= RSIZE_MAX ) - { - s[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - sprintf( s, "%s %s %2d %.2d:%.2d:%.2d %4d\n", - _PDCLIB_lc_time_C.day_name_abbr[ timeptr->tm_wday ], - _PDCLIB_lc_time_C.month_name_abbr[ timeptr->tm_mon ], - timeptr->tm_mday, - timeptr->tm_hour, - timeptr->tm_min, - timeptr->tm_sec, - timeptr->tm_year + 1900 ); - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* TODO: Constraint handling */ - - struct tm time; - MKTIME( time, 52, 3, 1, 16, 8, 73, 0, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sun Sep 16 01:03:52 1973\n" ) == 0 ); - MKTIME( time, 0, 0, 0, 1, 0, 0, 0, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sun Jan 1 00:00:00 1900\n" ) == 0 ); - MKTIME( time, 60, 59, 23, 31, 11, 8099, 6, 0 ); - TESTCASE( strcmp( asctime( &time ), "Sat Dec 31 23:59:60 9999\n" ) == 0 ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/clock.c b/rocklibc/src/time/clock.c deleted file mode 100644 index adb7d2a..0000000 --- a/rocklibc/src/time/clock.c +++ /dev/null @@ -1,37 +0,0 @@ -/* clock( void ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "sys/times.h" - -clock_t clock( void ) -{ - struct tms buf; - - if ( times( &buf ) != ( clock_t )-1 ) - { - return buf.tms_utime + buf.tms_stime; - } - - return -1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/ctime.c b/rocklibc/src/time/ctime.c deleted file mode 100644 index 9073e47..0000000 --- a/rocklibc/src/time/ctime.c +++ /dev/null @@ -1,44 +0,0 @@ -/* ctime( const time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -char * ctime( const time_t * timer ) -{ - /* Section 4.12.3.2 of X3.159-1989 requires that - The ctime function converts the calendar time pointed to by timer - to local time in the form of a string. It is equivalent to - asctime(localtime(timer)) - */ - struct tm * tmp = localtime( timer ); - return tmp ? asctime( tmp ) : NULL; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* TODO: System Clock DST */ - time_t t; - - t = -2147483648l; - TESTCASE( strcmp( ctime( &t ), "Fri Dec 13 21:45:52 1901\n" ) == 0 ); - - t = 2147483647l; - TESTCASE( strcmp( ctime( &t ), "Tue Jan 19 04:14:07 2038\n" ) == 0 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/ctime_s.c b/rocklibc/src/time/ctime_s.c deleted file mode 100644 index 95e4db6..0000000 --- a/rocklibc/src/time/ctime_s.c +++ /dev/null @@ -1,61 +0,0 @@ -/* ctime( const time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -errno_t ctime_s( char * s, rsize_t maxsize, const time_t * timer ) -{ - struct tm tm; - - if ( s == NULL || timer == NULL || maxsize < 26 || maxsize > RSIZE_MAX ) - { - if ( s != NULL && maxsize > 0 && maxsize <= RSIZE_MAX ) - { - s[0] = '\0'; - } - - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return _PDCLIB_EINVAL; - } - - return asctime_s( s, maxsize, localtime_s( timer, &tm ) ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ -#ifndef REGTEST - /* TODO: System Clock DST */ - time_t t; - char s[27]; - - /* TODO: Constraint handling */ - - t = -2147483648l; - TESTCASE( ctime_s( s, 27, &t ) == 0 ); - TESTCASE( strcmp( s, "Fri Dec 13 21:45:52 1901\n" ) == 0 ); - - t = 2147483647l; - TESTCASE( ctime_s( s, 27, &t ) == 0 ); - TESTCASE( strcmp( s, "Tue Jan 19 04:14:07 2038\n" ) == 0 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/difftime.c b/rocklibc/src/time/difftime.c deleted file mode 100644 index dd2a11d..0000000 --- a/rocklibc/src/time/difftime.c +++ /dev/null @@ -1,70 +0,0 @@ -/* difftime( time_t, time_t ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -double difftime( time_t time1, time_t time0 ) -{ - /* If we want to avoid rounding errors and overflows, we need to be - careful with the exact type of time_t being unknown to us. - The code below is based on tzcode's difftime.c, which is in the - public domain, so clarified as of 1996-06-05 by Arthur David Olson. - */ - - /* If double is large enough, simply covert and substract - (assuming that the larger type has more precision). - */ - if ( sizeof( time_t ) < sizeof( double ) ) - { - return ( double )time1 - ( double )time0; - } - - /* The difference of two unsigned values cannot overflow if the - minuend is greater or equal to the subtrahend. - */ - if ( ! _PDCLIB_TYPE_SIGNED( time_t ) ) - { - return ( time1 >= time0 ) ? ( double )( time1 - time0 ) : -( double )( time0 - time1 ); - } - - /* Use uintmax_t if wide enough. */ - if ( sizeof( time_t ) <= sizeof( _PDCLIB_uintmax_t ) ) - { - _PDCLIB_uintmax_t t1 = time1, t0 = time0; - return ( time1 >= time0 ) ? t1 - t0 : -( double )( t0 - t1 ); - } - - /* If both times have the same sign, their difference cannot overflow. */ - if ( ( time1 < 0 ) == ( time0 < 0 ) ) - { - return time1 - time0; - } - - /* The times have opposite signs, and uintmax_t is too narrow. - This suffers from double rounding; attempt to lessen that - by using long double temporaries. - */ - { - long double t1 = time1, t0 = time0; - return t1 - t0; - } -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/gmtime.c b/rocklibc/src/time/gmtime.c deleted file mode 100644 index 159f455..0000000 --- a/rocklibc/src/time/gmtime.c +++ /dev/null @@ -1,55 +0,0 @@ -/* gmtime( const time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -struct tm * gmtime( const time_t * timer ) -{ - _PDCLIB_gmtcheck(); - return _PDCLIB_gmtsub( &_PDCLIB_gmtmem, timer, 0, &_PDCLIB_tm ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - time_t t; - struct tm * time; - - t = -2147483648l; - time = gmtime( &t ); - TESTCASE( time->tm_sec == 52 ); - TESTCASE( time->tm_min == 45 ); - TESTCASE( time->tm_hour == 20 ); - TESTCASE( time->tm_mday == 13 ); - TESTCASE( time->tm_mon == 11 ); - TESTCASE( time->tm_year == 1 ); - TESTCASE( time->tm_wday == 5 ); - TESTCASE( time->tm_yday == 346 ); - - t = 2147483647l; - time = gmtime( &t ); - TESTCASE( time->tm_sec == 7 ); - TESTCASE( time->tm_min == 14 ); - TESTCASE( time->tm_hour == 3 ); - TESTCASE( time->tm_mday == 19 ); - TESTCASE( time->tm_mon == 0 ); - TESTCASE( time->tm_year == 138 ); - TESTCASE( time->tm_wday == 2 ); - TESTCASE( time->tm_yday == 18 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/gmtime_s.c b/rocklibc/src/time/gmtime_s.c deleted file mode 100644 index 698477d..0000000 --- a/rocklibc/src/time/gmtime_s.c +++ /dev/null @@ -1,68 +0,0 @@ -/* gmtime_s( const time_t *, struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -struct tm * gmtime_s( const time_t * _PDCLIB_restrict timer, struct tm * _PDCLIB_restrict result ) -{ - if ( timer == NULL || result == NULL ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - _PDCLIB_gmtcheck(); - return _PDCLIB_gmtsub( &_PDCLIB_gmtmem, timer, 0, result ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - time_t t; - struct tm time; - - /* TODO: Constraint handling */ - - t = -2147483648l; - TESTCASE( gmtime_s( &t, &time ) != NULL ); - TESTCASE( time.tm_sec == 52 ); - TESTCASE( time.tm_min == 45 ); - TESTCASE( time.tm_hour == 20 ); - TESTCASE( time.tm_mday == 13 ); - TESTCASE( time.tm_mon == 11 ); - TESTCASE( time.tm_year == 1 ); - TESTCASE( time.tm_wday == 5 ); - TESTCASE( time.tm_yday == 346 ); - - t = 2147483647l; - TESTCASE( gmtime_s( &t, &time ) != NULL ); - TESTCASE( time.tm_sec == 7 ); - TESTCASE( time.tm_min == 14 ); - TESTCASE( time.tm_hour == 3 ); - TESTCASE( time.tm_mday == 19 ); - TESTCASE( time.tm_mon == 0 ); - TESTCASE( time.tm_year == 138 ); - TESTCASE( time.tm_wday == 2 ); - TESTCASE( time.tm_yday == 18 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/localtime.c b/rocklibc/src/time/localtime.c deleted file mode 100644 index 02740d2..0000000 --- a/rocklibc/src/time/localtime.c +++ /dev/null @@ -1,56 +0,0 @@ -/* localtime( const time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -struct tm * localtime( const time_t * timer ) -{ - return _PDCLIB_localtime_tzset( timer, &_PDCLIB_tm, true ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - /* TODO: System Clock DST */ - - time_t t; - struct tm * time; - - t = -2147483648l; - time = localtime( &t ); - TESTCASE( time->tm_sec == 52 ); - TESTCASE( time->tm_min == 45 ); - TESTCASE( time->tm_hour == 21 ); - TESTCASE( time->tm_mday == 13 ); - TESTCASE( time->tm_mon == 11 ); - TESTCASE( time->tm_year == 1 ); - TESTCASE( time->tm_wday == 5 ); - TESTCASE( time->tm_yday == 346 ); - - t = 2147483647l; - time = localtime( &t ); - TESTCASE( time->tm_sec == 7 ); - TESTCASE( time->tm_min == 14 ); - TESTCASE( time->tm_hour == 4 ); - TESTCASE( time->tm_mday == 19 ); - TESTCASE( time->tm_mon == 0 ); - TESTCASE( time->tm_year == 138 ); - TESTCASE( time->tm_wday == 2 ); - TESTCASE( time->tm_yday == 18 ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/localtime_s.c b/rocklibc/src/time/localtime_s.c deleted file mode 100644 index bc88150..0000000 --- a/rocklibc/src/time/localtime_s.c +++ /dev/null @@ -1,67 +0,0 @@ -/* localtime_s( const time_t *, struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -struct tm * localtime_s( const time_t * _PDCLIB_restrict timer, struct tm * _PDCLIB_restrict result ) -{ - if ( timer == NULL || result == NULL ) - { - _PDCLIB_constraint_handler( _PDCLIB_CONSTRAINT_VIOLATION( _PDCLIB_EINVAL ) ); - return NULL; - } - - return _PDCLIB_localtime_tzset( timer, result, true ); -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ -#ifndef REGTEST - time_t t; - struct tm time; - - /* TODO: Constraint handling, System Clock DST */ - - t = -2147483648l; - TESTCASE( localtime_s( &t, &time ) != NULL ); - TESTCASE( time.tm_sec == 52 ); - TESTCASE( time.tm_min == 45 ); - TESTCASE( time.tm_hour == 21 ); - TESTCASE( time.tm_mday == 13 ); - TESTCASE( time.tm_mon == 11 ); - TESTCASE( time.tm_year == 1 ); - TESTCASE( time.tm_wday == 5 ); - TESTCASE( time.tm_yday == 346 ); - - t = 2147483647l; - TESTCASE( localtime_s( &t, &time ) != NULL ); - TESTCASE( time.tm_sec == 7 ); - TESTCASE( time.tm_min == 14 ); - TESTCASE( time.tm_hour == 4 ); - TESTCASE( time.tm_mday == 19 ); - TESTCASE( time.tm_mon == 0 ); - TESTCASE( time.tm_year == 138 ); - TESTCASE( time.tm_wday == 2 ); - TESTCASE( time.tm_yday == 18 ); -#endif - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/mktime.c b/rocklibc/src/time/mktime.c deleted file mode 100644 index 37a6c85..0000000 --- a/rocklibc/src/time/mktime.c +++ /dev/null @@ -1,53 +0,0 @@ -/* mktime( struct tm * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_tzcode.h" - -#ifndef __STDC_NO_THREADS__ -#include -extern mtx_t _PDCLIB_time_mtx; -#endif - -time_t mktime( struct tm * timeptr ) -{ - time_t t; - _PDCLIB_LOCK( _PDCLIB_time_mtx ); - _PDCLIB_tzset_unlocked(); - t = _PDCLIB_mktime_tzname( &_PDCLIB_lclmem, timeptr, true ); - _PDCLIB_UNLOCK( _PDCLIB_time_mtx ); - return t; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -#include - -int main( void ) -{ - /* System Clock DST */ - struct tm time; - time_t t; - - MKTIME( time, 52, 45, 21, 13, 11, 1, 0, 0 ); - t = mktime( &time ); - TESTCASE( t == -2147483648l ); - - MKTIME( time, 7, 14, 4, 19, 0, 138, 0, 0 ); - t = mktime( &time ); - TESTCASE( t == 2147483647l ); - - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/strftime.c b/rocklibc/src/time/strftime.c deleted file mode 100644 index 6968907..0000000 --- a/rocklibc/src/time/strftime.c +++ /dev/null @@ -1,1788 +0,0 @@ -/* strftime( char * restrict, size_t, const char * restrict, const struct tm * restrict ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include -#include -#include -#include -#include - -#ifndef REGTEST - -/* TODO: Alternative representations / numerals not supported. Multibyte support missing. */ - -/* This implementation's code is highly repetitive, but I did not really - care for putting it into a number of macros / helper functions. -*/ - -enum wstart_t -{ - E_SUNDAY = 0, - E_MONDAY = 1, - E_ISO_WEEK, - E_ISO_YEAR -}; - -#include - -static int week_calc( const struct tm * timeptr, int wtype ) -{ - int wday; - int bias; - int week; - - if ( wtype <= E_MONDAY ) - { - /* Simple -- first week starting with E_SUNDAY / E_MONDAY, - days before that are week 0. - */ - div_t weeks = div( timeptr->tm_yday, 7 ); - wday = ( timeptr->tm_wday + 7 - wtype ) % 7; - - if ( weeks.rem >= wday ) - { - ++weeks.quot; - } - - return weeks.quot; - } - - /* calculating ISO week; relies on Sunday == 7 */ - wday = timeptr->tm_wday; - - if ( wday == 0 ) - { - wday = 7; - } - - /* https://en.wikipedia.org/wiki/ISO_week_date */ - week = ( timeptr->tm_yday - wday + 11 ) / 7; - - if ( week == 53 ) - { - /* date *may* belong to the *next* year, if: - * it is 31.12. and Monday - Wednesday - * it is 30.12. and Monday - Tuesday - * it is 29.12. and Monday - We can safely assume December... - */ - if ( ( timeptr->tm_yday - wday - _PDCLIB_is_leap( timeptr->tm_year ) ) > 360 ) - { - week = 1; - } - } - else if ( week == 0 ) - { - /* date *does* belong to *previous* year, - i.e. has week 52 *unless*... - * current year started on a Friday, or - * previous year is leap and this year - started on a Saturday. - */ - int firstday = timeptr->tm_wday - ( timeptr->tm_yday % 7 ); - - if ( firstday < 0 ) - { - firstday += 7; - } - - if ( ( firstday == 5 ) || ( _PDCLIB_is_leap( timeptr->tm_year - 1 ) && firstday == 6 ) ) - { - week = 53; - } - else - { - week = 52; - } - } - - if ( wtype == E_ISO_WEEK ) - { - return week; - } - - /* E_ISO_YEAR -- determine the "week-based year" */ - bias = 0; - - if ( week >= 52 && timeptr->tm_mon == 0 ) - { - --bias; - } - else if ( week == 1 && timeptr->tm_mon == 11 ) - { - ++bias; - } - - return timeptr->tm_year + 1900 + bias; -} - -/* Assuming presence of s, rc, maxsize. - Checks index for valid range, target buffer for sufficient remaining - capacity, and copies the locale-specific string (or "?" if index out - of range). Returns with zero if buffer capacity insufficient. -*/ -#define SPRINTSTR( array, index, max ) \ - { \ - int ind = (index); \ - const char * str = "?"; \ - size_t len; \ - if ( ind >= 0 && ind <= max ) \ - { \ - str = array[ ind ]; \ - } \ - len = strlen( str ); \ - if ( rc < ( maxsize - len ) ) \ - { \ - strcpy( s + rc, str ); \ - rc += len; \ - } \ - else \ - { \ - return 0; \ - } \ - } - -#define SPRINTREC( format ) \ - { \ - size_t count = strftime( s + rc, maxsize - rc, format, timeptr ); \ - if ( count == 0 ) \ - { \ - return 0; \ - } \ - else \ - { \ - rc += count; \ - } \ - } - -size_t strftime( char * _PDCLIB_restrict s, size_t maxsize, const char * _PDCLIB_restrict format, const struct tm * _PDCLIB_restrict timeptr ) -{ - size_t rc = 0; - - while ( rc < maxsize ) - { - if ( *format != '%' ) - { - if ( ( s[rc] = *format++ ) == '\0' ) - { - return rc; - } - else - { - ++rc; - } - } - else - { - /* char flag = 0; */ - switch ( *++format ) - { - case 'E': - case 'O': - /* flag = *format++; */ - break; - - default: - /* EMPTY */ - break; - } - - switch ( *format++ ) - { - case 'a': - { - /* tm_wday abbreviated */ - SPRINTSTR( _PDCLIB_lc_time->day_name_abbr, timeptr->tm_wday, 6 ); - break; - } - - case 'A': - { - /* tm_wday full */ - SPRINTSTR( _PDCLIB_lc_time->day_name_full, timeptr->tm_wday, 6 ); - break; - } - - case 'b': - case 'h': - { - /* tm_mon abbreviated */ - SPRINTSTR( _PDCLIB_lc_time->month_name_abbr, timeptr->tm_mon, 11 ); - break; - } - - case 'B': - { - /* tm_mon full */ - SPRINTSTR( _PDCLIB_lc_time->month_name_full, timeptr->tm_mon, 11 ); - break; - } - - case 'c': - { - /* locale's date / time representation, %a %b %e %T %Y for C locale */ - /* 'E' for locale's alternative representation */ - SPRINTREC( _PDCLIB_lc_time->date_time_format ); - break; - } - - case 'C': - { - /* tm_year divided by 100, truncated to decimal (00-99) */ - /* 'E' for base year (period) in locale's alternative representation */ - if ( rc < ( maxsize - 2 ) ) - { - div_t period = div( ( ( timeptr->tm_year + 1900 ) / 100 ), 10 ); - s[rc++] = '0' + period.quot; - s[rc++] = '0' + period.rem; - } - else - { - return 0; - } - - break; - } - - case 'd': - { - /* tm_mday as decimal (01-31) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t day = div( timeptr->tm_mday, 10 ); - s[rc++] = '0' + day.quot; - s[rc++] = '0' + day.rem; - } - else - { - return 0; - } - - break; - } - - case 'D': - { - /* %m/%d/%y */ - SPRINTREC( "%m/%d/%y" ); - break; - } - - case 'e': - { - /* tm_mday as decimal ( 1-31) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t day = div( timeptr->tm_mday, 10 ); - s[rc++] = ( day.quot > 0 ) ? '0' + day.quot : ' '; - s[rc++] = '0' + day.rem; - } - else - { - return 0; - } - - break; - } - - case 'F': - { - /* %Y-%m-%d */ - SPRINTREC( "%Y-%m-%d" ); - break; - } - - case 'g': - { - /* last 2 digits of the week-based year as decimal (00-99) */ - if ( rc < ( maxsize - 2 ) ) - { - div_t year = div( week_calc( timeptr, E_ISO_YEAR ) % 100, 10 ); - s[rc++] = '0' + year.quot; - s[rc++] = '0' + year.rem; - } - else - { - return 0; - } - - break; - } - - case 'G': - { - /* week-based year as decimal (e.g. 1997) */ - if ( rc < ( maxsize - 4 ) ) - { - int year = week_calc( timeptr, E_ISO_YEAR ); - int i; - - for ( i = 3; i >= 0; --i ) - { - div_t digit = div( year, 10 ); - s[ rc + i ] = '0' + digit.rem; - year = digit.quot; - } - - rc += 4; - } - else - { - return 0; - } - - break; - } - - case 'H': - { - /* tm_hour as 24h decimal (00-23) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t hour = div( timeptr->tm_hour, 10 ); - s[rc++] = '0' + hour.quot; - s[rc++] = '0' + hour.rem; - } - else - { - return 0; - } - - break; - } - - case 'I': - { - /* tm_hour as 12h decimal (01-12) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t hour = div( ( timeptr->tm_hour + 11 ) % 12 + 1, 10 ); - s[rc++] = '0' + hour.quot; - s[rc++] = '0' + hour.rem; - } - else - { - return 0; - } - - break; - } - - case 'j': - { - /* tm_yday as decimal (001-366) */ - if ( rc < ( maxsize - 3 ) ) - { - div_t yday = div( timeptr->tm_yday + 1, 100 ); - s[rc++] = '0' + yday.quot; - s[rc++] = '0' + yday.rem / 10; - s[rc++] = '0' + yday.rem % 10; - } - else - { - return 0; - } - - break; - } - - case 'm': - { - /* tm_mon as decimal (01-12) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t mon = div( timeptr->tm_mon + 1, 10 ); - s[rc++] = '0' + mon.quot; - s[rc++] = '0' + mon.rem; - } - else - { - return 0; - } - - break; - } - - case 'M': - { - /* tm_min as decimal (00-59) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t min = div( timeptr->tm_min, 10 ); - s[rc++] = '0' + min.quot; - s[rc++] = '0' + min.rem; - } - else - { - return 0; - } - - break; - } - - case 'n': - { - /* newline */ - s[rc++] = '\n'; - break; - } - - case 'p': - { - /* tm_hour locale's AM/PM designations */ - SPRINTSTR( _PDCLIB_lc_time->am_pm, timeptr->tm_hour > 11, 1 ); - break; - } - - case 'r': - { - /* tm_hour / tm_min / tm_sec as locale's 12-hour clock time, %I:%M:%S %p for C locale */ - SPRINTREC( _PDCLIB_lc_time->time_format_12h ); - break; - } - - case 'R': - { - /* %H:%M */ - SPRINTREC( "%H:%M" ); - break; - } - - case 'S': - { - /* tm_sec as decimal (00-60) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t sec = div( timeptr->tm_sec, 10 ); - s[rc++] = '0' + sec.quot; - s[rc++] = '0' + sec.rem; - } - else - { - return 0; - } - - break; - } - - case 't': - { - /* tabulator */ - s[rc++] = '\t'; - break; - } - - case 'T': - { - /* %H:%M:%S */ - SPRINTREC( "%H:%M:%S" ); - break; - } - - case 'u': - { - /* tm_wday as decimal (1-7) with Monday == 1 */ - /* 'O' for locale's alternative numeric symbols */ - s[rc++] = ( timeptr->tm_wday == 0 ) ? '7' : '0' + timeptr->tm_wday; - break; - } - - case 'U': - { - /* week number of the year (first Sunday as the first day of week 1) as decimal (00-53) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t week = div( week_calc( timeptr, E_SUNDAY ), 10 ); - s[rc++] = '0' + week.quot; - s[rc++] = '0' + week.rem; - } - else - { - return 0; - } - - break; - } - - case 'V': - { - /* ISO week number as decimal (01-53) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t week = div( week_calc( timeptr, E_ISO_WEEK ), 10 ); - s[rc++] = '0' + week.quot; - s[rc++] = '0' + week.rem; - } - else - { - return 0; - } - - break; - } - - case 'w': - { - /* tm_wday as decimal number (0-6) with Sunday == 0 */ - /* 'O' for locale's alternative numeric symbols */ - s[rc++] = '0' + timeptr->tm_wday; - break; - } - - case 'W': - { - /* week number of the year (first Monday as the first day of week 1) as decimal (00-53) */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t week = div( week_calc( timeptr, E_MONDAY ), 10 ); - s[rc++] = '0' + week.quot; - s[rc++] = '0' + week.rem; - } - else - { - return 0; - } - - break; - } - - case 'x': - { - /* locale's date representation, %m/%d/%y for C locale */ - /* 'E' for locale's alternative representation */ - SPRINTREC( _PDCLIB_lc_time->date_format ); - break; - } - - case 'X': - { - /* locale's time representation, %T for C locale */ - /* 'E' for locale's alternative representation */ - SPRINTREC( _PDCLIB_lc_time->time_format ); - break; - } - - case 'y': - { - /* last 2 digits of tm_year as decimal (00-99) */ - /* 'E' for offset from %EC (year only) in locale's alternative representation */ - /* 'O' for locale's alternative numeric symbols */ - if ( rc < ( maxsize - 2 ) ) - { - div_t year = div( ( timeptr->tm_year % 100 ), 10 ); - s[rc++] = '0' + year.quot; - s[rc++] = '0' + year.rem; - } - else - { - return 0; - } - - break; - } - - case 'Y': - { - /* tm_year as decimal (e.g. 1997) */ - /* 'E' for locale's alternative representation */ - if ( rc < ( maxsize - 4 ) ) - { - int year = timeptr->tm_year + 1900; - int i; - - for ( i = 3; i >= 0; --i ) - { - div_t digit = div( year, 10 ); - s[ rc + i ] = '0' + digit.rem; - year = digit.quot; - } - - rc += 4; - } - else - { - return 0; - } - - break; - } - - case 'z': - { - /* tm_isdst / UTC offset in ISO8601 format (e.g. -0430 meaning 4 hours 30 minutes behind Greenwich), or no characters */ - /* TODO: 'z' */ - break; - } - - case 'Z': - { - /* tm_isdst / locale's time zone name or abbreviation, or no characters */ - /* TODO: 'Z' */ - break; - } - - case '%': - { - /* '%' character */ - s[rc++] = '%'; - break; - } - } - } - } - - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -/* Test data generated by reference mktime() / strftime(), listing: - * tm_year - * tm_wday - * tm_yday - * '%U' result - * '%V' result - * '%W' result -*/ -int data[1020][6] = -{ - { 70, 4, 0, 0, 1, 0 }, - { 70, 5, 1, 0, 1, 0 }, - { 70, 6, 2, 0, 1, 0 }, - { 70, 0, 3, 1, 1, 0 }, - { 70, 1, 4, 1, 2, 1 }, - { 70, 2, 5, 1, 2, 1 }, - { 70, 3, 6, 1, 2, 1 }, - { 70, 4, 357, 51, 52, 51 }, - { 70, 5, 358, 51, 52, 51 }, - { 70, 6, 359, 51, 52, 51 }, - { 70, 0, 360, 52, 52, 51 }, - { 70, 1, 361, 52, 53, 52 }, - { 70, 2, 362, 52, 53, 52 }, - { 70, 3, 363, 52, 53, 52 }, - { 70, 4, 364, 52, 53, 52 }, - { 71, 5, 0, 0, 53, 0 }, - { 71, 6, 1, 0, 53, 0 }, - { 71, 0, 2, 1, 53, 0 }, - { 71, 1, 3, 1, 1, 1 }, - { 71, 2, 4, 1, 1, 1 }, - { 71, 3, 5, 1, 1, 1 }, - { 71, 4, 6, 1, 1, 1 }, - { 71, 5, 357, 51, 51, 51 }, - { 71, 6, 358, 51, 51, 51 }, - { 71, 0, 359, 52, 51, 51 }, - { 71, 1, 360, 52, 52, 52 }, - { 71, 2, 361, 52, 52, 52 }, - { 71, 3, 362, 52, 52, 52 }, - { 71, 4, 363, 52, 52, 52 }, - { 71, 5, 364, 52, 52, 52 }, - { 72, 6, 0, 0, 52, 0 }, - { 72, 0, 1, 1, 52, 0 }, - { 72, 1, 2, 1, 1, 1 }, - { 72, 2, 3, 1, 1, 1 }, - { 72, 3, 4, 1, 1, 1 }, - { 72, 4, 5, 1, 1, 1 }, - { 72, 5, 6, 1, 1, 1 }, - { 72, 0, 358, 52, 51, 51 }, - { 72, 1, 359, 52, 52, 52 }, - { 72, 2, 360, 52, 52, 52 }, - { 72, 3, 361, 52, 52, 52 }, - { 72, 4, 362, 52, 52, 52 }, - { 72, 5, 363, 52, 52, 52 }, - { 72, 6, 364, 52, 52, 52 }, - { 72, 0, 365, 53, 52, 52 }, - { 73, 1, 0, 0, 1, 1 }, - { 73, 2, 1, 0, 1, 1 }, - { 73, 3, 2, 0, 1, 1 }, - { 73, 4, 3, 0, 1, 1 }, - { 73, 5, 4, 0, 1, 1 }, - { 73, 6, 5, 0, 1, 1 }, - { 73, 0, 6, 1, 1, 1 }, - { 73, 1, 357, 51, 52, 52 }, - { 73, 2, 358, 51, 52, 52 }, - { 73, 3, 359, 51, 52, 52 }, - { 73, 4, 360, 51, 52, 52 }, - { 73, 5, 361, 51, 52, 52 }, - { 73, 6, 362, 51, 52, 52 }, - { 73, 0, 363, 52, 52, 52 }, - { 73, 1, 364, 52, 1, 53 }, - { 74, 2, 0, 0, 1, 0 }, - { 74, 3, 1, 0, 1, 0 }, - { 74, 4, 2, 0, 1, 0 }, - { 74, 5, 3, 0, 1, 0 }, - { 74, 6, 4, 0, 1, 0 }, - { 74, 0, 5, 1, 1, 0 }, - { 74, 1, 6, 1, 2, 1 }, - { 74, 2, 357, 51, 52, 51 }, - { 74, 3, 358, 51, 52, 51 }, - { 74, 4, 359, 51, 52, 51 }, - { 74, 5, 360, 51, 52, 51 }, - { 74, 6, 361, 51, 52, 51 }, - { 74, 0, 362, 52, 52, 51 }, - { 74, 1, 363, 52, 1, 52 }, - { 74, 2, 364, 52, 1, 52 }, - { 75, 3, 0, 0, 1, 0 }, - { 75, 4, 1, 0, 1, 0 }, - { 75, 5, 2, 0, 1, 0 }, - { 75, 6, 3, 0, 1, 0 }, - { 75, 0, 4, 1, 1, 0 }, - { 75, 1, 5, 1, 2, 1 }, - { 75, 2, 6, 1, 2, 1 }, - { 75, 3, 357, 51, 52, 51 }, - { 75, 4, 358, 51, 52, 51 }, - { 75, 5, 359, 51, 52, 51 }, - { 75, 6, 360, 51, 52, 51 }, - { 75, 0, 361, 52, 52, 51 }, - { 75, 1, 362, 52, 1, 52 }, - { 75, 2, 363, 52, 1, 52 }, - { 75, 3, 364, 52, 1, 52 }, - { 76, 4, 0, 0, 1, 0 }, - { 76, 5, 1, 0, 1, 0 }, - { 76, 6, 2, 0, 1, 0 }, - { 76, 0, 3, 1, 1, 0 }, - { 76, 1, 4, 1, 2, 1 }, - { 76, 2, 5, 1, 2, 1 }, - { 76, 3, 6, 1, 2, 1 }, - { 76, 5, 358, 51, 52, 51 }, - { 76, 6, 359, 51, 52, 51 }, - { 76, 0, 360, 52, 52, 51 }, - { 76, 1, 361, 52, 53, 52 }, - { 76, 2, 362, 52, 53, 52 }, - { 76, 3, 363, 52, 53, 52 }, - { 76, 4, 364, 52, 53, 52 }, - { 76, 5, 365, 52, 53, 52 }, - { 77, 6, 0, 0, 53, 0 }, - { 77, 0, 1, 1, 53, 0 }, - { 77, 1, 2, 1, 1, 1 }, - { 77, 2, 3, 1, 1, 1 }, - { 77, 3, 4, 1, 1, 1 }, - { 77, 4, 5, 1, 1, 1 }, - { 77, 5, 6, 1, 1, 1 }, - { 77, 6, 357, 51, 51, 51 }, - { 77, 0, 358, 52, 51, 51 }, - { 77, 1, 359, 52, 52, 52 }, - { 77, 2, 360, 52, 52, 52 }, - { 77, 3, 361, 52, 52, 52 }, - { 77, 4, 362, 52, 52, 52 }, - { 77, 5, 363, 52, 52, 52 }, - { 77, 6, 364, 52, 52, 52 }, - { 78, 0, 0, 1, 52, 0 }, - { 78, 1, 1, 1, 1, 1 }, - { 78, 2, 2, 1, 1, 1 }, - { 78, 3, 3, 1, 1, 1 }, - { 78, 4, 4, 1, 1, 1 }, - { 78, 5, 5, 1, 1, 1 }, - { 78, 6, 6, 1, 1, 1 }, - { 78, 0, 357, 52, 51, 51 }, - { 78, 1, 358, 52, 52, 52 }, - { 78, 2, 359, 52, 52, 52 }, - { 78, 3, 360, 52, 52, 52 }, - { 78, 4, 361, 52, 52, 52 }, - { 78, 5, 362, 52, 52, 52 }, - { 78, 6, 363, 52, 52, 52 }, - { 78, 0, 364, 53, 52, 52 }, - { 79, 1, 0, 0, 1, 1 }, - { 79, 2, 1, 0, 1, 1 }, - { 79, 3, 2, 0, 1, 1 }, - { 79, 4, 3, 0, 1, 1 }, - { 79, 5, 4, 0, 1, 1 }, - { 79, 6, 5, 0, 1, 1 }, - { 79, 0, 6, 1, 1, 1 }, - { 79, 1, 357, 51, 52, 52 }, - { 79, 2, 358, 51, 52, 52 }, - { 79, 3, 359, 51, 52, 52 }, - { 79, 4, 360, 51, 52, 52 }, - { 79, 5, 361, 51, 52, 52 }, - { 79, 6, 362, 51, 52, 52 }, - { 79, 0, 363, 52, 52, 52 }, - { 79, 1, 364, 52, 1, 53 }, - { 80, 2, 0, 0, 1, 0 }, - { 80, 3, 1, 0, 1, 0 }, - { 80, 4, 2, 0, 1, 0 }, - { 80, 5, 3, 0, 1, 0 }, - { 80, 6, 4, 0, 1, 0 }, - { 80, 0, 5, 1, 1, 0 }, - { 80, 1, 6, 1, 2, 1 }, - { 80, 3, 358, 51, 52, 51 }, - { 80, 4, 359, 51, 52, 51 }, - { 80, 5, 360, 51, 52, 51 }, - { 80, 6, 361, 51, 52, 51 }, - { 80, 0, 362, 52, 52, 51 }, - { 80, 1, 363, 52, 1, 52 }, - { 80, 2, 364, 52, 1, 52 }, - { 80, 3, 365, 52, 1, 52 }, - { 81, 4, 0, 0, 1, 0 }, - { 81, 5, 1, 0, 1, 0 }, - { 81, 6, 2, 0, 1, 0 }, - { 81, 0, 3, 1, 1, 0 }, - { 81, 1, 4, 1, 2, 1 }, - { 81, 2, 5, 1, 2, 1 }, - { 81, 3, 6, 1, 2, 1 }, - { 81, 4, 357, 51, 52, 51 }, - { 81, 5, 358, 51, 52, 51 }, - { 81, 6, 359, 51, 52, 51 }, - { 81, 0, 360, 52, 52, 51 }, - { 81, 1, 361, 52, 53, 52 }, - { 81, 2, 362, 52, 53, 52 }, - { 81, 3, 363, 52, 53, 52 }, - { 81, 4, 364, 52, 53, 52 }, - { 82, 5, 0, 0, 53, 0 }, - { 82, 6, 1, 0, 53, 0 }, - { 82, 0, 2, 1, 53, 0 }, - { 82, 1, 3, 1, 1, 1 }, - { 82, 2, 4, 1, 1, 1 }, - { 82, 3, 5, 1, 1, 1 }, - { 82, 4, 6, 1, 1, 1 }, - { 82, 5, 357, 51, 51, 51 }, - { 82, 6, 358, 51, 51, 51 }, - { 82, 0, 359, 52, 51, 51 }, - { 82, 1, 360, 52, 52, 52 }, - { 82, 2, 361, 52, 52, 52 }, - { 82, 3, 362, 52, 52, 52 }, - { 82, 4, 363, 52, 52, 52 }, - { 82, 5, 364, 52, 52, 52 }, - { 83, 6, 0, 0, 52, 0 }, - { 83, 0, 1, 1, 52, 0 }, - { 83, 1, 2, 1, 1, 1 }, - { 83, 2, 3, 1, 1, 1 }, - { 83, 3, 4, 1, 1, 1 }, - { 83, 4, 5, 1, 1, 1 }, - { 83, 5, 6, 1, 1, 1 }, - { 83, 6, 357, 51, 51, 51 }, - { 83, 0, 358, 52, 51, 51 }, - { 83, 1, 359, 52, 52, 52 }, - { 83, 2, 360, 52, 52, 52 }, - { 83, 3, 361, 52, 52, 52 }, - { 83, 4, 362, 52, 52, 52 }, - { 83, 5, 363, 52, 52, 52 }, - { 83, 6, 364, 52, 52, 52 }, - { 84, 0, 0, 1, 52, 0 }, - { 84, 1, 1, 1, 1, 1 }, - { 84, 2, 2, 1, 1, 1 }, - { 84, 3, 3, 1, 1, 1 }, - { 84, 4, 4, 1, 1, 1 }, - { 84, 5, 5, 1, 1, 1 }, - { 84, 6, 6, 1, 1, 1 }, - { 84, 1, 358, 52, 52, 52 }, - { 84, 2, 359, 52, 52, 52 }, - { 84, 3, 360, 52, 52, 52 }, - { 84, 4, 361, 52, 52, 52 }, - { 84, 5, 362, 52, 52, 52 }, - { 84, 6, 363, 52, 52, 52 }, - { 84, 0, 364, 53, 52, 52 }, - { 84, 1, 365, 53, 1, 53 }, - { 85, 2, 0, 0, 1, 0 }, - { 85, 3, 1, 0, 1, 0 }, - { 85, 4, 2, 0, 1, 0 }, - { 85, 5, 3, 0, 1, 0 }, - { 85, 6, 4, 0, 1, 0 }, - { 85, 0, 5, 1, 1, 0 }, - { 85, 1, 6, 1, 2, 1 }, - { 85, 2, 357, 51, 52, 51 }, - { 85, 3, 358, 51, 52, 51 }, - { 85, 4, 359, 51, 52, 51 }, - { 85, 5, 360, 51, 52, 51 }, - { 85, 6, 361, 51, 52, 51 }, - { 85, 0, 362, 52, 52, 51 }, - { 85, 1, 363, 52, 1, 52 }, - { 85, 2, 364, 52, 1, 52 }, - { 86, 3, 0, 0, 1, 0 }, - { 86, 4, 1, 0, 1, 0 }, - { 86, 5, 2, 0, 1, 0 }, - { 86, 6, 3, 0, 1, 0 }, - { 86, 0, 4, 1, 1, 0 }, - { 86, 1, 5, 1, 2, 1 }, - { 86, 2, 6, 1, 2, 1 }, - { 86, 3, 357, 51, 52, 51 }, - { 86, 4, 358, 51, 52, 51 }, - { 86, 5, 359, 51, 52, 51 }, - { 86, 6, 360, 51, 52, 51 }, - { 86, 0, 361, 52, 52, 51 }, - { 86, 1, 362, 52, 1, 52 }, - { 86, 2, 363, 52, 1, 52 }, - { 86, 3, 364, 52, 1, 52 }, - { 87, 4, 0, 0, 1, 0 }, - { 87, 5, 1, 0, 1, 0 }, - { 87, 6, 2, 0, 1, 0 }, - { 87, 0, 3, 1, 1, 0 }, - { 87, 1, 4, 1, 2, 1 }, - { 87, 2, 5, 1, 2, 1 }, - { 87, 3, 6, 1, 2, 1 }, - { 87, 4, 357, 51, 52, 51 }, - { 87, 5, 358, 51, 52, 51 }, - { 87, 6, 359, 51, 52, 51 }, - { 87, 0, 360, 52, 52, 51 }, - { 87, 1, 361, 52, 53, 52 }, - { 87, 2, 362, 52, 53, 52 }, - { 87, 3, 363, 52, 53, 52 }, - { 87, 4, 364, 52, 53, 52 }, - { 88, 5, 0, 0, 53, 0 }, - { 88, 6, 1, 0, 53, 0 }, - { 88, 0, 2, 1, 53, 0 }, - { 88, 1, 3, 1, 1, 1 }, - { 88, 2, 4, 1, 1, 1 }, - { 88, 3, 5, 1, 1, 1 }, - { 88, 4, 6, 1, 1, 1 }, - { 88, 6, 358, 51, 51, 51 }, - { 88, 0, 359, 52, 51, 51 }, - { 88, 1, 360, 52, 52, 52 }, - { 88, 2, 361, 52, 52, 52 }, - { 88, 3, 362, 52, 52, 52 }, - { 88, 4, 363, 52, 52, 52 }, - { 88, 5, 364, 52, 52, 52 }, - { 88, 6, 365, 52, 52, 52 }, - { 89, 0, 0, 1, 52, 0 }, - { 89, 1, 1, 1, 1, 1 }, - { 89, 2, 2, 1, 1, 1 }, - { 89, 3, 3, 1, 1, 1 }, - { 89, 4, 4, 1, 1, 1 }, - { 89, 5, 5, 1, 1, 1 }, - { 89, 6, 6, 1, 1, 1 }, - { 89, 0, 357, 52, 51, 51 }, - { 89, 1, 358, 52, 52, 52 }, - { 89, 2, 359, 52, 52, 52 }, - { 89, 3, 360, 52, 52, 52 }, - { 89, 4, 361, 52, 52, 52 }, - { 89, 5, 362, 52, 52, 52 }, - { 89, 6, 363, 52, 52, 52 }, - { 89, 0, 364, 53, 52, 52 }, - { 90, 1, 0, 0, 1, 1 }, - { 90, 2, 1, 0, 1, 1 }, - { 90, 3, 2, 0, 1, 1 }, - { 90, 4, 3, 0, 1, 1 }, - { 90, 5, 4, 0, 1, 1 }, - { 90, 6, 5, 0, 1, 1 }, - { 90, 0, 6, 1, 1, 1 }, - { 90, 1, 357, 51, 52, 52 }, - { 90, 2, 358, 51, 52, 52 }, - { 90, 3, 359, 51, 52, 52 }, - { 90, 4, 360, 51, 52, 52 }, - { 90, 5, 361, 51, 52, 52 }, - { 90, 6, 362, 51, 52, 52 }, - { 90, 0, 363, 52, 52, 52 }, - { 90, 1, 364, 52, 1, 53 }, - { 91, 2, 0, 0, 1, 0 }, - { 91, 3, 1, 0, 1, 0 }, - { 91, 4, 2, 0, 1, 0 }, - { 91, 5, 3, 0, 1, 0 }, - { 91, 6, 4, 0, 1, 0 }, - { 91, 0, 5, 1, 1, 0 }, - { 91, 1, 6, 1, 2, 1 }, - { 91, 2, 357, 51, 52, 51 }, - { 91, 3, 358, 51, 52, 51 }, - { 91, 4, 359, 51, 52, 51 }, - { 91, 5, 360, 51, 52, 51 }, - { 91, 6, 361, 51, 52, 51 }, - { 91, 0, 362, 52, 52, 51 }, - { 91, 1, 363, 52, 1, 52 }, - { 91, 2, 364, 52, 1, 52 }, - { 92, 3, 0, 0, 1, 0 }, - { 92, 4, 1, 0, 1, 0 }, - { 92, 5, 2, 0, 1, 0 }, - { 92, 6, 3, 0, 1, 0 }, - { 92, 0, 4, 1, 1, 0 }, - { 92, 1, 5, 1, 2, 1 }, - { 92, 2, 6, 1, 2, 1 }, - { 92, 4, 358, 51, 52, 51 }, - { 92, 5, 359, 51, 52, 51 }, - { 92, 6, 360, 51, 52, 51 }, - { 92, 0, 361, 52, 52, 51 }, - { 92, 1, 362, 52, 53, 52 }, - { 92, 2, 363, 52, 53, 52 }, - { 92, 3, 364, 52, 53, 52 }, - { 92, 4, 365, 52, 53, 52 }, - { 93, 5, 0, 0, 53, 0 }, - { 93, 6, 1, 0, 53, 0 }, - { 93, 0, 2, 1, 53, 0 }, - { 93, 1, 3, 1, 1, 1 }, - { 93, 2, 4, 1, 1, 1 }, - { 93, 3, 5, 1, 1, 1 }, - { 93, 4, 6, 1, 1, 1 }, - { 93, 5, 357, 51, 51, 51 }, - { 93, 6, 358, 51, 51, 51 }, - { 93, 0, 359, 52, 51, 51 }, - { 93, 1, 360, 52, 52, 52 }, - { 93, 2, 361, 52, 52, 52 }, - { 93, 3, 362, 52, 52, 52 }, - { 93, 4, 363, 52, 52, 52 }, - { 93, 5, 364, 52, 52, 52 }, - { 94, 6, 0, 0, 52, 0 }, - { 94, 0, 1, 1, 52, 0 }, - { 94, 1, 2, 1, 1, 1 }, - { 94, 2, 3, 1, 1, 1 }, - { 94, 3, 4, 1, 1, 1 }, - { 94, 4, 5, 1, 1, 1 }, - { 94, 5, 6, 1, 1, 1 }, - { 94, 6, 357, 51, 51, 51 }, - { 94, 0, 358, 52, 51, 51 }, - { 94, 1, 359, 52, 52, 52 }, - { 94, 2, 360, 52, 52, 52 }, - { 94, 3, 361, 52, 52, 52 }, - { 94, 4, 362, 52, 52, 52 }, - { 94, 5, 363, 52, 52, 52 }, - { 94, 6, 364, 52, 52, 52 }, - { 95, 0, 0, 1, 52, 0 }, - { 95, 1, 1, 1, 1, 1 }, - { 95, 2, 2, 1, 1, 1 }, - { 95, 3, 3, 1, 1, 1 }, - { 95, 4, 4, 1, 1, 1 }, - { 95, 5, 5, 1, 1, 1 }, - { 95, 6, 6, 1, 1, 1 }, - { 95, 0, 357, 52, 51, 51 }, - { 95, 1, 358, 52, 52, 52 }, - { 95, 2, 359, 52, 52, 52 }, - { 95, 3, 360, 52, 52, 52 }, - { 95, 4, 361, 52, 52, 52 }, - { 95, 5, 362, 52, 52, 52 }, - { 95, 6, 363, 52, 52, 52 }, - { 95, 0, 364, 53, 52, 52 }, - { 96, 1, 0, 0, 1, 1 }, - { 96, 2, 1, 0, 1, 1 }, - { 96, 3, 2, 0, 1, 1 }, - { 96, 4, 3, 0, 1, 1 }, - { 96, 5, 4, 0, 1, 1 }, - { 96, 6, 5, 0, 1, 1 }, - { 96, 0, 6, 1, 1, 1 }, - { 96, 2, 358, 51, 52, 52 }, - { 96, 3, 359, 51, 52, 52 }, - { 96, 4, 360, 51, 52, 52 }, - { 96, 5, 361, 51, 52, 52 }, - { 96, 6, 362, 51, 52, 52 }, - { 96, 0, 363, 52, 52, 52 }, - { 96, 1, 364, 52, 1, 53 }, - { 96, 2, 365, 52, 1, 53 }, - { 97, 3, 0, 0, 1, 0 }, - { 97, 4, 1, 0, 1, 0 }, - { 97, 5, 2, 0, 1, 0 }, - { 97, 6, 3, 0, 1, 0 }, - { 97, 0, 4, 1, 1, 0 }, - { 97, 1, 5, 1, 2, 1 }, - { 97, 2, 6, 1, 2, 1 }, - { 97, 3, 357, 51, 52, 51 }, - { 97, 4, 358, 51, 52, 51 }, - { 97, 5, 359, 51, 52, 51 }, - { 97, 6, 360, 51, 52, 51 }, - { 97, 0, 361, 52, 52, 51 }, - { 97, 1, 362, 52, 1, 52 }, - { 97, 2, 363, 52, 1, 52 }, - { 97, 3, 364, 52, 1, 52 }, - { 98, 4, 0, 0, 1, 0 }, - { 98, 5, 1, 0, 1, 0 }, - { 98, 6, 2, 0, 1, 0 }, - { 98, 0, 3, 1, 1, 0 }, - { 98, 1, 4, 1, 2, 1 }, - { 98, 2, 5, 1, 2, 1 }, - { 98, 3, 6, 1, 2, 1 }, - { 98, 4, 357, 51, 52, 51 }, - { 98, 5, 358, 51, 52, 51 }, - { 98, 6, 359, 51, 52, 51 }, - { 98, 0, 360, 52, 52, 51 }, - { 98, 1, 361, 52, 53, 52 }, - { 98, 2, 362, 52, 53, 52 }, - { 98, 3, 363, 52, 53, 52 }, - { 98, 4, 364, 52, 53, 52 }, - { 99, 5, 0, 0, 53, 0 }, - { 99, 6, 1, 0, 53, 0 }, - { 99, 0, 2, 1, 53, 0 }, - { 99, 1, 3, 1, 1, 1 }, - { 99, 2, 4, 1, 1, 1 }, - { 99, 3, 5, 1, 1, 1 }, - { 99, 4, 6, 1, 1, 1 }, - { 99, 5, 357, 51, 51, 51 }, - { 99, 6, 358, 51, 51, 51 }, - { 99, 0, 359, 52, 51, 51 }, - { 99, 1, 360, 52, 52, 52 }, - { 99, 2, 361, 52, 52, 52 }, - { 99, 3, 362, 52, 52, 52 }, - { 99, 4, 363, 52, 52, 52 }, - { 99, 5, 364, 52, 52, 52 }, - { 100, 6, 0, 0, 52, 0 }, - { 100, 0, 1, 1, 52, 0 }, - { 100, 1, 2, 1, 1, 1 }, - { 100, 2, 3, 1, 1, 1 }, - { 100, 3, 4, 1, 1, 1 }, - { 100, 4, 5, 1, 1, 1 }, - { 100, 5, 6, 1, 1, 1 }, - { 100, 0, 358, 52, 51, 51 }, - { 100, 1, 359, 52, 52, 52 }, - { 100, 2, 360, 52, 52, 52 }, - { 100, 3, 361, 52, 52, 52 }, - { 100, 4, 362, 52, 52, 52 }, - { 100, 5, 363, 52, 52, 52 }, - { 100, 6, 364, 52, 52, 52 }, - { 100, 0, 365, 53, 52, 52 }, - { 101, 1, 0, 0, 1, 1 }, - { 101, 2, 1, 0, 1, 1 }, - { 101, 3, 2, 0, 1, 1 }, - { 101, 4, 3, 0, 1, 1 }, - { 101, 5, 4, 0, 1, 1 }, - { 101, 6, 5, 0, 1, 1 }, - { 101, 0, 6, 1, 1, 1 }, - { 101, 1, 357, 51, 52, 52 }, - { 101, 2, 358, 51, 52, 52 }, - { 101, 3, 359, 51, 52, 52 }, - { 101, 4, 360, 51, 52, 52 }, - { 101, 5, 361, 51, 52, 52 }, - { 101, 6, 362, 51, 52, 52 }, - { 101, 0, 363, 52, 52, 52 }, - { 101, 1, 364, 52, 1, 53 }, - { 102, 2, 0, 0, 1, 0 }, - { 102, 3, 1, 0, 1, 0 }, - { 102, 4, 2, 0, 1, 0 }, - { 102, 5, 3, 0, 1, 0 }, - { 102, 6, 4, 0, 1, 0 }, - { 102, 0, 5, 1, 1, 0 }, - { 102, 1, 6, 1, 2, 1 }, - { 102, 2, 357, 51, 52, 51 }, - { 102, 3, 358, 51, 52, 51 }, - { 102, 4, 359, 51, 52, 51 }, - { 102, 5, 360, 51, 52, 51 }, - { 102, 6, 361, 51, 52, 51 }, - { 102, 0, 362, 52, 52, 51 }, - { 102, 1, 363, 52, 1, 52 }, - { 102, 2, 364, 52, 1, 52 }, - { 103, 3, 0, 0, 1, 0 }, - { 103, 4, 1, 0, 1, 0 }, - { 103, 5, 2, 0, 1, 0 }, - { 103, 6, 3, 0, 1, 0 }, - { 103, 0, 4, 1, 1, 0 }, - { 103, 1, 5, 1, 2, 1 }, - { 103, 2, 6, 1, 2, 1 }, - { 103, 3, 357, 51, 52, 51 }, - { 103, 4, 358, 51, 52, 51 }, - { 103, 5, 359, 51, 52, 51 }, - { 103, 6, 360, 51, 52, 51 }, - { 103, 0, 361, 52, 52, 51 }, - { 103, 1, 362, 52, 1, 52 }, - { 103, 2, 363, 52, 1, 52 }, - { 103, 3, 364, 52, 1, 52 }, - { 104, 4, 0, 0, 1, 0 }, - { 104, 5, 1, 0, 1, 0 }, - { 104, 6, 2, 0, 1, 0 }, - { 104, 0, 3, 1, 1, 0 }, - { 104, 1, 4, 1, 2, 1 }, - { 104, 2, 5, 1, 2, 1 }, - { 104, 3, 6, 1, 2, 1 }, - { 104, 5, 358, 51, 52, 51 }, - { 104, 6, 359, 51, 52, 51 }, - { 104, 0, 360, 52, 52, 51 }, - { 104, 1, 361, 52, 53, 52 }, - { 104, 2, 362, 52, 53, 52 }, - { 104, 3, 363, 52, 53, 52 }, - { 104, 4, 364, 52, 53, 52 }, - { 104, 5, 365, 52, 53, 52 }, - { 105, 6, 0, 0, 53, 0 }, - { 105, 0, 1, 1, 53, 0 }, - { 105, 1, 2, 1, 1, 1 }, - { 105, 2, 3, 1, 1, 1 }, - { 105, 3, 4, 1, 1, 1 }, - { 105, 4, 5, 1, 1, 1 }, - { 105, 5, 6, 1, 1, 1 }, - { 105, 6, 357, 51, 51, 51 }, - { 105, 0, 358, 52, 51, 51 }, - { 105, 1, 359, 52, 52, 52 }, - { 105, 2, 360, 52, 52, 52 }, - { 105, 3, 361, 52, 52, 52 }, - { 105, 4, 362, 52, 52, 52 }, - { 105, 5, 363, 52, 52, 52 }, - { 105, 6, 364, 52, 52, 52 }, - { 106, 0, 0, 1, 52, 0 }, - { 106, 1, 1, 1, 1, 1 }, - { 106, 2, 2, 1, 1, 1 }, - { 106, 3, 3, 1, 1, 1 }, - { 106, 4, 4, 1, 1, 1 }, - { 106, 5, 5, 1, 1, 1 }, - { 106, 6, 6, 1, 1, 1 }, - { 106, 0, 357, 52, 51, 51 }, - { 106, 1, 358, 52, 52, 52 }, - { 106, 2, 359, 52, 52, 52 }, - { 106, 3, 360, 52, 52, 52 }, - { 106, 4, 361, 52, 52, 52 }, - { 106, 5, 362, 52, 52, 52 }, - { 106, 6, 363, 52, 52, 52 }, - { 106, 0, 364, 53, 52, 52 }, - { 107, 1, 0, 0, 1, 1 }, - { 107, 2, 1, 0, 1, 1 }, - { 107, 3, 2, 0, 1, 1 }, - { 107, 4, 3, 0, 1, 1 }, - { 107, 5, 4, 0, 1, 1 }, - { 107, 6, 5, 0, 1, 1 }, - { 107, 0, 6, 1, 1, 1 }, - { 107, 1, 357, 51, 52, 52 }, - { 107, 2, 358, 51, 52, 52 }, - { 107, 3, 359, 51, 52, 52 }, - { 107, 4, 360, 51, 52, 52 }, - { 107, 5, 361, 51, 52, 52 }, - { 107, 6, 362, 51, 52, 52 }, - { 107, 0, 363, 52, 52, 52 }, - { 107, 1, 364, 52, 1, 53 }, - { 108, 2, 0, 0, 1, 0 }, - { 108, 3, 1, 0, 1, 0 }, - { 108, 4, 2, 0, 1, 0 }, - { 108, 5, 3, 0, 1, 0 }, - { 108, 6, 4, 0, 1, 0 }, - { 108, 0, 5, 1, 1, 0 }, - { 108, 1, 6, 1, 2, 1 }, - { 108, 3, 358, 51, 52, 51 }, - { 108, 4, 359, 51, 52, 51 }, - { 108, 5, 360, 51, 52, 51 }, - { 108, 6, 361, 51, 52, 51 }, - { 108, 0, 362, 52, 52, 51 }, - { 108, 1, 363, 52, 1, 52 }, - { 108, 2, 364, 52, 1, 52 }, - { 108, 3, 365, 52, 1, 52 }, - { 109, 4, 0, 0, 1, 0 }, - { 109, 5, 1, 0, 1, 0 }, - { 109, 6, 2, 0, 1, 0 }, - { 109, 0, 3, 1, 1, 0 }, - { 109, 1, 4, 1, 2, 1 }, - { 109, 2, 5, 1, 2, 1 }, - { 109, 3, 6, 1, 2, 1 }, - { 109, 4, 357, 51, 52, 51 }, - { 109, 5, 358, 51, 52, 51 }, - { 109, 6, 359, 51, 52, 51 }, - { 109, 0, 360, 52, 52, 51 }, - { 109, 1, 361, 52, 53, 52 }, - { 109, 2, 362, 52, 53, 52 }, - { 109, 3, 363, 52, 53, 52 }, - { 109, 4, 364, 52, 53, 52 }, - { 110, 5, 0, 0, 53, 0 }, - { 110, 6, 1, 0, 53, 0 }, - { 110, 0, 2, 1, 53, 0 }, - { 110, 1, 3, 1, 1, 1 }, - { 110, 2, 4, 1, 1, 1 }, - { 110, 3, 5, 1, 1, 1 }, - { 110, 4, 6, 1, 1, 1 }, - { 110, 5, 357, 51, 51, 51 }, - { 110, 6, 358, 51, 51, 51 }, - { 110, 0, 359, 52, 51, 51 }, - { 110, 1, 360, 52, 52, 52 }, - { 110, 2, 361, 52, 52, 52 }, - { 110, 3, 362, 52, 52, 52 }, - { 110, 4, 363, 52, 52, 52 }, - { 110, 5, 364, 52, 52, 52 }, - { 111, 6, 0, 0, 52, 0 }, - { 111, 0, 1, 1, 52, 0 }, - { 111, 1, 2, 1, 1, 1 }, - { 111, 2, 3, 1, 1, 1 }, - { 111, 3, 4, 1, 1, 1 }, - { 111, 4, 5, 1, 1, 1 }, - { 111, 5, 6, 1, 1, 1 }, - { 111, 6, 357, 51, 51, 51 }, - { 111, 0, 358, 52, 51, 51 }, - { 111, 1, 359, 52, 52, 52 }, - { 111, 2, 360, 52, 52, 52 }, - { 111, 3, 361, 52, 52, 52 }, - { 111, 4, 362, 52, 52, 52 }, - { 111, 5, 363, 52, 52, 52 }, - { 111, 6, 364, 52, 52, 52 }, - { 112, 0, 0, 1, 52, 0 }, - { 112, 1, 1, 1, 1, 1 }, - { 112, 2, 2, 1, 1, 1 }, - { 112, 3, 3, 1, 1, 1 }, - { 112, 4, 4, 1, 1, 1 }, - { 112, 5, 5, 1, 1, 1 }, - { 112, 6, 6, 1, 1, 1 }, - { 112, 1, 358, 52, 52, 52 }, - { 112, 2, 359, 52, 52, 52 }, - { 112, 3, 360, 52, 52, 52 }, - { 112, 4, 361, 52, 52, 52 }, - { 112, 5, 362, 52, 52, 52 }, - { 112, 6, 363, 52, 52, 52 }, - { 112, 0, 364, 53, 52, 52 }, - { 112, 1, 365, 53, 1, 53 }, - { 113, 2, 0, 0, 1, 0 }, - { 113, 3, 1, 0, 1, 0 }, - { 113, 4, 2, 0, 1, 0 }, - { 113, 5, 3, 0, 1, 0 }, - { 113, 6, 4, 0, 1, 0 }, - { 113, 0, 5, 1, 1, 0 }, - { 113, 1, 6, 1, 2, 1 }, - { 113, 2, 357, 51, 52, 51 }, - { 113, 3, 358, 51, 52, 51 }, - { 113, 4, 359, 51, 52, 51 }, - { 113, 5, 360, 51, 52, 51 }, - { 113, 6, 361, 51, 52, 51 }, - { 113, 0, 362, 52, 52, 51 }, - { 113, 1, 363, 52, 1, 52 }, - { 113, 2, 364, 52, 1, 52 }, - { 114, 3, 0, 0, 1, 0 }, - { 114, 4, 1, 0, 1, 0 }, - { 114, 5, 2, 0, 1, 0 }, - { 114, 6, 3, 0, 1, 0 }, - { 114, 0, 4, 1, 1, 0 }, - { 114, 1, 5, 1, 2, 1 }, - { 114, 2, 6, 1, 2, 1 }, - { 114, 3, 357, 51, 52, 51 }, - { 114, 4, 358, 51, 52, 51 }, - { 114, 5, 359, 51, 52, 51 }, - { 114, 6, 360, 51, 52, 51 }, - { 114, 0, 361, 52, 52, 51 }, - { 114, 1, 362, 52, 1, 52 }, - { 114, 2, 363, 52, 1, 52 }, - { 114, 3, 364, 52, 1, 52 }, - { 115, 4, 0, 0, 1, 0 }, - { 115, 5, 1, 0, 1, 0 }, - { 115, 6, 2, 0, 1, 0 }, - { 115, 0, 3, 1, 1, 0 }, - { 115, 1, 4, 1, 2, 1 }, - { 115, 2, 5, 1, 2, 1 }, - { 115, 3, 6, 1, 2, 1 }, - { 115, 4, 357, 51, 52, 51 }, - { 115, 5, 358, 51, 52, 51 }, - { 115, 6, 359, 51, 52, 51 }, - { 115, 0, 360, 52, 52, 51 }, - { 115, 1, 361, 52, 53, 52 }, - { 115, 2, 362, 52, 53, 52 }, - { 115, 3, 363, 52, 53, 52 }, - { 115, 4, 364, 52, 53, 52 }, - { 116, 5, 0, 0, 53, 0 }, - { 116, 6, 1, 0, 53, 0 }, - { 116, 0, 2, 1, 53, 0 }, - { 116, 1, 3, 1, 1, 1 }, - { 116, 2, 4, 1, 1, 1 }, - { 116, 3, 5, 1, 1, 1 }, - { 116, 4, 6, 1, 1, 1 }, - { 116, 6, 358, 51, 51, 51 }, - { 116, 0, 359, 52, 51, 51 }, - { 116, 1, 360, 52, 52, 52 }, - { 116, 2, 361, 52, 52, 52 }, - { 116, 3, 362, 52, 52, 52 }, - { 116, 4, 363, 52, 52, 52 }, - { 116, 5, 364, 52, 52, 52 }, - { 116, 6, 365, 52, 52, 52 }, - { 117, 0, 0, 1, 52, 0 }, - { 117, 1, 1, 1, 1, 1 }, - { 117, 2, 2, 1, 1, 1 }, - { 117, 3, 3, 1, 1, 1 }, - { 117, 4, 4, 1, 1, 1 }, - { 117, 5, 5, 1, 1, 1 }, - { 117, 6, 6, 1, 1, 1 }, - { 117, 0, 357, 52, 51, 51 }, - { 117, 1, 358, 52, 52, 52 }, - { 117, 2, 359, 52, 52, 52 }, - { 117, 3, 360, 52, 52, 52 }, - { 117, 4, 361, 52, 52, 52 }, - { 117, 5, 362, 52, 52, 52 }, - { 117, 6, 363, 52, 52, 52 }, - { 117, 0, 364, 53, 52, 52 }, - { 118, 1, 0, 0, 1, 1 }, - { 118, 2, 1, 0, 1, 1 }, - { 118, 3, 2, 0, 1, 1 }, - { 118, 4, 3, 0, 1, 1 }, - { 118, 5, 4, 0, 1, 1 }, - { 118, 6, 5, 0, 1, 1 }, - { 118, 0, 6, 1, 1, 1 }, - { 118, 1, 357, 51, 52, 52 }, - { 118, 2, 358, 51, 52, 52 }, - { 118, 3, 359, 51, 52, 52 }, - { 118, 4, 360, 51, 52, 52 }, - { 118, 5, 361, 51, 52, 52 }, - { 118, 6, 362, 51, 52, 52 }, - { 118, 0, 363, 52, 52, 52 }, - { 118, 1, 364, 52, 1, 53 }, - { 119, 2, 0, 0, 1, 0 }, - { 119, 3, 1, 0, 1, 0 }, - { 119, 4, 2, 0, 1, 0 }, - { 119, 5, 3, 0, 1, 0 }, - { 119, 6, 4, 0, 1, 0 }, - { 119, 0, 5, 1, 1, 0 }, - { 119, 1, 6, 1, 2, 1 }, - { 119, 2, 357, 51, 52, 51 }, - { 119, 3, 358, 51, 52, 51 }, - { 119, 4, 359, 51, 52, 51 }, - { 119, 5, 360, 51, 52, 51 }, - { 119, 6, 361, 51, 52, 51 }, - { 119, 0, 362, 52, 52, 51 }, - { 119, 1, 363, 52, 1, 52 }, - { 119, 2, 364, 52, 1, 52 }, - { 120, 3, 0, 0, 1, 0 }, - { 120, 4, 1, 0, 1, 0 }, - { 120, 5, 2, 0, 1, 0 }, - { 120, 6, 3, 0, 1, 0 }, - { 120, 0, 4, 1, 1, 0 }, - { 120, 1, 5, 1, 2, 1 }, - { 120, 2, 6, 1, 2, 1 }, - { 120, 4, 358, 51, 52, 51 }, - { 120, 5, 359, 51, 52, 51 }, - { 120, 6, 360, 51, 52, 51 }, - { 120, 0, 361, 52, 52, 51 }, - { 120, 1, 362, 52, 53, 52 }, - { 120, 2, 363, 52, 53, 52 }, - { 120, 3, 364, 52, 53, 52 }, - { 120, 4, 365, 52, 53, 52 }, - { 121, 5, 0, 0, 53, 0 }, - { 121, 6, 1, 0, 53, 0 }, - { 121, 0, 2, 1, 53, 0 }, - { 121, 1, 3, 1, 1, 1 }, - { 121, 2, 4, 1, 1, 1 }, - { 121, 3, 5, 1, 1, 1 }, - { 121, 4, 6, 1, 1, 1 }, - { 121, 5, 357, 51, 51, 51 }, - { 121, 6, 358, 51, 51, 51 }, - { 121, 0, 359, 52, 51, 51 }, - { 121, 1, 360, 52, 52, 52 }, - { 121, 2, 361, 52, 52, 52 }, - { 121, 3, 362, 52, 52, 52 }, - { 121, 4, 363, 52, 52, 52 }, - { 121, 5, 364, 52, 52, 52 }, - { 122, 6, 0, 0, 52, 0 }, - { 122, 0, 1, 1, 52, 0 }, - { 122, 1, 2, 1, 1, 1 }, - { 122, 2, 3, 1, 1, 1 }, - { 122, 3, 4, 1, 1, 1 }, - { 122, 4, 5, 1, 1, 1 }, - { 122, 5, 6, 1, 1, 1 }, - { 122, 6, 357, 51, 51, 51 }, - { 122, 0, 358, 52, 51, 51 }, - { 122, 1, 359, 52, 52, 52 }, - { 122, 2, 360, 52, 52, 52 }, - { 122, 3, 361, 52, 52, 52 }, - { 122, 4, 362, 52, 52, 52 }, - { 122, 5, 363, 52, 52, 52 }, - { 122, 6, 364, 52, 52, 52 }, - { 123, 0, 0, 1, 52, 0 }, - { 123, 1, 1, 1, 1, 1 }, - { 123, 2, 2, 1, 1, 1 }, - { 123, 3, 3, 1, 1, 1 }, - { 123, 4, 4, 1, 1, 1 }, - { 123, 5, 5, 1, 1, 1 }, - { 123, 6, 6, 1, 1, 1 }, - { 123, 0, 357, 52, 51, 51 }, - { 123, 1, 358, 52, 52, 52 }, - { 123, 2, 359, 52, 52, 52 }, - { 123, 3, 360, 52, 52, 52 }, - { 123, 4, 361, 52, 52, 52 }, - { 123, 5, 362, 52, 52, 52 }, - { 123, 6, 363, 52, 52, 52 }, - { 123, 0, 364, 53, 52, 52 }, - { 124, 1, 0, 0, 1, 1 }, - { 124, 2, 1, 0, 1, 1 }, - { 124, 3, 2, 0, 1, 1 }, - { 124, 4, 3, 0, 1, 1 }, - { 124, 5, 4, 0, 1, 1 }, - { 124, 6, 5, 0, 1, 1 }, - { 124, 0, 6, 1, 1, 1 }, - { 124, 2, 358, 51, 52, 52 }, - { 124, 3, 359, 51, 52, 52 }, - { 124, 4, 360, 51, 52, 52 }, - { 124, 5, 361, 51, 52, 52 }, - { 124, 6, 362, 51, 52, 52 }, - { 124, 0, 363, 52, 52, 52 }, - { 124, 1, 364, 52, 1, 53 }, - { 124, 2, 365, 52, 1, 53 }, - { 125, 3, 0, 0, 1, 0 }, - { 125, 4, 1, 0, 1, 0 }, - { 125, 5, 2, 0, 1, 0 }, - { 125, 6, 3, 0, 1, 0 }, - { 125, 0, 4, 1, 1, 0 }, - { 125, 1, 5, 1, 2, 1 }, - { 125, 2, 6, 1, 2, 1 }, - { 125, 3, 357, 51, 52, 51 }, - { 125, 4, 358, 51, 52, 51 }, - { 125, 5, 359, 51, 52, 51 }, - { 125, 6, 360, 51, 52, 51 }, - { 125, 0, 361, 52, 52, 51 }, - { 125, 1, 362, 52, 1, 52 }, - { 125, 2, 363, 52, 1, 52 }, - { 125, 3, 364, 52, 1, 52 }, - { 126, 4, 0, 0, 1, 0 }, - { 126, 5, 1, 0, 1, 0 }, - { 126, 6, 2, 0, 1, 0 }, - { 126, 0, 3, 1, 1, 0 }, - { 126, 1, 4, 1, 2, 1 }, - { 126, 2, 5, 1, 2, 1 }, - { 126, 3, 6, 1, 2, 1 }, - { 126, 4, 357, 51, 52, 51 }, - { 126, 5, 358, 51, 52, 51 }, - { 126, 6, 359, 51, 52, 51 }, - { 126, 0, 360, 52, 52, 51 }, - { 126, 1, 361, 52, 53, 52 }, - { 126, 2, 362, 52, 53, 52 }, - { 126, 3, 363, 52, 53, 52 }, - { 126, 4, 364, 52, 53, 52 }, - { 127, 5, 0, 0, 53, 0 }, - { 127, 6, 1, 0, 53, 0 }, - { 127, 0, 2, 1, 53, 0 }, - { 127, 1, 3, 1, 1, 1 }, - { 127, 2, 4, 1, 1, 1 }, - { 127, 3, 5, 1, 1, 1 }, - { 127, 4, 6, 1, 1, 1 }, - { 127, 5, 357, 51, 51, 51 }, - { 127, 6, 358, 51, 51, 51 }, - { 127, 0, 359, 52, 51, 51 }, - { 127, 1, 360, 52, 52, 52 }, - { 127, 2, 361, 52, 52, 52 }, - { 127, 3, 362, 52, 52, 52 }, - { 127, 4, 363, 52, 52, 52 }, - { 127, 5, 364, 52, 52, 52 }, - { 128, 6, 0, 0, 52, 0 }, - { 128, 0, 1, 1, 52, 0 }, - { 128, 1, 2, 1, 1, 1 }, - { 128, 2, 3, 1, 1, 1 }, - { 128, 3, 4, 1, 1, 1 }, - { 128, 4, 5, 1, 1, 1 }, - { 128, 5, 6, 1, 1, 1 }, - { 128, 0, 358, 52, 51, 51 }, - { 128, 1, 359, 52, 52, 52 }, - { 128, 2, 360, 52, 52, 52 }, - { 128, 3, 361, 52, 52, 52 }, - { 128, 4, 362, 52, 52, 52 }, - { 128, 5, 363, 52, 52, 52 }, - { 128, 6, 364, 52, 52, 52 }, - { 128, 0, 365, 53, 52, 52 }, - { 129, 1, 0, 0, 1, 1 }, - { 129, 2, 1, 0, 1, 1 }, - { 129, 3, 2, 0, 1, 1 }, - { 129, 4, 3, 0, 1, 1 }, - { 129, 5, 4, 0, 1, 1 }, - { 129, 6, 5, 0, 1, 1 }, - { 129, 0, 6, 1, 1, 1 }, - { 129, 1, 357, 51, 52, 52 }, - { 129, 2, 358, 51, 52, 52 }, - { 129, 3, 359, 51, 52, 52 }, - { 129, 4, 360, 51, 52, 52 }, - { 129, 5, 361, 51, 52, 52 }, - { 129, 6, 362, 51, 52, 52 }, - { 129, 0, 363, 52, 52, 52 }, - { 129, 1, 364, 52, 1, 53 }, - { 130, 2, 0, 0, 1, 0 }, - { 130, 3, 1, 0, 1, 0 }, - { 130, 4, 2, 0, 1, 0 }, - { 130, 5, 3, 0, 1, 0 }, - { 130, 6, 4, 0, 1, 0 }, - { 130, 0, 5, 1, 1, 0 }, - { 130, 1, 6, 1, 2, 1 }, - { 130, 2, 357, 51, 52, 51 }, - { 130, 3, 358, 51, 52, 51 }, - { 130, 4, 359, 51, 52, 51 }, - { 130, 5, 360, 51, 52, 51 }, - { 130, 6, 361, 51, 52, 51 }, - { 130, 0, 362, 52, 52, 51 }, - { 130, 1, 363, 52, 1, 52 }, - { 130, 2, 364, 52, 1, 52 }, - { 131, 3, 0, 0, 1, 0 }, - { 131, 4, 1, 0, 1, 0 }, - { 131, 5, 2, 0, 1, 0 }, - { 131, 6, 3, 0, 1, 0 }, - { 131, 0, 4, 1, 1, 0 }, - { 131, 1, 5, 1, 2, 1 }, - { 131, 2, 6, 1, 2, 1 }, - { 131, 3, 357, 51, 52, 51 }, - { 131, 4, 358, 51, 52, 51 }, - { 131, 5, 359, 51, 52, 51 }, - { 131, 6, 360, 51, 52, 51 }, - { 131, 0, 361, 52, 52, 51 }, - { 131, 1, 362, 52, 1, 52 }, - { 131, 2, 363, 52, 1, 52 }, - { 131, 3, 364, 52, 1, 52 }, - { 132, 4, 0, 0, 1, 0 }, - { 132, 5, 1, 0, 1, 0 }, - { 132, 6, 2, 0, 1, 0 }, - { 132, 0, 3, 1, 1, 0 }, - { 132, 1, 4, 1, 2, 1 }, - { 132, 2, 5, 1, 2, 1 }, - { 132, 3, 6, 1, 2, 1 }, - { 132, 5, 358, 51, 52, 51 }, - { 132, 6, 359, 51, 52, 51 }, - { 132, 0, 360, 52, 52, 51 }, - { 132, 1, 361, 52, 53, 52 }, - { 132, 2, 362, 52, 53, 52 }, - { 132, 3, 363, 52, 53, 52 }, - { 132, 4, 364, 52, 53, 52 }, - { 132, 5, 365, 52, 53, 52 }, - { 133, 6, 0, 0, 53, 0 }, - { 133, 0, 1, 1, 53, 0 }, - { 133, 1, 2, 1, 1, 1 }, - { 133, 2, 3, 1, 1, 1 }, - { 133, 3, 4, 1, 1, 1 }, - { 133, 4, 5, 1, 1, 1 }, - { 133, 5, 6, 1, 1, 1 }, - { 133, 6, 357, 51, 51, 51 }, - { 133, 0, 358, 52, 51, 51 }, - { 133, 1, 359, 52, 52, 52 }, - { 133, 2, 360, 52, 52, 52 }, - { 133, 3, 361, 52, 52, 52 }, - { 133, 4, 362, 52, 52, 52 }, - { 133, 5, 363, 52, 52, 52 }, - { 133, 6, 364, 52, 52, 52 }, - { 134, 0, 0, 1, 52, 0 }, - { 134, 1, 1, 1, 1, 1 }, - { 134, 2, 2, 1, 1, 1 }, - { 134, 3, 3, 1, 1, 1 }, - { 134, 4, 4, 1, 1, 1 }, - { 134, 5, 5, 1, 1, 1 }, - { 134, 6, 6, 1, 1, 1 }, - { 134, 0, 357, 52, 51, 51 }, - { 134, 1, 358, 52, 52, 52 }, - { 134, 2, 359, 52, 52, 52 }, - { 134, 3, 360, 52, 52, 52 }, - { 134, 4, 361, 52, 52, 52 }, - { 134, 5, 362, 52, 52, 52 }, - { 134, 6, 363, 52, 52, 52 }, - { 134, 0, 364, 53, 52, 52 }, - { 135, 1, 0, 0, 1, 1 }, - { 135, 2, 1, 0, 1, 1 }, - { 135, 3, 2, 0, 1, 1 }, - { 135, 4, 3, 0, 1, 1 }, - { 135, 5, 4, 0, 1, 1 }, - { 135, 6, 5, 0, 1, 1 }, - { 135, 0, 6, 1, 1, 1 }, - { 135, 1, 357, 51, 52, 52 }, - { 135, 2, 358, 51, 52, 52 }, - { 135, 3, 359, 51, 52, 52 }, - { 135, 4, 360, 51, 52, 52 }, - { 135, 5, 361, 51, 52, 52 }, - { 135, 6, 362, 51, 52, 52 }, - { 135, 0, 363, 52, 52, 52 }, - { 135, 1, 364, 52, 1, 53 }, - { 136, 2, 0, 0, 1, 0 }, - { 136, 3, 1, 0, 1, 0 }, - { 136, 4, 2, 0, 1, 0 }, - { 136, 5, 3, 0, 1, 0 }, - { 136, 6, 4, 0, 1, 0 }, - { 136, 0, 5, 1, 1, 0 }, - { 136, 1, 6, 1, 2, 1 }, - { 136, 3, 358, 51, 52, 51 }, - { 136, 4, 359, 51, 52, 51 }, - { 136, 5, 360, 51, 52, 51 }, - { 136, 6, 361, 51, 52, 51 }, - { 136, 0, 362, 52, 52, 51 }, - { 136, 1, 363, 52, 1, 52 }, - { 136, 2, 364, 52, 1, 52 }, - { 136, 3, 365, 52, 1, 52 }, - { 137, 4, 0, 0, 1, 0 }, - { 137, 5, 1, 0, 1, 0 }, - { 137, 6, 2, 0, 1, 0 }, - { 137, 0, 3, 1, 1, 0 }, - { 137, 1, 4, 1, 2, 1 }, - { 137, 2, 5, 1, 2, 1 }, - { 137, 3, 6, 1, 2, 1 }, - { 137, 4, 357, 51, 52, 51 }, - { 137, 5, 358, 51, 52, 51 }, - { 137, 6, 359, 51, 52, 51 }, - { 137, 0, 360, 52, 52, 51 }, - { 137, 1, 361, 52, 53, 52 }, - { 137, 2, 362, 52, 53, 52 }, - { 137, 3, 363, 52, 53, 52 }, - { 137, 4, 364, 52, 53, 52 }, -}; - -static int test_week_calc( void ) -{ - char buffer[100]; - int rc = 1; - int i; - - for ( i = 0; i < 1020; ++i ) - { -#ifdef __cplusplus - struct tm t = {}; -#else - struct tm t = { 0 }; -#endif - int U, V, W; - t.tm_year = data[i][0]; - t.tm_wday = data[i][1]; - t.tm_yday = data[i][2]; - assert( strftime( buffer, 100, "%U %V %W", &t ) == 8 ); - assert( sscanf( buffer, "%d %d %d", &U, &V, &W ) == 3 ); - - if ( data[i][3] != U || data[i][4] != V || data[i][5] != W ) - { - printf( "Fehler in { %d, %d, %d, %d, %d, %d } (encountered { %d, %d, %d })\n", data[i][0], data[i][1], data[i][2], data[i][3], data[i][4], data[i][5], U, V, W ); - rc = 0; - } - } - - return rc; -} - -int main( void ) -{ - char buffer[100]; - /* Basic functionality */ - struct tm timeptr; - MKTIME( timeptr, 59, 30, 12, 1, 9, 72, 0, 274 ); - TESTCASE( strftime( buffer, 100, "%a ", &timeptr ) == 4 ); - TESTCASE( strcmp( buffer, "Sun " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%A ", &timeptr ) == 7 ); - TESTCASE( strcmp( buffer, "Sunday " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%b ", &timeptr ) == 4 ); - TESTCASE( strcmp( buffer, "Oct " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%h ", &timeptr ) == 4 ); - TESTCASE( strcmp( buffer, "Oct " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%B ", &timeptr ) == 8 ); - TESTCASE( strcmp( buffer, "October " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%c ", &timeptr ) == 25 ); - TESTCASE( strcmp( buffer, "Sun Oct 1 12:30:59 1972 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%C ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "19 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%d ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "01 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%D ", &timeptr ) == 9 ); - TESTCASE( strcmp( buffer, "10/01/72 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%e ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, " 1 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%F ", &timeptr ) == 11 ); - TESTCASE( strcmp( buffer, "1972-10-01 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%H ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "12 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%I ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "12 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%j ", &timeptr ) == 4 ); - TESTCASE( strcmp( buffer, "275 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%m ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "10 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%M ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "30 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%p ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "PM " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%r ", &timeptr ) == 12 ); - TESTCASE( strcmp( buffer, "12:30:59 PM " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%R ", &timeptr ) == 6 ); - TESTCASE( strcmp( buffer, "12:30 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%S ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "59 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%T ", &timeptr ) == 9 ); - TESTCASE( strcmp( buffer, "12:30:59 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%u ", &timeptr ) == 2 ); - TESTCASE( strcmp( buffer, "7 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%w ", &timeptr ) == 2 ); - TESTCASE( strcmp( buffer, "0 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%x ", &timeptr ) == 9 ); - TESTCASE( strcmp( buffer, "10/01/72 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%X ", &timeptr ) == 9 ); - TESTCASE( strcmp( buffer, "12:30:59 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%y ", &timeptr ) == 3 ); - TESTCASE( strcmp( buffer, "72 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%Y ", &timeptr ) == 5 ); - TESTCASE( strcmp( buffer, "1972 " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%% ", &timeptr ) == 2 ); - TESTCASE( strcmp( buffer, "% " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%n ", &timeptr ) == 2 ); - TESTCASE( strcmp( buffer, "\n " ) == 0 ); - TESTCASE( strftime( buffer, 100, "%t ", &timeptr ) == 2 ); - TESTCASE( strcmp( buffer, "\t " ) == 0 ); - TESTCASE( test_week_calc() ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/time.c b/rocklibc/src/time/time.c deleted file mode 100644 index 358d7f0..0000000 --- a/rocklibc/src/time/time.c +++ /dev/null @@ -1,48 +0,0 @@ -/* time( time_t * ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_defguard.h" - -#include "sys/time.h" - -/* See comments in _PDCLIB_config.h on the semantics of time_t. */ - -time_t time( time_t * timer ) -{ - struct timeval tv; - - if ( gettimeofday( &tv, NULL ) == 0 ) - { - if ( timer != NULL ) - { - *timer = tv.tv_sec; - } - - return tv.tv_sec; - } - - return -1; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - time_t t = time( NULL ); - printf( "%d\n", (int)t ); - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif diff --git a/rocklibc/src/time/timespec_get.c b/rocklibc/src/time/timespec_get.c deleted file mode 100644 index 13be220..0000000 --- a/rocklibc/src/time/timespec_get.c +++ /dev/null @@ -1,46 +0,0 @@ -/* timespec_get( struct timespec *, int ) - - This file is part of the Public Domain C Library (PDCLib). - Permission is granted to use, modify, and / or redistribute at will. -*/ - -#include - -#ifndef REGTEST - -#include "pdclib/_PDCLIB_defguard.h" - -#include "sys/time.h" - -int timespec_get( struct timespec * ts, int base ) -{ - if ( base == TIME_UTC ) - { - /* We can make do with a really thin wrapper here. */ - struct timeval tv; - - if ( gettimeofday( &tv, NULL ) == 0 ) - { - ts->tv_sec = tv.tv_sec; - ts->tv_nsec = tv.tv_usec * 1000; - return base; - } - } - - /* Not supporting any other time base than TIME_UTC for now. */ - return 0; -} - -#endif - -#ifdef TEST - -#include "_PDCLIB_test.h" - -int main( void ) -{ - TESTCASE( NO_TESTDRIVER ); - return TEST_RESULTS; -} - -#endif