diff --git a/src/cmd/cmd_c.ml b/src/cmd/cmd_c.ml index 472a7c57f..852e951e7 100644 --- a/src/cmd/cmd_c.ml +++ b/src/cmd/cmd_c.ml @@ -86,10 +86,9 @@ let compile ~workspace ~entry_point ~includes ~opt_lvl ~out_file Cmd.( of_list ( [ Fmt.str "-O%s" opt_lvl - ; "--target=wasm32-unknown-unknown" + ; "--sysroot=/home/drjoker/dev/c/wasi-libc/sysroot" + ; "--target=wasm32-wasi" ; "-m32" - ; "-ffreestanding" - ; "--no-standard-libraries" ; "-Wno-everything" ; "-flto=thin" ] @@ -103,6 +102,8 @@ let compile ~workspace ~entry_point ~includes ~opt_lvl ~out_file @ [ (* TODO: allow this behind a flag, this is slooooow *) "-Wl,--lto-O0" ; Fmt.str "-Wl,-z,stack-size=%s" stack_size + ; "-L$HOME/dev/c/wasi-libc/sysroot/lib/wasm32-wasi" + ; "-lc" ] ) %% includes ) in @@ -110,12 +111,9 @@ let compile ~workspace ~entry_point ~includes ~opt_lvl ~out_file let* clang_bin = OS.Cmd.resolve @@ Cmd.v "clang" in let out = Option.value ~default:Fpath.(workspace / "a.out.wasm") out_file in - let* libc = Cmd_utils.find_installed_c_file (Fpath.v "libc.wasm") in let* libowi = Cmd_utils.find_installed_c_file (Fpath.v "libowi.wasm") in - let files = - Cmd.of_list (List.map Fpath.to_string (libc :: libowi :: files)) - in + let files = Cmd.of_list (List.map Fpath.to_string (libowi :: files)) in let clang : Cmd.t = Cmd.(clang_bin %% flags % "-o" % p out %% files) in let err = diff --git a/src/lang_c/libowi/dune b/src/lang_c/dune similarity index 100% rename from src/lang_c/libowi/dune rename to src/lang_c/dune diff --git a/src/lang_c/libowi/include/dune b/src/lang_c/include/dune similarity index 100% rename from src/lang_c/libowi/include/dune rename to src/lang_c/include/dune diff --git a/src/lang_c/libowi/include/eacsl.h b/src/lang_c/include/eacsl.h similarity index 100% rename from src/lang_c/libowi/include/eacsl.h rename to src/lang_c/include/eacsl.h diff --git a/src/lang_c/libowi/include/klee.h b/src/lang_c/include/klee.h similarity index 100% rename from src/lang_c/libowi/include/klee.h rename to src/lang_c/include/klee.h diff --git a/src/lang_c/libowi/include/owi.h b/src/lang_c/include/owi.h similarity index 100% rename from src/lang_c/libowi/include/owi.h rename to src/lang_c/include/owi.h diff --git a/src/lang_c/libc/LICENSE_dietlibc b/src/lang_c/libc/LICENSE_dietlibc deleted file mode 100644 index b8306825e..000000000 --- a/src/lang_c/libc/LICENSE_dietlibc +++ /dev/null @@ -1,341 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc. - 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Library General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - , 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Library General -Public License instead of this License. - diff --git a/src/lang_c/libc/dune b/src/lang_c/libc/dune deleted file mode 100644 index 4455a9961..000000000 --- a/src/lang_c/libc/dune +++ /dev/null @@ -1,114 +0,0 @@ -(include_subdirs no) - -(executable - (name script) - (modules script)) - -(rule - (target libc.wasm) - (deps - stdlib.o - ctype.o - stdout.o - errno.o - strchr.o - math.o - strcmp.o - memccpy.o - strcpy.o - memchr.o - strdup.o - memcmp.o - strerror.o - memcpy.o - strftime.o - memmove.o - strlen.o - memset.o - strncmp.o - netinet_in.o - strncpy.o - strrchr.o - pthread.o - strstr.o - setjmp.o - sys_resources.o - stderr.o - time.o - stdio.o - unistd.o) - (action - (run wasm-ld %{deps} -o %{target} --no-entry --export-all --relocatable))) - -(rule - (targets - stdlib.o - ctype.o - stdout.o - errno.o - strchr.o - math.o - strcmp.o - memccpy.o - strcpy.o - memchr.o - strdup.o - memcmp.o - strerror.o - memcpy.o - strftime.o - memmove.o - strlen.o - memset.o - strncmp.o - netinet_in.o - strncpy.o - strrchr.o - pthread.o - strstr.o - setjmp.o - sys_resources.o - stderr.o - time.o - stdio.o - unistd.o) - (deps - src/stdlib.c - src/ctype.c - src/stdout.c - src/errno.c - src/strchr.c - src/math.c - src/strcmp.c - src/memccpy.c - src/strcpy.c - src/memchr.c - src/strdup.c - src/memcmp.c - src/strerror.c - src/memcpy.c - src/strftime.c - src/memmove.c - src/strlen.c - src/memset.c - src/strncmp.c - src/netinet_in.c - src/strncpy.c - src/strrchr.c - src/pthread.c - src/strstr.c - src/setjmp.c - src/sys_resources.c - src/stderr.c - src/time.c - src/stdio.c - src/unistd.c) - (action - (run ./script.exe %{deps}))) - -(install - (package owi) - (section - (site - (owi c_files))) - (files libc.wasm)) diff --git a/src/lang_c/libc/include/alloca.h b/src/lang_c/libc/include/alloca.h deleted file mode 100644 index 6a1dfd0c9..000000000 --- a/src/lang_c/libc/include/alloca.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef ALLOCA_H -#define ALLOCA_H - -#include - -void *alloca(size_t size); - -#endif diff --git a/src/lang_c/libc/include/assert.h b/src/lang_c/libc/include/assert.h deleted file mode 100644 index 2449b052d..000000000 --- a/src/lang_c/libc/include/assert.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef ASSERT_H -#define ASSERT_H - -#define static_assert(...) - -# if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L -# define __ASSERT_FUNCTION __func__ -# else -# define __ASSERT_FUNCTION (__func__ ? __func__ : "(unknown)") -# endif - - -extern void __assert_fail(const char *__assertion, const char *__file, - unsigned int __line, const char *__function); -#define assert(expr) \ - ((void)((expr) \ - ? 0 \ - : (__assert_fail(#expr, __FILE__, __LINE__, __ASSERT_FUNCTION), \ - 0))) - -#endif diff --git a/src/lang_c/libc/include/ctype.h b/src/lang_c/libc/include/ctype.h deleted file mode 100644 index 913679010..000000000 --- a/src/lang_c/libc/include/ctype.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef CTYPE_H -#define CTYPE_H - -extern int isascii(int c); -extern int isblank(int c); -extern int isalnum(int c); -extern int isalpha(int c); -extern int isdigit(int c); -extern int isspace(int c); - -extern int isupper(int c); -extern int islower(int c); - -extern int toascii(int c); -extern int tolower(int c); -extern int toupper(int c); - -extern int isprint(int c); -extern int ispunct(int c); -extern int iscntrl(int c); - -/* fscking GNU extensions! */ -extern int isxdigit(int c); - -extern int isgraph(int c); - -#endif diff --git a/src/lang_c/libc/include/dune b/src/lang_c/libc/include/dune deleted file mode 100644 index 1b128a7a1..000000000 --- a/src/lang_c/libc/include/dune +++ /dev/null @@ -1,35 +0,0 @@ -(install - (package owi) - (section - (site - (owi c_files))) - (files - (netinet/in.h as netinet/in.h) - (sys/cdefs.h as sys/cdefs.h) - (sys/param.h as sys/param.h) - (sys/resource.h as sys/resource.h) - (sys/time.h as sys/time.h) - (sys/types.h as sys/types.h) - alloca.h - assert.h - ctype.h - endian.h - errno.h - fcntl.h - inttypes.h - limits.h - math.h - pthread.h - sched.h - setjmp.h - signal.h - stdarg-cruft.h - stdarg.h - stdbool.h - stddef.h - stdint.h - stdio.h - stdlib.h - string.h - time.h - unistd.h)) diff --git a/src/lang_c/libc/include/endian.h b/src/lang_c/libc/include/endian.h deleted file mode 100644 index 9c53ea537..000000000 --- a/src/lang_c/libc/include/endian.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef ENDIAN_H -#define ENDIAN_H - -#endif diff --git a/src/lang_c/libc/include/errno.h b/src/lang_c/libc/include/errno.h deleted file mode 100644 index c51e38670..000000000 --- a/src/lang_c/libc/include/errno.h +++ /dev/null @@ -1,147 +0,0 @@ -#ifndef ERRNO_H -#define ERRNO_H - -#define EPERM 1 /* Operation not permitted */ -#define ENOENT 2 /* No such file or directory */ -#define ESRCH 3 /* No such process */ -#define EINTR 4 /* Interrupted system call */ -#define EIO 5 /* I/O error */ -#define ENXIO 6 /* No such device or address */ -#define E2BIG 7 /* Arg list too long */ -#define ENOEXEC 8 /* Exec format error */ -#define EBADF 9 /* Bad file number */ -#define ECHILD 10 /* No child processes */ -#define EAGAIN 11 /* Try again */ -#define ENOMEM 12 /* Out of memory */ -#define EACCES 13 /* Permission denied */ -#define EFAULT 14 /* Bad address */ -#define ENOTBLK 15 /* Block device required */ -#define EBUSY 16 /* Device or resource busy */ -#define EEXIST 17 /* File exists */ -#define EXDEV 18 /* Cross-device link */ -#define ENODEV 19 /* No such device */ -#define ENOTDIR 20 /* Not a directory */ -#define EISDIR 21 /* Is a directory */ -#define EINVAL 22 /* Invalid argument */ -#define ENFILE 23 /* File table overflow */ -#define EMFILE 24 /* Too many open files */ -#define ENOTTY 25 /* Not a typewriter */ -#define ETXTBSY 26 /* Text file busy */ -#define EFBIG 27 /* File too large */ -#define ENOSPC 28 /* No space left on device */ -#define ESPIPE 29 /* Illegal seek */ -#define EROFS 30 /* Read-only file system */ -#define EMLINK 31 /* Too many links */ -#define EPIPE 32 /* Broken pipe */ -#define EDOM 33 /* Math argument out of domain of func */ -#define ERANGE 34 /* Math result not representable */ -#define EDEADLK 35 /* Resource deadlock would occur */ -#define ENAMETOOLONG 36 /* File name too long */ -#define ENOLCK 37 /* No record locks available */ -#define ENOSYS 38 /* Function not implemented */ -#define ENOTEMPTY 39 /* Directory not empty */ -#define ELOOP 40 /* Too many symbolic links encountered */ -#define EWOULDBLOCK EAGAIN /* Operation would block */ -#define ENOMSG 42 /* No message of desired type */ -#define EIDRM 43 /* Identifier removed */ -#define ECHRNG 44 /* Channel number out of range */ -#define EL2NSYNC 45 /* Level 2 not synchronized */ -#define EL3HLT 46 /* Level 3 halted */ -#define EL3RST 47 /* Level 3 reset */ -#define ELNRNG 48 /* Link number out of range */ -#define EUNATCH 49 /* Protocol driver not attached */ -#define ENOCSI 50 /* No CSI structure available */ -#define EL2HLT 51 /* Level 2 halted */ -#define EBADE 52 /* Invalid exchange */ -#define EBADR 53 /* Invalid request descriptor */ -#define EXFULL 54 /* Exchange full */ -#define ENOANO 55 /* No anode */ -#define EBADRQC 56 /* Invalid request code */ -#define EBADSLT 57 /* Invalid slot */ -#define EDEADLOCK EDEADLK -#define EBFONT 59 /* Bad font file format */ -#define ENOSTR 60 /* Device not a stream */ -#define ENODATA 61 /* No data available */ -#define ETIME 62 /* Timer expired */ -#define ENOSR 63 /* Out of streams resources */ -#define ENONET 64 /* Machine is not on the network */ -#define ENOPKG 65 /* Package not installed */ -#define EREMOTE 66 /* Object is remote */ -#define ENOLINK 67 /* Link has been severed */ -#define EADV 68 /* Advertise error */ -#define ESRMNT 69 /* Srmount error */ -#define ECOMM 70 /* Communication error on send */ -#define EPROTO 71 /* Protocol error */ -#define EMULTIHOP 72 /* Multihop attempted */ -#define EDOTDOT 73 /* RFS specific error */ -#define EBADMSG 74 /* Not a data message */ -#define EOVERFLOW 75 /* Value too large for defined data type */ -#define ENOTUNIQ 76 /* Name not unique on network */ -#define EBADFD 77 /* File descriptor in bad state */ -#define EREMCHG 78 /* Remote address changed */ -#define ELIBACC 79 /* Can not access a needed shared library */ -#define ELIBBAD 80 /* Accessing a corrupted shared library */ -#define ELIBSCN 81 /* .lib section in a.out corrupted */ -#define ELIBMAX 82 /* Attempting to link in too many shared libraries */ -#define ELIBEXEC 83 /* Cannot exec a shared library directly */ -#define EILSEQ 84 /* Illegal byte sequence */ -#define ERESTART 85 /* Interrupted system call should be restarted */ -#define ESTRPIPE 86 /* Streams pipe error */ -#define EUSERS 87 /* Too many users */ -#define ENOTSOCK 88 /* Socket operation on non-socket */ -#define EDESTADDRREQ 89 /* Destination address required */ -#define EMSGSIZE 90 /* Message too long */ -#define EPROTOTYPE 91 /* Protocol wrong type for socket */ -#define ENOPROTOOPT 92 /* Protocol not available */ -#define EPROTONOSUPPORT 93 /* Protocol not supported */ -#define ESOCKTNOSUPPORT 94 /* Socket type not supported */ -#define EOPNOTSUPP 95 /* Operation not supported on transport endpoint */ -#define ENOTSUP EOPNOTSUPP /* Operation not supported on transport endpoint */ -#define EPFNOSUPPORT 96 /* Protocol family not supported */ -#define EAFNOSUPPORT 97 /* Address family not supported by protocol */ -#define EADDRINUSE 98 /* Address already in use */ -#define EADDRNOTAVAIL 99 /* Cannot assign requested address */ -#define ENETDOWN 100 /* Network is down */ -#define ENETUNREACH 101 /* Network is unreachable */ -#define ENETRESET 102 /* Network dropped connection because of reset */ -#define ECONNABORTED 103 /* Software caused connection abort */ -#define ECONNRESET 104 /* Connection reset by peer */ -#define ENOBUFS 105 /* No buffer space available */ -#define EISCONN 106 /* Transport endpoint is already connected */ -#define ENOTCONN 107 /* Transport endpoint is not connected */ -#define ESHUTDOWN 108 /* Cannot send after transport endpoint shutdown */ -#define ETOOMANYREFS 109 /* Too many references: cannot splice */ -#define ETIMEDOUT 110 /* Connection timed out */ -#define ECONNREFUSED 111 /* Connection refused */ -#define EHOSTDOWN 112 /* Host is down */ -#define EHOSTUNREACH 113 /* No route to host */ -#define EALREADY 114 /* Operation already in progress */ -#define EINPROGRESS 115 /* Operation now in progress */ -#define ESTALE 116 /* Stale NFS file handle */ -#define EUCLEAN 117 /* Structure needs cleaning */ -#define ENOTNAM 118 /* Not a XENIX named type file */ -#define ENAVAIL 119 /* No XENIX semaphores available */ -#define EISNAM 120 /* Is a named type file */ -#define EREMOTEIO 121 /* Remote I/O error */ -#define EDQUOT 122 /* Quota exceeded */ -#define ENOMEDIUM 123 /* No medium found */ -#define EMEDIUMTYPE 124 /* Wrong medium type */ -#define ECANCELED 125 /* Operation Canceled */ -#define ENOKEY 126 /* Required key not available */ -#define EKEYEXPIRED 127 /* Key has expired */ -#define EKEYREVOKED 128 /* Key has been revoked */ -#define EKEYREJECTED 129 /* Key was rejected by service */ - -/* for robust mutexes */ -#define EOWNERDEAD 130 /* Owner died */ -#define ENOTRECOVERABLE 131 /* State not recoverable */ - -#define ERFKILL 132 /* Operation not possible due to RF-kill */ - -#define EHWPOISON 133 /* Memory page has hardware error */ - -#define __SYS_NERR ((EHWPOISON) + 1) - -static int errno; - -#endif diff --git a/src/lang_c/libc/include/fcntl.h b/src/lang_c/libc/include/fcntl.h deleted file mode 100644 index 4cc5e3e0a..000000000 --- a/src/lang_c/libc/include/fcntl.h +++ /dev/null @@ -1,73 +0,0 @@ -#ifndef FCNTL_H -#define FCNTL_H - -#define F_LINUX_SPECIFIC_BASE 1024 - -#define O_ACCMODE 0003 -#define O_RDONLY 00 -#define O_WRONLY 01 -#define O_RDWR 02 -#define O_CREAT 0100 /* not fcntl */ -#define O_EXCL 0200 /* not fcntl */ -#define O_NOCTTY 0400 /* not fcntl */ -#define O_TRUNC 01000 /* not fcntl */ -#define O_APPEND 02000 -#define O_NONBLOCK 04000 -#define O_NDELAY O_NONBLOCK -#define O_DSYNC 010000 -#define FASYNC 020000 /* fcntl, for BSD compatibility */ -#define O_DIRECT 040000 /* direct disk access hint - currently ignored */ -#define O_LARGEFILE 0100000 -#define O_DIRECTORY 0200000 /* must be a directory */ -#define O_NOFOLLOW 0400000 /* don't follow links */ -#define O_NOATIME 01000000 -#define O_CLOEXEC 02000000 -#define O_SYNC (O_DSYNC | 04000000) -#define O_PATH 010000000 -#define __O_TMPFILE 020000000 - -#define F_DUPFD 0 /* dup */ -#define F_GETFD 1 /* get close_on_exec */ -#define F_SETFD 2 /* set/clear close_on_exec */ -#define F_GETFL 3 /* get file->f_flags */ -#define F_SETFL 4 /* set file->f_flags */ -#define F_GETLK 5 -#define F_SETLK 6 -#define F_SETLKW 7 -#define F_SETOWN 8 /* for sockets. */ -#define F_GETOWN 9 /* for sockets. */ -#define F_SETSIG 10 /* for sockets. */ -#define F_GETSIG 11 /* for sockets. */ - -#define F_GETLK64 12 /* using 'struct flock64' */ -#define F_SETLK64 13 -#define F_SETLKW64 14 - -#define FD_CLOEXEC 1 /* actually anything with low bit set goes */ - -/* for posix fcntl() and lockf() */ -#define F_RDLCK 0 -#define F_WRLCK 1 -#define F_UNLCK 2 - -/* for old implementation of bsd flock () */ -#define F_EXLCK 4 /* or 3 */ -#define F_SHLCK 8 /* or 4 */ - -/* for leases */ -#define F_INPROGRESS 16 - -/* operations for bsd flock(), also used by the kernel implementation */ -#define LOCK_SH 1 /* shared lock */ -#define LOCK_EX 2 /* exclusive lock */ -#define LOCK_NB \ - 4 /* or'd with one of the above to prevent \ - blocking */ -#define LOCK_UN 8 /* remove lock */ - -#define LOCK_MAND 32 /* This is a mandatory flock */ -#define LOCK_READ 64 /* ... Which allows concurrent read operations */ -#define LOCK_WRITE 128 /* ... Which allows concurrent write operations */ -#define LOCK_RW 192 /* ... Which allows concurrent read & write ops */ - -#endif diff --git a/src/lang_c/libc/include/inttypes.h b/src/lang_c/libc/include/inttypes.h deleted file mode 100644 index fa9b3f4a5..000000000 --- a/src/lang_c/libc/include/inttypes.h +++ /dev/null @@ -1,234 +0,0 @@ -#ifndef INTTYPES_H -#define INTTYPES_H - -#define __PRI64_PREFIX "ll" -#define __PRIPTR_PREFIX - -/* Decimal notation. */ -#define PRId8 "d" -#define PRId16 "d" -#define PRId32 "d" -#define PRId64 __PRI64_PREFIX "d" - -#define PRIdLEAST8 "d" -#define PRIdLEAST16 "d" -#define PRIdLEAST32 "d" -#define PRIdLEAST64 __PRI64_PREFIX "d" - -#define PRIdFAST8 "d" -#define PRIdFAST16 "d" -#define PRIdFAST32 "d" -#define PRIdFAST64 __PRI64_PREFIX "d" - -#define PRIi8 "i" -#define PRIi16 "i" -#define PRIi32 "i" -#define PRIi64 __PRI64_PREFIX "i" - -#define PRIiLEAST8 "i" -#define PRIiLEAST16 "i" -#define PRIiLEAST32 "i" -#define PRIiLEAST64 __PRI64_PREFIX "i" - -#define PRIiFAST8 "i" -#define PRIiFAST16 "i" -#define PRIiFAST32 "i" -#define PRIiFAST64 __PRI64_PREFIX "i" - -/* Octal notation. */ -#define PRIo8 "o" -#define PRIo16 "o" -#define PRIo32 "o" -#define PRIo64 __PRI64_PREFIX "o" - -#define PRIoLEAST8 "o" -#define PRIoLEAST16 "o" -#define PRIoLEAST32 "o" -#define PRIoLEAST64 __PRI64_PREFIX "o" - -#define PRIoFAST8 "o" -#define PRIoFAST16 "o" -#define PRIoFAST32 "o" -#define PRIoFAST64 __PRI64_PREFIX "o" - -/* Unsigned integers. */ -#define PRIu8 "u" -#define PRIu16 "u" -#define PRIu32 "u" -#define PRIu64 __PRI64_PREFIX "u" - -#define PRIuLEAST8 "u" -#define PRIuLEAST16 "u" -#define PRIuLEAST32 "u" -#define PRIuLEAST64 __PRI64_PREFIX "u" - -#define PRIuFAST8 "u" -#define PRIuFAST16 "u" -#define PRIuFAST32 "u" -#define PRIuFAST64 __PRI64_PREFIX "u" - -/* lowercase hexadecimal notation. */ -#define PRIx8 "x" -#define PRIx16 "x" -#define PRIx32 "x" -#define PRIx64 __PRI64_PREFIX "x" - -#define PRIxLEAST8 "x" -#define PRIxLEAST16 "x" -#define PRIxLEAST32 "x" -#define PRIxLEAST64 __PRI64_PREFIX "x" - -#define PRIxFAST8 "x" -#define PRIxFAST16 "x" -#define PRIxFAST32 "x" -#define PRIxFAST64 __PRI64_PREFIX "x" - -/* UPPERCASE hexadecimal notation. */ -#define PRIX8 "X" -#define PRIX16 "X" -#define PRIX32 "X" -#define PRIX64 __PRI64_PREFIX "X" - -#define PRIXLEAST8 "X" -#define PRIXLEAST16 "X" -#define PRIXLEAST32 "X" -#define PRIXLEAST64 __PRI64_PREFIX "X" - -#define PRIXFAST8 "X" -#define PRIXFAST16 "X" -#define PRIXFAST32 "X" -#define PRIXFAST64 __PRI64_PREFIX "X" - -/* Macros for printing `intmax_t' and `uintmax_t'. */ -#define PRIdMAX __PRI64_PREFIX "d" -#define PRIiMAX __PRI64_PREFIX "i" -#define PRIoMAX __PRI64_PREFIX "o" -#define PRIuMAX __PRI64_PREFIX "u" -#define PRIxMAX __PRI64_PREFIX "x" -#define PRIXMAX __PRI64_PREFIX "X" - -/* Macros for printing `intptr_t' and `uintptr_t'. */ -#define PRIdPTR __PRIPTR_PREFIX "d" -#define PRIiPTR __PRIPTR_PREFIX "i" -#define PRIoPTR __PRIPTR_PREFIX "o" -#define PRIuPTR __PRIPTR_PREFIX "u" -#define PRIxPTR __PRIPTR_PREFIX "x" -#define PRIXPTR __PRIPTR_PREFIX "X" - -/* Macros for scanning format specifiers. */ - -/* Signed decimal notation. */ -#define SCNd8 "hhd" -#define SCNd16 "hd" -#define SCNd32 "d" -#define SCNd64 __PRI64_PREFIX "d" - -#define SCNdLEAST8 "hhd" -#define SCNdLEAST16 "hd" -#define SCNdLEAST32 "d" -#define SCNdLEAST64 __PRI64_PREFIX "d" - -#define SCNdFAST8 "hhd" -#define SCNdFAST16 __PRIPTR_PREFIX "d" -#define SCNdFAST32 __PRIPTR_PREFIX "d" -#define SCNdFAST64 __PRI64_PREFIX "d" - -/* Signed decimal notation. */ -#define SCNi8 "hhi" -#define SCNi16 "hi" -#define SCNi32 "i" -#define SCNi64 __PRI64_PREFIX "i" - -#define SCNiLEAST8 "hhi" -#define SCNiLEAST16 "hi" -#define SCNiLEAST32 "i" -#define SCNiLEAST64 __PRI64_PREFIX "i" - -#define SCNiFAST8 "hhi" -#define SCNiFAST16 __PRIPTR_PREFIX "i" -#define SCNiFAST32 __PRIPTR_PREFIX "i" -#define SCNiFAST64 __PRI64_PREFIX "i" - -/* Unsigned decimal notation. */ -#define SCNu8 "hhu" -#define SCNu16 "hu" -#define SCNu32 "u" -#define SCNu64 __PRI64_PREFIX "u" - -#define SCNuLEAST8 "hhu" -#define SCNuLEAST16 "hu" -#define SCNuLEAST32 "u" -#define SCNuLEAST64 __PRI64_PREFIX "u" - -#define SCNuFAST8 "hhu" -#define SCNuFAST16 __PRIPTR_PREFIX "u" -#define SCNuFAST32 __PRIPTR_PREFIX "u" -#define SCNuFAST64 __PRI64_PREFIX "u" - -/* Octal notation. */ -#define SCNo8 "hho" -#define SCNo16 "ho" -#define SCNo32 "o" -#define SCNo64 __PRI64_PREFIX "o" - -#define SCNoLEAST8 "hho" -#define SCNoLEAST16 "ho" -#define SCNoLEAST32 "o" -#define SCNoLEAST64 __PRI64_PREFIX "o" - -#define SCNoFAST8 "hho" -#define SCNoFAST16 __PRIPTR_PREFIX "o" -#define SCNoFAST32 __PRIPTR_PREFIX "o" -#define SCNoFAST64 __PRI64_PREFIX "o" - -/* Hexadecimal notation. */ -#define SCNx8 "hhx" -#define SCNx16 "hx" -#define SCNx32 "x" -#define SCNx64 __PRI64_PREFIX "x" - -#define SCNxLEAST8 "hhx" -#define SCNxLEAST16 "hx" -#define SCNxLEAST32 "x" -#define SCNxLEAST64 __PRI64_PREFIX "x" - -#define SCNxFAST8 "hhx" -#define SCNxFAST16 __PRIPTR_PREFIX "x" -#define SCNxFAST32 __PRIPTR_PREFIX "x" -#define SCNxFAST64 __PRI64_PREFIX "x" - -/* Macros for scanning `intmax_t' and `uintmax_t'. */ -#define SCNdMAX __PRI64_PREFIX "d" -#define SCNiMAX __PRI64_PREFIX "i" -#define SCNoMAX __PRI64_PREFIX "o" -#define SCNuMAX __PRI64_PREFIX "u" -#define SCNxMAX __PRI64_PREFIX "x" - -/* Macros for scanning `intptr_t' and `uintptr_t'. */ -#define SCNdPTR __PRIPTR_PREFIX "d" -#define SCNiPTR __PRIPTR_PREFIX "i" -#define SCNoPTR __PRIPTR_PREFIX "o" -#define SCNuPTR __PRIPTR_PREFIX "u" -#define SCNxPTR __PRIPTR_PREFIX "x" - -typedef signed char int8_t; -typedef unsigned char uint8_t; -typedef short int16_t; -typedef unsigned short uint16_t; -typedef int int32_t; -typedef unsigned int uint32_t; -typedef long long int64_t; -typedef unsigned long long uint64_t; -typedef long long intmax_t; -typedef unsigned long long uintmax_t; -#ifndef __FRAMAC__ -typedef __int128 int128_t; -typedef unsigned __int128 uint128_t; -typedef int intptr_t; -typedef unsigned int uintptr_t; -#else -typedef long int intptr_t; -typedef unsigned long int uintptr_t; -#endif - -#endif diff --git a/src/lang_c/libc/include/limits.h b/src/lang_c/libc/include/limits.h deleted file mode 100644 index fec9984e6..000000000 --- a/src/lang_c/libc/include/limits.h +++ /dev/null @@ -1,85 +0,0 @@ -#ifndef _LIMITS_H -#define _LIMITS_H - -#include - -#ifndef __SCHAR_MAX__ -#define __SCHAR_MAX__ 0x7f -#endif -#ifndef __SHRT_MAX__ -#define __SHRT_MAX__ 0x7fff -#endif -#ifndef __INT_MAX__ -#define __INT_MAX__ 0x7fffffff -#endif -#ifndef __LONG_MAX__ -#define __LONG_MAX__ 0x7fffffffl -#endif - -#define CHAR_BIT 8 - -#define SCHAR_MIN (-1 - SCHAR_MAX) -#define SCHAR_MAX (__SCHAR_MAX__) -#define UCHAR_MAX (SCHAR_MAX * 2 + 1) - -#ifdef __CHAR_UNSIGNED__ -#undef CHAR_MIN -#define CHAR_MIN 0 -#undef CHAR_MAX -#define CHAR_MAX UCHAR_MAX -#else -#undef CHAR_MIN -#define CHAR_MIN SCHAR_MIN -#undef CHAR_MAX -#define CHAR_MAX SCHAR_MAX -#endif - -#define SHRT_MIN (-1 - SHRT_MAX) -#define SHRT_MAX (__SHRT_MAX__) -#define USHRT_MAX (SHRT_MAX * 2 + 1) - -#define INT_MIN (-1 - INT_MAX) -#define INT_MAX (__INT_MAX__) -#define UINT_MAX (INT_MAX * 2u + 1) - -#define LONG_MIN (-1l - LONG_MAX) -#define LONG_MAX (__LONG_MAX__) -#define ULONG_MAX (LONG_MAX * 2ul + 1) - -#define LLONG_MAX 0x7fffffffffffffffll -#define LLONG_MIN (-1ll - LLONG_MAX) - -/* Maximum value an `unsigned long long int' can hold. (Minimum is 0.) */ -#define ULLONG_MAX (~0ull) - -#define SSIZE_MIN LONG_MIN -#define SSIZE_MAX LONG_MAX - -#define PASS_MAX 256 - -#define NR_OPEN 1024 - -#define NGROUPS_MAX 32 /* supplemental group IDs are available */ -#define ARG_MAX 131072 /* # bytes of args + environ for exec() */ -#define CHILD_MAX 999 /* no limit :-) */ -#define OPEN_MAX 256 /* # open files a process may have */ -#define LINK_MAX 127 /* # links a file may have */ -#define MAX_CANON 255 /* size of the canonical input queue */ -#define MAX_INPUT 255 /* size of the type-ahead buffer */ -#define NAME_MAX 255 /* # chars in a file name */ -#define PATH_MAX 4095 /* # chars in a path name */ -#define PIPE_BUF 4096 /* # bytes in atomic write to a pipe */ - -#define RTSIG_MAX 32 - -#define LINE_MAX 2048 - -/* mutt demanded these */ -#define _POSIX_PATH_MAX PATH_MAX -#define MB_LEN_MAX 16 - -#ifdef _XOPEN_SOURCE -#define IOV_MAX 1024 -#endif - -#endif diff --git a/src/lang_c/libc/include/math.h b/src/lang_c/libc/include/math.h deleted file mode 100644 index 39aeeb1fc..000000000 --- a/src/lang_c/libc/include/math.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef _MATH_H_ -#define _MATH_H_ - -double sin(double); -double cos(double); -double floor(double); -double round(double); -float powf(float x, float y); -float floorf(float x); -double ceil(double x); -double sqrt(double x); -float roundf(float x); -float log2f(float x); -float sqrtf(float x); - -#endif diff --git a/src/lang_c/libc/include/netinet/in.h b/src/lang_c/libc/include/netinet/in.h deleted file mode 100644 index 9c71f8e34..000000000 --- a/src/lang_c/libc/include/netinet/in.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef NETINET_IN_H -#define NETINET_IN_H - -#include - -uint32_t htonl(uint32_t hostlong); -uint16_t htons(uint16_t hostshort); -uint32_t ntohl(uint32_t netlong); -uint16_t ntohs(uint16_t netshort); - -#endif diff --git a/src/lang_c/libc/include/pthread.h b/src/lang_c/libc/include/pthread.h deleted file mode 100644 index d3446d60a..000000000 --- a/src/lang_c/libc/include/pthread.h +++ /dev/null @@ -1,163 +0,0 @@ -#ifndef PTHREAD_H -#define PTHREAD_H - -#include - -#define PTHREAD_STACK_MIN 16384 -#define PTHREAD_STACK_MAX (8 << 20) - -struct _pthread_descr_struct { - int empty; -}; - -typedef struct _pthread_descr_struct *_pthread_descr; -typedef int pthread_t; - -/* Fast locks */ -struct _pthread_fastlock { - int __spinlock; -}; - -#define PTHREAD_SPIN_LOCKED 1 -#define PTHREAD_SPIN_UNLOCKED 0 - -/* Mutexes */ -typedef struct { - struct _pthread_fastlock lock; - _pthread_descr owner; - int kind; - unsigned int count; -} pthread_mutex_t; - -enum { - PTHREAD_MUTEX_FAST_NP, -#define PTHREAD_MUTEX_FAST_NP PTHREAD_MUTEX_FAST_NP -#define PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_FAST_NP - PTHREAD_MUTEX_RECURSIVE_NP, -#define PTHREAD_MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE_NP - PTHREAD_MUTEX_ERRORCHECK_NP, -#define PTHREAD_MUTEX_ERRORCHECK_NP PTHREAD_MUTEX_ERRORCHECK_NP -}; - -enum { - PTHREAD_PROCESS_PRIVATE, -#define PTHREAD_PROCESS_PRIVATE PTHREAD_PROCESS_PRIVATE - PTHREAD_PROCESS_SHARED -#define PTHREAD_PROCESS_SHARED PTHREAD_PROCESS_SHARED -}; - -#define PTHREAD_MUTEX_INITIALIZER \ - { {PTHREAD_SPIN_UNLOCKED}, 0, PTHREAD_MUTEX_FAST_NP, 0 } - -#define PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP \ - { {PTHREAD_SPIN_UNLOCKED}, 0, PTHREAD_MUTEX_RECURSIVE_NP, 0 } - -#define PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP \ - { {PTHREAD_SPIN_UNLOCKED}, 0, PTHREAD_MUTEX_ERRORCHECK_NP, 0 } - -typedef struct { - int __mutexkind; -} pthread_mutexattr_t; - -int pthread_mutexattr_init(pthread_mutexattr_t *attr); -int pthread_mutexattr_destroy(pthread_mutexattr_t *attr); - -int pthread_mutexattr_getkind_np(const pthread_mutexattr_t *attr, int *kind); -int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind); - -int pthread_mutex_init(pthread_mutex_t *mutex, - const pthread_mutexattr_t *mutexattr); -int pthread_mutex_lock(pthread_mutex_t *mutex); -int pthread_mutex_unlock(pthread_mutex_t *mutex); -int pthread_mutex_trylock(pthread_mutex_t *mutex); -int pthread_mutex_destroy(pthread_mutex_t *mutex); - -int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type); - -typedef void *pthread_condattr_t; - -typedef struct { - struct _pthread_fastlock lock; - _pthread_descr wait_chain; -} pthread_cond_t; - -#define PTHREAD_COND_INITIALIZER \ - { {PTHREAD_SPIN_UNLOCKED}, 0 } - -int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr); -int pthread_cond_destroy(pthread_cond_t *cond); -int pthread_cond_signal(pthread_cond_t *cond); -int pthread_cond_broadcast(pthread_cond_t *cond); -int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - const struct timespec *abstime); -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex); - -typedef int pthread_once_t; - -/* Attributes for threads. */ -typedef struct { - int __detachstate; - int __schedpolicy; - struct sched_param __schedparam; - int __inheritsched; - int __scope; - void *__stackaddr; - unsigned long __stacksize; -} pthread_attr_t; - -enum { - PTHREAD_CREATE_JOINABLE, -#define PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_JOINABLE - PTHREAD_CREATE_DETACHED -#define PTHREAD_CREATE_DETACHED PTHREAD_CREATE_DETACHED -}; - -enum { - PTHREAD_EXPLICIT_SCHED, -#define PTHREAD_EXPLICIT_SCHED PTHREAD_EXPLICIT_SCHED - PTHREAD_INHERIT_SCHED -#define PTHREAD_INHERIT_SCHED PTHREAD_INHERIT_SCHED -}; - -enum { /* for completeness */ - PTHREAD_SCOPE_SYSTEM, -#define PTHREAD_SCOPE_SYSTEM PTHREAD_SCOPE_SYSTEM - PTHREAD_SCOPE_PROCESS -#define PTHREAD_SCOPE_PROCESS PTHREAD_SCOPE_PROCESS -}; - -typedef struct { - unsigned int n; -} pthread_rwlock_t; - -typedef struct { - int dummy; -} pthread_rwlockattr_t; - -#define PTHREAD_RWLOCK_INITIALIZER \ - { 0 } - -int pthread_rwlock_init(pthread_rwlock_t *rwlock, - const pthread_rwlockattr_t *attr); -int pthread_rwlock_destroy(pthread_rwlock_t *rwlock); -// pthread_rwlock_t rwlock=PTHREAD_RWLOCK_INITIALIZER; -int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock); -int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock); -int pthread_rwlockattr_init(pthread_rwlockattr_t *attr); -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr); -int pthread_rwlock_unlock(pthread_rwlock_t *rwlock); - -int pthread_detach(pthread_t __th); -int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)); -int pthread_attr_init(pthread_attr_t *attr); -int pthread_attr_destroy(pthread_attr_t *attr); -int pthread_attr_setstacksize(pthread_attr_t *attr, const size_t stacksize); -int pthread_create(pthread_t *__threadarg, const pthread_attr_t *__attr, - void *(*__start_routine)(void *), void *__arg); -int pthread_join(pthread_t __th, void **__thread_return); -pthread_t pthread_self(void); -int pthread_equal(pthread_t __thread1, pthread_t __thread2); - -#endif diff --git a/src/lang_c/libc/include/sched.h b/src/lang_c/libc/include/sched.h deleted file mode 100644 index ab19da226..000000000 --- a/src/lang_c/libc/include/sched.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef SCHED_H -#define SCHED_H - -#include -#include - -/* - * Scheduling policies - */ -#define SCHED_OTHER 0 -#define SCHED_FIFO 1 -#define SCHED_RR 2 - -/* - * This is an additional bit set when we want to - * yield the CPU for one re-schedule.. - */ -#define SCHED_YIELD 0x10 - -struct sched_param { - int sched_priority; -}; - -#endif diff --git a/src/lang_c/libc/include/setjmp.h b/src/lang_c/libc/include/setjmp.h deleted file mode 100644 index 614333a91..000000000 --- a/src/lang_c/libc/include/setjmp.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef _SETJMP_H_ -#define _SETJMP_H_ - -struct __jmp_buf_tag {}; - -int setjmp(struct __jmp_buf_tag *); - -#endif diff --git a/src/lang_c/libc/include/signal.h b/src/lang_c/libc/include/signal.h deleted file mode 100644 index c74febeed..000000000 --- a/src/lang_c/libc/include/signal.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SIGNAL_H -#define SIGNAL_H - -#define NSIG 32 -#define _NSIG 65 - -#define SIGHUP 1 -#define SIGINT 2 -#define SIGQUIT 3 -#define SIGILL 4 -#define SIGTRAP 5 -#define SIGABRT 6 -#define SIGIOT 6 -#define SIGFPE 8 -#define SIGKILL 9 -#define SIGSEGV 11 -#define SIGPIPE 13 -#define SIGALRM 14 -#define SIGTERM 15 -#define SIGUNUSED 31 -#define SIGBUS 7 -#define SIGUSR1 10 -#define SIGUSR2 12 -#define SIGSTKFLT 16 -#define SIGCHLD 17 -#define SIGCONT 18 -#define SIGSTOP 19 -#define SIGTSTP 20 -#define SIGTTIN 21 -#define SIGTTOU 22 -#define SIGURG 23 -#define SIGXCPU 24 -#define SIGXFSZ 25 -#define SIGVTALRM 26 -#define SIGPROF 27 -#define SIGWINCH 28 -#define SIGIO 29 -#define SIGPWR 30 -#define SIGSYS 31 - -#define SIGCLD SIGCHLD -#define SIGPOLL SIGIO - -/* These should not be considered constants from userland. */ -#define SIGLOST SIGPWR -#define SIGRTMIN 32 -#define SIGRTMAX (_NSIG - 1) - -#endif diff --git a/src/lang_c/libc/include/stdarg-cruft.h b/src/lang_c/libc/include/stdarg-cruft.h deleted file mode 100644 index a29086132..000000000 --- a/src/lang_c/libc/include/stdarg-cruft.h +++ /dev/null @@ -1,286 +0,0 @@ -#include - -#if defined(__sparc__) || defined(__alpha__) || defined(__mips__) -enum { - __no_type_class = -1, - __void_type_class, - __integer_type_class, - __char_type_class, - __enumeral_type_class, - __boolean_type_class, - __pointer_type_class, - __reference_type_class, - __offset_type_class, - __real_type_class, - __complex_type_class, - __function_type_class, - __method_type_class, - __record_type_class, - __union_type_class, - __array_type_class, - __string_type_class, - __set_type_class, - __file_type_class, - __lang_type_class -}; -#endif - -#if defined(__sparc__) - -typedef char *va_list; -#define va_end(ap) ap = 0 - -#define va_start(AP, LASTARG) \ - (__builtin_next_arg(LASTARG), AP = (char *)__builtin_saveregs()) - -#define __va_rounded_size(TYPE) \ - (((sizeof(TYPE) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) - -/* We don't declare the union member `d' to have type TYPE - because that would lose in C++ if TYPE has a constructor. */ -/* We cast to void * and then to TYPE * because this avoids - a warning about increasing the alignment requirement. - The casts to char * avoid warnings about invalid pointer arithmetic. */ -#define va_arg(pvar, TYPE) \ - __extension__(*({ \ - ((__builtin_classify_type(*(TYPE *)0) >= __record_type_class || \ - (__builtin_classify_type(*(TYPE *)0) == __real_type_class && \ - sizeof(TYPE) == 16)) \ - ? ((pvar) = (char *)(pvar) + __va_rounded_size(TYPE *), \ - *(TYPE **)(void *)((char *)(pvar)-__va_rounded_size(TYPE *))) \ - : __va_rounded_size(TYPE) == 8 \ - ? ({ \ - union { \ - char __d[sizeof(TYPE)]; \ - int __i[2]; \ - } __u; \ - __u.__i[0] = ((int *)(void *)(pvar))[0]; \ - __u.__i[1] = ((int *)(void *)(pvar))[1]; \ - (pvar) = (char *)(pvar) + 8; \ - (TYPE *)(void *)__u.__d; \ - }) \ - : ((pvar) = (char *)(pvar) + __va_rounded_size(TYPE), \ - ((TYPE *)(void *)((char *)(pvar)-__va_rounded_size(TYPE))))); \ - })) - -#elif defined(__mips__) - -typedef char *va_list; - -#ifdef __mips64__ -#define __va_rounded_size(__TYPE) (((sizeof(__TYPE) + 8 - 1) / 8) * 8) -#else -#define __va_rounded_size(__TYPE) \ - (((sizeof(__TYPE) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) -#endif -#ifdef __mips64__ -#define __va_reg_size 8 -#else -#define __va_reg_size 4 -#endif - -#define va_start(__AP, __LASTARG) \ - (__AP = (va_list)__builtin_next_arg(__LASTARG)) - -#ifdef __mips64__ -#ifdef __MIPSEB__ -#define va_arg(__AP, __type) \ - ((__type *)(void *)(__AP = \ - (char *)((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) + \ - __va_rounded_size(__type))))[-1] -#else -#define va_arg(__AP, __type) \ - ((__AP = (char *)((((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8) + \ - __va_rounded_size(__type))), \ - *(__type *)(void *)(__AP - __va_rounded_size(__type))) -#endif - -#else /* not __mips64 */ - -#ifdef __MIPSEB__ -/* For big-endian machines. */ -#define va_arg(__AP, __type) \ - ((__AP = (char *)((__alignof__(__type) > 4 \ - ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & -8 \ - : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & -4) + \ - __va_rounded_size(__type))), \ - *(__type *)(void *)(__AP - __va_rounded_size(__type))) -#else -/* For little-endian machines. */ -#define va_arg(__AP, __type) \ - ((__type *)(void *)(__AP = \ - (char *)((__alignof__(__type) > 4 \ - ? ((__PTRDIFF_TYPE__)__AP + 8 - 1) & \ - -8 \ - : ((__PTRDIFF_TYPE__)__AP + 4 - 1) & \ - -4) + \ - __va_rounded_size(__type))))[-1] -#endif -#endif - -#elif defined(__powerpc__) - -typedef struct __va_list_tag { - unsigned char gpr; /* index into the array of 8 GPRs stored in the - register save area gpr=0 corresponds to r3, - gpr=1 to r4, etc. */ - unsigned char fpr; /* index into the array of 8 FPRs stored in the - register save area fpr=0 corresponds to f1, - fpr=1 to f2, etc. */ - char *overflow_arg_area; /* location on stack that holds the next - overflow argument */ - char *reg_save_area; /* where r3:r10 and f1:f8, if saved are stored */ -} va_list[1]; - -#define __va_overflow(AP) (AP)->overflow_arg_area -#ifdef __OPTIMIZE__ -extern void __va_arg_type_violation(void) __attribute__((__noreturn__)); -#else -#define __va_arg_type_violation() -#endif - -typedef struct { - long __gp_save[8]; /* save area for GP registers */ - double __fp_save[8]; /* save area for FP registers */ -} __va_regsave_t; - -/* Macros to access the register save area */ -/* We cast to void * and then to TYPE * because this avoids - a warning about increasing the alignment requirement. */ -#define __VA_FP_REGSAVE(AP, OFS, TYPE) \ - ((TYPE *)(void *)(&(((__va_regsave_t *)(AP)->reg_save_area)->__fp_save[OFS]))) - -#define __VA_GP_REGSAVE(AP, OFS, TYPE) \ - ((TYPE *)(void *)(&(((__va_regsave_t *)(AP)->reg_save_area)->__gp_save[OFS]))) - -#define __va_start_common(AP, FAKE) \ - __builtin_memcpy((AP), __builtin_saveregs(), sizeof(va_list)) - -#define va_start(AP, LASTARG) \ - (__builtin_next_arg(LASTARG), __va_start_common(AP, 0)) - -#ifdef _SOFT_FLOAT -#define __va_float_p(TYPE) 0 -#else -#define __va_float_p(TYPE) (__builtin_classify_type(*(TYPE *)0) == 8) -#endif - -#define __va_aggregate_p(TYPE) (__builtin_classify_type(*(TYPE *)0) >= 12) -#define __va_size(TYPE) ((sizeof(TYPE) + sizeof(long) - 1) / sizeof(long)) - -#define va_arg(AP, TYPE) \ - __extension__(*({ \ - register TYPE *__ptr; \ - \ - if (__va_float_p(TYPE) && sizeof(TYPE) < 16) { \ - unsigned char __fpr = (AP)->fpr; \ - if (__fpr < 8) { \ - __ptr = __VA_FP_REGSAVE(AP, __fpr, TYPE); \ - (AP)->fpr = __fpr + 1; \ - } else if (sizeof(TYPE) == 8) { \ - unsigned long __addr = (unsigned long)(__va_overflow(AP)); \ - __ptr = (TYPE *)((__addr + 7) & -8); \ - __va_overflow(AP) = (char *)(__ptr + 1); \ - } else { \ - /* float is promoted to double. */ \ - __va_arg_type_violation(); \ - } \ - } \ - \ - /* Aggregates and long doubles are passed by reference. */ \ - else if (__va_aggregate_p(TYPE) || __va_float_p(TYPE)) { \ - unsigned char __gpr = (AP)->gpr; \ - if (__gpr < 8) { \ - __ptr = *__VA_GP_REGSAVE(AP, __gpr, TYPE *); \ - (AP)->gpr = __gpr + 1; \ - } else { \ - TYPE **__pptr = (TYPE **)(__va_overflow(AP)); \ - __ptr = *__pptr; \ - __va_overflow(AP) = (char *)(__pptr + 1); \ - } \ - } \ - \ - /* Only integrals remaining. */ \ - else { \ - /* longlong is aligned. */ \ - if (sizeof(TYPE) == 8) { \ - unsigned char __gpr = (AP)->gpr; \ - if (__gpr < 7) { \ - __gpr += __gpr & 1; \ - __ptr = __VA_GP_REGSAVE(AP, __gpr, TYPE); \ - (AP)->gpr = __gpr + 2; \ - } else { \ - unsigned long __addr = (unsigned long)(__va_overflow(AP)); \ - __ptr = (TYPE *)((__addr + 7) & -8); \ - (AP)->gpr = 8; \ - __va_overflow(AP) = (char *)(__ptr + 1); \ - } \ - } else if (sizeof(TYPE) == 4) { \ - unsigned char __gpr = (AP)->gpr; \ - if (__gpr < 8) { \ - __ptr = __VA_GP_REGSAVE(AP, __gpr, TYPE); \ - (AP)->gpr = __gpr + 1; \ - } else { \ - __ptr = (TYPE *)__va_overflow(AP); \ - __va_overflow(AP) = (char *)(__ptr + 1); \ - } \ - } else { \ - /* Everything else was promoted to int. */ \ - __va_arg_type_violation(); \ - } \ - } \ - __ptr; \ - })) - -#define va_end(AP) ((void)0) - -/* Copy va_list into another variable of this type. */ -#define __va_copy(dest, src) *(dest) = *(src) - -#elif defined(__alpha__) - -typedef struct { - char *__base; /* Pointer to first integer register. */ - int __offset; /* Byte offset of args so far. */ -} va_list; - -#define va_start(pvar, firstarg) \ - (__builtin_next_arg(firstarg), (pvar) = *(va_list *)__builtin_saveregs()) -#define va_end(__va) ((void)0) - -#define __va_tsize(__type) \ - (((sizeof(__type) + __extension__ sizeof(long long) - 1) / \ - __extension__ sizeof(long long)) * \ - __extension__ sizeof(long long)) - -#define va_arg(__va, __type) \ - (*(((__va).__offset += __va_tsize(__type)), \ - (__type *)(void *)((__va).__base + (__va).__offset - \ - (((__builtin_classify_type(*(__type *)0) == \ - __real_type_class) && \ - (__va).__offset <= (6 * 8)) \ - ? (6 * 8) + 8 \ - : __va_tsize(__type))))) - -#else /* !__sparc__ && !__powerpc__ && !__mips__ && !__alpha__*/ - -typedef char *va_list; - -/* this only works when everything is passed on the stack (i.e. x86) */ -#if __WORDSIZE == 64 -#define va_start(ap, argn) ap = ((char *)&argn) + 8 -#else -#define va_start(ap, argn) ap = ((char *)&argn) + 4 -#endif -#define va_arg(ap, type) \ - (ap += sizeof(type), *(type *)((void *)ap - sizeof(type))) - -#endif - -#ifndef __va_copy -#define __va_copy(x, y) x = y -#endif - -#ifndef va_end -#define va_end(ap) ((void)0) -#endif diff --git a/src/lang_c/libc/include/stdarg.h b/src/lang_c/libc/include/stdarg.h deleted file mode 100644 index 7d8c39b4b..000000000 --- a/src/lang_c/libc/include/stdarg.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _STDARG_H -#define _STDARG_H - -#include - -typedef __builtin_va_list va_list; -#define va_start(ap, param) __builtin_va_start(ap, param) -#define va_end(ap) __builtin_va_end(ap) -#define va_arg(ap, type) __builtin_va_arg(ap, type) - -#ifndef va_end -#include -#endif - -#if !defined(__STRICT_ANSI__) || __STDC_VERSION__ + 0 >= 199900L -#define va_copy(d, s) __va_copy(d, s) -#endif - -#endif diff --git a/src/lang_c/libc/include/stdbool.h b/src/lang_c/libc/include/stdbool.h deleted file mode 100644 index 5faf6e899..000000000 --- a/src/lang_c/libc/include/stdbool.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef _STDBOOL_H -#define _STDBOOL_H - -/* believe it or not but the Single Unix Specification actually - * specifies this header, see - * http://www.opengroup.org/onlinepubs/007904975/basedefs/stdbool.h.html */ - -#define bool _Bool -#define true 1 -#define false 0 -#define __bool_true_false_are_defined 1 - -#endif diff --git a/src/lang_c/libc/include/stddef.h b/src/lang_c/libc/include/stddef.h deleted file mode 100644 index 4a7856e10..000000000 --- a/src/lang_c/libc/include/stddef.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef STDDEF_H -#define STDDEF_H - -typedef signed long ptrdiff_t; -typedef unsigned long size_t; - -#if defined(__cplusplus) -#else -typedef int wchar_t; -#endif - - -#undef NULL -#if defined(__cplusplus) -#define NULL 0 -#else -#define NULL (void *)0 -#endif - -#undef offsetof -#if defined(__GNUC__) && (__GNUC >= 3) -#define offsetof(type, member) __builtin_offsetof(type, member) -#else -#define offsetof(type, member) ((size_t) & ((type *)0)->member) -#endif - -#endif diff --git a/src/lang_c/libc/include/stdint.h b/src/lang_c/libc/include/stdint.h deleted file mode 100644 index 0351ed849..000000000 --- a/src/lang_c/libc/include/stdint.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef STDINT_H -#define STDINT_H - -#include - -typedef int8_t int_least8_t; -typedef int16_t int_least16_t; -typedef int32_t int_least32_t; -typedef int64_t int_least64_t; - -typedef uint8_t uint_least8_t; -typedef uint16_t uint_least16_t; -typedef uint32_t uint_least32_t; -typedef uint64_t uint_least64_t; - -typedef signed char int_fast8_t; -typedef signed long int int_fast16_t; -typedef signed long int int_fast32_t; -typedef int64_t int_fast64_t; - -typedef unsigned char uint_fast8_t; -typedef unsigned long int uint_fast16_t; -typedef unsigned long int uint_fast32_t; -typedef uint64_t uint_fast64_t; - -/* The ISO C99 standard specifies that in C++ implementations these - should only be defined if explicitly requested. */ - -#define INT8_MAX (127) -#define INT16_MAX (32767) -#define INT32_MAX (2147483647) -#define INT64_MAX (9223372036854775807ll) - -#define INT8_MIN (-1 - INT8_MAX) -#define INT16_MIN (-1 - INT16_MAX) -#define INT32_MIN (-1 - INT32_MAX) -#define INT64_MIN (-1 - INT64_MAX) - -#define INT_LEAST8_MAX INT8_MAX -#define INT_LEAST8_MIN INT8_MIN -#define INT_LEAST16_MAX INT16_MAX -#define INT_LEAST16_MIN INT16_MIN -#define INT_LEAST32_MAX INT32_MAX -#define INT_LEAST32_MIN INT32_MIN -#define INT_LEAST64_MAX INT64_MAX -#define INT_LEAST64_MIN INT64_MIN - -#define UINT8_MAX 0xff -#define UINT16_MAX 0xffff -#define UINT32_MAX 0xfffffffful -#define UINT64_MAX 0xffffffffffffffffull - -#define UINT_LEAST8_MAX UINT8_MAX -#define UINT_LEAST16_MAX UINT16_MAX -#define UINT_LEAST32_MAX UINT32_MAX -#define UINT_LEAST64_MAX UINT64_MAX - -#if __WORDSIZE == 64 -#define INTPTR_MIN INT64_MIN -#define INTPTR_MAX INT64_MAX -#define UINTPTR_MAX UINT64_MAX -#else -#define INTPTR_MIN INT32_MIN -#define INTPTR_MAX INT32_MAX -#define UINTPTR_MAX UINT32_MAX -#endif - -#define SIZE_MAX UINTPTR_MAX -#define PTRDIFF_MIN INTPTR_MIN -#define PTRDIFF_MAX INTPTR_MAX - -#define INTMAX_MIN INT64_MIN -#define INTMAX_MAX INT64_MAX -#define UINTMAX_MAX UINT64_MAX - -#define INT_FAST8_MIN INT8_MIN -#define INT_FAST8_MAX INT8_MAX -#define INT_FAST64_MIN INT64_MIN -#define INT_FAST64_MAX INT64_MAX - -#define UINT_FAST8_MAX UINT8_MAX -#define UINT_FAST64_MAX UINT64_MAX - -#define INT_FAST16_MIN INTPTR_MIN -#define INT_FAST16_MAX INTPTR_MAX -#define UINT_FAST16_MAX UINTPTR_MAX - -#define INT_FAST32_MIN INTPTR_MIN -#define INT_FAST32_MAX INTPTR_MAX -#define UINT_FAST32_MAX UINTPTR_MAX - -#define SIG_ATOMIC_MAX ((int)(~0u << sizeof(int) * 8 - 1)) -#define SIG_ATOMIC_MIN ((int)((~0u << sizeof(int) * 8 - 1) - 1)) - -#ifndef WCHAR_MIN -#define WCHAR_MIN ((int)(~0u << sizeof(int) * 8 - 1)) -#define WCHAR_MAX ((int)((~0u << sizeof(int) * 8 - 1) - 1)) -#endif - -#define WINT_MIN 0 -#define WINT_MAX (~(wint_t)0) - -/* The ISO C99 standard specifies that in C++ implementations these - should only be defined if explicitly requested. */ - -/* Signed. */ -#define INT8_C(c) c -#define INT16_C(c) c -#define INT32_C(c) c -#if __WORDSIZE == 64 -#define INT64_C(c) c##L -#else -#define INT64_C(c) c##LL -#endif - -/* Unsigned. */ -#define UINT8_C(c) c -#define UINT16_C(c) c -#define UINT32_C(c) c##U -#if __WORDSIZE == 64 -#define UINT64_C(c) c##UL -#else -#define UINT64_C(c) c##ULL -#endif - -/* Maximal type. */ -#if __WORDSIZE == 64 -#define INTMAX_C(c) c##L -#define UINTMAX_C(c) c##UL -#else -#define INTMAX_C(c) c##LL -#define UINTMAX_C(c) c##ULL -#endif - -#endif diff --git a/src/lang_c/libc/include/stdio.h b/src/lang_c/libc/include/stdio.h deleted file mode 100644 index 47b15903a..000000000 --- a/src/lang_c/libc/include/stdio.h +++ /dev/null @@ -1,95 +0,0 @@ -#ifndef STDIO_H -#define STDIO_H - -#include -#include - -#define BUFSIZE 128 - -struct __stdio_file { - int fd; - int flags; - uint32_t bs; /* read: bytes in buffer */ - uint32_t bm; /* position in buffer */ - uint32_t buflen; /* length of buf */ - char *buf; - struct __stdio_file *next; /* for fflush */ - pid_t popen_kludge; - unsigned char ungetbuf; - char ungotten; -}; - -typedef struct __stdio_file FILE; - -extern FILE *stdin, *stdout, *stderr; - -#define ERRORINDICATOR 1 -#define EOFINDICATOR 2 -#define BUFINPUT 4 -#define BUFLINEWISE 8 -#define NOBUF 16 -#define STATICBUF 32 -#define FDPIPE 64 -#define CANREAD 128 -#define CANWRITE 256 -#define CHECKLINEWISE 512 - -#define _IONBF 0 -#define _IOLBF 1 -#define _IOFBF 2 - -int puts(const char *); -int fputs(const char *s, FILE *stream); -int putchar(int); -int printf(const char *format, ...); -int fprintf(FILE *stream, const char *format, ...); -int sprintf(char *str, const char *format, ...); -int swprintf(wchar_t *, wchar_t const *, ...); -int snprintf(char *str, size_t size, const char *format, ...); -int asprintf(char **ptr, const char *format, ...); - -int scanf(const char *format, ...); -int fscanf(FILE *stream, const char *format, ...); -int sscanf(const char *str, const char *format, ...); - -int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap); -int vsnprintf(char *str, size_t size, const char *format, va_list ap); - -char getchar(void); - -int fflush(FILE *stream); -int ferror(FILE *stream); -size_t fread(void *ptr, size_t size, size_t nmemb, FILE *restrict stream); - -int vasprintf(char **s, const char *fmt, va_list ap); -/* -int vprintf(const char *format, va_list ap); -int vfprintf(FILE *stream, const char *format, va_list ap); -int vsprintf(char *str, const char *format, va_list ap); - -int fdprintf(int fd, const char *format, ...) __THROW -__attribute__((__format__(__printf__,2,3))); int vfdprintf(int fd, const char -*format, va_list ap) __THROW __attribute__((__format__(__printf__,2,0))); - -int vscanf(const char *format, va_list ap) __THROW -__attribute__((__format__(__scanf__,1,0))); int vsscanf(const char *str, const -char *format, va_list ap) __THROW __attribute__((__format__(__scanf__,2,0))); -int vfscanf(FILE *stream, const char *format, va_list ap) __THROW -__attribute__((__format__(__scanf__,2,0))); - -*/ - -void perror(const char *s); - -int fclose(FILE *stream); -FILE *fopen(const char *path, const char *mode); -int feof(FILE *stream); -size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream); -char *fgets(char *s, int size, FILE *stream); -long ftell(FILE *stream); - -FILE *popen(const char *command, const char *type); -int pclose(FILE *stream); - -FILE *open_memstream(char **ptr, size_t *sizeloc); -#endif diff --git a/src/lang_c/libc/include/stdlib.h b/src/lang_c/libc/include/stdlib.h deleted file mode 100644 index ce9b9f34b..000000000 --- a/src/lang_c/libc/include/stdlib.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef STDLIB_H -#define STDLIB_H - -#include -#include - -#define EXIT_SUCCESS 0 -#define EXIT_FAILURE 1 - - -void abort(void); -void exit(int); -__attribute__((import_module("owi"), import_name("alloc"))) void *owi_malloc(void *, unsigned int); -__attribute__((import_module("owi"), import_name("dealloc"))) void *owi_free(void *); - -void *malloc(size_t size); -void free(void *ptr); -void *realloc(void *, size_t); -void *alloca(size_t); -void *calloc(size_t, size_t); - -char *getenv(const char *name); -int setenv(const char *name, const char *value, int overwrite); -int unsetenv(const char *name); - -int atoi(const char *nptr); -double strtod(const char *str, char **endptr); -long int strtol(const char *nptr, char **endptr, int base); -long long int strtoll(const char *nptr, char **endptr, int base); -unsigned long int strtoul(const char *nptr, char **endptr, int base); -unsigned long long int strtoull(const char *nptr, char **endptr, int base); - -void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); - -#endif diff --git a/src/lang_c/libc/include/string.h b/src/lang_c/libc/include/string.h deleted file mode 100644 index 247364a72..000000000 --- a/src/lang_c/libc/include/string.h +++ /dev/null @@ -1,36 +0,0 @@ -#ifndef STRING_H -#define STRING_H - -#include -#include -#include - -char *strcpy(char *, const char *); - -void *memccpy(void *__restrict__ dest, const void *__restrict__ src, int c, - size_t n); -void *memmove(void *dest, const void *src, size_t n); - -void *memset(void *, int, size_t); -int memcmp(const void *s1, const void *s2, size_t n); -void *memcpy(void *, const void *, size_t); - -char *strncpy(char *, const char *, size_t); -int strncmp(const char *s1, const char *s2, size_t n); - -int strcmp(const char *s1, const char *s2); - -size_t strlen(const char *s); - -char *strstr(const char *hatstack, const char *needle); - -char *strdup(const char *s); - -char *strchr(const char *str, int c); -char *strrchr(const char *str, int c); - -void *memchr(const void *s, int c, size_t n); - -char *strerror(int errnum); - -#endif diff --git a/src/lang_c/libc/include/sys/cdefs.h b/src/lang_c/libc/include/sys/cdefs.h deleted file mode 100644 index b78712b9d..000000000 --- a/src/lang_c/libc/include/sys/cdefs.h +++ /dev/null @@ -1,142 +0,0 @@ -#ifndef _SYS_CDEFS_H -#define _SYS_CDEFS_H - -#ifndef __cplusplus -#define __THROW -#define __BEGIN_DECLS -#define __END_DECLS -#else -#define __THROW throw() -#define __BEGIN_DECLS extern "C" { -#define __END_DECLS } -#endif - -#ifndef __GNUC__ -#define __attribute__(xyz) -#define __extension__ -#endif - -#if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) -#define __leaf , __leaf__ -#else -#define __leaf -#endif - -#if !defined(__cplusplus) && \ - ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3))) -#undef __THROW -#define __THROW __attribute__((__nothrow__ __leaf)) -#define __THROWNL __attribute__((__nothrow__)) -#endif - -#ifndef __THROWNL -#define __THROWNL __THROW -#endif - -#if (__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 96)) -#define __pure __attribute__((__pure__)) -#else -#define __pure -#endif - -#if (__GNUC__ == 2) && (__GNUC_MINOR__ < 95) -#define __restrict__ -#endif - -#ifndef __STRICT_ANSI__ -#define restrict __restrict__ -#if __GNUC__ < 3 -#define __builtin_expect(foo, bar) (foo) -#define __expect(foo, bar) (foo) -#define __malloc__ -#else -#define __expect(foo, bar) __builtin_expect((long)(foo), bar) -#define __attribute_malloc__ __attribute__((__malloc__)) -#endif -#endif - -/* idea for these macros taken from Linux kernel */ -#define __likely(foo) __expect((foo), 1) -#define __unlikely(foo) __expect((foo), 0) - -#ifndef __attribute_malloc__ -#define __attribute_malloc__ -#endif - -#define __P(x) x - -#define __ptr_t void * - -#if defined(__STRICT_ANSI__) && __STDC_VERSION__ + 0 < 199900L -#define inline -#endif - -#ifndef __i386__ -#define __regparm__(x) -#endif - -#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 2)) -#define __attribute_dontuse__ __attribute__((__deprecated__)) -#else -#define __attribute_dontuse__ -#define __deprecated__ -#endif - -#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 3)) -#define __nonnull(params) __attribute__((__nonnull__ params)) -#else -#define __nonnull(params) -#endif - -#if (__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 4)) -#define __attribute_used __attribute__((__used__)) -#else -#define __attribute_used -#define __warn_unused_result__ -#endif - -#if (__GNUC__ >= 4) -#define __needsNULL__(x) __sentinel__(x) -#else -#define __needsNULL__(x) -#define __sentinel__ -#endif - -#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) -#define __cold__ -#define __hot__ -#endif - -#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 3)) -#define __attribute_alloc__(x) -#define __attribute_alloc2__(x, y) -#else -#define __attribute_alloc__(x) __attribute__((alloc_size(x))) -#define __attribute_alloc2__(x, y) __attribute__((alloc_size(x, y))) -#endif - -#if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 5)) -#define __attribute_const__ -#else -#define __attribute_const__ __attribute__((const)) -#endif - -#if (__GNUC__ < 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ < 8)) -#define __attribute_formatarg__(x) -#else -#define __attribute_formatarg__(x) __attribute__((format_arg(x))) -#endif - -#if (__GNUC__ < 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ < 1)) -#define __noinline__ -#else -#define __noinline__ __attribute__((noinline)) -#endif - -#if (__GNUC__ < 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ < 6)) -#define __hidden__ -#else -#define __hidden__ __attribute__((visibility("hidden"))) -#endif - -#endif diff --git a/src/lang_c/libc/include/sys/param.h b/src/lang_c/libc/include/sys/param.h deleted file mode 100644 index 7b0e5af6c..000000000 --- a/src/lang_c/libc/include/sys/param.h +++ /dev/null @@ -1,4 +0,0 @@ -#ifndef PARAM_H -#define PARAM_H - -#endif diff --git a/src/lang_c/libc/include/sys/resource.h b/src/lang_c/libc/include/sys/resource.h deleted file mode 100644 index d4404a759..000000000 --- a/src/lang_c/libc/include/sys/resource.h +++ /dev/null @@ -1,92 +0,0 @@ -#ifndef _SYS_RESOURCE_H -#define _SYS_RESOURCE_H - -#include - -#define RUSAGE_SELF 0 -#define RUSAGE_CHILDREN (-1) -#define RUSAGE_BOTH (-2) /* sys_wait4() uses this */ - -struct rusage { - struct timeval ru_utime; /* user time used */ - struct timeval ru_stime; /* system time used */ - long ru_maxrss; /* maximum resident set size */ - long ru_ixrss; /* integral shared memory size */ - long ru_idrss; /* integral unshared data size */ - long ru_isrss; /* integral unshared stack size */ - long ru_minflt; /* page reclaims */ - long ru_majflt; /* page faults */ - long ru_nswap; /* swaps */ - long ru_inblock; /* block input operations */ - long ru_oublock; /* block output operations */ - long ru_msgsnd; /* messages sent */ - long ru_msgrcv; /* messages received */ - long ru_nsignals; /* signals received */ - long ru_nvcsw; /* voluntary context switches */ - long ru_nivcsw; /* involuntary " */ -}; - -struct rlimit { - unsigned long rlim_cur; - unsigned long rlim_max; -}; - -#define PRIO_MIN (-20) -#define PRIO_MAX 20 - -#define PRIO_PROCESS 0 -#define PRIO_PGRP 1 -#define PRIO_USER 2 - -#define RLIMIT_CPU 0 /* CPU time in ms */ -#define RLIMIT_FSIZE 1 /* Maximum filesize */ -#define RLIMIT_DATA 2 /* max data size */ -#define RLIMIT_STACK 3 /* max stack size */ -#define RLIMIT_CORE 4 /* max core file size */ -#if defined(__alpha__) -#define RLIMIT_RSS 5 /* max resident set size */ -#define RLIMIT_NPROC 8 /* max number of processes */ -#define RLIMIT_NOFILE 6 /* max number of open files */ -#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ -#define RLIMIT_AS 7 /* address space limit */ -#elif defined(__mips__) -#define RLIMIT_RSS 7 /* max resident set size */ -#define RLIMIT_NPROC 8 /* max number of processes */ -#define RLIMIT_NOFILE 5 /* max number of open files */ -#define RLIMIT_MEMLOCK 9 /* max locked-in-memory address space */ -#define RLIMIT_AS 6 /* address space limit */ -#elif defined(__sparc__) -#define RLIMIT_RSS 5 /* max resident set size */ -#define RLIMIT_NPROC 7 /* max number of processes */ -#define RLIMIT_NOFILE 6 /* max number of open files */ -#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ -#define RLIMIT_AS 9 /* address space limit */ -#else -#define RLIMIT_RSS 5 /* max resident set size */ -#define RLIMIT_NPROC 6 /* max number of processes */ -#define RLIMIT_NOFILE 7 /* max number of open files */ -#define RLIMIT_MEMLOCK 8 /* max locked-in-memory address space */ -#define RLIMIT_AS 9 /* address space limit */ -#endif -#define RLIMIT_LOCKS 10 /* maximum file locks held */ -#define RLIMIT_SIGPENDING 11 /* max number of pending signals */ -#define RLIMIT_MSGQUEUE 12 /* maximum bytes in POSIX mqueues */ -#define RLIMIT_NICE \ - 13 /* max nice prio allowed to raise to \ - 0-39 for nice level 19 .. -20 */ -#define RLIMIT_RTPRIO 14 /* maximum realtime priority */ -#define RLIMIT_RTTIME 15 /* timeout for RT tasks in us */ -#define RLIM_NLIMITS 16 - -#define RLIM_INFINITY (~0UL) - -int getpriority(int which, int who); -int setpriority(int which, int who, int prio); - -int getrlimit(int resource, struct rlimit *rlim); -int getrusage(int who, struct rusage *usage); -int setrlimit(int resource, const struct rlimit *rlim); - -typedef unsigned long rlim_t; - -#endif diff --git a/src/lang_c/libc/include/sys/time.h b/src/lang_c/libc/include/sys/time.h deleted file mode 100644 index 51de6fcf6..000000000 --- a/src/lang_c/libc/include/sys/time.h +++ /dev/null @@ -1,52 +0,0 @@ -#ifndef SYS_TIME_H -#define SYS_TIME_H - -#include - -struct timespec { - time_t tv_sec; /* seconds */ - long tv_nsec; /* nanoseconds */ -}; - -struct timeval { - time_t tv_sec; /* seconds */ - suseconds_t tv_usec; /* microseconds */ -}; - -struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ -}; - -#define ITIMER_REAL 0 -#define ITIMER_VIRTUAL 1 -#define ITIMER_PROF 2 - -struct itimerspec { - struct timespec it_interval; /* timer period */ - struct timespec it_value; /* timer expiration */ -}; - -struct itimerval { - struct timeval it_interval; /* timer interval */ - struct timeval it_value; /* current value */ -}; - -typedef struct timezone *__timezone_ptr_t; - -struct tm { - int tm_sec; /* Seconds. [0-60] (1 leap second) */ - int tm_min; /* Minutes. [0-59] */ - int tm_hour; /* Hours. [0-23] */ - int tm_mday; /* Day. [1-31] */ - int tm_mon; /* Month. [0-11] */ - int tm_year; /* Year - 1900. */ - int tm_wday; /* Day of week. [0-6] */ - int tm_yday; /* Days in year.[0-365] */ - int tm_isdst; /* DST. [-1/0/1]*/ - - long int tm_gmtoff; /* Seconds east of UTC. */ - const char *tm_zone; /* Timezone abbreviation. */ -}; - -#endif diff --git a/src/lang_c/libc/include/sys/types.h b/src/lang_c/libc/include/sys/types.h deleted file mode 100644 index eeb46f231..000000000 --- a/src/lang_c/libc/include/sys/types.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef TYPES_H -#define TYPES_H - -#include -#include - -typedef signed long ssize_t; - -typedef signed long suseconds_t; /* Used for time in microseconds. */ -typedef signed long useconds_t; /* Used for time in microseconds. */ - -typedef signed long long time_t; - -typedef int32_t pid_t; - -typedef uint32_t uid32_t; -typedef uint32_t gid32_t; - -typedef int32_t clockid_t; -typedef int32_t timer_t; - -typedef long int fpos_t; - -typedef uint32_t socklen_t; -typedef uint16_t sa_family_t; - -#endif diff --git a/src/lang_c/libc/include/time.h b/src/lang_c/libc/include/time.h deleted file mode 100644 index 9f30d830c..000000000 --- a/src/lang_c/libc/include/time.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef TIME_H -#define TIME_H - -#include - -#define CLOCK_REALTIME 0 -#define CLOCK_MONOTONIC 1 -#define CLOCK_PROCESS_CPUTIME_ID 2 -#define CLOCK_THREAD_CPUTIME_ID 3 -#define CLOCK_REALTIME_HR 4 -#define CLOCK_MONOTONIC_HR 5 - -int clock_gettime(clockid_t clock_id, struct timespec *tp); - -time_t time(time_t *t); -time_t timegm(struct tm *timeptr); -time_t mktime(struct tm *timeptr); - -char *ctime(const time_t *timep); - -struct tm *localtime_r(const time_t *t, struct tm *r); -struct tm *gmtime_r(const time_t *t, struct tm *r); - -#endif diff --git a/src/lang_c/libc/include/unistd.h b/src/lang_c/libc/include/unistd.h deleted file mode 100644 index 0c91fe967..000000000 --- a/src/lang_c/libc/include/unistd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef UNISTD_H -#define UNISTD_H - -#include - -extern int optind, opterr, optopt; -extern char *optarg; - -/* int open(const char* pathname,int flags, ...); */ -int close(int fd); -ssize_t read(int fd, void *buf, size_t len) __attribute__ ((weak));; -int getopt(int argc, char *argv[], const char *optstring) __attribute__ ((weak)); - -#endif diff --git a/src/lang_c/libc/script.ml b/src/lang_c/libc/script.ml deleted file mode 100644 index 01a3789b7..000000000 --- a/src/lang_c/libc/script.ml +++ /dev/null @@ -1,25 +0,0 @@ -(* SPDX-License-Identifier: AGPL-3.0-or-later *) -(* Copyright © 2021-2024 OCamlPro *) -(* Written by the Owi programmers *) - -let () = - if Array.length Sys.argv < 2 then - Format.ksprintf failwith "usage: %s " Sys.argv.(0) - -let () = - for i = 1 to Array.length Sys.argv - 1 do - let c_filename = Sys.argv.(i) in - if Filename.extension c_filename = ".c" then begin - let filename = Filename.basename c_filename |> Filename.chop_extension in - let out = Format.sprintf "%s.o" filename in - let n = - Format.ksprintf Sys.command - "clang -O3 -ffreestanding --no-standard-libraries --target=wasm32 -c \ - -m32 -Iinclude -Wall -Werror -Wno-int-conversion -Wno-return-type \ - -fbracket-depth=512 -DWANT_STRTOD_WITHOUT_LONG_DOUBLE -o %s %s" - out c_filename - in - if n <> 0 then exit n - end - else assert false - done diff --git a/src/lang_c/libc/src/ctype.c b/src/lang_c/libc/src/ctype.c deleted file mode 100644 index 238ffa9c9..000000000 --- a/src/lang_c/libc/src/ctype.c +++ /dev/null @@ -1,71 +0,0 @@ -#include - -int isascii(int c) { - return !(c&~0x7f); -} - -int isblank(int c) { - return c == ' ' || c == '\t'; -} - -int isalpha(int c) { - return ((unsigned)c|32)-'a' < 26; -} - -int isdigit(int c) { - return (unsigned)c-'0' < 10; -} - -int isalnum(int c) { - return isalpha(c) || isdigit(c); -} - -int isspace(int c) { - return c == ' ' || (unsigned)c-'\t' < 5; -} - -int isupper(int c) { - return (unsigned)c-'A' < 26; -} - -int islower(int c) { - return (unsigned)c-'a' < 26; -} - -int tolower(int c) { - if (isupper(c)) { - return c | 32; - } - return c; -} - -int toupper(int c) { - if (islower(c)) { - return c & 0x5f; - } - return c; -} - -int toascii(int c) { - return c & 0x7f; -} - -int isprint(int c) { - return (unsigned)c-0x20 < 0x5f; -} - -int isgraph(int c) { - return (unsigned)c-0x21 < 0x5e; -} - -int ispunct(int c) { - return isgraph(c) && !isalnum(c); -} - -int iscntrl(int c) { - return (unsigned)c < 0x20 || c == 0x7f; -} - -int isxdigit(int c) { - return isdigit(c) || ((unsigned)c|32)-'a' < 6; -} diff --git a/src/lang_c/libc/src/errno.c b/src/lang_c/libc/src/errno.c deleted file mode 100644 index 339f4fc10..000000000 --- a/src/lang_c/libc/src/errno.c +++ /dev/null @@ -1 +0,0 @@ -#include diff --git a/src/lang_c/libc/src/math.c b/src/lang_c/libc/src/math.c deleted file mode 100644 index 2cba57288..000000000 --- a/src/lang_c/libc/src/math.c +++ /dev/null @@ -1,31 +0,0 @@ -#include - -// TODO: External to OWI -double sin(double x) { return x; } -double cos(double x) { return x; } -double floor(double x) { return x; } -double round(double x) { return x; } -float powf(float x, float y) { return x; } -float floorf(float x) { return x; } -double ceil(double x) { return x; } -double sqrt(double x) { return x; } -float roundf(float x) { return x; } -float log2f(float x) { return x; } -float sqrtf(float x) { return x; } -float fabsf(float x) { - __asm__ __volatile__( - "local.get 0;" - "f32.abs;" - "return;" - ); -} -/* -int isnan(float x) { - __asm__ __volatile__( - "local.get 0;" - "local.get 0;" - "f32.ne;" - "return;" - ); -} -*/ diff --git a/src/lang_c/libc/src/memccpy.c b/src/lang_c/libc/src/memccpy.c deleted file mode 100644 index cd6fe91f9..000000000 --- a/src/lang_c/libc/src/memccpy.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - -void *memccpy(void *dst, const void *src, int c, size_t count) { - char *a = dst; - const char *b = src; - while (count--) { - *a++ = *b; - if (*b == c) { - return (void *)a; - } - b++; - } - return 0; -} diff --git a/src/lang_c/libc/src/memchr.c b/src/lang_c/libc/src/memchr.c deleted file mode 100644 index 20b2a6321..000000000 --- a/src/lang_c/libc/src/memchr.c +++ /dev/null @@ -1,9 +0,0 @@ -#include - -void *memchr(const void *s, int c, size_t n) { - const unsigned char *pc = (unsigned char *)s; - for (; n--; pc++) - if (*pc == c) - return ((void *)pc); - return 0; -} diff --git a/src/lang_c/libc/src/memcmp.c b/src/lang_c/libc/src/memcmp.c deleted file mode 100644 index 22bb62c31..000000000 --- a/src/lang_c/libc/src/memcmp.c +++ /dev/null @@ -1,21 +0,0 @@ -#include -#include - -/* gcc is broken and has a non-SUSv2 compliant internal prototype. - * This causes it to warn about a type mismatch here. Ignore it. */ -int memcmp(const void *dst, const void *src, size_t count) { - register int r; - register const unsigned char *d = dst; - register const unsigned char *s = src; - ++count; - while (--count) { - // TODO: check this change ! - r = (*d - *s); - if (r) { - return r; - } - ++d; - ++s; - } - return 0; -} diff --git a/src/lang_c/libc/src/memcpy.c b/src/lang_c/libc/src/memcpy.c deleted file mode 100644 index b8be62ef4..000000000 --- a/src/lang_c/libc/src/memcpy.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -void *memcpy(void *dst, const void *src, size_t n) { - void *res = dst; - unsigned char *c1, *c2; - c1 = (unsigned char *)dst; - c2 = (unsigned char *)src; - while (n--) - *c1++ = *c2++; - return (res); -} diff --git a/src/lang_c/libc/src/memmove.c b/src/lang_c/libc/src/memmove.c deleted file mode 100644 index 5fe665703..000000000 --- a/src/lang_c/libc/src/memmove.c +++ /dev/null @@ -1,19 +0,0 @@ -#include -#include - -void *memmove(void *dst, const void *src, size_t count) { - char *a = dst; - const char *b = src; - if (src != dst) { - if (src > dst) { - while (count--) - *a++ = *b++; - } else { - a += count - 1; - b += count - 1; - while (count--) - *a-- = *b--; - } - } - return dst; -} diff --git a/src/lang_c/libc/src/memset.c b/src/lang_c/libc/src/memset.c deleted file mode 100644 index 8a3998f86..000000000 --- a/src/lang_c/libc/src/memset.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -/* gcc is broken and has a non-SUSv2 compliant internal prototype. - * This causes it to warn about a type mismatch here. Ignore it. */ -void *memset(void *dst, int s, size_t count) { - register char *a = dst; - count++; /* this actually creates smaller code than using count-- */ - while (--count) - *a++ = s; - return dst; -} diff --git a/src/lang_c/libc/src/netinet_in.c b/src/lang_c/libc/src/netinet_in.c deleted file mode 100644 index e0c66163e..000000000 --- a/src/lang_c/libc/src/netinet_in.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -uint32_t htonl(uint32_t hostlong) { - return (hostlong >> 24) | ((hostlong & 0xff0000) >> 8) | - ((hostlong & 0xff00) << 8) | (hostlong << 24); -} - -uint16_t htons(uint16_t hostshort) { - return ((hostshort >> 8) & 0xff) | (hostshort << 8); -} - -uint32_t ntohl(uint32_t hostlong) __attribute__((weak, alias("htonl"))); -uint16_t ntohs(uint16_t hostshort) __attribute__((weak, alias("htons"))); diff --git a/src/lang_c/libc/src/pthread.c b/src/lang_c/libc/src/pthread.c deleted file mode 100644 index 3cd10e1c3..000000000 --- a/src/lang_c/libc/src/pthread.c +++ /dev/null @@ -1,67 +0,0 @@ -#include - -int pthread_mutexattr_init(pthread_mutexattr_t *attr) { return 0; } -int pthread_mutexattr_destroy(pthread_mutexattr_t *attr) { return 0; } - -int pthread_mutexattr_getkind_np(const pthread_mutexattr_t *attr, int *kind) { - return 0; -} -int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind) { - return 0; -} - -int pthread_mutex_init(pthread_mutex_t *mutex, - const pthread_mutexattr_t *mutexattr) { - return 0; -} -int pthread_mutex_lock(pthread_mutex_t *mutex) { return 0; } -int pthread_mutex_unlock(pthread_mutex_t *mutex) { return 0; } -int pthread_mutex_trylock(pthread_mutex_t *mutex) { return 0; } -int pthread_mutex_destroy(pthread_mutex_t *mutex) { return 0; } - -int pthread_cond_init(pthread_cond_t *cond, pthread_condattr_t *cond_attr) { - return 0; -} -int pthread_cond_destroy(pthread_cond_t *cond) { return 0; } -int pthread_cond_signal(pthread_cond_t *cond) { return 0; } -int pthread_cond_broadcast(pthread_cond_t *cond) { return 0; } -int pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - const struct timespec *abstime) { - return 0; -} -int pthread_cond_wait(pthread_cond_t *cond, pthread_mutex_t *mutex) { - return 0; -} - -int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type) { return 0; } - -int pthread_rwlock_init(pthread_rwlock_t *rwlock, - const pthread_rwlockattr_t *attr) { - return 0; -} -int pthread_rwlock_destroy(pthread_rwlock_t *rwlock) { return 0; } - -int pthread_rwlock_rdlock(pthread_rwlock_t *rwlock) { return 0; } -int pthread_rwlock_tryrdlock(pthread_rwlock_t *rwlock) { return 0; } -int pthread_rwlock_wrlock(pthread_rwlock_t *rwlock) { return 0; } -int pthread_rwlock_trywrlock(pthread_rwlock_t *rwlock) { return 0; } -int pthread_rwlockattr_init(pthread_rwlockattr_t *attr) { return 0; } -int pthread_rwlockattr_destroy(pthread_rwlockattr_t *attr) { return 0; } -int pthread_rwlock_unlock(pthread_rwlock_t *rwlock) { return 0; } - -int pthread_detach(pthread_t __th) { return 0; } -int pthread_once(pthread_once_t *once_control, void (*init_routine)(void)) { - return 0; -} -int pthread_attr_init(pthread_attr_t *attr) { return 0; } -int pthread_attr_destroy(pthread_attr_t *attr) { return 0; } -int pthread_attr_setstacksize(pthread_attr_t *attr, const size_t stacksize) { - return 0; -} -int pthread_create(pthread_t *__threadarg, const pthread_attr_t *__attr, - void *(*__start_routine)(void *), void *__arg) { - return 0; -} -int pthread_join(pthread_t __th, void **__thread_return) { return 0; } -pthread_t pthread_self(void) { return 0; } -int pthread_equal(pthread_t __thread1, pthread_t __thread2) { return 0; } diff --git a/src/lang_c/libc/src/setjmp.c b/src/lang_c/libc/src/setjmp.c deleted file mode 100644 index 86f4c039c..000000000 --- a/src/lang_c/libc/src/setjmp.c +++ /dev/null @@ -1,3 +0,0 @@ -#include - -int setjmp(struct __jmp_buf_tag *tag) { return 0; } diff --git a/src/lang_c/libc/src/stderr.c b/src/lang_c/libc/src/stderr.c deleted file mode 100644 index 6273ec86a..000000000 --- a/src/lang_c/libc/src/stderr.c +++ /dev/null @@ -1,25 +0,0 @@ -#include - -static FILE __stderr = { - .fd = 2, - .flags = NOBUF | CANWRITE, - .bs = 0, - .bm = 0, - .buflen = 0, - .buf = 0, - .next = 0, - .popen_kludge = 0, - .ungetbuf = 0, - .ungotten = 0, -#ifdef WANT_THREAD_SAFE - .m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, -#endif -}; - -FILE *stderr = &__stderr; - -/* -int __fflush_stderr(void) { - return fflush(stderr); -} -*/ diff --git a/src/lang_c/libc/src/stdio.c b/src/lang_c/libc/src/stdio.c deleted file mode 100644 index 3480a9597..000000000 --- a/src/lang_c/libc/src/stdio.c +++ /dev/null @@ -1,57 +0,0 @@ -#include - -FILE *stdin = &(FILE){0}; - -int puts(const char *str) { return 0; } - -int fputs(const char *s, FILE *stream) { return 0; } - -int putchar(int c) { return 0; } - -int printf(const char *format, ...) { return 0; } - -int fprintf(FILE *stream, const char *format, ...) { return 0; } - -int sprintf(char *str, const char *format, ...) { return 0; } - -int swprintf(wchar_t *ptr1, const wchar_t *ptr2, ...) { return 0; } - -int snprintf(char *str, size_t size, const char *format, ...) { return 0; } - -int asprintf(char **ptr, const char *format, ...) { return 0; } - -int scanf(const char *format, ...) { return 0; } -int fscanf(FILE *stream, const char *format, ...) { return 0; } -int sscanf(const char *str, const char *format, ...) { return 0; } - -int fflush(FILE *stream) { return 0; } -int ferror(FILE *stream) { return 0; } -size_t fread(void *ptr, size_t size, size_t nmemb, FILE *restrict stream) { - return 0; -} - -void perror(const char *s) {} - -int fclose(FILE *stream) { return 0; } -FILE *fopen(const char *path, const char *mode) { return 0; } -int feof(FILE *stream) { return 0; } -size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream) { - return 0; -} -char *fgets(char *s, int size, FILE *stream) { return 0; } -long ftell(FILE *stream) { return 0; } - -FILE *popen(const char *command, const char *type) { return 0; } -int pclose(FILE *stream) { return 0; } - -int vfprintf(FILE *restrict stream, const char *restrict format, va_list ap) { - return 0; -} -int vsnprintf(char *str, size_t size, const char *format, va_list ap) { - return 0; -} - -int vasprintf(char **s, const char *fmt, va_list ap) { return 0; } - -FILE memstream = {0}; -FILE *open_memstream(char **ptr, size_t *sizeloc) { return &memstream; } diff --git a/src/lang_c/libc/src/stdlib.c b/src/lang_c/libc/src/stdlib.c deleted file mode 100644 index c0eb14123..000000000 --- a/src/lang_c/libc/src/stdlib.c +++ /dev/null @@ -1,423 +0,0 @@ -#include -#include -#include -#include - -#define ABS_LONG_MIN 2147483648UL - -#ifndef WANT_STRTOD_WITHOUT_LONG_DOUBLE -#define ldbltype long double -#else -#define ldbltype double -#endif - -__attribute__((import_module("owi"), import_name("abort"))) void owi_abort(void); - -void abort(void) { - owi_abort(); -} - -__attribute__((import_module("owi"), import_name("exit"))) void owi_exit(int); - -void exit(int n) { - owi_exit(n); -} - -extern unsigned char __heap_base; -unsigned int bump_pointer = &__heap_base; - -void *malloc(size_t size) { - if (size == 0) { - // TODO: this could also be a proper *unique* pointer - // that is, calling malloc(0) two times, and freeing the two pointers should not lead to a double free - // see issue# 602 and the test added in #604 whose result should change once this is added - return NULL; - } - unsigned int start = bump_pointer; - unsigned int closest_pow2 = 1 << (sizeof(size_t)*8 - (__builtin_clz(size) + 1)); - unsigned int align = (closest_pow2 <= 16) ? closest_pow2 : 16; - unsigned int off_align = bump_pointer % align; - - if ( off_align != 0 ) { - start += (align - off_align); - } - bump_pointer = size + start; - return (void *)owi_malloc(start, size); -} - -void free(void *ptr) { - (void) owi_free(ptr); -} - -void *realloc(void *ptr, size_t size) { - // TODO: fix - (void) free(ptr); - return (void *)owi_malloc(ptr, size); -} - - -void *alloca(size_t size) { return malloc(size); } - -void *calloc(size_t nmemb, size_t size) { - // TODO: correctly handle overflow on multiplication - return malloc(nmemb * size); -} - -char *getenv(const char *name) { return (char *)0; } -int setenv(const char *name, const char *value, int overwrite) { return 0; } -int unsetenv(const char *name) { return 0; } - -int atoi(const char *s) { - long int v = 0; - int sign = 1; - while (*s == ' ' || (unsigned int)(*s - 9) < 5u) - s++; - switch (*s) { - case '-': - sign = -1; /* fall through */ - case '+': - ++s; - } - while ((unsigned int)(*s - '0') < 10u) { - v = v * 10 + *s - '0'; - ++s; - } - return sign == -1 ? -v : v; -} - -double strtod(const char *s, char **endptr) { - register const char *p = s; - register ldbltype value = 0.; - int sign = +1; - ldbltype factor; - unsigned int expo; - - while (isspace(*p)) - p++; - - switch (*p) { - case '-': - sign = -1; /* fall through */ - case '+': - p++; - default: - break; - } - - while ((unsigned int)(*p - '0') < 10u) - value = value * 10 + (*p++ - '0'); - - if (*p == '.') { - factor = 1.; - - p++; - while ((unsigned int)(*p - '0') < 10u) { - factor *= 0.1; - value += (*p++ - '0') * factor; - } - } - - if ((*p | 32) == 'e') { - expo = 0; - factor = 10.; - - switch (*++p) { // ja hier weiß ich nicht, was mindestens nach einem 'E' - // folgenden MUSS. - case '-': - factor = 0.1; /* fall through */ - case '+': - p++; - break; - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - break; - default: - value = 0.; - p = s; - goto done; - } - - while ((unsigned int)(*p - '0') < 10u) - expo = 10 * expo + (*p++ - '0'); - - while (1) { - if (expo & 1) - value *= factor; - if ((expo >>= 1) == 0) - break; - factor *= factor; - } - } - -done: - if (endptr != NULL) - *endptr = (char *)p; - - return value * sign; -} - -long int strtol(const char *nptr, char **endptr, int base) { - int neg = 0; - unsigned long int v; - const char *orig = nptr; - - while (isspace(*nptr)) - nptr++; - - if (*nptr == '-' && isalnum(nptr[1])) { - neg = -1; - ++nptr; - } - v = strtoul(nptr, endptr, base); - if (endptr && *endptr == nptr) - *endptr = (char *)orig; - if (v >= ABS_LONG_MIN) { - if (v == ABS_LONG_MIN && neg) { - errno = 0; - return v; - } - errno = ERANGE; - return (neg ? LONG_MIN : LONG_MAX); - } - return (neg ? -v : v); -} - -long long int strtoll(const char *nptr, char **endptr, int base) { - int neg = 0; - unsigned long long int v; - const char *orig = nptr; - - while (isspace(*nptr)) - nptr++; - - if (*nptr == '-' && isalnum(nptr[1])) { - neg = -1; - nptr++; - } - v = strtoull(nptr, endptr, base); - if (endptr && *endptr == nptr) - *endptr = (char *)orig; - if (v > LLONG_MAX) { - if (v == 0x8000000000000000ull && neg) { - errno = 0; - return v; - } - errno = ERANGE; - return (neg ? LLONG_MIN : LLONG_MAX); - } - return (neg ? -v : v); -} - -unsigned long int strtoul(const char *ptr, char **endptr, int base) { - int neg = 0, overflow = 0; - unsigned long int v = 0; - const char *orig; - const char *nptr = ptr; - - while (isspace(*nptr)) - ++nptr; - - if (*nptr == '-') { - neg = 1; - nptr++; - } else if (*nptr == '+') - ++nptr; - orig = nptr; - if (base == 16 && nptr[0] == '0') - goto skip0x; - if (base) { - register unsigned int b = base - 2; - if (b > 34) { - errno = EINVAL; - return 0; - } - } else { - if (*nptr == '0') { - base = 8; - skip0x: - if ((nptr[1] == 'x' || nptr[1] == 'X') && isxdigit(nptr[2])) { - nptr += 2; - base = 16; - } - } else - base = 10; - } - while (*nptr) { - register unsigned char c = *nptr; - c = (c >= 'a' ? c - 'a' + 10 - : c >= 'A' ? c - 'A' + 10 - : c <= '9' ? c - '0' - : 0xff); - if (c >= base) - break; /* out of base */ - { - register unsigned long x = (v & 0xff) * base + c; - register unsigned long w = (v >> 8) * base + (x >> 8); - if (w > (ULONG_MAX >> 8)) - overflow = 1; - v = (w << 8) + (x & 0xff); - } - ++nptr; - } - if (nptr == orig) { /* no conversion done */ - nptr = ptr; - errno = EINVAL; - v = 0; - } - if (endptr) - *endptr = (char *)nptr; - if (overflow) { - errno = ERANGE; - return ULONG_MAX; - } - return (neg ? -v : v); -} - -unsigned long long int strtoull(const char *ptr, char **endptr, int base) { - int neg = 0, overflow = 0; - long long int v = 0; - const char *orig; - const char *nptr = ptr; - - while (isspace(*nptr)) - ++nptr; - - if (*nptr == '-') { - neg = 1; - nptr++; - } else if (*nptr == '+') - ++nptr; - orig = nptr; - if (base == 16 && nptr[0] == '0') - goto skip0x; - if (base) { - register unsigned int b = base - 2; - if ((b > 34)) { - errno = EINVAL; - return 0; - } - } else { - if (*nptr == '0') { - base = 8; - skip0x: - if (((*(nptr + 1) == 'x') || (*(nptr + 1) == 'X')) && isxdigit(nptr[2])) { - nptr += 2; - base = 16; - } - } else - base = 10; - } - while ((*nptr)) { - register unsigned char c = *nptr; - c = (c >= 'a' ? c - 'a' + 10 - : c >= 'A' ? c - 'A' + 10 - : c <= '9' ? c - '0' - : 0xff); - if ((c >= base)) - break; /* out of base */ - { - register unsigned long x = (v & 0xff) * base + c; - register unsigned long long w = (v >> 8) * base + (x >> 8); - if (w > (ULLONG_MAX >> 8)) - overflow = 1; - v = (w << 8) + (x & 0xff); - } - ++nptr; - } - if (nptr == orig) { /* no conversion done */ - nptr = ptr; - errno = EINVAL; - v = 0; - } - if (endptr) - *endptr = (char *)nptr; - if (overflow) { - errno = ERANGE; - return ULLONG_MAX; - } - return (neg ? -v : v); -} - -static void exch(char *base, size_t size, size_t a, size_t b) { - char *x = base + a * size; - char *y = base + b * size; - while (size) { - char z = *x; - *x = *y; - *y = z; - --size; - ++x; - ++y; - } -} - -/* Quicksort with 3-way partitioning, ala Sedgewick */ -/* Blame him for the scary variable names */ -/* http://www.cs.princeton.edu/~rs/talks/QuicksortIsOptimal.pdf */ -static void quicksort(char *base, size_t size, ssize_t l, ssize_t r, - int (*compar)(const void *, const void *)) { - ssize_t i = l - 1, j = r, p = l - 1, q = r, k; - char *v = base + r * size; - if (r <= l) - return; - /* - We chose the rightmost element in the array to be sorted as pivot, - which is OK if the data is random, but which is horrible if the - data is already sorted. Try to improve by chosing the middle - element instead. - */ - exch(base, size, l + (r - l) / 2, r); - - for (;;) { - while (++i != r && compar(base + i * size, v) < 0) - ; - while (compar(v, base + (--j) * size) < 0) - if (j == l) - break; - if (i >= j) - break; - exch(base, size, i, j); - if (compar(base + i * size, v) == 0) - exch(base, size, ++p, i); - if (compar(v, base + j * size) == 0) - exch(base, size, j, --q); - } - exch(base, size, i, r); - j = i - 1; - ++i; - for (k = l; k < p; k++, j--) - exch(base, size, k, j); - for (k = r - 1; k > q; k--, i++) - exch(base, size, i, k); - quicksort(base, size, l, j, compar); - quicksort(base, size, i, r, compar); -} - -void qsort(void *base, size_t nmemb, size_t size, - int (*compar)(const void *, const void *)) { - /* check for integer overflows */ - if (nmemb >= (((size_t)-1) >> 1) || size >= (((size_t)-1) >> 1)) - return; -#if 0 - if (sizeof(size_t) < sizeof(unsigned long long)) { - if ((unsigned long long)size * nmemb > (size_t)-1) return; - } else { - if (size*nmemb/nmemb != size) return; - } -#endif - if (nmemb > 1) - quicksort(base, size, 0, nmemb - 1, compar); -} - -int posix_memalign(void **memptr, size_t alignment, size_t size) { return 0; } - -// TODO: OWI external -char getchar(void) { return ' '; } diff --git a/src/lang_c/libc/src/stdout.c b/src/lang_c/libc/src/stdout.c deleted file mode 100644 index f055946aa..000000000 --- a/src/lang_c/libc/src/stdout.c +++ /dev/null @@ -1,26 +0,0 @@ -#include - -static char __stdout_buf[BUFSIZE]; -static FILE __stdout = { - .fd = 1, - .flags = BUFLINEWISE | STATICBUF | CANWRITE | CHECKLINEWISE, - .bs = 0, - .bm = 0, - .buflen = BUFSIZE, - .buf = __stdout_buf, - .next = 0, - .popen_kludge = 0, - .ungetbuf = 0, - .ungotten = 0, -#ifdef WANT_THREAD_SAFE - .m = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, -#endif -}; - -FILE *stdout = &__stdout; - -/* -int __fflush_stdout(void) { - return fflush(stdout); -} -*/ diff --git a/src/lang_c/libc/src/strchr.c b/src/lang_c/libc/src/strchr.c deleted file mode 100644 index 41577bd63..000000000 --- a/src/lang_c/libc/src/strchr.c +++ /dev/null @@ -1,15 +0,0 @@ -#include - -char *strchr(register const char *t, int c) { - register char ch; - - ch = c; - for (;;) { - if (*t == ch) - break; - if (!*t) - return 0; - ++t; - } - return (char *)t; -} diff --git a/src/lang_c/libc/src/strcmp.c b/src/lang_c/libc/src/strcmp.c deleted file mode 100644 index 17e5cb9dc..000000000 --- a/src/lang_c/libc/src/strcmp.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int strcmp(const char *s1, const char *s2) { - while (*s1 && *s1 == *s2) - s1++, s2++; - return (*s1 - *s2); -} diff --git a/src/lang_c/libc/src/strcpy.c b/src/lang_c/libc/src/strcpy.c deleted file mode 100644 index 802b2164a..000000000 --- a/src/lang_c/libc/src/strcpy.c +++ /dev/null @@ -1,8 +0,0 @@ -#include - -char *strcpy(char *s1, const char *s2) { - char *res = s1; - while ((*s1++ = *s2++)) - ; - return (res); -} diff --git a/src/lang_c/libc/src/strdup.c b/src/lang_c/libc/src/strdup.c deleted file mode 100644 index 7b1f7b698..000000000 --- a/src/lang_c/libc/src/strdup.c +++ /dev/null @@ -1,10 +0,0 @@ -#include -#include - -char *strdup(const char *s) { - size_t l = strlen(s) + 1; - char *tmp = (char *)malloc(l); - if (!tmp) - return 0; - return memcpy(tmp, s, l); -} diff --git a/src/lang_c/libc/src/strerror.c b/src/lang_c/libc/src/strerror.c deleted file mode 100644 index 8725f5e5d..000000000 --- a/src/lang_c/libc/src/strerror.c +++ /dev/null @@ -1,8 +0,0 @@ -#include -#include -#include - -extern const char __sys_err_unknown[]; - -// TODO -char *strerror(int errnum) { return NULL; } diff --git a/src/lang_c/libc/src/strftime.c b/src/lang_c/libc/src/strftime.c deleted file mode 100644 index ef002e462..000000000 --- a/src/lang_c/libc/src/strftime.c +++ /dev/null @@ -1,199 +0,0 @@ -#include -#include - -static const char sweekdays[7][4] = {"Sun", "Mon", "Tue", "Wed", - "Thu", "Fri", "Sat"}; -static const char weekdays[7][10] = {"Sunday", "Monday", "Tuesday", - "Wednesday", "Thursday", "Friday", - "Saturday"}; -static const char smonths[12][4] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; -static const char *months[12] = { - "January", "February", "March", "April", smonths[5 - 1], "June", - "July", "August", "September", "October", "November", "December"}; -static const char ampm[4][3] = {"am", "pm", "AM", "PM"}; - -static void i2a(char *dest, unsigned long x) { - int div = 10; - *dest++ = x / div + '0'; - *dest++ = x % div + '0'; - *dest++ = '\0'; -} - -size_t strftime(char *dst, size_t max, const char *format, - const struct tm *tm) { - char *p = dst; - const char *src; - unsigned long no; - char buf[5]; - - if (!max) - return 0; - for (; *format != '\0'; format++) { - if (*format == '%') { - if (*++format == '%') { - *p++ = '%'; - } else - again: - switch (*format) { - // case '%': *p++ = '%'; break; // reduce size - // of jump table - case 'n': - *p++ = '\n'; - break; - case 't': - *p++ = '\t'; - break; - case 'O': - case 'E': - ++format; - goto again; - case 'c': - src = "%b %a %d %k:%M:%S %Z %Y"; - goto _strf; - case 'r': - src = "%I:%M:%S %p"; - goto _strf; - case 'R': - src = "%H:%M"; - goto _strf; - case 'x': - src = "%b %a %d"; - goto _strf; - case 'X': - src = "%k:%M:%S"; - goto _strf; - case 'D': - src = "%m/%d/%y"; - goto _strf; - case 'F': - src = "%Y-%m-%d"; - goto _strf; - case 'T': - src = "%H:%M:%S"; - _strf: - p += strftime(p, (size_t)(dst + max - p), src, tm); - break; - case 'a': - src = sweekdays[tm->tm_wday]; - goto _str; - case 'A': - src = weekdays[tm->tm_wday]; - goto _str; - case 'h': - case 'b': - src = smonths[tm->tm_mon]; - goto _str; - case 'B': - src = months[tm->tm_mon]; - goto _str; - case 'p': - src = ampm[tm->tm_hour > 12 ? 3 : 2]; - goto _str; - case 'P': - src = ampm[tm->tm_hour > 12 ? 1 : 0]; - goto _str; - case 'C': - no = tm->tm_year / 100 + 19; - goto _no; - case 'd': - no = tm->tm_mday; - goto _no; - case 'e': - no = tm->tm_mday; - goto _nos; - case 'H': - no = tm->tm_hour; - goto _no; - case 'I': - no = tm->tm_hour % 12; - goto _no; - case 'j': - no = tm->tm_yday; - goto _no; - case 'k': - no = tm->tm_hour; - goto _nos; - case 'l': - no = tm->tm_hour % 12; - goto _nos; - case 'm': - no = tm->tm_mon + 1; - goto _no; - case 'M': - no = tm->tm_min; - goto _no; - case 'S': - no = tm->tm_sec; - goto _no; - case 'u': - no = tm->tm_wday ? tm->tm_wday : 7; - goto _no; - case 'w': - no = tm->tm_wday; - goto _no; - case 'U': - no = (tm->tm_yday - tm->tm_wday + 7) / 7; - goto _no; - case 'W': - no = (tm->tm_yday - (tm->tm_wday - 1 + 7) % 7 + 7) / 7; - goto _no; - case 's': { - time_t t = mktime((struct tm *)tm); - char sbuf[101]; - char *c; - sbuf[100] = 0; - for (c = sbuf + 99; c > sbuf; --c) { - *c = (t % 10) + '0'; - t /= 10; - if (!t) - break; - } - src = c; - goto _str; - } - case 'Z': -#ifdef WANT_TZFILE_PARSER - tzset(); - src = tzname[0]; -#else - src = "[unknown timezone]"; -#endif - goto _str; - case 'Y': - i2a(buf + 0, (unsigned int)(tm->tm_year / 100 + 19)); - i2a(buf + 2, (unsigned int)(tm->tm_year % 100)); - src = buf; - goto _str; - case 'y': - no = tm->tm_year % 100; - goto _no; - _no: - i2a(buf, no); /* append number 'no' */ - src = buf; - goto _str; - _nos: - i2a(buf, no); /* the same, but '0'->' ' */ - if (buf[0] == '0') - buf[0] = ' '; - src = buf; - _str: - while (*src && p < dst + max) /* append string */ - *p++ = *src++; - break; - }; - } else { - *p++ = *format; - } - - if (p >= dst + max) - break; - } - - if ((size_t)(p - dst) >= max) { - if (max) - p[-1] = 0; - } else - *p = '\0'; - return p - dst; -} diff --git a/src/lang_c/libc/src/strlen.c b/src/lang_c/libc/src/strlen.c deleted file mode 100644 index 7ff51a8ed..000000000 --- a/src/lang_c/libc/src/strlen.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -size_t strlen(const char *s) { - register size_t i; - if (!s) - return 0; - for (i = 0; *s; ++s) - ++i; - return i; -} diff --git a/src/lang_c/libc/src/strncmp.c b/src/lang_c/libc/src/strncmp.c deleted file mode 100644 index 2bffb57cb..000000000 --- a/src/lang_c/libc/src/strncmp.c +++ /dev/null @@ -1,20 +0,0 @@ -#include -#include - -/* gcc is broken and has a non-SUSv2 compliant internal prototype. - * This causes it to warn about a type mismatch here. Ignore it. */ -int strncmp(const char *s1, const char *s2, size_t n) { - register const unsigned char *a = (const unsigned char *)s1; - register const unsigned char *b = (const unsigned char *)s2; - register const unsigned char *fini = a + n; - while (a != fini) { - register int res = *a - *b; - if (res) - return res; - if (!*a) - return 0; - ++a; - ++b; - } - return 0; -} diff --git a/src/lang_c/libc/src/strncpy.c b/src/lang_c/libc/src/strncpy.c deleted file mode 100644 index 0ac92f51a..000000000 --- a/src/lang_c/libc/src/strncpy.c +++ /dev/null @@ -1,9 +0,0 @@ -#include -#include - -/* gcc is broken and has a non-SUSv2 compliant internal prototype. - * This causes it to warn about a type mismatch here. Ignore it. */ -char *strncpy(char *dest, const char *src, size_t n) { - memccpy(dest,src,0,n); - return dest; -} diff --git a/src/lang_c/libc/src/strrchr.c b/src/lang_c/libc/src/strrchr.c deleted file mode 100644 index e7ed84f9f..000000000 --- a/src/lang_c/libc/src/strrchr.c +++ /dev/null @@ -1,16 +0,0 @@ -#include - -char *strrchr(const char *t, int c) { - register char ch; - register const char *l = 0; - - ch = c; - for (;;) { - if (*t == ch) - l = t; - if (!*t) - return (char *)l; - ++t; - } - return (char *)l; -} diff --git a/src/lang_c/libc/src/strstr.c b/src/lang_c/libc/src/strstr.c deleted file mode 100644 index 9031af071..000000000 --- a/src/lang_c/libc/src/strstr.c +++ /dev/null @@ -1,17 +0,0 @@ -#include -#include - -char *strstr(const char *haystack, const char *needle) { - size_t nl=strlen(needle); - size_t hl=strlen(haystack); - size_t i; - if (!nl) goto found; - if (nl>hl) return 0; - for (i=hl-nl+1; i; --i) { - if (*haystack==*needle && !memcmp(haystack,needle,nl)) -found: - return (char*)haystack; - ++haystack; - } - return 0; -} diff --git a/src/lang_c/libc/src/sys_resources.c b/src/lang_c/libc/src/sys_resources.c deleted file mode 100644 index a87b9214d..000000000 --- a/src/lang_c/libc/src/sys_resources.c +++ /dev/null @@ -1,5 +0,0 @@ -#include - -int getrlimit(int resource, struct rlimit *rlim) { return 0; } -int getrusage(int who, struct rusage *usage) { return 0; } -int setrlimit(int resource, const struct rlimit *rlim) { return 0; } diff --git a/src/lang_c/libc/src/time.c b/src/lang_c/libc/src/time.c deleted file mode 100644 index ec356c336..000000000 --- a/src/lang_c/libc/src/time.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int clock_gettime(clockid_t clock_id, struct timespec *tp) { return 0; } - -time_t time(time_t *t) { return 0; } -time_t timegm(struct tm *timeptr) { return 0; } -time_t mktime(struct tm *timeptr) { return 0; } - -struct tm *localtime_r(const time_t *t, struct tm *r) { return (struct tm *)0; } -struct tm *gmtime_r(const time_t *t, struct tm *r) { return (struct tm *)0; } - -int nanosleep(const struct timespec *rqtp, struct timespec *rmtp) { return 0; } - -char *ctime(const time_t *timep) { return 0; } diff --git a/src/lang_c/libc/src/unistd.c b/src/lang_c/libc/src/unistd.c deleted file mode 100644 index e4f464ace..000000000 --- a/src/lang_c/libc/src/unistd.c +++ /dev/null @@ -1,12 +0,0 @@ -#include - -int optind = 0; -char *optarg = NULL; - -/* int getopt(int argc, char *const *argv, const char *options) { return 0; } */ -/* int open(const char* pathname,int flags, ...) { return 0; } */ -int close(int fd) { return 0; } -ssize_t read(int fd, void *buf, size_t len) { return 0; } -int getpid(void) { return 0; } - -int getopt(int argc, char *argv[], const char *optstring) { return -1; } diff --git a/src/lang_c/libowi/script.ml b/src/lang_c/script.ml similarity index 80% rename from src/lang_c/libowi/script.ml rename to src/lang_c/script.ml index 0e1d2d5c7..701a9c4dd 100644 --- a/src/lang_c/libowi/script.ml +++ b/src/lang_c/script.ml @@ -14,11 +14,12 @@ let () = let out = Format.sprintf "%s.o" filename in let n = Format.ksprintf Sys.command - "clang -O3 -ffreestanding --no-standard-libraries \ - --target=wasm32-unknown-unknown -c -m32 -Iinclude \ + {sh|clang -O3 \ + --sysroot=$HOME/dev/c/wasi-libc/sysroot \ + --target=wasm32-wasi -c -m32 -Iinclude \ -I../libc/include/ -Wall -Werror -Wno-int-conversion \ -Wno-return-type -fbracket-depth=512 \ - -DWANT_STRTOD_WITHOUT_LONG_DOUBLE -o %s %s" + -DWANT_STRTOD_WITHOUT_LONG_DOUBLE -o %s %s|sh} out c_filename in if n <> 0 then exit n diff --git a/src/lang_c/libowi/src/assert_fail.c b/src/lang_c/src/assert_fail.c similarity index 100% rename from src/lang_c/libowi/src/assert_fail.c rename to src/lang_c/src/assert_fail.c diff --git a/src/lang_c/libowi/src/eacsl.c b/src/lang_c/src/eacsl.c similarity index 64% rename from src/lang_c/libowi/src/eacsl.c rename to src/lang_c/src/eacsl.c index f4de348ce..1588220bc 100644 --- a/src/lang_c/libowi/src/eacsl.c +++ b/src/lang_c/src/eacsl.c @@ -1,20 +1,22 @@ // SPDX-License-Identifier: LGPL-2.1-or-later -// Copyright (C) 2012-2024 CEA (Commissariat à l'énergie atomique et aux énergies alternatives -// This file is originally from the Frama-C's E-ACSL plug-in available at https://git.frama-c.com/pub/frama-c/-/tree/master/src/plugins/e-acsl +// Copyright (C) 2012-2024 CEA (Commissariat à l'énergie atomique et aux +// énergies alternatives This file is originally from the Frama-C's E-ACSL +// plug-in available at +// https://git.frama-c.com/pub/frama-c/-/tree/master/src/plugins/e-acsl // SPDX-License-Identifier: AGPL-3.0-or-later // Copyright © 2021-2024 OCamlPro // Modified by the Owi programmers #include -#include -#include #include #include +#include +#include +#include extern void *malloc(size_t size); extern void *calloc(size_t, size_t); -__attribute__((import_module("owi"), import_name("dealloc"))) void *free(void *); /* Memory model */ @@ -31,8 +33,12 @@ void __e_acsl_delete_block(void *ptr) {} size_t __e_acsl_offset(void *ptr) {} void *__e_acsl_base_addr(void *ptr) {} size_t __e_acsl_block_length(void *ptr) {} -int __e_acsl_valid_read(void *ptr, size_t size, void *base, void *addrof_base) { return 1; } -int __e_acsl_valid(void *ptr, size_t size, void *base, void *addrof_base) { return 1; } +int __e_acsl_valid_read(void *ptr, size_t size, void *base, void *addrof_base) { + return 1; +} +int __e_acsl_valid(void *ptr, size_t size, void *base, void *addrof_base) { + return 1; +} int __e_acsl_initialized(void *ptr, size_t size) { return 1; } int __e_acsl_freeable(void *ptr) { return 1; } int __e_acsl_separated(size_t count, ...) { return 1; } @@ -61,14 +67,13 @@ static inline size_t find_char_count(size_t bit_count) { return char_count; } -static inline int normalize_to_boolean(int value) { - return value ? 1 : 0; -} +static inline int normalize_to_boolean(int value) { return value ? 1 : 0; } __e_acsl_contract_t *__e_acsl_contract_init(size_t size) { // Allocate memory for the structure __e_acsl_contract_t *c = malloc(sizeof(__e_acsl_contract_t)); - // DVASSERT(c != NULL, "Unable to allocate %d bytes of memory for contract_t\n", + // DVASSERT(c != NULL, "Unable to allocate %d bytes of memory for + // contract_t\n", // sizeof(__e_acsl_contract_t)); // Compute the number of char needed to store `size` behaviors, assuming @@ -97,7 +102,8 @@ void __e_acsl_contract_clean(__e_acsl_contract_t *c) { } /* Contract behaviors */ -void __e_acsl_contract_set_behavior_assumes(__e_acsl_contract_t *c, size_t i, int assumes) { +void __e_acsl_contract_set_behavior_assumes(__e_acsl_contract_t *c, size_t i, + int assumes) { size_t char_idx = find_char_index(i); // DVASSERT(char_idx < c->char_count, // "Out of bound char index %d (char_count: %d)\n", char_idx, @@ -107,7 +113,8 @@ void __e_acsl_contract_set_behavior_assumes(__e_acsl_contract_t *c, size_t i, in c->assumes[char_idx] |= (assumes << bit_idx); } -int __e_acsl_contract_get_behavior_assumes(const __e_acsl_contract_t *c, size_t i) { +int __e_acsl_contract_get_behavior_assumes(const __e_acsl_contract_t *c, + size_t i) { size_t char_idx = find_char_index(i); // DVASSERT(char_idx < c->char_count, // "Out of bound char index %d (char_count: %d)\n", char_idx, @@ -117,7 +124,8 @@ int __e_acsl_contract_get_behavior_assumes(const __e_acsl_contract_t *c, size_t return normalize_to_boolean(result); } -int __e_acsl_contract_partial_count_behaviors(const __e_acsl_contract_t *c, size_t count, ...) { +int __e_acsl_contract_partial_count_behaviors(const __e_acsl_contract_t *c, + size_t count, ...) { va_list args; va_start(args, count); @@ -130,12 +138,14 @@ int __e_acsl_contract_partial_count_behaviors(const __e_acsl_contract_t *c, size return result; } -int __e_acsl_contract_partial_count_all_behaviors(const __e_acsl_contract_t *c) { +int __e_acsl_contract_partial_count_all_behaviors( + const __e_acsl_contract_t *c) { int result = 0; for (int i = 0; i < c->char_count && result < 2; ++i) { // Counting bits set with Kernighan's algorithm, but stopping at two // bits set. - // cf. + // cf. + // unsigned char assumes_cell = c->assumes[i]; for (; assumes_cell && result < 2; ++result) { assumes_cell &= assumes_cell - 1; @@ -148,56 +158,68 @@ int __e_acsl_contract_partial_count_all_behaviors(const __e_acsl_contract_t *c) /* Assert */ void __e_acsl_assert(int predicate, __e_acsl_assert_data_t *data) { - owi_assert(predicate); + owi_assert(predicate); } /* Assert data registration */ -void __e_acsl_assert_register_bool(__e_acsl_assert_data_t *data, const char *name, - int is_enum, _Bool value) {} -void __e_acsl_assert_register_char(__e_acsl_assert_data_t *data, const char *name, - int is_enum, char value) {} -void __e_acsl_assert_register_schar(__e_acsl_assert_data_t *data, const char *name, - int is_enum, signed char value) {} -void __e_acsl_assert_register_uchar(__e_acsl_assert_data_t *data, const char *name, - int is_enum, unsigned char value) {} -void __e_acsl_assert_register_int(__e_acsl_assert_data_t *data, const char *name, - int is_enum, int value) {} -void __e_acsl_assert_register_uint(__e_acsl_assert_data_t *data, const char *name, - int is_enum, unsigned int value) {} -void __e_acsl_assert_register_short(__e_acsl_assert_data_t *data, const char *name, - int is_enum, short value) {} -void __e_acsl_assert_register_ushort(__e_acsl_assert_data_t *data, const char *name, - int is_enum, unsigned short value) {} -void __e_acsl_assert_register_long(__e_acsl_assert_data_t *data, const char *name, - int is_enum, long value) {} -void __e_acsl_assert_register_ulong(__e_acsl_assert_data_t *data, const char *name, - int is_enum, unsigned long value) {} -void __e_acsl_assert_register_longlong(__e_acsl_assert_data_t *data, const char *name, - int is_enum, long long value) {} -void __e_acsl_assert_register_ulonglong(__e_acsl_assert_data_t *data, +void __e_acsl_assert_register_bool(__e_acsl_assert_data_t *data, + const char *name, int is_enum, _Bool value) { +} +void __e_acsl_assert_register_char(__e_acsl_assert_data_t *data, + const char *name, int is_enum, char value) {} +void __e_acsl_assert_register_schar(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + signed char value) {} +void __e_acsl_assert_register_uchar(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + unsigned char value) {} +void __e_acsl_assert_register_int(__e_acsl_assert_data_t *data, + const char *name, int is_enum, int value) {} +void __e_acsl_assert_register_uint(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + unsigned int value) {} +void __e_acsl_assert_register_short(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + short value) {} +void __e_acsl_assert_register_ushort(__e_acsl_assert_data_t *data, const char *name, int is_enum, - unsigned long long value) {} -void __e_acsl_assert_register_generic_real(__e_acsl_assert_data_t *data, - const char *name, - __e_acsl_assert_data_rkind_t kind, - __e_acsl_assert_data_real_value_t value) {} -void __e_acsl_assert_register_float(__e_acsl_assert_data_t *data, const char *name, - float value) {} -void __e_acsl_assert_register_double(__e_acsl_assert_data_t *data, const char *name, - double value) {} + unsigned short value) {} +void __e_acsl_assert_register_long(__e_acsl_assert_data_t *data, + const char *name, int is_enum, long value) {} +void __e_acsl_assert_register_ulong(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + unsigned long value) {} +void __e_acsl_assert_register_longlong(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + long long value) {} +void __e_acsl_assert_register_ulonglong(__e_acsl_assert_data_t *data, + const char *name, int is_enum, + unsigned long long value) {} +void __e_acsl_assert_register_generic_real( + __e_acsl_assert_data_t *data, const char *name, + __e_acsl_assert_data_rkind_t kind, + __e_acsl_assert_data_real_value_t value) {} +void __e_acsl_assert_register_float(__e_acsl_assert_data_t *data, + const char *name, float value) {} +void __e_acsl_assert_register_double(__e_acsl_assert_data_t *data, + const char *name, double value) {} void __e_acsl_assert_register_longdouble(__e_acsl_assert_data_t *data, - const char *name, long double value) {} -void __e_acsl_assert_register_ptr(__e_acsl_assert_data_t *data, const char *name, - void *ptr) {} -void __e_acsl_assert_register_array(__e_acsl_assert_data_t *data, const char *name, - void *array) {} -void __e_acsl_assert_register_fun(__e_acsl_assert_data_t *data, const char *name) {} -void __e_acsl_assert_register_struct(__e_acsl_assert_data_t *data, const char *name) {} -void __e_acsl_assert_register_union(__e_acsl_assert_data_t *data, const char *name) {} -void __e_acsl_assert_register_other(__e_acsl_assert_data_t *data, const char *name) {} + const char *name, long double value) {} +void __e_acsl_assert_register_ptr(__e_acsl_assert_data_t *data, + const char *name, void *ptr) {} +void __e_acsl_assert_register_array(__e_acsl_assert_data_t *data, + const char *name, void *array) {} +void __e_acsl_assert_register_fun(__e_acsl_assert_data_t *data, + const char *name) {} +void __e_acsl_assert_register_struct(__e_acsl_assert_data_t *data, + const char *name) {} +void __e_acsl_assert_register_union(__e_acsl_assert_data_t *data, + const char *name) {} +void __e_acsl_assert_register_other(__e_acsl_assert_data_t *data, + const char *name) {} void __e_acsl_assert_free_value(__e_acsl_assert_data_value_t *value) {} void __e_acsl_assert_copy_value(__e_acsl_assert_data_t *dest, - __e_acsl_assert_data_value_t *value) {} + __e_acsl_assert_data_value_t *value) {} void __e_acsl_assert_copy_values(__e_acsl_assert_data_t *dest, - __e_acsl_assert_data_t *src) {} + __e_acsl_assert_data_t *src) {} void __e_acsl_assert_clean(__e_acsl_assert_data_t *data) {} diff --git a/src/lang_c/libowi/src/klee.c b/src/lang_c/src/klee.c similarity index 100% rename from src/lang_c/libowi/src/klee.c rename to src/lang_c/src/klee.c diff --git a/src/lang_c/libowi/src/owi.c b/src/lang_c/src/owi.c similarity index 71% rename from src/lang_c/libowi/src/owi.c rename to src/lang_c/src/owi.c index d0a23857c..f086daf6e 100644 --- a/src/lang_c/libowi/src/owi.c +++ b/src/lang_c/src/owi.c @@ -1,4 +1,8 @@ #include +#include + +#define OWI_IMPORT(name) \ + __attribute__((import_module("owi"), import_name(name))) #define magic_size_signed(T) \ ({ \ @@ -89,3 +93,35 @@ unsigned __int128 owi_uint128(void) { high128 = high128 << 64; return high128 | low128; } + +/* stdlib redifinitions */ + +OWI_IMPORT("abort") __attribute__((noreturn)) void abort(void); + +OWI_IMPORT("exit") __attribute__((noreturn)) void exit(int); + +extern unsigned char __heap_base; +unsigned int bump_pointer = &__heap_base; + +void *malloc(size_t size) { + if (size == 0) { + // TODO: this could also be a proper *unique* pointer + // that is, calling malloc(0) two times, and freeing the two pointers should + // not lead to a double free see issue# 602 and the test added in #604 whose + // result should change once this is added + return NULL; + } + unsigned int start = bump_pointer; + unsigned int closest_pow2 = + 1 << (sizeof(size_t) * 8 - (__builtin_clz(size) + 1)); + unsigned int align = (closest_pow2 <= 16) ? closest_pow2 : 16; + unsigned int off_align = bump_pointer % align; + + if (off_align != 0) { + start += (align - off_align); + } + bump_pointer = size + start; + return (void *)owi_malloc(start, size); +} + +OWI_IMPORT("free") void free(void *ptr); diff --git a/src/lang_c/libowi/src/test-comp.c b/src/lang_c/src/test-comp.c similarity index 100% rename from src/lang_c/libowi/src/test-comp.c rename to src/lang_c/src/test-comp.c