libc.info-10 293 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422
  1. This is libc.info, produced by makeinfo version 5.2 from libc.texinfo.
  2. This file documents the GNU C Library.
  3. This is ‘The GNU C Library Reference Manual’, for version 2.25.
  4. Copyright © 1993–2017 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being “Free Software Needs Free Documentation” and
  9. “GNU Lesser General Public License”, the Front-Cover texts being “A GNU
  10. Manual”, and with the Back-Cover Texts as in (a) below. A copy of the
  11. license is included in the section entitled "GNU Free Documentation
  12. License".
  13. (a) The FSF’s Back-Cover Text is: “You have the freedom to copy and
  14. modify this GNU manual. Buying copies from the FSF supports it in
  15. developing GNU and promoting software freedom.”
  16. INFO-DIR-SECTION Software libraries
  17. START-INFO-DIR-ENTRY
  18. * Libc: (libc). C library.
  19. END-INFO-DIR-ENTRY
  20. INFO-DIR-SECTION GNU C library functions and macros
  21. START-INFO-DIR-ENTRY
  22. * a64l: (libc)Encode Binary Data.
  23. * abort: (libc)Aborting a Program.
  24. * abs: (libc)Absolute Value.
  25. * accept: (libc)Accepting Connections.
  26. * access: (libc)Testing File Access.
  27. * acosf: (libc)Inverse Trig Functions.
  28. * acoshf: (libc)Hyperbolic Functions.
  29. * acosh: (libc)Hyperbolic Functions.
  30. * acoshl: (libc)Hyperbolic Functions.
  31. * acos: (libc)Inverse Trig Functions.
  32. * acosl: (libc)Inverse Trig Functions.
  33. * addmntent: (libc)mtab.
  34. * addseverity: (libc)Adding Severity Classes.
  35. * adjtime: (libc)High-Resolution Calendar.
  36. * adjtimex: (libc)High-Resolution Calendar.
  37. * aio_cancel64: (libc)Cancel AIO Operations.
  38. * aio_cancel: (libc)Cancel AIO Operations.
  39. * aio_error64: (libc)Status of AIO Operations.
  40. * aio_error: (libc)Status of AIO Operations.
  41. * aio_fsync64: (libc)Synchronizing AIO Operations.
  42. * aio_fsync: (libc)Synchronizing AIO Operations.
  43. * aio_init: (libc)Configuration of AIO.
  44. * aio_read64: (libc)Asynchronous Reads/Writes.
  45. * aio_read: (libc)Asynchronous Reads/Writes.
  46. * aio_return64: (libc)Status of AIO Operations.
  47. * aio_return: (libc)Status of AIO Operations.
  48. * aio_suspend64: (libc)Synchronizing AIO Operations.
  49. * aio_suspend: (libc)Synchronizing AIO Operations.
  50. * aio_write64: (libc)Asynchronous Reads/Writes.
  51. * aio_write: (libc)Asynchronous Reads/Writes.
  52. * alarm: (libc)Setting an Alarm.
  53. * aligned_alloc: (libc)Aligned Memory Blocks.
  54. * alloca: (libc)Variable Size Automatic.
  55. * alphasort64: (libc)Scanning Directory Content.
  56. * alphasort: (libc)Scanning Directory Content.
  57. * ALTWERASE: (libc)Local Modes.
  58. * ARG_MAX: (libc)General Limits.
  59. * argp_error: (libc)Argp Helper Functions.
  60. * ARGP_ERR_UNKNOWN: (libc)Argp Parser Functions.
  61. * argp_failure: (libc)Argp Helper Functions.
  62. * argp_help: (libc)Argp Help.
  63. * argp_parse: (libc)Argp.
  64. * argp_state_help: (libc)Argp Helper Functions.
  65. * argp_usage: (libc)Argp Helper Functions.
  66. * argz_add: (libc)Argz Functions.
  67. * argz_add_sep: (libc)Argz Functions.
  68. * argz_append: (libc)Argz Functions.
  69. * argz_count: (libc)Argz Functions.
  70. * argz_create: (libc)Argz Functions.
  71. * argz_create_sep: (libc)Argz Functions.
  72. * argz_delete: (libc)Argz Functions.
  73. * argz_extract: (libc)Argz Functions.
  74. * argz_insert: (libc)Argz Functions.
  75. * argz_next: (libc)Argz Functions.
  76. * argz_replace: (libc)Argz Functions.
  77. * argz_stringify: (libc)Argz Functions.
  78. * asctime: (libc)Formatting Calendar Time.
  79. * asctime_r: (libc)Formatting Calendar Time.
  80. * asinf: (libc)Inverse Trig Functions.
  81. * asinhf: (libc)Hyperbolic Functions.
  82. * asinh: (libc)Hyperbolic Functions.
  83. * asinhl: (libc)Hyperbolic Functions.
  84. * asin: (libc)Inverse Trig Functions.
  85. * asinl: (libc)Inverse Trig Functions.
  86. * asprintf: (libc)Dynamic Output.
  87. * assert: (libc)Consistency Checking.
  88. * assert_perror: (libc)Consistency Checking.
  89. * atan2f: (libc)Inverse Trig Functions.
  90. * atan2: (libc)Inverse Trig Functions.
  91. * atan2l: (libc)Inverse Trig Functions.
  92. * atanf: (libc)Inverse Trig Functions.
  93. * atanhf: (libc)Hyperbolic Functions.
  94. * atanh: (libc)Hyperbolic Functions.
  95. * atanhl: (libc)Hyperbolic Functions.
  96. * atan: (libc)Inverse Trig Functions.
  97. * atanl: (libc)Inverse Trig Functions.
  98. * atexit: (libc)Cleanups on Exit.
  99. * atof: (libc)Parsing of Floats.
  100. * atoi: (libc)Parsing of Integers.
  101. * atol: (libc)Parsing of Integers.
  102. * atoll: (libc)Parsing of Integers.
  103. * backtrace: (libc)Backtraces.
  104. * backtrace_symbols_fd: (libc)Backtraces.
  105. * backtrace_symbols: (libc)Backtraces.
  106. * basename: (libc)Finding Tokens in a String.
  107. * basename: (libc)Finding Tokens in a String.
  108. * BC_BASE_MAX: (libc)Utility Limits.
  109. * BC_DIM_MAX: (libc)Utility Limits.
  110. * bcmp: (libc)String/Array Comparison.
  111. * bcopy: (libc)Copying Strings and Arrays.
  112. * BC_SCALE_MAX: (libc)Utility Limits.
  113. * BC_STRING_MAX: (libc)Utility Limits.
  114. * bind: (libc)Setting Address.
  115. * bind_textdomain_codeset: (libc)Charset conversion in gettext.
  116. * bindtextdomain: (libc)Locating gettext catalog.
  117. * BRKINT: (libc)Input Modes.
  118. * brk: (libc)Resizing the Data Segment.
  119. * bsearch: (libc)Array Search Function.
  120. * btowc: (libc)Converting a Character.
  121. * BUFSIZ: (libc)Controlling Buffering.
  122. * bzero: (libc)Copying Strings and Arrays.
  123. * cabsf: (libc)Absolute Value.
  124. * cabs: (libc)Absolute Value.
  125. * cabsl: (libc)Absolute Value.
  126. * cacosf: (libc)Inverse Trig Functions.
  127. * cacoshf: (libc)Hyperbolic Functions.
  128. * cacosh: (libc)Hyperbolic Functions.
  129. * cacoshl: (libc)Hyperbolic Functions.
  130. * cacos: (libc)Inverse Trig Functions.
  131. * cacosl: (libc)Inverse Trig Functions.
  132. * calloc: (libc)Allocating Cleared Space.
  133. * canonicalize_file_name: (libc)Symbolic Links.
  134. * canonicalizef: (libc)FP Bit Twiddling.
  135. * canonicalize: (libc)FP Bit Twiddling.
  136. * canonicalizel: (libc)FP Bit Twiddling.
  137. * cargf: (libc)Operations on Complex.
  138. * carg: (libc)Operations on Complex.
  139. * cargl: (libc)Operations on Complex.
  140. * casinf: (libc)Inverse Trig Functions.
  141. * casinhf: (libc)Hyperbolic Functions.
  142. * casinh: (libc)Hyperbolic Functions.
  143. * casinhl: (libc)Hyperbolic Functions.
  144. * casin: (libc)Inverse Trig Functions.
  145. * casinl: (libc)Inverse Trig Functions.
  146. * catanf: (libc)Inverse Trig Functions.
  147. * catanhf: (libc)Hyperbolic Functions.
  148. * catanh: (libc)Hyperbolic Functions.
  149. * catanhl: (libc)Hyperbolic Functions.
  150. * catan: (libc)Inverse Trig Functions.
  151. * catanl: (libc)Inverse Trig Functions.
  152. * catclose: (libc)The catgets Functions.
  153. * catgets: (libc)The catgets Functions.
  154. * catopen: (libc)The catgets Functions.
  155. * cbc_crypt: (libc)DES Encryption.
  156. * cbrtf: (libc)Exponents and Logarithms.
  157. * cbrt: (libc)Exponents and Logarithms.
  158. * cbrtl: (libc)Exponents and Logarithms.
  159. * ccosf: (libc)Trig Functions.
  160. * ccoshf: (libc)Hyperbolic Functions.
  161. * ccosh: (libc)Hyperbolic Functions.
  162. * ccoshl: (libc)Hyperbolic Functions.
  163. * ccos: (libc)Trig Functions.
  164. * ccosl: (libc)Trig Functions.
  165. * CCTS_OFLOW: (libc)Control Modes.
  166. * ceilf: (libc)Rounding Functions.
  167. * ceil: (libc)Rounding Functions.
  168. * ceill: (libc)Rounding Functions.
  169. * cexpf: (libc)Exponents and Logarithms.
  170. * cexp: (libc)Exponents and Logarithms.
  171. * cexpl: (libc)Exponents and Logarithms.
  172. * cfgetispeed: (libc)Line Speed.
  173. * cfgetospeed: (libc)Line Speed.
  174. * cfmakeraw: (libc)Noncanonical Input.
  175. * cfree: (libc)Freeing after Malloc.
  176. * cfsetispeed: (libc)Line Speed.
  177. * cfsetospeed: (libc)Line Speed.
  178. * cfsetspeed: (libc)Line Speed.
  179. * chdir: (libc)Working Directory.
  180. * CHILD_MAX: (libc)General Limits.
  181. * chmod: (libc)Setting Permissions.
  182. * chown: (libc)File Owner.
  183. * CIGNORE: (libc)Control Modes.
  184. * cimagf: (libc)Operations on Complex.
  185. * cimag: (libc)Operations on Complex.
  186. * cimagl: (libc)Operations on Complex.
  187. * clearenv: (libc)Environment Access.
  188. * clearerr: (libc)Error Recovery.
  189. * clearerr_unlocked: (libc)Error Recovery.
  190. * CLK_TCK: (libc)Processor Time.
  191. * CLOCAL: (libc)Control Modes.
  192. * clock: (libc)CPU Time.
  193. * CLOCKS_PER_SEC: (libc)CPU Time.
  194. * clog10f: (libc)Exponents and Logarithms.
  195. * clog10: (libc)Exponents and Logarithms.
  196. * clog10l: (libc)Exponents and Logarithms.
  197. * clogf: (libc)Exponents and Logarithms.
  198. * clog: (libc)Exponents and Logarithms.
  199. * clogl: (libc)Exponents and Logarithms.
  200. * closedir: (libc)Reading/Closing Directory.
  201. * close: (libc)Opening and Closing Files.
  202. * closelog: (libc)closelog.
  203. * COLL_WEIGHTS_MAX: (libc)Utility Limits.
  204. * _Complex_I: (libc)Complex Numbers.
  205. * confstr: (libc)String Parameters.
  206. * conjf: (libc)Operations on Complex.
  207. * conj: (libc)Operations on Complex.
  208. * conjl: (libc)Operations on Complex.
  209. * connect: (libc)Connecting.
  210. * copysignf: (libc)FP Bit Twiddling.
  211. * copysign: (libc)FP Bit Twiddling.
  212. * copysignl: (libc)FP Bit Twiddling.
  213. * cosf: (libc)Trig Functions.
  214. * coshf: (libc)Hyperbolic Functions.
  215. * cosh: (libc)Hyperbolic Functions.
  216. * coshl: (libc)Hyperbolic Functions.
  217. * cos: (libc)Trig Functions.
  218. * cosl: (libc)Trig Functions.
  219. * cpowf: (libc)Exponents and Logarithms.
  220. * cpow: (libc)Exponents and Logarithms.
  221. * cpowl: (libc)Exponents and Logarithms.
  222. * cprojf: (libc)Operations on Complex.
  223. * cproj: (libc)Operations on Complex.
  224. * cprojl: (libc)Operations on Complex.
  225. * CPU_CLR: (libc)CPU Affinity.
  226. * CPU_ISSET: (libc)CPU Affinity.
  227. * CPU_SET: (libc)CPU Affinity.
  228. * CPU_SETSIZE: (libc)CPU Affinity.
  229. * CPU_ZERO: (libc)CPU Affinity.
  230. * CREAD: (libc)Control Modes.
  231. * crealf: (libc)Operations on Complex.
  232. * creal: (libc)Operations on Complex.
  233. * creall: (libc)Operations on Complex.
  234. * creat64: (libc)Opening and Closing Files.
  235. * creat: (libc)Opening and Closing Files.
  236. * CRTS_IFLOW: (libc)Control Modes.
  237. * crypt: (libc)crypt.
  238. * crypt_r: (libc)crypt.
  239. * CS5: (libc)Control Modes.
  240. * CS6: (libc)Control Modes.
  241. * CS7: (libc)Control Modes.
  242. * CS8: (libc)Control Modes.
  243. * csinf: (libc)Trig Functions.
  244. * csinhf: (libc)Hyperbolic Functions.
  245. * csinh: (libc)Hyperbolic Functions.
  246. * csinhl: (libc)Hyperbolic Functions.
  247. * csin: (libc)Trig Functions.
  248. * csinl: (libc)Trig Functions.
  249. * CSIZE: (libc)Control Modes.
  250. * csqrtf: (libc)Exponents and Logarithms.
  251. * csqrt: (libc)Exponents and Logarithms.
  252. * csqrtl: (libc)Exponents and Logarithms.
  253. * CSTOPB: (libc)Control Modes.
  254. * ctanf: (libc)Trig Functions.
  255. * ctanhf: (libc)Hyperbolic Functions.
  256. * ctanh: (libc)Hyperbolic Functions.
  257. * ctanhl: (libc)Hyperbolic Functions.
  258. * ctan: (libc)Trig Functions.
  259. * ctanl: (libc)Trig Functions.
  260. * ctermid: (libc)Identifying the Terminal.
  261. * ctime: (libc)Formatting Calendar Time.
  262. * ctime_r: (libc)Formatting Calendar Time.
  263. * cuserid: (libc)Who Logged In.
  264. * dcgettext: (libc)Translation with gettext.
  265. * dcngettext: (libc)Advanced gettext functions.
  266. * DES_FAILED: (libc)DES Encryption.
  267. * des_setparity: (libc)DES Encryption.
  268. * dgettext: (libc)Translation with gettext.
  269. * difftime: (libc)Elapsed Time.
  270. * dirfd: (libc)Opening a Directory.
  271. * dirname: (libc)Finding Tokens in a String.
  272. * div: (libc)Integer Division.
  273. * dngettext: (libc)Advanced gettext functions.
  274. * drand48: (libc)SVID Random.
  275. * drand48_r: (libc)SVID Random.
  276. * dremf: (libc)Remainder Functions.
  277. * drem: (libc)Remainder Functions.
  278. * dreml: (libc)Remainder Functions.
  279. * DTTOIF: (libc)Directory Entries.
  280. * dup2: (libc)Duplicating Descriptors.
  281. * dup: (libc)Duplicating Descriptors.
  282. * E2BIG: (libc)Error Codes.
  283. * EACCES: (libc)Error Codes.
  284. * EADDRINUSE: (libc)Error Codes.
  285. * EADDRNOTAVAIL: (libc)Error Codes.
  286. * EADV: (libc)Error Codes.
  287. * EAFNOSUPPORT: (libc)Error Codes.
  288. * EAGAIN: (libc)Error Codes.
  289. * EALREADY: (libc)Error Codes.
  290. * EAUTH: (libc)Error Codes.
  291. * EBACKGROUND: (libc)Error Codes.
  292. * EBADE: (libc)Error Codes.
  293. * EBADFD: (libc)Error Codes.
  294. * EBADF: (libc)Error Codes.
  295. * EBADMSG: (libc)Error Codes.
  296. * EBADR: (libc)Error Codes.
  297. * EBADRPC: (libc)Error Codes.
  298. * EBADRQC: (libc)Error Codes.
  299. * EBADSLT: (libc)Error Codes.
  300. * EBFONT: (libc)Error Codes.
  301. * EBUSY: (libc)Error Codes.
  302. * ECANCELED: (libc)Error Codes.
  303. * ecb_crypt: (libc)DES Encryption.
  304. * ECHILD: (libc)Error Codes.
  305. * ECHOCTL: (libc)Local Modes.
  306. * ECHOE: (libc)Local Modes.
  307. * ECHOKE: (libc)Local Modes.
  308. * ECHOK: (libc)Local Modes.
  309. * ECHO: (libc)Local Modes.
  310. * ECHONL: (libc)Local Modes.
  311. * ECHOPRT: (libc)Local Modes.
  312. * ECHRNG: (libc)Error Codes.
  313. * ECOMM: (libc)Error Codes.
  314. * ECONNABORTED: (libc)Error Codes.
  315. * ECONNREFUSED: (libc)Error Codes.
  316. * ECONNRESET: (libc)Error Codes.
  317. * ecvt: (libc)System V Number Conversion.
  318. * ecvt_r: (libc)System V Number Conversion.
  319. * EDEADLK: (libc)Error Codes.
  320. * EDEADLOCK: (libc)Error Codes.
  321. * EDESTADDRREQ: (libc)Error Codes.
  322. * EDIED: (libc)Error Codes.
  323. * ED: (libc)Error Codes.
  324. * EDOM: (libc)Error Codes.
  325. * EDOTDOT: (libc)Error Codes.
  326. * EDQUOT: (libc)Error Codes.
  327. * EEXIST: (libc)Error Codes.
  328. * EFAULT: (libc)Error Codes.
  329. * EFBIG: (libc)Error Codes.
  330. * EFTYPE: (libc)Error Codes.
  331. * EGRATUITOUS: (libc)Error Codes.
  332. * EGREGIOUS: (libc)Error Codes.
  333. * EHOSTDOWN: (libc)Error Codes.
  334. * EHOSTUNREACH: (libc)Error Codes.
  335. * EHWPOISON: (libc)Error Codes.
  336. * EIDRM: (libc)Error Codes.
  337. * EIEIO: (libc)Error Codes.
  338. * EILSEQ: (libc)Error Codes.
  339. * EINPROGRESS: (libc)Error Codes.
  340. * EINTR: (libc)Error Codes.
  341. * EINVAL: (libc)Error Codes.
  342. * EIO: (libc)Error Codes.
  343. * EISCONN: (libc)Error Codes.
  344. * EISDIR: (libc)Error Codes.
  345. * EISNAM: (libc)Error Codes.
  346. * EKEYEXPIRED: (libc)Error Codes.
  347. * EKEYREJECTED: (libc)Error Codes.
  348. * EKEYREVOKED: (libc)Error Codes.
  349. * EL2HLT: (libc)Error Codes.
  350. * EL2NSYNC: (libc)Error Codes.
  351. * EL3HLT: (libc)Error Codes.
  352. * EL3RST: (libc)Error Codes.
  353. * ELIBACC: (libc)Error Codes.
  354. * ELIBBAD: (libc)Error Codes.
  355. * ELIBEXEC: (libc)Error Codes.
  356. * ELIBMAX: (libc)Error Codes.
  357. * ELIBSCN: (libc)Error Codes.
  358. * ELNRNG: (libc)Error Codes.
  359. * ELOOP: (libc)Error Codes.
  360. * EMEDIUMTYPE: (libc)Error Codes.
  361. * EMFILE: (libc)Error Codes.
  362. * EMLINK: (libc)Error Codes.
  363. * EMSGSIZE: (libc)Error Codes.
  364. * EMULTIHOP: (libc)Error Codes.
  365. * ENAMETOOLONG: (libc)Error Codes.
  366. * ENAVAIL: (libc)Error Codes.
  367. * encrypt: (libc)DES Encryption.
  368. * encrypt_r: (libc)DES Encryption.
  369. * endfsent: (libc)fstab.
  370. * endgrent: (libc)Scanning All Groups.
  371. * endhostent: (libc)Host Names.
  372. * endmntent: (libc)mtab.
  373. * endnetent: (libc)Networks Database.
  374. * endnetgrent: (libc)Lookup Netgroup.
  375. * endprotoent: (libc)Protocols Database.
  376. * endpwent: (libc)Scanning All Users.
  377. * endservent: (libc)Services Database.
  378. * endutent: (libc)Manipulating the Database.
  379. * endutxent: (libc)XPG Functions.
  380. * ENEEDAUTH: (libc)Error Codes.
  381. * ENETDOWN: (libc)Error Codes.
  382. * ENETRESET: (libc)Error Codes.
  383. * ENETUNREACH: (libc)Error Codes.
  384. * ENFILE: (libc)Error Codes.
  385. * ENOANO: (libc)Error Codes.
  386. * ENOBUFS: (libc)Error Codes.
  387. * ENOCSI: (libc)Error Codes.
  388. * ENODATA: (libc)Error Codes.
  389. * ENODEV: (libc)Error Codes.
  390. * ENOENT: (libc)Error Codes.
  391. * ENOEXEC: (libc)Error Codes.
  392. * ENOKEY: (libc)Error Codes.
  393. * ENOLCK: (libc)Error Codes.
  394. * ENOLINK: (libc)Error Codes.
  395. * ENOMEDIUM: (libc)Error Codes.
  396. * ENOMEM: (libc)Error Codes.
  397. * ENOMSG: (libc)Error Codes.
  398. * ENONET: (libc)Error Codes.
  399. * ENOPKG: (libc)Error Codes.
  400. * ENOPROTOOPT: (libc)Error Codes.
  401. * ENOSPC: (libc)Error Codes.
  402. * ENOSR: (libc)Error Codes.
  403. * ENOSTR: (libc)Error Codes.
  404. * ENOSYS: (libc)Error Codes.
  405. * ENOTBLK: (libc)Error Codes.
  406. * ENOTCONN: (libc)Error Codes.
  407. * ENOTDIR: (libc)Error Codes.
  408. * ENOTEMPTY: (libc)Error Codes.
  409. * ENOTNAM: (libc)Error Codes.
  410. * ENOTRECOVERABLE: (libc)Error Codes.
  411. * ENOTSOCK: (libc)Error Codes.
  412. * ENOTSUP: (libc)Error Codes.
  413. * ENOTTY: (libc)Error Codes.
  414. * ENOTUNIQ: (libc)Error Codes.
  415. * envz_add: (libc)Envz Functions.
  416. * envz_entry: (libc)Envz Functions.
  417. * envz_get: (libc)Envz Functions.
  418. * envz_merge: (libc)Envz Functions.
  419. * envz_remove: (libc)Envz Functions.
  420. * envz_strip: (libc)Envz Functions.
  421. * ENXIO: (libc)Error Codes.
  422. * EOF: (libc)EOF and Errors.
  423. * EOPNOTSUPP: (libc)Error Codes.
  424. * EOVERFLOW: (libc)Error Codes.
  425. * EOWNERDEAD: (libc)Error Codes.
  426. * EPERM: (libc)Error Codes.
  427. * EPFNOSUPPORT: (libc)Error Codes.
  428. * EPIPE: (libc)Error Codes.
  429. * EPROCLIM: (libc)Error Codes.
  430. * EPROCUNAVAIL: (libc)Error Codes.
  431. * EPROGMISMATCH: (libc)Error Codes.
  432. * EPROGUNAVAIL: (libc)Error Codes.
  433. * EPROTO: (libc)Error Codes.
  434. * EPROTONOSUPPORT: (libc)Error Codes.
  435. * EPROTOTYPE: (libc)Error Codes.
  436. * EQUIV_CLASS_MAX: (libc)Utility Limits.
  437. * erand48: (libc)SVID Random.
  438. * erand48_r: (libc)SVID Random.
  439. * ERANGE: (libc)Error Codes.
  440. * EREMCHG: (libc)Error Codes.
  441. * EREMOTEIO: (libc)Error Codes.
  442. * EREMOTE: (libc)Error Codes.
  443. * ERESTART: (libc)Error Codes.
  444. * erfcf: (libc)Special Functions.
  445. * erfc: (libc)Special Functions.
  446. * erfcl: (libc)Special Functions.
  447. * erff: (libc)Special Functions.
  448. * ERFKILL: (libc)Error Codes.
  449. * erf: (libc)Special Functions.
  450. * erfl: (libc)Special Functions.
  451. * EROFS: (libc)Error Codes.
  452. * ERPCMISMATCH: (libc)Error Codes.
  453. * err: (libc)Error Messages.
  454. * errno: (libc)Checking for Errors.
  455. * error_at_line: (libc)Error Messages.
  456. * error: (libc)Error Messages.
  457. * errx: (libc)Error Messages.
  458. * ESHUTDOWN: (libc)Error Codes.
  459. * ESOCKTNOSUPPORT: (libc)Error Codes.
  460. * ESPIPE: (libc)Error Codes.
  461. * ESRCH: (libc)Error Codes.
  462. * ESRMNT: (libc)Error Codes.
  463. * ESTALE: (libc)Error Codes.
  464. * ESTRPIPE: (libc)Error Codes.
  465. * ETIMEDOUT: (libc)Error Codes.
  466. * ETIME: (libc)Error Codes.
  467. * ETOOMANYREFS: (libc)Error Codes.
  468. * ETXTBSY: (libc)Error Codes.
  469. * EUCLEAN: (libc)Error Codes.
  470. * EUNATCH: (libc)Error Codes.
  471. * EUSERS: (libc)Error Codes.
  472. * EWOULDBLOCK: (libc)Error Codes.
  473. * EXDEV: (libc)Error Codes.
  474. * execle: (libc)Executing a File.
  475. * execl: (libc)Executing a File.
  476. * execlp: (libc)Executing a File.
  477. * execve: (libc)Executing a File.
  478. * execv: (libc)Executing a File.
  479. * execvp: (libc)Executing a File.
  480. * EXFULL: (libc)Error Codes.
  481. * EXIT_FAILURE: (libc)Exit Status.
  482. * exit: (libc)Normal Termination.
  483. * _exit: (libc)Termination Internals.
  484. * _Exit: (libc)Termination Internals.
  485. * EXIT_SUCCESS: (libc)Exit Status.
  486. * exp10f: (libc)Exponents and Logarithms.
  487. * exp10: (libc)Exponents and Logarithms.
  488. * exp10l: (libc)Exponents and Logarithms.
  489. * exp2f: (libc)Exponents and Logarithms.
  490. * exp2: (libc)Exponents and Logarithms.
  491. * exp2l: (libc)Exponents and Logarithms.
  492. * expf: (libc)Exponents and Logarithms.
  493. * exp: (libc)Exponents and Logarithms.
  494. * explicit_bzero: (libc)Erasing Sensitive Data.
  495. * expl: (libc)Exponents and Logarithms.
  496. * expm1f: (libc)Exponents and Logarithms.
  497. * expm1: (libc)Exponents and Logarithms.
  498. * expm1l: (libc)Exponents and Logarithms.
  499. * EXPR_NEST_MAX: (libc)Utility Limits.
  500. * fabsf: (libc)Absolute Value.
  501. * fabs: (libc)Absolute Value.
  502. * fabsl: (libc)Absolute Value.
  503. * __fbufsize: (libc)Controlling Buffering.
  504. * fchdir: (libc)Working Directory.
  505. * fchmod: (libc)Setting Permissions.
  506. * fchown: (libc)File Owner.
  507. * fcloseall: (libc)Closing Streams.
  508. * fclose: (libc)Closing Streams.
  509. * fcntl: (libc)Control Operations.
  510. * fcvt: (libc)System V Number Conversion.
  511. * fcvt_r: (libc)System V Number Conversion.
  512. * fdatasync: (libc)Synchronizing I/O.
  513. * FD_CLOEXEC: (libc)Descriptor Flags.
  514. * FD_CLR: (libc)Waiting for I/O.
  515. * fdimf: (libc)Misc FP Arithmetic.
  516. * fdim: (libc)Misc FP Arithmetic.
  517. * fdiml: (libc)Misc FP Arithmetic.
  518. * FD_ISSET: (libc)Waiting for I/O.
  519. * fdopendir: (libc)Opening a Directory.
  520. * fdopen: (libc)Descriptors and Streams.
  521. * FD_SET: (libc)Waiting for I/O.
  522. * FD_SETSIZE: (libc)Waiting for I/O.
  523. * F_DUPFD: (libc)Duplicating Descriptors.
  524. * FD_ZERO: (libc)Waiting for I/O.
  525. * feclearexcept: (libc)Status bit operations.
  526. * fedisableexcept: (libc)Control Functions.
  527. * feenableexcept: (libc)Control Functions.
  528. * fegetenv: (libc)Control Functions.
  529. * fegetexceptflag: (libc)Status bit operations.
  530. * fegetexcept: (libc)Control Functions.
  531. * fegetmode: (libc)Control Functions.
  532. * fegetround: (libc)Rounding.
  533. * feholdexcept: (libc)Control Functions.
  534. * feof: (libc)EOF and Errors.
  535. * feof_unlocked: (libc)EOF and Errors.
  536. * feraiseexcept: (libc)Status bit operations.
  537. * ferror: (libc)EOF and Errors.
  538. * ferror_unlocked: (libc)EOF and Errors.
  539. * fesetenv: (libc)Control Functions.
  540. * fesetexceptflag: (libc)Status bit operations.
  541. * fesetexcept: (libc)Status bit operations.
  542. * fesetmode: (libc)Control Functions.
  543. * fesetround: (libc)Rounding.
  544. * FE_SNANS_ALWAYS_SIGNAL: (libc)Infinity and NaN.
  545. * fetestexceptflag: (libc)Status bit operations.
  546. * fetestexcept: (libc)Status bit operations.
  547. * feupdateenv: (libc)Control Functions.
  548. * fflush: (libc)Flushing Buffers.
  549. * fflush_unlocked: (libc)Flushing Buffers.
  550. * fgetc: (libc)Character Input.
  551. * fgetc_unlocked: (libc)Character Input.
  552. * F_GETFD: (libc)Descriptor Flags.
  553. * F_GETFL: (libc)Getting File Status Flags.
  554. * fgetgrent: (libc)Scanning All Groups.
  555. * fgetgrent_r: (libc)Scanning All Groups.
  556. * F_GETLK: (libc)File Locks.
  557. * F_GETOWN: (libc)Interrupt Input.
  558. * fgetpos64: (libc)Portable Positioning.
  559. * fgetpos: (libc)Portable Positioning.
  560. * fgetpwent: (libc)Scanning All Users.
  561. * fgetpwent_r: (libc)Scanning All Users.
  562. * fgets: (libc)Line Input.
  563. * fgets_unlocked: (libc)Line Input.
  564. * fgetwc: (libc)Character Input.
  565. * fgetwc_unlocked: (libc)Character Input.
  566. * fgetws: (libc)Line Input.
  567. * fgetws_unlocked: (libc)Line Input.
  568. * FILENAME_MAX: (libc)Limits for Files.
  569. * fileno: (libc)Descriptors and Streams.
  570. * fileno_unlocked: (libc)Descriptors and Streams.
  571. * finitef: (libc)Floating Point Classes.
  572. * finite: (libc)Floating Point Classes.
  573. * finitel: (libc)Floating Point Classes.
  574. * __flbf: (libc)Controlling Buffering.
  575. * flockfile: (libc)Streams and Threads.
  576. * floorf: (libc)Rounding Functions.
  577. * floor: (libc)Rounding Functions.
  578. * floorl: (libc)Rounding Functions.
  579. * _flushlbf: (libc)Flushing Buffers.
  580. * FLUSHO: (libc)Local Modes.
  581. * fmaf: (libc)Misc FP Arithmetic.
  582. * fma: (libc)Misc FP Arithmetic.
  583. * fmal: (libc)Misc FP Arithmetic.
  584. * fmaxf: (libc)Misc FP Arithmetic.
  585. * fmax: (libc)Misc FP Arithmetic.
  586. * fmaxl: (libc)Misc FP Arithmetic.
  587. * fmaxmagf: (libc)Misc FP Arithmetic.
  588. * fmaxmag: (libc)Misc FP Arithmetic.
  589. * fmaxmagl: (libc)Misc FP Arithmetic.
  590. * fmemopen: (libc)String Streams.
  591. * fminf: (libc)Misc FP Arithmetic.
  592. * fmin: (libc)Misc FP Arithmetic.
  593. * fminl: (libc)Misc FP Arithmetic.
  594. * fminmagf: (libc)Misc FP Arithmetic.
  595. * fminmag: (libc)Misc FP Arithmetic.
  596. * fminmagl: (libc)Misc FP Arithmetic.
  597. * fmodf: (libc)Remainder Functions.
  598. * fmod: (libc)Remainder Functions.
  599. * fmodl: (libc)Remainder Functions.
  600. * fmtmsg: (libc)Printing Formatted Messages.
  601. * fnmatch: (libc)Wildcard Matching.
  602. * F_OFD_GETLK: (libc)Open File Description Locks.
  603. * F_OFD_SETLK: (libc)Open File Description Locks.
  604. * F_OFD_SETLKW: (libc)Open File Description Locks.
  605. * F_OK: (libc)Testing File Access.
  606. * fopen64: (libc)Opening Streams.
  607. * fopencookie: (libc)Streams and Cookies.
  608. * fopen: (libc)Opening Streams.
  609. * FOPEN_MAX: (libc)Opening Streams.
  610. * fork: (libc)Creating a Process.
  611. * forkpty: (libc)Pseudo-Terminal Pairs.
  612. * fpathconf: (libc)Pathconf.
  613. * fpclassify: (libc)Floating Point Classes.
  614. * __fpending: (libc)Controlling Buffering.
  615. * FP_ILOGB0: (libc)Exponents and Logarithms.
  616. * FP_ILOGBNAN: (libc)Exponents and Logarithms.
  617. * FP_LLOGB0: (libc)Exponents and Logarithms.
  618. * FP_LLOGBNAN: (libc)Exponents and Logarithms.
  619. * fprintf: (libc)Formatted Output Functions.
  620. * __fpurge: (libc)Flushing Buffers.
  621. * fputc: (libc)Simple Output.
  622. * fputc_unlocked: (libc)Simple Output.
  623. * fputs: (libc)Simple Output.
  624. * fputs_unlocked: (libc)Simple Output.
  625. * fputwc: (libc)Simple Output.
  626. * fputwc_unlocked: (libc)Simple Output.
  627. * fputws: (libc)Simple Output.
  628. * fputws_unlocked: (libc)Simple Output.
  629. * __freadable: (libc)Opening Streams.
  630. * __freading: (libc)Opening Streams.
  631. * fread: (libc)Block Input/Output.
  632. * fread_unlocked: (libc)Block Input/Output.
  633. * free: (libc)Freeing after Malloc.
  634. * freopen64: (libc)Opening Streams.
  635. * freopen: (libc)Opening Streams.
  636. * frexpf: (libc)Normalization Functions.
  637. * frexp: (libc)Normalization Functions.
  638. * frexpl: (libc)Normalization Functions.
  639. * fromfpf: (libc)Rounding Functions.
  640. * fromfp: (libc)Rounding Functions.
  641. * fromfpl: (libc)Rounding Functions.
  642. * fromfpxf: (libc)Rounding Functions.
  643. * fromfpx: (libc)Rounding Functions.
  644. * fromfpxl: (libc)Rounding Functions.
  645. * fscanf: (libc)Formatted Input Functions.
  646. * fseek: (libc)File Positioning.
  647. * fseeko64: (libc)File Positioning.
  648. * fseeko: (libc)File Positioning.
  649. * F_SETFD: (libc)Descriptor Flags.
  650. * F_SETFL: (libc)Getting File Status Flags.
  651. * F_SETLK: (libc)File Locks.
  652. * F_SETLKW: (libc)File Locks.
  653. * __fsetlocking: (libc)Streams and Threads.
  654. * F_SETOWN: (libc)Interrupt Input.
  655. * fsetpos64: (libc)Portable Positioning.
  656. * fsetpos: (libc)Portable Positioning.
  657. * fstat64: (libc)Reading Attributes.
  658. * fstat: (libc)Reading Attributes.
  659. * fsync: (libc)Synchronizing I/O.
  660. * ftell: (libc)File Positioning.
  661. * ftello64: (libc)File Positioning.
  662. * ftello: (libc)File Positioning.
  663. * ftruncate64: (libc)File Size.
  664. * ftruncate: (libc)File Size.
  665. * ftrylockfile: (libc)Streams and Threads.
  666. * ftw64: (libc)Working with Directory Trees.
  667. * ftw: (libc)Working with Directory Trees.
  668. * funlockfile: (libc)Streams and Threads.
  669. * futimes: (libc)File Times.
  670. * fwide: (libc)Streams and I18N.
  671. * fwprintf: (libc)Formatted Output Functions.
  672. * __fwritable: (libc)Opening Streams.
  673. * fwrite: (libc)Block Input/Output.
  674. * fwrite_unlocked: (libc)Block Input/Output.
  675. * __fwriting: (libc)Opening Streams.
  676. * fwscanf: (libc)Formatted Input Functions.
  677. * gammaf: (libc)Special Functions.
  678. * gamma: (libc)Special Functions.
  679. * gammal: (libc)Special Functions.
  680. * __gconv_end_fct: (libc)glibc iconv Implementation.
  681. * __gconv_fct: (libc)glibc iconv Implementation.
  682. * __gconv_init_fct: (libc)glibc iconv Implementation.
  683. * gcvt: (libc)System V Number Conversion.
  684. * getauxval: (libc)Auxiliary Vector.
  685. * get_avphys_pages: (libc)Query Memory Parameters.
  686. * getchar: (libc)Character Input.
  687. * getchar_unlocked: (libc)Character Input.
  688. * getc: (libc)Character Input.
  689. * getcontext: (libc)System V contexts.
  690. * getc_unlocked: (libc)Character Input.
  691. * get_current_dir_name: (libc)Working Directory.
  692. * getcwd: (libc)Working Directory.
  693. * getdate: (libc)General Time String Parsing.
  694. * getdate_r: (libc)General Time String Parsing.
  695. * getdelim: (libc)Line Input.
  696. * getdomainnname: (libc)Host Identification.
  697. * getegid: (libc)Reading Persona.
  698. * getentropy: (libc)Unpredictable Bytes.
  699. * getenv: (libc)Environment Access.
  700. * geteuid: (libc)Reading Persona.
  701. * getfsent: (libc)fstab.
  702. * getfsfile: (libc)fstab.
  703. * getfsspec: (libc)fstab.
  704. * getgid: (libc)Reading Persona.
  705. * getgrent: (libc)Scanning All Groups.
  706. * getgrent_r: (libc)Scanning All Groups.
  707. * getgrgid: (libc)Lookup Group.
  708. * getgrgid_r: (libc)Lookup Group.
  709. * getgrnam: (libc)Lookup Group.
  710. * getgrnam_r: (libc)Lookup Group.
  711. * getgrouplist: (libc)Setting Groups.
  712. * getgroups: (libc)Reading Persona.
  713. * gethostbyaddr: (libc)Host Names.
  714. * gethostbyaddr_r: (libc)Host Names.
  715. * gethostbyname2: (libc)Host Names.
  716. * gethostbyname2_r: (libc)Host Names.
  717. * gethostbyname: (libc)Host Names.
  718. * gethostbyname_r: (libc)Host Names.
  719. * gethostent: (libc)Host Names.
  720. * gethostid: (libc)Host Identification.
  721. * gethostname: (libc)Host Identification.
  722. * getitimer: (libc)Setting an Alarm.
  723. * getline: (libc)Line Input.
  724. * getloadavg: (libc)Processor Resources.
  725. * getlogin: (libc)Who Logged In.
  726. * getmntent: (libc)mtab.
  727. * getmntent_r: (libc)mtab.
  728. * getnetbyaddr: (libc)Networks Database.
  729. * getnetbyname: (libc)Networks Database.
  730. * getnetent: (libc)Networks Database.
  731. * getnetgrent: (libc)Lookup Netgroup.
  732. * getnetgrent_r: (libc)Lookup Netgroup.
  733. * get_nprocs_conf: (libc)Processor Resources.
  734. * get_nprocs: (libc)Processor Resources.
  735. * getopt: (libc)Using Getopt.
  736. * getopt_long: (libc)Getopt Long Options.
  737. * getopt_long_only: (libc)Getopt Long Options.
  738. * getpagesize: (libc)Query Memory Parameters.
  739. * getpass: (libc)getpass.
  740. * getpayloadf: (libc)FP Bit Twiddling.
  741. * getpayload: (libc)FP Bit Twiddling.
  742. * getpayloadl: (libc)FP Bit Twiddling.
  743. * getpeername: (libc)Who is Connected.
  744. * getpgid: (libc)Process Group Functions.
  745. * getpgrp: (libc)Process Group Functions.
  746. * get_phys_pages: (libc)Query Memory Parameters.
  747. * getpid: (libc)Process Identification.
  748. * getppid: (libc)Process Identification.
  749. * getpriority: (libc)Traditional Scheduling Functions.
  750. * getprotobyname: (libc)Protocols Database.
  751. * getprotobynumber: (libc)Protocols Database.
  752. * getprotoent: (libc)Protocols Database.
  753. * getpt: (libc)Allocation.
  754. * getpwent: (libc)Scanning All Users.
  755. * getpwent_r: (libc)Scanning All Users.
  756. * getpwnam: (libc)Lookup User.
  757. * getpwnam_r: (libc)Lookup User.
  758. * getpwuid: (libc)Lookup User.
  759. * getpwuid_r: (libc)Lookup User.
  760. * getrandom: (libc)Unpredictable Bytes.
  761. * getrlimit64: (libc)Limits on Resources.
  762. * getrlimit: (libc)Limits on Resources.
  763. * getrusage: (libc)Resource Usage.
  764. * getservbyname: (libc)Services Database.
  765. * getservbyport: (libc)Services Database.
  766. * getservent: (libc)Services Database.
  767. * getsid: (libc)Process Group Functions.
  768. * gets: (libc)Line Input.
  769. * getsockname: (libc)Reading Address.
  770. * getsockopt: (libc)Socket Option Functions.
  771. * getsubopt: (libc)Suboptions.
  772. * gettext: (libc)Translation with gettext.
  773. * gettimeofday: (libc)High-Resolution Calendar.
  774. * getuid: (libc)Reading Persona.
  775. * getumask: (libc)Setting Permissions.
  776. * getutent: (libc)Manipulating the Database.
  777. * getutent_r: (libc)Manipulating the Database.
  778. * getutid: (libc)Manipulating the Database.
  779. * getutid_r: (libc)Manipulating the Database.
  780. * getutline: (libc)Manipulating the Database.
  781. * getutline_r: (libc)Manipulating the Database.
  782. * getutmp: (libc)XPG Functions.
  783. * getutmpx: (libc)XPG Functions.
  784. * getutxent: (libc)XPG Functions.
  785. * getutxid: (libc)XPG Functions.
  786. * getutxline: (libc)XPG Functions.
  787. * getwchar: (libc)Character Input.
  788. * getwchar_unlocked: (libc)Character Input.
  789. * getwc: (libc)Character Input.
  790. * getwc_unlocked: (libc)Character Input.
  791. * getwd: (libc)Working Directory.
  792. * getw: (libc)Character Input.
  793. * glob64: (libc)Calling Glob.
  794. * globfree64: (libc)More Flags for Globbing.
  795. * globfree: (libc)More Flags for Globbing.
  796. * glob: (libc)Calling Glob.
  797. * gmtime: (libc)Broken-down Time.
  798. * gmtime_r: (libc)Broken-down Time.
  799. * grantpt: (libc)Allocation.
  800. * gsignal: (libc)Signaling Yourself.
  801. * gtty: (libc)BSD Terminal Modes.
  802. * hasmntopt: (libc)mtab.
  803. * hcreate: (libc)Hash Search Function.
  804. * hcreate_r: (libc)Hash Search Function.
  805. * hdestroy: (libc)Hash Search Function.
  806. * hdestroy_r: (libc)Hash Search Function.
  807. * hsearch: (libc)Hash Search Function.
  808. * hsearch_r: (libc)Hash Search Function.
  809. * htonl: (libc)Byte Order.
  810. * htons: (libc)Byte Order.
  811. * HUGE_VALF: (libc)Math Error Reporting.
  812. * HUGE_VAL: (libc)Math Error Reporting.
  813. * HUGE_VALL: (libc)Math Error Reporting.
  814. * HUPCL: (libc)Control Modes.
  815. * hypotf: (libc)Exponents and Logarithms.
  816. * hypot: (libc)Exponents and Logarithms.
  817. * hypotl: (libc)Exponents and Logarithms.
  818. * ICANON: (libc)Local Modes.
  819. * iconv_close: (libc)Generic Conversion Interface.
  820. * iconv: (libc)Generic Conversion Interface.
  821. * iconv_open: (libc)Generic Conversion Interface.
  822. * ICRNL: (libc)Input Modes.
  823. * IEXTEN: (libc)Local Modes.
  824. * if_freenameindex: (libc)Interface Naming.
  825. * if_indextoname: (libc)Interface Naming.
  826. * if_nameindex: (libc)Interface Naming.
  827. * if_nametoindex: (libc)Interface Naming.
  828. * IFNAMSIZ: (libc)Interface Naming.
  829. * IFTODT: (libc)Directory Entries.
  830. * IGNBRK: (libc)Input Modes.
  831. * IGNCR: (libc)Input Modes.
  832. * IGNPAR: (libc)Input Modes.
  833. * I: (libc)Complex Numbers.
  834. * ilogbf: (libc)Exponents and Logarithms.
  835. * ilogb: (libc)Exponents and Logarithms.
  836. * ilogbl: (libc)Exponents and Logarithms.
  837. * _Imaginary_I: (libc)Complex Numbers.
  838. * imaxabs: (libc)Absolute Value.
  839. * IMAXBEL: (libc)Input Modes.
  840. * imaxdiv: (libc)Integer Division.
  841. * in6addr_any: (libc)Host Address Data Type.
  842. * in6addr_loopback: (libc)Host Address Data Type.
  843. * INADDR_ANY: (libc)Host Address Data Type.
  844. * INADDR_BROADCAST: (libc)Host Address Data Type.
  845. * INADDR_LOOPBACK: (libc)Host Address Data Type.
  846. * INADDR_NONE: (libc)Host Address Data Type.
  847. * index: (libc)Search Functions.
  848. * inet_addr: (libc)Host Address Functions.
  849. * inet_aton: (libc)Host Address Functions.
  850. * inet_lnaof: (libc)Host Address Functions.
  851. * inet_makeaddr: (libc)Host Address Functions.
  852. * inet_netof: (libc)Host Address Functions.
  853. * inet_network: (libc)Host Address Functions.
  854. * inet_ntoa: (libc)Host Address Functions.
  855. * inet_ntop: (libc)Host Address Functions.
  856. * inet_pton: (libc)Host Address Functions.
  857. * INFINITY: (libc)Infinity and NaN.
  858. * initgroups: (libc)Setting Groups.
  859. * initstate: (libc)BSD Random.
  860. * initstate_r: (libc)BSD Random.
  861. * INLCR: (libc)Input Modes.
  862. * innetgr: (libc)Netgroup Membership.
  863. * INPCK: (libc)Input Modes.
  864. * ioctl: (libc)IOCTLs.
  865. * _IOFBF: (libc)Controlling Buffering.
  866. * _IOLBF: (libc)Controlling Buffering.
  867. * _IONBF: (libc)Controlling Buffering.
  868. * IPPORT_RESERVED: (libc)Ports.
  869. * IPPORT_USERRESERVED: (libc)Ports.
  870. * isalnum: (libc)Classification of Characters.
  871. * isalpha: (libc)Classification of Characters.
  872. * isascii: (libc)Classification of Characters.
  873. * isatty: (libc)Is It a Terminal.
  874. * isblank: (libc)Classification of Characters.
  875. * iscanonical: (libc)Floating Point Classes.
  876. * iscntrl: (libc)Classification of Characters.
  877. * isdigit: (libc)Classification of Characters.
  878. * iseqsig: (libc)FP Comparison Functions.
  879. * isfinite: (libc)Floating Point Classes.
  880. * isgraph: (libc)Classification of Characters.
  881. * isgreaterequal: (libc)FP Comparison Functions.
  882. * isgreater: (libc)FP Comparison Functions.
  883. * ISIG: (libc)Local Modes.
  884. * isinff: (libc)Floating Point Classes.
  885. * isinf: (libc)Floating Point Classes.
  886. * isinfl: (libc)Floating Point Classes.
  887. * islessequal: (libc)FP Comparison Functions.
  888. * islessgreater: (libc)FP Comparison Functions.
  889. * isless: (libc)FP Comparison Functions.
  890. * islower: (libc)Classification of Characters.
  891. * isnanf: (libc)Floating Point Classes.
  892. * isnan: (libc)Floating Point Classes.
  893. * isnan: (libc)Floating Point Classes.
  894. * isnanl: (libc)Floating Point Classes.
  895. * isnormal: (libc)Floating Point Classes.
  896. * isprint: (libc)Classification of Characters.
  897. * ispunct: (libc)Classification of Characters.
  898. * issignaling: (libc)Floating Point Classes.
  899. * isspace: (libc)Classification of Characters.
  900. * issubnormal: (libc)Floating Point Classes.
  901. * ISTRIP: (libc)Input Modes.
  902. * isunordered: (libc)FP Comparison Functions.
  903. * isupper: (libc)Classification of Characters.
  904. * iswalnum: (libc)Classification of Wide Characters.
  905. * iswalpha: (libc)Classification of Wide Characters.
  906. * iswblank: (libc)Classification of Wide Characters.
  907. * iswcntrl: (libc)Classification of Wide Characters.
  908. * iswctype: (libc)Classification of Wide Characters.
  909. * iswdigit: (libc)Classification of Wide Characters.
  910. * iswgraph: (libc)Classification of Wide Characters.
  911. * iswlower: (libc)Classification of Wide Characters.
  912. * iswprint: (libc)Classification of Wide Characters.
  913. * iswpunct: (libc)Classification of Wide Characters.
  914. * iswspace: (libc)Classification of Wide Characters.
  915. * iswupper: (libc)Classification of Wide Characters.
  916. * iswxdigit: (libc)Classification of Wide Characters.
  917. * isxdigit: (libc)Classification of Characters.
  918. * iszero: (libc)Floating Point Classes.
  919. * IXANY: (libc)Input Modes.
  920. * IXOFF: (libc)Input Modes.
  921. * IXON: (libc)Input Modes.
  922. * j0f: (libc)Special Functions.
  923. * j0: (libc)Special Functions.
  924. * j0l: (libc)Special Functions.
  925. * j1f: (libc)Special Functions.
  926. * j1: (libc)Special Functions.
  927. * j1l: (libc)Special Functions.
  928. * jnf: (libc)Special Functions.
  929. * jn: (libc)Special Functions.
  930. * jnl: (libc)Special Functions.
  931. * jrand48: (libc)SVID Random.
  932. * jrand48_r: (libc)SVID Random.
  933. * kill: (libc)Signaling Another Process.
  934. * killpg: (libc)Signaling Another Process.
  935. * l64a: (libc)Encode Binary Data.
  936. * labs: (libc)Absolute Value.
  937. * lcong48: (libc)SVID Random.
  938. * lcong48_r: (libc)SVID Random.
  939. * L_ctermid: (libc)Identifying the Terminal.
  940. * L_cuserid: (libc)Who Logged In.
  941. * ldexpf: (libc)Normalization Functions.
  942. * ldexp: (libc)Normalization Functions.
  943. * ldexpl: (libc)Normalization Functions.
  944. * ldiv: (libc)Integer Division.
  945. * lfind: (libc)Array Search Function.
  946. * lgammaf: (libc)Special Functions.
  947. * lgammaf_r: (libc)Special Functions.
  948. * lgamma: (libc)Special Functions.
  949. * lgammal: (libc)Special Functions.
  950. * lgammal_r: (libc)Special Functions.
  951. * lgamma_r: (libc)Special Functions.
  952. * LINE_MAX: (libc)Utility Limits.
  953. * link: (libc)Hard Links.
  954. * LINK_MAX: (libc)Limits for Files.
  955. * lio_listio64: (libc)Asynchronous Reads/Writes.
  956. * lio_listio: (libc)Asynchronous Reads/Writes.
  957. * listen: (libc)Listening.
  958. * llabs: (libc)Absolute Value.
  959. * lldiv: (libc)Integer Division.
  960. * llogbf: (libc)Exponents and Logarithms.
  961. * llogb: (libc)Exponents and Logarithms.
  962. * llogbl: (libc)Exponents and Logarithms.
  963. * llrintf: (libc)Rounding Functions.
  964. * llrint: (libc)Rounding Functions.
  965. * llrintl: (libc)Rounding Functions.
  966. * llroundf: (libc)Rounding Functions.
  967. * llround: (libc)Rounding Functions.
  968. * llroundl: (libc)Rounding Functions.
  969. * localeconv: (libc)The Lame Way to Locale Data.
  970. * localtime: (libc)Broken-down Time.
  971. * localtime_r: (libc)Broken-down Time.
  972. * log10f: (libc)Exponents and Logarithms.
  973. * log10: (libc)Exponents and Logarithms.
  974. * log10l: (libc)Exponents and Logarithms.
  975. * log1pf: (libc)Exponents and Logarithms.
  976. * log1p: (libc)Exponents and Logarithms.
  977. * log1pl: (libc)Exponents and Logarithms.
  978. * log2f: (libc)Exponents and Logarithms.
  979. * log2: (libc)Exponents and Logarithms.
  980. * log2l: (libc)Exponents and Logarithms.
  981. * logbf: (libc)Exponents and Logarithms.
  982. * logb: (libc)Exponents and Logarithms.
  983. * logbl: (libc)Exponents and Logarithms.
  984. * logf: (libc)Exponents and Logarithms.
  985. * login: (libc)Logging In and Out.
  986. * login_tty: (libc)Logging In and Out.
  987. * log: (libc)Exponents and Logarithms.
  988. * logl: (libc)Exponents and Logarithms.
  989. * logout: (libc)Logging In and Out.
  990. * logwtmp: (libc)Logging In and Out.
  991. * longjmp: (libc)Non-Local Details.
  992. * lrand48: (libc)SVID Random.
  993. * lrand48_r: (libc)SVID Random.
  994. * lrintf: (libc)Rounding Functions.
  995. * lrint: (libc)Rounding Functions.
  996. * lrintl: (libc)Rounding Functions.
  997. * lroundf: (libc)Rounding Functions.
  998. * lround: (libc)Rounding Functions.
  999. * lroundl: (libc)Rounding Functions.
  1000. * lsearch: (libc)Array Search Function.
  1001. * lseek64: (libc)File Position Primitive.
  1002. * lseek: (libc)File Position Primitive.
  1003. * lstat64: (libc)Reading Attributes.
  1004. * lstat: (libc)Reading Attributes.
  1005. * L_tmpnam: (libc)Temporary Files.
  1006. * lutimes: (libc)File Times.
  1007. * madvise: (libc)Memory-mapped I/O.
  1008. * makecontext: (libc)System V contexts.
  1009. * mallinfo: (libc)Statistics of Malloc.
  1010. * malloc: (libc)Basic Allocation.
  1011. * mallopt: (libc)Malloc Tunable Parameters.
  1012. * MAX_CANON: (libc)Limits for Files.
  1013. * MAX_INPUT: (libc)Limits for Files.
  1014. * MAXNAMLEN: (libc)Limits for Files.
  1015. * MAXSYMLINKS: (libc)Symbolic Links.
  1016. * MB_CUR_MAX: (libc)Selecting the Conversion.
  1017. * mblen: (libc)Non-reentrant Character Conversion.
  1018. * MB_LEN_MAX: (libc)Selecting the Conversion.
  1019. * mbrlen: (libc)Converting a Character.
  1020. * mbrtowc: (libc)Converting a Character.
  1021. * mbsinit: (libc)Keeping the state.
  1022. * mbsnrtowcs: (libc)Converting Strings.
  1023. * mbsrtowcs: (libc)Converting Strings.
  1024. * mbstowcs: (libc)Non-reentrant String Conversion.
  1025. * mbtowc: (libc)Non-reentrant Character Conversion.
  1026. * mcheck: (libc)Heap Consistency Checking.
  1027. * MDMBUF: (libc)Control Modes.
  1028. * memalign: (libc)Aligned Memory Blocks.
  1029. * memccpy: (libc)Copying Strings and Arrays.
  1030. * memchr: (libc)Search Functions.
  1031. * memcmp: (libc)String/Array Comparison.
  1032. * memcpy: (libc)Copying Strings and Arrays.
  1033. * memfrob: (libc)Trivial Encryption.
  1034. * memmem: (libc)Search Functions.
  1035. * memmove: (libc)Copying Strings and Arrays.
  1036. * mempcpy: (libc)Copying Strings and Arrays.
  1037. * memrchr: (libc)Search Functions.
  1038. * memset: (libc)Copying Strings and Arrays.
  1039. * mkdir: (libc)Creating Directories.
  1040. * mkdtemp: (libc)Temporary Files.
  1041. * mkfifo: (libc)FIFO Special Files.
  1042. * mknod: (libc)Making Special Files.
  1043. * mkstemp: (libc)Temporary Files.
  1044. * mktemp: (libc)Temporary Files.
  1045. * mktime: (libc)Broken-down Time.
  1046. * mlockall: (libc)Page Lock Functions.
  1047. * mlock: (libc)Page Lock Functions.
  1048. * mmap64: (libc)Memory-mapped I/O.
  1049. * mmap: (libc)Memory-mapped I/O.
  1050. * modff: (libc)Rounding Functions.
  1051. * modf: (libc)Rounding Functions.
  1052. * modfl: (libc)Rounding Functions.
  1053. * mount: (libc)Mount-Unmount-Remount.
  1054. * mprobe: (libc)Heap Consistency Checking.
  1055. * mrand48: (libc)SVID Random.
  1056. * mrand48_r: (libc)SVID Random.
  1057. * mremap: (libc)Memory-mapped I/O.
  1058. * MSG_DONTROUTE: (libc)Socket Data Options.
  1059. * MSG_OOB: (libc)Socket Data Options.
  1060. * MSG_PEEK: (libc)Socket Data Options.
  1061. * msync: (libc)Memory-mapped I/O.
  1062. * mtrace: (libc)Tracing malloc.
  1063. * munlockall: (libc)Page Lock Functions.
  1064. * munlock: (libc)Page Lock Functions.
  1065. * munmap: (libc)Memory-mapped I/O.
  1066. * muntrace: (libc)Tracing malloc.
  1067. * NAME_MAX: (libc)Limits for Files.
  1068. * nanf: (libc)FP Bit Twiddling.
  1069. * nan: (libc)FP Bit Twiddling.
  1070. * NAN: (libc)Infinity and NaN.
  1071. * nanl: (libc)FP Bit Twiddling.
  1072. * nanosleep: (libc)Sleeping.
  1073. * NCCS: (libc)Mode Data Types.
  1074. * nearbyintf: (libc)Rounding Functions.
  1075. * nearbyint: (libc)Rounding Functions.
  1076. * nearbyintl: (libc)Rounding Functions.
  1077. * nextafterf: (libc)FP Bit Twiddling.
  1078. * nextafter: (libc)FP Bit Twiddling.
  1079. * nextafterl: (libc)FP Bit Twiddling.
  1080. * nextdownf: (libc)FP Bit Twiddling.
  1081. * nextdown: (libc)FP Bit Twiddling.
  1082. * nextdownl: (libc)FP Bit Twiddling.
  1083. * nexttowardf: (libc)FP Bit Twiddling.
  1084. * nexttoward: (libc)FP Bit Twiddling.
  1085. * nexttowardl: (libc)FP Bit Twiddling.
  1086. * nextupf: (libc)FP Bit Twiddling.
  1087. * nextup: (libc)FP Bit Twiddling.
  1088. * nextupl: (libc)FP Bit Twiddling.
  1089. * nftw64: (libc)Working with Directory Trees.
  1090. * nftw: (libc)Working with Directory Trees.
  1091. * ngettext: (libc)Advanced gettext functions.
  1092. * NGROUPS_MAX: (libc)General Limits.
  1093. * nice: (libc)Traditional Scheduling Functions.
  1094. * nl_langinfo: (libc)The Elegant and Fast Way.
  1095. * NOFLSH: (libc)Local Modes.
  1096. * NOKERNINFO: (libc)Local Modes.
  1097. * nrand48: (libc)SVID Random.
  1098. * nrand48_r: (libc)SVID Random.
  1099. * NSIG: (libc)Standard Signals.
  1100. * ntohl: (libc)Byte Order.
  1101. * ntohs: (libc)Byte Order.
  1102. * ntp_adjtime: (libc)High Accuracy Clock.
  1103. * ntp_gettime: (libc)High Accuracy Clock.
  1104. * NULL: (libc)Null Pointer Constant.
  1105. * O_ACCMODE: (libc)Access Modes.
  1106. * O_APPEND: (libc)Operating Modes.
  1107. * O_ASYNC: (libc)Operating Modes.
  1108. * obstack_1grow_fast: (libc)Extra Fast Growing.
  1109. * obstack_1grow: (libc)Growing Objects.
  1110. * obstack_alignment_mask: (libc)Obstacks Data Alignment.
  1111. * obstack_alloc: (libc)Allocation in an Obstack.
  1112. * obstack_base: (libc)Status of an Obstack.
  1113. * obstack_blank_fast: (libc)Extra Fast Growing.
  1114. * obstack_blank: (libc)Growing Objects.
  1115. * obstack_chunk_size: (libc)Obstack Chunks.
  1116. * obstack_copy0: (libc)Allocation in an Obstack.
  1117. * obstack_copy: (libc)Allocation in an Obstack.
  1118. * obstack_finish: (libc)Growing Objects.
  1119. * obstack_free: (libc)Freeing Obstack Objects.
  1120. * obstack_grow0: (libc)Growing Objects.
  1121. * obstack_grow: (libc)Growing Objects.
  1122. * obstack_init: (libc)Preparing for Obstacks.
  1123. * obstack_int_grow_fast: (libc)Extra Fast Growing.
  1124. * obstack_int_grow: (libc)Growing Objects.
  1125. * obstack_next_free: (libc)Status of an Obstack.
  1126. * obstack_object_size: (libc)Growing Objects.
  1127. * obstack_object_size: (libc)Status of an Obstack.
  1128. * obstack_printf: (libc)Dynamic Output.
  1129. * obstack_ptr_grow_fast: (libc)Extra Fast Growing.
  1130. * obstack_ptr_grow: (libc)Growing Objects.
  1131. * obstack_room: (libc)Extra Fast Growing.
  1132. * obstack_vprintf: (libc)Variable Arguments Output.
  1133. * O_CREAT: (libc)Open-time Flags.
  1134. * O_EXCL: (libc)Open-time Flags.
  1135. * O_EXEC: (libc)Access Modes.
  1136. * O_EXLOCK: (libc)Open-time Flags.
  1137. * offsetof: (libc)Structure Measurement.
  1138. * O_FSYNC: (libc)Operating Modes.
  1139. * O_IGNORE_CTTY: (libc)Open-time Flags.
  1140. * O_NDELAY: (libc)Operating Modes.
  1141. * on_exit: (libc)Cleanups on Exit.
  1142. * ONLCR: (libc)Output Modes.
  1143. * O_NOATIME: (libc)Operating Modes.
  1144. * O_NOCTTY: (libc)Open-time Flags.
  1145. * ONOEOT: (libc)Output Modes.
  1146. * O_NOLINK: (libc)Open-time Flags.
  1147. * O_NONBLOCK: (libc)Open-time Flags.
  1148. * O_NONBLOCK: (libc)Operating Modes.
  1149. * O_NOTRANS: (libc)Open-time Flags.
  1150. * open64: (libc)Opening and Closing Files.
  1151. * opendir: (libc)Opening a Directory.
  1152. * open: (libc)Opening and Closing Files.
  1153. * openlog: (libc)openlog.
  1154. * OPEN_MAX: (libc)General Limits.
  1155. * open_memstream: (libc)String Streams.
  1156. * openpty: (libc)Pseudo-Terminal Pairs.
  1157. * OPOST: (libc)Output Modes.
  1158. * O_RDONLY: (libc)Access Modes.
  1159. * O_RDWR: (libc)Access Modes.
  1160. * O_READ: (libc)Access Modes.
  1161. * O_SHLOCK: (libc)Open-time Flags.
  1162. * O_SYNC: (libc)Operating Modes.
  1163. * O_TRUNC: (libc)Open-time Flags.
  1164. * O_WRITE: (libc)Access Modes.
  1165. * O_WRONLY: (libc)Access Modes.
  1166. * OXTABS: (libc)Output Modes.
  1167. * PA_FLAG_MASK: (libc)Parsing a Template String.
  1168. * PARENB: (libc)Control Modes.
  1169. * PARMRK: (libc)Input Modes.
  1170. * PARODD: (libc)Control Modes.
  1171. * parse_printf_format: (libc)Parsing a Template String.
  1172. * pathconf: (libc)Pathconf.
  1173. * PATH_MAX: (libc)Limits for Files.
  1174. * _PATH_UTMP: (libc)Manipulating the Database.
  1175. * _PATH_WTMP: (libc)Manipulating the Database.
  1176. * pause: (libc)Using Pause.
  1177. * pclose: (libc)Pipe to a Subprocess.
  1178. * PENDIN: (libc)Local Modes.
  1179. * perror: (libc)Error Messages.
  1180. * PF_FILE: (libc)Local Namespace Details.
  1181. * PF_INET6: (libc)Internet Namespace.
  1182. * PF_INET: (libc)Internet Namespace.
  1183. * PF_LOCAL: (libc)Local Namespace Details.
  1184. * PF_UNIX: (libc)Local Namespace Details.
  1185. * PIPE_BUF: (libc)Limits for Files.
  1186. * pipe: (libc)Creating a Pipe.
  1187. * popen: (libc)Pipe to a Subprocess.
  1188. * _POSIX2_C_DEV: (libc)System Options.
  1189. * _POSIX2_C_VERSION: (libc)Version Supported.
  1190. * _POSIX2_FORT_DEV: (libc)System Options.
  1191. * _POSIX2_FORT_RUN: (libc)System Options.
  1192. * _POSIX2_LOCALEDEF: (libc)System Options.
  1193. * _POSIX2_SW_DEV: (libc)System Options.
  1194. * _POSIX_CHOWN_RESTRICTED: (libc)Options for Files.
  1195. * posix_fallocate64: (libc)Storage Allocation.
  1196. * posix_fallocate: (libc)Storage Allocation.
  1197. * _POSIX_JOB_CONTROL: (libc)System Options.
  1198. * posix_memalign: (libc)Aligned Memory Blocks.
  1199. * _POSIX_NO_TRUNC: (libc)Options for Files.
  1200. * _POSIX_SAVED_IDS: (libc)System Options.
  1201. * _POSIX_VDISABLE: (libc)Options for Files.
  1202. * _POSIX_VERSION: (libc)Version Supported.
  1203. * pow10f: (libc)Exponents and Logarithms.
  1204. * pow10: (libc)Exponents and Logarithms.
  1205. * pow10l: (libc)Exponents and Logarithms.
  1206. * powf: (libc)Exponents and Logarithms.
  1207. * pow: (libc)Exponents and Logarithms.
  1208. * powl: (libc)Exponents and Logarithms.
  1209. * __ppc_get_timebase_freq: (libc)PowerPC.
  1210. * __ppc_get_timebase: (libc)PowerPC.
  1211. * __ppc_mdoio: (libc)PowerPC.
  1212. * __ppc_mdoom: (libc)PowerPC.
  1213. * __ppc_set_ppr_low: (libc)PowerPC.
  1214. * __ppc_set_ppr_med_high: (libc)PowerPC.
  1215. * __ppc_set_ppr_med: (libc)PowerPC.
  1216. * __ppc_set_ppr_med_low: (libc)PowerPC.
  1217. * __ppc_set_ppr_very_low: (libc)PowerPC.
  1218. * __ppc_yield: (libc)PowerPC.
  1219. * pread64: (libc)I/O Primitives.
  1220. * pread: (libc)I/O Primitives.
  1221. * printf: (libc)Formatted Output Functions.
  1222. * printf_size_info: (libc)Predefined Printf Handlers.
  1223. * printf_size: (libc)Predefined Printf Handlers.
  1224. * psignal: (libc)Signal Messages.
  1225. * pthread_getattr_default_np: (libc)Default Thread Attributes.
  1226. * pthread_getspecific: (libc)Thread-specific Data.
  1227. * pthread_key_create: (libc)Thread-specific Data.
  1228. * pthread_key_delete: (libc)Thread-specific Data.
  1229. * pthread_setattr_default_np: (libc)Default Thread Attributes.
  1230. * pthread_setspecific: (libc)Thread-specific Data.
  1231. * P_tmpdir: (libc)Temporary Files.
  1232. * ptsname: (libc)Allocation.
  1233. * ptsname_r: (libc)Allocation.
  1234. * putchar: (libc)Simple Output.
  1235. * putchar_unlocked: (libc)Simple Output.
  1236. * putc: (libc)Simple Output.
  1237. * putc_unlocked: (libc)Simple Output.
  1238. * putenv: (libc)Environment Access.
  1239. * putpwent: (libc)Writing a User Entry.
  1240. * puts: (libc)Simple Output.
  1241. * pututline: (libc)Manipulating the Database.
  1242. * pututxline: (libc)XPG Functions.
  1243. * putwchar: (libc)Simple Output.
  1244. * putwchar_unlocked: (libc)Simple Output.
  1245. * putwc: (libc)Simple Output.
  1246. * putwc_unlocked: (libc)Simple Output.
  1247. * putw: (libc)Simple Output.
  1248. * pwrite64: (libc)I/O Primitives.
  1249. * pwrite: (libc)I/O Primitives.
  1250. * qecvt: (libc)System V Number Conversion.
  1251. * qecvt_r: (libc)System V Number Conversion.
  1252. * qfcvt: (libc)System V Number Conversion.
  1253. * qfcvt_r: (libc)System V Number Conversion.
  1254. * qgcvt: (libc)System V Number Conversion.
  1255. * qsort: (libc)Array Sort Function.
  1256. * raise: (libc)Signaling Yourself.
  1257. * rand: (libc)ISO Random.
  1258. * RAND_MAX: (libc)ISO Random.
  1259. * random: (libc)BSD Random.
  1260. * random_r: (libc)BSD Random.
  1261. * rand_r: (libc)ISO Random.
  1262. * rawmemchr: (libc)Search Functions.
  1263. * readdir64: (libc)Reading/Closing Directory.
  1264. * readdir64_r: (libc)Reading/Closing Directory.
  1265. * readdir: (libc)Reading/Closing Directory.
  1266. * readdir_r: (libc)Reading/Closing Directory.
  1267. * read: (libc)I/O Primitives.
  1268. * readlink: (libc)Symbolic Links.
  1269. * readv: (libc)Scatter-Gather.
  1270. * realloc: (libc)Changing Block Size.
  1271. * realpath: (libc)Symbolic Links.
  1272. * recvfrom: (libc)Receiving Datagrams.
  1273. * recv: (libc)Receiving Data.
  1274. * recvmsg: (libc)Receiving Datagrams.
  1275. * RE_DUP_MAX: (libc)General Limits.
  1276. * regcomp: (libc)POSIX Regexp Compilation.
  1277. * regerror: (libc)Regexp Cleanup.
  1278. * regexec: (libc)Matching POSIX Regexps.
  1279. * regfree: (libc)Regexp Cleanup.
  1280. * register_printf_function: (libc)Registering New Conversions.
  1281. * remainderf: (libc)Remainder Functions.
  1282. * remainder: (libc)Remainder Functions.
  1283. * remainderl: (libc)Remainder Functions.
  1284. * remove: (libc)Deleting Files.
  1285. * rename: (libc)Renaming Files.
  1286. * rewinddir: (libc)Random Access Directory.
  1287. * rewind: (libc)File Positioning.
  1288. * rindex: (libc)Search Functions.
  1289. * rintf: (libc)Rounding Functions.
  1290. * rint: (libc)Rounding Functions.
  1291. * rintl: (libc)Rounding Functions.
  1292. * RLIM_INFINITY: (libc)Limits on Resources.
  1293. * rmdir: (libc)Deleting Files.
  1294. * R_OK: (libc)Testing File Access.
  1295. * roundevenf: (libc)Rounding Functions.
  1296. * roundeven: (libc)Rounding Functions.
  1297. * roundevenl: (libc)Rounding Functions.
  1298. * roundf: (libc)Rounding Functions.
  1299. * round: (libc)Rounding Functions.
  1300. * roundl: (libc)Rounding Functions.
  1301. * rpmatch: (libc)Yes-or-No Questions.
  1302. * SA_NOCLDSTOP: (libc)Flags for Sigaction.
  1303. * SA_ONSTACK: (libc)Flags for Sigaction.
  1304. * SA_RESTART: (libc)Flags for Sigaction.
  1305. * sbrk: (libc)Resizing the Data Segment.
  1306. * scalbf: (libc)Normalization Functions.
  1307. * scalb: (libc)Normalization Functions.
  1308. * scalbl: (libc)Normalization Functions.
  1309. * scalblnf: (libc)Normalization Functions.
  1310. * scalbln: (libc)Normalization Functions.
  1311. * scalblnl: (libc)Normalization Functions.
  1312. * scalbnf: (libc)Normalization Functions.
  1313. * scalbn: (libc)Normalization Functions.
  1314. * scalbnl: (libc)Normalization Functions.
  1315. * scandir64: (libc)Scanning Directory Content.
  1316. * scandir: (libc)Scanning Directory Content.
  1317. * scanf: (libc)Formatted Input Functions.
  1318. * sched_getaffinity: (libc)CPU Affinity.
  1319. * sched_getparam: (libc)Basic Scheduling Functions.
  1320. * sched_get_priority_max: (libc)Basic Scheduling Functions.
  1321. * sched_get_priority_min: (libc)Basic Scheduling Functions.
  1322. * sched_getscheduler: (libc)Basic Scheduling Functions.
  1323. * sched_rr_get_interval: (libc)Basic Scheduling Functions.
  1324. * sched_setaffinity: (libc)CPU Affinity.
  1325. * sched_setparam: (libc)Basic Scheduling Functions.
  1326. * sched_setscheduler: (libc)Basic Scheduling Functions.
  1327. * sched_yield: (libc)Basic Scheduling Functions.
  1328. * secure_getenv: (libc)Environment Access.
  1329. * seed48: (libc)SVID Random.
  1330. * seed48_r: (libc)SVID Random.
  1331. * SEEK_CUR: (libc)File Positioning.
  1332. * seekdir: (libc)Random Access Directory.
  1333. * SEEK_END: (libc)File Positioning.
  1334. * SEEK_SET: (libc)File Positioning.
  1335. * select: (libc)Waiting for I/O.
  1336. * sem_close: (libc)Semaphores.
  1337. * semctl: (libc)Semaphores.
  1338. * sem_destroy: (libc)Semaphores.
  1339. * semget: (libc)Semaphores.
  1340. * sem_getvalue: (libc)Semaphores.
  1341. * sem_init: (libc)Semaphores.
  1342. * sem_open: (libc)Semaphores.
  1343. * semop: (libc)Semaphores.
  1344. * sem_post: (libc)Semaphores.
  1345. * semtimedop: (libc)Semaphores.
  1346. * sem_timedwait: (libc)Semaphores.
  1347. * sem_trywait: (libc)Semaphores.
  1348. * sem_unlink: (libc)Semaphores.
  1349. * sem_wait: (libc)Semaphores.
  1350. * send: (libc)Sending Data.
  1351. * sendmsg: (libc)Receiving Datagrams.
  1352. * sendto: (libc)Sending Datagrams.
  1353. * setbuffer: (libc)Controlling Buffering.
  1354. * setbuf: (libc)Controlling Buffering.
  1355. * setcontext: (libc)System V contexts.
  1356. * setdomainname: (libc)Host Identification.
  1357. * setegid: (libc)Setting Groups.
  1358. * setenv: (libc)Environment Access.
  1359. * seteuid: (libc)Setting User ID.
  1360. * setfsent: (libc)fstab.
  1361. * setgid: (libc)Setting Groups.
  1362. * setgrent: (libc)Scanning All Groups.
  1363. * setgroups: (libc)Setting Groups.
  1364. * sethostent: (libc)Host Names.
  1365. * sethostid: (libc)Host Identification.
  1366. * sethostname: (libc)Host Identification.
  1367. * setitimer: (libc)Setting an Alarm.
  1368. * setjmp: (libc)Non-Local Details.
  1369. * setkey: (libc)DES Encryption.
  1370. * setkey_r: (libc)DES Encryption.
  1371. * setlinebuf: (libc)Controlling Buffering.
  1372. * setlocale: (libc)Setting the Locale.
  1373. * setlogmask: (libc)setlogmask.
  1374. * setmntent: (libc)mtab.
  1375. * setnetent: (libc)Networks Database.
  1376. * setnetgrent: (libc)Lookup Netgroup.
  1377. * setpayloadf: (libc)FP Bit Twiddling.
  1378. * setpayload: (libc)FP Bit Twiddling.
  1379. * setpayloadl: (libc)FP Bit Twiddling.
  1380. * setpayloadsigf: (libc)FP Bit Twiddling.
  1381. * setpayloadsig: (libc)FP Bit Twiddling.
  1382. * setpayloadsigl: (libc)FP Bit Twiddling.
  1383. * setpgid: (libc)Process Group Functions.
  1384. * setpgrp: (libc)Process Group Functions.
  1385. * setpriority: (libc)Traditional Scheduling Functions.
  1386. * setprotoent: (libc)Protocols Database.
  1387. * setpwent: (libc)Scanning All Users.
  1388. * setregid: (libc)Setting Groups.
  1389. * setreuid: (libc)Setting User ID.
  1390. * setrlimit64: (libc)Limits on Resources.
  1391. * setrlimit: (libc)Limits on Resources.
  1392. * setservent: (libc)Services Database.
  1393. * setsid: (libc)Process Group Functions.
  1394. * setsockopt: (libc)Socket Option Functions.
  1395. * setstate: (libc)BSD Random.
  1396. * setstate_r: (libc)BSD Random.
  1397. * settimeofday: (libc)High-Resolution Calendar.
  1398. * setuid: (libc)Setting User ID.
  1399. * setutent: (libc)Manipulating the Database.
  1400. * setutxent: (libc)XPG Functions.
  1401. * setvbuf: (libc)Controlling Buffering.
  1402. * shm_open: (libc)Memory-mapped I/O.
  1403. * shm_unlink: (libc)Memory-mapped I/O.
  1404. * shutdown: (libc)Closing a Socket.
  1405. * S_IFMT: (libc)Testing File Type.
  1406. * SIGABRT: (libc)Program Error Signals.
  1407. * sigaction: (libc)Advanced Signal Handling.
  1408. * sigaddset: (libc)Signal Sets.
  1409. * SIGALRM: (libc)Alarm Signals.
  1410. * sigaltstack: (libc)Signal Stack.
  1411. * sigblock: (libc)BSD Signal Handling.
  1412. * SIGBUS: (libc)Program Error Signals.
  1413. * SIGCHLD: (libc)Job Control Signals.
  1414. * SIGCLD: (libc)Job Control Signals.
  1415. * SIGCONT: (libc)Job Control Signals.
  1416. * sigdelset: (libc)Signal Sets.
  1417. * sigemptyset: (libc)Signal Sets.
  1418. * SIGEMT: (libc)Program Error Signals.
  1419. * SIG_ERR: (libc)Basic Signal Handling.
  1420. * sigfillset: (libc)Signal Sets.
  1421. * SIGFPE: (libc)Program Error Signals.
  1422. * SIGHUP: (libc)Termination Signals.
  1423. * SIGILL: (libc)Program Error Signals.
  1424. * SIGINFO: (libc)Miscellaneous Signals.
  1425. * siginterrupt: (libc)BSD Signal Handling.
  1426. * SIGINT: (libc)Termination Signals.
  1427. * SIGIO: (libc)Asynchronous I/O Signals.
  1428. * SIGIOT: (libc)Program Error Signals.
  1429. * sigismember: (libc)Signal Sets.
  1430. * SIGKILL: (libc)Termination Signals.
  1431. * siglongjmp: (libc)Non-Local Exits and Signals.
  1432. * SIGLOST: (libc)Operation Error Signals.
  1433. * sigmask: (libc)BSD Signal Handling.
  1434. * signal: (libc)Basic Signal Handling.
  1435. * signbit: (libc)FP Bit Twiddling.
  1436. * significandf: (libc)Normalization Functions.
  1437. * significand: (libc)Normalization Functions.
  1438. * significandl: (libc)Normalization Functions.
  1439. * sigpause: (libc)BSD Signal Handling.
  1440. * sigpending: (libc)Checking for Pending Signals.
  1441. * SIGPIPE: (libc)Operation Error Signals.
  1442. * SIGPOLL: (libc)Asynchronous I/O Signals.
  1443. * sigprocmask: (libc)Process Signal Mask.
  1444. * SIGPROF: (libc)Alarm Signals.
  1445. * SIGQUIT: (libc)Termination Signals.
  1446. * SIGSEGV: (libc)Program Error Signals.
  1447. * sigsetjmp: (libc)Non-Local Exits and Signals.
  1448. * sigsetmask: (libc)BSD Signal Handling.
  1449. * sigstack: (libc)Signal Stack.
  1450. * SIGSTOP: (libc)Job Control Signals.
  1451. * sigsuspend: (libc)Sigsuspend.
  1452. * SIGSYS: (libc)Program Error Signals.
  1453. * SIGTERM: (libc)Termination Signals.
  1454. * SIGTRAP: (libc)Program Error Signals.
  1455. * SIGTSTP: (libc)Job Control Signals.
  1456. * SIGTTIN: (libc)Job Control Signals.
  1457. * SIGTTOU: (libc)Job Control Signals.
  1458. * SIGURG: (libc)Asynchronous I/O Signals.
  1459. * SIGUSR1: (libc)Miscellaneous Signals.
  1460. * SIGUSR2: (libc)Miscellaneous Signals.
  1461. * SIGVTALRM: (libc)Alarm Signals.
  1462. * SIGWINCH: (libc)Miscellaneous Signals.
  1463. * SIGXCPU: (libc)Operation Error Signals.
  1464. * SIGXFSZ: (libc)Operation Error Signals.
  1465. * sincosf: (libc)Trig Functions.
  1466. * sincos: (libc)Trig Functions.
  1467. * sincosl: (libc)Trig Functions.
  1468. * sinf: (libc)Trig Functions.
  1469. * sinhf: (libc)Hyperbolic Functions.
  1470. * sinh: (libc)Hyperbolic Functions.
  1471. * sinhl: (libc)Hyperbolic Functions.
  1472. * sin: (libc)Trig Functions.
  1473. * sinl: (libc)Trig Functions.
  1474. * S_ISBLK: (libc)Testing File Type.
  1475. * S_ISCHR: (libc)Testing File Type.
  1476. * S_ISDIR: (libc)Testing File Type.
  1477. * S_ISFIFO: (libc)Testing File Type.
  1478. * S_ISLNK: (libc)Testing File Type.
  1479. * S_ISREG: (libc)Testing File Type.
  1480. * S_ISSOCK: (libc)Testing File Type.
  1481. * sleep: (libc)Sleeping.
  1482. * SNANF: (libc)Infinity and NaN.
  1483. * SNAN: (libc)Infinity and NaN.
  1484. * SNANL: (libc)Infinity and NaN.
  1485. * snprintf: (libc)Formatted Output Functions.
  1486. * SOCK_DGRAM: (libc)Communication Styles.
  1487. * socket: (libc)Creating a Socket.
  1488. * socketpair: (libc)Socket Pairs.
  1489. * SOCK_RAW: (libc)Communication Styles.
  1490. * SOCK_RDM: (libc)Communication Styles.
  1491. * SOCK_SEQPACKET: (libc)Communication Styles.
  1492. * SOCK_STREAM: (libc)Communication Styles.
  1493. * SOL_SOCKET: (libc)Socket-Level Options.
  1494. * sprintf: (libc)Formatted Output Functions.
  1495. * sqrtf: (libc)Exponents and Logarithms.
  1496. * sqrt: (libc)Exponents and Logarithms.
  1497. * sqrtl: (libc)Exponents and Logarithms.
  1498. * srand48: (libc)SVID Random.
  1499. * srand48_r: (libc)SVID Random.
  1500. * srand: (libc)ISO Random.
  1501. * srandom: (libc)BSD Random.
  1502. * srandom_r: (libc)BSD Random.
  1503. * sscanf: (libc)Formatted Input Functions.
  1504. * ssignal: (libc)Basic Signal Handling.
  1505. * SSIZE_MAX: (libc)General Limits.
  1506. * stat64: (libc)Reading Attributes.
  1507. * stat: (libc)Reading Attributes.
  1508. * stime: (libc)Simple Calendar Time.
  1509. * stpcpy: (libc)Copying Strings and Arrays.
  1510. * stpncpy: (libc)Truncating Strings.
  1511. * strcasecmp: (libc)String/Array Comparison.
  1512. * strcasestr: (libc)Search Functions.
  1513. * strcat: (libc)Concatenating Strings.
  1514. * strchr: (libc)Search Functions.
  1515. * strchrnul: (libc)Search Functions.
  1516. * strcmp: (libc)String/Array Comparison.
  1517. * strcoll: (libc)Collation Functions.
  1518. * strcpy: (libc)Copying Strings and Arrays.
  1519. * strcspn: (libc)Search Functions.
  1520. * strdupa: (libc)Copying Strings and Arrays.
  1521. * strdup: (libc)Copying Strings and Arrays.
  1522. * STREAM_MAX: (libc)General Limits.
  1523. * strerror: (libc)Error Messages.
  1524. * strerror_r: (libc)Error Messages.
  1525. * strfmon: (libc)Formatting Numbers.
  1526. * strfromd: (libc)Printing of Floats.
  1527. * strfromf: (libc)Printing of Floats.
  1528. * strfroml: (libc)Printing of Floats.
  1529. * strfry: (libc)strfry.
  1530. * strftime: (libc)Formatting Calendar Time.
  1531. * strlen: (libc)String Length.
  1532. * strncasecmp: (libc)String/Array Comparison.
  1533. * strncat: (libc)Truncating Strings.
  1534. * strncmp: (libc)String/Array Comparison.
  1535. * strncpy: (libc)Truncating Strings.
  1536. * strndupa: (libc)Truncating Strings.
  1537. * strndup: (libc)Truncating Strings.
  1538. * strnlen: (libc)String Length.
  1539. * strpbrk: (libc)Search Functions.
  1540. * strptime: (libc)Low-Level Time String Parsing.
  1541. * strrchr: (libc)Search Functions.
  1542. * strsep: (libc)Finding Tokens in a String.
  1543. * strsignal: (libc)Signal Messages.
  1544. * strspn: (libc)Search Functions.
  1545. * strstr: (libc)Search Functions.
  1546. * strtod: (libc)Parsing of Floats.
  1547. * strtof: (libc)Parsing of Floats.
  1548. * strtoimax: (libc)Parsing of Integers.
  1549. * strtok: (libc)Finding Tokens in a String.
  1550. * strtok_r: (libc)Finding Tokens in a String.
  1551. * strtold: (libc)Parsing of Floats.
  1552. * strtol: (libc)Parsing of Integers.
  1553. * strtoll: (libc)Parsing of Integers.
  1554. * strtoq: (libc)Parsing of Integers.
  1555. * strtoul: (libc)Parsing of Integers.
  1556. * strtoull: (libc)Parsing of Integers.
  1557. * strtoumax: (libc)Parsing of Integers.
  1558. * strtouq: (libc)Parsing of Integers.
  1559. * strverscmp: (libc)String/Array Comparison.
  1560. * strxfrm: (libc)Collation Functions.
  1561. * stty: (libc)BSD Terminal Modes.
  1562. * S_TYPEISMQ: (libc)Testing File Type.
  1563. * S_TYPEISSEM: (libc)Testing File Type.
  1564. * S_TYPEISSHM: (libc)Testing File Type.
  1565. * SUN_LEN: (libc)Local Namespace Details.
  1566. * swapcontext: (libc)System V contexts.
  1567. * swprintf: (libc)Formatted Output Functions.
  1568. * swscanf: (libc)Formatted Input Functions.
  1569. * symlink: (libc)Symbolic Links.
  1570. * sync: (libc)Synchronizing I/O.
  1571. * syscall: (libc)System Calls.
  1572. * sysconf: (libc)Sysconf Definition.
  1573. * sysctl: (libc)System Parameters.
  1574. * syslog: (libc)syslog; vsyslog.
  1575. * system: (libc)Running a Command.
  1576. * sysv_signal: (libc)Basic Signal Handling.
  1577. * tanf: (libc)Trig Functions.
  1578. * tanhf: (libc)Hyperbolic Functions.
  1579. * tanh: (libc)Hyperbolic Functions.
  1580. * tanhl: (libc)Hyperbolic Functions.
  1581. * tan: (libc)Trig Functions.
  1582. * tanl: (libc)Trig Functions.
  1583. * tcdrain: (libc)Line Control.
  1584. * tcflow: (libc)Line Control.
  1585. * tcflush: (libc)Line Control.
  1586. * tcgetattr: (libc)Mode Functions.
  1587. * tcgetpgrp: (libc)Terminal Access Functions.
  1588. * tcgetsid: (libc)Terminal Access Functions.
  1589. * tcsendbreak: (libc)Line Control.
  1590. * tcsetattr: (libc)Mode Functions.
  1591. * tcsetpgrp: (libc)Terminal Access Functions.
  1592. * tdelete: (libc)Tree Search Function.
  1593. * tdestroy: (libc)Tree Search Function.
  1594. * telldir: (libc)Random Access Directory.
  1595. * tempnam: (libc)Temporary Files.
  1596. * textdomain: (libc)Locating gettext catalog.
  1597. * tfind: (libc)Tree Search Function.
  1598. * tgammaf: (libc)Special Functions.
  1599. * tgamma: (libc)Special Functions.
  1600. * tgammal: (libc)Special Functions.
  1601. * timegm: (libc)Broken-down Time.
  1602. * time: (libc)Simple Calendar Time.
  1603. * timelocal: (libc)Broken-down Time.
  1604. * times: (libc)Processor Time.
  1605. * tmpfile64: (libc)Temporary Files.
  1606. * tmpfile: (libc)Temporary Files.
  1607. * TMP_MAX: (libc)Temporary Files.
  1608. * tmpnam: (libc)Temporary Files.
  1609. * tmpnam_r: (libc)Temporary Files.
  1610. * toascii: (libc)Case Conversion.
  1611. * _tolower: (libc)Case Conversion.
  1612. * tolower: (libc)Case Conversion.
  1613. * TOSTOP: (libc)Local Modes.
  1614. * totalorderf: (libc)FP Comparison Functions.
  1615. * totalorder: (libc)FP Comparison Functions.
  1616. * totalorderl: (libc)FP Comparison Functions.
  1617. * totalordermagf: (libc)FP Comparison Functions.
  1618. * totalordermag: (libc)FP Comparison Functions.
  1619. * totalordermagl: (libc)FP Comparison Functions.
  1620. * _toupper: (libc)Case Conversion.
  1621. * toupper: (libc)Case Conversion.
  1622. * towctrans: (libc)Wide Character Case Conversion.
  1623. * towlower: (libc)Wide Character Case Conversion.
  1624. * towupper: (libc)Wide Character Case Conversion.
  1625. * truncate64: (libc)File Size.
  1626. * truncate: (libc)File Size.
  1627. * truncf: (libc)Rounding Functions.
  1628. * trunc: (libc)Rounding Functions.
  1629. * truncl: (libc)Rounding Functions.
  1630. * tsearch: (libc)Tree Search Function.
  1631. * ttyname: (libc)Is It a Terminal.
  1632. * ttyname_r: (libc)Is It a Terminal.
  1633. * twalk: (libc)Tree Search Function.
  1634. * TZNAME_MAX: (libc)General Limits.
  1635. * tzset: (libc)Time Zone Functions.
  1636. * ufromfpf: (libc)Rounding Functions.
  1637. * ufromfp: (libc)Rounding Functions.
  1638. * ufromfpl: (libc)Rounding Functions.
  1639. * ufromfpxf: (libc)Rounding Functions.
  1640. * ufromfpx: (libc)Rounding Functions.
  1641. * ufromfpxl: (libc)Rounding Functions.
  1642. * ulimit: (libc)Limits on Resources.
  1643. * umask: (libc)Setting Permissions.
  1644. * umount2: (libc)Mount-Unmount-Remount.
  1645. * umount: (libc)Mount-Unmount-Remount.
  1646. * uname: (libc)Platform Type.
  1647. * ungetc: (libc)How Unread.
  1648. * ungetwc: (libc)How Unread.
  1649. * unlink: (libc)Deleting Files.
  1650. * unlockpt: (libc)Allocation.
  1651. * unsetenv: (libc)Environment Access.
  1652. * updwtmp: (libc)Manipulating the Database.
  1653. * utime: (libc)File Times.
  1654. * utimes: (libc)File Times.
  1655. * utmpname: (libc)Manipulating the Database.
  1656. * utmpxname: (libc)XPG Functions.
  1657. * va_arg: (libc)Argument Macros.
  1658. * __va_copy: (libc)Argument Macros.
  1659. * va_copy: (libc)Argument Macros.
  1660. * va_end: (libc)Argument Macros.
  1661. * valloc: (libc)Aligned Memory Blocks.
  1662. * vasprintf: (libc)Variable Arguments Output.
  1663. * va_start: (libc)Argument Macros.
  1664. * VDISCARD: (libc)Other Special.
  1665. * VDSUSP: (libc)Signal Characters.
  1666. * VEOF: (libc)Editing Characters.
  1667. * VEOL2: (libc)Editing Characters.
  1668. * VEOL: (libc)Editing Characters.
  1669. * VERASE: (libc)Editing Characters.
  1670. * verr: (libc)Error Messages.
  1671. * verrx: (libc)Error Messages.
  1672. * versionsort64: (libc)Scanning Directory Content.
  1673. * versionsort: (libc)Scanning Directory Content.
  1674. * vfork: (libc)Creating a Process.
  1675. * vfprintf: (libc)Variable Arguments Output.
  1676. * vfscanf: (libc)Variable Arguments Input.
  1677. * vfwprintf: (libc)Variable Arguments Output.
  1678. * vfwscanf: (libc)Variable Arguments Input.
  1679. * VINTR: (libc)Signal Characters.
  1680. * VKILL: (libc)Editing Characters.
  1681. * vlimit: (libc)Limits on Resources.
  1682. * VLNEXT: (libc)Other Special.
  1683. * VMIN: (libc)Noncanonical Input.
  1684. * vprintf: (libc)Variable Arguments Output.
  1685. * VQUIT: (libc)Signal Characters.
  1686. * VREPRINT: (libc)Editing Characters.
  1687. * vscanf: (libc)Variable Arguments Input.
  1688. * vsnprintf: (libc)Variable Arguments Output.
  1689. * vsprintf: (libc)Variable Arguments Output.
  1690. * vsscanf: (libc)Variable Arguments Input.
  1691. * VSTART: (libc)Start/Stop Characters.
  1692. * VSTATUS: (libc)Other Special.
  1693. * VSTOP: (libc)Start/Stop Characters.
  1694. * VSUSP: (libc)Signal Characters.
  1695. * vswprintf: (libc)Variable Arguments Output.
  1696. * vswscanf: (libc)Variable Arguments Input.
  1697. * vsyslog: (libc)syslog; vsyslog.
  1698. * VTIME: (libc)Noncanonical Input.
  1699. * vtimes: (libc)Resource Usage.
  1700. * vwarn: (libc)Error Messages.
  1701. * vwarnx: (libc)Error Messages.
  1702. * VWERASE: (libc)Editing Characters.
  1703. * vwprintf: (libc)Variable Arguments Output.
  1704. * vwscanf: (libc)Variable Arguments Input.
  1705. * wait3: (libc)BSD Wait Functions.
  1706. * wait4: (libc)Process Completion.
  1707. * wait: (libc)Process Completion.
  1708. * waitpid: (libc)Process Completion.
  1709. * warn: (libc)Error Messages.
  1710. * warnx: (libc)Error Messages.
  1711. * WCHAR_MAX: (libc)Extended Char Intro.
  1712. * WCHAR_MIN: (libc)Extended Char Intro.
  1713. * WCOREDUMP: (libc)Process Completion Status.
  1714. * wcpcpy: (libc)Copying Strings and Arrays.
  1715. * wcpncpy: (libc)Truncating Strings.
  1716. * wcrtomb: (libc)Converting a Character.
  1717. * wcscasecmp: (libc)String/Array Comparison.
  1718. * wcscat: (libc)Concatenating Strings.
  1719. * wcschr: (libc)Search Functions.
  1720. * wcschrnul: (libc)Search Functions.
  1721. * wcscmp: (libc)String/Array Comparison.
  1722. * wcscoll: (libc)Collation Functions.
  1723. * wcscpy: (libc)Copying Strings and Arrays.
  1724. * wcscspn: (libc)Search Functions.
  1725. * wcsdup: (libc)Copying Strings and Arrays.
  1726. * wcsftime: (libc)Formatting Calendar Time.
  1727. * wcslen: (libc)String Length.
  1728. * wcsncasecmp: (libc)String/Array Comparison.
  1729. * wcsncat: (libc)Truncating Strings.
  1730. * wcsncmp: (libc)String/Array Comparison.
  1731. * wcsncpy: (libc)Truncating Strings.
  1732. * wcsnlen: (libc)String Length.
  1733. * wcsnrtombs: (libc)Converting Strings.
  1734. * wcspbrk: (libc)Search Functions.
  1735. * wcsrchr: (libc)Search Functions.
  1736. * wcsrtombs: (libc)Converting Strings.
  1737. * wcsspn: (libc)Search Functions.
  1738. * wcsstr: (libc)Search Functions.
  1739. * wcstod: (libc)Parsing of Floats.
  1740. * wcstof: (libc)Parsing of Floats.
  1741. * wcstoimax: (libc)Parsing of Integers.
  1742. * wcstok: (libc)Finding Tokens in a String.
  1743. * wcstold: (libc)Parsing of Floats.
  1744. * wcstol: (libc)Parsing of Integers.
  1745. * wcstoll: (libc)Parsing of Integers.
  1746. * wcstombs: (libc)Non-reentrant String Conversion.
  1747. * wcstoq: (libc)Parsing of Integers.
  1748. * wcstoul: (libc)Parsing of Integers.
  1749. * wcstoull: (libc)Parsing of Integers.
  1750. * wcstoumax: (libc)Parsing of Integers.
  1751. * wcstouq: (libc)Parsing of Integers.
  1752. * wcswcs: (libc)Search Functions.
  1753. * wcsxfrm: (libc)Collation Functions.
  1754. * wctob: (libc)Converting a Character.
  1755. * wctomb: (libc)Non-reentrant Character Conversion.
  1756. * wctrans: (libc)Wide Character Case Conversion.
  1757. * wctype: (libc)Classification of Wide Characters.
  1758. * WEOF: (libc)EOF and Errors.
  1759. * WEOF: (libc)Extended Char Intro.
  1760. * WEXITSTATUS: (libc)Process Completion Status.
  1761. * WIFEXITED: (libc)Process Completion Status.
  1762. * WIFSIGNALED: (libc)Process Completion Status.
  1763. * WIFSTOPPED: (libc)Process Completion Status.
  1764. * wmemchr: (libc)Search Functions.
  1765. * wmemcmp: (libc)String/Array Comparison.
  1766. * wmemcpy: (libc)Copying Strings and Arrays.
  1767. * wmemmove: (libc)Copying Strings and Arrays.
  1768. * wmempcpy: (libc)Copying Strings and Arrays.
  1769. * wmemset: (libc)Copying Strings and Arrays.
  1770. * W_OK: (libc)Testing File Access.
  1771. * wordexp: (libc)Calling Wordexp.
  1772. * wordfree: (libc)Calling Wordexp.
  1773. * wprintf: (libc)Formatted Output Functions.
  1774. * write: (libc)I/O Primitives.
  1775. * writev: (libc)Scatter-Gather.
  1776. * wscanf: (libc)Formatted Input Functions.
  1777. * WSTOPSIG: (libc)Process Completion Status.
  1778. * WTERMSIG: (libc)Process Completion Status.
  1779. * X_OK: (libc)Testing File Access.
  1780. * y0f: (libc)Special Functions.
  1781. * y0: (libc)Special Functions.
  1782. * y0l: (libc)Special Functions.
  1783. * y1f: (libc)Special Functions.
  1784. * y1: (libc)Special Functions.
  1785. * y1l: (libc)Special Functions.
  1786. * ynf: (libc)Special Functions.
  1787. * yn: (libc)Special Functions.
  1788. * ynl: (libc)Special Functions.
  1789. END-INFO-DIR-ENTRY
  1790. 
  1791. File: libc.info, Node: Flags for Sigaction, Next: Initial Signal Actions, Prev: Sigaction Function Example, Up: Signal Actions
  1792. 24.3.5 Flags for ‘sigaction’
  1793. ----------------------------
  1794. The ‘sa_flags’ member of the ‘sigaction’ structure is a catch-all for
  1795. special features. Most of the time, ‘SA_RESTART’ is a good value to use
  1796. for this field.
  1797. The value of ‘sa_flags’ is interpreted as a bit mask. Thus, you
  1798. should choose the flags you want to set, OR those flags together, and
  1799. store the result in the ‘sa_flags’ member of your ‘sigaction’ structure.
  1800. Each signal number has its own set of flags. Each call to
  1801. ‘sigaction’ affects one particular signal number, and the flags that you
  1802. specify apply only to that particular signal.
  1803. In the GNU C Library, establishing a handler with ‘signal’ sets all
  1804. the flags to zero except for ‘SA_RESTART’, whose value depends on the
  1805. settings you have made with ‘siginterrupt’. *Note Interrupted
  1806. Primitives::, to see what this is about.
  1807. These macros are defined in the header file ‘signal.h’.
  1808. -- Macro: int SA_NOCLDSTOP
  1809. This flag is meaningful only for the ‘SIGCHLD’ signal. When the
  1810. flag is set, the system delivers the signal for a terminated child
  1811. process but not for one that is stopped. By default, ‘SIGCHLD’ is
  1812. delivered for both terminated children and stopped children.
  1813. Setting this flag for a signal other than ‘SIGCHLD’ has no effect.
  1814. -- Macro: int SA_ONSTACK
  1815. If this flag is set for a particular signal number, the system uses
  1816. the signal stack when delivering that kind of signal. *Note Signal
  1817. Stack::. If a signal with this flag arrives and you have not set a
  1818. signal stack, the system terminates the program with ‘SIGILL’.
  1819. -- Macro: int SA_RESTART
  1820. This flag controls what happens when a signal is delivered during
  1821. certain primitives (such as ‘open’, ‘read’ or ‘write’), and the
  1822. signal handler returns normally. There are two alternatives: the
  1823. library function can resume, or it can return failure with error
  1824. code ‘EINTR’.
  1825. The choice is controlled by the ‘SA_RESTART’ flag for the
  1826. particular kind of signal that was delivered. If the flag is set,
  1827. returning from a handler resumes the library function. If the flag
  1828. is clear, returning from a handler makes the function fail. *Note
  1829. Interrupted Primitives::.
  1830. 
  1831. File: libc.info, Node: Initial Signal Actions, Prev: Flags for Sigaction, Up: Signal Actions
  1832. 24.3.6 Initial Signal Actions
  1833. -----------------------------
  1834. When a new process is created (*note Creating a Process::), it inherits
  1835. handling of signals from its parent process. However, when you load a
  1836. new process image using the ‘exec’ function (*note Executing a File::),
  1837. any signals that you’ve defined your own handlers for revert to their
  1838. ‘SIG_DFL’ handling. (If you think about it a little, this makes sense;
  1839. the handler functions from the old program are specific to that program,
  1840. and aren’t even present in the address space of the new program image.)
  1841. Of course, the new program can establish its own handlers.
  1842. When a program is run by a shell, the shell normally sets the initial
  1843. actions for the child process to ‘SIG_DFL’ or ‘SIG_IGN’, as appropriate.
  1844. It’s a good idea to check to make sure that the shell has not set up an
  1845. initial action of ‘SIG_IGN’ before you establish your own signal
  1846. handlers.
  1847. Here is an example of how to establish a handler for ‘SIGHUP’, but
  1848. not if ‘SIGHUP’ is currently ignored:
  1849. struct sigaction temp;
  1850. sigaction (SIGHUP, NULL, &temp);
  1851. if (temp.sa_handler != SIG_IGN)
  1852. {
  1853. temp.sa_handler = handle_sighup;
  1854. sigemptyset (&temp.sa_mask);
  1855. sigaction (SIGHUP, &temp, NULL);
  1856. }
  1857. 
  1858. File: libc.info, Node: Defining Handlers, Next: Interrupted Primitives, Prev: Signal Actions, Up: Signal Handling
  1859. 24.4 Defining Signal Handlers
  1860. =============================
  1861. This section describes how to write a signal handler function that can
  1862. be established with the ‘signal’ or ‘sigaction’ functions.
  1863. A signal handler is just a function that you compile together with
  1864. the rest of the program. Instead of directly invoking the function, you
  1865. use ‘signal’ or ‘sigaction’ to tell the operating system to call it when
  1866. a signal arrives. This is known as "establishing" the handler. *Note
  1867. Signal Actions::.
  1868. There are two basic strategies you can use in signal handler
  1869. functions:
  1870. • You can have the handler function note that the signal arrived by
  1871. tweaking some global data structures, and then return normally.
  1872. • You can have the handler function terminate the program or transfer
  1873. control to a point where it can recover from the situation that
  1874. caused the signal.
  1875. You need to take special care in writing handler functions because
  1876. they can be called asynchronously. That is, a handler might be called
  1877. at any point in the program, unpredictably. If two signals arrive
  1878. during a very short interval, one handler can run within another. This
  1879. section describes what your handler should do, and what you should
  1880. avoid.
  1881. * Menu:
  1882. * Handler Returns:: Handlers that return normally, and what
  1883. this means.
  1884. * Termination in Handler:: How handler functions terminate a program.
  1885. * Longjmp in Handler:: Nonlocal transfer of control out of a
  1886. signal handler.
  1887. * Signals in Handler:: What happens when signals arrive while
  1888. the handler is already occupied.
  1889. * Merged Signals:: When a second signal arrives before the
  1890. first is handled.
  1891. * Nonreentrancy:: Do not call any functions unless you know they
  1892. are reentrant with respect to signals.
  1893. * Atomic Data Access:: A single handler can run in the middle of
  1894. reading or writing a single object.
  1895. 
  1896. File: libc.info, Node: Handler Returns, Next: Termination in Handler, Up: Defining Handlers
  1897. 24.4.1 Signal Handlers that Return
  1898. ----------------------------------
  1899. Handlers which return normally are usually used for signals such as
  1900. ‘SIGALRM’ and the I/O and interprocess communication signals. But a
  1901. handler for ‘SIGINT’ might also return normally after setting a flag
  1902. that tells the program to exit at a convenient time.
  1903. It is not safe to return normally from the handler for a program
  1904. error signal, because the behavior of the program when the handler
  1905. function returns is not defined after a program error. *Note Program
  1906. Error Signals::.
  1907. Handlers that return normally must modify some global variable in
  1908. order to have any effect. Typically, the variable is one that is
  1909. examined periodically by the program during normal operation. Its data
  1910. type should be ‘sig_atomic_t’ for reasons described in *note Atomic Data
  1911. Access::.
  1912. Here is a simple example of such a program. It executes the body of
  1913. the loop until it has noticed that a ‘SIGALRM’ signal has arrived. This
  1914. technique is useful because it allows the iteration in progress when the
  1915. signal arrives to complete before the loop exits.
  1916. #include <signal.h>
  1917. #include <stdio.h>
  1918. #include <stdlib.h>
  1919. /* This flag controls termination of the main loop. */
  1920. volatile sig_atomic_t keep_going = 1;
  1921. /* The signal handler just clears the flag and re-enables itself. */
  1922. void
  1923. catch_alarm (int sig)
  1924. {
  1925. keep_going = 0;
  1926. signal (sig, catch_alarm);
  1927. }
  1928. void
  1929. do_stuff (void)
  1930. {
  1931. puts ("Doing stuff while waiting for alarm....");
  1932. }
  1933. int
  1934. main (void)
  1935. {
  1936. /* Establish a handler for SIGALRM signals. */
  1937. signal (SIGALRM, catch_alarm);
  1938. /* Set an alarm to go off in a little while. */
  1939. alarm (2);
  1940. /* Check the flag once in a while to see when to quit. */
  1941. while (keep_going)
  1942. do_stuff ();
  1943. return EXIT_SUCCESS;
  1944. }
  1945. 
  1946. File: libc.info, Node: Termination in Handler, Next: Longjmp in Handler, Prev: Handler Returns, Up: Defining Handlers
  1947. 24.4.2 Handlers That Terminate the Process
  1948. ------------------------------------------
  1949. Handler functions that terminate the program are typically used to cause
  1950. orderly cleanup or recovery from program error signals and interactive
  1951. interrupts.
  1952. The cleanest way for a handler to terminate the process is to raise
  1953. the same signal that ran the handler in the first place. Here is how to
  1954. do this:
  1955. volatile sig_atomic_t fatal_error_in_progress = 0;
  1956. void
  1957. fatal_error_signal (int sig)
  1958. {
  1959. /* Since this handler is established for more than one kind of signal,
  1960. it might still get invoked recursively by delivery of some other kind
  1961. of signal. Use a static variable to keep track of that. */
  1962. if (fatal_error_in_progress)
  1963. raise (sig);
  1964. fatal_error_in_progress = 1;
  1965. /* Now do the clean up actions:
  1966. - reset terminal modes
  1967. - kill child processes
  1968. - remove lock files */
  1969. /* Now reraise the signal. We reactivate the signal’s
  1970. default handling, which is to terminate the process.
  1971. We could just call ‘exit’ or ‘abort’,
  1972. but reraising the signal sets the return status
  1973. from the process correctly. */
  1974. signal (sig, SIG_DFL);
  1975. raise (sig);
  1976. }
  1977. 
  1978. File: libc.info, Node: Longjmp in Handler, Next: Signals in Handler, Prev: Termination in Handler, Up: Defining Handlers
  1979. 24.4.3 Nonlocal Control Transfer in Handlers
  1980. --------------------------------------------
  1981. You can do a nonlocal transfer of control out of a signal handler using
  1982. the ‘setjmp’ and ‘longjmp’ facilities (*note Non-Local Exits::).
  1983. When the handler does a nonlocal control transfer, the part of the
  1984. program that was running will not continue. If this part of the program
  1985. was in the middle of updating an important data structure, the data
  1986. structure will remain inconsistent. Since the program does not
  1987. terminate, the inconsistency is likely to be noticed later on.
  1988. There are two ways to avoid this problem. One is to block the signal
  1989. for the parts of the program that update important data structures.
  1990. Blocking the signal delays its delivery until it is unblocked, once the
  1991. critical updating is finished. *Note Blocking Signals::.
  1992. The other way is to re-initialize the crucial data structures in the
  1993. signal handler, or to make their values consistent.
  1994. Here is a rather schematic example showing the reinitialization of
  1995. one global variable.
  1996. #include <signal.h>
  1997. #include <setjmp.h>
  1998. jmp_buf return_to_top_level;
  1999. volatile sig_atomic_t waiting_for_input;
  2000. void
  2001. handle_sigint (int signum)
  2002. {
  2003. /* We may have been waiting for input when the signal arrived,
  2004. but we are no longer waiting once we transfer control. */
  2005. waiting_for_input = 0;
  2006. longjmp (return_to_top_level, 1);
  2007. }
  2008. int
  2009. main (void)
  2010. {
  2011. signal (SIGINT, sigint_handler);
  2012. while (1) {
  2013. prepare_for_command ();
  2014. if (setjmp (return_to_top_level) == 0)
  2015. read_and_execute_command ();
  2016. }
  2017. }
  2018. /* Imagine this is a subroutine used by various commands. */
  2019. char *
  2020. read_data ()
  2021. {
  2022. if (input_from_terminal) {
  2023. waiting_for_input = 1;
  2024. waiting_for_input = 0;
  2025. } else {
  2026. }
  2027. }
  2028. 
  2029. File: libc.info, Node: Signals in Handler, Next: Merged Signals, Prev: Longjmp in Handler, Up: Defining Handlers
  2030. 24.4.4 Signals Arriving While a Handler Runs
  2031. --------------------------------------------
  2032. What happens if another signal arrives while your signal handler
  2033. function is running?
  2034. When the handler for a particular signal is invoked, that signal is
  2035. automatically blocked until the handler returns. That means that if two
  2036. signals of the same kind arrive close together, the second one will be
  2037. held until the first has been handled. (The handler can explicitly
  2038. unblock the signal using ‘sigprocmask’, if you want to allow more
  2039. signals of this type to arrive; see *note Process Signal Mask::.)
  2040. However, your handler can still be interrupted by delivery of another
  2041. kind of signal. To avoid this, you can use the ‘sa_mask’ member of the
  2042. action structure passed to ‘sigaction’ to explicitly specify which
  2043. signals should be blocked while the signal handler runs. These signals
  2044. are in addition to the signal for which the handler was invoked, and any
  2045. other signals that are normally blocked by the process. *Note Blocking
  2046. for Handler::.
  2047. When the handler returns, the set of blocked signals is restored to
  2048. the value it had before the handler ran. So using ‘sigprocmask’ inside
  2049. the handler only affects what signals can arrive during the execution of
  2050. the handler itself, not what signals can arrive once the handler
  2051. returns.
  2052. *Portability Note:* Always use ‘sigaction’ to establish a handler for
  2053. a signal that you expect to receive asynchronously, if you want your
  2054. program to work properly on System V Unix. On this system, the handling
  2055. of a signal whose handler was established with ‘signal’ automatically
  2056. sets the signal’s action back to ‘SIG_DFL’, and the handler must
  2057. re-establish itself each time it runs. This practice, while
  2058. inconvenient, does work when signals cannot arrive in succession.
  2059. However, if another signal can arrive right away, it may arrive before
  2060. the handler can re-establish itself. Then the second signal would
  2061. receive the default handling, which could terminate the process.
  2062. 
  2063. File: libc.info, Node: Merged Signals, Next: Nonreentrancy, Prev: Signals in Handler, Up: Defining Handlers
  2064. 24.4.5 Signals Close Together Merge into One
  2065. --------------------------------------------
  2066. If multiple signals of the same type are delivered to your process
  2067. before your signal handler has a chance to be invoked at all, the
  2068. handler may only be invoked once, as if only a single signal had
  2069. arrived. In effect, the signals merge into one. This situation can
  2070. arise when the signal is blocked, or in a multiprocessing environment
  2071. where the system is busy running some other processes while the signals
  2072. are delivered. This means, for example, that you cannot reliably use a
  2073. signal handler to count signals. The only distinction you can reliably
  2074. make is whether at least one signal has arrived since a given time in
  2075. the past.
  2076. Here is an example of a handler for ‘SIGCHLD’ that compensates for
  2077. the fact that the number of signals received may not equal the number of
  2078. child processes that generate them. It assumes that the program keeps
  2079. track of all the child processes with a chain of structures as follows:
  2080. struct process
  2081. {
  2082. struct process *next;
  2083. /* The process ID of this child. */
  2084. int pid;
  2085. /* The descriptor of the pipe or pseudo terminal
  2086. on which output comes from this child. */
  2087. int input_descriptor;
  2088. /* Nonzero if this process has stopped or terminated. */
  2089. sig_atomic_t have_status;
  2090. /* The status of this child; 0 if running,
  2091. otherwise a status value from ‘waitpid’. */
  2092. int status;
  2093. };
  2094. struct process *process_list;
  2095. This example also uses a flag to indicate whether signals have
  2096. arrived since some time in the past—whenever the program last cleared it
  2097. to zero.
  2098. /* Nonzero means some child’s status has changed
  2099. so look at ‘process_list’ for the details. */
  2100. int process_status_change;
  2101. Here is the handler itself:
  2102. void
  2103. sigchld_handler (int signo)
  2104. {
  2105. int old_errno = errno;
  2106. while (1) {
  2107. register int pid;
  2108. int w;
  2109. struct process *p;
  2110. /* Keep asking for a status until we get a definitive result. */
  2111. do
  2112. {
  2113. errno = 0;
  2114. pid = waitpid (WAIT_ANY, &w, WNOHANG | WUNTRACED);
  2115. }
  2116. while (pid <= 0 && errno == EINTR);
  2117. if (pid <= 0) {
  2118. /* A real failure means there are no more
  2119. stopped or terminated child processes, so return. */
  2120. errno = old_errno;
  2121. return;
  2122. }
  2123. /* Find the process that signaled us, and record its status. */
  2124. for (p = process_list; p; p = p->next)
  2125. if (p->pid == pid) {
  2126. p->status = w;
  2127. /* Indicate that the ‘status’ field
  2128. has data to look at. We do this only after storing it. */
  2129. p->have_status = 1;
  2130. /* If process has terminated, stop waiting for its output. */
  2131. if (WIFSIGNALED (w) || WIFEXITED (w))
  2132. if (p->input_descriptor)
  2133. FD_CLR (p->input_descriptor, &input_wait_mask);
  2134. /* The program should check this flag from time to time
  2135. to see if there is any news in ‘process_list’. */
  2136. ++process_status_change;
  2137. }
  2138. /* Loop around to handle all the processes
  2139. that have something to tell us. */
  2140. }
  2141. }
  2142. Here is the proper way to check the flag ‘process_status_change’:
  2143. if (process_status_change) {
  2144. struct process *p;
  2145. process_status_change = 0;
  2146. for (p = process_list; p; p = p->next)
  2147. if (p->have_status) {
  2148. … Examine ‘p->status’ …
  2149. }
  2150. }
  2151. It is vital to clear the flag before examining the list; otherwise, if a
  2152. signal were delivered just before the clearing of the flag, and after
  2153. the appropriate element of the process list had been checked, the status
  2154. change would go unnoticed until the next signal arrived to set the flag
  2155. again. You could, of course, avoid this problem by blocking the signal
  2156. while scanning the list, but it is much more elegant to guarantee
  2157. correctness by doing things in the right order.
  2158. The loop which checks process status avoids examining ‘p->status’
  2159. until it sees that status has been validly stored. This is to make sure
  2160. that the status cannot change in the middle of accessing it. Once
  2161. ‘p->have_status’ is set, it means that the child process is stopped or
  2162. terminated, and in either case, it cannot stop or terminate again until
  2163. the program has taken notice. *Note Atomic Usage::, for more
  2164. information about coping with interruptions during accesses of a
  2165. variable.
  2166. Here is another way you can test whether the handler has run since
  2167. the last time you checked. This technique uses a counter which is never
  2168. changed outside the handler. Instead of clearing the count, the program
  2169. remembers the previous value and sees whether it has changed since the
  2170. previous check. The advantage of this method is that different parts of
  2171. the program can check independently, each part checking whether there
  2172. has been a signal since that part last checked.
  2173. sig_atomic_t process_status_change;
  2174. sig_atomic_t last_process_status_change;
  2175. {
  2176. sig_atomic_t prev = last_process_status_change;
  2177. last_process_status_change = process_status_change;
  2178. if (last_process_status_change != prev) {
  2179. struct process *p;
  2180. for (p = process_list; p; p = p->next)
  2181. if (p->have_status) {
  2182. … Examine ‘p->status’ …
  2183. }
  2184. }
  2185. }
  2186. 
  2187. File: libc.info, Node: Nonreentrancy, Next: Atomic Data Access, Prev: Merged Signals, Up: Defining Handlers
  2188. 24.4.6 Signal Handling and Nonreentrant Functions
  2189. -------------------------------------------------
  2190. Handler functions usually don’t do very much. The best practice is to
  2191. write a handler that does nothing but set an external variable that the
  2192. program checks regularly, and leave all serious work to the program.
  2193. This is best because the handler can be called asynchronously, at
  2194. unpredictable times—perhaps in the middle of a primitive function, or
  2195. even between the beginning and the end of a C operator that requires
  2196. multiple instructions. The data structures being manipulated might
  2197. therefore be in an inconsistent state when the handler function is
  2198. invoked. Even copying one ‘int’ variable into another can take two
  2199. instructions on most machines.
  2200. This means you have to be very careful about what you do in a signal
  2201. handler.
  2202. • If your handler needs to access any global variables from your
  2203. program, declare those variables ‘volatile’. This tells the
  2204. compiler that the value of the variable might change
  2205. asynchronously, and inhibits certain optimizations that would be
  2206. invalidated by such modifications.
  2207. • If you call a function in the handler, make sure it is "reentrant"
  2208. with respect to signals, or else make sure that the signal cannot
  2209. interrupt a call to a related function.
  2210. A function can be non-reentrant if it uses memory that is not on the
  2211. stack.
  2212. • If a function uses a static variable or a global variable, or a
  2213. dynamically-allocated object that it finds for itself, then it is
  2214. non-reentrant and any two calls to the function can interfere.
  2215. For example, suppose that the signal handler uses ‘gethostbyname’.
  2216. This function returns its value in a static object, reusing the
  2217. same object each time. If the signal happens to arrive during a
  2218. call to ‘gethostbyname’, or even after one (while the program is
  2219. still using the value), it will clobber the value that the program
  2220. asked for.
  2221. However, if the program does not use ‘gethostbyname’ or any other
  2222. function that returns information in the same object, or if it
  2223. always blocks signals around each use, then you are safe.
  2224. There are a large number of library functions that return values in
  2225. a fixed object, always reusing the same object in this fashion, and
  2226. all of them cause the same problem. Function descriptions in this
  2227. manual always mention this behavior.
  2228. • If a function uses and modifies an object that you supply, then it
  2229. is potentially non-reentrant; two calls can interfere if they use
  2230. the same object.
  2231. This case arises when you do I/O using streams. Suppose that the
  2232. signal handler prints a message with ‘fprintf’. Suppose that the
  2233. program was in the middle of an ‘fprintf’ call using the same
  2234. stream when the signal was delivered. Both the signal handler’s
  2235. message and the program’s data could be corrupted, because both
  2236. calls operate on the same data structure—the stream itself.
  2237. However, if you know that the stream that the handler uses cannot
  2238. possibly be used by the program at a time when signals can arrive,
  2239. then you are safe. It is no problem if the program uses some other
  2240. stream.
  2241. • On most systems, ‘malloc’ and ‘free’ are not reentrant, because
  2242. they use a static data structure which records what memory blocks
  2243. are free. As a result, no library functions that allocate or free
  2244. memory are reentrant. This includes functions that allocate space
  2245. to store a result.
  2246. The best way to avoid the need to allocate memory in a handler is
  2247. to allocate in advance space for signal handlers to use.
  2248. The best way to avoid freeing memory in a handler is to flag or
  2249. record the objects to be freed, and have the program check from
  2250. time to time whether anything is waiting to be freed. But this
  2251. must be done with care, because placing an object on a chain is not
  2252. atomic, and if it is interrupted by another signal handler that
  2253. does the same thing, you could “lose” one of the objects.
  2254. • Any function that modifies ‘errno’ is non-reentrant, but you can
  2255. correct for this: in the handler, save the original value of
  2256. ‘errno’ and restore it before returning normally. This prevents
  2257. errors that occur within the signal handler from being confused
  2258. with errors from system calls at the point the program is
  2259. interrupted to run the handler.
  2260. This technique is generally applicable; if you want to call in a
  2261. handler a function that modifies a particular object in memory, you
  2262. can make this safe by saving and restoring that object.
  2263. • Merely reading from a memory object is safe provided that you can
  2264. deal with any of the values that might appear in the object at a
  2265. time when the signal can be delivered. Keep in mind that
  2266. assignment to some data types requires more than one instruction,
  2267. which means that the handler could run “in the middle of” an
  2268. assignment to the variable if its type is not atomic. *Note Atomic
  2269. Data Access::.
  2270. • Merely writing into a memory object is safe as long as a sudden
  2271. change in the value, at any time when the handler might run, will
  2272. not disturb anything.
  2273. 
  2274. File: libc.info, Node: Atomic Data Access, Prev: Nonreentrancy, Up: Defining Handlers
  2275. 24.4.7 Atomic Data Access and Signal Handling
  2276. ---------------------------------------------
  2277. Whether the data in your application concerns atoms, or mere text, you
  2278. have to be careful about the fact that access to a single datum is not
  2279. necessarily "atomic". This means that it can take more than one
  2280. instruction to read or write a single object. In such cases, a signal
  2281. handler might be invoked in the middle of reading or writing the object.
  2282. There are three ways you can cope with this problem. You can use
  2283. data types that are always accessed atomically; you can carefully
  2284. arrange that nothing untoward happens if an access is interrupted, or
  2285. you can block all signals around any access that had better not be
  2286. interrupted (*note Blocking Signals::).
  2287. * Menu:
  2288. * Non-atomic Example:: A program illustrating interrupted access.
  2289. * Types: Atomic Types. Data types that guarantee no interruption.
  2290. * Usage: Atomic Usage. Proving that interruption is harmless.
  2291. 
  2292. File: libc.info, Node: Non-atomic Example, Next: Atomic Types, Up: Atomic Data Access
  2293. 24.4.7.1 Problems with Non-Atomic Access
  2294. ........................................
  2295. Here is an example which shows what can happen if a signal handler runs
  2296. in the middle of modifying a variable. (Interrupting the reading of a
  2297. variable can also lead to paradoxical results, but here we only show
  2298. writing.)
  2299. #include <signal.h>
  2300. #include <stdio.h>
  2301. volatile struct two_words { int a, b; } memory;
  2302. void
  2303. handler(int signum)
  2304. {
  2305. printf ("%d,%d\n", memory.a, memory.b);
  2306. alarm (1);
  2307. }
  2308. int
  2309. main (void)
  2310. {
  2311. static struct two_words zeros = { 0, 0 }, ones = { 1, 1 };
  2312. signal (SIGALRM, handler);
  2313. memory = zeros;
  2314. alarm (1);
  2315. while (1)
  2316. {
  2317. memory = zeros;
  2318. memory = ones;
  2319. }
  2320. }
  2321. This program fills ‘memory’ with zeros, ones, zeros, ones,
  2322. alternating forever; meanwhile, once per second, the alarm signal
  2323. handler prints the current contents. (Calling ‘printf’ in the handler
  2324. is safe in this program because it is certainly not being called outside
  2325. the handler when the signal happens.)
  2326. Clearly, this program can print a pair of zeros or a pair of ones.
  2327. But that’s not all it can do! On most machines, it takes several
  2328. instructions to store a new value in ‘memory’, and the value is stored
  2329. one word at a time. If the signal is delivered in between these
  2330. instructions, the handler might find that ‘memory.a’ is zero and
  2331. ‘memory.b’ is one (or vice versa).
  2332. On some machines it may be possible to store a new value in ‘memory’
  2333. with just one instruction that cannot be interrupted. On these
  2334. machines, the handler will always print two zeros or two ones.
  2335. 
  2336. File: libc.info, Node: Atomic Types, Next: Atomic Usage, Prev: Non-atomic Example, Up: Atomic Data Access
  2337. 24.4.7.2 Atomic Types
  2338. .....................
  2339. To avoid uncertainty about interrupting access to a variable, you can
  2340. use a particular data type for which access is always atomic:
  2341. ‘sig_atomic_t’. Reading and writing this data type is guaranteed to
  2342. happen in a single instruction, so there’s no way for a handler to run
  2343. “in the middle” of an access.
  2344. The type ‘sig_atomic_t’ is always an integer data type, but which one
  2345. it is, and how many bits it contains, may vary from machine to machine.
  2346. -- Data Type: sig_atomic_t
  2347. This is an integer data type. Objects of this type are always
  2348. accessed atomically.
  2349. In practice, you can assume that ‘int’ is atomic. You can also
  2350. assume that pointer types are atomic; that is very convenient. Both of
  2351. these assumptions are true on all of the machines that the GNU C Library
  2352. supports and on all POSIX systems we know of.
  2353. 
  2354. File: libc.info, Node: Atomic Usage, Prev: Atomic Types, Up: Atomic Data Access
  2355. 24.4.7.3 Atomic Usage Patterns
  2356. ..............................
  2357. Certain patterns of access avoid any problem even if an access is
  2358. interrupted. For example, a flag which is set by the handler, and
  2359. tested and cleared by the main program from time to time, is always safe
  2360. even if access actually requires two instructions. To show that this is
  2361. so, we must consider each access that could be interrupted, and show
  2362. that there is no problem if it is interrupted.
  2363. An interrupt in the middle of testing the flag is safe because either
  2364. it’s recognized to be nonzero, in which case the precise value doesn’t
  2365. matter, or it will be seen to be nonzero the next time it’s tested.
  2366. An interrupt in the middle of clearing the flag is no problem because
  2367. either the value ends up zero, which is what happens if a signal comes
  2368. in just before the flag is cleared, or the value ends up nonzero, and
  2369. subsequent events occur as if the signal had come in just after the flag
  2370. was cleared. As long as the code handles both of these cases properly,
  2371. it can also handle a signal in the middle of clearing the flag. (This
  2372. is an example of the sort of reasoning you need to do to figure out
  2373. whether non-atomic usage is safe.)
  2374. Sometimes you can ensure uninterrupted access to one object by
  2375. protecting its use with another object, perhaps one whose type
  2376. guarantees atomicity. *Note Merged Signals::, for an example.
  2377. 
  2378. File: libc.info, Node: Interrupted Primitives, Next: Generating Signals, Prev: Defining Handlers, Up: Signal Handling
  2379. 24.5 Primitives Interrupted by Signals
  2380. ======================================
  2381. A signal can arrive and be handled while an I/O primitive such as ‘open’
  2382. or ‘read’ is waiting for an I/O device. If the signal handler returns,
  2383. the system faces the question: what should happen next?
  2384. POSIX specifies one approach: make the primitive fail right away.
  2385. The error code for this kind of failure is ‘EINTR’. This is flexible,
  2386. but usually inconvenient. Typically, POSIX applications that use signal
  2387. handlers must check for ‘EINTR’ after each library function that can
  2388. return it, in order to try the call again. Often programmers forget to
  2389. check, which is a common source of error.
  2390. The GNU C Library provides a convenient way to retry a call after a
  2391. temporary failure, with the macro ‘TEMP_FAILURE_RETRY’:
  2392. -- Macro: TEMP_FAILURE_RETRY (EXPRESSION)
  2393. This macro evaluates EXPRESSION once, and examines its value as
  2394. type ‘long int’. If the value equals ‘-1’, that indicates a
  2395. failure and ‘errno’ should be set to show what kind of failure. If
  2396. it fails and reports error code ‘EINTR’, ‘TEMP_FAILURE_RETRY’
  2397. evaluates it again, and over and over until the result is not a
  2398. temporary failure.
  2399. The value returned by ‘TEMP_FAILURE_RETRY’ is whatever value
  2400. EXPRESSION produced.
  2401. BSD avoids ‘EINTR’ entirely and provides a more convenient approach:
  2402. to restart the interrupted primitive, instead of making it fail. If you
  2403. choose this approach, you need not be concerned with ‘EINTR’.
  2404. You can choose either approach with the GNU C Library. If you use
  2405. ‘sigaction’ to establish a signal handler, you can specify how that
  2406. handler should behave. If you specify the ‘SA_RESTART’ flag, return
  2407. from that handler will resume a primitive; otherwise, return from that
  2408. handler will cause ‘EINTR’. *Note Flags for Sigaction::.
  2409. Another way to specify the choice is with the ‘siginterrupt’
  2410. function. *Note BSD Signal Handling::.
  2411. When you don’t specify with ‘sigaction’ or ‘siginterrupt’ what a
  2412. particular handler should do, it uses a default choice. The default
  2413. choice in the GNU C Library is to make primitives fail with ‘EINTR’.
  2414. The description of each primitive affected by this issue lists
  2415. ‘EINTR’ among the error codes it can return.
  2416. There is one situation where resumption never happens no matter which
  2417. choice you make: when a data-transfer function such as ‘read’ or ‘write’
  2418. is interrupted by a signal after transferring part of the data. In this
  2419. case, the function returns the number of bytes already transferred,
  2420. indicating partial success.
  2421. This might at first appear to cause unreliable behavior on
  2422. record-oriented devices (including datagram sockets; *note Datagrams::),
  2423. where splitting one ‘read’ or ‘write’ into two would read or write two
  2424. records. Actually, there is no problem, because interruption after a
  2425. partial transfer cannot happen on such devices; they always transfer an
  2426. entire record in one burst, with no waiting once data transfer has
  2427. started.
  2428. 
  2429. File: libc.info, Node: Generating Signals, Next: Blocking Signals, Prev: Interrupted Primitives, Up: Signal Handling
  2430. 24.6 Generating Signals
  2431. =======================
  2432. Besides signals that are generated as a result of a hardware trap or
  2433. interrupt, your program can explicitly send signals to itself or to
  2434. another process.
  2435. * Menu:
  2436. * Signaling Yourself:: A process can send a signal to itself.
  2437. * Signaling Another Process:: Send a signal to another process.
  2438. * Permission for kill:: Permission for using ‘kill’.
  2439. * Kill Example:: Using ‘kill’ for Communication.
  2440. 
  2441. File: libc.info, Node: Signaling Yourself, Next: Signaling Another Process, Up: Generating Signals
  2442. 24.6.1 Signaling Yourself
  2443. -------------------------
  2444. A process can send itself a signal with the ‘raise’ function. This
  2445. function is declared in ‘signal.h’.
  2446. -- Function: int raise (int SIGNUM)
  2447. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2448. Concepts::.
  2449. The ‘raise’ function sends the signal SIGNUM to the calling
  2450. process. It returns zero if successful and a nonzero value if it
  2451. fails. About the only reason for failure would be if the value of
  2452. SIGNUM is invalid.
  2453. -- Function: int gsignal (int SIGNUM)
  2454. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2455. Concepts::.
  2456. The ‘gsignal’ function does the same thing as ‘raise’; it is
  2457. provided only for compatibility with SVID.
  2458. One convenient use for ‘raise’ is to reproduce the default behavior
  2459. of a signal that you have trapped. For instance, suppose a user of your
  2460. program types the SUSP character (usually ‘C-z’; *note Special
  2461. Characters::) to send it an interactive stop signal (‘SIGTSTP’), and you
  2462. want to clean up some internal data buffers before stopping. You might
  2463. set this up like this:
  2464. #include <signal.h>
  2465. /* When a stop signal arrives, set the action back to the default
  2466. and then resend the signal after doing cleanup actions. */
  2467. void
  2468. tstp_handler (int sig)
  2469. {
  2470. signal (SIGTSTP, SIG_DFL);
  2471. /* Do cleanup actions here. */
  2472. raise (SIGTSTP);
  2473. }
  2474. /* When the process is continued again, restore the signal handler. */
  2475. void
  2476. cont_handler (int sig)
  2477. {
  2478. signal (SIGCONT, cont_handler);
  2479. signal (SIGTSTP, tstp_handler);
  2480. }
  2481. /* Enable both handlers during program initialization. */
  2482. int
  2483. main (void)
  2484. {
  2485. signal (SIGCONT, cont_handler);
  2486. signal (SIGTSTP, tstp_handler);
  2487. }
  2488. *Portability note:* ‘raise’ was invented by the ISO C committee.
  2489. Older systems may not support it, so using ‘kill’ may be more portable.
  2490. *Note Signaling Another Process::.
  2491. 
  2492. File: libc.info, Node: Signaling Another Process, Next: Permission for kill, Prev: Signaling Yourself, Up: Generating Signals
  2493. 24.6.2 Signaling Another Process
  2494. --------------------------------
  2495. The ‘kill’ function can be used to send a signal to another process. In
  2496. spite of its name, it can be used for a lot of things other than causing
  2497. a process to terminate. Some examples of situations where you might
  2498. want to send signals between processes are:
  2499. • A parent process starts a child to perform a task—perhaps having
  2500. the child running an infinite loop—and then terminates the child
  2501. when the task is no longer needed.
  2502. • A process executes as part of a group, and needs to terminate or
  2503. notify the other processes in the group when an error or other
  2504. event occurs.
  2505. • Two processes need to synchronize while working together.
  2506. This section assumes that you know a little bit about how processes
  2507. work. For more information on this subject, see *note Processes::.
  2508. The ‘kill’ function is declared in ‘signal.h’.
  2509. -- Function: int kill (pid_t PID, int SIGNUM)
  2510. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2511. Concepts::.
  2512. The ‘kill’ function sends the signal SIGNUM to the process or
  2513. process group specified by PID. Besides the signals listed in
  2514. *note Standard Signals::, SIGNUM can also have a value of zero to
  2515. check the validity of the PID.
  2516. The PID specifies the process or process group to receive the
  2517. signal:
  2518. ‘PID > 0’
  2519. The process whose identifier is PID.
  2520. ‘PID == 0’
  2521. All processes in the same process group as the sender.
  2522. ‘PID < -1’
  2523. The process group whose identifier is −PID.
  2524. ‘PID == -1’
  2525. If the process is privileged, send the signal to all processes
  2526. except for some special system processes. Otherwise, send the
  2527. signal to all processes with the same effective user ID.
  2528. A process can send a signal to itself with a call like
  2529. ‘kill (getpid(), SIGNUM)’. If ‘kill’ is used by a process to send
  2530. a signal to itself, and the signal is not blocked, then ‘kill’
  2531. delivers at least one signal (which might be some other pending
  2532. unblocked signal instead of the signal SIGNUM) to that process
  2533. before it returns.
  2534. The return value from ‘kill’ is zero if the signal can be sent
  2535. successfully. Otherwise, no signal is sent, and a value of ‘-1’ is
  2536. returned. If PID specifies sending a signal to several processes,
  2537. ‘kill’ succeeds if it can send the signal to at least one of them.
  2538. There’s no way you can tell which of the processes got the signal
  2539. or whether all of them did.
  2540. The following ‘errno’ error conditions are defined for this
  2541. function:
  2542. ‘EINVAL’
  2543. The SIGNUM argument is an invalid or unsupported number.
  2544. ‘EPERM’
  2545. You do not have the privilege to send a signal to the process
  2546. or any of the processes in the process group named by PID.
  2547. ‘ESRCH’
  2548. The PID argument does not refer to an existing process or
  2549. group.
  2550. -- Function: int killpg (int PGID, int SIGNUM)
  2551. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2552. Concepts::.
  2553. This is similar to ‘kill’, but sends signal SIGNUM to the process
  2554. group PGID. This function is provided for compatibility with BSD;
  2555. using ‘kill’ to do this is more portable.
  2556. As a simple example of ‘kill’, the call ‘kill (getpid (), SIG)’ has
  2557. the same effect as ‘raise (SIG)’.
  2558. 
  2559. File: libc.info, Node: Permission for kill, Next: Kill Example, Prev: Signaling Another Process, Up: Generating Signals
  2560. 24.6.3 Permission for using ‘kill’
  2561. ----------------------------------
  2562. There are restrictions that prevent you from using ‘kill’ to send
  2563. signals to any random process. These are intended to prevent antisocial
  2564. behavior such as arbitrarily killing off processes belonging to another
  2565. user. In typical use, ‘kill’ is used to pass signals between parent,
  2566. child, and sibling processes, and in these situations you normally do
  2567. have permission to send signals. The only common exception is when you
  2568. run a setuid program in a child process; if the program changes its real
  2569. UID as well as its effective UID, you may not have permission to send a
  2570. signal. The ‘su’ program does this.
  2571. Whether a process has permission to send a signal to another process
  2572. is determined by the user IDs of the two processes. This concept is
  2573. discussed in detail in *note Process Persona::.
  2574. Generally, for a process to be able to send a signal to another
  2575. process, either the sending process must belong to a privileged user
  2576. (like ‘root’), or the real or effective user ID of the sending process
  2577. must match the real or effective user ID of the receiving process. If
  2578. the receiving process has changed its effective user ID from the
  2579. set-user-ID mode bit on its process image file, then the owner of the
  2580. process image file is used in place of its current effective user ID. In
  2581. some implementations, a parent process might be able to send signals to
  2582. a child process even if the user ID’s don’t match, and other
  2583. implementations might enforce other restrictions.
  2584. The ‘SIGCONT’ signal is a special case. It can be sent if the sender
  2585. is part of the same session as the receiver, regardless of user IDs.
  2586. 
  2587. File: libc.info, Node: Kill Example, Prev: Permission for kill, Up: Generating Signals
  2588. 24.6.4 Using ‘kill’ for Communication
  2589. -------------------------------------
  2590. Here is a longer example showing how signals can be used for
  2591. interprocess communication. This is what the ‘SIGUSR1’ and ‘SIGUSR2’
  2592. signals are provided for. Since these signals are fatal by default, the
  2593. process that is supposed to receive them must trap them through ‘signal’
  2594. or ‘sigaction’.
  2595. In this example, a parent process forks a child process and then
  2596. waits for the child to complete its initialization. The child process
  2597. tells the parent when it is ready by sending it a ‘SIGUSR1’ signal,
  2598. using the ‘kill’ function.
  2599. #include <signal.h>
  2600. #include <stdio.h>
  2601. #include <sys/types.h>
  2602. #include <unistd.h>
  2603. /* When a ‘SIGUSR1’ signal arrives, set this variable. */
  2604. volatile sig_atomic_t usr_interrupt = 0;
  2605. void
  2606. synch_signal (int sig)
  2607. {
  2608. usr_interrupt = 1;
  2609. }
  2610. /* The child process executes this function. */
  2611. void
  2612. child_function (void)
  2613. {
  2614. /* Perform initialization. */
  2615. printf ("I'm here!!! My pid is %d.\n", (int) getpid ());
  2616. /* Let parent know you’re done. */
  2617. kill (getppid (), SIGUSR1);
  2618. /* Continue with execution. */
  2619. puts ("Bye, now....");
  2620. exit (0);
  2621. }
  2622. int
  2623. main (void)
  2624. {
  2625. struct sigaction usr_action;
  2626. sigset_t block_mask;
  2627. pid_t child_id;
  2628. /* Establish the signal handler. */
  2629. sigfillset (&block_mask);
  2630. usr_action.sa_handler = synch_signal;
  2631. usr_action.sa_mask = block_mask;
  2632. usr_action.sa_flags = 0;
  2633. sigaction (SIGUSR1, &usr_action, NULL);
  2634. /* Create the child process. */
  2635. child_id = fork ();
  2636. if (child_id == 0)
  2637. child_function (); /* Does not return. */
  2638. /* Busy wait for the child to send a signal. */
  2639. while (!usr_interrupt)
  2640. ;
  2641. /* Now continue execution. */
  2642. puts ("That's all, folks!");
  2643. return 0;
  2644. }
  2645. This example uses a busy wait, which is bad, because it wastes CPU
  2646. cycles that other programs could otherwise use. It is better to ask the
  2647. system to wait until the signal arrives. See the example in *note
  2648. Waiting for a Signal::.
  2649. 
  2650. File: libc.info, Node: Blocking Signals, Next: Waiting for a Signal, Prev: Generating Signals, Up: Signal Handling
  2651. 24.7 Blocking Signals
  2652. =====================
  2653. Blocking a signal means telling the operating system to hold it and
  2654. deliver it later. Generally, a program does not block signals
  2655. indefinitely—it might as well ignore them by setting their actions to
  2656. ‘SIG_IGN’. But it is useful to block signals briefly, to prevent them
  2657. from interrupting sensitive operations. For instance:
  2658. • You can use the ‘sigprocmask’ function to block signals while you
  2659. modify global variables that are also modified by the handlers for
  2660. these signals.
  2661. • You can set ‘sa_mask’ in your ‘sigaction’ call to block certain
  2662. signals while a particular signal handler runs. This way, the
  2663. signal handler can run without being interrupted itself by signals.
  2664. * Menu:
  2665. * Why Block:: The purpose of blocking signals.
  2666. * Signal Sets:: How to specify which signals to
  2667. block.
  2668. * Process Signal Mask:: Blocking delivery of signals to your
  2669. process during normal execution.
  2670. * Testing for Delivery:: Blocking to Test for Delivery of
  2671. a Signal.
  2672. * Blocking for Handler:: Blocking additional signals while a
  2673. handler is being run.
  2674. * Checking for Pending Signals:: Checking for Pending Signals
  2675. * Remembering a Signal:: How you can get almost the same
  2676. effect as blocking a signal, by
  2677. handling it and setting a flag
  2678. to be tested later.
  2679. 
  2680. File: libc.info, Node: Why Block, Next: Signal Sets, Up: Blocking Signals
  2681. 24.7.1 Why Blocking Signals is Useful
  2682. -------------------------------------
  2683. Temporary blocking of signals with ‘sigprocmask’ gives you a way to
  2684. prevent interrupts during critical parts of your code. If signals
  2685. arrive in that part of the program, they are delivered later, after you
  2686. unblock them.
  2687. One example where this is useful is for sharing data between a signal
  2688. handler and the rest of the program. If the type of the data is not
  2689. ‘sig_atomic_t’ (*note Atomic Data Access::), then the signal handler
  2690. could run when the rest of the program has only half finished reading or
  2691. writing the data. This would lead to confusing consequences.
  2692. To make the program reliable, you can prevent the signal handler from
  2693. running while the rest of the program is examining or modifying that
  2694. data—by blocking the appropriate signal around the parts of the program
  2695. that touch the data.
  2696. Blocking signals is also necessary when you want to perform a certain
  2697. action only if a signal has not arrived. Suppose that the handler for
  2698. the signal sets a flag of type ‘sig_atomic_t’; you would like to test
  2699. the flag and perform the action if the flag is not set. This is
  2700. unreliable. Suppose the signal is delivered immediately after you test
  2701. the flag, but before the consequent action: then the program will
  2702. perform the action even though the signal has arrived.
  2703. The only way to test reliably for whether a signal has yet arrived is
  2704. to test while the signal is blocked.
  2705. 
  2706. File: libc.info, Node: Signal Sets, Next: Process Signal Mask, Prev: Why Block, Up: Blocking Signals
  2707. 24.7.2 Signal Sets
  2708. ------------------
  2709. All of the signal blocking functions use a data structure called a
  2710. "signal set" to specify what signals are affected. Thus, every activity
  2711. involves two stages: creating the signal set, and then passing it as an
  2712. argument to a library function.
  2713. These facilities are declared in the header file ‘signal.h’.
  2714. -- Data Type: sigset_t
  2715. The ‘sigset_t’ data type is used to represent a signal set.
  2716. Internally, it may be implemented as either an integer or structure
  2717. type.
  2718. For portability, use only the functions described in this section
  2719. to initialize, change, and retrieve information from ‘sigset_t’
  2720. objects—don’t try to manipulate them directly.
  2721. There are two ways to initialize a signal set. You can initially
  2722. specify it to be empty with ‘sigemptyset’ and then add specified signals
  2723. individually. Or you can specify it to be full with ‘sigfillset’ and
  2724. then delete specified signals individually.
  2725. You must always initialize the signal set with one of these two
  2726. functions before using it in any other way. Don’t try to set all the
  2727. signals explicitly because the ‘sigset_t’ object might include some
  2728. other information (like a version field) that needs to be initialized as
  2729. well. (In addition, it’s not wise to put into your program an
  2730. assumption that the system has no signals aside from the ones you know
  2731. about.)
  2732. -- Function: int sigemptyset (sigset_t *SET)
  2733. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2734. Concepts::.
  2735. This function initializes the signal set SET to exclude all of the
  2736. defined signals. It always returns ‘0’.
  2737. -- Function: int sigfillset (sigset_t *SET)
  2738. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2739. Concepts::.
  2740. This function initializes the signal set SET to include all of the
  2741. defined signals. Again, the return value is ‘0’.
  2742. -- Function: int sigaddset (sigset_t *SET, int SIGNUM)
  2743. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2744. Concepts::.
  2745. This function adds the signal SIGNUM to the signal set SET. All
  2746. ‘sigaddset’ does is modify SET; it does not block or unblock any
  2747. signals.
  2748. The return value is ‘0’ on success and ‘-1’ on failure. The
  2749. following ‘errno’ error condition is defined for this function:
  2750. ‘EINVAL’
  2751. The SIGNUM argument doesn’t specify a valid signal.
  2752. -- Function: int sigdelset (sigset_t *SET, int SIGNUM)
  2753. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2754. Concepts::.
  2755. This function removes the signal SIGNUM from the signal set SET.
  2756. All ‘sigdelset’ does is modify SET; it does not block or unblock
  2757. any signals. The return value and error conditions are the same as
  2758. for ‘sigaddset’.
  2759. Finally, there is a function to test what signals are in a signal
  2760. set:
  2761. -- Function: int sigismember (const sigset_t *SET, int SIGNUM)
  2762. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  2763. Concepts::.
  2764. The ‘sigismember’ function tests whether the signal SIGNUM is a
  2765. member of the signal set SET. It returns ‘1’ if the signal is in
  2766. the set, ‘0’ if not, and ‘-1’ if there is an error.
  2767. The following ‘errno’ error condition is defined for this function:
  2768. ‘EINVAL’
  2769. The SIGNUM argument doesn’t specify a valid signal.
  2770. 
  2771. File: libc.info, Node: Process Signal Mask, Next: Testing for Delivery, Prev: Signal Sets, Up: Blocking Signals
  2772. 24.7.3 Process Signal Mask
  2773. --------------------------
  2774. The collection of signals that are currently blocked is called the
  2775. "signal mask". Each process has its own signal mask. When you create a
  2776. new process (*note Creating a Process::), it inherits its parent’s mask.
  2777. You can block or unblock signals with total flexibility by modifying the
  2778. signal mask.
  2779. The prototype for the ‘sigprocmask’ function is in ‘signal.h’.
  2780. Note that you must not use ‘sigprocmask’ in multi-threaded processes,
  2781. because each thread has its own signal mask and there is no single
  2782. process signal mask. According to POSIX, the behavior of ‘sigprocmask’
  2783. in a multi-threaded process is “unspecified”. Instead, use
  2784. ‘pthread_sigmask’.
  2785. -- Function: int sigprocmask (int HOW, const sigset_t *restrict SET,
  2786. sigset_t *restrict OLDSET)
  2787. Preliminary: | MT-Unsafe race:sigprocmask/bsd(SIG_UNBLOCK) |
  2788. AS-Unsafe lock/hurd | AC-Unsafe lock/hurd | *Note POSIX Safety
  2789. Concepts::.
  2790. The ‘sigprocmask’ function is used to examine or change the calling
  2791. process’s signal mask. The HOW argument determines how the signal
  2792. mask is changed, and must be one of the following values:
  2793. ‘SIG_BLOCK’
  2794. Block the signals in ‘set’—add them to the existing mask. In
  2795. other words, the new mask is the union of the existing mask
  2796. and SET.
  2797. ‘SIG_UNBLOCK’
  2798. Unblock the signals in SET—remove them from the existing mask.
  2799. ‘SIG_SETMASK’
  2800. Use SET for the mask; ignore the previous value of the mask.
  2801. The last argument, OLDSET, is used to return information about the
  2802. old process signal mask. If you just want to change the mask
  2803. without looking at it, pass a null pointer as the OLDSET argument.
  2804. Similarly, if you want to know what’s in the mask without changing
  2805. it, pass a null pointer for SET (in this case the HOW argument is
  2806. not significant). The OLDSET argument is often used to remember
  2807. the previous signal mask in order to restore it later. (Since the
  2808. signal mask is inherited over ‘fork’ and ‘exec’ calls, you can’t
  2809. predict what its contents are when your program starts running.)
  2810. If invoking ‘sigprocmask’ causes any pending signals to be
  2811. unblocked, at least one of those signals is delivered to the
  2812. process before ‘sigprocmask’ returns. The order in which pending
  2813. signals are delivered is not specified, but you can control the
  2814. order explicitly by making multiple ‘sigprocmask’ calls to unblock
  2815. various signals one at a time.
  2816. The ‘sigprocmask’ function returns ‘0’ if successful, and ‘-1’ to
  2817. indicate an error. The following ‘errno’ error conditions are
  2818. defined for this function:
  2819. ‘EINVAL’
  2820. The HOW argument is invalid.
  2821. You can’t block the ‘SIGKILL’ and ‘SIGSTOP’ signals, but if the
  2822. signal set includes these, ‘sigprocmask’ just ignores them instead
  2823. of returning an error status.
  2824. Remember, too, that blocking program error signals such as ‘SIGFPE’
  2825. leads to undesirable results for signals generated by an actual
  2826. program error (as opposed to signals sent with ‘raise’ or ‘kill’).
  2827. This is because your program may be too broken to be able to
  2828. continue executing to a point where the signal is unblocked again.
  2829. *Note Program Error Signals::.
  2830. 
  2831. File: libc.info, Node: Testing for Delivery, Next: Blocking for Handler, Prev: Process Signal Mask, Up: Blocking Signals
  2832. 24.7.4 Blocking to Test for Delivery of a Signal
  2833. ------------------------------------------------
  2834. Now for a simple example. Suppose you establish a handler for ‘SIGALRM’
  2835. signals that sets a flag whenever a signal arrives, and your main
  2836. program checks this flag from time to time and then resets it. You can
  2837. prevent additional ‘SIGALRM’ signals from arriving in the meantime by
  2838. wrapping the critical part of the code with calls to ‘sigprocmask’, like
  2839. this:
  2840. /* This variable is set by the SIGALRM signal handler. */
  2841. volatile sig_atomic_t flag = 0;
  2842. int
  2843. main (void)
  2844. {
  2845. sigset_t block_alarm;
  2846. /* Initialize the signal mask. */
  2847. sigemptyset (&block_alarm);
  2848. sigaddset (&block_alarm, SIGALRM);
  2849. while (1)
  2850. {
  2851. /* Check if a signal has arrived; if so, reset the flag. */
  2852. sigprocmask (SIG_BLOCK, &block_alarm, NULL);
  2853. if (flag)
  2854. {
  2855. ACTIONS-IF-NOT-ARRIVED
  2856. flag = 0;
  2857. }
  2858. sigprocmask (SIG_UNBLOCK, &block_alarm, NULL);
  2859. }
  2860. }
  2861. 
  2862. File: libc.info, Node: Blocking for Handler, Next: Checking for Pending Signals, Prev: Testing for Delivery, Up: Blocking Signals
  2863. 24.7.5 Blocking Signals for a Handler
  2864. -------------------------------------
  2865. When a signal handler is invoked, you usually want it to be able to
  2866. finish without being interrupted by another signal. From the moment the
  2867. handler starts until the moment it finishes, you must block signals that
  2868. might confuse it or corrupt its data.
  2869. When a handler function is invoked on a signal, that signal is
  2870. automatically blocked (in addition to any other signals that are already
  2871. in the process’s signal mask) during the time the handler is running.
  2872. If you set up a handler for ‘SIGTSTP’, for instance, then the arrival of
  2873. that signal forces further ‘SIGTSTP’ signals to wait during the
  2874. execution of the handler.
  2875. However, by default, other kinds of signals are not blocked; they can
  2876. arrive during handler execution.
  2877. The reliable way to block other kinds of signals during the execution
  2878. of the handler is to use the ‘sa_mask’ member of the ‘sigaction’
  2879. structure.
  2880. Here is an example:
  2881. #include <signal.h>
  2882. #include <stddef.h>
  2883. void catch_stop ();
  2884. void
  2885. install_handler (void)
  2886. {
  2887. struct sigaction setup_action;
  2888. sigset_t block_mask;
  2889. sigemptyset (&block_mask);
  2890. /* Block other terminal-generated signals while handler runs. */
  2891. sigaddset (&block_mask, SIGINT);
  2892. sigaddset (&block_mask, SIGQUIT);
  2893. setup_action.sa_handler = catch_stop;
  2894. setup_action.sa_mask = block_mask;
  2895. setup_action.sa_flags = 0;
  2896. sigaction (SIGTSTP, &setup_action, NULL);
  2897. }
  2898. This is more reliable than blocking the other signals explicitly in
  2899. the code for the handler. If you block signals explicitly in the
  2900. handler, you can’t avoid at least a short interval at the beginning of
  2901. the handler where they are not yet blocked.
  2902. You cannot remove signals from the process’s current mask using this
  2903. mechanism. However, you can make calls to ‘sigprocmask’ within your
  2904. handler to block or unblock signals as you wish.
  2905. In any case, when the handler returns, the system restores the mask
  2906. that was in place before the handler was entered. If any signals that
  2907. become unblocked by this restoration are pending, the process will
  2908. receive those signals immediately, before returning to the code that was
  2909. interrupted.
  2910. 
  2911. File: libc.info, Node: Checking for Pending Signals, Next: Remembering a Signal, Prev: Blocking for Handler, Up: Blocking Signals
  2912. 24.7.6 Checking for Pending Signals
  2913. -----------------------------------
  2914. You can find out which signals are pending at any time by calling
  2915. ‘sigpending’. This function is declared in ‘signal.h’.
  2916. -- Function: int sigpending (sigset_t *SET)
  2917. Preliminary: | MT-Safe | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd
  2918. | *Note POSIX Safety Concepts::.
  2919. The ‘sigpending’ function stores information about pending signals
  2920. in SET. If there is a pending signal that is blocked from
  2921. delivery, then that signal is a member of the returned set. (You
  2922. can test whether a particular signal is a member of this set using
  2923. ‘sigismember’; see *note Signal Sets::.)
  2924. The return value is ‘0’ if successful, and ‘-1’ on failure.
  2925. Testing whether a signal is pending is not often useful. Testing
  2926. when that signal is not blocked is almost certainly bad design.
  2927. Here is an example.
  2928. #include <signal.h>
  2929. #include <stddef.h>
  2930. sigset_t base_mask, waiting_mask;
  2931. sigemptyset (&base_mask);
  2932. sigaddset (&base_mask, SIGINT);
  2933. sigaddset (&base_mask, SIGTSTP);
  2934. /* Block user interrupts while doing other processing. */
  2935. sigprocmask (SIG_SETMASK, &base_mask, NULL);
  2936. /* After a while, check to see whether any signals are pending. */
  2937. sigpending (&waiting_mask);
  2938. if (sigismember (&waiting_mask, SIGINT)) {
  2939. /* User has tried to kill the process. */
  2940. }
  2941. else if (sigismember (&waiting_mask, SIGTSTP)) {
  2942. /* User has tried to stop the process. */
  2943. }
  2944. Remember that if there is a particular signal pending for your
  2945. process, additional signals of that same type that arrive in the
  2946. meantime might be discarded. For example, if a ‘SIGINT’ signal is
  2947. pending when another ‘SIGINT’ signal arrives, your program will probably
  2948. only see one of them when you unblock this signal.
  2949. *Portability Note:* The ‘sigpending’ function is new in POSIX.1.
  2950. Older systems have no equivalent facility.
  2951. 
  2952. File: libc.info, Node: Remembering a Signal, Prev: Checking for Pending Signals, Up: Blocking Signals
  2953. 24.7.7 Remembering a Signal to Act On Later
  2954. -------------------------------------------
  2955. Instead of blocking a signal using the library facilities, you can get
  2956. almost the same results by making the handler set a flag to be tested
  2957. later, when you “unblock”. Here is an example:
  2958. /* If this flag is nonzero, don’t handle the signal right away. */
  2959. volatile sig_atomic_t signal_pending;
  2960. /* This is nonzero if a signal arrived and was not handled. */
  2961. volatile sig_atomic_t defer_signal;
  2962. void
  2963. handler (int signum)
  2964. {
  2965. if (defer_signal)
  2966. signal_pending = signum;
  2967. else
  2968. … /* “Really” handle the signal. */
  2969. }
  2970. void
  2971. update_mumble (int frob)
  2972. {
  2973. /* Prevent signals from having immediate effect. */
  2974. defer_signal++;
  2975. /* Now update ‘mumble’, without worrying about interruption. */
  2976. mumble.a = 1;
  2977. mumble.b = hack ();
  2978. mumble.c = frob;
  2979. /* We have updated ‘mumble’. Handle any signal that came in. */
  2980. defer_signal--;
  2981. if (defer_signal == 0 && signal_pending != 0)
  2982. raise (signal_pending);
  2983. }
  2984. Note how the particular signal that arrives is stored in
  2985. ‘signal_pending’. That way, we can handle several types of inconvenient
  2986. signals with the same mechanism.
  2987. We increment and decrement ‘defer_signal’ so that nested critical
  2988. sections will work properly; thus, if ‘update_mumble’ were called with
  2989. ‘signal_pending’ already nonzero, signals would be deferred not only
  2990. within ‘update_mumble’, but also within the caller. This is also why we
  2991. do not check ‘signal_pending’ if ‘defer_signal’ is still nonzero.
  2992. The incrementing and decrementing of ‘defer_signal’ each require more
  2993. than one instruction; it is possible for a signal to happen in the
  2994. middle. But that does not cause any problem. If the signal happens
  2995. early enough to see the value from before the increment or decrement,
  2996. that is equivalent to a signal which came before the beginning of the
  2997. increment or decrement, which is a case that works properly.
  2998. It is absolutely vital to decrement ‘defer_signal’ before testing
  2999. ‘signal_pending’, because this avoids a subtle bug. If we did these
  3000. things in the other order, like this,
  3001. if (defer_signal == 1 && signal_pending != 0)
  3002. raise (signal_pending);
  3003. defer_signal--;
  3004. then a signal arriving in between the ‘if’ statement and the decrement
  3005. would be effectively “lost” for an indefinite amount of time. The
  3006. handler would merely set ‘defer_signal’, but the program having already
  3007. tested this variable, it would not test the variable again.
  3008. Bugs like these are called "timing errors". They are especially bad
  3009. because they happen only rarely and are nearly impossible to reproduce.
  3010. You can’t expect to find them with a debugger as you would find a
  3011. reproducible bug. So it is worth being especially careful to avoid
  3012. them.
  3013. (You would not be tempted to write the code in this order, given the
  3014. use of ‘defer_signal’ as a counter which must be tested along with
  3015. ‘signal_pending’. After all, testing for zero is cleaner than testing
  3016. for one. But if you did not use ‘defer_signal’ as a counter, and gave
  3017. it values of zero and one only, then either order might seem equally
  3018. simple. This is a further advantage of using a counter for
  3019. ‘defer_signal’: it will reduce the chance you will write the code in the
  3020. wrong order and create a subtle bug.)
  3021. 
  3022. File: libc.info, Node: Waiting for a Signal, Next: Signal Stack, Prev: Blocking Signals, Up: Signal Handling
  3023. 24.8 Waiting for a Signal
  3024. =========================
  3025. If your program is driven by external events, or uses signals for
  3026. synchronization, then when it has nothing to do it should probably wait
  3027. until a signal arrives.
  3028. * Menu:
  3029. * Using Pause:: The simple way, using ‘pause’.
  3030. * Pause Problems:: Why the simple way is often not very good.
  3031. * Sigsuspend:: Reliably waiting for a specific signal.
  3032. 
  3033. File: libc.info, Node: Using Pause, Next: Pause Problems, Up: Waiting for a Signal
  3034. 24.8.1 Using ‘pause’
  3035. --------------------
  3036. The simple way to wait until a signal arrives is to call ‘pause’.
  3037. Please read about its disadvantages, in the following section, before
  3038. you use it.
  3039. -- Function: int pause (void)
  3040. Preliminary: | MT-Unsafe race:sigprocmask/!bsd!linux | AS-Unsafe
  3041. lock/hurd | AC-Unsafe lock/hurd | *Note POSIX Safety Concepts::.
  3042. The ‘pause’ function suspends program execution until a signal
  3043. arrives whose action is either to execute a handler function, or to
  3044. terminate the process.
  3045. If the signal causes a handler function to be executed, then
  3046. ‘pause’ returns. This is considered an unsuccessful return (since
  3047. “successful” behavior would be to suspend the program forever), so
  3048. the return value is ‘-1’. Even if you specify that other
  3049. primitives should resume when a system handler returns (*note
  3050. Interrupted Primitives::), this has no effect on ‘pause’; it always
  3051. fails when a signal is handled.
  3052. The following ‘errno’ error conditions are defined for this
  3053. function:
  3054. ‘EINTR’
  3055. The function was interrupted by delivery of a signal.
  3056. If the signal causes program termination, ‘pause’ doesn’t return
  3057. (obviously).
  3058. This function is a cancellation point in multithreaded programs.
  3059. This is a problem if the thread allocates some resources (like
  3060. memory, file descriptors, semaphores or whatever) at the time
  3061. ‘pause’ is called. If the thread gets cancelled these resources
  3062. stay allocated until the program ends. To avoid this calls to
  3063. ‘pause’ should be protected using cancellation handlers.
  3064. The ‘pause’ function is declared in ‘unistd.h’.
  3065. 
  3066. File: libc.info, Node: Pause Problems, Next: Sigsuspend, Prev: Using Pause, Up: Waiting for a Signal
  3067. 24.8.2 Problems with ‘pause’
  3068. ----------------------------
  3069. The simplicity of ‘pause’ can conceal serious timing errors that can
  3070. make a program hang mysteriously.
  3071. It is safe to use ‘pause’ if the real work of your program is done by
  3072. the signal handlers themselves, and the “main program” does nothing but
  3073. call ‘pause’. Each time a signal is delivered, the handler will do the
  3074. next batch of work that is to be done, and then return, so that the main
  3075. loop of the program can call ‘pause’ again.
  3076. You can’t safely use ‘pause’ to wait until one more signal arrives,
  3077. and then resume real work. Even if you arrange for the signal handler
  3078. to cooperate by setting a flag, you still can’t use ‘pause’ reliably.
  3079. Here is an example of this problem:
  3080. /* ‘usr_interrupt’ is set by the signal handler. */
  3081. if (!usr_interrupt)
  3082. pause ();
  3083. /* Do work once the signal arrives. */
  3084. This has a bug: the signal could arrive after the variable
  3085. ‘usr_interrupt’ is checked, but before the call to ‘pause’. If no
  3086. further signals arrive, the process would never wake up again.
  3087. You can put an upper limit on the excess waiting by using ‘sleep’ in
  3088. a loop, instead of using ‘pause’. (*Note Sleeping::, for more about
  3089. ‘sleep’.) Here is what this looks like:
  3090. /* ‘usr_interrupt’ is set by the signal handler.
  3091. while (!usr_interrupt)
  3092. sleep (1);
  3093. /* Do work once the signal arrives. */
  3094. For some purposes, that is good enough. But with a little more
  3095. complexity, you can wait reliably until a particular signal handler is
  3096. run, using ‘sigsuspend’. *Note Sigsuspend::.
  3097. 
  3098. File: libc.info, Node: Sigsuspend, Prev: Pause Problems, Up: Waiting for a Signal
  3099. 24.8.3 Using ‘sigsuspend’
  3100. -------------------------
  3101. The clean and reliable way to wait for a signal to arrive is to block it
  3102. and then use ‘sigsuspend’. By using ‘sigsuspend’ in a loop, you can
  3103. wait for certain kinds of signals, while letting other kinds of signals
  3104. be handled by their handlers.
  3105. -- Function: int sigsuspend (const sigset_t *SET)
  3106. Preliminary: | MT-Unsafe race:sigprocmask/!bsd!linux | AS-Unsafe
  3107. lock/hurd | AC-Unsafe lock/hurd | *Note POSIX Safety Concepts::.
  3108. This function replaces the process’s signal mask with SET and then
  3109. suspends the process until a signal is delivered whose action is
  3110. either to terminate the process or invoke a signal handling
  3111. function. In other words, the program is effectively suspended
  3112. until one of the signals that is not a member of SET arrives.
  3113. If the process is woken up by delivery of a signal that invokes a
  3114. handler function, and the handler function returns, then
  3115. ‘sigsuspend’ also returns.
  3116. The mask remains SET only as long as ‘sigsuspend’ is waiting. The
  3117. function ‘sigsuspend’ always restores the previous signal mask when
  3118. it returns.
  3119. The return value and error conditions are the same as for ‘pause’.
  3120. With ‘sigsuspend’, you can replace the ‘pause’ or ‘sleep’ loop in the
  3121. previous section with something completely reliable:
  3122. sigset_t mask, oldmask;
  3123. /* Set up the mask of signals to temporarily block. */
  3124. sigemptyset (&mask);
  3125. sigaddset (&mask, SIGUSR1);
  3126. /* Wait for a signal to arrive. */
  3127. sigprocmask (SIG_BLOCK, &mask, &oldmask);
  3128. while (!usr_interrupt)
  3129. sigsuspend (&oldmask);
  3130. sigprocmask (SIG_UNBLOCK, &mask, NULL);
  3131. This last piece of code is a little tricky. The key point to
  3132. remember here is that when ‘sigsuspend’ returns, it resets the process’s
  3133. signal mask to the original value, the value from before the call to
  3134. ‘sigsuspend’—in this case, the ‘SIGUSR1’ signal is once again blocked.
  3135. The second call to ‘sigprocmask’ is necessary to explicitly unblock this
  3136. signal.
  3137. One other point: you may be wondering why the ‘while’ loop is
  3138. necessary at all, since the program is apparently only waiting for one
  3139. ‘SIGUSR1’ signal. The answer is that the mask passed to ‘sigsuspend’
  3140. permits the process to be woken up by the delivery of other kinds of
  3141. signals, as well—for example, job control signals. If the process is
  3142. woken up by a signal that doesn’t set ‘usr_interrupt’, it just suspends
  3143. itself again until the “right” kind of signal eventually arrives.
  3144. This technique takes a few more lines of preparation, but that is
  3145. needed just once for each kind of wait criterion you want to use. The
  3146. code that actually waits is just four lines.
  3147. 
  3148. File: libc.info, Node: Signal Stack, Next: BSD Signal Handling, Prev: Waiting for a Signal, Up: Signal Handling
  3149. 24.9 Using a Separate Signal Stack
  3150. ==================================
  3151. A signal stack is a special area of memory to be used as the execution
  3152. stack during signal handlers. It should be fairly large, to avoid any
  3153. danger that it will overflow in turn; the macro ‘SIGSTKSZ’ is defined to
  3154. a canonical size for signal stacks. You can use ‘malloc’ to allocate
  3155. the space for the stack. Then call ‘sigaltstack’ or ‘sigstack’ to tell
  3156. the system to use that space for the signal stack.
  3157. You don’t need to write signal handlers differently in order to use a
  3158. signal stack. Switching from one stack to the other happens
  3159. automatically. (Some non-GNU debuggers on some machines may get
  3160. confused if you examine a stack trace while a handler that uses the
  3161. signal stack is running.)
  3162. There are two interfaces for telling the system to use a separate
  3163. signal stack. ‘sigstack’ is the older interface, which comes from 4.2
  3164. BSD. ‘sigaltstack’ is the newer interface, and comes from 4.4 BSD. The
  3165. ‘sigaltstack’ interface has the advantage that it does not require your
  3166. program to know which direction the stack grows, which depends on the
  3167. specific machine and operating system.
  3168. -- Data Type: stack_t
  3169. This structure describes a signal stack. It contains the following
  3170. members:
  3171. ‘void *ss_sp’
  3172. This points to the base of the signal stack.
  3173. ‘size_t ss_size’
  3174. This is the size (in bytes) of the signal stack which ‘ss_sp’
  3175. points to. You should set this to however much space you
  3176. allocated for the stack.
  3177. There are two macros defined in ‘signal.h’ that you should use
  3178. in calculating this size:
  3179. ‘SIGSTKSZ’
  3180. This is the canonical size for a signal stack. It is
  3181. judged to be sufficient for normal uses.
  3182. ‘MINSIGSTKSZ’
  3183. This is the amount of signal stack space the operating
  3184. system needs just to implement signal delivery. The size
  3185. of a signal stack *must* be greater than this.
  3186. For most cases, just using ‘SIGSTKSZ’ for ‘ss_size’ is
  3187. sufficient. But if you know how much stack space your
  3188. program’s signal handlers will need, you may want to use
  3189. a different size. In this case, you should allocate
  3190. ‘MINSIGSTKSZ’ additional bytes for the signal stack and
  3191. increase ‘ss_size’ accordingly.
  3192. ‘int ss_flags’
  3193. This field contains the bitwise OR of these flags:
  3194. ‘SS_DISABLE’
  3195. This tells the system that it should not use the signal
  3196. stack.
  3197. ‘SS_ONSTACK’
  3198. This is set by the system, and indicates that the signal
  3199. stack is currently in use. If this bit is not set, then
  3200. signals will be delivered on the normal user stack.
  3201. -- Function: int sigaltstack (const stack_t *restrict STACK, stack_t
  3202. *restrict OLDSTACK)
  3203. Preliminary: | MT-Safe | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd
  3204. | *Note POSIX Safety Concepts::.
  3205. The ‘sigaltstack’ function specifies an alternate stack for use
  3206. during signal handling. When a signal is received by the process
  3207. and its action indicates that the signal stack is used, the system
  3208. arranges a switch to the currently installed signal stack while the
  3209. handler for that signal is executed.
  3210. If OLDSTACK is not a null pointer, information about the currently
  3211. installed signal stack is returned in the location it points to.
  3212. If STACK is not a null pointer, then this is installed as the new
  3213. stack for use by signal handlers.
  3214. The return value is ‘0’ on success and ‘-1’ on failure. If
  3215. ‘sigaltstack’ fails, it sets ‘errno’ to one of these values:
  3216. ‘EINVAL’
  3217. You tried to disable a stack that was in fact currently in
  3218. use.
  3219. ‘ENOMEM’
  3220. The size of the alternate stack was too small. It must be
  3221. greater than ‘MINSIGSTKSZ’.
  3222. Here is the older ‘sigstack’ interface. You should use ‘sigaltstack’
  3223. instead on systems that have it.
  3224. -- Data Type: struct sigstack
  3225. This structure describes a signal stack. It contains the following
  3226. members:
  3227. ‘void *ss_sp’
  3228. This is the stack pointer. If the stack grows downwards on
  3229. your machine, this should point to the top of the area you
  3230. allocated. If the stack grows upwards, it should point to the
  3231. bottom.
  3232. ‘int ss_onstack’
  3233. This field is true if the process is currently using this
  3234. stack.
  3235. -- Function: int sigstack (struct sigstack *STACK, struct sigstack
  3236. *OLDSTACK)
  3237. Preliminary: | MT-Safe | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd
  3238. | *Note POSIX Safety Concepts::.
  3239. The ‘sigstack’ function specifies an alternate stack for use during
  3240. signal handling. When a signal is received by the process and its
  3241. action indicates that the signal stack is used, the system arranges
  3242. a switch to the currently installed signal stack while the handler
  3243. for that signal is executed.
  3244. If OLDSTACK is not a null pointer, information about the currently
  3245. installed signal stack is returned in the location it points to.
  3246. If STACK is not a null pointer, then this is installed as the new
  3247. stack for use by signal handlers.
  3248. The return value is ‘0’ on success and ‘-1’ on failure.
  3249. 
  3250. File: libc.info, Node: BSD Signal Handling, Prev: Signal Stack, Up: Signal Handling
  3251. 24.10 BSD Signal Handling
  3252. =========================
  3253. This section describes alternative signal handling functions derived
  3254. from BSD Unix. These facilities were an advance, in their time; today,
  3255. they are mostly obsolete, and supported mainly for compatibility with
  3256. BSD Unix.
  3257. There are many similarities between the BSD and POSIX signal handling
  3258. facilities, because the POSIX facilities were inspired by the BSD
  3259. facilities. Besides having different names for all the functions to
  3260. avoid conflicts, the main difference between the two is that BSD Unix
  3261. represents signal masks as an ‘int’ bit mask, rather than as a
  3262. ‘sigset_t’ object.
  3263. The BSD facilities are declared in ‘signal.h’.
  3264. -- Function: int siginterrupt (int SIGNUM, int FAILFLAG)
  3265. Preliminary: | MT-Unsafe const:sigintr | AS-Unsafe | AC-Unsafe
  3266. corrupt | *Note POSIX Safety Concepts::.
  3267. This function specifies which approach to use when certain
  3268. primitives are interrupted by handling signal SIGNUM. If FAILFLAG
  3269. is false, signal SIGNUM restarts primitives. If FAILFLAG is true,
  3270. handling SIGNUM causes these primitives to fail with error code
  3271. ‘EINTR’. *Note Interrupted Primitives::.
  3272. -- Macro: int sigmask (int SIGNUM)
  3273. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  3274. Concepts::.
  3275. This macro returns a signal mask that has the bit for signal SIGNUM
  3276. set. You can bitwise-OR the results of several calls to ‘sigmask’
  3277. together to specify more than one signal. For example,
  3278. (sigmask (SIGTSTP) | sigmask (SIGSTOP)
  3279. | sigmask (SIGTTIN) | sigmask (SIGTTOU))
  3280. specifies a mask that includes all the job-control stop signals.
  3281. -- Function: int sigblock (int MASK)
  3282. Preliminary: | MT-Safe | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd
  3283. | *Note POSIX Safety Concepts::.
  3284. This function is equivalent to ‘sigprocmask’ (*note Process Signal
  3285. Mask::) with a HOW argument of ‘SIG_BLOCK’: it adds the signals
  3286. specified by MASK to the calling process’s set of blocked signals.
  3287. The return value is the previous set of blocked signals.
  3288. -- Function: int sigsetmask (int MASK)
  3289. Preliminary: | MT-Safe | AS-Unsafe lock/hurd | AC-Unsafe lock/hurd
  3290. | *Note POSIX Safety Concepts::.
  3291. This function is equivalent to ‘sigprocmask’ (*note Process Signal
  3292. Mask::) with a HOW argument of ‘SIG_SETMASK’: it sets the calling
  3293. process’s signal mask to MASK. The return value is the previous
  3294. set of blocked signals.
  3295. -- Function: int sigpause (int MASK)
  3296. Preliminary: | MT-Unsafe race:sigprocmask/!bsd!linux | AS-Unsafe
  3297. lock/hurd | AC-Unsafe lock/hurd | *Note POSIX Safety Concepts::.
  3298. This function is the equivalent of ‘sigsuspend’ (*note Waiting for
  3299. a Signal::): it sets the calling process’s signal mask to MASK, and
  3300. waits for a signal to arrive. On return the previous set of
  3301. blocked signals is restored.
  3302. 
  3303. File: libc.info, Node: Program Basics, Next: Processes, Prev: Signal Handling, Up: Top
  3304. 25 The Basic Program/System Interface
  3305. *************************************
  3306. "Processes" are the primitive units for allocation of system resources.
  3307. Each process has its own address space and (usually) one thread of
  3308. control. A process executes a program; you can have multiple processes
  3309. executing the same program, but each process has its own copy of the
  3310. program within its own address space and executes it independently of
  3311. the other copies. Though it may have multiple threads of control within
  3312. the same program and a program may be composed of multiple logically
  3313. separate modules, a process always executes exactly one program.
  3314. Note that we are using a specific definition of “program” for the
  3315. purposes of this manual, which corresponds to a common definition in the
  3316. context of Unix systems. In popular usage, “program” enjoys a much
  3317. broader definition; it can refer for example to a system’s kernel, an
  3318. editor macro, a complex package of software, or a discrete section of
  3319. code executing within a process.
  3320. Writing the program is what this manual is all about. This chapter
  3321. explains the most basic interface between your program and the system
  3322. that runs, or calls, it. This includes passing of parameters (arguments
  3323. and environment) from the system, requesting basic services from the
  3324. system, and telling the system the program is done.
  3325. A program starts another program with the ‘exec’ family of system
  3326. calls. This chapter looks at program startup from the execee’s point of
  3327. view. To see the event from the execor’s point of view, see *note
  3328. Executing a File::.
  3329. * Menu:
  3330. * Program Arguments:: Parsing your program’s command-line arguments
  3331. * Environment Variables:: Less direct parameters affecting your program
  3332. * Auxiliary Vector:: Least direct parameters affecting your program
  3333. * System Calls:: Requesting service from the system
  3334. * Program Termination:: Telling the system you’re done; return status
  3335. 
  3336. File: libc.info, Node: Program Arguments, Next: Environment Variables, Up: Program Basics
  3337. 25.1 Program Arguments
  3338. ======================
  3339. The system starts a C program by calling the function ‘main’. It is up
  3340. to you to write a function named ‘main’—otherwise, you won’t even be
  3341. able to link your program without errors.
  3342. In ISO C you can define ‘main’ either to take no arguments, or to
  3343. take two arguments that represent the command line arguments to the
  3344. program, like this:
  3345. int main (int ARGC, char *ARGV[])
  3346. The command line arguments are the whitespace-separated tokens given
  3347. in the shell command used to invoke the program; thus, in ‘cat foo bar’,
  3348. the arguments are ‘foo’ and ‘bar’. The only way a program can look at
  3349. its command line arguments is via the arguments of ‘main’. If ‘main’
  3350. doesn’t take arguments, then you cannot get at the command line.
  3351. The value of the ARGC argument is the number of command line
  3352. arguments. The ARGV argument is a vector of C strings; its elements are
  3353. the individual command line argument strings. The file name of the
  3354. program being run is also included in the vector as the first element;
  3355. the value of ARGC counts this element. A null pointer always follows
  3356. the last element: ‘ARGV[ARGC]’ is this null pointer.
  3357. For the command ‘cat foo bar’, ARGC is 3 and ARGV has three elements,
  3358. ‘"cat"’, ‘"foo"’ and ‘"bar"’.
  3359. In Unix systems you can define ‘main’ a third way, using three
  3360. arguments:
  3361. int main (int ARGC, char *ARGV[], char *ENVP[])
  3362. The first two arguments are just the same. The third argument ENVP
  3363. gives the program’s environment; it is the same as the value of
  3364. ‘environ’. *Note Environment Variables::. POSIX.1 does not allow this
  3365. three-argument form, so to be portable it is best to write ‘main’ to
  3366. take two arguments, and use the value of ‘environ’.
  3367. * Menu:
  3368. * Argument Syntax:: By convention, options start with a hyphen.
  3369. * Parsing Program Arguments:: Ways to parse program options and arguments.
  3370. 
  3371. File: libc.info, Node: Argument Syntax, Next: Parsing Program Arguments, Up: Program Arguments
  3372. 25.1.1 Program Argument Syntax Conventions
  3373. ------------------------------------------
  3374. POSIX recommends these conventions for command line arguments. ‘getopt’
  3375. (*note Getopt::) and ‘argp_parse’ (*note Argp::) make it easy to
  3376. implement them.
  3377. • Arguments are options if they begin with a hyphen delimiter (‘-’).
  3378. • Multiple options may follow a hyphen delimiter in a single token if
  3379. the options do not take arguments. Thus, ‘-abc’ is equivalent to
  3380. ‘-a -b -c’.
  3381. • Option names are single alphanumeric characters (as for ‘isalnum’;
  3382. *note Classification of Characters::).
  3383. • Certain options require an argument. For example, the ‘-o’ command
  3384. of the ‘ld’ command requires an argument—an output file name.
  3385. • An option and its argument may or may not appear as separate
  3386. tokens. (In other words, the whitespace separating them is
  3387. optional.) Thus, ‘-o foo’ and ‘-ofoo’ are equivalent.
  3388. • Options typically precede other non-option arguments.
  3389. The implementations of ‘getopt’ and ‘argp_parse’ in the GNU C
  3390. Library normally make it appear as if all the option arguments were
  3391. specified before all the non-option arguments for the purposes of
  3392. parsing, even if the user of your program intermixed option and
  3393. non-option arguments. They do this by reordering the elements of
  3394. the ARGV array. This behavior is nonstandard; if you want to
  3395. suppress it, define the ‘_POSIX_OPTION_ORDER’ environment variable.
  3396. *Note Standard Environment::.
  3397. • The argument ‘--’ terminates all options; any following arguments
  3398. are treated as non-option arguments, even if they begin with a
  3399. hyphen.
  3400. • A token consisting of a single hyphen character is interpreted as
  3401. an ordinary non-option argument. By convention, it is used to
  3402. specify input from or output to the standard input and output
  3403. streams.
  3404. • Options may be supplied in any order, or appear multiple times.
  3405. The interpretation is left up to the particular application
  3406. program.
  3407. GNU adds "long options" to these conventions. Long options consist
  3408. of ‘--’ followed by a name made of alphanumeric characters and dashes.
  3409. Option names are typically one to three words long, with hyphens to
  3410. separate words. Users can abbreviate the option names as long as the
  3411. abbreviations are unique.
  3412. To specify an argument for a long option, write ‘--NAME=VALUE’. This
  3413. syntax enables a long option to accept an argument that is itself
  3414. optional.
  3415. Eventually, GNU systems will provide completion for long option names
  3416. in the shell.
  3417. 
  3418. File: libc.info, Node: Parsing Program Arguments, Prev: Argument Syntax, Up: Program Arguments
  3419. 25.1.2 Parsing Program Arguments
  3420. --------------------------------
  3421. If the syntax for the command line arguments to your program is simple
  3422. enough, you can simply pick the arguments off from ARGV by hand. But
  3423. unless your program takes a fixed number of arguments, or all of the
  3424. arguments are interpreted in the same way (as file names, for example),
  3425. you are usually better off using ‘getopt’ (*note Getopt::) or
  3426. ‘argp_parse’ (*note Argp::) to do the parsing.
  3427. ‘getopt’ is more standard (the short-option only version of it is a
  3428. part of the POSIX standard), but using ‘argp_parse’ is often easier,
  3429. both for very simple and very complex option structures, because it does
  3430. more of the dirty work for you.
  3431. * Menu:
  3432. * Getopt:: Parsing program options using ‘getopt’.
  3433. * Argp:: Parsing program options using ‘argp_parse’.
  3434. * Suboptions:: Some programs need more detailed options.
  3435. * Suboptions Example:: This shows how it could be done for ‘mount’.
  3436. 
  3437. File: libc.info, Node: Getopt, Next: Argp, Up: Parsing Program Arguments
  3438. 25.2 Parsing program options using ‘getopt’
  3439. ===========================================
  3440. The ‘getopt’ and ‘getopt_long’ functions automate some of the chore
  3441. involved in parsing typical unix command line options.
  3442. * Menu:
  3443. * Using Getopt:: Using the ‘getopt’ function.
  3444. * Example of Getopt:: An example of parsing options with ‘getopt’.
  3445. * Getopt Long Options:: GNU suggests utilities accept long-named
  3446. options; here is one way to do.
  3447. * Getopt Long Option Example:: An example of using ‘getopt_long’.
  3448. 
  3449. File: libc.info, Node: Using Getopt, Next: Example of Getopt, Up: Getopt
  3450. 25.2.1 Using the ‘getopt’ function
  3451. ----------------------------------
  3452. Here are the details about how to call the ‘getopt’ function. To use
  3453. this facility, your program must include the header file ‘unistd.h’.
  3454. -- Variable: int opterr
  3455. If the value of this variable is nonzero, then ‘getopt’ prints an
  3456. error message to the standard error stream if it encounters an
  3457. unknown option character or an option with a missing required
  3458. argument. This is the default behavior. If you set this variable
  3459. to zero, ‘getopt’ does not print any messages, but it still returns
  3460. the character ‘?’ to indicate an error.
  3461. -- Variable: int optopt
  3462. When ‘getopt’ encounters an unknown option character or an option
  3463. with a missing required argument, it stores that option character
  3464. in this variable. You can use this for providing your own
  3465. diagnostic messages.
  3466. -- Variable: int optind
  3467. This variable is set by ‘getopt’ to the index of the next element
  3468. of the ARGV array to be processed. Once ‘getopt’ has found all of
  3469. the option arguments, you can use this variable to determine where
  3470. the remaining non-option arguments begin. The initial value of
  3471. this variable is ‘1’.
  3472. -- Variable: char * optarg
  3473. This variable is set by ‘getopt’ to point at the value of the
  3474. option argument, for those options that accept arguments.
  3475. -- Function: int getopt (int ARGC, char *const *ARGV, const char
  3476. *OPTIONS)
  3477. Preliminary: | MT-Unsafe race:getopt env | AS-Unsafe heap i18n lock
  3478. corrupt | AC-Unsafe mem lock corrupt | *Note POSIX Safety
  3479. Concepts::.
  3480. The ‘getopt’ function gets the next option argument from the
  3481. argument list specified by the ARGV and ARGC arguments. Normally
  3482. these values come directly from the arguments received by ‘main’.
  3483. The OPTIONS argument is a string that specifies the option
  3484. characters that are valid for this program. An option character in
  3485. this string can be followed by a colon (‘:’) to indicate that it
  3486. takes a required argument. If an option character is followed by
  3487. two colons (‘::’), its argument is optional; this is a GNU
  3488. extension.
  3489. ‘getopt’ has three ways to deal with options that follow
  3490. non-options ARGV elements. The special argument ‘--’ forces in all
  3491. cases the end of option scanning.
  3492. • The default is to permute the contents of ARGV while scanning
  3493. it so that eventually all the non-options are at the end.
  3494. This allows options to be given in any order, even with
  3495. programs that were not written to expect this.
  3496. • If the OPTIONS argument string begins with a hyphen (‘-’),
  3497. this is treated specially. It permits arguments that are not
  3498. options to be returned as if they were associated with option
  3499. character ‘\1’.
  3500. • POSIX demands the following behavior: the first non-option
  3501. stops option processing. This mode is selected by either
  3502. setting the environment variable ‘POSIXLY_CORRECT’ or
  3503. beginning the OPTIONS argument string with a plus sign (‘+’).
  3504. The ‘getopt’ function returns the option character for the next
  3505. command line option. When no more option arguments are available,
  3506. it returns ‘-1’. There may still be more non-option arguments; you
  3507. must compare the external variable ‘optind’ against the ARGC
  3508. parameter to check this.
  3509. If the option has an argument, ‘getopt’ returns the argument by
  3510. storing it in the variable OPTARG. You don’t ordinarily need to
  3511. copy the ‘optarg’ string, since it is a pointer into the original
  3512. ARGV array, not into a static area that might be overwritten.
  3513. If ‘getopt’ finds an option character in ARGV that was not included
  3514. in OPTIONS, or a missing option argument, it returns ‘?’ and sets
  3515. the external variable ‘optopt’ to the actual option character. If
  3516. the first character of OPTIONS is a colon (‘:’), then ‘getopt’
  3517. returns ‘:’ instead of ‘?’ to indicate a missing option argument.
  3518. In addition, if the external variable ‘opterr’ is nonzero (which is
  3519. the default), ‘getopt’ prints an error message.
  3520. 
  3521. File: libc.info, Node: Example of Getopt, Next: Getopt Long Options, Prev: Using Getopt, Up: Getopt
  3522. 25.2.2 Example of Parsing Arguments with ‘getopt’
  3523. -------------------------------------------------
  3524. Here is an example showing how ‘getopt’ is typically used. The key
  3525. points to notice are:
  3526. • Normally, ‘getopt’ is called in a loop. When ‘getopt’ returns
  3527. ‘-1’, indicating no more options are present, the loop terminates.
  3528. • A ‘switch’ statement is used to dispatch on the return value from
  3529. ‘getopt’. In typical use, each case just sets a variable that is
  3530. used later in the program.
  3531. • A second loop is used to process the remaining non-option
  3532. arguments.
  3533. #include <ctype.h>
  3534. #include <stdio.h>
  3535. #include <stdlib.h>
  3536. #include <unistd.h>
  3537. int
  3538. main (int argc, char **argv)
  3539. {
  3540. int aflag = 0;
  3541. int bflag = 0;
  3542. char *cvalue = NULL;
  3543. int index;
  3544. int c;
  3545. opterr = 0;
  3546. while ((c = getopt (argc, argv, "abc:")) != -1)
  3547. switch (c)
  3548. {
  3549. case 'a':
  3550. aflag = 1;
  3551. break;
  3552. case 'b':
  3553. bflag = 1;
  3554. break;
  3555. case 'c':
  3556. cvalue = optarg;
  3557. break;
  3558. case '?':
  3559. if (optopt == 'c')
  3560. fprintf (stderr, "Option -%c requires an argument.\n", optopt);
  3561. else if (isprint (optopt))
  3562. fprintf (stderr, "Unknown option `-%c'.\n", optopt);
  3563. else
  3564. fprintf (stderr,
  3565. "Unknown option character `\\x%x'.\n",
  3566. optopt);
  3567. return 1;
  3568. default:
  3569. abort ();
  3570. }
  3571. printf ("aflag = %d, bflag = %d, cvalue = %s\n",
  3572. aflag, bflag, cvalue);
  3573. for (index = optind; index < argc; index++)
  3574. printf ("Non-option argument %s\n", argv[index]);
  3575. return 0;
  3576. }
  3577. Here are some examples showing what this program prints with
  3578. different combinations of arguments:
  3579. % testopt
  3580. aflag = 0, bflag = 0, cvalue = (null)
  3581. % testopt -a -b
  3582. aflag = 1, bflag = 1, cvalue = (null)
  3583. % testopt -ab
  3584. aflag = 1, bflag = 1, cvalue = (null)
  3585. % testopt -c foo
  3586. aflag = 0, bflag = 0, cvalue = foo
  3587. % testopt -cfoo
  3588. aflag = 0, bflag = 0, cvalue = foo
  3589. % testopt arg1
  3590. aflag = 0, bflag = 0, cvalue = (null)
  3591. Non-option argument arg1
  3592. % testopt -a arg1
  3593. aflag = 1, bflag = 0, cvalue = (null)
  3594. Non-option argument arg1
  3595. % testopt -c foo arg1
  3596. aflag = 0, bflag = 0, cvalue = foo
  3597. Non-option argument arg1
  3598. % testopt -a -- -b
  3599. aflag = 1, bflag = 0, cvalue = (null)
  3600. Non-option argument -b
  3601. % testopt -a -
  3602. aflag = 1, bflag = 0, cvalue = (null)
  3603. Non-option argument -
  3604. 
  3605. File: libc.info, Node: Getopt Long Options, Next: Getopt Long Option Example, Prev: Example of Getopt, Up: Getopt
  3606. 25.2.3 Parsing Long Options with ‘getopt_long’
  3607. ----------------------------------------------
  3608. To accept GNU-style long options as well as single-character options,
  3609. use ‘getopt_long’ instead of ‘getopt’. This function is declared in
  3610. ‘getopt.h’, not ‘unistd.h’. You should make every program accept long
  3611. options if it uses any options, for this takes little extra work and
  3612. helps beginners remember how to use the program.
  3613. -- Data Type: struct option
  3614. This structure describes a single long option name for the sake of
  3615. ‘getopt_long’. The argument LONGOPTS must be an array of these
  3616. structures, one for each long option. Terminate the array with an
  3617. element containing all zeros.
  3618. The ‘struct option’ structure has these fields:
  3619. ‘const char *name’
  3620. This field is the name of the option. It is a string.
  3621. ‘int has_arg’
  3622. This field says whether the option takes an argument. It is
  3623. an integer, and there are three legitimate values:
  3624. ‘no_argument’, ‘required_argument’ and ‘optional_argument’.
  3625. ‘int *flag’
  3626. ‘int val’
  3627. These fields control how to report or act on the option when
  3628. it occurs.
  3629. If ‘flag’ is a null pointer, then the ‘val’ is a value which
  3630. identifies this option. Often these values are chosen to
  3631. uniquely identify particular long options.
  3632. If ‘flag’ is not a null pointer, it should be the address of
  3633. an ‘int’ variable which is the flag for this option. The
  3634. value in ‘val’ is the value to store in the flag to indicate
  3635. that the option was seen.
  3636. -- Function: int getopt_long (int ARGC, char *const *ARGV, const char
  3637. *SHORTOPTS, const struct option *LONGOPTS, int *INDEXPTR)
  3638. Preliminary: | MT-Unsafe race:getopt env | AS-Unsafe heap i18n lock
  3639. corrupt | AC-Unsafe mem lock corrupt | *Note POSIX Safety
  3640. Concepts::.
  3641. Decode options from the vector ARGV (whose length is ARGC). The
  3642. argument SHORTOPTS describes the short options to accept, just as
  3643. it does in ‘getopt’. The argument LONGOPTS describes the long
  3644. options to accept (see above).
  3645. When ‘getopt_long’ encounters a short option, it does the same
  3646. thing that ‘getopt’ would do: it returns the character code for the
  3647. option, and stores the option’s argument (if it has one) in
  3648. ‘optarg’.
  3649. When ‘getopt_long’ encounters a long option, it takes actions based
  3650. on the ‘flag’ and ‘val’ fields of the definition of that option.
  3651. If ‘flag’ is a null pointer, then ‘getopt_long’ returns the
  3652. contents of ‘val’ to indicate which option it found. You should
  3653. arrange distinct values in the ‘val’ field for options with
  3654. different meanings, so you can decode these values after
  3655. ‘getopt_long’ returns. If the long option is equivalent to a short
  3656. option, you can use the short option’s character code in ‘val’.
  3657. If ‘flag’ is not a null pointer, that means this option should just
  3658. set a flag in the program. The flag is a variable of type ‘int’
  3659. that you define. Put the address of the flag in the ‘flag’ field.
  3660. Put in the ‘val’ field the value you would like this option to
  3661. store in the flag. In this case, ‘getopt_long’ returns ‘0’.
  3662. For any long option, ‘getopt_long’ tells you the index in the array
  3663. LONGOPTS of the options definition, by storing it into ‘*INDEXPTR’.
  3664. You can get the name of the option with ‘LONGOPTS[*INDEXPTR].name’.
  3665. So you can distinguish among long options either by the values in
  3666. their ‘val’ fields or by their indices. You can also distinguish
  3667. in this way among long options that set flags.
  3668. When a long option has an argument, ‘getopt_long’ puts the argument
  3669. value in the variable ‘optarg’ before returning. When the option
  3670. has no argument, the value in ‘optarg’ is a null pointer. This is
  3671. how you can tell whether an optional argument was supplied.
  3672. When ‘getopt_long’ has no more options to handle, it returns ‘-1’,
  3673. and leaves in the variable ‘optind’ the index in ARGV of the next
  3674. remaining argument.
  3675. Since long option names were used before ‘getopt_long’ was invented
  3676. there are program interfaces which require programs to recognize options
  3677. like ‘-option value’ instead of ‘--option value’. To enable these
  3678. programs to use the GNU getopt functionality there is one more function
  3679. available.
  3680. -- Function: int getopt_long_only (int ARGC, char *const *ARGV, const
  3681. char *SHORTOPTS, const struct option *LONGOPTS, int *INDEXPTR)
  3682. Preliminary: | MT-Unsafe race:getopt env | AS-Unsafe heap i18n lock
  3683. corrupt | AC-Unsafe mem lock corrupt | *Note POSIX Safety
  3684. Concepts::.
  3685. The ‘getopt_long_only’ function is equivalent to the ‘getopt_long’
  3686. function but it allows the user of the application to pass long
  3687. options with only ‘-’ instead of ‘--’. The ‘--’ prefix is still
  3688. recognized but instead of looking through the short options if a
  3689. ‘-’ is seen it is first tried whether this parameter names a long
  3690. option. If not, it is parsed as a short option.
  3691. Assuming ‘getopt_long_only’ is used starting an application with
  3692. app -foo
  3693. the ‘getopt_long_only’ will first look for a long option named
  3694. ‘foo’. If this is not found, the short options ‘f’, ‘o’, and again
  3695. ‘o’ are recognized.
  3696. 
  3697. File: libc.info, Node: Getopt Long Option Example, Prev: Getopt Long Options, Up: Getopt
  3698. 25.2.4 Example of Parsing Long Options with ‘getopt_long’
  3699. ---------------------------------------------------------
  3700. #include <stdio.h>
  3701. #include <stdlib.h>
  3702. #include <getopt.h>
  3703. /* Flag set by ‘--verbose’. */
  3704. static int verbose_flag;
  3705. int
  3706. main (int argc, char **argv)
  3707. {
  3708. int c;
  3709. while (1)
  3710. {
  3711. static struct option long_options[] =
  3712. {
  3713. /* These options set a flag. */
  3714. {"verbose", no_argument, &verbose_flag, 1},
  3715. {"brief", no_argument, &verbose_flag, 0},
  3716. /* These options don’t set a flag.
  3717. We distinguish them by their indices. */
  3718. {"add", no_argument, 0, 'a'},
  3719. {"append", no_argument, 0, 'b'},
  3720. {"delete", required_argument, 0, 'd'},
  3721. {"create", required_argument, 0, 'c'},
  3722. {"file", required_argument, 0, 'f'},
  3723. {0, 0, 0, 0}
  3724. };
  3725. /* ‘getopt_long’ stores the option index here. */
  3726. int option_index = 0;
  3727. c = getopt_long (argc, argv, "abc:d:f:",
  3728. long_options, &option_index);
  3729. /* Detect the end of the options. */
  3730. if (c == -1)
  3731. break;
  3732. switch (c)
  3733. {
  3734. case 0:
  3735. /* If this option set a flag, do nothing else now. */
  3736. if (long_options[option_index].flag != 0)
  3737. break;
  3738. printf ("option %s", long_options[option_index].name);
  3739. if (optarg)
  3740. printf (" with arg %s", optarg);
  3741. printf ("\n");
  3742. break;
  3743. case 'a':
  3744. puts ("option -a\n");
  3745. break;
  3746. case 'b':
  3747. puts ("option -b\n");
  3748. break;
  3749. case 'c':
  3750. printf ("option -c with value `%s'\n", optarg);
  3751. break;
  3752. case 'd':
  3753. printf ("option -d with value `%s'\n", optarg);
  3754. break;
  3755. case 'f':
  3756. printf ("option -f with value `%s'\n", optarg);
  3757. break;
  3758. case '?':
  3759. /* ‘getopt_long’ already printed an error message. */
  3760. break;
  3761. default:
  3762. abort ();
  3763. }
  3764. }
  3765. /* Instead of reporting ‘--verbose’
  3766. and ‘--brief’ as they are encountered,
  3767. we report the final status resulting from them. */
  3768. if (verbose_flag)
  3769. puts ("verbose flag is set");
  3770. /* Print any remaining command line arguments (not options). */
  3771. if (optind < argc)
  3772. {
  3773. printf ("non-option ARGV-elements: ");
  3774. while (optind < argc)
  3775. printf ("%s ", argv[optind++]);
  3776. putchar ('\n');
  3777. }
  3778. exit (0);
  3779. }
  3780. 
  3781. File: libc.info, Node: Argp, Next: Suboptions, Prev: Getopt, Up: Parsing Program Arguments
  3782. 25.3 Parsing Program Options with Argp
  3783. ======================================
  3784. "Argp" is an interface for parsing unix-style argument vectors. *Note
  3785. Program Arguments::.
  3786. Argp provides features unavailable in the more commonly used ‘getopt’
  3787. interface. These features include automatically producing output in
  3788. response to the ‘--help’ and ‘--version’ options, as described in the
  3789. GNU coding standards. Using argp makes it less likely that programmers
  3790. will neglect to implement these additional options or keep them up to
  3791. date.
  3792. Argp also provides the ability to merge several independently defined
  3793. option parsers into one, mediating conflicts between them and making the
  3794. result appear seamless. A library can export an argp option parser that
  3795. user programs might employ in conjunction with their own option parsers,
  3796. resulting in less work for the user programs. Some programs may use
  3797. only argument parsers exported by libraries, thereby achieving
  3798. consistent and efficient option-parsing for abstractions implemented by
  3799. the libraries.
  3800. The header file ‘<argp.h>’ should be included to use argp.
  3801. 25.3.1 The ‘argp_parse’ Function
  3802. --------------------------------
  3803. The main interface to argp is the ‘argp_parse’ function. In many cases,
  3804. calling ‘argp_parse’ is the only argument-parsing code needed in ‘main’.
  3805. *Note Program Arguments::.
  3806. -- Function: error_t argp_parse (const struct argp *ARGP, int ARGC,
  3807. char **ARGV, unsigned FLAGS, int *ARG_INDEX, void *INPUT)
  3808. Preliminary: | MT-Unsafe race:argpbuf locale env | AS-Unsafe heap
  3809. i18n lock corrupt | AC-Unsafe mem lock corrupt | *Note POSIX Safety
  3810. Concepts::.
  3811. The ‘argp_parse’ function parses the arguments in ARGV, of length
  3812. ARGC, using the argp parser ARGP. *Note Argp Parsers::. Passing a
  3813. null pointer for ARGP is the same as using a ‘struct argp’
  3814. containing all zeros.
  3815. FLAGS is a set of flag bits that modify the parsing behavior.
  3816. *Note Argp Flags::. INPUT is passed through to the argp parser
  3817. ARGP, and has meaning defined by ARGP. A typical usage is to pass
  3818. a pointer to a structure which is used for specifying parameters to
  3819. the parser and passing back the results.
  3820. Unless the ‘ARGP_NO_EXIT’ or ‘ARGP_NO_HELP’ flags are included in
  3821. FLAGS, calling ‘argp_parse’ may result in the program exiting.
  3822. This behavior is true if an error is detected, or when an unknown
  3823. option is encountered. *Note Program Termination::.
  3824. If ARG_INDEX is non-null, the index of the first unparsed option in
  3825. ARGV is returned as a value.
  3826. The return value is zero for successful parsing, or an error code
  3827. (*note Error Codes::) if an error is detected. Different argp
  3828. parsers may return arbitrary error codes, but the standard error
  3829. codes are: ‘ENOMEM’ if a memory allocation error occurred, or
  3830. ‘EINVAL’ if an unknown option or option argument is encountered.
  3831. * Menu:
  3832. * Globals: Argp Global Variables. Global argp parameters.
  3833. * Parsers: Argp Parsers. Defining parsers for use with ‘argp_parse’.
  3834. * Flags: Argp Flags. Flags that modify the behavior of ‘argp_parse’.
  3835. * Help: Argp Help. Printing help messages when not parsing.
  3836. * Examples: Argp Examples. Simple examples of programs using argp.
  3837. * Customization: Argp User Customization.
  3838. Users may control the ‘--help’ output format.
  3839. 
  3840. File: libc.info, Node: Argp Global Variables, Next: Argp Parsers, Up: Argp
  3841. 25.3.2 Argp Global Variables
  3842. ----------------------------
  3843. These variables make it easy for user programs to implement the
  3844. ‘--version’ option and provide a bug-reporting address in the ‘--help’
  3845. output. These are implemented in argp by default.
  3846. -- Variable: const char * argp_program_version
  3847. If defined or set by the user program to a non-zero value, then a
  3848. ‘--version’ option is added when parsing with ‘argp_parse’, which
  3849. will print the ‘--version’ string followed by a newline and exit.
  3850. The exception to this is if the ‘ARGP_NO_EXIT’ flag is used.
  3851. -- Variable: const char * argp_program_bug_address
  3852. If defined or set by the user program to a non-zero value,
  3853. ‘argp_program_bug_address’ should point to a string that will be
  3854. printed at the end of the standard output for the ‘--help’ option,
  3855. embedded in a sentence that says ‘Report bugs to ADDRESS.’.
  3856. -- Variable: argp_program_version_hook
  3857. If defined or set by the user program to a non-zero value, a
  3858. ‘--version’ option is added when parsing with ‘arg_parse’, which
  3859. prints the program version and exits with a status of zero. This
  3860. is not the case if the ‘ARGP_NO_HELP’ flag is used. If the
  3861. ‘ARGP_NO_EXIT’ flag is set, the exit behavior of the program is
  3862. suppressed or modified, as when the argp parser is going to be used
  3863. by other programs.
  3864. It should point to a function with this type of signature:
  3865. void PRINT-VERSION (FILE *STREAM, struct argp_state *STATE)
  3866. *Note Argp Parsing State::, for an explanation of STATE.
  3867. This variable takes precedence over ‘argp_program_version’, and is
  3868. useful if a program has version information not easily expressed in
  3869. a simple string.
  3870. -- Variable: error_t argp_err_exit_status
  3871. This is the exit status used when argp exits due to a parsing
  3872. error. If not defined or set by the user program, this defaults
  3873. to: ‘EX_USAGE’ from ‘<sysexits.h>’.
  3874. 
  3875. File: libc.info, Node: Argp Parsers, Next: Argp Flags, Prev: Argp Global Variables, Up: Argp
  3876. 25.3.3 Specifying Argp Parsers
  3877. ------------------------------
  3878. The first argument to the ‘argp_parse’ function is a pointer to a
  3879. ‘struct argp’, which is known as an "argp parser":
  3880. -- Data Type: struct argp
  3881. This structure specifies how to parse a given set of options and
  3882. arguments, perhaps in conjunction with other argp parsers. It has
  3883. the following fields:
  3884. ‘const struct argp_option *options’
  3885. A pointer to a vector of ‘argp_option’ structures specifying
  3886. which options this argp parser understands; it may be zero if
  3887. there are no options at all. *Note Argp Option Vectors::.
  3888. ‘argp_parser_t parser’
  3889. A pointer to a function that defines actions for this parser;
  3890. it is called for each option parsed, and at other well-defined
  3891. points in the parsing process. A value of zero is the same as
  3892. a pointer to a function that always returns
  3893. ‘ARGP_ERR_UNKNOWN’. *Note Argp Parser Functions::.
  3894. ‘const char *args_doc’
  3895. If non-zero, a string describing what non-option arguments are
  3896. called by this parser. This is only used to print the
  3897. ‘Usage:’ message. If it contains newlines, the strings
  3898. separated by them are considered alternative usage patterns
  3899. and printed on separate lines. Lines after the first are
  3900. prefixed by ‘ or: ’ instead of ‘Usage:’.
  3901. ‘const char *doc’
  3902. If non-zero, a string containing extra text to be printed
  3903. before and after the options in a long help message, with the
  3904. two sections separated by a vertical tab (‘'\v'’, ‘'\013'’)
  3905. character. By convention, the documentation before the
  3906. options is just a short string explaining what the program
  3907. does. Documentation printed after the options describe
  3908. behavior in more detail.
  3909. ‘const struct argp_child *children’
  3910. A pointer to a vector of ‘argp_child’ structures. This
  3911. pointer specifies which additional argp parsers should be
  3912. combined with this one. *Note Argp Children::.
  3913. ‘char *(*help_filter)(int KEY, const char *TEXT, void *INPUT)’
  3914. If non-zero, a pointer to a function that filters the output
  3915. of help messages. *Note Argp Help Filtering::.
  3916. ‘const char *argp_domain’
  3917. If non-zero, the strings used in the argp library are
  3918. translated using the domain described by this string. If
  3919. zero, the current default domain is used.
  3920. Of the above group, ‘options’, ‘parser’, ‘args_doc’, and the ‘doc’
  3921. fields are usually all that are needed. If an argp parser is defined as
  3922. an initialized C variable, only the fields used need be specified in the
  3923. initializer. The rest will default to zero due to the way C structure
  3924. initialization works. This design is exploited in most argp structures;
  3925. the most-used fields are grouped near the beginning, the unused fields
  3926. left unspecified.
  3927. * Menu:
  3928. * Options: Argp Option Vectors. Specifying options in an argp parser.
  3929. * Argp Parser Functions:: Defining actions for an argp parser.
  3930. * Children: Argp Children. Combining multiple argp parsers.
  3931. * Help Filtering: Argp Help Filtering. Customizing help output for an argp parser.
  3932. 
  3933. File: libc.info, Node: Argp Option Vectors, Next: Argp Parser Functions, Prev: Argp Parsers, Up: Argp Parsers
  3934. 25.3.4 Specifying Options in an Argp Parser
  3935. -------------------------------------------
  3936. The ‘options’ field in a ‘struct argp’ points to a vector of ‘struct
  3937. argp_option’ structures, each of which specifies an option that the argp
  3938. parser supports. Multiple entries may be used for a single option
  3939. provided it has multiple names. This should be terminated by an entry
  3940. with zero in all fields. Note that when using an initialized C array
  3941. for options, writing ‘{ 0 }’ is enough to achieve this.
  3942. -- Data Type: struct argp_option
  3943. This structure specifies a single option that an argp parser
  3944. understands, as well as how to parse and document that option. It
  3945. has the following fields:
  3946. ‘const char *name’
  3947. The long name for this option, corresponding to the long
  3948. option ‘--NAME’; this field may be zero if this option _only_
  3949. has a short name. To specify multiple names for an option,
  3950. additional entries may follow this one, with the
  3951. ‘OPTION_ALIAS’ flag set. *Note Argp Option Flags::.
  3952. ‘int key’
  3953. The integer key provided by the current option to the option
  3954. parser. If KEY has a value that is a printable ASCII
  3955. character (i.e., ‘isascii (KEY)’ is true), it _also_ specifies
  3956. a short option ‘-CHAR’, where CHAR is the ASCII character with
  3957. the code KEY.
  3958. ‘const char *arg’
  3959. If non-zero, this is the name of an argument associated with
  3960. this option, which must be provided (e.g., with the
  3961. ‘--NAME=VALUE’ or ‘-CHAR VALUE’ syntaxes), unless the
  3962. ‘OPTION_ARG_OPTIONAL’ flag (*note Argp Option Flags::) is set,
  3963. in which case it _may_ be provided.
  3964. ‘int flags’
  3965. Flags associated with this option, some of which are referred
  3966. to above. *Note Argp Option Flags::.
  3967. ‘const char *doc’
  3968. A documentation string for this option, for printing in help
  3969. messages.
  3970. If both the ‘name’ and ‘key’ fields are zero, this string will
  3971. be printed tabbed left from the normal option column, making
  3972. it useful as a group header. This will be the first thing
  3973. printed in its group. In this usage, it’s conventional to end
  3974. the string with a ‘:’ character.
  3975. ‘int group’
  3976. Group identity for this option.
  3977. In a long help message, options are sorted alphabetically
  3978. within each group, and the groups presented in the order 0, 1,
  3979. 2, …, N, −M, …, −2, −1.
  3980. Every entry in an options array with this field 0 will inherit
  3981. the group number of the previous entry, or zero if it’s the
  3982. first one. If it’s a group header with ‘name’ and ‘key’
  3983. fields both zero, the previous entry + 1 is the default.
  3984. Automagic options such as ‘--help’ are put into group −1.
  3985. Note that because of C structure initialization rules, this
  3986. field often need not be specified, because 0 is the correct
  3987. value.
  3988. * Menu:
  3989. * Flags: Argp Option Flags. Flags for options.
  3990. 
  3991. File: libc.info, Node: Argp Option Flags, Up: Argp Option Vectors
  3992. 25.3.4.1 Flags for Argp Options
  3993. ...............................
  3994. The following flags may be or’d together in the ‘flags’ field of a
  3995. ‘struct argp_option’. These flags control various aspects of how that
  3996. option is parsed or displayed in help messages:
  3997. ‘OPTION_ARG_OPTIONAL’
  3998. The argument associated with this option is optional.
  3999. ‘OPTION_HIDDEN’
  4000. This option isn’t displayed in any help messages.
  4001. ‘OPTION_ALIAS’
  4002. This option is an alias for the closest previous non-alias option.
  4003. This means that it will be displayed in the same help entry, and
  4004. will inherit fields other than ‘name’ and ‘key’ from the option
  4005. being aliased.
  4006. ‘OPTION_DOC’
  4007. This option isn’t actually an option and should be ignored by the
  4008. actual option parser. It is an arbitrary section of documentation
  4009. that should be displayed in much the same manner as the options.
  4010. This is known as a "documentation option".
  4011. If this flag is set, then the option ‘name’ field is displayed
  4012. unmodified (e.g., no ‘--’ prefix is added) at the left-margin where
  4013. a _short_ option would normally be displayed, and this
  4014. documentation string is left in its usual place. For purposes of
  4015. sorting, any leading whitespace and punctuation is ignored, unless
  4016. the first non-whitespace character is ‘-’. This entry is displayed
  4017. after all options, after ‘OPTION_DOC’ entries with a leading ‘-’,
  4018. in the same group.
  4019. ‘OPTION_NO_USAGE’
  4020. This option shouldn’t be included in ‘long’ usage messages, but
  4021. should still be included in other help messages. This is intended
  4022. for options that are completely documented in an argp’s ‘args_doc’
  4023. field. *Note Argp Parsers::. Including this option in the generic
  4024. usage list would be redundant, and should be avoided.
  4025. For instance, if ‘args_doc’ is ‘"FOO BAR\n-x BLAH"’, and the ‘-x’
  4026. option’s purpose is to distinguish these two cases, ‘-x’ should
  4027. probably be marked ‘OPTION_NO_USAGE’.
  4028. 
  4029. File: libc.info, Node: Argp Parser Functions, Next: Argp Children, Prev: Argp Option Vectors, Up: Argp Parsers
  4030. 25.3.5 Argp Parser Functions
  4031. ----------------------------
  4032. The function pointed to by the ‘parser’ field in a ‘struct argp’ (*note
  4033. Argp Parsers::) defines what actions take place in response to each
  4034. option or argument parsed. It is also used as a hook, allowing a parser
  4035. to perform tasks at certain other points during parsing.
  4036. Argp parser functions have the following type signature:
  4037. error_t PARSER (int KEY, char *ARG, struct argp_state *STATE)
  4038. where the arguments are as follows:
  4039. KEY
  4040. For each option that is parsed, PARSER is called with a value of
  4041. KEY from that option’s ‘key’ field in the option vector. *Note
  4042. Argp Option Vectors::. PARSER is also called at other times with
  4043. special reserved keys, such as ‘ARGP_KEY_ARG’ for non-option
  4044. arguments. *Note Argp Special Keys::.
  4045. ARG
  4046. If KEY is an option, ARG is its given value. This defaults to zero
  4047. if no value is specified. Only options that have a non-zero ‘arg’
  4048. field can ever have a value. These must _always_ have a value
  4049. unless the ‘OPTION_ARG_OPTIONAL’ flag is specified. If the input
  4050. being parsed specifies a value for an option that doesn’t allow
  4051. one, an error results before PARSER ever gets called.
  4052. If KEY is ‘ARGP_KEY_ARG’, ARG is a non-option argument. Other
  4053. special keys always have a zero ARG.
  4054. STATE
  4055. STATE points to a ‘struct argp_state’, containing useful
  4056. information about the current parsing state for use by PARSER.
  4057. *Note Argp Parsing State::.
  4058. When PARSER is called, it should perform whatever action is
  4059. appropriate for KEY, and return ‘0’ for success, ‘ARGP_ERR_UNKNOWN’ if
  4060. the value of KEY is not handled by this parser function, or a unix error
  4061. code if a real error occurred. *Note Error Codes::.
  4062. -- Macro: int ARGP_ERR_UNKNOWN
  4063. Argp parser functions should return ‘ARGP_ERR_UNKNOWN’ for any KEY
  4064. value they do not recognize, or for non-option arguments (‘KEY ==
  4065. ARGP_KEY_ARG’) that they are not equipped to handle.
  4066. A typical parser function uses a switch statement on KEY:
  4067. error_t
  4068. parse_opt (int key, char *arg, struct argp_state *state)
  4069. {
  4070. switch (key)
  4071. {
  4072. case OPTION_KEY:
  4073. ACTION
  4074. break;
  4075. default:
  4076. return ARGP_ERR_UNKNOWN;
  4077. }
  4078. return 0;
  4079. }
  4080. * Menu:
  4081. * Keys: Argp Special Keys. Special values for the KEY argument.
  4082. * State: Argp Parsing State. What the STATE argument refers to.
  4083. * Functions: Argp Helper Functions. Functions to help during argp parsing.
  4084. 
  4085. File: libc.info, Node: Argp Special Keys, Next: Argp Parsing State, Up: Argp Parser Functions
  4086. 25.3.5.1 Special Keys for Argp Parser Functions
  4087. ...............................................
  4088. In addition to key values corresponding to user options, the KEY
  4089. argument to argp parser functions may have a number of other special
  4090. values. In the following example ARG and STATE refer to parser function
  4091. arguments. *Note Argp Parser Functions::.
  4092. ‘ARGP_KEY_ARG’
  4093. This is not an option at all, but rather a command line argument,
  4094. whose value is pointed to by ARG.
  4095. When there are multiple parser functions in play due to argp
  4096. parsers being combined, it’s impossible to know which one will
  4097. handle a specific argument. Each is called until one returns 0 or
  4098. an error other than ‘ARGP_ERR_UNKNOWN’; if an argument is not
  4099. handled, ‘argp_parse’ immediately returns success, without parsing
  4100. any more arguments.
  4101. Once a parser function returns success for this key, that fact is
  4102. recorded, and the ‘ARGP_KEY_NO_ARGS’ case won’t be used.
  4103. _However_, if while processing the argument a parser function
  4104. decrements the ‘next’ field of its STATE argument, the option won’t
  4105. be considered processed; this is to allow you to actually modify
  4106. the argument, perhaps into an option, and have it processed again.
  4107. ‘ARGP_KEY_ARGS’
  4108. If a parser function returns ‘ARGP_ERR_UNKNOWN’ for ‘ARGP_KEY_ARG’,
  4109. it is immediately called again with the key ‘ARGP_KEY_ARGS’, which
  4110. has a similar meaning, but is slightly more convenient for
  4111. consuming all remaining arguments. ARG is 0, and the tail of the
  4112. argument vector may be found at ‘STATE->argv + STATE->next’. If
  4113. success is returned for this key, and ‘STATE->next’ is unchanged,
  4114. all remaining arguments are considered to have been consumed.
  4115. Otherwise, the amount by which ‘STATE->next’ has been adjusted
  4116. indicates how many were used. Here’s an example that uses both,
  4117. for different args:
  4118. case ARGP_KEY_ARG:
  4119. if (STATE->arg_num == 0)
  4120. /* First argument */
  4121. first_arg = ARG;
  4122. else
  4123. /* Let the next case parse it. */
  4124. return ARGP_KEY_UNKNOWN;
  4125. break;
  4126. case ARGP_KEY_ARGS:
  4127. remaining_args = STATE->argv + STATE->next;
  4128. num_remaining_args = STATE->argc - STATE->next;
  4129. break;
  4130. ‘ARGP_KEY_END’
  4131. This indicates that there are no more command line arguments.
  4132. Parser functions are called in a different order, children first.
  4133. This allows each parser to clean up its state for the parent.
  4134. ‘ARGP_KEY_NO_ARGS’
  4135. Because it’s common to do some special processing if there aren’t
  4136. any non-option args, parser functions are called with this key if
  4137. they didn’t successfully process any non-option arguments. This is
  4138. called just before ‘ARGP_KEY_END’, where more general validity
  4139. checks on previously parsed arguments take place.
  4140. ‘ARGP_KEY_INIT’
  4141. This is passed in before any parsing is done. Afterwards, the
  4142. values of each element of the ‘child_input’ field of STATE, if any,
  4143. are copied to each child’s state to be the initial value of the
  4144. ‘input’ when _their_ parsers are called.
  4145. ‘ARGP_KEY_SUCCESS’
  4146. Passed in when parsing has successfully been completed, even if
  4147. arguments remain.
  4148. ‘ARGP_KEY_ERROR’
  4149. Passed in if an error has occurred and parsing is terminated. In
  4150. this case a call with a key of ‘ARGP_KEY_SUCCESS’ is never made.
  4151. ‘ARGP_KEY_FINI’
  4152. The final key ever seen by any parser, even after
  4153. ‘ARGP_KEY_SUCCESS’ and ‘ARGP_KEY_ERROR’. Any resources allocated
  4154. by ‘ARGP_KEY_INIT’ may be freed here. At times, certain resources
  4155. allocated are to be returned to the caller after a successful
  4156. parse. In that case, those particular resources can be freed in
  4157. the ‘ARGP_KEY_ERROR’ case.
  4158. In all cases, ‘ARGP_KEY_INIT’ is the first key seen by parser
  4159. functions, and ‘ARGP_KEY_FINI’ the last, unless an error was returned by
  4160. the parser for ‘ARGP_KEY_INIT’. Other keys can occur in one the
  4161. following orders. OPT refers to an arbitrary option key:
  4162. OPT… ‘ARGP_KEY_NO_ARGS’ ‘ARGP_KEY_END’ ‘ARGP_KEY_SUCCESS’
  4163. The arguments being parsed did not contain any non-option
  4164. arguments.
  4165. ( OPT | ‘ARGP_KEY_ARG’ )… ‘ARGP_KEY_END’ ‘ARGP_KEY_SUCCESS’
  4166. All non-option arguments were successfully handled by a parser
  4167. function. There may be multiple parser functions if multiple argp
  4168. parsers were combined.
  4169. ( OPT | ‘ARGP_KEY_ARG’ )… ‘ARGP_KEY_SUCCESS’
  4170. Some non-option argument went unrecognized.
  4171. This occurs when every parser function returns ‘ARGP_KEY_UNKNOWN’
  4172. for an argument, in which case parsing stops at that argument if
  4173. ARG_INDEX is a null pointer. Otherwise an error occurs.
  4174. In all cases, if a non-null value for ARG_INDEX gets passed to
  4175. ‘argp_parse’, the index of the first unparsed command-line argument is
  4176. passed back in that value.
  4177. If an error occurs and is either detected by argp or because a parser
  4178. function returned an error value, each parser is called with
  4179. ‘ARGP_KEY_ERROR’. No further calls are made, except the final call with
  4180. ‘ARGP_KEY_FINI’.
  4181. 
  4182. File: libc.info, Node: Argp Parsing State, Next: Argp Helper Functions, Prev: Argp Special Keys, Up: Argp Parser Functions
  4183. 25.3.5.2 Argp Parsing State
  4184. ...........................
  4185. The third argument to argp parser functions (*note Argp Parser
  4186. Functions::) is a pointer to a ‘struct argp_state’, which contains
  4187. information about the state of the option parsing.
  4188. -- Data Type: struct argp_state
  4189. This structure has the following fields, which may be modified as
  4190. noted:
  4191. ‘const struct argp *const root_argp’
  4192. The top level argp parser being parsed. Note that this is
  4193. often _not_ the same ‘struct argp’ passed into ‘argp_parse’ by
  4194. the invoking program. *Note Argp::. It is an internal argp
  4195. parser that contains options implemented by ‘argp_parse’
  4196. itself, such as ‘--help’.
  4197. ‘int argc’
  4198. ‘char **argv’
  4199. The argument vector being parsed. This may be modified.
  4200. ‘int next’
  4201. The index in ‘argv’ of the next argument to be parsed. This
  4202. may be modified.
  4203. One way to consume all remaining arguments in the input is to
  4204. set ‘STATE->next = STATE->argc’, perhaps after recording the
  4205. value of the ‘next’ field to find the consumed arguments. The
  4206. current option can be re-parsed immediately by decrementing
  4207. this field, then modifying ‘STATE->argv[STATE->next]’ to
  4208. reflect the option that should be reexamined.
  4209. ‘unsigned flags’
  4210. The flags supplied to ‘argp_parse’. These may be modified,
  4211. although some flags may only take effect when ‘argp_parse’ is
  4212. first invoked. *Note Argp Flags::.
  4213. ‘unsigned arg_num’
  4214. While calling a parsing function with the KEY argument
  4215. ‘ARGP_KEY_ARG’, this represents the number of the current arg,
  4216. starting at 0. It is incremented after each ‘ARGP_KEY_ARG’
  4217. call returns. At all other times, this is the number of
  4218. ‘ARGP_KEY_ARG’ arguments that have been processed.
  4219. ‘int quoted’
  4220. If non-zero, the index in ‘argv’ of the first argument
  4221. following a special ‘--’ argument. This prevents anything
  4222. that follows from being interpreted as an option. It is only
  4223. set after argument parsing has proceeded past this point.
  4224. ‘void *input’
  4225. An arbitrary pointer passed in from the caller of
  4226. ‘argp_parse’, in the INPUT argument.
  4227. ‘void **child_inputs’
  4228. These are values that will be passed to child parsers. This
  4229. vector will be the same length as the number of children in
  4230. the current parser. Each child parser will be given the value
  4231. of ‘STATE->child_inputs[I]’ as _its_ ‘STATE->input’ field,
  4232. where I is the index of the child in the this parser’s
  4233. ‘children’ field. *Note Argp Children::.
  4234. ‘void *hook’
  4235. For the parser function’s use. Initialized to 0, but
  4236. otherwise ignored by argp.
  4237. ‘char *name’
  4238. The name used when printing messages. This is initialized to
  4239. ‘argv[0]’, or ‘program_invocation_name’ if ‘argv[0]’ is
  4240. unavailable.
  4241. ‘FILE *err_stream’
  4242. ‘FILE *out_stream’
  4243. The stdio streams used when argp prints. Error messages are
  4244. printed to ‘err_stream’, all other output, such as ‘--help’
  4245. output) to ‘out_stream’. These are initialized to ‘stderr’
  4246. and ‘stdout’ respectively. *Note Standard Streams::.
  4247. ‘void *pstate’
  4248. Private, for use by the argp implementation.
  4249. 
  4250. File: libc.info, Node: Argp Helper Functions, Prev: Argp Parsing State, Up: Argp Parser Functions
  4251. 25.3.5.3 Functions For Use in Argp Parsers
  4252. ..........................................
  4253. Argp provides a number of functions available to the user of argp (*note
  4254. Argp Parser Functions::), mostly for producing error messages. These
  4255. take as their first argument the STATE argument to the parser function.
  4256. *Note Argp Parsing State::.
  4257. -- Function: void argp_usage (const struct argp_state *STATE)
  4258. Preliminary: | MT-Unsafe race:argpbuf env locale | AS-Unsafe heap
  4259. i18n corrupt | AC-Unsafe mem corrupt lock | *Note POSIX Safety
  4260. Concepts::.
  4261. Outputs the standard usage message for the argp parser referred to
  4262. by STATE to ‘STATE->err_stream’ and terminates the program with
  4263. ‘exit (argp_err_exit_status)’. *Note Argp Global Variables::.
  4264. -- Function: void argp_error (const struct argp_state *STATE, const
  4265. char *FMT, …)
  4266. Preliminary: | MT-Unsafe race:argpbuf env locale | AS-Unsafe heap
  4267. i18n corrupt | AC-Unsafe mem corrupt lock | *Note POSIX Safety
  4268. Concepts::.
  4269. Prints the printf format string FMT and following args, preceded by
  4270. the program name and ‘:’, and followed by a ‘Try … --help’ message,
  4271. and terminates the program with an exit status of
  4272. ‘argp_err_exit_status’. *Note Argp Global Variables::.
  4273. -- Function: void argp_failure (const struct argp_state *STATE, int
  4274. STATUS, int ERRNUM, const char *FMT, …)
  4275. Preliminary: | MT-Safe | AS-Unsafe corrupt heap | AC-Unsafe lock
  4276. corrupt mem | *Note POSIX Safety Concepts::.
  4277. Similar to the standard GNU error-reporting function ‘error’, this
  4278. prints the program name and ‘:’, the printf format string FMT, and
  4279. the appropriate following args. If it is non-zero, the standard
  4280. unix error text for ERRNUM is printed. If STATUS is non-zero, it
  4281. terminates the program with that value as its exit status.
  4282. The difference between ‘argp_failure’ and ‘argp_error’ is that
  4283. ‘argp_error’ is for _parsing errors_, whereas ‘argp_failure’ is for
  4284. other problems that occur during parsing but don’t reflect a
  4285. syntactic problem with the input, such as illegal values for
  4286. options, bad phase of the moon, etc.
  4287. -- Function: void argp_state_help (const struct argp_state *STATE, FILE
  4288. *STREAM, unsigned FLAGS)
  4289. Preliminary: | MT-Unsafe race:argpbuf env locale | AS-Unsafe heap
  4290. i18n corrupt | AC-Unsafe mem corrupt lock | *Note POSIX Safety
  4291. Concepts::.
  4292. Outputs a help message for the argp parser referred to by STATE, to
  4293. STREAM. The FLAGS argument determines what sort of help message is
  4294. produced. *Note Argp Help Flags::.
  4295. Error output is sent to ‘STATE->err_stream’, and the program name
  4296. printed is ‘STATE->name’.
  4297. The output or program termination behavior of these functions may be
  4298. suppressed if the ‘ARGP_NO_EXIT’ or ‘ARGP_NO_ERRS’ flags are passed to
  4299. ‘argp_parse’. *Note Argp Flags::.
  4300. This behavior is useful if an argp parser is exported for use by
  4301. other programs (e.g., by a library), and may be used in a context where
  4302. it is not desirable to terminate the program in response to parsing
  4303. errors. In argp parsers intended for such general use, and for the case
  4304. where the program _doesn’t_ terminate, calls to any of these functions
  4305. should be followed by code that returns the appropriate error code:
  4306. if (BAD ARGUMENT SYNTAX)
  4307. {
  4308. argp_usage (STATE);
  4309. return EINVAL;
  4310. }
  4311. If a parser function will _only_ be used when ‘ARGP_NO_EXIT’ is not set,
  4312. the return may be omitted.
  4313. 
  4314. File: libc.info, Node: Argp Children, Next: Argp Help Filtering, Prev: Argp Parser Functions, Up: Argp Parsers
  4315. 25.3.6 Combining Multiple Argp Parsers
  4316. --------------------------------------
  4317. The ‘children’ field in a ‘struct argp’ enables other argp parsers to be
  4318. combined with the referencing one for the parsing of a single set of
  4319. arguments. This field should point to a vector of ‘struct argp_child’,
  4320. which is terminated by an entry having a value of zero in the ‘argp’
  4321. field.
  4322. Where conflicts between combined parsers arise, as when two specify
  4323. an option with the same name, the parser conflicts are resolved in favor
  4324. of the parent argp parser(s), or the earlier of the argp parsers in the
  4325. list of children.
  4326. -- Data Type: struct argp_child
  4327. An entry in the list of subsidiary argp parsers pointed to by the
  4328. ‘children’ field in a ‘struct argp’. The fields are as follows:
  4329. ‘const struct argp *argp’
  4330. The child argp parser, or zero to end of the list.
  4331. ‘int flags’
  4332. Flags for this child.
  4333. ‘const char *header’
  4334. If non-zero, this is an optional header to be printed within
  4335. help output before the child options. As a side-effect, a
  4336. non-zero value forces the child options to be grouped
  4337. together. To achieve this effect without actually printing a
  4338. header string, use a value of ‘""’. As with header strings
  4339. specified in an option entry, the conventional value of the
  4340. last character is ‘:’. *Note Argp Option Vectors::.
  4341. ‘int group’
  4342. This is where the child options are grouped relative to the
  4343. other ‘consolidated’ options in the parent argp parser. The
  4344. values are the same as the ‘group’ field in ‘struct
  4345. argp_option’. *Note Argp Option Vectors::. All
  4346. child-groupings follow parent options at a particular group
  4347. level. If both this field and ‘header’ are zero, then the
  4348. child’s options aren’t grouped together, they are merged with
  4349. parent options at the parent option group level.
  4350. 
  4351. File: libc.info, Node: Argp Flags, Next: Argp Help, Prev: Argp Parsers, Up: Argp
  4352. 25.3.7 Flags for ‘argp_parse’
  4353. -----------------------------
  4354. The default behavior of ‘argp_parse’ is designed to be convenient for
  4355. the most common case of parsing program command line argument. To
  4356. modify these defaults, the following flags may be or’d together in the
  4357. FLAGS argument to ‘argp_parse’:
  4358. ‘ARGP_PARSE_ARGV0’
  4359. Don’t ignore the first element of the ARGV argument to
  4360. ‘argp_parse’. Unless ‘ARGP_NO_ERRS’ is set, the first element of
  4361. the argument vector is skipped for option parsing purposes, as it
  4362. corresponds to the program name in a command line.
  4363. ‘ARGP_NO_ERRS’
  4364. Don’t print error messages for unknown options to ‘stderr’; unless
  4365. this flag is set, ‘ARGP_PARSE_ARGV0’ is ignored, as ‘argv[0]’ is
  4366. used as the program name in the error messages. This flag implies
  4367. ‘ARGP_NO_EXIT’. This is based on the assumption that silent
  4368. exiting upon errors is bad behavior.
  4369. ‘ARGP_NO_ARGS’
  4370. Don’t parse any non-option args. Normally these are parsed by
  4371. calling the parse functions with a key of ‘ARGP_KEY_ARG’, the
  4372. actual argument being the value. This flag needn’t normally be
  4373. set, as the default behavior is to stop parsing as soon as an
  4374. argument fails to be parsed. *Note Argp Parser Functions::.
  4375. ‘ARGP_IN_ORDER’
  4376. Parse options and arguments in the same order they occur on the
  4377. command line. Normally they’re rearranged so that all options come
  4378. first.
  4379. ‘ARGP_NO_HELP’
  4380. Don’t provide the standard long option ‘--help’, which ordinarily
  4381. causes usage and option help information to be output to ‘stdout’
  4382. and ‘exit (0)’.
  4383. ‘ARGP_NO_EXIT’
  4384. Don’t exit on errors, although they may still result in error
  4385. messages.
  4386. ‘ARGP_LONG_ONLY’
  4387. Use the GNU getopt ‘long-only’ rules for parsing arguments. This
  4388. allows long-options to be recognized with only a single ‘-’ (i.e.,
  4389. ‘-help’). This results in a less useful interface, and its use is
  4390. discouraged as it conflicts with the way most GNU programs work as
  4391. well as the GNU coding standards.
  4392. ‘ARGP_SILENT’
  4393. Turns off any message-printing/exiting options, specifically
  4394. ‘ARGP_NO_EXIT’, ‘ARGP_NO_ERRS’, and ‘ARGP_NO_HELP’.
  4395. 
  4396. File: libc.info, Node: Argp Help Filtering, Prev: Argp Children, Up: Argp Parsers
  4397. 25.3.8 Customizing Argp Help Output
  4398. -----------------------------------
  4399. The ‘help_filter’ field in a ‘struct argp’ is a pointer to a function
  4400. that filters the text of help messages before displaying them. They
  4401. have a function signature like:
  4402. char *HELP-FILTER (int KEY, const char *TEXT, void *INPUT)
  4403. Where KEY is either a key from an option, in which case TEXT is that
  4404. option’s help text. *Note Argp Option Vectors::. Alternately, one of
  4405. the special keys with names beginning with ‘ARGP_KEY_HELP_’ might be
  4406. used, describing which other help text TEXT will contain. *Note Argp
  4407. Help Filter Keys::.
  4408. The function should return either TEXT if it remains as-is, or a
  4409. replacement string allocated using ‘malloc’. This will be either be
  4410. freed by argp or zero, which prints nothing. The value of TEXT is
  4411. supplied _after_ any translation has been done, so if any of the
  4412. replacement text needs translation, it will be done by the filter
  4413. function. INPUT is either the input supplied to ‘argp_parse’ or it is
  4414. zero, if ‘argp_help’ was called directly by the user.
  4415. * Menu:
  4416. * Keys: Argp Help Filter Keys. Special KEY values for help filter functions.
  4417. 
  4418. File: libc.info, Node: Argp Help Filter Keys, Up: Argp Help Filtering
  4419. 25.3.8.1 Special Keys for Argp Help Filter Functions
  4420. ....................................................
  4421. The following special values may be passed to an argp help filter
  4422. function as the first argument in addition to key values for user
  4423. options. They specify which help text the TEXT argument contains:
  4424. ‘ARGP_KEY_HELP_PRE_DOC’
  4425. The help text preceding options.
  4426. ‘ARGP_KEY_HELP_POST_DOC’
  4427. The help text following options.
  4428. ‘ARGP_KEY_HELP_HEADER’
  4429. The option header string.
  4430. ‘ARGP_KEY_HELP_EXTRA’
  4431. This is used after all other documentation; TEXT is zero for this
  4432. key.
  4433. ‘ARGP_KEY_HELP_DUP_ARGS_NOTE’
  4434. The explanatory note printed when duplicate option arguments have
  4435. been suppressed.
  4436. ‘ARGP_KEY_HELP_ARGS_DOC’
  4437. The argument doc string; formally the ‘args_doc’ field from the
  4438. argp parser. *Note Argp Parsers::.
  4439. 
  4440. File: libc.info, Node: Argp Help, Next: Argp Examples, Prev: Argp Flags, Up: Argp
  4441. 25.3.9 The ‘argp_help’ Function
  4442. -------------------------------
  4443. Normally programs using argp need not be written with particular
  4444. printing argument-usage-type help messages in mind as the standard
  4445. ‘--help’ option is handled automatically by argp. Typical error cases
  4446. can be handled using ‘argp_usage’ and ‘argp_error’. *Note Argp Helper
  4447. Functions::. However, if it’s desirable to print a help message in some
  4448. context other than parsing the program options, argp offers the
  4449. ‘argp_help’ interface.
  4450. -- Function: void argp_help (const struct argp *ARGP, FILE *STREAM,
  4451. unsigned FLAGS, char *NAME)
  4452. Preliminary: | MT-Unsafe race:argpbuf env locale | AS-Unsafe heap
  4453. i18n corrupt | AC-Unsafe mem corrupt lock | *Note POSIX Safety
  4454. Concepts::.
  4455. This outputs a help message for the argp parser ARGP to STREAM.
  4456. The type of messages printed will be determined by FLAGS.
  4457. Any options such as ‘--help’ that are implemented automatically by
  4458. argp itself will _not_ be present in the help output; for this
  4459. reason it is best to use ‘argp_state_help’ if calling from within
  4460. an argp parser function. *Note Argp Helper Functions::.
  4461. * Menu:
  4462. * Flags: Argp Help Flags. Specifying what sort of help message to print.
  4463. 
  4464. File: libc.info, Node: Argp Help Flags, Up: Argp Help
  4465. 25.3.10 Flags for the ‘argp_help’ Function
  4466. ------------------------------------------
  4467. When calling ‘argp_help’ (*note Argp Help::) or ‘argp_state_help’ (*note
  4468. Argp Helper Functions::) the exact output is determined by the FLAGS
  4469. argument. This should consist of any of the following flags, or’d
  4470. together:
  4471. ‘ARGP_HELP_USAGE’
  4472. A unix ‘Usage:’ message that explicitly lists all options.
  4473. ‘ARGP_HELP_SHORT_USAGE’
  4474. A unix ‘Usage:’ message that displays an appropriate placeholder to
  4475. indicate where the options go; useful for showing the non-option
  4476. argument syntax.
  4477. ‘ARGP_HELP_SEE’
  4478. A ‘Try … for more help’ message; ‘…’ contains the program name and
  4479. ‘--help’.
  4480. ‘ARGP_HELP_LONG’
  4481. A verbose option help message that gives each option available
  4482. along with its documentation string.
  4483. ‘ARGP_HELP_PRE_DOC’
  4484. The part of the argp parser doc string preceding the verbose option
  4485. help.
  4486. ‘ARGP_HELP_POST_DOC’
  4487. The part of the argp parser doc string that following the verbose
  4488. option help.
  4489. ‘ARGP_HELP_DOC’
  4490. ‘(ARGP_HELP_PRE_DOC | ARGP_HELP_POST_DOC)’
  4491. ‘ARGP_HELP_BUG_ADDR’
  4492. A message that prints where to report bugs for this program, if the
  4493. ‘argp_program_bug_address’ variable contains this information.
  4494. ‘ARGP_HELP_LONG_ONLY’
  4495. This will modify any output to reflect the ‘ARGP_LONG_ONLY’ mode.
  4496. The following flags are only understood when used with
  4497. ‘argp_state_help’. They control whether the function returns after
  4498. printing its output, or terminates the program:
  4499. ‘ARGP_HELP_EXIT_ERR’
  4500. This will terminate the program with ‘exit (argp_err_exit_status)’.
  4501. ‘ARGP_HELP_EXIT_OK’
  4502. This will terminate the program with ‘exit (0)’.
  4503. The following flags are combinations of the basic flags for printing
  4504. standard messages:
  4505. ‘ARGP_HELP_STD_ERR’
  4506. Assuming that an error message for a parsing error has printed,
  4507. this prints a message on how to get help, and terminates the
  4508. program with an error.
  4509. ‘ARGP_HELP_STD_USAGE’
  4510. This prints a standard usage message and terminates the program
  4511. with an error. This is used when no other specific error messages
  4512. are appropriate or available.
  4513. ‘ARGP_HELP_STD_HELP’
  4514. This prints the standard response for a ‘--help’ option, and
  4515. terminates the program successfully.
  4516. 
  4517. File: libc.info, Node: Argp Examples, Next: Argp User Customization, Prev: Argp Help, Up: Argp
  4518. 25.3.11 Argp Examples
  4519. ---------------------
  4520. These example programs demonstrate the basic usage of argp.
  4521. * Menu:
  4522. * 1: Argp Example 1. A minimal program using argp.
  4523. * 2: Argp Example 2. A program using only default options.
  4524. * 3: Argp Example 3. A simple program with user options.
  4525. * 4: Argp Example 4. Combining multiple argp parsers.
  4526. 
  4527. File: libc.info, Node: Argp Example 1, Next: Argp Example 2, Up: Argp Examples
  4528. 25.3.11.1 A Minimal Program Using Argp
  4529. ......................................
  4530. This is perhaps the smallest program possible that uses argp. It won’t
  4531. do much except give an error message and exit when there are any
  4532. arguments, and prints a rather pointless message for ‘--help’.
  4533. /* This is (probably) the smallest possible program that
  4534. uses argp. It won’t do much except give an error
  4535. messages and exit when there are any arguments, and print
  4536. a (rather pointless) messages for –help. */
  4537. #include <stdlib.h>
  4538. #include <argp.h>
  4539. int
  4540. main (int argc, char **argv)
  4541. {
  4542. argp_parse (0, argc, argv, 0, 0, 0);
  4543. exit (0);
  4544. }
  4545. 
  4546. File: libc.info, Node: Argp Example 2, Next: Argp Example 3, Prev: Argp Example 1, Up: Argp Examples
  4547. 25.3.11.2 A Program Using Argp with Only Default Options
  4548. ........................................................
  4549. This program doesn’t use any options or arguments, it uses argp to be
  4550. compliant with the GNU standard command line format.
  4551. In addition to giving no arguments and implementing a ‘--help’
  4552. option, this example has a ‘--version’ option, which will put the given
  4553. documentation string and bug address in the ‘--help’ output, as per GNU
  4554. standards.
  4555. The variable ‘argp’ contains the argument parser specification.
  4556. Adding fields to this structure is the way most parameters are passed to
  4557. ‘argp_parse’. The first three fields are normally used, but they are
  4558. not in this small program. There are also two global variables that
  4559. argp can use defined here, ‘argp_program_version’ and
  4560. ‘argp_program_bug_address’. They are considered global variables
  4561. because they will almost always be constant for a given program, even if
  4562. they use different argument parsers for various tasks.
  4563. /* This program doesn’t use any options or arguments, but uses
  4564. argp to be compliant with the GNU standard command line
  4565. format.
  4566. In addition to making sure no arguments are given, and
  4567. implementing a –help option, this example will have a
  4568. –version option, and will put the given documentation string
  4569. and bug address in the –help output, as per GNU standards.
  4570. The variable ARGP contains the argument parser specification;
  4571. adding fields to this structure is the way most parameters are
  4572. passed to argp_parse (the first three fields are usually used,
  4573. but not in this small program). There are also two global
  4574. variables that argp knows about defined here,
  4575. ARGP_PROGRAM_VERSION and ARGP_PROGRAM_BUG_ADDRESS (they are
  4576. global variables because they will almost always be constant
  4577. for a given program, even if it uses different argument
  4578. parsers for various tasks). */
  4579. #include <stdlib.h>
  4580. #include <argp.h>
  4581. const char *argp_program_version =
  4582. "argp-ex2 1.0";
  4583. const char *argp_program_bug_address =
  4584. "<bug-gnu-utils@gnu.org>";
  4585. /* Program documentation. */
  4586. static char doc[] =
  4587. "Argp example #2 -- a pretty minimal program using argp";
  4588. /* Our argument parser. The ‘options’, ‘parser’, and
  4589. ‘args_doc’ fields are zero because we have neither options or
  4590. arguments; ‘doc’ and ‘argp_program_bug_address’ will be
  4591. used in the output for ‘--help’, and the ‘--version’
  4592. option will print out ‘argp_program_version’. */
  4593. static struct argp argp = { 0, 0, 0, doc };
  4594. int
  4595. main (int argc, char **argv)
  4596. {
  4597. argp_parse (&argp, argc, argv, 0, 0, 0);
  4598. exit (0);
  4599. }
  4600. 
  4601. File: libc.info, Node: Argp Example 3, Next: Argp Example 4, Prev: Argp Example 2, Up: Argp Examples
  4602. 25.3.11.3 A Program Using Argp with User Options
  4603. ................................................
  4604. This program uses the same features as example 2, adding user options
  4605. and arguments.
  4606. We now use the first four fields in ‘argp’ (*note Argp Parsers::) and
  4607. specify ‘parse_opt’ as the parser function. *Note Argp Parser
  4608. Functions::.
  4609. Note that in this example, ‘main’ uses a structure to communicate
  4610. with the ‘parse_opt’ function, a pointer to which it passes in the
  4611. ‘input’ argument to ‘argp_parse’. *Note Argp::. It is retrieved by
  4612. ‘parse_opt’ through the ‘input’ field in its ‘state’ argument. *Note
  4613. Argp Parsing State::. Of course, it’s also possible to use global
  4614. variables instead, but using a structure like this is somewhat more
  4615. flexible and clean.
  4616. /* This program uses the same features as example 2, and uses options and
  4617. arguments.
  4618. We now use the first four fields in ARGP, so here’s a description of them:
  4619. OPTIONS – A pointer to a vector of struct argp_option (see below)
  4620. PARSER – A function to parse a single option, called by argp
  4621. ARGS_DOC – A string describing how the non-option arguments should look
  4622. DOC – A descriptive string about this program; if it contains a
  4623. vertical tab character (\v), the part after it will be
  4624. printed *following* the options
  4625. The function PARSER takes the following arguments:
  4626. KEY – An integer specifying which option this is (taken
  4627. from the KEY field in each struct argp_option), or
  4628. a special key specifying something else; the only
  4629. special keys we use here are ARGP_KEY_ARG, meaning
  4630. a non-option argument, and ARGP_KEY_END, meaning
  4631. that all arguments have been parsed
  4632. ARG – For an option KEY, the string value of its
  4633. argument, or NULL if it has none
  4634. STATE– A pointer to a struct argp_state, containing
  4635. various useful information about the parsing state; used here
  4636. are the INPUT field, which reflects the INPUT argument to
  4637. argp_parse, and the ARG_NUM field, which is the number of the
  4638. current non-option argument being parsed
  4639. It should return either 0, meaning success, ARGP_ERR_UNKNOWN, meaning the
  4640. given KEY wasn’t recognized, or an errno value indicating some other
  4641. error.
  4642. Note that in this example, main uses a structure to communicate with the
  4643. parse_opt function, a pointer to which it passes in the INPUT argument to
  4644. argp_parse. Of course, it’s also possible to use global variables
  4645. instead, but this is somewhat more flexible.
  4646. The OPTIONS field contains a pointer to a vector of struct argp_option’s;
  4647. that structure has the following fields (if you assign your option
  4648. structures using array initialization like this example, unspecified
  4649. fields will be defaulted to 0, and need not be specified):
  4650. NAME – The name of this option’s long option (may be zero)
  4651. KEY – The KEY to pass to the PARSER function when parsing this option,
  4652. *and* the name of this option’s short option, if it is a
  4653. printable ascii character
  4654. ARG – The name of this option’s argument, if any
  4655. FLAGS – Flags describing this option; some of them are:
  4656. OPTION_ARG_OPTIONAL – The argument to this option is optional
  4657. OPTION_ALIAS – This option is an alias for the
  4658. previous option
  4659. OPTION_HIDDEN – Don’t show this option in –help output
  4660. DOC – A documentation string for this option, shown in –help output
  4661. An options vector should be terminated by an option with all fields zero. */
  4662. #include <stdlib.h>
  4663. #include <argp.h>
  4664. const char *argp_program_version =
  4665. "argp-ex3 1.0";
  4666. const char *argp_program_bug_address =
  4667. "<bug-gnu-utils@gnu.org>";
  4668. /* Program documentation. */
  4669. static char doc[] =
  4670. "Argp example #3 -- a program with options and arguments using argp";
  4671. /* A description of the arguments we accept. */
  4672. static char args_doc[] = "ARG1 ARG2";
  4673. /* The options we understand. */
  4674. static struct argp_option options[] = {
  4675. {"verbose", 'v', 0, 0, "Produce verbose output" },
  4676. {"quiet", 'q', 0, 0, "Don't produce any output" },
  4677. {"silent", 's', 0, OPTION_ALIAS },
  4678. {"output", 'o', "FILE", 0,
  4679. "Output to FILE instead of standard output" },
  4680. { 0 }
  4681. };
  4682. /* Used by ‘main’ to communicate with ‘parse_opt’. */
  4683. struct arguments
  4684. {
  4685. char *args[2]; /* ARG1 & ARG2 */
  4686. int silent, verbose;
  4687. char *output_file;
  4688. };
  4689. /* Parse a single option. */
  4690. static error_t
  4691. parse_opt (int key, char *arg, struct argp_state *state)
  4692. {
  4693. /* Get the INPUT argument from ‘argp_parse’, which we
  4694. know is a pointer to our arguments structure. */
  4695. struct arguments *arguments = state->input;
  4696. switch (key)
  4697. {
  4698. case 'q': case 's':
  4699. arguments->silent = 1;
  4700. break;
  4701. case 'v':
  4702. arguments->verbose = 1;
  4703. break;
  4704. case 'o':
  4705. arguments->output_file = arg;
  4706. break;
  4707. case ARGP_KEY_ARG:
  4708. if (state->arg_num >= 2)
  4709. /* Too many arguments. */
  4710. argp_usage (state);
  4711. arguments->args[state->arg_num] = arg;
  4712. break;
  4713. case ARGP_KEY_END:
  4714. if (state->arg_num < 2)
  4715. /* Not enough arguments. */
  4716. argp_usage (state);
  4717. break;
  4718. default:
  4719. return ARGP_ERR_UNKNOWN;
  4720. }
  4721. return 0;
  4722. }
  4723. /* Our argp parser. */
  4724. static struct argp argp = { options, parse_opt, args_doc, doc };
  4725. int
  4726. main (int argc, char **argv)
  4727. {
  4728. struct arguments arguments;
  4729. /* Default values. */
  4730. arguments.silent = 0;
  4731. arguments.verbose = 0;
  4732. arguments.output_file = "-";
  4733. /* Parse our arguments; every option seen by ‘parse_opt’ will
  4734. be reflected in ‘arguments’. */
  4735. argp_parse (&argp, argc, argv, 0, 0, &arguments);
  4736. printf ("ARG1 = %s\nARG2 = %s\nOUTPUT_FILE = %s\n"
  4737. "VERBOSE = %s\nSILENT = %s\n",
  4738. arguments.args[0], arguments.args[1],
  4739. arguments.output_file,
  4740. arguments.verbose ? "yes" : "no",
  4741. arguments.silent ? "yes" : "no");
  4742. exit (0);
  4743. }
  4744. 
  4745. File: libc.info, Node: Argp Example 4, Prev: Argp Example 3, Up: Argp Examples
  4746. 25.3.11.4 A Program Using Multiple Combined Argp Parsers
  4747. ........................................................
  4748. This program uses the same features as example 3, but has more options,
  4749. and presents more structure in the ‘--help’ output. It also illustrates
  4750. how you can ‘steal’ the remainder of the input arguments past a certain
  4751. point for programs that accept a list of items. It also illustrates the
  4752. KEY value ‘ARGP_KEY_NO_ARGS’, which is only given if no non-option
  4753. arguments were supplied to the program. *Note Argp Special Keys::.
  4754. For structuring help output, two features are used: _headers_ and a
  4755. two part option string. The _headers_ are entries in the options
  4756. vector. *Note Argp Option Vectors::. The first four fields are zero.
  4757. The two part documentation string are in the variable ‘doc’, which
  4758. allows documentation both before and after the options. *Note Argp
  4759. Parsers::, the two parts of ‘doc’ are separated by a vertical-tab
  4760. character (‘'\v'’, or ‘'\013'’). By convention, the documentation
  4761. before the options is a short string stating what the program does, and
  4762. after any options it is longer, describing the behavior in more detail.
  4763. All documentation strings are automatically filled for output, although
  4764. newlines may be included to force a line break at a particular point.
  4765. In addition, documentation strings are passed to the ‘gettext’ function,
  4766. for possible translation into the current locale.
  4767. /* This program uses the same features as example 3, but has more
  4768. options, and somewhat more structure in the -help output. It
  4769. also shows how you can ‘steal’ the remainder of the input
  4770. arguments past a certain point, for programs that accept a
  4771. list of items. It also shows the special argp KEY value
  4772. ARGP_KEY_NO_ARGS, which is only given if no non-option
  4773. arguments were supplied to the program.
  4774. For structuring the help output, two features are used,
  4775. *headers* which are entries in the options vector with the
  4776. first four fields being zero, and a two part documentation
  4777. string (in the variable DOC), which allows documentation both
  4778. before and after the options; the two parts of DOC are
  4779. separated by a vertical-tab character (’\v’, or ’\013’). By
  4780. convention, the documentation before the options is just a
  4781. short string saying what the program does, and that afterwards
  4782. is longer, describing the behavior in more detail. All
  4783. documentation strings are automatically filled for output,
  4784. although newlines may be included to force a line break at a
  4785. particular point. All documentation strings are also passed to
  4786. the ‘gettext’ function, for possible translation into the
  4787. current locale. */
  4788. #include <stdlib.h>
  4789. #include <error.h>
  4790. #include <argp.h>
  4791. const char *argp_program_version =
  4792. "argp-ex4 1.0";
  4793. const char *argp_program_bug_address =
  4794. "<bug-gnu-utils@prep.ai.mit.edu>";
  4795. /* Program documentation. */
  4796. static char doc[] =
  4797. "Argp example #4 -- a program with somewhat more complicated\
  4798. options\
  4799. \vThis part of the documentation comes *after* the options;\
  4800. note that the text is automatically filled, but it's possible\
  4801. to force a line-break, e.g.\n<-- here.";
  4802. /* A description of the arguments we accept. */
  4803. static char args_doc[] = "ARG1 [STRING...]";
  4804. /* Keys for options without short-options. */
  4805. #define OPT_ABORT 1 /* –abort */
  4806. /* The options we understand. */
  4807. static struct argp_option options[] = {
  4808. {"verbose", 'v', 0, 0, "Produce verbose output" },
  4809. {"quiet", 'q', 0, 0, "Don't produce any output" },
  4810. {"silent", 's', 0, OPTION_ALIAS },
  4811. {"output", 'o', "FILE", 0,
  4812. "Output to FILE instead of standard output" },
  4813. {0,0,0,0, "The following options should be grouped together:" },
  4814. {"repeat", 'r', "COUNT", OPTION_ARG_OPTIONAL,
  4815. "Repeat the output COUNT (default 10) times"},
  4816. {"abort", OPT_ABORT, 0, 0, "Abort before showing any output"},
  4817. { 0 }
  4818. };
  4819. /* Used by ‘main’ to communicate with ‘parse_opt’. */
  4820. struct arguments
  4821. {
  4822. char *arg1; /* ARG1 */
  4823. char **strings; /* [STRING…] */
  4824. int silent, verbose, abort; /* ‘-s’, ‘-v’, ‘--abort’ */
  4825. char *output_file; /* FILE arg to ‘--output’ */
  4826. int repeat_count; /* COUNT arg to ‘--repeat’ */
  4827. };
  4828. /* Parse a single option. */
  4829. static error_t
  4830. parse_opt (int key, char *arg, struct argp_state *state)
  4831. {
  4832. /* Get the ‘input’ argument from ‘argp_parse’, which we
  4833. know is a pointer to our arguments structure. */
  4834. struct arguments *arguments = state->input;
  4835. switch (key)
  4836. {
  4837. case 'q': case 's':
  4838. arguments->silent = 1;
  4839. break;
  4840. case 'v':
  4841. arguments->verbose = 1;
  4842. break;
  4843. case 'o':
  4844. arguments->output_file = arg;
  4845. break;
  4846. case 'r':
  4847. arguments->repeat_count = arg ? atoi (arg) : 10;
  4848. break;
  4849. case OPT_ABORT:
  4850. arguments->abort = 1;
  4851. break;
  4852. case ARGP_KEY_NO_ARGS:
  4853. argp_usage (state);
  4854. case ARGP_KEY_ARG:
  4855. /* Here we know that ‘state->arg_num == 0’, since we
  4856. force argument parsing to end before any more arguments can
  4857. get here. */
  4858. arguments->arg1 = arg;
  4859. /* Now we consume all the rest of the arguments.
  4860. ‘state->next’ is the index in ‘state->argv’ of the
  4861. next argument to be parsed, which is the first STRING
  4862. we’re interested in, so we can just use
  4863. ‘&state->argv[state->next]’ as the value for
  4864. arguments->strings.
  4865. _In addition_, by setting ‘state->next’ to the end
  4866. of the arguments, we can force argp to stop parsing here and
  4867. return. */
  4868. arguments->strings = &state->argv[state->next];
  4869. state->next = state->argc;
  4870. break;
  4871. default:
  4872. return ARGP_ERR_UNKNOWN;
  4873. }
  4874. return 0;
  4875. }
  4876. /* Our argp parser. */
  4877. static struct argp argp = { options, parse_opt, args_doc, doc };
  4878. int
  4879. main (int argc, char **argv)
  4880. {
  4881. int i, j;
  4882. struct arguments arguments;
  4883. /* Default values. */
  4884. arguments.silent = 0;
  4885. arguments.verbose = 0;
  4886. arguments.output_file = "-";
  4887. arguments.repeat_count = 1;
  4888. arguments.abort = 0;
  4889. /* Parse our arguments; every option seen by ‘parse_opt’ will be
  4890. reflected in ‘arguments’. */
  4891. argp_parse (&argp, argc, argv, 0, 0, &arguments);
  4892. if (arguments.abort)
  4893. error (10, 0, "ABORTED");
  4894. for (i = 0; i < arguments.repeat_count; i++)
  4895. {
  4896. printf ("ARG1 = %s\n", arguments.arg1);
  4897. printf ("STRINGS = ");
  4898. for (j = 0; arguments.strings[j]; j++)
  4899. printf (j == 0 ? "%s" : ", %s", arguments.strings[j]);
  4900. printf ("\n");
  4901. printf ("OUTPUT_FILE = %s\nVERBOSE = %s\nSILENT = %s\n",
  4902. arguments.output_file,
  4903. arguments.verbose ? "yes" : "no",
  4904. arguments.silent ? "yes" : "no");
  4905. }
  4906. exit (0);
  4907. }
  4908. 
  4909. File: libc.info, Node: Argp User Customization, Prev: Argp Examples, Up: Argp
  4910. 25.3.12 Argp User Customization
  4911. -------------------------------
  4912. The formatting of argp ‘--help’ output may be controlled to some extent
  4913. by a program’s users, by setting the ‘ARGP_HELP_FMT’ environment
  4914. variable to a comma-separated list of tokens. Whitespace is ignored:
  4915. ‘dup-args’
  4916. ‘no-dup-args’
  4917. These turn "duplicate-argument-mode" on or off. In duplicate
  4918. argument mode, if an option that accepts an argument has multiple
  4919. names, the argument is shown for each name. Otherwise, it is only
  4920. shown for the first long option. A note is subsequently printed so
  4921. the user knows that it applies to other names as well. The default
  4922. is ‘no-dup-args’, which is less consistent, but prettier.
  4923. ‘dup-args-note’
  4924. ‘no-dup-args-note’
  4925. These will enable or disable the note informing the user of
  4926. suppressed option argument duplication. The default is
  4927. ‘dup-args-note’.
  4928. ‘short-opt-col=N’
  4929. This prints the first short option in column N. The default is 2.
  4930. ‘long-opt-col=N’
  4931. This prints the first long option in column N. The default is 6.
  4932. ‘doc-opt-col=N’
  4933. This prints ‘documentation options’ (*note Argp Option Flags::) in
  4934. column N. The default is 2.
  4935. ‘opt-doc-col=N’
  4936. This prints the documentation for options starting in column N.
  4937. The default is 29.
  4938. ‘header-col=N’
  4939. This will indent the group headers that document groups of options
  4940. to column N. The default is 1.
  4941. ‘usage-indent=N’
  4942. This will indent continuation lines in ‘Usage:’ messages to column
  4943. N. The default is 12.
  4944. ‘rmargin=N’
  4945. This will word wrap help output at or before column N. The default
  4946. is 79.
  4947. 
  4948. File: libc.info, Node: Suboptions, Next: Suboptions Example, Prev: Argp, Up: Parsing Program Arguments
  4949. 25.3.12.1 Parsing of Suboptions
  4950. ...............................
  4951. Having a single level of options is sometimes not enough. There might
  4952. be too many options which have to be available or a set of options is
  4953. closely related.
  4954. For this case some programs use suboptions. One of the most
  4955. prominent programs is certainly ‘mount’(8). The ‘-o’ option take one
  4956. argument which itself is a comma separated list of options. To ease the
  4957. programming of code like this the function ‘getsubopt’ is available.
  4958. -- Function: int getsubopt (char **OPTIONP, char *const *TOKENS, char
  4959. **VALUEP)
  4960. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  4961. Concepts::.
  4962. The OPTIONP parameter must be a pointer to a variable containing
  4963. the address of the string to process. When the function returns,
  4964. the reference is updated to point to the next suboption or to the
  4965. terminating ‘\0’ character if there are no more suboptions
  4966. available.
  4967. The TOKENS parameter references an array of strings containing the
  4968. known suboptions. All strings must be ‘\0’ terminated and to mark
  4969. the end a null pointer must be stored. When ‘getsubopt’ finds a
  4970. possible legal suboption it compares it with all strings available
  4971. in the TOKENS array and returns the index in the string as the
  4972. indicator.
  4973. In case the suboption has an associated value introduced by a ‘=’
  4974. character, a pointer to the value is returned in VALUEP. The
  4975. string is ‘\0’ terminated. If no argument is available VALUEP is
  4976. set to the null pointer. By doing this the caller can check
  4977. whether a necessary value is given or whether no unexpected value
  4978. is present.
  4979. In case the next suboption in the string is not mentioned in the
  4980. TOKENS array the starting address of the suboption including a
  4981. possible value is returned in VALUEP and the return value of the
  4982. function is ‘-1’.
  4983. 
  4984. File: libc.info, Node: Suboptions Example, Prev: Suboptions, Up: Parsing Program Arguments
  4985. 25.3.13 Parsing of Suboptions Example
  4986. -------------------------------------
  4987. The code which might appear in the ‘mount’(8) program is a perfect
  4988. example of the use of ‘getsubopt’:
  4989. #include <stdio.h>
  4990. #include <stdlib.h>
  4991. #include <unistd.h>
  4992. int do_all;
  4993. const char *type;
  4994. int read_size;
  4995. int write_size;
  4996. int read_only;
  4997. enum
  4998. {
  4999. RO_OPTION = 0,
  5000. RW_OPTION,
  5001. READ_SIZE_OPTION,
  5002. WRITE_SIZE_OPTION,
  5003. THE_END
  5004. };
  5005. const char *mount_opts[] =
  5006. {
  5007. [RO_OPTION] = "ro",
  5008. [RW_OPTION] = "rw",
  5009. [READ_SIZE_OPTION] = "rsize",
  5010. [WRITE_SIZE_OPTION] = "wsize",
  5011. [THE_END] = NULL
  5012. };
  5013. int
  5014. main (int argc, char **argv)
  5015. {
  5016. char *subopts, *value;
  5017. int opt;
  5018. while ((opt = getopt (argc, argv, "at:o:")) != -1)
  5019. switch (opt)
  5020. {
  5021. case 'a':
  5022. do_all = 1;
  5023. break;
  5024. case 't':
  5025. type = optarg;
  5026. break;
  5027. case 'o':
  5028. subopts = optarg;
  5029. while (*subopts != '\0')
  5030. switch (getsubopt (&subopts, mount_opts, &value))
  5031. {
  5032. case RO_OPTION:
  5033. read_only = 1;
  5034. break;
  5035. case RW_OPTION:
  5036. read_only = 0;
  5037. break;
  5038. case READ_SIZE_OPTION:
  5039. if (value == NULL)
  5040. abort ();
  5041. read_size = atoi (value);
  5042. break;
  5043. case WRITE_SIZE_OPTION:
  5044. if (value == NULL)
  5045. abort ();
  5046. write_size = atoi (value);
  5047. break;
  5048. default:
  5049. /* Unknown suboption. */
  5050. printf ("Unknown suboption `%s'\n", value);
  5051. break;
  5052. }
  5053. break;
  5054. default:
  5055. abort ();
  5056. }
  5057. /* Do the real work. */
  5058. return 0;
  5059. }
  5060. 
  5061. File: libc.info, Node: Environment Variables, Next: Auxiliary Vector, Prev: Program Arguments, Up: Program Basics
  5062. 25.4 Environment Variables
  5063. ==========================
  5064. When a program is executed, it receives information about the context in
  5065. which it was invoked in two ways. The first mechanism uses the ARGV and
  5066. ARGC arguments to its ‘main’ function, and is discussed in *note Program
  5067. Arguments::. The second mechanism uses "environment variables" and is
  5068. discussed in this section.
  5069. The ARGV mechanism is typically used to pass command-line arguments
  5070. specific to the particular program being invoked. The environment, on
  5071. the other hand, keeps track of information that is shared by many
  5072. programs, changes infrequently, and that is less frequently used.
  5073. The environment variables discussed in this section are the same
  5074. environment variables that you set using assignments and the ‘export’
  5075. command in the shell. Programs executed from the shell inherit all of
  5076. the environment variables from the shell.
  5077. Standard environment variables are used for information about the
  5078. user’s home directory, terminal type, current locale, and so on; you can
  5079. define additional variables for other purposes. The set of all
  5080. environment variables that have values is collectively known as the
  5081. "environment".
  5082. Names of environment variables are case-sensitive and must not
  5083. contain the character ‘=’. System-defined environment variables are
  5084. invariably uppercase.
  5085. The values of environment variables can be anything that can be
  5086. represented as a string. A value must not contain an embedded null
  5087. character, since this is assumed to terminate the string.
  5088. * Menu:
  5089. * Environment Access:: How to get and set the values of
  5090. environment variables.
  5091. * Standard Environment:: These environment variables have
  5092. standard interpretations.
  5093. 
  5094. File: libc.info, Node: Environment Access, Next: Standard Environment, Up: Environment Variables
  5095. 25.4.1 Environment Access
  5096. -------------------------
  5097. The value of an environment variable can be accessed with the ‘getenv’
  5098. function. This is declared in the header file ‘stdlib.h’.
  5099. Libraries should use ‘secure_getenv’ instead of ‘getenv’, so that
  5100. they do not accidentally use untrusted environment variables.
  5101. Modifications of environment variables are not allowed in multi-threaded
  5102. programs. The ‘getenv’ and ‘secure_getenv’ functions can be safely used
  5103. in multi-threaded programs.
  5104. -- Function: char * getenv (const char *NAME)
  5105. Preliminary: | MT-Safe env | AS-Safe | AC-Safe | *Note POSIX Safety
  5106. Concepts::.
  5107. This function returns a string that is the value of the environment
  5108. variable NAME. You must not modify this string. In some non-Unix
  5109. systems not using the GNU C Library, it might be overwritten by
  5110. subsequent calls to ‘getenv’ (but not by any other library
  5111. function). If the environment variable NAME is not defined, the
  5112. value is a null pointer.
  5113. -- Function: char * secure_getenv (const char *NAME)
  5114. Preliminary: | MT-Safe env | AS-Safe | AC-Safe | *Note POSIX Safety
  5115. Concepts::.
  5116. This function is similar to ‘getenv’, but it returns a null pointer
  5117. if the environment is untrusted. This happens when the program
  5118. file has SUID or SGID bits set. General-purpose libraries should
  5119. always prefer this function over ‘getenv’ to avoid vulnerabilities
  5120. if the library is referenced from a SUID/SGID program.
  5121. This function is a GNU extension.
  5122. -- Function: int putenv (char *STRING)
  5123. Preliminary: | MT-Unsafe const:env | AS-Unsafe heap lock |
  5124. AC-Unsafe corrupt lock mem | *Note POSIX Safety Concepts::.
  5125. The ‘putenv’ function adds or removes definitions from the
  5126. environment. If the STRING is of the form ‘NAME=VALUE’, the
  5127. definition is added to the environment. Otherwise, the STRING is
  5128. interpreted as the name of an environment variable, and any
  5129. definition for this variable in the environment is removed.
  5130. If the function is successful it returns ‘0’. Otherwise the return
  5131. value is nonzero and ‘errno’ is set to indicate the error.
  5132. The difference to the ‘setenv’ function is that the exact string
  5133. given as the parameter STRING is put into the environment. If the
  5134. user should change the string after the ‘putenv’ call this will
  5135. reflect automatically in the environment. This also requires that
  5136. STRING not be an automatic variable whose scope is left before the
  5137. variable is removed from the environment. The same applies of
  5138. course to dynamically allocated variables which are freed later.
  5139. This function is part of the extended Unix interface. You should
  5140. define _XOPEN_SOURCE before including any header.
  5141. -- Function: int setenv (const char *NAME, const char *VALUE, int
  5142. REPLACE)
  5143. Preliminary: | MT-Unsafe const:env | AS-Unsafe heap lock |
  5144. AC-Unsafe corrupt lock mem | *Note POSIX Safety Concepts::.
  5145. The ‘setenv’ function can be used to add a new definition to the
  5146. environment. The entry with the name NAME is replaced by the value
  5147. ‘NAME=VALUE’. Please note that this is also true if VALUE is the
  5148. empty string. To do this a new string is created and the strings
  5149. NAME and VALUE are copied. A null pointer for the VALUE parameter
  5150. is illegal. If the environment already contains an entry with key
  5151. NAME the REPLACE parameter controls the action. If replace is
  5152. zero, nothing happens. Otherwise the old entry is replaced by the
  5153. new one.
  5154. Please note that you cannot remove an entry completely using this
  5155. function.
  5156. If the function is successful it returns ‘0’. Otherwise the
  5157. environment is unchanged and the return value is ‘-1’ and ‘errno’
  5158. is set.
  5159. This function was originally part of the BSD library but is now
  5160. part of the Unix standard.
  5161. -- Function: int unsetenv (const char *NAME)
  5162. Preliminary: | MT-Unsafe const:env | AS-Unsafe lock | AC-Unsafe
  5163. lock | *Note POSIX Safety Concepts::.
  5164. Using this function one can remove an entry completely from the
  5165. environment. If the environment contains an entry with the key
  5166. NAME this whole entry is removed. A call to this function is
  5167. equivalent to a call to ‘putenv’ when the VALUE part of the string
  5168. is empty.
  5169. The function returns ‘-1’ if NAME is a null pointer, points to an
  5170. empty string, or points to a string containing a ‘=’ character. It
  5171. returns ‘0’ if the call succeeded.
  5172. This function was originally part of the BSD library but is now
  5173. part of the Unix standard. The BSD version had no return value,
  5174. though.
  5175. There is one more function to modify the whole environment. This
  5176. function is said to be used in the POSIX.9 (POSIX bindings for Fortran
  5177. 77) and so one should expect it did made it into POSIX.1. But this
  5178. never happened. But we still provide this function as a GNU extension
  5179. to enable writing standard compliant Fortran environments.
  5180. -- Function: int clearenv (void)
  5181. Preliminary: | MT-Unsafe const:env | AS-Unsafe heap lock |
  5182. AC-Unsafe lock mem | *Note POSIX Safety Concepts::.
  5183. The ‘clearenv’ function removes all entries from the environment.
  5184. Using ‘putenv’ and ‘setenv’ new entries can be added again later.
  5185. If the function is successful it returns ‘0’. Otherwise the return
  5186. value is nonzero.
  5187. You can deal directly with the underlying representation of
  5188. environment objects to add more variables to the environment (for
  5189. example, to communicate with another program you are about to execute;
  5190. *note Executing a File::).
  5191. -- Variable: char ** environ
  5192. The environment is represented as an array of strings. Each string
  5193. is of the format ‘NAME=VALUE’. The order in which strings appear
  5194. in the environment is not significant, but the same NAME must not
  5195. appear more than once. The last element of the array is a null
  5196. pointer.
  5197. This variable is declared in the header file ‘unistd.h’.
  5198. If you just want to get the value of an environment variable, use
  5199. ‘getenv’.
  5200. Unix systems, and GNU systems, pass the initial value of ‘environ’ as
  5201. the third argument to ‘main’. *Note Program Arguments::.
  5202. 
  5203. File: libc.info, Node: Standard Environment, Prev: Environment Access, Up: Environment Variables
  5204. 25.4.2 Standard Environment Variables
  5205. -------------------------------------
  5206. These environment variables have standard meanings. This doesn’t mean
  5207. that they are always present in the environment; but if these variables
  5208. _are_ present, they have these meanings. You shouldn’t try to use these
  5209. environment variable names for some other purpose.
  5210. ‘HOME’
  5211. This is a string representing the user’s "home directory", or
  5212. initial default working directory.
  5213. The user can set ‘HOME’ to any value. If you need to make sure to
  5214. obtain the proper home directory for a particular user, you should
  5215. not use ‘HOME’; instead, look up the user’s name in the user
  5216. database (*note User Database::).
  5217. For most purposes, it is better to use ‘HOME’, precisely because
  5218. this lets the user specify the value.
  5219. ‘LOGNAME’
  5220. This is the name that the user used to log in. Since the value in
  5221. the environment can be tweaked arbitrarily, this is not a reliable
  5222. way to identify the user who is running a program; a function like
  5223. ‘getlogin’ (*note Who Logged In::) is better for that purpose.
  5224. For most purposes, it is better to use ‘LOGNAME’, precisely because
  5225. this lets the user specify the value.
  5226. ‘PATH’
  5227. A "path" is a sequence of directory names which is used for
  5228. searching for a file. The variable ‘PATH’ holds a path used for
  5229. searching for programs to be run.
  5230. The ‘execlp’ and ‘execvp’ functions (*note Executing a File::) use
  5231. this environment variable, as do many shells and other utilities
  5232. which are implemented in terms of those functions.
  5233. The syntax of a path is a sequence of directory names separated by
  5234. colons. An empty string instead of a directory name stands for the
  5235. current directory (*note Working Directory::).
  5236. A typical value for this environment variable might be a string
  5237. like:
  5238. :/bin:/etc:/usr/bin:/usr/new/X11:/usr/new:/usr/local/bin
  5239. This means that if the user tries to execute a program named ‘foo’,
  5240. the system will look for files named ‘foo’, ‘/bin/foo’, ‘/etc/foo’,
  5241. and so on. The first of these files that exists is the one that is
  5242. executed.
  5243. ‘TERM’
  5244. This specifies the kind of terminal that is receiving program
  5245. output. Some programs can make use of this information to take
  5246. advantage of special escape sequences or terminal modes supported
  5247. by particular kinds of terminals. Many programs which use the
  5248. termcap library (*note Find: (termcap)Finding a Terminal
  5249. Description.) use the ‘TERM’ environment variable, for example.
  5250. ‘TZ’
  5251. This specifies the time zone. *Note TZ Variable::, for information
  5252. about the format of this string and how it is used.
  5253. ‘LANG’
  5254. This specifies the default locale to use for attribute categories
  5255. where neither ‘LC_ALL’ nor the specific environment variable for
  5256. that category is set. *Note Locales::, for more information about
  5257. locales.
  5258. ‘LC_ALL’
  5259. If this environment variable is set it overrides the selection for
  5260. all the locales done using the other ‘LC_*’ environment variables.
  5261. The value of the other ‘LC_*’ environment variables is simply
  5262. ignored in this case.
  5263. ‘LC_COLLATE’
  5264. This specifies what locale to use for string sorting.
  5265. ‘LC_CTYPE’
  5266. This specifies what locale to use for character sets and character
  5267. classification.
  5268. ‘LC_MESSAGES’
  5269. This specifies what locale to use for printing messages and to
  5270. parse responses.
  5271. ‘LC_MONETARY’
  5272. This specifies what locale to use for formatting monetary values.
  5273. ‘LC_NUMERIC’
  5274. This specifies what locale to use for formatting numbers.
  5275. ‘LC_TIME’
  5276. This specifies what locale to use for formatting date/time values.
  5277. ‘NLSPATH’
  5278. This specifies the directories in which the ‘catopen’ function
  5279. looks for message translation catalogs.
  5280. ‘_POSIX_OPTION_ORDER’
  5281. If this environment variable is defined, it suppresses the usual
  5282. reordering of command line arguments by ‘getopt’ and ‘argp_parse’.
  5283. *Note Argument Syntax::.
  5284. 
  5285. File: libc.info, Node: Auxiliary Vector, Next: System Calls, Prev: Environment Variables, Up: Program Basics
  5286. 25.5 Auxiliary Vector
  5287. =====================
  5288. When a program is executed, it receives information from the operating
  5289. system about the environment in which it is operating. The form of this
  5290. information is a table of key-value pairs, where the keys are from the
  5291. set of ‘AT_’ values in ‘elf.h’. Some of the data is provided by the
  5292. kernel for libc consumption, and may be obtained by ordinary interfaces,
  5293. such as ‘sysconf’. However, on a platform-by-platform basis there may
  5294. be information that is not available any other way.
  5295. 25.5.1 Definition of ‘getauxval’
  5296. --------------------------------
  5297. -- Function: unsigned long int getauxval (unsigned long int TYPE)
  5298. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5299. Concepts::.
  5300. This function is used to inquire about the entries in the auxiliary
  5301. vector. The TYPE argument should be one of the ‘AT_’ symbols
  5302. defined in ‘elf.h’. If a matching entry is found, the value is
  5303. returned; if the entry is not found, zero is returned and ‘errno’
  5304. is set to ‘ENOENT’.
  5305. For some platforms, the key ‘AT_HWCAP’ is the easiest way to inquire
  5306. about any instruction set extensions available at runtime. In this
  5307. case, there will (of necessity) be a platform-specific set of ‘HWCAP_’
  5308. values masked together that describe the capabilities of the cpu on
  5309. which the program is being executed.
  5310. 
  5311. File: libc.info, Node: System Calls, Next: Program Termination, Prev: Auxiliary Vector, Up: Program Basics
  5312. 25.6 System Calls
  5313. =================
  5314. A system call is a request for service that a program makes of the
  5315. kernel. The service is generally something that only the kernel has the
  5316. privilege to do, such as doing I/O. Programmers don’t normally need to
  5317. be concerned with system calls because there are functions in the GNU C
  5318. Library to do virtually everything that system calls do. These
  5319. functions work by making system calls themselves. For example, there is
  5320. a system call that changes the permissions of a file, but you don’t need
  5321. to know about it because you can just use the GNU C Library’s ‘chmod’
  5322. function.
  5323. System calls are sometimes called kernel calls.
  5324. However, there are times when you want to make a system call
  5325. explicitly, and for that, the GNU C Library provides the ‘syscall’
  5326. function. ‘syscall’ is harder to use and less portable than functions
  5327. like ‘chmod’, but easier and more portable than coding the system call
  5328. in assembler instructions.
  5329. ‘syscall’ is most useful when you are working with a system call
  5330. which is special to your system or is newer than the GNU C Library you
  5331. are using. ‘syscall’ is implemented in an entirely generic way; the
  5332. function does not know anything about what a particular system call does
  5333. or even if it is valid.
  5334. The description of ‘syscall’ in this section assumes a certain
  5335. protocol for system calls on the various platforms on which the GNU C
  5336. Library runs. That protocol is not defined by any strong authority, but
  5337. we won’t describe it here either because anyone who is coding ‘syscall’
  5338. probably won’t accept anything less than kernel and C library source
  5339. code as a specification of the interface between them anyway.
  5340. ‘syscall’ is declared in ‘unistd.h’.
  5341. -- Function: long int syscall (long int SYSNO, …)
  5342. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5343. Concepts::.
  5344. ‘syscall’ performs a generic system call.
  5345. SYSNO is the system call number. Each kind of system call is
  5346. identified by a number. Macros for all the possible system call
  5347. numbers are defined in ‘sys/syscall.h’
  5348. The remaining arguments are the arguments for the system call, in
  5349. order, and their meanings depend on the kind of system call. Each
  5350. kind of system call has a definite number of arguments, from zero
  5351. to five. If you code more arguments than the system call takes,
  5352. the extra ones to the right are ignored.
  5353. The return value is the return value from the system call, unless
  5354. the system call failed. In that case, ‘syscall’ returns ‘-1’ and
  5355. sets ‘errno’ to an error code that the system call returned. Note
  5356. that system calls do not return ‘-1’ when they succeed.
  5357. If you specify an invalid SYSNO, ‘syscall’ returns ‘-1’ with
  5358. ‘errno’ = ‘ENOSYS’.
  5359. Example:
  5360. #include <unistd.h>
  5361. #include <sys/syscall.h>
  5362. #include <errno.h>
  5363. int rc;
  5364. rc = syscall(SYS_chmod, "/etc/passwd", 0444);
  5365. if (rc == -1)
  5366. fprintf(stderr, "chmod failed, errno = %d\n", errno);
  5367. This, if all the compatibility stars are aligned, is equivalent to
  5368. the following preferable code:
  5369. #include <sys/types.h>
  5370. #include <sys/stat.h>
  5371. #include <errno.h>
  5372. int rc;
  5373. rc = chmod("/etc/passwd", 0444);
  5374. if (rc == -1)
  5375. fprintf(stderr, "chmod failed, errno = %d\n", errno);
  5376. 
  5377. File: libc.info, Node: Program Termination, Prev: System Calls, Up: Program Basics
  5378. 25.7 Program Termination
  5379. ========================
  5380. The usual way for a program to terminate is simply for its ‘main’
  5381. function to return. The "exit status value" returned from the ‘main’
  5382. function is used to report information back to the process’s parent
  5383. process or shell.
  5384. A program can also terminate normally by calling the ‘exit’ function.
  5385. In addition, programs can be terminated by signals; this is discussed
  5386. in more detail in *note Signal Handling::. The ‘abort’ function causes
  5387. a signal that kills the program.
  5388. * Menu:
  5389. * Normal Termination:: If a program calls ‘exit’, a
  5390. process terminates normally.
  5391. * Exit Status:: The ‘exit status’ provides information
  5392. about why the process terminated.
  5393. * Cleanups on Exit:: A process can run its own cleanup
  5394. functions upon normal termination.
  5395. * Aborting a Program:: The ‘abort’ function causes
  5396. abnormal program termination.
  5397. * Termination Internals:: What happens when a process terminates.
  5398. 
  5399. File: libc.info, Node: Normal Termination, Next: Exit Status, Up: Program Termination
  5400. 25.7.1 Normal Termination
  5401. -------------------------
  5402. A process terminates normally when its program signals it is done by
  5403. calling ‘exit’. Returning from ‘main’ is equivalent to calling ‘exit’,
  5404. and the value that ‘main’ returns is used as the argument to ‘exit’.
  5405. -- Function: void exit (int STATUS)
  5406. Preliminary: | MT-Unsafe race:exit | AS-Unsafe corrupt | AC-Unsafe
  5407. corrupt lock | *Note POSIX Safety Concepts::.
  5408. The ‘exit’ function tells the system that the program is done,
  5409. which causes it to terminate the process.
  5410. STATUS is the program’s exit status, which becomes part of the
  5411. process’ termination status. This function does not return.
  5412. Normal termination causes the following actions:
  5413. 1. Functions that were registered with the ‘atexit’ or ‘on_exit’
  5414. functions are called in the reverse order of their registration.
  5415. This mechanism allows your application to specify its own “cleanup”
  5416. actions to be performed at program termination. Typically, this is
  5417. used to do things like saving program state information in a file,
  5418. or unlocking locks in shared data bases.
  5419. 2. All open streams are closed, writing out any buffered output data.
  5420. See *note Closing Streams::. In addition, temporary files opened
  5421. with the ‘tmpfile’ function are removed; see *note Temporary
  5422. Files::.
  5423. 3. ‘_exit’ is called, terminating the program. *Note Termination
  5424. Internals::.
  5425. 
  5426. File: libc.info, Node: Exit Status, Next: Cleanups on Exit, Prev: Normal Termination, Up: Program Termination
  5427. 25.7.2 Exit Status
  5428. ------------------
  5429. When a program exits, it can return to the parent process a small amount
  5430. of information about the cause of termination, using the "exit status".
  5431. This is a value between 0 and 255 that the exiting process passes as an
  5432. argument to ‘exit’.
  5433. Normally you should use the exit status to report very broad
  5434. information about success or failure. You can’t provide a lot of detail
  5435. about the reasons for the failure, and most parent processes would not
  5436. want much detail anyway.
  5437. There are conventions for what sorts of status values certain
  5438. programs should return. The most common convention is simply 0 for
  5439. success and 1 for failure. Programs that perform comparison use a
  5440. different convention: they use status 1 to indicate a mismatch, and
  5441. status 2 to indicate an inability to compare. Your program should
  5442. follow an existing convention if an existing convention makes sense for
  5443. it.
  5444. A general convention reserves status values 128 and up for special
  5445. purposes. In particular, the value 128 is used to indicate failure to
  5446. execute another program in a subprocess. This convention is not
  5447. universally obeyed, but it is a good idea to follow it in your programs.
  5448. *Warning:* Don’t try to use the number of errors as the exit status.
  5449. This is actually not very useful; a parent process would generally not
  5450. care how many errors occurred. Worse than that, it does not work,
  5451. because the status value is truncated to eight bits. Thus, if the
  5452. program tried to report 256 errors, the parent would receive a report of
  5453. 0 errors—that is, success.
  5454. For the same reason, it does not work to use the value of ‘errno’ as
  5455. the exit status—these can exceed 255.
  5456. *Portability note:* Some non-POSIX systems use different conventions
  5457. for exit status values. For greater portability, you can use the macros
  5458. ‘EXIT_SUCCESS’ and ‘EXIT_FAILURE’ for the conventional status value for
  5459. success and failure, respectively. They are declared in the file
  5460. ‘stdlib.h’.
  5461. -- Macro: int EXIT_SUCCESS
  5462. This macro can be used with the ‘exit’ function to indicate
  5463. successful program completion.
  5464. On POSIX systems, the value of this macro is ‘0’. On other
  5465. systems, the value might be some other (possibly non-constant)
  5466. integer expression.
  5467. -- Macro: int EXIT_FAILURE
  5468. This macro can be used with the ‘exit’ function to indicate
  5469. unsuccessful program completion in a general sense.
  5470. On POSIX systems, the value of this macro is ‘1’. On other
  5471. systems, the value might be some other (possibly non-constant)
  5472. integer expression. Other nonzero status values also indicate
  5473. failures. Certain programs use different nonzero status values to
  5474. indicate particular kinds of "non-success". For example, ‘diff’
  5475. uses status value ‘1’ to mean that the files are different, and ‘2’
  5476. or more to mean that there was difficulty in opening the files.
  5477. Don’t confuse a program’s exit status with a process’ termination
  5478. status. There are lots of ways a process can terminate besides having
  5479. its program finish. In the event that the process termination _is_
  5480. caused by program termination (i.e., ‘exit’), though, the program’s exit
  5481. status becomes part of the process’ termination status.
  5482. 
  5483. File: libc.info, Node: Cleanups on Exit, Next: Aborting a Program, Prev: Exit Status, Up: Program Termination
  5484. 25.7.3 Cleanups on Exit
  5485. -----------------------
  5486. Your program can arrange to run its own cleanup functions if normal
  5487. termination happens. If you are writing a library for use in various
  5488. application programs, then it is unreliable to insist that all
  5489. applications call the library’s cleanup functions explicitly before
  5490. exiting. It is much more robust to make the cleanup invisible to the
  5491. application, by setting up a cleanup function in the library itself
  5492. using ‘atexit’ or ‘on_exit’.
  5493. -- Function: int atexit (void (*FUNCTION) (void))
  5494. Preliminary: | MT-Safe | AS-Unsafe heap lock | AC-Unsafe lock mem |
  5495. *Note POSIX Safety Concepts::.
  5496. The ‘atexit’ function registers the function FUNCTION to be called
  5497. at normal program termination. The FUNCTION is called with no
  5498. arguments.
  5499. The return value from ‘atexit’ is zero on success and nonzero if
  5500. the function cannot be registered.
  5501. -- Function: int on_exit (void (*FUNCTION)(int STATUS, void *ARG), void
  5502. *ARG)
  5503. Preliminary: | MT-Safe | AS-Unsafe heap lock | AC-Unsafe lock mem |
  5504. *Note POSIX Safety Concepts::.
  5505. This function is a somewhat more powerful variant of ‘atexit’. It
  5506. accepts two arguments, a function FUNCTION and an arbitrary pointer
  5507. ARG. At normal program termination, the FUNCTION is called with
  5508. two arguments: the STATUS value passed to ‘exit’, and the ARG.
  5509. This function is included in the GNU C Library only for
  5510. compatibility for SunOS, and may not be supported by other
  5511. implementations.
  5512. Here’s a trivial program that illustrates the use of ‘exit’ and
  5513. ‘atexit’:
  5514. #include <stdio.h>
  5515. #include <stdlib.h>
  5516. void
  5517. bye (void)
  5518. {
  5519. puts ("Goodbye, cruel world....");
  5520. }
  5521. int
  5522. main (void)
  5523. {
  5524. atexit (bye);
  5525. exit (EXIT_SUCCESS);
  5526. }
  5527. When this program is executed, it just prints the message and exits.
  5528. 
  5529. File: libc.info, Node: Aborting a Program, Next: Termination Internals, Prev: Cleanups on Exit, Up: Program Termination
  5530. 25.7.4 Aborting a Program
  5531. -------------------------
  5532. You can abort your program using the ‘abort’ function. The prototype
  5533. for this function is in ‘stdlib.h’.
  5534. -- Function: void abort (void)
  5535. Preliminary: | MT-Safe | AS-Unsafe corrupt | AC-Unsafe lock corrupt
  5536. | *Note POSIX Safety Concepts::.
  5537. The ‘abort’ function causes abnormal program termination. This
  5538. does not execute cleanup functions registered with ‘atexit’ or
  5539. ‘on_exit’.
  5540. This function actually terminates the process by raising a
  5541. ‘SIGABRT’ signal, and your program can include a handler to
  5542. intercept this signal; see *note Signal Handling::.
  5543. *Future Change Warning:* Proposed Federal censorship regulations may
  5544. prohibit us from giving you information about the possibility of calling
  5545. this function. We would be required to say that this is not an
  5546. acceptable way of terminating a program.
  5547. 
  5548. File: libc.info, Node: Termination Internals, Prev: Aborting a Program, Up: Program Termination
  5549. 25.7.5 Termination Internals
  5550. ----------------------------
  5551. The ‘_exit’ function is the primitive used for process termination by
  5552. ‘exit’. It is declared in the header file ‘unistd.h’.
  5553. -- Function: void _exit (int STATUS)
  5554. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5555. Concepts::.
  5556. The ‘_exit’ function is the primitive for causing a process to
  5557. terminate with status STATUS. Calling this function does not
  5558. execute cleanup functions registered with ‘atexit’ or ‘on_exit’.
  5559. -- Function: void _Exit (int STATUS)
  5560. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5561. Concepts::.
  5562. The ‘_Exit’ function is the ISO C equivalent to ‘_exit’. The ISO C
  5563. committee members were not sure whether the definitions of ‘_exit’
  5564. and ‘_Exit’ were compatible so they have not used the POSIX name.
  5565. This function was introduced in ISO C99 and is declared in
  5566. ‘stdlib.h’.
  5567. When a process terminates for any reason—either because the program
  5568. terminates, or as a result of a signal—the following things happen:
  5569. • All open file descriptors in the process are closed. *Note
  5570. Low-Level I/O::. Note that streams are not flushed automatically
  5571. when the process terminates; see *note I/O on Streams::.
  5572. • A process exit status is saved to be reported back to the parent
  5573. process via ‘wait’ or ‘waitpid’; see *note Process Completion::.
  5574. If the program exited, this status includes as its low-order 8 bits
  5575. the program exit status.
  5576. • Any child processes of the process being terminated are assigned a
  5577. new parent process. (On most systems, including GNU, this is the
  5578. ‘init’ process, with process ID 1.)
  5579. • A ‘SIGCHLD’ signal is sent to the parent process.
  5580. • If the process is a session leader that has a controlling terminal,
  5581. then a ‘SIGHUP’ signal is sent to each process in the foreground
  5582. job, and the controlling terminal is disassociated from that
  5583. session. *Note Job Control::.
  5584. • If termination of a process causes a process group to become
  5585. orphaned, and any member of that process group is stopped, then a
  5586. ‘SIGHUP’ signal and a ‘SIGCONT’ signal are sent to each process in
  5587. the group. *Note Job Control::.
  5588. 
  5589. File: libc.info, Node: Processes, Next: Inter-Process Communication, Prev: Program Basics, Up: Top
  5590. 26 Processes
  5591. ************
  5592. "Processes" are the primitive units for allocation of system resources.
  5593. Each process has its own address space and (usually) one thread of
  5594. control. A process executes a program; you can have multiple processes
  5595. executing the same program, but each process has its own copy of the
  5596. program within its own address space and executes it independently of
  5597. the other copies.
  5598. Processes are organized hierarchically. Each process has a "parent
  5599. process" which explicitly arranged to create it. The processes created
  5600. by a given parent are called its "child processes". A child inherits
  5601. many of its attributes from the parent process.
  5602. This chapter describes how a program can create, terminate, and
  5603. control child processes. Actually, there are three distinct operations
  5604. involved: creating a new child process, causing the new process to
  5605. execute a program, and coordinating the completion of the child process
  5606. with the original program.
  5607. The ‘system’ function provides a simple, portable mechanism for
  5608. running another program; it does all three steps automatically. If you
  5609. need more control over the details of how this is done, you can use the
  5610. primitive functions to do each step individually instead.
  5611. * Menu:
  5612. * Running a Command:: The easy way to run another program.
  5613. * Process Creation Concepts:: An overview of the hard way to do it.
  5614. * Process Identification:: How to get the process ID of a process.
  5615. * Creating a Process:: How to fork a child process.
  5616. * Executing a File:: How to make a process execute another program.
  5617. * Process Completion:: How to tell when a child process has completed.
  5618. * Process Completion Status:: How to interpret the status value
  5619. returned from a child process.
  5620. * BSD Wait Functions:: More functions, for backward compatibility.
  5621. * Process Creation Example:: A complete example program.
  5622. 
  5623. File: libc.info, Node: Running a Command, Next: Process Creation Concepts, Up: Processes
  5624. 26.1 Running a Command
  5625. ======================
  5626. The easy way to run another program is to use the ‘system’ function.
  5627. This function does all the work of running a subprogram, but it doesn’t
  5628. give you much control over the details: you have to wait until the
  5629. subprogram terminates before you can do anything else.
  5630. -- Function: int system (const char *COMMAND)
  5631. Preliminary: | MT-Safe | AS-Unsafe plugin heap lock | AC-Unsafe
  5632. lock mem | *Note POSIX Safety Concepts::.
  5633. This function executes COMMAND as a shell command. In the GNU C
  5634. Library, it always uses the default shell ‘sh’ to run the command.
  5635. In particular, it searches the directories in ‘PATH’ to find
  5636. programs to execute. The return value is ‘-1’ if it wasn’t
  5637. possible to create the shell process, and otherwise is the status
  5638. of the shell process. *Note Process Completion::, for details on
  5639. how this status code can be interpreted.
  5640. If the COMMAND argument is a null pointer, a return value of zero
  5641. indicates that no command processor is available.
  5642. This function is a cancellation point in multi-threaded programs.
  5643. This is a problem if the thread allocates some resources (like
  5644. memory, file descriptors, semaphores or whatever) at the time
  5645. ‘system’ is called. If the thread gets canceled these resources
  5646. stay allocated until the program ends. To avoid this calls to
  5647. ‘system’ should be protected using cancellation handlers.
  5648. The ‘system’ function is declared in the header file ‘stdlib.h’.
  5649. *Portability Note:* Some C implementations may not have any notion of
  5650. a command processor that can execute other programs. You can determine
  5651. whether a command processor exists by executing ‘system (NULL)’; if the
  5652. return value is nonzero, a command processor is available.
  5653. The ‘popen’ and ‘pclose’ functions (*note Pipe to a Subprocess::) are
  5654. closely related to the ‘system’ function. They allow the parent process
  5655. to communicate with the standard input and output channels of the
  5656. command being executed.
  5657. 
  5658. File: libc.info, Node: Process Creation Concepts, Next: Process Identification, Prev: Running a Command, Up: Processes
  5659. 26.2 Process Creation Concepts
  5660. ==============================
  5661. This section gives an overview of processes and of the steps involved in
  5662. creating a process and making it run another program.
  5663. Each process is named by a "process ID" number. A unique process ID
  5664. is allocated to each process when it is created. The "lifetime" of a
  5665. process ends when its termination is reported to its parent process; at
  5666. that time, all of the process resources, including its process ID, are
  5667. freed.
  5668. Processes are created with the ‘fork’ system call (so the operation
  5669. of creating a new process is sometimes called "forking" a process). The
  5670. "child process" created by ‘fork’ is a copy of the original "parent
  5671. process", except that it has its own process ID.
  5672. After forking a child process, both the parent and child processes
  5673. continue to execute normally. If you want your program to wait for a
  5674. child process to finish executing before continuing, you must do this
  5675. explicitly after the fork operation, by calling ‘wait’ or ‘waitpid’
  5676. (*note Process Completion::). These functions give you limited
  5677. information about why the child terminated—for example, its exit status
  5678. code.
  5679. A newly forked child process continues to execute the same program as
  5680. its parent process, at the point where the ‘fork’ call returns. You can
  5681. use the return value from ‘fork’ to tell whether the program is running
  5682. in the parent process or the child.
  5683. Having several processes run the same program is only occasionally
  5684. useful. But the child can execute another program using one of the
  5685. ‘exec’ functions; see *note Executing a File::. The program that the
  5686. process is executing is called its "process image". Starting execution
  5687. of a new program causes the process to forget all about its previous
  5688. process image; when the new program exits, the process exits too,
  5689. instead of returning to the previous process image.
  5690. 
  5691. File: libc.info, Node: Process Identification, Next: Creating a Process, Prev: Process Creation Concepts, Up: Processes
  5692. 26.3 Process Identification
  5693. ===========================
  5694. The ‘pid_t’ data type represents process IDs. You can get the process
  5695. ID of a process by calling ‘getpid’. The function ‘getppid’ returns the
  5696. process ID of the parent of the current process (this is also known as
  5697. the "parent process ID"). Your program should include the header files
  5698. ‘unistd.h’ and ‘sys/types.h’ to use these functions.
  5699. -- Data Type: pid_t
  5700. The ‘pid_t’ data type is a signed integer type which is capable of
  5701. representing a process ID. In the GNU C Library, this is an ‘int’.
  5702. -- Function: pid_t getpid (void)
  5703. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5704. Concepts::.
  5705. The ‘getpid’ function returns the process ID of the current
  5706. process.
  5707. -- Function: pid_t getppid (void)
  5708. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5709. Concepts::.
  5710. The ‘getppid’ function returns the process ID of the parent of the
  5711. current process.
  5712. 
  5713. File: libc.info, Node: Creating a Process, Next: Executing a File, Prev: Process Identification, Up: Processes
  5714. 26.4 Creating a Process
  5715. =======================
  5716. The ‘fork’ function is the primitive for creating a process. It is
  5717. declared in the header file ‘unistd.h’.
  5718. -- Function: pid_t fork (void)
  5719. Preliminary: | MT-Safe | AS-Unsafe plugin | AC-Unsafe lock | *Note
  5720. POSIX Safety Concepts::.
  5721. The ‘fork’ function creates a new process.
  5722. If the operation is successful, there are then both parent and
  5723. child processes and both see ‘fork’ return, but with different
  5724. values: it returns a value of ‘0’ in the child process and returns
  5725. the child’s process ID in the parent process.
  5726. If process creation failed, ‘fork’ returns a value of ‘-1’ in the
  5727. parent process. The following ‘errno’ error conditions are defined
  5728. for ‘fork’:
  5729. ‘EAGAIN’
  5730. There aren’t enough system resources to create another
  5731. process, or the user already has too many processes running.
  5732. This means exceeding the ‘RLIMIT_NPROC’ resource limit, which
  5733. can usually be increased; *note Limits on Resources::.
  5734. ‘ENOMEM’
  5735. The process requires more space than the system can supply.
  5736. The specific attributes of the child process that differ from the
  5737. parent process are:
  5738. • The child process has its own unique process ID.
  5739. • The parent process ID of the child process is the process ID of its
  5740. parent process.
  5741. • The child process gets its own copies of the parent process’s open
  5742. file descriptors. Subsequently changing attributes of the file
  5743. descriptors in the parent process won’t affect the file descriptors
  5744. in the child, and vice versa. *Note Control Operations::.
  5745. However, the file position associated with each descriptor is
  5746. shared by both processes; *note File Position::.
  5747. • The elapsed processor times for the child process are set to zero;
  5748. see *note Processor Time::.
  5749. • The child doesn’t inherit file locks set by the parent process.
  5750. *Note Control Operations::.
  5751. • The child doesn’t inherit alarms set by the parent process. *Note
  5752. Setting an Alarm::.
  5753. • The set of pending signals (*note Delivery of Signal::) for the
  5754. child process is cleared. (The child process inherits its mask of
  5755. blocked signals and signal actions from the parent process.)
  5756. -- Function: pid_t vfork (void)
  5757. Preliminary: | MT-Safe | AS-Unsafe plugin | AC-Unsafe lock | *Note
  5758. POSIX Safety Concepts::.
  5759. The ‘vfork’ function is similar to ‘fork’ but on some systems it is
  5760. more efficient; however, there are restrictions you must follow to
  5761. use it safely.
  5762. While ‘fork’ makes a complete copy of the calling process’s address
  5763. space and allows both the parent and child to execute
  5764. independently, ‘vfork’ does not make this copy. Instead, the child
  5765. process created with ‘vfork’ shares its parent’s address space
  5766. until it calls ‘_exit’ or one of the ‘exec’ functions. In the
  5767. meantime, the parent process suspends execution.
  5768. You must be very careful not to allow the child process created
  5769. with ‘vfork’ to modify any global data or even local variables
  5770. shared with the parent. Furthermore, the child process cannot
  5771. return from (or do a long jump out of) the function that called
  5772. ‘vfork’! This would leave the parent process’s control information
  5773. very confused. If in doubt, use ‘fork’ instead.
  5774. Some operating systems don’t really implement ‘vfork’. The GNU C
  5775. Library permits you to use ‘vfork’ on all systems, but actually
  5776. executes ‘fork’ if ‘vfork’ isn’t available. If you follow the
  5777. proper precautions for using ‘vfork’, your program will still work
  5778. even if the system uses ‘fork’ instead.
  5779. 
  5780. File: libc.info, Node: Executing a File, Next: Process Completion, Prev: Creating a Process, Up: Processes
  5781. 26.5 Executing a File
  5782. =====================
  5783. This section describes the ‘exec’ family of functions, for executing a
  5784. file as a process image. You can use these functions to make a child
  5785. process execute a new program after it has been forked.
  5786. To see the effects of ‘exec’ from the point of view of the called
  5787. program, see *note Program Basics::.
  5788. The functions in this family differ in how you specify the arguments,
  5789. but otherwise they all do the same thing. They are declared in the
  5790. header file ‘unistd.h’.
  5791. -- Function: int execv (const char *FILENAME, char *const ARGV[])
  5792. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5793. Concepts::.
  5794. The ‘execv’ function executes the file named by FILENAME as a new
  5795. process image.
  5796. The ARGV argument is an array of null-terminated strings that is
  5797. used to provide a value for the ‘argv’ argument to the ‘main’
  5798. function of the program to be executed. The last element of this
  5799. array must be a null pointer. By convention, the first element of
  5800. this array is the file name of the program sans directory names.
  5801. *Note Program Arguments::, for full details on how programs can
  5802. access these arguments.
  5803. The environment for the new process image is taken from the
  5804. ‘environ’ variable of the current process image; see *note
  5805. Environment Variables::, for information about environments.
  5806. -- Function: int execl (const char *FILENAME, const char *ARG0, …)
  5807. Preliminary: | MT-Safe | AS-Unsafe heap | AC-Unsafe mem | *Note
  5808. POSIX Safety Concepts::.
  5809. This is similar to ‘execv’, but the ARGV strings are specified
  5810. individually instead of as an array. A null pointer must be passed
  5811. as the last such argument.
  5812. -- Function: int execve (const char *FILENAME, char *const ARGV[], char
  5813. *const ENV[])
  5814. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5815. Concepts::.
  5816. This is similar to ‘execv’, but permits you to specify the
  5817. environment for the new program explicitly as the ENV argument.
  5818. This should be an array of strings in the same format as for the
  5819. ‘environ’ variable; see *note Environment Access::.
  5820. -- Function: int execle (const char *FILENAME, const char *ARG0, …,
  5821. char *const ENV[])
  5822. Preliminary: | MT-Safe | AS-Unsafe heap | AC-Unsafe mem | *Note
  5823. POSIX Safety Concepts::.
  5824. This is similar to ‘execl’, but permits you to specify the
  5825. environment for the new program explicitly. The environment
  5826. argument is passed following the null pointer that marks the last
  5827. ARGV argument, and should be an array of strings in the same format
  5828. as for the ‘environ’ variable.
  5829. -- Function: int execvp (const char *FILENAME, char *const ARGV[])
  5830. Preliminary: | MT-Safe env | AS-Unsafe heap | AC-Unsafe mem | *Note
  5831. POSIX Safety Concepts::.
  5832. The ‘execvp’ function is similar to ‘execv’, except that it
  5833. searches the directories listed in the ‘PATH’ environment variable
  5834. (*note Standard Environment::) to find the full file name of a file
  5835. from FILENAME if FILENAME does not contain a slash.
  5836. This function is useful for executing system utility programs,
  5837. because it looks for them in the places that the user has chosen.
  5838. Shells use it to run the commands that users type.
  5839. -- Function: int execlp (const char *FILENAME, const char *ARG0, …)
  5840. Preliminary: | MT-Safe env | AS-Unsafe heap | AC-Unsafe mem | *Note
  5841. POSIX Safety Concepts::.
  5842. This function is like ‘execl’, except that it performs the same
  5843. file name searching as the ‘execvp’ function.
  5844. The size of the argument list and environment list taken together
  5845. must not be greater than ‘ARG_MAX’ bytes. *Note General Limits::. On
  5846. GNU/Hurd systems, the size (which compares against ‘ARG_MAX’) includes,
  5847. for each string, the number of characters in the string, plus the size
  5848. of a ‘char *’, plus one, rounded up to a multiple of the size of a ‘char
  5849. *’. Other systems may have somewhat different rules for counting.
  5850. These functions normally don’t return, since execution of a new
  5851. program causes the currently executing program to go away completely. A
  5852. value of ‘-1’ is returned in the event of a failure. In addition to the
  5853. usual file name errors (*note File Name Errors::), the following ‘errno’
  5854. error conditions are defined for these functions:
  5855. ‘E2BIG’
  5856. The combined size of the new program’s argument list and
  5857. environment list is larger than ‘ARG_MAX’ bytes. GNU/Hurd systems
  5858. have no specific limit on the argument list size, so this error
  5859. code cannot result, but you may get ‘ENOMEM’ instead if the
  5860. arguments are too big for available memory.
  5861. ‘ENOEXEC’
  5862. The specified file can’t be executed because it isn’t in the right
  5863. format.
  5864. ‘ENOMEM’
  5865. Executing the specified file requires more storage than is
  5866. available.
  5867. If execution of the new file succeeds, it updates the access time
  5868. field of the file as if the file had been read. *Note File Times::, for
  5869. more details about access times of files.
  5870. The point at which the file is closed again is not specified, but is
  5871. at some point before the process exits or before another process image
  5872. is executed.
  5873. Executing a new process image completely changes the contents of
  5874. memory, copying only the argument and environment strings to new
  5875. locations. But many other attributes of the process are unchanged:
  5876. • The process ID and the parent process ID. *Note Process Creation
  5877. Concepts::.
  5878. • Session and process group membership. *Note Concepts of Job
  5879. Control::.
  5880. • Real user ID and group ID, and supplementary group IDs. *Note
  5881. Process Persona::.
  5882. • Pending alarms. *Note Setting an Alarm::.
  5883. • Current working directory and root directory. *Note Working
  5884. Directory::. On GNU/Hurd systems, the root directory is not copied
  5885. when executing a setuid program; instead the system default root
  5886. directory is used for the new program.
  5887. • File mode creation mask. *Note Setting Permissions::.
  5888. • Process signal mask; see *note Process Signal Mask::.
  5889. • Pending signals; see *note Blocking Signals::.
  5890. • Elapsed processor time associated with the process; see *note
  5891. Processor Time::.
  5892. If the set-user-ID and set-group-ID mode bits of the process image
  5893. file are set, this affects the effective user ID and effective group ID
  5894. (respectively) of the process. These concepts are discussed in detail
  5895. in *note Process Persona::.
  5896. Signals that are set to be ignored in the existing process image are
  5897. also set to be ignored in the new process image. All other signals are
  5898. set to the default action in the new process image. For more
  5899. information about signals, see *note Signal Handling::.
  5900. File descriptors open in the existing process image remain open in
  5901. the new process image, unless they have the ‘FD_CLOEXEC’ (close-on-exec)
  5902. flag set. The files that remain open inherit all attributes of the open
  5903. file descriptors from the existing process image, including file locks.
  5904. File descriptors are discussed in *note Low-Level I/O::.
  5905. Streams, by contrast, cannot survive through ‘exec’ functions,
  5906. because they are located in the memory of the process itself. The new
  5907. process image has no streams except those it creates afresh. Each of
  5908. the streams in the pre-‘exec’ process image has a descriptor inside it,
  5909. and these descriptors do survive through ‘exec’ (provided that they do
  5910. not have ‘FD_CLOEXEC’ set). The new process image can reconnect these
  5911. to new streams using ‘fdopen’ (*note Descriptors and Streams::).
  5912. 
  5913. File: libc.info, Node: Process Completion, Next: Process Completion Status, Prev: Executing a File, Up: Processes
  5914. 26.6 Process Completion
  5915. =======================
  5916. The functions described in this section are used to wait for a child
  5917. process to terminate or stop, and determine its status. These functions
  5918. are declared in the header file ‘sys/wait.h’.
  5919. -- Function: pid_t waitpid (pid_t PID, int *STATUS-PTR, int OPTIONS)
  5920. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5921. Concepts::.
  5922. The ‘waitpid’ function is used to request status information from a
  5923. child process whose process ID is PID. Normally, the calling
  5924. process is suspended until the child process makes status
  5925. information available by terminating.
  5926. Other values for the PID argument have special interpretations. A
  5927. value of ‘-1’ or ‘WAIT_ANY’ requests status information for any
  5928. child process; a value of ‘0’ or ‘WAIT_MYPGRP’ requests information
  5929. for any child process in the same process group as the calling
  5930. process; and any other negative value − PGID requests information
  5931. for any child process whose process group ID is PGID.
  5932. If status information for a child process is available immediately,
  5933. this function returns immediately without waiting. If more than
  5934. one eligible child process has status information available, one of
  5935. them is chosen randomly, and its status is returned immediately.
  5936. To get the status from the other eligible child processes, you need
  5937. to call ‘waitpid’ again.
  5938. The OPTIONS argument is a bit mask. Its value should be the
  5939. bitwise OR (that is, the ‘|’ operator) of zero or more of the
  5940. ‘WNOHANG’ and ‘WUNTRACED’ flags. You can use the ‘WNOHANG’ flag to
  5941. indicate that the parent process shouldn’t wait; and the
  5942. ‘WUNTRACED’ flag to request status information from stopped
  5943. processes as well as processes that have terminated.
  5944. The status information from the child process is stored in the
  5945. object that STATUS-PTR points to, unless STATUS-PTR is a null
  5946. pointer.
  5947. This function is a cancellation point in multi-threaded programs.
  5948. This is a problem if the thread allocates some resources (like
  5949. memory, file descriptors, semaphores or whatever) at the time
  5950. ‘waitpid’ is called. If the thread gets canceled these resources
  5951. stay allocated until the program ends. To avoid this calls to
  5952. ‘waitpid’ should be protected using cancellation handlers.
  5953. The return value is normally the process ID of the child process
  5954. whose status is reported. If there are child processes but none of
  5955. them is waiting to be noticed, ‘waitpid’ will block until one is.
  5956. However, if the ‘WNOHANG’ option was specified, ‘waitpid’ will
  5957. return zero instead of blocking.
  5958. If a specific PID to wait for was given to ‘waitpid’, it will
  5959. ignore all other children (if any). Therefore if there are
  5960. children waiting to be noticed but the child whose PID was
  5961. specified is not one of them, ‘waitpid’ will block or return zero
  5962. as described above.
  5963. A value of ‘-1’ is returned in case of error. The following
  5964. ‘errno’ error conditions are defined for this function:
  5965. ‘EINTR’
  5966. The function was interrupted by delivery of a signal to the
  5967. calling process. *Note Interrupted Primitives::.
  5968. ‘ECHILD’
  5969. There are no child processes to wait for, or the specified PID
  5970. is not a child of the calling process.
  5971. ‘EINVAL’
  5972. An invalid value was provided for the OPTIONS argument.
  5973. These symbolic constants are defined as values for the PID argument
  5974. to the ‘waitpid’ function.
  5975. ‘WAIT_ANY’
  5976. This constant macro (whose value is ‘-1’) specifies that ‘waitpid’
  5977. should return status information about any child process.
  5978. ‘WAIT_MYPGRP’
  5979. This constant (with value ‘0’) specifies that ‘waitpid’ should
  5980. return status information about any child process in the same
  5981. process group as the calling process.
  5982. These symbolic constants are defined as flags for the OPTIONS
  5983. argument to the ‘waitpid’ function. You can bitwise-OR the flags
  5984. together to obtain a value to use as the argument.
  5985. ‘WNOHANG’
  5986. This flag specifies that ‘waitpid’ should return immediately
  5987. instead of waiting, if there is no child process ready to be
  5988. noticed.
  5989. ‘WUNTRACED’
  5990. This flag specifies that ‘waitpid’ should report the status of any
  5991. child processes that have been stopped as well as those that have
  5992. terminated.
  5993. -- Function: pid_t wait (int *STATUS-PTR)
  5994. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  5995. Concepts::.
  5996. This is a simplified version of ‘waitpid’, and is used to wait
  5997. until any one child process terminates. The call:
  5998. wait (&status)
  5999. is exactly equivalent to:
  6000. waitpid (-1, &status, 0)
  6001. This function is a cancellation point in multi-threaded programs.
  6002. This is a problem if the thread allocates some resources (like
  6003. memory, file descriptors, semaphores or whatever) at the time
  6004. ‘wait’ is called. If the thread gets canceled these resources stay
  6005. allocated until the program ends. To avoid this calls to ‘wait’
  6006. should be protected using cancellation handlers.
  6007. -- Function: pid_t wait4 (pid_t PID, int *STATUS-PTR, int OPTIONS,
  6008. struct rusage *USAGE)
  6009. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6010. Concepts::.
  6011. If USAGE is a null pointer, ‘wait4’ is equivalent to ‘waitpid (PID,
  6012. STATUS-PTR, OPTIONS)’.
  6013. If USAGE is not null, ‘wait4’ stores usage figures for the child
  6014. process in ‘*RUSAGE’ (but only if the child has terminated, not if
  6015. it has stopped). *Note Resource Usage::.
  6016. This function is a BSD extension.
  6017. Here’s an example of how to use ‘waitpid’ to get the status from all
  6018. child processes that have terminated, without ever waiting. This
  6019. function is designed to be a handler for ‘SIGCHLD’, the signal that
  6020. indicates that at least one child process has terminated.
  6021. void
  6022. sigchld_handler (int signum)
  6023. {
  6024. int pid, status, serrno;
  6025. serrno = errno;
  6026. while (1)
  6027. {
  6028. pid = waitpid (WAIT_ANY, &status, WNOHANG);
  6029. if (pid < 0)
  6030. {
  6031. perror ("waitpid");
  6032. break;
  6033. }
  6034. if (pid == 0)
  6035. break;
  6036. notice_termination (pid, status);
  6037. }
  6038. errno = serrno;
  6039. }
  6040. 
  6041. File: libc.info, Node: Process Completion Status, Next: BSD Wait Functions, Prev: Process Completion, Up: Processes
  6042. 26.7 Process Completion Status
  6043. ==============================
  6044. If the exit status value (*note Program Termination::) of the child
  6045. process is zero, then the status value reported by ‘waitpid’ or ‘wait’
  6046. is also zero. You can test for other kinds of information encoded in
  6047. the returned status value using the following macros. These macros are
  6048. defined in the header file ‘sys/wait.h’.
  6049. -- Macro: int WIFEXITED (int STATUS)
  6050. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6051. Concepts::.
  6052. This macro returns a nonzero value if the child process terminated
  6053. normally with ‘exit’ or ‘_exit’.
  6054. -- Macro: int WEXITSTATUS (int STATUS)
  6055. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6056. Concepts::.
  6057. If ‘WIFEXITED’ is true of STATUS, this macro returns the low-order
  6058. 8 bits of the exit status value from the child process. *Note Exit
  6059. Status::.
  6060. -- Macro: int WIFSIGNALED (int STATUS)
  6061. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6062. Concepts::.
  6063. This macro returns a nonzero value if the child process terminated
  6064. because it received a signal that was not handled. *Note Signal
  6065. Handling::.
  6066. -- Macro: int WTERMSIG (int STATUS)
  6067. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6068. Concepts::.
  6069. If ‘WIFSIGNALED’ is true of STATUS, this macro returns the signal
  6070. number of the signal that terminated the child process.
  6071. -- Macro: int WCOREDUMP (int STATUS)
  6072. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6073. Concepts::.
  6074. This macro returns a nonzero value if the child process terminated
  6075. and produced a core dump.
  6076. -- Macro: int WIFSTOPPED (int STATUS)
  6077. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6078. Concepts::.
  6079. This macro returns a nonzero value if the child process is stopped.
  6080. -- Macro: int WSTOPSIG (int STATUS)
  6081. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6082. Concepts::.
  6083. If ‘WIFSTOPPED’ is true of STATUS, this macro returns the signal
  6084. number of the signal that caused the child process to stop.
  6085. 
  6086. File: libc.info, Node: BSD Wait Functions, Next: Process Creation Example, Prev: Process Completion Status, Up: Processes
  6087. 26.8 BSD Process Wait Function
  6088. ==============================
  6089. The GNU C Library also provides the ‘wait3’ function for compatibility
  6090. with BSD. This function is declared in ‘sys/wait.h’. It is the
  6091. predecessor to ‘wait4’, which is more flexible. ‘wait3’ is now
  6092. obsolete.
  6093. -- Function: pid_t wait3 (int *STATUS-PTR, int OPTIONS, struct rusage
  6094. *USAGE)
  6095. Preliminary: | MT-Safe | AS-Safe | AC-Safe | *Note POSIX Safety
  6096. Concepts::.
  6097. If USAGE is a null pointer, ‘wait3’ is equivalent to ‘waitpid (-1,
  6098. STATUS-PTR, OPTIONS)’.
  6099. If USAGE is not null, ‘wait3’ stores usage figures for the child
  6100. process in ‘*RUSAGE’ (but only if the child has terminated, not if
  6101. it has stopped). *Note Resource Usage::.
  6102. 
  6103. File: libc.info, Node: Process Creation Example, Prev: BSD Wait Functions, Up: Processes
  6104. 26.9 Process Creation Example
  6105. =============================
  6106. Here is an example program showing how you might write a function
  6107. similar to the built-in ‘system’. It executes its COMMAND argument
  6108. using the equivalent of ‘sh -c COMMAND’.
  6109. #include <stddef.h>
  6110. #include <stdlib.h>
  6111. #include <unistd.h>
  6112. #include <sys/types.h>
  6113. #include <sys/wait.h>
  6114. /* Execute the command using this shell program. */
  6115. #define SHELL "/bin/sh"
  6116. int
  6117. my_system (const char *command)
  6118. {
  6119. int status;
  6120. pid_t pid;
  6121. pid = fork ();
  6122. if (pid == 0)
  6123. {
  6124. /* This is the child process. Execute the shell command. */
  6125. execl (SHELL, SHELL, "-c", command, NULL);
  6126. _exit (EXIT_FAILURE);
  6127. }
  6128. else if (pid < 0)
  6129. /* The fork failed. Report failure. */
  6130. status = -1;
  6131. else
  6132. /* This is the parent process. Wait for the child to complete. */
  6133. if (waitpid (pid, &status, 0) != pid)
  6134. status = -1;
  6135. return status;
  6136. }
  6137. There are a couple of things you should pay attention to in this
  6138. example.
  6139. Remember that the first ‘argv’ argument supplied to the program
  6140. represents the name of the program being executed. That is why, in the
  6141. call to ‘execl’, ‘SHELL’ is supplied once to name the program to execute
  6142. and a second time to supply a value for ‘argv[0]’.
  6143. The ‘execl’ call in the child process doesn’t return if it is
  6144. successful. If it fails, you must do something to make the child
  6145. process terminate. Just returning a bad status code with ‘return’ would
  6146. leave two processes running the original program. Instead, the right
  6147. behavior is for the child process to report failure to its parent
  6148. process.
  6149. Call ‘_exit’ to accomplish this. The reason for using ‘_exit’
  6150. instead of ‘exit’ is to avoid flushing fully buffered streams such as
  6151. ‘stdout’. The buffers of these streams probably contain data that was
  6152. copied from the parent process by the ‘fork’, data that will be output
  6153. eventually by the parent process. Calling ‘exit’ in the child would
  6154. output the data twice. *Note Termination Internals::.