From 71a4f8667c63c2ffbe58eee7b5e963d3e09a42de Mon Sep 17 00:00:00 2001 From: "kim (grufwub)" Date: Wed, 8 Sep 2021 21:12:23 +0100 Subject: update sqlite library -> v1.13.0 Signed-off-by: kim (grufwub) --- vendor/modernc.org/libc/musl_linux_arm.go | 6052 ++++++++++++++++++++--------- 1 file changed, 4313 insertions(+), 1739 deletions(-) (limited to 'vendor/modernc.org/libc/musl_linux_arm.go') diff --git a/vendor/modernc.org/libc/musl_linux_arm.go b/vendor/modernc.org/libc/musl_linux_arm.go index dfd805a9b..e73f2ca39 100644 --- a/vendor/modernc.org/libc/musl_linux_arm.go +++ b/vendor/modernc.org/libc/musl_linux_arm.go @@ -1,4 +1,4 @@ -// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm.go -pkgname libc -static-locals-prefix _s -Iarch/arm -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/scalbn.c src/math/scalbnl.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__toread.c src/stdio/__uflow.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c', DO NOT EDIT. +// Code generated by 'ccgo -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_linux_arm.go -pkgname libc -static-locals-prefix _s -Iarch/arm -Iarch/generic -Iobj/src/internal -Isrc/include -Isrc/internal -Iobj/include -Iinclude copyright.c src/ctype/isalnum.c src/ctype/isalpha.c src/ctype/isdigit.c src/ctype/islower.c src/ctype/isprint.c src/ctype/isupper.c src/ctype/isxdigit.c src/dirent/closedir.c src/dirent/opendir.c src/dirent/readdir.c src/internal/floatscan.c src/internal/intscan.c src/internal/shgetc.c src/math/__fpclassify.c src/math/__fpclassifyf.c src/math/__fpclassifyl.c src/math/copysignl.c src/math/fabsl.c src/math/fmodl.c src/math/nanf.c src/math/scalbn.c src/math/scalbnl.c src/multibyte/internal.c src/multibyte/mbrtowc.c src/multibyte/mbsinit.c src/network/freeaddrinfo.c src/network/getaddrinfo.c src/network/gethostbyaddr.c src/network/gethostbyaddr_r.c src/network/gethostbyname.c src/network/gethostbyname2.c src/network/gethostbyname2_r.c src/network/gethostbyname_r.c src/network/getnameinfo.c src/network/h_errno.c src/network/inet_aton.c src/network/inet_ntop.c src/network/inet_pton.c src/network/lookup_ipliteral.c src/network/lookup_name.c src/network/lookup_serv.c src/prng/rand_r.c src/stdio/__lockfile.c src/stdio/__toread.c src/stdio/__uflow.c src/stdio/sscanf.c src/stdio/vfscanf.c src/stdio/vsscanf.c src/stdlib/strtod.c src/stdlib/strtol.c src/string/strdup.c src/string/strlcat.c src/string/strlcpy.c src/string/strncasecmp.c src/string/strncat.c src/string/strnlen.c src/string/strspn.c src/string/strtok.c src/thread/pthread_attr_get.c src/thread/pthread_attr_setdetachstate.c src/thread/pthread_mutex_lock.c src/thread/pthread_mutexattr_destroy.c src/thread/pthread_mutexattr_init.c src/thread/pthread_mutexattr_settype.c', DO NOT EDIT. package libc @@ -351,6 +351,12 @@ const ( /* nameser.h:98:1: */ ns_r_badtime = 18 ) +const ( /* pthread_impl.h:58:1: */ + DT_EXITING = 0 + DT_JOINABLE = 1 + DT_DETACHED = 2 +) + type ptrdiff_t = int32 /* :3:26 */ type size_t = uint32 /* :9:23 */ @@ -361,6 +367,8 @@ func __isspace(tls *TLS, _c int32) int32 { /* ctype.h:26:21: */ return (Bool32((_c == ' ') || ((uint32(_c) - uint32('\t')) < uint32(5)))) } +type __locale_struct = struct{ cat [6]uintptr } /* alltypes.h:336:9 */ + type locale_t = uintptr /* alltypes.h:336:32 */ func Xisalnum(tls *TLS, c int32) int32 { /* isalnum.c:3:5: */ @@ -675,6 +683,44 @@ func __DOUBLE_BITS(tls *TLS, __f float64) uint64 { /* math.h:61:36: */ return *(*uint64)(unsafe.Pointer(bp /* &__u */)) } +type __pthread = struct { + self uintptr + dtv uintptr + prev uintptr + next uintptr + sysinfo uintptr_t + canary uintptr_t + canary2 uintptr_t + tid int32 + errno_val int32 + detach_state int32 + cancel int32 + canceldisable uint8 + cancelasync uint8 + tsd_used uint8 /* unsigned char tsd_used: 1, unsigned char dlerror_flag: 1 */ + _ [1]byte + map_base uintptr + map_size size_t + stack uintptr + stack_size size_t + guard_size size_t + result uintptr + cancelbuf uintptr + tsd uintptr + robust_list struct { + head uintptr + off int32 + pending uintptr + } + timer_id int32 + locale locale_t + killlock [1]int32 + dlerror_buf uintptr + stdio_locks uintptr + canary_at_end uintptr_t + dtv_copy uintptr +} /* alltypes.h:266:9 */ + func scanexp(tls *TLS, f uintptr, pok int32) int64 { /* floatscan.c:37:18: */ var c int32 var x int32 @@ -1891,192 +1937,1695 @@ func Xscalbnl(tls *TLS, x float64, n int32) float64 { /* scalbnl.c:4:13: */ return Xscalbn(tls, x, n) } -type imaxdiv_t = struct { - quot intmax_t - rem intmax_t -} /* inttypes.h:14:40 */ +// Upper 6 state bits are a negative integer offset to bound-check next byte +// equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f + +// Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. + +// Arbitrary encoding for representing code units instead of characters. + +// Get inline definition of MB_CUR_MAX. + +type lconv = struct { + decimal_point uintptr + thousands_sep uintptr + grouping uintptr + int_curr_symbol uintptr + currency_symbol uintptr + mon_decimal_point uintptr + mon_thousands_sep uintptr + mon_grouping uintptr + positive_sign uintptr + negative_sign uintptr + int_frac_digits int8 + frac_digits int8 + p_cs_precedes int8 + p_sep_by_space int8 + n_cs_precedes int8 + n_sep_by_space int8 + p_sign_posn int8 + n_sign_posn int8 + int_p_cs_precedes int8 + int_p_sep_by_space int8 + int_n_cs_precedes int8 + int_n_sep_by_space int8 + int_p_sign_posn int8 + int_n_sign_posn int8 + _ [2]byte +} /* locale.h:24:1 */ -type socklen_t = uint32 /* alltypes.h:354:18 */ +// Support signed or unsigned plain-char -type sa_family_t = uint16 /* alltypes.h:359:24 */ +// Implementation choices... -type msghdr = struct { - msg_name uintptr - msg_namelen socklen_t - msg_iov uintptr - msg_iovlen int32 - msg_control uintptr - msg_controllen socklen_t - msg_flags int32 -} /* socket.h:22:1 */ +// Arbitrary numbers... -type cmsghdr = struct { - cmsg_len socklen_t - cmsg_level int32 - cmsg_type int32 -} /* socket.h:44:1 */ +// POSIX/SUS requirements follow. These numbers come directly +// from SUS and have nothing to do with the host system. -type linger = struct { - l_onoff int32 - l_linger int32 -} /* socket.h:74:1 */ +type __locale_map = struct { + __map uintptr + map_size size_t + name [24]int8 + next uintptr +} /* alltypes.h:336:9 */ + +type tls_module = struct { + next uintptr + image uintptr + len size_t + size size_t + align size_t + offset size_t +} /* libc.h:14:1 */ + +type __libc = struct { + can_do_threads int8 + threaded int8 + secure int8 + need_locks int8 + threads_minus_1 int32 + auxv uintptr + tls_head uintptr + tls_size size_t + tls_align size_t + tls_cnt size_t + page_size size_t + global_locale struct{ cat [6]uintptr } +} /* libc.h:20:1 */ -type sockaddr = struct { - sa_family sa_family_t - sa_data [14]int8 -} /* socket.h:367:1 */ +type time_t = int64 /* alltypes.h:78:16 */ -type sockaddr_storage = struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 -} /* socket.h:372:1 */ +type clockid_t = int32 /* alltypes.h:207:13 */ -type in_port_t = uint16_t /* in.h:12:18 */ -type in_addr_t = uint32_t /* in.h:13:18 */ -type in_addr = struct{ s_addr in_addr_t } /* in.h:14:1 */ +type timespec = struct { + tv_sec time_t + tv_nsec int32 + __12 uint32 /* int : 32 */ +} /* alltypes.h:222:1 */ -type sockaddr_in = struct { - sin_family sa_family_t - sin_port in_port_t - sin_addr struct{ s_addr in_addr_t } - sin_zero [8]uint8_t -} /* in.h:16:1 */ +type pthread_t = uintptr /* alltypes.h:266:26 */ -type in6_addr = struct { - __in6_union struct { - _ [0]uint32 - __s6_addr [16]uint8_t - } -} /* in.h:23:1 */ +type pthread_once_t = int32 /* alltypes.h:272:13 */ -type sockaddr_in6 = struct { - sin6_family sa_family_t - sin6_port in_port_t - sin6_flowinfo uint32_t - sin6_addr struct { - __in6_union struct { - _ [0]uint32 - __s6_addr [16]uint8_t - } - } - sin6_scope_id uint32_t -} /* in.h:34:1 */ +type pthread_key_t = uint32 /* alltypes.h:277:18 */ -type ipv6_mreq = struct { - ipv6mr_multiaddr struct { - __in6_union struct { - _ [0]uint32 - __s6_addr [16]uint8_t - } - } - ipv6mr_interface uint32 -} /* in.h:42:1 */ +type pthread_spinlock_t = int32 /* alltypes.h:282:13 */ -type ip_opts = struct { - ip_dst struct{ s_addr in_addr_t } - ip_opts [40]int8 -} /* in.h:229:1 */ +type pthread_mutexattr_t = struct{ __attr uint32 } /* alltypes.h:287:37 */ -type ip_mreq = struct { - imr_multiaddr struct{ s_addr in_addr_t } - imr_interface struct{ s_addr in_addr_t } -} /* in.h:247:1 */ +type pthread_condattr_t = struct{ __attr uint32 } /* alltypes.h:292:37 */ -type ip_mreqn = struct { - imr_multiaddr struct{ s_addr in_addr_t } - imr_address struct{ s_addr in_addr_t } - imr_ifindex int32 -} /* in.h:252:1 */ +type pthread_barrierattr_t = struct{ __attr uint32 } /* alltypes.h:297:37 */ -type ip_mreq_source = struct { - imr_multiaddr struct{ s_addr in_addr_t } - imr_interface struct{ s_addr in_addr_t } - imr_sourceaddr struct{ s_addr in_addr_t } -} /* in.h:258:1 */ +type pthread_rwlockattr_t = struct{ __attr [2]uint32 } /* alltypes.h:302:40 */ -type ip_msfilter = struct { - imsf_multiaddr struct{ s_addr in_addr_t } - imsf_interface struct{ s_addr in_addr_t } - imsf_fmode uint32_t - imsf_numsrc uint32_t - imsf_slist [1]struct{ s_addr in_addr_t } -} /* in.h:264:1 */ +type __sigset_t = struct{ __bits [32]uint32 } /* alltypes.h:342:9 */ -type group_req = struct { - gr_interface uint32_t - gr_group struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 +type sigset_t = __sigset_t /* alltypes.h:342:71 */ + +type pthread_attr_t = struct{ __u struct{ __i [9]int32 } } /* alltypes.h:365:147 */ + +type pthread_mutex_t = struct{ __u struct{ __i [6]int32 } } /* alltypes.h:370:157 */ + +type pthread_cond_t = struct{ __u struct{ __i [12]int32 } } /* alltypes.h:380:112 */ + +type pthread_rwlock_t = struct{ __u struct{ __i [8]int32 } } /* alltypes.h:390:139 */ + +type pthread_barrier_t = struct{ __u struct{ __i [5]int32 } } /* alltypes.h:395:137 */ + +type sched_param = struct { + sched_priority int32 + __reserved1 int32 + __reserved2 [4]int32 + __reserved3 int32 +} /* sched.h:19:1 */ + +type timer_t = uintptr /* alltypes.h:202:14 */ + +type clock_t = int32 /* alltypes.h:212:14 */ + +type tm = struct { + tm_sec int32 + tm_min int32 + tm_hour int32 + tm_mday int32 + tm_mon int32 + tm_year int32 + tm_wday int32 + tm_yday int32 + tm_isdst int32 + tm_gmtoff int32 + tm_zone uintptr +} /* time.h:38:1 */ + +type itimerspec = struct { + it_interval struct { + tv_sec time_t + tv_nsec int32 + __12 uint32 /* int : 32 */ } -} /* in.h:275:1 */ + it_value struct { + tv_sec time_t + tv_nsec int32 + __12 uint32 /* int : 32 */ + } +} /* time.h:80:1 */ -type group_source_req = struct { - gsr_interface uint32_t - gsr_group struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 +type sigevent = struct { + sigev_value struct{ sival_int int32 } + sigev_signo int32 + sigev_notify int32 + sigev_notify_function uintptr + sigev_notify_attributes uintptr + __pad [44]int8 +} /* time.h:107:1 */ + +type __ptcb = struct { + __f uintptr + __x uintptr + __next uintptr +} /* alltypes.h:266:9 */ + +type sigaltstack = struct { + ss_sp uintptr + ss_flags int32 + ss_size size_t +} /* signal.h:44:9 */ + +type stack_t = sigaltstack /* signal.h:44:28 */ + +type greg_t = int32 /* signal.h:10:13 */ +type gregset_t = [18]int32 /* signal.h:10:21 */ +type sigcontext = struct { + trap_no uint32 + error_code uint32 + oldmask uint32 + arm_r0 uint32 + arm_r1 uint32 + arm_r2 uint32 + arm_r3 uint32 + arm_r4 uint32 + arm_r5 uint32 + arm_r6 uint32 + arm_r7 uint32 + arm_r8 uint32 + arm_r9 uint32 + arm_r10 uint32 + arm_fp uint32 + arm_ip uint32 + arm_sp uint32 + arm_lr uint32 + arm_pc uint32 + arm_cpsr uint32 + fault_address uint32 +} /* signal.h:11:9 */ + +type mcontext_t = sigcontext /* signal.h:18:3 */ + +type __ucontext = struct { + uc_flags uint32 + uc_link uintptr + uc_stack stack_t + uc_mcontext mcontext_t + uc_sigmask sigset_t + uc_regspace [64]uint64 +} /* signal.h:31:9 */ + +type ucontext_t = __ucontext /* signal.h:38:3 */ + +type sigval = struct{ sival_int int32 } /* time.h:107:1 */ + +type siginfo_t = struct { + si_signo int32 + si_errno int32 + si_code int32 + __si_fields struct { + _ [0]uint32 + __pad [116]int8 + } +} /* signal.h:145:3 */ + +type sigaction = struct { + __sa_handler struct{ sa_handler uintptr } + sa_mask sigset_t + sa_flags int32 + sa_restorer uintptr +} /* signal.h:167:1 */ + +type sig_t = uintptr /* signal.h:251:14 */ + +type sig_atomic_t = int32 /* signal.h:269:13 */ + +func a_cas(tls *TLS, p uintptr, t int32, s int32) int32 { /* atomic_arch.h:46:19: */ + panic(`arch/arm/atomic_arch.h:48:2: assembler statements not supported`) + return int32(0) + //TODO for (;;) { + //TODO register int r0 __asm__("r0") = t; + //TODO register int r1 __asm__("r1") = s; + //TODO register volatile int *r2 __asm__("r2") = p; + //TODO register uintptr_t r3 __asm__("r3") = __a_cas_ptr; + //TODO int old; + //TODO __asm__ __volatile__ ( + //TODO BLX " r3" + //TODO : "+r"(r0), "+r"(r3) : "r"(r1), "r"(r2) + //TODO : "memory", "lr", "ip", "cc" ); + //TODO if (!r0) return t; + //TODO if ((old=*p)!=t) return old; + //TODO } +} + +func a_barrier(tls *TLS) { /* atomic_arch.h:68:20: */ + panic(`arch/arm/atomic_arch.h:70:2: assembler statements not supported`) + //TODO register uintptr_t ip __asm__("ip") = __a_barrier_ptr; + //TODO __asm__ __volatile__( BLX " ip" : "+r"(ip) : : "memory", "cc", "lr" ); +} + +func a_clz_32(tls *TLS, x uint32_t) int32 { /* atomic_arch.h:91:19: */ + panic(`arch/arm/atomic_arch.h:93:2: assembler statements not supported`) + return int32(x) +} + +func a_swap(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:108:19: */ + var old int32 + for ok := true; ok; ok = (a_cas(tls, AtomicLoadUintptr(&p), old, v) != old) { + old = *(*int32)(unsafe.Pointer(AtomicLoadUintptr(&p))) } - gsr_source struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 + return old +} + +func a_fetch_add(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:119:19: */ + var old int32 + for ok := true; ok; ok = (a_cas(tls, AtomicLoadUintptr(&p), old, (int32(uint32(old)+uint32(v)))) != old) { + old = *(*int32)(unsafe.Pointer(AtomicLoadUintptr(&p))) } -} /* in.h:280:1 */ + return old +} -type group_filter = struct { - gf_interface uint32_t - gf_group struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 +func a_fetch_and(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:130:19: */ + var old int32 + for ok := true; ok; ok = (a_cas(tls, AtomicLoadUintptr(&p), old, (old&v)) != old) { + old = *(*int32)(unsafe.Pointer(AtomicLoadUintptr(&p))) } - gf_fmode uint32_t - gf_numsrc uint32_t - gf_slist [1]struct { - ss_family sa_family_t - __ss_padding [122]int8 - __ss_align uint32 + return old +} + +func a_fetch_or(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:140:19: */ + var old int32 + for ok := true; ok; ok = (a_cas(tls, AtomicLoadUintptr(&p), old, (old|v)) != old) { + old = *(*int32)(unsafe.Pointer(AtomicLoadUintptr(&p))) } -} /* in.h:286:1 */ + return old +} -type in_pktinfo = struct { - ipi_ifindex int32 - ipi_spec_dst struct{ s_addr in_addr_t } - ipi_addr struct{ s_addr in_addr_t } -} /* in.h:297:1 */ +func a_and(tls *TLS, p uintptr, v int32) { /* atomic.h:151:20: */ + a_fetch_and(tls, AtomicLoadUintptr(&p), v) +} -type in6_pktinfo = struct { - ipi6_addr struct { - __in6_union struct { - _ [0]uint32 - __s6_addr [16]uint8_t - } +func a_or(tls *TLS, p uintptr, v int32) { /* atomic.h:159:20: */ + a_fetch_or(tls, AtomicLoadUintptr(&p), v) +} + +func a_or_64(tls *TLS, p uintptr, v uint64_t) { /* atomic.h:220:20: */ + bp := tls.Alloc(8) + defer tls.Free(8) + + *(*struct{ v uint64_t })(unsafe.Pointer(bp /* u */)) = struct{ v uint64_t }{v: v} + if *(*uint32_t)(unsafe.Pointer((bp /* &u */ /* &.r */))) != 0 { + a_or(tls, AtomicLoadUintptr(&p), int32(*(*uint32_t)(unsafe.Pointer((bp /* &u */ /* &.r */))))) } - ipi6_ifindex uint32 -} /* in.h:303:1 */ + if *(*uint32_t)(unsafe.Pointer((bp /* &u */ /* &.r */) + 1*4)) != 0 { + a_or(tls, (AtomicLoadUintptr(&p) + uintptr(1)*4), int32(*(*uint32_t)(unsafe.Pointer((bp /* &u */ /* &.r */) + 1*4)))) + } +} -type ip6_mtuinfo = struct { - ip6m_addr struct { - sin6_family sa_family_t - sin6_port in_port_t - sin6_flowinfo uint32_t - sin6_addr struct { - __in6_union struct { - _ [0]uint32 - __s6_addr [16]uint8_t - } +type a_cas_p_undefined_but_pointer_not_32bit = [1]int8 /* atomic.h:229:14 */ + +func a_ctz_32(tls *TLS, x uint32_t) int32 { /* atomic.h:256:19: */ + return (31 - a_clz_32(tls, (x&-x))) +} + +func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic.h:272:19: */ + if uint32(unsafe.Sizeof(int32(0))) < uint32(8) { + var y uint32_t = uint32_t(x) + if !(y != 0) { + y = (uint32_t(x >> 32)) + return (32 + a_ctz_32(tls, y)) } - sin6_scope_id uint32_t + return a_ctz_32(tls, y) } - ip6m_mtu uint32_t -} /* in.h:308:1 */ + return int32(_sdebruijn648[(((x & -x) * 0x022fdd63cc95386d) >> 58)]) +} -type addrinfo = struct { - ai_flags int32 - ai_family int32 +var _sdebruijn648 = [64]int8{ + int8(0), int8(1), int8(2), int8(53), int8(3), int8(7), int8(54), int8(27), int8(4), int8(38), int8(41), int8(8), int8(34), int8(55), int8(48), int8(28), + int8(62), int8(5), int8(39), int8(46), int8(44), int8(42), int8(22), int8(9), int8(24), int8(35), int8(59), int8(56), int8(49), int8(18), int8(29), int8(11), + int8(63), int8(52), int8(6), int8(26), int8(37), int8(40), int8(33), int8(47), int8(61), int8(45), int8(43), int8(21), int8(23), int8(58), int8(17), int8(10), + int8(51), int8(25), int8(36), int8(32), int8(60), int8(20), int8(57), int8(16), int8(50), int8(31), int8(19), int8(15), int8(30), int8(14), int8(13), int8(12), +} /* atomic.h:274:20 */ + +type __timer = struct { + timerid int32 + thread pthread_t +} /* pthread_impl.h:64:1 */ + +func __pthread_self(tls *TLS) pthread_t { /* pthread_arch.h:19:25: */ + var p uintptr_t + panic(`arch/arm/pthread_arch.h:23:2: assembler statements not supported`) + return (uintptr(p - uintptr_t(unsafe.Sizeof(__pthread{})))) +} + +func __wake(tls *TLS, addr uintptr, cnt int32, priv int32) { /* pthread_impl.h:155:20: */ + if priv != 0 { + priv = 128 + } + if cnt < 0 { + cnt = 0x7fffffff + } + _ = (Bool32((X__syscall3(tls, 240, int32(AtomicLoadUintptr(&addr)), (int32(1|priv)), int32(cnt)) != -38) || (X__syscall3(tls, 240, int32(AtomicLoadUintptr(&addr)), 1, int32(cnt)) != 0))) +} + +func __futexwait(tls *TLS, addr uintptr, val int32, priv int32) { /* pthread_impl.h:162:20: */ + if priv != 0 { + priv = 128 + } + _ = (Bool32((X__syscall4(tls, 240, int32(AtomicLoadUintptr(&addr)), (int32(0|priv)), int32(val), 0) != -38) || (X__syscall4(tls, 240, int32(AtomicLoadUintptr(&addr)), 0, int32(val), 0) != 0))) +} + +var X__fsmu8 = [51]uint32_t{ + func() uint32 { + if 0x2 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x2)) + }(), func() uint32 { + if 0x3 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x3)) + }(), func() uint32 { + if 0x4 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x4)) + }(), func() uint32 { + if 0x5 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x5)) + }(), func() uint32 { + if 0x6 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x6)) + }(), func() uint32 { + if 0x7 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x7)) + }(), + func() uint32 { + if 0x8 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x8)) + }(), func() uint32 { + if 0x9 < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0x9)) + }(), func() uint32 { + if 0xa < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xa)) + }(), func() uint32 { + if 0xb < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xb)) + }(), func() uint32 { + if 0xc < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xc)) + }(), func() uint32 { + if 0xd < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xd)) + }(), func() uint32 { + if 0xe < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xe)) + }(), func() uint32 { + if 0xf < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | uint32_t(0xf)) + }(), + func() uint32 { + if (0x0 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x0 + 16))) + }(), func() uint32 { + if (0x1 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x1 + 16))) + }(), func() uint32 { + if (0x2 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x2 + 16))) + }(), func() uint32 { + if (0x3 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x3 + 16))) + }(), func() uint32 { + if (0x4 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x4 + 16))) + }(), func() uint32 { + if (0x5 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x5 + 16))) + }(), func() uint32 { + if (0x6 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x6 + 16))) + }(), func() uint32 { + if (0x7 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x7 + 16))) + }(), + func() uint32 { + if (0x8 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x8 + 16))) + }(), func() uint32 { + if (0x9 + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0x9 + 16))) + }(), func() uint32 { + if (0xa + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xa + 16))) + }(), func() uint32 { + if (0xb + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xb + 16))) + }(), func() uint32 { + if (0xc + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xc + 16))) + }(), func() uint32 { + if (0xd + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xd + 16))) + }(), func() uint32 { + if (0xe + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xe + 16))) + }(), func() uint32 { + if (0xf + 16) < 2 { + return Uint32FromInt32(-1) + } + return (((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) | (uint32_t(0xf + 16))) + }(), + (((func() uint32 { + if 0x0 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x0 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x0)), (((func() uint32 { + if 0x1 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x1 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x1)), (((func() uint32 { + if 0x2 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x2 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x2)), (((func() uint32 { + if 0x3 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x3 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x3)), (((func() uint32 { + if 0x4 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x4 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x4)), (((func() uint32 { + if 0x5 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x5 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x5)), (((func() uint32 { + if 0x6 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x6 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x6)), (((func() uint32 { + if 0x7 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x7 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x7)), + (((func() uint32 { + if 0x8 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x8 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x8)), (((func() uint32 { + if 0x9 == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0x9 == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0x9)), (((func() uint32 { + if 0xa == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xa == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xa)), (((func() uint32 { + if 0xb == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xb == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xb)), (((func() uint32 { + if 0xc == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xc == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xc)), (((func() uint32 { + if 0xd == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xd == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xd)), (((func() uint32 { + if 0xe == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xe == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xe)), (((func() uint32 { + if 0xf == 0 { + return ((func() uint32 { + if Int32(0xa0) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0xa0))) + }()) << 23) + } + return func() uint32 { + if 0xf == 0xd { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xa0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | uint32_t(0xf)), + ((((func() uint32 { + if 0x0 >= 5 { + return uint32(0) + } + return func() uint32 { + if 0x0 == 0 { + return ((func() uint32 { + if Int32(0x90) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x90))) + }()) << 23) + } + return func() uint32 { + if 0x0 == 4 { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0x90))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 12)) | uint32_t(0x0)), ((((func() uint32 { + if 0x1 >= 5 { + return uint32(0) + } + return func() uint32 { + if 0x1 == 0 { + return ((func() uint32 { + if Int32(0x90) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x90))) + }()) << 23) + } + return func() uint32 { + if 0x1 == 4 { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0x90))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 12)) | uint32_t(0x1)), ((((func() uint32 { + if 0x2 >= 5 { + return uint32(0) + } + return func() uint32 { + if 0x2 == 0 { + return ((func() uint32 { + if Int32(0x90) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x90))) + }()) << 23) + } + return func() uint32 { + if 0x2 == 4 { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0x90))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 12)) | uint32_t(0x2)), ((((func() uint32 { + if 0x3 >= 5 { + return uint32(0) + } + return func() uint32 { + if 0x3 == 0 { + return ((func() uint32 { + if Int32(0x90) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x90))) + }()) << 23) + } + return func() uint32 { + if 0x3 == 4 { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0x90))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 12)) | uint32_t(0x3)), ((((func() uint32 { + if 0x4 >= 5 { + return uint32(0) + } + return func() uint32 { + if 0x4 == 0 { + return ((func() uint32 { + if Int32(0x90) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x90))) + }()) << 23) + } + return func() uint32 { + if 0x4 == 4 { + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0x90))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + } + return ((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23) + }() + }() + }()) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 6)) | (uint32_t(((func() uint32 { + if Int32(0x80) == Int32(0x80) { + return (Uint32(Uint32(0x40) - Uint32FromInt32(0xc0))) + } + return (Uint32(Uint32(0) - Uint32FromInt32(0x80))) + }()) << 23)) >> 12)) | uint32_t(0x4)), +} /* internal.c:18:16 */ + +type wint_t = uint32 /* alltypes.h:191:18 */ + +type wctype_t = uint32 /* alltypes.h:196:23 */ + +type __mbstate_t = struct { + __opaque1 uint32 + __opaque2 uint32 +} /* alltypes.h:330:9 */ + +type mbstate_t = __mbstate_t /* alltypes.h:330:63 */ + +func Xmbrtowc(tls *TLS, wc uintptr, src uintptr, n size_t, st uintptr) size_t { /* mbrtowc.c:6:8: */ + bp := tls.Alloc(4) + defer tls.Free(4) + + var c uint32 + var s uintptr + var N uint32 + // var dummy wchar_t at bp, 4 + s = src + N = n + + if !(!(st != 0)) { + goto __1 + } + st = uintptr(unsafe.Pointer(&_sinternal_state)) +__1: + ; + c = *(*uint32)(unsafe.Pointer(st)) + + if !(!(s != 0)) { + goto __2 + } + if !(c != 0) { + goto __4 + } + goto ilseq +__4: + ; + return size_t(0) + goto __3 +__2: + if !(!(wc != 0)) { + goto __5 + } + wc = bp /* &dummy */ +__5: + ; +__3: + ; + + if !(!(n != 0)) { + goto __6 + } + return Uint32FromInt32(-2) +__6: + ; + if !(!(c != 0)) { + goto __7 + } + if !(int32(*(*uint8)(unsafe.Pointer(s))) < 0x80) { + goto __8 + } + return BoolUint32(!(!(int32(AssignPtrUint32(wc, wchar_t(*(*uint8)(unsafe.Pointer(s))))) != 0))) +__8: + ; + if !((func() int32 { + if !(!(int32(*(*uintptr)(unsafe.Pointer(((*__pthread)(unsafe.Pointer(__pthread_self(tls))).locale /* &.cat */)))) != 0)) { + return 4 + } + return 1 + }()) == 1) { + goto __9 + } + *(*wchar_t)(unsafe.Pointer(wc)) = (wchar_t(0xdfff & int32((int8(*(*uint8)(unsafe.Pointer(s))))))) + return 1 +__9: + ; + if !((uint32(*(*uint8)(unsafe.Pointer(s))) - 0xc2) > (0xf4 - 0xc2)) { + goto __10 + } + goto ilseq +__10: + ; + c = X__fsmu8[(uint32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&s, 1)))) - 0xc2)] + n-- +__7: + ; + + if !(n != 0) { + goto __11 + } + if !((((((int32(*(*uint8)(unsafe.Pointer(s)))) >> 3) - 0x10) | (((int32(*(*uint8)(unsafe.Pointer(s)))) >> 3) + ((int32_t(c)) >> 26))) & CplInt32(7)) != 0) { + goto __12 + } + goto ilseq +__12: + ; +loop: + c = ((c << 6) | (uint32(int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&s, 1)))) - 0x80))) + n-- + if !(!((c & (uint32(1) << 31)) != 0)) { + goto __13 + } + *(*uint32)(unsafe.Pointer(st)) = uint32(0) + *(*wchar_t)(unsafe.Pointer(wc)) = c + return (N - n) +__13: + ; + if !(n != 0) { + goto __14 + } + if !((uint32(*(*uint8)(unsafe.Pointer(s))) - 0x80) >= uint32(0x40)) { + goto __15 + } + goto ilseq +__15: + ; + goto loop +__14: + ; +__11: + ; + + *(*uint32)(unsafe.Pointer(st)) = c + return Uint32FromInt32(-2) +ilseq: + *(*uint32)(unsafe.Pointer(st)) = uint32(0) + (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 84 + return Uint32FromInt32(-1) +} + +var _sinternal_state uint32 /* mbrtowc.c:8:18: */ + +func Xmbsinit(tls *TLS, st uintptr) int32 { /* mbsinit.c:3:5: */ + return (Bool32(!(st != 0) || !(int32(*(*uint32)(unsafe.Pointer(st))) != 0))) +} + +type imaxdiv_t = struct { + quot intmax_t + rem intmax_t +} /* inttypes.h:14:40 */ + +type socklen_t = uint32 /* alltypes.h:354:18 */ + +type sa_family_t = uint16 /* alltypes.h:359:24 */ + +type msghdr = struct { + msg_name uintptr + msg_namelen socklen_t + msg_iov uintptr + msg_iovlen int32 + msg_control uintptr + msg_controllen socklen_t + msg_flags int32 +} /* socket.h:22:1 */ + +type cmsghdr = struct { + cmsg_len socklen_t + cmsg_level int32 + cmsg_type int32 +} /* socket.h:44:1 */ + +type linger = struct { + l_onoff int32 + l_linger int32 +} /* socket.h:74:1 */ + +type sockaddr = struct { + sa_family sa_family_t + sa_data [14]int8 +} /* socket.h:367:1 */ + +type sockaddr_storage = struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 +} /* socket.h:372:1 */ + +type in_port_t = uint16_t /* in.h:12:18 */ +type in_addr_t = uint32_t /* in.h:13:18 */ +type in_addr = struct{ s_addr in_addr_t } /* in.h:14:1 */ + +type sockaddr_in = struct { + sin_family sa_family_t + sin_port in_port_t + sin_addr struct{ s_addr in_addr_t } + sin_zero [8]uint8_t +} /* in.h:16:1 */ + +type in6_addr = struct { + __in6_union struct { + _ [0]uint32 + __s6_addr [16]uint8_t + } +} /* in.h:23:1 */ + +type sockaddr_in6 = struct { + sin6_family sa_family_t + sin6_port in_port_t + sin6_flowinfo uint32_t + sin6_addr struct { + __in6_union struct { + _ [0]uint32 + __s6_addr [16]uint8_t + } + } + sin6_scope_id uint32_t +} /* in.h:34:1 */ + +type ipv6_mreq = struct { + ipv6mr_multiaddr struct { + __in6_union struct { + _ [0]uint32 + __s6_addr [16]uint8_t + } + } + ipv6mr_interface uint32 +} /* in.h:42:1 */ + +type ip_opts = struct { + ip_dst struct{ s_addr in_addr_t } + ip_opts [40]int8 +} /* in.h:229:1 */ + +type ip_mreq = struct { + imr_multiaddr struct{ s_addr in_addr_t } + imr_interface struct{ s_addr in_addr_t } +} /* in.h:247:1 */ + +type ip_mreqn = struct { + imr_multiaddr struct{ s_addr in_addr_t } + imr_address struct{ s_addr in_addr_t } + imr_ifindex int32 +} /* in.h:252:1 */ + +type ip_mreq_source = struct { + imr_multiaddr struct{ s_addr in_addr_t } + imr_interface struct{ s_addr in_addr_t } + imr_sourceaddr struct{ s_addr in_addr_t } +} /* in.h:258:1 */ + +type ip_msfilter = struct { + imsf_multiaddr struct{ s_addr in_addr_t } + imsf_interface struct{ s_addr in_addr_t } + imsf_fmode uint32_t + imsf_numsrc uint32_t + imsf_slist [1]struct{ s_addr in_addr_t } +} /* in.h:264:1 */ + +type group_req = struct { + gr_interface uint32_t + gr_group struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 + } +} /* in.h:275:1 */ + +type group_source_req = struct { + gsr_interface uint32_t + gsr_group struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 + } + gsr_source struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 + } +} /* in.h:280:1 */ + +type group_filter = struct { + gf_interface uint32_t + gf_group struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 + } + gf_fmode uint32_t + gf_numsrc uint32_t + gf_slist [1]struct { + ss_family sa_family_t + __ss_padding [122]int8 + __ss_align uint32 + } +} /* in.h:286:1 */ + +type in_pktinfo = struct { + ipi_ifindex int32 + ipi_spec_dst struct{ s_addr in_addr_t } + ipi_addr struct{ s_addr in_addr_t } +} /* in.h:297:1 */ + +type in6_pktinfo = struct { + ipi6_addr struct { + __in6_union struct { + _ [0]uint32 + __s6_addr [16]uint8_t + } + } + ipi6_ifindex uint32 +} /* in.h:303:1 */ + +type ip6_mtuinfo = struct { + ip6m_addr struct { + sin6_family sa_family_t + sin6_port in_port_t + sin6_flowinfo uint32_t + sin6_addr struct { + __in6_union struct { + _ [0]uint32 + __s6_addr [16]uint8_t + } + } + sin6_scope_id uint32_t + } + ip6m_mtu uint32_t +} /* in.h:308:1 */ + +type addrinfo = struct { + ai_flags int32 + ai_family int32 ai_socktype int32 ai_protocol int32 ai_addrlen socklen_t @@ -2085,1893 +3634,2772 @@ type addrinfo = struct { ai_next uintptr } /* netdb.h:16:1 */ -// Legacy functions follow (marked OBsolete in SUS) +// Legacy functions follow (marked OBsolete in SUS) + +type netent = struct { + n_name uintptr + n_aliases uintptr + n_addrtype int32 + n_net uint32_t +} /* netdb.h:62:1 */ + +type hostent = struct { + h_name uintptr + h_aliases uintptr + h_addrtype int32 + h_length int32 + h_addr_list uintptr +} /* netdb.h:69:1 */ + +type servent = struct { + s_name uintptr + s_aliases uintptr + s_port int32 + s_proto uintptr +} /* netdb.h:78:1 */ + +type protoent = struct { + p_name uintptr + p_aliases uintptr + p_proto int32 +} /* netdb.h:85:1 */ + +type aibuf = struct { + ai struct { + ai_flags int32 + ai_family int32 + ai_socktype int32 + ai_protocol int32 + ai_addrlen socklen_t + ai_addr uintptr + ai_canonname uintptr + ai_next uintptr + } + sa struct { + sin struct { + sin_family sa_family_t + sin_port in_port_t + sin_addr struct{ s_addr in_addr_t } + sin_zero [8]uint8_t + } + _ [12]byte + } + lock [1]int32 + slot int16 + ref int16 +} /* lookup.h:10:1 */ + +type sa = struct { + sin struct { + sin_family sa_family_t + sin_port in_port_t + sin_addr struct{ s_addr in_addr_t } + sin_zero [8]uint8_t + } + _ [12]byte +} /* lookup.h:10:1 */ + +type address = struct { + family int32 + scopeid uint32 + addr [16]uint8_t + sortkey int32 +} /* lookup.h:20:1 */ + +type service = struct { + port uint16_t + proto uint8 + socktype uint8 +} /* lookup.h:27:1 */ + +type resolvconf = struct { + ns [3]struct { + family int32 + scopeid uint32 + addr [16]uint8_t + sortkey int32 + } + nns uint32 + attempts uint32 + ndots uint32 + timeout uint32 +} /* lookup.h:34:1 */ + +func Xfreeaddrinfo(tls *TLS, p uintptr) { /* freeaddrinfo.c:7:6: */ + var cnt size_t + cnt = size_t(1) +__1: + if !((*addrinfo)(unsafe.Pointer(p)).ai_next != 0) { + goto __3 + } + goto __2 +__2: + cnt++ + p = (*addrinfo)(unsafe.Pointer(p)).ai_next + goto __1 + goto __3 +__3: + ; + var b uintptr = (p - uintptr((uint32((uintptr(0) /* &.ai */))))) + b -= 68 * (uintptr((*aibuf)(unsafe.Pointer(b)).slot)) + //TODO LOCK(b->lock); + if !(int32(AssignSubPtrInt16(b+66 /* &.ref */, int16(cnt))) != 0) { + Xfree(tls, b) + } + //TODO else UNLOCK(b->lock); +} + +func Xgetaddrinfo(tls *TLS, host uintptr, serv uintptr, hint uintptr, res uintptr) int32 { /* getaddrinfo.c:12:5: */ + bp := tls.Alloc(1608) + defer tls.Free(1608) + + // var ports [2]service at bp, 8 + + // var addrs [48]address at bp+8, 1344 + + // var canon [256]int8 at bp+1352, 256 + + var outcanon uintptr + var nservs int32 + var naddrs int32 + var nais int32 + var canon_len int32 + var i int32 + var j int32 + var k int32 + var family int32 = 0 + var flags int32 = 0 + var proto int32 = 0 + var socktype int32 = 0 + var out uintptr + + if !(host != 0) && !(serv != 0) { + return -2 + } -type netent = struct { - n_name uintptr - n_aliases uintptr - n_addrtype int32 - n_net uint32_t -} /* netdb.h:62:1 */ + if hint != 0 { + family = (*addrinfo)(unsafe.Pointer(hint)).ai_family + flags = (*addrinfo)(unsafe.Pointer(hint)).ai_flags + proto = (*addrinfo)(unsafe.Pointer(hint)).ai_protocol + socktype = (*addrinfo)(unsafe.Pointer(hint)).ai_socktype -type hostent = struct { - h_name uintptr - h_aliases uintptr - h_addrtype int32 - h_length int32 - h_addr_list uintptr -} /* netdb.h:69:1 */ + var mask int32 = ((((((0x01 | 0x02) | 0x04) | 0x08) | 0x10) | 0x20) | 0x400) + if (flags & mask) != flags { + return -1 + } -type servent = struct { - s_name uintptr - s_aliases uintptr - s_port int32 - s_proto uintptr -} /* netdb.h:78:1 */ + switch family { + case 2: + fallthrough + case 10: + fallthrough + case 0: + break + fallthrough + default: + return -6 + } + } -type protoent = struct { - p_name uintptr - p_aliases uintptr - p_proto int32 -} /* netdb.h:85:1 */ + if (flags & 0x20) != 0 { + Xabort(tls) //TODO- + // /* Define the "an address is configured" condition for address + // * families via ability to create a socket for the family plus + // * routability of the loopback address for the family. */ + // static const struct sockaddr_in lo4 = { + // .sin_family = AF_INET, .sin_port = 65535, + // .sin_addr.s_addr = __BYTE_ORDER == __BIG_ENDIAN + // ? 0x7f000001 : 0x0100007f + // }; + // static const struct sockaddr_in6 lo6 = { + // .sin6_family = AF_INET6, .sin6_port = 65535, + // .sin6_addr = IN6ADDR_LOOPBACK_INIT + // }; + // int tf[2] = { AF_INET, AF_INET6 }; + // const void *ta[2] = { &lo4, &lo6 }; + // socklen_t tl[2] = { sizeof lo4, sizeof lo6 }; + // for (i=0; i<2; i++) { + // if (family==tf[1-i]) continue; + // int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM, + // IPPROTO_UDP); + // if (s>=0) { + // int cs; + // pthread_setcancelstate( + // PTHREAD_CANCEL_DISABLE, &cs); + // int r = connect(s, ta[i], tl[i]); + // pthread_setcancelstate(cs, 0); + // close(s); + // if (!r) continue; + // } + // switch (errno) { + // case EADDRNOTAVAIL: + // case EAFNOSUPPORT: + // case EHOSTUNREACH: + // case ENETDOWN: + // case ENETUNREACH: + // break; + // default: + // return EAI_SYSTEM; + // } + // if (family == tf[i]) return EAI_NONAME; + // family = tf[1-i]; + // } + } -type aibuf = struct { - ai struct { - ai_flags int32 - ai_family int32 - ai_socktype int32 - ai_protocol int32 - ai_addrlen socklen_t - ai_addr uintptr - ai_canonname uintptr - ai_next uintptr + nservs = X__lookup_serv(tls, bp /* &ports[0] */, serv, proto, socktype, flags) + if nservs < 0 { + return nservs } - sa struct { - sin struct { - sin_family sa_family_t - sin_port in_port_t - sin_addr struct{ s_addr in_addr_t } - sin_zero [8]uint8_t + + naddrs = X__lookup_name(tls, bp+8 /* &addrs[0] */, bp+1352 /* &canon[0] */, host, family, flags) + if naddrs < 0 { + return naddrs + } + + nais = (nservs * naddrs) + canon_len = int32(Xstrlen(tls, bp+1352 /* &canon[0] */)) + out = Xcalloc(tls, uint32(1), (((uint32(nais) * uint32(unsafe.Sizeof(aibuf{}))) + uint32(canon_len)) + uint32(1))) + if !(out != 0) { + return -10 + } + + if canon_len != 0 { + outcanon = (out + uintptr(nais)*68) + Xmemcpy(tls, outcanon, bp+1352 /* &canon[0] */, (uint32(canon_len + 1))) + } else { + outcanon = uintptr(0) + } + + for k = AssignInt32(&i, 0); i < naddrs; i++ { + j = 0 + __1: + if !(j < nservs) { + goto __3 } - _ [12]byte + { + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).slot = int16(k) + //TODO out[k].ai = (struct addrinfo){ + //TODO .ai_family = addrs[i].family, + //TODO .ai_socktype = ports[j].socktype, + //TODO .ai_protocol = ports[j].proto, + //TODO .ai_addrlen = addrs[i].family == AF_INET + //TODO ? sizeof(struct sockaddr_in) + //TODO : sizeof(struct sockaddr_in6), + //TODO .ai_addr = (void *)&out[k].sa, + //TODO .ai_canonname = outcanon }; + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_family = (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).family + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_socktype = int32((*service)(unsafe.Pointer(bp /* &ports */ + uintptr(j)*4)).socktype) + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_protocol = int32((*service)(unsafe.Pointer(bp /* &ports */ + uintptr(j)*4)).proto) + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_addrlen = func() uint32 { + if (*address)(unsafe.Pointer(bp+8 /* &addrs */ +uintptr(i)*28)).family == 2 { + return uint32(unsafe.Sizeof(sockaddr_in{})) + } + return uint32(unsafe.Sizeof(sockaddr_in6{})) + }() + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_addr = (out + uintptr(k)*68 + 32 /* &.sa */) + (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_canonname = outcanon + if k != 0 { + (*aibuf)(unsafe.Pointer(out + uintptr((k-1))*68)).ai.ai_next = (out + uintptr(k)*68 /* &.ai */) + } + switch (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).family { + case 2: + (*sockaddr_in)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin_family = sa_family_t(2) + (*sockaddr_in)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin_port = Xhtons(tls, (*service)(unsafe.Pointer(bp /* &ports */ +uintptr(j)*4)).port) + Xmemcpy(tls, (out + uintptr(k)*68 + 32 /* &.sa */ /* &.sin */ + 4 /* &.sin_addr */), (bp + 8 /* &addrs */ + uintptr(i)*28 + 8 /* &.addr */), uint32(4)) + break + case 10: + (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_family = sa_family_t(10) + (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_port = Xhtons(tls, (*service)(unsafe.Pointer(bp /* &ports */ +uintptr(j)*4)).port) + (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_scope_id = (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).scopeid + Xmemcpy(tls, (out + uintptr(k)*68 + 32 /* &.sa */ /* &.sin6 */ + 8 /* &.sin6_addr */), (bp + 8 /* &addrs */ + uintptr(i)*28 + 8 /* &.addr */), uint32(16)) + break + } + + } + goto __2 + __2: + j++ + k++ + goto __1 + goto __3 + __3: } - lock [1]int32 - slot int16 - ref int16 -} /* lookup.h:10:1 */ + (*aibuf)(unsafe.Pointer(out)).ref = int16(nais) + *(*uintptr)(unsafe.Pointer(res)) = (out /* &.ai */) + return 0 +} -type sa = struct { - sin struct { - sin_family sa_family_t - sin_port in_port_t - sin_addr struct{ s_addr in_addr_t } - sin_zero [8]uint8_t +type ucred = struct { + pid pid_t + uid uid_t + gid gid_t +} /* socket.h:57:1 */ + +type mmsghdr = struct { + msg_hdr struct { + msg_name uintptr + msg_namelen socklen_t + msg_iov uintptr + msg_iovlen int32 + msg_control uintptr + msg_controllen socklen_t + msg_flags int32 + } + msg_len uint32 +} /* socket.h:63:1 */ + +func Xgethostbyaddr(tls *TLS, a uintptr, l socklen_t, af int32) uintptr { /* gethostbyaddr.c:7:16: */ + bp := tls.Alloc(4) + defer tls.Free(4) + + var size size_t = size_t(63) + // var res uintptr at bp, 4 + + var err int32 + for ok := true; ok; ok = (err == 34) { + Xfree(tls, _sh) + _sh = Xmalloc(tls, AssignAddUint32(&size, (size+size_t(1)))) + if !(_sh != 0) { + (*(*int32)(unsafe.Pointer(X__h_errno_location(tls)))) = 3 + return uintptr(0) + } + err = Xgethostbyaddr_r(tls, a, l, af, _sh, + (_sh + uintptr(1)*20), (size - size_t(unsafe.Sizeof(hostent{}))), bp /* &res */, X__h_errno_location(tls)) + } + if err != 0 { + return uintptr(0) + } + return _sh +} + +var _sh uintptr /* gethostbyaddr.c:9:24: */ + +func Xgethostbyaddr_r(tls *TLS, a uintptr, l socklen_t, af int32, h uintptr, buf uintptr, buflen size_t, res uintptr, err uintptr) int32 { /* gethostbyaddr_r.c:10:5: */ + bp := tls.Alloc(28) + defer tls.Free(28) + + //TODO union { + //TODO struct sockaddr_in sin; + //TODO struct sockaddr_in6 sin6; + //TODO } sa = { .sin.sin_family = af }; + *(*struct { + sin sockaddr_in + _ [12]byte + })(unsafe.Pointer(bp /* sa1 */)) = struct { + sin sockaddr_in + _ [12]byte + }{} //TODO- + (*sockaddr_in)(unsafe.Pointer(bp /* &sa1 */)).sin_family = sa_family_t(af) //TODO- + var sl socklen_t + if af == 10 { + sl = uint32(unsafe.Sizeof(sockaddr_in6{})) + } else { + sl = uint32(unsafe.Sizeof(sockaddr_in{})) } - _ [12]byte -} /* lookup.h:10:1 */ - -type address = struct { - family int32 - scopeid uint32 - addr [16]uint8_t - sortkey int32 -} /* lookup.h:20:1 */ + var i int32 -type service = struct { - port uint16_t - proto uint8 - socktype uint8 -} /* lookup.h:27:1 */ + *(*uintptr)(unsafe.Pointer(res)) = uintptr(0) -type resolvconf = struct { - ns [3]struct { - family int32 - scopeid uint32 - addr [16]uint8_t - sortkey int32 + // Load address argument into sockaddr structure + if (af == 10) && (l == socklen_t(16)) { + Xmemcpy(tls, (bp /* &sa1 */ /* &.sin6 */ + 8 /* &.sin6_addr */), a, uint32(16)) + } else if (af == 2) && (l == socklen_t(4)) { + Xmemcpy(tls, (bp /* &sa1 */ /* &.sin */ + 4 /* &.sin_addr */), a, uint32(4)) + } else { + *(*int32)(unsafe.Pointer(err)) = 3 + return 22 } - nns uint32 - attempts uint32 - ndots uint32 - timeout uint32 -} /* lookup.h:34:1 */ -func Xfreeaddrinfo(tls *TLS, p uintptr) { /* freeaddrinfo.c:7:6: */ - var cnt size_t - cnt = size_t(1) -__1: - if !((*addrinfo)(unsafe.Pointer(p)).ai_next != 0) { - goto __3 + // Align buffer and check for space for pointers and ip address + i = (int32(uintptr_t(buf) & (uint32(unsafe.Sizeof(uintptr(0))) - uint32(1)))) + if !(i != 0) { + i = int32(unsafe.Sizeof(uintptr(0))) } - goto __2 -__2: - cnt++ - p = (*addrinfo)(unsafe.Pointer(p)).ai_next - goto __1 - goto __3 -__3: - ; - var b uintptr = (p - uintptr((uint32((uintptr(0) /* &.ai */))))) - b -= 68 * (uintptr((*aibuf)(unsafe.Pointer(b)).slot)) - //TODO LOCK(b->lock); - if !(int32(AssignSubPtrInt16(b+66 /* &.ref */, int16(cnt))) != 0) { - Xfree(tls, b) + if buflen <= (((uint32(5) * uint32(unsafe.Sizeof(uintptr(0)))) - uint32(i)) + l) { + return 34 } - //TODO else UNLOCK(b->lock); -} - -type time_t = int64 /* alltypes.h:78:16 */ + buf += (uintptr(uint32(unsafe.Sizeof(uintptr(0))) - uint32(i))) + buflen = buflen - (((uint32(5) * uint32(unsafe.Sizeof(uintptr(0)))) - uint32(i)) + l) -type clockid_t = int32 /* alltypes.h:207:13 */ + (*hostent)(unsafe.Pointer(h)).h_addr_list = buf + buf += (uintptr(uint32(2) * uint32(unsafe.Sizeof(uintptr(0))))) + (*hostent)(unsafe.Pointer(h)).h_aliases = buf + buf += (uintptr(uint32(2) * uint32(unsafe.Sizeof(uintptr(0))))) -type timespec = struct { - tv_sec time_t - tv_nsec int32 - __12 uint32 /* int : 32 */ -} /* alltypes.h:222:1 */ + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)) = buf + Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)), a, l) + buf += uintptr(l) + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + 1*4)) = uintptr(0) + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases)) = buf + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = uintptr(0) -type pthread_t = uintptr /* alltypes.h:266:26 */ + switch Xgetnameinfo(tls, bp /* &sa1 */, sl, buf, buflen, uintptr(0), uint32(0), 0) { + case -3: + *(*int32)(unsafe.Pointer(err)) = 2 + return 11 + case -12: + return 34 + default: + fallthrough + case -10: + fallthrough + case -11: + fallthrough + case -4: + *(*int32)(unsafe.Pointer(err)) = 3 + return *(*int32)(unsafe.Pointer(X___errno_location(tls))) + case 0: + break + } -type pthread_once_t = int32 /* alltypes.h:272:13 */ + (*hostent)(unsafe.Pointer(h)).h_addrtype = af + (*hostent)(unsafe.Pointer(h)).h_length = int32(l) + (*hostent)(unsafe.Pointer(h)).h_name = *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases)) + *(*uintptr)(unsafe.Pointer(res)) = h + return 0 +} -type pthread_key_t = uint32 /* alltypes.h:277:18 */ +func Xgethostbyname(tls *TLS, name uintptr) uintptr { /* gethostbyname.c:8:16: */ + return Xgethostbyname2(tls, name, 2) +} -type pthread_spinlock_t = int32 /* alltypes.h:282:13 */ +func Xgethostbyname2(tls *TLS, name uintptr, af int32) uintptr { /* gethostbyname2.c:8:16: */ + bp := tls.Alloc(4) + defer tls.Free(4) -type pthread_mutexattr_t = struct{ __attr uint32 } /* alltypes.h:287:37 */ + var size size_t = size_t(63) + // var res uintptr at bp, 4 -type pthread_condattr_t = struct{ __attr uint32 } /* alltypes.h:292:37 */ + var err int32 + for ok := true; ok; ok = (err == 34) { + Xfree(tls, _sh1) + _sh1 = Xmalloc(tls, AssignAddUint32(&size, (size+size_t(1)))) + if !(_sh1 != 0) { + (*(*int32)(unsafe.Pointer(X__h_errno_location(tls)))) = 3 + return uintptr(0) + } + err = Xgethostbyname2_r(tls, name, af, _sh1, + (_sh1 + uintptr(1)*20), (size - size_t(unsafe.Sizeof(hostent{}))), bp /* &res */, X__h_errno_location(tls)) + } + if err != 0 { + return uintptr(0) + } + return _sh1 +} -type pthread_barrierattr_t = struct{ __attr uint32 } /* alltypes.h:297:37 */ +var _sh1 uintptr /* gethostbyname2.c:10:24: */ -type pthread_rwlockattr_t = struct{ __attr [2]uint32 } /* alltypes.h:302:40 */ +func Xgethostbyname2_r(tls *TLS, name uintptr, af int32, h uintptr, buf uintptr, buflen size_t, res uintptr, err uintptr) int32 { /* gethostbyname2_r.c:11:5: */ + bp := tls.Alloc(1600) + defer tls.Free(1600) -type __sigset_t = struct{ __bits [32]uint32 } /* alltypes.h:342:9 */ + // var addrs [48]address at bp, 1344 -type sigset_t = __sigset_t /* alltypes.h:342:71 */ + // var canon [256]int8 at bp+1344, 256 -type pthread_attr_t = struct{ __u struct{ __i [9]int32 } } /* alltypes.h:365:147 */ + var i int32 + var cnt int32 + var align size_t + var need size_t -type pthread_mutex_t = struct{ __u struct{ __i [6]int32 } } /* alltypes.h:370:157 */ + *(*uintptr)(unsafe.Pointer(res)) = uintptr(0) + cnt = X__lookup_name(tls, bp /* &addrs[0] */, bp+1344 /* &canon[0] */, name, af, 0x02) + if cnt < 0 { + switch cnt { + case -2: + *(*int32)(unsafe.Pointer(err)) = 1 + return 2 + fallthrough + case -3: + *(*int32)(unsafe.Pointer(err)) = 2 + return 11 + fallthrough + default: + fallthrough + case -4: + *(*int32)(unsafe.Pointer(err)) = 3 + return 74 + fallthrough + case -10: + fallthrough + case -11: + *(*int32)(unsafe.Pointer(err)) = 3 + return *(*int32)(unsafe.Pointer(X___errno_location(tls))) + } + } -type pthread_cond_t = struct{ __u struct{ __i [12]int32 } } /* alltypes.h:380:112 */ + (*hostent)(unsafe.Pointer(h)).h_addrtype = af + (*hostent)(unsafe.Pointer(h)).h_length = func() int32 { + if af == 10 { + return 16 + } + return 4 + }() -type pthread_rwlock_t = struct{ __u struct{ __i [8]int32 } } /* alltypes.h:390:139 */ + // Align buffer + align = (-uintptr_t(buf) & (uint32(unsafe.Sizeof(uintptr(0))) - uint32(1))) -type pthread_barrier_t = struct{ __u struct{ __i [5]int32 } } /* alltypes.h:395:137 */ + need = (uint32(4) * uint32(unsafe.Sizeof(uintptr(0)))) + need = need + ((uint32(cnt + 1)) * (uint32(unsafe.Sizeof(uintptr(0))) + uint32((*hostent)(unsafe.Pointer(h)).h_length))) + need = need + (Xstrlen(tls, name) + size_t(1)) + need = need + (Xstrlen(tls, bp+1344 /* &canon[0] */) + size_t(1)) + need = need + (align) -type sched_param = struct { - sched_priority int32 - __reserved1 int32 - __reserved2 [4]int32 - __reserved3 int32 -} /* sched.h:19:1 */ + if need > buflen { + return 34 + } -type timer_t = uintptr /* alltypes.h:202:14 */ + buf += uintptr(align) + (*hostent)(unsafe.Pointer(h)).h_aliases = buf + buf += (uintptr(uint32(3) * uint32(unsafe.Sizeof(uintptr(0))))) + (*hostent)(unsafe.Pointer(h)).h_addr_list = buf + buf += (uintptr((uint32(cnt + 1)) * uint32(unsafe.Sizeof(uintptr(0))))) -type clock_t = int32 /* alltypes.h:212:14 */ + for i = 0; i < cnt; i++ { + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)) = buf + buf += uintptr((*hostent)(unsafe.Pointer(h)).h_length) + Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)), bp /* &addrs */ +uintptr(i)*28+8 /* &.addr */, uint32((*hostent)(unsafe.Pointer(h)).h_length)) + } + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)) = uintptr(0) -type tm = struct { - tm_sec int32 - tm_min int32 - tm_hour int32 - tm_mday int32 - tm_mon int32 - tm_year int32 - tm_wday int32 - tm_yday int32 - tm_isdst int32 - tm_gmtoff int32 - tm_zone uintptr -} /* time.h:38:1 */ + (*hostent)(unsafe.Pointer(h)).h_name = AssignPtrUintptr((*hostent)(unsafe.Pointer(h)).h_aliases, buf) + Xstrcpy(tls, (*hostent)(unsafe.Pointer(h)).h_name, bp+1344 /* &canon[0] */) + buf += (uintptr(Xstrlen(tls, (*hostent)(unsafe.Pointer(h)).h_name) + size_t(1))) -type itimerspec = struct { - it_interval struct { - tv_sec time_t - tv_nsec int32 - __12 uint32 /* int : 32 */ - } - it_value struct { - tv_sec time_t - tv_nsec int32 - __12 uint32 /* int : 32 */ + if Xstrcmp(tls, (*hostent)(unsafe.Pointer(h)).h_name, name) != 0 { + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = buf + Xstrcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)), name) + buf += (uintptr(Xstrlen(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4))) + size_t(1))) + } else { + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = uintptr(0) } -} /* time.h:80:1 */ -type __ptcb = struct { - __f uintptr - __x uintptr - __next uintptr -} /* pthread.h:206:1 */ + *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 2*4)) = uintptr(0) -func Xgetaddrinfo(tls *TLS, host uintptr, serv uintptr, hint uintptr, res uintptr) int32 { /* getaddrinfo.c:12:5: */ - bp := tls.Alloc(1608) - defer tls.Free(1608) + *(*uintptr)(unsafe.Pointer(res)) = h + return 0 +} - // var ports [2]service at bp, 8 +func Xgethostbyname_r(tls *TLS, name uintptr, h uintptr, buf uintptr, buflen size_t, res uintptr, err uintptr) int32 { /* gethostbyname_r.c:6:5: */ + return Xgethostbyname2_r(tls, name, 2, h, buf, buflen, res, err) +} - // var addrs [48]address at bp+8, 1344 +type if_nameindex = struct { + if_index uint32 + if_name uintptr +} /* if.h:12:1 */ - // var canon [256]int8 at bp+1352, 256 +type ifaddr = struct { + ifa_addr struct { + sa_family sa_family_t + sa_data [14]int8 + } + ifa_ifu struct { + ifu_broadaddr struct { + sa_family sa_family_t + sa_data [14]int8 + } + } + ifa_ifp uintptr + ifa_next uintptr +} /* if.h:51:1 */ - var outcanon uintptr - var nservs int32 - var naddrs int32 - var nais int32 - var canon_len int32 - var i int32 - var j int32 - var k int32 - var family int32 = 0 - var flags int32 = 0 - var proto int32 = 0 - var socktype int32 = 0 - var out uintptr +type ifmap = struct { + mem_start uint32 + mem_end uint32 + base_addr uint16 + irq uint8 + dma uint8 + port uint8 + _ [3]byte +} /* if.h:64:1 */ - if !(host != 0) && !(serv != 0) { - return -2 +type ifreq = struct { + ifr_ifrn struct{ ifrn_name [16]int8 } + ifr_ifru struct { + _ [0]uint32 + ifru_addr struct { + sa_family sa_family_t + sa_data [14]int8 + } } +} /* if.h:76:1 */ - if hint != 0 { - family = (*addrinfo)(unsafe.Pointer(hint)).ai_family - flags = (*addrinfo)(unsafe.Pointer(hint)).ai_flags - proto = (*addrinfo)(unsafe.Pointer(hint)).ai_protocol - socktype = (*addrinfo)(unsafe.Pointer(hint)).ai_socktype +type ifconf = struct { + ifc_len int32 + ifc_ifcu struct{ ifcu_buf uintptr } +} /* if.h:116:1 */ - var mask int32 = ((((((0x01 | 0x02) | 0x04) | 0x08) | 0x10) | 0x20) | 0x400) - if (flags & mask) != flags { - return -1 - } +type ns_sect = uint32 /* nameser.h:37:3 */ - switch family { - case 2: - fallthrough - case 10: - fallthrough - case 0: - break - fallthrough - default: - return -6 - } - } +type __ns_msg = struct { + _msg uintptr + _eom uintptr + _id uint16_t + _flags uint16_t + _counts [4]uint16_t + _sections [4]uintptr + _sect ns_sect + _rrnum int32 + _msg_ptr uintptr +} /* nameser.h:39:9 */ - if (flags & 0x20) != 0 { - Xabort(tls) //TODO- - // /* Define the "an address is configured" condition for address - // * families via ability to create a socket for the family plus - // * routability of the loopback address for the family. */ - // static const struct sockaddr_in lo4 = { - // .sin_family = AF_INET, .sin_port = 65535, - // .sin_addr.s_addr = __BYTE_ORDER == __BIG_ENDIAN - // ? 0x7f000001 : 0x0100007f - // }; - // static const struct sockaddr_in6 lo6 = { - // .sin6_family = AF_INET6, .sin6_port = 65535, - // .sin6_addr = IN6ADDR_LOOPBACK_INIT - // }; - // int tf[2] = { AF_INET, AF_INET6 }; - // const void *ta[2] = { &lo4, &lo6 }; - // socklen_t tl[2] = { sizeof lo4, sizeof lo6 }; - // for (i=0; i<2; i++) { - // if (family==tf[1-i]) continue; - // int s = socket(tf[i], SOCK_CLOEXEC|SOCK_DGRAM, - // IPPROTO_UDP); - // if (s>=0) { - // int cs; - // pthread_setcancelstate( - // PTHREAD_CANCEL_DISABLE, &cs); - // int r = connect(s, ta[i], tl[i]); - // pthread_setcancelstate(cs, 0); - // close(s); - // if (!r) continue; - // } - // switch (errno) { - // case EADDRNOTAVAIL: - // case EAFNOSUPPORT: - // case EHOSTUNREACH: - // case ENETDOWN: - // case ENETUNREACH: - // break; - // default: - // return EAI_SYSTEM; - // } - // if (family == tf[i]) return EAI_NONAME; - // family = tf[1-i]; - // } - } +type ns_msg = __ns_msg /* nameser.h:46:3 */ - nservs = X__lookup_serv(tls, bp /* &ports[0] */, serv, proto, socktype, flags) - if nservs < 0 { - return nservs - } +type _ns_flagdata = struct { + mask int32 + shift int32 +} /* nameser.h:48:1 */ - naddrs = X__lookup_name(tls, bp+8 /* &addrs[0] */, bp+1352 /* &canon[0] */, host, family, flags) - if naddrs < 0 { - return naddrs - } +type __ns_rr = struct { + name [1025]int8 + _ [1]byte + __type uint16_t + rr_class uint16_t + _ [2]byte + ttl uint32_t + rdlength uint16_t + _ [2]byte + rdata uintptr +} /* nameser.h:59:9 */ - nais = (nservs * naddrs) - canon_len = int32(Xstrlen(tls, bp+1352 /* &canon[0] */)) - out = Xcalloc(tls, uint32(1), (((uint32(nais) * uint32(unsafe.Sizeof(aibuf{}))) + uint32(canon_len)) + uint32(1))) - if !(out != 0) { - return -10 - } +type ns_rr = __ns_rr /* nameser.h:66:3 */ - if canon_len != 0 { - outcanon = (out + uintptr(nais)*68) - Xmemcpy(tls, outcanon, bp+1352 /* &canon[0] */, (uint32(canon_len + 1))) - } else { - outcanon = uintptr(0) - } +type ns_flag = uint32 /* nameser.h:87:3 */ - for k = AssignInt32(&i, 0); i < naddrs; i++ { - j = 0 - __1: - if !(j < nservs) { - goto __3 - } - { - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).slot = int16(k) - //TODO out[k].ai = (struct addrinfo){ - //TODO .ai_family = addrs[i].family, - //TODO .ai_socktype = ports[j].socktype, - //TODO .ai_protocol = ports[j].proto, - //TODO .ai_addrlen = addrs[i].family == AF_INET - //TODO ? sizeof(struct sockaddr_in) - //TODO : sizeof(struct sockaddr_in6), - //TODO .ai_addr = (void *)&out[k].sa, - //TODO .ai_canonname = outcanon }; - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_family = (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).family - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_socktype = int32((*service)(unsafe.Pointer(bp /* &ports */ + uintptr(j)*4)).socktype) - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_protocol = int32((*service)(unsafe.Pointer(bp /* &ports */ + uintptr(j)*4)).proto) - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_addrlen = func() uint32 { - if (*address)(unsafe.Pointer(bp+8 /* &addrs */ +uintptr(i)*28)).family == 2 { - return uint32(unsafe.Sizeof(sockaddr_in{})) - } - return uint32(unsafe.Sizeof(sockaddr_in6{})) - }() - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_addr = (out + uintptr(k)*68 + 32 /* &.sa */) - (*aibuf)(unsafe.Pointer(out + uintptr(k)*68)).ai.ai_canonname = outcanon - if k != 0 { - (*aibuf)(unsafe.Pointer(out + uintptr((k-1))*68)).ai.ai_next = (out + uintptr(k)*68 /* &.ai */) - } - switch (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).family { - case 2: - (*sockaddr_in)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin_family = sa_family_t(2) - (*sockaddr_in)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin_port = Xhtons(tls, (*service)(unsafe.Pointer(bp /* &ports */ +uintptr(j)*4)).port) - Xmemcpy(tls, (out + uintptr(k)*68 + 32 /* &.sa */ /* &.sin */ + 4 /* &.sin_addr */), (bp + 8 /* &addrs */ + uintptr(i)*28 + 8 /* &.addr */), uint32(4)) - break - case 10: - (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_family = sa_family_t(10) - (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_port = Xhtons(tls, (*service)(unsafe.Pointer(bp /* &ports */ +uintptr(j)*4)).port) - (*sockaddr_in6)(unsafe.Pointer(out + uintptr(k)*68 + 32 /* &.sa */)).sin6_scope_id = (*address)(unsafe.Pointer(bp + 8 /* &addrs */ + uintptr(i)*28)).scopeid - Xmemcpy(tls, (out + uintptr(k)*68 + 32 /* &.sa */ /* &.sin6 */ + 8 /* &.sin6_addr */), (bp + 8 /* &addrs */ + uintptr(i)*28 + 8 /* &.addr */), uint32(16)) - break - } +type ns_opcode = uint32 /* nameser.h:96:3 */ - } - goto __2 - __2: - j++ - k++ - goto __1 - goto __3 - __3: - } - (*aibuf)(unsafe.Pointer(out)).ref = int16(nais) - *(*uintptr)(unsafe.Pointer(res)) = (out /* &.ai */) - return 0 -} +type ns_rcode = uint32 /* nameser.h:115:3 */ -type ucred = struct { - pid pid_t - uid uid_t - gid gid_t -} /* socket.h:57:1 */ +type ns_update_operation = uint32 /* nameser.h:121:3 */ + +type ns_tsig_key1 = struct { + name [1025]int8 + alg [1025]int8 + _ [2]byte + data uintptr + len int32 +} /* nameser.h:123:1 */ -type mmsghdr = struct { - msg_hdr struct { - msg_name uintptr - msg_namelen socklen_t - msg_iov uintptr - msg_iovlen int32 - msg_control uintptr - msg_controllen socklen_t - msg_flags int32 - } - msg_len uint32 -} /* socket.h:63:1 */ +type ns_tsig_key = ns_tsig_key1 /* nameser.h:128:28 */ -func Xgethostbyaddr(tls *TLS, a uintptr, l socklen_t, af int32) uintptr { /* gethostbyaddr.c:7:16: */ - bp := tls.Alloc(4) - defer tls.Free(4) +type ns_tcp_tsig_state1 = struct { + counter int32 + key uintptr + ctx uintptr + sig [512]uint8 + siglen int32 +} /* nameser.h:130:1 */ - var size size_t = size_t(63) - // var res uintptr at bp, 4 +type ns_tcp_tsig_state = ns_tcp_tsig_state1 /* nameser.h:137:34 */ - var err int32 - for ok := true; ok; ok = (err == 34) { - Xfree(tls, _sh) - _sh = Xmalloc(tls, AssignAddUint32(&size, (size+size_t(1)))) - if !(_sh != 0) { - (*(*int32)(unsafe.Pointer(X__h_errno_location(tls)))) = 3 - return uintptr(0) - } - err = Xgethostbyaddr_r(tls, a, l, af, _sh, - (_sh + uintptr(1)*20), (size - size_t(unsafe.Sizeof(hostent{}))), bp /* &res */, X__h_errno_location(tls)) - } - if err != 0 { - return uintptr(0) - } - return _sh -} +type ns_type = uint32 /* nameser.h:200:3 */ -var _sh uintptr /* gethostbyaddr.c:9:24: */ +type ns_class = uint32 /* nameser.h:219:3 */ -func Xgethostbyaddr_r(tls *TLS, a uintptr, l socklen_t, af int32, h uintptr, buf uintptr, buflen size_t, res uintptr, err uintptr) int32 { /* gethostbyaddr_r.c:10:5: */ - bp := tls.Alloc(28) - defer tls.Free(28) +type ns_key_types = uint32 /* nameser.h:226:3 */ - //TODO union { - //TODO struct sockaddr_in sin; - //TODO struct sockaddr_in6 sin6; - //TODO } sa = { .sin.sin_family = af }; - *(*struct { - sin sockaddr_in - _ [12]byte - })(unsafe.Pointer(bp /* sa1 */)) = struct { - sin sockaddr_in - _ [12]byte - }{} //TODO- - (*sockaddr_in)(unsafe.Pointer(bp /* &sa1 */)).sin_family = sa_family_t(af) //TODO- - var sl socklen_t - if af == 10 { - sl = uint32(unsafe.Sizeof(sockaddr_in6{})) - } else { - sl = uint32(unsafe.Sizeof(sockaddr_in{})) - } - var i int32 +type ns_cert_types = uint32 /* nameser.h:234:3 */ - *(*uintptr)(unsafe.Pointer(res)) = uintptr(0) +type HEADER = struct { + _ [0]uint32 + id uint32 /* unsigned id: 16, unsigned rd: 1, unsigned tc: 1, unsigned aa: 1, unsigned opcode: 4, unsigned qr: 1, unsigned rcode: 4, unsigned cd: 1, unsigned ad: 1, unsigned unused: 1, unsigned ra: 1 */ + qdcount uint32 /* unsigned qdcount: 16, unsigned ancount: 16 */ + nscount uint32 /* unsigned nscount: 16, unsigned arcount: 16 */ +} /* nameser.h:353:3 */ - // Load address argument into sockaddr structure - if (af == 10) && (l == socklen_t(16)) { - Xmemcpy(tls, (bp /* &sa1 */ /* &.sin6 */ + 8 /* &.sin6_addr */), a, uint32(16)) - } else if (af == 2) && (l == socklen_t(4)) { - Xmemcpy(tls, (bp /* &sa1 */ /* &.sin */ + 4 /* &.sin_addr */), a, uint32(4)) - } else { - *(*int32)(unsafe.Pointer(err)) = 3 - return 22 +// unused; purely for broken apps +type __res_state = struct { + retrans int32 + retry int32 + options uint32 + nscount int32 + nsaddr_list [3]struct { + sin_family sa_family_t + sin_port in_port_t + sin_addr struct{ s_addr in_addr_t } + sin_zero [8]uint8_t } - - // Align buffer and check for space for pointers and ip address - i = (int32(uintptr_t(buf) & (uint32(unsafe.Sizeof(uintptr(0))) - uint32(1)))) - if !(i != 0) { - i = int32(unsafe.Sizeof(uintptr(0))) + id uint16 + _ [2]byte + dnsrch [7]uintptr + defdname [256]int8 + pfcode uint32 + ndots uint32 /* unsigned ndots: 4, unsigned nsort: 4, unsigned ipv6_unavail: 1, unsigned unused: 23 */ + _ [4]byte + sort_list [10]struct { + addr struct{ s_addr in_addr_t } + mask uint32_t } - if buflen <= (((uint32(5) * uint32(unsafe.Sizeof(uintptr(0)))) - uint32(i)) + l) { - return 34 + qhook uintptr + rhook uintptr + res_h_errno int32 + _vcsock int32 + _flags uint32 + _u struct { + _ [0]uint32 + pad [52]int8 } - buf += (uintptr(uint32(unsafe.Sizeof(uintptr(0))) - uint32(i))) - buflen = buflen - (((uint32(5) * uint32(unsafe.Sizeof(uintptr(0)))) - uint32(i)) + l) +} /* resolv.h:26:9 */ - (*hostent)(unsafe.Pointer(h)).h_addr_list = buf - buf += (uintptr(uint32(2) * uint32(unsafe.Sizeof(uintptr(0))))) - (*hostent)(unsafe.Pointer(h)).h_aliases = buf - buf += (uintptr(uint32(2) * uint32(unsafe.Sizeof(uintptr(0))))) +// unused; purely for broken apps +type res_state = uintptr /* resolv.h:62:3 */ - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)) = buf - Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)), a, l) - buf += uintptr(l) - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + 1*4)) = uintptr(0) - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases)) = buf - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = uintptr(0) +type res_sym = struct { + number int32 + name uintptr + humanname uintptr +} /* resolv.h:70:1 */ - switch Xgetnameinfo(tls, bp /* &sa1 */, sl, buf, buflen, uintptr(0), uint32(0), 0) { - case -3: - *(*int32)(unsafe.Pointer(err)) = 2 - return 11 - case -12: - return 34 - default: - fallthrough - case -10: - fallthrough - case -11: - fallthrough - case -4: - *(*int32)(unsafe.Pointer(err)) = 3 - return *(*int32)(unsafe.Pointer(X___errno_location(tls))) - case 0: - break +func itoa(tls *TLS, p uintptr, x uint32) uintptr { /* getnameinfo.c:18:13: */ + p += (uintptr(uint32(3) * uint32(unsafe.Sizeof(int32(0))))) + *(*int8)(unsafe.Pointer(PreDecUintptr(&p, 1))) = int8(0) + for ok := true; ok; ok = x != 0 { + *(*int8)(unsafe.Pointer(PreDecUintptr(&p, 1))) = (int8(uint32('0') + (x % uint32(10)))) + x = x / (uint32(10)) } - - (*hostent)(unsafe.Pointer(h)).h_addrtype = af - (*hostent)(unsafe.Pointer(h)).h_length = int32(l) - (*hostent)(unsafe.Pointer(h)).h_name = *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases)) - *(*uintptr)(unsafe.Pointer(res)) = h - return 0 -} - -func Xgethostbyname(tls *TLS, name uintptr) uintptr { /* gethostbyname.c:8:16: */ - return Xgethostbyname2(tls, name, 2) + return p } -func Xgethostbyname2(tls *TLS, name uintptr, af int32) uintptr { /* gethostbyname2.c:8:16: */ - bp := tls.Alloc(4) - defer tls.Free(4) +func mkptr4(tls *TLS, s uintptr, ip uintptr) { /* getnameinfo.c:28:13: */ + bp := tls.Alloc(32) + defer tls.Free(32) - var size size_t = size_t(63) - // var res uintptr at bp, 4 + Xsprintf(tls, s, ts+23, /* "%d.%d.%d.%d.in-a..." */ + VaList(bp, int32(*(*uint8)(unsafe.Pointer(ip + 3))), int32(*(*uint8)(unsafe.Pointer(ip + 2))), int32(*(*uint8)(unsafe.Pointer(ip + 1))), int32(*(*uint8)(unsafe.Pointer(ip))))) +} - var err int32 - for ok := true; ok; ok = (err == 34) { - Xfree(tls, _sh1) - _sh1 = Xmalloc(tls, AssignAddUint32(&size, (size+size_t(1)))) - if !(_sh1 != 0) { - (*(*int32)(unsafe.Pointer(X__h_errno_location(tls)))) = 3 - return uintptr(0) - } - err = Xgethostbyname2_r(tls, name, af, _sh1, - (_sh1 + uintptr(1)*20), (size - size_t(unsafe.Sizeof(hostent{}))), bp /* &res */, X__h_errno_location(tls)) - } - if err != 0 { - return uintptr(0) +func mkptr6(tls *TLS, s uintptr, ip uintptr) { /* getnameinfo.c:34:13: */ + var i int32 + for i = 15; i >= 0; i-- { + *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = _sxdigits[(int32(*(*uint8)(unsafe.Pointer(ip + uintptr(i)))) & 15)] + *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8('.') + *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = _sxdigits[(int32(*(*uint8)(unsafe.Pointer(ip + uintptr(i)))) >> 4)] + *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8('.') } - return _sh1 + Xstrcpy(tls, s, ts+48 /* "ip6.arpa" */) } -var _sh1 uintptr /* gethostbyname2.c:10:24: */ +var _sxdigits = *(*[17]int8)(unsafe.Pointer(ts + 57 /* "0123456789abcdef" */)) /* getnameinfo.c:36:20 */ -func Xgethostbyname2_r(tls *TLS, name uintptr, af int32, h uintptr, buf uintptr, buflen size_t, res uintptr, err uintptr) int32 { /* gethostbyname2_r.c:11:5: */ - bp := tls.Alloc(1600) - defer tls.Free(1600) +func reverse_hosts(tls *TLS, buf uintptr, a uintptr, scopeid uint32, family int32) { /* getnameinfo.c:45:13: */ + bp := tls.Alloc(556) + defer tls.Free(556) - // var addrs [48]address at bp, 1344 + // var line [512]int8 at bp+16, 512 - // var canon [256]int8 at bp+1344, 256 + var p uintptr + var z uintptr + var _buf [1032]uint8 + _ = _buf + // var atmp [16]uint8 at bp, 16 - var i int32 - var cnt int32 - var align size_t - var need size_t + // var iplit address at bp+528, 28 - *(*uintptr)(unsafe.Pointer(res)) = uintptr(0) - cnt = X__lookup_name(tls, bp /* &addrs[0] */, bp+1344 /* &canon[0] */, name, af, 0x02) - if cnt < 0 { - switch cnt { - case -2: - *(*int32)(unsafe.Pointer(err)) = 1 - return 2 - fallthrough - case -3: - *(*int32)(unsafe.Pointer(err)) = 2 - return 11 - fallthrough - default: - fallthrough - case -4: - *(*int32)(unsafe.Pointer(err)) = 3 - return 74 - fallthrough - case -10: - fallthrough - case -11: - *(*int32)(unsafe.Pointer(err)) = 3 - return *(*int32)(unsafe.Pointer(X___errno_location(tls))) - } + //TODO FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); + var f uintptr = Xfopen(tls, ts+74 /* "/etc/hosts" */, ts+85 /* "rb" */) + if !(f != 0) { + return + } + if family == 2 { + Xmemcpy(tls, (bp /* &atmp[0] */ + uintptr(12)), a, uint32(4)) + Xmemcpy(tls, bp /* &atmp[0] */, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) + a = bp /* &atmp[0] */ } + for Xfgets(tls, bp+16 /* &line[0] */, int32(unsafe.Sizeof([512]int8{})), f) != 0 { + if AssignUintptr(&p, Xstrchr(tls, bp+16 /* &line[0] */, '#')) != 0 { + *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8('\n') + *(*int8)(unsafe.Pointer(p)) = int8(0) + } - (*hostent)(unsafe.Pointer(h)).h_addrtype = af - (*hostent)(unsafe.Pointer(h)).h_length = func() int32 { - if af == 10 { - return 16 + for p = bp + 16; /* &line[0] */ (*(*int8)(unsafe.Pointer(p)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + } + *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8(0) + if X__lookup_ipliteral(tls, bp+528 /* &iplit */, bp+16 /* &line[0] */, 0) <= 0 { + continue } - return 4 - }() - // Align buffer - align = (-uintptr_t(buf) & (uint32(unsafe.Sizeof(uintptr(0))) - uint32(1))) + if (*address)(unsafe.Pointer(bp+528 /* &iplit */)).family == 2 { + Xmemcpy(tls, ((bp + 528 /* &iplit */ + 8 /* &.addr */) + uintptr(12)), bp+528 /* &iplit */ +8 /* &.addr */, uint32(4)) + Xmemcpy(tls, bp+528 /* &iplit */ +8 /* &.addr */, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) + (*address)(unsafe.Pointer(bp + 528 /* &iplit */)).scopeid = uint32(0) + } - need = (uint32(4) * uint32(unsafe.Sizeof(uintptr(0)))) - need = need + ((uint32(cnt + 1)) * (uint32(unsafe.Sizeof(uintptr(0))) + uint32((*hostent)(unsafe.Pointer(h)).h_length))) - need = need + (Xstrlen(tls, name) + size_t(1)) - need = need + (Xstrlen(tls, bp+1344 /* &canon[0] */) + size_t(1)) - need = need + (align) + if (Xmemcmp(tls, a, bp+528 /* &iplit */ +8 /* &.addr */, uint32(16)) != 0) || ((*address)(unsafe.Pointer(bp+528 /* &iplit */)).scopeid != scopeid) { + continue + } - if need > buflen { - return 34 + for ; (*(*int8)(unsafe.Pointer(p)) != 0) && (__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + } + for z = p; (*(*int8)(unsafe.Pointer(z)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(z)))) != 0); z++ { + } + *(*int8)(unsafe.Pointer(z)) = int8(0) + if ((int32(z) - int32(p)) / 1) < 256 { + Xmemcpy(tls, buf, p, (uint32(((int32(z) - int32(p)) / 1) + 1))) + break + } } + //TODO __fclose_ca(f); + Xfclose(tls, f) +} - buf += uintptr(align) - (*hostent)(unsafe.Pointer(h)).h_aliases = buf - buf += (uintptr(uint32(3) * uint32(unsafe.Sizeof(uintptr(0))))) - (*hostent)(unsafe.Pointer(h)).h_addr_list = buf - buf += (uintptr((uint32(cnt + 1)) * uint32(unsafe.Sizeof(uintptr(0))))) +func reverse_services(tls *TLS, buf uintptr, port int32, dgram int32) { /* getnameinfo.c:87:13: */ + Xabort(tls) //TODO- + // unsigned long svport; + // char line[128], *p, *z; + // unsigned char _buf[1032]; + // FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); + // if (!f) return; + // while (fgets(line, sizeof line, f)) { + // if ((p=strchr(line, '#'))) *p++='\n', *p=0; - for i = 0; i < cnt; i++ { - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)) = buf - buf += uintptr((*hostent)(unsafe.Pointer(h)).h_length) - Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)), bp /* &addrs */ +uintptr(i)*28+8 /* &.addr */, uint32((*hostent)(unsafe.Pointer(h)).h_length)) - } - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + uintptr(i)*4)) = uintptr(0) + // for (p=line; *p && !isspace(*p); p++); + // if (!*p) continue; + // *p++ = 0; + // svport = strtoul(p, &z, 10); - (*hostent)(unsafe.Pointer(h)).h_name = AssignPtrUintptr((*hostent)(unsafe.Pointer(h)).h_aliases, buf) - Xstrcpy(tls, (*hostent)(unsafe.Pointer(h)).h_name, bp+1344 /* &canon[0] */) - buf += (uintptr(Xstrlen(tls, (*hostent)(unsafe.Pointer(h)).h_name) + size_t(1))) + // if (svport != port || z==p) continue; + // if (dgram && strncmp(z, "/udp", 4)) continue; + // if (!dgram && strncmp(z, "/tcp", 4)) continue; + // if (p-line > 32) continue; - if Xstrcmp(tls, (*hostent)(unsafe.Pointer(h)).h_name, name) != 0 { - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = buf - Xstrcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)), name) - buf += (uintptr(Xstrlen(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4))) + size_t(1))) - } else { - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*4)) = uintptr(0) - } + // memcpy(buf, line, p-line); + // break; + // } + // __fclose_ca(f); +} - *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 2*4)) = uintptr(0) +func Xgetnameinfo(tls *TLS, sa1 uintptr, sl socklen_t, node uintptr, nodelen socklen_t, serv uintptr, servlen socklen_t, flags int32) int32 { /* getnameinfo.c:125:5: */ + bp := tls.Alloc(347) + defer tls.Free(347) - *(*uintptr)(unsafe.Pointer(res)) = h - return 0 -} + // var ptr [78]int8 at bp, 78 -type if_nameindex = struct { - if_index uint32 - if_name uintptr -} /* if.h:12:1 */ + // var buf [256]int8 at bp+78, 256 -type ifaddr = struct { - ifa_addr struct { - sa_family sa_family_t - sa_data [14]int8 - } - ifa_ifu struct { - ifu_broadaddr struct { - sa_family sa_family_t - sa_data [14]int8 - } - } - ifa_ifp uintptr - ifa_next uintptr -} /* if.h:51:1 */ + // var num [13]int8 at bp+334, 13 -type ifmap = struct { - mem_start uint32 - mem_end uint32 - base_addr uint16 - irq uint8 - dma uint8 - port uint8 - _ [3]byte -} /* if.h:64:1 */ + var af int32 = int32((*sockaddr)(unsafe.Pointer(sa1)).sa_family) + var a uintptr + var scopeid uint32 -type ifreq = struct { - ifr_ifrn struct{ ifrn_name [16]int8 } - ifr_ifru struct { - _ [0]uint32 - ifru_addr struct { - sa_family sa_family_t - sa_data [14]int8 + switch af { + case 2: + a = (sa1 + 4 /* &.sin_addr */) + if (sl < socklen_t(unsafe.Sizeof(sockaddr_in{}))) { + return -6 + } + mkptr4(tls, bp /* &ptr[0] */, a) + scopeid = uint32(0) + break + case 10: + a = (sa1 + 8 /* &.sin6_addr */) + if (sl < socklen_t(unsafe.Sizeof(sockaddr_in6{}))) { + return -6 + } + if Xmemcmp(tls, a, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) != 0 { + mkptr6(tls, bp /* &ptr[0] */, a) + } else { + mkptr4(tls, bp /* &ptr[0] */, (a + uintptr(12))) } + scopeid = (*sockaddr_in6)(unsafe.Pointer(sa1)).sin6_scope_id + break + default: + return -6 } -} /* if.h:76:1 */ - -type ifconf = struct { - ifc_len int32 - ifc_ifcu struct{ ifcu_buf uintptr } -} /* if.h:116:1 */ - -type ns_sect = uint32 /* nameser.h:37:3 */ - -type __ns_msg = struct { - _msg uintptr - _eom uintptr - _id uint16_t - _flags uint16_t - _counts [4]uint16_t - _sections [4]uintptr - _sect ns_sect - _rrnum int32 - _msg_ptr uintptr -} /* nameser.h:39:9 */ -type ns_msg = __ns_msg /* nameser.h:46:3 */ + if (node != 0) && (nodelen != 0) { + *(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0) + if !((flags & 0x01) != 0) { + reverse_hosts(tls, bp+78 /* &buf[0] */, a, scopeid, af) + } + if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) && !((flags & 0x01) != 0) { + Xabort(tls) //TODO- + // unsigned char query[18+PTR_MAX], reply[512]; + // int qlen = __res_mkquery(0, ptr, 1, RR_PTR, + // 0, 0, 0, query, sizeof query); + // query[3] = 0; /* don't need AD flag */ + // int rlen = __res_send(query, qlen, reply, sizeof reply); + // buf[0] = 0; + // if (rlen > 0) + // __dns_parse(reply, rlen, dns_parse_callback, buf); + } + if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) { + if (flags & 0x08) != 0 { + return -2 + } + Xinet_ntop(tls, af, a, bp+78 /* &buf[0] */, uint32(unsafe.Sizeof([256]int8{}))) + if scopeid != 0 { + Xabort(tls) //TODO- + // char *p = 0, tmp[IF_NAMESIZE+1]; + // if (!(flags & NI_NUMERICSCOPE) && + // (IN6_IS_ADDR_LINKLOCAL(a) || + // IN6_IS_ADDR_MC_LINKLOCAL(a))) + // p = if_indextoname(scopeid, tmp+1); + // if (!p) + // p = itoa(num, scopeid); + // *--p = '%'; + // strcat(buf, p); + } + } + if Xstrlen(tls, bp+78 /* &buf[0] */) >= nodelen { + return -12 + } + Xstrcpy(tls, node, bp+78 /* &buf[0] */) + } -type _ns_flagdata = struct { - mask int32 - shift int32 -} /* nameser.h:48:1 */ + if (serv != 0) && (servlen != 0) { + var p uintptr = bp + 78 /* buf */ + var port int32 = int32(Xntohs(tls, (*sockaddr_in)(unsafe.Pointer(sa1)).sin_port)) + *(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0) + if !((flags & 0x02) != 0) { + reverse_services(tls, bp+78 /* &buf[0] */, port, (flags & 0x10)) + } + if !(int32(*(*int8)(unsafe.Pointer(p))) != 0) { + p = itoa(tls, bp+334 /* &num[0] */, uint32(port)) + } + if Xstrlen(tls, p) >= servlen { + return -12 + } + Xstrcpy(tls, serv, p) + } -type __ns_rr = struct { - name [1025]int8 - _ [1]byte - __type uint16_t - rr_class uint16_t - _ [2]byte - ttl uint32_t - rdlength uint16_t - _ [2]byte - rdata uintptr -} /* nameser.h:59:9 */ + return 0 +} -type ns_rr = __ns_rr /* nameser.h:66:3 */ +var Xh_errno int32 /* h_errno.c:4:5: */ -type ns_flag = uint32 /* nameser.h:87:3 */ +func X__h_errno_location(tls *TLS) uintptr { /* h_errno.c:6:5: */ + return uintptr(unsafe.Pointer(&Xh_errno)) +} -type ns_opcode = uint32 /* nameser.h:96:3 */ +func X__inet_aton(tls *TLS, s0 uintptr, dest uintptr) int32 { /* inet_aton.c:7:5: */ + bp := tls.Alloc(20) + defer tls.Free(20) -type ns_rcode = uint32 /* nameser.h:115:3 */ + var s uintptr = s0 + var d uintptr = dest + *(*[4]uint32)(unsafe.Pointer(bp /* a */)) = [4]uint32{0: uint32(0)} + // var z uintptr at bp+16, 4 -type ns_update_operation = uint32 /* nameser.h:121:3 */ + var i int32 -type ns_tsig_key1 = struct { - name [1025]int8 - alg [1025]int8 - _ [2]byte - data uintptr - len int32 -} /* nameser.h:123:1 */ + for i = 0; i < 4; i++ { + *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4)) = Xstrtoul(tls, s, bp+16 /* &z */, 0) + if ((*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)) == s) || ((*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)))) != 0) && (int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */))))) != '.'))) || !(func() int32 { + if 0 != 0 { + return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(s)))) + } + return (Bool32(((uint32(*(*int8)(unsafe.Pointer(s)))) - uint32('0')) < uint32(10))) + }() != 0) { + return 0 + } + if !(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */))))) != 0) { + break + } + s = (*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)) + uintptr(1)) + } + if i == 4 { + return 0 + } + switch i { + case 0: + *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 1*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */)) & uint32(0xffffff)) + AssignShrPtrUint32(bp /* &a */, int(24)) + fallthrough + case 1: + *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 2*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 1*4)) & uint32(0xffff)) + AssignShrPtrUint32(bp /* &a */ +1*4, int(16)) + fallthrough + case 2: + *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 3*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 2*4)) & uint32(0xff)) + AssignShrPtrUint32(bp /* &a */ +2*4, int(8)) + } + for i = 0; i < 4; i++ { + if *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4)) > uint32(255) { + return 0 + } + *(*uint8)(unsafe.Pointer(d + uintptr(i))) = uint8(*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4))) + } + return 1 +} -type ns_tsig_key = ns_tsig_key1 /* nameser.h:128:28 */ +func Xinet_ntop(tls *TLS, af int32, a0 uintptr, s uintptr, l socklen_t) uintptr { /* inet_ntop.c:7:12: */ + bp := tls.Alloc(276) + defer tls.Free(276) -type ns_tcp_tsig_state1 = struct { - counter int32 - key uintptr - ctx uintptr - sig [512]uint8 - siglen int32 -} /* nameser.h:130:1 */ + var a uintptr = a0 + var i int32 + var j int32 + var max int32 + var best int32 + // var buf [100]int8 at bp+176, 100 -type ns_tcp_tsig_state = ns_tcp_tsig_state1 /* nameser.h:137:34 */ + switch af { + case 2: + if socklen_t(Xsnprintf(tls, s, l, ts+101 /* "%d.%d.%d.%d" */, VaList(bp, int32(*(*uint8)(unsafe.Pointer(a))), int32(*(*uint8)(unsafe.Pointer(a + 1))), int32(*(*uint8)(unsafe.Pointer(a + 2))), int32(*(*uint8)(unsafe.Pointer(a + 3)))))) < l { + return s + } + break + case 10: + if Xmemcmp(tls, a, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) != 0 { + Xsnprintf(tls, bp+176 /* &buf[0] */, uint32(unsafe.Sizeof([100]int8{})), + ts+113, /* "%x:%x:%x:%x:%x:%..." */ + VaList(bp+32, ((256*int32(*(*uint8)(unsafe.Pointer(a))))+int32(*(*uint8)(unsafe.Pointer(a + 1)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 2))))+int32(*(*uint8)(unsafe.Pointer(a + 3)))), + ((256*int32(*(*uint8)(unsafe.Pointer(a + 4))))+int32(*(*uint8)(unsafe.Pointer(a + 5)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 6))))+int32(*(*uint8)(unsafe.Pointer(a + 7)))), + ((256*int32(*(*uint8)(unsafe.Pointer(a + 8))))+int32(*(*uint8)(unsafe.Pointer(a + 9)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 10))))+int32(*(*uint8)(unsafe.Pointer(a + 11)))), + ((256*int32(*(*uint8)(unsafe.Pointer(a + 12))))+int32(*(*uint8)(unsafe.Pointer(a + 13)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 14))))+int32(*(*uint8)(unsafe.Pointer(a + 15)))))) + } else { + Xsnprintf(tls, bp+176 /* &buf[0] */, uint32(unsafe.Sizeof([100]int8{})), + ts+137, /* "%x:%x:%x:%x:%x:%..." */ + VaList(bp+96, ((256*int32(*(*uint8)(unsafe.Pointer(a))))+int32(*(*uint8)(unsafe.Pointer(a + 1)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 2))))+int32(*(*uint8)(unsafe.Pointer(a + 3)))), + ((256*int32(*(*uint8)(unsafe.Pointer(a + 4))))+int32(*(*uint8)(unsafe.Pointer(a + 5)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 6))))+int32(*(*uint8)(unsafe.Pointer(a + 7)))), + ((256*int32(*(*uint8)(unsafe.Pointer(a + 8))))+int32(*(*uint8)(unsafe.Pointer(a + 9)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 10))))+int32(*(*uint8)(unsafe.Pointer(a + 11)))), + int32(*(*uint8)(unsafe.Pointer(a + 12))), int32(*(*uint8)(unsafe.Pointer(a + 13))), int32(*(*uint8)(unsafe.Pointer(a + 14))), int32(*(*uint8)(unsafe.Pointer(a + 15))))) + } + // Replace longest /(^0|:)[:0]{2,}/ with "::" + i = AssignInt32(&best, 0) + max = 2 + for ; *(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(i))) != 0; i++ { + if (i != 0) && (int32(*(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(i)))) != ':') { + continue + } + j = int32(Xstrspn(tls, (bp + 176 /* &buf[0] */ + uintptr(i)), ts+167 /* ":0" */)) + if j > max { + best = i + max = j + } + } + if max > 3 { + *(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(best))) = AssignPtrInt8(bp+176 /* &buf */ +uintptr((best+1)), int8(':')) + Xmemmove(tls, ((bp + 176 /* &buf[0] */ + uintptr(best)) + uintptr(2)), ((bp + 176 /* &buf[0] */ + uintptr(best)) + uintptr(max)), (uint32(((i - best) - max) + 1))) + } + if Xstrlen(tls, bp+176 /* &buf[0] */) < l { + Xstrcpy(tls, s, bp+176 /* &buf[0] */) + return s + } + break + default: + (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 97 + return uintptr(0) + } + (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 28 + return uintptr(0) +} -type ns_type = uint32 /* nameser.h:200:3 */ +func hexval(tls *TLS, c uint32) int32 { /* inet_pton.c:7:12: */ + if (c - uint32('0')) < uint32(10) { + return (int32(c - uint32('0'))) + } + c = c | (uint32(32)) + if (c - uint32('a')) < uint32(6) { + return (int32((c - uint32('a')) + uint32(10))) + } + return -1 +} -type ns_class = uint32 /* nameser.h:219:3 */ +func Xinet_pton(tls *TLS, af int32, s uintptr, a0 uintptr) int32 { /* inet_pton.c:15:5: */ + bp := tls.Alloc(16) + defer tls.Free(16) -type ns_key_types = uint32 /* nameser.h:226:3 */ + // var ip [8]uint16_t at bp, 16 -type ns_cert_types = uint32 /* nameser.h:234:3 */ + var a uintptr = a0 + var i int32 + var j int32 + var v int32 + var d int32 + var brk int32 = -1 + var need_v4 int32 = 0 -type HEADER = struct { - _ [0]uint32 - id uint32 /* unsigned id: 16, unsigned rd: 1, unsigned tc: 1, unsigned aa: 1, unsigned opcode: 4, unsigned qr: 1, unsigned rcode: 4, unsigned cd: 1, unsigned ad: 1, unsigned unused: 1, unsigned ra: 1 */ - qdcount uint32 /* unsigned qdcount: 16, unsigned ancount: 16 */ - nscount uint32 /* unsigned nscount: 16, unsigned arcount: 16 */ -} /* nameser.h:353:3 */ + if af == 2 { + for i = 0; i < 4; i++ { + for v = AssignInt32(&j, 0); (j < 3) && (func() int32 { + if 0 != 0 { + return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) + } + return (Bool32(((uint32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) - uint32('0')) < uint32(10))) + }() != 0); j++ { + v = (((10 * v) + int32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) - '0') + } + if ((j == 0) || ((j > 1) && (int32(*(*int8)(unsafe.Pointer(s))) == '0'))) || (v > 255) { + return 0 + } + *(*uint8)(unsafe.Pointer(a + uintptr(i))) = uint8(v) + if (int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) == 0) && (i == 3) { + return 1 + } + if int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != '.' { + return 0 + } + s += (uintptr(j + 1)) + } + return 0 + } else if af != 10 { + (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 97 + return -1 + } -// unused; purely for broken apps -type __res_state = struct { - retrans int32 - retry int32 - options uint32 - nscount int32 - nsaddr_list [3]struct { - sin_family sa_family_t - sin_port in_port_t - sin_addr struct{ s_addr in_addr_t } - sin_zero [8]uint8_t + if (int32(*(*int8)(unsafe.Pointer(s))) == ':') && (int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&s, 1)))) != ':') { + return 0 } - id uint16 - _ [2]byte - dnsrch [7]uintptr - defdname [256]int8 - pfcode uint32 - ndots uint32 /* unsigned ndots: 4, unsigned nsort: 4, unsigned ipv6_unavail: 1, unsigned unused: 23 */ - sort_list [10]struct { - addr struct{ s_addr in_addr_t } - mask uint32_t + + for i = 0; ; i++ { + if (int32(*(*int8)(unsafe.Pointer(s))) == ':') && (brk < 0) { + brk = i + *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((i&7))*2)) = uint16_t(0) + if !(int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&s, 1)))) != 0) { + break + } + if i == 7 { + return 0 + } + continue + } + for v = AssignInt32(&j, 0); (j < 4) && ((AssignInt32(&d, hexval(tls, uint32(*(*int8)(unsafe.Pointer(s + uintptr(j))))))) >= 0); j++ { + v = ((16 * v) + d) + } + if j == 0 { + return 0 + } + *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((i&7))*2)) = uint16_t(v) + if !(int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != 0) && ((brk >= 0) || (i == 7)) { + break + } + if i == 7 { + return 0 + } + if int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != ':' { + if (int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != '.') || ((i < 6) && (brk < 0)) { + return 0 + } + need_v4 = 1 + i++ + break + } + s += (uintptr(j + 1)) } - qhook uintptr - rhook uintptr - res_h_errno int32 - _vcsock int32 - _flags uint32 - _u struct { - _ [0]uint32 - pad [52]int8 + if brk >= 0 { + Xmemmove(tls, (((bp /* &ip[0] */ + uintptr(brk)*2) + uintptr(7)*2) - uintptr(i)*2), (bp /* &ip[0] */ + uintptr(brk)*2), (uint32(2 * ((i + 1) - brk)))) + for j = 0; j < (7 - i); j++ { + *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((brk+j))*2)) = uint16_t(0) + } } -} /* resolv.h:26:9 */ - -// unused; purely for broken apps -type res_state = uintptr /* resolv.h:62:3 */ - -type res_sym = struct { - number int32 - name uintptr - humanname uintptr -} /* resolv.h:70:1 */ - -func itoa(tls *TLS, p uintptr, x uint32) uintptr { /* getnameinfo.c:18:13: */ - p += (uintptr(uint32(3) * uint32(unsafe.Sizeof(int32(0))))) - *(*int8)(unsafe.Pointer(PreDecUintptr(&p, 1))) = int8(0) - for ok := true; ok; ok = x != 0 { - *(*int8)(unsafe.Pointer(PreDecUintptr(&p, 1))) = (int8(uint32('0') + (x % uint32(10)))) - x = x / (uint32(10)) + for j = 0; j < 8; j++ { + *(*uint8)(unsafe.Pointer(PostIncUintptr(&a, 1))) = (uint8(int32(*(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr(j)*2))) >> 8)) + *(*uint8)(unsafe.Pointer(PostIncUintptr(&a, 1))) = uint8(*(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr(j)*2))) } - return p -} - -func mkptr4(tls *TLS, s uintptr, ip uintptr) { /* getnameinfo.c:28:13: */ - bp := tls.Alloc(32) - defer tls.Free(32) - - Xsprintf(tls, s, ts+23, /* "%d.%d.%d.%d.in-a..." */ - VaList(bp, int32(*(*uint8)(unsafe.Pointer(ip + 3))), int32(*(*uint8)(unsafe.Pointer(ip + 2))), int32(*(*uint8)(unsafe.Pointer(ip + 1))), int32(*(*uint8)(unsafe.Pointer(ip))))) -} - -func mkptr6(tls *TLS, s uintptr, ip uintptr) { /* getnameinfo.c:34:13: */ - var i int32 - for i = 15; i >= 0; i-- { - *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = _sxdigits[(int32(*(*uint8)(unsafe.Pointer(ip + uintptr(i)))) & 15)] - *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8('.') - *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = _sxdigits[(int32(*(*uint8)(unsafe.Pointer(ip + uintptr(i)))) >> 4)] - *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8('.') + if (need_v4 != 0) && (Xinet_pton(tls, 2, s, (a-uintptr(4))) <= 0) { + return 0 } - Xstrcpy(tls, s, ts+48 /* "ip6.arpa" */) + return 1 } -var _sxdigits = *(*[17]int8)(unsafe.Pointer(ts + 57 /* "0123456789abcdef" */)) /* getnameinfo.c:36:20 */ +func X__lookup_ipliteral(tls *TLS, buf uintptr, name uintptr, family int32) int32 { /* lookup_ipliteral.c:12:5: */ + bp := tls.Alloc(88) + defer tls.Free(88) -func reverse_hosts(tls *TLS, buf uintptr, a uintptr, scopeid uint32, family int32) { /* getnameinfo.c:45:13: */ - bp := tls.Alloc(556) - defer tls.Free(556) + // var a4 in_addr at bp, 4 - // var line [512]int8 at bp+16, 512 + // var a6 in6_addr at bp+68, 16 - var p uintptr - var z uintptr - var _buf [1032]uint8 - _ = _buf - // var atmp [16]uint8 at bp, 16 + if X__inet_aton(tls, name, bp /* &a4 */) > 0 { + if family == 10 { // wrong family + return -2 + } + Xmemcpy(tls, (buf + 8 /* &.addr */), bp /* &a4 */, uint32(unsafe.Sizeof(in_addr{}))) + (*address)(unsafe.Pointer(buf)).family = 2 + (*address)(unsafe.Pointer(buf)).scopeid = uint32(0) + return 1 + } + // var tmp [64]int8 at bp+4, 64 - // var iplit address at bp+528, 28 + var p uintptr = Xstrchr(tls, name, '%') + // var z uintptr at bp+84, 4 - //TODO FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); - var f uintptr = Xfopen(tls, ts+74 /* "/etc/hosts" */, ts+85 /* "rb" */) - if !(f != 0) { - return + var scopeid uint64 = uint64(0) + if (p != 0) && (((int32(p) - int32(name)) / 1) < 64) { + Xmemcpy(tls, bp+4 /* &tmp[0] */, name, (uint32((int32(p) - int32(name)) / 1))) + *(*int8)(unsafe.Pointer(bp + 4 /* &tmp[0] */ + uintptr(((int32(p) - int32(name)) / 1)))) = int8(0) + name = bp + 4 /* &tmp[0] */ } - if family == 2 { - Xmemcpy(tls, (bp /* &atmp[0] */ + uintptr(12)), a, uint32(4)) - Xmemcpy(tls, bp /* &atmp[0] */, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) - a = bp /* &atmp[0] */ + + if Xinet_pton(tls, 10, name, bp+68 /* &a6 */) <= 0 { + return 0 + } + if family == 2 { // wrong family + return -2 } - for Xfgets(tls, bp+16 /* &line[0] */, int32(unsafe.Sizeof([512]int8{})), f) != 0 { - if AssignUintptr(&p, Xstrchr(tls, bp+16 /* &line[0] */, '#')) != 0 { - *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8('\n') - *(*int8)(unsafe.Pointer(p)) = int8(0) - } - for p = bp + 16; /* &line[0] */ (*(*int8)(unsafe.Pointer(p)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + Xmemcpy(tls, (buf + 8 /* &.addr */), bp+68 /* &a6 */, uint32(unsafe.Sizeof(in6_addr{}))) + (*address)(unsafe.Pointer(buf)).family = 10 + if p != 0 { + if func() int32 { + if 0 != 0 { + return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&p, 1))))) + } + return (Bool32(((uint32(*(*int8)(unsafe.Pointer(PreIncUintptr(&p, 1))))) - uint32('0')) < uint32(10))) + }() != 0 { + scopeid = Xstrtoull(tls, p, bp+84 /* &z */, 10) + } else { + *(*uintptr)(unsafe.Pointer(bp + 84 /* z */)) = (p - uintptr(1)) } - *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8(0) - if X__lookup_ipliteral(tls, bp+528 /* &iplit */, bp+16 /* &line[0] */, 0) <= 0 { - continue + if *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 84 /* z */)))) != 0 { + Xabort(tls) //TODO- + // if (!IN6_IS_ADDR_LINKLOCAL(&a6) && + // !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) + // return EAI_NONAME; + // scopeid = if_nametoindex(p); + // if (!scopeid) return EAI_NONAME; } - - if (*address)(unsafe.Pointer(bp+528 /* &iplit */)).family == 2 { - Xmemcpy(tls, ((bp + 528 /* &iplit */ + 8 /* &.addr */) + uintptr(12)), bp+528 /* &iplit */ +8 /* &.addr */, uint32(4)) - Xmemcpy(tls, bp+528 /* &iplit */ +8 /* &.addr */, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) - (*address)(unsafe.Pointer(bp + 528 /* &iplit */)).scopeid = uint32(0) + if scopeid > uint64(0xffffffff) { + return -2 } + } + (*address)(unsafe.Pointer(buf)).scopeid = uint32(scopeid) + return 1 +} - if (Xmemcmp(tls, a, bp+528 /* &iplit */ +8 /* &.addr */, uint32(16)) != 0) || ((*address)(unsafe.Pointer(bp+528 /* &iplit */)).scopeid != scopeid) { - continue - } +func is_valid_hostname(tls *TLS, host uintptr) int32 { /* lookup_name.c:18:12: */ + var s uintptr + //TODO if (strnlen(host, 255)-1 >= 254 || mbstowcs(0, host, 0) == -1) return 0; + if (Xstrnlen(tls, host, uint32(255)) - size_t(1)) >= size_t(254) { + return 0 + } + for s = host; (((int32(*(*uint8)(unsafe.Pointer(s))) >= 0x80) || (int32(*(*uint8)(unsafe.Pointer(s))) == '.')) || (int32(*(*uint8)(unsafe.Pointer(s))) == '-')) || (Xisalnum(tls, int32(*(*uint8)(unsafe.Pointer(s)))) != 0); s++ { + } + return BoolInt32(!(*(*uint8)(unsafe.Pointer(s)) != 0)) +} - for ; (*(*int8)(unsafe.Pointer(p)) != 0) && (__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { - } - for z = p; (*(*int8)(unsafe.Pointer(z)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(z)))) != 0); z++ { +var Xzero_struct_address address /* lookup_name.c:27:16: */ + +func name_from_null(tls *TLS, buf uintptr, name uintptr, family int32, flags int32) int32 { /* lookup_name.c:29:12: */ + var cnt int32 = 0 + if name != 0 { + return 0 + } + if (flags & 0x01) != 0 { + //TODO if (family != AF_INET6) + //TODO buf[cnt++] = (struct address){ .family = AF_INET }; + if family != 10 { + var x = Xzero_struct_address + x.family = 2 + *(*address)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*28)) = x } - *(*int8)(unsafe.Pointer(z)) = int8(0) - if ((int32(z) - int32(p)) / 1) < 256 { - Xmemcpy(tls, buf, p, (uint32(((int32(z) - int32(p)) / 1) + 1))) - break + //TODO if (family != AF_INET) + //TODO buf[cnt++] = (struct address){ .family = AF_INET6 }; + if family != 2 { + var x = Xzero_struct_address + x.family = 10 + *(*address)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*28)) = x } + } else { + Xabort(tls) //TODO- + // if (family != AF_INET6) + // buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; + // if (family != AF_INET) + // buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; } - //TODO __fclose_ca(f); - Xfclose(tls, f) + return cnt } -func reverse_services(tls *TLS, buf uintptr, port int32, dgram int32) { /* getnameinfo.c:87:13: */ - Xabort(tls) //TODO- - // unsigned long svport; - // char line[128], *p, *z; - // unsigned char _buf[1032]; - // FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); - // if (!f) return; - // while (fgets(line, sizeof line, f)) { - // if ((p=strchr(line, '#'))) *p++='\n', *p=0; - - // for (p=line; *p && !isspace(*p); p++); - // if (!*p) continue; - // *p++ = 0; - // svport = strtoul(p, &z, 10); - - // if (svport != port || z==p) continue; - // if (dgram && strncmp(z, "/udp", 4)) continue; - // if (!dgram && strncmp(z, "/tcp", 4)) continue; - // if (p-line > 32) continue; - - // memcpy(buf, line, p-line); - // break; - // } - // __fclose_ca(f); +func name_from_numeric(tls *TLS, buf uintptr, name uintptr, family int32) int32 { /* lookup_name.c:58:12: */ + return X__lookup_ipliteral(tls, buf, name, family) } -func Xgetnameinfo(tls *TLS, sa1 uintptr, sl socklen_t, node uintptr, nodelen socklen_t, serv uintptr, servlen socklen_t, flags int32) int32 { /* getnameinfo.c:125:5: */ - bp := tls.Alloc(347) - defer tls.Free(347) - - // var ptr [78]int8 at bp, 78 - - // var buf [256]int8 at bp+78, 256 - - // var num [13]int8 at bp+334, 13 +func name_from_hosts(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32) int32 { /* lookup_name.c:63:12: */ + bp := tls.Alloc(512) + defer tls.Free(512) - var af int32 = int32((*sockaddr)(unsafe.Pointer(sa1)).sa_family) - var a uintptr - var scopeid uint32 + // var line [512]int8 at bp, 512 - switch af { - case 2: - a = (sa1 + 4 /* &.sin_addr */) - if (sl < socklen_t(unsafe.Sizeof(sockaddr_in{}))) { - return -6 - } - mkptr4(tls, bp /* &ptr[0] */, a) - scopeid = uint32(0) - break - case 10: - a = (sa1 + 8 /* &.sin6_addr */) - if (sl < socklen_t(unsafe.Sizeof(sockaddr_in6{}))) { - return -6 - } - if Xmemcmp(tls, a, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) != 0 { - mkptr6(tls, bp /* &ptr[0] */, a) - } else { - mkptr4(tls, bp /* &ptr[0] */, (a + uintptr(12))) + var l size_t = Xstrlen(tls, name) + var cnt int32 = 0 + var badfam int32 = 0 + var _buf [1032]uint8 + _ = _buf + //TODO FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); + var _f FILE + _ = _f + var f uintptr = Xfopen(tls, ts+74 /* "/etc/hosts" */, ts+85 /* "rb" */) + if !(f != 0) { + switch *(*int32)(unsafe.Pointer(X___errno_location(tls))) { + case 2: + fallthrough + case 20: + fallthrough + case 13: + return 0 + fallthrough + default: + return -11 } - scopeid = (*sockaddr_in6)(unsafe.Pointer(sa1)).sin6_scope_id - break - default: - return -6 } + for (Xfgets(tls, bp /* &line[0] */, int32(unsafe.Sizeof([512]int8{})), f) != 0) && (cnt < 48) { + var p uintptr + var z uintptr - if (node != 0) && (nodelen != 0) { - *(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0) - if !((flags & 0x01) != 0) { - reverse_hosts(tls, bp+78 /* &buf[0] */, a, scopeid, af) + if AssignUintptr(&p, Xstrchr(tls, bp /* &line[0] */, '#')) != 0 { + *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8('\n') + *(*int8)(unsafe.Pointer(p)) = int8(0) } - if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) && !((flags & 0x01) != 0) { - Xabort(tls) //TODO- - // unsigned char query[18+PTR_MAX], reply[512]; - // int qlen = __res_mkquery(0, ptr, 1, RR_PTR, - // 0, 0, 0, query, sizeof query); - // query[3] = 0; /* don't need AD flag */ - // int rlen = __res_send(query, qlen, reply, sizeof reply); - // buf[0] = 0; - // if (rlen > 0) - // __dns_parse(reply, rlen, dns_parse_callback, buf); + for p = (bp /* &line[0] */ + uintptr(1)); (AssignUintptr(&p, Xstrstr(tls, p, name)) != 0) && (!(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p + UintptrFromInt32(-1))))) != 0) || !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p + uintptr(l))))) != 0)); p++ { } - if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) { - if (flags & 0x08) != 0 { - return -2 - } - Xinet_ntop(tls, af, a, bp+78 /* &buf[0] */, uint32(unsafe.Sizeof([256]int8{}))) - if scopeid != 0 { - Xabort(tls) //TODO- - // char *p = 0, tmp[IF_NAMESIZE+1]; - // if (!(flags & NI_NUMERICSCOPE) && - // (IN6_IS_ADDR_LINKLOCAL(a) || - // IN6_IS_ADDR_MC_LINKLOCAL(a))) - // p = if_indextoname(scopeid, tmp+1); - // if (!p) - // p = itoa(num, scopeid); - // *--p = '%'; - // strcat(buf, p); - } + if !(p != 0) { + continue } - if Xstrlen(tls, bp+78 /* &buf[0] */) >= nodelen { - return -12 + + // Isolate IP address to parse + for p = bp; /* &line[0] */ (*(*int8)(unsafe.Pointer(p)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + } + *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8(0) + switch name_from_numeric(tls, (buf + uintptr(cnt)*28), bp /* &line[0] */, family) { + case 1: + cnt++ + break + case 0: + continue + default: + badfam = -2 + continue } - Xstrcpy(tls, node, bp+78 /* &buf[0] */) - } - if (serv != 0) && (servlen != 0) { - var p uintptr = bp + 78 /* buf */ - var port int32 = int32(Xntohs(tls, (*sockaddr_in)(unsafe.Pointer(sa1)).sin_port)) - *(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0) - if !((flags & 0x02) != 0) { - reverse_services(tls, bp+78 /* &buf[0] */, port, (flags & 0x10)) + // Extract first name as canonical name + for ; (*(*int8)(unsafe.Pointer(p)) != 0) && (__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { } - if !(int32(*(*int8)(unsafe.Pointer(p))) != 0) { - p = itoa(tls, bp+334 /* &num[0] */, uint32(port)) + for z = p; (*(*int8)(unsafe.Pointer(z)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(z)))) != 0); z++ { } - if Xstrlen(tls, p) >= servlen { - return -12 + *(*int8)(unsafe.Pointer(z)) = int8(0) + if is_valid_hostname(tls, p) != 0 { + Xmemcpy(tls, canon, p, (uint32(((int32(z) - int32(p)) / 1) + 1))) } - Xstrcpy(tls, serv, p) } - - return 0 + //TODO __fclose_ca(f); + Xfclose(tls, f) + if cnt != 0 { + return cnt + } + return badfam } -var Xh_errno int32 /* h_errno.c:4:5: */ +type dpc_ctx = struct { + addrs uintptr + canon uintptr + cnt int32 +} /* lookup_name.c:112:1 */ -func X__h_errno_location(tls *TLS) uintptr { /* h_errno.c:6:5: */ - return uintptr(unsafe.Pointer(&Xh_errno)) -} +func name_from_dns_search(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32) int32 { /* lookup_name.c:191:12: */ + return -1 //TODO- + Xabort(tls) + return int32(0) //TODO- + // char search[256]; + // struct resolvconf conf; + // size_t l, dots; + // char *p, *z; -func X__inet_aton(tls *TLS, s0 uintptr, dest uintptr) int32 { /* inet_aton.c:7:5: */ - bp := tls.Alloc(20) - defer tls.Free(20) + // if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1; - var s uintptr = s0 - var d uintptr = dest - *(*[4]uint32)(unsafe.Pointer(bp /* a */)) = [4]uint32{0: uint32(0)} - // var z uintptr at bp+16, 4 + // /* Count dots, suppress search when >=ndots or name ends in + // * a dot, which is an explicit request for global scope. */ + // for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++; + // if (dots >= conf.ndots || name[l-1]=='.') *search = 0; - var i int32 + // /* Strip final dot for canon, fail if multiple trailing dots. */ + // if (name[l-1]=='.') l--; + // if (!l || name[l-1]=='.') return EAI_NONAME; - for i = 0; i < 4; i++ { - *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4)) = Xstrtoul(tls, s, bp+16 /* &z */, 0) - if ((*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)) == s) || ((*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)))) != 0) && (int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */))))) != '.'))) || !(func() int32 { - if 0 != 0 { - return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(s)))) - } - return (Bool32(((uint32(*(*int8)(unsafe.Pointer(s)))) - uint32('0')) < uint32(10))) - }() != 0) { - return 0 - } - if !(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 16 /* z */))))) != 0) { - break - } - s = (*(*uintptr)(unsafe.Pointer(bp + 16 /* z */)) + uintptr(1)) - } - if i == 4 { - return 0 - } - switch i { - case 0: - *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 1*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */)) & uint32(0xffffff)) - AssignShrPtrUint32(bp /* &a */, int(uint32(24))) - fallthrough - case 1: - *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 2*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 1*4)) & uint32(0xffff)) - AssignShrPtrUint32(bp /* &a */ +1*4, int(uint32(16))) - fallthrough - case 2: - *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 3*4)) = (*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + 2*4)) & uint32(0xff)) - AssignShrPtrUint32(bp /* &a */ +2*4, int(uint32(8))) - } - for i = 0; i < 4; i++ { - if *(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4)) > uint32(255) { - return 0 - } - *(*uint8)(unsafe.Pointer(d + uintptr(i))) = uint8(*(*uint32)(unsafe.Pointer(bp /* &a[0] */ + uintptr(i)*4))) - } - return 1 + // /* This can never happen; the caller already checked length. */ + // if (l >= 256) return EAI_NONAME; + + // /* Name with search domain appended is setup in canon[]. This both + // * provides the desired default canonical name (if the requested + // * name is not a CNAME record) and serves as a buffer for passing + // * the full requested name to name_from_dns. */ + // memcpy(canon, name, l); + // canon[l] = '.'; + + // for (p=search; *p; p=z) { + // for (; isspace(*p); p++); + // for (z=p; *z && !isspace(*z); z++); + // if (z==p) break; + // if (z-p < 256 - l - 1) { + // memcpy(canon+l+1, p, z-p); + // canon[z-p+1+l] = 0; + // int cnt = name_from_dns(buf, canon, canon, family, &conf); + // if (cnt) return cnt; + // } + // } + + // canon[l] = 0; + // return name_from_dns(buf, canon, name, family, &conf); } -func Xinet_ntop(tls *TLS, af int32, a0 uintptr, s uintptr, l socklen_t) uintptr { /* inet_ntop.c:7:12: */ - bp := tls.Alloc(276) - defer tls.Free(276) +type policy = struct { + addr [16]uint8 + len uint8 + mask uint8 + prec uint8 + label uint8 +} /* lookup_name.c:237:14 */ - var a uintptr = a0 - var i int32 - var j int32 - var max int32 - var best int32 - // var buf [100]int8 at bp+176, 100 +var defpolicy = [6]policy{ + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 170 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" */)), len: uint8(15), mask: uint8(0xff), prec: uint8(50)}, + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 187 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00" */)), len: uint8(11), mask: uint8(0xff), prec: uint8(35), label: uint8(4)}, + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 203 /* " \x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), len: uint8(1), mask: uint8(0xff), prec: uint8(30), label: uint8(2)}, + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 219 /* " \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), len: uint8(3), mask: uint8(0xff), prec: uint8(5), label: uint8(5)}, + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 235 /* "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), mask: uint8(0xfe), prec: uint8(3), label: uint8(13)}, + // Last rule must match all addresses to stop loop. + {addr: *(*[16]uint8)(unsafe.Pointer(ts + 251 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), prec: uint8(40), label: uint8(1)}, +} /* lookup_name.c:241:3 */ - switch af { - case 2: - if socklen_t(Xsnprintf(tls, s, l, ts+101 /* "%d.%d.%d.%d" */, VaList(bp, int32(*(*uint8)(unsafe.Pointer(a))), int32(*(*uint8)(unsafe.Pointer(a + 1))), int32(*(*uint8)(unsafe.Pointer(a + 2))), int32(*(*uint8)(unsafe.Pointer(a + 3)))))) < l { - return s - } - break - case 10: - if Xmemcmp(tls, a, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) != 0 { - Xsnprintf(tls, bp+176 /* &buf[0] */, uint32(unsafe.Sizeof([100]int8{})), - ts+113, /* "%x:%x:%x:%x:%x:%..." */ - VaList(bp+32, ((256*int32(*(*uint8)(unsafe.Pointer(a))))+int32(*(*uint8)(unsafe.Pointer(a + 1)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 2))))+int32(*(*uint8)(unsafe.Pointer(a + 3)))), - ((256*int32(*(*uint8)(unsafe.Pointer(a + 4))))+int32(*(*uint8)(unsafe.Pointer(a + 5)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 6))))+int32(*(*uint8)(unsafe.Pointer(a + 7)))), - ((256*int32(*(*uint8)(unsafe.Pointer(a + 8))))+int32(*(*uint8)(unsafe.Pointer(a + 9)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 10))))+int32(*(*uint8)(unsafe.Pointer(a + 11)))), - ((256*int32(*(*uint8)(unsafe.Pointer(a + 12))))+int32(*(*uint8)(unsafe.Pointer(a + 13)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 14))))+int32(*(*uint8)(unsafe.Pointer(a + 15)))))) - } else { - Xsnprintf(tls, bp+176 /* &buf[0] */, uint32(unsafe.Sizeof([100]int8{})), - ts+137, /* "%x:%x:%x:%x:%x:%..." */ - VaList(bp+96, ((256*int32(*(*uint8)(unsafe.Pointer(a))))+int32(*(*uint8)(unsafe.Pointer(a + 1)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 2))))+int32(*(*uint8)(unsafe.Pointer(a + 3)))), - ((256*int32(*(*uint8)(unsafe.Pointer(a + 4))))+int32(*(*uint8)(unsafe.Pointer(a + 5)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 6))))+int32(*(*uint8)(unsafe.Pointer(a + 7)))), - ((256*int32(*(*uint8)(unsafe.Pointer(a + 8))))+int32(*(*uint8)(unsafe.Pointer(a + 9)))), ((256*int32(*(*uint8)(unsafe.Pointer(a + 10))))+int32(*(*uint8)(unsafe.Pointer(a + 11)))), - int32(*(*uint8)(unsafe.Pointer(a + 12))), int32(*(*uint8)(unsafe.Pointer(a + 13))), int32(*(*uint8)(unsafe.Pointer(a + 14))), int32(*(*uint8)(unsafe.Pointer(a + 15))))) - } - // Replace longest /(^0|:)[:0]{2,}/ with "::" - i = AssignInt32(&best, 0) - max = 2 - for ; *(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(i))) != 0; i++ { - if (i != 0) && (int32(*(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(i)))) != ':') { - continue - } - j = int32(Xstrspn(tls, (bp + 176 /* &buf[0] */ + uintptr(i)), ts+167 /* ":0" */)) - if j > max { - best = i - max = j - } - } - if max > 3 { - *(*int8)(unsafe.Pointer(bp + 176 /* &buf[0] */ + uintptr(best))) = AssignPtrInt8(bp+176 /* &buf */ +uintptr((best+1)), int8(':')) - Xmemmove(tls, ((bp + 176 /* &buf[0] */ + uintptr(best)) + uintptr(2)), ((bp + 176 /* &buf[0] */ + uintptr(best)) + uintptr(max)), (uint32(((i - best) - max) + 1))) +func policyof(tls *TLS, a uintptr) uintptr { /* lookup_name.c:259:28: */ + var i int32 + for i = 0; ; i++ { + if Xmemcmp(tls, a /* &.__in6_union */ /* &.__s6_addr */, uintptr(unsafe.Pointer(&defpolicy))+uintptr(i)*20 /* &.addr */, uint32(defpolicy[i].len)) != 0 { + continue } - if Xstrlen(tls, bp+176 /* &buf[0] */) < l { - Xstrcpy(tls, s, bp+176 /* &buf[0] */) - return s + if (int32(*(*uint8_t)(unsafe.Pointer((a /* &.__in6_union */ /* &.__s6_addr */) + uintptr(defpolicy[i].len)))) & int32(defpolicy[i].mask)) != + int32(*(*uint8)(unsafe.Pointer((uintptr(unsafe.Pointer(&defpolicy)) + uintptr(i)*20 /* &.addr */) + uintptr(defpolicy[i].len)))) { + continue } - break - default: - (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 97 - return uintptr(0) + return (uintptr(unsafe.Pointer(&defpolicy)) + uintptr(i)*20) } - (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 28 return uintptr(0) } -func hexval(tls *TLS, c uint32) int32 { /* inet_pton.c:7:12: */ - if (c - uint32('0')) < uint32(10) { - return (int32(c - uint32('0'))) - } - c = c | (uint32(32)) - if (c - uint32('a')) < uint32(6) { - return (int32((c - uint32('a')) + uint32(10))) - } - return -1 +func labelof(tls *TLS, a uintptr) int32 { /* lookup_name.c:272:12: */ + return int32((*policy)(unsafe.Pointer(policyof(tls, a))).label) } -func Xinet_pton(tls *TLS, af int32, s uintptr, a0 uintptr) int32 { /* inet_pton.c:15:5: */ - bp := tls.Alloc(16) - defer tls.Free(16) - - // var ip [8]uint16_t at bp, 16 - - var a uintptr = a0 - var i int32 - var j int32 - var v int32 - var d int32 - var brk int32 = -1 - var need_v4 int32 = 0 - - if af == 2 { - for i = 0; i < 4; i++ { - for v = AssignInt32(&j, 0); (j < 3) && (func() int32 { - if 0 != 0 { - return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) - } - return (Bool32(((uint32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) - uint32('0')) < uint32(10))) - }() != 0); j++ { - v = (((10 * v) + int32(*(*int8)(unsafe.Pointer(s + uintptr(j))))) - '0') - } - if ((j == 0) || ((j > 1) && (int32(*(*int8)(unsafe.Pointer(s))) == '0'))) || (v > 255) { - return 0 - } - *(*uint8)(unsafe.Pointer(a + uintptr(i))) = uint8(v) - if (int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) == 0) && (i == 3) { - return 1 - } - if int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != '.' { - return 0 - } - s += (uintptr(j + 1)) - } - return 0 - } else if af != 10 { - (*(*int32)(unsafe.Pointer(X___errno_location(tls)))) = 97 - return -1 - } - - if (int32(*(*int8)(unsafe.Pointer(s))) == ':') && (int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&s, 1)))) != ':') { - return 0 +func scopeof(tls *TLS, a uintptr) int32 { /* lookup_name.c:277:12: */ + if int32(*(*uint8_t)(unsafe.Pointer((a)))) == 0xff { + return (int32(*(*uint8_t)(unsafe.Pointer((a /* &.__in6_union */ /* &.__s6_addr */) + 1))) & 15) } - - for i = 0; ; i++ { - if (int32(*(*int8)(unsafe.Pointer(s))) == ':') && (brk < 0) { - brk = i - *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((i&7))*2)) = uint16_t(0) - if !(int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&s, 1)))) != 0) { - break - } - if i == 7 { - return 0 - } - continue - } - for v = AssignInt32(&j, 0); (j < 4) && ((AssignInt32(&d, hexval(tls, uint32(*(*int8)(unsafe.Pointer(s + uintptr(j))))))) >= 0); j++ { - v = ((16 * v) + d) - } - if j == 0 { - return 0 - } - *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((i&7))*2)) = uint16_t(v) - if !(int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != 0) && ((brk >= 0) || (i == 7)) { - break - } - if i == 7 { - return 0 - } - if int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != ':' { - if (int32(*(*int8)(unsafe.Pointer(s + uintptr(j)))) != '.') || ((i < 6) && (brk < 0)) { - return 0 - } - need_v4 = 1 - i++ - break - } - s += (uintptr(j + 1)) + if ((int32(*(*uint8_t)(unsafe.Pointer((a))))) == 0xfe) && ((int32(*(*uint8_t)(unsafe.Pointer((a) + 1))) & 0xc0) == 0x80) { + return 2 } - if brk >= 0 { - Xmemmove(tls, (((bp /* &ip[0] */ + uintptr(brk)*2) + uintptr(7)*2) - uintptr(i)*2), (bp /* &ip[0] */ + uintptr(brk)*2), (uint32(2 * ((i + 1) - brk)))) - for j = 0; j < (7 - i); j++ { - *(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr((brk+j))*2)) = uint16_t(0) - } + if ((((((*(*uint32_t)(unsafe.Pointer((a))) == uint32_t(0)) && (*(*uint32_t)(unsafe.Pointer((a) + 1*4)) == uint32_t(0))) && (*(*uint32_t)(unsafe.Pointer((a) + 2*4)) == uint32_t(0))) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 12))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 13))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 14))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 15))) == 1) { + return 2 } - for j = 0; j < 8; j++ { - *(*uint8)(unsafe.Pointer(PostIncUintptr(&a, 1))) = (uint8(int32(*(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr(j)*2))) >> 8)) - *(*uint8)(unsafe.Pointer(PostIncUintptr(&a, 1))) = uint8(*(*uint16_t)(unsafe.Pointer(bp /* &ip[0] */ + uintptr(j)*2))) + if ((int32(*(*uint8_t)(unsafe.Pointer((a))))) == 0xfe) && ((int32(*(*uint8_t)(unsafe.Pointer((a) + 1))) & 0xc0) == 0xc0) { + return 5 } - if (need_v4 != 0) && (Xinet_pton(tls, 2, s, (a-uintptr(4))) <= 0) { - return 0 + return 14 +} + +func prefixmatch(tls *TLS, s uintptr, d uintptr) int32 { /* lookup_name.c:286:12: */ + // FIXME: The common prefix length should be limited to no greater + // than the nominal length of the prefix portion of the source + // address. However the definition of the source prefix length is + // not clear and thus this limiting is not yet implemented. + var i uint32 + for i = uint32(0); (i < uint32(128)) && !(((int32(*(*uint8_t)(unsafe.Pointer((s /* &.__in6_union */ /* &.__s6_addr */) + uintptr((i / uint32(8)))))) ^ int32(*(*uint8_t)(unsafe.Pointer((d /* &.__in6_union */ /* &.__s6_addr */) + uintptr((i / uint32(8))))))) & (int32(128) >> (i % uint32(8)))) != 0); i++ { } - return 1 + return int32(i) } -func X__lookup_ipliteral(tls *TLS, buf uintptr, name uintptr, family int32) int32 { /* lookup_ipliteral.c:12:5: */ - bp := tls.Alloc(88) - defer tls.Free(88) +func addrcmp(tls *TLS, _a uintptr, _b uintptr) int32 { /* lookup_name.c:305:12: */ + var a uintptr = _a + var b uintptr = _b + return ((*address)(unsafe.Pointer(b)).sortkey - (*address)(unsafe.Pointer(a)).sortkey) +} - // var a4 in_addr at bp, 4 +func X__lookup_name(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32, flags int32) int32 { /* lookup_name.c:311:5: */ + bp := tls.Alloc(92) + defer tls.Free(92) - // var a6 in6_addr at bp+68, 16 + var cnt int32 = 0 + var i int32 + var j int32 + _ = j - if X__inet_aton(tls, name, bp /* &a4 */) > 0 { - if family == 10 { // wrong family + *(*int8)(unsafe.Pointer(canon)) = int8(0) + if name != 0 { + // reject empty name and check len so it fits into temp bufs + var l size_t = Xstrnlen(tls, name, uint32(255)) + if (l - size_t(1)) >= size_t(254) { return -2 } - Xmemcpy(tls, (buf + 8 /* &.addr */), bp /* &a4 */, uint32(unsafe.Sizeof(in_addr{}))) - (*address)(unsafe.Pointer(buf)).family = 2 - (*address)(unsafe.Pointer(buf)).scopeid = uint32(0) - return 1 + Xmemcpy(tls, canon, name, (l + size_t(1))) } - // var tmp [64]int8 at bp+4, 64 - - var p uintptr = Xstrchr(tls, name, '%') - // var z uintptr at bp+84, 4 - var scopeid uint64 = uint64(0) - if (p != 0) && (((int32(p) - int32(name)) / 1) < 64) { - Xmemcpy(tls, bp+4 /* &tmp[0] */, name, (uint32((int32(p) - int32(name)) / 1))) - *(*int8)(unsafe.Pointer(bp + 4 /* &tmp[0] */ + uintptr(((int32(p) - int32(name)) / 1)))) = int8(0) - name = bp + 4 /* &tmp[0] */ + // Procedurally, a request for v6 addresses with the v4-mapped + // flag set is like a request for unspecified family, followed + // by filtering of the results. + if (flags & 0x08) != 0 { + if family == 10 { + family = 0 + } else { + flags = flags - (0x08) + } } - if Xinet_pton(tls, 10, name, bp+68 /* &a6 */) <= 0 { - return 0 + // Try each backend until there's at least one result. + cnt = name_from_null(tls, buf, name, family, flags) + if !(cnt != 0) { + cnt = name_from_numeric(tls, buf, name, family) } - if family == 2 { // wrong family + if !(cnt != 0) && !((flags & 0x04) != 0) { + cnt = name_from_hosts(tls, buf, canon, name, family) + if !(cnt != 0) { + cnt = name_from_dns_search(tls, buf, canon, name, family) + } + } + if cnt <= 0 { + if cnt != 0 { + return cnt + } return -2 } - Xmemcpy(tls, (buf + 8 /* &.addr */), bp+68 /* &a6 */, uint32(unsafe.Sizeof(in6_addr{}))) - (*address)(unsafe.Pointer(buf)).family = 10 - if p != 0 { - if func() int32 { - if 0 != 0 { - return Xisdigit(tls, int32(*(*int8)(unsafe.Pointer(PreIncUintptr(&p, 1))))) - } - return (Bool32(((uint32(*(*int8)(unsafe.Pointer(PreIncUintptr(&p, 1))))) - uint32('0')) < uint32(10))) - }() != 0 { - scopeid = Xstrtoull(tls, p, bp+84 /* &z */, 10) - } else { - *(*uintptr)(unsafe.Pointer(bp + 84 /* z */)) = (p - uintptr(1)) - } - if *(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp + 84 /* z */)))) != 0 { - Xabort(tls) //TODO- - // if (!IN6_IS_ADDR_LINKLOCAL(&a6) && - // !IN6_IS_ADDR_MC_LINKLOCAL(&a6)) - // return EAI_NONAME; - // scopeid = if_nametoindex(p); - // if (!scopeid) return EAI_NONAME; - } - if scopeid > uint64(0xffffffff) { - return -2 - } + // Filter/transform results for v4-mapped lookup, if requested. + if (flags & 0x08) != 0 { + Xabort(tls) //TODO- + // if (!(flags & AI_ALL)) { + // /* If any v6 results exist, remove v4 results. */ + // for (i=0; i= 254 || mbstowcs(0, host, 0) == -1) return 0; - if (Xstrnlen(tls, host, uint32(255)) - size_t(1)) >= size_t(254) { - return 0 + // No further processing is needed if there are fewer than 2 + // results or if there are only IPv4 results. + if (cnt < 2) || (family == 2) { + return cnt } - for s = host; (((int32(*(*uint8)(unsafe.Pointer(s))) >= 0x80) || (int32(*(*uint8)(unsafe.Pointer(s))) == '.')) || (int32(*(*uint8)(unsafe.Pointer(s))) == '-')) || (Xisalnum(tls, int32(*(*uint8)(unsafe.Pointer(s)))) != 0); s++ { + for i = 0; i < cnt; i++ { + if (*address)(unsafe.Pointer(buf+uintptr(i)*28)).family != 2 { + break + } + } + if i == cnt { + return cnt } - return BoolInt32(!(*(*uint8)(unsafe.Pointer(s)) != 0)) -} + var cs int32 + _ = cs + //TODO pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs); -var Xzero_struct_address address /* lookup_name.c:27:16: */ + // The following implements a subset of RFC 3484/6724 destination + // address selection by generating a single 31-bit sort key for + // each address. Rules 3, 4, and 7 are omitted for having + // excessive runtime and code size cost and dubious benefit. + // So far the label/precedence table cannot be customized. + for i = 0; i < cnt; i++ { + var family int32 = (*address)(unsafe.Pointer(buf + uintptr(i)*28)).family + var key int32 = 0 + *(*sockaddr_in6)(unsafe.Pointer(bp + 28 /* sa6 */)) = sockaddr_in6{} + *(*sockaddr_in6)(unsafe.Pointer(bp /* da6 */)) = sockaddr_in6{sin6_family: sa_family_t(10), sin6_port: in_port_t(65535), sin6_scope_id: (*address)(unsafe.Pointer(buf + uintptr(i)*28)).scopeid} + *(*sockaddr_in)(unsafe.Pointer(bp + 72 /* sa4 */)) = sockaddr_in{} + *(*sockaddr_in)(unsafe.Pointer(bp + 56 /* da4 */)) = sockaddr_in{sin_family: sa_family_t(2), sin_port: in_port_t(65535)} + var sa1 uintptr + var da uintptr + // var salen socklen_t at bp+88, 4 -func name_from_null(tls *TLS, buf uintptr, name uintptr, family int32, flags int32) int32 { /* lookup_name.c:29:12: */ - var cnt int32 = 0 - if name != 0 { - return 0 - } - if (flags & 0x01) != 0 { - //TODO if (family != AF_INET6) - //TODO buf[cnt++] = (struct address){ .family = AF_INET }; - if family != 10 { - var x = Xzero_struct_address - x.family = 2 - *(*address)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*28)) = x + var dalen socklen_t + if family == 10 { + Xmemcpy(tls, bp /* &da6 */ +8 /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */, buf+uintptr(i)*28+8 /* &.addr */, uint32(16)) + da = bp /* &da6 */ + dalen = socklen_t(unsafe.Sizeof(sockaddr_in6{})) + sa1 = bp + 28 /* &sa6 */ + *(*socklen_t)(unsafe.Pointer(bp + 88 /* salen */)) = socklen_t(unsafe.Sizeof(sockaddr_in6{})) + } else { + Xmemcpy(tls, bp+28 /* &sa6 */ +8, /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */ + ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) + Xmemcpy(tls, ((bp /* &da6 */ + 8 /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */) + uintptr(12)), buf+uintptr(i)*28+8 /* &.addr */, uint32(4)) + Xmemcpy(tls, bp /* &da6 */ +8, /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */ + ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint32(12)) + Xmemcpy(tls, ((bp /* &da6 */ + 8 /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */) + uintptr(12)), buf+uintptr(i)*28+8 /* &.addr */, uint32(4)) + Xmemcpy(tls, (bp + 56 /* &da4 */ + 4 /* &.sin_addr */), buf+uintptr(i)*28+8 /* &.addr */, uint32(4)) + da = bp + 56 /* &da4 */ + dalen = socklen_t(unsafe.Sizeof(sockaddr_in{})) + sa1 = bp + 72 /* &sa4 */ + *(*socklen_t)(unsafe.Pointer(bp + 88 /* salen */)) = socklen_t(unsafe.Sizeof(sockaddr_in{})) } - //TODO if (family != AF_INET) - //TODO buf[cnt++] = (struct address){ .family = AF_INET6 }; - if family != 2 { - var x = Xzero_struct_address - x.family = 10 - *(*address)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*28)) = x + var dpolicy uintptr = policyof(tls, (bp /* &da6 */ + 8 /* &.sin6_addr */)) + var dscope int32 = scopeof(tls, (bp /* &da6 */ + 8 /* &.sin6_addr */)) + var dlabel int32 = int32((*policy)(unsafe.Pointer(dpolicy)).label) + var dprec int32 = int32((*policy)(unsafe.Pointer(dpolicy)).prec) + var prefixlen int32 = 0 + var fd int32 = Xsocket(tls, family, (2 | 02000000), 17) + if fd >= 0 { + if !(Xconnect(tls, fd, da, dalen) != 0) { + key = key | (0x40000000) + if !(Xgetsockname(tls, fd, sa1, bp+88 /* &salen */) != 0) { + if family == 2 { + Xmemcpy(tls, + ((bp + 28 /* &sa6 */ + 8 /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */) + uintptr(12)), + (bp + 72 /* &sa4 */ + 4 /* &.sin_addr */), uint32(4)) + } + if dscope == scopeof(tls, (bp+28 /* &sa6 */ +8 /* &.sin6_addr */)) { + key = key | (0x20000000) + } + if dlabel == labelof(tls, (bp+28 /* &sa6 */ +8 /* &.sin6_addr */)) { + key = key | (0x10000000) + } + prefixlen = prefixmatch(tls, (bp + 28 /* &sa6 */ + 8 /* &.sin6_addr */), + (bp /* &da6 */ + 8 /* &.sin6_addr */)) + } + } + Xclose(tls, fd) } - } else { - Xabort(tls) //TODO- - // if (family != AF_INET6) - // buf[cnt++] = (struct address){ .family = AF_INET, .addr = { 127,0,0,1 } }; - // if (family != AF_INET) - // buf[cnt++] = (struct address){ .family = AF_INET6, .addr = { [15] = 1 } }; + key = key | (dprec << 20) + key = key | ((15 - dscope) << 16) + key = key | (prefixlen << 8) + key = key | ((48 - i) << 0) + (*address)(unsafe.Pointer(buf + uintptr(i)*28)).sortkey = key } - return cnt -} + Xqsort(tls, buf, uint32(cnt), uint32(unsafe.Sizeof(address{})), *(*uintptr)(unsafe.Pointer(&struct { + f func(*TLS, uintptr, uintptr) int32 + }{addrcmp}))) -func name_from_numeric(tls *TLS, buf uintptr, name uintptr, family int32) int32 { /* lookup_name.c:58:12: */ - return X__lookup_ipliteral(tls, buf, name, family) -} + //TODO pthread_setcancelstate(cs, 0); -func name_from_hosts(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32) int32 { /* lookup_name.c:63:12: */ - bp := tls.Alloc(512) - defer tls.Free(512) + return cnt +} - // var line [512]int8 at bp, 512 +func X__lookup_serv(tls *TLS, buf uintptr, name uintptr, proto int32, socktype int32, flags int32) int32 { /* lookup_serv.c:12:5: */ + bp := tls.Alloc(4) + defer tls.Free(4) - var l size_t = Xstrlen(tls, name) + var line [128]int8 + _ = line var cnt int32 = 0 - var badfam int32 = 0 - var _buf [1032]uint8 - _ = _buf - //TODO FILE _f, *f = __fopen_rb_ca("/etc/hosts", &_f, _buf, sizeof _buf); - var _f FILE - _ = _f - var f uintptr = Xfopen(tls, ts+74 /* "/etc/hosts" */, ts+85 /* "rb" */) - if !(f != 0) { - switch *(*int32)(unsafe.Pointer(X___errno_location(tls))) { - case 2: - fallthrough - case 20: - fallthrough - case 13: - return 0 + var p uintptr + _ = p + *(*uintptr)(unsafe.Pointer(bp /* z */)) = ts + 13 /* "" */ + var port uint32 = uint32(0) + + switch socktype { + case 1: + switch proto { + case 0: + proto = 6 fallthrough + case 6: + break default: - return -11 - } - } - for (Xfgets(tls, bp /* &line[0] */, int32(unsafe.Sizeof([512]int8{})), f) != 0) && (cnt < 48) { - var p uintptr - var z uintptr - - if AssignUintptr(&p, Xstrchr(tls, bp /* &line[0] */, '#')) != 0 { - *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8('\n') - *(*int8)(unsafe.Pointer(p)) = int8(0) - } - for p = (bp /* &line[0] */ + uintptr(1)); (AssignUintptr(&p, Xstrstr(tls, p, name)) != 0) && (!(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p + UintptrFromInt32(-1))))) != 0) || !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p + uintptr(l))))) != 0)); p++ { - } - if !(p != 0) { - continue - } - - // Isolate IP address to parse - for p = bp; /* &line[0] */ (*(*int8)(unsafe.Pointer(p)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + return -8 } - *(*int8)(unsafe.Pointer(PostIncUintptr(&p, 1))) = int8(0) - switch name_from_numeric(tls, (buf + uintptr(cnt)*28), bp /* &line[0] */, family) { - case 1: - cnt++ - break + break + case 2: + switch proto { case 0: - continue + proto = 17 + fallthrough + case 17: + break default: - badfam = -2 - continue + return -8 + } + fallthrough + case 0: + break + default: + if name != 0 { + return -8 } + (*service)(unsafe.Pointer(buf)).port = uint16_t(0) + (*service)(unsafe.Pointer(buf)).proto = uint8(proto) + (*service)(unsafe.Pointer(buf)).socktype = uint8(socktype) + return 1 + } - // Extract first name as canonical name - for ; (*(*int8)(unsafe.Pointer(p)) != 0) && (__isspace(tls, int32(*(*int8)(unsafe.Pointer(p)))) != 0); p++ { + if name != 0 { + if !(int32(*(*int8)(unsafe.Pointer(name))) != 0) { + return -8 } - for z = p; (*(*int8)(unsafe.Pointer(z)) != 0) && !(__isspace(tls, int32(*(*int8)(unsafe.Pointer(z)))) != 0); z++ { + port = Xstrtoul(tls, name, bp /* &z */, 10) + } + if !(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp /* z */))))) != 0) { + if port > uint32(65535) { + return -8 } - *(*int8)(unsafe.Pointer(z)) = int8(0) - if is_valid_hostname(tls, p) != 0 { - Xmemcpy(tls, canon, p, (uint32(((int32(z) - int32(p)) / 1) + 1))) + if proto != 17 { + (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).port = uint16_t(port) + (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).socktype = uint8(1) + (*service)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*4)).proto = uint8(6) + } + if proto != 6 { + (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).port = uint16_t(port) + (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).socktype = uint8(2) + (*service)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*4)).proto = uint8(17) } - } - //TODO __fclose_ca(f); - Xfclose(tls, f) - if cnt != 0 { return cnt } - return badfam -} - -type dpc_ctx = struct { - addrs uintptr - canon uintptr - cnt int32 -} /* lookup_name.c:112:1 */ -func name_from_dns_search(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32) int32 { /* lookup_name.c:191:12: */ - return -1 //TODO- - Xabort(tls) - return int32(0) //TODO- - // char search[256]; - // struct resolvconf conf; - // size_t l, dots; - // char *p, *z; + if (flags & 0x400) != 0 { + return -2 + } - // if (__get_resolv_conf(&conf, search, sizeof search) < 0) return -1; + var l size_t = Xstrlen(tls, name) + _ = l - // /* Count dots, suppress search when >=ndots or name ends in - // * a dot, which is an explicit request for global scope. */ - // for (dots=l=0; name[l]; l++) if (name[l]=='.') dots++; - // if (dots >= conf.ndots || name[l-1]=='.') *search = 0; + Xabort(tls) //TODO- + // unsigned char _buf[1032]; + // FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); + // if (!f) switch (errno) { + // case ENOENT: + // case ENOTDIR: + // case EACCES: + // return EAI_SERVICE; + // default: + // return EAI_SYSTEM; + // } - // /* Strip final dot for canon, fail if multiple trailing dots. */ - // if (name[l-1]=='.') l--; - // if (!l || name[l-1]=='.') return EAI_NONAME; + Xabort(tls) //TODO- + // while (fgets(line, sizeof line, f) && cnt < MAXSERVS) { + // if ((p=strchr(line, '#'))) *p++='\n', *p=0; - // /* This can never happen; the caller already checked length. */ - // if (l >= 256) return EAI_NONAME; + // /* Find service name */ + // for(p=line; (p=strstr(p, name)); p++) { + // if (p>line && !isspace(p[-1])) continue; + // if (p[l] && !isspace(p[l])) continue; + // break; + // } + // if (!p) continue; - // /* Name with search domain appended is setup in canon[]. This both - // * provides the desired default canonical name (if the requested - // * name is not a CNAME record) and serves as a buffer for passing - // * the full requested name to name_from_dns. */ - // memcpy(canon, name, l); - // canon[l] = '.'; + // /* Skip past canonical name at beginning of line */ + // for (p=line; *p && !isspace(*p); p++); - // for (p=search; *p; p=z) { - // for (; isspace(*p); p++); - // for (z=p; *z && !isspace(*z); z++); - // if (z==p) break; - // if (z-p < 256 - l - 1) { - // memcpy(canon+l+1, p, z-p); - // canon[z-p+1+l] = 0; - // int cnt = name_from_dns(buf, canon, canon, family, &conf); - // if (cnt) return cnt; + // port = strtoul(p, &z, 10); + // if (port > 65535 || z==p) continue; + // if (!strncmp(z, "/udp", 4)) { + // if (proto == IPPROTO_TCP) continue; + // buf[cnt].port = port; + // buf[cnt].socktype = SOCK_DGRAM; + // buf[cnt++].proto = IPPROTO_UDP; + // } + // if (!strncmp(z, "/tcp", 4)) { + // if (proto == IPPROTO_UDP) continue; + // buf[cnt].port = port; + // buf[cnt].socktype = SOCK_STREAM; + // buf[cnt++].proto = IPPROTO_TCP; // } // } - - // canon[l] = 0; - // return name_from_dns(buf, canon, name, family, &conf); + // __fclose_ca(f); + // return cnt > 0 ? cnt : EAI_SERVICE; + Xabort(tls) + return int32(0) //TODO- } -type policy = struct { - addr [16]uint8 - len uint8 - mask uint8 - prec uint8 - label uint8 -} /* lookup_name.c:237:14 */ +func temper(tls *TLS, x uint32) uint32 { /* rand_r.c:3:17: */ + x = x ^ (x >> 11) + x = x ^ ((x << 7) & 0x9D2C5680) + x = x ^ ((x << 15) & 0xEFC60000) + x = x ^ (x >> 18) + return x +} -var defpolicy = [6]policy{ - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 170 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01" */)), len: uint8(15), mask: uint8(0xff), prec: uint8(50)}, - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 187 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00" */)), len: uint8(11), mask: uint8(0xff), prec: uint8(35), label: uint8(4)}, - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 203 /* " \x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), len: uint8(1), mask: uint8(0xff), prec: uint8(30), label: uint8(2)}, - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 219 /* " \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), len: uint8(3), mask: uint8(0xff), prec: uint8(5), label: uint8(5)}, - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 235 /* "\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), mask: uint8(0xfe), prec: uint8(3), label: uint8(13)}, - // Last rule must match all addresses to stop loop. - {addr: *(*[16]uint8)(unsafe.Pointer(ts + 251 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" */)), prec: uint8(40), label: uint8(1)}, -} /* lookup_name.c:241:3 */ +func Xrand_r(tls *TLS, seed uintptr) int32 { /* rand_r.c:12:5: */ + return (int32(temper(tls, AssignPtrUint32(seed, ((*(*uint32)(unsafe.Pointer(seed))*uint32(1103515245))+uint32(12345)))) / uint32(2))) +} -func policyof(tls *TLS, a uintptr) uintptr { /* lookup_name.c:259:28: */ - var i int32 - for i = 0; ; i++ { - if Xmemcmp(tls, a /* &.__in6_union */ /* &.__s6_addr */, uintptr(unsafe.Pointer(&defpolicy))+uintptr(i)*20 /* &.addr */, uint32(defpolicy[i].len)) != 0 { - continue - } - if (int32(*(*uint8_t)(unsafe.Pointer((a /* &.__in6_union */ /* &.__s6_addr */) + uintptr(defpolicy[i].len)))) & int32(defpolicy[i].mask)) != - int32(*(*uint8)(unsafe.Pointer((uintptr(unsafe.Pointer(&defpolicy)) + uintptr(i)*20 /* &.addr */) + uintptr(defpolicy[i].len)))) { - continue +func X__lockfile(tls *TLS, f uintptr) int32 { /* __lockfile.c:4:5: */ + var owner int32 = (*FILE)(unsafe.Pointer(f)).lock + var tid int32 = (*__pthread)(unsafe.Pointer(__pthread_self(tls))).tid + if (owner & CplInt32(0x40000000)) == tid { + return 0 + } + owner = a_cas(tls, (f + 76 /* &.lock */), 0, tid) + if !(owner != 0) { + return 1 + } + for AssignInt32(&owner, a_cas(tls, (f+76 /* &.lock */), 0, (tid|0x40000000))) != 0 { + if ((owner & 0x40000000) != 0) || (a_cas(tls, (f+76 /* &.lock */), owner, (owner|0x40000000)) == owner) { + __futexwait(tls, (f + 76 /* &.lock */), (owner | 0x40000000), 1) } - return (uintptr(unsafe.Pointer(&defpolicy)) + uintptr(i)*20) } - return uintptr(0) + return 1 } -func labelof(tls *TLS, a uintptr) int32 { /* lookup_name.c:272:12: */ - return int32((*policy)(unsafe.Pointer(policyof(tls, a))).label) +func X__unlockfile(tls *TLS, f uintptr) { /* __lockfile.c:19:6: */ + if (a_swap(tls, (f+76 /* &.lock */), 0) & 0x40000000) != 0 { + __wake(tls, (f + 76 /* &.lock */), 1, 1) + } } -func scopeof(tls *TLS, a uintptr) int32 { /* lookup_name.c:277:12: */ - if int32(*(*uint8_t)(unsafe.Pointer((a)))) == 0xff { - return (int32(*(*uint8_t)(unsafe.Pointer((a /* &.__in6_union */ /* &.__s6_addr */) + 1))) & 15) +func X__toread(tls *TLS, f uintptr) int32 { /* __toread.c:3:5: */ + *(*int32)(unsafe.Pointer(f + 72 /* &.mode */)) |= ((*FILE)(unsafe.Pointer(f)).mode - 1) + if (*FILE)(unsafe.Pointer(f)).wpos != (*FILE)(unsafe.Pointer(f)).wbase { + (*(*func(*TLS, uintptr, uintptr, size_t) size_t)(unsafe.Pointer((f + 36 /* &.write */))))(tls, f, uintptr(0), uint32(0)) } - if ((int32(*(*uint8_t)(unsafe.Pointer((a))))) == 0xfe) && ((int32(*(*uint8_t)(unsafe.Pointer((a) + 1))) & 0xc0) == 0x80) { - return 2 + (*FILE)(unsafe.Pointer(f)).wpos = AssignPtrUintptr(f+28 /* &.wbase */, AssignPtrUintptr(f+16 /* &.wend */, uintptr(0))) + if ((*FILE)(unsafe.Pointer(f)).flags & uint32(4)) != 0 { + *(*uint32)(unsafe.Pointer(f /* &.flags */)) |= (uint32(32)) + return -1 } - if ((((((*(*uint32_t)(unsafe.Pointer((a))) == uint32_t(0)) && (*(*uint32_t)(unsafe.Pointer((a) + 1*4)) == uint32_t(0))) && (*(*uint32_t)(unsafe.Pointer((a) + 2*4)) == uint32_t(0))) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 12))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 13))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 14))) == 0)) && (int32(*(*uint8_t)(unsafe.Pointer((a) + 15))) == 1) { - return 2 + (*FILE)(unsafe.Pointer(f)).rpos = AssignPtrUintptr(f+8 /* &.rend */, ((*FILE)(unsafe.Pointer(f)).buf + uintptr((*FILE)(unsafe.Pointer(f)).buf_size))) + if ((*FILE)(unsafe.Pointer(f)).flags & uint32(16)) != 0 { + return -1 } - if ((int32(*(*uint8_t)(unsafe.Pointer((a))))) == 0xfe) && ((int32(*(*uint8_t)(unsafe.Pointer((a) + 1))) & 0xc0) == 0xc0) { - return 5 + return 0 +} + +func X__toread_needs_stdio_exit(tls *TLS) { /* __toread.c:16:13: */ + X__builtin_abort(tls) //TODO- + // __stdio_exit_needed(); +} + +// This function assumes it will never be called if there is already +// data buffered for reading. + +func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */ + bp := tls.Alloc(1) + defer tls.Free(1) + + // var c uint8 at bp, 1 + + if !(X__toread(tls, f) != 0) && ((*(*func(*TLS, uintptr, uintptr, size_t) size_t)(unsafe.Pointer((f + 32 /* &.read */))))(tls, f, bp /* &c */, uint32(1)) == size_t(1)) { + return int32(*(*uint8)(unsafe.Pointer(bp /* c */))) } - return 14 + return -1 } -func prefixmatch(tls *TLS, s uintptr, d uintptr) int32 { /* lookup_name.c:286:12: */ - // FIXME: The common prefix length should be limited to no greater - // than the nominal length of the prefix portion of the source - // address. However the definition of the source prefix length is - // not clear and thus this limiting is not yet implemented. - var i uint32 - for i = uint32(0); (i < uint32(128)) && !(((int32(*(*uint8_t)(unsafe.Pointer((s /* &.__in6_union */ /* &.__s6_addr */) + uintptr((i / uint32(8)))))) ^ int32(*(*uint8_t)(unsafe.Pointer((d /* &.__in6_union */ /* &.__s6_addr */) + uintptr((i / uint32(8))))))) & (int32(128) >> (i % uint32(8)))) != 0); i++ { +func Xsscanf(tls *TLS, s uintptr, fmt uintptr, va uintptr) int32 { /* sscanf.c:4:5: */ + var ret int32 + var ap va_list + _ = ap + ap = va + ret = Xvsscanf(tls, s, fmt, ap) + _ = ap + return ret +} + +type wctrans_t = uintptr /* wctype.h:20:19 */ + +func store_int(tls *TLS, dest uintptr, size int32, i uint64) { /* vfscanf.c:22:13: */ + if !(dest != 0) { + return + } + switch size { + case -2: + *(*int8)(unsafe.Pointer(dest)) = int8(i) + break + case -1: + *(*int16)(unsafe.Pointer(dest)) = int16(i) + break + case 0: + *(*int32)(unsafe.Pointer(dest)) = int32(i) + break + case 1: + *(*int32)(unsafe.Pointer(dest)) = int32(i) + break + case 3: + *(*int64)(unsafe.Pointer(dest)) = int64(i) + break } - return int32(i) } -func addrcmp(tls *TLS, _a uintptr, _b uintptr) int32 { /* lookup_name.c:305:12: */ - var a uintptr = _a - var b uintptr = _b - return ((*address)(unsafe.Pointer(b)).sortkey - (*address)(unsafe.Pointer(a)).sortkey) +func arg_n(tls *TLS, ap va_list, n uint32) uintptr { /* vfscanf.c:44:13: */ + var p uintptr + var i uint32 + var ap2 va_list + _ = ap2 + ap2 = ap + for i = n; i > uint32(1); i-- { + VaUintptr(&ap2) + } + p = VaUintptr(&ap2) + _ = ap2 + return p } -func X__lookup_name(tls *TLS, buf uintptr, canon uintptr, name uintptr, family int32, flags int32) int32 { /* lookup_name.c:311:5: */ - bp := tls.Alloc(92) - defer tls.Free(92) +func Xvfscanf(tls *TLS, f uintptr, fmt uintptr, ap va_list) int32 { /* vfscanf.c:56:5: */ + bp := tls.Alloc(276) + defer tls.Free(276) - var cnt int32 = 0 - var i int32 - var j int32 - _ = j + var width int32 + var size int32 + var alloc int32 + var base int32 + var p uintptr + var c int32 + var t int32 + var s uintptr + var wcs uintptr + // var st mbstate_t at bp+268, 8 - *(*int8)(unsafe.Pointer(canon)) = int8(0) - if name != 0 { - // reject empty name and check len so it fits into temp bufs - var l size_t = Xstrnlen(tls, name, uint32(255)) - if (l - size_t(1)) >= size_t(254) { - return -2 + var dest uintptr + var invert int32 + var matches int32 + var x uint64 + var y float64 + var pos off_t + // var scanset [257]uint8 at bp, 257 + + var i size_t + var k size_t + // var wc wchar_t at bp+260, 4 + + var __need_unlock int32 + var tmp uintptr + var tmp1 uintptr + alloc = 0 + dest = uintptr(0) + matches = 0 + pos = int64(0) + __need_unlock = func() int32 { + if (*FILE)(unsafe.Pointer((f))).lock >= 0 { + return X__lockfile(tls, f) } - Xmemcpy(tls, canon, name, (l + size_t(1))) + return 0 + }() + + if !(!(int32((*FILE)(unsafe.Pointer(f)).rpos) != 0)) { + goto __1 } + X__toread(tls, f) +__1: + ; + if !(!(int32((*FILE)(unsafe.Pointer(f)).rpos) != 0)) { + goto __2 + } + goto input_fail +__2: + ; - // Procedurally, a request for v6 addresses with the v4-mapped - // flag set is like a request for unspecified family, followed - // by filtering of the results. - if (flags & 0x08) != 0 { - if family == 10 { - family = 0 - } else { - flags = flags - (0x08) - } + p = fmt +__3: + if !(*(*uint8)(unsafe.Pointer(p)) != 0) { + goto __5 } - // Try each backend until there's at least one result. - cnt = name_from_null(tls, buf, name, family, flags) - if !(cnt != 0) { - cnt = name_from_numeric(tls, buf, name, family) + alloc = 0 + + if !(__isspace(tls, int32(*(*uint8)(unsafe.Pointer(p)))) != 0) { + goto __6 } - if !(cnt != 0) && !((flags & 0x04) != 0) { - cnt = name_from_hosts(tls, buf, canon, name, family) - if !(cnt != 0) { - cnt = name_from_dns_search(tls, buf, canon, name, family) +__7: + if !(__isspace(tls, int32(*(*uint8)(unsafe.Pointer(p + 1)))) != 0) { + goto __8 + } + p++ + goto __7 +__8: + ; + X__shlim(tls, f, int64(0)) +__9: + if !(__isspace(tls, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) + } + return X__shgetc(tls, f) + }()) != 0) { + goto __10 + } + goto __9 +__10: + ; + if (*FILE)(unsafe.Pointer((f))).shlim >= int64(0) { + (*FILE)(unsafe.Pointer(f)).rpos-- + } else { + } + pos = pos + ((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) + goto __4 +__6: + ; + if !((int32(*(*uint8)(unsafe.Pointer(p))) != '%') || (int32(*(*uint8)(unsafe.Pointer(p + 1))) == '%')) { + goto __11 + } + X__shlim(tls, f, int64(0)) + if !(int32(*(*uint8)(unsafe.Pointer(p))) == '%') { + goto __12 + } + p++ +__14: + if !(__isspace(tls, AssignInt32(&c, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) + } + return X__shgetc(tls, f) + }())) != 0) { + goto __15 + } + goto __14 +__15: + ; + goto __13 +__12: + c = func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } + return X__shgetc(tls, f) + }() +__13: + ; + if !(c != int32(*(*uint8)(unsafe.Pointer(p)))) { + goto __16 } - if cnt <= 0 { - if cnt != 0 { - return cnt - } - return -2 + if (*FILE)(unsafe.Pointer((f))).shlim >= int64(0) { + (*FILE)(unsafe.Pointer(f)).rpos-- + } else { } - - // Filter/transform results for v4-mapped lookup, if requested. - if (flags & 0x08) != 0 { - Xabort(tls) //TODO- - // if (!(flags & AI_ALL)) { - // /* If any v6 results exist, remove v4 results. */ - // for (i=0; i= 0 { - if !(Xconnect(tls, fd, da, dalen) != 0) { - key = key | (0x40000000) - if !(Xgetsockname(tls, fd, sa1, bp+88 /* &salen */) != 0) { - if family == 2 { - Xmemcpy(tls, - ((bp + 28 /* &sa6 */ + 8 /* &.sin6_addr */ /* &.__in6_union */ /* &.__s6_addr */) + uintptr(12)), - (bp + 72 /* &sa4 */ + 4 /* &.sin_addr */), uint32(4)) - } - if dscope == scopeof(tls, (bp+28 /* &sa6 */ +8 /* &.sin6_addr */)) { - key = key | (0x20000000) - } - if dlabel == labelof(tls, (bp+28 /* &sa6 */ +8 /* &.sin6_addr */)) { - key = key | (0x10000000) - } - prefixlen = prefixmatch(tls, (bp + 28 /* &sa6 */ + 8 /* &.sin6_addr */), - (bp /* &da6 */ + 8 /* &.sin6_addr */)) - } - } - Xclose(tls, fd) + width = 0 +__22: + if !(func() int32 { + if 0 != 0 { + return Xisdigit(tls, int32(*(*uint8)(unsafe.Pointer(p)))) } - key = key | (dprec << 20) - key = key | ((15 - dscope) << 16) - key = key | (prefixlen << 8) - key = key | ((48 - i) << 0) - (*address)(unsafe.Pointer(buf + uintptr(i)*28)).sortkey = key + return (Bool32(((uint32(*(*uint8)(unsafe.Pointer(p)))) - uint32('0')) < uint32(10))) + }() != 0) { + goto __24 } - Xqsort(tls, buf, uint32(cnt), uint32(unsafe.Sizeof(address{})), *(*uintptr)(unsafe.Pointer(&struct { - f func(*TLS, uintptr, uintptr) int32 - }{addrcmp}))) + width = (((10 * width) + int32(*(*uint8)(unsafe.Pointer(p)))) - '0') + goto __23 +__23: + p++ + goto __22 + goto __24 +__24: + ; - //TODO pthread_setcancelstate(cs, 0); + if !(int32(*(*uint8)(unsafe.Pointer(p))) == 'm') { + goto __25 + } + wcs = uintptr(0) + s = uintptr(0) + alloc = BoolInt32(!(!(dest != 0))) + p++ + goto __26 +__25: + alloc = 0 +__26: + ; - return cnt -} + size = 0 + switch int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&p, 1)))) { + case 'h': + goto __28 + case 'l': + goto __29 + case 'j': + goto __30 + case 'z': + goto __31 + case 't': + goto __32 + case 'L': + goto __33 + case 'd': + goto __34 + case 'i': + goto __35 + case 'o': + goto __36 + case 'u': + goto __37 + case 'x': + goto __38 + case 'a': + goto __39 + case 'e': + goto __40 + case 'f': + goto __41 + case 'g': + goto __42 + case 'A': + goto __43 + case 'E': + goto __44 + case 'F': + goto __45 + case 'G': + goto __46 + case 'X': + goto __47 + case 's': + goto __48 + case 'c': + goto __49 + case '[': + goto __50 + case 'S': + goto __51 + case 'C': + goto __52 + case 'p': + goto __53 + case 'n': + goto __54 + default: + goto __55 + } + goto __27 +__28: + if !(int32(*(*uint8)(unsafe.Pointer(p))) == 'h') { + goto __56 + } + p++ + size = -2 + goto __57 +__56: + size = -1 +__57: + ; + goto __27 +__29: + if !(int32(*(*uint8)(unsafe.Pointer(p))) == 'l') { + goto __58 + } + p++ + size = 3 + goto __59 +__58: + size = 1 +__59: + ; + goto __27 +__30: + size = 3 + goto __27 +__31: +__32: + size = 1 + goto __27 +__33: + size = 2 + goto __27 +__34: +__35: +__36: +__37: +__38: +__39: +__40: +__41: +__42: +__43: +__44: +__45: +__46: +__47: +__48: +__49: +__50: +__51: +__52: +__53: +__54: + p-- + goto __27 +__55: + goto fmt_fail +__27: + ; -func X__lookup_serv(tls *TLS, buf uintptr, name uintptr, proto int32, socktype int32, flags int32) int32 { /* lookup_serv.c:12:5: */ - bp := tls.Alloc(4) - defer tls.Free(4) + t = int32(*(*uint8)(unsafe.Pointer(p))) - var line [128]int8 - _ = line - var cnt int32 = 0 - var p uintptr - _ = p - *(*uintptr)(unsafe.Pointer(bp /* z */)) = ts + 13 /* "" */ - var port uint32 = uint32(0) + // C or S + if !((t & 0x2f) == 3) { + goto __60 + } + t = t | (32) + size = 1 +__60: + ; - switch socktype { - case 1: - switch proto { - case 0: - proto = 6 - fallthrough - case 6: - break - default: - return -8 - } - break - case 2: - switch proto { - case 0: - proto = 17 - fallthrough - case 17: - break - default: - return -8 - } - fallthrough - case 0: - break + switch t { + case 'c': + goto __62 + case '[': + goto __63 + case 'n': + goto __64 default: - if name != 0 { - return -8 + goto __65 + } + goto __61 +__62: + if !(width < 1) { + goto __66 + } + width = 1 +__66: + ; +__63: + goto __61 +__64: + store_int(tls, dest, size, uint64(pos)) + // do not increment match count, etc! + goto __4 +__65: + X__shlim(tls, f, int64(0)) +__67: + if !(__isspace(tls, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } - (*service)(unsafe.Pointer(buf)).port = uint16_t(0) - (*service)(unsafe.Pointer(buf)).proto = uint8(proto) - (*service)(unsafe.Pointer(buf)).socktype = uint8(socktype) - return 1 + return X__shgetc(tls, f) + }()) != 0) { + goto __68 + } + goto __67 +__68: + ; + if (*FILE)(unsafe.Pointer((f))).shlim >= int64(0) { + (*FILE)(unsafe.Pointer(f)).rpos-- + } else { + } + pos = pos + ((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) +__61: + ; + + X__shlim(tls, f, int64(width)) + if !((func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) + } + return X__shgetc(tls, f) + }()) < 0) { + goto __69 + } + goto input_fail +__69: + ; + if (*FILE)(unsafe.Pointer((f))).shlim >= int64(0) { + (*FILE)(unsafe.Pointer(f)).rpos-- + } else { } - if name != 0 { - if !(int32(*(*int8)(unsafe.Pointer(name))) != 0) { - return -8 + switch t { + case 's': + goto __71 + case 'c': + goto __72 + case '[': + goto __73 + case 'p': + goto __74 + case 'X': + goto __75 + case 'x': + goto __76 + case 'o': + goto __77 + case 'd': + goto __78 + case 'u': + goto __79 + case 'i': + goto __80 + case 'a': + goto __81 + case 'A': + goto __82 + case 'e': + goto __83 + case 'E': + goto __84 + case 'f': + goto __85 + case 'F': + goto __86 + case 'g': + goto __87 + case 'G': + goto __88 + } + goto __70 +__71: +__72: +__73: + if !((t == 'c') || (t == 's')) { + goto __89 + } + Xmemset(tls, bp /* &scanset[0] */, -1, uint32(unsafe.Sizeof([257]uint8{}))) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */)) = uint8(0) + if !(t == 's') { + goto __91 + } + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 10)) = uint8(0) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 11)) = uint8(0) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 12)) = uint8(0) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 13)) = uint8(0) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 14)) = uint8(0) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 33)) = uint8(0) +__91: + ; + goto __90 +__89: + if !(int32(*(*uint8)(unsafe.Pointer(PreIncUintptr(&p, 1)))) == '^') { + goto __92 + } + p++ + invert = 1 + goto __93 +__92: + invert = 0 +__93: + ; + Xmemset(tls, bp /* &scanset[0] */, invert, uint32(unsafe.Sizeof([257]uint8{}))) + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */)) = uint8(0) + if !(int32(*(*uint8)(unsafe.Pointer(p))) == '-') { + goto __94 + } + p++ + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 46)) = (uint8(1 - invert)) + goto __95 +__94: + if !(int32(*(*uint8)(unsafe.Pointer(p))) == ']') { + goto __96 + } + p++ + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + 94)) = (uint8(1 - invert)) +__96: + ; +__95: + ; +__97: + if !(int32(*(*uint8)(unsafe.Pointer(p))) != ']') { + goto __99 + } + if !(!(int32(*(*uint8)(unsafe.Pointer(p))) != 0)) { + goto __100 + } + goto fmt_fail +__100: + ; + if !(((int32(*(*uint8)(unsafe.Pointer(p))) == '-') && (*(*uint8)(unsafe.Pointer(p + 1)) != 0)) && (int32(*(*uint8)(unsafe.Pointer(p + 1))) != ']')) { + goto __101 + } + c = int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&p, 1) + UintptrFromInt32(-1)))) +__102: + if !(c < int32(*(*uint8)(unsafe.Pointer(p)))) { + goto __104 + } + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr((1 + c)))) = (uint8(1 - invert)) + goto __103 +__103: + c++ + goto __102 + goto __104 +__104: + ; +__101: + ; + *(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr((1 + int32(*(*uint8)(unsafe.Pointer(p))))))) = (uint8(1 - invert)) + goto __98 +__98: + p++ + goto __97 + goto __99 +__99: + ; +__90: + ; + wcs = uintptr(0) + s = uintptr(0) + i = size_t(0) + if t == 'c' { + k = (uint32(width) + 1) + } else { + k = uint32(31) + } + if !(size == 1) { + goto __105 + } + if !(alloc != 0) { + goto __107 + } + wcs = Xmalloc(tls, (k * size_t(unsafe.Sizeof(wchar_t(0))))) + if !(!(wcs != 0)) { + goto __109 + } + goto alloc_fail +__109: + ; + goto __108 +__107: + wcs = dest +__108: + ; + *(*mbstate_t)(unsafe.Pointer(bp + 268 /* st */)) = mbstate_t{} +__110: + if !(*(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr(((AssignInt32(&c, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } - port = Xstrtoul(tls, name, bp /* &z */, 10) + return X__shgetc(tls, f) + }())) + 1)))) != 0) { + goto __111 + } + switch Xmbrtowc(tls, bp+260 /* &wc */, func() uintptr { *(*int8)(unsafe.Pointer(bp + 264)) = int8(c); return bp + 264 }(), uint32(1), bp+268 /* &st */) { + case Uint32FromInt32(-1): + goto __113 + case Uint32FromInt32(-2): + goto __114 + } + goto __112 +__113: + goto input_fail +__114: + goto __110 +__112: + ; + if !(wcs != 0) { + goto __115 } - if !(int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(bp /* z */))))) != 0) { - if port > uint32(65535) { - return -8 + *(*wchar_t)(unsafe.Pointer(wcs + uintptr(PostIncUint32(&i, 1))*4)) = *(*wchar_t)(unsafe.Pointer(bp + 260 /* wc */)) +__115: + ; + if !((alloc != 0) && (i == k)) { + goto __116 + } + k = k + (k + size_t(1)) + tmp = Xrealloc(tls, wcs, (k * size_t(unsafe.Sizeof(wchar_t(0))))) + if !(!(tmp != 0)) { + goto __117 + } + goto alloc_fail +__117: + ; + wcs = tmp +__116: + ; + goto __110 +__111: + ; + if !(!(Xmbsinit(tls, bp+268 /* &st */) != 0)) { + goto __118 + } + goto input_fail +__118: + ; + goto __106 +__105: + if !(alloc != 0) { + goto __119 + } + s = Xmalloc(tls, k) + if !(!(s != 0)) { + goto __121 + } + goto alloc_fail +__121: + ; +__122: + if !(*(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr(((AssignInt32(&c, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } - if proto != 17 { - (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).port = uint16_t(port) - (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).socktype = uint8(1) - (*service)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*4)).proto = uint8(6) + return X__shgetc(tls, f) + }())) + 1)))) != 0) { + goto __123 + } + *(*int8)(unsafe.Pointer(s + uintptr(PostIncUint32(&i, 1)))) = int8(c) + if !(i == k) { + goto __124 + } + k = k + (k + size_t(1)) + tmp1 = Xrealloc(tls, s, k) + if !(!(tmp1 != 0)) { + goto __125 + } + goto alloc_fail +__125: + ; + s = tmp1 +__124: + ; + goto __122 +__123: + ; + goto __120 +__119: + if !(AssignUintptr(&s, dest) != 0) { + goto __126 + } +__128: + if !(*(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr(((AssignInt32(&c, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } - if proto != 6 { - (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).port = uint16_t(port) - (*service)(unsafe.Pointer(buf + uintptr(cnt)*4)).socktype = uint8(2) - (*service)(unsafe.Pointer(buf + uintptr(PostIncInt32(&cnt, 1))*4)).proto = uint8(17) + return X__shgetc(tls, f) + }())) + 1)))) != 0) { + goto __129 + } + *(*int8)(unsafe.Pointer(s + uintptr(PostIncUint32(&i, 1)))) = int8(c) + goto __128 +__129: + ; + goto __127 +__126: +__130: + if !(*(*uint8)(unsafe.Pointer(bp /* &scanset[0] */ + uintptr(((AssignInt32(&c, func() int32 { + if (*FILE)(unsafe.Pointer((f))).rpos != (*FILE)(unsafe.Pointer((f))).shend { + return int32(*(*uint8)(unsafe.Pointer(PostIncUintptr(&(*FILE)(unsafe.Pointer(f)).rpos, 1)))) } - return cnt + return X__shgetc(tls, f) + }())) + 1)))) != 0) { + goto __131 } - - if (flags & 0x400) != 0 { - return -2 + goto __130 +__131: + ; +__127: + ; +__120: + ; +__106: + ; + if (*FILE)(unsafe.Pointer((f))).shlim >= int64(0) { + (*FILE)(unsafe.Pointer(f)).rpos-- + } else { } + if !(!(((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) != 0)) { + goto __132 + } + goto match_fail +__132: + ; + if !((t == 'c') && (((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) != off_t(width))) { + goto __133 + } + goto match_fail +__133: + ; + if !(alloc != 0) { + goto __134 + } + if !(size == 1) { + goto __135 + } + *(*uintptr)(unsafe.Pointer(dest)) = wcs + goto __136 +__135: + *(*uintptr)(unsafe.Pointer(dest)) = s +__136: + ; +__134: + ; + if !(t != 'c') { + goto __137 + } + if !(wcs != 0) { + goto __138 + } + *(*wchar_t)(unsafe.Pointer(wcs + uintptr(i)*4)) = wchar_t(0) +__138: + ; + if !(s != 0) { + goto __139 + } + *(*int8)(unsafe.Pointer(s + uintptr(i))) = int8(0) +__139: + ; +__137: + ; + goto __70 +__74: +__75: +__76: + base = 16 + goto int_common +__77: + base = 8 + goto int_common +__78: +__79: + base = 10 + goto int_common +__80: + base = 0 +int_common: + x = X__intscan(tls, f, uint32(base), 0, ((2 * uint64(0x7fffffffffffffff)) + uint64(1))) + if !(!(((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) != 0)) { + goto __140 + } + goto match_fail +__140: + ; + if !((t == 'p') && (dest != 0)) { + goto __141 + } + *(*uintptr)(unsafe.Pointer(dest)) = uintptr(uintptr_t(x)) + goto __142 +__141: + store_int(tls, dest, size, x) +__142: + ; + goto __70 +__81: +__82: +__83: +__84: +__85: +__86: +__87: +__88: + y = X__floatscan(tls, f, size, 0) + if !(!(((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) != 0)) { + goto __143 + } + goto match_fail +__143: + ; + if !(dest != 0) { + goto __144 + } + switch size { + case 0: + goto __146 + case 1: + goto __147 + case 2: + goto __148 + } + goto __145 +__146: + *(*float32)(unsafe.Pointer(dest)) = float32(y) + goto __145 +__147: + *(*float64)(unsafe.Pointer(dest)) = y + goto __145 +__148: + *(*float64)(unsafe.Pointer(dest)) = y + goto __145 +__145: + ; +__144: + ; + goto __70 +__70: + ; - var l size_t = Xstrlen(tls, name) - _ = l - - Xabort(tls) //TODO- - // unsigned char _buf[1032]; - // FILE _f, *f = __fopen_rb_ca("/etc/services", &_f, _buf, sizeof _buf); - // if (!f) switch (errno) { - // case ENOENT: - // case ENOTDIR: - // case EACCES: - // return EAI_SERVICE; - // default: - // return EAI_SYSTEM; - // } - - Xabort(tls) //TODO- - // while (fgets(line, sizeof line, f) && cnt < MAXSERVS) { - // if ((p=strchr(line, '#'))) *p++='\n', *p=0; - - // /* Find service name */ - // for(p=line; (p=strstr(p, name)); p++) { - // if (p>line && !isspace(p[-1])) continue; - // if (p[l] && !isspace(p[l])) continue; - // break; - // } - // if (!p) continue; - - // /* Skip past canonical name at beginning of line */ - // for (p=line; *p && !isspace(*p); p++); - - // port = strtoul(p, &z, 10); - // if (port > 65535 || z==p) continue; - // if (!strncmp(z, "/udp", 4)) { - // if (proto == IPPROTO_TCP) continue; - // buf[cnt].port = port; - // buf[cnt].socktype = SOCK_DGRAM; - // buf[cnt++].proto = IPPROTO_UDP; - // } - // if (!strncmp(z, "/tcp", 4)) { - // if (proto == IPPROTO_UDP) continue; - // buf[cnt].port = port; - // buf[cnt].socktype = SOCK_STREAM; - // buf[cnt++].proto = IPPROTO_TCP; - // } - // } - // __fclose_ca(f); - // return cnt > 0 ? cnt : EAI_SERVICE; - Xabort(tls) - return int32(0) //TODO- -} - -func temper(tls *TLS, x uint32) uint32 { /* rand_r.c:3:17: */ - x = x ^ (x >> 11) - x = x ^ ((x << 7) & 0x9D2C5680) - x = x ^ ((x << 15) & 0xEFC60000) - x = x ^ (x >> 18) - return x -} - -func Xrand_r(tls *TLS, seed uintptr) int32 { /* rand_r.c:12:5: */ - return (int32(temper(tls, AssignPtrUint32(seed, ((*(*uint32)(unsafe.Pointer(seed))*uint32(1103515245))+uint32(12345)))) / uint32(2))) -} - -func X__toread(tls *TLS, f uintptr) int32 { /* __toread.c:3:5: */ - *(*int32)(unsafe.Pointer(f + 72 /* &.mode */)) |= ((*FILE)(unsafe.Pointer(f)).mode - 1) - if (*FILE)(unsafe.Pointer(f)).wpos != (*FILE)(unsafe.Pointer(f)).wbase { - (*(*func(*TLS, uintptr, uintptr, size_t) size_t)(unsafe.Pointer((f + 36 /* &.write */))))(tls, f, uintptr(0), uint32(0)) + pos = pos + ((*FILE)(unsafe.Pointer((f))).shcnt + (off_t((int32((*FILE)(unsafe.Pointer((f))).rpos) - int32((*FILE)(unsafe.Pointer((f))).buf)) / 1))) + if !(dest != 0) { + goto __149 } - (*FILE)(unsafe.Pointer(f)).wpos = AssignPtrUintptr(f+28 /* &.wbase */, AssignPtrUintptr(f+16 /* &.wend */, uintptr(0))) - if ((*FILE)(unsafe.Pointer(f)).flags & uint32(4)) != 0 { - *(*uint32)(unsafe.Pointer(f /* &.flags */)) |= (uint32(32)) - return -1 + matches++ +__149: + ; + goto __4 +__4: + p++ + goto __3 + goto __5 +__5: + ; + if !(0 != 0) { + goto __150 } - (*FILE)(unsafe.Pointer(f)).rpos = AssignPtrUintptr(f+8 /* &.rend */, ((*FILE)(unsafe.Pointer(f)).buf + uintptr((*FILE)(unsafe.Pointer(f)).buf_size))) - if ((*FILE)(unsafe.Pointer(f)).flags & uint32(16)) != 0 { - return -1 +fmt_fail: +alloc_fail: +input_fail: + if !(!(matches != 0)) { + goto __151 } - return 0 + matches-- +__151: + ; +match_fail: + if !(alloc != 0) { + goto __152 + } + Xfree(tls, s) + Xfree(tls, wcs) +__152: + ; +__150: + ; +__153: + if !(__need_unlock != 0) { + goto __156 + } + X__unlockfile(tls, f) +__156: + ; + goto __154 +__154: + if 0 != 0 { + goto __153 + } + goto __155 +__155: + ; + return matches } -func X__toread_needs_stdio_exit(tls *TLS) { /* __toread.c:16:13: */ - X__builtin_abort(tls) //TODO- - // __stdio_exit_needed(); +func string_read(tls *TLS, f uintptr, buf uintptr, len size_t) size_t { /* vsscanf.c:4:15: */ + var src uintptr = (*FILE)(unsafe.Pointer(f)).cookie + var k size_t = (len + size_t(256)) + var end uintptr = Xmemchr(tls, src, 0, k) + if end != 0 { + k = (size_t((int32(end) - int32(src)) / 1)) + } + if k < len { + len = k + } + Xmemcpy(tls, buf, src, len) + (*FILE)(unsafe.Pointer(f)).rpos = (src + uintptr(len)) + (*FILE)(unsafe.Pointer(f)).rend = (src + uintptr(k)) + (*FILE)(unsafe.Pointer(f)).cookie = (src + uintptr(k)) + return len } -// This function assumes it will never be called if there is already -// data buffered for reading. - -func X__uflow(tls *TLS, f uintptr) int32 { /* __uflow.c:6:5: */ - bp := tls.Alloc(1) - defer tls.Free(1) - - // var c uint8 at bp, 1 +func Xvsscanf(tls *TLS, s uintptr, fmt uintptr, ap va_list) int32 { /* vsscanf.c:18:5: */ + bp := tls.Alloc(144) + defer tls.Free(144) - if !(X__toread(tls, f) != 0) && ((*(*func(*TLS, uintptr, uintptr, size_t) size_t)(unsafe.Pointer((f + 32 /* &.read */))))(tls, f, bp /* &c */, uint32(1)) == size_t(1)) { - return int32(*(*uint8)(unsafe.Pointer(bp /* c */))) - } - return -1 + *(*FILE)(unsafe.Pointer(bp /* f */)) = FILE{read: *(*uintptr)(unsafe.Pointer(&struct { + f func(*TLS, uintptr, uintptr, size_t) size_t + }{string_read})), buf: s, lock: -1, cookie: s} + return Xvfscanf(tls, bp /* &f */, fmt, ap) } func strtox(tls *TLS, s uintptr, p uintptr, prec int32) float64 { /* strtod.c:6:20: */ @@ -4233,5 +6661,151 @@ func Xstrtok(tls *TLS, s uintptr, sep uintptr) uintptr { /* strtok.c:3:6: */ var _sp uintptr /* strtok.c:5:14: */ +func X__ccgo_pthreadAttrGetDetachState(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:3:5: */ + return *(*int32)(unsafe.Pointer((a /* &.__u */ /* &.__i */) + 3*4)) +} + +func Xpthread_attr_getdetachstate(tls *TLS, a uintptr, state uintptr) int32 { /* pthread_attr_get.c:7:5: */ + *(*int32)(unsafe.Pointer(state)) = *(*int32)(unsafe.Pointer((a /* &.__u */ /* &.__i */) + 3*4)) + return 0 +} + +// +// int pthread_attr_getguardsize(const pthread_attr_t *restrict a, size_t *restrict size) +// { +// *size = a->_a_guardsize; +// return 0; +// } +// +// int pthread_attr_getinheritsched(const pthread_attr_t *restrict a, int *restrict inherit) +// { +// *inherit = a->_a_sched; +// return 0; +// } +// +// int pthread_attr_getschedparam(const pthread_attr_t *restrict a, struct sched_param *restrict param) +// { +// param->sched_priority = a->_a_prio; +// return 0; +// } +// +// int pthread_attr_getschedpolicy(const pthread_attr_t *restrict a, int *restrict policy) +// { +// *policy = a->_a_policy; +// return 0; +// } +// +// int pthread_attr_getscope(const pthread_attr_t *restrict a, int *restrict scope) +// { +// *scope = PTHREAD_SCOPE_SYSTEM; +// return 0; +// } +// +// int pthread_attr_getstack(const pthread_attr_t *restrict a, void **restrict addr, size_t *restrict size) +// { +// if (!a->_a_stackaddr) +// return EINVAL; +// *size = a->_a_stacksize; +// *addr = (void *)(a->_a_stackaddr - *size); +// return 0; +// } +// +// int pthread_attr_getstacksize(const pthread_attr_t *restrict a, size_t *restrict size) +// { +// *size = a->_a_stacksize; +// return 0; +// } +// +// int pthread_barrierattr_getpshared(const pthread_barrierattr_t *restrict a, int *restrict pshared) +// { +// *pshared = !!a->__attr; +// return 0; +// } +// +// int pthread_condattr_getclock(const pthread_condattr_t *restrict a, clockid_t *restrict clk) +// { +// *clk = a->__attr & 0x7fffffff; +// return 0; +// } +// +// int pthread_condattr_getpshared(const pthread_condattr_t *restrict a, int *restrict pshared) +// { +// *pshared = a->__attr>>31; +// return 0; +// } +// +// int pthread_mutexattr_getprotocol(const pthread_mutexattr_t *restrict a, int *restrict protocol) +// { +// *protocol = PTHREAD_PRIO_NONE; +// return 0; +// } +// int pthread_mutexattr_getpshared(const pthread_mutexattr_t *restrict a, int *restrict pshared) +// { +// *pshared = a->__attr / 128U % 2; +// return 0; +// } +// +// int pthread_mutexattr_getrobust(const pthread_mutexattr_t *restrict a, int *restrict robust) +// { +// *robust = a->__attr / 4U % 2; +// return 0; +// } + +func X__ccgo_pthreadMutexattrGettype(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:93:5: */ + return (int32((*pthread_mutexattr_t)(unsafe.Pointer(a)).__attr & uint32(3))) +} + +// int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict a, int *restrict type) +// { +// *type = a->__attr & 3; +// return 0; +// } +// +// int pthread_rwlockattr_getpshared(const pthread_rwlockattr_t *restrict a, int *restrict pshared) +// { +// *pshared = a->__attr[0]; +// return 0; +// } + +func Xpthread_attr_setdetachstate(tls *TLS, a uintptr, state int32) int32 { /* pthread_attr_setdetachstate.c:3:5: */ + if uint32(state) > 1 { + return 22 + } + *(*int32)(unsafe.Pointer((a /* &.__u */ /* &.__i */) + 3*4)) = state + return 0 +} + +func X__ccgo_getMutexType(tls *TLS, m uintptr) int32 { /* pthread_mutex_lock.c:3:5: */ + return (*(*int32)(unsafe.Pointer((m /* &.__u */ /* &.__i */))) & 15) +} + +// int __pthread_mutex_lock(pthread_mutex_t *m) +// { +// if ((m->_m_type&15) == PTHREAD_MUTEX_NORMAL +// && !a_cas(&m->_m_lock, 0, EBUSY)) +// return 0; +// +// return __pthread_mutex_timedlock(m, 0); +// } +// +// weak_alias(__pthread_mutex_lock, pthread_mutex_lock); + +func Xpthread_mutexattr_destroy(tls *TLS, a uintptr) int32 { /* pthread_mutexattr_destroy.c:3:5: */ + return 0 +} + +func Xpthread_mutexattr_init(tls *TLS, a uintptr) int32 { /* pthread_mutexattr_init.c:3:5: */ + *(*pthread_mutexattr_t)(unsafe.Pointer(a)) = pthread_mutexattr_t{} + return 0 +} + +func Xpthread_mutexattr_settype(tls *TLS, a uintptr, type1 int32) int32 { /* pthread_mutexattr_settype.c:3:5: */ + if uint32(type1) > uint32(2) { + return 22 + } + (*pthread_mutexattr_t)(unsafe.Pointer(a)).__attr = (((*pthread_mutexattr_t)(unsafe.Pointer(a)).__attr & Uint32FromInt32(CplInt32(3))) | uint32(type1)) + return 0 +} + var ts1 = "infinity\x00nan\x00\x00\x00\x01\x02\x04\a\x03\x06\x05\x00%d.%d.%d.%d.in-addr.arpa\x00ip6.arpa\x000123456789abcdef\x00/etc/hosts\x00rb\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00%d.%d.%d.%d\x00%x:%x:%x:%x:%x:%x:%x:%x\x00%x:%x:%x:%x:%x:%x:%d.%d.%d.%d\x00:0\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff\x00\x00\x00\x00 \x02\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xfc\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" var ts = (*reflect.StringHeader)(unsafe.Pointer(&ts1)).Data -- cgit v1.2.3