oldlinux.pp 139 KB

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