oldlinux.pp 140 KB

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