gtsocial-umbx

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

libc_netbsd_arm.go (17408B)


      1 // Copyright 2021 The Libc Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style
      3 // license that can be found in the LICENSE file.
      4 
      5 package libc // import "modernc.org/libc"
      6 
      7 import (
      8 	"strings"
      9 	"syscall"
     10 	"unsafe"
     11 
     12 	"golang.org/x/sys/unix"
     13 	"modernc.org/libc/fcntl"
     14 	"modernc.org/libc/fts"
     15 	"modernc.org/libc/sys/types"
     16 	"modernc.org/libc/time"
     17 	"modernc.org/libc/utime"
     18 )
     19 
     20 type (
     21 	long  = int32
     22 	ulong = uint32
     23 )
     24 
     25 // int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
     26 func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
     27 	panic(todo(""))
     28 	// if _, _, err := unix.Syscall(unix.SYS_SIGACTION, uintptr(signum), act, oldact); err != 0 {
     29 	// 	t.setErrno(err)
     30 	// 	return -1
     31 	// }
     32 
     33 	// return 0
     34 }
     35 
     36 // FILE *fopen64(const char *pathname, const char *mode);
     37 func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
     38 	m := strings.ReplaceAll(GoString(mode), "b", "")
     39 	var flags int
     40 	switch m {
     41 	case "r":
     42 		flags = fcntl.O_RDONLY
     43 	case "r+":
     44 		flags = fcntl.O_RDWR
     45 	case "w":
     46 		flags = fcntl.O_WRONLY | fcntl.O_CREAT | fcntl.O_TRUNC
     47 	case "w+":
     48 		flags = fcntl.O_RDWR | fcntl.O_CREAT | fcntl.O_TRUNC
     49 	case "a":
     50 		flags = fcntl.O_WRONLY | fcntl.O_CREAT | fcntl.O_APPEND
     51 	case "a+":
     52 		flags = fcntl.O_RDWR | fcntl.O_CREAT | fcntl.O_APPEND
     53 	default:
     54 		panic(m)
     55 	}
     56 	fd, err := unix.Open(GoString(pathname), int(flags), 0666)
     57 	if err != nil {
     58 		if dmesgs {
     59 			dmesg("%v: %q %q: %v FAIL", origin(1), GoString(pathname), GoString(mode), err)
     60 		}
     61 		t.setErrno(err)
     62 		return 0
     63 	}
     64 
     65 	if dmesgs {
     66 		dmesg("%v: %q %q: fd %v", origin(1), GoString(pathname), GoString(mode), fd)
     67 	}
     68 	if p := newFile(t, int32(fd)); p != 0 {
     69 		return p
     70 	}
     71 
     72 	panic("OOM")
     73 }
     74 
     75 // int lstat(const char *pathname, struct stat *statbuf);
     76 func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
     77 	if err := unix.Lstat(GoString(pathname), (*unix.Stat_t)(unsafe.Pointer(statbuf))); err != nil {
     78 		if dmesgs {
     79 			dmesg("%v: %q: %v FAIL", origin(1), GoString(pathname), err)
     80 		}
     81 		t.setErrno(err)
     82 		return -1
     83 	}
     84 
     85 	if dmesgs {
     86 		dmesg("%v: %q: ok", origin(1), GoString(pathname))
     87 	}
     88 	return 0
     89 }
     90 
     91 // int stat(const char *pathname, struct stat *statbuf);
     92 func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
     93 	if err := unix.Stat(GoString(pathname), (*unix.Stat_t)(unsafe.Pointer(statbuf))); err != nil {
     94 		if dmesgs {
     95 			dmesg("%v: %q: %v FAIL", origin(1), GoString(pathname), err)
     96 		}
     97 		t.setErrno(err)
     98 		return -1
     99 	}
    100 
    101 	if dmesgs {
    102 		dmesg("%v: %q: ok", origin(1), GoString(pathname))
    103 	}
    104 	return 0
    105 }
    106 
    107 // int mkdir(const char *path, mode_t mode);
    108 func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
    109 	if err := unix.Mkdir(GoString(path), uint32(mode)); err != nil {
    110 		if dmesgs {
    111 			dmesg("%v: %q: %v FAIL", origin(1), GoString(path), err)
    112 		}
    113 		t.setErrno(err)
    114 		return -1
    115 	}
    116 
    117 	if dmesgs {
    118 		dmesg("%v: %q: ok", origin(1), GoString(path))
    119 	}
    120 	return 0
    121 }
    122 
    123 // int access(const char *pathname, int mode);
    124 func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
    125 	if err := unix.Access(GoString(pathname), uint32(mode)); err != nil {
    126 		if dmesgs {
    127 			dmesg("%v: %q %#o: %v FAIL", origin(1), GoString(pathname), mode, err)
    128 		}
    129 		t.setErrno(err)
    130 		return -1
    131 	}
    132 
    133 	if dmesgs {
    134 		dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
    135 	}
    136 	return 0
    137 }
    138 
    139 // int unlink(const char *pathname);
    140 func Xunlink(t *TLS, pathname uintptr) int32 {
    141 	if err := unix.Unlink(GoString(pathname)); err != nil {
    142 		if dmesgs {
    143 			dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
    144 		}
    145 		t.setErrno(err)
    146 		return -1
    147 	}
    148 
    149 	if dmesgs {
    150 		dmesg("%v: ok", origin(1))
    151 	}
    152 	return 0
    153 }
    154 
    155 // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
    156 func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
    157 	var n int
    158 	var err error
    159 	switch {
    160 	case buf == 0 || bufsize == 0:
    161 		n, err = unix.Readlink(GoString(path), nil)
    162 	default:
    163 		n, err = unix.Readlink(GoString(path), (*RawMem)(unsafe.Pointer(buf))[:bufsize:bufsize])
    164 	}
    165 	if err != nil {
    166 		if dmesgs {
    167 			dmesg("%v: %v FAIL", err)
    168 		}
    169 		t.setErrno(err)
    170 		return -1
    171 	}
    172 
    173 	if dmesgs {
    174 		dmesg("%v: ok")
    175 	}
    176 	return types.Ssize_t(n)
    177 }
    178 
    179 // int symlink(const char *target, const char *linkpath);
    180 func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
    181 	if err := unix.Symlink(GoString(target), GoString(linkpath)); err != nil {
    182 		if dmesgs {
    183 			dmesg("%v: %v FAIL", origin(1), err)
    184 		}
    185 		t.setErrno(err)
    186 		return -1
    187 	}
    188 
    189 	if dmesgs {
    190 		dmesg("%v: ok", origin(1))
    191 	}
    192 	return 0
    193 }
    194 
    195 // int chmod(const char *pathname, mode_t mode)
    196 func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
    197 	if err := unix.Chmod(GoString(pathname), uint32(mode)); err != nil {
    198 		if dmesgs {
    199 			dmesg("%v: %q %#o: %v FAIL", origin(1), GoString(pathname), mode, err)
    200 		}
    201 		t.setErrno(err)
    202 		return -1
    203 	}
    204 
    205 	if dmesgs {
    206 		dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
    207 	}
    208 	return 0
    209 }
    210 
    211 // time_t time(time_t *tloc);
    212 func Xtime(t *TLS, tloc uintptr) time.Time_t {
    213 	panic(todo(""))
    214 	// n := time.Now().UTC().Unix()
    215 	// if tloc != 0 {
    216 	// 	*(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
    217 	// }
    218 	// return types.Time_t(n)
    219 }
    220 
    221 // int utimes(const char *filename, const struct timeval times[2]);
    222 func Xutimes(t *TLS, filename, times uintptr) int32 {
    223 	var a []unix.Timeval
    224 	if times != 0 {
    225 		a = make([]unix.Timeval, 2)
    226 		a[0] = *(*unix.Timeval)(unsafe.Pointer(times))
    227 		a[1] = *(*unix.Timeval)(unsafe.Pointer(times + unsafe.Sizeof(unix.Timeval{})))
    228 	}
    229 	if err := unix.Utimes(GoString(filename), a); err != nil {
    230 		if dmesgs {
    231 			dmesg("%v: %v FAIL", origin(1), err)
    232 		}
    233 		t.setErrno(err)
    234 		return -1
    235 	}
    236 
    237 	if dmesgs {
    238 		dmesg("%v: ok", origin(1))
    239 	}
    240 	return 0
    241 }
    242 
    243 // int fstat(int fd, struct stat *statbuf);
    244 func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
    245 	if err := unix.Fstat(int(fd), (*unix.Stat_t)(unsafe.Pointer(statbuf))); err != nil {
    246 		if dmesgs {
    247 			dmesg("%v: fd %d: %v FAIL", origin(1), fd, err)
    248 		}
    249 		t.setErrno(err)
    250 		return -1
    251 	}
    252 
    253 	if dmesgs {
    254 		dmesg("%v: fd %d: ok", origin(1), fd)
    255 	}
    256 	return 0
    257 }
    258 
    259 // off64_t lseek64(int fd, off64_t offset, int whence);
    260 func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
    261 	n, err := unix.Seek(int(fd), int64(offset), int(whence))
    262 	if err != nil {
    263 		if dmesgs {
    264 			dmesg("%v: %v FAIL", origin(1), err)
    265 		}
    266 		t.setErrno(err)
    267 		return -1
    268 	}
    269 
    270 	if dmesgs {
    271 		dmesg("%v: ok", origin(1))
    272 	}
    273 	return types.Off_t(n)
    274 }
    275 
    276 func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
    277 	var arg uintptr
    278 	if args != 0 {
    279 		arg = *(*uintptr)(unsafe.Pointer(args))
    280 	}
    281 	n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
    282 	if err != 0 {
    283 		if dmesgs {
    284 			dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
    285 		}
    286 		t.setErrno(err)
    287 		return -1
    288 	}
    289 
    290 	if dmesgs {
    291 		dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
    292 	}
    293 	return int32(n)
    294 }
    295 
    296 // int rename(const char *oldpath, const char *newpath);
    297 func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
    298 	if err := unix.Rename(GoString(oldpath), GoString(newpath)); err != nil {
    299 		if dmesgs {
    300 			dmesg("%v: %v FAIL", origin(1), err)
    301 		}
    302 		t.setErrno(err)
    303 		return -1
    304 	}
    305 
    306 	if dmesgs {
    307 		dmesg("%v: ok", origin(1))
    308 	}
    309 	return 0
    310 }
    311 
    312 // int mknod(const char *pathname, mode_t mode, dev_t dev);
    313 func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
    314 	panic(todo(""))
    315 	// if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
    316 	// 	t.setErrno(err)
    317 	// 	return -1
    318 	// }
    319 
    320 	// return 0
    321 }
    322 
    323 // int utime(const char *filename, const struct utimbuf *times);
    324 func Xutime(t *TLS, filename, times uintptr) int32 {
    325 	var a []unix.Timeval
    326 	if times != 0 {
    327 		a = make([]unix.Timeval, 2)
    328 		a[0].Sec = (*utime.Utimbuf)(unsafe.Pointer(times)).Factime
    329 		a[1].Sec = (*utime.Utimbuf)(unsafe.Pointer(times)).Fmodtime
    330 	}
    331 	if err := unix.Utimes(GoString(filename), a); err != nil {
    332 		if dmesgs {
    333 			dmesg("%v: %v FAIL", origin(1), err)
    334 		}
    335 		t.setErrno(err)
    336 		return -1
    337 	}
    338 
    339 	if dmesgs {
    340 		dmesg("%v: ok", origin(1))
    341 	}
    342 	return 0
    343 }
    344 
    345 // int chown(const char *pathname, uid_t owner, gid_t group);
    346 func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
    347 	if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
    348 		t.setErrno(err)
    349 		return -1
    350 	}
    351 
    352 	return 0
    353 }
    354 
    355 // int link(const char *oldpath, const char *newpath);
    356 func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
    357 	panic(todo(""))
    358 	// if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
    359 	// 	t.setErrno(err)
    360 	// 	return -1
    361 	// }
    362 
    363 	// return 0
    364 }
    365 
    366 // int dup2(int oldfd, int newfd);
    367 func Xdup2(t *TLS, oldfd, newfd int32) int32 {
    368 	panic(todo(""))
    369 	// n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
    370 	// if err != 0 {
    371 	// 	t.setErrno(err)
    372 	// 	return -1
    373 	// }
    374 
    375 	// return int32(n)
    376 }
    377 
    378 // unsigned int alarm(unsigned int seconds);
    379 func Xalarm(t *TLS, seconds uint32) uint32 {
    380 	panic(todo(""))
    381 	// n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
    382 	// if err != 0 {
    383 	// 	panic(todo(""))
    384 	// }
    385 
    386 	// return uint32(n)
    387 }
    388 
    389 func Xgetnameinfo(tls *TLS, sa1 uintptr, sl socklen_t, node uintptr, nodelen size_t, serv uintptr, servlen size_t, flags int32) int32 { /* getnameinfo.c:125:5: */
    390 	panic(todo(""))
    391 	//TODO bp := tls.Alloc(347)
    392 	//TODO defer tls.Free(347)
    393 
    394 	//TODO // var ptr [78]int8 at bp, 78
    395 
    396 	//TODO // var buf [256]int8 at bp+78, 256
    397 
    398 	//TODO // var num [13]int8 at bp+334, 13
    399 
    400 	//TODO var af int32 = int32((*sockaddr)(unsafe.Pointer(sa1)).sa_family)
    401 	//TODO var a uintptr
    402 	//TODO var scopeid uint32
    403 
    404 	//TODO switch af {
    405 	//TODO case 2:
    406 	//TODO 	a = (sa1 + 4 /* &.sin_addr */)
    407 	//TODO 	if (uint64(sl) < uint64(unsafe.Sizeof(sockaddr_in{}))) {
    408 	//TODO 		return -6
    409 	//TODO 	}
    410 	//TODO 	mkptr4(tls, bp /* &ptr[0] */, a)
    411 	//TODO 	scopeid = uint32(0)
    412 	//TODO 	break
    413 	//TODO case 10:
    414 	//TODO 	a = (sa1 + 8 /* &.sin6_addr */)
    415 	//TODO 	if (uint64(sl) < uint64(unsafe.Sizeof(sockaddr_in6{}))) {
    416 	//TODO 		return -6
    417 	//TODO 	}
    418 	//TODO 	if Xmemcmp(tls, a, ts+88 /* "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xff\xff" */, uint64(12)) != 0 {
    419 	//TODO 		mkptr6(tls, bp /* &ptr[0] */, a)
    420 	//TODO 	} else {
    421 	//TODO 		mkptr4(tls, bp /* &ptr[0] */, (a + uintptr(12)))
    422 	//TODO 	}
    423 	//TODO 	scopeid = (*sockaddr_in6)(unsafe.Pointer(sa1)).sin6_scope_id
    424 	//TODO 	break
    425 	//TODO default:
    426 	//TODO 	return -6
    427 	//TODO }
    428 
    429 	//TODO if (node != 0) && (nodelen != 0) {
    430 	//TODO 	*(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0)
    431 	//TODO 	if !((flags & 0x01) != 0) {
    432 	//TODO 		reverse_hosts(tls, bp+78 /* &buf[0] */, a, scopeid, af)
    433 	//TODO 	}
    434 	//TODO 	if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) && !((flags & 0x01) != 0) {
    435 	//TODO 		Xabort(tls) //TODO-
    436 	//TODO 		// unsigned char query[18+PTR_MAX], reply[512];
    437 	//TODO 		// int qlen = __res_mkquery(0, ptr, 1, RR_PTR,
    438 	//TODO 		// 	0, 0, 0, query, sizeof query);
    439 	//TODO 		// query[3] = 0; /* don't need AD flag */
    440 	//TODO 		// int rlen = __res_send(query, qlen, reply, sizeof reply);
    441 	//TODO 		// buf[0] = 0;
    442 	//TODO 		// if (rlen > 0)
    443 	//TODO 		// 	__dns_parse(reply, rlen, dns_parse_callback, buf);
    444 	//TODO 	}
    445 	//TODO 	if !(int32(*(*int8)(unsafe.Pointer(bp + 78 /* buf */))) != 0) {
    446 	//TODO 		if (flags & 0x08) != 0 {
    447 	//TODO 			return -2
    448 	//TODO 		}
    449 	//TODO 		Xinet_ntop(tls, af, a, bp+78 /* &buf[0] */, uint32(unsafe.Sizeof([256]int8{})))
    450 	//TODO 		if scopeid != 0 {
    451 	//TODO 			Xabort(tls) //TODO-
    452 	//TODO 			// char *p = 0, tmp[IF_NAMESIZE+1];
    453 	//TODO 			// if (!(flags & NI_NUMERICSCOPE) &&
    454 	//TODO 			//     (IN6_IS_ADDR_LINKLOCAL(a) ||
    455 	//TODO 			//      IN6_IS_ADDR_MC_LINKLOCAL(a)))
    456 	//TODO 			// 	p = if_indextoname(scopeid, tmp+1);
    457 	//TODO 			// if (!p)
    458 	//TODO 			// 	p = itoa(num, scopeid);
    459 	//TODO 			// *--p = '%';
    460 	//TODO 			// strcat(buf, p);
    461 	//TODO 		}
    462 	//TODO 	}
    463 	//TODO 	if Xstrlen(tls, bp+78 /* &buf[0] */) >= size_t(nodelen) {
    464 	//TODO 		return -12
    465 	//TODO 	}
    466 	//TODO 	Xstrcpy(tls, node, bp+78 /* &buf[0] */)
    467 	//TODO }
    468 
    469 	//TODO if (serv != 0) && (servlen != 0) {
    470 	//TODO 	var p uintptr = bp + 78 /* buf */
    471 	//TODO 	var port int32 = int32(Xntohs(tls, (*sockaddr_in)(unsafe.Pointer(sa1)).sin_port))
    472 	//TODO 	*(*int8)(unsafe.Pointer(bp + 78 /* &buf[0] */)) = int8(0)
    473 	//TODO 	if !((flags & 0x02) != 0) {
    474 	//TODO 		reverse_services(tls, bp+78 /* &buf[0] */, port, (flags & 0x10))
    475 	//TODO 	}
    476 	//TODO 	if !(int32(*(*int8)(unsafe.Pointer(p))) != 0) {
    477 	//TODO 		p = itoa(tls, bp+334 /* &num[0] */, uint32(port))
    478 	//TODO 	}
    479 	//TODO 	if Xstrlen(tls, p) >= size_t(servlen) {
    480 	//TODO 		return -12
    481 	//TODO 	}
    482 	//TODO 	Xstrcpy(tls, serv, p)
    483 	//TODO }
    484 
    485 	//TODO return 0
    486 }
    487 
    488 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: */
    489 	panic(todo(""))
    490 	//TODO bp := tls.Alloc(28)
    491 	//TODO defer tls.Free(28)
    492 
    493 	//TODO //TODO union {
    494 	//TODO //TODO 	struct sockaddr_in sin;
    495 	//TODO //TODO 	struct sockaddr_in6 sin6;
    496 	//TODO //TODO } sa = { .sin.sin_family = af };
    497 	//TODO *(*struct {
    498 	//TODO 	sin sockaddr_in
    499 	//TODO 	_   [12]byte
    500 	//TODO })(unsafe.Pointer(bp /* sa1 */)) = struct {
    501 	//TODO 	sin sockaddr_in
    502 	//TODO 	_   [12]byte
    503 	//TODO }{} //TODO-
    504 	//TODO (*sockaddr_in)(unsafe.Pointer(bp /* &sa1 */)).sin_family = sa_family_t(af) //TODO-
    505 	//TODO var sl socklen_t
    506 	//TODO if af == 10 {
    507 	//TODO 	sl = uint32(unsafe.Sizeof(sockaddr_in6{}))
    508 	//TODO } else {
    509 	//TODO 	sl = uint32(unsafe.Sizeof(sockaddr_in{}))
    510 	//TODO }
    511 	//TODO var i int32
    512 
    513 	//TODO *(*uintptr)(unsafe.Pointer(res)) = uintptr(0)
    514 
    515 	//TODO // Load address argument into sockaddr structure
    516 	//TODO if (af == 10) && (l == socklen_t(16)) {
    517 	//TODO 	Xmemcpy(tls, (bp /* &sa1 */ /* &.sin6 */ + 8 /* &.sin6_addr */), a, uint64(16))
    518 	//TODO } else if (af == 2) && (l == socklen_t(4)) {
    519 	//TODO 	Xmemcpy(tls, (bp /* &sa1 */ /* &.sin */ + 4 /* &.sin_addr */), a, uint64(4))
    520 	//TODO } else {
    521 	//TODO 	*(*int32)(unsafe.Pointer(err)) = 3
    522 	//TODO 	return 22
    523 	//TODO }
    524 
    525 	//TODO // Align buffer and check for space for pointers and ip address
    526 	//TODO i = (int32(uintptr_t(buf) & (uint64(unsafe.Sizeof(uintptr(0))) - uint64(1))))
    527 	//TODO if !(i != 0) {
    528 	//TODO 	i = int32(unsafe.Sizeof(uintptr(0)))
    529 	//TODO }
    530 	//TODO if buflen <= (((uint64(5) * uint64(unsafe.Sizeof(uintptr(0)))) - uint64(i)) + uint64(l)) {
    531 	//TODO 	return 34
    532 	//TODO }
    533 	//TODO buf += (uintptr(uint64(unsafe.Sizeof(uintptr(0))) - uint64(i)))
    534 	//TODO buflen = buflen - (((uint64(5) * uint64(unsafe.Sizeof(uintptr(0)))) - uint64(i)) + uint64(l))
    535 
    536 	//TODO (*hostent)(unsafe.Pointer(h)).h_addr_list = buf
    537 	//TODO buf += (uintptr(uint64(2) * uint64(unsafe.Sizeof(uintptr(0)))))
    538 	//TODO (*hostent)(unsafe.Pointer(h)).h_aliases = buf
    539 	//TODO buf += (uintptr(uint64(2) * uint64(unsafe.Sizeof(uintptr(0)))))
    540 
    541 	//TODO *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)) = buf
    542 	//TODO Xmemcpy(tls, *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list)), a, uint64(l))
    543 	//TODO buf += uintptr(l)
    544 	//TODO *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_addr_list + 1*8)) = uintptr(0)
    545 	//TODO *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases)) = buf
    546 	//TODO *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases + 1*8)) = uintptr(0)
    547 
    548 	//TODO switch Xgetnameinfo(tls, bp /* &sa1 */, sl, buf, uint32(buflen), uintptr(0), uint32(0), 0) {
    549 	//TODO case -3:
    550 	//TODO 	*(*int32)(unsafe.Pointer(err)) = 2
    551 	//TODO 	return 11
    552 	//TODO case -12:
    553 	//TODO 	return 34
    554 	//TODO default:
    555 	//TODO 	fallthrough
    556 	//TODO case -10:
    557 	//TODO 	fallthrough
    558 	//TODO case -11:
    559 	//TODO 	fallthrough
    560 	//TODO case -4:
    561 	//TODO 	*(*int32)(unsafe.Pointer(err)) = 3
    562 	//TODO 	return *(*int32)(unsafe.Pointer(X___errno_location(tls)))
    563 	//TODO case 0:
    564 	//TODO 	break
    565 	//TODO }
    566 
    567 	//TODO (*hostent)(unsafe.Pointer(h)).h_addrtype = af
    568 	//TODO (*hostent)(unsafe.Pointer(h)).h_length = int32(l)
    569 	//TODO (*hostent)(unsafe.Pointer(h)).h_name = *(*uintptr)(unsafe.Pointer((*hostent)(unsafe.Pointer(h)).h_aliases))
    570 	//TODO *(*uintptr)(unsafe.Pointer(res)) = h
    571 	//TODO return 0
    572 }
    573 
    574 // int getrlimit(int resource, struct rlimit *rlim);
    575 func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
    576 	if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
    577 		t.setErrno(err)
    578 		return -1
    579 	}
    580 
    581 	return 0
    582 }
    583 
    584 func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err syscall.Errno) (r *fts.FTSENT) {
    585 	var statp uintptr
    586 	if stat != nil {
    587 		statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
    588 		if statp == 0 {
    589 			panic("OOM")
    590 		}
    591 
    592 		*(*unix.Stat_t)(unsafe.Pointer(statp)) = *stat
    593 	}
    594 	csp, errx := CString(path)
    595 	if errx != nil {
    596 		panic("OOM")
    597 	}
    598 
    599 	return &fts.FTSENT{
    600 		Ffts_info:    uint16(info),
    601 		Ffts_path:    csp,
    602 		Ffts_pathlen: uint32(len(path)),
    603 		Ffts_statp:   statp,
    604 		Ffts_errno:   int32(err),
    605 	}
    606 }
    607 
    608 // DIR *opendir(const char *name);
    609 func Xopendir(t *TLS, name uintptr) uintptr {
    610 	p := Xmalloc(t, uint32(unsafe.Sizeof(darwinDir{})))
    611 	if p == 0 {
    612 		panic("OOM")
    613 	}
    614 
    615 	fd := int(Xopen(t, name, fcntl.O_RDONLY|fcntl.O_DIRECTORY|fcntl.O_CLOEXEC, 0))
    616 	if fd < 0 {
    617 		if dmesgs {
    618 			dmesg("%v: FAIL %v", origin(1), (*darwinDir)(unsafe.Pointer(p)).fd)
    619 		}
    620 		Xfree(t, p)
    621 		return 0
    622 	}
    623 
    624 	if dmesgs {
    625 		dmesg("%v: ok", origin(1))
    626 	}
    627 	(*darwinDir)(unsafe.Pointer(p)).fd = fd
    628 	(*darwinDir)(unsafe.Pointer(p)).h = 0
    629 	(*darwinDir)(unsafe.Pointer(p)).l = 0
    630 	(*darwinDir)(unsafe.Pointer(p)).eof = false
    631 	return p
    632 }