Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit bff4d4b

Browse files
authored
Merge pull request #2067 from yshui/musl_core_sys_posix
Add musl libc definitions to core/sys/posix/* merged-on-behalf-of: Iain Buclaw <ibuclaw@gdcproject.org>
2 parents 90770d3 + 192192a commit bff4d4b

File tree

19 files changed

+1163
-1
lines changed

19 files changed

+1163
-1
lines changed

src/core/sys/posix/config.d

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,18 @@ version (CRuntime_Glibc)
6565
else
6666
enum __WORDSIZE=32;
6767
}
68+
else version (CRuntime_Musl)
69+
{
70+
enum _FILE_OFFSET_BITS = 64;
71+
72+
enum __REDIRECT = false;
73+
74+
enum __USE_FILE_OFFSET64 = _FILE_OFFSET_BITS == 64;
75+
enum __USE_LARGEFILE = __USE_FILE_OFFSET64 && !__REDIRECT;
76+
enum __USE_LARGEFILE64 = __USE_FILE_OFFSET64 && !__REDIRECT;
77+
78+
enum __WORDSIZE=64;
79+
}
6880
else version (Solaris)
6981
{
7082
enum _FILE_OFFSET_BITS = 64;

src/core/sys/posix/dirent.d

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,44 @@ else version( CRuntime_Bionic )
317317

318318
dirent* readdir(DIR*);
319319
}
320+
else version( CRuntime_Musl )
321+
{
322+
enum
323+
{
324+
DT_UNKNOWN = 0,
325+
DT_FIFO = 1,
326+
DT_CHR = 2,
327+
DT_DIR = 4,
328+
DT_BLK = 6,
329+
DT_REG = 8,
330+
DT_LNK = 10,
331+
DT_SOCK = 12,
332+
DT_WHT = 14
333+
}
334+
335+
struct dirent
336+
{
337+
ino_t d_ino;
338+
off_t d_off;
339+
ushort d_reclen;
340+
ubyte d_type;
341+
char[256] d_name;
342+
}
343+
344+
struct DIR
345+
{
346+
}
347+
348+
static if( __USE_FILE_OFFSET64 )
349+
{
350+
dirent* readdir64(DIR*);
351+
alias readdir64 readdir;
352+
}
353+
else
354+
{
355+
dirent* readdir(DIR*);
356+
}
357+
}
320358
else
321359
{
322360
static assert(false, "Unsupported platform");
@@ -415,6 +453,10 @@ else version (Solaris)
415453
else version( CRuntime_Bionic )
416454
{
417455
int readdir_r(DIR*, dirent*, dirent**);
456+
}
457+
else version( CRuntime_Musl )
458+
{
459+
418460
}
419461
else
420462
{
@@ -485,6 +527,9 @@ else version (Solaris)
485527
else version (CRuntime_Bionic)
486528
{
487529
}
530+
else version (CRuntime_Musl)
531+
{
532+
}
488533
else
489534
{
490535
static assert(false, "Unsupported platform");

src/core/sys/posix/fcntl.d

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,66 @@ else version( CRuntime_Bionic )
784784

785785
enum AT_FDCWD = -100;
786786
}
787+
else version( CRuntime_Musl )
788+
{
789+
enum {
790+
O_CREAT = 0x40, // octal 0100
791+
O_EXCL = 0x80, // octal 0200
792+
O_NOCTTY = 0x100, // octal 0400
793+
O_TRUNC = 0x200, // octal 01000
794+
795+
O_APPEND = 0x400, // octal 02000
796+
O_NONBLOCK = 0x800, // octal 04000
797+
O_DSYNC = 0x1000, // octal 010000
798+
O_SYNC = 0x101000, // octal 04010000
799+
O_RSYNC = O_SYNC,
800+
O_DIRECTORY = 0x10000,
801+
O_NOFOLLOW = 0x20000,
802+
O_CLOEXEC = 0x80000,
803+
804+
O_ASYNC = 0x2000,
805+
O_DIRECT = 0x4000,
806+
O_LARGEFILE = 0,
807+
O_NOATIME = 0x40000,
808+
O_PATH = 0x200000,
809+
O_TMPFILE = 0x410000,
810+
O_NDELAY = O_NONBLOCK,
811+
O_SEARCH = O_PATH,
812+
O_EXEC = O_PATH,
813+
814+
O_ACCMODE = (03|O_SEARCH),
815+
O_RDONLY = 00,
816+
O_WRONLY = 01,
817+
O_RDWR = 02,
818+
}
819+
enum {
820+
F_DUPFD = 0,
821+
F_GETFD = 1,
822+
F_SETFD = 2,
823+
F_GETFL = 3,
824+
F_SETFL = 4,
825+
F_GETLK = 5,
826+
F_SETLK = 6,
827+
F_SETLKW = 7,
828+
F_SETOWN = 8,
829+
F_GETOWN = 9,
830+
}
831+
enum {
832+
F_RDLCK = 0,
833+
F_WRLCK = 1,
834+
F_UNLCK = 2,
835+
}
836+
struct flock
837+
{
838+
short l_type;
839+
short l_whence;
840+
off_t l_start;
841+
off_t l_len;
842+
pid_t l_pid;
843+
}
844+
enum FD_CLOEXEC = 1;
845+
int open(in char*, int, ...);
846+
}
787847
else
788848
{
789849
static assert(false, "Unsupported platform");

src/core/sys/posix/netdb.d

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,6 +866,81 @@ else version( CRuntime_Bionic )
866866
enum EAI_SYSTEM = 11;
867867
enum EAI_OVERFLOW = 14;
868868
}
869+
else version( CRuntime_Musl )
870+
{
871+
struct hostent
872+
{
873+
char* h_name;
874+
char** h_aliases;
875+
int h_addrtype;
876+
int h_length;
877+
char** h_addr_list;
878+
char* h_addr() @property { return h_addr_list[0]; } // non-standard
879+
}
880+
881+
struct netent
882+
{
883+
char* n_name;
884+
char** n_aliases;
885+
int n_addrtype;
886+
uint32_t n_net;
887+
}
888+
889+
struct protoent
890+
{
891+
char* p_name;
892+
char** p_aliases;
893+
int p_proto;
894+
}
895+
896+
struct servent
897+
{
898+
char* s_name;
899+
char** s_aliases;
900+
int s_port;
901+
char* s_proto;
902+
}
903+
904+
struct addrinfo
905+
{
906+
int ai_flags;
907+
int ai_family;
908+
int ai_socktype;
909+
int ai_protocol;
910+
socklen_t ai_addrlen;
911+
sockaddr* ai_addr;
912+
char* ai_canonname;
913+
addrinfo* ai_next;
914+
}
915+
916+
enum {
917+
AI_PASSIVE = 0x1,
918+
AI_CANONNAME = 0x2,
919+
AI_NUMERICHOST = 0x4,
920+
AI_NUMERICSERV = 0x8
921+
}
922+
enum {
923+
NI_NUMERICHOST = 1,
924+
NI_NUMERICSERV = 2,
925+
NI_NOFQDN = 4,
926+
NI_NAMEREQD = 8,
927+
NI_DGRAM = 16,
928+
NI_MAXSERV = 32,
929+
NI_MAXHOST = 255,
930+
}
931+
enum {
932+
EAI_BADFLAGS = -1,
933+
EAI_NONAME = -2,
934+
EAI_AGAIN = -3,
935+
EAI_FAIL = -4,
936+
EAI_FAMILY = -6,
937+
EAI_SOCKTYPE = -7,
938+
EAI_SERVICE = -8,
939+
EAI_MEMORY = -10,
940+
EAI_SYSTEM = -11,
941+
EAI_OVERFLOW = -12,
942+
}
943+
}
869944
else
870945
{
871946
static assert(false, "Unsupported platform");

src/core/sys/posix/netinet/in_.d

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ else version( linux )
345345
IPPROTO_TCP = 6,
346346
IPPROTO_PUP = 12,
347347
IPPROTO_UDP = 17,
348-
IPPROTO_IDP = 22
348+
IPPROTO_IDP = 22,
349+
IPPROTO_IPV6 = 41
349350
}
350351

351352
enum : c_ulong
@@ -1333,6 +1334,37 @@ else version( CRuntime_Bionic )
13331334
}
13341335
}
13351336
}
1337+
else version( CRuntime_Musl )
1338+
{
1339+
1340+
struct in6_addr {
1341+
union {
1342+
uint8_t[16] s6_addr;
1343+
uint16_t[8] s6_addr16;
1344+
uint32_t[4] s6_addr32;
1345+
}
1346+
}
1347+
struct sockaddr_in6 {
1348+
sa_family_t sin6_family;
1349+
in_port_t sin6_port;
1350+
uint32_t sin6_flowinfo;
1351+
in6_addr sin6_addr;
1352+
uint32_t sin6_scope_id;
1353+
}
1354+
1355+
enum : uint
1356+
{
1357+
IPV6_UNICAST_HOPS = 16,
1358+
IPV6_MULTICAST_IF = 17,
1359+
IPV6_MULTICAST_HOPS = 18,
1360+
IPV6_MULTICAST_LOOP = 19,
1361+
IPV6_JOIN_GROUP = 20,
1362+
IPV6_LEAVE_GROUP = 21,
1363+
IPV6_V6ONLY = 26
1364+
}
1365+
extern __gshared immutable in6_addr in6addr_any;
1366+
extern __gshared immutable in6_addr in6addr_loopback;
1367+
}
13361368

13371369

13381370
//

0 commit comments

Comments
 (0)