linuxold.inc 142 KB

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