libc_windows_386.go 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  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. "golang.org/x/sys/windows"
  7. "os"
  8. "strings"
  9. gotime "time"
  10. "unsafe"
  11. "modernc.org/libc/errno"
  12. "modernc.org/libc/sys/stat"
  13. "modernc.org/libc/sys/types"
  14. "modernc.org/libc/time"
  15. )
  16. // int sigaction(int signum, const struct sigaction *act, struct sigaction *oldact);
  17. func Xsigaction(t *TLS, signum int32, act, oldact uintptr) int32 {
  18. if __ccgo_strace {
  19. trc("t=%v signum=%v oldact=%v, (%v:)", t, signum, oldact, origin(2))
  20. }
  21. panic(todo(""))
  22. // // musl/arch/x32/ksigaction.h
  23. // //
  24. // // struct k_sigaction {
  25. // // void (*handler)(int);
  26. // // unsigned long flags;
  27. // // void (*restorer)(void);
  28. // // unsigned mask[2];
  29. // // };
  30. // type k_sigaction struct {
  31. // handler uintptr
  32. // flags ulong
  33. // restorer uintptr
  34. // mask [2]uint32
  35. // }
  36. // var kact, koldact uintptr
  37. // if act != 0 {
  38. // kact = t.Alloc(int(unsafe.Sizeof(k_sigaction{})))
  39. // defer Xfree(t, kact)
  40. // *(*k_sigaction)(unsafe.Pointer(kact)) = k_sigaction{
  41. // handler: (*signal.Sigaction)(unsafe.Pointer(act)).F__sigaction_handler.Fsa_handler,
  42. // flags: ulong((*signal.Sigaction)(unsafe.Pointer(act)).Fsa_flags),
  43. // restorer: (*signal.Sigaction)(unsafe.Pointer(act)).Fsa_restorer,
  44. // }
  45. // Xmemcpy(t, kact+unsafe.Offsetof(k_sigaction{}.mask), act+unsafe.Offsetof(signal.Sigaction{}.Fsa_mask), types.Size_t(unsafe.Sizeof(k_sigaction{}.mask)))
  46. // }
  47. // if oldact != 0 {
  48. // panic(todo(""))
  49. // }
  50. // if _, _, err := unix.Syscall6(unix.SYS_RT_SIGACTION, uintptr(signal.SIGABRT), kact, koldact, unsafe.Sizeof(k_sigaction{}.mask), 0, 0); err != 0 {
  51. // t.setErrno(err)
  52. // return -1
  53. // }
  54. // if oldact != 0 {
  55. // panic(todo(""))
  56. // }
  57. // return 0
  58. }
  59. // int fcntl(int fd, int cmd, ... /* arg */ );
  60. func Xfcntl64(t *TLS, fd, cmd int32, args uintptr) int32 {
  61. if __ccgo_strace {
  62. trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
  63. }
  64. panic(todo(""))
  65. // var arg uintptr
  66. // if args != 0 {
  67. // arg = *(*uintptr)(unsafe.Pointer(args))
  68. // }
  69. // n, _, err := unix.Syscall(unix.SYS_FCNTL64, uintptr(fd), uintptr(cmd), arg)
  70. // if err != 0 {
  71. // if dmesgs {
  72. // dmesg("%v: fd %v cmd %v", origin(1), fcntlCmdStr(fd), cmd)
  73. // }
  74. // t.setErrno(err)
  75. // return -1
  76. // }
  77. //
  78. // if dmesgs {
  79. // dmesg("%v: %d %s %#x: %d", origin(1), fd, fcntlCmdStr(cmd), arg, n)
  80. // }
  81. // return int32(n)
  82. }
  83. // int lstat(const char *pathname, struct stat *statbuf);
  84. func Xlstat64(t *TLS, pathname, statbuf uintptr) int32 {
  85. if __ccgo_strace {
  86. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  87. }
  88. panic(todo(""))
  89. // if _, _, err := unix.Syscall(unix.SYS_LSTAT64, pathname, statbuf, 0); err != 0 {
  90. // if dmesgs {
  91. // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  92. // }
  93. // t.setErrno(err)
  94. // return -1
  95. // }
  96. //
  97. // if dmesgs {
  98. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  99. // }
  100. // return 0
  101. }
  102. // int stat(const char *pathname, struct stat *statbuf);
  103. func Xstat64(t *TLS, pathname, statbuf uintptr) int32 {
  104. if __ccgo_strace {
  105. trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
  106. }
  107. panic(todo(""))
  108. // if _, _, err := unix.Syscall(unix.SYS_STAT64, pathname, statbuf, 0); err != 0 {
  109. // if dmesgs {
  110. // dmesg("%v: %q: %v", origin(1), GoString(pathname), err)
  111. // }
  112. // t.setErrno(err)
  113. // return -1
  114. // }
  115. //
  116. // if dmesgs {
  117. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  118. // }
  119. // return 0
  120. }
  121. // int fstat(int fd, struct stat *statbuf);
  122. func Xfstat64(t *TLS, fd int32, statbuf uintptr) int32 {
  123. if __ccgo_strace {
  124. trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
  125. }
  126. panic(todo(""))
  127. // if _, _, err := unix.Syscall(unix.SYS_FSTAT64, uintptr(fd), statbuf, 0); err != 0 {
  128. // if dmesgs {
  129. // dmesg("%v: fd %d: %v", origin(1), fd, err)
  130. // }
  131. // t.setErrno(err)
  132. // return -1
  133. // }
  134. //
  135. // if dmesgs {
  136. // dmesg("%v: %d, size %#x: ok\n%+v", origin(1), fd, (*stat.Stat)(unsafe.Pointer(statbuf)).Fst_size, (*stat.Stat)(unsafe.Pointer(statbuf)))
  137. // }
  138. // return 0
  139. }
  140. // void *mremap(void *old_address, size_t old_size, size_t new_size, int flags, ... /* void *new_address */);
  141. func Xmremap(t *TLS, old_address uintptr, old_size, new_size types.Size_t, flags int32, args uintptr) uintptr {
  142. if __ccgo_strace {
  143. trc("t=%v old_address=%v new_size=%v flags=%v args=%v, (%v:)", t, old_address, new_size, flags, args, origin(2))
  144. }
  145. panic(todo(""))
  146. // var arg uintptr
  147. // if args != 0 {
  148. // arg = *(*uintptr)(unsafe.Pointer(args))
  149. // }
  150. // data, _, err := unix.Syscall6(unix.SYS_MREMAP, old_address, uintptr(old_size), uintptr(new_size), uintptr(flags), arg, 0)
  151. // if err != 0 {
  152. // if dmesgs {
  153. // dmesg("%v: %v", origin(1), err)
  154. // }
  155. // t.setErrno(err)
  156. // return ^uintptr(0) // (void*)-1
  157. // }
  158. //
  159. // if dmesgs {
  160. // dmesg("%v: %#x", origin(1), data)
  161. // }
  162. // return data
  163. }
  164. func Xmmap(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  165. if __ccgo_strace {
  166. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  167. }
  168. return Xmmap64(t, addr, length, prot, flags, fd, offset)
  169. }
  170. // void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset);
  171. func Xmmap64(t *TLS, addr uintptr, length types.Size_t, prot, flags, fd int32, offset types.Off_t) uintptr {
  172. if __ccgo_strace {
  173. trc("t=%v addr=%v length=%v fd=%v offset=%v, (%v:)", t, addr, length, fd, offset, origin(2))
  174. }
  175. panic(todo(""))
  176. // data, _, err := unix.Syscall6(unix.SYS_MMAP2, addr, uintptr(length), uintptr(prot), uintptr(flags), uintptr(fd), uintptr(offset>>12))
  177. // if err != 0 {
  178. // if dmesgs {
  179. // dmesg("%v: %v", origin(1), err)
  180. // }
  181. // t.setErrno(err)
  182. // return ^uintptr(0) // (void*)-1
  183. // }
  184. //
  185. // if dmesgs {
  186. // dmesg("%v: %#x", origin(1), data)
  187. // }
  188. // return data
  189. }
  190. // int ftruncate(int fd, off_t length);
  191. func Xftruncate64(t *TLS, fd int32, length types.Off_t) int32 {
  192. if __ccgo_strace {
  193. trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
  194. }
  195. panic(todo(""))
  196. // if _, _, err := unix.Syscall(unix.SYS_FTRUNCATE64, uintptr(fd), uintptr(length), uintptr(length>>32)); err != 0 {
  197. // if dmesgs {
  198. // dmesg("%v: fd %d: %v", origin(1), fd, err)
  199. // }
  200. // t.setErrno(err)
  201. // return -1
  202. // }
  203. //
  204. // if dmesgs {
  205. // dmesg("%v: %d %#x: ok", origin(1), fd, length)
  206. // }
  207. // return 0
  208. }
  209. // off64_t lseek64(int fd, off64_t offset, int whence);
  210. func Xlseek64(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
  211. if __ccgo_strace {
  212. trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
  213. }
  214. f, ok := fdToFile(fd)
  215. if !ok {
  216. t.setErrno(errno.EBADF)
  217. return -1
  218. }
  219. n, err := windows.Seek(f.Handle, offset, int(whence))
  220. if err != nil {
  221. if dmesgs {
  222. dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
  223. }
  224. t.setErrno(err)
  225. return -1
  226. }
  227. if dmesgs {
  228. dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
  229. }
  230. return n
  231. }
  232. // int utime(const char *filename, const struct utimbuf *times);
  233. func Xutime(t *TLS, filename, times uintptr) int32 {
  234. if __ccgo_strace {
  235. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  236. }
  237. panic(todo(""))
  238. // if _, _, err := unix.Syscall(unix.SYS_UTIME, filename, times, 0); err != 0 {
  239. // t.setErrno(err)
  240. // return -1
  241. // }
  242. //
  243. // return 0
  244. }
  245. // unsigned int alarm(unsigned int seconds);
  246. func Xalarm(t *TLS, seconds uint32) uint32 {
  247. if __ccgo_strace {
  248. trc("t=%v seconds=%v, (%v:)", t, seconds, origin(2))
  249. }
  250. panic(todo(""))
  251. // n, _, err := unix.Syscall(unix.SYS_ALARM, uintptr(seconds), 0, 0)
  252. // if err != 0 {
  253. // panic(todo(""))
  254. // }
  255. //
  256. // return uint32(n)
  257. }
  258. // int getrlimit(int resource, struct rlimit *rlim);
  259. func Xgetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
  260. if __ccgo_strace {
  261. trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
  262. }
  263. panic(todo(""))
  264. // if _, _, err := unix.Syscall(unix.SYS_GETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
  265. // t.setErrno(err)
  266. // return -1
  267. // }
  268. //
  269. // return 0
  270. }
  271. // time_t time(time_t *tloc);
  272. func Xtime(t *TLS, tloc uintptr) types.Time_t {
  273. if __ccgo_strace {
  274. trc("t=%v tloc=%v, (%v:)", t, tloc, origin(2))
  275. }
  276. panic(todo(""))
  277. // n, _, err := unix.Syscall(unix.SYS_TIME, tloc, 0, 0)
  278. // if err != 0 {
  279. // t.setErrno(err)
  280. // return types.Time_t(-1)
  281. // }
  282. //
  283. // if tloc != 0 {
  284. // *(*types.Time_t)(unsafe.Pointer(tloc)) = types.Time_t(n)
  285. // }
  286. // return types.Time_t(n)
  287. }
  288. // int mkdir(const char *path, mode_t mode);
  289. func Xmkdir(t *TLS, path uintptr, mode types.Mode_t) int32 {
  290. if __ccgo_strace {
  291. trc("t=%v path=%v mode=%v, (%v:)", t, path, mode, origin(2))
  292. }
  293. panic(todo(""))
  294. // if _, _, err := unix.Syscall(unix.SYS_MKDIR, path, uintptr(mode), 0); err != 0 {
  295. // t.setErrno(err)
  296. // return -1
  297. // }
  298. //
  299. // if dmesgs {
  300. // dmesg("%v: %q: ok", origin(1), GoString(path))
  301. // }
  302. // return 0
  303. }
  304. // int symlink(const char *target, const char *linkpath);
  305. func Xsymlink(t *TLS, target, linkpath uintptr) int32 {
  306. if __ccgo_strace {
  307. trc("t=%v linkpath=%v, (%v:)", t, linkpath, origin(2))
  308. }
  309. panic(todo(""))
  310. // if _, _, err := unix.Syscall(unix.SYS_SYMLINK, target, linkpath, 0); err != 0 {
  311. // t.setErrno(err)
  312. // return -1
  313. // }
  314. //
  315. // if dmesgs {
  316. // dmesg("%v: %q %q: ok", origin(1), GoString(target), GoString(linkpath))
  317. // }
  318. // return 0
  319. }
  320. // int utimes(const char *filename, const struct timeval times[2]);
  321. func Xutimes(t *TLS, filename, times uintptr) int32 {
  322. if __ccgo_strace {
  323. trc("t=%v times=%v, (%v:)", t, times, origin(2))
  324. }
  325. panic(todo(""))
  326. // if _, _, err := unix.Syscall(unix.SYS_UTIMES, filename, times, 0); err != 0 {
  327. // t.setErrno(err)
  328. // return -1
  329. // }
  330. //
  331. // if dmesgs {
  332. // dmesg("%v: %q: ok", origin(1), GoString(filename))
  333. // }
  334. // return 0
  335. }
  336. // int unlink(const char *pathname);
  337. func Xunlink(t *TLS, pathname uintptr) int32 {
  338. if __ccgo_strace {
  339. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  340. }
  341. err := windows.DeleteFile((*uint16)(unsafe.Pointer(pathname)))
  342. if err != nil {
  343. t.setErrno(err)
  344. return -1
  345. }
  346. if dmesgs {
  347. dmesg("%v: %q: ok", origin(1), GoString(pathname))
  348. }
  349. return 0
  350. }
  351. // int rmdir(const char *pathname);
  352. func Xrmdir(t *TLS, pathname uintptr) int32 {
  353. if __ccgo_strace {
  354. trc("t=%v pathname=%v, (%v:)", t, pathname, origin(2))
  355. }
  356. panic(todo(""))
  357. // if _, _, err := unix.Syscall(unix.SYS_RMDIR, pathname, 0, 0); err != 0 {
  358. // t.setErrno(err)
  359. // return -1
  360. // }
  361. //
  362. // if dmesgs {
  363. // dmesg("%v: %q: ok", origin(1), GoString(pathname))
  364. // }
  365. // return 0
  366. }
  367. // int mknod(const char *pathname, mode_t mode, dev_t dev);
  368. func Xmknod(t *TLS, pathname uintptr, mode types.Mode_t, dev types.Dev_t) int32 {
  369. if __ccgo_strace {
  370. trc("t=%v pathname=%v mode=%v dev=%v, (%v:)", t, pathname, mode, dev, origin(2))
  371. }
  372. panic(todo(""))
  373. // if _, _, err := unix.Syscall(unix.SYS_MKNOD, pathname, uintptr(mode), uintptr(dev)); err != 0 {
  374. // t.setErrno(err)
  375. // return -1
  376. // }
  377. //
  378. // return 0
  379. }
  380. // // int chown(const char *pathname, uid_t owner, gid_t group);
  381. // func Xchown(t *TLS, pathname uintptr, owner types.Uid_t, group types.Gid_t) int32 {
  382. // panic(todo(""))
  383. // // if _, _, err := unix.Syscall(unix.SYS_CHOWN, pathname, uintptr(owner), uintptr(group)); err != 0 {
  384. // // t.setErrno(err)
  385. // // return -1
  386. // // }
  387. // //
  388. // // return 0
  389. // }
  390. // int link(const char *oldpath, const char *newpath);
  391. func Xlink(t *TLS, oldpath, newpath uintptr) int32 {
  392. if __ccgo_strace {
  393. trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
  394. }
  395. panic(todo(""))
  396. // if _, _, err := unix.Syscall(unix.SYS_LINK, oldpath, newpath, 0); err != 0 {
  397. // t.setErrno(err)
  398. // return -1
  399. // }
  400. //
  401. // return 0
  402. }
  403. // int pipe(int pipefd[2]);
  404. func Xpipe(t *TLS, pipefd uintptr) int32 {
  405. if __ccgo_strace {
  406. trc("t=%v pipefd=%v, (%v:)", t, pipefd, origin(2))
  407. }
  408. panic(todo(""))
  409. // if _, _, err := unix.Syscall(unix.SYS_PIPE, pipefd, 0, 0); err != 0 {
  410. // t.setErrno(err)
  411. // return -1
  412. // }
  413. //
  414. // return 0
  415. }
  416. // int dup2(int oldfd, int newfd);
  417. func Xdup2(t *TLS, oldfd, newfd int32) int32 {
  418. if __ccgo_strace {
  419. trc("t=%v newfd=%v, (%v:)", t, newfd, origin(2))
  420. }
  421. panic(todo(""))
  422. // n, _, err := unix.Syscall(unix.SYS_DUP2, uintptr(oldfd), uintptr(newfd), 0)
  423. // if err != 0 {
  424. // t.setErrno(err)
  425. // return -1
  426. // }
  427. //
  428. // return int32(n)
  429. }
  430. // ssize_t readlink(const char *restrict path, char *restrict buf, size_t bufsize);
  431. func Xreadlink(t *TLS, path, buf uintptr, bufsize types.Size_t) types.Ssize_t {
  432. if __ccgo_strace {
  433. trc("t=%v buf=%v bufsize=%v, (%v:)", t, buf, bufsize, origin(2))
  434. }
  435. panic(todo(""))
  436. // n, _, err := unix.Syscall(unix.SYS_READLINK, path, buf, uintptr(bufsize))
  437. // if err != 0 {
  438. // t.setErrno(err)
  439. // return -1
  440. // }
  441. //
  442. // return types.Ssize_t(n)
  443. }
  444. // FILE *fopen64(const char *pathname, const char *mode);
  445. func Xfopen64(t *TLS, pathname, mode uintptr) uintptr {
  446. if __ccgo_strace {
  447. trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
  448. }
  449. m := strings.ReplaceAll(GoString(mode), "b", "")
  450. var flags int
  451. switch m {
  452. case "r":
  453. flags = os.O_RDONLY
  454. case "r+":
  455. flags = os.O_RDWR
  456. case "w":
  457. flags = os.O_WRONLY | os.O_CREATE | os.O_TRUNC
  458. case "w+":
  459. flags = os.O_RDWR | os.O_CREATE | os.O_TRUNC
  460. case "a":
  461. flags = os.O_WRONLY | os.O_CREATE | os.O_APPEND
  462. case "a+":
  463. flags = os.O_RDWR | os.O_CREATE | os.O_APPEND
  464. default:
  465. panic(m)
  466. }
  467. //TODO- flags |= fcntl.O_LARGEFILE
  468. h, err := windows.Open(GoString(pathname), int(flags), uint32(0666))
  469. if err != nil {
  470. t.setErrno(err)
  471. return 0
  472. }
  473. p, _ := wrapFdHandle(h)
  474. if p != 0 {
  475. return p
  476. }
  477. _ = windows.Close(h)
  478. t.setErrno(errno.ENOMEM)
  479. return 0
  480. }
  481. func Xrecv(t *TLS, sockfd uint32, buf uintptr, len, flags int32) int32 {
  482. if __ccgo_strace {
  483. trc("t=%v sockfd=%v buf=%v flags=%v, (%v:)", t, sockfd, buf, flags, origin(2))
  484. }
  485. panic(todo(""))
  486. }
  487. func Xsend(t *TLS, sockfd uint32, buf uintptr, len, flags int32) int32 {
  488. if __ccgo_strace {
  489. trc("t=%v sockfd=%v buf=%v flags=%v, (%v:)", t, sockfd, buf, flags, origin(2))
  490. }
  491. panic(todo(""))
  492. }
  493. func Xshutdown(t *TLS, sockfd uint32, how int32) int32 {
  494. if __ccgo_strace {
  495. trc("t=%v sockfd=%v how=%v, (%v:)", t, sockfd, how, origin(2))
  496. }
  497. panic(todo(""))
  498. // if _, _, err := unix.Syscall(unix.SYS_SHUTDOWN, uintptr(sockfd), uintptr(how), 0); err != 0 {
  499. // t.setErrno(err)
  500. // return -1
  501. // }
  502. //
  503. // return 0
  504. }
  505. func Xgetpeername(t *TLS, sockfd uint32, addr uintptr, addrlen uintptr) int32 {
  506. if __ccgo_strace {
  507. trc("t=%v sockfd=%v addr=%v addrlen=%v, (%v:)", t, sockfd, addr, addrlen, origin(2))
  508. }
  509. panic(todo(""))
  510. }
  511. func Xgetsockname(t *TLS, sockfd uint32, addr, addrlen uintptr) int32 {
  512. if __ccgo_strace {
  513. trc("t=%v sockfd=%v addrlen=%v, (%v:)", t, sockfd, addrlen, origin(2))
  514. }
  515. panic(todo(""))
  516. }
  517. func Xsocket(t *TLS, domain, type1, protocol int32) uint32 {
  518. if __ccgo_strace {
  519. trc("t=%v protocol=%v, (%v:)", t, protocol, origin(2))
  520. }
  521. panic(todo(""))
  522. }
  523. func Xbind(t *TLS, sockfd uint32, addr uintptr, addrlen int32) int32 {
  524. if __ccgo_strace {
  525. trc("t=%v sockfd=%v addr=%v addrlen=%v, (%v:)", t, sockfd, addr, addrlen, origin(2))
  526. }
  527. panic(todo(""))
  528. }
  529. func Xconnect(t *TLS, sockfd uint32, addr uintptr, addrlen int32) int32 {
  530. if __ccgo_strace {
  531. trc("t=%v sockfd=%v addr=%v addrlen=%v, (%v:)", t, sockfd, addr, addrlen, origin(2))
  532. }
  533. panic(todo(""))
  534. }
  535. func Xlisten(t *TLS, sockfd uint32, backlog int32) int32 {
  536. if __ccgo_strace {
  537. trc("t=%v sockfd=%v backlog=%v, (%v:)", t, sockfd, backlog, origin(2))
  538. }
  539. panic(todo(""))
  540. }
  541. func Xaccept(t *TLS, sockfd uint32, addr uintptr, addrlen uintptr) uint32 {
  542. if __ccgo_strace {
  543. trc("t=%v sockfd=%v addr=%v addrlen=%v, (%v:)", t, sockfd, addr, addrlen, origin(2))
  544. }
  545. panic(todo(""))
  546. }
  547. // struct tm *_localtime32( const __time32_t *sourceTime );
  548. func X_localtime32(_ *TLS, sourceTime uintptr) uintptr {
  549. loc := getLocalLocation()
  550. ut := *(*time.Time_t)(unsafe.Pointer(sourceTime))
  551. t := gotime.Unix(int64(ut), 0).In(loc)
  552. localtime.Ftm_sec = int32(t.Second())
  553. localtime.Ftm_min = int32(t.Minute())
  554. localtime.Ftm_hour = int32(t.Hour())
  555. localtime.Ftm_mday = int32(t.Day())
  556. localtime.Ftm_mon = int32(t.Month() - 1)
  557. localtime.Ftm_year = int32(t.Year() - 1900)
  558. localtime.Ftm_wday = int32(t.Weekday())
  559. localtime.Ftm_yday = int32(t.YearDay())
  560. localtime.Ftm_isdst = Bool32(isTimeDST(t))
  561. return uintptr(unsafe.Pointer(&localtime))
  562. }
  563. // struct tm *_gmtime32( const __time32_t *sourceTime );
  564. func X_gmtime32(t *TLS, sourceTime uintptr) uintptr {
  565. r0, _, err := procGmtime32.Call(uintptr(sourceTime))
  566. if err != windows.NOERROR {
  567. t.setErrno(err)
  568. }
  569. return uintptr(r0)
  570. }
  571. // LONG SetWindowLongW(
  572. //
  573. // HWND hWnd,
  574. // int nIndex,
  575. // LONG dwNewLong
  576. //
  577. // );
  578. func XSetWindowLongW(t *TLS, hwnd uintptr, nIndex int32, dwNewLong long) long {
  579. if __ccgo_strace {
  580. trc("t=%v hwnd=%v nIndex=%v dwNewLong=%v, (%v:)", t, hwnd, nIndex, dwNewLong, origin(2))
  581. }
  582. panic(todo(""))
  583. }
  584. // LONG GetWindowLongW(
  585. //
  586. // HWND hWnd,
  587. // int nIndex
  588. //
  589. // );
  590. func XGetWindowLongW(t *TLS, hwnd uintptr, nIndex int32) long {
  591. if __ccgo_strace {
  592. trc("t=%v hwnd=%v nIndex=%v, (%v:)", t, hwnd, nIndex, origin(2))
  593. }
  594. panic(todo(""))
  595. }
  596. // LRESULT LRESULT DefWindowProcW(
  597. //
  598. // HWND hWnd,
  599. // UINT Msg,
  600. // WPARAM wParam,
  601. // LPARAM lParam
  602. //
  603. // );
  604. func XDefWindowProcW(t *TLS, _ ...interface{}) int32 {
  605. panic(todo(""))
  606. }
  607. func XSendMessageTimeoutW(t *TLS, _ ...interface{}) int32 {
  608. panic(todo(""))
  609. }
  610. // int _fstat(
  611. //
  612. // int fd,
  613. // struct __stat *buffer
  614. //
  615. // );
  616. func X_fstat(t *TLS, fd int32, buffer uintptr) int32 {
  617. if __ccgo_strace {
  618. trc("t=%v fd=%v buffer=%v, (%v:)", t, fd, buffer, origin(2))
  619. }
  620. f, ok := fdToFile(fd)
  621. if !ok {
  622. t.setErrno(EBADF)
  623. return -1
  624. }
  625. var d windows.ByHandleFileInformation
  626. err := windows.GetFileInformationByHandle(f.Handle, &d)
  627. if err != nil {
  628. t.setErrno(EBADF)
  629. return -1
  630. }
  631. var bStat32 = (*stat.X_stat32)(unsafe.Pointer(buffer))
  632. var accessTime = int64(d.LastAccessTime.HighDateTime)<<32 + int64(d.LastAccessTime.LowDateTime)
  633. bStat32.Fst_atime = int32(WindowsTickToUnixSeconds(accessTime))
  634. var modTime = int64(d.LastWriteTime.HighDateTime)<<32 + int64(d.LastWriteTime.LowDateTime)
  635. bStat32.Fst_mtime = int32(WindowsTickToUnixSeconds(modTime))
  636. var crTime = int64(d.CreationTime.HighDateTime)<<32 + int64(d.CreationTime.LowDateTime)
  637. bStat32.Fst_ctime = int32(WindowsTickToUnixSeconds(crTime))
  638. var fSz = int64(d.FileSizeHigh)<<32 + int64(d.FileSizeLow)
  639. bStat32.Fst_size = int32(fSz)
  640. bStat32.Fst_mode = WindowsAttrbiutesToStat(d.FileAttributes)
  641. return 0
  642. }
  643. func Xstrspn(tls *TLS, s uintptr, c uintptr) size_t { /* strspn.c:6:8: */
  644. if __ccgo_strace {
  645. trc("tls=%v s=%v c=%v, (%v:)", tls, s, c, origin(2))
  646. }
  647. bp := tls.Alloc(32)
  648. defer tls.Free(32)
  649. var a uintptr = s
  650. *(*[8]size_t)(unsafe.Pointer(bp /* byteset */)) = [8]size_t{0: size_t(0)}
  651. if !(int32(*(*int8)(unsafe.Pointer(c))) != 0) {
  652. return size_t(0)
  653. }
  654. if !(int32(*(*int8)(unsafe.Pointer(c + 1))) != 0) {
  655. for ; int32(*(*int8)(unsafe.Pointer(s))) == int32(*(*int8)(unsafe.Pointer(c))); s++ {
  656. }
  657. return size_t((int32(s) - int32(a)) / 1)
  658. }
  659. for ; *(*int8)(unsafe.Pointer(c)) != 0 && AssignOrPtrUint32(bp+uintptr(size_t(*(*uint8)(unsafe.Pointer(c)))/(uint32(8)*uint32(unsafe.Sizeof(size_t(0)))))*4, size_t(size_t(1))<<(size_t(*(*uint8)(unsafe.Pointer(c)))%(uint32(8)*uint32(unsafe.Sizeof(size_t(0)))))) != 0; c++ {
  660. }
  661. for ; *(*int8)(unsafe.Pointer(s)) != 0 && *(*size_t)(unsafe.Pointer(bp + uintptr(size_t(*(*uint8)(unsafe.Pointer(s)))/(uint32(8)*uint32(unsafe.Sizeof(size_t(0)))))*4))&(size_t(size_t(1))<<(size_t(*(*uint8)(unsafe.Pointer(s)))%(uint32(8)*uint32(unsafe.Sizeof(size_t(0)))))) != 0; s++ {
  662. }
  663. return size_t((int32(s) - int32(a)) / 1)
  664. }