From 01b59c19471a566c67c8da747d11d003bf94e11c Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Sun, 28 Feb 2016 12:11:02 +0100 Subject: [PATCH] Convert libc to C. --- kernel/Makefile | 1 + kernel/include/sortix/display.h | 6 +- kernel/libk.cpp | 177 ++++++++++++++++++ kernel/process.cpp | 2 +- libc/Makefile | 10 +- libc/arpa/inet/{inet_ntoa.cpp => inet_addr.c} | 5 +- libc/arpa/inet/{inet_addr.cpp => inet_ntoa.c} | 5 +- libc/arpa/inet/{inet_ntop.cpp => inet_ntop.c} | 12 +- libc/arpa/inet/{inet_pton.cpp => inet_pton.c} | 7 +- libc/assert/{__assert.cpp => __assert.c} | 12 +- libc/blf/{blowfish.cpp => blowfish.c} | 13 -- libc/c++/{c++.cpp => c++.c++} | 6 +- libc/c++/{op-new.cpp => op-new.c++} | 2 +- libc/ctype/{isalnum.cpp => isalnum.c} | 4 +- libc/ctype/{isalpha.cpp => isalpha.c} | 4 +- libc/ctype/{isascii.cpp => isascii.c} | 4 +- libc/ctype/{isblank.cpp => isblank.c} | 4 +- libc/ctype/{iscntrl.cpp => iscntrl.c} | 4 +- libc/ctype/{isdigit.cpp => isdigit.c} | 4 +- libc/ctype/{isgraph.cpp => isgraph.c} | 4 +- libc/ctype/{islower.cpp => islower.c} | 4 +- libc/ctype/{isprint.cpp => isprint.c} | 4 +- libc/ctype/{ispunct.cpp => ispunct.c} | 4 +- libc/ctype/{isspace.cpp => isspace.c} | 4 +- libc/ctype/{isupper.cpp => isupper.c} | 4 +- libc/ctype/{isxdigit.cpp => isxdigit.c} | 4 +- libc/ctype/{tolower.cpp => tolower.c} | 4 +- libc/ctype/{toupper.cpp => toupper.c} | 4 +- libc/dirent/{alphasort.cpp => alphasort.c} | 4 +- .../dirent/{alphasort_r.cpp => alphasort_r.c} | 5 +- libc/dirent/{closedir.cpp => closedir.c} | 4 +- libc/dirent/{dirfd.cpp => dirfd.c} | 4 +- libc/dirent/{dscandir_r.cpp => dscandir_r.c} | 9 +- libc/dirent/{fdopendir.cpp => fdopendir.c} | 4 +- libc/dirent/{opendir.cpp => opendir.c} | 4 +- libc/dirent/{readdir.cpp => readdir.c} | 4 +- libc/dirent/{rewinddir.cpp => rewinddir.c} | 4 +- libc/dirent/{scandir.cpp => scandir.c} | 3 +- .../dirent/{versionsort.cpp => versionsort.c} | 4 +- .../{versionsort_r.cpp => versionsort_r.c} | 5 +- libc/dlfcn/{dlfcn.cpp => dlfcn.c} | 10 +- libc/err/{err.cpp => err.c} | 4 +- libc/err/{errx.cpp => errx.c} | 4 +- libc/err/{verr.cpp => verr.c} | 4 +- libc/err/{verrx.cpp => verrx.c} | 4 +- libc/err/{vwarn.cpp => vwarn.c} | 4 +- libc/err/{vwarnx.cpp => vwarnx.c} | 4 +- libc/err/{warn.cpp => warn.c} | 4 +- libc/err/{warnx.cpp => warnx.c} | 4 +- libc/errno/{errno.cpp => errno.c} | 18 +- libc/error/{gnu_error.cpp => gnu_error.c} | 4 +- libc/fcntl/{creat.cpp => creat.c} | 4 +- libc/fcntl/{fcntl.cpp => fcntl.c} | 4 +- libc/fcntl/{open.cpp => open.c} | 4 +- libc/fcntl/{openat.cpp => openat.c} | 4 +- libc/fnmatch/{fnmatch.cpp => fnmatch.c} | 5 +- .../{fsm_fsbind.cpp => fsm_fsbind.c} | 4 +- .../{fsm_mountat.cpp => fsm_mountat.c} | 4 +- libc/fstab/{endfsent.cpp => endfsent.c} | 4 +- libc/fstab/{getfsent.cpp => getfsent.c} | 4 +- libc/fstab/{getfsfile.cpp => getfsfile.c} | 4 +- libc/fstab/{getfsspec.cpp => getfsspec.c} | 4 +- libc/fstab/{scanfsent.cpp => scanfsent.c} | 4 +- libc/fstab/{setfsent.cpp => setfsent.c} | 6 +- libc/getopt/{getopt.cpp => getopt.c} | 4 +- .../getopt/{getopt_long.cpp => getopt_long.c} | 12 +- libc/grp/{endgrent.cpp => endgrent.c} | 4 +- libc/grp/{fgetgrent.cpp => fgetgrent.c} | 7 +- libc/grp/{fgetgrent_r.cpp => fgetgrent_r.c} | 8 +- libc/grp/{getgrent.cpp => getgrent.c} | 4 +- libc/grp/{getgrent_r.cpp => getgrent_r.c} | 3 +- libc/grp/{getgrgid.cpp => getgrgid.c} | 7 +- libc/grp/{getgrgid_r.cpp => getgrgid_r.c} | 3 +- libc/grp/{getgrnam.cpp => getgrnam.c} | 7 +- libc/grp/{getgrnam_r.cpp => getgrnam_r.c} | 3 +- libc/grp/{opengr.cpp => opengr.c} | 4 +- libc/grp/{setgrent.cpp => setgrent.c} | 6 +- libc/include/FILE.h | 4 +- libc/include/dlfcn.h | 2 +- libc/include/libk.h | 63 +++++++ libc/include/sys/cdefs.h | 4 - libc/include/sys/syscall.h | 2 +- libc/include/timespec.h | 2 +- libc/init/{init.cpp => init.c} | 8 +- libc/inttypes/{imaxabs.cpp => imaxabs.c} | 4 +- libc/inttypes/{imaxdiv.cpp => imaxdiv.c} | 4 +- libc/inttypes/{strtoimax.cpp => strtoimax.c} | 4 +- libc/inttypes/{strtoumax.cpp => strtoumax.c} | 4 +- libc/inttypes/{wcstoimax.cpp => wcstoimax.c} | 4 +- libc/inttypes/{wcstoumax.cpp => wcstoumax.c} | 4 +- libc/ioleast/{preadall.cpp => preadall.c} | 4 +- libc/ioleast/{preadleast.cpp => preadleast.c} | 3 +- libc/ioleast/{pwriteall.cpp => pwriteall.c} | 4 +- .../{pwriteleast.cpp => pwriteleast.c} | 3 +- libc/ioleast/{readall.cpp => readall.c} | 4 +- libc/ioleast/{readleast.cpp => readleast.c} | 3 +- libc/ioleast/{writeall.cpp => writeall.c} | 4 +- libc/ioleast/{writeleast.cpp => writeleast.c} | 3 +- libc/libgen/{basename.cpp => basename.c} | 4 +- libc/libgen/{dirname.cpp => dirname.c} | 4 +- libc/locale/{localeconv.cpp => localeconv.c} | 4 +- libc/locale/{setlocale.cpp => setlocale.c} | 4 +- ..._part.cpp => __heap_expand_current_part.c} | 44 ++--- libc/malloc/__heap_lock.c | 43 +++++ libc/malloc/__heap_lock.cpp | 47 ----- libc/malloc/__heap_unlock.c | 43 +++++ libc/malloc/__heap_unlock.cpp | 47 ----- .../{__heap_verify.cpp => __heap_verify.c} | 4 +- ...p_get_paranoia.cpp => heap_get_paranoia.c} | 8 +- libc/malloc/heap_init.c | 33 ++++ libc/malloc/heap_init.cpp | 41 ---- libc/msr/{rdmsr.cpp => rdmsr.c} | 4 +- libc/msr/{wrmsr.cpp => wrmsr.c} | 4 +- libc/netdb/{setnetent.cpp => endnetent.c} | 4 +- libc/netdb/{setprotoent.cpp => endprotoent.c} | 4 +- libc/netdb/{setservent.cpp => endservent.c} | 4 +- .../{freeaddrinfo.cpp => freeaddrinfo.c} | 4 +- .../{gai_strerror.cpp => gai_strerror.c} | 4 +- libc/netdb/{getaddrinfo.cpp => getaddrinfo.c} | 11 +- libc/netdb/{getnameinfo.cpp => getnameinfo.c} | 19 +- .../{getnetbyaddr.cpp => getnetbyaddr.c} | 6 +- .../{getnetbyname.cpp => getnetbyname.c} | 5 +- libc/netdb/{endnetent.cpp => getnetent.c} | 4 +- ...{getprotobynumber.cpp => getprotobyname.c} | 5 +- ...{getprotobyname.cpp => getprotobynumber.c} | 5 +- libc/netdb/{endprotoent.cpp => getprotoent.c} | 4 +- .../{getservbyport.cpp => getservbyname.c} | 6 +- .../{getservbyname.cpp => getservbyport.c} | 6 +- libc/netdb/{endservent.cpp => getservent.c} | 4 +- libc/netdb/{getnetent.cpp => setnetent.c} | 5 +- libc/netdb/{getprotoent.cpp => setprotoent.c} | 5 +- libc/netdb/{getservent.cpp => setservent.c} | 5 +- .../in/{in6addr_any.cpp => in6addr_any.c} | 4 +- ...n6addr_loopback.cpp => in6addr_loopback.c} | 4 +- libc/poll/{poll.cpp => poll.c} | 4 +- libc/poll/{ppoll.cpp => ppoll.c} | 6 +- libc/psctl/{psctl.cpp => psctl.c} | 4 +- .../{bcrypt_newhash.cpp => bcrypt_newhash.c} | 2 - libc/pwd/{endpwent.cpp => endpwent.c} | 4 +- libc/pwd/{fgetpwent.cpp => fgetpwent.c} | 7 +- libc/pwd/{fgetpwent_r.cpp => fgetpwent_r.c} | 6 +- libc/pwd/{getpwent.cpp => getpwent.c} | 4 +- libc/pwd/{getpwent_r.cpp => getpwent_r.c} | 3 +- libc/pwd/{getpwnam.cpp => getpwnam.c} | 7 +- libc/pwd/{getpwnam_r.cpp => getpwnam_r.c} | 3 +- libc/pwd/{getpwuid.cpp => getpwuid.c} | 7 +- libc/pwd/{getpwuid_r.cpp => getpwuid_r.c} | 3 +- libc/pwd/{openpw.cpp => openpw.c} | 4 +- libc/pwd/{setpwent.cpp => setpwent.c} | 6 +- libc/regex/{regcomp.cpp => regcomp.c} | 4 +- libc/regex/{regerror.cpp => regerror.c} | 3 +- libc/regex/{regexec.cpp => regexec.c} | 8 +- libc/regex/{regfree.cpp => regfree.c} | 4 +- libc/sched/{sched_yield.cpp => sched_yield.c} | 4 +- libc/scram/{scram.cpp => scram.c} | 4 +- libc/signal/{kill.cpp => kill.c} | 4 +- libc/signal/{killpg.cpp => killpg.c} | 4 +- libc/signal/{psiginfo.cpp => psiginfo.c} | 4 +- libc/signal/{psignal.cpp => psignal.c} | 4 +- libc/signal/{raise.cpp => raise.c} | 4 +- libc/signal/{sigaction.cpp => sigaction.c} | 3 +- libc/signal/{sigaddset.cpp => sigaddset.c} | 4 +- .../signal/{sigaltstack.cpp => sigaltstack.c} | 4 +- libc/signal/{sigandset.cpp => sigandset.c} | 3 +- libc/signal/{sigdelset.cpp => sigdelset.c} | 4 +- .../signal/{sigemptyset.cpp => sigemptyset.c} | 4 +- libc/signal/{sigfillset.cpp => sigfillset.c} | 4 +- .../{sigisemptyset.cpp => sigisemptyset.c} | 4 +- .../signal/{sigismember.cpp => sigismember.c} | 4 +- libc/signal/{signal.cpp => signal.c} | 4 +- libc/signal/{signotset.cpp => signotset.c} | 3 +- libc/signal/{sigorset.cpp => sigorset.c} | 3 +- libc/signal/{sigpending.cpp => sigpending.c} | 4 +- .../signal/{sigprocmask.cpp => sigprocmask.c} | 4 +- libc/signal/{sigsuspend.cpp => sigsuspend.c} | 4 +- ..._stack_chk_fail.cpp => __stack_chk_fail.c} | 22 +-- libc/stdio/{asprintf.cpp => asprintf.c} | 3 +- libc/stdio/{cbprintf.cpp => cbprintf.c} | 3 +- libc/stdio/{clearerr.cpp => clearerr.c} | 4 +- ...arerr_unlocked.cpp => clearerr_unlocked.c} | 4 +- libc/stdio/{dprintf.cpp => dprintf.c} | 4 +- libc/stdio/{fclose.cpp => fclose.c} | 4 +- libc/stdio/{fdeletefile.cpp => fdeletefile.c} | 4 +- libc/stdio/{fdio_close.cpp => fdio_close.c} | 3 +- ...{fdio_install_fd.cpp => fdio_install_fd.c} | 5 +- ...o_install_path.cpp => fdio_install_path.c} | 5 +- libc/stdio/{fdio_read.cpp => fdio_read.c} | 3 +- libc/stdio/{fdio_seek.cpp => fdio_seek.c} | 3 +- libc/stdio/{fdio_write.cpp => fdio_write.c} | 3 +- libc/stdio/{fdopen.cpp => fdopen.c} | 4 +- libc/stdio/{feof.cpp => feof.c} | 4 +- .../{feof_unlocked.cpp => feof_unlocked.c} | 4 +- libc/stdio/{ferror.cpp => ferror.c} | 4 +- ...{ferror_unlocked.cpp => ferror_unlocked.c} | 4 +- libc/stdio/{fflush.cpp => fflush.c} | 6 +- ...stop_reading.cpp => fflush_stop_reading.c} | 4 +- ...ked.cpp => fflush_stop_reading_unlocked.c} | 4 +- ...stop_writing.cpp => fflush_stop_writing.c} | 4 +- ...ked.cpp => fflush_stop_writing_unlocked.c} | 4 +- ...{fflush_unlocked.cpp => fflush_unlocked.c} | 4 +- libc/stdio/{fgetc.cpp => fgetc.c} | 4 +- .../{fgetc_unlocked.cpp => fgetc_unlocked.c} | 4 +- libc/stdio/{fgetpos.cpp => fgetpos.c} | 4 +- libc/stdio/{fgets.cpp => fgets.c} | 4 +- .../{fgets_unlocked.cpp => fgets_unlocked.c} | 3 +- libc/stdio/{fileno.cpp => fileno.c} | 4 +- ...{fileno_unlocked.cpp => fileno_unlocked.c} | 4 +- libc/stdio/{flockfile.cpp => flockfile.c} | 4 +- libc/stdio/{fmemopen.cpp => fmemopen.c} | 4 +- libc/stdio/{fnewfile.cpp => fnewfile.c} | 7 +- libc/stdio/{fopen.cpp => fopen.c} | 4 +- libc/stdio/{fparsemode.cpp => fparsemode.c} | 4 +- libc/stdio/{fpipe.cpp => fpipe.c} | 4 +- libc/stdio/{fprintf.cpp => fprintf.c} | 4 +- ...printf_unlocked.cpp => fprintf_unlocked.c} | 4 +- libc/stdio/{fputc.cpp => fputc.c} | 4 +- .../{fputc_unlocked.cpp => fputc_unlocked.c} | 4 +- libc/stdio/{fputs.cpp => fputs.c} | 4 +- .../{fputs_unlocked.cpp => fputs_unlocked.c} | 4 +- libc/stdio/{fread.cpp => fread.c} | 4 +- .../{fread_unlocked.cpp => fread_unlocked.c} | 3 +- libc/stdio/{fregister.cpp => fregister.c} | 4 +- libc/stdio/{freopen.cpp => freopen.c} | 4 +- libc/stdio/{fresetfile.cpp => fresetfile.c} | 6 +- libc/stdio/{fscanf.cpp => fscanf.c} | 4 +- ...{fscanf_unlocked.cpp => fscanf_unlocked.c} | 4 +- libc/stdio/{fseek.cpp => fseek.c} | 4 +- libc/stdio/{fseeko.cpp => fseeko.c} | 4 +- ...{fseeko_unlocked.cpp => fseeko_unlocked.c} | 4 +- libc/stdio/{fsetpos.cpp => fsetpos.c} | 4 +- libc/stdio/{fshutdown.cpp => fshutdown.c} | 4 +- libc/stdio/{ftell.cpp => ftell.c} | 4 +- libc/stdio/{ftello.cpp => ftello.c} | 4 +- ...{ftello_unlocked.cpp => ftello_unlocked.c} | 4 +- .../{ftrylockfile.cpp => ftrylockfile.c} | 4 +- libc/stdio/{funlockfile.cpp => funlockfile.c} | 4 +- libc/stdio/{funregister.cpp => funregister.c} | 4 +- libc/stdio/{fwrite.cpp => fwrite.c} | 4 +- ...{fwrite_unlocked.cpp => fwrite_unlocked.c} | 3 +- libc/stdio/{getc.cpp => getc.c} | 4 +- .../{getc_unlocked.cpp => getc_unlocked.c} | 4 +- libc/stdio/{getchar.cpp => getchar.c} | 4 +- ...etchar_unlocked.cpp => getchar_unlocked.c} | 4 +- libc/stdio/{getdelim.cpp => getdelim.c} | 4 +- libc/stdio/{getline.cpp => getline.c} | 4 +- .../{open_memstream.cpp => open_memstream.c} | 4 +- libc/stdio/{perror.cpp => perror.c} | 4 +- libc/stdio/{popen.cpp => popen.c} | 14 +- libc/stdio/{printf.cpp => printf.c} | 4 +- libc/stdio/{putc.cpp => putc.c} | 4 +- .../{putc_unlocked.cpp => putc_unlocked.c} | 4 +- libc/stdio/{putchar.cpp => putchar.c} | 4 +- ...utchar_unlocked.cpp => putchar_unlocked.c} | 4 +- libc/stdio/{puts.cpp => puts.c} | 4 +- libc/stdio/{remove.cpp => remove.c} | 4 +- libc/stdio/{removeat.cpp => removeat.c} | 4 +- libc/stdio/{rename.cpp => rename.c} | 4 +- libc/stdio/{renameat.cpp => renameat.c} | 5 +- libc/stdio/{rewind.cpp => rewind.c} | 4 +- libc/stdio/{scanf.cpp => scanf.c} | 4 +- libc/stdio/{setbuf.cpp => setbuf.c} | 4 +- libc/stdio/{setvbuf.cpp => setvbuf.c} | 4 +- ...etvbuf_unlocked.cpp => setvbuf_unlocked.c} | 6 +- libc/stdio/{snprintf.cpp => snprintf.c} | 3 +- libc/stdio/{sprintf.cpp => sprintf.c} | 4 +- libc/stdio/{sscanf.cpp => sscanf.c} | 4 +- libc/stdio/{stderr.cpp => stderr.c} | 8 +- libc/stdio/{stdin.cpp => stdin.c} | 6 +- libc/stdio/{stdout.cpp => stdout.c} | 8 +- libc/stdio/{tmpfile.cpp => tmpfile.c} | 4 +- libc/stdio/{ungetc.cpp => ungetc.c} | 4 +- ...{ungetc_unlocked.cpp => ungetc_unlocked.c} | 4 +- libc/stdio/{vasprintf.cpp => vasprintf.c} | 3 +- libc/stdio/{vcbprintf.cpp => vcbprintf.c} | 15 +- libc/stdio/{vdprintf.cpp => vdprintf.c} | 4 +- libc/stdio/{vfprintf.cpp => vfprintf.c} | 4 +- ...rintf_unlocked.cpp => vfprintf_unlocked.c} | 3 +- libc/stdio/{vfscanf.cpp => vfscanf.c} | 4 +- ...fscanf_unlocked.cpp => vfscanf_unlocked.c} | 4 +- libc/stdio/{vprintf.cpp => vprintf.c} | 4 +- libc/stdio/{vscanf.cpp => vscanf.c} | 4 +- ...{vscanf_callback.cpp => vscanf_callback.c} | 18 +- libc/stdio/{vsnprintf.cpp => vsnprintf.c} | 3 +- libc/stdio/{vsprintf.cpp => vsprintf.c} | 3 +- libc/stdio/{vsscanf.cpp => vsscanf.c} | 4 +- .../{__fbufsize.cpp => __fbufsize.c} | 4 +- .../{__fpending.cpp => __fpending.c} | 4 +- libc/stdio_ext/{__fpurge.cpp => __fpurge.c} | 4 +- .../{__freadable.cpp => __freadable.c} | 4 +- .../{__freading.cpp => __freading.c} | 4 +- libc/stdio_ext/{__fseterr.cpp => __fseterr.c} | 4 +- .../{__fwritable.cpp => __fwritable.c} | 4 +- .../{__fwriting.cpp => __fwriting.c} | 4 +- libc/stdlib/{_Exit.cpp => _Exit.c} | 4 +- libc/stdlib/{abort.cpp => abort.c} | 32 +--- libc/stdlib/{abs.cpp => abs.c} | 4 +- libc/stdlib/{arc4random.cpp => arc4random.c} | 4 +- .../{arc4random_buf.cpp => arc4random_buf.c} | 43 +++-- ...andom_uniform.cpp => arc4random_uniform.c} | 2 +- libc/stdlib/{atexit.cpp => atexit.c} | 7 +- libc/stdlib/{atof.cpp => atof.c} | 6 +- libc/stdlib/{atoi.cpp => atoi.c} | 4 +- libc/stdlib/{atol.cpp => atol.c} | 4 +- libc/stdlib/{atoll.cpp => atoll.c} | 4 +- libc/stdlib/{bsearch.cpp => bsearch.c} | 6 +- libc/stdlib/{calloc.cpp => calloc.c} | 4 +- ...file_name.cpp => canonicalize_file_name.c} | 4 +- ...ame_at.cpp => canonicalize_file_name_at.c} | 4 +- libc/stdlib/{clearenv.cpp => clearenv.c} | 4 +- libc/stdlib/{div.cpp => div.c} | 4 +- libc/stdlib/{exit.cpp => exit.c} | 19 +- libc/stdlib/{free.cpp => free.c} | 24 +-- libc/stdlib/{getenv.cpp => getenv.c} | 5 +- libc/stdlib/{labs.cpp => labs.c} | 4 +- libc/stdlib/{ldiv.cpp => ldiv.c} | 4 +- libc/stdlib/{llabs.cpp => llabs.c} | 4 +- libc/stdlib/{lldiv.cpp => lldiv.c} | 4 +- libc/stdlib/{malloc.cpp => malloc.c} | 40 ++-- libc/stdlib/{mblen.cpp => mblen.c} | 4 +- libc/stdlib/{mbstowcs.cpp => mbstowcs.c} | 3 +- libc/stdlib/{mbtowc.cpp => mbtowc.c} | 4 +- libc/stdlib/{mkdtemp.cpp => mkdtemp.c} | 4 +- libc/stdlib/{mkdtemps.cpp => mkdtemps.c} | 8 +- libc/stdlib/{mkostemp.cpp => mkostemp.c} | 4 +- libc/stdlib/{mkostemps.cpp => mkostemps.c} | 8 +- libc/stdlib/{mkstemp.cpp => mkstemp.c} | 4 +- libc/stdlib/{mkstemps.cpp => mkstemps.c} | 4 +- libc/stdlib/{on_exit.cpp => on_exit.c} | 4 +- libc/stdlib/{qsort.cpp => qsort.c} | 3 +- libc/stdlib/{qsort_r.cpp => qsort_r.c} | 3 +- libc/stdlib/{rand.cpp => rand.c} | 8 +- libc/stdlib/{realloc.cpp => realloc.c} | 20 +- .../{reallocarray.cpp => reallocarray.c} | 4 +- libc/stdlib/{realpath.cpp => realpath.c} | 3 +- libc/stdlib/{setenv.cpp => setenv.c} | 7 +- libc/stdlib/{strtod.cpp => strtod.c} | 4 +- libc/stdlib/{strtof.cpp => strtof.c} | 7 +- libc/stdlib/{strtol.cpp => strtol.c} | 85 +-------- libc/stdlib/{strtold.cpp => strtold.c} | 4 +- libc/stdlib/{strtoll.cpp => strtoll.c} | 4 +- libc/stdlib/{strtoul.cpp => strtoul.c} | 4 +- libc/stdlib/{strtoull.cpp => strtoull.c} | 4 +- libc/stdlib/{system.cpp => system.c} | 4 +- libc/stdlib/{unsetenv.cpp => unsetenv.c} | 5 +- libc/stdlib/{wcstombs.cpp => wcstombs.c} | 4 +- libc/stdlib/{wctomb.cpp => wctomb.c} | 4 +- .../{explicit_bzero.cpp => explicit_bzero.c} | 4 +- libc/string/{ffs.cpp => ffs.c} | 4 +- libc/string/{ffsl.cpp => ffsl.c} | 4 +- libc/string/{ffsll.cpp => ffsll.c} | 4 +- libc/string/{memccpy.cpp => memccpy.c} | 4 +- libc/string/{memchr.cpp => memchr.c} | 4 +- libc/string/{memcmp.cpp => memcmp.c} | 4 +- libc/string/{memcpy.cpp => memcpy.c} | 31 ++- libc/string/{memmove.cpp => memmove.c} | 4 +- libc/string/{memrchr.cpp => memrchr.c} | 4 +- libc/string/{memset.cpp => memset.c} | 4 +- libc/string/{stpcpy.cpp => stpcpy.c} | 4 +- libc/string/{stpncpy.cpp => stpncpy.c} | 4 +- libc/string/{strcasecmp.cpp => strcasecmp.c} | 7 +- libc/string/{strcat.cpp => strcat.c} | 4 +- libc/string/{strchr.cpp => strchr.c} | 4 +- libc/string/{strchrnul.cpp => strchrnul.c} | 5 +- libc/string/{strcmp.cpp => strcmp.c} | 5 +- libc/string/{strcoll.cpp => strcoll.c} | 4 +- libc/string/{strcoll_l.cpp => strcoll_l.c} | 5 +- libc/string/{strcpy.cpp => strcpy.c} | 4 +- libc/string/{strcspn.cpp => strcspn.c} | 5 +- libc/string/{strdup.cpp => strdup.c} | 4 +- libc/string/{strerror.cpp => strerror.c} | 6 +- libc/string/{strerror_l.cpp => strerror_l.c} | 7 +- libc/string/{strerror_r.cpp => strerror_r.c} | 4 +- libc/string/{stresep.cpp => stresep.c} | 5 +- libc/string/{strlcat.cpp => strlcat.c} | 3 +- libc/string/{strlcpy.cpp => strlcpy.c} | 3 +- libc/string/{strlen.cpp => strlen.c} | 4 +- .../string/{strncasecmp.cpp => strncasecmp.c} | 4 +- libc/string/{strncat.cpp => strncat.c} | 4 +- libc/string/{strncmp.cpp => strncmp.c} | 4 +- libc/string/{strncpy.cpp => strncpy.c} | 4 +- libc/string/{strndup.cpp => strndup.c} | 4 +- libc/string/{strnlen.cpp => strnlen.c} | 4 +- libc/string/{strpbrk.cpp => strpbrk.c} | 4 +- libc/string/{strrchr.cpp => strrchr.c} | 5 +- libc/string/{strsep.cpp => strsep.c} | 4 +- libc/string/{strsignal.cpp => strsignal.c} | 6 +- libc/string/{strspn.cpp => strspn.c} | 5 +- libc/string/{strstr.cpp => strstr.c} | 5 +- libc/string/{strtok.cpp => strtok.c} | 4 +- libc/string/{strtok_r.cpp => strtok_r.c} | 4 +- libc/string/{strverscmp.cpp => strverscmp.c} | 5 +- libc/string/{strxfrm.cpp => strxfrm.c} | 4 +- libc/string/{strxfrm_l.cpp => strxfrm_l.c} | 6 +- ...ingsafe_memcmp.cpp => timingsafe_memcmp.c} | 1 - .../{dispmsg_issue.cpp => dispmsg_issue.c} | 4 +- libc/sys/ioctl/{ioctl.cpp => ioctl.c} | 4 +- .../{kernelinfo.cpp => kernelinfo.c} | 4 +- libc/sys/mman/{mmap.cpp => mmap.c} | 3 +- libc/sys/mman/{mprotect.cpp => mprotect.c} | 4 +- libc/sys/mman/{munmap.cpp => munmap.c} | 4 +- libc/sys/mount/{unmount.cpp => unmount.c} | 4 +- libc/sys/mount/{unmountat.cpp => unmountat.c} | 4 +- .../{readdirents.cpp => readdirents.c} | 4 +- .../{getpriority.cpp => getpriority.c} | 4 +- .../resource/{getrlimit.cpp => getrlimit.c} | 4 +- .../resource/{getrusage.cpp => getrusage.c} | 4 +- libc/sys/resource/{prlimit.cpp => prlimit.c} | 3 +- .../{setpriority.cpp => setpriority.c} | 4 +- .../resource/{setrlimit.cpp => setrlimit.c} | 4 +- libc/sys/select/{select.cpp => select.c} | 3 +- libc/sys/socket/{accept.cpp => accept.c} | 5 +- libc/sys/socket/{accept4.cpp => accept4.c} | 6 +- libc/sys/socket/{bind.cpp => bind.c} | 4 +- libc/sys/socket/{connect.cpp => connect.c} | 4 +- .../socket/{getpeername.cpp => getpeername.c} | 3 +- .../socket/{getsockname.cpp => getsockname.c} | 3 +- .../socket/{getsockopt.cpp => getsockopt.c} | 3 +- libc/sys/socket/{listen.cpp => listen.c} | 4 +- libc/sys/socket/{recv.cpp => recv.c} | 4 +- libc/sys/socket/{recvfrom.cpp => recvfrom.c} | 3 +- libc/sys/socket/{recvmsg.cpp => recvmsg.c} | 4 +- libc/sys/socket/{send.cpp => send.c} | 4 +- libc/sys/socket/{sendmsg.cpp => sendmsg.c} | 4 +- libc/sys/socket/{sendto.cpp => sendto.c} | 3 +- .../socket/{setsockopt.cpp => setsockopt.c} | 3 +- libc/sys/socket/{shutdown.cpp => shutdown.c} | 4 +- .../socket/{sockatmark.cpp => sockatmark.c} | 5 +- libc/sys/socket/{socket.cpp => socket.c} | 4 +- .../socket/{socketpair.cpp => socketpair.c} | 5 +- libc/sys/stat/{chmod.cpp => chmod.c} | 4 +- libc/sys/stat/{fchmod.cpp => fchmod.c} | 4 +- libc/sys/stat/{fchmodat.cpp => fchmodat.c} | 4 +- libc/sys/stat/{fstat.cpp => fstat.c} | 4 +- libc/sys/stat/{fstatat.cpp => fstatat.c} | 4 +- libc/sys/stat/{futimens.cpp => futimens.c} | 4 +- libc/sys/stat/{getumask.cpp => getumask.c} | 4 +- libc/sys/stat/{lstat.cpp => lstat.c} | 4 +- libc/sys/stat/{mkdir.cpp => mkdir.c} | 4 +- libc/sys/stat/{mkdirat.cpp => mkdirat.c} | 4 +- libc/sys/stat/{stat.cpp => stat.c} | 4 +- libc/sys/stat/{umask.cpp => umask.c} | 4 +- libc/sys/stat/{utimens.cpp => utimens.c} | 3 +- libc/sys/stat/{utimensat.cpp => utimensat.c} | 3 +- libc/sys/statvfs/{fstatvfs.cpp => fstatvfs.c} | 4 +- .../statvfs/{fstatvfsat.cpp => fstatvfsat.c} | 3 +- libc/sys/statvfs/{statvfs.cpp => statvfs.c} | 3 +- .../{gettermmode.cpp => gettermmode.c} | 4 +- .../{settermmode.cpp => settermmode.c} | 4 +- .../time/{gettimeofday.cpp => gettimeofday.c} | 5 +- libc/sys/times/{times.cpp => times.c} | 4 +- libc/sys/uio/{preadv.cpp => preadv.c} | 3 +- libc/sys/uio/{pwritev.cpp => pwritev.c} | 3 +- libc/sys/uio/{readv.cpp => readv.c} | 4 +- libc/sys/uio/{writev.cpp => writev.c} | 4 +- libc/sys/utsname/{uname.cpp => uname.c} | 4 +- libc/sys/wait/{wait.cpp => wait.c} | 4 +- libc/sys/wait/{waitpid.cpp => waitpid.c} | 4 +- libc/syslog/{closelog.cpp => closelog.c} | 4 +- libc/syslog/{connectlog.cpp => connectlog.c} | 4 +- libc/syslog/{openlog.cpp => openlog.c} | 4 +- libc/syslog/{setlogmask.cpp => setlogmask.c} | 4 +- libc/syslog/{syslog.cpp => syslog.c} | 4 +- libc/syslog/{vsyslog.cpp => vsyslog.c} | 14 +- .../{cfgetispeed.cpp => cfgetispeed.c} | 4 +- .../{cfgetospeed.cpp => cfgetospeed.c} | 4 +- .../{cfsetispeed.cpp => cfsetispeed.c} | 4 +- .../{cfsetospeed.cpp => cfsetospeed.c} | 4 +- libc/termios/{tcdrain.cpp => tcdrain.c} | 4 +- libc/termios/{tcflow.cpp => tcflow.c} | 4 +- libc/termios/{tcflush.cpp => tcflush.c} | 4 +- libc/termios/{tcgetattr.cpp => tcgetattr.c} | 4 +- libc/termios/{tcgetblob.cpp => tcgetblob.c} | 4 +- libc/termios/{tcgetsid.cpp => tcgetsid.c} | 4 +- .../{tcgetwincurpos.cpp => tcgetwincurpos.c} | 4 +- .../{tcgetwinsize.cpp => tcgetwinsize.c} | 4 +- .../{tcsendbreak.cpp => tcsendbreak.c} | 4 +- libc/termios/{tcsetattr.cpp => tcsetattr.c} | 4 +- libc/termios/{tcsetblob.cpp => tcsetblob.c} | 4 +- libc/time/{asctime.cpp => asctime.c} | 4 +- libc/time/{asctime_r.cpp => asctime_r.c} | 4 +- libc/time/{clock.cpp => clock.c} | 4 +- .../time/{clock_getres.cpp => clock_getres.c} | 4 +- .../{clock_gettime.cpp => clock_gettime.c} | 4 +- ...lock_gettimeres.cpp => clock_gettimeres.c} | 7 +- ...{clock_nanosleep.cpp => clock_nanosleep.c} | 3 +- .../{clock_settime.cpp => clock_settime.c} | 4 +- ...lock_settimeres.cpp => clock_settimeres.c} | 7 +- libc/time/{ctime.cpp => ctime.c} | 4 +- libc/time/{ctime_r.cpp => ctime_r.c} | 4 +- libc/time/{difftime.cpp => difftime.c} | 4 +- libc/time/{gmtime.cpp => gmtime.c} | 4 +- libc/time/{gmtime_r.cpp => gmtime_r.c} | 7 +- libc/time/{localtime.cpp => localtime.c} | 4 +- libc/time/{localtime_r.cpp => localtime_r.c} | 4 +- libc/time/{mktime.cpp => mktime.c} | 4 +- libc/time/{nanosleep.cpp => nanosleep.c} | 4 +- libc/time/{strftime.cpp => strftime.c} | 7 +- libc/time/{strftime_l.cpp => strftime_l.c} | 6 +- libc/time/{time.cpp => time.c} | 4 +- libc/time/{timegm.cpp => timegm.c} | 4 +- libc/time/{timens.cpp => timens.c} | 4 +- .../time/{timer_create.cpp => timer_create.c} | 7 +- .../time/{timer_delete.cpp => timer_delete.c} | 4 +- ...imer_getoverrun.cpp => timer_getoverrun.c} | 4 +- .../{timer_gettime.cpp => timer_gettime.c} | 4 +- .../{timer_settime.cpp => timer_settime.c} | 9 +- libc/time/{tzset.cpp => tzset.c} | 6 +- libc/timespec/{timespec.cpp => timespec.c} | 8 +- libc/ubsan/{ubsan.cpp => ubsan.c} | 44 +---- libc/unistd/{_exit.cpp => _exit.c} | 4 +- libc/unistd/{access.cpp => access.c} | 4 +- libc/unistd/{alarm.cpp => alarm.c} | 4 +- libc/unistd/{alarmns.cpp => alarmns.c} | 4 +- libc/unistd/{chdir.cpp => chdir.c} | 4 +- libc/unistd/{chown.cpp => chown.c} | 4 +- libc/unistd/{chroot.cpp => chroot.c} | 4 +- libc/unistd/{close.cpp => close.c} | 4 +- libc/unistd/{closefrom.cpp => closefrom.c} | 4 +- libc/unistd/{confstr.cpp => confstr.c} | 4 +- .../{crypt_newhash.cpp => crypt_newhash.c} | 2 - libc/unistd/{dup.cpp => dup.c} | 4 +- libc/unistd/{dup2.cpp => dup2.c} | 4 +- libc/unistd/{dup3.cpp => dup3.c} | 4 +- libc/unistd/{environ.cpp => environ.c} | 10 +- libc/unistd/{execl.cpp => execl.c} | 4 +- libc/unistd/{execle.cpp => execle.c} | 4 +- libc/unistd/{execlp.cpp => execlp.c} | 4 +- libc/unistd/{execlpe.cpp => execlpe.c} | 4 +- libc/unistd/{execv.cpp => execv.c} | 4 +- libc/unistd/{execve.cpp => execve.c} | 5 +- libc/unistd/{execvp.cpp => execvp.c} | 4 +- libc/unistd/{execvpe.cpp => execvpe.c} | 6 +- .../unistd/{exit_thread.cpp => exit_thread.c} | 3 +- libc/unistd/{faccessat.cpp => faccessat.c} | 4 +- libc/unistd/{fchdir.cpp => fchdir.c} | 4 +- libc/unistd/{fchdirat.cpp => fchdirat.c} | 4 +- libc/unistd/{fchown.cpp => fchown.c} | 4 +- libc/unistd/{fchownat.cpp => fchownat.c} | 4 +- libc/unistd/{fchroot.cpp => fchroot.c} | 4 +- libc/unistd/{fchrootat.cpp => fchrootat.c} | 4 +- libc/unistd/{fork.cpp => fork.c} | 4 +- libc/unistd/{fpathconf.cpp => fpathconf.c} | 4 +- libc/unistd/{fsync.cpp => fsync.c} | 4 +- libc/unistd/{ftruncate.cpp => ftruncate.c} | 4 +- ...nt_dir_name.cpp => get_current_dir_name.c} | 4 +- libc/unistd/{getcwd.cpp => getcwd.c} | 4 +- .../{getdomainname.cpp => getdomainname.c} | 4 +- libc/unistd/{getegid.cpp => getegid.c} | 4 +- libc/unistd/{getentropy.cpp => getentropy.c} | 4 +- libc/unistd/{geteuid.cpp => geteuid.c} | 4 +- libc/unistd/{getgid.cpp => getgid.c} | 4 +- .../unistd/{gethostname.cpp => gethostname.c} | 4 +- libc/unistd/{getlogin.cpp => getlogin.c} | 4 +- libc/unistd/{getlogin_r.cpp => getlogin_r.c} | 4 +- .../unistd/{getpagesize.cpp => getpagesize.c} | 4 +- libc/unistd/{getpgid.cpp => getpgid.c} | 4 +- libc/unistd/{getpid.cpp => getpid.c} | 4 +- libc/unistd/{getppid.cpp => getppid.c} | 4 +- libc/unistd/{getuid.cpp => getuid.c} | 4 +- libc/unistd/{isatty.cpp => isatty.c} | 4 +- libc/unistd/{lchown.cpp => lchown.c} | 4 +- libc/unistd/{link.cpp => link.c} | 4 +- libc/unistd/{linkat.cpp => linkat.c} | 7 +- libc/unistd/{lseek.cpp => lseek.c} | 4 +- libc/unistd/{memstat.cpp => memstat.c} | 4 +- .../unistd/{mkpartition.cpp => mkpartition.c} | 4 +- libc/unistd/{pathconf.cpp => pathconf.c} | 4 +- libc/unistd/{pipe.cpp => pipe.c} | 4 +- libc/unistd/{pipe2.cpp => pipe2.c} | 4 +- libc/unistd/{pread.cpp => pread.c} | 4 +- libc/unistd/{pwrite.cpp => pwrite.c} | 4 +- libc/unistd/{read.cpp => read.c} | 4 +- libc/unistd/{readlink.cpp => readlink.c} | 5 +- libc/unistd/{readlinkat.cpp => readlinkat.c} | 6 +- libc/unistd/{rmdir.cpp => rmdir.c} | 4 +- libc/unistd/{setegid.cpp => setegid.c} | 4 +- libc/unistd/{seteuid.cpp => seteuid.c} | 4 +- libc/unistd/{setgid.cpp => setgid.c} | 4 +- .../unistd/{sethostname.cpp => sethostname.c} | 4 +- libc/unistd/{setpgid.cpp => setpgid.c} | 4 +- libc/unistd/{setuid.cpp => setuid.c} | 4 +- libc/unistd/{sfork.cpp => sfork.c} | 6 +- libc/unistd/{sleep.cpp => sleep.c} | 4 +- libc/unistd/{symlink.cpp => symlink.c} | 4 +- libc/unistd/{symlinkat.cpp => symlinkat.c} | 4 +- libc/unistd/{sysconf.cpp => sysconf.c} | 4 +- libc/unistd/{tcgetpgrp.cpp => tcgetpgrp.c} | 4 +- libc/unistd/{tcsetpgrp.cpp => tcsetpgrp.c} | 4 +- libc/unistd/{tfork.cpp => tfork.c} | 4 +- libc/unistd/{truncate.cpp => truncate.c} | 4 +- libc/unistd/{truncateat.cpp => truncateat.c} | 4 +- libc/unistd/{ttyname.cpp => ttyname.c} | 4 +- libc/unistd/{ttyname_r.cpp => ttyname_r.c} | 4 +- libc/unistd/{unlink.cpp => unlink.c} | 4 +- libc/unistd/{unlinkat.cpp => unlinkat.c} | 4 +- libc/unistd/{usleep.cpp => usleep.c} | 4 +- libc/unistd/{write.cpp => write.c} | 4 +- libc/utime/{utime.cpp => utime.c} | 4 +- libc/wchar/{btowc.cpp => btowc.c} | 4 +- libc/wchar/{mbrlen.cpp => mbrlen.c} | 3 +- libc/wchar/{mbrtowc.cpp => mbrtowc.c} | 3 +- libc/wchar/{mbsinit.cpp => mbsinit.c} | 4 +- libc/wchar/{mbsnrtowcs.cpp => mbsnrtowcs.c} | 3 +- libc/wchar/{mbsrtowcs.cpp => mbsrtowcs.c} | 3 +- libc/wchar/{wcpcpy.cpp => wcpcpy.c} | 4 +- libc/wchar/{wcpncpy.cpp => wcpncpy.c} | 3 +- libc/wchar/{wcrtomb.cpp => wcrtomb.c} | 6 +- libc/wchar/{wcscasecmp.cpp => wcscasecmp.c} | 4 +- libc/wchar/{wcscat.cpp => wcscat.c} | 4 +- libc/wchar/{wcschr.cpp => wcschr.c} | 4 +- libc/wchar/{wcschrnul.cpp => wcschrnul.c} | 5 +- libc/wchar/{wcscmp.cpp => wcscmp.c} | 5 +- libc/wchar/{wcscoll.cpp => wcscoll.c} | 4 +- libc/wchar/{wcscpy.cpp => wcscpy.c} | 4 +- libc/wchar/{wcscspn.cpp => wcscspn.c} | 5 +- libc/wchar/{wcsdup.cpp => wcsdup.c} | 4 +- libc/wchar/{wcsftime.cpp => wcsftime.c} | 4 +- libc/wchar/{wcslcat.cpp => wcslcat.c} | 3 +- libc/wchar/{wcslcpy.cpp => wcslcpy.c} | 3 +- libc/wchar/{wcslen.cpp => wcslen.c} | 4 +- libc/wchar/{wcsncasecmp.cpp => wcsncasecmp.c} | 3 +- libc/wchar/{wcsncat.cpp => wcsncat.c} | 4 +- libc/wchar/{wcsncmp.cpp => wcsncmp.c} | 4 +- libc/wchar/{wcsncpy.cpp => wcsncpy.c} | 4 +- libc/wchar/{wcsnlen.cpp => wcsnlen.c} | 4 +- libc/wchar/{wcsnrtombs.cpp => wcsnrtombs.c} | 3 +- libc/wchar/{wcspbrk.cpp => wcspbrk.c} | 4 +- libc/wchar/{wcsrchr.cpp => wcsrchr.c} | 5 +- libc/wchar/{wcsrtombs.cpp => wcsrtombs.c} | 3 +- libc/wchar/{wcsspn.cpp => wcsspn.c} | 5 +- libc/wchar/{wcsstr.cpp => wcsstr.c} | 4 +- libc/wchar/{wcstod.cpp => wcstod.c} | 4 +- libc/wchar/{wcstof.cpp => wcstof.c} | 4 +- libc/wchar/{wcstok.cpp => wcstok.c} | 4 +- libc/wchar/{wcstol.cpp => wcstol.c} | 4 +- libc/wchar/{wcstold.cpp => wcstold.c} | 4 +- libc/wchar/{wcstoll.cpp => wcstoll.c} | 4 +- libc/wchar/{wcstoul.cpp => wcstoul.c} | 4 +- libc/wchar/{wcstoull.cpp => wcstoull.c} | 4 +- libc/wchar/{wcswidth.cpp => wcswidth.c} | 4 +- libc/wchar/{wcsxfrm.cpp => wcsxfrm.c} | 3 +- libc/wchar/{wctob.cpp => wctob.c} | 4 +- libc/wchar/{wcwidth.cpp => wcwidth.c} | 4 +- libc/wchar/{wmemchr.cpp => wmemchr.c} | 4 +- libc/wchar/{wmemcmp.cpp => wmemcmp.c} | 4 +- libc/wchar/{wmemcpy.cpp => wmemcpy.c} | 3 +- libc/wchar/{wmemmove.cpp => wmemmove.c} | 4 +- libc/wchar/{wmemset.cpp => wmemset.c} | 4 +- libc/wctype/{iswalnum.cpp => iswalnum.c} | 4 +- libc/wctype/{iswalpha.cpp => iswalpha.c} | 4 +- libc/wctype/{iswblank.cpp => iswblank.c} | 4 +- libc/wctype/{iswcntrl.cpp => iswcntrl.c} | 4 +- libc/wctype/{iswctype.cpp => iswctype.c} | 4 +- libc/wctype/{iswdigit.cpp => iswdigit.c} | 4 +- libc/wctype/{iswgraph.cpp => iswgraph.c} | 4 +- libc/wctype/{iswlower.cpp => iswlower.c} | 4 +- libc/wctype/{iswprint.cpp => iswprint.c} | 4 +- libc/wctype/{iswpunct.cpp => iswpunct.c} | 4 +- libc/wctype/{iswspace.cpp => iswspace.c} | 4 +- libc/wctype/{iswupper.cpp => iswupper.c} | 4 +- libc/wctype/{iswxdigit.cpp => iswxdigit.c} | 4 +- libc/wctype/{towlower.cpp => towlower.c} | 4 +- libc/wctype/{towupper.cpp => towupper.c} | 4 +- libc/wctype/{wctype.cpp => wctype.c} | 4 +- utils/du.cpp | 18 +- utils/find.cpp | 4 +- utils/mv.cpp | 4 +- utils/which.cpp | 2 +- 668 files changed, 1895 insertions(+), 1851 deletions(-) create mode 100644 kernel/libk.cpp rename libc/arpa/inet/{inet_ntoa.cpp => inet_addr.c} (94%) rename libc/arpa/inet/{inet_addr.cpp => inet_ntoa.c} (94%) rename libc/arpa/inet/{inet_ntop.cpp => inet_ntop.c} (83%) rename libc/arpa/inet/{inet_pton.cpp => inet_pton.c} (90%) rename libc/assert/{__assert.cpp => __assert.c} (85%) rename libc/blf/{blowfish.cpp => blowfish.c} (99%) rename libc/c++/{c++.cpp => c++.c++} (87%) rename libc/c++/{op-new.cpp => op-new.c++} (98%) rename libc/ctype/{isalnum.cpp => isalnum.c} (95%) rename libc/ctype/{isalpha.cpp => isalpha.c} (95%) rename libc/ctype/{isascii.cpp => isascii.c} (95%) rename libc/ctype/{isblank.cpp => isblank.c} (95%) rename libc/ctype/{iscntrl.cpp => iscntrl.c} (95%) rename libc/ctype/{isdigit.cpp => isdigit.c} (95%) rename libc/ctype/{isgraph.cpp => isgraph.c} (95%) rename libc/ctype/{islower.cpp => islower.c} (95%) rename libc/ctype/{isprint.cpp => isprint.c} (95%) rename libc/ctype/{ispunct.cpp => ispunct.c} (95%) rename libc/ctype/{isspace.cpp => isspace.c} (95%) rename libc/ctype/{isupper.cpp => isupper.c} (95%) rename libc/ctype/{isxdigit.cpp => isxdigit.c} (95%) rename libc/ctype/{tolower.cpp => tolower.c} (95%) rename libc/ctype/{toupper.cpp => toupper.c} (95%) rename libc/dirent/{alphasort.cpp => alphasort.c} (91%) rename libc/dirent/{alphasort_r.cpp => alphasort_r.c} (90%) rename libc/dirent/{closedir.cpp => closedir.c} (95%) rename libc/dirent/{dirfd.cpp => dirfd.c} (95%) rename libc/dirent/{dscandir_r.cpp => dscandir_r.c} (96%) rename libc/dirent/{fdopendir.cpp => fdopendir.c} (96%) rename libc/dirent/{opendir.cpp => opendir.c} (95%) rename libc/dirent/{readdir.cpp => readdir.c} (96%) rename libc/dirent/{rewinddir.cpp => rewinddir.c} (94%) rename libc/dirent/{scandir.cpp => scandir.c} (98%) rename libc/dirent/{versionsort.cpp => versionsort.c} (91%) rename libc/dirent/{versionsort_r.cpp => versionsort_r.c} (89%) rename libc/dlfcn/{dlfcn.cpp => dlfcn.c} (87%) rename libc/err/{err.cpp => err.c} (94%) rename libc/err/{errx.cpp => errx.c} (93%) rename libc/err/{verr.cpp => verr.c} (93%) rename libc/err/{verrx.cpp => verrx.c} (93%) rename libc/err/{vwarn.cpp => vwarn.c} (95%) rename libc/err/{vwarnx.cpp => vwarnx.c} (94%) rename libc/err/{warn.cpp => warn.c} (94%) rename libc/err/{warnx.cpp => warnx.c} (94%) rename libc/errno/{errno.cpp => errno.c} (74%) rename libc/error/{gnu_error.cpp => gnu_error.c} (93%) rename libc/fcntl/{creat.cpp => creat.c} (93%) rename libc/fcntl/{fcntl.cpp => fcntl.c} (96%) rename libc/fcntl/{open.cpp => open.c} (94%) rename libc/fcntl/{openat.cpp => openat.c} (93%) rename libc/fnmatch/{fnmatch.cpp => fnmatch.c} (97%) rename libc/fsmarshall/{fsm_fsbind.cpp => fsm_fsbind.c} (92%) rename libc/fsmarshall/{fsm_mountat.cpp => fsm_mountat.c} (90%) rename libc/fstab/{endfsent.cpp => endfsent.c} (95%) rename libc/fstab/{getfsent.cpp => getfsent.c} (95%) rename libc/fstab/{getfsfile.cpp => getfsfile.c} (93%) rename libc/fstab/{getfsspec.cpp => getfsspec.c} (93%) rename libc/fstab/{scanfsent.cpp => scanfsent.c} (97%) rename libc/fstab/{setfsent.cpp => setfsent.c} (92%) rename libc/getopt/{getopt.cpp => getopt.c} (91%) rename libc/getopt/{getopt_long.cpp => getopt_long.c} (97%) rename libc/grp/{endgrent.cpp => endgrent.c} (95%) rename libc/grp/{fgetgrent.cpp => fgetgrent.c} (92%) rename libc/grp/{fgetgrent_r.cpp => fgetgrent_r.c} (97%) rename libc/grp/{getgrent.cpp => getgrent.c} (94%) rename libc/grp/{getgrent_r.cpp => getgrent_r.c} (97%) rename libc/grp/{getgrgid.cpp => getgrgid.c} (92%) rename libc/grp/{getgrgid_r.cpp => getgrgid_r.c} (98%) rename libc/grp/{getgrnam.cpp => getgrnam.c} (91%) rename libc/grp/{getgrnam_r.cpp => getgrnam_r.c} (98%) rename libc/grp/{opengr.cpp => opengr.c} (95%) rename libc/grp/{setgrent.cpp => setgrent.c} (92%) create mode 100644 libc/include/libk.h rename libc/init/{init.cpp => init.c} (89%) rename libc/inttypes/{imaxabs.cpp => imaxabs.c} (94%) rename libc/inttypes/{imaxdiv.cpp => imaxdiv.c} (92%) rename libc/inttypes/{strtoimax.cpp => strtoimax.c} (95%) rename libc/inttypes/{strtoumax.cpp => strtoumax.c} (95%) rename libc/inttypes/{wcstoimax.cpp => wcstoimax.c} (95%) rename libc/inttypes/{wcstoumax.cpp => wcstoumax.c} (95%) rename libc/ioleast/{preadall.cpp => preadall.c} (91%) rename libc/ioleast/{preadleast.cpp => preadleast.c} (97%) rename libc/ioleast/{pwriteall.cpp => pwriteall.c} (91%) rename libc/ioleast/{pwriteleast.cpp => pwriteleast.c} (97%) rename libc/ioleast/{readall.cpp => readall.c} (92%) rename libc/ioleast/{readleast.cpp => readleast.c} (97%) rename libc/ioleast/{writeall.cpp => writeall.c} (92%) rename libc/ioleast/{writeleast.cpp => writeleast.c} (97%) rename libc/libgen/{basename.cpp => basename.c} (95%) rename libc/libgen/{dirname.cpp => dirname.c} (96%) rename libc/locale/{localeconv.cpp => localeconv.c} (96%) rename libc/locale/{setlocale.cpp => setlocale.c} (95%) rename libc/malloc/{__heap_expand_current_part.cpp => __heap_expand_current_part.c} (81%) create mode 100644 libc/malloc/__heap_lock.c delete mode 100644 libc/malloc/__heap_lock.cpp create mode 100644 libc/malloc/__heap_unlock.c delete mode 100644 libc/malloc/__heap_unlock.cpp rename libc/malloc/{__heap_verify.cpp => __heap_verify.c} (95%) rename libc/malloc/{heap_get_paranoia.cpp => heap_get_paranoia.c} (88%) create mode 100644 libc/malloc/heap_init.c delete mode 100644 libc/malloc/heap_init.cpp rename libc/msr/{rdmsr.cpp => rdmsr.c} (95%) rename libc/msr/{wrmsr.cpp => wrmsr.c} (94%) rename libc/netdb/{setnetent.cpp => endnetent.c} (95%) rename libc/netdb/{setprotoent.cpp => endprotoent.c} (95%) rename libc/netdb/{setservent.cpp => endservent.c} (95%) rename libc/netdb/{freeaddrinfo.cpp => freeaddrinfo.c} (93%) rename libc/netdb/{gai_strerror.cpp => gai_strerror.c} (95%) rename libc/netdb/{getaddrinfo.cpp => getaddrinfo.c} (92%) rename libc/netdb/{getnameinfo.cpp => getnameinfo.c} (75%) rename libc/netdb/{getnetbyaddr.cpp => getnetbyaddr.c} (91%) rename libc/netdb/{getnetbyname.cpp => getnetbyname.c} (92%) rename libc/netdb/{endnetent.cpp => getnetent.c} (95%) rename libc/netdb/{getprotobynumber.cpp => getprotobyname.c} (92%) rename libc/netdb/{getprotobyname.cpp => getprotobynumber.c} (92%) rename libc/netdb/{endprotoent.cpp => getprotoent.c} (94%) rename libc/netdb/{getservbyport.cpp => getservbyname.c} (90%) rename libc/netdb/{getservbyname.cpp => getservbyport.c} (90%) rename libc/netdb/{endservent.cpp => getservent.c} (95%) rename libc/netdb/{getnetent.cpp => setnetent.c} (94%) rename libc/netdb/{getprotoent.cpp => setprotoent.c} (93%) rename libc/netdb/{getservent.cpp => setservent.c} (94%) rename libc/netinet/in/{in6addr_any.cpp => in6addr_any.c} (91%) rename libc/netinet/in/{in6addr_loopback.cpp => in6addr_loopback.c} (90%) rename libc/poll/{poll.cpp => poll.c} (93%) rename libc/poll/{ppoll.cpp => ppoll.c} (88%) rename libc/psctl/{psctl.cpp => psctl.c} (94%) rename libc/pwd/{bcrypt_newhash.cpp => bcrypt_newhash.c} (99%) rename libc/pwd/{endpwent.cpp => endpwent.c} (95%) rename libc/pwd/{fgetpwent.cpp => fgetpwent.c} (92%) rename libc/pwd/{fgetpwent_r.cpp => fgetpwent_r.c} (97%) rename libc/pwd/{getpwent.cpp => getpwent.c} (94%) rename libc/pwd/{getpwent_r.cpp => getpwent_r.c} (97%) rename libc/pwd/{getpwnam.cpp => getpwnam.c} (91%) rename libc/pwd/{getpwnam_r.cpp => getpwnam_r.c} (98%) rename libc/pwd/{getpwuid.cpp => getpwuid.c} (92%) rename libc/pwd/{getpwuid_r.cpp => getpwuid_r.c} (98%) rename libc/pwd/{openpw.cpp => openpw.c} (95%) rename libc/pwd/{setpwent.cpp => setpwent.c} (92%) rename libc/regex/{regcomp.cpp => regcomp.c} (99%) rename libc/regex/{regerror.cpp => regerror.c} (98%) rename libc/regex/{regexec.cpp => regexec.c} (98%) rename libc/regex/{regfree.cpp => regfree.c} (97%) rename libc/sched/{sched_yield.cpp => sched_yield.c} (95%) rename libc/scram/{scram.cpp => scram.c} (94%) rename libc/signal/{kill.cpp => kill.c} (94%) rename libc/signal/{killpg.cpp => killpg.c} (93%) rename libc/signal/{psiginfo.cpp => psiginfo.c} (92%) rename libc/signal/{psignal.cpp => psignal.c} (93%) rename libc/signal/{raise.cpp => raise.c} (95%) rename libc/signal/{sigaction.cpp => sigaction.c} (97%) rename libc/signal/{sigaddset.cpp => sigaddset.c} (94%) rename libc/signal/{sigaltstack.cpp => sigaltstack.c} (91%) rename libc/signal/{sigandset.cpp => sigandset.c} (97%) rename libc/signal/{sigdelset.cpp => sigdelset.c} (94%) rename libc/signal/{sigemptyset.cpp => sigemptyset.c} (94%) rename libc/signal/{sigfillset.cpp => sigfillset.c} (94%) rename libc/signal/{sigisemptyset.cpp => sigisemptyset.c} (93%) rename libc/signal/{sigismember.cpp => sigismember.c} (93%) rename libc/signal/{signal.cpp => signal.c} (95%) rename libc/signal/{signotset.cpp => signotset.c} (97%) rename libc/signal/{sigorset.cpp => sigorset.c} (97%) rename libc/signal/{sigpending.cpp => sigpending.c} (94%) rename libc/signal/{sigprocmask.cpp => sigprocmask.c} (92%) rename libc/signal/{sigsuspend.cpp => sigsuspend.c} (94%) rename libc/ssp/{__stack_chk_fail.cpp => __stack_chk_fail.c} (78%) rename libc/stdio/{asprintf.cpp => asprintf.c} (97%) rename libc/stdio/{cbprintf.cpp => cbprintf.c} (97%) rename libc/stdio/{clearerr.cpp => clearerr.c} (94%) rename libc/stdio/{clearerr_unlocked.cpp => clearerr_unlocked.c} (93%) rename libc/stdio/{dprintf.cpp => dprintf.c} (93%) rename libc/stdio/{fclose.cpp => fclose.c} (95%) rename libc/stdio/{fdeletefile.cpp => fdeletefile.c} (94%) rename libc/stdio/{fdio_close.cpp => fdio_close.c} (96%) rename libc/stdio/{fdio_install_fd.cpp => fdio_install_fd.c} (94%) rename libc/stdio/{fdio_install_path.cpp => fdio_install_path.c} (93%) rename libc/stdio/{fdio_read.cpp => fdio_read.c} (97%) rename libc/stdio/{fdio_seek.cpp => fdio_seek.c} (97%) rename libc/stdio/{fdio_write.cpp => fdio_write.c} (97%) rename libc/stdio/{fdopen.cpp => fdopen.c} (94%) rename libc/stdio/{feof.cpp => feof.c} (95%) rename libc/stdio/{feof_unlocked.cpp => feof_unlocked.c} (94%) rename libc/stdio/{ferror.cpp => ferror.c} (95%) rename libc/stdio/{ferror_unlocked.cpp => ferror_unlocked.c} (93%) rename libc/stdio/{fflush.cpp => fflush.c} (92%) rename libc/stdio/{fflush_stop_reading.cpp => fflush_stop_reading.c} (93%) rename libc/stdio/{fflush_stop_reading_unlocked.cpp => fflush_stop_reading_unlocked.c} (95%) rename libc/stdio/{fflush_stop_writing.cpp => fflush_stop_writing.c} (93%) rename libc/stdio/{fflush_stop_writing_unlocked.cpp => fflush_stop_writing_unlocked.c} (95%) rename libc/stdio/{fflush_unlocked.cpp => fflush_unlocked.c} (94%) rename libc/stdio/{fgetc.cpp => fgetc.c} (95%) rename libc/stdio/{fgetc_unlocked.cpp => fgetc_unlocked.c} (97%) rename libc/stdio/{fgetpos.cpp => fgetpos.c} (92%) rename libc/stdio/{fgets.cpp => fgets.c} (92%) rename libc/stdio/{fgets_unlocked.cpp => fgets_unlocked.c} (97%) rename libc/stdio/{fileno.cpp => fileno.c} (95%) rename libc/stdio/{fileno_unlocked.cpp => fileno_unlocked.c} (93%) rename libc/stdio/{flockfile.cpp => flockfile.c} (94%) rename libc/stdio/{fmemopen.cpp => fmemopen.c} (99%) rename libc/stdio/{fnewfile.cpp => fnewfile.c} (92%) rename libc/stdio/{fopen.cpp => fopen.c} (93%) rename libc/stdio/{fparsemode.cpp => fparsemode.c} (96%) rename libc/stdio/{fpipe.cpp => fpipe.c} (95%) rename libc/stdio/{fprintf.cpp => fprintf.c} (93%) rename libc/stdio/{fprintf_unlocked.cpp => fprintf_unlocked.c} (91%) rename libc/stdio/{fputc.cpp => fputc.c} (95%) rename libc/stdio/{fputc_unlocked.cpp => fputc_unlocked.c} (96%) rename libc/stdio/{fputs.cpp => fputs.c} (94%) rename libc/stdio/{fputs_unlocked.cpp => fputs_unlocked.c} (93%) rename libc/stdio/{fread.cpp => fread.c} (92%) rename libc/stdio/{fread_unlocked.cpp => fread_unlocked.c} (98%) rename libc/stdio/{fregister.cpp => fregister.c} (95%) rename libc/stdio/{freopen.cpp => freopen.c} (93%) rename libc/stdio/{fresetfile.cpp => fresetfile.c} (93%) rename libc/stdio/{fscanf.cpp => fscanf.c} (93%) rename libc/stdio/{fscanf_unlocked.cpp => fscanf_unlocked.c} (92%) rename libc/stdio/{fseek.cpp => fseek.c} (93%) rename libc/stdio/{fseeko.cpp => fseeko.c} (93%) rename libc/stdio/{fseeko_unlocked.cpp => fseeko_unlocked.c} (92%) rename libc/stdio/{fsetpos.cpp => fsetpos.c} (92%) rename libc/stdio/{fshutdown.cpp => fshutdown.c} (96%) rename libc/stdio/{ftell.cpp => ftell.c} (95%) rename libc/stdio/{ftello.cpp => ftello.c} (95%) rename libc/stdio/{ftello_unlocked.cpp => ftello_unlocked.c} (95%) rename libc/stdio/{ftrylockfile.cpp => ftrylockfile.c} (94%) rename libc/stdio/{funlockfile.cpp => funlockfile.c} (94%) rename libc/stdio/{funregister.cpp => funregister.c} (95%) rename libc/stdio/{fwrite.cpp => fwrite.c} (91%) rename libc/stdio/{fwrite_unlocked.cpp => fwrite_unlocked.c} (98%) rename libc/stdio/{getc.cpp => getc.c} (95%) rename libc/stdio/{getc_unlocked.cpp => getc_unlocked.c} (94%) rename libc/stdio/{getchar.cpp => getchar.c} (95%) rename libc/stdio/{getchar_unlocked.cpp => getchar_unlocked.c} (93%) rename libc/stdio/{getdelim.cpp => getdelim.c} (95%) rename libc/stdio/{getline.cpp => getline.c} (92%) rename libc/stdio/{open_memstream.cpp => open_memstream.c} (97%) rename libc/stdio/{perror.cpp => perror.c} (95%) rename libc/stdio/{popen.cpp => popen.c} (94%) rename libc/stdio/{printf.cpp => printf.c} (93%) rename libc/stdio/{putc.cpp => putc.c} (95%) rename libc/stdio/{putc_unlocked.cpp => putc_unlocked.c} (93%) rename libc/stdio/{putchar.cpp => putchar.c} (95%) rename libc/stdio/{putchar_unlocked.cpp => putchar_unlocked.c} (93%) rename libc/stdio/{puts.cpp => puts.c} (95%) rename libc/stdio/{remove.cpp => remove.c} (94%) rename libc/stdio/{removeat.cpp => removeat.c} (93%) rename libc/stdio/{rename.cpp => rename.c} (92%) rename libc/stdio/{renameat.cpp => renameat.c} (89%) rename libc/stdio/{rewind.cpp => rewind.c} (95%) rename libc/stdio/{scanf.cpp => scanf.c} (94%) rename libc/stdio/{setbuf.cpp => setbuf.c} (95%) rename libc/stdio/{setvbuf.cpp => setvbuf.c} (92%) rename libc/stdio/{setvbuf_unlocked.cpp => setvbuf_unlocked.c} (91%) rename libc/stdio/{snprintf.cpp => snprintf.c} (97%) rename libc/stdio/{sprintf.cpp => sprintf.c} (92%) rename libc/stdio/{sscanf.cpp => sscanf.c} (93%) rename libc/stdio/{stderr.cpp => stderr.c} (91%) rename libc/stdio/{stdin.cpp => stdin.c} (92%) rename libc/stdio/{stdout.cpp => stdout.c} (91%) rename libc/stdio/{tmpfile.cpp => tmpfile.c} (96%) rename libc/stdio/{ungetc.cpp => ungetc.c} (95%) rename libc/stdio/{ungetc_unlocked.cpp => ungetc_unlocked.c} (96%) rename libc/stdio/{vasprintf.cpp => vasprintf.c} (98%) rename libc/stdio/{vcbprintf.cpp => vcbprintf.c} (98%) rename libc/stdio/{vdprintf.cpp => vdprintf.c} (93%) rename libc/stdio/{vfprintf.cpp => vfprintf.c} (92%) rename libc/stdio/{vfprintf_unlocked.cpp => vfprintf_unlocked.c} (97%) rename libc/stdio/{vfscanf.cpp => vfscanf.c} (92%) rename libc/stdio/{vfscanf_unlocked.cpp => vfscanf_unlocked.c} (92%) rename libc/stdio/{vprintf.cpp => vprintf.c} (92%) rename libc/stdio/{vscanf.cpp => vscanf.c} (93%) rename libc/stdio/{vscanf_callback.cpp => vscanf_callback.c} (96%) rename libc/stdio/{vsnprintf.cpp => vsnprintf.c} (98%) rename libc/stdio/{vsprintf.cpp => vsprintf.c} (97%) rename libc/stdio/{vsscanf.cpp => vsscanf.c} (94%) rename libc/stdio_ext/{__fbufsize.cpp => __fbufsize.c} (94%) rename libc/stdio_ext/{__fpending.cpp => __fpending.c} (94%) rename libc/stdio_ext/{__fpurge.cpp => __fpurge.c} (95%) rename libc/stdio_ext/{__freadable.cpp => __freadable.c} (94%) rename libc/stdio_ext/{__freading.cpp => __freading.c} (95%) rename libc/stdio_ext/{__fseterr.cpp => __fseterr.c} (94%) rename libc/stdio_ext/{__fwritable.cpp => __fwritable.c} (94%) rename libc/stdio_ext/{__fwriting.cpp => __fwriting.c} (95%) rename libc/stdlib/{_Exit.cpp => _Exit.c} (95%) rename libc/stdlib/{abort.cpp => abort.c} (82%) rename libc/stdlib/{abs.cpp => abs.c} (95%) rename libc/stdlib/{arc4random.cpp => arc4random.c} (94%) rename libc/stdlib/{arc4random_buf.cpp => arc4random_buf.c} (92%) rename libc/stdlib/{arc4random_uniform.cpp => arc4random_uniform.c} (96%) rename libc/stdlib/{atexit.cpp => atexit.c} (90%) rename libc/stdlib/{atof.cpp => atof.c} (92%) rename libc/stdlib/{atoi.cpp => atoi.c} (95%) rename libc/stdlib/{atol.cpp => atol.c} (94%) rename libc/stdlib/{atoll.cpp => atoll.c} (94%) rename libc/stdlib/{bsearch.cpp => bsearch.c} (88%) rename libc/stdlib/{calloc.cpp => calloc.c} (94%) rename libc/stdlib/{canonicalize_file_name.cpp => canonicalize_file_name.c} (91%) rename libc/stdlib/{canonicalize_file_name_at.cpp => canonicalize_file_name_at.c} (98%) rename libc/stdlib/{clearenv.cpp => clearenv.c} (96%) rename libc/stdlib/{div.cpp => div.c} (94%) rename libc/stdlib/{exit.cpp => exit.c} (81%) rename libc/stdlib/{free.cpp => free.c} (77%) rename libc/stdlib/{getenv.cpp => getenv.c} (96%) rename libc/stdlib/{labs.cpp => labs.c} (94%) rename libc/stdlib/{ldiv.cpp => ldiv.c} (94%) rename libc/stdlib/{llabs.cpp => llabs.c} (93%) rename libc/stdlib/{lldiv.cpp => lldiv.c} (93%) rename libc/stdlib/{malloc.cpp => malloc.c} (84%) rename libc/stdlib/{mblen.cpp => mblen.c} (95%) rename libc/stdlib/{mbstowcs.cpp => mbstowcs.c} (97%) rename libc/stdlib/{mbtowc.cpp => mbtowc.c} (94%) rename libc/stdlib/{mkdtemp.cpp => mkdtemp.c} (94%) rename libc/stdlib/{mkdtemps.cpp => mkdtemps.c} (91%) rename libc/stdlib/{mkostemp.cpp => mkostemp.c} (93%) rename libc/stdlib/{mkostemps.cpp => mkostemps.c} (91%) rename libc/stdlib/{mkstemp.cpp => mkstemp.c} (94%) rename libc/stdlib/{mkstemps.cpp => mkstemps.c} (93%) rename libc/stdlib/{on_exit.cpp => on_exit.c} (93%) rename libc/stdlib/{qsort.cpp => qsort.c} (97%) rename libc/stdlib/{qsort_r.cpp => qsort_r.c} (98%) rename libc/stdlib/{rand.cpp => rand.c} (93%) rename libc/stdlib/{realloc.cpp => realloc.c} (88%) rename libc/stdlib/{reallocarray.cpp => reallocarray.c} (92%) rename libc/stdlib/{realpath.cpp => realpath.c} (97%) rename libc/stdlib/{setenv.cpp => setenv.c} (97%) rename libc/stdlib/{strtod.cpp => strtod.c} (96%) rename libc/stdlib/{strtof.cpp => strtof.c} (97%) rename libc/stdlib/{strtol.cpp => strtol.c} (65%) rename libc/stdlib/{strtold.cpp => strtold.c} (96%) rename libc/stdlib/{strtoll.cpp => strtoll.c} (96%) rename libc/stdlib/{strtoul.cpp => strtoul.c} (96%) rename libc/stdlib/{strtoull.cpp => strtoull.c} (96%) rename libc/stdlib/{system.cpp => system.c} (95%) rename libc/stdlib/{unsetenv.cpp => unsetenv.c} (96%) rename libc/stdlib/{wcstombs.cpp => wcstombs.c} (93%) rename libc/stdlib/{wctomb.cpp => wctomb.c} (95%) rename libc/string/{explicit_bzero.cpp => explicit_bzero.c} (93%) rename libc/string/{ffs.cpp => ffs.c} (95%) rename libc/string/{ffsl.cpp => ffsl.c} (95%) rename libc/string/{ffsll.cpp => ffsll.c} (94%) rename libc/string/{memccpy.cpp => memccpy.c} (92%) rename libc/string/{memchr.cpp => memchr.c} (93%) rename libc/string/{memcmp.cpp => memcmp.c} (93%) rename libc/string/{memcpy.cpp => memcpy.c} (84%) rename libc/string/{memmove.cpp => memmove.c} (93%) rename libc/string/{memrchr.cpp => memrchr.c} (93%) rename libc/string/{memset.cpp => memset.c} (96%) rename libc/string/{stpcpy.cpp => stpcpy.c} (93%) rename libc/string/{stpncpy.cpp => stpncpy.c} (93%) rename libc/string/{strcasecmp.cpp => strcasecmp.c} (93%) rename libc/string/{strcat.cpp => strcat.c} (93%) rename libc/string/{strchr.cpp => strchr.c} (94%) rename libc/string/{strchrnul.cpp => strchrnul.c} (93%) rename libc/string/{strcmp.cpp => strcmp.c} (93%) rename libc/string/{strcoll.cpp => strcoll.c} (93%) rename libc/string/{strcoll_l.cpp => strcoll_l.c} (91%) rename libc/string/{strcpy.cpp => strcpy.c} (93%) rename libc/string/{strcspn.cpp => strcspn.c} (93%) rename libc/string/{strdup.cpp => strdup.c} (94%) rename libc/string/{strerror.cpp => strerror.c} (97%) rename libc/string/{strerror_l.cpp => strerror_l.c} (87%) rename libc/string/{strerror_r.cpp => strerror_r.c} (92%) rename libc/string/{stresep.cpp => stresep.c} (94%) rename libc/string/{strlcat.cpp => strlcat.c} (97%) rename libc/string/{strlcpy.cpp => strlcpy.c} (97%) rename libc/string/{strlen.cpp => strlen.c} (94%) rename libc/string/{strncasecmp.cpp => strncasecmp.c} (93%) rename libc/string/{strncat.cpp => strncat.c} (93%) rename libc/string/{strncmp.cpp => strncmp.c} (93%) rename libc/string/{strncpy.cpp => strncpy.c} (93%) rename libc/string/{strndup.cpp => strndup.c} (94%) rename libc/string/{strnlen.cpp => strnlen.c} (93%) rename libc/string/{strpbrk.cpp => strpbrk.c} (93%) rename libc/string/{strrchr.cpp => strrchr.c} (94%) rename libc/string/{strsep.cpp => strsep.c} (93%) rename libc/string/{strsignal.cpp => strsignal.c} (95%) rename libc/string/{strspn.cpp => strspn.c} (93%) rename libc/string/{strstr.cpp => strstr.c} (93%) rename libc/string/{strtok.cpp => strtok.c} (93%) rename libc/string/{strtok_r.cpp => strtok_r.c} (93%) rename libc/string/{strverscmp.cpp => strverscmp.c} (97%) rename libc/string/{strxfrm.cpp => strxfrm.c} (92%) rename libc/string/{strxfrm_l.cpp => strxfrm_l.c} (95%) rename libc/string/{timingsafe_memcmp.cpp => timingsafe_memcmp.c} (99%) rename libc/sys/display/{dispmsg_issue.cpp => dispmsg_issue.c} (93%) rename libc/sys/ioctl/{ioctl.cpp => ioctl.c} (95%) rename libc/sys/kernelinfo/{kernelinfo.cpp => kernelinfo.c} (91%) rename libc/sys/mman/{mmap.cpp => mmap.c} (98%) rename libc/sys/mman/{mprotect.cpp => mprotect.c} (92%) rename libc/sys/mman/{munmap.cpp => munmap.c} (94%) rename libc/sys/mount/{unmount.cpp => unmount.c} (93%) rename libc/sys/mount/{unmountat.cpp => unmountat.c} (92%) rename libc/sys/readdirents/{readdirents.cpp => readdirents.c} (91%) rename libc/sys/resource/{getpriority.cpp => getpriority.c} (93%) rename libc/sys/resource/{getrlimit.cpp => getrlimit.c} (92%) rename libc/sys/resource/{getrusage.cpp => getrusage.c} (95%) rename libc/sys/resource/{prlimit.cpp => prlimit.c} (97%) rename libc/sys/resource/{setpriority.cpp => setpriority.c} (92%) rename libc/sys/resource/{setrlimit.cpp => setrlimit.c} (92%) rename libc/sys/select/{select.cpp => select.c} (98%) rename libc/sys/socket/{accept.cpp => accept.c} (88%) rename libc/sys/socket/{accept4.cpp => accept4.c} (91%) rename libc/sys/socket/{bind.cpp => bind.c} (92%) rename libc/sys/socket/{connect.cpp => connect.c} (91%) rename libc/sys/socket/{getpeername.cpp => getpeername.c} (96%) rename libc/sys/socket/{getsockname.cpp => getsockname.c} (96%) rename libc/sys/socket/{getsockopt.cpp => getsockopt.c} (97%) rename libc/sys/socket/{listen.cpp => listen.c} (94%) rename libc/sys/socket/{recv.cpp => recv.c} (92%) rename libc/sys/socket/{recvfrom.cpp => recvfrom.c} (97%) rename libc/sys/socket/{recvmsg.cpp => recvmsg.c} (92%) rename libc/sys/socket/{send.cpp => send.c} (92%) rename libc/sys/socket/{sendmsg.cpp => sendmsg.c} (92%) rename libc/sys/socket/{sendto.cpp => sendto.c} (97%) rename libc/sys/socket/{setsockopt.cpp => setsockopt.c} (96%) rename libc/sys/socket/{shutdown.cpp => shutdown.c} (94%) rename libc/sys/socket/{sockatmark.cpp => sockatmark.c} (94%) rename libc/sys/socket/{socket.cpp => socket.c} (96%) rename libc/sys/socket/{socketpair.cpp => socketpair.c} (97%) rename libc/sys/stat/{chmod.cpp => chmod.c} (93%) rename libc/sys/stat/{fchmod.cpp => fchmod.c} (94%) rename libc/sys/stat/{fchmodat.cpp => fchmodat.c} (92%) rename libc/sys/stat/{fstat.cpp => fstat.c} (94%) rename libc/sys/stat/{fstatat.cpp => fstatat.c} (91%) rename libc/sys/stat/{futimens.cpp => futimens.c} (92%) rename libc/sys/stat/{getumask.cpp => getumask.c} (95%) rename libc/sys/stat/{lstat.cpp => lstat.c} (93%) rename libc/sys/stat/{mkdir.cpp => mkdir.c} (93%) rename libc/sys/stat/{mkdirat.cpp => mkdirat.c} (92%) rename libc/sys/stat/{stat.cpp => stat.c} (93%) rename libc/sys/stat/{umask.cpp => umask.c} (94%) rename libc/sys/stat/{utimens.cpp => utimens.c} (97%) rename libc/sys/stat/{utimensat.cpp => utimensat.c} (97%) rename libc/sys/statvfs/{fstatvfs.cpp => fstatvfs.c} (93%) rename libc/sys/statvfs/{fstatvfsat.cpp => fstatvfsat.c} (96%) rename libc/sys/statvfs/{statvfs.cpp => statvfs.c} (96%) rename libc/sys/termmode/{gettermmode.cpp => gettermmode.c} (93%) rename libc/sys/termmode/{settermmode.cpp => settermmode.c} (93%) rename libc/sys/time/{gettimeofday.cpp => gettimeofday.c} (92%) rename libc/sys/times/{times.cpp => times.c} (97%) rename libc/sys/uio/{preadv.cpp => preadv.c} (97%) rename libc/sys/uio/{pwritev.cpp => pwritev.c} (97%) rename libc/sys/uio/{readv.cpp => readv.c} (92%) rename libc/sys/uio/{writev.cpp => writev.c} (92%) rename libc/sys/utsname/{uname.cpp => uname.c} (97%) rename libc/sys/wait/{wait.cpp => wait.c} (94%) rename libc/sys/wait/{waitpid.cpp => waitpid.c} (93%) rename libc/syslog/{closelog.cpp => closelog.c} (95%) rename libc/syslog/{connectlog.cpp => connectlog.c} (94%) rename libc/syslog/{openlog.cpp => openlog.c} (94%) rename libc/syslog/{setlogmask.cpp => setlogmask.c} (94%) rename libc/syslog/{syslog.cpp => syslog.c} (93%) rename libc/syslog/{vsyslog.cpp => vsyslog.c} (88%) rename libc/termios/{cfgetispeed.cpp => cfgetispeed.c} (92%) rename libc/termios/{cfgetospeed.cpp => cfgetospeed.c} (92%) rename libc/termios/{cfsetispeed.cpp => cfsetispeed.c} (92%) rename libc/termios/{cfsetospeed.cpp => cfsetospeed.c} (92%) rename libc/termios/{tcdrain.cpp => tcdrain.c} (95%) rename libc/termios/{tcflow.cpp => tcflow.c} (94%) rename libc/termios/{tcflush.cpp => tcflush.c} (94%) rename libc/termios/{tcgetattr.cpp => tcgetattr.c} (93%) rename libc/termios/{tcgetblob.cpp => tcgetblob.c} (91%) rename libc/termios/{tcgetsid.cpp => tcgetsid.c} (95%) rename libc/termios/{tcgetwincurpos.cpp => tcgetwincurpos.c} (92%) rename libc/termios/{tcgetwinsize.cpp => tcgetwinsize.c} (93%) rename libc/termios/{tcsendbreak.cpp => tcsendbreak.c} (93%) rename libc/termios/{tcsetattr.cpp => tcsetattr.c} (92%) rename libc/termios/{tcsetblob.cpp => tcsetblob.c} (91%) rename libc/time/{asctime.cpp => asctime.c} (95%) rename libc/time/{asctime_r.cpp => asctime_r.c} (95%) rename libc/time/{clock.cpp => clock.c} (96%) rename libc/time/{clock_getres.cpp => clock_getres.c} (91%) rename libc/time/{clock_gettime.cpp => clock_gettime.c} (91%) rename libc/time/{clock_gettimeres.cpp => clock_gettimeres.c} (87%) rename libc/time/{clock_nanosleep.cpp => clock_nanosleep.c} (97%) rename libc/time/{clock_settime.cpp => clock_settime.c} (90%) rename libc/time/{clock_settimeres.cpp => clock_settimeres.c} (86%) rename libc/time/{ctime.cpp => ctime.c} (94%) rename libc/time/{ctime_r.cpp => ctime_r.c} (93%) rename libc/time/{difftime.cpp => difftime.c} (93%) rename libc/time/{gmtime.cpp => gmtime.c} (94%) rename libc/time/{gmtime_r.cpp => gmtime_r.c} (98%) rename libc/time/{localtime.cpp => localtime.c} (93%) rename libc/time/{localtime_r.cpp => localtime_r.c} (92%) rename libc/time/{mktime.cpp => mktime.c} (94%) rename libc/time/{nanosleep.cpp => nanosleep.c} (92%) rename libc/time/{strftime.cpp => strftime.c} (99%) rename libc/time/{strftime_l.cpp => strftime_l.c} (91%) rename libc/time/{time.cpp => time.c} (95%) rename libc/time/{timegm.cpp => timegm.c} (91%) rename libc/time/{timens.cpp => timens.c} (94%) rename libc/time/{timer_create.cpp => timer_create.c} (88%) rename libc/time/{timer_delete.cpp => timer_delete.c} (94%) rename libc/time/{timer_getoverrun.cpp => timer_getoverrun.c} (93%) rename libc/time/{timer_gettime.cpp => timer_gettime.c} (92%) rename libc/time/{timer_settime.cpp => timer_settime.c} (84%) rename libc/time/{tzset.cpp => tzset.c} (90%) rename libc/timespec/{timespec.cpp => timespec.c} (87%) rename libc/ubsan/{ubsan.cpp => ubsan.c} (94%) rename libc/unistd/{_exit.cpp => _exit.c} (95%) rename libc/unistd/{access.cpp => access.c} (93%) rename libc/unistd/{alarm.cpp => alarm.c} (94%) rename libc/unistd/{alarmns.cpp => alarmns.c} (92%) rename libc/unistd/{chdir.cpp => chdir.c} (94%) rename libc/unistd/{chown.cpp => chown.c} (92%) rename libc/unistd/{chroot.cpp => chroot.c} (94%) rename libc/unistd/{close.cpp => close.c} (95%) rename libc/unistd/{closefrom.cpp => closefrom.c} (95%) rename libc/unistd/{confstr.cpp => confstr.c} (93%) rename libc/unistd/{crypt_newhash.cpp => crypt_newhash.c} (99%) rename libc/unistd/{dup.cpp => dup.c} (96%) rename libc/unistd/{dup2.cpp => dup2.c} (94%) rename libc/unistd/{dup3.cpp => dup3.c} (93%) rename libc/unistd/{environ.cpp => environ.c} (83%) rename libc/unistd/{execl.cpp => execl.c} (94%) rename libc/unistd/{execle.cpp => execle.c} (95%) rename libc/unistd/{execlp.cpp => execlp.c} (94%) rename libc/unistd/{execlpe.cpp => execlpe.c} (94%) rename libc/unistd/{execv.cpp => execv.c} (92%) rename libc/unistd/{execve.cpp => execve.c} (90%) rename libc/unistd/{execvp.cpp => execvp.c} (92%) rename libc/unistd/{execvpe.cpp => execvpe.c} (98%) rename libc/unistd/{exit_thread.cpp => exit_thread.c} (96%) rename libc/unistd/{faccessat.cpp => faccessat.c} (92%) rename libc/unistd/{fchdir.cpp => fchdir.c} (95%) rename libc/unistd/{fchdirat.cpp => fchdirat.c} (93%) rename libc/unistd/{fchown.cpp => fchown.c} (93%) rename libc/unistd/{fchownat.cpp => fchownat.c} (91%) rename libc/unistd/{fchroot.cpp => fchroot.c} (95%) rename libc/unistd/{fchrootat.cpp => fchrootat.c} (93%) rename libc/unistd/{fork.cpp => fork.c} (96%) rename libc/unistd/{fpathconf.cpp => fpathconf.c} (94%) rename libc/unistd/{fsync.cpp => fsync.c} (95%) rename libc/unistd/{ftruncate.cpp => ftruncate.c} (94%) rename libc/unistd/{get_current_dir_name.cpp => get_current_dir_name.c} (95%) rename libc/unistd/{getcwd.cpp => getcwd.c} (94%) rename libc/unistd/{getdomainname.cpp => getdomainname.c} (94%) rename libc/unistd/{getegid.cpp => getegid.c} (95%) rename libc/unistd/{getentropy.cpp => getentropy.c} (93%) rename libc/unistd/{geteuid.cpp => geteuid.c} (95%) rename libc/unistd/{getgid.cpp => getgid.c} (95%) rename libc/unistd/{gethostname.cpp => gethostname.c} (93%) rename libc/unistd/{getlogin.cpp => getlogin.c} (96%) rename libc/unistd/{getlogin_r.cpp => getlogin_r.c} (96%) rename libc/unistd/{getpagesize.cpp => getpagesize.c} (94%) rename libc/unistd/{getpgid.cpp => getpgid.c} (95%) rename libc/unistd/{getpid.cpp => getpid.c} (95%) rename libc/unistd/{getppid.cpp => getppid.c} (95%) rename libc/unistd/{getuid.cpp => getuid.c} (95%) rename libc/unistd/{isatty.cpp => isatty.c} (95%) rename libc/unistd/{lchown.cpp => lchown.c} (92%) rename libc/unistd/{link.cpp => link.c} (93%) rename libc/unistd/{linkat.cpp => linkat.c} (87%) rename libc/unistd/{lseek.cpp => lseek.c} (93%) rename libc/unistd/{memstat.cpp => memstat.c} (93%) rename libc/unistd/{mkpartition.cpp => mkpartition.c} (93%) rename libc/unistd/{pathconf.cpp => pathconf.c} (94%) rename libc/unistd/{pipe.cpp => pipe.c} (95%) rename libc/unistd/{pipe2.cpp => pipe2.c} (94%) rename libc/unistd/{pread.cpp => pread.c} (92%) rename libc/unistd/{pwrite.cpp => pwrite.c} (92%) rename libc/unistd/{read.cpp => read.c} (93%) rename libc/unistd/{readlink.cpp => readlink.c} (88%) rename libc/unistd/{readlinkat.cpp => readlinkat.c} (88%) rename libc/unistd/{rmdir.cpp => rmdir.c} (94%) rename libc/unistd/{setegid.cpp => setegid.c} (95%) rename libc/unistd/{seteuid.cpp => seteuid.c} (95%) rename libc/unistd/{setgid.cpp => setgid.c} (95%) rename libc/unistd/{sethostname.cpp => sethostname.c} (92%) rename libc/unistd/{setpgid.cpp => setpgid.c} (94%) rename libc/unistd/{setuid.cpp => setuid.c} (95%) rename libc/unistd/{sfork.cpp => sfork.c} (92%) rename libc/unistd/{sleep.cpp => sleep.c} (95%) rename libc/unistd/{symlink.cpp => symlink.c} (92%) rename libc/unistd/{symlinkat.cpp => symlinkat.c} (91%) rename libc/unistd/{sysconf.cpp => sysconf.c} (96%) rename libc/unistd/{tcgetpgrp.cpp => tcgetpgrp.c} (95%) rename libc/unistd/{tcsetpgrp.cpp => tcsetpgrp.c} (94%) rename libc/unistd/{tfork.cpp => tfork.c} (94%) rename libc/unistd/{truncate.cpp => truncate.c} (93%) rename libc/unistd/{truncateat.cpp => truncateat.c} (92%) rename libc/unistd/{ttyname.cpp => ttyname.c} (96%) rename libc/unistd/{ttyname_r.cpp => ttyname_r.c} (93%) rename libc/unistd/{unlink.cpp => unlink.c} (94%) rename libc/unistd/{unlinkat.cpp => unlinkat.c} (92%) rename libc/unistd/{usleep.cpp => usleep.c} (95%) rename libc/unistd/{write.cpp => write.c} (93%) rename libc/utime/{utime.cpp => utime.c} (94%) rename libc/wchar/{btowc.cpp => btowc.c} (96%) rename libc/wchar/{mbrlen.cpp => mbrlen.c} (97%) rename libc/wchar/{mbrtowc.cpp => mbrtowc.c} (99%) rename libc/wchar/{mbsinit.cpp => mbsinit.c} (94%) rename libc/wchar/{mbsnrtowcs.cpp => mbsnrtowcs.c} (98%) rename libc/wchar/{mbsrtowcs.cpp => mbsrtowcs.c} (97%) rename libc/wchar/{wcpcpy.cpp => wcpcpy.c} (91%) rename libc/wchar/{wcpncpy.cpp => wcpncpy.c} (97%) rename libc/wchar/{wcrtomb.cpp => wcrtomb.c} (98%) rename libc/wchar/{wcscasecmp.cpp => wcscasecmp.c} (96%) rename libc/wchar/{wcscat.cpp => wcscat.c} (92%) rename libc/wchar/{wcschr.cpp => wcschr.c} (93%) rename libc/wchar/{wcschrnul.cpp => wcschrnul.c} (92%) rename libc/wchar/{wcscmp.cpp => wcscmp.c} (93%) rename libc/wchar/{wcscoll.cpp => wcscoll.c} (92%) rename libc/wchar/{wcscpy.cpp => wcscpy.c} (93%) rename libc/wchar/{wcscspn.cpp => wcscspn.c} (93%) rename libc/wchar/{wcsdup.cpp => wcsdup.c} (94%) rename libc/wchar/{wcsftime.cpp => wcsftime.c} (95%) rename libc/wchar/{wcslcat.cpp => wcslcat.c} (97%) rename libc/wchar/{wcslcpy.cpp => wcslcpy.c} (97%) rename libc/wchar/{wcslen.cpp => wcslen.c} (94%) rename libc/wchar/{wcsncasecmp.cpp => wcsncasecmp.c} (97%) rename libc/wchar/{wcsncat.cpp => wcsncat.c} (92%) rename libc/wchar/{wcsncmp.cpp => wcsncmp.c} (92%) rename libc/wchar/{wcsncpy.cpp => wcsncpy.c} (92%) rename libc/wchar/{wcsnlen.cpp => wcsnlen.c} (93%) rename libc/wchar/{wcsnrtombs.cpp => wcsnrtombs.c} (98%) rename libc/wchar/{wcspbrk.cpp => wcspbrk.c} (92%) rename libc/wchar/{wcsrchr.cpp => wcsrchr.c} (93%) rename libc/wchar/{wcsrtombs.cpp => wcsrtombs.c} (97%) rename libc/wchar/{wcsspn.cpp => wcsspn.c} (93%) rename libc/wchar/{wcsstr.cpp => wcsstr.c} (97%) rename libc/wchar/{wcstod.cpp => wcstod.c} (95%) rename libc/wchar/{wcstof.cpp => wcstof.c} (95%) rename libc/wchar/{wcstok.cpp => wcstok.c} (92%) rename libc/wchar/{wcstol.cpp => wcstol.c} (96%) rename libc/wchar/{wcstold.cpp => wcstold.c} (95%) rename libc/wchar/{wcstoll.cpp => wcstoll.c} (96%) rename libc/wchar/{wcstoul.cpp => wcstoul.c} (96%) rename libc/wchar/{wcstoull.cpp => wcstoull.c} (96%) rename libc/wchar/{wcswidth.cpp => wcswidth.c} (94%) rename libc/wchar/{wcsxfrm.cpp => wcsxfrm.c} (97%) rename libc/wchar/{wctob.cpp => wctob.c} (96%) rename libc/wchar/{wcwidth.cpp => wcwidth.c} (95%) rename libc/wchar/{wmemchr.cpp => wmemchr.c} (92%) rename libc/wchar/{wmemcmp.cpp => wmemcmp.c} (92%) rename libc/wchar/{wmemcpy.cpp => wmemcpy.c} (97%) rename libc/wchar/{wmemmove.cpp => wmemmove.c} (92%) rename libc/wchar/{wmemset.cpp => wmemset.c} (92%) rename libc/wctype/{iswalnum.cpp => iswalnum.c} (94%) rename libc/wctype/{iswalpha.cpp => iswalpha.c} (94%) rename libc/wctype/{iswblank.cpp => iswblank.c} (94%) rename libc/wctype/{iswcntrl.cpp => iswcntrl.c} (95%) rename libc/wctype/{iswctype.cpp => iswctype.c} (93%) rename libc/wctype/{iswdigit.cpp => iswdigit.c} (94%) rename libc/wctype/{iswgraph.cpp => iswgraph.c} (94%) rename libc/wctype/{iswlower.cpp => iswlower.c} (94%) rename libc/wctype/{iswprint.cpp => iswprint.c} (94%) rename libc/wctype/{iswpunct.cpp => iswpunct.c} (94%) rename libc/wctype/{iswspace.cpp => iswspace.c} (95%) rename libc/wctype/{iswupper.cpp => iswupper.c} (94%) rename libc/wctype/{iswxdigit.cpp => iswxdigit.c} (95%) rename libc/wctype/{towlower.cpp => towlower.c} (94%) rename libc/wctype/{towupper.cpp => towupper.c} (94%) rename libc/wctype/{wctype.cpp => wctype.c} (96%) 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 . - pwd/getpwuid.cpp + pwd/getpwuid.c Searchs the passwd database for a user with the given numeric user id in a thread-insecure manner. @@ -27,7 +27,7 @@ #include #include -extern "C" struct passwd* getpwuid(uid_t uid) +struct passwd* getpwuid(uid_t uid) { static struct passwd result_object; static char* buf = NULL; @@ -40,8 +40,9 @@ extern "C" struct passwd* getpwuid(uid_t uid) buflen = new_buflen; } struct passwd* result; + int errnum; retry: - int errnum = getpwuid_r(uid, &result_object, buf, buflen, &result); + errnum = getpwuid_r(uid, &result_object, buf, buflen, &result); if ( errnum == ERANGE ) { size_t new_buflen = 2 * buflen; diff --git a/libc/pwd/getpwuid_r.cpp b/libc/pwd/getpwuid_r.c similarity index 98% rename from libc/pwd/getpwuid_r.cpp rename to libc/pwd/getpwuid_r.c index 6cc558d8..79f24bd4 100644 --- a/libc/pwd/getpwuid_r.cpp +++ b/libc/pwd/getpwuid_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/getpwuid_r.cpp + pwd/getpwuid_r.c Searchs the passwd database for a user with the given numeric user id. *******************************************************************************/ @@ -26,7 +26,6 @@ #include #include -extern "C" int getpwuid_r(uid_t uid, struct passwd* restrict ret, char* restrict buf, diff --git a/libc/pwd/openpw.cpp b/libc/pwd/openpw.c similarity index 95% rename from libc/pwd/openpw.cpp rename to libc/pwd/openpw.c index 98f2f30d..bdea205a 100644 --- a/libc/pwd/openpw.cpp +++ b/libc/pwd/openpw.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/openpw.cpp + pwd/openpw.c Opens the passwd database and returns a FILE to it. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" FILE* openpw(void) +FILE* openpw(void) { return fopen("/etc/passwd", "r"); } diff --git a/libc/pwd/setpwent.cpp b/libc/pwd/setpwent.c similarity index 92% rename from libc/pwd/setpwent.cpp rename to libc/pwd/setpwent.c index a682a67d..539de383 100644 --- a/libc/pwd/setpwent.cpp +++ b/libc/pwd/setpwent.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/setpwent.cpp + pwd/setpwent.c Rewinds the passwd database. *******************************************************************************/ @@ -25,9 +25,9 @@ #include #include -extern "C" { FILE* __pwd_file = NULL; } +FILE* __pwd_file = NULL; -extern "C" void setpwent(void) +void setpwent(void) { if ( __pwd_file ) rewind(__pwd_file); diff --git a/libc/regex/regcomp.cpp b/libc/regex/regcomp.c similarity index 99% rename from libc/regex/regcomp.cpp rename to libc/regex/regcomp.c index 384d203a..94e957f5 100644 --- a/libc/regex/regcomp.cpp +++ b/libc/regex/regcomp.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 . - regex/regcomp.cpp + regex/regcomp.c Regular expression compiler. *******************************************************************************/ @@ -27,6 +27,7 @@ #include #include #include +#include #include #include #include @@ -684,7 +685,6 @@ static inline void re_control_flow(struct re* re, } } -extern "C" int regcomp(regex_t* restrict regex, const char* restrict pattern, int cflags) diff --git a/libc/regex/regerror.cpp b/libc/regex/regerror.c similarity index 98% rename from libc/regex/regerror.cpp rename to libc/regex/regerror.c index 3b9463bf..d3847094 100644 --- a/libc/regex/regerror.cpp +++ b/libc/regex/regerror.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 . - regex/regerror.cpp + regex/regerror.c Regular expression error reporting. *******************************************************************************/ @@ -26,7 +26,6 @@ #include #include -extern "C" size_t regerror(int errnum, const regex_t* restrict regex, char* restrict errbuf, diff --git a/libc/regex/regexec.cpp b/libc/regex/regexec.c similarity index 98% rename from libc/regex/regexec.cpp rename to libc/regex/regexec.c index 159ae356..48d9088b 100644 --- a/libc/regex/regexec.cpp +++ b/libc/regex/regexec.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 . - regex/regexec.cpp + regex/regexec.c Regular expression execution. *******************************************************************************/ #include -#include #include +#include +#include #define QUEUE_CURRENT_STATE(new_state) \ { \ @@ -95,7 +96,6 @@ } \ } \ -extern "C" int regexec(const regex_t* restrict regex_const, const char* restrict string, size_t nmatch, @@ -144,7 +144,7 @@ int regexec(const regex_t* restrict regex_const, regex->re->re_is_upcoming = 0; for ( size_t m = 0; m < nmatch; m++ ) { - regex->re->re_matches[m].rm_so = m == 0 ? i : -1; + regex->re->re_matches[m].rm_so = m == 0 ? (regoff_t) i : -1; regex->re->re_matches[m].rm_eo = -1; } } diff --git a/libc/regex/regfree.cpp b/libc/regex/regfree.c similarity index 97% rename from libc/regex/regfree.cpp rename to libc/regex/regfree.c index f30261fb..665c20ab 100644 --- a/libc/regex/regfree.cpp +++ b/libc/regex/regfree.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 . - regex/regfree.cpp + regex/regfree.c Regular expression freeing. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void regfree(regex_t* regex) +void regfree(regex_t* regex) { struct re* parent = NULL; struct re* re = regex->re; diff --git a/libc/sched/sched_yield.cpp b/libc/sched/sched_yield.c similarity index 95% rename from libc/sched/sched_yield.cpp rename to libc/sched/sched_yield.c index 664d87a1..c385ad25 100644 --- a/libc/sched/sched_yield.cpp +++ b/libc/sched/sched_yield.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 . - sched/sched_yield.cpp + sched/sched_yield.c Yields control of the CPU so another thread can run. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL0(int, sys_sched_yield, SYSCALL_SCHED_YIELD); -extern "C" int sched_yield(void) +int sched_yield(void) { return sys_sched_yield(); } diff --git a/libc/scram/scram.cpp b/libc/scram/scram.c similarity index 94% rename from libc/scram/scram.cpp rename to libc/scram/scram.c index 6d791e7c..02dc6823 100644 --- a/libc/scram/scram.cpp +++ b/libc/scram/scram.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 . - scram/scram.cpp + scram/scram.c Emergency process shutdown. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(void, sys_scram, SYSCALL_SCRAM, int, const void*); -extern "C" void scram(int event, const void* info) +void scram(int event, const void* info) { sys_scram(event, info); __builtin_unreachable(); diff --git a/libc/signal/kill.cpp b/libc/signal/kill.c similarity index 94% rename from libc/signal/kill.cpp rename to libc/signal/kill.c index 81cf5464..78b8b4e8 100644 --- a/libc/signal/kill.cpp +++ b/libc/signal/kill.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 . - signal/kill.cpp + signal/kill.c Send signal to process. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL2(int, sys_kill, SYSCALL_KILL, pid_t, int); -extern "C" int kill(pid_t pid, int signum) +int kill(pid_t pid, int signum) { return sys_kill(pid, signum); } diff --git a/libc/signal/killpg.cpp b/libc/signal/killpg.c similarity index 93% rename from libc/signal/killpg.cpp rename to libc/signal/killpg.c index 00bee597..0713b0cb 100644 --- a/libc/signal/killpg.cpp +++ b/libc/signal/killpg.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 . - signal/killpg.cpp + signal/killpg.c Send signal to a process group. *******************************************************************************/ #include -extern "C" int killpg(pid_t pgid, int signum) +int killpg(pid_t pgid, int signum) { return kill(-pgid, signum); } diff --git a/libc/signal/psiginfo.cpp b/libc/signal/psiginfo.c similarity index 92% rename from libc/signal/psiginfo.cpp rename to libc/signal/psiginfo.c index 465077f7..e2d960e1 100644 --- a/libc/signal/psiginfo.cpp +++ b/libc/signal/psiginfo.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 . - signal/psiginfo.cpp + signal/psiginfo.c Print signal error condition to stderr. *******************************************************************************/ #include -extern "C" void psiginfo(const siginfo_t* si, const char* message) +void psiginfo(const siginfo_t* si, const char* message) { psignal(si->si_signo, message); } diff --git a/libc/signal/psignal.cpp b/libc/signal/psignal.c similarity index 93% rename from libc/signal/psignal.cpp rename to libc/signal/psignal.c index 5830db08..e2d2ca04 100644 --- a/libc/signal/psignal.cpp +++ b/libc/signal/psignal.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 . - signal/psignal.cpp + signal/psignal.c Print signal error condition to stderr. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" void psignal(int signum, const char* message) +void psignal(int signum, const char* message) { const char* signumstr = strsignal(signum); if ( message ) diff --git a/libc/signal/raise.cpp b/libc/signal/raise.c similarity index 95% rename from libc/signal/raise.cpp rename to libc/signal/raise.c index 9fd779b6..946ebda7 100644 --- a/libc/signal/raise.cpp +++ b/libc/signal/raise.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 . - signal/raise.cpp + signal/raise.c Send signal to current process. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL1(int, sys_raise, SYSCALL_RAISE, int); -extern "C" int raise(int signum) +int raise(int signum) { return sys_raise(signum); } diff --git a/libc/signal/sigaction.cpp b/libc/signal/sigaction.c similarity index 97% rename from libc/signal/sigaction.cpp rename to libc/signal/sigaction.c index 087787c9..7e9dbe4d 100644 --- a/libc/signal/sigaction.cpp +++ b/libc/signal/sigaction.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 . - signal/sigaction.cpp + signal/sigaction.c Set the action that happens when a signal is triggered. *******************************************************************************/ @@ -31,7 +31,6 @@ DEFN_SYSCALL3(int, sys_sigaction, SYSCALL_SIGACTION, const struct sigaction*, struct sigaction*); -extern "C" int sigaction(int signum, const struct sigaction* restrict act, struct sigaction* restrict oldact) diff --git a/libc/signal/sigaddset.cpp b/libc/signal/sigaddset.c similarity index 94% rename from libc/signal/sigaddset.cpp rename to libc/signal/sigaddset.c index 02bd53fa..ebbe1102 100644 --- a/libc/signal/sigaddset.cpp +++ b/libc/signal/sigaddset.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 . - signal/sigaddset.cpp + signal/sigaddset.c Add a signal to a signal set. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int sigaddset(sigset_t* set, int signum) +int sigaddset(sigset_t* set, int signum) { int max_signals = sizeof(set->__val) * 8; if ( max_signals <= signum ) diff --git a/libc/signal/sigaltstack.cpp b/libc/signal/sigaltstack.c similarity index 91% rename from libc/signal/sigaltstack.cpp rename to libc/signal/sigaltstack.c index 35e7dfb1..2a60903d 100644 --- a/libc/signal/sigaltstack.cpp +++ b/libc/signal/sigaltstack.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 . - signal/sigaltstack.cpp + signal/sigaltstack.c Sets the stack used during signal handling. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_sigaltstack, SYSCALL_SIGALTSTACK, const stack_t*, stack_t*); -extern "C" int sigaltstack(const stack_t* restrict ss, stack_t* restrict oss) +int sigaltstack(const stack_t* restrict ss, stack_t* restrict oss) { return sys_sigaltstack(ss, oss); } diff --git a/libc/signal/sigandset.cpp b/libc/signal/sigandset.c similarity index 97% rename from libc/signal/sigandset.cpp rename to libc/signal/sigandset.c index 6351c9c0..1bca775e 100644 --- a/libc/signal/sigandset.cpp +++ b/libc/signal/sigandset.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 . - signal/sigandset.cpp + signal/sigandset.c Computes the intersection of two signal sets. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int sigandset(sigset_t* set, const sigset_t* left, const sigset_t* right) { for ( size_t i = 0; i < sizeof(set->__val) / sizeof(set->__val[0]); i++ ) diff --git a/libc/signal/sigdelset.cpp b/libc/signal/sigdelset.c similarity index 94% rename from libc/signal/sigdelset.cpp rename to libc/signal/sigdelset.c index d48f0bf6..bd2c03de 100644 --- a/libc/signal/sigdelset.cpp +++ b/libc/signal/sigdelset.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 . - signal/sigdelset.cpp + signal/sigdelset.c Remove a signal from a signal set. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int sigdelset(sigset_t* set, int signum) +int sigdelset(sigset_t* set, int signum) { int max_signals = sizeof(set->__val) * 8; if ( max_signals <= signum ) diff --git a/libc/signal/sigemptyset.cpp b/libc/signal/sigemptyset.c similarity index 94% rename from libc/signal/sigemptyset.cpp rename to libc/signal/sigemptyset.c index 574a5fd2..642c137e 100644 --- a/libc/signal/sigemptyset.cpp +++ b/libc/signal/sigemptyset.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 . - signal/sigemptyset.cpp + signal/sigemptyset.c Removes all the signals from a signal set. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int sigemptyset(sigset_t* set) +int sigemptyset(sigset_t* set) { memset(set, 0, sizeof(*set)); return 0; diff --git a/libc/signal/sigfillset.cpp b/libc/signal/sigfillset.c similarity index 94% rename from libc/signal/sigfillset.cpp rename to libc/signal/sigfillset.c index 2d5a1a30..4b5f2790 100644 --- a/libc/signal/sigfillset.cpp +++ b/libc/signal/sigfillset.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 . - signal/sigfillset.cpp + signal/sigfillset.c Add all signals to a signal set. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int sigfillset(sigset_t* set) +int sigfillset(sigset_t* set) { memset(set, 255, sizeof(*set)); return 0; diff --git a/libc/signal/sigisemptyset.cpp b/libc/signal/sigisemptyset.c similarity index 93% rename from libc/signal/sigisemptyset.cpp rename to libc/signal/sigisemptyset.c index ef267020..168c65fa 100644 --- a/libc/signal/sigisemptyset.cpp +++ b/libc/signal/sigisemptyset.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 . - signal/sigisemptyset.cpp + signal/sigisemptyset.c Tests whether this is the empty signal set. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int sigisemptyset(const sigset_t* set) +int sigisemptyset(const sigset_t* set) { for ( size_t i = 0; i < sizeof(set->__val) / sizeof(set->__val[0]); i++ ) if ( set->__val[i] != 0 ) diff --git a/libc/signal/sigismember.cpp b/libc/signal/sigismember.c similarity index 93% rename from libc/signal/sigismember.cpp rename to libc/signal/sigismember.c index 95da635c..b39ca360 100644 --- a/libc/signal/sigismember.cpp +++ b/libc/signal/sigismember.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 . - signal/sigismember.cpp + signal/sigismember.c Test signal membership in a signal set. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int sigismember(const sigset_t* set, int signum) +int sigismember(const sigset_t* set, int signum) { int max_signals = sizeof(set->__val) * 8; if ( signum < 0 || max_signals <= signum ) diff --git a/libc/signal/signal.cpp b/libc/signal/signal.c similarity index 95% rename from libc/signal/signal.cpp rename to libc/signal/signal.c index 3bf6c9e2..c17a4d68 100644 --- a/libc/signal/signal.cpp +++ b/libc/signal/signal.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 . - signal/signal.cpp + signal/signal.c Configure and retrieve a signal handler. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void (*signal(int signum, void (*handler)(int)))(int) +void (*signal(int signum, void (*handler)(int)))(int) { // Create a structure describing the new handler. struct sigaction newact; diff --git a/libc/signal/signotset.cpp b/libc/signal/signotset.c similarity index 97% rename from libc/signal/signotset.cpp rename to libc/signal/signotset.c index f2f4bcc4..caff2618 100644 --- a/libc/signal/signotset.cpp +++ b/libc/signal/signotset.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 . - signal/signotset.cpp + signal/signotset.c Computes the complement of a signal set. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int signotset(sigset_t* dst, const sigset_t* src) { for ( size_t i = 0; i < sizeof(dst->__val) / sizeof(dst->__val[0]); i++ ) diff --git a/libc/signal/sigorset.cpp b/libc/signal/sigorset.c similarity index 97% rename from libc/signal/sigorset.cpp rename to libc/signal/sigorset.c index ca279d40..a66db98c 100644 --- a/libc/signal/sigorset.cpp +++ b/libc/signal/sigorset.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 . - signal/sigorset.cpp + signal/sigorset.c Computes the union of two signal sets. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int sigorset(sigset_t* set, const sigset_t* left, const sigset_t* right) { for ( size_t i = 0; i < sizeof(set->__val) / sizeof(set->__val[0]); i++ ) diff --git a/libc/signal/sigpending.cpp b/libc/signal/sigpending.c similarity index 94% rename from libc/signal/sigpending.cpp rename to libc/signal/sigpending.c index 2fa42edd..d3318e47 100644 --- a/libc/signal/sigpending.cpp +++ b/libc/signal/sigpending.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 . - signal/sigpending.cpp + signal/sigpending.c Get the set of pending signals. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_sigpending, SYSCALL_SIGPENDING, sigset_t*); -extern "C" int sigpending(sigset_t* set) +int sigpending(sigset_t* set) { return sys_sigpending(set); } diff --git a/libc/signal/sigprocmask.cpp b/libc/signal/sigprocmask.c similarity index 92% rename from libc/signal/sigprocmask.cpp rename to libc/signal/sigprocmask.c index bed6d425..c9fc5b80 100644 --- a/libc/signal/sigprocmask.cpp +++ b/libc/signal/sigprocmask.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 . - signal/sigprocmask.cpp + signal/sigprocmask.c Examine and change blocked signals. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(int, sys_sigprocmask, SYSCALL_SIGPROCMASK, int, const sigset_t*, sigset_t*); -extern "C" int sigprocmask(int how, const sigset_t* set, sigset_t* oldset) +int sigprocmask(int how, const sigset_t* set, sigset_t* oldset) { return sys_sigprocmask(how, set, oldset); } diff --git a/libc/signal/sigsuspend.cpp b/libc/signal/sigsuspend.c similarity index 94% rename from libc/signal/sigsuspend.cpp rename to libc/signal/sigsuspend.c index e3d76db5..4a6ca98a 100644 --- a/libc/signal/sigsuspend.cpp +++ b/libc/signal/sigsuspend.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 . - signal/sigsuspend.cpp + signal/sigsuspend.c Wait until a signal occurs. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_sigsuspend, SYSCALL_SIGSUSPEND, const sigset_t*); -extern "C" int sigsuspend(const sigset_t* set) +int sigsuspend(const sigset_t* set) { return sys_sigsuspend(set); } diff --git a/libc/ssp/__stack_chk_fail.cpp b/libc/ssp/__stack_chk_fail.c similarity index 78% rename from libc/ssp/__stack_chk_fail.cpp rename to libc/ssp/__stack_chk_fail.c index 06b42902..bda732a4 100644 --- a/libc/ssp/__stack_chk_fail.cpp +++ b/libc/ssp/__stack_chk_fail.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 . - ssp/__stack_chk_fail.cpp + ssp/__stack_chk_fail.c Abnormally terminate the process on stack smashing. *******************************************************************************/ @@ -32,9 +32,8 @@ #include <__/wordsize.h> -#if defined(__is_sortix_kernel) -#include -#include +#ifdef __is_sortix_libk +#include #endif #if __WORDSIZE == 32 @@ -43,22 +42,19 @@ #define STACK_CHK_GUARD 0x0123456789ABCDEF #endif -#if __STDC_HOSTED__ +#ifdef __is_sortix_libk /* TODO: Have this filled in by the program loader. */ #else /* TODO: Have this filled in by the boot loader. */ #endif -extern "C" { uintptr_t __stack_chk_guard = STACK_CHK_GUARD; } +uintptr_t __stack_chk_guard = STACK_CHK_GUARD; -extern "C" __attribute__((noreturn)) +__attribute__((noreturn)) void __stack_chk_fail(void) { -#if __STDC_HOSTED__ - scram(SCRAM_STACK_SMASH, NULL); -#elif defined(__is_sortix_kernel) - Sortix::Panic("Stack smashing detected"); +#ifdef __is_sortix_libk + libk_stack_chk_fail(); #else - #warning "You need to implement a stack smash reporting mechanism" - abort(); + scram(SCRAM_STACK_SMASH, NULL); #endif } diff --git a/libc/stdio/asprintf.cpp b/libc/stdio/asprintf.c similarity index 97% rename from libc/stdio/asprintf.cpp rename to libc/stdio/asprintf.c index af1aa6e4..ce2f4998 100644 --- a/libc/stdio/asprintf.cpp +++ b/libc/stdio/asprintf.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 . - stdio/asprintf.cpp + stdio/asprintf.c Prints a string to a newly allocated buffer. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int asprintf(char** restrict result_ptr, const char* restrict format, ...) diff --git a/libc/stdio/cbprintf.cpp b/libc/stdio/cbprintf.c similarity index 97% rename from libc/stdio/cbprintf.cpp rename to libc/stdio/cbprintf.c index 018a040d..9c819db4 100644 --- a/libc/stdio/cbprintf.cpp +++ b/libc/stdio/cbprintf.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 . - stdio/cbprintf.cpp + stdio/cbprintf.c Formats text and outputs it via callback functions. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int cbprintf(void* user, size_t (*callback)(void*, const char*, size_t), const char* format, diff --git a/libc/stdio/clearerr.cpp b/libc/stdio/clearerr.c similarity index 94% rename from libc/stdio/clearerr.cpp rename to libc/stdio/clearerr.c index e3e0aa32..d9f956bc 100644 --- a/libc/stdio/clearerr.cpp +++ b/libc/stdio/clearerr.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 . - stdio/clearerr.cpp + stdio/clearerr.c Clears the error condition on a FILE. *******************************************************************************/ #include -extern "C" void clearerr(FILE* fp) +void clearerr(FILE* fp) { flockfile(fp); clearerr_unlocked(fp); diff --git a/libc/stdio/clearerr_unlocked.cpp b/libc/stdio/clearerr_unlocked.c similarity index 93% rename from libc/stdio/clearerr_unlocked.cpp rename to libc/stdio/clearerr_unlocked.c index 4bce93cb..5618092e 100644 --- a/libc/stdio/clearerr_unlocked.cpp +++ b/libc/stdio/clearerr_unlocked.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 . - stdio/clearerr_unlocked.cpp + stdio/clearerr_unlocked.c Clears the error condition on a FILE. *******************************************************************************/ #include -extern "C" void clearerr_unlocked(FILE* fp) +void clearerr_unlocked(FILE* fp) { fp->flags &= ~_FILE_STATUS_ERROR; } diff --git a/libc/stdio/dprintf.cpp b/libc/stdio/dprintf.c similarity index 93% rename from libc/stdio/dprintf.cpp rename to libc/stdio/dprintf.c index 4b406d4f..e370cacb 100644 --- a/libc/stdio/dprintf.cpp +++ b/libc/stdio/dprintf.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 . - stdio/dprintf.cpp + stdio/dprintf.c Prints a formatted string to a file descriptor. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int dprintf(int fd, const char* restrict format, ...) +int dprintf(int fd, const char* restrict format, ...) { va_list list; va_start(list, format); diff --git a/libc/stdio/fclose.cpp b/libc/stdio/fclose.c similarity index 95% rename from libc/stdio/fclose.cpp rename to libc/stdio/fclose.c index 293454d9..f27cd723 100644 --- a/libc/stdio/fclose.cpp +++ b/libc/stdio/fclose.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 . - stdio/fclose.cpp + stdio/fclose.c Closes and flushes a FILE. *******************************************************************************/ #include -extern "C" int fclose(FILE* fp) +int fclose(FILE* fp) { flockfile(fp); funlockfile(fp); diff --git a/libc/stdio/fdeletefile.cpp b/libc/stdio/fdeletefile.c similarity index 94% rename from libc/stdio/fdeletefile.cpp rename to libc/stdio/fdeletefile.c index e37fec9e..5dfb1ffa 100644 --- a/libc/stdio/fdeletefile.cpp +++ b/libc/stdio/fdeletefile.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 . - stdio/fdeletefile.cpp + stdio/fdeletefile.c Deallocator for things returned by fnewfile after being shut down. *******************************************************************************/ #include -extern "C" void fdeletefile(FILE* fp) +void fdeletefile(FILE* fp) { funregister(fp); if ( fp->free_func ) diff --git a/libc/stdio/fdio_close.cpp b/libc/stdio/fdio_close.c similarity index 96% rename from libc/stdio/fdio_close.cpp rename to libc/stdio/fdio_close.c index 1b058907..d4887a6a 100644 --- a/libc/stdio/fdio_close.cpp +++ b/libc/stdio/fdio_close.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 . - stdio/fdio_close.cpp + stdio/fdio_close.c File descriptor FILE backend closing. *******************************************************************************/ @@ -27,7 +27,6 @@ #include "fdio.h" -extern "C" int fdio_close(void* user) { FILE* fp = (FILE*) user; diff --git a/libc/stdio/fdio_install_fd.cpp b/libc/stdio/fdio_install_fd.c similarity index 94% rename from libc/stdio/fdio_install_fd.cpp rename to libc/stdio/fdio_install_fd.c index 41ae7edc..db25b4f8 100644 --- a/libc/stdio/fdio_install_fd.cpp +++ b/libc/stdio/fdio_install_fd.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 . - stdio/fdio_install_fd.cpp + stdio/fdio_install_fd.c Opens a FILE from a file descriptor. *******************************************************************************/ @@ -26,13 +26,14 @@ #include #include +#include #include #include #include #include "fdio.h" -extern "C" bool fdio_install_fd(FILE* fp, int fd, const char* mode) +bool fdio_install_fd(FILE* fp, int fd, const char* mode) { int mode_flags = fparsemode(mode); if ( mode_flags < 0 ) diff --git a/libc/stdio/fdio_install_path.cpp b/libc/stdio/fdio_install_path.c similarity index 93% rename from libc/stdio/fdio_install_path.cpp rename to libc/stdio/fdio_install_path.c index ea63a600..8ce3e870 100644 --- a/libc/stdio/fdio_install_path.cpp +++ b/libc/stdio/fdio_install_path.c @@ -17,19 +17,20 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdio/fdio_install_path.cpp + stdio/fdio_install_path.c Opens a FILE from a path. *******************************************************************************/ #include #include +#include #include #include #include "fdio.h" -extern "C" bool fdio_install_path(FILE* fp, const char* path, const char* mode) +bool fdio_install_path(FILE* fp, const char* path, const char* mode) { int mode_flags = fparsemode(mode); if ( mode_flags < 0 ) diff --git a/libc/stdio/fdio_read.cpp b/libc/stdio/fdio_read.c similarity index 97% rename from libc/stdio/fdio_read.cpp rename to libc/stdio/fdio_read.c index 6a1578a3..3313930f 100644 --- a/libc/stdio/fdio_read.cpp +++ b/libc/stdio/fdio_read.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 . - stdio/fdio_read.cpp + stdio/fdio_read.c File descriptor FILE backend reading. *******************************************************************************/ @@ -27,7 +27,6 @@ #include "fdio.h" -extern "C" ssize_t fdio_read(void* user, void* ptr, size_t size) { FILE* fp = (FILE*) user; diff --git a/libc/stdio/fdio_seek.cpp b/libc/stdio/fdio_seek.c similarity index 97% rename from libc/stdio/fdio_seek.cpp rename to libc/stdio/fdio_seek.c index 59fa76f7..9bed267e 100644 --- a/libc/stdio/fdio_seek.cpp +++ b/libc/stdio/fdio_seek.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 . - stdio/fdio_seek.cpp + stdio/fdio_seek.c File descriptor FILE backend seeking. *******************************************************************************/ @@ -27,7 +27,6 @@ #include "fdio.h" -extern "C" off_t fdio_seek(void* user, off_t offset, int whence) { FILE* fp = (FILE*) user; diff --git a/libc/stdio/fdio_write.cpp b/libc/stdio/fdio_write.c similarity index 97% rename from libc/stdio/fdio_write.cpp rename to libc/stdio/fdio_write.c index 49f3d20c..36cf7010 100644 --- a/libc/stdio/fdio_write.cpp +++ b/libc/stdio/fdio_write.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 . - stdio/fdio_write.cpp + stdio/fdio_write.c File descriptor FILE backend writing. *******************************************************************************/ @@ -27,7 +27,6 @@ #include "fdio.h" -extern "C" ssize_t fdio_write(void* user, const void* ptr, size_t size) { FILE* fp = (FILE*) user; diff --git a/libc/stdio/fdopen.cpp b/libc/stdio/fdopen.c similarity index 94% rename from libc/stdio/fdopen.cpp rename to libc/stdio/fdopen.c index 305ce268..56b191a8 100644 --- a/libc/stdio/fdopen.cpp +++ b/libc/stdio/fdopen.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 . - stdio/fdopen.cpp + stdio/fdopen.c Opens a FILE from a file descriptor. *******************************************************************************/ @@ -26,7 +26,7 @@ #include "fdio.h" -extern "C" FILE* fdopen(int fd, const char* mode) +FILE* fdopen(int fd, const char* mode) { FILE* fp = fnewfile(); if ( !fp ) diff --git a/libc/stdio/feof.cpp b/libc/stdio/feof.c similarity index 95% rename from libc/stdio/feof.cpp rename to libc/stdio/feof.c index e412a450..3251658d 100644 --- a/libc/stdio/feof.cpp +++ b/libc/stdio/feof.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 . - stdio/feof.cpp + stdio/feof.c Returns whether the end of file condition is set on a FILE. *******************************************************************************/ #include -extern "C" int feof(FILE* fp) +int feof(FILE* fp) { flockfile(fp); int ret = feof_unlocked(fp); diff --git a/libc/stdio/feof_unlocked.cpp b/libc/stdio/feof_unlocked.c similarity index 94% rename from libc/stdio/feof_unlocked.cpp rename to libc/stdio/feof_unlocked.c index a4daa10e..32a4dc84 100644 --- a/libc/stdio/feof_unlocked.cpp +++ b/libc/stdio/feof_unlocked.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 . - stdio/feof_unlocked.cpp + stdio/feof_unlocked.c Returns whether the end of file condition is set on a FILE. *******************************************************************************/ #include -extern "C" int feof_unlocked(FILE* fp) +int feof_unlocked(FILE* fp) { return fp->flags & _FILE_STATUS_EOF ? 1 : 0; } diff --git a/libc/stdio/ferror.cpp b/libc/stdio/ferror.c similarity index 95% rename from libc/stdio/ferror.cpp rename to libc/stdio/ferror.c index 8f427fb3..51a135d6 100644 --- a/libc/stdio/ferror.cpp +++ b/libc/stdio/ferror.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 . - stdio/ferror.cpp + stdio/ferror.c Returns whether the error condition is set on a FILE. *******************************************************************************/ #include -extern "C" int ferror(FILE* fp) +int ferror(FILE* fp) { flockfile(fp); int ret = ferror_unlocked(fp); diff --git a/libc/stdio/ferror_unlocked.cpp b/libc/stdio/ferror_unlocked.c similarity index 93% rename from libc/stdio/ferror_unlocked.cpp rename to libc/stdio/ferror_unlocked.c index 5195f9db..4a0bb6b6 100644 --- a/libc/stdio/ferror_unlocked.cpp +++ b/libc/stdio/ferror_unlocked.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 . - stdio/ferror_unlocked.cpp + stdio/ferror_unlocked.c Returns whether the error condition is set on a FILE. *******************************************************************************/ #include -extern "C" int ferror_unlocked(FILE* fp) +int ferror_unlocked(FILE* fp) { return fp->flags & _FILE_STATUS_ERROR ? 1 : 0; } diff --git a/libc/stdio/fflush.cpp b/libc/stdio/fflush.c similarity index 92% rename from libc/stdio/fflush.cpp rename to libc/stdio/fflush.c index d4168bc0..842f0011 100644 --- a/libc/stdio/fflush.cpp +++ b/libc/stdio/fflush.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 . - stdio/fflush.cpp + stdio/fflush.c Flushes a FILE. *******************************************************************************/ @@ -26,9 +26,9 @@ #include static FILE* volatile dummy_file = NULL; -weak_alias_cxx(dummy_file, __stdout_used, "_ZL10dummy_file"); +weak_alias(dummy_file, __stdout_used); -extern "C" int fflush(FILE* fp) +int fflush(FILE* fp) { if ( !fp ) { diff --git a/libc/stdio/fflush_stop_reading.cpp b/libc/stdio/fflush_stop_reading.c similarity index 93% rename from libc/stdio/fflush_stop_reading.cpp rename to libc/stdio/fflush_stop_reading.c index 203030c8..e605e817 100644 --- a/libc/stdio/fflush_stop_reading.cpp +++ b/libc/stdio/fflush_stop_reading.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 . - stdio/fflush_stop_reading.cpp + stdio/fflush_stop_reading.c Resets the FILE to a consistent state so it is ready for writing. *******************************************************************************/ #include -extern "C" int fflush_stop_reading(FILE* fp) +int fflush_stop_reading(FILE* fp) { flockfile(fp); int ret = fflush_stop_reading_unlocked(fp); diff --git a/libc/stdio/fflush_stop_reading_unlocked.cpp b/libc/stdio/fflush_stop_reading_unlocked.c similarity index 95% rename from libc/stdio/fflush_stop_reading_unlocked.cpp rename to libc/stdio/fflush_stop_reading_unlocked.c index 9988025a..39744e52 100644 --- a/libc/stdio/fflush_stop_reading_unlocked.cpp +++ b/libc/stdio/fflush_stop_reading_unlocked.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 . - stdio/fflush_stop_reading_unlocked.cpp + stdio/fflush_stop_reading_unlocked.c Resets the FILE to a consistent state ready for writing. *******************************************************************************/ @@ -29,7 +29,7 @@ #include #include -extern "C" int fflush_stop_reading_unlocked(FILE* fp) +int fflush_stop_reading_unlocked(FILE* fp) { if ( !(fp->flags & _FILE_LAST_READ) ) return 0; diff --git a/libc/stdio/fflush_stop_writing.cpp b/libc/stdio/fflush_stop_writing.c similarity index 93% rename from libc/stdio/fflush_stop_writing.cpp rename to libc/stdio/fflush_stop_writing.c index 23209fbb..bb25e2a1 100644 --- a/libc/stdio/fflush_stop_writing.cpp +++ b/libc/stdio/fflush_stop_writing.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 . - stdio/fflush_stop_writing.cpp + stdio/fflush_stop_writing.c Resets the FILE to a consistent state so it is ready for reading. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fflush_stop_writing(FILE* fp) +int fflush_stop_writing(FILE* fp) { flockfile(fp); int ret = fflush_stop_writing_unlocked(fp); diff --git a/libc/stdio/fflush_stop_writing_unlocked.cpp b/libc/stdio/fflush_stop_writing_unlocked.c similarity index 95% rename from libc/stdio/fflush_stop_writing_unlocked.cpp rename to libc/stdio/fflush_stop_writing_unlocked.c index d0e74297..5146f2ea 100644 --- a/libc/stdio/fflush_stop_writing_unlocked.cpp +++ b/libc/stdio/fflush_stop_writing_unlocked.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 . - stdio/fflush_stop_writing_unlocked.cpp + stdio/fflush_stop_writing_unlocked.c Resets the FILE to a consistent state so it is ready for reading. *******************************************************************************/ @@ -29,7 +29,7 @@ #include #include -extern "C" int fflush_stop_writing_unlocked(FILE* fp) +int fflush_stop_writing_unlocked(FILE* fp) { if ( !(fp->flags & _FILE_LAST_WRITE) ) return 0; diff --git a/libc/stdio/fflush_unlocked.cpp b/libc/stdio/fflush_unlocked.c similarity index 94% rename from libc/stdio/fflush_unlocked.cpp rename to libc/stdio/fflush_unlocked.c index a394b56f..7dd06eab 100644 --- a/libc/stdio/fflush_unlocked.cpp +++ b/libc/stdio/fflush_unlocked.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 . - stdio/fflush_unlocked.cpp + stdio/fflush_unlocked.c Flushes a FILE. *******************************************************************************/ #include -extern "C" int fflush_unlocked(FILE* fp) +int fflush_unlocked(FILE* fp) { if ( (fp->flags & _FILE_LAST_READ) && fflush_stop_reading_unlocked(fp) == EOF ) return EOF; diff --git a/libc/stdio/fgetc.cpp b/libc/stdio/fgetc.c similarity index 95% rename from libc/stdio/fgetc.cpp rename to libc/stdio/fgetc.c index 014f1512..416d16f0 100644 --- a/libc/stdio/fgetc.cpp +++ b/libc/stdio/fgetc.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 . - stdio/fgetc.cpp + stdio/fgetc.c Reads a single character from a FILE. *******************************************************************************/ #include -extern "C" int fgetc(FILE* fp) +int fgetc(FILE* fp) { flockfile(fp); int ret = fgetc_unlocked(fp); diff --git a/libc/stdio/fgetc_unlocked.cpp b/libc/stdio/fgetc_unlocked.c similarity index 97% rename from libc/stdio/fgetc_unlocked.cpp rename to libc/stdio/fgetc_unlocked.c index e132fee7..12d8f107 100644 --- a/libc/stdio/fgetc_unlocked.cpp +++ b/libc/stdio/fgetc_unlocked.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 . - stdio/fgetc_unlocked.cpp + stdio/fgetc_unlocked.c Reads a single character from a FILE. *******************************************************************************/ @@ -32,7 +32,7 @@ #include #include -extern "C" int fgetc_unlocked(FILE* fp) +int fgetc_unlocked(FILE* fp) { if ( !(fp->flags & _FILE_READABLE) ) return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, EOF; diff --git a/libc/stdio/fgetpos.cpp b/libc/stdio/fgetpos.c similarity index 92% rename from libc/stdio/fgetpos.cpp rename to libc/stdio/fgetpos.c index 903fdbb0..3139bc07 100644 --- a/libc/stdio/fgetpos.cpp +++ b/libc/stdio/fgetpos.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 . - stdio/fgetpos.cpp + stdio/fgetpos.c Get current file position information. *******************************************************************************/ #include -extern "C" int fgetpos(FILE* restrict fp, fpos_t* restrict pos) +int fgetpos(FILE* restrict fp, fpos_t* restrict pos) { if ( (*pos = ftello(fp)) < 0 ) return -1; diff --git a/libc/stdio/fgets.cpp b/libc/stdio/fgets.c similarity index 92% rename from libc/stdio/fgets.cpp rename to libc/stdio/fgets.c index 8dabec75..b55c9042 100644 --- a/libc/stdio/fgets.cpp +++ b/libc/stdio/fgets.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 . - stdio/fgets.cpp + stdio/fgets.c Reads a string from a FILE. *******************************************************************************/ #include -extern "C" char* fgets(char* restrict dest, int size, FILE* restrict fp) +char* fgets(char* restrict dest, int size, FILE* restrict fp) { flockfile(fp); char* result = fgets_unlocked(dest, size, fp); diff --git a/libc/stdio/fgets_unlocked.cpp b/libc/stdio/fgets_unlocked.c similarity index 97% rename from libc/stdio/fgets_unlocked.cpp rename to libc/stdio/fgets_unlocked.c index 82281a75..de20bfa1 100644 --- a/libc/stdio/fgets_unlocked.cpp +++ b/libc/stdio/fgets_unlocked.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 . - stdio/fgets_unlocked.cpp + stdio/fgets_unlocked.c Reads a string from a FILE. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" char* fgets_unlocked(char* restrict dest, int size, FILE* restrict fp) { if ( size <= 0 ) diff --git a/libc/stdio/fileno.cpp b/libc/stdio/fileno.c similarity index 95% rename from libc/stdio/fileno.cpp rename to libc/stdio/fileno.c index 5eacb9a8..09e02752 100644 --- a/libc/stdio/fileno.cpp +++ b/libc/stdio/fileno.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 . - stdio/fileno.cpp + stdio/fileno.c Returns the underlying file descriptor of a FILE if applicable. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fileno(FILE* fp) +int fileno(FILE* fp) { flockfile(fp); int ret = fileno_unlocked(fp); diff --git a/libc/stdio/fileno_unlocked.cpp b/libc/stdio/fileno_unlocked.c similarity index 93% rename from libc/stdio/fileno_unlocked.cpp rename to libc/stdio/fileno_unlocked.c index 98308495..85785177 100644 --- a/libc/stdio/fileno_unlocked.cpp +++ b/libc/stdio/fileno_unlocked.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 . - stdio/fileno_unlocked.cpp + stdio/fileno_unlocked.c Returns the underlying file descriptor of a FILE if applicable. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fileno_unlocked(FILE* fp) +int fileno_unlocked(FILE* fp) { return fp->fd; } diff --git a/libc/stdio/flockfile.cpp b/libc/stdio/flockfile.c similarity index 94% rename from libc/stdio/flockfile.cpp rename to libc/stdio/flockfile.c index 7d2e1503..cfab068d 100644 --- a/libc/stdio/flockfile.cpp +++ b/libc/stdio/flockfile.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 . - stdio/flockfile.cpp + stdio/flockfile.c Locks this FILE object to the current thread. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void flockfile(FILE* fp) +void flockfile(FILE* fp) { pthread_mutex_lock(&fp->file_lock); } diff --git a/libc/stdio/fmemopen.cpp b/libc/stdio/fmemopen.c similarity index 99% rename from libc/stdio/fmemopen.cpp rename to libc/stdio/fmemopen.c index 0808f89c..4e20c7a7 100644 --- a/libc/stdio/fmemopen.cpp +++ b/libc/stdio/fmemopen.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 . - libc/stdio/fmemopen.cpp + libc/stdio/fmemopen.c Open a memory buffer stream. *******************************************************************************/ @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -133,7 +134,6 @@ static int fmemopen_close(void* state_ptr) return 0; } -extern "C" FILE* fmemopen(void* restrict buffer_ptr, size_t buffer_size, const char* restrict mode_str) diff --git a/libc/stdio/fnewfile.cpp b/libc/stdio/fnewfile.c similarity index 92% rename from libc/stdio/fnewfile.cpp rename to libc/stdio/fnewfile.c index 802c72e9..e20abff1 100644 --- a/libc/stdio/fnewfile.cpp +++ b/libc/stdio/fnewfile.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 . - stdio/fnewfile.cpp + stdio/fnewfile.c Allocates and initializes a simple FILE object ready for construction. *******************************************************************************/ @@ -27,12 +27,13 @@ #include #include -static void fnewfile_destroyer(void* /*user*/, FILE* fp) +static void fnewfile_destroyer(void* user, FILE* fp) { + (void) user; free(fp); } -extern "C" FILE* fnewfile(void) +FILE* fnewfile(void) { FILE* fp = (FILE*) malloc(sizeof(FILE) + BUFSIZ); if ( !fp ) diff --git a/libc/stdio/fopen.cpp b/libc/stdio/fopen.c similarity index 93% rename from libc/stdio/fopen.cpp rename to libc/stdio/fopen.c index 92c472c7..4c4a424a 100644 --- a/libc/stdio/fopen.cpp +++ b/libc/stdio/fopen.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 . - stdio/fopen.cpp + stdio/fopen.c Opens a FILE from a path. *******************************************************************************/ @@ -26,7 +26,7 @@ #include "fdio.h" -extern "C" FILE* fopen(const char* path, const char* mode) +FILE* fopen(const char* path, const char* mode) { FILE* fp = fnewfile(); if ( !fp ) diff --git a/libc/stdio/fparsemode.cpp b/libc/stdio/fparsemode.c similarity index 96% rename from libc/stdio/fparsemode.cpp rename to libc/stdio/fparsemode.c index 49ff2ef7..f08147eb 100644 --- a/libc/stdio/fparsemode.cpp +++ b/libc/stdio/fparsemode.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 . - stdio/fparsemode.cpp + stdio/fparsemode.c Parses the mode argument of functions like fopen(). *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fparsemode(const char* mode) +int fparsemode(const char* mode) { int result; diff --git a/libc/stdio/fpipe.cpp b/libc/stdio/fpipe.c similarity index 95% rename from libc/stdio/fpipe.cpp rename to libc/stdio/fpipe.c index 82bab483..ccbfb4a2 100644 --- a/libc/stdio/fpipe.cpp +++ b/libc/stdio/fpipe.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 . - stdio/fpipe.cpp + stdio/fpipe.c Provides pipe(2) through the FILE interface. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fpipe(FILE* pipes[2]) +int fpipe(FILE* pipes[2]) { int pipefd[2]; if ( pipe(pipefd) ) { return -1; } diff --git a/libc/stdio/fprintf.cpp b/libc/stdio/fprintf.c similarity index 93% rename from libc/stdio/fprintf.cpp rename to libc/stdio/fprintf.c index 037030ee..6596a2d8 100644 --- a/libc/stdio/fprintf.cpp +++ b/libc/stdio/fprintf.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 . - stdio/fprintf.cpp + stdio/fprintf.c Prints a string to a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fprintf(FILE* fp, const char* restrict format, ...) +int fprintf(FILE* fp, const char* restrict format, ...) { va_list list; va_start(list, format); diff --git a/libc/stdio/fprintf_unlocked.cpp b/libc/stdio/fprintf_unlocked.c similarity index 91% rename from libc/stdio/fprintf_unlocked.cpp rename to libc/stdio/fprintf_unlocked.c index 97fae0a7..78010edc 100644 --- a/libc/stdio/fprintf_unlocked.cpp +++ b/libc/stdio/fprintf_unlocked.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 . - stdio/fprintf_unlocked.cpp + stdio/fprintf_unlocked.c Prints a string to a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fprintf_unlocked(FILE* fp, const char* restrict format, ...) +int fprintf_unlocked(FILE* fp, const char* restrict format, ...) { va_list list; va_start(list, format); diff --git a/libc/stdio/fputc.cpp b/libc/stdio/fputc.c similarity index 95% rename from libc/stdio/fputc.cpp rename to libc/stdio/fputc.c index f085f75e..5c9ebfd4 100644 --- a/libc/stdio/fputc.cpp +++ b/libc/stdio/fputc.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 . - stdio/fputc.cpp + stdio/fputc.c Writes a character to a FILE. *******************************************************************************/ #include -extern "C" int fputc(int c, FILE* fp) +int fputc(int c, FILE* fp) { flockfile(fp); int ret = fputc_unlocked(c, fp); diff --git a/libc/stdio/fputc_unlocked.cpp b/libc/stdio/fputc_unlocked.c similarity index 96% rename from libc/stdio/fputc_unlocked.cpp rename to libc/stdio/fputc_unlocked.c index 964c3352..8882be28 100644 --- a/libc/stdio/fputc_unlocked.cpp +++ b/libc/stdio/fputc_unlocked.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 . - stdio/fputc_unlocked.cpp + stdio/fputc_unlocked.c Writes a character to a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fputc_unlocked(int c, FILE* fp) +int fputc_unlocked(int c, FILE* fp) { if ( !(fp->flags & _FILE_WRITABLE) ) return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, EOF; diff --git a/libc/stdio/fputs.cpp b/libc/stdio/fputs.c similarity index 94% rename from libc/stdio/fputs.cpp rename to libc/stdio/fputs.c index 01000770..6c70181f 100644 --- a/libc/stdio/fputs.cpp +++ b/libc/stdio/fputs.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 . - stdio/fputs.cpp + stdio/fputs.c Writes a string to a FILE. *******************************************************************************/ #include -extern "C" int fputs(const char* str, FILE* fp) +int fputs(const char* str, FILE* fp) { flockfile(fp); int result = fputs_unlocked(str, fp); diff --git a/libc/stdio/fputs_unlocked.cpp b/libc/stdio/fputs_unlocked.c similarity index 93% rename from libc/stdio/fputs_unlocked.cpp rename to libc/stdio/fputs_unlocked.c index 777353ad..868f8e67 100644 --- a/libc/stdio/fputs_unlocked.cpp +++ b/libc/stdio/fputs_unlocked.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 . - stdio/fputs_unlocked.cpp + stdio/fputs_unlocked.c Writes a string to a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fputs_unlocked(const char* str, FILE* fp) +int fputs_unlocked(const char* str, FILE* fp) { size_t stringlen = strlen(str); if ( fwrite_unlocked(str, 1, stringlen, fp) < stringlen ) diff --git a/libc/stdio/fread.cpp b/libc/stdio/fread.c similarity index 92% rename from libc/stdio/fread.cpp rename to libc/stdio/fread.c index 5bc291e3..7d0f6112 100644 --- a/libc/stdio/fread.cpp +++ b/libc/stdio/fread.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 . - stdio/fread.cpp + stdio/fread.c Reads data from a FILE. *******************************************************************************/ #include -extern "C" size_t fread(void* ptr, size_t size, size_t nmemb, FILE* fp) +size_t fread(void* ptr, size_t size, size_t nmemb, FILE* fp) { flockfile(fp); size_t ret = fread_unlocked(ptr, size, nmemb, fp); diff --git a/libc/stdio/fread_unlocked.cpp b/libc/stdio/fread_unlocked.c similarity index 98% rename from libc/stdio/fread_unlocked.cpp rename to libc/stdio/fread_unlocked.c index 10342e69..0085d12b 100644 --- a/libc/stdio/fread_unlocked.cpp +++ b/libc/stdio/fread_unlocked.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 . - stdio/fread_unlocked.cpp + stdio/fread_unlocked.c Reads data from a FILE. *******************************************************************************/ @@ -29,7 +29,6 @@ #include #include -extern "C" size_t fread_unlocked(void* ptr, size_t element_size, size_t num_elements, diff --git a/libc/stdio/fregister.cpp b/libc/stdio/fregister.c similarity index 95% rename from libc/stdio/fregister.cpp rename to libc/stdio/fregister.c index 7489bc1d..302b06de 100644 --- a/libc/stdio/fregister.cpp +++ b/libc/stdio/fregister.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 . - stdio/fregister.cpp + stdio/fregister.c Registers a FILE in the global list of open FILEs. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void fregister(FILE* fp) +void fregister(FILE* fp) { pthread_mutex_lock(&__first_file_lock); fp->flags |= _FILE_REGISTERED; diff --git a/libc/stdio/freopen.cpp b/libc/stdio/freopen.c similarity index 93% rename from libc/stdio/freopen.cpp rename to libc/stdio/freopen.c index c718993a..470ce4ce 100644 --- a/libc/stdio/freopen.cpp +++ b/libc/stdio/freopen.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 . - stdio/freopen.cpp + stdio/freopen.c Changes the file with which a FILE is associated. *******************************************************************************/ @@ -27,7 +27,7 @@ #include "fdio.h" -extern "C" FILE* freopen(const char* path, const char* mode, FILE* fp) +FILE* freopen(const char* path, const char* mode, FILE* fp) { if ( !path ) return errno = EBADF, (FILE*) NULL; diff --git a/libc/stdio/fresetfile.cpp b/libc/stdio/fresetfile.c similarity index 93% rename from libc/stdio/fresetfile.cpp rename to libc/stdio/fresetfile.c index cd83e90b..d53870dc 100644 --- a/libc/stdio/fresetfile.cpp +++ b/libc/stdio/fresetfile.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 . - stdio/fresetfile.cpp + stdio/fresetfile.c After a FILE has been shut down, returns all fields to their default state. *******************************************************************************/ @@ -29,7 +29,7 @@ // Note: This function preserves a few parts of the fields - this means that if // you are using this to reset a fresh FILE object, you should memset it // to zeroes first to avoid problems. -extern "C" void fresetfile(FILE* fp) +void fresetfile(FILE* fp) { FILE* prev = fp->prev; FILE* next = fp->next; @@ -39,7 +39,7 @@ extern "C" void fresetfile(FILE* fp) int kept_flags = fp->flags & (_FILE_REGISTERED | 0); memset(fp, 0, sizeof(*fp)); fp->buffer = keep_buffer; - fp->file_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; + fp->file_lock = (pthread_mutex_t) PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; fp->flags = kept_flags; fp->buffer_mode = -1; fp->free_user = free_user; diff --git a/libc/stdio/fscanf.cpp b/libc/stdio/fscanf.c similarity index 93% rename from libc/stdio/fscanf.cpp rename to libc/stdio/fscanf.c index 532c2c01..e5fdd965 100644 --- a/libc/stdio/fscanf.cpp +++ b/libc/stdio/fscanf.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 . - stdio/fscanf.cpp + stdio/fscanf.c Input format conversion. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fscanf(FILE* fp, const char* format, ...) +int fscanf(FILE* fp, const char* format, ...) { va_list ap; va_start(ap, format); diff --git a/libc/stdio/fscanf_unlocked.cpp b/libc/stdio/fscanf_unlocked.c similarity index 92% rename from libc/stdio/fscanf_unlocked.cpp rename to libc/stdio/fscanf_unlocked.c index 8efe54b9..6b238a56 100644 --- a/libc/stdio/fscanf_unlocked.cpp +++ b/libc/stdio/fscanf_unlocked.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 . - stdio/fscanf_unlocked.cpp + stdio/fscanf_unlocked.c Input format conversion. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fscanf_unlocked(FILE* fp, const char* format, ...) +int fscanf_unlocked(FILE* fp, const char* format, ...) { va_list ap; va_start(ap, format); diff --git a/libc/stdio/fseek.cpp b/libc/stdio/fseek.c similarity index 93% rename from libc/stdio/fseek.cpp rename to libc/stdio/fseek.c index 3a45de6c..34bbd4d3 100644 --- a/libc/stdio/fseek.cpp +++ b/libc/stdio/fseek.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 . - stdio/fseek.cpp + stdio/fseek.c Changes the current offset in a FILE. *******************************************************************************/ #include -extern "C" int fseek(FILE* fp, long offset, int whence) +int fseek(FILE* fp, long offset, int whence) { return fseeko(fp, offset, whence); } diff --git a/libc/stdio/fseeko.cpp b/libc/stdio/fseeko.c similarity index 93% rename from libc/stdio/fseeko.cpp rename to libc/stdio/fseeko.c index d703686b..570b1e3d 100644 --- a/libc/stdio/fseeko.cpp +++ b/libc/stdio/fseeko.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 . - stdio/fseeko.cpp + stdio/fseeko.c Changes the current offset in a FILE. *******************************************************************************/ #include -extern "C" int fseeko(FILE* fp, off_t offset, int whence) +int fseeko(FILE* fp, off_t offset, int whence) { flockfile(fp); int ret = fseeko_unlocked(fp, offset, whence); diff --git a/libc/stdio/fseeko_unlocked.cpp b/libc/stdio/fseeko_unlocked.c similarity index 92% rename from libc/stdio/fseeko_unlocked.cpp rename to libc/stdio/fseeko_unlocked.c index 0be5a706..44ca5c77 100644 --- a/libc/stdio/fseeko_unlocked.cpp +++ b/libc/stdio/fseeko_unlocked.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 . - stdio/fseeko_unlocked.cpp + stdio/fseeko_unlocked.c Changes the current offset in a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fseeko_unlocked(FILE* fp, off_t offset, int whence) +int fseeko_unlocked(FILE* fp, off_t offset, int whence) { if ( !fp->seek_func ) return errno = EBADF, -1; diff --git a/libc/stdio/fsetpos.cpp b/libc/stdio/fsetpos.c similarity index 92% rename from libc/stdio/fsetpos.cpp rename to libc/stdio/fsetpos.c index d613958d..8858cf64 100644 --- a/libc/stdio/fsetpos.cpp +++ b/libc/stdio/fsetpos.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 . - stdio/fsetpos.cpp + stdio/fsetpos.c Set current file position. *******************************************************************************/ #include -extern "C" int fsetpos(FILE* restrict fp, const fpos_t* restrict pos) +int fsetpos(FILE* restrict fp, const fpos_t* restrict pos) { if ( fseeko(fp, *pos, SEEK_SET) < 0 ) return -1; diff --git a/libc/stdio/fshutdown.cpp b/libc/stdio/fshutdown.c similarity index 96% rename from libc/stdio/fshutdown.cpp rename to libc/stdio/fshutdown.c index e874eb04..736e18eb 100644 --- a/libc/stdio/fshutdown.cpp +++ b/libc/stdio/fshutdown.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 . - stdio/fshutdown.cpp + stdio/fshutdown.c Uninstalls the backend from a FILE so another can be reinstalled. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int fshutdown(FILE* fp) +int fshutdown(FILE* fp) { int ret = fp->fflush_indirect ? fp->fflush_indirect(fp) : 0; if ( ret ) diff --git a/libc/stdio/ftell.cpp b/libc/stdio/ftell.c similarity index 95% rename from libc/stdio/ftell.cpp rename to libc/stdio/ftell.c index 678ddb53..22a99a84 100644 --- a/libc/stdio/ftell.cpp +++ b/libc/stdio/ftell.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 . - stdio/ftell.cpp + stdio/ftell.c Returns the current offset of a FILE. *******************************************************************************/ #include -extern "C" long ftell(FILE* fp) +long ftell(FILE* fp) { return (long) ftello(fp); } diff --git a/libc/stdio/ftello.cpp b/libc/stdio/ftello.c similarity index 95% rename from libc/stdio/ftello.cpp rename to libc/stdio/ftello.c index 873a0a1d..af264998 100644 --- a/libc/stdio/ftello.cpp +++ b/libc/stdio/ftello.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 . - stdio/ftello.cpp + stdio/ftello.c Returns the current offset of a FILE. *******************************************************************************/ #include -extern "C" off_t ftello(FILE* fp) +off_t ftello(FILE* fp) { flockfile(fp); off_t ret = ftello_unlocked(fp); diff --git a/libc/stdio/ftello_unlocked.cpp b/libc/stdio/ftello_unlocked.c similarity index 95% rename from libc/stdio/ftello_unlocked.cpp rename to libc/stdio/ftello_unlocked.c index d922b136..35e05030 100644 --- a/libc/stdio/ftello_unlocked.cpp +++ b/libc/stdio/ftello_unlocked.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 . - stdio/ftello_unlocked.cpp + stdio/ftello_unlocked.c Returns the current offset of a FILE. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" off_t ftello_unlocked(FILE* fp) +off_t ftello_unlocked(FILE* fp) { if ( !fp->seek_func ) return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, -1; diff --git a/libc/stdio/ftrylockfile.cpp b/libc/stdio/ftrylockfile.c similarity index 94% rename from libc/stdio/ftrylockfile.cpp rename to libc/stdio/ftrylockfile.c index 33e149b1..cce1343b 100644 --- a/libc/stdio/ftrylockfile.cpp +++ b/libc/stdio/ftrylockfile.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 . - stdio/ftrylockfile.cpp + stdio/ftrylockfile.c Attemps to lock a FILE to the current thread. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int ftrylockfile(FILE* fp) +int ftrylockfile(FILE* fp) { return pthread_mutex_lock(&fp->file_lock) ? -1 : 0; } diff --git a/libc/stdio/funlockfile.cpp b/libc/stdio/funlockfile.c similarity index 94% rename from libc/stdio/funlockfile.cpp rename to libc/stdio/funlockfile.c index 7d86e59a..7394fe77 100644 --- a/libc/stdio/funlockfile.cpp +++ b/libc/stdio/funlockfile.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 . - stdio/funlockfile.cpp + stdio/funlockfile.c Unlocks a thread object so another thread can lock it. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void funlockfile(FILE* fp) +void funlockfile(FILE* fp) { pthread_mutex_unlock(&fp->file_lock); } diff --git a/libc/stdio/funregister.cpp b/libc/stdio/funregister.c similarity index 95% rename from libc/stdio/funregister.cpp rename to libc/stdio/funregister.c index 5613d910..ad3a4a24 100644 --- a/libc/stdio/funregister.cpp +++ b/libc/stdio/funregister.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 . - stdio/funregister.cpp + stdio/funregister.c Unregisters a FILE in the global list of open FILEs. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void funregister(FILE* fp) +void funregister(FILE* fp) { if ( !(fp->flags & _FILE_REGISTERED) ) return; diff --git a/libc/stdio/fwrite.cpp b/libc/stdio/fwrite.c similarity index 91% rename from libc/stdio/fwrite.cpp rename to libc/stdio/fwrite.c index c8177b29..2889b0fe 100644 --- a/libc/stdio/fwrite.cpp +++ b/libc/stdio/fwrite.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 . - stdio/fwrite.cpp + stdio/fwrite.c Writes data to a FILE. *******************************************************************************/ #include -extern "C" size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* fp) +size_t fwrite(const void* ptr, size_t size, size_t nmemb, FILE* fp) { flockfile(fp); size_t ret = fwrite_unlocked(ptr, size, nmemb, fp); diff --git a/libc/stdio/fwrite_unlocked.cpp b/libc/stdio/fwrite_unlocked.c similarity index 98% rename from libc/stdio/fwrite_unlocked.cpp rename to libc/stdio/fwrite_unlocked.c index 17d712e1..3a24efd1 100644 --- a/libc/stdio/fwrite_unlocked.cpp +++ b/libc/stdio/fwrite_unlocked.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 . - stdio/fwrite_unlocked.cpp + stdio/fwrite_unlocked.c Writes data to a FILE. *******************************************************************************/ @@ -29,7 +29,6 @@ #include #include -extern "C" size_t fwrite_unlocked(const void* ptr, size_t element_size, size_t num_elements, diff --git a/libc/stdio/getc.cpp b/libc/stdio/getc.c similarity index 95% rename from libc/stdio/getc.cpp rename to libc/stdio/getc.c index 7f6bff05..409457b4 100644 --- a/libc/stdio/getc.cpp +++ b/libc/stdio/getc.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 . - stdio/getc.cpp + stdio/getc.c Reads a single character from a FILE. *******************************************************************************/ #include -extern "C" int getc(FILE* fp) +int getc(FILE* fp) { flockfile(fp); int ret = getc_unlocked(fp); diff --git a/libc/stdio/getc_unlocked.cpp b/libc/stdio/getc_unlocked.c similarity index 94% rename from libc/stdio/getc_unlocked.cpp rename to libc/stdio/getc_unlocked.c index 85c055ac..edbdf024 100644 --- a/libc/stdio/getc_unlocked.cpp +++ b/libc/stdio/getc_unlocked.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 . - stdio/getc_unlocked.cpp + stdio/getc_unlocked.c Reads a single character from a FILE. *******************************************************************************/ #include -extern "C" int getc_unlocked(FILE* fp) +int getc_unlocked(FILE* fp) { return fgetc_unlocked(fp); } diff --git a/libc/stdio/getchar.cpp b/libc/stdio/getchar.c similarity index 95% rename from libc/stdio/getchar.cpp rename to libc/stdio/getchar.c index ee70a13f..d37949cb 100644 --- a/libc/stdio/getchar.cpp +++ b/libc/stdio/getchar.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 . - stdio/getchar.cpp + stdio/getchar.c Reads a character from stdin. *******************************************************************************/ #include -extern "C" int getchar(void) +int getchar(void) { flockfile(stdin); int ret = getchar_unlocked(); diff --git a/libc/stdio/getchar_unlocked.cpp b/libc/stdio/getchar_unlocked.c similarity index 93% rename from libc/stdio/getchar_unlocked.cpp rename to libc/stdio/getchar_unlocked.c index 2c0a1747..a12cd24c 100644 --- a/libc/stdio/getchar_unlocked.cpp +++ b/libc/stdio/getchar_unlocked.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 . - stdio/getchar_unlocked.cpp + stdio/getchar_unlocked.c Reads a character from stdin. *******************************************************************************/ #include -extern "C" int getchar_unlocked(void) +int getchar_unlocked(void) { return fgetc_unlocked(stdin); } diff --git a/libc/stdio/getdelim.cpp b/libc/stdio/getdelim.c similarity index 95% rename from libc/stdio/getdelim.cpp rename to libc/stdio/getdelim.c index 1dfe5d88..e9da4266 100644 --- a/libc/stdio/getdelim.cpp +++ b/libc/stdio/getdelim.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 . - stdio/getdelim.cpp + stdio/getdelim.c Delimited string input. *******************************************************************************/ @@ -31,7 +31,7 @@ static const size_t DEFAULT_BUFSIZE = 32UL; -extern "C" ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* fp) +ssize_t getdelim(char** lineptr, size_t* n, int delim, FILE* fp) { int err = EINVAL; flockfile(fp); diff --git a/libc/stdio/getline.cpp b/libc/stdio/getline.c similarity index 92% rename from libc/stdio/getline.cpp rename to libc/stdio/getline.c index 637020c9..233f77f8 100644 --- a/libc/stdio/getline.cpp +++ b/libc/stdio/getline.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 . - stdio/getline.cpp + stdio/getline.c Reads a line from a FILE. *******************************************************************************/ #include -extern "C" ssize_t getline(char** lineptr, size_t* n, FILE* fp) +ssize_t getline(char** lineptr, size_t* n, FILE* fp) { return getdelim(lineptr, n, '\n', fp); } diff --git a/libc/stdio/open_memstream.cpp b/libc/stdio/open_memstream.c similarity index 97% rename from libc/stdio/open_memstream.cpp rename to libc/stdio/open_memstream.c index f223c7a3..ac138f91 100644 --- a/libc/stdio/open_memstream.cpp +++ b/libc/stdio/open_memstream.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 . - libc/stdio/open_memstream.cpp + libc/stdio/open_memstream.c Open a memory stream. *******************************************************************************/ @@ -94,7 +94,7 @@ static off_t memstream_seek(void* ms_ptr, off_t offset, int whence) return (off_t) (ms->offset = (size_t) (base + offset)); } -extern "C" FILE* open_memstream(char** string_out, size_t* used_out) +FILE* open_memstream(char** string_out, size_t* used_out) { char* string = (char*) malloc(1); if ( !string ) diff --git a/libc/stdio/perror.cpp b/libc/stdio/perror.c similarity index 95% rename from libc/stdio/perror.cpp rename to libc/stdio/perror.c index bc350ae0..70dc4345 100644 --- a/libc/stdio/perror.cpp +++ b/libc/stdio/perror.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 . - stdio/perror.cpp + stdio/perror.c Prints a error messages to the terminal. *******************************************************************************/ #include -extern "C" void perror(const char* s) +void perror(const char* s) { if ( s && s[0] ) fprintf(stderr, "%s: %m\n", s); diff --git a/libc/stdio/popen.cpp b/libc/stdio/popen.c similarity index 94% rename from libc/stdio/popen.cpp rename to libc/stdio/popen.c index e5881792..b189b76f 100644 --- a/libc/stdio/popen.cpp +++ b/libc/stdio/popen.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 . - stdio/popen.cpp + stdio/popen.c Pipe stream to or from a process. *******************************************************************************/ @@ -27,9 +27,10 @@ #include #include +#include +#include #include #include -#include #include typedef struct popen_struct @@ -51,8 +52,11 @@ static ssize_t popen_write(void* user, const void* ptr, size_t size) return write(info->fd, ptr, size); } -static off_t popen_seek(void* /*user*/, off_t /*offset*/, int /*whence*/) +static off_t popen_seek(void* user, off_t offset, int whence) { + (void) user; + (void) offset; + (void) whence; return errno = ESPIPE, -1; } @@ -79,7 +83,7 @@ static void popen_install(FILE* fp, popen_t* info) fp->close_func = popen_close; } -extern "C" FILE* popen(const char* command, const char* type) +FILE* popen(const char* command, const char* type) { int mode_flags = fparsemode(type); if ( mode_flags < 0 ) @@ -146,7 +150,7 @@ cleanup_out: return NULL; } -extern "C" int pclose(FILE* fp) +int pclose(FILE* fp) { return fclose(fp); } diff --git a/libc/stdio/printf.cpp b/libc/stdio/printf.c similarity index 93% rename from libc/stdio/printf.cpp rename to libc/stdio/printf.c index 1e2d3cad..0cf3c33c 100644 --- a/libc/stdio/printf.cpp +++ b/libc/stdio/printf.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 . - stdio/printf.cpp + stdio/printf.c Prints a string to stdout. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int printf(const char* restrict format, ...) +int printf(const char* restrict format, ...) { va_list list; va_start(list, format); diff --git a/libc/stdio/putc.cpp b/libc/stdio/putc.c similarity index 95% rename from libc/stdio/putc.cpp rename to libc/stdio/putc.c index 8a9f40d6..7ef24ffd 100644 --- a/libc/stdio/putc.cpp +++ b/libc/stdio/putc.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 . - stdio/putc.cpp + stdio/putc.c Writes a character to a FILE. *******************************************************************************/ #include -extern "C" int putc(int c, FILE* fp) +int putc(int c, FILE* fp) { flockfile(fp); int ret = putc_unlocked(c, fp); diff --git a/libc/stdio/putc_unlocked.cpp b/libc/stdio/putc_unlocked.c similarity index 93% rename from libc/stdio/putc_unlocked.cpp rename to libc/stdio/putc_unlocked.c index 888e163e..7ed00fb4 100644 --- a/libc/stdio/putc_unlocked.cpp +++ b/libc/stdio/putc_unlocked.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 . - stdio/putc_unlocked.cpp + stdio/putc_unlocked.c Writes a character to a FILE. *******************************************************************************/ #include -extern "C" int putc_unlocked(int c, FILE* fp) +int putc_unlocked(int c, FILE* fp) { return fputc_unlocked(c, fp); } diff --git a/libc/stdio/putchar.cpp b/libc/stdio/putchar.c similarity index 95% rename from libc/stdio/putchar.cpp rename to libc/stdio/putchar.c index bbdd4353..d6aef068 100644 --- a/libc/stdio/putchar.cpp +++ b/libc/stdio/putchar.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 . - stdio/putchar.cpp + stdio/putchar.c Writes a character to stdout. *******************************************************************************/ #include -extern "C" int putchar(int c) +int putchar(int c) { flockfile(stdin); int ret = putchar_unlocked(c); diff --git a/libc/stdio/putchar_unlocked.cpp b/libc/stdio/putchar_unlocked.c similarity index 93% rename from libc/stdio/putchar_unlocked.cpp rename to libc/stdio/putchar_unlocked.c index 9286cc50..3bee653d 100644 --- a/libc/stdio/putchar_unlocked.cpp +++ b/libc/stdio/putchar_unlocked.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 . - stdio/putchar_unlocked.cpp + stdio/putchar_unlocked.c Writes a character to stdout. *******************************************************************************/ #include -extern "C" int putchar_unlocked(int c) +int putchar_unlocked(int c) { return fputc_unlocked(c, stdout); } diff --git a/libc/stdio/puts.cpp b/libc/stdio/puts.c similarity index 95% rename from libc/stdio/puts.cpp rename to libc/stdio/puts.c index 5027e67d..3cc79af1 100644 --- a/libc/stdio/puts.cpp +++ b/libc/stdio/puts.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 . - stdio/puts.cpp + stdio/puts.c Write a string and newline to stdout. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int puts(const char* str) +int puts(const char* str) { int ret = 0; flockfile(stdout); diff --git a/libc/stdio/remove.cpp b/libc/stdio/remove.c similarity index 94% rename from libc/stdio/remove.cpp rename to libc/stdio/remove.c index 9c505b12..aad1b2be 100644 --- a/libc/stdio/remove.cpp +++ b/libc/stdio/remove.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 . - stdio/remove.cpp + stdio/remove.c Remove a file or directory. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int remove(const char* path) +int remove(const char* path) { return removeat(AT_FDCWD, path); } diff --git a/libc/stdio/removeat.cpp b/libc/stdio/removeat.c similarity index 93% rename from libc/stdio/removeat.cpp rename to libc/stdio/removeat.c index 24cd851d..cc230f93 100644 --- a/libc/stdio/removeat.cpp +++ b/libc/stdio/removeat.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 . - stdio/removeat.cpp + stdio/removeat.c Remove a file or directory. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int removeat(int dirfd, const char* path) +int removeat(int dirfd, const char* path) { return unlinkat(dirfd, path, AT_REMOVEDIR | AT_REMOVEFILE); } diff --git a/libc/stdio/rename.cpp b/libc/stdio/rename.c similarity index 92% rename from libc/stdio/rename.cpp rename to libc/stdio/rename.c index 085507f8..9baf78f7 100644 --- a/libc/stdio/rename.cpp +++ b/libc/stdio/rename.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 . - stdio/rename.cpp + stdio/rename.c Moves a directory entry within the same file system. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int rename(const char* oldname, const char* newname) +int rename(const char* oldname, const char* newname) { return renameat(AT_FDCWD, oldname, AT_FDCWD, newname); } diff --git a/libc/stdio/renameat.cpp b/libc/stdio/renameat.c similarity index 89% rename from libc/stdio/renameat.cpp rename to libc/stdio/renameat.c index e9e1dcc9..33373ed8 100644 --- a/libc/stdio/renameat.cpp +++ b/libc/stdio/renameat.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 . - stdio/renameat.cpp + stdio/renameat.c Moves a directory entry within the same file system. *******************************************************************************/ @@ -29,8 +29,7 @@ DEFN_SYSCALL4(int, sys_renameat, SYSCALL_RENAMEAT, int, const char*, int, const char*); -extern "C" int renameat(int olddir, const char* oldname, int newdir, - const char* newname) +int renameat(int olddir, const char* oldname, int newdir, const char* newname) { return sys_renameat(olddir, oldname, newdir, newname); } diff --git a/libc/stdio/rewind.cpp b/libc/stdio/rewind.c similarity index 95% rename from libc/stdio/rewind.cpp rename to libc/stdio/rewind.c index 08c0e930..3a65e990 100644 --- a/libc/stdio/rewind.cpp +++ b/libc/stdio/rewind.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 . - stdio/rewind.cpp + stdio/rewind.c Sets the offset of a FILE to the start and clears any error condition. *******************************************************************************/ #include -extern "C" void rewind(FILE* fp) +void rewind(FILE* fp) { flockfile(fp); fseeko_unlocked(fp, 0, SEEK_SET); diff --git a/libc/stdio/scanf.cpp b/libc/stdio/scanf.c similarity index 94% rename from libc/stdio/scanf.cpp rename to libc/stdio/scanf.c index 2facd6c9..9c5d36f5 100644 --- a/libc/stdio/scanf.cpp +++ b/libc/stdio/scanf.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 . - stdio/scanf.cpp + stdio/scanf.c Input format conversion. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int scanf(const char* format, ...) +int scanf(const char* format, ...) { va_list ap; va_start(ap, format); diff --git a/libc/stdio/setbuf.cpp b/libc/stdio/setbuf.c similarity index 95% rename from libc/stdio/setbuf.cpp rename to libc/stdio/setbuf.c index 25c6778d..70f8d9c4 100644 --- a/libc/stdio/setbuf.cpp +++ b/libc/stdio/setbuf.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 . - stdio/setbuf.cpp + stdio/setbuf.c Sets up buffering semantics for a FILE. *******************************************************************************/ @@ -28,7 +28,7 @@ // TODO: This function just be removed as setvbuf provides a superior interface, // however it's currently defined in C89, C99 and C11 - so removing it // is non-standard - and this little file doesn't hurt anyone. :-) -extern "C" void setbuf(FILE* fp, char* buf) +void setbuf(FILE* fp, char* buf) { setvbuf(fp, buf, buf ? _IOFBF : _IONBF, BUFSIZ); } diff --git a/libc/stdio/setvbuf.cpp b/libc/stdio/setvbuf.c similarity index 92% rename from libc/stdio/setvbuf.cpp rename to libc/stdio/setvbuf.c index 9d5c71df..bdca0289 100644 --- a/libc/stdio/setvbuf.cpp +++ b/libc/stdio/setvbuf.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 . - stdio/setvbuf.cpp + stdio/setvbuf.c Sets up buffering semantics for a FILE. *******************************************************************************/ #include -extern "C" int setvbuf(FILE* fp, char* buf, int mode, size_t size) +int setvbuf(FILE* fp, char* buf, int mode, size_t size) { flockfile(fp); int ret = setvbuf_unlocked(fp, buf, mode, size); diff --git a/libc/stdio/setvbuf_unlocked.cpp b/libc/stdio/setvbuf_unlocked.c similarity index 91% rename from libc/stdio/setvbuf_unlocked.cpp rename to libc/stdio/setvbuf_unlocked.c index 9ca99585..ee4ba935 100644 --- a/libc/stdio/setvbuf_unlocked.cpp +++ b/libc/stdio/setvbuf_unlocked.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 . - stdio/setvbuf_unlocked.cpp + stdio/setvbuf_unlocked.c Sets up buffering semantics for a FILE. *******************************************************************************/ @@ -26,13 +26,13 @@ #include #include -extern "C" int setvbuf_unlocked(FILE* fp, char* buf, int mode, size_t size) +int setvbuf_unlocked(FILE* fp, char* buf, int mode, size_t size) { (void) buf; (void) size; if ( mode == -1 ) { -#if defined(__is_sortix_kernel) +#ifdef __is_sortix_libk mode = _IOLBF; #else mode = _IOFBF; diff --git a/libc/stdio/snprintf.cpp b/libc/stdio/snprintf.c similarity index 97% rename from libc/stdio/snprintf.cpp rename to libc/stdio/snprintf.c index d0ed7847..7f3fe94b 100644 --- a/libc/stdio/snprintf.cpp +++ b/libc/stdio/snprintf.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 . - stdio/snprintf.cpp + stdio/snprintf.c Prints a formatted string to the supplied buffer. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int snprintf(char* restrict str, size_t size, const char* restrict format, ...) { va_list list; diff --git a/libc/stdio/sprintf.cpp b/libc/stdio/sprintf.c similarity index 92% rename from libc/stdio/sprintf.cpp rename to libc/stdio/sprintf.c index 046c86fe..6c1e0c4b 100644 --- a/libc/stdio/sprintf.cpp +++ b/libc/stdio/sprintf.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 . - stdio/sprintf.cpp + stdio/sprintf.c Prints a formatted string to the supplied buffer. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int sprintf(char* restrict str, const char* restrict format, ...) +int sprintf(char* restrict str, const char* restrict format, ...) { va_list list; va_start(list, format); diff --git a/libc/stdio/sscanf.cpp b/libc/stdio/sscanf.c similarity index 93% rename from libc/stdio/sscanf.cpp rename to libc/stdio/sscanf.c index f74aa03f..b60fd7c1 100644 --- a/libc/stdio/sscanf.cpp +++ b/libc/stdio/sscanf.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 . - stdio/sscanf.cpp + stdio/sscanf.c Input format conversion. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int sscanf(const char* str, const char* format, ...) +int sscanf(const char* str, const char* format, ...) { va_list ap; va_start(ap, format); diff --git a/libc/stdio/stderr.cpp b/libc/stdio/stderr.c similarity index 91% rename from libc/stdio/stderr.cpp rename to libc/stdio/stderr.c index d353cfa2..b43dfac6 100644 --- a/libc/stdio/stderr.cpp +++ b/libc/stdio/stderr.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 . - stdio/stderr.cpp + stdio/stderr.c Standard error. *******************************************************************************/ @@ -27,7 +27,7 @@ #include "fdio.h" -static FILE stderr_file +static FILE stderr_file = { /* buffer = */ NULL, /* user = */ &stderr_file, @@ -49,5 +49,5 @@ static FILE stderr_file /* amount_output_buffered = */ 0, }; -extern "C" { FILE* const stderr = &stderr_file; } -extern "C" { FILE* volatile __stderr_used = &stderr_file; } +FILE* const stderr = &stderr_file; +FILE* volatile __stderr_used = &stderr_file; diff --git a/libc/stdio/stdin.cpp b/libc/stdio/stdin.c similarity index 92% rename from libc/stdio/stdin.cpp rename to libc/stdio/stdin.c index 3dda2220..94b9a62e 100644 --- a/libc/stdio/stdin.cpp +++ b/libc/stdio/stdin.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 . - stdio/stdin.cpp + stdio/stdin.c Standard input. *******************************************************************************/ @@ -50,5 +50,5 @@ static FILE stdin_file = /* amount_output_buffered = */ 0, }; -extern "C" { FILE* const stdin = &stdin_file; } -extern "C" { FILE* volatile __stdin_used = &stdin_file; } +FILE* const stdin = &stdin_file; +FILE* volatile __stdin_used = &stdin_file; diff --git a/libc/stdio/stdout.cpp b/libc/stdio/stdout.c similarity index 91% rename from libc/stdio/stdout.cpp rename to libc/stdio/stdout.c index 6a61c249..39fd7a4d 100644 --- a/libc/stdio/stdout.cpp +++ b/libc/stdio/stdout.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 . - stdio/stdout.cpp + stdio/stdout.c Standard output. *******************************************************************************/ @@ -28,7 +28,7 @@ #include "fdio.h" static unsigned char stdout_buffer[BUFSIZ]; -static FILE stdout_file +static FILE stdout_file = { /* buffer = */ stdout_buffer, /* user = */ &stdout_file, @@ -50,5 +50,5 @@ static FILE stdout_file /* amount_output_buffered = */ 0, }; -extern "C" { FILE* const stdout = &stdout_file; } -extern "C" { FILE* volatile __stdout_used = &stdout_file; } +FILE* const stdout = &stdout_file; +FILE* volatile __stdout_used = &stdout_file; diff --git a/libc/stdio/tmpfile.cpp b/libc/stdio/tmpfile.c similarity index 96% rename from libc/stdio/tmpfile.cpp rename to libc/stdio/tmpfile.c index 17c53db0..5dc57dc1 100644 --- a/libc/stdio/tmpfile.cpp +++ b/libc/stdio/tmpfile.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 . - stdio/tmpfile.cpp + stdio/tmpfile.c Opens an unnamed temporary file. *******************************************************************************/ @@ -28,7 +28,7 @@ #include #include -extern "C" FILE* tmpfile() +FILE* tmpfile(void) { // TODO: There is a short interval during which other processes can access // this file. Implement and use O_TMPFILE. diff --git a/libc/stdio/ungetc.cpp b/libc/stdio/ungetc.c similarity index 95% rename from libc/stdio/ungetc.cpp rename to libc/stdio/ungetc.c index 6f97c4e4..aa6ebbbe 100644 --- a/libc/stdio/ungetc.cpp +++ b/libc/stdio/ungetc.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 . - stdio/ungetc.cpp + stdio/ungetc.c Inserts data in front of the current read queue, allowing applications to peek the incoming data and pretend they didn't. @@ -25,7 +25,7 @@ #include -extern "C" int ungetc(int c, FILE* fp) +int ungetc(int c, FILE* fp) { flockfile(fp); int ret = ungetc_unlocked(c, fp); diff --git a/libc/stdio/ungetc_unlocked.cpp b/libc/stdio/ungetc_unlocked.c similarity index 96% rename from libc/stdio/ungetc_unlocked.cpp rename to libc/stdio/ungetc_unlocked.c index dd839085..b45565fc 100644 --- a/libc/stdio/ungetc_unlocked.cpp +++ b/libc/stdio/ungetc_unlocked.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 . - stdio/ungetc_unlocked.cpp + stdio/ungetc_unlocked.c Inserts data in front of the current read queue, allowing applications to peek the incoming data and pretend they didn't. @@ -27,7 +27,7 @@ #include #include -extern "C" int ungetc_unlocked(int c, FILE* fp) +int ungetc_unlocked(int c, FILE* fp) { if ( c == EOF ) return EOF; diff --git a/libc/stdio/vasprintf.cpp b/libc/stdio/vasprintf.c similarity index 98% rename from libc/stdio/vasprintf.cpp rename to libc/stdio/vasprintf.c index 914b2b86..91c9a9c3 100644 --- a/libc/stdio/vasprintf.cpp +++ b/libc/stdio/vasprintf.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 . - stdio/vasprintf.cpp + stdio/vasprintf.c Prints a string to a newly allocated buffer. *******************************************************************************/ @@ -59,7 +59,6 @@ static size_t vasprintf_callback(void* ctx, const char* string, size_t length) return length; } -extern "C" int vasprintf(char** restrict result_ptr, const char* restrict format, va_list list) diff --git a/libc/stdio/vcbprintf.cpp b/libc/stdio/vcbprintf.c similarity index 98% rename from libc/stdio/vcbprintf.cpp rename to libc/stdio/vcbprintf.c index 026df172..ed692c14 100644 --- a/libc/stdio/vcbprintf.cpp +++ b/libc/stdio/vcbprintf.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 . - stdio/vcbprintf.cpp + stdio/vcbprintf.c Formats text and outputs it via callback functions. *******************************************************************************/ #include #include +#include #include #include #include @@ -46,12 +47,13 @@ static size_t convert_integer(char* destination, uintmax_t value, return result; } -static size_t noop_callback(void*, const char*, size_t amount) +static size_t noop_callback(void* ctx, const char* str, size_t amount) { + (void) ctx; + (void) str; return amount; } -extern "C" int vcbprintf(void* ctx, size_t (*callback)(void*, const char*, size_t), const char* format, @@ -67,8 +69,9 @@ int vcbprintf(void* ctx, { if ( *format != '%' ) { + size_t amount; print_c: - size_t amount = 1; + amount = 1; while ( format[amount] && format[amount] != '%' ) amount++; if ( callback(ctx, format, amount) != amount ) @@ -208,7 +211,7 @@ int vcbprintf(void* ctx, uintmax_t value; if ( conversion == 'p' ) { - value = (uintmax_t) va_arg(parameters, void*); + value = (uintptr_t) va_arg(parameters, void*); conversion = 'x'; alternate = !alternate; prepend_blank_if_positive = false; @@ -347,7 +350,7 @@ int vcbprintf(void* ctx, } } } -#if !defined(__is_sortix_kernel) +#ifndef __is_sortix_libk else if ( *format == 'e' || *format == 'E' || *format == 'f' || *format == 'F' || *format == 'g' || *format == 'G' || diff --git a/libc/stdio/vdprintf.cpp b/libc/stdio/vdprintf.c similarity index 93% rename from libc/stdio/vdprintf.cpp rename to libc/stdio/vdprintf.c index 85fba1a1..680c240f 100644 --- a/libc/stdio/vdprintf.cpp +++ b/libc/stdio/vdprintf.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 . - stdio/vdprintf.cpp + stdio/vdprintf.c Prints a formatted string to a file descriptor. *******************************************************************************/ @@ -33,7 +33,7 @@ static size_t vdprintf_callback(void* fdptr, const char* string, size_t length) return writeall(*(int*) fdptr, string, length); } -extern "C" int vdprintf(int fd, const char* restrict format, va_list list) +int vdprintf(int fd, const char* restrict format, va_list list) { return vcbprintf(&fd, vdprintf_callback, format, list); } diff --git a/libc/stdio/vfprintf.cpp b/libc/stdio/vfprintf.c similarity index 92% rename from libc/stdio/vfprintf.cpp rename to libc/stdio/vfprintf.c index 7f198117..1a8feb86 100644 --- a/libc/stdio/vfprintf.cpp +++ b/libc/stdio/vfprintf.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 . - stdio/vfprintf.cpp + stdio/vfprintf.c Prints a string to a FILE. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int vfprintf(FILE* fp, const char* restrict format, va_list list) +int vfprintf(FILE* fp, const char* restrict format, va_list list) { flockfile(fp); int ret = vfprintf_unlocked(fp, format, list); diff --git a/libc/stdio/vfprintf_unlocked.cpp b/libc/stdio/vfprintf_unlocked.c similarity index 97% rename from libc/stdio/vfprintf_unlocked.cpp rename to libc/stdio/vfprintf_unlocked.c index bb07e21e..dc546111 100644 --- a/libc/stdio/vfprintf_unlocked.cpp +++ b/libc/stdio/vfprintf_unlocked.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 . - stdio/vfprintf_unlocked.cpp + stdio/vfprintf_unlocked.c Prints a string to a FILE. *******************************************************************************/ @@ -32,7 +32,6 @@ static size_t vfprintf_callback(void* ctx, const char* string, size_t length) return fwrite_unlocked(string, 1, length, (FILE*) ctx); } -extern "C" int vfprintf_unlocked(FILE* fp, const char* restrict format, va_list list) { if ( !(fp->flags & _FILE_WRITABLE) ) diff --git a/libc/stdio/vfscanf.cpp b/libc/stdio/vfscanf.c similarity index 92% rename from libc/stdio/vfscanf.cpp rename to libc/stdio/vfscanf.c index ca23c27b..ba959397 100644 --- a/libc/stdio/vfscanf.cpp +++ b/libc/stdio/vfscanf.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 . - stdio/vfscanf.cpp + stdio/vfscanf.c Input format conversion. *******************************************************************************/ #include -extern "C" int vfscanf(FILE* fp, const char* format, va_list ap) +int vfscanf(FILE* fp, const char* format, va_list ap) { flockfile(fp); int result = vfscanf_unlocked(fp, format, ap); diff --git a/libc/stdio/vfscanf_unlocked.cpp b/libc/stdio/vfscanf_unlocked.c similarity index 92% rename from libc/stdio/vfscanf_unlocked.cpp rename to libc/stdio/vfscanf_unlocked.c index d91119d0..c906c429 100644 --- a/libc/stdio/vfscanf_unlocked.cpp +++ b/libc/stdio/vfscanf_unlocked.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 . - stdio/vfscanf_unlocked.cpp + stdio/vfscanf_unlocked.c Input format conversion. *******************************************************************************/ @@ -35,7 +35,7 @@ static int wrap_ungetc(int c, void* fp) return ungetc_unlocked(c, (FILE*) fp); } -extern "C" int vfscanf_unlocked(FILE* fp, const char* format, va_list ap) +int vfscanf_unlocked(FILE* fp, const char* format, va_list ap) { if ( !(fp->flags & _FILE_READABLE) ) return errno = EBADF, fp->flags |= _FILE_STATUS_ERROR, EOF; diff --git a/libc/stdio/vprintf.cpp b/libc/stdio/vprintf.c similarity index 92% rename from libc/stdio/vprintf.cpp rename to libc/stdio/vprintf.c index 3841863e..ed42129b 100644 --- a/libc/stdio/vprintf.cpp +++ b/libc/stdio/vprintf.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 . - stdio/vprintf.cpp + stdio/vprintf.c Prints a string to stdout. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int vprintf(const char* restrict format, va_list list) +int vprintf(const char* restrict format, va_list list) { return vfprintf(stdout, format, list); } diff --git a/libc/stdio/vscanf.cpp b/libc/stdio/vscanf.c similarity index 93% rename from libc/stdio/vscanf.cpp rename to libc/stdio/vscanf.c index d3a6eb96..21e984dd 100644 --- a/libc/stdio/vscanf.cpp +++ b/libc/stdio/vscanf.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 . - stdio/vscanf.cpp + stdio/vscanf.c Input format conversion. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int vscanf(const char* format, va_list ap) +int vscanf(const char* format, va_list ap) { return vfscanf(stdin, format, ap); } diff --git a/libc/stdio/vscanf_callback.cpp b/libc/stdio/vscanf_callback.c similarity index 96% rename from libc/stdio/vscanf_callback.cpp rename to libc/stdio/vscanf_callback.c index a085d375..37f1e543 100644 --- a/libc/stdio/vscanf_callback.cpp +++ b/libc/stdio/vscanf_callback.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 . - stdio/vscanf_callback.cpp + stdio/vscanf_callback.c Input format conversion. *******************************************************************************/ -#define __STDC_LIMIT_MACROS #include +#include #include +#include #include #include #include -#include enum scanmode { @@ -70,15 +70,12 @@ static int debase(char c, int base) return ret; } -extern "C" int vscanf_callback(void* fp, int (*fgetc)(void*), int (*ungetc)(int, void*), - const char* restrict origformat, + const char* restrict format, va_list ap) { - union { const char* format; const unsigned char* formatuc; }; - format = origformat; int matcheditems = 0; size_t fieldwidth = 0; bool escaped = false; @@ -98,6 +95,7 @@ int vscanf_callback(void* fp, size_t undoable = 0; size_t strwritten = 0; char* strdest = NULL; + char convc; enum scantype scantype = TYPE_INT; enum scanmode scanmode = MODE_INIT; while ( true ) @@ -112,13 +110,13 @@ int vscanf_callback(void* fp, ungetc(ic, fp); goto break_loop; } - if ( isspace(*formatuc) ) + if ( isspace((unsigned char) *format) ) { if ( isspace(ic) ) continue; else do format++; - while ( isspace(*formatuc) ); + while ( isspace((unsigned char) *format) ); } if ( *format == '%' && !escaped ) { @@ -151,7 +149,7 @@ int vscanf_callback(void* fp, case 'z': scantype = TYPE_SIZE; break; } - switch ( char convc = *format++ ) + switch ( (convc = *format++) ) { case '%': escaped = true; diff --git a/libc/stdio/vsnprintf.cpp b/libc/stdio/vsnprintf.c similarity index 98% rename from libc/stdio/vsnprintf.cpp rename to libc/stdio/vsnprintf.c index 118722e1..ee38fee7 100644 --- a/libc/stdio/vsnprintf.cpp +++ b/libc/stdio/vsnprintf.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 . - stdio/vsnprintf.cpp + stdio/vsnprintf.c Prints a formatted string to the supplied buffer. *******************************************************************************/ @@ -46,7 +46,6 @@ static size_t vsnprintf_callback(void* ctx, const char* string, size_t length) return length; } -extern "C" int vsnprintf(char* restrict str, size_t size, const char* restrict format, diff --git a/libc/stdio/vsprintf.cpp b/libc/stdio/vsprintf.c similarity index 97% rename from libc/stdio/vsprintf.cpp rename to libc/stdio/vsprintf.c index 8fc07b2d..36b35c98 100644 --- a/libc/stdio/vsprintf.cpp +++ b/libc/stdio/vsprintf.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 . - stdio/vsprintf.cpp + stdio/vsprintf.c Prints a formatted string to the supplied buffer. *******************************************************************************/ @@ -26,7 +26,6 @@ #include #include -extern "C" int vsprintf(char* restrict str, const char* restrict format, va_list list) { return vsnprintf(str, SIZE_MAX, format, list); diff --git a/libc/stdio/vsscanf.cpp b/libc/stdio/vsscanf.c similarity index 94% rename from libc/stdio/vsscanf.cpp rename to libc/stdio/vsscanf.c index 6061b273..de50f80a 100644 --- a/libc/stdio/vsscanf.cpp +++ b/libc/stdio/vsscanf.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 . - stdio/vsscanf.cpp + stdio/vsscanf.c Input format conversion. *******************************************************************************/ @@ -54,7 +54,7 @@ static int vsscanf_ungetc(int c, void* fp) return c; } -extern "C" int vsscanf(const char* str, const char* format, va_list ap) +int vsscanf(const char* str, const char* format, va_list ap) { struct vsscanf_input input; input.str = str; diff --git a/libc/stdio_ext/__fbufsize.cpp b/libc/stdio_ext/__fbufsize.c similarity index 94% rename from libc/stdio_ext/__fbufsize.cpp rename to libc/stdio_ext/__fbufsize.c index 3f71b750..0538fd56 100644 --- a/libc/stdio_ext/__fbufsize.cpp +++ b/libc/stdio_ext/__fbufsize.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 . - stdio_ext/__fbufsize.cpp + stdio_ext/__fbufsize.c Returns the size of the FILE's buffer. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" size_t __fbufsize(FILE* fp) +size_t __fbufsize(FILE* fp) { flockfile(fp); int mode = fp->buffer_mode; diff --git a/libc/stdio_ext/__fpending.cpp b/libc/stdio_ext/__fpending.c similarity index 94% rename from libc/stdio_ext/__fpending.cpp rename to libc/stdio_ext/__fpending.c index f375acf0..c8e88c42 100644 --- a/libc/stdio_ext/__fpending.cpp +++ b/libc/stdio_ext/__fpending.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 . - stdio_ext/__fpending.cpp + stdio_ext/__fpending.c Returns the number of bytes pending in the output buffer. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" size_t __fpending(FILE* fp) +size_t __fpending(FILE* fp) { flockfile(fp); size_t result = fp->amount_output_buffered; diff --git a/libc/stdio_ext/__fpurge.cpp b/libc/stdio_ext/__fpurge.c similarity index 95% rename from libc/stdio_ext/__fpurge.cpp rename to libc/stdio_ext/__fpurge.c index 785d0673..080b6cd0 100644 --- a/libc/stdio_ext/__fpurge.cpp +++ b/libc/stdio_ext/__fpurge.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 . - stdio_ext/__fpurge.cpp + stdio_ext/__fpurge.c Discards all contents in the FILE's buffer. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void __fpurge(FILE* fp) +void __fpurge(FILE* fp) { flockfile(fp); fp->offset_input_buffer = 0; diff --git a/libc/stdio_ext/__freadable.cpp b/libc/stdio_ext/__freadable.c similarity index 94% rename from libc/stdio_ext/__freadable.cpp rename to libc/stdio_ext/__freadable.c index d37219f6..0d411529 100644 --- a/libc/stdio_ext/__freadable.cpp +++ b/libc/stdio_ext/__freadable.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 . - stdio_ext/__freadable.cpp + stdio_ext/__freadable.c Returns whether this FILE can be read from. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int __freadable(FILE* fp) +int __freadable(FILE* fp) { flockfile(fp); int result = fp->flags & _FILE_READABLE ? 1 : 0; diff --git a/libc/stdio_ext/__freading.cpp b/libc/stdio_ext/__freading.c similarity index 95% rename from libc/stdio_ext/__freading.cpp rename to libc/stdio_ext/__freading.c index d207386d..53899aeb 100644 --- a/libc/stdio_ext/__freading.cpp +++ b/libc/stdio_ext/__freading.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 . - stdio_ext/__freading.cpp + stdio_ext/__freading.c Returns whether the last operation was a read or FILE is read only. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int __freading(FILE* fp) +int __freading(FILE* fp) { int result = 0; flockfile(fp); diff --git a/libc/stdio_ext/__fseterr.cpp b/libc/stdio_ext/__fseterr.c similarity index 94% rename from libc/stdio_ext/__fseterr.cpp rename to libc/stdio_ext/__fseterr.c index 4067d00e..255f8ed8 100644 --- a/libc/stdio_ext/__fseterr.cpp +++ b/libc/stdio_ext/__fseterr.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 . - stdio_ext/__fseterr.cpp + stdio_ext/__fseterr.c Sets the error condition bit on a FILE. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void __fseterr(FILE* fp) +void __fseterr(FILE* fp) { flockfile(fp); fp->flags |= _FILE_STATUS_ERROR; diff --git a/libc/stdio_ext/__fwritable.cpp b/libc/stdio_ext/__fwritable.c similarity index 94% rename from libc/stdio_ext/__fwritable.cpp rename to libc/stdio_ext/__fwritable.c index 93c07036..52130768 100644 --- a/libc/stdio_ext/__fwritable.cpp +++ b/libc/stdio_ext/__fwritable.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 . - stdio_ext/__fwritable.cpp + stdio_ext/__fwritable.c Returns whether this FILE can be written to. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int __fwritable(FILE* fp) +int __fwritable(FILE* fp) { flockfile(fp); int result = fp->flags & _FILE_WRITABLE ? 1 : 0; diff --git a/libc/stdio_ext/__fwriting.cpp b/libc/stdio_ext/__fwriting.c similarity index 95% rename from libc/stdio_ext/__fwriting.cpp rename to libc/stdio_ext/__fwriting.c index d906689c..56b4827c 100644 --- a/libc/stdio_ext/__fwriting.cpp +++ b/libc/stdio_ext/__fwriting.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 . - stdio_ext/__fwriting.cpp + stdio_ext/__fwriting.c Returns whether the last operation was a write or FILE is write only. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int __fwriting(FILE* fp) +int __fwriting(FILE* fp) { int result = 0; flockfile(fp); diff --git a/libc/stdlib/_Exit.cpp b/libc/stdlib/_Exit.c similarity index 95% rename from libc/stdlib/_Exit.cpp rename to libc/stdlib/_Exit.c index fc2c7efa..65d7a2d1 100644 --- a/libc/stdlib/_Exit.cpp +++ b/libc/stdlib/_Exit.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 . - stdlib/_Exit.cpp + stdlib/_Exit.c Terminates the current process. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void _Exit(int status) +void _Exit(int status) { _exit(status); } diff --git a/libc/stdlib/abort.cpp b/libc/stdlib/abort.c similarity index 82% rename from libc/stdlib/abort.cpp rename to libc/stdlib/abort.c index 4194119b..8e150d38 100644 --- a/libc/stdlib/abort.cpp +++ b/libc/stdlib/abort.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 . - stdlib/abort.cpp + stdlib/abort.c Abnormal process termination. *******************************************************************************/ @@ -29,20 +29,15 @@ #include #include -#if defined(__is_sortix_kernel) +#ifdef __is_sortix_libk +#include +#endif -#include -#include - -extern "C" void abort(void) -{ - Sortix::PanicF("abort()"); -} - -#elif __STDC_HOSTED__ - -extern "C" void abort(void) +void abort(void) { +#ifdef __is_sortix_libk + libk_abort(); +#else sigset_t set_of_sigabrt; sigemptyset(&set_of_sigabrt); sigaddset(&set_of_sigabrt, SIGABRT); @@ -55,14 +50,5 @@ extern "C" void abort(void) exit_thread(exit_code, exit_flags, NULL); __builtin_unreachable(); -} - -#else - -extern "C" void abort(void) -{ - while ( true ) { } - __builtin_unreachable(); -} - #endif +} diff --git a/libc/stdlib/abs.cpp b/libc/stdlib/abs.c similarity index 95% rename from libc/stdlib/abs.cpp rename to libc/stdlib/abs.c index 9dd9d1b6..5fc6fbb6 100644 --- a/libc/stdlib/abs.cpp +++ b/libc/stdlib/abs.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 . - stdlib/abs.cpp + stdlib/abs.c Computes the absolute value of an integer. *******************************************************************************/ #include -extern "C" int abs(int val) +int abs(int val) { return val < 0 ? -val : val; } diff --git a/libc/stdlib/arc4random.cpp b/libc/stdlib/arc4random.c similarity index 94% rename from libc/stdlib/arc4random.cpp rename to libc/stdlib/arc4random.c index 15e9d94d..02076d43 100644 --- a/libc/stdlib/arc4random.cpp +++ b/libc/stdlib/arc4random.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 . - stdlib/arc4random.cpp + stdlib/arc4random.c Generate a cryptographically secure 32-bit value. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" uint32_t arc4random(void) +uint32_t arc4random(void) { uint32_t result; arc4random_buf(&result, sizeof(result)); diff --git a/libc/stdlib/arc4random_buf.cpp b/libc/stdlib/arc4random_buf.c similarity index 92% rename from libc/stdlib/arc4random_buf.cpp rename to libc/stdlib/arc4random_buf.c index 3b9c463e..15d12104 100644 --- a/libc/stdlib/arc4random_buf.cpp +++ b/libc/stdlib/arc4random_buf.c @@ -30,26 +30,15 @@ #include #include +#include +#include #include #include #include -#if !defined(__is_sortix_kernel) -#include -#endif #include -#if defined(__is_sortix_kernel) -#include -#include -#endif - -#if defined(__is_sortix_kernel) -#define PTHREAD_MUTEX_INITIALIZER Sortix::KTHREAD_MUTEX_INITIALIZER -#define pthread_mutex_t Sortix::kthread_mutex_t -#define pthread_mutex_lock Sortix::kthread_mutex_lock -#define pthread_mutex_unlock Sortix::kthread_mutex_unlock -#define getpid() 0 -#define getentropy Sortix::Random::GetEntropy +#ifdef __is_sortix_libk +#include #endif struct chacha @@ -161,32 +150,37 @@ void chacha_keystream(struct chacha* ctx, #define KEYSZ 32 #define IVSZ 8 +#ifndef __is_sortix_libk static pthread_mutex_t arc4random_mutex = PTHREAD_MUTEX_INITIALIZER; +#endif /* TODO: Use address space randomization of libc global variables such that these variables end up in unpredictable places. */ static bool rs_initialized = false; +#ifndef __is_sortix_libk static pid_t rs_pid = 0; +#endif static size_t rs_have = 0; static size_t rs_count = 0; static struct chacha rs_chacha; static unsigned char rs_buf[16 * 64]; -extern "C" void arc4random_buf(void* buffer_ptr, size_t size) +void arc4random_buf(void* buffer_ptr, size_t size) { unsigned char* buffer = (unsigned char*) buffer_ptr; - pthread_mutex_lock(&arc4random_mutex); +#ifdef __is_sortix_libk + libk_random_lock(); -#if defined(__is_sortix_kernel) - if ( Sortix::Random::HasEntropy() ) + if ( libk_hasentropy() ) { rs_count = 0; rs_have = 0; memset(rs_buf, 0, sizeof(rs_buf)); } -#endif +#else + pthread_mutex_lock(&arc4random_mutex); /* TODO: Employ zero-memory-on-fork semantics instead. */ /* pid_t are never reused on Sortix at the moment. */ @@ -198,6 +192,7 @@ extern "C" void arc4random_buf(void* buffer_ptr, size_t size) /* TODO: Should rs_chacha be zeroed as well? */ rs_pid = getpid(); } +#endif while ( 0 < size ) { @@ -221,7 +216,11 @@ extern "C" void arc4random_buf(void* buffer_ptr, size_t size) if ( rs_count == 0 ) { unsigned char entropy[KEYSZ + IVSZ]; +#ifdef __is_sortix_libk + libk_getentropy(entropy, sizeof(entropy)); +#else getentropy(entropy, sizeof(entropy)); +#endif if ( rs_initialized ) { @@ -253,5 +252,9 @@ extern "C" void arc4random_buf(void* buffer_ptr, size_t size) } } +#ifdef __is_sortix_libk + libk_random_unlock(); +#else pthread_mutex_unlock(&arc4random_mutex); +#endif } diff --git a/libc/stdlib/arc4random_uniform.cpp b/libc/stdlib/arc4random_uniform.c similarity index 96% rename from libc/stdlib/arc4random_uniform.cpp rename to libc/stdlib/arc4random_uniform.c index cd661490..aa03408e 100644 --- a/libc/stdlib/arc4random_uniform.cpp +++ b/libc/stdlib/arc4random_uniform.c @@ -29,7 +29,7 @@ * [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound) * after reduction modulo upper_bound. */ -extern "C" uint32_t arc4random_uniform(uint32_t upper_bound) +uint32_t arc4random_uniform(uint32_t upper_bound) { uint32_t r, min; diff --git a/libc/stdlib/atexit.cpp b/libc/stdlib/atexit.c similarity index 90% rename from libc/stdlib/atexit.cpp rename to libc/stdlib/atexit.c index 90212d6b..d689f1c5 100644 --- a/libc/stdlib/atexit.cpp +++ b/libc/stdlib/atexit.c @@ -17,19 +17,20 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdlib/atexit.cpp + stdlib/atexit.c Hooks that are called upon process exit. *******************************************************************************/ #include -static void atexit_adapter(int /*status*/, void* user) +static void atexit_adapter(int status, void* user) { + (void) status; ((void (*)(void)) user)(); } -extern "C" int atexit(void (*hook)(void)) +int atexit(void (*hook)(void)) { return on_exit(atexit_adapter, (void*) hook); } diff --git a/libc/stdlib/atof.cpp b/libc/stdlib/atof.c similarity index 92% rename from libc/stdlib/atof.cpp rename to libc/stdlib/atof.c index 80950ddf..2b260f07 100644 --- a/libc/stdlib/atof.cpp +++ b/libc/stdlib/atof.c @@ -17,15 +17,15 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdlib/atof.cpp + stdlib/atof.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ #include -#if !defined(__is_sortix_kernel) -extern "C" double atof(const char* str) +#ifndef __is_sortix_libk +double atof(const char* str) { return strtod(str, NULL); } diff --git a/libc/stdlib/atoi.cpp b/libc/stdlib/atoi.c similarity index 95% rename from libc/stdlib/atoi.cpp rename to libc/stdlib/atoi.c index 46454ee7..61e9d1b2 100644 --- a/libc/stdlib/atoi.cpp +++ b/libc/stdlib/atoi.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 . - stdlib/atoi.cpp + stdlib/atoi.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int atoi(const char* str) +int atoi(const char* str) { long long_result = strtol(str, (char**) NULL, 10); if ( long_result < INT_MIN ) diff --git a/libc/stdlib/atol.cpp b/libc/stdlib/atol.c similarity index 94% rename from libc/stdlib/atol.cpp rename to libc/stdlib/atol.c index cda94620..d3baa60e 100644 --- a/libc/stdlib/atol.cpp +++ b/libc/stdlib/atol.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 . - stdlib/atol.cpp + stdlib/atol.c Converts integers represented as strings to binary representation. *******************************************************************************/ #include -extern "C" long atol(const char* str) +long atol(const char* str) { return strtol(str, (char**) NULL, 10); } diff --git a/libc/stdlib/atoll.cpp b/libc/stdlib/atoll.c similarity index 94% rename from libc/stdlib/atoll.cpp rename to libc/stdlib/atoll.c index 7e648baf..bd741825 100644 --- a/libc/stdlib/atoll.cpp +++ b/libc/stdlib/atoll.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 . - stdlib/atoll.cpp + stdlib/atoll.c Converts integers represented as strings to binary representation. *******************************************************************************/ #include -extern "C" long long atoll(const char* str) +long long atoll(const char* str) { return strtoll(str, (char **) NULL, 10); } diff --git a/libc/stdlib/bsearch.cpp b/libc/stdlib/bsearch.c similarity index 88% rename from libc/stdlib/bsearch.cpp rename to libc/stdlib/bsearch.c index 28ea0b92..4eee3529 100644 --- a/libc/stdlib/bsearch.cpp +++ b/libc/stdlib/bsearch.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 . - stdlib/bsearch.cpp + stdlib/bsearch.c Binary search. *******************************************************************************/ @@ -25,8 +25,8 @@ #include #include -extern "C" void* bsearch(const void* key, const void* base, size_t nmemb, - size_t size, int (*compare)(const void*, const void*)) +void* bsearch(const void* key, const void* base, size_t nmemb, + size_t size, int (*compare)(const void*, const void*)) { const uint8_t* baseptr = (const uint8_t*) base; // TODO: Just a quick and surprisingly correct yet slow implementation. diff --git a/libc/stdlib/calloc.cpp b/libc/stdlib/calloc.c similarity index 94% rename from libc/stdlib/calloc.cpp rename to libc/stdlib/calloc.c index 34b2edb5..e9c508c7 100644 --- a/libc/stdlib/calloc.cpp +++ b/libc/stdlib/calloc.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 . - stdlib/calloc.cpp + stdlib/calloc.c Allocates zeroed memory. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" void* calloc(size_t nmemb, size_t size) +void* calloc(size_t nmemb, size_t size) { if ( size && nmemb && SIZE_MAX / size < nmemb ) return errno = ENOMEM, (void*) NULL; diff --git a/libc/stdlib/canonicalize_file_name.cpp b/libc/stdlib/canonicalize_file_name.c similarity index 91% rename from libc/stdlib/canonicalize_file_name.cpp rename to libc/stdlib/canonicalize_file_name.c index 01d94890..60efed3b 100644 --- a/libc/stdlib/canonicalize_file_name.cpp +++ b/libc/stdlib/canonicalize_file_name.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 . - stdlib/canonicalize_file_name.cpp + stdlib/canonicalize_file_name.c Return the canonicalized filename. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" char* canonicalize_file_name(const char* path) +char* canonicalize_file_name(const char* path) { return canonicalize_file_name_at(AT_FDCWD, path); } diff --git a/libc/stdlib/canonicalize_file_name_at.cpp b/libc/stdlib/canonicalize_file_name_at.c similarity index 98% rename from libc/stdlib/canonicalize_file_name_at.cpp rename to libc/stdlib/canonicalize_file_name_at.c index 6ecdcc44..1825c3af 100644 --- a/libc/stdlib/canonicalize_file_name_at.cpp +++ b/libc/stdlib/canonicalize_file_name_at.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 . - stdlib/canonicalize_file_name_at.cpp + stdlib/canonicalize_file_name_at.c Return the canonicalized filename. *******************************************************************************/ @@ -72,7 +72,7 @@ static const char* SkipSlashes(const char* path) return *path ? path : NULL; } -extern "C" char* canonicalize_file_name_at(int dirfd, const char* path) +char* canonicalize_file_name_at(int dirfd, const char* path) { if ( path && path[0] == '.' && !path[1] ) path = NULL; diff --git a/libc/stdlib/clearenv.cpp b/libc/stdlib/clearenv.c similarity index 96% rename from libc/stdlib/clearenv.cpp rename to libc/stdlib/clearenv.c index f8660835..8b74c18a 100644 --- a/libc/stdlib/clearenv.cpp +++ b/libc/stdlib/clearenv.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 . - stdlib/clearenv.cpp + stdlib/clearenv.c Clear the environment and set environ to NULL. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int clearenv() +int clearenv(void) { if ( environ == __environ_malloced ) { diff --git a/libc/stdlib/div.cpp b/libc/stdlib/div.c similarity index 94% rename from libc/stdlib/div.cpp rename to libc/stdlib/div.c index c7b73e00..775b99d9 100644 --- a/libc/stdlib/div.cpp +++ b/libc/stdlib/div.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 . - stdlib/div.cpp + stdlib/div.c Compute quotient and remainder of integer division. *******************************************************************************/ #include -extern "C" div_t div(int numer, int denom) +div_t div(int numer, int denom) { div_t ret; ret.quot = numer / denom; diff --git a/libc/stdlib/exit.cpp b/libc/stdlib/exit.c similarity index 81% rename from libc/stdlib/exit.cpp rename to libc/stdlib/exit.c index 5fa70644..a7cb4e59 100644 --- a/libc/stdlib/exit.cpp +++ b/libc/stdlib/exit.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 . - stdlib/exit.cpp + stdlib/exit.c Terminates the current process. *******************************************************************************/ @@ -26,23 +26,24 @@ #include #include #include +#include #include #include #include -extern "C" { struct exit_handler* __exit_handler_stack = NULL; } +struct exit_handler* __exit_handler_stack = NULL; static pthread_mutex_t exit_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static bool currently_exiting = false; static FILE* volatile dummy_file = NULL; // volatile due to constant folding bug -weak_alias_cxx(dummy_file, __stdin_used, "_ZL10dummy_file"); -weak_alias_cxx(dummy_file, __stdout_used, "_ZL10dummy_file"); +weak_alias(dummy_file, __stdin_used); +weak_alias(dummy_file, __stdout_used); -extern "C" { DIR* __first_dir = NULL; } -extern "C" { pthread_mutex_t __first_dir_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; } -extern "C" { FILE* __first_file = NULL; } -extern "C" { pthread_mutex_t __first_file_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; } +DIR* __first_dir = NULL; +pthread_mutex_t __first_dir_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; +FILE* __first_file = NULL; +pthread_mutex_t __first_file_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; static void exit_file(FILE* fp) { @@ -55,7 +56,7 @@ static void exit_file(FILE* fp) fp->close_func(fp->user); } -extern "C" void exit(int status) +void exit(int status) { // It's undefined behavior to call this function more than once: If more // than one thread calls the function we'll wait until the process dies. diff --git a/libc/stdlib/free.cpp b/libc/stdlib/free.c similarity index 77% rename from libc/stdlib/free.cpp rename to libc/stdlib/free.c index ddcbc463..90f26fc0 100644 --- a/libc/stdlib/free.cpp +++ b/libc/stdlib/free.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 . - stdlib/free.cpp + stdlib/free.c Returns a chunk of memory to the dynamic memory heap. *******************************************************************************/ @@ -33,7 +33,7 @@ #if !defined(HEAP_GUARD_DEBUG) -extern "C" void free(void* addr) +void free(void* addr) { if ( !addr ) return; @@ -56,28 +56,22 @@ extern "C" void free(void* addr) #else -#if defined(__is_sortix_kernel) -#include -#include -#else #include + +#ifdef __is_sortix_libk +#include #endif -extern "C" void free(void* addr) +void free(void* addr) { if ( !addr ) return; -#if defined(__is_sortix_kernel) - using namespace Sortix; - addralloc_t* alloc_ptr = (addralloc_t*) Page::AlignDown((uintptr_t) addr - 16); - assert(alloc_ptr->from == (uintptr_t) alloc_ptr); - addralloc_t alloc = *alloc_ptr; - Memory::UnmapRange(alloc.from, alloc.size - Page::Size(), PAGE_USAGE_KERNEL_HEAP); - FreeKernelAddress(&alloc); -#else struct heap_alloc* alloc_ptr = (struct heap_alloc*) HEAP_ALIGN_PAGEDOWN((uintptr_t) addr - 16); +#ifdef __is_sortix_libk + libk_munmap((void*) alloc_ptr->from, alloc_ptr->size); +#else munmap((void*) alloc_ptr->from, alloc_ptr->size); #endif } diff --git a/libc/stdlib/getenv.cpp b/libc/stdlib/getenv.c similarity index 96% rename from libc/stdlib/getenv.cpp rename to libc/stdlib/getenv.c index 1e621462..0cd0012f 100644 --- a/libc/stdlib/getenv.cpp +++ b/libc/stdlib/getenv.c @@ -17,12 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdlib/getenv.cpp + stdlib/getenv.c Get an environment variable. *******************************************************************************/ #include +#include #include #include #include @@ -34,7 +35,7 @@ bool matches_environment_variable(const char* what, return !strncmp(what, name, name_length) && what[name_length] == '='; } -extern "C" char* getenv(const char* name) +char* getenv(const char* name) { if ( !name ) return errno = EINVAL, (char*) NULL; diff --git a/libc/stdlib/labs.cpp b/libc/stdlib/labs.c similarity index 94% rename from libc/stdlib/labs.cpp rename to libc/stdlib/labs.c index cf9980c2..5e0bbade 100644 --- a/libc/stdlib/labs.cpp +++ b/libc/stdlib/labs.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 . - stdlib/labs.cpp + stdlib/labs.c Computes the absolute value of an integer. *******************************************************************************/ #include -extern "C" long int labs(long int val) +long int labs(long int val) { return val < 0 ? -val : val; } diff --git a/libc/stdlib/ldiv.cpp b/libc/stdlib/ldiv.c similarity index 94% rename from libc/stdlib/ldiv.cpp rename to libc/stdlib/ldiv.c index f2fb0422..35f35000 100644 --- a/libc/stdlib/ldiv.cpp +++ b/libc/stdlib/ldiv.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 . - stdlib/ldiv.cpp + stdlib/ldiv.c Compute quotient and remainder of integer division. *******************************************************************************/ #include -extern "C" ldiv_t ldiv(long numer, long denom) +ldiv_t ldiv(long numer, long denom) { ldiv_t ret; ret.quot = numer / denom; diff --git a/libc/stdlib/llabs.cpp b/libc/stdlib/llabs.c similarity index 93% rename from libc/stdlib/llabs.cpp rename to libc/stdlib/llabs.c index ca8fdaab..cd997011 100644 --- a/libc/stdlib/llabs.cpp +++ b/libc/stdlib/llabs.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 . - stdlib/llabs.cpp + stdlib/llabs.c Computes the absolute value of an integer. *******************************************************************************/ #include -extern "C" long long int llabs(long long int val) +long long int llabs(long long int val) { return val < 0 ? -val : val; } diff --git a/libc/stdlib/lldiv.cpp b/libc/stdlib/lldiv.c similarity index 93% rename from libc/stdlib/lldiv.cpp rename to libc/stdlib/lldiv.c index 4f23988f..068e3067 100644 --- a/libc/stdlib/lldiv.cpp +++ b/libc/stdlib/lldiv.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 . - stdlib/lldiv.cpp + stdlib/lldiv.c Compute quotient and remainder of integer division. *******************************************************************************/ #include -extern "C" lldiv_t lldiv(long long numer, long long denom) +lldiv_t lldiv(long long numer, long long denom) { lldiv_t ret; ret.quot = numer / denom; diff --git a/libc/stdlib/malloc.cpp b/libc/stdlib/malloc.c similarity index 84% rename from libc/stdlib/malloc.cpp rename to libc/stdlib/malloc.c index 8e687b6c..1a125e86 100644 --- a/libc/stdlib/malloc.cpp +++ b/libc/stdlib/malloc.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 . - stdlib/malloc.cpp + stdlib/malloc.c Allocates a chunk of memory from the dynamic memory heap. *******************************************************************************/ @@ -36,7 +36,7 @@ #if !defined(HEAP_GUARD_DEBUG) -extern "C" void* malloc(size_t original_size) +void* malloc(size_t original_size) { if ( !heap_size_has_bin(original_size) ) return errno = ENOMEM, (void*) NULL; @@ -103,50 +103,38 @@ extern "C" void* malloc(size_t original_size) #else -#if defined(__is_sortix_kernel) -#include -#include -#include -#else #include + +#ifdef __is_sortix_libk +#include #endif -extern "C" void* malloc(size_t original_size) +void* malloc(size_t original_size) { if ( !original_size ) original_size = 1; size_t size = -(-original_size & ~15UL); size_t needed = 16 + size; -#if defined(__is_sortix_kernel) - using namespace Sortix; - needed = Page::AlignUp(needed); - size_t virtsize = needed + Page::Size(); - addralloc_t addralloc; - if ( !AllocateKernelAddress(&addralloc, virtsize) ) - return NULL; - if ( !Memory::MapRange(addralloc.from, addralloc.size - Page::Size(), - PROT_KREAD | PROT_KWRITE, PAGE_USAGE_KERNEL_HEAP) ) - { - FreeKernelAddress(&addralloc); - return NULL; - } - Memory::Flush(); - addralloc_t* addralloc_ptr = (addralloc_t*) (addralloc.from); - *addralloc_ptr = addralloc; -#else needed = HEAP_ALIGN_PAGEUP(needed); size_t virtsize = needed + HEAP_PAGE_SIZE; +#ifdef __is_sortix_libk + void* from = libk_mmap(virtsize, PROT_KREAD | PROT_KWRITE); +#else void* from = mmap(NULL, virtsize, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); +#endif if ( from == MAP_FAILED ) return NULL; void* guard = (char*) from + needed; +#ifdef __is_sortix_libk + libk_mprotect(guard, HEAP_PAGE_SIZE, PROT_NONE); +#else if ( mprotect(guard, HEAP_PAGE_SIZE, PROT_NONE) < 0 ) return munmap(from, virtsize), (void*) NULL; +#endif struct heap_alloc* addralloc_ptr = (struct heap_alloc*) from; addralloc_ptr->from = (uintptr_t) from; addralloc_ptr->size = virtsize; -#endif size_t offset = needed - size; return (void*) (addralloc_ptr->from + offset); } diff --git a/libc/stdlib/mblen.cpp b/libc/stdlib/mblen.c similarity index 95% rename from libc/stdlib/mblen.cpp rename to libc/stdlib/mblen.c index ac88ab2d..d66992df 100644 --- a/libc/stdlib/mblen.cpp +++ b/libc/stdlib/mblen.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 . - stdlib/mblen.cpp + stdlib/mblen.c Determine number of bytes in next multibyte character. *******************************************************************************/ @@ -27,7 +27,7 @@ #include // TODO: This function is unpure and should be removed. -extern "C" int mblen(const char* s, size_t n) +int mblen(const char* s, size_t n) { wchar_t wc; static mbstate_t ps; diff --git a/libc/stdlib/mbstowcs.cpp b/libc/stdlib/mbstowcs.c similarity index 97% rename from libc/stdlib/mbstowcs.cpp rename to libc/stdlib/mbstowcs.c index 4b2dbfca..efb20718 100644 --- a/libc/stdlib/mbstowcs.cpp +++ b/libc/stdlib/mbstowcs.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 . - stdlib/mbstowcs.cpp + stdlib/mbstowcs.c Convert a multibyte string to a wide-character string. *******************************************************************************/ @@ -27,7 +27,6 @@ #include // TODO: This function is unpure and should be removed. -extern "C" size_t mbstowcs(wchar_t* restrict dst, const char* restrict src, size_t n) { mbstate_t ps; diff --git a/libc/stdlib/mbtowc.cpp b/libc/stdlib/mbtowc.c similarity index 94% rename from libc/stdlib/mbtowc.cpp rename to libc/stdlib/mbtowc.c index fc410a1d..aed93415 100644 --- a/libc/stdlib/mbtowc.cpp +++ b/libc/stdlib/mbtowc.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 . - stdlib/mbtowc.cpp + stdlib/mbtowc.c Convert a multibyte sequence to a wide character. *******************************************************************************/ @@ -28,7 +28,7 @@ #include // TODO: This function is unpure and should be removed. -extern "C" int mbtowc(wchar_t* pwc, const char* s, size_t n) +int mbtowc(wchar_t* pwc, const char* s, size_t n) { static mbstate_t ps; size_t result = mbrtowc(pwc, s, n, &ps); diff --git a/libc/stdlib/mkdtemp.cpp b/libc/stdlib/mkdtemp.c similarity index 94% rename from libc/stdlib/mkdtemp.cpp rename to libc/stdlib/mkdtemp.c index fca0dc94..ebbc92e1 100644 --- a/libc/stdlib/mkdtemp.cpp +++ b/libc/stdlib/mkdtemp.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 . - stdlib/mkdtemp.cpp + stdlib/mkdtemp.c Make a unique temporary directory path and create it. *******************************************************************************/ #include -extern "C" char* mkdtemp(char* templ) +char* mkdtemp(char* templ) { return mkdtemps(templ, 0); } diff --git a/libc/stdlib/mkdtemps.cpp b/libc/stdlib/mkdtemps.c similarity index 91% rename from libc/stdlib/mkdtemps.cpp rename to libc/stdlib/mkdtemps.c index 0ba3bb5c..52ea4233 100644 --- a/libc/stdlib/mkdtemps.cpp +++ b/libc/stdlib/mkdtemps.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 . - stdlib/mkdtemps.cpp + stdlib/mkdtemps.c Make a unique temporary directory path and create it. *******************************************************************************/ @@ -27,9 +27,9 @@ #include #include -const uint32_t NUM_CHARACTERS = 10 + 26 + 26; +static const uint32_t NUM_CHARACTERS = 10 + 26 + 26; -static inline char random_character() +static inline char random_character(void) { uint32_t index = arc4random_uniform(NUM_CHARACTERS); if ( index < 10 ) @@ -41,7 +41,7 @@ static inline char random_character() __builtin_unreachable(); } -extern "C" char* mkdtemps(char* templ, size_t suffixlen) +char* mkdtemps(char* templ, size_t suffixlen) { size_t templ_length = strlen(templ); if ( templ_length < 6 || diff --git a/libc/stdlib/mkostemp.cpp b/libc/stdlib/mkostemp.c similarity index 93% rename from libc/stdlib/mkostemp.cpp rename to libc/stdlib/mkostemp.c index c0bd77fe..11d3216d 100644 --- a/libc/stdlib/mkostemp.cpp +++ b/libc/stdlib/mkostemp.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 . - stdlib/mkostemp.cpp + stdlib/mkostemp.c Make a unique temporary file path and open it. *******************************************************************************/ #include -extern "C" int mkostemp(char* templ, int flags) +int mkostemp(char* templ, int flags) { return mkostemps(templ, 0, flags); } diff --git a/libc/stdlib/mkostemps.cpp b/libc/stdlib/mkostemps.c similarity index 91% rename from libc/stdlib/mkostemps.cpp rename to libc/stdlib/mkostemps.c index c2a79487..096f7c43 100644 --- a/libc/stdlib/mkostemps.cpp +++ b/libc/stdlib/mkostemps.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 . - stdlib/mkostemps.cpp + stdlib/mkostemps.c Make a unique temporary file path and open it. *******************************************************************************/ @@ -27,9 +27,9 @@ #include #include -const uint32_t NUM_CHARACTERS = 10 + 26 + 26; +static const uint32_t NUM_CHARACTERS = 10 + 26 + 26; -static inline char random_character() +static inline char random_character(void) { uint32_t index = arc4random_uniform(NUM_CHARACTERS); if ( index < 10 ) @@ -41,7 +41,7 @@ static inline char random_character() __builtin_unreachable(); } -extern "C" int mkostemps(char* templ, int suffixlen, int flags) +int mkostemps(char* templ, int suffixlen, int flags) { size_t templ_length = strlen(templ); if ( templ_length < 6 || diff --git a/libc/stdlib/mkstemp.cpp b/libc/stdlib/mkstemp.c similarity index 94% rename from libc/stdlib/mkstemp.cpp rename to libc/stdlib/mkstemp.c index 9c491620..cd2e47d3 100644 --- a/libc/stdlib/mkstemp.cpp +++ b/libc/stdlib/mkstemp.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 . - stdlib/mkstemp.cpp + stdlib/mkstemp.c Make a unique temporary file path and open it. *******************************************************************************/ #include -extern "C" int mkstemp(char* templ) +int mkstemp(char* templ) { return mkostemps(templ, 0, 0); } diff --git a/libc/stdlib/mkstemps.cpp b/libc/stdlib/mkstemps.c similarity index 93% rename from libc/stdlib/mkstemps.cpp rename to libc/stdlib/mkstemps.c index 34b694b7..d520618a 100644 --- a/libc/stdlib/mkstemps.cpp +++ b/libc/stdlib/mkstemps.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 . - stdlib/mkstemps.cpp + stdlib/mkstemps.c Make a unique temporary file path and open it. *******************************************************************************/ #include -extern "C" int mkstemps(char* templ, int suffixlen) +int mkstemps(char* templ, int suffixlen) { return mkostemps(templ, suffixlen, 0); } diff --git a/libc/stdlib/on_exit.cpp b/libc/stdlib/on_exit.c similarity index 93% rename from libc/stdlib/on_exit.cpp rename to libc/stdlib/on_exit.c index 3904b8c3..200cabeb 100644 --- a/libc/stdlib/on_exit.cpp +++ b/libc/stdlib/on_exit.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 . - stdlib/on_exit.cpp + stdlib/on_exit.c Hooks that are called upon process exit. *******************************************************************************/ #include -extern "C" int on_exit(void (*hook)(int, void*), void* param) +int on_exit(void (*hook)(int, void*), void* param) { struct exit_handler* handler = (struct exit_handler*) malloc(sizeof(struct exit_handler)); diff --git a/libc/stdlib/qsort.cpp b/libc/stdlib/qsort.c similarity index 97% rename from libc/stdlib/qsort.cpp rename to libc/stdlib/qsort.c index 6421d576..5be5a41b 100644 --- a/libc/stdlib/qsort.cpp +++ b/libc/stdlib/qsort.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 . - stdlib/qsort.cpp + stdlib/qsort.c Sort an array. *******************************************************************************/ @@ -31,7 +31,6 @@ static int compare_wrapper(const void* a, const void* b, void* arg) return ((int (*)(const void*, const void*)) arg)(a, b); } -extern "C" void qsort(void* base_ptr, size_t num_elements, size_t element_size, diff --git a/libc/stdlib/qsort_r.cpp b/libc/stdlib/qsort_r.c similarity index 98% rename from libc/stdlib/qsort_r.cpp rename to libc/stdlib/qsort_r.c index 14400bdb..378388f1 100644 --- a/libc/stdlib/qsort_r.cpp +++ b/libc/stdlib/qsort_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 . - stdlib/qsort_r.cpp + stdlib/qsort_r.c Sort an array. *******************************************************************************/ @@ -81,7 +81,6 @@ size_t partition(unsigned char* base, return store_index; } -extern "C" void qsort_r(void* base_ptr, size_t num_elements, size_t element_size, diff --git a/libc/stdlib/rand.cpp b/libc/stdlib/rand.c similarity index 93% rename from libc/stdlib/rand.cpp rename to libc/stdlib/rand.c index 4d0b7a4e..5c4fac7d 100644 --- a/libc/stdlib/rand.cpp +++ b/libc/stdlib/rand.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 . - stdlib/rand.cpp + stdlib/rand.c Returns a random value. *******************************************************************************/ @@ -30,14 +30,14 @@ static pthread_mutex_t rand_mutex = PTHREAD_MUTEX_INITIALIZER; static uint32_t m_w = 1337; static uint32_t m_z = 37; -static uint32_t random_32_bits() +static uint32_t random_32_bits(void) { m_z = 36969 * (m_z >> 0 & 0xFFFF) + (m_z >> 16 & 0xFFFF); m_w = 18000 * (m_w >> 0 & 0xFFFF) + (m_w >> 16 & 0xFFFF); return (m_z << 16) + m_w; } -extern "C" int rand() +int rand(void) { pthread_mutex_lock(&rand_mutex); int result = (int) (random_32_bits() % ((uint32_t) RAND_MAX + 1)); @@ -45,7 +45,7 @@ extern "C" int rand() return result; } -extern "C" void srand(unsigned int seed) +void srand(unsigned int seed) { pthread_mutex_lock(&rand_mutex); m_w = seed >> 16 & 0xFFFF; diff --git a/libc/stdlib/realloc.cpp b/libc/stdlib/realloc.c similarity index 88% rename from libc/stdlib/realloc.cpp rename to libc/stdlib/realloc.c index 4af689d1..1063cbb5 100644 --- a/libc/stdlib/realloc.cpp +++ b/libc/stdlib/realloc.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 . - stdlib/realloc.cpp + stdlib/realloc.c Reallocates a chunk of memory from the dynamic memory heap. *******************************************************************************/ @@ -36,7 +36,7 @@ #if !defined(HEAP_GUARD_DEBUG) -extern "C" void* realloc(void* ptr, size_t requested_size) +void* realloc(void* ptr, size_t requested_size) { if ( !ptr ) return malloc(requested_size); @@ -126,30 +126,16 @@ extern "C" void* realloc(void* ptr, size_t requested_size) #else -#if defined(__is_sortix_kernel) -#include -#include -#endif - -extern "C" void* realloc(void* ptr, size_t requested_size) +void* realloc(void* ptr, size_t requested_size) { if ( !ptr ) return malloc(requested_size); -#if defined(__is_sortix_kernel) - using namespace Sortix; - addralloc_t* alloc_ptr = - (addralloc_t*) Page::AlignDown((uintptr_t) ptr - 16); - assert(alloc_ptr->from == (uintptr_t) alloc_ptr); - addralloc_t alloc = *alloc_ptr; - size_t size = (alloc.from + alloc.size - Page::Size()) - (uintptr_t) ptr; -#else struct heap_alloc* alloc_ptr = (struct heap_alloc*) HEAP_ALIGN_PAGEDOWN((uintptr_t) ptr - 16); assert(alloc_ptr->from == (uintptr_t) alloc_ptr); struct heap_alloc alloc = *alloc_ptr; size_t size = (alloc.from + alloc.size - HEAP_PAGE_SIZE) - (uintptr_t) ptr; -#endif if ( requested_size <= size ) return ptr; void* replacement = malloc(requested_size); diff --git a/libc/stdlib/reallocarray.cpp b/libc/stdlib/reallocarray.c similarity index 92% rename from libc/stdlib/reallocarray.cpp rename to libc/stdlib/reallocarray.c index 52c134fe..b08671f9 100644 --- a/libc/stdlib/reallocarray.cpp +++ b/libc/stdlib/reallocarray.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 . - stdlib/reallocarray.cpp + stdlib/reallocarray.c Reallocates a chunk of memory from the dynamic memory heap. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" void* reallocarray(void* ptr, size_t nmemb, size_t size) +void* reallocarray(void* ptr, size_t nmemb, size_t size) { if ( size && nmemb && SIZE_MAX / size < nmemb ) return errno = ENOMEM, (void*) NULL; diff --git a/libc/stdlib/realpath.cpp b/libc/stdlib/realpath.c similarity index 97% rename from libc/stdlib/realpath.cpp rename to libc/stdlib/realpath.c index 2b08c9b5..ce70389e 100644 --- a/libc/stdlib/realpath.cpp +++ b/libc/stdlib/realpath.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 . - stdlib/realpath.cpp + stdlib/realpath.c Return the canonicalized filename. *******************************************************************************/ @@ -35,7 +35,6 @@ #error "This realpath implementation assumes no PATH_MAX" #endif -extern "C" char* realpath(const char* restrict path, char* restrict resolved_path) { if ( resolved_path ) diff --git a/libc/stdlib/setenv.cpp b/libc/stdlib/setenv.c similarity index 97% rename from libc/stdlib/setenv.cpp rename to libc/stdlib/setenv.c index aeff0f26..df35af65 100644 --- a/libc/stdlib/setenv.cpp +++ b/libc/stdlib/setenv.c @@ -17,12 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdlib/setenv.cpp + stdlib/setenv.c Set an environment variable. *******************************************************************************/ #include +#include #include #include #include @@ -61,7 +62,7 @@ static bool set_entry_at(char** environ, size_t position, return true; } -static bool recover_environment() +static bool recover_environment(void) { // It is undefined behavior to change environ to another value (manually // taking control of the environment) and reusing any of the pointers from @@ -112,7 +113,7 @@ static bool recover_environment() return true; } -extern "C" int setenv(const char* name, const char* value, int overwrite) +int setenv(const char* name, const char* value, int overwrite) { if ( !name || !value ) return errno = EINVAL, -1; diff --git a/libc/stdlib/strtod.cpp b/libc/stdlib/strtod.c similarity index 96% rename from libc/stdlib/strtod.cpp rename to libc/stdlib/strtod.c index 783ea857..944403e8 100644 --- a/libc/stdlib/strtod.cpp +++ b/libc/stdlib/strtod.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 . - stdlib/strtod.cpp + stdlib/strtod.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -31,4 +31,4 @@ #define STRTOF_STRNCASECMP strncasecmp #define STRTOF_POW pow -#include "strtof.cpp" +#include "strtof.c" diff --git a/libc/stdlib/strtof.cpp b/libc/stdlib/strtof.c similarity index 97% rename from libc/stdlib/strtof.cpp rename to libc/stdlib/strtof.c index e31548d7..4697af4d 100644 --- a/libc/stdlib/strtof.cpp +++ b/libc/stdlib/strtof.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 . - stdlib/strtof.cpp + stdlib/strtof.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include @@ -45,7 +46,7 @@ // and explicitly handle overflow conditions. It behaves well enough on // simple common inputs to do for now. -#if !defined(__is_sortix_kernel) +#ifndef __is_sortix_libk static inline size_t nan_parameter(const STRTOF_CHAR* str) { size_t index = 0; @@ -101,7 +102,7 @@ static inline bool parse_digit(const STRTOF_CHAR* str, return false; } -extern "C" STRTOF_FLOAT STRTOF(const STRTOF_CHAR* str, STRTOF_CHAR** nptr) +STRTOF_FLOAT STRTOF(const STRTOF_CHAR* str, STRTOF_CHAR** nptr) { if ( nptr ) *nptr = (STRTOF_CHAR*) str; diff --git a/libc/stdlib/strtol.cpp b/libc/stdlib/strtol.c similarity index 65% rename from libc/stdlib/strtol.cpp rename to libc/stdlib/strtol.c index eb17ae3d..4e2e1d87 100644 --- a/libc/stdlib/strtol.cpp +++ b/libc/stdlib/strtol.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 . - stdlib/strtol.cpp + stdlib/strtol.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -39,16 +39,14 @@ #include #include #include +#include +#include #include #include #include #include #include -// Nasty, nasty hack to get LLONG_* macros. -#define __STDC_VERSION__ 199901L -#include - // Convert a character into a digit. static int debase(STRTOL_CHAR c) { @@ -61,69 +59,6 @@ static int debase(STRTOL_CHAR c) return -1; } -// Determine whether a multiplication of two integers would overflow/underflow. -// This is easy if we have a larger integer type, otherwise we'll be creative. -template -static bool would_multiplication_overflow(T_INT a, T_INT b) -{ - // Prevent accidental divisons by zero in this simple case. - if ( !a || !b ) - return false; - - // Trivial cases. - if ( a == 1 || b == 1 ) - return false; - - // Check if we have a 64-bit integer that it is large enough. - if ( sizeof(T_INT)*2 <= sizeof(int64_t) ) - { - int64_t ret_large = (int64_t) a * (int64_t) b; - return ret_large < (int64_t) T_INT_MIN || - (int64_t) T_INT_MAX < ret_large; - } - - // Check if we have a 128-bit integer that it is large enough. -#if 64 <= __WORDSIZE - if ( sizeof(T_INT)*2 <= sizeof(__int128) ) - { - __int128 ret_large = (__int128) a * (__int128) b; - return ret_large < (__int128) T_INT_MIN || - (__int128) T_INT_MAX < ret_large; - } -#endif - - // The fallback strategy is to determine the largest b given a that will not - // overflow and then see if b is within range. This is trivial if in the - // unsigned integer case. - if ( T_INT_IS_UNSIGNED ) - { - T_INT max_b = T_INT_MAX / a; - return max_b < b; - } - - // We have to deal with some cases for signed integers. We'll assume signed - // integers are in two's complement and use - (unsigned int) value to take - // the absolute value of a negative value as an unsigned integer in a manner - // that is defined in C. Whether we use the smallest or largest value depend - // on whether the sign of a and b is identical. - else - { - T_UNSIGNED_INT a_abs = a < 0 ? - (T_UNSIGNED_INT) a : a; - T_UNSIGNED_INT b_abs = b < 0 ? - (T_UNSIGNED_INT) b : b; - T_UNSIGNED_INT min_abs = - (T_UNSIGNED_INT) T_INT_MIN; - T_UNSIGNED_INT max_abs = T_INT_MAX; - bool limit_pos = (0 <= a && 0 <= b) || (a < 0 && b < 0); - T_UNSIGNED_INT limit = limit_pos ? max_abs : min_abs; - T_UNSIGNED_INT max_b = limit / a_abs; - return max_b < b_abs; - } -} - -extern "C" STRTOL_INT STRTOL(const STRTOL_CHAR* restrict str, STRTOL_CHAR** restrict end_ptr, int base) @@ -198,25 +133,13 @@ STRTOL_INT STRTOL(const STRTOL_CHAR* restrict str, continue; // Attempt to multiply the accumulator with the current base. - if ( would_multiplication_overflow - (result, (STRTOL_INT) base) ) + if ( __builtin_mul_overflow(result, base, &result) ) { overflow_occured = true; result = overflow_value; errno = ERANGE; continue; } - else - { - STRTOL_INT new_result = result * (STRTOL_INT) base; - assert( actually_negative || result <= new_result); - assert(!actually_negative || result >= new_result); - result = new_result; - } // Nothing needs to be added if we are encountered a zero digit. if ( val == 0 ) diff --git a/libc/stdlib/strtold.cpp b/libc/stdlib/strtold.c similarity index 96% rename from libc/stdlib/strtold.cpp rename to libc/stdlib/strtold.c index e31f0986..584ec467 100644 --- a/libc/stdlib/strtold.cpp +++ b/libc/stdlib/strtold.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 . - stdlib/strtold.cpp + stdlib/strtold.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -31,4 +31,4 @@ #define STRTOF_STRNCASECMP strncasecmp #define STRTOF_POW pow /* TODO: powl */ -#include "strtof.cpp" +#include "strtof.c" diff --git a/libc/stdlib/strtoll.cpp b/libc/stdlib/strtoll.c similarity index 96% rename from libc/stdlib/strtoll.cpp rename to libc/stdlib/strtoll.c index d1de6ef6..7fb94980 100644 --- a/libc/stdlib/strtoll.cpp +++ b/libc/stdlib/strtoll.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 . - stdlib/strtoll.cpp + stdlib/strtoll.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX LLONG_MAX #define STRTOL_INT_IS_UNSIGNED false -#include "strtol.cpp" +#include "strtol.c" diff --git a/libc/stdlib/strtoul.cpp b/libc/stdlib/strtoul.c similarity index 96% rename from libc/stdlib/strtoul.cpp rename to libc/stdlib/strtoul.c index 533d235c..6c9d95b2 100644 --- a/libc/stdlib/strtoul.cpp +++ b/libc/stdlib/strtoul.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 . - stdlib/strtoul.cpp + stdlib/strtoul.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX ULONG_MAX #define STRTOL_INT_IS_UNSIGNED true -#include "strtol.cpp" +#include "strtol.c" diff --git a/libc/stdlib/strtoull.cpp b/libc/stdlib/strtoull.c similarity index 96% rename from libc/stdlib/strtoull.cpp rename to libc/stdlib/strtoull.c index 3a40bbac..3d5151c4 100644 --- a/libc/stdlib/strtoull.cpp +++ b/libc/stdlib/strtoull.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 . - stdlib/strtoull.cpp + stdlib/strtoull.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX ULLONG_MAX #define STRTOL_INT_IS_UNSIGNED true -#include "strtol.cpp" +#include "strtol.c" diff --git a/libc/stdlib/system.cpp b/libc/stdlib/system.c similarity index 95% rename from libc/stdlib/system.cpp rename to libc/stdlib/system.c index 1f2d12aa..c2e2a8b1 100644 --- a/libc/stdlib/system.cpp +++ b/libc/stdlib/system.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 . - stdlib/system.cpp + stdlib/system.c Execute a shell command. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int system(const char* command) +int system(const char* command) { const int ret_error = command ? -1 : 0; const int exit_error = command ? 127 : 0; diff --git a/libc/stdlib/unsetenv.cpp b/libc/stdlib/unsetenv.c similarity index 96% rename from libc/stdlib/unsetenv.cpp rename to libc/stdlib/unsetenv.c index 243594ff..258133aa 100644 --- a/libc/stdlib/unsetenv.cpp +++ b/libc/stdlib/unsetenv.c @@ -17,12 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - stdlib/unsetenv.cpp + stdlib/unsetenv.c Unset an environment variable. *******************************************************************************/ #include +#include #include #include #include @@ -34,7 +35,7 @@ bool matches_environment_variable(const char* what, return !strncmp(what, name, name_length) && what[name_length] == '='; } -extern "C" int unsetenv(const char* name) +int unsetenv(const char* name) { if ( !name ) return errno = EINVAL, -1; diff --git a/libc/stdlib/wcstombs.cpp b/libc/stdlib/wcstombs.c similarity index 93% rename from libc/stdlib/wcstombs.cpp rename to libc/stdlib/wcstombs.c index c6cf6be1..e79e867b 100644 --- a/libc/stdlib/wcstombs.cpp +++ b/libc/stdlib/wcstombs.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 . - stdlib/wcstombs.cpp + stdlib/wcstombs.c Convert a wide-character string to multibyte string. *******************************************************************************/ @@ -27,7 +27,7 @@ #include // TODO: This function is unpure and should be removed. -extern "C" size_t wcstombs(char* dst, const wchar_t* src, size_t n) +size_t wcstombs(char* dst, const wchar_t* src, size_t n) { mbstate_t ps; memset(&ps, 0, sizeof(ps)); diff --git a/libc/stdlib/wctomb.cpp b/libc/stdlib/wctomb.c similarity index 95% rename from libc/stdlib/wctomb.cpp rename to libc/stdlib/wctomb.c index a2bb5c70..defd7f6e 100644 --- a/libc/stdlib/wctomb.cpp +++ b/libc/stdlib/wctomb.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 . - stdlib/wctomb.cpp + stdlib/wctomb.c Convert a wide character to a multibyte sequence. *******************************************************************************/ @@ -27,7 +27,7 @@ #include // TODO: This function is unpure and should be removed. -extern "C" int wctomb(char* s, wchar_t wc) +int wctomb(char* s, wchar_t wc) { static mbstate_t ps; size_t result = wcrtomb(s, wc, &ps); diff --git a/libc/string/explicit_bzero.cpp b/libc/string/explicit_bzero.c similarity index 93% rename from libc/string/explicit_bzero.cpp rename to libc/string/explicit_bzero.c index a603e027..7487737e 100644 --- a/libc/string/explicit_bzero.cpp +++ b/libc/string/explicit_bzero.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 . - string/explicit_bzero.cpp + string/explicit_bzero.c Initializes a region of memory to a byte value in a manner that is not optimized away by the compiler. @@ -26,7 +26,7 @@ #include // TODO: Employ special compiler support to ensure this is not optimized away. -extern "C" void explicit_bzero(void* dest_ptr, size_t size) +void explicit_bzero(void* dest_ptr, size_t size) { volatile unsigned char* dest = (volatile unsigned char*) dest_ptr; for ( size_t i = 0; i < size; i++ ) diff --git a/libc/string/ffs.cpp b/libc/string/ffs.c similarity index 95% rename from libc/string/ffs.cpp rename to libc/string/ffs.c index 84b11519..2f13c43b 100644 --- a/libc/string/ffs.cpp +++ b/libc/string/ffs.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 . - string/ffs.cpp + string/ffs.c Returns the index of the first set bit. *******************************************************************************/ #include -extern "C" int ffs(int val) +int ffs(int val) { return __builtin_ffs(val); } diff --git a/libc/string/ffsl.cpp b/libc/string/ffsl.c similarity index 95% rename from libc/string/ffsl.cpp rename to libc/string/ffsl.c index 35d8173d..0b1bcb57 100644 --- a/libc/string/ffsl.cpp +++ b/libc/string/ffsl.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 . - string/ffsl.cpp + string/ffsl.c Returns the index of the first set bit. *******************************************************************************/ #include -extern "C" int ffsl(long int val) +int ffsl(long int val) { return __builtin_ffsl(val); } diff --git a/libc/string/ffsll.cpp b/libc/string/ffsll.c similarity index 94% rename from libc/string/ffsll.cpp rename to libc/string/ffsll.c index 30661ea9..c8708727 100644 --- a/libc/string/ffsll.cpp +++ b/libc/string/ffsll.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 . - string/ffsll.cpp + string/ffsll.c Returns the index of the first set bit. *******************************************************************************/ #include -extern "C" int ffsll(long long int val) +int ffsll(long long int val) { return __builtin_ffsll(val); } diff --git a/libc/string/memccpy.cpp b/libc/string/memccpy.c similarity index 92% rename from libc/string/memccpy.cpp rename to libc/string/memccpy.c index 9534c100..497f39e5 100644 --- a/libc/string/memccpy.cpp +++ b/libc/string/memccpy.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 . - string/memccpy.cpp + string/memccpy.c Copy memory until length is met or character is encountered. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void* memccpy(void* dest_ptr, const void* src_ptr, int c, size_t n) +void* memccpy(void* dest_ptr, const void* src_ptr, int c, size_t n) { unsigned char* dest = (unsigned char*) dest_ptr; const unsigned char* src = (const unsigned char*) src_ptr; diff --git a/libc/string/memchr.cpp b/libc/string/memchr.c similarity index 93% rename from libc/string/memchr.cpp rename to libc/string/memchr.c index 1116ee93..33741e7c 100644 --- a/libc/string/memchr.cpp +++ b/libc/string/memchr.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 . - string/memchr.cpp + string/memchr.c Scans memory for a character. *******************************************************************************/ #include -extern "C" void* memchr(const void* s, int c, size_t size) +void* memchr(const void* s, int c, size_t size) { const unsigned char* buf = (const unsigned char*) s; for ( size_t i = 0; i < size; i++ ) diff --git a/libc/string/memcmp.cpp b/libc/string/memcmp.c similarity index 93% rename from libc/string/memcmp.cpp rename to libc/string/memcmp.c index 1e25cbfc..bd161e69 100644 --- a/libc/string/memcmp.cpp +++ b/libc/string/memcmp.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 . - string/memcmp.cpp + string/memcmp.c Compares two memory regions. *******************************************************************************/ #include -extern "C" int memcmp(const void* a_ptr, const void* b_ptr, size_t size) +int memcmp(const void* a_ptr, const void* b_ptr, size_t size) { const unsigned char* a = (const unsigned char*) a_ptr; const unsigned char* b = (const unsigned char*) b_ptr; diff --git a/libc/string/memcpy.cpp b/libc/string/memcpy.c similarity index 84% rename from libc/string/memcpy.cpp rename to libc/string/memcpy.c index d3c12018..12dd8fcd 100644 --- a/libc/string/memcpy.cpp +++ b/libc/string/memcpy.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 . - string/memcpy.cpp + string/memcpy.c Copy memory between non-overlapping regions. *******************************************************************************/ @@ -37,7 +37,6 @@ void* memcpy_slow(void* restrict dst_ptr, return dst_ptr; } -extern "C" void* memcpy(void* restrict dst_ptr, const void* restrict src_ptr, size_t size) @@ -60,8 +59,8 @@ void* memcpy(void* restrict dst_ptr, const uint32_t* restrict src32; const uint64_t* restrict src64; const unsigned long* restrict srcul; - }; - srcval = (unsigned long) src_ptr; + } su; + su.srcval = (unsigned long) src_ptr; union { @@ -71,29 +70,29 @@ void* memcpy(void* restrict dst_ptr, uint32_t* restrict dst32; uint64_t* restrict dst64; unsigned long* restrict dstul; - }; - dstval = (unsigned long) dst_ptr; + } du; + du.dstval = (unsigned long) dst_ptr; if ( dst_unalign ) { - if ( 1 <= size && !(dstval & (1-1)) && (dstval & (2-1)) ) - *dst8++ = *src8++, + if ( 1 <= size && !(du.dstval & (1-1)) && (du.dstval & (2-1)) ) + *du.dst8++ = *su.src8++, size -= 1; - if ( 2 <= size && !(dstval & (2-1)) && (dstval & (4-1)) ) - *dst16++ = *src16++, + if ( 2 <= size && !(du.dstval & (2-1)) && (du.dstval & (4-1)) ) + *du.dst16++ = *su.src16++, size -= 2; #if 8 <= __SIZEOF_LONG__ - if ( 4 <= size && !(dstval & (4-1)) && (dstval & (8-1)) ) - *dst32++ = *src32++, + if ( 4 <= size && !(du.dstval & (4-1)) && (du.dstval & (8-1)) ) + *du.dst32++ = *su.src32++, size -= 4; #endif } size_t num_copies = size / sizeof(unsigned long); for ( size_t i = 0; i < num_copies; i++ ) - *dstul++ = *srcul++; + *du.dstul++ = *su.srcul++; size -= num_copies * sizeof(unsigned long); @@ -101,16 +100,16 @@ void* memcpy(void* restrict dst_ptr, { #if 8 <= __SIZEOF_LONG__ if ( 4 <= size ) - *dst32++ = *src32++, + *du.dst32++ = *su.src32++, size -= 4; #endif if ( 2 <= size ) - *dst16++ = *src16++, + *du.dst16++ = *su.src16++, size -= 2; if ( 1 <= size ) - *dst8++ = *src8++, + *du.dst8++ = *su.src8++, size -= 1; } diff --git a/libc/string/memmove.cpp b/libc/string/memmove.c similarity index 93% rename from libc/string/memmove.cpp rename to libc/string/memmove.c index 2deafe10..04f5dce3 100644 --- a/libc/string/memmove.cpp +++ b/libc/string/memmove.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 . - string/memmove.cpp + string/memmove.c Copy memory between potentionally overlapping regions. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void* memmove(void* dest_ptr, const void* src_ptr, size_t n) +void* memmove(void* dest_ptr, const void* src_ptr, size_t n) { unsigned char* dest = (unsigned char*) dest_ptr; const unsigned char* src = (const unsigned char*) src_ptr; diff --git a/libc/string/memrchr.cpp b/libc/string/memrchr.c similarity index 93% rename from libc/string/memrchr.cpp rename to libc/string/memrchr.c index 735a0210..d5a5ea07 100644 --- a/libc/string/memrchr.cpp +++ b/libc/string/memrchr.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 . - string/memrchr.cpp + string/memrchr.c Scans memory in reverse directory for a character. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void* memrchr(const void* ptr, int c, size_t n) +void* memrchr(const void* ptr, int c, size_t n) { const unsigned char* buf = (const unsigned char*) ptr; for ( size_t i = n; i != 0; i-- ) diff --git a/libc/string/memset.cpp b/libc/string/memset.c similarity index 96% rename from libc/string/memset.cpp rename to libc/string/memset.c index 404287c9..74407c9a 100644 --- a/libc/string/memset.cpp +++ b/libc/string/memset.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 . - string/memset.cpp + string/memset.c Initializes a region of memory to a byte value. *******************************************************************************/ @@ -27,7 +27,7 @@ #include <__/wordsize.h> -extern "C" void* memset(void* dest_ptr, int value, size_t length) +void* memset(void* dest_ptr, int value, size_t length) { unsigned char* dest = (unsigned char*) dest_ptr; #if __WORDSIZE == 32 || __WORDSIZE == 64 diff --git a/libc/string/stpcpy.cpp b/libc/string/stpcpy.c similarity index 93% rename from libc/string/stpcpy.cpp rename to libc/string/stpcpy.c index 3249c158..27a87aa1 100644 --- a/libc/string/stpcpy.cpp +++ b/libc/string/stpcpy.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 . - string/stpcpy.cpp + string/stpcpy.c Copy a string returning a pointer to its end. *******************************************************************************/ #include -extern "C" char* stpcpy(char* dest, const char* src) +char* stpcpy(char* dest, const char* src) { size_t index; for ( index = 0; src[index]; index++ ) diff --git a/libc/string/stpncpy.cpp b/libc/string/stpncpy.c similarity index 93% rename from libc/string/stpncpy.cpp rename to libc/string/stpncpy.c index afeb60a7..a936ff3c 100644 --- a/libc/string/stpncpy.cpp +++ b/libc/string/stpncpy.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 . - string/stpncpy.cpp + string/stpncpy.c Copies a string into a fixed size buffer and returns last byte. *******************************************************************************/ #include -extern "C" char* stpncpy(char* dest, const char* src, size_t n) +char* stpncpy(char* dest, const char* src, size_t n) { size_t i; for ( i = 0; i < n && src[i] != '\0'; i++ ) diff --git a/libc/string/strcasecmp.cpp b/libc/string/strcasecmp.c similarity index 93% rename from libc/string/strcasecmp.cpp rename to libc/string/strcasecmp.c index 8fa76ed7..cf4fe1be 100644 --- a/libc/string/strcasecmp.cpp +++ b/libc/string/strcasecmp.c @@ -17,15 +17,16 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strcasecmp.cpp + string/strcasecmp.c Compares two strings ignoring case. *******************************************************************************/ -#include #include +#include +#include -extern "C" int strcasecmp(const char* a, const char* b) +int strcasecmp(const char* a, const char* b) { for ( size_t i = 0; true; i++ ) { diff --git a/libc/string/strcat.cpp b/libc/string/strcat.c similarity index 93% rename from libc/string/strcat.cpp rename to libc/string/strcat.c index d7c9cd04..cb8c6685 100644 --- a/libc/string/strcat.cpp +++ b/libc/string/strcat.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 . - string/strcat.cpp + string/strcat.c Appends a string onto another string. *******************************************************************************/ #include -extern "C" char* strcat(char* dest, const char* src) +char* strcat(char* dest, const char* src) { strcpy(dest + strlen(dest), src); return dest; diff --git a/libc/string/strchr.cpp b/libc/string/strchr.c similarity index 94% rename from libc/string/strchr.cpp rename to libc/string/strchr.c index c36a065c..3bb862fc 100644 --- a/libc/string/strchr.cpp +++ b/libc/string/strchr.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 . - string/strchr.cpp + string/strchr.c Searches a string for a specific character. *******************************************************************************/ #include -extern "C" char* strchr(const char* str, int uc) +char* strchr(const char* str, int uc) { char* ret = strchrnul(str, uc); return (unsigned char) uc == ((unsigned char*) ret)[0] ? ret : NULL; diff --git a/libc/string/strchrnul.cpp b/libc/string/strchrnul.c similarity index 93% rename from libc/string/strchrnul.cpp rename to libc/string/strchrnul.c index a35d75e6..7d8221f7 100644 --- a/libc/string/strchrnul.cpp +++ b/libc/string/strchrnul.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 . - string/strchrnul.cpp + string/strchrnul.c Searches a string for a specific character. *******************************************************************************/ +#include #include -extern "C" char* strchrnul(const char* str, int uc) +char* strchrnul(const char* str, int uc) { const unsigned char* ustr = (const unsigned char*) str; for ( size_t i = 0; true; i++) diff --git a/libc/string/strcmp.cpp b/libc/string/strcmp.c similarity index 93% rename from libc/string/strcmp.cpp rename to libc/string/strcmp.c index 7b14353f..9c0cdb15 100644 --- a/libc/string/strcmp.cpp +++ b/libc/string/strcmp.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 . - string/strcmp.cpp + string/strcmp.c Compares two strings. *******************************************************************************/ +#include #include -extern "C" int strcmp(const char* a, const char* b) +int strcmp(const char* a, const char* b) { for ( size_t i = 0; true; i++ ) { diff --git a/libc/string/strcoll.cpp b/libc/string/strcoll.c similarity index 93% rename from libc/string/strcoll.cpp rename to libc/string/strcoll.c index cfaea683..9197f220 100644 --- a/libc/string/strcoll.cpp +++ b/libc/string/strcoll.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 . - string/strcoll.cpp + string/strcoll.c Compare two strings using the current locale. *******************************************************************************/ #include -extern "C" int strcoll(const char* s1, const char* s2) +int strcoll(const char* s1, const char* s2) { // TODO: Pay attention to locales. return strcmp(s1, s2); diff --git a/libc/string/strcoll_l.cpp b/libc/string/strcoll_l.c similarity index 91% rename from libc/string/strcoll_l.cpp rename to libc/string/strcoll_l.c index 28c6f373..738f75c3 100644 --- a/libc/string/strcoll_l.cpp +++ b/libc/string/strcoll_l.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 . - string/strcoll_l.cpp + string/strcoll_l.c Compare two strings using the given locale. *******************************************************************************/ #include -extern "C" int strcoll_l(const char* s1, const char* s2, locale_t /*locale*/) +int strcoll_l(const char* s1, const char* s2, locale_t locale) { + (void) locale; return strcoll(s1, s2); } diff --git a/libc/string/strcpy.cpp b/libc/string/strcpy.c similarity index 93% rename from libc/string/strcpy.cpp rename to libc/string/strcpy.c index fdb6a94e..16685ed2 100644 --- a/libc/string/strcpy.cpp +++ b/libc/string/strcpy.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 . - string/strcpy.cpp + string/strcpy.c Copies a string and returns dest. *******************************************************************************/ #include -extern "C" char* strcpy(char* dest, const char* src) +char* strcpy(char* dest, const char* src) { size_t index; for ( index = 0; src[index]; index++ ) diff --git a/libc/string/strcspn.cpp b/libc/string/strcspn.c similarity index 93% rename from libc/string/strcspn.cpp rename to libc/string/strcspn.c index 617952ea..4f6631d7 100644 --- a/libc/string/strcspn.cpp +++ b/libc/string/strcspn.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 . - string/strcspn.cpp + string/strcspn.c Search a string for a set of characters. *******************************************************************************/ +#include #include -extern "C" size_t strcspn(const char* str, const char* reject) +size_t strcspn(const char* str, const char* reject) { size_t reject_length = 0; while ( reject[reject_length] ) diff --git a/libc/string/strdup.cpp b/libc/string/strdup.c similarity index 94% rename from libc/string/strdup.cpp rename to libc/string/strdup.c index 5f3375ea..8cceae99 100644 --- a/libc/string/strdup.cpp +++ b/libc/string/strdup.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 . - string/strdup.cpp + string/strdup.c Creates a copy of a string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" char* strdup(const char* input) +char* strdup(const char* input) { size_t input_length = strlen(input); char* result = (char*) malloc(input_length + 1); diff --git a/libc/string/strerror.cpp b/libc/string/strerror.c similarity index 97% rename from libc/string/strerror.cpp rename to libc/string/strerror.c index b3e60cc1..03eff49d 100644 --- a/libc/string/strerror.cpp +++ b/libc/string/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 . - string/strerror.cpp + string/strerror.c Convert error code to a string. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" const char* sortix_strerror(int errnum) +const char* sortix_strerror(int errnum) { switch ( errnum ) { @@ -122,7 +122,7 @@ extern "C" const char* sortix_strerror(int errnum) } } -extern "C" char* strerror(int errnum) +char* strerror(int errnum) { return (char*) sortix_strerror(errnum); } diff --git a/libc/string/strerror_l.cpp b/libc/string/strerror_l.c similarity index 87% rename from libc/string/strerror_l.cpp rename to libc/string/strerror_l.c index d91528da..3486d75c 100644 --- a/libc/string/strerror_l.cpp +++ b/libc/string/strerror_l.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 . - string/strerror_l.cpp + string/strerror_l.c Convert error code to a string. *******************************************************************************/ @@ -25,12 +25,13 @@ #define __SORTIX_STDLIB_REDIRECTS 0 #include -extern "C" const char* sortix_strerror_l(int errnum, locale_t /*locale*/) +const char* sortix_strerror_l(int errnum, locale_t locale) { + (void) locale; return sortix_strerror(errnum); } -extern "C" char* strerror_l(int errnum, locale_t locale) +char* strerror_l(int errnum, locale_t locale) { return (char*) sortix_strerror_l(errnum, locale); } diff --git a/libc/string/strerror_r.cpp b/libc/string/strerror_r.c similarity index 92% rename from libc/string/strerror_r.cpp rename to libc/string/strerror_r.c index 743b3b2b..9f0b1a0b 100644 --- a/libc/string/strerror_r.cpp +++ b/libc/string/strerror_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 . - string/strerror_r.cpp + string/strerror_r.c Convert error code to a string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int strerror_r(int errnum, char* dest, size_t dest_len) +int strerror_r(int errnum, char* dest, size_t dest_len) { const char* msg = sortix_strerror(errnum); if ( !msg ) diff --git a/libc/string/stresep.cpp b/libc/string/stresep.c similarity index 94% rename from libc/string/stresep.cpp rename to libc/string/stresep.c index 432f0ca3..f5eeb131 100644 --- a/libc/string/stresep.cpp +++ b/libc/string/stresep.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 . - string/stresep.cpp + string/stresep.c Extract a token from a string while handling escape characters. *******************************************************************************/ +#include #include -extern "C" char* stresep(char** string_ptr, const char* delim, int escape) +char* stresep(char** string_ptr, const char* delim, int escape) { char* token = *string_ptr; if ( !token ) diff --git a/libc/string/strlcat.cpp b/libc/string/strlcat.c similarity index 97% rename from libc/string/strlcat.cpp rename to libc/string/strlcat.c index 04d92240..68babbbd 100644 --- a/libc/string/strlcat.cpp +++ b/libc/string/strlcat.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strlcat.cpp + string/strlcat.c Appends a string onto another string truncating if the string is too small. *******************************************************************************/ #include -extern "C" size_t strlcat(char* restrict dest, const char* restrict src, size_t size) { size_t dest_len = strnlen(dest, size); diff --git a/libc/string/strlcpy.cpp b/libc/string/strlcpy.c similarity index 97% rename from libc/string/strlcpy.cpp rename to libc/string/strlcpy.c index 878f5327..45e0bf98 100644 --- a/libc/string/strlcpy.cpp +++ b/libc/string/strlcpy.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strlcpy.cpp + string/strlcpy.c Copies a string and truncates it if the destination is too small. *******************************************************************************/ #include -extern "C" size_t strlcpy(char* restrict dest, const char* restrict src, size_t size) { if ( !size ) diff --git a/libc/string/strlen.cpp b/libc/string/strlen.c similarity index 94% rename from libc/string/strlen.cpp rename to libc/string/strlen.c index 14514723..a5b69236 100644 --- a/libc/string/strlen.cpp +++ b/libc/string/strlen.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 . - string/strlen.cpp + string/strlen.c Returns the length of a string. *******************************************************************************/ #include -extern "C" size_t strlen(const char* str) +size_t strlen(const char* str) { size_t ret = 0; while ( str[ret] ) diff --git a/libc/string/strncasecmp.cpp b/libc/string/strncasecmp.c similarity index 93% rename from libc/string/strncasecmp.cpp rename to libc/string/strncasecmp.c index 50674e4f..d669781e 100644 --- a/libc/string/strncasecmp.cpp +++ b/libc/string/strncasecmp.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 . - string/strncasecmp.cpp + string/strncasecmp.c Compares a prefix of two strings ignoring case. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int strncasecmp(const char* a, const char* b, size_t max_count) +int strncasecmp(const char* a, const char* b, size_t max_count) { for ( size_t i = 0; i < max_count; i++ ) { diff --git a/libc/string/strncat.cpp b/libc/string/strncat.c similarity index 93% rename from libc/string/strncat.cpp rename to libc/string/strncat.c index 4d0e57b9..1020719e 100644 --- a/libc/string/strncat.cpp +++ b/libc/string/strncat.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 . - string/strncat.cpp + string/strncat.c Appends parts of a string onto another string. *******************************************************************************/ #include -extern "C" char* strncat(char* dest, const char* src, size_t n) +char* strncat(char* dest, const char* src, size_t n) { size_t dest_len = strlen(dest); size_t i; diff --git a/libc/string/strncmp.cpp b/libc/string/strncmp.c similarity index 93% rename from libc/string/strncmp.cpp rename to libc/string/strncmp.c index 429ee066..0a862a47 100644 --- a/libc/string/strncmp.cpp +++ b/libc/string/strncmp.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 . - string/strncmp.cpp + string/strncmp.c Compares a prefix of two strings. *******************************************************************************/ #include -extern "C" int strncmp(const char* a, const char* b, size_t max_count) +int strncmp(const char* a, const char* b, size_t max_count) { for ( size_t i = 0; i < max_count; i++ ) { diff --git a/libc/string/strncpy.cpp b/libc/string/strncpy.c similarity index 93% rename from libc/string/strncpy.cpp rename to libc/string/strncpy.c index fa698657..3e638d65 100644 --- a/libc/string/strncpy.cpp +++ b/libc/string/strncpy.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 . - string/strncpy.cpp + string/strncpy.c Copies a string into a fixed size buffer and returns dest. *******************************************************************************/ #include -extern "C" char* strncpy(char* dest, const char* src, size_t n) +char* strncpy(char* dest, const char* src, size_t n) { size_t i; for ( i = 0; i < n && src[i] != '\0'; i++ ) diff --git a/libc/string/strndup.cpp b/libc/string/strndup.c similarity index 94% rename from libc/string/strndup.cpp rename to libc/string/strndup.c index 7f14a823..7025eb56 100644 --- a/libc/string/strndup.cpp +++ b/libc/string/strndup.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 . - string/strndup.cpp + string/strndup.c Creates a copy of a string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" char* strndup(const char* input, size_t n) +char* strndup(const char* input, size_t n) { size_t input_size = strnlen(input, n); char* result = (char*) malloc(input_size + 1); diff --git a/libc/string/strnlen.cpp b/libc/string/strnlen.c similarity index 93% rename from libc/string/strnlen.cpp rename to libc/string/strnlen.c index 4a1f130c..ad60f793 100644 --- a/libc/string/strnlen.cpp +++ b/libc/string/strnlen.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 . - string/strnlen.cpp + string/strnlen.c Returns the length of a fixed length string. *******************************************************************************/ #include -extern "C" size_t strnlen(const char* str, size_t maxlen) +size_t strnlen(const char* str, size_t maxlen) { size_t ret = 0; while ( ret < maxlen && str[ret] ) diff --git a/libc/string/strpbrk.cpp b/libc/string/strpbrk.c similarity index 93% rename from libc/string/strpbrk.cpp rename to libc/string/strpbrk.c index fb865ab9..f5e66a90 100644 --- a/libc/string/strpbrk.cpp +++ b/libc/string/strpbrk.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 . - string/strpbrk.cpp + string/strpbrk.c Search a string for any of a set of characters. *******************************************************************************/ #include -extern "C" char* strpbrk(const char* str, const char* accept) +char* strpbrk(const char* str, const char* accept) { size_t reject_length = strcspn(str, accept); if ( !str[reject_length] ) diff --git a/libc/string/strrchr.cpp b/libc/string/strrchr.c similarity index 94% rename from libc/string/strrchr.cpp rename to libc/string/strrchr.c index ebf380b2..e2eaf1ba 100644 --- a/libc/string/strrchr.cpp +++ b/libc/string/strrchr.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 . - string/strrchr.cpp + string/strrchr.c Searches a string for a specific character. *******************************************************************************/ +#include #include -extern "C" char* strrchr(const char* str, int uc) +char* strrchr(const char* str, int uc) { const unsigned char* ustr = (const unsigned char*) str; const char* last = NULL; diff --git a/libc/string/strsep.cpp b/libc/string/strsep.c similarity index 93% rename from libc/string/strsep.cpp rename to libc/string/strsep.c index 6fb95ac9..bc959a83 100644 --- a/libc/string/strsep.cpp +++ b/libc/string/strsep.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 . - string/strsep.cpp + string/strsep.c Extract a token from a string. *******************************************************************************/ #include -extern "C" char* strsep(char** string_ptr, const char* delim) +char* strsep(char** string_ptr, const char* delim) { char* token = *string_ptr; if ( !token ) diff --git a/libc/string/strsignal.cpp b/libc/string/strsignal.c similarity index 95% rename from libc/string/strsignal.cpp rename to libc/string/strsignal.c index 56981ab6..75155d2c 100644 --- a/libc/string/strsignal.cpp +++ b/libc/string/strsignal.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 . - string/strsignal.cpp + string/strsignal.c Convert signal number to a string. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" const char* sortix_strsignal(int signum) +const char* sortix_strsignal(int signum) { switch ( signum ) { @@ -67,7 +67,7 @@ extern "C" const char* sortix_strsignal(int signum) return "Unknown signal value"; } -extern "C" char* strsignal(int signum) +char* strsignal(int signum) { return (char*) sortix_strsignal(signum); } diff --git a/libc/string/strspn.cpp b/libc/string/strspn.c similarity index 93% rename from libc/string/strspn.cpp rename to libc/string/strspn.c index 5114aa38..0951199b 100644 --- a/libc/string/strspn.cpp +++ b/libc/string/strspn.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 . - string/strspn.cpp + string/strspn.c Search a string for a set of characters. *******************************************************************************/ +#include #include -extern "C" size_t strspn(const char* str, const char* accept) +size_t strspn(const char* str, const char* accept) { size_t accept_length = 0; while ( accept[accept_length] ) diff --git a/libc/string/strstr.cpp b/libc/string/strstr.c similarity index 93% rename from libc/string/strstr.cpp rename to libc/string/strstr.c index f0cc78cd..9a78a967 100644 --- a/libc/string/strstr.cpp +++ b/libc/string/strstr.c @@ -17,16 +17,17 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strstr.cpp + string/strstr.c Locate a substring. *******************************************************************************/ +#include #include // TODO: This simple and hacky implementation runs in O(N^2) even though this // problem can be solved in O(N). -extern "C" char* strstr(const char* haystack, const char* needle) +char* strstr(const char* haystack, const char* needle) { if ( !needle[0] ) return (char*) haystack; diff --git a/libc/string/strtok.cpp b/libc/string/strtok.c similarity index 93% rename from libc/string/strtok.cpp rename to libc/string/strtok.c index e2309137..5dc14754 100644 --- a/libc/string/strtok.cpp +++ b/libc/string/strtok.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 . - string/strtok.cpp + string/strtok.c Extract tokens from strings. *******************************************************************************/ #include -extern "C" char* strtok(char* str, const char* delim) +char* strtok(char* str, const char* delim) { static char* lasttokensaveptr = NULL; return strtok_r(str, delim, &lasttokensaveptr); diff --git a/libc/string/strtok_r.cpp b/libc/string/strtok_r.c similarity index 93% rename from libc/string/strtok_r.cpp rename to libc/string/strtok_r.c index eff6eb3e..87f549c7 100644 --- a/libc/string/strtok_r.cpp +++ b/libc/string/strtok_r.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 . - string/strtok_r.cpp + string/strtok_r.c Extract tokens from strings. *******************************************************************************/ #include -extern "C" char* strtok_r(char* str, const char* delim, char** saveptr) +char* strtok_r(char* str, const char* delim, char** saveptr) { if ( !str && !*saveptr ) return NULL; diff --git a/libc/string/strverscmp.cpp b/libc/string/strverscmp.c similarity index 97% rename from libc/string/strverscmp.cpp rename to libc/string/strverscmp.c index bd0b0f59..c2adb858 100644 --- a/libc/string/strverscmp.cpp +++ b/libc/string/strverscmp.c @@ -17,11 +17,12 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strverscmp.cpp + string/strverscmp.c Compares two version strings. *******************************************************************************/ +#include #include static bool is_number(char c) @@ -34,7 +35,7 @@ static int to_number(char c) return c - '0'; } -extern "C" int strverscmp(const char* a, const char* b) +int strverscmp(const char* a, const char* b) { for ( size_t i = 0; true; i++ ) { diff --git a/libc/string/strxfrm.cpp b/libc/string/strxfrm.c similarity index 92% rename from libc/string/strxfrm.cpp rename to libc/string/strxfrm.c index 89ad62d0..e1fa32a4 100644 --- a/libc/string/strxfrm.cpp +++ b/libc/string/strxfrm.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 . - string/strxfrm.cpp + string/strxfrm.c Transform a string such that the result of strcmp is the same as strcoll. *******************************************************************************/ #include -extern "C" size_t strxfrm(char* dest, const char* src, size_t n) +size_t strxfrm(char* dest, const char* src, size_t n) { size_t srclen = strlen(src); strncpy(dest, src, n); diff --git a/libc/string/strxfrm_l.cpp b/libc/string/strxfrm_l.c similarity index 95% rename from libc/string/strxfrm_l.cpp rename to libc/string/strxfrm_l.c index 037cef89..77b09b09 100644 --- a/libc/string/strxfrm_l.cpp +++ b/libc/string/strxfrm_l.c @@ -17,15 +17,15 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - string/strxfrm_l.cpp + string/strxfrm_l.c Transform a string such that the result of strcmp is the same as strcoll_l. *******************************************************************************/ #include -extern "C" -size_t strxfrm_l(char* dest, const char* src, size_t n, locale_t /*locale*/) +size_t strxfrm_l(char* dest, const char* src, size_t n, locale_t locale) { + (void) locale; return strxfrm(dest, src, n); } diff --git a/libc/string/timingsafe_memcmp.cpp b/libc/string/timingsafe_memcmp.c similarity index 99% rename from libc/string/timingsafe_memcmp.cpp rename to libc/string/timingsafe_memcmp.c index d4ecb2d8..7f3262eb 100644 --- a/libc/string/timingsafe_memcmp.cpp +++ b/libc/string/timingsafe_memcmp.c @@ -26,7 +26,6 @@ // from branching on the information (and such). // TODO: We should add testcases that verify this is actually timing safe. -extern "C" int timingsafe_memcmp(const void* a_ptr, const void* b_ptr, size_t size) { const unsigned char* a = (const unsigned char*) a_ptr; diff --git a/libc/sys/display/dispmsg_issue.cpp b/libc/sys/display/dispmsg_issue.c similarity index 93% rename from libc/sys/display/dispmsg_issue.cpp rename to libc/sys/display/dispmsg_issue.c index 9e7f37c1..fd631e1b 100644 --- a/libc/sys/display/dispmsg_issue.cpp +++ b/libc/sys/display/dispmsg_issue.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 . - sys/display/dispmsg_issue.cpp + sys/display/dispmsg_issue.c Send a message to the display engine. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_dispmsg_issue, SYSCALL_DISPMSG_ISSUE, void*, size_t); -extern "C" int dispmsg_issue(void* ptr, size_t size) +int dispmsg_issue(void* ptr, size_t size) { return sys_dispmsg_issue(ptr, size); } diff --git a/libc/sys/ioctl/ioctl.cpp b/libc/sys/ioctl/ioctl.c similarity index 95% rename from libc/sys/ioctl/ioctl.cpp rename to libc/sys/ioctl/ioctl.c index 36bae922..0fdf0162 100644 --- a/libc/sys/ioctl/ioctl.cpp +++ b/libc/sys/ioctl/ioctl.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 . - sys/ioctl/ioctl.cpp + sys/ioctl/ioctl.c Miscellaneous device control interface. *******************************************************************************/ @@ -31,7 +31,7 @@ DEFN_SYSCALL3(int, sys_ioctl, SYSCALL_IOCTL, int, int, uintptr_t); -extern "C" int ioctl(int fd, int request, ...) +int ioctl(int fd, int request, ...) { uintptr_t arg; va_list ap; diff --git a/libc/sys/kernelinfo/kernelinfo.cpp b/libc/sys/kernelinfo/kernelinfo.c similarity index 91% rename from libc/sys/kernelinfo/kernelinfo.cpp rename to libc/sys/kernelinfo/kernelinfo.c index abdaa7c9..1c88efa9 100644 --- a/libc/sys/kernelinfo/kernelinfo.cpp +++ b/libc/sys/kernelinfo/kernelinfo.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 . - sys/kernelinfo/kernelinfo.cpp + sys/kernelinfo/kernelinfo.c Queries information about the kernel. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(ssize_t, sys_kernelinfo, SYSCALL_KERNELINFO, const char*, char*, size_t); -extern "C" ssize_t kernelinfo(const char* req, char* resp, size_t resplen) +ssize_t kernelinfo(const char* req, char* resp, size_t resplen) { return sys_kernelinfo(req, resp, resplen); } diff --git a/libc/sys/mman/mmap.cpp b/libc/sys/mman/mmap.c similarity index 98% rename from libc/sys/mman/mmap.cpp rename to libc/sys/mman/mmap.c index d7ed379c..bea1fad7 100644 --- a/libc/sys/mman/mmap.cpp +++ b/libc/sys/mman/mmap.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 . - sys/mman/mmap.cpp + sys/mman/mmap.c Maps a window of a file into memory. *******************************************************************************/ @@ -48,7 +48,6 @@ static void* mmap_wrapper(struct mmap_request* request) return sys_mmap_wrapper(request); } -extern "C" void* mmap(void* addr, size_t size, int prot, int flags, int fd, off_t offset) { struct mmap_request request = { addr, size, prot, flags, fd, offset }; diff --git a/libc/sys/mman/mprotect.cpp b/libc/sys/mman/mprotect.c similarity index 92% rename from libc/sys/mman/mprotect.cpp rename to libc/sys/mman/mprotect.c index caac808d..e3d1710f 100644 --- a/libc/sys/mman/mprotect.cpp +++ b/libc/sys/mman/mprotect.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 . - sys/mman/mprotect.cpp + sys/mman/mprotect.c Changes the protection of a memory region. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(int, sys_mprotect, SYSCALL_MPROTECT, const void*, size_t, int); -extern "C" int mprotect(const void* addr, size_t size, int prot) +int mprotect(const void* addr, size_t size, int prot) { return sys_mprotect(addr, size, prot); } diff --git a/libc/sys/mman/munmap.cpp b/libc/sys/mman/munmap.c similarity index 94% rename from libc/sys/mman/munmap.cpp rename to libc/sys/mman/munmap.c index d52eb4b8..f4a78bb3 100644 --- a/libc/sys/mman/munmap.cpp +++ b/libc/sys/mman/munmap.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 . - sys/mman/munmap.cpp + sys/mman/munmap.c Unmaps a memory region. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_munmap, SYSCALL_MUNMAP, void*, size_t); -extern "C" int munmap(void* addr, size_t size) +int munmap(void* addr, size_t size) { return sys_munmap(addr, size); } diff --git a/libc/sys/mount/unmount.cpp b/libc/sys/mount/unmount.c similarity index 93% rename from libc/sys/mount/unmount.cpp rename to libc/sys/mount/unmount.c index 5e7cb9cb..eecf323d 100644 --- a/libc/sys/mount/unmount.cpp +++ b/libc/sys/mount/unmount.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 . - sys/mount/unmount.cpp + sys/mount/unmount.c Unmount filesystem at path. *******************************************************************************/ @@ -26,7 +26,7 @@ #include -extern "C" int unmount(const char* path, int flags) +int unmount(const char* path, int flags) { return unmountat(AT_FDCWD, path, flags); } diff --git a/libc/sys/mount/unmountat.cpp b/libc/sys/mount/unmountat.c similarity index 92% rename from libc/sys/mount/unmountat.cpp rename to libc/sys/mount/unmountat.c index 300152f6..2a2e7501 100644 --- a/libc/sys/mount/unmountat.cpp +++ b/libc/sys/mount/unmountat.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 . - sys/mount/unmountat.cpp + sys/mount/unmountat.c Unmount filesystem at path. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(int, sys_unmountat, SYSCALL_UNMOUNTAT, int, const char*, int); -extern "C" int unmountat(int dirfd, const char* path, int flags) +int unmountat(int dirfd, const char* path, int flags) { return sys_unmountat(dirfd, path, flags); } diff --git a/libc/sys/readdirents/readdirents.cpp b/libc/sys/readdirents/readdirents.c similarity index 91% rename from libc/sys/readdirents/readdirents.cpp rename to libc/sys/readdirents/readdirents.c index 6a54aeed..402191f9 100644 --- a/libc/sys/readdirents/readdirents.cpp +++ b/libc/sys/readdirents/readdirents.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 . - sys/readdirents/readdirents.cpp + sys/readdirents/readdirents.c Reads directory entries from a directory file descriptor. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(ssize_t, sys_readdirents, SYSCALL_READDIRENTS, int, struct dirent*, size_t); -extern "C" ssize_t readdirents(int fd, struct dirent* dirent, size_t size) +ssize_t readdirents(int fd, struct dirent* dirent, size_t size) { return sys_readdirents(fd, dirent, size); } diff --git a/libc/sys/resource/getpriority.cpp b/libc/sys/resource/getpriority.c similarity index 93% rename from libc/sys/resource/getpriority.cpp rename to libc/sys/resource/getpriority.c index 5d8615d5..c9c9568f 100644 --- a/libc/sys/resource/getpriority.cpp +++ b/libc/sys/resource/getpriority.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 . - sys/resource/getpriority.cpp + sys/resource/getpriority.c Get the scheduling priority of a process, process group, or user. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_getpriority, SYSCALL_GETPRIORITY, int, id_t); -extern "C" int getpriority(int which, id_t who) +int getpriority(int which, id_t who) { return sys_getpriority(which, who); } diff --git a/libc/sys/resource/getrlimit.cpp b/libc/sys/resource/getrlimit.c similarity index 92% rename from libc/sys/resource/getrlimit.cpp rename to libc/sys/resource/getrlimit.c index 6dfcf027..ae3d1434 100644 --- a/libc/sys/resource/getrlimit.cpp +++ b/libc/sys/resource/getrlimit.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 . - sys/resource/getrlimit.cpp + sys/resource/getrlimit.c Get the resource limits of the current process. *******************************************************************************/ @@ -27,7 +27,7 @@ #include -extern "C" int getrlimit(int resource, struct rlimit* limit) +int getrlimit(int resource, struct rlimit* limit) { return prlimit(0, resource, NULL, limit); } diff --git a/libc/sys/resource/getrusage.cpp b/libc/sys/resource/getrusage.c similarity index 95% rename from libc/sys/resource/getrusage.cpp rename to libc/sys/resource/getrusage.c index 08646228..3a3a0bd3 100644 --- a/libc/sys/resource/getrusage.cpp +++ b/libc/sys/resource/getrusage.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 . - sys/resource/getrusage.cpp + sys/resource/getrusage.c Get resource usage statistics. *******************************************************************************/ @@ -37,7 +37,7 @@ static struct timeval timeval_of_timespec(struct timespec ts) return tv; } -extern "C" int getrusage(int who, struct rusage* usage) +int getrusage(int who, struct rusage* usage) { struct tmns tmns; if ( timens(&tmns) != 0 ) diff --git a/libc/sys/resource/prlimit.cpp b/libc/sys/resource/prlimit.c similarity index 97% rename from libc/sys/resource/prlimit.cpp rename to libc/sys/resource/prlimit.c index 30ec0b2c..9c7d55a6 100644 --- a/libc/sys/resource/prlimit.cpp +++ b/libc/sys/resource/prlimit.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 . - sys/resource/prlimit.cpp + sys/resource/prlimit.c Access and modify the resource limits of the given process. *******************************************************************************/ @@ -31,7 +31,6 @@ DEFN_SYSCALL4(int, sys_prlimit, SYSCALL_PRLIMIT, const struct rlimit*, struct rlimit*); -extern "C" int prlimit(pid_t pid, int resource, const struct rlimit* new_limit, diff --git a/libc/sys/resource/setpriority.cpp b/libc/sys/resource/setpriority.c similarity index 92% rename from libc/sys/resource/setpriority.cpp rename to libc/sys/resource/setpriority.c index a63c30da..93940805 100644 --- a/libc/sys/resource/setpriority.cpp +++ b/libc/sys/resource/setpriority.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 . - sys/resource/setpriority.cpp + sys/resource/setpriority.c Set the scheduling priority of a process, process group, or user. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(int, sys_setpriority, SYSCALL_SETPRIORITY, int, id_t, int); -extern "C" int setpriority(int which, id_t who, int prio) +int setpriority(int which, id_t who, int prio) { return sys_setpriority(which, who, prio); } diff --git a/libc/sys/resource/setrlimit.cpp b/libc/sys/resource/setrlimit.c similarity index 92% rename from libc/sys/resource/setrlimit.cpp rename to libc/sys/resource/setrlimit.c index 391b8a0b..215f1aef 100644 --- a/libc/sys/resource/setrlimit.cpp +++ b/libc/sys/resource/setrlimit.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 . - sys/resource/setrlimit.cpp + sys/resource/setrlimit.c Set the resource limits of the current process. *******************************************************************************/ @@ -27,7 +27,7 @@ #include -extern "C" int setrlimit(int resource, const struct rlimit* limit) +int setrlimit(int resource, const struct rlimit* limit) { return prlimit(0, resource, limit, NULL); } diff --git a/libc/sys/select/select.cpp b/libc/sys/select/select.c similarity index 98% rename from libc/sys/select/select.cpp rename to libc/sys/select/select.c index b6893c95..58c1c83a 100644 --- a/libc/sys/select/select.cpp +++ b/libc/sys/select/select.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 . - sys/select/select.cpp + sys/select/select.c Waiting on multiple file descriptors. *******************************************************************************/ @@ -31,7 +31,6 @@ static const int READ_EVENTS = POLLIN | POLLRDNORM; static const int WRITE_EVENTS = POLLOUT | POLLWRNORM; static const int EXCEPT_EVENTS = POLLERR | POLLHUP; -extern "C" int select(int nfds, fd_set* restrict readfds, fd_set* restrict writefds, fd_set* restrict exceptfds, struct timeval* restrict timeout) { diff --git a/libc/sys/socket/accept.cpp b/libc/sys/socket/accept.c similarity index 88% rename from libc/sys/socket/accept.cpp rename to libc/sys/socket/accept.c index ee0ee4a3..c41eb6ca 100644 --- a/libc/sys/socket/accept.cpp +++ b/libc/sys/socket/accept.c @@ -17,15 +17,14 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - sys/socket/accept.cpp + sys/socket/accept.c Accepts a connection from a listening socket. *******************************************************************************/ #include -extern "C" int accept(int fd, struct sockaddr* restrict addr, - socklen_t* restrict addrlen) +int accept(int fd, struct sockaddr* restrict addr, socklen_t* restrict addrlen) { return accept4(fd, addr, addrlen, 0); } diff --git a/libc/sys/socket/accept4.cpp b/libc/sys/socket/accept4.c similarity index 91% rename from libc/sys/socket/accept4.cpp rename to libc/sys/socket/accept4.c index 03e0a856..459a36d6 100644 --- a/libc/sys/socket/accept4.cpp +++ b/libc/sys/socket/accept4.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 . - sys/socket/accept4.cpp + sys/socket/accept4.c Accepts a connection from a listening socket. *******************************************************************************/ @@ -29,8 +29,8 @@ DEFN_SYSCALL4(int, sys_accept4, SYSCALL_ACCEPT4, int, void*, size_t*, int); -extern "C" int accept4(int fd, struct sockaddr* restrict addr, - socklen_t* restrict addrlen, int flags) +int accept4(int fd, struct sockaddr* restrict addr, socklen_t* restrict addrlen, + int flags) { // Deal with that the kernel doesn't need to understand socklen_t. Since // that type is designed to be size_t-sized anyway, the compiler should be diff --git a/libc/sys/socket/bind.cpp b/libc/sys/socket/bind.c similarity index 92% rename from libc/sys/socket/bind.cpp rename to libc/sys/socket/bind.c index 8ecb7c51..2f553629 100644 --- a/libc/sys/socket/bind.cpp +++ b/libc/sys/socket/bind.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 . - sys/socket/bind.cpp + sys/socket/bind.c Binds a socket to an address. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(int, sys_bind, SYSCALL_BIND, int, const void*, size_t); -extern "C" int bind(int fd, const struct sockaddr* addr, socklen_t addrlen) +int bind(int fd, const struct sockaddr* addr, socklen_t addrlen) { return sys_bind(fd, addr, addrlen); } diff --git a/libc/sys/socket/connect.cpp b/libc/sys/socket/connect.c similarity index 91% rename from libc/sys/socket/connect.cpp rename to libc/sys/socket/connect.c index bad21550..22924629 100644 --- a/libc/sys/socket/connect.cpp +++ b/libc/sys/socket/connect.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 . - sys/socket/connect.cpp + sys/socket/connect.c Connects a socket to an address. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(int, sys_connect, SYSCALL_CONNECT, int, const void*, size_t); -extern "C" int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) +int connect(int fd, const struct sockaddr* addr, socklen_t addrlen) { return sys_connect(fd, addr, addrlen); } diff --git a/libc/sys/socket/getpeername.cpp b/libc/sys/socket/getpeername.c similarity index 96% rename from libc/sys/socket/getpeername.cpp rename to libc/sys/socket/getpeername.c index 995fad24..d55f112e 100644 --- a/libc/sys/socket/getpeername.cpp +++ b/libc/sys/socket/getpeername.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 . - sys/socket/getpeername.cpp + sys/socket/getpeername.c Get name of connected peer socket. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL3(int, sys_getpeername, SYSCALL_GETPEERNAME, int, struct sockaddr*, socklen_t*); -extern "C" int getpeername(int fd, struct sockaddr* restrict addr, socklen_t* restrict addrsize) diff --git a/libc/sys/socket/getsockname.cpp b/libc/sys/socket/getsockname.c similarity index 96% rename from libc/sys/socket/getsockname.cpp rename to libc/sys/socket/getsockname.c index 80d3c140..504f5b82 100644 --- a/libc/sys/socket/getsockname.cpp +++ b/libc/sys/socket/getsockname.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 . - sys/socket/getsockname.cpp + sys/socket/getsockname.c Get socket name. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL3(int, sys_getsockname, SYSCALL_GETSOCKNAME, int, struct sockaddr*, socklen_t*); -extern "C" int getsockname(int fd, struct sockaddr* restrict addr, socklen_t* restrict addrsize) diff --git a/libc/sys/socket/getsockopt.cpp b/libc/sys/socket/getsockopt.c similarity index 97% rename from libc/sys/socket/getsockopt.cpp rename to libc/sys/socket/getsockopt.c index a9db4d25..d96028ec 100644 --- a/libc/sys/socket/getsockopt.cpp +++ b/libc/sys/socket/getsockopt.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 . - sys/socket/getsockopt.cpp + sys/socket/getsockopt.c Get socket options. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL5(int, sys_getsockopt, SYSCALL_GETSOCKOPT, int, int, int, const void*, size_t*); -extern "C" int getsockopt(int fd, int level, int option_name, void* restrict option_value, socklen_t* restrict option_size) { diff --git a/libc/sys/socket/listen.cpp b/libc/sys/socket/listen.c similarity index 94% rename from libc/sys/socket/listen.cpp rename to libc/sys/socket/listen.c index 33f5a3a5..aaf229d6 100644 --- a/libc/sys/socket/listen.cpp +++ b/libc/sys/socket/listen.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 . - sys/socket/listen.cpp + sys/socket/listen.c Listens for connections on a socket. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_listen, SYSCALL_LISTEN, int, int); -extern "C" int listen(int fd, int backlog) +int listen(int fd, int backlog) { return sys_listen(fd, backlog); } diff --git a/libc/sys/socket/recv.cpp b/libc/sys/socket/recv.c similarity index 92% rename from libc/sys/socket/recv.cpp rename to libc/sys/socket/recv.c index 1d0d9f27..9ebcf7d3 100644 --- a/libc/sys/socket/recv.cpp +++ b/libc/sys/socket/recv.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 . - sys/socket/recv.cpp + sys/socket/recv.c Receive data on a socket. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL4(ssize_t, sys_recv, SYSCALL_RECV, int, void*, size_t, int); -extern "C" ssize_t recv(int fd, void* buf, size_t count, int flags) +ssize_t recv(int fd, void* buf, size_t count, int flags) { return sys_recv(fd, buf, count, flags); } diff --git a/libc/sys/socket/recvfrom.cpp b/libc/sys/socket/recvfrom.c similarity index 97% rename from libc/sys/socket/recvfrom.cpp rename to libc/sys/socket/recvfrom.c index adad2c88..76cd9edb 100644 --- a/libc/sys/socket/recvfrom.cpp +++ b/libc/sys/socket/recvfrom.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 . - sys/socket/recvfrom.cpp + sys/socket/recvfrom.c Receive a message from a socket. *******************************************************************************/ @@ -26,7 +26,6 @@ #include -extern "C" ssize_t recvfrom(int fd, void* restrict buffer, size_t buffer_size, diff --git a/libc/sys/socket/recvmsg.cpp b/libc/sys/socket/recvmsg.c similarity index 92% rename from libc/sys/socket/recvmsg.cpp rename to libc/sys/socket/recvmsg.c index 144e30a5..fb0f072c 100644 --- a/libc/sys/socket/recvmsg.cpp +++ b/libc/sys/socket/recvmsg.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 . - sys/socket/recvmsg.cpp + sys/socket/recvmsg.c Receive a message on a socket. *******************************************************************************/ @@ -30,7 +30,7 @@ DEFN_SYSCALL3(ssize_t, sys_recvmsg, SYSCALL_RECVMSG, int, struct msghdr*, int); -extern "C" ssize_t recvmsg(int fd, struct msghdr* msg, int flags) +ssize_t recvmsg(int fd, struct msghdr* msg, int flags) { return sys_recvmsg(fd, msg, flags); } diff --git a/libc/sys/socket/send.cpp b/libc/sys/socket/send.c similarity index 92% rename from libc/sys/socket/send.cpp rename to libc/sys/socket/send.c index daabc9d1..449906bb 100644 --- a/libc/sys/socket/send.cpp +++ b/libc/sys/socket/send.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 . - sys/socket/send.cpp + sys/socket/send.c Receive data on a socket. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL4(ssize_t, sys_send, SYSCALL_SEND, int, const void*, size_t, int); -extern "C" ssize_t send(int fd, const void* buf, size_t count, int flags) +ssize_t send(int fd, const void* buf, size_t count, int flags) { return sys_send(fd, buf, count, flags); } diff --git a/libc/sys/socket/sendmsg.cpp b/libc/sys/socket/sendmsg.c similarity index 92% rename from libc/sys/socket/sendmsg.cpp rename to libc/sys/socket/sendmsg.c index 73b15887..954ec397 100644 --- a/libc/sys/socket/sendmsg.cpp +++ b/libc/sys/socket/sendmsg.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 . - sys/socket/sendmsg.cpp + sys/socket/sendmsg.c Send a message on a socket. *******************************************************************************/ @@ -30,7 +30,7 @@ DEFN_SYSCALL3(ssize_t, sys_sendmsg, SYSCALL_SENDMSG, int, const struct msghdr*, int); -extern "C" ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) +ssize_t sendmsg(int fd, const struct msghdr* msg, int flags) { return sys_sendmsg(fd, msg, flags); } diff --git a/libc/sys/socket/sendto.cpp b/libc/sys/socket/sendto.c similarity index 97% rename from libc/sys/socket/sendto.cpp rename to libc/sys/socket/sendto.c index a7a23c69..8b91e018 100644 --- a/libc/sys/socket/sendto.cpp +++ b/libc/sys/socket/sendto.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 . - sys/socket/sendto.cpp + sys/socket/sendto.c Send a message on a socket. *******************************************************************************/ @@ -26,7 +26,6 @@ #include -extern "C" ssize_t sendto(int fd, const void* buffer, size_t buffer_size, diff --git a/libc/sys/socket/setsockopt.cpp b/libc/sys/socket/setsockopt.c similarity index 96% rename from libc/sys/socket/setsockopt.cpp rename to libc/sys/socket/setsockopt.c index d3be27e2..ae32377e 100644 --- a/libc/sys/socket/setsockopt.cpp +++ b/libc/sys/socket/setsockopt.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 . - sys/socket/setsockopt.cpp + sys/socket/setsockopt.c Set socket options. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL5(int, sys_setsockopt, SYSCALL_SETSOCKOPT, int, int, int, const void*, size_t); -extern "C" int setsockopt(int fd, int level, int option_name, const void* option_value, socklen_t option_size) { diff --git a/libc/sys/socket/shutdown.cpp b/libc/sys/socket/shutdown.c similarity index 94% rename from libc/sys/socket/shutdown.cpp rename to libc/sys/socket/shutdown.c index 0431ede8..8c3f4aa2 100644 --- a/libc/sys/socket/shutdown.cpp +++ b/libc/sys/socket/shutdown.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 . - sys/socket/shutdown.cpp + sys/socket/shutdown.c Shut down part of a full-duplex connection. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_shutdown, SYSCALL_SHUTDOWN, int, int); -extern "C" int shutdown(int fd, int how) +int shutdown(int fd, int how) { return sys_shutdown(fd, how); } diff --git a/libc/sys/socket/sockatmark.cpp b/libc/sys/socket/sockatmark.c similarity index 94% rename from libc/sys/socket/sockatmark.cpp rename to libc/sys/socket/sockatmark.c index 7b635f4a..0836bc2b 100644 --- a/libc/sys/socket/sockatmark.cpp +++ b/libc/sys/socket/sockatmark.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 . - sys/socket/sockatmark.cpp + sys/socket/sockatmark.c Determine whether socket is at out-of-band mark. *******************************************************************************/ @@ -27,8 +27,9 @@ #include #include -extern "C" int sockatmark(int) +int sockatmark(int fd) { + (void) fd; fprintf(stderr, "%s is not implemented yet.\n", __func__); return errno = ENOSYS, -1; } diff --git a/libc/sys/socket/socket.cpp b/libc/sys/socket/socket.c similarity index 96% rename from libc/sys/socket/socket.cpp rename to libc/sys/socket/socket.c index 642eeadb..7d2e0df4 100644 --- a/libc/sys/socket/socket.cpp +++ b/libc/sys/socket/socket.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 . - sys/socket/socket.cpp + sys/socket/socket.c Creates a new unconnected socket. *******************************************************************************/ @@ -60,7 +60,7 @@ static const char* get_socket_factory(int domain, int type, int protocol) return errno = EAFNOSUPPORT, (const char*) NULL; } -extern "C" int socket(int domain, int type, int protocol) +int socket(int domain, int type, int protocol) { int open_flags = O_RDWR; if ( type & SOCK_NONBLOCK ) open_flags |= O_NONBLOCK; diff --git a/libc/sys/socket/socketpair.cpp b/libc/sys/socket/socketpair.c similarity index 97% rename from libc/sys/socket/socketpair.cpp rename to libc/sys/socket/socketpair.c index 73a474fb..a928da02 100644 --- a/libc/sys/socket/socketpair.cpp +++ b/libc/sys/socket/socketpair.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 . - sys/socket/socketpair.cpp + sys/socket/socketpair.c Create a pair of connected sockets. *******************************************************************************/ @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -133,7 +134,7 @@ static int socketpair_unix_stream(int flags, int fds[2]) } } -extern "C" int socketpair(int family, int type, int protocol, int fds[2]) +int socketpair(int family, int type, int protocol, int fds[2]) { if ( family == AF_UNIX ) { diff --git a/libc/sys/stat/chmod.cpp b/libc/sys/stat/chmod.c similarity index 93% rename from libc/sys/stat/chmod.cpp rename to libc/sys/stat/chmod.c index 7e759a8f..eff0366a 100644 --- a/libc/sys/stat/chmod.cpp +++ b/libc/sys/stat/chmod.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 . - sys/stat/chmod.cpp + sys/stat/chmod.c Changes the mode bits of a file. *******************************************************************************/ @@ -27,7 +27,7 @@ #include -extern "C" int chmod(const char* path, mode_t mode) +int chmod(const char* path, mode_t mode) { return fchmodat(AT_FDCWD, path, mode, 0); } diff --git a/libc/sys/stat/fchmod.cpp b/libc/sys/stat/fchmod.c similarity index 94% rename from libc/sys/stat/fchmod.cpp rename to libc/sys/stat/fchmod.c index 34a74a0a..8760f581 100644 --- a/libc/sys/stat/fchmod.cpp +++ b/libc/sys/stat/fchmod.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 . - sys/stat/fchmod.cpp + sys/stat/fchmod.c Changes the mode bits of an open file. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_fchmod, SYSCALL_FCHMOD, int, mode_t); -extern "C" int fchmod(int fd, mode_t mode) +int fchmod(int fd, mode_t mode) { return sys_fchmod(fd, mode); } diff --git a/libc/sys/stat/fchmodat.cpp b/libc/sys/stat/fchmodat.c similarity index 92% rename from libc/sys/stat/fchmodat.cpp rename to libc/sys/stat/fchmodat.c index a904ed9c..7d7568a6 100644 --- a/libc/sys/stat/fchmodat.cpp +++ b/libc/sys/stat/fchmodat.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 . - sys/stat/fchmodat.cpp + sys/stat/fchmodat.c Changes the mode bits of a file. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL4(int, sys_fchmodat, SYSCALL_FCHMODAT, int, const char*, mode_t, int); -extern "C" int fchmodat(int dirfd, const char* path, mode_t mode, int flags) +int fchmodat(int dirfd, const char* path, mode_t mode, int flags) { return sys_fchmodat(dirfd, path, mode, flags); } diff --git a/libc/sys/stat/fstat.cpp b/libc/sys/stat/fstat.c similarity index 94% rename from libc/sys/stat/fstat.cpp rename to libc/sys/stat/fstat.c index 282e275a..037de338 100644 --- a/libc/sys/stat/fstat.cpp +++ b/libc/sys/stat/fstat.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 . - sys/stat/fstat.cpp + sys/stat/fstat.c Retrieves status of an open file. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_fstat, SYSCALL_FSTAT, int, struct stat*); -extern "C" int fstat(int fd, struct stat* st) +int fstat(int fd, struct stat* st) { return sys_fstat(fd, st); } diff --git a/libc/sys/stat/fstatat.cpp b/libc/sys/stat/fstatat.c similarity index 91% rename from libc/sys/stat/fstatat.cpp rename to libc/sys/stat/fstatat.c index a45bdfc2..87318fad 100644 --- a/libc/sys/stat/fstatat.cpp +++ b/libc/sys/stat/fstatat.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 . - sys/stat/fstatat.cpp + sys/stat/fstatat.c Retrieves status of an open file. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL4(int, sys_fstatat, SYSCALL_FSTATAT, int, const char*, struct stat*, int); -extern "C" int fstatat(int dirfd, const char* path, struct stat* buf, int flags) +int fstatat(int dirfd, const char* path, struct stat* buf, int flags) { return sys_fstatat(dirfd, path, buf, flags); } diff --git a/libc/sys/stat/futimens.cpp b/libc/sys/stat/futimens.c similarity index 92% rename from libc/sys/stat/futimens.cpp rename to libc/sys/stat/futimens.c index a9f1f2b0..6672ff97 100644 --- a/libc/sys/stat/futimens.cpp +++ b/libc/sys/stat/futimens.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 . - sys/stat/futimens.cpp + sys/stat/futimens.c Change file last access and modification times. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_futimens, SYSCALL_FUTIMENS, int, const struct timespec*); -extern "C" int futimens(int fd, const struct timespec times[2]) +int futimens(int fd, const struct timespec times[2]) { return sys_futimens(fd, times); } diff --git a/libc/sys/stat/getumask.cpp b/libc/sys/stat/getumask.c similarity index 95% rename from libc/sys/stat/getumask.cpp rename to libc/sys/stat/getumask.c index 269a8115..741e3f99 100644 --- a/libc/sys/stat/getumask.cpp +++ b/libc/sys/stat/getumask.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 . - sys/stat/getumask.cpp + sys/stat/getumask.c Get file mode creation mask. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL0(mode_t, sys_getumask, SYSCALL_GETUMASK); -extern "C" mode_t getumask(void) +mode_t getumask(void) { return sys_getumask(); } diff --git a/libc/sys/stat/lstat.cpp b/libc/sys/stat/lstat.c similarity index 93% rename from libc/sys/stat/lstat.cpp rename to libc/sys/stat/lstat.c index 75cb18ec..dbc75b27 100644 --- a/libc/sys/stat/lstat.cpp +++ b/libc/sys/stat/lstat.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 . - sys/stat/lstat.cpp + sys/stat/lstat.c Retrieves status of a file. *******************************************************************************/ @@ -26,7 +26,7 @@ #include -extern "C" int lstat(const char* path, struct stat* st) +int lstat(const char* path, struct stat* st) { return fstatat(AT_FDCWD, path, st, AT_SYMLINK_NOFOLLOW); } diff --git a/libc/sys/stat/mkdir.cpp b/libc/sys/stat/mkdir.c similarity index 93% rename from libc/sys/stat/mkdir.cpp rename to libc/sys/stat/mkdir.c index 420ab661..cf52008b 100644 --- a/libc/sys/stat/mkdir.cpp +++ b/libc/sys/stat/mkdir.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 . - sys/stat/mkdir.cpp + sys/stat/mkdir.c Creates a new directory. *******************************************************************************/ @@ -26,7 +26,7 @@ #include -extern "C" int mkdir(const char* pathname, mode_t mode) +int mkdir(const char* pathname, mode_t mode) { return mkdirat(AT_FDCWD, pathname, mode); } diff --git a/libc/sys/stat/mkdirat.cpp b/libc/sys/stat/mkdirat.c similarity index 92% rename from libc/sys/stat/mkdirat.cpp rename to libc/sys/stat/mkdirat.c index 2635e02e..64510d21 100644 --- a/libc/sys/stat/mkdirat.cpp +++ b/libc/sys/stat/mkdirat.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 . - sys/stat/mkdirat.cpp + sys/stat/mkdirat.c Creates a new directory. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL3(int, sys_mkdirat, SYSCALL_MKDIRAT, int, const char*, mode_t); -extern "C" int mkdirat(int dirfd, const char* path, mode_t mode) +int mkdirat(int dirfd, const char* path, mode_t mode) { return sys_mkdirat(dirfd, path, mode); } diff --git a/libc/sys/stat/stat.cpp b/libc/sys/stat/stat.c similarity index 93% rename from libc/sys/stat/stat.cpp rename to libc/sys/stat/stat.c index f49f4b2d..1d2badce 100644 --- a/libc/sys/stat/stat.cpp +++ b/libc/sys/stat/stat.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 . - sys/stat/stat.cpp + sys/stat/stat.c Retrieves status of a file. *******************************************************************************/ @@ -26,7 +26,7 @@ #include -extern "C" int stat(const char* path, struct stat* st) +int stat(const char* path, struct stat* st) { return fstatat(AT_FDCWD, path, st, 0); } diff --git a/libc/sys/stat/umask.cpp b/libc/sys/stat/umask.c similarity index 94% rename from libc/sys/stat/umask.cpp rename to libc/sys/stat/umask.c index 397e652c..8a095419 100644 --- a/libc/sys/stat/umask.cpp +++ b/libc/sys/stat/umask.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 . - sys/stat/umask.cpp + sys/stat/umask.c Set file mode creation mask. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL1(mode_t, sys_umask, SYSCALL_UMASK, mode_t); -extern "C" mode_t umask(mode_t mask) +mode_t umask(mode_t mask) { return sys_umask(mask); } diff --git a/libc/sys/stat/utimens.cpp b/libc/sys/stat/utimens.c similarity index 97% rename from libc/sys/stat/utimens.cpp rename to libc/sys/stat/utimens.c index bc665213..8daff881 100644 --- a/libc/sys/stat/utimens.cpp +++ b/libc/sys/stat/utimens.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 . - sys/stat/utimens.cpp + sys/stat/utimens.c Change file last access and modification times. *******************************************************************************/ @@ -26,7 +26,6 @@ #include -extern "C" int utimens(const char* path, const struct timespec times[2]) { return utimensat(AT_FDCWD, path, times, 0); diff --git a/libc/sys/stat/utimensat.cpp b/libc/sys/stat/utimensat.c similarity index 97% rename from libc/sys/stat/utimensat.cpp rename to libc/sys/stat/utimensat.c index ae077b6e..0ac6a512 100644 --- a/libc/sys/stat/utimensat.cpp +++ b/libc/sys/stat/utimensat.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 . - sys/stat/utimensat.cpp + sys/stat/utimensat.c Change file last access and modification times. *******************************************************************************/ @@ -30,7 +30,6 @@ DEFN_SYSCALL4(int, sys_utimensat, SYSCALL_UTIMENSAT, int, const char*, const struct timespec*, int); -extern "C" int utimensat(int dirfd, const char* path, const struct timespec times[2], int flags) { diff --git a/libc/sys/statvfs/fstatvfs.cpp b/libc/sys/statvfs/fstatvfs.c similarity index 93% rename from libc/sys/statvfs/fstatvfs.cpp rename to libc/sys/statvfs/fstatvfs.c index 19fab561..267d44f8 100644 --- a/libc/sys/statvfs/fstatvfs.cpp +++ b/libc/sys/statvfs/fstatvfs.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 . - sys/statvfs/fstatvfs.cpp + sys/statvfs/fstatvfs.c Get virtual filesystem information. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_fstatvfs, SYSCALL_FSTATVFS, int, struct statvfs*); -extern "C" int fstatvfs(int fd, struct statvfs* stvfs) +int fstatvfs(int fd, struct statvfs* stvfs) { return sys_fstatvfs(fd, stvfs); } diff --git a/libc/sys/statvfs/fstatvfsat.cpp b/libc/sys/statvfs/fstatvfsat.c similarity index 96% rename from libc/sys/statvfs/fstatvfsat.cpp rename to libc/sys/statvfs/fstatvfsat.c index a551cb8d..e953e572 100644 --- a/libc/sys/statvfs/fstatvfsat.cpp +++ b/libc/sys/statvfs/fstatvfsat.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 . - sys/statvfs/fstatvfsat.cpp + sys/statvfs/fstatvfsat.c Get virtual filesystem information. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL4(int, sys_fstatvfsat, SYSCALL_FSTATVFSAT, int, const char*, struct statvfs*, int); -extern "C" int fstatvfsat(int dirfd, const char* restrict path, struct statvfs* restrict stvfs, diff --git a/libc/sys/statvfs/statvfs.cpp b/libc/sys/statvfs/statvfs.c similarity index 96% rename from libc/sys/statvfs/statvfs.cpp rename to libc/sys/statvfs/statvfs.c index 909f024a..cdc2ca0c 100644 --- a/libc/sys/statvfs/statvfs.cpp +++ b/libc/sys/statvfs/statvfs.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 . - sys/statvfs/statvfs.cpp + sys/statvfs/statvfs.c Get virtual filesystem information. *******************************************************************************/ @@ -26,7 +26,6 @@ #include -extern "C" int statvfs(const char* restrict path, struct statvfs* restrict stvfs) { return fstatvfsat(AT_FDCWD, path, stvfs, 0); diff --git a/libc/sys/termmode/gettermmode.cpp b/libc/sys/termmode/gettermmode.c similarity index 93% rename from libc/sys/termmode/gettermmode.cpp rename to libc/sys/termmode/gettermmode.c index c5bed6e5..d4557e16 100644 --- a/libc/sys/termmode/gettermmode.cpp +++ b/libc/sys/termmode/gettermmode.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 . - sys/termmode/gettermmode.cpp + sys/termmode/gettermmode.c Gets the terminal modes. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_gettermmode, SYSCALL_GETTERMMODE, int, unsigned*); -extern "C" int gettermmode(int fd, unsigned* mode) +int gettermmode(int fd, unsigned* mode) { return sys_gettermmode(fd, mode); } diff --git a/libc/sys/termmode/settermmode.cpp b/libc/sys/termmode/settermmode.c similarity index 93% rename from libc/sys/termmode/settermmode.cpp rename to libc/sys/termmode/settermmode.c index d61ae275..9b59273c 100644 --- a/libc/sys/termmode/settermmode.cpp +++ b/libc/sys/termmode/settermmode.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 . - sys/termmode/settermmode.cpp + sys/termmode/settermmode.c Sets the terminal modes. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL2(int, sys_settermmode, SYSCALL_SETTERMMODE, int, unsigned); -extern "C" int settermmode(int fd, unsigned mode) +int settermmode(int fd, unsigned mode) { return sys_settermmode(fd, mode); } diff --git a/libc/sys/time/gettimeofday.cpp b/libc/sys/time/gettimeofday.c similarity index 92% rename from libc/sys/time/gettimeofday.cpp rename to libc/sys/time/gettimeofday.c index fd3feb87..8f2c154d 100644 --- a/libc/sys/time/gettimeofday.cpp +++ b/libc/sys/time/gettimeofday.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 . - sys/time/gettimeofday.cpp + sys/time/gettimeofday.c Get date and time. *******************************************************************************/ @@ -26,8 +26,9 @@ #include -extern "C" int gettimeofday(struct timeval* tp, void* /*tzp*/) +int gettimeofday(struct timeval* tp, void* tzp) { + (void) tzp; struct timespec now; if ( clock_gettime(CLOCK_REALTIME, &now) < 0 ) return -1; diff --git a/libc/sys/times/times.cpp b/libc/sys/times/times.c similarity index 97% rename from libc/sys/times/times.cpp rename to libc/sys/times/times.c index 3ffd39ba..80910a3e 100644 --- a/libc/sys/times/times.cpp +++ b/libc/sys/times/times.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 . - sys/times/times.cpp + sys/times/times.c Get process execution time statistics. *******************************************************************************/ @@ -44,7 +44,7 @@ clock_t timespec_to_clock(struct timespec t) } // TODO: This function is crap and has been replaced by timens or clock_gettime. -extern "C" clock_t times(struct tms* buf) +clock_t times(struct tms* buf) { if ( buf ) { diff --git a/libc/sys/uio/preadv.cpp b/libc/sys/uio/preadv.c similarity index 97% rename from libc/sys/uio/preadv.cpp rename to libc/sys/uio/preadv.c index 35f4b9e2..e9beea83 100644 --- a/libc/sys/uio/preadv.cpp +++ b/libc/sys/uio/preadv.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 . - sys/uio/preadv.cpp + sys/uio/preadv.c Read data into multiple buffers. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL4(ssize_t, sys_preadv, SYSCALL_PREADV, int, const struct iovec*, int, off_t); -extern "C" ssize_t preadv(int fd, const struct iovec* iov, int iovcnt, off_t offset) { return sys_preadv(fd, iov, iovcnt, offset); diff --git a/libc/sys/uio/pwritev.cpp b/libc/sys/uio/pwritev.c similarity index 97% rename from libc/sys/uio/pwritev.cpp rename to libc/sys/uio/pwritev.c index 80024dac..1703106d 100644 --- a/libc/sys/uio/pwritev.cpp +++ b/libc/sys/uio/pwritev.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 . - sys/uio/pwritev.cpp + sys/uio/pwritev.c Write data from multiple buffers. *******************************************************************************/ @@ -27,7 +27,6 @@ DEFN_SYSCALL4(ssize_t, sys_pwritev, SYSCALL_PWRITEV, int, const struct iovec*, int, off_t); -extern "C" ssize_t pwritev(int fd, const struct iovec* iov, int iovcnt, off_t offset) { return sys_pwritev(fd, iov, iovcnt, offset); diff --git a/libc/sys/uio/readv.cpp b/libc/sys/uio/readv.c similarity index 92% rename from libc/sys/uio/readv.cpp rename to libc/sys/uio/readv.c index 5e27cec1..4292e4ac 100644 --- a/libc/sys/uio/readv.cpp +++ b/libc/sys/uio/readv.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 . - sys/uio/readv.cpp + sys/uio/readv.c Read data into multiple buffers. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(ssize_t, sys_readv, SYSCALL_READV, int, const struct iovec*, int); -extern "C" ssize_t readv(int fd, const struct iovec* iov, int iovcnt) +ssize_t readv(int fd, const struct iovec* iov, int iovcnt) { return sys_readv(fd, iov, iovcnt); } diff --git a/libc/sys/uio/writev.cpp b/libc/sys/uio/writev.c similarity index 92% rename from libc/sys/uio/writev.cpp rename to libc/sys/uio/writev.c index 2300e9cd..eb6c6bbb 100644 --- a/libc/sys/uio/writev.cpp +++ b/libc/sys/uio/writev.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 . - sys/uio/writev.cpp + sys/uio/writev.c Write data from multiple buffers. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(ssize_t, sys_writev, SYSCALL_WRITEV, int, const struct iovec*, int); -extern "C" ssize_t writev(int fd, const struct iovec* iov, int iovcnt) +ssize_t writev(int fd, const struct iovec* iov, int iovcnt) { return sys_writev(fd, iov, iovcnt); } diff --git a/libc/sys/utsname/uname.cpp b/libc/sys/utsname/uname.c similarity index 97% rename from libc/sys/utsname/uname.cpp rename to libc/sys/utsname/uname.c index 0b1bdc93..5ccba1d1 100644 --- a/libc/sys/utsname/uname.cpp +++ b/libc/sys/utsname/uname.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 . - sys/utsname/uname.cpp + sys/utsname/uname.c Get name of the current system. *******************************************************************************/ @@ -52,7 +52,7 @@ static const char* hwplatform = "unknown"; #endif static const char* opsysname = BRAND_OPERATING_SYSTEM_NAME; -extern "C" int uname(struct utsname* name) +int uname(struct utsname* name) { if ( kernelinfo("name", name->sysname, sizeof(name->sysname)) != 0 ) strlcpy(name->sysname, "unknown", sizeof(name->sysname)); diff --git a/libc/sys/wait/wait.cpp b/libc/sys/wait/wait.c similarity index 94% rename from libc/sys/wait/wait.cpp rename to libc/sys/wait/wait.c index 13bc1741..5e2b1838 100644 --- a/libc/sys/wait/wait.cpp +++ b/libc/sys/wait/wait.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 . - sys/wait/wait.cpp + sys/wait/wait.c Wait for child process. *******************************************************************************/ #include -extern "C" pid_t wait(int* status) +pid_t wait(int* status) { return waitpid(-1, status, 0); } diff --git a/libc/sys/wait/waitpid.cpp b/libc/sys/wait/waitpid.c similarity index 93% rename from libc/sys/wait/waitpid.cpp rename to libc/sys/wait/waitpid.c index f5b0ec40..fd94d849 100644 --- a/libc/sys/wait/waitpid.cpp +++ b/libc/sys/wait/waitpid.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 . - sys/wait/waitpid.cpp + sys/wait/waitpid.c Wait for child process. *******************************************************************************/ @@ -27,7 +27,7 @@ DEFN_SYSCALL3(pid_t, sys_waitpid, SYSCALL_WAITPID, pid_t, int*, int); -extern "C" pid_t waitpid(pid_t pid, int* status, int options) +pid_t waitpid(pid_t pid, int* status, int options) { return sys_waitpid(pid, status, options); } diff --git a/libc/syslog/closelog.cpp b/libc/syslog/closelog.c similarity index 95% rename from libc/syslog/closelog.cpp rename to libc/syslog/closelog.c index b2ed2b85..304afc2e 100644 --- a/libc/syslog/closelog.cpp +++ b/libc/syslog/closelog.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 . - syslog/closelog.cpp + syslog/closelog.c Closes the connection to the system log. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void closelog(void) +void closelog(void) { if ( 0 <= __syslog_fd ) { diff --git a/libc/syslog/connectlog.cpp b/libc/syslog/connectlog.c similarity index 94% rename from libc/syslog/connectlog.cpp rename to libc/syslog/connectlog.c index 19de04dd..8a06e39d 100644 --- a/libc/syslog/connectlog.cpp +++ b/libc/syslog/connectlog.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 . - syslog/connectlog.cpp + syslog/connectlog.c Returns a file descriptor to the system log. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int connectlog(void) +int connectlog(void) { return open("/dev/tty", O_WRONLY | O_CLOEXEC); } diff --git a/libc/syslog/openlog.cpp b/libc/syslog/openlog.c similarity index 94% rename from libc/syslog/openlog.cpp rename to libc/syslog/openlog.c index 9d1ae790..a1988d78 100644 --- a/libc/syslog/openlog.cpp +++ b/libc/syslog/openlog.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 . - syslog/openlog.cpp + syslog/openlog.c Opens the connection to the system log. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" void openlog(const char* identity, int option, int facility) +void openlog(const char* identity, int option, int facility) { // Remember the identity to report in the system log events. free(__syslog_identity); diff --git a/libc/syslog/setlogmask.cpp b/libc/syslog/setlogmask.c similarity index 94% rename from libc/syslog/setlogmask.cpp rename to libc/syslog/setlogmask.c index 58a9a986..7d5551c2 100644 --- a/libc/syslog/setlogmask.cpp +++ b/libc/syslog/setlogmask.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 . - syslog/setlogmask.cpp + syslog/setlogmask.c Sets the log priority mask. *******************************************************************************/ #include -extern "C" int setlogmask(int mask) +int setlogmask(int mask) { int previous_mask = __syslog_mask; if ( mask ) diff --git a/libc/syslog/syslog.cpp b/libc/syslog/syslog.c similarity index 93% rename from libc/syslog/syslog.cpp rename to libc/syslog/syslog.c index 8ff0e76e..d1e6eefb 100644 --- a/libc/syslog/syslog.cpp +++ b/libc/syslog/syslog.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 . - syslog/syslog.cpp + syslog/syslog.c Logs a condition to the system log. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" void syslog(int priority, const char* format, ...) +void syslog(int priority, const char* format, ...) { va_list ap; va_start(ap, format); diff --git a/libc/syslog/vsyslog.cpp b/libc/syslog/vsyslog.c similarity index 88% rename from libc/syslog/vsyslog.cpp rename to libc/syslog/vsyslog.c index 9041bc7c..5b9ee6e8 100644 --- a/libc/syslog/vsyslog.cpp +++ b/libc/syslog/vsyslog.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 . - syslog/vsyslog.cpp + syslog/vsyslog.c Logs a condition to the system log. *******************************************************************************/ @@ -29,11 +29,11 @@ #include #include -extern "C" { char* __syslog_identity = NULL; } -extern "C" { int __syslog_facility = LOG_USER; } -extern "C" { int __syslog_fd = -1; } -extern "C" { int __syslog_mask = LOG_UPTO(LOG_DEBUG); } -extern "C" { int __syslog_option = 0; } +char* __syslog_identity = NULL; +int __syslog_facility = LOG_USER; +int __syslog_fd = -1; +int __syslog_mask = LOG_UPTO(LOG_DEBUG); +int __syslog_option = 0; // TODO: The transmitted string might be delivered in chunks using this dprintf // approach (plus there are multiple dprintf calls). We should buffer the @@ -42,7 +42,7 @@ extern "C" { int __syslog_option = 0; } // TODO: The log entry format here is just whatever some other system does. We // should work out the Sortix system log semantics and adapt this to that. -extern "C" void vsyslog(int priority, const char* format, va_list ap) +void vsyslog(int priority, const char* format, va_list ap) { // Drop the event if it doesn't fit the current priority mask. if ( !(LOG_MASK(LOG_PRI(priority)) & __syslog_mask) ) diff --git a/libc/termios/cfgetispeed.cpp b/libc/termios/cfgetispeed.c similarity index 92% rename from libc/termios/cfgetispeed.cpp rename to libc/termios/cfgetispeed.c index bc897380..a4481a43 100644 --- a/libc/termios/cfgetispeed.cpp +++ b/libc/termios/cfgetispeed.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 . - termios/cfgetispeed.cpp + termios/cfgetispeed.c Get termios input speed. *******************************************************************************/ #include -extern "C" speed_t cfgetispeed(const struct termios* tio) +speed_t cfgetispeed(const struct termios* tio) { return tio->c_ispeed; } diff --git a/libc/termios/cfgetospeed.cpp b/libc/termios/cfgetospeed.c similarity index 92% rename from libc/termios/cfgetospeed.cpp rename to libc/termios/cfgetospeed.c index f2f7e305..77b1cd68 100644 --- a/libc/termios/cfgetospeed.cpp +++ b/libc/termios/cfgetospeed.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 . - termios/cfgetospeed.cpp + termios/cfgetospeed.c Get termios output speed. *******************************************************************************/ #include -extern "C" speed_t cfgetospeed(const struct termios* tio) +speed_t cfgetospeed(const struct termios* tio) { return tio->c_ospeed; } diff --git a/libc/termios/cfsetispeed.cpp b/libc/termios/cfsetispeed.c similarity index 92% rename from libc/termios/cfsetispeed.cpp rename to libc/termios/cfsetispeed.c index 4130e0a2..8d76cc59 100644 --- a/libc/termios/cfsetispeed.cpp +++ b/libc/termios/cfsetispeed.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 . - termios/cfsetispeed.cpp + termios/cfsetispeed.c Set termios input speed. *******************************************************************************/ #include -extern "C" int cfsetispeed(struct termios* tio, speed_t speed) +int cfsetispeed(struct termios* tio, speed_t speed) { tio->c_ispeed = speed; return 0; diff --git a/libc/termios/cfsetospeed.cpp b/libc/termios/cfsetospeed.c similarity index 92% rename from libc/termios/cfsetospeed.cpp rename to libc/termios/cfsetospeed.c index 8ed87588..edd739ca 100644 --- a/libc/termios/cfsetospeed.cpp +++ b/libc/termios/cfsetospeed.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 . - termios/cfsetospeed.cpp + termios/cfsetospeed.c Set termios output speed. *******************************************************************************/ #include -extern "C" int cfsetospeed(struct termios* tio, speed_t speed) +int cfsetospeed(struct termios* tio, speed_t speed) { tio->c_ospeed = speed; return 0; diff --git a/libc/termios/tcdrain.cpp b/libc/termios/tcdrain.c similarity index 95% rename from libc/termios/tcdrain.cpp rename to libc/termios/tcdrain.c index 886dfff0..687dcc6d 100644 --- a/libc/termios/tcdrain.cpp +++ b/libc/termios/tcdrain.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 . - termios/tcdrain.cpp + termios/tcdrain.c Wait for transmission of output. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_tcdrain, SYSCALL_TCDRAIN, int); -extern "C" int tcdrain(int fd) +int tcdrain(int fd) { return sys_tcdrain(fd); } diff --git a/libc/termios/tcflow.cpp b/libc/termios/tcflow.c similarity index 94% rename from libc/termios/tcflow.cpp rename to libc/termios/tcflow.c index c72f9ee4..4699c862 100644 --- a/libc/termios/tcflow.cpp +++ b/libc/termios/tcflow.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 . - termios/tcflow.cpp + termios/tcflow.c Suspend or restart the transmission or reception of data. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcflow, SYSCALL_TCFLOW, int, int); -extern "C" int tcflow(int fd, int action) +int tcflow(int fd, int action) { return sys_tcflow(fd, action); } diff --git a/libc/termios/tcflush.cpp b/libc/termios/tcflush.c similarity index 94% rename from libc/termios/tcflush.cpp rename to libc/termios/tcflush.c index 6a1c0fa6..972d0e2b 100644 --- a/libc/termios/tcflush.cpp +++ b/libc/termios/tcflush.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 . - termios/tcflush.cpp + termios/tcflush.c Flush non-transmitted output data, non-read input data, or both. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcflush, SYSCALL_TCFLUSH, int, int); -extern "C" int tcflush(int fd, int queue_selector) +int tcflush(int fd, int queue_selector) { return sys_tcflush(fd, queue_selector); } diff --git a/libc/termios/tcgetattr.cpp b/libc/termios/tcgetattr.c similarity index 93% rename from libc/termios/tcgetattr.cpp rename to libc/termios/tcgetattr.c index b250cc3e..7145320f 100644 --- a/libc/termios/tcgetattr.cpp +++ b/libc/termios/tcgetattr.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 . - termios/tcgetattr.cpp + termios/tcgetattr.c Get the parameters associated with the terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcgetattr, SYSCALL_TCGETATTR, int, struct termios*); -extern "C" int tcgetattr(int fd, struct termios* tio) +int tcgetattr(int fd, struct termios* tio) { return sys_tcgetattr(fd, tio); } diff --git a/libc/termios/tcgetblob.cpp b/libc/termios/tcgetblob.c similarity index 91% rename from libc/termios/tcgetblob.cpp rename to libc/termios/tcgetblob.c index 83fd8cc2..55490f7a 100644 --- a/libc/termios/tcgetblob.cpp +++ b/libc/termios/tcgetblob.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 . - termios/tcgetblob.cpp + termios/tcgetblob.c Download a blob from a terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL4(int, sys_tcgetblob, SYSCALL_TCGETBLOB, int, const char*, void*, size_t); -extern "C" ssize_t tcgetblob(int fd, const char* name, void* buffer, size_t count) +ssize_t tcgetblob(int fd, const char* name, void* buffer, size_t count) { return sys_tcgetblob(fd, name, buffer, count); } diff --git a/libc/termios/tcgetsid.cpp b/libc/termios/tcgetsid.c similarity index 95% rename from libc/termios/tcgetsid.cpp rename to libc/termios/tcgetsid.c index 686ca8a6..fa3eb615 100644 --- a/libc/termios/tcgetsid.cpp +++ b/libc/termios/tcgetsid.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 . - termios/tcgetsid.cpp + termios/tcgetsid.c Get terminal session id. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_tcgetsid, SYSCALL_TCGETSID, int); -extern "C" pid_t tcgetsid(int fd) +pid_t tcgetsid(int fd) { return sys_tcgetsid(fd); } diff --git a/libc/termios/tcgetwincurpos.cpp b/libc/termios/tcgetwincurpos.c similarity index 92% rename from libc/termios/tcgetwincurpos.cpp rename to libc/termios/tcgetwincurpos.c index 27e829a9..e7b1db9a 100644 --- a/libc/termios/tcgetwincurpos.cpp +++ b/libc/termios/tcgetwincurpos.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 . - termios/tcgetwincurpos.cpp + termios/tcgetwincurpos.c Access to terminal cursor position. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcgetwincurpos, SYSCALL_TCGETWINCURPOS, int, struct wincurpos*); -extern "C" int tcgetwincurpos(int fd, struct wincurpos* ws) +int tcgetwincurpos(int fd, struct wincurpos* ws) { return sys_tcgetwincurpos(fd, ws); } diff --git a/libc/termios/tcgetwinsize.cpp b/libc/termios/tcgetwinsize.c similarity index 93% rename from libc/termios/tcgetwinsize.cpp rename to libc/termios/tcgetwinsize.c index ac574047..ba3d9ba3 100644 --- a/libc/termios/tcgetwinsize.cpp +++ b/libc/termios/tcgetwinsize.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 . - termios/tcgetwinsize.cpp + termios/tcgetwinsize.c Access to terminal resolution. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcgetwinsize, SYSCALL_TCGETWINSIZE, int, struct winsize*); -extern "C" int tcgetwinsize(int fd, struct winsize* ws) +int tcgetwinsize(int fd, struct winsize* ws) { return sys_tcgetwinsize(fd, ws); } diff --git a/libc/termios/tcsendbreak.cpp b/libc/termios/tcsendbreak.c similarity index 93% rename from libc/termios/tcsendbreak.cpp rename to libc/termios/tcsendbreak.c index f00b6620..d7c1ae21 100644 --- a/libc/termios/tcsendbreak.cpp +++ b/libc/termios/tcsendbreak.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 . - termios/tcsendbreak.cpp + termios/tcsendbreak.c Send a break for a specific duration. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcsendbreak, SYSCALL_TCSENDBREAK, int, int); -extern "C" int tcsendbreak(int fd, int duration) +int tcsendbreak(int fd, int duration) { return sys_tcsendbreak(fd, duration); } diff --git a/libc/termios/tcsetattr.cpp b/libc/termios/tcsetattr.c similarity index 92% rename from libc/termios/tcsetattr.cpp rename to libc/termios/tcsetattr.c index c2be4c31..15949eb1 100644 --- a/libc/termios/tcsetattr.cpp +++ b/libc/termios/tcsetattr.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 . - termios/tcsetattr.cpp + termios/tcsetattr.c Set the parameters associated with the terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(int, sys_tcsetattr, SYSCALL_TCSETATTR, int, int, const struct termios*); -extern "C" int tcsetattr(int fd, int actions, const struct termios* tio) +int tcsetattr(int fd, int actions, const struct termios* tio) { return sys_tcsetattr(fd, actions, tio); } diff --git a/libc/termios/tcsetblob.cpp b/libc/termios/tcsetblob.c similarity index 91% rename from libc/termios/tcsetblob.cpp rename to libc/termios/tcsetblob.c index 8faad547..268e35f8 100644 --- a/libc/termios/tcsetblob.cpp +++ b/libc/termios/tcsetblob.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 . - termios/tcsetblob.cpp + termios/tcsetblob.c Upload a blob to a terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL4(int, sys_tcsetblob, SYSCALL_TCSETBLOB, int, const char*, const void*, size_t); -extern "C" ssize_t tcsetblob(int fd, const char* name, const void* buffer, size_t count) +ssize_t tcsetblob(int fd, const char* name, const void* buffer, size_t count) { return sys_tcsetblob(fd, name, buffer, count); } diff --git a/libc/time/asctime.cpp b/libc/time/asctime.c similarity index 95% rename from libc/time/asctime.cpp rename to libc/time/asctime.c index f0c6bc14..46070ab8 100644 --- a/libc/time/asctime.cpp +++ b/libc/time/asctime.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 . - time/asctime.cpp + time/asctime.c Convert date and time to a string. *******************************************************************************/ @@ -29,7 +29,7 @@ // TODO: Oh god. This function is horrible! It's obsolescent in POSIX - but it's // still widely used and I need it at the moment to port software. Please // do remove this function when all the calls to it has been purged. -extern "C" char* asctime(const struct tm* tm) +char* asctime(const struct tm* tm) { static char buf[26]; return asctime_r(tm, buf); diff --git a/libc/time/asctime_r.cpp b/libc/time/asctime_r.c similarity index 95% rename from libc/time/asctime_r.cpp rename to libc/time/asctime_r.c index 1dfc86d0..d18b430b 100644 --- a/libc/time/asctime_r.cpp +++ b/libc/time/asctime_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 . - time/asctime_r.cpp + time/asctime_r.c Convert date and time to a string. *******************************************************************************/ @@ -29,7 +29,7 @@ // TODO: Oh god. This function is horrible! It's obsolescent in POSIX - but it's // still widely used and I need it at the moment to port software. Please // do remove this function when all the calls to it has been purged. -extern "C" char* asctime_r(const struct tm* tm, char* buf) +char* asctime_r(const struct tm* tm, char* buf) { static char weekday_names[7][4] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; diff --git a/libc/time/clock.cpp b/libc/time/clock.c similarity index 96% rename from libc/time/clock.cpp rename to libc/time/clock.c index fcd5111c..8d45dea3 100644 --- a/libc/time/clock.cpp +++ b/libc/time/clock.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 . - time/clock.cpp + time/clock.c Get process execution time. *******************************************************************************/ @@ -26,7 +26,7 @@ #include // TODO: This function is crap and has been replaced by clock_gettime. -extern "C" clock_t clock() +clock_t clock(void) { struct timespec now; if ( clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now) < 0 ) diff --git a/libc/time/clock_getres.cpp b/libc/time/clock_getres.c similarity index 91% rename from libc/time/clock_getres.cpp rename to libc/time/clock_getres.c index 9fc1d1f9..745cea67 100644 --- a/libc/time/clock_getres.cpp +++ b/libc/time/clock_getres.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 . - time/clock_getres.cpp + time/clock_getres.c Get clock resolution. *******************************************************************************/ #include -extern "C" int clock_getres(clockid_t clockid, struct timespec* res) +int clock_getres(clockid_t clockid, struct timespec* res) { return clock_gettimeres(clockid, NULL, res); } diff --git a/libc/time/clock_gettime.cpp b/libc/time/clock_gettime.c similarity index 91% rename from libc/time/clock_gettime.cpp rename to libc/time/clock_gettime.c index d01fd061..df19cf0d 100644 --- a/libc/time/clock_gettime.cpp +++ b/libc/time/clock_gettime.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 . - time/clock_gettime.cpp + time/clock_gettime.c Get clock time. *******************************************************************************/ #include -extern "C" int clock_gettime(clockid_t clockid, struct timespec* time) +int clock_gettime(clockid_t clockid, struct timespec* time) { return clock_gettimeres(clockid, time, NULL); } diff --git a/libc/time/clock_gettimeres.cpp b/libc/time/clock_gettimeres.c similarity index 87% rename from libc/time/clock_gettimeres.cpp rename to libc/time/clock_gettimeres.c index 987d389d..e042308c 100644 --- a/libc/time/clock_gettimeres.cpp +++ b/libc/time/clock_gettimeres.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 . - time/clock_gettimeres.cpp + time/clock_gettimeres.c Get clock time and resolution. *******************************************************************************/ @@ -29,8 +29,9 @@ DEFN_SYSCALL3(int, sys_clock_gettimeres, SYSCALL_CLOCK_GETTIMERES, clockid_t, struct timespec*, struct timespec*); -extern "C" int clock_gettimeres(clockid_t clockid, struct timespec* time, - struct timespec* res) +int clock_gettimeres(clockid_t clockid, + struct timespec* time, + struct timespec* res) { return sys_clock_gettimeres(clockid, time, res); } diff --git a/libc/time/clock_nanosleep.cpp b/libc/time/clock_nanosleep.c similarity index 97% rename from libc/time/clock_nanosleep.cpp rename to libc/time/clock_nanosleep.c index dedbbc93..758f6903 100644 --- a/libc/time/clock_nanosleep.cpp +++ b/libc/time/clock_nanosleep.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 . - time/clock_nanosleep.cpp + time/clock_nanosleep.c Sleep for a duration on a clock. *******************************************************************************/ @@ -29,7 +29,6 @@ DEFN_SYSCALL4(int, sys_clock_nanosleep, SYSCALL_CLOCK_NANOSLEEP, clockid_t, int, const struct timespec*, struct timespec*); -extern "C" int clock_nanosleep(clockid_t clockid, int flags, const struct timespec* duration, struct timespec* remainder) { diff --git a/libc/time/clock_settime.cpp b/libc/time/clock_settime.c similarity index 90% rename from libc/time/clock_settime.cpp rename to libc/time/clock_settime.c index c7609f96..27d28dff 100644 --- a/libc/time/clock_settime.cpp +++ b/libc/time/clock_settime.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 . - time/clock_settime.cpp + time/clock_settime.c Set clock time. *******************************************************************************/ #include -extern "C" int clock_settime(clockid_t clockid, const struct timespec* time) +int clock_settime(clockid_t clockid, const struct timespec* time) { return clock_settimeres(clockid, time, NULL); } diff --git a/libc/time/clock_settimeres.cpp b/libc/time/clock_settimeres.c similarity index 86% rename from libc/time/clock_settimeres.cpp rename to libc/time/clock_settimeres.c index 049e8f18..1f50ef91 100644 --- a/libc/time/clock_settimeres.cpp +++ b/libc/time/clock_settimeres.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 . - time/clock_settimeres.cpp + time/clock_settimeres.c Set clock time and resolution. *******************************************************************************/ @@ -29,8 +29,9 @@ DEFN_SYSCALL3(int, sys_clock_settimeres, SYSCALL_CLOCK_SETTIMERES, clockid_t, const struct timespec*, const struct timespec*); -extern "C" int clock_settimeres(clockid_t clockid, const struct timespec* time, - const struct timespec* res) +int clock_settimeres(clockid_t clockid, + const struct timespec* time, + const struct timespec* res) { return sys_clock_settimeres(clockid, time, res); } diff --git a/libc/time/ctime.cpp b/libc/time/ctime.c similarity index 94% rename from libc/time/ctime.cpp rename to libc/time/ctime.c index 31e86515..ea334947 100644 --- a/libc/time/ctime.cpp +++ b/libc/time/ctime.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 . - time/ctime.cpp + time/ctime.c Convert a time value to a date and time string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include // TODO: Gah, remove this as well when asctime is removed. -extern "C" char* ctime(const time_t* clock) +char* ctime(const time_t* clock) { return asctime(localtime(clock)); } diff --git a/libc/time/ctime_r.cpp b/libc/time/ctime_r.c similarity index 93% rename from libc/time/ctime_r.cpp rename to libc/time/ctime_r.c index adab97e3..b41fea69 100644 --- a/libc/time/ctime_r.cpp +++ b/libc/time/ctime_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 . - time/ctime_r.cpp + time/ctime_r.c Convert a time value to a date and time string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include // TODO: Gah, remove this as well when asctime_r is removed. -extern "C" char* ctime_r(const time_t* clock, char* buf) +char* ctime_r(const time_t* clock, char* buf) { return asctime_r(localtime(clock), buf); } diff --git a/libc/time/difftime.cpp b/libc/time/difftime.c similarity index 93% rename from libc/time/difftime.cpp rename to libc/time/difftime.c index 459e16cc..eaa9d72f 100644 --- a/libc/time/difftime.cpp +++ b/libc/time/difftime.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 . - time/difftime.cpp + time/difftime.c Calculate time difference. *******************************************************************************/ #include -extern "C" double difftime(time_t a, time_t b) +double difftime(time_t a, time_t b) { return (double) (a - b); } diff --git a/libc/time/gmtime.cpp b/libc/time/gmtime.c similarity index 94% rename from libc/time/gmtime.cpp rename to libc/time/gmtime.c index 479450ee..a9997b0e 100644 --- a/libc/time/gmtime.cpp +++ b/libc/time/gmtime.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 . - time/gmtime.cpp + time/gmtime.c Convert a timestamp into a date and time according to the local timezone. *******************************************************************************/ #include -extern "C" struct tm* gmtime(const time_t* timer) +struct tm* gmtime(const time_t* timer) { static struct tm hack_gmtime_ret; return gmtime_r(timer, &hack_gmtime_ret); diff --git a/libc/time/gmtime_r.cpp b/libc/time/gmtime_r.c similarity index 98% rename from libc/time/gmtime_r.cpp rename to libc/time/gmtime_r.c index 177db40a..ec66c947 100644 --- a/libc/time/gmtime_r.cpp +++ b/libc/time/gmtime_r.c @@ -17,11 +17,12 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - time/gmtime_r.cpp + time/gmtime_r.c Convert a timestamp into a date and time according to UTC. *******************************************************************************/ +#include #include #include @@ -132,7 +133,7 @@ static time_t days_in_year(int year) DAYS_DECEMBER; } -extern "C" struct tm* gmtime_r(const time_t* time_ptr, struct tm* ret) +struct tm* gmtime_r(const time_t* time_ptr, struct tm* ret) { time_t left = *time_ptr; @@ -242,7 +243,7 @@ extern "C" struct tm* gmtime_r(const time_t* time_ptr, struct tm* ret) return ret; } -extern "C" time_t timegm(struct tm* tm) +time_t timegm(struct tm* tm) { time_t year = tm->tm_year + 1900; time_t month = tm->tm_mon; diff --git a/libc/time/localtime.cpp b/libc/time/localtime.c similarity index 93% rename from libc/time/localtime.cpp rename to libc/time/localtime.c index c11caedf..da5ebf40 100644 --- a/libc/time/localtime.cpp +++ b/libc/time/localtime.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 . - time/localtime.cpp + time/localtime.c Convert a timestamp into a date and time according to the local timezone. *******************************************************************************/ #include -extern "C" struct tm* localtime(const time_t* timer) +struct tm* localtime(const time_t* timer) { static struct tm hack_localtime_ret; return localtime_r(timer, &hack_localtime_ret); diff --git a/libc/time/localtime_r.cpp b/libc/time/localtime_r.c similarity index 92% rename from libc/time/localtime_r.cpp rename to libc/time/localtime_r.c index 5735a734..ad172757 100644 --- a/libc/time/localtime_r.cpp +++ b/libc/time/localtime_r.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 . - time/localtime_r.cpp + time/localtime_r.c Convert a timestamp into a date and time according to the local timezone. *******************************************************************************/ #include -extern "C" struct tm* localtime_r(const time_t* time_ptr, struct tm* ret) +struct tm* localtime_r(const time_t* time_ptr, struct tm* ret) { struct tm utc_tm; if ( !gmtime_r(time_ptr, &utc_tm) ) diff --git a/libc/time/mktime.cpp b/libc/time/mktime.c similarity index 94% rename from libc/time/mktime.cpp rename to libc/time/mktime.c index e1477184..542aa0d2 100644 --- a/libc/time/mktime.cpp +++ b/libc/time/mktime.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 . - time/mktime.cpp + time/mktime.c Create time stamp from broken time time format. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" time_t mktime(struct tm* tm) +time_t mktime(struct tm* tm) { return timegm(tm); } diff --git a/libc/time/nanosleep.cpp b/libc/time/nanosleep.c similarity index 92% rename from libc/time/nanosleep.cpp rename to libc/time/nanosleep.c index c38fbe1a..30d460ca 100644 --- a/libc/time/nanosleep.cpp +++ b/libc/time/nanosleep.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 . - time/nanosleep.cpp + time/nanosleep.c Sleep for a duration. *******************************************************************************/ #include -extern "C" int nanosleep(const struct timespec* delay, struct timespec* left) +int nanosleep(const struct timespec* delay, struct timespec* left) { // NOTE: POSIX specifies that we should nanosleep on CLOCK_REALTIME, but it // makes more sense to sleep on the monotonic system clock. Futhermore diff --git a/libc/time/strftime.cpp b/libc/time/strftime.c similarity index 99% rename from libc/time/strftime.cpp rename to libc/time/strftime.c index f913509a..5002cbc0 100644 --- a/libc/time/strftime.cpp +++ b/libc/time/strftime.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 . - time/strftime.cpp + time/strftime.c Format time and date into a string. *******************************************************************************/ @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -131,7 +132,6 @@ size_t strftime_convert_int(STRFTIME_CHAR* destination, int value) return strftime_convert_uintmax(destination, (uintmax_t) value); } -extern "C" size_t STRFTIME(STRFTIME_CHAR* s, size_t max, const STRFTIME_CHAR* format, @@ -198,7 +198,8 @@ size_t STRFTIME(STRFTIME_CHAR* s, #define OUTPUT_UNDEFINED() OUTPUT_UNSUPPORTED() - while ( STRFTIME_CHAR c = *format++ ) + STRFTIME_CHAR c; + while ( (c = *format++) ) { if ( c != STRFTIME_L('%') ) { diff --git a/libc/time/strftime_l.cpp b/libc/time/strftime_l.c similarity index 91% rename from libc/time/strftime_l.cpp rename to libc/time/strftime_l.c index 07d03cce..0430372a 100644 --- a/libc/time/strftime_l.cpp +++ b/libc/time/strftime_l.c @@ -17,16 +17,16 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - time/strftime_l.cpp + time/strftime_l.c Format time and date into a string using the given locale. *******************************************************************************/ #include -extern "C" size_t strftime_l(char* restrict s, size_t max, const char* restrict format, - const struct tm* restrict tm, locale_t /*locale*/) + const struct tm* restrict tm, locale_t locale) { + (void) locale; return strftime(s, max, format, tm); } diff --git a/libc/time/time.cpp b/libc/time/time.c similarity index 95% rename from libc/time/time.cpp rename to libc/time/time.c index 44f3a50d..492138aa 100644 --- a/libc/time/time.cpp +++ b/libc/time/time.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 . - time/time.cpp + time/time.c Get time in seconds. *******************************************************************************/ #include -extern "C" time_t time(time_t* t) +time_t time(time_t* t) { struct timespec now; if ( clock_gettime(CLOCK_REALTIME, &now) < 0 ) diff --git a/libc/time/timegm.cpp b/libc/time/timegm.c similarity index 91% rename from libc/time/timegm.cpp rename to libc/time/timegm.c index 388d34d6..51e888e7 100644 --- a/libc/time/timegm.cpp +++ b/libc/time/timegm.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 . - time/timegm.cpp + time/timegm.c Create time stamp from broken time time format. *******************************************************************************/ @@ -25,4 +25,4 @@ #include #include -// Note: timegm has been moved to gmtime_r.cpp because it made more sense there. +// Note: timegm has been moved to gmtime_r.c because it made more sense there. diff --git a/libc/time/timens.cpp b/libc/time/timens.c similarity index 94% rename from libc/time/timens.cpp rename to libc/time/timens.c index 9119f13a..9dbdc3c5 100644 --- a/libc/time/timens.cpp +++ b/libc/time/timens.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 . - time/timens.cpp + time/timens.c Get process execution time statistics. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_timens, SYSCALL_TIMENS, struct tmns*); -extern "C" int timens(struct tmns* tmns) +int timens(struct tmns* tmns) { return sys_timens(tmns); } diff --git a/libc/time/timer_create.cpp b/libc/time/timer_create.c similarity index 88% rename from libc/time/timer_create.cpp rename to libc/time/timer_create.c index ca8f87ad..bd73958b 100644 --- a/libc/time/timer_create.cpp +++ b/libc/time/timer_create.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 . - time/timer_create.cpp + time/timer_create.c Creates a per-process timer. *******************************************************************************/ @@ -30,8 +30,9 @@ DEFN_SYSCALL3(int, sys_timer_create, SYSCALL_TIMER_CREATE, clockid_t, struct sigevent*, timer_t*); -extern "C" int timer_create(clockid_t clockid, struct sigevent* restrict evp, - timer_t* restrict timerid) +int timer_create(clockid_t clockid, + struct sigevent* restrict evp, + timer_t* restrict timerid) { return sys_timer_create(clockid, evp, timerid); } diff --git a/libc/time/timer_delete.cpp b/libc/time/timer_delete.c similarity index 94% rename from libc/time/timer_delete.cpp rename to libc/time/timer_delete.c index 6c675d28..797329d7 100644 --- a/libc/time/timer_delete.cpp +++ b/libc/time/timer_delete.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 . - time/timer_delete.cpp + time/timer_delete.c Delete a per-process timer. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_timer_delete, SYSCALL_TIMER_DELETE, timer_t); -extern "C" int timer_delete(timer_t timerid) +int timer_delete(timer_t timerid) { return sys_timer_delete(timerid); } diff --git a/libc/time/timer_getoverrun.cpp b/libc/time/timer_getoverrun.c similarity index 93% rename from libc/time/timer_getoverrun.cpp rename to libc/time/timer_getoverrun.c index d030526d..ac3c86d4 100644 --- a/libc/time/timer_getoverrun.cpp +++ b/libc/time/timer_getoverrun.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 . - time/timer_getoverrun.cpp + time/timer_getoverrun.c Retrieve number of missed events on a timer. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_timer_getoverrun, SYSCALL_TIMER_GETOVERRUN, timer_t); -extern "C" int timer_getoverrun(timer_t timerid) +int timer_getoverrun(timer_t timerid) { return sys_timer_getoverrun(timerid); } diff --git a/libc/time/timer_gettime.cpp b/libc/time/timer_gettime.c similarity index 92% rename from libc/time/timer_gettime.cpp rename to libc/time/timer_gettime.c index 144f22e4..05c1b629 100644 --- a/libc/time/timer_gettime.cpp +++ b/libc/time/timer_gettime.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 . - time/timer_gettime.cpp + time/timer_gettime.c Get time remaining on a timer. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL2(int, sys_timer_gettime, SYSCALL_TIMER_GETTIME, timer_t, struct itimerspec*); -extern "C" int timer_gettime(timer_t timerid, struct itimerspec* value) +int timer_gettime(timer_t timerid, struct itimerspec* value) { return sys_timer_gettime(timerid, value); } diff --git a/libc/time/timer_settime.cpp b/libc/time/timer_settime.c similarity index 84% rename from libc/time/timer_settime.cpp rename to libc/time/timer_settime.c index 2aec7db1..31af1696 100644 --- a/libc/time/timer_settime.cpp +++ b/libc/time/timer_settime.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 . - time/timer_settime.cpp + time/timer_settime.c Set time remaining on a timer. *******************************************************************************/ @@ -29,9 +29,10 @@ DEFN_SYSCALL4(int, sys_timer_settime, SYSCALL_TIMER_SETTIME, timer_t, int, const struct itimerspec*, struct itimerspec*); -extern "C" int timer_settime(timer_t timerid, int flags, - const struct itimerspec* restrict value, - struct itimerspec* restrict ovalue) +int timer_settime(timer_t timerid, + int flags, + const struct itimerspec* restrict value, + struct itimerspec* restrict ovalue) { return sys_timer_settime(timerid, flags, value, ovalue); } diff --git a/libc/time/tzset.cpp b/libc/time/tzset.c similarity index 90% rename from libc/time/tzset.cpp rename to libc/time/tzset.c index c5474059..f3e49062 100644 --- a/libc/time/tzset.cpp +++ b/libc/time/tzset.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 . - time/tzset.cpp + time/tzset.c Initialize time conversion information. *******************************************************************************/ @@ -25,9 +25,9 @@ #include #include -extern "C" { char* tzname[2] = { (char*) "UTC", (char*) "UTC" }; } +char* tzname[2] = { (char*) "UTC", (char*) "UTC" }; -extern "C" void tzset(void) +void tzset(void) { const char* tz = getenv("TZ"); if ( !tz ) diff --git a/libc/timespec/timespec.cpp b/libc/timespec/timespec.c similarity index 87% rename from libc/timespec/timespec.cpp rename to libc/timespec/timespec.c index 973e8e09..ceb911dd 100644 --- a/libc/timespec/timespec.cpp +++ b/libc/timespec/timespec.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 . - timespec/timespec.cpp + timespec/timespec.c Utility functions for manipulation of struct timespec. *******************************************************************************/ @@ -35,14 +35,14 @@ static long proper_modulo(long a, long b) return tmp ? tmp : 0; } -extern "C" struct timespec timespec_canonalize(struct timespec t) +struct timespec timespec_canonalize(struct timespec t) { t.tv_sec += t.tv_nsec / NANOSECONDS_PER_SECOND; t.tv_nsec = proper_modulo(t.tv_nsec, NANOSECONDS_PER_SECOND); return t; } -extern "C" struct timespec timespec_add(struct timespec a, struct timespec b) +struct timespec timespec_add(struct timespec a, struct timespec b) { struct timespec ret; a = timespec_canonalize(a); @@ -52,7 +52,7 @@ extern "C" struct timespec timespec_add(struct timespec a, struct timespec b) return timespec_canonalize(ret); } -extern "C" struct timespec timespec_sub(struct timespec a, struct timespec b) +struct timespec timespec_sub(struct timespec a, struct timespec b) { a = timespec_canonalize(a); b = timespec_canonalize(b); diff --git a/libc/ubsan/ubsan.cpp b/libc/ubsan/ubsan.c similarity index 94% rename from libc/ubsan/ubsan.cpp rename to libc/ubsan/ubsan.c index 34e9d4f6..9b6154b7 100644 --- a/libc/ubsan/ubsan.cpp +++ b/libc/ubsan/ubsan.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 . - ubsan/ubsan.cpp + ubsan/ubsan.c Undefined behavior sanitizer runtime support. *******************************************************************************/ @@ -30,9 +30,8 @@ #include #include -#if defined(__is_sortix_kernel) -#include -#include +#ifdef __is_sortix_libk +#include #endif struct ubsan_source_location @@ -64,29 +63,21 @@ static void ubsan_abort(const struct ubsan_source_location* location, { if ( !location || !location->filename ) location = &unknown_location; -#if __STDC_HOSTED__ +#ifdef __is_sortix_libk + libk_ubsan_abort(violation, location->filename, location->line, + location->column); +#else struct scram_undefined_behavior info; info.filename = location->filename; info.line = location->line; info.column = location->column; info.violation = violation; scram(SCRAM_UNDEFINED_BEHAVIOR, &info); -#elif defined(__is_sortix_kernel) - Sortix::PanicF("Undefined behavior: %s at %s:%u:%u", - violation, - location->filename, - location->line, - location->column); -#else - #warning "You need to implement a undefined-behavior reporting mechanism" - (void) location; - (void) violation; - abort(); #endif } #define ABORT_VARIANT(name, params, call) \ -extern "C" __attribute__((noreturn)) \ +__attribute__((noreturn)) \ void __ubsan_handle_##name##_abort params \ { \ __ubsan_handle_##name call; \ @@ -110,7 +101,6 @@ struct ubsan_type_mismatch_data unsigned char type_check_kind; }; -extern "C" void __ubsan_handle_type_mismatch(void* data_raw, void* pointer_raw) { @@ -133,7 +123,6 @@ struct ubsan_overflow_data struct ubsan_type_descriptor* type; }; -extern "C" void __ubsan_handle_add_overflow(void* data_raw, void* lhs_raw, void* rhs_raw) @@ -148,7 +137,6 @@ void __ubsan_handle_add_overflow(void* data_raw, ABORT_VARIANT_VP_VP_VP(add_overflow); -extern "C" void __ubsan_handle_sub_overflow(void* data_raw, void* lhs_raw, void* rhs_raw) @@ -163,7 +151,6 @@ void __ubsan_handle_sub_overflow(void* data_raw, ABORT_VARIANT_VP_VP_VP(sub_overflow); -extern "C" void __ubsan_handle_mul_overflow(void* data_raw, void* lhs_raw, void* rhs_raw) @@ -178,7 +165,6 @@ void __ubsan_handle_mul_overflow(void* data_raw, ABORT_VARIANT_VP_VP_VP(mul_overflow); -extern "C" void __ubsan_handle_negate_overflow(void* data_raw, void* old_value_raw) { @@ -190,7 +176,6 @@ void __ubsan_handle_negate_overflow(void* data_raw, ABORT_VARIANT_VP_VP(negate_overflow); -extern "C" void __ubsan_handle_divrem_overflow(void* data_raw, void* lhs_raw, void* rhs_raw) @@ -212,7 +197,6 @@ struct ubsan_shift_out_of_bounds_data struct ubsan_type_descriptor* rhs_type; }; -extern "C" void __ubsan_handle_shift_out_of_bounds(void* data_raw, void* lhs_raw, void* rhs_raw) @@ -235,7 +219,6 @@ struct ubsan_out_of_bounds_data struct ubsan_type_descriptor* index_type; }; -extern "C" void __ubsan_handle_out_of_bounds(void* data_raw, void* index_raw) { @@ -253,7 +236,7 @@ struct ubsan_unreachable_data struct ubsan_source_location location; }; -extern "C" __attribute__((noreturn)) +__attribute__((noreturn)) void __ubsan_handle_builtin_unreachable(void* data_raw) { struct ubsan_unreachable_data* data = @@ -261,7 +244,7 @@ void __ubsan_handle_builtin_unreachable(void* data_raw) ubsan_abort(&data->location, "reached unreachable"); } -extern "C" __attribute__((noreturn)) +__attribute__((noreturn)) void __ubsan_handle_missing_return(void* data_raw) { struct ubsan_unreachable_data* data = @@ -275,7 +258,6 @@ struct ubsan_vla_bound_data struct ubsan_type_descriptor* type; }; -extern "C" void __ubsan_handle_vla_bound_not_positive(void* data_raw, void* bound_raw) { @@ -300,7 +282,6 @@ struct ubsan_float_cast_overflow_data struct ubsan_type_descriptor* to_type; }; -extern "C" void __ubsan_handle_float_cast_overflow(void* data_raw, void* from_raw) { @@ -323,7 +304,6 @@ struct ubsan_invalid_value_data struct ubsan_type_descriptor* type; }; -extern "C" void __ubsan_handle_load_invalid_value(void* data_raw, void* value_raw) { @@ -342,7 +322,6 @@ struct ubsan_function_type_mismatch_data struct ubsan_type_descriptor* type; }; -extern "C" void __ubsan_handle_function_type_mismatch(void* data_raw, void* value_raw) { @@ -361,7 +340,6 @@ struct ubsan_nonnull_return_data struct ubsan_source_location attr_location; }; -extern "C" void __ubsan_handle_nonnull_return(void* data_raw) { struct ubsan_nonnull_return_data* data = @@ -379,7 +357,6 @@ struct ubsan_nonnull_arg_data // TODO: GCC's libubsan does not have the second parameter, but its builtin // somehow has it and conflict if we don't match it. -extern "C" void __ubsan_handle_nonnull_arg(void* data_raw, intptr_t index_raw) { @@ -398,7 +375,6 @@ struct ubsan_cfi_bad_icall_data struct ubsan_type_descriptor* type; }; -extern "C" void __ubsan_handle_cfi_bad_icall(void* data_raw, void* value_raw) { diff --git a/libc/unistd/_exit.cpp b/libc/unistd/_exit.c similarity index 95% rename from libc/unistd/_exit.cpp rename to libc/unistd/_exit.c index 69414c3b..fc693a80 100644 --- a/libc/unistd/_exit.cpp +++ b/libc/unistd/_exit.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 . - unistd/_exit.cpp + unistd/_exit.c Terminates the current process. *******************************************************************************/ @@ -26,7 +26,7 @@ #include -extern "C" void _exit(int status) +void _exit(int status) { int exit_code = WCONSTRUCT(WNATURE_EXITED, status, 0); exit_thread(exit_code, EXIT_THREAD_PROCESS, NULL); diff --git a/libc/unistd/access.cpp b/libc/unistd/access.c similarity index 93% rename from libc/unistd/access.cpp rename to libc/unistd/access.c index 15a7b390..b0b649a3 100644 --- a/libc/unistd/access.cpp +++ b/libc/unistd/access.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 . - unistd/access.cpp + unistd/access.c Check real user's permissions for a file *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int access(const char* pathname, int mode) +int access(const char* pathname, int mode) { return faccessat(AT_FDCWD, pathname, mode, 0); } diff --git a/libc/unistd/alarm.cpp b/libc/unistd/alarm.c similarity index 94% rename from libc/unistd/alarm.cpp rename to libc/unistd/alarm.c index 9f428fe2..347ab0d4 100644 --- a/libc/unistd/alarm.cpp +++ b/libc/unistd/alarm.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 . - unistd/alarm.cpp + unistd/alarm.c Set an alarm clock for delivery of a signal. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" unsigned int alarm(unsigned int seconds) +unsigned int alarm(unsigned int seconds) { struct timespec delay = timespec_make(seconds, 0); struct timespec odelay; diff --git a/libc/unistd/alarmns.cpp b/libc/unistd/alarmns.c similarity index 92% rename from libc/unistd/alarmns.cpp rename to libc/unistd/alarmns.c index 9b967816..6229bd02 100644 --- a/libc/unistd/alarmns.cpp +++ b/libc/unistd/alarmns.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 . - unistd/alarmns.cpp + unistd/alarmns.c Set an alarm clock for delivery of a signal. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL2(int, sys_alarmns, SYSCALL_ALARMNS, const struct timespec*, struct timespec*) -extern "C" int alarmns(const struct timespec* delay, struct timespec* odelay) +int alarmns(const struct timespec* delay, struct timespec* odelay) { return sys_alarmns(delay, odelay); } diff --git a/libc/unistd/chdir.cpp b/libc/unistd/chdir.c similarity index 94% rename from libc/unistd/chdir.cpp rename to libc/unistd/chdir.c index 0306d096..fe0f3b9a 100644 --- a/libc/unistd/chdir.cpp +++ b/libc/unistd/chdir.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 . - unistd/chdir.cpp + unistd/chdir.c Changes the current working directory. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int chdir(const char* path) +int chdir(const char* path) { return fchdirat(AT_FDCWD, path); } diff --git a/libc/unistd/chown.cpp b/libc/unistd/chown.c similarity index 92% rename from libc/unistd/chown.cpp rename to libc/unistd/chown.c index c19a4692..813d6683 100644 --- a/libc/unistd/chown.cpp +++ b/libc/unistd/chown.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 . - unistd/chown.cpp + unistd/chown.c Changes the owner and group of a file. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int chown(const char* path, uid_t owner, gid_t group) +int chown(const char* path, uid_t owner, gid_t group) { return fchownat(AT_FDCWD, path, owner, group, 0); } diff --git a/libc/unistd/chroot.cpp b/libc/unistd/chroot.c similarity index 94% rename from libc/unistd/chroot.cpp rename to libc/unistd/chroot.c index 767104f8..438bc230 100644 --- a/libc/unistd/chroot.cpp +++ b/libc/unistd/chroot.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 . - unistd/chroot.cpp + unistd/chroot.c Changes the root directory. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int chroot(const char* path) +int chroot(const char* path) { return fchrootat(AT_FDCWD, path); } diff --git a/libc/unistd/close.cpp b/libc/unistd/close.c similarity index 95% rename from libc/unistd/close.cpp rename to libc/unistd/close.c index 3562c6aa..b2f65ce7 100644 --- a/libc/unistd/close.cpp +++ b/libc/unistd/close.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 . - unistd/close.cpp + unistd/close.c Closes a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_close, SYSCALL_CLOSE, int); -extern "C" int close(int fd) +int close(int fd) { return sys_close(fd); } diff --git a/libc/unistd/closefrom.cpp b/libc/unistd/closefrom.c similarity index 95% rename from libc/unistd/closefrom.cpp rename to libc/unistd/closefrom.c index 9c31716f..78dbde54 100644 --- a/libc/unistd/closefrom.cpp +++ b/libc/unistd/closefrom.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 . - unistd/closefrom.cpp + unistd/closefrom.c Closes all file descriptors from a value and upwards. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_closefrom, SYSCALL_CLOSEFROM, int); -extern "C" int closefrom(int fd) +int closefrom(int fd) { return sys_closefrom(fd); } diff --git a/libc/unistd/confstr.cpp b/libc/unistd/confstr.c similarity index 93% rename from libc/unistd/confstr.cpp rename to libc/unistd/confstr.c index 3c465383..3ef75444 100644 --- a/libc/unistd/confstr.cpp +++ b/libc/unistd/confstr.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 . - unistd/confstr.cpp + unistd/confstr.c Get configurable string variables. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" size_t confstr(int name, char* buf, size_t len) +size_t confstr(int name, char* buf, size_t len) { switch ( name ) { diff --git a/libc/unistd/crypt_newhash.cpp b/libc/unistd/crypt_newhash.c similarity index 99% rename from libc/unistd/crypt_newhash.cpp rename to libc/unistd/crypt_newhash.c index 6dfda8a0..0c33f449 100644 --- a/libc/unistd/crypt_newhash.cpp +++ b/libc/unistd/crypt_newhash.c @@ -20,7 +20,6 @@ #include #include -extern "C" int crypt_checkpass(const char *pass, const char *goodhash) { @@ -49,7 +48,6 @@ fail: return -1; } -extern "C" int crypt_newhash(const char *pass, const char *pref, char *hash, size_t hashlen) { diff --git a/libc/unistd/dup.cpp b/libc/unistd/dup.c similarity index 96% rename from libc/unistd/dup.cpp rename to libc/unistd/dup.c index 3040a84f..86142a0e 100644 --- a/libc/unistd/dup.cpp +++ b/libc/unistd/dup.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 . - unistd/dup.cpp + unistd/dup.c Duplicates a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_dup, SYSCALL_DUP, int); -extern "C" int dup(int fd) +int dup(int fd) { return sys_dup(fd); } diff --git a/libc/unistd/dup2.cpp b/libc/unistd/dup2.c similarity index 94% rename from libc/unistd/dup2.cpp rename to libc/unistd/dup2.c index bad755dd..2818c5e9 100644 --- a/libc/unistd/dup2.cpp +++ b/libc/unistd/dup2.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 . - unistd/dup2.cpp + unistd/dup2.c Duplicates a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_dup2, SYSCALL_DUP2, int, int); -extern "C" int dup2(int oldfd, int newfd) +int dup2(int oldfd, int newfd) { return sys_dup2(oldfd, newfd); } diff --git a/libc/unistd/dup3.cpp b/libc/unistd/dup3.c similarity index 93% rename from libc/unistd/dup3.cpp rename to libc/unistd/dup3.c index a8aae77b..735eabe9 100644 --- a/libc/unistd/dup3.cpp +++ b/libc/unistd/dup3.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 . - unistd/dup3.cpp + unistd/dup3.c Duplicates a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(int, sys_dup3, SYSCALL_DUP3, int, int, int); -extern "C" int dup3(int oldfd, int newfd, int flags) +int dup3(int oldfd, int newfd, int flags) { return sys_dup3(oldfd, newfd, flags); } diff --git a/libc/unistd/environ.cpp b/libc/unistd/environ.c similarity index 83% rename from libc/unistd/environ.cpp rename to libc/unistd/environ.c index 022ecd42..c9f24833 100644 --- a/libc/unistd/environ.cpp +++ b/libc/unistd/environ.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 . - unistd/environ.cpp + unistd/environ.c Environment variables. *******************************************************************************/ #include -extern "C" { char** environ = NULL; } -extern "C" { char** __environ_malloced = NULL; } -extern "C" { size_t __environ_used = 0; } -extern "C" { size_t __environ_length = 0; } +char** environ = NULL; +char** __environ_malloced = NULL; +size_t __environ_used = 0; +size_t __environ_length = 0; diff --git a/libc/unistd/execl.cpp b/libc/unistd/execl.c similarity index 94% rename from libc/unistd/execl.cpp rename to libc/unistd/execl.c index c486fa70..0500c780 100644 --- a/libc/unistd/execl.cpp +++ b/libc/unistd/execl.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 . - unistd/execl.cpp + unistd/execl.c Loads a program image. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int execl(const char* pathname, const char* argv0, ...) +int execl(const char* pathname, const char* argv0, ...) { if ( !argv0 ) return execv(pathname, (char* const*) &argv0); diff --git a/libc/unistd/execle.cpp b/libc/unistd/execle.c similarity index 95% rename from libc/unistd/execle.cpp rename to libc/unistd/execle.c index e7160811..b0af7420 100644 --- a/libc/unistd/execle.cpp +++ b/libc/unistd/execle.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 . - unistd/execle.cpp + unistd/execle.c Loads a program image. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int execle(const char* pathname, const char* argv0, ...) +int execle(const char* pathname, const char* argv0, ...) { if ( !argv0 ) { diff --git a/libc/unistd/execlp.cpp b/libc/unistd/execlp.c similarity index 94% rename from libc/unistd/execlp.cpp rename to libc/unistd/execlp.c index 9985d011..cc3f7297 100644 --- a/libc/unistd/execlp.cpp +++ b/libc/unistd/execlp.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 . - unistd/execlp.cpp + unistd/execlp.c Loads a program image. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int execlp(const char* filename, const char* argv0, ...) +int execlp(const char* filename, const char* argv0, ...) { if ( !argv0 ) return execvp(filename, (char* const*) &argv0); diff --git a/libc/unistd/execlpe.cpp b/libc/unistd/execlpe.c similarity index 94% rename from libc/unistd/execlpe.cpp rename to libc/unistd/execlpe.c index f9f118d8..255d47db 100644 --- a/libc/unistd/execlpe.cpp +++ b/libc/unistd/execlpe.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 . - unistd/execlpe.cpp + unistd/execlpe.c Loads a program image. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int execlpe(const char* filename, const char* argv0, ...) +int execlpe(const char* filename, const char* argv0, ...) { va_list args; va_start(args, argv0); diff --git a/libc/unistd/execv.cpp b/libc/unistd/execv.c similarity index 92% rename from libc/unistd/execv.cpp rename to libc/unistd/execv.c index a9eec88d..ccb05325 100644 --- a/libc/unistd/execv.cpp +++ b/libc/unistd/execv.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 . - unistd/execv.cpp + unistd/execv.c Loads a program image. *******************************************************************************/ #include -extern "C" int execv(const char* pathname, char* const* argv) +int execv(const char* pathname, char* const* argv) { return execve(pathname, argv, environ); } diff --git a/libc/unistd/execve.cpp b/libc/unistd/execve.c similarity index 90% rename from libc/unistd/execve.cpp rename to libc/unistd/execve.c index 7d1e6105..8b1cac75 100644 --- a/libc/unistd/execve.cpp +++ b/libc/unistd/execve.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 . - unistd/execve.cpp + unistd/execve.c Loads a program image. *******************************************************************************/ @@ -28,8 +28,7 @@ DEFN_SYSCALL3(int, sys_execve, SYSCALL_EXECVE, const char*, char* const*, char* const*); -extern "C" int execve(const char* pathname, char* const* argv, - char* const* envp) +int execve(const char* pathname, char* const* argv, char* const* envp) { return sys_execve(pathname, argv, envp); } diff --git a/libc/unistd/execvp.cpp b/libc/unistd/execvp.c similarity index 92% rename from libc/unistd/execvp.cpp rename to libc/unistd/execvp.c index 583ceaae..b8d41b90 100644 --- a/libc/unistd/execvp.cpp +++ b/libc/unistd/execvp.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 . - unistd/execvp.cpp + unistd/execvp.c Loads a program image. *******************************************************************************/ #include -extern "C" int execvp(const char* filename, char* const* argv) +int execvp(const char* filename, char* const* argv) { return execvpe(filename, argv, environ); } diff --git a/libc/unistd/execvpe.cpp b/libc/unistd/execvpe.c similarity index 98% rename from libc/unistd/execvpe.cpp rename to libc/unistd/execvpe.c index 1a97c3d4..1fdfec6b 100644 --- a/libc/unistd/execvpe.cpp +++ b/libc/unistd/execvpe.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 . - unistd/execvpe.cpp + unistd/execvpe.c Loads a program image. *******************************************************************************/ #include #include +#include #include #include #include @@ -92,10 +93,9 @@ int execvpe_attempt(const char* filename, // 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 -extern "C" int execvpe(const char* filename, char* const* argv, char* const* envp) { if ( !filename || !filename[0] ) diff --git a/libc/unistd/exit_thread.cpp b/libc/unistd/exit_thread.c similarity index 96% rename from libc/unistd/exit_thread.cpp rename to libc/unistd/exit_thread.c index ea73936a..07e2384d 100644 --- a/libc/unistd/exit_thread.cpp +++ b/libc/unistd/exit_thread.c @@ -17,7 +17,7 @@ You should have received a copy of the GNU General Public License along with Sortix. If not, see . - unistd/exit_thread.cpp + unistd/exit_thread.c Destroys the current thread immediately with no clean up. *******************************************************************************/ @@ -28,7 +28,6 @@ DEFN_SYSCALL3(int, sys_exit_thread, SYSCALL_EXIT_THREAD, int, int, const struct exit_thread*); -extern "C" int exit_thread(int status, int flags, const struct exit_thread* extended) { return sys_exit_thread(status, flags, extended); diff --git a/libc/unistd/faccessat.cpp b/libc/unistd/faccessat.c similarity index 92% rename from libc/unistd/faccessat.cpp rename to libc/unistd/faccessat.c index 46f48859..4163b1ed 100644 --- a/libc/unistd/faccessat.cpp +++ b/libc/unistd/faccessat.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 . - unistd/faccessat.cpp + unistd/faccessat.c Check real user's permissions for a file *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL4(int, sys_faccessat, SYSCALL_FACCESSAT, int, const char*, int, int); -extern "C" int faccessat(int dirfd, const char* path, int mode, int flags) +int faccessat(int dirfd, const char* path, int mode, int flags) { return sys_faccessat(dirfd, path, mode, flags); } diff --git a/libc/unistd/fchdir.cpp b/libc/unistd/fchdir.c similarity index 95% rename from libc/unistd/fchdir.cpp rename to libc/unistd/fchdir.c index 7eb87a18..caea0e58 100644 --- a/libc/unistd/fchdir.cpp +++ b/libc/unistd/fchdir.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 . - unistd/fchdir.cpp + unistd/fchdir.c Changes the current working directory. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_fchdir, SYSCALL_FCHDIR, int); -extern "C" int fchdir(int fd) +int fchdir(int fd) { return sys_fchdir(fd); } diff --git a/libc/unistd/fchdirat.cpp b/libc/unistd/fchdirat.c similarity index 93% rename from libc/unistd/fchdirat.cpp rename to libc/unistd/fchdirat.c index 2c35fd17..e6a1c5e6 100644 --- a/libc/unistd/fchdirat.cpp +++ b/libc/unistd/fchdirat.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 . - unistd/fchdirat.cpp + unistd/fchdirat.c Changes the current working directory. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_fchdirat, SYSCALL_FCHDIRAT, int, const char*); -extern "C" int fchdirat(int dirfd, const char* path) +int fchdirat(int dirfd, const char* path) { return sys_fchdirat(dirfd, path); } diff --git a/libc/unistd/fchown.cpp b/libc/unistd/fchown.c similarity index 93% rename from libc/unistd/fchown.cpp rename to libc/unistd/fchown.c index d8af8365..f5c77d58 100644 --- a/libc/unistd/fchown.cpp +++ b/libc/unistd/fchown.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 . - unistd/fchown.cpp + unistd/fchown.c Changes the owner and group of a file. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL3(int, sys_fchown, SYSCALL_FCHOWN, int, uid_t, gid_t); -extern "C" int fchown(int fd, uid_t owner, gid_t group) +int fchown(int fd, uid_t owner, gid_t group) { return sys_fchown(fd, owner, group); } diff --git a/libc/unistd/fchownat.cpp b/libc/unistd/fchownat.c similarity index 91% rename from libc/unistd/fchownat.cpp rename to libc/unistd/fchownat.c index ad34cb5f..04a76b6d 100644 --- a/libc/unistd/fchownat.cpp +++ b/libc/unistd/fchownat.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 . - unistd/fchownat.cpp + unistd/fchownat.c Changes the owner and group of a file. *******************************************************************************/ @@ -30,7 +30,7 @@ DEFN_SYSCALL5(int, sys_fchownat, SYSCALL_FCHOWNAT, int, const char*, uid_t, gid_t, int); -extern "C" int fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags) +int fchownat(int dirfd, const char* path, uid_t owner, gid_t group, int flags) { return sys_fchownat(dirfd, path, owner, group, flags); } diff --git a/libc/unistd/fchroot.cpp b/libc/unistd/fchroot.c similarity index 95% rename from libc/unistd/fchroot.cpp rename to libc/unistd/fchroot.c index 7ab00297..510eb87f 100644 --- a/libc/unistd/fchroot.cpp +++ b/libc/unistd/fchroot.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 . - unistd/fchroot.cpp + unistd/fchroot.c Changes the root directory. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_fchroot, SYSCALL_FCHROOT, int); -extern "C" int fchroot(int fd) +int fchroot(int fd) { return sys_fchroot(fd); } diff --git a/libc/unistd/fchrootat.cpp b/libc/unistd/fchrootat.c similarity index 93% rename from libc/unistd/fchrootat.cpp rename to libc/unistd/fchrootat.c index 461e4a90..2191348c 100644 --- a/libc/unistd/fchrootat.cpp +++ b/libc/unistd/fchrootat.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 . - unistd/fchrootat.cpp + unistd/fchrootat.c Changes the root directory. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_fchrootat, SYSCALL_FCHROOTAT, int, const char*); -extern "C" int fchrootat(int dirfd, const char* path) +int fchrootat(int dirfd, const char* path) { return sys_fchrootat(dirfd, path); } diff --git a/libc/unistd/fork.cpp b/libc/unistd/fork.c similarity index 96% rename from libc/unistd/fork.cpp rename to libc/unistd/fork.c index 4d44f073..52a80866 100644 --- a/libc/unistd/fork.cpp +++ b/libc/unistd/fork.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 . - unistd/fork.cpp + unistd/fork.c Create a new task inheriting some properties from the current task. *******************************************************************************/ #include -extern "C" pid_t fork() +pid_t fork(void) { return sfork(SFFORK); } diff --git a/libc/unistd/fpathconf.cpp b/libc/unistd/fpathconf.c similarity index 94% rename from libc/unistd/fpathconf.cpp rename to libc/unistd/fpathconf.c index e5490f49..fe8d6d7c 100644 --- a/libc/unistd/fpathconf.cpp +++ b/libc/unistd/fpathconf.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 . - unistd/fpathconf.cpp + unistd/fpathconf.c Get configurable pathname variables. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" long fpathconf(int fd, int name) +long fpathconf(int fd, int name) { switch ( name ) { diff --git a/libc/unistd/fsync.cpp b/libc/unistd/fsync.c similarity index 95% rename from libc/unistd/fsync.cpp rename to libc/unistd/fsync.c index 455e5e23..d8845e2d 100644 --- a/libc/unistd/fsync.cpp +++ b/libc/unistd/fsync.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 . - unistd/fsync.cpp + unistd/fsync.c Flushes a file to its backing storage. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_fsync, SYSCALL_FSYNC, int); -extern "C" int fsync(int fd) +int fsync(int fd) { return sys_fsync(fd); } diff --git a/libc/unistd/ftruncate.cpp b/libc/unistd/ftruncate.c similarity index 94% rename from libc/unistd/ftruncate.cpp rename to libc/unistd/ftruncate.c index 28b096d1..2ff78010 100644 --- a/libc/unistd/ftruncate.cpp +++ b/libc/unistd/ftruncate.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 . - unistd/ftruncate.cpp + unistd/ftruncate.c Truncates an open file to a specific size. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_ftruncate, SYSCALL_FTRUNCATE, int, off_t); -extern "C" int ftruncate(int fd, off_t length) +int ftruncate(int fd, off_t length) { return sys_ftruncate(fd, length); } diff --git a/libc/unistd/get_current_dir_name.cpp b/libc/unistd/get_current_dir_name.c similarity index 95% rename from libc/unistd/get_current_dir_name.cpp rename to libc/unistd/get_current_dir_name.c index 46f4c0fe..1353ddab 100644 --- a/libc/unistd/get_current_dir_name.cpp +++ b/libc/unistd/get_current_dir_name.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 . - unistd/get_current_dir_name.cpp + unistd/get_current_dir_name.c Returns the current working directory. *******************************************************************************/ @@ -30,7 +30,7 @@ #include // TODO: This interface should removed as its $PWD use is not thread safe. -extern "C" char* get_current_dir_name(void) +char* get_current_dir_name(void) { const char* pwd = getenv("PWD"); int saved_errno = errno; diff --git a/libc/unistd/getcwd.cpp b/libc/unistd/getcwd.c similarity index 94% rename from libc/unistd/getcwd.cpp rename to libc/unistd/getcwd.c index 9a06f591..770d8b9e 100644 --- a/libc/unistd/getcwd.cpp +++ b/libc/unistd/getcwd.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 . - unistd/getcwd.cpp + unistd/getcwd.c Returns the current working directory. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" char* getcwd(char* buf, size_t size) +char* getcwd(char* buf, size_t size) { char* cwd = canonicalize_file_name("."); if ( !cwd ) diff --git a/libc/unistd/getdomainname.cpp b/libc/unistd/getdomainname.c similarity index 94% rename from libc/unistd/getdomainname.cpp rename to libc/unistd/getdomainname.c index 9d4effeb..53fad418 100644 --- a/libc/unistd/getdomainname.cpp +++ b/libc/unistd/getdomainname.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 . - unistd/getdomainname.cpp + unistd/getdomainname.c Get the domainname. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int getdomainname(char* name, size_t len) +int getdomainname(char* name, size_t len) { const char* domainname = getenv("DOMAINNAME"); if ( !domainname ) diff --git a/libc/unistd/getegid.cpp b/libc/unistd/getegid.c similarity index 95% rename from libc/unistd/getegid.cpp rename to libc/unistd/getegid.c index 0065a95a..ed7e9f8f 100644 --- a/libc/unistd/getegid.cpp +++ b/libc/unistd/getegid.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 . - unistd/getegid.cpp + unistd/getegid.c Get effective group id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL0(gid_t, sys_getegid, SYSCALL_GETEGID); -extern "C" gid_t getegid() +gid_t getegid(void) { return sys_getegid(); } diff --git a/libc/unistd/getentropy.cpp b/libc/unistd/getentropy.c similarity index 93% rename from libc/unistd/getentropy.cpp rename to libc/unistd/getentropy.c index e8c02352..285f99d6 100644 --- a/libc/unistd/getentropy.cpp +++ b/libc/unistd/getentropy.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 . - unistd/getentropy.cpp + unistd/getentropy.c Read entropy into an user buffer. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_getentropy, SYSCALL_GETENTROPY, void*, size_t); -extern "C" int getentropy(void* buffer, size_t size) +int getentropy(void* buffer, size_t size) { return sys_getentropy(buffer, size); } diff --git a/libc/unistd/geteuid.cpp b/libc/unistd/geteuid.c similarity index 95% rename from libc/unistd/geteuid.cpp rename to libc/unistd/geteuid.c index f59b5b76..ef213945 100644 --- a/libc/unistd/geteuid.cpp +++ b/libc/unistd/geteuid.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 . - unistd/geteuid.cpp + unistd/geteuid.c Get effective user id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL0(uid_t, sys_geteuid, SYSCALL_GETEUID); -extern "C" uid_t geteuid() +uid_t geteuid(void) { return sys_geteuid(); } diff --git a/libc/unistd/getgid.cpp b/libc/unistd/getgid.c similarity index 95% rename from libc/unistd/getgid.cpp rename to libc/unistd/getgid.c index a964bf58..a4e9abd9 100644 --- a/libc/unistd/getgid.cpp +++ b/libc/unistd/getgid.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 . - unistd/getgid.cpp + unistd/getgid.c Get current group id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL0(gid_t, sys_getgid, SYSCALL_GETGID); -extern "C" gid_t getgid() +gid_t getgid(void) { return sys_getgid(); } diff --git a/libc/unistd/gethostname.cpp b/libc/unistd/gethostname.c similarity index 93% rename from libc/unistd/gethostname.cpp rename to libc/unistd/gethostname.c index 3ac3c167..23e292f1 100644 --- a/libc/unistd/gethostname.cpp +++ b/libc/unistd/gethostname.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 . - unistd/gethostname.cpp + unistd/gethostname.c Get the hostname. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_gethostname, SYSCALL_GETHOSTNAME, char*, size_t); -extern "C" int gethostname(char* name, size_t name_size) +int gethostname(char* name, size_t name_size) { return sys_gethostname(name, name_size); } diff --git a/libc/unistd/getlogin.cpp b/libc/unistd/getlogin.c similarity index 96% rename from libc/unistd/getlogin.cpp rename to libc/unistd/getlogin.c index 73f4298f..7232a272 100644 --- a/libc/unistd/getlogin.cpp +++ b/libc/unistd/getlogin.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 . - unistd/getlogin.cpp + unistd/getlogin.c Get name of user logged in at the controlling terminal. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" char* getlogin() +char* getlogin(void) { static char* buffer = NULL; static size_t buffer_size = 0; diff --git a/libc/unistd/getlogin_r.cpp b/libc/unistd/getlogin_r.c similarity index 96% rename from libc/unistd/getlogin_r.cpp rename to libc/unistd/getlogin_r.c index 4140e80d..f91e87a2 100644 --- a/libc/unistd/getlogin_r.cpp +++ b/libc/unistd/getlogin_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 . - unistd/getlogin_r.cpp + unistd/getlogin_r.c Get name of user logged in at the controlling terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ #include #include -extern "C" int getlogin_r(char* buf, size_t size) +int getlogin_r(char* buf, size_t size) { struct passwd passwd_object; struct passwd* passwd; diff --git a/libc/unistd/getpagesize.cpp b/libc/unistd/getpagesize.c similarity index 94% rename from libc/unistd/getpagesize.cpp rename to libc/unistd/getpagesize.c index b0f4648c..438b5c51 100644 --- a/libc/unistd/getpagesize.cpp +++ b/libc/unistd/getpagesize.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 . - unistd/getpagesize.cpp + unistd/getpagesize.c Returns the size of virtual memory pages. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL0(size_t, sys_getpagesize, SYSCALL_GETPAGESIZE); -extern "C" size_t getpagesize(void) +size_t getpagesize(void) { return sys_getpagesize(); } diff --git a/libc/unistd/getpgid.cpp b/libc/unistd/getpgid.c similarity index 95% rename from libc/unistd/getpgid.cpp rename to libc/unistd/getpgid.c index 236833b5..5a39c69c 100644 --- a/libc/unistd/getpgid.cpp +++ b/libc/unistd/getpgid.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 . - unistd/getpgid.cpp + unistd/getpgid.c Get the process group of a process. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(pid_t, sys_getpgid, SYSCALL_GETPGID, pid_t); -extern "C" pid_t getpgid(pid_t pid) +pid_t getpgid(pid_t pid) { return sys_getpgid(pid); } diff --git a/libc/unistd/getpid.cpp b/libc/unistd/getpid.c similarity index 95% rename from libc/unistd/getpid.cpp rename to libc/unistd/getpid.c index 28f5124c..86338b49 100644 --- a/libc/unistd/getpid.cpp +++ b/libc/unistd/getpid.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 . - unistd/getpid.cpp + unistd/getpid.c Get current process id. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL0(pid_t, sys_getpid, SYSCALL_GETPID); -extern "C" pid_t getpid() +pid_t getpid(void) { return sys_getpid(); } diff --git a/libc/unistd/getppid.cpp b/libc/unistd/getppid.c similarity index 95% rename from libc/unistd/getppid.cpp rename to libc/unistd/getppid.c index a44bee8e..5757a25e 100644 --- a/libc/unistd/getppid.cpp +++ b/libc/unistd/getppid.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 . - unistd/getppid.cpp + unistd/getppid.c Get parent process id. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL0(pid_t, sys_getppid, SYSCALL_GETPPID); -extern "C" pid_t getppid() +pid_t getppid(void) { return sys_getppid(); } diff --git a/libc/unistd/getuid.cpp b/libc/unistd/getuid.c similarity index 95% rename from libc/unistd/getuid.cpp rename to libc/unistd/getuid.c index f85f520b..dc346349 100644 --- a/libc/unistd/getuid.cpp +++ b/libc/unistd/getuid.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 . - unistd/getuid.cpp + unistd/getuid.c Get current user id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL0(uid_t, sys_getuid, SYSCALL_GETUID); -extern "C" uid_t getuid() +uid_t getuid(void) { return sys_getuid(); } diff --git a/libc/unistd/isatty.cpp b/libc/unistd/isatty.c similarity index 95% rename from libc/unistd/isatty.cpp rename to libc/unistd/isatty.c index ffed6cc8..b7a66f7d 100644 --- a/libc/unistd/isatty.cpp +++ b/libc/unistd/isatty.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 . - unistd/isatty.cpp + unistd/isatty.c Queries whether a file descriptor is associated with a terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(int, sys_isatty, SYSCALL_ISATTY, int); -extern "C" int isatty(int fd) +int isatty(int fd) { return sys_isatty(fd); } diff --git a/libc/unistd/lchown.cpp b/libc/unistd/lchown.c similarity index 92% rename from libc/unistd/lchown.cpp rename to libc/unistd/lchown.c index 13dfa0be..1fd3b515 100644 --- a/libc/unistd/lchown.cpp +++ b/libc/unistd/lchown.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 . - unistd/lchown.cpp + unistd/lchown.c Changes the owner and group of a file. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int lchown(const char* path, uid_t owner, gid_t group) +int lchown(const char* path, uid_t owner, gid_t group) { return fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW); } diff --git a/libc/unistd/link.cpp b/libc/unistd/link.c similarity index 93% rename from libc/unistd/link.cpp rename to libc/unistd/link.c index d9930c18..8848be11 100644 --- a/libc/unistd/link.cpp +++ b/libc/unistd/link.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 . - unistd/link.cpp + unistd/link.c Give a new name to a file. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int link(const char* oldpath, const char* newpath) +int link(const char* oldpath, const char* newpath) { return linkat(AT_FDCWD, oldpath, AT_FDCWD, newpath, 0); } diff --git a/libc/unistd/linkat.cpp b/libc/unistd/linkat.c similarity index 87% rename from libc/unistd/linkat.cpp rename to libc/unistd/linkat.c index d232ae92..ed5a44d8 100644 --- a/libc/unistd/linkat.cpp +++ b/libc/unistd/linkat.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 . - unistd/linkat.cpp + unistd/linkat.c Give a new name to a file. *******************************************************************************/ @@ -29,9 +29,8 @@ DEFN_SYSCALL5(int, sys_linkat, SYSCALL_LINKAT, int, const char*, int, const char*, int); -extern "C" int linkat(int olddirfd, const char* oldpath, - int newdirfd, const char* newpath, - int flags) +int linkat(int olddirfd, const char* oldpath, int newdirfd, const char* newpath, + int flags) { return sys_linkat(olddirfd, oldpath, newdirfd, newpath, flags); } diff --git a/libc/unistd/lseek.cpp b/libc/unistd/lseek.c similarity index 93% rename from libc/unistd/lseek.cpp rename to libc/unistd/lseek.c index fa188bb3..9744f6c5 100644 --- a/libc/unistd/lseek.cpp +++ b/libc/unistd/lseek.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 . - unistd/lseek.cpp + unistd/lseek.c Sets the offset on a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(off_t, sys_seek, SYSCALL_LSEEK, int, off_t, int); -extern "C" off_t lseek(int fd, off_t offset, int whence) +off_t lseek(int fd, off_t offset, int whence) { return sys_seek(fd, offset, whence); } diff --git a/libc/unistd/memstat.cpp b/libc/unistd/memstat.c similarity index 93% rename from libc/unistd/memstat.cpp rename to libc/unistd/memstat.c index f918b369..d79f6b6c 100644 --- a/libc/unistd/memstat.cpp +++ b/libc/unistd/memstat.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 . - unistd/memstat.cpp + unistd/memstat.c Retrieves memory statistics. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_memstat, SYSCALL_MEMSTAT, size_t*, size_t*); -extern "C" int memstat(size_t* memused, size_t* memtotal) +int memstat(size_t* memused, size_t* memtotal) { return sys_memstat(memused, memtotal); } diff --git a/libc/unistd/mkpartition.cpp b/libc/unistd/mkpartition.c similarity index 93% rename from libc/unistd/mkpartition.cpp rename to libc/unistd/mkpartition.c index fb2fdc31..62b8e0fd 100644 --- a/libc/unistd/mkpartition.cpp +++ b/libc/unistd/mkpartition.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 . - unistd/mkpartition.cpp + unistd/mkpartition.c Creates a block device representating a partition of another block device. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(int, sys_mkpartition, SYSCALL_MKPARTITION, int, off_t, off_t); -extern "C" int mkpartition(int fd, off_t start, off_t length) +int mkpartition(int fd, off_t start, off_t length) { return sys_mkpartition(fd, start, length); } diff --git a/libc/unistd/pathconf.cpp b/libc/unistd/pathconf.c similarity index 94% rename from libc/unistd/pathconf.cpp rename to libc/unistd/pathconf.c index d60983ef..4c97538b 100644 --- a/libc/unistd/pathconf.cpp +++ b/libc/unistd/pathconf.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 . - unistd/pathconf.cpp + unistd/pathconf.c Get configurable pathname variables. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" long pathconf(const char* path, int name) +long pathconf(const char* path, int name) { switch ( name ) { diff --git a/libc/unistd/pipe.cpp b/libc/unistd/pipe.c similarity index 95% rename from libc/unistd/pipe.cpp rename to libc/unistd/pipe.c index d30bdcfb..ba6f0980 100644 --- a/libc/unistd/pipe.cpp +++ b/libc/unistd/pipe.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 . - unistd/pipe.cpp + unistd/pipe.c Creates a pair of file descriptors with a reading and writing end. *******************************************************************************/ #include -extern "C" int pipe(int pipefd[2]) +int pipe(int pipefd[2]) { return pipe2(pipefd, 0); } diff --git a/libc/unistd/pipe2.cpp b/libc/unistd/pipe2.c similarity index 94% rename from libc/unistd/pipe2.cpp rename to libc/unistd/pipe2.c index a428458d..e9ad8253 100644 --- a/libc/unistd/pipe2.cpp +++ b/libc/unistd/pipe2.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 . - unistd/pipe2.cpp + unistd/pipe2.c Creates a pair of file descriptors with a reading and writing end. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_pipe2, SYSCALL_PIPE2, int*, int); -extern "C" int pipe2(int pipefd[2], int flags) +int pipe2(int pipefd[2], int flags) { return sys_pipe2(pipefd, flags); } diff --git a/libc/unistd/pread.cpp b/libc/unistd/pread.c similarity index 92% rename from libc/unistd/pread.cpp rename to libc/unistd/pread.c index 3276349a..73c770f4 100644 --- a/libc/unistd/pread.cpp +++ b/libc/unistd/pread.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 . - unistd/pread.cpp + unistd/pread.c Reads from a file descriptor at the given offset. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL4(ssize_t, sys_pread, SYSCALL_PREAD, int, void*, size_t, off_t); -extern "C" ssize_t pread(int fd, void* buf, size_t count, off_t offset) +ssize_t pread(int fd, void* buf, size_t count, off_t offset) { return sys_pread(fd, buf, count, offset); } diff --git a/libc/unistd/pwrite.cpp b/libc/unistd/pwrite.c similarity index 92% rename from libc/unistd/pwrite.cpp rename to libc/unistd/pwrite.c index 07abf56b..aa2971da 100644 --- a/libc/unistd/pwrite.cpp +++ b/libc/unistd/pwrite.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 . - unistd/pwrite.cpp + unistd/pwrite.c Writes to a file descriptor at the given offset. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL4(ssize_t, sys_pwrite, SYSCALL_PWRITE, int, const void*, size_t, off_t); -extern "C" ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) +ssize_t pwrite(int fd, const void* buf, size_t count, off_t offset) { return sys_pwrite(fd, buf, count, offset); } diff --git a/libc/unistd/read.cpp b/libc/unistd/read.c similarity index 93% rename from libc/unistd/read.cpp rename to libc/unistd/read.c index 4352eef7..67b034ef 100644 --- a/libc/unistd/read.cpp +++ b/libc/unistd/read.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 . - unistd/read.cpp + unistd/read.c Reads from a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(ssize_t, sys_read, SYSCALL_READ, int, void*, size_t); -extern "C" ssize_t read(int fd, void* buf, size_t count) +ssize_t read(int fd, void* buf, size_t count) { return sys_read(fd, buf, count); } diff --git a/libc/unistd/readlink.cpp b/libc/unistd/readlink.c similarity index 88% rename from libc/unistd/readlink.cpp rename to libc/unistd/readlink.c index 1ad64487..c21fd354 100644 --- a/libc/unistd/readlink.cpp +++ b/libc/unistd/readlink.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 . - unistd/readlink.cpp + unistd/readlink.c Read contents of symbolic link. *******************************************************************************/ @@ -25,8 +25,7 @@ #include #include -extern "C" ssize_t readlink(const char* restrict path, char* restrict buf, - size_t size) +ssize_t readlink(const char* restrict path, char* restrict buf, size_t size) { return readlinkat(AT_FDCWD, path, buf, size); } diff --git a/libc/unistd/readlinkat.cpp b/libc/unistd/readlinkat.c similarity index 88% rename from libc/unistd/readlinkat.cpp rename to libc/unistd/readlinkat.c index 939d1391..b974b19a 100644 --- a/libc/unistd/readlinkat.cpp +++ b/libc/unistd/readlinkat.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 . - unistd/readlinkat.cpp + unistd/readlinkat.c Read contents of symbolic link. *******************************************************************************/ @@ -30,8 +30,8 @@ DEFN_SYSCALL4(ssize_t, sys_readlinkat, SYSCALL_READLINKAT, int, const char* restrict, char* restrict, size_t); -extern "C" ssize_t readlinkat(int dirfd, const char* restrict path, - char* restrict buf, size_t size) +ssize_t readlinkat(int dirfd, const char* restrict path, char* restrict buf, + size_t size) { return sys_readlinkat(dirfd, path, buf, size); } diff --git a/libc/unistd/rmdir.cpp b/libc/unistd/rmdir.c similarity index 94% rename from libc/unistd/rmdir.cpp rename to libc/unistd/rmdir.c index 076880b0..ea7c5323 100644 --- a/libc/unistd/rmdir.cpp +++ b/libc/unistd/rmdir.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 . - unistd/rmdir.cpp + unistd/rmdir.c Removes an empty directory. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int rmdir(const char* pathname) +int rmdir(const char* pathname) { return unlinkat(AT_FDCWD, pathname, AT_REMOVEDIR); } diff --git a/libc/unistd/setegid.cpp b/libc/unistd/setegid.c similarity index 95% rename from libc/unistd/setegid.cpp rename to libc/unistd/setegid.c index 03520b83..2fd9c187 100644 --- a/libc/unistd/setegid.cpp +++ b/libc/unistd/setegid.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 . - unistd/setegid.cpp + unistd/setegid.c Set effective group id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL1(gid_t, sys_setegid, SYSCALL_SETEGID, gid_t); -extern "C" int setegid(gid_t egid) +int setegid(gid_t egid) { return sys_setegid(egid); } diff --git a/libc/unistd/seteuid.cpp b/libc/unistd/seteuid.c similarity index 95% rename from libc/unistd/seteuid.cpp rename to libc/unistd/seteuid.c index f3ee736e..ea5e4ace 100644 --- a/libc/unistd/seteuid.cpp +++ b/libc/unistd/seteuid.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 . - unistd/seteuid.cpp + unistd/seteuid.c Set effective user id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL1(uid_t, sys_seteuid, SYSCALL_SETEUID, uid_t); -extern "C" int seteuid(uid_t euid) +int seteuid(uid_t euid) { return sys_seteuid(euid); } diff --git a/libc/unistd/setgid.cpp b/libc/unistd/setgid.c similarity index 95% rename from libc/unistd/setgid.cpp rename to libc/unistd/setgid.c index dc7ac7e8..84ebf664 100644 --- a/libc/unistd/setgid.cpp +++ b/libc/unistd/setgid.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 . - unistd/setgid.cpp + unistd/setgid.c Set current group id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL1(gid_t, sys_setgid, SYSCALL_SETGID, gid_t); -extern "C" int setgid(gid_t gid) +int setgid(gid_t gid) { return sys_setgid(gid); } diff --git a/libc/unistd/sethostname.cpp b/libc/unistd/sethostname.c similarity index 92% rename from libc/unistd/sethostname.cpp rename to libc/unistd/sethostname.c index 1482c67c..819157fc 100644 --- a/libc/unistd/sethostname.cpp +++ b/libc/unistd/sethostname.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 . - unistd/sethostname.cpp + unistd/sethostname.c Set the hostname. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_sethostname, SYSCALL_SETHOSTNAME, const char*, size_t); -extern "C" int sethostname(const char* name, size_t name_size) +int sethostname(const char* name, size_t name_size) { return sys_sethostname(name, name_size); } diff --git a/libc/unistd/setpgid.cpp b/libc/unistd/setpgid.c similarity index 94% rename from libc/unistd/setpgid.cpp rename to libc/unistd/setpgid.c index 72f9dbf7..c0b3ac5a 100644 --- a/libc/unistd/setpgid.cpp +++ b/libc/unistd/setpgid.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 . - unistd/setpgid.cpp + unistd/setpgid.c Change the process group of a process. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_setpgid, SYSCALL_SETPGID, pid_t, pid_t); -extern "C" int setpgid(pid_t pid, pid_t pgid) +int setpgid(pid_t pid, pid_t pgid) { return sys_setpgid(pid, pgid); } diff --git a/libc/unistd/setuid.cpp b/libc/unistd/setuid.c similarity index 95% rename from libc/unistd/setuid.cpp rename to libc/unistd/setuid.c index 028eb7b5..5f4d65da 100644 --- a/libc/unistd/setuid.cpp +++ b/libc/unistd/setuid.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 . - unistd/setuid.cpp + unistd/setuid.c Set user id. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL1(uid_t, sys_setuid, SYSCALL_SETUID, uid_t); -extern "C" int setuid(uid_t uid) +int setuid(uid_t uid) { return sys_setuid(uid); } diff --git a/libc/unistd/sfork.cpp b/libc/unistd/sfork.c similarity index 92% rename from libc/unistd/sfork.cpp rename to libc/unistd/sfork.c index 4161cdf5..c11acb8d 100644 --- a/libc/unistd/sfork.cpp +++ b/libc/unistd/sfork.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 . - unistd/sfork.cpp + unistd/sfork.c Create a new task inheriting some properties from the current task. *******************************************************************************/ @@ -26,9 +26,9 @@ #include #include -extern "C" pid_t __sfork(int flags, struct tfork* regs); +pid_t __sfork(int flags, struct tfork* regs); -extern "C" pid_t sfork(int flags) +pid_t sfork(int flags) { struct tfork regs; memset(®s, 0, sizeof(regs)); diff --git a/libc/unistd/sleep.cpp b/libc/unistd/sleep.c similarity index 95% rename from libc/unistd/sleep.cpp rename to libc/unistd/sleep.c index 319719b4..b29d53ff 100644 --- a/libc/unistd/sleep.cpp +++ b/libc/unistd/sleep.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 . - unistd/sleep.cpp + unistd/sleep.c Blocks the current thread for for at least N seconds. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" unsigned sleep(unsigned secs) +unsigned sleep(unsigned secs) { struct timespec delay = timespec_make(secs, 0); struct timespec left; diff --git a/libc/unistd/symlink.cpp b/libc/unistd/symlink.c similarity index 92% rename from libc/unistd/symlink.cpp rename to libc/unistd/symlink.c index e5becae6..d8565837 100644 --- a/libc/unistd/symlink.cpp +++ b/libc/unistd/symlink.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 . - unistd/symlink.cpp + unistd/symlink.c Create a symbolic link. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int symlink(const char* oldpath, const char* newpath) +int symlink(const char* oldpath, const char* newpath) { return symlinkat(oldpath, AT_FDCWD, newpath); } diff --git a/libc/unistd/symlinkat.cpp b/libc/unistd/symlinkat.c similarity index 91% rename from libc/unistd/symlinkat.cpp rename to libc/unistd/symlinkat.c index 01e86f3d..af124b65 100644 --- a/libc/unistd/symlinkat.cpp +++ b/libc/unistd/symlinkat.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 . - unistd/symlinkat.cpp + unistd/symlinkat.c Create a symbolic link. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL3(int, sys_symlinkat, SYSCALL_SYMLINKAT, const char*, int, const char*); -extern "C" int symlinkat(const char* oldpath, int newdirfd, const char* newpath) +int symlinkat(const char* oldpath, int newdirfd, const char* newpath) { return sys_symlinkat(oldpath, newdirfd, newpath); } diff --git a/libc/unistd/sysconf.cpp b/libc/unistd/sysconf.c similarity index 96% rename from libc/unistd/sysconf.cpp rename to libc/unistd/sysconf.c index 78005bda..12a1416a 100644 --- a/libc/unistd/sysconf.cpp +++ b/libc/unistd/sysconf.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 . - unistd/sysconf.cpp + unistd/sysconf.c Get configuration information at runtime. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" long sysconf(int name) +long sysconf(int name) { switch ( name ) { diff --git a/libc/unistd/tcgetpgrp.cpp b/libc/unistd/tcgetpgrp.c similarity index 95% rename from libc/unistd/tcgetpgrp.cpp rename to libc/unistd/tcgetpgrp.c index e7a116ff..40208dfa 100644 --- a/libc/unistd/tcgetpgrp.cpp +++ b/libc/unistd/tcgetpgrp.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 . - unistd/tcgetpgrp.cpp + unistd/tcgetpgrp.c Get the foreground process group of a terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL1(pid_t, sys_tcgetpgrp, SYSCALL_TCGETPGRP, int); -extern "C" pid_t tcgetpgrp(int fd) +pid_t tcgetpgrp(int fd) { return sys_tcgetpgrp(fd); } diff --git a/libc/unistd/tcsetpgrp.cpp b/libc/unistd/tcsetpgrp.c similarity index 94% rename from libc/unistd/tcsetpgrp.cpp rename to libc/unistd/tcsetpgrp.c index a5c8401c..b202331e 100644 --- a/libc/unistd/tcsetpgrp.cpp +++ b/libc/unistd/tcsetpgrp.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 . - unistd/tcsetpgrp.cpp + unistd/tcsetpgrp.c set the foreground process group of a terminal. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(int, sys_tcsetpgrp, SYSCALL_TCSETPGRP, int, pid_t); -extern "C" int tcsetpgrp(int fd, pid_t pgid) +int tcsetpgrp(int fd, pid_t pgid) { return sys_tcsetpgrp(fd, pgid); } diff --git a/libc/unistd/tfork.cpp b/libc/unistd/tfork.c similarity index 94% rename from libc/unistd/tfork.cpp rename to libc/unistd/tfork.c index 33824273..dd43936a 100644 --- a/libc/unistd/tfork.cpp +++ b/libc/unistd/tfork.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 . - unistd/tfork.cpp + unistd/tfork.c Create a new task inheriting some properties from the current task. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL2(pid_t, sys_tfork, SYSCALL_TFORK, int, struct tfork*); -extern "C" pid_t tfork(int flags, struct tfork* regs) +pid_t tfork(int flags, struct tfork* regs) { return sys_tfork(flags, regs); } diff --git a/libc/unistd/truncate.cpp b/libc/unistd/truncate.c similarity index 93% rename from libc/unistd/truncate.cpp rename to libc/unistd/truncate.c index 488ef1ba..95d5baff 100644 --- a/libc/unistd/truncate.cpp +++ b/libc/unistd/truncate.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 . - unistd/truncate.cpp + unistd/truncate.c Truncates a file to a specific size. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" int truncate(const char* pathname, off_t length) +int truncate(const char* pathname, off_t length) { return truncateat(AT_FDCWD, pathname, length); } diff --git a/libc/unistd/truncateat.cpp b/libc/unistd/truncateat.c similarity index 92% rename from libc/unistd/truncateat.cpp rename to libc/unistd/truncateat.c index c417933f..3c60806b 100644 --- a/libc/unistd/truncateat.cpp +++ b/libc/unistd/truncateat.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 . - unistd/truncateat.cpp + unistd/truncateat.c Truncates a file to a specific size. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL3(int, sys_truncateat, SYSCALL_TRUNCATEAT, int, const char*, off_t); -extern "C" int truncateat(int dirfd, const char* pathname, off_t length) +int truncateat(int dirfd, const char* pathname, off_t length) { return sys_truncateat(dirfd, pathname, length); } diff --git a/libc/unistd/ttyname.cpp b/libc/unistd/ttyname.c similarity index 96% rename from libc/unistd/ttyname.cpp rename to libc/unistd/ttyname.c index 1bb908a9..c607a45c 100644 --- a/libc/unistd/ttyname.cpp +++ b/libc/unistd/ttyname.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 . - unistd/ttyname.cpp + unistd/ttyname.c Returns the pathname of a terminal. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" char* ttyname(int fd) +char* ttyname(int fd) { static char* result = NULL; static size_t result_size = 0; diff --git a/libc/unistd/ttyname_r.cpp b/libc/unistd/ttyname_r.c similarity index 93% rename from libc/unistd/ttyname_r.cpp rename to libc/unistd/ttyname_r.c index 98e63bed..6917b9a6 100644 --- a/libc/unistd/ttyname_r.cpp +++ b/libc/unistd/ttyname_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 . - unistd/ttyname_r.cpp + unistd/ttyname_r.c Returns the pathname of a terminal. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int ttyname_r(int fd, char* path, size_t path_size) +int ttyname_r(int fd, char* path, size_t path_size) { if ( isatty(fd) < 1 ) return -1; diff --git a/libc/unistd/unlink.cpp b/libc/unistd/unlink.c similarity index 94% rename from libc/unistd/unlink.cpp rename to libc/unistd/unlink.c index dadf9f40..49f1cd84 100644 --- a/libc/unistd/unlink.cpp +++ b/libc/unistd/unlink.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 . - unistd/unlink.cpp + unistd/unlink.c Removes a directory entry. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int unlink(const char* pathname) +int unlink(const char* pathname) { return unlinkat(AT_FDCWD, pathname, 0); } diff --git a/libc/unistd/unlinkat.cpp b/libc/unistd/unlinkat.c similarity index 92% rename from libc/unistd/unlinkat.cpp rename to libc/unistd/unlinkat.c index 134a3744..b6d0a3d4 100644 --- a/libc/unistd/unlinkat.cpp +++ b/libc/unistd/unlinkat.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 . - unistd/unlinkat.cpp + unistd/unlinkat.c Removes a directory entry relative to directory. *******************************************************************************/ @@ -29,7 +29,7 @@ DEFN_SYSCALL3(int, sys_unlinkat, SYSCALL_UNLINKAT, int, const char*, int); -extern "C" int unlinkat(int dirfd, const char* pathname, int flags) +int unlinkat(int dirfd, const char* pathname, int flags) { return sys_unlinkat(dirfd, pathname, flags); } diff --git a/libc/unistd/usleep.cpp b/libc/unistd/usleep.c similarity index 95% rename from libc/unistd/usleep.cpp rename to libc/unistd/usleep.c index cd8f13e6..bc75e414 100644 --- a/libc/unistd/usleep.cpp +++ b/libc/unistd/usleep.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 . - unistd/usleep.cpp + unistd/usleep.c Blocks the current thread for for at least N microseconds. *******************************************************************************/ @@ -26,7 +26,7 @@ #include #include -extern "C" int usleep(useconds_t usecs) +int usleep(useconds_t usecs) { struct timespec delay = timespec_canonalize(timespec_make(0, usecs * 1000)); return nanosleep(&delay, NULL); diff --git a/libc/unistd/write.cpp b/libc/unistd/write.c similarity index 93% rename from libc/unistd/write.cpp rename to libc/unistd/write.c index 0202760a..00164513 100644 --- a/libc/unistd/write.cpp +++ b/libc/unistd/write.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 . - unistd/write.cpp + unistd/write.c Writes to a file descriptor. *******************************************************************************/ @@ -28,7 +28,7 @@ DEFN_SYSCALL3(ssize_t, sys_write, SYSCALL_WRITE, int, const void*, size_t); -extern "C" ssize_t write(int fd, const void* buf, size_t count) +ssize_t write(int fd, const void* buf, size_t count) { return sys_write(fd, buf, count); } diff --git a/libc/utime/utime.cpp b/libc/utime/utime.c similarity index 94% rename from libc/utime/utime.cpp rename to libc/utime/utime.c index 261cc170..71331abf 100644 --- a/libc/utime/utime.cpp +++ b/libc/utime/utime.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 . - utime/utime.cpp + utime/utime.c Change file last access and modification times. *******************************************************************************/ @@ -32,7 +32,7 @@ // TODO: This interface has been deprecated by utimens (although that's a // non-standard Sortix extension, in which case by utimensat) - it'd be // nice to remove this at some point. -extern "C" int utime(const char* filepath, const struct utimbuf* times) +int utime(const char* filepath, const struct utimbuf* times) { struct timespec ts_times[2]; ts_times[0] = timespec_make(times->actime, 0); diff --git a/libc/wchar/btowc.cpp b/libc/wchar/btowc.c similarity index 96% rename from libc/wchar/btowc.cpp rename to libc/wchar/btowc.c index edd1ad5a..eae1b688 100644 --- a/libc/wchar/btowc.cpp +++ b/libc/wchar/btowc.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 . - wchar/btowc.cpp + wchar/btowc.c Single byte to wide character conversion. *******************************************************************************/ @@ -27,7 +27,7 @@ #include #include -extern "C" wint_t btowc(int ic) +wint_t btowc(int ic) { if ( ic == EOF ) return WEOF; diff --git a/libc/wchar/mbrlen.cpp b/libc/wchar/mbrlen.c similarity index 97% rename from libc/wchar/mbrlen.cpp rename to libc/wchar/mbrlen.c index 2589f837..4dddd1ed 100644 --- a/libc/wchar/mbrlen.cpp +++ b/libc/wchar/mbrlen.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/mbrlen.cpp + wchar/mbrlen.c Determine number of bytes in next multibyte character. *******************************************************************************/ #include -extern "C" size_t mbrlen(const char* restrict s, size_t n, mbstate_t* restrict ps) { static mbstate_t static_ps; diff --git a/libc/wchar/mbrtowc.cpp b/libc/wchar/mbrtowc.c similarity index 99% rename from libc/wchar/mbrtowc.cpp rename to libc/wchar/mbrtowc.c index 985d68e1..75ce646f 100644 --- a/libc/wchar/mbrtowc.cpp +++ b/libc/wchar/mbrtowc.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 . - wchar/mbrtowc.cpp + wchar/mbrtowc.c Convert a multibyte sequence to a wide character. *******************************************************************************/ @@ -134,7 +134,6 @@ size_t utf8_mbrtowc(wchar_t* restrict pwc, return result != L'\0' ? i : 0; } -extern "C" size_t mbrtowc(wchar_t* restrict pwc, const char* restrict s, size_t n, diff --git a/libc/wchar/mbsinit.cpp b/libc/wchar/mbsinit.c similarity index 94% rename from libc/wchar/mbsinit.cpp rename to libc/wchar/mbsinit.c index 1bc8ac51..8ca5b912 100644 --- a/libc/wchar/mbsinit.cpp +++ b/libc/wchar/mbsinit.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 . - wchar/mbsinit.cpp + wchar/mbsinit.c Determine conversion object status. *******************************************************************************/ #include -extern "C" int mbsinit(const mbstate_t* ps) +int mbsinit(const mbstate_t* ps) { return !ps || !ps->count; } diff --git a/libc/wchar/mbsnrtowcs.cpp b/libc/wchar/mbsnrtowcs.c similarity index 98% rename from libc/wchar/mbsnrtowcs.cpp rename to libc/wchar/mbsnrtowcs.c index 53c919e3..e07a133f 100644 --- a/libc/wchar/mbsnrtowcs.cpp +++ b/libc/wchar/mbsnrtowcs.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 . - wchar/mbsnrtowcs.cpp + wchar/mbsnrtowcs.c Convert a multibyte string to a wide-character string. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" size_t mbsnrtowcs(wchar_t* restrict dst, const char** restrict src_ptr, size_t src_len, diff --git a/libc/wchar/mbsrtowcs.cpp b/libc/wchar/mbsrtowcs.c similarity index 97% rename from libc/wchar/mbsrtowcs.cpp rename to libc/wchar/mbsrtowcs.c index 0289d266..c400e9d4 100644 --- a/libc/wchar/mbsrtowcs.cpp +++ b/libc/wchar/mbsrtowcs.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 . - wchar/mbsrtowcs.cpp + wchar/mbsrtowcs.c Convert a multibyte string to a wide-character string. *******************************************************************************/ @@ -29,7 +29,6 @@ #include #include -extern "C" size_t mbsrtowcs(wchar_t* restrict dst, const char** restrict src_ptr, size_t dst_len, diff --git a/libc/wchar/wcpcpy.cpp b/libc/wchar/wcpcpy.c similarity index 91% rename from libc/wchar/wcpcpy.cpp rename to libc/wchar/wcpcpy.c index efd81f03..0cbf91c4 100644 --- a/libc/wchar/wcpcpy.cpp +++ b/libc/wchar/wcpcpy.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 . - wchar/wcpcpy.cpp + wchar/wcpcpy.c Copy a string returning a pointer to its end. *******************************************************************************/ #include -extern "C" wchar_t* wcpcpy(wchar_t* restrict dest, const wchar_t* restrict src) +wchar_t* wcpcpy(wchar_t* restrict dest, const wchar_t* restrict src) { size_t index; for ( index = 0; src[index]; index++ ) diff --git a/libc/wchar/wcpncpy.cpp b/libc/wchar/wcpncpy.c similarity index 97% rename from libc/wchar/wcpncpy.cpp rename to libc/wchar/wcpncpy.c index ddfa5514..01487f8b 100644 --- a/libc/wchar/wcpncpy.cpp +++ b/libc/wchar/wcpncpy.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcpncpy.cpp + wchar/wcpncpy.c Copies a string into a fixed size buffer and returns last byte. *******************************************************************************/ #include -extern "C" wchar_t* wcpncpy(wchar_t* restrict dest, const wchar_t* restrict src, size_t n) { size_t i; diff --git a/libc/wchar/wcrtomb.cpp b/libc/wchar/wcrtomb.c similarity index 98% rename from libc/wchar/wcrtomb.cpp rename to libc/wchar/wcrtomb.c index 32bea61b..6b0ef485 100644 --- a/libc/wchar/wcrtomb.cpp +++ b/libc/wchar/wcrtomb.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 . - wchar/wcrtomb.cpp + wchar/wcrtomb.c Convert a wide character to a multibyte sequence. *******************************************************************************/ @@ -27,8 +27,9 @@ #include static -size_t utf8_wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict /*ps*/) +size_t utf8_wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps) { + (void) ps; // The definition of UTF-8 prohibits encoding character numbers between // U+D800 and U+DFFF, which are reserved for use with the UTF-16 encoding // form (as surrogate pairs) and do not directly represent characters. @@ -97,7 +98,6 @@ size_t utf8_wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict /*ps*/) return errno = EILSEQ; return (size_t) -1; } -extern "C" size_t wcrtomb(char* restrict s, wchar_t wc, mbstate_t* restrict ps) { char internal_buffer[MB_CUR_MAX]; diff --git a/libc/wchar/wcscasecmp.cpp b/libc/wchar/wcscasecmp.c similarity index 96% rename from libc/wchar/wcscasecmp.cpp rename to libc/wchar/wcscasecmp.c index d55344d1..9bb48b29 100644 --- a/libc/wchar/wcscasecmp.cpp +++ b/libc/wchar/wcscasecmp.c @@ -17,15 +17,15 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcscasecmp.cpp + wchar/wcscasecmp.c Compares two strings ignoring case. *******************************************************************************/ +#include #include #include -extern "C" int wcscasecmp(const wchar_t* a, const wchar_t* b) { for ( size_t i = 0; true; i++ ) diff --git a/libc/wchar/wcscat.cpp b/libc/wchar/wcscat.c similarity index 92% rename from libc/wchar/wcscat.cpp rename to libc/wchar/wcscat.c index 42db6e62..147709b2 100644 --- a/libc/wchar/wcscat.cpp +++ b/libc/wchar/wcscat.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 . - wchar/wcscat.cpp + wchar/wcscat.c Appends a string onto another string. *******************************************************************************/ #include -extern "C" wchar_t* wcscat(wchar_t* dest, const wchar_t* src) +wchar_t* wcscat(wchar_t* dest, const wchar_t* src) { wcscpy(dest + wcslen(dest), src); return dest; diff --git a/libc/wchar/wcschr.cpp b/libc/wchar/wcschr.c similarity index 93% rename from libc/wchar/wcschr.cpp rename to libc/wchar/wcschr.c index f4602f85..705826a8 100644 --- a/libc/wchar/wcschr.cpp +++ b/libc/wchar/wcschr.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 . - wchar/wcschr.cpp + wchar/wcschr.c Searches a string for a specific character. *******************************************************************************/ #include -extern "C" wchar_t* wcschr(const wchar_t* str, wchar_t uc) +wchar_t* wcschr(const wchar_t* str, wchar_t uc) { wchar_t* ret = wcschrnul(str, uc); return (wint_t) uc == ((wint_t*) ret)[0] ? ret : NULL; diff --git a/libc/wchar/wcschrnul.cpp b/libc/wchar/wcschrnul.c similarity index 92% rename from libc/wchar/wcschrnul.cpp rename to libc/wchar/wcschrnul.c index d85ab85b..1b6c1873 100644 --- a/libc/wchar/wcschrnul.cpp +++ b/libc/wchar/wcschrnul.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 . - wchar/wcschrnul.cpp + wchar/wcschrnul.c Searches a string for a specific character. *******************************************************************************/ +#include #include -extern "C" wchar_t* wcschrnul(const wchar_t* str, wchar_t uc) +wchar_t* wcschrnul(const wchar_t* str, wchar_t uc) { const wint_t* ustr = (const wint_t*) str; for ( size_t i = 0; true; i++) diff --git a/libc/wchar/wcscmp.cpp b/libc/wchar/wcscmp.c similarity index 93% rename from libc/wchar/wcscmp.cpp rename to libc/wchar/wcscmp.c index 9bd2d56d..963ea2ab 100644 --- a/libc/wchar/wcscmp.cpp +++ b/libc/wchar/wcscmp.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 . - wchar/wcscmp.cpp + wchar/wcscmp.c Compares two strings. *******************************************************************************/ +#include #include -extern "C" int wcscmp(const wchar_t* a, const wchar_t* b) +int wcscmp(const wchar_t* a, const wchar_t* b) { for ( size_t i = 0; true; i++ ) { diff --git a/libc/wchar/wcscoll.cpp b/libc/wchar/wcscoll.c similarity index 92% rename from libc/wchar/wcscoll.cpp rename to libc/wchar/wcscoll.c index a51d39ca..8ddcd260 100644 --- a/libc/wchar/wcscoll.cpp +++ b/libc/wchar/wcscoll.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 . - wchar/wcscoll.cpp + wchar/wcscoll.c Compare two strings using the current locale. *******************************************************************************/ #include -extern "C" int wcscoll(const wchar_t* s1, const wchar_t* s2) +int wcscoll(const wchar_t* s1, const wchar_t* s2) { // TODO: Pay attention to locales. return wcscmp(s1, s2); diff --git a/libc/wchar/wcscpy.cpp b/libc/wchar/wcscpy.c similarity index 93% rename from libc/wchar/wcscpy.cpp rename to libc/wchar/wcscpy.c index 9e5d2325..b41f9d0c 100644 --- a/libc/wchar/wcscpy.cpp +++ b/libc/wchar/wcscpy.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 . - wchar/wcscpy.cpp + wchar/wcscpy.c Copies a string and returns dest. *******************************************************************************/ #include -extern "C" wchar_t* wcscpy(wchar_t* dest, const wchar_t* src) +wchar_t* wcscpy(wchar_t* dest, const wchar_t* src) { size_t index; for ( index = 0; src[index]; index++ ) diff --git a/libc/wchar/wcscspn.cpp b/libc/wchar/wcscspn.c similarity index 93% rename from libc/wchar/wcscspn.cpp rename to libc/wchar/wcscspn.c index 9d7eb29d..061f730c 100644 --- a/libc/wchar/wcscspn.cpp +++ b/libc/wchar/wcscspn.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 . - wchar/wcscspn.cpp + wchar/wcscspn.c Search a string for a set of characters. *******************************************************************************/ +#include #include -extern "C" size_t wcscspn(const wchar_t* str, const wchar_t* reject) +size_t wcscspn(const wchar_t* str, const wchar_t* reject) { size_t reject_length = 0; while ( reject[reject_length] ) diff --git a/libc/wchar/wcsdup.cpp b/libc/wchar/wcsdup.c similarity index 94% rename from libc/wchar/wcsdup.cpp rename to libc/wchar/wcsdup.c index 030dbd04..162261ed 100644 --- a/libc/wchar/wcsdup.cpp +++ b/libc/wchar/wcsdup.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 . - wchar/wcsdup.cpp + wchar/wcsdup.c Creates a copy of a string. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" wchar_t* wcsdup(const wchar_t* input) +wchar_t* wcsdup(const wchar_t* input) { size_t input_length = wcslen(input); wchar_t* result = (wchar_t*) malloc(sizeof(wchar_t) * (input_length + 1)); diff --git a/libc/wchar/wcsftime.cpp b/libc/wchar/wcsftime.c similarity index 95% rename from libc/wchar/wcsftime.cpp rename to libc/wchar/wcsftime.c index acb08c88..5e0f28c0 100644 --- a/libc/wchar/wcsftime.cpp +++ b/libc/wchar/wcsftime.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 . - wchar/wcsftime.cpp + wchar/wcsftime.c Format time and date into a string. *******************************************************************************/ @@ -27,4 +27,4 @@ #define STRFTIME_L(x) L##x #define STRFTIME_IS_WCHAR 1 -#include "../time/strftime.cpp" +#include "../time/strftime.c" diff --git a/libc/wchar/wcslcat.cpp b/libc/wchar/wcslcat.c similarity index 97% rename from libc/wchar/wcslcat.cpp rename to libc/wchar/wcslcat.c index 347d3366..4614e531 100644 --- a/libc/wchar/wcslcat.cpp +++ b/libc/wchar/wcslcat.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcslcat.cpp + wchar/wcslcat.c Appends a string onto another string truncating if the string is too small. *******************************************************************************/ #include -extern "C" size_t wcslcat(wchar_t* restrict dest, const wchar_t* restrict src, size_t size) { size_t dest_len = wcsnlen(dest, size); diff --git a/libc/wchar/wcslcpy.cpp b/libc/wchar/wcslcpy.c similarity index 97% rename from libc/wchar/wcslcpy.cpp rename to libc/wchar/wcslcpy.c index edf29e80..365e9de3 100644 --- a/libc/wchar/wcslcpy.cpp +++ b/libc/wchar/wcslcpy.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcslcpy.cpp + wchar/wcslcpy.c Copies a string and truncates it if the destination is too small. *******************************************************************************/ #include -extern "C" size_t wcslcpy(wchar_t* restrict dest, const wchar_t* restrict src, size_t size) { if ( !size ) diff --git a/libc/wchar/wcslen.cpp b/libc/wchar/wcslen.c similarity index 94% rename from libc/wchar/wcslen.cpp rename to libc/wchar/wcslen.c index 737233af..29f8c82a 100644 --- a/libc/wchar/wcslen.cpp +++ b/libc/wchar/wcslen.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 . - wchar/wcslen.cpp + wchar/wcslen.c Returns the length of a string. *******************************************************************************/ #include -extern "C" size_t wcslen(const wchar_t* str) +size_t wcslen(const wchar_t* str) { size_t ret = 0; while ( str[ret] ) diff --git a/libc/wchar/wcsncasecmp.cpp b/libc/wchar/wcsncasecmp.c similarity index 97% rename from libc/wchar/wcsncasecmp.cpp rename to libc/wchar/wcsncasecmp.c index 24d27c25..665db035 100644 --- a/libc/wchar/wcsncasecmp.cpp +++ b/libc/wchar/wcsncasecmp.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 . - wchar/wcsncasecmp.cpp + wchar/wcsncasecmp.c Compares a prefix of two strings ignoring case. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" int wcsncasecmp(const wchar_t* a, const wchar_t* b, size_t max_count) { for ( size_t i = 0; i < max_count; i++ ) diff --git a/libc/wchar/wcsncat.cpp b/libc/wchar/wcsncat.c similarity index 92% rename from libc/wchar/wcsncat.cpp rename to libc/wchar/wcsncat.c index 80c023ed..881a9ec2 100644 --- a/libc/wchar/wcsncat.cpp +++ b/libc/wchar/wcsncat.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 . - wchar/wcsncat.cpp + wchar/wcsncat.c Appends parts of a string onto another string. *******************************************************************************/ #include -extern "C" wchar_t* wcsncat(wchar_t* dest, const wchar_t* src, size_t n) +wchar_t* wcsncat(wchar_t* dest, const wchar_t* src, size_t n) { size_t dest_len = wcslen(dest); size_t i; diff --git a/libc/wchar/wcsncmp.cpp b/libc/wchar/wcsncmp.c similarity index 92% rename from libc/wchar/wcsncmp.cpp rename to libc/wchar/wcsncmp.c index a57a3720..538d9a97 100644 --- a/libc/wchar/wcsncmp.cpp +++ b/libc/wchar/wcsncmp.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 . - wchar/wcsncmp.cpp + wchar/wcsncmp.c Compares a prefix of two wide strings. *******************************************************************************/ #include -extern "C" int wcsncmp(const wchar_t* a, const wchar_t* b, size_t max_count) +int wcsncmp(const wchar_t* a, const wchar_t* b, size_t max_count) { for ( size_t i = 0; i < max_count; i++ ) { diff --git a/libc/wchar/wcsncpy.cpp b/libc/wchar/wcsncpy.c similarity index 92% rename from libc/wchar/wcsncpy.cpp rename to libc/wchar/wcsncpy.c index 15fe10ce..9fd84354 100644 --- a/libc/wchar/wcsncpy.cpp +++ b/libc/wchar/wcsncpy.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 . - wchar/wcsncpy.cpp + wchar/wcsncpy.c Copies a string into a fixed size buffer and returns dest. *******************************************************************************/ #include -extern "C" wchar_t* wcsncpy(wchar_t* dest, const wchar_t* src, size_t n) +wchar_t* wcsncpy(wchar_t* dest, const wchar_t* src, size_t n) { size_t i; for ( i = 0; i < n && src[i] != L'\0'; i++ ) diff --git a/libc/wchar/wcsnlen.cpp b/libc/wchar/wcsnlen.c similarity index 93% rename from libc/wchar/wcsnlen.cpp rename to libc/wchar/wcsnlen.c index 5841e623..fe388808 100644 --- a/libc/wchar/wcsnlen.cpp +++ b/libc/wchar/wcsnlen.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 . - wchar/wcsnlen.cpp + wchar/wcsnlen.c Returns the length of a fixed length string. *******************************************************************************/ #include -extern "C" size_t wcsnlen(const wchar_t* str, size_t maxlen) +size_t wcsnlen(const wchar_t* str, size_t maxlen) { size_t ret = 0; while ( ret < maxlen && str[ret] ) diff --git a/libc/wchar/wcsnrtombs.cpp b/libc/wchar/wcsnrtombs.c similarity index 98% rename from libc/wchar/wcsnrtombs.cpp rename to libc/wchar/wcsnrtombs.c index 0e634955..6ad13619 100644 --- a/libc/wchar/wcsnrtombs.cpp +++ b/libc/wchar/wcsnrtombs.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 . - wchar/wcsnrtombs.cpp + wchar/wcsnrtombs.c Convert a wide-character string to multibyte string. *******************************************************************************/ @@ -28,7 +28,6 @@ #include #include -extern "C" size_t wcsnrtombs(char* restrict dst, const wchar_t** restrict src_ptr, size_t src_len, diff --git a/libc/wchar/wcspbrk.cpp b/libc/wchar/wcspbrk.c similarity index 92% rename from libc/wchar/wcspbrk.cpp rename to libc/wchar/wcspbrk.c index 6d7c7499..43fa75ed 100644 --- a/libc/wchar/wcspbrk.cpp +++ b/libc/wchar/wcspbrk.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 . - wchar/wcspbrk.cpp + wchar/wcspbrk.c Search a wide string for any of a set of wide characters. *******************************************************************************/ #include -extern "C" wchar_t* wcspbrk(const wchar_t* str, const wchar_t* accept) +wchar_t* wcspbrk(const wchar_t* str, const wchar_t* accept) { size_t reject_length = wcscspn(str, accept); if ( !str[reject_length] ) diff --git a/libc/wchar/wcsrchr.cpp b/libc/wchar/wcsrchr.c similarity index 93% rename from libc/wchar/wcsrchr.cpp rename to libc/wchar/wcsrchr.c index fa8ac4d1..093d592e 100644 --- a/libc/wchar/wcsrchr.cpp +++ b/libc/wchar/wcsrchr.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 . - wchar/wcsrchr.cpp + wchar/wcsrchr.c Searches a string for a specific character. *******************************************************************************/ +#include #include -extern "C" wchar_t* wcsrchr(const wchar_t* str, wchar_t uc) +wchar_t* wcsrchr(const wchar_t* str, wchar_t uc) { const wint_t* ustr = (const wint_t*) str; const wchar_t* last = NULL; diff --git a/libc/wchar/wcsrtombs.cpp b/libc/wchar/wcsrtombs.c similarity index 97% rename from libc/wchar/wcsrtombs.cpp rename to libc/wchar/wcsrtombs.c index 09c7067d..bfdea371 100644 --- a/libc/wchar/wcsrtombs.cpp +++ b/libc/wchar/wcsrtombs.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 . - wchar/wcsrtombs.cpp + wchar/wcsrtombs.c Convert a wide-character string to multibyte string. *******************************************************************************/ @@ -25,7 +25,6 @@ #include #include -extern "C" size_t wcsrtombs(char* restrict dst, const wchar_t** restrict src_ptr, size_t dst_len, diff --git a/libc/wchar/wcsspn.cpp b/libc/wchar/wcsspn.c similarity index 93% rename from libc/wchar/wcsspn.cpp rename to libc/wchar/wcsspn.c index b466a93c..452abdd7 100644 --- a/libc/wchar/wcsspn.cpp +++ b/libc/wchar/wcsspn.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 . - wchar/wcsspn.cpp + wchar/wcsspn.c Search a string for a set of characters. *******************************************************************************/ +#include #include -extern "C" size_t wcsspn(const wchar_t* str, const wchar_t* accept) +size_t wcsspn(const wchar_t* str, const wchar_t* accept) { size_t accept_length = 0; while ( accept[accept_length] ) diff --git a/libc/wchar/wcsstr.cpp b/libc/wchar/wcsstr.c similarity index 97% rename from libc/wchar/wcsstr.cpp rename to libc/wchar/wcsstr.c index b4ca8379..aef5aa05 100644 --- a/libc/wchar/wcsstr.cpp +++ b/libc/wchar/wcsstr.c @@ -17,16 +17,16 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcsstr.cpp + wchar/wcsstr.c Locate a wide substring. *******************************************************************************/ +#include #include // TODO: This simple and hacky implementation runs in O(N^2) even though this // problem can be solved in O(N). -extern "C" wchar_t* wcsstr(const wchar_t* restrict haystack, const wchar_t* restrict needle) { diff --git a/libc/wchar/wcstod.cpp b/libc/wchar/wcstod.c similarity index 95% rename from libc/wchar/wcstod.cpp rename to libc/wchar/wcstod.c index 4016ffe7..d02773d2 100644 --- a/libc/wchar/wcstod.cpp +++ b/libc/wchar/wcstod.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 . - wchar/wcstod.cpp + wchar/wcstod.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -31,4 +31,4 @@ #define STRTOF_STRNCASECMP wcsncasecmp #define STRTOF_POW pow -#include "../stdlib/strtof.cpp" +#include "../stdlib/strtof.c" diff --git a/libc/wchar/wcstof.cpp b/libc/wchar/wcstof.c similarity index 95% rename from libc/wchar/wcstof.cpp rename to libc/wchar/wcstof.c index cf5dfca1..669c7913 100644 --- a/libc/wchar/wcstof.cpp +++ b/libc/wchar/wcstof.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 . - wchar/wcstof.cpp + wchar/wcstof.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -31,4 +31,4 @@ #define STRTOF_STRNCASECMP wcsncasecmp #define STRTOF_POW powf -#include "../stdlib/strtof.cpp" +#include "../stdlib/strtof.c" diff --git a/libc/wchar/wcstok.cpp b/libc/wchar/wcstok.c similarity index 92% rename from libc/wchar/wcstok.cpp rename to libc/wchar/wcstok.c index 8cbbc1e1..e88ba078 100644 --- a/libc/wchar/wcstok.cpp +++ b/libc/wchar/wcstok.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 . - wchar/wcstok.cpp + wchar/wcstok.c Extract tokens from strings. *******************************************************************************/ #include -extern "C" wchar_t* wcstok(wchar_t* str, const wchar_t* delim, wchar_t** saveptr) +wchar_t* wcstok(wchar_t* str, const wchar_t* delim, wchar_t** saveptr) { if ( !str && !*saveptr ) return NULL; diff --git a/libc/wchar/wcstol.cpp b/libc/wchar/wcstol.c similarity index 96% rename from libc/wchar/wcstol.cpp rename to libc/wchar/wcstol.c index c12ee79a..51265fa5 100644 --- a/libc/wchar/wcstol.cpp +++ b/libc/wchar/wcstol.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 . - wchar/wcstol.cpp + wchar/wcstol.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX LONG_MAX #define STRTOL_INT_IS_UNSIGNED false -#include "../stdlib/strtol.cpp" +#include "../stdlib/strtol.c" diff --git a/libc/wchar/wcstold.cpp b/libc/wchar/wcstold.c similarity index 95% rename from libc/wchar/wcstold.cpp rename to libc/wchar/wcstold.c index e13682c2..2aaddd20 100644 --- a/libc/wchar/wcstold.cpp +++ b/libc/wchar/wcstold.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 . - wchar/wcstold.cpp + wchar/wcstold.c Converts floating numbers represented as strings to binary representation. *******************************************************************************/ @@ -31,4 +31,4 @@ #define STRTOF_STRNCASECMP wcsncasecmp #define STRTOF_POW pow /* TODO: powl */ -#include "../stdlib/strtof.cpp" +#include "../stdlib/strtof.c" diff --git a/libc/wchar/wcstoll.cpp b/libc/wchar/wcstoll.c similarity index 96% rename from libc/wchar/wcstoll.cpp rename to libc/wchar/wcstoll.c index 64ed1cf2..093d81f6 100644 --- a/libc/wchar/wcstoll.cpp +++ b/libc/wchar/wcstoll.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 . - wchar/wcstoll.cpp + wchar/wcstoll.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX LLONG_MAX #define STRTOL_INT_IS_UNSIGNED false -#include "../stdlib/strtol.cpp" +#include "../stdlib/strtol.c" diff --git a/libc/wchar/wcstoul.cpp b/libc/wchar/wcstoul.c similarity index 96% rename from libc/wchar/wcstoul.cpp rename to libc/wchar/wcstoul.c index 60038c70..5e7bae97 100644 --- a/libc/wchar/wcstoul.cpp +++ b/libc/wchar/wcstoul.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 . - wchar/wcstoul.cpp + wchar/wcstoul.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX ULONG_MAX #define STRTOL_INT_IS_UNSIGNED true -#include "../stdlib/strtol.cpp" +#include "../stdlib/strtol.c" diff --git a/libc/wchar/wcstoull.cpp b/libc/wchar/wcstoull.c similarity index 96% rename from libc/wchar/wcstoull.cpp rename to libc/wchar/wcstoull.c index 114ff856..157364be 100644 --- a/libc/wchar/wcstoull.cpp +++ b/libc/wchar/wcstoull.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 . - wchar/wcstoull.cpp + wchar/wcstoull.c Converts integers represented as strings to binary representation. *******************************************************************************/ @@ -33,4 +33,4 @@ #define STRTOL_INT_MAX ULLONG_MAX #define STRTOL_INT_IS_UNSIGNED true -#include "../stdlib/strtol.cpp" +#include "../stdlib/strtol.c" diff --git a/libc/wchar/wcswidth.cpp b/libc/wchar/wcswidth.c similarity index 94% rename from libc/wchar/wcswidth.cpp rename to libc/wchar/wcswidth.c index 15d4403a..e1aeb817 100644 --- a/libc/wchar/wcswidth.cpp +++ b/libc/wchar/wcswidth.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 . - wchar/wcswidth.cpp + wchar/wcswidth.c Number of column positions of a wide-character string. *******************************************************************************/ #include -extern "C" int wcswidth(const wchar_t* wcs, size_t n) +int wcswidth(const wchar_t* wcs, size_t n) { int result = 0; for ( size_t i = 0; i < n && wcs[n]; i++ ) diff --git a/libc/wchar/wcsxfrm.cpp b/libc/wchar/wcsxfrm.c similarity index 97% rename from libc/wchar/wcsxfrm.cpp rename to libc/wchar/wcsxfrm.c index 61bb9dae..c2f00e84 100644 --- a/libc/wchar/wcsxfrm.cpp +++ b/libc/wchar/wcsxfrm.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wcsxfrm.cpp + wchar/wcsxfrm.c Transform a string such that the result of wcscmp is the same as wcscoll. *******************************************************************************/ #include -extern "C" size_t wcsxfrm(wchar_t* restrict dest, const wchar_t* restrict src, size_t n) { size_t srclen = wcslen(src); diff --git a/libc/wchar/wctob.cpp b/libc/wchar/wctob.c similarity index 96% rename from libc/wchar/wctob.cpp rename to libc/wchar/wctob.c index 14def1a8..3f670885 100644 --- a/libc/wchar/wctob.cpp +++ b/libc/wchar/wctob.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 . - wchar/wctob.cpp + wchar/wctob.c Wide-character to single-byte conversion. *******************************************************************************/ @@ -28,7 +28,7 @@ #include #include -extern "C" int wctob(wint_t wc) +int wctob(wint_t wc) { mbstate_t ps; memset(&ps, 0, sizeof(ps)); diff --git a/libc/wchar/wcwidth.cpp b/libc/wchar/wcwidth.c similarity index 95% rename from libc/wchar/wcwidth.cpp rename to libc/wchar/wcwidth.c index 6772ae06..515397ec 100644 --- a/libc/wchar/wcwidth.cpp +++ b/libc/wchar/wcwidth.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 . - wchar/wcwidth.cpp + wchar/wcwidth.c Number of column positions of a wide-character code. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" int wcwidth(wchar_t wc) +int wcwidth(wchar_t wc) { if ( !wc ) return 0; diff --git a/libc/wchar/wmemchr.cpp b/libc/wchar/wmemchr.c similarity index 92% rename from libc/wchar/wmemchr.cpp rename to libc/wchar/wmemchr.c index 93ebef86..552ee524 100644 --- a/libc/wchar/wmemchr.cpp +++ b/libc/wchar/wmemchr.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 . - wchar/wmemchr.cpp + wchar/wmemchr.c Scans memory for a wide character. *******************************************************************************/ #include -extern "C" wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n) +wchar_t* wmemchr(const wchar_t* s, wchar_t c, size_t n) { for ( size_t i = 0; i < n; i++ ) if ( s[i] == c ) diff --git a/libc/wchar/wmemcmp.cpp b/libc/wchar/wmemcmp.c similarity index 92% rename from libc/wchar/wmemcmp.cpp rename to libc/wchar/wmemcmp.c index 5ada300f..5a53e856 100644 --- a/libc/wchar/wmemcmp.cpp +++ b/libc/wchar/wmemcmp.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 . - wchar/wmemcmp.cpp + wchar/wmemcmp.c Compares two arrays of wide characters. *******************************************************************************/ #include -extern "C" int wmemcmp(const wchar_t* a, const wchar_t* b, size_t n) +int wmemcmp(const wchar_t* a, const wchar_t* b, size_t n) { for ( size_t i = 0; i < n; i++ ) { diff --git a/libc/wchar/wmemcpy.cpp b/libc/wchar/wmemcpy.c similarity index 97% rename from libc/wchar/wmemcpy.cpp rename to libc/wchar/wmemcpy.c index 0db403a5..6cd04723 100644 --- a/libc/wchar/wmemcpy.cpp +++ b/libc/wchar/wmemcpy.c @@ -17,14 +17,13 @@ You should have received a copy of the GNU Lesser General Public License along with the Sortix C Library. If not, see . - wchar/wmemcpy.cpp + wchar/wmemcpy.c Copy wide memory between non-overlapping regions. *******************************************************************************/ #include -extern "C" wchar_t* wmemcpy(wchar_t* restrict dst, const wchar_t* restrict src, size_t n) { for ( size_t i = 0; i < n; i++ ) diff --git a/libc/wchar/wmemmove.cpp b/libc/wchar/wmemmove.c similarity index 92% rename from libc/wchar/wmemmove.cpp rename to libc/wchar/wmemmove.c index e8c01c31..2db14fa5 100644 --- a/libc/wchar/wmemmove.cpp +++ b/libc/wchar/wmemmove.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 . - wchar/wmemmove.cpp + wchar/wmemmove.c Copy wide memory between potentially overlapping regions. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t n) +wchar_t* wmemmove(wchar_t* dst, const wchar_t* src, size_t n) { if ( (uintptr_t) dst < (uintptr_t) src ) { diff --git a/libc/wchar/wmemset.cpp b/libc/wchar/wmemset.c similarity index 92% rename from libc/wchar/wmemset.cpp rename to libc/wchar/wmemset.c index 3aeba351..4c4f1ed5 100644 --- a/libc/wchar/wmemset.cpp +++ b/libc/wchar/wmemset.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 . - wchar/wmemset.cpp + wchar/wmemset.c Initializes a wide character array with the given wide character. *******************************************************************************/ #include -extern "C" wchar_t* wmemset(wchar_t* dst, wchar_t wc, size_t n) +wchar_t* wmemset(wchar_t* dst, wchar_t wc, size_t n) { for ( size_t i = 0; i < n; i++ ) dst[i] = wc; diff --git a/libc/wctype/iswalnum.cpp b/libc/wctype/iswalnum.c similarity index 94% rename from libc/wctype/iswalnum.cpp rename to libc/wctype/iswalnum.c index 9c278b65..9161ee37 100644 --- a/libc/wctype/iswalnum.cpp +++ b/libc/wctype/iswalnum.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 . - wctype/iswalnum.cpp + wctype/iswalnum.c Returns whether the wide character is alphabetical or a digit. *******************************************************************************/ #include -extern "C" int iswalnum(wint_t c) +int iswalnum(wint_t c) { return iswalpha(c) || iswdigit(c); } diff --git a/libc/wctype/iswalpha.cpp b/libc/wctype/iswalpha.c similarity index 94% rename from libc/wctype/iswalpha.cpp rename to libc/wctype/iswalpha.c index ca2edb20..8ce6a629 100644 --- a/libc/wctype/iswalpha.cpp +++ b/libc/wctype/iswalpha.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 . - wctype/iswalpha.cpp + wctype/iswalpha.c Returns whether the wide character is alphabetical. *******************************************************************************/ #include -extern "C" int iswalpha(wint_t c) +int iswalpha(wint_t c) { return iswupper(c) || iswlower(c); } diff --git a/libc/wctype/iswblank.cpp b/libc/wctype/iswblank.c similarity index 94% rename from libc/wctype/iswblank.cpp rename to libc/wctype/iswblank.c index 182230f9..d0600d1e 100644 --- a/libc/wctype/iswblank.cpp +++ b/libc/wctype/iswblank.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 . - wctype/iswblank.cpp + wctype/iswblank.c Returns whether the wide character is blank. *******************************************************************************/ #include -extern "C" int iswblank(wint_t c) +int iswblank(wint_t c) { return c == L' ' || c == L'\t'; } diff --git a/libc/wctype/iswcntrl.cpp b/libc/wctype/iswcntrl.c similarity index 95% rename from libc/wctype/iswcntrl.cpp rename to libc/wctype/iswcntrl.c index f2de04da..79af385a 100644 --- a/libc/wctype/iswcntrl.cpp +++ b/libc/wctype/iswcntrl.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 . - wctype/iswcntrl.cpp + wctype/iswcntrl.c Returns whether the wide character is a control character. *******************************************************************************/ #include -extern "C" int iswcntrl(wint_t c) +int iswcntrl(wint_t c) { return /*0 <= c [c is unsigned] && */ c < 32; } diff --git a/libc/wctype/iswctype.cpp b/libc/wctype/iswctype.c similarity index 93% rename from libc/wctype/iswctype.cpp rename to libc/wctype/iswctype.c index a4b99474..b01dbb45 100644 --- a/libc/wctype/iswctype.cpp +++ b/libc/wctype/iswctype.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 . - wctype/iswctype.cpp + wctype/iswctype.c Returns whether the wide character belongs to the character class. *******************************************************************************/ #include -extern "C" int iswctype(wint_t c, wctype_t wct) +int iswctype(wint_t c, wctype_t wct) { return wct(c); } diff --git a/libc/wctype/iswdigit.cpp b/libc/wctype/iswdigit.c similarity index 94% rename from libc/wctype/iswdigit.cpp rename to libc/wctype/iswdigit.c index 8f60e056..fe358eef 100644 --- a/libc/wctype/iswdigit.cpp +++ b/libc/wctype/iswdigit.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 . - wctype/iswdigit.cpp + wctype/iswdigit.c Returns whether the wide character is a digit. *******************************************************************************/ #include -extern "C" int iswdigit(wint_t c) +int iswdigit(wint_t c) { return L'0' <= c && c <= L'9'; } diff --git a/libc/wctype/iswgraph.cpp b/libc/wctype/iswgraph.c similarity index 94% rename from libc/wctype/iswgraph.cpp rename to libc/wctype/iswgraph.c index 9795f252..cc3431e0 100644 --- a/libc/wctype/iswgraph.cpp +++ b/libc/wctype/iswgraph.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 . - wctype/iswgraph.cpp + wctype/iswgraph.c Returns whether the wide character is graphical. *******************************************************************************/ #include -extern "C" int iswgraph(wint_t c) +int iswgraph(wint_t c) { return L'!' <= c && c != 127; } diff --git a/libc/wctype/iswlower.cpp b/libc/wctype/iswlower.c similarity index 94% rename from libc/wctype/iswlower.cpp rename to libc/wctype/iswlower.c index d744facd..a98346ac 100644 --- a/libc/wctype/iswlower.cpp +++ b/libc/wctype/iswlower.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 . - wctype/iswlower.cpp + wctype/iswlower.c Returns whether the wide character is lower-case. *******************************************************************************/ #include -extern "C" int iswlower(wint_t c) +int iswlower(wint_t c) { return L'a' <= c && c <= L'z'; } diff --git a/libc/wctype/iswprint.cpp b/libc/wctype/iswprint.c similarity index 94% rename from libc/wctype/iswprint.cpp rename to libc/wctype/iswprint.c index 009f6c0a..6da147e9 100644 --- a/libc/wctype/iswprint.cpp +++ b/libc/wctype/iswprint.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 . - wctype/iswprint.cpp + wctype/iswprint.c Returns whether the wide character is printable. *******************************************************************************/ #include -extern "C" int iswprint(wint_t c) +int iswprint(wint_t c) { return iswgraph(c) || c == L' '; } diff --git a/libc/wctype/iswpunct.cpp b/libc/wctype/iswpunct.c similarity index 94% rename from libc/wctype/iswpunct.cpp rename to libc/wctype/iswpunct.c index ca3dfaba..5a0caad2 100644 --- a/libc/wctype/iswpunct.cpp +++ b/libc/wctype/iswpunct.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 . - wctype/iswpunct.cpp + wctype/iswpunct.c Returns whether the wide character is punctuational. *******************************************************************************/ #include -extern "C" int iswpunct(wint_t c) +int iswpunct(wint_t c) { return iswprint(c) && c != L' ' && !iswalnum(c); } diff --git a/libc/wctype/iswspace.cpp b/libc/wctype/iswspace.c similarity index 95% rename from libc/wctype/iswspace.cpp rename to libc/wctype/iswspace.c index 69bc763c..39f9063a 100644 --- a/libc/wctype/iswspace.cpp +++ b/libc/wctype/iswspace.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 . - wctype/iswspace.cpp + wctype/iswspace.c Returns whether the wide character is white-space. *******************************************************************************/ #include -extern "C" int iswspace(wint_t c) +int iswspace(wint_t c) { return c == L'\t' || c == L'\n' || c == L'\v' || c == L'\f' || c == L'\r' || c == L' '; diff --git a/libc/wctype/iswupper.cpp b/libc/wctype/iswupper.c similarity index 94% rename from libc/wctype/iswupper.cpp rename to libc/wctype/iswupper.c index d46ff826..63b81275 100644 --- a/libc/wctype/iswupper.cpp +++ b/libc/wctype/iswupper.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 . - wctype/iswupper.cpp + wctype/iswupper.c Returns whether the wide character is upper-case. *******************************************************************************/ #include -extern "C" int iswupper(wint_t c) +int iswupper(wint_t c) { return L'A' <= c && c <= L'Z'; } diff --git a/libc/wctype/iswxdigit.cpp b/libc/wctype/iswxdigit.c similarity index 95% rename from libc/wctype/iswxdigit.cpp rename to libc/wctype/iswxdigit.c index 240a816f..f2619114 100644 --- a/libc/wctype/iswxdigit.cpp +++ b/libc/wctype/iswxdigit.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 . - wctype/iswxdigit.cpp + wctype/iswxdigit.c Returns whether the wide character is a hexadecimal digit. *******************************************************************************/ #include -extern "C" int iswxdigit(wint_t c) +int iswxdigit(wint_t c) { if ( iswdigit(c) ) return 1; diff --git a/libc/wctype/towlower.cpp b/libc/wctype/towlower.c similarity index 94% rename from libc/wctype/towlower.cpp rename to libc/wctype/towlower.c index b8aa889e..2f44cb17 100644 --- a/libc/wctype/towlower.cpp +++ b/libc/wctype/towlower.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 . - wctype/towlower.cpp + wctype/towlower.c Converts the wide character to lower-case if it is upper-case. *******************************************************************************/ #include -extern "C" wint_t towlower(wint_t c) +wint_t towlower(wint_t c) { if ( L'A' <= c && c <= L'Z' ) return L'a' + c - L'A'; diff --git a/libc/wctype/towupper.cpp b/libc/wctype/towupper.c similarity index 94% rename from libc/wctype/towupper.cpp rename to libc/wctype/towupper.c index e2308492..97fa03da 100644 --- a/libc/wctype/towupper.cpp +++ b/libc/wctype/towupper.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 . - wctype/towupper.cpp + wctype/towupper.c Converts the wide character to upper-case if it is lower-case. *******************************************************************************/ #include -extern "C" wint_t towupper(wint_t c) +wint_t towupper(wint_t c) { if ( L'a' <= c && c <= L'z' ) return L'A' + c - L'a'; diff --git a/libc/wctype/wctype.cpp b/libc/wctype/wctype.c similarity index 96% rename from libc/wctype/wctype.cpp rename to libc/wctype/wctype.c index 24a63205..90196124 100644 --- a/libc/wctype/wctype.cpp +++ b/libc/wctype/wctype.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 . - wctype/wctype.cpp + wctype/wctype.c Returns the character class description with the given name. *******************************************************************************/ @@ -25,7 +25,7 @@ #include #include -extern "C" wctype_t wctype(const char *name) +wctype_t wctype(const char *name) { if ( !strcmp(name, "alnum") ) return (wctype_t) iswalnum; if ( !strcmp(name, "alpha") ) return (wctype_t) iswalpha; diff --git a/utils/du.cpp b/utils/du.cpp index b5c65efe..d3b77806 100644 --- a/utils/du.cpp +++ b/utils/du.cpp @@ -36,15 +36,15 @@ #include #include -const int FLAG_ALL = 1 << 0; -const int FLAG_SUMMARIZE = 1 << 1; -const int FLAG_SAME_DEVICE = 1 << 2; -const int FLAG_APPARENT_SIZE = 1 << 3; -const int FLAG_TOTAL = 1 << 4; -const int FLAG_HUMAN_READABLE = 1 << 5; -const int FLAG_SI = 1 << 6; -const int FLAG_SEPARATE_DIRS = 1 << 7; -const int FLAG_IS_OPERAND = 1 << 8; +static const int FLAG_ALL = 1 << 0; +static const int FLAG_SUMMARIZE = 1 << 1; +static const int FLAG_SAME_DEVICE = 1 << 2; +static const int FLAG_APPARENT_SIZE = 1 << 3; +static const int FLAG_TOTAL = 1 << 4; +static const int FLAG_HUMAN_READABLE = 1 << 5; +static const int FLAG_SI = 1 << 6; +static const int FLAG_SEPARATE_DIRS = 1 << 7; +static const int FLAG_IS_OPERAND = 1 << 8; enum symbolic_dereference { diff --git a/utils/find.cpp b/utils/find.cpp index d4505650..0543066f 100644 --- a/utils/find.cpp +++ b/utils/find.cpp @@ -47,8 +47,8 @@ char* AddElemToPath(const char* path, const char* elem) return ret; } -const int TYPE_FILE = 1 << 0; -const int TYPE_DIR = 1 << 1; +static const int TYPE_FILE = 1 << 0; +static const int TYPE_DIR = 1 << 1; bool Find(int dirfd, const char* relpath, const char* path, int types) { diff --git a/utils/mv.cpp b/utils/mv.cpp index a0988c6f..4828a312 100644 --- a/utils/mv.cpp +++ b/utils/mv.cpp @@ -43,8 +43,8 @@ char* basename_dup(const char* path) return result; } -const int FLAG_VERBOSE = 1 << 0; -const int FLAG_ASK_OVERWRITE = 1 << 1; +static const int FLAG_VERBOSE = 1 << 0; +static const int FLAG_ASK_OVERWRITE = 1 << 1; bool mv(int src_dirfd, const char* src_rel, const char* src_path, int dst_dirfd, const char* dst_rel, const char* dst_path, diff --git a/utils/which.cpp b/utils/which.cpp index b24f9cd7..141bb8e9 100644 --- a/utils/which.cpp +++ b/utils/which.cpp @@ -35,7 +35,7 @@ // 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.