linuxold.inc 143 KB

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