gtsocial-umbx

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

musl_windows_386.go (30972B)


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