| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857 |
- // Copyright 2020 The Libc Authors. All rights reserved.
- // Use of this source code is governed by a BSD-style
- // license that can be found in the LICENSE file.
- package libc // import "modernc.org/libc"
- import (
- "errors"
- "fmt"
- "golang.org/x/sys/windows"
- "math"
- mbits "math/bits"
- "os"
- "os/exec"
- "os/user"
- "path/filepath"
- "runtime/debug"
- "strings"
- "sync"
- "sync/atomic"
- gotime "time"
- "unicode"
- "unicode/utf16"
- "unsafe"
- "github.com/ncruces/go-strftime"
- "modernc.org/libc/errno"
- "modernc.org/libc/fcntl"
- "modernc.org/libc/limits"
- "modernc.org/libc/stdio"
- "modernc.org/libc/sys/stat"
- "modernc.org/libc/sys/types"
- "modernc.org/libc/time"
- "modernc.org/libc/unistd"
- )
- // Keep these outside of the var block otherwise go generate will miss them.
- var X__imp__environ = EnvironP()
- var X__imp__wenviron = uintptr(unsafe.Pointer(&wenviron))
- var X_imp___environ = EnvironP()
- var X_imp___wenviron = uintptr(unsafe.Pointer(&wenviron))
- var X_iob [stdio.X_IOB_ENTRIES]stdio.FILE
- var Xin6addr_any [16]byte
- var Xtimezone long // extern long timezone;
- type Tsize_t = types.Size_t
- var (
- iobMap = map[uintptr]int32{} // &_iob[fd] -> fd
- wenvValid bool
- wenviron uintptr // &winEnviron[0]
- winEnviron = []uintptr{0}
- )
- func init() {
- for i := range X_iob {
- iobMap[uintptr(unsafe.Pointer(&X_iob[i]))] = int32(i)
- }
- }
- func X__p__wenviron(t *TLS) uintptr {
- if !wenvValid {
- bootWinEnviron(t)
- }
- return uintptr(unsafe.Pointer(&wenviron))
- }
- func winGetObject(stream uintptr) interface{} {
- if fd, ok := iobMap[stream]; ok {
- f, _ := fdToFile(fd)
- return f
- }
- return getObject(stream)
- }
- type (
- syscallErrno = windows.Errno
- long = int32
- ulong = uint32
- )
- var (
- modkernel32 = windows.NewLazySystemDLL("kernel32.dll")
- //--
- procAreFileApisANSI = modkernel32.NewProc("AreFileApisANSI")
- procCopyFileW = modkernel32.NewProc("CopyFileW")
- procCreateEventA = modkernel32.NewProc("CreateEventA")
- procCreateEventW = modkernel32.NewProc("CreateEventW")
- procCreateFileA = modkernel32.NewProc("CreateFileA")
- procCreateFileMappingW = modkernel32.NewProc("CreateFileMappingW")
- procCreateFileW = modkernel32.NewProc("CreateFileW")
- procCreateHardLinkW = modkernel32.NewProc("CreateHardLinkW")
- procCreatePipe = modkernel32.NewProc("CreatePipe")
- procCreateProcessA = modkernel32.NewProc("CreateProcessA")
- procCreateProcessW = modkernel32.NewProc("CreateProcessW")
- procCreateThread = modkernel32.NewProc("CreateThread")
- procDeleteCriticalSection = modkernel32.NewProc("DeleteCriticalSection")
- procDeviceIoControl = modkernel32.NewProc("DeviceIoControl")
- procDuplicateHandle = modkernel32.NewProc("DuplicateHandle")
- procEnterCriticalSection = modkernel32.NewProc("EnterCriticalSection")
- procFindClose = modkernel32.NewProc("FindClose")
- procFindFirstFileExW = modkernel32.NewProc("FindFirstFileExW")
- procFindFirstFileW = modkernel32.NewProc("FindFirstFileW")
- procFindNextFileW = modkernel32.NewProc("FindNextFileW")
- procFormatMessageW = modkernel32.NewProc("FormatMessageW")
- procGetACP = modkernel32.NewProc("GetACP")
- procGetCommState = modkernel32.NewProc("GetCommState")
- procGetComputerNameExW = modkernel32.NewProc("GetComputerNameExW")
- procGetConsoleCP = modkernel32.NewProc("GetConsoleCP")
- procGetConsoleScreenBufferInfo = modkernel32.NewProc("GetConsoleScreenBufferInfo")
- procGetCurrentProcess = modkernel32.NewProc("GetCurrentProcess")
- procGetCurrentProcessId = modkernel32.NewProc("GetCurrentProcessId")
- procGetCurrentThread = modkernel32.NewProc("GetCurrentThread")
- procGetCurrentThreadId = modkernel32.NewProc("GetCurrentThreadId")
- procGetEnvironmentVariableA = modkernel32.NewProc("GetEnvironmentVariableA")
- procGetEnvironmentVariableW = modkernel32.NewProc("GetEnvironmentVariableW")
- procGetExitCodeProcess = modkernel32.NewProc("GetExitCodeProcess")
- procGetExitCodeThread = modkernel32.NewProc("GetExitCodeThread")
- procGetFileAttributesA = modkernel32.NewProc("GetFileAttributesA")
- procGetFileAttributesExA = modkernel32.NewProc("GetFileAttributesExA")
- procGetFileAttributesExW = modkernel32.NewProc("GetFileAttributesExW")
- procGetFileInformationByHandle = modkernel32.NewProc("GetFileInformationByHandle")
- procGetFileSize = modkernel32.NewProc("GetFileSize")
- procGetFullPathNameW = modkernel32.NewProc("GetFullPathNameW")
- procGetLastError = modkernel32.NewProc("GetLastError")
- procGetLogicalDriveStringsA = modkernel32.NewProc("GetLogicalDriveStringsA")
- procGetModuleFileNameW = modkernel32.NewProc("GetModuleFileNameW")
- procGetModuleHandleA = modkernel32.NewProc("GetModuleHandleA")
- procGetModuleHandleW = modkernel32.NewProc("GetModuleHandleW")
- procGetPrivateProfileStringA = modkernel32.NewProc("GetPrivateProfileStringA")
- procGetProcAddress = modkernel32.NewProc("GetProcAddress")
- procGetProcessHeap = modkernel32.NewProc("GetProcessHeap")
- procGetSystemInfo = modkernel32.NewProc("GetSystemInfo")
- procGetSystemTime = modkernel32.NewProc("GetSystemTime")
- procGetSystemTimeAsFileTime = modkernel32.NewProc("GetSystemTimeAsFileTime")
- procGetTempFileNameW = modkernel32.NewProc("GetTempFileNameW")
- procGetTickCount = modkernel32.NewProc("GetTickCount")
- procGetVersionExA = modkernel32.NewProc("GetVersionExA")
- procGetVersionExW = modkernel32.NewProc("GetVersionExW")
- procGetVolumeInformationA = modkernel32.NewProc("GetVolumeInformationA")
- procGetVolumeInformationW = modkernel32.NewProc("GetVolumeInformationW")
- procHeapAlloc = modkernel32.NewProc("HeapAlloc")
- procHeapFree = modkernel32.NewProc("HeapFree")
- procInitializeCriticalSection = modkernel32.NewProc("InitializeCriticalSection")
- procLeaveCriticalSection = modkernel32.NewProc("LeaveCriticalSection")
- procLockFile = modkernel32.NewProc("LockFile")
- procLockFileEx = modkernel32.NewProc("LockFileEx")
- procLstrlenW = modkernel32.NewProc("lstrlenW")
- procMapViewOfFile = modkernel32.NewProc("MapViewOfFile")
- procMoveFileW = modkernel32.NewProc("MoveFileW")
- procMultiByteToWideChar = modkernel32.NewProc("MultiByteToWideChar")
- procOpenEventA = modkernel32.NewProc("OpenEventA")
- procOpenProcessToken = modkernel32.NewProc("OpenProcessToken")
- procPeekConsoleInputW = modkernel32.NewProc("PeekConsoleInputW")
- procPeekNamedPipe = modkernel32.NewProc("PeekNamedPipe")
- procQueryPerformanceCounter = modkernel32.NewProc("QueryPerformanceCounter")
- procQueryPerformanceFrequency = modkernel32.NewProc("QueryPerformanceFrequency")
- procReadConsoleW = modkernel32.NewProc("ReadConsoleW")
- procReadFile = modkernel32.NewProc("ReadFile")
- procResetEvent = modkernel32.NewProc("ResetEvent")
- procSearchPathW = modkernel32.NewProc("SearchPathW")
- procSetConsoleCtrlHandler = modkernel32.NewProc("SetConsoleCtrlHandler")
- procSetConsoleMode = modkernel32.NewProc("SetConsoleMode")
- procSetConsoleTextAttribute = modkernel32.NewProc("SetConsoleTextAttribute")
- procSetEvent = modkernel32.NewProc("SetEvent")
- procSetFilePointer = modkernel32.NewProc("SetFilePointer")
- procSetFileTime = modkernel32.NewProc("SetFileTime")
- procSleepEx = modkernel32.NewProc("SleepEx")
- procSystemTimeToFileTime = modkernel32.NewProc("SystemTimeToFileTime")
- procTerminateThread = modkernel32.NewProc("TerminateThread")
- procTryEnterCriticalSection = modkernel32.NewProc("TryEnterCriticalSection")
- procUnlockFile = modkernel32.NewProc("UnlockFile")
- procUnlockFileEx = modkernel32.NewProc("UnlockFileEx")
- procWaitForSingleObjectEx = modkernel32.NewProc("WaitForSingleObjectEx")
- procWideCharToMultiByte = modkernel32.NewProc("WideCharToMultiByte")
- procWriteConsoleA = modkernel32.NewProc("WriteConsoleA")
- procWriteConsoleW = modkernel32.NewProc("WriteConsoleW")
- procWriteFile = modkernel32.NewProc("WriteFile")
- // procSetConsoleCP = modkernel32.NewProc("SetConsoleCP")
- // procSetThreadPriority = modkernel32.NewProc("SetThreadPriority")
- //--
- modadvapi = windows.NewLazySystemDLL("advapi32.dll")
- //--
- procAccessCheck = modadvapi.NewProc("AccessCheck")
- procAddAce = modadvapi.NewProc("AddAce")
- procEqualSid = modadvapi.NewProc("EqualSid")
- procGetAce = modadvapi.NewProc("GetAce")
- procGetAclInformation = modadvapi.NewProc("GetAclInformation")
- procGetFileSecurityA = modadvapi.NewProc("GetFileSecurityA")
- procGetFileSecurityW = modadvapi.NewProc("GetFileSecurityW")
- procGetLengthSid = modadvapi.NewProc("GetLengthSid")
- procGetNamedSecurityInfoW = modadvapi.NewProc("GetNamedSecurityInfoW")
- procGetSecurityDescriptorDacl = modadvapi.NewProc("GetSecurityDescriptorDacl")
- procGetSecurityDescriptorOwner = modadvapi.NewProc("GetSecurityDescriptorOwner")
- procGetSidIdentifierAuthority = modadvapi.NewProc("GetSidIdentifierAuthority")
- procGetSidLengthRequired = modadvapi.NewProc("GetSidLengthRequired")
- procGetSidSubAuthority = modadvapi.NewProc("GetSidSubAuthority")
- procGetTokenInformation = modadvapi.NewProc("GetTokenInformation")
- procImpersonateSelf = modadvapi.NewProc("ImpersonateSelf")
- procInitializeAcl = modadvapi.NewProc("InitializeAcl")
- procInitializeSid = modadvapi.NewProc("InitializeSid")
- procOpenThreadToken = modadvapi.NewProc("OpenThreadToken")
- procRevertToSelf = modadvapi.NewProc("RevertToSelf")
- //--
- modws2_32 = windows.NewLazySystemDLL("ws2_32.dll")
- //--
- procWSAStartup = modws2_32.NewProc("WSAStartup")
- //--
- moduser32 = windows.NewLazySystemDLL("user32.dll")
- //--
- procCharLowerW = moduser32.NewProc("CharLowerW")
- procCreateWindowExW = moduser32.NewProc("CreateWindowExW")
- procMsgWaitForMultipleObjectsEx = moduser32.NewProc("MsgWaitForMultipleObjectsEx")
- procPeekMessageW = moduser32.NewProc("PeekMessageW")
- procRegisterClassW = moduser32.NewProc("RegisterClassW")
- procUnregisterClassW = moduser32.NewProc("UnregisterClassW")
- procWaitForInputIdle = moduser32.NewProc("WaitForInputIdle")
- //--
- netapi = windows.NewLazySystemDLL("netapi32.dll")
- procNetGetDCName = netapi.NewProc("NetGetDCName")
- procNetUserGetInfo = netapi.NewProc("NetUserGetInfo")
- userenvapi = windows.NewLazySystemDLL("userenv.dll")
- procGetProfilesDirectoryW = userenvapi.NewProc("GetProfilesDirectoryW")
- modcrt = windows.NewLazySystemDLL("msvcrt.dll")
- procAccess = modcrt.NewProc("_access")
- procChmod = modcrt.NewProc("_chmod")
- procCtime64 = modcrt.NewProc("ctime64")
- procGmtime = modcrt.NewProc("gmtime")
- procGmtime32 = modcrt.NewProc("_gmtime32")
- procGmtime64 = modcrt.NewProc("_gmtime64")
- procStati64 = modcrt.NewProc("_stati64")
- procStrftime = modcrt.NewProc("strftime")
- procStrnicmp = modcrt.NewProc("_strnicmp")
- procStrtod = modcrt.NewProc("strtod")
- procTime64 = modcrt.NewProc("time64")
- procWcsncpy = modcrt.NewProc("wcsncpy")
- procWcsrchr = modcrt.NewProc("wcsrchr")
- moducrt = windows.NewLazySystemDLL("ucrtbase.dll")
- procFindfirst32 = moducrt.NewProc("_findfirst32")
- procFindnext32 = moducrt.NewProc("_findnext32")
- procStat64i32 = moducrt.NewProc("_stat64i32")
- procWchmod = moducrt.NewProc("_wchmod")
- procWfindfirst32 = moducrt.NewProc("_wfindfirst32")
- procWfindfirst64i32 = moducrt.NewProc("_wfindfirst64i32")
- procWfindnext32 = moducrt.NewProc("_wfindnext32")
- procWfindnext64i32 = moducrt.NewProc("_wfindnext64i32")
- procWmkdir = moducrt.NewProc("_wmkdir")
- procWstat32 = moducrt.NewProc("_wstat32")
- procWstat64i32 = moducrt.NewProc("_wstat64i32")
- )
- var (
- threadCallback uintptr
- )
- func init() {
- isWindows = true
- threadCallback = windows.NewCallback(ThreadProc)
- }
- // ---------------------------------
- // Windows filehandle-to-fd mapping
- // so the lib-c interface contract looks
- // like normal fds being passed around
- // but we're mapping them back and forth to
- // native windows file handles (windows.Handle)
- //
- var EBADF = errors.New("EBADF")
- var w_nextFd int32 = 42
- var w_fdLock sync.Mutex
- var w_fd_to_file = map[int32]*file{}
- type file struct {
- _fd int32
- hadErr bool
- t uintptr
- windows.Handle
- }
- func addFile(hdl windows.Handle, fd int32) uintptr {
- var f = file{_fd: fd, Handle: hdl}
- w_fdLock.Lock()
- defer w_fdLock.Unlock()
- w_fd_to_file[fd] = &f
- f.t = addObject(&f)
- return f.t
- }
- func remFile(f *file) {
- removeObject(f.t)
- w_fdLock.Lock()
- defer w_fdLock.Unlock()
- delete(w_fd_to_file, f._fd)
- }
- func fdToFile(fd int32) (*file, bool) {
- w_fdLock.Lock()
- defer w_fdLock.Unlock()
- f, ok := w_fd_to_file[fd]
- return f, ok
- }
- // Wrap the windows handle up tied to a unique fd
- func wrapFdHandle(hdl windows.Handle) (uintptr, int32) {
- newFd := atomic.AddInt32(&w_nextFd, 1)
- return addFile(hdl, newFd), newFd
- }
- func (f *file) err() bool {
- return f.hadErr
- }
- func (f *file) setErr() {
- f.hadErr = true
- }
- func (tls *TLS) SetLastError(_dwErrCode uint32) {
- if tls != nil {
- tls.lastError = _dwErrCode
- }
- }
- // https://github.com/golang/go/issues/41220
- func (tls *TLS) GetLastError() (r uint32) {
- if tls == nil {
- return 0
- }
- return tls.lastError
- }
- // -----------------------------------
- // On windows we have to fetch these
- //
- // stdout, stdin, sterr
- //
- // Using the windows specific GetStdHandle
- // they're mapped to the standard fds (0,1,2)
- // Note: it's possible they don't exist
- // if the app has been built for a GUI only
- // target in windows. If that's the case
- // panic seems like the only reasonable option
- // ------------------------------
- func newFile(t *TLS, fd int32) uintptr {
- if fd == unistd.STDIN_FILENO {
- h, err := windows.GetStdHandle(windows.STD_INPUT_HANDLE)
- if err != nil {
- panic("no console")
- }
- return addFile(h, fd)
- }
- if fd == unistd.STDOUT_FILENO {
- h, err := windows.GetStdHandle(windows.STD_OUTPUT_HANDLE)
- if err != nil {
- panic("no console")
- }
- return addFile(h, fd)
- }
- if fd == unistd.STDERR_FILENO {
- h, err := windows.GetStdHandle(windows.STD_ERROR_HANDLE)
- if err != nil {
- panic("no console")
- }
- return addFile(h, fd)
- }
- // should not get here -- unless newFile
- // is being used from somewhere we don't know about
- // to originate fds.
- panic("unknown fd source")
- return 0
- }
- func (f *file) close(t *TLS) int32 {
- remFile(f)
- err := windows.Close(f.Handle)
- if err != nil {
- return (-1) // EOF
- }
- return 0
- }
- func fwrite(fd int32, b []byte) (int, error) {
- if fd == unistd.STDOUT_FILENO {
- return write(b)
- }
- f, ok := fdToFile(fd)
- if !ok {
- return -1, EBADF
- }
- if dmesgs {
- dmesg("%v: fd %v: %s", origin(1), fd, b)
- }
- return windows.Write(f.Handle, b)
- }
- // int fprintf(FILE *stream, const char *format, ...);
- func Xfprintf(t *TLS, stream, format, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v args=%v, (%v:)", t, args, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- n, _ := fwrite(f._fd, printf(format, args))
- return int32(n)
- }
- // int usleep(useconds_t usec);
- func Xusleep(t *TLS, usec types.Useconds_t) int32 {
- if __ccgo_strace {
- trc("t=%v usec=%v, (%v:)", t, usec, origin(2))
- }
- gotime.Sleep(gotime.Microsecond * gotime.Duration(usec))
- return 0
- }
- // int getrusage(int who, struct rusage *usage);
- func Xgetrusage(t *TLS, who int32, usage uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v who=%v usage=%v, (%v:)", t, who, usage, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_GETRUSAGE, uintptr(who), usage, 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- // return 0
- }
- // int lstat(const char *pathname, struct stat *statbuf);
- func Xlstat(t *TLS, pathname, statbuf uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
- }
- return Xlstat64(t, pathname, statbuf)
- }
- // int stat(const char *pathname, struct stat *statbuf);
- func Xstat(t *TLS, pathname, statbuf uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v statbuf=%v, (%v:)", t, statbuf, origin(2))
- }
- return Xstat64(t, pathname, statbuf)
- }
- // int chdir(const char *path);
- func Xchdir(t *TLS, path uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v path=%v, (%v:)", t, path, origin(2))
- }
- err := windows.Chdir(GoString(path))
- if err != nil {
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- dmesg("%v: %q: ok", origin(1), GoString(path))
- }
- return 0
- }
- var localtime time.Tm
- // struct tm *localtime(const time_t *timep);
- func Xlocaltime(_ *TLS, timep uintptr) uintptr {
- loc := getLocalLocation()
- ut := *(*time.Time_t)(unsafe.Pointer(timep))
- t := gotime.Unix(int64(ut), 0).In(loc)
- localtime.Ftm_sec = int32(t.Second())
- localtime.Ftm_min = int32(t.Minute())
- localtime.Ftm_hour = int32(t.Hour())
- localtime.Ftm_mday = int32(t.Day())
- localtime.Ftm_mon = int32(t.Month() - 1)
- localtime.Ftm_year = int32(t.Year() - 1900)
- localtime.Ftm_wday = int32(t.Weekday())
- localtime.Ftm_yday = int32(t.YearDay())
- localtime.Ftm_isdst = Bool32(isTimeDST(t))
- return uintptr(unsafe.Pointer(&localtime))
- }
- // struct tm *localtime(const time_t *timep);
- func X_localtime64(_ *TLS, timep uintptr) uintptr {
- return Xlocaltime(nil, timep)
- }
- // struct tm *localtime_r(const time_t *timep, struct tm *result);
- func Xlocaltime_r(_ *TLS, timep, result uintptr) uintptr {
- panic(todo(""))
- // loc := getLocalLocation()
- // ut := *(*unix.Time_t)(unsafe.Pointer(timep))
- // t := gotime.Unix(int64(ut), 0).In(loc)
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_sec = int32(t.Second())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_min = int32(t.Minute())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_hour = int32(t.Hour())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_mday = int32(t.Day())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_mon = int32(t.Month() - 1)
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_year = int32(t.Year() - 1900)
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_wday = int32(t.Weekday())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_yday = int32(t.YearDay())
- // (*time.Tm)(unsafe.Pointer(result)).Ftm_isdst = Bool32(isTimeDST(t))
- // return result
- }
- // int _wopen(
- //
- // const wchar_t *filename,
- // int oflag [,
- // int pmode]
- //
- // );
- func X_wopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v flags=%v args=%v, (%v:)", t, pathname, flags, args, origin(2))
- }
- var mode types.Mode_t
- if args != 0 {
- mode = *(*types.Mode_t)(unsafe.Pointer(args))
- }
- s := goWideString(pathname)
- h, err := windows.Open(GoString(pathname), int(flags), uint32(mode))
- if err != nil {
- if dmesgs {
- dmesg("%v: %q %#x: %v", origin(1), s, flags, err)
- }
- t.setErrno(err)
- return 0
- }
- _, n := wrapFdHandle(h)
- if dmesgs {
- dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), s, flags, mode, n)
- }
- return n
- }
- // int open(const char *pathname, int flags, ...);
- func Xopen(t *TLS, pathname uintptr, flags int32, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v flags=%v args=%v, (%v:)", t, pathname, flags, args, origin(2))
- }
- return Xopen64(t, pathname, flags, args)
- }
- // int open(const char *pathname, int flags, ...);
- func Xopen64(t *TLS, pathname uintptr, flags int32, cmode uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v flags=%v cmode=%v, (%v:)", t, pathname, flags, cmode, origin(2))
- }
- var mode types.Mode_t
- if cmode != 0 {
- mode = (types.Mode_t)(VaUint32(&cmode))
- }
- // fdcwd := fcntl.AT_FDCWD
- h, err := windows.Open(GoString(pathname), int(flags), uint32(mode))
- if err != nil {
- if dmesgs {
- dmesg("%v: %q %#x: %v", origin(1), GoString(pathname), flags, err)
- }
- t.setErrno(err)
- return -1
- }
- _, n := wrapFdHandle(h)
- if dmesgs {
- dmesg("%v: %q flags %#x mode %#o: fd %v", origin(1), GoString(pathname), flags, mode, n)
- }
- return n
- }
- // off_t lseek(int fd, off_t offset, int whence);
- func Xlseek(t *TLS, fd int32, offset types.Off_t, whence int32) types.Off_t {
- if __ccgo_strace {
- trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
- }
- return types.Off_t(Xlseek64(t, fd, offset, whence))
- }
- func whenceStr(whence int32) string {
- switch whence {
- case windows.FILE_CURRENT:
- return "SEEK_CUR"
- case windows.FILE_END:
- return "SEEK_END"
- case windows.FILE_BEGIN:
- return "SEEK_SET"
- default:
- return fmt.Sprintf("whence(%d)", whence)
- }
- }
- var fsyncStatbuf stat.Stat
- // int fsync(int fd);
- func Xfsync(t *TLS, fd int32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- err := windows.FlushFileBuffers(f.Handle)
- if err != nil {
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- dmesg("%v: %d: ok", origin(1), fd)
- }
- return 0
- }
- // long sysconf(int name);
- func Xsysconf(t *TLS, name int32) long {
- if __ccgo_strace {
- trc("t=%v name=%v, (%v:)", t, name, origin(2))
- }
- panic(todo(""))
- // switch name {
- // case unistd.X_SC_PAGESIZE:
- // return long(unix.Getpagesize())
- // }
- // panic(todo(""))
- }
- // int close(int fd);
- func Xclose(t *TLS, fd int32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- err := windows.Close(f.Handle)
- if err != nil {
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- dmesg("%v: %d: ok", origin(1), fd)
- }
- return 0
- }
- // char *getcwd(char *buf, size_t size);
- func Xgetcwd(t *TLS, buf uintptr, size types.Size_t) uintptr {
- if __ccgo_strace {
- trc("t=%v buf=%v size=%v, (%v:)", t, buf, size, origin(2))
- }
- b := make([]uint16, size)
- n, err := windows.GetCurrentDirectory(uint32(len(b)), &b[0])
- if err != nil {
- t.setErrno(err)
- return 0
- }
- // to bytes
- var wd = []byte(string(utf16.Decode(b[0:n])))
- if types.Size_t(len(wd)) > size {
- t.setErrno(errno.ERANGE)
- return 0
- }
- copy((*RawMem)(unsafe.Pointer(buf))[:], wd)
- (*RawMem)(unsafe.Pointer(buf))[len(wd)] = 0
- if dmesgs {
- dmesg("%v: %q: ok", origin(1), GoString(buf))
- }
- return buf
- }
- // int fstat(int fd, struct stat *statbuf);
- func Xfstat(t *TLS, fd int32, statbuf uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v statbuf=%v, (%v:)", t, fd, statbuf, origin(2))
- }
- return Xfstat64(t, fd, statbuf)
- }
- // int ftruncate(int fd, off_t length);
- func Xftruncate(t *TLS, fd int32, length types.Off_t) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v length=%v, (%v:)", t, fd, length, origin(2))
- }
- return Xftruncate64(t, fd, length)
- }
- // int fcntl(int fd, int cmd, ... /* arg */ );
- func Xfcntl(t *TLS, fd, cmd int32, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v cmd=%v args=%v, (%v:)", t, cmd, args, origin(2))
- }
- return Xfcntl64(t, fd, cmd, args)
- }
- // int _read( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/read?view=msvc-160
- //
- // int const fd,
- // void * const buffer,
- // unsigned const buffer_size
- //
- // );
- func Xread(t *TLS, fd int32, buf uintptr, count uint32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
- n, err := windows.Read(f.Handle, obuf)
- if err != nil {
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
- dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
- }
- return int32(n)
- }
- func X_read(t *TLS, fd int32, buf uintptr, count uint32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
- }
- return Xread(t, fd, buf, count)
- }
- // int _write( // https://docs.microsoft.com/en-us/cpp/c-runtime-library/reference/write?view=msvc-160
- //
- // int fd,
- // const void *buffer,
- // unsigned int count
- //
- // );
- func Xwrite(t *TLS, fd int32, buf uintptr, count uint32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- var obuf = ((*RawMem)(unsafe.Pointer(buf)))[:count]
- n, err := windows.Write(f.Handle, obuf)
- if err != nil {
- if dmesgs {
- dmesg("%v: fd %v, count %#x: %v", origin(1), fd, count, err)
- }
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- // dmesg("%v: %d %#x: %#x\n%s", origin(1), fd, count, n, hex.Dump(GoBytes(buf, int(n))))
- dmesg("%v: %d %#x: %#x", origin(1), fd, count, n)
- }
- return int32(n)
- }
- func X_write(t *TLS, fd int32, buf uintptr, count uint32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v buf=%v count=%v, (%v:)", t, fd, buf, count, origin(2))
- }
- return Xwrite(t, fd, buf, count)
- }
- // int fchmod(int fd, mode_t mode);
- func Xfchmod(t *TLS, fd int32, mode types.Mode_t) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v mode=%v, (%v:)", t, fd, mode, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_FCHMOD, uintptr(fd), uintptr(mode), 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- // if dmesgs {
- // dmesg("%v: %d %#o: ok", origin(1), fd, mode)
- // }
- // return 0
- }
- // // int fchown(int fd, uid_t owner, gid_t group);
- // func Xfchown(t *TLS, fd int32, owner types.Uid_t, group types.Gid_t) int32 {
- // if _, _, err := unix.Syscall(unix.SYS_FCHOWN, uintptr(fd), uintptr(owner), uintptr(group)); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return 0
- // }
- // // uid_t geteuid(void);
- // func Xgeteuid(t *TLS) types.Uid_t {
- // n, _, _ := unix.Syscall(unix.SYS_GETEUID, 0, 0, 0)
- // return types.Uid_t(n)
- // }
- // int munmap(void *addr, size_t length);
- func Xmunmap(t *TLS, addr uintptr, length types.Size_t) int32 {
- if __ccgo_strace {
- trc("t=%v addr=%v length=%v, (%v:)", t, addr, length, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_MUNMAP, addr, uintptr(length), 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- // return 0
- }
- type Timeval = struct {
- Ftv_sec int32
- Ftv_usec int32
- }
- // int gettimeofday(struct timeval *tv, struct timezone *tz);
- func Xgettimeofday(t *TLS, tv, tz uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v tz=%v, (%v:)", t, tz, origin(2))
- }
- if tv == 0 {
- return 0
- }
- // This seems to work as well
- // var u64 uint64
- // procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&u64)), 0, 0)
- // u64 /= 10
- // u64 -= 11644473600000000
- // (*Timeval)(unsafe.Pointer(tv)).Ftv_sec = int32(u64/1e6)
- // (*Timeval)(unsafe.Pointer(tv)).Ftv_usec = int32(u64%1e6)
- // return 0
- // But let's use the golang.org/x/sys version
- windows.Gettimeofday((*windows.Timeval)(unsafe.Pointer(tv)))
- return 0
- }
- type Timespec = struct {
- Ftv_sec time.Time_t
- Ftv_nsec int32
- }
- // int clock_gettime(clockid_t clk_id, struct timespec *tp);
- func Xclock_gettime(t *TLS, clk_id int32, tp uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v clk_id=%v tp=%v, (%v:)", t, clk_id, tp, origin(2))
- }
- var u64 uint64 // [100ns]
- procGetSystemTimeAsFileTime.Call(uintptr(unsafe.Pointer(&u64)), 0, 0)
- (*Timespec)(unsafe.Pointer(tp)).Ftv_sec = time.Time_t((u64/10 - 11644473600000000) / 1e6)
- (*Timespec)(unsafe.Pointer(tp)).Ftv_nsec = int32((u64 * 100) % 1e9)
- return 0
- }
- // int getsockopt(int sockfd, int level, int optname, void *optval, socklen_t *optlen);
- func Xgetsockopt(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- // if _, _, err := unix.Syscall6(unix.SYS_GETSOCKOPT, uintptr(sockfd), uintptr(level), uintptr(optname), optval, optlen, 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- // return 0
- }
- // // int setsockopt(int sockfd, int level, int optname, const void *optval, socklen_t optlen);
- func Xsetsockopt(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // int ioctl(int fd, unsigned long request, ...);
- func Xioctl(t *TLS, fd int32, request ulong, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v request=%v va=%v, (%v:)", t, fd, request, va, origin(2))
- }
- panic(todo(""))
- // var argp uintptr
- // if va != 0 {
- // argp = VaUintptr(&va)
- // }
- // n, _, err := unix.Syscall(unix.SYS_IOCTL, uintptr(fd), uintptr(request), argp)
- // if err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- // return int32(n)
- }
- // int select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
- func Xselect(t *TLS, nfds int32, readfds, writefds, exceptfds, timeout uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v nfds=%v timeout=%v, (%v:)", t, nfds, timeout, origin(2))
- }
- panic(todo(""))
- // n, err := unix.Select(
- // int(nfds),
- // (*unix.FdSet)(unsafe.Pointer(readfds)),
- // (*unix.FdSet)(unsafe.Pointer(writefds)),
- // (*unix.FdSet)(unsafe.Pointer(exceptfds)),
- // (*unix.Timeval)(unsafe.Pointer(timeout)),
- // )
- // if err != nil {
- // t.setErrno(err)
- // return -1
- // }
- // return int32(n)
- }
- // int mkfifo(const char *pathname, mode_t mode);
- func Xmkfifo(t *TLS, pathname uintptr, mode types.Mode_t) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
- }
- panic(todo(""))
- // if err := unix.Mkfifo(GoString(pathname), mode); err != nil {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return 0
- }
- // mode_t umask(mode_t mask);
- func Xumask(t *TLS, mask types.Mode_t) types.Mode_t {
- if __ccgo_strace {
- trc("t=%v mask=%v, (%v:)", t, mask, origin(2))
- }
- panic(todo(""))
- // n, _, _ := unix.Syscall(unix.SYS_UMASK, uintptr(mask), 0, 0)
- // return types.Mode_t(n)
- }
- // int execvp(const char *file, char *const argv[]);
- func Xexecvp(t *TLS, file, argv uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v argv=%v, (%v:)", t, argv, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_EXECVE, file, argv, Environ()); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return 0
- }
- // pid_t waitpid(pid_t pid, int *wstatus, int options);
- func Xwaitpid(t *TLS, pid types.Pid_t, wstatus uintptr, optname int32) types.Pid_t {
- if __ccgo_strace {
- trc("t=%v pid=%v wstatus=%v optname=%v, (%v:)", t, pid, wstatus, optname, origin(2))
- }
- panic(todo(""))
- // n, _, err := unix.Syscall6(unix.SYS_WAIT4, uintptr(pid), wstatus, uintptr(optname), 0, 0, 0)
- // if err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return types.Pid_t(n)
- }
- // int uname(struct utsname *buf);
- func Xuname(t *TLS, buf uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v buf=%v, (%v:)", t, buf, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_UNAME, buf, 0, 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return 0
- }
- // int getrlimit(int resource, struct rlimit *rlim);
- func Xgetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
- }
- return Xgetrlimit64(t, resource, rlim)
- }
- // int setrlimit(int resource, const struct rlimit *rlim);
- func Xsetrlimit(t *TLS, resource int32, rlim uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
- }
- return Xsetrlimit64(t, resource, rlim)
- }
- // int setrlimit(int resource, const struct rlimit *rlim);
- func Xsetrlimit64(t *TLS, resource int32, rlim uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v resource=%v rlim=%v, (%v:)", t, resource, rlim, origin(2))
- }
- panic(todo(""))
- // if _, _, err := unix.Syscall(unix.SYS_SETRLIMIT, uintptr(resource), uintptr(rlim), 0); err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return 0
- }
- // // uid_t getuid(void);
- // func Xgetuid(t *TLS) types.Uid_t {
- // return types.Uid_t(os.Getuid())
- // }
- // pid_t getpid(void);
- func Xgetpid(t *TLS) int32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- return int32(os.Getpid())
- }
- // int system(const char *command);
- func Xsystem(t *TLS, command uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v command=%v, (%v:)", t, command, origin(2))
- }
- s := GoString(command)
- if command == 0 {
- panic(todo(""))
- }
- cmd := exec.Command("sh", "-c", s)
- cmd.Stdout = os.Stdout
- cmd.Stderr = os.Stderr
- err := cmd.Run()
- if err != nil {
- ps := err.(*exec.ExitError)
- return int32(ps.ExitCode())
- }
- return 0
- }
- // var staticGetpwuid pwd.Passwd
- //
- // func init() {
- // atExit = append(atExit, func() { closePasswd(&staticGetpwuid) })
- // }
- //
- // func closePasswd(p *pwd.Passwd) {
- // Xfree(nil, p.Fpw_name)
- // Xfree(nil, p.Fpw_passwd)
- // Xfree(nil, p.Fpw_gecos)
- // Xfree(nil, p.Fpw_dir)
- // Xfree(nil, p.Fpw_shell)
- // *p = pwd.Passwd{}
- // }
- // struct passwd *getpwuid(uid_t uid);
- func Xgetpwuid(t *TLS, uid uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v uid=%v, (%v:)", t, uid, origin(2))
- }
- panic(todo(""))
- // f, err := os.Open("/etc/passwd")
- // if err != nil {
- // panic(todo("", err))
- // }
- //
- // defer f.Close()
- //
- // sid := strconv.Itoa(int(uid))
- // sc := bufio.NewScanner(f)
- // for sc.Scan() {
- // // eg. "root:x:0:0:root:/root:/bin/bash"
- // a := strings.Split(sc.Text(), ":")
- // if len(a) < 7 {
- // panic(todo(""))
- // }
- //
- // if a[2] == sid {
- // uid, err := strconv.Atoi(a[2])
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // gid, err := strconv.Atoi(a[3])
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // closePasswd(&staticGetpwuid)
- // gecos := a[4]
- // if strings.Contains(gecos, ",") {
- // a := strings.Split(gecos, ",")
- // gecos = a[0]
- // }
- // initPasswd(t, &staticGetpwuid, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
- // return uintptr(unsafe.Pointer(&staticGetpwuid))
- // }
- // }
- //
- // if sc.Err() != nil {
- // panic(todo(""))
- // }
- //
- // return 0
- }
- // func initPasswd(t *TLS, p *pwd.Passwd, name, pwd string, uid, gid uint32, gecos, dir, shell string) {
- // p.Fpw_name = cString(t, name)
- // p.Fpw_passwd = cString(t, pwd)
- // p.Fpw_uid = uid
- // p.Fpw_gid = gid
- // p.Fpw_gecos = cString(t, gecos)
- // p.Fpw_dir = cString(t, dir)
- // p.Fpw_shell = cString(t, shell)
- // }
- // int setvbuf(FILE *stream, char *buf, int mode, size_t size);
- func Xsetvbuf(t *TLS, stream, buf uintptr, mode int32, size types.Size_t) int32 {
- if __ccgo_strace {
- trc("t=%v buf=%v mode=%v size=%v, (%v:)", t, buf, mode, size, origin(2))
- }
- return 0 //TODO
- }
- // int raise(int sig);
- func Xraise(t *TLS, sig int32) int32 {
- if __ccgo_strace {
- trc("t=%v sig=%v, (%v:)", t, sig, origin(2))
- }
- panic(todo(""))
- }
- // int backtrace(void **buffer, int size);
- func Xbacktrace(t *TLS, buf uintptr, size int32) int32 {
- if __ccgo_strace {
- trc("t=%v buf=%v size=%v, (%v:)", t, buf, size, origin(2))
- }
- panic(todo(""))
- }
- // void backtrace_symbols_fd(void *const *buffer, int size, int fd);
- func Xbacktrace_symbols_fd(t *TLS, buffer uintptr, size, fd int32) {
- if __ccgo_strace {
- trc("t=%v buffer=%v fd=%v, (%v:)", t, buffer, fd, origin(2))
- }
- panic(todo(""))
- }
- // int fileno(FILE *stream);
- func Xfileno(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- if stream == 0 {
- t.setErrno(errno.EBADF)
- return -1
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- return f._fd
- }
- // var staticGetpwnam pwd.Passwd
- //
- // func init() {
- // atExit = append(atExit, func() { closePasswd(&staticGetpwnam) })
- // }
- //
- // // struct passwd *getpwnam(const char *name);
- // func Xgetpwnam(t *TLS, name uintptr) uintptr {
- // f, err := os.Open("/etc/passwd")
- // if err != nil {
- // panic(todo("", err))
- // }
- //
- // defer f.Close()
- //
- // sname := GoString(name)
- // sc := bufio.NewScanner(f)
- // for sc.Scan() {
- // // eg. "root:x:0:0:root:/root:/bin/bash"
- // a := strings.Split(sc.Text(), ":")
- // if len(a) < 7 {
- // panic(todo(""))
- // }
- //
- // if a[0] == sname {
- // uid, err := strconv.Atoi(a[2])
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // gid, err := strconv.Atoi(a[3])
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // closePasswd(&staticGetpwnam)
- // gecos := a[4]
- // if strings.Contains(gecos, ",") {
- // a := strings.Split(gecos, ",")
- // gecos = a[0]
- // }
- // initPasswd(t, &staticGetpwnam, a[0], a[1], uint32(uid), uint32(gid), gecos, a[5], a[6])
- // return uintptr(unsafe.Pointer(&staticGetpwnam))
- // }
- // }
- //
- // if sc.Err() != nil {
- // panic(todo(""))
- // }
- //
- // return 0
- // }
- //
- // var staticGetgrnam grp.Group
- //
- // func init() {
- // atExit = append(atExit, func() { closeGroup(&staticGetgrnam) })
- // }
- //
- // // struct group *getgrnam(const char *name);
- // func Xgetgrnam(t *TLS, name uintptr) uintptr {
- // f, err := os.Open("/etc/group")
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // defer f.Close()
- //
- // sname := GoString(name)
- // sc := bufio.NewScanner(f)
- // for sc.Scan() {
- // // eg. "root:x:0:"
- // a := strings.Split(sc.Text(), ":")
- // if len(a) < 4 {
- // panic(todo(""))
- // }
- //
- // if a[0] == sname {
- // closeGroup(&staticGetgrnam)
- // gid, err := strconv.Atoi(a[2])
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // var names []string
- // if a[3] != "" {
- // names = strings.Split(a[3], ",")
- // }
- // initGroup(t, &staticGetgrnam, a[0], a[1], uint32(gid), names)
- // return uintptr(unsafe.Pointer(&staticGetgrnam))
- // }
- // }
- //
- // if sc.Err() != nil {
- // panic(todo(""))
- // }
- //
- // return 0
- // }
- //
- // func closeGroup(p *grp.Group) {
- // Xfree(nil, p.Fgr_name)
- // Xfree(nil, p.Fgr_passwd)
- // if p.Fgr_mem != 0 {
- // panic(todo(""))
- // }
- //
- // *p = grp.Group{}
- // }
- //
- // func initGroup(t *TLS, p *grp.Group, name, pwd string, gid uint32, names []string) {
- // p.Fgr_name = cString(t, name)
- // p.Fgr_passwd = cString(t, pwd)
- // p.Fgr_gid = gid
- // p.Fgr_mem = 0
- // if len(names) != 0 {
- // panic(todo("%q %q %v %q %v", name, pwd, gid, names, len(names)))
- // }
- // }
- //
- // func init() {
- // atExit = append(atExit, func() { closeGroup(&staticGetgrgid) })
- // }
- //
- // var staticGetgrgid grp.Group
- //
- // // struct group *getgrgid(gid_t gid);
- // func Xgetgrgid(t *TLS, gid uint32) uintptr {
- // f, err := os.Open("/etc/group")
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // defer f.Close()
- //
- // sid := strconv.Itoa(int(gid))
- // sc := bufio.NewScanner(f)
- // for sc.Scan() {
- // // eg. "root:x:0:"
- // a := strings.Split(sc.Text(), ":")
- // if len(a) < 4 {
- // panic(todo(""))
- // }
- //
- // if a[2] == sid {
- // closeGroup(&staticGetgrgid)
- // var names []string
- // if a[3] != "" {
- // names = strings.Split(a[3], ",")
- // }
- // initGroup(t, &staticGetgrgid, a[0], a[1], gid, names)
- // return uintptr(unsafe.Pointer(&staticGetgrgid))
- // }
- // }
- //
- // if sc.Err() != nil {
- // panic(todo(""))
- // }
- //
- // return 0
- // }
- // int mkstemps(char *template, int suffixlen);
- func Xmkstemps(t *TLS, template uintptr, suffixlen int32) int32 {
- if __ccgo_strace {
- trc("t=%v template=%v suffixlen=%v, (%v:)", t, template, suffixlen, origin(2))
- }
- return Xmkstemps64(t, template, suffixlen)
- }
- // int mkstemps(char *template, int suffixlen);
- func Xmkstemps64(t *TLS, template uintptr, suffixlen int32) int32 {
- if __ccgo_strace {
- trc("t=%v template=%v suffixlen=%v, (%v:)", t, template, suffixlen, origin(2))
- }
- panic(todo(""))
- // len := uintptr(Xstrlen(t, template))
- // x := template + uintptr(len-6) - uintptr(suffixlen)
- // for i := uintptr(0); i < 6; i++ {
- // if *(*byte)(unsafe.Pointer(x + i)) != 'X' {
- // t.setErrno(errno.EINVAL)
- // return -1
- // }
- // }
- //
- // fd, err := tempFile(template, x)
- // if err != 0 {
- // t.setErrno(err)
- // return -1
- // }
- //
- // return int32(fd)
- }
- // int mkstemp(char *template);
- func Xmkstemp64(t *TLS, template uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v template=%v, (%v:)", t, template, origin(2))
- }
- return Xmkstemps64(t, template, 0)
- }
- // func newFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err windows.Errno) (r *fts.FTSENT) {
- // var statp uintptr
- // if stat != nil {
- // statp = Xmalloc(t, types.Size_t(unsafe.Sizeof(unix.Stat_t{})))
- // if statp == 0 {
- // panic("OOM")
- // }
- //
- // *(*unix.Stat_t)(unsafe.Pointer(statp)) = *stat
- // }
- // csp := CString(path)
- // if csp == 0 {
- // panic("OOM")
- // }
- //
- // return &fts.FTSENT{
- // Ffts_info: uint16(info),
- // Ffts_path: csp,
- // Ffts_pathlen: uint16(len(path)),
- // Ffts_statp: statp,
- // Ffts_errno: int32(err),
- // }
- // }
- //
- // func newCFtsent(t *TLS, info int, path string, stat *unix.Stat_t, err windows.Errno) uintptr {
- // p := Xcalloc(t, types.Size_t(unsafe.Sizeof(fts.FTSENT{})))
- // if p == 0 {
- // panic("OOM")
- // }
- //
- // *(*fts.FTSENT)(unsafe.Pointer(p)) = *newFtsent(t, info, path, stat, err)
- // return p
- // }
- //
- // func ftsentClose(t *TLS, p uintptr) {
- // Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_path)
- // Xfree(t, (*fts.FTSENT)(unsafe.Pointer(p)).Ffts_statp)
- // }
- type ftstream struct {
- s []uintptr
- x int
- }
- // func (f *ftstream) close(t *TLS) {
- // for _, p := range f.s {
- // ftsentClose(t, p)
- // Xfree(t, p)
- // }
- // *f = ftstream{}
- // }
- //
- // // FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
- // func Xfts_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
- // return Xfts64_open(t, path_argv, options, compar)
- // }
- // FTS *fts_open(char * const *path_argv, int options, int (*compar)(const FTSENT **, const FTSENT **));
- func Xfts64_open(t *TLS, path_argv uintptr, options int32, compar uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v path_argv=%v options=%v compar=%v, (%v:)", t, path_argv, options, compar, origin(2))
- }
- panic(todo(""))
- // f := &ftstream{}
- //
- // var walk func(string)
- // walk = func(path string) {
- // var fi os.FileInfo
- // var err error
- // switch {
- // case options&fts.FTS_LOGICAL != 0:
- // fi, err = os.Stat(path)
- // case options&fts.FTS_PHYSICAL != 0:
- // fi, err = os.Lstat(path)
- // default:
- // panic(todo(""))
- // }
- //
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // var statp *unix.Stat_t
- // if options&fts.FTS_NOSTAT == 0 {
- // var stat unix.Stat_t
- // switch {
- // case options&fts.FTS_LOGICAL != 0:
- // if err := unix.Stat(path, &stat); err != nil {
- // panic(todo(""))
- // }
- // case options&fts.FTS_PHYSICAL != 0:
- // if err := unix.Lstat(path, &stat); err != nil {
- // panic(todo(""))
- // }
- // default:
- // panic(todo(""))
- // }
- //
- // statp = &stat
- // }
- //
- // out:
- // switch {
- // case fi.IsDir():
- // f.s = append(f.s, newCFtsent(t, fts.FTS_D, path, statp, 0))
- // g, err := os.Open(path)
- // switch x := err.(type) {
- // case nil:
- // // ok
- // case *os.PathError:
- // f.s = append(f.s, newCFtsent(t, fts.FTS_DNR, path, statp, errno.EACCES))
- // break out
- // default:
- // panic(todo("%q: %v %T", path, x, x))
- // }
- //
- // names, err := g.Readdirnames(-1)
- // g.Close()
- // if err != nil {
- // panic(todo(""))
- // }
- //
- // for _, name := range names {
- // walk(path + "/" + name)
- // if f == nil {
- // break out
- // }
- // }
- //
- // f.s = append(f.s, newCFtsent(t, fts.FTS_DP, path, statp, 0))
- // default:
- // info := fts.FTS_F
- // if fi.Mode()&os.ModeSymlink != 0 {
- // info = fts.FTS_SL
- // }
- // switch {
- // case statp != nil:
- // f.s = append(f.s, newCFtsent(t, info, path, statp, 0))
- // case options&fts.FTS_NOSTAT != 0:
- // f.s = append(f.s, newCFtsent(t, fts.FTS_NSOK, path, nil, 0))
- // default:
- // panic(todo(""))
- // }
- // }
- // }
- //
- // for {
- // p := *(*uintptr)(unsafe.Pointer(path_argv))
- // if p == 0 {
- // if f == nil {
- // return 0
- // }
- //
- // if compar != 0 {
- // panic(todo(""))
- // }
- //
- // return addObject(f)
- // }
- //
- // walk(GoString(p))
- // path_argv += unsafe.Sizeof(uintptr(0))
- // }
- }
- // FTSENT *fts_read(FTS *ftsp);
- func Xfts_read(t *TLS, ftsp uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
- }
- return Xfts64_read(t, ftsp)
- }
- // FTSENT *fts_read(FTS *ftsp);
- func Xfts64_read(t *TLS, ftsp uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
- }
- panic(todo(""))
- // f := winGetObject(ftsp).(*ftstream)
- // if f.x == len(f.s) {
- // t.setErrno(0)
- // return 0
- // }
- //
- // r := f.s[f.x]
- // if e := (*fts.FTSENT)(unsafe.Pointer(r)).Ffts_errno; e != 0 {
- // t.setErrno(e)
- // }
- // f.x++
- // return r
- }
- // int fts_close(FTS *ftsp);
- func Xfts_close(t *TLS, ftsp uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
- }
- return Xfts64_close(t, ftsp)
- }
- // int fts_close(FTS *ftsp);
- func Xfts64_close(t *TLS, ftsp uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ftsp=%v, (%v:)", t, ftsp, origin(2))
- }
- panic(todo(""))
- // winGetObject(ftsp).(*ftstream).close(t)
- // removeObject(ftsp)
- // return 0
- }
- // void tzset (void);
- func Xtzset(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- //TODO
- }
- var strerrorBuf [256]byte
- // char *strerror(int errnum);
- func Xstrerror(t *TLS, errnum int32) uintptr {
- if __ccgo_strace {
- trc("t=%v errnum=%v, (%v:)", t, errnum, origin(2))
- }
- copy((*RawMem)(unsafe.Pointer(&strerrorBuf[0]))[:len(strerrorBuf):len(strerrorBuf)], fmt.Sprintf("errno %d\x00", errnum))
- return uintptr(unsafe.Pointer(&strerrorBuf[0]))
- }
- // void *dlopen(const char *filename, int flags);
- func Xdlopen(t *TLS, filename uintptr, flags int32) uintptr {
- if __ccgo_strace {
- trc("t=%v filename=%v flags=%v, (%v:)", t, filename, flags, origin(2))
- }
- panic(todo(""))
- }
- // char *dlerror(void);
- func Xdlerror(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- // int dlclose(void *handle);
- func Xdlclose(t *TLS, handle uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v handle=%v, (%v:)", t, handle, origin(2))
- }
- panic(todo(""))
- }
- // void *dlsym(void *handle, const char *symbol);
- func Xdlsym(t *TLS, handle, symbol uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v symbol=%v, (%v:)", t, symbol, origin(2))
- }
- panic(todo(""))
- }
- // void perror(const char *s);
- func Xperror(t *TLS, s uintptr) {
- if __ccgo_strace {
- trc("t=%v s=%v, (%v:)", t, s, origin(2))
- }
- panic(todo(""))
- }
- // int pclose(FILE *stream);
- func Xpclose(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- panic(todo(""))
- }
- var gai_strerrorBuf [100]byte
- // const char *gai_strerror(int errcode);
- func Xgai_strerror(t *TLS, errcode int32) uintptr {
- if __ccgo_strace {
- trc("t=%v errcode=%v, (%v:)", t, errcode, origin(2))
- }
- copy(gai_strerrorBuf[:], fmt.Sprintf("gai error %d\x00", errcode))
- return uintptr(unsafe.Pointer(&gai_strerrorBuf))
- }
- // int tcgetattr(int fd, struct termios *termios_p);
- func Xtcgetattr(t *TLS, fd int32, termios_p uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v termios_p=%v, (%v:)", t, fd, termios_p, origin(2))
- }
- panic(todo(""))
- }
- // int tcsetattr(int fd, int optional_actions, const struct termios *termios_p);
- func Xtcsetattr(t *TLS, fd, optional_actions int32, termios_p uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v optional_actions=%v termios_p=%v, (%v:)", t, optional_actions, termios_p, origin(2))
- }
- panic(todo(""))
- }
- // // speed_t cfgetospeed(const struct termios *termios_p);
- // func Xcfgetospeed(t *TLS, termios_p uintptr) termios.Speed_t {
- // panic(todo(""))
- // }
- // int cfsetospeed(struct termios *termios_p, speed_t speed);
- func Xcfsetospeed(t *TLS, termios_p uintptr, speed uint32) int32 {
- if __ccgo_strace {
- trc("t=%v termios_p=%v speed=%v, (%v:)", t, termios_p, speed, origin(2))
- }
- panic(todo(""))
- }
- // int cfsetispeed(struct termios *termios_p, speed_t speed);
- func Xcfsetispeed(t *TLS, termios_p uintptr, speed uint32) int32 {
- if __ccgo_strace {
- trc("t=%v termios_p=%v speed=%v, (%v:)", t, termios_p, speed, origin(2))
- }
- panic(todo(""))
- }
- // pid_t fork(void);
- func Xfork(t *TLS) int32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- t.setErrno(errno.ENOSYS)
- return -1
- }
- // char *setlocale(int category, const char *locale);
- func Xsetlocale(t *TLS, category int32, locale uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v category=%v locale=%v, (%v:)", t, category, locale, origin(2))
- }
- return 0 //TODO
- }
- // // char *nl_langinfo(nl_item item);
- // func Xnl_langinfo(t *TLS, item langinfo.Nl_item) uintptr {
- // panic(todo(""))
- // }
- // FILE *popen(const char *command, const char *type);
- func Xpopen(t *TLS, command, type1 uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v type1=%v, (%v:)", t, type1, origin(2))
- }
- panic(todo(""))
- }
- // char *realpath(const char *path, char *resolved_path);
- func Xrealpath(t *TLS, path, resolved_path uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v resolved_path=%v, (%v:)", t, resolved_path, origin(2))
- }
- s, err := filepath.EvalSymlinks(GoString(path))
- if err != nil {
- if os.IsNotExist(err) {
- if dmesgs {
- dmesg("%v: %q: %v", origin(1), GoString(path), err)
- }
- t.setErrno(errno.ENOENT)
- return 0
- }
- panic(todo("", err))
- }
- if resolved_path == 0 {
- panic(todo(""))
- }
- if len(s) >= limits.PATH_MAX {
- s = s[:limits.PATH_MAX-1]
- }
- copy((*RawMem)(unsafe.Pointer(resolved_path))[:len(s):len(s)], s)
- (*RawMem)(unsafe.Pointer(resolved_path))[len(s)] = 0
- return resolved_path
- }
- // // char *inet_ntoa(struct in_addr in);
- // func Xinet_ntoa(t *TLS, in1 in.In_addr) uintptr {
- // panic(todo(""))
- // }
- // func X__ccgo_in6addr_anyp(t *TLS) uintptr {
- // return uintptr(unsafe.Pointer(&in6_addr_any))
- // }
- func Xabort(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- // if dmesgs {
- // dmesg("%v:\n%s", origin(1), debug.Stack())
- // }
- // p := Xmalloc(t, types.Size_t(unsafe.Sizeof(signal.Sigaction{})))
- // if p == 0 {
- // panic("OOM")
- // }
- //
- // *(*signal.Sigaction)(unsafe.Pointer(p)) = signal.Sigaction{
- // F__sigaction_handler: struct{ Fsa_handler signal.X__sighandler_t }{Fsa_handler: signal.SIG_DFL},
- // }
- // Xsigaction(t, signal.SIGABRT, p, 0)
- // Xfree(t, p)
- // unix.Kill(unix.Getpid(), windows.Signal(signal.SIGABRT))
- // panic(todo("unrechable"))
- }
- // int fflush(FILE *stream);
- func Xfflush(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- err := windows.FlushFileBuffers(f.Handle)
- if err != nil {
- t.setErrno(err)
- return -1
- }
- return 0
- }
- // size_t fread(void *ptr, size_t size, size_t nmemb, FILE *stream);
- func Xfread(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
- if __ccgo_strace {
- trc("t=%v ptr=%v nmemb=%v stream=%v, (%v:)", t, ptr, nmemb, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return 0
- }
- var sz = size * nmemb
- var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
- n, err := windows.Read(f.Handle, obuf)
- if err != nil {
- f.setErr()
- return 0
- }
- if dmesgs {
- // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
- dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
- }
- return types.Size_t(n) / size
- }
- // size_t fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream);
- func Xfwrite(t *TLS, ptr uintptr, size, nmemb types.Size_t, stream uintptr) types.Size_t {
- if __ccgo_strace {
- trc("t=%v ptr=%v nmemb=%v stream=%v, (%v:)", t, ptr, nmemb, stream, origin(2))
- }
- if ptr == 0 || size == 0 {
- return 0
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return 0
- }
- var sz = size * nmemb
- var obuf = ((*RawMem)(unsafe.Pointer(ptr)))[:sz]
- n, err := windows.Write(f.Handle, obuf)
- if err != nil {
- f.setErr()
- return 0
- }
- if dmesgs {
- // // dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), file(stream).fd(), size, nmemb, types.Size_t(m)/size, hex.Dump(GoBytes(ptr, int(m))))
- dmesg("%v: %d %#x x %#x: %#x\n%s", origin(1), f._fd, size, nmemb, types.Size_t(n)/size)
- }
- return types.Size_t(n) / size
- }
- // int fclose(FILE *stream);
- func Xfclose(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- return f.close(t)
- }
- // int fputc(int c, FILE *stream);
- func Xfputc(t *TLS, c int32, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v c=%v stream=%v, (%v:)", t, c, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- if _, err := fwrite(f._fd, []byte{byte(c)}); err != nil {
- return -1
- }
- return int32(byte(c))
- }
- // int fseek(FILE *stream, long offset, int whence);
- func Xfseek(t *TLS, stream uintptr, offset long, whence int32) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v offset=%v whence=%v, (%v:)", t, stream, offset, whence, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- if n := Xlseek(t, f._fd, types.Off_t(offset), whence); n < 0 {
- if dmesgs {
- dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
- }
- f.setErr()
- return -1
- }
- if dmesgs {
- dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
- }
- return 0
- }
- // long ftell(FILE *stream);
- func Xftell(t *TLS, stream uintptr) long {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- n := Xlseek(t, f._fd, 0, windows.FILE_CURRENT)
- if n < 0 {
- f.setErr()
- return -1
- }
- if dmesgs {
- dmesg("%v: fd %v, n %#x: ok %#x", origin(1), f._fd, n, long(n))
- }
- return long(n)
- }
- // int ferror(FILE *stream);
- func Xferror(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- return Bool32(f.err())
- }
- // int getc(FILE *stream);
- func Xfgetc(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return stdio.EOF
- }
- var buf [1]byte
- if n, _ := windows.Read(f.Handle, buf[:]); n != 0 {
- return int32(buf[0])
- }
- return stdio.EOF
- }
- // int ungetc(int c, FILE *stream);
- func Xungetc(t *TLS, c int32, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v c=%v stream=%v, (%v:)", t, c, stream, origin(2))
- }
- panic(todo(""))
- }
- // int fscanf(FILE *stream, const char *format, ...);
- func Xfscanf(t *TLS, stream, format, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v va=%v, (%v:)", t, va, origin(2))
- }
- panic(todo(""))
- }
- // int fputs(const char *s, FILE *stream);
- func Xfputs(t *TLS, s, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- gS := GoString(s)
- if _, err := fwrite(f._fd, []byte(gS)); err != nil {
- return -1
- }
- return 0
- }
- // var getservbynameStaticResult netdb.Servent
- //
- // // struct servent *getservbyname(const char *name, const char *proto);
- // func Xgetservbyname(t *TLS, name, proto uintptr) uintptr {
- // var protoent *gonetdb.Protoent
- // if proto != 0 {
- // protoent = gonetdb.GetProtoByName(GoString(proto))
- // }
- // servent := gonetdb.GetServByName(GoString(name), protoent)
- // if servent == nil {
- // if dmesgs {
- // dmesg("%q %q: nil (protoent %+v)", GoString(name), GoString(proto), protoent)
- // }
- // return 0
- // }
- //
- // Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_name)
- // if v := (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_aliases; v != 0 {
- // for {
- // p := *(*uintptr)(unsafe.Pointer(v))
- // if p == 0 {
- // break
- // }
- //
- // Xfree(t, p)
- // v += unsafe.Sizeof(uintptr(0))
- // }
- // Xfree(t, v)
- // }
- // Xfree(t, (*netdb.Servent)(unsafe.Pointer(&getservbynameStaticResult)).Fs_proto)
- // cname, err := CString(servent.Name)
- // if err != nil {
- // getservbynameStaticResult = netdb.Servent{}
- // return 0
- // }
- //
- // var protoname uintptr
- // if protoent != nil {
- // if protoname, err = CString(protoent.Name); err != nil {
- // Xfree(t, cname)
- // getservbynameStaticResult = netdb.Servent{}
- // return 0
- // }
- // }
- // var a []uintptr
- // for _, v := range servent.Aliases {
- // cs, err := CString(v)
- // if err != nil {
- // for _, v := range a {
- // Xfree(t, v)
- // }
- // return 0
- // }
- //
- // a = append(a, cs)
- // }
- // v := Xcalloc(t, types.Size_t(len(a)+1), types.Size_t(unsafe.Sizeof(uintptr(0))))
- // if v == 0 {
- // Xfree(t, cname)
- // Xfree(t, protoname)
- // for _, v := range a {
- // Xfree(t, v)
- // }
- // getservbynameStaticResult = netdb.Servent{}
- // return 0
- // }
- // for _, p := range a {
- // *(*uintptr)(unsafe.Pointer(v)) = p
- // v += unsafe.Sizeof(uintptr(0))
- // }
- //
- // getservbynameStaticResult = netdb.Servent{
- // Fs_name: cname,
- // Fs_aliases: v,
- // Fs_port: int32(servent.Port),
- // Fs_proto: protoname,
- // }
- // return uintptr(unsafe.Pointer(&getservbynameStaticResult))
- // }
- // func Xreaddir64(t *TLS, dir uintptr) uintptr {
- // return Xreaddir(t, dir)
- // }
- // func fcntlCmdStr(cmd int32) string {
- // switch cmd {
- // case fcntl.F_GETOWN:
- // return "F_GETOWN"
- // case fcntl.F_SETLK:
- // return "F_SETLK"
- // case fcntl.F_GETLK:
- // return "F_GETLK"
- // case fcntl.F_SETFD:
- // return "F_SETFD"
- // case fcntl.F_GETFD:
- // return "F_GETFD"
- // default:
- // return fmt.Sprintf("cmd(%d)", cmd)
- // }
- // }
- // _CRTIMP extern int *__cdecl _errno(void); // /usr/share/mingw-w64/include/errno.h:17:
- func X_errno(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- return t.errnop
- }
- // int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
- func X__ms_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vsscanf(const char *str, const char *format, va_list ap);
- func X__ms_vsscanf(t *TLS, str, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vscanf(const char *format, va_list ap);
- func X__ms_vscanf(t *TLS, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
- func X__ms_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
- }
- return Xvsnprintf(t, str, size, format, ap)
- }
- // int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
- func X__ms_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vwscanf(const wchar_t * restrict format, va_list arg);
- func X__ms_vwscanf(t *TLS, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int _vsnwprintf(wchar_t *buffer, size_t count, const wchar_t *format, va_list argptr);
- func X_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v buffer=%v count=%v ap=%v, (%v:)", t, buffer, count, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
- func X__ms_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
- }
- panic(todo(""))
- }
- // __acrt_iob_func
- func X__acrt_iob_func(t *TLS, fd uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
- }
- f, ok := fdToFile(int32(fd))
- if !ok {
- t.setErrno(EBADF)
- return 0
- }
- return f.t
- }
- // BOOL SetEvent(
- //
- // HANDLE hEvent
- //
- // );
- func XSetEvent(t *TLS, hEvent uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hEvent=%v, (%v:)", t, hEvent, origin(2))
- }
- r0, _, err := procSetEvent.Call(hEvent, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int _stricmp(
- //
- // const char *string1,
- // const char *string2
- //
- // );
- func X_stricmp(t *TLS, string1, string2 uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
- }
- var s1 = strings.ToLower(GoString(string1))
- var s2 = strings.ToLower(GoString(string2))
- return int32(strings.Compare(s1, s2))
- }
- // BOOL HeapFree(
- //
- // HANDLE hHeap,
- // DWORD dwFlags,
- // _Frees_ptr_opt_ LPVOID lpMem
- //
- // );
- func XHeapFree(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
- }
- r0, _, err := procHeapFree.Call(hHeap, uintptr(dwFlags), lpMem)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // HANDLE GetProcessHeap();
- func XGetProcessHeap(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, err := procGetProcessHeap.Call(0, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // LPVOID HeapAlloc(
- //
- // HANDLE hHeap,
- // DWORD dwFlags,
- // SIZE_T dwBytes
- //
- // );
- func XHeapAlloc(t *TLS, hHeap uintptr, dwFlags uint32, dwBytes types.Size_t) uintptr {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v dwBytes=%v, (%v:)", t, hHeap, dwFlags, dwBytes, origin(2))
- }
- r0, _, err := procHeapAlloc.Call(hHeap, uintptr(dwFlags), uintptr(dwBytes))
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // WCHAR * gai_strerrorW(
- //
- // int ecode
- //
- // );
- func Xgai_strerrorW(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- // servent * getservbyname(
- //
- // const char *name,
- // const char *proto
- //
- // );
- func Xgetservbyname(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- // INT WSAAPI getaddrinfo(
- //
- // PCSTR pNodeName,
- // PCSTR pServiceName,
- // const ADDRINFOA *pHints,
- // PADDRINFOA *ppResult
- //
- // );
- func XWspiapiGetAddrInfo(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // int wcscmp(
- //
- // const wchar_t *string1,
- // const wchar_t *string2
- //
- // );
- func Xwcscmp(t *TLS, string1, string2 uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
- }
- var s1 = goWideString(string1)
- var s2 = goWideString(string2)
- return int32(strings.Compare(s1, s2))
- }
- // BOOL IsDebuggerPresent();
- func XIsDebuggerPresent(t *TLS) int32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- return 0
- }
- func XExitProcess(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // BOOL GetVersionExW(
- //
- // LPOSVERSIONINFOW lpVersionInformation
- //
- // );
- func XGetVersionExW(t *TLS, lpVersionInformation uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
- }
- r0, _, err := procGetVersionExW.Call(lpVersionInformation, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL GetVolumeNameForVolumeMountPointW(
- //
- // LPCWSTR lpszVolumeMountPoint,
- // LPWSTR lpszVolumeName,
- // DWORD cchBufferLength
- //
- // );
- func XGetVolumeNameForVolumeMountPointW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // size_t wcslen(
- //
- // const wchar_t *str
- //
- // );
- func Xwcslen(t *TLS, str uintptr) types.Size_t {
- if __ccgo_strace {
- trc("t=%v str=%v, (%v:)", t, str, origin(2))
- }
- r0, _, _ := procLstrlenW.Call(str, 0, 0)
- return types.Size_t(r0)
- }
- // HANDLE WINAPI GetStdHandle(
- //
- // _In_ DWORD nStdHandle
- //
- // );
- func XGetStdHandle(t *TLS, nStdHandle uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v nStdHandle=%v, (%v:)", t, nStdHandle, origin(2))
- }
- h, err := windows.GetStdHandle(nStdHandle)
- if err != nil {
- panic("no console")
- }
- return uintptr(h)
- }
- // BOOL CloseHandle(
- //
- // HANDLE hObject
- //
- // );
- func XCloseHandle(t *TLS, hObject uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hObject=%v, (%v:)", t, hObject, origin(2))
- }
- r := windows.CloseHandle(windows.Handle(hObject))
- if r != nil {
- return errno.EINVAL
- }
- return 1
- }
- // DWORD GetLastError();
- func XGetLastError(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- var rv = *(*int32)(unsafe.Pointer(t.errnop))
- return uint32(rv)
- //r1, _, _ := procGetLastError.Call(0, 0, 0)
- //return uint32(r1)
- }
- // DWORD SetFilePointer(
- //
- // HANDLE hFile,
- // LONG lDistanceToMove,
- // PLONG lpDistanceToMoveHigh,
- // DWORD dwMoveMethod
- //
- // );
- func XSetFilePointer(t *TLS, hFile uintptr, lDistanceToMove long, lpDistanceToMoveHigh uintptr, dwMoveMethod uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v lDistanceToMove=%v lpDistanceToMoveHigh=%v dwMoveMethod=%v, (%v:)", t, hFile, lDistanceToMove, lpDistanceToMoveHigh, dwMoveMethod, origin(2))
- }
- r0, _, e1 := procSetFilePointer.Call(hFile, uintptr(lDistanceToMove), lpDistanceToMoveHigh, uintptr(dwMoveMethod), 0, 0)
- var uOff = uint32(r0)
- if uOff == 0xffffffff {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return uint32(r0)
- }
- // BOOL SetEndOfFile(
- //
- // HANDLE hFile
- //
- // );
- func XSetEndOfFile(t *TLS, hFile uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
- }
- err := windows.SetEndOfFile(windows.Handle(hFile))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // BOOL ReadFile(
- //
- // HANDLE hFile,
- // LPVOID lpBuffer,
- // DWORD nNumberOfBytesToRead,
- // LPDWORD lpNumberOfBytesRead,
- // LPOVERLAPPED lpOverlapped
- //
- // );
- func XReadFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToRead uint32, lpNumberOfBytesRead, lpOverlapped uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nNumberOfBytesToRead=%v lpOverlapped=%v, (%v:)", t, lpBuffer, nNumberOfBytesToRead, lpOverlapped, origin(2))
- }
- r1, _, e1 := procReadFile.Call(hFile, lpBuffer, uintptr(nNumberOfBytesToRead), uintptr(lpNumberOfBytesRead), uintptr(lpOverlapped), 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // BOOL WriteFile(
- //
- // HANDLE hFile,
- // LPCVOID lpBuffer,
- // DWORD nNumberOfBytesToWrite,
- // LPDWORD lpNumberOfBytesWritten,
- // LPOVERLAPPED lpOverlapped
- //
- // );
- func XWriteFile(t *TLS, hFile, lpBuffer uintptr, nNumberOfBytesToWrite uint32, lpNumberOfBytesWritten, lpOverlapped uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nNumberOfBytesToWrite=%v lpOverlapped=%v, (%v:)", t, lpBuffer, nNumberOfBytesToWrite, lpOverlapped, origin(2))
- }
- r1, _, e1 := procWriteFile.Call(hFile, lpBuffer, uintptr(nNumberOfBytesToWrite), lpNumberOfBytesWritten, lpOverlapped, 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // DWORD GetFileAttributesW(
- //
- // LPCWSTR lpFileName
- //
- // );
- func XGetFileAttributesW(t *TLS, lpFileName uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
- }
- attrs, err := windows.GetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)))
- if attrs == windows.INVALID_FILE_ATTRIBUTES {
- if err != nil {
- t.setErrno(err)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return attrs
- }
- // HANDLE CreateFileW(
- //
- // LPCWSTR lpFileName,
- // DWORD dwDesiredAccess,
- // DWORD dwShareMode,
- // LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- // DWORD dwCreationDisposition,
- // DWORD dwFlagsAndAttributes,
- // HANDLE hTemplateFile
- //
- // );
- func XCreateFileW(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32, lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v dwShareMode=%v lpSecurityAttributes=%v dwFlagsAndAttributes=%v hTemplateFile=%v, (%v:)", t, lpFileName, dwShareMode, lpSecurityAttributes, dwFlagsAndAttributes, hTemplateFile, origin(2))
- }
- r0, _, e1 := procCreateFileW.Call(lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
- uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
- h := windows.Handle(r0)
- if h == windows.InvalidHandle {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return r0
- }
- return uintptr(h)
- }
- // BOOL DuplicateHandle(
- //
- // HANDLE hSourceProcessHandle,
- // HANDLE hSourceHandle,
- // HANDLE hTargetProcessHandle,
- // LPHANDLE lpTargetHandle,
- // DWORD dwDesiredAccess,
- // BOOL bInheritHandle,
- // DWORD dwOptions
- //
- // );
- func XDuplicateHandle(t *TLS, hSourceProcessHandle, hSourceHandle, hTargetProcessHandle, lpTargetHandle uintptr, dwDesiredAccess uint32, bInheritHandle int32, dwOptions uint32) int32 {
- if __ccgo_strace {
- trc("t=%v lpTargetHandle=%v dwDesiredAccess=%v bInheritHandle=%v dwOptions=%v, (%v:)", t, lpTargetHandle, dwDesiredAccess, bInheritHandle, dwOptions, origin(2))
- }
- r0, _, err := procDuplicateHandle.Call(hSourceProcessHandle, hSourceHandle, hTargetProcessHandle,
- lpTargetHandle, uintptr(dwDesiredAccess), uintptr(bInheritHandle), uintptr(dwOptions), 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // HANDLE GetCurrentProcess();
- func XGetCurrentProcess(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, e1 := procGetCurrentProcess.Call(0, 0, 0)
- if r0 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return r0
- }
- // BOOL FlushFileBuffers(
- //
- // HANDLE hFile
- //
- // );
- func XFlushFileBuffers(t *TLS, hFile uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
- }
- err := windows.FlushFileBuffers(windows.Handle(hFile))
- if err != nil {
- t.setErrno(err)
- return -1
- }
- return 1
- }
- // DWORD GetFileType(
- //
- // HANDLE hFile
- //
- // );
- func XGetFileType(t *TLS, hFile uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v, (%v:)", t, hFile, origin(2))
- }
- n, err := windows.GetFileType(windows.Handle(hFile))
- if err != nil {
- t.setErrno(err)
- }
- return n
- }
- // BOOL WINAPI GetConsoleMode(
- //
- // _In_ HANDLE hConsoleHandle,
- // _Out_ LPDWORD lpMode
- //
- // );
- func XGetConsoleMode(t *TLS, hConsoleHandle, lpMode uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpMode=%v, (%v:)", t, lpMode, origin(2))
- }
- err := windows.GetConsoleMode(windows.Handle(hConsoleHandle), (*uint32)(unsafe.Pointer(lpMode)))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // BOOL GetCommState(
- //
- // HANDLE hFile,
- // LPDCB lpDCB
- //
- // );
- func XGetCommState(t *TLS, hFile, lpDCB uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpDCB=%v, (%v:)", t, lpDCB, origin(2))
- }
- r1, _, err := procGetCommState.Call(hFile, lpDCB, 0)
- if r1 == 0 {
- t.setErrno(err)
- return 0
- }
- return int32(r1)
- }
- // int _wcsnicmp(
- //
- // const wchar_t *string1,
- // const wchar_t *string2,
- // size_t count
- //
- // );
- func X_wcsnicmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v count=%v, (%v:)", t, string2, count, origin(2))
- }
- var s1 = strings.ToLower(goWideString(string1))
- var l1 = len(s1)
- var s2 = strings.ToLower(goWideString(string2))
- var l2 = len(s2)
- // shorter is lesser
- if l1 < l2 {
- return -1
- }
- if l2 > l1 {
- return 1
- }
- // compare at most count
- var cmpLen = count
- if types.Size_t(l1) < cmpLen {
- cmpLen = types.Size_t(l1)
- }
- return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
- }
- // BOOL WINAPI ReadConsole(
- //
- // _In_ HANDLE hConsoleInput,
- // _Out_ LPVOID lpBuffer,
- // _In_ DWORD nNumberOfCharsToRead,
- // _Out_ LPDWORD lpNumberOfCharsRead,
- // _In_opt_ LPVOID pInputControl
- //
- // );
- func XReadConsoleW(t *TLS, hConsoleInput, lpBuffer uintptr, nNumberOfCharsToRead uint32, lpNumberOfCharsRead, pInputControl uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nNumberOfCharsToRead=%v pInputControl=%v, (%v:)", t, lpBuffer, nNumberOfCharsToRead, pInputControl, origin(2))
- }
- rv, _, err := procReadConsoleW.Call(hConsoleInput,
- lpBuffer, uintptr(nNumberOfCharsToRead), lpNumberOfCharsRead, pInputControl, 0)
- if rv == 0 {
- t.setErrno(err)
- }
- return int32(rv)
- }
- // BOOL WINAPI WriteConsoleW(
- //
- // _In_ HANDLE hConsoleOutput,
- // _In_ const VOID *lpBuffer,
- // _In_ DWORD nNumberOfCharsToWrite,
- // _Out_opt_ LPDWORD lpNumberOfCharsWritten,
- // _Reserved_ LPVOID lpReserved
- //
- // );
- func XWriteConsoleW(t *TLS, hConsoleOutput, lpBuffer uintptr, nNumberOfCharsToWrite uint32, lpNumberOfCharsWritten, lpReserved uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nNumberOfCharsToWrite=%v lpReserved=%v, (%v:)", t, lpBuffer, nNumberOfCharsToWrite, lpReserved, origin(2))
- }
- rv, _, err := procWriteConsoleW.Call(hConsoleOutput,
- lpBuffer, uintptr(nNumberOfCharsToWrite), lpNumberOfCharsWritten, lpReserved, 0)
- if rv == 0 {
- t.setErrno(err)
- }
- return int32(rv)
- }
- // DWORD WaitForSingleObject(
- //
- // HANDLE hHandle,
- // DWORD dwMilliseconds
- //
- // );
- func XWaitForSingleObject(t *TLS, hHandle uintptr, dwMilliseconds uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v hHandle=%v dwMilliseconds=%v, (%v:)", t, hHandle, dwMilliseconds, origin(2))
- }
- rv, err := windows.WaitForSingleObject(windows.Handle(hHandle), dwMilliseconds)
- if err != nil {
- t.setErrno(err)
- }
- return rv
- }
- // BOOL ResetEvent(
- //
- // HANDLE hEvent
- //
- // );
- func XResetEvent(t *TLS, hEvent uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hEvent=%v, (%v:)", t, hEvent, origin(2))
- }
- rv, _, err := procResetEvent.Call(hEvent, 0, 0)
- if rv == 0 {
- t.setErrno(err)
- }
- return int32(rv)
- }
- // BOOL WINAPI PeekConsoleInput(
- //
- // _In_ HANDLE hConsoleInput,
- // _Out_ PINPUT_RECORD lpBuffer,
- // _In_ DWORD nLength,
- // _Out_ LPDWORD lpNumberOfEventsRead
- //
- // );
- func XPeekConsoleInputW(t *TLS, hConsoleInput, lpBuffer uintptr, nLength uint32, lpNumberOfEventsRead uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nLength=%v lpNumberOfEventsRead=%v, (%v:)", t, lpBuffer, nLength, lpNumberOfEventsRead, origin(2))
- }
- r0, _, err := procPeekConsoleInputW.Call(hConsoleInput, lpBuffer, uintptr(nLength), lpNumberOfEventsRead, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int WINAPIV wsprintfA(
- //
- // LPSTR ,
- // LPCSTR ,
- // ...
- //
- // );
- func XwsprintfA(t *TLS, buf, format, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v args=%v, (%v:)", t, args, origin(2))
- }
- return Xsprintf(t, buf, format, args)
- }
- // UINT WINAPI GetConsoleCP(void);
- func XGetConsoleCP(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, err := procGetConsoleCP.Call(0, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- // UINT WINAPI SetConsoleCP(UNIT);
- //func setConsoleCP(cp uint32) uint32 {
- //
- // r0, _, _ := procSetConsoleCP.Call(uintptr(cp), 0, 0)
- // if r0 == 0 {
- // panic("setcp failed")
- // }
- // return uint32(r0)
- //}
- // HANDLE CreateEventW(
- //
- // LPSECURITY_ATTRIBUTES lpEventAttributes,
- // BOOL bManualReset,
- // BOOL bInitialState,
- // LPCWSTR lpName
- //
- // );
- func XCreateEventW(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpEventAttributes=%v bInitialState=%v lpName=%v, (%v:)", t, lpEventAttributes, bInitialState, lpName, origin(2))
- }
- r0, _, err := procCreateEventW.Call(lpEventAttributes, uintptr(bManualReset),
- uintptr(bInitialState), lpName, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- type ThreadAdapter struct {
- token uintptr
- tls *TLS
- param uintptr
- threadFunc func(*TLS, uintptr) uint32
- }
- func (ta *ThreadAdapter) run() uintptr {
- r := ta.threadFunc(ta.tls, ta.param)
- ta.tls.Close()
- removeObject(ta.token)
- return uintptr(r)
- }
- func ThreadProc(p uintptr) uintptr {
- adp, ok := winGetObject(p).(*ThreadAdapter)
- if !ok {
- panic("invalid thread")
- }
- return adp.run()
- }
- // HANDLE CreateThread(
- //
- // LPSECURITY_ATTRIBUTES lpThreadAttributes,
- // SIZE_T dwStackSize,
- // LPTHREAD_START_ROUTINE lpStartAddress,
- // __drv_aliasesMem LPVOID lpParameter,
- // DWORD dwCreationFlags,
- // LPDWORD lpThreadId
- //
- // );
- func XCreateThread(t *TLS, lpThreadAttributes uintptr, dwStackSize types.Size_t, lpStartAddress, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpThreadAttributes=%v dwStackSize=%v lpParameter=%v dwCreationFlags=%v lpThreadId=%v, (%v:)", t, lpThreadAttributes, dwStackSize, lpParameter, dwCreationFlags, lpThreadId, origin(2))
- }
- f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{lpStartAddress})).f
- var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: lpParameter}
- tAdp.token = addObject(&tAdp)
- r0, _, err := procCreateThread.Call(lpThreadAttributes, uintptr(dwStackSize),
- threadCallback, tAdp.token, uintptr(dwCreationFlags), lpThreadId)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // BOOL SetThreadPriority(
- //
- // HANDLE hThread,
- // int nPriority
- //
- // );
- func XSetThreadPriority(t *TLS, hThread uintptr, nPriority int32) int32 {
- if __ccgo_strace {
- trc("t=%v hThread=%v nPriority=%v, (%v:)", t, hThread, nPriority, origin(2))
- }
- //r0, _, err := procSetThreadPriority.Call(hThread, uintptr(nPriority), 0)
- //if r0 == 0 {
- // t.setErrno(err)
- //}
- //return int32(r0)
- return 1
- }
- // BOOL WINAPI SetConsoleMode(
- //
- // _In_ HANDLE hConsoleHandle,
- // _In_ DWORD dwMode
- //
- // );
- func XSetConsoleMode(t *TLS, hConsoleHandle uintptr, dwMode uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hConsoleHandle=%v dwMode=%v, (%v:)", t, hConsoleHandle, dwMode, origin(2))
- }
- rv, _, err := procSetConsoleMode.Call(hConsoleHandle, uintptr(dwMode), 0)
- if rv == 0 {
- t.setErrno(err)
- }
- return int32(rv)
- }
- func XPurgeComm(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XClearCommError(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // void DeleteCriticalSection(
- //
- // LPCRITICAL_SECTION lpCriticalSection
- //
- // );
- func XDeleteCriticalSection(t *TLS, lpCriticalSection uintptr) {
- if __ccgo_strace {
- trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
- }
- procDeleteCriticalSection.Call(lpCriticalSection, 0, 0)
- }
- // void EnterCriticalSection(
- //
- // LPCRITICAL_SECTION lpCriticalSection
- //
- // );
- func XEnterCriticalSection(t *TLS, lpCriticalSection uintptr) {
- if __ccgo_strace {
- trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
- }
- procEnterCriticalSection.Call(lpCriticalSection, 0, 0)
- }
- // BOOL TryEnterCriticalSection(
- //
- // LPCRITICAL_SECTION lpCriticalSection
- //
- // );
- func XTryEnterCriticalSection(t *TLS, lpCriticalSection uintptr) (r int32) {
- if __ccgo_strace {
- trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
- }
- r0, _, err := procTryEnterCriticalSection.Call(lpCriticalSection)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // void LeaveCriticalSection(
- //
- // LPCRITICAL_SECTION lpCriticalSection
- //
- // );
- func XLeaveCriticalSection(t *TLS, lpCriticalSection uintptr) {
- if __ccgo_strace {
- trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
- }
- procLeaveCriticalSection.Call(lpCriticalSection, 0, 0)
- }
- func XGetOverlappedResult(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetupComm(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetCommTimeouts(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // void InitializeCriticalSection(
- //
- // LPCRITICAL_SECTION lpCriticalSection
- //
- // );
- func XInitializeCriticalSection(t *TLS, lpCriticalSection uintptr) {
- if __ccgo_strace {
- trc("t=%v lpCriticalSection=%v, (%v:)", t, lpCriticalSection, origin(2))
- }
- // InitializeCriticalSection always succeeds, even in low memory situations.
- procInitializeCriticalSection.Call(lpCriticalSection, 0, 0)
- }
- func XBuildCommDCBW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetCommState(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XEscapeCommFunction(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XGetCommModemStatus(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // BOOL MoveFileW(
- //
- // LPCWSTR lpExistingFileName,
- // LPCWSTR lpNewFileName
- //
- // );
- func XMoveFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpNewFileName=%v, (%v:)", t, lpNewFileName, origin(2))
- }
- r0, _, err := procMoveFileW.Call(lpExistingFileName, lpNewFileName, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // DWORD GetFullPathNameW(
- //
- // LPCWSTR lpFileName,
- // DWORD nBufferLength,
- // LPWSTR lpBuffer,
- // LPWSTR *lpFilePart
- //
- // );
- func XGetFullPathNameW(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpFileName, nBufferLength, lpFilePart, origin(2))
- }
- r0, _, e1 := procGetFullPathNameW.Call(lpFileName, uintptr(nBufferLength), uintptr(lpBuffer), uintptr(lpFilePart), 0, 0)
- n := uint32(r0)
- if n == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return n
- }
- // __attribute__((dllimport)) LPWSTR CharLowerW(LPWSTR lpsz);
- func XCharLowerW(tls *TLS, _lpsz uintptr) (r uintptr) {
- if __ccgo_strace {
- trc("lpsz=%+v", _lpsz)
- defer func() { trc(`XCharLowerW->%+v`, r) }()
- }
- r0, r1, err := procCharLowerW.Call(_lpsz)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return r0
- }
- // BOOL CreateDirectoryW(
- //
- // LPCWSTR lpPathName,
- // LPSECURITY_ATTRIBUTES lpSecurityAttributes
- //
- // );
- func XCreateDirectoryW(t *TLS, lpPathName, lpSecurityAttributes uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpSecurityAttributes=%v, (%v:)", t, lpSecurityAttributes, origin(2))
- }
- err := windows.CreateDirectory((*uint16)(unsafe.Pointer(lpPathName)),
- (*windows.SecurityAttributes)(unsafe.Pointer(lpSecurityAttributes)))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // BOOL SetFileAttributesW(
- //
- // LPCWSTR lpFileName,
- // DWORD dwFileAttributes
- //
- // );
- func XSetFileAttributesW(t *TLS, lpFileName uintptr, dwFileAttributes uint32) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v dwFileAttributes=%v, (%v:)", t, lpFileName, dwFileAttributes, origin(2))
- }
- err := windows.SetFileAttributes((*uint16)(unsafe.Pointer(lpFileName)), dwFileAttributes)
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // UINT GetTempFileNameW(
- //
- // LPCWSTR lpPathName,
- // LPCWSTR lpPrefixString,
- // UINT uUnique,
- // LPWSTR lpTempFileName
- //
- // );
- func XGetTempFileNameW(t *TLS, lpPathName, lpPrefixString uintptr, uUnique uint32, lpTempFileName uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpPrefixString=%v uUnique=%v lpTempFileName=%v, (%v:)", t, lpPrefixString, uUnique, lpTempFileName, origin(2))
- }
- r0, _, e1 := procGetTempFileNameW.Call(lpPathName, lpPrefixString, uintptr(uUnique), lpTempFileName, 0, 0)
- if r0 == 0 {
- t.setErrno(e1)
- }
- return uint32(r0)
- }
- // BOOL CopyFileW(
- //
- // LPCWSTR lpExistingFileName,
- // LPCWSTR lpNewFileName,
- // BOOL bFailIfExists
- //
- // );
- func XCopyFileW(t *TLS, lpExistingFileName, lpNewFileName uintptr, bFailIfExists int32) int32 {
- if __ccgo_strace {
- trc("t=%v lpNewFileName=%v bFailIfExists=%v, (%v:)", t, lpNewFileName, bFailIfExists, origin(2))
- }
- r0, _, e1 := procCopyFileW.Call(lpExistingFileName, lpNewFileName, uintptr(bFailIfExists))
- if r0 == 0 {
- t.setErrno(e1)
- }
- return int32(r0)
- }
- // BOOL DeleteFileW(
- //
- // LPCWSTR lpFileName
- //
- // );
- func XDeleteFileW(t *TLS, lpFileName uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
- }
- err := windows.DeleteFile((*uint16)(unsafe.Pointer(lpFileName)))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // BOOL RemoveDirectoryW(
- //
- // LPCWSTR lpPathName
- //
- // );
- func XRemoveDirectoryW(t *TLS, lpPathName uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpPathName=%v, (%v:)", t, lpPathName, origin(2))
- }
- err := windows.RemoveDirectory((*uint16)(unsafe.Pointer(lpPathName)))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
- func XFindFirstFileW(t *TLS, lpFileName, lpFindFileData uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpFindFileData=%v, (%v:)", t, lpFindFileData, origin(2))
- }
- r0, _, e1 := procFindFirstFileW.Call(lpFileName, lpFindFileData, 0)
- handle := windows.Handle(r0)
- if handle == windows.InvalidHandle {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return r0
- }
- // HANDLE FindFirstFileExW(
- //
- // LPCWSTR lpFileName,
- // FINDEX_INFO_LEVELS fInfoLevelId,
- // LPVOID lpFindFileData,
- // FINDEX_SEARCH_OPS fSearchOp,
- // LPVOID lpSearchFilter,
- // DWORD dwAdditionalFlags
- //
- // );
- func XFindFirstFileExW(t *TLS, lpFileName uintptr, fInfoLevelId int32, lpFindFileData uintptr, fSearchOp int32, lpSearchFilter uintptr, dwAdditionalFlags uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v fInfoLevelId=%v lpFindFileData=%v fSearchOp=%v lpSearchFilter=%v dwAdditionalFlags=%v, (%v:)", t, lpFileName, fInfoLevelId, lpFindFileData, fSearchOp, lpSearchFilter, dwAdditionalFlags, origin(2))
- }
- r0, _, e1 := procFindFirstFileExW.Call(lpFileName, uintptr(fInfoLevelId), lpFindFileData, uintptr(fSearchOp), lpSearchFilter, uintptr(dwAdditionalFlags))
- handle := windows.Handle(r0)
- if handle == windows.InvalidHandle {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return r0
- }
- // BOOL FindClose(HANDLE hFindFile);
- func XFindClose(t *TLS, hFindFile uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hFindFile=%v, (%v:)", t, hFindFile, origin(2))
- }
- r0, _, e1 := procFindClose.Call(hFindFile, 0, 0)
- if r0 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return int32(r0)
- }
- // BOOL FindNextFileW(
- //
- // HANDLE hFindFile,
- // LPWIN32_FIND_DATAW lpFindFileData
- //
- // );
- func XFindNextFileW(t *TLS, hFindFile, lpFindFileData uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFindFileData=%v, (%v:)", t, lpFindFileData, origin(2))
- }
- r0, _, e1 := procFindNextFileW.Call(hFindFile, lpFindFileData, 0)
- if r0 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return int32(r0)
- }
- // DWORD GetLogicalDriveStringsA(
- //
- // DWORD nBufferLength,
- // LPSTR lpBuffer
- //
- // );
- func XGetLogicalDriveStringsA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
- }
- r0, _, err := procGetLogicalDriveStringsA.Call(uintptr(nBufferLength), lpBuffer, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- // BOOL GetVolumeInformationA(
- //
- // LPCSTR lpRootPathName,
- // LPSTR lpVolumeNameBuffer,
- // DWORD nVolumeNameSize,
- // LPDWORD lpVolumeSerialNumber,
- // LPDWORD lpMaximumComponentLength,
- // LPDWORD lpFileSystemFlags,
- // LPSTR lpFileSystemNameBuffer,
- // DWORD nFileSystemNameSize
- //
- // );
- func XGetVolumeInformationA(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
- if __ccgo_strace {
- trc("t=%v lpVolumeNameBuffer=%v nVolumeNameSize=%v lpFileSystemNameBuffer=%v nFileSystemNameSize=%v, (%v:)", t, lpVolumeNameBuffer, nVolumeNameSize, lpFileSystemNameBuffer, nFileSystemNameSize, origin(2))
- }
- r0, _, err := procGetVolumeInformationA.Call(lpRootPathName,
- lpVolumeNameBuffer,
- uintptr(nVolumeNameSize),
- lpVolumeSerialNumber,
- lpMaximumComponentLength,
- lpFileSystemFlags,
- lpFileSystemNameBuffer,
- uintptr(nFileSystemNameSize),
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL CreateHardLinkW(
- //
- // LPCWSTR lpFileName,
- // LPCWSTR lpExistingFileName,
- // LPSECURITY_ATTRIBUTES lpSecurityAttributes
- //
- // );
- func XCreateHardLinkW(t *TLS, lpFileName, lpExistingFileName, lpSecurityAttributes uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpSecurityAttributes=%v, (%v:)", t, lpSecurityAttributes, origin(2))
- }
- r0, _, err := procCreateHardLinkW.Call(lpFileName, lpExistingFileName, lpSecurityAttributes)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL DeviceIoControl(
- //
- // HANDLE hDevice,
- // DWORD dwIoControlCode,
- // LPVOID lpInBuffer,
- // DWORD nInBufferSize,
- // LPVOID lpOutBuffer,
- // DWORD nOutBufferSize,
- // LPDWORD lpBytesReturned,
- // LPOVERLAPPED lpOverlapped
- //
- // );
- func XDeviceIoControl(t *TLS, hDevice uintptr, dwIoControlCode uint32, lpInBuffer uintptr, nInBufferSize uint32, lpOutBuffer uintptr, nOutBufferSize uint32, lpBytesReturned, lpOverlapped uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hDevice=%v dwIoControlCode=%v lpInBuffer=%v nInBufferSize=%v lpOutBuffer=%v nOutBufferSize=%v lpOverlapped=%v, (%v:)", t, hDevice, dwIoControlCode, lpInBuffer, nInBufferSize, lpOutBuffer, nOutBufferSize, lpOverlapped, origin(2))
- }
- r0, _, err := procDeviceIoControl.Call(hDevice, uintptr(dwIoControlCode), lpInBuffer,
- uintptr(nInBufferSize), lpOutBuffer, uintptr(nOutBufferSize), lpBytesReturned, lpOverlapped, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int wcsncmp(
- //
- // const wchar_t *string1,
- // const wchar_t *string2,
- // size_t count
- //
- // );
- func Xwcsncmp(t *TLS, string1, string2 uintptr, count types.Size_t) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v count=%v, (%v:)", t, string2, count, origin(2))
- }
- var s1 = goWideString(string1)
- var l1 = len(s1)
- var s2 = goWideString(string2)
- var l2 = len(s2)
- // shorter is lesser
- if l1 < l2 {
- return -1
- }
- if l2 > l1 {
- return 1
- }
- // compare at most count
- var cmpLen = count
- if types.Size_t(l1) < cmpLen {
- cmpLen = types.Size_t(l1)
- }
- return int32(strings.Compare(s1[:cmpLen], s2[:cmpLen]))
- }
- // int MultiByteToWideChar(
- //
- // UINT CodePage,
- // DWORD dwFlags,
- // _In_NLS_string_(cbMultiByte)LPCCH lpMultiByteStr,
- // int cbMultiByte,
- // LPWSTR lpWideCharStr,
- // int cchWideChar
- //
- // );
- func XMultiByteToWideChar(t *TLS, CodePage uint32, dwFlags uint32, lpMultiByteStr uintptr, cbMultiByte int32, lpWideCharStr uintptr, cchWideChar int32) int32 {
- if __ccgo_strace {
- trc("t=%v CodePage=%v dwFlags=%v lpMultiByteStr=%v cbMultiByte=%v lpWideCharStr=%v cchWideChar=%v, (%v:)", t, CodePage, dwFlags, lpMultiByteStr, cbMultiByte, lpWideCharStr, cchWideChar, origin(2))
- }
- r1, _, _ := procMultiByteToWideChar.Call(uintptr(CodePage), uintptr(dwFlags), uintptr(lpMultiByteStr),
- uintptr(cbMultiByte), uintptr(lpWideCharStr), uintptr(cchWideChar))
- return (int32(r1))
- }
- // void OutputDebugStringW(
- //
- // LPCWSTR lpOutputString
- //
- // );
- func XOutputDebugStringW(t *TLS, lpOutputString uintptr) {
- if __ccgo_strace {
- trc("t=%v lpOutputString=%v, (%v:)", t, lpOutputString, origin(2))
- }
- panic(todo(""))
- }
- func XMessageBeep(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- //====
- // long _InterlockedCompareExchange(
- //
- // long volatile * Destination,
- // long Exchange,
- // long Comparand
- //
- // );
- func X_InterlockedCompareExchange(t *TLS, Destination uintptr, Exchange, Comparand long) long {
- if __ccgo_strace {
- trc("t=%v Destination=%v Comparand=%v, (%v:)", t, Destination, Comparand, origin(2))
- }
- // The function returns the initial value of the Destination parameter.
- var v = *(*int32)(unsafe.Pointer(Destination))
- _ = atomic.CompareAndSwapInt32((*int32)(unsafe.Pointer(Destination)), Comparand, Exchange)
- return long(v)
- }
- // int rename(const char *oldpath, const char *newpath);
- func Xrename(t *TLS, oldpath, newpath uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v newpath=%v, (%v:)", t, newpath, origin(2))
- }
- panic(todo(""))
- }
- // BOOL AreFileApisANSI();
- func XAreFileApisANSI(t *TLS) int32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, _ := procAreFileApisANSI.Call(0, 0, 0)
- return int32(r0)
- }
- // HANDLE CreateFileA(
- //
- // LPCSTR lpFileName,
- // DWORD dwDesiredAccess,
- // DWORD dwShareMode,
- // LPSECURITY_ATTRIBUTES lpSecurityAttributes,
- // DWORD dwCreationDisposition,
- // DWORD dwFlagsAndAttributes,
- // HANDLE hTemplateFile
- //
- // );
- func XCreateFileA(t *TLS, lpFileName uintptr, dwDesiredAccess, dwShareMode uint32,
- lpSecurityAttributes uintptr, dwCreationDisposition, dwFlagsAndAttributes uint32, hTemplateFile uintptr) uintptr {
- r0, _, e1 := procCreateFileA.Call(lpFileName, uintptr(dwDesiredAccess), uintptr(dwShareMode), lpSecurityAttributes,
- uintptr(dwCreationDisposition), uintptr(dwFlagsAndAttributes), hTemplateFile, 0, 0)
- h := windows.Handle(r0)
- if h == windows.InvalidHandle {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return r0
- }
- return uintptr(h)
- }
- // HANDLE CreateFileMappingA(
- //
- // HANDLE hFile,
- // LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
- // DWORD flProtect,
- // DWORD dwMaximumSizeHigh,
- // DWORD dwMaximumSizeLow,
- // LPCSTR lpName
- //
- // );
- func XCreateFileMappingA(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpFileMappingAttributes=%v dwMaximumSizeLow=%v lpName=%v, (%v:)", t, lpFileMappingAttributes, dwMaximumSizeLow, lpName, origin(2))
- }
- panic(todo(""))
- }
- // HANDLE CreateFileMappingW(
- //
- // HANDLE hFile,
- // LPSECURITY_ATTRIBUTES lpFileMappingAttributes,
- // DWORD flProtect,
- // DWORD dwMaximumSizeHigh,
- // DWORD dwMaximumSizeLow,
- // LPCWSTR lpName
- //
- // );
- func XCreateFileMappingW(t *TLS, hFile, lpFileMappingAttributes uintptr, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow uint32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpFileMappingAttributes=%v dwMaximumSizeLow=%v lpName=%v, (%v:)", t, lpFileMappingAttributes, dwMaximumSizeLow, lpName, origin(2))
- }
- h, _, e1 := procCreateFileMappingW.Call(hFile, lpFileMappingAttributes, uintptr(flProtect),
- uintptr(dwMaximumSizeHigh), uintptr(dwMaximumSizeLow), lpName)
- if h == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return h
- }
- // HANDLE CreateMutexW(
- //
- // LPSECURITY_ATTRIBUTES lpMutexAttributes,
- // BOOL bInitialOwner,
- // LPCWSTR lpName
- //
- // );
- func XCreateMutexW(t *TLS, lpMutexAttributes uintptr, bInitialOwner int32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpMutexAttributes=%v bInitialOwner=%v lpName=%v, (%v:)", t, lpMutexAttributes, bInitialOwner, lpName, origin(2))
- }
- panic(todo(""))
- }
- // BOOL DeleteFileA(
- //
- // LPCSTR lpFileName
- //
- // );
- func XDeleteFileA(t *TLS, lpFileName uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
- }
- panic(todo(""))
- }
- // DWORD FormatMessageA(
- //
- // DWORD dwFlags,
- // LPCVOID lpSource,
- // DWORD dwMessageId,
- // DWORD dwLanguageId,
- // LPSTR lpBuffer,
- // DWORD nSize,
- // va_list *Arguments
- //
- // );
- func XFormatMessageA(t *TLS, dwFlagsAndAttributes uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v dwFlagsAndAttributes=%v lpSource=%v dwLanguageId=%v lpBuffer=%v nSize=%v Arguments=%v, (%v:)", t, dwFlagsAndAttributes, lpSource, dwLanguageId, lpBuffer, nSize, Arguments, origin(2))
- }
- panic(todo(""))
- }
- // DWORD FormatMessageW(
- //
- // DWORD dwFlags,
- // LPCVOID lpSource,
- // DWORD dwMessageId,
- // DWORD dwLanguageId,
- // LPWSTR lpBuffer,
- // DWORD nSize,
- // va_list *Arguments
- //
- // );
- func XFormatMessageW(t *TLS, dwFlags uint32, lpSource uintptr, dwMessageId, dwLanguageId uint32, lpBuffer uintptr, nSize uint32, Arguments uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v dwFlags=%v lpSource=%v dwLanguageId=%v lpBuffer=%v nSize=%v Arguments=%v, (%v:)", t, dwFlags, lpSource, dwLanguageId, lpBuffer, nSize, Arguments, origin(2))
- }
- r0, _, e1 := procFormatMessageW.Call(uintptr(dwFlags), lpSource, uintptr(dwMessageId), uintptr(dwLanguageId),
- lpBuffer, uintptr(nSize), Arguments, 0, 0)
- n := uint32(r0)
- if n == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return n
- }
- // BOOL FreeLibrary(HMODULE hLibModule);
- func XFreeLibrary(t *TLS, hLibModule uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hLibModule=%v, (%v:)", t, hLibModule, origin(2))
- }
- panic(todo(""))
- }
- // DWORD GetCurrentProcessId();
- func XGetCurrentProcessId(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, _ := procGetCurrentProcessId.Call(0, 0, 0)
- pid := uint32(r0)
- return pid
- }
- // BOOL GetDiskFreeSpaceA(
- //
- // LPCSTR lpRootPathName,
- // LPDWORD lpSectorsPerCluster,
- // LPDWORD lpBytesPerSector,
- // LPDWORD lpNumberOfFreeClusters,
- // LPDWORD lpTotalNumberOfClusters
- //
- // );
- func XGetDiskFreeSpaceA(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpTotalNumberOfClusters=%v, (%v:)", t, lpTotalNumberOfClusters, origin(2))
- }
- panic(todo(""))
- }
- // BOOL GetDiskFreeSpaceW(
- //
- // LPCWSTR lpRootPathName,
- // LPDWORD lpSectorsPerCluster,
- // LPDWORD lpBytesPerSector,
- // LPDWORD lpNumberOfFreeClusters,
- // LPDWORD lpTotalNumberOfClusters
- //
- // );
- func XGetDiskFreeSpaceW(t *TLS, lpRootPathName, lpSectorsPerCluster, lpBytesPerSector, lpNumberOfFreeClusters, lpTotalNumberOfClusters uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpTotalNumberOfClusters=%v, (%v:)", t, lpTotalNumberOfClusters, origin(2))
- }
- panic(todo(""))
- }
- // DWORD GetFileAttributesA(
- //
- // LPCSTR lpFileName
- //
- // );
- func XGetFileAttributesA(t *TLS, lpFileName uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v, (%v:)", t, lpFileName, origin(2))
- }
- r0, _, err := procGetFileAttributesA.Call(lpFileName, 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- // BOOL GetFileAttributesExW(
- //
- // LPCWSTR lpFileName,
- // GET_FILEEX_INFO_LEVELS fInfoLevelId,
- // LPVOID lpFileInformation
- //
- // );
- func XGetFileAttributesExW(t *TLS, lpFileName uintptr, fInfoLevelId int32, lpFileInformation uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v fInfoLevelId=%v lpFileInformation=%v, (%v:)", t, lpFileName, fInfoLevelId, lpFileInformation, origin(2))
- }
- r1, _, e1 := procGetFileAttributesExW.Call(lpFileName, uintptr(fInfoLevelId), lpFileInformation)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // DWORD GetFileSize(
- //
- // HANDLE hFile,
- // LPDWORD lpFileSizeHigh
- //
- // );
- func XGetFileSize(t *TLS, hFile, lpFileSizeHigh uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileSizeHigh=%v, (%v:)", t, lpFileSizeHigh, origin(2))
- }
- r1, _, e1 := procGetFileSize.Call(hFile, lpFileSizeHigh, 0)
- if r1 == math.MaxUint32 {
- if lpFileSizeHigh == 0 {
- // If the function fails and lpFileSizeHigh is NULL, the return value is INVALID_FILE_SIZE.
- // Note that if the return value is INVALID_FILE_SIZE (0xffffffff),
- // an application must call GetLastError to determine whether the function has succeeded or failed.
- t.setErrno(e1)
- return math.MaxUint32
- } else {
- // If the function fails and lpFileSizeHigh is non-NULL, the return value is INVALID_FILE_SIZE
- // and GetLastError will return a value other than NO_ERROR.
- t.setErrno(e1)
- return math.MaxUint32
- }
- }
- return uint32(r1)
- }
- // DWORD GetFullPathNameA(
- //
- // LPCSTR lpFileName,
- // DWORD nBufferLength,
- // LPSTR lpBuffer,
- // LPSTR *lpFilePart
- //
- // );
- func XGetFullPathNameA(t *TLS, lpFileName uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpFileName, nBufferLength, lpFilePart, origin(2))
- }
- panic(todo(""))
- }
- // FARPROC GetProcAddress(HMODULE hModule, LPCSTR lpProcName);
- func XGetProcAddress(t *TLS, hModule, lpProcName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpProcName=%v, (%v:)", t, lpProcName, origin(2))
- }
- return 0
- //panic(todo(GoString(lpProcName)))
- //
- //r0, _, err := procGetProcAddress.Call(hModule, lpProcName, 0)
- //if r0 == 0 {
- // t.setErrno(err)
- //}
- //return r0
- }
- // NTSYSAPI NTSTATUS RtlGetVersion( // ntdll.dll
- //
- // PRTL_OSVERSIONINFOW lpVersionInformation
- //
- // );
- func XRtlGetVersion(t *TLS, lpVersionInformation uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
- }
- panic(todo(""))
- }
- // void GetSystemInfo(
- //
- // LPSYSTEM_INFO lpSystemInfo
- //
- // );
- func XGetSystemInfo(t *TLS, lpSystemInfo uintptr) {
- if __ccgo_strace {
- trc("t=%v lpSystemInfo=%v, (%v:)", t, lpSystemInfo, origin(2))
- }
- procGetSystemInfo.Call(lpSystemInfo, 0, 0)
- }
- // void GetSystemTime(LPSYSTEMTIME lpSystemTime);
- func XGetSystemTime(t *TLS, lpSystemTime uintptr) {
- if __ccgo_strace {
- trc("t=%v lpSystemTime=%v, (%v:)", t, lpSystemTime, origin(2))
- }
- procGetSystemTime.Call(lpSystemTime, 0, 0)
- }
- // void GetSystemTimeAsFileTime(
- //
- // LPFILETIME lpSystemTimeAsFileTime
- //
- // );
- func XGetSystemTimeAsFileTime(t *TLS, lpSystemTimeAsFileTime uintptr) {
- if __ccgo_strace {
- trc("t=%v lpSystemTimeAsFileTime=%v, (%v:)", t, lpSystemTimeAsFileTime, origin(2))
- }
- procGetSystemTimeAsFileTime.Call(lpSystemTimeAsFileTime, 0, 0)
- }
- // DWORD GetTempPathA(
- //
- // DWORD nBufferLength,
- // LPSTR lpBuffer
- //
- // );
- func XGetTempPathA(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
- }
- panic(todo(""))
- }
- // DWORD GetTempPathW(
- //
- // DWORD nBufferLength,
- // LPWSTR lpBuffer
- //
- // );
- func XGetTempPathW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
- }
- rv, err := windows.GetTempPath(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
- if err != nil {
- t.setErrno(err)
- }
- return rv
- }
- // DWORD GetTickCount();
- func XGetTickCount(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, _ := procGetTickCount.Call(0, 0, 0)
- return uint32(r0)
- }
- // BOOL GetVersionExA(
- //
- // LPOSVERSIONINFOA lpVersionInformation
- //
- // );
- func XGetVersionExA(t *TLS, lpVersionInformation uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpVersionInformation=%v, (%v:)", t, lpVersionInformation, origin(2))
- }
- r0, _, err := procGetVersionExA.Call(lpVersionInformation, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // HANDLE HeapCreate(
- //
- // DWORD flOptions,
- // SIZE_T dwInitialSize,
- // SIZE_T dwMaximumSize
- //
- // );
- func XHeapCreate(t *TLS, flOptions uint32, dwInitialSize, dwMaximumSize types.Size_t) uintptr {
- if __ccgo_strace {
- trc("t=%v flOptions=%v dwMaximumSize=%v, (%v:)", t, flOptions, dwMaximumSize, origin(2))
- }
- panic(todo(""))
- }
- // BOOL HeapDestroy(
- //
- // HANDLE hHeap
- //
- // );
- func XHeapDestroy(t *TLS, hHeap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hHeap=%v, (%v:)", t, hHeap, origin(2))
- }
- panic(todo(""))
- }
- // LPVOID HeapReAlloc(
- //
- // HANDLE hHeap,
- // DWORD dwFlags,
- // _Frees_ptr_opt_ LPVOID lpMem,
- // SIZE_T dwBytes
- //
- // );
- func XHeapReAlloc(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr, dwBytes types.Size_t) uintptr {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v lpMem=%v dwBytes=%v, (%v:)", t, hHeap, dwFlags, lpMem, dwBytes, origin(2))
- }
- panic(todo(""))
- }
- // SIZE_T HeapSize(
- //
- // HANDLE hHeap,
- // DWORD dwFlags,
- // LPCVOID lpMem
- //
- // );
- func XHeapSize(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) types.Size_t {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
- }
- panic(todo(""))
- }
- // BOOL HeapValidate(
- //
- // HANDLE hHeap,
- // DWORD dwFlags,
- // LPCVOID lpMem
- //
- // );
- func XHeapValidate(t *TLS, hHeap uintptr, dwFlags uint32, lpMem uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v lpMem=%v, (%v:)", t, hHeap, dwFlags, lpMem, origin(2))
- }
- panic(todo(""))
- }
- // SIZE_T HeapCompact(
- //
- // HANDLE hHeap,
- // DWORD dwFlags
- //
- // );
- func XHeapCompact(t *TLS, hHeap uintptr, dwFlags uint32) types.Size_t {
- if __ccgo_strace {
- trc("t=%v hHeap=%v dwFlags=%v, (%v:)", t, hHeap, dwFlags, origin(2))
- }
- panic(todo(""))
- }
- // HMODULE LoadLibraryA(LPCSTR lpLibFileName);
- func XLoadLibraryA(t *TLS, lpLibFileName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpLibFileName=%v, (%v:)", t, lpLibFileName, origin(2))
- }
- panic(todo(""))
- }
- // HMODULE LoadLibraryW(
- //
- // LPCWSTR lpLibFileName
- //
- // );
- func XLoadLibraryW(t *TLS, lpLibFileName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpLibFileName=%v, (%v:)", t, lpLibFileName, origin(2))
- }
- panic(todo(""))
- }
- // HLOCAL LocalFree(
- //
- // HLOCAL hMem
- //
- // );
- func XLocalFree(t *TLS, hMem uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v hMem=%v, (%v:)", t, hMem, origin(2))
- }
- h, err := windows.LocalFree(windows.Handle(hMem))
- if h != 0 {
- if err != nil {
- t.setErrno(err)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return uintptr(h)
- }
- return 0
- }
- // BOOL LockFile(
- //
- // HANDLE hFile,
- // DWORD dwFileOffsetLow,
- // DWORD dwFileOffsetHigh,
- // DWORD nNumberOfBytesToLockLow,
- // DWORD nNumberOfBytesToLockHigh
- //
- // );
- func XLockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v nNumberOfBytesToLockHigh=%v, (%v:)", t, hFile, nNumberOfBytesToLockHigh, origin(2))
- }
- r1, _, e1 := procLockFile.Call(hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // BOOL LockFileEx(
- //
- // HANDLE hFile,
- // DWORD dwFlags,
- // DWORD dwReserved,
- // DWORD nNumberOfBytesToLockLow,
- // DWORD nNumberOfBytesToLockHigh,
- // LPOVERLAPPED lpOverlapped
- //
- // );
- func XLockFileEx(t *TLS, hFile uintptr, dwFlags, dwReserved, nNumberOfBytesToLockLow, nNumberOfBytesToLockHigh uint32, lpOverlapped uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v nNumberOfBytesToLockHigh=%v lpOverlapped=%v, (%v:)", t, hFile, nNumberOfBytesToLockHigh, lpOverlapped, origin(2))
- }
- r1, _, e1 := procLockFileEx.Call(hFile, uintptr(dwFlags), uintptr(dwReserved), uintptr(nNumberOfBytesToLockLow), uintptr(nNumberOfBytesToLockHigh), lpOverlapped)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // LPVOID MapViewOfFile(
- //
- // HANDLE hFileMappingObject,
- // DWORD dwDesiredAccess,
- // DWORD dwFileOffsetHigh,
- // DWORD dwFileOffsetLow,
- // SIZE_T dwNumberOfBytesToMap
- //
- // );
- func XMapViewOfFile(t *TLS, hFileMappingObject uintptr, dwDesiredAccess, dwFileOffsetHigh, dwFileOffsetLow uint32, dwNumberOfBytesToMap types.Size_t) uintptr {
- if __ccgo_strace {
- trc("t=%v hFileMappingObject=%v dwFileOffsetLow=%v dwNumberOfBytesToMap=%v, (%v:)", t, hFileMappingObject, dwFileOffsetLow, dwNumberOfBytesToMap, origin(2))
- }
- h, _, e1 := procMapViewOfFile.Call(hFileMappingObject, uintptr(dwDesiredAccess),
- uintptr(dwFileOffsetHigh), uintptr(dwFileOffsetLow), uintptr(dwNumberOfBytesToMap), 0)
- if h == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return h
- }
- // BOOL QueryPerformanceCounter(
- //
- // LARGE_INTEGER *lpPerformanceCount
- //
- // );
- func XQueryPerformanceCounter(t *TLS, lpPerformanceCount uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpPerformanceCount=%v, (%v:)", t, lpPerformanceCount, origin(2))
- }
- r0, _, _ := procQueryPerformanceCounter.Call(lpPerformanceCount, 0, 0)
- return int32(r0)
- }
- // void Sleep(
- //
- // DWORD dwMilliseconds
- //
- // );
- func XSleep(t *TLS, dwMilliseconds uint32) {
- if __ccgo_strace {
- trc("t=%v dwMilliseconds=%v, (%v:)", t, dwMilliseconds, origin(2))
- }
- gotime.Sleep(gotime.Duration(dwMilliseconds) * gotime.Millisecond)
- }
- // BOOL SystemTimeToFileTime(const SYSTEMTIME *lpSystemTime, LPFILETIME lpFileTime);
- func XSystemTimeToFileTime(t *TLS, lpSystemTime, lpFileTime uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileTime=%v, (%v:)", t, lpFileTime, origin(2))
- }
- r0, _, _ := procSystemTimeToFileTime.Call(lpSystemTime, lpFileTime, 0)
- return int32(r0)
- }
- // BOOL UnlockFile(
- //
- // HANDLE hFile,
- // DWORD dwFileOffsetLow,
- // DWORD dwFileOffsetHigh,
- // DWORD nNumberOfBytesToUnlockLow,
- // DWORD nNumberOfBytesToUnlockHigh
- //
- // );
- func XUnlockFile(t *TLS, hFile uintptr, dwFileOffsetLow, dwFileOffsetHigh, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v nNumberOfBytesToUnlockHigh=%v, (%v:)", t, hFile, nNumberOfBytesToUnlockHigh, origin(2))
- }
- r1, _, e1 := procUnlockFile.Call(hFile, uintptr(dwFileOffsetLow), uintptr(dwFileOffsetHigh), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // BOOL UnlockFileEx(
- //
- // HANDLE hFile,
- // DWORD dwReserved,
- // DWORD nNumberOfBytesToUnlockLow,
- // DWORD nNumberOfBytesToUnlockHigh,
- // LPOVERLAPPED lpOverlapped
- //
- // );
- func XUnlockFileEx(t *TLS, hFile uintptr, dwReserved, nNumberOfBytesToUnlockLow, nNumberOfBytesToUnlockHigh uint32, lpOverlapped uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hFile=%v nNumberOfBytesToUnlockHigh=%v lpOverlapped=%v, (%v:)", t, hFile, nNumberOfBytesToUnlockHigh, lpOverlapped, origin(2))
- }
- r1, _, e1 := procUnlockFileEx.Call(hFile, uintptr(dwReserved), uintptr(nNumberOfBytesToUnlockLow), uintptr(nNumberOfBytesToUnlockHigh), lpOverlapped, 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return 0
- }
- return int32(r1)
- }
- // BOOL UnmapViewOfFile(
- //
- // LPCVOID lpBaseAddress
- //
- // );
- func XUnmapViewOfFile(t *TLS, lpBaseAddress uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBaseAddress=%v, (%v:)", t, lpBaseAddress, origin(2))
- }
- err := windows.UnmapViewOfFile(lpBaseAddress)
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // int WideCharToMultiByte(
- //
- // UINT CodePage,
- // DWORD dwFlags,
- // _In_NLS_string_(cchWideChar)LPCWCH lpWideCharStr,
- // int cchWideChar,
- // LPSTR lpMultiByteStr,
- // int cbMultiByte,
- // LPCCH lpDefaultChar,
- // LPBOOL lpUsedDefaultChar
- //
- // );
- func XWideCharToMultiByte(t *TLS, CodePage uint32, dwFlags uint32, lpWideCharStr uintptr, cchWideChar int32, lpMultiByteStr uintptr, cbMultiByte int32, lpDefaultChar, lpUsedDefaultChar uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v CodePage=%v dwFlags=%v lpWideCharStr=%v cchWideChar=%v lpMultiByteStr=%v cbMultiByte=%v lpUsedDefaultChar=%v, (%v:)", t, CodePage, dwFlags, lpWideCharStr, cchWideChar, lpMultiByteStr, cbMultiByte, lpUsedDefaultChar, origin(2))
- }
- r1, _, _ := procWideCharToMultiByte.Call(uintptr(CodePage), uintptr(dwFlags), lpWideCharStr,
- uintptr(cchWideChar), lpMultiByteStr, uintptr(cbMultiByte),
- lpDefaultChar, lpUsedDefaultChar, 0)
- return (int32(r1))
- }
- // void OutputDebugStringA(
- //
- // LPCSTR lpOutputString
- //
- // )
- func XOutputDebugStringA(t *TLS, lpOutputString uintptr) {
- if __ccgo_strace {
- trc("t=%v lpOutputString=%v, (%v:)", t, lpOutputString, origin(2))
- }
- panic(todo(""))
- }
- // BOOL FlushViewOfFile(
- //
- // LPCVOID lpBaseAddress,
- // SIZE_T dwNumberOfBytesToFlush
- //
- // );
- func XFlushViewOfFile(t *TLS, lpBaseAddress uintptr, dwNumberOfBytesToFlush types.Size_t) int32 {
- if __ccgo_strace {
- trc("t=%v lpBaseAddress=%v dwNumberOfBytesToFlush=%v, (%v:)", t, lpBaseAddress, dwNumberOfBytesToFlush, origin(2))
- }
- err := windows.FlushViewOfFile(lpBaseAddress, uintptr(dwNumberOfBytesToFlush))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- type _ino_t = uint16 /* types.h:43:24 */
- type _dev_t = uint32 /* types.h:51:22 */
- type _stat64 = struct {
- Fst_dev _dev_t
- Fst_ino _ino_t
- Fst_mode uint16
- Fst_nlink int16
- Fst_uid int16
- Fst_gid int16
- _ [2]byte
- Fst_rdev _dev_t
- _ [4]byte
- Fst_size int64
- Fst_atime int64
- Fst_mtime int64
- Fst_ctime int64
- } /* _mingw_stat64.h:83:3 */
- var (
- Windows_Tick int64 = 10000000
- SecToUnixEpoch int64 = 11644473600
- )
- func WindowsTickToUnixSeconds(windowsTicks int64) int64 {
- return (windowsTicks/Windows_Tick - SecToUnixEpoch)
- }
- // int _stat64(const char *path, struct __stat64 *buffer);
- func X_stat64(t *TLS, path, buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v buffer=%v, (%v:)", t, buffer, origin(2))
- }
- var fa windows.Win32FileAttributeData
- r1, _, e1 := procGetFileAttributesExA.Call(path, windows.GetFileExInfoStandard, (uintptr)(unsafe.Pointer(&fa)))
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- return -1
- }
- var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
- var accessTime = int64(fa.LastAccessTime.HighDateTime)<<32 + int64(fa.LastAccessTime.LowDateTime)
- bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
- var modTime = int64(fa.LastWriteTime.HighDateTime)<<32 + int64(fa.LastWriteTime.LowDateTime)
- bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
- var crTime = int64(fa.CreationTime.HighDateTime)<<32 + int64(fa.CreationTime.LowDateTime)
- bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
- var fSz = int64(fa.FileSizeHigh)<<32 + int64(fa.FileSizeLow)
- bStat64.Fst_size = fSz
- bStat64.Fst_mode = WindowsAttrbiutesToStat(fa.FileAttributes)
- return 0
- }
- func WindowsAttrbiutesToStat(fa uint32) uint16 {
- var src_mode = fa & 0xff
- var st_mode uint16
- if (src_mode & windows.FILE_ATTRIBUTE_DIRECTORY) != 0 {
- st_mode = windows.S_IFDIR
- } else {
- st_mode = windows.S_IFREG
- }
- if src_mode&windows.FILE_ATTRIBUTE_READONLY != 0 {
- st_mode = st_mode | windows.S_IRUSR
- } else {
- st_mode = st_mode | windows.S_IRUSR | windows.S_IWUSR
- }
- // fill group fields
- st_mode = st_mode | (st_mode&0x700)>>3
- st_mode = st_mode | (st_mode&0x700)>>6
- return st_mode
- }
- // int _chsize(
- //
- // int fd,
- // long size
- //
- // );
- func X_chsize(t *TLS, fd int32, size long) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v size=%v, (%v:)", t, fd, size, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(EBADF)
- return -1
- }
- err := windows.Ftruncate(f.Handle, int64(size))
- if err != nil {
- t.setErrno(err)
- return -1
- }
- return 0
- }
- // int _snprintf(char *str, size_t size, const char *format, ...);
- func X_snprintf(t *TLS, str uintptr, size types.Size_t, format, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v str=%v size=%v args=%v, (%v:)", t, str, size, args, origin(2))
- }
- return Xsnprintf(t, str, size, format, args)
- }
- const wErr_ERROR_INSUFFICIENT_BUFFER = 122
- func win32FindDataToFileInfo(t *TLS, fdata *stat.X_finddata64i32_t, wfd *windows.Win32finddata) int32 {
- // t64 = 64-bit time value
- var accessTime = int64(wfd.LastAccessTime.HighDateTime)<<32 + int64(wfd.LastAccessTime.LowDateTime)
- fdata.Ftime_access = WindowsTickToUnixSeconds(accessTime)
- var modTime = int64(wfd.LastWriteTime.HighDateTime)<<32 + int64(wfd.LastWriteTime.LowDateTime)
- fdata.Ftime_write = WindowsTickToUnixSeconds(modTime)
- var crTime = int64(wfd.CreationTime.HighDateTime)<<32 + int64(wfd.CreationTime.LowDateTime)
- fdata.Ftime_create = WindowsTickToUnixSeconds(crTime)
- // i32 = 32-bit size
- fdata.Fsize = wfd.FileSizeLow
- fdata.Fattrib = wfd.FileAttributes
- var cp = XGetConsoleCP(t)
- var wcFn = (uintptr)(unsafe.Pointer(&wfd.FileName[0]))
- var mbcsFn = (uintptr)(unsafe.Pointer(&fdata.Fname[0]))
- rv := XWideCharToMultiByte(t, cp, 0, wcFn, -1, mbcsFn, 260, 0, 0)
- if rv == wErr_ERROR_INSUFFICIENT_BUFFER {
- t.setErrno(errno.ENOMEM)
- return -1
- }
- return 0
- }
- // intptr_t _findfirst64i32(
- //
- // const char *filespec,
- // struct _finddata64i32_t *fileinfo
- //
- // );
- func X_findfirst64i32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
- if __ccgo_strace {
- trc("t=%v fileinfo=%v, (%v:)", t, fileinfo, origin(2))
- }
- // Note: this is the 'narrow' character findfirst -- expects output
- // as mbcs -- conversion below -- via ToFileInfo
- var gsFileSpec = GoString(filespec)
- namep, err := windows.UTF16PtrFromString(gsFileSpec)
- if err != nil {
- t.setErrno(err)
- return types.Intptr_t(-1)
- }
- var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
- var wfd windows.Win32finddata
- h, err := windows.FindFirstFile((*uint16)(unsafe.Pointer(namep)), &wfd)
- if err != nil {
- t.setErrno(err)
- return types.Intptr_t(-1)
- }
- rv := win32FindDataToFileInfo(t, fdata, &wfd)
- if rv != 0 {
- if h != 0 {
- windows.FindClose(h)
- }
- return types.Intptr_t(-1)
- }
- return types.Intptr_t(h)
- }
- // int _findnext64i32(
- //
- // intptr_t handle,
- // struct _finddata64i32_t *fileinfo
- //
- // );
- func X_findnext64i32(t *TLS, handle types.Intptr_t, fileinfo uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v handle=%v fileinfo=%v, (%v:)", t, handle, fileinfo, origin(2))
- }
- var fdata = (*stat.X_finddata64i32_t)(unsafe.Pointer(fileinfo))
- var wfd windows.Win32finddata
- err := windows.FindNextFile(windows.Handle(handle), &wfd)
- if err != nil {
- t.setErrno(err)
- return -1
- }
- rv := win32FindDataToFileInfo(t, fdata, &wfd)
- if rv != 0 {
- return -1
- }
- return 0
- }
- // int _findclose(
- //
- // intptr_t handle
- //
- // );
- func X_findclose(t *TLS, handle types.Intptr_t) int32 {
- if __ccgo_strace {
- trc("t=%v handle=%v, (%v:)", t, handle, origin(2))
- }
- err := windows.FindClose(windows.Handle(handle))
- if err != nil {
- t.setErrno(err)
- return -1
- }
- return 0
- }
- // DWORD GetEnvironmentVariableA(
- //
- // LPCSTR lpName,
- // LPSTR lpBuffer,
- // DWORD nSize
- //
- // );
- func XGetEnvironmentVariableA(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nSize=%v, (%v:)", t, lpBuffer, nSize, origin(2))
- }
- r0, _, e1 := procGetEnvironmentVariableA.Call(lpName, lpBuffer, uintptr(nSize))
- n := uint32(r0)
- if n == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return n
- }
- // int _fstat64(
- //
- // int fd,
- // struct __stat64 *buffer
- //
- // );
- func X_fstat64(t *TLS, fd int32, buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v buffer=%v, (%v:)", t, fd, buffer, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(EBADF)
- return -1
- }
- var d windows.ByHandleFileInformation
- err := windows.GetFileInformationByHandle(f.Handle, &d)
- if err != nil {
- t.setErrno(EBADF)
- return -1
- }
- var bStat64 = (*_stat64)(unsafe.Pointer(buffer))
- var accessTime = int64(d.LastAccessTime.HighDateTime)<<32 + int64(d.LastAccessTime.LowDateTime)
- bStat64.Fst_atime = WindowsTickToUnixSeconds(accessTime)
- var modTime = int64(d.LastWriteTime.HighDateTime)<<32 + int64(d.LastWriteTime.LowDateTime)
- bStat64.Fst_mtime = WindowsTickToUnixSeconds(modTime)
- var crTime = int64(d.CreationTime.HighDateTime)<<32 + int64(d.CreationTime.LowDateTime)
- bStat64.Fst_ctime = WindowsTickToUnixSeconds(crTime)
- var fSz = int64(d.FileSizeHigh)<<32 + int64(d.FileSizeLow)
- bStat64.Fst_size = fSz
- bStat64.Fst_mode = WindowsAttrbiutesToStat(d.FileAttributes)
- return 0
- }
- // HANDLE CreateEventA(
- //
- // LPSECURITY_ATTRIBUTES lpEventAttributes,
- // BOOL bManualReset,
- // BOOL bInitialState,
- // LPCSTR lpName
- //
- // );
- func XCreateEventA(t *TLS, lpEventAttributes uintptr, bManualReset, bInitialState int32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpEventAttributes=%v bInitialState=%v lpName=%v, (%v:)", t, lpEventAttributes, bInitialState, lpName, origin(2))
- }
- r0, _, err := procCreateEventA.Call(lpEventAttributes, uintptr(bManualReset),
- uintptr(bInitialState), lpName, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // BOOL WINAPI CancelSynchronousIo(
- //
- // _In_ HANDLE hThread
- //
- // );
- func XCancelSynchronousIo(t *TLS, hThread uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hThread=%v, (%v:)", t, hThread, origin(2))
- }
- panic(todo(""))
- }
- func X_endthreadex(t *TLS, _ ...interface{}) {
- // NOOP
- }
- // The calling convention for beginthread is cdecl -- but in this
- // case we're just intercepting it and sending it through CreateThread which expects stdcall
- // and gets that via the go callback. This is safe because the thread is calling into go
- // not a cdecl function which would expect the stack setup of cdecl.
- func X_beginthread(t *TLS, procAddr uintptr, stack_sz uint32, args uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v procAddr=%v stack_sz=%v args=%v, (%v:)", t, procAddr, stack_sz, args, origin(2))
- }
- f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
- var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
- tAdp.token = addObject(&tAdp)
- r0, _, err := procCreateThread.Call(0, uintptr(stack_sz),
- threadCallback, tAdp.token, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // uintptr_t _beginthreadex( // NATIVE CODE
- //
- // void *security,
- // unsigned stack_size,
- // unsigned ( __stdcall *start_address )( void * ),
- // void *arglist,
- // unsigned initflag,
- // unsigned *thrdaddr
- //
- // );
- func X_beginthreadex(t *TLS, _ uintptr, stack_sz uint32, procAddr uintptr, args uintptr, initf uint32, thAddr uintptr) int32 {
- f := (*struct{ f func(*TLS, uintptr) uint32 })(unsafe.Pointer(&struct{ uintptr }{procAddr})).f
- var tAdp = ThreadAdapter{threadFunc: f, tls: NewTLS(), param: args}
- tAdp.token = addObject(&tAdp)
- r0, _, err := procCreateThread.Call(0, uintptr(stack_sz),
- threadCallback, tAdp.token, uintptr(initf), thAddr)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // DWORD GetCurrentThreadId();
- func XGetCurrentThreadId(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, _ := procGetCurrentThreadId.Call(0, 0, 0)
- return uint32(r0)
- //return uint32(t.ID)
- }
- // BOOL GetExitCodeThread(
- //
- // HANDLE hThread,
- // LPDWORD lpExitCode
- //
- // );
- func XGetExitCodeThread(t *TLS, hThread, lpExitCode uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpExitCode=%v, (%v:)", t, lpExitCode, origin(2))
- }
- r0, _, _ := procGetExitCodeThread.Call(hThread, lpExitCode, 0)
- return int32(r0)
- }
- // DWORD WaitForSingleObjectEx(
- //
- // HANDLE hHandle,
- // DWORD dwMilliseconds,
- // BOOL bAlertable
- //
- // );
- func XWaitForSingleObjectEx(t *TLS, hHandle uintptr, dwMilliseconds uint32, bAlertable int32) uint32 {
- if __ccgo_strace {
- trc("t=%v hHandle=%v dwMilliseconds=%v bAlertable=%v, (%v:)", t, hHandle, dwMilliseconds, bAlertable, origin(2))
- }
- rv, _, _ := procWaitForSingleObjectEx.Call(hHandle, uintptr(dwMilliseconds), uintptr(bAlertable))
- return uint32(rv)
- }
- // DWORD MsgWaitForMultipleObjectsEx(
- //
- // DWORD nCount,
- // const HANDLE *pHandles,
- // DWORD dwMilliseconds,
- // DWORD dwWakeMask,
- // DWORD dwFlags
- //
- // );
- func XMsgWaitForMultipleObjectsEx(t *TLS, nCount uint32, pHandles uintptr, dwMilliseconds, dwWakeMask, dwFlags uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v nCount=%v pHandles=%v dwFlags=%v, (%v:)", t, nCount, pHandles, dwFlags, origin(2))
- }
- r0, _, err := procMsgWaitForMultipleObjectsEx.Call(uintptr(nCount),
- pHandles,
- uintptr(dwMilliseconds),
- uintptr(dwWakeMask),
- uintptr(dwFlags),
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- func XMessageBoxW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // DWORD GetModuleFileNameW(
- //
- // HMODULE hModule,
- // LPWSTR lpFileName,
- // DWORD nSize
- //
- // );
- func XGetModuleFileNameW(t *TLS, hModule, lpFileName uintptr, nSize uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v nSize=%v, (%v:)", t, lpFileName, nSize, origin(2))
- }
- r0, _, err := procGetModuleFileNameW.Call(hModule, lpFileName, uintptr(nSize))
- if r0 == 0 {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- // NET_API_STATUS NET_API_FUNCTION NetGetDCName(
- //
- // LPCWSTR ServerName,
- // LPCWSTR DomainName,
- // LPBYTE *Buffer
- //
- // );
- func XNetGetDCName(t *TLS, ServerName, DomainName, Buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v Buffer=%v, (%v:)", t, Buffer, origin(2))
- }
- r0, _, err := procNetGetDCName.Call(ServerName, DomainName, Buffer)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // NET_API_STATUS NET_API_FUNCTION NetUserGetInfo(
- //
- // LPCWSTR servername,
- // LPCWSTR username,
- // DWORD level,
- // LPBYTE *bufptr
- //
- // );
- func XNetUserGetInfo(t *TLS, servername, username uintptr, level uint32, bufptr uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v username=%v level=%v bufptr=%v, (%v:)", t, username, level, bufptr, origin(2))
- }
- r0, _, err := procNetUserGetInfo.Call(servername,
- username,
- uintptr(level),
- bufptr,
- 0,
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return uint32(r0)
- }
- func XlstrlenW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // USERENVAPI BOOL GetProfilesDirectoryW(
- //
- // [out] LPWSTR lpProfileDir,
- // [in, out] LPDWORD lpcchSize
- //
- // );
- func XGetProfilesDirectoryW(t *TLS, lpProfileDir, lpcchSize uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpcchSize=%v, (%v:)", t, lpcchSize, origin(2))
- }
- r0, _, err := procGetProfilesDirectoryW.Call(lpProfileDir, lpcchSize, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func XNetApiBufferFree(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // DWORD GetPrivateProfileStringA(
- //
- // LPCSTR lpAppName,
- // LPCSTR lpKeyName,
- // LPCSTR lpDefault,
- // LPSTR lpReturnedString,
- // DWORD nSize,
- // LPCSTR lpFileName
- //
- // );
- func XGetPrivateProfileStringA(t *TLS, lpAppName, lpKeyName, lpDefault, lpReturnedString uintptr, nSize uint32, lpFileName uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v lpReturnedString=%v nSize=%v lpFileName=%v, (%v:)", t, lpReturnedString, nSize, lpFileName, origin(2))
- }
- r0, _, err := procGetPrivateProfileStringA.Call(lpAppName,
- lpKeyName,
- lpDefault,
- lpReturnedString,
- uintptr(nSize),
- lpFileName,
- )
- if err != windows.NOERROR {
- t.setErrno(0x02)
- }
- return uint32(r0)
- }
- func XGetWindowsDirectoryA(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // BOOL GetFileSecurityW(
- //
- // LPCSTR lpFileName,
- // SECURITY_INFORMATION RequestedInformation,
- // PSECURITY_DESCRIPTOR pSecurityDescriptor,
- // DWORD nLength,
- // LPDWORD lpnLengthNeeded
- //
- // );
- func XGetFileSecurityW(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v RequestedInformation=%v pSecurityDescriptor=%v nLength=%v lpnLengthNeeded=%v, (%v:)", t, lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded, origin(2))
- }
- r0, _, err := procGetFileSecurityW.Call(lpFileName, uintptr(RequestedInformation), pSecurityDescriptor, uintptr(nLength), lpnLengthNeeded, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL GetSecurityDescriptorOwner(
- //
- // PSECURITY_DESCRIPTOR pSecurityDescriptor,
- // PSID *pOwner,
- // LPBOOL lpbOwnerDefaulted
- //
- // );
- func XGetSecurityDescriptorOwner(t *TLS, pSecurityDescriptor, pOwner, lpbOwnerDefaulted uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpbOwnerDefaulted=%v, (%v:)", t, lpbOwnerDefaulted, origin(2))
- }
- r0, _, err := procGetSecurityDescriptorOwner.Call(pSecurityDescriptor, pOwner, lpbOwnerDefaulted)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // PSID_IDENTIFIER_AUTHORITY GetSidIdentifierAuthority(
- //
- // PSID pSid
- //
- // );
- func XGetSidIdentifierAuthority(t *TLS, pSid uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v pSid=%v, (%v:)", t, pSid, origin(2))
- }
- r0, _, err := procGetSidIdentifierAuthority.Call(pSid, 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // BOOL ImpersonateSelf(
- //
- // SECURITY_IMPERSONATION_LEVEL ImpersonationLevel
- //
- // );
- func XImpersonateSelf(t *TLS, ImpersonationLevel int32) int32 {
- if __ccgo_strace {
- trc("t=%v ImpersonationLevel=%v, (%v:)", t, ImpersonationLevel, origin(2))
- }
- r0, _, err := procImpersonateSelf.Call(uintptr(ImpersonationLevel), 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL OpenThreadToken(
- //
- // HANDLE ThreadHandle,
- // DWORD DesiredAccess,
- // BOOL OpenAsSelf,
- // PHANDLE TokenHandle
- //
- // );
- func XOpenThreadToken(t *TLS, ThreadHandle uintptr, DesiredAccess uint32, OpenAsSelf int32, TokenHandle uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ThreadHandle=%v DesiredAccess=%v OpenAsSelf=%v TokenHandle=%v, (%v:)", t, ThreadHandle, DesiredAccess, OpenAsSelf, TokenHandle, origin(2))
- }
- r0, _, err := procOpenThreadToken.Call(ThreadHandle, uintptr(DesiredAccess), uintptr(OpenAsSelf), TokenHandle, 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // HANDLE GetCurrentThread();
- func XGetCurrentThread(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, err := procGetCurrentThread.Call(0, 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // BOOL RevertToSelf();
- func XRevertToSelf(t *TLS) int32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, err := procRevertToSelf.Call(0, 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL AccessCheck(
- //
- // PSECURITY_DESCRIPTOR pSecurityDescriptor,
- // HANDLE ClientToken,
- // DWORD DesiredAccess,
- // PGENERIC_MAPPING GenericMapping,
- // PPRIVILEGE_SET PrivilegeSet,
- // LPDWORD PrivilegeSetLength,
- // LPDWORD GrantedAccess,
- // LPBOOL AccessStatus
- //
- // );
- func XAccessCheck(t *TLS, pSecurityDescriptor, ClientToken uintptr, DesiredAccess uint32, GenericMapping, PrivilegeSet, PrivilegeSetLength, GrantedAccess, AccessStatus uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ClientToken=%v DesiredAccess=%v AccessStatus=%v, (%v:)", t, ClientToken, DesiredAccess, AccessStatus, origin(2))
- }
- r0, _, err := procAccessCheck.Call(pSecurityDescriptor,
- ClientToken,
- uintptr(DesiredAccess),
- GenericMapping,
- PrivilegeSet,
- PrivilegeSetLength,
- GrantedAccess,
- AccessStatus,
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int _wcsicmp(
- //
- // const wchar_t *string1,
- // const wchar_t *string2
- //
- // );
- func Xwcsicmp(t *TLS, string1, string2 uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
- }
- var s1 = strings.ToLower(goWideString(string1))
- var s2 = strings.ToLower(goWideString(string2))
- return int32(strings.Compare(s1, s2))
- }
- // BOOL SetCurrentDirectoryW(
- //
- // LPCTSTR lpPathName
- //
- // );
- func XSetCurrentDirectoryW(t *TLS, lpPathName uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpPathName=%v, (%v:)", t, lpPathName, origin(2))
- }
- err := windows.SetCurrentDirectory((*uint16)(unsafe.Pointer(lpPathName)))
- if err != nil {
- t.setErrno(err)
- return 0
- }
- return 1
- }
- // DWORD GetCurrentDirectory(
- //
- // DWORD nBufferLength,
- // LPWTSTR lpBuffer
- //
- // );
- func XGetCurrentDirectoryW(t *TLS, nBufferLength uint32, lpBuffer uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v nBufferLength=%v lpBuffer=%v, (%v:)", t, nBufferLength, lpBuffer, origin(2))
- }
- n, err := windows.GetCurrentDirectory(nBufferLength, (*uint16)(unsafe.Pointer(lpBuffer)))
- if err != nil {
- t.setErrno(err)
- }
- return n
- }
- // BOOL GetFileInformationByHandle(
- //
- // HANDLE hFile,
- // LPBY_HANDLE_FILE_INFORMATION lpFileInformation
- //
- // );
- func XGetFileInformationByHandle(t *TLS, hFile, lpFileInformation uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileInformation=%v, (%v:)", t, lpFileInformation, origin(2))
- }
- r1, _, e1 := procGetFileInformationByHandle.Call(hFile, lpFileInformation, 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return int32(r1)
- }
- // BOOL GetVolumeInformationW(
- //
- // LPCWSTR lpRootPathName,
- // LPWSTR lpVolumeNameBuffer,
- // DWORD nVolumeNameSize,
- // LPDWORD lpVolumeSerialNumber,
- // LPDWORD lpMaximumComponentLength,
- // LPDWORD lpFileSystemFlags,
- // LPWSTR lpFileSystemNameBuffer,
- // DWORD nFileSystemNameSize
- //
- // );
- func XGetVolumeInformationW(t *TLS, lpRootPathName, lpVolumeNameBuffer uintptr, nVolumeNameSize uint32, lpVolumeSerialNumber, lpMaximumComponentLength, lpFileSystemFlags, lpFileSystemNameBuffer uintptr, nFileSystemNameSize uint32) int32 {
- if __ccgo_strace {
- trc("t=%v lpVolumeNameBuffer=%v nVolumeNameSize=%v lpFileSystemNameBuffer=%v nFileSystemNameSize=%v, (%v:)", t, lpVolumeNameBuffer, nVolumeNameSize, lpFileSystemNameBuffer, nFileSystemNameSize, origin(2))
- }
- r0, _, err := procGetVolumeInformationW.Call(lpRootPathName,
- lpVolumeNameBuffer,
- uintptr(nVolumeNameSize),
- lpVolumeSerialNumber,
- lpMaximumComponentLength,
- lpFileSystemFlags,
- lpFileSystemNameBuffer,
- uintptr(nFileSystemNameSize),
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // wchar_t *wcschr(
- //
- // const wchar_t *str,
- // wchar_t c
- //
- // );
- func Xwcschr(t *TLS, str uintptr, c wchar_t) uintptr {
- if __ccgo_strace {
- trc("t=%v str=%v c=%v, (%v:)", t, str, c, origin(2))
- }
- var source = str
- for {
- var buf = *(*uint16)(unsafe.Pointer(source))
- if buf == 0 {
- return 0
- }
- if buf == c {
- return source
- }
- // wchar_t = 2 bytes
- source++
- source++
- }
- }
- // BOOL SetFileTime(
- //
- // HANDLE hFile,
- // const FILETIME *lpCreationTime,
- // const FILETIME *lpLastAccessTime,
- // const FILETIME *lpLastWriteTime
- //
- // );
- func XSetFileTime(t *TLS, _hFile uintptr, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime uintptr) (r int32) {
- if __ccgo_strace {
- trc("hFile=%+v lpCreationTime=%+v lpLastAccessTime=%+v lpLastWriteTime=%+v", _hFile, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime)
- defer func() { trc(`XSetFileTime->%+v`, r) }()
- }
- r0, r1, err := procSetFileTime.Call(_hFile, _lpCreationTime, _lpLastAccessTime, _lpLastWriteTime)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- t.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // __attribute__((dllimport)) DWORD GetNamedSecurityInfoW (LPCWSTR pObjectName, SE_OBJECT_TYPE ObjectType, SECURITY_INFORMATION SecurityInfo, PSID *ppsidOwner, PSID *ppsidGroup, PACL *ppDacl, PACL *ppSacl, PSECURITY_DESCRIPTOR *ppSecurityDescriptor);
- func XGetNamedSecurityInfoW(tls *TLS, _pObjectName uintptr, _ObjectType int32, _SecurityInfo uint32, _ppsidOwner uintptr, _ppsidGroup uintptr, _ppDacl uintptr, _ppSacl uintptr, _ppSecurityDescriptor uintptr) (r uint32) {
- if __ccgo_strace {
- trc("pObjectName=%+v ObjectType=%+v SecurityInfo=%+v ppsidOwner=%+v ppsidGroup=%+v ppDacl=%+v ppSacl=%+v ppSecurityDescriptor=%+v", _pObjectName, _ObjectType, _SecurityInfo, _ppsidOwner, _ppsidGroup, _ppDacl, _ppSacl, _ppSecurityDescriptor)
- defer func() { trc(`XGetNamedSecurityInfoW->%+v`, r) }()
- }
- r0, r1, err := procGetNamedSecurityInfoW.Call(_pObjectName, uintptr(_ObjectType), uintptr(_SecurityInfo), _ppsidOwner, _ppsidGroup, _ppDacl, _ppSacl, _ppSecurityDescriptor)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return uint32(r0)
- }
- // __attribute__((dllimport)) WINBOOL OpenProcessToken (HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);
- func XOpenProcessToken(tls *TLS, _ProcessHandle uintptr, _DesiredAccess uint32, _TokenHandle uintptr) (r int32) {
- if __ccgo_strace {
- trc("ProcessHandle=%+v DesiredAccess=%+v TokenHandle=%+v", _ProcessHandle, _DesiredAccess, _TokenHandle)
- defer func() { trc(`XOpenProcessToken->%+v`, r) }()
- }
- r0, r1, err := procOpenProcessToken.Call(_ProcessHandle, uintptr(_DesiredAccess), _TokenHandle)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // __attribute__((dllimport)) WINBOOL GetTokenInformation (HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength);
- func XGetTokenInformation(tls *TLS, _TokenHandle uintptr, _TokenInformationClass int32, _TokenInformation uintptr, _TokenInformationLength uint32, _ReturnLength uintptr) (r int32) {
- if __ccgo_strace {
- trc("TokenHandle=%+v TokenInformationClass=%+v TokenInformation=%+v TokenInformationLength=%+v ReturnLength=%+v", _TokenHandle, _TokenInformationClass, _TokenInformation, _TokenInformationLength, _ReturnLength)
- defer func() { trc(`XGetTokenInformation->%+v`, r) }()
- }
- r0, r1, err := procGetTokenInformation.Call(_TokenHandle, uintptr(_TokenInformationClass), _TokenInformation, uintptr(_TokenInformationLength), _ReturnLength)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // __attribute__((dllimport)) WINBOOL EqualSid (PSID pSid1, PSID pSid2);
- func XEqualSid(tls *TLS, _pSid1 uintptr, _pSid2 uintptr) (r int32) {
- if __ccgo_strace {
- trc("pSid1=%+v pSid2=%+v", _pSid1, _pSid2)
- defer func() { trc(`XEqualSid->%+v`, r) }()
- }
- r0, r1, err := procEqualSid.Call(_pSid1, _pSid2)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // int WSAStartup(
- //
- // WORD wVersionRequired,
- // LPWSADATA lpWSAData
- //
- // );
- func XWSAStartup(t *TLS, wVersionRequired uint16, lpWSAData uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v wVersionRequired=%v lpWSAData=%v, (%v:)", t, wVersionRequired, lpWSAData, origin(2))
- }
- r0, _, _ := procWSAStartup.Call(uintptr(wVersionRequired), lpWSAData, 0)
- if r0 != 0 {
- t.setErrno(r0)
- }
- return int32(r0)
- }
- // HMODULE GetModuleHandleA(LPCSTR lpModuleName);
- func XGetModuleHandleA(t *TLS, lpModuleName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpModuleName=%v, (%v:)", t, lpModuleName, origin(2))
- }
- r0, _, err := procGetModuleHandleA.Call(lpModuleName, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // HMODULE GetModuleHandleW(
- //
- // LPCWSTR lpModuleName
- //
- // );
- func XGetModuleHandleW(t *TLS, lpModuleName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v lpModuleName=%v, (%v:)", t, lpModuleName, origin(2))
- }
- r0, _, err := procGetModuleHandleW.Call(lpModuleName, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // DWORD GetEnvironmentVariableW(
- //
- // LPCWSTR lpName,
- // LPWSTR lpBuffer,
- // DWORD nSize
- //
- // );
- func XGetEnvironmentVariableW(t *TLS, lpName, lpBuffer uintptr, nSize uint32) uint32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nSize=%v, (%v:)", t, lpBuffer, nSize, origin(2))
- }
- r0, _, e1 := procGetEnvironmentVariableW.Call(lpName, lpBuffer, uintptr(nSize))
- n := uint32(r0)
- if n == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return n
- }
- // int lstrcmpiA(
- //
- // LPCSTR lpString1,
- // LPCSTR lpString2
- //
- // );
- func XlstrcmpiA(t *TLS, lpString1, lpString2 uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpString2=%v, (%v:)", t, lpString2, origin(2))
- }
- var s1 = strings.ToLower(GoString(lpString1))
- var s2 = strings.ToLower(GoString(lpString2))
- return int32(strings.Compare(s1, s2))
- }
- func XGetModuleFileNameA(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // UINT GetACP();
- func XGetACP(t *TLS) uint32 {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- r0, _, _ := procGetACP.Call(0, 0, 0)
- return uint32(r0)
- }
- // BOOL GetUserNameW(
- //
- // LPWSTR lpBuffer,
- // LPDWORD pcbBuffer
- //
- // );
- func XGetUserNameW(t *TLS, lpBuffer, pcbBuffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v pcbBuffer=%v, (%v:)", t, pcbBuffer, origin(2))
- }
- u, err := user.Current()
- if err != nil {
- panic(todo(""))
- return 0
- }
- wcnt := *(*uint16)(unsafe.Pointer(pcbBuffer))
- s := utf16.Encode([]rune(u.Username))
- if len(s)+1 > int(wcnt) {
- panic(todo(""))
- }
- *(*uint16)(unsafe.Pointer(pcbBuffer)) = uint16(len(s) + 1)
- for _, v := range s {
- *(*uint16)(unsafe.Pointer(lpBuffer)) = v
- lpBuffer += 2
- }
- return 1
- }
- // HMODULE LoadLibraryExW(
- //
- // LPCWSTR lpLibFileName,
- // HANDLE hFile,
- // DWORD dwFlags
- //
- // );
- func XLoadLibraryExW(t *TLS, lpLibFileName, hFile uintptr, dwFlags uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v hFile=%v dwFlags=%v, (%v:)", t, hFile, dwFlags, origin(2))
- }
- return 0 // If the function fails, the return value is NULL.
- }
- // wchar_t *wcscpy(
- //
- // wchar_t *strDestination,
- // const wchar_t *strSource
- //
- // );
- func Xwcscpy(t *TLS, strDestination, strSource uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v strSource=%v, (%v:)", t, strSource, origin(2))
- }
- if strSource == 0 {
- return 0
- }
- d := strDestination
- for {
- c := *(*uint16)(unsafe.Pointer(strSource))
- strSource += 2
- *(*uint16)(unsafe.Pointer(d)) = c
- d += 2
- if c == 0 {
- return strDestination
- }
- }
- }
- func XwsprintfW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // ATOM RegisterClassW(
- //
- // const WNDCLASSW *lpWndClass
- //
- // );
- func XRegisterClassW(t *TLS, lpWndClass uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpWndClass=%v, (%v:)", t, lpWndClass, origin(2))
- }
- r0, _, err := procRegisterClassW.Call(lpWndClass, 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func XKillTimer(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDestroyWindow(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // BOOL UnregisterClassW(
- //
- // LPCWSTR lpClassName,
- // HINSTANCE hInstance
- //
- // );
- func XUnregisterClassW(t *TLS, lpClassName, hInstance uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v hInstance=%v, (%v:)", t, hInstance, origin(2))
- }
- r0, _, err := procUnregisterClassW.Call(lpClassName, hInstance, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func XPostMessageW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetTimer(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // HWND CreateWindowExW(
- //
- // DWORD dwExStyle,
- // LPCWSTR lpClassName,
- // LPCWSTR lpWindowName,
- // DWORD dwStyle,
- // int X,
- // int Y,
- // int nWidth,
- // int nHeight,
- // HWND hWndParent,
- // HMENU hMenu,
- // HINSTANCE hInstance,
- // LPVOID lpParam
- //
- // );
- func XCreateWindowExW(t *TLS, dwExStyle uint32, lpClassName, lpWindowName uintptr, dwStyle uint32, x, y, nWidth, nHeight int32, hWndParent, hMenu, hInstance, lpParam uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v dwExStyle=%v lpWindowName=%v dwStyle=%v nHeight=%v lpParam=%v, (%v:)", t, dwExStyle, lpWindowName, dwStyle, nHeight, lpParam, origin(2))
- }
- r0, _, err := procCreateWindowExW.Call(
- uintptr(dwExStyle),
- lpClassName,
- lpWindowName,
- uintptr(dwStyle),
- uintptr(x),
- uintptr(y),
- uintptr(nWidth),
- uintptr(nHeight),
- hWndParent,
- hMenu,
- hInstance,
- lpParam,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // BOOL PeekMessageW(
- //
- // LPMSG lpMsg,
- // HWND hWnd,
- // UINT wMsgFilterMin,
- // UINT wMsgFilterMax,
- // UINT wRemoveMsg
- //
- // );
- func XPeekMessageW(t *TLS, lpMsg, hWnd uintptr, wMsgFilterMin, wMsgFilterMax, wRemoveMsg uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hWnd=%v wRemoveMsg=%v, (%v:)", t, hWnd, wRemoveMsg, origin(2))
- }
- r0, _, err := procPeekMessageW.Call(lpMsg,
- hWnd,
- uintptr(wMsgFilterMin),
- uintptr(wMsgFilterMax),
- uintptr(wRemoveMsg),
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func XGetMessageW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XPostQuitMessage(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XTranslateMessage(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDispatchMessageW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // DWORD SleepEx(
- //
- // DWORD dwMilliseconds,
- // BOOL bAlertable
- //
- // );
- func XSleepEx(t *TLS, dwMilliseconds uint32, bAlertable int32) uint32 {
- if __ccgo_strace {
- trc("t=%v dwMilliseconds=%v bAlertable=%v, (%v:)", t, dwMilliseconds, bAlertable, origin(2))
- }
- r0, _, _ := procSleepEx.Call(uintptr(dwMilliseconds), uintptr(bAlertable), 0)
- return uint32(r0)
- }
- // BOOL CreatePipe(
- //
- // PHANDLE hReadPipe,
- // PHANDLE hWritePipe,
- // LPSECURITY_ATTRIBUTES lpPipeAttributes,
- // DWORD nSize
- //
- // );
- func XCreatePipe(t *TLS, hReadPipe, hWritePipe, lpPipeAttributes uintptr, nSize uint32) int32 {
- if __ccgo_strace {
- trc("t=%v lpPipeAttributes=%v nSize=%v, (%v:)", t, lpPipeAttributes, nSize, origin(2))
- }
- r0, _, err := procCreatePipe.Call(hReadPipe, hWritePipe, lpPipeAttributes, uintptr(nSize), 0, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL CreateProcessW(
- //
- // LPCWSTR lpApplicationName,
- // LPWSTR lpCommandLine,
- // LPSECURITY_ATTRIBUTES lpProcessAttributes,
- // LPSECURITY_ATTRIBUTES lpThreadAttributes,
- // BOOL bInheritHandles,
- // DWORD dwCreationFlags,
- // LPVOID lpEnvironment,
- // LPCWSTR lpCurrentDirectory,
- // LPSTARTUPINFOW lpStartupInfo,
- // LPPROCESS_INFORMATION lpProcessInformation
- //
- // );
- func XCreateProcessW(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32, dwCreationFlags uint32,
- lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
- r1, _, e1 := procCreateProcessW.Call(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
- uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
- if r1 == 0 {
- if e1 != windows.NOERROR {
- t.setErrno(e1)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return int32(r1)
- }
- // DWORD WaitForInputIdle(
- //
- // HANDLE hProcess,
- // DWORD dwMilliseconds
- //
- // );
- func XWaitForInputIdle(t *TLS, hProcess uintptr, dwMilliseconds uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hProcess=%v dwMilliseconds=%v, (%v:)", t, hProcess, dwMilliseconds, origin(2))
- }
- r0, _, _ := procWaitForInputIdle.Call(hProcess, uintptr(dwMilliseconds), 0)
- return int32(r0)
- }
- // DWORD SearchPathW(
- //
- // LPCWSTR lpPath,
- // LPCWSTR lpFileName,
- // LPCWSTR lpExtension,
- // DWORD nBufferLength,
- // LPWSTR lpBuffer,
- // LPWSTR *lpFilePart
- //
- // );
- func XSearchPathW(t *TLS, lpPath, lpFileName, lpExtension uintptr, nBufferLength uint32, lpBuffer, lpFilePart uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpExtension=%v nBufferLength=%v lpFilePart=%v, (%v:)", t, lpExtension, nBufferLength, lpFilePart, origin(2))
- }
- r0, _, err := procSearchPathW.Call(lpPath, lpFileName, lpExtension, uintptr(nBufferLength), lpBuffer, lpFilePart)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func XGetShortPathNameW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // BOOL GetExitCodeProcess(
- //
- // HANDLE hProcess,
- // LPDWORD lpExitCode
- //
- // );
- func XGetExitCodeProcess(t *TLS, hProcess, lpExitCode uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpExitCode=%v, (%v:)", t, lpExitCode, origin(2))
- }
- r0, _, err := procGetExitCodeProcess.Call(hProcess, lpExitCode, 0)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL PeekNamedPipe(
- //
- // HANDLE hNamedPipe,
- // LPVOID lpBuffer,
- // DWORD nBufferSize,
- // LPDWORD lpBytesRead,
- // LPDWORD lpTotalBytesAvail,
- // LPDWORD lpBytesLeftThisMessage
- //
- // );
- func XPeekNamedPipe(t *TLS, hNamedPipe, lpBuffer uintptr, nBufferSize uint32, lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpBuffer=%v nBufferSize=%v lpBytesLeftThisMessage=%v, (%v:)", t, lpBuffer, nBufferSize, lpBytesLeftThisMessage, origin(2))
- }
- r0, _, err := procPeekNamedPipe.Call(hNamedPipe, lpBuffer, uintptr(nBufferSize), lpBytesRead, lpTotalBytesAvail, lpBytesLeftThisMessage)
- if r0 == 0 {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // long _InterlockedExchange(
- //
- // long volatile * Target,
- // long Value
- //
- // );
- func X_InterlockedExchange(t *TLS, Target uintptr, Value long) long {
- if __ccgo_strace {
- trc("t=%v Target=%v Value=%v, (%v:)", t, Target, Value, origin(2))
- }
- old := atomic.SwapInt32((*int32)(unsafe.Pointer(Target)), Value)
- return old
- }
- // BOOL TerminateThread(
- //
- // [in, out] HANDLE hThread,
- // [in] DWORD dwExitCode
- //
- // );
- func XTerminateThread(t *TLS, hThread uintptr, dwExitCode uint32) int32 {
- if __ccgo_strace {
- trc("t=%v hThread=%v dwExitCode=%v, (%v:)", t, hThread, dwExitCode, origin(2))
- }
- r0, _, err := procTerminateThread.Call(hThread, uintptr(dwExitCode), 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL GetComputerNameW(
- //
- // LPWSTR lpBuffer,
- // LPDWORD nSize
- //
- // );
- func XGetComputerNameW(t *TLS, lpBuffer, nSize uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v nSize=%v, (%v:)", t, nSize, origin(2))
- }
- panic(todo(""))
- }
- func Xgethostname(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSendMessageW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XWSAGetLastError(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func Xclosesocket(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XWspiapiFreeAddrInfo(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XWspiapiGetNameInfo(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XIN6_ADDR_EQUAL(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func X__ccgo_in6addr_anyp(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XIN6_IS_ADDR_V4MAPPED(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetHandleInformation(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func Xioctlsocket(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XGetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XSetWindowLongPtrW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XWSAAsyncSelect(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func Xinet_ntoa(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- func X_controlfp(t *TLS, _ ...interface{}) uint32 {
- panic(todo(""))
- }
- // BOOL QueryPerformanceFrequency(
- //
- // LARGE_INTEGER *lpFrequency
- //
- // );
- func XQueryPerformanceFrequency(t *TLS, lpFrequency uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFrequency=%v, (%v:)", t, lpFrequency, origin(2))
- }
- r1, _, err := procQueryPerformanceFrequency.Call(lpFrequency, 0, 0)
- if r1 == 0 {
- t.setErrno(err)
- return 0
- }
- return int32(r1)
- }
- func inDST(t gotime.Time) bool {
- jan1st := gotime.Date(t.Year(), 1, 1, 0, 0, 0, 0, t.Location()) // January 1st is always outside DST window
- _, off1 := t.Zone()
- _, off2 := jan1st.Zone()
- return off1 != off2
- }
- // void _ftime( struct _timeb *timeptr );
- func X_ftime(t *TLS, timeptr uintptr) {
- if __ccgo_strace {
- trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
- }
- var tm = gotime.Now()
- var tPtr = (*time.X__timeb64)(unsafe.Pointer(timeptr))
- tPtr.Ftime = tm.Unix()
- tPtr.Fmillitm = uint16(gotime.Duration(tm.Nanosecond()) / gotime.Millisecond)
- if inDST(tm) {
- tPtr.Fdstflag = 1
- }
- _, offset := tm.Zone()
- tPtr.Ftimezone = int16(offset)
- }
- func XDdeInitializeW(t *TLS, _ ...interface{}) uint32 {
- panic(todo(""))
- }
- func XDdeCreateStringHandleW(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- func XDdeNameService(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func X_snwprintf(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeQueryStringW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // int _wcsicmp(
- //
- // const wchar_t *string1,
- // const wchar_t *string2
- //
- // );
- func X_wcsicmp(t *TLS, string1, string2 uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v string2=%v, (%v:)", t, string2, origin(2))
- }
- return Xwcsicmp(t, string1, string2)
- }
- func XDdeCreateDataHandle(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- func XDdeAccessData(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- func XDdeUnaccessData(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeUninitialize(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeConnect(t *TLS, _ ...interface{}) uintptr {
- panic(todo(""))
- }
- func XDdeFreeStringHandle(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegisterClassExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XGlobalGetAtomNameW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XGlobalAddAtomW(t *TLS, _ ...interface{}) uint16 {
- panic(todo(""))
- }
- func XEnumWindows(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XIsWindow(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XGlobalDeleteAtom(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeGetLastError(t *TLS, _ ...interface{}) uint32 {
- panic(todo(""))
- }
- // HDDEDATA DdeClientTransaction(
- //
- // LPBYTE pData,
- // DWORD cbData,
- // HCONV hConv,
- // HSZ hszItem,
- // UINT wFmt,
- // UINT wType,
- // DWORD dwTimeout,
- // LPDWORD pdwResult
- //
- // );
- func XDdeClientTransaction(t *TLS, pData uintptr, cbData uint32, hConv uintptr, hszItem uintptr, wFmt, wType, dwTimeout uint32, pdwResult uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v pData=%v cbData=%v hConv=%v hszItem=%v dwTimeout=%v pdwResult=%v, (%v:)", t, pData, cbData, hConv, hszItem, dwTimeout, pdwResult, origin(2))
- }
- panic(todo(""))
- }
- func XDdeAbandonTransaction(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeFreeDataHandle(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeGetData(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XDdeDisconnect(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegCloseKey(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegDeleteValueW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegEnumKeyExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegQueryValueExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegEnumValueW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegConnectRegistryW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegCreateKeyExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegOpenKeyExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegDeleteKeyW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- func XRegSetValueExW(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // int _vsnwprintf(
- //
- // wchar_t *buffer,
- // size_t count,
- // const wchar_t *format,
- // va_list argptr
- //
- // );
- func X__mingw_vsnwprintf(t *TLS, buffer uintptr, count types.Size_t, format, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v buffer=%v count=%v va=%v, (%v:)", t, buffer, count, va, origin(2))
- }
- panic(todo(""))
- }
- // int vprintf(const char *format, va_list ap);
- func X__mingw_vprintf(t *TLS, s, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- return Xvprintf(t, s, ap)
- }
- // int vfscanf(FILE * restrict stream, const char * restrict format, va_list arg);
- func X__mingw_vfscanf(t *TLS, stream, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vsscanf(const char *str, const char *format, va_list ap);
- func X__mingw_vsscanf(t *TLS, str, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- return Xsscanf(t, str, format, ap)
- }
- // int vfprintf(FILE * restrict stream, const char * restrict format, va_list arg);
- func X__mingw_vfprintf(t *TLS, f uintptr, format, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v f=%v va=%v, (%v:)", t, f, va, origin(2))
- }
- return Xvfprintf(t, f, format, va)
- }
- // int vsprintf(char * restrict s, const char * restrict format, va_list arg);
- func X__mingw_vsprintf(t *TLS, s, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- return Xvsprintf(t, s, format, ap)
- }
- // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
- func X__mingw_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
- }
- return Xvsnprintf(t, str, size, format, ap)
- }
- // int putchar(int char)
- func X_putchar(t *TLS, c int32) int32 {
- if __ccgo_strace {
- trc("t=%v c=%v, (%v:)", t, c, origin(2))
- }
- if _, err := fwrite(unistd.STDOUT_FILENO, []byte{byte(c)}); err != nil {
- return -1
- }
- return int32(byte(c))
- }
- // int vfwscanf(FILE *stream, const wchar_t *format, va_list argptr;);
- func X__mingw_vfwscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vswscanf(const wchar_t *buffer, const wchar_t *format, va_list arglist);
- func X__mingw_vswscanf(t *TLS, stream uintptr, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v ap=%v, (%v:)", t, stream, ap, origin(2))
- }
- panic(todo(""))
- }
- // int vfwprintf(FILE * restrict stream, const wchar_t * restrict format, va_list arg);
- func X__mingw_vfwprintf(t *TLS, stream, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v ap=%v, (%v:)", t, ap, origin(2))
- }
- panic(todo(""))
- }
- // int putchar(int c);
- func Xputchar(t *TLS, c int32) int32 {
- if __ccgo_strace {
- trc("t=%v c=%v, (%v:)", t, c, origin(2))
- }
- panic(todo(""))
- }
- // void _assert(
- //
- // char const* message,
- // char const* filename,
- // unsigned line
- //
- // );
- func X_assert(t *TLS, message, filename uintptr, line uint32) {
- if __ccgo_strace {
- trc("t=%v filename=%v line=%v, (%v:)", t, filename, line, origin(2))
- }
- panic(todo(""))
- }
- // char *strdup(const char *s);
- func X_strdup(t *TLS, s uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v s=%v, (%v:)", t, s, origin(2))
- }
- panic(todo(""))
- }
- // int _access(
- //
- // const char *path,
- // int mode
- //
- // );
- func X_access(t *TLS, pathname uintptr, mode int32) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
- }
- var path = GoString(pathname)
- info, err := os.Stat(path)
- if err != nil {
- // doesn't exist
- return errno.ENOENT
- }
- switch mode {
- case 0:
- // exists
- return 0
- case 2:
- // write-only
- // Check if the user bit is enabled in file permission
- if info.Mode().Perm()&(1<<(uint(7))) == 1 {
- // write-able
- return 0
- }
- case 4:
- // read-only
- // Check if the user bit is enabled in file permission
- if info.Mode().Perm()&(1<<(uint(7))) == 0 {
- // not set, so read-only
- return 0
- }
- case 6:
- // r/w
- if info.Mode().Perm()&(1<<(uint(7))) == 1 {
- // write-able
- return 0
- }
- }
- return errno.EACCES
- }
- // BOOL WINAPI SetConsoleCtrlHandler(
- //
- // _In_opt_ PHANDLER_ROUTINE HandlerRoutine,
- // _In_ BOOL Add
- //
- // );
- func XSetConsoleCtrlHandler(t *TLS, HandlerRoutine uintptr, Add int32) int32 {
- if __ccgo_strace {
- trc("t=%v HandlerRoutine=%v Add=%v, (%v:)", t, HandlerRoutine, Add, origin(2))
- }
- //var fcc = &struct {
- // f func(*TLS, uint32) int32
- //}{}
- //fcc = (*struct{ f func(*TLS, uint32) int32 })(unsafe.Pointer(HandlerRoutine))
- //var hdlr = fcc.f
- //
- //_, _, err := procSetConsoleCtrlHandler.Call(
- //windows.NewCallback(func(controlType uint) uint {
- // return uint( hdlr(t, uint32(controlType)) )
- // }), 1)
- //
- //if err != nil {
- // panic("failed: SetConsoleCtrlHandler")
- //}
- return 0
- }
- // DebugBreak
- func XDebugBreak(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- // int _isatty( int fd );
- func X_isatty(t *TLS, fd int32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return 0
- }
- if fd == unistd.STDOUT_FILENO ||
- fd == unistd.STDIN_FILENO ||
- fd == unistd.STDERR_FILENO {
- var mode uint32
- err := windows.GetConsoleMode(f.Handle, &mode)
- if err != nil {
- t.setErrno(errno.EINVAL)
- return 0
- }
- // is console
- return 1
- }
- return 0
- }
- // BOOL WINAPI SetConsoleTextAttribute(
- //
- // _In_ HANDLE hConsoleOutput,
- // _In_ WORD wAttributes
- //
- // );
- func XSetConsoleTextAttribute(t *TLS, hConsoleOutput uintptr, wAttributes uint16) int32 {
- if __ccgo_strace {
- trc("t=%v hConsoleOutput=%v wAttributes=%v, (%v:)", t, hConsoleOutput, wAttributes, origin(2))
- }
- r1, _, _ := procSetConsoleTextAttribute.Call(hConsoleOutput, uintptr(wAttributes), 0)
- return int32(r1)
- }
- // BOOL WINAPI GetConsoleScreenBufferInfo(
- //
- // _In_ HANDLE hConsoleOutput,
- // _Out_ PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
- //
- // );
- func XGetConsoleScreenBufferInfo(t *TLS, hConsoleOutput, lpConsoleScreenBufferInfo uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpConsoleScreenBufferInfo=%v, (%v:)", t, lpConsoleScreenBufferInfo, origin(2))
- }
- r1, _, _ := procGetConsoleScreenBufferInfo.Call(hConsoleOutput, lpConsoleScreenBufferInfo, 0)
- return int32(r1)
- }
- // FILE *_popen(
- //
- // const char *command,
- // const char *mode
- //
- // );
- func X_popen(t *TLS, command, mode uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
- }
- panic(todo(""))
- }
- // int _wunlink(
- //
- // const wchar_t *filename
- //
- // );
- func X_wunlink(t *TLS, filename uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v filename=%v, (%v:)", t, filename, origin(2))
- }
- panic(todo(""))
- }
- func Xclosedir(tls *TLS, dir uintptr) int32 {
- if __ccgo_strace {
- trc("tls=%v dir=%v, (%v:)", tls, dir, origin(2))
- }
- panic(todo(""))
- }
- func Xopendir(tls *TLS, name uintptr) uintptr {
- if __ccgo_strace {
- trc("tls=%v name=%v, (%v:)", tls, name, origin(2))
- }
- panic(todo(""))
- }
- func Xreaddir(tls *TLS, dir uintptr) uintptr {
- if __ccgo_strace {
- trc("tls=%v dir=%v, (%v:)", tls, dir, origin(2))
- }
- panic(todo(""))
- }
- // int _unlink(
- //
- // const char *filename
- //
- // );
- func X_unlink(t *TLS, filename uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v filename=%v, (%v:)", t, filename, origin(2))
- }
- panic(todo(""))
- }
- // int pclose(FILE *stream);
- func X_pclose(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- panic(todo(""))
- }
- // int setmode (int fd, int mode);
- func Xsetmode(t *TLS, fd, mode int32) int32 {
- if __ccgo_strace {
- trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
- }
- return X_setmode(t, fd, mode)
- }
- // int _setmode (int fd, int mode);
- func X_setmode(t *TLS, fd, mode int32) int32 {
- if __ccgo_strace {
- trc("t=%v mode=%v, (%v:)", t, mode, origin(2))
- }
- _, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- // we're always in binary mode.
- // at least for now.
- if mode == fcntl.O_BINARY {
- return fcntl.O_BINARY
- } else {
- t.setErrno(errno.EINVAL)
- return -1
- }
- }
- // int _mkdir(const char *dirname);
- func X_mkdir(t *TLS, dirname uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v dirname=%v, (%v:)", t, dirname, origin(2))
- }
- panic(todo(""))
- }
- // int _chmod( const char *filename, int pmode );
- func X_chmod(t *TLS, filename uintptr, pmode int32) int32 {
- if __ccgo_strace {
- trc("t=%v filename=%v pmode=%v, (%v:)", t, filename, pmode, origin(2))
- }
- panic(todo(""))
- }
- // int _fileno(FILE *stream);
- func X_fileno(t *TLS, stream uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- f, ok := winGetObject(stream).(*file)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- return f._fd
- }
- // void rewind(FILE *stream);
- func Xrewind(t *TLS, stream uintptr) {
- if __ccgo_strace {
- trc("t=%v stream=%v, (%v:)", t, stream, origin(2))
- }
- Xfseek(t, stream, 0, unistd.SEEK_SET)
- }
- // __atomic_load_n
- func X__atomic_load_n(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- // __atomic_store_n
- func X__atomic_store_n(t *TLS, _ ...interface{}) int32 {
- panic(todo(""))
- }
- // __builtin_add_overflow
- func X__builtin_add_overflow(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- // __builtin_mul_overflow
- func X__builtin_mul_overflow(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- // __builtin_sub_overflow
- func X__builtin_sub_overflow(t *TLS) {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- panic(todo(""))
- }
- func goWideBytes(p uintptr, n int) []uint16 {
- b := GoBytes(p, 2*n)
- var w []uint16
- for i := 0; i < len(b); i += 2 {
- w = append(w, *(*uint16)(unsafe.Pointer(&b[i])))
- }
- return w
- }
- // This version does include the zero terminator in the returned Go string.
- func goWideString(p uintptr) string {
- if p == 0 {
- return ""
- }
- var w []uint16
- var raw = (*RawMem)(unsafe.Pointer(p))
- var i = 0
- for {
- wc := *(*uint16)(unsafe.Pointer(&raw[i]))
- w = append(w, wc)
- // append until U0000
- if wc == 0 {
- break
- }
- i = i + 2
- }
- s := utf16.Decode(w)
- return string(s)
- }
- func goWideStringN(p uintptr, n int) string {
- panic(todo(""))
- }
- // This version does not include the zero terminator in the returned Go string.
- func goWideStringNZ(p uintptr) string {
- if p == 0 {
- return ""
- }
- var w []uint16
- var raw = (*RawMem)(unsafe.Pointer(p))
- var i = 0
- for {
- wc := *(*uint16)(unsafe.Pointer(&raw[i]))
- if wc == 0 {
- break
- }
- w = append(w, wc)
- i = i + 2
- }
- s := utf16.Decode(w)
- return string(s)
- }
- // LPWSTR GetCommandLineW();
- func XGetCommandLineW(t *TLS) uintptr {
- if __ccgo_strace {
- trc("t=%v, (%v:)", t, origin(2))
- }
- return uintptr(unsafe.Pointer(windows.GetCommandLine()))
- }
- // BOOL AddAccessDeniedAce(
- //
- // PACL pAcl,
- // DWORD dwAceRevision,
- // DWORD AccessMask,
- // PSID pSid
- //
- // );
- func XAddAccessDeniedAce(t *TLS, pAcl uintptr, dwAceRevision, AccessMask uint32, pSid uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v pAcl=%v AccessMask=%v pSid=%v, (%v:)", t, pAcl, AccessMask, pSid, origin(2))
- }
- panic(todo(""))
- }
- // __attribute__((dllimport)) WINBOOL AddAce (PACL pAcl, DWORD dwAceRevision, DWORD dwStartingAceIndex, LPVOID pAceList, DWORD nAceListLength);
- func XAddAce(tls *TLS, _pAcl uintptr, _dwAceRevision uint32, _dwStartingAceIndex uint32, _pAceList uintptr, _nAceListLength uint32) (r uint32) {
- if __ccgo_strace {
- trc("pAcl=%+v dwAceRevision=%+v dwStartingAceIndex=%+v pAceList=%+v nAceListLength=%+v", _pAcl, _dwAceRevision, _dwStartingAceIndex, _pAceList, _nAceListLength)
- defer func() { trc(`XAddAce->%+v`, r) }()
- }
- r0, r1, err := procAddAce.Call(_pAcl, uintptr(_dwAceRevision), uintptr(_dwStartingAceIndex), _pAceList, uintptr(_nAceListLength))
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return uint32(r0)
- }
- // __attribute__((dllimport)) WINBOOL GetAce (PACL pAcl, DWORD dwAceIndex, LPVOID *pAce);
- func XGetAce(tls *TLS, _pAcl uintptr, _dwAceIndex uint32, _pAce uintptr) (r int32) {
- if __ccgo_strace {
- trc("pAcl=%+v dwAceIndex=%+v pAce=%+v", _pAcl, _dwAceIndex, _pAce)
- defer func() { trc(`XGetAce->%+v`, r) }()
- }
- r0, r1, err := procGetAce.Call(_pAcl, uintptr(_dwAceIndex), _pAce)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // BOOL GetAclInformation(
- //
- // PACL pAcl,
- // LPVOID pAclInformation,
- // DWORD nAclInformationLength,
- // ACL_INFORMATION_CLASS dwAclInformationClass
- //
- // );
- func XGetAclInformation(t *TLS, pAcl, pAclInformation uintptr, nAclInformationLength uint32, dwAclInformationClass int32) int32 {
- if __ccgo_strace {
- trc("t=%v pAclInformation=%v dwAclInformationClass=%v, (%v:)", t, pAclInformation, dwAclInformationClass, origin(2))
- }
- r0, _, err := procGetAclInformation.Call(pAclInformation,
- pAclInformation,
- uintptr(nAclInformationLength),
- uintptr(dwAclInformationClass),
- 0,
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // BOOL GetFileSecurityA(
- //
- // LPCSTR lpFileName,
- // SECURITY_INFORMATION RequestedInformation,
- // PSECURITY_DESCRIPTOR pSecurityDescriptor,
- // DWORD nLength,
- // LPDWORD lpnLengthNeeded
- //
- // );
- func XGetFileSecurityA(t *TLS, lpFileName uintptr, RequestedInformation uint32, pSecurityDescriptor uintptr, nLength uint32, lpnLengthNeeded uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpFileName=%v RequestedInformation=%v pSecurityDescriptor=%v nLength=%v lpnLengthNeeded=%v, (%v:)", t, lpFileName, RequestedInformation, pSecurityDescriptor, nLength, lpnLengthNeeded, origin(2))
- }
- r0, _, err := procGetFileSecurityA.Call(lpFileName,
- uintptr(RequestedInformation),
- pSecurityDescriptor,
- uintptr(nLength),
- lpnLengthNeeded,
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // __attribute__((dllimport)) DWORD GetLengthSid (PSID pSid);
- func XGetLengthSid(tls *TLS, _pSid uintptr) (r uint32) {
- if __ccgo_strace {
- trc("pSid=%+v", _pSid)
- defer func() { trc(`XGetLengthSid->%+v`, r) }()
- }
- r0, r1, err := procGetLengthSid.Call(_pSid)
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return uint32(r0)
- }
- // BOOL GetSecurityDescriptorDacl(
- //
- // PSECURITY_DESCRIPTOR pSecurityDescriptor,
- // LPBOOL lpbDaclPresent,
- // PACL *pDacl,
- // LPBOOL lpbDaclDefaulted
- //
- // );
- func XGetSecurityDescriptorDacl(t *TLS, pSecurityDescriptor, lpbDaclPresent, pDacl, lpbDaclDefaulted uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v lpbDaclDefaulted=%v, (%v:)", t, lpbDaclDefaulted, origin(2))
- }
- r0, _, err := procGetSecurityDescriptorDacl.Call(pSecurityDescriptor,
- lpbDaclPresent,
- pDacl,
- lpbDaclDefaulted,
- 0,
- 0,
- )
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // DWORD GetSidLengthRequired(
- //
- // UCHAR nSubAuthorityCount
- //
- // );
- func XGetSidLengthRequired(t *TLS, nSubAuthorityCount uint8) int32 {
- if __ccgo_strace {
- trc("t=%v nSubAuthorityCount=%v, (%v:)", t, nSubAuthorityCount, origin(2))
- }
- r0, _, err := procGetSidLengthRequired.Call(uintptr(nSubAuthorityCount), 0, 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // PDWORD GetSidSubAuthority(
- //
- // PSID pSid,
- // DWORD nSubAuthority
- //
- // );
- func XGetSidSubAuthority(t *TLS, pSid uintptr, nSubAuthority uint32) uintptr {
- if __ccgo_strace {
- trc("t=%v pSid=%v nSubAuthority=%v, (%v:)", t, pSid, nSubAuthority, origin(2))
- }
- r0, _, err := procGetSidSubAuthority.Call(pSid, uintptr(nSubAuthority), 0)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // __attribute__((dllimport)) WINBOOL InitializeAcl (PACL pAcl, DWORD nAclLength, DWORD dwAclRevision);
- func XInitializeAcl(tls *TLS, _pAcl uintptr, _nAclLength uint32, _dwAclRevision uint32) (r int32) {
- if __ccgo_strace {
- trc("pAcl=%+v nAclLength=%+v dwAclRevision=%+v", _pAcl, _nAclLength, _dwAclRevision)
- defer func() { trc(`XInitializeAcl->%+v`, r) }()
- }
- r0, r1, err := procInitializeAcl.Call(_pAcl, uintptr(_nAclLength), uintptr(_dwAclRevision))
- if err != windows.NOERROR {
- if __ccgo_strace {
- trc(`r0=%v r1=%v err=%v`, r0, r1, err)
- }
- tls.SetLastError(uint32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // BOOL InitializeSid(
- //
- // PSID Sid,
- // PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority,
- // BYTE nSubAuthorityCount
- //
- // );
- func XInitializeSid(t *TLS, Sid, pIdentifierAuthority uintptr, nSubAuthorityCount uint8) int32 {
- if __ccgo_strace {
- trc("t=%v pIdentifierAuthority=%v nSubAuthorityCount=%v, (%v:)", t, pIdentifierAuthority, nSubAuthorityCount, origin(2))
- }
- r0, _, err := procInitializeSid.Call(Sid, pIdentifierAuthority, uintptr(nSubAuthorityCount))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // VOID RaiseException(
- //
- // DWORD dwExceptionCode,
- // DWORD dwExceptionFlags,
- // DWORD nNumberOfArguments,
- // const ULONG_PTR *lpArguments
- //
- // );
- func XRaiseException(t *TLS, dwExceptionCode, dwExceptionFlags, nNumberOfArguments uint32, lpArguments uintptr) {
- if __ccgo_strace {
- trc("t=%v nNumberOfArguments=%v lpArguments=%v, (%v:)", t, nNumberOfArguments, lpArguments, origin(2))
- }
- panic(todo(""))
- }
- // UINT SetErrorMode(
- //
- // UINT uMode
- //
- // );
- func XSetErrorMode(t *TLS, uMode uint32) int32 {
- if __ccgo_strace {
- trc("t=%v uMode=%v, (%v:)", t, uMode, origin(2))
- }
- panic(todo(""))
- }
- // DWORD SetNamedSecurityInfoA(
- //
- // LPSTR pObjectName,
- // SE_OBJECT_TYPE ObjectType,
- // SECURITY_INFORMATION SecurityInfo,
- // PSID psidOwner,
- // PSID psidGroup,
- // PACL pDacl,
- // PACL pSacl
- //
- // );
- func XSetNamedSecurityInfoA(t *TLS, pObjectName uintptr, ObjectType int32, SecurityInfo uint32, psidOwner, psidGroup, pDacl, pSacl uintptr) uint32 {
- if __ccgo_strace {
- trc("t=%v pObjectName=%v SecurityInfo=%v pSacl=%v, (%v:)", t, pObjectName, SecurityInfo, pSacl, origin(2))
- }
- panic(todo(""))
- }
- // BOOL CreateProcessA(
- //
- // LPCSTR lpApplicationName,
- // LPSTR lpCommandLine,
- // LPSECURITY_ATTRIBUTES lpProcessAttributes,
- // LPSECURITY_ATTRIBUTES lpThreadAttributes,
- // BOOL bInheritHandles,
- // DWORD dwCreationFlags,
- // LPVOID lpEnvironment,
- // LPCSTR lpCurrentDirectory,
- // LPSTARTUPINFOA lpStartupInfo,
- // LPPROCESS_INFORMATION lpProcessInformation
- //
- // );
- func XCreateProcessA(t *TLS, lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes uintptr, bInheritHandles int32,
- dwCreationFlags uint32, lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation uintptr) int32 {
- r1, _, err := procCreateProcessA.Call(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes,
- uintptr(bInheritHandles), uintptr(dwCreationFlags), lpEnvironment, lpCurrentDirectory, lpStartupInfo, lpProcessInformation, 0, 0)
- if r1 == 0 {
- if err != windows.NOERROR {
- t.setErrno(err)
- } else {
- t.setErrno(errno.EINVAL)
- }
- }
- return int32(r1)
- }
- // unsigned int _set_abort_behavior(
- //
- // unsigned int flags,
- // unsigned int mask
- //
- // );
- func X_set_abort_behavior(t *TLS, _ ...interface{}) uint32 {
- panic(todo(""))
- }
- // HANDLE OpenEventA(
- //
- // DWORD dwDesiredAccess,
- // BOOL bInheritHandle,
- // LPCSTR lpName
- //
- // );
- func XOpenEventA(t *TLS, dwDesiredAccess uint32, bInheritHandle uint32, lpName uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v dwDesiredAccess=%v bInheritHandle=%v lpName=%v, (%v:)", t, dwDesiredAccess, bInheritHandle, lpName, origin(2))
- }
- r0, _, err := procOpenEventA.Call(uintptr(dwDesiredAccess), uintptr(bInheritHandle), lpName)
- if r0 == 0 {
- t.setErrno(err)
- }
- return r0
- }
- // size_t _msize(
- //
- // void *memblock
- //
- // );
- func X_msize(t *TLS, memblock uintptr) types.Size_t {
- if __ccgo_strace {
- trc("t=%v memblock=%v, (%v:)", t, memblock, origin(2))
- }
- return types.Size_t(UsableSize(memblock))
- }
- // unsigned long _byteswap_ulong ( unsigned long val );
- func X_byteswap_ulong(t *TLS, val ulong) ulong {
- if __ccgo_strace {
- trc("t=%v val=%v, (%v:)", t, val, origin(2))
- }
- return X__builtin_bswap32(t, val)
- }
- // unsigned __int64 _byteswap_uint64 ( unsigned __int64 val );
- func X_byteswap_uint64(t *TLS, val uint64) uint64 {
- if __ccgo_strace {
- trc("t=%v val=%v, (%v:)", t, val, origin(2))
- }
- return X__builtin_bswap64(t, val)
- }
- // int _commit(
- //
- // int fd
- //
- // );
- func X_commit(t *TLS, fd int32) int32 {
- if __ccgo_strace {
- trc("t=%v fd=%v, (%v:)", t, fd, origin(2))
- }
- return Xfsync(t, fd)
- }
- // int _stati64(
- //
- // const char *path,
- // struct _stati64 *buffer
- //
- // );
- func X_stati64(t *TLS, path, buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v path=%v buffer=%v, (%v:)", t, path, buffer, origin(2))
- }
- r0, _, err := procStati64.Call(uintptr(path), uintptr(buffer))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int _fstati64(int fd, struct _stati64 *buffer);
- func X_fstati64(t *TLS, fd int32, buffer uintptr) int32 {
- return X_fstat64(t, fd, buffer)
- }
- // int _findnext32(
- //
- // intptr_t handle,
- // struct _finddata32_t *fileinfo
- //
- // );
- func X_findnext32(t *TLS, handle types.Intptr_t, buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v handle=%v buffer=%v, (%v:)", t, handle, buffer, origin(2))
- }
- r0, _, err := procFindnext32.Call(uintptr(handle), buffer)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // intptr_t _findfirst32(
- //
- // const char *filespec,
- // struct _finddata32_t *fileinfo
- //
- // );
- func X_findfirst32(t *TLS, filespec, fileinfo uintptr) types.Intptr_t {
- if __ccgo_strace {
- trc("t=%v fileinfo=%v, (%v:)", t, fileinfo, origin(2))
- }
- r0, _, err := procFindfirst32.Call(filespec, fileinfo)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return types.Intptr_t(r0)
- }
- /*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of the University nor the names of its contributors
- * may be used to endorse or promote products derived from this software
- * without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
- // long strtol(const char *nptr, char **endptr, int base);
- func Xstrtol(t *TLS, nptr, endptr uintptr, base int32) long {
- if __ccgo_strace {
- trc("t=%v endptr=%v base=%v, (%v:)", t, endptr, base, origin(2))
- }
- var s uintptr = nptr
- var acc ulong
- var c byte
- var cutoff ulong
- var neg int32
- var any int32
- var cutlim int32
- /*
- * Skip white space and pick up leading +/- sign if any.
- * If base is 0, allow 0x for hex and 0 for octal, else
- * assume decimal; if base is already 16, allow 0x.
- */
- for {
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- var sp = strings.TrimSpace(string(c))
- if len(sp) > 0 {
- break
- }
- }
- if c == '-' {
- neg = 1
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- } else if c == '+' {
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- }
- sp := *(*byte)(unsafe.Pointer(s))
- if (base == 0 || base == 16) &&
- c == '0' && (sp == 'x' || sp == 'X') {
- PostIncUintptr(&s, 1)
- c = *(*byte)(unsafe.Pointer(s)) //s[1];
- PostIncUintptr(&s, 1)
- base = 16
- }
- if base == 0 {
- if c == '0' {
- base = 0
- } else {
- base = 10
- }
- }
- /*
- * Compute the cutoff value between legal numbers and illegal
- * numbers. That is the largest legal value, divided by the
- * base. An input number that is greater than this value, if
- * followed by a legal input character, is too big. One that
- * is equal to this value may be valid or not; the limit
- * between valid and invalid numbers is then based on the last
- * digit. For instance, if the range for longs is
- * [-2147483648..2147483647] and the input base is 10,
- * cutoff will be set to 214748364 and cutlim to either
- * 7 (neg==0) or 8 (neg==1), meaning that if we have accumulated
- * a value > 214748364, or equal but the next digit is > 7 (or 8),
- * the number is too big, and we will return a range error.
- *
- * Set any if any `digits' consumed; make it negative to indicate
- * overflow.
- */
- var ULONG_MAX ulong = 0xFFFFFFFF
- var LONG_MAX long = long(ULONG_MAX >> 1)
- var LONG_MIN long = ^LONG_MAX
- if neg == 1 {
- cutoff = ulong(-1 * LONG_MIN)
- } else {
- cutoff = ulong(LONG_MAX)
- }
- cutlim = int32(cutoff % ulong(base))
- cutoff = cutoff / ulong(base)
- acc = 0
- any = 0
- for {
- var cs = string(c)
- if unicode.IsDigit([]rune(cs)[0]) {
- c -= '0'
- } else if unicode.IsLetter([]rune(cs)[0]) {
- if unicode.IsUpper([]rune(cs)[0]) {
- c -= 'A' - 10
- } else {
- c -= 'a' - 10
- }
- } else {
- break
- }
- if int32(c) >= base {
- break
- }
- if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
- any = -1
- } else {
- any = 1
- acc *= ulong(base)
- acc += ulong(c)
- }
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- }
- if any < 0 {
- if neg == 1 {
- acc = ulong(LONG_MIN)
- } else {
- acc = ulong(LONG_MAX)
- }
- t.setErrno(errno.ERANGE)
- } else if neg == 1 {
- acc = -acc
- }
- if endptr != 0 {
- if any == 1 {
- PostDecUintptr(&s, 1)
- AssignPtrUintptr(endptr, s)
- } else {
- AssignPtrUintptr(endptr, nptr)
- }
- }
- return long(acc)
- }
- // unsigned long int strtoul(const char *nptr, char **endptr, int base);
- func Xstrtoul(t *TLS, nptr, endptr uintptr, base int32) ulong {
- if __ccgo_strace {
- trc("t=%v endptr=%v base=%v, (%v:)", t, endptr, base, origin(2))
- }
- var s uintptr = nptr
- var acc ulong
- var c byte
- var cutoff ulong
- var neg int32
- var any int32
- var cutlim int32
- /*
- * Skip white space and pick up leading +/- sign if any.
- * If base is 0, allow 0x for hex and 0 for octal, else
- * assume decimal; if base is already 16, allow 0x.
- */
- for {
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- var sp = strings.TrimSpace(string(c))
- if len(sp) > 0 {
- break
- }
- }
- if c == '-' {
- neg = 1
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- } else if c == '+' {
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- }
- sp := *(*byte)(unsafe.Pointer(s))
- if (base == 0 || base == 16) &&
- c == '0' && (sp == 'x' || sp == 'X') {
- PostIncUintptr(&s, 1)
- c = *(*byte)(unsafe.Pointer(s)) //s[1];
- PostIncUintptr(&s, 1)
- base = 16
- }
- if base == 0 {
- if c == '0' {
- base = 0
- } else {
- base = 10
- }
- }
- var ULONG_MAX ulong = 0xFFFFFFFF
- cutoff = ULONG_MAX / ulong(base)
- cutlim = int32(ULONG_MAX % ulong(base))
- acc = 0
- any = 0
- for {
- var cs = string(c)
- if unicode.IsDigit([]rune(cs)[0]) {
- c -= '0'
- } else if unicode.IsLetter([]rune(cs)[0]) {
- if unicode.IsUpper([]rune(cs)[0]) {
- c -= 'A' - 10
- } else {
- c -= 'a' - 10
- }
- } else {
- break
- }
- if int32(c) >= base {
- break
- }
- if any < 0 || acc > cutoff || (acc == cutoff && int32(c) > cutlim) {
- any = -1
- } else {
- any = 1
- acc *= ulong(base)
- acc += ulong(c)
- }
- c = *(*byte)(unsafe.Pointer(s))
- PostIncUintptr(&s, 1)
- }
- if any < 0 {
- acc = ULONG_MAX
- t.setErrno(errno.ERANGE)
- } else if neg == 1 {
- acc = -acc
- }
- if endptr != 0 {
- if any == 1 {
- PostDecUintptr(&s, 1)
- AssignPtrUintptr(endptr, s)
- } else {
- AssignPtrUintptr(endptr, nptr)
- }
- }
- return acc
- }
- // int __isoc99_sscanf(const char *str, const char *format, ...);
- func X__isoc99_sscanf(t *TLS, str, format, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v va=%v, (%v:)", t, va, origin(2))
- }
- r := scanf(strings.NewReader(GoString(str)), format, va)
- // if dmesgs {
- // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
- // }
- return r
- }
- // int sscanf(const char *str, const char *format, ...);
- func Xsscanf(t *TLS, str, format, va uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v va=%v, (%v:)", t, va, origin(2))
- }
- r := scanf(strings.NewReader(GoString(str)), format, va)
- // if dmesgs {
- // dmesg("%v: %q %q: %d", origin(1), GoString(str), GoString(format), r)
- // }
- return r
- }
- var _toint4 = Float64FromInt32(1) / Float64FromFloat64(2.220446049250313e-16)
- func Xrint(tls *TLS, x float64) float64 {
- if __ccgo_strace {
- trc("tls=%v x=%v, (%v:)", tls, x, origin(2))
- }
- bp := tls.Alloc(16)
- defer tls.Free(16)
- var e, s int32
- var y Tdouble_t
- var v1 float64
- var _ /* u at bp+0 */ struct {
- Fi [0]Tuint64_t
- Ff float64
- }
- _, _, _, _ = e, s, y, v1
- *(*struct {
- Fi [0]Tuint64_t
- Ff float64
- })(unsafe.Pointer(bp)) = struct {
- Fi [0]Tuint64_t
- Ff float64
- }{}
- *(*float64)(unsafe.Pointer(bp)) = x
- e = Int32FromUint64(*(*Tuint64_t)(unsafe.Pointer(bp)) >> int32(52) & uint64(0x7ff))
- s = Int32FromUint64(*(*Tuint64_t)(unsafe.Pointer(bp)) >> int32(63))
- if e >= Int32FromInt32(0x3ff)+Int32FromInt32(52) {
- return x
- }
- if s != 0 {
- y = x - _toint4 + _toint4
- } else {
- y = x + _toint4 - _toint4
- }
- if y == Float64FromInt32(0) {
- if s != 0 {
- v1 = -Float64FromFloat64(0)
- } else {
- v1 = Float64FromInt32(0)
- }
- return v1
- }
- return y
- }
- // FILE *fdopen(int fd, const char *mode);
- func Xfdopen(t *TLS, fd int32, mode uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v fd=%v mode=%v, (%v:)", t, fd, mode, origin(2))
- }
- panic(todo(""))
- }
- // struct tm *_gmtime64( const __time64_t *sourceTime );
- func X_gmtime64(t *TLS, sourceTime uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v sourceTime=%v, (%v:)", t, sourceTime, origin(2))
- }
- r0, _, err := procGmtime64.Call(uintptr(sourceTime))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return uintptr(r0)
- }
- // __time64_t _mktime64(struct tm *timeptr);
- func X_mktime64(t *TLS, timeptr uintptr) time.X__time64_t {
- if __ccgo_strace {
- trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
- }
- return time.X__time64_t(Xmktime(t, timeptr))
- }
- // char * gai_strerrorA(int ecode);
- func Xgai_strerrorA(t *TLS, ecode int32) uintptr {
- if __ccgo_strace {
- trc("t=%v ecode=%v, (%v:)", t, ecode, origin(2))
- }
- panic(todo(""))
- }
- // https://github.com/Alexpux/mingw-w64/blob/master/mingw-w64-headers/crt/sys/timeb.h#L69
- //
- // struct __timeb64 {
- // __time64_t time;
- // unsigned short millitm;
- // short timezone;
- // short dstflag;
- // };
- type __timeb64 struct {
- time types.X__time64_t
- millitm uint32
- timezone int16
- dstflag int16
- }
- // void _ftime64( struct __timeb64 *timeptr );
- func X_ftime64(t *TLS, timeptr uintptr) {
- if __ccgo_strace {
- trc("t=%v timeptr=%v, (%v:)", t, timeptr, origin(2))
- }
- tm := gotime.Now()
- (*__timeb64)(unsafe.Pointer(timeptr)).time = types.X__time64_t(tm.Unix())
- //TODO When Go 1.16 is no more supported
- // (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(tm.UnixMilli() % 1000)
- (*__timeb64)(unsafe.Pointer(timeptr)).millitm = uint32(int64(tm.Nanosecond()) / 1e6)
- }
- func X__ccgo_getMutexType(tls *TLS, m uintptr) int32 { /* pthread_mutex_lock.c:3:5: */
- if __ccgo_strace {
- trc("tls=%v m=%v, (%v:)", tls, m, origin(2))
- }
- return *(*int32)(unsafe.Pointer(m)) & 15
- }
- func X__ccgo_pthreadAttrGetDetachState(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:3:5: */
- if __ccgo_strace {
- trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
- }
- return *(*int32)(unsafe.Pointer(a))
- }
- func X__ccgo_pthreadMutexattrGettype(tls *TLS, a uintptr) int32 { /* pthread_attr_get.c:93:5: */
- if __ccgo_strace {
- trc("tls=%v a=%v, (%v:)", tls, a, origin(2))
- }
- return *(*int32)(unsafe.Pointer(a)) & int32(3)
- }
- func Xchmod(t *TLS, pathname uintptr, mode int32) int32 {
- r0, _, err := procChmod.Call(pathname, uintptr(mode))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // typedef enum _COMPUTER_NAME_FORMAT {
- // ComputerNameNetBIOS,
- // ComputerNameDnsHostname,
- // ComputerNameDnsDomain,
- // ComputerNameDnsFullyQualified,
- // ComputerNamePhysicalNetBIOS,
- // ComputerNamePhysicalDnsHostname,
- // ComputerNamePhysicalDnsDomain,
- // ComputerNamePhysicalDnsFullyQualified,
- // ComputerNameMax
- // } COMPUTER_NAME_FORMAT;
- // BOOL GetComputerNameExW(
- //
- // [in] COMPUTER_NAME_FORMAT NameType,
- // [out] LPWSTR lpBuffer,
- // [in, out] LPDWORD nSize
- //
- // );
- func XGetComputerNameExW(t *TLS, nameType int32, lpBuffer, nSize uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v nameType=%v nSize=%v, (%v:)", t, nameType, nSize, origin(2))
- }
- r0, _, err := procGetComputerNameExW.Call(uintptr(nameType), lpBuffer, nSize)
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // double _copysign(
- //
- // double x,
- // double y
- //
- // );
- func X_copysign(t *TLS, x, y float64) float64 {
- if __ccgo_strace {
- trc("t=%v y=%v, (%v:)", t, y, origin(2))
- }
- return Xcopysign(t, x, y)
- }
- // int _wtoi(
- //
- // const wchar_t *str
- //
- // );
- func X_wtoi(t *TLS, str uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v str=%v, (%v:)", t, str, origin(2))
- }
- panic(todo(""))
- }
- func allocW(t *TLS, v string) (r uintptr) {
- s := utf16.Encode([]rune(v))
- p := Xcalloc(t, types.Size_t(len(s)+1), 2)
- if p == 0 {
- panic(todo(""))
- }
- r = p
- for _, v := range s {
- *(*uint16)(unsafe.Pointer(p)) = v
- p += 2
- }
- return r
- }
- // wchar_t *_wgetenv(
- //
- // const wchar_t *varname
- //
- // );
- func X_wgetenv(t *TLS, varname uintptr) uintptr {
- if __ccgo_strace {
- trc("t=%v varname=%v, (%v:)", t, varname, origin(2))
- }
- if !wenvValid {
- bootWinEnviron(t)
- }
- k := strings.ToLower(goWideStringNZ(varname))
- for _, v := range winEnviron[:len(winEnviron)-1] {
- s := strings.ToLower(goWideStringNZ(v))
- x := strings.IndexByte(s, '=')
- if s[:x] == k {
- // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), goWideStringNZ(v))
- return v
- }
- }
- // trc("%v: %q -> %q", origin(1), goWideStringNZ(varname), "")
- return 0
- }
- // int _wputenv(
- //
- // const wchar_t *envstring
- //
- // );
- func X_wputenv(t *TLS, envstring uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v envstring=%v, (%v:)", t, envstring, origin(2))
- }
- if !wenvValid {
- bootWinEnviron(t)
- }
- s0 := goWideStringNZ(envstring)
- s := strings.ToLower(s0)
- x := strings.IndexByte(s, '=')
- k := s[:x]
- for i, v := range winEnviron[:len(winEnviron)-1] {
- s2 := strings.ToLower(goWideStringNZ(v))
- x := strings.IndexByte(s2, '=')
- if s2[:x] == k {
- Xfree(t, v)
- winEnviron[i] = allocW(t, s0)
- return 0
- }
- }
- np := allocW(t, s0)
- winEnviron = winEnviron[:len(winEnviron)-1]
- winEnviron = append(winEnviron, np, 0)
- wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
- return 0
- }
- func bootWinEnviron(t *TLS) {
- winEnviron = winEnviron[:0]
- p := Environ()
- for {
- q := *(*uintptr)(unsafe.Pointer(p))
- p += unsafe.Sizeof(uintptr(0))
- if q == 0 {
- break
- }
- s := GoString(q)
- // trc("%v: %q", origin(1), s)
- r := allocW(t, s)
- winEnviron = append(winEnviron, r)
- }
- wenviron = uintptr(unsafe.Pointer(&winEnviron[0]))
- wenvValid = true
- }
- func Xfabsl(t *TLS, x float64) float64 {
- if __ccgo_strace {
- trc("t=%v x=%v, (%v:)", t, x, origin(2))
- }
- return math.Abs(x)
- }
- func X__stdio_common_vfprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vfprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vfprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vfscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vfwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vfwscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsnprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsnwprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsprintf_p(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vsscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vswprintf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vswprintf_s(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X__stdio_common_vswscanf(t *TLS, args ...interface{}) int32 { panic("TODO") }
- func X_lseeki64(t *TLS, fd int32, offset int64, whence int32) int64 {
- if __ccgo_strace {
- trc("t=%v fd=%v offset=%v whence=%v, (%v:)", t, fd, offset, whence, origin(2))
- }
- f, ok := fdToFile(fd)
- if !ok {
- t.setErrno(errno.EBADF)
- return -1
- }
- n, err := windows.Seek(f.Handle, offset, int(whence))
- if err != nil {
- if dmesgs {
- dmesg("%v: fd %v, off %#x, whence %v: %v", origin(1), f._fd, offset, whenceStr(whence), n)
- }
- t.setErrno(err)
- return -1
- }
- if dmesgs {
- dmesg("%v: fd %v, off %#x, whence %v: ok", origin(1), f._fd, offset, whenceStr(whence))
- }
- return n
- }
- func Xislower(tls *TLS, c int32) int32 { /* islower.c:4:5: */
- if __ccgo_strace {
- trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
- }
- return Bool32(uint32(c)-uint32('a') < uint32(26))
- }
- func Xisupper(tls *TLS, c int32) int32 { /* isupper.c:4:5: */
- if __ccgo_strace {
- trc("tls=%v c=%v, (%v:)", tls, c, origin(2))
- }
- return Bool32(uint32(c)-uint32('A') < uint32(26))
- }
- // int access(const char *pathname, int mode);
- func Xaccess(t *TLS, pathname uintptr, mode int32) int32 {
- if __ccgo_strace {
- trc("t=%v pathname=%v mode=%v, (%v:)", t, pathname, mode, origin(2))
- }
- r0, _, err := procAccess.Call(uintptr(pathname), uintptr(mode))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- // int _vscprintf(const char *format, va_list argptr);
- func X_vscprintf(t *TLS, format uintptr, argptr uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v format=%v argptr=%v, (%v:)", t, format, argptr, origin(2))
- }
- return int32(len(printf(format, argptr)))
- }
- // int _stat32i64(const char *path, struct _stat32i64 *buffer);
- func X_stat64i32(t *TLS, path uintptr, buffer uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v path=%v buffer=%v, (%v:)", t, path, buffer, origin(2))
- }
- r0, _, err := procStat64i32.Call(uintptr(path), uintptr(buffer))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return int32(r0)
- }
- func AtomicLoadNUint8(ptr uintptr, memorder int32) uint8 {
- return byte(a_load_8(ptr))
- }
- // struct tm *gmtime( const time_t *sourceTime );
- // func Xgmtime(t *TLS, sourceTime uintptr) uintptr {
- // if __ccgo_strace {
- // trc("t=%v sourceTime=%v, (%v:)", t, sourceTime, origin(2))
- // }
- // r0, _, err := procGmtime.Call(uintptr(sourceTime))
- // if err != windows.NOERROR {
- // t.setErrno(err)
- // }
- // return uintptr(r0)
- // }
- var _tm time.Tm
- // /tmp/libc/musl-master/src/time/gmtime.c:4:11:
- func Xgmtime(tls *TLS, t uintptr) (r uintptr) { // /tmp/libc/musl-master/src/time/gmtime.c:7:2:
- if __ccgo_strace {
- trc("tls=%v t=%v, (%v:)", tls, t, origin(2))
- defer func() { trc("-> %v", r) }()
- }
- r = Xgmtime_r(tls, t, uintptr(unsafe.Pointer(&_tm)))
- return r
- }
- var _days_in_month = [12]int8{
- 0: int8(31),
- 1: int8(30),
- 2: int8(31),
- 3: int8(30),
- 4: int8(31),
- 5: int8(31),
- 6: int8(30),
- 7: int8(31),
- 8: int8(30),
- 9: int8(31),
- 10: int8(31),
- 11: int8(29),
- }
- var x___utc = [4]int8{'U', 'T', 'C'}
- func Xgmtime_r(tls *TLS, t uintptr, tm uintptr) (r uintptr) {
- if __ccgo_strace {
- trc("tls=%v t=%v tm=%v, (%v:)", tls, t, tm, origin(2))
- defer func() { trc("-> %v", r) }()
- }
- if x___secs_to_tm(tls, int64(*(*time.Time_t)(unsafe.Pointer(t))), tm) < 0 {
- *(*int32)(unsafe.Pointer(X__errno_location(tls))) = int32(errno.EOVERFLOW)
- return uintptr(0)
- }
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_isdst = 0
- return tm
- }
- func x___secs_to_tm(tls *TLS, t int64, tm uintptr) (r int32) {
- var c_cycles, leap, months, q_cycles, qc_cycles, remdays, remsecs, remyears, wday, yday int32
- var days, secs, years int64
- _, _, _, _, _, _, _, _, _, _, _, _, _ = c_cycles, days, leap, months, q_cycles, qc_cycles, remdays, remsecs, remyears, secs, wday, yday, years
- /* Reject time_t values whose year would overflow int */
- if t < int64(-Int32FromInt32(1)-Int32FromInt32(0x7fffffff))*Int64FromInt64(31622400) || t > Int64FromInt32(limits.INT_MAX)*Int64FromInt64(31622400) {
- return -int32(1)
- }
- secs = t - (Int64FromInt64(946684800) + int64(Int32FromInt32(86400)*(Int32FromInt32(31)+Int32FromInt32(29))))
- days = secs / int64(86400)
- remsecs = int32(secs % int64(86400))
- if remsecs < 0 {
- remsecs += int32(86400)
- days--
- }
- wday = int32((int64(3) + days) % int64(7))
- if wday < 0 {
- wday += int32(7)
- }
- qc_cycles = int32(days / int64(Int32FromInt32(365)*Int32FromInt32(400)+Int32FromInt32(97)))
- remdays = int32(days % int64(Int32FromInt32(365)*Int32FromInt32(400)+Int32FromInt32(97)))
- if remdays < 0 {
- remdays += Int32FromInt32(365)*Int32FromInt32(400) + Int32FromInt32(97)
- qc_cycles--
- }
- c_cycles = remdays / (Int32FromInt32(365)*Int32FromInt32(100) + Int32FromInt32(24))
- if c_cycles == int32(4) {
- c_cycles--
- }
- remdays -= c_cycles * (Int32FromInt32(365)*Int32FromInt32(100) + Int32FromInt32(24))
- q_cycles = remdays / (Int32FromInt32(365)*Int32FromInt32(4) + Int32FromInt32(1))
- if q_cycles == int32(25) {
- q_cycles--
- }
- remdays -= q_cycles * (Int32FromInt32(365)*Int32FromInt32(4) + Int32FromInt32(1))
- remyears = remdays / int32(365)
- if remyears == int32(4) {
- remyears--
- }
- remdays -= remyears * int32(365)
- leap = BoolInt32(!(remyears != 0) && (q_cycles != 0 || !(c_cycles != 0)))
- yday = remdays + int32(31) + int32(28) + leap
- if yday >= int32(365)+leap {
- yday -= int32(365) + leap
- }
- years = int64(remyears+int32(4)*q_cycles+int32(100)*c_cycles) + int64(400)*int64(int64(qc_cycles))
- months = 0
- for {
- if !(int32(_days_in_month[months]) <= remdays) {
- break
- }
- remdays -= int32(_days_in_month[months])
- goto _1
- _1:
- months++
- }
- if months >= int32(10) {
- months -= int32(12)
- years++
- }
- if years+int64(100) > int64(limits.INT_MAX) || years+int64(100) < int64(-Int32FromInt32(1)-Int32FromInt32(0x7fffffff)) {
- return -int32(1)
- }
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_year = int32(years + int64(100))
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_mon = months + int32(2)
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_mday = remdays + int32(1)
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_wday = wday
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_yday = yday
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_hour = remsecs / int32(3600)
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_min = remsecs / int32(60) % int32(60)
- (*time.Tm)(unsafe.Pointer(tm)).Ftm_sec = remsecs % int32(60)
- return 0
- }
- // size_t strftime(
- //
- // char *strDest,
- // size_t maxsize,
- // const char *format,
- // const struct tm *timeptr
- //
- // );
- func Xstrftime(tls *TLS, s uintptr, n size_t, f uintptr, tm uintptr) (r size_t) {
- if __ccgo_strace {
- trc("tls=%v s=%v n=%v f=%v tm=%v, (%v:)", tls, s, n, f, tm, origin(2))
- defer func() { trc("-> %v", r) }()
- }
- tt := gotime.Date(
- int((*time.Tm)(unsafe.Pointer(tm)).Ftm_year+1900),
- gotime.Month((*time.Tm)(unsafe.Pointer(tm)).Ftm_mon+1),
- int((*time.Tm)(unsafe.Pointer(tm)).Ftm_mday),
- int((*time.Tm)(unsafe.Pointer(tm)).Ftm_hour),
- int((*time.Tm)(unsafe.Pointer(tm)).Ftm_min),
- int((*time.Tm)(unsafe.Pointer(tm)).Ftm_sec),
- 0,
- gotime.UTC,
- )
- fmt := GoString(f)
- var result string
- if fmt != "" {
- result = strftime.Format(fmt, tt)
- }
- switch r = size_t(len(result)); {
- case r > n:
- r = 0
- default:
- copy((*RawMem)(unsafe.Pointer(s))[:r:r], result)
- *(*byte)(unsafe.Pointer(s + uintptr(r))) = 0
- }
- return r
- }
- func X__mingw_strtod(t *TLS, s uintptr, p uintptr) float64 {
- return Xstrtod(t, s, p)
- }
- func Xstrtod(t *TLS, s uintptr, p uintptr) float64 {
- if __ccgo_strace {
- trc("tls=%v s=%v p=%v, (%v:)", t, s, p, origin(2))
- }
- r0, _, err := procStrtod.Call(uintptr(s), uintptr(p))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return math.Float64frombits(uint64(r0))
- }
- // int vsnprintf(char *str, size_t size, const char *format, va_list ap);
- func X_vsnprintf(t *TLS, str uintptr, size types.Size_t, format, ap uintptr) int32 {
- if __ccgo_strace {
- trc("t=%v str=%v size=%v ap=%v, (%v:)", t, str, size, ap, origin(2))
- }
- return Xvsnprintf(t, str, size, format, ap)
- }
- func X__ccgo_SyscallFP() {
- s := fmt.Sprintf("%s\nTODO syscall: function pointer", debug.Stack())
- panic(s)
- }
- func CreateThread(t *TLS, lpThreadAttributes uintptr, dwStackSize types.Size_t, lpStartAddress, lpParameter uintptr, dwCreationFlags uint32, lpThreadId uintptr) uintptr {
- return XCreateThread(t, lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId)
- }
- // wchar_t *wcsncpy(wchar_t *strDest, const wchar_t *strSource, size_t count);
- func Xwcsncpy(t *TLS, strDest, strSource uintptr, count types.Size_t) uintptr {
- r0, _, err := procWcsncpy.Call(strDest, strSource, uintptr(count))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // wchar_t *wcsrchr(const wchar_t *str, wchar_t c);
- func Xwcsrchr(t *TLS, str uintptr, c types.Wchar_t) uintptr {
- r0, _, err := procWcsrchr.Call(str, uintptr(c))
- if err != windows.NOERROR {
- t.setErrno(err)
- }
- return r0
- }
- // __attribute__ ((__dllimport__)) char * __attribute__((__cdecl__)) _ctime64(const __time64_t *_Time);
- func X_ctime64(tls *TLS, __Time uintptr) (r uintptr) {
- if __ccgo_strace {
- trc("_Time=%+v", __Time)
- defer func() { trc(`X_ctime64->%+v`, r) }()
- }
- r0, _, err := procCtime64.Call(__Time)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return uintptr(r0)
- }
- // __attribute__ ((__dllimport__)) __time64_t __attribute__((__cdecl__)) _time64(__time64_t *_Time);
- func X_time64(tls *TLS, __Time uintptr) (r int64) {
- if __ccgo_strace {
- trc("_Time=%+v", __Time)
- defer func() { trc(`X_time64->%+v`, r) }()
- }
- r0, _, err := procTime64.Call(__Time)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int64(r0)
- }
- // __attribute__ ((__dllimport__)) int __attribute__((__cdecl__)) _strnicmp(const char *_Str1,const char *_Str2,size_t _MaxCount);
- func X_strnicmp(tls *TLS, __Str1 uintptr, __Str2 uintptr, __MaxCount types.Size_t) (r int32) {
- if __ccgo_strace {
- trc("_Str1=%+v _Str2=%+v _MaxCount=%+v", __Str1, __Str2, __MaxCount)
- defer func() { trc(`X_strnicmp->%+v`, r) }()
- }
- r0, _, err := procStrnicmp.Call(__Str1, __Str2, uintptr(__MaxCount))
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- func X__builtin_ctz(t *TLS, n uint32) int32 {
- return int32(mbits.TrailingZeros32(n))
- }
- // intptr_t _wfindfirst64i32(const wchar_t *filespec, struct _wfinddata64i32_t *fileinfo);
- func X_wfindfirst64i32(tls *TLS, filespec, fileinfo uintptr) (r types.Intptr_t) {
- r0, _, err := procWfindfirst64i32.Call(filespec, fileinfo)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return types.Intptr_t(r0)
- }
- // int _wfindnext64i32(intptr_t handle, struct _wfinddata64i32_t *fileinfo);
- func X_wfindnext64i32(tls *TLS, handle types.Intptr_t, fileinfo uintptr) (r int32) {
- r0, _, err := procWfindnext64i32.Call(uintptr(handle), fileinfo)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // int _wchmod( const wchar_t *filename, int pmode );
- func X_wchmod(tls *TLS, filename uintptr, pmode int32) (r int32) {
- r0, _, err := procWchmod.Call(filename, uintptr(pmode))
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // int _wmkdir(const wchar_t *dirname);
- func X_wmkdir(tls *TLS, dirname uintptr) (r int32) {
- r0, _, err := procWmkdir.Call(dirname)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // int _wstat64i32(const wchar_t *path, struct _stat64i32 *buffer);
- func X_wstat64i32(tls *TLS, path, buffer uintptr) (r int32) {
- r0, _, err := procWstat64i32.Call(path, buffer)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // intptr_t _wfindfirst32(const wchar_t *filespec, struct _wfinddata32_t *fileinfo);
- func X_wfindfirst32(tls *TLS, filespec, fileinfo uintptr) (r types.Intptr_t) {
- r0, _, err := procWfindfirst32.Call(filespec, fileinfo)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return types.Intptr_t(r0)
- }
- // int _wfindnext32(intptr_t handle, struct _wfinddata32_t *fileinfo);
- func X_wfindnext32(tls *TLS, handle types.Intptr_t, fileinfo uintptr) (r int32) {
- r0, _, err := procWfindnext32.Call(uintptr(handle), fileinfo)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
- // int _wstat32(const wchar_t *path, struct __stat32 *buffer);
- func X_wstat32(tls *TLS, path, buffer uintptr) (r int32) {
- r0, _, err := procWstat32.Call(path, buffer)
- if err != windows.NOERROR {
- tls.setErrno(int32(err.(windows.Errno)))
- }
- return int32(r0)
- }
|