posixmodule.c.h 326 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005
  1. /*[clinic input]
  2. preserve
  3. [clinic start generated code]*/
  4. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5. # include "pycore_gc.h" // PyGC_Head
  6. # include "pycore_runtime.h" // _Py_ID()
  7. #endif
  8. PyDoc_STRVAR(os_stat__doc__,
  9. "stat($module, /, path, *, dir_fd=None, follow_symlinks=True)\n"
  10. "--\n"
  11. "\n"
  12. "Perform a stat system call on the given path.\n"
  13. "\n"
  14. " path\n"
  15. " Path to be examined; can be string, bytes, a path-like object or\n"
  16. " open-file-descriptor int.\n"
  17. " dir_fd\n"
  18. " If not None, it should be a file descriptor open to a directory,\n"
  19. " and path should be a relative string; path will then be relative to\n"
  20. " that directory.\n"
  21. " follow_symlinks\n"
  22. " If False, and the last element of the path is a symbolic link,\n"
  23. " stat will examine the symbolic link itself instead of the file\n"
  24. " the link points to.\n"
  25. "\n"
  26. "dir_fd and follow_symlinks may not be implemented\n"
  27. " on your platform. If they are unavailable, using them will raise a\n"
  28. " NotImplementedError.\n"
  29. "\n"
  30. "It\'s an error to use dir_fd or follow_symlinks when specifying path as\n"
  31. " an open file descriptor.");
  32. #define OS_STAT_METHODDEF \
  33. {"stat", _PyCFunction_CAST(os_stat), METH_FASTCALL|METH_KEYWORDS, os_stat__doc__},
  34. static PyObject *
  35. os_stat_impl(PyObject *module, path_t *path, int dir_fd, int follow_symlinks);
  36. static PyObject *
  37. os_stat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  38. {
  39. PyObject *return_value = NULL;
  40. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  41. #define NUM_KEYWORDS 3
  42. static struct {
  43. PyGC_Head _this_is_not_used;
  44. PyObject_VAR_HEAD
  45. PyObject *ob_item[NUM_KEYWORDS];
  46. } _kwtuple = {
  47. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  48. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
  49. };
  50. #undef NUM_KEYWORDS
  51. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  52. #else // !Py_BUILD_CORE
  53. # define KWTUPLE NULL
  54. #endif // !Py_BUILD_CORE
  55. static const char * const _keywords[] = {"path", "dir_fd", "follow_symlinks", NULL};
  56. static _PyArg_Parser _parser = {
  57. .keywords = _keywords,
  58. .fname = "stat",
  59. .kwtuple = KWTUPLE,
  60. };
  61. #undef KWTUPLE
  62. PyObject *argsbuf[3];
  63. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  64. path_t path = PATH_T_INITIALIZE_P("stat", "path", 0, 0, 0, 1);
  65. int dir_fd = DEFAULT_DIR_FD;
  66. int follow_symlinks = 1;
  67. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  68. if (!args) {
  69. goto exit;
  70. }
  71. if (!path_converter(args[0], &path)) {
  72. goto exit;
  73. }
  74. if (!noptargs) {
  75. goto skip_optional_kwonly;
  76. }
  77. if (args[1]) {
  78. if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  79. goto exit;
  80. }
  81. if (!--noptargs) {
  82. goto skip_optional_kwonly;
  83. }
  84. }
  85. follow_symlinks = PyObject_IsTrue(args[2]);
  86. if (follow_symlinks < 0) {
  87. goto exit;
  88. }
  89. skip_optional_kwonly:
  90. return_value = os_stat_impl(module, &path, dir_fd, follow_symlinks);
  91. exit:
  92. /* Cleanup for path */
  93. path_cleanup(&path);
  94. return return_value;
  95. }
  96. PyDoc_STRVAR(os_lstat__doc__,
  97. "lstat($module, /, path, *, dir_fd=None)\n"
  98. "--\n"
  99. "\n"
  100. "Perform a stat system call on the given path, without following symbolic links.\n"
  101. "\n"
  102. "Like stat(), but do not follow symbolic links.\n"
  103. "Equivalent to stat(path, follow_symlinks=False).");
  104. #define OS_LSTAT_METHODDEF \
  105. {"lstat", _PyCFunction_CAST(os_lstat), METH_FASTCALL|METH_KEYWORDS, os_lstat__doc__},
  106. static PyObject *
  107. os_lstat_impl(PyObject *module, path_t *path, int dir_fd);
  108. static PyObject *
  109. os_lstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  110. {
  111. PyObject *return_value = NULL;
  112. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  113. #define NUM_KEYWORDS 2
  114. static struct {
  115. PyGC_Head _this_is_not_used;
  116. PyObject_VAR_HEAD
  117. PyObject *ob_item[NUM_KEYWORDS];
  118. } _kwtuple = {
  119. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  120. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
  121. };
  122. #undef NUM_KEYWORDS
  123. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  124. #else // !Py_BUILD_CORE
  125. # define KWTUPLE NULL
  126. #endif // !Py_BUILD_CORE
  127. static const char * const _keywords[] = {"path", "dir_fd", NULL};
  128. static _PyArg_Parser _parser = {
  129. .keywords = _keywords,
  130. .fname = "lstat",
  131. .kwtuple = KWTUPLE,
  132. };
  133. #undef KWTUPLE
  134. PyObject *argsbuf[2];
  135. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  136. path_t path = PATH_T_INITIALIZE_P("lstat", "path", 0, 0, 0, 0);
  137. int dir_fd = DEFAULT_DIR_FD;
  138. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  139. if (!args) {
  140. goto exit;
  141. }
  142. if (!path_converter(args[0], &path)) {
  143. goto exit;
  144. }
  145. if (!noptargs) {
  146. goto skip_optional_kwonly;
  147. }
  148. if (!FSTATAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  149. goto exit;
  150. }
  151. skip_optional_kwonly:
  152. return_value = os_lstat_impl(module, &path, dir_fd);
  153. exit:
  154. /* Cleanup for path */
  155. path_cleanup(&path);
  156. return return_value;
  157. }
  158. PyDoc_STRVAR(os_access__doc__,
  159. "access($module, /, path, mode, *, dir_fd=None, effective_ids=False,\n"
  160. " follow_symlinks=True)\n"
  161. "--\n"
  162. "\n"
  163. "Use the real uid/gid to test for access to a path.\n"
  164. "\n"
  165. " path\n"
  166. " Path to be tested; can be string, bytes, or a path-like object.\n"
  167. " mode\n"
  168. " Operating-system mode bitfield. Can be F_OK to test existence,\n"
  169. " or the inclusive-OR of R_OK, W_OK, and X_OK.\n"
  170. " dir_fd\n"
  171. " If not None, it should be a file descriptor open to a directory,\n"
  172. " and path should be relative; path will then be relative to that\n"
  173. " directory.\n"
  174. " effective_ids\n"
  175. " If True, access will use the effective uid/gid instead of\n"
  176. " the real uid/gid.\n"
  177. " follow_symlinks\n"
  178. " If False, and the last element of the path is a symbolic link,\n"
  179. " access will examine the symbolic link itself instead of the file\n"
  180. " the link points to.\n"
  181. "\n"
  182. "dir_fd, effective_ids, and follow_symlinks may not be implemented\n"
  183. " on your platform. If they are unavailable, using them will raise a\n"
  184. " NotImplementedError.\n"
  185. "\n"
  186. "Note that most operations will use the effective uid/gid, therefore this\n"
  187. " routine can be used in a suid/sgid environment to test if the invoking user\n"
  188. " has the specified access to the path.");
  189. #define OS_ACCESS_METHODDEF \
  190. {"access", _PyCFunction_CAST(os_access), METH_FASTCALL|METH_KEYWORDS, os_access__doc__},
  191. static int
  192. os_access_impl(PyObject *module, path_t *path, int mode, int dir_fd,
  193. int effective_ids, int follow_symlinks);
  194. static PyObject *
  195. os_access(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  196. {
  197. PyObject *return_value = NULL;
  198. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  199. #define NUM_KEYWORDS 5
  200. static struct {
  201. PyGC_Head _this_is_not_used;
  202. PyObject_VAR_HEAD
  203. PyObject *ob_item[NUM_KEYWORDS];
  204. } _kwtuple = {
  205. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  206. .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(effective_ids), &_Py_ID(follow_symlinks), },
  207. };
  208. #undef NUM_KEYWORDS
  209. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  210. #else // !Py_BUILD_CORE
  211. # define KWTUPLE NULL
  212. #endif // !Py_BUILD_CORE
  213. static const char * const _keywords[] = {"path", "mode", "dir_fd", "effective_ids", "follow_symlinks", NULL};
  214. static _PyArg_Parser _parser = {
  215. .keywords = _keywords,
  216. .fname = "access",
  217. .kwtuple = KWTUPLE,
  218. };
  219. #undef KWTUPLE
  220. PyObject *argsbuf[5];
  221. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  222. path_t path = PATH_T_INITIALIZE_P("access", "path", 0, 0, 0, 0);
  223. int mode;
  224. int dir_fd = DEFAULT_DIR_FD;
  225. int effective_ids = 0;
  226. int follow_symlinks = 1;
  227. int _return_value;
  228. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  229. if (!args) {
  230. goto exit;
  231. }
  232. if (!path_converter(args[0], &path)) {
  233. goto exit;
  234. }
  235. mode = _PyLong_AsInt(args[1]);
  236. if (mode == -1 && PyErr_Occurred()) {
  237. goto exit;
  238. }
  239. if (!noptargs) {
  240. goto skip_optional_kwonly;
  241. }
  242. if (args[2]) {
  243. if (!FACCESSAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
  244. goto exit;
  245. }
  246. if (!--noptargs) {
  247. goto skip_optional_kwonly;
  248. }
  249. }
  250. if (args[3]) {
  251. effective_ids = PyObject_IsTrue(args[3]);
  252. if (effective_ids < 0) {
  253. goto exit;
  254. }
  255. if (!--noptargs) {
  256. goto skip_optional_kwonly;
  257. }
  258. }
  259. follow_symlinks = PyObject_IsTrue(args[4]);
  260. if (follow_symlinks < 0) {
  261. goto exit;
  262. }
  263. skip_optional_kwonly:
  264. _return_value = os_access_impl(module, &path, mode, dir_fd, effective_ids, follow_symlinks);
  265. if ((_return_value == -1) && PyErr_Occurred()) {
  266. goto exit;
  267. }
  268. return_value = PyBool_FromLong((long)_return_value);
  269. exit:
  270. /* Cleanup for path */
  271. path_cleanup(&path);
  272. return return_value;
  273. }
  274. #if defined(HAVE_TTYNAME)
  275. PyDoc_STRVAR(os_ttyname__doc__,
  276. "ttyname($module, fd, /)\n"
  277. "--\n"
  278. "\n"
  279. "Return the name of the terminal device connected to \'fd\'.\n"
  280. "\n"
  281. " fd\n"
  282. " Integer file descriptor handle.");
  283. #define OS_TTYNAME_METHODDEF \
  284. {"ttyname", (PyCFunction)os_ttyname, METH_O, os_ttyname__doc__},
  285. static PyObject *
  286. os_ttyname_impl(PyObject *module, int fd);
  287. static PyObject *
  288. os_ttyname(PyObject *module, PyObject *arg)
  289. {
  290. PyObject *return_value = NULL;
  291. int fd;
  292. fd = _PyLong_AsInt(arg);
  293. if (fd == -1 && PyErr_Occurred()) {
  294. goto exit;
  295. }
  296. return_value = os_ttyname_impl(module, fd);
  297. exit:
  298. return return_value;
  299. }
  300. #endif /* defined(HAVE_TTYNAME) */
  301. #if defined(HAVE_CTERMID)
  302. PyDoc_STRVAR(os_ctermid__doc__,
  303. "ctermid($module, /)\n"
  304. "--\n"
  305. "\n"
  306. "Return the name of the controlling terminal for this process.");
  307. #define OS_CTERMID_METHODDEF \
  308. {"ctermid", (PyCFunction)os_ctermid, METH_NOARGS, os_ctermid__doc__},
  309. static PyObject *
  310. os_ctermid_impl(PyObject *module);
  311. static PyObject *
  312. os_ctermid(PyObject *module, PyObject *Py_UNUSED(ignored))
  313. {
  314. return os_ctermid_impl(module);
  315. }
  316. #endif /* defined(HAVE_CTERMID) */
  317. PyDoc_STRVAR(os_chdir__doc__,
  318. "chdir($module, /, path)\n"
  319. "--\n"
  320. "\n"
  321. "Change the current working directory to the specified path.\n"
  322. "\n"
  323. "path may always be specified as a string.\n"
  324. "On some platforms, path may also be specified as an open file descriptor.\n"
  325. " If this functionality is unavailable, using it raises an exception.");
  326. #define OS_CHDIR_METHODDEF \
  327. {"chdir", _PyCFunction_CAST(os_chdir), METH_FASTCALL|METH_KEYWORDS, os_chdir__doc__},
  328. static PyObject *
  329. os_chdir_impl(PyObject *module, path_t *path);
  330. static PyObject *
  331. os_chdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  332. {
  333. PyObject *return_value = NULL;
  334. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  335. #define NUM_KEYWORDS 1
  336. static struct {
  337. PyGC_Head _this_is_not_used;
  338. PyObject_VAR_HEAD
  339. PyObject *ob_item[NUM_KEYWORDS];
  340. } _kwtuple = {
  341. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  342. .ob_item = { &_Py_ID(path), },
  343. };
  344. #undef NUM_KEYWORDS
  345. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  346. #else // !Py_BUILD_CORE
  347. # define KWTUPLE NULL
  348. #endif // !Py_BUILD_CORE
  349. static const char * const _keywords[] = {"path", NULL};
  350. static _PyArg_Parser _parser = {
  351. .keywords = _keywords,
  352. .fname = "chdir",
  353. .kwtuple = KWTUPLE,
  354. };
  355. #undef KWTUPLE
  356. PyObject *argsbuf[1];
  357. path_t path = PATH_T_INITIALIZE_P("chdir", "path", 0, 0, 0, PATH_HAVE_FCHDIR);
  358. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  359. if (!args) {
  360. goto exit;
  361. }
  362. if (!path_converter(args[0], &path)) {
  363. goto exit;
  364. }
  365. return_value = os_chdir_impl(module, &path);
  366. exit:
  367. /* Cleanup for path */
  368. path_cleanup(&path);
  369. return return_value;
  370. }
  371. #if defined(HAVE_FCHDIR)
  372. PyDoc_STRVAR(os_fchdir__doc__,
  373. "fchdir($module, /, fd)\n"
  374. "--\n"
  375. "\n"
  376. "Change to the directory of the given file descriptor.\n"
  377. "\n"
  378. "fd must be opened on a directory, not a file.\n"
  379. "Equivalent to os.chdir(fd).");
  380. #define OS_FCHDIR_METHODDEF \
  381. {"fchdir", _PyCFunction_CAST(os_fchdir), METH_FASTCALL|METH_KEYWORDS, os_fchdir__doc__},
  382. static PyObject *
  383. os_fchdir_impl(PyObject *module, int fd);
  384. static PyObject *
  385. os_fchdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  386. {
  387. PyObject *return_value = NULL;
  388. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  389. #define NUM_KEYWORDS 1
  390. static struct {
  391. PyGC_Head _this_is_not_used;
  392. PyObject_VAR_HEAD
  393. PyObject *ob_item[NUM_KEYWORDS];
  394. } _kwtuple = {
  395. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  396. .ob_item = { &_Py_ID(fd), },
  397. };
  398. #undef NUM_KEYWORDS
  399. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  400. #else // !Py_BUILD_CORE
  401. # define KWTUPLE NULL
  402. #endif // !Py_BUILD_CORE
  403. static const char * const _keywords[] = {"fd", NULL};
  404. static _PyArg_Parser _parser = {
  405. .keywords = _keywords,
  406. .fname = "fchdir",
  407. .kwtuple = KWTUPLE,
  408. };
  409. #undef KWTUPLE
  410. PyObject *argsbuf[1];
  411. int fd;
  412. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  413. if (!args) {
  414. goto exit;
  415. }
  416. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  417. goto exit;
  418. }
  419. return_value = os_fchdir_impl(module, fd);
  420. exit:
  421. return return_value;
  422. }
  423. #endif /* defined(HAVE_FCHDIR) */
  424. PyDoc_STRVAR(os_chmod__doc__,
  425. "chmod($module, /, path, mode, *, dir_fd=None, follow_symlinks=True)\n"
  426. "--\n"
  427. "\n"
  428. "Change the access permissions of a file.\n"
  429. "\n"
  430. " path\n"
  431. " Path to be modified. May always be specified as a str, bytes, or a path-like object.\n"
  432. " On some platforms, path may also be specified as an open file descriptor.\n"
  433. " If this functionality is unavailable, using it raises an exception.\n"
  434. " mode\n"
  435. " Operating-system mode bitfield.\n"
  436. " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
  437. " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
  438. " Python.\n"
  439. " dir_fd\n"
  440. " If not None, it should be a file descriptor open to a directory,\n"
  441. " and path should be relative; path will then be relative to that\n"
  442. " directory.\n"
  443. " follow_symlinks\n"
  444. " If False, and the last element of the path is a symbolic link,\n"
  445. " chmod will modify the symbolic link itself instead of the file\n"
  446. " the link points to.\n"
  447. "\n"
  448. "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
  449. " an open file descriptor.\n"
  450. "dir_fd and follow_symlinks may not be implemented on your platform.\n"
  451. " If they are unavailable, using them will raise a NotImplementedError.");
  452. #define OS_CHMOD_METHODDEF \
  453. {"chmod", _PyCFunction_CAST(os_chmod), METH_FASTCALL|METH_KEYWORDS, os_chmod__doc__},
  454. static PyObject *
  455. os_chmod_impl(PyObject *module, path_t *path, int mode, int dir_fd,
  456. int follow_symlinks);
  457. static PyObject *
  458. os_chmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  459. {
  460. PyObject *return_value = NULL;
  461. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  462. #define NUM_KEYWORDS 4
  463. static struct {
  464. PyGC_Head _this_is_not_used;
  465. PyObject_VAR_HEAD
  466. PyObject *ob_item[NUM_KEYWORDS];
  467. } _kwtuple = {
  468. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  469. .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
  470. };
  471. #undef NUM_KEYWORDS
  472. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  473. #else // !Py_BUILD_CORE
  474. # define KWTUPLE NULL
  475. #endif // !Py_BUILD_CORE
  476. static const char * const _keywords[] = {"path", "mode", "dir_fd", "follow_symlinks", NULL};
  477. static _PyArg_Parser _parser = {
  478. .keywords = _keywords,
  479. .fname = "chmod",
  480. .kwtuple = KWTUPLE,
  481. };
  482. #undef KWTUPLE
  483. PyObject *argsbuf[4];
  484. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  485. path_t path = PATH_T_INITIALIZE_P("chmod", "path", 0, 0, 0, PATH_HAVE_FCHMOD);
  486. int mode;
  487. int dir_fd = DEFAULT_DIR_FD;
  488. int follow_symlinks = 1;
  489. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  490. if (!args) {
  491. goto exit;
  492. }
  493. if (!path_converter(args[0], &path)) {
  494. goto exit;
  495. }
  496. mode = _PyLong_AsInt(args[1]);
  497. if (mode == -1 && PyErr_Occurred()) {
  498. goto exit;
  499. }
  500. if (!noptargs) {
  501. goto skip_optional_kwonly;
  502. }
  503. if (args[2]) {
  504. if (!FCHMODAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
  505. goto exit;
  506. }
  507. if (!--noptargs) {
  508. goto skip_optional_kwonly;
  509. }
  510. }
  511. follow_symlinks = PyObject_IsTrue(args[3]);
  512. if (follow_symlinks < 0) {
  513. goto exit;
  514. }
  515. skip_optional_kwonly:
  516. return_value = os_chmod_impl(module, &path, mode, dir_fd, follow_symlinks);
  517. exit:
  518. /* Cleanup for path */
  519. path_cleanup(&path);
  520. return return_value;
  521. }
  522. #if defined(HAVE_FCHMOD)
  523. PyDoc_STRVAR(os_fchmod__doc__,
  524. "fchmod($module, /, fd, mode)\n"
  525. "--\n"
  526. "\n"
  527. "Change the access permissions of the file given by file descriptor fd.\n"
  528. "\n"
  529. " fd\n"
  530. " The file descriptor of the file to be modified.\n"
  531. " mode\n"
  532. " Operating-system mode bitfield.\n"
  533. " Be careful when using number literals for *mode*. The conventional UNIX notation for\n"
  534. " numeric modes uses an octal base, which needs to be indicated with a ``0o`` prefix in\n"
  535. " Python.\n"
  536. "\n"
  537. "Equivalent to os.chmod(fd, mode).");
  538. #define OS_FCHMOD_METHODDEF \
  539. {"fchmod", _PyCFunction_CAST(os_fchmod), METH_FASTCALL|METH_KEYWORDS, os_fchmod__doc__},
  540. static PyObject *
  541. os_fchmod_impl(PyObject *module, int fd, int mode);
  542. static PyObject *
  543. os_fchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  544. {
  545. PyObject *return_value = NULL;
  546. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  547. #define NUM_KEYWORDS 2
  548. static struct {
  549. PyGC_Head _this_is_not_used;
  550. PyObject_VAR_HEAD
  551. PyObject *ob_item[NUM_KEYWORDS];
  552. } _kwtuple = {
  553. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  554. .ob_item = { &_Py_ID(fd), &_Py_ID(mode), },
  555. };
  556. #undef NUM_KEYWORDS
  557. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  558. #else // !Py_BUILD_CORE
  559. # define KWTUPLE NULL
  560. #endif // !Py_BUILD_CORE
  561. static const char * const _keywords[] = {"fd", "mode", NULL};
  562. static _PyArg_Parser _parser = {
  563. .keywords = _keywords,
  564. .fname = "fchmod",
  565. .kwtuple = KWTUPLE,
  566. };
  567. #undef KWTUPLE
  568. PyObject *argsbuf[2];
  569. int fd;
  570. int mode;
  571. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  572. if (!args) {
  573. goto exit;
  574. }
  575. fd = _PyLong_AsInt(args[0]);
  576. if (fd == -1 && PyErr_Occurred()) {
  577. goto exit;
  578. }
  579. mode = _PyLong_AsInt(args[1]);
  580. if (mode == -1 && PyErr_Occurred()) {
  581. goto exit;
  582. }
  583. return_value = os_fchmod_impl(module, fd, mode);
  584. exit:
  585. return return_value;
  586. }
  587. #endif /* defined(HAVE_FCHMOD) */
  588. #if defined(HAVE_LCHMOD)
  589. PyDoc_STRVAR(os_lchmod__doc__,
  590. "lchmod($module, /, path, mode)\n"
  591. "--\n"
  592. "\n"
  593. "Change the access permissions of a file, without following symbolic links.\n"
  594. "\n"
  595. "If path is a symlink, this affects the link itself rather than the target.\n"
  596. "Equivalent to chmod(path, mode, follow_symlinks=False).\"");
  597. #define OS_LCHMOD_METHODDEF \
  598. {"lchmod", _PyCFunction_CAST(os_lchmod), METH_FASTCALL|METH_KEYWORDS, os_lchmod__doc__},
  599. static PyObject *
  600. os_lchmod_impl(PyObject *module, path_t *path, int mode);
  601. static PyObject *
  602. os_lchmod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  603. {
  604. PyObject *return_value = NULL;
  605. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  606. #define NUM_KEYWORDS 2
  607. static struct {
  608. PyGC_Head _this_is_not_used;
  609. PyObject_VAR_HEAD
  610. PyObject *ob_item[NUM_KEYWORDS];
  611. } _kwtuple = {
  612. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  613. .ob_item = { &_Py_ID(path), &_Py_ID(mode), },
  614. };
  615. #undef NUM_KEYWORDS
  616. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  617. #else // !Py_BUILD_CORE
  618. # define KWTUPLE NULL
  619. #endif // !Py_BUILD_CORE
  620. static const char * const _keywords[] = {"path", "mode", NULL};
  621. static _PyArg_Parser _parser = {
  622. .keywords = _keywords,
  623. .fname = "lchmod",
  624. .kwtuple = KWTUPLE,
  625. };
  626. #undef KWTUPLE
  627. PyObject *argsbuf[2];
  628. path_t path = PATH_T_INITIALIZE_P("lchmod", "path", 0, 0, 0, 0);
  629. int mode;
  630. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  631. if (!args) {
  632. goto exit;
  633. }
  634. if (!path_converter(args[0], &path)) {
  635. goto exit;
  636. }
  637. mode = _PyLong_AsInt(args[1]);
  638. if (mode == -1 && PyErr_Occurred()) {
  639. goto exit;
  640. }
  641. return_value = os_lchmod_impl(module, &path, mode);
  642. exit:
  643. /* Cleanup for path */
  644. path_cleanup(&path);
  645. return return_value;
  646. }
  647. #endif /* defined(HAVE_LCHMOD) */
  648. #if defined(HAVE_CHFLAGS)
  649. PyDoc_STRVAR(os_chflags__doc__,
  650. "chflags($module, /, path, flags, follow_symlinks=True)\n"
  651. "--\n"
  652. "\n"
  653. "Set file flags.\n"
  654. "\n"
  655. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  656. " link, chflags will change flags on the symbolic link itself instead of the\n"
  657. " file the link points to.\n"
  658. "follow_symlinks may not be implemented on your platform. If it is\n"
  659. "unavailable, using it will raise a NotImplementedError.");
  660. #define OS_CHFLAGS_METHODDEF \
  661. {"chflags", _PyCFunction_CAST(os_chflags), METH_FASTCALL|METH_KEYWORDS, os_chflags__doc__},
  662. static PyObject *
  663. os_chflags_impl(PyObject *module, path_t *path, unsigned long flags,
  664. int follow_symlinks);
  665. static PyObject *
  666. os_chflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  667. {
  668. PyObject *return_value = NULL;
  669. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  670. #define NUM_KEYWORDS 3
  671. static struct {
  672. PyGC_Head _this_is_not_used;
  673. PyObject_VAR_HEAD
  674. PyObject *ob_item[NUM_KEYWORDS];
  675. } _kwtuple = {
  676. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  677. .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
  678. };
  679. #undef NUM_KEYWORDS
  680. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  681. #else // !Py_BUILD_CORE
  682. # define KWTUPLE NULL
  683. #endif // !Py_BUILD_CORE
  684. static const char * const _keywords[] = {"path", "flags", "follow_symlinks", NULL};
  685. static _PyArg_Parser _parser = {
  686. .keywords = _keywords,
  687. .fname = "chflags",
  688. .kwtuple = KWTUPLE,
  689. };
  690. #undef KWTUPLE
  691. PyObject *argsbuf[3];
  692. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  693. path_t path = PATH_T_INITIALIZE_P("chflags", "path", 0, 0, 0, 0);
  694. unsigned long flags;
  695. int follow_symlinks = 1;
  696. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  697. if (!args) {
  698. goto exit;
  699. }
  700. if (!path_converter(args[0], &path)) {
  701. goto exit;
  702. }
  703. if (!PyLong_Check(args[1])) {
  704. _PyArg_BadArgument("chflags", "argument 'flags'", "int", args[1]);
  705. goto exit;
  706. }
  707. flags = PyLong_AsUnsignedLongMask(args[1]);
  708. if (!noptargs) {
  709. goto skip_optional_pos;
  710. }
  711. follow_symlinks = PyObject_IsTrue(args[2]);
  712. if (follow_symlinks < 0) {
  713. goto exit;
  714. }
  715. skip_optional_pos:
  716. return_value = os_chflags_impl(module, &path, flags, follow_symlinks);
  717. exit:
  718. /* Cleanup for path */
  719. path_cleanup(&path);
  720. return return_value;
  721. }
  722. #endif /* defined(HAVE_CHFLAGS) */
  723. #if defined(HAVE_LCHFLAGS)
  724. PyDoc_STRVAR(os_lchflags__doc__,
  725. "lchflags($module, /, path, flags)\n"
  726. "--\n"
  727. "\n"
  728. "Set file flags.\n"
  729. "\n"
  730. "This function will not follow symbolic links.\n"
  731. "Equivalent to chflags(path, flags, follow_symlinks=False).");
  732. #define OS_LCHFLAGS_METHODDEF \
  733. {"lchflags", _PyCFunction_CAST(os_lchflags), METH_FASTCALL|METH_KEYWORDS, os_lchflags__doc__},
  734. static PyObject *
  735. os_lchflags_impl(PyObject *module, path_t *path, unsigned long flags);
  736. static PyObject *
  737. os_lchflags(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  738. {
  739. PyObject *return_value = NULL;
  740. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  741. #define NUM_KEYWORDS 2
  742. static struct {
  743. PyGC_Head _this_is_not_used;
  744. PyObject_VAR_HEAD
  745. PyObject *ob_item[NUM_KEYWORDS];
  746. } _kwtuple = {
  747. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  748. .ob_item = { &_Py_ID(path), &_Py_ID(flags), },
  749. };
  750. #undef NUM_KEYWORDS
  751. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  752. #else // !Py_BUILD_CORE
  753. # define KWTUPLE NULL
  754. #endif // !Py_BUILD_CORE
  755. static const char * const _keywords[] = {"path", "flags", NULL};
  756. static _PyArg_Parser _parser = {
  757. .keywords = _keywords,
  758. .fname = "lchflags",
  759. .kwtuple = KWTUPLE,
  760. };
  761. #undef KWTUPLE
  762. PyObject *argsbuf[2];
  763. path_t path = PATH_T_INITIALIZE_P("lchflags", "path", 0, 0, 0, 0);
  764. unsigned long flags;
  765. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  766. if (!args) {
  767. goto exit;
  768. }
  769. if (!path_converter(args[0], &path)) {
  770. goto exit;
  771. }
  772. if (!PyLong_Check(args[1])) {
  773. _PyArg_BadArgument("lchflags", "argument 'flags'", "int", args[1]);
  774. goto exit;
  775. }
  776. flags = PyLong_AsUnsignedLongMask(args[1]);
  777. return_value = os_lchflags_impl(module, &path, flags);
  778. exit:
  779. /* Cleanup for path */
  780. path_cleanup(&path);
  781. return return_value;
  782. }
  783. #endif /* defined(HAVE_LCHFLAGS) */
  784. #if defined(HAVE_CHROOT)
  785. PyDoc_STRVAR(os_chroot__doc__,
  786. "chroot($module, /, path)\n"
  787. "--\n"
  788. "\n"
  789. "Change root directory to path.");
  790. #define OS_CHROOT_METHODDEF \
  791. {"chroot", _PyCFunction_CAST(os_chroot), METH_FASTCALL|METH_KEYWORDS, os_chroot__doc__},
  792. static PyObject *
  793. os_chroot_impl(PyObject *module, path_t *path);
  794. static PyObject *
  795. os_chroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  796. {
  797. PyObject *return_value = NULL;
  798. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  799. #define NUM_KEYWORDS 1
  800. static struct {
  801. PyGC_Head _this_is_not_used;
  802. PyObject_VAR_HEAD
  803. PyObject *ob_item[NUM_KEYWORDS];
  804. } _kwtuple = {
  805. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  806. .ob_item = { &_Py_ID(path), },
  807. };
  808. #undef NUM_KEYWORDS
  809. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  810. #else // !Py_BUILD_CORE
  811. # define KWTUPLE NULL
  812. #endif // !Py_BUILD_CORE
  813. static const char * const _keywords[] = {"path", NULL};
  814. static _PyArg_Parser _parser = {
  815. .keywords = _keywords,
  816. .fname = "chroot",
  817. .kwtuple = KWTUPLE,
  818. };
  819. #undef KWTUPLE
  820. PyObject *argsbuf[1];
  821. path_t path = PATH_T_INITIALIZE_P("chroot", "path", 0, 0, 0, 0);
  822. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  823. if (!args) {
  824. goto exit;
  825. }
  826. if (!path_converter(args[0], &path)) {
  827. goto exit;
  828. }
  829. return_value = os_chroot_impl(module, &path);
  830. exit:
  831. /* Cleanup for path */
  832. path_cleanup(&path);
  833. return return_value;
  834. }
  835. #endif /* defined(HAVE_CHROOT) */
  836. #if defined(HAVE_FSYNC)
  837. PyDoc_STRVAR(os_fsync__doc__,
  838. "fsync($module, /, fd)\n"
  839. "--\n"
  840. "\n"
  841. "Force write of fd to disk.");
  842. #define OS_FSYNC_METHODDEF \
  843. {"fsync", _PyCFunction_CAST(os_fsync), METH_FASTCALL|METH_KEYWORDS, os_fsync__doc__},
  844. static PyObject *
  845. os_fsync_impl(PyObject *module, int fd);
  846. static PyObject *
  847. os_fsync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  848. {
  849. PyObject *return_value = NULL;
  850. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  851. #define NUM_KEYWORDS 1
  852. static struct {
  853. PyGC_Head _this_is_not_used;
  854. PyObject_VAR_HEAD
  855. PyObject *ob_item[NUM_KEYWORDS];
  856. } _kwtuple = {
  857. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  858. .ob_item = { &_Py_ID(fd), },
  859. };
  860. #undef NUM_KEYWORDS
  861. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  862. #else // !Py_BUILD_CORE
  863. # define KWTUPLE NULL
  864. #endif // !Py_BUILD_CORE
  865. static const char * const _keywords[] = {"fd", NULL};
  866. static _PyArg_Parser _parser = {
  867. .keywords = _keywords,
  868. .fname = "fsync",
  869. .kwtuple = KWTUPLE,
  870. };
  871. #undef KWTUPLE
  872. PyObject *argsbuf[1];
  873. int fd;
  874. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  875. if (!args) {
  876. goto exit;
  877. }
  878. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  879. goto exit;
  880. }
  881. return_value = os_fsync_impl(module, fd);
  882. exit:
  883. return return_value;
  884. }
  885. #endif /* defined(HAVE_FSYNC) */
  886. #if defined(HAVE_SYNC)
  887. PyDoc_STRVAR(os_sync__doc__,
  888. "sync($module, /)\n"
  889. "--\n"
  890. "\n"
  891. "Force write of everything to disk.");
  892. #define OS_SYNC_METHODDEF \
  893. {"sync", (PyCFunction)os_sync, METH_NOARGS, os_sync__doc__},
  894. static PyObject *
  895. os_sync_impl(PyObject *module);
  896. static PyObject *
  897. os_sync(PyObject *module, PyObject *Py_UNUSED(ignored))
  898. {
  899. return os_sync_impl(module);
  900. }
  901. #endif /* defined(HAVE_SYNC) */
  902. #if defined(HAVE_FDATASYNC)
  903. PyDoc_STRVAR(os_fdatasync__doc__,
  904. "fdatasync($module, /, fd)\n"
  905. "--\n"
  906. "\n"
  907. "Force write of fd to disk without forcing update of metadata.");
  908. #define OS_FDATASYNC_METHODDEF \
  909. {"fdatasync", _PyCFunction_CAST(os_fdatasync), METH_FASTCALL|METH_KEYWORDS, os_fdatasync__doc__},
  910. static PyObject *
  911. os_fdatasync_impl(PyObject *module, int fd);
  912. static PyObject *
  913. os_fdatasync(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  914. {
  915. PyObject *return_value = NULL;
  916. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  917. #define NUM_KEYWORDS 1
  918. static struct {
  919. PyGC_Head _this_is_not_used;
  920. PyObject_VAR_HEAD
  921. PyObject *ob_item[NUM_KEYWORDS];
  922. } _kwtuple = {
  923. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  924. .ob_item = { &_Py_ID(fd), },
  925. };
  926. #undef NUM_KEYWORDS
  927. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  928. #else // !Py_BUILD_CORE
  929. # define KWTUPLE NULL
  930. #endif // !Py_BUILD_CORE
  931. static const char * const _keywords[] = {"fd", NULL};
  932. static _PyArg_Parser _parser = {
  933. .keywords = _keywords,
  934. .fname = "fdatasync",
  935. .kwtuple = KWTUPLE,
  936. };
  937. #undef KWTUPLE
  938. PyObject *argsbuf[1];
  939. int fd;
  940. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  941. if (!args) {
  942. goto exit;
  943. }
  944. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  945. goto exit;
  946. }
  947. return_value = os_fdatasync_impl(module, fd);
  948. exit:
  949. return return_value;
  950. }
  951. #endif /* defined(HAVE_FDATASYNC) */
  952. #if defined(HAVE_CHOWN)
  953. PyDoc_STRVAR(os_chown__doc__,
  954. "chown($module, /, path, uid, gid, *, dir_fd=None, follow_symlinks=True)\n"
  955. "--\n"
  956. "\n"
  957. "Change the owner and group id of path to the numeric uid and gid.\\\n"
  958. "\n"
  959. " path\n"
  960. " Path to be examined; can be string, bytes, a path-like object, or open-file-descriptor int.\n"
  961. " dir_fd\n"
  962. " If not None, it should be a file descriptor open to a directory,\n"
  963. " and path should be relative; path will then be relative to that\n"
  964. " directory.\n"
  965. " follow_symlinks\n"
  966. " If False, and the last element of the path is a symbolic link,\n"
  967. " stat will examine the symbolic link itself instead of the file\n"
  968. " the link points to.\n"
  969. "\n"
  970. "path may always be specified as a string.\n"
  971. "On some platforms, path may also be specified as an open file descriptor.\n"
  972. " If this functionality is unavailable, using it raises an exception.\n"
  973. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  974. " and path should be relative; path will then be relative to that directory.\n"
  975. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  976. " link, chown will modify the symbolic link itself instead of the file the\n"
  977. " link points to.\n"
  978. "It is an error to use dir_fd or follow_symlinks when specifying path as\n"
  979. " an open file descriptor.\n"
  980. "dir_fd and follow_symlinks may not be implemented on your platform.\n"
  981. " If they are unavailable, using them will raise a NotImplementedError.");
  982. #define OS_CHOWN_METHODDEF \
  983. {"chown", _PyCFunction_CAST(os_chown), METH_FASTCALL|METH_KEYWORDS, os_chown__doc__},
  984. static PyObject *
  985. os_chown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid,
  986. int dir_fd, int follow_symlinks);
  987. static PyObject *
  988. os_chown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  989. {
  990. PyObject *return_value = NULL;
  991. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  992. #define NUM_KEYWORDS 5
  993. static struct {
  994. PyGC_Head _this_is_not_used;
  995. PyObject_VAR_HEAD
  996. PyObject *ob_item[NUM_KEYWORDS];
  997. } _kwtuple = {
  998. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  999. .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
  1000. };
  1001. #undef NUM_KEYWORDS
  1002. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1003. #else // !Py_BUILD_CORE
  1004. # define KWTUPLE NULL
  1005. #endif // !Py_BUILD_CORE
  1006. static const char * const _keywords[] = {"path", "uid", "gid", "dir_fd", "follow_symlinks", NULL};
  1007. static _PyArg_Parser _parser = {
  1008. .keywords = _keywords,
  1009. .fname = "chown",
  1010. .kwtuple = KWTUPLE,
  1011. };
  1012. #undef KWTUPLE
  1013. PyObject *argsbuf[5];
  1014. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  1015. path_t path = PATH_T_INITIALIZE_P("chown", "path", 0, 0, 0, PATH_HAVE_FCHOWN);
  1016. uid_t uid;
  1017. gid_t gid;
  1018. int dir_fd = DEFAULT_DIR_FD;
  1019. int follow_symlinks = 1;
  1020. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  1021. if (!args) {
  1022. goto exit;
  1023. }
  1024. if (!path_converter(args[0], &path)) {
  1025. goto exit;
  1026. }
  1027. if (!_Py_Uid_Converter(args[1], &uid)) {
  1028. goto exit;
  1029. }
  1030. if (!_Py_Gid_Converter(args[2], &gid)) {
  1031. goto exit;
  1032. }
  1033. if (!noptargs) {
  1034. goto skip_optional_kwonly;
  1035. }
  1036. if (args[3]) {
  1037. if (!FCHOWNAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
  1038. goto exit;
  1039. }
  1040. if (!--noptargs) {
  1041. goto skip_optional_kwonly;
  1042. }
  1043. }
  1044. follow_symlinks = PyObject_IsTrue(args[4]);
  1045. if (follow_symlinks < 0) {
  1046. goto exit;
  1047. }
  1048. skip_optional_kwonly:
  1049. return_value = os_chown_impl(module, &path, uid, gid, dir_fd, follow_symlinks);
  1050. exit:
  1051. /* Cleanup for path */
  1052. path_cleanup(&path);
  1053. return return_value;
  1054. }
  1055. #endif /* defined(HAVE_CHOWN) */
  1056. #if defined(HAVE_FCHOWN)
  1057. PyDoc_STRVAR(os_fchown__doc__,
  1058. "fchown($module, /, fd, uid, gid)\n"
  1059. "--\n"
  1060. "\n"
  1061. "Change the owner and group id of the file specified by file descriptor.\n"
  1062. "\n"
  1063. "Equivalent to os.chown(fd, uid, gid).");
  1064. #define OS_FCHOWN_METHODDEF \
  1065. {"fchown", _PyCFunction_CAST(os_fchown), METH_FASTCALL|METH_KEYWORDS, os_fchown__doc__},
  1066. static PyObject *
  1067. os_fchown_impl(PyObject *module, int fd, uid_t uid, gid_t gid);
  1068. static PyObject *
  1069. os_fchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1070. {
  1071. PyObject *return_value = NULL;
  1072. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1073. #define NUM_KEYWORDS 3
  1074. static struct {
  1075. PyGC_Head _this_is_not_used;
  1076. PyObject_VAR_HEAD
  1077. PyObject *ob_item[NUM_KEYWORDS];
  1078. } _kwtuple = {
  1079. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1080. .ob_item = { &_Py_ID(fd), &_Py_ID(uid), &_Py_ID(gid), },
  1081. };
  1082. #undef NUM_KEYWORDS
  1083. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1084. #else // !Py_BUILD_CORE
  1085. # define KWTUPLE NULL
  1086. #endif // !Py_BUILD_CORE
  1087. static const char * const _keywords[] = {"fd", "uid", "gid", NULL};
  1088. static _PyArg_Parser _parser = {
  1089. .keywords = _keywords,
  1090. .fname = "fchown",
  1091. .kwtuple = KWTUPLE,
  1092. };
  1093. #undef KWTUPLE
  1094. PyObject *argsbuf[3];
  1095. int fd;
  1096. uid_t uid;
  1097. gid_t gid;
  1098. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  1099. if (!args) {
  1100. goto exit;
  1101. }
  1102. fd = _PyLong_AsInt(args[0]);
  1103. if (fd == -1 && PyErr_Occurred()) {
  1104. goto exit;
  1105. }
  1106. if (!_Py_Uid_Converter(args[1], &uid)) {
  1107. goto exit;
  1108. }
  1109. if (!_Py_Gid_Converter(args[2], &gid)) {
  1110. goto exit;
  1111. }
  1112. return_value = os_fchown_impl(module, fd, uid, gid);
  1113. exit:
  1114. return return_value;
  1115. }
  1116. #endif /* defined(HAVE_FCHOWN) */
  1117. #if defined(HAVE_LCHOWN)
  1118. PyDoc_STRVAR(os_lchown__doc__,
  1119. "lchown($module, /, path, uid, gid)\n"
  1120. "--\n"
  1121. "\n"
  1122. "Change the owner and group id of path to the numeric uid and gid.\n"
  1123. "\n"
  1124. "This function will not follow symbolic links.\n"
  1125. "Equivalent to os.chown(path, uid, gid, follow_symlinks=False).");
  1126. #define OS_LCHOWN_METHODDEF \
  1127. {"lchown", _PyCFunction_CAST(os_lchown), METH_FASTCALL|METH_KEYWORDS, os_lchown__doc__},
  1128. static PyObject *
  1129. os_lchown_impl(PyObject *module, path_t *path, uid_t uid, gid_t gid);
  1130. static PyObject *
  1131. os_lchown(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1132. {
  1133. PyObject *return_value = NULL;
  1134. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1135. #define NUM_KEYWORDS 3
  1136. static struct {
  1137. PyGC_Head _this_is_not_used;
  1138. PyObject_VAR_HEAD
  1139. PyObject *ob_item[NUM_KEYWORDS];
  1140. } _kwtuple = {
  1141. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1142. .ob_item = { &_Py_ID(path), &_Py_ID(uid), &_Py_ID(gid), },
  1143. };
  1144. #undef NUM_KEYWORDS
  1145. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1146. #else // !Py_BUILD_CORE
  1147. # define KWTUPLE NULL
  1148. #endif // !Py_BUILD_CORE
  1149. static const char * const _keywords[] = {"path", "uid", "gid", NULL};
  1150. static _PyArg_Parser _parser = {
  1151. .keywords = _keywords,
  1152. .fname = "lchown",
  1153. .kwtuple = KWTUPLE,
  1154. };
  1155. #undef KWTUPLE
  1156. PyObject *argsbuf[3];
  1157. path_t path = PATH_T_INITIALIZE_P("lchown", "path", 0, 0, 0, 0);
  1158. uid_t uid;
  1159. gid_t gid;
  1160. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  1161. if (!args) {
  1162. goto exit;
  1163. }
  1164. if (!path_converter(args[0], &path)) {
  1165. goto exit;
  1166. }
  1167. if (!_Py_Uid_Converter(args[1], &uid)) {
  1168. goto exit;
  1169. }
  1170. if (!_Py_Gid_Converter(args[2], &gid)) {
  1171. goto exit;
  1172. }
  1173. return_value = os_lchown_impl(module, &path, uid, gid);
  1174. exit:
  1175. /* Cleanup for path */
  1176. path_cleanup(&path);
  1177. return return_value;
  1178. }
  1179. #endif /* defined(HAVE_LCHOWN) */
  1180. PyDoc_STRVAR(os_getcwd__doc__,
  1181. "getcwd($module, /)\n"
  1182. "--\n"
  1183. "\n"
  1184. "Return a unicode string representing the current working directory.");
  1185. #define OS_GETCWD_METHODDEF \
  1186. {"getcwd", (PyCFunction)os_getcwd, METH_NOARGS, os_getcwd__doc__},
  1187. static PyObject *
  1188. os_getcwd_impl(PyObject *module);
  1189. static PyObject *
  1190. os_getcwd(PyObject *module, PyObject *Py_UNUSED(ignored))
  1191. {
  1192. return os_getcwd_impl(module);
  1193. }
  1194. PyDoc_STRVAR(os_getcwdb__doc__,
  1195. "getcwdb($module, /)\n"
  1196. "--\n"
  1197. "\n"
  1198. "Return a bytes string representing the current working directory.");
  1199. #define OS_GETCWDB_METHODDEF \
  1200. {"getcwdb", (PyCFunction)os_getcwdb, METH_NOARGS, os_getcwdb__doc__},
  1201. static PyObject *
  1202. os_getcwdb_impl(PyObject *module);
  1203. static PyObject *
  1204. os_getcwdb(PyObject *module, PyObject *Py_UNUSED(ignored))
  1205. {
  1206. return os_getcwdb_impl(module);
  1207. }
  1208. #if defined(HAVE_LINK)
  1209. PyDoc_STRVAR(os_link__doc__,
  1210. "link($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None,\n"
  1211. " follow_symlinks=True)\n"
  1212. "--\n"
  1213. "\n"
  1214. "Create a hard link to a file.\n"
  1215. "\n"
  1216. "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
  1217. " descriptor open to a directory, and the respective path string (src or dst)\n"
  1218. " should be relative; the path will then be relative to that directory.\n"
  1219. "If follow_symlinks is False, and the last element of src is a symbolic\n"
  1220. " link, link will create a link to the symbolic link itself instead of the\n"
  1221. " file the link points to.\n"
  1222. "src_dir_fd, dst_dir_fd, and follow_symlinks may not be implemented on your\n"
  1223. " platform. If they are unavailable, using them will raise a\n"
  1224. " NotImplementedError.");
  1225. #define OS_LINK_METHODDEF \
  1226. {"link", _PyCFunction_CAST(os_link), METH_FASTCALL|METH_KEYWORDS, os_link__doc__},
  1227. static PyObject *
  1228. os_link_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
  1229. int dst_dir_fd, int follow_symlinks);
  1230. static PyObject *
  1231. os_link(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1232. {
  1233. PyObject *return_value = NULL;
  1234. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1235. #define NUM_KEYWORDS 5
  1236. static struct {
  1237. PyGC_Head _this_is_not_used;
  1238. PyObject_VAR_HEAD
  1239. PyObject *ob_item[NUM_KEYWORDS];
  1240. } _kwtuple = {
  1241. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1242. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), &_Py_ID(follow_symlinks), },
  1243. };
  1244. #undef NUM_KEYWORDS
  1245. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1246. #else // !Py_BUILD_CORE
  1247. # define KWTUPLE NULL
  1248. #endif // !Py_BUILD_CORE
  1249. static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", "follow_symlinks", NULL};
  1250. static _PyArg_Parser _parser = {
  1251. .keywords = _keywords,
  1252. .fname = "link",
  1253. .kwtuple = KWTUPLE,
  1254. };
  1255. #undef KWTUPLE
  1256. PyObject *argsbuf[5];
  1257. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  1258. path_t src = PATH_T_INITIALIZE_P("link", "src", 0, 0, 0, 0);
  1259. path_t dst = PATH_T_INITIALIZE_P("link", "dst", 0, 0, 0, 0);
  1260. int src_dir_fd = DEFAULT_DIR_FD;
  1261. int dst_dir_fd = DEFAULT_DIR_FD;
  1262. int follow_symlinks = 1;
  1263. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  1264. if (!args) {
  1265. goto exit;
  1266. }
  1267. if (!path_converter(args[0], &src)) {
  1268. goto exit;
  1269. }
  1270. if (!path_converter(args[1], &dst)) {
  1271. goto exit;
  1272. }
  1273. if (!noptargs) {
  1274. goto skip_optional_kwonly;
  1275. }
  1276. if (args[2]) {
  1277. if (!dir_fd_converter(args[2], &src_dir_fd)) {
  1278. goto exit;
  1279. }
  1280. if (!--noptargs) {
  1281. goto skip_optional_kwonly;
  1282. }
  1283. }
  1284. if (args[3]) {
  1285. if (!dir_fd_converter(args[3], &dst_dir_fd)) {
  1286. goto exit;
  1287. }
  1288. if (!--noptargs) {
  1289. goto skip_optional_kwonly;
  1290. }
  1291. }
  1292. follow_symlinks = PyObject_IsTrue(args[4]);
  1293. if (follow_symlinks < 0) {
  1294. goto exit;
  1295. }
  1296. skip_optional_kwonly:
  1297. return_value = os_link_impl(module, &src, &dst, src_dir_fd, dst_dir_fd, follow_symlinks);
  1298. exit:
  1299. /* Cleanup for src */
  1300. path_cleanup(&src);
  1301. /* Cleanup for dst */
  1302. path_cleanup(&dst);
  1303. return return_value;
  1304. }
  1305. #endif /* defined(HAVE_LINK) */
  1306. PyDoc_STRVAR(os_listdir__doc__,
  1307. "listdir($module, /, path=None)\n"
  1308. "--\n"
  1309. "\n"
  1310. "Return a list containing the names of the files in the directory.\n"
  1311. "\n"
  1312. "path can be specified as either str, bytes, or a path-like object. If path is bytes,\n"
  1313. " the filenames returned will also be bytes; in all other circumstances\n"
  1314. " the filenames returned will be str.\n"
  1315. "If path is None, uses the path=\'.\'.\n"
  1316. "On some platforms, path may also be specified as an open file descriptor;\\\n"
  1317. " the file descriptor must refer to a directory.\n"
  1318. " If this functionality is unavailable, using it raises NotImplementedError.\n"
  1319. "\n"
  1320. "The list is in arbitrary order. It does not include the special\n"
  1321. "entries \'.\' and \'..\' even if they are present in the directory.");
  1322. #define OS_LISTDIR_METHODDEF \
  1323. {"listdir", _PyCFunction_CAST(os_listdir), METH_FASTCALL|METH_KEYWORDS, os_listdir__doc__},
  1324. static PyObject *
  1325. os_listdir_impl(PyObject *module, path_t *path);
  1326. static PyObject *
  1327. os_listdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1328. {
  1329. PyObject *return_value = NULL;
  1330. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1331. #define NUM_KEYWORDS 1
  1332. static struct {
  1333. PyGC_Head _this_is_not_used;
  1334. PyObject_VAR_HEAD
  1335. PyObject *ob_item[NUM_KEYWORDS];
  1336. } _kwtuple = {
  1337. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1338. .ob_item = { &_Py_ID(path), },
  1339. };
  1340. #undef NUM_KEYWORDS
  1341. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1342. #else // !Py_BUILD_CORE
  1343. # define KWTUPLE NULL
  1344. #endif // !Py_BUILD_CORE
  1345. static const char * const _keywords[] = {"path", NULL};
  1346. static _PyArg_Parser _parser = {
  1347. .keywords = _keywords,
  1348. .fname = "listdir",
  1349. .kwtuple = KWTUPLE,
  1350. };
  1351. #undef KWTUPLE
  1352. PyObject *argsbuf[1];
  1353. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  1354. path_t path = PATH_T_INITIALIZE_P("listdir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
  1355. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  1356. if (!args) {
  1357. goto exit;
  1358. }
  1359. if (!noptargs) {
  1360. goto skip_optional_pos;
  1361. }
  1362. if (!path_converter(args[0], &path)) {
  1363. goto exit;
  1364. }
  1365. skip_optional_pos:
  1366. return_value = os_listdir_impl(module, &path);
  1367. exit:
  1368. /* Cleanup for path */
  1369. path_cleanup(&path);
  1370. return return_value;
  1371. }
  1372. #if defined(MS_WINDOWS)
  1373. PyDoc_STRVAR(os_listdrives__doc__,
  1374. "listdrives($module, /)\n"
  1375. "--\n"
  1376. "\n"
  1377. "Return a list containing the names of drives in the system.\n"
  1378. "\n"
  1379. "A drive name typically looks like \'C:\\\\\'.");
  1380. #define OS_LISTDRIVES_METHODDEF \
  1381. {"listdrives", (PyCFunction)os_listdrives, METH_NOARGS, os_listdrives__doc__},
  1382. static PyObject *
  1383. os_listdrives_impl(PyObject *module);
  1384. static PyObject *
  1385. os_listdrives(PyObject *module, PyObject *Py_UNUSED(ignored))
  1386. {
  1387. return os_listdrives_impl(module);
  1388. }
  1389. #endif /* defined(MS_WINDOWS) */
  1390. #if defined(MS_WINDOWS)
  1391. PyDoc_STRVAR(os_listvolumes__doc__,
  1392. "listvolumes($module, /)\n"
  1393. "--\n"
  1394. "\n"
  1395. "Return a list containing the volumes in the system.\n"
  1396. "\n"
  1397. "Volumes are typically represented as a GUID path.");
  1398. #define OS_LISTVOLUMES_METHODDEF \
  1399. {"listvolumes", (PyCFunction)os_listvolumes, METH_NOARGS, os_listvolumes__doc__},
  1400. static PyObject *
  1401. os_listvolumes_impl(PyObject *module);
  1402. static PyObject *
  1403. os_listvolumes(PyObject *module, PyObject *Py_UNUSED(ignored))
  1404. {
  1405. return os_listvolumes_impl(module);
  1406. }
  1407. #endif /* defined(MS_WINDOWS) */
  1408. #if defined(MS_WINDOWS)
  1409. PyDoc_STRVAR(os_listmounts__doc__,
  1410. "listmounts($module, /, volume)\n"
  1411. "--\n"
  1412. "\n"
  1413. "Return a list containing mount points for a particular volume.\n"
  1414. "\n"
  1415. "\'volume\' should be a GUID path as returned from os.listvolumes.");
  1416. #define OS_LISTMOUNTS_METHODDEF \
  1417. {"listmounts", _PyCFunction_CAST(os_listmounts), METH_FASTCALL|METH_KEYWORDS, os_listmounts__doc__},
  1418. static PyObject *
  1419. os_listmounts_impl(PyObject *module, path_t *volume);
  1420. static PyObject *
  1421. os_listmounts(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1422. {
  1423. PyObject *return_value = NULL;
  1424. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1425. #define NUM_KEYWORDS 1
  1426. static struct {
  1427. PyGC_Head _this_is_not_used;
  1428. PyObject_VAR_HEAD
  1429. PyObject *ob_item[NUM_KEYWORDS];
  1430. } _kwtuple = {
  1431. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1432. .ob_item = { &_Py_ID(volume), },
  1433. };
  1434. #undef NUM_KEYWORDS
  1435. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1436. #else // !Py_BUILD_CORE
  1437. # define KWTUPLE NULL
  1438. #endif // !Py_BUILD_CORE
  1439. static const char * const _keywords[] = {"volume", NULL};
  1440. static _PyArg_Parser _parser = {
  1441. .keywords = _keywords,
  1442. .fname = "listmounts",
  1443. .kwtuple = KWTUPLE,
  1444. };
  1445. #undef KWTUPLE
  1446. PyObject *argsbuf[1];
  1447. path_t volume = PATH_T_INITIALIZE_P("listmounts", "volume", 0, 0, 0, 0);
  1448. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1449. if (!args) {
  1450. goto exit;
  1451. }
  1452. if (!path_converter(args[0], &volume)) {
  1453. goto exit;
  1454. }
  1455. return_value = os_listmounts_impl(module, &volume);
  1456. exit:
  1457. /* Cleanup for volume */
  1458. path_cleanup(&volume);
  1459. return return_value;
  1460. }
  1461. #endif /* defined(MS_WINDOWS) */
  1462. #if defined(MS_WINDOWS)
  1463. PyDoc_STRVAR(os__path_isdevdrive__doc__,
  1464. "_path_isdevdrive($module, /, path)\n"
  1465. "--\n"
  1466. "\n"
  1467. "Determines whether the specified path is on a Windows Dev Drive.");
  1468. #define OS__PATH_ISDEVDRIVE_METHODDEF \
  1469. {"_path_isdevdrive", _PyCFunction_CAST(os__path_isdevdrive), METH_FASTCALL|METH_KEYWORDS, os__path_isdevdrive__doc__},
  1470. static PyObject *
  1471. os__path_isdevdrive_impl(PyObject *module, path_t *path);
  1472. static PyObject *
  1473. os__path_isdevdrive(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1474. {
  1475. PyObject *return_value = NULL;
  1476. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1477. #define NUM_KEYWORDS 1
  1478. static struct {
  1479. PyGC_Head _this_is_not_used;
  1480. PyObject_VAR_HEAD
  1481. PyObject *ob_item[NUM_KEYWORDS];
  1482. } _kwtuple = {
  1483. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1484. .ob_item = { &_Py_ID(path), },
  1485. };
  1486. #undef NUM_KEYWORDS
  1487. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1488. #else // !Py_BUILD_CORE
  1489. # define KWTUPLE NULL
  1490. #endif // !Py_BUILD_CORE
  1491. static const char * const _keywords[] = {"path", NULL};
  1492. static _PyArg_Parser _parser = {
  1493. .keywords = _keywords,
  1494. .fname = "_path_isdevdrive",
  1495. .kwtuple = KWTUPLE,
  1496. };
  1497. #undef KWTUPLE
  1498. PyObject *argsbuf[1];
  1499. path_t path = PATH_T_INITIALIZE_P("_path_isdevdrive", "path", 0, 0, 0, 0);
  1500. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1501. if (!args) {
  1502. goto exit;
  1503. }
  1504. if (!path_converter(args[0], &path)) {
  1505. goto exit;
  1506. }
  1507. return_value = os__path_isdevdrive_impl(module, &path);
  1508. exit:
  1509. /* Cleanup for path */
  1510. path_cleanup(&path);
  1511. return return_value;
  1512. }
  1513. #endif /* defined(MS_WINDOWS) */
  1514. #if defined(MS_WINDOWS)
  1515. PyDoc_STRVAR(os__getfullpathname__doc__,
  1516. "_getfullpathname($module, path, /)\n"
  1517. "--\n"
  1518. "\n");
  1519. #define OS__GETFULLPATHNAME_METHODDEF \
  1520. {"_getfullpathname", (PyCFunction)os__getfullpathname, METH_O, os__getfullpathname__doc__},
  1521. static PyObject *
  1522. os__getfullpathname_impl(PyObject *module, path_t *path);
  1523. static PyObject *
  1524. os__getfullpathname(PyObject *module, PyObject *arg)
  1525. {
  1526. PyObject *return_value = NULL;
  1527. path_t path = PATH_T_INITIALIZE_P("_getfullpathname", "path", 0, 0, 0, 0);
  1528. if (!path_converter(arg, &path)) {
  1529. goto exit;
  1530. }
  1531. return_value = os__getfullpathname_impl(module, &path);
  1532. exit:
  1533. /* Cleanup for path */
  1534. path_cleanup(&path);
  1535. return return_value;
  1536. }
  1537. #endif /* defined(MS_WINDOWS) */
  1538. #if defined(MS_WINDOWS)
  1539. PyDoc_STRVAR(os__getfinalpathname__doc__,
  1540. "_getfinalpathname($module, path, /)\n"
  1541. "--\n"
  1542. "\n"
  1543. "A helper function for samepath on windows.");
  1544. #define OS__GETFINALPATHNAME_METHODDEF \
  1545. {"_getfinalpathname", (PyCFunction)os__getfinalpathname, METH_O, os__getfinalpathname__doc__},
  1546. static PyObject *
  1547. os__getfinalpathname_impl(PyObject *module, path_t *path);
  1548. static PyObject *
  1549. os__getfinalpathname(PyObject *module, PyObject *arg)
  1550. {
  1551. PyObject *return_value = NULL;
  1552. path_t path = PATH_T_INITIALIZE_P("_getfinalpathname", "path", 0, 0, 0, 0);
  1553. if (!path_converter(arg, &path)) {
  1554. goto exit;
  1555. }
  1556. return_value = os__getfinalpathname_impl(module, &path);
  1557. exit:
  1558. /* Cleanup for path */
  1559. path_cleanup(&path);
  1560. return return_value;
  1561. }
  1562. #endif /* defined(MS_WINDOWS) */
  1563. #if defined(MS_WINDOWS)
  1564. PyDoc_STRVAR(os__getvolumepathname__doc__,
  1565. "_getvolumepathname($module, /, path)\n"
  1566. "--\n"
  1567. "\n"
  1568. "A helper function for ismount on Win32.");
  1569. #define OS__GETVOLUMEPATHNAME_METHODDEF \
  1570. {"_getvolumepathname", _PyCFunction_CAST(os__getvolumepathname), METH_FASTCALL|METH_KEYWORDS, os__getvolumepathname__doc__},
  1571. static PyObject *
  1572. os__getvolumepathname_impl(PyObject *module, path_t *path);
  1573. static PyObject *
  1574. os__getvolumepathname(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1575. {
  1576. PyObject *return_value = NULL;
  1577. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1578. #define NUM_KEYWORDS 1
  1579. static struct {
  1580. PyGC_Head _this_is_not_used;
  1581. PyObject_VAR_HEAD
  1582. PyObject *ob_item[NUM_KEYWORDS];
  1583. } _kwtuple = {
  1584. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1585. .ob_item = { &_Py_ID(path), },
  1586. };
  1587. #undef NUM_KEYWORDS
  1588. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1589. #else // !Py_BUILD_CORE
  1590. # define KWTUPLE NULL
  1591. #endif // !Py_BUILD_CORE
  1592. static const char * const _keywords[] = {"path", NULL};
  1593. static _PyArg_Parser _parser = {
  1594. .keywords = _keywords,
  1595. .fname = "_getvolumepathname",
  1596. .kwtuple = KWTUPLE,
  1597. };
  1598. #undef KWTUPLE
  1599. PyObject *argsbuf[1];
  1600. path_t path = PATH_T_INITIALIZE_P("_getvolumepathname", "path", 0, 0, 0, 0);
  1601. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1602. if (!args) {
  1603. goto exit;
  1604. }
  1605. if (!path_converter(args[0], &path)) {
  1606. goto exit;
  1607. }
  1608. return_value = os__getvolumepathname_impl(module, &path);
  1609. exit:
  1610. /* Cleanup for path */
  1611. path_cleanup(&path);
  1612. return return_value;
  1613. }
  1614. #endif /* defined(MS_WINDOWS) */
  1615. #if defined(MS_WINDOWS)
  1616. PyDoc_STRVAR(os__path_splitroot__doc__,
  1617. "_path_splitroot($module, /, path)\n"
  1618. "--\n"
  1619. "\n"
  1620. "Removes everything after the root on Win32.");
  1621. #define OS__PATH_SPLITROOT_METHODDEF \
  1622. {"_path_splitroot", _PyCFunction_CAST(os__path_splitroot), METH_FASTCALL|METH_KEYWORDS, os__path_splitroot__doc__},
  1623. static PyObject *
  1624. os__path_splitroot_impl(PyObject *module, path_t *path);
  1625. static PyObject *
  1626. os__path_splitroot(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1627. {
  1628. PyObject *return_value = NULL;
  1629. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1630. #define NUM_KEYWORDS 1
  1631. static struct {
  1632. PyGC_Head _this_is_not_used;
  1633. PyObject_VAR_HEAD
  1634. PyObject *ob_item[NUM_KEYWORDS];
  1635. } _kwtuple = {
  1636. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1637. .ob_item = { &_Py_ID(path), },
  1638. };
  1639. #undef NUM_KEYWORDS
  1640. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1641. #else // !Py_BUILD_CORE
  1642. # define KWTUPLE NULL
  1643. #endif // !Py_BUILD_CORE
  1644. static const char * const _keywords[] = {"path", NULL};
  1645. static _PyArg_Parser _parser = {
  1646. .keywords = _keywords,
  1647. .fname = "_path_splitroot",
  1648. .kwtuple = KWTUPLE,
  1649. };
  1650. #undef KWTUPLE
  1651. PyObject *argsbuf[1];
  1652. path_t path = PATH_T_INITIALIZE_P("_path_splitroot", "path", 0, 0, 0, 0);
  1653. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1654. if (!args) {
  1655. goto exit;
  1656. }
  1657. if (!path_converter(args[0], &path)) {
  1658. goto exit;
  1659. }
  1660. return_value = os__path_splitroot_impl(module, &path);
  1661. exit:
  1662. /* Cleanup for path */
  1663. path_cleanup(&path);
  1664. return return_value;
  1665. }
  1666. #endif /* defined(MS_WINDOWS) */
  1667. #if defined(MS_WINDOWS)
  1668. PyDoc_STRVAR(os__path_exists__doc__,
  1669. "_path_exists($module, path, /)\n"
  1670. "--\n"
  1671. "\n"
  1672. "Test whether a path exists. Returns False for broken symbolic links.");
  1673. #define OS__PATH_EXISTS_METHODDEF \
  1674. {"_path_exists", (PyCFunction)os__path_exists, METH_O, os__path_exists__doc__},
  1675. static int
  1676. os__path_exists_impl(PyObject *module, path_t *path);
  1677. static PyObject *
  1678. os__path_exists(PyObject *module, PyObject *arg)
  1679. {
  1680. PyObject *return_value = NULL;
  1681. path_t path = PATH_T_INITIALIZE_P("_path_exists", "path", 0, 0, 1, 1);
  1682. int _return_value;
  1683. if (!path_converter(arg, &path)) {
  1684. goto exit;
  1685. }
  1686. _return_value = os__path_exists_impl(module, &path);
  1687. if ((_return_value == -1) && PyErr_Occurred()) {
  1688. goto exit;
  1689. }
  1690. return_value = PyBool_FromLong((long)_return_value);
  1691. exit:
  1692. /* Cleanup for path */
  1693. path_cleanup(&path);
  1694. return return_value;
  1695. }
  1696. #endif /* defined(MS_WINDOWS) */
  1697. #if defined(MS_WINDOWS)
  1698. PyDoc_STRVAR(os__path_isdir__doc__,
  1699. "_path_isdir($module, /, s)\n"
  1700. "--\n"
  1701. "\n"
  1702. "Return true if the pathname refers to an existing directory.");
  1703. #define OS__PATH_ISDIR_METHODDEF \
  1704. {"_path_isdir", _PyCFunction_CAST(os__path_isdir), METH_FASTCALL|METH_KEYWORDS, os__path_isdir__doc__},
  1705. static int
  1706. os__path_isdir_impl(PyObject *module, path_t *path);
  1707. static PyObject *
  1708. os__path_isdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1709. {
  1710. PyObject *return_value = NULL;
  1711. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1712. #define NUM_KEYWORDS 1
  1713. static struct {
  1714. PyGC_Head _this_is_not_used;
  1715. PyObject_VAR_HEAD
  1716. PyObject *ob_item[NUM_KEYWORDS];
  1717. } _kwtuple = {
  1718. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1719. .ob_item = { &_Py_ID(s), },
  1720. };
  1721. #undef NUM_KEYWORDS
  1722. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1723. #else // !Py_BUILD_CORE
  1724. # define KWTUPLE NULL
  1725. #endif // !Py_BUILD_CORE
  1726. static const char * const _keywords[] = {"s", NULL};
  1727. static _PyArg_Parser _parser = {
  1728. .keywords = _keywords,
  1729. .fname = "_path_isdir",
  1730. .kwtuple = KWTUPLE,
  1731. };
  1732. #undef KWTUPLE
  1733. PyObject *argsbuf[1];
  1734. path_t path = PATH_T_INITIALIZE_P("_path_isdir", "path", 0, 0, 1, 1);
  1735. int _return_value;
  1736. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1737. if (!args) {
  1738. goto exit;
  1739. }
  1740. if (!path_converter(args[0], &path)) {
  1741. goto exit;
  1742. }
  1743. _return_value = os__path_isdir_impl(module, &path);
  1744. if ((_return_value == -1) && PyErr_Occurred()) {
  1745. goto exit;
  1746. }
  1747. return_value = PyBool_FromLong((long)_return_value);
  1748. exit:
  1749. /* Cleanup for path */
  1750. path_cleanup(&path);
  1751. return return_value;
  1752. }
  1753. #endif /* defined(MS_WINDOWS) */
  1754. #if defined(MS_WINDOWS)
  1755. PyDoc_STRVAR(os__path_isfile__doc__,
  1756. "_path_isfile($module, /, path)\n"
  1757. "--\n"
  1758. "\n"
  1759. "Test whether a path is a regular file");
  1760. #define OS__PATH_ISFILE_METHODDEF \
  1761. {"_path_isfile", _PyCFunction_CAST(os__path_isfile), METH_FASTCALL|METH_KEYWORDS, os__path_isfile__doc__},
  1762. static int
  1763. os__path_isfile_impl(PyObject *module, path_t *path);
  1764. static PyObject *
  1765. os__path_isfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1766. {
  1767. PyObject *return_value = NULL;
  1768. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1769. #define NUM_KEYWORDS 1
  1770. static struct {
  1771. PyGC_Head _this_is_not_used;
  1772. PyObject_VAR_HEAD
  1773. PyObject *ob_item[NUM_KEYWORDS];
  1774. } _kwtuple = {
  1775. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1776. .ob_item = { &_Py_ID(path), },
  1777. };
  1778. #undef NUM_KEYWORDS
  1779. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1780. #else // !Py_BUILD_CORE
  1781. # define KWTUPLE NULL
  1782. #endif // !Py_BUILD_CORE
  1783. static const char * const _keywords[] = {"path", NULL};
  1784. static _PyArg_Parser _parser = {
  1785. .keywords = _keywords,
  1786. .fname = "_path_isfile",
  1787. .kwtuple = KWTUPLE,
  1788. };
  1789. #undef KWTUPLE
  1790. PyObject *argsbuf[1];
  1791. path_t path = PATH_T_INITIALIZE_P("_path_isfile", "path", 0, 0, 1, 1);
  1792. int _return_value;
  1793. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1794. if (!args) {
  1795. goto exit;
  1796. }
  1797. if (!path_converter(args[0], &path)) {
  1798. goto exit;
  1799. }
  1800. _return_value = os__path_isfile_impl(module, &path);
  1801. if ((_return_value == -1) && PyErr_Occurred()) {
  1802. goto exit;
  1803. }
  1804. return_value = PyBool_FromLong((long)_return_value);
  1805. exit:
  1806. /* Cleanup for path */
  1807. path_cleanup(&path);
  1808. return return_value;
  1809. }
  1810. #endif /* defined(MS_WINDOWS) */
  1811. #if defined(MS_WINDOWS)
  1812. PyDoc_STRVAR(os__path_islink__doc__,
  1813. "_path_islink($module, /, path)\n"
  1814. "--\n"
  1815. "\n"
  1816. "Test whether a path is a symbolic link");
  1817. #define OS__PATH_ISLINK_METHODDEF \
  1818. {"_path_islink", _PyCFunction_CAST(os__path_islink), METH_FASTCALL|METH_KEYWORDS, os__path_islink__doc__},
  1819. static int
  1820. os__path_islink_impl(PyObject *module, path_t *path);
  1821. static PyObject *
  1822. os__path_islink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1823. {
  1824. PyObject *return_value = NULL;
  1825. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1826. #define NUM_KEYWORDS 1
  1827. static struct {
  1828. PyGC_Head _this_is_not_used;
  1829. PyObject_VAR_HEAD
  1830. PyObject *ob_item[NUM_KEYWORDS];
  1831. } _kwtuple = {
  1832. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1833. .ob_item = { &_Py_ID(path), },
  1834. };
  1835. #undef NUM_KEYWORDS
  1836. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1837. #else // !Py_BUILD_CORE
  1838. # define KWTUPLE NULL
  1839. #endif // !Py_BUILD_CORE
  1840. static const char * const _keywords[] = {"path", NULL};
  1841. static _PyArg_Parser _parser = {
  1842. .keywords = _keywords,
  1843. .fname = "_path_islink",
  1844. .kwtuple = KWTUPLE,
  1845. };
  1846. #undef KWTUPLE
  1847. PyObject *argsbuf[1];
  1848. path_t path = PATH_T_INITIALIZE_P("_path_islink", "path", 0, 0, 1, 1);
  1849. int _return_value;
  1850. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1851. if (!args) {
  1852. goto exit;
  1853. }
  1854. if (!path_converter(args[0], &path)) {
  1855. goto exit;
  1856. }
  1857. _return_value = os__path_islink_impl(module, &path);
  1858. if ((_return_value == -1) && PyErr_Occurred()) {
  1859. goto exit;
  1860. }
  1861. return_value = PyBool_FromLong((long)_return_value);
  1862. exit:
  1863. /* Cleanup for path */
  1864. path_cleanup(&path);
  1865. return return_value;
  1866. }
  1867. #endif /* defined(MS_WINDOWS) */
  1868. PyDoc_STRVAR(os__path_normpath__doc__,
  1869. "_path_normpath($module, /, path)\n"
  1870. "--\n"
  1871. "\n"
  1872. "Normalize path, eliminating double slashes, etc.");
  1873. #define OS__PATH_NORMPATH_METHODDEF \
  1874. {"_path_normpath", _PyCFunction_CAST(os__path_normpath), METH_FASTCALL|METH_KEYWORDS, os__path_normpath__doc__},
  1875. static PyObject *
  1876. os__path_normpath_impl(PyObject *module, path_t *path);
  1877. static PyObject *
  1878. os__path_normpath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1879. {
  1880. PyObject *return_value = NULL;
  1881. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1882. #define NUM_KEYWORDS 1
  1883. static struct {
  1884. PyGC_Head _this_is_not_used;
  1885. PyObject_VAR_HEAD
  1886. PyObject *ob_item[NUM_KEYWORDS];
  1887. } _kwtuple = {
  1888. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1889. .ob_item = { &_Py_ID(path), },
  1890. };
  1891. #undef NUM_KEYWORDS
  1892. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1893. #else // !Py_BUILD_CORE
  1894. # define KWTUPLE NULL
  1895. #endif // !Py_BUILD_CORE
  1896. static const char * const _keywords[] = {"path", NULL};
  1897. static _PyArg_Parser _parser = {
  1898. .keywords = _keywords,
  1899. .fname = "_path_normpath",
  1900. .kwtuple = KWTUPLE,
  1901. };
  1902. #undef KWTUPLE
  1903. PyObject *argsbuf[1];
  1904. path_t path = PATH_T_INITIALIZE("_path_normpath", "path", 0, 1, 1, 0, 0);
  1905. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  1906. if (!args) {
  1907. goto exit;
  1908. }
  1909. if (!path_converter(args[0], &path)) {
  1910. goto exit;
  1911. }
  1912. return_value = os__path_normpath_impl(module, &path);
  1913. exit:
  1914. /* Cleanup for path */
  1915. path_cleanup(&path);
  1916. return return_value;
  1917. }
  1918. PyDoc_STRVAR(os_mkdir__doc__,
  1919. "mkdir($module, /, path, mode=511, *, dir_fd=None)\n"
  1920. "--\n"
  1921. "\n"
  1922. "Create a directory.\n"
  1923. "\n"
  1924. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  1925. " and path should be relative; path will then be relative to that directory.\n"
  1926. "dir_fd may not be implemented on your platform.\n"
  1927. " If it is unavailable, using it will raise a NotImplementedError.\n"
  1928. "\n"
  1929. "The mode argument is ignored on Windows. Where it is used, the current umask\n"
  1930. "value is first masked out.");
  1931. #define OS_MKDIR_METHODDEF \
  1932. {"mkdir", _PyCFunction_CAST(os_mkdir), METH_FASTCALL|METH_KEYWORDS, os_mkdir__doc__},
  1933. static PyObject *
  1934. os_mkdir_impl(PyObject *module, path_t *path, int mode, int dir_fd);
  1935. static PyObject *
  1936. os_mkdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  1937. {
  1938. PyObject *return_value = NULL;
  1939. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  1940. #define NUM_KEYWORDS 3
  1941. static struct {
  1942. PyGC_Head _this_is_not_used;
  1943. PyObject_VAR_HEAD
  1944. PyObject *ob_item[NUM_KEYWORDS];
  1945. } _kwtuple = {
  1946. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  1947. .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
  1948. };
  1949. #undef NUM_KEYWORDS
  1950. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  1951. #else // !Py_BUILD_CORE
  1952. # define KWTUPLE NULL
  1953. #endif // !Py_BUILD_CORE
  1954. static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
  1955. static _PyArg_Parser _parser = {
  1956. .keywords = _keywords,
  1957. .fname = "mkdir",
  1958. .kwtuple = KWTUPLE,
  1959. };
  1960. #undef KWTUPLE
  1961. PyObject *argsbuf[3];
  1962. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  1963. path_t path = PATH_T_INITIALIZE_P("mkdir", "path", 0, 0, 0, 0);
  1964. int mode = 511;
  1965. int dir_fd = DEFAULT_DIR_FD;
  1966. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  1967. if (!args) {
  1968. goto exit;
  1969. }
  1970. if (!path_converter(args[0], &path)) {
  1971. goto exit;
  1972. }
  1973. if (!noptargs) {
  1974. goto skip_optional_pos;
  1975. }
  1976. if (args[1]) {
  1977. mode = _PyLong_AsInt(args[1]);
  1978. if (mode == -1 && PyErr_Occurred()) {
  1979. goto exit;
  1980. }
  1981. if (!--noptargs) {
  1982. goto skip_optional_pos;
  1983. }
  1984. }
  1985. skip_optional_pos:
  1986. if (!noptargs) {
  1987. goto skip_optional_kwonly;
  1988. }
  1989. if (!MKDIRAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
  1990. goto exit;
  1991. }
  1992. skip_optional_kwonly:
  1993. return_value = os_mkdir_impl(module, &path, mode, dir_fd);
  1994. exit:
  1995. /* Cleanup for path */
  1996. path_cleanup(&path);
  1997. return return_value;
  1998. }
  1999. #if defined(HAVE_NICE)
  2000. PyDoc_STRVAR(os_nice__doc__,
  2001. "nice($module, increment, /)\n"
  2002. "--\n"
  2003. "\n"
  2004. "Add increment to the priority of process and return the new priority.");
  2005. #define OS_NICE_METHODDEF \
  2006. {"nice", (PyCFunction)os_nice, METH_O, os_nice__doc__},
  2007. static PyObject *
  2008. os_nice_impl(PyObject *module, int increment);
  2009. static PyObject *
  2010. os_nice(PyObject *module, PyObject *arg)
  2011. {
  2012. PyObject *return_value = NULL;
  2013. int increment;
  2014. increment = _PyLong_AsInt(arg);
  2015. if (increment == -1 && PyErr_Occurred()) {
  2016. goto exit;
  2017. }
  2018. return_value = os_nice_impl(module, increment);
  2019. exit:
  2020. return return_value;
  2021. }
  2022. #endif /* defined(HAVE_NICE) */
  2023. #if defined(HAVE_GETPRIORITY)
  2024. PyDoc_STRVAR(os_getpriority__doc__,
  2025. "getpriority($module, /, which, who)\n"
  2026. "--\n"
  2027. "\n"
  2028. "Return program scheduling priority.");
  2029. #define OS_GETPRIORITY_METHODDEF \
  2030. {"getpriority", _PyCFunction_CAST(os_getpriority), METH_FASTCALL|METH_KEYWORDS, os_getpriority__doc__},
  2031. static PyObject *
  2032. os_getpriority_impl(PyObject *module, int which, int who);
  2033. static PyObject *
  2034. os_getpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2035. {
  2036. PyObject *return_value = NULL;
  2037. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2038. #define NUM_KEYWORDS 2
  2039. static struct {
  2040. PyGC_Head _this_is_not_used;
  2041. PyObject_VAR_HEAD
  2042. PyObject *ob_item[NUM_KEYWORDS];
  2043. } _kwtuple = {
  2044. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2045. .ob_item = { &_Py_ID(which), &_Py_ID(who), },
  2046. };
  2047. #undef NUM_KEYWORDS
  2048. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2049. #else // !Py_BUILD_CORE
  2050. # define KWTUPLE NULL
  2051. #endif // !Py_BUILD_CORE
  2052. static const char * const _keywords[] = {"which", "who", NULL};
  2053. static _PyArg_Parser _parser = {
  2054. .keywords = _keywords,
  2055. .fname = "getpriority",
  2056. .kwtuple = KWTUPLE,
  2057. };
  2058. #undef KWTUPLE
  2059. PyObject *argsbuf[2];
  2060. int which;
  2061. int who;
  2062. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  2063. if (!args) {
  2064. goto exit;
  2065. }
  2066. which = _PyLong_AsInt(args[0]);
  2067. if (which == -1 && PyErr_Occurred()) {
  2068. goto exit;
  2069. }
  2070. who = _PyLong_AsInt(args[1]);
  2071. if (who == -1 && PyErr_Occurred()) {
  2072. goto exit;
  2073. }
  2074. return_value = os_getpriority_impl(module, which, who);
  2075. exit:
  2076. return return_value;
  2077. }
  2078. #endif /* defined(HAVE_GETPRIORITY) */
  2079. #if defined(HAVE_SETPRIORITY)
  2080. PyDoc_STRVAR(os_setpriority__doc__,
  2081. "setpriority($module, /, which, who, priority)\n"
  2082. "--\n"
  2083. "\n"
  2084. "Set program scheduling priority.");
  2085. #define OS_SETPRIORITY_METHODDEF \
  2086. {"setpriority", _PyCFunction_CAST(os_setpriority), METH_FASTCALL|METH_KEYWORDS, os_setpriority__doc__},
  2087. static PyObject *
  2088. os_setpriority_impl(PyObject *module, int which, int who, int priority);
  2089. static PyObject *
  2090. os_setpriority(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2091. {
  2092. PyObject *return_value = NULL;
  2093. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2094. #define NUM_KEYWORDS 3
  2095. static struct {
  2096. PyGC_Head _this_is_not_used;
  2097. PyObject_VAR_HEAD
  2098. PyObject *ob_item[NUM_KEYWORDS];
  2099. } _kwtuple = {
  2100. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2101. .ob_item = { &_Py_ID(which), &_Py_ID(who), &_Py_ID(priority), },
  2102. };
  2103. #undef NUM_KEYWORDS
  2104. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2105. #else // !Py_BUILD_CORE
  2106. # define KWTUPLE NULL
  2107. #endif // !Py_BUILD_CORE
  2108. static const char * const _keywords[] = {"which", "who", "priority", NULL};
  2109. static _PyArg_Parser _parser = {
  2110. .keywords = _keywords,
  2111. .fname = "setpriority",
  2112. .kwtuple = KWTUPLE,
  2113. };
  2114. #undef KWTUPLE
  2115. PyObject *argsbuf[3];
  2116. int which;
  2117. int who;
  2118. int priority;
  2119. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  2120. if (!args) {
  2121. goto exit;
  2122. }
  2123. which = _PyLong_AsInt(args[0]);
  2124. if (which == -1 && PyErr_Occurred()) {
  2125. goto exit;
  2126. }
  2127. who = _PyLong_AsInt(args[1]);
  2128. if (who == -1 && PyErr_Occurred()) {
  2129. goto exit;
  2130. }
  2131. priority = _PyLong_AsInt(args[2]);
  2132. if (priority == -1 && PyErr_Occurred()) {
  2133. goto exit;
  2134. }
  2135. return_value = os_setpriority_impl(module, which, who, priority);
  2136. exit:
  2137. return return_value;
  2138. }
  2139. #endif /* defined(HAVE_SETPRIORITY) */
  2140. PyDoc_STRVAR(os_rename__doc__,
  2141. "rename($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
  2142. "--\n"
  2143. "\n"
  2144. "Rename a file or directory.\n"
  2145. "\n"
  2146. "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
  2147. " descriptor open to a directory, and the respective path string (src or dst)\n"
  2148. " should be relative; the path will then be relative to that directory.\n"
  2149. "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
  2150. " If they are unavailable, using them will raise a NotImplementedError.");
  2151. #define OS_RENAME_METHODDEF \
  2152. {"rename", _PyCFunction_CAST(os_rename), METH_FASTCALL|METH_KEYWORDS, os_rename__doc__},
  2153. static PyObject *
  2154. os_rename_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
  2155. int dst_dir_fd);
  2156. static PyObject *
  2157. os_rename(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2158. {
  2159. PyObject *return_value = NULL;
  2160. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2161. #define NUM_KEYWORDS 4
  2162. static struct {
  2163. PyGC_Head _this_is_not_used;
  2164. PyObject_VAR_HEAD
  2165. PyObject *ob_item[NUM_KEYWORDS];
  2166. } _kwtuple = {
  2167. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2168. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
  2169. };
  2170. #undef NUM_KEYWORDS
  2171. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2172. #else // !Py_BUILD_CORE
  2173. # define KWTUPLE NULL
  2174. #endif // !Py_BUILD_CORE
  2175. static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
  2176. static _PyArg_Parser _parser = {
  2177. .keywords = _keywords,
  2178. .fname = "rename",
  2179. .kwtuple = KWTUPLE,
  2180. };
  2181. #undef KWTUPLE
  2182. PyObject *argsbuf[4];
  2183. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  2184. path_t src = PATH_T_INITIALIZE_P("rename", "src", 0, 0, 0, 0);
  2185. path_t dst = PATH_T_INITIALIZE_P("rename", "dst", 0, 0, 0, 0);
  2186. int src_dir_fd = DEFAULT_DIR_FD;
  2187. int dst_dir_fd = DEFAULT_DIR_FD;
  2188. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  2189. if (!args) {
  2190. goto exit;
  2191. }
  2192. if (!path_converter(args[0], &src)) {
  2193. goto exit;
  2194. }
  2195. if (!path_converter(args[1], &dst)) {
  2196. goto exit;
  2197. }
  2198. if (!noptargs) {
  2199. goto skip_optional_kwonly;
  2200. }
  2201. if (args[2]) {
  2202. if (!dir_fd_converter(args[2], &src_dir_fd)) {
  2203. goto exit;
  2204. }
  2205. if (!--noptargs) {
  2206. goto skip_optional_kwonly;
  2207. }
  2208. }
  2209. if (!dir_fd_converter(args[3], &dst_dir_fd)) {
  2210. goto exit;
  2211. }
  2212. skip_optional_kwonly:
  2213. return_value = os_rename_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
  2214. exit:
  2215. /* Cleanup for src */
  2216. path_cleanup(&src);
  2217. /* Cleanup for dst */
  2218. path_cleanup(&dst);
  2219. return return_value;
  2220. }
  2221. PyDoc_STRVAR(os_replace__doc__,
  2222. "replace($module, /, src, dst, *, src_dir_fd=None, dst_dir_fd=None)\n"
  2223. "--\n"
  2224. "\n"
  2225. "Rename a file or directory, overwriting the destination.\n"
  2226. "\n"
  2227. "If either src_dir_fd or dst_dir_fd is not None, it should be a file\n"
  2228. " descriptor open to a directory, and the respective path string (src or dst)\n"
  2229. " should be relative; the path will then be relative to that directory.\n"
  2230. "src_dir_fd and dst_dir_fd, may not be implemented on your platform.\n"
  2231. " If they are unavailable, using them will raise a NotImplementedError.");
  2232. #define OS_REPLACE_METHODDEF \
  2233. {"replace", _PyCFunction_CAST(os_replace), METH_FASTCALL|METH_KEYWORDS, os_replace__doc__},
  2234. static PyObject *
  2235. os_replace_impl(PyObject *module, path_t *src, path_t *dst, int src_dir_fd,
  2236. int dst_dir_fd);
  2237. static PyObject *
  2238. os_replace(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2239. {
  2240. PyObject *return_value = NULL;
  2241. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2242. #define NUM_KEYWORDS 4
  2243. static struct {
  2244. PyGC_Head _this_is_not_used;
  2245. PyObject_VAR_HEAD
  2246. PyObject *ob_item[NUM_KEYWORDS];
  2247. } _kwtuple = {
  2248. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2249. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(src_dir_fd), &_Py_ID(dst_dir_fd), },
  2250. };
  2251. #undef NUM_KEYWORDS
  2252. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2253. #else // !Py_BUILD_CORE
  2254. # define KWTUPLE NULL
  2255. #endif // !Py_BUILD_CORE
  2256. static const char * const _keywords[] = {"src", "dst", "src_dir_fd", "dst_dir_fd", NULL};
  2257. static _PyArg_Parser _parser = {
  2258. .keywords = _keywords,
  2259. .fname = "replace",
  2260. .kwtuple = KWTUPLE,
  2261. };
  2262. #undef KWTUPLE
  2263. PyObject *argsbuf[4];
  2264. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  2265. path_t src = PATH_T_INITIALIZE_P("replace", "src", 0, 0, 0, 0);
  2266. path_t dst = PATH_T_INITIALIZE_P("replace", "dst", 0, 0, 0, 0);
  2267. int src_dir_fd = DEFAULT_DIR_FD;
  2268. int dst_dir_fd = DEFAULT_DIR_FD;
  2269. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  2270. if (!args) {
  2271. goto exit;
  2272. }
  2273. if (!path_converter(args[0], &src)) {
  2274. goto exit;
  2275. }
  2276. if (!path_converter(args[1], &dst)) {
  2277. goto exit;
  2278. }
  2279. if (!noptargs) {
  2280. goto skip_optional_kwonly;
  2281. }
  2282. if (args[2]) {
  2283. if (!dir_fd_converter(args[2], &src_dir_fd)) {
  2284. goto exit;
  2285. }
  2286. if (!--noptargs) {
  2287. goto skip_optional_kwonly;
  2288. }
  2289. }
  2290. if (!dir_fd_converter(args[3], &dst_dir_fd)) {
  2291. goto exit;
  2292. }
  2293. skip_optional_kwonly:
  2294. return_value = os_replace_impl(module, &src, &dst, src_dir_fd, dst_dir_fd);
  2295. exit:
  2296. /* Cleanup for src */
  2297. path_cleanup(&src);
  2298. /* Cleanup for dst */
  2299. path_cleanup(&dst);
  2300. return return_value;
  2301. }
  2302. PyDoc_STRVAR(os_rmdir__doc__,
  2303. "rmdir($module, /, path, *, dir_fd=None)\n"
  2304. "--\n"
  2305. "\n"
  2306. "Remove a directory.\n"
  2307. "\n"
  2308. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  2309. " and path should be relative; path will then be relative to that directory.\n"
  2310. "dir_fd may not be implemented on your platform.\n"
  2311. " If it is unavailable, using it will raise a NotImplementedError.");
  2312. #define OS_RMDIR_METHODDEF \
  2313. {"rmdir", _PyCFunction_CAST(os_rmdir), METH_FASTCALL|METH_KEYWORDS, os_rmdir__doc__},
  2314. static PyObject *
  2315. os_rmdir_impl(PyObject *module, path_t *path, int dir_fd);
  2316. static PyObject *
  2317. os_rmdir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2318. {
  2319. PyObject *return_value = NULL;
  2320. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2321. #define NUM_KEYWORDS 2
  2322. static struct {
  2323. PyGC_Head _this_is_not_used;
  2324. PyObject_VAR_HEAD
  2325. PyObject *ob_item[NUM_KEYWORDS];
  2326. } _kwtuple = {
  2327. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2328. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
  2329. };
  2330. #undef NUM_KEYWORDS
  2331. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2332. #else // !Py_BUILD_CORE
  2333. # define KWTUPLE NULL
  2334. #endif // !Py_BUILD_CORE
  2335. static const char * const _keywords[] = {"path", "dir_fd", NULL};
  2336. static _PyArg_Parser _parser = {
  2337. .keywords = _keywords,
  2338. .fname = "rmdir",
  2339. .kwtuple = KWTUPLE,
  2340. };
  2341. #undef KWTUPLE
  2342. PyObject *argsbuf[2];
  2343. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  2344. path_t path = PATH_T_INITIALIZE_P("rmdir", "path", 0, 0, 0, 0);
  2345. int dir_fd = DEFAULT_DIR_FD;
  2346. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2347. if (!args) {
  2348. goto exit;
  2349. }
  2350. if (!path_converter(args[0], &path)) {
  2351. goto exit;
  2352. }
  2353. if (!noptargs) {
  2354. goto skip_optional_kwonly;
  2355. }
  2356. if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  2357. goto exit;
  2358. }
  2359. skip_optional_kwonly:
  2360. return_value = os_rmdir_impl(module, &path, dir_fd);
  2361. exit:
  2362. /* Cleanup for path */
  2363. path_cleanup(&path);
  2364. return return_value;
  2365. }
  2366. #if defined(HAVE_SYSTEM) && defined(MS_WINDOWS)
  2367. PyDoc_STRVAR(os_system__doc__,
  2368. "system($module, /, command)\n"
  2369. "--\n"
  2370. "\n"
  2371. "Execute the command in a subshell.");
  2372. #define OS_SYSTEM_METHODDEF \
  2373. {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
  2374. static long
  2375. os_system_impl(PyObject *module, const Py_UNICODE *command);
  2376. static PyObject *
  2377. os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2378. {
  2379. PyObject *return_value = NULL;
  2380. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2381. #define NUM_KEYWORDS 1
  2382. static struct {
  2383. PyGC_Head _this_is_not_used;
  2384. PyObject_VAR_HEAD
  2385. PyObject *ob_item[NUM_KEYWORDS];
  2386. } _kwtuple = {
  2387. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2388. .ob_item = { &_Py_ID(command), },
  2389. };
  2390. #undef NUM_KEYWORDS
  2391. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2392. #else // !Py_BUILD_CORE
  2393. # define KWTUPLE NULL
  2394. #endif // !Py_BUILD_CORE
  2395. static const char * const _keywords[] = {"command", NULL};
  2396. static _PyArg_Parser _parser = {
  2397. .keywords = _keywords,
  2398. .fname = "system",
  2399. .kwtuple = KWTUPLE,
  2400. };
  2401. #undef KWTUPLE
  2402. PyObject *argsbuf[1];
  2403. const Py_UNICODE *command = NULL;
  2404. long _return_value;
  2405. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2406. if (!args) {
  2407. goto exit;
  2408. }
  2409. if (!PyUnicode_Check(args[0])) {
  2410. _PyArg_BadArgument("system", "argument 'command'", "str", args[0]);
  2411. goto exit;
  2412. }
  2413. command = PyUnicode_AsWideCharString(args[0], NULL);
  2414. if (command == NULL) {
  2415. goto exit;
  2416. }
  2417. _return_value = os_system_impl(module, command);
  2418. if ((_return_value == -1) && PyErr_Occurred()) {
  2419. goto exit;
  2420. }
  2421. return_value = PyLong_FromLong(_return_value);
  2422. exit:
  2423. /* Cleanup for command */
  2424. PyMem_Free((void *)command);
  2425. return return_value;
  2426. }
  2427. #endif /* defined(HAVE_SYSTEM) && defined(MS_WINDOWS) */
  2428. #if defined(HAVE_SYSTEM) && !defined(MS_WINDOWS)
  2429. PyDoc_STRVAR(os_system__doc__,
  2430. "system($module, /, command)\n"
  2431. "--\n"
  2432. "\n"
  2433. "Execute the command in a subshell.");
  2434. #define OS_SYSTEM_METHODDEF \
  2435. {"system", _PyCFunction_CAST(os_system), METH_FASTCALL|METH_KEYWORDS, os_system__doc__},
  2436. static long
  2437. os_system_impl(PyObject *module, PyObject *command);
  2438. static PyObject *
  2439. os_system(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2440. {
  2441. PyObject *return_value = NULL;
  2442. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2443. #define NUM_KEYWORDS 1
  2444. static struct {
  2445. PyGC_Head _this_is_not_used;
  2446. PyObject_VAR_HEAD
  2447. PyObject *ob_item[NUM_KEYWORDS];
  2448. } _kwtuple = {
  2449. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2450. .ob_item = { &_Py_ID(command), },
  2451. };
  2452. #undef NUM_KEYWORDS
  2453. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2454. #else // !Py_BUILD_CORE
  2455. # define KWTUPLE NULL
  2456. #endif // !Py_BUILD_CORE
  2457. static const char * const _keywords[] = {"command", NULL};
  2458. static _PyArg_Parser _parser = {
  2459. .keywords = _keywords,
  2460. .fname = "system",
  2461. .kwtuple = KWTUPLE,
  2462. };
  2463. #undef KWTUPLE
  2464. PyObject *argsbuf[1];
  2465. PyObject *command = NULL;
  2466. long _return_value;
  2467. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2468. if (!args) {
  2469. goto exit;
  2470. }
  2471. if (!PyUnicode_FSConverter(args[0], &command)) {
  2472. goto exit;
  2473. }
  2474. _return_value = os_system_impl(module, command);
  2475. if ((_return_value == -1) && PyErr_Occurred()) {
  2476. goto exit;
  2477. }
  2478. return_value = PyLong_FromLong(_return_value);
  2479. exit:
  2480. /* Cleanup for command */
  2481. Py_XDECREF(command);
  2482. return return_value;
  2483. }
  2484. #endif /* defined(HAVE_SYSTEM) && !defined(MS_WINDOWS) */
  2485. #if defined(HAVE_UMASK)
  2486. PyDoc_STRVAR(os_umask__doc__,
  2487. "umask($module, mask, /)\n"
  2488. "--\n"
  2489. "\n"
  2490. "Set the current numeric umask and return the previous umask.");
  2491. #define OS_UMASK_METHODDEF \
  2492. {"umask", (PyCFunction)os_umask, METH_O, os_umask__doc__},
  2493. static PyObject *
  2494. os_umask_impl(PyObject *module, int mask);
  2495. static PyObject *
  2496. os_umask(PyObject *module, PyObject *arg)
  2497. {
  2498. PyObject *return_value = NULL;
  2499. int mask;
  2500. mask = _PyLong_AsInt(arg);
  2501. if (mask == -1 && PyErr_Occurred()) {
  2502. goto exit;
  2503. }
  2504. return_value = os_umask_impl(module, mask);
  2505. exit:
  2506. return return_value;
  2507. }
  2508. #endif /* defined(HAVE_UMASK) */
  2509. PyDoc_STRVAR(os_unlink__doc__,
  2510. "unlink($module, /, path, *, dir_fd=None)\n"
  2511. "--\n"
  2512. "\n"
  2513. "Remove a file (same as remove()).\n"
  2514. "\n"
  2515. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  2516. " and path should be relative; path will then be relative to that directory.\n"
  2517. "dir_fd may not be implemented on your platform.\n"
  2518. " If it is unavailable, using it will raise a NotImplementedError.");
  2519. #define OS_UNLINK_METHODDEF \
  2520. {"unlink", _PyCFunction_CAST(os_unlink), METH_FASTCALL|METH_KEYWORDS, os_unlink__doc__},
  2521. static PyObject *
  2522. os_unlink_impl(PyObject *module, path_t *path, int dir_fd);
  2523. static PyObject *
  2524. os_unlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2525. {
  2526. PyObject *return_value = NULL;
  2527. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2528. #define NUM_KEYWORDS 2
  2529. static struct {
  2530. PyGC_Head _this_is_not_used;
  2531. PyObject_VAR_HEAD
  2532. PyObject *ob_item[NUM_KEYWORDS];
  2533. } _kwtuple = {
  2534. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2535. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
  2536. };
  2537. #undef NUM_KEYWORDS
  2538. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2539. #else // !Py_BUILD_CORE
  2540. # define KWTUPLE NULL
  2541. #endif // !Py_BUILD_CORE
  2542. static const char * const _keywords[] = {"path", "dir_fd", NULL};
  2543. static _PyArg_Parser _parser = {
  2544. .keywords = _keywords,
  2545. .fname = "unlink",
  2546. .kwtuple = KWTUPLE,
  2547. };
  2548. #undef KWTUPLE
  2549. PyObject *argsbuf[2];
  2550. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  2551. path_t path = PATH_T_INITIALIZE_P("unlink", "path", 0, 0, 0, 0);
  2552. int dir_fd = DEFAULT_DIR_FD;
  2553. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2554. if (!args) {
  2555. goto exit;
  2556. }
  2557. if (!path_converter(args[0], &path)) {
  2558. goto exit;
  2559. }
  2560. if (!noptargs) {
  2561. goto skip_optional_kwonly;
  2562. }
  2563. if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  2564. goto exit;
  2565. }
  2566. skip_optional_kwonly:
  2567. return_value = os_unlink_impl(module, &path, dir_fd);
  2568. exit:
  2569. /* Cleanup for path */
  2570. path_cleanup(&path);
  2571. return return_value;
  2572. }
  2573. PyDoc_STRVAR(os_remove__doc__,
  2574. "remove($module, /, path, *, dir_fd=None)\n"
  2575. "--\n"
  2576. "\n"
  2577. "Remove a file (same as unlink()).\n"
  2578. "\n"
  2579. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  2580. " and path should be relative; path will then be relative to that directory.\n"
  2581. "dir_fd may not be implemented on your platform.\n"
  2582. " If it is unavailable, using it will raise a NotImplementedError.");
  2583. #define OS_REMOVE_METHODDEF \
  2584. {"remove", _PyCFunction_CAST(os_remove), METH_FASTCALL|METH_KEYWORDS, os_remove__doc__},
  2585. static PyObject *
  2586. os_remove_impl(PyObject *module, path_t *path, int dir_fd);
  2587. static PyObject *
  2588. os_remove(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2589. {
  2590. PyObject *return_value = NULL;
  2591. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2592. #define NUM_KEYWORDS 2
  2593. static struct {
  2594. PyGC_Head _this_is_not_used;
  2595. PyObject_VAR_HEAD
  2596. PyObject *ob_item[NUM_KEYWORDS];
  2597. } _kwtuple = {
  2598. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2599. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
  2600. };
  2601. #undef NUM_KEYWORDS
  2602. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2603. #else // !Py_BUILD_CORE
  2604. # define KWTUPLE NULL
  2605. #endif // !Py_BUILD_CORE
  2606. static const char * const _keywords[] = {"path", "dir_fd", NULL};
  2607. static _PyArg_Parser _parser = {
  2608. .keywords = _keywords,
  2609. .fname = "remove",
  2610. .kwtuple = KWTUPLE,
  2611. };
  2612. #undef KWTUPLE
  2613. PyObject *argsbuf[2];
  2614. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  2615. path_t path = PATH_T_INITIALIZE_P("remove", "path", 0, 0, 0, 0);
  2616. int dir_fd = DEFAULT_DIR_FD;
  2617. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2618. if (!args) {
  2619. goto exit;
  2620. }
  2621. if (!path_converter(args[0], &path)) {
  2622. goto exit;
  2623. }
  2624. if (!noptargs) {
  2625. goto skip_optional_kwonly;
  2626. }
  2627. if (!UNLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  2628. goto exit;
  2629. }
  2630. skip_optional_kwonly:
  2631. return_value = os_remove_impl(module, &path, dir_fd);
  2632. exit:
  2633. /* Cleanup for path */
  2634. path_cleanup(&path);
  2635. return return_value;
  2636. }
  2637. #if defined(HAVE_UNAME)
  2638. PyDoc_STRVAR(os_uname__doc__,
  2639. "uname($module, /)\n"
  2640. "--\n"
  2641. "\n"
  2642. "Return an object identifying the current operating system.\n"
  2643. "\n"
  2644. "The object behaves like a named tuple with the following fields:\n"
  2645. " (sysname, nodename, release, version, machine)");
  2646. #define OS_UNAME_METHODDEF \
  2647. {"uname", (PyCFunction)os_uname, METH_NOARGS, os_uname__doc__},
  2648. static PyObject *
  2649. os_uname_impl(PyObject *module);
  2650. static PyObject *
  2651. os_uname(PyObject *module, PyObject *Py_UNUSED(ignored))
  2652. {
  2653. return os_uname_impl(module);
  2654. }
  2655. #endif /* defined(HAVE_UNAME) */
  2656. PyDoc_STRVAR(os_utime__doc__,
  2657. "utime($module, /, path, times=None, *, ns=<unrepresentable>,\n"
  2658. " dir_fd=None, follow_symlinks=True)\n"
  2659. "--\n"
  2660. "\n"
  2661. "Set the access and modified time of path.\n"
  2662. "\n"
  2663. "path may always be specified as a string.\n"
  2664. "On some platforms, path may also be specified as an open file descriptor.\n"
  2665. " If this functionality is unavailable, using it raises an exception.\n"
  2666. "\n"
  2667. "If times is not None, it must be a tuple (atime, mtime);\n"
  2668. " atime and mtime should be expressed as float seconds since the epoch.\n"
  2669. "If ns is specified, it must be a tuple (atime_ns, mtime_ns);\n"
  2670. " atime_ns and mtime_ns should be expressed as integer nanoseconds\n"
  2671. " since the epoch.\n"
  2672. "If times is None and ns is unspecified, utime uses the current time.\n"
  2673. "Specifying tuples for both times and ns is an error.\n"
  2674. "\n"
  2675. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  2676. " and path should be relative; path will then be relative to that directory.\n"
  2677. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  2678. " link, utime will modify the symbolic link itself instead of the file the\n"
  2679. " link points to.\n"
  2680. "It is an error to use dir_fd or follow_symlinks when specifying path\n"
  2681. " as an open file descriptor.\n"
  2682. "dir_fd and follow_symlinks may not be available on your platform.\n"
  2683. " If they are unavailable, using them will raise a NotImplementedError.");
  2684. #define OS_UTIME_METHODDEF \
  2685. {"utime", _PyCFunction_CAST(os_utime), METH_FASTCALL|METH_KEYWORDS, os_utime__doc__},
  2686. static PyObject *
  2687. os_utime_impl(PyObject *module, path_t *path, PyObject *times, PyObject *ns,
  2688. int dir_fd, int follow_symlinks);
  2689. static PyObject *
  2690. os_utime(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2691. {
  2692. PyObject *return_value = NULL;
  2693. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2694. #define NUM_KEYWORDS 5
  2695. static struct {
  2696. PyGC_Head _this_is_not_used;
  2697. PyObject_VAR_HEAD
  2698. PyObject *ob_item[NUM_KEYWORDS];
  2699. } _kwtuple = {
  2700. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2701. .ob_item = { &_Py_ID(path), &_Py_ID(times), &_Py_ID(ns), &_Py_ID(dir_fd), &_Py_ID(follow_symlinks), },
  2702. };
  2703. #undef NUM_KEYWORDS
  2704. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2705. #else // !Py_BUILD_CORE
  2706. # define KWTUPLE NULL
  2707. #endif // !Py_BUILD_CORE
  2708. static const char * const _keywords[] = {"path", "times", "ns", "dir_fd", "follow_symlinks", NULL};
  2709. static _PyArg_Parser _parser = {
  2710. .keywords = _keywords,
  2711. .fname = "utime",
  2712. .kwtuple = KWTUPLE,
  2713. };
  2714. #undef KWTUPLE
  2715. PyObject *argsbuf[5];
  2716. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  2717. path_t path = PATH_T_INITIALIZE_P("utime", "path", 0, 0, 0, PATH_UTIME_HAVE_FD);
  2718. PyObject *times = Py_None;
  2719. PyObject *ns = NULL;
  2720. int dir_fd = DEFAULT_DIR_FD;
  2721. int follow_symlinks = 1;
  2722. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  2723. if (!args) {
  2724. goto exit;
  2725. }
  2726. if (!path_converter(args[0], &path)) {
  2727. goto exit;
  2728. }
  2729. if (!noptargs) {
  2730. goto skip_optional_pos;
  2731. }
  2732. if (args[1]) {
  2733. times = args[1];
  2734. if (!--noptargs) {
  2735. goto skip_optional_pos;
  2736. }
  2737. }
  2738. skip_optional_pos:
  2739. if (!noptargs) {
  2740. goto skip_optional_kwonly;
  2741. }
  2742. if (args[2]) {
  2743. ns = args[2];
  2744. if (!--noptargs) {
  2745. goto skip_optional_kwonly;
  2746. }
  2747. }
  2748. if (args[3]) {
  2749. if (!FUTIMENSAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
  2750. goto exit;
  2751. }
  2752. if (!--noptargs) {
  2753. goto skip_optional_kwonly;
  2754. }
  2755. }
  2756. follow_symlinks = PyObject_IsTrue(args[4]);
  2757. if (follow_symlinks < 0) {
  2758. goto exit;
  2759. }
  2760. skip_optional_kwonly:
  2761. return_value = os_utime_impl(module, &path, times, ns, dir_fd, follow_symlinks);
  2762. exit:
  2763. /* Cleanup for path */
  2764. path_cleanup(&path);
  2765. return return_value;
  2766. }
  2767. PyDoc_STRVAR(os__exit__doc__,
  2768. "_exit($module, /, status)\n"
  2769. "--\n"
  2770. "\n"
  2771. "Exit to the system with specified status, without normal exit processing.");
  2772. #define OS__EXIT_METHODDEF \
  2773. {"_exit", _PyCFunction_CAST(os__exit), METH_FASTCALL|METH_KEYWORDS, os__exit__doc__},
  2774. static PyObject *
  2775. os__exit_impl(PyObject *module, int status);
  2776. static PyObject *
  2777. os__exit(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2778. {
  2779. PyObject *return_value = NULL;
  2780. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2781. #define NUM_KEYWORDS 1
  2782. static struct {
  2783. PyGC_Head _this_is_not_used;
  2784. PyObject_VAR_HEAD
  2785. PyObject *ob_item[NUM_KEYWORDS];
  2786. } _kwtuple = {
  2787. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2788. .ob_item = { &_Py_ID(status), },
  2789. };
  2790. #undef NUM_KEYWORDS
  2791. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2792. #else // !Py_BUILD_CORE
  2793. # define KWTUPLE NULL
  2794. #endif // !Py_BUILD_CORE
  2795. static const char * const _keywords[] = {"status", NULL};
  2796. static _PyArg_Parser _parser = {
  2797. .keywords = _keywords,
  2798. .fname = "_exit",
  2799. .kwtuple = KWTUPLE,
  2800. };
  2801. #undef KWTUPLE
  2802. PyObject *argsbuf[1];
  2803. int status;
  2804. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  2805. if (!args) {
  2806. goto exit;
  2807. }
  2808. status = _PyLong_AsInt(args[0]);
  2809. if (status == -1 && PyErr_Occurred()) {
  2810. goto exit;
  2811. }
  2812. return_value = os__exit_impl(module, status);
  2813. exit:
  2814. return return_value;
  2815. }
  2816. #if defined(HAVE_EXECV)
  2817. PyDoc_STRVAR(os_execv__doc__,
  2818. "execv($module, path, argv, /)\n"
  2819. "--\n"
  2820. "\n"
  2821. "Execute an executable path with arguments, replacing current process.\n"
  2822. "\n"
  2823. " path\n"
  2824. " Path of executable file.\n"
  2825. " argv\n"
  2826. " Tuple or list of strings.");
  2827. #define OS_EXECV_METHODDEF \
  2828. {"execv", _PyCFunction_CAST(os_execv), METH_FASTCALL, os_execv__doc__},
  2829. static PyObject *
  2830. os_execv_impl(PyObject *module, path_t *path, PyObject *argv);
  2831. static PyObject *
  2832. os_execv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  2833. {
  2834. PyObject *return_value = NULL;
  2835. path_t path = PATH_T_INITIALIZE_P("execv", "path", 0, 0, 0, 0);
  2836. PyObject *argv;
  2837. if (!_PyArg_CheckPositional("execv", nargs, 2, 2)) {
  2838. goto exit;
  2839. }
  2840. if (!path_converter(args[0], &path)) {
  2841. goto exit;
  2842. }
  2843. argv = args[1];
  2844. return_value = os_execv_impl(module, &path, argv);
  2845. exit:
  2846. /* Cleanup for path */
  2847. path_cleanup(&path);
  2848. return return_value;
  2849. }
  2850. #endif /* defined(HAVE_EXECV) */
  2851. #if defined(HAVE_EXECV)
  2852. PyDoc_STRVAR(os_execve__doc__,
  2853. "execve($module, /, path, argv, env)\n"
  2854. "--\n"
  2855. "\n"
  2856. "Execute an executable path with arguments, replacing current process.\n"
  2857. "\n"
  2858. " path\n"
  2859. " Path of executable file.\n"
  2860. " argv\n"
  2861. " Tuple or list of strings.\n"
  2862. " env\n"
  2863. " Dictionary of strings mapping to strings.");
  2864. #define OS_EXECVE_METHODDEF \
  2865. {"execve", _PyCFunction_CAST(os_execve), METH_FASTCALL|METH_KEYWORDS, os_execve__doc__},
  2866. static PyObject *
  2867. os_execve_impl(PyObject *module, path_t *path, PyObject *argv, PyObject *env);
  2868. static PyObject *
  2869. os_execve(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2870. {
  2871. PyObject *return_value = NULL;
  2872. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2873. #define NUM_KEYWORDS 3
  2874. static struct {
  2875. PyGC_Head _this_is_not_used;
  2876. PyObject_VAR_HEAD
  2877. PyObject *ob_item[NUM_KEYWORDS];
  2878. } _kwtuple = {
  2879. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2880. .ob_item = { &_Py_ID(path), &_Py_ID(argv), &_Py_ID(env), },
  2881. };
  2882. #undef NUM_KEYWORDS
  2883. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2884. #else // !Py_BUILD_CORE
  2885. # define KWTUPLE NULL
  2886. #endif // !Py_BUILD_CORE
  2887. static const char * const _keywords[] = {"path", "argv", "env", NULL};
  2888. static _PyArg_Parser _parser = {
  2889. .keywords = _keywords,
  2890. .fname = "execve",
  2891. .kwtuple = KWTUPLE,
  2892. };
  2893. #undef KWTUPLE
  2894. PyObject *argsbuf[3];
  2895. path_t path = PATH_T_INITIALIZE_P("execve", "path", 0, 0, 0, PATH_HAVE_FEXECVE);
  2896. PyObject *argv;
  2897. PyObject *env;
  2898. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  2899. if (!args) {
  2900. goto exit;
  2901. }
  2902. if (!path_converter(args[0], &path)) {
  2903. goto exit;
  2904. }
  2905. argv = args[1];
  2906. env = args[2];
  2907. return_value = os_execve_impl(module, &path, argv, env);
  2908. exit:
  2909. /* Cleanup for path */
  2910. path_cleanup(&path);
  2911. return return_value;
  2912. }
  2913. #endif /* defined(HAVE_EXECV) */
  2914. #if defined(HAVE_POSIX_SPAWN)
  2915. PyDoc_STRVAR(os_posix_spawn__doc__,
  2916. "posix_spawn($module, path, argv, env, /, *, file_actions=(),\n"
  2917. " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
  2918. " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
  2919. "--\n"
  2920. "\n"
  2921. "Execute the program specified by path in a new process.\n"
  2922. "\n"
  2923. " path\n"
  2924. " Path of executable file.\n"
  2925. " argv\n"
  2926. " Tuple or list of strings.\n"
  2927. " env\n"
  2928. " Dictionary of strings mapping to strings.\n"
  2929. " file_actions\n"
  2930. " A sequence of file action tuples.\n"
  2931. " setpgroup\n"
  2932. " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
  2933. " resetids\n"
  2934. " If the value is `true` the POSIX_SPAWN_RESETIDS will be activated.\n"
  2935. " setsid\n"
  2936. " If the value is `true` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
  2937. " setsigmask\n"
  2938. " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
  2939. " setsigdef\n"
  2940. " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
  2941. " scheduler\n"
  2942. " A tuple with the scheduler policy (optional) and parameters.");
  2943. #define OS_POSIX_SPAWN_METHODDEF \
  2944. {"posix_spawn", _PyCFunction_CAST(os_posix_spawn), METH_FASTCALL|METH_KEYWORDS, os_posix_spawn__doc__},
  2945. static PyObject *
  2946. os_posix_spawn_impl(PyObject *module, path_t *path, PyObject *argv,
  2947. PyObject *env, PyObject *file_actions,
  2948. PyObject *setpgroup, int resetids, int setsid,
  2949. PyObject *setsigmask, PyObject *setsigdef,
  2950. PyObject *scheduler);
  2951. static PyObject *
  2952. os_posix_spawn(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  2953. {
  2954. PyObject *return_value = NULL;
  2955. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  2956. #define NUM_KEYWORDS 7
  2957. static struct {
  2958. PyGC_Head _this_is_not_used;
  2959. PyObject_VAR_HEAD
  2960. PyObject *ob_item[NUM_KEYWORDS];
  2961. } _kwtuple = {
  2962. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  2963. .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
  2964. };
  2965. #undef NUM_KEYWORDS
  2966. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  2967. #else // !Py_BUILD_CORE
  2968. # define KWTUPLE NULL
  2969. #endif // !Py_BUILD_CORE
  2970. static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
  2971. static _PyArg_Parser _parser = {
  2972. .keywords = _keywords,
  2973. .fname = "posix_spawn",
  2974. .kwtuple = KWTUPLE,
  2975. };
  2976. #undef KWTUPLE
  2977. PyObject *argsbuf[10];
  2978. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  2979. path_t path = PATH_T_INITIALIZE_P("posix_spawn", "path", 0, 0, 0, 0);
  2980. PyObject *argv;
  2981. PyObject *env;
  2982. PyObject *file_actions = NULL;
  2983. PyObject *setpgroup = NULL;
  2984. int resetids = 0;
  2985. int setsid = 0;
  2986. PyObject *setsigmask = NULL;
  2987. PyObject *setsigdef = NULL;
  2988. PyObject *scheduler = NULL;
  2989. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  2990. if (!args) {
  2991. goto exit;
  2992. }
  2993. if (!path_converter(args[0], &path)) {
  2994. goto exit;
  2995. }
  2996. argv = args[1];
  2997. env = args[2];
  2998. if (!noptargs) {
  2999. goto skip_optional_kwonly;
  3000. }
  3001. if (args[3]) {
  3002. file_actions = args[3];
  3003. if (!--noptargs) {
  3004. goto skip_optional_kwonly;
  3005. }
  3006. }
  3007. if (args[4]) {
  3008. setpgroup = args[4];
  3009. if (!--noptargs) {
  3010. goto skip_optional_kwonly;
  3011. }
  3012. }
  3013. if (args[5]) {
  3014. resetids = PyObject_IsTrue(args[5]);
  3015. if (resetids < 0) {
  3016. goto exit;
  3017. }
  3018. if (!--noptargs) {
  3019. goto skip_optional_kwonly;
  3020. }
  3021. }
  3022. if (args[6]) {
  3023. setsid = PyObject_IsTrue(args[6]);
  3024. if (setsid < 0) {
  3025. goto exit;
  3026. }
  3027. if (!--noptargs) {
  3028. goto skip_optional_kwonly;
  3029. }
  3030. }
  3031. if (args[7]) {
  3032. setsigmask = args[7];
  3033. if (!--noptargs) {
  3034. goto skip_optional_kwonly;
  3035. }
  3036. }
  3037. if (args[8]) {
  3038. setsigdef = args[8];
  3039. if (!--noptargs) {
  3040. goto skip_optional_kwonly;
  3041. }
  3042. }
  3043. scheduler = args[9];
  3044. skip_optional_kwonly:
  3045. return_value = os_posix_spawn_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
  3046. exit:
  3047. /* Cleanup for path */
  3048. path_cleanup(&path);
  3049. return return_value;
  3050. }
  3051. #endif /* defined(HAVE_POSIX_SPAWN) */
  3052. #if defined(HAVE_POSIX_SPAWNP)
  3053. PyDoc_STRVAR(os_posix_spawnp__doc__,
  3054. "posix_spawnp($module, path, argv, env, /, *, file_actions=(),\n"
  3055. " setpgroup=<unrepresentable>, resetids=False, setsid=False,\n"
  3056. " setsigmask=(), setsigdef=(), scheduler=<unrepresentable>)\n"
  3057. "--\n"
  3058. "\n"
  3059. "Execute the program specified by path in a new process.\n"
  3060. "\n"
  3061. " path\n"
  3062. " Path of executable file.\n"
  3063. " argv\n"
  3064. " Tuple or list of strings.\n"
  3065. " env\n"
  3066. " Dictionary of strings mapping to strings.\n"
  3067. " file_actions\n"
  3068. " A sequence of file action tuples.\n"
  3069. " setpgroup\n"
  3070. " The pgroup to use with the POSIX_SPAWN_SETPGROUP flag.\n"
  3071. " resetids\n"
  3072. " If the value is `True` the POSIX_SPAWN_RESETIDS will be activated.\n"
  3073. " setsid\n"
  3074. " If the value is `True` the POSIX_SPAWN_SETSID or POSIX_SPAWN_SETSID_NP will be activated.\n"
  3075. " setsigmask\n"
  3076. " The sigmask to use with the POSIX_SPAWN_SETSIGMASK flag.\n"
  3077. " setsigdef\n"
  3078. " The sigmask to use with the POSIX_SPAWN_SETSIGDEF flag.\n"
  3079. " scheduler\n"
  3080. " A tuple with the scheduler policy (optional) and parameters.");
  3081. #define OS_POSIX_SPAWNP_METHODDEF \
  3082. {"posix_spawnp", _PyCFunction_CAST(os_posix_spawnp), METH_FASTCALL|METH_KEYWORDS, os_posix_spawnp__doc__},
  3083. static PyObject *
  3084. os_posix_spawnp_impl(PyObject *module, path_t *path, PyObject *argv,
  3085. PyObject *env, PyObject *file_actions,
  3086. PyObject *setpgroup, int resetids, int setsid,
  3087. PyObject *setsigmask, PyObject *setsigdef,
  3088. PyObject *scheduler);
  3089. static PyObject *
  3090. os_posix_spawnp(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  3091. {
  3092. PyObject *return_value = NULL;
  3093. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  3094. #define NUM_KEYWORDS 7
  3095. static struct {
  3096. PyGC_Head _this_is_not_used;
  3097. PyObject_VAR_HEAD
  3098. PyObject *ob_item[NUM_KEYWORDS];
  3099. } _kwtuple = {
  3100. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  3101. .ob_item = { &_Py_ID(file_actions), &_Py_ID(setpgroup), &_Py_ID(resetids), &_Py_ID(setsid), &_Py_ID(setsigmask), &_Py_ID(setsigdef), &_Py_ID(scheduler), },
  3102. };
  3103. #undef NUM_KEYWORDS
  3104. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  3105. #else // !Py_BUILD_CORE
  3106. # define KWTUPLE NULL
  3107. #endif // !Py_BUILD_CORE
  3108. static const char * const _keywords[] = {"", "", "", "file_actions", "setpgroup", "resetids", "setsid", "setsigmask", "setsigdef", "scheduler", NULL};
  3109. static _PyArg_Parser _parser = {
  3110. .keywords = _keywords,
  3111. .fname = "posix_spawnp",
  3112. .kwtuple = KWTUPLE,
  3113. };
  3114. #undef KWTUPLE
  3115. PyObject *argsbuf[10];
  3116. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  3117. path_t path = PATH_T_INITIALIZE_P("posix_spawnp", "path", 0, 0, 0, 0);
  3118. PyObject *argv;
  3119. PyObject *env;
  3120. PyObject *file_actions = NULL;
  3121. PyObject *setpgroup = NULL;
  3122. int resetids = 0;
  3123. int setsid = 0;
  3124. PyObject *setsigmask = NULL;
  3125. PyObject *setsigdef = NULL;
  3126. PyObject *scheduler = NULL;
  3127. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 3, 0, argsbuf);
  3128. if (!args) {
  3129. goto exit;
  3130. }
  3131. if (!path_converter(args[0], &path)) {
  3132. goto exit;
  3133. }
  3134. argv = args[1];
  3135. env = args[2];
  3136. if (!noptargs) {
  3137. goto skip_optional_kwonly;
  3138. }
  3139. if (args[3]) {
  3140. file_actions = args[3];
  3141. if (!--noptargs) {
  3142. goto skip_optional_kwonly;
  3143. }
  3144. }
  3145. if (args[4]) {
  3146. setpgroup = args[4];
  3147. if (!--noptargs) {
  3148. goto skip_optional_kwonly;
  3149. }
  3150. }
  3151. if (args[5]) {
  3152. resetids = PyObject_IsTrue(args[5]);
  3153. if (resetids < 0) {
  3154. goto exit;
  3155. }
  3156. if (!--noptargs) {
  3157. goto skip_optional_kwonly;
  3158. }
  3159. }
  3160. if (args[6]) {
  3161. setsid = PyObject_IsTrue(args[6]);
  3162. if (setsid < 0) {
  3163. goto exit;
  3164. }
  3165. if (!--noptargs) {
  3166. goto skip_optional_kwonly;
  3167. }
  3168. }
  3169. if (args[7]) {
  3170. setsigmask = args[7];
  3171. if (!--noptargs) {
  3172. goto skip_optional_kwonly;
  3173. }
  3174. }
  3175. if (args[8]) {
  3176. setsigdef = args[8];
  3177. if (!--noptargs) {
  3178. goto skip_optional_kwonly;
  3179. }
  3180. }
  3181. scheduler = args[9];
  3182. skip_optional_kwonly:
  3183. return_value = os_posix_spawnp_impl(module, &path, argv, env, file_actions, setpgroup, resetids, setsid, setsigmask, setsigdef, scheduler);
  3184. exit:
  3185. /* Cleanup for path */
  3186. path_cleanup(&path);
  3187. return return_value;
  3188. }
  3189. #endif /* defined(HAVE_POSIX_SPAWNP) */
  3190. #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
  3191. PyDoc_STRVAR(os_spawnv__doc__,
  3192. "spawnv($module, mode, path, argv, /)\n"
  3193. "--\n"
  3194. "\n"
  3195. "Execute the program specified by path in a new process.\n"
  3196. "\n"
  3197. " mode\n"
  3198. " Mode of process creation.\n"
  3199. " path\n"
  3200. " Path of executable file.\n"
  3201. " argv\n"
  3202. " Tuple or list of strings.");
  3203. #define OS_SPAWNV_METHODDEF \
  3204. {"spawnv", _PyCFunction_CAST(os_spawnv), METH_FASTCALL, os_spawnv__doc__},
  3205. static PyObject *
  3206. os_spawnv_impl(PyObject *module, int mode, path_t *path, PyObject *argv);
  3207. static PyObject *
  3208. os_spawnv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3209. {
  3210. PyObject *return_value = NULL;
  3211. int mode;
  3212. path_t path = PATH_T_INITIALIZE_P("spawnv", "path", 0, 0, 0, 0);
  3213. PyObject *argv;
  3214. if (!_PyArg_CheckPositional("spawnv", nargs, 3, 3)) {
  3215. goto exit;
  3216. }
  3217. mode = _PyLong_AsInt(args[0]);
  3218. if (mode == -1 && PyErr_Occurred()) {
  3219. goto exit;
  3220. }
  3221. if (!path_converter(args[1], &path)) {
  3222. goto exit;
  3223. }
  3224. argv = args[2];
  3225. return_value = os_spawnv_impl(module, mode, &path, argv);
  3226. exit:
  3227. /* Cleanup for path */
  3228. path_cleanup(&path);
  3229. return return_value;
  3230. }
  3231. #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
  3232. #if (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN))
  3233. PyDoc_STRVAR(os_spawnve__doc__,
  3234. "spawnve($module, mode, path, argv, env, /)\n"
  3235. "--\n"
  3236. "\n"
  3237. "Execute the program specified by path in a new process.\n"
  3238. "\n"
  3239. " mode\n"
  3240. " Mode of process creation.\n"
  3241. " path\n"
  3242. " Path of executable file.\n"
  3243. " argv\n"
  3244. " Tuple or list of strings.\n"
  3245. " env\n"
  3246. " Dictionary of strings mapping to strings.");
  3247. #define OS_SPAWNVE_METHODDEF \
  3248. {"spawnve", _PyCFunction_CAST(os_spawnve), METH_FASTCALL, os_spawnve__doc__},
  3249. static PyObject *
  3250. os_spawnve_impl(PyObject *module, int mode, path_t *path, PyObject *argv,
  3251. PyObject *env);
  3252. static PyObject *
  3253. os_spawnve(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3254. {
  3255. PyObject *return_value = NULL;
  3256. int mode;
  3257. path_t path = PATH_T_INITIALIZE_P("spawnve", "path", 0, 0, 0, 0);
  3258. PyObject *argv;
  3259. PyObject *env;
  3260. if (!_PyArg_CheckPositional("spawnve", nargs, 4, 4)) {
  3261. goto exit;
  3262. }
  3263. mode = _PyLong_AsInt(args[0]);
  3264. if (mode == -1 && PyErr_Occurred()) {
  3265. goto exit;
  3266. }
  3267. if (!path_converter(args[1], &path)) {
  3268. goto exit;
  3269. }
  3270. argv = args[2];
  3271. env = args[3];
  3272. return_value = os_spawnve_impl(module, mode, &path, argv, env);
  3273. exit:
  3274. /* Cleanup for path */
  3275. path_cleanup(&path);
  3276. return return_value;
  3277. }
  3278. #endif /* (defined(HAVE_SPAWNV) || defined(HAVE_WSPAWNV) || defined(HAVE_RTPSPAWN)) */
  3279. #if defined(HAVE_FORK)
  3280. PyDoc_STRVAR(os_register_at_fork__doc__,
  3281. "register_at_fork($module, /, *, before=<unrepresentable>,\n"
  3282. " after_in_child=<unrepresentable>,\n"
  3283. " after_in_parent=<unrepresentable>)\n"
  3284. "--\n"
  3285. "\n"
  3286. "Register callables to be called when forking a new process.\n"
  3287. "\n"
  3288. " before\n"
  3289. " A callable to be called in the parent before the fork() syscall.\n"
  3290. " after_in_child\n"
  3291. " A callable to be called in the child after fork().\n"
  3292. " after_in_parent\n"
  3293. " A callable to be called in the parent after fork().\n"
  3294. "\n"
  3295. "\'before\' callbacks are called in reverse order.\n"
  3296. "\'after_in_child\' and \'after_in_parent\' callbacks are called in order.");
  3297. #define OS_REGISTER_AT_FORK_METHODDEF \
  3298. {"register_at_fork", _PyCFunction_CAST(os_register_at_fork), METH_FASTCALL|METH_KEYWORDS, os_register_at_fork__doc__},
  3299. static PyObject *
  3300. os_register_at_fork_impl(PyObject *module, PyObject *before,
  3301. PyObject *after_in_child, PyObject *after_in_parent);
  3302. static PyObject *
  3303. os_register_at_fork(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  3304. {
  3305. PyObject *return_value = NULL;
  3306. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  3307. #define NUM_KEYWORDS 3
  3308. static struct {
  3309. PyGC_Head _this_is_not_used;
  3310. PyObject_VAR_HEAD
  3311. PyObject *ob_item[NUM_KEYWORDS];
  3312. } _kwtuple = {
  3313. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  3314. .ob_item = { &_Py_ID(before), &_Py_ID(after_in_child), &_Py_ID(after_in_parent), },
  3315. };
  3316. #undef NUM_KEYWORDS
  3317. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  3318. #else // !Py_BUILD_CORE
  3319. # define KWTUPLE NULL
  3320. #endif // !Py_BUILD_CORE
  3321. static const char * const _keywords[] = {"before", "after_in_child", "after_in_parent", NULL};
  3322. static _PyArg_Parser _parser = {
  3323. .keywords = _keywords,
  3324. .fname = "register_at_fork",
  3325. .kwtuple = KWTUPLE,
  3326. };
  3327. #undef KWTUPLE
  3328. PyObject *argsbuf[3];
  3329. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  3330. PyObject *before = NULL;
  3331. PyObject *after_in_child = NULL;
  3332. PyObject *after_in_parent = NULL;
  3333. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  3334. if (!args) {
  3335. goto exit;
  3336. }
  3337. if (!noptargs) {
  3338. goto skip_optional_kwonly;
  3339. }
  3340. if (args[0]) {
  3341. before = args[0];
  3342. if (!--noptargs) {
  3343. goto skip_optional_kwonly;
  3344. }
  3345. }
  3346. if (args[1]) {
  3347. after_in_child = args[1];
  3348. if (!--noptargs) {
  3349. goto skip_optional_kwonly;
  3350. }
  3351. }
  3352. after_in_parent = args[2];
  3353. skip_optional_kwonly:
  3354. return_value = os_register_at_fork_impl(module, before, after_in_child, after_in_parent);
  3355. exit:
  3356. return return_value;
  3357. }
  3358. #endif /* defined(HAVE_FORK) */
  3359. #if defined(HAVE_FORK1)
  3360. PyDoc_STRVAR(os_fork1__doc__,
  3361. "fork1($module, /)\n"
  3362. "--\n"
  3363. "\n"
  3364. "Fork a child process with a single multiplexed (i.e., not bound) thread.\n"
  3365. "\n"
  3366. "Return 0 to child process and PID of child to parent process.");
  3367. #define OS_FORK1_METHODDEF \
  3368. {"fork1", (PyCFunction)os_fork1, METH_NOARGS, os_fork1__doc__},
  3369. static PyObject *
  3370. os_fork1_impl(PyObject *module);
  3371. static PyObject *
  3372. os_fork1(PyObject *module, PyObject *Py_UNUSED(ignored))
  3373. {
  3374. return os_fork1_impl(module);
  3375. }
  3376. #endif /* defined(HAVE_FORK1) */
  3377. #if defined(HAVE_FORK)
  3378. PyDoc_STRVAR(os_fork__doc__,
  3379. "fork($module, /)\n"
  3380. "--\n"
  3381. "\n"
  3382. "Fork a child process.\n"
  3383. "\n"
  3384. "Return 0 to child process and PID of child to parent process.");
  3385. #define OS_FORK_METHODDEF \
  3386. {"fork", (PyCFunction)os_fork, METH_NOARGS, os_fork__doc__},
  3387. static PyObject *
  3388. os_fork_impl(PyObject *module);
  3389. static PyObject *
  3390. os_fork(PyObject *module, PyObject *Py_UNUSED(ignored))
  3391. {
  3392. return os_fork_impl(module);
  3393. }
  3394. #endif /* defined(HAVE_FORK) */
  3395. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
  3396. PyDoc_STRVAR(os_sched_get_priority_max__doc__,
  3397. "sched_get_priority_max($module, /, policy)\n"
  3398. "--\n"
  3399. "\n"
  3400. "Get the maximum scheduling priority for policy.");
  3401. #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF \
  3402. {"sched_get_priority_max", _PyCFunction_CAST(os_sched_get_priority_max), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_max__doc__},
  3403. static PyObject *
  3404. os_sched_get_priority_max_impl(PyObject *module, int policy);
  3405. static PyObject *
  3406. os_sched_get_priority_max(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  3407. {
  3408. PyObject *return_value = NULL;
  3409. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  3410. #define NUM_KEYWORDS 1
  3411. static struct {
  3412. PyGC_Head _this_is_not_used;
  3413. PyObject_VAR_HEAD
  3414. PyObject *ob_item[NUM_KEYWORDS];
  3415. } _kwtuple = {
  3416. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  3417. .ob_item = { &_Py_ID(policy), },
  3418. };
  3419. #undef NUM_KEYWORDS
  3420. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  3421. #else // !Py_BUILD_CORE
  3422. # define KWTUPLE NULL
  3423. #endif // !Py_BUILD_CORE
  3424. static const char * const _keywords[] = {"policy", NULL};
  3425. static _PyArg_Parser _parser = {
  3426. .keywords = _keywords,
  3427. .fname = "sched_get_priority_max",
  3428. .kwtuple = KWTUPLE,
  3429. };
  3430. #undef KWTUPLE
  3431. PyObject *argsbuf[1];
  3432. int policy;
  3433. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  3434. if (!args) {
  3435. goto exit;
  3436. }
  3437. policy = _PyLong_AsInt(args[0]);
  3438. if (policy == -1 && PyErr_Occurred()) {
  3439. goto exit;
  3440. }
  3441. return_value = os_sched_get_priority_max_impl(module, policy);
  3442. exit:
  3443. return return_value;
  3444. }
  3445. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
  3446. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX)
  3447. PyDoc_STRVAR(os_sched_get_priority_min__doc__,
  3448. "sched_get_priority_min($module, /, policy)\n"
  3449. "--\n"
  3450. "\n"
  3451. "Get the minimum scheduling priority for policy.");
  3452. #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF \
  3453. {"sched_get_priority_min", _PyCFunction_CAST(os_sched_get_priority_min), METH_FASTCALL|METH_KEYWORDS, os_sched_get_priority_min__doc__},
  3454. static PyObject *
  3455. os_sched_get_priority_min_impl(PyObject *module, int policy);
  3456. static PyObject *
  3457. os_sched_get_priority_min(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  3458. {
  3459. PyObject *return_value = NULL;
  3460. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  3461. #define NUM_KEYWORDS 1
  3462. static struct {
  3463. PyGC_Head _this_is_not_used;
  3464. PyObject_VAR_HEAD
  3465. PyObject *ob_item[NUM_KEYWORDS];
  3466. } _kwtuple = {
  3467. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  3468. .ob_item = { &_Py_ID(policy), },
  3469. };
  3470. #undef NUM_KEYWORDS
  3471. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  3472. #else // !Py_BUILD_CORE
  3473. # define KWTUPLE NULL
  3474. #endif // !Py_BUILD_CORE
  3475. static const char * const _keywords[] = {"policy", NULL};
  3476. static _PyArg_Parser _parser = {
  3477. .keywords = _keywords,
  3478. .fname = "sched_get_priority_min",
  3479. .kwtuple = KWTUPLE,
  3480. };
  3481. #undef KWTUPLE
  3482. PyObject *argsbuf[1];
  3483. int policy;
  3484. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  3485. if (!args) {
  3486. goto exit;
  3487. }
  3488. policy = _PyLong_AsInt(args[0]);
  3489. if (policy == -1 && PyErr_Occurred()) {
  3490. goto exit;
  3491. }
  3492. return_value = os_sched_get_priority_min_impl(module, policy);
  3493. exit:
  3494. return return_value;
  3495. }
  3496. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_GET_PRIORITY_MAX) */
  3497. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
  3498. PyDoc_STRVAR(os_sched_getscheduler__doc__,
  3499. "sched_getscheduler($module, pid, /)\n"
  3500. "--\n"
  3501. "\n"
  3502. "Get the scheduling policy for the process identified by pid.\n"
  3503. "\n"
  3504. "Passing 0 for pid returns the scheduling policy for the calling process.");
  3505. #define OS_SCHED_GETSCHEDULER_METHODDEF \
  3506. {"sched_getscheduler", (PyCFunction)os_sched_getscheduler, METH_O, os_sched_getscheduler__doc__},
  3507. static PyObject *
  3508. os_sched_getscheduler_impl(PyObject *module, pid_t pid);
  3509. static PyObject *
  3510. os_sched_getscheduler(PyObject *module, PyObject *arg)
  3511. {
  3512. PyObject *return_value = NULL;
  3513. pid_t pid;
  3514. if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getscheduler", &pid)) {
  3515. goto exit;
  3516. }
  3517. return_value = os_sched_getscheduler_impl(module, pid);
  3518. exit:
  3519. return return_value;
  3520. }
  3521. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
  3522. #if defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM))
  3523. PyDoc_STRVAR(os_sched_param__doc__,
  3524. "sched_param(sched_priority)\n"
  3525. "--\n"
  3526. "\n"
  3527. "Currently has only one field: sched_priority\n"
  3528. "\n"
  3529. " sched_priority\n"
  3530. " A scheduling parameter.");
  3531. static PyObject *
  3532. os_sched_param_impl(PyTypeObject *type, PyObject *sched_priority);
  3533. static PyObject *
  3534. os_sched_param(PyTypeObject *type, PyObject *args, PyObject *kwargs)
  3535. {
  3536. PyObject *return_value = NULL;
  3537. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  3538. #define NUM_KEYWORDS 1
  3539. static struct {
  3540. PyGC_Head _this_is_not_used;
  3541. PyObject_VAR_HEAD
  3542. PyObject *ob_item[NUM_KEYWORDS];
  3543. } _kwtuple = {
  3544. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  3545. .ob_item = { &_Py_ID(sched_priority), },
  3546. };
  3547. #undef NUM_KEYWORDS
  3548. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  3549. #else // !Py_BUILD_CORE
  3550. # define KWTUPLE NULL
  3551. #endif // !Py_BUILD_CORE
  3552. static const char * const _keywords[] = {"sched_priority", NULL};
  3553. static _PyArg_Parser _parser = {
  3554. .keywords = _keywords,
  3555. .fname = "sched_param",
  3556. .kwtuple = KWTUPLE,
  3557. };
  3558. #undef KWTUPLE
  3559. PyObject *argsbuf[1];
  3560. PyObject * const *fastargs;
  3561. Py_ssize_t nargs = PyTuple_GET_SIZE(args);
  3562. PyObject *sched_priority;
  3563. fastargs = _PyArg_UnpackKeywords(_PyTuple_CAST(args)->ob_item, nargs, kwargs, NULL, &_parser, 1, 1, 0, argsbuf);
  3564. if (!fastargs) {
  3565. goto exit;
  3566. }
  3567. sched_priority = fastargs[0];
  3568. return_value = os_sched_param_impl(type, sched_priority);
  3569. exit:
  3570. return return_value;
  3571. }
  3572. #endif /* defined(HAVE_SCHED_H) && (defined(HAVE_SCHED_SETPARAM) || defined(HAVE_SCHED_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDULER) || defined(POSIX_SPAWN_SETSCHEDPARAM)) */
  3573. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER)
  3574. PyDoc_STRVAR(os_sched_setscheduler__doc__,
  3575. "sched_setscheduler($module, pid, policy, param, /)\n"
  3576. "--\n"
  3577. "\n"
  3578. "Set the scheduling policy for the process identified by pid.\n"
  3579. "\n"
  3580. "If pid is 0, the calling process is changed.\n"
  3581. "param is an instance of sched_param.");
  3582. #define OS_SCHED_SETSCHEDULER_METHODDEF \
  3583. {"sched_setscheduler", _PyCFunction_CAST(os_sched_setscheduler), METH_FASTCALL, os_sched_setscheduler__doc__},
  3584. static PyObject *
  3585. os_sched_setscheduler_impl(PyObject *module, pid_t pid, int policy,
  3586. PyObject *param_obj);
  3587. static PyObject *
  3588. os_sched_setscheduler(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3589. {
  3590. PyObject *return_value = NULL;
  3591. pid_t pid;
  3592. int policy;
  3593. PyObject *param_obj;
  3594. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "iO:sched_setscheduler",
  3595. &pid, &policy, &param_obj)) {
  3596. goto exit;
  3597. }
  3598. return_value = os_sched_setscheduler_impl(module, pid, policy, param_obj);
  3599. exit:
  3600. return return_value;
  3601. }
  3602. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETSCHEDULER) */
  3603. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
  3604. PyDoc_STRVAR(os_sched_getparam__doc__,
  3605. "sched_getparam($module, pid, /)\n"
  3606. "--\n"
  3607. "\n"
  3608. "Returns scheduling parameters for the process identified by pid.\n"
  3609. "\n"
  3610. "If pid is 0, returns parameters for the calling process.\n"
  3611. "Return value is an instance of sched_param.");
  3612. #define OS_SCHED_GETPARAM_METHODDEF \
  3613. {"sched_getparam", (PyCFunction)os_sched_getparam, METH_O, os_sched_getparam__doc__},
  3614. static PyObject *
  3615. os_sched_getparam_impl(PyObject *module, pid_t pid);
  3616. static PyObject *
  3617. os_sched_getparam(PyObject *module, PyObject *arg)
  3618. {
  3619. PyObject *return_value = NULL;
  3620. pid_t pid;
  3621. if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getparam", &pid)) {
  3622. goto exit;
  3623. }
  3624. return_value = os_sched_getparam_impl(module, pid);
  3625. exit:
  3626. return return_value;
  3627. }
  3628. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
  3629. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM)
  3630. PyDoc_STRVAR(os_sched_setparam__doc__,
  3631. "sched_setparam($module, pid, param, /)\n"
  3632. "--\n"
  3633. "\n"
  3634. "Set scheduling parameters for the process identified by pid.\n"
  3635. "\n"
  3636. "If pid is 0, sets parameters for the calling process.\n"
  3637. "param should be an instance of sched_param.");
  3638. #define OS_SCHED_SETPARAM_METHODDEF \
  3639. {"sched_setparam", _PyCFunction_CAST(os_sched_setparam), METH_FASTCALL, os_sched_setparam__doc__},
  3640. static PyObject *
  3641. os_sched_setparam_impl(PyObject *module, pid_t pid, PyObject *param_obj);
  3642. static PyObject *
  3643. os_sched_setparam(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3644. {
  3645. PyObject *return_value = NULL;
  3646. pid_t pid;
  3647. PyObject *param_obj;
  3648. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setparam",
  3649. &pid, &param_obj)) {
  3650. goto exit;
  3651. }
  3652. return_value = os_sched_setparam_impl(module, pid, param_obj);
  3653. exit:
  3654. return return_value;
  3655. }
  3656. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETPARAM) */
  3657. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL)
  3658. PyDoc_STRVAR(os_sched_rr_get_interval__doc__,
  3659. "sched_rr_get_interval($module, pid, /)\n"
  3660. "--\n"
  3661. "\n"
  3662. "Return the round-robin quantum for the process identified by pid, in seconds.\n"
  3663. "\n"
  3664. "Value returned is a float.");
  3665. #define OS_SCHED_RR_GET_INTERVAL_METHODDEF \
  3666. {"sched_rr_get_interval", (PyCFunction)os_sched_rr_get_interval, METH_O, os_sched_rr_get_interval__doc__},
  3667. static double
  3668. os_sched_rr_get_interval_impl(PyObject *module, pid_t pid);
  3669. static PyObject *
  3670. os_sched_rr_get_interval(PyObject *module, PyObject *arg)
  3671. {
  3672. PyObject *return_value = NULL;
  3673. pid_t pid;
  3674. double _return_value;
  3675. if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_rr_get_interval", &pid)) {
  3676. goto exit;
  3677. }
  3678. _return_value = os_sched_rr_get_interval_impl(module, pid);
  3679. if ((_return_value == -1.0) && PyErr_Occurred()) {
  3680. goto exit;
  3681. }
  3682. return_value = PyFloat_FromDouble(_return_value);
  3683. exit:
  3684. return return_value;
  3685. }
  3686. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_RR_GET_INTERVAL) */
  3687. #if defined(HAVE_SCHED_H)
  3688. PyDoc_STRVAR(os_sched_yield__doc__,
  3689. "sched_yield($module, /)\n"
  3690. "--\n"
  3691. "\n"
  3692. "Voluntarily relinquish the CPU.");
  3693. #define OS_SCHED_YIELD_METHODDEF \
  3694. {"sched_yield", (PyCFunction)os_sched_yield, METH_NOARGS, os_sched_yield__doc__},
  3695. static PyObject *
  3696. os_sched_yield_impl(PyObject *module);
  3697. static PyObject *
  3698. os_sched_yield(PyObject *module, PyObject *Py_UNUSED(ignored))
  3699. {
  3700. return os_sched_yield_impl(module);
  3701. }
  3702. #endif /* defined(HAVE_SCHED_H) */
  3703. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
  3704. PyDoc_STRVAR(os_sched_setaffinity__doc__,
  3705. "sched_setaffinity($module, pid, mask, /)\n"
  3706. "--\n"
  3707. "\n"
  3708. "Set the CPU affinity of the process identified by pid to mask.\n"
  3709. "\n"
  3710. "mask should be an iterable of integers identifying CPUs.");
  3711. #define OS_SCHED_SETAFFINITY_METHODDEF \
  3712. {"sched_setaffinity", _PyCFunction_CAST(os_sched_setaffinity), METH_FASTCALL, os_sched_setaffinity__doc__},
  3713. static PyObject *
  3714. os_sched_setaffinity_impl(PyObject *module, pid_t pid, PyObject *mask);
  3715. static PyObject *
  3716. os_sched_setaffinity(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3717. {
  3718. PyObject *return_value = NULL;
  3719. pid_t pid;
  3720. PyObject *mask;
  3721. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "O:sched_setaffinity",
  3722. &pid, &mask)) {
  3723. goto exit;
  3724. }
  3725. return_value = os_sched_setaffinity_impl(module, pid, mask);
  3726. exit:
  3727. return return_value;
  3728. }
  3729. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
  3730. #if defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY)
  3731. PyDoc_STRVAR(os_sched_getaffinity__doc__,
  3732. "sched_getaffinity($module, pid, /)\n"
  3733. "--\n"
  3734. "\n"
  3735. "Return the affinity of the process identified by pid (or the current process if zero).\n"
  3736. "\n"
  3737. "The affinity is returned as a set of CPU identifiers.");
  3738. #define OS_SCHED_GETAFFINITY_METHODDEF \
  3739. {"sched_getaffinity", (PyCFunction)os_sched_getaffinity, METH_O, os_sched_getaffinity__doc__},
  3740. static PyObject *
  3741. os_sched_getaffinity_impl(PyObject *module, pid_t pid);
  3742. static PyObject *
  3743. os_sched_getaffinity(PyObject *module, PyObject *arg)
  3744. {
  3745. PyObject *return_value = NULL;
  3746. pid_t pid;
  3747. if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":sched_getaffinity", &pid)) {
  3748. goto exit;
  3749. }
  3750. return_value = os_sched_getaffinity_impl(module, pid);
  3751. exit:
  3752. return return_value;
  3753. }
  3754. #endif /* defined(HAVE_SCHED_H) && defined(HAVE_SCHED_SETAFFINITY) */
  3755. #if (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX))
  3756. PyDoc_STRVAR(os_openpty__doc__,
  3757. "openpty($module, /)\n"
  3758. "--\n"
  3759. "\n"
  3760. "Open a pseudo-terminal.\n"
  3761. "\n"
  3762. "Return a tuple of (master_fd, slave_fd) containing open file descriptors\n"
  3763. "for both the master and slave ends.");
  3764. #define OS_OPENPTY_METHODDEF \
  3765. {"openpty", (PyCFunction)os_openpty, METH_NOARGS, os_openpty__doc__},
  3766. static PyObject *
  3767. os_openpty_impl(PyObject *module);
  3768. static PyObject *
  3769. os_openpty(PyObject *module, PyObject *Py_UNUSED(ignored))
  3770. {
  3771. return os_openpty_impl(module);
  3772. }
  3773. #endif /* (defined(HAVE_OPENPTY) || defined(HAVE__GETPTY) || defined(HAVE_DEV_PTMX)) */
  3774. #if (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY))
  3775. PyDoc_STRVAR(os_login_tty__doc__,
  3776. "login_tty($module, fd, /)\n"
  3777. "--\n"
  3778. "\n"
  3779. "Prepare the tty of which fd is a file descriptor for a new login session.\n"
  3780. "\n"
  3781. "Make the calling process a session leader; make the tty the\n"
  3782. "controlling tty, the stdin, the stdout, and the stderr of the\n"
  3783. "calling process; close fd.");
  3784. #define OS_LOGIN_TTY_METHODDEF \
  3785. {"login_tty", (PyCFunction)os_login_tty, METH_O, os_login_tty__doc__},
  3786. static PyObject *
  3787. os_login_tty_impl(PyObject *module, int fd);
  3788. static PyObject *
  3789. os_login_tty(PyObject *module, PyObject *arg)
  3790. {
  3791. PyObject *return_value = NULL;
  3792. int fd;
  3793. if (!_PyLong_FileDescriptor_Converter(arg, &fd)) {
  3794. goto exit;
  3795. }
  3796. return_value = os_login_tty_impl(module, fd);
  3797. exit:
  3798. return return_value;
  3799. }
  3800. #endif /* (defined(HAVE_LOGIN_TTY) || defined(HAVE_FALLBACK_LOGIN_TTY)) */
  3801. #if defined(HAVE_FORKPTY)
  3802. PyDoc_STRVAR(os_forkpty__doc__,
  3803. "forkpty($module, /)\n"
  3804. "--\n"
  3805. "\n"
  3806. "Fork a new process with a new pseudo-terminal as controlling tty.\n"
  3807. "\n"
  3808. "Returns a tuple of (pid, master_fd).\n"
  3809. "Like fork(), return pid of 0 to the child process,\n"
  3810. "and pid of child to the parent process.\n"
  3811. "To both, return fd of newly opened pseudo-terminal.");
  3812. #define OS_FORKPTY_METHODDEF \
  3813. {"forkpty", (PyCFunction)os_forkpty, METH_NOARGS, os_forkpty__doc__},
  3814. static PyObject *
  3815. os_forkpty_impl(PyObject *module);
  3816. static PyObject *
  3817. os_forkpty(PyObject *module, PyObject *Py_UNUSED(ignored))
  3818. {
  3819. return os_forkpty_impl(module);
  3820. }
  3821. #endif /* defined(HAVE_FORKPTY) */
  3822. #if defined(HAVE_GETEGID)
  3823. PyDoc_STRVAR(os_getegid__doc__,
  3824. "getegid($module, /)\n"
  3825. "--\n"
  3826. "\n"
  3827. "Return the current process\'s effective group id.");
  3828. #define OS_GETEGID_METHODDEF \
  3829. {"getegid", (PyCFunction)os_getegid, METH_NOARGS, os_getegid__doc__},
  3830. static PyObject *
  3831. os_getegid_impl(PyObject *module);
  3832. static PyObject *
  3833. os_getegid(PyObject *module, PyObject *Py_UNUSED(ignored))
  3834. {
  3835. return os_getegid_impl(module);
  3836. }
  3837. #endif /* defined(HAVE_GETEGID) */
  3838. #if defined(HAVE_GETEUID)
  3839. PyDoc_STRVAR(os_geteuid__doc__,
  3840. "geteuid($module, /)\n"
  3841. "--\n"
  3842. "\n"
  3843. "Return the current process\'s effective user id.");
  3844. #define OS_GETEUID_METHODDEF \
  3845. {"geteuid", (PyCFunction)os_geteuid, METH_NOARGS, os_geteuid__doc__},
  3846. static PyObject *
  3847. os_geteuid_impl(PyObject *module);
  3848. static PyObject *
  3849. os_geteuid(PyObject *module, PyObject *Py_UNUSED(ignored))
  3850. {
  3851. return os_geteuid_impl(module);
  3852. }
  3853. #endif /* defined(HAVE_GETEUID) */
  3854. #if defined(HAVE_GETGID)
  3855. PyDoc_STRVAR(os_getgid__doc__,
  3856. "getgid($module, /)\n"
  3857. "--\n"
  3858. "\n"
  3859. "Return the current process\'s group id.");
  3860. #define OS_GETGID_METHODDEF \
  3861. {"getgid", (PyCFunction)os_getgid, METH_NOARGS, os_getgid__doc__},
  3862. static PyObject *
  3863. os_getgid_impl(PyObject *module);
  3864. static PyObject *
  3865. os_getgid(PyObject *module, PyObject *Py_UNUSED(ignored))
  3866. {
  3867. return os_getgid_impl(module);
  3868. }
  3869. #endif /* defined(HAVE_GETGID) */
  3870. #if defined(HAVE_GETPID)
  3871. PyDoc_STRVAR(os_getpid__doc__,
  3872. "getpid($module, /)\n"
  3873. "--\n"
  3874. "\n"
  3875. "Return the current process id.");
  3876. #define OS_GETPID_METHODDEF \
  3877. {"getpid", (PyCFunction)os_getpid, METH_NOARGS, os_getpid__doc__},
  3878. static PyObject *
  3879. os_getpid_impl(PyObject *module);
  3880. static PyObject *
  3881. os_getpid(PyObject *module, PyObject *Py_UNUSED(ignored))
  3882. {
  3883. return os_getpid_impl(module);
  3884. }
  3885. #endif /* defined(HAVE_GETPID) */
  3886. #if defined(HAVE_GETGROUPLIST) && defined(__APPLE__)
  3887. PyDoc_STRVAR(os_getgrouplist__doc__,
  3888. "getgrouplist($module, user, group, /)\n"
  3889. "--\n"
  3890. "\n"
  3891. "Returns a list of groups to which a user belongs.\n"
  3892. "\n"
  3893. " user\n"
  3894. " username to lookup\n"
  3895. " group\n"
  3896. " base group id of the user");
  3897. #define OS_GETGROUPLIST_METHODDEF \
  3898. {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
  3899. static PyObject *
  3900. os_getgrouplist_impl(PyObject *module, const char *user, int basegid);
  3901. static PyObject *
  3902. os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3903. {
  3904. PyObject *return_value = NULL;
  3905. const char *user;
  3906. int basegid;
  3907. if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
  3908. goto exit;
  3909. }
  3910. if (!PyUnicode_Check(args[0])) {
  3911. _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
  3912. goto exit;
  3913. }
  3914. Py_ssize_t user_length;
  3915. user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
  3916. if (user == NULL) {
  3917. goto exit;
  3918. }
  3919. if (strlen(user) != (size_t)user_length) {
  3920. PyErr_SetString(PyExc_ValueError, "embedded null character");
  3921. goto exit;
  3922. }
  3923. basegid = _PyLong_AsInt(args[1]);
  3924. if (basegid == -1 && PyErr_Occurred()) {
  3925. goto exit;
  3926. }
  3927. return_value = os_getgrouplist_impl(module, user, basegid);
  3928. exit:
  3929. return return_value;
  3930. }
  3931. #endif /* defined(HAVE_GETGROUPLIST) && defined(__APPLE__) */
  3932. #if defined(HAVE_GETGROUPLIST) && !defined(__APPLE__)
  3933. PyDoc_STRVAR(os_getgrouplist__doc__,
  3934. "getgrouplist($module, user, group, /)\n"
  3935. "--\n"
  3936. "\n"
  3937. "Returns a list of groups to which a user belongs.\n"
  3938. "\n"
  3939. " user\n"
  3940. " username to lookup\n"
  3941. " group\n"
  3942. " base group id of the user");
  3943. #define OS_GETGROUPLIST_METHODDEF \
  3944. {"getgrouplist", _PyCFunction_CAST(os_getgrouplist), METH_FASTCALL, os_getgrouplist__doc__},
  3945. static PyObject *
  3946. os_getgrouplist_impl(PyObject *module, const char *user, gid_t basegid);
  3947. static PyObject *
  3948. os_getgrouplist(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  3949. {
  3950. PyObject *return_value = NULL;
  3951. const char *user;
  3952. gid_t basegid;
  3953. if (!_PyArg_CheckPositional("getgrouplist", nargs, 2, 2)) {
  3954. goto exit;
  3955. }
  3956. if (!PyUnicode_Check(args[0])) {
  3957. _PyArg_BadArgument("getgrouplist", "argument 1", "str", args[0]);
  3958. goto exit;
  3959. }
  3960. Py_ssize_t user_length;
  3961. user = PyUnicode_AsUTF8AndSize(args[0], &user_length);
  3962. if (user == NULL) {
  3963. goto exit;
  3964. }
  3965. if (strlen(user) != (size_t)user_length) {
  3966. PyErr_SetString(PyExc_ValueError, "embedded null character");
  3967. goto exit;
  3968. }
  3969. if (!_Py_Gid_Converter(args[1], &basegid)) {
  3970. goto exit;
  3971. }
  3972. return_value = os_getgrouplist_impl(module, user, basegid);
  3973. exit:
  3974. return return_value;
  3975. }
  3976. #endif /* defined(HAVE_GETGROUPLIST) && !defined(__APPLE__) */
  3977. #if defined(HAVE_GETGROUPS)
  3978. PyDoc_STRVAR(os_getgroups__doc__,
  3979. "getgroups($module, /)\n"
  3980. "--\n"
  3981. "\n"
  3982. "Return list of supplemental group IDs for the process.");
  3983. #define OS_GETGROUPS_METHODDEF \
  3984. {"getgroups", (PyCFunction)os_getgroups, METH_NOARGS, os_getgroups__doc__},
  3985. static PyObject *
  3986. os_getgroups_impl(PyObject *module);
  3987. static PyObject *
  3988. os_getgroups(PyObject *module, PyObject *Py_UNUSED(ignored))
  3989. {
  3990. return os_getgroups_impl(module);
  3991. }
  3992. #endif /* defined(HAVE_GETGROUPS) */
  3993. #if defined(HAVE_INITGROUPS) && defined(__APPLE__)
  3994. PyDoc_STRVAR(os_initgroups__doc__,
  3995. "initgroups($module, username, gid, /)\n"
  3996. "--\n"
  3997. "\n"
  3998. "Initialize the group access list.\n"
  3999. "\n"
  4000. "Call the system initgroups() to initialize the group access list with all of\n"
  4001. "the groups of which the specified username is a member, plus the specified\n"
  4002. "group id.");
  4003. #define OS_INITGROUPS_METHODDEF \
  4004. {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
  4005. static PyObject *
  4006. os_initgroups_impl(PyObject *module, PyObject *oname, int gid);
  4007. static PyObject *
  4008. os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4009. {
  4010. PyObject *return_value = NULL;
  4011. PyObject *oname = NULL;
  4012. int gid;
  4013. if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
  4014. goto exit;
  4015. }
  4016. if (!PyUnicode_FSConverter(args[0], &oname)) {
  4017. goto exit;
  4018. }
  4019. gid = _PyLong_AsInt(args[1]);
  4020. if (gid == -1 && PyErr_Occurred()) {
  4021. goto exit;
  4022. }
  4023. return_value = os_initgroups_impl(module, oname, gid);
  4024. exit:
  4025. /* Cleanup for oname */
  4026. Py_XDECREF(oname);
  4027. return return_value;
  4028. }
  4029. #endif /* defined(HAVE_INITGROUPS) && defined(__APPLE__) */
  4030. #if defined(HAVE_INITGROUPS) && !defined(__APPLE__)
  4031. PyDoc_STRVAR(os_initgroups__doc__,
  4032. "initgroups($module, username, gid, /)\n"
  4033. "--\n"
  4034. "\n"
  4035. "Initialize the group access list.\n"
  4036. "\n"
  4037. "Call the system initgroups() to initialize the group access list with all of\n"
  4038. "the groups of which the specified username is a member, plus the specified\n"
  4039. "group id.");
  4040. #define OS_INITGROUPS_METHODDEF \
  4041. {"initgroups", _PyCFunction_CAST(os_initgroups), METH_FASTCALL, os_initgroups__doc__},
  4042. static PyObject *
  4043. os_initgroups_impl(PyObject *module, PyObject *oname, gid_t gid);
  4044. static PyObject *
  4045. os_initgroups(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4046. {
  4047. PyObject *return_value = NULL;
  4048. PyObject *oname = NULL;
  4049. gid_t gid;
  4050. if (!_PyArg_CheckPositional("initgroups", nargs, 2, 2)) {
  4051. goto exit;
  4052. }
  4053. if (!PyUnicode_FSConverter(args[0], &oname)) {
  4054. goto exit;
  4055. }
  4056. if (!_Py_Gid_Converter(args[1], &gid)) {
  4057. goto exit;
  4058. }
  4059. return_value = os_initgroups_impl(module, oname, gid);
  4060. exit:
  4061. /* Cleanup for oname */
  4062. Py_XDECREF(oname);
  4063. return return_value;
  4064. }
  4065. #endif /* defined(HAVE_INITGROUPS) && !defined(__APPLE__) */
  4066. #if defined(HAVE_GETPGID)
  4067. PyDoc_STRVAR(os_getpgid__doc__,
  4068. "getpgid($module, /, pid)\n"
  4069. "--\n"
  4070. "\n"
  4071. "Call the system call getpgid(), and return the result.");
  4072. #define OS_GETPGID_METHODDEF \
  4073. {"getpgid", _PyCFunction_CAST(os_getpgid), METH_FASTCALL|METH_KEYWORDS, os_getpgid__doc__},
  4074. static PyObject *
  4075. os_getpgid_impl(PyObject *module, pid_t pid);
  4076. static PyObject *
  4077. os_getpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4078. {
  4079. PyObject *return_value = NULL;
  4080. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4081. #define NUM_KEYWORDS 1
  4082. static struct {
  4083. PyGC_Head _this_is_not_used;
  4084. PyObject_VAR_HEAD
  4085. PyObject *ob_item[NUM_KEYWORDS];
  4086. } _kwtuple = {
  4087. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4088. .ob_item = { &_Py_ID(pid), },
  4089. };
  4090. #undef NUM_KEYWORDS
  4091. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4092. #else // !Py_BUILD_CORE
  4093. # define KWTUPLE NULL
  4094. #endif // !Py_BUILD_CORE
  4095. static const char * const _keywords[] = {"pid", NULL};
  4096. static _PyArg_Parser _parser = {
  4097. .keywords = _keywords,
  4098. .format = "" _Py_PARSE_PID ":getpgid",
  4099. .kwtuple = KWTUPLE,
  4100. };
  4101. #undef KWTUPLE
  4102. pid_t pid;
  4103. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  4104. &pid)) {
  4105. goto exit;
  4106. }
  4107. return_value = os_getpgid_impl(module, pid);
  4108. exit:
  4109. return return_value;
  4110. }
  4111. #endif /* defined(HAVE_GETPGID) */
  4112. #if defined(HAVE_GETPGRP)
  4113. PyDoc_STRVAR(os_getpgrp__doc__,
  4114. "getpgrp($module, /)\n"
  4115. "--\n"
  4116. "\n"
  4117. "Return the current process group id.");
  4118. #define OS_GETPGRP_METHODDEF \
  4119. {"getpgrp", (PyCFunction)os_getpgrp, METH_NOARGS, os_getpgrp__doc__},
  4120. static PyObject *
  4121. os_getpgrp_impl(PyObject *module);
  4122. static PyObject *
  4123. os_getpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
  4124. {
  4125. return os_getpgrp_impl(module);
  4126. }
  4127. #endif /* defined(HAVE_GETPGRP) */
  4128. #if defined(HAVE_SETPGRP)
  4129. PyDoc_STRVAR(os_setpgrp__doc__,
  4130. "setpgrp($module, /)\n"
  4131. "--\n"
  4132. "\n"
  4133. "Make the current process the leader of its process group.");
  4134. #define OS_SETPGRP_METHODDEF \
  4135. {"setpgrp", (PyCFunction)os_setpgrp, METH_NOARGS, os_setpgrp__doc__},
  4136. static PyObject *
  4137. os_setpgrp_impl(PyObject *module);
  4138. static PyObject *
  4139. os_setpgrp(PyObject *module, PyObject *Py_UNUSED(ignored))
  4140. {
  4141. return os_setpgrp_impl(module);
  4142. }
  4143. #endif /* defined(HAVE_SETPGRP) */
  4144. #if defined(HAVE_GETPPID)
  4145. PyDoc_STRVAR(os_getppid__doc__,
  4146. "getppid($module, /)\n"
  4147. "--\n"
  4148. "\n"
  4149. "Return the parent\'s process id.\n"
  4150. "\n"
  4151. "If the parent process has already exited, Windows machines will still\n"
  4152. "return its id; others systems will return the id of the \'init\' process (1).");
  4153. #define OS_GETPPID_METHODDEF \
  4154. {"getppid", (PyCFunction)os_getppid, METH_NOARGS, os_getppid__doc__},
  4155. static PyObject *
  4156. os_getppid_impl(PyObject *module);
  4157. static PyObject *
  4158. os_getppid(PyObject *module, PyObject *Py_UNUSED(ignored))
  4159. {
  4160. return os_getppid_impl(module);
  4161. }
  4162. #endif /* defined(HAVE_GETPPID) */
  4163. #if defined(HAVE_GETLOGIN)
  4164. PyDoc_STRVAR(os_getlogin__doc__,
  4165. "getlogin($module, /)\n"
  4166. "--\n"
  4167. "\n"
  4168. "Return the actual login name.");
  4169. #define OS_GETLOGIN_METHODDEF \
  4170. {"getlogin", (PyCFunction)os_getlogin, METH_NOARGS, os_getlogin__doc__},
  4171. static PyObject *
  4172. os_getlogin_impl(PyObject *module);
  4173. static PyObject *
  4174. os_getlogin(PyObject *module, PyObject *Py_UNUSED(ignored))
  4175. {
  4176. return os_getlogin_impl(module);
  4177. }
  4178. #endif /* defined(HAVE_GETLOGIN) */
  4179. #if defined(HAVE_GETUID)
  4180. PyDoc_STRVAR(os_getuid__doc__,
  4181. "getuid($module, /)\n"
  4182. "--\n"
  4183. "\n"
  4184. "Return the current process\'s user id.");
  4185. #define OS_GETUID_METHODDEF \
  4186. {"getuid", (PyCFunction)os_getuid, METH_NOARGS, os_getuid__doc__},
  4187. static PyObject *
  4188. os_getuid_impl(PyObject *module);
  4189. static PyObject *
  4190. os_getuid(PyObject *module, PyObject *Py_UNUSED(ignored))
  4191. {
  4192. return os_getuid_impl(module);
  4193. }
  4194. #endif /* defined(HAVE_GETUID) */
  4195. #if defined(HAVE_KILL)
  4196. PyDoc_STRVAR(os_kill__doc__,
  4197. "kill($module, pid, signal, /)\n"
  4198. "--\n"
  4199. "\n"
  4200. "Kill a process with a signal.");
  4201. #define OS_KILL_METHODDEF \
  4202. {"kill", _PyCFunction_CAST(os_kill), METH_FASTCALL, os_kill__doc__},
  4203. static PyObject *
  4204. os_kill_impl(PyObject *module, pid_t pid, Py_ssize_t signal);
  4205. static PyObject *
  4206. os_kill(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4207. {
  4208. PyObject *return_value = NULL;
  4209. pid_t pid;
  4210. Py_ssize_t signal;
  4211. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "n:kill",
  4212. &pid, &signal)) {
  4213. goto exit;
  4214. }
  4215. return_value = os_kill_impl(module, pid, signal);
  4216. exit:
  4217. return return_value;
  4218. }
  4219. #endif /* defined(HAVE_KILL) */
  4220. #if defined(HAVE_KILLPG)
  4221. PyDoc_STRVAR(os_killpg__doc__,
  4222. "killpg($module, pgid, signal, /)\n"
  4223. "--\n"
  4224. "\n"
  4225. "Kill a process group with a signal.");
  4226. #define OS_KILLPG_METHODDEF \
  4227. {"killpg", _PyCFunction_CAST(os_killpg), METH_FASTCALL, os_killpg__doc__},
  4228. static PyObject *
  4229. os_killpg_impl(PyObject *module, pid_t pgid, int signal);
  4230. static PyObject *
  4231. os_killpg(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4232. {
  4233. PyObject *return_value = NULL;
  4234. pid_t pgid;
  4235. int signal;
  4236. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:killpg",
  4237. &pgid, &signal)) {
  4238. goto exit;
  4239. }
  4240. return_value = os_killpg_impl(module, pgid, signal);
  4241. exit:
  4242. return return_value;
  4243. }
  4244. #endif /* defined(HAVE_KILLPG) */
  4245. #if defined(HAVE_PLOCK)
  4246. PyDoc_STRVAR(os_plock__doc__,
  4247. "plock($module, op, /)\n"
  4248. "--\n"
  4249. "\n"
  4250. "Lock program segments into memory.\");");
  4251. #define OS_PLOCK_METHODDEF \
  4252. {"plock", (PyCFunction)os_plock, METH_O, os_plock__doc__},
  4253. static PyObject *
  4254. os_plock_impl(PyObject *module, int op);
  4255. static PyObject *
  4256. os_plock(PyObject *module, PyObject *arg)
  4257. {
  4258. PyObject *return_value = NULL;
  4259. int op;
  4260. op = _PyLong_AsInt(arg);
  4261. if (op == -1 && PyErr_Occurred()) {
  4262. goto exit;
  4263. }
  4264. return_value = os_plock_impl(module, op);
  4265. exit:
  4266. return return_value;
  4267. }
  4268. #endif /* defined(HAVE_PLOCK) */
  4269. #if defined(HAVE_SETUID)
  4270. PyDoc_STRVAR(os_setuid__doc__,
  4271. "setuid($module, uid, /)\n"
  4272. "--\n"
  4273. "\n"
  4274. "Set the current process\'s user id.");
  4275. #define OS_SETUID_METHODDEF \
  4276. {"setuid", (PyCFunction)os_setuid, METH_O, os_setuid__doc__},
  4277. static PyObject *
  4278. os_setuid_impl(PyObject *module, uid_t uid);
  4279. static PyObject *
  4280. os_setuid(PyObject *module, PyObject *arg)
  4281. {
  4282. PyObject *return_value = NULL;
  4283. uid_t uid;
  4284. if (!_Py_Uid_Converter(arg, &uid)) {
  4285. goto exit;
  4286. }
  4287. return_value = os_setuid_impl(module, uid);
  4288. exit:
  4289. return return_value;
  4290. }
  4291. #endif /* defined(HAVE_SETUID) */
  4292. #if defined(HAVE_SETEUID)
  4293. PyDoc_STRVAR(os_seteuid__doc__,
  4294. "seteuid($module, euid, /)\n"
  4295. "--\n"
  4296. "\n"
  4297. "Set the current process\'s effective user id.");
  4298. #define OS_SETEUID_METHODDEF \
  4299. {"seteuid", (PyCFunction)os_seteuid, METH_O, os_seteuid__doc__},
  4300. static PyObject *
  4301. os_seteuid_impl(PyObject *module, uid_t euid);
  4302. static PyObject *
  4303. os_seteuid(PyObject *module, PyObject *arg)
  4304. {
  4305. PyObject *return_value = NULL;
  4306. uid_t euid;
  4307. if (!_Py_Uid_Converter(arg, &euid)) {
  4308. goto exit;
  4309. }
  4310. return_value = os_seteuid_impl(module, euid);
  4311. exit:
  4312. return return_value;
  4313. }
  4314. #endif /* defined(HAVE_SETEUID) */
  4315. #if defined(HAVE_SETEGID)
  4316. PyDoc_STRVAR(os_setegid__doc__,
  4317. "setegid($module, egid, /)\n"
  4318. "--\n"
  4319. "\n"
  4320. "Set the current process\'s effective group id.");
  4321. #define OS_SETEGID_METHODDEF \
  4322. {"setegid", (PyCFunction)os_setegid, METH_O, os_setegid__doc__},
  4323. static PyObject *
  4324. os_setegid_impl(PyObject *module, gid_t egid);
  4325. static PyObject *
  4326. os_setegid(PyObject *module, PyObject *arg)
  4327. {
  4328. PyObject *return_value = NULL;
  4329. gid_t egid;
  4330. if (!_Py_Gid_Converter(arg, &egid)) {
  4331. goto exit;
  4332. }
  4333. return_value = os_setegid_impl(module, egid);
  4334. exit:
  4335. return return_value;
  4336. }
  4337. #endif /* defined(HAVE_SETEGID) */
  4338. #if defined(HAVE_SETREUID)
  4339. PyDoc_STRVAR(os_setreuid__doc__,
  4340. "setreuid($module, ruid, euid, /)\n"
  4341. "--\n"
  4342. "\n"
  4343. "Set the current process\'s real and effective user ids.");
  4344. #define OS_SETREUID_METHODDEF \
  4345. {"setreuid", _PyCFunction_CAST(os_setreuid), METH_FASTCALL, os_setreuid__doc__},
  4346. static PyObject *
  4347. os_setreuid_impl(PyObject *module, uid_t ruid, uid_t euid);
  4348. static PyObject *
  4349. os_setreuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4350. {
  4351. PyObject *return_value = NULL;
  4352. uid_t ruid;
  4353. uid_t euid;
  4354. if (!_PyArg_CheckPositional("setreuid", nargs, 2, 2)) {
  4355. goto exit;
  4356. }
  4357. if (!_Py_Uid_Converter(args[0], &ruid)) {
  4358. goto exit;
  4359. }
  4360. if (!_Py_Uid_Converter(args[1], &euid)) {
  4361. goto exit;
  4362. }
  4363. return_value = os_setreuid_impl(module, ruid, euid);
  4364. exit:
  4365. return return_value;
  4366. }
  4367. #endif /* defined(HAVE_SETREUID) */
  4368. #if defined(HAVE_SETREGID)
  4369. PyDoc_STRVAR(os_setregid__doc__,
  4370. "setregid($module, rgid, egid, /)\n"
  4371. "--\n"
  4372. "\n"
  4373. "Set the current process\'s real and effective group ids.");
  4374. #define OS_SETREGID_METHODDEF \
  4375. {"setregid", _PyCFunction_CAST(os_setregid), METH_FASTCALL, os_setregid__doc__},
  4376. static PyObject *
  4377. os_setregid_impl(PyObject *module, gid_t rgid, gid_t egid);
  4378. static PyObject *
  4379. os_setregid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4380. {
  4381. PyObject *return_value = NULL;
  4382. gid_t rgid;
  4383. gid_t egid;
  4384. if (!_PyArg_CheckPositional("setregid", nargs, 2, 2)) {
  4385. goto exit;
  4386. }
  4387. if (!_Py_Gid_Converter(args[0], &rgid)) {
  4388. goto exit;
  4389. }
  4390. if (!_Py_Gid_Converter(args[1], &egid)) {
  4391. goto exit;
  4392. }
  4393. return_value = os_setregid_impl(module, rgid, egid);
  4394. exit:
  4395. return return_value;
  4396. }
  4397. #endif /* defined(HAVE_SETREGID) */
  4398. #if defined(HAVE_SETGID)
  4399. PyDoc_STRVAR(os_setgid__doc__,
  4400. "setgid($module, gid, /)\n"
  4401. "--\n"
  4402. "\n"
  4403. "Set the current process\'s group id.");
  4404. #define OS_SETGID_METHODDEF \
  4405. {"setgid", (PyCFunction)os_setgid, METH_O, os_setgid__doc__},
  4406. static PyObject *
  4407. os_setgid_impl(PyObject *module, gid_t gid);
  4408. static PyObject *
  4409. os_setgid(PyObject *module, PyObject *arg)
  4410. {
  4411. PyObject *return_value = NULL;
  4412. gid_t gid;
  4413. if (!_Py_Gid_Converter(arg, &gid)) {
  4414. goto exit;
  4415. }
  4416. return_value = os_setgid_impl(module, gid);
  4417. exit:
  4418. return return_value;
  4419. }
  4420. #endif /* defined(HAVE_SETGID) */
  4421. #if defined(HAVE_SETGROUPS)
  4422. PyDoc_STRVAR(os_setgroups__doc__,
  4423. "setgroups($module, groups, /)\n"
  4424. "--\n"
  4425. "\n"
  4426. "Set the groups of the current process to list.");
  4427. #define OS_SETGROUPS_METHODDEF \
  4428. {"setgroups", (PyCFunction)os_setgroups, METH_O, os_setgroups__doc__},
  4429. #endif /* defined(HAVE_SETGROUPS) */
  4430. #if defined(HAVE_WAIT3)
  4431. PyDoc_STRVAR(os_wait3__doc__,
  4432. "wait3($module, /, options)\n"
  4433. "--\n"
  4434. "\n"
  4435. "Wait for completion of a child process.\n"
  4436. "\n"
  4437. "Returns a tuple of information about the child process:\n"
  4438. " (pid, status, rusage)");
  4439. #define OS_WAIT3_METHODDEF \
  4440. {"wait3", _PyCFunction_CAST(os_wait3), METH_FASTCALL|METH_KEYWORDS, os_wait3__doc__},
  4441. static PyObject *
  4442. os_wait3_impl(PyObject *module, int options);
  4443. static PyObject *
  4444. os_wait3(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4445. {
  4446. PyObject *return_value = NULL;
  4447. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4448. #define NUM_KEYWORDS 1
  4449. static struct {
  4450. PyGC_Head _this_is_not_used;
  4451. PyObject_VAR_HEAD
  4452. PyObject *ob_item[NUM_KEYWORDS];
  4453. } _kwtuple = {
  4454. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4455. .ob_item = { &_Py_ID(options), },
  4456. };
  4457. #undef NUM_KEYWORDS
  4458. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4459. #else // !Py_BUILD_CORE
  4460. # define KWTUPLE NULL
  4461. #endif // !Py_BUILD_CORE
  4462. static const char * const _keywords[] = {"options", NULL};
  4463. static _PyArg_Parser _parser = {
  4464. .keywords = _keywords,
  4465. .fname = "wait3",
  4466. .kwtuple = KWTUPLE,
  4467. };
  4468. #undef KWTUPLE
  4469. PyObject *argsbuf[1];
  4470. int options;
  4471. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  4472. if (!args) {
  4473. goto exit;
  4474. }
  4475. options = _PyLong_AsInt(args[0]);
  4476. if (options == -1 && PyErr_Occurred()) {
  4477. goto exit;
  4478. }
  4479. return_value = os_wait3_impl(module, options);
  4480. exit:
  4481. return return_value;
  4482. }
  4483. #endif /* defined(HAVE_WAIT3) */
  4484. #if defined(HAVE_WAIT4)
  4485. PyDoc_STRVAR(os_wait4__doc__,
  4486. "wait4($module, /, pid, options)\n"
  4487. "--\n"
  4488. "\n"
  4489. "Wait for completion of a specific child process.\n"
  4490. "\n"
  4491. "Returns a tuple of information about the child process:\n"
  4492. " (pid, status, rusage)");
  4493. #define OS_WAIT4_METHODDEF \
  4494. {"wait4", _PyCFunction_CAST(os_wait4), METH_FASTCALL|METH_KEYWORDS, os_wait4__doc__},
  4495. static PyObject *
  4496. os_wait4_impl(PyObject *module, pid_t pid, int options);
  4497. static PyObject *
  4498. os_wait4(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4499. {
  4500. PyObject *return_value = NULL;
  4501. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4502. #define NUM_KEYWORDS 2
  4503. static struct {
  4504. PyGC_Head _this_is_not_used;
  4505. PyObject_VAR_HEAD
  4506. PyObject *ob_item[NUM_KEYWORDS];
  4507. } _kwtuple = {
  4508. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4509. .ob_item = { &_Py_ID(pid), &_Py_ID(options), },
  4510. };
  4511. #undef NUM_KEYWORDS
  4512. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4513. #else // !Py_BUILD_CORE
  4514. # define KWTUPLE NULL
  4515. #endif // !Py_BUILD_CORE
  4516. static const char * const _keywords[] = {"pid", "options", NULL};
  4517. static _PyArg_Parser _parser = {
  4518. .keywords = _keywords,
  4519. .format = "" _Py_PARSE_PID "i:wait4",
  4520. .kwtuple = KWTUPLE,
  4521. };
  4522. #undef KWTUPLE
  4523. pid_t pid;
  4524. int options;
  4525. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  4526. &pid, &options)) {
  4527. goto exit;
  4528. }
  4529. return_value = os_wait4_impl(module, pid, options);
  4530. exit:
  4531. return return_value;
  4532. }
  4533. #endif /* defined(HAVE_WAIT4) */
  4534. #if (defined(HAVE_WAITID) && !defined(__APPLE__))
  4535. PyDoc_STRVAR(os_waitid__doc__,
  4536. "waitid($module, idtype, id, options, /)\n"
  4537. "--\n"
  4538. "\n"
  4539. "Returns the result of waiting for a process or processes.\n"
  4540. "\n"
  4541. " idtype\n"
  4542. " Must be one of be P_PID, P_PGID or P_ALL.\n"
  4543. " id\n"
  4544. " The id to wait on.\n"
  4545. " options\n"
  4546. " Constructed from the ORing of one or more of WEXITED, WSTOPPED\n"
  4547. " or WCONTINUED and additionally may be ORed with WNOHANG or WNOWAIT.\n"
  4548. "\n"
  4549. "Returns either waitid_result or None if WNOHANG is specified and there are\n"
  4550. "no children in a waitable state.");
  4551. #define OS_WAITID_METHODDEF \
  4552. {"waitid", _PyCFunction_CAST(os_waitid), METH_FASTCALL, os_waitid__doc__},
  4553. static PyObject *
  4554. os_waitid_impl(PyObject *module, idtype_t idtype, id_t id, int options);
  4555. static PyObject *
  4556. os_waitid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4557. {
  4558. PyObject *return_value = NULL;
  4559. idtype_t idtype;
  4560. id_t id;
  4561. int options;
  4562. if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID "i:waitid",
  4563. &idtype, &id, &options)) {
  4564. goto exit;
  4565. }
  4566. return_value = os_waitid_impl(module, idtype, id, options);
  4567. exit:
  4568. return return_value;
  4569. }
  4570. #endif /* (defined(HAVE_WAITID) && !defined(__APPLE__)) */
  4571. #if defined(HAVE_WAITPID)
  4572. PyDoc_STRVAR(os_waitpid__doc__,
  4573. "waitpid($module, pid, options, /)\n"
  4574. "--\n"
  4575. "\n"
  4576. "Wait for completion of a given child process.\n"
  4577. "\n"
  4578. "Returns a tuple of information regarding the child process:\n"
  4579. " (pid, status)\n"
  4580. "\n"
  4581. "The options argument is ignored on Windows.");
  4582. #define OS_WAITPID_METHODDEF \
  4583. {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
  4584. static PyObject *
  4585. os_waitpid_impl(PyObject *module, pid_t pid, int options);
  4586. static PyObject *
  4587. os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4588. {
  4589. PyObject *return_value = NULL;
  4590. pid_t pid;
  4591. int options;
  4592. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "i:waitpid",
  4593. &pid, &options)) {
  4594. goto exit;
  4595. }
  4596. return_value = os_waitpid_impl(module, pid, options);
  4597. exit:
  4598. return return_value;
  4599. }
  4600. #endif /* defined(HAVE_WAITPID) */
  4601. #if !defined(HAVE_WAITPID) && defined(HAVE_CWAIT)
  4602. PyDoc_STRVAR(os_waitpid__doc__,
  4603. "waitpid($module, pid, options, /)\n"
  4604. "--\n"
  4605. "\n"
  4606. "Wait for completion of a given process.\n"
  4607. "\n"
  4608. "Returns a tuple of information regarding the process:\n"
  4609. " (pid, status << 8)\n"
  4610. "\n"
  4611. "The options argument is ignored on Windows.");
  4612. #define OS_WAITPID_METHODDEF \
  4613. {"waitpid", _PyCFunction_CAST(os_waitpid), METH_FASTCALL, os_waitpid__doc__},
  4614. static PyObject *
  4615. os_waitpid_impl(PyObject *module, intptr_t pid, int options);
  4616. static PyObject *
  4617. os_waitpid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  4618. {
  4619. PyObject *return_value = NULL;
  4620. intptr_t pid;
  4621. int options;
  4622. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "i:waitpid",
  4623. &pid, &options)) {
  4624. goto exit;
  4625. }
  4626. return_value = os_waitpid_impl(module, pid, options);
  4627. exit:
  4628. return return_value;
  4629. }
  4630. #endif /* !defined(HAVE_WAITPID) && defined(HAVE_CWAIT) */
  4631. #if defined(HAVE_WAIT)
  4632. PyDoc_STRVAR(os_wait__doc__,
  4633. "wait($module, /)\n"
  4634. "--\n"
  4635. "\n"
  4636. "Wait for completion of a child process.\n"
  4637. "\n"
  4638. "Returns a tuple of information about the child process:\n"
  4639. " (pid, status)");
  4640. #define OS_WAIT_METHODDEF \
  4641. {"wait", (PyCFunction)os_wait, METH_NOARGS, os_wait__doc__},
  4642. static PyObject *
  4643. os_wait_impl(PyObject *module);
  4644. static PyObject *
  4645. os_wait(PyObject *module, PyObject *Py_UNUSED(ignored))
  4646. {
  4647. return os_wait_impl(module);
  4648. }
  4649. #endif /* defined(HAVE_WAIT) */
  4650. #if (defined(__linux__) && defined(__NR_pidfd_open))
  4651. PyDoc_STRVAR(os_pidfd_open__doc__,
  4652. "pidfd_open($module, /, pid, flags=0)\n"
  4653. "--\n"
  4654. "\n"
  4655. "Return a file descriptor referring to the process *pid*.\n"
  4656. "\n"
  4657. "The descriptor can be used to perform process management without races and\n"
  4658. "signals.");
  4659. #define OS_PIDFD_OPEN_METHODDEF \
  4660. {"pidfd_open", _PyCFunction_CAST(os_pidfd_open), METH_FASTCALL|METH_KEYWORDS, os_pidfd_open__doc__},
  4661. static PyObject *
  4662. os_pidfd_open_impl(PyObject *module, pid_t pid, unsigned int flags);
  4663. static PyObject *
  4664. os_pidfd_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4665. {
  4666. PyObject *return_value = NULL;
  4667. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4668. #define NUM_KEYWORDS 2
  4669. static struct {
  4670. PyGC_Head _this_is_not_used;
  4671. PyObject_VAR_HEAD
  4672. PyObject *ob_item[NUM_KEYWORDS];
  4673. } _kwtuple = {
  4674. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4675. .ob_item = { &_Py_ID(pid), &_Py_ID(flags), },
  4676. };
  4677. #undef NUM_KEYWORDS
  4678. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4679. #else // !Py_BUILD_CORE
  4680. # define KWTUPLE NULL
  4681. #endif // !Py_BUILD_CORE
  4682. static const char * const _keywords[] = {"pid", "flags", NULL};
  4683. static _PyArg_Parser _parser = {
  4684. .keywords = _keywords,
  4685. .format = "" _Py_PARSE_PID "|O&:pidfd_open",
  4686. .kwtuple = KWTUPLE,
  4687. };
  4688. #undef KWTUPLE
  4689. pid_t pid;
  4690. unsigned int flags = 0;
  4691. if (!_PyArg_ParseStackAndKeywords(args, nargs, kwnames, &_parser,
  4692. &pid, _PyLong_UnsignedInt_Converter, &flags)) {
  4693. goto exit;
  4694. }
  4695. return_value = os_pidfd_open_impl(module, pid, flags);
  4696. exit:
  4697. return return_value;
  4698. }
  4699. #endif /* (defined(__linux__) && defined(__NR_pidfd_open)) */
  4700. #if defined(HAVE_SETNS)
  4701. PyDoc_STRVAR(os_setns__doc__,
  4702. "setns($module, /, fd, nstype=0)\n"
  4703. "--\n"
  4704. "\n"
  4705. "Move the calling thread into different namespaces.\n"
  4706. "\n"
  4707. " fd\n"
  4708. " A file descriptor to a namespace.\n"
  4709. " nstype\n"
  4710. " Type of namespace.");
  4711. #define OS_SETNS_METHODDEF \
  4712. {"setns", _PyCFunction_CAST(os_setns), METH_FASTCALL|METH_KEYWORDS, os_setns__doc__},
  4713. static PyObject *
  4714. os_setns_impl(PyObject *module, int fd, int nstype);
  4715. static PyObject *
  4716. os_setns(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4717. {
  4718. PyObject *return_value = NULL;
  4719. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4720. #define NUM_KEYWORDS 2
  4721. static struct {
  4722. PyGC_Head _this_is_not_used;
  4723. PyObject_VAR_HEAD
  4724. PyObject *ob_item[NUM_KEYWORDS];
  4725. } _kwtuple = {
  4726. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4727. .ob_item = { &_Py_ID(fd), &_Py_ID(nstype), },
  4728. };
  4729. #undef NUM_KEYWORDS
  4730. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4731. #else // !Py_BUILD_CORE
  4732. # define KWTUPLE NULL
  4733. #endif // !Py_BUILD_CORE
  4734. static const char * const _keywords[] = {"fd", "nstype", NULL};
  4735. static _PyArg_Parser _parser = {
  4736. .keywords = _keywords,
  4737. .fname = "setns",
  4738. .kwtuple = KWTUPLE,
  4739. };
  4740. #undef KWTUPLE
  4741. PyObject *argsbuf[2];
  4742. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  4743. int fd;
  4744. int nstype = 0;
  4745. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  4746. if (!args) {
  4747. goto exit;
  4748. }
  4749. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  4750. goto exit;
  4751. }
  4752. if (!noptargs) {
  4753. goto skip_optional_pos;
  4754. }
  4755. nstype = _PyLong_AsInt(args[1]);
  4756. if (nstype == -1 && PyErr_Occurred()) {
  4757. goto exit;
  4758. }
  4759. skip_optional_pos:
  4760. return_value = os_setns_impl(module, fd, nstype);
  4761. exit:
  4762. return return_value;
  4763. }
  4764. #endif /* defined(HAVE_SETNS) */
  4765. #if defined(HAVE_UNSHARE)
  4766. PyDoc_STRVAR(os_unshare__doc__,
  4767. "unshare($module, /, flags)\n"
  4768. "--\n"
  4769. "\n"
  4770. "Disassociate parts of a process (or thread) execution context.\n"
  4771. "\n"
  4772. " flags\n"
  4773. " Namespaces to be unshared.");
  4774. #define OS_UNSHARE_METHODDEF \
  4775. {"unshare", _PyCFunction_CAST(os_unshare), METH_FASTCALL|METH_KEYWORDS, os_unshare__doc__},
  4776. static PyObject *
  4777. os_unshare_impl(PyObject *module, int flags);
  4778. static PyObject *
  4779. os_unshare(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4780. {
  4781. PyObject *return_value = NULL;
  4782. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4783. #define NUM_KEYWORDS 1
  4784. static struct {
  4785. PyGC_Head _this_is_not_used;
  4786. PyObject_VAR_HEAD
  4787. PyObject *ob_item[NUM_KEYWORDS];
  4788. } _kwtuple = {
  4789. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4790. .ob_item = { &_Py_ID(flags), },
  4791. };
  4792. #undef NUM_KEYWORDS
  4793. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4794. #else // !Py_BUILD_CORE
  4795. # define KWTUPLE NULL
  4796. #endif // !Py_BUILD_CORE
  4797. static const char * const _keywords[] = {"flags", NULL};
  4798. static _PyArg_Parser _parser = {
  4799. .keywords = _keywords,
  4800. .fname = "unshare",
  4801. .kwtuple = KWTUPLE,
  4802. };
  4803. #undef KWTUPLE
  4804. PyObject *argsbuf[1];
  4805. int flags;
  4806. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  4807. if (!args) {
  4808. goto exit;
  4809. }
  4810. flags = _PyLong_AsInt(args[0]);
  4811. if (flags == -1 && PyErr_Occurred()) {
  4812. goto exit;
  4813. }
  4814. return_value = os_unshare_impl(module, flags);
  4815. exit:
  4816. return return_value;
  4817. }
  4818. #endif /* defined(HAVE_UNSHARE) */
  4819. #if (defined(HAVE_READLINK) || defined(MS_WINDOWS))
  4820. PyDoc_STRVAR(os_readlink__doc__,
  4821. "readlink($module, /, path, *, dir_fd=None)\n"
  4822. "--\n"
  4823. "\n"
  4824. "Return a string representing the path to which the symbolic link points.\n"
  4825. "\n"
  4826. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  4827. "and path should be relative; path will then be relative to that directory.\n"
  4828. "\n"
  4829. "dir_fd may not be implemented on your platform. If it is unavailable,\n"
  4830. "using it will raise a NotImplementedError.");
  4831. #define OS_READLINK_METHODDEF \
  4832. {"readlink", _PyCFunction_CAST(os_readlink), METH_FASTCALL|METH_KEYWORDS, os_readlink__doc__},
  4833. static PyObject *
  4834. os_readlink_impl(PyObject *module, path_t *path, int dir_fd);
  4835. static PyObject *
  4836. os_readlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4837. {
  4838. PyObject *return_value = NULL;
  4839. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4840. #define NUM_KEYWORDS 2
  4841. static struct {
  4842. PyGC_Head _this_is_not_used;
  4843. PyObject_VAR_HEAD
  4844. PyObject *ob_item[NUM_KEYWORDS];
  4845. } _kwtuple = {
  4846. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4847. .ob_item = { &_Py_ID(path), &_Py_ID(dir_fd), },
  4848. };
  4849. #undef NUM_KEYWORDS
  4850. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4851. #else // !Py_BUILD_CORE
  4852. # define KWTUPLE NULL
  4853. #endif // !Py_BUILD_CORE
  4854. static const char * const _keywords[] = {"path", "dir_fd", NULL};
  4855. static _PyArg_Parser _parser = {
  4856. .keywords = _keywords,
  4857. .fname = "readlink",
  4858. .kwtuple = KWTUPLE,
  4859. };
  4860. #undef KWTUPLE
  4861. PyObject *argsbuf[2];
  4862. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  4863. path_t path = PATH_T_INITIALIZE_P("readlink", "path", 0, 0, 0, 0);
  4864. int dir_fd = DEFAULT_DIR_FD;
  4865. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  4866. if (!args) {
  4867. goto exit;
  4868. }
  4869. if (!path_converter(args[0], &path)) {
  4870. goto exit;
  4871. }
  4872. if (!noptargs) {
  4873. goto skip_optional_kwonly;
  4874. }
  4875. if (!READLINKAT_DIR_FD_CONVERTER(args[1], &dir_fd)) {
  4876. goto exit;
  4877. }
  4878. skip_optional_kwonly:
  4879. return_value = os_readlink_impl(module, &path, dir_fd);
  4880. exit:
  4881. /* Cleanup for path */
  4882. path_cleanup(&path);
  4883. return return_value;
  4884. }
  4885. #endif /* (defined(HAVE_READLINK) || defined(MS_WINDOWS)) */
  4886. #if defined(HAVE_SYMLINK)
  4887. PyDoc_STRVAR(os_symlink__doc__,
  4888. "symlink($module, /, src, dst, target_is_directory=False, *, dir_fd=None)\n"
  4889. "--\n"
  4890. "\n"
  4891. "Create a symbolic link pointing to src named dst.\n"
  4892. "\n"
  4893. "target_is_directory is required on Windows if the target is to be\n"
  4894. " interpreted as a directory. (On Windows, symlink requires\n"
  4895. " Windows 6.0 or greater, and raises a NotImplementedError otherwise.)\n"
  4896. " target_is_directory is ignored on non-Windows platforms.\n"
  4897. "\n"
  4898. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  4899. " and path should be relative; path will then be relative to that directory.\n"
  4900. "dir_fd may not be implemented on your platform.\n"
  4901. " If it is unavailable, using it will raise a NotImplementedError.");
  4902. #define OS_SYMLINK_METHODDEF \
  4903. {"symlink", _PyCFunction_CAST(os_symlink), METH_FASTCALL|METH_KEYWORDS, os_symlink__doc__},
  4904. static PyObject *
  4905. os_symlink_impl(PyObject *module, path_t *src, path_t *dst,
  4906. int target_is_directory, int dir_fd);
  4907. static PyObject *
  4908. os_symlink(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  4909. {
  4910. PyObject *return_value = NULL;
  4911. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  4912. #define NUM_KEYWORDS 4
  4913. static struct {
  4914. PyGC_Head _this_is_not_used;
  4915. PyObject_VAR_HEAD
  4916. PyObject *ob_item[NUM_KEYWORDS];
  4917. } _kwtuple = {
  4918. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  4919. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(target_is_directory), &_Py_ID(dir_fd), },
  4920. };
  4921. #undef NUM_KEYWORDS
  4922. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  4923. #else // !Py_BUILD_CORE
  4924. # define KWTUPLE NULL
  4925. #endif // !Py_BUILD_CORE
  4926. static const char * const _keywords[] = {"src", "dst", "target_is_directory", "dir_fd", NULL};
  4927. static _PyArg_Parser _parser = {
  4928. .keywords = _keywords,
  4929. .fname = "symlink",
  4930. .kwtuple = KWTUPLE,
  4931. };
  4932. #undef KWTUPLE
  4933. PyObject *argsbuf[4];
  4934. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  4935. path_t src = PATH_T_INITIALIZE_P("symlink", "src", 0, 0, 0, 0);
  4936. path_t dst = PATH_T_INITIALIZE_P("symlink", "dst", 0, 0, 0, 0);
  4937. int target_is_directory = 0;
  4938. int dir_fd = DEFAULT_DIR_FD;
  4939. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  4940. if (!args) {
  4941. goto exit;
  4942. }
  4943. if (!path_converter(args[0], &src)) {
  4944. goto exit;
  4945. }
  4946. if (!path_converter(args[1], &dst)) {
  4947. goto exit;
  4948. }
  4949. if (!noptargs) {
  4950. goto skip_optional_pos;
  4951. }
  4952. if (args[2]) {
  4953. target_is_directory = PyObject_IsTrue(args[2]);
  4954. if (target_is_directory < 0) {
  4955. goto exit;
  4956. }
  4957. if (!--noptargs) {
  4958. goto skip_optional_pos;
  4959. }
  4960. }
  4961. skip_optional_pos:
  4962. if (!noptargs) {
  4963. goto skip_optional_kwonly;
  4964. }
  4965. if (!SYMLINKAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
  4966. goto exit;
  4967. }
  4968. skip_optional_kwonly:
  4969. return_value = os_symlink_impl(module, &src, &dst, target_is_directory, dir_fd);
  4970. exit:
  4971. /* Cleanup for src */
  4972. path_cleanup(&src);
  4973. /* Cleanup for dst */
  4974. path_cleanup(&dst);
  4975. return return_value;
  4976. }
  4977. #endif /* defined(HAVE_SYMLINK) */
  4978. #if defined(HAVE_TIMES)
  4979. PyDoc_STRVAR(os_times__doc__,
  4980. "times($module, /)\n"
  4981. "--\n"
  4982. "\n"
  4983. "Return a collection containing process timing information.\n"
  4984. "\n"
  4985. "The object returned behaves like a named tuple with these fields:\n"
  4986. " (utime, stime, cutime, cstime, elapsed_time)\n"
  4987. "All fields are floating-point numbers.");
  4988. #define OS_TIMES_METHODDEF \
  4989. {"times", (PyCFunction)os_times, METH_NOARGS, os_times__doc__},
  4990. static PyObject *
  4991. os_times_impl(PyObject *module);
  4992. static PyObject *
  4993. os_times(PyObject *module, PyObject *Py_UNUSED(ignored))
  4994. {
  4995. return os_times_impl(module);
  4996. }
  4997. #endif /* defined(HAVE_TIMES) */
  4998. #if defined(HAVE_GETSID)
  4999. PyDoc_STRVAR(os_getsid__doc__,
  5000. "getsid($module, pid, /)\n"
  5001. "--\n"
  5002. "\n"
  5003. "Call the system call getsid(pid) and return the result.");
  5004. #define OS_GETSID_METHODDEF \
  5005. {"getsid", (PyCFunction)os_getsid, METH_O, os_getsid__doc__},
  5006. static PyObject *
  5007. os_getsid_impl(PyObject *module, pid_t pid);
  5008. static PyObject *
  5009. os_getsid(PyObject *module, PyObject *arg)
  5010. {
  5011. PyObject *return_value = NULL;
  5012. pid_t pid;
  5013. if (!PyArg_Parse(arg, "" _Py_PARSE_PID ":getsid", &pid)) {
  5014. goto exit;
  5015. }
  5016. return_value = os_getsid_impl(module, pid);
  5017. exit:
  5018. return return_value;
  5019. }
  5020. #endif /* defined(HAVE_GETSID) */
  5021. #if defined(HAVE_SETSID)
  5022. PyDoc_STRVAR(os_setsid__doc__,
  5023. "setsid($module, /)\n"
  5024. "--\n"
  5025. "\n"
  5026. "Call the system call setsid().");
  5027. #define OS_SETSID_METHODDEF \
  5028. {"setsid", (PyCFunction)os_setsid, METH_NOARGS, os_setsid__doc__},
  5029. static PyObject *
  5030. os_setsid_impl(PyObject *module);
  5031. static PyObject *
  5032. os_setsid(PyObject *module, PyObject *Py_UNUSED(ignored))
  5033. {
  5034. return os_setsid_impl(module);
  5035. }
  5036. #endif /* defined(HAVE_SETSID) */
  5037. #if defined(HAVE_SETPGID)
  5038. PyDoc_STRVAR(os_setpgid__doc__,
  5039. "setpgid($module, pid, pgrp, /)\n"
  5040. "--\n"
  5041. "\n"
  5042. "Call the system call setpgid(pid, pgrp).");
  5043. #define OS_SETPGID_METHODDEF \
  5044. {"setpgid", _PyCFunction_CAST(os_setpgid), METH_FASTCALL, os_setpgid__doc__},
  5045. static PyObject *
  5046. os_setpgid_impl(PyObject *module, pid_t pid, pid_t pgrp);
  5047. static PyObject *
  5048. os_setpgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5049. {
  5050. PyObject *return_value = NULL;
  5051. pid_t pid;
  5052. pid_t pgrp;
  5053. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_PID "" _Py_PARSE_PID ":setpgid",
  5054. &pid, &pgrp)) {
  5055. goto exit;
  5056. }
  5057. return_value = os_setpgid_impl(module, pid, pgrp);
  5058. exit:
  5059. return return_value;
  5060. }
  5061. #endif /* defined(HAVE_SETPGID) */
  5062. #if defined(HAVE_TCGETPGRP)
  5063. PyDoc_STRVAR(os_tcgetpgrp__doc__,
  5064. "tcgetpgrp($module, fd, /)\n"
  5065. "--\n"
  5066. "\n"
  5067. "Return the process group associated with the terminal specified by fd.");
  5068. #define OS_TCGETPGRP_METHODDEF \
  5069. {"tcgetpgrp", (PyCFunction)os_tcgetpgrp, METH_O, os_tcgetpgrp__doc__},
  5070. static PyObject *
  5071. os_tcgetpgrp_impl(PyObject *module, int fd);
  5072. static PyObject *
  5073. os_tcgetpgrp(PyObject *module, PyObject *arg)
  5074. {
  5075. PyObject *return_value = NULL;
  5076. int fd;
  5077. fd = _PyLong_AsInt(arg);
  5078. if (fd == -1 && PyErr_Occurred()) {
  5079. goto exit;
  5080. }
  5081. return_value = os_tcgetpgrp_impl(module, fd);
  5082. exit:
  5083. return return_value;
  5084. }
  5085. #endif /* defined(HAVE_TCGETPGRP) */
  5086. #if defined(HAVE_TCSETPGRP)
  5087. PyDoc_STRVAR(os_tcsetpgrp__doc__,
  5088. "tcsetpgrp($module, fd, pgid, /)\n"
  5089. "--\n"
  5090. "\n"
  5091. "Set the process group associated with the terminal specified by fd.");
  5092. #define OS_TCSETPGRP_METHODDEF \
  5093. {"tcsetpgrp", _PyCFunction_CAST(os_tcsetpgrp), METH_FASTCALL, os_tcsetpgrp__doc__},
  5094. static PyObject *
  5095. os_tcsetpgrp_impl(PyObject *module, int fd, pid_t pgid);
  5096. static PyObject *
  5097. os_tcsetpgrp(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5098. {
  5099. PyObject *return_value = NULL;
  5100. int fd;
  5101. pid_t pgid;
  5102. if (!_PyArg_ParseStack(args, nargs, "i" _Py_PARSE_PID ":tcsetpgrp",
  5103. &fd, &pgid)) {
  5104. goto exit;
  5105. }
  5106. return_value = os_tcsetpgrp_impl(module, fd, pgid);
  5107. exit:
  5108. return return_value;
  5109. }
  5110. #endif /* defined(HAVE_TCSETPGRP) */
  5111. PyDoc_STRVAR(os_open__doc__,
  5112. "open($module, /, path, flags, mode=511, *, dir_fd=None)\n"
  5113. "--\n"
  5114. "\n"
  5115. "Open a file for low level IO. Returns a file descriptor (integer).\n"
  5116. "\n"
  5117. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  5118. " and path should be relative; path will then be relative to that directory.\n"
  5119. "dir_fd may not be implemented on your platform.\n"
  5120. " If it is unavailable, using it will raise a NotImplementedError.");
  5121. #define OS_OPEN_METHODDEF \
  5122. {"open", _PyCFunction_CAST(os_open), METH_FASTCALL|METH_KEYWORDS, os_open__doc__},
  5123. static int
  5124. os_open_impl(PyObject *module, path_t *path, int flags, int mode, int dir_fd);
  5125. static PyObject *
  5126. os_open(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5127. {
  5128. PyObject *return_value = NULL;
  5129. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5130. #define NUM_KEYWORDS 4
  5131. static struct {
  5132. PyGC_Head _this_is_not_used;
  5133. PyObject_VAR_HEAD
  5134. PyObject *ob_item[NUM_KEYWORDS];
  5135. } _kwtuple = {
  5136. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5137. .ob_item = { &_Py_ID(path), &_Py_ID(flags), &_Py_ID(mode), &_Py_ID(dir_fd), },
  5138. };
  5139. #undef NUM_KEYWORDS
  5140. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5141. #else // !Py_BUILD_CORE
  5142. # define KWTUPLE NULL
  5143. #endif // !Py_BUILD_CORE
  5144. static const char * const _keywords[] = {"path", "flags", "mode", "dir_fd", NULL};
  5145. static _PyArg_Parser _parser = {
  5146. .keywords = _keywords,
  5147. .fname = "open",
  5148. .kwtuple = KWTUPLE,
  5149. };
  5150. #undef KWTUPLE
  5151. PyObject *argsbuf[4];
  5152. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  5153. path_t path = PATH_T_INITIALIZE_P("open", "path", 0, 0, 0, 0);
  5154. int flags;
  5155. int mode = 511;
  5156. int dir_fd = DEFAULT_DIR_FD;
  5157. int _return_value;
  5158. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  5159. if (!args) {
  5160. goto exit;
  5161. }
  5162. if (!path_converter(args[0], &path)) {
  5163. goto exit;
  5164. }
  5165. flags = _PyLong_AsInt(args[1]);
  5166. if (flags == -1 && PyErr_Occurred()) {
  5167. goto exit;
  5168. }
  5169. if (!noptargs) {
  5170. goto skip_optional_pos;
  5171. }
  5172. if (args[2]) {
  5173. mode = _PyLong_AsInt(args[2]);
  5174. if (mode == -1 && PyErr_Occurred()) {
  5175. goto exit;
  5176. }
  5177. if (!--noptargs) {
  5178. goto skip_optional_pos;
  5179. }
  5180. }
  5181. skip_optional_pos:
  5182. if (!noptargs) {
  5183. goto skip_optional_kwonly;
  5184. }
  5185. if (!OPENAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
  5186. goto exit;
  5187. }
  5188. skip_optional_kwonly:
  5189. _return_value = os_open_impl(module, &path, flags, mode, dir_fd);
  5190. if ((_return_value == -1) && PyErr_Occurred()) {
  5191. goto exit;
  5192. }
  5193. return_value = PyLong_FromLong((long)_return_value);
  5194. exit:
  5195. /* Cleanup for path */
  5196. path_cleanup(&path);
  5197. return return_value;
  5198. }
  5199. PyDoc_STRVAR(os_close__doc__,
  5200. "close($module, /, fd)\n"
  5201. "--\n"
  5202. "\n"
  5203. "Close a file descriptor.");
  5204. #define OS_CLOSE_METHODDEF \
  5205. {"close", _PyCFunction_CAST(os_close), METH_FASTCALL|METH_KEYWORDS, os_close__doc__},
  5206. static PyObject *
  5207. os_close_impl(PyObject *module, int fd);
  5208. static PyObject *
  5209. os_close(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5210. {
  5211. PyObject *return_value = NULL;
  5212. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5213. #define NUM_KEYWORDS 1
  5214. static struct {
  5215. PyGC_Head _this_is_not_used;
  5216. PyObject_VAR_HEAD
  5217. PyObject *ob_item[NUM_KEYWORDS];
  5218. } _kwtuple = {
  5219. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5220. .ob_item = { &_Py_ID(fd), },
  5221. };
  5222. #undef NUM_KEYWORDS
  5223. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5224. #else // !Py_BUILD_CORE
  5225. # define KWTUPLE NULL
  5226. #endif // !Py_BUILD_CORE
  5227. static const char * const _keywords[] = {"fd", NULL};
  5228. static _PyArg_Parser _parser = {
  5229. .keywords = _keywords,
  5230. .fname = "close",
  5231. .kwtuple = KWTUPLE,
  5232. };
  5233. #undef KWTUPLE
  5234. PyObject *argsbuf[1];
  5235. int fd;
  5236. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  5237. if (!args) {
  5238. goto exit;
  5239. }
  5240. fd = _PyLong_AsInt(args[0]);
  5241. if (fd == -1 && PyErr_Occurred()) {
  5242. goto exit;
  5243. }
  5244. return_value = os_close_impl(module, fd);
  5245. exit:
  5246. return return_value;
  5247. }
  5248. PyDoc_STRVAR(os_closerange__doc__,
  5249. "closerange($module, fd_low, fd_high, /)\n"
  5250. "--\n"
  5251. "\n"
  5252. "Closes all file descriptors in [fd_low, fd_high), ignoring errors.");
  5253. #define OS_CLOSERANGE_METHODDEF \
  5254. {"closerange", _PyCFunction_CAST(os_closerange), METH_FASTCALL, os_closerange__doc__},
  5255. static PyObject *
  5256. os_closerange_impl(PyObject *module, int fd_low, int fd_high);
  5257. static PyObject *
  5258. os_closerange(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5259. {
  5260. PyObject *return_value = NULL;
  5261. int fd_low;
  5262. int fd_high;
  5263. if (!_PyArg_CheckPositional("closerange", nargs, 2, 2)) {
  5264. goto exit;
  5265. }
  5266. fd_low = _PyLong_AsInt(args[0]);
  5267. if (fd_low == -1 && PyErr_Occurred()) {
  5268. goto exit;
  5269. }
  5270. fd_high = _PyLong_AsInt(args[1]);
  5271. if (fd_high == -1 && PyErr_Occurred()) {
  5272. goto exit;
  5273. }
  5274. return_value = os_closerange_impl(module, fd_low, fd_high);
  5275. exit:
  5276. return return_value;
  5277. }
  5278. PyDoc_STRVAR(os_dup__doc__,
  5279. "dup($module, fd, /)\n"
  5280. "--\n"
  5281. "\n"
  5282. "Return a duplicate of a file descriptor.");
  5283. #define OS_DUP_METHODDEF \
  5284. {"dup", (PyCFunction)os_dup, METH_O, os_dup__doc__},
  5285. static int
  5286. os_dup_impl(PyObject *module, int fd);
  5287. static PyObject *
  5288. os_dup(PyObject *module, PyObject *arg)
  5289. {
  5290. PyObject *return_value = NULL;
  5291. int fd;
  5292. int _return_value;
  5293. fd = _PyLong_AsInt(arg);
  5294. if (fd == -1 && PyErr_Occurred()) {
  5295. goto exit;
  5296. }
  5297. _return_value = os_dup_impl(module, fd);
  5298. if ((_return_value == -1) && PyErr_Occurred()) {
  5299. goto exit;
  5300. }
  5301. return_value = PyLong_FromLong((long)_return_value);
  5302. exit:
  5303. return return_value;
  5304. }
  5305. #if ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS)))
  5306. PyDoc_STRVAR(os_dup2__doc__,
  5307. "dup2($module, /, fd, fd2, inheritable=True)\n"
  5308. "--\n"
  5309. "\n"
  5310. "Duplicate file descriptor.");
  5311. #define OS_DUP2_METHODDEF \
  5312. {"dup2", _PyCFunction_CAST(os_dup2), METH_FASTCALL|METH_KEYWORDS, os_dup2__doc__},
  5313. static int
  5314. os_dup2_impl(PyObject *module, int fd, int fd2, int inheritable);
  5315. static PyObject *
  5316. os_dup2(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5317. {
  5318. PyObject *return_value = NULL;
  5319. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5320. #define NUM_KEYWORDS 3
  5321. static struct {
  5322. PyGC_Head _this_is_not_used;
  5323. PyObject_VAR_HEAD
  5324. PyObject *ob_item[NUM_KEYWORDS];
  5325. } _kwtuple = {
  5326. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5327. .ob_item = { &_Py_ID(fd), &_Py_ID(fd2), &_Py_ID(inheritable), },
  5328. };
  5329. #undef NUM_KEYWORDS
  5330. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5331. #else // !Py_BUILD_CORE
  5332. # define KWTUPLE NULL
  5333. #endif // !Py_BUILD_CORE
  5334. static const char * const _keywords[] = {"fd", "fd2", "inheritable", NULL};
  5335. static _PyArg_Parser _parser = {
  5336. .keywords = _keywords,
  5337. .fname = "dup2",
  5338. .kwtuple = KWTUPLE,
  5339. };
  5340. #undef KWTUPLE
  5341. PyObject *argsbuf[3];
  5342. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  5343. int fd;
  5344. int fd2;
  5345. int inheritable = 1;
  5346. int _return_value;
  5347. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 3, 0, argsbuf);
  5348. if (!args) {
  5349. goto exit;
  5350. }
  5351. fd = _PyLong_AsInt(args[0]);
  5352. if (fd == -1 && PyErr_Occurred()) {
  5353. goto exit;
  5354. }
  5355. fd2 = _PyLong_AsInt(args[1]);
  5356. if (fd2 == -1 && PyErr_Occurred()) {
  5357. goto exit;
  5358. }
  5359. if (!noptargs) {
  5360. goto skip_optional_pos;
  5361. }
  5362. inheritable = PyObject_IsTrue(args[2]);
  5363. if (inheritable < 0) {
  5364. goto exit;
  5365. }
  5366. skip_optional_pos:
  5367. _return_value = os_dup2_impl(module, fd, fd2, inheritable);
  5368. if ((_return_value == -1) && PyErr_Occurred()) {
  5369. goto exit;
  5370. }
  5371. return_value = PyLong_FromLong((long)_return_value);
  5372. exit:
  5373. return return_value;
  5374. }
  5375. #endif /* ((defined(HAVE_DUP3) || defined(F_DUPFD) || defined(MS_WINDOWS))) */
  5376. #if defined(HAVE_LOCKF)
  5377. PyDoc_STRVAR(os_lockf__doc__,
  5378. "lockf($module, fd, command, length, /)\n"
  5379. "--\n"
  5380. "\n"
  5381. "Apply, test or remove a POSIX lock on an open file descriptor.\n"
  5382. "\n"
  5383. " fd\n"
  5384. " An open file descriptor.\n"
  5385. " command\n"
  5386. " One of F_LOCK, F_TLOCK, F_ULOCK or F_TEST.\n"
  5387. " length\n"
  5388. " The number of bytes to lock, starting at the current position.");
  5389. #define OS_LOCKF_METHODDEF \
  5390. {"lockf", _PyCFunction_CAST(os_lockf), METH_FASTCALL, os_lockf__doc__},
  5391. static PyObject *
  5392. os_lockf_impl(PyObject *module, int fd, int command, Py_off_t length);
  5393. static PyObject *
  5394. os_lockf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5395. {
  5396. PyObject *return_value = NULL;
  5397. int fd;
  5398. int command;
  5399. Py_off_t length;
  5400. if (!_PyArg_CheckPositional("lockf", nargs, 3, 3)) {
  5401. goto exit;
  5402. }
  5403. fd = _PyLong_AsInt(args[0]);
  5404. if (fd == -1 && PyErr_Occurred()) {
  5405. goto exit;
  5406. }
  5407. command = _PyLong_AsInt(args[1]);
  5408. if (command == -1 && PyErr_Occurred()) {
  5409. goto exit;
  5410. }
  5411. if (!Py_off_t_converter(args[2], &length)) {
  5412. goto exit;
  5413. }
  5414. return_value = os_lockf_impl(module, fd, command, length);
  5415. exit:
  5416. return return_value;
  5417. }
  5418. #endif /* defined(HAVE_LOCKF) */
  5419. PyDoc_STRVAR(os_lseek__doc__,
  5420. "lseek($module, fd, position, whence, /)\n"
  5421. "--\n"
  5422. "\n"
  5423. "Set the position of a file descriptor. Return the new position.\n"
  5424. "\n"
  5425. " fd\n"
  5426. " An open file descriptor, as returned by os.open().\n"
  5427. " position\n"
  5428. " Position, interpreted relative to \'whence\'.\n"
  5429. " whence\n"
  5430. " The relative position to seek from. Valid values are:\n"
  5431. " - SEEK_SET: seek from the start of the file.\n"
  5432. " - SEEK_CUR: seek from the current file position.\n"
  5433. " - SEEK_END: seek from the end of the file.\n"
  5434. "\n"
  5435. "The return value is the number of bytes relative to the beginning of the file.");
  5436. #define OS_LSEEK_METHODDEF \
  5437. {"lseek", _PyCFunction_CAST(os_lseek), METH_FASTCALL, os_lseek__doc__},
  5438. static Py_off_t
  5439. os_lseek_impl(PyObject *module, int fd, Py_off_t position, int how);
  5440. static PyObject *
  5441. os_lseek(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5442. {
  5443. PyObject *return_value = NULL;
  5444. int fd;
  5445. Py_off_t position;
  5446. int how;
  5447. Py_off_t _return_value;
  5448. if (!_PyArg_CheckPositional("lseek", nargs, 3, 3)) {
  5449. goto exit;
  5450. }
  5451. fd = _PyLong_AsInt(args[0]);
  5452. if (fd == -1 && PyErr_Occurred()) {
  5453. goto exit;
  5454. }
  5455. if (!Py_off_t_converter(args[1], &position)) {
  5456. goto exit;
  5457. }
  5458. how = _PyLong_AsInt(args[2]);
  5459. if (how == -1 && PyErr_Occurred()) {
  5460. goto exit;
  5461. }
  5462. _return_value = os_lseek_impl(module, fd, position, how);
  5463. if ((_return_value == -1) && PyErr_Occurred()) {
  5464. goto exit;
  5465. }
  5466. return_value = PyLong_FromPy_off_t(_return_value);
  5467. exit:
  5468. return return_value;
  5469. }
  5470. PyDoc_STRVAR(os_read__doc__,
  5471. "read($module, fd, length, /)\n"
  5472. "--\n"
  5473. "\n"
  5474. "Read from a file descriptor. Returns a bytes object.");
  5475. #define OS_READ_METHODDEF \
  5476. {"read", _PyCFunction_CAST(os_read), METH_FASTCALL, os_read__doc__},
  5477. static PyObject *
  5478. os_read_impl(PyObject *module, int fd, Py_ssize_t length);
  5479. static PyObject *
  5480. os_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5481. {
  5482. PyObject *return_value = NULL;
  5483. int fd;
  5484. Py_ssize_t length;
  5485. if (!_PyArg_CheckPositional("read", nargs, 2, 2)) {
  5486. goto exit;
  5487. }
  5488. fd = _PyLong_AsInt(args[0]);
  5489. if (fd == -1 && PyErr_Occurred()) {
  5490. goto exit;
  5491. }
  5492. {
  5493. Py_ssize_t ival = -1;
  5494. PyObject *iobj = _PyNumber_Index(args[1]);
  5495. if (iobj != NULL) {
  5496. ival = PyLong_AsSsize_t(iobj);
  5497. Py_DECREF(iobj);
  5498. }
  5499. if (ival == -1 && PyErr_Occurred()) {
  5500. goto exit;
  5501. }
  5502. length = ival;
  5503. }
  5504. return_value = os_read_impl(module, fd, length);
  5505. exit:
  5506. return return_value;
  5507. }
  5508. #if defined(HAVE_READV)
  5509. PyDoc_STRVAR(os_readv__doc__,
  5510. "readv($module, fd, buffers, /)\n"
  5511. "--\n"
  5512. "\n"
  5513. "Read from a file descriptor fd into an iterable of buffers.\n"
  5514. "\n"
  5515. "The buffers should be mutable buffers accepting bytes.\n"
  5516. "readv will transfer data into each buffer until it is full\n"
  5517. "and then move on to the next buffer in the sequence to hold\n"
  5518. "the rest of the data.\n"
  5519. "\n"
  5520. "readv returns the total number of bytes read,\n"
  5521. "which may be less than the total capacity of all the buffers.");
  5522. #define OS_READV_METHODDEF \
  5523. {"readv", _PyCFunction_CAST(os_readv), METH_FASTCALL, os_readv__doc__},
  5524. static Py_ssize_t
  5525. os_readv_impl(PyObject *module, int fd, PyObject *buffers);
  5526. static PyObject *
  5527. os_readv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5528. {
  5529. PyObject *return_value = NULL;
  5530. int fd;
  5531. PyObject *buffers;
  5532. Py_ssize_t _return_value;
  5533. if (!_PyArg_CheckPositional("readv", nargs, 2, 2)) {
  5534. goto exit;
  5535. }
  5536. fd = _PyLong_AsInt(args[0]);
  5537. if (fd == -1 && PyErr_Occurred()) {
  5538. goto exit;
  5539. }
  5540. buffers = args[1];
  5541. _return_value = os_readv_impl(module, fd, buffers);
  5542. if ((_return_value == -1) && PyErr_Occurred()) {
  5543. goto exit;
  5544. }
  5545. return_value = PyLong_FromSsize_t(_return_value);
  5546. exit:
  5547. return return_value;
  5548. }
  5549. #endif /* defined(HAVE_READV) */
  5550. #if defined(HAVE_PREAD)
  5551. PyDoc_STRVAR(os_pread__doc__,
  5552. "pread($module, fd, length, offset, /)\n"
  5553. "--\n"
  5554. "\n"
  5555. "Read a number of bytes from a file descriptor starting at a particular offset.\n"
  5556. "\n"
  5557. "Read length bytes from file descriptor fd, starting at offset bytes from\n"
  5558. "the beginning of the file. The file offset remains unchanged.");
  5559. #define OS_PREAD_METHODDEF \
  5560. {"pread", _PyCFunction_CAST(os_pread), METH_FASTCALL, os_pread__doc__},
  5561. static PyObject *
  5562. os_pread_impl(PyObject *module, int fd, Py_ssize_t length, Py_off_t offset);
  5563. static PyObject *
  5564. os_pread(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5565. {
  5566. PyObject *return_value = NULL;
  5567. int fd;
  5568. Py_ssize_t length;
  5569. Py_off_t offset;
  5570. if (!_PyArg_CheckPositional("pread", nargs, 3, 3)) {
  5571. goto exit;
  5572. }
  5573. fd = _PyLong_AsInt(args[0]);
  5574. if (fd == -1 && PyErr_Occurred()) {
  5575. goto exit;
  5576. }
  5577. {
  5578. Py_ssize_t ival = -1;
  5579. PyObject *iobj = _PyNumber_Index(args[1]);
  5580. if (iobj != NULL) {
  5581. ival = PyLong_AsSsize_t(iobj);
  5582. Py_DECREF(iobj);
  5583. }
  5584. if (ival == -1 && PyErr_Occurred()) {
  5585. goto exit;
  5586. }
  5587. length = ival;
  5588. }
  5589. if (!Py_off_t_converter(args[2], &offset)) {
  5590. goto exit;
  5591. }
  5592. return_value = os_pread_impl(module, fd, length, offset);
  5593. exit:
  5594. return return_value;
  5595. }
  5596. #endif /* defined(HAVE_PREAD) */
  5597. #if (defined(HAVE_PREADV) || defined (HAVE_PREADV2))
  5598. PyDoc_STRVAR(os_preadv__doc__,
  5599. "preadv($module, fd, buffers, offset, flags=0, /)\n"
  5600. "--\n"
  5601. "\n"
  5602. "Reads from a file descriptor into a number of mutable bytes-like objects.\n"
  5603. "\n"
  5604. "Combines the functionality of readv() and pread(). As readv(), it will\n"
  5605. "transfer data into each buffer until it is full and then move on to the next\n"
  5606. "buffer in the sequence to hold the rest of the data. Its fourth argument,\n"
  5607. "specifies the file offset at which the input operation is to be performed. It\n"
  5608. "will return the total number of bytes read (which can be less than the total\n"
  5609. "capacity of all the objects).\n"
  5610. "\n"
  5611. "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
  5612. "\n"
  5613. "- RWF_HIPRI\n"
  5614. "- RWF_NOWAIT\n"
  5615. "\n"
  5616. "Using non-zero flags requires Linux 4.6 or newer.");
  5617. #define OS_PREADV_METHODDEF \
  5618. {"preadv", _PyCFunction_CAST(os_preadv), METH_FASTCALL, os_preadv__doc__},
  5619. static Py_ssize_t
  5620. os_preadv_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
  5621. int flags);
  5622. static PyObject *
  5623. os_preadv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5624. {
  5625. PyObject *return_value = NULL;
  5626. int fd;
  5627. PyObject *buffers;
  5628. Py_off_t offset;
  5629. int flags = 0;
  5630. Py_ssize_t _return_value;
  5631. if (!_PyArg_CheckPositional("preadv", nargs, 3, 4)) {
  5632. goto exit;
  5633. }
  5634. fd = _PyLong_AsInt(args[0]);
  5635. if (fd == -1 && PyErr_Occurred()) {
  5636. goto exit;
  5637. }
  5638. buffers = args[1];
  5639. if (!Py_off_t_converter(args[2], &offset)) {
  5640. goto exit;
  5641. }
  5642. if (nargs < 4) {
  5643. goto skip_optional;
  5644. }
  5645. flags = _PyLong_AsInt(args[3]);
  5646. if (flags == -1 && PyErr_Occurred()) {
  5647. goto exit;
  5648. }
  5649. skip_optional:
  5650. _return_value = os_preadv_impl(module, fd, buffers, offset, flags);
  5651. if ((_return_value == -1) && PyErr_Occurred()) {
  5652. goto exit;
  5653. }
  5654. return_value = PyLong_FromSsize_t(_return_value);
  5655. exit:
  5656. return return_value;
  5657. }
  5658. #endif /* (defined(HAVE_PREADV) || defined (HAVE_PREADV2)) */
  5659. PyDoc_STRVAR(os_write__doc__,
  5660. "write($module, fd, data, /)\n"
  5661. "--\n"
  5662. "\n"
  5663. "Write a bytes object to a file descriptor.");
  5664. #define OS_WRITE_METHODDEF \
  5665. {"write", _PyCFunction_CAST(os_write), METH_FASTCALL, os_write__doc__},
  5666. static Py_ssize_t
  5667. os_write_impl(PyObject *module, int fd, Py_buffer *data);
  5668. static PyObject *
  5669. os_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5670. {
  5671. PyObject *return_value = NULL;
  5672. int fd;
  5673. Py_buffer data = {NULL, NULL};
  5674. Py_ssize_t _return_value;
  5675. if (!_PyArg_CheckPositional("write", nargs, 2, 2)) {
  5676. goto exit;
  5677. }
  5678. fd = _PyLong_AsInt(args[0]);
  5679. if (fd == -1 && PyErr_Occurred()) {
  5680. goto exit;
  5681. }
  5682. if (PyObject_GetBuffer(args[1], &data, PyBUF_SIMPLE) != 0) {
  5683. goto exit;
  5684. }
  5685. if (!PyBuffer_IsContiguous(&data, 'C')) {
  5686. _PyArg_BadArgument("write", "argument 2", "contiguous buffer", args[1]);
  5687. goto exit;
  5688. }
  5689. _return_value = os_write_impl(module, fd, &data);
  5690. if ((_return_value == -1) && PyErr_Occurred()) {
  5691. goto exit;
  5692. }
  5693. return_value = PyLong_FromSsize_t(_return_value);
  5694. exit:
  5695. /* Cleanup for data */
  5696. if (data.obj) {
  5697. PyBuffer_Release(&data);
  5698. }
  5699. return return_value;
  5700. }
  5701. #if defined(HAVE_SENDFILE) && defined(__APPLE__)
  5702. PyDoc_STRVAR(os_sendfile__doc__,
  5703. "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
  5704. " trailers=(), flags=0)\n"
  5705. "--\n"
  5706. "\n"
  5707. "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
  5708. #define OS_SENDFILE_METHODDEF \
  5709. {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
  5710. static PyObject *
  5711. os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
  5712. Py_off_t sbytes, PyObject *headers, PyObject *trailers,
  5713. int flags);
  5714. static PyObject *
  5715. os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5716. {
  5717. PyObject *return_value = NULL;
  5718. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5719. #define NUM_KEYWORDS 7
  5720. static struct {
  5721. PyGC_Head _this_is_not_used;
  5722. PyObject_VAR_HEAD
  5723. PyObject *ob_item[NUM_KEYWORDS];
  5724. } _kwtuple = {
  5725. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5726. .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
  5727. };
  5728. #undef NUM_KEYWORDS
  5729. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5730. #else // !Py_BUILD_CORE
  5731. # define KWTUPLE NULL
  5732. #endif // !Py_BUILD_CORE
  5733. static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
  5734. static _PyArg_Parser _parser = {
  5735. .keywords = _keywords,
  5736. .fname = "sendfile",
  5737. .kwtuple = KWTUPLE,
  5738. };
  5739. #undef KWTUPLE
  5740. PyObject *argsbuf[7];
  5741. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
  5742. int out_fd;
  5743. int in_fd;
  5744. Py_off_t offset;
  5745. Py_off_t sbytes;
  5746. PyObject *headers = NULL;
  5747. PyObject *trailers = NULL;
  5748. int flags = 0;
  5749. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
  5750. if (!args) {
  5751. goto exit;
  5752. }
  5753. out_fd = _PyLong_AsInt(args[0]);
  5754. if (out_fd == -1 && PyErr_Occurred()) {
  5755. goto exit;
  5756. }
  5757. in_fd = _PyLong_AsInt(args[1]);
  5758. if (in_fd == -1 && PyErr_Occurred()) {
  5759. goto exit;
  5760. }
  5761. if (!Py_off_t_converter(args[2], &offset)) {
  5762. goto exit;
  5763. }
  5764. if (!Py_off_t_converter(args[3], &sbytes)) {
  5765. goto exit;
  5766. }
  5767. if (!noptargs) {
  5768. goto skip_optional_pos;
  5769. }
  5770. if (args[4]) {
  5771. headers = args[4];
  5772. if (!--noptargs) {
  5773. goto skip_optional_pos;
  5774. }
  5775. }
  5776. if (args[5]) {
  5777. trailers = args[5];
  5778. if (!--noptargs) {
  5779. goto skip_optional_pos;
  5780. }
  5781. }
  5782. flags = _PyLong_AsInt(args[6]);
  5783. if (flags == -1 && PyErr_Occurred()) {
  5784. goto exit;
  5785. }
  5786. skip_optional_pos:
  5787. return_value = os_sendfile_impl(module, out_fd, in_fd, offset, sbytes, headers, trailers, flags);
  5788. exit:
  5789. return return_value;
  5790. }
  5791. #endif /* defined(HAVE_SENDFILE) && defined(__APPLE__) */
  5792. #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__))
  5793. PyDoc_STRVAR(os_sendfile__doc__,
  5794. "sendfile($module, /, out_fd, in_fd, offset, count, headers=(),\n"
  5795. " trailers=(), flags=0)\n"
  5796. "--\n"
  5797. "\n"
  5798. "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
  5799. #define OS_SENDFILE_METHODDEF \
  5800. {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
  5801. static PyObject *
  5802. os_sendfile_impl(PyObject *module, int out_fd, int in_fd, Py_off_t offset,
  5803. Py_ssize_t count, PyObject *headers, PyObject *trailers,
  5804. int flags);
  5805. static PyObject *
  5806. os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5807. {
  5808. PyObject *return_value = NULL;
  5809. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5810. #define NUM_KEYWORDS 7
  5811. static struct {
  5812. PyGC_Head _this_is_not_used;
  5813. PyObject_VAR_HEAD
  5814. PyObject *ob_item[NUM_KEYWORDS];
  5815. } _kwtuple = {
  5816. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5817. .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), &_Py_ID(headers), &_Py_ID(trailers), &_Py_ID(flags), },
  5818. };
  5819. #undef NUM_KEYWORDS
  5820. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5821. #else // !Py_BUILD_CORE
  5822. # define KWTUPLE NULL
  5823. #endif // !Py_BUILD_CORE
  5824. static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", "headers", "trailers", "flags", NULL};
  5825. static _PyArg_Parser _parser = {
  5826. .keywords = _keywords,
  5827. .fname = "sendfile",
  5828. .kwtuple = KWTUPLE,
  5829. };
  5830. #undef KWTUPLE
  5831. PyObject *argsbuf[7];
  5832. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 4;
  5833. int out_fd;
  5834. int in_fd;
  5835. Py_off_t offset;
  5836. Py_ssize_t count;
  5837. PyObject *headers = NULL;
  5838. PyObject *trailers = NULL;
  5839. int flags = 0;
  5840. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 7, 0, argsbuf);
  5841. if (!args) {
  5842. goto exit;
  5843. }
  5844. out_fd = _PyLong_AsInt(args[0]);
  5845. if (out_fd == -1 && PyErr_Occurred()) {
  5846. goto exit;
  5847. }
  5848. in_fd = _PyLong_AsInt(args[1]);
  5849. if (in_fd == -1 && PyErr_Occurred()) {
  5850. goto exit;
  5851. }
  5852. if (!Py_off_t_converter(args[2], &offset)) {
  5853. goto exit;
  5854. }
  5855. {
  5856. Py_ssize_t ival = -1;
  5857. PyObject *iobj = _PyNumber_Index(args[3]);
  5858. if (iobj != NULL) {
  5859. ival = PyLong_AsSsize_t(iobj);
  5860. Py_DECREF(iobj);
  5861. }
  5862. if (ival == -1 && PyErr_Occurred()) {
  5863. goto exit;
  5864. }
  5865. count = ival;
  5866. }
  5867. if (!noptargs) {
  5868. goto skip_optional_pos;
  5869. }
  5870. if (args[4]) {
  5871. headers = args[4];
  5872. if (!--noptargs) {
  5873. goto skip_optional_pos;
  5874. }
  5875. }
  5876. if (args[5]) {
  5877. trailers = args[5];
  5878. if (!--noptargs) {
  5879. goto skip_optional_pos;
  5880. }
  5881. }
  5882. flags = _PyLong_AsInt(args[6]);
  5883. if (flags == -1 && PyErr_Occurred()) {
  5884. goto exit;
  5885. }
  5886. skip_optional_pos:
  5887. return_value = os_sendfile_impl(module, out_fd, in_fd, offset, count, headers, trailers, flags);
  5888. exit:
  5889. return return_value;
  5890. }
  5891. #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && (defined(__FreeBSD__) || defined(__DragonFly__)) */
  5892. #if defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__))
  5893. PyDoc_STRVAR(os_sendfile__doc__,
  5894. "sendfile($module, /, out_fd, in_fd, offset, count)\n"
  5895. "--\n"
  5896. "\n"
  5897. "Copy count bytes from file descriptor in_fd to file descriptor out_fd.");
  5898. #define OS_SENDFILE_METHODDEF \
  5899. {"sendfile", _PyCFunction_CAST(os_sendfile), METH_FASTCALL|METH_KEYWORDS, os_sendfile__doc__},
  5900. static PyObject *
  5901. os_sendfile_impl(PyObject *module, int out_fd, int in_fd, PyObject *offobj,
  5902. Py_ssize_t count);
  5903. static PyObject *
  5904. os_sendfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  5905. {
  5906. PyObject *return_value = NULL;
  5907. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  5908. #define NUM_KEYWORDS 4
  5909. static struct {
  5910. PyGC_Head _this_is_not_used;
  5911. PyObject_VAR_HEAD
  5912. PyObject *ob_item[NUM_KEYWORDS];
  5913. } _kwtuple = {
  5914. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  5915. .ob_item = { &_Py_ID(out_fd), &_Py_ID(in_fd), &_Py_ID(offset), &_Py_ID(count), },
  5916. };
  5917. #undef NUM_KEYWORDS
  5918. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  5919. #else // !Py_BUILD_CORE
  5920. # define KWTUPLE NULL
  5921. #endif // !Py_BUILD_CORE
  5922. static const char * const _keywords[] = {"out_fd", "in_fd", "offset", "count", NULL};
  5923. static _PyArg_Parser _parser = {
  5924. .keywords = _keywords,
  5925. .fname = "sendfile",
  5926. .kwtuple = KWTUPLE,
  5927. };
  5928. #undef KWTUPLE
  5929. PyObject *argsbuf[4];
  5930. int out_fd;
  5931. int in_fd;
  5932. PyObject *offobj;
  5933. Py_ssize_t count;
  5934. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 4, 4, 0, argsbuf);
  5935. if (!args) {
  5936. goto exit;
  5937. }
  5938. out_fd = _PyLong_AsInt(args[0]);
  5939. if (out_fd == -1 && PyErr_Occurred()) {
  5940. goto exit;
  5941. }
  5942. in_fd = _PyLong_AsInt(args[1]);
  5943. if (in_fd == -1 && PyErr_Occurred()) {
  5944. goto exit;
  5945. }
  5946. offobj = args[2];
  5947. {
  5948. Py_ssize_t ival = -1;
  5949. PyObject *iobj = _PyNumber_Index(args[3]);
  5950. if (iobj != NULL) {
  5951. ival = PyLong_AsSsize_t(iobj);
  5952. Py_DECREF(iobj);
  5953. }
  5954. if (ival == -1 && PyErr_Occurred()) {
  5955. goto exit;
  5956. }
  5957. count = ival;
  5958. }
  5959. return_value = os_sendfile_impl(module, out_fd, in_fd, offobj, count);
  5960. exit:
  5961. return return_value;
  5962. }
  5963. #endif /* defined(HAVE_SENDFILE) && !defined(__APPLE__) && !(defined(__FreeBSD__) || defined(__DragonFly__)) */
  5964. #if defined(__APPLE__)
  5965. PyDoc_STRVAR(os__fcopyfile__doc__,
  5966. "_fcopyfile($module, in_fd, out_fd, flags, /)\n"
  5967. "--\n"
  5968. "\n"
  5969. "Efficiently copy content or metadata of 2 regular file descriptors (macOS).");
  5970. #define OS__FCOPYFILE_METHODDEF \
  5971. {"_fcopyfile", _PyCFunction_CAST(os__fcopyfile), METH_FASTCALL, os__fcopyfile__doc__},
  5972. static PyObject *
  5973. os__fcopyfile_impl(PyObject *module, int in_fd, int out_fd, int flags);
  5974. static PyObject *
  5975. os__fcopyfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  5976. {
  5977. PyObject *return_value = NULL;
  5978. int in_fd;
  5979. int out_fd;
  5980. int flags;
  5981. if (!_PyArg_CheckPositional("_fcopyfile", nargs, 3, 3)) {
  5982. goto exit;
  5983. }
  5984. in_fd = _PyLong_AsInt(args[0]);
  5985. if (in_fd == -1 && PyErr_Occurred()) {
  5986. goto exit;
  5987. }
  5988. out_fd = _PyLong_AsInt(args[1]);
  5989. if (out_fd == -1 && PyErr_Occurred()) {
  5990. goto exit;
  5991. }
  5992. flags = _PyLong_AsInt(args[2]);
  5993. if (flags == -1 && PyErr_Occurred()) {
  5994. goto exit;
  5995. }
  5996. return_value = os__fcopyfile_impl(module, in_fd, out_fd, flags);
  5997. exit:
  5998. return return_value;
  5999. }
  6000. #endif /* defined(__APPLE__) */
  6001. PyDoc_STRVAR(os_fstat__doc__,
  6002. "fstat($module, /, fd)\n"
  6003. "--\n"
  6004. "\n"
  6005. "Perform a stat system call on the given file descriptor.\n"
  6006. "\n"
  6007. "Like stat(), but for an open file descriptor.\n"
  6008. "Equivalent to os.stat(fd).");
  6009. #define OS_FSTAT_METHODDEF \
  6010. {"fstat", _PyCFunction_CAST(os_fstat), METH_FASTCALL|METH_KEYWORDS, os_fstat__doc__},
  6011. static PyObject *
  6012. os_fstat_impl(PyObject *module, int fd);
  6013. static PyObject *
  6014. os_fstat(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6015. {
  6016. PyObject *return_value = NULL;
  6017. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6018. #define NUM_KEYWORDS 1
  6019. static struct {
  6020. PyGC_Head _this_is_not_used;
  6021. PyObject_VAR_HEAD
  6022. PyObject *ob_item[NUM_KEYWORDS];
  6023. } _kwtuple = {
  6024. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6025. .ob_item = { &_Py_ID(fd), },
  6026. };
  6027. #undef NUM_KEYWORDS
  6028. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6029. #else // !Py_BUILD_CORE
  6030. # define KWTUPLE NULL
  6031. #endif // !Py_BUILD_CORE
  6032. static const char * const _keywords[] = {"fd", NULL};
  6033. static _PyArg_Parser _parser = {
  6034. .keywords = _keywords,
  6035. .fname = "fstat",
  6036. .kwtuple = KWTUPLE,
  6037. };
  6038. #undef KWTUPLE
  6039. PyObject *argsbuf[1];
  6040. int fd;
  6041. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  6042. if (!args) {
  6043. goto exit;
  6044. }
  6045. fd = _PyLong_AsInt(args[0]);
  6046. if (fd == -1 && PyErr_Occurred()) {
  6047. goto exit;
  6048. }
  6049. return_value = os_fstat_impl(module, fd);
  6050. exit:
  6051. return return_value;
  6052. }
  6053. PyDoc_STRVAR(os_isatty__doc__,
  6054. "isatty($module, fd, /)\n"
  6055. "--\n"
  6056. "\n"
  6057. "Return True if the fd is connected to a terminal.\n"
  6058. "\n"
  6059. "Return True if the file descriptor is an open file descriptor\n"
  6060. "connected to the slave end of a terminal.");
  6061. #define OS_ISATTY_METHODDEF \
  6062. {"isatty", (PyCFunction)os_isatty, METH_O, os_isatty__doc__},
  6063. static int
  6064. os_isatty_impl(PyObject *module, int fd);
  6065. static PyObject *
  6066. os_isatty(PyObject *module, PyObject *arg)
  6067. {
  6068. PyObject *return_value = NULL;
  6069. int fd;
  6070. int _return_value;
  6071. fd = _PyLong_AsInt(arg);
  6072. if (fd == -1 && PyErr_Occurred()) {
  6073. goto exit;
  6074. }
  6075. _return_value = os_isatty_impl(module, fd);
  6076. if ((_return_value == -1) && PyErr_Occurred()) {
  6077. goto exit;
  6078. }
  6079. return_value = PyBool_FromLong((long)_return_value);
  6080. exit:
  6081. return return_value;
  6082. }
  6083. #if defined(HAVE_PIPE)
  6084. PyDoc_STRVAR(os_pipe__doc__,
  6085. "pipe($module, /)\n"
  6086. "--\n"
  6087. "\n"
  6088. "Create a pipe.\n"
  6089. "\n"
  6090. "Returns a tuple of two file descriptors:\n"
  6091. " (read_fd, write_fd)");
  6092. #define OS_PIPE_METHODDEF \
  6093. {"pipe", (PyCFunction)os_pipe, METH_NOARGS, os_pipe__doc__},
  6094. static PyObject *
  6095. os_pipe_impl(PyObject *module);
  6096. static PyObject *
  6097. os_pipe(PyObject *module, PyObject *Py_UNUSED(ignored))
  6098. {
  6099. return os_pipe_impl(module);
  6100. }
  6101. #endif /* defined(HAVE_PIPE) */
  6102. #if defined(HAVE_PIPE2)
  6103. PyDoc_STRVAR(os_pipe2__doc__,
  6104. "pipe2($module, flags, /)\n"
  6105. "--\n"
  6106. "\n"
  6107. "Create a pipe with flags set atomically.\n"
  6108. "\n"
  6109. "Returns a tuple of two file descriptors:\n"
  6110. " (read_fd, write_fd)\n"
  6111. "\n"
  6112. "flags can be constructed by ORing together one or more of these values:\n"
  6113. "O_NONBLOCK, O_CLOEXEC.");
  6114. #define OS_PIPE2_METHODDEF \
  6115. {"pipe2", (PyCFunction)os_pipe2, METH_O, os_pipe2__doc__},
  6116. static PyObject *
  6117. os_pipe2_impl(PyObject *module, int flags);
  6118. static PyObject *
  6119. os_pipe2(PyObject *module, PyObject *arg)
  6120. {
  6121. PyObject *return_value = NULL;
  6122. int flags;
  6123. flags = _PyLong_AsInt(arg);
  6124. if (flags == -1 && PyErr_Occurred()) {
  6125. goto exit;
  6126. }
  6127. return_value = os_pipe2_impl(module, flags);
  6128. exit:
  6129. return return_value;
  6130. }
  6131. #endif /* defined(HAVE_PIPE2) */
  6132. #if defined(HAVE_WRITEV)
  6133. PyDoc_STRVAR(os_writev__doc__,
  6134. "writev($module, fd, buffers, /)\n"
  6135. "--\n"
  6136. "\n"
  6137. "Iterate over buffers, and write the contents of each to a file descriptor.\n"
  6138. "\n"
  6139. "Returns the total number of bytes written.\n"
  6140. "buffers must be a sequence of bytes-like objects.");
  6141. #define OS_WRITEV_METHODDEF \
  6142. {"writev", _PyCFunction_CAST(os_writev), METH_FASTCALL, os_writev__doc__},
  6143. static Py_ssize_t
  6144. os_writev_impl(PyObject *module, int fd, PyObject *buffers);
  6145. static PyObject *
  6146. os_writev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6147. {
  6148. PyObject *return_value = NULL;
  6149. int fd;
  6150. PyObject *buffers;
  6151. Py_ssize_t _return_value;
  6152. if (!_PyArg_CheckPositional("writev", nargs, 2, 2)) {
  6153. goto exit;
  6154. }
  6155. fd = _PyLong_AsInt(args[0]);
  6156. if (fd == -1 && PyErr_Occurred()) {
  6157. goto exit;
  6158. }
  6159. buffers = args[1];
  6160. _return_value = os_writev_impl(module, fd, buffers);
  6161. if ((_return_value == -1) && PyErr_Occurred()) {
  6162. goto exit;
  6163. }
  6164. return_value = PyLong_FromSsize_t(_return_value);
  6165. exit:
  6166. return return_value;
  6167. }
  6168. #endif /* defined(HAVE_WRITEV) */
  6169. #if defined(HAVE_PWRITE)
  6170. PyDoc_STRVAR(os_pwrite__doc__,
  6171. "pwrite($module, fd, buffer, offset, /)\n"
  6172. "--\n"
  6173. "\n"
  6174. "Write bytes to a file descriptor starting at a particular offset.\n"
  6175. "\n"
  6176. "Write buffer to fd, starting at offset bytes from the beginning of\n"
  6177. "the file. Returns the number of bytes writte. Does not change the\n"
  6178. "current file offset.");
  6179. #define OS_PWRITE_METHODDEF \
  6180. {"pwrite", _PyCFunction_CAST(os_pwrite), METH_FASTCALL, os_pwrite__doc__},
  6181. static Py_ssize_t
  6182. os_pwrite_impl(PyObject *module, int fd, Py_buffer *buffer, Py_off_t offset);
  6183. static PyObject *
  6184. os_pwrite(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6185. {
  6186. PyObject *return_value = NULL;
  6187. int fd;
  6188. Py_buffer buffer = {NULL, NULL};
  6189. Py_off_t offset;
  6190. Py_ssize_t _return_value;
  6191. if (!_PyArg_CheckPositional("pwrite", nargs, 3, 3)) {
  6192. goto exit;
  6193. }
  6194. fd = _PyLong_AsInt(args[0]);
  6195. if (fd == -1 && PyErr_Occurred()) {
  6196. goto exit;
  6197. }
  6198. if (PyObject_GetBuffer(args[1], &buffer, PyBUF_SIMPLE) != 0) {
  6199. goto exit;
  6200. }
  6201. if (!PyBuffer_IsContiguous(&buffer, 'C')) {
  6202. _PyArg_BadArgument("pwrite", "argument 2", "contiguous buffer", args[1]);
  6203. goto exit;
  6204. }
  6205. if (!Py_off_t_converter(args[2], &offset)) {
  6206. goto exit;
  6207. }
  6208. _return_value = os_pwrite_impl(module, fd, &buffer, offset);
  6209. if ((_return_value == -1) && PyErr_Occurred()) {
  6210. goto exit;
  6211. }
  6212. return_value = PyLong_FromSsize_t(_return_value);
  6213. exit:
  6214. /* Cleanup for buffer */
  6215. if (buffer.obj) {
  6216. PyBuffer_Release(&buffer);
  6217. }
  6218. return return_value;
  6219. }
  6220. #endif /* defined(HAVE_PWRITE) */
  6221. #if (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2))
  6222. PyDoc_STRVAR(os_pwritev__doc__,
  6223. "pwritev($module, fd, buffers, offset, flags=0, /)\n"
  6224. "--\n"
  6225. "\n"
  6226. "Writes the contents of bytes-like objects to a file descriptor at a given offset.\n"
  6227. "\n"
  6228. "Combines the functionality of writev() and pwrite(). All buffers must be a sequence\n"
  6229. "of bytes-like objects. Buffers are processed in array order. Entire contents of first\n"
  6230. "buffer is written before proceeding to second, and so on. The operating system may\n"
  6231. "set a limit (sysconf() value SC_IOV_MAX) on the number of buffers that can be used.\n"
  6232. "This function writes the contents of each object to the file descriptor and returns\n"
  6233. "the total number of bytes written.\n"
  6234. "\n"
  6235. "The flags argument contains a bitwise OR of zero or more of the following flags:\n"
  6236. "\n"
  6237. "- RWF_DSYNC\n"
  6238. "- RWF_SYNC\n"
  6239. "- RWF_APPEND\n"
  6240. "\n"
  6241. "Using non-zero flags requires Linux 4.7 or newer.");
  6242. #define OS_PWRITEV_METHODDEF \
  6243. {"pwritev", _PyCFunction_CAST(os_pwritev), METH_FASTCALL, os_pwritev__doc__},
  6244. static Py_ssize_t
  6245. os_pwritev_impl(PyObject *module, int fd, PyObject *buffers, Py_off_t offset,
  6246. int flags);
  6247. static PyObject *
  6248. os_pwritev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6249. {
  6250. PyObject *return_value = NULL;
  6251. int fd;
  6252. PyObject *buffers;
  6253. Py_off_t offset;
  6254. int flags = 0;
  6255. Py_ssize_t _return_value;
  6256. if (!_PyArg_CheckPositional("pwritev", nargs, 3, 4)) {
  6257. goto exit;
  6258. }
  6259. fd = _PyLong_AsInt(args[0]);
  6260. if (fd == -1 && PyErr_Occurred()) {
  6261. goto exit;
  6262. }
  6263. buffers = args[1];
  6264. if (!Py_off_t_converter(args[2], &offset)) {
  6265. goto exit;
  6266. }
  6267. if (nargs < 4) {
  6268. goto skip_optional;
  6269. }
  6270. flags = _PyLong_AsInt(args[3]);
  6271. if (flags == -1 && PyErr_Occurred()) {
  6272. goto exit;
  6273. }
  6274. skip_optional:
  6275. _return_value = os_pwritev_impl(module, fd, buffers, offset, flags);
  6276. if ((_return_value == -1) && PyErr_Occurred()) {
  6277. goto exit;
  6278. }
  6279. return_value = PyLong_FromSsize_t(_return_value);
  6280. exit:
  6281. return return_value;
  6282. }
  6283. #endif /* (defined(HAVE_PWRITEV) || defined (HAVE_PWRITEV2)) */
  6284. #if defined(HAVE_COPY_FILE_RANGE)
  6285. PyDoc_STRVAR(os_copy_file_range__doc__,
  6286. "copy_file_range($module, /, src, dst, count, offset_src=None,\n"
  6287. " offset_dst=None)\n"
  6288. "--\n"
  6289. "\n"
  6290. "Copy count bytes from one file descriptor to another.\n"
  6291. "\n"
  6292. " src\n"
  6293. " Source file descriptor.\n"
  6294. " dst\n"
  6295. " Destination file descriptor.\n"
  6296. " count\n"
  6297. " Number of bytes to copy.\n"
  6298. " offset_src\n"
  6299. " Starting offset in src.\n"
  6300. " offset_dst\n"
  6301. " Starting offset in dst.\n"
  6302. "\n"
  6303. "If offset_src is None, then src is read from the current position;\n"
  6304. "respectively for offset_dst.");
  6305. #define OS_COPY_FILE_RANGE_METHODDEF \
  6306. {"copy_file_range", _PyCFunction_CAST(os_copy_file_range), METH_FASTCALL|METH_KEYWORDS, os_copy_file_range__doc__},
  6307. static PyObject *
  6308. os_copy_file_range_impl(PyObject *module, int src, int dst, Py_ssize_t count,
  6309. PyObject *offset_src, PyObject *offset_dst);
  6310. static PyObject *
  6311. os_copy_file_range(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6312. {
  6313. PyObject *return_value = NULL;
  6314. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6315. #define NUM_KEYWORDS 5
  6316. static struct {
  6317. PyGC_Head _this_is_not_used;
  6318. PyObject_VAR_HEAD
  6319. PyObject *ob_item[NUM_KEYWORDS];
  6320. } _kwtuple = {
  6321. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6322. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), },
  6323. };
  6324. #undef NUM_KEYWORDS
  6325. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6326. #else // !Py_BUILD_CORE
  6327. # define KWTUPLE NULL
  6328. #endif // !Py_BUILD_CORE
  6329. static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", NULL};
  6330. static _PyArg_Parser _parser = {
  6331. .keywords = _keywords,
  6332. .fname = "copy_file_range",
  6333. .kwtuple = KWTUPLE,
  6334. };
  6335. #undef KWTUPLE
  6336. PyObject *argsbuf[5];
  6337. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  6338. int src;
  6339. int dst;
  6340. Py_ssize_t count;
  6341. PyObject *offset_src = Py_None;
  6342. PyObject *offset_dst = Py_None;
  6343. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 5, 0, argsbuf);
  6344. if (!args) {
  6345. goto exit;
  6346. }
  6347. src = _PyLong_AsInt(args[0]);
  6348. if (src == -1 && PyErr_Occurred()) {
  6349. goto exit;
  6350. }
  6351. dst = _PyLong_AsInt(args[1]);
  6352. if (dst == -1 && PyErr_Occurred()) {
  6353. goto exit;
  6354. }
  6355. {
  6356. Py_ssize_t ival = -1;
  6357. PyObject *iobj = _PyNumber_Index(args[2]);
  6358. if (iobj != NULL) {
  6359. ival = PyLong_AsSsize_t(iobj);
  6360. Py_DECREF(iobj);
  6361. }
  6362. if (ival == -1 && PyErr_Occurred()) {
  6363. goto exit;
  6364. }
  6365. count = ival;
  6366. }
  6367. if (!noptargs) {
  6368. goto skip_optional_pos;
  6369. }
  6370. if (args[3]) {
  6371. offset_src = args[3];
  6372. if (!--noptargs) {
  6373. goto skip_optional_pos;
  6374. }
  6375. }
  6376. offset_dst = args[4];
  6377. skip_optional_pos:
  6378. return_value = os_copy_file_range_impl(module, src, dst, count, offset_src, offset_dst);
  6379. exit:
  6380. return return_value;
  6381. }
  6382. #endif /* defined(HAVE_COPY_FILE_RANGE) */
  6383. #if ((defined(HAVE_SPLICE) && !defined(_AIX)))
  6384. PyDoc_STRVAR(os_splice__doc__,
  6385. "splice($module, /, src, dst, count, offset_src=None, offset_dst=None,\n"
  6386. " flags=0)\n"
  6387. "--\n"
  6388. "\n"
  6389. "Transfer count bytes from one pipe to a descriptor or vice versa.\n"
  6390. "\n"
  6391. " src\n"
  6392. " Source file descriptor.\n"
  6393. " dst\n"
  6394. " Destination file descriptor.\n"
  6395. " count\n"
  6396. " Number of bytes to copy.\n"
  6397. " offset_src\n"
  6398. " Starting offset in src.\n"
  6399. " offset_dst\n"
  6400. " Starting offset in dst.\n"
  6401. " flags\n"
  6402. " Flags to modify the semantics of the call.\n"
  6403. "\n"
  6404. "If offset_src is None, then src is read from the current position;\n"
  6405. "respectively for offset_dst. The offset associated to the file\n"
  6406. "descriptor that refers to a pipe must be None.");
  6407. #define OS_SPLICE_METHODDEF \
  6408. {"splice", _PyCFunction_CAST(os_splice), METH_FASTCALL|METH_KEYWORDS, os_splice__doc__},
  6409. static PyObject *
  6410. os_splice_impl(PyObject *module, int src, int dst, Py_ssize_t count,
  6411. PyObject *offset_src, PyObject *offset_dst,
  6412. unsigned int flags);
  6413. static PyObject *
  6414. os_splice(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6415. {
  6416. PyObject *return_value = NULL;
  6417. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6418. #define NUM_KEYWORDS 6
  6419. static struct {
  6420. PyGC_Head _this_is_not_used;
  6421. PyObject_VAR_HEAD
  6422. PyObject *ob_item[NUM_KEYWORDS];
  6423. } _kwtuple = {
  6424. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6425. .ob_item = { &_Py_ID(src), &_Py_ID(dst), &_Py_ID(count), &_Py_ID(offset_src), &_Py_ID(offset_dst), &_Py_ID(flags), },
  6426. };
  6427. #undef NUM_KEYWORDS
  6428. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6429. #else // !Py_BUILD_CORE
  6430. # define KWTUPLE NULL
  6431. #endif // !Py_BUILD_CORE
  6432. static const char * const _keywords[] = {"src", "dst", "count", "offset_src", "offset_dst", "flags", NULL};
  6433. static _PyArg_Parser _parser = {
  6434. .keywords = _keywords,
  6435. .fname = "splice",
  6436. .kwtuple = KWTUPLE,
  6437. };
  6438. #undef KWTUPLE
  6439. PyObject *argsbuf[6];
  6440. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  6441. int src;
  6442. int dst;
  6443. Py_ssize_t count;
  6444. PyObject *offset_src = Py_None;
  6445. PyObject *offset_dst = Py_None;
  6446. unsigned int flags = 0;
  6447. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 6, 0, argsbuf);
  6448. if (!args) {
  6449. goto exit;
  6450. }
  6451. src = _PyLong_AsInt(args[0]);
  6452. if (src == -1 && PyErr_Occurred()) {
  6453. goto exit;
  6454. }
  6455. dst = _PyLong_AsInt(args[1]);
  6456. if (dst == -1 && PyErr_Occurred()) {
  6457. goto exit;
  6458. }
  6459. {
  6460. Py_ssize_t ival = -1;
  6461. PyObject *iobj = _PyNumber_Index(args[2]);
  6462. if (iobj != NULL) {
  6463. ival = PyLong_AsSsize_t(iobj);
  6464. Py_DECREF(iobj);
  6465. }
  6466. if (ival == -1 && PyErr_Occurred()) {
  6467. goto exit;
  6468. }
  6469. count = ival;
  6470. }
  6471. if (!noptargs) {
  6472. goto skip_optional_pos;
  6473. }
  6474. if (args[3]) {
  6475. offset_src = args[3];
  6476. if (!--noptargs) {
  6477. goto skip_optional_pos;
  6478. }
  6479. }
  6480. if (args[4]) {
  6481. offset_dst = args[4];
  6482. if (!--noptargs) {
  6483. goto skip_optional_pos;
  6484. }
  6485. }
  6486. if (!_PyLong_UnsignedInt_Converter(args[5], &flags)) {
  6487. goto exit;
  6488. }
  6489. skip_optional_pos:
  6490. return_value = os_splice_impl(module, src, dst, count, offset_src, offset_dst, flags);
  6491. exit:
  6492. return return_value;
  6493. }
  6494. #endif /* ((defined(HAVE_SPLICE) && !defined(_AIX))) */
  6495. #if defined(HAVE_MKFIFO)
  6496. PyDoc_STRVAR(os_mkfifo__doc__,
  6497. "mkfifo($module, /, path, mode=438, *, dir_fd=None)\n"
  6498. "--\n"
  6499. "\n"
  6500. "Create a \"fifo\" (a POSIX named pipe).\n"
  6501. "\n"
  6502. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  6503. " and path should be relative; path will then be relative to that directory.\n"
  6504. "dir_fd may not be implemented on your platform.\n"
  6505. " If it is unavailable, using it will raise a NotImplementedError.");
  6506. #define OS_MKFIFO_METHODDEF \
  6507. {"mkfifo", _PyCFunction_CAST(os_mkfifo), METH_FASTCALL|METH_KEYWORDS, os_mkfifo__doc__},
  6508. static PyObject *
  6509. os_mkfifo_impl(PyObject *module, path_t *path, int mode, int dir_fd);
  6510. static PyObject *
  6511. os_mkfifo(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6512. {
  6513. PyObject *return_value = NULL;
  6514. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6515. #define NUM_KEYWORDS 3
  6516. static struct {
  6517. PyGC_Head _this_is_not_used;
  6518. PyObject_VAR_HEAD
  6519. PyObject *ob_item[NUM_KEYWORDS];
  6520. } _kwtuple = {
  6521. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6522. .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(dir_fd), },
  6523. };
  6524. #undef NUM_KEYWORDS
  6525. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6526. #else // !Py_BUILD_CORE
  6527. # define KWTUPLE NULL
  6528. #endif // !Py_BUILD_CORE
  6529. static const char * const _keywords[] = {"path", "mode", "dir_fd", NULL};
  6530. static _PyArg_Parser _parser = {
  6531. .keywords = _keywords,
  6532. .fname = "mkfifo",
  6533. .kwtuple = KWTUPLE,
  6534. };
  6535. #undef KWTUPLE
  6536. PyObject *argsbuf[3];
  6537. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  6538. path_t path = PATH_T_INITIALIZE_P("mkfifo", "path", 0, 0, 0, 0);
  6539. int mode = 438;
  6540. int dir_fd = DEFAULT_DIR_FD;
  6541. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  6542. if (!args) {
  6543. goto exit;
  6544. }
  6545. if (!path_converter(args[0], &path)) {
  6546. goto exit;
  6547. }
  6548. if (!noptargs) {
  6549. goto skip_optional_pos;
  6550. }
  6551. if (args[1]) {
  6552. mode = _PyLong_AsInt(args[1]);
  6553. if (mode == -1 && PyErr_Occurred()) {
  6554. goto exit;
  6555. }
  6556. if (!--noptargs) {
  6557. goto skip_optional_pos;
  6558. }
  6559. }
  6560. skip_optional_pos:
  6561. if (!noptargs) {
  6562. goto skip_optional_kwonly;
  6563. }
  6564. if (!MKFIFOAT_DIR_FD_CONVERTER(args[2], &dir_fd)) {
  6565. goto exit;
  6566. }
  6567. skip_optional_kwonly:
  6568. return_value = os_mkfifo_impl(module, &path, mode, dir_fd);
  6569. exit:
  6570. /* Cleanup for path */
  6571. path_cleanup(&path);
  6572. return return_value;
  6573. }
  6574. #endif /* defined(HAVE_MKFIFO) */
  6575. #if (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV))
  6576. PyDoc_STRVAR(os_mknod__doc__,
  6577. "mknod($module, /, path, mode=384, device=0, *, dir_fd=None)\n"
  6578. "--\n"
  6579. "\n"
  6580. "Create a node in the file system.\n"
  6581. "\n"
  6582. "Create a node in the file system (file, device special file or named pipe)\n"
  6583. "at path. mode specifies both the permissions to use and the\n"
  6584. "type of node to be created, being combined (bitwise OR) with one of\n"
  6585. "S_IFREG, S_IFCHR, S_IFBLK, and S_IFIFO. If S_IFCHR or S_IFBLK is set on mode,\n"
  6586. "device defines the newly created device special file (probably using\n"
  6587. "os.makedev()). Otherwise device is ignored.\n"
  6588. "\n"
  6589. "If dir_fd is not None, it should be a file descriptor open to a directory,\n"
  6590. " and path should be relative; path will then be relative to that directory.\n"
  6591. "dir_fd may not be implemented on your platform.\n"
  6592. " If it is unavailable, using it will raise a NotImplementedError.");
  6593. #define OS_MKNOD_METHODDEF \
  6594. {"mknod", _PyCFunction_CAST(os_mknod), METH_FASTCALL|METH_KEYWORDS, os_mknod__doc__},
  6595. static PyObject *
  6596. os_mknod_impl(PyObject *module, path_t *path, int mode, dev_t device,
  6597. int dir_fd);
  6598. static PyObject *
  6599. os_mknod(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6600. {
  6601. PyObject *return_value = NULL;
  6602. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6603. #define NUM_KEYWORDS 4
  6604. static struct {
  6605. PyGC_Head _this_is_not_used;
  6606. PyObject_VAR_HEAD
  6607. PyObject *ob_item[NUM_KEYWORDS];
  6608. } _kwtuple = {
  6609. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6610. .ob_item = { &_Py_ID(path), &_Py_ID(mode), &_Py_ID(device), &_Py_ID(dir_fd), },
  6611. };
  6612. #undef NUM_KEYWORDS
  6613. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6614. #else // !Py_BUILD_CORE
  6615. # define KWTUPLE NULL
  6616. #endif // !Py_BUILD_CORE
  6617. static const char * const _keywords[] = {"path", "mode", "device", "dir_fd", NULL};
  6618. static _PyArg_Parser _parser = {
  6619. .keywords = _keywords,
  6620. .fname = "mknod",
  6621. .kwtuple = KWTUPLE,
  6622. };
  6623. #undef KWTUPLE
  6624. PyObject *argsbuf[4];
  6625. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  6626. path_t path = PATH_T_INITIALIZE_P("mknod", "path", 0, 0, 0, 0);
  6627. int mode = 384;
  6628. dev_t device = 0;
  6629. int dir_fd = DEFAULT_DIR_FD;
  6630. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 3, 0, argsbuf);
  6631. if (!args) {
  6632. goto exit;
  6633. }
  6634. if (!path_converter(args[0], &path)) {
  6635. goto exit;
  6636. }
  6637. if (!noptargs) {
  6638. goto skip_optional_pos;
  6639. }
  6640. if (args[1]) {
  6641. mode = _PyLong_AsInt(args[1]);
  6642. if (mode == -1 && PyErr_Occurred()) {
  6643. goto exit;
  6644. }
  6645. if (!--noptargs) {
  6646. goto skip_optional_pos;
  6647. }
  6648. }
  6649. if (args[2]) {
  6650. if (!_Py_Dev_Converter(args[2], &device)) {
  6651. goto exit;
  6652. }
  6653. if (!--noptargs) {
  6654. goto skip_optional_pos;
  6655. }
  6656. }
  6657. skip_optional_pos:
  6658. if (!noptargs) {
  6659. goto skip_optional_kwonly;
  6660. }
  6661. if (!MKNODAT_DIR_FD_CONVERTER(args[3], &dir_fd)) {
  6662. goto exit;
  6663. }
  6664. skip_optional_kwonly:
  6665. return_value = os_mknod_impl(module, &path, mode, device, dir_fd);
  6666. exit:
  6667. /* Cleanup for path */
  6668. path_cleanup(&path);
  6669. return return_value;
  6670. }
  6671. #endif /* (defined(HAVE_MKNOD) && defined(HAVE_MAKEDEV)) */
  6672. #if defined(HAVE_DEVICE_MACROS)
  6673. PyDoc_STRVAR(os_major__doc__,
  6674. "major($module, device, /)\n"
  6675. "--\n"
  6676. "\n"
  6677. "Extracts a device major number from a raw device number.");
  6678. #define OS_MAJOR_METHODDEF \
  6679. {"major", (PyCFunction)os_major, METH_O, os_major__doc__},
  6680. static PyObject *
  6681. os_major_impl(PyObject *module, dev_t device);
  6682. static PyObject *
  6683. os_major(PyObject *module, PyObject *arg)
  6684. {
  6685. PyObject *return_value = NULL;
  6686. dev_t device;
  6687. if (!_Py_Dev_Converter(arg, &device)) {
  6688. goto exit;
  6689. }
  6690. return_value = os_major_impl(module, device);
  6691. exit:
  6692. return return_value;
  6693. }
  6694. #endif /* defined(HAVE_DEVICE_MACROS) */
  6695. #if defined(HAVE_DEVICE_MACROS)
  6696. PyDoc_STRVAR(os_minor__doc__,
  6697. "minor($module, device, /)\n"
  6698. "--\n"
  6699. "\n"
  6700. "Extracts a device minor number from a raw device number.");
  6701. #define OS_MINOR_METHODDEF \
  6702. {"minor", (PyCFunction)os_minor, METH_O, os_minor__doc__},
  6703. static PyObject *
  6704. os_minor_impl(PyObject *module, dev_t device);
  6705. static PyObject *
  6706. os_minor(PyObject *module, PyObject *arg)
  6707. {
  6708. PyObject *return_value = NULL;
  6709. dev_t device;
  6710. if (!_Py_Dev_Converter(arg, &device)) {
  6711. goto exit;
  6712. }
  6713. return_value = os_minor_impl(module, device);
  6714. exit:
  6715. return return_value;
  6716. }
  6717. #endif /* defined(HAVE_DEVICE_MACROS) */
  6718. #if defined(HAVE_DEVICE_MACROS)
  6719. PyDoc_STRVAR(os_makedev__doc__,
  6720. "makedev($module, major, minor, /)\n"
  6721. "--\n"
  6722. "\n"
  6723. "Composes a raw device number from the major and minor device numbers.");
  6724. #define OS_MAKEDEV_METHODDEF \
  6725. {"makedev", _PyCFunction_CAST(os_makedev), METH_FASTCALL, os_makedev__doc__},
  6726. static dev_t
  6727. os_makedev_impl(PyObject *module, dev_t major, dev_t minor);
  6728. static PyObject *
  6729. os_makedev(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6730. {
  6731. PyObject *return_value = NULL;
  6732. dev_t major;
  6733. dev_t minor;
  6734. dev_t _return_value;
  6735. if (!_PyArg_CheckPositional("makedev", nargs, 2, 2)) {
  6736. goto exit;
  6737. }
  6738. if (!_Py_Dev_Converter(args[0], &major)) {
  6739. goto exit;
  6740. }
  6741. if (!_Py_Dev_Converter(args[1], &minor)) {
  6742. goto exit;
  6743. }
  6744. _return_value = os_makedev_impl(module, major, minor);
  6745. if ((_return_value == (dev_t)-1) && PyErr_Occurred()) {
  6746. goto exit;
  6747. }
  6748. return_value = _PyLong_FromDev(_return_value);
  6749. exit:
  6750. return return_value;
  6751. }
  6752. #endif /* defined(HAVE_DEVICE_MACROS) */
  6753. #if (defined HAVE_FTRUNCATE || defined MS_WINDOWS)
  6754. PyDoc_STRVAR(os_ftruncate__doc__,
  6755. "ftruncate($module, fd, length, /)\n"
  6756. "--\n"
  6757. "\n"
  6758. "Truncate a file, specified by file descriptor, to a specific length.");
  6759. #define OS_FTRUNCATE_METHODDEF \
  6760. {"ftruncate", _PyCFunction_CAST(os_ftruncate), METH_FASTCALL, os_ftruncate__doc__},
  6761. static PyObject *
  6762. os_ftruncate_impl(PyObject *module, int fd, Py_off_t length);
  6763. static PyObject *
  6764. os_ftruncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6765. {
  6766. PyObject *return_value = NULL;
  6767. int fd;
  6768. Py_off_t length;
  6769. if (!_PyArg_CheckPositional("ftruncate", nargs, 2, 2)) {
  6770. goto exit;
  6771. }
  6772. fd = _PyLong_AsInt(args[0]);
  6773. if (fd == -1 && PyErr_Occurred()) {
  6774. goto exit;
  6775. }
  6776. if (!Py_off_t_converter(args[1], &length)) {
  6777. goto exit;
  6778. }
  6779. return_value = os_ftruncate_impl(module, fd, length);
  6780. exit:
  6781. return return_value;
  6782. }
  6783. #endif /* (defined HAVE_FTRUNCATE || defined MS_WINDOWS) */
  6784. #if (defined HAVE_TRUNCATE || defined MS_WINDOWS)
  6785. PyDoc_STRVAR(os_truncate__doc__,
  6786. "truncate($module, /, path, length)\n"
  6787. "--\n"
  6788. "\n"
  6789. "Truncate a file, specified by path, to a specific length.\n"
  6790. "\n"
  6791. "On some platforms, path may also be specified as an open file descriptor.\n"
  6792. " If this functionality is unavailable, using it raises an exception.");
  6793. #define OS_TRUNCATE_METHODDEF \
  6794. {"truncate", _PyCFunction_CAST(os_truncate), METH_FASTCALL|METH_KEYWORDS, os_truncate__doc__},
  6795. static PyObject *
  6796. os_truncate_impl(PyObject *module, path_t *path, Py_off_t length);
  6797. static PyObject *
  6798. os_truncate(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  6799. {
  6800. PyObject *return_value = NULL;
  6801. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  6802. #define NUM_KEYWORDS 2
  6803. static struct {
  6804. PyGC_Head _this_is_not_used;
  6805. PyObject_VAR_HEAD
  6806. PyObject *ob_item[NUM_KEYWORDS];
  6807. } _kwtuple = {
  6808. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  6809. .ob_item = { &_Py_ID(path), &_Py_ID(length), },
  6810. };
  6811. #undef NUM_KEYWORDS
  6812. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  6813. #else // !Py_BUILD_CORE
  6814. # define KWTUPLE NULL
  6815. #endif // !Py_BUILD_CORE
  6816. static const char * const _keywords[] = {"path", "length", NULL};
  6817. static _PyArg_Parser _parser = {
  6818. .keywords = _keywords,
  6819. .fname = "truncate",
  6820. .kwtuple = KWTUPLE,
  6821. };
  6822. #undef KWTUPLE
  6823. PyObject *argsbuf[2];
  6824. path_t path = PATH_T_INITIALIZE_P("truncate", "path", 0, 0, 0, PATH_HAVE_FTRUNCATE);
  6825. Py_off_t length;
  6826. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  6827. if (!args) {
  6828. goto exit;
  6829. }
  6830. if (!path_converter(args[0], &path)) {
  6831. goto exit;
  6832. }
  6833. if (!Py_off_t_converter(args[1], &length)) {
  6834. goto exit;
  6835. }
  6836. return_value = os_truncate_impl(module, &path, length);
  6837. exit:
  6838. /* Cleanup for path */
  6839. path_cleanup(&path);
  6840. return return_value;
  6841. }
  6842. #endif /* (defined HAVE_TRUNCATE || defined MS_WINDOWS) */
  6843. #if (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__))
  6844. PyDoc_STRVAR(os_posix_fallocate__doc__,
  6845. "posix_fallocate($module, fd, offset, length, /)\n"
  6846. "--\n"
  6847. "\n"
  6848. "Ensure a file has allocated at least a particular number of bytes on disk.\n"
  6849. "\n"
  6850. "Ensure that the file specified by fd encompasses a range of bytes\n"
  6851. "starting at offset bytes from the beginning and continuing for length bytes.");
  6852. #define OS_POSIX_FALLOCATE_METHODDEF \
  6853. {"posix_fallocate", _PyCFunction_CAST(os_posix_fallocate), METH_FASTCALL, os_posix_fallocate__doc__},
  6854. static PyObject *
  6855. os_posix_fallocate_impl(PyObject *module, int fd, Py_off_t offset,
  6856. Py_off_t length);
  6857. static PyObject *
  6858. os_posix_fallocate(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6859. {
  6860. PyObject *return_value = NULL;
  6861. int fd;
  6862. Py_off_t offset;
  6863. Py_off_t length;
  6864. if (!_PyArg_CheckPositional("posix_fallocate", nargs, 3, 3)) {
  6865. goto exit;
  6866. }
  6867. fd = _PyLong_AsInt(args[0]);
  6868. if (fd == -1 && PyErr_Occurred()) {
  6869. goto exit;
  6870. }
  6871. if (!Py_off_t_converter(args[1], &offset)) {
  6872. goto exit;
  6873. }
  6874. if (!Py_off_t_converter(args[2], &length)) {
  6875. goto exit;
  6876. }
  6877. return_value = os_posix_fallocate_impl(module, fd, offset, length);
  6878. exit:
  6879. return return_value;
  6880. }
  6881. #endif /* (defined(HAVE_POSIX_FALLOCATE) && !defined(POSIX_FADVISE_AIX_BUG) && !defined(__wasi__)) */
  6882. #if (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG))
  6883. PyDoc_STRVAR(os_posix_fadvise__doc__,
  6884. "posix_fadvise($module, fd, offset, length, advice, /)\n"
  6885. "--\n"
  6886. "\n"
  6887. "Announce an intention to access data in a specific pattern.\n"
  6888. "\n"
  6889. "Announce an intention to access data in a specific pattern, thus allowing\n"
  6890. "the kernel to make optimizations.\n"
  6891. "The advice applies to the region of the file specified by fd starting at\n"
  6892. "offset and continuing for length bytes.\n"
  6893. "advice is one of POSIX_FADV_NORMAL, POSIX_FADV_SEQUENTIAL,\n"
  6894. "POSIX_FADV_RANDOM, POSIX_FADV_NOREUSE, POSIX_FADV_WILLNEED, or\n"
  6895. "POSIX_FADV_DONTNEED.");
  6896. #define OS_POSIX_FADVISE_METHODDEF \
  6897. {"posix_fadvise", _PyCFunction_CAST(os_posix_fadvise), METH_FASTCALL, os_posix_fadvise__doc__},
  6898. static PyObject *
  6899. os_posix_fadvise_impl(PyObject *module, int fd, Py_off_t offset,
  6900. Py_off_t length, int advice);
  6901. static PyObject *
  6902. os_posix_fadvise(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6903. {
  6904. PyObject *return_value = NULL;
  6905. int fd;
  6906. Py_off_t offset;
  6907. Py_off_t length;
  6908. int advice;
  6909. if (!_PyArg_CheckPositional("posix_fadvise", nargs, 4, 4)) {
  6910. goto exit;
  6911. }
  6912. fd = _PyLong_AsInt(args[0]);
  6913. if (fd == -1 && PyErr_Occurred()) {
  6914. goto exit;
  6915. }
  6916. if (!Py_off_t_converter(args[1], &offset)) {
  6917. goto exit;
  6918. }
  6919. if (!Py_off_t_converter(args[2], &length)) {
  6920. goto exit;
  6921. }
  6922. advice = _PyLong_AsInt(args[3]);
  6923. if (advice == -1 && PyErr_Occurred()) {
  6924. goto exit;
  6925. }
  6926. return_value = os_posix_fadvise_impl(module, fd, offset, length, advice);
  6927. exit:
  6928. return return_value;
  6929. }
  6930. #endif /* (defined(HAVE_POSIX_FADVISE) && !defined(POSIX_FADVISE_AIX_BUG)) */
  6931. #if defined(MS_WINDOWS)
  6932. PyDoc_STRVAR(os_putenv__doc__,
  6933. "putenv($module, name, value, /)\n"
  6934. "--\n"
  6935. "\n"
  6936. "Change or add an environment variable.");
  6937. #define OS_PUTENV_METHODDEF \
  6938. {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
  6939. static PyObject *
  6940. os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
  6941. static PyObject *
  6942. os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6943. {
  6944. PyObject *return_value = NULL;
  6945. PyObject *name;
  6946. PyObject *value;
  6947. if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
  6948. goto exit;
  6949. }
  6950. if (!PyUnicode_Check(args[0])) {
  6951. _PyArg_BadArgument("putenv", "argument 1", "str", args[0]);
  6952. goto exit;
  6953. }
  6954. if (PyUnicode_READY(args[0]) == -1) {
  6955. goto exit;
  6956. }
  6957. name = args[0];
  6958. if (!PyUnicode_Check(args[1])) {
  6959. _PyArg_BadArgument("putenv", "argument 2", "str", args[1]);
  6960. goto exit;
  6961. }
  6962. if (PyUnicode_READY(args[1]) == -1) {
  6963. goto exit;
  6964. }
  6965. value = args[1];
  6966. return_value = os_putenv_impl(module, name, value);
  6967. exit:
  6968. return return_value;
  6969. }
  6970. #endif /* defined(MS_WINDOWS) */
  6971. #if !defined(MS_WINDOWS)
  6972. PyDoc_STRVAR(os_putenv__doc__,
  6973. "putenv($module, name, value, /)\n"
  6974. "--\n"
  6975. "\n"
  6976. "Change or add an environment variable.");
  6977. #define OS_PUTENV_METHODDEF \
  6978. {"putenv", _PyCFunction_CAST(os_putenv), METH_FASTCALL, os_putenv__doc__},
  6979. static PyObject *
  6980. os_putenv_impl(PyObject *module, PyObject *name, PyObject *value);
  6981. static PyObject *
  6982. os_putenv(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  6983. {
  6984. PyObject *return_value = NULL;
  6985. PyObject *name = NULL;
  6986. PyObject *value = NULL;
  6987. if (!_PyArg_CheckPositional("putenv", nargs, 2, 2)) {
  6988. goto exit;
  6989. }
  6990. if (!PyUnicode_FSConverter(args[0], &name)) {
  6991. goto exit;
  6992. }
  6993. if (!PyUnicode_FSConverter(args[1], &value)) {
  6994. goto exit;
  6995. }
  6996. return_value = os_putenv_impl(module, name, value);
  6997. exit:
  6998. /* Cleanup for name */
  6999. Py_XDECREF(name);
  7000. /* Cleanup for value */
  7001. Py_XDECREF(value);
  7002. return return_value;
  7003. }
  7004. #endif /* !defined(MS_WINDOWS) */
  7005. #if defined(MS_WINDOWS)
  7006. PyDoc_STRVAR(os_unsetenv__doc__,
  7007. "unsetenv($module, name, /)\n"
  7008. "--\n"
  7009. "\n"
  7010. "Delete an environment variable.");
  7011. #define OS_UNSETENV_METHODDEF \
  7012. {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
  7013. static PyObject *
  7014. os_unsetenv_impl(PyObject *module, PyObject *name);
  7015. static PyObject *
  7016. os_unsetenv(PyObject *module, PyObject *arg)
  7017. {
  7018. PyObject *return_value = NULL;
  7019. PyObject *name;
  7020. if (!PyUnicode_Check(arg)) {
  7021. _PyArg_BadArgument("unsetenv", "argument", "str", arg);
  7022. goto exit;
  7023. }
  7024. if (PyUnicode_READY(arg) == -1) {
  7025. goto exit;
  7026. }
  7027. name = arg;
  7028. return_value = os_unsetenv_impl(module, name);
  7029. exit:
  7030. return return_value;
  7031. }
  7032. #endif /* defined(MS_WINDOWS) */
  7033. #if !defined(MS_WINDOWS)
  7034. PyDoc_STRVAR(os_unsetenv__doc__,
  7035. "unsetenv($module, name, /)\n"
  7036. "--\n"
  7037. "\n"
  7038. "Delete an environment variable.");
  7039. #define OS_UNSETENV_METHODDEF \
  7040. {"unsetenv", (PyCFunction)os_unsetenv, METH_O, os_unsetenv__doc__},
  7041. static PyObject *
  7042. os_unsetenv_impl(PyObject *module, PyObject *name);
  7043. static PyObject *
  7044. os_unsetenv(PyObject *module, PyObject *arg)
  7045. {
  7046. PyObject *return_value = NULL;
  7047. PyObject *name = NULL;
  7048. if (!PyUnicode_FSConverter(arg, &name)) {
  7049. goto exit;
  7050. }
  7051. return_value = os_unsetenv_impl(module, name);
  7052. exit:
  7053. /* Cleanup for name */
  7054. Py_XDECREF(name);
  7055. return return_value;
  7056. }
  7057. #endif /* !defined(MS_WINDOWS) */
  7058. PyDoc_STRVAR(os_strerror__doc__,
  7059. "strerror($module, code, /)\n"
  7060. "--\n"
  7061. "\n"
  7062. "Translate an error code to a message string.");
  7063. #define OS_STRERROR_METHODDEF \
  7064. {"strerror", (PyCFunction)os_strerror, METH_O, os_strerror__doc__},
  7065. static PyObject *
  7066. os_strerror_impl(PyObject *module, int code);
  7067. static PyObject *
  7068. os_strerror(PyObject *module, PyObject *arg)
  7069. {
  7070. PyObject *return_value = NULL;
  7071. int code;
  7072. code = _PyLong_AsInt(arg);
  7073. if (code == -1 && PyErr_Occurred()) {
  7074. goto exit;
  7075. }
  7076. return_value = os_strerror_impl(module, code);
  7077. exit:
  7078. return return_value;
  7079. }
  7080. #if defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP)
  7081. PyDoc_STRVAR(os_WCOREDUMP__doc__,
  7082. "WCOREDUMP($module, status, /)\n"
  7083. "--\n"
  7084. "\n"
  7085. "Return True if the process returning status was dumped to a core file.");
  7086. #define OS_WCOREDUMP_METHODDEF \
  7087. {"WCOREDUMP", (PyCFunction)os_WCOREDUMP, METH_O, os_WCOREDUMP__doc__},
  7088. static int
  7089. os_WCOREDUMP_impl(PyObject *module, int status);
  7090. static PyObject *
  7091. os_WCOREDUMP(PyObject *module, PyObject *arg)
  7092. {
  7093. PyObject *return_value = NULL;
  7094. int status;
  7095. int _return_value;
  7096. status = _PyLong_AsInt(arg);
  7097. if (status == -1 && PyErr_Occurred()) {
  7098. goto exit;
  7099. }
  7100. _return_value = os_WCOREDUMP_impl(module, status);
  7101. if ((_return_value == -1) && PyErr_Occurred()) {
  7102. goto exit;
  7103. }
  7104. return_value = PyBool_FromLong((long)_return_value);
  7105. exit:
  7106. return return_value;
  7107. }
  7108. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WCOREDUMP) */
  7109. #if defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED)
  7110. PyDoc_STRVAR(os_WIFCONTINUED__doc__,
  7111. "WIFCONTINUED($module, /, status)\n"
  7112. "--\n"
  7113. "\n"
  7114. "Return True if a particular process was continued from a job control stop.\n"
  7115. "\n"
  7116. "Return True if the process returning status was continued from a\n"
  7117. "job control stop.");
  7118. #define OS_WIFCONTINUED_METHODDEF \
  7119. {"WIFCONTINUED", _PyCFunction_CAST(os_WIFCONTINUED), METH_FASTCALL|METH_KEYWORDS, os_WIFCONTINUED__doc__},
  7120. static int
  7121. os_WIFCONTINUED_impl(PyObject *module, int status);
  7122. static PyObject *
  7123. os_WIFCONTINUED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7124. {
  7125. PyObject *return_value = NULL;
  7126. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7127. #define NUM_KEYWORDS 1
  7128. static struct {
  7129. PyGC_Head _this_is_not_used;
  7130. PyObject_VAR_HEAD
  7131. PyObject *ob_item[NUM_KEYWORDS];
  7132. } _kwtuple = {
  7133. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7134. .ob_item = { &_Py_ID(status), },
  7135. };
  7136. #undef NUM_KEYWORDS
  7137. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7138. #else // !Py_BUILD_CORE
  7139. # define KWTUPLE NULL
  7140. #endif // !Py_BUILD_CORE
  7141. static const char * const _keywords[] = {"status", NULL};
  7142. static _PyArg_Parser _parser = {
  7143. .keywords = _keywords,
  7144. .fname = "WIFCONTINUED",
  7145. .kwtuple = KWTUPLE,
  7146. };
  7147. #undef KWTUPLE
  7148. PyObject *argsbuf[1];
  7149. int status;
  7150. int _return_value;
  7151. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7152. if (!args) {
  7153. goto exit;
  7154. }
  7155. status = _PyLong_AsInt(args[0]);
  7156. if (status == -1 && PyErr_Occurred()) {
  7157. goto exit;
  7158. }
  7159. _return_value = os_WIFCONTINUED_impl(module, status);
  7160. if ((_return_value == -1) && PyErr_Occurred()) {
  7161. goto exit;
  7162. }
  7163. return_value = PyBool_FromLong((long)_return_value);
  7164. exit:
  7165. return return_value;
  7166. }
  7167. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFCONTINUED) */
  7168. #if defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED)
  7169. PyDoc_STRVAR(os_WIFSTOPPED__doc__,
  7170. "WIFSTOPPED($module, /, status)\n"
  7171. "--\n"
  7172. "\n"
  7173. "Return True if the process returning status was stopped.");
  7174. #define OS_WIFSTOPPED_METHODDEF \
  7175. {"WIFSTOPPED", _PyCFunction_CAST(os_WIFSTOPPED), METH_FASTCALL|METH_KEYWORDS, os_WIFSTOPPED__doc__},
  7176. static int
  7177. os_WIFSTOPPED_impl(PyObject *module, int status);
  7178. static PyObject *
  7179. os_WIFSTOPPED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7180. {
  7181. PyObject *return_value = NULL;
  7182. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7183. #define NUM_KEYWORDS 1
  7184. static struct {
  7185. PyGC_Head _this_is_not_used;
  7186. PyObject_VAR_HEAD
  7187. PyObject *ob_item[NUM_KEYWORDS];
  7188. } _kwtuple = {
  7189. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7190. .ob_item = { &_Py_ID(status), },
  7191. };
  7192. #undef NUM_KEYWORDS
  7193. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7194. #else // !Py_BUILD_CORE
  7195. # define KWTUPLE NULL
  7196. #endif // !Py_BUILD_CORE
  7197. static const char * const _keywords[] = {"status", NULL};
  7198. static _PyArg_Parser _parser = {
  7199. .keywords = _keywords,
  7200. .fname = "WIFSTOPPED",
  7201. .kwtuple = KWTUPLE,
  7202. };
  7203. #undef KWTUPLE
  7204. PyObject *argsbuf[1];
  7205. int status;
  7206. int _return_value;
  7207. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7208. if (!args) {
  7209. goto exit;
  7210. }
  7211. status = _PyLong_AsInt(args[0]);
  7212. if (status == -1 && PyErr_Occurred()) {
  7213. goto exit;
  7214. }
  7215. _return_value = os_WIFSTOPPED_impl(module, status);
  7216. if ((_return_value == -1) && PyErr_Occurred()) {
  7217. goto exit;
  7218. }
  7219. return_value = PyBool_FromLong((long)_return_value);
  7220. exit:
  7221. return return_value;
  7222. }
  7223. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSTOPPED) */
  7224. #if defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED)
  7225. PyDoc_STRVAR(os_WIFSIGNALED__doc__,
  7226. "WIFSIGNALED($module, /, status)\n"
  7227. "--\n"
  7228. "\n"
  7229. "Return True if the process returning status was terminated by a signal.");
  7230. #define OS_WIFSIGNALED_METHODDEF \
  7231. {"WIFSIGNALED", _PyCFunction_CAST(os_WIFSIGNALED), METH_FASTCALL|METH_KEYWORDS, os_WIFSIGNALED__doc__},
  7232. static int
  7233. os_WIFSIGNALED_impl(PyObject *module, int status);
  7234. static PyObject *
  7235. os_WIFSIGNALED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7236. {
  7237. PyObject *return_value = NULL;
  7238. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7239. #define NUM_KEYWORDS 1
  7240. static struct {
  7241. PyGC_Head _this_is_not_used;
  7242. PyObject_VAR_HEAD
  7243. PyObject *ob_item[NUM_KEYWORDS];
  7244. } _kwtuple = {
  7245. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7246. .ob_item = { &_Py_ID(status), },
  7247. };
  7248. #undef NUM_KEYWORDS
  7249. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7250. #else // !Py_BUILD_CORE
  7251. # define KWTUPLE NULL
  7252. #endif // !Py_BUILD_CORE
  7253. static const char * const _keywords[] = {"status", NULL};
  7254. static _PyArg_Parser _parser = {
  7255. .keywords = _keywords,
  7256. .fname = "WIFSIGNALED",
  7257. .kwtuple = KWTUPLE,
  7258. };
  7259. #undef KWTUPLE
  7260. PyObject *argsbuf[1];
  7261. int status;
  7262. int _return_value;
  7263. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7264. if (!args) {
  7265. goto exit;
  7266. }
  7267. status = _PyLong_AsInt(args[0]);
  7268. if (status == -1 && PyErr_Occurred()) {
  7269. goto exit;
  7270. }
  7271. _return_value = os_WIFSIGNALED_impl(module, status);
  7272. if ((_return_value == -1) && PyErr_Occurred()) {
  7273. goto exit;
  7274. }
  7275. return_value = PyBool_FromLong((long)_return_value);
  7276. exit:
  7277. return return_value;
  7278. }
  7279. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFSIGNALED) */
  7280. #if defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED)
  7281. PyDoc_STRVAR(os_WIFEXITED__doc__,
  7282. "WIFEXITED($module, /, status)\n"
  7283. "--\n"
  7284. "\n"
  7285. "Return True if the process returning status exited via the exit() system call.");
  7286. #define OS_WIFEXITED_METHODDEF \
  7287. {"WIFEXITED", _PyCFunction_CAST(os_WIFEXITED), METH_FASTCALL|METH_KEYWORDS, os_WIFEXITED__doc__},
  7288. static int
  7289. os_WIFEXITED_impl(PyObject *module, int status);
  7290. static PyObject *
  7291. os_WIFEXITED(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7292. {
  7293. PyObject *return_value = NULL;
  7294. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7295. #define NUM_KEYWORDS 1
  7296. static struct {
  7297. PyGC_Head _this_is_not_used;
  7298. PyObject_VAR_HEAD
  7299. PyObject *ob_item[NUM_KEYWORDS];
  7300. } _kwtuple = {
  7301. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7302. .ob_item = { &_Py_ID(status), },
  7303. };
  7304. #undef NUM_KEYWORDS
  7305. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7306. #else // !Py_BUILD_CORE
  7307. # define KWTUPLE NULL
  7308. #endif // !Py_BUILD_CORE
  7309. static const char * const _keywords[] = {"status", NULL};
  7310. static _PyArg_Parser _parser = {
  7311. .keywords = _keywords,
  7312. .fname = "WIFEXITED",
  7313. .kwtuple = KWTUPLE,
  7314. };
  7315. #undef KWTUPLE
  7316. PyObject *argsbuf[1];
  7317. int status;
  7318. int _return_value;
  7319. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7320. if (!args) {
  7321. goto exit;
  7322. }
  7323. status = _PyLong_AsInt(args[0]);
  7324. if (status == -1 && PyErr_Occurred()) {
  7325. goto exit;
  7326. }
  7327. _return_value = os_WIFEXITED_impl(module, status);
  7328. if ((_return_value == -1) && PyErr_Occurred()) {
  7329. goto exit;
  7330. }
  7331. return_value = PyBool_FromLong((long)_return_value);
  7332. exit:
  7333. return return_value;
  7334. }
  7335. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WIFEXITED) */
  7336. #if defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS)
  7337. PyDoc_STRVAR(os_WEXITSTATUS__doc__,
  7338. "WEXITSTATUS($module, /, status)\n"
  7339. "--\n"
  7340. "\n"
  7341. "Return the process return code from status.");
  7342. #define OS_WEXITSTATUS_METHODDEF \
  7343. {"WEXITSTATUS", _PyCFunction_CAST(os_WEXITSTATUS), METH_FASTCALL|METH_KEYWORDS, os_WEXITSTATUS__doc__},
  7344. static int
  7345. os_WEXITSTATUS_impl(PyObject *module, int status);
  7346. static PyObject *
  7347. os_WEXITSTATUS(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7348. {
  7349. PyObject *return_value = NULL;
  7350. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7351. #define NUM_KEYWORDS 1
  7352. static struct {
  7353. PyGC_Head _this_is_not_used;
  7354. PyObject_VAR_HEAD
  7355. PyObject *ob_item[NUM_KEYWORDS];
  7356. } _kwtuple = {
  7357. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7358. .ob_item = { &_Py_ID(status), },
  7359. };
  7360. #undef NUM_KEYWORDS
  7361. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7362. #else // !Py_BUILD_CORE
  7363. # define KWTUPLE NULL
  7364. #endif // !Py_BUILD_CORE
  7365. static const char * const _keywords[] = {"status", NULL};
  7366. static _PyArg_Parser _parser = {
  7367. .keywords = _keywords,
  7368. .fname = "WEXITSTATUS",
  7369. .kwtuple = KWTUPLE,
  7370. };
  7371. #undef KWTUPLE
  7372. PyObject *argsbuf[1];
  7373. int status;
  7374. int _return_value;
  7375. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7376. if (!args) {
  7377. goto exit;
  7378. }
  7379. status = _PyLong_AsInt(args[0]);
  7380. if (status == -1 && PyErr_Occurred()) {
  7381. goto exit;
  7382. }
  7383. _return_value = os_WEXITSTATUS_impl(module, status);
  7384. if ((_return_value == -1) && PyErr_Occurred()) {
  7385. goto exit;
  7386. }
  7387. return_value = PyLong_FromLong((long)_return_value);
  7388. exit:
  7389. return return_value;
  7390. }
  7391. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WEXITSTATUS) */
  7392. #if defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG)
  7393. PyDoc_STRVAR(os_WTERMSIG__doc__,
  7394. "WTERMSIG($module, /, status)\n"
  7395. "--\n"
  7396. "\n"
  7397. "Return the signal that terminated the process that provided the status value.");
  7398. #define OS_WTERMSIG_METHODDEF \
  7399. {"WTERMSIG", _PyCFunction_CAST(os_WTERMSIG), METH_FASTCALL|METH_KEYWORDS, os_WTERMSIG__doc__},
  7400. static int
  7401. os_WTERMSIG_impl(PyObject *module, int status);
  7402. static PyObject *
  7403. os_WTERMSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7404. {
  7405. PyObject *return_value = NULL;
  7406. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7407. #define NUM_KEYWORDS 1
  7408. static struct {
  7409. PyGC_Head _this_is_not_used;
  7410. PyObject_VAR_HEAD
  7411. PyObject *ob_item[NUM_KEYWORDS];
  7412. } _kwtuple = {
  7413. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7414. .ob_item = { &_Py_ID(status), },
  7415. };
  7416. #undef NUM_KEYWORDS
  7417. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7418. #else // !Py_BUILD_CORE
  7419. # define KWTUPLE NULL
  7420. #endif // !Py_BUILD_CORE
  7421. static const char * const _keywords[] = {"status", NULL};
  7422. static _PyArg_Parser _parser = {
  7423. .keywords = _keywords,
  7424. .fname = "WTERMSIG",
  7425. .kwtuple = KWTUPLE,
  7426. };
  7427. #undef KWTUPLE
  7428. PyObject *argsbuf[1];
  7429. int status;
  7430. int _return_value;
  7431. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7432. if (!args) {
  7433. goto exit;
  7434. }
  7435. status = _PyLong_AsInt(args[0]);
  7436. if (status == -1 && PyErr_Occurred()) {
  7437. goto exit;
  7438. }
  7439. _return_value = os_WTERMSIG_impl(module, status);
  7440. if ((_return_value == -1) && PyErr_Occurred()) {
  7441. goto exit;
  7442. }
  7443. return_value = PyLong_FromLong((long)_return_value);
  7444. exit:
  7445. return return_value;
  7446. }
  7447. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WTERMSIG) */
  7448. #if defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG)
  7449. PyDoc_STRVAR(os_WSTOPSIG__doc__,
  7450. "WSTOPSIG($module, /, status)\n"
  7451. "--\n"
  7452. "\n"
  7453. "Return the signal that stopped the process that provided the status value.");
  7454. #define OS_WSTOPSIG_METHODDEF \
  7455. {"WSTOPSIG", _PyCFunction_CAST(os_WSTOPSIG), METH_FASTCALL|METH_KEYWORDS, os_WSTOPSIG__doc__},
  7456. static int
  7457. os_WSTOPSIG_impl(PyObject *module, int status);
  7458. static PyObject *
  7459. os_WSTOPSIG(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7460. {
  7461. PyObject *return_value = NULL;
  7462. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7463. #define NUM_KEYWORDS 1
  7464. static struct {
  7465. PyGC_Head _this_is_not_used;
  7466. PyObject_VAR_HEAD
  7467. PyObject *ob_item[NUM_KEYWORDS];
  7468. } _kwtuple = {
  7469. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7470. .ob_item = { &_Py_ID(status), },
  7471. };
  7472. #undef NUM_KEYWORDS
  7473. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7474. #else // !Py_BUILD_CORE
  7475. # define KWTUPLE NULL
  7476. #endif // !Py_BUILD_CORE
  7477. static const char * const _keywords[] = {"status", NULL};
  7478. static _PyArg_Parser _parser = {
  7479. .keywords = _keywords,
  7480. .fname = "WSTOPSIG",
  7481. .kwtuple = KWTUPLE,
  7482. };
  7483. #undef KWTUPLE
  7484. PyObject *argsbuf[1];
  7485. int status;
  7486. int _return_value;
  7487. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7488. if (!args) {
  7489. goto exit;
  7490. }
  7491. status = _PyLong_AsInt(args[0]);
  7492. if (status == -1 && PyErr_Occurred()) {
  7493. goto exit;
  7494. }
  7495. _return_value = os_WSTOPSIG_impl(module, status);
  7496. if ((_return_value == -1) && PyErr_Occurred()) {
  7497. goto exit;
  7498. }
  7499. return_value = PyLong_FromLong((long)_return_value);
  7500. exit:
  7501. return return_value;
  7502. }
  7503. #endif /* defined(HAVE_SYS_WAIT_H) && defined(WSTOPSIG) */
  7504. #if (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H))
  7505. PyDoc_STRVAR(os_fstatvfs__doc__,
  7506. "fstatvfs($module, fd, /)\n"
  7507. "--\n"
  7508. "\n"
  7509. "Perform an fstatvfs system call on the given fd.\n"
  7510. "\n"
  7511. "Equivalent to statvfs(fd).");
  7512. #define OS_FSTATVFS_METHODDEF \
  7513. {"fstatvfs", (PyCFunction)os_fstatvfs, METH_O, os_fstatvfs__doc__},
  7514. static PyObject *
  7515. os_fstatvfs_impl(PyObject *module, int fd);
  7516. static PyObject *
  7517. os_fstatvfs(PyObject *module, PyObject *arg)
  7518. {
  7519. PyObject *return_value = NULL;
  7520. int fd;
  7521. fd = _PyLong_AsInt(arg);
  7522. if (fd == -1 && PyErr_Occurred()) {
  7523. goto exit;
  7524. }
  7525. return_value = os_fstatvfs_impl(module, fd);
  7526. exit:
  7527. return return_value;
  7528. }
  7529. #endif /* (defined(HAVE_FSTATVFS) && defined(HAVE_SYS_STATVFS_H)) */
  7530. #if (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H))
  7531. PyDoc_STRVAR(os_statvfs__doc__,
  7532. "statvfs($module, /, path)\n"
  7533. "--\n"
  7534. "\n"
  7535. "Perform a statvfs system call on the given path.\n"
  7536. "\n"
  7537. "path may always be specified as a string.\n"
  7538. "On some platforms, path may also be specified as an open file descriptor.\n"
  7539. " If this functionality is unavailable, using it raises an exception.");
  7540. #define OS_STATVFS_METHODDEF \
  7541. {"statvfs", _PyCFunction_CAST(os_statvfs), METH_FASTCALL|METH_KEYWORDS, os_statvfs__doc__},
  7542. static PyObject *
  7543. os_statvfs_impl(PyObject *module, path_t *path);
  7544. static PyObject *
  7545. os_statvfs(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7546. {
  7547. PyObject *return_value = NULL;
  7548. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7549. #define NUM_KEYWORDS 1
  7550. static struct {
  7551. PyGC_Head _this_is_not_used;
  7552. PyObject_VAR_HEAD
  7553. PyObject *ob_item[NUM_KEYWORDS];
  7554. } _kwtuple = {
  7555. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7556. .ob_item = { &_Py_ID(path), },
  7557. };
  7558. #undef NUM_KEYWORDS
  7559. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7560. #else // !Py_BUILD_CORE
  7561. # define KWTUPLE NULL
  7562. #endif // !Py_BUILD_CORE
  7563. static const char * const _keywords[] = {"path", NULL};
  7564. static _PyArg_Parser _parser = {
  7565. .keywords = _keywords,
  7566. .fname = "statvfs",
  7567. .kwtuple = KWTUPLE,
  7568. };
  7569. #undef KWTUPLE
  7570. PyObject *argsbuf[1];
  7571. path_t path = PATH_T_INITIALIZE_P("statvfs", "path", 0, 0, 0, PATH_HAVE_FSTATVFS);
  7572. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7573. if (!args) {
  7574. goto exit;
  7575. }
  7576. if (!path_converter(args[0], &path)) {
  7577. goto exit;
  7578. }
  7579. return_value = os_statvfs_impl(module, &path);
  7580. exit:
  7581. /* Cleanup for path */
  7582. path_cleanup(&path);
  7583. return return_value;
  7584. }
  7585. #endif /* (defined(HAVE_STATVFS) && defined(HAVE_SYS_STATVFS_H)) */
  7586. #if defined(MS_WINDOWS)
  7587. PyDoc_STRVAR(os__getdiskusage__doc__,
  7588. "_getdiskusage($module, /, path)\n"
  7589. "--\n"
  7590. "\n"
  7591. "Return disk usage statistics about the given path as a (total, free) tuple.");
  7592. #define OS__GETDISKUSAGE_METHODDEF \
  7593. {"_getdiskusage", _PyCFunction_CAST(os__getdiskusage), METH_FASTCALL|METH_KEYWORDS, os__getdiskusage__doc__},
  7594. static PyObject *
  7595. os__getdiskusage_impl(PyObject *module, path_t *path);
  7596. static PyObject *
  7597. os__getdiskusage(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7598. {
  7599. PyObject *return_value = NULL;
  7600. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7601. #define NUM_KEYWORDS 1
  7602. static struct {
  7603. PyGC_Head _this_is_not_used;
  7604. PyObject_VAR_HEAD
  7605. PyObject *ob_item[NUM_KEYWORDS];
  7606. } _kwtuple = {
  7607. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7608. .ob_item = { &_Py_ID(path), },
  7609. };
  7610. #undef NUM_KEYWORDS
  7611. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7612. #else // !Py_BUILD_CORE
  7613. # define KWTUPLE NULL
  7614. #endif // !Py_BUILD_CORE
  7615. static const char * const _keywords[] = {"path", NULL};
  7616. static _PyArg_Parser _parser = {
  7617. .keywords = _keywords,
  7618. .fname = "_getdiskusage",
  7619. .kwtuple = KWTUPLE,
  7620. };
  7621. #undef KWTUPLE
  7622. PyObject *argsbuf[1];
  7623. path_t path = PATH_T_INITIALIZE_P("_getdiskusage", "path", 0, 0, 0, 0);
  7624. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  7625. if (!args) {
  7626. goto exit;
  7627. }
  7628. if (!path_converter(args[0], &path)) {
  7629. goto exit;
  7630. }
  7631. return_value = os__getdiskusage_impl(module, &path);
  7632. exit:
  7633. /* Cleanup for path */
  7634. path_cleanup(&path);
  7635. return return_value;
  7636. }
  7637. #endif /* defined(MS_WINDOWS) */
  7638. #if defined(HAVE_FPATHCONF)
  7639. PyDoc_STRVAR(os_fpathconf__doc__,
  7640. "fpathconf($module, fd, name, /)\n"
  7641. "--\n"
  7642. "\n"
  7643. "Return the configuration limit name for the file descriptor fd.\n"
  7644. "\n"
  7645. "If there is no limit, return -1.");
  7646. #define OS_FPATHCONF_METHODDEF \
  7647. {"fpathconf", _PyCFunction_CAST(os_fpathconf), METH_FASTCALL, os_fpathconf__doc__},
  7648. static long
  7649. os_fpathconf_impl(PyObject *module, int fd, int name);
  7650. static PyObject *
  7651. os_fpathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  7652. {
  7653. PyObject *return_value = NULL;
  7654. int fd;
  7655. int name;
  7656. long _return_value;
  7657. if (!_PyArg_CheckPositional("fpathconf", nargs, 2, 2)) {
  7658. goto exit;
  7659. }
  7660. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  7661. goto exit;
  7662. }
  7663. if (!conv_path_confname(args[1], &name)) {
  7664. goto exit;
  7665. }
  7666. _return_value = os_fpathconf_impl(module, fd, name);
  7667. if ((_return_value == -1) && PyErr_Occurred()) {
  7668. goto exit;
  7669. }
  7670. return_value = PyLong_FromLong(_return_value);
  7671. exit:
  7672. return return_value;
  7673. }
  7674. #endif /* defined(HAVE_FPATHCONF) */
  7675. #if defined(HAVE_PATHCONF)
  7676. PyDoc_STRVAR(os_pathconf__doc__,
  7677. "pathconf($module, /, path, name)\n"
  7678. "--\n"
  7679. "\n"
  7680. "Return the configuration limit name for the file or directory path.\n"
  7681. "\n"
  7682. "If there is no limit, return -1.\n"
  7683. "On some platforms, path may also be specified as an open file descriptor.\n"
  7684. " If this functionality is unavailable, using it raises an exception.");
  7685. #define OS_PATHCONF_METHODDEF \
  7686. {"pathconf", _PyCFunction_CAST(os_pathconf), METH_FASTCALL|METH_KEYWORDS, os_pathconf__doc__},
  7687. static long
  7688. os_pathconf_impl(PyObject *module, path_t *path, int name);
  7689. static PyObject *
  7690. os_pathconf(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7691. {
  7692. PyObject *return_value = NULL;
  7693. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7694. #define NUM_KEYWORDS 2
  7695. static struct {
  7696. PyGC_Head _this_is_not_used;
  7697. PyObject_VAR_HEAD
  7698. PyObject *ob_item[NUM_KEYWORDS];
  7699. } _kwtuple = {
  7700. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7701. .ob_item = { &_Py_ID(path), &_Py_ID(name), },
  7702. };
  7703. #undef NUM_KEYWORDS
  7704. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7705. #else // !Py_BUILD_CORE
  7706. # define KWTUPLE NULL
  7707. #endif // !Py_BUILD_CORE
  7708. static const char * const _keywords[] = {"path", "name", NULL};
  7709. static _PyArg_Parser _parser = {
  7710. .keywords = _keywords,
  7711. .fname = "pathconf",
  7712. .kwtuple = KWTUPLE,
  7713. };
  7714. #undef KWTUPLE
  7715. PyObject *argsbuf[2];
  7716. path_t path = PATH_T_INITIALIZE_P("pathconf", "path", 0, 0, 0, PATH_HAVE_FPATHCONF);
  7717. int name;
  7718. long _return_value;
  7719. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  7720. if (!args) {
  7721. goto exit;
  7722. }
  7723. if (!path_converter(args[0], &path)) {
  7724. goto exit;
  7725. }
  7726. if (!conv_path_confname(args[1], &name)) {
  7727. goto exit;
  7728. }
  7729. _return_value = os_pathconf_impl(module, &path, name);
  7730. if ((_return_value == -1) && PyErr_Occurred()) {
  7731. goto exit;
  7732. }
  7733. return_value = PyLong_FromLong(_return_value);
  7734. exit:
  7735. /* Cleanup for path */
  7736. path_cleanup(&path);
  7737. return return_value;
  7738. }
  7739. #endif /* defined(HAVE_PATHCONF) */
  7740. #if defined(HAVE_CONFSTR)
  7741. PyDoc_STRVAR(os_confstr__doc__,
  7742. "confstr($module, name, /)\n"
  7743. "--\n"
  7744. "\n"
  7745. "Return a string-valued system configuration variable.");
  7746. #define OS_CONFSTR_METHODDEF \
  7747. {"confstr", (PyCFunction)os_confstr, METH_O, os_confstr__doc__},
  7748. static PyObject *
  7749. os_confstr_impl(PyObject *module, int name);
  7750. static PyObject *
  7751. os_confstr(PyObject *module, PyObject *arg)
  7752. {
  7753. PyObject *return_value = NULL;
  7754. int name;
  7755. if (!conv_confstr_confname(arg, &name)) {
  7756. goto exit;
  7757. }
  7758. return_value = os_confstr_impl(module, name);
  7759. exit:
  7760. return return_value;
  7761. }
  7762. #endif /* defined(HAVE_CONFSTR) */
  7763. #if defined(HAVE_SYSCONF)
  7764. PyDoc_STRVAR(os_sysconf__doc__,
  7765. "sysconf($module, name, /)\n"
  7766. "--\n"
  7767. "\n"
  7768. "Return an integer-valued system configuration variable.");
  7769. #define OS_SYSCONF_METHODDEF \
  7770. {"sysconf", (PyCFunction)os_sysconf, METH_O, os_sysconf__doc__},
  7771. static long
  7772. os_sysconf_impl(PyObject *module, int name);
  7773. static PyObject *
  7774. os_sysconf(PyObject *module, PyObject *arg)
  7775. {
  7776. PyObject *return_value = NULL;
  7777. int name;
  7778. long _return_value;
  7779. if (!conv_sysconf_confname(arg, &name)) {
  7780. goto exit;
  7781. }
  7782. _return_value = os_sysconf_impl(module, name);
  7783. if ((_return_value == -1) && PyErr_Occurred()) {
  7784. goto exit;
  7785. }
  7786. return_value = PyLong_FromLong(_return_value);
  7787. exit:
  7788. return return_value;
  7789. }
  7790. #endif /* defined(HAVE_SYSCONF) */
  7791. PyDoc_STRVAR(os_abort__doc__,
  7792. "abort($module, /)\n"
  7793. "--\n"
  7794. "\n"
  7795. "Abort the interpreter immediately.\n"
  7796. "\n"
  7797. "This function \'dumps core\' or otherwise fails in the hardest way possible\n"
  7798. "on the hosting operating system. This function never returns.");
  7799. #define OS_ABORT_METHODDEF \
  7800. {"abort", (PyCFunction)os_abort, METH_NOARGS, os_abort__doc__},
  7801. static PyObject *
  7802. os_abort_impl(PyObject *module);
  7803. static PyObject *
  7804. os_abort(PyObject *module, PyObject *Py_UNUSED(ignored))
  7805. {
  7806. return os_abort_impl(module);
  7807. }
  7808. #if defined(MS_WINDOWS)
  7809. PyDoc_STRVAR(os_startfile__doc__,
  7810. "startfile($module, /, filepath, operation=<unrepresentable>,\n"
  7811. " arguments=<unrepresentable>, cwd=None, show_cmd=1)\n"
  7812. "--\n"
  7813. "\n"
  7814. "Start a file with its associated application.\n"
  7815. "\n"
  7816. "When \"operation\" is not specified or \"open\", this acts like\n"
  7817. "double-clicking the file in Explorer, or giving the file name as an\n"
  7818. "argument to the DOS \"start\" command: the file is opened with whatever\n"
  7819. "application (if any) its extension is associated.\n"
  7820. "When another \"operation\" is given, it specifies what should be done with\n"
  7821. "the file. A typical operation is \"print\".\n"
  7822. "\n"
  7823. "\"arguments\" is passed to the application, but should be omitted if the\n"
  7824. "file is a document.\n"
  7825. "\n"
  7826. "\"cwd\" is the working directory for the operation. If \"filepath\" is\n"
  7827. "relative, it will be resolved against this directory. This argument\n"
  7828. "should usually be an absolute path.\n"
  7829. "\n"
  7830. "\"show_cmd\" can be used to override the recommended visibility option.\n"
  7831. "See the Windows ShellExecute documentation for values.\n"
  7832. "\n"
  7833. "startfile returns as soon as the associated application is launched.\n"
  7834. "There is no option to wait for the application to close, and no way\n"
  7835. "to retrieve the application\'s exit status.\n"
  7836. "\n"
  7837. "The filepath is relative to the current directory. If you want to use\n"
  7838. "an absolute path, make sure the first character is not a slash (\"/\");\n"
  7839. "the underlying Win32 ShellExecute function doesn\'t work if it is.");
  7840. #define OS_STARTFILE_METHODDEF \
  7841. {"startfile", _PyCFunction_CAST(os_startfile), METH_FASTCALL|METH_KEYWORDS, os_startfile__doc__},
  7842. static PyObject *
  7843. os_startfile_impl(PyObject *module, path_t *filepath,
  7844. const Py_UNICODE *operation, const Py_UNICODE *arguments,
  7845. path_t *cwd, int show_cmd);
  7846. static PyObject *
  7847. os_startfile(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7848. {
  7849. PyObject *return_value = NULL;
  7850. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7851. #define NUM_KEYWORDS 5
  7852. static struct {
  7853. PyGC_Head _this_is_not_used;
  7854. PyObject_VAR_HEAD
  7855. PyObject *ob_item[NUM_KEYWORDS];
  7856. } _kwtuple = {
  7857. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7858. .ob_item = { &_Py_ID(filepath), &_Py_ID(operation), &_Py_ID(arguments), &_Py_ID(cwd), &_Py_ID(show_cmd), },
  7859. };
  7860. #undef NUM_KEYWORDS
  7861. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7862. #else // !Py_BUILD_CORE
  7863. # define KWTUPLE NULL
  7864. #endif // !Py_BUILD_CORE
  7865. static const char * const _keywords[] = {"filepath", "operation", "arguments", "cwd", "show_cmd", NULL};
  7866. static _PyArg_Parser _parser = {
  7867. .keywords = _keywords,
  7868. .fname = "startfile",
  7869. .kwtuple = KWTUPLE,
  7870. };
  7871. #undef KWTUPLE
  7872. PyObject *argsbuf[5];
  7873. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  7874. path_t filepath = PATH_T_INITIALIZE_P("startfile", "filepath", 0, 0, 0, 0);
  7875. const Py_UNICODE *operation = NULL;
  7876. const Py_UNICODE *arguments = NULL;
  7877. path_t cwd = PATH_T_INITIALIZE_P("startfile", "cwd", 1, 0, 0, 0);
  7878. int show_cmd = 1;
  7879. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 5, 0, argsbuf);
  7880. if (!args) {
  7881. goto exit;
  7882. }
  7883. if (!path_converter(args[0], &filepath)) {
  7884. goto exit;
  7885. }
  7886. if (!noptargs) {
  7887. goto skip_optional_pos;
  7888. }
  7889. if (args[1]) {
  7890. if (!PyUnicode_Check(args[1])) {
  7891. _PyArg_BadArgument("startfile", "argument 'operation'", "str", args[1]);
  7892. goto exit;
  7893. }
  7894. operation = PyUnicode_AsWideCharString(args[1], NULL);
  7895. if (operation == NULL) {
  7896. goto exit;
  7897. }
  7898. if (!--noptargs) {
  7899. goto skip_optional_pos;
  7900. }
  7901. }
  7902. if (args[2]) {
  7903. if (!PyUnicode_Check(args[2])) {
  7904. _PyArg_BadArgument("startfile", "argument 'arguments'", "str", args[2]);
  7905. goto exit;
  7906. }
  7907. arguments = PyUnicode_AsWideCharString(args[2], NULL);
  7908. if (arguments == NULL) {
  7909. goto exit;
  7910. }
  7911. if (!--noptargs) {
  7912. goto skip_optional_pos;
  7913. }
  7914. }
  7915. if (args[3]) {
  7916. if (!path_converter(args[3], &cwd)) {
  7917. goto exit;
  7918. }
  7919. if (!--noptargs) {
  7920. goto skip_optional_pos;
  7921. }
  7922. }
  7923. show_cmd = _PyLong_AsInt(args[4]);
  7924. if (show_cmd == -1 && PyErr_Occurred()) {
  7925. goto exit;
  7926. }
  7927. skip_optional_pos:
  7928. return_value = os_startfile_impl(module, &filepath, operation, arguments, &cwd, show_cmd);
  7929. exit:
  7930. /* Cleanup for filepath */
  7931. path_cleanup(&filepath);
  7932. /* Cleanup for operation */
  7933. PyMem_Free((void *)operation);
  7934. /* Cleanup for arguments */
  7935. PyMem_Free((void *)arguments);
  7936. /* Cleanup for cwd */
  7937. path_cleanup(&cwd);
  7938. return return_value;
  7939. }
  7940. #endif /* defined(MS_WINDOWS) */
  7941. #if defined(HAVE_GETLOADAVG)
  7942. PyDoc_STRVAR(os_getloadavg__doc__,
  7943. "getloadavg($module, /)\n"
  7944. "--\n"
  7945. "\n"
  7946. "Return average recent system load information.\n"
  7947. "\n"
  7948. "Return the number of processes in the system run queue averaged over\n"
  7949. "the last 1, 5, and 15 minutes as a tuple of three floats.\n"
  7950. "Raises OSError if the load average was unobtainable.");
  7951. #define OS_GETLOADAVG_METHODDEF \
  7952. {"getloadavg", (PyCFunction)os_getloadavg, METH_NOARGS, os_getloadavg__doc__},
  7953. static PyObject *
  7954. os_getloadavg_impl(PyObject *module);
  7955. static PyObject *
  7956. os_getloadavg(PyObject *module, PyObject *Py_UNUSED(ignored))
  7957. {
  7958. return os_getloadavg_impl(module);
  7959. }
  7960. #endif /* defined(HAVE_GETLOADAVG) */
  7961. PyDoc_STRVAR(os_device_encoding__doc__,
  7962. "device_encoding($module, /, fd)\n"
  7963. "--\n"
  7964. "\n"
  7965. "Return a string describing the encoding of a terminal\'s file descriptor.\n"
  7966. "\n"
  7967. "The file descriptor must be attached to a terminal.\n"
  7968. "If the device is not a terminal, return None.");
  7969. #define OS_DEVICE_ENCODING_METHODDEF \
  7970. {"device_encoding", _PyCFunction_CAST(os_device_encoding), METH_FASTCALL|METH_KEYWORDS, os_device_encoding__doc__},
  7971. static PyObject *
  7972. os_device_encoding_impl(PyObject *module, int fd);
  7973. static PyObject *
  7974. os_device_encoding(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  7975. {
  7976. PyObject *return_value = NULL;
  7977. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  7978. #define NUM_KEYWORDS 1
  7979. static struct {
  7980. PyGC_Head _this_is_not_used;
  7981. PyObject_VAR_HEAD
  7982. PyObject *ob_item[NUM_KEYWORDS];
  7983. } _kwtuple = {
  7984. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  7985. .ob_item = { &_Py_ID(fd), },
  7986. };
  7987. #undef NUM_KEYWORDS
  7988. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  7989. #else // !Py_BUILD_CORE
  7990. # define KWTUPLE NULL
  7991. #endif // !Py_BUILD_CORE
  7992. static const char * const _keywords[] = {"fd", NULL};
  7993. static _PyArg_Parser _parser = {
  7994. .keywords = _keywords,
  7995. .fname = "device_encoding",
  7996. .kwtuple = KWTUPLE,
  7997. };
  7998. #undef KWTUPLE
  7999. PyObject *argsbuf[1];
  8000. int fd;
  8001. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  8002. if (!args) {
  8003. goto exit;
  8004. }
  8005. fd = _PyLong_AsInt(args[0]);
  8006. if (fd == -1 && PyErr_Occurred()) {
  8007. goto exit;
  8008. }
  8009. return_value = os_device_encoding_impl(module, fd);
  8010. exit:
  8011. return return_value;
  8012. }
  8013. #if defined(HAVE_SETRESUID)
  8014. PyDoc_STRVAR(os_setresuid__doc__,
  8015. "setresuid($module, ruid, euid, suid, /)\n"
  8016. "--\n"
  8017. "\n"
  8018. "Set the current process\'s real, effective, and saved user ids.");
  8019. #define OS_SETRESUID_METHODDEF \
  8020. {"setresuid", _PyCFunction_CAST(os_setresuid), METH_FASTCALL, os_setresuid__doc__},
  8021. static PyObject *
  8022. os_setresuid_impl(PyObject *module, uid_t ruid, uid_t euid, uid_t suid);
  8023. static PyObject *
  8024. os_setresuid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8025. {
  8026. PyObject *return_value = NULL;
  8027. uid_t ruid;
  8028. uid_t euid;
  8029. uid_t suid;
  8030. if (!_PyArg_CheckPositional("setresuid", nargs, 3, 3)) {
  8031. goto exit;
  8032. }
  8033. if (!_Py_Uid_Converter(args[0], &ruid)) {
  8034. goto exit;
  8035. }
  8036. if (!_Py_Uid_Converter(args[1], &euid)) {
  8037. goto exit;
  8038. }
  8039. if (!_Py_Uid_Converter(args[2], &suid)) {
  8040. goto exit;
  8041. }
  8042. return_value = os_setresuid_impl(module, ruid, euid, suid);
  8043. exit:
  8044. return return_value;
  8045. }
  8046. #endif /* defined(HAVE_SETRESUID) */
  8047. #if defined(HAVE_SETRESGID)
  8048. PyDoc_STRVAR(os_setresgid__doc__,
  8049. "setresgid($module, rgid, egid, sgid, /)\n"
  8050. "--\n"
  8051. "\n"
  8052. "Set the current process\'s real, effective, and saved group ids.");
  8053. #define OS_SETRESGID_METHODDEF \
  8054. {"setresgid", _PyCFunction_CAST(os_setresgid), METH_FASTCALL, os_setresgid__doc__},
  8055. static PyObject *
  8056. os_setresgid_impl(PyObject *module, gid_t rgid, gid_t egid, gid_t sgid);
  8057. static PyObject *
  8058. os_setresgid(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8059. {
  8060. PyObject *return_value = NULL;
  8061. gid_t rgid;
  8062. gid_t egid;
  8063. gid_t sgid;
  8064. if (!_PyArg_CheckPositional("setresgid", nargs, 3, 3)) {
  8065. goto exit;
  8066. }
  8067. if (!_Py_Gid_Converter(args[0], &rgid)) {
  8068. goto exit;
  8069. }
  8070. if (!_Py_Gid_Converter(args[1], &egid)) {
  8071. goto exit;
  8072. }
  8073. if (!_Py_Gid_Converter(args[2], &sgid)) {
  8074. goto exit;
  8075. }
  8076. return_value = os_setresgid_impl(module, rgid, egid, sgid);
  8077. exit:
  8078. return return_value;
  8079. }
  8080. #endif /* defined(HAVE_SETRESGID) */
  8081. #if defined(HAVE_GETRESUID)
  8082. PyDoc_STRVAR(os_getresuid__doc__,
  8083. "getresuid($module, /)\n"
  8084. "--\n"
  8085. "\n"
  8086. "Return a tuple of the current process\'s real, effective, and saved user ids.");
  8087. #define OS_GETRESUID_METHODDEF \
  8088. {"getresuid", (PyCFunction)os_getresuid, METH_NOARGS, os_getresuid__doc__},
  8089. static PyObject *
  8090. os_getresuid_impl(PyObject *module);
  8091. static PyObject *
  8092. os_getresuid(PyObject *module, PyObject *Py_UNUSED(ignored))
  8093. {
  8094. return os_getresuid_impl(module);
  8095. }
  8096. #endif /* defined(HAVE_GETRESUID) */
  8097. #if defined(HAVE_GETRESGID)
  8098. PyDoc_STRVAR(os_getresgid__doc__,
  8099. "getresgid($module, /)\n"
  8100. "--\n"
  8101. "\n"
  8102. "Return a tuple of the current process\'s real, effective, and saved group ids.");
  8103. #define OS_GETRESGID_METHODDEF \
  8104. {"getresgid", (PyCFunction)os_getresgid, METH_NOARGS, os_getresgid__doc__},
  8105. static PyObject *
  8106. os_getresgid_impl(PyObject *module);
  8107. static PyObject *
  8108. os_getresgid(PyObject *module, PyObject *Py_UNUSED(ignored))
  8109. {
  8110. return os_getresgid_impl(module);
  8111. }
  8112. #endif /* defined(HAVE_GETRESGID) */
  8113. #if defined(USE_XATTRS)
  8114. PyDoc_STRVAR(os_getxattr__doc__,
  8115. "getxattr($module, /, path, attribute, *, follow_symlinks=True)\n"
  8116. "--\n"
  8117. "\n"
  8118. "Return the value of extended attribute attribute on path.\n"
  8119. "\n"
  8120. "path may be either a string, a path-like object, or an open file descriptor.\n"
  8121. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  8122. " link, getxattr will examine the symbolic link itself instead of the file\n"
  8123. " the link points to.");
  8124. #define OS_GETXATTR_METHODDEF \
  8125. {"getxattr", _PyCFunction_CAST(os_getxattr), METH_FASTCALL|METH_KEYWORDS, os_getxattr__doc__},
  8126. static PyObject *
  8127. os_getxattr_impl(PyObject *module, path_t *path, path_t *attribute,
  8128. int follow_symlinks);
  8129. static PyObject *
  8130. os_getxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8131. {
  8132. PyObject *return_value = NULL;
  8133. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8134. #define NUM_KEYWORDS 3
  8135. static struct {
  8136. PyGC_Head _this_is_not_used;
  8137. PyObject_VAR_HEAD
  8138. PyObject *ob_item[NUM_KEYWORDS];
  8139. } _kwtuple = {
  8140. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8141. .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
  8142. };
  8143. #undef NUM_KEYWORDS
  8144. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8145. #else // !Py_BUILD_CORE
  8146. # define KWTUPLE NULL
  8147. #endif // !Py_BUILD_CORE
  8148. static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
  8149. static _PyArg_Parser _parser = {
  8150. .keywords = _keywords,
  8151. .fname = "getxattr",
  8152. .kwtuple = KWTUPLE,
  8153. };
  8154. #undef KWTUPLE
  8155. PyObject *argsbuf[3];
  8156. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  8157. path_t path = PATH_T_INITIALIZE_P("getxattr", "path", 0, 0, 0, 1);
  8158. path_t attribute = PATH_T_INITIALIZE_P("getxattr", "attribute", 0, 0, 0, 0);
  8159. int follow_symlinks = 1;
  8160. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  8161. if (!args) {
  8162. goto exit;
  8163. }
  8164. if (!path_converter(args[0], &path)) {
  8165. goto exit;
  8166. }
  8167. if (!path_converter(args[1], &attribute)) {
  8168. goto exit;
  8169. }
  8170. if (!noptargs) {
  8171. goto skip_optional_kwonly;
  8172. }
  8173. follow_symlinks = PyObject_IsTrue(args[2]);
  8174. if (follow_symlinks < 0) {
  8175. goto exit;
  8176. }
  8177. skip_optional_kwonly:
  8178. return_value = os_getxattr_impl(module, &path, &attribute, follow_symlinks);
  8179. exit:
  8180. /* Cleanup for path */
  8181. path_cleanup(&path);
  8182. /* Cleanup for attribute */
  8183. path_cleanup(&attribute);
  8184. return return_value;
  8185. }
  8186. #endif /* defined(USE_XATTRS) */
  8187. #if defined(USE_XATTRS)
  8188. PyDoc_STRVAR(os_setxattr__doc__,
  8189. "setxattr($module, /, path, attribute, value, flags=0, *,\n"
  8190. " follow_symlinks=True)\n"
  8191. "--\n"
  8192. "\n"
  8193. "Set extended attribute attribute on path to value.\n"
  8194. "\n"
  8195. "path may be either a string, a path-like object, or an open file descriptor.\n"
  8196. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  8197. " link, setxattr will modify the symbolic link itself instead of the file\n"
  8198. " the link points to.");
  8199. #define OS_SETXATTR_METHODDEF \
  8200. {"setxattr", _PyCFunction_CAST(os_setxattr), METH_FASTCALL|METH_KEYWORDS, os_setxattr__doc__},
  8201. static PyObject *
  8202. os_setxattr_impl(PyObject *module, path_t *path, path_t *attribute,
  8203. Py_buffer *value, int flags, int follow_symlinks);
  8204. static PyObject *
  8205. os_setxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8206. {
  8207. PyObject *return_value = NULL;
  8208. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8209. #define NUM_KEYWORDS 5
  8210. static struct {
  8211. PyGC_Head _this_is_not_used;
  8212. PyObject_VAR_HEAD
  8213. PyObject *ob_item[NUM_KEYWORDS];
  8214. } _kwtuple = {
  8215. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8216. .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(value), &_Py_ID(flags), &_Py_ID(follow_symlinks), },
  8217. };
  8218. #undef NUM_KEYWORDS
  8219. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8220. #else // !Py_BUILD_CORE
  8221. # define KWTUPLE NULL
  8222. #endif // !Py_BUILD_CORE
  8223. static const char * const _keywords[] = {"path", "attribute", "value", "flags", "follow_symlinks", NULL};
  8224. static _PyArg_Parser _parser = {
  8225. .keywords = _keywords,
  8226. .fname = "setxattr",
  8227. .kwtuple = KWTUPLE,
  8228. };
  8229. #undef KWTUPLE
  8230. PyObject *argsbuf[5];
  8231. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 3;
  8232. path_t path = PATH_T_INITIALIZE_P("setxattr", "path", 0, 0, 0, 1);
  8233. path_t attribute = PATH_T_INITIALIZE_P("setxattr", "attribute", 0, 0, 0, 0);
  8234. Py_buffer value = {NULL, NULL};
  8235. int flags = 0;
  8236. int follow_symlinks = 1;
  8237. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 3, 4, 0, argsbuf);
  8238. if (!args) {
  8239. goto exit;
  8240. }
  8241. if (!path_converter(args[0], &path)) {
  8242. goto exit;
  8243. }
  8244. if (!path_converter(args[1], &attribute)) {
  8245. goto exit;
  8246. }
  8247. if (PyObject_GetBuffer(args[2], &value, PyBUF_SIMPLE) != 0) {
  8248. goto exit;
  8249. }
  8250. if (!PyBuffer_IsContiguous(&value, 'C')) {
  8251. _PyArg_BadArgument("setxattr", "argument 'value'", "contiguous buffer", args[2]);
  8252. goto exit;
  8253. }
  8254. if (!noptargs) {
  8255. goto skip_optional_pos;
  8256. }
  8257. if (args[3]) {
  8258. flags = _PyLong_AsInt(args[3]);
  8259. if (flags == -1 && PyErr_Occurred()) {
  8260. goto exit;
  8261. }
  8262. if (!--noptargs) {
  8263. goto skip_optional_pos;
  8264. }
  8265. }
  8266. skip_optional_pos:
  8267. if (!noptargs) {
  8268. goto skip_optional_kwonly;
  8269. }
  8270. follow_symlinks = PyObject_IsTrue(args[4]);
  8271. if (follow_symlinks < 0) {
  8272. goto exit;
  8273. }
  8274. skip_optional_kwonly:
  8275. return_value = os_setxattr_impl(module, &path, &attribute, &value, flags, follow_symlinks);
  8276. exit:
  8277. /* Cleanup for path */
  8278. path_cleanup(&path);
  8279. /* Cleanup for attribute */
  8280. path_cleanup(&attribute);
  8281. /* Cleanup for value */
  8282. if (value.obj) {
  8283. PyBuffer_Release(&value);
  8284. }
  8285. return return_value;
  8286. }
  8287. #endif /* defined(USE_XATTRS) */
  8288. #if defined(USE_XATTRS)
  8289. PyDoc_STRVAR(os_removexattr__doc__,
  8290. "removexattr($module, /, path, attribute, *, follow_symlinks=True)\n"
  8291. "--\n"
  8292. "\n"
  8293. "Remove extended attribute attribute on path.\n"
  8294. "\n"
  8295. "path may be either a string, a path-like object, or an open file descriptor.\n"
  8296. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  8297. " link, removexattr will modify the symbolic link itself instead of the file\n"
  8298. " the link points to.");
  8299. #define OS_REMOVEXATTR_METHODDEF \
  8300. {"removexattr", _PyCFunction_CAST(os_removexattr), METH_FASTCALL|METH_KEYWORDS, os_removexattr__doc__},
  8301. static PyObject *
  8302. os_removexattr_impl(PyObject *module, path_t *path, path_t *attribute,
  8303. int follow_symlinks);
  8304. static PyObject *
  8305. os_removexattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8306. {
  8307. PyObject *return_value = NULL;
  8308. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8309. #define NUM_KEYWORDS 3
  8310. static struct {
  8311. PyGC_Head _this_is_not_used;
  8312. PyObject_VAR_HEAD
  8313. PyObject *ob_item[NUM_KEYWORDS];
  8314. } _kwtuple = {
  8315. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8316. .ob_item = { &_Py_ID(path), &_Py_ID(attribute), &_Py_ID(follow_symlinks), },
  8317. };
  8318. #undef NUM_KEYWORDS
  8319. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8320. #else // !Py_BUILD_CORE
  8321. # define KWTUPLE NULL
  8322. #endif // !Py_BUILD_CORE
  8323. static const char * const _keywords[] = {"path", "attribute", "follow_symlinks", NULL};
  8324. static _PyArg_Parser _parser = {
  8325. .keywords = _keywords,
  8326. .fname = "removexattr",
  8327. .kwtuple = KWTUPLE,
  8328. };
  8329. #undef KWTUPLE
  8330. PyObject *argsbuf[3];
  8331. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 2;
  8332. path_t path = PATH_T_INITIALIZE_P("removexattr", "path", 0, 0, 0, 1);
  8333. path_t attribute = PATH_T_INITIALIZE_P("removexattr", "attribute", 0, 0, 0, 0);
  8334. int follow_symlinks = 1;
  8335. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  8336. if (!args) {
  8337. goto exit;
  8338. }
  8339. if (!path_converter(args[0], &path)) {
  8340. goto exit;
  8341. }
  8342. if (!path_converter(args[1], &attribute)) {
  8343. goto exit;
  8344. }
  8345. if (!noptargs) {
  8346. goto skip_optional_kwonly;
  8347. }
  8348. follow_symlinks = PyObject_IsTrue(args[2]);
  8349. if (follow_symlinks < 0) {
  8350. goto exit;
  8351. }
  8352. skip_optional_kwonly:
  8353. return_value = os_removexattr_impl(module, &path, &attribute, follow_symlinks);
  8354. exit:
  8355. /* Cleanup for path */
  8356. path_cleanup(&path);
  8357. /* Cleanup for attribute */
  8358. path_cleanup(&attribute);
  8359. return return_value;
  8360. }
  8361. #endif /* defined(USE_XATTRS) */
  8362. #if defined(USE_XATTRS)
  8363. PyDoc_STRVAR(os_listxattr__doc__,
  8364. "listxattr($module, /, path=None, *, follow_symlinks=True)\n"
  8365. "--\n"
  8366. "\n"
  8367. "Return a list of extended attributes on path.\n"
  8368. "\n"
  8369. "path may be either None, a string, a path-like object, or an open file descriptor.\n"
  8370. "if path is None, listxattr will examine the current directory.\n"
  8371. "If follow_symlinks is False, and the last element of the path is a symbolic\n"
  8372. " link, listxattr will examine the symbolic link itself instead of the file\n"
  8373. " the link points to.");
  8374. #define OS_LISTXATTR_METHODDEF \
  8375. {"listxattr", _PyCFunction_CAST(os_listxattr), METH_FASTCALL|METH_KEYWORDS, os_listxattr__doc__},
  8376. static PyObject *
  8377. os_listxattr_impl(PyObject *module, path_t *path, int follow_symlinks);
  8378. static PyObject *
  8379. os_listxattr(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8380. {
  8381. PyObject *return_value = NULL;
  8382. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8383. #define NUM_KEYWORDS 2
  8384. static struct {
  8385. PyGC_Head _this_is_not_used;
  8386. PyObject_VAR_HEAD
  8387. PyObject *ob_item[NUM_KEYWORDS];
  8388. } _kwtuple = {
  8389. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8390. .ob_item = { &_Py_ID(path), &_Py_ID(follow_symlinks), },
  8391. };
  8392. #undef NUM_KEYWORDS
  8393. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8394. #else // !Py_BUILD_CORE
  8395. # define KWTUPLE NULL
  8396. #endif // !Py_BUILD_CORE
  8397. static const char * const _keywords[] = {"path", "follow_symlinks", NULL};
  8398. static _PyArg_Parser _parser = {
  8399. .keywords = _keywords,
  8400. .fname = "listxattr",
  8401. .kwtuple = KWTUPLE,
  8402. };
  8403. #undef KWTUPLE
  8404. PyObject *argsbuf[2];
  8405. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  8406. path_t path = PATH_T_INITIALIZE_P("listxattr", "path", 1, 0, 0, 1);
  8407. int follow_symlinks = 1;
  8408. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  8409. if (!args) {
  8410. goto exit;
  8411. }
  8412. if (!noptargs) {
  8413. goto skip_optional_pos;
  8414. }
  8415. if (args[0]) {
  8416. if (!path_converter(args[0], &path)) {
  8417. goto exit;
  8418. }
  8419. if (!--noptargs) {
  8420. goto skip_optional_pos;
  8421. }
  8422. }
  8423. skip_optional_pos:
  8424. if (!noptargs) {
  8425. goto skip_optional_kwonly;
  8426. }
  8427. follow_symlinks = PyObject_IsTrue(args[1]);
  8428. if (follow_symlinks < 0) {
  8429. goto exit;
  8430. }
  8431. skip_optional_kwonly:
  8432. return_value = os_listxattr_impl(module, &path, follow_symlinks);
  8433. exit:
  8434. /* Cleanup for path */
  8435. path_cleanup(&path);
  8436. return return_value;
  8437. }
  8438. #endif /* defined(USE_XATTRS) */
  8439. PyDoc_STRVAR(os_urandom__doc__,
  8440. "urandom($module, size, /)\n"
  8441. "--\n"
  8442. "\n"
  8443. "Return a bytes object containing random bytes suitable for cryptographic use.");
  8444. #define OS_URANDOM_METHODDEF \
  8445. {"urandom", (PyCFunction)os_urandom, METH_O, os_urandom__doc__},
  8446. static PyObject *
  8447. os_urandom_impl(PyObject *module, Py_ssize_t size);
  8448. static PyObject *
  8449. os_urandom(PyObject *module, PyObject *arg)
  8450. {
  8451. PyObject *return_value = NULL;
  8452. Py_ssize_t size;
  8453. {
  8454. Py_ssize_t ival = -1;
  8455. PyObject *iobj = _PyNumber_Index(arg);
  8456. if (iobj != NULL) {
  8457. ival = PyLong_AsSsize_t(iobj);
  8458. Py_DECREF(iobj);
  8459. }
  8460. if (ival == -1 && PyErr_Occurred()) {
  8461. goto exit;
  8462. }
  8463. size = ival;
  8464. }
  8465. return_value = os_urandom_impl(module, size);
  8466. exit:
  8467. return return_value;
  8468. }
  8469. #if defined(HAVE_MEMFD_CREATE)
  8470. PyDoc_STRVAR(os_memfd_create__doc__,
  8471. "memfd_create($module, /, name, flags=MFD_CLOEXEC)\n"
  8472. "--\n"
  8473. "\n");
  8474. #define OS_MEMFD_CREATE_METHODDEF \
  8475. {"memfd_create", _PyCFunction_CAST(os_memfd_create), METH_FASTCALL|METH_KEYWORDS, os_memfd_create__doc__},
  8476. static PyObject *
  8477. os_memfd_create_impl(PyObject *module, PyObject *name, unsigned int flags);
  8478. static PyObject *
  8479. os_memfd_create(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8480. {
  8481. PyObject *return_value = NULL;
  8482. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8483. #define NUM_KEYWORDS 2
  8484. static struct {
  8485. PyGC_Head _this_is_not_used;
  8486. PyObject_VAR_HEAD
  8487. PyObject *ob_item[NUM_KEYWORDS];
  8488. } _kwtuple = {
  8489. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8490. .ob_item = { &_Py_ID(name), &_Py_ID(flags), },
  8491. };
  8492. #undef NUM_KEYWORDS
  8493. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8494. #else // !Py_BUILD_CORE
  8495. # define KWTUPLE NULL
  8496. #endif // !Py_BUILD_CORE
  8497. static const char * const _keywords[] = {"name", "flags", NULL};
  8498. static _PyArg_Parser _parser = {
  8499. .keywords = _keywords,
  8500. .fname = "memfd_create",
  8501. .kwtuple = KWTUPLE,
  8502. };
  8503. #undef KWTUPLE
  8504. PyObject *argsbuf[2];
  8505. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  8506. PyObject *name = NULL;
  8507. unsigned int flags = MFD_CLOEXEC;
  8508. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  8509. if (!args) {
  8510. goto exit;
  8511. }
  8512. if (!PyUnicode_FSConverter(args[0], &name)) {
  8513. goto exit;
  8514. }
  8515. if (!noptargs) {
  8516. goto skip_optional_pos;
  8517. }
  8518. flags = (unsigned int)PyLong_AsUnsignedLongMask(args[1]);
  8519. if (flags == (unsigned int)-1 && PyErr_Occurred()) {
  8520. goto exit;
  8521. }
  8522. skip_optional_pos:
  8523. return_value = os_memfd_create_impl(module, name, flags);
  8524. exit:
  8525. /* Cleanup for name */
  8526. Py_XDECREF(name);
  8527. return return_value;
  8528. }
  8529. #endif /* defined(HAVE_MEMFD_CREATE) */
  8530. #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
  8531. PyDoc_STRVAR(os_eventfd__doc__,
  8532. "eventfd($module, /, initval, flags=EFD_CLOEXEC)\n"
  8533. "--\n"
  8534. "\n"
  8535. "Creates and returns an event notification file descriptor.");
  8536. #define OS_EVENTFD_METHODDEF \
  8537. {"eventfd", _PyCFunction_CAST(os_eventfd), METH_FASTCALL|METH_KEYWORDS, os_eventfd__doc__},
  8538. static PyObject *
  8539. os_eventfd_impl(PyObject *module, unsigned int initval, int flags);
  8540. static PyObject *
  8541. os_eventfd(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8542. {
  8543. PyObject *return_value = NULL;
  8544. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8545. #define NUM_KEYWORDS 2
  8546. static struct {
  8547. PyGC_Head _this_is_not_used;
  8548. PyObject_VAR_HEAD
  8549. PyObject *ob_item[NUM_KEYWORDS];
  8550. } _kwtuple = {
  8551. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8552. .ob_item = { &_Py_ID(initval), &_Py_ID(flags), },
  8553. };
  8554. #undef NUM_KEYWORDS
  8555. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8556. #else // !Py_BUILD_CORE
  8557. # define KWTUPLE NULL
  8558. #endif // !Py_BUILD_CORE
  8559. static const char * const _keywords[] = {"initval", "flags", NULL};
  8560. static _PyArg_Parser _parser = {
  8561. .keywords = _keywords,
  8562. .fname = "eventfd",
  8563. .kwtuple = KWTUPLE,
  8564. };
  8565. #undef KWTUPLE
  8566. PyObject *argsbuf[2];
  8567. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  8568. unsigned int initval;
  8569. int flags = EFD_CLOEXEC;
  8570. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  8571. if (!args) {
  8572. goto exit;
  8573. }
  8574. if (!_PyLong_UnsignedInt_Converter(args[0], &initval)) {
  8575. goto exit;
  8576. }
  8577. if (!noptargs) {
  8578. goto skip_optional_pos;
  8579. }
  8580. flags = _PyLong_AsInt(args[1]);
  8581. if (flags == -1 && PyErr_Occurred()) {
  8582. goto exit;
  8583. }
  8584. skip_optional_pos:
  8585. return_value = os_eventfd_impl(module, initval, flags);
  8586. exit:
  8587. return return_value;
  8588. }
  8589. #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
  8590. #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
  8591. PyDoc_STRVAR(os_eventfd_read__doc__,
  8592. "eventfd_read($module, /, fd)\n"
  8593. "--\n"
  8594. "\n"
  8595. "Read eventfd value");
  8596. #define OS_EVENTFD_READ_METHODDEF \
  8597. {"eventfd_read", _PyCFunction_CAST(os_eventfd_read), METH_FASTCALL|METH_KEYWORDS, os_eventfd_read__doc__},
  8598. static PyObject *
  8599. os_eventfd_read_impl(PyObject *module, int fd);
  8600. static PyObject *
  8601. os_eventfd_read(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8602. {
  8603. PyObject *return_value = NULL;
  8604. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8605. #define NUM_KEYWORDS 1
  8606. static struct {
  8607. PyGC_Head _this_is_not_used;
  8608. PyObject_VAR_HEAD
  8609. PyObject *ob_item[NUM_KEYWORDS];
  8610. } _kwtuple = {
  8611. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8612. .ob_item = { &_Py_ID(fd), },
  8613. };
  8614. #undef NUM_KEYWORDS
  8615. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8616. #else // !Py_BUILD_CORE
  8617. # define KWTUPLE NULL
  8618. #endif // !Py_BUILD_CORE
  8619. static const char * const _keywords[] = {"fd", NULL};
  8620. static _PyArg_Parser _parser = {
  8621. .keywords = _keywords,
  8622. .fname = "eventfd_read",
  8623. .kwtuple = KWTUPLE,
  8624. };
  8625. #undef KWTUPLE
  8626. PyObject *argsbuf[1];
  8627. int fd;
  8628. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  8629. if (!args) {
  8630. goto exit;
  8631. }
  8632. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  8633. goto exit;
  8634. }
  8635. return_value = os_eventfd_read_impl(module, fd);
  8636. exit:
  8637. return return_value;
  8638. }
  8639. #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
  8640. #if (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC))
  8641. PyDoc_STRVAR(os_eventfd_write__doc__,
  8642. "eventfd_write($module, /, fd, value)\n"
  8643. "--\n"
  8644. "\n"
  8645. "Write eventfd value.");
  8646. #define OS_EVENTFD_WRITE_METHODDEF \
  8647. {"eventfd_write", _PyCFunction_CAST(os_eventfd_write), METH_FASTCALL|METH_KEYWORDS, os_eventfd_write__doc__},
  8648. static PyObject *
  8649. os_eventfd_write_impl(PyObject *module, int fd, unsigned long long value);
  8650. static PyObject *
  8651. os_eventfd_write(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8652. {
  8653. PyObject *return_value = NULL;
  8654. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8655. #define NUM_KEYWORDS 2
  8656. static struct {
  8657. PyGC_Head _this_is_not_used;
  8658. PyObject_VAR_HEAD
  8659. PyObject *ob_item[NUM_KEYWORDS];
  8660. } _kwtuple = {
  8661. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  8662. .ob_item = { &_Py_ID(fd), &_Py_ID(value), },
  8663. };
  8664. #undef NUM_KEYWORDS
  8665. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  8666. #else // !Py_BUILD_CORE
  8667. # define KWTUPLE NULL
  8668. #endif // !Py_BUILD_CORE
  8669. static const char * const _keywords[] = {"fd", "value", NULL};
  8670. static _PyArg_Parser _parser = {
  8671. .keywords = _keywords,
  8672. .fname = "eventfd_write",
  8673. .kwtuple = KWTUPLE,
  8674. };
  8675. #undef KWTUPLE
  8676. PyObject *argsbuf[2];
  8677. int fd;
  8678. unsigned long long value;
  8679. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 2, 2, 0, argsbuf);
  8680. if (!args) {
  8681. goto exit;
  8682. }
  8683. if (!_PyLong_FileDescriptor_Converter(args[0], &fd)) {
  8684. goto exit;
  8685. }
  8686. if (!_PyLong_UnsignedLongLong_Converter(args[1], &value)) {
  8687. goto exit;
  8688. }
  8689. return_value = os_eventfd_write_impl(module, fd, value);
  8690. exit:
  8691. return return_value;
  8692. }
  8693. #endif /* (defined(HAVE_EVENTFD) && defined(EFD_CLOEXEC)) */
  8694. #if (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL))
  8695. PyDoc_STRVAR(os_get_terminal_size__doc__,
  8696. "get_terminal_size($module, fd=<unrepresentable>, /)\n"
  8697. "--\n"
  8698. "\n"
  8699. "Return the size of the terminal window as (columns, lines).\n"
  8700. "\n"
  8701. "The optional argument fd (default standard output) specifies\n"
  8702. "which file descriptor should be queried.\n"
  8703. "\n"
  8704. "If the file descriptor is not connected to a terminal, an OSError\n"
  8705. "is thrown.\n"
  8706. "\n"
  8707. "This function will only be defined if an implementation is\n"
  8708. "available for this system.\n"
  8709. "\n"
  8710. "shutil.get_terminal_size is the high-level function which should\n"
  8711. "normally be used, os.get_terminal_size is the low-level implementation.");
  8712. #define OS_GET_TERMINAL_SIZE_METHODDEF \
  8713. {"get_terminal_size", _PyCFunction_CAST(os_get_terminal_size), METH_FASTCALL, os_get_terminal_size__doc__},
  8714. static PyObject *
  8715. os_get_terminal_size_impl(PyObject *module, int fd);
  8716. static PyObject *
  8717. os_get_terminal_size(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8718. {
  8719. PyObject *return_value = NULL;
  8720. int fd = fileno(stdout);
  8721. if (!_PyArg_CheckPositional("get_terminal_size", nargs, 0, 1)) {
  8722. goto exit;
  8723. }
  8724. if (nargs < 1) {
  8725. goto skip_optional;
  8726. }
  8727. fd = _PyLong_AsInt(args[0]);
  8728. if (fd == -1 && PyErr_Occurred()) {
  8729. goto exit;
  8730. }
  8731. skip_optional:
  8732. return_value = os_get_terminal_size_impl(module, fd);
  8733. exit:
  8734. return return_value;
  8735. }
  8736. #endif /* (defined(TERMSIZE_USE_CONIO) || defined(TERMSIZE_USE_IOCTL)) */
  8737. PyDoc_STRVAR(os_cpu_count__doc__,
  8738. "cpu_count($module, /)\n"
  8739. "--\n"
  8740. "\n"
  8741. "Return the number of CPUs in the system; return None if indeterminable.\n"
  8742. "\n"
  8743. "This number is not equivalent to the number of CPUs the current process can\n"
  8744. "use. The number of usable CPUs can be obtained with\n"
  8745. "``len(os.sched_getaffinity(0))``");
  8746. #define OS_CPU_COUNT_METHODDEF \
  8747. {"cpu_count", (PyCFunction)os_cpu_count, METH_NOARGS, os_cpu_count__doc__},
  8748. static PyObject *
  8749. os_cpu_count_impl(PyObject *module);
  8750. static PyObject *
  8751. os_cpu_count(PyObject *module, PyObject *Py_UNUSED(ignored))
  8752. {
  8753. return os_cpu_count_impl(module);
  8754. }
  8755. PyDoc_STRVAR(os_get_inheritable__doc__,
  8756. "get_inheritable($module, fd, /)\n"
  8757. "--\n"
  8758. "\n"
  8759. "Get the close-on-exe flag of the specified file descriptor.");
  8760. #define OS_GET_INHERITABLE_METHODDEF \
  8761. {"get_inheritable", (PyCFunction)os_get_inheritable, METH_O, os_get_inheritable__doc__},
  8762. static int
  8763. os_get_inheritable_impl(PyObject *module, int fd);
  8764. static PyObject *
  8765. os_get_inheritable(PyObject *module, PyObject *arg)
  8766. {
  8767. PyObject *return_value = NULL;
  8768. int fd;
  8769. int _return_value;
  8770. fd = _PyLong_AsInt(arg);
  8771. if (fd == -1 && PyErr_Occurred()) {
  8772. goto exit;
  8773. }
  8774. _return_value = os_get_inheritable_impl(module, fd);
  8775. if ((_return_value == -1) && PyErr_Occurred()) {
  8776. goto exit;
  8777. }
  8778. return_value = PyBool_FromLong((long)_return_value);
  8779. exit:
  8780. return return_value;
  8781. }
  8782. PyDoc_STRVAR(os_set_inheritable__doc__,
  8783. "set_inheritable($module, fd, inheritable, /)\n"
  8784. "--\n"
  8785. "\n"
  8786. "Set the inheritable flag of the specified file descriptor.");
  8787. #define OS_SET_INHERITABLE_METHODDEF \
  8788. {"set_inheritable", _PyCFunction_CAST(os_set_inheritable), METH_FASTCALL, os_set_inheritable__doc__},
  8789. static PyObject *
  8790. os_set_inheritable_impl(PyObject *module, int fd, int inheritable);
  8791. static PyObject *
  8792. os_set_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8793. {
  8794. PyObject *return_value = NULL;
  8795. int fd;
  8796. int inheritable;
  8797. if (!_PyArg_CheckPositional("set_inheritable", nargs, 2, 2)) {
  8798. goto exit;
  8799. }
  8800. fd = _PyLong_AsInt(args[0]);
  8801. if (fd == -1 && PyErr_Occurred()) {
  8802. goto exit;
  8803. }
  8804. inheritable = _PyLong_AsInt(args[1]);
  8805. if (inheritable == -1 && PyErr_Occurred()) {
  8806. goto exit;
  8807. }
  8808. return_value = os_set_inheritable_impl(module, fd, inheritable);
  8809. exit:
  8810. return return_value;
  8811. }
  8812. #if defined(MS_WINDOWS)
  8813. PyDoc_STRVAR(os_get_handle_inheritable__doc__,
  8814. "get_handle_inheritable($module, handle, /)\n"
  8815. "--\n"
  8816. "\n"
  8817. "Get the close-on-exe flag of the specified file descriptor.");
  8818. #define OS_GET_HANDLE_INHERITABLE_METHODDEF \
  8819. {"get_handle_inheritable", (PyCFunction)os_get_handle_inheritable, METH_O, os_get_handle_inheritable__doc__},
  8820. static int
  8821. os_get_handle_inheritable_impl(PyObject *module, intptr_t handle);
  8822. static PyObject *
  8823. os_get_handle_inheritable(PyObject *module, PyObject *arg)
  8824. {
  8825. PyObject *return_value = NULL;
  8826. intptr_t handle;
  8827. int _return_value;
  8828. if (!PyArg_Parse(arg, "" _Py_PARSE_INTPTR ":get_handle_inheritable", &handle)) {
  8829. goto exit;
  8830. }
  8831. _return_value = os_get_handle_inheritable_impl(module, handle);
  8832. if ((_return_value == -1) && PyErr_Occurred()) {
  8833. goto exit;
  8834. }
  8835. return_value = PyBool_FromLong((long)_return_value);
  8836. exit:
  8837. return return_value;
  8838. }
  8839. #endif /* defined(MS_WINDOWS) */
  8840. #if defined(MS_WINDOWS)
  8841. PyDoc_STRVAR(os_set_handle_inheritable__doc__,
  8842. "set_handle_inheritable($module, handle, inheritable, /)\n"
  8843. "--\n"
  8844. "\n"
  8845. "Set the inheritable flag of the specified handle.");
  8846. #define OS_SET_HANDLE_INHERITABLE_METHODDEF \
  8847. {"set_handle_inheritable", _PyCFunction_CAST(os_set_handle_inheritable), METH_FASTCALL, os_set_handle_inheritable__doc__},
  8848. static PyObject *
  8849. os_set_handle_inheritable_impl(PyObject *module, intptr_t handle,
  8850. int inheritable);
  8851. static PyObject *
  8852. os_set_handle_inheritable(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8853. {
  8854. PyObject *return_value = NULL;
  8855. intptr_t handle;
  8856. int inheritable;
  8857. if (!_PyArg_ParseStack(args, nargs, "" _Py_PARSE_INTPTR "p:set_handle_inheritable",
  8858. &handle, &inheritable)) {
  8859. goto exit;
  8860. }
  8861. return_value = os_set_handle_inheritable_impl(module, handle, inheritable);
  8862. exit:
  8863. return return_value;
  8864. }
  8865. #endif /* defined(MS_WINDOWS) */
  8866. PyDoc_STRVAR(os_get_blocking__doc__,
  8867. "get_blocking($module, fd, /)\n"
  8868. "--\n"
  8869. "\n"
  8870. "Get the blocking mode of the file descriptor.\n"
  8871. "\n"
  8872. "Return False if the O_NONBLOCK flag is set, True if the flag is cleared.");
  8873. #define OS_GET_BLOCKING_METHODDEF \
  8874. {"get_blocking", (PyCFunction)os_get_blocking, METH_O, os_get_blocking__doc__},
  8875. static int
  8876. os_get_blocking_impl(PyObject *module, int fd);
  8877. static PyObject *
  8878. os_get_blocking(PyObject *module, PyObject *arg)
  8879. {
  8880. PyObject *return_value = NULL;
  8881. int fd;
  8882. int _return_value;
  8883. fd = _PyLong_AsInt(arg);
  8884. if (fd == -1 && PyErr_Occurred()) {
  8885. goto exit;
  8886. }
  8887. _return_value = os_get_blocking_impl(module, fd);
  8888. if ((_return_value == -1) && PyErr_Occurred()) {
  8889. goto exit;
  8890. }
  8891. return_value = PyBool_FromLong((long)_return_value);
  8892. exit:
  8893. return return_value;
  8894. }
  8895. PyDoc_STRVAR(os_set_blocking__doc__,
  8896. "set_blocking($module, fd, blocking, /)\n"
  8897. "--\n"
  8898. "\n"
  8899. "Set the blocking mode of the specified file descriptor.\n"
  8900. "\n"
  8901. "Set the O_NONBLOCK flag if blocking is False,\n"
  8902. "clear the O_NONBLOCK flag otherwise.");
  8903. #define OS_SET_BLOCKING_METHODDEF \
  8904. {"set_blocking", _PyCFunction_CAST(os_set_blocking), METH_FASTCALL, os_set_blocking__doc__},
  8905. static PyObject *
  8906. os_set_blocking_impl(PyObject *module, int fd, int blocking);
  8907. static PyObject *
  8908. os_set_blocking(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
  8909. {
  8910. PyObject *return_value = NULL;
  8911. int fd;
  8912. int blocking;
  8913. if (!_PyArg_CheckPositional("set_blocking", nargs, 2, 2)) {
  8914. goto exit;
  8915. }
  8916. fd = _PyLong_AsInt(args[0]);
  8917. if (fd == -1 && PyErr_Occurred()) {
  8918. goto exit;
  8919. }
  8920. blocking = PyObject_IsTrue(args[1]);
  8921. if (blocking < 0) {
  8922. goto exit;
  8923. }
  8924. return_value = os_set_blocking_impl(module, fd, blocking);
  8925. exit:
  8926. return return_value;
  8927. }
  8928. PyDoc_STRVAR(os_DirEntry_is_symlink__doc__,
  8929. "is_symlink($self, /)\n"
  8930. "--\n"
  8931. "\n"
  8932. "Return True if the entry is a symbolic link; cached per entry.");
  8933. #define OS_DIRENTRY_IS_SYMLINK_METHODDEF \
  8934. {"is_symlink", _PyCFunction_CAST(os_DirEntry_is_symlink), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_symlink__doc__},
  8935. static int
  8936. os_DirEntry_is_symlink_impl(DirEntry *self, PyTypeObject *defining_class);
  8937. static PyObject *
  8938. os_DirEntry_is_symlink(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8939. {
  8940. PyObject *return_value = NULL;
  8941. int _return_value;
  8942. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  8943. PyErr_SetString(PyExc_TypeError, "is_symlink() takes no arguments");
  8944. goto exit;
  8945. }
  8946. _return_value = os_DirEntry_is_symlink_impl(self, defining_class);
  8947. if ((_return_value == -1) && PyErr_Occurred()) {
  8948. goto exit;
  8949. }
  8950. return_value = PyBool_FromLong((long)_return_value);
  8951. exit:
  8952. return return_value;
  8953. }
  8954. PyDoc_STRVAR(os_DirEntry_is_junction__doc__,
  8955. "is_junction($self, /)\n"
  8956. "--\n"
  8957. "\n"
  8958. "Return True if the entry is a junction; cached per entry.");
  8959. #define OS_DIRENTRY_IS_JUNCTION_METHODDEF \
  8960. {"is_junction", _PyCFunction_CAST(os_DirEntry_is_junction), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_junction__doc__},
  8961. static int
  8962. os_DirEntry_is_junction_impl(DirEntry *self, PyTypeObject *defining_class);
  8963. static PyObject *
  8964. os_DirEntry_is_junction(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8965. {
  8966. PyObject *return_value = NULL;
  8967. int _return_value;
  8968. if (nargs || (kwnames && PyTuple_GET_SIZE(kwnames))) {
  8969. PyErr_SetString(PyExc_TypeError, "is_junction() takes no arguments");
  8970. goto exit;
  8971. }
  8972. _return_value = os_DirEntry_is_junction_impl(self, defining_class);
  8973. if ((_return_value == -1) && PyErr_Occurred()) {
  8974. goto exit;
  8975. }
  8976. return_value = PyBool_FromLong((long)_return_value);
  8977. exit:
  8978. return return_value;
  8979. }
  8980. PyDoc_STRVAR(os_DirEntry_stat__doc__,
  8981. "stat($self, /, *, follow_symlinks=True)\n"
  8982. "--\n"
  8983. "\n"
  8984. "Return stat_result object for the entry; cached per entry.");
  8985. #define OS_DIRENTRY_STAT_METHODDEF \
  8986. {"stat", _PyCFunction_CAST(os_DirEntry_stat), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_stat__doc__},
  8987. static PyObject *
  8988. os_DirEntry_stat_impl(DirEntry *self, PyTypeObject *defining_class,
  8989. int follow_symlinks);
  8990. static PyObject *
  8991. os_DirEntry_stat(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  8992. {
  8993. PyObject *return_value = NULL;
  8994. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  8995. #define NUM_KEYWORDS 1
  8996. static struct {
  8997. PyGC_Head _this_is_not_used;
  8998. PyObject_VAR_HEAD
  8999. PyObject *ob_item[NUM_KEYWORDS];
  9000. } _kwtuple = {
  9001. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9002. .ob_item = { &_Py_ID(follow_symlinks), },
  9003. };
  9004. #undef NUM_KEYWORDS
  9005. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9006. #else // !Py_BUILD_CORE
  9007. # define KWTUPLE NULL
  9008. #endif // !Py_BUILD_CORE
  9009. static const char * const _keywords[] = {"follow_symlinks", NULL};
  9010. static _PyArg_Parser _parser = {
  9011. .keywords = _keywords,
  9012. .fname = "stat",
  9013. .kwtuple = KWTUPLE,
  9014. };
  9015. #undef KWTUPLE
  9016. PyObject *argsbuf[1];
  9017. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  9018. int follow_symlinks = 1;
  9019. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  9020. if (!args) {
  9021. goto exit;
  9022. }
  9023. if (!noptargs) {
  9024. goto skip_optional_kwonly;
  9025. }
  9026. follow_symlinks = PyObject_IsTrue(args[0]);
  9027. if (follow_symlinks < 0) {
  9028. goto exit;
  9029. }
  9030. skip_optional_kwonly:
  9031. return_value = os_DirEntry_stat_impl(self, defining_class, follow_symlinks);
  9032. exit:
  9033. return return_value;
  9034. }
  9035. PyDoc_STRVAR(os_DirEntry_is_dir__doc__,
  9036. "is_dir($self, /, *, follow_symlinks=True)\n"
  9037. "--\n"
  9038. "\n"
  9039. "Return True if the entry is a directory; cached per entry.");
  9040. #define OS_DIRENTRY_IS_DIR_METHODDEF \
  9041. {"is_dir", _PyCFunction_CAST(os_DirEntry_is_dir), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_dir__doc__},
  9042. static int
  9043. os_DirEntry_is_dir_impl(DirEntry *self, PyTypeObject *defining_class,
  9044. int follow_symlinks);
  9045. static PyObject *
  9046. os_DirEntry_is_dir(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9047. {
  9048. PyObject *return_value = NULL;
  9049. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9050. #define NUM_KEYWORDS 1
  9051. static struct {
  9052. PyGC_Head _this_is_not_used;
  9053. PyObject_VAR_HEAD
  9054. PyObject *ob_item[NUM_KEYWORDS];
  9055. } _kwtuple = {
  9056. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9057. .ob_item = { &_Py_ID(follow_symlinks), },
  9058. };
  9059. #undef NUM_KEYWORDS
  9060. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9061. #else // !Py_BUILD_CORE
  9062. # define KWTUPLE NULL
  9063. #endif // !Py_BUILD_CORE
  9064. static const char * const _keywords[] = {"follow_symlinks", NULL};
  9065. static _PyArg_Parser _parser = {
  9066. .keywords = _keywords,
  9067. .fname = "is_dir",
  9068. .kwtuple = KWTUPLE,
  9069. };
  9070. #undef KWTUPLE
  9071. PyObject *argsbuf[1];
  9072. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  9073. int follow_symlinks = 1;
  9074. int _return_value;
  9075. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  9076. if (!args) {
  9077. goto exit;
  9078. }
  9079. if (!noptargs) {
  9080. goto skip_optional_kwonly;
  9081. }
  9082. follow_symlinks = PyObject_IsTrue(args[0]);
  9083. if (follow_symlinks < 0) {
  9084. goto exit;
  9085. }
  9086. skip_optional_kwonly:
  9087. _return_value = os_DirEntry_is_dir_impl(self, defining_class, follow_symlinks);
  9088. if ((_return_value == -1) && PyErr_Occurred()) {
  9089. goto exit;
  9090. }
  9091. return_value = PyBool_FromLong((long)_return_value);
  9092. exit:
  9093. return return_value;
  9094. }
  9095. PyDoc_STRVAR(os_DirEntry_is_file__doc__,
  9096. "is_file($self, /, *, follow_symlinks=True)\n"
  9097. "--\n"
  9098. "\n"
  9099. "Return True if the entry is a file; cached per entry.");
  9100. #define OS_DIRENTRY_IS_FILE_METHODDEF \
  9101. {"is_file", _PyCFunction_CAST(os_DirEntry_is_file), METH_METHOD|METH_FASTCALL|METH_KEYWORDS, os_DirEntry_is_file__doc__},
  9102. static int
  9103. os_DirEntry_is_file_impl(DirEntry *self, PyTypeObject *defining_class,
  9104. int follow_symlinks);
  9105. static PyObject *
  9106. os_DirEntry_is_file(DirEntry *self, PyTypeObject *defining_class, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9107. {
  9108. PyObject *return_value = NULL;
  9109. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9110. #define NUM_KEYWORDS 1
  9111. static struct {
  9112. PyGC_Head _this_is_not_used;
  9113. PyObject_VAR_HEAD
  9114. PyObject *ob_item[NUM_KEYWORDS];
  9115. } _kwtuple = {
  9116. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9117. .ob_item = { &_Py_ID(follow_symlinks), },
  9118. };
  9119. #undef NUM_KEYWORDS
  9120. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9121. #else // !Py_BUILD_CORE
  9122. # define KWTUPLE NULL
  9123. #endif // !Py_BUILD_CORE
  9124. static const char * const _keywords[] = {"follow_symlinks", NULL};
  9125. static _PyArg_Parser _parser = {
  9126. .keywords = _keywords,
  9127. .fname = "is_file",
  9128. .kwtuple = KWTUPLE,
  9129. };
  9130. #undef KWTUPLE
  9131. PyObject *argsbuf[1];
  9132. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  9133. int follow_symlinks = 1;
  9134. int _return_value;
  9135. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 0, 0, argsbuf);
  9136. if (!args) {
  9137. goto exit;
  9138. }
  9139. if (!noptargs) {
  9140. goto skip_optional_kwonly;
  9141. }
  9142. follow_symlinks = PyObject_IsTrue(args[0]);
  9143. if (follow_symlinks < 0) {
  9144. goto exit;
  9145. }
  9146. skip_optional_kwonly:
  9147. _return_value = os_DirEntry_is_file_impl(self, defining_class, follow_symlinks);
  9148. if ((_return_value == -1) && PyErr_Occurred()) {
  9149. goto exit;
  9150. }
  9151. return_value = PyBool_FromLong((long)_return_value);
  9152. exit:
  9153. return return_value;
  9154. }
  9155. PyDoc_STRVAR(os_DirEntry_inode__doc__,
  9156. "inode($self, /)\n"
  9157. "--\n"
  9158. "\n"
  9159. "Return inode of the entry; cached per entry.");
  9160. #define OS_DIRENTRY_INODE_METHODDEF \
  9161. {"inode", (PyCFunction)os_DirEntry_inode, METH_NOARGS, os_DirEntry_inode__doc__},
  9162. static PyObject *
  9163. os_DirEntry_inode_impl(DirEntry *self);
  9164. static PyObject *
  9165. os_DirEntry_inode(DirEntry *self, PyObject *Py_UNUSED(ignored))
  9166. {
  9167. return os_DirEntry_inode_impl(self);
  9168. }
  9169. PyDoc_STRVAR(os_DirEntry___fspath____doc__,
  9170. "__fspath__($self, /)\n"
  9171. "--\n"
  9172. "\n"
  9173. "Returns the path for the entry.");
  9174. #define OS_DIRENTRY___FSPATH___METHODDEF \
  9175. {"__fspath__", (PyCFunction)os_DirEntry___fspath__, METH_NOARGS, os_DirEntry___fspath____doc__},
  9176. static PyObject *
  9177. os_DirEntry___fspath___impl(DirEntry *self);
  9178. static PyObject *
  9179. os_DirEntry___fspath__(DirEntry *self, PyObject *Py_UNUSED(ignored))
  9180. {
  9181. return os_DirEntry___fspath___impl(self);
  9182. }
  9183. PyDoc_STRVAR(os_scandir__doc__,
  9184. "scandir($module, /, path=None)\n"
  9185. "--\n"
  9186. "\n"
  9187. "Return an iterator of DirEntry objects for given path.\n"
  9188. "\n"
  9189. "path can be specified as either str, bytes, or a path-like object. If path\n"
  9190. "is bytes, the names of yielded DirEntry objects will also be bytes; in\n"
  9191. "all other circumstances they will be str.\n"
  9192. "\n"
  9193. "If path is None, uses the path=\'.\'.");
  9194. #define OS_SCANDIR_METHODDEF \
  9195. {"scandir", _PyCFunction_CAST(os_scandir), METH_FASTCALL|METH_KEYWORDS, os_scandir__doc__},
  9196. static PyObject *
  9197. os_scandir_impl(PyObject *module, path_t *path);
  9198. static PyObject *
  9199. os_scandir(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9200. {
  9201. PyObject *return_value = NULL;
  9202. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9203. #define NUM_KEYWORDS 1
  9204. static struct {
  9205. PyGC_Head _this_is_not_used;
  9206. PyObject_VAR_HEAD
  9207. PyObject *ob_item[NUM_KEYWORDS];
  9208. } _kwtuple = {
  9209. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9210. .ob_item = { &_Py_ID(path), },
  9211. };
  9212. #undef NUM_KEYWORDS
  9213. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9214. #else // !Py_BUILD_CORE
  9215. # define KWTUPLE NULL
  9216. #endif // !Py_BUILD_CORE
  9217. static const char * const _keywords[] = {"path", NULL};
  9218. static _PyArg_Parser _parser = {
  9219. .keywords = _keywords,
  9220. .fname = "scandir",
  9221. .kwtuple = KWTUPLE,
  9222. };
  9223. #undef KWTUPLE
  9224. PyObject *argsbuf[1];
  9225. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 0;
  9226. path_t path = PATH_T_INITIALIZE_P("scandir", "path", 1, 0, 0, PATH_HAVE_FDOPENDIR);
  9227. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 0, 1, 0, argsbuf);
  9228. if (!args) {
  9229. goto exit;
  9230. }
  9231. if (!noptargs) {
  9232. goto skip_optional_pos;
  9233. }
  9234. if (!path_converter(args[0], &path)) {
  9235. goto exit;
  9236. }
  9237. skip_optional_pos:
  9238. return_value = os_scandir_impl(module, &path);
  9239. exit:
  9240. /* Cleanup for path */
  9241. path_cleanup(&path);
  9242. return return_value;
  9243. }
  9244. PyDoc_STRVAR(os_fspath__doc__,
  9245. "fspath($module, /, path)\n"
  9246. "--\n"
  9247. "\n"
  9248. "Return the file system path representation of the object.\n"
  9249. "\n"
  9250. "If the object is str or bytes, then allow it to pass through as-is. If the\n"
  9251. "object defines __fspath__(), then return the result of that method. All other\n"
  9252. "types raise a TypeError.");
  9253. #define OS_FSPATH_METHODDEF \
  9254. {"fspath", _PyCFunction_CAST(os_fspath), METH_FASTCALL|METH_KEYWORDS, os_fspath__doc__},
  9255. static PyObject *
  9256. os_fspath_impl(PyObject *module, PyObject *path);
  9257. static PyObject *
  9258. os_fspath(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9259. {
  9260. PyObject *return_value = NULL;
  9261. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9262. #define NUM_KEYWORDS 1
  9263. static struct {
  9264. PyGC_Head _this_is_not_used;
  9265. PyObject_VAR_HEAD
  9266. PyObject *ob_item[NUM_KEYWORDS];
  9267. } _kwtuple = {
  9268. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9269. .ob_item = { &_Py_ID(path), },
  9270. };
  9271. #undef NUM_KEYWORDS
  9272. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9273. #else // !Py_BUILD_CORE
  9274. # define KWTUPLE NULL
  9275. #endif // !Py_BUILD_CORE
  9276. static const char * const _keywords[] = {"path", NULL};
  9277. static _PyArg_Parser _parser = {
  9278. .keywords = _keywords,
  9279. .fname = "fspath",
  9280. .kwtuple = KWTUPLE,
  9281. };
  9282. #undef KWTUPLE
  9283. PyObject *argsbuf[1];
  9284. PyObject *path;
  9285. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  9286. if (!args) {
  9287. goto exit;
  9288. }
  9289. path = args[0];
  9290. return_value = os_fspath_impl(module, path);
  9291. exit:
  9292. return return_value;
  9293. }
  9294. #if defined(HAVE_GETRANDOM_SYSCALL)
  9295. PyDoc_STRVAR(os_getrandom__doc__,
  9296. "getrandom($module, /, size, flags=0)\n"
  9297. "--\n"
  9298. "\n"
  9299. "Obtain a series of random bytes.");
  9300. #define OS_GETRANDOM_METHODDEF \
  9301. {"getrandom", _PyCFunction_CAST(os_getrandom), METH_FASTCALL|METH_KEYWORDS, os_getrandom__doc__},
  9302. static PyObject *
  9303. os_getrandom_impl(PyObject *module, Py_ssize_t size, int flags);
  9304. static PyObject *
  9305. os_getrandom(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9306. {
  9307. PyObject *return_value = NULL;
  9308. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9309. #define NUM_KEYWORDS 2
  9310. static struct {
  9311. PyGC_Head _this_is_not_used;
  9312. PyObject_VAR_HEAD
  9313. PyObject *ob_item[NUM_KEYWORDS];
  9314. } _kwtuple = {
  9315. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9316. .ob_item = { &_Py_ID(size), &_Py_ID(flags), },
  9317. };
  9318. #undef NUM_KEYWORDS
  9319. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9320. #else // !Py_BUILD_CORE
  9321. # define KWTUPLE NULL
  9322. #endif // !Py_BUILD_CORE
  9323. static const char * const _keywords[] = {"size", "flags", NULL};
  9324. static _PyArg_Parser _parser = {
  9325. .keywords = _keywords,
  9326. .fname = "getrandom",
  9327. .kwtuple = KWTUPLE,
  9328. };
  9329. #undef KWTUPLE
  9330. PyObject *argsbuf[2];
  9331. Py_ssize_t noptargs = nargs + (kwnames ? PyTuple_GET_SIZE(kwnames) : 0) - 1;
  9332. Py_ssize_t size;
  9333. int flags = 0;
  9334. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 2, 0, argsbuf);
  9335. if (!args) {
  9336. goto exit;
  9337. }
  9338. {
  9339. Py_ssize_t ival = -1;
  9340. PyObject *iobj = _PyNumber_Index(args[0]);
  9341. if (iobj != NULL) {
  9342. ival = PyLong_AsSsize_t(iobj);
  9343. Py_DECREF(iobj);
  9344. }
  9345. if (ival == -1 && PyErr_Occurred()) {
  9346. goto exit;
  9347. }
  9348. size = ival;
  9349. }
  9350. if (!noptargs) {
  9351. goto skip_optional_pos;
  9352. }
  9353. flags = _PyLong_AsInt(args[1]);
  9354. if (flags == -1 && PyErr_Occurred()) {
  9355. goto exit;
  9356. }
  9357. skip_optional_pos:
  9358. return_value = os_getrandom_impl(module, size, flags);
  9359. exit:
  9360. return return_value;
  9361. }
  9362. #endif /* defined(HAVE_GETRANDOM_SYSCALL) */
  9363. #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
  9364. PyDoc_STRVAR(os__add_dll_directory__doc__,
  9365. "_add_dll_directory($module, /, path)\n"
  9366. "--\n"
  9367. "\n"
  9368. "Add a path to the DLL search path.\n"
  9369. "\n"
  9370. "This search path is used when resolving dependencies for imported\n"
  9371. "extension modules (the module itself is resolved through sys.path),\n"
  9372. "and also by ctypes.\n"
  9373. "\n"
  9374. "Returns an opaque value that may be passed to os.remove_dll_directory\n"
  9375. "to remove this directory from the search path.");
  9376. #define OS__ADD_DLL_DIRECTORY_METHODDEF \
  9377. {"_add_dll_directory", _PyCFunction_CAST(os__add_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__add_dll_directory__doc__},
  9378. static PyObject *
  9379. os__add_dll_directory_impl(PyObject *module, path_t *path);
  9380. static PyObject *
  9381. os__add_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9382. {
  9383. PyObject *return_value = NULL;
  9384. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9385. #define NUM_KEYWORDS 1
  9386. static struct {
  9387. PyGC_Head _this_is_not_used;
  9388. PyObject_VAR_HEAD
  9389. PyObject *ob_item[NUM_KEYWORDS];
  9390. } _kwtuple = {
  9391. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9392. .ob_item = { &_Py_ID(path), },
  9393. };
  9394. #undef NUM_KEYWORDS
  9395. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9396. #else // !Py_BUILD_CORE
  9397. # define KWTUPLE NULL
  9398. #endif // !Py_BUILD_CORE
  9399. static const char * const _keywords[] = {"path", NULL};
  9400. static _PyArg_Parser _parser = {
  9401. .keywords = _keywords,
  9402. .fname = "_add_dll_directory",
  9403. .kwtuple = KWTUPLE,
  9404. };
  9405. #undef KWTUPLE
  9406. PyObject *argsbuf[1];
  9407. path_t path = PATH_T_INITIALIZE_P("_add_dll_directory", "path", 0, 0, 0, 0);
  9408. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  9409. if (!args) {
  9410. goto exit;
  9411. }
  9412. if (!path_converter(args[0], &path)) {
  9413. goto exit;
  9414. }
  9415. return_value = os__add_dll_directory_impl(module, &path);
  9416. exit:
  9417. /* Cleanup for path */
  9418. path_cleanup(&path);
  9419. return return_value;
  9420. }
  9421. #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
  9422. #if (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM))
  9423. PyDoc_STRVAR(os__remove_dll_directory__doc__,
  9424. "_remove_dll_directory($module, /, cookie)\n"
  9425. "--\n"
  9426. "\n"
  9427. "Removes a path from the DLL search path.\n"
  9428. "\n"
  9429. "The parameter is an opaque value that was returned from\n"
  9430. "os.add_dll_directory. You can only remove directories that you added\n"
  9431. "yourself.");
  9432. #define OS__REMOVE_DLL_DIRECTORY_METHODDEF \
  9433. {"_remove_dll_directory", _PyCFunction_CAST(os__remove_dll_directory), METH_FASTCALL|METH_KEYWORDS, os__remove_dll_directory__doc__},
  9434. static PyObject *
  9435. os__remove_dll_directory_impl(PyObject *module, PyObject *cookie);
  9436. static PyObject *
  9437. os__remove_dll_directory(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9438. {
  9439. PyObject *return_value = NULL;
  9440. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9441. #define NUM_KEYWORDS 1
  9442. static struct {
  9443. PyGC_Head _this_is_not_used;
  9444. PyObject_VAR_HEAD
  9445. PyObject *ob_item[NUM_KEYWORDS];
  9446. } _kwtuple = {
  9447. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9448. .ob_item = { &_Py_ID(cookie), },
  9449. };
  9450. #undef NUM_KEYWORDS
  9451. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9452. #else // !Py_BUILD_CORE
  9453. # define KWTUPLE NULL
  9454. #endif // !Py_BUILD_CORE
  9455. static const char * const _keywords[] = {"cookie", NULL};
  9456. static _PyArg_Parser _parser = {
  9457. .keywords = _keywords,
  9458. .fname = "_remove_dll_directory",
  9459. .kwtuple = KWTUPLE,
  9460. };
  9461. #undef KWTUPLE
  9462. PyObject *argsbuf[1];
  9463. PyObject *cookie;
  9464. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  9465. if (!args) {
  9466. goto exit;
  9467. }
  9468. cookie = args[0];
  9469. return_value = os__remove_dll_directory_impl(module, cookie);
  9470. exit:
  9471. return return_value;
  9472. }
  9473. #endif /* (defined(MS_WINDOWS_DESKTOP) || defined(MS_WINDOWS_APP) || defined(MS_WINDOWS_SYSTEM)) */
  9474. #if (defined(WIFEXITED) || defined(MS_WINDOWS))
  9475. PyDoc_STRVAR(os_waitstatus_to_exitcode__doc__,
  9476. "waitstatus_to_exitcode($module, /, status)\n"
  9477. "--\n"
  9478. "\n"
  9479. "Convert a wait status to an exit code.\n"
  9480. "\n"
  9481. "On Unix:\n"
  9482. "\n"
  9483. "* If WIFEXITED(status) is true, return WEXITSTATUS(status).\n"
  9484. "* If WIFSIGNALED(status) is true, return -WTERMSIG(status).\n"
  9485. "* Otherwise, raise a ValueError.\n"
  9486. "\n"
  9487. "On Windows, return status shifted right by 8 bits.\n"
  9488. "\n"
  9489. "On Unix, if the process is being traced or if waitpid() was called with\n"
  9490. "WUNTRACED option, the caller must first check if WIFSTOPPED(status) is true.\n"
  9491. "This function must not be called if WIFSTOPPED(status) is true.");
  9492. #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF \
  9493. {"waitstatus_to_exitcode", _PyCFunction_CAST(os_waitstatus_to_exitcode), METH_FASTCALL|METH_KEYWORDS, os_waitstatus_to_exitcode__doc__},
  9494. static PyObject *
  9495. os_waitstatus_to_exitcode_impl(PyObject *module, PyObject *status_obj);
  9496. static PyObject *
  9497. os_waitstatus_to_exitcode(PyObject *module, PyObject *const *args, Py_ssize_t nargs, PyObject *kwnames)
  9498. {
  9499. PyObject *return_value = NULL;
  9500. #if defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_MODULE)
  9501. #define NUM_KEYWORDS 1
  9502. static struct {
  9503. PyGC_Head _this_is_not_used;
  9504. PyObject_VAR_HEAD
  9505. PyObject *ob_item[NUM_KEYWORDS];
  9506. } _kwtuple = {
  9507. .ob_base = PyVarObject_HEAD_INIT(&PyTuple_Type, NUM_KEYWORDS)
  9508. .ob_item = { &_Py_ID(status), },
  9509. };
  9510. #undef NUM_KEYWORDS
  9511. #define KWTUPLE (&_kwtuple.ob_base.ob_base)
  9512. #else // !Py_BUILD_CORE
  9513. # define KWTUPLE NULL
  9514. #endif // !Py_BUILD_CORE
  9515. static const char * const _keywords[] = {"status", NULL};
  9516. static _PyArg_Parser _parser = {
  9517. .keywords = _keywords,
  9518. .fname = "waitstatus_to_exitcode",
  9519. .kwtuple = KWTUPLE,
  9520. };
  9521. #undef KWTUPLE
  9522. PyObject *argsbuf[1];
  9523. PyObject *status_obj;
  9524. args = _PyArg_UnpackKeywords(args, nargs, NULL, kwnames, &_parser, 1, 1, 0, argsbuf);
  9525. if (!args) {
  9526. goto exit;
  9527. }
  9528. status_obj = args[0];
  9529. return_value = os_waitstatus_to_exitcode_impl(module, status_obj);
  9530. exit:
  9531. return return_value;
  9532. }
  9533. #endif /* (defined(WIFEXITED) || defined(MS_WINDOWS)) */
  9534. #ifndef OS_TTYNAME_METHODDEF
  9535. #define OS_TTYNAME_METHODDEF
  9536. #endif /* !defined(OS_TTYNAME_METHODDEF) */
  9537. #ifndef OS_CTERMID_METHODDEF
  9538. #define OS_CTERMID_METHODDEF
  9539. #endif /* !defined(OS_CTERMID_METHODDEF) */
  9540. #ifndef OS_FCHDIR_METHODDEF
  9541. #define OS_FCHDIR_METHODDEF
  9542. #endif /* !defined(OS_FCHDIR_METHODDEF) */
  9543. #ifndef OS_FCHMOD_METHODDEF
  9544. #define OS_FCHMOD_METHODDEF
  9545. #endif /* !defined(OS_FCHMOD_METHODDEF) */
  9546. #ifndef OS_LCHMOD_METHODDEF
  9547. #define OS_LCHMOD_METHODDEF
  9548. #endif /* !defined(OS_LCHMOD_METHODDEF) */
  9549. #ifndef OS_CHFLAGS_METHODDEF
  9550. #define OS_CHFLAGS_METHODDEF
  9551. #endif /* !defined(OS_CHFLAGS_METHODDEF) */
  9552. #ifndef OS_LCHFLAGS_METHODDEF
  9553. #define OS_LCHFLAGS_METHODDEF
  9554. #endif /* !defined(OS_LCHFLAGS_METHODDEF) */
  9555. #ifndef OS_CHROOT_METHODDEF
  9556. #define OS_CHROOT_METHODDEF
  9557. #endif /* !defined(OS_CHROOT_METHODDEF) */
  9558. #ifndef OS_FSYNC_METHODDEF
  9559. #define OS_FSYNC_METHODDEF
  9560. #endif /* !defined(OS_FSYNC_METHODDEF) */
  9561. #ifndef OS_SYNC_METHODDEF
  9562. #define OS_SYNC_METHODDEF
  9563. #endif /* !defined(OS_SYNC_METHODDEF) */
  9564. #ifndef OS_FDATASYNC_METHODDEF
  9565. #define OS_FDATASYNC_METHODDEF
  9566. #endif /* !defined(OS_FDATASYNC_METHODDEF) */
  9567. #ifndef OS_CHOWN_METHODDEF
  9568. #define OS_CHOWN_METHODDEF
  9569. #endif /* !defined(OS_CHOWN_METHODDEF) */
  9570. #ifndef OS_FCHOWN_METHODDEF
  9571. #define OS_FCHOWN_METHODDEF
  9572. #endif /* !defined(OS_FCHOWN_METHODDEF) */
  9573. #ifndef OS_LCHOWN_METHODDEF
  9574. #define OS_LCHOWN_METHODDEF
  9575. #endif /* !defined(OS_LCHOWN_METHODDEF) */
  9576. #ifndef OS_LINK_METHODDEF
  9577. #define OS_LINK_METHODDEF
  9578. #endif /* !defined(OS_LINK_METHODDEF) */
  9579. #ifndef OS_LISTDRIVES_METHODDEF
  9580. #define OS_LISTDRIVES_METHODDEF
  9581. #endif /* !defined(OS_LISTDRIVES_METHODDEF) */
  9582. #ifndef OS_LISTVOLUMES_METHODDEF
  9583. #define OS_LISTVOLUMES_METHODDEF
  9584. #endif /* !defined(OS_LISTVOLUMES_METHODDEF) */
  9585. #ifndef OS_LISTMOUNTS_METHODDEF
  9586. #define OS_LISTMOUNTS_METHODDEF
  9587. #endif /* !defined(OS_LISTMOUNTS_METHODDEF) */
  9588. #ifndef OS__PATH_ISDEVDRIVE_METHODDEF
  9589. #define OS__PATH_ISDEVDRIVE_METHODDEF
  9590. #endif /* !defined(OS__PATH_ISDEVDRIVE_METHODDEF) */
  9591. #ifndef OS__GETFULLPATHNAME_METHODDEF
  9592. #define OS__GETFULLPATHNAME_METHODDEF
  9593. #endif /* !defined(OS__GETFULLPATHNAME_METHODDEF) */
  9594. #ifndef OS__GETFINALPATHNAME_METHODDEF
  9595. #define OS__GETFINALPATHNAME_METHODDEF
  9596. #endif /* !defined(OS__GETFINALPATHNAME_METHODDEF) */
  9597. #ifndef OS__GETVOLUMEPATHNAME_METHODDEF
  9598. #define OS__GETVOLUMEPATHNAME_METHODDEF
  9599. #endif /* !defined(OS__GETVOLUMEPATHNAME_METHODDEF) */
  9600. #ifndef OS__PATH_SPLITROOT_METHODDEF
  9601. #define OS__PATH_SPLITROOT_METHODDEF
  9602. #endif /* !defined(OS__PATH_SPLITROOT_METHODDEF) */
  9603. #ifndef OS__PATH_EXISTS_METHODDEF
  9604. #define OS__PATH_EXISTS_METHODDEF
  9605. #endif /* !defined(OS__PATH_EXISTS_METHODDEF) */
  9606. #ifndef OS__PATH_ISDIR_METHODDEF
  9607. #define OS__PATH_ISDIR_METHODDEF
  9608. #endif /* !defined(OS__PATH_ISDIR_METHODDEF) */
  9609. #ifndef OS__PATH_ISFILE_METHODDEF
  9610. #define OS__PATH_ISFILE_METHODDEF
  9611. #endif /* !defined(OS__PATH_ISFILE_METHODDEF) */
  9612. #ifndef OS__PATH_ISLINK_METHODDEF
  9613. #define OS__PATH_ISLINK_METHODDEF
  9614. #endif /* !defined(OS__PATH_ISLINK_METHODDEF) */
  9615. #ifndef OS_NICE_METHODDEF
  9616. #define OS_NICE_METHODDEF
  9617. #endif /* !defined(OS_NICE_METHODDEF) */
  9618. #ifndef OS_GETPRIORITY_METHODDEF
  9619. #define OS_GETPRIORITY_METHODDEF
  9620. #endif /* !defined(OS_GETPRIORITY_METHODDEF) */
  9621. #ifndef OS_SETPRIORITY_METHODDEF
  9622. #define OS_SETPRIORITY_METHODDEF
  9623. #endif /* !defined(OS_SETPRIORITY_METHODDEF) */
  9624. #ifndef OS_SYSTEM_METHODDEF
  9625. #define OS_SYSTEM_METHODDEF
  9626. #endif /* !defined(OS_SYSTEM_METHODDEF) */
  9627. #ifndef OS_UMASK_METHODDEF
  9628. #define OS_UMASK_METHODDEF
  9629. #endif /* !defined(OS_UMASK_METHODDEF) */
  9630. #ifndef OS_UNAME_METHODDEF
  9631. #define OS_UNAME_METHODDEF
  9632. #endif /* !defined(OS_UNAME_METHODDEF) */
  9633. #ifndef OS_EXECV_METHODDEF
  9634. #define OS_EXECV_METHODDEF
  9635. #endif /* !defined(OS_EXECV_METHODDEF) */
  9636. #ifndef OS_EXECVE_METHODDEF
  9637. #define OS_EXECVE_METHODDEF
  9638. #endif /* !defined(OS_EXECVE_METHODDEF) */
  9639. #ifndef OS_POSIX_SPAWN_METHODDEF
  9640. #define OS_POSIX_SPAWN_METHODDEF
  9641. #endif /* !defined(OS_POSIX_SPAWN_METHODDEF) */
  9642. #ifndef OS_POSIX_SPAWNP_METHODDEF
  9643. #define OS_POSIX_SPAWNP_METHODDEF
  9644. #endif /* !defined(OS_POSIX_SPAWNP_METHODDEF) */
  9645. #ifndef OS_SPAWNV_METHODDEF
  9646. #define OS_SPAWNV_METHODDEF
  9647. #endif /* !defined(OS_SPAWNV_METHODDEF) */
  9648. #ifndef OS_SPAWNVE_METHODDEF
  9649. #define OS_SPAWNVE_METHODDEF
  9650. #endif /* !defined(OS_SPAWNVE_METHODDEF) */
  9651. #ifndef OS_REGISTER_AT_FORK_METHODDEF
  9652. #define OS_REGISTER_AT_FORK_METHODDEF
  9653. #endif /* !defined(OS_REGISTER_AT_FORK_METHODDEF) */
  9654. #ifndef OS_FORK1_METHODDEF
  9655. #define OS_FORK1_METHODDEF
  9656. #endif /* !defined(OS_FORK1_METHODDEF) */
  9657. #ifndef OS_FORK_METHODDEF
  9658. #define OS_FORK_METHODDEF
  9659. #endif /* !defined(OS_FORK_METHODDEF) */
  9660. #ifndef OS_SCHED_GET_PRIORITY_MAX_METHODDEF
  9661. #define OS_SCHED_GET_PRIORITY_MAX_METHODDEF
  9662. #endif /* !defined(OS_SCHED_GET_PRIORITY_MAX_METHODDEF) */
  9663. #ifndef OS_SCHED_GET_PRIORITY_MIN_METHODDEF
  9664. #define OS_SCHED_GET_PRIORITY_MIN_METHODDEF
  9665. #endif /* !defined(OS_SCHED_GET_PRIORITY_MIN_METHODDEF) */
  9666. #ifndef OS_SCHED_GETSCHEDULER_METHODDEF
  9667. #define OS_SCHED_GETSCHEDULER_METHODDEF
  9668. #endif /* !defined(OS_SCHED_GETSCHEDULER_METHODDEF) */
  9669. #ifndef OS_SCHED_SETSCHEDULER_METHODDEF
  9670. #define OS_SCHED_SETSCHEDULER_METHODDEF
  9671. #endif /* !defined(OS_SCHED_SETSCHEDULER_METHODDEF) */
  9672. #ifndef OS_SCHED_GETPARAM_METHODDEF
  9673. #define OS_SCHED_GETPARAM_METHODDEF
  9674. #endif /* !defined(OS_SCHED_GETPARAM_METHODDEF) */
  9675. #ifndef OS_SCHED_SETPARAM_METHODDEF
  9676. #define OS_SCHED_SETPARAM_METHODDEF
  9677. #endif /* !defined(OS_SCHED_SETPARAM_METHODDEF) */
  9678. #ifndef OS_SCHED_RR_GET_INTERVAL_METHODDEF
  9679. #define OS_SCHED_RR_GET_INTERVAL_METHODDEF
  9680. #endif /* !defined(OS_SCHED_RR_GET_INTERVAL_METHODDEF) */
  9681. #ifndef OS_SCHED_YIELD_METHODDEF
  9682. #define OS_SCHED_YIELD_METHODDEF
  9683. #endif /* !defined(OS_SCHED_YIELD_METHODDEF) */
  9684. #ifndef OS_SCHED_SETAFFINITY_METHODDEF
  9685. #define OS_SCHED_SETAFFINITY_METHODDEF
  9686. #endif /* !defined(OS_SCHED_SETAFFINITY_METHODDEF) */
  9687. #ifndef OS_SCHED_GETAFFINITY_METHODDEF
  9688. #define OS_SCHED_GETAFFINITY_METHODDEF
  9689. #endif /* !defined(OS_SCHED_GETAFFINITY_METHODDEF) */
  9690. #ifndef OS_OPENPTY_METHODDEF
  9691. #define OS_OPENPTY_METHODDEF
  9692. #endif /* !defined(OS_OPENPTY_METHODDEF) */
  9693. #ifndef OS_LOGIN_TTY_METHODDEF
  9694. #define OS_LOGIN_TTY_METHODDEF
  9695. #endif /* !defined(OS_LOGIN_TTY_METHODDEF) */
  9696. #ifndef OS_FORKPTY_METHODDEF
  9697. #define OS_FORKPTY_METHODDEF
  9698. #endif /* !defined(OS_FORKPTY_METHODDEF) */
  9699. #ifndef OS_GETEGID_METHODDEF
  9700. #define OS_GETEGID_METHODDEF
  9701. #endif /* !defined(OS_GETEGID_METHODDEF) */
  9702. #ifndef OS_GETEUID_METHODDEF
  9703. #define OS_GETEUID_METHODDEF
  9704. #endif /* !defined(OS_GETEUID_METHODDEF) */
  9705. #ifndef OS_GETGID_METHODDEF
  9706. #define OS_GETGID_METHODDEF
  9707. #endif /* !defined(OS_GETGID_METHODDEF) */
  9708. #ifndef OS_GETPID_METHODDEF
  9709. #define OS_GETPID_METHODDEF
  9710. #endif /* !defined(OS_GETPID_METHODDEF) */
  9711. #ifndef OS_GETGROUPLIST_METHODDEF
  9712. #define OS_GETGROUPLIST_METHODDEF
  9713. #endif /* !defined(OS_GETGROUPLIST_METHODDEF) */
  9714. #ifndef OS_GETGROUPS_METHODDEF
  9715. #define OS_GETGROUPS_METHODDEF
  9716. #endif /* !defined(OS_GETGROUPS_METHODDEF) */
  9717. #ifndef OS_INITGROUPS_METHODDEF
  9718. #define OS_INITGROUPS_METHODDEF
  9719. #endif /* !defined(OS_INITGROUPS_METHODDEF) */
  9720. #ifndef OS_GETPGID_METHODDEF
  9721. #define OS_GETPGID_METHODDEF
  9722. #endif /* !defined(OS_GETPGID_METHODDEF) */
  9723. #ifndef OS_GETPGRP_METHODDEF
  9724. #define OS_GETPGRP_METHODDEF
  9725. #endif /* !defined(OS_GETPGRP_METHODDEF) */
  9726. #ifndef OS_SETPGRP_METHODDEF
  9727. #define OS_SETPGRP_METHODDEF
  9728. #endif /* !defined(OS_SETPGRP_METHODDEF) */
  9729. #ifndef OS_GETPPID_METHODDEF
  9730. #define OS_GETPPID_METHODDEF
  9731. #endif /* !defined(OS_GETPPID_METHODDEF) */
  9732. #ifndef OS_GETLOGIN_METHODDEF
  9733. #define OS_GETLOGIN_METHODDEF
  9734. #endif /* !defined(OS_GETLOGIN_METHODDEF) */
  9735. #ifndef OS_GETUID_METHODDEF
  9736. #define OS_GETUID_METHODDEF
  9737. #endif /* !defined(OS_GETUID_METHODDEF) */
  9738. #ifndef OS_KILL_METHODDEF
  9739. #define OS_KILL_METHODDEF
  9740. #endif /* !defined(OS_KILL_METHODDEF) */
  9741. #ifndef OS_KILLPG_METHODDEF
  9742. #define OS_KILLPG_METHODDEF
  9743. #endif /* !defined(OS_KILLPG_METHODDEF) */
  9744. #ifndef OS_PLOCK_METHODDEF
  9745. #define OS_PLOCK_METHODDEF
  9746. #endif /* !defined(OS_PLOCK_METHODDEF) */
  9747. #ifndef OS_SETUID_METHODDEF
  9748. #define OS_SETUID_METHODDEF
  9749. #endif /* !defined(OS_SETUID_METHODDEF) */
  9750. #ifndef OS_SETEUID_METHODDEF
  9751. #define OS_SETEUID_METHODDEF
  9752. #endif /* !defined(OS_SETEUID_METHODDEF) */
  9753. #ifndef OS_SETEGID_METHODDEF
  9754. #define OS_SETEGID_METHODDEF
  9755. #endif /* !defined(OS_SETEGID_METHODDEF) */
  9756. #ifndef OS_SETREUID_METHODDEF
  9757. #define OS_SETREUID_METHODDEF
  9758. #endif /* !defined(OS_SETREUID_METHODDEF) */
  9759. #ifndef OS_SETREGID_METHODDEF
  9760. #define OS_SETREGID_METHODDEF
  9761. #endif /* !defined(OS_SETREGID_METHODDEF) */
  9762. #ifndef OS_SETGID_METHODDEF
  9763. #define OS_SETGID_METHODDEF
  9764. #endif /* !defined(OS_SETGID_METHODDEF) */
  9765. #ifndef OS_SETGROUPS_METHODDEF
  9766. #define OS_SETGROUPS_METHODDEF
  9767. #endif /* !defined(OS_SETGROUPS_METHODDEF) */
  9768. #ifndef OS_WAIT3_METHODDEF
  9769. #define OS_WAIT3_METHODDEF
  9770. #endif /* !defined(OS_WAIT3_METHODDEF) */
  9771. #ifndef OS_WAIT4_METHODDEF
  9772. #define OS_WAIT4_METHODDEF
  9773. #endif /* !defined(OS_WAIT4_METHODDEF) */
  9774. #ifndef OS_WAITID_METHODDEF
  9775. #define OS_WAITID_METHODDEF
  9776. #endif /* !defined(OS_WAITID_METHODDEF) */
  9777. #ifndef OS_WAITPID_METHODDEF
  9778. #define OS_WAITPID_METHODDEF
  9779. #endif /* !defined(OS_WAITPID_METHODDEF) */
  9780. #ifndef OS_WAIT_METHODDEF
  9781. #define OS_WAIT_METHODDEF
  9782. #endif /* !defined(OS_WAIT_METHODDEF) */
  9783. #ifndef OS_PIDFD_OPEN_METHODDEF
  9784. #define OS_PIDFD_OPEN_METHODDEF
  9785. #endif /* !defined(OS_PIDFD_OPEN_METHODDEF) */
  9786. #ifndef OS_SETNS_METHODDEF
  9787. #define OS_SETNS_METHODDEF
  9788. #endif /* !defined(OS_SETNS_METHODDEF) */
  9789. #ifndef OS_UNSHARE_METHODDEF
  9790. #define OS_UNSHARE_METHODDEF
  9791. #endif /* !defined(OS_UNSHARE_METHODDEF) */
  9792. #ifndef OS_READLINK_METHODDEF
  9793. #define OS_READLINK_METHODDEF
  9794. #endif /* !defined(OS_READLINK_METHODDEF) */
  9795. #ifndef OS_SYMLINK_METHODDEF
  9796. #define OS_SYMLINK_METHODDEF
  9797. #endif /* !defined(OS_SYMLINK_METHODDEF) */
  9798. #ifndef OS_TIMES_METHODDEF
  9799. #define OS_TIMES_METHODDEF
  9800. #endif /* !defined(OS_TIMES_METHODDEF) */
  9801. #ifndef OS_GETSID_METHODDEF
  9802. #define OS_GETSID_METHODDEF
  9803. #endif /* !defined(OS_GETSID_METHODDEF) */
  9804. #ifndef OS_SETSID_METHODDEF
  9805. #define OS_SETSID_METHODDEF
  9806. #endif /* !defined(OS_SETSID_METHODDEF) */
  9807. #ifndef OS_SETPGID_METHODDEF
  9808. #define OS_SETPGID_METHODDEF
  9809. #endif /* !defined(OS_SETPGID_METHODDEF) */
  9810. #ifndef OS_TCGETPGRP_METHODDEF
  9811. #define OS_TCGETPGRP_METHODDEF
  9812. #endif /* !defined(OS_TCGETPGRP_METHODDEF) */
  9813. #ifndef OS_TCSETPGRP_METHODDEF
  9814. #define OS_TCSETPGRP_METHODDEF
  9815. #endif /* !defined(OS_TCSETPGRP_METHODDEF) */
  9816. #ifndef OS_DUP2_METHODDEF
  9817. #define OS_DUP2_METHODDEF
  9818. #endif /* !defined(OS_DUP2_METHODDEF) */
  9819. #ifndef OS_LOCKF_METHODDEF
  9820. #define OS_LOCKF_METHODDEF
  9821. #endif /* !defined(OS_LOCKF_METHODDEF) */
  9822. #ifndef OS_READV_METHODDEF
  9823. #define OS_READV_METHODDEF
  9824. #endif /* !defined(OS_READV_METHODDEF) */
  9825. #ifndef OS_PREAD_METHODDEF
  9826. #define OS_PREAD_METHODDEF
  9827. #endif /* !defined(OS_PREAD_METHODDEF) */
  9828. #ifndef OS_PREADV_METHODDEF
  9829. #define OS_PREADV_METHODDEF
  9830. #endif /* !defined(OS_PREADV_METHODDEF) */
  9831. #ifndef OS_SENDFILE_METHODDEF
  9832. #define OS_SENDFILE_METHODDEF
  9833. #endif /* !defined(OS_SENDFILE_METHODDEF) */
  9834. #ifndef OS__FCOPYFILE_METHODDEF
  9835. #define OS__FCOPYFILE_METHODDEF
  9836. #endif /* !defined(OS__FCOPYFILE_METHODDEF) */
  9837. #ifndef OS_PIPE_METHODDEF
  9838. #define OS_PIPE_METHODDEF
  9839. #endif /* !defined(OS_PIPE_METHODDEF) */
  9840. #ifndef OS_PIPE2_METHODDEF
  9841. #define OS_PIPE2_METHODDEF
  9842. #endif /* !defined(OS_PIPE2_METHODDEF) */
  9843. #ifndef OS_WRITEV_METHODDEF
  9844. #define OS_WRITEV_METHODDEF
  9845. #endif /* !defined(OS_WRITEV_METHODDEF) */
  9846. #ifndef OS_PWRITE_METHODDEF
  9847. #define OS_PWRITE_METHODDEF
  9848. #endif /* !defined(OS_PWRITE_METHODDEF) */
  9849. #ifndef OS_PWRITEV_METHODDEF
  9850. #define OS_PWRITEV_METHODDEF
  9851. #endif /* !defined(OS_PWRITEV_METHODDEF) */
  9852. #ifndef OS_COPY_FILE_RANGE_METHODDEF
  9853. #define OS_COPY_FILE_RANGE_METHODDEF
  9854. #endif /* !defined(OS_COPY_FILE_RANGE_METHODDEF) */
  9855. #ifndef OS_SPLICE_METHODDEF
  9856. #define OS_SPLICE_METHODDEF
  9857. #endif /* !defined(OS_SPLICE_METHODDEF) */
  9858. #ifndef OS_MKFIFO_METHODDEF
  9859. #define OS_MKFIFO_METHODDEF
  9860. #endif /* !defined(OS_MKFIFO_METHODDEF) */
  9861. #ifndef OS_MKNOD_METHODDEF
  9862. #define OS_MKNOD_METHODDEF
  9863. #endif /* !defined(OS_MKNOD_METHODDEF) */
  9864. #ifndef OS_MAJOR_METHODDEF
  9865. #define OS_MAJOR_METHODDEF
  9866. #endif /* !defined(OS_MAJOR_METHODDEF) */
  9867. #ifndef OS_MINOR_METHODDEF
  9868. #define OS_MINOR_METHODDEF
  9869. #endif /* !defined(OS_MINOR_METHODDEF) */
  9870. #ifndef OS_MAKEDEV_METHODDEF
  9871. #define OS_MAKEDEV_METHODDEF
  9872. #endif /* !defined(OS_MAKEDEV_METHODDEF) */
  9873. #ifndef OS_FTRUNCATE_METHODDEF
  9874. #define OS_FTRUNCATE_METHODDEF
  9875. #endif /* !defined(OS_FTRUNCATE_METHODDEF) */
  9876. #ifndef OS_TRUNCATE_METHODDEF
  9877. #define OS_TRUNCATE_METHODDEF
  9878. #endif /* !defined(OS_TRUNCATE_METHODDEF) */
  9879. #ifndef OS_POSIX_FALLOCATE_METHODDEF
  9880. #define OS_POSIX_FALLOCATE_METHODDEF
  9881. #endif /* !defined(OS_POSIX_FALLOCATE_METHODDEF) */
  9882. #ifndef OS_POSIX_FADVISE_METHODDEF
  9883. #define OS_POSIX_FADVISE_METHODDEF
  9884. #endif /* !defined(OS_POSIX_FADVISE_METHODDEF) */
  9885. #ifndef OS_PUTENV_METHODDEF
  9886. #define OS_PUTENV_METHODDEF
  9887. #endif /* !defined(OS_PUTENV_METHODDEF) */
  9888. #ifndef OS_UNSETENV_METHODDEF
  9889. #define OS_UNSETENV_METHODDEF
  9890. #endif /* !defined(OS_UNSETENV_METHODDEF) */
  9891. #ifndef OS_WCOREDUMP_METHODDEF
  9892. #define OS_WCOREDUMP_METHODDEF
  9893. #endif /* !defined(OS_WCOREDUMP_METHODDEF) */
  9894. #ifndef OS_WIFCONTINUED_METHODDEF
  9895. #define OS_WIFCONTINUED_METHODDEF
  9896. #endif /* !defined(OS_WIFCONTINUED_METHODDEF) */
  9897. #ifndef OS_WIFSTOPPED_METHODDEF
  9898. #define OS_WIFSTOPPED_METHODDEF
  9899. #endif /* !defined(OS_WIFSTOPPED_METHODDEF) */
  9900. #ifndef OS_WIFSIGNALED_METHODDEF
  9901. #define OS_WIFSIGNALED_METHODDEF
  9902. #endif /* !defined(OS_WIFSIGNALED_METHODDEF) */
  9903. #ifndef OS_WIFEXITED_METHODDEF
  9904. #define OS_WIFEXITED_METHODDEF
  9905. #endif /* !defined(OS_WIFEXITED_METHODDEF) */
  9906. #ifndef OS_WEXITSTATUS_METHODDEF
  9907. #define OS_WEXITSTATUS_METHODDEF
  9908. #endif /* !defined(OS_WEXITSTATUS_METHODDEF) */
  9909. #ifndef OS_WTERMSIG_METHODDEF
  9910. #define OS_WTERMSIG_METHODDEF
  9911. #endif /* !defined(OS_WTERMSIG_METHODDEF) */
  9912. #ifndef OS_WSTOPSIG_METHODDEF
  9913. #define OS_WSTOPSIG_METHODDEF
  9914. #endif /* !defined(OS_WSTOPSIG_METHODDEF) */
  9915. #ifndef OS_FSTATVFS_METHODDEF
  9916. #define OS_FSTATVFS_METHODDEF
  9917. #endif /* !defined(OS_FSTATVFS_METHODDEF) */
  9918. #ifndef OS_STATVFS_METHODDEF
  9919. #define OS_STATVFS_METHODDEF
  9920. #endif /* !defined(OS_STATVFS_METHODDEF) */
  9921. #ifndef OS__GETDISKUSAGE_METHODDEF
  9922. #define OS__GETDISKUSAGE_METHODDEF
  9923. #endif /* !defined(OS__GETDISKUSAGE_METHODDEF) */
  9924. #ifndef OS_FPATHCONF_METHODDEF
  9925. #define OS_FPATHCONF_METHODDEF
  9926. #endif /* !defined(OS_FPATHCONF_METHODDEF) */
  9927. #ifndef OS_PATHCONF_METHODDEF
  9928. #define OS_PATHCONF_METHODDEF
  9929. #endif /* !defined(OS_PATHCONF_METHODDEF) */
  9930. #ifndef OS_CONFSTR_METHODDEF
  9931. #define OS_CONFSTR_METHODDEF
  9932. #endif /* !defined(OS_CONFSTR_METHODDEF) */
  9933. #ifndef OS_SYSCONF_METHODDEF
  9934. #define OS_SYSCONF_METHODDEF
  9935. #endif /* !defined(OS_SYSCONF_METHODDEF) */
  9936. #ifndef OS_STARTFILE_METHODDEF
  9937. #define OS_STARTFILE_METHODDEF
  9938. #endif /* !defined(OS_STARTFILE_METHODDEF) */
  9939. #ifndef OS_GETLOADAVG_METHODDEF
  9940. #define OS_GETLOADAVG_METHODDEF
  9941. #endif /* !defined(OS_GETLOADAVG_METHODDEF) */
  9942. #ifndef OS_SETRESUID_METHODDEF
  9943. #define OS_SETRESUID_METHODDEF
  9944. #endif /* !defined(OS_SETRESUID_METHODDEF) */
  9945. #ifndef OS_SETRESGID_METHODDEF
  9946. #define OS_SETRESGID_METHODDEF
  9947. #endif /* !defined(OS_SETRESGID_METHODDEF) */
  9948. #ifndef OS_GETRESUID_METHODDEF
  9949. #define OS_GETRESUID_METHODDEF
  9950. #endif /* !defined(OS_GETRESUID_METHODDEF) */
  9951. #ifndef OS_GETRESGID_METHODDEF
  9952. #define OS_GETRESGID_METHODDEF
  9953. #endif /* !defined(OS_GETRESGID_METHODDEF) */
  9954. #ifndef OS_GETXATTR_METHODDEF
  9955. #define OS_GETXATTR_METHODDEF
  9956. #endif /* !defined(OS_GETXATTR_METHODDEF) */
  9957. #ifndef OS_SETXATTR_METHODDEF
  9958. #define OS_SETXATTR_METHODDEF
  9959. #endif /* !defined(OS_SETXATTR_METHODDEF) */
  9960. #ifndef OS_REMOVEXATTR_METHODDEF
  9961. #define OS_REMOVEXATTR_METHODDEF
  9962. #endif /* !defined(OS_REMOVEXATTR_METHODDEF) */
  9963. #ifndef OS_LISTXATTR_METHODDEF
  9964. #define OS_LISTXATTR_METHODDEF
  9965. #endif /* !defined(OS_LISTXATTR_METHODDEF) */
  9966. #ifndef OS_MEMFD_CREATE_METHODDEF
  9967. #define OS_MEMFD_CREATE_METHODDEF
  9968. #endif /* !defined(OS_MEMFD_CREATE_METHODDEF) */
  9969. #ifndef OS_EVENTFD_METHODDEF
  9970. #define OS_EVENTFD_METHODDEF
  9971. #endif /* !defined(OS_EVENTFD_METHODDEF) */
  9972. #ifndef OS_EVENTFD_READ_METHODDEF
  9973. #define OS_EVENTFD_READ_METHODDEF
  9974. #endif /* !defined(OS_EVENTFD_READ_METHODDEF) */
  9975. #ifndef OS_EVENTFD_WRITE_METHODDEF
  9976. #define OS_EVENTFD_WRITE_METHODDEF
  9977. #endif /* !defined(OS_EVENTFD_WRITE_METHODDEF) */
  9978. #ifndef OS_GET_TERMINAL_SIZE_METHODDEF
  9979. #define OS_GET_TERMINAL_SIZE_METHODDEF
  9980. #endif /* !defined(OS_GET_TERMINAL_SIZE_METHODDEF) */
  9981. #ifndef OS_GET_HANDLE_INHERITABLE_METHODDEF
  9982. #define OS_GET_HANDLE_INHERITABLE_METHODDEF
  9983. #endif /* !defined(OS_GET_HANDLE_INHERITABLE_METHODDEF) */
  9984. #ifndef OS_SET_HANDLE_INHERITABLE_METHODDEF
  9985. #define OS_SET_HANDLE_INHERITABLE_METHODDEF
  9986. #endif /* !defined(OS_SET_HANDLE_INHERITABLE_METHODDEF) */
  9987. #ifndef OS_GETRANDOM_METHODDEF
  9988. #define OS_GETRANDOM_METHODDEF
  9989. #endif /* !defined(OS_GETRANDOM_METHODDEF) */
  9990. #ifndef OS__ADD_DLL_DIRECTORY_METHODDEF
  9991. #define OS__ADD_DLL_DIRECTORY_METHODDEF
  9992. #endif /* !defined(OS__ADD_DLL_DIRECTORY_METHODDEF) */
  9993. #ifndef OS__REMOVE_DLL_DIRECTORY_METHODDEF
  9994. #define OS__REMOVE_DLL_DIRECTORY_METHODDEF
  9995. #endif /* !defined(OS__REMOVE_DLL_DIRECTORY_METHODDEF) */
  9996. #ifndef OS_WAITSTATUS_TO_EXITCODE_METHODDEF
  9997. #define OS_WAITSTATUS_TO_EXITCODE_METHODDEF
  9998. #endif /* !defined(OS_WAITSTATUS_TO_EXITCODE_METHODDEF) */
  9999. /*[clinic end generated code: output=6f0c08f692891c72 input=a9049054013a1b77]*/