musl_windows_arm64.go 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267
  1. // Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_arm64.go -pkgname libc -static-locals-prefix _s -Iarch\aarch64 -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/isspace.c src/ctype/isxdigit.c src/env/putenv.c src/env/setenv.c src/env/unsetenv.c src/multibyte/wcrtomb.c src/multibyte/wcsrtombs.c src/multibyte/wcstombs.c src/stdlib/bsearch.c src/string/strchrnul.c src/string/strdup.c', DO NOT EDIT.
  2. package libc
  3. import (
  4. "math"
  5. "reflect"
  6. "sync/atomic"
  7. "unsafe"
  8. )
  9. var _ = math.Pi
  10. var _ reflect.Kind
  11. var _ atomic.Value
  12. var _ unsafe.Pointer
  13. // musl as a whole is licensed under the following standard MIT license:
  14. //
  15. // ----------------------------------------------------------------------
  16. // Copyright © 2005-2020 Rich Felker, et al.
  17. //
  18. // Permission is hereby granted, free of charge, to any person obtaining
  19. // a copy of this software and associated documentation files (the
  20. // "Software"), to deal in the Software without restriction, including
  21. // without limitation the rights to use, copy, modify, merge, publish,
  22. // distribute, sublicense, and/or sell copies of the Software, and to
  23. // permit persons to whom the Software is furnished to do so, subject to
  24. // the following conditions:
  25. //
  26. // The above copyright notice and this permission notice shall be
  27. // included in all copies or substantial portions of the Software.
  28. //
  29. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  30. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  31. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  32. // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  33. // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  34. // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  35. // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  36. // ----------------------------------------------------------------------
  37. //
  38. // Authors/contributors include:
  39. //
  40. // A. Wilcox
  41. // Ada Worcester
  42. // Alex Dowad
  43. // Alex Suykov
  44. // Alexander Monakov
  45. // Andre McCurdy
  46. // Andrew Kelley
  47. // Anthony G. Basile
  48. // Aric Belsito
  49. // Arvid Picciani
  50. // Bartosz Brachaczek
  51. // Benjamin Peterson
  52. // Bobby Bingham
  53. // Boris Brezillon
  54. // Brent Cook
  55. // Chris Spiegel
  56. // Clément Vasseur
  57. // Daniel Micay
  58. // Daniel Sabogal
  59. // Daurnimator
  60. // David Carlier
  61. // David Edelsohn
  62. // Denys Vlasenko
  63. // Dmitry Ivanov
  64. // Dmitry V. Levin
  65. // Drew DeVault
  66. // Emil Renner Berthing
  67. // Fangrui Song
  68. // Felix Fietkau
  69. // Felix Janda
  70. // Gianluca Anzolin
  71. // Hauke Mehrtens
  72. // He X
  73. // Hiltjo Posthuma
  74. // Isaac Dunham
  75. // Jaydeep Patil
  76. // Jens Gustedt
  77. // Jeremy Huntwork
  78. // Jo-Philipp Wich
  79. // Joakim Sindholt
  80. // John Spencer
  81. // Julien Ramseier
  82. // Justin Cormack
  83. // Kaarle Ritvanen
  84. // Khem Raj
  85. // Kylie McClain
  86. // Leah Neukirchen
  87. // Luca Barbato
  88. // Luka Perkov
  89. // M Farkas-Dyck (Strake)
  90. // Mahesh Bodapati
  91. // Markus Wichmann
  92. // Masanori Ogino
  93. // Michael Clark
  94. // Michael Forney
  95. // Mikhail Kremnyov
  96. // Natanael Copa
  97. // Nicholas J. Kain
  98. // orc
  99. // Pascal Cuoq
  100. // Patrick Oppenlander
  101. // Petr Hosek
  102. // Petr Skocik
  103. // Pierre Carrier
  104. // Reini Urban
  105. // Rich Felker
  106. // Richard Pennington
  107. // Ryan Fairfax
  108. // Samuel Holland
  109. // Segev Finer
  110. // Shiz
  111. // sin
  112. // Solar Designer
  113. // Stefan Kristiansson
  114. // Stefan O'Rear
  115. // Szabolcs Nagy
  116. // Timo Teräs
  117. // Trutz Behn
  118. // Valentin Ochs
  119. // Will Dietz
  120. // William Haddon
  121. // William Pitcock
  122. //
  123. // Portions of this software are derived from third-party works licensed
  124. // under terms compatible with the above MIT license:
  125. //
  126. // The TRE regular expression implementation (src/regex/reg* and
  127. // src/regex/tre*) is Copyright © 2001-2008 Ville Laurikari and licensed
  128. // under a 2-clause BSD license (license text in the source files). The
  129. // included version has been heavily modified by Rich Felker in 2012, in
  130. // the interests of size, simplicity, and namespace cleanliness.
  131. //
  132. // Much of the math library code (src/math/* and src/complex/*) is
  133. // Copyright © 1993,2004 Sun Microsystems or
  134. // Copyright © 2003-2011 David Schultz or
  135. // Copyright © 2003-2009 Steven G. Kargl or
  136. // Copyright © 2003-2009 Bruce D. Evans or
  137. // Copyright © 2008 Stephen L. Moshier or
  138. // Copyright © 2017-2018 Arm Limited
  139. // and labelled as such in comments in the individual source files. All
  140. // have been licensed under extremely permissive terms.
  141. //
  142. // The ARM memcpy code (src/string/arm/memcpy.S) is Copyright © 2008
  143. // The Android Open Source Project and is licensed under a two-clause BSD
  144. // license. It was taken from Bionic libc, used on Android.
  145. //
  146. // The AArch64 memcpy and memset code (src/string/aarch64/*) are
  147. // Copyright © 1999-2019, Arm Limited.
  148. //
  149. // The implementation of DES for crypt (src/crypt/crypt_des.c) is
  150. // Copyright © 1994 David Burren. It is licensed under a BSD license.
  151. //
  152. // The implementation of blowfish crypt (src/crypt/crypt_blowfish.c) was
  153. // originally written by Solar Designer and placed into the public
  154. // domain. The code also comes with a fallback permissive license for use
  155. // in jurisdictions that may not recognize the public domain.
  156. //
  157. // The smoothsort implementation (src/stdlib/qsort.c) is Copyright © 2011
  158. // Valentin Ochs and is licensed under an MIT-style license.
  159. //
  160. // The x86_64 port was written by Nicholas J. Kain and is licensed under
  161. // the standard MIT terms.
  162. //
  163. // The mips and microblaze ports were originally written by Richard
  164. // Pennington for use in the ellcc project. The original code was adapted
  165. // by Rich Felker for build system and code conventions during upstream
  166. // integration. It is licensed under the standard MIT terms.
  167. //
  168. // The mips64 port was contributed by Imagination Technologies and is
  169. // licensed under the standard MIT terms.
  170. //
  171. // The powerpc port was also originally written by Richard Pennington,
  172. // and later supplemented and integrated by John Spencer. It is licensed
  173. // under the standard MIT terms.
  174. //
  175. // All other files which have no copyright comments are original works
  176. // produced specifically for use as part of this library, written either
  177. // by Rich Felker, the main author of the library, or by one or more
  178. // contibutors listed above. Details on authorship of individual files
  179. // can be found in the git version control history of the project. The
  180. // omission of copyright and license comments in each file is in the
  181. // interest of source tree size.
  182. //
  183. // In addition, permission is hereby granted for all public header files
  184. // (include/* and arch/*/bits/*) and crt files intended to be linked into
  185. // applications (crt/*, ldso/dlstart.c, and arch/*/crt_arch.h) to omit
  186. // the copyright notice and permission notice otherwise required by the
  187. // license, and to use these files without any requirement of
  188. // attribution. These files include substantial contributions from:
  189. //
  190. // Bobby Bingham
  191. // John Spencer
  192. // Nicholas J. Kain
  193. // Rich Felker
  194. // Richard Pennington
  195. // Stefan Kristiansson
  196. // Szabolcs Nagy
  197. //
  198. // all of whom have explicitly granted such permission.
  199. //
  200. // This file previously contained text expressing a belief that most of
  201. // the files covered by the above exception were sufficiently trivial not
  202. // to be subject to copyright, resulting in confusion over whether it
  203. // negated the permissions granted in the license. In the spirit of
  204. // permissive licensing, and of not having licensing issues being an
  205. // obstacle to adoption, that text has been removed.
  206. const ( /* copyright.c:194:1: */
  207. __musl__copyright__ = 0
  208. )
  209. const ( /* pthread_impl.h:58:1: */
  210. DT_EXITING = 0
  211. DT_JOINABLE = 1
  212. DT_DETACHED = 2
  213. )
  214. type ptrdiff_t = int64 /* <builtin>:3:26 */
  215. type size_t = uint64 /* <builtin>:9:23 */
  216. type wchar_t = uint16 /* <builtin>:15:24 */
  217. type va_list = uintptr /* <builtin>:50:27 */
  218. type __locale_struct = struct{ cat [6]uintptr } /* alltypes.h:351:9 */
  219. type locale_t = uintptr /* alltypes.h:351:32 */
  220. func Xisalnum(tls *TLS, c int32) int32 { /* isalnum.c:3:5: */
  221. if __ccgo_strace {
  222. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  223. }
  224. return Bool32(func() int32 {
  225. if 0 != 0 {
  226. return Xisalpha(tls, c)
  227. }
  228. return Bool32(uint32(c)|uint32(32)-uint32('a') < uint32(26))
  229. }() != 0 || func() int32 {
  230. if 0 != 0 {
  231. return Xisdigit(tls, c)
  232. }
  233. return Bool32(uint32(c)-uint32('0') < uint32(10))
  234. }() != 0)
  235. }
  236. func X__isalnum_l(tls *TLS, c int32, l locale_t) int32 { /* isalnum.c:8:5: */
  237. if __ccgo_strace {
  238. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  239. }
  240. return Xisalnum(tls, c)
  241. }
  242. func Xisalpha(tls *TLS, c int32) int32 { /* isalpha.c:4:5: */
  243. if __ccgo_strace {
  244. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  245. }
  246. return Bool32(uint32(c)|uint32(32)-uint32('a') < uint32(26))
  247. }
  248. func X__isalpha_l(tls *TLS, c int32, l locale_t) int32 { /* isalpha.c:9:5: */
  249. if __ccgo_strace {
  250. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  251. }
  252. return Xisalpha(tls, c)
  253. }
  254. func Xisdigit(tls *TLS, c int32) int32 { /* isdigit.c:4:5: */
  255. if __ccgo_strace {
  256. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  257. }
  258. return Bool32(uint32(c)-uint32('0') < uint32(10))
  259. }
  260. func X__isdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isdigit.c:9:5: */
  261. if __ccgo_strace {
  262. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  263. }
  264. return Xisdigit(tls, c)
  265. }
  266. func X__islower_l(tls *TLS, c int32, l locale_t) int32 { /* islower.c:9:5: */
  267. if __ccgo_strace {
  268. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  269. }
  270. return Xislower(tls, c)
  271. }
  272. func Xisprint(tls *TLS, c int32) int32 { /* isprint.c:4:5: */
  273. if __ccgo_strace {
  274. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  275. }
  276. return Bool32(uint32(c)-uint32(0x20) < uint32(0x5f))
  277. }
  278. func X__isprint_l(tls *TLS, c int32, l locale_t) int32 { /* isprint.c:9:5: */
  279. if __ccgo_strace {
  280. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  281. }
  282. return Xisprint(tls, c)
  283. }
  284. func Xisspace(tls *TLS, c int32) int32 { /* isspace.c:4:5: */
  285. if __ccgo_strace {
  286. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  287. }
  288. return Bool32(c == ' ' || uint32(c)-uint32('\t') < uint32(5))
  289. }
  290. func X__isspace_l(tls *TLS, c int32, l locale_t) int32 { /* isspace.c:9:5: */
  291. if __ccgo_strace {
  292. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  293. }
  294. return Xisspace(tls, c)
  295. }
  296. func Xisxdigit(tls *TLS, c int32) int32 { /* isxdigit.c:3:5: */
  297. if __ccgo_strace {
  298. trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
  299. }
  300. return Bool32(func() int32 {
  301. if 0 != 0 {
  302. return Xisdigit(tls, c)
  303. }
  304. return Bool32(uint32(c)-uint32('0') < uint32(10))
  305. }() != 0 || uint32(c)|uint32(32)-uint32('a') < uint32(6))
  306. }
  307. func X__isxdigit_l(tls *TLS, c int32, l locale_t) int32 { /* isxdigit.c:8:5: */
  308. if __ccgo_strace {
  309. trc("tls=%v c=%v l=%v, (%v:)", tls, c, l, origin(2))
  310. }
  311. return Xisxdigit(tls, c)
  312. }
  313. type div_t = struct {
  314. quot int32
  315. rem int32
  316. } /* stdlib.h:62:35 */
  317. type ldiv_t = struct {
  318. quot int32
  319. rem int32
  320. } /* stdlib.h:63:36 */
  321. type lldiv_t = struct {
  322. quot int64
  323. rem int64
  324. } /* stdlib.h:64:41 */
  325. type ssize_t = int32 /* alltypes.h:73:15 */
  326. type intptr_t = int32 /* alltypes.h:78:15 */
  327. type off_t = int32 /* alltypes.h:170:16 */
  328. type pid_t = int32 /* alltypes.h:243:13 */
  329. type uid_t = uint32 /* alltypes.h:253:18 */
  330. type gid_t = uint32 /* alltypes.h:258:18 */
  331. type useconds_t = uint32 /* alltypes.h:268:18 */
  332. func X__putenv(tls *TLS, s uintptr, l size_t, r uintptr) int32 { /* putenv.c:8:5: */
  333. if __ccgo_strace {
  334. trc("tls=%v s=%v l=%v r=%v, (%v:)", tls, s, l, r, origin(2))
  335. }
  336. var i size_t
  337. var newenv uintptr
  338. var tmp uintptr
  339. //TODO for (char **e = __environ; *e; e++, i++)
  340. var e uintptr
  341. i = uint64(0)
  342. if !(Environ() != 0) {
  343. goto __1
  344. }
  345. //TODO for (char **e = __environ; *e; e++, i++)
  346. e = Environ()
  347. __2:
  348. if !(*(*uintptr)(unsafe.Pointer(e)) != 0) {
  349. goto __4
  350. }
  351. if !!(Xstrncmp(tls, s, *(*uintptr)(unsafe.Pointer(e)), l+uint64(1)) != 0) {
  352. goto __5
  353. }
  354. tmp = *(*uintptr)(unsafe.Pointer(e))
  355. *(*uintptr)(unsafe.Pointer(e)) = s
  356. X__env_rm_add(tls, tmp, r)
  357. return 0
  358. __5:
  359. ;
  360. goto __3
  361. __3:
  362. e += 8
  363. i++
  364. goto __2
  365. goto __4
  366. __4:
  367. ;
  368. __1:
  369. ;
  370. if !(Environ() == _soldenv) {
  371. goto __6
  372. }
  373. newenv = Xrealloc(tls, _soldenv, uint64(unsafe.Sizeof(uintptr(0)))*(i+uint64(2)))
  374. if !!(newenv != 0) {
  375. goto __8
  376. }
  377. goto oom
  378. __8:
  379. ;
  380. goto __7
  381. __6:
  382. newenv = Xmalloc(tls, uint64(unsafe.Sizeof(uintptr(0)))*(i+uint64(2)))
  383. if !!(newenv != 0) {
  384. goto __9
  385. }
  386. goto oom
  387. __9:
  388. ;
  389. if !(i != 0) {
  390. goto __10
  391. }
  392. Xmemcpy(tls, newenv, Environ(), uint64(unsafe.Sizeof(uintptr(0)))*i)
  393. __10:
  394. ;
  395. Xfree(tls, _soldenv)
  396. __7:
  397. ;
  398. *(*uintptr)(unsafe.Pointer(newenv + uintptr(i)*8)) = s
  399. *(*uintptr)(unsafe.Pointer(newenv + uintptr(i+uint64(1))*8)) = uintptr(0)
  400. *(*uintptr)(unsafe.Pointer(EnvironP())) = AssignPtrUintptr(uintptr(unsafe.Pointer(&_soldenv)), newenv)
  401. if !(r != 0) {
  402. goto __11
  403. }
  404. X__env_rm_add(tls, uintptr(0), r)
  405. __11:
  406. ;
  407. return 0
  408. oom:
  409. Xfree(tls, r)
  410. return -1
  411. }
  412. var _soldenv uintptr /* putenv.c:22:14: */
  413. func Xputenv(tls *TLS, s uintptr) int32 { /* putenv.c:43:5: */
  414. if __ccgo_strace {
  415. trc("tls=%v s=%v, (%v:)", tls, s, origin(2))
  416. }
  417. var l size_t = size_t((int64(X__strchrnul(tls, s, '=')) - int64(s)) / 1)
  418. if !(l != 0) || !(int32(*(*int8)(unsafe.Pointer(s + uintptr(l)))) != 0) {
  419. return Xunsetenv(tls, s)
  420. }
  421. return X__putenv(tls, s, l, uintptr(0))
  422. }
  423. func X__env_rm_add(tls *TLS, old uintptr, new uintptr) { /* setenv.c:5:6: */
  424. if __ccgo_strace {
  425. trc("tls=%v old=%v new=%v, (%v:)", tls, old, new, origin(2))
  426. }
  427. //TODO for (size_t i=0; i < env_alloced_n; i++)
  428. var i size_t = uint64(0)
  429. for ; i < _senv_alloced_n; i++ {
  430. if *(*uintptr)(unsafe.Pointer(_senv_alloced + uintptr(i)*8)) == old {
  431. *(*uintptr)(unsafe.Pointer(_senv_alloced + uintptr(i)*8)) = new
  432. Xfree(tls, old)
  433. return
  434. } else if !(int32(*(*uintptr)(unsafe.Pointer(_senv_alloced + uintptr(i)*8))) != 0) && new != 0 {
  435. *(*uintptr)(unsafe.Pointer(_senv_alloced + uintptr(i)*8)) = new
  436. new = uintptr(0)
  437. }
  438. }
  439. if !(new != 0) {
  440. return
  441. }
  442. var t uintptr = Xrealloc(tls, _senv_alloced, uint64(unsafe.Sizeof(uintptr(0)))*(_senv_alloced_n+uint64(1)))
  443. if !(t != 0) {
  444. return
  445. }
  446. *(*uintptr)(unsafe.Pointer(AssignPtrUintptr(uintptr(unsafe.Pointer(&_senv_alloced)), t) + uintptr(PostIncUint64(&_senv_alloced_n, 1))*8)) = new
  447. }
  448. var _senv_alloced uintptr /* setenv.c:7:14: */
  449. var _senv_alloced_n size_t /* setenv.c:8:16: */
  450. func Xsetenv(tls *TLS, var1 uintptr, value uintptr, overwrite int32) int32 { /* setenv.c:26:5: */
  451. if __ccgo_strace {
  452. trc("tls=%v var1=%v value=%v overwrite=%v, (%v:)", tls, var1, value, overwrite, origin(2))
  453. }
  454. var s uintptr
  455. var l1 size_t
  456. var l2 size_t
  457. if !(var1 != 0) || !(int32(AssignUint64(&l1, size_t((int64(X__strchrnul(tls, var1, '='))-int64(var1))/1))) != 0) || *(*int8)(unsafe.Pointer(var1 + uintptr(l1))) != 0 {
  458. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 22
  459. return -1
  460. }
  461. if !(overwrite != 0) && Xgetenv(tls, var1) != 0 {
  462. return 0
  463. }
  464. l2 = Xstrlen(tls, value)
  465. s = Xmalloc(tls, l1+l2+uint64(2))
  466. if !(s != 0) {
  467. return -1
  468. }
  469. Xmemcpy(tls, s, var1, l1)
  470. *(*int8)(unsafe.Pointer(s + uintptr(l1))) = int8('=')
  471. Xmemcpy(tls, s+uintptr(l1)+uintptr(1), value, l2+uint64(1))
  472. return X__putenv(tls, s, l1, s)
  473. }
  474. func Xunsetenv(tls *TLS, name uintptr) int32 { /* unsetenv.c:9:5: */
  475. if __ccgo_strace {
  476. trc("tls=%v name=%v, (%v:)", tls, name, origin(2))
  477. }
  478. var l size_t = size_t((int64(X__strchrnul(tls, name, '=')) - int64(name)) / 1)
  479. if !(l != 0) || *(*int8)(unsafe.Pointer(name + uintptr(l))) != 0 {
  480. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 22
  481. return -1
  482. }
  483. if Environ() != 0 {
  484. var e uintptr = Environ()
  485. var eo uintptr = e
  486. for ; *(*uintptr)(unsafe.Pointer(e)) != 0; e += 8 {
  487. //TODO if (!strncmp(name, *e, l) && l[*e] == '=')
  488. if !(Xstrncmp(tls, name, *(*uintptr)(unsafe.Pointer(e)), l) != 0) && int32(*(*int8)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(e)) + uintptr(l)))) == '=' {
  489. X__env_rm_add(tls, *(*uintptr)(unsafe.Pointer(e)), uintptr(0))
  490. } else if eo != e {
  491. *(*uintptr)(unsafe.Pointer(PostIncUintptr(&eo, 8))) = *(*uintptr)(unsafe.Pointer(e))
  492. } else {
  493. eo += 8
  494. }
  495. }
  496. if eo != e {
  497. *(*uintptr)(unsafe.Pointer(eo)) = uintptr(0)
  498. }
  499. }
  500. return 0
  501. }
  502. type wint_t = uint32 /* alltypes.h:21:18 */
  503. type wctype_t = uint32 /* alltypes.h:211:23 */
  504. type __mbstate_t = struct {
  505. __opaque1 uint32
  506. __opaque2 uint32
  507. } /* alltypes.h:345:9 */
  508. type mbstate_t = __mbstate_t /* alltypes.h:345:63 */
  509. type tm = struct {
  510. tm_sec int32
  511. tm_min int32
  512. tm_hour int32
  513. tm_mday int32
  514. tm_mon int32
  515. tm_year int32
  516. tm_wday int32
  517. tm_yday int32
  518. tm_isdst int32
  519. tm_gmtoff int32
  520. tm_zone uintptr
  521. } /* wchar.h:138:1 */
  522. type uintptr_t = uint32 /* alltypes.h:63:24 */
  523. type int8_t = int8 /* alltypes.h:104:25 */
  524. type int16_t = int16 /* alltypes.h:109:25 */
  525. type int32_t = int32 /* alltypes.h:114:25 */
  526. type int64_t = int32 /* alltypes.h:119:25 */
  527. type intmax_t = int32 /* alltypes.h:124:25 */
  528. type uint8_t = uint8 /* alltypes.h:129:25 */
  529. type uint16_t = uint16 /* alltypes.h:134:25 */
  530. type uint32_t = uint32 /* alltypes.h:139:25 */
  531. type uint64_t = uint32 /* alltypes.h:144:25 */
  532. type uintmax_t = uint32 /* alltypes.h:154:25 */
  533. type int_fast8_t = int8_t /* stdint.h:22:16 */
  534. type int_fast64_t = int64_t /* stdint.h:23:17 */
  535. type int_least8_t = int8_t /* stdint.h:25:17 */
  536. type int_least16_t = int16_t /* stdint.h:26:17 */
  537. type int_least32_t = int32_t /* stdint.h:27:17 */
  538. type int_least64_t = int64_t /* stdint.h:28:17 */
  539. type uint_fast8_t = uint8_t /* stdint.h:30:17 */
  540. type uint_fast64_t = uint64_t /* stdint.h:31:18 */
  541. type uint_least8_t = uint8_t /* stdint.h:33:18 */
  542. type uint_least16_t = uint16_t /* stdint.h:34:18 */
  543. type uint_least32_t = uint32_t /* stdint.h:35:18 */
  544. type uint_least64_t = uint64_t /* stdint.h:36:18 */
  545. type int_fast16_t = int32_t /* stdint.h:1:17 */
  546. type int_fast32_t = int32_t /* stdint.h:2:17 */
  547. type uint_fast16_t = uint32_t /* stdint.h:3:18 */
  548. type uint_fast32_t = uint32_t /* stdint.h:4:18 */
  549. // Upper 6 state bits are a negative integer offset to bound-check next byte
  550. // equivalent to: ( (b-0x80) | (b+offset) ) & ~0x3f
  551. // Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear.
  552. // Arbitrary encoding for representing code units instead of characters.
  553. // Get inline definition of MB_CUR_MAX.
  554. type lconv = struct {
  555. decimal_point uintptr
  556. thousands_sep uintptr
  557. grouping uintptr
  558. int_curr_symbol uintptr
  559. currency_symbol uintptr
  560. mon_decimal_point uintptr
  561. mon_thousands_sep uintptr
  562. mon_grouping uintptr
  563. positive_sign uintptr
  564. negative_sign uintptr
  565. int_frac_digits int8
  566. frac_digits int8
  567. p_cs_precedes int8
  568. p_sep_by_space int8
  569. n_cs_precedes int8
  570. n_sep_by_space int8
  571. p_sign_posn int8
  572. n_sign_posn int8
  573. int_p_cs_precedes int8
  574. int_p_sep_by_space int8
  575. int_n_cs_precedes int8
  576. int_n_sep_by_space int8
  577. int_p_sign_posn int8
  578. int_n_sign_posn int8
  579. _ [2]byte
  580. } /* locale.h:24:1 */
  581. type _G_fpos64_t = struct {
  582. _ [0]uint64
  583. __opaque [16]int8
  584. } /* stdio.h:54:9 */
  585. type fpos_t = _G_fpos64_t /* stdio.h:58:3 */
  586. // Support signed or unsigned plain-char
  587. // Implementation choices...
  588. // Arbitrary numbers...
  589. // POSIX/SUS requirements follow. These numbers come directly
  590. // from SUS and have nothing to do with the host system.
  591. type __locale_map = struct {
  592. __map uintptr
  593. map_size size_t
  594. name [24]int8
  595. next uintptr
  596. } /* alltypes.h:351:9 */
  597. type tls_module = struct {
  598. next uintptr
  599. image uintptr
  600. len size_t
  601. size size_t
  602. align size_t
  603. offset size_t
  604. } /* libc.h:14:1 */
  605. type __libc = struct {
  606. can_do_threads int8
  607. threaded int8
  608. secure int8
  609. need_locks int8
  610. threads_minus_1 int32
  611. auxv uintptr
  612. tls_head uintptr
  613. tls_size size_t
  614. tls_align size_t
  615. tls_cnt size_t
  616. page_size size_t
  617. global_locale struct{ cat [6]uintptr }
  618. } /* libc.h:20:1 */
  619. type time_t = int32 /* alltypes.h:93:16 */
  620. type clockid_t = int32 /* alltypes.h:222:13 */
  621. type timespec = struct {
  622. tv_sec time_t
  623. tv_nsec int32
  624. } /* alltypes.h:237:1 */
  625. type __pthread = struct {
  626. self uintptr
  627. dtv uintptr
  628. prev uintptr
  629. next uintptr
  630. sysinfo uintptr_t
  631. canary uintptr_t
  632. canary2 uintptr_t
  633. tid int32
  634. errno_val int32
  635. detach_state int32
  636. cancel int32
  637. canceldisable uint8
  638. cancelasync uint8
  639. tsd_used uint8 /* unsigned char tsd_used: 1, unsigned char dlerror_flag: 1 */
  640. _ [1]byte
  641. map_base uintptr
  642. map_size size_t
  643. stack uintptr
  644. stack_size size_t
  645. guard_size size_t
  646. result uintptr
  647. cancelbuf uintptr
  648. tsd uintptr
  649. robust_list struct {
  650. head uintptr
  651. off int32
  652. _ [4]byte
  653. pending uintptr
  654. }
  655. timer_id int32
  656. _ [4]byte
  657. locale locale_t
  658. killlock [1]int32
  659. _ [4]byte
  660. dlerror_buf uintptr
  661. stdio_locks uintptr
  662. canary_at_end uintptr_t
  663. _ [4]byte
  664. dtv_copy uintptr
  665. } /* alltypes.h:281:9 */
  666. type pthread_t = uintptr /* alltypes.h:281:26 */
  667. type pthread_once_t = int32 /* alltypes.h:287:13 */
  668. type pthread_key_t = uint32 /* alltypes.h:292:18 */
  669. type pthread_spinlock_t = int32 /* alltypes.h:297:13 */
  670. type pthread_mutexattr_t = struct{ __attr uint32 } /* alltypes.h:302:37 */
  671. type pthread_condattr_t = struct{ __attr uint32 } /* alltypes.h:307:37 */
  672. type pthread_barrierattr_t = struct{ __attr uint32 } /* alltypes.h:312:37 */
  673. type pthread_rwlockattr_t = struct{ __attr [2]uint32 } /* alltypes.h:317:40 */
  674. type __sigset_t = struct{ __bits [32]uint32 } /* alltypes.h:357:9 */
  675. type sigset_t = __sigset_t /* alltypes.h:357:71 */
  676. type pthread_attr_t = struct{ __u struct{ __i [9]int32 } } /* alltypes.h:380:147 */
  677. type pthread_mutex_t = struct {
  678. __u struct {
  679. _ [0]uint64
  680. __i [6]int32
  681. _ [24]byte
  682. }
  683. } /* alltypes.h:385:157 */
  684. type pthread_cond_t = struct {
  685. __u struct {
  686. _ [0]uint64
  687. __i [12]int32
  688. }
  689. } /* alltypes.h:395:112 */
  690. type pthread_rwlock_t = struct {
  691. __u struct {
  692. _ [0]uint64
  693. __i [8]int32
  694. _ [32]byte
  695. }
  696. } /* alltypes.h:405:139 */
  697. type pthread_barrier_t = struct {
  698. __u struct {
  699. _ [0]uint64
  700. __i [5]int32
  701. _ [20]byte
  702. }
  703. } /* alltypes.h:410:137 */
  704. type sched_param = struct {
  705. sched_priority int32
  706. __reserved1 int32
  707. __reserved2 [2]struct {
  708. __reserved1 time_t
  709. __reserved2 int32
  710. }
  711. __reserved3 int32
  712. } /* sched.h:19:1 */
  713. type timer_t = uintptr /* alltypes.h:217:14 */
  714. type clock_t = int32 /* alltypes.h:227:14 */
  715. type itimerspec = struct {
  716. it_interval struct {
  717. tv_sec time_t
  718. tv_nsec int32
  719. }
  720. it_value struct {
  721. tv_sec time_t
  722. tv_nsec int32
  723. }
  724. } /* time.h:80:1 */
  725. type sigevent = struct {
  726. sigev_value struct {
  727. _ [0]uint64
  728. sival_int int32
  729. _ [4]byte
  730. }
  731. sigev_signo int32
  732. sigev_notify int32
  733. sigev_notify_function uintptr
  734. sigev_notify_attributes uintptr
  735. __pad [44]int8
  736. _ [4]byte
  737. } /* time.h:107:1 */
  738. type __ptcb = struct {
  739. __f uintptr
  740. __x uintptr
  741. __next uintptr
  742. } /* alltypes.h:281:9 */
  743. type sigaltstack = struct {
  744. ss_sp uintptr
  745. ss_flags int32
  746. _ [4]byte
  747. ss_size size_t
  748. } /* signal.h:44:9 */
  749. type stack_t = sigaltstack /* signal.h:44:28 */
  750. type greg_t = uint32 /* signal.h:10:23 */
  751. type gregset_t = [34]uint32 /* signal.h:11:23 */
  752. type fpregset_t = struct {
  753. vregs [32]float64
  754. fpsr uint32
  755. fpcr uint32
  756. } /* signal.h:17:3 */
  757. type sigcontext = struct {
  758. fault_address uint32
  759. regs [31]uint32
  760. sp uint32
  761. pc uint32
  762. pstate uint32
  763. _ [4]byte
  764. __reserved [256]float64
  765. } /* signal.h:18:9 */
  766. type mcontext_t = sigcontext /* signal.h:23:3 */
  767. type _aarch64_ctx = struct {
  768. magic uint32
  769. size uint32
  770. } /* signal.h:29:1 */
  771. type fpsimd_context = struct {
  772. head struct {
  773. magic uint32
  774. size uint32
  775. }
  776. fpsr uint32
  777. fpcr uint32
  778. vregs [32]float64
  779. } /* signal.h:33:1 */
  780. type esr_context = struct {
  781. head struct {
  782. magic uint32
  783. size uint32
  784. }
  785. esr uint32
  786. } /* signal.h:39:1 */
  787. type extra_context = struct {
  788. head struct {
  789. magic uint32
  790. size uint32
  791. }
  792. datap uint32
  793. size uint32
  794. __reserved [3]uint32
  795. } /* signal.h:43:1 */
  796. type sve_context = struct {
  797. head struct {
  798. magic uint32
  799. size uint32
  800. }
  801. vl uint16
  802. __reserved [3]uint16
  803. } /* signal.h:49:1 */
  804. type __ucontext = struct {
  805. uc_flags uint32
  806. _ [4]byte
  807. uc_link uintptr
  808. uc_stack stack_t
  809. uc_sigmask sigset_t
  810. uc_mcontext mcontext_t
  811. } /* signal.h:99:9 */
  812. type ucontext_t = __ucontext /* signal.h:105:3 */
  813. type sigval = struct {
  814. _ [0]uint64
  815. sival_int int32
  816. _ [4]byte
  817. } /* time.h:107:1 */
  818. type siginfo_t = struct {
  819. si_signo int32
  820. si_errno int32
  821. si_code int32
  822. _ [4]byte
  823. __si_fields struct {
  824. _ [0]uint64
  825. __pad [116]int8
  826. _ [4]byte
  827. }
  828. } /* signal.h:145:3 */
  829. type sigaction = struct {
  830. __sa_handler struct{ sa_handler uintptr }
  831. sa_mask sigset_t
  832. sa_flags int32
  833. _ [4]byte
  834. sa_restorer uintptr
  835. } /* signal.h:167:1 */
  836. type sig_t = uintptr /* signal.h:251:14 */
  837. type sig_atomic_t = int32 /* signal.h:269:13 */
  838. type mode_t = uint32 /* alltypes.h:160:18 */
  839. type syscall_arg_t = int32 /* syscall.h:22:14 */
  840. func a_ll(tls *TLS, p uintptr) int32 { /* atomic_arch.h:2:19: */
  841. var v int32
  842. panic(`arch\aarch64\atomic_arch.h:5:2: assembler statements not supported`)
  843. return v
  844. }
  845. func a_sc(tls *TLS, p uintptr, v int32) int32 { /* atomic_arch.h:10:19: */
  846. var r int32
  847. panic(`arch\aarch64\atomic_arch.h:13:2: assembler statements not supported`)
  848. return BoolInt32(!(r != 0))
  849. }
  850. func a_barrier(tls *TLS) { /* atomic_arch.h:18:20: */
  851. panic(`arch\aarch64\atomic_arch.h:20:2: assembler statements not supported`)
  852. }
  853. func a_ll_p(tls *TLS, p uintptr) uintptr { /* atomic_arch.h:38:20: */
  854. var v uintptr
  855. panic(`arch\aarch64\atomic_arch.h:41:2: assembler statements not supported`)
  856. return v
  857. }
  858. func a_sc_p(tls *TLS, p uintptr, v uintptr) int32 { /* atomic_arch.h:46:19: */
  859. var r int32
  860. panic(`arch\aarch64\atomic_arch.h:49:2: assembler statements not supported`)
  861. return BoolInt32(!(r != 0))
  862. }
  863. func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic_arch.h:68:19: */
  864. panic(`arch\aarch64\atomic_arch.h:70:2: assembler statements not supported`)
  865. return int32(x)
  866. }
  867. func a_fetch_add(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:46:19: */
  868. var old int32
  869. for __ccgo := true; __ccgo; __ccgo = !(a_sc(tls, p, int32(uint32(old)+uint32(v))) != 0) {
  870. old = a_ll(tls, p)
  871. }
  872. return old
  873. }
  874. func a_fetch_and(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:59:19: */
  875. var old int32
  876. for __ccgo := true; __ccgo; __ccgo = !(a_sc(tls, p, old&v) != 0) {
  877. old = a_ll(tls, p)
  878. }
  879. return old
  880. }
  881. func a_fetch_or(tls *TLS, p uintptr, v int32) int32 { /* atomic.h:72:19: */
  882. var old int32
  883. for __ccgo := true; __ccgo; __ccgo = !(a_sc(tls, p, old|v) != 0) {
  884. old = a_ll(tls, p)
  885. }
  886. return old
  887. }
  888. func a_and(tls *TLS, p uintptr, v int32) { /* atomic.h:151:20: */
  889. a_fetch_and(tls, p, v)
  890. }
  891. func a_or(tls *TLS, p uintptr, v int32) { /* atomic.h:159:20: */
  892. a_fetch_or(tls, p, v)
  893. }
  894. func a_or_64(tls *TLS, p uintptr, v uint64_t) { /* atomic.h:220:20: */
  895. bp := tls.Alloc(8)
  896. defer tls.Free(8)
  897. *(*struct {
  898. v uint64_t
  899. _ [4]byte
  900. })(unsafe.Pointer(bp)) = func() (r struct {
  901. v uint64_t
  902. _ [4]byte
  903. }) {
  904. *(*uint64_t)(unsafe.Pointer(uintptr(unsafe.Pointer(&r)) + 0)) = v
  905. return r
  906. }()
  907. if *(*uint32_t)(unsafe.Pointer(bp)) != 0 {
  908. a_or(tls, p, int32(*(*uint32_t)(unsafe.Pointer(bp))))
  909. }
  910. if *(*uint32_t)(unsafe.Pointer(bp + 1*4)) != 0 {
  911. a_or(tls, p+uintptr(1)*4, int32(*(*uint32_t)(unsafe.Pointer(bp + 1*4))))
  912. }
  913. }
  914. func a_ctz_32(tls *TLS, x uint32_t) int32 { /* atomic.h:256:19: */
  915. return int32(_sdebruijn32[x&-x*uint32_t(0x076be629)>>27])
  916. }
  917. var _sdebruijn32 = [32]int8{
  918. int8(0), int8(1), int8(23), int8(2), int8(29), int8(24), int8(19), int8(3), int8(30), int8(27), int8(25), int8(11), int8(20), int8(8), int8(4), int8(13),
  919. int8(31), int8(22), int8(28), int8(18), int8(26), int8(10), int8(7), int8(12), int8(21), int8(17), int8(9), int8(6), int8(16), int8(5), int8(15), int8(14),
  920. } /* atomic.h:261:20 */
  921. type __timer = struct {
  922. timerid int32
  923. _ [4]byte
  924. thread pthread_t
  925. } /* pthread_impl.h:64:1 */
  926. func __pthread_self(tls *TLS) uintptr { /* pthread_arch.h:1:30: */
  927. var self uintptr
  928. panic(`arch\aarch64\pthread_arch.h:4:2: assembler statements not supported`)
  929. return self - uintptr(uint64(unsafe.Sizeof(__pthread{})))
  930. }
  931. func Xwcrtomb(tls *TLS, s uintptr, wc wchar_t, st uintptr) size_t { /* wcrtomb.c:6:8: */
  932. if __ccgo_strace {
  933. trc("tls=%v s=%v wc=%v st=%v, (%v:)", tls, s, wc, st, origin(2))
  934. }
  935. if !(s != 0) {
  936. return uint64(1)
  937. }
  938. if uint32(wc) < uint32(0x80) {
  939. *(*int8)(unsafe.Pointer(s)) = int8(wc)
  940. return uint64(1)
  941. } else if func() int32 {
  942. if !!(int32(*(*uintptr)(unsafe.Pointer((*__pthread)(unsafe.Pointer(__pthread_self(tls))).locale))) != 0) {
  943. return 4
  944. }
  945. return 1
  946. }() == 1 {
  947. if !(uint32(wc)-uint32(0xdf80) < uint32(0x80)) {
  948. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 84
  949. return Uint64FromInt32(-1)
  950. }
  951. *(*int8)(unsafe.Pointer(s)) = int8(wc)
  952. return uint64(1)
  953. } else if uint32(wc) < uint32(0x800) {
  954. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xc0 | int32(wc)>>6)
  955. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  956. return uint64(2)
  957. } else if uint32(wc) < uint32(0xd800) || uint32(wc)-uint32(0xe000) < uint32(0x2000) {
  958. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xe0 | int32(wc)>>12)
  959. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>6&0x3f)
  960. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  961. return uint64(3)
  962. } else if uint32(wc)-uint32(0x10000) < uint32(0x100000) {
  963. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xf0 | int32(wc)>>18)
  964. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>12&0x3f)
  965. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>6&0x3f)
  966. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  967. return uint64(4)
  968. }
  969. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 84
  970. return Uint64FromInt32(-1)
  971. }
  972. func Xwcsrtombs(tls *TLS, s uintptr, ws uintptr, n size_t, st uintptr) size_t { /* wcsrtombs.c:3:8: */
  973. if __ccgo_strace {
  974. trc("tls=%v s=%v ws=%v n=%v st=%v, (%v:)", tls, s, ws, n, st, origin(2))
  975. }
  976. bp := tls.Alloc(4)
  977. defer tls.Free(4)
  978. var ws2 uintptr
  979. // var buf [4]int8 at bp, 4
  980. var N size_t = n
  981. var l size_t
  982. if !(s != 0) {
  983. n = uint64(0)
  984. ws2 = *(*uintptr)(unsafe.Pointer(ws))
  985. for ; *(*wchar_t)(unsafe.Pointer(ws2)) != 0; ws2 += 2 {
  986. if uint32(*(*wchar_t)(unsafe.Pointer(ws2))) >= 0x80 {
  987. l = Xwcrtomb(tls, bp, *(*wchar_t)(unsafe.Pointer(ws2)), uintptr(0))
  988. if !(l+uint64(1) != 0) {
  989. return Uint64FromInt32(-1)
  990. }
  991. n = n + l
  992. } else {
  993. n++
  994. }
  995. }
  996. return n
  997. }
  998. for n >= uint64(4) {
  999. if uint32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))-1 >= 0x7f {
  1000. if !(int32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws))))) != 0) {
  1001. *(*int8)(unsafe.Pointer(s)) = int8(0)
  1002. *(*uintptr)(unsafe.Pointer(ws)) = uintptr(0)
  1003. return N - n
  1004. }
  1005. l = Xwcrtomb(tls, s, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  1006. if !(l+uint64(1) != 0) {
  1007. return Uint64FromInt32(-1)
  1008. }
  1009. s += uintptr(l)
  1010. n = n - l
  1011. } else {
  1012. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))
  1013. n--
  1014. }
  1015. *(*uintptr)(unsafe.Pointer(ws)) += 2
  1016. }
  1017. for n != 0 {
  1018. if uint32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))-1 >= 0x7f {
  1019. if !(int32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws))))) != 0) {
  1020. *(*int8)(unsafe.Pointer(s)) = int8(0)
  1021. *(*uintptr)(unsafe.Pointer(ws)) = uintptr(0)
  1022. return N - n
  1023. }
  1024. l = Xwcrtomb(tls, bp, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  1025. if !(l+uint64(1) != 0) {
  1026. return Uint64FromInt32(-1)
  1027. }
  1028. if l > n {
  1029. return N - n
  1030. }
  1031. Xwcrtomb(tls, s, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  1032. s += uintptr(l)
  1033. n = n - l
  1034. } else {
  1035. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))
  1036. n--
  1037. }
  1038. *(*uintptr)(unsafe.Pointer(ws)) += 2
  1039. }
  1040. return N
  1041. }
  1042. func Xwcstombs(tls *TLS, s uintptr, ws uintptr, n size_t) size_t { /* wcstombs.c:4:8: */
  1043. if __ccgo_strace {
  1044. trc("tls=%v s=%v ws=%v n=%v, (%v:)", tls, s, ws, n, origin(2))
  1045. }
  1046. bp := tls.Alloc(8)
  1047. defer tls.Free(8)
  1048. *(*uintptr)(unsafe.Pointer(bp)) = ws
  1049. //TODO return wcsrtombs(s, &(const wchar_t *){ws}, n, 0);
  1050. return Xwcsrtombs(tls, s, bp, n, uintptr(0))
  1051. }
  1052. func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
  1053. if __ccgo_strace {
  1054. trc("tls=%v key=%v base=%v nel=%v width=%v cmp=%v, (%v:)", tls, key, base, nel, width, cmp, origin(2))
  1055. }
  1056. var try uintptr
  1057. var sign int32
  1058. for nel > uint64(0) {
  1059. try = base + uintptr(width*(nel/uint64(2)))
  1060. sign = (*struct {
  1061. f func(*TLS, uintptr, uintptr) int32
  1062. })(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
  1063. if sign < 0 {
  1064. nel = nel / uint64(2)
  1065. } else if sign > 0 {
  1066. base = try + uintptr(width)
  1067. nel = nel - (nel/uint64(2) + uint64(1))
  1068. } else {
  1069. return try
  1070. }
  1071. }
  1072. return uintptr(0)
  1073. }
  1074. // Support signed or unsigned plain-char
  1075. // Implementation choices...
  1076. // Arbitrary numbers...
  1077. // POSIX/SUS requirements follow. These numbers come directly
  1078. // from SUS and have nothing to do with the host system.
  1079. func X__strchrnul(tls *TLS, s uintptr, c int32) uintptr { /* strchrnul.c:10:6: */
  1080. if __ccgo_strace {
  1081. trc("tls=%v s=%v c=%v, (%v:)", tls, s, c, origin(2))
  1082. }
  1083. c = int32(uint8(c))
  1084. if !(c != 0) {
  1085. return s + uintptr(Xstrlen(tls, s))
  1086. }
  1087. var w uintptr
  1088. for ; uint64(s)%uint64(unsafe.Sizeof(size_t(0))) != 0; s++ {
  1089. if !(int32(*(*int8)(unsafe.Pointer(s))) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c {
  1090. return s
  1091. }
  1092. }
  1093. var k size_t = Uint64(Uint64FromInt32(-1)) / uint64(255) * size_t(c)
  1094. for w = s; !((*(*uint64)(unsafe.Pointer(w))-Uint64(Uint64FromInt32(-1))/uint64(255)) & ^*(*uint64)(unsafe.Pointer(w)) & (Uint64(Uint64FromInt32(-1))/uint64(255)*uint64(255/2+1)) != 0) && !((*(*uint64)(unsafe.Pointer(w))^k-Uint64(Uint64FromInt32(-1))/uint64(255)) & ^(*(*uint64)(unsafe.Pointer(w))^k) & (Uint64(Uint64FromInt32(-1))/uint64(255)*uint64(255/2+1)) != 0); w += 8 {
  1095. }
  1096. s = w
  1097. for ; *(*int8)(unsafe.Pointer(s)) != 0 && int32(*(*uint8)(unsafe.Pointer(s))) != c; s++ {
  1098. }
  1099. return s
  1100. }
  1101. func Xstrdup(tls *TLS, s uintptr) uintptr { /* strdup.c:4:6: */
  1102. if __ccgo_strace {
  1103. trc("tls=%v s=%v, (%v:)", tls, s, origin(2))
  1104. }
  1105. var l size_t = Xstrlen(tls, s)
  1106. var d uintptr = Xmalloc(tls, l+uint64(1))
  1107. if !(d != 0) {
  1108. return uintptr(0)
  1109. }
  1110. return Xmemcpy(tls, d, s, l+uint64(1))
  1111. }