musl_windows_amd64.go 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189
  1. // Code generated by 'ccgo -D__environ=environ -export-externs X -hide __syscall0,__syscall1,__syscall2,__syscall3,__syscall4,__syscall5,__syscall6 -nostdinc -nostdlib -o ../musl_windows_amd64.go -pkgname libc -static-locals-prefix _s -Iarch\x86_64 -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:343:9 */
  219. type locale_t = uintptr /* alltypes.h:343: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:65:15 */
  326. type intptr_t = int32 /* alltypes.h:70:15 */
  327. type off_t = int32 /* alltypes.h:162:16 */
  328. type pid_t = int32 /* alltypes.h:235:13 */
  329. type uid_t = uint32 /* alltypes.h:245:18 */
  330. type gid_t = uint32 /* alltypes.h:250:18 */
  331. type useconds_t = uint32 /* alltypes.h:260: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:198:18 */
  503. type wctype_t = uint32 /* alltypes.h:203:23 */
  504. type __mbstate_t = struct {
  505. __opaque1 uint32
  506. __opaque2 uint32
  507. } /* alltypes.h:337:9 */
  508. type mbstate_t = __mbstate_t /* alltypes.h:337: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:55:24 */
  523. type int8_t = int8 /* alltypes.h:96:25 */
  524. type int16_t = int16 /* alltypes.h:101:25 */
  525. type int32_t = int32 /* alltypes.h:106:25 */
  526. type int64_t = int32 /* alltypes.h:111:25 */
  527. type intmax_t = int32 /* alltypes.h:116:25 */
  528. type uint8_t = uint8 /* alltypes.h:121:25 */
  529. type uint16_t = uint16 /* alltypes.h:126:25 */
  530. type uint32_t = uint32 /* alltypes.h:131:25 */
  531. type uint64_t = uint32 /* alltypes.h:136:25 */
  532. type uintmax_t = uint32 /* alltypes.h:146: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:343: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:85:16 */
  620. type clockid_t = int32 /* alltypes.h:214:13 */
  621. type timespec = struct {
  622. tv_sec time_t
  623. tv_nsec int32
  624. } /* alltypes.h:229: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:273:9 */
  666. type pthread_t = uintptr /* alltypes.h:273:26 */
  667. type pthread_once_t = int32 /* alltypes.h:279:13 */
  668. type pthread_key_t = uint32 /* alltypes.h:284:18 */
  669. type pthread_spinlock_t = int32 /* alltypes.h:289:13 */
  670. type pthread_mutexattr_t = struct{ __attr uint32 } /* alltypes.h:294:37 */
  671. type pthread_condattr_t = struct{ __attr uint32 } /* alltypes.h:299:37 */
  672. type pthread_barrierattr_t = struct{ __attr uint32 } /* alltypes.h:304:37 */
  673. type pthread_rwlockattr_t = struct{ __attr [2]uint32 } /* alltypes.h:309:40 */
  674. type __sigset_t = struct{ __bits [32]uint32 } /* alltypes.h:349:9 */
  675. type sigset_t = __sigset_t /* alltypes.h:349:71 */
  676. type pthread_attr_t = struct{ __u struct{ __i [9]int32 } } /* alltypes.h:372:147 */
  677. type pthread_mutex_t = struct {
  678. __u struct {
  679. _ [0]uint64
  680. __i [6]int32
  681. _ [24]byte
  682. }
  683. } /* alltypes.h:377:157 */
  684. type pthread_cond_t = struct {
  685. __u struct {
  686. _ [0]uint64
  687. __i [12]int32
  688. }
  689. } /* alltypes.h:387:112 */
  690. type pthread_rwlock_t = struct {
  691. __u struct {
  692. _ [0]uint64
  693. __i [8]int32
  694. _ [32]byte
  695. }
  696. } /* alltypes.h:397:139 */
  697. type pthread_barrier_t = struct {
  698. __u struct {
  699. _ [0]uint64
  700. __i [5]int32
  701. _ [20]byte
  702. }
  703. } /* alltypes.h:402: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:209:14 */
  714. type clock_t = int32 /* alltypes.h:219: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:273: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 = int64 /* signal.h:59:19 */
  751. type gregset_t = [23]int64 /* signal.h:59:27 */
  752. type _fpstate = struct {
  753. cwd uint16
  754. swd uint16
  755. ftw uint16
  756. fop uint16
  757. rip uint64
  758. rdp uint64
  759. mxcsr uint32
  760. mxcr_mask uint32
  761. _st [8]struct {
  762. significand [4]uint16
  763. exponent uint16
  764. padding [3]uint16
  765. }
  766. _xmm [16]struct{ element [4]uint32 }
  767. padding [24]uint32
  768. } /* signal.h:60:9 */
  769. type fpregset_t = uintptr /* signal.h:71:3 */
  770. type sigcontext = struct {
  771. r8 uint32
  772. r9 uint32
  773. r10 uint32
  774. r11 uint32
  775. r12 uint32
  776. r13 uint32
  777. r14 uint32
  778. r15 uint32
  779. rdi uint32
  780. rsi uint32
  781. rbp uint32
  782. rbx uint32
  783. rdx uint32
  784. rax uint32
  785. rcx uint32
  786. rsp uint32
  787. rip uint32
  788. eflags uint32
  789. cs uint16
  790. gs uint16
  791. fs uint16
  792. __pad0 uint16
  793. err uint32
  794. trapno uint32
  795. oldmask uint32
  796. cr2 uint32
  797. fpstate uintptr
  798. __reserved1 [8]uint32
  799. } /* signal.h:72:1 */
  800. type mcontext_t = struct {
  801. gregs gregset_t
  802. fpregs fpregset_t
  803. __reserved1 [8]uint64
  804. } /* signal.h:84:3 */
  805. type __ucontext = struct {
  806. uc_flags uint32
  807. _ [4]byte
  808. uc_link uintptr
  809. uc_stack stack_t
  810. uc_mcontext mcontext_t
  811. uc_sigmask sigset_t
  812. __fpregs_mem [64]uint32
  813. } /* signal.h:97:9 */
  814. type ucontext_t = __ucontext /* signal.h:104:3 */
  815. type sigval = struct {
  816. _ [0]uint64
  817. sival_int int32
  818. _ [4]byte
  819. } /* time.h:107:1 */
  820. type siginfo_t = struct {
  821. si_signo int32
  822. si_errno int32
  823. si_code int32
  824. _ [4]byte
  825. __si_fields struct {
  826. _ [0]uint64
  827. __pad [116]int8
  828. _ [4]byte
  829. }
  830. } /* signal.h:145:3 */
  831. type sigaction = struct {
  832. __sa_handler struct{ sa_handler uintptr }
  833. sa_mask sigset_t
  834. sa_flags int32
  835. _ [4]byte
  836. sa_restorer uintptr
  837. } /* signal.h:167:1 */
  838. type sig_t = uintptr /* signal.h:251:14 */
  839. type sig_atomic_t = int32 /* signal.h:269:13 */
  840. type mode_t = uint32 /* alltypes.h:152:18 */
  841. type syscall_arg_t = int32 /* syscall.h:22:14 */
  842. func a_cas(tls *TLS, p uintptr, t int32, s int32) int32 { /* atomic_arch.h:2:19: */
  843. panic(`arch\x86_64\atomic_arch.h:4:2: assembler statements not supported`)
  844. return t
  845. }
  846. func a_or(tls *TLS, p uintptr, v int32) { /* atomic_arch.h:46:20: */
  847. panic(`arch\x86_64\atomic_arch.h:48:2: assembler statements not supported`)
  848. }
  849. func a_or_64(tls *TLS, p uintptr, v uint64_t) { /* atomic_arch.h:62:20: */
  850. panic(`arch\x86_64\atomic_arch.h:64:2: assembler statements not supported`)
  851. }
  852. func a_ctz_64(tls *TLS, x uint64_t) int32 { /* atomic_arch.h:112:19: */
  853. panic(`arch\x86_64\atomic_arch.h:114:2: assembler statements not supported`)
  854. return int32(x)
  855. }
  856. func a_ctz_32(tls *TLS, x uint32_t) int32 { /* atomic.h:256:19: */
  857. return int32(_sdebruijn32[x&-x*uint32_t(0x076be629)>>27])
  858. }
  859. var _sdebruijn32 = [32]int8{
  860. 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),
  861. 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),
  862. } /* atomic.h:261:20 */
  863. type __timer = struct {
  864. timerid int32
  865. _ [4]byte
  866. thread pthread_t
  867. } /* pthread_impl.h:64:1 */
  868. func __pthread_self(tls *TLS) uintptr { /* pthread_arch.h:1:30: */
  869. var self uintptr
  870. panic(`arch\x86_64\pthread_arch.h:4:2: assembler statements not supported`)
  871. return self
  872. }
  873. func Xwcrtomb(tls *TLS, s uintptr, wc wchar_t, st uintptr) size_t { /* wcrtomb.c:6:8: */
  874. if __ccgo_strace {
  875. trc("tls=%v s=%v wc=%v st=%v, (%v:)", tls, s, wc, st, origin(2))
  876. }
  877. if !(s != 0) {
  878. return uint64(1)
  879. }
  880. if uint32(wc) < uint32(0x80) {
  881. *(*int8)(unsafe.Pointer(s)) = int8(wc)
  882. return uint64(1)
  883. } else if func() int32 {
  884. if !!(int32(*(*uintptr)(unsafe.Pointer((*__pthread)(unsafe.Pointer(__pthread_self(tls))).locale))) != 0) {
  885. return 4
  886. }
  887. return 1
  888. }() == 1 {
  889. if !(uint32(wc)-uint32(0xdf80) < uint32(0x80)) {
  890. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 84
  891. return Uint64FromInt32(-1)
  892. }
  893. *(*int8)(unsafe.Pointer(s)) = int8(wc)
  894. return uint64(1)
  895. } else if uint32(wc) < uint32(0x800) {
  896. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xc0 | int32(wc)>>6)
  897. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  898. return uint64(2)
  899. } else if uint32(wc) < uint32(0xd800) || uint32(wc)-uint32(0xe000) < uint32(0x2000) {
  900. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xe0 | int32(wc)>>12)
  901. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>6&0x3f)
  902. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  903. return uint64(3)
  904. } else if uint32(wc)-uint32(0x10000) < uint32(0x100000) {
  905. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0xf0 | int32(wc)>>18)
  906. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>12&0x3f)
  907. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(0x80 | int32(wc)>>6&0x3f)
  908. *(*int8)(unsafe.Pointer(s)) = int8(0x80 | int32(wc)&0x3f)
  909. return uint64(4)
  910. }
  911. *(*int32)(unsafe.Pointer(X___errno_location(tls))) = 84
  912. return Uint64FromInt32(-1)
  913. }
  914. func Xwcsrtombs(tls *TLS, s uintptr, ws uintptr, n size_t, st uintptr) size_t { /* wcsrtombs.c:3:8: */
  915. if __ccgo_strace {
  916. trc("tls=%v s=%v ws=%v n=%v st=%v, (%v:)", tls, s, ws, n, st, origin(2))
  917. }
  918. bp := tls.Alloc(4)
  919. defer tls.Free(4)
  920. var ws2 uintptr
  921. // var buf [4]int8 at bp, 4
  922. var N size_t = n
  923. var l size_t
  924. if !(s != 0) {
  925. n = uint64(0)
  926. ws2 = *(*uintptr)(unsafe.Pointer(ws))
  927. for ; *(*wchar_t)(unsafe.Pointer(ws2)) != 0; ws2 += 2 {
  928. if uint32(*(*wchar_t)(unsafe.Pointer(ws2))) >= 0x80 {
  929. l = Xwcrtomb(tls, bp, *(*wchar_t)(unsafe.Pointer(ws2)), uintptr(0))
  930. if !(l+uint64(1) != 0) {
  931. return Uint64FromInt32(-1)
  932. }
  933. n = n + l
  934. } else {
  935. n++
  936. }
  937. }
  938. return n
  939. }
  940. for n >= uint64(4) {
  941. if uint32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))-1 >= 0x7f {
  942. if !(int32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws))))) != 0) {
  943. *(*int8)(unsafe.Pointer(s)) = int8(0)
  944. *(*uintptr)(unsafe.Pointer(ws)) = uintptr(0)
  945. return N - n
  946. }
  947. l = Xwcrtomb(tls, s, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  948. if !(l+uint64(1) != 0) {
  949. return Uint64FromInt32(-1)
  950. }
  951. s += uintptr(l)
  952. n = n - l
  953. } else {
  954. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))
  955. n--
  956. }
  957. *(*uintptr)(unsafe.Pointer(ws)) += 2
  958. }
  959. for n != 0 {
  960. if uint32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))-1 >= 0x7f {
  961. if !(int32(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws))))) != 0) {
  962. *(*int8)(unsafe.Pointer(s)) = int8(0)
  963. *(*uintptr)(unsafe.Pointer(ws)) = uintptr(0)
  964. return N - n
  965. }
  966. l = Xwcrtomb(tls, bp, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  967. if !(l+uint64(1) != 0) {
  968. return Uint64FromInt32(-1)
  969. }
  970. if l > n {
  971. return N - n
  972. }
  973. Xwcrtomb(tls, s, *(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))), uintptr(0))
  974. s += uintptr(l)
  975. n = n - l
  976. } else {
  977. *(*int8)(unsafe.Pointer(PostIncUintptr(&s, 1))) = int8(*(*wchar_t)(unsafe.Pointer(*(*uintptr)(unsafe.Pointer(ws)))))
  978. n--
  979. }
  980. *(*uintptr)(unsafe.Pointer(ws)) += 2
  981. }
  982. return N
  983. }
  984. func Xwcstombs(tls *TLS, s uintptr, ws uintptr, n size_t) size_t { /* wcstombs.c:4:8: */
  985. if __ccgo_strace {
  986. trc("tls=%v s=%v ws=%v n=%v, (%v:)", tls, s, ws, n, origin(2))
  987. }
  988. bp := tls.Alloc(8)
  989. defer tls.Free(8)
  990. *(*uintptr)(unsafe.Pointer(bp)) = ws
  991. //TODO return wcsrtombs(s, &(const wchar_t *){ws}, n, 0);
  992. return Xwcsrtombs(tls, s, bp, n, uintptr(0))
  993. }
  994. func Xbsearch(tls *TLS, key uintptr, base uintptr, nel size_t, width size_t, cmp uintptr) uintptr { /* bsearch.c:3:6: */
  995. if __ccgo_strace {
  996. trc("tls=%v key=%v base=%v nel=%v width=%v cmp=%v, (%v:)", tls, key, base, nel, width, cmp, origin(2))
  997. }
  998. var try uintptr
  999. var sign int32
  1000. for nel > uint64(0) {
  1001. try = base + uintptr(width*(nel/uint64(2)))
  1002. sign = (*struct {
  1003. f func(*TLS, uintptr, uintptr) int32
  1004. })(unsafe.Pointer(&struct{ uintptr }{cmp})).f(tls, key, try)
  1005. if sign < 0 {
  1006. nel = nel / uint64(2)
  1007. } else if sign > 0 {
  1008. base = try + uintptr(width)
  1009. nel = nel - (nel/uint64(2) + uint64(1))
  1010. } else {
  1011. return try
  1012. }
  1013. }
  1014. return uintptr(0)
  1015. }
  1016. // Support signed or unsigned plain-char
  1017. // Implementation choices...
  1018. // Arbitrary numbers...
  1019. // POSIX/SUS requirements follow. These numbers come directly
  1020. // from SUS and have nothing to do with the host system.
  1021. func X__strchrnul(tls *TLS, s uintptr, c int32) uintptr { /* strchrnul.c:10:6: */
  1022. if __ccgo_strace {
  1023. trc("tls=%v s=%v c=%v, (%v:)", tls, s, c, origin(2))
  1024. }
  1025. c = int32(uint8(c))
  1026. if !(c != 0) {
  1027. return s + uintptr(Xstrlen(tls, s))
  1028. }
  1029. var w uintptr
  1030. for ; uint64(s)%uint64(unsafe.Sizeof(size_t(0))) != 0; s++ {
  1031. if !(int32(*(*int8)(unsafe.Pointer(s))) != 0) || int32(*(*uint8)(unsafe.Pointer(s))) == c {
  1032. return s
  1033. }
  1034. }
  1035. var k size_t = Uint64(Uint64FromInt32(-1)) / uint64(255) * size_t(c)
  1036. 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 {
  1037. }
  1038. s = w
  1039. for ; *(*int8)(unsafe.Pointer(s)) != 0 && int32(*(*uint8)(unsafe.Pointer(s))) != c; s++ {
  1040. }
  1041. return s
  1042. }
  1043. func Xstrdup(tls *TLS, s uintptr) uintptr { /* strdup.c:4:6: */
  1044. if __ccgo_strace {
  1045. trc("tls=%v s=%v, (%v:)", tls, s, origin(2))
  1046. }
  1047. var l size_t = Xstrlen(tls, s)
  1048. var d uintptr = Xmalloc(tls, l+uint64(1))
  1049. if !(d != 0) {
  1050. return uintptr(0)
  1051. }
  1052. return Xmemcpy(tls, d, s, l+uint64(1))
  1053. }