libc_illumos_amd64.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794
  1. // Copyright 2020 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. package libc // import "modernc.org/libc"
  5. import (
  6. // "os"
  7. // "strings"
  8. gotime "time"
  9. "unicode"
  10. "unsafe"
  11. "golang.org/x/sys/unix"
  12. // "modernc.org/libc/errno"
  13. "modernc.org/libc/fcntl"
  14. // "modernc.org/libc/signal"
  15. "modernc.org/libc/stdio"
  16. "modernc.org/libc/sys/types"
  17. "modernc.org/libc/time"
  18. "modernc.org/libc/wctype"
  19. )
  20. var (
  21. startTime = gotime.Now() // For clock(3)
  22. )
  23. // int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  24. func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
  25. if __ccgo_strace {
  26. trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
  27. }
  28. panic(todo(""))
  29. // // musl/arch/x86_64/ksigaction.h
  30. // //
  31. // // struct k_sigaction {
  32. // // void (*handler)(int);
  33. // // unsigned long flags;
  34. // // void (*restorer)(void);
  35. // // unsigned mask[2];
  36. // // };
  37. // type k_sigaction struct {
  38. // handler uintptr
  39. // flags ulong
  40. // restorer uintptr
  41. // mask [2]uint32
  42. // }
  43. //
  44. // var kact, koldact uintptr
  45. // if act != 0 {
  46. // sz := int(unsafe.Sizeof(k_sigaction{}))
  47. // kact = t.Alloc(sz)
  48. // defer t.Free(sz)
  49. // *(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
  50. // handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
  51. // flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
  52. // restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
  53. // }
  54. // Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
  55. // }
  56. // if oldact != 0 {
  57. // panic(todo(""))
  58. // }
  59. //
  60. // if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signum), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
  61. // t.setErrno(err)
  62. // return -1
  63. // }
  64. //
  65. // if oldact != 0 {
  66. // panic(todo(""))
  67. // }
  68. //
  69. // return 0
  70. }
  71. // int fcntl(int fd, int cmd, ... /* arg */ );
  72. func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
  73. if __ccgo_strace {
  74. trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
  75. }
  76. var arg uintptr
  77. if args != 0 {
  78. arg = *(*uintptr)(unsafe.Pointer(args))
  79. }
  80. if cmd == fcntl.F_SETFL {
  81. arg |= unix.O_LARGEFILE
  82. }
  83. panic(todo(""))
  84. // n, _, err := unix.Syscall(unix.SYS_FCNTL, uintptr(fd), uintptr(cmd), arg)
  85. // if err != 0 {
  86. // // if dmesgs {
  87. // // dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
  88. // // }
  89. // t.setErrno(err)
  90. // return -1
  91. // }
  92. //
  93. // // if dmesgs {
  94. // // dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
  95. // // }
  96. // return int32(n)
  97. }
  98. // int lstat(const char *pathname, struct stat *statbuf);
  99. func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
  100. if __ccgo_strace {
  101. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  102. }
  103. panic(todo(""))
  104. // if _, _, err := unix.Syscall(unix.SYS_LSTAT, pathname, statbuf, 0); err != 0 {
  105. // // if dmesgs {
  106. // // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  107. // // }
  108. // t.setErrno(err)
  109. // return -1
  110. // }
  111. //
  112. // // if dmesgs {
  113. // // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  114. // // }
  115. // return 0
  116. }
  117. // int stat(const char *pathname, struct stat *statbuf);
  118. func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
  119. if __ccgo_strace {
  120. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  121. }
  122. panic(todo(""))
  123. // if _, _, err := unix.Syscall(unix.SYS_STAT, pathname, statbuf, 0); err != 0 {
  124. // // if dmesgs {
  125. // // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  126. // // }
  127. // t.setErrno(err)
  128. // return -1
  129. // }
  130. //
  131. // // if dmesgs {
  132. // // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  133. // // }
  134. // return 0
  135. }
  136. // int fstat(int fd, struct stat *statbuf);
  137. func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
  138. if __ccgo_strace {
  139. trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
  140. }
  141. panic(todo(""))
  142. // if _, _, err := unix.Syscall(unix.SYS_FSTAT, uintptr(fd), statbuf, 0); err != 0 {
  143. // // if dmesgs {
  144. // // dmesg("%v: fd %d: %v", origin(1), fd, err)
  145. // // }
  146. // t.setErrno(err)
  147. // return -1
  148. // }
  149. //
  150. // // if dmesgs {
  151. // // dmesg("%v: %d size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
  152. // // }
  153. // return 0
  154. }
  155. func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  156. if __ccgo_strace {
  157. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  158. }
  159. return Xmmap64(t, addr, length, prot, flags, fd, offset)
  160. }
  161. // void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
  162. func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  163. if __ccgo_strace {
  164. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  165. }
  166. panic(todo(""))
  167. // data, _, err := unix.Syscall6(unix.SYS_MMAP, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset))
  168. // if err != 0 {
  169. // // if dmesgs {
  170. // // dmesg("%v: %v", origin(1), err)
  171. // // }
  172. // t.setErrno(err)
  173. // return ^uintptr(0) // (void*)-1
  174. // }
  175. //
  176. // // if dmesgs {
  177. // // dmesg("%v: %#x", origin(1), data)
  178. // // }
  179. // return data
  180. }
  181. // void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
  182. func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
  183. if __ccgo_strace {
  184. trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
  185. }
  186. panic(todo(""))
  187. // var arg uintptr
  188. // if args != 0 {
  189. // arg = *(*uintptr)(unsafe.Pointer(args))
  190. // }
  191. // data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
  192. // if err != 0 {
  193. // // if dmesgs {
  194. // // dmesg("%v: %v", origin(1), err)
  195. // // }
  196. // t.setErrno(err)
  197. // return ^uintptr(0) // (void*)-1
  198. // }
  199. //
  200. // // if dmesgs {
  201. // // dmesg("%v: %#x", origin(1), data)
  202. // // }
  203. // return data
  204. }
  205. // int ftruncate(int fd, off_t length);
  206. func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
  207. if __ccgo_strace {
  208. trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
  209. }
  210. panic(todo(""))
  211. // if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE, uintptr(fd), uintptr(length), 0); err != 0 {
  212. // // if dmesgs {
  213. // // dmesg("%v: fd %d: %v", origin(1), fd, err)
  214. // // }
  215. // t.setErrno(err)
  216. // return -1
  217. // }
  218. //
  219. // // if dmesgs {
  220. // // dmesg("%v: %d %#x: ok", origin(1), fd, length)
  221. // // }
  222. // return 0
  223. }
  224. // off64_t lseek64(int fd, off64_t offset, int whence);
  225. func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
  226. if __ccgo_strace {
  227. trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
  228. }
  229. panic(todo(""))
  230. // n, _, err := unix.Syscall(unix.SYS_LSEEK, uintptr(fd), uintptr(offset), uintptr(whence))
  231. // if err != 0 {
  232. // // if dmesgs {
  233. // // dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), fd, offset, whenceStr(whence), err)
  234. // // }
  235. // t.setErrno(err)
  236. // return -1
  237. // }
  238. // // if dmesgs {
  239. // // dmesg("%v: fd %v, off %#x, whence %v: %#x", origin(1), fd, offset, whenceStr(whence), n)
  240. // // }
  241. // return types.Off_t(n)
  242. }
  243. // int utime(const char *filename, const struct utimbuf *times);
  244. func Xutime(t *TLS, filename, times uintptr) int32 {
  245. if __ccgo_strace {
  246. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  247. }
  248. panic(todo(""))
  249. // if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
  250. // t.setErrno(err)
  251. // return -1
  252. // }
  253. // return 0
  254. }
  255. // unsigned int alarm(unsigned int seconds);
  256. func Xalarm(t *TLS, seconds uint32) uint32 {
  257. if __ccgo_strace {
  258. trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
  259. }
  260. panic(todo(""))
  261. // n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
  262. // if err != 0 {
  263. // panic(todo(""))
  264. // }
  265. //
  266. // return uint32(n)
  267. }
  268. // time_t time(time_t *tloc);
  269. func Xtime(t *TLS, tloc uintptr) types.Time_t {
  270. if __ccgo_strace {
  271. trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
  272. }
  273. panic(todo(""))
  274. // n, _, err := unix.Syscall(unix.SYS_TIME, tloc, 0, 0)
  275. // if err != 0 {
  276. // t.setErrno(err)
  277. // return types.Time_t(-1)
  278. // }
  279. //
  280. // if tloc != 0 {
  281. // *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
  282. // }
  283. // return types.Time_t(n)
  284. }
  285. // int getrlimit(int resource, struct rlimit *rlim);
  286. func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  287. if __ccgo_strace {
  288. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  289. }
  290. panic(todo(""))
  291. // if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  292. // t.setErrno(err)
  293. // return -1
  294. // }
  295. //
  296. // return 0
  297. }
  298. // int mkdir(const char *path, mode_t mode);
  299. func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
  300. if __ccgo_strace {
  301. trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
  302. }
  303. panic(todo(""))
  304. // if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
  305. // t.setErrno(err)
  306. // return -1
  307. // }
  308. //
  309. // // if dmesgs {
  310. // // dmesg("%v: %q: ok", origin(1), GoString(path))
  311. // // }
  312. // return 0
  313. }
  314. // int symlink(const char *target, const char *linkpath);
  315. func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
  316. if __ccgo_strace {
  317. trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
  318. }
  319. panic(todo(""))
  320. // if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
  321. // t.setErrno(err)
  322. // return -1
  323. // }
  324. //
  325. // // if dmesgs {
  326. // // dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
  327. // // }
  328. // return 0
  329. }
  330. // int chmod(const char *pathname, mode_t mode)
  331. func Xchmod(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
  332. if __ccgo_strace {
  333. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  334. }
  335. panic(todo(""))
  336. // if _, _, err := unix.Syscall(unix.SYS_CHMOD, pathname, uintptr(mode), 0); err != 0 {
  337. // t.setErrno(err)
  338. // return -1
  339. // }
  340. //
  341. // // if dmesgs {
  342. // // dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
  343. // // }
  344. // return 0
  345. }
  346. // int utimes(const char *filename, const struct timeval times[2]);
  347. func Xutimes(t *TLS, filename, times uintptr) int32 {
  348. if __ccgo_strace {
  349. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  350. }
  351. panic(todo(""))
  352. // if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
  353. // t.setErrno(err)
  354. // return -1
  355. // }
  356. //
  357. // // if dmesgs {
  358. // // dmesg("%v: %q: ok", origin(1), GoString(filename))
  359. // // }
  360. // return 0
  361. }
  362. // int unlink(const char *pathname);
  363. func Xunlink(t *TLS, pathname uintptr) int32 {
  364. if __ccgo_strace {
  365. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  366. }
  367. panic(todo(""))
  368. // if _, _, err := unix.Syscall(unix.SYS_UNLINK, pathname, 0, 0); err != 0 {
  369. // t.setErrno(err)
  370. // return -1
  371. // }
  372. //
  373. // // if dmesgs {
  374. // // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  375. // // }
  376. // return 0
  377. }
  378. // int access(const char *pathname, int mode);
  379. func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
  380. if __ccgo_strace {
  381. trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
  382. }
  383. panic(todo(""))
  384. // if _, _, err := unix.Syscall(unix.SYS_ACCESS, pathname, uintptr(mode), 0); err != 0 {
  385. // // if dmesgs {
  386. // // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  387. // // }
  388. // t.setErrno(err)
  389. // return -1
  390. // }
  391. //
  392. // // if dmesgs {
  393. // // dmesg("%v: %q %#o: ok", origin(1), GoString(pathname), mode)
  394. // // }
  395. // return 0
  396. }
  397. // int rmdir(const char *pathname);
  398. func Xrmdir(t *TLS, pathname uintptr) int32 {
  399. if __ccgo_strace {
  400. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  401. }
  402. panic(todo(""))
  403. // if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
  404. // t.setErrno(err)
  405. // return -1
  406. // }
  407. //
  408. // // if dmesgs {
  409. // // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  410. // // }
  411. // return 0
  412. }
  413. // int rename(const char *oldpath, const char *newpath);
  414. func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
  415. if __ccgo_strace {
  416. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  417. }
  418. panic(todo(""))
  419. // if _, _, err := unix.Syscall(unix.SYS_RENAME, oldpath, newpath, 0); err != 0 {
  420. // t.setErrno(err)
  421. // return -1
  422. // }
  423. //
  424. // return 0
  425. }
  426. // int mknod(const char *pathname, mode_t mode, dev_t dev);
  427. func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
  428. if __ccgo_strace {
  429. trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
  430. }
  431. panic(todo(""))
  432. // if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
  433. // t.setErrno(err)
  434. // return -1
  435. // }
  436. //
  437. // return 0
  438. }
  439. // int chown(const char *pathname, uid_t owner, gid_t group);
  440. func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
  441. if __ccgo_strace {
  442. trc("t=%v pathname=%v owner=%v group=%v, (%v:)", t, pathname, owner, group, origin(2))
  443. }
  444. panic(todo(""))
  445. // if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
  446. // t.setErrno(err)
  447. // return -1
  448. // }
  449. //
  450. // return 0
  451. }
  452. // int link(const char *oldpath, const char *newpath);
  453. func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
  454. if __ccgo_strace {
  455. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  456. }
  457. panic(todo(""))
  458. // if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
  459. // t.setErrno(err)
  460. // return -1
  461. // }
  462. //
  463. // return 0
  464. }
  465. // int pipe(int pipefd[2]);
  466. func Xpipe(t *TLS, pipefd uintptr) int32 {
  467. if __ccgo_strace {
  468. trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
  469. }
  470. panic(todo(""))
  471. // if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
  472. // t.setErrno(err)
  473. // return -1
  474. // }
  475. //
  476. // return 0
  477. }
  478. // int dup2(int oldfd, int newfd);
  479. func Xdup2(t *TLS, oldfd, newfd int32) int32 {
  480. if __ccgo_strace {
  481. trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
  482. }
  483. panic(todo(""))
  484. // n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
  485. // if err != 0 {
  486. // t.setErrno(err)
  487. // return -1
  488. // }
  489. //
  490. // return int32(n)
  491. }
  492. // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
  493. func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
  494. if __ccgo_strace {
  495. trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
  496. }
  497. panic(todo(""))
  498. // n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
  499. // if err != 0 {
  500. // t.setErrno(err)
  501. // return -1
  502. // }
  503. //
  504. // return types.Ssize_t(n)
  505. }
  506. // FILE *fopen64(const char *pathname, const char *mode);
  507. func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
  508. if __ccgo_strace {
  509. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  510. }
  511. panic(todo(""))
  512. // m := strings.ReplaceAll(GoString(mode), "b", "")
  513. // var flags int
  514. // switch m {
  515. // case "r":
  516. // flags = os.O_RDONLY
  517. // case "r+":
  518. // flags = os.O_RDWR
  519. // case "w":
  520. // flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
  521. // case "w+":
  522. // flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
  523. // case "a":
  524. // flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
  525. // case "a+":
  526. // flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
  527. // default:
  528. // panic(m)
  529. // }
  530. // //TODO- flags |= fcntl.O_LARGEFILE
  531. // fd, _, err := unix.Syscall(unix.SYS_OPEN, pathname, uintptr(flags|unix.O_LARGEFILE), 0666)
  532. // if err != 0 {
  533. // t.setErrno(err)
  534. // return 0
  535. // }
  536. //
  537. // if p := newFile(t, int32(fd)); p != 0 {
  538. // return p
  539. // }
  540. //
  541. // Xclose(t, int32(fd))
  542. // t.setErrno(errno.ENOMEM)
  543. // return 0
  544. }
  545. // int iswspace(wint_t wc);
  546. func Xiswspace(t *TLS, wc wctype.Wint_t) int32 {
  547. if __ccgo_strace {
  548. trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
  549. }
  550. return Bool32(unicode.IsSpace(rune(wc)))
  551. }
  552. // int iswalnum(wint_t wc);
  553. func Xiswalnum(t *TLS, wc wctype.Wint_t) int32 {
  554. if __ccgo_strace {
  555. trc("t=%v wc=%v, (%v:)", t, wc, origin(2))
  556. }
  557. return Bool32(unicode.IsLetter(rune(wc)) || unicode.IsNumber(rune(wc)))
  558. }
  559. // int setrlimit(int resource, const struct rlimit *rlim);
  560. func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  561. if __ccgo_strace {
  562. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  563. }
  564. panic(todo(""))
  565. // if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  566. // t.setErrno(err)
  567. // return -1
  568. // }
  569. //
  570. // return 0
  571. }
  572. func AtomicLoadPInt8(addr uintptr) (val int8) {
  573. return int8(a_load_8(addr))
  574. }
  575. func AtomicLoadPInt16(addr uintptr) (val int16) {
  576. return int16(a_load_16(addr))
  577. }
  578. func AtomicLoadPUint8(addr uintptr) byte {
  579. return byte(a_load_8(addr))
  580. }
  581. func AtomicLoadPUint16(addr uintptr) uint16 {
  582. return uint16(a_load_16(addr))
  583. }
  584. func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
  585. return byte(a_load_8(ptr))
  586. }
  587. var _table1 = [384]int32{
  588. 129: int32(1),
  589. 130: int32(2),
  590. 131: int32(3),
  591. 132: int32(4),
  592. 133: int32(5),
  593. 134: int32(6),
  594. 135: int32(7),
  595. 136: int32(8),
  596. 137: int32(9),
  597. 138: int32(10),
  598. 139: int32(11),
  599. 140: int32(12),
  600. 141: int32(13),
  601. 142: int32(14),
  602. 143: int32(15),
  603. 144: int32(16),
  604. 145: int32(17),
  605. 146: int32(18),
  606. 147: int32(19),
  607. 148: int32(20),
  608. 149: int32(21),
  609. 150: int32(22),
  610. 151: int32(23),
  611. 152: int32(24),
  612. 153: int32(25),
  613. 154: int32(26),
  614. 155: int32(27),
  615. 156: int32(28),
  616. 157: int32(29),
  617. 158: int32(30),
  618. 159: int32(31),
  619. 160: int32(32),
  620. 161: int32(33),
  621. 162: int32(34),
  622. 163: int32(35),
  623. 164: int32(36),
  624. 165: int32(37),
  625. 166: int32(38),
  626. 167: int32(39),
  627. 168: int32(40),
  628. 169: int32(41),
  629. 170: int32(42),
  630. 171: int32(43),
  631. 172: int32(44),
  632. 173: int32(45),
  633. 174: int32(46),
  634. 175: int32(47),
  635. 176: int32(48),
  636. 177: int32(49),
  637. 178: int32(50),
  638. 179: int32(51),
  639. 180: int32(52),
  640. 181: int32(53),
  641. 182: int32(54),
  642. 183: int32(55),
  643. 184: int32(56),
  644. 185: int32(57),
  645. 186: int32(58),
  646. 187: int32(59),
  647. 188: int32(60),
  648. 189: int32(61),
  649. 190: int32(62),
  650. 191: int32(63),
  651. 192: int32(64),
  652. 193: int32('a'),
  653. 194: int32('b'),
  654. 195: int32('c'),
  655. 196: int32('d'),
  656. 197: int32('e'),
  657. 198: int32('f'),
  658. 199: int32('g'),
  659. 200: int32('h'),
  660. 201: int32('i'),
  661. 202: int32('j'),
  662. 203: int32('k'),
  663. 204: int32('l'),
  664. 205: int32('m'),
  665. 206: int32('n'),
  666. 207: int32('o'),
  667. 208: int32('p'),
  668. 209: int32('q'),
  669. 210: int32('r'),
  670. 211: int32('s'),
  671. 212: int32('t'),
  672. 213: int32('u'),
  673. 214: int32('v'),
  674. 215: int32('w'),
  675. 216: int32('x'),
  676. 217: int32('y'),
  677. 218: int32('z'),
  678. 219: int32(91),
  679. 220: int32(92),
  680. 221: int32(93),
  681. 222: int32(94),
  682. 223: int32(95),
  683. 224: int32(96),
  684. 225: int32('a'),
  685. 226: int32('b'),
  686. 227: int32('c'),
  687. 228: int32('d'),
  688. 229: int32('e'),
  689. 230: int32('f'),
  690. 231: int32('g'),
  691. 232: int32('h'),
  692. 233: int32('i'),
  693. 234: int32('j'),
  694. 235: int32('k'),
  695. 236: int32('l'),
  696. 237: int32('m'),
  697. 238: int32('n'),
  698. 239: int32('o'),
  699. 240: int32('p'),
  700. 241: int32('q'),
  701. 242: int32('r'),
  702. 243: int32('s'),
  703. 244: int32('t'),
  704. 245: int32('u'),
  705. 246: int32('v'),
  706. 247: int32('w'),
  707. 248: int32('x'),
  708. 249: int32('y'),
  709. 250: int32('z'),
  710. 251: int32(123),
  711. 252: int32(124),
  712. 253: int32(125),
  713. 254: int32(126),
  714. 255: int32(127),
  715. }
  716. var _ptable1 = uintptr(unsafe.Pointer(&_table1)) + uintptr(128)*4
  717. func X__ctype_tolower_loc(tls *TLS) (r uintptr) {
  718. if __ccgo_strace {
  719. trc("tls=%v, (%v:)", tls, origin(2))
  720. defer func() { trc("-> %v", r) }()
  721. }
  722. return uintptr(unsafe.Pointer(&_ptable1))
  723. }
  724. type Tin6_addr = struct {
  725. F__in6_union struct {
  726. F__s6_addr16 [0][8]uint16
  727. F__s6_addr32 [0][4]uint32
  728. F__s6_addr [16]uint8
  729. }
  730. }
  731. var Xin6addr_any = Tin6_addr{}
  732. func Xrewinddir(tls *TLS, f uintptr) {
  733. if __ccgo_strace {
  734. trc("tls=%v f=%v, (%v:)", tls, f, origin(2))
  735. }
  736. Xfseek(tls, f, 0, stdio.SEEK_SET)
  737. }
  738. // clock_t clock(void);
  739. func Xclock(t *TLS) time.Clock_t {
  740. if __ccgo_strace {
  741. trc("t=%v, (%v:)", t, origin(2))
  742. }
  743. return time.Clock_t(gotime.Since(startTime) * gotime.Duration(time.CLOCKS_PER_SEC) / gotime.Second)
  744. }