Compare commits
57 commits
8210ac97d3
...
cef7779f31
Author | SHA1 | Date | |
---|---|---|---|
|
cef7779f31 | ||
|
36a2d0ccc3 | ||
|
a180902247 | ||
|
5633699695 | ||
|
e3af5ae322 | ||
|
63a6509396 | ||
|
9d287d9433 | ||
|
7eb6a5f517 | ||
|
3cb2bf4590 | ||
|
e88c1ca56c | ||
|
035cd9b1a2 | ||
|
189e79d62d | ||
|
08a834d932 | ||
|
504415bc22 | ||
|
7de016539a | ||
|
bc2cf40dab | ||
|
e76b19fd2b | ||
|
5cec2e2f55 | ||
|
4ba880938e | ||
|
005eb40d27 | ||
|
adb08e530d | ||
|
544b52583e | ||
|
8f879f75a3 | ||
|
e5ae1e62e3 | ||
|
6b158f7795 | ||
|
e74efce270 | ||
|
372370f37d | ||
|
8826615b48 | ||
|
1e2a1f155a | ||
|
257b3abe40 | ||
|
4ea8396b5d | ||
|
0871fa71c3 | ||
|
f9a346a6dc | ||
|
ffafa81cd0 | ||
|
0ab8901f8b | ||
|
8f4c3371f5 | ||
|
e9bfbc8d03 | ||
|
456e2ac596 | ||
|
faff59cffc | ||
|
06fcbdb6ae | ||
|
3fe2a32914 | ||
|
a9b15bffe6 | ||
|
35e68109c9 | ||
|
5248220e40 | ||
|
35f4d2f000 | ||
|
9d317c462e | ||
|
250b95616b | ||
|
204576b7a8 | ||
|
8e3e058fd6 | ||
|
bf2d489da1 | ||
|
d3d339b616 | ||
|
83ac75a083 | ||
|
cc182e7912 | ||
|
d75c716891 | ||
|
704ddbe061 | ||
|
96d4615aee | ||
|
12a69346a0 |
47 changed files with 331 additions and 901 deletions
|
@ -6,7 +6,7 @@ if [ "$#" = 0 ]; then
|
||||||
set i686-sortix x86_64-sortix
|
set i686-sortix x86_64-sortix
|
||||||
fi
|
fi
|
||||||
for target; do
|
for target; do
|
||||||
for feature in "" "-D_POSIX_C_SOURCE=202405L" "-D_XOPEN_SOURCE=800" "-D_SORTIX_SOURCE"; do
|
for feature in "" "-D_POSIX_C_SOURCE=200809L" "-D_XOPEN_SOURCE=700" "-D_SORTIX_SOURCE"; do
|
||||||
for std in \
|
for std in \
|
||||||
"-ansi -pedantic-errors" \
|
"-ansi -pedantic-errors" \
|
||||||
"-std=c89 -pedantic-errors" \
|
"-std=c89 -pedantic-errors" \
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2016, 2017, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2014, 2016, 2017 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -28,8 +28,4 @@
|
||||||
#define IOV_MAX 1024
|
#define IOV_MAX 1024
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
#define GETENTROPY_MAX 256
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -679,7 +679,7 @@ Ref<Inode> Socket(int type, int protocol)
|
||||||
switch ( type )
|
switch ( type )
|
||||||
{
|
{
|
||||||
case SOCK_STREAM: return Ref<Inode>(new StreamSocket(0, 0, 0600, manager));
|
case SOCK_STREAM: return Ref<Inode>(new StreamSocket(0, 0, 0600, manager));
|
||||||
default: return errno = ESOCKTNOSUPPORT, Ref<Inode>(NULL);
|
default: return errno = EPROTOTYPE, Ref<Inode>(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -445,7 +445,7 @@ Ref<Inode> Socket(int type, int protocol)
|
||||||
if ( protocol == 0 || protocol == IPPROTO_TCP )
|
if ( protocol == 0 || protocol == IPPROTO_TCP )
|
||||||
return TCP::Socket(AF_INET);
|
return TCP::Socket(AF_INET);
|
||||||
return errno = EPROTONOSUPPORT, Ref<Inode>(NULL);
|
return errno = EPROTONOSUPPORT, Ref<Inode>(NULL);
|
||||||
default: return errno = ESOCKTNOSUPPORT, Ref<Inode>(NULL);
|
default: return errno = EPROTOTYPE, Ref<Inode>(NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2015, 2016, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2014, 2015, 2016 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -24,7 +24,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sortix/clock.h>
|
#include <sortix/clock.h>
|
||||||
#include <sortix/limits.h>
|
|
||||||
|
|
||||||
#include <sortix/kernel/addralloc.h>
|
#include <sortix/kernel/addralloc.h>
|
||||||
#include <sortix/kernel/copy.h>
|
#include <sortix/kernel/copy.h>
|
||||||
|
@ -163,7 +162,7 @@ namespace Sortix {
|
||||||
|
|
||||||
int sys_getentropy(void* user_buffer, size_t size)
|
int sys_getentropy(void* user_buffer, size_t size)
|
||||||
{
|
{
|
||||||
unsigned char buffer[GETENTROPY_MAX];
|
unsigned char buffer[256];
|
||||||
if ( sizeof(buffer) < size )
|
if ( sizeof(buffer) < size )
|
||||||
return errno = EIO, -1;
|
return errno = EIO, -1;
|
||||||
arc4random_buf(buffer, size);
|
arc4random_buf(buffer, size);
|
||||||
|
|
|
@ -60,7 +60,6 @@ malloc/__heap_verify.o \
|
||||||
netinet/if_ether/etheraddr_broadcast.o \
|
netinet/if_ether/etheraddr_broadcast.o \
|
||||||
netinet/in/in6addr_any.o \
|
netinet/in/in6addr_any.o \
|
||||||
netinet/in/in6addr_loopback.o \
|
netinet/in/in6addr_loopback.o \
|
||||||
signal/sig2str.o \
|
|
||||||
signal/sigaddset.o \
|
signal/sigaddset.o \
|
||||||
signal/sigandset.o \
|
signal/sigandset.o \
|
||||||
signal/sigdelset.o \
|
signal/sigdelset.o \
|
||||||
|
@ -70,7 +69,6 @@ signal/sigisemptyset.o \
|
||||||
signal/sigismember.o \
|
signal/sigismember.o \
|
||||||
signal/signotset.o \
|
signal/signotset.o \
|
||||||
signal/sigorset.o \
|
signal/sigorset.o \
|
||||||
signal/str2sig.o \
|
|
||||||
ssp/__stack_chk_fail.o \
|
ssp/__stack_chk_fail.o \
|
||||||
stdio/asprintf.o \
|
stdio/asprintf.o \
|
||||||
stdio/cbprintf.o \
|
stdio/cbprintf.o \
|
||||||
|
@ -181,7 +179,6 @@ string/memccpy.o \
|
||||||
string/memchr.o \
|
string/memchr.o \
|
||||||
string/memcmp.o \
|
string/memcmp.o \
|
||||||
string/memcpy.o \
|
string/memcpy.o \
|
||||||
string/memmem.o \
|
|
||||||
string/memmove.o \
|
string/memmove.o \
|
||||||
string/memrchr.o \
|
string/memrchr.o \
|
||||||
string/memset.o \
|
string/memset.o \
|
||||||
|
@ -397,7 +394,6 @@ ioleast/writeall.o \
|
||||||
ioleast/writeleast.o \
|
ioleast/writeleast.o \
|
||||||
langinfo/nl_langinfo_l.o \
|
langinfo/nl_langinfo_l.o \
|
||||||
langinfo/nl_langinfo.o \
|
langinfo/nl_langinfo.o \
|
||||||
locale/getlocalename_l.o \
|
|
||||||
locale/localeconv.o \
|
locale/localeconv.o \
|
||||||
locale/setlocale.o \
|
locale/setlocale.o \
|
||||||
memusage/memusage.o \
|
memusage/memusage.o \
|
||||||
|
@ -440,7 +436,6 @@ pthread/pthread_condattr_getclock.o \
|
||||||
pthread/pthread_condattr_init.o \
|
pthread/pthread_condattr_init.o \
|
||||||
pthread/pthread_condattr_setclock.o \
|
pthread/pthread_condattr_setclock.o \
|
||||||
pthread/pthread_cond_broadcast.o \
|
pthread/pthread_cond_broadcast.o \
|
||||||
pthread/pthread_cond_clockwait.o \
|
|
||||||
pthread/pthread_cond_destroy.o \
|
pthread/pthread_cond_destroy.o \
|
||||||
pthread/pthread_cond_init.o \
|
pthread/pthread_cond_init.o \
|
||||||
pthread/pthread_cond_signal.o \
|
pthread/pthread_cond_signal.o \
|
||||||
|
@ -459,21 +454,15 @@ pthread/pthread_mutexattr_destroy.o \
|
||||||
pthread/pthread_mutexattr_gettype.o \
|
pthread/pthread_mutexattr_gettype.o \
|
||||||
pthread/pthread_mutexattr_init.o \
|
pthread/pthread_mutexattr_init.o \
|
||||||
pthread/pthread_mutexattr_settype.o \
|
pthread/pthread_mutexattr_settype.o \
|
||||||
pthread/pthread_mutex_clocklock.o \
|
|
||||||
pthread/pthread_mutex_destroy.o \
|
pthread/pthread_mutex_destroy.o \
|
||||||
pthread/pthread_mutex_init.o \
|
pthread/pthread_mutex_init.o \
|
||||||
pthread/pthread_mutex_lock.o \
|
pthread/pthread_mutex_lock.o \
|
||||||
pthread/pthread_mutex_timedlock.o \
|
|
||||||
pthread/pthread_mutex_trylock.o \
|
pthread/pthread_mutex_trylock.o \
|
||||||
pthread/pthread_mutex_unlock.o \
|
pthread/pthread_mutex_unlock.o \
|
||||||
pthread/pthread_once.o \
|
pthread/pthread_once.o \
|
||||||
pthread/pthread_rwlock_clockrdlock.o \
|
|
||||||
pthread/pthread_rwlock_clockwrlock.o \
|
|
||||||
pthread/pthread_rwlock_destroy.o \
|
pthread/pthread_rwlock_destroy.o \
|
||||||
pthread/pthread_rwlock_init.o \
|
pthread/pthread_rwlock_init.o \
|
||||||
pthread/pthread_rwlock_rdlock.o \
|
pthread/pthread_rwlock_rdlock.o \
|
||||||
pthread/pthread_rwlock_timedrdlock.o \
|
|
||||||
pthread/pthread_rwlock_timedwrlock.o \
|
|
||||||
pthread/pthread_rwlock_tryrdlock.o \
|
pthread/pthread_rwlock_tryrdlock.o \
|
||||||
pthread/pthread_rwlock_trywrlock.o \
|
pthread/pthread_rwlock_trywrlock.o \
|
||||||
pthread/pthread_rwlock_unlock.o \
|
pthread/pthread_rwlock_unlock.o \
|
||||||
|
@ -497,7 +486,6 @@ pwd/setpwent.o \
|
||||||
sched/sched_yield.o \
|
sched/sched_yield.o \
|
||||||
pty/openpty.o \
|
pty/openpty.o \
|
||||||
scram/scram.o \
|
scram/scram.o \
|
||||||
semaphore/sem_clockwait.o \
|
|
||||||
semaphore/sem_destroy.o \
|
semaphore/sem_destroy.o \
|
||||||
semaphore/sem_getvalue.o \
|
semaphore/sem_getvalue.o \
|
||||||
semaphore/sem_init.o \
|
semaphore/sem_init.o \
|
||||||
|
@ -714,7 +702,6 @@ unistd/fchownat.o \
|
||||||
unistd/fchown.o \
|
unistd/fchown.o \
|
||||||
unistd/fchrootat.o \
|
unistd/fchrootat.o \
|
||||||
unistd/fchroot.o \
|
unistd/fchroot.o \
|
||||||
unistd/_Fork.o \
|
|
||||||
unistd/fork.o \
|
unistd/fork.o \
|
||||||
unistd/fpathconf.o \
|
unistd/fpathconf.o \
|
||||||
unistd/fsync.o \
|
unistd/fsync.o \
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2013, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012, 2013 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,13 +22,6 @@
|
||||||
|
|
||||||
static const char* dlerrormsg = NULL;
|
static const char* dlerrormsg = NULL;
|
||||||
|
|
||||||
int dladdr(const void* restrict addr, Dl_info_t* restrict dlip)
|
|
||||||
{
|
|
||||||
(void) addr;
|
|
||||||
(void) dlip;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void* dlopen(const char* filename, int mode)
|
void* dlopen(const char* filename, int mode)
|
||||||
{
|
{
|
||||||
(void) filename;
|
(void) filename;
|
||||||
|
|
|
@ -34,6 +34,12 @@ const char* inet_ntop(int, const void* __restrict, char* __restrict, socklen_t);
|
||||||
int inet_pton(int, const char* __restrict, void* __restrict);
|
int inet_pton(int, const char* __restrict, void* __restrict);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Functions copied from elsewhere. */
|
||||||
|
#if __USE_SORTIX
|
||||||
|
/* TODO: int inet_aton(const char*, struct in_addr*); */
|
||||||
|
/* TODO: char* inet_neta(in_addr_t, char*, size_t); */
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,32 +22,19 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
#define RTLD_LAZY (1<<0)
|
#define RTLD_LAZY (1<<0)
|
||||||
#define RTLD_NOW (1<<1)
|
#define RTLD_NOW (1<<1)
|
||||||
#define RTLD_GLOBAL (1<<8)
|
#define RTLD_GLOBAL (1<<8)
|
||||||
#define RTLD_LOCAL 0 /* Bit 8 is not set. */
|
#define RTLD_LOCAL 0 /* Bit 8 is not set. */
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
int dlclose(void* handle);
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
const char* dli_fname;
|
|
||||||
void* dli_fbase;
|
|
||||||
const char* dli_sname;
|
|
||||||
void* dli_saddr;
|
|
||||||
} Dl_info_t;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
int dladdr(const void* restrict, Dl_info_t* __restrict);
|
|
||||||
#endif
|
|
||||||
int dlclose(void*);
|
|
||||||
char* dlerror(void);
|
char* dlerror(void);
|
||||||
void* dlopen(const char*, int);
|
void* dlopen(const char* filename, int mode);
|
||||||
void* dlsym(void*, const char*);
|
void* dlsym(void* handle, const char* name);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -109,7 +109,6 @@
|
||||||
#define ENOMOUNT 99
|
#define ENOMOUNT 99
|
||||||
#define ENOMEDIUM 100
|
#define ENOMEDIUM 100
|
||||||
#define EHOSTDOWN 101
|
#define EHOSTDOWN 101
|
||||||
#define ESOCKTNOSUPPORT 102
|
|
||||||
|
|
||||||
#define EOPNOTSUPP ENOTSUP
|
#define EOPNOTSUPP ENOTSUP
|
||||||
#define EWOULDBLOCK EAGAIN
|
#define EWOULDBLOCK EAGAIN
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -62,13 +62,14 @@
|
||||||
#define _C11_SOURCE
|
#define _C11_SOURCE
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_POSIX_C_SOURCE)
|
#if !defined(_POSIX_C_SOURCE)
|
||||||
#define _POSIX_C_SOURCE 202405L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_XOPEN_SOURCE)
|
#if !defined(_XOPEN_SOURCE)
|
||||||
#define _XOPEN_SOURCE 700
|
#define _XOPEN_SOURCE 700
|
||||||
#endif
|
#endif
|
||||||
#if !defined(_SORTIX_SOURCE)
|
#if !defined(_SORTIX_SOURCE)
|
||||||
#define _SORTIX_SOURCE 1
|
#define _SORTIX_SOURCE 1
|
||||||
|
#define __IMPLICIT_SORTIX_SOURCE
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -89,14 +90,12 @@
|
||||||
/* Use the Sortix API if the default API was requested. */
|
/* Use the Sortix API if the default API was requested. */
|
||||||
#if defined(_DEFAULT_SOURCE) && !defined(_SORTIX_SOURCE)
|
#if defined(_DEFAULT_SOURCE) && !defined(_SORTIX_SOURCE)
|
||||||
#define _SORTIX_SOURCE 1
|
#define _SORTIX_SOURCE 1
|
||||||
|
#define __IMPLICIT_SORTIX_SOURCE
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Particular XSI revisions imply certain POSIX revisions. */
|
/* Particular XSI revisions imply certain POSIX revisions. */
|
||||||
#if defined(_XOPEN_SOURCE)
|
#if defined(_XOPEN_SOURCE)
|
||||||
#if 800 <= _XOPEN_SOURCE - 0
|
#if 700 <= _XOPEN_SOURCE - 0
|
||||||
#undef _POSIX_C_SOURCE
|
|
||||||
#define _POSIX_C_SOURCE 202405L
|
|
||||||
#elif 700 <= _XOPEN_SOURCE - 0
|
|
||||||
#undef _POSIX_C_SOURCE
|
#undef _POSIX_C_SOURCE
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
#elif 600 <= _XOPEN_SOURCE - 0
|
#elif 600 <= _XOPEN_SOURCE - 0
|
||||||
|
@ -158,9 +157,7 @@
|
||||||
|
|
||||||
/* Determine which revision of POSIX is used. */
|
/* Determine which revision of POSIX is used. */
|
||||||
#ifdef _POSIX_C_SOURCE
|
#ifdef _POSIX_C_SOURCE
|
||||||
#if 202405L <= _POSIX_C_SOURCE - 0
|
#if 200809L <= _POSIX_C_SOURCE - 0
|
||||||
#define __USE_POSIX 202405L
|
|
||||||
#elif 200809L <= _POSIX_C_SOURCE - 0
|
|
||||||
#define __USE_POSIX 200809L
|
#define __USE_POSIX 200809L
|
||||||
#elif 200112L <= _POSIX_C_SOURCE - 0
|
#elif 200112L <= _POSIX_C_SOURCE - 0
|
||||||
#define __USE_POSIX 200112L
|
#define __USE_POSIX 200112L
|
||||||
|
@ -195,6 +192,15 @@
|
||||||
#define __USE_SORTIX 0
|
#define __USE_SORTIX 0
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Whether to override some "standard" functions with Sortix alternatives. */
|
||||||
|
#if !defined(__SORTIX_STDLIB_REDIRECTS)
|
||||||
|
#if __USE_SORTIX && !defined(__IMPLICIT_SORTIX_SOURCE)
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 1
|
||||||
|
#else
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Provide the restrict keyword when building system components. */
|
/* Provide the restrict keyword when building system components. */
|
||||||
#if defined(__is_sortix_system_component) && !defined(__want_restrict)
|
#if defined(__is_sortix_system_component) && !defined(__want_restrict)
|
||||||
#define __want_restrict 1
|
#define __want_restrict 1
|
||||||
|
|
|
@ -64,29 +64,12 @@ struct lconv
|
||||||
#define LC_ALL 6
|
#define LC_ALL 6
|
||||||
#define LC_NUM_CATEGORIES LC_ALL
|
#define LC_NUM_CATEGORIES LC_ALL
|
||||||
|
|
||||||
#if __USE_SORTIX || __USE_POSIX
|
|
||||||
#define LC_GLOBAL_LOCALE ((locale_t) -1)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __USE_SORTIX || __USE_POSIX
|
|
||||||
#ifndef __locale_t_defined
|
|
||||||
#define __locale_t_defined
|
|
||||||
/* TODO: figure out what this does and typedef it properly. This is just a
|
|
||||||
temporary assignment. */
|
|
||||||
typedef int __locale_t;
|
|
||||||
typedef __locale_t locale_t;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
char* setlocale(int category, const char* locale);
|
char* setlocale(int category, const char* locale);
|
||||||
struct lconv* localeconv(void);
|
struct lconv* localeconv(void);
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
const char* getlocalename_l(int, locale_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -24,23 +24,28 @@
|
||||||
|
|
||||||
#include <sys/__/types.h>
|
#include <sys/__/types.h>
|
||||||
|
|
||||||
#include <sortix/poll.h>
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
#include <sortix/sigset.h>
|
|
||||||
#include <sortix/timespec.h>
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef __time_t_defined
|
||||||
|
#define __time_t_defined
|
||||||
|
typedef __time_t time_t;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
} /* extern "C" */
|
||||||
|
#endif
|
||||||
|
#include <sortix/poll.h>
|
||||||
|
#include <sortix/sigset.h>
|
||||||
|
#include <sortix/timespec.h>
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
int poll(struct pollfd* fds, nfds_t nfds, int timeout);
|
int poll(struct pollfd* fds, nfds_t nfds, int timeout);
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* timeout,
|
int ppoll(struct pollfd* fds, nfds_t nfds, const struct timespec* timeout,
|
||||||
const sigset_t* sigmask);
|
const sigset_t* sigmask);
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
|
|
|
@ -252,8 +252,7 @@ int pthread_mutex_init(pthread_mutex_t* __restrict,
|
||||||
const pthread_mutexattr_t* __restrict);
|
const pthread_mutexattr_t* __restrict);
|
||||||
int pthread_mutex_lock(pthread_mutex_t*);
|
int pthread_mutex_lock(pthread_mutex_t*);
|
||||||
/* TODO: pthread_mutex_setprioceiling */
|
/* TODO: pthread_mutex_setprioceiling */
|
||||||
int pthread_mutex_timedlock(pthread_mutex_t* __restrict,
|
/* TODO: pthread_mutex_timedlock */
|
||||||
const struct timespec* __restrict);
|
|
||||||
int pthread_mutex_trylock(pthread_mutex_t*);
|
int pthread_mutex_trylock(pthread_mutex_t*);
|
||||||
int pthread_mutex_unlock(pthread_mutex_t*);
|
int pthread_mutex_unlock(pthread_mutex_t*);
|
||||||
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
|
int pthread_mutexattr_destroy(pthread_mutexattr_t*);
|
||||||
|
@ -273,10 +272,8 @@ int pthread_rwlock_destroy(pthread_rwlock_t*);
|
||||||
int pthread_rwlock_init(pthread_rwlock_t* __restrict,
|
int pthread_rwlock_init(pthread_rwlock_t* __restrict,
|
||||||
const pthread_rwlockattr_t* __restrict);
|
const pthread_rwlockattr_t* __restrict);
|
||||||
int pthread_rwlock_rdlock(pthread_rwlock_t*);
|
int pthread_rwlock_rdlock(pthread_rwlock_t*);
|
||||||
int pthread_rwlock_timedrdlock(pthread_rwlock_t* __restrict,
|
/* TODO: pthread_rwlock_timedrdlock */
|
||||||
const struct timespec* __restrict);
|
/* TODO: pthread_rwlock_timedwrlock */
|
||||||
int pthread_rwlock_timedwrlock(pthread_rwlock_t* __restrict,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
|
int pthread_rwlock_tryrdlock(pthread_rwlock_t*);
|
||||||
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
|
int pthread_rwlock_trywrlock(pthread_rwlock_t*);
|
||||||
int pthread_rwlock_unlock(pthread_rwlock_t*);
|
int pthread_rwlock_unlock(pthread_rwlock_t*);
|
||||||
|
@ -299,18 +296,6 @@ int pthread_setspecific(pthread_key_t, const void*);
|
||||||
/* TODO: pthread_spin_unlock */
|
/* TODO: pthread_spin_unlock */
|
||||||
/* TODO: pthread_testcancel */
|
/* TODO: pthread_testcancel */
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
int pthread_cond_clockwait(pthread_cond_t* __restrict,
|
|
||||||
pthread_mutex_t* __restrict, clockid_t,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
int pthread_mutex_clocklock(pthread_mutex_t* __restrict, clockid_t,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
int pthread_rwlock_clockrdlock(pthread_rwlock_t* __restrict, clockid_t,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
int pthread_rwlock_clockwrlock(pthread_rwlock_t* __restrict, clockid_t,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
#include <time.h>
|
#include <sortix/timespec.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
|
@ -52,11 +52,6 @@ int sem_trywait(sem_t*);
|
||||||
/*int sem_unlink(const char*);*/
|
/*int sem_unlink(const char*);*/
|
||||||
int sem_wait(sem_t*);
|
int sem_wait(sem_t*);
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
int sem_clockwait(sem_t* __restrict, clockid_t clock,
|
|
||||||
const struct timespec* __restrict);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -87,10 +87,6 @@ typedef int sig_atomic_t;
|
||||||
#define MINSIGSTKSZ 2048
|
#define MINSIGSTKSZ 2048
|
||||||
#define SIGSTKSZ 8192
|
#define SIGSTKSZ 8192
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
#define SIG2STR_MAX 16
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
@ -126,11 +122,6 @@ int sigsuspend(const sigset_t*);
|
||||||
/* TODO: int sigwaitinfo(const sigset_t* __restrict, siginfo_t* __restrict); */
|
/* TODO: int sigwaitinfo(const sigset_t* __restrict, siginfo_t* __restrict); */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
int sig2str(int, char*);
|
|
||||||
int str2sig(const char* __restrict, int* __restrict);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} /* extern "C" */
|
} /* extern "C" */
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2017, 2022, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011-2017, 2022 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -121,6 +121,7 @@ int mkstemp(char*);
|
||||||
int mkstemps(char*, int);
|
int mkstemps(char*, int);
|
||||||
int on_exit(void (*function)(int, void*), void* arg);
|
int on_exit(void (*function)(int, void*), void* arg);
|
||||||
void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
|
void qsort(void*, size_t, size_t, int (*)(const void*, const void*));
|
||||||
|
void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*);
|
||||||
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
#if !defined(__is_sortix_libc) /* not a warning inside libc */
|
||||||
__attribute__((__warning__("rand() isn't random, use arc4random()")))
|
__attribute__((__warning__("rand() isn't random, use arc4random()")))
|
||||||
#endif
|
#endif
|
||||||
|
@ -155,17 +156,6 @@ unsigned long long strtoull(const char* __restrict, char** __restrict, int);
|
||||||
long long strtoll(const char* __restrict, char** __restrict, int);
|
long long strtoll(const char* __restrict, char** __restrict, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions from POSIX 2024. */
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
void qsort_r(void*, size_t, size_t, int (*)(const void*, const void*, void*), void*);
|
|
||||||
#ifdef __TRACE_ALLOCATION_SITES
|
|
||||||
void* reallocarray_trace(struct __allocation_site*, void*, size_t, size_t);
|
|
||||||
#define reallocarray(a, b, c) reallocarray_trace(ALLOCATION_SITE, (a), (b), (c))
|
|
||||||
#else
|
|
||||||
void* reallocarray(void*, size_t, size_t);
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(__is_sortix_libc)
|
#if defined(__is_sortix_libc)
|
||||||
struct exit_handler
|
struct exit_handler
|
||||||
{
|
{
|
||||||
|
@ -214,6 +204,12 @@ int posix_openpt(int);
|
||||||
uint32_t arc4random(void);
|
uint32_t arc4random(void);
|
||||||
void arc4random_buf(void*, size_t);
|
void arc4random_buf(void*, size_t);
|
||||||
uint32_t arc4random_uniform(uint32_t);
|
uint32_t arc4random_uniform(uint32_t);
|
||||||
|
#ifdef __TRACE_ALLOCATION_SITES
|
||||||
|
void* reallocarray_trace(struct __allocation_site*, void*, size_t, size_t);
|
||||||
|
#define reallocarray(a, b, c) reallocarray_trace(ALLOCATION_SITE, (a), (b), (c))
|
||||||
|
#else
|
||||||
|
void* reallocarray(void*, size_t, size_t);
|
||||||
|
#endif
|
||||||
int ptsname_r(int, char*, size_t);
|
int ptsname_r(int, char*, size_t);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2014, 2017, 2022, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2017, 2022 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -62,7 +62,11 @@ int strcmp(const char*, const char*);
|
||||||
int strcoll(const char*, const char*);
|
int strcoll(const char*, const char*);
|
||||||
char* strcpy(char* __restrict, const char* __restrict);
|
char* strcpy(char* __restrict, const char* __restrict);
|
||||||
size_t strcspn(const char*, const char*);
|
size_t strcspn(const char*, const char*);
|
||||||
|
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
|
||||||
|
const char* strerror(int errnum) __asm__ ("sortix_strerror");
|
||||||
|
#else
|
||||||
char* strerror(int errnum);
|
char* strerror(int errnum);
|
||||||
|
#endif
|
||||||
size_t strlen(const char*);
|
size_t strlen(const char*);
|
||||||
char* strncat(char* __restrict, const char* __restrict, size_t);
|
char* strncat(char* __restrict, const char* __restrict, size_t);
|
||||||
int strncmp(const char*, const char*, size_t);
|
int strncmp(const char*, const char*, size_t);
|
||||||
|
@ -98,7 +102,11 @@ char* strdup(const char*);
|
||||||
/* Functions from POSIX 2001. */
|
/* Functions from POSIX 2001. */
|
||||||
#if __USE_SORTIX || 200112L <= __USE_POSIX
|
#if __USE_SORTIX || 200112L <= __USE_POSIX
|
||||||
int ffs(int);
|
int ffs(int);
|
||||||
|
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
|
||||||
|
const char* strerror_l(int, locale_t) __asm__ ("sortix_strerror_l");
|
||||||
|
#else
|
||||||
char* strerror_l(int, locale_t);
|
char* strerror_l(int, locale_t);
|
||||||
|
#endif
|
||||||
int strerror_r(int, char*, size_t);
|
int strerror_r(int, char*, size_t);
|
||||||
char* strtok_r(char* __restrict, const char* __restrict, char** __restrict);
|
char* strtok_r(char* __restrict, const char* __restrict, char** __restrict);
|
||||||
#endif
|
#endif
|
||||||
|
@ -115,15 +123,12 @@ char* strndup_trace(struct __allocation_site*, const char*, size_t);
|
||||||
char* strndup(const char*, size_t);
|
char* strndup(const char*, size_t);
|
||||||
#endif
|
#endif
|
||||||
size_t strnlen(const char*, size_t);
|
size_t strnlen(const char*, size_t);
|
||||||
|
#if __USE_SORTIX && __SORTIX_STDLIB_REDIRECTS
|
||||||
|
const char* strsignal(int signum) __asm__ ("sortix_strsignal");
|
||||||
|
#else
|
||||||
char* strsignal(int signum);
|
char* strsignal(int signum);
|
||||||
size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
|
|
||||||
#endif
|
#endif
|
||||||
|
size_t strxfrm_l(char* __restrict, const char* __restrict, size_t, locale_t);
|
||||||
/* Functions from POSIX 2024. */
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
void* memmem(const void*, size_t, const void*, size_t);
|
|
||||||
size_t strlcat(char* __restrict, const char* __restrict, size_t);
|
|
||||||
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions copied from elsewhere. */
|
/* Functions copied from elsewhere. */
|
||||||
|
@ -134,6 +139,8 @@ void* memrchr(const void*, int, size_t);
|
||||||
/* TODO: strcasecmp_l */
|
/* TODO: strcasecmp_l */
|
||||||
char* strchrnul(const char* str, int c);
|
char* strchrnul(const char* str, int c);
|
||||||
char* stresep(char**, const char*, int);
|
char* stresep(char**, const char*, int);
|
||||||
|
size_t strlcat(char* __restrict, const char* __restrict, size_t);
|
||||||
|
size_t strlcpy(char* __restrict, const char* __restrict, size_t);
|
||||||
/* TODO: strncasecmp_l */
|
/* TODO: strncasecmp_l */
|
||||||
char* strsep(char**, const char*);
|
char* strsep(char**, const char*);
|
||||||
int strverscmp(const char*, const char*);
|
int strverscmp(const char*, const char*);
|
||||||
|
@ -143,6 +150,9 @@ int timingsafe_memcmp(const void*, const void*, size_t);
|
||||||
/* Functions that are Sortix extensions. */
|
/* Functions that are Sortix extensions. */
|
||||||
#if __USE_SORTIX
|
#if __USE_SORTIX
|
||||||
int ffsll(long long int);
|
int ffsll(long long int);
|
||||||
|
const char* sortix_strerror(int errnum);
|
||||||
|
const char* sortix_strerror_l(int, locale_t);
|
||||||
|
const char* sortix_strsignal(int signum);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if __USE_SORTIX
|
#if __USE_SORTIX
|
||||||
|
|
|
@ -43,10 +43,10 @@ extern "C" {
|
||||||
#define _POSIX_VERSION __USE_POSIX /* C bindings */
|
#define _POSIX_VERSION __USE_POSIX /* C bindings */
|
||||||
#define _POSIX2_VERSION __USE_POSIX /* Shell utilities. */
|
#define _POSIX2_VERSION __USE_POSIX /* Shell utilities. */
|
||||||
|
|
||||||
/* The native API is based on POSIX 2024. */
|
/* The native API is based on POSIX 2008. */
|
||||||
#elif __USE_SORTIX
|
#elif __USE_SORTIX
|
||||||
#define _POSIX_VERSION 202405L /* C bindings */
|
#define _POSIX_VERSION 200809L /* C bindings */
|
||||||
#define _POSIX2_VERSION 202405L /* Shell utilities. */
|
#define _POSIX2_VERSION 200809L /* Shell utilities. */
|
||||||
|
|
||||||
/* That's odd. This is a POSIX header, but the POSIX API is not visible. The
|
/* That's odd. This is a POSIX header, but the POSIX API is not visible. The
|
||||||
best option is probably to just say we are the 1990 POSIX standard, since it
|
best option is probably to just say we are the 1990 POSIX standard, since it
|
||||||
|
@ -67,86 +67,95 @@ extern "C" {
|
||||||
#define _XOPEN_VERSION 4
|
#define _XOPEN_VERSION 4
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* #define _POSIX_ADVISORY_INFO 202405L
|
/* #define _POSIX_ADVISORY_INFO 200809L
|
||||||
TODO: Uncomment when posix_fadvise(), posix_fallocate(), posix_madvise(),
|
TODO: Uncomment when posix_fadvise(), posix_fallocate(), posix_madvise(),
|
||||||
posix_memalign() has been added. */
|
posix_memalign() has been added. */
|
||||||
#define _POSIX_ASYNCHRONOUS_IO 202405L
|
#define _POSIX_ASYNCHRONOUS_IO 200809L
|
||||||
#define _POSIX_BARRIERS 202405L
|
#define _POSIX_BARRIERS 200809L
|
||||||
/* TODO: _POSIX_CHOWN_RESTRICTED - Decide when security policies are implemented. */
|
/* TODO: _POSIX_CHOWN_RESTRICTED - Decide when security policies are implemented. */
|
||||||
#define _POSIX_CLOCK_SELECTION 202405L
|
#define _POSIX_CLOCK_SELECTION 200809L
|
||||||
#define _POSIX_CPUTIME 202405L
|
#define _POSIX_CPUTIME 200809L
|
||||||
/* #undef _POSIX_DEVICE_CONTROL - posix_devctl won't be implemented */
|
#define _POSIX_FSYNC 200809L
|
||||||
#define _POSIX_FSYNC 202405L
|
#define _POSIX_IPV6 200809L
|
||||||
#define _POSIX_IPV6 202405L
|
#define _POSIX_JOB_CONTROL
|
||||||
#define _POSIX_JOB_CONTROL 1
|
|
||||||
/*TODO: _POSIX_MAPPED_FILES - Needs to be implemented */
|
|
||||||
/*TODO: _POSIX_MEMLOCK - Research what this is. */
|
/*TODO: _POSIX_MEMLOCK - Research what this is. */
|
||||||
/*TODO: _POSIX_MEMLOCK_RANGE - Research what this is. */
|
/*TODO: _POSIX_MEMLOCK_RANGE - Research what this is. */
|
||||||
#define _POSIX_MEMORY_PROTECTION 202405L
|
#define _POSIX_MEMORY_PROTECTION 200809L
|
||||||
/*TODO: _POSIX_MESSAGE_PASSING - Research what this is. */
|
/*TODO: _POSIX_MESSAGE_PASSING - Research what this is. */
|
||||||
#define _POSIX_MONOTONIC_CLOCK 202405L
|
#define _POSIX_MONOTONIC_CLOCK 200809L
|
||||||
#define _POSIX_NO_TRUNC 1
|
#define _POSIX_NO_TRUNC 1
|
||||||
/*TODO: _POSIX_PRIORITIZED_IO - Research what this is. */
|
/*TODO: _POSIX_PRIORITIZED_IO - Research what this is. */
|
||||||
/*TODO: _POSIX_PRIORITY_SCHEDULING - Research what this is. */
|
/*TODO: _POSIX_PRIORITY_SCHEDULING - Research what this is. */
|
||||||
/*TODO: _POSIX_RAW_SOCKETS - Research what this is. */
|
/*TODO: _POSIX_RAW_SOCKETS - Research what this is. */
|
||||||
#define _POSIX_READER_WRITER_LOCKS 202405L
|
#define _POSIX_READER_WRITER_LOCKS 200809L
|
||||||
#define _POSIX_REALTIME_SIGNALS 202405L
|
#define _POSIX_REALTIME_SIGNALS 200809L
|
||||||
#define _POSIX_REGEXP 1
|
/* #define _POSIX_REGEXP 1
|
||||||
|
TODO: Uncomment when regular expressions are implemented. */
|
||||||
/* #define _POSIX_SAVED_IDS 1
|
/* #define _POSIX_SAVED_IDS 1
|
||||||
TODO: Uncomment when saved ids are implemented. I forgot if they already are. */
|
TODO: Uncomment when saved ids are implemented. I forgot if they already are. */
|
||||||
#define _POSIX_SEMAPHORES 202405L
|
#define _POSIX_SEMAPHORES 200809L
|
||||||
/*TODO: _POSIX_SHARED_MEMORY_OBJECTS - Research what this is. */
|
/*TODO: _POSIX_SHARED_MEMORY_OBJECTS - Research what this is. */
|
||||||
#define _POSIX_SHELL 1
|
#define _POSIX_SHELL 1
|
||||||
/*TODO: _POSIX_SPAWN - Research what this is. */
|
/*TODO: _POSIX_SPAWN - Research what this is. */
|
||||||
#define _POSIX_SPIN_LOCKS 202405L
|
#define _POSIX_SPIN_LOCKS 200809L
|
||||||
/*TODO: _POSIX_SPORADIC_SERVER - Research what this is. */
|
/*TODO: _POSIX_SPORADIC_SERVER - Research what this is. */
|
||||||
/*TODO: _POSIX_SYNCHRONIZED_IO - Research what this is. */
|
/*TODO: _POSIX_SYNCHRONIZED_IO - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_ATTR_STACKADDR - Research what this is. */
|
/*TODO: _POSIX_THREAD_ATTR_STACKADDR - Research what this is. */
|
||||||
#define _POSIX_THREAD_ATTR_STACKSIZE 202405L
|
/*TODO: _POSIX_THREAD_ATTR_STACKSIZE - Research what this is. */
|
||||||
#define _POSIX_THREAD_CPUTIME 202405L
|
#define _POSIX_THREAD_CPUTIME 200809L
|
||||||
/*TODO: _POSIX_THREAD_PRIO_INHERIT - Research what this is. */
|
/*TODO: _POSIX_THREAD_PRIO_INHERIT - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_PRIO_PROTECT - Research what this is. */
|
/*TODO: _POSIX_THREAD_PRIO_PROTECT - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_PRIORITY_SCHEDULING - Research what this is. */
|
/*TODO: _POSIX_THREAD_PRIORITY_SCHEDULING - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_PROCESS_SHARED - Research what this is. */
|
/*TODO: _POSIX_THREAD_PROCESS_SHARED - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_ROBUST_PRIO_INHERIT - Research what this is. */
|
/*TODO: _POSIX_THREAD_ROBUST_PRIO_INHERIT - Research what this is. */
|
||||||
/*TODO: _POSIX_THREAD_ROBUST_PRIO_PROTECT - Research what this is. */
|
/*TODO: _POSIX_THREAD_ROBUST_PRIO_PROTECT - Research what this is. */
|
||||||
#define _POSIX_THREAD_SAFE_FUNCTIONS 202405L
|
#define _POSIX_THREAD_SAFE_FUNCTIONS 200809L
|
||||||
/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is. */
|
/*TODO: _POSIX_THREAD_SPORADIC_SERVER - Research what this is. */
|
||||||
#define _POSIX_THREADS 202405L
|
#define _POSIX_THREADS 200809L
|
||||||
#define _POSIX_TIMEOUTS 202405L
|
#define _POSIX_TIMEOUTS 200809L
|
||||||
#define _POSIX_TIMERS 202405L
|
#define _POSIX_TIMERS 200809L
|
||||||
/* TODO: _POSIX_TYPED_MEMORY_OBJECTS - Research what this is. */
|
/* TODO: _POSIX_TRACE (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V7_ILP32_OFF32 (Obsolescent) - Research what this is. */
|
/* TODO: _POSIX_TRACE_EVENT_FILTER (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V7_ILP32_OFFBIG (Obsolescent) - Research what this is. */
|
/* TODO: _POSIX_TRACE_INHERIT (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V7_LP64_OFF64 (Obsolescent) - Research what this is. */
|
/* TODO: _POSIX_TRACE_LOG (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V7_LPBIG_OFFBIG (Obsolescent) - Research what this is. */
|
/* TODO: TYPED_MEMORY_OBJECTS - Research what this is. */
|
||||||
/* TODO: _POSIX_V8_ILP32_OFF32 - Research what this is. */
|
/* TODO: _POSIX_V6_ILP32_OFF32 (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V8_ILP32_OFFBIG - Research what this is. */
|
/* TODO: _POSIX_V6_ILP32_OFFBIG (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V8_LP64_OFF64 - Research what this is. */
|
/* TODO: _POSIX_V6_LP64_OFF64 (Obsolescent) - Research what this is. */
|
||||||
/* TODO: _POSIX_V8_LPBIG_OFFBIG - Research what this is. */
|
/* TODO: _POSIX_V6_LPBIG_OFFBIG (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX_V7_ILP32_OFF32 - Research what this is. */
|
||||||
|
/* TODO: _POSIX_V7_ILP32_OFFBIG - Research what this is. */
|
||||||
|
/* TODO: _POSIX_V7_LP64_OFF64 - Research what this is. */
|
||||||
|
/* TODO: _POSIX_V7_LPBIG_OFFBIG - Research what this is. */
|
||||||
#define _POSIX2_C_BIND _POSIX2_VERSION
|
#define _POSIX2_C_BIND _POSIX2_VERSION
|
||||||
#define _POSIX2_C_DEV _POSIX2_VERSION
|
#define _POSIX2_C_DEV _POSIX2_VERSION
|
||||||
#define _POSIX2_CHAR_TERM 1
|
#define _POSIX2_CHAR_TERM 1
|
||||||
/* TODO: _POSIX2_FORT_RUN - When fortran becomes supported. */
|
/* TODO: _POSIX2_FORT_RUN - When fortran becomes supported. */
|
||||||
/* #define _POSIX2_LOCALEDEF 202405L
|
/* #define _POSIX2_LOCALEDEF __POSIX2_THIS_VERSION
|
||||||
TODO: Uncomment when locales are implemented. */
|
TODO: Uncomment when locales are implemented. */
|
||||||
/* TODO: _POSIX2_SW_DEV - Research what this is. */
|
/* TODO: _POSIX2_PBS (Obsolescent) - Research what this is. */
|
||||||
/* #define _POSIX2_UPE 202405L
|
/* TODO: _POSIX2_PBS_ACCOUNTING (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX2_PBS_CHECKPOINT (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX2_PBS_LOCATE (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX2_PBS_MESSAGE (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX2_PBS_TRACK (Obsolescent) - Research what this is. */
|
||||||
|
/* TODO: _POSIX2_SW_DEV - Research what this is. (Define to _POSIX2_VERSION) */
|
||||||
|
/* #define _POSIX2_UPE 200809L
|
||||||
TODO: Uncomment when bg, ex, fc, fg, jobs, more, talk, vi are implemented. */
|
TODO: Uncomment when bg, ex, fc, fg, jobs, more, talk, vi are implemented. */
|
||||||
/* TODO: _XOPEN_CRYPT - Research what this is. */
|
/* TODO: _XOPEN_CRYPT - Research what this is. */
|
||||||
#define _XOPEN_ENH_I18N 1
|
#define _XOPEN_ENH_I18N 1
|
||||||
#define _XOPEN_REALTIME 1
|
#define _XOPEN_REALTIME 1
|
||||||
#define _XOPEN_REALTIME_THREADS 1
|
#define _XOPEN_REALTIME 1
|
||||||
|
/* TODO: _XOPEN_STREAMS (Obsolescent) - Probably don't want to support this. */
|
||||||
/* TODO: _XOPEN_UNIX - Decide whether we actually support this (probably not),
|
/* TODO: _XOPEN_UNIX - Decide whether we actually support this (probably not),
|
||||||
but also whether this header should lie. */
|
but also whether this header should lie. */
|
||||||
/* TODO: _XOPEN_UUCP - Research what this is. */
|
/* TODO: _XOPEN_UUCP - Research what this is. */
|
||||||
|
|
||||||
/* TODO: _POSIX_ASYNC_IO - Research what exactly this is. */
|
/* TODO: _POSIX_ASYNC_IO - Research what exactly this is. */
|
||||||
/* TODO: _POSIX_FALLOC - Research what exactly this is. */
|
|
||||||
/* TODO: _POSIX_PRIO_IO - Research what exactly this is. */
|
/* TODO: _POSIX_PRIO_IO - Research what exactly this is. */
|
||||||
/* TODO: _POSIX_SYNC_IO - Research what exactly this is. */
|
/* TODO: _POSIX_SYNC_IO - Research what exactly this is. */
|
||||||
#define _POSIX_TIMESTAMP_RESOLUTION 1
|
/* TODO: _POSIX_TIMESTAMP_RESOLUTION - Research what exactly this is. */
|
||||||
#define _POSIX2_SYMLINKS 1
|
/* TODO: _POSIX2_SYMLINKS - Research what exactly this is. */
|
||||||
|
|
||||||
#ifndef NULL
|
#ifndef NULL
|
||||||
#define __need_NULL
|
#define __need_NULL
|
||||||
|
@ -154,35 +163,35 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define _CS_PATH 0
|
#define _CS_PATH 0
|
||||||
#define _CS_POSIX_V8_ILP32_OFF32_CFLAGS 1
|
#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 1
|
||||||
#define _CS_POSIX_V8_ILP32_OFF32_LDFLAGS 2
|
#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 2
|
||||||
#define _CS_POSIX_V8_ILP32_OFF32_LIBS 3
|
#define _CS_POSIX_V7_ILP32_OFF32_LIBS 3
|
||||||
#define _CS_POSIX_V8_ILP32_OFFBIG_CFLAGS 4
|
#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 4
|
||||||
#define _CS_POSIX_V8_ILP32_OFFBIG_LDFLAGS 5
|
#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 5
|
||||||
#define _CS_POSIX_V8_ILP32_OFFBIG_LIBS 6
|
#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 6
|
||||||
#define _CS_POSIX_V8_LP64_OFF64_CFLAGS 7
|
#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 7
|
||||||
#define _CS_POSIX_V8_LP64_OFF64_LDFLAGS 8
|
#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 8
|
||||||
#define _CS_POSIX_V8_LP64_OFF64_LIBS 9
|
#define _CS_POSIX_V7_LP64_OFF64_LIBS 9
|
||||||
#define _CS_POSIX_V8_LPBIG_OFFBIG_CFLAGS 10
|
#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 10
|
||||||
#define _CS_POSIX_V8_LPBIG_OFFBIG_LDFLAGS 11
|
#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 11
|
||||||
#define _CS_POSIX_V8_LPBIG_OFFBIG_LIBS 12
|
#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 12
|
||||||
#define _CS_POSIX_V8_THREADS_CFLAGS 13
|
#define _CS_POSIX_V7_THREADS_CFLAGS 13
|
||||||
#define _CS_POSIX_V8_THREADS_LDFLAGS 14
|
#define _CS_POSIX_V7_THREADS_LDFLAGS 14
|
||||||
#define _CS_POSIX_V8_WIDTH_RESTRICTED_ENVS 15
|
#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 15
|
||||||
#define _CS_V7_ENV 16
|
#define _CS_V7_ENV 16
|
||||||
#define _CS_POSIX_V7_ILP32_OFF32_CFLAGS 17 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFF32_CFLAGS 17 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_ILP32_OFF32_LDFLAGS 18 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFF32_LDFLAGS 18 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_ILP32_OFF32_LIBS 19 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFF32_LIBS 19 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_ILP32_OFFBIG_CFLAGS 20 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFFBIG_CFLAGS 20 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_ILP32_OFFBIG_LDFLAGS 21 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFFBIG_LDFLAGS 21 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_ILP32_OFFBIG_LIBS 22 /* obsolescent */
|
#define _CS_POSIX_V6_ILP32_OFFBIG_LIBS 22 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LP64_OFF64_CFLAGS 23 /* obsolescent */
|
#define _CS_POSIX_V6_LP64_OFF64_CFLAGS 23 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LP64_OFF64_LDFLAGS 24 /* obsolescent */
|
#define _CS_POSIX_V6_LP64_OFF64_LDFLAGS 24 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LP64_OFF64_LIBS 25 /* obsolescent */
|
#define _CS_POSIX_V6_LP64_OFF64_LIBS 25 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LPBIG_OFFBIG_CFLAGS 26 /* obsolescent */
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_CFLAGS 26 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LPBIG_OFFBIG_LDFLAGS 27 /* obsolescent */
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_LDFLAGS 27 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_LPBIG_OFFBIG_LIBS 28 /* obsolescent */
|
#define _CS_POSIX_V6_LPBIG_OFFBIG_LIBS 28 /* obsolescent */
|
||||||
#define _CS_POSIX_V7_WIDTH_RESTRICTED_ENVS 29 /* obsolescent */
|
#define _CS_POSIX_V6_WIDTH_RESTRICTED_ENVS 29 /* obsolescent */
|
||||||
#define _CS_V6_ENV 30 /* obsolescent */
|
#define _CS_V6_ENV 30 /* obsolescent */
|
||||||
|
|
||||||
/* Sortix will not support POSIX advisory locks and doesn't declare:
|
/* Sortix will not support POSIX advisory locks and doesn't declare:
|
||||||
|
@ -212,8 +221,6 @@ extern "C" {
|
||||||
#define _PC_SYNC_IO 19
|
#define _PC_SYNC_IO 19
|
||||||
#define _PC_TIMESTAMP_RESOLUTION 20
|
#define _PC_TIMESTAMP_RESOLUTION 20
|
||||||
#define _PC_VDISABLE 21
|
#define _PC_VDISABLE 21
|
||||||
#define _PC_FALLOC 22
|
|
||||||
#define _PC_TEXTDOMAIN_MAX 23
|
|
||||||
|
|
||||||
#define _SC_AIO_LISTIO_MAX 0
|
#define _SC_AIO_LISTIO_MAX 0
|
||||||
#define _SC_AIO_MAX 1
|
#define _SC_AIO_MAX 1
|
||||||
|
@ -340,9 +347,6 @@ extern "C" {
|
||||||
#define _SC_XOPEN_UNIX 132
|
#define _SC_XOPEN_UNIX 132
|
||||||
#define _SC_XOPEN_UUCP 133
|
#define _SC_XOPEN_UUCP 133
|
||||||
#define _SC_XOPEN_VERSION 134
|
#define _SC_XOPEN_VERSION 134
|
||||||
#define _SC_NPROCESSORS_CONF 135
|
|
||||||
#define _SC_NPROCESSORS_ONLN 136
|
|
||||||
#define _SC_NSIG 137
|
|
||||||
|
|
||||||
#define STDIN_FILENO 0
|
#define STDIN_FILENO 0
|
||||||
#define STDOUT_FILENO 1
|
#define STDOUT_FILENO 1
|
||||||
|
@ -531,14 +535,6 @@ int symlinkat(const char*, int, const char*);
|
||||||
int unlinkat(int, const char*, int);
|
int unlinkat(int, const char*, int);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions from POSIX 2024. */
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
pid_t _Fork(void);
|
|
||||||
int dup3(int, int, int);
|
|
||||||
int getentropy(void*, size_t);
|
|
||||||
int pipe2(int [2], int);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if __USE_SORTIX || !(200112L <= __USE_POSIX || 600 <= __USE_XOPEN)
|
#if __USE_SORTIX || !(200112L <= __USE_POSIX || 600 <= __USE_XOPEN)
|
||||||
size_t getpagesize(void);
|
size_t getpagesize(void);
|
||||||
#endif
|
#endif
|
||||||
|
@ -549,8 +545,11 @@ int chroot(const char*);
|
||||||
int closefrom(int);
|
int closefrom(int);
|
||||||
int crypt_checkpass(const char*, const char*);
|
int crypt_checkpass(const char*, const char*);
|
||||||
int crypt_newhash(const char*, const char*, char*, size_t);
|
int crypt_newhash(const char*, const char*, char*, size_t);
|
||||||
|
int dup3(int, int, int);
|
||||||
int execvpe(const char*, char* const [], char* const []);
|
int execvpe(const char*, char* const [], char* const []);
|
||||||
char* get_current_dir_name(void);
|
char* get_current_dir_name(void);
|
||||||
|
int getentropy(void*, size_t);
|
||||||
|
int pipe2(int [2], int);
|
||||||
int sethostname(const char*, size_t);
|
int sethostname(const char*, size_t);
|
||||||
typedef unsigned int useconds_t;
|
typedef unsigned int useconds_t;
|
||||||
int usleep(useconds_t useconds);
|
int usleep(useconds_t useconds);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014, 2015, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014, 2015 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -207,12 +207,6 @@ size_t wcsnrtombs(char* __restrict, const wchar_t** __restrict, size_t, size_t,
|
||||||
/* TODO: size_t wcsxfrm_l(wchar_t* __restrict, const wchar_t* __restrict, size_t, locale_t); */
|
/* TODO: size_t wcsxfrm_l(wchar_t* __restrict, const wchar_t* __restrict, size_t, locale_t); */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Functions from POSIX 2024. */
|
|
||||||
#if __USE_SORTIX || 202405L <= __USE_POSIX
|
|
||||||
size_t wcslcat(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
|
||||||
size_t wcslcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Functions copied from elsewhere. */
|
/* Functions copied from elsewhere. */
|
||||||
#if __USE_SORTIX
|
#if __USE_SORTIX
|
||||||
/* TODO: getwc_unlocked */
|
/* TODO: getwc_unlocked */
|
||||||
|
@ -225,6 +219,8 @@ size_t wcslcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
||||||
/* TODO: fputws_unlocked */
|
/* TODO: fputws_unlocked */
|
||||||
wchar_t* wcschrnul(const wchar_t*, wchar_t);
|
wchar_t* wcschrnul(const wchar_t*, wchar_t);
|
||||||
/* TODO: wcsftime_l */
|
/* TODO: wcsftime_l */
|
||||||
|
size_t wcslcat(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
||||||
|
size_t wcslcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t);
|
||||||
/* TODO: wchar_t* wmempcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t); */
|
/* TODO: wchar_t* wmempcpy(wchar_t* __restrict, const wchar_t* __restrict, size_t); */
|
||||||
/* TODO: wcstod_l? */
|
/* TODO: wcstod_l? */
|
||||||
/* TODO: wcstof_l? */
|
/* TODO: wcstof_l? */
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* locale/getlocalename_l.c
|
|
||||||
* Get locale name.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <assert.h>
|
|
||||||
#include <locale.h>
|
|
||||||
|
|
||||||
extern char* __current_locales[LC_NUM_CATEGORIES];
|
|
||||||
|
|
||||||
const char* getlocalename_l(int cat, locale_t locale)
|
|
||||||
{
|
|
||||||
assert(locale == LC_GLOBAL_LOCALE);
|
|
||||||
return __current_locales[cat] ? __current_locales[cat] : (char*) "C";
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2014, 2015, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012, 2014, 2015 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char* __current_locales[LC_NUM_CATEGORIES] = { NULL };
|
static char* current_locales[LC_NUM_CATEGORIES] = { NULL };
|
||||||
|
|
||||||
char* setlocale(int category, const char* locale)
|
char* setlocale(int category, const char* locale)
|
||||||
{
|
{
|
||||||
|
@ -32,7 +32,7 @@ char* setlocale(int category, const char* locale)
|
||||||
int from = category != LC_ALL ? category : 0;
|
int from = category != LC_ALL ? category : 0;
|
||||||
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
|
int to = category != LC_ALL ? category : LC_NUM_CATEGORIES - 1;
|
||||||
if ( !locale )
|
if ( !locale )
|
||||||
return __current_locales[to] ? __current_locales[to] : (char*) "C";
|
return current_locales[to] ? current_locales[to] : (char*) "C";
|
||||||
for ( int i = from; i <= to; i++ )
|
for ( int i = from; i <= to; i++ )
|
||||||
{
|
{
|
||||||
if ( !(new_strings[i] = strdup(locale)) )
|
if ( !(new_strings[i] = strdup(locale)) )
|
||||||
|
@ -44,8 +44,8 @@ char* setlocale(int category, const char* locale)
|
||||||
}
|
}
|
||||||
for ( int i = from; i <= to; i++ )
|
for ( int i = from; i <= to; i++ )
|
||||||
{
|
{
|
||||||
free(__current_locales[i]);
|
free(current_locales[i]);
|
||||||
__current_locales[i] = new_strings[i];
|
current_locales[i] = new_strings[i];
|
||||||
}
|
}
|
||||||
return (char*) locale;
|
return (char*) locale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_cond_clockwait.c
|
|
||||||
* Waits on a condition or until a timeout happens.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/futex.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_cond_clockwait(pthread_cond_t* restrict cond,
|
|
||||||
pthread_mutex_t* restrict mutex,
|
|
||||||
clockid_t clock,
|
|
||||||
const struct timespec* restrict abstime)
|
|
||||||
{
|
|
||||||
struct pthread_cond_elem elem;
|
|
||||||
pthread_mutex_lock(&cond->lock);
|
|
||||||
elem.next = NULL;
|
|
||||||
elem.prev = cond->last;
|
|
||||||
elem.woken = 0;
|
|
||||||
if ( cond->last )
|
|
||||||
cond->last->next = &elem;
|
|
||||||
if ( !cond->first )
|
|
||||||
cond->first = &elem;
|
|
||||||
cond->last = &elem;
|
|
||||||
pthread_mutex_unlock(&cond->lock);
|
|
||||||
pthread_mutex_unlock(mutex);
|
|
||||||
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
|
|
||||||
int result = 0;
|
|
||||||
while ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) &&
|
|
||||||
futex(&elem.woken, op, 0, abstime) < 0 )
|
|
||||||
{
|
|
||||||
if ( errno == EINTR )
|
|
||||||
continue;
|
|
||||||
if ( errno != EAGAIN )
|
|
||||||
result = errno;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
pthread_mutex_lock(mutex);
|
|
||||||
pthread_mutex_lock(&cond->lock);
|
|
||||||
if ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) )
|
|
||||||
{
|
|
||||||
if ( elem.next )
|
|
||||||
elem.next->prev = elem.prev;
|
|
||||||
else
|
|
||||||
cond->last = elem.prev;
|
|
||||||
if ( elem.prev )
|
|
||||||
elem.prev->next = elem.next;
|
|
||||||
else
|
|
||||||
cond->first = elem.next;
|
|
||||||
}
|
|
||||||
pthread_mutex_unlock(&cond->lock);
|
|
||||||
return result;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2014, 2021 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,11 +17,51 @@
|
||||||
* Waits on a condition or until a timeout happens.
|
* Waits on a condition or until a timeout happens.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/futex.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
int pthread_cond_timedwait(pthread_cond_t* restrict cond,
|
int pthread_cond_timedwait(pthread_cond_t* restrict cond,
|
||||||
pthread_mutex_t* restrict mutex,
|
pthread_mutex_t* restrict mutex,
|
||||||
const struct timespec* restrict abstime)
|
const struct timespec* restrict abstime)
|
||||||
{
|
{
|
||||||
return pthread_cond_clockwait(cond, mutex, cond->clock, abstime);
|
struct pthread_cond_elem elem;
|
||||||
|
pthread_mutex_lock(&cond->lock);
|
||||||
|
elem.next = NULL;
|
||||||
|
elem.prev = cond->last;
|
||||||
|
elem.woken = 0;
|
||||||
|
if ( cond->last )
|
||||||
|
cond->last->next = &elem;
|
||||||
|
if ( !cond->first )
|
||||||
|
cond->first = &elem;
|
||||||
|
cond->last = &elem;
|
||||||
|
pthread_mutex_unlock(&cond->lock);
|
||||||
|
pthread_mutex_unlock(mutex);
|
||||||
|
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(cond->clock);
|
||||||
|
int result = 0;
|
||||||
|
while ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) &&
|
||||||
|
futex(&elem.woken, op, 0, abstime) < 0 )
|
||||||
|
{
|
||||||
|
if ( errno == EINTR )
|
||||||
|
continue;
|
||||||
|
if ( errno != EAGAIN )
|
||||||
|
result = errno;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pthread_mutex_lock(mutex);
|
||||||
|
pthread_mutex_lock(&cond->lock);
|
||||||
|
if ( !__atomic_load_n(&elem.woken, __ATOMIC_SEQ_CST) )
|
||||||
|
{
|
||||||
|
if ( elem.next )
|
||||||
|
elem.next->prev = elem.prev;
|
||||||
|
else
|
||||||
|
cond->last = elem.prev;
|
||||||
|
if ( elem.prev )
|
||||||
|
elem.prev->next = elem.next;
|
||||||
|
else
|
||||||
|
cond->first = elem.next;
|
||||||
|
}
|
||||||
|
pthread_mutex_unlock(&cond->lock);
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_mutex_clocklock.c
|
|
||||||
* Locks a mutex or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/futex.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <limits.h>
|
|
||||||
#include <pthread.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
|
|
||||||
static const int UNLOCKED = 0;
|
|
||||||
static const int LOCKED = 1;
|
|
||||||
static const int CONTENDED = 2;
|
|
||||||
|
|
||||||
int pthread_mutex_clocklock(pthread_mutex_t* mutex,
|
|
||||||
clockid_t clock,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
int state = UNLOCKED;
|
|
||||||
int desired = LOCKED;
|
|
||||||
while ( !__atomic_compare_exchange_n(&mutex->lock, &state, desired, false,
|
|
||||||
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) )
|
|
||||||
{
|
|
||||||
if ( mutex->type == PTHREAD_MUTEX_RECURSIVE &&
|
|
||||||
(pthread_t) mutex->owner == pthread_self() )
|
|
||||||
{
|
|
||||||
if ( mutex->recursion == ULONG_MAX )
|
|
||||||
return errno = EAGAIN;
|
|
||||||
mutex->recursion++;
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
if ( state == LOCKED &&
|
|
||||||
!__atomic_compare_exchange_n(&mutex->lock, &state, CONTENDED,
|
|
||||||
false, __ATOMIC_SEQ_CST,
|
|
||||||
__ATOMIC_SEQ_CST) )
|
|
||||||
{
|
|
||||||
state = UNLOCKED;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
desired = CONTENDED;
|
|
||||||
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
|
|
||||||
if ( futex(&mutex->lock, op, CONTENDED, abstime) < 0 &&
|
|
||||||
errno != EAGAIN && errno != EINTR )
|
|
||||||
return errno;
|
|
||||||
state = UNLOCKED;
|
|
||||||
}
|
|
||||||
mutex->owner = (unsigned long) pthread_self();
|
|
||||||
mutex->recursion = 0;
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2013, 2014, 2021 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,9 +17,47 @@
|
||||||
* Locks a mutex.
|
* Locks a mutex.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/futex.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
|
#include <limits.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
static const int UNLOCKED = 0;
|
||||||
|
static const int LOCKED = 1;
|
||||||
|
static const int CONTENDED = 2;
|
||||||
|
|
||||||
int pthread_mutex_lock(pthread_mutex_t* mutex)
|
int pthread_mutex_lock(pthread_mutex_t* mutex)
|
||||||
{
|
{
|
||||||
return pthread_mutex_timedlock(mutex, NULL);
|
int state = UNLOCKED;
|
||||||
|
int desired = LOCKED;
|
||||||
|
while ( !__atomic_compare_exchange_n(&mutex->lock, &state, desired, false,
|
||||||
|
__ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST) )
|
||||||
|
{
|
||||||
|
if ( mutex->type == PTHREAD_MUTEX_RECURSIVE &&
|
||||||
|
(pthread_t) mutex->owner == pthread_self() )
|
||||||
|
{
|
||||||
|
if ( mutex->recursion == ULONG_MAX )
|
||||||
|
return errno = EAGAIN;
|
||||||
|
mutex->recursion++;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
if ( state == LOCKED &&
|
||||||
|
!__atomic_compare_exchange_n(&mutex->lock, &state, CONTENDED,
|
||||||
|
false, __ATOMIC_SEQ_CST,
|
||||||
|
__ATOMIC_SEQ_CST) )
|
||||||
|
{
|
||||||
|
state = UNLOCKED;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
desired = CONTENDED;
|
||||||
|
if ( futex(&mutex->lock, FUTEX_WAIT, CONTENDED, NULL) < 0 &&
|
||||||
|
errno != EAGAIN && errno != EINTR )
|
||||||
|
return errno;
|
||||||
|
state = UNLOCKED;
|
||||||
|
}
|
||||||
|
mutex->owner = (unsigned long) pthread_self();
|
||||||
|
mutex->recursion = 0;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_mutex_timedlock.c
|
|
||||||
* Locks a mutex or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_mutex_timedlock(pthread_mutex_t* mutex,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
return pthread_mutex_clocklock(mutex, CLOCK_REALTIME, abstime);
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_rwlock_clockrdlock.c
|
|
||||||
* Acquires read access to a read-write lock or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_rwlock_clockrdlock(pthread_rwlock_t* rwlock, clockid_t clock,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&rwlock->request_mutex);
|
|
||||||
rwlock->pending_readers++;
|
|
||||||
int ret = 0;
|
|
||||||
while ( !ret && (!rwlock->num_writers || rwlock->pending_writers) )
|
|
||||||
ret = pthread_cond_clockwait(&rwlock->reader_condition,
|
|
||||||
&rwlock->request_mutex, clock, abstime);
|
|
||||||
rwlock->pending_readers--;
|
|
||||||
if ( !ret )
|
|
||||||
rwlock->num_readers++;
|
|
||||||
pthread_mutex_unlock(&rwlock->request_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -1,36 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_rwlock_clockwrlock.c
|
|
||||||
* Acquires write access to a read-write lock or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_rwlock_clocklock(pthread_rwlock_t* rwlock, clockid_t clock,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
pthread_mutex_lock(&rwlock->request_mutex);
|
|
||||||
rwlock->pending_writers++;
|
|
||||||
int ret = 0;
|
|
||||||
while ( !ret && (rwlock->num_readers || rwlock->num_writers) )
|
|
||||||
ret = pthread_cond_clockwait(&rwlock->writer_condition,
|
|
||||||
&rwlock->request_mutex, clock, abstime);
|
|
||||||
rwlock->pending_writers--;
|
|
||||||
if ( !ret )
|
|
||||||
rwlock->num_writers = 1;
|
|
||||||
pthread_mutex_unlock(&rwlock->request_mutex);
|
|
||||||
return ret;
|
|
||||||
}
|
|
|
@ -21,5 +21,12 @@
|
||||||
|
|
||||||
int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock)
|
int pthread_rwlock_rdlock(pthread_rwlock_t* rwlock)
|
||||||
{
|
{
|
||||||
return pthread_rwlock_timedrdlock(rwlock, NULL);
|
pthread_mutex_lock(&rwlock->request_mutex);
|
||||||
|
rwlock->pending_readers++;
|
||||||
|
while ( rwlock->num_writers || rwlock->pending_writers )
|
||||||
|
pthread_cond_wait(&rwlock->reader_condition, &rwlock->request_mutex);
|
||||||
|
rwlock->pending_readers--;
|
||||||
|
rwlock->num_readers++;
|
||||||
|
pthread_mutex_unlock(&rwlock->request_mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_rwlock_timedrdlock.c
|
|
||||||
* Acquires read access to a read-write lock or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_rwlock_timedrdlock(pthread_rwlock_t* rwlock,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
return pthread_rwlock_clockrdlock(rwlock, CLOCK_REALTIME, abstime);
|
|
||||||
}
|
|
|
@ -1,26 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* pthread/pthread_rwlock_timedwrlock.c
|
|
||||||
* Acquires write access to a read-write lock or waits for a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <pthread.h>
|
|
||||||
|
|
||||||
int pthread_rwlock_timedrwlock(pthread_rwlock_t* rwlock,
|
|
||||||
const struct timespec* abstime)
|
|
||||||
{
|
|
||||||
return pthread_rwlock_clockwrlock(rwlock, CLOCK_REALTIME, abstime);
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -21,5 +21,12 @@
|
||||||
|
|
||||||
int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock)
|
int pthread_rwlock_wrlock(pthread_rwlock_t* rwlock)
|
||||||
{
|
{
|
||||||
return pthread_rwlock_timedwrlock(rwlock, NULL);
|
pthread_mutex_lock(&rwlock->request_mutex);
|
||||||
|
rwlock->pending_writers++;
|
||||||
|
while ( rwlock->num_readers || rwlock->num_writers )
|
||||||
|
pthread_cond_wait(&rwlock->writer_condition, &rwlock->request_mutex);
|
||||||
|
rwlock->pending_writers--;
|
||||||
|
rwlock->num_writers = 1;
|
||||||
|
pthread_mutex_unlock(&rwlock->request_mutex);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,53 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* semaphore/sem_clockwait.c
|
|
||||||
* Lock a semaphore with a timeout.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <sys/futex.h>
|
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <semaphore.h>
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <time.h>
|
|
||||||
|
|
||||||
int sem_clockwait(sem_t* restrict sem, clockid_t clock,
|
|
||||||
const struct timespec* restrict abstime)
|
|
||||||
{
|
|
||||||
while ( true )
|
|
||||||
{
|
|
||||||
int old = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST);
|
|
||||||
int new = old != -1 ? old - 1 : -1;
|
|
||||||
bool waiting = new == -1;
|
|
||||||
if ( waiting )
|
|
||||||
__atomic_add_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
|
||||||
if ( old != new &&
|
|
||||||
!__atomic_compare_exchange_n(&sem->value, &old, new, false,
|
|
||||||
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED) )
|
|
||||||
{
|
|
||||||
if ( waiting )
|
|
||||||
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ( !waiting )
|
|
||||||
return 0;
|
|
||||||
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(clock);
|
|
||||||
int ret = futex(&sem->value, op, -1, abstime);
|
|
||||||
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
|
||||||
if ( ret < 0 && errno != EAGAIN )
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2014, 2021, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2014, 2021 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,9 +17,36 @@
|
||||||
* Lock a semaphore with a timeout.
|
* Lock a semaphore with a timeout.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include <sys/futex.h>
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <semaphore.h>
|
#include <semaphore.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
int sem_timedwait(sem_t* restrict sem, const struct timespec* restrict abstime)
|
int sem_timedwait(sem_t* restrict sem, const struct timespec* restrict abstime)
|
||||||
{
|
{
|
||||||
return sem_clockwait(sem, CLOCK_REALTIME, abstime);
|
while ( true )
|
||||||
|
{
|
||||||
|
int old = __atomic_load_n(&sem->value, __ATOMIC_SEQ_CST);
|
||||||
|
int new = old != -1 ? old - 1 : -1;
|
||||||
|
bool waiting = new == -1;
|
||||||
|
if ( waiting )
|
||||||
|
__atomic_add_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
||||||
|
if ( old != new &&
|
||||||
|
!__atomic_compare_exchange_n(&sem->value, &old, new, false,
|
||||||
|
__ATOMIC_SEQ_CST, __ATOMIC_RELAXED) )
|
||||||
|
{
|
||||||
|
if ( waiting )
|
||||||
|
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ( !waiting )
|
||||||
|
return 0;
|
||||||
|
int op = FUTEX_WAIT | FUTEX_ABSOLUTE | FUTEX_CLOCK(CLOCK_REALTIME);
|
||||||
|
int ret = futex(&sem->value, op, -1, abstime);
|
||||||
|
__atomic_sub_fetch(&sem->waiters, 1, __ATOMIC_SEQ_CST);
|
||||||
|
if ( ret < 0 && errno != EAGAIN )
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,68 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* signal/sig2str.c
|
|
||||||
* Get signal name.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int sig2str(int signum, char* str)
|
|
||||||
{
|
|
||||||
if ( SIGRTMIN < signum || signum < SIGRTMAX )
|
|
||||||
{
|
|
||||||
snprintf(str, SIG2STR_MAX, "RTMIN+%i", signum - SIGRTMIN);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
const char* name;
|
|
||||||
switch ( signum )
|
|
||||||
{
|
|
||||||
case SIGHUP: name = "HUP"; break;
|
|
||||||
case SIGINT: name = "INT"; break;
|
|
||||||
case SIGQUIT: name = "QUIT"; break;
|
|
||||||
case SIGILL: name = "ILL"; break;
|
|
||||||
case SIGTRAP: name = "TRAP"; break;
|
|
||||||
case SIGABRT: name = "ABRT"; break;
|
|
||||||
case SIGBUS: name = "BUS"; break;
|
|
||||||
case SIGFPE: name = "FPE"; break;
|
|
||||||
case SIGKILL: name = "KILL"; break;
|
|
||||||
case SIGUSR1: name = "USR1"; break;
|
|
||||||
case SIGSEGV: name = "SEGV"; break;
|
|
||||||
case SIGUSR2: name = "USR2"; break;
|
|
||||||
case SIGPIPE: name = "PIPE"; break;
|
|
||||||
case SIGALRM: name = "ALRM"; break;
|
|
||||||
case SIGTERM: name = "TERM"; break;
|
|
||||||
case SIGSYS: name = "SYS"; break;
|
|
||||||
case SIGCHLD: name = "CHLD"; break;
|
|
||||||
case SIGCONT: name = "CONT"; break;
|
|
||||||
case SIGSTOP: name = "STOP"; break;
|
|
||||||
case SIGTSTP: name = "TSTP"; break;
|
|
||||||
case SIGTTIN: name = "TTIN"; break;
|
|
||||||
case SIGTTOU: name = "TTOU"; break;
|
|
||||||
case SIGURG: name = "URG"; break;
|
|
||||||
case SIGXCPU: name = "XCPU"; break;
|
|
||||||
case SIGXFSZ: name = "XFSZ"; break;
|
|
||||||
case SIGVTALRM: name = "VTALRM"; break;
|
|
||||||
case SIGPWR: name = "PWR"; break;
|
|
||||||
case SIGWINCH: name = "WINCH"; break;
|
|
||||||
case SIGRTMIN: name = "RTMIN"; break;
|
|
||||||
case SIGRTMAX: name = "RTMAX"; break;
|
|
||||||
default: return -1;
|
|
||||||
}
|
|
||||||
strlcpy(str, name, SIG2STR_MAX);
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,67 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* signal/str2sig.c
|
|
||||||
* Lookup signal by name.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <signal.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
int str2sig(const char* signame, int* signum)
|
|
||||||
{
|
|
||||||
int ret;
|
|
||||||
if ( !strncmp(signame, "RTMIN+", strlen("RTMIN+")) ||
|
|
||||||
!strncmp(signame, "RTMAX-", strlen("RTMAX-")) )
|
|
||||||
{
|
|
||||||
// TODO: Stricter check.
|
|
||||||
int off = atoi(signame + 6);
|
|
||||||
if ( off < 1 || SIGRTMAX - SIGRTMIN <= off )
|
|
||||||
return -1;
|
|
||||||
ret = signame[5] == '+' ? SIGRTMIN + off : SIGRTMAX - off;
|
|
||||||
}
|
|
||||||
else if ( !strcmp(signame, "HUP") ) ret = SIGHUP;
|
|
||||||
else if ( !strcmp(signame, "INT") ) ret = SIGINT;
|
|
||||||
else if ( !strcmp(signame, "QUIT") ) ret = SIGQUIT;
|
|
||||||
else if ( !strcmp(signame, "ILL") ) ret = SIGILL;
|
|
||||||
else if ( !strcmp(signame, "TRAP") ) ret = SIGTRAP;
|
|
||||||
else if ( !strcmp(signame, "ABRT") ) ret = SIGABRT;
|
|
||||||
else if ( !strcmp(signame, "BUS") ) ret = SIGBUS;
|
|
||||||
else if ( !strcmp(signame, "FPE") ) ret = SIGFPE;
|
|
||||||
else if ( !strcmp(signame, "KILL") ) ret = SIGKILL;
|
|
||||||
else if ( !strcmp(signame, "USR1") ) ret = SIGUSR1;
|
|
||||||
else if ( !strcmp(signame, "SEGV") ) ret = SIGSEGV;
|
|
||||||
else if ( !strcmp(signame, "USR2") ) ret = SIGUSR2;
|
|
||||||
else if ( !strcmp(signame, "PIPE") ) ret = SIGPIPE;
|
|
||||||
else if ( !strcmp(signame, "ALRM") ) ret = SIGALRM;
|
|
||||||
else if ( !strcmp(signame, "TERM") ) ret = SIGTERM;
|
|
||||||
else if ( !strcmp(signame, "SYS") ) ret = SIGSYS;
|
|
||||||
else if ( !strcmp(signame, "CHLD") ) ret = SIGCHLD;
|
|
||||||
else if ( !strcmp(signame, "CONT") ) ret = SIGCONT;
|
|
||||||
else if ( !strcmp(signame, "STOP") ) ret = SIGSTOP;
|
|
||||||
else if ( !strcmp(signame, "TSTP") ) ret = SIGTSTP;
|
|
||||||
else if ( !strcmp(signame, "TTIN") ) ret = SIGTTIN;
|
|
||||||
else if ( !strcmp(signame, "TTOU") ) ret = SIGTTOU;
|
|
||||||
else if ( !strcmp(signame, "URG") ) ret = SIGURG;
|
|
||||||
else if ( !strcmp(signame, "XCPU") ) ret = SIGXCPU;
|
|
||||||
else if ( !strcmp(signame, "XFSZ") ) ret = SIGXFSZ;
|
|
||||||
else if ( !strcmp(signame, "VTALRM") ) ret = SIGVTALRM;
|
|
||||||
else if ( !strcmp(signame, "PWR") ) ret = SIGPWR;
|
|
||||||
else if ( !strcmp(signame, "WINCH") ) ret = SIGWINCH;
|
|
||||||
else return -1;
|
|
||||||
*signum = ret;
|
|
||||||
return 0;
|
|
||||||
}
|
|
|
@ -1,41 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* string/memmem.c
|
|
||||||
* Locate a subsequence.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
// TODO: Remember the fast algorithm and implemented it here and in strstr.
|
|
||||||
void* memmem(const void* haystack, size_t haystack_size,
|
|
||||||
const void* needle, size_t needle_size)
|
|
||||||
{
|
|
||||||
if ( !needle_size )
|
|
||||||
return (void*) haystack;
|
|
||||||
if ( haystack_size < needle_size )
|
|
||||||
return NULL;
|
|
||||||
for ( size_t i = 0; i < haystack_size - needle_size; i++ )
|
|
||||||
{
|
|
||||||
for ( size_t n = 0; n < needle_size; n++ )
|
|
||||||
{
|
|
||||||
if ( ((char*) haystack)[i + n] != ((char*) needle)[n] )
|
|
||||||
break;
|
|
||||||
if ( n + 1 == needle_size )
|
|
||||||
return (char*) haystack + i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NULL;
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011-2016, 2020-2022, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011-2016, 2020-2022 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,10 +17,11 @@
|
||||||
* Convert error code to a string.
|
* Convert error code to a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char* strerror(int errnum)
|
const char* sortix_strerror(int errnum)
|
||||||
{
|
{
|
||||||
switch ( errnum )
|
switch ( errnum )
|
||||||
{
|
{
|
||||||
|
@ -111,7 +112,11 @@ char* strerror(int errnum)
|
||||||
case ENOMOUNT: return "No such mountpoint";
|
case ENOMOUNT: return "No such mountpoint";
|
||||||
case ENOMEDIUM: return "No medium found";
|
case ENOMEDIUM: return "No medium found";
|
||||||
case EHOSTDOWN: return "Host is down";
|
case EHOSTDOWN: return "Host is down";
|
||||||
case ESOCKTNOSUPPORT: "Socket type is not supported";
|
|
||||||
default: return "Unknown error condition";
|
default: return "Unknown error condition";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strerror(int errnum)
|
||||||
|
{
|
||||||
|
return (char*) sortix_strerror(errnum);
|
||||||
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2013 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,10 +17,16 @@
|
||||||
* Convert error code to a string.
|
* Convert error code to a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
const char* sortix_strerror_l(int errnum, locale_t locale)
|
||||||
|
{
|
||||||
|
(void) locale;
|
||||||
|
return sortix_strerror(errnum);
|
||||||
|
}
|
||||||
|
|
||||||
char* strerror_l(int errnum, locale_t locale)
|
char* strerror_l(int errnum, locale_t locale)
|
||||||
{
|
{
|
||||||
(void) locale;
|
return (char*) sortix_strerror_l(errnum, locale);
|
||||||
return (char*) strerror(errnum);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2013, 2014, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012, 2013, 2014 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -22,7 +22,7 @@
|
||||||
|
|
||||||
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 = strerror(errnum);
|
const char* msg = sortix_strerror(errnum);
|
||||||
if ( !msg )
|
if ( !msg )
|
||||||
return -1;
|
return -1;
|
||||||
if ( dest_len < strlen(msg) + 1 )
|
if ( dest_len < strlen(msg) + 1 )
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2012, 2014, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2012, 2014 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -17,10 +17,11 @@
|
||||||
* Convert signal number to a string.
|
* Convert signal number to a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#define __SORTIX_STDLIB_REDIRECTS 0
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
char* strsignal(int signum)
|
const char* sortix_strsignal(int signum)
|
||||||
{
|
{
|
||||||
switch ( signum )
|
switch ( signum )
|
||||||
{
|
{
|
||||||
|
@ -60,3 +61,8 @@ char* strsignal(int signum)
|
||||||
|
|
||||||
return "Unknown signal value";
|
return "Unknown signal value";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char* strsignal(int signum)
|
||||||
|
{
|
||||||
|
return (char*) sortix_strsignal(signum);
|
||||||
|
}
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (c) 2011, 2012, 2024 Jonas 'Sortie' Termansen.
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
|
||||||
* copyright notice and this permission notice appear in all copies.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
||||||
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
||||||
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
||||||
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
||||||
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
||||||
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|
||||||
*
|
|
||||||
* unistd/_Fork.c
|
|
||||||
* Create a new task inheriting some properties from the current task.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
pid_t _Fork(void)
|
|
||||||
{
|
|
||||||
return sfork(SFFORK);
|
|
||||||
}
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2011, 2012, 2024 Jonas 'Sortie' Termansen.
|
* Copyright (c) 2011, 2012 Jonas 'Sortie' Termansen.
|
||||||
*
|
*
|
||||||
* Permission to use, copy, modify, and distribute this software for any
|
* Permission to use, copy, modify, and distribute this software for any
|
||||||
* purpose with or without fee is hereby granted, provided that the above
|
* purpose with or without fee is hereby granted, provided that the above
|
||||||
|
@ -21,5 +21,5 @@
|
||||||
|
|
||||||
pid_t fork(void)
|
pid_t fork(void)
|
||||||
{
|
{
|
||||||
return _Fork();
|
return sfork(SFFORK);
|
||||||
}
|
}
|
||||||
|
|
|
@ -773,7 +773,8 @@ static void think(struct glogin* state)
|
||||||
state->warning = strerror(errno);
|
state->warning = strerror(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// TODO: Find a method to detect what init is trying to do so we can display
|
||||||
|
// the appropriate message to the user.
|
||||||
if ( got_sigterm )
|
if ( got_sigterm )
|
||||||
{
|
{
|
||||||
int exit_code = get_init_exit_plan();
|
int exit_code = get_init_exit_plan();
|
||||||
|
|
|
@ -259,10 +259,6 @@ bool login(const char* username, const char* session)
|
||||||
return free(login_shell), close(pipe_fds[0]), close(pipe_fds[1]), false;
|
return free(login_shell), close(pipe_fds[0]), close(pipe_fds[1]), false;
|
||||||
if ( child_pid == 0 )
|
if ( child_pid == 0 )
|
||||||
{
|
{
|
||||||
sigset_t sigterm;
|
|
||||||
sigemptyset(&sigterm);
|
|
||||||
sigaddset(&sigterm, SIGTERM);
|
|
||||||
sigprocmask(SIG_UNBLOCK, &sigterm, NULL);
|
|
||||||
sigdelset(&oldset, SIGINT);
|
sigdelset(&oldset, SIGINT);
|
||||||
sigdelset(&oldset, SIGQUIT);
|
sigdelset(&oldset, SIGQUIT);
|
||||||
sigdelset(&oldset, SIGTERM);
|
sigdelset(&oldset, SIGTERM);
|
||||||
|
@ -289,6 +285,7 @@ bool login(const char* username, const char* session)
|
||||||
open("/dev/tty", O_WRONLY) != 2 ||
|
open("/dev/tty", O_WRONLY) != 2 ||
|
||||||
setcloexecfrom(3) < 0 ||
|
setcloexecfrom(3) < 0 ||
|
||||||
tcsetpgrp(0, getpgid(0)) ||
|
tcsetpgrp(0, getpgid(0)) ||
|
||||||
|
// TODO: Do this immediately? At least unblock SIGTERM.
|
||||||
sigprocmask(SIG_SETMASK, &oldset, NULL) < 0 ||
|
sigprocmask(SIG_SETMASK, &oldset, NULL) < 0 ||
|
||||||
settermmode(0, TERMMODE_NORMAL) < 0 ||
|
settermmode(0, TERMMODE_NORMAL) < 0 ||
|
||||||
(session ?
|
(session ?
|
||||||
|
@ -314,6 +311,7 @@ bool login(const char* username, const char* session)
|
||||||
sigaction(SIGTERM, &sa, &old_sa);
|
sigaction(SIGTERM, &sa, &old_sa);
|
||||||
sigprocmask(SIG_UNBLOCK, &sigterm, NULL);
|
sigprocmask(SIG_UNBLOCK, &sigterm, NULL);
|
||||||
|
|
||||||
|
// TODO: What happens if EINTR happens here? waitpid might block.
|
||||||
int errnum;
|
int errnum;
|
||||||
if ( readall(pipe_fds[0], &errnum, sizeof(errnum)) < (ssize_t) sizeof(errnum) )
|
if ( readall(pipe_fds[0], &errnum, sizeof(errnum)) < (ssize_t) sizeof(errnum) )
|
||||||
errnum = 0;
|
errnum = 0;
|
||||||
|
|
|
@ -91,22 +91,6 @@ and
|
||||||
.Xr setpgid 3
|
.Xr setpgid 3
|
||||||
are the standard portable replacements without disagreement on the function
|
are the standard portable replacements without disagreement on the function
|
||||||
signatures.
|
signatures.
|
||||||
.Ss getresgid, getresuid, setresgid, setresuid
|
|
||||||
These are not implemented yet as multi-user security is not yet implemented
|
|
||||||
in this operating system.
|
|
||||||
The kernel does not have a saved uid and saved gid concept at this time.
|
|
||||||
The
|
|
||||||
.Xr getuid 2 ,
|
|
||||||
.Xr getgid 2 ,
|
|
||||||
.Xr geteuid 2 ,
|
|
||||||
.Xr getegid 2 ,
|
|
||||||
.Xr setuid 2 ,
|
|
||||||
.Xr setgid 2 ,
|
|
||||||
.Xr seteuid 2 ,
|
|
||||||
and
|
|
||||||
.Xr setegid 2
|
|
||||||
system calls can be used to retrieve and manipulate the implemented concepts as
|
|
||||||
a workaround.
|
|
||||||
.Ss gettimeofday
|
.Ss gettimeofday
|
||||||
.Xr gettimeofday 2
|
.Xr gettimeofday 2
|
||||||
is implemented but the second parameter is defunct and is typed
|
is implemented but the second parameter is defunct and is typed
|
||||||
|
@ -182,61 +166,6 @@ is implemented in
|
||||||
per POSIX, however some operating systems have a
|
per POSIX, however some operating systems have a
|
||||||
.In sys/poll.h
|
.In sys/poll.h
|
||||||
alias which is not implemented.
|
alias which is not implemented.
|
||||||
.Ss posix_close
|
|
||||||
.Xr close 2
|
|
||||||
should be used instead.
|
|
||||||
POSIX 2024 defined this replacement interface because some broken legacy
|
|
||||||
operating systems could fail with
|
|
||||||
.Ev EINTR
|
|
||||||
in
|
|
||||||
.Xr close 2
|
|
||||||
on slow devices,
|
|
||||||
instead of returning 0 and either completing the operating in the background
|
|
||||||
or aborting it.
|
|
||||||
However, this means most programs need to be updated to use the more
|
|
||||||
complicated alternative function instead for no practical gain, which isn't
|
|
||||||
going to happen.
|
|
||||||
The standard has added a lot of complexity where none needs to exist, which
|
|
||||||
is rejected in this operating system.
|
|
||||||
.Xr close 2
|
|
||||||
never fails with
|
|
||||||
.Ev EINTR on this operating system.
|
|
||||||
.Ss posix_devctl
|
|
||||||
.Xr ioctl 2
|
|
||||||
should be used instead.
|
|
||||||
POSIX 2024 defined this optional function as a replacement for
|
|
||||||
.Xr ioctl 2
|
|
||||||
but never defined any way for portable applications to actually use it.
|
|
||||||
The
|
|
||||||
.Fa dev_info_ptr
|
|
||||||
parameter is especially useless as its semantics are not defined, and often
|
|
||||||
the desired output does not necessarily fit in an int type.
|
|
||||||
The
|
|
||||||
.Xr ioctl 2
|
|
||||||
interface is fine and this alternative function is rejected in this operating
|
|
||||||
system as it is optional in POSIX 2024.
|
|
||||||
.Ss posix_getdents
|
|
||||||
.Xr readdir 3
|
|
||||||
should be used instead.
|
|
||||||
.Xr readdirents 2
|
|
||||||
is a similar Sortix-specific system call that will likely be replaced with
|
|
||||||
something else in the future.
|
|
||||||
This new
|
|
||||||
.Ft posix_getdents
|
|
||||||
function is due to a mess of diverent
|
|
||||||
.Fn getdents
|
|
||||||
functions.
|
|
||||||
It is unfortunate they used
|
|
||||||
.Vt struct posix_dent
|
|
||||||
instead of
|
|
||||||
.Vt struct dirent
|
|
||||||
as they did not want to mandate the addition of the common
|
|
||||||
.Vt d_type
|
|
||||||
field in
|
|
||||||
.Vt struct dirent .
|
|
||||||
However,
|
|
||||||
.Vt posix_getdents
|
|
||||||
is decent and may be implemented in the future.
|
|
||||||
.Ss printf
|
.Ss printf
|
||||||
.Xr printf 3
|
.Xr printf 3
|
||||||
is implemented, however floating point formatting is not currently implemented
|
is implemented, however floating point formatting is not currently implemented
|
||||||
|
|
Loading…
Reference in a new issue