linuxold.inc 140 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165
  1. {
  2. $Id$
  3. This file is part of the Free Pascal run time library.
  4. Copyright (c) 1999-2000 by Michael Van Canneyt,
  5. BSD parts (c) 2000 by Marco van de Voort
  6. members of the Free Pascal development team.
  7. See the file COPYING.FPC, included in this distribution,
  8. for details about the copyright.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY;without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. **********************************************************************}
  13. {$ifdef VER1_0}
  14. unit linux;
  15. {$else}
  16. unit oldlinux;
  17. {$endif}
  18. Interface
  19. Const
  20. { Things for LSEEK call }
  21. Seek_set = 0;
  22. Seek_Cur = 1;
  23. Seek_End = 2;
  24. { Things for OPEN call - after linux/fcntl.h }
  25. Open_Accmode = 3;
  26. Open_RdOnly = 0;
  27. Open_WrOnly = 1;
  28. Open_RdWr = 2;
  29. Open_Creat = 1 shl 6;
  30. Open_Excl = 2 shl 6;
  31. Open_NoCtty = 4 shl 6;
  32. Open_Trunc = 1 shl 9;
  33. Open_Append = 2 shl 9;
  34. Open_NonBlock = 4 shl 9;
  35. Open_NDelay = Open_NonBlock;
  36. Open_Sync = 1 shl 12;
  37. Open_Direct = 4 shl 12;
  38. Open_LargeFile = 1 shl 15;
  39. Open_Directory = 2 shl 15;
  40. Open_NoFollow = 4 shl 15;
  41. { The waitpid uses the following options:}
  42. Wait_NoHang = 1;
  43. Wait_UnTraced = 2;
  44. Wait_Any = -1;
  45. Wait_MyPGRP = 0;
  46. Wait_Clone = $80000000;
  47. { Constants to check stat.mode }
  48. STAT_IFMT = $f000; {00170000}
  49. STAT_IFSOCK = $c000; {0140000}
  50. STAT_IFLNK = $a000; {0120000}
  51. STAT_IFREG = $8000; {0100000}
  52. STAT_IFBLK = $6000; {0060000}
  53. STAT_IFDIR = $4000; {0040000}
  54. STAT_IFCHR = $2000; {0020000}
  55. STAT_IFIFO = $1000; {0010000}
  56. STAT_ISUID = $0800; {0004000}
  57. STAT_ISGID = $0400; {0002000}
  58. STAT_ISVTX = $0200; {0001000}
  59. { Constants to check permissions }
  60. STAT_IRWXO = $7;
  61. STAT_IROTH = $4;
  62. STAT_IWOTH = $2;
  63. STAT_IXOTH = $1;
  64. STAT_IRWXG = STAT_IRWXO shl 3;
  65. STAT_IRGRP = STAT_IROTH shl 3;
  66. STAT_IWGRP = STAT_IWOTH shl 3;
  67. STAT_IXGRP = STAT_IXOTH shl 3;
  68. STAT_IRWXU = STAT_IRWXO shl 6;
  69. STAT_IRUSR = STAT_IROTH shl 6;
  70. STAT_IWUSR = STAT_IWOTH shl 6;
  71. STAT_IXUSR = STAT_IXOTH shl 6;
  72. { Constants to test the type of filesystem }
  73. fs_old_ext2 = $ef51;
  74. fs_ext2 = $ef53;
  75. fs_ext = $137d;
  76. fs_iso = $9660;
  77. fs_minix = $137f;
  78. fs_minix_30 = $138f;
  79. fs_minux_V2 = $2468;
  80. fs_msdos = $4d44;
  81. fs_nfs = $6969;
  82. fs_proc = $9fa0;
  83. fs_xia = $012FD16D;
  84. { Constansts for MMAP }
  85. MAP_PRIVATE =2;
  86. MAP_ANONYMOUS =$20;
  87. {Constansts Termios/Ioctl (used in Do_IsDevice) }
  88. IOCtl_TCGETS=$5401; // TCGETS is also in termios.inc, but the sysunix needs only this
  89. type
  90. {
  91. Linux system calls take arguments as follows :
  92. cpui386/m68k:
  93. %eax/%d0 : System call number
  94. %ebx/%d1 : first argument
  95. %ecx/%d2 : second argument
  96. %edx/%d3 : third argumens
  97. %esi/%d3 : fourth argument
  98. %edi/%d4 : fifth argument
  99. That is why we define a special type, with only these arguments
  100. To make it processor independent, we don't give any system dependent
  101. names, but the rather abstract reg1,reg2 etc;
  102. }
  103. SysCallRegs=record
  104. reg1,reg2,reg3,reg4,reg5,reg6 : longint;
  105. end;
  106. PSysCallRegs=^SysCallRegs;
  107. TSysCallRegs=SysCallRegs;
  108. { The following are records for system calls }
  109. dirent = packed record
  110. ino,
  111. off : longint;
  112. reclen : word;
  113. name : array [0..255] of char;
  114. end;
  115. pdirent =^dirent;
  116. TDirEnt = dirent;
  117. TDir = packed record
  118. fd : integer;
  119. loc : longint;
  120. size : integer;
  121. buf : pdirent;
  122. {The following are used in libc, but NOT in the linux kernel sources ??}
  123. nextoff: longint;
  124. dd_max : integer; {size of buf. Irrelevant, as buf is of type dirent}
  125. lock : pointer;
  126. end;
  127. PDir =^TDir;
  128. dev_t = word;
  129. Stat = packed record
  130. dev : dev_t;
  131. pad1 : word;
  132. ino : longint;
  133. mode,
  134. nlink,
  135. uid,
  136. gid : word;
  137. rdev : dev_t;
  138. pad2 : word;
  139. size,
  140. blksze,
  141. blocks,
  142. atime,
  143. unused1,
  144. mtime,
  145. unused2,
  146. ctime,
  147. unused3,
  148. unused4,
  149. unused5 : longint;
  150. end;
  151. PStat=^Stat;
  152. TStat=Stat;
  153. Statfs = packed record
  154. fstype, { File system type }
  155. bsize, { Optimal block trensfer size }
  156. blocks, { Data blocks in system }
  157. bfree, { free blocks in system }
  158. bavail, { Available free blocks to non-root users }
  159. files, { File nodes in system }
  160. ffree, { Free file nodes in system }
  161. fsid, { File system ID }
  162. namelen : longint; { Maximum name length in system }
  163. spare : array [0..6] of longint; { For later use }
  164. end;
  165. PStatFS=^StatFS;
  166. TStatFS=StatFS;
  167. fdSet=array[0..7] of longint;{=256 bits}
  168. pfdset=^fdset;
  169. TFDSet=fdset;
  170. timeval = packed record
  171. sec,usec:longint
  172. end;
  173. ptimeval=^timeval;
  174. TTimeVal=timeval;
  175. timespec = packed record
  176. tv_sec,tv_nsec:longint;
  177. end;
  178. timezone = packed record
  179. minuteswest,dsttime:longint;
  180. end;
  181. ptimezone =^timezone;
  182. TTimeZone = timezone;
  183. utsname = packed record
  184. sysname,
  185. nodename,
  186. release,
  187. version,
  188. machine,
  189. domainname : Array[0..64] of char;
  190. end;
  191. PUTSName=^UTSName;
  192. TUTSName=UTSName;
  193. { Get System call numbers and error-numbers}
  194. const
  195. syscall_nr_setup = 0;
  196. syscall_nr_exit = 1;
  197. syscall_nr_fork = 2;
  198. syscall_nr_read = 3;
  199. syscall_nr_write = 4;
  200. syscall_nr_open = 5;
  201. syscall_nr_close = 6;
  202. syscall_nr_waitpid = 7;
  203. syscall_nr_creat = 8;
  204. syscall_nr_link = 9;
  205. syscall_nr_unlink = 10;
  206. syscall_nr_execve = 11;
  207. syscall_nr_chdir = 12;
  208. syscall_nr_time = 13;
  209. syscall_nr_mknod = 14;
  210. syscall_nr_chmod = 15;
  211. syscall_nr_chown = 16;
  212. syscall_nr_break = 17;
  213. syscall_nr_oldstat = 18;
  214. syscall_nr_lseek = 19;
  215. syscall_nr_getpid = 20;
  216. syscall_nr_mount = 21;
  217. syscall_nr_umount = 22;
  218. syscall_nr_setuid = 23;
  219. syscall_nr_getuid = 24;
  220. syscall_nr_stime = 25;
  221. syscall_nr_ptrace = 26;
  222. syscall_nr_alarm = 27;
  223. syscall_nr_oldfstat = 28;
  224. syscall_nr_pause = 29;
  225. syscall_nr_utime = 30;
  226. syscall_nr_stty = 31;
  227. syscall_nr_gtty = 32;
  228. syscall_nr_access = 33;
  229. syscall_nr_nice = 34;
  230. syscall_nr_ftime = 35;
  231. syscall_nr_sync = 36;
  232. syscall_nr_kill = 37;
  233. syscall_nr_rename = 38;
  234. syscall_nr_mkdir = 39;
  235. syscall_nr_rmdir = 40;
  236. syscall_nr_dup = 41;
  237. syscall_nr_pipe = 42;
  238. syscall_nr_times = 43;
  239. syscall_nr_prof = 44;
  240. syscall_nr_brk = 45;
  241. syscall_nr_setgid = 46;
  242. syscall_nr_getgid = 47;
  243. syscall_nr_signal = 48;
  244. syscall_nr_geteuid = 49;
  245. syscall_nr_getegid = 50;
  246. syscall_nr_acct = 51;
  247. syscall_nr_phys = 52;
  248. syscall_nr_lock = 53;
  249. syscall_nr_ioctl = 54;
  250. syscall_nr_fcntl = 55;
  251. syscall_nr_mpx = 56;
  252. syscall_nr_setpgid = 57;
  253. syscall_nr_ulimit = 58;
  254. syscall_nr_oldolduname = 59;
  255. syscall_nr_umask = 60;
  256. syscall_nr_chroot = 61;
  257. syscall_nr_ustat = 62;
  258. syscall_nr_dup2 = 63;
  259. syscall_nr_getppid = 64;
  260. syscall_nr_getpgrp = 65;
  261. syscall_nr_setsid = 66;
  262. syscall_nr_sigaction = 67;
  263. syscall_nr_sgetmask = 68;
  264. syscall_nr_ssetmask = 69;
  265. syscall_nr_setreuid = 70;
  266. syscall_nr_setregid = 71;
  267. syscall_nr_sigsuspend = 72;
  268. syscall_nr_sigpending = 73;
  269. syscall_nr_sethostname = 74;
  270. syscall_nr_setrlimit = 75;
  271. syscall_nr_getrlimit = 76;
  272. syscall_nr_getrusage = 77;
  273. syscall_nr_gettimeofday = 78;
  274. syscall_nr_settimeofday = 79;
  275. syscall_nr_getgroups = 80;
  276. syscall_nr_setgroups = 81;
  277. syscall_nr_select = 82;
  278. syscall_nr_symlink = 83;
  279. syscall_nr_oldlstat = 84;
  280. syscall_nr_readlink = 85;
  281. syscall_nr_uselib = 86;
  282. syscall_nr_swapon = 87;
  283. syscall_nr_reboot = 88;
  284. syscall_nr_readdir = 89;
  285. syscall_nr_mmap = 90;
  286. syscall_nr_munmap = 91;
  287. syscall_nr_truncate = 92;
  288. syscall_nr_ftruncate = 93;
  289. syscall_nr_fchmod = 94;
  290. syscall_nr_fchown = 95;
  291. syscall_nr_getpriority = 96;
  292. syscall_nr_setpriority = 97;
  293. syscall_nr_profil = 98;
  294. syscall_nr_statfs = 99;
  295. syscall_nr_fstatfs = 100;
  296. syscall_nr_ioperm = 101;
  297. syscall_nr_socketcall = 102;
  298. syscall_nr_syslog = 103;
  299. syscall_nr_setitimer = 104;
  300. syscall_nr_getitimer = 105;
  301. syscall_nr_stat = 106;
  302. syscall_nr_lstat = 107;
  303. syscall_nr_fstat = 108;
  304. syscall_nr_olduname = 109;
  305. syscall_nr_iopl = 110;
  306. syscall_nr_vhangup = 111;
  307. syscall_nr_idle = 112;
  308. syscall_nr_vm86old = 113;
  309. syscall_nr_wait4 = 114;
  310. syscall_nr_swapoff = 115;
  311. syscall_nr_sysinfo = 116;
  312. syscall_nr_ipc = 117;
  313. syscall_nr_fsync = 118;
  314. syscall_nr_sigreturn = 119;
  315. syscall_nr_clone = 120;
  316. syscall_nr_setdomainname = 121;
  317. syscall_nr_uname = 122;
  318. syscall_nr_modify_ldt = 123;
  319. syscall_nr_adjtimex = 124;
  320. syscall_nr_mprotect = 125;
  321. syscall_nr_sigprocmask = 126;
  322. syscall_nr_create_module = 127;
  323. syscall_nr_init_module = 128;
  324. syscall_nr_delete_module = 129;
  325. syscall_nr_get_kernel_syms = 130;
  326. syscall_nr_quotactl = 131;
  327. syscall_nr_getpgid = 132;
  328. syscall_nr_fchdir = 133;
  329. syscall_nr_bdflush = 134;
  330. syscall_nr_sysfs = 135;
  331. syscall_nr_personality = 136;
  332. syscall_nr_afs_syscall = 137;
  333. syscall_nr_setfsuid = 138;
  334. syscall_nr_setfsgid = 139;
  335. syscall_nr__llseek = 140;
  336. syscall_nr_getdents = 141;
  337. syscall_nr__newselect = 142;
  338. syscall_nr_flock = 143;
  339. syscall_nr_msync = 144;
  340. syscall_nr_readv = 145;
  341. syscall_nr_writev = 146;
  342. syscall_nr_getsid = 147;
  343. syscall_nr_fdatasync = 148;
  344. syscall_nr__sysctl = 149;
  345. syscall_nr_mlock = 150;
  346. syscall_nr_munlock = 151;
  347. syscall_nr_mlockall = 152;
  348. syscall_nr_munlockall = 153;
  349. syscall_nr_sched_setparam = 154;
  350. syscall_nr_sched_getparam = 155;
  351. syscall_nr_sched_setscheduler = 156;
  352. syscall_nr_sched_getscheduler = 157;
  353. syscall_nr_sched_yield = 158;
  354. syscall_nr_sched_get_priority_max = 159;
  355. syscall_nr_sched_get_priority_min = 160;
  356. syscall_nr_sched_rr_get_interval = 161;
  357. syscall_nr_nanosleep = 162;
  358. syscall_nr_mremap = 163;
  359. syscall_nr_setresuid = 164;
  360. syscall_nr_getresuid = 165;
  361. syscall_nr_vm86 = 166;
  362. syscall_nr_query_module = 167;
  363. syscall_nr_poll = 168;
  364. syscall_nr_sigaltstack = 186;
  365. {$IFDEF SYSCALL_DEBUG}
  366. const
  367. Sys_nr_txt : array[0..168] of string[15]=(
  368. 'Setup', { 0 }
  369. 'Exit', { 1 }
  370. 'Fork', { 2 }
  371. 'Read', { 3 }
  372. 'Write', { 4 }
  373. 'Open', { 5 }
  374. 'Close', { 6 }
  375. 'WaitPid', { 7 }
  376. 'Create', { 8 }
  377. 'Link', { 9 }
  378. 'UnLink', { 10 }
  379. 'ExecVe', { 11 }
  380. 'ChDir', { 12 }
  381. 'Time', { 13 }
  382. 'MkNod', { 14 }
  383. 'ChMod', { 15 }
  384. 'ChOwn', { 16 }
  385. 'Break', { 17 }
  386. 'OldState', { 18 }
  387. 'LSeek', { 19 }
  388. 'GetPid', { 20 }
  389. 'Mount', { 21 }
  390. 'UMount', { 22 }
  391. 'SetUid', { 23 }
  392. 'GetUid', { 24 }
  393. 'STime', { 25 }
  394. 'PTrace', { 26 }
  395. 'Alarm', { 27 }
  396. 'OldFStat', { 28 }
  397. 'Pause', { 29 }
  398. 'UTime', { 30 }
  399. 'STTY', { 31 }
  400. 'GTTY', { 32 }
  401. 'Access', { 33 }
  402. 'Nice', { 34 }
  403. 'FTime', { 35 }
  404. 'Sync', { 36 }
  405. 'Kill', { 37 }
  406. 'Rename', { 38 }
  407. 'MkDir', { 39 }
  408. 'RmDir', { 40 }
  409. 'Dup', { 41 }
  410. 'Pipe', { 42 }
  411. 'Times', { 43 }
  412. 'Prof', { 44 }
  413. 'Break', { 45 }
  414. 'SetGid', { 46 }
  415. 'GetGid', { 47 }
  416. 'Signal', { 48 }
  417. 'GetEUid', { 49 }
  418. 'GetEGid', { 50 }
  419. 'Acct', { 51 }
  420. 'Phys', { 52 }
  421. 'Lock', { 53 }
  422. 'IOCtl', { 54 }
  423. 'FCNtl', { 55 }
  424. 'Mpx', { 56 }
  425. 'SetPGid', { 57 }
  426. 'ULimit', { 58 }
  427. 'OldOldUName', { 59 }
  428. 'UMask', { 60 }
  429. 'ChRoot', { 61 }
  430. 'UStat', { 62 }
  431. 'Dup2', { 63 }
  432. 'GetPPid', { 64 }
  433. 'GetPGrp', { 65 }
  434. 'SetSid', { 66 }
  435. 'SigAction', { 67 }
  436. 'SGetMask', { 68 }
  437. 'SSetMask', { 69 }
  438. 'SetReUid', { 70 }
  439. 'SetReGid', { 71 }
  440. 'SigSuspend', { 72 }
  441. 'SigPending', { 73 }
  442. 'SetHostName', { 74 }
  443. 'SetRLimit', { 75 }
  444. 'GetRLimit', { 76 }
  445. 'GetRUsage', { 77 }
  446. 'GetTimeOfDay', { 78 }
  447. 'SetTimeOfDay', { 79 }
  448. 'GetGroups', { 80 }
  449. 'SetGroups', { 81 }
  450. 'Select', { 82 }
  451. 'SymLink', { 83 }
  452. 'OldLStat', { 84 }
  453. 'ReadLink', { 85 }
  454. 'UseLib', { 86 }
  455. 'SwapOn', { 87 }
  456. 'Reboot', { 88 }
  457. 'ReadDir', { 89 }
  458. 'MMap', { 90 }
  459. 'MunMap', { 91 }
  460. 'Truncate', { 92 }
  461. 'FTruncate', { 93 }
  462. 'FChMod', { 94 }
  463. 'FChOwn', { 95 }
  464. 'GetPriority', { 96 }
  465. 'SetPriority', { 97 }
  466. 'Profile', { 98 }
  467. 'StatFs', { 99 }
  468. 'FStatFs', { 100 }
  469. 'IOPerm', { 101 }
  470. 'SocketCall', { 102 }
  471. 'SysLog', { 103 }
  472. 'SetITimer', { 104 }
  473. 'GetITimer', { 105 }
  474. 'Stat', { 106 }
  475. 'LStat', { 107 }
  476. 'FStat', { 108 }
  477. 'OldUName', { 109 }
  478. 'IOPl', { 110 }
  479. 'VHangup', { 111 }
  480. 'Idle', { 112 }
  481. 'VM86', { 113 }
  482. 'Wait4', { 114 }
  483. 'SwapOff', { 115 }
  484. 'SysInfo', { 116 }
  485. 'IPC', { 117 }
  486. 'FSync', { 118 }
  487. 'SigReturn', { 119 }
  488. 'Clone', { 120 }
  489. 'SetDomainName', { 121 }
  490. 'UName', { 122 }
  491. 'Modify_Ldt', { 123 }
  492. 'AdjTimeX', { 124 }
  493. 'MProtect', { 125 }
  494. 'SigProcMask', { 126 }
  495. 'Create_Module', { 127 }
  496. 'Init_Module', { 128 }
  497. 'Delete_Module', { 129 }
  498. 'Get_Kernel_Syms', { 130 }
  499. 'QuotaCtl', { 131 }
  500. 'GetPGid', { 132 }
  501. 'FChDir', { 133 }
  502. 'BDFlush', { 134 }
  503. 'SysFs', { 135 }
  504. 'Personality', { 136 }
  505. 'AFS_SysCall', { 137 }
  506. 'SetFsUid', { 138 }
  507. 'SetFsGid', { 139 }
  508. '__LLSeek', { 140 }
  509. 'GetDents', { 141 }
  510. '__NewSelect', { 142 }
  511. 'FLock', { 143 }
  512. 'MSync', { 144 }
  513. 'ReadV', { 145 }
  514. 'WriteV', { 146 }
  515. 'GetSid', { 147 }
  516. 'FDataSync', { 148 }
  517. '__SysCtl', { 149 }
  518. 'MLock', { 150 }
  519. 'MUnLock', { 151 }
  520. 'MLockAll', { 152 }
  521. 'MUnLockAll', { 153 }
  522. 'MSchdSetParam', { 154 }
  523. 'MSchdGetParam', { 155 }
  524. 'MSchdSetSchd', { 156 }
  525. 'MSchdGetSchd', { 157 }
  526. 'MSchdYield', { 158 }
  527. 'MSchdGetPriMax', { 159 }
  528. 'MSchdGetPriMin', { 160 }
  529. 'MSchdRRGetInt', { 161 }
  530. 'NanoSleep', { 162 }
  531. 'MRemap', { 163 }
  532. 'SetReSuid', { 164 }
  533. 'GetReSuid', { 165 }
  534. 'vm86', { 166 }
  535. 'QueryModule', { 167 }
  536. 'Poll'); { 168 }
  537. {$ENDIF}
  538. Const
  539. Sys_EPERM = 1; { Operation not permitted }
  540. Sys_ENOENT = 2; { No such file or directory }
  541. Sys_ESRCH = 3; { No such process }
  542. Sys_EINTR = 4; { Interrupted system call }
  543. Sys_EIO = 5; { I/O error }
  544. Sys_ENXIO = 6; { No such device or address }
  545. Sys_E2BIG = 7; { Arg list too long }
  546. Sys_ENOEXEC = 8; { Exec format error }
  547. Sys_EBADF = 9; { Bad file number }
  548. Sys_ECHILD = 10; { No child processes }
  549. Sys_EAGAIN = 11; { Try again }
  550. Sys_ENOMEM = 12; { Out of memory }
  551. Sys_EACCES = 13; { Permission denied }
  552. Sys_EFAULT = 14; { Bad address }
  553. Sys_ENOTBLK = 15; { Block device required, NOT POSIX! }
  554. Sys_EBUSY = 16; { Device or resource busy }
  555. Sys_EEXIST = 17; { File exists }
  556. Sys_EXDEV = 18; { Cross-device link }
  557. Sys_ENODEV = 19; { No such device }
  558. Sys_ENOTDIR = 20; { Not a directory }
  559. Sys_EISDIR = 21; { Is a directory }
  560. Sys_EINVAL = 22; { Invalid argument }
  561. Sys_ENFILE = 23; { File table overflow }
  562. Sys_EMFILE = 24; { Too many open files }
  563. Sys_ENOTTY = 25; { Not a typewriter }
  564. Sys_ETXTBSY = 26; { Text file busy }
  565. Sys_EFBIG = 27; { File too large }
  566. Sys_ENOSPC = 28; { No space left on device }
  567. Sys_ESPIPE = 29; { Illegal seek }
  568. Sys_EROFS = 30; { Read-only file system }
  569. Sys_EMLINK = 31; { Too many links }
  570. Sys_EPIPE = 32; { Broken pipe }
  571. Sys_EDOM = 33; { Math argument out of domain of func }
  572. Sys_ERANGE = 34; { Math result not representable }
  573. Sys_EDEADLK = 35; { Resource deadlock would occur }
  574. Sys_ENAMETOOLONG= 36; { File name too long }
  575. Sys_ENOLCK = 37; { No record locks available }
  576. Sys_ENOSYS = 38; { Function not implemented }
  577. Sys_ENOTEMPTY= 39; { Directory not empty }
  578. Sys_ELOOP = 40; { Too many symbolic links encountered }
  579. Sys_EWOULDBLOCK = Sys_EAGAIN; { Operation would block }
  580. Sys_ENOMSG = 42; { No message of desired type }
  581. Sys_EIDRM = 43; { Identifier removed }
  582. Sys_ECHRNG = 44; { Channel number out of range }
  583. Sys_EL2NSYNC= 45; { Level 2 not synchronized }
  584. Sys_EL3HLT = 46; { Level 3 halted }
  585. Sys_EL3RST = 47; { Level 3 reset }
  586. Sys_ELNRNG = 48; { Link number out of range }
  587. Sys_EUNATCH = 49; { Protocol driver not attached }
  588. Sys_ENOCSI = 50; { No CSI structure available }
  589. Sys_EL2HLT = 51; { Level 2 halted }
  590. Sys_EBADE = 52; { Invalid exchange }
  591. Sys_EBADR = 53; { Invalid request descriptor }
  592. Sys_EXFULL = 54; { Exchange full }
  593. Sys_ENOANO = 55; { No anode }
  594. Sys_EBADRQC = 56; { Invalid request code }
  595. Sys_EBADSLT = 57; { Invalid slot }
  596. Sys_EDEADLOCK= 58; { File locking deadlock error }
  597. Sys_EBFONT = 59; { Bad font file format }
  598. Sys_ENOSTR = 60; { Device not a stream }
  599. Sys_ENODATA = 61; { No data available }
  600. Sys_ETIME = 62; { Timer expired }
  601. Sys_ENOSR = 63; { Out of streams resources }
  602. Sys_ENONET = 64; { Machine is not on the network }
  603. Sys_ENOPKG = 65; { Package not installed }
  604. Sys_EREMOTE = 66; { Object is remote }
  605. Sys_ENOLINK = 67; { Link has been severed }
  606. Sys_EADV = 68; { Advertise error }
  607. Sys_ESRMNT = 69; { Srmount error }
  608. Sys_ECOMM = 70; { Communication error on send }
  609. Sys_EPROTO = 71; { Protocol error }
  610. Sys_EMULTIHOP= 72; { Multihop attempted }
  611. Sys_EDOTDOT = 73; { RFS specific error }
  612. Sys_EBADMSG = 74; { Not a data message }
  613. Sys_EOVERFLOW= 75; { Value too large for defined data type }
  614. Sys_ENOTUNIQ= 76; { Name not unique on network }
  615. Sys_EBADFD = 77; { File descriptor in bad state }
  616. Sys_EREMCHG = 78; { Remote address changed }
  617. Sys_ELIBACC = 79; { Can not access a needed shared library }
  618. Sys_ELIBBAD = 80; { Accessing a corrupted shared library }
  619. Sys_ELIBSCN = 81; { .lib section in a.out corrupted }
  620. Sys_ELIBMAX = 82; { Attempting to link in too many shared libraries }
  621. Sys_ELIBEXEC= 83; { Cannot exec a shared library directly }
  622. Sys_EILSEQ = 84; { Illegal byte sequence }
  623. Sys_ERESTART= 85; { Interrupted system call should be restarted }
  624. Sys_ESTRPIPE= 86; { Streams pipe error }
  625. Sys_EUSERS = 87; { Too many users }
  626. Sys_ENOTSOCK= 88; { Socket operation on non-socket }
  627. Sys_EDESTADDRREQ= 89; { Destination address required }
  628. Sys_EMSGSIZE= 90; { Message too long }
  629. Sys_EPROTOTYPE= 91; { Protocol wrong type for socket }
  630. Sys_ENOPROTOOPT= 92; { Protocol not available }
  631. Sys_EPROTONOSUPPORT= 93; { Protocol not supported }
  632. Sys_ESOCKTNOSUPPORT= 94; { Socket type not supported }
  633. Sys_EOPNOTSUPP= 95; { Operation not supported on transport endpoint }
  634. Sys_EPFNOSUPPORT= 96; { Protocol family not supported }
  635. Sys_EAFNOSUPPORT= 97; { Address family not supported by protocol }
  636. Sys_EADDRINUSE= 98; { Address already in use }
  637. Sys_EADDRNOTAVAIL= 99; { Cannot assign requested address }
  638. Sys_ENETDOWN= 100; { Network is down }
  639. Sys_ENETUNREACH= 101; { Network is unreachable }
  640. Sys_ENETRESET= 102; { Network dropped connection because of reset }
  641. Sys_ECONNABORTED= 103; { Software caused connection abort }
  642. Sys_ECONNRESET= 104; { Connection reset by peer }
  643. Sys_ENOBUFS = 105; { No buffer space available }
  644. Sys_EISCONN = 106; { Transport endpoint is already connected }
  645. Sys_ENOTCONN= 107; { Transport endpoint is not connected }
  646. Sys_ESHUTDOWN= 108; { Cannot send after transport endpoint shutdown }
  647. Sys_ETOOMANYREFS= 109; { Too many references: cannot splice }
  648. Sys_ETIMEDOUT= 110; { Connection timed out }
  649. Sys_ECONNREFUSED= 111; { Connection refused }
  650. Sys_EHOSTDOWN= 112; { Host is down }
  651. Sys_EHOSTUNREACH= 113; { No route to host }
  652. Sys_EALREADY= 114; { Operation already in progress }
  653. Sys_EINPROGRESS= 115; { Operation now in progress }
  654. Sys_ESTALE = 116; { Stale NFS file handle }
  655. Sys_EUCLEAN = 117; { Structure needs cleaning }
  656. Sys_ENOTNAM = 118; { Not a XENIX named type file }
  657. Sys_ENAVAIL = 119; { No XENIX semaphores available }
  658. Sys_EISNAM = 120; { Is a named type file }
  659. Sys_EREMOTEIO= 121; { Remote I/O error }
  660. Sys_EDQUOT = 122; { Quota exceeded }
  661. { This value was suggested by Daniel
  662. based on infos from www.linuxassembly.org }
  663. Sys_ERROR_MAX = $fff;
  664. {$packrecords C}
  665. {********************
  666. Signal
  667. ********************}
  668. type
  669. SigSet = Longint;
  670. PSigSet = ^SigSet;
  671. Const
  672. { For sending a signal }
  673. SA_NOCLDSTOP = 1;
  674. SA_SHIRQ = $04000000;
  675. SA_STACK = $08000000;
  676. SA_RESTART = $10000000;
  677. SA_INTERRUPT = $20000000;
  678. SA_NOMASK = $40000000;
  679. SA_ONESHOT = $80000000;
  680. SA_ONSTACK = SA_STACK;
  681. SIG_BLOCK = 0;
  682. SIG_UNBLOCK = 1;
  683. SIG_SETMASK = 2;
  684. SIG_DFL = 0 ;
  685. SIG_IGN = 1 ;
  686. SIG_ERR = -1 ;
  687. SIGHUP = 1;
  688. SIGINT = 2;
  689. SIGQUIT = 3;
  690. SIGILL = 4;
  691. SIGTRAP = 5;
  692. SIGABRT = 6;
  693. SIGIOT = 6;
  694. SIGBUS = 7;
  695. SIGFPE = 8;
  696. SIGKILL = 9;
  697. SIGUSR1 = 10;
  698. SIGSEGV = 11;
  699. SIGUSR2 = 12;
  700. SIGPIPE = 13;
  701. SIGALRM = 14;
  702. SIGTerm = 15;
  703. SIGSTKFLT = 16;
  704. SIGCHLD = 17;
  705. SIGCONT = 18;
  706. SIGSTOP = 19;
  707. SIGTSTP = 20;
  708. SIGTTIN = 21;
  709. SIGTTOU = 22;
  710. SIGURG = 23;
  711. SIGXCPU = 24;
  712. SIGXFSZ = 25;
  713. SIGVTALRM = 26;
  714. SIGPROF = 27;
  715. SIGWINCH = 28;
  716. SIGIO = 29;
  717. SIGPOLL = SIGIO;
  718. SIGPWR = 30;
  719. SIGUNUSED = 31;
  720. const
  721. SI_PAD_SIZE = ((128/sizeof(longint)) - 3);
  722. type
  723. Size_T = cardinal;
  724. tfpreg = record
  725. significand: array[0..3] of word;
  726. exponent: word;
  727. end;
  728. pfpstate = ^tfpstate;
  729. tfpstate = record
  730. cw, sw, tag, ipoff, cssel, dataoff, datasel: cardinal;
  731. st: array[0..7] of tfpreg;
  732. status: cardinal;
  733. end;
  734. PSigContextRec = ^SigContextRec;
  735. SigContextRec = record
  736. gs, __gsh: word;
  737. fs, __fsh: word;
  738. es, __esh: word;
  739. ds, __dsh: word;
  740. edi: cardinal;
  741. esi: cardinal;
  742. ebp: cardinal;
  743. esp: cardinal;
  744. ebx: cardinal;
  745. edx: cardinal;
  746. ecx: cardinal;
  747. eax: cardinal;
  748. trapno: cardinal;
  749. err: cardinal;
  750. eip: cardinal;
  751. cs, __csh: word;
  752. eflags: cardinal;
  753. esp_at_signal: cardinal;
  754. ss, __ssh: word;
  755. fpstate: pfpstate;
  756. oldmask: cardinal;
  757. cr2: cardinal;
  758. end;
  759. (*
  760. PSigInfoRec = ^SigInfoRec;
  761. SigInfoRec = record
  762. si_signo: longint;
  763. si_errno: longint;
  764. si_code: longint;
  765. case longint of
  766. 0:
  767. (pad: array[SI_PAD_SIZE] of longint);
  768. 1: { kill }
  769. ( kill: record
  770. pid: longint; { sender's pid }
  771. uid : longint; { sender's uid }
  772. end );
  773. 2: { POSIX.1b timers }
  774. ( timer : record
  775. timer1 : cardinal;
  776. timer2 : cardinal;
  777. end );
  778. 3: { POSIX.1b signals }
  779. ( rt : record
  780. pid : longint; { sender's pid }
  781. uid : longint; { sender's uid }
  782. sigval : longint;
  783. end );
  784. 4: { SIGCHLD }
  785. ( sigchld : record
  786. pid : longint; { which child }
  787. uid : longint; { sender's uid }
  788. status : longint; { exit code }
  789. utime : timeval;
  790. stime : timeval;
  791. end );
  792. 5: { SIGILL, SIGFPE, SIGSEGV, SIGBUS }
  793. ( sigfault : record
  794. addr : pointer;{ faulting insn/memory ref. }
  795. end );
  796. 6:
  797. ( sigpoll : record
  798. band : longint; { POLL_IN, POLL_OUT, POLL_MSG }
  799. fd : longint;
  800. end );
  801. end;
  802. *)
  803. SignalHandler = Procedure(Sig : Longint);cdecl;
  804. PSignalHandler = ^SignalHandler;
  805. SignalRestorer = Procedure;cdecl;
  806. PSignalRestorer = ^SignalRestorer;
  807. TSigAction = procedure(Sig: Longint; SigContext: SigContextRec);cdecl;
  808. SigActionRec = packed record
  809. Handler : record
  810. case byte of
  811. 0: (Sh: SignalHandler);
  812. 1: (Sa: TSigAction);
  813. end;
  814. Sa_Mask : SigSet;
  815. Sa_Flags : Longint;
  816. Sa_restorer : SignalRestorer; { Obsolete - Don't use }
  817. end;
  818. PSigActionRec = ^SigActionRec;
  819. const
  820. SS_ONSTACK = 1;
  821. SS_DISABLE = 2;
  822. MINSIGSTKSZ = 2048;
  823. SIGSTKSZ = 8192;
  824. type
  825. SigAltStack = record
  826. ss_sp : pointer;
  827. ss_flags : longint;
  828. ss_size : size_t;
  829. end;
  830. stack_t = sigaltstack;
  831. PSigAltStack = ^SigAltStack;
  832. pstack_t = ^stack_t;
  833. var
  834. ErrNo,
  835. LinuxError : Longint;
  836. {********************
  837. Process
  838. ********************}
  839. const
  840. {Checked for BSD using Linuxthreads port}
  841. { cloning flags }
  842. CSIGNAL = $000000ff; // signal mask to be sent at exit
  843. CLONE_VM = $00000100; // set if VM shared between processes
  844. CLONE_FS = $00000200; // set if fs info shared between processes
  845. CLONE_FILES = $00000400; // set if open files shared between processes
  846. CLONE_SIGHAND = $00000800; // set if signal handlers shared
  847. CLONE_PID = $00001000; // set if pid shared
  848. type
  849. TCloneFunc=function(args:pointer):longint;cdecl;
  850. const
  851. { For getting/setting priority }
  852. Prio_Process = 0;
  853. Prio_PGrp = 1;
  854. Prio_User = 2;
  855. {$ifdef Solaris}
  856. WNOHANG = $100;
  857. WUNTRACED = $4;
  858. {$ELSE}
  859. WNOHANG = $1;
  860. WUNTRACED = $2;
  861. __WCLONE = $80000000;
  862. {$ENDIF}
  863. {********************
  864. File
  865. ********************}
  866. Const
  867. P_IN = 1;
  868. P_OUT = 2;
  869. Const
  870. LOCK_SH = 1;
  871. LOCK_EX = 2;
  872. LOCK_UN = 8;
  873. LOCK_NB = 4;
  874. Type
  875. Tpipe = array[1..2] of longint;
  876. pglob = ^tglob;
  877. tglob = record
  878. name : pchar;
  879. next : pglob;
  880. end;
  881. ComStr = String[255];
  882. PathStr = String[255];
  883. DirStr = String[255];
  884. NameStr = String[255];
  885. ExtStr = String[255];
  886. const
  887. { For testing access rights }
  888. R_OK = 4;
  889. W_OK = 2;
  890. X_OK = 1;
  891. F_OK = 0;
  892. {$ifndef newreaddir}
  893. { For File control mechanism }
  894. F_GetFd = 1;
  895. F_SetFd = 2;
  896. F_GetFl = 3;
  897. F_SetFl = 4;
  898. {$ifdef Solaris}
  899. F_DupFd = 0;
  900. F_Dup2Fd = 9;
  901. F_GetOwn = 23;
  902. F_SetOwn = 24;
  903. F_GetLk = 14;
  904. F_SetLk = 6;
  905. F_SetLkW = 7;
  906. F_FreeSp = 11;
  907. {$else}
  908. F_GetLk = 5;
  909. F_SetLk = 6;
  910. F_SetLkW = 7;
  911. F_SetOwn = 8;
  912. F_GetOwn = 9;
  913. {$endif}
  914. {$endif}
  915. {********************
  916. IOCtl(TermIOS)
  917. ********************}
  918. {Is too freebsd/Linux specific}
  919. {********************
  920. IOCtl(TermIOS)
  921. ********************}
  922. Const
  923. { Amount of Control Chars }
  924. NCCS = 32;
  925. NCC = 8;
  926. {$Ifndef BSD}
  927. { For Terminal handling }
  928. TCGETS = $5401;
  929. TCSETS = $5402;
  930. TCSETSW = $5403;
  931. TCSETSF = $5404;
  932. TCGETA = $5405;
  933. TCSETA = $5406;
  934. TCSETAW = $5407;
  935. TCSETAF = $5408;
  936. TCSBRK = $5409;
  937. TCXONC = $540A;
  938. TCFLSH = $540B;
  939. TIOCEXCL = $540C;
  940. TIOCNXCL = $540D;
  941. TIOCSCTTY = $540E;
  942. TIOCGPGRP = $540F;
  943. TIOCSPGRP = $5410;
  944. TIOCOUTQ = $5411;
  945. TIOCSTI = $5412;
  946. TIOCGWINSZ = $5413;
  947. TIOCSWINSZ = $5414;
  948. TIOCMGET = $5415;
  949. TIOCMBIS = $5416;
  950. TIOCMBIC = $5417;
  951. TIOCMSET = $5418;
  952. TIOCGSOFTCAR = $5419;
  953. TIOCSSOFTCAR = $541A;
  954. FIONREAD = $541B;
  955. TIOCINQ = FIONREAD;
  956. TIOCLINUX = $541C;
  957. TIOCCONS = $541D;
  958. TIOCGSERIAL = $541E;
  959. TIOCSSERIAL = $541F;
  960. TIOCPKT = $5420;
  961. FIONBIO = $5421;
  962. TIOCNOTTY = $5422;
  963. TIOCSETD = $5423;
  964. TIOCGETD = $5424;
  965. TCSBRKP = $5425;
  966. TIOCTTYGSTRUCT = $5426;
  967. FIONCLEX = $5450;
  968. FIOCLEX = $5451;
  969. FIOASYNC = $5452;
  970. TIOCSERCONFIG = $5453;
  971. TIOCSERGWILD = $5454;
  972. TIOCSERSWILD = $5455;
  973. TIOCGLCKTRMIOS = $5456;
  974. TIOCSLCKTRMIOS = $5457;
  975. TIOCSERGSTRUCT = $5458;
  976. TIOCSERGETLSR = $5459;
  977. TIOCSERGETMULTI = $545A;
  978. TIOCSERSETMULTI = $545B;
  979. TIOCMIWAIT = $545C;
  980. TIOCGICOUNT = $545D;
  981. TIOCPKT_DATA = 0;
  982. TIOCPKT_FLUSHREAD = 1;
  983. TIOCPKT_FLUSHWRITE = 2;
  984. TIOCPKT_STOP = 4;
  985. TIOCPKT_START = 8;
  986. TIOCPKT_NOSTOP = 16;
  987. TIOCPKT_DOSTOP = 32;
  988. {$else}
  989. {$endif}
  990. Type
  991. winsize = packed record
  992. ws_row,
  993. ws_col,
  994. ws_xpixel,
  995. ws_ypixel : word;
  996. end;
  997. TWinSize=winsize;
  998. Termio = packed record
  999. c_iflag, { input mode flags }
  1000. c_oflag, { output mode flags }
  1001. c_cflag, { control mode flags }
  1002. c_lflag : Word; { local mode flags }
  1003. c_line : Word; { line discipline - careful, only High byte in use}
  1004. c_cc : array [0..NCC-1] of char;{ control characters }
  1005. end;
  1006. TTermio=Termio;
  1007. {$PACKRECORDS C}
  1008. Termios = record
  1009. c_iflag,
  1010. c_oflag,
  1011. c_cflag,
  1012. c_lflag : Cardinal;
  1013. c_line : char;
  1014. c_cc : array[0..NCCS-1] of byte;
  1015. c_ispeed,
  1016. c_ospeed : longint;
  1017. end;
  1018. TTermios=Termios;
  1019. {$PACKRECORDS Default}
  1020. {const
  1021. InitCC:array[0..NCCS-1] of byte=(3,34,177,25,4,0,1,0,21,23,32,0,22,17,27,26,0,0,0);}
  1022. const
  1023. {c_cc characters}
  1024. VINTR = 0;
  1025. VQUIT = 1;
  1026. VERASE = 2;
  1027. VKILL = 3;
  1028. VEOF = 4;
  1029. VTIME = 5;
  1030. VMIN = 6;
  1031. VSWTC = 7;
  1032. VSTART = 8;
  1033. VSTOP = 9;
  1034. VSUSP = 10;
  1035. VEOL = 11;
  1036. VREPRINT = 12;
  1037. VDISCARD = 13;
  1038. VWERASE = 14;
  1039. VLNEXT = 15;
  1040. VEOL2 = 16;
  1041. {c_iflag bits}
  1042. IGNBRK = $0000001;
  1043. BRKINT = $0000002;
  1044. IGNPAR = $0000004;
  1045. PARMRK = $0000008;
  1046. INPCK = $0000010;
  1047. ISTRIP = $0000020;
  1048. INLCR = $0000040;
  1049. IGNCR = $0000080;
  1050. ICRNL = $0000100;
  1051. IUCLC = $0000200;
  1052. IXON = $0000400;
  1053. IXANY = $0000800;
  1054. IXOFF = $0001000;
  1055. IMAXBEL = $0002000;
  1056. {c_oflag bits}
  1057. OPOST = $0000001;
  1058. OLCUC = $0000002;
  1059. ONLCR = $0000004;
  1060. OCRNL = $0000008;
  1061. ONOCR = $0000010;
  1062. ONLRET = $0000020;
  1063. OFILL = $0000040;
  1064. OFDEL = $0000080;
  1065. NLDLY = $0000100;
  1066. NL0 = $0000000;
  1067. NL1 = $0000100;
  1068. CRDLY = $0000600;
  1069. CR0 = $0000000;
  1070. CR1 = $0000200;
  1071. CR2 = $0000400;
  1072. CR3 = $0000600;
  1073. TABDLY = $0001800;
  1074. TAB0 = $0000000;
  1075. TAB1 = $0000800;
  1076. TAB2 = $0001000;
  1077. TAB3 = $0001800;
  1078. XTABS = $0001800;
  1079. BSDLY = $0002000;
  1080. BS0 = $0000000;
  1081. BS1 = $0002000;
  1082. VTDLY = $0004000;
  1083. VT0 = $0000000;
  1084. VT1 = $0004000;
  1085. FFDLY = $0008000;
  1086. FF0 = $0000000;
  1087. FF1 = $0008000;
  1088. {c_cflag bits}
  1089. CBAUD = $000100F;
  1090. B0 = $0000000;
  1091. B50 = $0000001;
  1092. B75 = $0000002;
  1093. B110 = $0000003;
  1094. B134 = $0000004;
  1095. B150 = $0000005;
  1096. B200 = $0000006;
  1097. B300 = $0000007;
  1098. B600 = $0000008;
  1099. B1200 = $0000009;
  1100. B1800 = $000000A;
  1101. B2400 = $000000B;
  1102. B4800 = $000000C;
  1103. B9600 = $000000D;
  1104. B19200 = $000000E;
  1105. B38400 = $000000F;
  1106. EXTA = B19200;
  1107. EXTB = B38400;
  1108. CSIZE = $0000030;
  1109. CS5 = $0000000;
  1110. CS6 = $0000010;
  1111. CS7 = $0000020;
  1112. CS8 = $0000030;
  1113. CSTOPB = $0000040;
  1114. CREAD = $0000080;
  1115. PARENB = $0000100;
  1116. PARODD = $0000200;
  1117. HUPCL = $0000400;
  1118. CLOCAL = $0000800;
  1119. CBAUDEX = $0001000;
  1120. B57600 = $0001001;
  1121. B115200 = $0001002;
  1122. B230400 = $0001003;
  1123. B460800 = $0001004;
  1124. CIBAUD = $100F0000;
  1125. CMSPAR = $40000000;
  1126. CRTSCTS = $80000000;
  1127. {c_lflag bits}
  1128. ISIG = $0000001;
  1129. ICANON = $0000002;
  1130. XCASE = $0000004;
  1131. ECHO = $0000008;
  1132. ECHOE = $0000010;
  1133. ECHOK = $0000020;
  1134. ECHONL = $0000040;
  1135. NOFLSH = $0000080;
  1136. TOSTOP = $0000100;
  1137. ECHOCTL = $0000200;
  1138. ECHOPRT = $0000400;
  1139. ECHOKE = $0000800;
  1140. FLUSHO = $0001000;
  1141. PENDIN = $0004000;
  1142. IEXTEN = $0008000;
  1143. {c_line bits}
  1144. TIOCM_LE = $001;
  1145. TIOCM_DTR = $002;
  1146. TIOCM_RTS = $004;
  1147. TIOCM_ST = $008;
  1148. TIOCM_SR = $010;
  1149. TIOCM_CTS = $020;
  1150. TIOCM_CAR = $040;
  1151. TIOCM_RNG = $080;
  1152. TIOCM_DSR = $100;
  1153. TIOCM_CD = TIOCM_CAR;
  1154. TIOCM_RI = TIOCM_RNG;
  1155. TIOCM_OUT1 = $2000;
  1156. TIOCM_OUT2 = $4000;
  1157. {TCSetAttr}
  1158. TCSANOW = 0;
  1159. TCSADRAIN = 1;
  1160. TCSAFLUSH = 2;
  1161. {TCFlow}
  1162. TCOOFF = 0;
  1163. TCOON = 1;
  1164. TCIOFF = 2;
  1165. TCION = 3;
  1166. {TCFlush}
  1167. TCIFLUSH = 0;
  1168. TCOFLUSH = 1;
  1169. TCIOFLUSH = 2;
  1170. {********************
  1171. Info
  1172. ********************}
  1173. Type
  1174. UTimBuf = packed record{in BSD array[0..1] of timeval, but this is
  1175. backwards compatible with linux version}
  1176. actime,
  1177. modtime
  1178. : longint;
  1179. end;
  1180. UTimeBuf=UTimBuf;
  1181. TUTimeBuf=UTimeBuf;
  1182. PUTimeBuf=^UTimeBuf;
  1183. TSysinfo = packed record
  1184. uptime : longint;
  1185. loads : array[1..3] of longint;
  1186. totalram,
  1187. freeram,
  1188. sharedram,
  1189. bufferram,
  1190. totalswap,
  1191. freeswap : longint;
  1192. procs : integer;
  1193. s : string[18];
  1194. end;
  1195. PSysInfo = ^TSysInfo;
  1196. {******************************************************************************
  1197. Procedure/Functions
  1198. ******************************************************************************}
  1199. Function SysCall(callnr:longint;var regs:SysCallregs):longint;
  1200. {**************************
  1201. Time/Date Handling
  1202. ***************************}
  1203. var
  1204. tzdaylight : boolean;
  1205. tzseconds : longint;
  1206. tzname : array[boolean] of pchar;
  1207. { timezone support }
  1208. procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
  1209. procedure GetLocalTimezone(timer:longint);
  1210. procedure ReadTimezoneFile(fn:string);
  1211. function GetTimezoneFile:string;
  1212. Procedure GetTimeOfDay(var tv:timeval);
  1213. Function GetTimeOfDay:longint;
  1214. Function GetEpochTime: longint;
  1215. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  1216. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  1217. procedure GetTime(var hour,min,sec,msec,usec:word);
  1218. procedure GetTime(var hour,min,sec,sec100:word);
  1219. procedure GetTime(var hour,min,sec:word);
  1220. Procedure GetDate(Var Year,Month,Day:Word);
  1221. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  1222. function SetTime(Hour,Min,Sec:word) : Boolean;
  1223. function SetDate(Year,Month,Day:Word) : Boolean;
  1224. function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  1225. {**************************
  1226. Process Handling
  1227. ***************************}
  1228. function CreateShellArgV(const prog:string):ppchar;
  1229. function CreateShellArgV(const prog:Ansistring):ppchar;
  1230. Procedure Execve(Path: pathstr;args:ppchar;ep:ppchar);
  1231. Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
  1232. Procedure Execve(path: pchar;args:ppchar;ep:ppchar);
  1233. Procedure Execv(const path:pathstr;args:ppchar);
  1234. Procedure Execv(const path: AnsiString;args:ppchar);
  1235. Procedure Execvp(Path: Pathstr;Args:ppchar;Ep:ppchar);
  1236. Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
  1237. Procedure Execl(const Todo: String);
  1238. Procedure Execl(const Todo: Ansistring);
  1239. Procedure Execle(Todo: String;Ep:ppchar);
  1240. Procedure Execle(Todo: AnsiString;Ep:ppchar);
  1241. Procedure Execlp(Todo: string;Ep:ppchar);
  1242. Procedure Execlp(Todo: Ansistring;Ep:ppchar);
  1243. Function Shell(const Command:String):Longint;
  1244. Function Shell(const Command:AnsiString):Longint;
  1245. Function Fork:longint;
  1246. {Clone for FreeBSD is copied from the LinuxThread port, and rfork based}
  1247. function Clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  1248. Procedure ExitProcess(val:longint);
  1249. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint; {=>PID (Status Valid), 0 (No Status), -1: Error, special case errno=EINTR }
  1250. Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  1251. Procedure Nice(N:integer);
  1252. Function GetPriority(Which,Who:Integer):integer;
  1253. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  1254. function WEXITSTATUS(Status: Integer): Integer;
  1255. function WTERMSIG(Status: Integer): Integer;
  1256. function WSTOPSIG(Status: Integer): Integer;
  1257. Function WIFEXITED(Status: Integer): Boolean;
  1258. Function WIFSTOPPED(Status: Integer): Boolean;
  1259. Function WIFSIGNALED(Status: Integer): Boolean;
  1260. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  1261. Function W_STOPCODE(Signal: Integer): Integer;
  1262. Function GetPid:LongInt;
  1263. Function GetPPid:LongInt;
  1264. Function GetUid:Longint;
  1265. Function GetEUid:Longint;
  1266. Function GetGid:Longint;
  1267. Function GetEGid:Longint;
  1268. {**************************
  1269. File Handling
  1270. ***************************}
  1271. Function fdOpen(pathname:string;flags:longint):longint;
  1272. Function fdOpen(pathname:string;flags,mode:longint):longint;
  1273. Function fdOpen(pathname:pchar;flags:longint):longint;
  1274. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  1275. Function fdClose(fd:longint):boolean;
  1276. Function fdRead(fd:longint;var buf;size:longint):longint;
  1277. Function fdWrite(fd:longint;const buf;size:longint):longint;
  1278. Function fdTruncate(fd,size:longint):boolean;
  1279. Function fdSeek (fd,pos,seektype :longint): longint;
  1280. Function fdFlush (fd : Longint) : Boolean;
  1281. Function Link(OldPath,NewPath:pathstr):boolean;
  1282. Function SymLink(OldPath,NewPath:pathstr):boolean;
  1283. Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
  1284. Function ReadLink(name:pathstr):pathstr;
  1285. Function UnLink(Path:pathstr):boolean;
  1286. Function UnLink(Path:pchar):Boolean;
  1287. Function FReName (OldName,NewName : Pchar) : Boolean;
  1288. Function FReName (OldName,NewName : String) : Boolean;
  1289. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  1290. Function Chmod(path:pathstr;Newmode:longint):boolean;
  1291. Function Utime(const path:pathstr;utim:utimebuf):boolean;
  1292. Function Access(Path:Pathstr ;mode:integer):boolean;
  1293. Function Umask(Mask:Integer):integer;
  1294. Function Flock (fd,mode : longint) : boolean;
  1295. Function Flock (var T : text;mode : longint) : boolean;
  1296. Function Flock (var F : File;mode : longint) : boolean;
  1297. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  1298. Function FStat(Fd:longint;Var Info:stat):Boolean;
  1299. Function FStat(var F:Text;Var Info:stat):Boolean;
  1300. Function FStat(var F:File;Var Info:stat):Boolean;
  1301. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  1302. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  1303. Function FSStat(Fd: Longint;Var Info:statfs):Boolean;
  1304. Function Fcntl(Fd:longint;Cmd:longint):longint;
  1305. Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
  1306. Function Fcntl(var Fd:Text;Cmd:longint):longint;
  1307. Procedure Fcntl(var Fd:Text;Cmd:longint;Arg:Longint);
  1308. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  1309. Function Dup(var oldfile,newfile:text):Boolean;
  1310. Function Dup(var oldfile,newfile:file):Boolean;
  1311. Function Dup2(oldfile,newfile:longint):Boolean;
  1312. Function Dup2(var oldfile,newfile:text):Boolean;
  1313. Function Dup2(var oldfile,newfile:file):Boolean;
  1314. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  1315. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  1316. Function SelectText(var T:Text;TimeOut :PTimeVal):Longint;
  1317. Function SelectText(var T:Text;TimeOut :Longint):Longint;
  1318. {**************************
  1319. Directory Handling
  1320. ***************************}
  1321. {$ifndef newreaddir} {only for FreeBSD, temporary solution}
  1322. Function OpenDir(f:pchar):pdir;
  1323. Function OpenDir(f: String):pdir;
  1324. function CloseDir(p:pdir):integer;
  1325. Function ReadDir(p:pdir):pdirent;
  1326. procedure SeekDir(p:pdir;off:longint);
  1327. function TellDir(p:pdir):longint;
  1328. {$else}
  1329. Function OpenDir(name:pchar):pdir;
  1330. Function OpenDir(f: String):pdir;
  1331. function CloseDir(dirp:pdir):integer;
  1332. Function ReadDir(p:pdir):pdirent;
  1333. procedure SeekDir(dirp:pdir;loc:longint);
  1334. function TellDir(dirp:pdir):longint;
  1335. {$endif}
  1336. {**************************
  1337. Pipe/Fifo/Stream
  1338. ***************************}
  1339. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  1340. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  1341. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  1342. Function PClose(Var F:text) : longint;
  1343. Function PClose(Var F:file) : longint;
  1344. Procedure POpen(var F:text;const Prog:String;rw:char);
  1345. Procedure POpen(var F:file;const Prog:String;rw:char);
  1346. Function mkFifo(pathname:string;mode:longint):boolean;
  1347. function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  1348. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  1349. {**************************
  1350. General information
  1351. ***************************}
  1352. Function GetEnv(P:string):Pchar;
  1353. Function GetDomainName:String;
  1354. Function GetHostName:String;
  1355. Function Sysinfo(var Info:TSysinfo):Boolean;
  1356. Function Uname(var unamerec:utsname):Boolean;
  1357. {**************************
  1358. Signal
  1359. ***************************}
  1360. Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
  1361. Procedure SigProcMask (How:longint;SSet,OldSSet:PSigSet);
  1362. Function SigPending:SigSet;
  1363. Procedure SigSuspend(Mask:Sigset);
  1364. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  1365. Function Kill(Pid:longint;Sig:longint):integer;
  1366. Procedure SigRaise(Sig:integer);
  1367. Function Alarm(Sec : Longint) : longint;
  1368. Procedure Pause;
  1369. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  1370. {**************************
  1371. IOCtl/Termios Functions
  1372. ***************************}
  1373. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  1374. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  1375. Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
  1376. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  1377. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  1378. Procedure CFMakeRaw(var tios:TermIOS);
  1379. Function TCSendBreak(fd,duration:longint):boolean;
  1380. Function TCSetPGrp(fd,id:longint):boolean;
  1381. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  1382. Function TCFlush(fd,qsel:longint):boolean;
  1383. Function TCDrain(fd:longint):boolean;
  1384. Function TCFlow(fd,act:longint):boolean;
  1385. Function IsATTY(Handle:Longint):Boolean;
  1386. Function IsATTY(var f:text):Boolean;
  1387. function TTYname(Handle:Longint):string;
  1388. function TTYname(var F:Text):string;
  1389. {**************************
  1390. Memory functions
  1391. ***************************}
  1392. const
  1393. PROT_READ = $1; { page can be read }
  1394. PROT_WRITE = $2; { page can be written }
  1395. PROT_EXEC = $4; { page can be executed }
  1396. PROT_NONE = $0; { page can not be accessed }
  1397. MAP_SHARED = $1; { Share changes }
  1398. // MAP_PRIVATE = $2; { Changes are private }
  1399. MAP_TYPE = $f; { Mask for type of mapping }
  1400. MAP_FIXED = $10; { Interpret addr exactly }
  1401. // MAP_ANONYMOUS = $20; { don't use a file }
  1402. MAP_GROWSDOWN = $100; { stack-like segment }
  1403. MAP_DENYWRITE = $800; { ETXTBSY }
  1404. MAP_EXECUTABLE = $1000; { mark it as an executable }
  1405. MAP_LOCKED = $2000; { pages are locked }
  1406. MAP_NORESERVE = $4000; { don't check for reservations }
  1407. type
  1408. tmmapargs=record
  1409. address : longint;
  1410. size : longint;
  1411. prot : longint;
  1412. flags : longint;
  1413. fd : longint;
  1414. offset : longint;
  1415. end;
  1416. function MMap(const m:tmmapargs):longint;
  1417. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  1418. {**************************
  1419. Port IO functions
  1420. ***************************}
  1421. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  1422. Function IoPL(Level : longint) : Boolean;
  1423. {$ifdef cpui386}
  1424. Procedure WritePort (Port : Longint; Value : Byte);
  1425. Procedure WritePort (Port : Longint; Value : Word);
  1426. Procedure WritePort (Port : Longint; Value : Longint);
  1427. Procedure WritePortB (Port : Longint; Value : Byte);
  1428. Procedure WritePortW (Port : Longint; Value : Word);
  1429. Procedure WritePortL (Port : Longint; Value : Longint);
  1430. Procedure WritePortL (Port : Longint; Var Buf; Count: longint);
  1431. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  1432. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  1433. Procedure ReadPort (Port : Longint; Var Value : Byte);
  1434. Procedure ReadPort (Port : Longint; Var Value : Word);
  1435. Procedure ReadPort (Port : Longint; Var Value : Longint);
  1436. function ReadPortB (Port : Longint): Byte;
  1437. function ReadPortW (Port : Longint): Word;
  1438. function ReadPortL (Port : Longint): LongInt;
  1439. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  1440. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  1441. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  1442. {$endif}
  1443. {**************************
  1444. Utility functions
  1445. ***************************}
  1446. Function Octal(l:longint):longint;
  1447. Function FExpand(Const Path: PathStr):PathStr;
  1448. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  1449. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  1450. Function Dirname(Const path:pathstr):pathstr;
  1451. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  1452. Function FNMatch(const Pattern,Name:string):Boolean;
  1453. Function Glob(Const path:pathstr):pglob;
  1454. Procedure Globfree(var p:pglob);
  1455. Function StringToPPChar(Var S:String):ppchar;
  1456. Function StringToPPChar(Var S:AnsiString):ppchar;
  1457. Function StringToPPChar(S : Pchar):ppchar;
  1458. Function GetFS(var T:Text):longint;
  1459. Function GetFS(Var F:File):longint;
  1460. {Filedescriptorsets}
  1461. Procedure FD_Zero(var fds:fdSet);
  1462. Procedure FD_Clr(fd:longint;var fds:fdSet);
  1463. Procedure FD_Set(fd:longint;var fds:fdSet);
  1464. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  1465. {Stat.Mode Types}
  1466. Function S_ISLNK(m:word):boolean;
  1467. Function S_ISREG(m:word):boolean;
  1468. Function S_ISDIR(m:word):boolean;
  1469. Function S_ISCHR(m:word):boolean;
  1470. Function S_ISBLK(m:word):boolean;
  1471. Function S_ISFIFO(m:word):boolean;
  1472. Function S_ISSOCK(m:word):boolean;
  1473. {******************************************************************************
  1474. Implementation
  1475. ******************************************************************************}
  1476. Implementation
  1477. Uses Strings;
  1478. { Get the definitions of textrec and filerec }
  1479. {$i textrec.inc}
  1480. {$i filerec.inc}
  1481. {No debugging for syslinux include !}
  1482. {$IFDEF SYS_LINUX}
  1483. {$UNDEF SYSCALL_DEBUG}
  1484. {$ENDIF SYS_LINUX}
  1485. {*****************************************************************************
  1486. --- Main:The System Call Self ---
  1487. *****************************************************************************}
  1488. {$ifdef FPC_PROFILE}
  1489. {$define PROFILE_WAS_ACTIVE}
  1490. {$profile off}
  1491. {$else}
  1492. {$undef PROFILE_WAS_ACTIVE}
  1493. {$endif}
  1494. Procedure Do_SysCall( callnr:longint;var regs : SysCallregs );assembler;
  1495. {
  1496. This function puts the registers in place, does the call, and then
  1497. copies back the registers as they are after the SysCall.
  1498. }
  1499. {$ifdef cpui386}
  1500. {$ASMMODE ATT}
  1501. asm
  1502. { load the registers... }
  1503. movl 12(%ebp),%eax
  1504. movl 4(%eax),%ebx
  1505. movl 8(%eax),%ecx
  1506. movl 12(%eax),%edx
  1507. movl 16(%eax),%esi
  1508. movl 20(%eax),%edi
  1509. { set the call number }
  1510. movl 8(%ebp),%eax
  1511. { Go ! }
  1512. int $0x80
  1513. { Put back the registers... }
  1514. pushl %eax
  1515. movl 12(%ebp),%eax
  1516. movl %edi,20(%eax)
  1517. movl %esi,16(%eax)
  1518. movl %edx,12(%eax)
  1519. movl %ecx,8(%eax)
  1520. movl %ebx,4(%eax)
  1521. popl %ebx
  1522. movl %ebx,(%eax)
  1523. end;
  1524. {$ASMMODE DEFAULT}
  1525. {$else}
  1526. {$ifdef m68k}
  1527. asm
  1528. { load the registers... }
  1529. move.l 12(a6),a0
  1530. move.l 4(a0),d1
  1531. move.l 8(a0),d2
  1532. move.l 12(a0),d3
  1533. move.l 16(a0),d4
  1534. move.l 20(a0),d5
  1535. { set the call number }
  1536. move.l 8(a6),d0
  1537. { Go ! }
  1538. trap #0
  1539. { Put back the registers... }
  1540. move.l d0,-(sp)
  1541. move.l 12(a6),a0
  1542. move.l d5,20(a0)
  1543. move.l d4,16(a0)
  1544. move.l d3,12(a0)
  1545. move.l d2,8(a0)
  1546. move.l d1,4(a0)
  1547. move.l (sp)+,d1
  1548. move.l d1,(a0)
  1549. end;
  1550. {$else}
  1551. {$error Cannot decide which processor you have ! define cpui386 or m68k }
  1552. {$endif}
  1553. {$endif}
  1554. {$IFDEF SYSCALL_DEBUG}
  1555. Const
  1556. DoSysCallDebug : Boolean = False;
  1557. var
  1558. LastCnt,
  1559. LastEax,
  1560. LastCall : longint;
  1561. DebugTxt : string[20];
  1562. {$ENDIF}
  1563. Function SysCall( callnr:longint;var regs : SysCallregs ):longint;
  1564. {
  1565. This function serves as an interface to do_SysCall.
  1566. If the SysCall returned a negative number, it returns -1, and puts the
  1567. SysCall result in errno. Otherwise, it returns the SysCall return value
  1568. }
  1569. begin
  1570. do_SysCall(callnr,regs);
  1571. if (regs.reg1<0) and (regs.reg1>=-Sys_ERROR_MAX) then
  1572. begin
  1573. {$IFDEF SYSCALL_DEBUG}
  1574. If DoSysCallDebug then
  1575. debugtxt:=' syscall error: ';
  1576. {$endif}
  1577. ErrNo:=-regs.reg1;
  1578. SysCall:=-1;
  1579. end
  1580. else
  1581. begin
  1582. {$IFDEF SYSCALL_DEBUG}
  1583. if DoSysCallDebug then
  1584. debugtxt:=' syscall returned: ';
  1585. {$endif}
  1586. SysCall:=regs.reg1;
  1587. errno:=0
  1588. end;
  1589. {$IFDEF SYSCALL_DEBUG}
  1590. if DoSysCallDebug then
  1591. begin
  1592. inc(lastcnt);
  1593. if (callnr<>lastcall) or (regs.reg1<>lasteax) then
  1594. begin
  1595. if lastcnt>1 then
  1596. writeln(sys_nr_txt[lastcall],debugtxt,lasteax,' (',lastcnt,'x)');
  1597. lastcall:=callnr;
  1598. lasteax:=regs.reg1;
  1599. lastcnt:=0;
  1600. writeln(sys_nr_txt[lastcall],debugtxt,lasteax);
  1601. end;
  1602. end;
  1603. {$endif}
  1604. end;
  1605. {$ifdef PROFILE_WAS_ACTIVE}
  1606. {$profile on}
  1607. {$undef PROFILE_WAS_ACTIVE}
  1608. {$endif}
  1609. Function Sys_Time:longint;
  1610. var
  1611. regs : SysCallregs;
  1612. begin
  1613. regs.reg2:=0;
  1614. Sys_Time:=SysCall(SysCall_nr_time,regs);
  1615. end;
  1616. {*****************************************************************************
  1617. --- File:File handling related calls ---
  1618. *****************************************************************************}
  1619. Function Sys_Open(f:pchar;flags:longint;mode:integer):longint;
  1620. var
  1621. regs : SysCallregs;
  1622. Begin
  1623. regs.reg2:=longint(f);
  1624. regs.reg3:=flags;
  1625. regs.reg4:=mode;
  1626. Sys_Open:=SysCall(SysCall_nr_open,regs);
  1627. End;
  1628. Function Sys_Close(f:longint):longint;
  1629. var
  1630. regs : SysCallregs;
  1631. begin
  1632. regs.reg2:=f;
  1633. Sys_Close:=SysCall(SysCall_nr_close,regs);
  1634. end;
  1635. Function Sys_Lseek(F:longint;Off:longint;Whence:longint):longint;
  1636. var
  1637. regs : SysCallregs;
  1638. begin
  1639. regs.reg2:=f;
  1640. regs.reg3:=off;
  1641. regs.reg4:=Whence;
  1642. Sys_lseek:=SysCall(SysCall_nr_lseek,regs);
  1643. end;
  1644. Function Sys_Read(f:longint;buffer:pchar;count:longint):longint;
  1645. var
  1646. regs : SysCallregs;
  1647. begin
  1648. regs.reg2:=f;
  1649. regs.reg3:=longint(buffer);
  1650. regs.reg4:=count;
  1651. Sys_Read:=SysCall(SysCall_nr_read,regs);
  1652. end;
  1653. Function Sys_Write(f:longint;buffer:pchar;count:longint):longint;
  1654. var
  1655. regs : SysCallregs;
  1656. begin
  1657. regs.reg2:=f;
  1658. regs.reg3:=longint(buffer);
  1659. regs.reg4:=count;
  1660. Sys_Write:=SysCall(SysCall_nr_write,regs);
  1661. end;
  1662. Function Sys_Unlink(Filename:pchar):longint;
  1663. var
  1664. regs : SysCallregs;
  1665. begin
  1666. regs.reg2:=longint(filename);
  1667. Sys_Unlink:=SysCall(SysCall_nr_unlink,regs);
  1668. end;
  1669. Function Sys_fstat(fd : longint;var Info:stat):Longint;
  1670. var
  1671. regs : SysCallregs;
  1672. begin
  1673. regs.reg2:=fd;
  1674. regs.reg3:=longint(@Info);
  1675. Sys_fStat:=SysCall(SysCall_nr_fstat,regs);
  1676. end;
  1677. Function Sys_Rename(Oldname,Newname:pchar):longint;
  1678. var
  1679. regs : SysCallregs;
  1680. begin
  1681. regs.reg2:=longint(oldname);
  1682. regs.reg3:=longint(newname);
  1683. Sys_Rename:=SysCall(SysCall_nr_rename,regs);
  1684. end;
  1685. Function Sys_Stat(Filename:pchar;var Buffer: stat):longint;
  1686. {
  1687. We need this for getcwd
  1688. }
  1689. var
  1690. regs : SysCallregs;
  1691. begin
  1692. regs.reg2:=longint(filename);
  1693. regs.reg3:=longint(@buffer);
  1694. Sys_Stat:=SysCall(SysCall_nr_stat,regs);
  1695. end;
  1696. Function Sys_Symlink(oldname,newname:pchar):longint;
  1697. {
  1698. We need this for erase
  1699. }
  1700. var
  1701. regs : SysCallregs;
  1702. begin
  1703. regs.reg2:=longint(oldname);
  1704. regs.reg3:=longint(newname);
  1705. Sys_symlink:=SysCall(SysCall_nr_symlink,regs);
  1706. end;
  1707. Function Sys_ReadLink(name,linkname:pchar;maxlen:longint):longint;
  1708. var
  1709. regs : SysCallRegs;
  1710. begin
  1711. regs.reg2:=longint(name);
  1712. regs.reg3:=longint(linkname);
  1713. regs.reg4:=maxlen;
  1714. Sys_ReadLink:=SysCall(Syscall_nr_readlink,regs);
  1715. end;
  1716. {*****************************************************************************
  1717. --- Directory:Directory related calls ---
  1718. *****************************************************************************}
  1719. Function Sys_Chdir(Filename:pchar):longint;
  1720. var
  1721. regs : SysCallregs;
  1722. begin
  1723. regs.reg2:=longint(filename);
  1724. Sys_ChDir:=SysCall(SysCall_nr_chdir,regs);
  1725. end;
  1726. Function Sys_Mkdir(Filename:pchar;mode:longint):longint;
  1727. var
  1728. regs : SysCallregs;
  1729. begin
  1730. regs.reg2:=longint(filename);
  1731. regs.reg3:=mode;
  1732. Sys_MkDir:=SysCall(SysCall_nr_mkdir,regs);
  1733. end;
  1734. Function Sys_Rmdir(Filename:pchar):longint;
  1735. var
  1736. regs : SysCallregs;
  1737. begin
  1738. regs.reg2:=longint(filename);
  1739. Sys_Rmdir:=SysCall(SysCall_nr_rmdir,regs);
  1740. end;
  1741. { we need this for getcwd }
  1742. Function OpenDir(f:pchar):pdir;
  1743. var
  1744. fd:integer;
  1745. st:stat;
  1746. ptr:pdir;
  1747. begin
  1748. opendir:=nil;
  1749. if sys_stat(f,st)<0 then
  1750. exit;
  1751. { Is it a dir ? }
  1752. if not((st.mode and $f000)=$4000)then
  1753. begin
  1754. errno:=sys_enotdir;
  1755. exit
  1756. end;
  1757. { Open it}
  1758. fd:=sys_open(f,OPEN_RDONLY,438);
  1759. if fd<0 then
  1760. exit;
  1761. new(ptr);
  1762. if ptr=nil then
  1763. exit;
  1764. new(ptr^.buf);
  1765. if ptr^.buf=nil then
  1766. exit;
  1767. ptr^.fd:=fd;
  1768. ptr^.loc:=0;
  1769. ptr^.size:=0;
  1770. ptr^.dd_max:=sizeof(ptr^.buf^);
  1771. opendir:=ptr;
  1772. end;
  1773. function CloseDir(p:pdir):integer;
  1774. begin
  1775. closedir:=sys_close(p^.fd);
  1776. dispose(p^.buf);
  1777. dispose(p);
  1778. end;
  1779. Function Sys_ReadDir(p:pdir):pdirent;
  1780. var
  1781. regs :SysCallregs;
  1782. dummy:longint;
  1783. begin
  1784. regs.reg3:=longint(p^.buf);
  1785. regs.reg2:=p^.fd;
  1786. regs.reg4:=1;
  1787. dummy:=SysCall(SysCall_nr_readdir,regs);
  1788. { the readdir system call returns the number of bytes written }
  1789. if dummy=0 then
  1790. sys_readdir:=nil
  1791. else
  1792. sys_readdir:=p^.buf
  1793. end;
  1794. {*****************************************************************************
  1795. --- Process:Process & program handling - related calls ---
  1796. *****************************************************************************}
  1797. Function Sys_GetPid:LongInt;
  1798. var
  1799. regs : SysCallregs;
  1800. begin
  1801. Sys_GetPid:=SysCall(SysCall_nr_getpid,regs);
  1802. end;
  1803. Procedure Sys_Exit(ExitCode:Integer);
  1804. var
  1805. regs : SysCallregs;
  1806. begin
  1807. regs.reg2:=exitcode;
  1808. SysCall(SysCall_nr_exit,regs)
  1809. end;
  1810. Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
  1811. {
  1812. Change action of process upon receipt of a signal.
  1813. Signum specifies the signal (all except SigKill and SigStop).
  1814. If Act is non-nil, it is used to specify the new action.
  1815. If OldAct is non-nil the previous action is saved there.
  1816. }
  1817. Var
  1818. sr : Syscallregs;
  1819. begin
  1820. sr.reg2:=Signum;
  1821. sr.reg3:=Longint(act);
  1822. sr.reg4:=Longint(oldact);
  1823. SysCall(Syscall_nr_sigaction,sr);
  1824. end;
  1825. function Sys_FTruncate(Handle,Pos:longint):longint; //moved from sysunix.inc Do_Truncate
  1826. var
  1827. sr : syscallregs;
  1828. begin
  1829. sr.reg2:=Handle;
  1830. sr.reg3:=Pos;
  1831. Sys_FTruncate:=syscall(syscall_nr_ftruncate,sr);
  1832. end;
  1833. Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint; // moved from sysunix.inc, used in sbrk
  1834. type
  1835. tmmapargs=packed record
  1836. address : longint;
  1837. size : longint;
  1838. prot : longint;
  1839. flags : longint;
  1840. fd : longint;
  1841. offset : longint;
  1842. end;
  1843. var
  1844. t : syscallregs;
  1845. mmapargs : tmmapargs;
  1846. begin
  1847. mmapargs.address:=adr;
  1848. mmapargs.size:=len;
  1849. mmapargs.prot:=prot;
  1850. mmapargs.flags:=flags;
  1851. mmapargs.fd:=fdes;
  1852. mmapargs.offset:=off;
  1853. t.reg2:=longint(@mmapargs);
  1854. do_syscall(syscall_nr_mmap,t);
  1855. Sys_mmap:=t.reg1;
  1856. if t.reg1=-1 then
  1857. errno:=-1;
  1858. end;
  1859. {
  1860. Interface to Unix ioctl call.
  1861. Performs various operations on the filedescriptor Handle.
  1862. Ndx describes the operation to perform.
  1863. Data points to data needed for the Ndx function. The structure of this
  1864. data is function-dependent.
  1865. }
  1866. Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; // This was missing here, instead hardcode in Do_IsDevice
  1867. var
  1868. sr: SysCallRegs;
  1869. begin
  1870. sr.reg2:=Handle;
  1871. sr.reg3:=Ndx;
  1872. sr.reg4:=Longint(Data);
  1873. Sys_IOCtl:=SysCall(Syscall_nr_ioctl,sr);
  1874. end;
  1875. Function Sys_SigAltStack(ss, oss :psigaltstack):longint;
  1876. var
  1877. regs : SysCallregs;
  1878. begin
  1879. regs.reg2:=longint(ss);
  1880. regs.reg3:=longint(oss);
  1881. sys_sigaltstack:=SysCall(syscall_nr_sigaltstack,regs);
  1882. end;
  1883. Function Fork:longint;
  1884. {
  1885. This function issues the 'fork' System call. the program is duplicated in memory
  1886. and Execution continues in parent and child process.
  1887. In the parent process, fork returns the PID of the child. In the child process,
  1888. zero is returned.
  1889. A negative value indicates that an error has occurred, the error is returned in
  1890. LinuxError.
  1891. }
  1892. var
  1893. regs:SysCallregs;
  1894. begin
  1895. Fork:=SysCall(SysCall_nr_fork,regs);
  1896. LinuxError:=Errno;
  1897. End;
  1898. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  1899. begin
  1900. if (pointer(func)=nil) or (sp=nil) then
  1901. begin
  1902. LinuxError:=Sys_EInval;
  1903. exit(-1); // give an error result
  1904. end;
  1905. {$ifdef cpui386}
  1906. asm
  1907. { Insert the argument onto the new stack. }
  1908. movl sp,%ecx
  1909. subl $8,%ecx
  1910. movl args,%eax
  1911. movl %eax,4(%ecx)
  1912. { Save the function pointer as the zeroth argument.
  1913. It will be popped off in the child in the ebx frobbing below. }
  1914. movl func,%eax
  1915. movl %eax,0(%ecx)
  1916. { Do the system call }
  1917. pushl %ebx
  1918. movl flags,%ebx
  1919. movl SysCall_nr_clone,%eax
  1920. int $0x80
  1921. popl %ebx
  1922. test %eax,%eax
  1923. jnz .Lclone_end
  1924. { We're in the new thread }
  1925. subl %ebp,%ebp { terminate the stack frame }
  1926. call *%ebx
  1927. { exit process }
  1928. movl %eax,%ebx
  1929. movl $1,%eax
  1930. int $0x80
  1931. .Lclone_end:
  1932. movl %eax,__RESULT
  1933. end;
  1934. {$endif cpui386}
  1935. {$ifdef m68k}
  1936. { No yet translated, my m68k assembler is too weak for such things PM }
  1937. (*
  1938. asm
  1939. { Insert the argument onto the new stack. }
  1940. movl sp,%ecx
  1941. subl $8,%ecx
  1942. movl args,%eax
  1943. movl %eax,4(%ecx)
  1944. { Save the function pointer as the zeroth argument.
  1945. It will be popped off in the child in the ebx frobbing below. }
  1946. movl func,%eax
  1947. movl %eax,0(%ecx)
  1948. { Do the system call }
  1949. pushl %ebx
  1950. movl flags,%ebx
  1951. movl SysCall_nr_clone,%eax
  1952. int $0x80
  1953. popl %ebx
  1954. test %eax,%eax
  1955. jnz .Lclone_end
  1956. { We're in the new thread }
  1957. subl %ebp,%ebp { terminate the stack frame }
  1958. call *%ebx
  1959. { exit process }
  1960. movl %eax,%ebx
  1961. movl $1,%eax
  1962. int $0x80
  1963. .Lclone_end:
  1964. movl %eax,__RESULT
  1965. end;
  1966. *)
  1967. {$endif m68k}
  1968. end;
  1969. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  1970. {
  1971. Replaces the current program by the program specified in path,
  1972. arguments in args are passed to Execve.
  1973. environment specified in ep is passed on.
  1974. }
  1975. var
  1976. regs:SysCallregs;
  1977. begin
  1978. path:=path+#0;
  1979. regs.reg2:=longint(@path[1]);
  1980. regs.reg3:=longint(args);
  1981. regs.reg4:=longint(ep);
  1982. SysCall(SysCall_nr_Execve,regs);
  1983. { This only gets set when the call fails, otherwise we don't get here ! }
  1984. Linuxerror:=errno;
  1985. end;
  1986. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  1987. {
  1988. Replaces the current program by the program specified in path,
  1989. arguments in args are passed to Execve.
  1990. environment specified in ep is passed on.
  1991. }
  1992. var
  1993. regs:SysCallregs;
  1994. begin
  1995. regs.reg2:=longint(path);
  1996. regs.reg3:=longint(args);
  1997. regs.reg4:=longint(ep);
  1998. SysCall(SysCall_nr_Execve,regs);
  1999. { This only gets set when the call fails, otherwise we don't get here ! }
  2000. Linuxerror:=errno;
  2001. end;
  2002. Procedure ExitProcess(val:longint);
  2003. var
  2004. regs : SysCallregs;
  2005. begin
  2006. regs.reg2:=val;
  2007. SysCall(SysCall_nr_exit,regs);
  2008. end;
  2009. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
  2010. {
  2011. Waits until a child with PID Pid exits, or returns if it is exited already.
  2012. Any resources used by the child are freed.
  2013. The exit status is reported in the adress referred to by Status. It should
  2014. be a longint.
  2015. }
  2016. var
  2017. regs : SysCallregs;
  2018. begin
  2019. regs.reg2:=pid;
  2020. regs.reg3:=longint(status);
  2021. regs.reg4:=options;
  2022. WaitPid:=SysCall(SysCall_nr_waitpid,regs);
  2023. LinuxError:=errno;
  2024. end;
  2025. Procedure GetTimeOfDay(var tv:timeval);
  2026. {
  2027. Get the number of seconds since 00:00, January 1 1970, GMT
  2028. the time NOT corrected any way
  2029. }
  2030. var
  2031. regs : SysCallregs;
  2032. begin
  2033. regs.reg2:=longint(@tv);
  2034. regs.reg3:=0;
  2035. SysCall(SysCall_nr_gettimeofday,regs);
  2036. LinuxError:=Errno;
  2037. end;
  2038. Function GetPriority(Which,Who:Integer):integer;
  2039. {
  2040. Get Priority of process, process group, or user.
  2041. Which : selects what kind of priority is used.
  2042. can be one of the following predefined Constants :
  2043. Prio_User.
  2044. Prio_PGrp.
  2045. Prio_Process.
  2046. Who : depending on which, this is , respectively :
  2047. Uid
  2048. Pid
  2049. Process Group id
  2050. Errors are reported in linuxerror _only_. (priority can be negative)
  2051. }
  2052. var
  2053. sr : Syscallregs;
  2054. begin
  2055. errno:=0;
  2056. if (which<prio_process) or (which>prio_user) then
  2057. begin
  2058. { We can save an interrupt here }
  2059. getpriority:=0;
  2060. linuxerror:=Sys_einval;
  2061. end
  2062. else
  2063. begin
  2064. sr.reg2:=which;
  2065. sr.reg3:=who;
  2066. getpriority:=SysCall(Syscall_nr_getpriority,sr);
  2067. linuxerror:=errno;
  2068. end;
  2069. end;
  2070. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  2071. {
  2072. Set Priority of process, process group, or user.
  2073. Which : selects what kind of priority is used.
  2074. can be one of the following predefined Constants :
  2075. Prio_User.
  2076. Prio_PGrp.
  2077. Prio_Process.
  2078. Who : depending on value of which, this is, respectively :
  2079. Uid
  2080. Pid
  2081. Process Group id
  2082. what : A number between -20 and 20. -20 is most favorable, 20 least.
  2083. 0 is the default.
  2084. }
  2085. var
  2086. sr : Syscallregs;
  2087. begin
  2088. errno:=0;
  2089. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  2090. linuxerror:=Sys_einval { We can save an interrupt here }
  2091. else
  2092. begin
  2093. sr.reg2:=which;
  2094. sr.reg3:=who;
  2095. sr.reg4:=what;
  2096. SysCall(Syscall_nr_setpriority,sr);
  2097. linuxerror:=errno;
  2098. end;
  2099. end;
  2100. Procedure Nice(N:integer);
  2101. {
  2102. Set process priority. A positive N means a lower priority.
  2103. A negative N decreases priority.
  2104. }
  2105. var
  2106. sr : Syscallregs;
  2107. begin
  2108. sr.reg2:=n;
  2109. SysCall(Syscall_nr_nice,sr);
  2110. linuxerror:=errno;
  2111. end;
  2112. Function GetPid:LongInt;
  2113. {
  2114. Get Process ID.
  2115. }
  2116. var
  2117. regs : SysCallregs;
  2118. begin
  2119. GetPid:=SysCall(SysCall_nr_getpid,regs);
  2120. linuxerror:=errno;
  2121. end;
  2122. Function GetPPid:LongInt;
  2123. {
  2124. Get Process ID of parent process.
  2125. }
  2126. var
  2127. regs : SysCallregs;
  2128. begin
  2129. GetPpid:=SysCall(SysCall_nr_getppid,regs);
  2130. linuxerror:=errno;
  2131. end;
  2132. Function GetUid:Longint;
  2133. {
  2134. Get User ID.
  2135. }
  2136. var
  2137. regs : SysCallregs;
  2138. begin
  2139. GetUid:=SysCall(SysCall_nr_getuid,regs);
  2140. Linuxerror:=errno;
  2141. end;
  2142. Function GetEUid:Longint;
  2143. {
  2144. Get _effective_ User ID.
  2145. }
  2146. var
  2147. regs : SysCallregs;
  2148. begin
  2149. GetEuid:=SysCall(SysCall_nr_geteuid,regs);
  2150. Linuxerror:=errno;
  2151. end;
  2152. Function GetGid:Longint;
  2153. {
  2154. Get Group ID.
  2155. }
  2156. var
  2157. regs : SysCallregs;
  2158. begin
  2159. Getgid:=SysCall(SysCall_nr_getgid,regs);
  2160. Linuxerror:=errno;
  2161. end;
  2162. Function GetEGid:Longint;
  2163. {
  2164. Get _effective_ Group ID.
  2165. }
  2166. var
  2167. regs : SysCallregs;
  2168. begin
  2169. GetEgid:=SysCall(SysCall_nr_getegid,regs);
  2170. Linuxerror:=errno;
  2171. end;
  2172. Function GetTimeOfDay: longint;
  2173. {
  2174. Get the number of seconds since 00:00, January 1 1970, GMT
  2175. the time NOT corrected any way
  2176. }
  2177. var
  2178. regs : SysCallregs;
  2179. tv : timeval;
  2180. begin
  2181. regs.reg2:=longint(@tv);
  2182. regs.reg3:=0;
  2183. SysCall(SysCall_nr_gettimeofday,regs);
  2184. LinuxError:=Errno;
  2185. GetTimeOfDay:=tv.sec;
  2186. end;
  2187. Function fdTruncate(fd,size:longint):boolean;
  2188. var
  2189. Regs : SysCallRegs;
  2190. begin
  2191. Regs.reg2:=fd;
  2192. Regs.reg3:=size;
  2193. fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
  2194. LinuxError:=Errno;
  2195. end;
  2196. Function fdFlush (fd : Longint) : Boolean;
  2197. var
  2198. SR: SysCallRegs;
  2199. begin
  2200. SR.reg2 := fd;
  2201. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  2202. LinuxError:=Errno;
  2203. end;
  2204. Function Fcntl(Fd:longint;Cmd:longint): longint;
  2205. {
  2206. Read or manipulate a file.(See also fcntl (2) )
  2207. Possible values for Cmd are :
  2208. F_GetFd,F_GetFl,F_GetOwn
  2209. Errors are reported in Linuxerror;
  2210. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  2211. }
  2212. var
  2213. sr : Syscallregs;
  2214. begin
  2215. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  2216. begin
  2217. sr.reg2:=Fd;
  2218. sr.reg3:=cmd;
  2219. Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
  2220. if linuxerror=-1 then
  2221. begin
  2222. linuxerror:=errno;
  2223. fcntl:=0;
  2224. end
  2225. else
  2226. begin
  2227. fcntl:=linuxerror;
  2228. linuxerror:=0;
  2229. end;
  2230. end
  2231. else
  2232. begin
  2233. linuxerror:=Sys_einval;
  2234. Fcntl:=0;
  2235. end;
  2236. end;
  2237. Procedure Fcntl(Fd:longint;Cmd:LongInt;Arg:Longint);
  2238. {
  2239. Read or manipulate a file. (See also fcntl (2) )
  2240. Possible values for Cmd are :
  2241. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  2242. Errors are reported in Linuxerror;
  2243. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  2244. F_DupFD is not allowed, due to the structure of Files in Pascal.
  2245. }
  2246. var
  2247. sr : Syscallregs;
  2248. begin
  2249. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  2250. begin
  2251. sr.reg2:=Fd;
  2252. sr.reg3:=cmd;
  2253. sr.reg4:=arg;
  2254. SysCall(Syscall_nr_fcntl,sr);
  2255. linuxerror:=errno;
  2256. end
  2257. else
  2258. linuxerror:=Sys_einval;
  2259. end;
  2260. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  2261. {
  2262. Changes the permissions of a file.
  2263. }
  2264. var
  2265. sr : Syscallregs;
  2266. begin
  2267. path:=path+#0;
  2268. sr.reg2:=longint(@(path[1]));
  2269. sr.reg3:=newmode;
  2270. Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
  2271. linuxerror:=errno;
  2272. end;
  2273. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  2274. {
  2275. Change the owner and group of a file.
  2276. A user can only change the group to a group of which he is a member.
  2277. The super-user can change uid and gid of any file.
  2278. }
  2279. var
  2280. sr : Syscallregs;
  2281. begin
  2282. path:=path+#0;
  2283. sr.reg2:=longint(@(path[1]));
  2284. sr.reg3:=newuid;
  2285. sr.reg4:=newgid;
  2286. ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
  2287. linuxerror:=errno;
  2288. end;
  2289. Function Utime(const path:pathstr;utim:utimebuf):boolean;
  2290. var
  2291. sr : Syscallregs;
  2292. buf : pathstr;
  2293. begin
  2294. buf:=path+#0;
  2295. sr.reg2:=longint(@(buf[1]));
  2296. sr.reg3:=longint(@utim);
  2297. Utime:=SysCall(Syscall_nr_utime,sr)=0;
  2298. linuxerror:=errno;
  2299. end;
  2300. Function Flock (fd,mode : longint) : boolean;
  2301. var
  2302. sr : Syscallregs;
  2303. begin
  2304. sr.reg2:=fd;
  2305. sr.reg3:=mode;
  2306. flock:=Syscall(Syscall_nr_flock,sr)=0;
  2307. LinuxError:=errno;
  2308. end;
  2309. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  2310. {
  2311. Get all information on a file descriptor, and return it in info.
  2312. }
  2313. var
  2314. regs : SysCallregs;
  2315. begin
  2316. regs.reg2:=Fd;
  2317. regs.reg3:=longint(@Info);
  2318. FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
  2319. LinuxError:=Errno;
  2320. end;
  2321. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  2322. {
  2323. Get all information on a link (the link itself), and return it in info.
  2324. }
  2325. var
  2326. regs : SysCallregs;
  2327. begin
  2328. FileName:=FileName+#0;
  2329. regs.reg2:=longint(@filename[1]);
  2330. regs.reg3:=longint(@Info);
  2331. LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
  2332. LinuxError:=Errno;
  2333. end;
  2334. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  2335. {
  2336. Get all information on a fileSystem, and return it in Info.
  2337. Path is the name of a file/directory on the fileSystem you wish to
  2338. investigate.
  2339. }
  2340. var
  2341. regs : SysCallregs;
  2342. begin
  2343. path:=path+#0;
  2344. regs.reg2:=longint(@path[1]);
  2345. regs.reg3:=longint(@Info);
  2346. FSStat:=(SysCall(SysCall_nr_statfs,regs)=0);
  2347. LinuxError:=errno;
  2348. end;
  2349. Function FSStat(Fd:Longint;Var Info:statfs):Boolean;
  2350. {
  2351. Get all information on a fileSystem, and return it in Info.
  2352. Fd is the file descriptor of a file/directory on the fileSystem
  2353. you wish to investigate.
  2354. }
  2355. var
  2356. regs : SysCallregs;
  2357. begin
  2358. regs.reg2:=Fd;
  2359. regs.reg3:=longint(@Info);
  2360. FSStat:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  2361. LinuxError:=errno;
  2362. end;
  2363. Function Link(OldPath,NewPath:pathstr):boolean;
  2364. {
  2365. Proceduces a hard link from new to old.
  2366. In effect, new will be the same file as old.
  2367. }
  2368. var
  2369. regs : SysCallregs;
  2370. begin
  2371. oldpath:=oldpath+#0;
  2372. newpath:=newpath+#0;
  2373. regs.reg2:=longint(@oldpath[1]);
  2374. regs.reg3:=longint(@newpath[1]);
  2375. Link:=SysCall(SysCall_nr_link,regs)=0;
  2376. linuxerror:=errno;
  2377. end;
  2378. Function Umask(Mask:Integer):integer;
  2379. {
  2380. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  2381. previous value.
  2382. }
  2383. var
  2384. sr : Syscallregs;
  2385. begin
  2386. sr.reg2:=mask;
  2387. Umask:=SysCall(Syscall_nr_umask,sr);
  2388. linuxerror:=0;
  2389. end;
  2390. Function Access(Path:Pathstr ;mode:integer):boolean;
  2391. {
  2392. Test users access rights on the specified file.
  2393. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  2394. R,W,X stand for read,write and Execute access, simultaneously.
  2395. F_OK checks whether the test would be allowed on the file.
  2396. i.e. It checks the search permissions in all directory components
  2397. of the path.
  2398. The test is done with the real user-ID, instead of the effective.
  2399. If access is denied, or an error occurred, false is returned.
  2400. If access is granted, true is returned.
  2401. Errors other than no access,are reported in linuxerror.
  2402. }
  2403. var
  2404. sr : Syscallregs;
  2405. begin
  2406. path:=path+#0;
  2407. sr.reg2:=longint(@(path[1]));
  2408. sr.reg3:=mode;
  2409. access:=(SysCall(Syscall_nr_access,sr)=0);
  2410. linuxerror:=errno;
  2411. end;
  2412. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  2413. {
  2414. Copies the filedescriptor oldfile to newfile
  2415. }
  2416. var
  2417. sr : Syscallregs;
  2418. begin
  2419. sr.reg2:=oldfile;
  2420. newfile:=Syscall(Syscall_nr_dup,sr);
  2421. linuxerror:=errno;
  2422. Dup:=(LinuxError=0);
  2423. end;
  2424. Function Dup2(oldfile,newfile:longint):Boolean;
  2425. {
  2426. Copies the filedescriptor oldfile to newfile
  2427. }
  2428. var
  2429. sr : Syscallregs;
  2430. begin
  2431. sr.reg2:=oldfile;
  2432. sr.reg3:=newfile;
  2433. SysCall(Syscall_nr_dup2,sr);
  2434. linuxerror:=errno;
  2435. Dup2:=(LinuxError=0);
  2436. end;
  2437. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  2438. {
  2439. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  2440. have changed.
  2441. }
  2442. Var
  2443. SelectArray : Array[1..5] of longint;
  2444. Sr : Syscallregs;
  2445. begin
  2446. SelectArray[1]:=n;
  2447. SelectArray[2]:=longint(Readfds);
  2448. Selectarray[3]:=longint(Writefds);
  2449. selectarray[4]:=longint(exceptfds);
  2450. Selectarray[5]:=longint(TimeOut);
  2451. sr.reg2:=longint(@selectarray);
  2452. Select:=SysCall(Syscall_nr_select,sr);
  2453. LinuxError:=Errno;
  2454. end;
  2455. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  2456. {
  2457. Sets up a pair of file variables, which act as a pipe. The first one can
  2458. be read from, the second one can be written to.
  2459. If the operation was unsuccesful, linuxerror is set.
  2460. }
  2461. var
  2462. pip : tpipe;
  2463. regs : SysCallregs;
  2464. begin
  2465. regs.reg2:=longint(@pip);
  2466. SysCall(SysCall_nr_pipe,regs);
  2467. pipe_in:=pip[1];
  2468. pipe_out:=pip[2];
  2469. linuxerror:=errno;
  2470. AssignPipe:=(LinuxError=0);
  2471. end;
  2472. Function PClose(Var F:text) :longint;
  2473. var
  2474. sr : syscallregs;
  2475. pl : ^longint;
  2476. res : longint;
  2477. begin
  2478. sr.reg2:=Textrec(F).Handle;
  2479. SysCall (syscall_nr_close,sr);
  2480. { closed our side, Now wait for the other - this appears to be needed ?? }
  2481. pl:=@(textrec(f).userdata[2]);
  2482. waitpid(pl^,@res,0);
  2483. pclose:=res shr 8;
  2484. end;
  2485. Function PClose(Var F:file) : longint;
  2486. var
  2487. sr : syscallregs;
  2488. pl : ^longint;
  2489. res : longint;
  2490. begin
  2491. sr.reg2:=FileRec(F).Handle;
  2492. SysCall (Syscall_nr_close,sr);
  2493. { closed our side, Now wait for the other - this appears to be needed ?? }
  2494. pl:=@(filerec(f).userdata[2]);
  2495. waitpid(pl^,@res,0);
  2496. pclose:=res shr 8;
  2497. end;
  2498. Function Sysinfo(var Info:TSysinfo):Boolean;
  2499. {
  2500. Get system info
  2501. }
  2502. var
  2503. regs : SysCallregs;
  2504. Begin
  2505. regs.reg2:=longint(@info);
  2506. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  2507. End;
  2508. Function mkFifo(pathname:string;mode:longint):boolean;
  2509. var
  2510. regs : SysCallRegs;
  2511. begin
  2512. pathname:=pathname+#0;
  2513. regs.reg2:=longint(@pathname[1]);
  2514. regs.reg3:=mode or STAT_IFIFO;
  2515. regs.reg4:=0;
  2516. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  2517. end;
  2518. Function Uname(var unamerec:utsname):Boolean;
  2519. {
  2520. Get machine's names
  2521. }
  2522. var
  2523. regs : SysCallregs;
  2524. Begin
  2525. regs.reg2:=longint(@unamerec);
  2526. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  2527. LinuxError:=Errno;
  2528. End;
  2529. Function Kill(Pid:longint;Sig:longint):integer;
  2530. {
  2531. Send signal 'sig' to a process, or a group of processes.
  2532. If Pid > 0 then the signal is sent to pid
  2533. pid=-1 to all processes except process 1
  2534. pid < -1 to process group -pid
  2535. Return value is zero, except for case three, where the return value
  2536. is the number of processes to which the signal was sent.
  2537. }
  2538. var
  2539. regs : Syscallregs;
  2540. begin
  2541. regs.reg2:=Pid;
  2542. regs.reg3:=Sig;
  2543. kill:=SysCall(Syscall_nr_kill,regs);
  2544. if kill<0 then
  2545. Kill:=0;
  2546. linuxerror:=errno;
  2547. end;
  2548. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
  2549. {
  2550. Change the list of currently blocked signals.
  2551. How determines which signals will be blocked :
  2552. SigBlock : Add SSet to the current list of blocked signals
  2553. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  2554. SigSetMask : Set the list of blocked signals to SSet
  2555. if OldSSet is non-null, the old set will be saved there.
  2556. }
  2557. Var
  2558. sr : SyscallRegs;
  2559. begin
  2560. sr.reg2:=how;
  2561. sr.reg3:=longint(SSet);
  2562. sr.reg4:=longint(OldSSet);
  2563. SysCall(Syscall_nr_sigprocmask,sr);
  2564. linuxerror:=errno;
  2565. end;
  2566. Function SigPending:SigSet;
  2567. {
  2568. Allows examination of pending signals. The signal mask of pending
  2569. signals is set in SSet
  2570. }
  2571. Var
  2572. sr : SyscallRegs;
  2573. dummy : Sigset;
  2574. begin
  2575. sr.reg2:=longint(@dummy);
  2576. SysCall(Syscall_nr_sigpending,sr);
  2577. linuxerror:=errno;
  2578. Sigpending:=dummy;
  2579. end;
  2580. Procedure SigSuspend(Mask:Sigset);
  2581. {
  2582. Set the signal mask with Mask, and suspend the program until a signal
  2583. is received.
  2584. }
  2585. Var
  2586. sr : SyscallRegs;
  2587. begin
  2588. sr.reg2:=mask;
  2589. SysCall(Syscall_nr_sigsuspend,sr);
  2590. linuxerror:=errno;
  2591. end;
  2592. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  2593. {
  2594. Install a new handler for signal Signum.
  2595. The old signal handler is returned.
  2596. This call does, in fact, the same as SigAction.
  2597. }
  2598. var
  2599. sr : Syscallregs;
  2600. begin
  2601. sr.reg2:=signum;
  2602. sr.reg3:=longint(handler);
  2603. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  2604. If linuxerror=Sig_Err then
  2605. begin
  2606. Signal:=nil;
  2607. Linuxerror:=errno;
  2608. end
  2609. else
  2610. begin
  2611. Signal:=signalhandler(Linuxerror);
  2612. linuxerror:=0;
  2613. end;
  2614. end;
  2615. Function Alarm(Sec : Longint) : longint;
  2616. Var Sr : Syscallregs;
  2617. begin
  2618. sr.reg2:=Sec;
  2619. Alarm:=Syscall(syscall_nr_alarm,sr);
  2620. end;
  2621. Procedure Pause;
  2622. Var Sr : Syscallregs;
  2623. begin
  2624. syscall(syscall_nr_pause,sr);
  2625. end;
  2626. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  2627. var Sr : Syscallregs;
  2628. begin
  2629. sr.reg2:=longint(@req);
  2630. sr.reg3:=longint(@rem);
  2631. NanoSleep:=Syscall(syscall_nr_nanosleep,sr);
  2632. LinuxError:=Errno;
  2633. end;
  2634. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  2635. {
  2636. Interface to Unix ioctl call.
  2637. Performs various operations on the filedescriptor Handle.
  2638. Ndx describes the operation to perform.
  2639. Data points to data needed for the Ndx function. The structure of this
  2640. data is function-dependent.
  2641. }
  2642. var
  2643. sr: SysCallRegs;
  2644. begin
  2645. sr.reg2:=Handle;
  2646. sr.reg3:=Ndx;
  2647. sr.reg4:=Longint(Data);
  2648. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  2649. LinuxError:=Errno;
  2650. end;
  2651. function MMap(const m:tmmapargs):longint;
  2652. Var
  2653. Sr : Syscallregs;
  2654. begin
  2655. Sr.reg2:=longint(@m);
  2656. MMap:=syscall(syscall_nr_mmap,sr);
  2657. LinuxError:=Errno;
  2658. end;
  2659. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  2660. Var
  2661. Sr : Syscallregs;
  2662. begin
  2663. Sr.reg2:=longint(P);
  2664. sr.reg3:=Size;
  2665. MUnMap:=syscall(syscall_nr_munmap,sr)=0;
  2666. LinuxError:=Errno;
  2667. end;
  2668. {--------------------------------
  2669. Port IO functions
  2670. --------------------------------}
  2671. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  2672. {
  2673. Set permissions on NUM ports starting with port FROM to VALUE
  2674. this works ONLY as root.
  2675. }
  2676. Var
  2677. Sr : Syscallregs;
  2678. begin
  2679. Sr.Reg2:=From;
  2680. Sr.Reg3:=Num;
  2681. Sr.Reg4:=Value;
  2682. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  2683. LinuxError:=Errno;
  2684. end;
  2685. Function IoPL(Level : longint) : Boolean;
  2686. Var
  2687. Sr : Syscallregs;
  2688. begin
  2689. Sr.Reg2:=Level;
  2690. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  2691. LinuxError:=Errno;
  2692. end;
  2693. {******************************************************************************
  2694. Process related calls
  2695. ******************************************************************************}
  2696. { Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
  2697. Function WaitProcess(Pid:longint):Longint; { like WaitPid(PID,@result,0) Handling of Signal interrupts (errno=EINTR), returning the Exitcode of Process (>=0) or -Status if terminated}
  2698. var r,s : LongInt;
  2699. begin
  2700. repeat
  2701. s:=$7F00;
  2702. r:=WaitPid(Pid,@s,0);
  2703. until (r<>-1) or (LinuxError<>Sys_EINTR);
  2704. if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
  2705. WaitProcess:=-1 // return -1 to indicate an error
  2706. else
  2707. begin
  2708. {$ifdef solaris}
  2709. if (s and $FF)=0 then // Only this is a valid returncode
  2710. {$else solaris}
  2711. { the following is at least correct for Linux and Darwin (JM) }
  2712. if (s and $7F)=0 then
  2713. {$endif solaris}
  2714. WaitProcess:=s shr 8
  2715. else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
  2716. WaitProcess:=-s // normal case
  2717. else
  2718. WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
  2719. end;
  2720. end;
  2721. function InternalCreateShellArgV(cmd:pChar; len:longint):ppchar;
  2722. {
  2723. Create an argv which executes a command in a shell using /bin/sh -c
  2724. }
  2725. const Shell = '/bin/sh'#0'-c'#0;
  2726. var
  2727. pp,p : ppchar;
  2728. // temp : string; !! Never pass a local var back!!
  2729. begin
  2730. getmem(pp,4*4);
  2731. p:=pp;
  2732. p^:=@Shell[1];
  2733. inc(p);
  2734. p^:=@Shell[9];
  2735. inc(p);
  2736. getmem(p^,len+1);
  2737. move(cmd^,p^^,len);
  2738. pchar(p^)[len]:=#0;
  2739. inc(p);
  2740. p^:=Nil;
  2741. InternalCreateShellArgV:=pp;
  2742. end;
  2743. function CreateShellArgV(const prog:string):ppchar;
  2744. begin
  2745. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
  2746. end;
  2747. function CreateShellArgV(const prog:Ansistring):ppchar;
  2748. {
  2749. Create an argv which executes a command in a shell using /bin/sh -c
  2750. using a AnsiString;
  2751. }
  2752. begin
  2753. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
  2754. end;
  2755. procedure FreeShellArgV(p:ppchar);
  2756. begin
  2757. if (p<>nil) then begin
  2758. freemem(p[2]);
  2759. freemem(p);
  2760. end;
  2761. end;
  2762. Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
  2763. {
  2764. overloaded ansistring version.
  2765. }
  2766. begin
  2767. ExecVE(PChar(Path),args,ep);
  2768. end;
  2769. Procedure Execv(const path: AnsiString;args:ppchar);
  2770. {
  2771. Overloaded ansistring version.
  2772. }
  2773. begin
  2774. ExecVe(Path,Args,envp)
  2775. end;
  2776. Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
  2777. {
  2778. Overloaded ansistring version
  2779. }
  2780. var
  2781. thepath : Ansistring;
  2782. begin
  2783. if path[1]<>'/' then
  2784. begin
  2785. Thepath:=strpas(getenv('PATH'));
  2786. if thepath='' then
  2787. thepath:='.';
  2788. Path:=FSearch(path,thepath)
  2789. end
  2790. else
  2791. Path:='';
  2792. if Path='' then
  2793. linuxerror:=Sys_enoent
  2794. else
  2795. Execve(Path,args,ep);{On error linuxerror will get set there}
  2796. end;
  2797. Procedure Execv(const path:pathstr;args:ppchar);
  2798. {
  2799. Replaces the current program by the program specified in path,
  2800. arguments in args are passed to Execve.
  2801. the current environment is passed on.
  2802. }
  2803. begin
  2804. Execve(path,args,envp); {On error linuxerror will get set there}
  2805. end;
  2806. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  2807. {
  2808. This does the same as Execve, only it searches the PATH environment
  2809. for the place of the Executable, except when Path starts with a slash.
  2810. if the PATH environment variable is unavailable, the path is set to '.'
  2811. }
  2812. var
  2813. thepath : string;
  2814. begin
  2815. if path[1]<>'/' then
  2816. begin
  2817. Thepath:=strpas(getenv('PATH'));
  2818. if thepath='' then
  2819. thepath:='.';
  2820. Path:=FSearch(path,thepath)
  2821. end
  2822. else
  2823. Path:='';
  2824. if Path='' then
  2825. linuxerror:=Sys_enoent
  2826. else
  2827. Execve(Path,args,ep);{On error linuxerror will get set there}
  2828. end;
  2829. Procedure Execle(Todo:string;Ep:ppchar);
  2830. {
  2831. This procedure takes the string 'Todo', parses it for command and
  2832. command options, and Executes the command with the given options.
  2833. The string 'Todo' shoud be of the form 'command options', options
  2834. separated by commas.
  2835. the PATH environment is not searched for 'command'.
  2836. The specified environment(in 'ep') is passed on to command
  2837. }
  2838. var
  2839. p : ppchar;
  2840. begin
  2841. p:=StringToPPChar(ToDo);
  2842. if (p=nil) or (p^=nil) then
  2843. exit;
  2844. ExecVE(p^,p,EP);
  2845. end;
  2846. Procedure Execle(Todo:AnsiString;Ep:ppchar);
  2847. {
  2848. This procedure takes the string 'Todo', parses it for command and
  2849. command options, and Executes the command with the given options.
  2850. The string 'Todo' shoud be of the form 'command options', options
  2851. separated by commas.
  2852. the PATH environment is not searched for 'command'.
  2853. The specified environment(in 'ep') is passed on to command
  2854. }
  2855. var
  2856. p : ppchar;
  2857. begin
  2858. p:=StringToPPChar(ToDo);
  2859. if (p=nil) or (p^=nil) then
  2860. exit;
  2861. ExecVE(p^,p,EP);
  2862. end;
  2863. Procedure Execl(const Todo:string);
  2864. {
  2865. This procedure takes the string 'Todo', parses it for command and
  2866. command options, and Executes the command with the given options.
  2867. The string 'Todo' shoud be of the form 'command options', options
  2868. separated by commas.
  2869. the PATH environment is not searched for 'command'.
  2870. The current environment is passed on to command
  2871. }
  2872. begin
  2873. ExecLE(ToDo,EnvP);
  2874. end;
  2875. Procedure Execl(const Todo:Ansistring);
  2876. {
  2877. Overloaded AnsiString Version of ExecL.
  2878. }
  2879. begin
  2880. ExecLE(ToDo,EnvP);
  2881. end;
  2882. Procedure Execlp(Todo:string;Ep:ppchar);
  2883. {
  2884. This procedure takes the string 'Todo', parses it for command and
  2885. command options, and Executes the command with the given options.
  2886. The string 'Todo' shoud be of the form 'command options', options
  2887. separated by commas.
  2888. the PATH environment is searched for 'command'.
  2889. The specified environment (in 'ep') is passed on to command
  2890. }
  2891. var
  2892. p : ppchar;
  2893. begin
  2894. p:=StringToPPchar(todo);
  2895. if (p=nil) or (p^=nil) then
  2896. exit;
  2897. ExecVP(StrPas(p^),p,EP);
  2898. end;
  2899. Procedure Execlp(Todo: Ansistring;Ep:ppchar);
  2900. {
  2901. Overloaded ansistring version.
  2902. }
  2903. var
  2904. p : ppchar;
  2905. begin
  2906. p:=StringToPPchar(todo);
  2907. if (p=nil) or (p^=nil) then
  2908. exit;
  2909. ExecVP(StrPas(p^),p,EP);
  2910. end;
  2911. Function Shell(const Command:String):Longint;
  2912. {
  2913. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  2914. The current environment is passed to the shell.
  2915. It waits for the shell to exit, and returns its exit status.
  2916. If the Exec call failed exit status 127 is reported.
  2917. }
  2918. { Changed the structure:
  2919. - the previous version returns an undefinied value if fork fails
  2920. - it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
  2921. - it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
  2922. - ShellArgs are now released
  2923. - The Old CreateShellArg gives back pointers to a local var
  2924. }
  2925. var
  2926. p : ppchar;
  2927. pid,r,s : longint;
  2928. begin
  2929. p:=CreateShellArgv(command);
  2930. pid:=fork;
  2931. if pid=0 then // We are in the Child
  2932. begin
  2933. {This is the child.}
  2934. Execve(p^,p,envp);
  2935. ExitProcess(127); // was Exit(127)
  2936. end
  2937. else if (pid<>-1) then // Successfull started
  2938. begin
  2939. repeat
  2940. s:=$7F00;
  2941. r:=WaitPid(Pid,@s,0);
  2942. until (r<>-1) or (LinuxError<>Sys_EINTR);
  2943. if (r=-1) or (r=0) then
  2944. Shell:=-1
  2945. else
  2946. Shell:=s;
  2947. end
  2948. else // no success
  2949. Shell:=-1; // indicate an error
  2950. FreeShellArgV(p);
  2951. end;
  2952. Function Shell(const Command:AnsiString):Longint;
  2953. {
  2954. AnsiString version of Shell
  2955. }
  2956. var
  2957. p : ppchar;
  2958. pid : longint;
  2959. begin { Changes as above }
  2960. p:=CreateShellArgv(command);
  2961. pid:=fork;
  2962. if pid=0 then // We are in the Child
  2963. begin
  2964. Execve(p^,p,envp);
  2965. ExitProcess(127); // was exit(127)!! We must exit the Process, not the function
  2966. end
  2967. else if (pid<>-1) then // Successfull started
  2968. Shell:=WaitProcess(pid) {Linuxerror is set there}
  2969. else // no success
  2970. Shell:=-1;
  2971. FreeShellArgV(p);
  2972. end;
  2973. function WEXITSTATUS(Status: Integer): Integer;
  2974. begin
  2975. WEXITSTATUS:=(Status and $FF00) shr 8;
  2976. end;
  2977. function WTERMSIG(Status: Integer): Integer;
  2978. begin
  2979. WTERMSIG:=(Status and $7F);
  2980. end;
  2981. function WSTOPSIG(Status: Integer): Integer;
  2982. begin
  2983. WSTOPSIG:=WEXITSTATUS(Status);
  2984. end;
  2985. Function WIFEXITED(Status: Integer): Boolean;
  2986. begin
  2987. WIFEXITED:=(WTERMSIG(Status)=0);
  2988. end;
  2989. Function WIFSTOPPED(Status: Integer): Boolean;
  2990. begin
  2991. WIFSTOPPED:=((Status and $FF)=$7F);
  2992. end;
  2993. Function WIFSIGNALED(Status: Integer): Boolean;
  2994. begin
  2995. WIFSIGNALED:=(not WIFSTOPPED(Status)) and
  2996. (not WIFEXITED(Status));
  2997. end;
  2998. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  2999. begin
  3000. W_EXITCODE:=(ReturnCode shl 8) or Signal;
  3001. end;
  3002. Function W_STOPCODE(Signal: Integer): Integer;
  3003. begin
  3004. W_STOPCODE:=(Signal shl 8) or $7F;
  3005. end;
  3006. {******************************************************************************
  3007. Date and Time related calls
  3008. ******************************************************************************}
  3009. Const
  3010. {Date Translation}
  3011. C1970=2440588;
  3012. D0 = 1461;
  3013. D1 = 146097;
  3014. D2 =1721119;
  3015. Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
  3016. Var
  3017. Century,XYear: LongInt;
  3018. Begin
  3019. If Month<=2 Then
  3020. Begin
  3021. Dec(Year);
  3022. Inc(Month,12);
  3023. End;
  3024. Dec(Month,3);
  3025. Century:=(longint(Year Div 100)*D1) shr 2;
  3026. XYear:=(longint(Year Mod 100)*D0) shr 2;
  3027. GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
  3028. End;
  3029. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  3030. Var
  3031. YYear,XYear,Temp,TempMonth : LongInt;
  3032. Begin
  3033. Temp:=((JulianDN-D2) shl 2)-1;
  3034. JulianDN:=Temp Div D1;
  3035. XYear:=(Temp Mod D1) or 3;
  3036. YYear:=(XYear Div D0);
  3037. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  3038. Day:=((Temp Mod 153)+5) Div 5;
  3039. TempMonth:=Temp Div 153;
  3040. If TempMonth>=10 Then
  3041. Begin
  3042. inc(YYear);
  3043. dec(TempMonth,12);
  3044. End;
  3045. inc(TempMonth,3);
  3046. Month := TempMonth;
  3047. Year:=YYear+(JulianDN*100);
  3048. end;
  3049. Function GetEpochTime: longint;
  3050. {
  3051. Get the number of seconds since 00:00, January 1 1970, GMT
  3052. the time NOT corrected any way
  3053. }
  3054. begin
  3055. GetEpochTime:=GetTimeOfDay;
  3056. end;
  3057. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  3058. {
  3059. Transforms Epoch time into local time (hour, minute,seconds)
  3060. }
  3061. Var
  3062. DateNum: LongInt;
  3063. Begin
  3064. inc(Epoch,TZSeconds);
  3065. Datenum:=(Epoch Div 86400) + c1970;
  3066. JulianToGregorian(DateNum,Year,Month,day);
  3067. Epoch:=Abs(Epoch Mod 86400);
  3068. Hour:=Epoch Div 3600;
  3069. Epoch:=Epoch Mod 3600;
  3070. Minute:=Epoch Div 60;
  3071. Second:=Epoch Mod 60;
  3072. End;
  3073. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  3074. {
  3075. Transforms local time (year,month,day,hour,minutes,second) to Epoch time
  3076. (seconds since 00:00, january 1 1970, corrected for local time zone)
  3077. }
  3078. Begin
  3079. LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
  3080. (LongInt(Hour)*3600)+(Minute*60)+Second-TZSeconds;
  3081. End;
  3082. procedure GetTime(var hour,min,sec,msec,usec:word);
  3083. {
  3084. Gets the current time, adjusted to local time
  3085. }
  3086. var
  3087. year,day,month:Word;
  3088. t : timeval;
  3089. begin
  3090. gettimeofday(t);
  3091. EpochToLocal(t.sec,year,month,day,hour,min,sec);
  3092. msec:=t.usec div 1000;
  3093. usec:=t.usec mod 1000;
  3094. end;
  3095. procedure GetTime(var hour,min,sec,sec100:word);
  3096. {
  3097. Gets the current time, adjusted to local time
  3098. }
  3099. var
  3100. usec : word;
  3101. begin
  3102. gettime(hour,min,sec,sec100,usec);
  3103. sec100:=sec100 div 10;
  3104. end;
  3105. Procedure GetTime(Var Hour,Min,Sec:Word);
  3106. {
  3107. Gets the current time, adjusted to local time
  3108. }
  3109. var
  3110. msec,usec : Word;
  3111. Begin
  3112. gettime(hour,min,sec,msec,usec);
  3113. End;
  3114. Procedure GetDate(Var Year,Month,Day:Word);
  3115. {
  3116. Gets the current date, adjusted to local time
  3117. }
  3118. var
  3119. hour,minute,second : word;
  3120. Begin
  3121. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  3122. End;
  3123. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  3124. {
  3125. Gets the current date, adjusted to local time
  3126. }
  3127. Begin
  3128. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  3129. End;
  3130. {$ifndef BSD} {Fix for 1.0.x starting compiler only}
  3131. {$ifdef linux}
  3132. Function stime (t : longint) : Boolean;
  3133. var
  3134. sr : Syscallregs;
  3135. begin
  3136. sr.reg2:=longint(@t);
  3137. SysCall(Syscall_nr_stime,sr);
  3138. linuxerror:=errno;
  3139. stime:=linuxerror=0;
  3140. end;
  3141. {$endif}
  3142. {$endif}
  3143. {$ifdef BSD}
  3144. Function stime (t : longint) : Boolean;
  3145. begin
  3146. stime:=false;
  3147. end;
  3148. {$endif}
  3149. Function SetTime(Hour,Min,Sec:word) : boolean;
  3150. var
  3151. Year, Month, Day : Word;
  3152. begin
  3153. GetDate (Year, Month, Day);
  3154. SetTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Min, Sec ) );
  3155. end;
  3156. Function SetDate(Year,Month,Day:Word) : boolean;
  3157. var
  3158. Hour, Minute, Second, Sec100 : Word;
  3159. begin
  3160. GetTime ( Hour, Minute, Second, Sec100 );
  3161. SetDate:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  3162. end;
  3163. Function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  3164. begin
  3165. SetDateTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  3166. end;
  3167. { Include timezone handling routines which use /usr/share/timezone info }
  3168. type
  3169. plongint=^longint;
  3170. pbyte=^byte;
  3171. ttzhead=packed record
  3172. tzh_reserved : array[0..19] of byte;
  3173. tzh_ttisgmtcnt,
  3174. tzh_ttisstdcnt,
  3175. tzh_leapcnt,
  3176. tzh_timecnt,
  3177. tzh_typecnt,
  3178. tzh_charcnt : longint;
  3179. end;
  3180. pttinfo=^tttinfo;
  3181. tttinfo=packed record
  3182. offset : longint;
  3183. isdst : boolean;
  3184. idx : byte;
  3185. isstd : byte;
  3186. isgmt : byte;
  3187. end;
  3188. pleap=^tleap;
  3189. tleap=record
  3190. transition : longint;
  3191. change : longint;
  3192. end;
  3193. var
  3194. num_transitions,
  3195. num_leaps,
  3196. num_types : longint;
  3197. transitions : plongint;
  3198. type_idxs : pbyte;
  3199. types : pttinfo;
  3200. zone_names : pchar;
  3201. leaps : pleap;
  3202. function find_transition(timer:longint):pttinfo;
  3203. var
  3204. i : longint;
  3205. begin
  3206. if (num_transitions=0) or (timer<transitions[0]) then
  3207. begin
  3208. i:=0;
  3209. while (i<num_types) and (types[i].isdst) do
  3210. inc(i);
  3211. if (i=num_types) then
  3212. i:=0;
  3213. end
  3214. else
  3215. begin
  3216. for i:=1 to num_transitions do
  3217. if (timer<transitions[i]) then
  3218. break;
  3219. i:=type_idxs[i-1];
  3220. end;
  3221. find_transition:=@types[i];
  3222. end;
  3223. procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
  3224. var
  3225. info : pttinfo;
  3226. i : longint;
  3227. begin
  3228. { reset }
  3229. TZDaylight:=false;
  3230. TZSeconds:=0;
  3231. TZName[false]:=nil;
  3232. TZName[true]:=nil;
  3233. leap_correct:=0;
  3234. leap_hit:=0;
  3235. { get info }
  3236. info:=find_transition(timer);
  3237. if not assigned(info) then
  3238. exit;
  3239. TZDaylight:=info^.isdst;
  3240. TZSeconds:=info^.offset;
  3241. i:=0;
  3242. while (i<num_types) do
  3243. begin
  3244. tzname[types[i].isdst]:=@zone_names[types[i].idx];
  3245. inc(i);
  3246. end;
  3247. tzname[info^.isdst]:=@zone_names[info^.idx];
  3248. i:=num_leaps;
  3249. repeat
  3250. if i=0 then
  3251. exit;
  3252. dec(i);
  3253. until (timer>leaps[i].transition);
  3254. leap_correct:=leaps[i].change;
  3255. if (timer=leaps[i].transition) and
  3256. (((i=0) and (leaps[i].change>0)) or
  3257. (leaps[i].change>leaps[i-1].change)) then
  3258. begin
  3259. leap_hit:=1;
  3260. while (i>0) and
  3261. (leaps[i].transition=leaps[i-1].transition+1) and
  3262. (leaps[i].change=leaps[i-1].change+1) do
  3263. begin
  3264. inc(leap_hit);
  3265. dec(i);
  3266. end;
  3267. end;
  3268. end;
  3269. procedure GetLocalTimezone(timer:longint);
  3270. var
  3271. lc,lh : longint;
  3272. begin
  3273. GetLocalTimezone(timer,lc,lh);
  3274. end;
  3275. procedure ReadTimezoneFile(fn:string);
  3276. procedure decode(var l:longint);
  3277. var
  3278. k : longint;
  3279. p : pbyte;
  3280. begin
  3281. p:=pbyte(@l);
  3282. if (p[0] and (1 shl 7))<>0 then
  3283. k:=not 0
  3284. else
  3285. k:=0;
  3286. k:=(k shl 8) or p[0];
  3287. k:=(k shl 8) or p[1];
  3288. k:=(k shl 8) or p[2];
  3289. k:=(k shl 8) or p[3];
  3290. l:=k;
  3291. end;
  3292. var
  3293. f : longint;
  3294. tzdir : string;
  3295. tzhead : ttzhead;
  3296. i : longint;
  3297. chars : longint;
  3298. buf : pbyte;
  3299. begin
  3300. if fn='' then
  3301. fn:='localtime';
  3302. if fn[1]<>'/' then
  3303. begin
  3304. tzdir:=getenv('TZDIR');
  3305. if tzdir='' then
  3306. tzdir:='/usr/share/zoneinfo';
  3307. if tzdir[length(tzdir)]<>'/' then
  3308. tzdir:=tzdir+'/';
  3309. fn:=tzdir+fn;
  3310. end;
  3311. f:=fdopen(fn,Open_RdOnly);
  3312. if f<0 then
  3313. exit;
  3314. i:=fdread(f,tzhead,sizeof(tzhead));
  3315. if i<>sizeof(tzhead) then
  3316. exit;
  3317. decode(tzhead.tzh_timecnt);
  3318. decode(tzhead.tzh_typecnt);
  3319. decode(tzhead.tzh_charcnt);
  3320. decode(tzhead.tzh_leapcnt);
  3321. decode(tzhead.tzh_ttisstdcnt);
  3322. decode(tzhead.tzh_ttisgmtcnt);
  3323. num_transitions:=tzhead.tzh_timecnt;
  3324. num_types:=tzhead.tzh_typecnt;
  3325. chars:=tzhead.tzh_charcnt;
  3326. reallocmem(transitions,num_transitions*sizeof(longint));
  3327. reallocmem(type_idxs,num_transitions);
  3328. reallocmem(types,num_types*sizeof(tttinfo));
  3329. reallocmem(zone_names,chars);
  3330. reallocmem(leaps,num_leaps*sizeof(tleap));
  3331. fdread(f,transitions^,num_transitions*4);
  3332. fdread(f,type_idxs^,num_transitions);
  3333. for i:=0 to num_transitions-1 do
  3334. decode(transitions[i]);
  3335. for i:=0 to num_types-1 do
  3336. begin
  3337. fdread(f,types[i].offset,4);
  3338. fdread(f,types[i].isdst,1);
  3339. fdread(f,types[i].idx,1);
  3340. decode(types[i].offset);
  3341. types[i].isstd:=0;
  3342. types[i].isgmt:=0;
  3343. end;
  3344. fdread(f,zone_names^,chars);
  3345. for i:=0 to num_leaps-1 do
  3346. begin
  3347. fdread(f,leaps[i].transition,4);
  3348. fdread(f,leaps[i].change,4);
  3349. decode(leaps[i].transition);
  3350. decode(leaps[i].change);
  3351. end;
  3352. getmem(buf,tzhead.tzh_ttisstdcnt);
  3353. fdread(f,buf^,tzhead.tzh_ttisstdcnt);
  3354. for i:=0 to tzhead.tzh_ttisstdcnt-1 do
  3355. types[i].isstd:=byte(buf[i]<>0);
  3356. freemem(buf);
  3357. getmem(buf,tzhead.tzh_ttisgmtcnt);
  3358. fdread(f,buf^,tzhead.tzh_ttisgmtcnt);
  3359. for i:=0 to tzhead.tzh_ttisgmtcnt-1 do
  3360. types[i].isgmt:=byte(buf[i]<>0);
  3361. freemem(buf);
  3362. fdclose(f);
  3363. end;
  3364. Const
  3365. // Debian system; contains location of timezone file.
  3366. TimeZoneLocationFile = '/etc/timezone';
  3367. // SuSE has link in /usr/lib/zoneinfo/localtime to /etc/localtime
  3368. // RedHat uses /etc/localtime
  3369. TimeZoneFile = '/usr/lib/zoneinfo/localtime';
  3370. AltTimeZoneFile = '/etc/localtime';
  3371. function GetTimezoneFile:string;
  3372. var
  3373. f,len : longint;
  3374. s : string;
  3375. info : stat;
  3376. begin
  3377. GetTimezoneFile:='';
  3378. f:=fdopen(TimeZoneLocationFile,Open_RdOnly);
  3379. if f>0 then
  3380. begin
  3381. len:=fdread(f,s[1],high(s));
  3382. s[0]:=chr(len);
  3383. len:=pos(#10,s);
  3384. if len<>0 then
  3385. s[0]:=chr(len-1);
  3386. fdclose(f);
  3387. GetTimezoneFile:=s;
  3388. end
  3389. // Try SuSE
  3390. else if fstat(TimeZoneFile,info) then
  3391. GetTimeZoneFile:=TimeZoneFile
  3392. // Try RedHat
  3393. else If fstat(AltTimeZoneFile,Info) then
  3394. GetTimeZoneFile:=AltTimeZoneFile;
  3395. end;
  3396. procedure InitLocalTime;
  3397. begin
  3398. ReadTimezoneFile(GetTimezoneFile);
  3399. GetLocalTimezone(GetTimeOfDay);
  3400. end;
  3401. procedure DoneLocalTime;
  3402. begin
  3403. if assigned(transitions) then
  3404. freemem(transitions);
  3405. if assigned(type_idxs) then
  3406. freemem(type_idxs);
  3407. if assigned(types) then
  3408. freemem(types);
  3409. if assigned(zone_names) then
  3410. freemem(zone_names);
  3411. if assigned(leaps) then
  3412. freemem(leaps);
  3413. num_transitions:=0;
  3414. num_leaps:=0;
  3415. num_types:=0;
  3416. end;
  3417. {******************************************************************************
  3418. FileSystem calls
  3419. ******************************************************************************}
  3420. Function fdOpen(pathname:string;flags:longint):longint;
  3421. begin
  3422. pathname:=pathname+#0;
  3423. fdOpen:=Sys_Open(@pathname[1],flags,438);
  3424. LinuxError:=Errno;
  3425. end;
  3426. Function fdOpen(pathname:string;flags,mode:longint):longint;
  3427. begin
  3428. pathname:=pathname+#0;
  3429. fdOpen:=Sys_Open(@pathname[1],flags,mode);
  3430. LinuxError:=Errno;
  3431. end;
  3432. Function fdOpen(pathname:pchar;flags:longint):longint;
  3433. begin
  3434. fdOpen:=Sys_Open(pathname,flags,0);
  3435. LinuxError:=Errno;
  3436. end;
  3437. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  3438. begin
  3439. fdOpen:=Sys_Open(pathname,flags,mode);
  3440. LinuxError:=Errno;
  3441. end;
  3442. Function fdClose(fd:longint):boolean;
  3443. begin
  3444. fdClose:=(Sys_Close(fd)=0);
  3445. LinuxError:=Errno;
  3446. end;
  3447. Function fdRead(fd:longint;var buf;size:longint):longint;
  3448. begin
  3449. fdRead:=Sys_Read(fd,pchar(@buf),size);
  3450. LinuxError:=Errno;
  3451. end;
  3452. Function fdWrite(fd:longint;const buf;size:longint):longint;
  3453. begin
  3454. fdWrite:=Sys_Write(fd,pchar(@buf),size);
  3455. LinuxError:=Errno;
  3456. end;
  3457. Function fdSeek (fd,pos,seektype :longint): longint;
  3458. {
  3459. Do a Seek on a file descriptor fd to position pos, starting from seektype
  3460. }
  3461. begin
  3462. fdseek:=Sys_LSeek (fd,pos,seektype);
  3463. LinuxError:=Errno;
  3464. end;
  3465. {$ifdef BSD}
  3466. Function Fcntl(Fd:longint;Cmd:longint):longint;
  3467. {
  3468. Read or manipulate a file.(See also fcntl (2) )
  3469. Possible values for Cmd are :
  3470. F_GetFd,F_GetFl,F_GetOwn
  3471. Errors are reported in Linuxerror;
  3472. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  3473. }
  3474. begin
  3475. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  3476. begin
  3477. Linuxerror:=sys_fcntl(fd,cmd,0);
  3478. if linuxerror=-1 then
  3479. begin
  3480. linuxerror:=errno;
  3481. fcntl:=0;
  3482. end
  3483. else
  3484. begin
  3485. fcntl:=linuxerror;
  3486. linuxerror:=0;
  3487. end;
  3488. end
  3489. else
  3490. begin
  3491. linuxerror:=Sys_einval;
  3492. Fcntl:=0;
  3493. end;
  3494. end;
  3495. Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
  3496. {
  3497. Read or manipulate a file. (See also fcntl (2) )
  3498. Possible values for Cmd are :
  3499. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  3500. Errors are reported in Linuxerror;
  3501. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  3502. F_DupFD is not allowed, due to the structure of Files in Pascal.
  3503. }
  3504. begin
  3505. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  3506. begin
  3507. sys_fcntl(fd,cmd,arg);
  3508. LinuxError:=ErrNo;
  3509. end
  3510. else
  3511. linuxerror:=Sys_einval;
  3512. end;
  3513. {$endif}
  3514. Function Fcntl(var Fd:Text;Cmd:longint):longint;
  3515. begin
  3516. Fcntl := Fcntl(textrec(Fd).handle, Cmd);
  3517. end;
  3518. Procedure Fcntl(var Fd:Text;Cmd,Arg:Longint);
  3519. begin
  3520. Fcntl(textrec(Fd).handle, Cmd, Arg);
  3521. end;
  3522. Function Flock (var T : text;mode : longint) : boolean;
  3523. begin
  3524. Flock:=Flock(TextRec(T).Handle,mode);
  3525. end;
  3526. Function Flock (var F : File;mode : longint) : boolean;
  3527. begin
  3528. Flock:=Flock(FileRec(F).Handle,mode);
  3529. end;
  3530. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  3531. {
  3532. Get all information on a file, and return it in Info.
  3533. }
  3534. begin
  3535. path:=path+#0;
  3536. FStat:=(Sys_stat(@(path[1]),Info)=0);
  3537. LinuxError:=errno;
  3538. end;
  3539. Function FStat(var F:Text;Var Info:stat):Boolean;
  3540. {
  3541. Get all information on a text file, and return it in info.
  3542. }
  3543. begin
  3544. FStat:=Fstat(TextRec(F).Handle,INfo);
  3545. end;
  3546. Function FStat(var F:File;Var Info:stat):Boolean;
  3547. {
  3548. Get all information on a untyped file, and return it in info.
  3549. }
  3550. begin
  3551. FStat:=Fstat(FileRec(F).Handle,Info);
  3552. end;
  3553. Function SymLink(OldPath,newPath:pathstr):boolean;
  3554. {
  3555. Proceduces a soft link from new to old.
  3556. }
  3557. begin
  3558. oldpath:=oldpath+#0;
  3559. newpath:=newpath+#0;
  3560. Symlink:=Sys_symlink(pchar(@(oldpath[1])),pchar(@(newpath[1])))=0;
  3561. linuxerror:=errno;
  3562. end;
  3563. Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
  3564. {
  3565. Read a link (where it points to)
  3566. }
  3567. begin
  3568. Readlink:=Sys_readlink(Name,LinkName,maxlen);
  3569. linuxerror:=errno;
  3570. end;
  3571. Function ReadLink(Name:pathstr):pathstr;
  3572. {
  3573. Read a link (where it points to)
  3574. }
  3575. var
  3576. LinkName : pathstr;
  3577. i : longint;
  3578. begin
  3579. Name:=Name+#0;
  3580. i:=ReadLink(@Name[1],@LinkName[1],high(linkname));
  3581. if i>0 then
  3582. begin
  3583. linkname[0]:=chr(i);
  3584. ReadLink:=LinkName;
  3585. end
  3586. else
  3587. ReadLink:='';
  3588. end;
  3589. Function UnLink(Path:pathstr):boolean;
  3590. {
  3591. Removes the file in 'Path' (that is, it decreases the link count with one.
  3592. if the link count is zero, the file is removed from the disk.
  3593. }
  3594. begin
  3595. path:=path+#0;
  3596. Unlink:=Sys_unlink(pchar(@(path[1])))=0;
  3597. linuxerror:=errno;
  3598. end;
  3599. Function UnLink(Path:pchar):Boolean;
  3600. {
  3601. Removes the file in 'Path' (that is, it decreases the link count with one.
  3602. if the link count is zero, the file is removed from the disk.
  3603. }
  3604. begin
  3605. Unlink:=(Sys_unlink(path)=0);
  3606. linuxerror:=errno;
  3607. end;
  3608. Function FRename (OldName,NewName : Pchar) : Boolean;
  3609. begin
  3610. FRename:=Sys_rename(OldName,NewName)=0;
  3611. LinuxError:=Errno;
  3612. end;
  3613. Function FRename (OldName,NewName : String) : Boolean;
  3614. begin
  3615. OldName:=OldName+#0;
  3616. NewName:=NewName+#0;
  3617. FRename:=FRename (@OldName[1],@NewName[1]);
  3618. end;
  3619. Function Dup(var oldfile,newfile:text):Boolean;
  3620. {
  3621. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  3622. oldfile.
  3623. After which the two textfiles are, in effect, the same, except
  3624. that they don't share the same buffer, and don't share the same
  3625. close_on_exit flag.
  3626. }
  3627. begin
  3628. flush(oldfile);{ We cannot share buffers, so we flush them. }
  3629. textrec(newfile):=textrec(oldfile);
  3630. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  3631. Dup:=Dup(textrec(oldfile).handle,textrec(newfile).handle);
  3632. end;
  3633. Function Dup(var oldfile,newfile:file):Boolean;
  3634. {
  3635. Copies the filedescriptor oldfile to newfile
  3636. }
  3637. begin
  3638. filerec(newfile):=filerec(oldfile);
  3639. Dup:=Dup(filerec(oldfile).handle,filerec(newfile).handle);
  3640. end;
  3641. Function Dup2(var oldfile,newfile:text):Boolean;
  3642. {
  3643. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  3644. oldfile. It closes newfile if it was still open.
  3645. After which the two textfiles are, in effect, the same, except
  3646. that they don't share the same buffer, and don't share the same
  3647. close_on_exit flag.
  3648. }
  3649. var
  3650. tmphandle : word;
  3651. begin
  3652. case TextRec(oldfile).mode of
  3653. fmOutput, fmInOut, fmAppend :
  3654. flush(oldfile);{ We cannot share buffers, so we flush them. }
  3655. end;
  3656. case TextRec(newfile).mode of
  3657. fmOutput, fmInOut, fmAppend :
  3658. flush(newfile);
  3659. end;
  3660. tmphandle:=textrec(newfile).handle;
  3661. textrec(newfile):=textrec(oldfile);
  3662. textrec(newfile).handle:=tmphandle;
  3663. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  3664. Dup2:=Dup2(textrec(oldfile).handle,textrec(newfile).handle);
  3665. end;
  3666. Function Dup2(var oldfile,newfile:file):Boolean;
  3667. {
  3668. Copies the filedescriptor oldfile to newfile
  3669. }
  3670. begin
  3671. filerec(newfile):=filerec(oldfile);
  3672. Dup2:=Dup2(filerec(oldfile).handle,filerec(newfile).handle);
  3673. end;
  3674. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  3675. {
  3676. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  3677. have changed.
  3678. This function allows specification of a timeout as a longint.
  3679. }
  3680. var
  3681. p : PTimeVal;
  3682. tv : TimeVal;
  3683. begin
  3684. if TimeOut=-1 then
  3685. p:=nil
  3686. else
  3687. begin
  3688. tv.Sec:=Timeout div 1000;
  3689. tv.Usec:=(Timeout mod 1000)*1000;
  3690. p:=@tv;
  3691. end;
  3692. Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
  3693. end;
  3694. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  3695. Var
  3696. F:FDSet;
  3697. begin
  3698. if textrec(t).mode=fmclosed then
  3699. begin
  3700. LinuxError:=Sys_EBADF;
  3701. exit(-1);
  3702. end;
  3703. FD_Zero(f);
  3704. FD_Set(textrec(T).handle,f);
  3705. if textrec(T).mode=fminput then
  3706. SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
  3707. else
  3708. SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
  3709. end;
  3710. Function SelectText(var T:Text;TimeOut :Longint):Longint;
  3711. var
  3712. p : PTimeVal;
  3713. tv : TimeVal;
  3714. begin
  3715. if TimeOut=-1 then
  3716. p:=nil
  3717. else
  3718. begin
  3719. tv.Sec:=Timeout div 1000;
  3720. tv.Usec:=(Timeout mod 1000)*1000;
  3721. p:=@tv;
  3722. end;
  3723. SelectText:=SelectText(T,p);
  3724. end;
  3725. {******************************************************************************
  3726. Directory
  3727. ******************************************************************************}
  3728. Function OpenDir(F:String):PDir;
  3729. begin
  3730. F:=F+#0;
  3731. OpenDir:=OpenDir(@F[1]);
  3732. LinuxError:=ErrNo;
  3733. end;
  3734. {$ifndef newreaddir}
  3735. procedure SeekDir(p:pdir;off:longint);
  3736. begin
  3737. if p=nil then
  3738. begin
  3739. errno:=Sys_EBADF;
  3740. exit;
  3741. end;
  3742. {$ifndef bsd}
  3743. p^.nextoff:=Sys_lseek(p^.fd,off,seek_set);
  3744. {$endif}
  3745. p^.size:=0;
  3746. p^.loc:=0;
  3747. end;
  3748. function TellDir(p:pdir):longint;
  3749. begin
  3750. if p=nil then
  3751. begin
  3752. errno:=Sys_EBADF;
  3753. telldir:=-1;
  3754. exit;
  3755. end;
  3756. telldir:=Sys_lseek(p^.fd,0,seek_cur)
  3757. { We could try to use the nextoff field here, but on my 1.2.13
  3758. kernel, this gives nothing... This may have to do with
  3759. the readdir implementation of libc... I also didn't find any trace of
  3760. the field in the kernel code itself, So I suspect it is an artifact of libc.
  3761. Michael. }
  3762. end;
  3763. {$endif}
  3764. Function ReadDir(P:pdir):pdirent;
  3765. begin
  3766. ReadDir:=Sys_ReadDir(p);
  3767. LinuxError:=Errno;
  3768. end;
  3769. {******************************************************************************
  3770. Pipes/Fifo
  3771. ******************************************************************************}
  3772. Procedure OpenPipe(var F:Text);
  3773. begin
  3774. case textrec(f).mode of
  3775. fmoutput :
  3776. if textrec(f).userdata[1]<>P_OUT then
  3777. textrec(f).mode:=fmclosed;
  3778. fminput :
  3779. if textrec(f).userdata[1]<>P_IN then
  3780. textrec(f).mode:=fmclosed;
  3781. else
  3782. textrec(f).mode:=fmclosed;
  3783. end;
  3784. end;
  3785. Procedure IOPipe(var F:text);
  3786. begin
  3787. case textrec(f).mode of
  3788. fmoutput :
  3789. begin
  3790. { first check if we need something to write, else we may
  3791. get a SigPipe when Close() is called (PFV) }
  3792. if textrec(f).bufpos>0 then
  3793. Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  3794. end;
  3795. fminput :
  3796. textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  3797. end;
  3798. textrec(f).bufpos:=0;
  3799. end;
  3800. Procedure FlushPipe(var F:Text);
  3801. begin
  3802. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  3803. IOPipe(f);
  3804. textrec(f).bufpos:=0;
  3805. end;
  3806. Procedure ClosePipe(var F:text);
  3807. begin
  3808. textrec(f).mode:=fmclosed;
  3809. Sys_close(textrec(f).handle);
  3810. end;
  3811. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  3812. {
  3813. Sets up a pair of file variables, which act as a pipe. The first one can
  3814. be read from, the second one can be written to.
  3815. If the operation was unsuccesful, linuxerror is set.
  3816. }
  3817. var
  3818. f_in,f_out : longint;
  3819. begin
  3820. if not AssignPipe(f_in,f_out) then
  3821. begin
  3822. AssignPipe:=false;
  3823. exit;
  3824. end;
  3825. { Set up input }
  3826. Assign(Pipe_in,'');
  3827. Textrec(Pipe_in).Handle:=f_in;
  3828. Textrec(Pipe_in).Mode:=fmInput;
  3829. Textrec(Pipe_in).userdata[1]:=P_IN;
  3830. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  3831. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  3832. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  3833. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  3834. { Set up output }
  3835. Assign(Pipe_out,'');
  3836. Textrec(Pipe_out).Handle:=f_out;
  3837. Textrec(Pipe_out).Mode:=fmOutput;
  3838. Textrec(Pipe_out).userdata[1]:=P_OUT;
  3839. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  3840. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  3841. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  3842. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  3843. AssignPipe:=true;
  3844. end;
  3845. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  3846. {
  3847. Sets up a pair of file variables, which act as a pipe. The first one can
  3848. be read from, the second one can be written to.
  3849. If the operation was unsuccesful, linuxerror is set.
  3850. }
  3851. var
  3852. f_in,f_out : longint;
  3853. begin
  3854. if not AssignPipe(f_in,f_out) then
  3855. begin
  3856. AssignPipe:=false;
  3857. exit;
  3858. end;
  3859. { Set up input }
  3860. Assign(Pipe_in,'');
  3861. Filerec(Pipe_in).Handle:=f_in;
  3862. Filerec(Pipe_in).Mode:=fmInput;
  3863. Filerec(Pipe_in).recsize:=1;
  3864. Filerec(Pipe_in).userdata[1]:=P_IN;
  3865. { Set up output }
  3866. Assign(Pipe_out,'');
  3867. Filerec(Pipe_out).Handle:=f_out;
  3868. Filerec(Pipe_out).Mode:=fmoutput;
  3869. Filerec(Pipe_out).recsize:=1;
  3870. Filerec(Pipe_out).userdata[1]:=P_OUT;
  3871. AssignPipe:=true;
  3872. end;
  3873. Procedure PCloseText(Var F:text);
  3874. {
  3875. May not use @PClose due overloading
  3876. }
  3877. begin
  3878. PClose(f);
  3879. end;
  3880. Procedure POpen(var F:text;const Prog:String;rw:char);
  3881. {
  3882. Starts the program in 'Prog' and makes it's input or out put the
  3883. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  3884. F, will be read from stdin by the program in 'Prog'. The inverse is true
  3885. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  3886. read from 'f'.
  3887. }
  3888. var
  3889. pipi,
  3890. pipo : text;
  3891. pid : longint;
  3892. pl : ^longint;
  3893. pp : ppchar;
  3894. begin
  3895. LinuxError:=0;
  3896. rw:=upcase(rw);
  3897. if not (rw in ['R','W']) then
  3898. begin
  3899. LinuxError:=Sys_enoent;
  3900. exit;
  3901. end;
  3902. AssignPipe(pipi,pipo);
  3903. if Linuxerror<>0 then
  3904. exit;
  3905. pid:=fork;
  3906. if linuxerror<>0 then
  3907. begin
  3908. close(pipi);
  3909. close(pipo);
  3910. exit;
  3911. end;
  3912. if pid=0 then
  3913. begin
  3914. {$ifdef BSD} // FreeBSD checked only
  3915. { We're in the child }
  3916. close(pipi);
  3917. if textrec(pipo).handle<>textrec(output).handle Then
  3918. begin
  3919. dup2(textrec(pipo).handle,textrec(output).handle);
  3920. if rw='W' Then
  3921. dup2(textrec(output).handle,textrec(input).handle);
  3922. end
  3923. else
  3924. if (rw='W') and (textrec(pipi).handle<>textrec(input).handle) then
  3925. dup2(textrec(output).handle,textrec(input).handle);
  3926. close(pipo);
  3927. if linuxerror<>0 then
  3928. halt(127);
  3929. pp:=createshellargv(prog);
  3930. Execve(pp^,pp,envp);
  3931. halt(127);
  3932. end
  3933. {$else}
  3934. { We're in the child }
  3935. if rw='W' then
  3936. begin
  3937. close(pipo);
  3938. dup2(pipi,input);
  3939. close(pipi);
  3940. if linuxerror<>0 then
  3941. halt(127);
  3942. end
  3943. else
  3944. begin
  3945. close(pipi);
  3946. dup2(pipo,output);
  3947. close(pipo);
  3948. if linuxerror<>0 then
  3949. halt(127);
  3950. end;
  3951. pp:=createshellargv(prog);
  3952. Execve(pp^,pp,envp);
  3953. halt(127);
  3954. end
  3955. {$endif}
  3956. else
  3957. begin
  3958. { We're in the parent }
  3959. if rw='W' then
  3960. begin
  3961. close(pipi);
  3962. f:=pipo;
  3963. textrec(f).bufptr:=@textrec(f).buffer;
  3964. end
  3965. else
  3966. begin
  3967. close(pipo);
  3968. f:=pipi;
  3969. textrec(f).bufptr:=@textrec(f).buffer;
  3970. end;
  3971. {Save the process ID - needed when closing }
  3972. pl:=@(textrec(f).userdata[2]);
  3973. pl^:=pid;
  3974. textrec(f).closefunc:=@PCloseText;
  3975. end;
  3976. end;
  3977. Procedure POpen(var F:file;const Prog:String;rw:char);
  3978. {
  3979. Starts the program in 'Prog' and makes it's input or out put the
  3980. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  3981. F, will be read from stdin by the program in 'Prog'. The inverse is true
  3982. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  3983. read from 'f'.
  3984. }
  3985. var
  3986. pipi,
  3987. pipo : file;
  3988. pid : longint;
  3989. pl : ^longint;
  3990. p,pp : ppchar;
  3991. temp : string[255];
  3992. begin
  3993. LinuxError:=0;
  3994. rw:=upcase(rw);
  3995. if not (rw in ['R','W']) then
  3996. begin
  3997. LinuxError:=Sys_enoent;
  3998. exit;
  3999. end;
  4000. AssignPipe(pipi,pipo);
  4001. if Linuxerror<>0 then
  4002. exit;
  4003. pid:=fork;
  4004. if linuxerror<>0 then
  4005. begin
  4006. close(pipi);
  4007. close(pipo);
  4008. exit;
  4009. end;
  4010. if pid=0 then
  4011. begin
  4012. { We're in the child }
  4013. if rw='W' then
  4014. begin
  4015. close(pipo);
  4016. dup2(filerec(pipi).handle,stdinputhandle);
  4017. close(pipi);
  4018. if linuxerror<>0 then
  4019. halt(127);
  4020. end
  4021. else
  4022. begin
  4023. close(pipi);
  4024. dup2(filerec(pipo).handle,stdoutputhandle);
  4025. close(pipo);
  4026. if linuxerror<>0 then
  4027. halt(127);
  4028. end;
  4029. getmem(pp,sizeof(pchar)*4);
  4030. temp:='/bin/sh'#0'-c'#0+prog+#0;
  4031. p:=pp;
  4032. p^:=@temp[1];
  4033. inc(p);
  4034. p^:=@temp[9];
  4035. inc(p);
  4036. p^:=@temp[12];
  4037. inc(p);
  4038. p^:=Nil;
  4039. Execve('/bin/sh',pp,envp);
  4040. halt(127);
  4041. end
  4042. else
  4043. begin
  4044. { We're in the parent }
  4045. if rw='W' then
  4046. begin
  4047. close(pipi);
  4048. f:=pipo;
  4049. end
  4050. else
  4051. begin
  4052. close(pipo);
  4053. f:=pipi;
  4054. end;
  4055. {Save the process ID - needed when closing }
  4056. pl:=@(filerec(f).userdata[2]);
  4057. pl^:=pid;
  4058. end;
  4059. end;
  4060. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  4061. {
  4062. Starts the program in 'Prog' and makes its input and output the
  4063. other end of two pipes, which are the stdin and stdout of a program
  4064. specified in 'Prog'.
  4065. streamout can be used to write to the program, streamin can be used to read
  4066. the output of the program. See the following diagram :
  4067. Parent Child
  4068. STreamout --> Input
  4069. Streamin <-- Output
  4070. Return value is the process ID of the process being spawned, or -1 in case of failure.
  4071. }
  4072. var
  4073. pipi,
  4074. pipo : text;
  4075. pid : longint;
  4076. pl : ^Longint;
  4077. begin
  4078. LinuxError:=0;
  4079. AssignStream:=-1;
  4080. AssignPipe(streamin,pipo);
  4081. if Linuxerror<>0 then
  4082. exit;
  4083. AssignPipe(pipi,streamout);
  4084. if Linuxerror<>0 then
  4085. exit;
  4086. pid:=fork;
  4087. if linuxerror<>0 then
  4088. begin
  4089. close(pipi);
  4090. close(pipo);
  4091. close (streamin);
  4092. close (streamout);
  4093. exit;
  4094. end;
  4095. if pid=0 then
  4096. begin
  4097. { We're in the child }
  4098. { Close what we don't need }
  4099. close(streamout);
  4100. close(streamin);
  4101. dup2(pipi,input);
  4102. if linuxerror<>0 then
  4103. halt(127);
  4104. close(pipi);
  4105. dup2(pipo,output);
  4106. if linuxerror<>0 then
  4107. halt (127);
  4108. close(pipo);
  4109. Execl(Prog);
  4110. halt(127);
  4111. end
  4112. else
  4113. begin
  4114. { we're in the parent}
  4115. close(pipo);
  4116. close(pipi);
  4117. {Save the process ID - needed when closing }
  4118. pl:=@(textrec(StreamIn).userdata[2]);
  4119. pl^:=pid;
  4120. textrec(StreamIn).closefunc:=@PCloseText;
  4121. {Save the process ID - needed when closing }
  4122. pl:=@(textrec(StreamOut).userdata[2]);
  4123. pl^:=pid;
  4124. textrec(StreamOut).closefunc:=@PCloseText;
  4125. AssignStream:=Pid;
  4126. end;
  4127. end;
  4128. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  4129. {
  4130. Starts the program in 'prog' and makes its input, output and error output the
  4131. other end of three pipes, which are the stdin, stdout and stderr of a program
  4132. specified in 'prog'.
  4133. StreamOut can be used to write to the program, StreamIn can be used to read
  4134. the output of the program, StreamErr reads the error output of the program.
  4135. See the following diagram :
  4136. Parent Child
  4137. StreamOut --> StdIn (input)
  4138. StreamIn <-- StdOut (output)
  4139. StreamErr <-- StdErr (error output)
  4140. }
  4141. var
  4142. PipeIn, PipeOut, PipeErr: text;
  4143. pid: LongInt;
  4144. pl: ^LongInt;
  4145. begin
  4146. LinuxError := 0;
  4147. AssignStream := -1;
  4148. // Assign pipes
  4149. AssignPipe(StreamIn, PipeOut);
  4150. if LinuxError <> 0 then exit;
  4151. AssignPipe(StreamErr, PipeErr);
  4152. if LinuxError <> 0 then begin
  4153. Close(StreamIn);
  4154. Close(PipeOut);
  4155. exit;
  4156. end;
  4157. AssignPipe(PipeIn, StreamOut);
  4158. if LinuxError <> 0 then begin
  4159. Close(StreamIn);
  4160. Close(PipeOut);
  4161. Close(StreamErr);
  4162. Close(PipeErr);
  4163. exit;
  4164. end;
  4165. // Fork
  4166. pid := Fork;
  4167. if LinuxError <> 0 then begin
  4168. Close(StreamIn);
  4169. Close(PipeOut);
  4170. Close(StreamErr);
  4171. Close(PipeErr);
  4172. Close(PipeIn);
  4173. Close(StreamOut);
  4174. exit;
  4175. end;
  4176. if pid = 0 then begin
  4177. // *** We are in the child ***
  4178. // Close what we don not need
  4179. Close(StreamOut);
  4180. Close(StreamIn);
  4181. Close(StreamErr);
  4182. // Connect pipes
  4183. dup2(PipeIn, Input);
  4184. if LinuxError <> 0 then Halt(127);
  4185. Close(PipeIn);
  4186. dup2(PipeOut, Output);
  4187. if LinuxError <> 0 then Halt(127);
  4188. Close(PipeOut);
  4189. dup2(PipeErr, StdErr);
  4190. if LinuxError <> 0 then Halt(127);
  4191. Close(PipeErr);
  4192. // Execute program
  4193. Execl(Prog);
  4194. Halt(127);
  4195. end else begin
  4196. // *** We are in the parent ***
  4197. Close(PipeErr);
  4198. Close(PipeOut);
  4199. Close(PipeIn);
  4200. // Save the process ID - needed when closing
  4201. pl := @(TextRec(StreamIn).userdata[2]);
  4202. pl^ := pid;
  4203. TextRec(StreamIn).closefunc := @PCloseText;
  4204. // Save the process ID - needed when closing
  4205. pl := @(TextRec(StreamOut).userdata[2]);
  4206. pl^ := pid;
  4207. TextRec(StreamOut).closefunc := @PCloseText;
  4208. // Save the process ID - needed when closing
  4209. pl := @(TextRec(StreamErr).userdata[2]);
  4210. pl^ := pid;
  4211. TextRec(StreamErr).closefunc := @PCloseText;
  4212. AssignStream := pid;
  4213. end;
  4214. end;
  4215. {******************************************************************************
  4216. General information calls
  4217. ******************************************************************************}
  4218. Function GetEnv(P:string):Pchar;
  4219. {
  4220. Searches the environment for a string with name p and
  4221. returns a pchar to it's value.
  4222. A pchar is used to accomodate for strings of length > 255
  4223. }
  4224. var
  4225. ep : ppchar;
  4226. found : boolean;
  4227. Begin
  4228. p:=p+'='; {Else HOST will also find HOSTNAME, etc}
  4229. ep:=envp;
  4230. found:=false;
  4231. if ep<>nil then
  4232. begin
  4233. while (not found) and (ep^<>nil) do
  4234. begin
  4235. if strlcomp(@p[1],(ep^),length(p))=0 then
  4236. found:=true
  4237. else
  4238. inc(ep);
  4239. end;
  4240. end;
  4241. if found then
  4242. getenv:=ep^+length(p)
  4243. else
  4244. getenv:=nil;
  4245. end;
  4246. {$ifndef bsd}
  4247. Function GetDomainName:String;
  4248. {
  4249. Get machines domain name. Returns empty string if not set.
  4250. }
  4251. Var
  4252. Sysn : utsname;
  4253. begin
  4254. Uname(Sysn);
  4255. linuxerror:=errno;
  4256. If linuxerror<>0 then
  4257. getdomainname:=''
  4258. else
  4259. getdomainname:=strpas(@Sysn.domainname[0]);
  4260. end;
  4261. Function GetHostName:String;
  4262. {
  4263. Get machines name. Returns empty string if not set.
  4264. }
  4265. Var
  4266. Sysn : utsname;
  4267. begin
  4268. uname(Sysn);
  4269. linuxerror:=errno;
  4270. If linuxerror<>0 then
  4271. gethostname:=''
  4272. else
  4273. gethostname:=strpas(@Sysn.nodename[0]);
  4274. end;
  4275. {$endif}
  4276. {******************************************************************************
  4277. Signal handling calls
  4278. ******************************************************************************}
  4279. procedure SigRaise(sig:integer);
  4280. begin
  4281. Kill(GetPid,Sig);
  4282. end;
  4283. {******************************************************************************
  4284. IOCtl and Termios calls
  4285. ******************************************************************************}
  4286. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  4287. begin
  4288. {$ifndef BSD}
  4289. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  4290. {$else}
  4291. TCGETAttr:=IoCtl(Fd,TIOCGETA,@tios);
  4292. {$endif}
  4293. end;
  4294. Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
  4295. var
  4296. nr:longint;
  4297. begin
  4298. {$ifndef BSD}
  4299. case OptAct of
  4300. TCSANOW : nr:=TCSETS;
  4301. TCSADRAIN : nr:=TCSETSW;
  4302. TCSAFLUSH : nr:=TCSETSF;
  4303. {$else}
  4304. case OptAct of
  4305. TCSANOW : nr:=TIOCSETA;
  4306. TCSADRAIN : nr:=TIOCSETAW;
  4307. TCSAFLUSH : nr:=TIOCSETAF;
  4308. {$endif}
  4309. else
  4310. begin
  4311. ErrNo:=Sys_EINVAL;
  4312. TCSetAttr:=false;
  4313. exit;
  4314. end;
  4315. end;
  4316. TCSetAttr:=IOCtl(fd,nr,@Tios);
  4317. end;
  4318. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  4319. begin
  4320. {$ifndef BSD}
  4321. tios.c_cflag:=Cardinal(tios.c_cflag and cardinal(not CBAUD)) or speed;
  4322. {$else}
  4323. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  4324. {$endif}
  4325. end;
  4326. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  4327. begin
  4328. {$ifndef BSD}
  4329. CFSetISpeed(tios,speed);
  4330. {$else}
  4331. tios.c_ospeed:=speed;
  4332. {$endif}
  4333. end;
  4334. Procedure CFMakeRaw(var tios:TermIOS);
  4335. begin
  4336. {$ifndef BSD}
  4337. with tios do
  4338. begin
  4339. c_iflag:=c_iflag and cardinal(not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  4340. INLCR or IGNCR or ICRNL or IXON));
  4341. c_oflag:=c_oflag and cardinal(not OPOST);
  4342. c_lflag:=c_lflag and cardinal(not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  4343. c_cflag:=(c_cflag and cardinal(not (CSIZE or PARENB))) or CS8;
  4344. end;
  4345. {$else}
  4346. with tios do
  4347. begin
  4348. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  4349. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  4350. IGNPAR));
  4351. c_iflag:=c_iflag OR IGNBRK;
  4352. c_oflag:=c_oflag and (not OPOST);
  4353. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  4354. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  4355. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  4356. c_cc[VMIN]:=1;
  4357. c_cc[VTIME]:=0;
  4358. end;
  4359. {$endif}
  4360. end;
  4361. Function TCSendBreak(fd,duration:longint):boolean;
  4362. begin
  4363. {$ifndef BSD}
  4364. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  4365. {$else}
  4366. TCSendBreak:=IOCtl(fd,TIOCSBRK,0);
  4367. {$endif}
  4368. end;
  4369. Function TCSetPGrp(fd,id:longint):boolean;
  4370. begin
  4371. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  4372. end;
  4373. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  4374. begin
  4375. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  4376. end;
  4377. Function TCDrain(fd:longint):boolean;
  4378. begin
  4379. {$ifndef BSD}
  4380. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  4381. {$else}
  4382. TCDrain:=IOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
  4383. {$endif}
  4384. end;
  4385. Function TCFlow(fd,act:longint):boolean;
  4386. begin
  4387. {$ifndef BSD}
  4388. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  4389. {$else}
  4390. case act OF
  4391. TCOOFF : TCFlow:=Ioctl(fd,TIOCSTOP,0);
  4392. TCOOn : TCFlow:=IOctl(Fd,TIOCStart,0);
  4393. TCIOFF : {N/I}
  4394. end;
  4395. {$endif}
  4396. end;
  4397. Function TCFlush(fd,qsel:longint):boolean;
  4398. begin
  4399. {$ifndef BSD}
  4400. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  4401. {$else}
  4402. TCFlush:=IOCtl(fd,TIOCFLUSH,pointer(qsel));
  4403. {$endif}
  4404. end;
  4405. Function IsATTY(Handle:Longint):Boolean;
  4406. {
  4407. Check if the filehandle described by 'handle' is a TTY (Terminal)
  4408. }
  4409. var
  4410. t : Termios;
  4411. begin
  4412. IsAtty:=TCGetAttr(Handle,t);
  4413. end;
  4414. Function IsATTY(var f: text):Boolean;
  4415. {
  4416. Idem as previous, only now for text variables.
  4417. }
  4418. begin
  4419. IsATTY:=IsaTTY(textrec(f).handle);
  4420. end;
  4421. function TTYName(Handle:Longint):string;
  4422. {
  4423. Return the name of the current tty described by handle f.
  4424. returns empty string in case of an error.
  4425. }
  4426. {$ifdef BSD}
  4427. var
  4428. mydev,
  4429. myino : cardinal;
  4430. {$else not BSD}
  4431. var
  4432. mydev,
  4433. myino : longint;
  4434. {$endif not BSD}
  4435. st : stat;
  4436. function mysearch(n:string): boolean;
  4437. {searches recursively for the device in the directory given by n,
  4438. returns true if found and sets the name of the device in ttyname}
  4439. var dirstream : pdir;
  4440. d : pdirent;
  4441. name : string;
  4442. st : stat;
  4443. begin
  4444. dirstream:=opendir(n);
  4445. if (linuxerror<>0) then
  4446. exit;
  4447. d:=Readdir(dirstream);
  4448. while (d<>nil) do
  4449. begin
  4450. name:=n+'/'+strpas(@(d^.name));
  4451. fstat(name,st);
  4452. if linuxerror=0 then
  4453. begin
  4454. if ((st.mode and $E000)=$4000) and { if it is a directory }
  4455. (strpas(@(d^.name))<>'.') and { but not ., .. and fd subdirs }
  4456. (strpas(@(d^.name))<>'..') and
  4457. (strpas(@(d^.name))<>'') and
  4458. (strpas(@(d^.name))<>'fd') then
  4459. begin {we found a directory, search inside it}
  4460. if mysearch(name) then
  4461. begin {the device is here}
  4462. closedir(dirstream); {then don't continue searching}
  4463. mysearch:=true;
  4464. exit;
  4465. end;
  4466. end
  4467. else if (d^.ino=myino) and (st.dev=mydev) then
  4468. begin
  4469. closedir(dirstream);
  4470. ttyname:=name;
  4471. mysearch:=true;
  4472. exit;
  4473. end;
  4474. end;
  4475. d:=Readdir(dirstream);
  4476. end;
  4477. closedir(dirstream);
  4478. mysearch:=false;
  4479. end;
  4480. begin
  4481. TTYName:='';
  4482. fstat(handle,st);
  4483. if (errno<>0) and isatty (handle) then
  4484. exit;
  4485. mydev:=st.dev;
  4486. myino:=st.ino;
  4487. mysearch('/dev');
  4488. end;
  4489. function TTYName(var F:Text):string;
  4490. {
  4491. Idem as previous, only now for text variables;
  4492. }
  4493. begin
  4494. TTYName:=TTYName(textrec(f).handle);
  4495. end;
  4496. {******************************************************************************
  4497. Utility calls
  4498. ******************************************************************************}
  4499. Function Octal(l:longint):longint;
  4500. {
  4501. Convert an octal specified number to decimal;
  4502. }
  4503. var
  4504. octnr,
  4505. oct : longint;
  4506. begin
  4507. octnr:=0;
  4508. oct:=0;
  4509. while (l>0) do
  4510. begin
  4511. oct:=oct or ((l mod 10) shl octnr);
  4512. l:=l div 10;
  4513. inc(octnr,3);
  4514. end;
  4515. Octal:=oct;
  4516. end;
  4517. Function StringToPPChar(S: PChar):ppchar;
  4518. var
  4519. nr : longint;
  4520. Buf : ^char;
  4521. p : ppchar;
  4522. begin
  4523. buf:=s;
  4524. nr:=0;
  4525. while(buf^<>#0) do
  4526. begin
  4527. while (buf^ in [' ',#9,#10]) do
  4528. inc(buf);
  4529. inc(nr);
  4530. while not (buf^ in [' ',#0,#9,#10]) do
  4531. inc(buf);
  4532. end;
  4533. getmem(p,(nr+1)*4);
  4534. StringToPPChar:=p;
  4535. if p=nil then
  4536. begin
  4537. LinuxError:=sys_enomem;
  4538. exit;
  4539. end;
  4540. buf:=s;
  4541. while (buf^<>#0) do
  4542. begin
  4543. while (buf^ in [' ',#9,#10]) do
  4544. begin
  4545. buf^:=#0;
  4546. inc(buf);
  4547. end;
  4548. p^:=buf;
  4549. inc(p);
  4550. p^:=nil;
  4551. while not (buf^ in [' ',#0,#9,#10]) do
  4552. inc(buf);
  4553. end;
  4554. end;
  4555. Function StringToPPChar(Var S:String):ppchar;
  4556. {
  4557. Create a PPChar to structure of pchars which are the arguments specified
  4558. in the string S. Especially usefull for creating an ArgV for Exec-calls
  4559. Note that the string S is destroyed by this call.
  4560. }
  4561. begin
  4562. S:=S+#0;
  4563. StringToPPChar:=StringToPPChar(@S[1]);
  4564. end;
  4565. Function StringToPPChar(Var S:AnsiString):ppchar;
  4566. {
  4567. Create a PPChar to structure of pchars which are the arguments specified
  4568. in the string S. Especially usefull for creating an ArgV for Exec-calls
  4569. }
  4570. begin
  4571. StringToPPChar:=StringToPPChar(PChar(S));
  4572. end;
  4573. {
  4574. function FExpand (const Path: PathStr): PathStr;
  4575. - declared in fexpand.inc
  4576. }
  4577. {$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
  4578. {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
  4579. const
  4580. LFNSupport = true;
  4581. FileNameCaseSensitive = true;
  4582. {$I fexpand.inc}
  4583. {$UNDEF FPC_FEXPAND_GETENVPCHAR}
  4584. {$UNDEF FPC_FEXPAND_TILDE}
  4585. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  4586. {
  4587. Searches for a file 'path' in the list of direcories in 'dirlist'.
  4588. returns an empty string if not found. Wildcards are NOT allowed.
  4589. If dirlist is empty, it is set to '.'
  4590. }
  4591. Var
  4592. NewDir : PathStr;
  4593. p1 : Longint;
  4594. Info : Stat;
  4595. Begin
  4596. {Replace ':' with ';'}
  4597. for p1:=1to length(dirlist) do
  4598. if dirlist[p1]=':' then
  4599. dirlist[p1]:=';';
  4600. {Check for WildCards}
  4601. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  4602. FSearch:='' {No wildcards allowed in these things.}
  4603. Else
  4604. Begin
  4605. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  4606. Repeat
  4607. p1:=Pos(';',DirList);
  4608. If p1=0 Then
  4609. p1:=255;
  4610. NewDir:=Copy(DirList,1,P1 - 1);
  4611. if NewDir[Length(NewDir)]<>'/' then
  4612. NewDir:=NewDir+'/';
  4613. NewDir:=NewDir+Path;
  4614. Delete(DirList,1,p1);
  4615. if FStat(NewDir,Info) then
  4616. Begin
  4617. If Pos('./',NewDir)=1 Then
  4618. Delete(NewDir,1,2);
  4619. {DOS strips off an initial .\}
  4620. End
  4621. Else
  4622. NewDir:='';
  4623. Until (DirList='') or (Length(NewDir) > 0);
  4624. FSearch:=NewDir;
  4625. End;
  4626. End;
  4627. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  4628. Var
  4629. DotPos,SlashPos,i : longint;
  4630. Begin
  4631. SlashPos:=0;
  4632. DotPos:=256;
  4633. i:=Length(Path);
  4634. While (i>0) and (SlashPos=0) Do
  4635. Begin
  4636. If (DotPos=256) and (Path[i]='.') Then
  4637. begin
  4638. DotPos:=i;
  4639. end;
  4640. If (Path[i]='/') Then
  4641. SlashPos:=i;
  4642. Dec(i);
  4643. End;
  4644. Ext:=Copy(Path,DotPos,255);
  4645. Dir:=Copy(Path,1,SlashPos);
  4646. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  4647. End;
  4648. Function Dirname(Const path:pathstr):pathstr;
  4649. {
  4650. This function returns the directory part of a complete path.
  4651. Unless the directory is root '/', The last character is not
  4652. a slash.
  4653. }
  4654. var
  4655. Dir : PathStr;
  4656. Name : NameStr;
  4657. Ext : ExtStr;
  4658. begin
  4659. FSplit(Path,Dir,Name,Ext);
  4660. if length(Dir)>1 then
  4661. Delete(Dir,length(Dir),1);
  4662. DirName:=Dir;
  4663. end;
  4664. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  4665. {
  4666. This function returns the filename part of a complete path. If suf is
  4667. supplied, it is cut off the filename.
  4668. }
  4669. var
  4670. Dir : PathStr;
  4671. Name : NameStr;
  4672. Ext : ExtStr;
  4673. begin
  4674. FSplit(Path,Dir,Name,Ext);
  4675. if Suf<>Ext then
  4676. Name:=Name+Ext;
  4677. BaseName:=Name;
  4678. end;
  4679. Function FNMatch(const Pattern,Name:string):Boolean;
  4680. Var
  4681. LenPat,LenName : longint;
  4682. Function DoFNMatch(i,j:longint):Boolean;
  4683. Var
  4684. Found : boolean;
  4685. Begin
  4686. Found:=true;
  4687. While Found and (i<=LenPat) Do
  4688. Begin
  4689. Case Pattern[i] of
  4690. '?' : Found:=(j<=LenName);
  4691. '*' : Begin
  4692. {find the next character in pattern, different of ? and *}
  4693. while Found and (i<LenPat) do
  4694. begin
  4695. inc(i);
  4696. case Pattern[i] of
  4697. '*' : ;
  4698. '?' : begin
  4699. inc(j);
  4700. Found:=(j<=LenName);
  4701. end;
  4702. else
  4703. Found:=false;
  4704. end;
  4705. end;
  4706. {Now, find in name the character which i points to, if the * or ?
  4707. wasn't the last character in the pattern, else, use up all the
  4708. chars in name}
  4709. Found:=true;
  4710. if (i<=LenPat) then
  4711. begin
  4712. repeat
  4713. {find a letter (not only first !) which maches pattern[i]}
  4714. while (j<=LenName) and (name[j]<>pattern[i]) do
  4715. inc (j);
  4716. if (j<LenName) then
  4717. begin
  4718. if DoFnMatch(i+1,j+1) then
  4719. begin
  4720. i:=LenPat;
  4721. j:=LenName;{we can stop}
  4722. Found:=true;
  4723. end
  4724. else
  4725. inc(j);{We didn't find one, need to look further}
  4726. end;
  4727. until (j>=LenName);
  4728. end
  4729. else
  4730. j:=LenName;{we can stop}
  4731. end;
  4732. else {not a wildcard character in pattern}
  4733. Found:=(j<=LenName) and (pattern[i]=name[j]);
  4734. end;
  4735. inc(i);
  4736. inc(j);
  4737. end;
  4738. DoFnMatch:=Found and (j>LenName);
  4739. end;
  4740. Begin {start FNMatch}
  4741. LenPat:=Length(Pattern);
  4742. LenName:=Length(Name);
  4743. FNMatch:=DoFNMatch(1,1);
  4744. End;
  4745. Procedure Globfree(var p : pglob);
  4746. {
  4747. Release memory occupied by pglob structure, and names in it.
  4748. sets p to nil.
  4749. }
  4750. var
  4751. temp : pglob;
  4752. begin
  4753. while assigned(p) do
  4754. begin
  4755. temp:=p^.next;
  4756. if assigned(p^.name) then
  4757. freemem(p^.name);
  4758. dispose(p);
  4759. p:=temp;
  4760. end;
  4761. end;
  4762. Function Glob(Const path:pathstr):pglob;
  4763. {
  4764. Fills a tglob structure with entries matching path,
  4765. and returns a pointer to it. Returns nil on error,
  4766. linuxerror is set accordingly.
  4767. }
  4768. var
  4769. temp,
  4770. temp2 : string[255];
  4771. thedir : pdir;
  4772. buffer : pdirent;
  4773. root,
  4774. current : pglob;
  4775. begin
  4776. { Get directory }
  4777. temp:=dirname(path);
  4778. if temp='' then
  4779. temp:='.';
  4780. temp:=temp+#0;
  4781. thedir:=opendir(@temp[1]);
  4782. if thedir=nil then
  4783. begin
  4784. glob:=nil;
  4785. linuxerror:=errno;
  4786. exit;
  4787. end;
  4788. temp:=basename(path,''); { get the pattern }
  4789. if thedir^.fd<0 then
  4790. begin
  4791. linuxerror:=errno;
  4792. glob:=nil;
  4793. exit;
  4794. end;
  4795. {get the entries}
  4796. root:=nil;
  4797. current:=nil;
  4798. repeat
  4799. buffer:=Sys_readdir(thedir);
  4800. if buffer=nil then
  4801. break;
  4802. temp2:=strpas(@(buffer^.name[0]));
  4803. if fnmatch(temp,temp2) then
  4804. begin
  4805. if root=nil then
  4806. begin
  4807. new(root);
  4808. current:=root;
  4809. end
  4810. else
  4811. begin
  4812. new(current^.next);
  4813. current:=current^.next;
  4814. end;
  4815. if current=nil then
  4816. begin
  4817. linuxerror:=Sys_ENOMEM;
  4818. globfree(root);
  4819. break;
  4820. end;
  4821. current^.next:=nil;
  4822. getmem(current^.name,length(temp2)+1);
  4823. if current^.name=nil then
  4824. begin
  4825. linuxerror:=Sys_ENOMEM;
  4826. globfree(root);
  4827. break;
  4828. end;
  4829. move(buffer^.name[0],current^.name^,length(temp2)+1);
  4830. end;
  4831. until false;
  4832. closedir(thedir);
  4833. glob:=root;
  4834. end;
  4835. {--------------------------------
  4836. FiledescriptorSets
  4837. --------------------------------}
  4838. Procedure FD_Zero(var fds:fdSet);
  4839. {
  4840. Clear the set of filedescriptors
  4841. }
  4842. begin
  4843. FillChar(fds,sizeof(fdSet),0);
  4844. end;
  4845. Procedure FD_Clr(fd:longint;var fds:fdSet);
  4846. {
  4847. Remove fd from the set of filedescriptors
  4848. }
  4849. begin
  4850. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  4851. end;
  4852. Procedure FD_Set(fd:longint;var fds:fdSet);
  4853. {
  4854. Add fd to the set of filedescriptors
  4855. }
  4856. begin
  4857. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  4858. end;
  4859. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  4860. {
  4861. Test if fd is part of the set of filedescriptors
  4862. }
  4863. begin
  4864. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  4865. end;
  4866. Function GetFS (var T:Text):longint;
  4867. {
  4868. Get File Descriptor of a text file.
  4869. }
  4870. begin
  4871. if textrec(t).mode=fmclosed then
  4872. exit(-1)
  4873. else
  4874. GETFS:=textrec(t).Handle
  4875. end;
  4876. Function GetFS(Var F:File):longint;
  4877. {
  4878. Get File Descriptor of an unTyped file.
  4879. }
  4880. begin
  4881. { Handle and mode are on the same place in textrec and filerec. }
  4882. if filerec(f).mode=fmclosed then
  4883. exit(-1)
  4884. else
  4885. GETFS:=filerec(f).Handle
  4886. end;
  4887. {--------------------------------
  4888. Stat.Mode Macro's
  4889. --------------------------------}
  4890. Function S_ISLNK(m:word):boolean;
  4891. {
  4892. Check mode field of inode for link.
  4893. }
  4894. begin
  4895. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  4896. end;
  4897. Function S_ISREG(m:word):boolean;
  4898. {
  4899. Check mode field of inode for regular file.
  4900. }
  4901. begin
  4902. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  4903. end;
  4904. Function S_ISDIR(m:word):boolean;
  4905. {
  4906. Check mode field of inode for directory.
  4907. }
  4908. begin
  4909. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  4910. end;
  4911. Function S_ISCHR(m:word):boolean;
  4912. {
  4913. Check mode field of inode for character device.
  4914. }
  4915. begin
  4916. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  4917. end;
  4918. Function S_ISBLK(m:word):boolean;
  4919. {
  4920. Check mode field of inode for block device.
  4921. }
  4922. begin
  4923. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  4924. end;
  4925. Function S_ISFIFO(m:word):boolean;
  4926. {
  4927. Check mode field of inode for named pipe (FIFO).
  4928. }
  4929. begin
  4930. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  4931. end;
  4932. Function S_ISSOCK(m:word):boolean;
  4933. {
  4934. Check mode field of inode for socket.
  4935. }
  4936. begin
  4937. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  4938. end;
  4939. Procedure WritePort (Port : Longint; Value : Byte);
  4940. {
  4941. Writes 'Value' to port 'Port'
  4942. }
  4943. begin
  4944. asm
  4945. movl port,%edx
  4946. movb value,%al
  4947. outb %al,%dx
  4948. end ['EAX','EDX'];
  4949. end;
  4950. Procedure WritePort (Port : Longint; Value : Word);
  4951. {
  4952. Writes 'Value' to port 'Port'
  4953. }
  4954. begin
  4955. asm
  4956. movl port,%edx
  4957. movw value,%ax
  4958. outw %ax,%dx
  4959. end ['EAX','EDX'];
  4960. end;
  4961. Procedure WritePort (Port : Longint; Value : Longint);
  4962. {
  4963. Writes 'Value' to port 'Port'
  4964. }
  4965. begin
  4966. asm
  4967. movl port,%edx
  4968. movl value,%eax
  4969. outl %eax,%dx
  4970. end ['EAX','EDX'];
  4971. end;
  4972. Procedure WritePortB (Port : Longint; Value : Byte);
  4973. {
  4974. Writes 'Value' to port 'Port'
  4975. }
  4976. begin
  4977. asm
  4978. movl port,%edx
  4979. movb value,%al
  4980. outb %al,%dx
  4981. end ['EAX','EDX'];
  4982. end;
  4983. Procedure WritePortW (Port : Longint; Value : Word);
  4984. {
  4985. Writes 'Value' to port 'Port'
  4986. }
  4987. begin
  4988. asm
  4989. movl port,%edx
  4990. movw value,%ax
  4991. outw %ax,%dx
  4992. end ['EAX','EDX'];
  4993. end;
  4994. Procedure WritePortL (Port : Longint; Value : Longint);
  4995. {
  4996. Writes 'Value' to port 'Port'
  4997. }
  4998. begin
  4999. asm
  5000. movl port,%edx
  5001. movl value,%eax
  5002. outl %eax,%dx
  5003. end ['EAX','EDX'];
  5004. end;
  5005. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);
  5006. {
  5007. Writes 'Count' longints from 'Buf' to Port
  5008. }
  5009. begin
  5010. asm
  5011. movl count,%ecx
  5012. movl buf,%esi
  5013. movl port,%edx
  5014. cld
  5015. rep
  5016. outsl
  5017. end ['ECX','ESI','EDX'];
  5018. end;
  5019. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);
  5020. {
  5021. Writes 'Count' words from 'Buf' to Port
  5022. }
  5023. begin
  5024. asm
  5025. movl count,%ecx
  5026. movl buf,%esi
  5027. movl port,%edx
  5028. cld
  5029. rep
  5030. outsw
  5031. end ['ECX','ESI','EDX'];
  5032. end;
  5033. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);
  5034. {
  5035. Writes 'Count' bytes from 'Buf' to Port
  5036. }
  5037. begin
  5038. asm
  5039. movl count,%ecx
  5040. movl buf,%esi
  5041. movl port,%edx
  5042. cld
  5043. rep
  5044. outsb
  5045. end ['ECX','ESI','EDX'];
  5046. end;
  5047. Procedure ReadPort (Port : Longint; Var Value : Byte);
  5048. {
  5049. Reads 'Value' from port 'Port'
  5050. }
  5051. begin
  5052. asm
  5053. movl port,%edx
  5054. inb %dx,%al
  5055. movl value,%edx
  5056. movb %al,(%edx)
  5057. end ['EAX','EDX'];
  5058. end;
  5059. Procedure ReadPort (Port : Longint; Var Value : Word);
  5060. {
  5061. Reads 'Value' from port 'Port'
  5062. }
  5063. begin
  5064. asm
  5065. movl port,%edx
  5066. inw %dx,%ax
  5067. movl value,%edx
  5068. movw %ax,(%edx)
  5069. end ['EAX','EDX'];
  5070. end;
  5071. Procedure ReadPort (Port : Longint; Var Value : Longint);
  5072. {
  5073. Reads 'Value' from port 'Port'
  5074. }
  5075. begin
  5076. asm
  5077. movl port,%edx
  5078. inl %dx,%eax
  5079. movl value,%edx
  5080. movl %eax,(%edx)
  5081. end ['EAX','EDX'];
  5082. end;
  5083. function ReadPortB (Port : Longint): Byte; assembler;
  5084. {
  5085. Reads a byte from port 'Port'
  5086. }
  5087. asm
  5088. xorl %eax,%eax
  5089. movl port,%edx
  5090. inb %dx,%al
  5091. end ['EAX','EDX'];
  5092. function ReadPortW (Port : Longint): Word; assembler;
  5093. {
  5094. Reads a word from port 'Port'
  5095. }
  5096. asm
  5097. xorl %eax,%eax
  5098. movl port,%edx
  5099. inw %dx,%ax
  5100. end ['EAX','EDX'];
  5101. function ReadPortL (Port : Longint): LongInt; assembler;
  5102. {
  5103. Reads a LongInt from port 'Port'
  5104. }
  5105. asm
  5106. movl port,%edx
  5107. inl %dx,%eax
  5108. end ['EAX','EDX'];
  5109. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);
  5110. {
  5111. Reads 'Count' longints from port 'Port' to 'Buf'.
  5112. }
  5113. begin
  5114. asm
  5115. movl count,%ecx
  5116. movl buf,%edi
  5117. movl port,%edx
  5118. cld
  5119. rep
  5120. insl
  5121. end ['ECX','EDI','EDX'];
  5122. end;
  5123. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);
  5124. {
  5125. Reads 'Count' words from port 'Port' to 'Buf'.
  5126. }
  5127. begin
  5128. asm
  5129. movl count,%ecx
  5130. movl buf,%edi
  5131. movl port,%edx
  5132. cld
  5133. rep
  5134. insw
  5135. end ['ECX','EDI','EDX'];
  5136. end;
  5137. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);
  5138. {
  5139. Reads 'Count' bytes from port 'Port' to 'Buf'.
  5140. }
  5141. begin
  5142. asm
  5143. movl count,%ecx
  5144. movl buf,%edi
  5145. movl port,%edx
  5146. cld
  5147. rep
  5148. insb
  5149. end ['ECX','EDI','EDX'];
  5150. end;
  5151. {--------------------------------
  5152. Memory functions
  5153. --------------------------------}
  5154. Initialization
  5155. InitLocalTime;
  5156. finalization
  5157. DoneLocalTime;
  5158. End.
  5159. {
  5160. $Log$
  5161. Revision 1.10 2003-11-10 16:54:28 marco
  5162. * new oldlinux unit. 1_0 defines killed in some former FCL parts.
  5163. Revision 1.1.2.41 2003/06/18 06:56:51 pierre
  5164. * restore return value of shell function to status parameter
  5165. Revision 1.1.2.40 2003/05/24 20:36:41 jonas
  5166. * fixed DosExitCode translation (at least for linux, and it's the same
  5167. for Darwin, other BSD's should still be checked)
  5168. Revision 1.1.2.39 2003/03/15 15:41:03 marco
  5169. * utime fixes. Has now "const" argument.
  5170. Revision 1.1.2.38 2003/03/11 08:24:46 michael
  5171. * stringtoppchar should use tabs instead of backspace as delimiter
  5172. Revision 1.1.2.37 2002/11/25 19:43:47 marco
  5173. * Hmm, I cycled this?
  5174. Revision 1.1.2.36 2002/11/25 19:38:24 marco
  5175. * quick pipe fix.
  5176. Revision 1.1.2.35 2002/09/20 07:08:41 pierre
  5177. * avoid compiler warnings for bsd
  5178. Revision 1.1.2.34 2002/09/13 13:02:06 jonas
  5179. * fixed buffer overflow error in StringToPPChar(), detected using
  5180. DIOTA (http://www.elis/rug.ac.be/~ronsse/diota) (which I also work on :)
  5181. Revision 1.1.2.33 2002/09/10 09:18:43 pierre
  5182. * added several explicit typecast to remove warnings
  5183. Revision 1.1.2.32 2002/08/06 11:12:26 sg
  5184. * replaced some Longints with Cardinals, to mach the C headers
  5185. * updated the termios record
  5186. Revision 1.1.2.31 2002/07/30 11:33:52 marco
  5187. * Small OpenBSD fix.
  5188. Revision 1.1.2.30 2002/06/10 19:28:49 pierre
  5189. * fix IsATTY declaration
  5190. Revision 1.1.2.29 2002/03/05 20:07:01 michael
  5191. + Patched patch from Sebastian for FCNTL call
  5192. Revision 1.1.2.28 2002/03/05 19:59:42 michael
  5193. + Patch from Sebastian for FCNTL call
  5194. Revision 1.1.2.27 2002/02/19 14:37:54 marco
  5195. * Changes to support Alarm()
  5196. Revision 1.1.2.26 2001/12/31 23:26:45 marco
  5197. * Gettimeofday uncommented for FreeBSD.
  5198. Revision 1.1.2.25 2001/12/15 19:55:33 michael
  5199. + removed debug writelns
  5200. Revision 1.1.2.24 2001/12/13 18:29:49 michael
  5201. + Added ansistring version of most Exec* calls.
  5202. Revision 1.1.2.23 2001/11/30 07:20:22 marco
  5203. * TTYName fix from Maarten Beekers.
  5204. Revision 1.1.2.22 2001/11/05 20:52:47 michael
  5205. + Added exit status examination macros
  5206. Revision 1.1.2.21 2001/10/14 13:34:27 peter
  5207. * tcsetattr const argument
  5208. Revision 1.1.2.20 2001/09/10 18:40:04 marco
  5209. * OpenDir(String) now correctly updates linuxerror
  5210. Revision 1.1.2.19 2001/08/12 15:17:46 carl
  5211. * avoid range check error when with timezone info, we get a negative result here
  5212. Revision 1.1.2.18 2001/07/12 12:53:28 marco
  5213. * Small fix to datetime routines for 1.0.x starting compiler
  5214. Revision 1.1.2.17 2001/07/12 07:09:36 michael
  5215. + Corrected setdate/time/datetime implementation
  5216. Revision 1.1.2.16 2001/07/12 07:05:53 michael
  5217. + Added SetDate/time/datetime functions
  5218. Revision 1.1.2.15 2001/07/08 14:02:16 marco
  5219. * Readlink fix
  5220. Revision 1.1.2.14 2001/06/13 22:13:15 hajny
  5221. * universal FExpand merged
  5222. Revision 1.1.2.13 2001/06/02 00:21:06 peter
  5223. * waitprocess fixed to give the correct exitcode back under linux
  5224. Revision 1.1.2.12 2001/03/27 11:45:35 michael
  5225. + Fixed F_[G,S]etOwn constants. By Alexander Sychev
  5226. Revision 1.1.2.11 2001/03/15 16:02:18 marco
  5227. * More NewReaddir fixes. Now compiles
  5228. Revision 1.1.2.10 2001/03/13 10:31:48 marco
  5229. * Small fixes + moving of linsyscall and bsdsyscall
  5230. Revision 1.1.2.9 2001/03/12 20:37:50 marco
  5231. * [Solaris] Now cycles for FreeBSD (wrong version Linux unit commited)
  5232. Revision 1.1.2.8 2001/01/23 06:39:27 marco
  5233. * IOPerm for FreeBSD; I/O routines back to Unix.
  5234. Revision 1.1.2.7 2001/01/01 20:16:14 marco
  5235. * Fdwrite now has a CONST instead of a var parameter
  5236. Revision 1.1.2.6 2000/12/28 20:41:26 peter
  5237. * ttyname fix from the mailinglist
  5238. Revision 1.1.2.5 2000/12/17 13:58:43 peter
  5239. * removed unused var
  5240. Revision 1.1.2.4 2000/11/14 22:08:53 michael
  5241. + Added missing iopl call
  5242. Revision 1.1.2.3 2000/10/25 09:44:54 marco
  5243. * Termios backport
  5244. Revision 1.1.2.2 2000/10/24 12:18:51 pierre
  5245. + NanoSleep function
  5246. Revision 1.1.2.1 2000/09/14 13:38:26 marco
  5247. * Moved from Linux dir. now start of generic unix dir, from which the
  5248. really exotic features should be moved to the target specific dirs.
  5249. Revision 1.1.2.6 2000/09/10 16:12:40 marco
  5250. The rearrangement to linux for
  5251. Revision 1.1.2.5 2000/09/06 20:46:19 peter
  5252. * removed previous fsplit() patch as it's not the correct behaviour for
  5253. LFNs. The code showing the bug could easily be adapted
  5254. Revision 1.1.2.4 2000/09/04 20:15:22 peter
  5255. * fixed previous commit
  5256. Revision 1.1.2.3 2000/09/04 19:36:25 peter
  5257. * fsplit with .. fix from Thomas
  5258. Revision 1.1.2.2 2000/07/30 19:18:49 peter
  5259. * added overloaded selecttext with timeout as longint
  5260. Revision 1.1.2.1 2000/07/20 16:50:49 michael
  5261. + Fixed waitpid. Thanks to Rob Bugel
  5262. Revision 1.1 2000/07/13 06:30:54 michael
  5263. + Initial import
  5264. Revision 1.72 2000/05/26 18:21:04 peter
  5265. * fixed @ with var parameters
  5266. Revision 1.71 2000/05/25 19:59:57 michael
  5267. + Added munmap call
  5268. Revision 1.70 2000/05/21 17:10:13 michael
  5269. + AssignStream now always returns PID of spawned process
  5270. Revision 1.69 2000/05/17 17:11:44 peter
  5271. * added sigaction record from signal.inc
  5272. Revision 1.68 2000/04/16 16:09:32 marco
  5273. * Some small mistakes when merging BSD and Linux version fixed
  5274. Revision 1.67 2000/04/14 16:07:06 marco
  5275. * Splitted linux into linux.pp and linsysca.inc, and merged BSD diffs
  5276. into header
  5277. Revision 1.66 2000/03/27 13:25:48 jonas
  5278. * fixed readport* functions (thanks Florian ;)
  5279. Revision 1.65 2000/03/23 17:10:32 jonas
  5280. * fixes for port reading
  5281. Revision 1.64 2000/03/17 13:27:00 sg
  5282. * Added WritePort[B|W|L] for single data access
  5283. * Added ReadPort[B|W|L] functions
  5284. Revision 1.63 2000/02/23 17:19:06 peter
  5285. + readded getepochtime which simply calls gettimeofday
  5286. Revision 1.62 2000/02/09 23:09:13 peter
  5287. * rewrote glob to be much simpler and cleaner, the old code did
  5288. strange complex things with pointers which was unnecessary
  5289. Revision 1.61 2000/02/09 16:59:31 peter
  5290. * truncated log
  5291. Revision 1.60 2000/02/08 12:05:58 peter
  5292. + readlink
  5293. Revision 1.59 2000/01/07 16:41:40 daniel
  5294. * copyright 2000
  5295. Revision 1.58 2000/01/07 16:32:26 daniel
  5296. * copyright 2000 added
  5297. Revision 1.57 2000/01/04 12:56:09 jonas
  5298. * fixed modified registers for port routines
  5299. Revision 1.56 1999/12/28 09:38:07 sg
  5300. * the long version of AssignStream now sets the result value to -1 in
  5301. _all_ cases when it would fail.
  5302. Revision 1.55 1999/12/08 01:03:54 peter
  5303. * overloaded gettime functions supporting hsec and msec,usec
  5304. Revision 1.54 1999/12/01 22:46:59 peter
  5305. + timezone support
  5306. Revision 1.53 1999/11/14 21:35:04 peter
  5307. * removed warnings
  5308. Revision 1.52 1999/11/14 11:11:15 michael
  5309. + Added Pause() and alarm()
  5310. Revision 1.51 1999/11/11 19:43:49 sg
  5311. * fixed severe bug: change by ? in dup2 (flushing) resulted in broken
  5312. AssignStream functions
  5313. Revision 1.50 1999/11/06 14:39:12 peter
  5314. * truncated log
  5315. Revision 1.49 1999/10/28 09:48:31 peter
  5316. + mmap
  5317. Revision 1.48 1999/10/22 10:37:44 peter
  5318. * fixed sigset
  5319. Revision 1.47 1999/10/06 17:43:58 peter
  5320. * freemem with wrong size (found with the new heapmanager)
  5321. Revision 1.46 1999/09/08 16:14:41 peter
  5322. * pointer fixes
  5323. Revision 1.45 1999/08/11 22:02:25 peter
  5324. * removed old integer versions of localtoepoch and epochtolocal, you
  5325. need to use the word versions instead else you got an overloaded bug
  5326. Revision 1.44 1999/07/31 23:55:04 michael
  5327. + FCNTL patch from Sebastian Guenther
  5328. Revision 1.43 1999/07/29 16:33:24 michael
  5329. + Yet more Fixes to assignstream with rerouting of stderr
  5330. Revision 1.42 1999/07/29 15:55:54 michael
  5331. + Fixes to assignstream with rerouting of stderr, by Sebastian Guenther
  5332. Revision 1.41 1999/07/29 15:53:55 michael
  5333. + Added assignstream with rerouting of stderr, by Sebastian Guenther
  5334. }