diff --git a/kernel/Makefile b/kernel/Makefile
index 63715c63..9e9eba5f 100644
--- a/kernel/Makefile
+++ b/kernel/Makefile
@@ -116,6 +116,7 @@ kernelinfo.o \
kernel.o \
kthread.o \
lfbtextbuffer.o \
+libk.o \
linebuffer.o \
log.o \
logterminal.o \
diff --git a/kernel/include/sortix/display.h b/kernel/include/sortix/display.h
index 13d625b5..5999fb60 100644
--- a/kernel/include/sortix/display.h
+++ b/kernel/include/sortix/display.h
@@ -34,9 +34,9 @@
extern "C" {
#endif
-const uint32_t DISPMSG_CONTROL_VALID = 1 << 0;
-const uint32_t DISPMSG_CONTROL_VGA = 1 << 1;
-const uint32_t DISPMSG_CONTROL_OTHER_RESOLUTIONS = 1 << 2;
+static const uint32_t DISPMSG_CONTROL_VALID = 1 << 0;
+static const uint32_t DISPMSG_CONTROL_VGA = 1 << 1;
+static const uint32_t DISPMSG_CONTROL_OTHER_RESOLUTIONS = 1 << 2;
struct dispmsg_string
{
diff --git a/kernel/libk.cpp b/kernel/libk.cpp
new file mode 100644
index 00000000..3a6fc8d9
--- /dev/null
+++ b/kernel/libk.cpp
@@ -0,0 +1,177 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2016.
+
+ This file is part of Sortix.
+
+ Sortix 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 3 of the License, or (at your option) any later
+ version.
+
+ Sortix 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
+ Sortix. If not, see .
+
+ libk.cpp
+ Hooks for libk.
+
+*******************************************************************************/
+
+#include
+
+#include
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+namespace Sortix {
+
+static kthread_mutex_t heap_mutex = KTHREAD_MUTEX_INITIALIZER;
+static kthread_mutex_t random_mutex = KTHREAD_MUTEX_INITIALIZER;
+
+extern "C"
+void libk_assert(const char* filename,
+ unsigned long line,
+ const char* function_name,
+ const char* expression)
+{
+ Sortix::PanicF("Assertion failure: %s:%lu: %s: %s", filename, line,
+ function_name, expression);
+}
+
+extern "C"
+size_t libk_getpagesize(void)
+{
+ return Sortix::Page::Size();
+}
+
+extern "C"
+void* libk_heap_expand(size_t* num_bytes)
+{
+ // Decide where we would like to add memory to the heap.
+ uintptr_t mapto = Sortix::GetHeapUpper();
+ void* mapping = (void*) mapto;
+
+ // Attempt to allocate the needed virtual address space such that we can put
+ // memory there to extend the heap with.
+ if ( !(*num_bytes = Sortix::ExpandHeap(*num_bytes)) )
+ return NULL;
+
+ // Attempt to map actual memory at our new virtual addresses.
+ int prot = PROT_KREAD | PROT_KWRITE;
+ enum Sortix::page_usage page_usage = Sortix::PAGE_USAGE_KERNEL_HEAP;
+ if ( !Sortix::Memory::MapRange(mapto, *num_bytes, prot, page_usage) )
+ return NULL;
+ Sortix::Memory::Flush();
+
+ return mapping;
+}
+
+extern "C"
+void libk_heap_lock(void)
+{
+ kthread_mutex_lock(&heap_mutex);
+}
+
+extern "C"
+void libk_heap_unlock(void)
+{
+ kthread_mutex_unlock(&heap_mutex);
+}
+
+extern "C"
+void libk_stack_chk_fail(void)
+{
+ Panic("Stack smashing detected");
+}
+
+extern "C"
+void libk_abort(void)
+{
+ Sortix::PanicF("abort()");
+}
+
+extern "C"
+void libk_random_lock(void)
+{
+ kthread_mutex_lock(&random_mutex);
+}
+
+extern "C"
+void libk_random_unlock(void)
+{
+ kthread_mutex_unlock(&random_mutex);
+}
+
+extern "C"
+bool libk_hasentropy(void)
+{
+ return Sortix::Random::HasEntropy();
+}
+
+extern "C"
+void libk_getentropy(void* buffer, size_t size)
+{
+ Sortix::Random::GetEntropy(buffer, size);
+}
+
+extern "C"
+__attribute__((noreturn))
+void libk_ubsan_abort(const char* violation,
+ const char* filename,
+ uint32_t line,
+ uint32_t column)
+{
+ Sortix::PanicF("Undefined behavior: %s at %s:%u:%u",
+ violation, filename, line, column);
+}
+
+extern "C"
+void* libk_mmap(size_t size, int prot)
+{
+ size = Page::AlignUp(size);
+ addralloc_t addralloc;
+ if ( !AllocateKernelAddress(&addralloc, size) )
+ return NULL;
+ if ( !Memory::MapRange(addralloc.from, size, prot, PAGE_USAGE_KERNEL_HEAP) )
+ {
+ Memory::Flush();
+ FreeKernelAddress(&addralloc);
+ return NULL;
+ }
+ Memory::Flush();
+ return (void*) addralloc.from;
+}
+
+extern "C"
+void libk_mprotect(void* ptr, size_t size, int prot)
+{
+ addr_t mapto = (addr_t) ptr;
+ for ( size_t i = 0; i < size; i += Page::Size() )
+ Memory::PageProtect(mapto + i, prot);
+ Memory::Flush();
+}
+
+extern "C"
+void libk_munmap(void* ptr, size_t size)
+{
+ size = Page::AlignUp(size);
+ addralloc_t addralloc;
+ addralloc.from = (addr_t) ptr;
+ addralloc.size = size;
+ Memory::UnmapRange(addralloc.from, size, PAGE_USAGE_KERNEL_HEAP);
+ Memory::Flush();
+ FreeKernelAddress(&addralloc);
+}
+
+} // namespace Sortix
diff --git a/kernel/process.cpp b/kernel/process.cpp
index 1d16e59f..c8cb3356 100644
--- a/kernel/process.cpp
+++ b/kernel/process.cpp
@@ -1083,7 +1083,7 @@ static size_t shebang_count_arguments(char* line)
// can be shared somehow, you need to keep this comment in sync as well
// as the logic in these files:
// * kernel/process.cpp
-// * libc/unistd/execvpe.cpp
+// * libc/unistd/execvpe.c
// * utils/which.cpp
// NOTE: See comments in execvpe() for algorithmic commentary.
diff --git a/libc/Makefile b/libc/Makefile
index d1b2a9ea..bf222402 100644
--- a/libc/Makefile
+++ b/libc/Makefile
@@ -11,7 +11,7 @@ CPUDIR:=$(CPU)
CPPINCLUDES=-Iinclude
CPPFLAGS=-D__is_sortix_libc $(CPPINCLUDES)
FLAGS=-Wall -Wextra $(OPTLEVEL)
-CFLAGS=-std=gnu99
+CFLAGS=-std=gnu11 -Wstrict-prototypes -Werror=implicit-function-declaration
CXXFLAGS=-std=gnu++11 -fno-exceptions -fno-rtti
ASFLAGS=
@@ -688,7 +688,7 @@ $(CRTOBJ) \
HEADERS:=$(shell find include -type f)
LIBK_OBJS:=$(FREEOBJS:.o=.libk.o)
-LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_kernel
+LIBK_CPPFLAGS:=$(CPPFLAGS) -D__is_sortix_libk
LIBK_FLAGS:=$(FLAGS) -ffreestanding
LIBK_CFLAGS:=$(CFLAGS)
LIBK_CXXFLAGS:=$(CXXFLAGS)
@@ -745,17 +745,17 @@ headers:
%.o: %.c
$(CC) -c $< -o $@ $(CPPFLAGS) $(FLAGS) $(CFLAGS)
-%.o: %.cpp
+%.o: %.c++
$(CXX) -c $< -o $@ $(CPPFLAGS) $(FLAGS) $(CXXFLAGS)
%.o: %.S
- $(CXX) -c $< -o $@ $(CPPFLAGS) $(FLAGS) $(CFLAGS)
+ $(CC) -c $< -o $@ $(CPPFLAGS) $(FLAGS) $(CFLAGS)
# libk
%.libk.o: %.c
$(CC) -c $< -o $@ $(LIBK_CPPFLAGS) $(LIBK_FLAGS) $(LIBK_CFLAGS)
-%.libk.o: %.cpp
+%.libk.o: %.c++
$(CXX) -c $< -o $@ $(LIBK_CPPFLAGS) $(LIBK_FLAGS) $(LIBK_CXXFLAGS)
%.libk.o: %.S
diff --git a/libc/arpa/inet/inet_ntoa.cpp b/libc/arpa/inet/inet_addr.c
similarity index 94%
rename from libc/arpa/inet/inet_ntoa.cpp
rename to libc/arpa/inet/inet_addr.c
index 58664384..2994b026 100644
--- a/libc/arpa/inet/inet_ntoa.cpp
+++ b/libc/arpa/inet/inet_addr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- arpa/inet/inet_ntoa.cpp
+ arpa/inet/inet_addr.c
Internet address manipulation routines.
*******************************************************************************/
@@ -29,8 +29,9 @@
#include
#include
-extern "C" char* inet_ntoa(struct in_addr)
+in_addr_t inet_addr(const char* cp)
{
+ (void) cp;
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}
diff --git a/libc/arpa/inet/inet_addr.cpp b/libc/arpa/inet/inet_ntoa.c
similarity index 94%
rename from libc/arpa/inet/inet_addr.cpp
rename to libc/arpa/inet/inet_ntoa.c
index 765e468a..e46d6dc3 100644
--- a/libc/arpa/inet/inet_addr.cpp
+++ b/libc/arpa/inet/inet_ntoa.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- arpa/inet/inet_addr.cpp
+ arpa/inet/inet_ntoa.c
Internet address manipulation routines.
*******************************************************************************/
@@ -29,8 +29,9 @@
#include
#include
-extern "C" in_addr_t inet_addr(const char*)
+char* inet_ntoa(struct in_addr in)
{
+ (void) in;
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}
diff --git a/libc/arpa/inet/inet_ntop.cpp b/libc/arpa/inet/inet_ntop.c
similarity index 83%
rename from libc/arpa/inet/inet_ntop.cpp
rename to libc/arpa/inet/inet_ntop.c
index c2234368..19560903 100644
--- a/libc/arpa/inet/inet_ntop.cpp
+++ b/libc/arpa/inet/inet_ntop.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- arpa/inet/inet_ntop.cpp
+ arpa/inet/inet_ntop.c
Internet address manipulation routines.
*******************************************************************************/
@@ -29,9 +29,15 @@
#include
#include
-extern "C" const char* inet_ntop(int, const void* restrict, char* restrict,
- socklen_t)
+const char* inet_ntop(int af,
+ const void* restrict src,
+ char* restrict dst,
+ socklen_t size)
{
+ (void) af;
+ (void) src;
+ (void) dst;
+ (void) size;
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}
diff --git a/libc/arpa/inet/inet_pton.cpp b/libc/arpa/inet/inet_pton.c
similarity index 90%
rename from libc/arpa/inet/inet_pton.cpp
rename to libc/arpa/inet/inet_pton.c
index 950ecd93..00d422d2 100644
--- a/libc/arpa/inet/inet_pton.cpp
+++ b/libc/arpa/inet/inet_pton.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- arpa/inet/inet_pton.cpp
+ arpa/inet/inet_pton.c
Internet address manipulation routines.
*******************************************************************************/
@@ -29,8 +29,11 @@
#include
#include
-extern "C" int inet_pton(int, const char* restrict, void* restrict)
+int inet_pton(int af, const char* restrict src, void* restrict dst)
{
+ (void) af;
+ (void) src;
+ (void) dst;
fprintf(stderr, "%s is not implemented yet, aborting.\n", __func__);
abort();
}
diff --git a/libc/assert/__assert.cpp b/libc/assert/__assert.c
similarity index 85%
rename from libc/assert/__assert.cpp
rename to libc/assert/__assert.c
index c2e1cbf7..63b28387 100644
--- a/libc/assert/__assert.cpp
+++ b/libc/assert/__assert.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- assert/__assert.cpp
+ assert/__assert.c
Reports the occurence of an assertion failure.
*******************************************************************************/
@@ -25,19 +25,17 @@
#include
#include
-#if defined(__is_sortix_kernel)
-#include
+#ifdef __is_sortix_libk
+#include
#endif
-extern "C"
void __assert(const char* filename,
unsigned long line,
const char* function_name,
const char* expression)
{
-#if defined(__is_sortix_kernel)
- Sortix::PanicF("Assertion failure: %s:%lu: %s: %s", filename, line,
- function_name, expression);
+#ifdef __is_sortix_libk
+ libk_assert(filename, line, function_name, expression);
#else
struct scram_assert info;
info.filename = filename;
diff --git a/libc/blf/blowfish.cpp b/libc/blf/blowfish.c
similarity index 99%
rename from libc/blf/blowfish.cpp
rename to libc/blf/blowfish.c
index e45440a4..c82de225 100644
--- a/libc/blf/blowfish.cpp
+++ b/libc/blf/blowfish.c
@@ -52,7 +52,6 @@
#define BLFRND(s,p,i,j,n) (i ^= F(s,j) ^ (p)[n])
-extern "C"
void
Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
{
@@ -78,7 +77,6 @@ Blowfish_encipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
*xr = Xl;
}
-extern "C"
void
Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
{
@@ -104,7 +102,6 @@ Blowfish_decipher(blf_ctx *c, uint32_t *xl, uint32_t *xr)
*xr = Xl;
}
-extern "C"
void
Blowfish_initstate(blf_ctx *c)
{
@@ -384,7 +381,6 @@ Blowfish_initstate(blf_ctx *c)
*c = initstate;
}
-extern "C"
uint32_t
Blowfish_stream2word(const uint8_t *data, uint16_t databytes,
uint16_t *current)
@@ -406,7 +402,6 @@ Blowfish_stream2word(const uint8_t *data, uint16_t databytes,
return temp;
}
-extern "C"
void
Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
{
@@ -444,7 +439,6 @@ Blowfish_expand0state(blf_ctx *c, const uint8_t *key, uint16_t keybytes)
}
}
-extern "C"
void
Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
const uint8_t *key, uint16_t keybytes)
@@ -488,7 +482,6 @@ Blowfish_expandstate(blf_ctx *c, const uint8_t *data, uint16_t databytes,
}
-extern "C"
void
blf_key(blf_ctx *c, const uint8_t *k, uint16_t len)
{
@@ -499,7 +492,6 @@ blf_key(blf_ctx *c, const uint8_t *k, uint16_t len)
Blowfish_expand0state(c, k, len);
}
-extern "C"
void
blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks)
{
@@ -513,7 +505,6 @@ blf_enc(blf_ctx *c, uint32_t *data, uint16_t blocks)
}
}
-extern "C"
void
blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks)
{
@@ -527,7 +518,6 @@ blf_dec(blf_ctx *c, uint32_t *data, uint16_t blocks)
}
}
-extern "C"
void
blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len)
{
@@ -550,7 +540,6 @@ blf_ecb_encrypt(blf_ctx *c, uint8_t *data, uint32_t len)
}
}
-extern "C"
void
blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len)
{
@@ -573,7 +562,6 @@ blf_ecb_decrypt(blf_ctx *c, uint8_t *data, uint32_t len)
}
}
-extern "C"
void
blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
{
@@ -599,7 +587,6 @@ blf_cbc_encrypt(blf_ctx *c, uint8_t *iv, uint8_t *data, uint32_t len)
}
}
-extern "C"
void
blf_cbc_decrypt(blf_ctx *c, uint8_t *iva, uint8_t *data, uint32_t len)
{
diff --git a/libc/c++/c++.cpp b/libc/c++/c++.c++
similarity index 87%
rename from libc/c++/c++.cpp
rename to libc/c++/c++.c++
index f0367cfa..f19baefe 100644
--- a/libc/c++/c++.cpp
+++ b/libc/c++/c++.c++
@@ -17,8 +17,8 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- c++/c++.cpp
- Implements required C++ stuff for use in the Sortix kernel.
+ c++/c++.c++
+ Implements required C++ stuff.
*******************************************************************************/
@@ -26,5 +26,5 @@
extern "C" void __attribute__ ((weak)) __cxa_pure_virtual()
{
- // This shouldn't happen. TODO: Possibly crash the kernel here.
+ // This shouldn't happen. TODO: Crash here.
}
diff --git a/libc/c++/op-new.cpp b/libc/c++/op-new.c++
similarity index 98%
rename from libc/c++/op-new.cpp
rename to libc/c++/op-new.c++
index b3e37a37..886bc2ea 100644
--- a/libc/c++/op-new.cpp
+++ b/libc/c++/op-new.c++
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- c++/op-new.cpp
+ c++/op-new.c++
C++ allocation operators.
*******************************************************************************/
diff --git a/libc/ctype/isalnum.cpp b/libc/ctype/isalnum.c
similarity index 95%
rename from libc/ctype/isalnum.cpp
rename to libc/ctype/isalnum.c
index e65638ca..e4e1f0c3 100644
--- a/libc/ctype/isalnum.cpp
+++ b/libc/ctype/isalnum.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isalnum.cpp
+ ctype/isalnum.c
Returns whether the character is a letter or a digit.
*******************************************************************************/
#include
-extern "C" int isalnum(int c)
+int isalnum(int c)
{
return isalpha(c) || isdigit(c);
}
diff --git a/libc/ctype/isalpha.cpp b/libc/ctype/isalpha.c
similarity index 95%
rename from libc/ctype/isalpha.cpp
rename to libc/ctype/isalpha.c
index 76541567..bfff6e0a 100644
--- a/libc/ctype/isalpha.cpp
+++ b/libc/ctype/isalpha.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isalpha.cpp
+ ctype/isalpha.c
Returns whether the character is a letter.
*******************************************************************************/
#include
-extern "C" int isalpha(int c)
+int isalpha(int c)
{
return isupper(c) || islower(c);
}
diff --git a/libc/ctype/isascii.cpp b/libc/ctype/isascii.c
similarity index 95%
rename from libc/ctype/isascii.cpp
rename to libc/ctype/isascii.c
index 95fcabbd..5c439eb2 100644
--- a/libc/ctype/isascii.cpp
+++ b/libc/ctype/isascii.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isascii.cpp
+ ctype/isascii.c
Returns whether the character is an ascii character.
*******************************************************************************/
#include
-extern "C" int isascii(int c)
+int isascii(int c)
{
return 0 <= c && c < 128 ? 1 : 0;
}
diff --git a/libc/ctype/isblank.cpp b/libc/ctype/isblank.c
similarity index 95%
rename from libc/ctype/isblank.cpp
rename to libc/ctype/isblank.c
index 7693d5d4..b7b23344 100644
--- a/libc/ctype/isblank.cpp
+++ b/libc/ctype/isblank.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isblank.cpp
+ ctype/isblank.c
Returns whether the character is blank.
*******************************************************************************/
#include
-extern "C" int isblank(int c)
+int isblank(int c)
{
return c == ' ' || c == '\t';
}
diff --git a/libc/ctype/iscntrl.cpp b/libc/ctype/iscntrl.c
similarity index 95%
rename from libc/ctype/iscntrl.cpp
rename to libc/ctype/iscntrl.c
index e4f0455b..a3956f22 100644
--- a/libc/ctype/iscntrl.cpp
+++ b/libc/ctype/iscntrl.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/iscntrl.cpp
+ ctype/iscntrl.c
Returns whether the character is a control character.
*******************************************************************************/
#include
-extern "C" int iscntrl(int c)
+int iscntrl(int c)
{
return 0 <= c && c < 32;
}
diff --git a/libc/ctype/isdigit.cpp b/libc/ctype/isdigit.c
similarity index 95%
rename from libc/ctype/isdigit.cpp
rename to libc/ctype/isdigit.c
index 868ac997..80331d27 100644
--- a/libc/ctype/isdigit.cpp
+++ b/libc/ctype/isdigit.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isdigit.cpp
+ ctype/isdigit.c
Returns whether the character is a digit.
*******************************************************************************/
#include
-extern "C" int isdigit(int c)
+int isdigit(int c)
{
return '0' <= c && c <= '9';
}
diff --git a/libc/ctype/isgraph.cpp b/libc/ctype/isgraph.c
similarity index 95%
rename from libc/ctype/isgraph.cpp
rename to libc/ctype/isgraph.c
index 7c329896..5eff35a8 100644
--- a/libc/ctype/isgraph.cpp
+++ b/libc/ctype/isgraph.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isgraph.cpp
+ ctype/isgraph.c
Returns whether the character is graphical.
*******************************************************************************/
#include
-extern "C" int isgraph(int c)
+int isgraph(int c)
{
return '!' <= c && c <= '~';
}
diff --git a/libc/ctype/islower.cpp b/libc/ctype/islower.c
similarity index 95%
rename from libc/ctype/islower.cpp
rename to libc/ctype/islower.c
index ba437443..0393dec4 100644
--- a/libc/ctype/islower.cpp
+++ b/libc/ctype/islower.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/islower.cpp
+ ctype/islower.c
Returns whether the character is lower-case.
*******************************************************************************/
#include
-extern "C" int islower(int c)
+int islower(int c)
{
return 'a' <= c && c <= 'z';
}
diff --git a/libc/ctype/isprint.cpp b/libc/ctype/isprint.c
similarity index 95%
rename from libc/ctype/isprint.cpp
rename to libc/ctype/isprint.c
index dbdccc76..b46f4bec 100644
--- a/libc/ctype/isprint.cpp
+++ b/libc/ctype/isprint.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isprint.cpp
+ ctype/isprint.c
Returns whether the character is printable.
*******************************************************************************/
#include
-extern "C" int isprint(int c)
+int isprint(int c)
{
return isgraph(c) || c == ' ';
}
diff --git a/libc/ctype/ispunct.cpp b/libc/ctype/ispunct.c
similarity index 95%
rename from libc/ctype/ispunct.cpp
rename to libc/ctype/ispunct.c
index ae01456a..6e34029f 100644
--- a/libc/ctype/ispunct.cpp
+++ b/libc/ctype/ispunct.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/ispunct.cpp
+ ctype/ispunct.c
Returns whether the character is punctuational.
*******************************************************************************/
#include
-extern "C" int ispunct(int c)
+int ispunct(int c)
{
return isprint(c) && c != ' ' && !isalnum(c);
}
diff --git a/libc/ctype/isspace.cpp b/libc/ctype/isspace.c
similarity index 95%
rename from libc/ctype/isspace.cpp
rename to libc/ctype/isspace.c
index 8601e74e..3d84d0fa 100644
--- a/libc/ctype/isspace.cpp
+++ b/libc/ctype/isspace.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isspace.cpp
+ ctype/isspace.c
Returns whether the character is white-space.
*******************************************************************************/
#include
-extern "C" int isspace(int c)
+int isspace(int c)
{
return c == '\t' || c == '\n' || c == '\v' ||
c == '\f' || c == '\r' || c == ' ';
diff --git a/libc/ctype/isupper.cpp b/libc/ctype/isupper.c
similarity index 95%
rename from libc/ctype/isupper.cpp
rename to libc/ctype/isupper.c
index cb384221..592bf9dd 100644
--- a/libc/ctype/isupper.cpp
+++ b/libc/ctype/isupper.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isupper.cpp
+ ctype/isupper.c
Returns whether the character is upper-case.
*******************************************************************************/
#include
-extern "C" int isupper(int c)
+int isupper(int c)
{
return 'A' <= c && c <= 'Z';
}
diff --git a/libc/ctype/isxdigit.cpp b/libc/ctype/isxdigit.c
similarity index 95%
rename from libc/ctype/isxdigit.cpp
rename to libc/ctype/isxdigit.c
index e5a042f9..7e54c703 100644
--- a/libc/ctype/isxdigit.cpp
+++ b/libc/ctype/isxdigit.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/isxdigit.cpp
+ ctype/isxdigit.c
Returns whether the character is a hexadecimal digit.
*******************************************************************************/
#include
-extern "C" int isxdigit(int c)
+int isxdigit(int c)
{
if ( isdigit(c) )
return 1;
diff --git a/libc/ctype/tolower.cpp b/libc/ctype/tolower.c
similarity index 95%
rename from libc/ctype/tolower.cpp
rename to libc/ctype/tolower.c
index 114602db..c4081dec 100644
--- a/libc/ctype/tolower.cpp
+++ b/libc/ctype/tolower.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/tolower.cpp
+ ctype/tolower.c
Converts the character to lower-case if it is upper-case.
*******************************************************************************/
#include
-extern "C" int tolower(int c)
+int tolower(int c)
{
if ( 'A' <= c && c <= 'Z' )
return 'a' + c - 'A';
diff --git a/libc/ctype/toupper.cpp b/libc/ctype/toupper.c
similarity index 95%
rename from libc/ctype/toupper.cpp
rename to libc/ctype/toupper.c
index 49851877..15e244f6 100644
--- a/libc/ctype/toupper.cpp
+++ b/libc/ctype/toupper.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ctype/toupper.cpp
+ ctype/toupper.c
Converts the character to upper-case if it is lower-case.
*******************************************************************************/
#include
-extern "C" int toupper(int c)
+int toupper(int c)
{
if ( 'a' <= c && c <= 'z' )
return 'A' + c - 'a';
diff --git a/libc/dirent/alphasort.cpp b/libc/dirent/alphasort.c
similarity index 91%
rename from libc/dirent/alphasort.cpp
rename to libc/dirent/alphasort.c
index f2203b5f..8f874164 100644
--- a/libc/dirent/alphasort.cpp
+++ b/libc/dirent/alphasort.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/alphasort.cpp
+ dirent/alphasort.c
Compare directory entries alphabetically.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" int alphasort(const struct dirent** a, const struct dirent** b)
+int alphasort(const struct dirent** a, const struct dirent** b)
{
return strcoll((*a)->d_name, (*b)->d_name);
}
diff --git a/libc/dirent/alphasort_r.cpp b/libc/dirent/alphasort_r.c
similarity index 90%
rename from libc/dirent/alphasort_r.cpp
rename to libc/dirent/alphasort_r.c
index c7d51745..8e1c43df 100644
--- a/libc/dirent/alphasort_r.cpp
+++ b/libc/dirent/alphasort_r.c
@@ -17,14 +17,15 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/alphasort_r.cpp
+ dirent/alphasort_r.c
Compare directory entries alphabetically.
*******************************************************************************/
#include
-extern "C" int alphasort_r(const struct dirent** a, const struct dirent** b, void*)
+int alphasort_r(const struct dirent** a, const struct dirent** b, void* ctx)
{
+ (void) ctx;
return alphasort(a, b);
}
diff --git a/libc/dirent/closedir.cpp b/libc/dirent/closedir.c
similarity index 95%
rename from libc/dirent/closedir.cpp
rename to libc/dirent/closedir.c
index fad1dcc3..4a3c89df 100644
--- a/libc/dirent/closedir.cpp
+++ b/libc/dirent/closedir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/closedir.cpp
+ dirent/closedir.c
Closes a directory stream.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" int closedir(DIR* dir)
+int closedir(DIR* dir)
{
close(dir->fd);
free(dir->entry);
diff --git a/libc/dirent/dirfd.cpp b/libc/dirent/dirfd.c
similarity index 95%
rename from libc/dirent/dirfd.cpp
rename to libc/dirent/dirfd.c
index 68a5b3b4..70a622ff 100644
--- a/libc/dirent/dirfd.cpp
+++ b/libc/dirent/dirfd.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/dirfd.cpp
+ dirent/dirfd.c
Returns the file descriptor associated with the directory stream.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" int dirfd(DIR* dir)
+int dirfd(DIR* dir)
{
return dir->fd;
}
diff --git a/libc/dirent/dscandir_r.cpp b/libc/dirent/dscandir_r.c
similarity index 96%
rename from libc/dirent/dscandir_r.cpp
rename to libc/dirent/dscandir_r.c
index 0dec6bf7..c26b1660 100644
--- a/libc/dirent/dscandir_r.cpp
+++ b/libc/dirent/dscandir_r.c
@@ -17,18 +17,18 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/dscandir_r.cpp
+ dirent/dscandir_r.c
Filtered and sorted directory reading.
*******************************************************************************/
-#include
#include
+#include
#include
+#include
#include
#include
-extern "C"
int dscandir_r(DIR* dir,
struct dirent*** namelist_ptr,
int (*filter)(const struct dirent*, void*),
@@ -51,7 +51,8 @@ int dscandir_r(DIR* dir,
return errno = EOVERFLOW, -1;
}
- while ( struct dirent* entry = readdir(dir) )
+ struct dirent* entry;
+ while ( (entry = readdir(dir)) )
{
if ( filter && !filter(entry, filter_ctx) )
continue;
diff --git a/libc/dirent/fdopendir.cpp b/libc/dirent/fdopendir.c
similarity index 96%
rename from libc/dirent/fdopendir.cpp
rename to libc/dirent/fdopendir.c
index 7c5012bb..d6946ba3 100644
--- a/libc/dirent/fdopendir.cpp
+++ b/libc/dirent/fdopendir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/fdopendir.cpp
+ dirent/fdopendir.c
Handles the file descriptor backend for the DIR* API on Sortix.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" DIR* fdopendir(int fd)
+DIR* fdopendir(int fd)
{
int old_dflags = fcntl(fd, F_GETFD);
if ( 0 <= old_dflags && !(old_dflags & FD_CLOEXEC) )
diff --git a/libc/dirent/opendir.cpp b/libc/dirent/opendir.c
similarity index 95%
rename from libc/dirent/opendir.cpp
rename to libc/dirent/opendir.c
index 026bb4e2..ecf99a91 100644
--- a/libc/dirent/opendir.cpp
+++ b/libc/dirent/opendir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/opendir.cpp
+ dirent/opendir.c
Opens a stream for the directory specified by the path.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" DIR* opendir(const char* path)
+DIR* opendir(const char* path)
{
int fd = open(path, O_SEARCH | O_DIRECTORY | O_CLOEXEC);
if ( fd < 0 )
diff --git a/libc/dirent/readdir.cpp b/libc/dirent/readdir.c
similarity index 96%
rename from libc/dirent/readdir.cpp
rename to libc/dirent/readdir.c
index ac24fb16..f62ce1b6 100644
--- a/libc/dirent/readdir.cpp
+++ b/libc/dirent/readdir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/readdir.cpp
+ dirent/readdir.c
Reads a directory entry from a directory stream into a DIR-specific buffer.
*******************************************************************************/
@@ -28,7 +28,7 @@
#include
#include
-extern "C" struct dirent* readdir(DIR* dir)
+struct dirent* readdir(DIR* dir)
{
int old_errno = errno;
struct dirent fallback;
diff --git a/libc/dirent/rewinddir.cpp b/libc/dirent/rewinddir.c
similarity index 94%
rename from libc/dirent/rewinddir.cpp
rename to libc/dirent/rewinddir.c
index c3265657..8e020bd3 100644
--- a/libc/dirent/rewinddir.cpp
+++ b/libc/dirent/rewinddir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/rewinddir.cpp
+ dirent/rewinddir.c
Rewinds a directory stream to the start.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void rewinddir(DIR* dir)
+void rewinddir(DIR* dir)
{
lseek(dir->fd, 0, SEEK_SET);
}
diff --git a/libc/dirent/scandir.cpp b/libc/dirent/scandir.c
similarity index 98%
rename from libc/dirent/scandir.cpp
rename to libc/dirent/scandir.c
index b9938f83..4a67a0e9 100644
--- a/libc/dirent/scandir.cpp
+++ b/libc/dirent/scandir.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/scandir.cpp
+ dirent/scandir.c
Filtered and sorted directory reading.
*******************************************************************************/
@@ -39,7 +39,6 @@ static int wrap_compare(const struct dirent** dirent_a,
return ((int (*)(const struct dirent**, const struct dirent**)) function)(dirent_a, dirent_b);
}
-extern "C"
int scandir(const char* path, struct dirent*** namelist_ptr,
int (*filter)(const struct dirent*),
int (*compare)(const struct dirent**, const struct dirent**))
diff --git a/libc/dirent/versionsort.cpp b/libc/dirent/versionsort.c
similarity index 91%
rename from libc/dirent/versionsort.cpp
rename to libc/dirent/versionsort.c
index 59825d74..66789c80 100644
--- a/libc/dirent/versionsort.cpp
+++ b/libc/dirent/versionsort.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/versionsort.cpp
+ dirent/versionsort.c
Compare directory entries using strverscmp.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" int versionsort(const struct dirent** a, const struct dirent** b)
+int versionsort(const struct dirent** a, const struct dirent** b)
{
return strverscmp((*a)->d_name, (*b)->d_name);
}
diff --git a/libc/dirent/versionsort_r.cpp b/libc/dirent/versionsort_r.c
similarity index 89%
rename from libc/dirent/versionsort_r.cpp
rename to libc/dirent/versionsort_r.c
index d1a17532..770f0ce4 100644
--- a/libc/dirent/versionsort_r.cpp
+++ b/libc/dirent/versionsort_r.c
@@ -17,14 +17,15 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dirent/versionsort_r.cpp
+ dirent/versionsort_r.c
Compare directory entries using strverscmp.
*******************************************************************************/
#include
-extern "C" int versionsort_r(const struct dirent** a, const struct dirent** b, void*)
+int versionsort_r(const struct dirent** a, const struct dirent** b, void* ctx)
{
+ (void) ctx;
return versionsort(a, b);
}
diff --git a/libc/dlfcn/dlfcn.cpp b/libc/dlfcn/dlfcn.c
similarity index 87%
rename from libc/dlfcn/dlfcn.cpp
rename to libc/dlfcn/dlfcn.c
index 2651bdd5..be775255 100644
--- a/libc/dlfcn/dlfcn.cpp
+++ b/libc/dlfcn/dlfcn.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- dlfcn/dlfcn.cpp
+ dlfcn/dlfcn.c
Dynamic linking.
*******************************************************************************/
@@ -27,7 +27,7 @@
static const char* dlerrormsg = NULL;
-extern "C" void* dlopen(const char* filename, int mode)
+void* dlopen(const char* filename, int mode)
{
(void) filename;
(void) mode;
@@ -35,7 +35,7 @@ extern "C" void* dlopen(const char* filename, int mode)
return NULL;
}
-extern "C" void* dlsym(void* handle, const char* name)
+void* dlsym(void* handle, const char* name)
{
(void) handle;
(void) name;
@@ -43,13 +43,13 @@ extern "C" void* dlsym(void* handle, const char* name)
return NULL;
}
-extern "C" int dlclose(void* handle)
+int dlclose(void* handle)
{
(void) handle;
return 0;
}
-extern "C" char* dlerror()
+char* dlerror(void)
{
const char* result = dlerrormsg;
dlerrormsg = NULL;
diff --git a/libc/err/err.cpp b/libc/err/err.c
similarity index 94%
rename from libc/err/err.cpp
rename to libc/err/err.c
index 2f8e2593..ca9bd78b 100644
--- a/libc/err/err.cpp
+++ b/libc/err/err.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/err.cpp
+ err/err.c
Print an error message to stderr and exit the process.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void err(int exitcode, const char* fmt, ...)
+void err(int exitcode, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
diff --git a/libc/err/errx.cpp b/libc/err/errx.c
similarity index 93%
rename from libc/err/errx.cpp
rename to libc/err/errx.c
index 5b1abbad..ae26a5b6 100644
--- a/libc/err/errx.cpp
+++ b/libc/err/errx.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/errx.cpp
+ err/errx.c
Print an error message to stderr and exit the process.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void errx(int exitcode, const char* fmt, ...)
+void errx(int exitcode, const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
diff --git a/libc/err/verr.cpp b/libc/err/verr.c
similarity index 93%
rename from libc/err/verr.cpp
rename to libc/err/verr.c
index 83a88478..cf17bf57 100644
--- a/libc/err/verr.cpp
+++ b/libc/err/verr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/verr.cpp
+ err/verr.c
Print an error message to stderr and exit the process.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" void verr(int exitcode, const char* fmt, va_list ap)
+void verr(int exitcode, const char* fmt, va_list ap)
{
vwarn(fmt, ap);
exit(exitcode);
diff --git a/libc/err/verrx.cpp b/libc/err/verrx.c
similarity index 93%
rename from libc/err/verrx.cpp
rename to libc/err/verrx.c
index e9af7675..ef0e2b2e 100644
--- a/libc/err/verrx.cpp
+++ b/libc/err/verrx.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/verrx.cpp
+ err/verrx.c
Print an error message to stderr and exit the process.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" void verrx(int exitcode, const char* fmt, va_list ap)
+void verrx(int exitcode, const char* fmt, va_list ap)
{
vwarnx(fmt, ap);
exit(exitcode);
diff --git a/libc/err/vwarn.cpp b/libc/err/vwarn.c
similarity index 95%
rename from libc/err/vwarn.cpp
rename to libc/err/vwarn.c
index ea231725..0bd624b4 100644
--- a/libc/err/vwarn.cpp
+++ b/libc/err/vwarn.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/vwarn.cpp
+ err/vwarn.c
Print an error message to stderr.
*******************************************************************************/
@@ -28,7 +28,7 @@
#include
#include
-extern "C" void vwarn(const char* fmt, va_list ap)
+void vwarn(const char* fmt, va_list ap)
{
int errnum = errno;
flockfile(stderr);
diff --git a/libc/err/vwarnx.cpp b/libc/err/vwarnx.c
similarity index 94%
rename from libc/err/vwarnx.cpp
rename to libc/err/vwarnx.c
index 328b3bb8..eeb15a87 100644
--- a/libc/err/vwarnx.cpp
+++ b/libc/err/vwarnx.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/vwarnx.cpp
+ err/vwarnx.c
Print an error message to stderr.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void vwarnx(const char* fmt, va_list ap)
+void vwarnx(const char* fmt, va_list ap)
{
flockfile(stderr);
fprintf_unlocked(stderr, "%s", program_invocation_name);
diff --git a/libc/err/warn.cpp b/libc/err/warn.c
similarity index 94%
rename from libc/err/warn.cpp
rename to libc/err/warn.c
index a3c004a8..246eb486 100644
--- a/libc/err/warn.cpp
+++ b/libc/err/warn.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/warn.cpp
+ err/warn.c
Print an error message to stderr.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void warn(const char* fmt, ...)
+void warn(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
diff --git a/libc/err/warnx.cpp b/libc/err/warnx.c
similarity index 94%
rename from libc/err/warnx.cpp
rename to libc/err/warnx.c
index 974def1c..8ed7d6b3 100644
--- a/libc/err/warnx.cpp
+++ b/libc/err/warnx.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- err/warnx.cpp
+ err/warnx.c
Print an error message to stderr.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void warnx(const char* fmt, ...)
+void warnx(const char* fmt, ...)
{
va_list ap;
va_start(ap, fmt);
diff --git a/libc/errno/errno.cpp b/libc/errno/errno.c
similarity index 74%
rename from libc/errno/errno.cpp
rename to libc/errno/errno.c
index 54780d57..56346d8e 100644
--- a/libc/errno/errno.cpp
+++ b/libc/errno/errno.c
@@ -17,31 +17,31 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- errno/errno.cpp
+ errno/errno.c
Value storing a numeric value representing the last occured error.
*******************************************************************************/
-#define __SORTIX_STDLIB_REDIRECTS 0
#include
#include
-#if __STDC_HOSTED__
+#ifndef __is_sortix_libk
-extern "C" { int __thread errno = 0; }
+__thread int errno = 0;
#else
-extern "C" { int global_errno = 0; }
-extern "C" { errno_location_func_t errno_location_func = NULL; }
+int global_errno = 0;
+errno_location_func_t errno_location_func = NULL;
-extern "C" int* get_errno_location(void)
+int* get_errno_location(void)
{
- if ( errno_location_func ) { return errno_location_func(); }
+ if ( errno_location_func )
+ return errno_location_func();
return &global_errno;
}
-extern "C" void set_errno_location_func(errno_location_func_t func)
+void set_errno_location_func(errno_location_func_t func)
{
errno_location_func = func;
}
diff --git a/libc/error/gnu_error.cpp b/libc/error/gnu_error.c
similarity index 93%
rename from libc/error/gnu_error.cpp
rename to libc/error/gnu_error.c
index bcda2d9a..e7e62bb0 100644
--- a/libc/error/gnu_error.cpp
+++ b/libc/error/gnu_error.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- error/gnu_error.cpp
+ error/gnu_error.c
Prints an error message to stderr and optionally exits the process.
*******************************************************************************/
@@ -29,7 +29,7 @@
#include
#include
-extern "C" void gnu_error(int status, int errnum, const char *format, ...)
+void gnu_error(int status, int errnum, const char *format, ...)
{
flockfile(stderr);
diff --git a/libc/fcntl/creat.cpp b/libc/fcntl/creat.c
similarity index 93%
rename from libc/fcntl/creat.cpp
rename to libc/fcntl/creat.c
index 3082ce03..6dffbd7c 100644
--- a/libc/fcntl/creat.cpp
+++ b/libc/fcntl/creat.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fcntl/creat.cpp
+ fcntl/creat.c
Create a file.
*******************************************************************************/
#include
-extern "C" int creat(const char* path, mode_t mode)
+int creat(const char* path, mode_t mode)
{
return open(path, O_WRONLY | O_CREAT | O_TRUNC, mode);
}
diff --git a/libc/fcntl/fcntl.cpp b/libc/fcntl/fcntl.c
similarity index 96%
rename from libc/fcntl/fcntl.cpp
rename to libc/fcntl/fcntl.c
index fc3ae280..740edc59 100644
--- a/libc/fcntl/fcntl.cpp
+++ b/libc/fcntl/fcntl.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fcntl/fcntl.cpp
+ fcntl/fcntl.c
Manipulates a file descriptor.
*******************************************************************************/
@@ -31,7 +31,7 @@
DEFN_SYSCALL3(int, sys_fcntl, SYSCALL_FCNTL, int, int, uintptr_t);
-extern "C" int fcntl(int fd, int cmd, ...)
+int fcntl(int fd, int cmd, ...)
{
uintptr_t arg;
va_list ap;
diff --git a/libc/fcntl/open.cpp b/libc/fcntl/open.c
similarity index 94%
rename from libc/fcntl/open.cpp
rename to libc/fcntl/open.c
index 0aeb7c8b..78584c4a 100644
--- a/libc/fcntl/open.cpp
+++ b/libc/fcntl/open.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fcntl/open.cpp
+ fcntl/open.c
Open a file.
*******************************************************************************/
@@ -28,7 +28,7 @@
#include
#include
-extern "C" int open(const char* path, int flags, ...)
+int open(const char* path, int flags, ...)
{
mode_t mode = 0;
if ( flags & O_CREAT )
diff --git a/libc/fcntl/openat.cpp b/libc/fcntl/openat.c
similarity index 93%
rename from libc/fcntl/openat.cpp
rename to libc/fcntl/openat.c
index 5f9b3464..12d973c8 100644
--- a/libc/fcntl/openat.cpp
+++ b/libc/fcntl/openat.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fcntl/openat.cpp
+ fcntl/openat.c
Open a file relative to directory.
*******************************************************************************/
@@ -29,7 +29,7 @@
DEFN_SYSCALL4(int, sys_openat, SYSCALL_OPENAT, int, const char*, int, mode_t);
-extern "C" int openat(int dirfd, const char* path, int flags, ...)
+int openat(int dirfd, const char* path, int flags, ...)
{
mode_t mode = 0;
if ( flags & O_CREAT )
diff --git a/libc/fnmatch/fnmatch.cpp b/libc/fnmatch/fnmatch.c
similarity index 97%
rename from libc/fnmatch/fnmatch.cpp
rename to libc/fnmatch/fnmatch.c
index f3c81457..250a665c 100644
--- a/libc/fnmatch/fnmatch.cpp
+++ b/libc/fnmatch/fnmatch.c
@@ -17,13 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fnmatch/fnmatch.cpp
+ fnmatch/fnmatch.c
Filename matching.
*******************************************************************************/
#include
#include
+#include
#include
#define __FNM_NOT_LEADING (1 << 31)
@@ -91,7 +92,7 @@ static bool matches_bracket_pattern(char c, const char* pattern, int flags)
return negated || matched_any;
}
-extern "C" int fnmatch(const char* pattern, const char* string, int flags)
+int fnmatch(const char* pattern, const char* string, int flags)
{
int next_flags = flags | __FNM_NOT_LEADING;
const char* pattern_end;
diff --git a/libc/fsmarshall/fsm_fsbind.cpp b/libc/fsmarshall/fsm_fsbind.c
similarity index 92%
rename from libc/fsmarshall/fsm_fsbind.cpp
rename to libc/fsmarshall/fsm_fsbind.c
index 892c3e7e..07307753 100644
--- a/libc/fsmarshall/fsm_fsbind.cpp
+++ b/libc/fsmarshall/fsm_fsbind.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fsmarshall/fsm_fsbind.cpp
+ fsmarshall/fsm_fsbind.c
Binds a user-space filesystem inode at a mount point.
*******************************************************************************/
@@ -30,7 +30,7 @@
DEFN_SYSCALL3(int, sys_fsm_fsbind, SYSCALL_FSM_FSBIND, int, int, int);
-extern "C" int fsm_fsbind(int rootfd, int mountpoint, int flags)
+int fsm_fsbind(int rootfd, int mountpoint, int flags)
{
return sys_fsm_fsbind(rootfd, mountpoint, flags);
}
diff --git a/libc/fsmarshall/fsm_mountat.cpp b/libc/fsmarshall/fsm_mountat.c
similarity index 90%
rename from libc/fsmarshall/fsm_mountat.cpp
rename to libc/fsmarshall/fsm_mountat.c
index 9b44f198..7b47096f 100644
--- a/libc/fsmarshall/fsm_mountat.cpp
+++ b/libc/fsmarshall/fsm_mountat.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fsmarshall/fsm_mountat.cpp
+ fsmarshall/fsm_mountat.c
Attaches a user-space filesystem at the specified mount point.
*******************************************************************************/
@@ -28,7 +28,7 @@
DEFN_SYSCALL4(int, sys_fsm_mountat, SYSCALL_FSM_MOUNTAT, int, const char*, const struct stat*, int);
-extern "C" int fsm_mountat(int dirfd, const char* path, const struct stat* rootst, int flags)
+int fsm_mountat(int dirfd, const char* path, const struct stat* rootst, int flags)
{
return sys_fsm_mountat(dirfd, path, rootst, flags);
}
diff --git a/libc/fstab/endfsent.cpp b/libc/fstab/endfsent.c
similarity index 95%
rename from libc/fstab/endfsent.cpp
rename to libc/fstab/endfsent.c
index 85667a46..e1ccc01d 100644
--- a/libc/fstab/endfsent.cpp
+++ b/libc/fstab/endfsent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/endfsent.cpp
+ fstab/endfsent.c
Closes the filesystem table.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void endfsent(void)
+void endfsent(void)
{
if ( !__fstab_file )
return;
diff --git a/libc/fstab/getfsent.cpp b/libc/fstab/getfsent.c
similarity index 95%
rename from libc/fstab/getfsent.cpp
rename to libc/fstab/getfsent.c
index a8e107bf..d4fc0a20 100644
--- a/libc/fstab/getfsent.cpp
+++ b/libc/fstab/getfsent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/getfsent.cpp
+ fstab/getfsent.c
Read filesystem table entry.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" struct fstab* getfsent(void)
+struct fstab* getfsent(void)
{
if ( !__fstab_file && !setfsent() )
return NULL;
diff --git a/libc/fstab/getfsfile.cpp b/libc/fstab/getfsfile.c
similarity index 93%
rename from libc/fstab/getfsfile.cpp
rename to libc/fstab/getfsfile.c
index 0e03da64..f311d109 100644
--- a/libc/fstab/getfsfile.cpp
+++ b/libc/fstab/getfsfile.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/getfsfile.cpp
+ fstab/getfsfile.c
Lookup filesystem table by mount point.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" struct fstab* getfsfile(const char* mount_point)
+struct fstab* getfsfile(const char* mount_point)
{
if ( !setfsent() )
return NULL;
diff --git a/libc/fstab/getfsspec.cpp b/libc/fstab/getfsspec.c
similarity index 93%
rename from libc/fstab/getfsspec.cpp
rename to libc/fstab/getfsspec.c
index 9cea2375..4f3a9551 100644
--- a/libc/fstab/getfsspec.cpp
+++ b/libc/fstab/getfsspec.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/getfsspec.cpp
+ fstab/getfsspec.c
Lookup filesystem table by special file.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" struct fstab* getfsspec(const char* special_file)
+struct fstab* getfsspec(const char* special_file)
{
if ( !setfsent() )
return NULL;
diff --git a/libc/fstab/scanfsent.cpp b/libc/fstab/scanfsent.c
similarity index 97%
rename from libc/fstab/scanfsent.cpp
rename to libc/fstab/scanfsent.c
index 858c3f6d..9931a420 100644
--- a/libc/fstab/scanfsent.cpp
+++ b/libc/fstab/scanfsent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/scanfsent.cpp
+ fstab/scanfsent.c
Parse filesystem table entry.
*******************************************************************************/
@@ -80,7 +80,7 @@ char* find_fstype(char* str)
return NULL;
}
-extern "C" int scanfsent(char* str, struct fstab* fs)
+int scanfsent(char* str, struct fstab* fs)
{
char* str_freq;
char* str_passno;
diff --git a/libc/fstab/setfsent.cpp b/libc/fstab/setfsent.c
similarity index 92%
rename from libc/fstab/setfsent.cpp
rename to libc/fstab/setfsent.c
index b2e80365..f88a5a59 100644
--- a/libc/fstab/setfsent.cpp
+++ b/libc/fstab/setfsent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- fstab/setfsent.cpp
+ fstab/setfsent.c
Open filesystem table.
*******************************************************************************/
@@ -25,9 +25,9 @@
#include
#include
-extern "C" { FILE* __fstab_file = NULL; }
+FILE* __fstab_file = NULL;
-extern "C" int setfsent(void)
+int setfsent(void)
{
if ( __fstab_file )
rewind(__fstab_file);
diff --git a/libc/getopt/getopt.cpp b/libc/getopt/getopt.c
similarity index 91%
rename from libc/getopt/getopt.cpp
rename to libc/getopt/getopt.c
index 75776e79..43e4dc21 100644
--- a/libc/getopt/getopt.cpp
+++ b/libc/getopt/getopt.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- getopt/getopt.cpp
+ getopt/getopt.c
Command-line parsing utility function.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" int getopt(int argc, char* const* argv, const char* shortopts)
+int getopt(int argc, char* const* argv, const char* shortopts)
{
return getopt_long(argc, argv, shortopts, NULL, NULL);
}
diff --git a/libc/getopt/getopt_long.cpp b/libc/getopt/getopt_long.c
similarity index 97%
rename from libc/getopt/getopt_long.cpp
rename to libc/getopt/getopt_long.c
index 5455f927..a7f4a31e 100644
--- a/libc/getopt/getopt_long.cpp
+++ b/libc/getopt/getopt_long.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- getopt/getopt_long.cpp
+ getopt/getopt_long.c
Command-line parsing utility function.
*******************************************************************************/
@@ -26,12 +26,13 @@
#include
#include
#include
+#include
#include
-extern "C" { char* optarg = NULL; }
-extern "C" { int opterr = 1; }
-extern "C" { int optind = 1; }
-extern "C" { int optopt = 0; }
+char* optarg = NULL;
+int opterr = 1;
+int optind = 1;
+int optopt = 0;
static char* const* optcurargv;
static const char* optcurarg;
@@ -93,7 +94,6 @@ const struct option* find_long_option(char* arg,
return NULL;
}
-extern "C"
int getopt_long(int argc, char* const* argv, const char* shortopts,
const struct option* longopts, int* longindex)
{
diff --git a/libc/grp/endgrent.cpp b/libc/grp/endgrent.c
similarity index 95%
rename from libc/grp/endgrent.cpp
rename to libc/grp/endgrent.c
index efaa9517..2a365717 100644
--- a/libc/grp/endgrent.cpp
+++ b/libc/grp/endgrent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/endgrent.cpp
+ grp/endgrent.c
Closes the group database.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void endgrent(void)
+void endgrent(void)
{
if ( !__grp_file )
return;
diff --git a/libc/grp/fgetgrent.cpp b/libc/grp/fgetgrent.c
similarity index 92%
rename from libc/grp/fgetgrent.cpp
rename to libc/grp/fgetgrent.c
index c1cdd331..ef13d283 100644
--- a/libc/grp/fgetgrent.cpp
+++ b/libc/grp/fgetgrent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/fgetgrent.cpp
+ grp/fgetgrent.c
Reads a group entry from a FILE in a thread-insecure manner.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" struct group* fgetgrent(FILE* fp)
+struct group* fgetgrent(FILE* fp)
{
static struct group result_object;
static char* buf = NULL;
@@ -39,8 +39,9 @@ extern "C" struct group* fgetgrent(FILE* fp)
buflen = new_buflen;
}
struct group* result;
+ int errnum;
retry:
- int errnum = fgetgrent_r(fp, &result_object, buf, buflen, &result);
+ errnum = fgetgrent_r(fp, &result_object, buf, buflen, &result);
if ( errnum == ERANGE )
{
size_t new_buflen = 2 * buflen;
diff --git a/libc/grp/fgetgrent_r.cpp b/libc/grp/fgetgrent_r.c
similarity index 97%
rename from libc/grp/fgetgrent_r.cpp
rename to libc/grp/fgetgrent_r.c
index 7d6c5476..d3ed11cb 100644
--- a/libc/grp/fgetgrent_r.cpp
+++ b/libc/grp/fgetgrent_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/fgetgrent_r.cpp
+ grp/fgetgrent_r.c
Reads a group entry from a FILE.
*******************************************************************************/
@@ -25,9 +25,10 @@
#include
#include
-#include
#include
+#include
#include
+#include
#include
#include
#include
@@ -106,7 +107,6 @@ static char* next_member(char** current)
return result;
}
-extern "C"
int fgetgrent_r(FILE* restrict fp,
struct group* restrict result,
char* restrict buf,
@@ -158,7 +158,7 @@ int fgetgrent_r(FILE* restrict fp,
if ( !buf_used && feof(fp) )
{
funlockfile(fp);
- return *result_pointer = NULL, errno = original_errno, NULL;
+ return *result_pointer = NULL, errno = original_errno, 0;
}
if ( buf_used == buf_len )
diff --git a/libc/grp/getgrent.cpp b/libc/grp/getgrent.c
similarity index 94%
rename from libc/grp/getgrent.cpp
rename to libc/grp/getgrent.c
index a7b57a38..7a80ea5a 100644
--- a/libc/grp/getgrent.cpp
+++ b/libc/grp/getgrent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrent.cpp
+ grp/getgrent.c
Reads a group entry in a thread-insecure manner.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" struct group* getgrent(void)
+struct group* getgrent(void)
{
if ( !__grp_file && !(__grp_file = opengr()) )
return NULL;
diff --git a/libc/grp/getgrent_r.cpp b/libc/grp/getgrent_r.c
similarity index 97%
rename from libc/grp/getgrent_r.cpp
rename to libc/grp/getgrent_r.c
index 8ed74c72..a80d89f9 100644
--- a/libc/grp/getgrent_r.cpp
+++ b/libc/grp/getgrent_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrent_r.cpp
+ grp/getgrent_r.c
Reads a group entry (but not fully thread-securely).
*******************************************************************************/
@@ -25,7 +25,6 @@
#include
#include
-extern "C"
int getgrent_r(struct group* restrict result,
char* restrict buf,
size_t buflen,
diff --git a/libc/grp/getgrgid.cpp b/libc/grp/getgrgid.c
similarity index 92%
rename from libc/grp/getgrgid.cpp
rename to libc/grp/getgrgid.c
index cdb88d47..2a904c61 100644
--- a/libc/grp/getgrgid.cpp
+++ b/libc/grp/getgrgid.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrgid.cpp
+ grp/getgrgid.c
Searchs the group database for a group with the given numeric group id in a
thread-insecure manner.
@@ -27,7 +27,7 @@
#include
#include
-extern "C" struct group* getgrgid(gid_t gid)
+struct group* getgrgid(gid_t gid)
{
static struct group result_object;
static char* buf = NULL;
@@ -40,8 +40,9 @@ extern "C" struct group* getgrgid(gid_t gid)
buflen = new_buflen;
}
struct group* result;
+ int errnum;
retry:
- int errnum = getgrgid_r(gid, &result_object, buf, buflen, &result);
+ errnum = getgrgid_r(gid, &result_object, buf, buflen, &result);
if ( errnum == ERANGE )
{
size_t new_buflen = 2 * buflen;
diff --git a/libc/grp/getgrgid_r.cpp b/libc/grp/getgrgid_r.c
similarity index 98%
rename from libc/grp/getgrgid_r.cpp
rename to libc/grp/getgrgid_r.c
index 15de23dc..09c57349 100644
--- a/libc/grp/getgrgid_r.cpp
+++ b/libc/grp/getgrgid_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrgid_r.cpp
+ grp/getgrgid_r.c
Searchs the group database for a group with the given numeric group id.
*******************************************************************************/
@@ -26,7 +26,6 @@
#include
#include
-extern "C"
int getgrgid_r(gid_t gid,
struct group* restrict ret,
char* restrict buf,
diff --git a/libc/grp/getgrnam.cpp b/libc/grp/getgrnam.c
similarity index 91%
rename from libc/grp/getgrnam.cpp
rename to libc/grp/getgrnam.c
index b00b7c2e..5187c0ef 100644
--- a/libc/grp/getgrnam.cpp
+++ b/libc/grp/getgrnam.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrnam.cpp
+ grp/getgrnam.c
Searches the group database for a user with the given groupname in a
thread-insecure manner.
@@ -27,7 +27,7 @@
#include
#include
-extern "C" struct group* getgrnam(const char* groupname)
+struct group* getgrnam(const char* groupname)
{
static struct group result_object;
static char* buf = NULL;
@@ -40,8 +40,9 @@ extern "C" struct group* getgrnam(const char* groupname)
buflen = new_buflen;
}
struct group* result;
+ int errnum;
retry:
- int errnum = getgrnam_r(groupname, &result_object, buf, buflen, &result);
+ errnum = getgrnam_r(groupname, &result_object, buf, buflen, &result);
if ( errnum == ERANGE )
{
size_t new_buflen = 2 * buflen;
diff --git a/libc/grp/getgrnam_r.cpp b/libc/grp/getgrnam_r.c
similarity index 98%
rename from libc/grp/getgrnam_r.cpp
rename to libc/grp/getgrnam_r.c
index 6fd5e5f7..7f064d55 100644
--- a/libc/grp/getgrnam_r.cpp
+++ b/libc/grp/getgrnam_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/getgrnam_r.cpp
+ grp/getgrnam_r.c
Searchs the group database for a group with the given groupname.
*******************************************************************************/
@@ -27,7 +27,6 @@
#include
#include
-extern "C"
int getgrnam_r(const char* restrict groupname,
struct group* restrict ret,
char* restrict buf,
diff --git a/libc/grp/opengr.cpp b/libc/grp/opengr.c
similarity index 95%
rename from libc/grp/opengr.cpp
rename to libc/grp/opengr.c
index 8b5c9dee..82b080ff 100644
--- a/libc/grp/opengr.cpp
+++ b/libc/grp/opengr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/opengr.cpp
+ grp/opengr.c
Opens the group database and returns a FILE to it.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" FILE* opengr(void)
+FILE* opengr(void)
{
return fopen("/etc/group", "r");
}
diff --git a/libc/grp/setgrent.cpp b/libc/grp/setgrent.c
similarity index 92%
rename from libc/grp/setgrent.cpp
rename to libc/grp/setgrent.c
index ce3034b2..a12912ef 100644
--- a/libc/grp/setgrent.cpp
+++ b/libc/grp/setgrent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- grp/setgrent.cpp
+ grp/setgrent.c
Rewinds the group database.
*******************************************************************************/
@@ -25,9 +25,9 @@
#include
#include
-extern "C" { FILE* __grp_file = NULL; }
+FILE* __grp_file = NULL;
-extern "C" void setgrent(void)
+void setgrent(void)
{
if ( __grp_file )
rewind(__grp_file);
diff --git a/libc/include/FILE.h b/libc/include/FILE.h
index 8b361d41..ab02bf2b 100644
--- a/libc/include/FILE.h
+++ b/libc/include/FILE.h
@@ -72,8 +72,8 @@ typedef struct __FILE FILE;
#define _FILE_MAX_PUSHBACK 8
-/* Note stdio/stdio.cpp's declarations of stdin/stdout/stderr also needs to be
- changed if you make changes to this structure. */
+/* Note libc's declarations of stdin/stdout/stderr also needs to be changed if
+ you make changes to this structure. */
struct __FILE
{
unsigned char* buffer;
diff --git a/libc/include/dlfcn.h b/libc/include/dlfcn.h
index 5d4633bf..6c4ded19 100644
--- a/libc/include/dlfcn.h
+++ b/libc/include/dlfcn.h
@@ -37,7 +37,7 @@ extern "C" {
#define RTLD_LOCAL 0 /* Bit 8 is not set. */
int dlclose(void* handle);
-char* dlerror();
+char* dlerror(void);
void* dlopen(const char* filename, int mode);
void* dlsym(void* handle, const char* name);
diff --git a/libc/include/libk.h b/libc/include/libk.h
new file mode 100644
index 00000000..a7a408be
--- /dev/null
+++ b/libc/include/libk.h
@@ -0,0 +1,63 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2011, 2012, 2013, 2014, 2015.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ libk.h
+ Standalone C library hooks.
+
+*******************************************************************************/
+
+#ifndef INCLUDE_LIBK_H
+#define INCLUDE_LIBK_H
+
+#include
+#include
+
+#include
+#include
+#include
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+__attribute__((noreturn))
+void libk_assert(const char*, unsigned long, const char*, const char*);
+size_t libk_getpagesize(void);
+void* libk_heap_expand(size_t*);
+void libk_heap_lock(void);
+void libk_heap_unlock(void);
+__attribute__((noreturn))
+void libk_stack_chk_fail(void);
+__attribute__((noreturn))
+void libk_abort(void);
+void libk_random_lock(void);
+void libk_random_unlock(void);
+bool libk_hasentropy(void);
+void libk_getentropy(void*, size_t);
+__attribute__((noreturn))
+void libk_ubsan_abort(const char*, const char*, uint32_t, uint32_t);
+void* libk_mmap(size_t, int);
+void libk_mprotect(void*, size_t, int);
+void libk_munmap(void*, size_t);
+
+#ifdef __cplusplus
+} /* extern "C" */
+#endif
+
+#endif
diff --git a/libc/include/sys/cdefs.h b/libc/include/sys/cdefs.h
index 9616516f..cfb90d9b 100644
--- a/libc/include/sys/cdefs.h
+++ b/libc/include/sys/cdefs.h
@@ -54,10 +54,6 @@
/* Macro to declare a weak alias. */
#if defined(__is_sortix_libc)
-#ifdef __cplusplus
-#define weak_alias_cxx(old, new, mangled) \
- extern "C" { extern __typeof(old) new __attribute__((weak, alias(mangled))); }
-#endif
#define weak_alias(old, new) \
extern __typeof(old) new __attribute__((weak, alias(#old)))
#endif
diff --git a/libc/include/sys/syscall.h b/libc/include/sys/syscall.h
index 206e39d7..4c08327b 100644
--- a/libc/include/sys/syscall.h
+++ b/libc/include/sys/syscall.h
@@ -88,7 +88,7 @@ syscall_type syscall_name syscall_formals;
/* System call accepting no parameters. */
#define DEFN_SYSCALL0(type, fn, num) \
-DEFINE_SYSCALL(type, fn, num, ())
+DEFINE_SYSCALL(type, fn, num, (void))
/* System call accepting 1 parameter. */
#define DEFN_SYSCALL1(type, fn, num, t1) \
diff --git a/libc/include/timespec.h b/libc/include/timespec.h
index eb37cd88..221a8b74 100644
--- a/libc/include/timespec.h
+++ b/libc/include/timespec.h
@@ -101,7 +101,7 @@ static __inline struct timespec timespec_neg(struct timespec t)
return timespec_make(-t.tv_sec, 0);
}
-static __inline struct timespec timespec_nul()
+static __inline struct timespec timespec_nul(void)
{
return timespec_make(0, 0);
}
diff --git a/libc/init/init.cpp b/libc/init/init.c
similarity index 89%
rename from libc/init/init.cpp
rename to libc/init/init.c
index d8a8023d..d71e78cf 100644
--- a/libc/init/init.cpp
+++ b/libc/init/init.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- init/init.cpp
+ init/init.c
Initializes the process by setting up the heap, signal handling, static
memory and other useful things.
@@ -27,8 +27,8 @@
#include
#include
-extern "C" { char* program_invocation_name; }
-extern "C" { char* program_invocation_short_name; }
+char* program_invocation_name;
+char* program_invocation_short_name;
static char* find_last_elem(char* str)
{
@@ -39,7 +39,7 @@ static char* find_last_elem(char* str)
return str;
}
-extern "C" void initialize_standard_library(int argc, char* argv[])
+void initialize_standard_library(int argc, char* argv[])
{
const char* argv0 = argc ? argv[0] : "";
program_invocation_name = (char*) argv0;
diff --git a/libc/inttypes/imaxabs.cpp b/libc/inttypes/imaxabs.c
similarity index 94%
rename from libc/inttypes/imaxabs.cpp
rename to libc/inttypes/imaxabs.c
index 058ab4f9..d3120a43 100644
--- a/libc/inttypes/imaxabs.cpp
+++ b/libc/inttypes/imaxabs.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/imaxabs.cpp
+ inttypes/imaxabs.c
Computes the absolute value of an integer.
*******************************************************************************/
#include
-extern "C" intmax_t imaxabs(intmax_t val)
+intmax_t imaxabs(intmax_t val)
{
return val < 0 ? -val : val;
}
diff --git a/libc/inttypes/imaxdiv.cpp b/libc/inttypes/imaxdiv.c
similarity index 92%
rename from libc/inttypes/imaxdiv.cpp
rename to libc/inttypes/imaxdiv.c
index a5ad4efc..2ad6abef 100644
--- a/libc/inttypes/imaxdiv.cpp
+++ b/libc/inttypes/imaxdiv.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/imaxdiv.cpp
+ inttypes/imaxdiv.c
Compute quotient and remainder of integer division.
*******************************************************************************/
#include
-extern "C" imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom)
+imaxdiv_t imaxdiv(intmax_t numer, intmax_t denom)
{
imaxdiv_t ret;
ret.quot = numer / denom;
diff --git a/libc/inttypes/strtoimax.cpp b/libc/inttypes/strtoimax.c
similarity index 95%
rename from libc/inttypes/strtoimax.cpp
rename to libc/inttypes/strtoimax.c
index 46976c8f..e464dc4b 100644
--- a/libc/inttypes/strtoimax.cpp
+++ b/libc/inttypes/strtoimax.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/strtoimax.cpp
+ inttypes/strtoimax.c
Converts integers represented as strings to binary representation.
*******************************************************************************/
@@ -33,4 +33,4 @@
#define STRTOL_INT_MAX INTMAX_MAX
#define STRTOL_INT_IS_UNSIGNED false
-#include "../stdlib/strtol.cpp"
+#include "../stdlib/strtol.c"
diff --git a/libc/inttypes/strtoumax.cpp b/libc/inttypes/strtoumax.c
similarity index 95%
rename from libc/inttypes/strtoumax.cpp
rename to libc/inttypes/strtoumax.c
index 5d34fad7..bace1727 100644
--- a/libc/inttypes/strtoumax.cpp
+++ b/libc/inttypes/strtoumax.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/strtoumax.cpp
+ inttypes/strtoumax.c
Converts integers represented as strings to binary representation.
*******************************************************************************/
@@ -33,4 +33,4 @@
#define STRTOL_INT_MAX UINTMAX_MAX
#define STRTOL_INT_IS_UNSIGNED true
-#include "../stdlib/strtol.cpp"
+#include "../stdlib/strtol.c"
diff --git a/libc/inttypes/wcstoimax.cpp b/libc/inttypes/wcstoimax.c
similarity index 95%
rename from libc/inttypes/wcstoimax.cpp
rename to libc/inttypes/wcstoimax.c
index 7e3e6f34..c0ab097a 100644
--- a/libc/inttypes/wcstoimax.cpp
+++ b/libc/inttypes/wcstoimax.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/wcstoimax.cpp
+ inttypes/wcstoimax.c
Converts integers represented as strings to binary representation.
*******************************************************************************/
@@ -33,4 +33,4 @@
#define STRTOL_INT_MAX INTMAX_MAX
#define STRTOL_INT_IS_UNSIGNED false
-#include "../stdlib/strtol.cpp"
+#include "../stdlib/strtol.c"
diff --git a/libc/inttypes/wcstoumax.cpp b/libc/inttypes/wcstoumax.c
similarity index 95%
rename from libc/inttypes/wcstoumax.cpp
rename to libc/inttypes/wcstoumax.c
index 01cbbe33..6e895235 100644
--- a/libc/inttypes/wcstoumax.cpp
+++ b/libc/inttypes/wcstoumax.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- inttypes/wcstoumax.cpp
+ inttypes/wcstoumax.c
Converts integers represented as strings to binary representation.
*******************************************************************************/
@@ -33,4 +33,4 @@
#define STRTOL_INT_MAX UINTMAX_MAX
#define STRTOL_INT_IS_UNSIGNED true
-#include "../stdlib/strtol.cpp"
+#include "../stdlib/strtol.c"
diff --git a/libc/ioleast/preadall.cpp b/libc/ioleast/preadall.c
similarity index 91%
rename from libc/ioleast/preadall.cpp
rename to libc/ioleast/preadall.c
index 277dfc8b..99e49a44 100644
--- a/libc/ioleast/preadall.cpp
+++ b/libc/ioleast/preadall.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/preadall.cpp
+ ioleast/preadall.c
Reads as much data as requested from the given offset.
*******************************************************************************/
#include
-extern "C" size_t preadall(int fd, void* buf, size_t count, off_t off)
+size_t preadall(int fd, void* buf, size_t count, off_t off)
{
return preadleast(fd, buf, count, count, off);
}
diff --git a/libc/ioleast/preadleast.cpp b/libc/ioleast/preadleast.c
similarity index 97%
rename from libc/ioleast/preadleast.cpp
rename to libc/ioleast/preadleast.c
index b86a3232..1f60185e 100644
--- a/libc/ioleast/preadleast.cpp
+++ b/libc/ioleast/preadleast.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/preadleast.cpp
+ ioleast/preadleast.c
Reads at least as much data as requested or more from the given offset.
*******************************************************************************/
@@ -28,7 +28,6 @@
#include
#include
-extern "C"
size_t preadleast(int fd, void* buf_ptr, size_t least, size_t max, off_t off)
{
assert(least <= max);
diff --git a/libc/ioleast/pwriteall.cpp b/libc/ioleast/pwriteall.c
similarity index 91%
rename from libc/ioleast/pwriteall.cpp
rename to libc/ioleast/pwriteall.c
index 3da542e9..1b6ac273 100644
--- a/libc/ioleast/pwriteall.cpp
+++ b/libc/ioleast/pwriteall.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/pwriteall.cpp
+ ioleast/pwriteall.c
Writes as much data as requested at the given offset.
*******************************************************************************/
#include
-extern "C" size_t pwriteall(int fd, const void* buf, size_t count, off_t off)
+size_t pwriteall(int fd, const void* buf, size_t count, off_t off)
{
return pwriteleast(fd, buf, count, count, off);
}
diff --git a/libc/ioleast/pwriteleast.cpp b/libc/ioleast/pwriteleast.c
similarity index 97%
rename from libc/ioleast/pwriteleast.cpp
rename to libc/ioleast/pwriteleast.c
index b33ad737..5a863edb 100644
--- a/libc/ioleast/pwriteleast.cpp
+++ b/libc/ioleast/pwriteleast.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/pwriteleast.cpp
+ ioleast/pwriteleast.c
Writes at least as much data as requested or more at the given offset.
*******************************************************************************/
@@ -28,7 +28,6 @@
#include
#include
-extern "C"
size_t pwriteleast(int fd, const void* buf_ptr, size_t least, size_t max, off_t off)
{
assert(least <= max);
diff --git a/libc/ioleast/readall.cpp b/libc/ioleast/readall.c
similarity index 92%
rename from libc/ioleast/readall.cpp
rename to libc/ioleast/readall.c
index 1bd57416..2d70fea5 100644
--- a/libc/ioleast/readall.cpp
+++ b/libc/ioleast/readall.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/readall.cpp
+ ioleast/readall.c
Reads as much data as requested.
*******************************************************************************/
#include
-extern "C" size_t readall(int fd, void* buf, size_t count)
+size_t readall(int fd, void* buf, size_t count)
{
return readleast(fd, buf, count, count);
}
diff --git a/libc/ioleast/readleast.cpp b/libc/ioleast/readleast.c
similarity index 97%
rename from libc/ioleast/readleast.cpp
rename to libc/ioleast/readleast.c
index 0b0cd52f..c5177391 100644
--- a/libc/ioleast/readleast.cpp
+++ b/libc/ioleast/readleast.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/readleast.cpp
+ ioleast/readleast.c
Reads at least as much data as requested or more.
*******************************************************************************/
@@ -28,7 +28,6 @@
#include
#include
-extern "C"
size_t readleast(int fd, void* buf_ptr, size_t least, size_t max)
{
assert(least <= max);
diff --git a/libc/ioleast/writeall.cpp b/libc/ioleast/writeall.c
similarity index 92%
rename from libc/ioleast/writeall.cpp
rename to libc/ioleast/writeall.c
index cc3abb55..a3fd4eb3 100644
--- a/libc/ioleast/writeall.cpp
+++ b/libc/ioleast/writeall.c
@@ -17,14 +17,14 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/writeall.cpp
+ ioleast/writeall.c
Writes as much data as requested.
*******************************************************************************/
#include
-extern "C" size_t writeall(int fd, const void* buf, size_t count)
+size_t writeall(int fd, const void* buf, size_t count)
{
return writeleast(fd, buf, count, count);
}
diff --git a/libc/ioleast/writeleast.cpp b/libc/ioleast/writeleast.c
similarity index 97%
rename from libc/ioleast/writeleast.cpp
rename to libc/ioleast/writeleast.c
index 2db3435b..30fc4df9 100644
--- a/libc/ioleast/writeleast.cpp
+++ b/libc/ioleast/writeleast.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- ioleast/writeleast.cpp
+ ioleast/writeleast.c
Writes at least as much data as requested or more.
*******************************************************************************/
@@ -28,7 +28,6 @@
#include
#include
-extern "C"
size_t writeleast(int fd, const void* buf_ptr, size_t least, size_t max)
{
assert(least <= max);
diff --git a/libc/libgen/basename.cpp b/libc/libgen/basename.c
similarity index 95%
rename from libc/libgen/basename.cpp
rename to libc/libgen/basename.c
index 844148ee..5fbea285 100644
--- a/libc/libgen/basename.cpp
+++ b/libc/libgen/basename.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- libgen/basename.cpp
+ libgen/basename.c
Returns the name part of a path.
*******************************************************************************/
@@ -27,7 +27,7 @@
static const char current_directory[2] = ".";
-extern "C" char* basename(char* path)
+char* basename(char* path)
{
if ( !path || !*path )
return (char*) current_directory;
diff --git a/libc/libgen/dirname.cpp b/libc/libgen/dirname.c
similarity index 96%
rename from libc/libgen/dirname.cpp
rename to libc/libgen/dirname.c
index 83876bb3..0a98f634 100644
--- a/libc/libgen/dirname.cpp
+++ b/libc/libgen/dirname.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- libgen/dirname.cpp
+ libgen/dirname.c
Returns the directory part of a path.
*******************************************************************************/
@@ -27,7 +27,7 @@
static const char current_directory[2] = ".";
-extern "C" char* dirname(char* path)
+char* dirname(char* path)
{
if ( !path || !*path )
return (char*) current_directory;
diff --git a/libc/locale/localeconv.cpp b/libc/locale/localeconv.c
similarity index 96%
rename from libc/locale/localeconv.cpp
rename to libc/locale/localeconv.c
index 5e5f962a..df578563 100644
--- a/libc/locale/localeconv.cpp
+++ b/libc/locale/localeconv.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- locale/localeconv.cpp
+ locale/localeconv.c
Return locale-specific information.
*******************************************************************************/
@@ -26,7 +26,7 @@
static struct lconv lc;
-extern "C" struct lconv* localeconv(void)
+struct lconv* localeconv(void)
{
lc.decimal_point = (char*) ".";
lc.thousands_sep = (char*) "";
diff --git a/libc/locale/setlocale.cpp b/libc/locale/setlocale.c
similarity index 95%
rename from libc/locale/setlocale.cpp
rename to libc/locale/setlocale.c
index e5a19619..4a232afb 100644
--- a/libc/locale/setlocale.cpp
+++ b/libc/locale/setlocale.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- locale/setlocale.cpp
+ locale/setlocale.c
Set program locale.
*******************************************************************************/
@@ -29,7 +29,7 @@
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
-extern "C" char* setlocale(int category, const char* locale)
+char* setlocale(int category, const char* locale)
{
if ( category < 0 || LC_ALL < category )
return errno = EINVAL, (char*) NULL;
diff --git a/libc/malloc/__heap_expand_current_part.cpp b/libc/malloc/__heap_expand_current_part.c
similarity index 81%
rename from libc/malloc/__heap_expand_current_part.cpp
rename to libc/malloc/__heap_expand_current_part.c
index 8b3afb61..8e00fed7 100644
--- a/libc/malloc/__heap_expand_current_part.cpp
+++ b/libc/malloc/__heap_expand_current_part.c
@@ -17,35 +17,28 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- malloc/__heap_expand_current_part.cpp
+ malloc/__heap_expand_current_part.c
Attemps to extend the current part of the heap or create a new part.
*******************************************************************************/
-#if __STDC_HOSTED__
#include
-#endif
#include
#include
+#include
#include
#include
-#if __is_sortix_kernel
-#include
+#ifdef __is_sortix_libk
+#include
#endif
-#if __is_sortix_kernel
-#include
-#include
-#include
-#endif
-
-extern "C" bool __heap_expand_current_part(size_t requested_expansion)
+bool __heap_expand_current_part(size_t requested_expansion)
{
// Determine the current page size.
-#if __is_sortix_kernel
- size_t page_size = Sortix::Page::Size();
+#ifdef __is_sortix_libk
+ size_t page_size = libk_getpagesize();
#else
size_t page_size = getpagesize();
#endif
@@ -54,7 +47,7 @@ extern "C" bool __heap_expand_current_part(size_t requested_expansion)
// case is that we'll need to create a new part, so allocate enough
// memory for that case.
size_t needed_expansion =
- sizeof(struct heap_part) + requested_expansion + sizeof(heap_part_post);
+ sizeof(struct heap_part) + requested_expansion + sizeof(struct heap_part_post);
size_t needed_expansion_pages =
needed_expansion / page_size + (needed_expansion % page_size ? 1 : 0);
@@ -72,25 +65,10 @@ extern "C" bool __heap_expand_current_part(size_t requested_expansion)
// Calculate exactly how many bytes are added to the heap.
size_t num_bytes = needed_expansion_pages * page_size;
-#if __is_sortix_kernel
- // Decide where we would like to add memory to the heap.
- uintptr_t mapto = Sortix::GetHeapUpper();
- assert(!__heap_state.current_part ||
- (uintptr_t) heap_part_end(__heap_state.current_part) == mapto);
- void* mapping = (void*) mapto;
-
- // Attempt to allocate the needed virtual address space such that we can put
- // memory there to extend the heap with.
- if ( !(num_bytes = Sortix::ExpandHeap(num_bytes)) )
+#ifdef __is_sortix_libk
+ void* mapping = libk_heap_expand(&num_bytes);
+ if ( !mapping )
return false;
-
- // Attempt to map actual memory at our new virtual addresses.
- int prot = PROT_KREAD | PROT_KWRITE;
- enum Sortix::page_usage page_usage = Sortix::PAGE_USAGE_KERNEL_HEAP;
- if ( !Sortix::Memory::MapRange(mapto, num_bytes, prot, page_usage) )
- return false;
- Sortix::Memory::Flush();
-
bool ideal_allocation = true;
#else
// Decide where we'd like to allocation memory. Ideally, we'd like to extend
diff --git a/libc/malloc/__heap_lock.c b/libc/malloc/__heap_lock.c
new file mode 100644
index 00000000..b14dd71b
--- /dev/null
+++ b/libc/malloc/__heap_lock.c
@@ -0,0 +1,43 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ malloc/__heap_lock.c
+ Locks the dynamic heap.
+
+*******************************************************************************/
+
+#include
+#include
+
+#ifdef __is_sortix_libk
+#include
+#endif
+
+#ifndef __is_sortix_libk
+pthread_mutex_t __heap_mutex;
+#endif
+
+void __heap_lock(void)
+{
+#ifdef __is_sortix_libk
+ libk_heap_lock();
+#else
+ pthread_mutex_lock(&__heap_mutex);
+#endif
+}
diff --git a/libc/malloc/__heap_lock.cpp b/libc/malloc/__heap_lock.cpp
deleted file mode 100644
index a3d6467f..00000000
--- a/libc/malloc/__heap_lock.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
-
- Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
-
- This file is part of the Sortix C Library.
-
- The Sortix C Library is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or (at your
- option) any later version.
-
- The Sortix C Library 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with the Sortix C Library. If not, see .
-
- malloc/__heap_lock.cpp
- Locks the dynamic heap.
-
-*******************************************************************************/
-
-#include
-#if __STDC_HOSTED__
-#include
-#endif
-
-#if __is_sortix_kernel
-#include
-#endif
-
-#if __STDC_HOSTED__
-extern "C" pthread_mutex_t __heap_mutex;
-#elif __is_sortix_kernel
-extern "C" Sortix::kthread_mutex_t __heap_mutex;
-#endif
-
-extern "C" void __heap_lock(void)
-{
-#if __STDC_HOSTED__
- pthread_mutex_lock(&__heap_mutex);
-#elif __is_sortix_kernel
- Sortix::kthread_mutex_lock(&__heap_mutex);
-#endif
-}
diff --git a/libc/malloc/__heap_unlock.c b/libc/malloc/__heap_unlock.c
new file mode 100644
index 00000000..c3fb3e02
--- /dev/null
+++ b/libc/malloc/__heap_unlock.c
@@ -0,0 +1,43 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ malloc/__heap_unlock.c
+ Unlocks the dynamic heap.
+
+*******************************************************************************/
+
+#include
+#include
+
+#ifdef __is_sortix_libk
+#include
+#endif
+
+#ifndef __is_sortix_libk
+pthread_mutex_t __heap_mutex;
+#endif
+
+void __heap_unlock(void)
+{
+#ifdef __is_sortix_libk
+ libk_heap_unlock();
+#else
+ pthread_mutex_unlock(&__heap_mutex);
+#endif
+}
diff --git a/libc/malloc/__heap_unlock.cpp b/libc/malloc/__heap_unlock.cpp
deleted file mode 100644
index 21cb226d..00000000
--- a/libc/malloc/__heap_unlock.cpp
+++ /dev/null
@@ -1,47 +0,0 @@
-/*******************************************************************************
-
- Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
-
- This file is part of the Sortix C Library.
-
- The Sortix C Library is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or (at your
- option) any later version.
-
- The Sortix C Library 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with the Sortix C Library. If not, see .
-
- malloc/__heap_unlock.cpp
- Unlocks the dynamic heap.
-
-*******************************************************************************/
-
-#include
-#if __STDC_HOSTED__
-#include
-#endif
-
-#if __is_sortix_kernel
-#include
-#endif
-
-#if __STDC_HOSTED__
-extern "C" pthread_mutex_t __heap_mutex;
-#elif __is_sortix_kernel
-extern "C" Sortix::kthread_mutex_t __heap_mutex;
-#endif
-
-extern "C" void __heap_unlock(void)
-{
-#if __STDC_HOSTED__
- pthread_mutex_unlock(&__heap_mutex);
-#elif __is_sortix_kernel
- Sortix::kthread_mutex_unlock(&__heap_mutex);
-#endif
-}
diff --git a/libc/malloc/__heap_verify.cpp b/libc/malloc/__heap_verify.c
similarity index 95%
rename from libc/malloc/__heap_verify.cpp
rename to libc/malloc/__heap_verify.c
index 484df01d..f1904172 100644
--- a/libc/malloc/__heap_verify.cpp
+++ b/libc/malloc/__heap_verify.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- malloc/__heap_verify.cpp
+ malloc/__heap_verify.c
Perform a heap consistency check.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" void __heap_verify()
+void __heap_verify(void)
{
for ( size_t i = 0; i < sizeof(size_t) * 8 - 1; i++ )
{
diff --git a/libc/malloc/heap_get_paranoia.cpp b/libc/malloc/heap_get_paranoia.c
similarity index 88%
rename from libc/malloc/heap_get_paranoia.cpp
rename to libc/malloc/heap_get_paranoia.c
index c033e6d2..af4bd3d4 100644
--- a/libc/malloc/heap_get_paranoia.cpp
+++ b/libc/malloc/heap_get_paranoia.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- malloc/heap_get_paranoia.cpp
+ malloc/heap_get_paranoia.c
Returns how paranoid the heap implementation should be.
*******************************************************************************/
@@ -25,11 +25,11 @@
#include
#include
-extern "C" int heap_get_paranoia(void)
+int heap_get_paranoia(void)
{
-#if defined(PARANOIA_DEFAULT) && !__STDC_HOSTED__
+#if defined(PARANOIA_DEFAULT) && defined(__is_sortix_libk)
return PARANOIA_DEFAULT;
-#elif defined(PARANOIA_DEFAULT) && __STDC_HOSTED__
+#elif defined(PARANOIA_DEFAULT)
static int cached_paranoia = -1;
if ( cached_paranoia < 0 )
{
diff --git a/libc/malloc/heap_init.c b/libc/malloc/heap_init.c
new file mode 100644
index 00000000..cc5d8d31
--- /dev/null
+++ b/libc/malloc/heap_init.c
@@ -0,0 +1,33 @@
+/*******************************************************************************
+
+ Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
+
+ This file is part of the Sortix C Library.
+
+ The Sortix C Library is free software: you can redistribute it and/or modify
+ it under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or (at your
+ option) any later version.
+
+ The Sortix C Library 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 Lesser General Public
+ License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with the Sortix C Library. If not, see .
+
+ malloc/heap_init.c
+ Initializes the dynamic heap.
+
+*******************************************************************************/
+
+#include
+#include
+#include
+
+struct heap_state __heap_state;
+
+#ifdef __is_sortix_libk
+pthread_mutex_t __heap_mutex = PTHREAD_MUTEX_INITIALIZER;
+#endif
diff --git a/libc/malloc/heap_init.cpp b/libc/malloc/heap_init.cpp
deleted file mode 100644
index 97b8fc91..00000000
--- a/libc/malloc/heap_init.cpp
+++ /dev/null
@@ -1,41 +0,0 @@
-/*******************************************************************************
-
- Copyright(C) Jonas 'Sortie' Termansen 2013, 2014.
-
- This file is part of the Sortix C Library.
-
- The Sortix C Library is free software: you can redistribute it and/or modify
- it under the terms of the GNU Lesser General Public License as published by
- the Free Software Foundation, either version 3 of the License, or (at your
- option) any later version.
-
- The Sortix C Library 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 Lesser General Public
- License for more details.
-
- You should have received a copy of the GNU Lesser General Public License
- along with the Sortix C Library. If not, see .
-
- malloc/heap_init.cpp
- Initializes the dynamic heap.
-
-*******************************************************************************/
-
-#include
-#if __STDC_HOSTED__
-#include
-#endif
-#include
-
-#if __is_sortix_kernel
-#include
-#endif
-
-extern "C" { struct heap_state __heap_state; }
-
-#if __STDC_HOSTED__
-extern "C" { pthread_mutex_t __heap_mutex = PTHREAD_MUTEX_INITIALIZER; }
-#elif __is_sortix_kernel
-extern "C" { Sortix::kthread_mutex_t __heap_mutex = Sortix::KTHREAD_MUTEX_INITIALIZER; }
-#endif
diff --git a/libc/msr/rdmsr.cpp b/libc/msr/rdmsr.c
similarity index 95%
rename from libc/msr/rdmsr.cpp
rename to libc/msr/rdmsr.c
index 5b0a8754..e71c8401 100644
--- a/libc/msr/rdmsr.cpp
+++ b/libc/msr/rdmsr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- msr/rdmsr.cpp
+ msr/rdmsr.c
Reads a model specific register.
*******************************************************************************/
@@ -31,7 +31,7 @@
DEFN_SYSCALL1(uint64_t, sys_rdmsr, SYSCALL_RDMSR, uint32_t);
-extern "C" uint64_t rdmsr(uint32_t msrid)
+uint64_t rdmsr(uint32_t msrid)
{
return sys_rdmsr(msrid);
}
diff --git a/libc/msr/wrmsr.cpp b/libc/msr/wrmsr.c
similarity index 94%
rename from libc/msr/wrmsr.cpp
rename to libc/msr/wrmsr.c
index eabb9ccc..f77af716 100644
--- a/libc/msr/wrmsr.cpp
+++ b/libc/msr/wrmsr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- msr/wrmsr.cpp
+ msr/wrmsr.c
Sets a model specific register.
*******************************************************************************/
@@ -31,7 +31,7 @@
DEFN_SYSCALL2(uint64_t, sys_wrmsr, SYSCALL_WRMSR, uint32_t, uint64_t);
-extern "C" uint64_t wrmsr(uint32_t msrid, uint64_t value)
+uint64_t wrmsr(uint32_t msrid, uint64_t value)
{
return sys_wrmsr(msrid, value);
}
diff --git a/libc/netdb/setnetent.cpp b/libc/netdb/endnetent.c
similarity index 95%
rename from libc/netdb/setnetent.cpp
rename to libc/netdb/endnetent.c
index 454da589..d04b8b2d 100644
--- a/libc/netdb/setnetent.cpp
+++ b/libc/netdb/endnetent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/setnetent.cpp
+ netdb/endnetent.c
Get network entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void setnetent(int)
+void endnetent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/setprotoent.cpp b/libc/netdb/endprotoent.c
similarity index 95%
rename from libc/netdb/setprotoent.cpp
rename to libc/netdb/endprotoent.c
index a9dad17e..05d043ac 100644
--- a/libc/netdb/setprotoent.cpp
+++ b/libc/netdb/endprotoent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/setprotoent.cpp
+ netdb/endprotoent.c
Get protocol entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void setprotoent(int)
+void endprotoent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/setservent.cpp b/libc/netdb/endservent.c
similarity index 95%
rename from libc/netdb/setservent.cpp
rename to libc/netdb/endservent.c
index 387bb8a7..b78c3836 100644
--- a/libc/netdb/setservent.cpp
+++ b/libc/netdb/endservent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/setservent.cpp
+ netdb/endservent.c
Get service entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void setservent(int)
+void endservent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/freeaddrinfo.cpp b/libc/netdb/freeaddrinfo.c
similarity index 93%
rename from libc/netdb/freeaddrinfo.cpp
rename to libc/netdb/freeaddrinfo.c
index fca2ab3a..c5dc33ca 100644
--- a/libc/netdb/freeaddrinfo.cpp
+++ b/libc/netdb/freeaddrinfo.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/freeaddrinfo.cpp
+ netdb/freeaddrinfo.c
Free address data structure.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void freeaddrinfo(struct addrinfo* ai)
+void freeaddrinfo(struct addrinfo* ai)
{
while ( ai )
{
diff --git a/libc/netdb/gai_strerror.cpp b/libc/netdb/gai_strerror.c
similarity index 95%
rename from libc/netdb/gai_strerror.cpp
rename to libc/netdb/gai_strerror.c
index 6c930d05..0f4a4327 100644
--- a/libc/netdb/gai_strerror.cpp
+++ b/libc/netdb/gai_strerror.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/gai_strerror.cpp
+ netdb/gai_strerror.c
Error information for getaddrinfo.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" const char* gai_strerror(int err)
+const char* gai_strerror(int err)
{
switch ( err )
{
diff --git a/libc/netdb/getaddrinfo.cpp b/libc/netdb/getaddrinfo.c
similarity index 92%
rename from libc/netdb/getaddrinfo.cpp
rename to libc/netdb/getaddrinfo.c
index 7c0f373d..025eb0e3 100644
--- a/libc/netdb/getaddrinfo.cpp
+++ b/libc/netdb/getaddrinfo.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getaddrinfo.cpp
+ netdb/getaddrinfo.c
Network address and service translation.
*******************************************************************************/
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
#include
#include
@@ -53,10 +54,10 @@ static bool linkaddrinfo(struct addrinfo** restrict* res_ptr,
return true;
}
-extern "C" int getaddrinfo(const char* restrict node,
- const char* restrict servname,
- const struct addrinfo* restrict hints,
- struct addrinfo** restrict res)
+int getaddrinfo(const char* restrict node,
+ const char* restrict servname,
+ const struct addrinfo* restrict hints,
+ struct addrinfo** restrict res)
{
struct addrinfo hints_def;
if ( !hints )
diff --git a/libc/netdb/getnameinfo.cpp b/libc/netdb/getnameinfo.c
similarity index 75%
rename from libc/netdb/getnameinfo.cpp
rename to libc/netdb/getnameinfo.c
index 8bb93f00..3eb41c08 100644
--- a/libc/netdb/getnameinfo.cpp
+++ b/libc/netdb/getnameinfo.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getnameinfo.cpp
+ netdb/getnameinfo.c
Address-to-name translation in protocol-independent manner.
*******************************************************************************/
@@ -27,10 +27,21 @@
#include
#include
-extern "C" int getnameinfo(const struct sockaddr* restrict, socklen_t,
- char* restrict, socklen_t, char* restrict, socklen_t,
- int)
+int getnameinfo(const struct sockaddr* restrict sa,
+ socklen_t salen,
+ char* restrict host,
+ socklen_t hostlen,
+ char* restrict serv,
+ socklen_t servlen,
+ int flags)
{
+ (void) sa;
+ (void) salen;
+ (void) host;
+ (void) hostlen;
+ (void) serv;
+ (void) servlen;
+ (void) flags;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getnetbyaddr.cpp b/libc/netdb/getnetbyaddr.c
similarity index 91%
rename from libc/netdb/getnetbyaddr.cpp
rename to libc/netdb/getnetbyaddr.c
index 2f193b46..e3b24825 100644
--- a/libc/netdb/getnetbyaddr.cpp
+++ b/libc/netdb/getnetbyaddr.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getnetbyaddr.cpp
+ netdb/getnetbyaddr.c
Get network entry.
*******************************************************************************/
@@ -27,8 +27,10 @@
#include
#include
-extern "C" struct netent* getnetbyaddr(uint32_t, int)
+struct netent* getnetbyaddr(uint32_t net, int type)
{
+ (void) net;
+ (void) type;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getnetbyname.cpp b/libc/netdb/getnetbyname.c
similarity index 92%
rename from libc/netdb/getnetbyname.cpp
rename to libc/netdb/getnetbyname.c
index 634e9dab..267c3504 100644
--- a/libc/netdb/getnetbyname.cpp
+++ b/libc/netdb/getnetbyname.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getnetbyname.cpp
+ netdb/getnetbyname.c
Get network entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct netent* getnetbyname(const char*)
+struct netent* getnetbyname(const char* name)
{
+ (void) name;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/endnetent.cpp b/libc/netdb/getnetent.c
similarity index 95%
rename from libc/netdb/endnetent.cpp
rename to libc/netdb/getnetent.c
index d8aa269f..49c4b3b7 100644
--- a/libc/netdb/endnetent.cpp
+++ b/libc/netdb/getnetent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/endnetent.cpp
+ netdb/getnetent.c
Get network entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void endnetent(void)
+struct netent* getnetent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/getprotobynumber.cpp b/libc/netdb/getprotobyname.c
similarity index 92%
rename from libc/netdb/getprotobynumber.cpp
rename to libc/netdb/getprotobyname.c
index d0922cca..dd4e5e58 100644
--- a/libc/netdb/getprotobynumber.cpp
+++ b/libc/netdb/getprotobyname.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getprotobynumber.cpp
+ netdb/getprotobyname.c
Get protocol entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct protoent* getprotobynumber(int)
+struct protoent* getprotobyname(const char* name)
{
+ (void) name;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getprotobyname.cpp b/libc/netdb/getprotobynumber.c
similarity index 92%
rename from libc/netdb/getprotobyname.cpp
rename to libc/netdb/getprotobynumber.c
index 59ebec6e..f650d498 100644
--- a/libc/netdb/getprotobyname.cpp
+++ b/libc/netdb/getprotobynumber.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getprotobyname.cpp
+ netdb/getprotobynumber.c
Get protocol entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct protoent* getprotobyname(const char*)
+struct protoent* getprotobynumber(int proto)
{
+ (void) proto;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/endprotoent.cpp b/libc/netdb/getprotoent.c
similarity index 94%
rename from libc/netdb/endprotoent.cpp
rename to libc/netdb/getprotoent.c
index 5973a93f..5b3c012d 100644
--- a/libc/netdb/endprotoent.cpp
+++ b/libc/netdb/getprotoent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/endprotoent.cpp
+ netdb/getprotoent.c
Get protocol entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void endprotoent(void)
+struct protoent* getprotoent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/getservbyport.cpp b/libc/netdb/getservbyname.c
similarity index 90%
rename from libc/netdb/getservbyport.cpp
rename to libc/netdb/getservbyname.c
index ce7256f1..950867ed 100644
--- a/libc/netdb/getservbyport.cpp
+++ b/libc/netdb/getservbyname.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getservbyport.cpp
+ netdb/getservbyname.c
Get service entry.
*******************************************************************************/
@@ -27,8 +27,10 @@
#include
#include
-extern "C" struct servent* getservbyport(int, const char*)
+struct servent* getservbyname(const char* name, const char* proto)
{
+ (void) name;
+ (void) proto;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getservbyname.cpp b/libc/netdb/getservbyport.c
similarity index 90%
rename from libc/netdb/getservbyname.cpp
rename to libc/netdb/getservbyport.c
index 76016b40..8999b04a 100644
--- a/libc/netdb/getservbyname.cpp
+++ b/libc/netdb/getservbyport.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getservbyname.cpp
+ netdb/getservbyport.c
Get service entry.
*******************************************************************************/
@@ -27,8 +27,10 @@
#include
#include
-extern "C" struct servent* getservbyname(const char*, const char*)
+struct servent* getservbyport(int port, const char* proto)
{
+ (void) port;
+ (void) proto;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/endservent.cpp b/libc/netdb/getservent.c
similarity index 95%
rename from libc/netdb/endservent.cpp
rename to libc/netdb/getservent.c
index ee14c643..80e22463 100644
--- a/libc/netdb/endservent.cpp
+++ b/libc/netdb/getservent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/endservent.cpp
+ netdb/getservent.c
Get service entry.
*******************************************************************************/
@@ -27,7 +27,7 @@
#include
#include
-extern "C" void endservent(void)
+struct servent* getservent(void)
{
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
diff --git a/libc/netdb/getnetent.cpp b/libc/netdb/setnetent.c
similarity index 94%
rename from libc/netdb/getnetent.cpp
rename to libc/netdb/setnetent.c
index 62e2c6b4..1c667ad7 100644
--- a/libc/netdb/getnetent.cpp
+++ b/libc/netdb/setnetent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getnetent.cpp
+ netdb/setnetent.c
Get network entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct netent* getnetent(void)
+void setnetent(int stayopen)
{
+ (void) stayopen;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getprotoent.cpp b/libc/netdb/setprotoent.c
similarity index 93%
rename from libc/netdb/getprotoent.cpp
rename to libc/netdb/setprotoent.c
index 6812adac..b521d262 100644
--- a/libc/netdb/getprotoent.cpp
+++ b/libc/netdb/setprotoent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getprotoent.cpp
+ netdb/setprotoent.c
Get protocol entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct protoent* getprotoent(void)
+void setprotoent(int stayopen)
{
+ (void) stayopen;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netdb/getservent.cpp b/libc/netdb/setservent.c
similarity index 94%
rename from libc/netdb/getservent.cpp
rename to libc/netdb/setservent.c
index b4ce20c2..7ff4adbb 100644
--- a/libc/netdb/getservent.cpp
+++ b/libc/netdb/setservent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netdb/getservent.cpp
+ netdb/setservent.c
Get service entry.
*******************************************************************************/
@@ -27,8 +27,9 @@
#include
#include
-extern "C" struct servent* getservent(void)
+void setservent(int stayopen)
{
+ (void) stayopen;
fprintf(stderr, "%s is not implemented, aborting.\n", __func__);
abort();
}
diff --git a/libc/netinet/in/in6addr_any.cpp b/libc/netinet/in/in6addr_any.c
similarity index 91%
rename from libc/netinet/in/in6addr_any.cpp
rename to libc/netinet/in/in6addr_any.c
index f374dc0c..8c3a6968 100644
--- a/libc/netinet/in/in6addr_any.cpp
+++ b/libc/netinet/in/in6addr_any.c
@@ -17,11 +17,11 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netinet/in/in6addr_any.cpp
+ netinet/in/in6addr_any.c
IPv6 wildcard address.
*******************************************************************************/
#include
-extern "C" const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
+const struct in6_addr in6addr_any = IN6ADDR_ANY_INIT;
diff --git a/libc/netinet/in/in6addr_loopback.cpp b/libc/netinet/in/in6addr_loopback.c
similarity index 90%
rename from libc/netinet/in/in6addr_loopback.cpp
rename to libc/netinet/in/in6addr_loopback.c
index cd04eda0..695e99e7 100644
--- a/libc/netinet/in/in6addr_loopback.cpp
+++ b/libc/netinet/in/in6addr_loopback.c
@@ -17,11 +17,11 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- netinet/in/in6addr_loopback.cpp
+ netinet/in/in6addr_loopback.c
IPv6 loopback address.
*******************************************************************************/
#include
-extern "C" const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
+const struct in6_addr in6addr_loopback = IN6ADDR_LOOPBACK_INIT;
diff --git a/libc/poll/poll.cpp b/libc/poll/poll.c
similarity index 93%
rename from libc/poll/poll.cpp
rename to libc/poll/poll.c
index 630a5ca5..beeac1ef 100644
--- a/libc/poll/poll.cpp
+++ b/libc/poll/poll.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- poll/poll.cpp
+ poll/poll.c
Input/output multiplexing.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" int poll(struct pollfd* fds, nfds_t nfds, int timeout)
+int poll(struct pollfd* fds, nfds_t nfds, int timeout)
{
struct timespec ts;
ts.tv_sec = timeout / 1000;
diff --git a/libc/poll/ppoll.cpp b/libc/poll/ppoll.c
similarity index 88%
rename from libc/poll/ppoll.cpp
rename to libc/poll/ppoll.c
index 5a9968ec..32244be3 100644
--- a/libc/poll/ppoll.cpp
+++ b/libc/poll/ppoll.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- poll/ppoll.cpp
+ poll/ppoll.c
Input/output multiplexing.
*******************************************************************************/
@@ -29,8 +29,8 @@
DEFN_SYSCALL4(int, sys_ppoll, SYSCALL_PPOLL, struct pollfd*, nfds_t,
const struct timespec*, const sigset_t*);
-extern "C" int ppoll(struct pollfd* fds, nfds_t nfds,
- const struct timespec* timeout, const sigset_t* sigmask)
+int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* timeout,
+ const sigset_t* sigmask)
{
return sys_ppoll(fds, nfds, timeout, sigmask);
}
diff --git a/libc/psctl/psctl.cpp b/libc/psctl/psctl.c
similarity index 94%
rename from libc/psctl/psctl.cpp
rename to libc/psctl/psctl.c
index bbd476db..e74baeb7 100644
--- a/libc/psctl/psctl.cpp
+++ b/libc/psctl/psctl.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- psctl/psctl.cpp
+ psctl/psctl.c
Process control interface.
*******************************************************************************/
@@ -29,7 +29,7 @@
DEFN_SYSCALL3(int, sys_psctl, SYSCALL_PSCTL, pid_t, int, void*);
-extern "C" int psctl(pid_t pid, int request, ...)
+int psctl(pid_t pid, int request, ...)
{
va_list ap;
va_start(ap, request);
diff --git a/libc/pwd/bcrypt_newhash.cpp b/libc/pwd/bcrypt_newhash.c
similarity index 99%
rename from libc/pwd/bcrypt_newhash.cpp
rename to libc/pwd/bcrypt_newhash.c
index ce46a4f0..91cabd4e 100644
--- a/libc/pwd/bcrypt_newhash.cpp
+++ b/libc/pwd/bcrypt_newhash.c
@@ -202,7 +202,6 @@ inval:
/*
* user friendly functions
*/
-extern "C"
int
bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen)
{
@@ -218,7 +217,6 @@ bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen)
return 0;
}
-extern "C"
int
bcrypt_checkpass(const char *pass, const char *goodhash)
{
diff --git a/libc/pwd/endpwent.cpp b/libc/pwd/endpwent.c
similarity index 95%
rename from libc/pwd/endpwent.cpp
rename to libc/pwd/endpwent.c
index d6adb1d5..90e8b4c7 100644
--- a/libc/pwd/endpwent.cpp
+++ b/libc/pwd/endpwent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/endpwent.cpp
+ pwd/endpwent.c
Closes the passwd database.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" void endpwent(void)
+void endpwent(void)
{
if ( !__pwd_file )
return;
diff --git a/libc/pwd/fgetpwent.cpp b/libc/pwd/fgetpwent.c
similarity index 92%
rename from libc/pwd/fgetpwent.cpp
rename to libc/pwd/fgetpwent.c
index 16f46877..1a383152 100644
--- a/libc/pwd/fgetpwent.cpp
+++ b/libc/pwd/fgetpwent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/fgetpwent.cpp
+ pwd/fgetpwent.c
Reads a passwd entry from a FILE in a thread-insecure manner.
*******************************************************************************/
@@ -26,7 +26,7 @@
#include
#include
-extern "C" struct passwd* fgetpwent(FILE* fp)
+struct passwd* fgetpwent(FILE* fp)
{
static struct passwd result_object;
static char* buf = NULL;
@@ -39,8 +39,9 @@ extern "C" struct passwd* fgetpwent(FILE* fp)
buflen = new_buflen;
}
struct passwd* result;
+ int errnum;
retry:
- int errnum = fgetpwent_r(fp, &result_object, buf, buflen, &result);
+ errnum = fgetpwent_r(fp, &result_object, buf, buflen, &result);
if ( errnum == ERANGE )
{
size_t new_buflen = 2 * buflen;
diff --git a/libc/pwd/fgetpwent_r.cpp b/libc/pwd/fgetpwent_r.c
similarity index 97%
rename from libc/pwd/fgetpwent_r.cpp
rename to libc/pwd/fgetpwent_r.c
index 11239a42..f3e23ccb 100644
--- a/libc/pwd/fgetpwent_r.cpp
+++ b/libc/pwd/fgetpwent_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/fgetpwent_r.cpp
+ pwd/fgetpwent_r.c
Reads a passwd entry from a FILE.
*******************************************************************************/
@@ -27,6 +27,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -86,7 +87,6 @@ static uid_t next_field_uid(char** current, uid_t* result)
return true;
}
-extern "C"
int fgetpwent_r(FILE* restrict fp,
struct passwd* restrict result,
char* restrict buf,
@@ -138,7 +138,7 @@ int fgetpwent_r(FILE* restrict fp,
if ( !buf_used && feof(fp) )
{
funlockfile(fp);
- return *result_pointer = NULL, errno = original_errno, NULL;
+ return *result_pointer = NULL, errno = original_errno, 0;
}
if ( buf_used == buf_len )
diff --git a/libc/pwd/getpwent.cpp b/libc/pwd/getpwent.c
similarity index 94%
rename from libc/pwd/getpwent.cpp
rename to libc/pwd/getpwent.c
index adbe1b33..0ba9e3f4 100644
--- a/libc/pwd/getpwent.cpp
+++ b/libc/pwd/getpwent.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/getpwent.cpp
+ pwd/getpwent.c
Reads a passwd entry in a thread-insecure manner.
*******************************************************************************/
@@ -25,7 +25,7 @@
#include
#include
-extern "C" struct passwd* getpwent(void)
+struct passwd* getpwent(void)
{
if ( !__pwd_file && !(__pwd_file = openpw()) )
return NULL;
diff --git a/libc/pwd/getpwent_r.cpp b/libc/pwd/getpwent_r.c
similarity index 97%
rename from libc/pwd/getpwent_r.cpp
rename to libc/pwd/getpwent_r.c
index 28e34236..2b2eb098 100644
--- a/libc/pwd/getpwent_r.cpp
+++ b/libc/pwd/getpwent_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/getpwent_r.cpp
+ pwd/getpwent_r.c
Reads a passwd entry (but not fully thread-securely).
*******************************************************************************/
@@ -25,7 +25,6 @@
#include
#include
-extern "C"
int getpwent_r(struct passwd* restrict result,
char* restrict buf,
size_t buflen,
diff --git a/libc/pwd/getpwnam.cpp b/libc/pwd/getpwnam.c
similarity index 91%
rename from libc/pwd/getpwnam.cpp
rename to libc/pwd/getpwnam.c
index c740df4f..229e4e0f 100644
--- a/libc/pwd/getpwnam.cpp
+++ b/libc/pwd/getpwnam.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/getpwnam.cpp
+ pwd/getpwnam.c
Searchs the passwd database for a user with the given username in a
thread-insecure manner.
@@ -27,7 +27,7 @@
#include
#include
-extern "C" struct passwd* getpwnam(const char* username)
+struct passwd* getpwnam(const char* username)
{
static struct passwd result_object;
static char* buf = NULL;
@@ -40,8 +40,9 @@ extern "C" struct passwd* getpwnam(const char* username)
buflen = new_buflen;
}
struct passwd* result;
+ int errnum;
retry:
- int errnum = getpwnam_r(username, &result_object, buf, buflen, &result);
+ errnum = getpwnam_r(username, &result_object, buf, buflen, &result);
if ( errnum == ERANGE )
{
size_t new_buflen = 2 * buflen;
diff --git a/libc/pwd/getpwnam_r.cpp b/libc/pwd/getpwnam_r.c
similarity index 98%
rename from libc/pwd/getpwnam_r.cpp
rename to libc/pwd/getpwnam_r.c
index 7f00eeb9..706a2630 100644
--- a/libc/pwd/getpwnam_r.cpp
+++ b/libc/pwd/getpwnam_r.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see .
- pwd/getpwnam_r.cpp
+ pwd/getpwnam_r.c
Searchs the passwd database for a user with the given username.
*******************************************************************************/
@@ -27,7 +27,6 @@
#include
#include
-extern "C"
int getpwnam_r(const char* restrict username,
struct passwd* restrict ret,
char* restrict buf,
diff --git a/libc/pwd/getpwuid.cpp b/libc/pwd/getpwuid.c
similarity index 92%
rename from libc/pwd/getpwuid.cpp
rename to libc/pwd/getpwuid.c
index fc647095..5f56cf11 100644
--- a/libc/pwd/getpwuid.cpp
+++ b/libc/pwd/getpwuid.c
@@ -17,7 +17,7 @@
You should have received a copy of the GNU Lesser General Public License
along with the Sortix C Library. If not, see