2
0

oldlinux.pp 139 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918
  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. regs.reg2:=longint(filename);
  1741. regs.reg3:=mode;
  1742. Sys_MkDir:=SysCall(SysCall_nr_mkdir,regs);
  1743. end;
  1744. Function Sys_Rmdir(Filename:pchar):longint;
  1745. var
  1746. regs : SysCallregs;
  1747. begin
  1748. regs.reg2:=longint(filename);
  1749. Sys_Rmdir:=SysCall(SysCall_nr_rmdir,regs);
  1750. end;
  1751. { we need this for getcwd }
  1752. Function OpenDir(f:pchar):pdir;
  1753. var
  1754. fd:integer;
  1755. st:stat;
  1756. ptr:pdir;
  1757. begin
  1758. opendir:=nil;
  1759. if sys_stat(f,st)<0 then
  1760. exit;
  1761. { Is it a dir ? }
  1762. if not((st.mode and $f000)=$4000)then
  1763. begin
  1764. errno:=sys_enotdir;
  1765. exit
  1766. end;
  1767. { Open it}
  1768. fd:=sys_open(f,OPEN_RDONLY,438);
  1769. if fd<0 then
  1770. exit;
  1771. new(ptr);
  1772. if ptr=nil then
  1773. exit;
  1774. new(ptr^.buf);
  1775. if ptr^.buf=nil then
  1776. exit;
  1777. ptr^.fd:=fd;
  1778. ptr^.loc:=0;
  1779. ptr^.size:=0;
  1780. ptr^.dd_max:=sizeof(ptr^.buf^);
  1781. opendir:=ptr;
  1782. end;
  1783. function CloseDir(p:pdir):integer;
  1784. begin
  1785. closedir:=sys_close(p^.fd);
  1786. dispose(p^.buf);
  1787. dispose(p);
  1788. end;
  1789. Function Sys_ReadDir(p:pdir):pdirent;
  1790. var
  1791. regs :SysCallregs;
  1792. dummy:longint;
  1793. begin
  1794. regs.reg3:=longint(p^.buf);
  1795. regs.reg2:=p^.fd;
  1796. regs.reg4:=1;
  1797. dummy:=SysCall(SysCall_nr_readdir,regs);
  1798. { the readdir system call returns the number of bytes written }
  1799. if dummy=0 then
  1800. sys_readdir:=nil
  1801. else
  1802. sys_readdir:=p^.buf
  1803. end;
  1804. {*****************************************************************************
  1805. --- Process:Process & program handling - related calls ---
  1806. *****************************************************************************}
  1807. Function Sys_GetPid:LongInt;
  1808. var
  1809. regs : SysCallregs;
  1810. begin
  1811. Sys_GetPid:=SysCall(SysCall_nr_getpid,regs);
  1812. end;
  1813. Procedure Sys_Exit(ExitCode:Integer);
  1814. var
  1815. regs : SysCallregs;
  1816. begin
  1817. regs.reg2:=exitcode;
  1818. SysCall(SysCall_nr_exit,regs)
  1819. end;
  1820. Procedure SigAction(Signum:longint;Act,OldAct:PSigActionRec );
  1821. {
  1822. Change action of process upon receipt of a signal.
  1823. Signum specifies the signal (all except SigKill and SigStop).
  1824. If Act is non-nil, it is used to specify the new action.
  1825. If OldAct is non-nil the previous action is saved there.
  1826. }
  1827. Var
  1828. sr : Syscallregs;
  1829. begin
  1830. sr.reg2:=Signum;
  1831. sr.reg3:=Longint(act);
  1832. sr.reg4:=Longint(oldact);
  1833. SysCall(Syscall_nr_sigaction,sr);
  1834. end;
  1835. function Sys_FTruncate(Handle,Pos:longint):longint; //moved from sysunix.inc Do_Truncate
  1836. var
  1837. sr : syscallregs;
  1838. begin
  1839. sr.reg2:=Handle;
  1840. sr.reg3:=Pos;
  1841. Sys_FTruncate:=syscall(syscall_nr_ftruncate,sr);
  1842. end;
  1843. Function Sys_mmap(adr,len,prot,flags,fdes,off:longint):longint; // moved from sysunix.inc, used in sbrk
  1844. type
  1845. tmmapargs=packed record
  1846. address : longint;
  1847. size : longint;
  1848. prot : longint;
  1849. flags : longint;
  1850. fd : longint;
  1851. offset : longint;
  1852. end;
  1853. var
  1854. t : syscallregs;
  1855. mmapargs : tmmapargs;
  1856. begin
  1857. mmapargs.address:=adr;
  1858. mmapargs.size:=len;
  1859. mmapargs.prot:=prot;
  1860. mmapargs.flags:=flags;
  1861. mmapargs.fd:=fdes;
  1862. mmapargs.offset:=off;
  1863. t.reg2:=longint(@mmapargs);
  1864. do_syscall(syscall_nr_mmap,t);
  1865. Sys_mmap:=t.reg1;
  1866. if t.reg1=-1 then
  1867. errno:=-1;
  1868. end;
  1869. {
  1870. Interface to Unix ioctl call.
  1871. Performs various operations on the filedescriptor Handle.
  1872. Ndx describes the operation to perform.
  1873. Data points to data needed for the Ndx function. The structure of this
  1874. data is function-dependent.
  1875. }
  1876. Function Sys_IOCtl(Handle,Ndx: Longint;Data: Pointer):LongInt; // This was missing here, instead hardcode in Do_IsDevice
  1877. var
  1878. sr: SysCallRegs;
  1879. begin
  1880. sr.reg2:=Handle;
  1881. sr.reg3:=Ndx;
  1882. sr.reg4:=Longint(Data);
  1883. Sys_IOCtl:=SysCall(Syscall_nr_ioctl,sr);
  1884. end;
  1885. Function Sys_SigAltStack(ss, oss :psigaltstack):longint;
  1886. var
  1887. regs : SysCallregs;
  1888. begin
  1889. regs.reg2:=longint(ss);
  1890. regs.reg3:=longint(oss);
  1891. sys_sigaltstack:=SysCall(syscall_nr_sigaltstack,regs);
  1892. end;
  1893. Function Fork:longint;
  1894. {
  1895. This function issues the 'fork' System call. the program is duplicated in memory
  1896. and Execution continues in parent and child process.
  1897. In the parent process, fork returns the PID of the child. In the child process,
  1898. zero is returned.
  1899. A negative value indicates that an error has occurred, the error is returned in
  1900. LinuxError.
  1901. }
  1902. var
  1903. regs:SysCallregs;
  1904. begin
  1905. Fork:=SysCall(SysCall_nr_fork,regs);
  1906. LinuxError:=Errno;
  1907. End;
  1908. function clone(func:TCloneFunc;sp:pointer;flags:longint;args:pointer):longint;
  1909. begin
  1910. if (pointer(func)=nil) or (sp=nil) then
  1911. begin
  1912. LinuxError:=Sys_EInval;
  1913. exit(-1); // give an error result
  1914. end;
  1915. {$ifdef cpui386}
  1916. {$ASMMODE ATT}
  1917. asm
  1918. { Insert the argument onto the new stack. }
  1919. movl sp,%ecx
  1920. subl $8,%ecx
  1921. movl args,%eax
  1922. movl %eax,4(%ecx)
  1923. { Save the function pointer as the zeroth argument.
  1924. It will be popped off in the child in the ebx frobbing below. }
  1925. movl func,%eax
  1926. movl %eax,0(%ecx)
  1927. { Do the system call }
  1928. pushl %ebx
  1929. movl flags,%ebx
  1930. movl SysCall_nr_clone,%eax
  1931. int $0x80
  1932. popl %ebx
  1933. test %eax,%eax
  1934. jnz .Lclone_end
  1935. { We're in the new thread }
  1936. subl %ebp,%ebp { terminate the stack frame }
  1937. call *%ebx
  1938. { exit process }
  1939. movl %eax,%ebx
  1940. movl $1,%eax
  1941. int $0x80
  1942. .Lclone_end:
  1943. movl %eax,__RESULT
  1944. end;
  1945. {$endif cpui386}
  1946. {$ifdef cpum68k}
  1947. { No yet translated, my m68k assembler is too weak for such things PM }
  1948. (*
  1949. asm
  1950. { Insert the argument onto the new stack. }
  1951. movl sp,%ecx
  1952. subl $8,%ecx
  1953. movl args,%eax
  1954. movl %eax,4(%ecx)
  1955. { Save the function pointer as the zeroth argument.
  1956. It will be popped off in the child in the ebx frobbing below. }
  1957. movl func,%eax
  1958. movl %eax,0(%ecx)
  1959. { Do the system call }
  1960. pushl %ebx
  1961. movl flags,%ebx
  1962. movl SysCall_nr_clone,%eax
  1963. int $0x80
  1964. popl %ebx
  1965. test %eax,%eax
  1966. jnz .Lclone_end
  1967. { We're in the new thread }
  1968. subl %ebp,%ebp { terminate the stack frame }
  1969. call *%ebx
  1970. { exit process }
  1971. movl %eax,%ebx
  1972. movl $1,%eax
  1973. int $0x80
  1974. .Lclone_end:
  1975. movl %eax,__RESULT
  1976. end;
  1977. *)
  1978. {$endif cpum68k}
  1979. end;
  1980. Procedure Execve(path:pathstr;args:ppchar;ep:ppchar);
  1981. {
  1982. Replaces the current program by the program specified in path,
  1983. arguments in args are passed to Execve.
  1984. environment specified in ep is passed on.
  1985. }
  1986. var
  1987. regs:SysCallregs;
  1988. begin
  1989. path:=path+#0;
  1990. regs.reg2:=longint(@path[1]);
  1991. regs.reg3:=longint(args);
  1992. regs.reg4:=longint(ep);
  1993. SysCall(SysCall_nr_Execve,regs);
  1994. { This only gets set when the call fails, otherwise we don't get here ! }
  1995. Linuxerror:=errno;
  1996. end;
  1997. Procedure Execve(path:pchar;args:ppchar;ep:ppchar);
  1998. {
  1999. Replaces the current program by the program specified in path,
  2000. arguments in args are passed to Execve.
  2001. environment specified in ep is passed on.
  2002. }
  2003. var
  2004. regs:SysCallregs;
  2005. begin
  2006. regs.reg2:=longint(path);
  2007. regs.reg3:=longint(args);
  2008. regs.reg4:=longint(ep);
  2009. SysCall(SysCall_nr_Execve,regs);
  2010. { This only gets set when the call fails, otherwise we don't get here ! }
  2011. Linuxerror:=errno;
  2012. end;
  2013. Procedure ExitProcess(val:longint);
  2014. var
  2015. regs : SysCallregs;
  2016. begin
  2017. regs.reg2:=val;
  2018. SysCall(SysCall_nr_exit,regs);
  2019. end;
  2020. Function WaitPid(Pid:longint;Status:pointer;Options:Longint):Longint;
  2021. {
  2022. Waits until a child with PID Pid exits, or returns if it is exited already.
  2023. Any resources used by the child are freed.
  2024. The exit status is reported in the adress referred to by Status. It should
  2025. be a longint.
  2026. }
  2027. var
  2028. regs : SysCallregs;
  2029. begin
  2030. regs.reg2:=pid;
  2031. regs.reg3:=longint(status);
  2032. regs.reg4:=options;
  2033. WaitPid:=SysCall(SysCall_nr_waitpid,regs);
  2034. LinuxError:=errno;
  2035. end;
  2036. Procedure GetTimeOfDay(var tv:timeval);
  2037. {
  2038. Get the number of seconds since 00:00, January 1 1970, GMT
  2039. the time NOT corrected any way
  2040. }
  2041. var
  2042. regs : SysCallregs;
  2043. begin
  2044. regs.reg2:=longint(@tv);
  2045. regs.reg3:=0;
  2046. SysCall(SysCall_nr_gettimeofday,regs);
  2047. LinuxError:=Errno;
  2048. end;
  2049. Function GetPriority(Which,Who:Integer):integer;
  2050. {
  2051. Get Priority of process, process group, or user.
  2052. Which : selects what kind of priority is used.
  2053. can be one of the following predefined Constants :
  2054. Prio_User.
  2055. Prio_PGrp.
  2056. Prio_Process.
  2057. Who : depending on which, this is , respectively :
  2058. Uid
  2059. Pid
  2060. Process Group id
  2061. Errors are reported in linuxerror _only_. (priority can be negative)
  2062. }
  2063. var
  2064. sr : Syscallregs;
  2065. begin
  2066. errno:=0;
  2067. if (which<prio_process) or (which>prio_user) then
  2068. begin
  2069. { We can save an interrupt here }
  2070. getpriority:=0;
  2071. linuxerror:=Sys_einval;
  2072. end
  2073. else
  2074. begin
  2075. sr.reg2:=which;
  2076. sr.reg3:=who;
  2077. getpriority:=SysCall(Syscall_nr_getpriority,sr);
  2078. linuxerror:=errno;
  2079. end;
  2080. end;
  2081. Procedure SetPriority(Which:Integer;Who:Integer;What:Integer);
  2082. {
  2083. Set Priority of process, process group, or user.
  2084. Which : selects what kind of priority is used.
  2085. can be one of the following predefined Constants :
  2086. Prio_User.
  2087. Prio_PGrp.
  2088. Prio_Process.
  2089. Who : depending on value of which, this is, respectively :
  2090. Uid
  2091. Pid
  2092. Process Group id
  2093. what : A number between -20 and 20. -20 is most favorable, 20 least.
  2094. 0 is the default.
  2095. }
  2096. var
  2097. sr : Syscallregs;
  2098. begin
  2099. errno:=0;
  2100. if ((which<prio_process) or (which>prio_user)) or ((what<-20) or (what>20)) then
  2101. linuxerror:=Sys_einval { We can save an interrupt here }
  2102. else
  2103. begin
  2104. sr.reg2:=which;
  2105. sr.reg3:=who;
  2106. sr.reg4:=what;
  2107. SysCall(Syscall_nr_setpriority,sr);
  2108. linuxerror:=errno;
  2109. end;
  2110. end;
  2111. Procedure Nice(N:integer);
  2112. {
  2113. Set process priority. A positive N means a lower priority.
  2114. A negative N decreases priority.
  2115. }
  2116. var
  2117. sr : Syscallregs;
  2118. begin
  2119. sr.reg2:=n;
  2120. SysCall(Syscall_nr_nice,sr);
  2121. linuxerror:=errno;
  2122. end;
  2123. Function GetPid:LongInt;
  2124. {
  2125. Get Process ID.
  2126. }
  2127. var
  2128. regs : SysCallregs;
  2129. begin
  2130. GetPid:=SysCall(SysCall_nr_getpid,regs);
  2131. linuxerror:=errno;
  2132. end;
  2133. Function GetPPid:LongInt;
  2134. {
  2135. Get Process ID of parent process.
  2136. }
  2137. var
  2138. regs : SysCallregs;
  2139. begin
  2140. GetPpid:=SysCall(SysCall_nr_getppid,regs);
  2141. linuxerror:=errno;
  2142. end;
  2143. Function GetUid:Longint;
  2144. {
  2145. Get User ID.
  2146. }
  2147. var
  2148. regs : SysCallregs;
  2149. begin
  2150. GetUid:=SysCall(SysCall_nr_getuid,regs);
  2151. Linuxerror:=errno;
  2152. end;
  2153. Function GetEUid:Longint;
  2154. {
  2155. Get _effective_ User ID.
  2156. }
  2157. var
  2158. regs : SysCallregs;
  2159. begin
  2160. GetEuid:=SysCall(SysCall_nr_geteuid,regs);
  2161. Linuxerror:=errno;
  2162. end;
  2163. Function GetGid:Longint;
  2164. {
  2165. Get Group ID.
  2166. }
  2167. var
  2168. regs : SysCallregs;
  2169. begin
  2170. Getgid:=SysCall(SysCall_nr_getgid,regs);
  2171. Linuxerror:=errno;
  2172. end;
  2173. Function GetEGid:Longint;
  2174. {
  2175. Get _effective_ Group ID.
  2176. }
  2177. var
  2178. regs : SysCallregs;
  2179. begin
  2180. GetEgid:=SysCall(SysCall_nr_getegid,regs);
  2181. Linuxerror:=errno;
  2182. end;
  2183. Function GetTimeOfDay: longint;
  2184. {
  2185. Get the number of seconds since 00:00, January 1 1970, GMT
  2186. the time NOT corrected any way
  2187. }
  2188. var
  2189. regs : SysCallregs;
  2190. tv : timeval;
  2191. begin
  2192. regs.reg2:=longint(@tv);
  2193. regs.reg3:=0;
  2194. SysCall(SysCall_nr_gettimeofday,regs);
  2195. LinuxError:=Errno;
  2196. GetTimeOfDay:=tv.sec;
  2197. end;
  2198. Function fdTruncate(fd,size:longint):boolean;
  2199. var
  2200. Regs : SysCallRegs;
  2201. begin
  2202. Regs.reg2:=fd;
  2203. Regs.reg3:=size;
  2204. fdTruncate:=(SysCall(Syscall_nr_ftruncate,regs)=0);
  2205. LinuxError:=Errno;
  2206. end;
  2207. Function fdFlush (fd : Longint) : Boolean;
  2208. var
  2209. SR: SysCallRegs;
  2210. begin
  2211. SR.reg2 := fd;
  2212. fdFlush := (SysCall(syscall_nr_fsync, SR)=0);
  2213. LinuxError:=Errno;
  2214. end;
  2215. Function Fcntl(Fd:longint;Cmd:longint): longint;
  2216. {
  2217. Read or manipulate a file.(See also fcntl (2) )
  2218. Possible values for Cmd are :
  2219. F_GetFd,F_GetFl,F_GetOwn
  2220. Errors are reported in Linuxerror;
  2221. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  2222. }
  2223. var
  2224. sr : Syscallregs;
  2225. begin
  2226. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  2227. begin
  2228. sr.reg2:=Fd;
  2229. sr.reg3:=cmd;
  2230. Linuxerror:=SysCall(Syscall_nr_fcntl,sr);
  2231. if linuxerror=-1 then
  2232. begin
  2233. linuxerror:=errno;
  2234. fcntl:=0;
  2235. end
  2236. else
  2237. begin
  2238. fcntl:=linuxerror;
  2239. linuxerror:=0;
  2240. end;
  2241. end
  2242. else
  2243. begin
  2244. linuxerror:=Sys_einval;
  2245. Fcntl:=0;
  2246. end;
  2247. end;
  2248. Procedure Fcntl(Fd:longint;Cmd:LongInt;Arg:Longint);
  2249. {
  2250. Read or manipulate a file. (See also fcntl (2) )
  2251. Possible values for Cmd are :
  2252. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  2253. Errors are reported in Linuxerror;
  2254. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  2255. F_DupFD is not allowed, due to the structure of Files in Pascal.
  2256. }
  2257. var
  2258. sr : Syscallregs;
  2259. begin
  2260. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  2261. begin
  2262. sr.reg2:=Fd;
  2263. sr.reg3:=cmd;
  2264. sr.reg4:=arg;
  2265. SysCall(Syscall_nr_fcntl,sr);
  2266. linuxerror:=errno;
  2267. end
  2268. else
  2269. linuxerror:=Sys_einval;
  2270. end;
  2271. Function Chmod(path:pathstr;Newmode:longint):Boolean;
  2272. {
  2273. Changes the permissions of a file.
  2274. }
  2275. var
  2276. sr : Syscallregs;
  2277. begin
  2278. path:=path+#0;
  2279. sr.reg2:=longint(@(path[1]));
  2280. sr.reg3:=newmode;
  2281. Chmod:=(SysCall(Syscall_nr_chmod,sr)=0);
  2282. linuxerror:=errno;
  2283. end;
  2284. Function Chown(path:pathstr;NewUid,NewGid:longint):boolean;
  2285. {
  2286. Change the owner and group of a file.
  2287. A user can only change the group to a group of which he is a member.
  2288. The super-user can change uid and gid of any file.
  2289. }
  2290. var
  2291. sr : Syscallregs;
  2292. begin
  2293. path:=path+#0;
  2294. sr.reg2:=longint(@(path[1]));
  2295. sr.reg3:=newuid;
  2296. sr.reg4:=newgid;
  2297. ChOwn:=(Syscall(Syscall_nr_chown,sr)=0);
  2298. linuxerror:=errno;
  2299. end;
  2300. Function Utime(const path:pathstr;utim:utimebuf):boolean;
  2301. var
  2302. sr : Syscallregs;
  2303. buf : pathstr;
  2304. begin
  2305. buf:=path+#0;
  2306. sr.reg2:=longint(@(buf[1]));
  2307. sr.reg3:=longint(@utim);
  2308. Utime:=SysCall(Syscall_nr_utime,sr)=0;
  2309. linuxerror:=errno;
  2310. end;
  2311. Function Flock (fd,mode : longint) : boolean;
  2312. var
  2313. sr : Syscallregs;
  2314. begin
  2315. sr.reg2:=fd;
  2316. sr.reg3:=mode;
  2317. flock:=Syscall(Syscall_nr_flock,sr)=0;
  2318. LinuxError:=errno;
  2319. end;
  2320. Function Fstat(Fd:Longint;var Info:stat):Boolean;
  2321. {
  2322. Get all information on a file descriptor, and return it in info.
  2323. }
  2324. var
  2325. regs : SysCallregs;
  2326. begin
  2327. regs.reg2:=Fd;
  2328. regs.reg3:=longint(@Info);
  2329. FStat:=(SysCall(SysCall_nr_fstat,regs)=0);
  2330. LinuxError:=Errno;
  2331. end;
  2332. Function Lstat(Filename: PathStr;var Info:stat):Boolean;
  2333. {
  2334. Get all information on a link (the link itself), and return it in info.
  2335. }
  2336. var
  2337. regs : SysCallregs;
  2338. begin
  2339. FileName:=FileName+#0;
  2340. regs.reg2:=longint(@filename[1]);
  2341. regs.reg3:=longint(@Info);
  2342. LStat:=(SysCall(SysCall_nr_lstat,regs)=0);
  2343. LinuxError:=Errno;
  2344. end;
  2345. Function FSStat(Path:Pathstr;Var Info:statfs):Boolean;
  2346. {
  2347. Get all information on a fileSystem, and return it in Info.
  2348. Path is the name of a file/directory on the fileSystem you wish to
  2349. investigate.
  2350. }
  2351. var
  2352. regs : SysCallregs;
  2353. begin
  2354. path:=path+#0;
  2355. regs.reg2:=longint(@path[1]);
  2356. regs.reg3:=longint(@Info);
  2357. FSStat:=(SysCall(SysCall_nr_statfs,regs)=0);
  2358. LinuxError:=errno;
  2359. end;
  2360. Function FSStat(Fd:Longint;Var Info:statfs):Boolean;
  2361. {
  2362. Get all information on a fileSystem, and return it in Info.
  2363. Fd is the file descriptor of a file/directory on the fileSystem
  2364. you wish to investigate.
  2365. }
  2366. var
  2367. regs : SysCallregs;
  2368. begin
  2369. regs.reg2:=Fd;
  2370. regs.reg3:=longint(@Info);
  2371. FSStat:=(SysCall(SysCall_nr_fstatfs,regs)=0);
  2372. LinuxError:=errno;
  2373. end;
  2374. Function Link(OldPath,NewPath:pathstr):boolean;
  2375. {
  2376. Proceduces a hard link from new to old.
  2377. In effect, new will be the same file as old.
  2378. }
  2379. var
  2380. regs : SysCallregs;
  2381. begin
  2382. oldpath:=oldpath+#0;
  2383. newpath:=newpath+#0;
  2384. regs.reg2:=longint(@oldpath[1]);
  2385. regs.reg3:=longint(@newpath[1]);
  2386. Link:=SysCall(SysCall_nr_link,regs)=0;
  2387. linuxerror:=errno;
  2388. end;
  2389. Function Umask(Mask:Integer):integer;
  2390. {
  2391. Sets file creation mask to (Mask and 0777 (octal) ), and returns the
  2392. previous value.
  2393. }
  2394. var
  2395. sr : Syscallregs;
  2396. begin
  2397. sr.reg2:=mask;
  2398. Umask:=SysCall(Syscall_nr_umask,sr);
  2399. linuxerror:=0;
  2400. end;
  2401. Function Access(Path:Pathstr ;mode:integer):boolean;
  2402. {
  2403. Test users access rights on the specified file.
  2404. Mode is a mask xosisting of one or more of R_OK, W_OK, X_OK, F_OK.
  2405. R,W,X stand for read,write and Execute access, simultaneously.
  2406. F_OK checks whether the test would be allowed on the file.
  2407. i.e. It checks the search permissions in all directory components
  2408. of the path.
  2409. The test is done with the real user-ID, instead of the effective.
  2410. If access is denied, or an error occurred, false is returned.
  2411. If access is granted, true is returned.
  2412. Errors other than no access,are reported in linuxerror.
  2413. }
  2414. var
  2415. sr : Syscallregs;
  2416. begin
  2417. path:=path+#0;
  2418. sr.reg2:=longint(@(path[1]));
  2419. sr.reg3:=mode;
  2420. access:=(SysCall(Syscall_nr_access,sr)=0);
  2421. linuxerror:=errno;
  2422. end;
  2423. Function Dup(oldfile:longint;var newfile:longint):Boolean;
  2424. {
  2425. Copies the filedescriptor oldfile to newfile
  2426. }
  2427. var
  2428. sr : Syscallregs;
  2429. begin
  2430. sr.reg2:=oldfile;
  2431. newfile:=Syscall(Syscall_nr_dup,sr);
  2432. linuxerror:=errno;
  2433. Dup:=(LinuxError=0);
  2434. end;
  2435. Function Dup2(oldfile,newfile:longint):Boolean;
  2436. {
  2437. Copies the filedescriptor oldfile to newfile
  2438. }
  2439. var
  2440. sr : Syscallregs;
  2441. begin
  2442. sr.reg2:=oldfile;
  2443. sr.reg3:=newfile;
  2444. SysCall(Syscall_nr_dup2,sr);
  2445. linuxerror:=errno;
  2446. Dup2:=(LinuxError=0);
  2447. end;
  2448. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:PTimeVal):longint;
  2449. {
  2450. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  2451. have changed.
  2452. }
  2453. Var
  2454. SelectArray : Array[1..5] of longint;
  2455. Sr : Syscallregs;
  2456. begin
  2457. SelectArray[1]:=n;
  2458. SelectArray[2]:=longint(Readfds);
  2459. Selectarray[3]:=longint(Writefds);
  2460. selectarray[4]:=longint(exceptfds);
  2461. Selectarray[5]:=longint(TimeOut);
  2462. sr.reg2:=longint(@selectarray);
  2463. Select:=SysCall(Syscall_nr_select,sr);
  2464. LinuxError:=Errno;
  2465. end;
  2466. Function AssignPipe(var pipe_in,pipe_out:longint):boolean;
  2467. {
  2468. Sets up a pair of file variables, which act as a pipe. The first one can
  2469. be read from, the second one can be written to.
  2470. If the operation was unsuccesful, linuxerror is set.
  2471. }
  2472. var
  2473. pip : tpipe;
  2474. regs : SysCallregs;
  2475. begin
  2476. regs.reg2:=longint(@pip);
  2477. SysCall(SysCall_nr_pipe,regs);
  2478. pipe_in:=pip[1];
  2479. pipe_out:=pip[2];
  2480. linuxerror:=errno;
  2481. AssignPipe:=(LinuxError=0);
  2482. end;
  2483. Function PClose(Var F:text) :longint;
  2484. var
  2485. sr : syscallregs;
  2486. pl : ^longint;
  2487. res : longint;
  2488. begin
  2489. sr.reg2:=Textrec(F).Handle;
  2490. SysCall (syscall_nr_close,sr);
  2491. { closed our side, Now wait for the other - this appears to be needed ?? }
  2492. pl:=plongint(@(textrec(f).userdata[2]));
  2493. waitpid(pl^,@res,0);
  2494. pclose:=res shr 8;
  2495. end;
  2496. Function PClose(Var F:file) : longint;
  2497. var
  2498. sr : syscallregs;
  2499. pl : ^longint;
  2500. res : longint;
  2501. begin
  2502. sr.reg2:=FileRec(F).Handle;
  2503. SysCall (Syscall_nr_close,sr);
  2504. { closed our side, Now wait for the other - this appears to be needed ?? }
  2505. pl:=plongint(@(filerec(f).userdata[2]));
  2506. waitpid(pl^,@res,0);
  2507. pclose:=res shr 8;
  2508. end;
  2509. Function Sysinfo(var Info:TSysinfo):Boolean;
  2510. {
  2511. Get system info
  2512. }
  2513. var
  2514. regs : SysCallregs;
  2515. Begin
  2516. regs.reg2:=longint(@info);
  2517. Sysinfo:=SysCall(SysCall_nr_Sysinfo,regs)=0;
  2518. End;
  2519. Function mkFifo(pathname:string;mode:longint):boolean;
  2520. var
  2521. regs : SysCallRegs;
  2522. begin
  2523. pathname:=pathname+#0;
  2524. regs.reg2:=longint(@pathname[1]);
  2525. regs.reg3:=mode or STAT_IFIFO;
  2526. regs.reg4:=0;
  2527. mkFifo:=(SysCall(syscall_nr_mknod,regs)=0);
  2528. end;
  2529. Function Uname(var unamerec:utsname):Boolean;
  2530. {
  2531. Get machine's names
  2532. }
  2533. var
  2534. regs : SysCallregs;
  2535. Begin
  2536. regs.reg2:=longint(@unamerec);
  2537. Uname:=SysCall(SysCall_nr_uname,regs)=0;
  2538. LinuxError:=Errno;
  2539. End;
  2540. Function Kill(Pid:longint;Sig:longint):integer;
  2541. {
  2542. Send signal 'sig' to a process, or a group of processes.
  2543. If Pid > 0 then the signal is sent to pid
  2544. pid=-1 to all processes except process 1
  2545. pid < -1 to process group -pid
  2546. Return value is zero, except for case three, where the return value
  2547. is the number of processes to which the signal was sent.
  2548. }
  2549. var
  2550. regs : Syscallregs;
  2551. begin
  2552. regs.reg2:=Pid;
  2553. regs.reg3:=Sig;
  2554. kill:=SysCall(Syscall_nr_kill,regs);
  2555. if kill<0 then
  2556. Kill:=0;
  2557. linuxerror:=errno;
  2558. end;
  2559. Procedure SigProcMask(How:longint;SSet,OldSSet:PSigSet);
  2560. {
  2561. Change the list of currently blocked signals.
  2562. How determines which signals will be blocked :
  2563. SigBlock : Add SSet to the current list of blocked signals
  2564. SigUnBlock : Remove the signals in SSet from the list of blocked signals.
  2565. SigSetMask : Set the list of blocked signals to SSet
  2566. if OldSSet is non-null, the old set will be saved there.
  2567. }
  2568. Var
  2569. sr : SyscallRegs;
  2570. begin
  2571. sr.reg2:=how;
  2572. sr.reg3:=longint(SSet);
  2573. sr.reg4:=longint(OldSSet);
  2574. SysCall(Syscall_nr_sigprocmask,sr);
  2575. linuxerror:=errno;
  2576. end;
  2577. Function SigPending:SigSet;
  2578. {
  2579. Allows examination of pending signals. The signal mask of pending
  2580. signals is set in SSet
  2581. }
  2582. Var
  2583. sr : SyscallRegs;
  2584. dummy : Sigset;
  2585. begin
  2586. sr.reg2:=longint(@dummy);
  2587. SysCall(Syscall_nr_sigpending,sr);
  2588. linuxerror:=errno;
  2589. Sigpending:=dummy;
  2590. end;
  2591. Procedure SigSuspend(Mask:Sigset);
  2592. {
  2593. Set the signal mask with Mask, and suspend the program until a signal
  2594. is received.
  2595. }
  2596. Var
  2597. sr : SyscallRegs;
  2598. begin
  2599. sr.reg2:=mask;
  2600. SysCall(Syscall_nr_sigsuspend,sr);
  2601. linuxerror:=errno;
  2602. end;
  2603. Function Signal(Signum:longint;Handler:SignalHandler):SignalHandler;
  2604. {
  2605. Install a new handler for signal Signum.
  2606. The old signal handler is returned.
  2607. This call does, in fact, the same as SigAction.
  2608. }
  2609. var
  2610. sr : Syscallregs;
  2611. begin
  2612. sr.reg2:=signum;
  2613. sr.reg3:=longint(handler);
  2614. Linuxerror:=SysCall(Syscall_nr_signal,sr);
  2615. If linuxerror=Sig_Err then
  2616. begin
  2617. Signal:=nil;
  2618. Linuxerror:=errno;
  2619. end
  2620. else
  2621. begin
  2622. Signal:=signalhandler(Linuxerror);
  2623. linuxerror:=0;
  2624. end;
  2625. end;
  2626. Function Alarm(Sec : Longint) : longint;
  2627. Var Sr : Syscallregs;
  2628. begin
  2629. sr.reg2:=Sec;
  2630. Alarm:=Syscall(syscall_nr_alarm,sr);
  2631. end;
  2632. Procedure Pause;
  2633. Var Sr : Syscallregs;
  2634. begin
  2635. syscall(syscall_nr_pause,sr);
  2636. end;
  2637. Function NanoSleep(const req : timespec;var rem : timespec) : longint;
  2638. var Sr : Syscallregs;
  2639. begin
  2640. sr.reg2:=longint(@req);
  2641. sr.reg3:=longint(@rem);
  2642. NanoSleep:=Syscall(syscall_nr_nanosleep,sr);
  2643. LinuxError:=Errno;
  2644. end;
  2645. Function IOCtl(Handle,Ndx: Longint;Data: Pointer):boolean;
  2646. {
  2647. Interface to Unix ioctl call.
  2648. Performs various operations on the filedescriptor Handle.
  2649. Ndx describes the operation to perform.
  2650. Data points to data needed for the Ndx function. The structure of this
  2651. data is function-dependent.
  2652. }
  2653. var
  2654. sr: SysCallRegs;
  2655. begin
  2656. sr.reg2:=Handle;
  2657. sr.reg3:=Ndx;
  2658. sr.reg4:=Longint(Data);
  2659. IOCtl:=(SysCall(Syscall_nr_ioctl,sr)=0);
  2660. LinuxError:=Errno;
  2661. end;
  2662. function MMap(const m:tmmapargs):longint;
  2663. Var
  2664. Sr : Syscallregs;
  2665. begin
  2666. Sr.reg2:=longint(@m);
  2667. MMap:=syscall(syscall_nr_mmap,sr);
  2668. LinuxError:=Errno;
  2669. end;
  2670. function MUnMap (P : Pointer; Size : Longint) : Boolean;
  2671. Var
  2672. Sr : Syscallregs;
  2673. begin
  2674. Sr.reg2:=longint(P);
  2675. sr.reg3:=Size;
  2676. MUnMap:=syscall(syscall_nr_munmap,sr)=0;
  2677. LinuxError:=Errno;
  2678. end;
  2679. {--------------------------------
  2680. Port IO functions
  2681. --------------------------------}
  2682. Function IOperm (From,Num : Cardinal; Value : Longint) : boolean;
  2683. {
  2684. Set permissions on NUM ports starting with port FROM to VALUE
  2685. this works ONLY as root.
  2686. }
  2687. Var
  2688. Sr : Syscallregs;
  2689. begin
  2690. Sr.Reg2:=From;
  2691. Sr.Reg3:=Num;
  2692. Sr.Reg4:=Value;
  2693. IOPerm:=Syscall(Syscall_nr_ioperm,sr)=0;
  2694. LinuxError:=Errno;
  2695. end;
  2696. Function IoPL(Level : longint) : Boolean;
  2697. Var
  2698. Sr : Syscallregs;
  2699. begin
  2700. Sr.Reg2:=Level;
  2701. IOPL:=Syscall(Syscall_nr_iopl,sr)=0;
  2702. LinuxError:=Errno;
  2703. end;
  2704. {******************************************************************************
  2705. Process related calls
  2706. ******************************************************************************}
  2707. { Most calls of WaitPID do not handle the result correctly, this funktion treats errors more correctly }
  2708. 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}
  2709. var r,s : LongInt;
  2710. begin
  2711. repeat
  2712. s:=$7F00;
  2713. r:=WaitPid(Pid,@s,0);
  2714. until (r<>-1) or (LinuxError<>Sys_EINTR);
  2715. if (r=-1) or (r=0) then // 0 is not a valid return and should never occur (it means status invalid when using WNOHANG)
  2716. WaitProcess:=-1 // return -1 to indicate an error
  2717. else
  2718. begin
  2719. {$ifdef solaris}
  2720. if (s and $FF)=0 then // Only this is a valid returncode
  2721. {$else solaris}
  2722. { the following is at least correct for Linux and Darwin (JM) }
  2723. if (s and $7F)=0 then
  2724. {$endif solaris}
  2725. WaitProcess:=s shr 8
  2726. else if (s>0) then // Until now there is not use of the highest bit , but check this for the future
  2727. WaitProcess:=-s // normal case
  2728. else
  2729. WaitProcess:=s; // s<0 should not occur, but wie return also a negativ value
  2730. end;
  2731. end;
  2732. function InternalCreateShellArgV(cmd:pChar; len:longint):ppchar;
  2733. {
  2734. Create an argv which executes a command in a shell using /bin/sh -c
  2735. }
  2736. const Shell = '/bin/sh'#0'-c'#0;
  2737. var
  2738. pp,p : ppchar;
  2739. // temp : string; !! Never pass a local var back!!
  2740. begin
  2741. getmem(pp,4*4);
  2742. p:=pp;
  2743. p^:=@Shell[1];
  2744. inc(p);
  2745. p^:=@Shell[9];
  2746. inc(p);
  2747. getmem(p^,len+1);
  2748. move(cmd^,p^^,len);
  2749. pchar(p^)[len]:=#0;
  2750. inc(p);
  2751. p^:=Nil;
  2752. InternalCreateShellArgV:=pp;
  2753. end;
  2754. function CreateShellArgV(const prog:string):ppchar;
  2755. begin
  2756. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog));
  2757. end;
  2758. function CreateShellArgV(const prog:Ansistring):ppchar;
  2759. {
  2760. Create an argv which executes a command in a shell using /bin/sh -c
  2761. using a AnsiString;
  2762. }
  2763. begin
  2764. CreateShellArgV:=InternalCreateShellArgV(@prog[1],length(prog)); // if ppc works like delphi this also work when @prog[1] is invalid (len=0)
  2765. end;
  2766. procedure FreeShellArgV(p:ppchar);
  2767. begin
  2768. if (p<>nil) then begin
  2769. freemem(p[2]);
  2770. freemem(p);
  2771. end;
  2772. end;
  2773. Procedure Execve(Path: AnsiString;args:ppchar;ep:ppchar);
  2774. {
  2775. overloaded ansistring version.
  2776. }
  2777. begin
  2778. ExecVE(PChar(Path),args,ep);
  2779. end;
  2780. Procedure Execv(const path: AnsiString;args:ppchar);
  2781. {
  2782. Overloaded ansistring version.
  2783. }
  2784. begin
  2785. ExecVe(Path,Args,envp)
  2786. end;
  2787. Procedure Execvp(Path: AnsiString; Args:ppchar;Ep:ppchar);
  2788. {
  2789. Overloaded ansistring version
  2790. }
  2791. var
  2792. thepath : Ansistring;
  2793. begin
  2794. if path[1]<>'/' then
  2795. begin
  2796. Thepath:=strpas(getenv('PATH'));
  2797. if thepath='' then
  2798. thepath:='.';
  2799. Path:=FSearch(path,thepath)
  2800. end
  2801. else
  2802. Path:='';
  2803. if Path='' then
  2804. linuxerror:=Sys_enoent
  2805. else
  2806. Execve(Path,args,ep);{On error linuxerror will get set there}
  2807. end;
  2808. Procedure Execv(const path:pathstr;args:ppchar);
  2809. {
  2810. Replaces the current program by the program specified in path,
  2811. arguments in args are passed to Execve.
  2812. the current environment is passed on.
  2813. }
  2814. begin
  2815. Execve(path,args,envp); {On error linuxerror will get set there}
  2816. end;
  2817. Procedure Execvp(Path:Pathstr;Args:ppchar;Ep:ppchar);
  2818. {
  2819. This does the same as Execve, only it searches the PATH environment
  2820. for the place of the Executable, except when Path starts with a slash.
  2821. if the PATH environment variable is unavailable, the path is set to '.'
  2822. }
  2823. var
  2824. thepath : string;
  2825. begin
  2826. if path[1]<>'/' then
  2827. begin
  2828. Thepath:=strpas(getenv('PATH'));
  2829. if thepath='' then
  2830. thepath:='.';
  2831. Path:=FSearch(path,thepath)
  2832. end
  2833. else
  2834. Path:='';
  2835. if Path='' then
  2836. linuxerror:=Sys_enoent
  2837. else
  2838. Execve(Path,args,ep);{On error linuxerror will get set there}
  2839. end;
  2840. Procedure Execle(Todo:string;Ep:ppchar);
  2841. {
  2842. This procedure takes the string 'Todo', parses it for command and
  2843. command options, and Executes the command with the given options.
  2844. The string 'Todo' shoud be of the form 'command options', options
  2845. separated by commas.
  2846. the PATH environment is not searched for 'command'.
  2847. The specified environment(in 'ep') is passed on to command
  2848. }
  2849. var
  2850. p : ppchar;
  2851. begin
  2852. p:=StringToPPChar(ToDo);
  2853. if (p=nil) or (p^=nil) then
  2854. exit;
  2855. ExecVE(p^,p,EP);
  2856. end;
  2857. Procedure Execle(Todo:AnsiString;Ep:ppchar);
  2858. {
  2859. This procedure takes the string 'Todo', parses it for command and
  2860. command options, and Executes the command with the given options.
  2861. The string 'Todo' shoud be of the form 'command options', options
  2862. separated by commas.
  2863. the PATH environment is not searched for 'command'.
  2864. The specified environment(in 'ep') is passed on to command
  2865. }
  2866. var
  2867. p : ppchar;
  2868. begin
  2869. p:=StringToPPChar(ToDo);
  2870. if (p=nil) or (p^=nil) then
  2871. exit;
  2872. ExecVE(p^,p,EP);
  2873. end;
  2874. Procedure Execl(const Todo:string);
  2875. {
  2876. This procedure takes the string 'Todo', parses it for command and
  2877. command options, and Executes the command with the given options.
  2878. The string 'Todo' shoud be of the form 'command options', options
  2879. separated by commas.
  2880. the PATH environment is not searched for 'command'.
  2881. The current environment is passed on to command
  2882. }
  2883. begin
  2884. ExecLE(ToDo,EnvP);
  2885. end;
  2886. Procedure Execl(const Todo:Ansistring);
  2887. {
  2888. Overloaded AnsiString Version of ExecL.
  2889. }
  2890. begin
  2891. ExecLE(ToDo,EnvP);
  2892. end;
  2893. Procedure Execlp(Todo:string;Ep:ppchar);
  2894. {
  2895. This procedure takes the string 'Todo', parses it for command and
  2896. command options, and Executes the command with the given options.
  2897. The string 'Todo' shoud be of the form 'command options', options
  2898. separated by commas.
  2899. the PATH environment is searched for 'command'.
  2900. The specified environment (in 'ep') is passed on to command
  2901. }
  2902. var
  2903. p : ppchar;
  2904. begin
  2905. p:=StringToPPchar(todo);
  2906. if (p=nil) or (p^=nil) then
  2907. exit;
  2908. ExecVP(StrPas(p^),p,EP);
  2909. end;
  2910. Procedure Execlp(Todo: Ansistring;Ep:ppchar);
  2911. {
  2912. Overloaded ansistring version.
  2913. }
  2914. var
  2915. p : ppchar;
  2916. begin
  2917. p:=StringToPPchar(todo);
  2918. if (p=nil) or (p^=nil) then
  2919. exit;
  2920. ExecVP(StrPas(p^),p,EP);
  2921. end;
  2922. Function Shell(const Command:String):Longint;
  2923. {
  2924. Executes the shell, and passes it the string Command. (Through /bin/sh -c)
  2925. The current environment is passed to the shell.
  2926. It waits for the shell to exit, and returns its exit status.
  2927. If the Exec call failed exit status 127 is reported.
  2928. }
  2929. { Changed the structure:
  2930. - the previous version returns an undefinied value if fork fails
  2931. - it returns the status of Waitpid instead of the Process returnvalue (see the doc to Shell)
  2932. - it uses exit(127) not ExitProc (The Result in pp386: going on Compiling in 2 processes!)
  2933. - ShellArgs are now released
  2934. - The Old CreateShellArg gives back pointers to a local var
  2935. }
  2936. var
  2937. p : ppchar;
  2938. pid,r,s : longint;
  2939. begin
  2940. p:=CreateShellArgv(command);
  2941. pid:=fork;
  2942. if pid=0 then // We are in the Child
  2943. begin
  2944. {This is the child.}
  2945. Execve(p^,p,envp);
  2946. ExitProcess(127); // was Exit(127)
  2947. end
  2948. else if (pid<>-1) then // Successfull started
  2949. begin
  2950. repeat
  2951. s:=$7F00;
  2952. r:=WaitPid(Pid,@s,0);
  2953. until (r<>-1) or (LinuxError<>Sys_EINTR);
  2954. if (r=-1) or (r=0) then
  2955. Shell:=-1
  2956. else
  2957. Shell:=s;
  2958. end
  2959. else // no success
  2960. Shell:=-1; // indicate an error
  2961. FreeShellArgV(p);
  2962. end;
  2963. Function Shell(const Command:AnsiString):Longint;
  2964. {
  2965. AnsiString version of Shell
  2966. }
  2967. var
  2968. p : ppchar;
  2969. pid : longint;
  2970. begin { Changes as above }
  2971. p:=CreateShellArgv(command);
  2972. pid:=fork;
  2973. if pid=0 then // We are in the Child
  2974. begin
  2975. Execve(p^,p,envp);
  2976. ExitProcess(127); // was exit(127)!! We must exit the Process, not the function
  2977. end
  2978. else if (pid<>-1) then // Successfull started
  2979. Shell:=WaitProcess(pid) {Linuxerror is set there}
  2980. else // no success
  2981. Shell:=-1;
  2982. FreeShellArgV(p);
  2983. end;
  2984. function WEXITSTATUS(Status: Integer): Integer;
  2985. begin
  2986. WEXITSTATUS:=(Status and $FF00) shr 8;
  2987. end;
  2988. function WTERMSIG(Status: Integer): Integer;
  2989. begin
  2990. WTERMSIG:=(Status and $7F);
  2991. end;
  2992. function WSTOPSIG(Status: Integer): Integer;
  2993. begin
  2994. WSTOPSIG:=WEXITSTATUS(Status);
  2995. end;
  2996. Function WIFEXITED(Status: Integer): Boolean;
  2997. begin
  2998. WIFEXITED:=(WTERMSIG(Status)=0);
  2999. end;
  3000. Function WIFSTOPPED(Status: Integer): Boolean;
  3001. begin
  3002. WIFSTOPPED:=((Status and $FF)=$7F);
  3003. end;
  3004. Function WIFSIGNALED(Status: Integer): Boolean;
  3005. begin
  3006. WIFSIGNALED:=(not WIFSTOPPED(Status)) and
  3007. (not WIFEXITED(Status));
  3008. end;
  3009. Function W_EXITCODE(ReturnCode, Signal: Integer): Integer;
  3010. begin
  3011. W_EXITCODE:=(ReturnCode shl 8) or Signal;
  3012. end;
  3013. Function W_STOPCODE(Signal: Integer): Integer;
  3014. begin
  3015. W_STOPCODE:=(Signal shl 8) or $7F;
  3016. end;
  3017. {******************************************************************************
  3018. Date and Time related calls
  3019. ******************************************************************************}
  3020. Const
  3021. {Date Translation}
  3022. C1970=2440588;
  3023. D0 = 1461;
  3024. D1 = 146097;
  3025. D2 =1721119;
  3026. Function GregorianToJulian(Year,Month,Day:Longint):LongInt;
  3027. Var
  3028. Century,XYear: LongInt;
  3029. Begin
  3030. If Month<=2 Then
  3031. Begin
  3032. Dec(Year);
  3033. Inc(Month,12);
  3034. End;
  3035. Dec(Month,3);
  3036. Century:=(longint(Year Div 100)*D1) shr 2;
  3037. XYear:=(longint(Year Mod 100)*D0) shr 2;
  3038. GregorianToJulian:=((((Month*153)+2) div 5)+Day)+D2+XYear+Century;
  3039. End;
  3040. Procedure JulianToGregorian(JulianDN:LongInt;Var Year,Month,Day:Word);
  3041. Var
  3042. YYear,XYear,Temp,TempMonth : LongInt;
  3043. Begin
  3044. Temp:=((JulianDN-D2) shl 2)-1;
  3045. JulianDN:=Temp Div D1;
  3046. XYear:=(Temp Mod D1) or 3;
  3047. YYear:=(XYear Div D0);
  3048. Temp:=((((XYear mod D0)+4) shr 2)*5)-3;
  3049. Day:=((Temp Mod 153)+5) Div 5;
  3050. TempMonth:=Temp Div 153;
  3051. If TempMonth>=10 Then
  3052. Begin
  3053. inc(YYear);
  3054. dec(TempMonth,12);
  3055. End;
  3056. inc(TempMonth,3);
  3057. Month := TempMonth;
  3058. Year:=YYear+(JulianDN*100);
  3059. end;
  3060. Function GetEpochTime: longint;
  3061. {
  3062. Get the number of seconds since 00:00, January 1 1970, GMT
  3063. the time NOT corrected any way
  3064. }
  3065. begin
  3066. GetEpochTime:=GetTimeOfDay;
  3067. end;
  3068. Procedure EpochToLocal(epoch:longint;var year,month,day,hour,minute,second:Word);
  3069. {
  3070. Transforms Epoch time into local time (hour, minute,seconds)
  3071. }
  3072. Var
  3073. DateNum: LongInt;
  3074. Begin
  3075. inc(Epoch,TZSeconds);
  3076. Datenum:=(Epoch Div 86400) + c1970;
  3077. JulianToGregorian(DateNum,Year,Month,day);
  3078. Epoch:=Abs(Epoch Mod 86400);
  3079. Hour:=Epoch Div 3600;
  3080. Epoch:=Epoch Mod 3600;
  3081. Minute:=Epoch Div 60;
  3082. Second:=Epoch Mod 60;
  3083. End;
  3084. Function LocalToEpoch(year,month,day,hour,minute,second:Word):Longint;
  3085. {
  3086. Transforms local time (year,month,day,hour,minutes,second) to Epoch time
  3087. (seconds since 00:00, january 1 1970, corrected for local time zone)
  3088. }
  3089. Begin
  3090. LocalToEpoch:=((GregorianToJulian(Year,Month,Day)-c1970)*86400)+
  3091. (LongInt(Hour)*3600)+(Minute*60)+Second-TZSeconds;
  3092. End;
  3093. procedure GetTime(var hour,min,sec,msec,usec:word);
  3094. {
  3095. Gets the current time, adjusted to local time
  3096. }
  3097. var
  3098. year,day,month:Word;
  3099. t : timeval;
  3100. begin
  3101. gettimeofday(t);
  3102. EpochToLocal(t.sec,year,month,day,hour,min,sec);
  3103. msec:=t.usec div 1000;
  3104. usec:=t.usec mod 1000;
  3105. end;
  3106. procedure GetTime(var hour,min,sec,sec100:word);
  3107. {
  3108. Gets the current time, adjusted to local time
  3109. }
  3110. var
  3111. usec : word;
  3112. begin
  3113. gettime(hour,min,sec,sec100,usec);
  3114. sec100:=sec100 div 10;
  3115. end;
  3116. Procedure GetTime(Var Hour,Min,Sec:Word);
  3117. {
  3118. Gets the current time, adjusted to local time
  3119. }
  3120. var
  3121. msec,usec : Word;
  3122. Begin
  3123. gettime(hour,min,sec,msec,usec);
  3124. End;
  3125. Procedure GetDate(Var Year,Month,Day:Word);
  3126. {
  3127. Gets the current date, adjusted to local time
  3128. }
  3129. var
  3130. hour,minute,second : word;
  3131. Begin
  3132. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  3133. End;
  3134. Procedure GetDateTime(Var Year,Month,Day,hour,minute,second:Word);
  3135. {
  3136. Gets the current date, adjusted to local time
  3137. }
  3138. Begin
  3139. EpochToLocal(GetTimeOfDay,year,month,day,hour,minute,second);
  3140. End;
  3141. {$ifndef BSD} {Fix for 1.0.x starting compiler only}
  3142. {$ifdef linux}
  3143. Function stime (t : longint) : Boolean;
  3144. var
  3145. sr : Syscallregs;
  3146. begin
  3147. sr.reg2:=longint(@t);
  3148. SysCall(Syscall_nr_stime,sr);
  3149. linuxerror:=errno;
  3150. stime:=linuxerror=0;
  3151. end;
  3152. {$endif}
  3153. {$endif}
  3154. {$ifdef BSD}
  3155. Function stime (t : longint) : Boolean;
  3156. begin
  3157. stime:=false;
  3158. end;
  3159. {$endif}
  3160. Function SetTime(Hour,Min,Sec:word) : boolean;
  3161. var
  3162. Year, Month, Day : Word;
  3163. begin
  3164. GetDate (Year, Month, Day);
  3165. SetTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Min, Sec ) );
  3166. end;
  3167. Function SetDate(Year,Month,Day:Word) : boolean;
  3168. var
  3169. Hour, Minute, Second, Sec100 : Word;
  3170. begin
  3171. GetTime ( Hour, Minute, Second, Sec100 );
  3172. SetDate:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  3173. end;
  3174. Function SetDateTime(Year,Month,Day,hour,minute,second:Word) : Boolean;
  3175. begin
  3176. SetDateTime:=stime ( LocalToEpoch ( Year, Month, Day, Hour, Minute, Second ) );
  3177. end;
  3178. { Include timezone handling routines which use /usr/share/timezone info }
  3179. type
  3180. plongint=^longint;
  3181. pbyte=^byte;
  3182. ttzhead=packed record
  3183. tzh_reserved : array[0..19] of byte;
  3184. tzh_ttisgmtcnt,
  3185. tzh_ttisstdcnt,
  3186. tzh_leapcnt,
  3187. tzh_timecnt,
  3188. tzh_typecnt,
  3189. tzh_charcnt : longint;
  3190. end;
  3191. pttinfo=^tttinfo;
  3192. tttinfo=packed record
  3193. offset : longint;
  3194. isdst : boolean;
  3195. idx : byte;
  3196. isstd : byte;
  3197. isgmt : byte;
  3198. end;
  3199. pleap=^tleap;
  3200. tleap=record
  3201. transition : longint;
  3202. change : longint;
  3203. end;
  3204. var
  3205. num_transitions,
  3206. num_leaps,
  3207. num_types : longint;
  3208. transitions : plongint;
  3209. type_idxs : pbyte;
  3210. types : pttinfo;
  3211. zone_names : pchar;
  3212. leaps : pleap;
  3213. function find_transition(timer:longint):pttinfo;
  3214. var
  3215. i : longint;
  3216. begin
  3217. if (num_transitions=0) or (timer<transitions[0]) then
  3218. begin
  3219. i:=0;
  3220. while (i<num_types) and (types[i].isdst) do
  3221. inc(i);
  3222. if (i=num_types) then
  3223. i:=0;
  3224. end
  3225. else
  3226. begin
  3227. for i:=1 to num_transitions do
  3228. if (timer<transitions[i]) then
  3229. break;
  3230. i:=type_idxs[i-1];
  3231. end;
  3232. find_transition:=@types[i];
  3233. end;
  3234. procedure GetLocalTimezone(timer:longint;var leap_correct,leap_hit:longint);
  3235. var
  3236. info : pttinfo;
  3237. i : longint;
  3238. begin
  3239. { reset }
  3240. TZDaylight:=false;
  3241. TZSeconds:=0;
  3242. TZName[false]:=nil;
  3243. TZName[true]:=nil;
  3244. leap_correct:=0;
  3245. leap_hit:=0;
  3246. { get info }
  3247. info:=find_transition(timer);
  3248. if not assigned(info) then
  3249. exit;
  3250. TZDaylight:=info^.isdst;
  3251. TZSeconds:=info^.offset;
  3252. i:=0;
  3253. while (i<num_types) do
  3254. begin
  3255. tzname[types[i].isdst]:=@zone_names[types[i].idx];
  3256. inc(i);
  3257. end;
  3258. tzname[info^.isdst]:=@zone_names[info^.idx];
  3259. i:=num_leaps;
  3260. repeat
  3261. if i=0 then
  3262. exit;
  3263. dec(i);
  3264. until (timer>leaps[i].transition);
  3265. leap_correct:=leaps[i].change;
  3266. if (timer=leaps[i].transition) and
  3267. (((i=0) and (leaps[i].change>0)) or
  3268. (leaps[i].change>leaps[i-1].change)) then
  3269. begin
  3270. leap_hit:=1;
  3271. while (i>0) and
  3272. (leaps[i].transition=leaps[i-1].transition+1) and
  3273. (leaps[i].change=leaps[i-1].change+1) do
  3274. begin
  3275. inc(leap_hit);
  3276. dec(i);
  3277. end;
  3278. end;
  3279. end;
  3280. procedure GetLocalTimezone(timer:longint);
  3281. var
  3282. lc,lh : longint;
  3283. begin
  3284. GetLocalTimezone(timer,lc,lh);
  3285. end;
  3286. procedure ReadTimezoneFile(fn:string);
  3287. procedure decode(var l:longint);
  3288. var
  3289. k : longint;
  3290. p : pbyte;
  3291. begin
  3292. p:=pbyte(@l);
  3293. if (p[0] and (1 shl 7))<>0 then
  3294. k:=not 0
  3295. else
  3296. k:=0;
  3297. k:=(k shl 8) or p[0];
  3298. k:=(k shl 8) or p[1];
  3299. k:=(k shl 8) or p[2];
  3300. k:=(k shl 8) or p[3];
  3301. l:=k;
  3302. end;
  3303. var
  3304. f : longint;
  3305. tzdir : string;
  3306. tzhead : ttzhead;
  3307. i : longint;
  3308. chars : longint;
  3309. buf : pbyte;
  3310. begin
  3311. if fn='' then
  3312. fn:='localtime';
  3313. if fn[1]<>'/' then
  3314. begin
  3315. tzdir:=getenv('TZDIR');
  3316. if tzdir='' then
  3317. tzdir:='/usr/share/zoneinfo';
  3318. if tzdir[length(tzdir)]<>'/' then
  3319. tzdir:=tzdir+'/';
  3320. fn:=tzdir+fn;
  3321. end;
  3322. f:=fdopen(fn,Open_RdOnly);
  3323. if f<0 then
  3324. exit;
  3325. i:=fdread(f,tzhead,sizeof(tzhead));
  3326. if i<>sizeof(tzhead) then
  3327. exit;
  3328. decode(tzhead.tzh_timecnt);
  3329. decode(tzhead.tzh_typecnt);
  3330. decode(tzhead.tzh_charcnt);
  3331. decode(tzhead.tzh_leapcnt);
  3332. decode(tzhead.tzh_ttisstdcnt);
  3333. decode(tzhead.tzh_ttisgmtcnt);
  3334. num_transitions:=tzhead.tzh_timecnt;
  3335. num_types:=tzhead.tzh_typecnt;
  3336. chars:=tzhead.tzh_charcnt;
  3337. reallocmem(transitions,num_transitions*sizeof(longint));
  3338. reallocmem(type_idxs,num_transitions);
  3339. reallocmem(types,num_types*sizeof(tttinfo));
  3340. reallocmem(zone_names,chars);
  3341. reallocmem(leaps,num_leaps*sizeof(tleap));
  3342. fdread(f,transitions^,num_transitions*4);
  3343. fdread(f,type_idxs^,num_transitions);
  3344. for i:=0 to num_transitions-1 do
  3345. decode(transitions[i]);
  3346. for i:=0 to num_types-1 do
  3347. begin
  3348. fdread(f,types[i].offset,4);
  3349. fdread(f,types[i].isdst,1);
  3350. fdread(f,types[i].idx,1);
  3351. decode(types[i].offset);
  3352. types[i].isstd:=0;
  3353. types[i].isgmt:=0;
  3354. end;
  3355. fdread(f,zone_names^,chars);
  3356. for i:=0 to num_leaps-1 do
  3357. begin
  3358. fdread(f,leaps[i].transition,4);
  3359. fdread(f,leaps[i].change,4);
  3360. decode(leaps[i].transition);
  3361. decode(leaps[i].change);
  3362. end;
  3363. getmem(buf,tzhead.tzh_ttisstdcnt);
  3364. fdread(f,buf^,tzhead.tzh_ttisstdcnt);
  3365. for i:=0 to tzhead.tzh_ttisstdcnt-1 do
  3366. types[i].isstd:=byte(buf[i]<>0);
  3367. freemem(buf);
  3368. getmem(buf,tzhead.tzh_ttisgmtcnt);
  3369. fdread(f,buf^,tzhead.tzh_ttisgmtcnt);
  3370. for i:=0 to tzhead.tzh_ttisgmtcnt-1 do
  3371. types[i].isgmt:=byte(buf[i]<>0);
  3372. freemem(buf);
  3373. fdclose(f);
  3374. end;
  3375. Const
  3376. // Debian system; contains location of timezone file.
  3377. TimeZoneLocationFile = '/etc/timezone';
  3378. // SuSE has link in /usr/lib/zoneinfo/localtime to /etc/localtime
  3379. // RedHat uses /etc/localtime
  3380. TimeZoneFile = '/usr/lib/zoneinfo/localtime';
  3381. AltTimeZoneFile = '/etc/localtime';
  3382. function GetTimezoneFile:string;
  3383. var
  3384. f,len : longint;
  3385. s : string;
  3386. info : stat;
  3387. begin
  3388. GetTimezoneFile:='';
  3389. f:=fdopen(TimeZoneLocationFile,Open_RdOnly);
  3390. if f>0 then
  3391. begin
  3392. len:=fdread(f,s[1],high(s));
  3393. s[0]:=chr(len);
  3394. len:=pos(#10,s);
  3395. if len<>0 then
  3396. s[0]:=chr(len-1);
  3397. fdclose(f);
  3398. GetTimezoneFile:=s;
  3399. end
  3400. // Try SuSE
  3401. else if fstat(TimeZoneFile,info) then
  3402. GetTimeZoneFile:=TimeZoneFile
  3403. // Try RedHat
  3404. else If fstat(AltTimeZoneFile,Info) then
  3405. GetTimeZoneFile:=AltTimeZoneFile;
  3406. end;
  3407. procedure InitLocalTime;
  3408. begin
  3409. ReadTimezoneFile(GetTimezoneFile);
  3410. GetLocalTimezone(GetTimeOfDay);
  3411. end;
  3412. procedure DoneLocalTime;
  3413. begin
  3414. if assigned(transitions) then
  3415. freemem(transitions);
  3416. if assigned(type_idxs) then
  3417. freemem(type_idxs);
  3418. if assigned(types) then
  3419. freemem(types);
  3420. if assigned(zone_names) then
  3421. freemem(zone_names);
  3422. if assigned(leaps) then
  3423. freemem(leaps);
  3424. num_transitions:=0;
  3425. num_leaps:=0;
  3426. num_types:=0;
  3427. end;
  3428. {******************************************************************************
  3429. FileSystem calls
  3430. ******************************************************************************}
  3431. Function fdOpen(pathname:string;flags:longint):longint;
  3432. begin
  3433. pathname:=pathname+#0;
  3434. fdOpen:=Sys_Open(@pathname[1],flags,438);
  3435. LinuxError:=Errno;
  3436. end;
  3437. Function fdOpen(pathname:string;flags,mode:longint):longint;
  3438. begin
  3439. pathname:=pathname+#0;
  3440. fdOpen:=Sys_Open(@pathname[1],flags,mode);
  3441. LinuxError:=Errno;
  3442. end;
  3443. Function fdOpen(pathname:pchar;flags:longint):longint;
  3444. begin
  3445. fdOpen:=Sys_Open(pathname,flags,0);
  3446. LinuxError:=Errno;
  3447. end;
  3448. Function fdOpen(pathname:pchar;flags,mode:longint):longint;
  3449. begin
  3450. fdOpen:=Sys_Open(pathname,flags,mode);
  3451. LinuxError:=Errno;
  3452. end;
  3453. Function fdClose(fd:longint):boolean;
  3454. begin
  3455. fdClose:=(Sys_Close(fd)=0);
  3456. LinuxError:=Errno;
  3457. end;
  3458. Function fdRead(fd:longint;var buf;size:longint):longint;
  3459. begin
  3460. fdRead:=Sys_Read(fd,pchar(@buf),size);
  3461. LinuxError:=Errno;
  3462. end;
  3463. Function fdWrite(fd:longint;const buf;size:longint):longint;
  3464. begin
  3465. fdWrite:=Sys_Write(fd,pchar(@buf),size);
  3466. LinuxError:=Errno;
  3467. end;
  3468. Function fdSeek (fd,pos,seektype :longint): longint;
  3469. {
  3470. Do a Seek on a file descriptor fd to position pos, starting from seektype
  3471. }
  3472. begin
  3473. fdseek:=Sys_LSeek (fd,pos,seektype);
  3474. LinuxError:=Errno;
  3475. end;
  3476. {$ifdef BSD}
  3477. Function Fcntl(Fd:longint;Cmd:longint):longint;
  3478. {
  3479. Read or manipulate a file.(See also fcntl (2) )
  3480. Possible values for Cmd are :
  3481. F_GetFd,F_GetFl,F_GetOwn
  3482. Errors are reported in Linuxerror;
  3483. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  3484. }
  3485. begin
  3486. if (cmd in [F_GetFd,F_GetFl,F_GetOwn]) then
  3487. begin
  3488. Linuxerror:=sys_fcntl(fd,cmd,0);
  3489. if linuxerror=-1 then
  3490. begin
  3491. linuxerror:=errno;
  3492. fcntl:=0;
  3493. end
  3494. else
  3495. begin
  3496. fcntl:=linuxerror;
  3497. linuxerror:=0;
  3498. end;
  3499. end
  3500. else
  3501. begin
  3502. linuxerror:=Sys_einval;
  3503. Fcntl:=0;
  3504. end;
  3505. end;
  3506. Procedure Fcntl(Fd:longint;Cmd:longint;Arg:Longint);
  3507. {
  3508. Read or manipulate a file. (See also fcntl (2) )
  3509. Possible values for Cmd are :
  3510. F_setFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkW,F_SetOwn;
  3511. Errors are reported in Linuxerror;
  3512. If Cmd is different from the allowed values, linuxerror=Sys_eninval.
  3513. F_DupFD is not allowed, due to the structure of Files in Pascal.
  3514. }
  3515. begin
  3516. if (cmd in [F_SetFd,F_SetFl,F_GetLk,F_SetLk,F_SetLkw,F_SetOwn]) then
  3517. begin
  3518. sys_fcntl(fd,cmd,arg);
  3519. LinuxError:=ErrNo;
  3520. end
  3521. else
  3522. linuxerror:=Sys_einval;
  3523. end;
  3524. {$endif}
  3525. Function Fcntl(var Fd:Text;Cmd:longint):longint;
  3526. begin
  3527. Fcntl := Fcntl(textrec(Fd).handle, Cmd);
  3528. end;
  3529. Procedure Fcntl(var Fd:Text;Cmd,Arg:Longint);
  3530. begin
  3531. Fcntl(textrec(Fd).handle, Cmd, Arg);
  3532. end;
  3533. Function Flock (var T : text;mode : longint) : boolean;
  3534. begin
  3535. Flock:=Flock(TextRec(T).Handle,mode);
  3536. end;
  3537. Function Flock (var F : File;mode : longint) : boolean;
  3538. begin
  3539. Flock:=Flock(FileRec(F).Handle,mode);
  3540. end;
  3541. Function FStat(Path:Pathstr;Var Info:stat):Boolean;
  3542. {
  3543. Get all information on a file, and return it in Info.
  3544. }
  3545. begin
  3546. path:=path+#0;
  3547. FStat:=(Sys_stat(@(path[1]),Info)=0);
  3548. LinuxError:=errno;
  3549. end;
  3550. Function FStat(var F:Text;Var Info:stat):Boolean;
  3551. {
  3552. Get all information on a text file, and return it in info.
  3553. }
  3554. begin
  3555. FStat:=Fstat(TextRec(F).Handle,INfo);
  3556. end;
  3557. Function FStat(var F:File;Var Info:stat):Boolean;
  3558. {
  3559. Get all information on a untyped file, and return it in info.
  3560. }
  3561. begin
  3562. FStat:=Fstat(FileRec(F).Handle,Info);
  3563. end;
  3564. Function SymLink(OldPath,newPath:pathstr):boolean;
  3565. {
  3566. Proceduces a soft link from new to old.
  3567. }
  3568. begin
  3569. oldpath:=oldpath+#0;
  3570. newpath:=newpath+#0;
  3571. Symlink:=Sys_symlink(pchar(@(oldpath[1])),pchar(@(newpath[1])))=0;
  3572. linuxerror:=errno;
  3573. end;
  3574. Function ReadLink(name,linkname:pchar;maxlen:longint):longint;
  3575. {
  3576. Read a link (where it points to)
  3577. }
  3578. begin
  3579. Readlink:=Sys_readlink(Name,LinkName,maxlen);
  3580. linuxerror:=errno;
  3581. end;
  3582. Function ReadLink(Name:pathstr):pathstr;
  3583. {
  3584. Read a link (where it points to)
  3585. }
  3586. var
  3587. LinkName : pathstr;
  3588. i : longint;
  3589. begin
  3590. Name:=Name+#0;
  3591. i:=ReadLink(@Name[1],@LinkName[1],high(linkname));
  3592. if i>0 then
  3593. begin
  3594. linkname[0]:=chr(i);
  3595. ReadLink:=LinkName;
  3596. end
  3597. else
  3598. ReadLink:='';
  3599. end;
  3600. Function UnLink(Path:pathstr):boolean;
  3601. {
  3602. Removes the file in 'Path' (that is, it decreases the link count with one.
  3603. if the link count is zero, the file is removed from the disk.
  3604. }
  3605. begin
  3606. path:=path+#0;
  3607. Unlink:=Sys_unlink(pchar(@(path[1])))=0;
  3608. linuxerror:=errno;
  3609. end;
  3610. Function UnLink(Path:pchar):Boolean;
  3611. {
  3612. Removes the file in 'Path' (that is, it decreases the link count with one.
  3613. if the link count is zero, the file is removed from the disk.
  3614. }
  3615. begin
  3616. Unlink:=(Sys_unlink(path)=0);
  3617. linuxerror:=errno;
  3618. end;
  3619. Function FRename (OldName,NewName : Pchar) : Boolean;
  3620. begin
  3621. FRename:=Sys_rename(OldName,NewName)=0;
  3622. LinuxError:=Errno;
  3623. end;
  3624. Function FRename (OldName,NewName : String) : Boolean;
  3625. begin
  3626. OldName:=OldName+#0;
  3627. NewName:=NewName+#0;
  3628. FRename:=FRename (@OldName[1],@NewName[1]);
  3629. end;
  3630. Function Dup(var oldfile,newfile:text):Boolean;
  3631. {
  3632. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  3633. oldfile.
  3634. After which the two textfiles are, in effect, the same, except
  3635. that they don't share the same buffer, and don't share the same
  3636. close_on_exit flag.
  3637. }
  3638. begin
  3639. flush(oldfile);{ We cannot share buffers, so we flush them. }
  3640. textrec(newfile):=textrec(oldfile);
  3641. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  3642. Dup:=Dup(textrec(oldfile).handle,textrec(newfile).handle);
  3643. end;
  3644. Function Dup(var oldfile,newfile:file):Boolean;
  3645. {
  3646. Copies the filedescriptor oldfile to newfile
  3647. }
  3648. begin
  3649. filerec(newfile):=filerec(oldfile);
  3650. Dup:=Dup(filerec(oldfile).handle,filerec(newfile).handle);
  3651. end;
  3652. Function Dup2(var oldfile,newfile:text):Boolean;
  3653. {
  3654. Copies the filedescriptor oldfile to newfile, after flushing the buffer of
  3655. oldfile. It closes newfile if it was still open.
  3656. After which the two textfiles are, in effect, the same, except
  3657. that they don't share the same buffer, and don't share the same
  3658. close_on_exit flag.
  3659. }
  3660. var
  3661. tmphandle : word;
  3662. begin
  3663. case TextRec(oldfile).mode of
  3664. fmOutput, fmInOut, fmAppend :
  3665. flush(oldfile);{ We cannot share buffers, so we flush them. }
  3666. end;
  3667. case TextRec(newfile).mode of
  3668. fmOutput, fmInOut, fmAppend :
  3669. flush(newfile);
  3670. end;
  3671. tmphandle:=textrec(newfile).handle;
  3672. textrec(newfile):=textrec(oldfile);
  3673. textrec(newfile).handle:=tmphandle;
  3674. textrec(newfile).bufptr:=@(textrec(newfile).buffer);{ No shared buffer. }
  3675. Dup2:=Dup2(textrec(oldfile).handle,textrec(newfile).handle);
  3676. end;
  3677. Function Dup2(var oldfile,newfile:file):Boolean;
  3678. {
  3679. Copies the filedescriptor oldfile to newfile
  3680. }
  3681. begin
  3682. filerec(newfile):=filerec(oldfile);
  3683. Dup2:=Dup2(filerec(oldfile).handle,filerec(newfile).handle);
  3684. end;
  3685. Function Select(N:longint;readfds,writefds,exceptfds:PFDSet;TimeOut:Longint):longint;
  3686. {
  3687. Select checks whether the file descriptor sets in readfs/writefs/exceptfs
  3688. have changed.
  3689. This function allows specification of a timeout as a longint.
  3690. }
  3691. var
  3692. p : PTimeVal;
  3693. tv : TimeVal;
  3694. begin
  3695. if TimeOut=-1 then
  3696. p:=nil
  3697. else
  3698. begin
  3699. tv.Sec:=Timeout div 1000;
  3700. tv.Usec:=(Timeout mod 1000)*1000;
  3701. p:=@tv;
  3702. end;
  3703. Select:=Select(N,Readfds,WriteFds,ExceptFds,p);
  3704. end;
  3705. Function SelectText(var T:Text;TimeOut :PTimeval):Longint;
  3706. Var
  3707. F:FDSet;
  3708. begin
  3709. if textrec(t).mode=fmclosed then
  3710. begin
  3711. LinuxError:=Sys_EBADF;
  3712. exit(-1);
  3713. end;
  3714. FD_Zero(f);
  3715. FD_Set(textrec(T).handle,f);
  3716. if textrec(T).mode=fminput then
  3717. SelectText:=select(textrec(T).handle+1,@f,nil,nil,TimeOut)
  3718. else
  3719. SelectText:=select(textrec(T).handle+1,nil,@f,nil,TimeOut);
  3720. end;
  3721. Function SelectText(var T:Text;TimeOut :Longint):Longint;
  3722. var
  3723. p : PTimeVal;
  3724. tv : TimeVal;
  3725. begin
  3726. if TimeOut=-1 then
  3727. p:=nil
  3728. else
  3729. begin
  3730. tv.Sec:=Timeout div 1000;
  3731. tv.Usec:=(Timeout mod 1000)*1000;
  3732. p:=@tv;
  3733. end;
  3734. SelectText:=SelectText(T,p);
  3735. end;
  3736. {******************************************************************************
  3737. Directory
  3738. ******************************************************************************}
  3739. Function OpenDir(F:String):PDir;
  3740. begin
  3741. F:=F+#0;
  3742. OpenDir:=OpenDir(@F[1]);
  3743. LinuxError:=ErrNo;
  3744. end;
  3745. {$ifndef newreaddir}
  3746. procedure SeekDir(p:pdir;off:longint);
  3747. begin
  3748. if p=nil then
  3749. begin
  3750. errno:=Sys_EBADF;
  3751. exit;
  3752. end;
  3753. {$ifndef bsd}
  3754. p^.nextoff:=Sys_lseek(p^.fd,off,seek_set);
  3755. {$endif}
  3756. p^.size:=0;
  3757. p^.loc:=0;
  3758. end;
  3759. function TellDir(p:pdir):longint;
  3760. begin
  3761. if p=nil then
  3762. begin
  3763. errno:=Sys_EBADF;
  3764. telldir:=-1;
  3765. exit;
  3766. end;
  3767. telldir:=Sys_lseek(p^.fd,0,seek_cur)
  3768. { We could try to use the nextoff field here, but on my 1.2.13
  3769. kernel, this gives nothing... This may have to do with
  3770. the readdir implementation of libc... I also didn't find any trace of
  3771. the field in the kernel code itself, So I suspect it is an artifact of libc.
  3772. Michael. }
  3773. end;
  3774. {$endif}
  3775. Function ReadDir(P:pdir):pdirent;
  3776. begin
  3777. ReadDir:=Sys_ReadDir(p);
  3778. LinuxError:=Errno;
  3779. end;
  3780. {******************************************************************************
  3781. Pipes/Fifo
  3782. ******************************************************************************}
  3783. Procedure OpenPipe(var F:Text);
  3784. begin
  3785. case textrec(f).mode of
  3786. fmoutput :
  3787. if textrec(f).userdata[1]<>P_OUT then
  3788. textrec(f).mode:=fmclosed;
  3789. fminput :
  3790. if textrec(f).userdata[1]<>P_IN then
  3791. textrec(f).mode:=fmclosed;
  3792. else
  3793. textrec(f).mode:=fmclosed;
  3794. end;
  3795. end;
  3796. Procedure IOPipe(var F:text);
  3797. begin
  3798. case textrec(f).mode of
  3799. fmoutput :
  3800. begin
  3801. { first check if we need something to write, else we may
  3802. get a SigPipe when Close() is called (PFV) }
  3803. if textrec(f).bufpos>0 then
  3804. Sys_write(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufpos);
  3805. end;
  3806. fminput :
  3807. textrec(f).bufend:=Sys_read(textrec(f).handle,pchar(textrec(f).bufptr),textrec(f).bufsize);
  3808. end;
  3809. textrec(f).bufpos:=0;
  3810. end;
  3811. Procedure FlushPipe(var F:Text);
  3812. begin
  3813. if (textrec(f).mode=fmoutput) and (textrec(f).bufpos<>0) then
  3814. IOPipe(f);
  3815. textrec(f).bufpos:=0;
  3816. end;
  3817. Procedure ClosePipe(var F:text);
  3818. begin
  3819. textrec(f).mode:=fmclosed;
  3820. Sys_close(textrec(f).handle);
  3821. end;
  3822. Function AssignPipe(var pipe_in,pipe_out:text):boolean;
  3823. {
  3824. Sets up a pair of file variables, which act as a pipe. The first one can
  3825. be read from, the second one can be written to.
  3826. If the operation was unsuccesful, linuxerror is set.
  3827. }
  3828. var
  3829. f_in,f_out : longint;
  3830. begin
  3831. if not AssignPipe(f_in,f_out) then
  3832. begin
  3833. AssignPipe:=false;
  3834. exit;
  3835. end;
  3836. { Set up input }
  3837. Assign(Pipe_in,'');
  3838. Textrec(Pipe_in).Handle:=f_in;
  3839. Textrec(Pipe_in).Mode:=fmInput;
  3840. Textrec(Pipe_in).userdata[1]:=P_IN;
  3841. TextRec(Pipe_in).OpenFunc:=@OpenPipe;
  3842. TextRec(Pipe_in).InOutFunc:=@IOPipe;
  3843. TextRec(Pipe_in).FlushFunc:=@FlushPipe;
  3844. TextRec(Pipe_in).CloseFunc:=@ClosePipe;
  3845. { Set up output }
  3846. Assign(Pipe_out,'');
  3847. Textrec(Pipe_out).Handle:=f_out;
  3848. Textrec(Pipe_out).Mode:=fmOutput;
  3849. Textrec(Pipe_out).userdata[1]:=P_OUT;
  3850. TextRec(Pipe_out).OpenFunc:=@OpenPipe;
  3851. TextRec(Pipe_out).InOutFunc:=@IOPipe;
  3852. TextRec(Pipe_out).FlushFunc:=@FlushPipe;
  3853. TextRec(Pipe_out).CloseFunc:=@ClosePipe;
  3854. AssignPipe:=true;
  3855. end;
  3856. Function AssignPipe(var pipe_in,pipe_out:file):boolean;
  3857. {
  3858. Sets up a pair of file variables, which act as a pipe. The first one can
  3859. be read from, the second one can be written to.
  3860. If the operation was unsuccesful, linuxerror is set.
  3861. }
  3862. var
  3863. f_in,f_out : longint;
  3864. begin
  3865. if not AssignPipe(f_in,f_out) then
  3866. begin
  3867. AssignPipe:=false;
  3868. exit;
  3869. end;
  3870. { Set up input }
  3871. Assign(Pipe_in,'');
  3872. Filerec(Pipe_in).Handle:=f_in;
  3873. Filerec(Pipe_in).Mode:=fmInput;
  3874. Filerec(Pipe_in).recsize:=1;
  3875. Filerec(Pipe_in).userdata[1]:=P_IN;
  3876. { Set up output }
  3877. Assign(Pipe_out,'');
  3878. Filerec(Pipe_out).Handle:=f_out;
  3879. Filerec(Pipe_out).Mode:=fmoutput;
  3880. Filerec(Pipe_out).recsize:=1;
  3881. Filerec(Pipe_out).userdata[1]:=P_OUT;
  3882. AssignPipe:=true;
  3883. end;
  3884. Procedure PCloseText(Var F:text);
  3885. {
  3886. May not use @PClose due overloading
  3887. }
  3888. begin
  3889. PClose(f);
  3890. end;
  3891. Procedure POpen(var F:text;const Prog:String;rw:char);
  3892. {
  3893. Starts the program in 'Prog' and makes it's input or out put the
  3894. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  3895. F, will be read from stdin by the program in 'Prog'. The inverse is true
  3896. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  3897. read from 'f'.
  3898. }
  3899. var
  3900. pipi,
  3901. pipo : text;
  3902. pid : longint;
  3903. pl : ^longint;
  3904. pp : ppchar;
  3905. begin
  3906. LinuxError:=0;
  3907. rw:=upcase(rw);
  3908. if not (rw in ['R','W']) then
  3909. begin
  3910. LinuxError:=Sys_enoent;
  3911. exit;
  3912. end;
  3913. AssignPipe(pipi,pipo);
  3914. if Linuxerror<>0 then
  3915. exit;
  3916. pid:=fork;
  3917. if linuxerror<>0 then
  3918. begin
  3919. close(pipi);
  3920. close(pipo);
  3921. exit;
  3922. end;
  3923. if pid=0 then
  3924. begin
  3925. {$ifdef BSD} // FreeBSD checked only
  3926. { We're in the child }
  3927. close(pipi);
  3928. if textrec(pipo).handle<>textrec(output).handle Then
  3929. begin
  3930. dup2(textrec(pipo).handle,textrec(output).handle);
  3931. if rw='W' Then
  3932. dup2(textrec(output).handle,textrec(input).handle);
  3933. end
  3934. else
  3935. if (rw='W') and (textrec(pipi).handle<>textrec(input).handle) then
  3936. dup2(textrec(output).handle,textrec(input).handle);
  3937. close(pipo);
  3938. if linuxerror<>0 then
  3939. halt(127);
  3940. pp:=createshellargv(prog);
  3941. Execve(pp^,pp,envp);
  3942. halt(127);
  3943. end
  3944. {$else}
  3945. { We're in the child }
  3946. if rw='W' then
  3947. begin
  3948. close(pipo);
  3949. dup2(pipi,input);
  3950. close(pipi);
  3951. if linuxerror<>0 then
  3952. halt(127);
  3953. end
  3954. else
  3955. begin
  3956. close(pipi);
  3957. dup2(pipo,output);
  3958. close(pipo);
  3959. if linuxerror<>0 then
  3960. halt(127);
  3961. end;
  3962. pp:=createshellargv(prog);
  3963. Execve(pp^,pp,envp);
  3964. halt(127);
  3965. end
  3966. {$endif}
  3967. else
  3968. begin
  3969. { We're in the parent }
  3970. if rw='W' then
  3971. begin
  3972. close(pipi);
  3973. f:=pipo;
  3974. textrec(f).bufptr:=@textrec(f).buffer;
  3975. end
  3976. else
  3977. begin
  3978. close(pipo);
  3979. f:=pipi;
  3980. textrec(f).bufptr:=@textrec(f).buffer;
  3981. end;
  3982. {Save the process ID - needed when closing }
  3983. pl:=plongint(@(textrec(f).userdata[2]));
  3984. pl^:=pid;
  3985. textrec(f).closefunc:=@PCloseText;
  3986. end;
  3987. end;
  3988. Procedure POpen(var F:file;const Prog:String;rw:char);
  3989. {
  3990. Starts the program in 'Prog' and makes it's input or out put the
  3991. other end of a pipe. If rw is 'w' or 'W', then whatever is written to
  3992. F, will be read from stdin by the program in 'Prog'. The inverse is true
  3993. for 'r' or 'R' : whatever the program in 'Prog' writes to stdout, can be
  3994. read from 'f'.
  3995. }
  3996. var
  3997. pipi,
  3998. pipo : file;
  3999. pid : longint;
  4000. pl : ^longint;
  4001. p,pp : ppchar;
  4002. temp : string[255];
  4003. begin
  4004. LinuxError:=0;
  4005. rw:=upcase(rw);
  4006. if not (rw in ['R','W']) then
  4007. begin
  4008. LinuxError:=Sys_enoent;
  4009. exit;
  4010. end;
  4011. AssignPipe(pipi,pipo);
  4012. if Linuxerror<>0 then
  4013. exit;
  4014. pid:=fork;
  4015. if linuxerror<>0 then
  4016. begin
  4017. close(pipi);
  4018. close(pipo);
  4019. exit;
  4020. end;
  4021. if pid=0 then
  4022. begin
  4023. { We're in the child }
  4024. if rw='W' then
  4025. begin
  4026. close(pipo);
  4027. dup2(filerec(pipi).handle,stdinputhandle);
  4028. close(pipi);
  4029. if linuxerror<>0 then
  4030. halt(127);
  4031. end
  4032. else
  4033. begin
  4034. close(pipi);
  4035. dup2(filerec(pipo).handle,stdoutputhandle);
  4036. close(pipo);
  4037. if linuxerror<>0 then
  4038. halt(127);
  4039. end;
  4040. getmem(pp,sizeof(pchar)*4);
  4041. temp:='/bin/sh'#0'-c'#0+prog+#0;
  4042. p:=pp;
  4043. p^:=@temp[1];
  4044. inc(p);
  4045. p^:=@temp[9];
  4046. inc(p);
  4047. p^:=@temp[12];
  4048. inc(p);
  4049. p^:=Nil;
  4050. Execve('/bin/sh',pp,envp);
  4051. halt(127);
  4052. end
  4053. else
  4054. begin
  4055. { We're in the parent }
  4056. if rw='W' then
  4057. begin
  4058. close(pipi);
  4059. f:=pipo;
  4060. end
  4061. else
  4062. begin
  4063. close(pipo);
  4064. f:=pipi;
  4065. end;
  4066. {Save the process ID - needed when closing }
  4067. pl:=plongint(@(filerec(f).userdata[2]));
  4068. pl^:=pid;
  4069. end;
  4070. end;
  4071. Function AssignStream(Var StreamIn,Streamout:text;Const Prog:String) : longint;
  4072. {
  4073. Starts the program in 'Prog' and makes its input and output the
  4074. other end of two pipes, which are the stdin and stdout of a program
  4075. specified in 'Prog'.
  4076. streamout can be used to write to the program, streamin can be used to read
  4077. the output of the program. See the following diagram :
  4078. Parent Child
  4079. STreamout --> Input
  4080. Streamin <-- Output
  4081. Return value is the process ID of the process being spawned, or -1 in case of failure.
  4082. }
  4083. var
  4084. pipi,
  4085. pipo : text;
  4086. pid : longint;
  4087. pl : ^Longint;
  4088. begin
  4089. LinuxError:=0;
  4090. AssignStream:=-1;
  4091. AssignPipe(streamin,pipo);
  4092. if Linuxerror<>0 then
  4093. exit;
  4094. AssignPipe(pipi,streamout);
  4095. if Linuxerror<>0 then
  4096. exit;
  4097. pid:=fork;
  4098. if linuxerror<>0 then
  4099. begin
  4100. close(pipi);
  4101. close(pipo);
  4102. close (streamin);
  4103. close (streamout);
  4104. exit;
  4105. end;
  4106. if pid=0 then
  4107. begin
  4108. { We're in the child }
  4109. { Close what we don't need }
  4110. close(streamout);
  4111. close(streamin);
  4112. dup2(pipi,input);
  4113. if linuxerror<>0 then
  4114. halt(127);
  4115. close(pipi);
  4116. dup2(pipo,output);
  4117. if linuxerror<>0 then
  4118. halt (127);
  4119. close(pipo);
  4120. Execl(Prog);
  4121. halt(127);
  4122. end
  4123. else
  4124. begin
  4125. { we're in the parent}
  4126. close(pipo);
  4127. close(pipi);
  4128. {Save the process ID - needed when closing }
  4129. pl:=plongint(@(textrec(StreamIn).userdata[2]));
  4130. pl^:=pid;
  4131. textrec(StreamIn).closefunc:=@PCloseText;
  4132. {Save the process ID - needed when closing }
  4133. pl:=plongint(@(textrec(StreamOut).userdata[2]));
  4134. pl^:=pid;
  4135. textrec(StreamOut).closefunc:=@PCloseText;
  4136. AssignStream:=Pid;
  4137. end;
  4138. end;
  4139. function AssignStream(var StreamIn, StreamOut, StreamErr: Text; const prog: String): LongInt;
  4140. {
  4141. Starts the program in 'prog' and makes its input, output and error output the
  4142. other end of three pipes, which are the stdin, stdout and stderr of a program
  4143. specified in 'prog'.
  4144. StreamOut can be used to write to the program, StreamIn can be used to read
  4145. the output of the program, StreamErr reads the error output of the program.
  4146. See the following diagram :
  4147. Parent Child
  4148. StreamOut --> StdIn (input)
  4149. StreamIn <-- StdOut (output)
  4150. StreamErr <-- StdErr (error output)
  4151. }
  4152. var
  4153. PipeIn, PipeOut, PipeErr: text;
  4154. pid: LongInt;
  4155. pl: ^LongInt;
  4156. begin
  4157. LinuxError := 0;
  4158. AssignStream := -1;
  4159. // Assign pipes
  4160. AssignPipe(StreamIn, PipeOut);
  4161. if LinuxError <> 0 then exit;
  4162. AssignPipe(StreamErr, PipeErr);
  4163. if LinuxError <> 0 then begin
  4164. Close(StreamIn);
  4165. Close(PipeOut);
  4166. exit;
  4167. end;
  4168. AssignPipe(PipeIn, StreamOut);
  4169. if LinuxError <> 0 then begin
  4170. Close(StreamIn);
  4171. Close(PipeOut);
  4172. Close(StreamErr);
  4173. Close(PipeErr);
  4174. exit;
  4175. end;
  4176. // Fork
  4177. pid := Fork;
  4178. if LinuxError <> 0 then begin
  4179. Close(StreamIn);
  4180. Close(PipeOut);
  4181. Close(StreamErr);
  4182. Close(PipeErr);
  4183. Close(PipeIn);
  4184. Close(StreamOut);
  4185. exit;
  4186. end;
  4187. if pid = 0 then begin
  4188. // *** We are in the child ***
  4189. // Close what we don not need
  4190. Close(StreamOut);
  4191. Close(StreamIn);
  4192. Close(StreamErr);
  4193. // Connect pipes
  4194. dup2(PipeIn, Input);
  4195. if LinuxError <> 0 then Halt(127);
  4196. Close(PipeIn);
  4197. dup2(PipeOut, Output);
  4198. if LinuxError <> 0 then Halt(127);
  4199. Close(PipeOut);
  4200. dup2(PipeErr, StdErr);
  4201. if LinuxError <> 0 then Halt(127);
  4202. Close(PipeErr);
  4203. // Execute program
  4204. Execl(Prog);
  4205. Halt(127);
  4206. end else begin
  4207. // *** We are in the parent ***
  4208. Close(PipeErr);
  4209. Close(PipeOut);
  4210. Close(PipeIn);
  4211. // Save the process ID - needed when closing
  4212. pl := plongint(@(TextRec(StreamIn).userdata[2]));
  4213. pl^ := pid;
  4214. TextRec(StreamIn).closefunc := @PCloseText;
  4215. // Save the process ID - needed when closing
  4216. pl := plongint(@(TextRec(StreamOut).userdata[2]));
  4217. pl^ := pid;
  4218. TextRec(StreamOut).closefunc := @PCloseText;
  4219. // Save the process ID - needed when closing
  4220. pl := plongint(@(TextRec(StreamErr).userdata[2]));
  4221. pl^ := pid;
  4222. TextRec(StreamErr).closefunc := @PCloseText;
  4223. AssignStream := pid;
  4224. end;
  4225. end;
  4226. {******************************************************************************
  4227. General information calls
  4228. ******************************************************************************}
  4229. Function GetEnv(P:string):Pchar;
  4230. {
  4231. Searches the environment for a string with name p and
  4232. returns a pchar to it's value.
  4233. A pchar is used to accomodate for strings of length > 255
  4234. }
  4235. var
  4236. ep : ppchar;
  4237. found : boolean;
  4238. Begin
  4239. p:=p+'='; {Else HOST will also find HOSTNAME, etc}
  4240. ep:=envp;
  4241. found:=false;
  4242. if ep<>nil then
  4243. begin
  4244. while (not found) and (ep^<>nil) do
  4245. begin
  4246. if strlcomp(@p[1],(ep^),length(p))=0 then
  4247. found:=true
  4248. else
  4249. inc(ep);
  4250. end;
  4251. end;
  4252. if found then
  4253. getenv:=ep^+length(p)
  4254. else
  4255. getenv:=nil;
  4256. end;
  4257. {$ifndef bsd}
  4258. Function GetDomainName:String;
  4259. {
  4260. Get machines domain name. Returns empty string if not set.
  4261. }
  4262. Var
  4263. Sysn : utsname;
  4264. begin
  4265. Uname(Sysn);
  4266. linuxerror:=errno;
  4267. If linuxerror<>0 then
  4268. getdomainname:=''
  4269. else
  4270. getdomainname:=strpas(@Sysn.domainname[0]);
  4271. end;
  4272. Function GetHostName:String;
  4273. {
  4274. Get machines name. Returns empty string if not set.
  4275. }
  4276. Var
  4277. Sysn : utsname;
  4278. begin
  4279. uname(Sysn);
  4280. linuxerror:=errno;
  4281. If linuxerror<>0 then
  4282. gethostname:=''
  4283. else
  4284. gethostname:=strpas(@Sysn.nodename[0]);
  4285. end;
  4286. {$endif}
  4287. {******************************************************************************
  4288. Signal handling calls
  4289. ******************************************************************************}
  4290. procedure SigRaise(sig:integer);
  4291. begin
  4292. Kill(GetPid,Sig);
  4293. end;
  4294. {******************************************************************************
  4295. IOCtl and Termios calls
  4296. ******************************************************************************}
  4297. Function TCGetAttr(fd:longint;var tios:TermIOS):boolean;
  4298. begin
  4299. {$ifndef BSD}
  4300. TCGetAttr:=IOCtl(fd,TCGETS,@tios);
  4301. {$else}
  4302. TCGETAttr:=IoCtl(Fd,TIOCGETA,@tios);
  4303. {$endif}
  4304. end;
  4305. Function TCSetAttr(fd:longint;OptAct:longint;const tios:TermIOS):boolean;
  4306. var
  4307. nr:longint;
  4308. begin
  4309. {$ifndef BSD}
  4310. case OptAct of
  4311. TCSANOW : nr:=TCSETS;
  4312. TCSADRAIN : nr:=TCSETSW;
  4313. TCSAFLUSH : nr:=TCSETSF;
  4314. {$else}
  4315. case OptAct of
  4316. TCSANOW : nr:=TIOCSETA;
  4317. TCSADRAIN : nr:=TIOCSETAW;
  4318. TCSAFLUSH : nr:=TIOCSETAF;
  4319. {$endif}
  4320. else
  4321. begin
  4322. ErrNo:=Sys_EINVAL;
  4323. TCSetAttr:=false;
  4324. exit;
  4325. end;
  4326. end;
  4327. TCSetAttr:=IOCtl(fd,nr,@Tios);
  4328. end;
  4329. Procedure CFSetISpeed(var tios:TermIOS;speed:Cardinal);
  4330. begin
  4331. {$ifndef BSD}
  4332. tios.c_cflag:=Cardinal(tios.c_cflag and cardinal(not CBAUD)) or speed;
  4333. {$else}
  4334. tios.c_ispeed:=speed; {Probably the Bxxxx speed constants}
  4335. {$endif}
  4336. end;
  4337. Procedure CFSetOSpeed(var tios:TermIOS;speed:Cardinal);
  4338. begin
  4339. {$ifndef BSD}
  4340. CFSetISpeed(tios,speed);
  4341. {$else}
  4342. tios.c_ospeed:=speed;
  4343. {$endif}
  4344. end;
  4345. Procedure CFMakeRaw(var tios:TermIOS);
  4346. begin
  4347. {$ifndef BSD}
  4348. with tios do
  4349. begin
  4350. c_iflag:=c_iflag and cardinal(not (IGNBRK or BRKINT or PARMRK or ISTRIP or
  4351. INLCR or IGNCR or ICRNL or IXON));
  4352. c_oflag:=c_oflag and cardinal(not OPOST);
  4353. c_lflag:=c_lflag and cardinal(not (ECHO or ECHONL or ICANON or ISIG or IEXTEN));
  4354. c_cflag:=(c_cflag and cardinal(not (CSIZE or PARENB))) or CS8;
  4355. end;
  4356. {$else}
  4357. with tios do
  4358. begin
  4359. c_iflag:=c_iflag and (not (IMAXBEL or IXOFF or INPCK or BRKINT or
  4360. PARMRK or ISTRIP or INLCR or IGNCR or ICRNL or IXON or
  4361. IGNPAR));
  4362. c_iflag:=c_iflag OR IGNBRK;
  4363. c_oflag:=c_oflag and (not OPOST);
  4364. c_lflag:=c_lflag and (not (ECHO or ECHOE or ECHOK or ECHONL or ICANON or
  4365. ISIG or IEXTEN or NOFLSH or TOSTOP or PENDIN));
  4366. c_cflag:=(c_cflag and (not (CSIZE or PARENB))) or (CS8 OR cread);
  4367. c_cc[VMIN]:=1;
  4368. c_cc[VTIME]:=0;
  4369. end;
  4370. {$endif}
  4371. end;
  4372. Function TCSendBreak(fd,duration:longint):boolean;
  4373. begin
  4374. {$ifndef BSD}
  4375. TCSendBreak:=IOCtl(fd,TCSBRK,pointer(duration));
  4376. {$else}
  4377. TCSendBreak:=IOCtl(fd,TIOCSBRK,0);
  4378. {$endif}
  4379. end;
  4380. Function TCSetPGrp(fd,id:longint):boolean;
  4381. begin
  4382. TCSetPGrp:=IOCtl(fd,TIOCSPGRP,pointer(id));
  4383. end;
  4384. Function TCGetPGrp(fd:longint;var id:longint):boolean;
  4385. begin
  4386. TCGetPGrp:=IOCtl(fd,TIOCGPGRP,@id);
  4387. end;
  4388. Function TCDrain(fd:longint):boolean;
  4389. begin
  4390. {$ifndef BSD}
  4391. TCDrain:=IOCtl(fd,TCSBRK,pointer(1));
  4392. {$else}
  4393. TCDrain:=IOCtl(fd,TIOCDRAIN,0); {Should set timeout to 1 first?}
  4394. {$endif}
  4395. end;
  4396. Function TCFlow(fd,act:longint):boolean;
  4397. begin
  4398. {$ifndef BSD}
  4399. TCFlow:=IOCtl(fd,TCXONC,pointer(act));
  4400. {$else}
  4401. case act OF
  4402. TCOOFF : TCFlow:=Ioctl(fd,TIOCSTOP,0);
  4403. TCOOn : TCFlow:=IOctl(Fd,TIOCStart,0);
  4404. TCIOFF : {N/I}
  4405. end;
  4406. {$endif}
  4407. end;
  4408. Function TCFlush(fd,qsel:longint):boolean;
  4409. begin
  4410. {$ifndef BSD}
  4411. TCFlush:=IOCtl(fd,TCFLSH,pointer(qsel));
  4412. {$else}
  4413. TCFlush:=IOCtl(fd,TIOCFLUSH,pointer(qsel));
  4414. {$endif}
  4415. end;
  4416. Function IsATTY(Handle:Longint):Boolean;
  4417. {
  4418. Check if the filehandle described by 'handle' is a TTY (Terminal)
  4419. }
  4420. var
  4421. t : Termios;
  4422. begin
  4423. IsAtty:=TCGetAttr(Handle,t);
  4424. end;
  4425. Function IsATTY(var f: text):Boolean;
  4426. {
  4427. Idem as previous, only now for text variables.
  4428. }
  4429. begin
  4430. IsATTY:=IsaTTY(textrec(f).handle);
  4431. end;
  4432. function TTYName(Handle:Longint):string;
  4433. {
  4434. Return the name of the current tty described by handle f.
  4435. returns empty string in case of an error.
  4436. }
  4437. {$ifdef BSD}
  4438. var
  4439. mydev,
  4440. myino : cardinal;
  4441. {$else not BSD}
  4442. var
  4443. mydev,
  4444. myino : longint;
  4445. {$endif not BSD}
  4446. st : stat;
  4447. function mysearch(n:string): boolean;
  4448. {searches recursively for the device in the directory given by n,
  4449. returns true if found and sets the name of the device in ttyname}
  4450. var dirstream : pdir;
  4451. d : pdirent;
  4452. name : string;
  4453. st : stat;
  4454. begin
  4455. dirstream:=opendir(n);
  4456. if (linuxerror<>0) then
  4457. exit;
  4458. d:=Readdir(dirstream);
  4459. while (d<>nil) do
  4460. begin
  4461. name:=n+'/'+strpas(@(d^.name[0]));
  4462. fstat(name,st);
  4463. if linuxerror=0 then
  4464. begin
  4465. if ((st.mode and $E000)=$4000) and { if it is a directory }
  4466. (strpas(@(d^.name[0]))<>'.') and { but not ., .. and fd subdirs }
  4467. (strpas(@(d^.name[0]))<>'..') and
  4468. (strpas(@(d^.name[0]))<>'') and
  4469. (strpas(@(d^.name[0]))<>'fd') then
  4470. begin {we found a directory, search inside it}
  4471. if mysearch(name) then
  4472. begin {the device is here}
  4473. closedir(dirstream); {then don't continue searching}
  4474. mysearch:=true;
  4475. exit;
  4476. end;
  4477. end
  4478. else if (d^.ino=myino) and (st.dev=mydev) then
  4479. begin
  4480. closedir(dirstream);
  4481. ttyname:=name;
  4482. mysearch:=true;
  4483. exit;
  4484. end;
  4485. end;
  4486. d:=Readdir(dirstream);
  4487. end;
  4488. closedir(dirstream);
  4489. mysearch:=false;
  4490. end;
  4491. begin
  4492. TTYName:='';
  4493. fstat(handle,st);
  4494. if (errno<>0) and isatty (handle) then
  4495. exit;
  4496. mydev:=st.dev;
  4497. myino:=st.ino;
  4498. mysearch('/dev');
  4499. end;
  4500. function TTYName(var F:Text):string;
  4501. {
  4502. Idem as previous, only now for text variables;
  4503. }
  4504. begin
  4505. TTYName:=TTYName(textrec(f).handle);
  4506. end;
  4507. {******************************************************************************
  4508. Utility calls
  4509. ******************************************************************************}
  4510. Function Octal(l:longint):longint;
  4511. {
  4512. Convert an octal specified number to decimal;
  4513. }
  4514. var
  4515. octnr,
  4516. oct : longint;
  4517. begin
  4518. octnr:=0;
  4519. oct:=0;
  4520. while (l>0) do
  4521. begin
  4522. oct:=oct or ((l mod 10) shl octnr);
  4523. l:=l div 10;
  4524. inc(octnr,3);
  4525. end;
  4526. Octal:=oct;
  4527. end;
  4528. Function StringToPPChar(S: PChar):ppchar;
  4529. var
  4530. nr : longint;
  4531. Buf : ^char;
  4532. p : ppchar;
  4533. begin
  4534. buf:=s;
  4535. nr:=0;
  4536. while(buf^<>#0) do
  4537. begin
  4538. while (buf^ in [' ',#9,#10]) do
  4539. inc(buf);
  4540. inc(nr);
  4541. while not (buf^ in [' ',#0,#9,#10]) do
  4542. inc(buf);
  4543. end;
  4544. getmem(p,(nr+1)*4);
  4545. StringToPPChar:=p;
  4546. if p=nil then
  4547. begin
  4548. LinuxError:=sys_enomem;
  4549. exit;
  4550. end;
  4551. buf:=s;
  4552. while (buf^<>#0) do
  4553. begin
  4554. while (buf^ in [' ',#9,#10]) do
  4555. begin
  4556. buf^:=#0;
  4557. inc(buf);
  4558. end;
  4559. p^:=buf;
  4560. inc(p);
  4561. p^:=nil;
  4562. while not (buf^ in [' ',#0,#9,#10]) do
  4563. inc(buf);
  4564. end;
  4565. end;
  4566. Function StringToPPChar(Var S:String):ppchar;
  4567. {
  4568. Create a PPChar to structure of pchars which are the arguments specified
  4569. in the string S. Especially useful for creating an ArgV for Exec-calls
  4570. Note that the string S is destroyed by this call.
  4571. }
  4572. begin
  4573. S:=S+#0;
  4574. StringToPPChar:=StringToPPChar(@S[1]);
  4575. end;
  4576. Function StringToPPChar(Var S:AnsiString):ppchar;
  4577. {
  4578. Create a PPChar to structure of pchars which are the arguments specified
  4579. in the string S. Especially useful for creating an ArgV for Exec-calls
  4580. }
  4581. begin
  4582. StringToPPChar:=StringToPPChar(PChar(S));
  4583. end;
  4584. {
  4585. function FExpand (const Path: PathStr): PathStr;
  4586. - declared in fexpand.inc
  4587. }
  4588. {$DEFINE FPC_FEXPAND_TILDE} { Tilde is expanded to home }
  4589. {$DEFINE FPC_FEXPAND_GETENVPCHAR} { GetEnv result is a PChar }
  4590. const
  4591. LFNSupport = true;
  4592. FileNameCaseSensitive = true;
  4593. FileNameCasePreserving = true;
  4594. {$I fexpand.inc}
  4595. {$UNDEF FPC_FEXPAND_GETENVPCHAR}
  4596. {$UNDEF FPC_FEXPAND_TILDE}
  4597. Function FSearch(const path:pathstr;dirlist:string):pathstr;
  4598. {
  4599. Searches for a file 'path' in the list of direcories in 'dirlist'.
  4600. returns an empty string if not found. Wildcards are NOT allowed.
  4601. If dirlist is empty, it is set to '.'
  4602. }
  4603. Var
  4604. NewDir : PathStr;
  4605. p1 : Longint;
  4606. Info : Stat;
  4607. Begin
  4608. {Replace ':' with ';'}
  4609. for p1:=1to length(dirlist) do
  4610. if dirlist[p1]=':' then
  4611. dirlist[p1]:=';';
  4612. {Check for WildCards}
  4613. If (Pos('?',Path) <> 0) or (Pos('*',Path) <> 0) Then
  4614. FSearch:='' {No wildcards allowed in these things.}
  4615. Else
  4616. Begin
  4617. Dirlist:='.;'+dirlist;{Make sure current dir is first to be searched.}
  4618. Repeat
  4619. p1:=Pos(';',DirList);
  4620. If p1=0 Then
  4621. p1:=255;
  4622. NewDir:=Copy(DirList,1,P1 - 1);
  4623. if NewDir[Length(NewDir)]<>'/' then
  4624. NewDir:=NewDir+'/';
  4625. NewDir:=NewDir+Path;
  4626. Delete(DirList,1,p1);
  4627. if FStat(NewDir,Info) then
  4628. Begin
  4629. If Pos('./',NewDir)=1 Then
  4630. Delete(NewDir,1,2);
  4631. {DOS strips off an initial .\}
  4632. End
  4633. Else
  4634. NewDir:='';
  4635. Until (DirList='') or (Length(NewDir) > 0);
  4636. FSearch:=NewDir;
  4637. End;
  4638. End;
  4639. Procedure FSplit(const Path:PathStr;Var Dir:DirStr;Var Name:NameStr;Var Ext:ExtStr);
  4640. Var
  4641. DotPos,SlashPos,i : longint;
  4642. Begin
  4643. SlashPos:=0;
  4644. DotPos:=256;
  4645. i:=Length(Path);
  4646. While (i>0) and (SlashPos=0) Do
  4647. Begin
  4648. If (DotPos=256) and (Path[i]='.') Then
  4649. begin
  4650. DotPos:=i;
  4651. end;
  4652. If (Path[i]='/') Then
  4653. SlashPos:=i;
  4654. Dec(i);
  4655. End;
  4656. Ext:=Copy(Path,DotPos,255);
  4657. Dir:=Copy(Path,1,SlashPos);
  4658. Name:=Copy(Path,SlashPos + 1,DotPos - SlashPos - 1);
  4659. End;
  4660. Function Dirname(Const path:pathstr):pathstr;
  4661. {
  4662. This function returns the directory part of a complete path.
  4663. Unless the directory is root '/', The last character is not
  4664. a slash.
  4665. }
  4666. var
  4667. Dir : PathStr;
  4668. Name : NameStr;
  4669. Ext : ExtStr;
  4670. begin
  4671. FSplit(Path,Dir,Name,Ext);
  4672. if length(Dir)>1 then
  4673. Delete(Dir,length(Dir),1);
  4674. DirName:=Dir;
  4675. end;
  4676. Function Basename(Const path:pathstr;Const suf:pathstr):pathstr;
  4677. {
  4678. This function returns the filename part of a complete path. If suf is
  4679. supplied, it is cut off the filename.
  4680. }
  4681. var
  4682. Dir : PathStr;
  4683. Name : NameStr;
  4684. Ext : ExtStr;
  4685. begin
  4686. FSplit(Path,Dir,Name,Ext);
  4687. if Suf<>Ext then
  4688. Name:=Name+Ext;
  4689. BaseName:=Name;
  4690. end;
  4691. Function FNMatch(const Pattern,Name:string):Boolean;
  4692. Var
  4693. LenPat,LenName : longint;
  4694. Function DoFNMatch(i,j:longint):Boolean;
  4695. Var
  4696. Found : boolean;
  4697. Begin
  4698. Found:=true;
  4699. While Found and (i<=LenPat) Do
  4700. Begin
  4701. Case Pattern[i] of
  4702. '?' : Found:=(j<=LenName);
  4703. '*' : Begin
  4704. {find the next character in pattern, different of ? and *}
  4705. while Found and (i<LenPat) do
  4706. begin
  4707. inc(i);
  4708. case Pattern[i] of
  4709. '*' : ;
  4710. '?' : begin
  4711. inc(j);
  4712. Found:=(j<=LenName);
  4713. end;
  4714. else
  4715. Found:=false;
  4716. end;
  4717. end;
  4718. {Now, find in name the character which i points to, if the * or ?
  4719. wasn't the last character in the pattern, else, use up all the
  4720. chars in name}
  4721. Found:=true;
  4722. if (i<=LenPat) then
  4723. begin
  4724. repeat
  4725. {find a letter (not only first !) which maches pattern[i]}
  4726. while (j<=LenName) and (name[j]<>pattern[i]) do
  4727. inc (j);
  4728. if (j<LenName) then
  4729. begin
  4730. if DoFnMatch(i+1,j+1) then
  4731. begin
  4732. i:=LenPat;
  4733. j:=LenName;{we can stop}
  4734. Found:=true;
  4735. end
  4736. else
  4737. inc(j);{We didn't find one, need to look further}
  4738. end;
  4739. until (j>=LenName);
  4740. end
  4741. else
  4742. j:=LenName;{we can stop}
  4743. end;
  4744. else {not a wildcard character in pattern}
  4745. Found:=(j<=LenName) and (pattern[i]=name[j]);
  4746. end;
  4747. inc(i);
  4748. inc(j);
  4749. end;
  4750. DoFnMatch:=Found and (j>LenName);
  4751. end;
  4752. Begin {start FNMatch}
  4753. LenPat:=Length(Pattern);
  4754. LenName:=Length(Name);
  4755. FNMatch:=DoFNMatch(1,1);
  4756. End;
  4757. Procedure Globfree(var p : pglob);
  4758. {
  4759. Release memory occupied by pglob structure, and names in it.
  4760. sets p to nil.
  4761. }
  4762. var
  4763. temp : pglob;
  4764. begin
  4765. while assigned(p) do
  4766. begin
  4767. temp:=p^.next;
  4768. if assigned(p^.name) then
  4769. freemem(p^.name);
  4770. dispose(p);
  4771. p:=temp;
  4772. end;
  4773. end;
  4774. Function Glob(Const path:pathstr):pglob;
  4775. {
  4776. Fills a tglob structure with entries matching path,
  4777. and returns a pointer to it. Returns nil on error,
  4778. linuxerror is set accordingly.
  4779. }
  4780. var
  4781. temp,
  4782. temp2 : string[255];
  4783. thedir : pdir;
  4784. buffer : pdirent;
  4785. root,
  4786. current : pglob;
  4787. begin
  4788. { Get directory }
  4789. temp:=dirname(path);
  4790. if temp='' then
  4791. temp:='.';
  4792. temp:=temp+#0;
  4793. thedir:=opendir(@temp[1]);
  4794. if thedir=nil then
  4795. begin
  4796. glob:=nil;
  4797. linuxerror:=errno;
  4798. exit;
  4799. end;
  4800. temp:=basename(path,''); { get the pattern }
  4801. if thedir^.fd<0 then
  4802. begin
  4803. linuxerror:=errno;
  4804. glob:=nil;
  4805. exit;
  4806. end;
  4807. {get the entries}
  4808. root:=nil;
  4809. current:=nil;
  4810. repeat
  4811. buffer:=Sys_readdir(thedir);
  4812. if buffer=nil then
  4813. break;
  4814. temp2:=strpas(@(buffer^.name[0]));
  4815. if fnmatch(temp,temp2) then
  4816. begin
  4817. if root=nil then
  4818. begin
  4819. new(root);
  4820. current:=root;
  4821. end
  4822. else
  4823. begin
  4824. new(current^.next);
  4825. current:=current^.next;
  4826. end;
  4827. if current=nil then
  4828. begin
  4829. linuxerror:=Sys_ENOMEM;
  4830. globfree(root);
  4831. break;
  4832. end;
  4833. current^.next:=nil;
  4834. getmem(current^.name,length(temp2)+1);
  4835. if current^.name=nil then
  4836. begin
  4837. linuxerror:=Sys_ENOMEM;
  4838. globfree(root);
  4839. break;
  4840. end;
  4841. move(buffer^.name[0],current^.name^,length(temp2)+1);
  4842. end;
  4843. until false;
  4844. closedir(thedir);
  4845. glob:=root;
  4846. end;
  4847. {--------------------------------
  4848. FiledescriptorSets
  4849. --------------------------------}
  4850. Procedure FD_Zero(var fds:fdSet);
  4851. {
  4852. Clear the set of filedescriptors
  4853. }
  4854. begin
  4855. FillChar(fds,sizeof(fdSet),0);
  4856. end;
  4857. Procedure FD_Clr(fd:longint;var fds:fdSet);
  4858. {
  4859. Remove fd from the set of filedescriptors
  4860. }
  4861. begin
  4862. fds[fd shr 5]:=fds[fd shr 5] and (not (1 shl (fd and 31)));
  4863. end;
  4864. Procedure FD_Set(fd:longint;var fds:fdSet);
  4865. {
  4866. Add fd to the set of filedescriptors
  4867. }
  4868. begin
  4869. fds[fd shr 5]:=fds[fd shr 5] or (1 shl (fd and 31));
  4870. end;
  4871. Function FD_IsSet(fd:longint;var fds:fdSet):boolean;
  4872. {
  4873. Test if fd is part of the set of filedescriptors
  4874. }
  4875. begin
  4876. FD_IsSet:=((fds[fd shr 5] and (1 shl (fd and 31)))<>0);
  4877. end;
  4878. Function GetFS (var T:Text):longint;
  4879. {
  4880. Get File Descriptor of a text file.
  4881. }
  4882. begin
  4883. if textrec(t).mode=fmclosed then
  4884. exit(-1)
  4885. else
  4886. GETFS:=textrec(t).Handle
  4887. end;
  4888. Function GetFS(Var F:File):longint;
  4889. {
  4890. Get File Descriptor of an unTyped file.
  4891. }
  4892. begin
  4893. { Handle and mode are on the same place in textrec and filerec. }
  4894. if filerec(f).mode=fmclosed then
  4895. exit(-1)
  4896. else
  4897. GETFS:=filerec(f).Handle
  4898. end;
  4899. {--------------------------------
  4900. Stat.Mode Macro's
  4901. --------------------------------}
  4902. Function S_ISLNK(m:word):boolean;
  4903. {
  4904. Check mode field of inode for link.
  4905. }
  4906. begin
  4907. S_ISLNK:=(m and STAT_IFMT)=STAT_IFLNK;
  4908. end;
  4909. Function S_ISREG(m:word):boolean;
  4910. {
  4911. Check mode field of inode for regular file.
  4912. }
  4913. begin
  4914. S_ISREG:=(m and STAT_IFMT)=STAT_IFREG;
  4915. end;
  4916. Function S_ISDIR(m:word):boolean;
  4917. {
  4918. Check mode field of inode for directory.
  4919. }
  4920. begin
  4921. S_ISDIR:=(m and STAT_IFMT)=STAT_IFDIR;
  4922. end;
  4923. Function S_ISCHR(m:word):boolean;
  4924. {
  4925. Check mode field of inode for character device.
  4926. }
  4927. begin
  4928. S_ISCHR:=(m and STAT_IFMT)=STAT_IFCHR;
  4929. end;
  4930. Function S_ISBLK(m:word):boolean;
  4931. {
  4932. Check mode field of inode for block device.
  4933. }
  4934. begin
  4935. S_ISBLK:=(m and STAT_IFMT)=STAT_IFBLK;
  4936. end;
  4937. Function S_ISFIFO(m:word):boolean;
  4938. {
  4939. Check mode field of inode for named pipe (FIFO).
  4940. }
  4941. begin
  4942. S_ISFIFO:=(m and STAT_IFMT)=STAT_IFIFO;
  4943. end;
  4944. Function S_ISSOCK(m:word):boolean;
  4945. {
  4946. Check mode field of inode for socket.
  4947. }
  4948. begin
  4949. S_ISSOCK:=(m and STAT_IFMT)=STAT_IFSOCK;
  4950. end;
  4951. Procedure WritePort (Port : Longint; Value : Byte);oldfpccall;
  4952. {
  4953. Writes 'Value' to port 'Port'
  4954. }
  4955. begin
  4956. asm
  4957. movl port,%edx
  4958. movb value,%al
  4959. outb %al,%dx
  4960. end ['EAX','EDX'];
  4961. end;
  4962. Procedure WritePort (Port : Longint; Value : Word);oldfpccall;
  4963. {
  4964. Writes 'Value' to port 'Port'
  4965. }
  4966. begin
  4967. asm
  4968. movl port,%edx
  4969. movw value,%ax
  4970. outw %ax,%dx
  4971. end ['EAX','EDX'];
  4972. end;
  4973. Procedure WritePort (Port : Longint; Value : Longint);oldfpccall;
  4974. {
  4975. Writes 'Value' to port 'Port'
  4976. }
  4977. begin
  4978. asm
  4979. movl port,%edx
  4980. movl value,%eax
  4981. outl %eax,%dx
  4982. end ['EAX','EDX'];
  4983. end;
  4984. Procedure WritePortB (Port : Longint; Value : Byte);oldfpccall;
  4985. {
  4986. Writes 'Value' to port 'Port'
  4987. }
  4988. begin
  4989. asm
  4990. movl port,%edx
  4991. movb value,%al
  4992. outb %al,%dx
  4993. end ['EAX','EDX'];
  4994. end;
  4995. Procedure WritePortW (Port : Longint; Value : Word);oldfpccall;
  4996. {
  4997. Writes 'Value' to port 'Port'
  4998. }
  4999. begin
  5000. asm
  5001. movl port,%edx
  5002. movw value,%ax
  5003. outw %ax,%dx
  5004. end ['EAX','EDX'];
  5005. end;
  5006. Procedure WritePortL (Port : Longint; Value : Longint);oldfpccall;
  5007. {
  5008. Writes 'Value' to port 'Port'
  5009. }
  5010. begin
  5011. asm
  5012. movl port,%edx
  5013. movl value,%eax
  5014. outl %eax,%dx
  5015. end ['EAX','EDX'];
  5016. end;
  5017. Procedure WritePortl (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5018. {
  5019. Writes 'Count' longints from 'Buf' to Port
  5020. }
  5021. begin
  5022. asm
  5023. movl count,%ecx
  5024. movl buf,%esi
  5025. movl port,%edx
  5026. cld
  5027. rep
  5028. outsl
  5029. end ['ECX','ESI','EDX'];
  5030. end;
  5031. Procedure WritePortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5032. {
  5033. Writes 'Count' words from 'Buf' to Port
  5034. }
  5035. begin
  5036. asm
  5037. movl count,%ecx
  5038. movl buf,%esi
  5039. movl port,%edx
  5040. cld
  5041. rep
  5042. outsw
  5043. end ['ECX','ESI','EDX'];
  5044. end;
  5045. Procedure WritePortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5046. {
  5047. Writes 'Count' bytes from 'Buf' to Port
  5048. }
  5049. begin
  5050. asm
  5051. movl count,%ecx
  5052. movl buf,%esi
  5053. movl port,%edx
  5054. cld
  5055. rep
  5056. outsb
  5057. end ['ECX','ESI','EDX'];
  5058. end;
  5059. Procedure ReadPort (Port : Longint; Var Value : Byte);oldfpccall;
  5060. {
  5061. Reads 'Value' from port 'Port'
  5062. }
  5063. begin
  5064. asm
  5065. movl port,%edx
  5066. inb %dx,%al
  5067. movl value,%edx
  5068. movb %al,(%edx)
  5069. end ['EAX','EDX'];
  5070. end;
  5071. Procedure ReadPort (Port : Longint; Var Value : Word);oldfpccall;
  5072. {
  5073. Reads 'Value' from port 'Port'
  5074. }
  5075. begin
  5076. asm
  5077. movl port,%edx
  5078. inw %dx,%ax
  5079. movl value,%edx
  5080. movw %ax,(%edx)
  5081. end ['EAX','EDX'];
  5082. end;
  5083. Procedure ReadPort (Port : Longint; Var Value : Longint);oldfpccall;
  5084. {
  5085. Reads 'Value' from port 'Port'
  5086. }
  5087. begin
  5088. asm
  5089. movl port,%edx
  5090. inl %dx,%eax
  5091. movl value,%edx
  5092. movl %eax,(%edx)
  5093. end ['EAX','EDX'];
  5094. end;
  5095. function ReadPortB (Port : Longint): Byte;oldfpccall; assembler;
  5096. {
  5097. Reads a byte from port 'Port'
  5098. }
  5099. asm
  5100. xorl %eax,%eax
  5101. movl port,%edx
  5102. inb %dx,%al
  5103. end ['EAX','EDX'];
  5104. function ReadPortW (Port : Longint): Word;oldfpccall; assembler;
  5105. {
  5106. Reads a word from port 'Port'
  5107. }
  5108. asm
  5109. xorl %eax,%eax
  5110. movl port,%edx
  5111. inw %dx,%ax
  5112. end ['EAX','EDX'];
  5113. function ReadPortL (Port : Longint): LongInt;oldfpccall; assembler;
  5114. {
  5115. Reads a LongInt from port 'Port'
  5116. }
  5117. asm
  5118. movl port,%edx
  5119. inl %dx,%eax
  5120. end ['EAX','EDX'];
  5121. Procedure ReadPortL (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5122. {
  5123. Reads 'Count' longints from port 'Port' to 'Buf'.
  5124. }
  5125. begin
  5126. asm
  5127. movl count,%ecx
  5128. movl buf,%edi
  5129. movl port,%edx
  5130. cld
  5131. rep
  5132. insl
  5133. end ['ECX','EDI','EDX'];
  5134. end;
  5135. Procedure ReadPortW (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5136. {
  5137. Reads 'Count' words from port 'Port' to 'Buf'.
  5138. }
  5139. begin
  5140. asm
  5141. movl count,%ecx
  5142. movl buf,%edi
  5143. movl port,%edx
  5144. cld
  5145. rep
  5146. insw
  5147. end ['ECX','EDI','EDX'];
  5148. end;
  5149. Procedure ReadPortB (Port : Longint; Var Buf; Count: longint);oldfpccall;
  5150. {
  5151. Reads 'Count' bytes from port 'Port' to 'Buf'.
  5152. }
  5153. begin
  5154. asm
  5155. movl count,%ecx
  5156. movl buf,%edi
  5157. movl port,%edx
  5158. cld
  5159. rep
  5160. insb
  5161. end ['ECX','EDI','EDX'];
  5162. end;
  5163. {--------------------------------
  5164. Memory functions
  5165. --------------------------------}
  5166. Initialization
  5167. InitLocalTime;
  5168. finalization
  5169. DoneLocalTime;
  5170. End.