posixmodule.c.h 327 KB

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