authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 19:36:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-08-06 19:36:31-04:00
log2c9ed664dd771ebb96f02ede84dd1ce7b6d58e44
tree00f2e741097f3493fcc603fb83cbdda0ee006e77
parent97be8debabcebf3102156a6df09f5acf4e0d8f6a

merge @kristate's std lib changes to darwin


2 files changed, 142 insertions(+), 93 deletions(-)

std/c/darwin.zig+26-8
......@@ -30,10 +30,36 @@ pub extern "c" fn sysctl(name: [*]c_int, namelen: c_uint, oldp: ?*c_void, oldlen
3030pub extern "c" fn sysctlbyname(name: [*]const u8, oldp: ?*c_void, oldlenp: ?*usize, newp: ?*c_void, newlen: usize) c_int;
3131pub extern "c" fn sysctlnametomib(name: [*]const u8, mibp: ?*c_int, sizep: ?*usize) c_int;
3232
33pub extern "c" fn bind(socket: c_int, address: ?*const sockaddr, address_len: socklen_t) c_int;
34pub extern "c" fn socket(domain: c_int, type: c_int, protocol: c_int) c_int;
35
3336pub use @import("../os/darwin/errno.zig");
3437
3538pub const _errno = __error;
3639
40pub const in_port_t = u16;
41pub const sa_family_t = u8;
42pub const socklen_t = u32;
43pub const sockaddr = extern union {
44 in: sockaddr_in,
45 in6: sockaddr_in6,
46};
47pub const sockaddr_in = extern struct {
48 len: u8,
49 family: sa_family_t,
50 port: in_port_t,
51 addr: u32,
52 zero: [8]u8,
53};
54pub const sockaddr_in6 = extern struct {
55 len: u8,
56 family: sa_family_t,
57 port: in_port_t,
58 flowinfo: u32,
59 addr: [16]u8,
60 scope_id: u32,
61};
62
3763pub const timeval = extern struct {
3864 tv_sec: isize,
3965 tv_usec: isize,
......@@ -98,14 +124,6 @@ pub const dirent = extern struct {
98124 d_name: u8, // field address is address of first byte of name
99125};
100126
101pub const sockaddr = extern struct {
102 sa_len: u8,
103 sa_family: sa_family_t,
104 sa_data: [14]u8,
105};
106
107pub const sa_family_t = u8;
108
109127pub const pthread_attr_t = extern struct {
110128 __sig: c_long,
111129 __opaque: [56]u8,
std/os/darwin.zig+116-85
......@@ -482,91 +482,98 @@ pub const NOTE_MACH_CONTINUOUS_TIME = 0x00000080;
482482/// data is mach absolute time units
483483pub const NOTE_MACHTIME = 0x00000100;
484484
485pub const AF_UNSPEC: c_int = 0;
486pub const AF_LOCAL: c_int = 1;
487pub const AF_UNIX: c_int = AF_LOCAL;
488pub const AF_INET: c_int = 2;
489pub const AF_SYS_CONTROL: c_int = 2;
490pub const AF_IMPLINK: c_int = 3;
491pub const AF_PUP: c_int = 4;
492pub const AF_CHAOS: c_int = 5;
493pub const AF_NS: c_int = 6;
494pub const AF_ISO: c_int = 7;
495pub const AF_OSI: c_int = AF_ISO;
496pub const AF_ECMA: c_int = 8;
497pub const AF_DATAKIT: c_int = 9;
498pub const AF_CCITT: c_int = 10;
499pub const AF_SNA: c_int = 11;
500pub const AF_DECnet: c_int = 12;
501pub const AF_DLI: c_int = 13;
502pub const AF_LAT: c_int = 14;
503pub const AF_HYLINK: c_int = 15;
504pub const AF_APPLETALK: c_int = 16;
505pub const AF_ROUTE: c_int = 17;
506pub const AF_LINK: c_int = 18;
507pub const AF_XTP: c_int = 19;
508pub const AF_COIP: c_int = 20;
509pub const AF_CNT: c_int = 21;
510pub const AF_RTIP: c_int = 22;
511pub const AF_IPX: c_int = 23;
512pub const AF_SIP: c_int = 24;
513pub const AF_PIP: c_int = 25;
514pub const AF_ISDN: c_int = 28;
515pub const AF_E164: c_int = AF_ISDN;
516pub const AF_KEY: c_int = 29;
517pub const AF_INET6: c_int = 30;
518pub const AF_NATM: c_int = 31;
519pub const AF_SYSTEM: c_int = 32;
520pub const AF_NETBIOS: c_int = 33;
521pub const AF_PPP: c_int = 34;
522pub const AF_MAX: c_int = 40;
523
524pub const PF_UNSPEC: c_int = AF_UNSPEC;
525pub const PF_LOCAL: c_int = AF_LOCAL;
526pub const PF_UNIX: c_int = PF_LOCAL;
527pub const PF_INET: c_int = AF_INET;
528pub const PF_IMPLINK: c_int = AF_IMPLINK;
529pub const PF_PUP: c_int = AF_PUP;
530pub const PF_CHAOS: c_int = AF_CHAOS;
531pub const PF_NS: c_int = AF_NS;
532pub const PF_ISO: c_int = AF_ISO;
533pub const PF_OSI: c_int = AF_ISO;
534pub const PF_ECMA: c_int = AF_ECMA;
535pub const PF_DATAKIT: c_int = AF_DATAKIT;
536pub const PF_CCITT: c_int = AF_CCITT;
537pub const PF_SNA: c_int = AF_SNA;
538pub const PF_DECnet: c_int = AF_DECnet;
539pub const PF_DLI: c_int = AF_DLI;
540pub const PF_LAT: c_int = AF_LAT;
541pub const PF_HYLINK: c_int = AF_HYLINK;
542pub const PF_APPLETALK: c_int = AF_APPLETALK;
543pub const PF_ROUTE: c_int = AF_ROUTE;
544pub const PF_LINK: c_int = AF_LINK;
545pub const PF_XTP: c_int = AF_XTP;
546pub const PF_COIP: c_int = AF_COIP;
547pub const PF_CNT: c_int = AF_CNT;
548pub const PF_SIP: c_int = AF_SIP;
549pub const PF_IPX: c_int = AF_IPX;
550pub const PF_RTIP: c_int = AF_RTIP;
551pub const PF_PIP: c_int = AF_PIP;
552pub const PF_ISDN: c_int = AF_ISDN;
553pub const PF_KEY: c_int = AF_KEY;
554pub const PF_INET6: c_int = AF_INET6;
555pub const PF_NATM: c_int = AF_NATM;
556pub const PF_SYSTEM: c_int = AF_SYSTEM;
557pub const PF_NETBIOS: c_int = AF_NETBIOS;
558pub const PF_PPP: c_int = AF_PPP;
559pub const PF_MAX: c_int = AF_MAX;
560
561pub const SYSPROTO_EVENT: c_int = 1;
562pub const SYSPROTO_CONTROL: c_int = 2;
563
564pub const SOCK_STREAM: c_int = 1;
565pub const SOCK_DGRAM: c_int = 2;
566pub const SOCK_RAW: c_int = 3;
567pub const SOCK_RDM: c_int = 4;
568pub const SOCK_SEQPACKET: c_int = 5;
569pub const SOCK_MAXADDRLEN: c_int = 255;
485pub const AF_UNSPEC = 0;
486pub const AF_LOCAL = 1;
487pub const AF_UNIX = AF_LOCAL;
488pub const AF_INET = 2;
489pub const AF_SYS_CONTROL = 2;
490pub const AF_IMPLINK = 3;
491pub const AF_PUP = 4;
492pub const AF_CHAOS = 5;
493pub const AF_NS = 6;
494pub const AF_ISO = 7;
495pub const AF_OSI = AF_ISO;
496pub const AF_ECMA = 8;
497pub const AF_DATAKIT = 9;
498pub const AF_CCITT = 10;
499pub const AF_SNA = 11;
500pub const AF_DECnet = 12;
501pub const AF_DLI = 13;
502pub const AF_LAT = 14;
503pub const AF_HYLINK = 15;
504pub const AF_APPLETALK = 16;
505pub const AF_ROUTE = 17;
506pub const AF_LINK = 18;
507pub const AF_XTP = 19;
508pub const AF_COIP = 20;
509pub const AF_CNT = 21;
510pub const AF_RTIP = 22;
511pub const AF_IPX = 23;
512pub const AF_SIP = 24;
513pub const AF_PIP = 25;
514pub const AF_ISDN = 28;
515pub const AF_E164 = AF_ISDN;
516pub const AF_KEY = 29;
517pub const AF_INET6 = 30;
518pub const AF_NATM = 31;
519pub const AF_SYSTEM = 32;
520pub const AF_NETBIOS = 33;
521pub const AF_PPP = 34;
522pub const AF_MAX = 40;
523
524pub const PF_UNSPEC = AF_UNSPEC;
525pub const PF_LOCAL = AF_LOCAL;
526pub const PF_UNIX = PF_LOCAL;
527pub const PF_INET = AF_INET;
528pub const PF_IMPLINK = AF_IMPLINK;
529pub const PF_PUP = AF_PUP;
530pub const PF_CHAOS = AF_CHAOS;
531pub const PF_NS = AF_NS;
532pub const PF_ISO = AF_ISO;
533pub const PF_OSI = AF_ISO;
534pub const PF_ECMA = AF_ECMA;
535pub const PF_DATAKIT = AF_DATAKIT;
536pub const PF_CCITT = AF_CCITT;
537pub const PF_SNA = AF_SNA;
538pub const PF_DECnet = AF_DECnet;
539pub const PF_DLI = AF_DLI;
540pub const PF_LAT = AF_LAT;
541pub const PF_HYLINK = AF_HYLINK;
542pub const PF_APPLETALK = AF_APPLETALK;
543pub const PF_ROUTE = AF_ROUTE;
544pub const PF_LINK = AF_LINK;
545pub const PF_XTP = AF_XTP;
546pub const PF_COIP = AF_COIP;
547pub const PF_CNT = AF_CNT;
548pub const PF_SIP = AF_SIP;
549pub const PF_IPX = AF_IPX;
550pub const PF_RTIP = AF_RTIP;
551pub const PF_PIP = AF_PIP;
552pub const PF_ISDN = AF_ISDN;
553pub const PF_KEY = AF_KEY;
554pub const PF_INET6 = AF_INET6;
555pub const PF_NATM = AF_NATM;
556pub const PF_SYSTEM = AF_SYSTEM;
557pub const PF_NETBIOS = AF_NETBIOS;
558pub const PF_PPP = AF_PPP;
559pub const PF_MAX = AF_MAX;
560
561pub const SYSPROTO_EVENT = 1;
562pub const SYSPROTO_CONTROL = 2;
563
564pub const SOCK_STREAM = 1;
565pub const SOCK_DGRAM = 2;
566pub const SOCK_RAW = 3;
567pub const SOCK_RDM = 4;
568pub const SOCK_SEQPACKET = 5;
569pub const SOCK_MAXADDRLEN = 255;
570
571pub const IPPROTO_ICMP = 1;
572pub const IPPROTO_ICMPV6 = 58;
573pub const IPPROTO_TCP = 6;
574pub const IPPROTO_UDP = 17;
575pub const IPPROTO_IP = 0;
576pub const IPPROTO_IPV6 = 41;
570577
571578fn wstatus(x: i32) i32 {
572579 return x & 0o177;
......@@ -605,6 +612,11 @@ pub fn abort() noreturn {
605612 c.abort();
606613}
607614
615// bind(int socket, const struct sockaddr *address, socklen_t address_len)
616pub fn bind(fd: i32, addr: *const sockaddr, len: socklen_t) usize {
617 return errnoWrap(c.bind(@bitCast(c_int, fd), addr, len));
618}
619
608620pub fn exit(code: i32) noreturn {
609621 c.exit(code);
610622}
......@@ -805,6 +817,20 @@ pub fn sigaction(sig: u5, noalias act: *const Sigaction, noalias oact: ?*Sigacti
805817 return result;
806818}
807819
820pub fn socket(domain: u32, socket_type: u32, protocol: u32) usize {
821 return errnoWrap(c.socket(@bitCast(c_int, domain), @bitCast(c_int, socket_type), @bitCast(c_int, protocol)));
822}
823
824pub const iovec = extern struct {
825 iov_base: [*]u8,
826 iov_len: usize,
827};
828
829pub const iovec_const = extern struct {
830 iov_base: [*]const u8,
831 iov_len: usize,
832};
833
808834pub const sigset_t = c.sigset_t;
809835pub const empty_sigset = sigset_t(0);
810836
......@@ -812,8 +838,13 @@ pub const timespec = c.timespec;
812838pub const Stat = c.Stat;
813839pub const dirent = c.dirent;
814840
841pub const in_port_t = c.in_port_t;
815842pub const sa_family_t = c.sa_family_t;
843pub const socklen_t = c.socklen_t;
844
816845pub const sockaddr = c.sockaddr;
846pub const sockaddr_in = c.sockaddr_in;
847pub const sockaddr_in6 = c.sockaddr_in6;
817848
818849/// Renamed from `kevent` to `Kevent` to avoid conflict with the syscall.
819850pub const Kevent = c.Kevent;